akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long LL;
const int N=4e5+100;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int head[N],nxt[N],to[N],fa[N],dep[N];
int ans,u[N],v[N];
vector<int>e[N];
inline void dfs(int k) {
	for (int i=head[k];i;i=nxt[i])
		if (to[i]!=fa[k])
			fa[to[i]]=k,dep[to[i]]=dep[k]+1,dfs(to[i]);
}
bool win[N];
inline bool check(int a,int b) {
	if (fa[a]==b||fa[b]==a) return false;
	if (fa[a]==fa[b]||fa[fa[a]]==b||fa[fa[b]]==a) return false;
	return true;
}
inline void dfs(int k,int fa,int t) {
	if (win[k]) puts("-1"),exit(0);
	ans=max(ans,dep[k]);
	for (int y:e[k])
		if (y!=fa)
			if (dep[y]>t)
				dfs(y,k,t+1);
}
int main()
{
	int n=gi(),x=gi(),y=gi(),i,a,b,tot=0;
	for (i=1;i<n;i++) u[i]=gi(),v[i]=gi(),e[u[i]].push_back(v[i]),e[v[i]].push_back(u[i]);
	for (i=1;i<n;i++) {
		a=gi(),b=gi();
		to[++tot]=b,nxt[tot]=head[a],head[a]=tot;
		to[++tot]=a,nxt[tot]=head[b],head[b]=tot;
	}
	dfs(y);
	for (i=1;i<n;i++) if (check(u[i],v[i])) win[u[i]]=win[v[i]]=true;

	dfs(x,0,1);
	printf("%d\n",ans<<1);
	return 0;
}


Measured memory_bytes: 30972
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef deque<int> DI;
typedef deque<LL> DLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	sll(n); sll(k);
	LD prob = 0.0;
	rep(i, 1, n+1) {
		LL cnt = 0, score = i;
		while(score < k)	cnt++, score <<= 1;
		prob += 1.0 / (((LD)n) * (pow(2.0, cnt)));
	}
	cout << fixed << setprecision(12) << prob << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
#define SIZE 262144
typedef long long ll;
ll mod = 1000000007;
class BIT
{
public:
	ll bit[SIZE + 1];
	void add(int a, ll b)
	{
		a+=120000;
		for (;;)
		{
			bit[a] += b;
			bit[a] %= mod;
			a += a&-a;
			if (a > SIZE)return;
		}
	}
	ll get(int a)
	{
		a+=120000;
		ll ret = 0;
		for (;;)
		{
			ret += bit[a];
			a -= a&-a;
			if (a == 0)return ret%mod;
		}
	}
};
BIT bi;
ll dp[202020];
ll sub[2][202020][2];
int main()
{
	int num, len;
	scanf("%d%d", &num, &len);
	string s;
	cin >> s;
	if (s[0] == 'B')
	{
		for (int i = 0; i < s.size(); i++)s[i] = 'R' + 'B' - s[i];
	}
	int mini = 1000000000, cnt = 0;
	bool ff = false;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == 'R')cnt++;
		else
		{
			if (!ff)
			{
				if (cnt % 2 == 0)mini = min(mini, cnt + 1);
				else mini = min(mini, cnt);
				ff = true;
			}
			else if (cnt % 2 == 1)mini = min(mini, cnt);
			cnt = 0;
		}
	}
	if (!ff)
	{
		sub[0][0][0] = sub[1][0][1] = 1;
		for (int i = 0; i < 2; i++)
		{
			for (int j = 1; j < num; j++)
			{
				sub[i][j][0] = (sub[i][j - 1][0] + sub[i][j - 1][1]) % mod;
				sub[i][j][1] = sub[i][j - 1][0];
			}
		}
		ll r = sub[0][num - 1][0] + sub[0][num - 1][1] + sub[1][num - 1][0];
		printf("%lld\n", r%mod);
		return 0;
	}
	if (num % 2 == 1)
	{
		printf("0\n");
		return 0;
	}
	mini = (mini + 1) / 2;
	num /= 2;
	mini = min(mini, num);
	dp[0] = 1;
	bi.add(0, 1);
	for (int i = 1; i <= num; i++)
	{
		dp[i] = (bi.get(i - 1) - bi.get(i - mini - 1) + mod) % mod;
		bi.add(i, dp[i]);
		//printf("%d %lld\n", i, dp[i]);
	}
	ll r = 0;
	for (int i = 1; i <= mini; i++)r = (r + dp[num - i] * i * 2) % mod;
	printf("%lld\n", r);
}

Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
void pr(){ln;}
template<Z A,Z...B>void pr(const A &a,const B&...b){cout<<a<<' ';pr(b...);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,m;
  cin >> n >> m;
  ll a[n];
  rep(i,n) R a[i];
  vector<int> v[n];
  rep(i,m) {
    int x,y;
    cin >> x >> y;
    x--,y--;
    v[x].pb(y);
    v[y].pb(x);
  }
  int ans=0;
  rep(i,n) {
    int f=1;
    rep(j,v[i].size()) {
      int y=v[i][j];
      if(a[i]<=a[y]) f=0;
    }
    ans+=f;
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 9568
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Scan()
	args := strings.Split(sc.Text(), " ")
	a, _ := strconv.Atoi(args[0])
	b, _ := strconv.Atoi(args[1])

	if a < b {
		a ^= b
		b ^= a
		a ^= b
	}

	diff := a - b

	switch {
	case diff >= 2:
		fmt.Print(a + (a - 1))
	default:
		fmt.Print(a + b)
	}
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> mat;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define mset(a,x) memset(a,x,sizeof(a))
#define OUT(x) cout<<(x)<<"\n"
#define SZ(x) (int)(x).size()
#define FASTIO cin.tie(0),ios::sync_with_stdio(0)


ll n, a, b;
const ll INF = 1LL << 30;


bool valid(ll x, vi& h) {
    ll c = a - b;
    ll k = 0;
    rep(i, n) {
        if(h[i] > x * b) {
            ll p = h[i] - x * b;
            k += (p + c - 1) / c;
        }
    }
    return k <= x;
}

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

    vector<int> h(n);
    rep(i, n) scanf("%d", &h[i]);

    ll lb = 0, rb = INF;
    while(rb - lb > 1) {
        ll mid = (rb + lb) / 2LL;
        if(valid(mid, h)) rb = mid;
        else lb = mid;
    }

    cout << rb << endl;


    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int r = sc.nextInt();
    
    if(n < 10){
      System.out.println(100*(10-n)+r);
    }else{
      System.out.println(r);
    }
  }
}


Measured memory_bytes: 22868
#include <iostream>

using namespace std;

int main()
{
	int A, B, K, tmp = 1;
	cin >> K >> A >> B;
	while (K * tmp < A)
	{
		tmp++;
	}
	if (K * tmp <= B)
		cout << "OK" << endl;
	else
		cout << "NG" << endl;
}

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

#define mp make_pair
#define pb push_back

#define int int64_t
#define ld long double

const int MOD = 1e9+7;
const int N = 1e6+5;

int dp[(1<<21)];
int n;

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n;
	int arr[n][n];
	for(int i=0;i<n;i++) {
		for(int j=0;j<n;j++) {
			cin>>arr[i][j];
		}
	}	
	dp[0]=1;
	for(int i=0;i<(1<<n)-1;i++) {
		for(int j=0;j<n;j++) {
			int k = __builtin_popcount(i);
			if(arr[k][j] && ((i&(1<<j)) ==0)) {
				dp[(i|(1<<j))] = (dp[(i|(1<<j))]+dp[i])%MOD;
			}
		}
	}

	cout<<dp[(1<<n)-1];

	return 0;
}

Measured memory_bytes: 19984
//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring> 
using namespace std;
int ar[200008];
int has[200008];
int main()
{
 	//freopen("","r",stdin);
	//freopen("","w",stdout);
	 int n;cin>>n;for(int i=0;i<n;i++) cin>>ar[i];
	 int ans=0;
	 for(int j=0;j<n;j++)
	 {
	 	has[ar[j]]=has[ar[j]-1]+1;
	 	ans=max(ans,has[ar[j]]);
	 }
	cout<<n-ans;
	return 0;
}

Measured memory_bytes: 1920
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N = II()
	d = {}
	ansl=[]
	max_c = 0
	for _ in range(N):
		s = IS()
		if not s in d:
			d[s]=1
		else:
			d[s]+=1

		if(d[s]>max_c):
				max_c=d[s]
				ansl=[]
				ansl.append(s)
		elif(d[s]==max_c):
			ansl.append(s)
	ansl.sort()
	printV(ansl)


if __name__ == '__main__':
	main()

Measured memory_bytes: 96220
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
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(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int main(){
    int n;
    while(scanf("%d", &n) && n){
        set<int> a[n];
        rep(i, n){
            int m;
            scanf("%d", &m);
            rep(j, m){
                int p;
                scanf("%d", &p);
                a[i].insert(p);
            }
        }
        int K;
        scanf("%d", &K);
        vector<int> l(K);
        rep(i, K) scanf("%d", &l[i]);
        set<int> S;
        rep(i, n){
            bool flag = true;
            rep(j, K)if(a[i].find(l[j]) == a[i].end()){
                flag = false;
                break;
            }
            if(flag) S.insert(i);
        }
        if(S.size() != 1) puts("-1");
        else printf("%d\n", *S.begin() + 1);
    }
}


Measured memory_bytes: 3596
void main() {
  problem();
}

void problem() {
  const N = scan!int;
  const A = scan!long(N);

  void solve2() {
    auto B = N.iota.map!(i => A[i] + i).array;

    int[long] C;
    foreach(i; 0..N) {
      C[i - A[i]]++;
    }
    
    long answer;
    foreach(b; B) {
      if (b in C) answer += C[b];
    }

    writeln(answer);
  }

  // solve();
  solve2();
}

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

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

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


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

int a,b,x;
double pi=acos(-1);

bool ok(double m) {
    double c=b*tan(pi/2-m);
    if (c<=a)
        return c*b/2*a>=x;
    return a*a*b-a*a*a*tan(m)/2>=x;
}

int main() {
    cin>>a>>b>>x;
    double l=0,r=pi/2;
    for (int i=0;i<100;i++) {
        double m=(l+r)/2;
        if (ok(m))
            l=m;
        else
            r=m;
    }
    cout<<fixed<<l*180/pi<<endl;
    return 0;
}

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

typedef long long LL;
const int N = 5e5 + 10;
int n;
LL a, b, c, d, F[N][2], G[N][2];

bool ok(){
    F[1][0] = F[1][1] = a;
    for(int i=2; i<=n; i++){
        F[i][0] = F[i-1][0] + c;
        F[i][1] = F[i-1][1] + d;
    }
    G[n][0] = G[n][1] = b;
    for(int i=n-1; i>=1; i--){
        G[i][0] = G[i+1][0] + c;
        G[i][1] = G[i+1][1] + d;
    }
    for(int i=1; i<=n; i++){
        LL low = max(F[i][0], G[i][0]);
        LL top = min(F[i][1], G[i][1]);
        if(low <= top){
            return 1;
        }
    }
    return 0;
}

int main(){
    while(~scanf("%d %lld %lld %lld %lld", &n, &a, &b, &c, &d)){
        puts(ok()?"YES":"NO");
    }
    return 0;
}


Measured memory_bytes: 15872
#include<bits/stdc++.h>
#include<cstring>
using namespace std;
//#define num 1000000007
#define num 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define up(a,b) (((a)%(b)==0)?((a)/(b)):((a)/(b))+1)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) (a>b)?(a>c)?a:c:(b>c)?b:c
#define min3(a,b,c) (a<b)?(a<c)?a:c:(b<c)?b:c
#define avg(a,b) ((a)+(b))/2
#define push push_back
#define pop pop_back
#define mp make_pair
#define sf int flag=0     //Remember semicolon
#define assmin(a,b) if(b<=a) { a=b; }
#define assmax(a,b) if(b>=a) { a=b; }
#define fi first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
typedef long long ll;
 
ll mod(ll a, ll b)
{
	if(a%b<0)
	{
		return a%b + b;
	}
	return a%b;
}
 
 
ll mod_exp(ll a, ll b, ll c)
{
	ll res=1;
	a=a%c;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%c;
		}
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll gcd(ll a, ll b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b, a%b);
}
bool prime[3001];
void SieveOfEratosthenes() 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
    for (int p=2; p*p<=3000; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=3000; i += p) 
                prime[i] = false; 
        } 
    } 
}
ll powe[20];
void power()
{
	powe[0]=1;
	REP(i,1,20)
	{
		powe[i]=(powe[i-1]*10)%num;
        if(powe[i]<0)
        powe[i]+=num;
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll n,m;
	cin>>n>>m;
	cout<< (n*(n-1) + m*(m-1))/2;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main()
{
    string s;
    cin >> s;
    if(s[0] != s[1] && s[1] != s[2] && s[0] != s[2])
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x-I .)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int PRIMES_MAX = 10000000;
vector<int> min_primefactor(PRIMES_MAX, inf);

void init_min_primefactor(){
	min_primefactor[0] = 0;
	min_primefactor[1] = 1;
	for(int i = 2; i < PRIMES_MAX; ++i){
		if(min_primefactor[i] == inf){
			for(int k = 1; i * k < PRIMES_MAX; ++k){
				min_primefactor[i * k] = i;
			}
		}
	}
}

map<int,int> prime_factor(int N){
	map<int, int> res;
	while(N > 1){
		res[min_primefactor[N]]++;
		N /= min_primefactor[N];
	}
	return res;
}

int main(){
    init_min_primefactor();
    int N;
    cin >> N;
    ll ans = 0;
    for(int c = 1; c < N; ++c){
        int rest = N - c;
        map<int,int> ele = prime_factor(rest);
        ll tmp = 1;
        for(auto x:ele)tmp *= (x.second + 1);
        ans += tmp;
    }
    cout << ans << endl;;
    return 0;
}


Measured memory_bytes: 42108
n = int(input())
a = list(map(int, input().split()))
import collections

c = collections.Counter(a)
values, counts = zip(*c.most_common())
counts = list(counts)
if counts[-1] == 1:
	k = counts.index(1)
	del counts[k:]


from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

from collections import deque
t = deque()
for i in counts:
    t.append(cmb(i,2))

t = list(t)
ans = sum(t)

for i in a:
	print(ans - c[i] + 1)


Measured memory_bytes: 37224
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define fast ios_base::sync_with_stdio(false)
#define cintie cin.tie(NULL)
int main()
{
	ll sum,x,d,n,i;
	cin>>d>>n;
	sum=0;
	for(i=0;i<n;i++)
	{
		cin>>x;
		sum=sum+x;
	}
	if(sum<=d)
	cout<<d-sum<<endl;
	else
	cout<<-1<<endl;
}


Measured memory_bytes: 3620
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

template<typename T>
T power(T x, long long n, const T &m){
    if(n == 0) return 1;
    if(n == 1) return x;
    T tmp = power(x, n/2, m);
    if(n%2 == 0) return tmp * tmp % m;
    else return tmp * tmp % m * x % m;
}

template<typename T>
T inverse(T x, const T &m){
    return power(x, m-2, m);
}

struct Combination{
private:
    int N;
    long long M;
    vector<long long> f, i;
public:
    void init(int n, long long m){
        N = n; M = m;
        f.resize(N+1); f[0] = 1;
        for(long long j=1; j<=N; j++){
            f[j] = f[j-1] * j % M;
        }
        i.resize(N+1); i[N] = inverse(f[N], M);
        for(long long j=N-1; j>=0; j--){
            i[j] = i[j+1] * (j+1) % M;
        }
    }
    long long fact(int n){
        return f[n];
    }
    long long P(int n, int r){
        return f[n] * i[n-r] % M;
    }
    long long C(int n, int r){
        return f[n] * i[r] % M * i[n-r] % M;
    }
};

template<long long Mod>
struct mint{
    long long x;
    mint(long long x=0) :x((x% Mod+Mod)%Mod){}

    mint operator-() const { return mint(-x); }

    mint& operator+=(const mint a) {
        if((x += a.x) >= Mod) x -= Mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if((x += Mod-a.x) >= Mod) x -= Mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= Mod;
        return *this;
    }

    mint operator^(long long t) const {
        mint ret(1);
        mint a = *this;
        while(t){
            if(t&1){
                ret *= a;
            }
            a *= *this;
            t /= 2;
        }
        return a;
    }
    mint inv() const { return *this ^ (Mod-2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }

    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint operator/(const mint a) const { return mint(*this) /= a; }

    friend istream& operator>>(istream& is, mint& a) { return is >> a.x; }
    friend ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
};

ll H, W, A, B;
Combination C;

signed main(){
    cin >> H >> W >> A >> B;
    C.init(H+W, MOD);
    mint<MOD> ans = 0;
    for(ll i=0; i<H-A; i++){
        mint<MOD> tmp = C.C(i+B-1, i) * C.C(H+W-2-i-B, W-B-1);
        ans += tmp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6320
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    List<Integer>[] exits = new List[N];
    for (int i = 0; i < N; i++) exits[i] = new ArrayList<>();

    for (int i = 0; i < M; i++) {
      int s = scanner.nextInt() - 1;
      int t = scanner.nextInt() - 1;
      exits[s].add(t);
    }

    double min = Double.POSITIVE_INFINITY;

    for (int i = 0; i < N; i++) {
      double[] e = new double[N];
      for (int j = N - 2; j >= 0; j--) {
        double max = 0.d;
        for (int k : exits[j]) {
          e[j] += e[k] + 1;
          max = Math.max(max, e[k] + 1);
        }
        int s = exits[j].size();
        if (s > 1 && j == i) e[j] = (e[j] - max) / (s - 1);
        else e[j] /= s;
      }
      min = Math.min(min, e[0]);
    }

    System.out.println(min);
  }
}


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

int main()
{
	int a[5];
	cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
	
	int f;
	for(int i=0;i<5;i++){
		if(a[i]%10!=0&&a[i]%10<a[f]%10) f=i;
	}
	int sum=0;
	for(int i=0;i<5;i++){
		if(i!=f&&a[i]%10!=0) a[i]=a[i]/10*10+10;
		sum+=a[i];
	}
	
	cout<<sum<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int A, B, C;
    cin >> A >> B >> C;
    vector<int> a;
    a.pb(A), a.pb(B), a.pb(C);
    sort(all(a));
    int cnt = 0;
    cnt += (a[2] - a[0]) / 2;
    cnt += (a[2] - a[1]) / 2;
    
    int odd = 0;
    if((a[2] - a[0]) % 2 == 1) odd++;
    if((a[2] - a[1]) % 2 == 1) odd++;
    if(odd == 1) {
        cnt += 2;
    }
    else if(odd == 2) cnt++;
    
    output(cnt);
    
    
    
    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * 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;
    Scanner in = new Scanner(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    A solver = new A();
    solver.solve(1, in, out);
    out.close();
  }

  static class A {
    public void solve(int testNumber, Scanner in, PrintWriter out) {
      String S = in.next();

      if (S.equals("ABC")) {
        out.print("ARC");
      } else if (S.equals("ARC")) {
        out.print("ABC");
      }
    }

  }
}



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

int main()
{
  int n, m;
  cin >> n >> m;
  int arr[m];
  for(int i=0; i<m; i++)
    cin >> arr[i];
  for(int i=0; i<m; i++)
  {
    n = n-arr[i];
  }
  if(n<0)
    cout << "-1";
  else
    cout << n;
  return 0;
}


Measured memory_bytes: 3604
import sys
readline = sys.stdin.buffer.readline
import numpy as np
# 価値 x 以上になる握手の方法が M通りになる Xを二分探索で求める

N,M = map(int,readline().split())
A = np.array(readline().split(),np.int64)
A.sort()

def shake_cnt(x):
    # 価値 x 以上の握手を全て行うとして、前通りからx未満の回数を引く
    X = np.searchsorted(A,x-A)  # A の binary-serch を Aの値別に行った結果の配列
    return N * N - X.sum()

# 二分探索
left = 0        # 握手の回数がM以上の価値
right = 10 ** 6 # 握手の回数がM未満の価値
while left + 1 < right:
    x = (left + right) // 2
    if shake_cnt(x) >= M:
        left = x
    else:
        right = x

# 価値 right 以上の握手を全て行ったとして、回数と総和を計算
X = np.searchsorted(A,right-A) # 握手しない人数の左手別配列
Acum = np.zeros(N+1,np.int64)  # 価値 -> 累積和
Acum[1:] = np.cumsum(A)

shake = N * N - X.sum()     # 価値 right 以上の握手の回数
happy = (Acum[-1] - Acum[X]).sum() + (A * (N - X)).sum()    # 価値 right 以上の握手の価値の合計（左手＋右手）

happy += (M - shake) * left     # 価値 left の握手の価値を加算(M回までの制約なので、価値 left の全ての組み合わせとは限らない)
print(happy)

Measured memory_bytes: 18756
#include <bits/stdc++.h>
#define rep(i, f, n) for (ll i = (f); i < (ll)(n); i++)
#define repe(i, f, n) for (ll i = (f); i <= (ll)(n); i++)
using namespace std;
using ll = long long;
using pint = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> c(n), s(n), f(n);
  rep(i, 0, n - 1) cin >> c[i] >> s[i] >> f[i];

  rep(i, 0, n) {
    int t = 0;
    rep(j, i, n - 1) {
      if (t < s[j])
        t = s[j];
      else if (t % f[j] == 0)
        ;
      else {
        t = t + f[j] - t % f[j];
      }
      t += c[j];
    }
    cout << t << endl;
  }

  return 0;
}


Measured memory_bytes: 3552
#include<bits/stdc++.h>
#define U [7<<15]={}
#define G )+((c=A[a]+A[P[a]]+C[a])%k?c:0)-M(
typedef long long L;using namespace std;map<L,L>T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U;L M(L f){return f?B[f]+M(f^f&-f):0;}L S(L a,L i){for(a=M(i++G i);i<2e5;i+=i&-i)B[i]+=a;}L D(L f){L d;for(map<L,L>::iterator I=T[f].begin();I!=T[f].end();I++)d=I->first,!Z[d]?P[d]=f,E[d]=E[f]+1,C[d]=I->second,Z[d]=1,D(d),Z[f]+=Z[d],Z[H[f]]<Z[d]?H[f]=d:0:0;}L K(L f){a=X[f];n=X[b];return a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f]G O[a])+K(P[a]):abs(M(O[f])-M(O[b]));}main(){for(cin>>n>>k;--*Z+n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(a=n=0);Z[n];a=H[P[++n]]-n?n:0)for(;!O[a];S(a=H[a],O[a]=++b))X[a]=n;for(cin>>a;cin>>s>>a>>b;S(H[a],O[a]),S(a,O[a]-1))*s&2?cout<<K(a)<<endl,0:A[a]+=b;}

Measured memory_bytes: 38084
import java.io.InputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();
    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
    }
    int last = 0;
    long ans = 0;
    for (int i = 0; i < n; i++) {
      if (last > 0 && a[i] > 0) {
        ans++; a[i]--;
      }
      ans += a[i] / 2;
      last = a[i] % 2;
    }
    os.println(ans);
  }

  private static class Scanner {

    private final InputStream is;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    Scanner(InputStream is) {
      this.is = is;
    }

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

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

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

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

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

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

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

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


Measured memory_bytes: 22996
#include<bits/stdc++.h>
#define pb          push_back
#define endl        '\n'
#define pll         pair<int,int>
#define vll          vector<int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define int	    int64_t
#define ios     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 
int n,i,j,k,l,sum=0,flag=0,t,w[101],m;
int dp[100001];
vector<int> v[100001];
int f(int node){
	if(dp[node]!=-1)
		return dp[node];
	int ans=0;
	for(auto j:v[node]){
		ans=max(ans,f(j)+1);
	}
	return dp[node]=ans;
}
void solve(){
	memset(dp,-1,sizeof dp);
    cin>>n>>m;
    for(int i=0;i<m;i++){
    	cin>>j>>k;
    	v[j].pb(k);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
    	ans=max(ans,f(i));
    }
    cout<<ans<<endl;
}
signed main()
{
    ios
    int test = 1;
    //cin>>test;
    while(test--){
    	solve();
    }
    return 0;
}

Measured memory_bytes: 8576
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int p[11000];
int q[11000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",p+i);
	for(int i=0;i<a;i++)scanf("%d",q+i);
	long long A=0;
	long long B=0;
	for(int i=0;i<a;i++){
		A+=p[i];
		B+=q[i];
	}
	if(A>B){
		printf("No\n");return 0;
	}
	long long ar=0;
	long long br=0;
	for(int i=0;i<a;i++){
		if(p[i]<q[i]){
			ar+=(q[i]-p[i]+1)/2;
			if(q[i]%2!=p[i]%2)br++;
		}else{
			br+=p[i]-q[i];
		}
	}
	if(ar>B-A||br>B-A){
		printf("No\n");
	}else printf("Yes\n");
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = Long.parseLong(sc.next());
		long a = x/11;
		long b = x%11;
		if(b == 0)
			System.out.println(String.valueOf(a*2));
		else if(b <= 6)
			System.out.println(String.valueOf(a*2 + 1));
		else
			System.out.println(String.valueOf(a*2 + 2));
	}
}

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

#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
namespace adaptor = boost::adaptors;

// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */

using ll = long long;
using ull = unsigned long long;

const ll INF = 1LL << 60;

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; }

/*
	int N;
	std::cin >> N;
	std::vector<int> vec(N);
	for (auto& v : vec)
	{
		std::cin >> v;
	}
*/

ll w[110];
ll v[110];
ll dp[110][100010];

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

	ll W;
	cin >> W;

	for (int i = 0; i < N; ++i) {
		std::cin >> w[i] >> v[i];
	}

	const int MAX_V = 100010;
	for (int i = 0; i < 110; ++i) {
		for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {
			dp[i][sum_v] = INF;
		}
	}

	dp[0][0] = 0;
	for (int i = 0; i < N; ++i) {
		for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {
			if (sum_v - v[i] >= 0) {
				chmin(dp[i + 1][sum_v], dp[i][sum_v - v[i]] + w[i]);
			}
			chmin(dp[i + 1][sum_v], dp[i][sum_v]);
		}
	}

	ll res = 0;
	for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {
		if (dp[N][sum_v] <= W) {
			res = sum_v;
		}
	}
	cout << res;
	return;
}

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

Measured memory_bytes: 89516
//S.G.N.//
#include <bits/stdc++.h>
using namespace std;
typedef vector< long long > vi;
typedef long long ll;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define fr(n) for(ll i=0;i<n;i++)
#define tr(a) for(auto it=a.begin();it!=a.end();it++)
#define N 998244353445 
#define PI 3.1415926535897932384
#define F first
#define S second
#define mp make_pair
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007

void solve()
{
 ll n;
 cin>>n;
 double a[n];
 fr(n)
 cin>>a[i];
 double dp[n+1][n+1];
fr(n+1)
dp[0][i]=0;
dp[0][0]=1;
fr(n+1)
{
  if(i==0)
    continue;
  rep(j,0,n+1)
  {

    if(j==0){
      dp[i][j]=dp[i-1][j]*(a[i-1]);
    }
    else
    {
      dp[i][j]=dp[i-1][j-1]*(1-a[i-1])+dp[i-1][j]*(a[i-1]);
      
      
    }
    //cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
    
  }
}
double ans=0;
rep(i,0,(n+1)/2)
{
  ans+=dp[n][i];
}
cout<<setprecision(10)<<ans;
}
int main()
{
  
  #ifndef ONLINE_JUDGE
     * freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif
  FAST
  ll test;
test=1;
  //cin>>test;
  while(test--)
  {
    solve();
  }
  return 0;
}

Measured memory_bytes: 74080
import sys
N = int(input())

if N > 81 or N == 50 or N == 60 or N == 70 or N == 80:
    print('No')
    sys.exit()
else:
    val = []
    i = 3
    while N != 1:
        if N % 2 == 0:
            val.append(2)
            N //= 2
        else:
            if i >= 10:
                print('No')
                sys.exit()
            elif N % i == 0:
                val.append(i)
                N //= i
            else:
                i += 2

print('Yes')
        


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

int main(){
  int N;
  cin >> N;
  vector < tuple<int,int,int> > vt;
  int A,B;
  int x;
  for(int i=0;i<N*2;i++){
    if(i<N){
      x=0;
    }else{
      x=1;
    }
    cin >> A >> B;
    vt.push_back(make_tuple(x,A,B));
  }
  int n=0;
  sort(vt.begin(),vt.end());
  vector < pair<int,int> > vp;
  for(int j=N;j<N*2;j++){
    for(int i=0;i<N;i++){
      if((get<1>(vt.at(i)) < get<1>(vt.at(j)))&&(get<2>(vt.at(i)) < get<2>(vt.at(j)))){
        vp.push_back(make_pair(get<2>(vt.at(i)),i));
      }
    }
    if(vp.size()!=0){
      sort(vp.begin(),vp.end());
      reverse(vp.begin(),vp.end());
      get<1>(vt.at(vp.at(0).second))=N*2;
      n++;
      while(vp.size()!=0){
        vp.pop_back();
      }
    }
  }
  cout << n << endl;
  return 0;
}


Measured memory_bytes: 256
n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
keep=1
count=0
ababa=0
for i in range(n):
  count+=1
  keep=a[keep-1]
  if keep==2:
    ababa=1
    print(count)
    break
if ababa==0:
  print(-1)

Measured memory_bytes: 7084
n = int(input())
l = []
for _ in range(n):
  xi,li = map(int,input().split())
  l.append([xi+li,xi-li])
l.sort(key=lambda x:x[0])
count = 1
r = l[0][0]
ll = l[0][1]
for i in range(1,n):
  if l[i][1] >= r:
    count += 1
    r = l[i][0]
    ll = l[i][1]
print(count)
    
    
  

Measured memory_bytes: 21336
#include <bits/stdc++.h>
// #include "lib.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define LLINF 1e18//1234567890987654321
#define INF 1234567890
#define pb push_back
#define ins insert
#define f first
#define s second
#define db 0
#define MAXN 200026
#define MAXK 26
#define MAXX 15000006
#define rep0(kk, l1, l2)for(long long kk = l1; kk < l2; kk++)
#define rep1(kk, l1, l2)for(long long kk = l1; kk <= l2; kk++)
#define bg(ms) *ms.begin()
#define ed(ms) *prev(ms.end(), 1)
#define addedge(a, b, c) v[a].pb(pi(b, c)); v[b].pb(pi(a, c))
#define ph push
#define all(x) x.begin(), x.end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef long long ll;
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
ll h, w, grid[501][501], co;
string ans;
string lts(ll x)
{
	stringstream s;
	s << x;
	return s.str();
}
int main()
{
	cin >> h >> w;
	for(ll i = 0; i < h; i++)
	{
		for(ll j = 0; j < w; j++)
		{
			cin >> grid[i][j];
		}
	}
	for(ll i = 0; i < h; i++)
	{
		for(ll j = 0; j < w-1; j++)
		{
			if(grid[i][j]%2 == 0)continue;
			grid[i][j] --;
			grid[i][j+1] ++;
			++co;
			ans += lts(i+1) + ' ' + lts(j+1) + ' ' + lts(i+1) + ' ' + lts(j+1+1) + '\n'; 
		}
		ll j = w-1;
		if(grid[i][j]%2 == 0 || i == h-1)continue;
		grid[i][j]--;
		grid[i+1][j] ++;
		co++;
		ans += lts(i+1) + ' ' + lts(j+1) + ' ' + lts(i+2) + ' ' + lts(j+1) + '\n';
	}
	cout << co << "\n";
	cout << ans << '\n';
	return 0;
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

typedef tuple<int,int,int,int,int>state;
const int INF=1001001001;
int W,H;
char fld[60][30];
int dist[60][30][60][30];

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

void solve(){
    fill_n(***dist,60*30*60*30,INF);
    priority_queue<state,vector<state>,greater<state>>que;
    rep(a,H)rep(b,W)rep(c,H)rep(d,W){
        if(b>=d||abs(a-c)+abs(b-d)>3)continue;
        if(fld[a][b]=='X'||fld[c][d]=='X')continue;
        if(a==H-1&&fld[a][b]=='0'){
            dist[a][b][c][d]=fld[c][d]-'0';
            que.push(make_tuple(dist[a][b][c][d],a,b,c,d));
        }
        if(c==H-1&&fld[c][d]=='0'){
            dist[a][b][c][d]=fld[a][b]-'0';
            que.push(make_tuple(dist[a][b][c][d],a,b,c,d));
        }
    }

    while(que.size()){
        int c,ly,lx,ry,rx;
        tie(c,ly,lx,ry,rx)=que.top();
        que.pop();
        if(ly==0&&fld[ly][lx]=='0'){
            cout<<c<<endl;
            return;
        }
        if(ry==0&&fld[ry][rx]=='0'){
            cout<<c<<endl;
            return;
        }
        if(dist[ly][lx][ry][rx]<c)continue;

        rep(i,9){
            int ny=ly+dy[i],nx=lx+dx[i];
            if(ny<0||ny>=H||nx<0||nx>=W||fld[ny][nx]=='X')continue;
            int nc=c+fld[ny][nx]-'0';
            if(dist[ly][lx][ny][nx]<=nc)continue;
            dist[ly][lx][ny][nx]=nc;
            que.push(make_tuple(nc,ly,lx,ny,nx));
        }
        rep(i,9){
            int ny=ry+dy[i],nx=rx-dx[i];
            if(ny<0||ny>=H||nx<0||nx>=W||fld[ny][nx]=='X')continue;
            int nc=c+fld[ny][nx]-'0';
            if(dist[ny][nx][ry][rx]<=nc)continue;
            dist[ny][nx][ry][rx]=nc;
            que.push(make_tuple(nc,ny,nx,ry,rx));
        }
    }

    cout<<-1<<endl;
}

signed main(){
    while(cin>>W>>H,W||H){
        rep(i,H)rep(j,W){
            cin>>fld[i][j];
            if(fld[i][j]=='S'||fld[i][j]=='T')fld[i][j]='0';
        }
        solve();
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

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

struct UnionFind{
	vi par;
	vi rank;

	UnionFind(int n=1){
		init(n);
	}

	// n要素で初期化
	void init(int n=1){
		par.resize(n);
		rank.resize(n);
		REP(i, n){
			par[i]=i;
			rank[i]=0;
		}
	}

	// xの根を求める
	int find(int x){
		if(par[x]==x){
			return x;
		}
		else{
			return par[x]=find(par[x]);
		}
	}

	// xとyが属する集合を併合
	bool unite(int x, int y){
		x=find(x);
		y=find(y);
		if(x==y){
			return false;
		}
		if(rank[x]<rank[y]){
			par[x]=y;
		}
		else{
			par[y]=x;
			if(rank[x]==rank[y]){
				++rank[x];
			}
		}
		return true;
	}

	// xとyが同じ集合に属するか判定
	bool issame(int x, int y){
		return find(x)==find(y);
	}
};

bool used[60];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int n;
	pii xy[60];
	cin>>n;
	REP(i, n){
		cin>>xy[i].first>>xy[i].second;
		--xy[i].first;
		--xy[i].second;
	}
	if(n==1){
		cout<<1<<'\n';
		return 0;
	}
	int ans=1e9;
	REP(i, n){
		REP(j, n){
			if(i==j){
				continue;
			}
			int dx=xy[j].first-xy[i].first;
			int dy=xy[j].second-xy[i].second;
			if(dx==0 && dy==0){
				continue;
			}
			UnionFind uf(n);
			REP(a, n){
				REP(b, n){
					if((xy[b].first-xy[a].first==dx) && (xy[b].second-xy[a].second==dy)){
						uf.unite(a, b);
					}
				}
			}
			REP(a, n){
				used[a]=false;
			}
			int cnt=0;
			REP(a, n){
				int tmp=uf.find(a);
				if(!used[tmp]){
					++cnt;
				}
				used[tmp]=true;
			}
			CHMIN(ans, cnt);
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };
int n, p;
int vl[50];
int main() {
	while (cin>>n>>p, n|p){
		int max = p;
		int ans = 0;
		for (int i = 0; i < n; i++){
			vl[i] = 0;
		}
		
		for (int i = 0; i < 10000000;i++){
			if (p > 0){
				vl[i%n]++;
				p--;
				if (p == 0 && vl[i%n] == max){
					ans = i%n;
					break;
				}
			}
			else{
				p=vl[i%n]++;
				vl[i%n] = 0;
			}
		}
		cout << ans << endl;
	}
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int Sum(const string&s){
  int n = (int)s.size();
  int sum = 0;
  for(int i = 0; i < n; ++i)sum += s[i] - '0';
  return sum;
}

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


Measured memory_bytes: 3588