akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

int h, w, dotcount = 0;
char stage[52][52];
int dist[52][52];

void bfs(int y, int x){
	for (int i = 0; i < 52; i++){
		for (int j = 0; j < 52; j++){
			dist[i][j] = -1;
		}
	}
	int dir1[4] = {1, 0, -1, 0};
	int dir2[4] = {0, 1, 0, -1};
	dist[y][x] = 0;
	queue <pair<int, int> > que;
	que.push(make_pair(y, x));
	while(!que.empty()){
		pair<int, int> p = que.front();
		que.pop();
		for (int i = 0; i < 4; i++){
			int nexty = p.first + dir1[i];
			int nextx = p.second + dir2[i];
			if (stage[nexty][nextx] == '.' && dist[nexty][nextx] == -1){
				dist[nexty][nextx] = dist[p.first][p.second] + 1;
				que.push(make_pair(nexty, nextx));
			}
		}
	}
	return;
}


int main(){
	cin >> h >> w;
	for (int i = 0; i < 52; i++){
		for (int j = 0; j < 52; j++){
			stage[i][j] = '#';
		}
	}
	for (int i = 1; i <= h; i++){
		for (int j = 1; j <= w; j++){
			cin >> stage[i][j];
			if (stage[i][j] == '.'){
				dotcount++;
			}
		}
	}
	if (stage[h][w] == '#'){
		cout << -1 << endl;
		return 0;
	}
	bfs(1, 1);
	if (dist[h][w] == -1){
		cout << -1 << endl;
	}else{
		cout << dotcount - dist[h][w] - 1 << endl;
	}
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define MAX 1e6
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

int main() 
{
    ll k;
    cin>>k;
    queue<ll> q;
    REP(i,1,10){
    	q.push(i);
    }
    ll ct = 0;
    ll p;
    while(ct < k){
    	p = q.front();
    	ct++;
    	q.pop();
    	ll rem = p % 10;
    	if(rem - 1 >= 0)
    		q.push(p*10 + rem - 1);
    	q.push(p*10 + rem);
    	if(rem + 1 <= 9)
    		q.push(p*10 + rem + 1);
    }
    cout<<p<<endl;
    return 0;
}



Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,m,w=0,ans=0; cin>>n>>m;
    map<int,int> se;
    rep(i,m){
        int p; string s; cin>>p>>s;
        if(s=="AC"){
            if(se.count(p)){
                if(se[p]!=-1){
                    w+=se[p]; ans++;
                }
            }
            else ans++;
            se[p]=-1;
        }
        else{
            if(!(se.count(p))){
                se[p]=1;
            }
            else{
                if(se[p]!=-1) se[p]++;
            }
        }
    }
    cout<<ans<<" "<<w<<endl;
}

Measured memory_bytes: 8216
#include <bits/stdc++.h>
#define ll long long
#define mod7 1000000007
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define queries ll t;cin>>t;while(t--)
using namespace std;


int main(){

    fast
	
	ll n;
	cin>>n;
	vector<ll>v(n);
	ll flag=0;
	for(ll i=0;i<n;i++){
		cin>>v[i];
		if(v[i]%2==0){
			if(v[i]%3==0 || v[i]%5==0)
				continue;
			else{
				flag=1;
				break;
			}
		}
	}
	if(flag){
		cout<<"DENIED";
	}else{
		cout<<"APPROVED";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mxn 100005;
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);    
    int n; cin >> n;

    vector<int> b(n - 1);
    for (int i = 0; i < n - 1; i++) {
    	cin >> b[i];
    }

    vector<int> a(n);
    for (int i = 0; i < n - 1; i++) {
    	a[i] = b[i];
    }
    a[n - 1] = mxn;

    for (int i = 0; i < n - 1; i++) {
    	a[i + 1] = min(a[i + 1], b[i]);
    }

    int sum = 0;

    for (int i = 0; i < n; i++) {
    	sum += a[i];
    }
    cout << sum << "\n";

    return 0;
}

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

const int maxn=3000;

double dp[maxn][maxn];

signed main(){
	int n;cin>>n;
	vector<double>p(n);
	for(auto&& u:p)cin>>u;
	fill(dp[0],dp[maxn],0.0);
	dp[0][0]=1.0;
	rep(i,n)rep(j,n){
		dp[i+1][j]+=dp[i][j]*(1-p[i]);
		dp[i+1][j+1]+=dp[i][j]*(p[i]);
	}
	double ret=0.0;
	for(int i=n/2+1;i<=n;i++)ret+=dp[n][i];
	cout<<setprecision(10)  <<ret<<endl;
}

Measured memory_bytes: 70656
C = []
for i in range(3):
  C.append([int(i) for i in input().split()])

ans = "Yes"

A = [0] * 3
B = C[0]

A[1] = C[1][0] - B[0]
A[2] = C[2][0] - B[0]

for i in range(3):
  for j in range(3):
    if C[i][j] != A[i] + B[j]:
      ans = "No"
      break

print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	bool num[50001] = {0};
	for(int i=2; i<50001; i++){
		if(!num[i]){
			for(int j=i*2; j<50001; j+=i){num[j] = true;}
		}
	}
	for(;;){
		int n,sum = 0;
		cin >>n;
		if(n == 0){break;}
		for(int i=2; i<=n/2; i++){
			if(!num[i] && !num[n-i]){sum++;}
		}
		cout <<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
import sys
from operator import itemgetter
import collections
import math

def r(n, m, a):
    s = n - sum(a)
    if s < 0:
        s = -1
    return s


def main():
    input = sys.stdin.readline
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    print(r(n, m, a))

    
if __name__ == '__main__':
    main()


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

int main(void){
  int N;cin>>N;
  vector<string> w;
  w.resize(N);
  for(int q = 0;q < N;q++)cin>>w[q];

  int count = 0;
  bool jud = true;

  for(int i = 0;i < N - 1;i++){
    if(w[i][w[i].length()-1] == w[i + 1][0])count++;
  }

  for(int t = 0;t < N - 1;t++){
    for(int k = t + 1;k <= N - 1;k++){
      if(w[t] == w[k])jud = false;
    }
  }

  if(jud && count == N - 1)cout<<"Yes";
  else cout<<"No";
}


Measured memory_bytes: 256
// AOJ DSL_2_C Range Search (kD Tree)
// 2018.5.17 bal4u

#include <stdio.h>
#include <stdlib.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in()
{
	int n = 0, c = gc();
	if (c == '-') { c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void out(int n)
{
	int i;
	char ob[20];

	if (!n) pc('0');
	else {
		i = 0; while (n) ob[i++] = n%10 + '0', n/=10;
		while (i--) pc(ob[i]);
	}
	pc('\n');
}

#define MAX_N  500005

typedef struct { int id; int p[2], child[2], min[2], max[2]; } NODE;
NODE kdTree[MAX_N];

int root;       // root of kd tree
int ans[102], len;
int s[2], t[2];

int mkKdTree(int l, int r, int k)
{
	int i, j, c;
	int m, x;
	NODE t;

	m = (l+r)>>1;
	t = kdTree[m], x = t.p[k], kdTree[m] = kdTree[r], kdTree[r] = t;
	i = l-1;
	for (j = l; j < r; j++) {
		if (kdTree[j].p[k] <= x) {
			if (++i != j) t = kdTree[++i], kdTree[i] = kdTree[j], kdTree[j] = t;
		}
	}
	t = kdTree[r], kdTree[r] = kdTree[m], kdTree[m] = t;

	kdTree[m].child[0] = (l == m)? 0: mkKdTree(l, m-1, k);
	kdTree[m].child[1] = (m == r)? 0: mkKdTree(m+1, r, k);

	for (i = 0; i < 2; i++) {
		kdTree[m].min[i] = kdTree[m].max[i] = kdTree[m].p[i];
		for (j = 0; j < 2; j++) if (c = kdTree[m].child[j]) {
			if (kdTree[m].min[i] > kdTree[c].min[i]) kdTree[m].min[i] = kdTree[c].min[i];
			if (kdTree[m].max[i] < kdTree[c].max[i]) kdTree[m].max[i] = kdTree[c].max[i];
		}
	}
	return m;
}

void printRange(int node)
{
	int c;

	if (kdTree[node].p[0] >= s[0] && kdTree[node].p[0] <= t[0] &&
		kdTree[node].p[1] >= s[1] && kdTree[node].p[1] <= t[1]) {
		ans[len++] = kdTree[node].id;
	}

	if ((c = kdTree[node].child[0]) &&
		kdTree[c].min[0] <= t[0] && s[0] <= kdTree[c].max[0] &&
		kdTree[c].min[1] <= t[1] && s[1] <= kdTree[c].max[1])
			printRange(c);

	if ((c = kdTree[node].child[1]) &&
		kdTree[c].min[0] <= t[0] && s[0] <= kdTree[c].max[0] &&
		kdTree[c].min[1] <= t[1] && s[1] <= kdTree[c].max[1])
			printRange(c);
}

int kdcmp(NODE *a, NODE *b) { if (a->p[0]-b->p[0]) return a->p[0]-b->p[0]; return a->p[1]-b->p[1]; }
int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; }

int main()
{
	int n, q, i;

	n = in();
	for (i = 1; i <= n; i++) {
		kdTree[i].id = i-1, kdTree[i].p[0] = in(), kdTree[i].p[1] = in();
	}
	qsort(kdTree+1, n, sizeof(NODE), kdcmp);
	root = mkKdTree(1, n, 0);

	q = in();
	while (q--) {
		s[0] = in(), t[0] = in();
		s[1] = in(), t[1] = in();
		len = 0;
		printRange(root);
		qsort(ans, len, sizeof(int), cmp);
		for (i = 0; i < len; i++) out(ans[i]);
		pc('\n');
	}
}


Measured memory_bytes: 26100
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const K = parseInt(arg[0].split(" ")[1]);
    
    const S = arg[1].split("").map(n=>parseInt(n));
    
    // 奇数番目に連続する1の数、偶数版目に連続する0の数 の配列を用意
    let list = [];
    
    if(S.indexOf(0) === -1) {
        console.log(N);
        return;
    }
    
    if(S.indexOf(1) === -1) {
        console.log(N);
        return;
    }
    
    if(S[0] !== 1) {
        list.push(0);
    }
    
    let streak = 0;
    
    for(let i=1; i<S.length; i++) {
        if(S[i] === S[i - 1]) {
            streak++;
        } else {
            streak++;
            list.push(streak);
            streak = 0;
        }
    }
    
    streak++;
    list.push(streak);

    
    if(S[S.length - 1] !== 1) {
        list.push(0);
    }
    
    // 集計
    let temp = 0;
    let answer = 0;
    
    
    // しゃくとり
    
    if(K + K > list.length) {
        
        answer = list.reduce((m,n)=>m+n)
    
    } else {
        
        // 累積和
        let cumulativeSum = [list[0]];
        
        for(let i=1; i<list.length; i++) {
            cumulativeSum[i] = cumulativeSum[i-1] + list[i];
        }
        
        // console.log(cumulativeSum)
        // console.log(list);
        
        for(let left=0; left<list.length - (K + K); left += 2) {
            let sum = cumulativeSum[left + K + K];
            let minus = left - 1 > 0 ? cumulativeSum[left - 1] : 0;

            
            // console.log("sum:" + sum)
            answer = Math.max(sum - minus, answer);
        }
        
    }

    
    answer = Math.max(answer, temp);
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FScanner sc = new FScanner();
		int N = sc.nextInt();
		int[] ary = new int[N];
		for (int i = 0; i < N; i++) {
			ary[i] = sc.nextInt();
		}
		int[] collect = new int[N];
		for (int i = N - 1; i >= 0; i--) {
			if (N / (i + 1) == 1) {
				collect[i] = ary[i];
			} else {
				int sum = 0;
				int syou = N / (i + 1);
				int f = (i + 1) * syou;
				while (syou > 0) {
					sum += collect[f - 1];
					f -= (i + 1);
					syou -= 1;
				}
				sum = sum % 2;
				if (ary[i] == sum) {
					collect[i] = 0;
				} else {
					collect[i] = 1;
				}
			}
		}
		int sum2 = 0;
		for (int i = 0; i < N; i++) {
			sum2 += collect[i];
		}
		sum2 %= 2;
		if (sum2 != ary[0]) {
			System.out.println(-1);
			return;
		}
		int kosu = 0;
		for (int i = 0; i < N; i++) {
			if (collect[i] == 1) {
				kosu++;
			}
		}
		System.out.println(kosu);
		boolean fFlg = false;
		for (int i = 0; i < N; i++) {
			if (collect[i] == 1) {
				if (fFlg) {
					System.out.print(" ");
				}
				fFlg = true;
				System.out.print(i + 1);
			}
		}
	}

}

class FScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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

Measured memory_bytes: 51072
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fi first
#define se second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>
 
using std::cin;
using std::cout;
using std::endl;
 
typedef long long ll;
typedef unsigned long long ull;
 
const int N = 100000 + 5;
const int M = 1000 + 5;
const int K = 1e7 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int LOG = 40;
const ull BASE = 19260817;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };
const double PI = acos(-1);

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
 
template<class T>
inline T readT() {
    T res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}
#define read readT<int>

int n;

int main() {
    String s, t;
    int n;
    bool flag = false;
    cin >> s >> t;
    n = s.length();
    s += s;
    // cout << s << endl;
    for (int i = 0; i < n; i++) {
        if (s.substr(i, n) == t) flag = true;
    }
    if (flag) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e15;
using Graph = vector<vector<int>>;

signed main() {
  int A;
  cin >> A;
  cout << A+A*A+A*A*A << endl;

}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int A = reader.nextInt();
		int B = reader.nextInt();
		int K = reader.nextInt();
		for (int i = A; i <= B; i++) {
			if ((Math.abs(A - i) < K) || (Math.abs(B - i) < K)) {
				System.out.println(i);
			}
		}
		reader.close();
	}
}



Measured memory_bytes: 23252
import sys
input = sys.stdin.readline
n = int(input())
ab = [list(map(int, input().split(' '))) for i in range(n-1)]
graph = [[] for i in range(n+1)]
parent = [0 for i in range(n+1)]
Q,K = map(int, input().split(' '))
root = K
d = 0
stack = [root]
order = []
for a,b,e in ab:
    graph[a].append(b)
    graph[b].append(a)
while stack:
    x = stack.pop()
    order.append(x)
    for y in graph[x]:
        if parent[x] == y:
            continue
        parent[y] = x
        stack.append(y)
dist = [0 for i in range(n+1)]
for a,b,e in ab:
    if parent[a] == b:
        dist[a] = e
    else:
        dist[b] = e
visited = [0 for i in range(n+1)]
visited[root] = 1
ans = [0 for i in range(n+1)]
for i in order:
    if i == root:
        continue
    ans[i] += dist[i]
    if visited[parent[i]] == 1:
        ans[i] += ans[parent[i]]
        visited[i] = 1
for i in range(Q):
    s,t = map(int, input().split(' '))
    print(ans[s]+ans[t])

Measured memory_bytes: 47288
A,B = input().split()
A = A[::-1]
B = str(B[0]+B[2]+B[3])[::-1]
ans = [0]*20
for i in range(len(B)):
    for j in range(i,len(A)+i):
        ans[j] += int(A[j-i])*int(B[i])
for i in range(19):
    ans[i+1] += ans[i]//10
    ans[i] = ans[i]%10
ans = ans[2:]
ans = "".join([str(a) for a in ans])[::-1]
print(int(ans))

Measured memory_bytes: 9108
N=int(input())
A=list(map(int,input().split()))
ans=0
for i in range(N-1):
  if A[i]>A[i+1]:
    dif=A[i]-A[i+1]
    ans+=dif
    A[i+1]+=dif
  else:
    continue
print(ans)

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

int ten[2222][2222];
int tatehenn[2222][2222];
int yokohenn[2222][2222];

int main(){
	
	int n,m,q;cin >> n >> m >> q;
	
	for(int i = 1; i <= n;i++){
		string moziretu;cin >> moziretu;
		for(int j = 1;j <= m;j++){
			if(moziretu[j-1] == '1')ten[i][j] = 1; 
		}
	}
	
	for(int i = 1; i <= n;i++){
		for(int j = 1;j <= m;j++){
			if(ten[i][j]){
				tatehenn[i][j] = ten[i-1][j];
				yokohenn[i][j] = ten[i][j-1];
			}
		}
	}
	
	for(int i = 1; i <= n;i++){
		for(int j = 1;j <= m;j++){
			ten[i][j+1] += ten[i][j];
			tatehenn[i][j+1] += tatehenn[i][j];
			yokohenn[i][j+1] += yokohenn[i][j];
		}
	}
	
	for(int i = 1; i <= n;i++){
		for(int j = 1;j <= m;j++){
			ten[i+1][j] += ten[i][j];
			tatehenn[i+1][j] += tatehenn[i][j];
			yokohenn[i+1][j] += yokohenn[i][j];
		}
	}
		
	REP(i,q){
		int neko, ni, nari, tai;
		cin >> neko >> ni >> nari >> tai;
		int ten_no_kazu = ten[nari][tai] - ten[neko-1][tai] - ten[nari][ni-1] + ten[neko-1][ni-1];
		int tatehen_no_kazu = tatehenn[nari][tai] - tatehenn[neko][tai] - tatehenn[nari][ni-1] + tatehenn[neko][ni-1];
		int yokohen_no_kazu = yokohenn[nari][tai] - yokohenn[neko-1][tai] - yokohenn[nari][ni] + yokohenn[neko-1][ni];
		int hen_no_kazu = tatehen_no_kazu + yokohen_no_kazu;
		cout << ten_no_kazu - hen_no_kazu << endl;
	}

	return 0;
}


Measured memory_bytes: 59136
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <limits>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

#define N_MAX 400200

int bit[N_MAX + 1];

int sum(int i){
  int s = 0;
  while(i > 0){
    s += bit[i];
    i -= i & -i;
  }
  return s;
}

void add(int i, int x){
  while(i <= N_MAX){
    bit[i] += x;
    i += i & -i;
  }
}

int main() {
  ll n,k;
  cin>>n>>k;
  vector<ll> v; 
  rep(i,0,n){
    ll a;
    cin>>a;
    v.pb(a);
  }
  vector<ll> v1;
  ll all = 0;
  v1.pb(0);
  rep(i,0,v.sz){
    all += v[i];
    v1.pb(all-(k*(i+1)));
  }
  vector<ll> v2 = v1;
  sort(all(v2));
  map<ll,ll> mi;
  ll index = 1;
  rep(i,0,v2.sz){
    if(mi[v2[i]]==0){
      mi[v2[i]] = index;
      index++;
    }
  }
  ll ans = 0;
  clr(bit,0);
  rep(i,0,v1.sz){
    ans += sum(mi[v1[i]]);
    add(mi[v1[i]],1);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 19056
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
n = ni()
if n==1:
    print(1)
    exit()
xy = []
for i in range(n):
    xy.append(tma())
co = collections.Counter()

for i in range(n):
    for j in range(n):
        if i==j:
            continue
        x1,y1 = xy[i]
        x2,y2 = xy[j]
        co[(x2-x1,y2-y1)] +=1

ans = 10**9
for num in co.values():
    ans = min(ans,n-num)
print(ans)


Measured memory_bytes: 9648
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
struct edge{int to,cost;};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=MOD;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%MOD;
    int memo=modpow(a,b/2);
    return memo*memo%MOD;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int inv(int x){
    x=modpow(x,MOD-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
double dist(double ax,double ay,double bx,double by){
    return sqrt((bx-ax)*(bx-ax)+(ay-by)*(ay-by));
}

signed main(){
    int n,m;
    cin>>n>>m;
    cout<<n*m<<endl;
    return 0;
}



Measured memory_bytes: 3120
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: chars
    }
    let n = &s[1..(s.len()-1)].len();
    println!("{}{}{}", s[0],n,s[s.len()-1]);
}


Measured memory_bytes: 4352
#ifdef OJ_MISC_OFFLINE

#include "prolog.h"

#else
#define PRINT
#define LCERR
#endif

#include <algorithm>
#include <array>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

namespace {

using namespace std;

class Solution {
public:
    int remainer_minimization_2019(int L, int R) {
        vector<char> avail(2019, false);
        for (int i = L; i <= R; ++i) {
            if (i % 2019 == 0) return 0; // will trigger for any range longer than 2019
        }

        for (int i = L; i <= R; ++i) {
            avail[i % 2019] = true;
        }
        int min_remainder = 2019;
        for (int i = 0; i < 2019; ++i) {
            for (int j = i + 1; j < 2019; ++j) {
                if (avail[i] && avail[j]) {
                    min_remainder = min(min_remainder, (i * j) % 2019);
                }
            }
        }
        return min_remainder;
    }

private:

};

int solve() {
    Solution solution;
    // handle IO here
    int L, R;
    cin >> L >> R;
    cout << solution.remainer_minimization_2019(L, R) << endl;
    return 0;
}

} // anonymous namespace

#ifdef OJ_MISC_OFFLINE

#include "epilog.h"

#else

int main() {
    return solve();
}

#endif


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>

using namespace std;

template<class T>
void splitstr(const string &s, vector<T> &out)
{
    istringstream in(s);
    out.clear();
    copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}


int main()
{
	vector< vector<int> > a;
	string s;
	while(cin>>s){
		a.push_back(vector<int>());
		replace(s.begin(),s.end(),',',' ');
		splitstr(s,a.back());
	}
	for (int i = 0; i < ((int)a.size() - 1) /2 ; i++){
		for (int j = 0; j <= i + 1; j++){
			if(j == 0) a[i+1][j] += a[i][j];
			else if(j == i+1) a[i+1][j] += a[i][j-1];
			else a[i+1][j] += max(a[i][j],a[i][j-1]);
		}
	}
	for (int i = ((int)a.size() - 1) /2 ; i < a.size() - 1; i++){
		for (int j = 0; j < (int)a[i].size() - 1; j++){
			a[i+1][j] += max(a[i][j],a[i][j+1]);
		}
	}

	cout << a.back()[0] << endl;

	return 0;
}

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

int main(){
    long long int h;
    cin >> h;

    long long int ans = 0;
    long long int times = 1;
    while(h > 0){
        h /= 2;
        ans += times;
        times *= 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
using ll = 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>
struct WeightedUnionFind{
  int n;
  T d;
  vector<int> r, p;
  vector<T> ws;
  WeightedUnionFind(){}
  WeightedUnionFind(int sz, T d_):
    n(sz), d(d_), r(n, 1), p(n), ws(n, d){iota(p.begin(), p.end(), 0);}

  int find(int x){
    if(x == p[x]){
      return x;
    }else{
      int t = find(p[x]);
      ws[x] += ws[ p[x] ];
      return p[x] = t;
    }
  }

  T weight(int x){
    find(x);
    return ws[x];
  }

  int same(int x,int y){
    return find(x) == find(y);
  }

  void unite(int x, int y, T w){
    w += weight(x);
    w -= weight(y);
    x = find(x); y = find(y);
    if(x == y) return;
    if(r[x] < r[y]) swap(x, y), w = -w;
    r[x] += r[y];
    p[y] = x;
    ws[y] = w;
  }

  T diff(int x,int y){
    return weight(y) - weight(x);
  }
};
  
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n;
  while(cin>>n,n){
    WeightedUnionFind<int> uf(n*2,0);
    int sz=0;
    map<string,int> idx;

    int flg=1;
    for(int i=0;i<n;i++){
      string a,b,c,d,e;
      cin>>a>>b>>c>>d>>e;
      if(!idx.count(b)) idx[b]=sz++;
      if(!idx.count(e)) idx[e]=sz++;

      int dif=stoi(d.substr(3));
      if(!uf.same(idx[b],idx[e])){
        uf.unite(idx[b],idx[e],dif);        
      }else{
        int act=uf.diff(idx[b],idx[e]);
        //cout<<act<<" "<<dif<<endl;
        flg&=(dif==act);
      }
    }
    cout<<(flg?"Yes":"No")<<endl;
  }
  
  return 0;
}



Measured memory_bytes: 3216
/**
*    author:  yuya1234
*    created: 24.06.2020 15:29:49
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)

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

    ll a, b, x, ans = 0;
    cin >> a >> b >> x;

    if (a % x == 0)
        ans = b / x - a / x + 1;
    else
        ans = b / x - a / x;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
import sys
S  = input()
T  = input()

for ch in list("abcdefghijklmnopqrstuvwxyx"):
    tmp_s, tmp_t = "", ""
    for s, t in zip(S, T):
        if s == ch or t == ch:
            if tmp_s == "" and tmp_t == "":
                tmp_s, tmp_t = s, t
        
        if s == tmp_s: 
            if t != tmp_t:  
                print("No")
                sys.exit()
        if t == tmp_t: 
            if s != tmp_s:  
                print("No")
                sys.exit()
print("Yes")

Measured memory_bytes: 3632
import numpy as np

[H, W, M] = map(int, input().split())
colsum = np.zeros(W+1)
rowsum = np.zeros(H+1)
bombs = []
rowbombs = [set() for i in range(H+1)]
for i in range(M):
    [h, w] = map(int, input().split())
    rowsum[h] += 1
    colsum[w] += 1
    bombs.append([h, w])
    rowbombs[h].add(w)

maxcol = max(colsum)
maxrow = max(rowsum)

colchk = np.where(colsum==maxcol)
rowchk = np.where(rowsum==maxrow)

for i in range(len(rowchk[0])):
    for j in range(len(colchk[0])):
        if colchk[0][j] not in rowbombs[rowchk[0][i]]:
            print(int(max(colsum)+max(rowsum)))
            quit()

print(int(max(colsum)+max(rowsum))-1)


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

class Cmondai
{
    struct Connection
    {
        public List<int> list;
        public Connection(int index)
        {
            list = new List<int>();
        }
    }

    static void Main()
    {
        var nm = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var N = nm[0];
        var M = nm[1];
        var a = new int[M];
        var b = new int[M];
        for (int i = 0; i < M; ++i)
        {
            var ab = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
            a[i] = ab[0];
            b[i] = ab[1];
        }

        var ans = 0L;
        for (int i = 0; i < M; ++i)
        {
            var connection = new Connection[N];
            for (int j = 0; j < N; ++j) connection[j] = new Connection(j);
            for (int j = 0; j < M; ++j)
            {
                if (i == j) continue;
                connection[a[j] - 1].list.Add(b[j] - 1);
                connection[b[j] - 1].list.Add(a[j] - 1);
            }
            var hashSet = new HashSet<int>();
            Dfs(hashSet, connection, 0);
            if (hashSet.Count() != N) ans++;
        }
        Console.WriteLine(ans);
    }
    static void Dfs(HashSet<int> hashSet, Connection[] connection, int index)
    {
        hashSet.Add(index);
        foreach (var l in connection[index].list)
        {
            if (!hashSet.Contains(l)) Dfs(hashSet, connection, l);
        }
    }
}

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

int main() {

  int N;
  cin >> N;

  int tmp;
  for(int i = 0; i < N; i++){
    cin >> tmp;
    if(tmp % 2 == 0 && tmp % 3 != 0 && tmp % 5 != 0){
      cout << "DENIED" << endl;
      return 0;
    }
  }

  cout << "APPROVED" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long int

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C;
    cin >> A >> B >> C;
    if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0) {
        cout << "0" << endl;
    } else {
        cout << min(A*B, min(B*C, C*A)) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

int main() {
  int x, a, b;
  scanf("%d %d %d", &x, &a, &b);
  if (std::abs(x-a) < std::abs(x-b)) {
    puts("A");
  } else {
    puts("B");
  }

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch HAndV | diff HAndV.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address HAndV.cpp && ./a.out

/*

 7/5/2020

 5:04-

 */

const int MAX_N=10+1;
string A[MAX_N];
int N,M,K;

bool ith(int mask, int i) { return (mask>>i)&1; }
void solve() {
  int res=0;
  REP(mask, 1<<(N+M)) {
    vector<string> B(A,A+N);
    REP(i,N) if(ith(mask,i)) {
      REP(j,M) B[i][j]='R';
    }
    REP(j,M) if(ith(mask,N+j)) {
      REP(i,N) B[i][j]='R';
    }
    int cnt=0;
    REP(i,N)REP(j,M)cnt+=(B[i][j]=='#');
    res+=cnt==K;
  }
  cout<<res<<endl;
}

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

  cin>>N>>M>>K;
  REP(i,N) cin>>A[i];
  solve();

  return 0;
}


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

int main(){
  int n,out=0,temp=0;;
  cin >> n;
  vector<int> v(n);
  for(int i=0;i<n;i++) cin >> v[i];
  sort(v.begin(),v.end());
  for(auto i:v){
    if(temp<i){
      temp=i;
      out++;
    }
  }
  cout << out << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(int argc, char const* argv[])
{
	int a, b, c;
	std::cin >> a >> b >> c;

	if (a < b) {
		if (b < c) {
			std::cout << "Yes" << std::endl;
		} else {
			std::cout << "No" << std::endl;
		}
	} else {
		std::cout << "No" << std::endl;
	}
	return 0;
}



Measured memory_bytes: 3132
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.regex;
import std.stdio;
import std.string;
import std.typecons;

int readint() { return readln.chomp.to!int; }
int[] readints() { return readln.split.map!(to!int).array; }

void main() {
    auto s = readln.chomp;
    auto m = matchFirst(s, r"([0-9])\1\1");
    // writeln(m.empty ? "No" : "Yes");
    writefln("%s", m.empty ? "No" : "Yes");
}

Measured memory_bytes: 256
import numpy as np

D=int(input())
C=np.array(list(map(int,input().split())))
last_day=np.array([-1 for _ in range(26)])
score=np.array([list(map(int,input().split())) for _ in range(D)])
output=[0 for _ in range(D)]

for day in range(D):
    today_point=C*(day-last_day)
    S_today=sum(today_point)
    for k in range(26):
        today_point[k]=score[day][k]-S_today+today_point[k]
 
    if day!=D-1:
        max_score=-1*float("inf")
        for k in range(26):
            nday_point=C*((day+1)-last_day)
            S_nday=sum(nday_point)-C[k]*(day-last_day[k])
            
            for i in range(26):
                if k!=i:
                    nday_point[i]=score[day+1][i]-S_nday+nday_point[i]
                else:
                    nday_point[i]=score[day+1][i]-S_nday+C[i]
 
                if today_point[k]+nday_point[i]>max_score:
                    max_score=today_point[k]+nday_point[i]
                    idx=k
    else:
        idx=np.argmax(today_point)
 
    last_day[idx]=day
    output[day]=idx+1

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

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

using namespace std;

int q_sort(int d[],int left,int right){
	if(left >= right) return 0;
	int pipot = d[(left+right)/2], l = left, r = right, tmp;
	while(l<r){
		while(d[l] < pipot) l++;
		while(d[r] > pipot) r--;
		if( l <=  r){
			tmp = d[l];
			d[l] = d[r];
			d[r] = tmp;
			l++;
			r--;
		}
	}
	q_sort(d,left,r);
	q_sort(d,l,right);
}

int main(void)
{
	int n;
	cin >> n;
	int a[n],i;
	for(i = 0; i < n ; i++) cin>>a[i];
	q_sort(a,0,n-1);
	int j,w;
	w = 2;
	for(i = 0; i < n-1; i++){
		if(a[i] == a[i+1]){
			printf("NO\n");
			return 0;
		}
	}
	
	printf("YES\n");
	
	return 0;
}




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

typedef long long ll;

int n, m;
vector<int> adjlist[100005], x, y, DP;
vector<bool> vis;

int dfs(int idx) {
    if(vis[idx]) return DP[idx];
    vis[idx] = 1;

    int retval = 0;

    for(int next : adjlist[idx]) {
        int val = dfs(next) + 1;
        retval = max(retval, val);
    }

    return DP[idx] = retval;
}

int main()
{
    scanf("%d %d", &n, &m);
    x.assign(m, 0);
    y.assign(m, 0);
    DP.assign(n, 0);
    vis.assign(n, 0);

    for(int i = 0; i < m; i++) {
        scanf("%d %d", &x[i], &y[i]);
        x[i]--;
        y[i]--;
        adjlist[x[i]].push_back(y[i]);
    }

    int sol = 0;
    for(int i = 0; i < n; i++) {
        if(!vis[i]) {
            sol = max(sol, dfs(i));
        }
    }

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

    return 0;
}


Measured memory_bytes: 8960
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt(); long k = sc.nextLong();
        boolean [] vis = new boolean[n];
        long [] c = new long[n];
        int [] p = new int[n];
        for (int i = 0; i <n; i++) {
            p[i] = sc.nextInt() - 1;
        }
        for (int i = 0; i < n; i++) {
            c[i] = sc.nextLong();
        }
        long ans = Long.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            if (vis[i]) continue;
            ArrayList<Integer> cycle = new ArrayList<>();
            cycle.add(i); vis[i] = true; int cur = p[i]; int start = i;
            while (cur != start) {
                vis[cur] = true;
                cycle.add(cur);
                cur = p[cur];
            }
            int len = cycle.size();
            long total = 0;
            for (int j = 0; j < cycle.size(); j++) total += c[cycle.get(j)];
            long move = Math.min(len, k);
            for (int j = 0; j < cycle.size(); j++) {
                int v = cycle.get(j);
                int ct = 0; long cost = 0;
                while (ct < move) {
                    v = p[v];
                    cost += c[v];
                    ans = Math.max(ans, cost);
                    ++ct;
                    ans = Math.max(ans, cost + ((k - ct) / len) * total);
                }
                if (move == len) {

                }
            }
        }
        out.println(ans);
        out.close();
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

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

import sys


def LI():
    return list(map(int, sys.stdin.buffer.readline().split()))


def I():
    return int(sys.stdin.buffer.readline())


def LS():
    return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()


def S():
    return sys.stdin.buffer.readline().rstrip().decode('utf-8')


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


def SRL(n):
    return [list(S()) for i in range(n)]


def MSRL(n):
    return [[int(j) for j in list(S())] for i in range(n)]

# ----------------------------------------------------------------


def main():
    x = I()

    yen500 = x // 500
    yen5 = (x - 500 * yen500) // 5

    ans = yen500 * 1000 + yen5 * 5

    print(ans)


main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define N 200005
using namespace std;
template<class T>inline void Rd(T &x){
	x=0;char c=getchar();bool f=0;
	while(c<'0'||c>'9'){if(c=='-')f^=1;c=getchar();}
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+c-'0',c=getchar();
	if(f)x=-x;
}
int n;
struct Job{
	int a,b;
	bool operator < (const Job&_)const{
		return b<_.b;
	}
}A[N];

int main(){
	Rd(n);
	for(int i=1;i<=n;++i)Rd(A[i].a),Rd(A[i].b);
	sort(A+1,A+n+1);
	int las=0;
	for(int i=1;i<=n;++i){
		if(A[i].b-A[i].a<las){
			puts("No");
			return 0;
		}
		las+=A[i].a;
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 1792
n,t=map(int,input().split())
ct=[list(map(int,input().split()))for i in range(n)]
ct.sort()
a=False
for i in ct:
    if i[1]<=t:
        b=i[0]
        a=True
        break
if a:
    print(b)
else:
    print("TLE")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int a[200005];
int min1=0x3f3f3f3f;
int ans=0;
int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]<min1)
		{
			min1=a[i];
			ans++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for(int i = 0;i < (int)(n);i++)
int main() {
  const int dx[4]  = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
  int H, W, nh, nw, S = 0, c = 0;cin >> H >> W;
  P p;
  vector<string> v(H);
  queue<P> q, nq;
  rep(i, H) cin >> v[i];
  rep(i, H) rep(j, W) {
    if(v[i][j] == '#') q.push(P(i, j));
    else S++;
  }
  while(S > 0) {
    while(q.size() != 0) {
      p = q.front();q.pop();
      rep(i, 4) {
        nh = p.first + dx[i], nw = p.second + dy[i];
        if(0<=nh&&nh<H&&0<=nw&&nw<W&&v[nh][nw] == '.') {
          v[nh][nw] = '#';
          S--;
          nq.push(P(nh, nw));
        }
      }
    }
    swap(q, nq);
    c++;
  }
  cout << c << endl;
}

Measured memory_bytes: 13484
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<ctime>
#include<set>
#include<string>
using namespace std;
double eps=1e-9,pi=acos(-1.0);
struct Point
{
    double x,y;
    Point(){}
    Point(double _x,double _y){x=_x;y=_y;}
    double operator*(const Point &b){return x*b.y-y*b.x;}
    Point operator-(const Point &b){return Point(x-b.x,y-b.y);}
    Point operator+(const Point &b){return Point(x+b.x,y+b.y);}
    Point operator*(const double s){return Point(x*s,y*s);}
    double len(){return x*x+y*y;}
}p[30];
int n,Q;
double R;
Point turn(Point a,Point o,double al)
{
    double cs=cos(al),si=sin(al);
    Point ret;
    a=a-o;
    ret.x=a.x*cs-a.y*si;
    ret.y=a.x*si+a.y*cs;
    return o+ret;
}
double dis(Point a,Point b)
{
    return (a-b).len();
}
int main()
{
    while(scanf("%d%lf%d",&n,&R,&Q))
    {
        if(n==0&&Q==0)break;
        int o;
        R=R*R;
        for(int i=0;i<n;i++)
        {
            scanf("%lf%lf",&p[i].x,&p[i].y);
            if(fabs(p[i].len()-R)<eps)o=i;
        }
        //for(int i=1;i<n;i++)printf("%f\n",turn(p[i],p[0],0.0).len());
        for(int jj=1;jj<=Q;jj++)
        {
            double l=0,r=pi,m;
            int tim=90;
            while(tim--)
            {
                m=(l+r)*.5;
                int big=0;
                for(int i=0;i<n;i++)
                if(i!=o)
                {
                    if(turn(p[i],p[o],m).len()>R+eps)
                    {
                        big=1;
                        break;
                    }
                }
                //printf("m=%f big=%d\n",m,big);
                if(big)r=m;
                else l=m;
            }
            //printf("m=%f\n",m);
            Point tp=p[o];
            for(int i=0;i<n;i++)
            if(i!=o)p[i]=turn(p[i],p[o],l);
            //for(int i=0;i<n;i++)printf("%f %f %f\n",p[i].x,p[i].y,p[i].len());
            int o2=-1;
            double ma;
            for(int i=0;i<n;i++)
            if(i!=o&&fabs(p[i].len()-R)<1e-7)
            {
                //printf("i=%d\n",i);
                if(o2==-1||dis(p[i],tp)>ma)
                {
                    ma=dis(p[i],tp);
                    o2=i;
                }
            }
            printf("%.8f %.8f\n",p[o2].x,p[o2].y);
            o=o2;
        }
    }
}

Measured memory_bytes: 1256
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#define NUM 1

using namespace std;

int main(){
    long long a,b,k;
    cin >> a >> b >>k;
    if(a + b <= k) {
        a=0;
        b=0;
    }else if(a <= k){
        b = b -(k-a);
        a = 0;
    }else{
        a = a-k;
    }
    cout << a << " "<< b;
    return 0;
}

Measured memory_bytes: 256