akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long ll;
ll n, m, num, mn = 9e15,a[3];
ll f(ll p, ll q, ll w) {
	a[0] = p;
	a[1] = q;
	a[2] = w;
	sort(a, a + 3);
	mn = min(mn, a[2] - a[0]);
}
int main()
{
	ll i;
	cin >> n >> m;
	if (n % 3 == 0) mn = min(mn, 0ll);
	else if (n > 3) mn = min(mn, m);
	if (m % 3 == 0) mn = min(mn, 0ll);
	else if (m > 3) mn = min(mn, n);
	for (i = 1; i < n; i++) {
		num = (n - i) * (m / 2);
//		else num = (n - i) * (m / 2 + 1);
		f(i * m, num, (n - i) * m - num);
	}
	for (i = 1; i < m; i++) {
		num = (m - i) * (n / 2);
//		else num = (m - i) * (n / 2 + 1);
		f(i * n, num, (m - i) * n - num);
	}
	cout << mn;
    return 0;
}


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

typedef long long ll;
ll A, B, C, D;

ll gcd(ll a, ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b){
  return a * b / gcd(a,b);
}


int main(void){
   cin >> A >> B >> C >>D;
   
   ll conly = 0;
   ll donly = 0;
   ll cdboth = 0;
   
   conly = (B/C) - ((A-1)/C);
   donly = (B/D) - ((A-1)/D);
   cdboth = (B/(lcm(C, D))) - ((A-1)/(lcm(C, D)));

   cout << (B-A+1) - (conly + donly - cdboth) << endl;
}


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

int main(int argc, char *argv[])
{
  int n, i, j, q, tmp;
  int *A;
  int x;

  scanf("%d", &n);
  A = (int *)malloc(sizeof(int) * n);
  for (i = 0; i < n; i++) scanf("%d", &A[i]);

  x = A[n-1];
  i = -1;
  for (j = 0; j < n - 1; j++) {
    if (A[j] <= x) {
      i++;
      tmp = A[j];
      A[j] = A[i];
      A[i] = tmp;
    }
  }
  tmp = A[n-1];
  A[n-1] = A[i+1];
  A[i+1] = tmp;
  q = i+1;

  for (i = 0; i < n; i++) {
    if (i != n - 1) {
      if (i == q) printf("[%d] ", A[i]);
      else printf("%d ", A[i]);
    } else {
      if (i == q) printf("[%d]\n", A[i]);
      else printf("%d\n", A[i]);
    }
  }

  return 0;
}

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

int main() {
  string s;
  cin>>s;
  int n;
  cin >> n;
  int to=n;
  rep(i,s.size()){
    if(n>0){
      if(s.at(i)!='a'&&'a'+26-s.at(i)<=n){
        n-='a'+26-s.at(i);
        s.at(i)='a';
      }
    }
  }
  n=(n+26)%26;
  int sa=s.at(s.size()-1)-'a';
  sa=(sa+n)%26;
  s.at(s.size()-1)='a'+sa;
  cout<<s<<endl;  
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x)      x.begin(), x.end()
#define rep(i,n)    for (int i = 0; i < (n); ++i)
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}

signed main()
{
    int H, W;
    int a[505][505];
    scanf("%d%d", &H, &W);

    rep(i, H) rep(j, W) scanf("%d", &a[i+1][j+1]);

    using P = tuple<int,int,int,int>;
    vector<P> ans;

    int x = 1;
    for (int y = 1; y <= H; ++y) {
        if (y & 1) {
            for(; x < W; ++x) {
                if (a[y][x] & 1) {
                    ans.emplace_back(y, x, y, x+1);
                    ++a[y][x+1];
                }
            }
        } else {
            for (; x > 1; --x) {
                if (a[y][x] & 1) {
                    ans.emplace_back(y, x, y, x-1);
                    ++a[y][x-1];
                }
            }
        }

        if (y < H && (a[y][x] & 1)) {
            ans.emplace_back(y, x, y+1, x);
            ++a[y+1][x];
        }
    }

    printf("%zu\n", ans.size());
    for (const auto &e : ans) {
        int a, b, c, d;
        tie(a,b,c,d) = e;
        printf("%d %d %d %d\n", a, b, c, d);
    }

    return 0;
}



Measured memory_bytes: 5232
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N;
	char C;
	while (!isdigit(C = getchar_unlocked()));
	N = C - '0';
	while (isdigit(C = getchar_unlocked())) N = N * 10 + C - '0';

	char S[300001];
	fread_unlocked(S, 1, N, stdin);

	int kotae = 1e9;
	int A = 0;
	rep(i, N) kotae = min(kotae, A - i + (A += S[i] == 'W'));

	co(kotae + N - 1 - A);

	Would you please return 0;
}

Measured memory_bytes: 512
from heapq import heappop, heappush

def prim(adjacent:list, root=0):
    n = len(adjacent)
    visited = [False] * n
    min_cost = 0
    q = [(0, root)]

    count = 0
    while q and count < n:
        weight, vi = heappop(q)
        if visited[vi]:
            continue
        visited[vi] = True
        min_cost += weight
        count += 1
        for vj, weight in adjacent[vi]:
            heappush(q, (weight, vj))
    return min_cost

n = int(input())
xordered = []
yordered = []
for i in range(n):
    x, y = map(int, input().split())
    xordered.append((x, y, i))
    yordered.append((y, x, i))
xordered.sort()
yordered.sort()

adjacent = [[] for _ in range(n)]
for i in range(n-1):
    x0, y0, v0 = xordered[i]
    x1, y1, v1 = xordered[i+1]
    weight = min(abs(x0-x1), abs(y0-y1))
    adjacent[v0].append((v1, weight))
    adjacent[v1].append((v0, weight))
    x0, y0, v0 = yordered[i]
    x1, y1, v1 = yordered[i+1]
    weight = min(abs(x0-x1), abs(y0-y1))
    adjacent[v0].append((v1, weight))
    adjacent[v1].append((v0, weight))

print(prim(adjacent))

Measured memory_bytes: 145180
#include<stdio.h>

int main(void){
	char ch;
	int counter[26]={},i;
	
	while(scanf("%c",&ch)!=EOF){
		if(ch>='a' &&ch<='z')
			counter[ch-'a']++;
		else if(ch>='A' && ch<='Z')
			counter[ch-'A']++;
	}
	for(i=0;i<26;i++){
		printf("%c : %d\n",i+'a',counter[i]);
	}
	return 0;
}

Measured memory_bytes: 540
// TEMPLATE {{{
#include <bits/stdc++.h>
using namespace std;
#ifndef LOCAL
#define OJ 1
#else
#define OJ 0
#endif
 
#define endl '\n'
#define TIMESTAMP merr << "Execution time: " << (double)clock()/CLOCKS_PER_SEC << " s.\n"
class C_ {}; template <typename T> C_& operator <<(C_& __m, const T& __s) { if (!OJ) cerr << "\E[91m" << __s << "\E[0m"; return __m; }
C_ merr;
 
struct __s { __s() { if (OJ) { ios_base::Init i; cin.sync_with_stdio(0); cin.tie(0); } } ~__s(){ TIMESTAMP; } } __S;
/// END OF TEMPLATE }}}

#define size_t unsigned long long

void no() {
    cout << "NO" << endl;
    exit(0);
}

void move(size_t& x, size_t& y, char c) {
    if (c == 'L') {
        y--;
    } else if (c == 'R') {
        y++;
    } else if (c == 'U') {
        x--;
    } else if (c == 'D') {
        x++;
    } else {
        assert(0);
    }
}

int main(void) {
    size_t h,w,n;
    cin >> h >> w >> n;
    size_t x, y;
    cin >> x >> y;
    string s,t;
    cin >> s >> t;

    size_t sx = x, sy = y;

    for (auto m : {"LR", "RL", "UD", "DU"}) {
        x = sx, y = sy;
        for (size_t i = 0; i < n; i++) {
            if (s[i] == m[0]) {
                move(x, y, s[i]);
            }
            if (x < 1 || x > h || y < 1 || y > w) no();
            if (t[i] == m[1]) {
                move(x, y, t[i]);
                if (x < 1 || x > h || y < 1 || y > w) move(x, y, m[0]);
            }
        }
    }
    cout << "YES" << endl;
}


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

int main() {
    string s;
    while(getline(cin, s), s != ".") {
        string t;
        for(auto c : s) {
            if(c == '(' || c == ')' || c == '[' || c == ']') t += c;
        }
        stack<char> st;
        bool ok = true;
        for(auto c : t) {
            if(c == '(' || c == '[') st.push(c);
            else if(c == ')') {
                if(st.empty() || st.top() != '(') {
                    ok = false;
                    break;
                }
                st.pop();
            } else if(c == ']') {
                if(st.empty() || st.top() != '[') {
                    ok = false;
                    break;
                }
                st.pop();
            }
        }
        ok &= st.empty();
        cout << (ok ? "yes" : "no") << endl;
    }
}



Measured memory_bytes: 3140
N, M = map(int, input().split())

ans = 0
for i in range(1,10 ** 5):
    ans += i * (100 * (N - M) + 1900 * M ) * ((0.5 ** M) * ((1 - (0.5 ** M)) ** (i - 1))) 
    
print(round(ans))

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

// #include <boost/algorithm/string/join.hpp>
// using boost::algorithm::join;
//
// #include "boost/multi_array.hpp"
// boost::multi_array<int, 3> dp;
// dp.resize(boost::extents[10][9][8]);
//
// #include <boost/multiprecision/cpp_dec_float.hpp>  // quite slowly
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision; // mp::log10
// using bigint = boost::multiprecision::cpp_int;
// using rational = mp::cpp_rational;  // double d = static_cast<double>(r);

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

//constexpr ll MOD = 1e9+7;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/4;
constexpr int INF=inf<int>;
constexpr ll LINF=inf<ll>;

#define Sort(x) sort(begin(x),end(x))
#define Reverse(x) reverse(begin(x),end(x))
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ull<<(n))
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,(v).size())

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
#define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  int N;
  cin >> N;
  REP(i, N) {
    int A;
    cin >> A;

    if (A%2) continue;

    if (A%3 && A%5) {
      cout << "DENIED" << endl;
      return 0;
    }
  }


  cout << "APPROVED" << endl;
  return 0;
}

/* vim: set expandtab shiftwidth=2 softtabstop=2 : */


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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define show_table(n, k, table) rep(i,n){ rep(j,k) cout << table[i][j] << " "; cout << endl;}

template<class T> void chmax(T& a,const T& b){a=max(a,b);}
template<class T> void chmin(T& a,const T& b){a=min(a,b);}

using namespace std;

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<60;
const int MAX_N = 100005;

int main(){
  int H,W,h,w; cin >> H >> W >> h >> w;
  if(H%h==0 && W%w==0){
    cout << "No" << endl;
    return 0;
  }else{
    cout << "Yes" << endl;
  }
  if(h==1){
    REP(i,1,H+1){
      REP(j,1,W+1){
        if(j%w==1) cout << int(1e6)-1 << " ";
        else if(j%w==0) cout << int(-1e6) << " ";
        else cout << "0 ";
      }
      cout << "" << endl;
    }
  }else if(w==1){
    REP(i,1,H+1){
      REP(j,1,W+1){
        if(i%h==1) cout << int(1e6)-1 << " ";
        else if(i%h==0) cout << int(-1e6) << " ";
        else cout << "0 ";
      }
      cout << "" << endl;
    }

  }
  else REP(i,1,H+1){
    REP(j,1,W+1){
      if(i%h==1 && j%w==1) cout << int(1e6)-1 << " ";
      else if(i%h==0 && j%w==0) cout << int(-1e6) <<  " " ;
      else cout << "0 ";
    }
    cout << "" << endl;
  }
  return 0;
}

Measured memory_bytes: 2176
import java.io.*;
import java.util.*;
import java.util.function.*;

final class Pair {
	int a, b;

	Pair(int a, int b) {
		this.a = a;
		this.b = b;
	}
}

class UnionFind {
	int[] parent;

	UnionFind(int size) {
		parent = new int[size];
		Arrays.fill(parent, -1);
	}

	int find(int i) {
		if (parent[i] < 0) return i;
		return parent[i] = find(parent[i]);
	}

	int size(int i) {
		return -parent[find(i)];
	}

	boolean same(int i, int j) {
		return find(i) == find(j);
	}

	boolean union(int i, int j) {
		i = find(i);
		j = find(j);
		if (i == j) return false;
		if (size(i) < size(j)) {
			int temp = i;
			i = j;
			j = temp;
		}

		parent[i] += parent[j];
		parent[j] = i;
		return true;
	}
}

final class Solver {
	void solve(Supplier<String> sc) {
		int N = Integer.parseInt(sc.get());
		int M = Integer.parseInt(sc.get());

		Pair[] pairs = new Pair[M];
		for (int i = 0; i < M; i++) {
			int A = Integer.parseInt(sc.get()) - 1;
			int B = Integer.parseInt(sc.get()) - 1;
			pairs[i] = new Pair(A, B);
		}


		UnionFind uf = new UnionFind(N);
		long[] unhappiness = new long[M];
		unhappiness[M - 1] = N * (N - 1L) / 2;
		for (int i = pairs.length - 1; i > 0; i--) {
			Pair pair = pairs[i];
			if (uf.same(pair.a, pair.b)) {
				unhappiness[i - 1] = unhappiness[i];
				continue;
			}

			unhappiness[i - 1] = unhappiness[i] - (long) uf.size(pair.a) * uf.size(pair.b);
			uf.union(pair.a, pair.b);
		}
		for (long l : unhappiness) {
			System.out.println(l);
		}
	}
}

class Main {
	public static void main(String... args) {
		System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		new Solver().solve(new Supplier<String>() {
			StringTokenizer line;

			public String get() {
				while (line == null || !line.hasMoreTokens()) try {
					line = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
				return line.nextToken();
			}
		});
		System.out.flush();
	}
}

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

int main() {
  string A, B, C;
  cin >> A >> B >> C;
  int a = A.size();
  int b = B.size();
  if (A[a-1] == B[0] && B[b-1] == C[0]) cout << "YES";
  else cout << "NO";
}


Measured memory_bytes: 256
#!/usr/bin/env ruby
# -*- coding:utf-8 -*-

module Geometry
  EPS = 1e-6
  class Point
    attr_accessor :x, :y
    
    def initialize(x = 0.0, y = 0.0)
      @x = x
      @y = y
    end
  
    def abs()
      return Math.sqrt(x*x + y*y)
    end
    
    def dot(p)
      return x * p.x + y * p.y
    end
    
    def cross(p)
      return x * p.y - y * p.x
    end
  
    def norm()
      return x*x + y*y
    end
    
    def -(p)
      return Point.new(x-p.x,y-p.y)
    end 
  end
  
  def ccw(a,b,c)
    b-=a
    c-=a
    return +1 if b.cross(c) > EPS
    return -1 if b.cross(c) < -EPS
    return +2 if b.dot(c) < 0 
    return -2 if b.norm() < c.norm()
    return 0
  end

  def convex_hull(ps)
    n, k = ps.length(), 0
    ps.sort!{|a,b| 
              if a.x == b.x
                a.y <=> b.y
              else
                a.x <=> b.x
              end
            }
    ch = Array.new(n * 2)
    i = 0
    while i < n
      k -= 1 while (k >= 2 && ccw(ch[k-2], ch[k-1], ps[i]) <= 0)
      ch[k] = ps[i]
      k, i = k + 1, i + 1
    end
    i,t = n - 2,k + 1
    while i >= 0
      k -= 1 while (k >= t && ccw(ch[k-2], ch[k-1], ps[i]) <= 0)
      ch[k] = ps [i]
      k, i = k + 1, i - 1
    end
    ch = ch[0...(k-1)]
    return ch
  end
end

include Geometry

n = 0
while (n = gets.to_i) > 0
  pts = []
  n.times do 
    x ,y = gets.split(',').map(&:to_f)
    pts.push(Point.new(x,y))
  end
  puts n - convex_hull(pts).size
end

Measured memory_bytes: 6020
import math
X = int(input())
maximumList = []

#32^2=1024なので、2～31までで試せばいい

if X <= 3:
    print(1)
else:    
    for b in range(2,math.ceil(X**0.5)):
        p = 2
        while b**p <= X:
            p += 1
        else:
            if b**(p-1) <= X:
                maximumList.append(b**(p-1))
    print(max(maximumList))

Measured memory_bytes: 3188
package main

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

var sc *bufio.Scanner

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 0), 1000000001*3)
	sc.Split(bufio.ScanWords)
	h, w, a, b := nextInt(), nextInt(), nextInt(), nextInt()

	for hi := 0; hi < b; hi++ {
		for wi := 0; wi < a; wi++ {
			fmt.Print("1")
		}
		for wi := a; wi < w; wi++ {
			fmt.Print("0")
		}
		fmt.Println("")
	}
	for hi := b; hi < h; hi++ {
		for wi := 0; wi < a; wi++ {
			fmt.Print("0")
		}
		for wi := a; wi < w; wi++ {
			fmt.Print("1")
		}
		fmt.Println("")
	}
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;
const long long INF = 1LL << 60;

int main()
{
    int n;
    cin >> n;
    ll ans = 0;
    rep(i, n)
    {
        ll a;
        cin >> a;
        ans += a - 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios_base::sync_with_stdio(false) , cin.tie(0) ;
#define all(v) v.begin(),v.end()
#define w(x) cout << (#x) << " is " << x << "\n" ;

int main()
{
    fast ;
//#ifndef ONLINE_JUDGE
//    freopen("input.txt","r",stdin);
//#endif
    string s,t;
    cin >> s >> t ;
    int i,c=0;
    for(i = 0 ; i < s.size() ; i++)
    {
        if(s[i]!=t[i])
            c++;
    }
    cout << c << "\n";
    return 0 ;
}


Measured memory_bytes: 3736
#include <stdio.h>
#include <math.h>
#include <stdbool.h>

bool isprime(int x);

int main(void) {
	int n = 0;
	int x = 0;
	int count = 0;

	scanf("%d", &n);

	for (; n > 0; n--) {
		scanf("%d", &x);

		if (isprime(x))
			count++;
	}

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

	return 0;
}

bool isprime(int x) {
	int i = 0;

	if (x == 2)
		return true;
	
	if (x < 2 || x % 2 == 0)
		return false;

	i = 3;
	while (i <= sqrt(x)) {
		if (x % i == 0)
			return false;
		i = i + 2;
	}

	return true;
}

Measured memory_bytes: 596
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

int H, W;
char m[1000][1000];
ll memo[1000][1000];

void init()
{
}

ll rec(int i, int j)
{
    if(i >= H || j >= W) return 0;
    if(m[i][j] == '#') return memo[i][j] = 0;
    if(i == H-1 && j == W-1) return memo[i][j] = 1;
    if(memo[i][j] != -1) return memo[i][j];
    ll ret = 0;
    ret += rec(i+1, j) % MOD;
    ret += rec(i, j+1) % MOD;
    ret %= MOD;
    memo[i][j] = ret;
    return ret;
}

void solve()
{
    REP(i, H){
        REP(j, W){
            memo[i][j] = -1;
        }
    }
    cout << rec(0, 0) << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H >> W;
    REP(i, H){
        REP(j, W){
            cin >> m[i][j];
        }
    }
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 9088
#![allow(non_snake_case)]

use std::io;
use std::str::FromStr;
use std::cmp::min;

macro_rules! parse_line {
    ($($t: ty),+) => ({
        let mut a_str = String::new();
        io::stdin().read_line(&mut a_str).expect("read error");
        let mut a_iter = a_str.split_whitespace();
        (
            $(
                a_iter.next().unwrap().parse::<$t>().expect("parse error"),
            )+
        )
    })
}

fn parse_line_to_vec<T: FromStr>() -> Vec<T> {
    let mut tmp = String::new();
    io::stdin().read_line(&mut tmp).expect("read error");
    return tmp.split_whitespace().filter_map(|s| T::from_str(s.trim()).ok()).collect();
}

fn main() {
    let (N, C) = parse_line!(usize, usize);
    let mut D = Vec::<Vec<u32>>::new();
    let mut c = Vec::<Vec<u32>>::new();
    for _ in 0..C {
        D.push(parse_line_to_vec());
    }
    for _ in 0..N {
        c.push(parse_line_to_vec());
    }

    let mut color_counts = Vec::new();
    for i in 0..3 {
        color_counts.push(Vec::new());
        color_counts[i].resize(C as usize, 0);
    }
    for i in 0..N {
        for j in 0..N {
            color_counts[((i + j) % 3) as usize][c[i][j] as usize - 1] += 1;
        }
    }

    let mut min_cost = u32::max_value();
    for c0 in 0..C {
        for c1 in 0..C {
            if c0 == c1 {
                continue;
            }
            for c2 in 0..C {
                if c0 == c2 || c1 == c2 {
                    continue;
                }
                let mut cost = 0u32;
                for j in 0..C {
                    cost += color_counts[0][j] * D[j][c0];
                    cost += color_counts[1][j] * D[j][c1];
                    cost += color_counts[2][j] * D[j][c2];
                }
                min_cost = min(min_cost, cost);
            }
        }
    }
    println!("{}", min_cost);
}

Measured memory_bytes: 4352
#include<algorithm>

#define MAX_N 1001

using namespace std;

int BinSearch(int v[], int vsize, int search){
	int l = 0;
	int r = vsize;
	int m = 0;
	if( v[r - 1] < search ){
		return r - 1;
	}else if(v[1] > search ){
		return 0;
	}
	while( r - 1 > l ){
		m = (r + l) / 2;

		if( v[m] > search ){
			r = m;
		}else if(v[m] == search){
			return m;
		}else{
			l = m;
		}
	}
	return m;
}

void Merge(int a[], int p ,int q, int r){
	int i, j;
	int n1 = q - p + 1;
	int n2 = r - q;
	int *L = (int *)malloc(sizeof(int)*n1);
	int *R = (int *)malloc(sizeof(int)*n2);

	for(i = 0; i < n1; i++)
		L[i] = a[p + i];

	for(j = 0; j < n2; j++)
		R[j] = a[q + j + 1];

	i = 0;
	j = 0;

	for(int k = p; k < r; k++){
		if( i == n1 ){
			while( j < n2 ){
				a[k] = R[j];k++;j++;
			}
			break;
		}else if( j == n2 ){
			while( i < n1 ){
				a[k] = L[i];k++;i++;
			}
			break;
		}else{
			if( L[i] <= R[j] ){
				a[k] = L[i];
				i++;
			}else{
				a[k] = R[j];
				j++;
			}
		}
	}

	free(L);
	free(R);
}

void InsertionSort(int *a, int n){
	for(int i = 1; i < n; i++){
		int v = a[i], j;
		for(j = i; j > 0; j--)
			if( v < a[j - 1])
				a[j] = a[j - 1];
			else
				break;
		a[j] = v;
	}
}

void MergeSort(int a[], int p, int r){
	if( p < r ){
		if( r - p < 10 ){
			InsertionSort(a + p, r + 1 - p);
			return ;
		}
		int q = (p + r) / 2;
		MergeSort(a, p, q);
		MergeSort(a, q + 1, r);
		Merge(a, p, q, r);
	}
}

int main(void){
	while( true ){
		int prevQ = -1;
		int index = 0;
		int Max = 0;
		int N, M;
		int *Q;
		int V[MAX_N];

		cin >> N >> M;
		
		if( N == 0 && M == 0 ){
			break;
		}

		for(int i = 0; i < N; i++){
			cin >> V[i];
		}
		V[N] = 0;
		N++;

		Q = new int[N*N];

		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				Q[i * N + j] = V[i] + V[j];
			}
		}

		sort(Q, Q+N*N);
		//0, N * N - 1);

		for(int i = 0; i < N * N; i++){
			if( prevQ == Q[i] ){
				continue;
			}else{
				prevQ = Q[i];
			}
			int optim = BinSearch(Q, N*N, M - Q[i]);
			if( optim > 0 && Q[i] + Q[optim] > M) optim--;
			Max = max( Max , Q[i] + Q[optim] > M ? 0 : Q[i] + Q[optim]);
		}

		delete[] Q;
		cout << Max << '\n';
	}
	return 0;
}

Measured memory_bytes: 5180
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	//adjMatrix[u][v] = 1 if there is an edge from u to v, otherwise 0
	private int[][] adjMatrix;
	//adjWeight[u][v] -- the weight of the edge from u to v if there is one
	private int[][] adjWeight;
	//if a node is settled (e.g., processed in the Dijkstra's algorithm)
	private Boolean[] ifSettled;
	public Graph() { totalVertex = 0; }
	public int getTotalVertex() { return totalVertex; }
	//load graph from standard input
	public void loadAdjMatrix() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjMatrix = new int[totalVertex][totalVertex];
		adjWeight = new int[totalVertex][totalVertex];
		ifSettled = new Boolean[totalVertex];
		int i, j;
		for(i = 0; i < totalVertex; i ++) {
			ifSettled[i] = false;
			for(j = 0; j < totalVertex; j ++) {
				adjMatrix[i][j] = adjWeight[i][j] = 0;
			}
		}
		int u, v;
		for(i = 0; i < totalVertex; i ++) {
			u = in.nextInt();
			int degree = in.nextInt();
			for(j = 0; j < degree; j ++) {
				v = in.nextInt(); 
				adjMatrix[u][v] = 1;
				adjWeight[u][v] = in.nextInt();
			}	
		}
		in.close();
	}
	//return weight of the edge from u to v if there is one
	public int getWeight(int u, int v) {
		return adjWeight[u][v];
	}
	//return neighbors of u as a LinkedList
	public LinkedList<Integer> getNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if(adjMatrix[u][v] == 1) tmp.add(v);
		}
		return tmp;
	}
	//return unsettled neighbors of u as a LinkedList
	public LinkedList<Integer> getUnsettledNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if((adjMatrix[u][v] == 1) && (ifSettled[v] == false)) tmp.add(v);
		}
		return tmp;
	}
	//return the unsettled node that has the smallest dist
	public int getUnsettledNearest(int[] dist) {
		int md = Integer.MAX_VALUE;
		int mv = -1;
		int v;
		for(v = 0; v < totalVertex; v ++) {
			if((ifSettled[v] == false) && (dist[v] < md)) {
				md = dist[v];
				mv = v;
			}
		}
		return mv;
	}
	public boolean djikstraDone(Boolean[] b) {
		for (int i=0; i<b.length; i++) {
			if (b[i]==false) {
				return false;
			}
		}
		return true;
	}
	//implement the following	
	public int[] Dijkstra(int s) {
		int[] dist = new int[this.getTotalVertex()];
		for (int i=0; i<dist.length; i++) {
			dist[i] = Integer.MAX_VALUE;
		}
		dist[s] = 0;
		int recent = getUnsettledNearest(dist);
		while ((recent!=-1) && (dist[recent]!=Integer.MAX_VALUE)) {
			ifSettled[recent] = true;
			LinkedList<Integer> neighbors = getUnsettledNeighbors(recent);
			for (Integer neighbor : neighbors) {
				dist[neighbor] = Math.min(dist[recent] + getWeight(recent, neighbor), dist[neighbor]);
			}
			recent = getUnsettledNearest(dist);
		}
		return dist;
	}
}

public class Main {
	public static void main(String[] argv) {
		Graph g = new Graph();
		g.loadAdjMatrix();
		int[] dist = g.Dijkstra(0);
		for(int i = 0; i < g.getTotalVertex(); i ++) {
			System.out.println(i + " " + dist[i]);
		}
	}
}


Measured memory_bytes: 39504
def main():
    import sys
    import bisect
    input = sys.stdin.readline

    n, m = map(int, input().split())
    query = []
    result =  [[] for i in range(n)]
    for _ in range(m):
        p, y = map(int, input().split())
        query.append((p, y))
        result[p-1].append(y)

    result = [sorted(i) for i in result]
 
    for city in query:
        rank = bisect.bisect_left(result[city[0]-1], city[1])
        ans = "%06d%06d"%(city[0],rank+1)
        print(ans)

main()

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

int main(){
    int n;
    cin >> n;
    vector<int> x(n);
    rep(i,n) cin >> x.at(i);
    int ans = INF;
    for(int i = 1;i <= 100;i++){
        int sum = 0;
        rep(j,n) sum += pow(x.at(j) - i,2);
        ans = min(ans,sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3600
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

dist = {}
for idx, d in enumerate(A):
  dist[idx+1] = d

n = 1
hist = [1]
already = {1}
flag = True
for i in range(K):
  n = dist[n]
  if n in already:
    flag = False
    break
  already.add(n)
  hist.append(n)
if flag:
  print(n)
else:
  start = hist.index(n)
  loop = hist[start:]
  print(loop[(K - start) % len(loop)])


Measured memory_bytes: 48424
#include <cstdio>
#include <cstring>

using namespace std;
    
const int maxn=55;  
char mp[maxn][maxn];  
int f[maxn][maxn]; 
 
int main(){  
    int h,w;  
    scanf("%d%d",&h,&w);  
    memset(f,0,sizeof(f));  
    for(int i=0;i<h;i++){  
        scanf("%s",mp[i]);  
    }  
    for(int i=0;i<h;i++){  
        for(int j=0;j<w;j++){  
            if(mp[i][j]=='#'){  
                if(i-1>=0){  
                    f[i-1][j]++;  
                }  
                if(j-1>=0){  
                    f[i][j-1]++;  
                }  
                if(i+1<h){  
                    f[i+1][j]++;  
                }  
                if(j+1<w){  
                    f[i][j+1]++;  
                }  
                if(i-1>=0&&j-1>=0){  
                    f[i-1][j-1]++;  
                }  
                if(i+1<h&&j-1>=0){  
                    f[i+1][j-1]++;  
                }  
                if(i-1>=0&&j+1<w){  
                    f[i-1][j+1]++;  
                }  
                if(i+1<h&&j+1<w){  
                    f[i+1][j+1]++;  
                }  
            }  
        }  
    }  
    for(int i=0;i<h;i++){  
        for(int j=0;j<w;j++){  
            if(mp[i][j]=='#') printf("#");  
            else printf("%d",f[i][j]);  
        }printf("\n");  
    }  
    return 0;  
} 


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

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

#define fr first
#define sc second

const ll MOD = 1000000007;

ll modpow(ll x,ll k){
	if(k == 0)return 1;
	ll ret = modpow(x,k/2);
	ret *= ret; ret %= MOD;
	if(k%2 == 1){
		ret *= x; ret %= MOD;
	}
	return ret;
}

struct node{
	node* par;
	set<node*> ch;
	ll cnt,a,b;
	ll dp0,dp1;
	ll id;
} v[200010];

void add_edge(node* x,node* y){
	y->par = x;
	x->ch.insert(y);
}
void redu(node* x){
	if(x->par == nullptr)return;
	x->par->ch.erase(x);
	add_edge(x->par,*(x->ch.begin()));
}
void eras(node* x){
	if(x->par == nullptr)return;
	//cout << "eras" << x->id << endl;
	x->par->ch.erase(x);
	if(x->par->ch.size() == 0)eras(x->par);
	else if(x->par->ch.size() == 1)redu(x->par);
}
void run(node* x){
	x->cnt = 0;
	x->a = 1;
	x->b = 0;
	if(x->ch.size() == 0){
		x->cnt = 1;
		x->dp0 = 1;
		x->dp1 = 1;
		return;
	}
	for(set<node*>::iterator itr = x->ch.begin() ; itr != x->ch.end() ; ++itr){
		run(*itr);
		x->cnt += (*itr)->cnt;
		x->a *= (*itr)->dp1;
		x->b += (*itr)->dp0*modpow((*itr)->dp1,MOD-2);
		x->a %= MOD;
		x->b %= MOD;
	}
	x->dp0 = x->a*x->b; x->dp0 %= MOD;
	x->dp1 = modpow(2,x->cnt)+MOD-x->dp0; x->dp1 %= MOD;
}

int n;
vector<int> G[200010];
int p[200010];
int dep[200010];
vector<int> ch[200010];
void dfs(int v,int par,int d){
	p[v] = par;
	dep[v] = d;
	for(int i = 0 ; i < G[v].size() ; i ++){
		if(G[v][i] == par)continue;
		dfs(G[v][i],v,d+1);
		ch[v].push_back(G[v][i]);
	}
}

int main(){
	scanf("%d",&n);
	for(int i = 1 ; i <= n ; i ++){
		scanf("%d",&p[i]);
		G[p[i]].push_back(i);
		G[i].push_back(p[i]);
	}
	dfs(0,-1,0);
	
	vector<P> vec;
	for(int i = 0 ; i <= n ; i ++){
		vec.push_back(P(dep[i],i));
	}
	sort(vec.begin(),vec.end());
	
	for(int i = 0 ; i < 200010 ; i ++){
		v[i].par = nullptr;
		v[i].id = i;
	}
	ll ret = modpow(2,n);
	for(int i = 0 ; i < vec.size() ; i ++){
		//cout << i << endl;
		int x = vec[i].sc;
		if(ch[x].size() == 0)eras(&v[x]);
		else if(ch[x].size() == 1){
			add_edge(&v[x],&v[ch[x][0]]);
			redu(&v[x]);
		}
		else {
			for(int j = 0 ; j < ch[x].size() ; j ++){
				add_edge(&v[x],&v[ch[x][j]]);
			}
		}
		//puts("DEBUG");
		if(i+1 != vec.size() && vec[i].fr != vec[i+1].fr){
			run(&v[0]);
			//cout << i << " " << v[0].cnt << " " << v[0].dp0 << endl;
			ret += modpow(2,n+1-v[0].cnt)*v[0].dp0;
			ret %= MOD;
		}
	}
	cout << ret << endl;
}

Measured memory_bytes: 70512
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  string S;
  cin>>S;
  for(auto c:S){
    cout<<'x';
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define mod (ll)(1e9+7)
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<(x)<<endl
#define ps(x) cout<<(x);
#define pk(x) cout<<(x)<<" ";
#define pfix(d,x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
#define fi first
#define se second
ll a[100001],b[100001],c[100001],d,n,m,x,y,z,h,w,k,sum,mi=inf,ma=-inf,ans,s,t,l,r,res,tmp,itr,p,q;
bool flag;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int dx8[8]={1,1,0,-1,-1,-1,0,1},dy8[8]={0,1,1,1,0,-1,-1,-1};
char cha;
string st;
typedef map<ll, ll> imap;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<pair<ll,ll> > VP;
P pa;
int main(){
    cin>>h;
    x=1;
    while(h>0){
        h/=2;
        sum+=x;
        x*=2;
    }
    p(sum);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int X,Y,Z;
    cin >> X >> Y >> Z;
    while(X){
        int maxi = 0;
        rep(i,1,Z+1)rep(j,1,Z+1){
            int num = (i * (100 + X) / 100) + (j * (100 + X) / 100);
            if(num == Z)maxi = max(maxi, (i * (100 + Y) / 100 ) + (j * (100 + Y) / 100));
        }
        cout << maxi << endl;
        cin >> X >> Y >> Z;
    }
}


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

int n, m, x, costn = 0, costnol = 0, a, tol[110];
int main()
{
    cin >> n >> m >> x;
    for (int i = 1; i <= m; i++)
    {
        cin >> a;
        tol[a] = 1;
    }
    for (int i = x; i <= n; i++)
    {
        if (tol[i] > 0)
        {
            costn++;
        }
        
    }
    for (int i = x; i >= 0; i--)
    {
        if (tol[i] > 0)
        {
            costnol++;
        }
        
    }
    cout << min(costn, costnol) << endl;
}

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


public class Main {

    private static BufferedReader br;
    private static StreamTokenizer st;
    private static PrintWriter pw;

    static final int INF = 1000000007;
    static final int MOD = 1000000007;

    private static void solve() throws IOException {
        int n = nextInt();
        int cnt = 0;
        for (int i = 1; i <= n; i++) {
            if (nextInt() != i) {
                cnt++;
            }
        }
        if (cnt == 0 || cnt == 2) {
            pw.println("YES");
        } else {
            pw.println("NO");
        }
    }

    static long gcd(long a, long b) {
        if (a < b) {
            a ^= b;
            b ^= a;
            a ^= b;
        }
        while (b != 0) {
            long t = a % b;
            a = b;
            b = t;
        }
        return a;
    }

    static long inv(long t, long p) {
        return t == 1 ? 1 : (p - p / t) * inv(p % t, p) % p;
    }

    public static void main(String args[]) throws IOException {
//        System.out.println(System.getProperty("java.library.path"));

//        boolean oj = System.getProperty("ONLINE_JUDGE") != null;
//        if (!oj) {
//            System.setIn(new FileInputStream("src/in.txt"));
//            System.setOut(new PrintStream("out.txt"));
//        }
        br = new BufferedReader(new InputStreamReader(System.in));
        st = new StreamTokenizer(br);
        pw = new PrintWriter(new OutputStreamWriter(System.out));
        st.ordinaryChar('\'');
        st.ordinaryChar('\"');
        st.ordinaryChar('/');

//        long t = System.currentTimeMillis();
        solve();
//        if (!oj) {
//            pw.println("[" + (System.currentTimeMillis() - t) + "ms]");
//        }
        pw.flush();
    }

    private static long[] anLong(int n) throws IOException {
        long a[] = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    private static String next(int len) throws IOException {
        int b = br.read();
        while (b == '\n' || b == ' ' || b == '\r' || b == '\t') {
            b = br.read();
        }
        char ch[] = new char[len];
        ch[0] = (char) b;
        int idx = 1;
        while (idx < len && (b = br.read()) != ' ' && b != '\n' && b != '\r' && b != '\t') {
            ch[idx++] = (char) b;
        }
        return String.valueOf(ch).trim();
    }

    private static int nextInt() throws IOException {
        st.nextToken();
        return (int) st.nval;
    }

    private static long nextLong() throws IOException {
        return Long.parseLong(nextLine());
    }

    private static double nextDouble() throws IOException {
        st.nextToken();
        return st.nval;
    }

    private static String[] nextSS(String reg) throws IOException {
        return br.readLine().split(reg);
    }

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

Measured memory_bytes: 21332
N, S = map(int, input().split())
A = [int(a) for a in input().split()]
X = [0] * 3001
ans = 0
P = 998244353
for i, a in enumerate(A):
    X[0] += 1
    for j in range(S, a-1, -1):
        X[j] = (X[j] + X[j-a]) % P
    ans += X[S]
print(ans % P)

Measured memory_bytes: 42220
def main():
    N = int(input())
    A = list(map(int, input().split()))

    Asum = sum(A)
    rem = N * (N + 1) // 2
    if Asum % rem != 0:
        return False

    K = Asum // rem
    A.append(A[0])
    dif = [r - l for l, r in zip(A[:-1], A[1:])]
    for d in dif:
        if d > K:
            return False
        if (K - d) % N != 0:
            return False
    return True


if __name__ == "__main__":
    if main():
        print("YES")
    else:
        print("NO")
        

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

using namespace std;

using int64 = long long;
const int64 LINF = 1LL << 61;
const int INF = 1 << 30;

int main()
{
  string S;
  cin >> S;
  S[3] = '8';
  cout << S << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
H = [int(h) for h in input().split()]
flag = [1 for i in range(N)]
for i in range(M):
  a, b = map(int, input().split())
  if H[a-1] <= H[b-1]:
    flag[a-1] = 0
  if H[a-1] >= H[b-1]:
    flag[b-1] = 0
print(sum(flag))

Measured memory_bytes: 20088
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <string>
#include <queue>
#include <map>
#include <set>

using namespace std;

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

const int Maxn = 1010;
const int INF = (int) 1e9;

char f[Maxn][Maxn];
int d[Maxn][Maxn];

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int h, w;
    cin >> h >> w;
    queue<P> que;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> f[i][j];
            if (f[i][j] == '.') d[i][j] = INF;
            else que.push(P(i, j));
        }
    }

    int ans = 0;
    while (!que.empty()) {
        auto p = que.front();
        que.pop();
        for (int i = 0; i < 4; ++i) {
            int nx = p.first + dx[i], ny = p.second + dy[i];
            if (0 <= nx && nx < h && 0 <= ny && ny < w && d[nx][ny] == INF) {
                d[nx][ny] = d[p.first][p.second] + 1;
                ans = max(ans, d[nx][ny]);
                que.push(P(nx, ny));
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 11408
#include <stdio.h>
int main()
{
	int i,j,k=0,kazu=0,a=0;
	char ring[101][101],n[101];
	scanf("%s %d",n,&i);
	
	for(j=0;j<i;j++){
		scanf("%s",ring[j]);
	}
	for(j=0;j<i;j++){
		a=0;
		for(k=0;k<10;k++){
			if(n[a]==ring[j][k]){
				a++;
				if(n[a]=='\0'){
					kazu++;
					break;
				}
				else if(ring[j][k+1]=='\0'){
					k=-1;
				}
				
			}
		}
	}
	printf("%d\n",kazu);
		return 0;
}



Measured memory_bytes: 2100
import sys
input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def func(N, mod):
    F = [1]
    for i in range(1, N + 1):
        F.append(F[-1] * i % mod)
    return F


def inv(a, mod):
    return pow(a, mod - 2, mod)


def C(F, a, b, mod):
    return F[a] * inv(F[b], mod) * inv(F[a - b], mod) % mod


def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    if A[0] != 0:
        print(-1)
        return
    
    for i in range(N - 1):
        if A[i + 1] - A[i] > 1:
            print(-1)
            return
    
    res = 0
    c = 0
    for a in A[::-1]:
        if c < a:
            res += a
            c = a
        c -= 1
    print(res)


if __name__ == "__main__":
    main()



Measured memory_bytes: 12584
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, k; cin >> n >> k;
    vector<double> v(k+1, 0);
    for (int i = 1; i <= n; i++) {
        v[min(i, k)] += (double) 1 / n;
    }
    for (int i = 1; i < k; i++) {
        v[min(k, i*2)] += v[i] / 2;
        v[0] += v[i] / 2;
    }
    printf("%.12f\n", v[k]);
    return 0;
}

Measured memory_bytes: 1024
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <math.h> // sqrt
using namespace std;

int str(long long N) {
    int ans = 1;
    long long num = 26;
    while (true) {
        if (N <= num) {
         return ans;
        }
        ans++;
        num *= 26;
    }
}

int main() {
    long long N;
    cin >> N;
    long long ansn;
    char ans;
    int s = str(N);
    string anss(s, ' ');
    int i = 0;
    while (true) {
        ansn = ((N - 1) % 26);
        ans = 'a' + ansn;
        anss.at(s - 1 - i) = ans;
        N--;
        i++;
        N = floor(N / 26);
        if (N == 0) {
            cout << anss << endl;
            return 0;
        }
    }

}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pr(a) cout << (a) << endl
#define PR(a,b) cout << (a) << " " << (b) << endl;
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000001;
const ll MAXL=1000000000000000001LL;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

string s;
string::iterator p;
int fact();
int term();
int exp();

int fact() {
  int x;
  string num;
  while(isdigit(*p)) {
    num += *p;
    ++p;
  }
  if(num.size()) {
    x = atoi(num.c_str());
  } else {
    ++p;
    x = exp();
    ++p;
  }
  return x;
}
 
int term() {
  int x = fact();
  while(*p == '*' || *p == '/') {
    if(*p == '*') {
      ++p;
      x *= fact();
    } else {
      ++p;
      x /= fact();
    }
  }
  return x;
 
}
 
int exp() {
  int x = term();
  while(*p == '+' || *p == '-') {
    if(*p == '+') {
      ++p;
      x += term();
    } else {
      ++p;
      x -= term();
    }
  }
  return x;
}

int main() {
  int n;
  cin >> n;
  while(n--) {
    cin >> s;
    p = s.begin();
    cout << exp() << endl;
  }
  return 0;
}


Measured memory_bytes: 1220
#include <stdio.h>

int main(void)
{
	int W, H, x, y, r,i;
	i = 0;

	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if ((x, y >= -100) && (x, y <= 100) && (W, H, r > 0) && (W, H, r <= 100))
	{
		if ((y + r <= H) && (x + r <= W) && (y - r >= 0) && (x - r >= 0))
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	return 0;
}


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

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

    int n;
    cin >> n;

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

    int ans = 0;
    int x = 1;
    for(int i = 0; i < n; i++){
        if(a[i] == x){
            x++;
        } else {
            ans++;
        }
    }
    if(ans == n) ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MOD 1000000007
typedef long long  ll;

using namespace std;

// 素因数分解
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) { // √n以下にしか約数(素数)はない
		while (n % i == 0) { // 小さい数(2)からスタートすることで必ず素数のみがこのループに入る
			ret[i]++; // 何回割り切れるのかで何条か判断する
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1; // 最後に残った数を追加
	return ret;
}

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

	ll N,P;
	cin >> N >> P;

	ll ans = 1;

	map<ll, ll> m = prime_factor(P);

	for(auto p : m){
		ans *= pow(p.first,p.second/N);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4072