akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
#define PI 3.141592653589793238462643383279
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
typedef long long int ll;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;
const long long MOD = 1e9+7;
const ll INF = 1LL << 60;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
  
int n,m;
vector<vector<int>> G;

void solve(){
    vector<int> dist(n,-1);
    vector<int> prev(n,-1);

    queue<int> que;
    que.push(0);
    dist[0] = 0;

    while(!que.empty()){
        int v = que.front();
        que.pop();

        for(auto nv: G[v]){
            if(dist[nv] == -1){
                dist[nv] = dist[v] + 1;
                prev[nv] = v;
                que.push(nv);
            }
        }

    }

    cout << "Yes" << endl;
    
    for(int i = 1; i < n; i++){
        cout << prev[i] + 1 << endl;
    }



}

int main(){
    cin >> n >> m;
    G.assign(n,vector<int>());

    for(int i = 0; i < m; i++){
        int a,b;
        cin >> a >> b; a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    solve();


}

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

#define rep(i, n) for (ll i=0;i<(n); i++)

using namespace std;
//using ll=long long;
typedef long long ll;
typedef pair<ll, ll> pi;



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

  string t="";
  rep(i, s.size()){
    if(s[i]!='x') t+=s[i];
  }

  string u = "";

  u += t;
  reverse(u.begin(), u.end());

  //cout <<u<<endl;
  ll ans;
  if(u==t) {
    ans = s.size()-u.size();
    // if((s.size()+ans)%2==1 && u.size()%2==0) ans--;

    ll lc=0; ll rc=0;
    int l =0;
    int r=s.size()-1;
    while(l<=r){
      //cout<<rc<<lc<<s[l]<<l<<r<<endl;;
      if(l==r && s[l]=='x') {
	ans = rc+lc;
	//cout<<rc<<lc;

	break;
      }
      else if(l==r && s[l]!='x'){
	ans = rc+lc;
	break;	
      }
      
      else if(l+1==r) {
	if(s[l]==s[r]) {ans=rc+lc;break;}
	else{ans = rc+lc+1;break;}	
      }

      //cout << s[l]<<" " <<s[r]<<endl;
      if(s[l]!=s[r]) {
	if(s[l]=='x') {rc++; l++;}
	else {lc++;r--;}
      }
      else{l++;r--;}
      
    }
    
    
  }
  else ans = -1;
  
  cout << ans << endl;

}


Measured memory_bytes: 640
import itertools
import operator

def product(iterable):
    return reduce(operator.mul, iterable, 1)

def main():
    n = int(raw_input())
    table = dict((c, 0) for c in 'MARCH')

    for _ in xrange(n):
        s = raw_input()
        if s[0] in table:
            table[s[0]] += 1

    m = 0
    for comb in itertools.combinations('MARCH', 3):
        m += product(table[c] for c in comb)
    print m

main()

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

typedef long long ll;
const long long LINF = 1LL << 60;
const long long LMINF = 1LL << 63;
const int INF = 1 << 30;

#define REP(i,n) for(int i = 0;i < n;++i)
#define REPS(i,x) for(int i = 1;i <= (int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i >= 0;i--)
#define RREPS(i,x) for(int i=((int)(x));i > 0;i--)
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << ": " << x << "\n"

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



int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int h,w,k;
    cin >> h >> w >> k;
    vector<vector<char>> c(h,vector<char>(w));
    int blcnt = 0,whcnt = 0;
    REP(i,h){REP(j,w){cin >> c[i][j];}}

    int ans = 0;
	for (int bi = 0; bi < (1 << h); ++bi){ 
        for (int bj = 0; bj < (1 << w); ++bj){
            blcnt = 0;
            REP(i,h){
                if (bi & (1 << i)){ 
                    REP(j,w){
                        if (bj & (1 << j)){ 
                            if(c[i][j] == '#'){blcnt++;}
                        }
                    }
                }
            }
            if(blcnt == k){ans++;}
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

typedef vector<vector<ll> > Graph;

vector<bool> seen;
vector<ll> c;

void dfs(const Graph &G, ll v) {
    seen[v] = true;

    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue;
        c[next_v] += c[v];
        dfs(G, next_v);
    }
}

int main() {
    ll n, q;
    cin >> n >> q;
    Graph G(n);
    rep1(i, n-1){
        ll a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    seen.assign(n, false);
    c.assign(n, 0);
    rep1(i, q){
        ll p, x;
        cin >> p >> x;
        p--;
        c[p] += x;
    }
    dfs(G, 0);
    rep1(i, n){
        if (i==n-1) cout << c[i] << endl;
        else cout << c[i] << " ";
    }
    //printf("%.12f", ans);
}

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

int main(void) 
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int a,b,c,d;

	cin >> a >> b >> c >> d;

	if(abs(c-a)<=d || (abs(b-a)<=d && abs(c-b)<=d))
	{
		cout << "Yes" << '\n';
	}
	else
	{
		cout << "No" << '\n';
	}
	
	return 0;	
}


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

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

    int ans = n * 800 - n / 15 * 200;

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


Measured memory_bytes: 3512
#include<iostream>
#include<string> 
using namespace std;
int n,m;
string s;
bool no=false;
int main()
{
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		//cout<<s[i]<<" "<<endl;
		if((i+1)%2==1 && s[i]=='L')
		{
		//	cout<<i<<"　"<<s[i]<<"@@@"<<endl;
			no=true;
			break;
		}
		else if((i+1)%2==0 && s[i]=='R')
		{
		//	cout<<i<<"!!!"<<endl;
			no=true;
			break;
		}
	}
	if(no==true)
		cout<<"No"<<endl;
	else
		cout<<"Yes"<<endl;	
} 

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

using namespace std;



int main(int argc, char* argv[])
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int N, M;
  cin >> N >> M;

  int mx = M / N;
  int rem = M % N;
  rem %= mx;

  while (rem)
  {
    mx--;
    rem = M - N*mx;
    rem %= mx;
  }

  cout << mx << "\n";

  return 0;
}


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

public class Main{
	static char[] x, y, ans;
	static int[][] dp;

	public static void trace(int i, int j, int k) {
		if (k == 0) {
			return;
		}
		if (x[i - 1] == y[j - 1]) {
			ans[k-1] = x[i - 1];
			trace(i - 1, j - 1, k - 1);
		} else if (dp[i - 1][j] > dp[i][j - 1]) {
			trace(i - 1, j, k);
		} else {
			trace(i, j - 1, k);
		}
	}

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		x = sc.next().toCharArray();
		y = sc.next().toCharArray();
		dp = new int[x.length + 1][y.length + 1];
		int i;
		int j = 0;
		for (i = 0; i <= x.length; i++) {
			for (j = 0; j <= y.length; j++) {
				if (i == 0 || j == 0) {
					dp[i][j] = 0;
				} else if (x[i - 1] == y[j - 1]) {
					dp[i][j] = dp[i - 1][j - 1] + 1;
				} else {
					dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
				}
			}
		}
		int k = dp[i-1][j-1];
		ans = new char[k];
		trace(x.length, y.length, k);
		for (int k2 = 0; k2 < k; k2++) {
			pw.print(ans[k2]);
		}
		pw.close();
	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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

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

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

		public int[] nextIntArr(int n) throws IOException {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = Integer.parseInt(next());
			}
			return arr;
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}


Measured memory_bytes: 76628
#include <set>
#include <queue>
#include <cstdio>
#include <vector>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
const int INF = 999999999;
int N, M, Q;
int main() {
	scanf("%d%d%d", &N, &M, &Q);
	vector<vector<int> > G(N);
	vector<int> s(M), t(M);
	for (int i = 0; i < M; i++) {
		scanf("%d%d", &s[i], &t[i]); s[i]--, t[i]--;
		G[s[i]].push_back(t[i]);
		G[t[i]].push_back(s[i]);
	}
	queue<int> que1; que1.push(0);
	vector<int> dist(N, INF); dist[0] = 0;
	while (!que1.empty()) {
		int u = que1.front(); que1.pop();
		for (int i : G[u]) {
			if (dist[i] == INF) {
				dist[i] = dist[u] + 1;
				que1.push(i);
			}
		}
	}
	for (int i = 0; i < M; i++) {
		if (dist[s[i]] > dist[t[i]]) swap(s[i], t[i]);
		if (dist[s[i]] + 1 != dist[t[i]]) s[i] = -1;
	}
	vector<int> x(Q), f(M);
	for (int i = 0; i < Q; i++) scanf("%d", &x[i]), f[--x[i]] = 1;
	vector<set<int> > G2(N);
	vector<vector<int> > G3(N);
	for (int i = 0; i < M; i++) {
		if (!f[i] && s[i] != -1) G2[s[i]].insert(t[i]);
		if (s[i] != -1) G3[t[i]].push_back(s[i]);
	}
	queue<int> que2; que2.push(0);
	vector<int> dist2(N, INF); dist2[0] = 0;
	while (!que2.empty()) {
		int u = que2.front(); que2.pop();
		for (int i : G2[u]) {
			if (dist2[i] == INF) {
				dist2[i] = dist2[u] + 1;
				que2.push(i);
			}
		}
	}
	vector<int> ok(N);
	for (int i = 0; i < N; i++) {
		if (dist[i] == dist2[i]) ok[i] = 1;
	}
	int sum = 0;
	for (int i = 0; i < N; i++) sum += ok[i];
	reverse(x.begin(), x.end());
	vector<int> ret(Q);
	for (int i = 0; i < Q; i++) {
		ret[i] = N - sum;
		int z = x[i];
		if (s[z] == -1) continue;
		G2[s[z]].insert(t[z]);
		if (ok[s[z]] == ok[t[z]]) continue;
		if (!ok[s[z]]) swap(s[z], t[z]);
		queue<int> que3; que3.push(s[z]);
		while (!que3.empty()) {
			int u = que3.front(); que3.pop();
			vector<int> moved;
			for (int i : G2[u]) {
				if (!ok[i]) {
					ok[i] = 1; sum++;
					moved.push_back(i);
					que3.push(i);
				}
			}
			for (int i : moved) {
				for (int j : G3[i]) {
					G2[j].erase(i);
				}
			}
		}
	}
	reverse(ret.begin(), ret.end());
	for (int i : ret) printf("%d\n", i);
	return 0;
}

Measured memory_bytes: 31992
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdlib>

/*
 *変数
 */
int a,b,c;

/*
 *関数
 */
int ctoi(char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

/*
 *解 
 */
void solve(){
  printf("%d",c/a*b);
}

/*
 *入力 
 */
int main(){
       std::cin.tie(0);
       std::ios::sync_with_stdio(false);
       std::cin>>a>>b>>c;
       solve();
       return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const auto INF = (ll)1e9;  
using  p = pair<int,int>;
using  v = vector<char>;


int main(){
   int h,w;
   cin >> h>>w;
   auto a = vector<v>(h+2,v(w+2,'#'));
   for (int i = 1; i <= h; i++)
   {
      for (int j = 1; j <= w; j++)
      {
         cin >>a[i][j];
      }
   }

   for (int i = 0; i <= h+1; i++)
   {
      for (int j = 0; j <= w+1; j++)
      {
         cout<<a[i][j];
      }
      cout << endl;
   }
   

}
  

Measured memory_bytes: 256
trait Monoid {
    type T: Clone;
    fn id() -> Self::T;
    fn op(a: &Self::T, b: &Self::T) -> Self::T;
}

#[derive(Debug)]
struct SegmentTree<M: Monoid> {
    n: usize,
    vec: Vec<M::T>,
}

impl<M: Monoid> SegmentTree<M> {
    fn new(n: usize) -> Self {
        let n = n.next_power_of_two();
        SegmentTree {
            n: n,
            vec: vec![M::id().clone(); 2 * n - 1],
        }
    }

    // vec[k] = a
    fn update(&mut self, k: usize, a: M::T) {
        let mut k = k + self.n - 1;
        self.vec[k] = a;
        while k > 0 {
            k = (k - 1) / 2;
            self.vec[k] = M::op(&self.vec[2 * k + 1], &self.vec[2 * k + 2]);
        }
    }

    fn querySub(&self, a: usize, b: usize, k: usize, l: usize, r: usize) -> M::T {
        if r <= a || b <= l {
            M::id()
        } else if a <= l && r <= b {
            self.vec[k].clone()
        } else {
            M::op(
                &self.querySub(a, b, k * 2 + 1, l, (l + r) / 2),
                &self.querySub(a, b, k * 2 + 2, (l + r) / 2, r),
            )
        }
    }

    // op [a, b)
    fn query(&self, a: usize, b: usize) -> M::T {
        self.querySub(a, b, 0, 0, self.n)
    }
}

use std::io::*;
use std::str::FromStr;

struct RMQ;
impl Monoid for RMQ {
    type T = i64;
    fn id() -> Self::T {
        2_i64.pow(31) - 1
    }
    fn op(a: &Self::T, b: &Self::T) -> Self::T {
        std::cmp::min(*a, *b)
    }
}

fn main() {
    let n: usize = read();
    let q: usize = read();
    let mut seg: SegmentTree<RMQ> = SegmentTree::new(n);
    for _ in 0..q {
        let com: usize = read();
        let x: usize = read();
        let y: usize = read();
        if com == 0 {
            seg.update(x, y as i64);
        } else {
            println!("{}", seg.query(x, y + 1));
        }
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}



Measured memory_bytes: 7084
import sys
from itertools import accumulate

MOD = 10 ** 9 + 7

def make_table(size=10**6, p=MOD):
    fac = [None] * (size + 1)
    fac[0] = 1
    for i in range(size):
        fac[i+1] = fac[i] * (i + 1) % p
    ifac = [None] * (size + 1)
    ifac[size] = pow(fac[size], p-2, p)
    for i in range(size, 0, -1):
        ifac[i-1] = ifac[i] * i % p
    return fac, ifac

fac, ifac = make_table(10**5)

def comb(n, r, mod=MOD):
    if r > n or r < 0:
        return 0
    return fac[n] * ifac[r] % mod * ifac[n-r] % mod

n, k, *a = map(int, sys.stdin.read().split())
a.sort()

def main():
    if k == 1:
        return 0

    s1 = a.copy()
    for i in range(n-1):
        s1[i+1] += s1[i]
        s1[i+1] %= MOD
    s2 = a[::-1]
    for i in range(n-1):
        s2[i+1] += s2[i]
        s2[i+1] %= MOD

    res = 0
    for m in range(k-2, n-2+1):
        res += (s2[n-(m+1)-1] - s1[n-(m+1)-1]) % MOD * comb(m, k-2) % MOD
        res %= MOD
    
    return res

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 22892
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
// -----------------------------------------------------------------------------

string get_rest(string s) {
    vector<int> bin(26);
    FOR (i, 0, s.length())
        bin[s[i] - 'a']++;
    FOR (i, 0, 26)
        if (!bin[i]) {
            s += (i + 'a');
            return s;
        }
}

int main() {
    string s; cin >> s;
    if (s.length() < 26) {
        cout << get_rest(s) << endl;
    } else {
        FORD (i, 24, -1) {
            if (s[i] < s[i + 1]) {
                int best = i + 1;
                FOR (j, i + 1, s.length()) {
                    if (s[j] > s[i] && s[j] < s[best])
                        best = j;
                }
                s[i] = s[best];
                cout << s.substr(0, i + 1) << endl;
                return 0;
            }
        }
        puts("-1");
    }
}

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

using namespace std;
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define MOD 1000000007
#define fix(n) cout << fixed << setprecision(n)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for(long i=a; i<=b; i++)
#define REN(i, a, b) for(long i=b; i>=a; i--)
// Debugging 
#define line cout << endl
#define out(n) cout << n << " "
#define bug(n) cout << n << "\n"
#define print(arr, start, end) REP(i, start, end) out(arr[i]); line

typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pi;
typedef map<int, int> mii;

///// General Purpose functions /////

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

void solve(){
	int n;
  	cin >> n;
  
  	ll A[n];
  	ll pre_sum[n];
  	cin >> A[0];
    pre_sum[0] = A[0];
  	
  	REP(i,1,n-1)
    {
      cin >> A[i];
      pre_sum[i] = (pre_sum[i-1]%MOD + A[i]%MOD)%MOD; 
    }
  
  	ll ans = 0;
    ll psum = 0;
  	REP(i,0,n-2)
    {
      psum = (pre_sum[n-1] - pre_sum[i] + MOD)%MOD;
      psum = ((A[i]%MOD)*(psum%MOD))%MOD;
      ans =  (ans%MOD + psum%MOD)%MOD;
    }
  	
  	bug(ans);
}

void prep(){

}

int main()
{
	//code
	io;
	int t = 1;
	//cin >> t;
	prep();
	fix(12);
	while(t--){
	    solve();
	}
	
	return 0;
}

Measured memory_bytes: 6772
import math

n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

d1 = 0
for i in range(n):
    d1 += abs(x[i]-y[i])
print('{:.7f}'.format(d1))

d2 = 0
for i in range(n):
    d2 += abs(x[i]-y[i])**2
print('{:.7f}'.format(math.sqrt(d2)))

d3 = 0
for i in range(n):
    d3 += abs(x[i]-y[i])**3
print('{:.7f}'.format(d3**0.3333333333))

di = []
for i in range(n):
    di.append(abs(x[i]-y[i]))
print('{:.7f}'.format(max(di)))


Measured memory_bytes: 5700
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#define ll long long int

using namespace std;



int main()
{


    int ans = -1;
    for (int i = 0; i < 5;i++)
    {
        int temp;
        cin >> temp;
        if(temp ==0)
        {
            ans = i+ 1;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3576
# -*- coding: utf-8 -*-
"""
Created on Sat Apr  6 21:35:04 2019

@author: yuta
"""

ABCDE = [int(input()) for i in range(5)]
K = int(input())

def main(x,k):
    if max(x) - min(x) <= k:
        print("Yay!")
    else:
        print(":(")
main(ABCDE,K)

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int n,a[50]; cin>>n;
	rep(i,n) cin>>a[i];

	int pos=0;
	rep(i,n) if(abs(a[pos])<abs(a[i])) pos=i;

	cout<<2*n-2<<endl;
	rep(i,n) if(i!=pos) cout<<pos+1<<' '<<i+1<<endl;
	if(a[pos]>=0){
		rep(i,n-1) cout<<i+1<<' '<<i+2<<endl;
	}
	else{
		rep(i,n-1) cout<<n-i<<' '<<n-i-1<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld double
#define F first
#define S second
#define sz size

using namespace std;

const int MAXN = 1e6 + 5;
const int inf = 1e9 + 7;
const int INF = 1e18;

int n, m, b[25], c;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n >> m >> c;
    for (int i = 1; i <= m; i++) {
        cin >> b[i];
    }
    int res = 0;
    for (int i = 1; i <= n; i++) {
        int sum = 0;
        for (int j = 1; j <= m; j++) {
            int a;
            cin >> a;
            sum += (a * b[j]);
        }
        if (sum + c > 0) res++;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def solve(S):
    a = S.count("a")
    b = S.count("b")
    c = S.count("c")
    a, b, c = list(sorted([a, b, c], reverse=True))
    if (a == b == c) or (a - 1 == b == c) or (a - 1 == b - 1 == c):
        return True
    return False


def main():
    S = input()
    print("YES" if solve(S) else "NO")


if __name__ == '__main__':
    main()


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

#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'

template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

typedef long long ll;

int main(){
  ios::sync_with_stdio(0), cin.tie(0);
  
  ll a, b, x; cin >> a >> b >> x;
  if(a==0 and b==0) {
    cout << 1 << "\n";
  } else if(a==0){
    cout << b/x+1 << "\n";
  } else {
    cout << b/x - (a-1)/x << "\n";
  }
  return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <math.h>
int main(void) {
    int num,temp,i,j,count=0;
    scanf("%d",&num);
    for (i=0; i<num; i++) {
        scanf("%d",&temp);
        for (j=2; j<=sqrt(temp); j++) {
            if (temp%j==0) break;
        }
        if (j>sqrt(temp)||sqrt(temp)<2) count++;
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;

ll modexp(ll a,ll b,ll m)
{
	ll r=1;
	a=a%m;
	while(b>0)
	{
		if(b&1)
		r=(r*a)%m;
		b=b/2;
		a=(a*a)%m;
	}
	return r%m;
}
//vi arr;
ll n;

int main(){
    cin>>n;
    cout<<((n-1)*n)/2<<endl;
    return 0;
}


Measured memory_bytes: 256
N, M, Q = map(int, input().split())
X = [[0] * (N+1) for _ in range(N+1)]

for _ in range(M):
    l, r = map(int, input().split())
    X[l][r] += 1

for i in range(N):
    for j in range(N):
        X[i+1][j+1] += X[i+1][j] + X[i][j+1] - X[i][j]

for _ in range(Q):
    p, q = map(int, input().split())
    print(X[N][q]-X[p-1][q])

Measured memory_bytes: 56920
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n ; cin >> n ;
	vll a(n) ;
	for(auto &i:a) cin >> i ;
	vll b = a ;
	sort(all(b)) ;
	reverse(all(b)) ;
	for(int i=0;i<n;i++){
		if(a.at(i)==b.at(0)) cout << b.at(1) << endl ;
		else cout << b.at(0) << endl ;
	}
}


Measured memory_bytes: 4736
import java.util.*;
public class Main {    
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[] nums=new int[n];
        for(int i=0;i<n;i++){
            nums[i]=sc.nextInt();
        
            
        }
        int output=0;
        flag2:while(true){
            for(int i=0;i<n;i++){
                if(nums[i]>0){
                    output++;
                    for(int j=0;j<n-i;j++){
                        if(nums[i+j]==0){
                            
                            continue flag2;
                        }
                        nums[i+j]-=1;
                        }
                    continue flag2;
                        
                        
                    }
                
            }
            break flag2;
            
            }
        System.out.println(output);
        }
    
            
            
        
        
        

    }

Measured memory_bytes: 23764
from collections import defaultdict
s = input()
t = input()
S = defaultdict(list)
T = defaultdict(list)
trans = defaultdict(int)
for i in range(len(t)):
  c = t[i]
  m = s[i]
  if T[c]==[]:
    T[c] = i
  if S[m]==[]:
    S[m] = i
  if T[c]!= S[m]:
    print('No')
    break
else:
  print('Yes')

Measured memory_bytes: 4144
import types

_atcoder_code = """
# Python port of AtCoder Library.

__version__ = '0.0.1'
"""

atcoder = types.ModuleType('atcoder')
exec(_atcoder_code, atcoder.__dict__)

_atcoder_dsu_code = """
import typing


class DSU:
    '''
    Implement (union by size) + (path compression)
    Reference:
    Zvi Galil and Giuseppe F. Italiano,
    Data structures and algorithms for disjoint set union problems
    '''

    def __init__(self, n: int = 0):
        self._n = n
        self.parent_or_size = [-1] * n

    def merge(self, a: int, b: int) -> int:
        assert 0 <= a < self._n
        assert 0 <= b < self._n

        x = self.leader(a)
        y = self.leader(b)

        if x == y:
            return x

        if -self.parent_or_size[x] < -self.parent_or_size[y]:
            x, y = y, x

        self.parent_or_size[x] += self.parent_or_size[y]
        self.parent_or_size[y] = x

        return x

    def same(self, a: int, b: int) -> bool:
        assert 0 <= a < self._n
        assert 0 <= b < self._n

        return self.leader(a) == self.leader(b)

    def leader(self, a: int) -> int:
        assert 0 <= a < self._n

        if self.parent_or_size[a] < 0:
            return a

        self.parent_or_size[a] = self.leader(self.parent_or_size[a])
        return self.parent_or_size[a]

    def size(self, a: int) -> int:
        assert 0 <= a < self._n

        return -self.parent_or_size[self.leader(a)]

    def groups(self) -> typing.List[typing.List[int]]:
        leader_buf = [self.leader(i) for i in range(self._n)]

        result = [[] for _ in range(self._n)]
        for i in range(self._n):
            result[leader_buf[i]].append(i)

        return list(filter(lambda r: r, result))
"""

atcoder.dsu = types.ModuleType('atcoder.dsu')
exec(_atcoder_dsu_code, atcoder.dsu.__dict__)

#!/usr/bin/env python3
# from typing import *

# import atcoder.dsu


# def solve(N: int, M: int, A: List[int], B: List[int]) -> int:
def solve(N, M, A, B):
    dsu = atcoder.dsu.DSU(N)
    for i in range(M):
        dsu.merge(A[i] - 1, B[i] - 1)
    num_groups = len(dsu.groups())
    return num_groups - 1


# generated by online-judge-template-generator v4.7.1 (https://github.com/online-judge-tools/template-generator)
def main():
    N, M = map(int, input().split())
    A = [None for _ in range(M)]
    B = [None for _ in range(M)]
    for i in range(M):
        A[i], B[i] = map(int, input().split())
    b = solve(N, M, A, B)
    print(b)


if __name__ == '__main__':
    main()


Measured memory_bytes: 31716
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 305

int N,M;
bool can_go[SIZE][SIZE];

int main(){

	scanf("%d %d",&N,&M);

	for(int i = 0; i < N; i++){
		for(int k = 0; k < N; k++){

			can_go[i][k] = (i == k);
		}
	}

	int from,to;

	for(int loop = 0; loop < M; loop++){

		scanf("%d %d",&from,&to);
		from--;
		to--;

		can_go[from][to] = true;
	}

	for(int mid = 0; mid < N; mid++){
		for(int start = 0; start < N; start++){
			if(!can_go[start][mid])continue;
			for(int goal = 0; goal < N; goal++){
				if(!can_go[mid][goal])continue;

				can_go[start][goal] = true;
			}
		}
	}

	for(int i = 0; i < N; i++){
		bool is_First = true;
		for(int k = 0; k < N; k++){
			if(can_go[i][k] && can_go[k][i]){
				if(is_First){

					printf("%d",k+1);
					is_First = false;
				}else{

					printf(" %d",k+1);
				}
			}
		}
		printf("\n");
	}

	return 0;
}



Measured memory_bytes: 3312
S=input()
if S=="SUN":
    print(7)
elif S=="MON":
    print(6)
elif S=="TUE":
    print(5)
elif S=="WED":
    print(4)
elif S=="THU":
    print(3)
elif S=="FRI":
    print(2)
elif S=="SAT":
    print(1)

Measured memory_bytes: 8968
#!/usr/bin/env python3
import sys
import heapq
from collections import deque
input = lambda: sys.stdin.buffer.readline()[:-1].decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7

h,w=map(int,input().split())
A=[list(input()) for i in range(h)]
# A=(tuple(input()) for i in range(h))
# print(A)
dis=[[-1]*w for i in range(h)]
hq=deque()
for i in range(h):
    for j in range(w):
        if A[i][j]=="#":
            hq.append((0,i,j))
            dis[i][j]=0
dii=[(1,0),(-1,0),(0,1),(0,-1)]
# heapq.heapify(hq)
ans=0
while hq:
    count,i,j=hq.popleft()
    for di,dj in dii:
        if not (0<=i+di<h and 0<=j+dj<w):
            continue
        if dis[i+di][j+dj]==-1:
            hq.append((count+1, i+di, j+dj))
            dis[i+di][j+dj]=count+1
            ans=max(ans,count+1)
#             # print(count+1)
# ans=0
# for Ai in dis:
#     ans=max(ans,max(Ai))
print(ans)
# for d in dis:
#     print(d)

    
    


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

int h, w;
int t[1002][1002];
int col[1002], row[1002];

void solve(){
  memset(col, 0, sizeof(col));
  memset(row, 0, sizeof(row));

  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(t[i][j] == 0){
        col[j]++;
        row[i]++;
      }
    }
  }

  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(j != 0) cout << " ";
      cout << (!t[i][j] + col[j] + row[i]) % 2;
    }
    cout << endl;
  }
}

int main(){
  while(cin >> h >> w){
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        cin >> t[i][j];
      }
    }

    solve();
  }
}

Measured memory_bytes: 5084
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <functional>
#include <iomanip>

#define int long long

int n, a[100005], b[100005], suma, m;

signed main() {
    scanf("%Ld", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%Ld %Ld", &a[i], &b[i]);
        //a += suma;
        //m = a % b;
        //suma += b - m;
    }

    for (int i = n-1; i >= 0; i--) {
        a[i]+=suma;
        m = a[i] % b[i];
        if (m != 0) suma += b[i] - m;
        a[i] += suma;
    }
    printf("%Ld\n", suma);
}

Measured memory_bytes: 1792
import kotlin.math.sqrt

fun main(){
    var n = readLine()!!.split(" ")[0].toLong()
    val sqrt = sqrt(n.toDouble()).toLong()
    val soinsuu = mutableListOf<Long>()
    val kaisuu = mutableListOf<Int>()
    for (i in 2 until sqrt + 1){
        var count = 0
        if (n % i == 0L) {
            while (n % i == 0L) {
                count++
                n /= i
            }
            soinsuu += i
            kaisuu += count
        }
    }
    if (n > sqrt) {
        soinsuu += n
        kaisuu += 1
    }
    var ans = 0
    for (i in 0 until kaisuu.size){
        var j = 1
        while (kaisuu[i] >= 0){
            kaisuu[i] -= j
            j++
            ans++
            if (kaisuu[i] < j) break
        }
    }
    if (soinsuu.size == 0 && n != 1L){
        ans = 1
    }
    println(ans)
}



Measured memory_bytes: 37412
#include <iostream>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  int X;
  cin >> X;
  if (X < 600)
    cout << 8 << endl;
  else if (X < 800)
    cout << 7 << endl;
  else if (X < 1000)
    cout << 6 << endl;
  else if (X < 1200)
    cout << 5 << endl;
  else if (X < 1400)
    cout << 4 << endl;
  else if (X < 1600)
    cout << 3 << endl;
  else if (X < 1800)
    cout << 2 << endl;
  else if (X < 2000)
    cout << 1 << endl;

  return 0;
}


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

string s;
int main(){
	int h,w; cin >>h>>w;
	int cnth=-1;  int cntw=-1;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> s;
			if(s=="snuke"){
				cnth=i; cntw=j;
			}
		}
	}
	char a='A';
	for(int i=0;i<cntw;i++){
		a++;
	}
	cout << a <<cnth+1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;
int main () {
	map< char, int > freq;
	int n;
	cin >> n;
	string a;
	for (int i=0; i<n; i++) {
		cin >> a;
		freq[a[0]]++;
	}
	cout << "AC x " << freq['A'] << endl;
	cout << "WA x " << freq['W'] << endl;
	cout << "TLE x " << freq['T'] << endl;
	cout << "RE x " << freq['R'] << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
 
typedef pair<int,int> P;

typedef struct{
  int x,y;
} Point; 

int dist(P a){
  return a.first*a.first+a.second*a.second;
}
 
int main(){
  int n;
 
  while(cin >> n ,n){
    Point a;
    vector<P> v;
 
    for(int i = 0 ; i < n ; i++){
      cin >> a.x >> a.y;
      v.push_back(P(a.x,a.y));
    }  
 
    sort(v.begin(),v.end());
 
    int ans = 0;

    for(int i = 0 ; i < n-1 ; i++){
      for(int j = i + 1 ; j < n ; j++){
	P b,c,d;
	
	b.first = v[i].first - v[j].first;
	b.second = v[i].second - v[j].second;
	
	c.first = v[i].first - b.second;
	c.second = v[i].second + b.first;
	d.first = v[j].first - b.second;
	d.second = v[j].second + b.first;

	if(binary_search(v.begin(),v.end(),c) && binary_search(v.begin(),v.end(),d)){
	  ans = max(ans,dist(b));
	}	

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

Measured memory_bytes: 1256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
  int e[10] = {0};
  for (int i = 0; i < 4; ++i) {
    int n;
    cin >> n;
    e[n] = 1;
  }
  cout << (e[1] and e[9] and e[7] and e[4] ? "YES": "NO") << endl;
  return 0;
}

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

namespace IO {
    #define gc getchar()
    template <typename T>
    inline void read(T& x) {
        x = 0; bool f = 1; char ch;
        for (ch = gc; ch < '0' || '9' < ch; ch = gc) if (ch == '-') f ^= 1;
        for (; '0' <= ch && ch <= '9'; ch = gc) x = (x << 3) + (x << 1) + (ch ^ 48);
        x = f ? x : -x;
    }
    #undef gc
}

const int MAXN = 200000 + 10;

int n, arr[MAXN], cnt1, ans;
char str[MAXN];

int main() {
    IO::read(n);
    scanf("%s", str + 1);
    rep(i, 1, n) arr[i] = (str[i] == 'R');
    rep(i, 1, n) cnt1 += arr[i];
    rep(i, 1, cnt1) ans += !arr[i];
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 4716
n=int(input())
s=list(input())
t=list(reversed(s))

S,T=[],[]
x,y=0,0
for i in range(n):
    if s[i]=='W':
        x+=1
        S.append(x)
    else:
        S.append(x)
    
    if t[i]=='E':
        y+=1
        T.append(y)
    else:
        T.append(y)

S=[0]+S
T=[0]+T

T.reverse()

z=3*(10**5)
for j in range(n):
    z=min(z,S[j]+T[j+1])

print(z)

Measured memory_bytes: 24992
/*
[agc034] C - Tests
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 1e5;

int N;
ll X;
ll b[MAX_N], l[MAX_N], u[MAX_N];
int idx[MAX_N];
ll s[MAX_N + 2];
ll lb;

ll calc(int i) { return (X - b[i]) * u[i] + b[i] * l[i]; }

bool cmp(int x, int y) { return calc(x) > calc(y); }

bool can(ll t) {
    ll q = t / X;
    for (int i = 0; i < N; i++) {
        ll d = lb;
        if (i < q) {
            d += s[q + 1] - calc(idx[i]);
        } else {
            d += s[q];
        }
        d += l[idx[i]] * min(b[idx[i]], t % X) +
             u[idx[i]] * max(0LL, t % X - b[idx[i]]);

        if (d >= 0) {
            return true;
        }
    }

    return false;
}

ll solve() {
    for (int i = 0; i < N; i++) {
        idx[i] = i;
    }
    sort(idx, idx + N, cmp);

    lb = 0;
    s[0] = 0;
    for (int i = 0; i < N; i++) {
        s[i + 1] = s[i] + calc(idx[i]);
        lb += -l[i] * b[i];
    }
    s[N + 1] = s[N];

    ll ok = 1LL * X * N;
    ll ng = -1;
    while (ok - ng > 1) {
        ll m = (ok + ng) / 2;
        if (can(m)) {
            ok = m;
        } else {
            ng = m;
        }
    }

    return ok;
}

int main() {
    cin >> N >> X;
    for (int i = 0; i < N; i++) {
        cin >> b[i] >> l[i] >> u[i];
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 3712
#include <stdio.h>
#include <stdlib.h>

int main()
{
	char S[500002];
	scanf("%s", S);
	
	int i = 0, j, up, down;
	long long sum = 0;
	while (S[i] != 0) {
		up = 0;
		down = 0;
		while (S[i] == '<') {
			up++;
			i++;
		}
		while (S[i] == '>') {
			down++;
			i++;
		}
		sum += (long long)up * (up - 1) / 2 + (long long)down * (down - 1) / 2 + ((up < down)? down: up);
	}
	
	printf("%lld\n", sum);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 2216
n, m = map(int, input().split())

ok = [0 for _ in range(n)]
ng = [0 for _ in range(n)]
for _ in range(m):
    p, s = input().split()
    index = int(p) - 1
    if s == "AC":
        ok[index] += 1
    else:
        if ok[index] == 0:
            ng[index] += 1

count_ok = 0
count_ng = 0
for i in range(n):
    if ok[i] > 0:
        count_ok += 1
        if ng[i] > 0:
            count_ng += ng[i]
print("{} {}".format(count_ok, count_ng))


Measured memory_bytes: 4760
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N, D;
    cin >> N >> D;
    vector<vector<int>> X(N, vector<int>(D));
    for(int i=0; i<N; i++){
        for(int j=0; j<D; j++){
            cin >> X[i][j];
        }
    }
    int ans=0;
    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            int norm = 0;
            for(int k=0; k<D; k++){
                int diff = abs(X[i][k]-X[j][k]);
                norm += diff * diff;
            }


            for(int l=0; l<=sqrt(norm); l++){                       /*normは距離の二乗*/
                if(l*l == norm)                           /*normが整数の二乗になるまで繰り返す*/
                ans++;
            }

        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned ll
#define ioi exit(0);
 
#define f first
#define s second
 
#define inf (int)1e9 + 7
 
#define NFS ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
 
#define mp(x,y) make_pair(x,y)
 
#define lb(x) lower_bound(x)
#define ub(x) upper_bound(x)
 
#define pb push_back
#define ppb pop_back
 
#define bitcoin __builtin_popcount
 
#define endl "\n"
 
#define in(x) insert(x)
 
#define sz(x) (int)x.size()
 
#define all(x) x.begin(),x.end()
 
#define pw2(x) (1ll<<x) //2^x
 
#define forit(it,v) for (typeof(v.begin()) it = v.begin(); it != v.end(); ++it)
 
#define sqr(x) ((x) * 1ll * (x))
 
#define UpdateRandom srand (time(NULL));
 
using namespace std;
 
const int N = (int)5e5 + 7, MOD = (int)1e9 + 7;

int n,m;
int dp[N];
vector<int> v[N];
bool used[N];

void dfs(int x){
	used[x]=1;
	for(int i=0;i<sz(v[x]);i++){
		int to=v[x][i];
		if(!used[to])dfs(to);
		dp[x]=max(dp[x],dp[to]+1);
	}
}

int main(){
		
	NFS

	cin >> n >> m;

	for(int i=1;i<=m;i++){
		int x,y;
		cin >> x >> y;
		v[x].pb(y);
	}
	
	for(int i=1;i<=n;i++){
		if(!used[i]){
			dfs(i);
		}
	}
	
	int ans=0;
	
	for(int i=1;i<=n;i++){
		ans=max(ans,dp[i]);
	}
	
	cout << ans << endl;
	
	ioi
}

Measured memory_bytes: 18304
require 'prime'

n = gets.strip.to_i

divided = n.downto(1).inject({}) {|memo, num|
  num.prime_division.each {|div, count|
    if memo[div].nil?
      memo[div]=count
    else
      memo[div]+=count 
    end
  }
  memo
}.to_a

factor_counts = divided.map(&:last)

counts_4_arr = factor_counts.select {|f| f >= 4 }.to_a
counts_4 = factor_counts.select {|f| f >= 4 }.to_a.length
counts_2 = factor_counts.select {|f| f >= 2 }.to_a.length
counts_14 = factor_counts.select {|f| f >= 14 }.to_a.length
counts_24 = factor_counts.select {|f| f >= 24 }.to_a.length
counts_74 = factor_counts.select {|f| f >= 74 }.to_a.length

with_4_4_2 =  counts_4_arr.combination(2).to_a.length * (counts_2-2)
with_24_2 =  counts_24 * (counts_2-1)
with_14_4 = counts_14 * (counts_4-1)
with_74_0 = counts_74

p with_4_4_2 + with_24_2 + with_14_4 + with_74_0


Measured memory_bytes: 1916
n = int(input())
# h1, m1, h2, m2, k = list(map(int, input().split()))
# n, a, b = list(map(int, input().split()))
# a = list(map(int, input().split()))
# data = [list(map(int, input().split())) for i in range(n)]
# k = int(input())
t = list(map(int, input().split()))
# ab_sorted = sorted(ab, key=lambda x: x[0])
# py = [list(map(int, input().split())) for i in range(m)]
# b = list(map(int, input().split()))
t_sorted = sorted(t)
m = t_sorted[n//2-1]
m2 = t_sorted[n//2]
for i in range(n):
    if t[i] <= m:
        print(m2)
    else:
        print(m)


Measured memory_bytes: 26180
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rd3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define rl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009

void solve()
{
	ll n,m;
	rl2(n,m);
	if(n==m)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return;
}
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	solve();
	return 0;
}

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

int main() {
    int h, w;
    cin >> h >> w;
    vector<bool> column(h, false), row(w, false);
    vector<vector<char>> field(h, vector<char>(w));
    rep(i, h) {
        string temp;
        cin >> temp;
        rep(j, w) {
            field.at(i).at(j) = temp.at(j);
            if(temp.at(j) == '#') {
                column.at(i) = true;
                row.at(j) = true;
            }
        }
    }
    rep(i, h) {
        if(!column.at(i)) continue;
        rep(j, w) if(row.at(j)) cout << field.at(i).at(j);
        cout << endl;
    }
}

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

using namespace std;
typedef long long ll;
using Graph =vector<int>;
typedef pair<int,int> P;

const ll MAX_N=131072;

int bit[MAX_N*2-1];
ll n;
vector<int> G[1000010];
const int MAX = 210000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; 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;
    }
}
long long COM(int n, int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main(){
  int N,K;cin>>N>>K;
  COMinit();
  for(int i=1;i<=K;i++){
    ll ans=1;
    ans*=COM(K-i+i-1,i-1);
    ans*=COM(N-K+1,i);
    cout<<ans%MOD<<endl;
  }
}


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

int main(){
    int n, m;
    while(cin >> n >> m, n+m){
        int a[n], b[m];
        for(int i = 0; i < n; i++)  cin >> a[i];
        for(int i = 0; i < m; i++)  cin >> b[i];

        int ans = 0;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                if(a[i] == b[j]){
                    ans += a[i];
                    a[i] = b[j] = 0;
                    break;
                }
            }
        }

        ans += accumulate(a, a+n, 0) + accumulate(b, b+m, 0);

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


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

int main() {
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int w[n];
  for(int i = 0;i < n;i++){
    w[i] = s[i] == 'W' ? 1 : 0;
    if(i)
      w[i] += w[i - 1];
//    cout << w[i] << endl;
  }
  int res = 1e9;
  for(int i = 0;i < n;i++){
    res = min(res, (i ? w[i - 1] : 0) + (n - i - 1 - (w[n - 1] - w[i])));
//    cout << res << endl;
  }
  cout << res;
  return 0;
}


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

void cnt_C(int &x, int &y,int z){
	if(y>z){
		x = x-z;
		y = y-z;
	}
	else{
		x = x-y;
		y = 0;
	}
	return;
}

void cnt_B(int &a, int &b,int c,int d){
	if(b>c){
		b = b - c;
		cnt_C(a,b,d);
	}
	else{
		b = 0;
	}
	return;
}

int main(){
	int A,B,C,K,p,r;
	cin >> A >> B >> C >> K;
	r = K;
	p = 0;
	
	if(r>A){
		p = p + A;
		r = r-A;
		
		cnt_B(p,r,B,C);
	}
	else{
		p = r;
		r = 0;
	}
	
	cout << p << endl;
}

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

int main()
{
	string s;
	cin >> s;
	int num1 = stoi(s.substr(0, 2));
	int num2 = stoi(s.substr(2, 2));

	if (num1 == 0 && num2 == 0) {
		cout << "NA" << endl;
	}

	else if (12 < num1) {
		if (12 < num2 || num2 == 0) {
			cout << "NA" << endl;
		}

		else {
			cout << "YYMM" << endl;
		}
	}

	else {
		if (num2 <= 12 && num2 != 0 && num1 != 0) {
			cout << "AMBIGUOUS" << endl;
		}

		else if(num1 == 0) {
			cout << "YYMM" << endl;
		}

		else {
			cout << "MMYY" << endl;
		}
	}
}

Measured memory_bytes: 256