akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n;
	int map[20][20];
	int a[20][20];
	cin >> n;
	for (int z = 0; z < n; z++) {
		for (int i = 0; i < 20; i++) { for (int j = 0; j < 20; j++) { map[i][j] = 0; a[i][j] = 0; } }
		int s, t;
		cin >> s >> t;
		map[s][t] = 100;
		int p;
		cin >> p;
		int x, y, xx, yy;
		for (int i = 0; i < p; i++) {
			scanf("%d%d%d%d", &x, &y, &xx, &yy);
			if (x == xx) { map[x][min(y, yy)] += 1; }
			if (y == yy)map[min(x, xx)][y] += 2;
		}
		a[0][0] = 1;
		for (int i = 0; i <= s; i++) {
			for (int j = 0; j <= t; j++)
			{
				if (i > 0) { if (!(map[i - 1][j] >= 2))a[i][j] += a[i - 1][j]; }
				if (j > 0) { if (!(map[i][j - 1] == 1 || map[i][j - 1] == 3))a[i][j] += a[i][j - 1]; }
			}
		}
		if (a[s][t] == 0)cout << "Miserable Hokusai!" << endl;
		else cout << a[s][t] << endl;
	}
}

Measured memory_bytes: 1248
N = int(input())
A_l = list(map(int, input().split()))

ans_l = [0]*N

i = 0
while i < N-1:
  ans_l[A_l[i]-1] += 1
  i += 1

i=0
while i < N:
  print(ans_l[i])
  i += 1


Measured memory_bytes: 32348
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw=new PrintWriter(System.out);
		int x=Integer.parseInt(br.readLine());
		ArrayDeque<Integer> list=new ArrayDeque<Integer>();
		for (int i = 0; i < x; i++) {
			String s=br.readLine();
			if(s.charAt(0)=='i'){
				list.addFirst(Integer.parseInt(s.substring(7)));
			}
			else if(s.charAt(6)==' '){
				list.remove(Integer.parseInt(s.substring(7)));
			}else if(s.charAt(6)=='F'){
				list.removeFirst();
			}else{
				list.removeLast();

			}
		}
		StringBuffer sb=new StringBuffer();
		sb.append(list.poll());
		for (Integer integer : list) {
			sb.append(" "+integer);
		}
		pw.println(sb);
		pw.close();
	}

}

Measured memory_bytes: 118196
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    h = list(map(int, input().rstrip('\n').split()))
    cnt = 0
    m_cnt = 0
    for i in range(1, n):
        if h[i] <= h[i-1]:
            cnt += 1
            m_cnt = max(m_cnt, cnt)
        else:
            cnt = 0
    print(m_cnt)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 63856
L, R = map(int, input().split())
MOD = 2019

def f(i, j):
    if j - i >= MOD:
        return 0
    i %= MOD
    j %= MOD
    if i > j:
        return 0
    ans = 2018
    for a in range(i, j):
        for b in range(a+1, j+1):
            ans = min(ans, a*b%MOD)
    return ans

print(f(L,R))



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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

void Main(){
    long double A,B; cin >> A >> B;
    ll ans = floor(A*B);
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t){
        Main();
    }
    return 0;
}

Measured memory_bytes: 3736
import java.io.*;
public class Main {
	
	public static void main(String[] args)throws IOException{
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		while(true){
			String[] str = br.readLine().split(" ");
			int H = Integer.parseInt(str[0]);
			int W = Integer.parseInt(str[1]);
			//System.out.print("\n");
			if(H==0 && W==0)break;
			//System.out.print("\n");
			
			for(int j=0; j<H; j++){
			
				for(int i=0; i<W; i++){
					System.out.print("#");
				}
					System.out.print("\n");
			}
			System.out.print("\n");
		}
	}

}

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

int main() {
   string n;
   cin >> n;

   rep(i, 3) {
       if (n[i] == '7') {
           cout << "Yes" << endl;
           return 0;
       }
   }

   cout << "No" << endl;
}

Measured memory_bytes: 3528
l = [[[0 for k in range(10)] for j in range(3)] for i in range(4)]
n = int(input())
for i in range(n):
  b, f, r, v = map(int, input().split())
  l[b-1][f-1][r-1] += v
for i in range(4):
  for j in range(3):
    for k in range(10):
        print("", l[i][j][k], end = "")
    print()
  if i != 3:
    print("#"*20)


Measured memory_bytes: 5636
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
	int k,n;
	scanf("%d%d",&k,&n);
	int before,maxn=0;
	int first;
	scanf("%d",&first);
	before=first;
	int x;
	for(int i=2;i<=n;i++)
	{
		scanf("%d",&x);
		maxn=max(maxn,x-before);
		before=x;
	}
	maxn=max(maxn,k-x+first);
	printf("%d\n",k-maxn);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

string app() {
  int k,a,b;
  cin>>k>>a>>b;

  return (b/k*k>=a)?"OK":"NG";
}

int main(){cout<<app()<<endl;return 0;}


Measured memory_bytes: 3624
import sys
import math
import bisect

def solve():
    n = int(input())
    my_set = set()
    for i in range(n):
        if i == 0:
            s = input()
            my_set.add(s)
        else:
            pre, s = s, input()
            if pre[-1] != s[0]:
                return False
            if s in my_set:
                return False
            my_set.add(s)
    return True

def main():
    if solve():
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAXN 300

// dp[i][j][k]:1スi枚,2スj枚,3スk枚
double dp[MAXN+1][MAXN+1][MAXN+1];
int n;

double rec(int i, int j, int k){
  if(!i && !j && !k)return 0.0;
  if(dp[i][j][k]>0.0)return dp[i][j][k];

  double sum = i+j+k;
  double ret = n/sum;
  if(i>0)ret += (double)(i/sum) * rec(i-1, j, k);
  if(j>0)ret += (double)(j/sum) * rec(i+1, j-1, k);
  if(k>0)ret += (double)(k/sum) * rec(i, j+1, k-1);

  return dp[i][j][k]=ret;
}

int main(){
  cin>>n;
  double dn=(double)n;
  vector<int>a(n);
  rep(i, n)cin>>a[i];

  map<int, int>m;
  for(auto t:a)m[t]++;

//  cout<<fixed<<setprecision(12)<<rec(m[1], m[2], m[3])<<endl;
  printf("%.12f", rec(m[1], m[2], m[3]));

  return 0;

rep(i, n)rep(j, n)rep(k, n)cout<<dp[i][j][k]<<' '<<i<<' '<<j<<' '<<k<<endl;

  return 0;
}

Measured memory_bytes: 111236
import java.util.*
import kotlin.math.max
import kotlin.math.min

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val k = sc.nextInt()
    println(problem162c(k))
}

fun problem162c(k: Int): Long {
    /**
     * 最大公約数
     * @param big 2つの値の大きな方
     * @param small 2つの値の小さな方
     */
    fun computeGreatestCommonDivisor(big: Long, small: Long): Long {
        val rest = big % small
        return if (rest == 0L) small else computeGreatestCommonDivisor(small, rest)
    }
    var sum = 0L
    for (a in 1L..k) {
        for (b in 1L..k) {
            for (c in 1L..k) {
                val big = listOf(a, b).max()!!
                val small = listOf(a, b).min()!!
                val tmp = computeGreatestCommonDivisor(big, small)
                sum += computeGreatestCommonDivisor(min(tmp, c), max(tmp, c))
            }
        }
    }
    return sum
}

Measured memory_bytes: 60480
import java.util.Scanner;

class Main{
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        while (true) {
            int n = scan.nextInt();
            if (n == 0) {
                break;
            }
            System.out.println(hurui(n));
        }
    }

    private static int hurui(int num) {
        int[] data = new int[num * 2+1];
        for(int i=1;i<=num*2;i++){
            data[i]=i;
        }
        for(int i=2;i<=Math.sqrt(data.length-1);i++){
            if(data[i]==i){
                for(int j=i+1;j<data.length;j++){
                    if (j%i==0){
                        data[j]=0;
                    }
                }
            }
        }
        int count=0;
        for(int i=num+1;i<data.length;i++){
            if(data[i]==i){
                count++;
            }
        }
        return count;
    }
}


Measured memory_bytes: 58812
let k, t, ss = Scanf.scanf "%d %d %d %d %d %s" @@ fun n k r s p t -> k, t, Array.init n (fun i -> match t.[i] with 'r' -> p | 's' -> r | _ -> s)
let _ = Array.(iteri (fun i s -> if i >= k && ss.(i - k) > 0 && t.[i] = t.[i - k] then ss.(i) <- 0) ss; fold_left (+) 0 ss) |> Printf.printf "%d\n"

Measured memory_bytes: 3584
#include <stdio.h>

int main(void)
{
  int a, b, ans=0, i;
  scanf("%d %d", &a, &b);

  for(i = 0; i < b - a; i++){
    ans += i;
  }
  ans = ans - a;

  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define eps 1e-6
#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const int mod = 998244353;
long double PI = acosl(-1);
const ll infl = 1e18+100;
const int inf = 2e9+100;
const int nmax = 1e6+10;
const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;

bool cmp(pii a, pii b){
    return a.first-a.second < b.first-b.second;
}

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

    int x,y,z;
    cin>>x>>y>>z;
    int n = x+y+z;
    vector<pii>v(n);
    ll tmp = 0;
    for(pii &z : v){
        cin>>z.first>>z.second;
        int p;
        cin>>p;
        tmp+=p;
        z.first-=p, z.second-=p;
    }
    sort(v.begin(), v.end(), cmp);

    vector<ll>sambam(n), samdan(n);
    priority_queue<int>bam, dan;
    ll curbam=0, curdan=0;

    for(int i=0; i<n; i++){
        bam.push(-v[i].second), curbam+=v[i].second;
        if(bam.size()>y) curbam+=bam.top(), bam.pop();
        sambam[i] = curbam;
    }
    for(int i=n-1; i>=0; i--){
        dan.push(-v[i].first), curdan+=v[i].first;
        if(dan.size()>x) curdan+=dan.top(), dan.pop();
        samdan[i] = curdan;
    }

    ll ans = -infl;
    for(int i=y; x<=n-i; i++) ans = max(ans, sambam[i-1]+samdan[i]);
    cout<<ans+tmp<<endl;
}
/*

*/


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

using namespace std;

int main() {
    string s;
    cin >> s;

    int ans = 0;
    for (int i = 0; i < s.length() - 1; ++i) {
        if (s[i] != s[i + 1]) {
            ans++;
        }
    }

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

Measured memory_bytes: 512
from bisect import *
A,B,Q=map(int,input().split())
s=[-10**11]+[int(input()) for i in range(A)]+[10**11]
t=[-10**11]+[int(input()) for i in range(B)]+[10**11]
x=[int(input()) for i in range(Q)]
for i in range(Q):
    S=[0,0]
    T=[0,0]
    sidx=bisect_left(s,x[i])-1
    S[0]=s[sidx]
    S[1]=s[sidx+1]
    tidx=bisect_left(t,x[i])-1
    T[0]=t[tidx]
    T[1]=t[tidx+1]
    ans=10**12
    seq=[(0,1),(1,0),(1,1),(0,0)]
    for a,b in seq:
        tmp=abs(x[i]-S[a])+abs(S[a]-T[b])
        ans=min(ans,tmp)
        tmp=abs(x[i]-T[a])+abs(T[a]-S[b])
        ans=min(ans,tmp)
    print(ans)

Measured memory_bytes: 18048
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

double A, B, H, M;
const double pi = acos(-1);

int main()
{
  std::cin >> A >> B >> H >> M;

  double h = H+M/60.0;

  double hA = fmod( h, 12 )/12.0*2*pi;
  double mA = fmod( h, 1.0 )*2*pi;

  printf( "%.12f\n", sqrt( A*A+B*B-2*A*B*cos(hA-mA) ) );

  return 0;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>	
#define int long long int
#define pb push_back
#define endl "\n"
#define F first
#define S second 
#define mod 1000000007     
using namespace std;

main()
{	
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int k, n, sum = 0, diff = -1 * mod;
	cin >> k >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	for(int i = 1; i < n; i++){
		diff = max(a[i] - a[i - 1], diff);
	}
	diff = max(k - a[n - 1] + a[0], diff);
	cout << k - diff << endl;
}

Measured memory_bytes: 1792
// in case of multiple test cases and N=1e5 don't intialize arrays as global except for graph vector-array
// always check whether or not you are doing mod of a negative number
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
using namespace __gnu_pbds;
using namespace std;

#define double      	long double
#define int         	long long
#define pb          	push_back
#define pii         	pair<int,int>
#define vi          	vector<int>
#define vii         	vector<pii>
#define mi          	map<int,int>
#define mii         	map<pii,int>
#define all(a)      	(a).begin(),(a).end()
#define sz(x)       	(int)x.size()
#define endl        	"\n"
#define repp(i,a,b) 	for(int i=a;i<b;i++)
#define rep(i,a,b) 		for(int i=a;i<=b;i++)
#define brep(i,a,b)     for(int i=a;i>=b;i--)
#define deb1(x)      	cout << #x << "=" << x << endl
#define deb2(x, y)  	cout << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x, y, z)  	cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define trace(v) 		for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
#define tracearr(a,l,r) for(int iii=l;iii<=r;iii++)cout << a[iii] << " ";cout << endl;
#define PI          	3.1415926535897932384626
#define F 				first
#define S 				second
#define clr(x,y) 		memset(x, y, sizeof(x))
#define IOS         	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
// *s.find_by_order(1) - gives the 2nd samllest element in set
// s.order_of_key(x)   - gives the number of elements in the set which are strictly smaller than x


const int N=1e5 + 5;
const int MOD=1e9 + 7;

int32_t main()
{
	IOS;
	int T=1;
	//cin >> T;
	// int numOfSetBits = __builtin_popcountll(n);
	std::cout << std::fixed << std::setprecision(12);
	while(T--)
	{
		string s;
		cin >> s;
		int ans = 0;
		int c = 0;
		for(char cc: s)
		{
			if(cc=='R')
			{
				c++;
				ans = max(ans,c);
			}
			else
				c = 0;
		}
		cout << ans;
	}
}

Measured memory_bytes: 3604
import java.util.*;

public class Main {
	String s = "";
	int pos = 0;
	
	int exp(){
		int p = term();
		while(true){
			if(pos==s.length()) break;
			int q = s.codePointAt(pos);
			pos++;
			if(q==43) p+=term();
			else if(q==45) p-=term();
			else break;
		}
		return p;
	}
	
	int term(){
		int p = fact();
		while(true){
			if(pos==s.length()) break;
			int q = s.codePointAt(pos);
			pos++;
			if(q==42) p*=fact();
			else if(q==47) p/=fact();
			else break;
		}
		pos--;
		return p;
	}
	
	int fact(){
		int q = s.codePointAt(pos);
		pos++;
		if(q==40) return exp();
		if(q==43) return fact();
		if(q==45) return -fact();

		pos--;
		int ini = pos;
		while(s.codePointAt(pos)>=48 && s.codePointAt(pos)<=57){
			pos++;
			if(pos==s.length()) break;
		}
		int p = Integer.valueOf(s.substring(ini,pos));
		return p;
	}
	
	void solve(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i=0;i<n;i++){
			s = sc.next();
			pos = 0;
			System.out.println(exp());
		}
	}

	
	public static void main(String[] args) {
		new Main().solve();
	}	
}

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

typedef long long ll;
typedef long long LL;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

#ifdef DEBUG
    #define cek(x) cout<<x
#else
    #define cek(x) if(false){}
#endif // DEBUG

#define fi first
#define se second
#define INF 1000000000
#define INFLL 1000000000000000000LL
#define EPS 1e-9
#define PI acos(-1.0)
#define pb push_back
#define TC() while(tc--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORN(i,n) for(int i=0;i<=n;i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define REPN(i,a,b) for(int i=a;i<=b;i++)
#define reset(a,b) memset(a,b,sizeof(a))
#define sc(x) scanf("%d",&x)

void open(){
	freopen("D:/Code/in.txt","r",stdin);
	// freopen("D:/Code/out.txt", "w", stdout);
}

int inc[100010];
vi adjList[100010];
int lvl[100010];
vi ret[100010];

// void dfs(int node, int p = -1){
// 	int anak = (int) adjList[node].size();
// 	int ret = 0;
// 	for(int i = 0;i<adjList[node].size();i++){
// 		int nxt = adjList[node][i];
// 		if(nxt == p)continue;
// 		dfs(nxt, node);
// 		ret = max(ret, lvl[nxt] + 1);
// 	}
// 	lvl[node] = max(ret, anak - ((p == -1) ? 0 : 1));
// }

int main(void){
	// open();
	int n;
	sc(n);
	reset(lvl, 0);
	for(int i = 1;i<n;i++){
		int x;
		sc(x);
		x--;
		adjList[i].pb(x);
		// adjList[x].pb(i);
		inc[x]++;
		// lvl[x] = inc[x];
	}

	queue<int> q;
	for(int i = 0;i<n;i++){
		if(!inc[i])q.push(i);
	}
	while(!q.empty()){
		int cur = q.front();q.pop();
		for(int i = 0;i<adjList[cur].size();i++){
			int nxt = adjList[cur][i];
			inc[nxt]--;
			ret[nxt].pb(lvl[cur]);
			if(inc[nxt] == 0){
				q.push(nxt);
				// lvl[nxt] = max(lvl[nxt], lvl[cur] + 1);
				sort(ret[nxt].begin(), ret[nxt].end());
				int val = ret[nxt].size();
				for(int j = 0;j<ret[nxt].size();j++){
					lvl[nxt] = max(lvl[nxt], ret[nxt][j] + val);
					val--;
				}
			}
		}
	}
	// dfs(0);
	// FOR(i,n){
	// 	cout << lvl[i] << " ";
	// }cout << endl;
	cout << lvl[0] << endl;
    return 0;
}




Measured memory_bytes: 12032
#include<bits/stdc++.h>
using namespace std;
int n,AS,AT,BS,BT;
char ss[200005];
bool pan3(int s,int t) {
	for(int i=s;i<=t;i++) {
		if(ss[i-1]=='.'&&ss[i]=='.'&&ss[i+1]=='.') return 1;
	}
	return 0;
}
bool ok(int s,int t) {
	if(ss[s]=='#'||ss[t]=='#') return 0;
	for(int i=s+1;i<=t;i++) {
		if(ss[i]=='#'&&ss[i-1]=='#') return 0;
	}
	return 1;
}
int main() {
	scanf("%d%d%d%d%d",&n,&AS,&BS,&AT,&BT);
	scanf("%s",&ss[1]);
	if(AT<BS|| (BT>AT) ) {
		if(ok(AS,AT)&&ok(BS,BT)) puts("Yes");
		else puts("No");
		return 0;
	}
	if(pan3(BS,BT)&&ok(BS,BT)&&ok(AS,AT)) puts("Yes");
	else puts("No");
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int[] a = new int[4];
			int[] b = new int[4];
			for(int i = 0; i < 4; i++) {
				a[i] = sc.nextInt();
			}
			for(int i = 0; i < 4; i++) {
				b[i] = sc.nextInt();
			}
			int c1 = 0;
			int c2 = 0;
			for(int i = 0; i < 4; i++) {
				if(a[i] == b[i]) {
					c1++;
				}
				for(int j = 0; j < 4; j++) {
					if(a[i] == b[j]) {
						c2++;
					}
				}
			}
			System.out.printf("%d %d\n", c1, c2 - c1);
		}
		sc.close();
	}
}


Measured memory_bytes: 26472
#include <stdio.h>
#include <stdlib.h>//random,NULL
#include <string.h>
#include <time.h>
#include <unistd.h>//sleep()
#include <math.h>
#include <stdbool.h>

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000

int main(){
  char buf[1024];
  int A,B;

  fgets(buf,sizeof(buf),stdin);
  sscanf(buf, "%d %d", &A, &B);

  if(B%A==0){
    printf("%d\n",A+B);
  }
  else{
    printf("%d\n",B-A);
  }

  return 0;


}


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

class Cube{
    public:
    int f[6];
    Cube(){}
    void roll_z(){roll(1,2,4,3);}
    void roll_y(){roll(0,2,5,3);}
    void roll_x(){roll(0,1,5,4);}
    void roll(int i,int j,int k,int l){
        int t =f[i]; f[i]=f[j]; f[j]=f[k]; f[k]=f[l]; f[l]=t;
    }
    void move(char ch){
        if (ch =='E') for (int i =0;i<3;i++) roll_y();
        if (ch =='W') roll_y();
        if (ch =='N') roll_x();
        if (ch =='S') for (int i =0; i<3; i++) roll_x();
    }
};

int main(){
    Cube c;
    string com;
    
    for (int i=0;i<6;i++) cin >> c.f[i];
    cin >> com;
    
    for (int i=0; i<com.size(); i++) c.move(com[i]);
    
    cout << c.f[0] << endl ;
    
    return 0;
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

ll fac[510000], finv[510000], inv[510000];

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

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
*/

int main(){
    ll N,M;
    cin >> N >> M;
    vector<vector<ll>> cost(16,vector<ll>(16,INF));
    vector<vector<ll>> memo(1 << 16,vector<ll>(16,INF));
    ll a,b,c;
    rep(i,M){
        cin >> a >> b >> c;
        cost[a][b] = c;
    }
    memo[(1 << N) - 1][0] = 0;
    for(ll i = (1 << N) - 2;i >= 0;i--){
        rep(v,N){
            rep(u,N){
                if(!(i >> u&1)){
                    memo[i][v] = min(memo[i][v],memo[i | 1 << u][u] + cost[u][v]);
                }
            }
        }
    }
    if(memo[0][0] != INF)cout << memo[0][0] << endl;
    else cout << -1 << endl;
}


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

typedef pair <string, string> pii;

const long long MAX_N = 36, BASE = 37, MOD = 1e9 + 7;
long long n, ans;
long long pw[MAX_N];
string s;
map <pii, long long> Map;

long long _sum(long long a, long long b) {
	long long c = a + b;
	if (MOD <= c)
		c -= MOD;
		
	return c;
}

long long _mul(long long a, long long b) {
	return 1LL * a * b % MOD;
}

void pre_process() {
	pw[0] = 1;
	for (long long i = 1; i < MAX_N; i++)
		pw[i] = (BASE * pw[i - 1]) % MOD;
}


int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);	
	cin >> n >> s;
	pre_process();
	
	for (long long i = 0; i < (1 << n); i++) {
		string s1, s2;
		
		for (long long j = 0; j < n; j++) {
			if ((i >> j) & 1)
				s1 += s[j];
			else
				s2 = s[j] + s2;
		}
		
		Map[{s1, s2}]++;
	}
	
	for (long long i = 0; i < (1 << n); i++) {
		string s1, s2;
	
		for (long long j = 0; j < n; j++) {
			if ((i >> j) & 1)
				s1 += s[j + n];
			else
				s2 = s[j + n] + s2;
		}
		
		ans += Map[{s2, s1}];
	}
	
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 87040
#include<stdio.h>
int main()
{
    long long int a,b,gcd,t,x;
    while(scanf("%lld %lld",&a,&b)!=EOF)
    {
x=1;
x*=a*b;
    if(b==0)
        gcd=a;
    else if(a==0)
        gcd=b;
    else
    {
        while(b!=0)
        {
          t=b;
          b=a%b;
          a=t;
        }
        gcd=a;
    }
    printf("%lld %lld\n",gcd,x/gcd);
    }
    return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;

int main() {
    int N, M; cin >> N >> M;
    vector<vector<int>> L(M);
    for (int i = 0; i < M; i++) {
        int k; cin >> k;
        for (int j = 0; j < k; j++) {
            int s; cin >> s;
            s--;
            L[i].push_back(s);
        }
    }
    vector<int> P(M);
    for (int i = 0; i < M; i++) {
        cin >> P[i];
    }

    int ans = 0;
    for (int tmp = 0; tmp < (1 << N); tmp++) {
        bitset<10> b(tmp);
        vector<bool> S(N, 0);
        vector<bool> on(M, 0);
        for (int i = 0; i < N; i++) {
            if (b.test(i)) S[i] = 1;
        }

        for (int i = 0; i < M; i++) {
            int cnt = 0;
            for (auto s : L[i]) {
                if (S[s]) cnt++;
            }

            if (cnt % 2 == P[i]) on[i] = 1;
        }

        bool flag = true;
        for (int i = 0; i < M; i++) {
            if (on[i] == 0) flag = false;
        }

        if (flag) ans++;
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
const int yuzu=3e5;
typedef ll fuko[yuzu|10];
fuko a,dp_l,dp_r;
int n=read();

priority_queue<ll,vector<ll>,greater<ll> > xiao;
priority_queue<ll> da;

void doleft(){
int i;ll sum=0;
for (i=1;i<=n*3;++i){
  xiao.push(a[i]);
  sum+=a[i];
  dp_l[i]=sum;
  if (xiao.size()>n){
    sum-=xiao.top();
    xiao.pop();
    dp_l[i]=sum;
    }
  }
}

void doright(){
int i;ll sum=0;
for (i=n*3;i;--i){
  da.push(a[i]);
  sum+=a[i];
  dp_r[i]=sum;
  if (da.size()>n){
    sum-=da.top();
    da.pop();
    dp_r[i]=sum;
    }
  }
}

int main(){
int i;
for (i=1;i<=n*3;++i) read(a[i]);
doleft(),doright();
ll ans=-1e17;
for (i=n;i<=(n<<1);++i) ans=max(dp_l[i]-dp_r[i+1],ans);
write(ans);
}

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

#define ll long long
#define mx  3000005
#define mod 1000000007
#define lim 100

using namespace std;


int main() {
	ios_base ::sync_with_stdio(false);
	int n;cin>>n;

	int a[n+5];

	for(int i=0;i<n;i++)cin>>a[i];

	int cnt=0;

	for(int i=1;i<n;i++)
	{
		if(a[i-1]==a[i])
		{
			cnt++;i++;
		}
	}

	cout<<cnt<<"\n";

     return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+5;
signed main(){
	int n;cin>>n;int sb[200005];
	int num=0;memset(sb,0,sizeof(sb));
		for(int j=1;j<=150;j++){
			for(int z=1;z<=150;z++){
				for(int y=1;y<=150;y++){int t=pow(j,2)+pow(z,2)+pow(y,2)+j*z+j*y+z*y;
					sb[t]++;
				}
			}
		}
		for(int i=1;i<=n;i++)cout<<sb[i]<<'\n';
}

Measured memory_bytes: 5080
#include "bits/stdc++.h"
using namespace std;
 
// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
 
 
/*
--------------------------------------------
 
	type
 
--------------------------------------------
*/
using LL = long long;
using ULL = unsigned long long;
//using pair<T1, T2> = p12;
 
/*
--------------------------------------------
 
	container
 
--------------------------------------------
*/
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
 
/*
--------------------------------------------
 
	repetition
 
--------------------------------------------
*/
#define MAX(a,b) (a>b)?a:b
#define MIN(a,b) (a>b)?b:a
#define REP(n) for(int i=0; i<n; i++)
#define REPj(n) for(int j=0; j<n; j++)
#define REPinit(a,n) for(int i=a; i<n; i++)
#define REPinitj(a,n) for(int j=a; j<n; j++)
 
//algorithm
//#define SORT(c) sort((c).begin(),(c).end())
 
/*
--------------------------------------------
 
	constant
 
--------------------------------------------
*/
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
/*
 
	Optimizer
 
*/
//#pragma GCC optimize("Ofast")


/*
 
	Utility Algorithm
 
*/
template <typename T>
void swapAlgorithm(T& a, T& b) {
    T tmp = a;
    a = b;
    b = tmp;
}

LL euclideanAlgorithm(LL a, LL b) {
    LL a_tmp = a;
    LL b_tmp = b;

    if (a_tmp > b_tmp) {
        swapAlgorithm<LL>(a_tmp, b_tmp);
    }

    LL r = a_tmp % b_tmp;
    while (r != 0) {
        a_tmp = b_tmp;
        b_tmp = r;
        r = a_tmp % b_tmp;
    }
    return b_tmp;    
}

LL getLCM(LL a, LL b) {
    return (a * b)/(euclideanAlgorithm(a, b));
}

/*
  Code
*/

double eauclidDistance(pair<double, double>& x1, pair<double, double>& x2) {
  return sqrt((x1.first - x2.first) * (x1.first - x2.first) + (x1.second - x2.second) * (x1.second - x2.second));
}

void swap(int& a, int& b) {
  int tmp;
  tmp = a;
  a = b;
  b = tmp;
}

int main(int argc, char const *argv[])
{
  string S;
  cin >> S;
  cout << S.replace(3,1,"8") << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
bool judge(vector<int>V){
    if(V[0]!=1)return false;
    for(int i=1;i<V.size();i++){
        if(V[i]!=V[i-1]+1)return false;
    }
    return true;
}
int main(){
    int n;
    while(scanf("%d",&n),n){
        vector<int>V(n);
        for(int i=0;i<n;i++){
            scanf("%d",&V[i]);
        }
        bool flag=true;
        for(int i=0;i<=10000;i++){
            if(judge(V)){
                printf("%d\n",i);
                flag=false;
                break;
            }
            vector<int>next;
            for(int i=0;i<V.size();i++){
                if(V[i]>1)next.push_back(V[i]-1);
            }
            next.push_back(V.size());
            V=next;
        }
        if(flag)puts("-1");
    }

    return 0;
}

Measured memory_bytes: 1092
/**
 *    author:  math2do
 *    created: 12.04.2020 17:34:24
**/

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    if ((i % 3 != 0) && (i % 5 != 0)) {
      sum += i;
    } 
  }
  cout << sum << endl; 
  return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);std::iostream::sync_with_stdio(0);cout<<std::fixed<<std::setprecision(10);cerr<<std::fixed<<std::setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}

const int N=1e7+1;
const int M=998244353;
int bp(int a,int pw){ 
    int r=1;
    for(;pw;(a*=a)%=M,pw/=2)if(pw&1)(r*=a)%=M;
    return r;
}
int inverse(int a){return bp(a%M,M-2);} 
int fc[N],ifc[N];
struct pcfc{pcfc(){
        fc[0]=1;
        for(int i=1;i<N;++i)fc[i]=(fc[i-1]*i)%M;
        ifc[N-1]=inverse(fc[N-1]);
        for(int i=N-2;i>=0;--i)ifc[i]=(ifc[i+1]*(i+1))%M;
}}pcfc;
int C(int n,int k){
    if(k<0||k>n)return 0;
    return(((fc[n]*ifc[k])%M)*ifc[n-k])%M;
}
int p[N];


int32_t main(){
    int n;
    cin>>n;
    p[0]=1;
    for(int i=1;i<=n;++i)p[i]=(p[i-1]*2)%M;
    int bad=0;
    for(int a=n/2+1;a<=n;++a){
        bad+=C(n,a)*p[n-a]%M;
    }
    bad%=M;
    int p3=1;
    for(int i=1;i<=n;++i)(p3*=3)%=M;
    int ans=p3-bad*2;
    ans%=M;
    ans+=M;
    ans%=M;
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 234624
A = int(input())
B = int(input())
C = int(input())
X = int(input())

l = []
for i in range(0, A + 1):
    for j in range(0, B + 1):
        for k in range(0, C + 1):
            l.append([i, j, k])

ans = 0
for i in range(len(l)):
    if 500 * l[i][0] + 100 * l[i][1] + 50 * l[i][2] == X:
        ans += 1

print(ans)


Measured memory_bytes: 16500
X, K, D = map(int, input().split())

num_min_move = abs(X//D)
tmp = abs(X%D)

if num_min_move == K:
  print(tmp)
elif num_min_move > K:
  print(abs(X)-K*D)
else:
  out = tmp
  if (K - num_min_move) % 2 == 1:
    print(abs(tmp-D))
  else:
    print(tmp)

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

l = make_divisors(n)

if len(l)%2==0:
    p = len(l)//2 - 1
    print(l[p] + l[p+1] - 2)
else:
    p = len(l)//2
    print(l[p] + l[p] -2)

Measured memory_bytes: 3268
// user:halahen
#include<bits/stdc++.h>
using namespace std;
const int maxn=100010;
int i,j,k;
int n;
int a[maxn],ha[maxn],t1,t2,t3,t4,t5,t6;
int read(){
	int tot=0,fh=1;
	char c=getchar();
	while ((c<'0')||(c>'9')){ if(c=='-') fh=-1; c=getchar(); }
	while ((c>='0')&&(c<='9')){ tot=tot*10+c-'0'; c=getchar(); }
	return tot*fh;
}
int main(){
	n=read();
	for (i=1;i<=n;i++){
		a[i]=read();
	}
	t1=n; t3=n; t2=n; t4=n;
	for (i=2;i<=n;i=i+2){
		ha[a[i]]++;
	}
	for (i=0;i<maxn;i++){
		t1=min(t1,(n/2)-ha[i]);
		if (t3>t1){
			swap(t3,t1);
			t5=i;
		}
	}
	memset(ha,0,sizeof(ha));
	for (i=1;i<=n;i=i+2){
		ha[a[i]]++;
	}
	for (i=0;i<maxn;i++){
		t2=min(t2,(n/2)-ha[i]);
		if (t4>t2){
			swap(t4,t2);
			t6=i;
		}
	}
	if (t5!=t6) printf("%d\n",t3+t4);
	else{
		printf("%d\n",min(t1+t4,t3+t2));
	}
	return 0;
}

Measured memory_bytes: 1024
from collections import deque
n,m = map(int,input().split())
r = []
for _ in range(m):
    r.append(tuple(map(int,input().split())))
r = deque(sorted(r,key = lambda x:x[1]))
ans = 0
while len(r) > 0:
    _,y = r[0]
    ans += 1
    while len(r) > 0 and r[0][0] < y:
        r.popleft()
print(ans)

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

int main(){
  ll n;
  cin>>n;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      vec.push_back(i);
      if(i!=n/i)vec.push_back(n/i);
    }
  }
  ll ans=0;
  for(int i=0;i<vec.size();i++){
    ll m=vec[i]-1;
    if(m>0&&n/m==n%m){
      ans+=m;
    }
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main() {
    int N, sum = 0, max = 0;
    cin >> N;
    for (int i = 0, l; i < N; i++) {
        cin >> l;
        sum += l;
        if (l > max) max = l;
    }
    cout << (max < sum - max ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var P = cin.ReadIntArray(N);
            var Min =P[0];
            var answer = 0;
            for(int i = 0; i < N; i++)
            {
                if (Min >= P[i])
                {
                    answer++;
                    Min = P[i];
                }
            }
            WriteLine(answer);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 35468
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  int n,k;cin>>n>>k;
  cout<<(n*500>=k?"Yes":"No");
}

Measured memory_bytes: 256
fn main() {
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: i32 = s.next().unwrap().parse().unwrap();
	let k: i32 = s.next().unwrap().parse().unwrap();
	println!("{}", if n % k == 0 { 0 } else { 1 });
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<cstdlib>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<vector>
#include<cmath>
#include<string>
#include<bitset>
#define lmid l,mid,rt<<1
#define rmid mid+1,r,rt<<1|1
#define ll long long
using namespace std;
char s[55][55];
int d[8][2] = {1, 0, 0, 1, -1, 0, 0, -1, 1, 1, 1, -1, -1, 1, -1, -1};
int main() {
     int n, m;
     scanf("%d%d", &n, &m);
     for (int i = 0; i < n; i++) {
          scanf("%s", s[i]);
          for (int j = 0; j < m; j++)
               if (s[i][j] == '.')s[i][j] = '0';
     }
     for (int i = 0; i < n; i++)
          for (int j = 0; j < m; j++) {
               if (s[i][j] != '#')continue;
               for (int k = 0; k < 8; k++) {
                    int x = i + d[k][0];
                    int y = j + d[k][1];
                    if (x >= 0 && x < n)
                         if (y >= 0 && y < m)
                              if (s[x][y] != '#')
                                   s[x][y] += 1;
               }
          }
     for (int i = 0; i < n; i++)
          printf("%s\n", s[i]);
     return 0;
}


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

namespace competitive_programming
{
    class Program
    {
        static void Main(string[] args)
        {
            var main = new Program();
            main.solve();
        }

        void solve()
        {
            long n = long.Parse(Console.ReadLine());
            long[] nums = Console.ReadLine().Split(' ').Select(val => long.Parse(val)).ToArray();

            var dic = new Dictionary<long, long>();

            foreach(var num in nums)
            {
                if (dic.ContainsKey(num))
                {
                    dic[num]++;
                }
                else
                {
                    dic.Add(num, 1);
                }
            }

            if (dic.Keys.Count() % 2 == 0) Console.WriteLine(dic.Keys.Count() - 1);
            else Console.WriteLine(dic.Keys.Count());
        }
    }

    struct Vector2
    {
        public Vector2(long x, long y)
        {
            this.x = x;
            this.y = y;
        }
        public long x;
        public long y;
    }

    struct Vector3
    {
        public int x;
        public int y;
        public int z;
    }
}


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

int cum[2][4000][4000];

int cumsum(int c, int lx, int rx, int ly, int ry){
    return cum[c][ry][rx]-(ly!=0?cum[c][ly-1][rx]:0)-(lx!=0?cum[c][ry][lx-1]:0)+((lx&&ly)?cum[c][ly-1][lx-1]:0);
}


int main(){
    int N,K;
    cin>>N>>K;
    for(int i=0;i<N;i++){
        int x,y;
        cin>>x>>y;
        char c;
        cin>>c;
        x%=2*K;y%=2*K;
        cum[c=='B'][y][x]++;
        cum[c=='B'][y][x+2*K]++;
        cum[c=='B'][y+2*K][x]++;
        cum[c=='B'][y+2*K][x+2*K]++;
    }
    for(int i=0;i<4*K;i++){
        for(int j=1;j<4*K;j++){
            cum[0][i][j]+=cum[0][i][j-1];
            cum[1][i][j]+=cum[1][i][j-1];
        }
    }
    for(int i=0;i<4*K;i++){
        for(int j=1;j<4*K;j++){
            cum[0][j][i]+=cum[0][j-1][i];
            cum[1][j][i]+=cum[1][j-1][i];
        }
    }
    int ans = 0;
    for(int i=0;i<2*K;i++){
        for(int j=0;j<2*K;j++){
            // cout<<i<<' '<<j<<endl;
            int sum=0;
            sum+=cumsum(1,i,i+K-1,j,j+K-1);
            sum+=cumsum(0,i+K,i+2*K-1,j,j+K-1);
            sum+=cumsum(0,i,i+K-1,j+K,j+2*K-1);
            sum+=cumsum(1,i+K,i+2*K-1,j+K,j+2*K-1);
            ans=max(ans,sum);
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 125312
#!/usr/bin/env python3

import sys
input=sys.stdin.readline

mod=998244353

n,k=map(int,input().split())
arr=[list(map(int,input().split()))+[i] for i in range(k)]
dp=[0]*(n+1)
dp[1]=1
sums=[0]*k
for i in range(2,n+1):
  for l,r,j in arr:
    if l>i:
      continue
    elif l<=i<=r:
      sums[j]+=dp[i-l]
    else:
      sums[j]-=dp[i-r-1]
      sums[j]+=dp[i-l]
    sums[j]%=mod
  for j in range(k):
    dp[i]+=sums[j]
print(dp[n]%mod)

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

int main () 
{
    int W, H, x, y, r;
    
    std::cin >> W >> H >> x >> y >> r;
    
    if (x-r < 0 || x+r > W)
    {
        std::cout << "No" << std::endl;
    }
    else if (y-r < 0 || y+r > H)
    {
        std::cout << "No" << std::endl;
    }
    else std::cout << "Yes" << std::endl;
    
    return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <bitset>
#include <unordered_map>
#include <tuple>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <sys/time.h>

using namespace std;

void solve(long long N, string S){
  vector<long long> c(26, 0);
  for (int i = 0; i < S.size(); i++) {
    c[S[i] - 'a']++;
  }
  long long ret = 1;
  for (auto&& x : c) {
    ret *= x+1;
    ret %= 1000000007;
  }
  ret -= 1;
  std::cout << ret << std::endl;
}

int main(){
  string S;
  long long N;
  scanf("%lld",&N);
  cin >> S;
  solve(N, S);
  return 0;
}


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

#define EB emplace_back
#define int long long
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define rt return 0;
using namespace std;

int32_t main(){
	IOS;
	int tt = 1; 
	//cin >> tt;
	string Y = "YES";
	string N = "NO";
	string yy = "Yes";
	string nn = "No";
	while(tt--){
		
		
		
		
		
		//rt;
		
		int a; cin >> a;
		
		if(a >= 30){
			cout << yy;
		}
		else{
			cout << nn;
		}	
	}
	return 0;
}


Measured memory_bytes: 3608
import java.io.*;
import java.util.Scanner;

public class Main {
  
  public static void main(String[] args){
    
    try {
      
      //標準入力受け取り
      Scanner scan = new Scanner(System.in);
      double page = Integer.parseInt(scan.next());
      
      //用紙算出
      System.out.println((int) Math.ceil(page / 2));
      
    } catch (Exception e) {
      
      System.out.println("error");

    }
  }
}

Measured memory_bytes: 23892