akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(long long i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int main(){
  string S;
  cin >> S;
  if(S.size() == 26){
    string pre = S;
    if(next_permutation(S.begin(), S.end())){
      REP(i, S.size()-1){
        if(S[i] != pre[i]){
          S.erase(S.begin()+i+1, S.end());
        }
      }
      cout << S << endl;
    }
    else{
      cout << -1 << endl;
    }
  }
  else{
    vector<int> cnt(26, 0);
    REP(i, S.size()){
      cnt[S[i]-'a']++;
    }
    REP(i, 26){
      if(cnt[i] == 0){
        S+='a'+i;
        break;
      }
    }
    cout << S << endl;
  }
  return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	const maxWord = (1 << 30)
	buf := []byte{}
	sc.Buffer(buf, maxWord)
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func solve(h, w int, s []string) int {
	sumH := make([][]int, h)
	for i := 0; i < h; i++ {
		sumH[i] = make([]int, w)
	}
	for i := 0; i < h; i++ {
		start := 0
		end := 0
		for j := 0; j < w; j++ {
			if s[i][j] == '.' {
				end++
			} else {
				for k := start; k < end; k++ {
					sumH[i][k] = end - start
				}
				end++
				start = end
			}
		}
		for k := start; k < end; k++ {
			sumH[i][k] = end - start
		}
	}

	sumW := make([][]int, h)
	for i := 0; i < h; i++ {
		sumW[i] = make([]int, w)
	}
	for j := 0; j < w; j++ {
		start := 0
		end := 0
		for i := 0; i < h; i++ {
			if s[i][j] == '.' {
				end++
			} else {
				for k := start; k < end; k++ {
					sumW[k][j] = end - start
				}
				end++
				start = end
			}
		}
		for k := start; k < end; k++ {
			sumW[k][j] = end - start
		}
	}

	ans := 0
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			ans = max(ans, sumH[i][j]+sumW[i][j]-1)
		}
	}
	return ans
}

func main() {
	h, _ := strconv.Atoi(input())
	w, _ := strconv.Atoi(input())
	s := make([]string, h)
	for i := 0; i < h; i++ {
		s[i] = input()
	}
	fmt.Println(solve(h, w, s))
}


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

public class Main {

	void submit() {
		String s = nextToken();
		out.println(s.substring(0, s.length() - 8));
	}

	void preCalc() {

	}

	void stress() {

	}

	void test() {

	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		//stress();
		//test();
		out.close();
	}

	static final Random rng = new Random();

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

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

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

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


Measured memory_bytes: 20948
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin>>s;
    bool ans=true;
    for(int i=0;i<s.size();i++){
        if(i%2==0&&s.at(i)=='L') ans=false;
        else if(i%2==1&&s.at(i)=='R') ans=false;
    }
    if(ans) cout<<"Yes";
    else cout<<"No";
}


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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;

std::map<int, int> cnt;
std::vector<int> p;
int N;
int main() {
    std::cin >> N;

    p.reserve(N/2 + 1);
    REP(i, N) {
        int A;
        std::cin >> A;

        if(++cnt[A] >= 2) {
            p.pb(A);
            cnt[A] -= 2;
        }
    }

    SORT(p);

    int s = p.size();
    if(s < 2) {
        std::cout << 0 << std::endl;
    } else {
        std::cout << (long)p[s-1] * p[s-2] << std::endl;
    }
}

Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<map>
using namespace std;
typedef pair<int ,int > P;
int xs[] = {-1, 0, 1, 0}, ys[] = {0, 1, 0, -1};
char a[55][55];
int w, h;
bool b[55][55], wh[55][55];
 
int main(){
	while(cin >> w >> h, w | h){
		memset(b, 0, sizeof(b));
		memset(wh, 0, sizeof(wh));
		queue<P> black, white;
		for(int i = 0;i < h;i++){
			for(int j = 0;j < w;j++){
				cin >> a[i][j];
				if(a[i][j] == 'B')black.push(P(i, j));
				if(a[i][j] == 'W')white.push(P(i, j));
			}
		}
		while(!black.empty()){
			for(int t = black.size() - 1;t >= 0;t--){
				P tmp = black.front();black.pop();
				for(int i = 0;i < 4;i++){
					int nx = tmp.first + xs[i], ny = tmp.second + ys[i];
					if(nx < 0 || nx >= h || ny < 0 || ny >= w || a[nx][ny] != '.')continue;
					if(b[nx][ny])continue;
					b[nx][ny] = true;
					black.push(P(nx, ny));
				}
			}
		}
		while(!white.empty()){
			for(int t = white.size() - 1;t >= 0;t--){
				P tmp = white.front();white.pop();
				for(int i = 0;i < 4;i++){
					int nx = tmp.first + xs[i], ny = tmp.second + ys[i];
					if(nx < 0 || nx >= h || ny < 0 || ny >= w || a[nx][ny] != '.')continue;
					if(wh[nx][ny])continue;
					wh[nx][ny] = true;
					white.push(P(nx, ny));
				}
			}
		}
		int bc = 0, wc = 0;
		for(int i = 0;i < h;i++){
			for(int j = 0;j < w;j++){
				if(b[i][j] && !wh[i][j])bc++;
				if(!b[i][j] && wh[i][j])wc++;
			}
		}
		cout << bc << " " << wc << endl;
	}
	return 0;
}

Measured memory_bytes: 1252
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <limits.h>
#include <algorithm>

#define Int long long
#define rep(i, n) for (Int i = 0; i < n; i++)
#define in(params) cin >> params;
#define p(params) cout << params << endl;
#define mod 1000000007LL

using namespace std;

int main()
{
    Int N;
    cin >> N;

    map<string, Int> m;
    string s;
    Int count = 0;

    for (Int i = 0; i < N; i++)
    {
        cin >> s;
        sort(s.begin(), s.end());

        auto f = m.find(s);

        if (f != m.end())
        {
            m[s]++;
            count += m[s];
        }
        else
        {
            m[s] = 0;
        }
    }

    // for (auto i : m)
    // {
    //     Int num = i.second;
    //     if (num != 1)
    //     {
    //         count += (num * (num - 1)) / 2;
    //     }
    // }

    cout << count << endl;

    return 0;
}



Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

// 負の数にも対応した mod (a = -11 とかでも OK) 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}

// a^n mod を計算する
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


int main() {
    int N; cin >> N;
    if (N <= 1) {
        cout << 0 << endl;
        return 0;
    }
    ll MOD = 1000000007;
    ll res;
    // 包除原理 全体                0を使わない        9を使わない       0,9を使わない
    // res = modpow(10, N, MOD) - modpow(9,N,MOD) - modpow(9,N,MOD) + modpow(8,N,MOD);
    res = modpow(10, N, MOD);
    res -= modpow(9, N, MOD);
    res = mod(res, MOD);
    res -= modpow(9, N, MOD);
    res = mod(res, MOD);
    res += modpow(8, N, MOD);
    res = mod(res, MOD);
    cout << res << endl;
}


Measured memory_bytes: 3576
local h, w = io.read("*n", "*n", "*l")
local t = {}
for i = 1, h do
  local s = io.read()
  for j = 1, w do
    t[(i - 1) * w + j] = s:sub(j, j) == "#"
  end
end
local omit_h = {}
local omit_w = {}
for i = 1, h do
  local f = true
  for j = 1, w do
    if t[(i - 1) * w + j] then
      f = false
      break
    end
  end
  if f then omit_h[i] = true end
end
for j = 1, w do
  local f = true
  for i = 1, h do
    if t[(i - 1) * w + j] then
      f = false
      break
    end
  end
  if f then omit_w[j] = true end
end
for i = 1, h do
  if not omit_h[i] then
    for j = 1, w do
      if not omit_w[j] then
        io.write(t[(i - 1) * w + j] and "#" or ".")
      end
    end
    io.write("\n")
  end
end


Measured memory_bytes: 888
from collections import deque

N, M = map(int, input().split())
edge = [[] for _ in range(N)]
sign = [-1] * N

for _ in range(M):
    A, B = map(int, input().split())
    edge[A - 1].append(B - 1)
    edge[B - 1].append(A - 1)

d = deque([0])

while d:
    cur = d.popleft()
    for adj in edge[cur]:
        if sign[adj] == -1:
            sign[adj] = cur
            d.append(adj)

print("Yes")
for i in range(1, N):
    print(sign[i] + 1)

Measured memory_bytes: 99048
#include<iostream>
#include <stdio.h>
#include <string.h>

using namespace std;
int main()
{
	long long A, B, K, i, j, a, b;

	cin >> A;
	cin >> B;
	cin >> K;

	a = B - A;
	b = 2 * K;

	if (a < b) {
		for (i = A; i < B + 1; i++) {
			cout << i << endl;
		}

	}
	else {
		for (j = A; j < A + K ; j++) {
			cout << j << endl;
		}
		for (j = B - K + 1; j < B + 1; j++) {
			cout << j << endl;
		}

	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	int A, B, C; cin >> A >> B >> C;
	cout << (max({A, B, C})==7 && min({A, B, C})==5 && A+B+C==17?"YES":"NO") << endl;
	return 0;
}

Measured memory_bytes: 256
n, r_from, r_to = [int(v) for v in input().split(' ')]
ans = 0
for nn in range(1, n + 1):
  ad_digit = 0
  tmp = nn
  while True:
    ad_digit += tmp % 10
    tmp = tmp // 10
    if tmp == 0:
      break
  if r_from <= ad_digit and ad_digit <= r_to:
  	ans += nn
    
print(ans)

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

int main() {
  
 int n,k;
 cin>>n>>k;
  vector<int> kasi(n,0);
  for(int i=0;i<k;i++){
    int d;
    cin>>d;
    for(int j=0;j<d;j++){
      int x;
      cin>>x;
      kasi[x-1]++;
    }
  }
  int count=0;
  for(int i=0;i<n;i++){
  if(kasi[i]==0){
    count++;
  }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 3620
import sys
from math import ceil
INPUT = lambda: sys.stdin.readline().rstrip()
MAP = lambda: map(int, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')

D, G = MAP()
PC = [LIST() for _ in range(D)]


def dfs(g, i):
    if i <= 0: return INF
    n = min(ceil(g/(100*i)), PC[i-1][0])
    s = 100 * i * n
    if n == PC[i-1][0]: s += PC[i-1][1]
    if g > s: n += dfs(g-s, i-1)

    return min(n, dfs(g, i-1))


def main():
    print(dfs(G, D))


if __name__ == '__main__':
    main()


Measured memory_bytes: 39704
#include <bits/stdc++.h>
using namespace std;
int main ()
{
	string s;
	cin>>s;
	int booom = 0;
	if (s[0] == '1')
	
		++booom;
	
	if (s[1] == '1')
	
		++booom;
	
	if (s[2]=='1')
	
		++booom;
	
	cout<<booom<<endl;

}

Measured memory_bytes: 256
function main(input) {
  var arr = input.split(' ').map(n => +n)
  var a = arr[0]
  var b = arr[1]
  var g = function(n, m){
  	return m ? g(m, n % m) : n
  }
  console.log(a * b / g(a, b))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 11468
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N;
    cin >> N;
    // vector<int> A(N);
    map<int,int> A;
    for (int i = 0; i < N; i++) {
        // cin >> A[i];
        int a;
        cin >> a;
        A[a]++;
    }
    
    ll ans = 0;
    for(auto&& a : A){
        ans += a.fi * a.se;
    }

    int Q;
    cin >> Q;
    REP(i, Q){
        int B,C;
        cin >> B >> C;

        ll Bn = A[B];
        ans -= B*Bn;
        ans += C*Bn;
        A[C] += A[B];
        A[B] = 0;

        pr(ans);
    }

}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<ll> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amin(T& a,T b){ a=min(a,b);}
template <class T> void amax(T& a,T b){ a=max(a,b);}


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n; cin >>n;
	vector<vector<int>> a(n, vector<int>(n));
	VI dp((1<<n)+5); dp[0] =1;
	rep(i,n) rep(j,n) cin >>a[i][j];
	
	rep(i, 1<<n){
		int pt = __builtin_popcount(i);
		rep(j,n) if(!(i>>j&1) && a[pt][j]) (dp[i | 1<<j] += dp[i]) %=mod;
	}
	
	cout << dp[(1<<n) -1] <<"\n";
	//for(auto x :dp) printf("%lld ",x); puts("");
	return 0;
}


Measured memory_bytes: 16640
N, K = map(int, input().split())

count = [0 for _ in range(N)]

for i in range(K):
    d = int(input())
    List = list(map(int, input().split()))
    for j in List:
        count[j - 1] += 1


ans = 0
for i in count:
    if i == 0:
        ans += 1

print(ans)

Measured memory_bytes: 9192
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <stack>
#include <list>
#include <math.h>
#include <map>
#include <iomanip>
#include <functional>
#include <string>
#include <algorithm>
#include <queue>
#include <set>

using namespace std;

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) os << *i << (i == end(v) - 1 ? "" : " "); return os;
}
template<class T> istream& operator>>(istream& is, vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) is >> *i; return is;
}


struct Pt
{
	int x, y;
	int num;
};

int main()
{
#if defined(_DEBUG) 
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	cout.tie(NULL);

	int r, c, n;
	cin >> r >> c >> n;

	vector<Pt> xx, yy;
	for (int i = 0; i < n; i++)
	{
		int x, y;
		Pt a, b;
		cin >> a.x >> a.y;
		cin >> b.x >> b.y;
		a.num = b.num = i;

		if (a.x != 0 && a.x != r && a.y != 0 && a.y != c)
			continue;

		if (b.x != 0 && b.x != r && b.y != 0 && b.y != c)
			continue;
		
		xx.push_back(a); xx.push_back(b);
		yy.push_back(a); yy.push_back(b);
	}

	sort(xx.begin(), xx.end(), [&](Pt& a, Pt& b) {
		return a.x < b.x;
		});

	sort(yy.begin(), yy.end(), [&](Pt& a, Pt& b) {
		return a.y < b.y;
		});
	
	vector<Pt> order;
	for (auto x : xx)
	{
		if (x.y == c)
			order.push_back(x);
	}

	for (int j = yy.size() - 1; j >= 0; j--)
	{
		if (yy[j].x == r)
			order.push_back(yy[j]);
	}
	for (int j = xx.size() - 1; j >= 0; j--)
	{
		if (xx[j].y == 0)
			order.push_back(xx[j]);
	}
	for (auto y : yy)
	{
		if (y.x == 0)
			order.push_back(y);
	}

	stack<int> st;
	set<pair<int, int>> been;
	for (auto x : order) {
		if (been.find({ x.x,x.y }) != been.end())
			continue;
		been.insert({ x.x,x.y });
		if (st.size() == 0)
			st.push(x.num);
		else if (st.top() == x.num)
			st.pop();
		else
			st.push(x.num);
	}

	if (st.size() == 0)
		cout << "YES";
	else
		cout << "NO";

	return 0;
}

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

int main(){
    double a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;
    vector<double> water;
    vector<double> sugar;
    double con=0;
    double ans1=100*a,ans2=0;
    for(int i=0;i<=30;i++){
        for(int j=0;j<=30;j++){
            if(i*a*100+j*b*100<=f) water.push_back(i*a*100+j*b*100);
        }
    }
    for(int i=0;i<=3000;i++){
        for(int j=0;j<=3000;j++){
            if(i*c+j*d<=f) sugar.push_back(i*c+j*d);
        }
    }
    sort(water.begin(),water.end());
    sort(sugar.begin(),sugar.end());
    for(int i=0;i<water.size();i++){
        for(int j=0;j<sugar.size();j++){
            if(water[i]+sugar[j]<=f&&water[i]/100*e>=sugar[j]&&(100*sugar[j])/(water[i]+sugar[j])>con){
                con=(100*sugar[j])/(water[i]+sugar[j]);
                ans1=water[i]+sugar[j];
                ans2=sugar[j];
            }
        }
    }
    cout << ans1 << " " << ans2 << endl;
}


Measured memory_bytes: 2420
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class D
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var NM = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var (N, M) = (NM[0], NM[1]);
            var infinity = (int)1e9;
            var nodes = new (int A, int B, int C)[M];
            var graph = new int[N][].Select(x => x = Enumerable.Repeat(infinity, N).ToArray()).ToArray();
            for (var i = 0; i < N; i++)
            {
                graph[i][i] = 0;
            }
            for (var i = 0; i < M; i++)
            {
                var abc = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
                var a = abc[0] - 1;
                var b = abc[1] - 1;
                var c = abc[2];
                graph[a][b] = Math.Min(graph[a][b], c);
                graph[b][a] = Math.Min(graph[b][a], c);
                nodes[i] = (a, b, c);
            }

            for (var k = 0; k < N; k++)
            {
                for (var i = 0; i < N; i++)
                {
                    for (var j = 0; j < N; j++)
                    {
                        graph[i][j] = Math.Min(graph[i][j], graph[i][k] + graph[k][j]);
                    }
                }
            }

            var answer = M;
            for (var i = 0; i < M; i++)
            {
                var ok = false;
                for (var j = 0; j < N; j++)
                {
                    if (graph[j][nodes[i].A] + nodes[i].C == graph[j][nodes[i].B]) ok = true;
                }
                if (ok) answer--;
            }
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 28688
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
using namespace std;

int main()
{
	int Q;
	int can[3];
	int total,temp;

	scanf("%d",&Q);
	for(int i = 0; i < Q; i++){
		total = 100000;
		for(int j = 0; j < 3; j++){
			scanf("%d",&can[j]);
			if(total > can[j])
				total = can[j];
		}

		for(int j = 0; j< 3; j++)
			can[j] -= total;

		temp = min(can[0]/2,can[1]);
		total += temp;
		can[0] -= temp*2;
		can[1] -= temp;

		total += can[0]/3;

		printf("%d\n",total);
	}

	return 0;
}

Measured memory_bytes: 1032
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z main.cpp
//.\a.exe

int main(void){ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////////////////
int n,k,a=0;
cin >> n >> k;
int h[n];
for(int i=0;i<n;i++){
    cin >> h[i];
}
for(int i=0;i<n;i++){
    if(h[i]>=k){
        a++;
    }
}
cout << a << endl;
////////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  vector<ll> a(n),b(n), dif(n);
  ll suma = 0, sumb = 0;
  rep(i,n) {
    cin >> a[i];
    suma += a[i];
  }
  rep(i,n) {
    cin >> b[i];
    sumb += b[i];
    dif[i] = a[i] - b[i];
  }
  if (sumb > suma) {
    cout << -1 << endl;
    return 0;
  }
  sort(all(dif));
  int idx = lower_bound(all(dif), 0) - dif.begin();
  ll lacks = 0; //不足量
  debug(idx);
  for (int i = 0; i < idx; ++i) {
    debug(dif[i]);
    lacks += -(dif[i]);
  }
  ll ans = idx;
  for (int i = n-1; i >= 0; --i) { //多く余ってるところから取る
    if (lacks <= 0) break;
    lacks -= dif[i];
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
#include<stdlib.h>
 
#define NMAX 10000
#define QMAX 500
 
int main(void){
  int i,j,n,S[NMAX],q,T[QMAX],C=0;
 
  scanf("%d", &n);
  if(n>NMAX) exit(1);
  for(i=0;i<n;i++)scanf("%d", &S[i]);
 
  scanf("%d", &q);
  if(q>QMAX) exit(1);
  for(i=0;i<q;i++)scanf("%d", &T[i]);
 
  for(i=0;i<q;i++){
    for(j=0;j<n;j++){
      if(S[j]==T[i]){
        C++;
        break;
      }
    }
  }
 
  printf("%d\n",C);
  return 0;
}

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

using ll = long long;

template<typename T>
T gcd(T a, T b)
{
	if (a < b)	return gcd(b, a);
	T r;
	while ((r = a % b))
	{
		a = b;
		b = r;
	}
	return b;
}

template<typename T>
T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}

template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
	x = 1;
	y = 0;
	T x0 = 0, y0 = 1;
	while (b != 0)
	{
		T q = a / b;
		a -= q * b;
		swap(a, b);
		x -= q * x0;
		swap(x, x0);
		y -= q * y0;
		swap(y, y0);
	}
	return a;
}

template<typename T>
T inv_mod(T a, T mod)
{
	T t1, t2;
	ext_gcd(a, mod, t1, t2);
	t1 %= mod;
	if (t1 < 0)		t1 += mod;
	return t1;
}

template<typename T>
T combination_large(T n, T k, T mod)
{
	if (n < k || n < 0 || k < 0)	return 0;
	vector<T> inv(n + 1, 1), fact(n + 1, 1), fact_inv(n + 1, 1);
	for (T i = 2; i <= n; ++i)
	{
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fact[i] = (fact[i - 1] * i) % mod;
		fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
	}
	return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

template<typename T>
T combination(T n, T k, T mod = 1)
{
	vector<vector<T>> table(n + 1, vector<T>(k + 1, 1));
	for (T i = 1; i <= n; ++i)
	{
		table[i][0] = 1;
		for (T j = 1; j <= n; ++j)
		{
			table[i][j] = (table[i - 1][j - 1] + table[i - 1][j]) % mod;
		}
	}
}


int main(int, char**)
{
	long long N;
	scanf("%lld",&N);
	std::vector<long long> A(N);
	for(ll i = 0 ; i < N ; i++){
		scanf("%lld",&A[i]);
	}

	sort(A.begin(), A.end());
	ll before = 0;
	for (ll i = 0; i < N; ++i)
	{
		if (before == A[i])
		{
			cout << "NO" << endl;
			return EXIT_SUCCESS;
		}
		before = A[i];
	}
	cout << "YES" << endl;

	return 0;
}


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

int n, m, d;

void solve()
{
	double ans;
	if(!d) ans = 1.0*(m-1)/n;
	else {
		ans = 2.0*(n-d)*(m-1)/n/n;
	}
	printf("%.8lf\n", ans);
}

int main()
{
	cin >> n >> m >> d;
	solve();
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
	int num, i = 0;
	cin >> num;
	vector<int> d(num);
	for (; i < num; i++)
		scanf("%d", &d[i]);
	for (i = num - 1; i > 0; i -= 2)
		printf("%d ", d[i]);
	cout << d[0];
	for (i = 2 - (num % 2); i < num - 1; i += 2)
		printf(" %d", d[i]);
	return 0;
}

Measured memory_bytes: 2944
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
#include<map>
#include<vector>
using namespace std;
int read(){
    int xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
long long READ(){
    long long xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
char one(){
	char ch=getchar();
	while(ch==' '||ch=='\n')
		ch=getchar();
	return ch;
}
const int maxn=200010;
int N,Q,lin[maxn],len;
struct edge{
	int y,next;
}e[maxn*2];
inline void insert(int xx,int yy){
	e[++len].next=lin[xx];
	lin[xx]=len;
	e[len].y=yy;
}
inline void ins(int xx,int yy){
	insert(xx,yy);
	insert(yy,xx);
}
int tid[maxn],rk[maxn],dfn,R[maxn];
void dfs(int x,int fa){
	tid[x]=++dfn;
	rk[dfn]=x;
	for(int i=lin[x];i;i=e[i].next)
		if(e[i].y!=fa)
			dfs(e[i].y,x);
	R[x]=dfn;
}
struct BIT{
	long long b[maxn];
	inline int lowbit(int x){
		return x&(-x);
	}
	void add(int x,int d){
		for(;x<maxn;x+=lowbit(x))
			b[x]+=d;
	}
	long long query(int x){
		long long ret=0;
		for(;x;x-=lowbit(x))
			ret+=b[x];
		return ret;
	}
}bit;
int main(){
	//freopen("in","r",stdin);
	N=read(),Q=read();
	for(int i=1;i<N;i++)
		ins(read(),read());
	dfs(1,0);
	while(Q--){
		int p=read(),v=read();
		bit.add(tid[p],v);
		bit.add(R[p]+1,-v);
	}
	for(int i=1;i<N;i++)
		printf("%I64d ",bit.query(tid[i]));
	printf("%I64d\n",bit.query(tid[N]));
	return 0;
}



Measured memory_bytes: 30080
import java.util.*;
import java.io.*;
public class Main {
  public static void main(String[] args) throws IOException,InterruptedException{
	Scanner sc =new Scanner(System.in);
	PrintWriter pw = new PrintWriter(System.out);
	int n =sc.nextInt(),m=sc.nextInt();
	char [][] arr=new char[n][m];
	for (int i=0;i<n;++i)
		arr[i]=sc.next().toCharArray();
	long mod =(int)1e9+7;
	long [] [] poss=new long [n][m];
	poss[0][0]=1;
	for (int i =0;i<n;++i)
		for (int j=0;j<m;++j) {
			if (arr[i][j]=='#')
				continue;
			poss[i][j]+=((i-1>=0&&arr[i-1][j]=='.')?poss[i-1][j]:0)%mod;
			poss[i][j]+=((j-1>=0&&arr[i][j-1]=='.')?poss[i][j-1]:0)%mod;
		}
	//System.out.println(Arrays.deepToString(poss));
	pw.println(poss[n-1][m-1]%mod);
	pw.flush();
  }
  static long gcd (long a ,long b)
  {
	  return (b==0)?a:gcd(b, a%b);
  }
  static long [] gcd2 (long a ,long b) {
	  if (b==0)
		  return new long [] {a,1,0};
	  long [] val =gcd2(b, a%b);
	  long gcd =val[0];
	  long x =val[2],y=val[1]-(a/b)*val[2];
	  return new long [] {gcd,x,y};
  }
  static class Scanner {
		StringTokenizer stringTokenizer;	
		BufferedReader bfBufferedReader;
		public Scanner(InputStream system) {
			bfBufferedReader=new BufferedReader(new InputStreamReader( system));
		}
		 public Scanner(String file) throws Exception {
	            bfBufferedReader = new BufferedReader(new FileReader( file));
	        }			 
	        public String next() throws IOException {
	            while (stringTokenizer == null || !stringTokenizer.hasMoreTokens())
	                stringTokenizer = new StringTokenizer( bfBufferedReader.readLine());
	            return stringTokenizer.nextToken();
	        }
	 
	        public String nextLine() throws IOException {
	            return bfBufferedReader.readLine();
	        }
	 
	        public int nextInt() throws IOException {
	            return Integer.parseInt(next());
	        }
	 
	        public double nextDouble() throws IOException {
	            return Double.parseDouble(next());
	        }
	 
	        public char nextChar() throws IOException {
	            return next().charAt(0);
	        }
	 
	        public Long nextLong() throws IOException {
	            return Long.parseLong(next());
	        }
	 
	        public boolean ready() throws IOException {
	            return bfBufferedReader.ready();
	        }
	 
	        public void waitForInput() throws InterruptedException {
	            Thread.sleep(3000);
	        }
  }
  }

Measured memory_bytes: 38096
/* 
 * Project: AtCoder Beginners Contest 174 B - Distance
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/08/02
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cmath>
using namespace std;

int n;
long d;
long x[200000];
long y[200000];

void solve() {

    int cnt = 0;

    for (int i=0;i<n;i++) {
        if (d*d >= x[i]*x[i] + y[i]*y[i]) {
            cnt++;
        }
    }
    printf("%d\n",cnt);

}

int main() {

    scanf("%d", &n);
    scanf("%ld", &d);
    for (int i=0;i<n;i++) {
        scanf("%ld", &x[i]);
        scanf("%ld", &y[i]);
    }

    solve();

}

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

using namespace std;

#define int long long
#define ll long long

#define N 3000005
int P[N];
int PI[N];
#define MOD 998244353

ll modInverse(ll a,ll m)
    {
        ll m0 = m;
        ll y = 0, x = 1;
         if(m == 1)
            return 0;
        while (a > 1)
            {
                int q = a / m;
                int t = m;
                m = a % m, a = t;
                t = y;
                y = x - q * y;
                x = t;
            }
        if (x < 0)
            x += m0;
        return x;
    }

void fun()
     {
         P[0]=1;
        int i;
         for(i=1;i<N;i++)
         {
            P[i]=(P[i-1]*i)%MOD;
         }
         for(i=0;i<N;i++)
         {
            PI[i]=modInverse(P[i],MOD);
         }
     }

int ncr(int n, int r)
{
        int ans = P[n];
        ans*=PI[r];
        ans%=MOD;
        ans*=PI[n-r];
        ans%=MOD;
        return ans;
}

int distribute(int x,int n)
{
        int ans = ncr(n+x-1,n-1);
        return ans;
}

int dp[N];

int32_t main()
{
        ios_base::sync_with_stdio(false);

        fun();
        

        int n, m;
        cin>>n>>m;
        
        int ans = 0;
        for(int i=0;i<=min(n,m);i++)
        {
                int left = m-i;
                if(left%2)
                        continue;
                int temp = m + left/2;
                int dis = distribute(temp, n);
                ans+=dis*ncr(n,i);
                ans%=MOD;
        }

        for(int i=2*m+1;i<=3*m;i++)
        {
                int temp = 3*m - i;
                temp = distribute(temp, n-1);
                ans-=temp*n;
                ans%=MOD;
                if(ans<0)
                        ans+=MOD;
        }
        cout<<ans<<endl;


        return 0;
}


Measured memory_bytes: 48128
import sys
sys.setrecursionlimit(10**6)


def main(input, print):
    N = int(input())
    a = list(map(int, input().split()))
    ans = 0
    for i in range(0, N, 2):
        if(a[i] % 2 == 1):
            ans += 1
    print(ans)


if __name__ == '__main__':
    main(sys.stdin.readline, print)


Measured memory_bytes: 61736
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<algorithm>
using std::cout;
using std::cin;
using std::endl;

int main(void){
    std::string number;
    int num[4];
    cin>>number;
    for(int i=0;i<4;i++){
        num[i]=(int)(number[i]-'0');
    }
    if(num[0]+num[1]+num[2]+num[3]==7) cout<<num[0]<<"+"<<num[1]<<"+"<<num[2]<<"+"<<num[3]<<"="<<7<<endl;
    else if(num[0]+num[1]+num[2]-num[3]==7) cout<<num[0]<<"+"<<num[1]<<"+"<<num[2]<<"-"<<num[3]<<"="<<7<<endl;
    else if(num[0]+num[1]-num[2]+num[3]==7) cout<<num[0]<<"+"<<num[1]<<"-"<<num[2]<<"+"<<num[3]<<"="<<7<<endl;
    else if(num[0]+num[1]-num[2]-num[3]==7) cout<<num[0]<<"+"<<num[1]<<"-"<<num[2]<<"-"<<num[3]<<"="<<7<<endl;
    else if(num[0]-num[1]+num[2]+num[3]==7) cout<<num[0]<<"-"<<num[1]<<"+"<<num[2]<<"+"<<num[3]<<"="<<7<<endl;
    else if(num[0]-num[1]+num[2]-num[3]==7) cout<<num[0]<<"-"<<num[1]<<"+"<<num[2]<<"-"<<num[3]<<"="<<7<<endl;
    else if(num[0]-num[1]-num[2]+num[3]==7) cout<<num[0]<<"-"<<num[1]<<"-"<<num[2]<<"+"<<num[3]<<"="<<7<<endl;
    else if(num[0]-num[1]-num[2]-num[3]==7) cout<<num[0]<<"-"<<num[1]<<"-"<<num[2]<<"-"<<num[3]<<"="<<7<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 200'000;
const int LOGN = 19;

int n, m, k;

void solve(int test)
{
  cin >> n;
  vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    --a[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
  }
  for (int i = 0; i < n - 1; ++i) {
    cin >> c[i];
  }
  int ans = 0;
  int prev = inf;
  for (int i = 0; i < n; ++i) {
    ans += b[a[i]];
    if (prev + 1 == a[i]) {
      ans += c[prev];
    }
    prev = a[i];
  }
  cout << ans << '\n';
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
    solve(i);
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 256
N, M = map(lambda x: int(x), input().split())
a = [int(input()) for _ in range(M)]
mod = 1e9+7

is_broken = [False]*(N+1)
for aa in a:
    is_broken[aa] = True

dp = [0]*(N+1)
dp[0] = 1

for now in range(N):
    for next in range(now+1, min(N, now+2)+1):
        if not is_broken[next]:
            dp[next] += dp[now]
            dp[next] %= mod
print(int(dp[N]))

Measured memory_bytes: 8616
input = input()
W,H,x,y,r = map(int ,input.split())
if x - r < 0 or x + r > W or y - r < 0 or y + r > H:
    print("No")
if x - r >= 0 and x + r <= W and y - r >= 0 and y + r <= H:
    print("Yes")


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

int main(void) {
	int N;
	cin >> N;

	int min_cnt = 32;
	for (int i = 0; i < N; ++i) {
		int x;
		cin >> x;
		int cnt = 0;
		while (x > 1) {
			if (x & 1)
				break;
			x >>= 1;
			++cnt;
		}
		min_cnt = min(cnt, min_cnt);
	}

	cout << min_cnt << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) printf("0\n");
	else printf("%lld\n", min(min((ll)a * b, (ll)a * c), (ll)b * c));
}


Measured memory_bytes: 256
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<string>
#include<cstdio>
#include<vector>
#include<cassert>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,a,b) for (int i=a; i<=b; i++)
#define per(i,a,b) for (int i=a; i>=b; i--)
#define debug(x) {cout<<(#x)<<" "<<x<<endl;}
using namespace std;
typedef long long LL;

inline int read() {
    int x=0,f=1; char ch=getchar();
    while (!(ch>='0'&&ch<='9')) {if (ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9') {x=x*10+(ch-'0'); ch=getchar();}
    return x*f;
}

const int N = 100005;

int n,R,C;
int tot=0;
struct data {
	int p,delta,id;
} a[N<<1];
inline bool cmp(const data &a,const data &b) {return a.p<b.p;}

inline bool onSide(int x,int y) {
	return (x==0)||(y==0)||(x==R)||(y==C);
}

inline int G(int x,int y) {
	if (x==0) return y;
	if (y==C) return C+x;
	if (x==R) return C+R+C-y;
	return C+R+C+R-x;
}

inline void getseg(int x1,int y1,int x2,int y2,int id1,int id2,data &a,data &b) {
	int l=G(x1,y1),r=G(x2,y2);
	if (l>r)swap(l,r);
	a.p=l,b.p=r;
	a.delta=1; b.delta=-1;
	a.id=id1,b.id=id2;
}

int main() {

	#ifndef ONLINE_JUDGE
	//	freopen("data.in","r",stdin);
	//	freopen("data.out","w",stdout);
	#endif

	R=read(),C=read(),n=read();
	rep(i,1,n) {
		int x1=read(),y1=read(),x2=read(),y2=read();
		if(onSide(x1,y1)&&onSide(x2,y2)) {
			getseg(x1,y1,x2,y2,tot+1,tot+2,a[tot+1],a[tot+2]); tot+=2;
		}
	}
	sort(a+1,a+tot+1,cmp);
	bool flag=1;
	int stk[N],top=0;
	rep(i,1,tot) {
		if (a[i].delta==-1) {
			if (a[i].id!=stk[top]+1) flag=0;
			else top--;
		}
		else stk[++top]=a[i].id;
	}
	if (flag) puts("YES");
	else puts("NO");

	return 0;
}


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

typedef long long ll;
const int N = 3002, mod = 1000000007;
int n, q, a[N], f[N][N];
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    for (int j = 1; j < i; j++) {
      if (a[j] < a[i]) f[i][j] = 1;
      if (a[j] > a[i]) f[j][i] = 1;
    }
  }
  int ans = 0, t = 1;
  while (q--) {
    (t <<= 1) %= mod;
    int x, y;
    scanf("%d%d", &x, &y);
    f[y][x] = f[x][y] = (ll) (f[x][y] + f[y][x]) * (mod + 1) / 2 % mod;
    for (int i = 1; i <= n; i++) if (i != x && i != y) {
      f[x][i] = f[y][i] = (ll) (f[x][i] + f[y][i]) * (mod + 1) / 2 % mod;
      f[i][x] = f[i][y] = (ll) (f[i][x] + f[i][y]) * (mod + 1) / 2 % mod;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < i; j++) {
      ans = (ans + (ll) f[j][i] * t) % mod;
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 35456
#include<bits/stdc++.h>
using namespace std;
string S;
int main(){
	cin>>S;
	int i=0;
	if(S.length()%2!=0){
		cout<<"No\n";
		return 0;
	}
	for(i=0;i<S.length();++i){
		if((i%2==0&&S[i]!='h')||((i&1)&&S[i]!='i')){
			cout<<"No\n";
			break;
		}
	}
	if(i!=S.length())return 0;
	else cout<<"Yes\n";
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main(){
    int H,W;
    cin >> H >> W;
    int eight[8][2]={{0,1},{0,-1},{-1,0},{1,0},{1,1},{-1,-1},{1,-1},{-1,1}};
    char S[H][W];
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> S[i][j];
        }
    }
    for(int h=0; h<H; h++){
        for(int w=0; w<W; w++){
            int cnt=0;
            if(S[h][w] == '.' ){
                for(int i=0; i<8; i++){
                    int ipos = eight[i][0];
                    int jpos = eight[i][1];
                    if(S[h+ipos][w+jpos] == '#' && h+ipos>=0 && w+jpos>=0 && h+ipos<H && w+jpos<W){
                        cnt++;
                    }
                }
                S[h][w] = cnt+'0';
            }
            cout << S[h][w];
        }
        cout << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
	string s;
	cin>>s;
	string b;
	cin>>b;
	int sum=0;
	for(int i=0;i<s.size();i++){
		if(s[i]!=b[i])sum++;
	}
	cout<<sum<<endl;
	return 0;
}


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

int main()
{
    ll n;
    cin >> n;
    ll hp = 0;
    ll x;
    if(n >= 500){
        x = n / 500;
        hp = x * 1000;
        n = n - (x * 500);
    }
    //cout << n << endl;
    if(n >= 5){
        x = n / 5;
        hp += x * 5;
        n = n - (x * 5);
    }
    cout << hp << endl;

    return 0;
}


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

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

using namespace std;

int main() {
  int n; cin >> n;
  int minAns = 1000000, maxAns = -1000000;
  long long sum = 0;
  REP(i, n) {
    int a; cin >> a;
    minAns = min(minAns, a);
    maxAns = max(maxAns, a);
    sum += a;
  }
  printf("%d %d %lld\n", minAns, maxAns, sum);
}


Measured memory_bytes: 3232
import java.util.Scanner;
import java.util.*;

public class Main {
        public static void main(String[] args) {
                Scanner scan = new Scanner(System.in);
		int ans = 0;
		for(int i = 0; i < 5; i++){

		int n = scan.nextInt();
		if(n == 0){
			ans = i + 1;
		}
		}

                System.out.println(ans);
    }
}


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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define LL long long

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}

const int maxc = 31;
const int maxn = 1e5+5;

struct tele{
    int s,t;
    tele(int s,int t):s(s),t(t){;}
    bool operator<(const tele &b){
        return s < b.s;
    }
};

vector<tele> channel[maxc];
vector<int> st;
vector<int> ed;

int N,C;


int main()
{
    cin >> N >> C;
    _for(i,0,N){
        int s,t,c;
        cin >> s >> t >> c;
        channel[c].push_back(tele(s,t));
    }
    _rep(i,1,C){
        sort(ALL(channel[i]));
        int sz =channel[i].size();
        _for(j,0,sz-1){
            if(channel[i][j+1].s == channel[i][j].t){
                channel[i][j+1].s = channel[i][j].s;
                channel[i][j].s = maxn;
            }
        }
        _for(j,0,sz){
            if(channel[i][j].s != maxn){
                st.push_back(channel[i][j].s);
                ed.push_back(channel[i][j].t);
            }
        }
    }

    sort(ALL(st));
    sort(ALL(ed));
    //cout <<st << endl;
    //cout << ed << endl;

    int ans = 0;
    int cnt = 0;
    int l = 0,r = 0;
    int szs = st.size();
    int szt = ed.size();
    _for(t,1,maxn){
        while(l < szs && st[l] == t){
            cnt++;
            l++;
            ans = max(ans,cnt);
        }
        while(r < szt && ed[r] == t){
            cnt--;
            r++;
        }
        if(l == szs) break;
    }

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


Measured memory_bytes: 2396
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define MXN 15000
int main(){
    char c[105];
    MEM(c);
    int k;
    scanf("%s %d",c,&k);
    LL ans=0;
    int same=1;
    for(int i = 1;c[i]!=0;i++){
        if(c[i]!=c[0])same=0;
    }
    for(int i=0;c[i+1]!=0;i++){
        if(c[i]==c[i+1]){
            ans++;
            i++;
        }
    }
    ans*=k;
    LL len=strlen(c);
    if(same){
        printf("%lld\n",k*len/2);
        return 0;
    }
    
    if(c[len-1]==c[0]){
        int a=0,b=0;
        for(int i = 0;c[i]==c[0];i++)a++;
        for(int i=len-1;c[i]==c[len-1];i--)b++;
        if((a&1)&&(b&1))
        ans+=k-1;
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 256