akhauriyash/Code-Regression huggingface dataset:
import java.lang.Exception
import java.lang.IllegalArgumentException
import java.util.*

val dx = listOf(1, 1, 1, 0, 0, -1, -1, -1)
val dy = listOf(1, 0, -1, 1, -1, 1, 0, -1)

var map: Array<IntArray> = emptyArray()
var seen: Array<BooleanArray> = emptyArray()
val SEA = 0
val LAND = 1
var height = -1;
var width = -1;


var sc = Scanner(System.`in`)
var count = 0
fun main(args: Array<String>) {

    try {
        while (true) {
            solve()
        }
    } catch (e: Exception) {
        return
    }
}

private fun solve() {

    width = sc.nextInt()
    height = sc.nextInt()

    if(width == 0 && height == 0){
        throw IllegalArgumentException()
    }

    map = Array(height) { IntArray(width) }
    seen = Array(height) { BooleanArray(width) }
    count = 0
    for (h in 0 until height) {
        for (w in 0 until width) {
            map[h][w] = sc.nextInt()
            if (map[h][w] == SEA) seen[h][w] = true
        }
    }


    for (w in 0 until width) {
        for (h in 0 until height) {
            if (seen[h][w]) {
                continue
            }
            if (map[h][w] == LAND) {
                count++
                dfs(h, w)
            }
        }
    }
    println(count)

}

private fun dfs(h: Int, w: Int) {
    if (seen[h][w]) {
        return
    }
    seen[h][w] = true
    for ((x, y) in dx.zip(dy)) {
        val ny = h + y
        val nx = w + x
        if (ny < 0 || nx < 0 || ny >= height || nx >= width) continue
        dfs(ny, nx)
    }
}



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

#define ll long long

int n,x,y,c[2001];
vector<ll>adj[2001];

int main()
{
//    freopen("a.in","r",stdin);
    cin>>n>>x>>y;
    for(int i=1;i<n;i++)
    {
        adj[i].push_back(i+1);
        adj[i+1].push_back(i);
    }
    adj[x].push_back(y);
    for(int i=1;i<n;i++)
    {
        int d[2001]={0};
        bool visit[2001]={0};
        visit[i]=1;
        queue<ll>q;
        q.push(i);
        while(q.size())
        {
            ll u=q.front();
            q.pop();
            for(int j=0;j<adj[u].size();j++)
            {
                if(!visit[adj[u][j]])
                {
                    visit[adj[u][j]]=1;
                    q.push(adj[u][j]);
                    d[adj[u][j]]=d[u]+1;
                }
            }
        }
        for(int j=i;j<=n;j++)
            c[d[j]]++;

    }
    for(int i=1;i<n;i++)
        cout<<c[i]<<endl;
}




Measured memory_bytes: 384
S = gets.chomp
N = S.length

MOD = 10**9+7

a = Array.new(N+1, 0)
c = Array.new(N+1, 0)

sum = 1
N.times do |i|
    if S[i] == 'A'
        a[i] = a[i-1] + sum
    elsif S[i] == '?'
        a[i] = 3*a[i-1] + sum
        sum = sum * 3 % MOD
    else
        a[i] = a[i-1]
    end
    a[i] %= MOD
end

sum = 1
(N-1).downto(0) do |i|
    if S[i] == 'C'
        c[i] = c[i+1] + sum
    elsif S[i] == '?'
        c[i] = 3*c[i+1] + sum
        sum = sum * 3 % MOD
    else
        c[i] = c[i+1]
    end
    c[i] %= MOD
end

ans = 0
(1..(N-2)).each do |i|
    if S[i] == 'B' || S[i] == '?'
        ans += a[i-1] * c[i+1]
        ans %= MOD
    end
end
puts ans

Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int N;
int a[100000];
vector<int> c;

int main(){
    cin >> N;
    c.resize(100000);
    for(int i=0;i<N;i++) cin >> a[i];
    for(int i=0;i<100000;i++) c[i] = 0;
    for(int i=0;i<N;i++){
        if(a[i]!=0) c[a[i]-1]++;
        c[a[i]]++;
        if(a[i]!=99999) c[a[i]+1]++; 
    }
    sort(c.begin(),c.end(),greater<int>());
    cout << c[0] << endl;
    return 0;
}

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

using namespace std;

int main()
{
    int n,i,ar[1000],j;
    vector<int>v;
    vector<int>::iterator it,its;
    its=v.begin();
    cin>>n;
    for (i=0;i<n;++i){

        cin>>ar[i];

    }

    for (i=0;i<n;++i){

        if (ar[i]>(i+1)){

            cout<<-1<<endl;
            return 0;

        }
        else{

            for(j=1;j<ar[i];++j)++its;
            v.insert(its,ar[i]);
            its=v.begin();

        }

    }
    for (it=v.begin();it!=v.end();++it){

        cout<<*it<<endl;

    }

    return 0;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int inf = 1e8;
#define maxn 300005
int f[maxn][3],n;
char t[maxn];

int main(){
	scanf("%s",t+1);
	n=std::strlen(t+1);
	for(int i=1;i<=n;++i){
		if(t[i]=='?')printf("D");
		else printf("%c",t[i]);
	}
	return 0;
}



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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ll x;
  cin >> x;
  
  if(x < 1000)
    cout << "ABC" << endl;
  else
    cout << "ABD" << endl;
  
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.util.Map;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.nextInt();
            int M = in.nextInt();
            List<C.City> list = new ArrayList<>();
            Map<Integer, List<C.City>> map = new HashMap<>();
            for (int i = 0; i < M; i++) {
                int P = in.nextInt();
                int Y = in.nextInt();
                C.City c = new C.City(i, P, Y);
                list.add(c);
                if (!map.containsKey(P))
                    map.put(P, new ArrayList<>());
                map.get(P).add(c);
            }
            for (List<C.City> cities :
                    map.values()) {
                cities.sort((o1, o2) -> Integer.compare(o1.Y, o2.Y));
                for (int i = 0; i < cities.size(); i++) {
                    cities.get(i).no = i + 1;
                }
            }
            for (C.City city : list) {
                out.printf("%06d%06d\n", city.P, city.no);
            }
        }

        static class City {
            int i;
            int P;
            int Y;
            int no;

            City(int i, int P, int Y) {
                this.i = i;
                this.P = P;
                this.Y = Y;
            }

        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

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

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

    }
}



Measured memory_bytes: 114096
_,a=$<.map{|m|m.split.map(&:to_i)}
mgcd = a[0]
mngcd = 1
a[1..-1].each.with_index(1) do |ai, i|
  gcd = mgcd.gcd(a[i])
  mngcd = mngcd.gcd(a[i])
  if gcd < mgcd && mngcd < mgcd
    mngcd = mgcd
  end
  mgcd = gcd
end

fgcd = 0
a[1..-1].each do |ai|
  fgcd = fgcd.gcd(ai)
end
p [mngcd, mgcd, fgcd].max


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

#define REP(i,n) for(int i=0;i<(n);++i)
const long long INF = 1LL<<60;
const long long mod=1e9+7;

int main(){
    int N;
    cin >> N;
    int p [22];
    REP(i,N) cin >> p[i];
    int count = 0;
    for(int i = 1; i < N - 1; ++i){
        if(p[i] > p[i-1] && p[i] < p[i+1] && p[i-1] < p[i+1]) count++;
        else if(p[i] < p[i-1] && p[i] > p[i+1] && p[i-1] > p[i+1]) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
A = list(map(int,input().split()))
S = []
for i in range(N):
    t = i
    s = 0
    for j in range(t,N):
        s += A[j]
        S.append(s)
n = len(S)
x = 0
for i in range(40):
    m = 40 - i
    t = m - 1
    k = 0
    for j in range(n):
        if (x+2**t)&S[j] == x+2**t:
            k += 1
    if k >= K:
        x += 2**t
print(x)


Measured memory_bytes: 65916
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define repf(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define repfr(i, x, n) for (int i = (int)(x)-1; i >= (int)(n); i--)
#define INF 1e9
using ll = int64_t;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
#define waru 1000000007

std::int64_t gcd(std::int64_t a, std::int64_t b) {
  // a >= b && b != 0
  std::int64_t c;
  do {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
std::int64_t gcd_s(std::int64_t aa, std::int64_t bb) {
  std::int64_t a = max(aa, bb);
  std::int64_t b = min(aa, bb);
  std::int64_t c;
  if (b == 0) {
    return -1;
  }
  do {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
void rle(std::vector<std::pair<char, std::int64_t>> &data, std::string str) {
  char now = str[0];
  std::int64_t count = 0;
  for (std::int64_t i = 0; i < str.size() + 1; i++) {
    if (i == str.size()) {
      data.push_back(make_pair(str[i - 1], count));
      break;
    } else if (now != str[i]) {
      data.push_back(make_pair(now, count));
      now = str[i];
      count = 0;
    }
    count++;
  }

  return;
}

#define MAX_NUM 1000
array<int, 3> a;

void Main() {
  //自動整形防止用コメント
  cin >> a[0] >> a[1] >> a[2];
  sort(all(a));
  std::cout << a[1] + a[0] << std::endl;
  return;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);
		int X=sc.nextInt();
		int ans=1;
		for(int i=2;i*i<=X;i++) {
			for(int j=i*i;j<=X;j*=i) {
				ans=Math.max(ans,j);
			}
		}
		System.out.println(ans);
		sc.close();
	}
}

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

// alias templates
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

// alias declaration
using ll = long long;
using str = string;

using vll = V<ll>;
using vvll = V<vll>;
using vs = V<str>;

// loops
#define FOR(i, a, b)  for (ll i = (a); i <= (ll)(b); i++) // [a,b]
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) // [b,a]
#define REP(i, a) FOR((i), 0, (ll)(a)-1) // [0,a-1]

// for debug
#define dbg(a) cerr << "  " << (#a) << ": " << (a) << "\n";

// procon common constants
const ll MOD_BIG = 1e9 + 7;

int main(void){
    ll r;
    /*
    vll a(n);
    REP(i,n){
        cin >> a[i];
    }
    */
    cin >> r;
    cout << 2*r*M_PI << endl;
}


Measured memory_bytes: 3776
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 200005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
const int mod = 1e9+7;

int main(){
	ll n,k;
	cin >> n >> k;
	int cont[n+5] = {};
	ll ans = 0;
	f(n){
		cin >> cont[i];
	}
	f(n){
		fr(j,i+1,n){
			if(cont[i]>cont[j])ans++;
		}
	}
	ans *= k;
	ans %= mod;
	ll ans2 = 0;
	f(n){
		fr(j,0,n){
			if(cont[i]<cont[j]){
				ans2++;
			}
		}
	}
	ll mul = k*(k-1)/2;
	mul %= mod;
	ans2 *= mul;
	ans2 %= mod;
	ans += ans2;
	ans %= mod;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    int n,m;cin>>n>>m;
    string s;cin>>s;
    reverse(s.begin(),s.end());
    vector<int> a(n+m+10,0);
    int tmp=0;
    rep(i,n+1){
        if(s[i]=='0')tmp=i;
        a[i]=tmp;
    }
    int now=0;
    //rep(i,n+1) cout<<a[i]<<endl;
    vector<int> b;
    while(true){
        if(now+m>=n){
            b.push_back(n-now);
            break;
        }
        if(a[now+m]<=now){
            cout<<-1<<endl;
            return 0;
        }
        b.push_back(a[now+m]-now);
        now=a[now+m];
    }
    reverse(b.begin(),b.end());
    
    rep(i,b.size())cout<<b[i]<<" ";
    cout<<endl;
}

Measured memory_bytes: 1528
# -*- coding: utf-8 -*-
import numpy as np

a, b = map(int, input().split())

if b >= a:
    tmp = a
    a = b
    b = tmp

for i in range(b):
    now_num = a * (i + 1)
    if now_num % b == 0:
        ans = now_num
        break
    if i + 1 == b:
        ans = a * b

print(ans)

Measured memory_bytes: 12488
N = int(input())
A = [int(i) for i in input().split()]
C = [0] * 100001
s = 0
for i in A:
    C[i] += 1
    s += i

K = int(input())

for i in range(K):
    f, t = map(int, input().split())
    C[t] += C[f]
    s += t * C[f]
    s -= f * C[f]
    C[f] = 0
    print(s)

Measured memory_bytes: 20640
use std::cmp::*;
use std::io::*;
use std::num::*;
use std::str::*;

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

fn main() {
    let n: i32 = read();
    let h: i32 = read();
    let w: i32 = read();

    println!("{}", (n - h + 1) * (n - w + 1))
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		try {
			String answer = "";
			for (int i = 0; i < 3; i++) {
				answer += scanner.nextLine().charAt(i);
			}
			System.out.print(answer);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			scanner.close();
		}
	}
}

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

int main() {
	string s;
	cin >> s;
	ll ans = 0;
	for (int i = 0; i < 3; i++) {
		if (s.at(i) == '1')ans++;
	}
	cout << ans << endl;
}

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

int main() {
  int n,k;
  cin >> n >> k;
  int h[n];
  REP(i, n) cin >> h[i];

  int dp[n];
  REP(i,n+1) dp[i] = INF;

  dp[0] = 0;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j <= k; j++) {
      if (i-j < 0) break;
      int cost = dp[i-j] + abs(h[i-j]-h[i]);
      dp[i] = min(dp[i],cost);
    }
  }
  cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
  char **S;
  int N,L;
  char *tmp;
  int flag;
  
  scanf("%d %d",&N,&L);
  S=(char**)malloc(sizeof(char*)*N);
  tmp=(char*)malloc(sizeof(char)*L);
  for(int i=0;i<N;i++){
    S[i]=(char*)malloc(sizeof(char)*L);
    scanf("%s",S[i]);
  }
   
  for(int i=0;i<N-1;i++){
    for(int k=i+1;k<N;k++){
      flag=0;
      for(int j=0;j<L;j++){
        if(S[i][j]>S[k][j]){
          strcpy(tmp,S[i]);
          strcpy(S[i],S[k]);
          strcpy(S[k],tmp);
          flag=1;
        }
        if(flag==1||S[i][j]<S[k][j]) break;
      }
    }
  }
  for(int i=0;i<N;i++)
    printf("%s",S[i]);
  
  
  
  return 0;
}

Measured memory_bytes: 128
/*
 *  Lang    : C++
 *  Author  : little_angel
 */
#include <bits/stdc++.h>

#include <random>

using namespace std;
#define int long long


string sol(int n) {
    if (n <= 26)return string(1, 'a' + n - 1);
    int x = (n - 1) % 26;
    return sol((n - 1) / 26) + string(1, 'a' + x);
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int sum = 0, n;
    cin >> n;
    unordered_map<int, int> m;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        m[a]++;
        sum += a;
    }
    int qry;
    cin >> qry;
    while (qry--) {
        int b, c;
        cin >> b >> c;
        if (b != c) {
            sum -= b * m[b];
            sum += c * m[b];
            m[c] += m[b];
            m.erase(b);
        }
        cout << sum << endl;
    }
}

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

int main() {
    int n, m;
    unordered_map<string, int> cards;

    string s;

    // blue
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s;
        if (cards.find(s) == cards.end()) {
            cards[s] = 1;
        } else {
            cards[s]++;
        }
    }

    // red
    cin >> m;
    for (int i = 0; i < m; i++) {
        cin >> s;
        if (cards.find(s) == cards.end()) {
            cards[s] = -1;
        } else {
            cards[s]--;
        }
    }

    int max = 0;
    for (auto card : cards) {
        max = std::max(max, card.second);
    }

    cout << max << endl;

    return 0;
}


Measured memory_bytes: 256
n,a,b = map(int,input().split())
mod = 10**9+7
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
def cmb(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res
print((2**n%mod-cmb(n,a)-cmb(n,b)-1)%mod)

Measured memory_bytes: 157852
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	int n;
	cin >> n;
	print(n % 2 == 0 ? 0.5 : double((n / 2) + 1) / double(n));
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


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

int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;
vector<P>list(n);
rep(i,n)
{int x,l;
cin >> x >>l;
P p;
  //firstに、アームを一番右側に伸ばしたときの数字
  p.first=x+l;
  //secondに、アームを一番左側に伸ばした時の数字(かぶってはいけないので)
  p.second=x-l;
  list.at(i)=p;
}
sort(list.begin(),list.end());

int nowx=-1e9;
int ans=0;
rep(i,n)
{P p=list.at(i);
  if(nowx<=p.second)
  {ans++; nowx=p.first;}
}

cout << ans << endl;



}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/

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

vector<int> solve(vector<vector<int>> G, vector<int> indeg, int root, int N) {
    vector<int> par(N, -1);
    vector<int> dist(N, -1);
    dist[root] = 0;

    queue<int> Q;
    Q.push(root);

    while(!Q.empty()) {
        int v = Q.front(); Q.pop();
        for(int to : G[v]) {
            if(dist[to] < dist[v] + 1) {
                dist[to] = dist[v] + 1;
                par[to] = v;
            }
            indeg[to] -= 1;
            if(indeg[to] == 0) Q.push(to);
        }
    }

    return par;
}

int main() {
    int N, M; cin >> N >> M;
    vector<vector<int>> G(N);
    vector<int> indeg(N, 0);
    for(int i=0; i<N-1+M; ++i) {
        int x, y; cin >> x >> y;
        G[x - 1].push_back(y - 1);
        indeg[y - 1] += 1;
    }

    int root = -1;
    for(int i=0; i<N; ++i) {
        if(indeg[i] == 0) {
            root = i;
            break;
        }
    }

    auto par = solve(G, indeg, root, N);
    for(int i=0; i<N; ++i) cout << par[i] + 1 << endl;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> a(N);
  for (int i = 0; i < N; i++) cin >> a.at(i);
  
  set<string> color;
  int count = 0; // レート 3200 以上の人の数
  
  for (int i = 0; i < N; i++) {
    if (                   a.at(i) < 400 ) color.insert("gray");
    if ( 400 <= a.at(i) && a.at(i) < 800 ) color.insert("brown");
    if ( 800 <= a.at(i) && a.at(i) < 1200) color.insert("green");
    if (1200 <= a.at(i) && a.at(i) < 1600) color.insert("lightBlue");
    if (1600 <= a.at(i) && a.at(i) < 2000) color.insert("blue");
    if (2000 <= a.at(i) && a.at(i) < 2400) color.insert("yellow");
    if (2400 <= a.at(i) && a.at(i) < 2800) color.insert("orange");
    if (2800 <= a.at(i) && a.at(i) < 3200) color.insert("red");
    if (3200 <= a.at(i)                  ) count ++;
  }
  
  if (color.size() == 0) cout << 1;
  else cout << color.size();
  
  cout << " " << color.size() + count << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int min = 1 << 24;
			String num = null;
			for(int i = 1; ; i++){
				StringBuilder sb = new StringBuilder();
				sb.append(i);
				String s = i + "";
				if(s.equals(sb.reverse().toString())){
					int diff  = n - i;
					if(Math.abs(diff) < min){
						min = Math.abs(diff);
						num = s;
					}
					if(n < i){
						break;
					}
				}
			}
			System.out.println(num);
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

Measured memory_bytes: 23132
#include <bits/stdc++.h>
#define REP(i, n) for(int 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++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

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

int main()
{
	int n;
	cin >> n;
	int t[n];
	REP(i, n) cin >> t[i];
	int m;
	cin >> m;
	vector<int> sum(m);
	pair<int, int> p;
	REP(i, m){
		cin >> p.first >> p.second;
		REP(j, n){
			if (j + 1 == p.first){
				sum[i] += p.second;
			}
			else{
				sum[i] += t[j];
			}
		}

	}

	REP(i, m) cout << sum[i] << endl;

}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n)         for(int i=0; i<(n); i++)
#define P pair<int, int>
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"

//----------------------------------------------------

int main(){
    int a, b, h, m, tmp;
    double pi = 3.141592653589793;
    cin >> a >> b >> h >> m;
    double thh, thm;
    thm = (double)360 * m / 60;
    thh = (double)360 * h / 12;
    tmp = (double)360 / 12;
    thh += tmp*(double)m/60;
    double th;
    th = abs(thh - thm);
    if(abs(thh - thm) > 180){
        th = 360 - th;
    }
    double ans = sqrt(pow(a,2) + pow(b,2) - 2*a*b*cos(th*pi/180));
    prtd(14, ans);

}

Measured memory_bytes: 4192
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll  = long long;
constexpr ll MOD = 1e9 + 7;
template <typename T> T In() {
    T t;
    cin >> t;
    return t;
}
template <typename T> vector<T> ReadVec1(int N) {
    vector<T> vec(N);
    for(int i = 0; i < N; i++)
        vec[i] = In<T>();
    return move(vec);
}
template <typename T> vector<vector<T>> Vec2(int i, int j, T ini = 0) {
    vector<vector<T>> vec(i, vector<T>(j, ini));
    return move(vec);
}
template <typename T> vector<vector<vector<T>>> Vec3(int i, int j, int k, T ini = 0) {
    vector<vector<vector<T>>> vec(i, vector<vector<T>>(j, vector<T>(k, ini)));
    return move(vec);
}


int main() {
    int N = In<int>(), K = In<int>();
    auto pascal = Vec2<ll>(N+1,N+1, 0);

    for(int n = 0; n<= N; n++) {
        pascal[n][0] = 1;
        for(int k = 1; k <= n; k++) {
            pascal[n][k] = (pascal[n - 1][k] + pascal[n - 1][k - 1]) % MOD;
        }
    }
    for(int i = 1; i <= K; i++)
        cout << (pascal[N - K + 1][i] * pascal[K - 1][i - 1]) % MOD << endl;
}

Measured memory_bytes: 31616
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main() {
  int R[MAX], n;

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

  int maxv = -2000000000;
  int minv = R[0];

  for ( int i = 1; i < n; i++ ) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;

  return 0;
}


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

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

    vector<int> vec;
    set<int> numbers;

    int a;
    for(int i=0; i<N; i++) {
        cin >> a;
        vec.push_back(a);
        numbers.insert(a);
    }

    if (vec.size() == numbers.size()) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 10356
from math import pow
def get_table():
    table = []
    for i in range(10):
        a = int(pow(10, i))
        table.append(a % 2019)
    return table

table = get_table()
# print(table)

def get_power_2019(idx):
    if (idx < len(table)):
        return table[idx]
    else:
        j = int(idx/2)
        i = idx - j
        return (get_power_2019(i) * get_power_2019(j)) % 2019

for i in range(10, 10000):
    curr = get_power_2019(i)
    table.append(curr)

s = input()
mod_dict = {}

last_mod = 0
for i in range(len(s)-1, -1, -1):
    current_lowest_digit = int(s[i])
    current_mod = ((current_lowest_digit * get_power_2019(len(s)-1-i))% 2019 + last_mod) % 2019
    if (current_mod not in mod_dict.keys()):
        mod_dict[current_mod] = [i]
    else:
        mod_dict[current_mod].append(i)
    last_mod = current_mod

# print(mod_dict)

count = 0
for k in mod_dict.keys():
    n = len(mod_dict[k])
    count += int(n*(n-1)/2)
    if (k == 0):
        count += n
print(count)

Measured memory_bytes: 18244
# @param int s start edge number
# @param Edge e the graph
# @param int k the number of colors
def bfs(s,e,k)
	# --- setup ---
	mod = 10**9+7
	childs = Array.new(E.size){0}
	# --- initial calc ---
	childs[s] = 0
	comb = k
	# --- initial next ---
	# queue format : [node, parent node, level]
	q = []
	e[s].each{|a| # must be `each`, not `map`
		q << [a,s,1]
	}
	while(!q.empty?)
		# p q
		v,v_p,lev = q.shift
		# p [v,v_p,lev]
		# --- calc ---
		# when no color can be allocated
		return 0 if ((k-[lev,2].min-childs[v_p])<=0)
		# calc
		comb *= (k-[lev,2].min-childs[v_p])
		comb %= mod
		childs[v_p] += 1		
		# --- next ---
		v_nxt = e[v].each{|i| 
			q << [i,v,lev+1] if (i != v_p)
		}
		# p comb
	end
	return comb
end
N,K=gets.chomp.split(' ').map{|n| n.to_i}
E = Array.new(N){[]}
1.upto(N-1){
	p=gets.chomp.split(' ').map{|n| n.to_i}
	p[0] -= 1
	p[1] -= 1
	E[p[0]].push(p[1])
	E[p[1]].push(p[0])
}
puts bfs(0,E,K)


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

bool A[1000000] = {};

int main() {
    int s, count = 0;
    cin >> s;
    A[s] = true;
    ++count;
    while (true) {
        if (s % 2 == 0) {
            s = s / 2;
            ++count;
            if (!A[s]) {
                A[s] = true;
            } else {
                break;
            }
        } else {
            s = 3 * s + 1;
            ++count;
            if (!A[s]) {
                A[s] = true;
            } else {
                break;
            }
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from bisect import bisect_left
import sys,math,itertools,pprint,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

a = [inpl() for i in range(3)]
c = [[False] * 3 for i in range(3)]
n = inp()
b = [inp() for i in range(n)]
for x in b:
    for i in range(3):
        for j in range(3):
            if x == a[i][j]:
                c[i][j] = True
# c = [[True,True,False],[True,False,False],[True,False,False]]
res = False
for i in range(3):
    if c[i].count(True) == 3:
        res = True
for i in range(3):
    if c[0][i] == c[1][i] == c[2][i] == True:
        res = True
if c[0][2] == c[1][1] == c[2][0] == True or c[0][0] == c[1][1] == c[2][2] == True:
    res = True
print('Yes' if res else 'No')

Measured memory_bytes: 5288
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N, H, W; cin >> N >> H >> W;
    int A = N - H + 1;
    int B = N - W + 1;
    cout << A * B << endl;
    return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

int main() {
	int n, s[1000], i, j;
	double a, m;
	while (1) {
		cin >> n;
		if (!n)
			break;
		m = a = 0;
		for (i = 0; i < n; i++) {
			cin >> s[i];
			m += s[i];
		}
		m /= n;
		for (i = 0; i < n; i++) {
			a += (s[i]-m)*(s[i]-m);
		}
		a = sqrt(a/n);
		cout << fixed << setprecision(6) << a << endl;
	}
	return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
const int MOD = 1e9 + 7;
const int INF = 9e18;

signed main(){
    int N;
    cin >> N;
    multiset<int> A;
    for (int i = 0; i < N; i++) {
        int temp;
        cin >> temp;
        A.insert(temp);
    }
    int ans = 0;
    while (!A.empty()) {
        int base, key;
        {
            auto itr = A.end();
            --itr;
            base = *itr;
            int count = 0;
            int k = base;
            while (k > 0) {
                k /= 2;
                ++count;
            }
            key = (1<<count) - base;
            A.erase(itr);
        }
        auto itr = A.find(key);
        if (itr != A.end()) {
            A.erase(itr);
            ++ans;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 9600
#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 n;
	scanf("%d", &n);
	vector<int> a(n);
	for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
	ll best = 1LL << 60;
	for (int spos = 0; spos < 2; ++spos) {
		bool pos = spos;
		ll sum = 0;
		ll ans = 0;
		for (int i = 0; i < n; ++i) {
			sum += a[i];
			if (sum >= 0 && !pos) {
				ans += sum + 1;
				sum = -1;
			} else if (sum <= 0 && pos) {
				ans += 1 - sum;
				sum = 1;
			}
			pos = !pos;
		}
		best = min(best, ans);
	}
	printf("%lld\n", best);
}


Measured memory_bytes: 640
while True:
    n = int(input())
    if n == 0: break
    a = list(map(int, input().split()))
    a.sort()
    ans = a[1]-a[0]
    for i in range(2, n):
        if a[i]-a[i-1] < ans: ans = a[i]-a[i-1];
    print(ans)


Measured memory_bytes: 5628
#include <stdio.h>
#include <stdlib.h>
#define MAX_N 100000

typedef struct {
  int n;
  char id[13];
  int P;
  int Y;
} st_city;

int city_sort(const void*a, const void*b) {
  int x = ((st_city*)a)->P - ((st_city*)b)->P;
  if(x != 0)
    return x;
  return (((st_city*)a)->Y - ((st_city*)b)->Y);
}

int n_sort(const void*a, const void*b) {
  return (((st_city*)a)->n - ((st_city*)b)->n);
}

int main(void) {
  int N, M;
  scanf("%d %d", &N, &M);

  st_city city[MAX_N];
  for(int i = 0; i < M; i++) {
    city[i].n = i;
    scanf("%d %d", &city[i].P, &city[i].Y);
  }
  qsort(city, M, sizeof(st_city), city_sort);

  int n = 1;
  int prevP = -1;
  for(int i = 0; i < M; i++) {
    if(prevP != city[i].P)
      n = 1;
    sprintf(city[i].id, "%06d%06d", city[i].P, n++);
    prevP = city[i].P;
  }

  qsort(city, M, sizeof(st_city), n_sort);
  for(int i = 0; i < M; i++) {
    printf("%s\n", city[i].id);
  }

  return 0;
}


Measured memory_bytes: 6988
n = int(input())
place = []
for _ in range(n):
    place.append(list(map(int, input().split())))
    
import itertools
route = list(itertools.permutations(range(n), n))

import math

ans = 0
for i in range(len(route)):
    dist = 0
    for j in range(n-1):
        dist += math.sqrt((place[route[i][j+1]][0] - place[route[i][j]][0])**2 + (place[route[i][j+1]][1] - place[route[i][j]][1])**2)
    
    ans += dist

print(ans/len(route))

Measured memory_bytes: 8052
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;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;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=100005;
struct edge{int x,y,next;};
vector<int> nxt[MAXN];
int n;
struct Graph
{
	edge a[2*MAXN];int len,last[MAXN];
	int du[MAXN];
	void ins(int x,int y){len++;a[len].x=x;a[len].y=y;a[len].next=last[x];last[x]=len;}
	int init()
	{
		int ret;
		for(int i=1;i<=n;i++)
		{
			int x=read();
			if(x==-1)ret=i;else ins(x,i),++du[x];
		}return ret;
	}
	vector<int> vec[MAXN];
	int dfs(int x)
	{
		for(int k=last[x];k;k=a[k].next)
		{
			int y=a[k].y;
			int u=dfs(y);vec[x].push_back(u);
		}
		if(!(du[x]&1))vec[x].push_back(x);
		for(int i=0;i<vec[x].size()-1;i+=2)
		{
			int u=vec[x][i],v=vec[x][i+1];
			nxt[u].push_back(v);nxt[v].push_back(u);
		}return vec[x].back();
	}
}G1,G2;
int col[MAXN];
void dfs(int x){for(int k=0;k<nxt[x].size();k++)if(col[nxt[x][k]]==-1)col[nxt[x][k]]=col[x]^1,dfs(nxt[x][k]);}
int main()
{
	n=read();
	int r1=G1.init();
	int r2=G2.init();
	for(int i=1;i<=n;i++)if((G1.du[i]&1)!=(G2.du[i]&1))return puts("IMPOSSIBLE"),0;
	G1.dfs(r1);G2.dfs(r2);
	puts("POSSIBLE");
	memset(col,-1,sizeof(col));
	for(int i=1;i<=n;i++)if(col[i]==-1&&!(G1.du[i]&1))col[i]=0,dfs(i);
	for(int i=1;i<=n;i++)pr1(col[i]==-1?0:(col[i]==1?1:-1));
	return 0;
}


Measured memory_bytes: 27384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    string s;
    cin >> s;
    if(s=="Sunny") cout<<"Cloudy"<<endl;
    if(s=="Cloudy") cout<<"Rainy"<<endl;
    if(s=="Rainy") cout<<"Sunny"<<endl;
}

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

int main() {
    int N;
    while (cin >> N, N) {
        vector<vector<int> > d(N, vector<int>(N));
        for (auto& i : d) for (auto& j : i) cin >> j;

        vector<int> r(N, 1 << 28), l(N);
        for (int i = 0; i < N; i++) {
            for (auto j : d[i]) r[i] = min(r[i], j);
        }

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                l[i] = max(l[i], d[j][i]);
            }
        }

        int ans = -1;
        for (int i = 0; i < N; i++)
            for (int j = 0; j < N; j++)
                if (l[i] == r[j]) ans = max(ans, l[i]);

        if (ans > -1) cout << ans << endl;
        else cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 3000
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<int, pii> pipii;

int g[505][505];

void solve() {
  int r, c;
  cin >> r >> c;
  for(int i = 1; i <= r; i++) {
    for(int j = 1; j <= c; j++) {
      cin >> g[i][j];
    }
  }
  vector<pii> lhs;
  vector<pii> rhs;
  for(int i = 1; i <= r; i++) {
    for(int j = 1; j <= c; j++) {
      if(g[i][j] % 2 == 0) continue;
      g[i][j]--;
      if(j < c) {
        g[i][j+1]++;
        lhs.push_back({i, j});
        rhs.push_back({i, j+1});
      }
      else if(i < r) {
        g[i+1][j]++;
        lhs.push_back({i, j});
        rhs.push_back({i+1, j});
      }
    }
  }
  cout << lhs.size() << "\n";
  for(int i = 0; i < lhs.size(); i++) {
    cout << lhs[i].first << " " << lhs[i].second << " " << rhs[i].first << " " << rhs[i].second << "\n";
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


Measured memory_bytes: 7268
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long long ll;
const int maxn = 2e5+100;
int n, k;
int a[maxn];

int main()
{
    cin >> n >> k;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = k; i < n; ++i)
    {
        if (a[i]>a[i-k]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 4412
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

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

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int MAXN = 210000;

ll h[MAXN];
ll a[MAXN];
ll fv[MAXN];

int n;
vector<int> vv;

ll get(int x) {
	ll ans = 0;
	for (; x >= 0; x = (x & (x + 1)) - 1)
		ans = max(ans, fv[x]);
	return ans;
}

void upd(int x, ll y) {
	for (; x < MAXN; x |= (x + 1))
		fv[x] = max(fv[x], y);
}

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> h[i], vv.push_back(h[i]);
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	sort(ALL(vv));
	for (int i = 0; i < n; ++i)
		h[i] = lower_bound(ALL(vv), h[i]) - vv.begin();
	ll ans = 0;
	for (int i = 0; i < n; ++i) {
		ll go = get(h[i]) + a[i];
		upd(h[i], go);
		ans = max(ans, go);
	}
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 6004
<?php

    for ($i = 1; true; $i++) {
        fscanf(STDIN, "%d %d", $x, $y);
        if ($x == 0 && $y == 0) {
            break;
        }
        printf(($x < $y ? $x . ' ' . $y : $y . ' ' . $x) . PHP_EOL);
    }

Measured memory_bytes: 15124
'use strict';
function Main(input) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  let inputs = input.split("\n");
  let tmp1 = inputs[0].split(" ");
  // let l = inputs[1].split(" ");
  //文字列から10進数に変換するときはparseIntを使います
  let W = parseInt(tmp1[0], 10);
  let H = parseInt(tmp1[1], 10);
  let x = parseInt(tmp1[2], 10);
  let y = parseInt(tmp1[3], 10);

  let a = W * H / 2;
  let b = 0;
  if (x === W / 2 && y === H / 2) {
    b = 1;
  }

  //出力
  console.log('%d %s', a, b);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;

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

    string s;

    cin >> s;
    cout << s.substr(0, 5) << ' ' << s.substr(6, 7) << ' ' << s.substr(14) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

int main(){
  ll N,M;
  cin >> N >> M;
  vector<P> A(N),C(M);
  rep(i,N){
    cin >>A.at(i).first >> A.at(i).second;
  }
  rep(i,M){
    cin >>C.at(i).first >> C.at(i).second;
  }
  rep(i,N){
    ll a=INF,b;
    rep(j,M){
      if(abs(A.at(i).first-C.at(j).first)+abs(A.at(i).second-C.at(j).second)<a){
        b=j+1;
        a=abs(A.at(i).first-C.at(j).first)+abs(A.at(i).second-C.at(j).second);
      }
    }
    cout << b << endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
  string s;
  cin>>s;
  ll a=0,b=0;
  for(int i=0;i<3;i++)
  {
    if(s[i]=='A')
       a++;
       else
       b++;
       }
       if(a==0||b==0)
       cout<<"No";
       else
       cout<<"Yes";
       }

Measured memory_bytes: 256
n=int(input())
s=input()
ndot=0
nx=0
mx=10000000
for i in range(n+1):
    if i==0:
        ndot=sum([1 for i in s if i=="."])
        nx=0
    else:
        if s[i-1]==".":
            ndot-=1
        elif s[i-1]=="#":
            nx+=1
    mx=min(mx,nx+ndot)
print(mx)

Measured memory_bytes: 5096
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int p[] = new int[N+1];
    for (int i=1; i<=N; i++) {
      p[i] = sc.nextInt();
    }

    DS ds = new DS(N+1);
    for (int i=1; i<=M; i++) {
      ds.union(sc.nextInt(), sc.nextInt());
    }

    int ans = 0;
    for (int i=1; i<=N; i++) {
      if (p[i] == i) {
        ans++;
      } else if (ds.root(i) == ds.root(p[i])) {
        ans++;
      }
    }
    System.out.println(ans);
  }

  static class DS {
    int[] parent;
    int[] counter;

    DS(int n) {
      parent = new int[n];
      counter = new int[n];
      Arrays.fill(counter, 1);
      Arrays.setAll(parent, i -> i);
    }

    int root(int a) {
      int q = a;
      // search root q
      while (q != parent[q]) {
        q = parent[q];
      }
      // fill parents with root q to avoid unnecessary search in the next calls
      while (a != q) {
        int next = parent[a];
        parent[a] = q;
        a = next;
      }
      return q;
    }

    void union(int i, int j) {
      int ri = root(i);
      int rj = root(j);
      if (ri == rj) {
        return;
      }
      if (counter[rj] < counter[ri]) {
        // swap ri and rj to avoid infinite loop (ex. A -> B -> C -> A)
        int s = ri;
        ri = rj;
        rj = s;
      }
      parent[ri] = rj;
      counter[rj] += counter[ri];
    }
  }
}


Measured memory_bytes: 91872