akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL)
    x=x->left;
  return x;
}

Node treeMaximum(Node x){
  while(x->right!=NIL)
    x=x->right;
  return x;
}

Node treeSearch(Node u, int k){
while(u!=NIL && k!=u->key){
    if(k<u->key) u=u->left;
    else u=u->right;         }
  return u;
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL)
    return treeMinimum(x->right);

  y=x->parent;
  while(y!=NIL && x==y->right)
    {x=y;
      y=y->parent;}
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left == NIL || z->right == NIL)y=z;
  else y=treeSuccessor(z);
  if(y->left!=NIL) x=y->left;
  else x=y->right;

  if(x!=NIL) x->parent=y->parent;
  if(y->parent==NIL)root=x;
  else if(y==y->parent->left)y->parent->left=x;
    else y->parent->right=x;

  if(y!=z) z->key=y->key;
  free(y);
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL)
    {y=x;
      if(z->key < x->key) x=x->left;
      else x=x->right;  }
  z->parent = y;
  if(y==NIL) root=z;
  else
    { if(z->key < y->key)y->left=z;
      else y->right=z;
    }
}

void inorder(Node u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    }
    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20452
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
     
long long A, B, ans;
double b;
     
int main() {
  std::cin >> A >> b;
  b = b * 100;
  B = round(b);
  ans = (long long)((A * B) / 100);
  std::cout << ans << std::endl;
     
  return 0;
}

Measured memory_bytes: 3780
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  ll ans = a;

  if(k <= a) {
    ans = k;
  } else if(k <= a + b) ans = a;
  else {
    ans = a - (k - (a + b));
  }
  cout << ans << endl;

}

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

using namespace std;

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for(ll i =0;i<t;i++)
#define bs(a,x) binary_search(a.begin(),a.end(),x)
#define ll long long int
#define ul unsigned long int
#define ld long double
#define umpi unordered_map<int,int> 
#define umpl unordered_map<ll,ll> 
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define mod 1000000007 
#define N 10000000
#define all(a) a.begin(),a.end()
#define point pair<int,int>
const int inf = 1000000007;
const ll linf = 1ll * inf * inf;

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c >= mod) c -= mod; return c; }

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

int main()
{	
	fio;
	ll t;t=1;
	while(t--)
	{
		ll n,k;cin>>n>>k;
		vl a(n);
		f(n)cin>>a[i];
		ll dp[k+1];
		memset(dp,0,sizeof(dp));
		dp[0]=1;
		for(ll i=0;i<n;i++)
		{
			vl fake(k+1,0);
			for(ll used=k;used>=0;used--)
			{
				ll l=used+1;
				ll r=used+min(a[i],k-used);
				if(l<=r){
					fake[l]=add(fake[l],dp[used]);
					if(r+1<=k){
						fake[r+1]=sub(fake[r+1],dp[used]);
					}
				}
			}
			ll sum=0;
			for(ll j=0;j<=k;j++)
			{
				sum=add(sum,fake[j]);
				dp[j]=add(dp[j],sum);
			}
		}
		cout<<dp[k]<<"\n";
	}
}


Measured memory_bytes: 1792
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
ng=0
ok=10**9
while ok-ng >1:
  l = (ng+ok)//2
  kt=0
  for i in range(n):
    kt += a[i]//l - (0 if a[i]%l else 1)
  if kt <= k:
    ok = l
  else:
    ng = l
print(ok)

Measured memory_bytes: 93824
#include<cstdio>
#include<vector>
using namespace std;

int main(){
	unsigned N, K;
	scanf("%u %u\n", &N, &K);
	bool left_is_upsidedown = false;
	unsigned consecutive = 0;
	vector<unsigned> A;
	A.push_back(0);
	for (unsigned i = 0; i < N; ++i){
		char tmp;
		scanf("%c", &tmp);
		bool this_is_upsidedown = tmp == '1';
		if(left_is_upsidedown ^ this_is_upsidedown){
			A.push_back(consecutive);
			consecutive = 1;
			left_is_upsidedown ^= 1;
		}else{
			consecutive++;
		}
	}
	A.push_back(consecutive);
	unsigned ans = 0, block = A.size();
	for (unsigned i = 1; i <= K*2 && i < block; ++i){
		ans += A[i];
	}
	unsigned candidate = ans;
	for (int i = 0; i*2 + K*2 + 1 < block; ++i){
		candidate = candidate + A[i*2 + K*2 + 1] - A[i*2] - A[i*2 + 1];
		if(i*2 + K*2 + 2 < block) candidate += A[i*2 + K*2 + 2];
		if(ans < candidate) ans = candidate;
	}
	printf("%u\n", ans);
	return 0;
}

Measured memory_bytes: 892
#include <iostream>
using namespace std;
int main()
{
	int a[5];
	for(int i=0;i<3;i++)
		cin>>a[i];
	if(a[0]%2==0||a[1]%2==0||a[2]%2==0)
		cout<<"0";
	else
	{
		long long max=0;
		int maxid=-1;
		for(int i=0;i<3;i++)
		{
			if(a[i]>max)
			{
				max=a[i];
				maxid=i;
			}
		}
		long long sum=1;
		for(int i=0;i<3;i++)
			if(i!=maxid)
				sum*=a[i];
		cout<<sum<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(int)(n);++i)
using namespace std;
int main()
{
  int n,l,r,sum;
  cin>>n;
  for(int i=0;i<n;++i){
    cin>>l>>r;
    sum+=r-l;
    sum++;
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int a,b,c;
  int ans;
  scanf("%d %d %d",&a,&b,&c);
 
  if(a==b && b==c){
    ans=1;
  }else if(a==b && b!=c){
    ans=2;
  }else if(a!=b && b==c){
    ans=2;
  }else if(a!=b && b!=c && a==c){
    ans=2;
  }else{
    ans=3;
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

constexpr ll MOD = 1000000007;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

int main() {
  int n;
  cin >> n;
  vector<ll> l(n), r(n);
  rep(i, 0, n) cin >> l[i] >> r[i];

  sort(l.begin(), l.end());
  sort(r.begin(), r.end());
  if (n % 2 == 0) {
    cout << r[n / 2] + r[n / 2 - 1] - (l[n / 2] + l[n / 2 - 1]) + 1;
  } else {
    cout << r[n / 2] - l[n / 2] + 1;
  }
  return 0;
}

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

using ll=long long;

int main(){
    int N; cin >> N;
    vector<ll> cnt(N, 0);
    vector<int> A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
        if(i-A[i] < 0) continue;
        cnt[i-A[i]]++;
    }
    ll res=0;
    for(int i=0; i<N; i++){
        if(i+A[i] >= N) continue;
        res+=cnt[i+A[i]];
    }
    cout << res << endl;
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  for(int i=0; s[i]!='\0'; i++) {
    if(s[i]=='?') s[i]='D';
  }
  cout << s << endl;
}


Measured memory_bytes: 3724
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i = 0;i < (n); ++i)
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> p(n), q(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];
    vector<int> a(n);
    rep(i,n) a[i] = i+1;

    map<vector<int>, int> mp;
    do {
        mp[a] = mp.size();
    } while(next_permutation(a.begin(), a.end()));
    int ans = abs(mp[p] - mp[q]);
    cout << ans << endl;
}

Measured memory_bytes: 5248
//#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include<cmath>
#pragma warning (disable:4996)
using namespace std;

vector<vector<float>> minKoch(vector<float> s, vector<float>t) {
	vector<float> u = { (2 * s[0] + t[0]) / 3,(2 * s[1] + t[1]) / 3 };
	vector<float> v = { (s[0] + t[0]) / 2 - (t[1] - s[1])*sqrtf(3) / 6,(s[1] + t[1]) / 2 + (t[0] - s[0])*sqrtf(3) / 6 };
	vector<float> w = { (s[0] + 2 * t[0]) / 3,(s[1] + 2 * t[1]) / 3 };
	vector<vector<float>> ret(5);
	ret[0] = s;
	ret[1] = u;
	ret[2] = v;
	ret[3] = w;
	ret[4] = t;
	return ret;
}

vector<vector<float>> Koch(vector<vector<float>>p) {
	int num = p.size(),k=0;
	vector<vector<float>> q;
	vector<vector<float>>K(num + (num - 1) * 3);
	for (int i = 0; i < num - 1; i++) {
		q = minKoch(p[i], p[i + 1]);
		for (int j = 0; j < 4; j++) {
			K[k] = q[j];
			k++;
		}
	}
	K[k] = q[4];
	return K;
}

int main() {
	vector<vector<float>> ans = { {0,0 }, {100, 0}};
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		ans = Koch(ans);
	}
	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i][0] << " " << ans[i][1] << endl;
	}
}


Measured memory_bytes: 3364
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>

using namespace std;

#define ll long long

int main(void){
    int i , j, k;
    int n;
    cin >> n;
    vector<int> l(n);
    for(i = 0;i < n;++i)    cin >> l[i];

    sort(l.begin(), l.end());

    int ans = 0;
    int old_a = -1, old_b = -1, old_c = -1;

    i = 0;
    j = 1;
    k = 2;
    for(i = 0;i < j;++i){
        for(j = i+1; j < k;++j){
            for(k = j+1;k < n;++k){
                if((l[i] < l[j]+l[k]) && (l[j] < l[i]+l[k]) && (l[k] < l[i]+l[j])){
                    ans++;
                }
            }
        }
    }

    cout << ans << endl;
    

    


    return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int r;
  cin >> r;
  if (r < 1200) cout << "ABC";
  else if (r < 2800) cout << "ARC";
  else cout << "AGC";
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3596
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50

def run():
    S = int(input())
    x1 = 10 ** 9
    y1 = 1
    if not S % x1:
        x2 = 0
        y2 = S // x1
    else:
        x2 = x1 - (S % x1)
        y2 = S // x1 + 1
    print(0,0,x1,y1,x2,y2)
    #print(x1 * y2 - x2 * y1)

if __name__ == "__main__":
    run()

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

using namespace std;
typedef long long ll;

int main() {
    int n, m; cin >> n >> m;
    vector<int> c(m);
    for (int i = 0; i < m; i++) {
        cin >> c[i];
    }

    vector<int> dp(n+1, 1000010010);
    dp[0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < m; j++) {
            if (i - c[j] >= 0) dp[i] = min(dp[i], dp[i - c[j]]+1);
        }
    }
    cout << dp[n] << endl;
}



Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
  for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
  for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
//#define endl "\n"
#define ciosup \
  cin.tie(0);  \
  ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (int i = 0; i < v.size(); ++i) {
    is >> v[i];
  }
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < v.size() - 1; ++i) {
    os << v[i] << " ";
  }
  if (v.size() > 0) {
    os << v[v.size() - 1] << endl;
  }
  return os;
}

int main() {
  int h,w;
  cin >> h >> w;
  vector<vint> a(h, vint(w));
  REP(i,h){
    REP(j, w) { cin >> a[i][j]; }
  }
  REP(i, h) {
    REP(j, w) {
      int b;
      cin >> b;
      a[i][j] = abs(a[i][j] - b);
    }
  }
  vector<vector<vector<bool>>> dp(h+1, vector<vector<bool>>(w+1, vector<bool>(2*160*80 + 1, false)));
  dp[0][1][160*80] = true;
  REP(i, h) {
    REP(j,w){
      FOR(k, 0, 2*160*80+1){
        if (dp[i+1][j][k]){
          if (0 <= k - a[i][j] && k - a[i][j] <= 2*160*80){
            dp[i + 1][j + 1][k - a[i][j]] = true;
          }
          if (0 <= k + a[i][j] && k + a[i][j] <= 2 * 160 * 80) {
            dp[i + 1][j + 1][k + a[i][j]] = true;
          }
        }
        if (dp[i][j+1][k]) {
          if (0 <= k - a[i][j] && k - a[i][j] <= 2 * 160 * 80) {
            dp[i + 1][j + 1][k - a[i][j]] = true;
          }
          if (0 <= k + a[i][j] && k + a[i][j] <= 2 * 160 * 80) {
            dp[i + 1][j + 1][k + a[i][j]] = true;
          }
        }
      }
    }
  }
  int ans = INT_MAX;
  FOR(k, 0, 2 * 160 * 80) {
    if (dp[h][w][k]){
      int tmp = abs(k - 160 * 80);
      ans = min(ans, tmp);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 23424
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
long long n, m;

int gcd(int a, int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

void solve() {
    cout << abs(n * m) << endl; 
    return;
}

int main() {
    cin >> n >> m;
    n = n - 2;
    m = m - 2;
    solve();
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#if ONLINE_JUDGE
#define DEBUG false
#else
#define DEBUG true
#endif
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)
#define foreach(i, vec) for(auto &&i : vec)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define truecheck assert
#define dump(x) cerr << #x << ": " << (x) << endl
using namespace std;
typedef long long LL;
typedef long long int64;
typedef std::vector<int> VI;
typedef std::vector<VI> VVI;
typedef std::vector<LL> VL;
typedef std::vector<VL> VVL;
typedef std::vector<string> VS;
typedef std::pair<int, int> PII;
typedef std::pair<int64, int64> PLL;
typedef std::queue<int> QI;
typedef std::priority_queue<int> PQI;
template<class T,class U>inline bool chmax(T &a, const U &b){if (a<b){a=b;return true;}return false;}
template<class T,class U>inline bool chmin(T &a, const U &b){if (b<a){a=b;return true;}return false;}
template<class T,class U>inline void vcin(T &v, U n){rep(i, n){typename T::value_type a;cin >> a;v.pb(a);}}
const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;
// M_PI 3.1415...

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cill(n);
    cill(k);
    VL dp(100100, INF);
    VL h;
    vcin(h, n);
    dp[0]=0;
    REP(i, 1, n){
        for (int j = 1; j <= min((LL)i, k); ++j) {
            chmin(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
        }
    }
    LL ans = dp[n-1];
    co(ans);
    return 0;
}

Measured memory_bytes: 2168
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  int a, b, h;
  cin >> a >> b >> h;

  cout << ((a + b) * h) / 2 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define ci cin
#define co cout
#define ed endl
#define vc vector
#define sr string
#define pb push_back
#define st(a,n) sort(a,a+n)
#define ms(a) memset(a,0,sizeof(a))
#define fr(i,k,n) for(int i=k;i<=n;++i)
#define FR(i,n,k) for(int i=n;i>=k;--i)
#define inf 0x3f3f3f3f
#define mod 10000019
#define maxn 1000
#define exp 1e-6
typedef long long ll;
using namespace std;
int main()
{
    int n;
    ci>>n;
    int a[110]={0};
    fr(i,1,n)
    ci>>a[i];
    int ans=inf;
    fr(i,-100,100)
    {
        int mx=0;
        fr(j,1,n)
        mx+=(a[j]-i)*(a[j]-i);
        ans=min(mx,ans);
    }
    co<<ans<<ed;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  char c;std::cin >> c;
  if('a'<=c&&c<='z') std::cout << "a" << '\n';
  else std::cout << "A" << '\n';
  return 0;
}


Measured memory_bytes: 3052
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {
	ll N,W;
	cin >> N >> W;
	vector<ll> w0;
	vector<ll> w1;
	vector<ll> w2;
	vector<ll> w3;
	ll wf,v0;
	cin >> wf>>v0;
	w0.push_back(v0);
	rep(i, N-1) {
		ll w, v;
		cin >> w>> v;
		if(w==wf)w0.push_back(v);
		else if (w == wf+1)w1.push_back(v);
		else if (w == wf+2)w2.push_back(v);
		else if (w == wf+3)w3.push_back(v);
	}
	ll an = 0;
	sort(w0.begin(), w0.end());
	sort(w1.begin(), w1.end());
	sort(w2.begin(), w2.end());
	sort(w3.begin(), w3.end());
	reverse(w0.begin(), w0.end());
	reverse(w1.begin(), w1.end());
	reverse(w2.begin(), w2.end());
	reverse(w3.begin(), w3.end());
	for(ll i0 = 0; i0 <= w0.size(); i0++) {
		for (ll i1 = 0; i1 <= w1.size(); i1++) {
			for (ll i2 = 0; i2 <= w2.size(); i2++) {
				for (ll i3 = 0; i3 <= w3.size(); i3++) {
					if (wf * i0 + (wf + 1) * i1 + (wf + 2) * i2 + (wf + 3) * i3 > W)continue;
					ll k = 0;
					rep(i, i0) {
						k += w0[i];
					}
					rep(i, i1) {
						k += w1[i];
					}
					rep(i, i2) {
						k += w2[i];
					}
					rep(i, i3) {
						k += w3[i];
					}
					an = max(an, k);
				}
			}
		}
	}
	cout << an << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define mp make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (1<<30)
#define LLINF (1LL<<60)
//#define MOD 998244353
#define MOD 1000000007
#define PI 3.14159265358979
using ll = long long;
using namespace std;

int main(){
    int n,sum[105]={};
    cin>>n;
    rep(i,n){
        int t;
        cin>>t;
        if(i==0)sum[i]=t;
        else sum[i]=sum[i-1]+t;
    }
    int ans=INF;
    rep(i,n){
        int left=sum[i];
        int right=sum[n-1]-sum[i];
        ans=min(ans,abs(left-right));
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct edge{
  int a,b,c;
  edge(int a,int b,int c) : a(a),b(b),c(c) {}
  edge(){}
  bool operator<(const edge &e ) const {
    return c < e.c;
  }
 
};
int N;
vector<edge> E[100005];
 
struct uni{
  int d[200005];
  void init(){ memset( d, -1, sizeof( d ) ); }
  int find( int a ) { return d[a]<0?a:(d[a]=find(d[a])); }
  bool merge(int a,int b){
    a = find(a); b = find(b);
    if( a == b ) return false;
    if( d[a]>d[b] ) swap( a, b );
    d[a] += d[b];
    d[b] = a;
  }
  int size(int a){ return -d[find(a)]; }
};
uni U;
int main(){
  U.init();
  cin >> N;
  for(int i=0;i<N-1;i++){
    int a,b,c;
    cin >> a >> b >> c;
    E[c].push_back( edge( a, b, c ) );
  }
  ll res = 0;
  for(int i=0;i<=100000;i++){
    for( edge e : E[i] ){
      res += (ll)U.size( e.a ) * (ll)U.size(e.b) * (ll)e.c;
      U.merge( e.a, e.b );
    }
  }
  cout << res << endl;
 
}

Measured memory_bytes: 10312
#include <iostream>
#include <string>
#include <numeric>

using namespace std;

int main() {
    string x;

    while (cin >> x) {
        if (x == "0") {
            break;
        }

        int32_t sum = accumulate(x.begin(), x.end(), 0, [](int32_t sum, int8_t c) {
            return sum + c - 48;
        });

        cout << sum << endl;
    }

    return 0;
}

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

int main(){
    int Lmax = 0;
    int Rmin = 10e5;
    
    int n,m;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int l,r;
        cin >> l>>r;
        if(l>Lmax)Lmax = l;
        if(r<Rmin)Rmin = r;
    }

    cout << std::max(Rmin-Lmax+1,0) << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>

using namespace std;

int main() {
    int h, w, n, s_r, s_c;
    string s, t;
    cin >> h >> w >> n;
    cin >> s_r >> s_c;
    cin >> s >> t;

    int n_su = 0, n_sd = 0, n_sl = 0, n_sr = 0;
    int n_tu = 0, n_td = 0, n_tl = 0, n_tr = 0;

    for (int i = 0; i < n; i++) {
        if (s[i] == 'U') n_su++;
        if (s[i] == 'D') n_sd++;
        if (s[i] == 'L') n_sl++;
        if (s[i] == 'R') n_sr++;

        if (s_r - n_su + n_td < 1 || s_r + n_sd - n_tu > h || s_c - n_sl + n_tr < 1 || s_c + n_sr - n_tl > w) {
            cout << "NO" << endl;
            return 0;
        }

        if (t[i] == 'U' && s_r - n_tu + n_sd > 1) n_tu++;
        if (t[i] == 'D' && s_r + n_td - n_su < h) n_td++;
        if (t[i] == 'L' && s_c - n_tl + n_sr > 1) n_tl++;
        if (t[i] == 'R' && s_c + n_tr - n_sl < w) n_tr++;
    }

    cout << "YES" << endl;
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)


void solve(long long N, long long K){
    ll ans = 0;
    while(N > 0){
        ans++;
        N /= K;
    }
    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    solve(N, K);
    return 0;
}


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

using namespace std;

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

typedef long long ll;

void solve(){
	int k;
	cin >> k;
	ll sum = 0;
	for(int a = 1; a <= k; ++a) {
		for(int b = 1; b <= k; ++b) {
			for(int c = 1; c <= k; ++c) {
				int f = __gcd(a, b);
				sum += __gcd(f, c);
			}
		}
	}
	
	cout << sum;
}

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

	solve();
    
    return 0;
}


Measured memory_bytes: 3604
/*input
1
2
4
8
9
15
*/
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-6;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll sub(ll a,ll b){
    ll x=a-b;
    while(x<0) x+=MOD;
    while(x>MOD) x-=MOD;
    return x;
}
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=(res*a)%MOD;
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
const ll maxn=1e2+5;
const ll maxlg=__lg(maxn)+2; 
int main(){
	int arr[5];
	REP(i,5) cin>>arr[i];
	int k;
	cin>>k;
	REP(i,5) REP(j,i){
		if(abs(arr[i]-arr[j])>k){
			cout<<":(";
			return 0;
		}
	}
	cout<<"Yay!";
}


Measured memory_bytes: 768
#include<bits/stdc++.h>   
#include<tr1/unordered_map>
#define ll long long int  
#define mkp make_pair 
#define mod 1000000007
using namespace std;   
  

int main(){    
  ios_base::sync_with_stdio(false); 
  cin.tie(NULL);   
  int n; 
  cin>>n; 
  if(n%1000==0)cout<<"0\n"; 
  else{  
    int q=n/1000;  
    cout<<((q+1)*1000)-n<<"\n"; 
   
   
    }
  return 0;
}    

Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MON 1000000007
#define INF (1<<29)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))

class Vec{
public:
  double x, y;
  Vec(double x = 0, double y = 0):x(x),y(y){}

  void read(){
    cin >> x >> y;
  }
  
  Vec operator+(const Vec &other)
  {
    Vec result = *this;
    result.x += other.x;
    result.y += other.y;
    return result;
  }

  Vec operator-(const Vec &other)
  {
    Vec result = *this;
    result.x -= other.x;
    result.y -= other.y;
    return result;
  }

  Vec operator*(const float &k)
  {
    Vec result = *this;
    result.x *= k;
    result.y *= k;
    return result;
  }

  Vec operator/(const float &k)
  {
    Vec result = *this;
    result.x /= k;
    result.y /= k;
    return result;
  } 
  
  double cross(const Vec &other)
  {
    return x*other.y - y*other.x;
  }

  double dot(const Vec &other){
    return x*other.x + y*other.y;
  }
  
  bool operator==(const Vec &other) const
  {
    return abs(x - other.x) < EPS && abs(y - other.y) < EPS;
  }

  float norm()
  {
    return sqrt(x*x+y*y);
  }

  float norm2()
  {
    return x*x+y*y;
  }

  Vec standard(){
    Vec result = *this;
    return result/result.norm();
  }
};

class Line{
public:
  Vec a, b;
  Vec vect;
  Line(Vec a = Vec(), Vec b = Vec()):a(a),b(b),vect(b-a){}

  //projection
  Vec proj(Vec p){
    p = p - a;
    return a + vect * vect.dot(p) / vect.norm2();
  }

  //reflection
  Vec reflect(Vec p){
    return proj(p) * 2 - p;
  }

  bool onSegment(Vec p){
    return abs((p-a).cross(b-a)) < EPS && (p-a).dot(p-b) < EPS;
  }
};


//ccw:1, cw:-1, other:0
Int CCW(Vec a, Vec b, Vec c){
  b = b - a;
  c = c - a;
  if(b.cross(c) > EPS)return -1;
  if(b.cross(c) < -EPS)return 1;
  return 0;
}

int main(){
  Vec p1, p2, p0;
  Int q;
  p0.read();
  p1.read();
  cin >> q;
  while(q--){
    p2.read();
    switch (CCW(p0, p1, p2)) {
    case 1: {
      cout << "CLOCKWISE" << endl;
      break;
    }
    case -1: {
      cout << "COUNTER_CLOCKWISE" << endl;
      break;
    }
    case 0:{
      if(Line(p0, p1).onSegment(p2))cout << "ON_SEGMENT" << endl;
      else if(Line(p0, p2).onSegment(p1))cout << "ONLINE_FRONT" << endl;
      else if(Line(p1, p2).onSegment(p0))cout << "ONLINE_BACK" << endl;
      else return -1;
    }
    }
  }
  return 0;
}


Measured memory_bytes: 3240
#!/usr/bin/env python3


def merge(n, s, t):
    res = ""
    for i in range(n):
        res += s[i] + t[i]
    return res


def main():
    n = int(input())
    s, t = input().split()
    r = merge(n, s, t)
    print(r)


if __name__ == "__main__":
    main()


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

int main(){
  int n;
  string s;
  cin>>n>>s;
  n=s.size();
  if(n%2==0){
    if(s.substr(0,n/2)==s.substr(n/2,n/2)){
      cout<<n/2<<endl;
      return 0;
    }
  }
  if(n<=26){
    string t=s;
    sort(t.begin(),t.end());
    int flag=0;
    for(int i=0;i<n-1;i++){
      if(t[i]==t[i+1]){
        flag++;
      }
    }
    if(flag==0){
      cout<<0<<endl;
      return 0;
    }
  }
  int ng=(n+1)/2;
  int ok=0;
  string t;
  int check,flag;
  while(!(ng-ok==1)){
    check=(ok+ng)/2;
    flag=0;
    for(int i=0;i<n-check;i++){
      t=s.substr(i,check);
      for(int j=i+check;j<n;j++){
        if(t[0]!=s[j]||t[1]!=s[j+1]){
          continue;
        }
        if(t==s.substr(j,check)){
          flag=1;
          break;
        }
      }
      if(flag==1){
        break;
      }
    }
    if(flag==0){
      ng=check;
    }
    else{
      ok=check;
    }
  }
  cout<<ok<<endl;
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define root sqrt
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli e, f, h, k, n, w, ans = 0, count = 0;
  string s, t;
  cin >> s;
  cout << (regex_match(s, regex("(dream|dreamer|erase|eraser)*")) ? "YES" : "NO") << endl;
}

Measured memory_bytes: 39888
import math


def slv(A, B):
    A, B = (A, B) if A > B else (B, A)

    # print(, A, B)
    s = A * B
    c = math.floor(math.sqrt(A * B))
    # print(A, B, c)

    if c * (c + 1) < s:
        return 2 * c - 1
    elif A == B:
        return 2 * c - 2
    elif c * c < s:
        return 2 * c - 2
    elif c * (c - 1) < s:
        return 2 * c - 3


# 1
# 12
# 4
# 11
# 14
# 57
# 31
# 671644785


def main():

    Q = int(input())
    for q in range(Q):
        A, B = map(int, input().split())
        print(slv(A, B))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define ll int
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define debug 0

 using namespace std;
 
 const ll MOD = 1000000007LL;
 
ll ar[500056],br[500056];


map<ll,ll> has,mark;
multiset<ll> st,buk;


vector<pair<ll,ll> > vp;
ll maxi;
vector<ll> vec,pec;



int main() 
{
	
//freopen("input.in","r",stdin);
//freopen("output.out","w",stdout);
    
    ll n,p,t,j,x,y=0,k,l,m,z,c,e,f,q,s,flag=0,sum=0,res=0,num,g,h,santax,santay,bagsize,len,yy,lg,kk,remov,a,b;
	ll i,u,v,w,ans=0,maxm=0,r,minm=999999999999,dist;
	bool fl=0;
	ll d,pos,neg;
	string str,ptr;

	
	cin>>n>>a>>b;
	
	for(i=1;i<=n;i++)
	{
		p=i;
		
		res=0;
		
		
		while(p)
		{
			d=p%10;
			res+=d;
			p/=10;
		}
        
        
		
		if(res>=a  && res<=b)
		sum+=i;
	}
	
  cout<<sum;
	
	
	
    return 0;
}    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=505,M=2e5+5,inf=1<<30;
int head[N],nxt[M],to[M],wei[M],tot=1,s,t,n,m,x[N],y[N],a[N],b[N],lx[N],rx[N],ly[N],ry[N];
ll cost[M],dis[N],v[N],res,ans; char op[N][2]; bool vis[N];
void adde(int u, int v, ll c=0, int w=1)
{
	nxt[++tot]=head[u],head[u]=tot,to[tot]=v,wei[tot]=w,cost[tot]=-c;
	nxt[++tot]=head[v],head[v]=tot,to[tot]=u,wei[tot]=0,cost[tot]=c;
}
bool spfa()
{
	memset(vis,0,sizeof(bool)*(t+3));
	memset(dis,0x3f,sizeof(ll)*(t+3));
	queue<int> q;
	dis[t]=0,q.push(t);
	while(!q.empty())
	{
		int u=q.front();
		vis[u]=false,q.pop();
		for(int e=head[u];e;e=nxt[e])
			if(wei[e^1]&&dis[to[e]]>dis[u]-cost[e])
			{
				dis[to[e]]=dis[u]-cost[e];
				if(!vis[to[e]]) vis[to[e]]=true,q.push(to[e]);
			}
	}
	return dis[s]!=dis[0];
}
int dfs(int u, int mx)
{
	vis[u]=true;
	if(u==t) return mx;
	int l=mx;
	for(int e=head[u];e&&l;e=nxt[e])
		if(!vis[to[e]]&&wei[e]>0&&dis[to[e]]==dis[u]-cost[e])
		{
			int f=dfs(to[e],min(l,wei[e]));
			res+=1ll*f*cost[e];
			l-=f,wei[e]-=f,wei[e^1]+=f;
		}
	return mx-l;
}
ll exec()
{
	res=0;
	while(spfa())
		do
		{
			memset(vis,0,sizeof(bool)*(t+3));
			dfs(s,inf);
		} while(vis[t]);
	return -res;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d%d%lld",&x[i],&y[i],&v[i]);
	scanf("%d",&m);
	for(int i=1;i<=m;++i) scanf("%s%d%d",op[i],&a[i],&b[i]);
	for(int k=1;k<=n;++k)
	{
		memset(head,0,sizeof(head)),tot=1;
		s=(n+k)*2+1,t=s+1;
		for(int i=1;i<=k;++i) adde(s,i),adde(i+k+2*n,t),lx[i]=ly[i]=0,rx[i]=ry[i]=inf;
		for(int i=1;i<=n;++i) adde(i+k,i+n+k,v[i]);
		for(int i=1;i<=m;++i)
		{
			if(op[i][0]=='L')
				for(int j=b[i]+1;j<=k;++j) lx[j]=max(lx[j],a[i]+1);
			if(op[i][0]=='R')
				for(int j=1;j<=k-b[i];++j) rx[j]=min(rx[j],a[i]-1);
			if(op[i][0]=='D')
				for(int j=b[i]+1;j<=k;++j) ly[j]=max(ly[j],a[i]+1);
			if(op[i][0]=='U')
				for(int j=1;j<=k-b[i];++j) ry[j]=min(ry[j],a[i]-1);
		}
		for(int i=1;i<=k;++i)
			for(int j=1;j<=n;++j)
			{
				if(lx[i]<=x[j]&&x[j]<=rx[i]) adde(i,j+k);
				if(ly[i]<=y[j]&&y[j]<=ry[i]) adde(j+k+n,i+k+2*n);
			}
		ans=max(ans,exec());
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 640
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    h, w = ns()
    mat = [na() for _ in range(h)]

    n = 0
    ans = []
    for y in range(h):
        for x in range(w - 1):
            if mat[y][x] % 2:
                mat[y][x] -= 1
                mat[y][x + 1] += 1
                ans.append((y + 1, x + 1, y + 1, x + 1 + 1))
                n += 1

    for y in range(h - 1):
        if mat[y][w - 1] % 2:
            mat[y][w - 1] -= 1
            mat[y + 1][w - 1] += 1
            ans.append((y + 1, w, y + 1 + 1, w))
            n += 1

    print(n)
    for item in ans:
        print(*item, sep=" ")


if __name__ == '__main__':
    main()


Measured memory_bytes: 28736
#include<iostream>
#include<algorithm>
#include<string>
#include<stack>
#include<queue>
using namespace std;

int w, h;
int map[50][50];
int ans;

void Suibotu(int y, int x)
{//??¨??????????????????????±?????????¶????????°???????°´????????????
	map[y][x] = 0;
	if(x<w-1 && map[y][x+1]==1)				//???
		Suibotu(y, x+1);
	if(x<w-1 && y<h-1 && map[y+1][x+1]==1)	//??????
		Suibotu(y+1, x+1);
	if(y<h-1 && map[y+1][x]==1)				//???
		Suibotu(y+1, x);
	if(x>0 && y<h-1 && map[y+1][x-1]==1)	//??????
		Suibotu(y+1, x-1);
	if(x>0 && map[y][x-1]==1)				//???
		Suibotu(y, x-1);
	if(x>0 && y>0 && map[y-1][x-1]==1)		//??????
		Suibotu(y-1, x-1);
	if(y>0 && map[y-1][x]==1)				//???
		Suibotu(y-1, x);
	if(x<w-1 && y>0 && map[y-1][x+1]==1)	//??????
		Suibotu(y-1, x+1);
}
int main(){
	cin >> w >> h;
	while(w+h>0){
		ans = 0;
		for(int i=0; i<h; i++)
			for(int j=0; j<w; j++)
				cin >> map[i][j];
			for(int i=0; i<h; i++)
			for(int j=0; j<w; j++)
				if(map[i][j]==1){
					ans++;
					Suibotu(i, j);
				}
		cout << ans << endl;
		cin >> w >> h;
	}
	return 0;
}

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

int main() {
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<ll> a(x), b(y), c(z);
  for (int i = 0; i < x; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < y; i++) {
    cin >> b.at(i);
  }
  for (int i = 0; i < z; i++) {
    cin >> c.at(i);
  }

  vector<ll> ab(x * y);
  for (int i = 0; i < x; i++) {
    for (int j = 0; j < y; j++) {
      ab.push_back(a.at(i) + b.at(j));
    }
  }
  sort(ab.begin(), ab.end(), greater<ll>());
  ab.resize(k);

  vector<ll> abc(ab.size() * z);
  for (int i = 0; i < ab.size(); i++) {
    for (int j = 0; j < z; j++) {
      abc.push_back(ab.at(i) + c.at(j));
    }
  }
  sort(abc.begin(), abc.end(), greater<ll>());
  abc.resize(k);

  for (ll ans : abc) {
    cout << ans << endl;
  }
}


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

int a,b,c,d,e,f,g,h,i,j,k,l;
int sum=0;
int n,m,x;
int C[20];
int A[20][20];
int Count[20];
int ans=-1;
bool over()
{
if(a==1){sum+=C[0];{for(int I=0;I<m;I++)Count[I]+=A[0][I];}}
if(b==1){sum+=C[1];{for(int I=0;I<m;I++)Count[I]+=A[1][I];}}
if(c==1){sum+=C[2];{for(int I=0;I<m;I++)Count[I]+=A[2][I];}}
if(d==1){sum+=C[3];{for(int I=0;I<m;I++)Count[I]+=A[3][I];}}
if(e==1){sum+=C[4];{for(int I=0;I<m;I++)Count[I]+=A[4][I];}}
if(f==1){sum+=C[5];{for(int I=0;I<m;I++)Count[I]+=A[5][I];}}
if(g==1){sum+=C[6];{for(int I=0;I<m;I++)Count[I]+=A[6][I];}}
if(h==1){sum+=C[7];{for(int I=0;I<m;I++)Count[I]+=A[7][I];}}
if(i==1){sum+=C[8];{for(int I=0;I<m;I++)Count[I]+=A[8][I];}}
if(j==1){sum+=C[9];{for(int I=0;I<m;I++)Count[I]+=A[9][I];}}
if(k==1){sum+=C[10];{for(int I=0;I<m;I++)Count[I]+=A[10][I];}}
if(l==1){sum+=C[11];{for(int I=0;I<m;I++)Count[I]+=A[11][I];}}

for(int I=0;I<m;I++)
{if(Count[I]<x)return false;
}

return true;
}
int main()
{


cin>>n>>m>>x;
for (int I=0;I<20;I++)
    {
    C[I]=0;
    for(int J=0;J<20;J++)
    A[I][J]=0;
    }

for (int I=0;I<n;I++)
{
    cin>>C[I];
    for(int J=0;J<m;J++)
    cin>>A[I][J];
}



for(a=0;a<=1;a++)
    {for(b=0;b<=1;b++)
        {for(c=0;c<=1;c++)
            {for(d=0;d<=1;d++)
                {for(e=0;e<=1;e++)
                    {for(f=0;f<=1;f++)
                        {for(g=0;g<=1;g++)
                            {for(h=0;h<=1;h++)
                                {for(i=0;i<=1;i++)
                                    {for(j=0;j<=1;j++)
                                        {for(k=0;k<=1;k++)
                                            {for(l=0;l<=1;l++)
                                            {
                                                sum=0;
                                                for(int J=0;J<m;J++)Count[J]=0;
                                                if(over())
                                                {
                                                if(ans==-1)ans=sum;
                                                else {if(ans>sum)ans=sum;

                                                }
                                                }
                                            }
                                            }
                                        }
                                    }
                                }       
                            }
                        }
                    }
                }
            }
        }
    }
cout <<ans;
}                                                                                                                                                     


Measured memory_bytes: 3628
#include <stdio.h>

int main() {
	int n, a, b;
	int i, sum, num, cnt = 0, ans = 0;

	scanf("%d %d %d", &n, &a, &b);

	for (i = 1; i <= n; i++) {
		sum = 0;
		num = i;

		sum += num / 10000;
		num %= 10000;
		sum += num / 1000;
		num %= 1000;
		sum += num / 100;
		num %= 100;
		sum += num / 10;
		num %= 10;
		sum += num;

		if (a <= sum && sum <= b)
			ans += i;
	}

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

	return 0;
}

Measured memory_bytes: 128
n = int(input())
c0 = 0
c1 = 0
c2 = 0
c3 = 0
for i in range(n):
    s = input()
    if s == "AC":
        c0 += 1
    elif s == "WA":
        c1 += 1
    elif s == "TLE":
        c2 += 1
    elif s == "RE":
        c3 += 1
    else:
        exit()

print(f"AC x {c0}")
print(f"WA x {c1}")
print(f"TLE x {c2}")
print(f"RE x {c3}")


Measured memory_bytes: 9048
#include <stdio.h>

int main(){
	long long h, w;
	scanf("%lld%lld",&h,&w);
	if((h==1)||(w==1)) printf("1\n");
	else if(h%2==0) printf("%lld\n",h*w/2);
	else if(w%2==0) printf("%lld\n",h*w/2);
	else printf("%lld\n",((h/2+1)+(h/2))*(w-1)/2+h/2+1);
}

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

int main(void){
    int n,m,t;
    cin>>n>>m>>t;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    int sum = a[0]-m + max(t-a[n-1]-m,0);
    rep(i,n-1){
        sum += max(a[i+1]-a[i]-m*2, 0);
    }
    cout<<sum<<endl;
    return 0;
}



Measured memory_bytes: 3092
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
//#include<unordered_map>//イテレータあるけど順序保持しないmap
//#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<valarray>//なんとなく追加
//メモ：表示桁数を大きくする　　cout << fixed << setprecision(20) << cm << endl;
using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PI acos(-1.0)
#define answer(ans) cout<<ans<<endl;
#define input(N) cin >> N ;

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

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

signed main() {
ll A,B,ans;
cin >> A>>B;
ans=lcm(A,B);
answer(ans);
return 0;
}


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


using namespace std;
using ll = long long;


int main() {
    ll n;
    cin >> n;
    vector<ll> A(n), arr;
    map<ll, ll> mp;
    for(auto& x : A) {
        cin >> x;
        mp[x]++;
    }
    for(auto x : mp) arr.push_back(x.first);
    n = arr.size();
    ll res = 0;
    for(ll i = 0; i < n - 2; i++) {
        for(ll j = i + 1; j < n - 1; j++) {
            for(ll k = j + 1; k < n; k++) {
                ll a = arr[i], b = arr[j], c = arr[k];
                bool ok = (a + b > c) && (b + c > a) && (c + a) > b;
                if(ok) {
                    res += mp[a] * mp[b] * mp[c];
                }
            }
        }
    }
    cout << res << "\n";
    return 0;
}



Measured memory_bytes: 3608