akhauriyash/Code-Regression huggingface dataset:
#ARC162 C:Sum of gcd of Tuples(Easy)
import math
import numpy as np
import itertools
k = int(input())
ans = 0

if k == 1:
    ans = 1
else:
    for i in range(1,k+1):
        for j in range(1,k+1):
            a = math.gcd(i,j)
            for k in range(1,k+1):
                b = math.gcd(a,k)
                ans += b    
print(ans)

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

int kaibun(string s){
    int l = s.size();
    int no = 0;
    rep(i,l/2){
        if(s.at(i)==s.at(l-1-i)){
            continue;
        }
        else{
            no = 1;
            break;
        }
    }

    if(no==0){
        return 1;
    }
    else{
        return 0;
    }
}



int main(){
    string S;
    cin >> S;
    int N = S.size();

    string sub1 = S.substr(0,(N-1)/2);
    string sub2 = S.substr((N+3)/2-1);

    if(kaibun(S)==1 && kaibun(sub1)==1 && kaibun(sub2)==1){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

}



Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))

l.sort()
ans = 0
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      if l[i] != l[j] and l[j] != l[k] and l[i]+l[j] > l[k]:
        ans+=1
print(ans)    

Measured memory_bytes: 9156
#include <iostream>
#include<iomanip>
#include <cmath>
#include <climits>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <queue>
#include <tuple>
#include <map>
#include <list>
#include <string>
#include <numeric>
#include <utility>
#include <cfloat>

using namespace std;

bool verified[200000];
map <char, int> last_index;
int next_same_char[200000];
int main(){
    int D;
    cin >> D;
    if(D == 25){
        cout << "Christmas" << endl;
    } else if(D == 24){
        cout << "Christmas Eve" << endl;
    } else if(D == 23){
        cout << "Christmas Eve Eve" << endl;
    } else {
        cout << "Christmas Eve Eve Eve" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n,a,b=map(int,input().split())
x=list(map(int,input().split()))
ans=0
for i in range(n-1):
    if (x[i+1]-x[i])*a>b:
        ans+=b
    else:
        ans+=((x[i+1]-x[i])*a)
print(ans)


Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define int long long
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1<<(i-1)))
using namespace std;
int n,cur;
int a[20][20];
int c[1<<20],f[1<<20];
void dfs(int i,int x)
{
  if(i>n) f[cur]=max(f[cur],f[x]+c[cur^x]);
  else
  {
    dfs(i+1,x);
    if(bit(cur,i)) dfs(i+1,on(x,i));
  }
}
main()
{
  ios_base::sync_with_stdio(false),cin.tie(nullptr);
  //freopen("gr.inp","r",stdin);
  cin>>n;
  for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) cin>>a[i][j];
  for(int t=1;t<=(1<<n)-1;++t)
    for(int i=1;i<n;++i) if(bit(t,i))
      for(int j=i+1;j<=n;++j) if(bit(t,j)) c[t]+=a[i][j];
  memset(f,-127,sizeof(f));
  f[0]=0;
  for(int i=1;i<=(1<<n)-1;++i) cur=i,dfs(1,0);
  cout<<f[(1<<n)-1];
}


Measured memory_bytes: 10496
n=int(input())
r=[list(map(int,input().split())) for i in range(n)]
b=sorted([list(map(int,input().split())) for i in range(n)], key=lambda x:x[0])
cnt=0
for bb in b:
    t_r=[-1,-1]
    for rr in r:
        if rr[0]<bb[0] and t_r[1]<rr[1]<bb[1]:
            t_r=rr
    if t_r!=[-1,-1]:
        cnt+=1
        r.remove(t_r)
print(cnt)

Measured memory_bytes: 3064
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;

long long int gcd(long long int a, long long int b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

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

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

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

	cin >> N;
	L = N;
	vector<int>v(1, 1);
	for (int i = 2; i*i <= N; i++) {
		while (N%i == 0) {
			if (v.back() == i) {
				cout << -1 << endl;
				return 0;
			}
			v.push_back(i);
			N /= i;
		}
	}
	if (N > 1)v.push_back(N);
	long long int box = 1;
	for (int i = 1; i < v.size(); i++) {
		box = lcm(box, v[i] - 1);
	}
	N = L;
	//cerr << box << endl;
	if (gcd(box, N) != 1) {
		cout << -1 << endl;
		return 0;
	}
	long long int bag = box;
	R = box;
	for (int i = 2; i*i <= box; i++) {
		if (box%i == 0) {
			bag *= i - 1;
			bag /= i;
			while (box%i == 0) {
				box /= i;
			}
		}
	}
	if (box > 1) {
		bag *= box - 1;
		bag /= box;
	}
	box = R;
	//cerr << bag << endl;
	int ans = MOD;
	for (int i = 1; i*i <= bag; i++) {
		if (power(N, i, box) == 1%box) {
			ans = min(ans, i);
		}
		if (power(N, bag/i, box) == 1%box) {
			ans = min(ans, (int)bag/i);
		}
	}
	if (ans == MOD)ans = -1;
	cout << ans << endl;
	return 0;
}


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

int main(){
  ll s; cin >> s;
  ll x1, y1, x2, y2, x3, y3;
  x1 = 1e9;
  x2 = 1;
  if(s % x1 == 0) y2 = s / x1;
  else y2 = s / x1 + 1;
  y1 = x1 * y2 - s;
  cout << 0 << " " << 0 << " " << x1 << " " << y1 << " " << x2 << " " << y2 << endl;
  //cout << abs(x1 * y2 - x2 * y1) << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

string S;

int a;

int ans = 0;

int main()
{
	cin >> S;
	if (S[0] - '0' == 0)
	{
		a = 0;
	}
	else
	{
		a = 1;
	}

	for (int i = 1; i < S.size(); i++)
	{
		if (a == 0) a = 1;
		else if (a == 1) a = 0;

		if (S[i] - '0' != a)
		{
			ans++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 512
# 乗せれるだけ乗っけるのがいいと思うだけなんだけどどうなんでしょう
# なんか実装しにくい 世界一プログラミングが下手
# 二重whileなんてやるからだ forでいいやろ
n, c, k = map(int, input().split())
ans = 0
arr = sorted([int(input()) for _ in range(n)])
cur_passenger = 0
limit = arr[0] + k
for i in range(n):
    if cur_passenger < c and arr[i] <= limit:
        cur_passenger += 1
        # print("{}番目の人は{}のバスに乗せた".format(i, ans))
    else:
        cur_passenger = 1
        limit = arr[i] + k
        ans += 1
        # print("{}番目の人を{}のバスの最初の客にした".format(i, ans))
# あぶれた人を救済
if cur_passenger > 0:
    ans += 1
print(ans)


Measured memory_bytes: 8280
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int a,b;
	while(cin>>a>>b)cout<<a-b<<endl;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 2e5 + 10; 

int n,k;
int P[N][60];

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   cin >> n >> k;
   f(i,1,n+1){
      int x;
      cin >> x;
      P[i][0] = x;
   }
   f(j,1,60){
      f(i,1,n+1){
         P[i][j] = P[P[i][j-1]][j-1];
      }
   }
   int cur = 1;
   f(i,0,60){
      if((1ll<<i)&k){
         cur = P[cur][i];
      }
   }
   cout << cur << '\n';
   return 0;
} 

Measured memory_bytes: 97408
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <utility>
using namespace std;
typedef pair<int,int> P;
vector<P> p[2502];
vector<int> dp[2502];
int w,h,x,y,v,n,max_n;
int i,j,k;
char s[9];
int diff(P p1,P p2) {return abs(p1.first-p2.first)+abs(p1.second-p2.second);}
int main() {
	while(scanf("%d%d",&w,&h),w) {
		max_n=0;
		for(i=0;i<2502;i++) p[i].clear();
		for(i=0;i<h;i++)for(j=0;j<w;j++) {
			scanf("%s",s);
			if(*s=='S') p[0].push_back(P(j,i));
			else if(*s=='G') x=j,y=i;
			else if(*s!='.') {
				p[n=atoi(s)].push_back(P(j,i));
				if(max_n<n) max_n=n;
			}
		}
		p[max_n+1].push_back(P(x,y));
		max_n++;
		for(i=0;i<=max_n;i++) {
			dp[i].resize(n=p[i].size());
			for(j=0;j<n;j++) dp[i][j]=(1<<30);
		}
		dp[0][0]=0;
		for(i=1;i<=max_n;i++)
			for(j=0;j<p[i-1].size();j++)
				for(k=0;k<p[i].size();k++)
					dp[i][k]=min(dp[i][k],dp[i-1][j]+diff(p[i-1][j],p[i][k]));
		printf("%d\n",dp[max_n][0]);
	}
}

Measured memory_bytes: 1420
#include <iostream>
#include <cstdio>
#include <cassert>
#include <ctime>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define all(x) (x).begin(), (x).end()

#ifdef LOCAL
#define dbg(x) cerr << #x " = " << x << endl;
#define idbg(x) #x " = " << x
#include "pretty_print.h"
#else
#define dbg(x)
#define idbg(x) ""
#endif

#ifdef _WIN32
#  define LLD "%I64d"
#else
#  define LLD "%lld"
#endif

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

template <typename T> T sqr(T x) { return x * x; }
template <typename T> T abs(T x) { return x < 0? -x : x; }
template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; }
template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return true; } return false; }
template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return true; } return false; }


int main(int /* argc */, char** /* argv */)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef LOCAL
    assert(freopen("inp", "r", stdin));
    assert(freopen("out", "w", stdout));
    #endif
    int h1, m1, h2, m2, k;
    while (cin >> h1 >> m1 >> h2 >> m2 >> k) {
        cout << h2 * 60 + m2 - (h1 * 60 + m1) - k << endl;
    }

    cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;
    return 0;
}


Measured memory_bytes: 3804
<?php

    while(fscanf(STDIN,"%d %d",$tate,$yoko)) {
        if ($tate == 0 && $yoko == 0) {
            exit;
        }
        
        for($i = 0; $i < $tate; $i++) {
            for($j = 0; $j < $yoko; $j++) {
                if ($j == 0 || $j == $yoko - 1 || $i == 0 || $i == $tate - 1) {
                    echo "#";
                } else {
                    echo ".";
                }
            }
            echo PHP_EOL;
        }
        echo PHP_EOL;
    }

?>



Measured memory_bytes: 9196
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, M;
bool wa[202020], wb[202020];

int main()
{
	scanf("%d%d", &N, &M);
	for (int i = 0; i < M; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		if (a > b) swap(a, b);

		--a; --b;

		if (a == 0) wa[b] = true;
		if (b == N - 1) wb[a] = true;
	}

	for (int i = 0; i < N; ++i) {
		if (wa[i] && wb[i]) {
			puts("POSSIBLE");
			return 0;
		}
	}
	puts("IMPOSSIBLE");

	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
typedef vector<ll> vll;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const double pi=acos(-1);
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    vll a(n);
    rep(i,n)
		cin>>a[i];
    ll sum=0;
    for(int i=0;i<n;i++)
        sum+=a[i];
    ll ans=0;
    rep(i,n)
	{
        sum-=a[i];
        sum%=1000000007;
        ans+=sum*a[i];
        sum+=1000000007;
        ans%=1000000007;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4672
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
//#define int ll

const int N = 1e6 + 10;
int n, from[N], pref[N];
int get_sum(int l, int r) {
  return pref[r] - pref[l - 1];
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
	cin >> n;
  string s, t;
  cin >> s >> t;
  if (s == t) {
    cout << 0 << '\n';
    exit(0);
  }
  vector<pair<int, int>> kek;
  kek.pb({t[0] - 'a', 1});
  for (int i = 2; i <= n; i++) {
    if (t[i - 1] - 'a' != kek.back().F) {
      kek.pb({t[i - 1] - 'a', i});
    }
  }
  int ptr = n;
  for (int i = SZ(kek) - 1; i >= 0; i--) {
    ptr = min(ptr, kek[i].S);
    while (ptr && s[ptr - 1] - 'a' != kek[i].F) {
      ptr--;
    }
    if (ptr == 0) {
      cout << -1 << '\n';
      exit(0);
    }
    from[i] = ptr;
    pref[ptr]++;
  }
  for (int i = 1; i <= n; i++) {
    pref[i] += pref[i - 1];
  }
  for (int i = 0; i + 1 < SZ(kek); i++) {
    kek[i].S = kek[i + 1].S - 1;
  }
  kek.back().S = n;
  int ans = 0, cp = 1;
  for (int i = 0; i < SZ(kek); i++) {
    if (from[i] == kek[i].S) {
      continue;
    }
    cp = max(cp, kek[i].S);
    while (get_sum(from[i] + 1, cp) > cp - kek[i].S) {
      cp++;
    }
    ans = max(ans, cp - kek[i].S + 1);
  }
  cout << ans << '\n';
} 

Measured memory_bytes: 18960
#include <iostream>
#include <numeric>
#include <bits/stdc++.h>
using namespace std;
// long long -> lint
using lint = long long;
// fast cin and cout from hitonanode-san's code
// w/o 71 ms -> w/ 18 ms (tested on ABC148-D with C++14(GCC 5.4.1))
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;


int main(){
    // input
    int H, N, tmp;
    cin >> H >> N;
    int total = 0;
    for( int i=0; i<N; i++ ){
        cin >> tmp;
        total += tmp;
    } 

    // out
    printf( total >= H ? "Yes" : "No" );
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n>>m;
    tmp=min(n,m/2);
    ans=tmp;
    n-=tmp;
    m-=tmp*2;
    if(m==0||m==1)Cout(ans);
    else{
        ans+=m/4;
        Cout(ans);
    }
    return 0;
}


Measured memory_bytes: 764
fun main(args: Array<String>) {
    val n = readInteger()
    val aList = readIntegerList()
    val ave = aList.average()
    var minDeviation = Math.abs(ave - aList.first())
    var minIndex = 0
    for (i in 1 until n) {
        val deviation = Math.abs(ave - aList[i])
        if (deviation < minDeviation) {
            minDeviation = deviation
            minIndex = i
        }
    }
    println(minIndex)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 38048
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main() {
  string s, p;
  cin >> s >> p;
  s.append(s);
  if (s.find(p) != string::npos)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}

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

using namespace std;

using ll = long long;

ll dp[100001];
ll ww[100];
ll vs[100];

int main() {
  ll n, w;
  cin >> n >> w;
  for (ll i = 0; i < n; ++i) {
    cin >> ww[i] >> vs[i];
  }
  ll ans = 0;
  for (ll i = 0; i < n; ++i) {
    for (ll j = w - ww[i]; j >= 0; --j) {
      dp[j + ww[i]] = max(dp[j + ww[i]], dp[j] + vs[i]);
      // cout << dp[j + ww[i]] << endl;
    }
  }
  for (int i = 0; i <= w; ++i) {
    ans = max(ans, dp[i]);
    // cout << dp[i] << endl;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        private const int MODULO = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static bool Solve(int H, int W, string[] S)
        {
            Func<int, int, bool> blank = (i, j) => i < 0 || i >= H || j < 0 || j >= W || S[i][j] == '.';
            for (int i = 0; i < H; ++i)
            {
                for (int j = 0; j < W; ++j)
                {
                    if (S[i][j] == '#')
                    {
                        if (blank(i - 1, j)
                         && blank(i + 1, j)
                         && blank(i, j - 1)
                         && blank(i, j + 1))
                        {
                            return false;
                        }
                    }
                }
            }
            return true;
        }

        static void Main(string[] args)
        {
            var V = ReadInts();
            int H = V[0];
            int W = V[1];
            var S = new string[H];
            for (int i = 0; i < H; ++i) { S[i] = Read(); }
            Console.WriteLine(Solve(H, W, S) ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 13140
#include <stdio.h>

int main()
{
	int i=0,r=0,c=0,ii=0;
	scanf("%d %d",&r,&c);
	int a[100+1][100+1];

	
		for(i=0; i<r+1; i++)
		{
			for(ii=0; ii<c+1; ii++)
			{
				a[ii][i]=0;
				//printf("%d ",a[c][r]);
			}
			//printf("\n");
		}

		for(i=0; i<r; i++)
		{
			for(ii=0; ii<c; ii++)
			{
				a[ii][i]=0;
				//printf("%d ",a[ii][i]);
			}
			//printf("\n");
		}
		

	for(i=0; i<r; i++)
	{
		for(ii=0; ii<c; ii++)
		{
			scanf("%d", &a[ii][i]);
		}
	}

	for(ii=0; ii<c; ii++)
	{
		for(i=0; i<r; i++)
		{
		a[ii][r]+=a[ii][i];
		a[c][i]+=a[ii][i];
	//	a[c][r]+=a[c][i];

		}
	}
	
	for(i=0; i<r; i++) a[c][r]+=a[c][i];

	
	
	

	for(i=0; i<r+1; i++)
		{
			for(ii=0; ii<c+1; ii++)
			{
				
				printf("%d",a[ii][i]);
				if(ii!=c) printf(" ");
			}
			printf("\n");
		}

//	printf("\n");


return 0;
}



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


int main(){
	int a,b,cnt=0;
	cin >> a >> b;
	for(int i=1;i<=a;i++){
		for(int j=11;j<=b;j++){
			int x=j/10,y=(j%10);
			if(x<2 || y<2) continue;
			if(x*y==i){
				cnt++;
			}
		}
	}
	
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())

l = []
for _ in range(N):
    l.append(list(map(int, input().split())))

for m in range(N):
    if l[m][2] != 0:
        break

for i in range(0, 101):
    for j in range(0, 101):
        center = [i, j]
        h = l[m][2] + abs(i - l[m][0]) + abs(j - l[m][1])
        # print(i, j, h)

        flag = True

        number = list(range(N))
        number.pop(m)
        for k in number:
            # print(l[k])
            # print(l[k][0])
            if max(h - abs(i - l[k][0]) - abs(j - l[k][1]), 0) != l[k][2]:
                flag = False

        if flag:
            print(i, j, h)
            exit()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
using ll = long long;

int main(){
    int x;
    cin >> x;
    int ans=0;
    while(x>=500){
        ans+=1000;
        x-=500;
    }
    while(x>=5){
        ans+=5;
        x-=5;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<P, ll>;
#define rep(i,s,g) for(int i=s; i<g; i++)

int h, w;
std::vector<std::vector<bool>> fie(22, std::vector<bool>(22, 1));;
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

ll bfs(P sp){
	ll ret = 0;
	std::vector<std::vector<bool>> used(fie);
	std::queue<PP> que;
	que.push(PP(sp, 0));
	while(!que.empty()){
		P p;
		ll d;
		std::tie(p, d) = que.front();
		que.pop();
		if(used[p.first][p.second]) continue;
		used[p.first][p.second] = true;
		ret = std::max(ret, d);
		rep(i, 0, 4){
			ll nx = p.first + dx[i], ny = p.second + dy[i];
			if(!used[nx][ny]) que.push(PP(P(nx,ny), d+1));
		}
	}
	return ret;
}


int main(){
	scanf("%d %d", &h, &w);
	rep(i, 1, h+1){
		char s[w+1];
		scanf("%s", s);
		rep(j, 1, w+1) fie[i][j] = (s[j-1]=='#');
	}
	
	ll ans = 0;
	rep(sx, 1, h+1) rep(sy, 1, w+1){
		ans = std::max(ans, bfs(P(sx, sy)));
	}
	printf("%ld\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define vpi vector<ppi>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/

int main()
{
	fast
	pre

		
	int n;
	cin>>n;

	vector<ld> dp(n+1,0);

	dp[0] = 1;

	ld head;
	forn(i,0,n)
	{
		cin>>head;
		forr(j,i+1,0)
		{
			dp[j] = ((j == 0) ? 0 : (dp[j-1]*head)) + dp[j]*(1-head);
		}

		// cout<<dp[0]<<" "<<dp[1]<<endl;
	}


	ld ans = 0;

	forn(heads,0,n+1)
	{
		int tails = n-heads;
		if(heads > tails)
		{
			ans += dp[heads];
		}
	}

	cout<<ans;

	return 0;
}

Measured memory_bytes: 384
/* *****fireice**** */

#include<bits/stdc++.h>

#define ll long long int
#define vi vector<int>
#define vc vector<char>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define pii pair<int,int>
#define pb push_back
#define el '\n'
#define N 1000000007
#define re return
#define F first
#define S second
#define L length
#define mp make_pair
#define PI 3.14159265
#define all(a) (a).begin(),(a).end()
#define forup(i,n) for(int i=0;i<n;i++)
#define forf(i,x,n) for(int i=x;i<n;i++)
#define ford(i,n) for(int (i)=(n)-1;i>=0;(i)--)
#define take(a,n) forup(i,n) cin>>a[i];
using namespace std;

int gcdExtended(int a, int b, int *x, int *y)
{
    // Base Case
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }

    int x1, y1; // To store results of recursive call
    int gcd = gcdExtended(b%a, a, &x1, &y1);

    // Update x and y using results of recursive
    // call
    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}

ll modInverse(int a, int m)
{
    int x, y;
    int g = gcdExtended(a, m, &x, &y);
        // m is added to handle negative x
    ll res = ((ll)x%m + (ll)m) % m;

    return res;
}

ll poww(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return poww(x*x,n/2);
    else                             //n is odd
        return x*poww(x*x,(n-1)/2);
}

ll modularExponentiation(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}

inline ll max(ll a, ll b)
{
  if(a>b) re a;
  else re b;
}

inline ll min(ll a, ll b)
{
  if(a>b) re b;
  else re a;
}

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

    if (a == b)
        return a;

    if (a > b)
        return gcd(a-b, b);
    else return gcd(a, b-a);
}

ll ncr(int n,int r)
{
  ll ans=1;
  r=min(r,n-r);
  forup(i,r)
  {
    ans=(ans*(n-i)/(i+1))%N;
  }
  re ans;
}

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

  int t=1;
  //cin>>t;
  while(t--)
  {
    ll n,m,k;
    string s;
    cin>>s;
    if(s.L()!=6) {cout<<"No";re 0;}
    if(s[2]==s[3] && s[4]==s[5]) cout<<"Yes";
    else cout<<"No";

  }


  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int count1=0, count2=0;
    for(int i=0; i<s.size(); i++)
    {
        if(s[i]=='R')
            count1++;
    }
     for(int i=0; i<s.size(); i++)
    {
        if(s[i]=='B')
            count2++;
    }
    if(count1>count2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        while(true) {
        	int n = sc.nextInt();
        	if(n == 0) break;
        	int[] a = new int[n];
        	for(int i=0;i<n;i++) {
        		a[i] = sc.nextInt();
        	}
        	Arrays.sort(a);
        	int min = Integer.MAX_VALUE;
        	for(int i=0;i<n-1;i++) {
        		min = Math.min(Math.abs(a[i] - a[i+1]), min);
        	}
        	System.out.println(min);
        }
    }
}


Measured memory_bytes: 46944
k=int(input())
A=[int(i) for i in input().split()]
mi=2
ma=2

for i in range(k-1,-1,-1):
    mi=((mi+A[i]-1)//A[i])*A[i]
    if mi>ma:
        print(-1)
        break
    ma=(ma//A[i])*A[i]+(A[i]-1)
else:
    if A[-1]==2:
        print(mi,ma)
    else:
        print(-1)
    


Measured memory_bytes: 20112
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
	const int maxn=55;
	int a[maxn][maxn];
	int n;
	int main(){
		IOS
		cin>>n;
		long long ans=0;
		for(int i=1;i<=n;i++){
			if(i%3&&i%5)
				ans+=i;
		}
		cout<<ans<<endl;
		return 0;
	} 

Measured memory_bytes: 3648
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;

#define rp(i,t) for(int i=0;i<(t);i++)
#define rep(i,s,t) for(int i=(s);i<=(t);i++)
#define rsp(i,s,t) for(int i=(s);i<(t);i++)
#define rrp(i,t,s) for(int i=(t);i>=(s);i--)
#define rcp(i,s,b,d) for(int i=(s);b;d)
#define mst(a,x) memset(a,x,sizeof(a))
#define INF 0x3f3f3f3f
#define N

#define Dp puts("")
#define Dw printf
#define Ds printf("#")

typedef long long ll;
char ch;
ll n,m,ans;

inline void read(ll &x){x=0;do{ch=getchar();}while(ch<'0'||'9'<ch);do{x=x*10+ch-'0';ch=getchar();}while('0'<=ch&&ch<='9');}

int main(void)
{
	read(n),read(m);
	if((n<<1)<=m)
	{
		ans+=n;
		m-=n<<1;
		ans+=m>>2;
	}
	else ans=m>>1;
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 256
<?php
$line = trim(fgets(STDIN));
$array = explode(" ", $line);

list($n, $k) = $array;

$line2 = explode(" ",trim(fgets(STDIN)));

$count = 0;
foreach($line2 as $v){
    if($v >= $k){
        $count += 1;
    }
}
echo $count;

Measured memory_bytes: 12792
#include <stdio.h>

int main(void)
{
	int i, N;
	unsigned long long int power = 1;
	
	scanf("%d", &N);
	
	for(i = 1; i <= N; i++){
		power *= i;
		power = power % (1000000000+7);
	}
	
	printf("%llu\n", power);
	return 0;
}


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

int main(){
  int a,b,m;
  cin>>a>>b>>m;
  
  int arr[a];
  int brr[b];
  
  int mini_a = 99999999;
  int mini_b = 99999999;
  for(int i =0;i <a;i++)
  {cin>>arr[i]; mini_a = min(mini_a,arr[i]);}
  
  for(int i =0;i<b;i++)
  {cin>>brr[i]; mini_b = min(mini_b, brr[i]);}
  
	int x,y,d;
  int mini = mini_a + mini_b;
  
  for(int i =0;i < m;i++)
    {cin>>x>>y>>d;
   mini = min(mini, arr[x - 1] + brr[y -1] - d);
    }
  cout<<mini;
  
  return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader

fun main() {
    val br = System.`in`.bufferedReader()
    val n = br.readInt()
    val q = br.readInt()
    val colors = IntArray(n) { br.readInt() - 1 }
    val lefts = IntArray(q)
    val rights = IntArray(q) {
        lefts[it] = br.readInt() - 1
        br.readInt() - 1
    }
    val order = IntArray(q) { it }.sortedWith(Comparator { a, b -> rights[a].compareTo(rights[b]) })
    var idx = 0
    val fenwick = Fenwick(n)
    val answers = IntArray(q)
    val lastOccurrence = IntArray(n) { -1 }
    for (x in 0 until n) {
        val c = colors[x]
        if (lastOccurrence[c] != -1) {
            fenwick.add(n - lastOccurrence[c], -1)
        }
        lastOccurrence[c] = x
        fenwick.add(n - x, 1)
        while (idx < q && rights[order[idx]] == x) {
            answers[order[idx]] = fenwick.get(n - lefts[order[idx]])
            idx++
        }
    }
    print(answers.joinToString("\n"))
}

private class Fenwick(val size: Int) {
    private val ary = IntArray(size)

    fun add(idx: Int, v: Int) {
        var k = idx
        while (k <= size) {
            ary[k - 1] += v
            k += k and -k
        }
    }

    fun set(idx: Int, v: Int) {
        add(idx, v - get(idx, idx))
    }

    fun get(idx: Int): Int {
        var k = idx
        var r = 0
        while (k > 0) {
            r += ary[k - 1]
            k -= k and -k
        }
        return r
    }

    fun get(a: Int, b: Int): Int {
        return get(b) - get(a - 1)
    }
}

private const val SPACE_INT = ' '.toInt()
private const val ZERO_INT = '0'.toInt()
private const val NL_INT = '\n'.toInt()

private fun BufferedReader.readInt(): Int {
    var ret = read()
    while (ret <= SPACE_INT) {
        ret = read()
    }
    val neg = ret == '-'.toInt()
    if (neg) {
        ret = read()
    }
    ret -= ZERO_INT
    var read = read()
    while (read >= ZERO_INT) {
        ret *= 10
        ret += read - ZERO_INT
        read = read()
    }

    while (read <= SPACE_INT && read != -1 && read != NL_INT) {
        mark(1)
        read = read()
    }
    if (read > SPACE_INT) {
        reset()
    }
    return if (neg) -ret else ret
}

Measured memory_bytes: 91960
import java.util.*;
class Main {
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int x = A+B;
		int y = A-B;
		int z = A*B;
		if(x>=y && x>=z) {
			System.out.println(x);
		}else if(y>=x && y>=z) {
			System.out.println(y);
		}else {
			System.out.println(z);
		}
	}
}

Measured memory_bytes: 22868
N = int(input())
from math import sqrt

def divisor(num):
    max_num = int(sqrt(num))
    divisor_list = []
    for i in range(1, max_num + 1):
        if num % i == 0:
            divisor_list.append(i)
            divisor_list.append(num//i)
    return divisor_list

K0 = divisor(N)
K1 = divisor(N-1)
S = set(K1)
S.remove(1)
for k in K0:
    tmp = N
    if k == 1:
        continue
    while tmp % k == 0 and tmp >= k:
        tmp //= k
    if tmp % k == 1:
        S.add(k)
print(len(S))

Measured memory_bytes: 65736
n=int(input())

if n<4:
    print("No")
    exit()

a=n//4
b=n//7

ans=[]
for i in range(0,a+1):
    for j in range(0,b+1):
        if i*4+j*7==n:
            print("Yes")
            exit()
print("No")


Measured memory_bytes: 3060
using System; 
using System.Collections;

namespace CSharp
{
    class Edge 
    {
        public int x, y;
        public Edge(int _x, int _y)
        {
            x = _x;
            y = _y;
        }
    }

    class Program
    {

        private static int[] parent, size, rank;

        private static int find(int u) 
        {
            if (u == parent[u]) return u;
            return parent[u] = find(parent[u]);
        }

        private static long merge(int u, int v)
        {
            u = find(u); v = find(v);
            if (u == v) return -1L;
            int size_u = size[u], size_v = size[v];
            if (rank[u] < rank[v])
            {
                parent[u] = v;
                size[v] += size[u];
            }
            else
            {
                parent[v] = u;
                size[u] += size[v];
            }
            if (rank[u] == rank[v]) rank[u]++;
            return size_u * (size_u - 1L) * 1L / 2L + size_v * (size_v - 1L) * 1L / 2L;
        }

        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int n = int.Parse(s[0]);
            int m = int.Parse(s[1]);

            parent = new int[n + 1];
            size = new int[n + 1];
            rank = new int[n + 1];

            Edge[] edges = new Edge[m];
            for (int i = 0; i < m; i++) {
                string[] es = Console.ReadLine().Split();
                int u = int.Parse(es[0]);
                int v = int.Parse(es[1]);

                edges[i] = new Edge(u, v);
            }

            for (int i = 1; i <= n; i++) {
                parent[i] = i;
                size[i] = 1;
            }

            long[] ans = new long[m];
            long tmp = n * (n - 1L) * 1L / 2L;

            for (int i = 0; i < m; i++) {
                ans[m - i - 1] = tmp;
                Edge edge = edges[m - i - 1];
                long delta = merge(edge.x, edge.y);
                if (delta == -1L) continue;
                tmp += delta;
                int nsize = size[find(edge.x)];
                tmp -= nsize * (nsize - 1L) * 1L / 2L;
            }

            for (int i = 0; i < m; i++) {
                Console.WriteLine(ans[i]);
            }
        }
    }
}


Measured memory_bytes: 24776
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
int m[105];
int main(int argc, char *argv[]) {
    int n,x,mn=1000;
    scanf("%d%d", &n,&x);
    for (int i = 0; i < n; i++) {
        scanf("%d", &m[i]);
        if (mn>m[i]){
            mn=m[i];
        }
        x-=m[i];
    }
    printf("%d\n", n+x/mn);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define fi first
#define se second 
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define rep(i,a,b) for( ll i = a ; i < b ; i+=1 )
#define pp pair<ll,ll> 
#define sz(v) (ll)(v.size())
#define hell (ll)1000000007
#define slld(x) scanf("%lld",&x)
ll t = 1;
void solve() 
{
	vector<ll> v(3);
	cin>>v[0]>>v[1]>>v[2];
	sort(all(v));
	if((v[0]==v[1] and v[1]==v[2]) || (v[0]!=v[1] and v[1]!=v[2]))
		cout<<"No\n";
	else
		cout<<"Yes\n";
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //cin >> t ;
    while(t--){
        solve();
    }
    return 0 ;
}


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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename Ostream,typename Container>
Ostream& operator<<(Ostream& os,const Container& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

inline int ncr(int n,int r)
{
	static int memo[201][201];
	if(memo[n][r]) return memo[n][r];
	if(r==0 || r==n) return 1;
	return memo[n][r]=(ncr(n-1,r-1)+ncr(n-1,r))%MOD;
}
inline int npr(int n,int r)
{
	static int memo[201][201];
	if(memo[n][r]) return memo[n][r];
	if(r==0) return 1;
	return memo[n][r]=n*(ll)npr(n-1,r-1)%MOD;
}

int solve(vi as)
{
	array<int,801> ts={1}; // ts[i]=10^i mod m
	repi(i,1,ts.size()) ts[i]=(ll)ts[i-1]*10%MOD;
	array<int,201> fs={1}; // fs[i]=i! mod m
	repi(i,1,fs.size()) fs[i]=(ll)fs[i-1]*i%MOD;
	
	sort(all(as));
	
	int n=as.size();
	vi ls(n);
	rep(i,n){
		if(as[i]==0) ls[i]=1;
		for(int x=as[i];x;x/=10) ls[i]++;
	}
	array<int,5> hist={0};
	rep(i,n) hist[ls[i]]++;
	
	array<int,5> bs,es;
	repi(i,1,5){
		bs[i]=lower_bound(all(ls),i)-begin(ls);
		es[i]=upper_bound(all(ls),i)-begin(ls);
	}
	
	ll res=0;
	rep(c1,hist[1]+1) rep(c2,hist[2]+1) rep(c3,hist[3]+1) rep(c4,hist[4]+1){
		array<int,5> uses={-1,c1,c2,c3,c4};
		const int locnt=c1+c2+c3+c4;
		const int lolen=c1+2*c2+3*c3+4*c4;
		repi(len,1,5) if(uses[len]<hist[len]){
			hist[len]--;
			int lopat=fs[locnt];
			repi(j,1,5) lopat=(lopat*(ll)ncr(hist[j],uses[j]))%MOD;
			hist[len]++;
			ll hipat=0;
			rep(j,n-locnt) hipat+=npr(n-locnt-1,j);
			hipat%=MOD;
			ll coeff=(ll)ts[lolen]*lopat%MOD*hipat%MOD;
			repi(j,bs[len],es[len])
				res+=as[j]*coeff%MOD;
			res%=MOD;
		}
	}
	return res;
}

int main()
{
	for(int n;cin>>n && n;){
		vi as(n);
		rep(i,n) cin>>as[i];
		
		int res=solve(as);
		if(count(all(as),0)){
			as.erase(find(all(as),0));
			res=(res-solve(as)+MOD)%MOD;
		}
		cout<<res<<endl;
	}
}

Measured memory_bytes: 1456
#include<bits/stdc++.h>
using namespace std;
int n,l,m,t[1004][1004];
vector < pair < int,pair < int,pair < int,int > > > > v;
int main()
{
    ios_base::sync_with_stdio(0);
    scanf("%d %d",&n,&m);
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            scanf("%d",&l);
            t[i][j]+=l;
            if(t[i][j]%2==1)
            {
                if(j!=m)
                {
                    t[i][j+1]++;
                    v.push_back( { i, { j, {i,j+1} } } );
                }
                else if(i!=n)
                {
                    t[i+1][j]++;
                    v.push_back( { i,{ j, { i+1,j } } } );
                }
            }
        }
    }
    m=v.size();
    cout<<m<<endl;
    for(int i=0; i<m; i++)
    {
        cout<<v[i].first<<" "<<v[i].second.first<<" "<<v[i].second.second.first<<" "<<v[i].second.second.second;
        if(i!=m-1) cout<<endl;
    }
}


Measured memory_bytes: 6128
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


//INSERT ABOVE HERE
signed main(){
  Int l,n;
  cin>>l>>n;
  string s;
  cin>>s;
  Int oo=0;
  for(Int i=0;i+1<l;i++)
    oo+=s[i]=='o'&&s[i+1]=='o';

  Int len=l;
  for(Int i=0;i<n;i++){
    len+=oo*3;
    oo*=2;
  }
  cout<<len<<endl;
  return 0;
}



Measured memory_bytes: 3192
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int a, b, c, d = 0, e;
	cin >> a >> b >> c;
	for (int h = 1; h <= a; h++) {
		if (h <= 9) {
			if (h >= b && h <= c) {
				d = d + h;
			}
		}
		else if (h > 9 && h < 100) {
			if (h / 10 + h % 10 >= b && h / 10 + h % 10 <= c) {
				d = d + h;
			}
		}
		else if (h > 99 && h < 1000) {
			if (h / 100 + h % 100 / 10 + h % 100 % 10 >= b && h / 100 + h % 100 / 10 + h % 100 % 10 <= c) {
				d = d + h;
			}
		}
		else if (h >= 1000 && h < 10000) {
			if (h / 1000 + h % 1000 / 100 + h % 1000 % 100 / 10 + h % 1000 % 100 % 10 >= b && h / 1000 + h % 1000 / 100 + h % 1000 % 100 / 10 + h % 1000 % 100 % 10 <= c) {
				d = d + h;
			}
		}
		else {
			if (1 >= b) {
				d = d + h;
			}
		}
	}
	cout << d << "\n";
	cin >> e;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())

signed main(){

	lli n;
	cin>>n;

	vector<lli> d(n);

	REP(i,0,n)cin>>d[i];

	lli sum = 0;

	REP(i,0,n)REP(j,i+1,n){
		sum += (d[i]*d[j]);
	}

	cout<<sum<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int solve(bool visited[20][20],vector<string> v,int x,int y,int w,int h){
	if(x<0||y<0||w<=x||h<=y) return 0;
	if(visited[y][x]==true||v[y][x]=='#') return 0;
	int sum=1;
	visited[y][x]=true;
	sum+=solve(visited,v,x+1,y,w,h);
	sum+=solve(visited,v,x,y+1,w,h);
	sum+=solve(visited,v,x-1,y,w,h);
	sum+=solve(visited,v,x,y-1,w,h);
	return sum;
}
int main(void){
	int w,h;
	while(cin>>w>>h,w||h){
		vector<string> v;
		bool visited[20][20];
		for(int i=0;i<20;++i) for(int j=0;j<20;++j)visited[i][j]=false;
		int x,y;
		for(int i=0;i<h;++i){
			string s;cin>>s;
			if(s.find("@")!=-1){x=s.find("@");y=i;}
			v.push_back(s);
		}
		cout<<solve(visited,v,x,y,w,h)<<endl;
	}
	return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair

typedef long long int ll;
typedef vector< pair<int,int> > vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long int> vll;
typedef pair<int,int> pii;

const ll INF= ll (1e18);
const int MOD= 1e9+7;
const int N=200000+10;

ll arr[N];

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

    ll n,c,k;

    cin>>n>>c>>k;

    for(int i=1;i<=n;i++)
        cin>>arr[i];

    sort(arr+1,arr+n+1);

    ll time=arr[1]+k;
    ll bus=1;
    ll cap=1;

    for(int i=1;i<n;i++)
    {

        if(arr[i+1]>time||cap==c)
            {

                bus++;
                cap=1;
                time=arr[i+1]+k;
            }
            else
            {
                cap++;
            }

    }
    cout<<bus<<endl;

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
#include<random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const int MOD=1e9+7;

int main(){

  int a[3][3], b[11], n;
  bool flag[3][3];
  rep(i, 3) rep(j, 3) cin >> a[i][j], flag[i][j] = false;
  cin >> n;
  rep(i, n) cin >> b[i];
  rep(i, n) rep(j, 3) rep(k, 3) if(b[i] == a[j][k]) flag[j][k] = true;
  string ans = "No";
  rep(i, 3) if(flag[i][0] && flag[i][1] && flag[i][2]) ans = "Yes";
  rep(i, 3) if(flag[0][i] && flag[1][i] && flag[2][i]) ans = "Yes";
  if(flag[0][0] && flag[1][1] && flag[2][2]) ans = "Yes";
  if(flag[0][2] && flag[1][1] && flag[2][0]) ans = "Yes";
  cout << ans << endl;

  return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  cin>>N;
  vector<int>p(N);
  for(int i=0;i<N;i++)cin>>p[i];
  bool ok=false;
  int ans=0;
  for(int i=0;i<N;i++){
    if(i==N-1&&p[i]==i+1){
      ans++;
    }
    else if(ok&&p[i]==i+1){
      ok=false;
      ans++;
    }
    else if(ok){
      ok=false;
      ans++;
    }
    else if(!ok&&p[i]==i+1){
      ok=true;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int a = in.nextInt();
            int b = in.nextInt();

            if (a + b == 15) {
                System.out.println("+");
                return;
            }
            if (a * b == 15) {
                System.out.println("*");
                return;
            }
            System.out.println("x");
        }
    }
}


Measured memory_bytes: 21716
#include <stdio.h>
#define N 500000
#define P 250000
#define SENTINEL 1000000000
int s[N];
long count;

void MergeSort(int *,int,int);
void Merge(int *,int,int,int);

main(){
  long n,i,left,right;

  scanf("%d",&n);
  for(i=0; i<n; i++)
    scanf("%d",&s[i]);

 
  left=0;
  right=n;

  MergeSort(s,left,right);

  for(i=0; i<n-1; i++)
    printf("%d ",s[i]);
  printf("%d\n%d\n",s[n-1],count);
  return 0;

}


void MergeSort(int *s, int left, int right){
  long mid;
  if(left+1<right){
    mid=(left+right)/2;
    MergeSort(s,left,mid);
    MergeSort(s,mid,right);
    Merge(s,left,mid,right);
  }
}
  
void Merge(int *s, int left, int mid, int right){
  long n1,n2,i,j,k;
  
  n1=mid-left;
  n2=right-mid;

  int l[n1+1],r[n2+1];

  for(i=0; i<n1; i++)
    l[i]=s[left+i];

  for(i=0; i<n2; i++)
    r[i]=s[mid+i];
  
  l[n1]=SENTINEL;
  r[n2]=SENTINEL;
  
  i=0;
  j=0;
  
  for(k=left; k<right; k++){
    if(l[i]<=r[j]){
      s[k]=l[i];
      i++;
    }
    else {
      s[k]=r[j];
      j++;
    }
    count++;
  }
}

Measured memory_bytes: 4504