akhauriyash/Code-Regression huggingface dataset:
//保留所有权利。
#include<iostream>
#include<stdio.h>//printするよ
#include<vector>
#include<algorithm>//辞書順はnext_permutationだよ
#include<set>
#include<string>
#include<sstream>
#include<string.h>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swapで数値交換するよ
//END OF LIBRARIES.
#define rt "\n"//改行を最速化させるよ
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define vcin(v) for (int i = 0; i < (v).size(); i++) { cin >> (v)[i]; }
#define sort(s) sort(s.begin(),s.end())
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define cncn int cnt=0
#define smsm int sum=0
#define str srting
#define v vector
#define please return
#define AC 0//おまじないだよ
#define Rapid cin.tie(0);ios::sync_with_stdio(false)
//END OF DEFINE.
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vcha;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
//printf("%02d:%02d:%02d\n", h, m, s);・・・2文字は埋める・h、m、ｓ
//END OF TYPEDEF.

//最大公約数（GCD）を求めるよ
//最小公倍数（LCM）は＜＜　A × B ÷ GCD　 ＞＞で求まるよ

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

//for A以上B未満でI探索 for (int I = A; i <= B; i++)

//string s = to_string(i);

//char→小文字のほうが大きい数値　　&&　その差は32

//大文字→小文字 文字列のn文字目を大文字で出力→ (char)toupper(a[0])

int a = 0, b = 0, c = 0, x = 0, y = 0, z = 0, n = 0, sum = 0, i = 0;
string s = ""; asas; cncn;

int main(void) {
	cin >> x >> y;
	if (x == 1)x = 100;
	if (x == 2)x = 300;
	if (x == 3)x = 100;
	if (x == 4)x = 200;
	if (x == 5)x = 100;
	if (x == 6)x = 200;
	if (x == 7)x = 100;
	if (x == 8)x = 100;
	if (x == 9)x = 200;
	if (x == 10)x = 100;
	if (x == 11)x = 200;
	if (x == 12)x = 100;
	if (y == 1)y = 100;
	if (y == 2)y = 300;
	if (y == 3)y = 100;
	if (y == 4)y = 200;
	if (y == 5)y = 100;
	if (y == 6)y = 200;
	if (y == 7)y = 100;
	if (y == 8)y = 100;
	if (y== 9)y = 200;
	if (y == 10)y = 100;
	if (y == 11)y = 200;
	if (y == 12)y = 100;
	Yes(x == y);
	please AC;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

int main () {
    int n, k;
    std::cin >> n >> k;
    std::vector<int> a(n);
    std::vector<long double> ex(n);
    for (int i = 0; i < n; i++)
    {
        std::cin >> a[i];

    }


    for (int i = 0; i < n; i++) {
        ex[i] = (a[i] + 1) / 2.0;
    }

    double ans = 0;
    for (int i = 0; i < k; i++) {
        ans += ex[i];
    }

    std::vector<double> anss;
    anss.push_back(ans);
    double cmp = ans;
    for (int i = k; i < n; i++)
    {
        
        cmp -= ex[i - k];
        cmp += ex[i];
      
        anss.push_back(cmp);
    }

    std::cout <<std::fixed << std::setprecision(12) <<*std::max_element(anss.begin(), anss.end()) << std::endl;

}

Measured memory_bytes: 6388
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

S = input()
T = list(set(S))

if (len(T)== 2) and (S.count(T[0])==2) and (S.count(T[1])==2):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 39408
<?php
$input = trim(fgets(STDIN));
list($a, $b) = explode(" ", $input);
$a = (int)$a;
$b = (int)$b;

if ($a < $b) {
    echo "a < b";
} else if ($a > $b) {
    echo "a > b";
} else {
    echo "a == b";
}
echo "\n";
?>


Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int n, a;
  cin >> n;
  a = (n / 1000 + 1) * 1000 - n;
  if(a == 1000){
    cout << 0;
  }
  else{
    cout << a;
  }
  
  return 0;
}




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

using namespace std;

const int MAX_N = 100000;
const int MAX_LOG_N = 17;

int m[MAX_LOG_N][MAX_N];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> x(n);
	for (int i = 0; i < n; i++) cin >> x[i];
	int L, q;
	cin >> L >> q;
	for (int i = 0; i < n; i++) {
		int nex = upper_bound(x.begin() + i, x.end(), x[i] + L) - x.begin();
		nex--;
		m[0][i] = nex;
	}

	for (int i = 0; i + 1 < MAX_LOG_N; i++) {
		for (int j = 0; j < n; j++) {
			if (m[i][j] == n) m[i + 1][j] = n;
			else m[i + 1][j] = m[i][m[i][j]];
		}
	}

	for (int i = 0; i < q; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		if (a > b) swap(a, b);
		int ng = 0, ok = n - 1;
		while (ok - ng > 1) {
			int mid = (ok + ng) / 2;
			int cur = a;
			for (int i = 0; i < MAX_LOG_N; i++) {
				if (mid & (1 << i)) cur = m[i][cur]; 
			}
			if (cur >= b) ok = mid;
			else ng = mid;
		}
		cout << ok << endl;
	}
	return 0;
}

Measured memory_bytes: 7936
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <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 <list>          // list
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

vector<int> w(100000);
int n, k;

int64_t check(int64_t center)
{
    int64_t i = 0;
    rep(j, k)
    {
        int64_t contain = 0;
        while (contain + w.at(i) <= center)
        {
            contain += w.at(i);
            i++;
            if (i == n)
                return n;
        }
    }
    return i;
}

int main()
{
    cin >> n >> k;
    rep(i, n) cin >> w.at(i);

    int64_t right = 1000000001;
    int64_t left = 0;
    while (right - left > 1)
    {
        int64_t center = (left + right) / 2;
        int64_t v = check(center);
        if (v >= n)
            right = center;
        else
            left = center;
    }
    cout << right << endl;
}


Measured memory_bytes: 3112
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        string[] P = Console.ReadLine().Split(' ');
        string[] Q = Console.ReadLine().Split(' ');
        int pNum = 0;
        int qNum = 0;
        for(int i = 0; i < N - 1; i++)
        {
            int p = int.Parse(P[i]);
            int q = int.Parse(Q[i]);

            pNum += kaijo(N - i - 1) * (p - 1);
            qNum += kaijo(N - i - 1) * (q - 1);


            for (int j = i + 1; j < N; j++)
            {
                int ppp = int.Parse(P[j]);
                int qqq = int.Parse(Q[j]);
                if (p < ppp)
                {
                    P[j] = (ppp - 1).ToString();
                }
                if (q < qqq)
                {
                    Q[j] = (qqq - 1).ToString();
                }
            }
        }

        Console.WriteLine(Math.Abs(pNum - qNum));
    }

    static int kaijo(int a)
    {
        int ret = 1;
        while (a >= 1)
        {
            ret *= a;
            a--;
        }
        return ret;
    }
}

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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define rep(idx, N) for (i64 idx = 1; idx <= N; idx++)

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

  u32 m = (u32)sqrt(N) + 2;

  u32 ans = 0;
  for (i64 n = 1; n < N + 1; n++) {
    ans = 0;
    rep(x, m) {
      rep(y, m) {
        i64 k = (n - x * x - y * y - x * y);
        if (y * y * x * x + 4 * k < 0)
          continue;
        i64 z = ((-(y + x) + sqrt((y+x) * (y + x) + 4 * k)))/2;
        if (z <= 0)
          continue;
        if (x * x + y * y + z * z + x * y + y * z + z * x == n)
        {
            // cout << x << "\t" << y <<  "\t" << z << endl;
          ans++;
        }
      }
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3600
#include <stdio.h>

int main()
{
	int i, N, A, min = 1001, max = -1;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%d", &A);
		if (A < min) min = A;
		if (A > max) max = A;
	}
	printf("%d\n", max - min);
	fflush(stdout);
	return 0;
}

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    char a;
    cin >> a;
    char ans = a + 1;
    print(ans);

    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>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using Graph = vector<vector<bool>>;
const int MOD = 1e9 + 7;

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

    int H, W, K;
    cin >> H >> W >> K;
    K--;

    static int div[9];
    div[2] = 1;
    for (int i = 3; i <= 8; ++i)
        div[i] = div[i - 1] + div[i - 2];
    for (int i = 1; i <= 8; ++i)
        div[i] += div[i - 1];

    vector<vector<ll>> dp(H + 2, vector<ll>(W + 2));
    dp[0][0] = 1;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            ll tmp = 0;
            if (j - 1 >= 0)
                tmp += dp[i][j - 1] * (div[j - 1] + 1) * (div[W - j - 1] + 1);
            if (j + 1 < W)
                tmp += dp[i][j + 1] * (div[j] + 1) * (div[W - j - 2] + 1);
            tmp += dp[i][j] * (div[j] + 1) * (div[W - j - 1] + 1);
            (dp[i + 1][j] += tmp) %= MOD;
        }
    }

    cout << dp[H][K] << endl;
    return 0;
}


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


int a[2003];

int main() {
	long long n, k;
	cin>> n >> k;
	int i, j;
	for(i=1;i<=n;i++) cin>>a[i];
	
	long long ans = 0, MOD = 1e9 + 7;
	
	for(i=1;i<=n;i++) {
	    
	    int low = 0, high=0;
	    for(j=1;j<=n;j++){
	        if(a[i]>a[j]) {
	            if(i>j)
	                high++;
	            else 
	                low++;
	        }
	    }
	    long long lc = ((((k+1)*k)/2)%MOD)*low;
	    long long hc = ((((k)*(k-1))/2)%MOD)*high;
	    //cout<<lc<<", "<<hc<<"\n";
	    ans+=lc%MOD + hc%MOD;
	    ans%=MOD;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
cd = [list(map(int, input().split())) for _ in range(M)]
for i in range(N):
    ans = -1
    dist = 10**12
    for j in range(M):
        tmp = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1]) 
        if tmp < dist:
            ans = j
            dist = tmp
    print(ans+1)

Measured memory_bytes: 9196
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <vector>

using namespace std;

#define TRACE(x) cerr << #x << " = " << x << endl
#define _ << " " <<
#define X first
#define Y second
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)

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

const int MAX = 52;

int n;
ll p[MAX];

int check(ll x) {
  if (x < 0) return 0;
  ll kol = 0;
  
  REP(i, n) {
    ll tmp = p[i] + x - n + 1;
    //    if (!x) TRACE(tmp);
    
    if (tmp > 0)
      kol += (tmp - 1) / (n+1) + 1;
  }
  return kol <= x;
}

int main()
{
  scanf("%d", &n);
  REP(i, n)
    scanf("%lld", &p[i]);

  ll lo=0;
  REP(i, n) lo += p[i];

  for (ll i=lo-2*n*n; ; i++) {
    if (check(i)) {
      printf("%lld\n", i);
      return 0;
    }
  }

  assert(0);
}


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

int main (){
	char a[100];
	char b[100];
	char c[100];
	scanf("%s %s %s", a, b, c);
	
	int A = strlen(a);
	int B = strlen (b);
	
	for (int i = 0; i < 10; i++){
		if ( a[A - 1] == b[0] && b[B - 1]== c[0]){
			puts ("YES");
			break;
		}
		else{
			puts ("NO");
			break;
		}
	}
	
	return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

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


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

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


int main() {
    i64 N; cin >> N;
    vector<i64> A(N);
    REP(i, N) cin >> A[i];
    sort(A.rbegin(), A.rend());

    if (N == 2) {
        i64 ans = A[0];
        cout << ans << endl;
        return 0;
    }

    i64 maxv = A[0];
    i64 j = 0;
    for (i64 i = 2; i < N; i++) {
        if (i % 2 == 0) j++;
        maxv += A[j];
    }
    cout << maxv << endl;

    return 0;
}


Measured memory_bytes: 4744
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

vector<ll> solve(ll n, ll a, ll b) {
  if (n == 1) {
    vector<ll> res;
    res.push_back(a);
    res.push_back(b);
    return res;
  }
  ll x = a^b;
  ll d = 0;
  REP(i,n) {
    if ((x >> i) & 1) d = i;
  }
  vector<ll> va, vb;
  REP(i,n) {
    if (i != d) {
      va.push_back((a >> i) & 1);
      vb.push_back((b >> i) & 1);
    }
  }
  ll ra = 0, rb = 0;
  REP(i,n-1) {
    ra |= va[i] << i;
    rb |= vb[i] << i;
  }
  auto r1 = solve(n-1, ra, ra^1);
  auto r2 = solve(n-1, ra^1, rb);
  vector<ll> res;
  for(ll r : r1) {
    vector<ll> v;
    REP(i,n-1) {
      v.push_back((r >> i) & 1);
    }
    ll s = 0;
    REP(i,d) {
      s |= v[i] << i;
    }
    s |= a & (1 << d);
    FOR(i,d,n-1) {
      s |= v[i] << (i+1);
    }
    res.push_back(s);
  }
  for(ll r : r2) {
    vector<ll> v;
    REP(i,n-1) {
      v.push_back((r >> i) & 1);
    }
    ll s = 0;
    REP(i,d) {
      s |= v[i] << i;
    }
    s |= b & (1 << d);
    FOR(i,d,n-1) {
      s |= v[i] << (i+1);
    }
    res.push_back(s);
  }
  return res;
}

int main()
{
  ll n,a,b;
  cin>>n>>a>>b;
  ll x = a^b;
  if (__builtin_popcount(x) % 2 != 1) {
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
  vector<ll> res = solve(n, a, b);
  REP(i,1<<n) {
    if(i)cout<<' ';
    cout<<res[i];
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 2384
import math
N, D = map(int, input().split())
X = []
for i in range(N):
    x = list(map(int, input().split()))
    X.append(x)

ans = 0
for i in range(N):
    for j in range(i+1,N):
        sum = 0
        for k in range(D):
            sum = sum + (X[i][k]-X[j][k])*(X[i][k]-X[j][k])
        dist = math.sqrt(sum)
        if dist.is_integer():
            ans=ans+1
print(ans)

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

using namespace std;

#define pb push_back
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) FOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

const double eps = 1e-10;
const int MOD = 1000000007;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, s.size()) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int x, y; cin >> x >> y;
  
  int ans = abs(abs(x)-abs(y));
  if(x == y) {
    cout << 0 << endl;
  } else if(x == 0) {
    cout << ans + (int)(y < 0) << endl;
  } else if(y == 0) {
    cout << ans + (int)(x > 0) << endl;
  } else if((x >= 0) == (y >= 0)) {
    cout << ans + (int)(y < x) * 2 << endl;
  } else {
    cout << ans + 1 << endl;
  }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll   long long int
#define T int t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define PI 3.141592653589793238462643383

int main(){
   
    fast;
    
    ll n;
    ll mod = 1000000007;
	cin >> n;
	ll arr[n];
	for(int i=0;i<n;i++){
	 cin >> arr[i];
	}
	ll ans = 0;
	ll sum = 0;
	for(int i=0;i<n;i++){
		sum = (sum + arr[i]);
	}
	for(int i=0;i<n;i++){
		sum = sum - arr[i];
		ans = (ans + ((sum%mod)*(arr[i]%mod))%mod)%mod;
	}
	cout << ans << endl;










}

Measured memory_bytes: 5168
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)


# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))

def divisor_list(n):
    ret = set()
    i = 1
    while i * i <= n:
        if n % i == 0:
            ret.add(i)
            ret.add(n // i)
        i += 1
    return ret


N = int(input())
A = [int(x) for x in input().split()]
A = [0] + A

R = []

for i in range(N, 0, -1):
    if A[i] == 1:
        R.append(i)
        dl = divisor_list(i)
        for j in dl:
            A[j] = (A[j] + 1) % 2

print(len(R))
print(" ".join([str(i) for i in R]))

# print(R)


Measured memory_bytes: 77796
#include <stdio.h>

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

    int sum = 0;
    if(n == 100000){
        printf("90909");
        return 0;
    } 

    if(n > 9999){
        for (;n > 9999;n--){
            sum++;
        }
    }

    if (n > 999){
        n = 999;
    }

    if(n > 99) {
        for (;n > 99;n--){
            sum++;
        }
    }

    if (n > 9){
        n = 9;
    }

    if(n > 0){
        for(;n > 0;n--){
            sum++;
        }
    }

    printf("%d",sum);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <sstream>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for(ll i = a; i <= b; ++i)
#define fo(i,a,b) for(int i = a; i<= b; ++i)
#define ull unsigned long long int
#define ll long long
#define all(a) a.begin(),a.end()
using namespace std;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
ll MD=1000000007;
ll md=998244353;
ll exp(ll a,ll b){ll r=1ll;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b/=2;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}//put b as bmod(md-1) if md is prime}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll pow_2(ll a, ll b)
{
    ll res = 1;
    while(b)
    {
        if(b & 1)
            res = (res * a);
        a = (a * a);
        b >>= 1;
    }

    return res;
}
bool isPrime(ll a)
{
    for(ll i=3; (i*i)<=a; i+=2)
    {
        if( (a%i)==0 )
            return false;
    }
    if( ( a!=2 ) && ( (a%2)==0 ) )
        return false;
    if( a==1 )
        return false;

    return true;
}
string decToBinary(int n)
{
    // Size of an integer is assumed to be 32 bits
    string s="";
    for (int i = 31; i >= 0; i--) {
        int k = n >> i;
        if (k & 1)
            //cout << "1";
            s=s+"1";
        else
            //cout << "0";
            s=s+"0";
    }
    return s;
}
int decimalToBinary(int N)
{

    // To store the binary number
    ull B_Number = 0;
    int cnt = 0;
    while (N != 0) {
        int rem = N % 2;
        ull c = pow(10, cnt);
        B_Number += rem * c;
        N /= 2;

        // Count used to store exponent value
        cnt++;
    }

    return B_Number;
}
string toString(ull num)
{
    std::string number;
    std::stringstream strstream;
    strstream << num;
    strstream >> number;
    return number;
}
const double PI = acos(-1);
struct Test
{
   double x, y, z;
};
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
    int n;
    cin>>n;
    ll w;
    cin>>w;
    vector<pair<ll,ll> > arr;
    ll W,v;
    fo(i,0,n-1){cin>>W>>v;arr.PB(MP(W,v));}
    sort(all(arr));
    ll dp[n+1][w+1];
    for(int i=0;i<=w;i++)dp[0][i]=0;
    for(int i=0;i<=n;i++)dp[i][0]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=w;j++)
        {   if(j-arr[i-1].first>=0)dp[i][j]=max(dp[i-1][j],dp[i-1][j-arr[i-1].first]+arr[i-1].second);
            else dp[i][j]=dp[i-1][j];
        }
    }
    cout<<dp[n][w]<<endl;
return 0;}




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

using namespace std;

#define ll long long
ll input(){
	ll x=0,f=0;char ch=getchar();
	while(ch<'0'||ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return f? -x:x;
}

const int N=3007;
const ll mod=1e9+7;

ll dp[N],pre[N],suf[N];

int main(){
	int n=input();
	dp[1]=suf[1]=pre[1]=1;
	for(int i=2;i<=n;i++){
		char ch=getchar();
		if(ch=='<') for(int j=1;j<=i;j++) dp[j]=pre[j-1];
		else for(int j=1;j<=i;j++) dp[j]=suf[j];
		for(int j=1;j<=i;j++) pre[j]=(pre[j-1]+dp[j])%mod;
		for(int j=i;j>=1;j--) suf[j]=(suf[j+1]+dp[j])%mod;
	}
	printf("%lld\n",pre[n]);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ioS            ios::sync_with_stdio(false);cin.tie(0);
#define li             long int
#define lli            long li
#define ull            unsigned lli
#define pi             pair<int,int>
#define vi             vector<int>
#define vli            vector<li>
#define vlli           vector<lli>
#define vvi            vector<vector<int>>
#define pb             push_back
#define mp             make_pair
#define forn(i,s,n)    for(auto i=s;i<n;i++)               
#define forr(i,s,n)    for(auto i=s;i>=n;i--) 
const lli MOD = 1e9+7;
const lli mx = 1e7; 

void solve()
{
    int n,x;
    cin>>n;
    vi f(1e5+1,0);
    li sum=0;
    forn(i,0,n)
    {
        cin>>x;
        f[x]++;
        sum+=x;
    }
    int q;
    cin>>q;
    li b,c;
    forn(i,0,q)
    {
        cin>>b>>c;
        sum +=f[b]*(c-b);    
        f[c]+=f[b]; 
        f[b]=0;
        cout<<sum<<endl;
    }
}


int32_t main()
{
    ioS
    // int t;
    // cin>>t;
    // while(t--)
        solve();
}

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

#define _GLIBCXX_DEBAC
typedef long long ll;
using namespace std;


int main() {
	int a, b;
	cin >> a >> b;
	cout << 6 - a - b;
		return 0;
}









Measured memory_bytes: 256
open Printf open Scanf
open Array

let () = scanf " %d %d %d %d" @@ fun n a b c ->
  let l = init n (fun _ -> scanf " %d" @@ fun v -> v) in
  sort compare l;
  let res = ref max_int in
  let rec solve k l sum =
    for i=0 to k-1 do
      for j=i+1 to k-1 do
        for p=j+1 to k-1 do
          let ca,cb,cc = l.(p),l.(j),l.(i) in
          let v = sum + abs (ca - a) + abs (cb - b) + abs (cc - c)
          in
          (* printf "    %2d,%2d,%2d v. %2d,%2d,%2d :: %d"
            a b c
            ca cb cc v; *)
          res := min !res v
        done
      done
    done;
    (* printf "%d(%d): [" k sum;
    iter (printf "%3d ") l;
    printf "] :: %d" !res; print_newline (); *)
    if k>3 then (
      for i=0 to k-1 do
        for j=i+1 to k-1 do
          let r = ref [] in
          for p=0 to k-1 do
            if p=i then r := (l.(i) + l.(j)) :: !r
            else if p=j then ()
            else r := l.(p) :: !r
          done;
          r := List.sort compare !r;
          solve (k-1) (of_list !r) (sum+10)
        done
      done
    )
  in solve n l 0;
  printf "%d" @@ !res

Measured memory_bytes: 4608
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a[] = new int[2];
    a[0] = sc.nextInt();
    a[1] = sc.nextInt();
    for(int i = 1;i<=3;i++){
      int count = 0;
      for(int j = 0;j<2;j++){
        if(i != a[j]){
          count++;
        }
      }
      if(count == 2){
        System.out.println(i);
      }
    }

  }
}


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

int f[2000000];

int main()
{
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;++i){
        cin>>a[i];
        f[a[i]]++;
    }
    if(n==1){
        cout<<1<<endl;
        return 0;
    }
    int ans=0;
    for(int i=0;i<n;++i){
        if(f[a[i]]>=2)continue;
        bool b=1;
        for(int k=1;k*k<=a[i];++k){
            if(a[i]%k==0){
                if(f[k] && k!=a[i])b=0;
                if(f[a[i]/k] && a[i]/k!=a[i])b=0;
            }
        }
        if(b)ans++;
    }
    cout<<ans<<endl;
}

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

#define BeatMeScanf    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define tc(x)          int x; cin >> x; while(x--)
#define ll             long long
#define vi             vector<int>
#define pii            pair<int,int>
#define mii            map<int,int>
#define inf            1<<28
#define mem(x,y)       memset(x, y, sizeof(x))
#define ps(x,y)        fixed<<setprecision(y)<<x
#define show(val)      cout<< #val << " -> " << val << endl
#define Case           cout<< "Case "<< ++cs << ": "
#define all(v)         (v).begin(), (v).end()
#define rall(v)        (v).rbegin(), (v).rend()
#define MOD            1000000007
#define MAX            100005

int main()
{
	BeatMeScanf;
	double r;
	cin >> r;
	double ans = 2.00*3.14159265358979323*r;
	cout<< ps(ans, 20) <<'\n';
	return 0;
}


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

typedef long long   ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    if(s=="BBB"||s=="AAA") cout << "No" << "\n";
    else cout << "Yes" << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;



int main(){
    int N;
    cin >> N;
    int A, B, C;
    cin >> A >> B >> C;
    int l[8];
    int ans = INT32_MAX;
    for(int i = 0; i < N; i++){
        cin >> l[i];
    }
    for(int i = 0; i < (2 << 2*N); i++){
        int a = 0, b = 0, c = 0;
        int cnta = 0, cntb = 0, cntc = 0;
        //cout << i << endl;
        for(int j = 0; j < N; j++){
            if((i >> 2*j)%4 == 0) {
                a += l[j];
                cnta++;
            }
            if((i >> 2*j)%4 == 1) {
                b += l[j];
                cntb++;
            }
            if((i >> 2*j)%4 == 2) {
                c += l[j];
                cntc++;
            }
        }
        if(cnta > 0 && cntb > 0 && cntc > 0){
            int tmp = abs(A-a)+abs(B-b)+abs(C-c)+10*(cnta+cntb+cntc-3);
            ans = min(ans, tmp);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define lli long long int
#define pb push_back
#define mod 1000000007
#define mod2 998244353
#define MAXN 1000000000
#define v32 vector<int>
#define v64 vector<lli>
#define v1024 vector <vector <int>>
#define v4096 vector <vector <lli>>
#define vt vector
#define true 1
#define false 0
#define f(x, y, z) for (lli x = y; x < z; x++)
#define fd(x, y, z) for (int x = y; x > z; x--)
#define lb lower_bound
#define ld long double
#define m64 map<lli,lli>
#define m32 map<int,int>
#define m64it map<lli,lli>::iterator
#define m32it map<int,int>::iterator
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ist insert
#define pi (ld)3.1415926535897
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace __gnu_pbds;
using namespace std;
lli tmod(lli x,lli m){return (x%m+m)%m;}
lli bit_cnt[60];
int main()
{
  fastio;
  lli n;cin>>n;
  lli a[n];
  f(i,0,n)cin>>a[i];
  f(i,0,n){
    f(j,0,60){
      if((((1ll)<<j)&a[i]))
        bit_cnt[j]++;
    }
  }
  lli ans=0;
  f(i,0,60){  
    lli x=(((1ll)<<i)%mod);
    lli cnt=(bit_cnt[i])*(n-bit_cnt[i]);
    cnt=cnt%mod;
    x=(x*cnt)%mod;
    ans=(ans+x)%mod;
  }
  cout<<tmod(ans,mod)<<"\n";
  return 0;    	
}

Measured memory_bytes: 2560
#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;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main() {
    int n;
    cin >> n;
    map<string, int> m;
    rep(i,n) {
        string s;
        cin >> s;
        m[s]++;
    }
    cout << m.size() << endl;
}


Measured memory_bytes: 19224
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int k = scanner.nextInt();
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        for(int i = a; i <= b; i++){
            if(i%k==0){
                System.out.println("OK");
                return;
            }
        }
        System.out.println("NG");
    }
}



Measured memory_bytes: 35740
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

int main(){
int N; cin >> N;
  map<int,int> mp1,mp2;
  for(int i = 0; i < N; i++){
    int a; cin >> a;
    if( i % 2 == 0){ mp1[a]++;}
    else{ mp2[a]++;}}
  
  int cnt1 = 0; int cnt12 = 0; int cnt2 = 0; int cnt22 = 0;
  int maxa = 0; int maxb = 0;
 
  for(auto p:mp1){
    int s = p.first;
    int t = p.second;
    if( t > cnt1){ cnt12 = cnt1; cnt1 = t; maxa = s;}
    else if( t > cnt12){ cnt12 = t;}}
  
  for(auto p:mp2){
    int s = p.first;
    int t = p.second;
    if( t > cnt2){ cnt22 = cnt2; cnt2 = t; maxb = s;}
    else if( t > cnt22){ cnt22 = t;}}
  
  if( maxa != maxb){ cout << N - cnt1 - cnt2 << endl;}
  else{
    cout << min( ( N - cnt1 - cnt22) , ( N - cnt2 - cnt12)) << endl;}
  return 0;}
    

Measured memory_bytes: 4992
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
 
#if DEBUG
    #include "debug.h"
#else
    #define debug(args...)
#endif    

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;


#define M 1000000 
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = INT_MAX;
const int mod = 1e9+7;

const int N = 2e5 + 10;
inline int add(int x,int y){
  x += y;
  if(x >= mod) x -= mod;
  return x;
}
inline int mul(int x,int y){
  x = (1LL * x * y) % mod;
  return x;
}
clock_t time_p=clock();



int32_t main(){
  fast;

  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout);

  ll x;
  cin >> x;
  ll ans = 0;
  ans = ((x / 500) * 1000) + ((x % 500) / 5) * 5;
  cout << ans << "\n";


  time_p=clock()-time_p;
  cerr<<"\nTime Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
    char s[100100];
    scanf("%s",s);
    int ans = 0;
    for(int i = 0; i < strlen(s) - 1; i++){
        if(s[i] != s[i + 1])
            continue;
        if(s[i] == '0')
            s[i + 1] = '1';
        else 
            s[i + 1] = '0';
        ans ++;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 384
step = input()
flag = True
for i,s in enumerate(step):
	if s=='U' or s=='D':
		continue
	elif i%2!=0:
	#even
		if s=='L':
			continue
		else:
			flag = False
	else:
		if s=='R':
			continue
		else:
			flag = False
if flag:
	print('Yes')
else:
	print('No')


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

int main(){
    long long A,B,C,ans=0,x,y,z;
    cin>>A>>B>>C;
    x = A;
    y = B;
    z = C;
    bool flag = true;
    while(flag){
        long long a=A,b=B,c=C;
        if(A%2==1||B%2==1||C%2==1){
            flag = false;
        }else if(A==x&&B==y&&C==z&&ans!=0){
            ans = -1;
            flag = false;
        }else{
            A = b/2+c/2;
            B = a/2+c/2;
            C = a/2+b/2;
            ++ans;
        }
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 256
package main

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

func main() {
	var N, K int
	fmt.Scan(&N, &K)
	arr := make([]int, N)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := range arr {
		sc.Scan()
		arr[i], _ = strconv.Atoi(sc.Text())
	}
	sort.Sort(sort.IntSlice(arr))
	min := 99999999999
	for i := 0; i+K-1 < N; i++ {
		w := arr[i+K-1] - arr[i]
		if w < min {
			min = w
		}
	}
	fmt.Println(min)

}

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

int main(){
    while(1){
        char a;
        cin.get(a);
        if(a=='\n'){
            cout<<endl;
            break;
        }
        if(islower(a)) {
            cout<<(char)toupper(a);
        }else if(isupper(a)) {
            cout<<(char)tolower(a);
        }else {
            cout<<a;
        }
    }
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  
  int n;
  cin >> n ;
  
  vector<pair<long long int , long long int>> work;
  for (int i = 0; i < n; i++) {
    long long int a, b;
    cin >> a >> b;
    work.push_back({b, a});
  }  
 	sort(work.begin(), work.end());
    long long int c = work[n-1].first;
    for (int i = n - 1; i >= 0; i = i - 1) {
    	if (work[i].first >= c) {
      c = c - work[i].second;
   		}else{
      c = work[i].first - work[i].second;
    	}
  	}
  	if (c >= 0) {
		cout << "Yes" << endl;  
	}else{
      	cout << "No" << endl;
    }
}

Measured memory_bytes: 6384
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int m,n,cnt;
inline int read(){
	char ch=getchar();int o=0;
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') o=(o<<3)+(o<<1)+(ch^48),ch=getchar();
	return o;
}
int main(){
	cin>>n>>m;
	for(register int i=1;i<=n;i++){
		int x=read();
		if(x>=m) cnt++;
	}
	cout<<cnt<<endl;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;

int sum1[2019][2019], sum2[2019][2019], sum3[2019][2019], sum4[2019][2019], s[2019][2019];

int main(){
	int N, M, Q; cin >> N >> M >> Q;
	for(int i=1; i<=N; i++){
		for(int j=1; j<=M; j++){
			char c; cin >> c;
			s[i][j] = c - '0';
		}
	}
	for(int i=1; i<=N; i++){
		for(int j=1; j<=M; j++){
			sum1[i][j] = sum1[i-1][j] + sum1[i][j-1] - sum1[i-1][j-1] + s[i][j];
			sum2[i][j] = sum2[i-1][j] + sum2[i][j-1] - sum2[i-1][j-1];
			if(s[i-1][j] + s[i][j] == 2) sum2[i][j]++;
			if(s[i][j-1] + s[i][j] == 2) sum2[i][j]++;
		}
	}
	for(int i=1; i<=N; i++){
		for(int j=1; j<=M; j++){
			if(s[i][j] + s[i+1][j] == 2){
				sum3[i][j] = sum3[i][j-1] + 1;
			}else{
				sum3[i][j] = sum3[i][j-1];
			}
		}
	}
	for(int j=1; j<=M; j++){
		for(int i=1; i<=N; i++){
			if(s[i][j] + s[i][j+1] == 2){
				sum4[i][j] = sum4[i-1][j] + 1;
			}else{
				sum4[i][j] = sum4[i-1][j];
			}
		}
	}
	for(int i=0; i<Q; i++){
		int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
		int v = sum1[x2][y2] - sum1[x2][y1-1] - sum1[x1-1][y2] + sum1[x1-1][y1-1];
		int e = sum2[x2][y2] - sum2[x2][y1-1] - sum2[x1-1][y2] + sum2[x1-1][y1-1] - (sum4[x2][y1-1] - sum4[x1-1][y1-1]) - (sum3[x1-1][y2] - sum3[x1-1][y1-1]);
		cout << v - e << endl;
	}
	return 0;
}

Measured memory_bytes: 81280
import math
c=0
t,k = [int(x) for x in input().split(' ')]
for _ in range(t):
    x1,y1 = [int(x) for x in input().split(' ')]
    d = math.sqrt(x1**2+y1**2)
    if d<=k:
        c+=1
print(c)


Measured memory_bytes: 9184
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;


int main()
{
	int N;
	cin >> N;
	vector<int> A(N+1);
	vector<int> B(N);
	rep(i, N+1) cin >> A[i];
	rep(i, N) cin >> B[i];
	ll ans = 0;
	rep(i, N)
	{
		if (A[i]-B[i]>=0)
		{
			A[i] -= B[i];
			ans += B[i];
		}
		else
		{
			ans += A[i];
			B[i] -= A[i];
			A[i] = 0;
			if (A[i + 1] - B[i] >= 0)
			{
				ans += B[i];
				A[i + 1] -= B[i];
			}
			else
			{
				ans += A[i + 1];
				A[i + 1] = 0;
			}
		}
	}
	co(ans);
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<deque>
#include<string>

using namespace std;

int main(void){
  string S, T;
  deque<char> Sq, Tq;
  cin >> S >> T;
  for(auto itr = S.begin(); itr != S.end(); itr++) Sq.push_back(*itr);
  for(auto itr = T.begin(); itr != T.end(); itr++) Tq.push_back(*itr);
  for(int i = 0; i < S.length(); i++){
    if(Sq == Tq){
      cout << "Yes" << endl;
      return 0;
    }
    Sq.push_front(Sq.back());
    Sq.pop_back();
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <memory.h>
struct Data{
	int team,solve,time,wrong[10];
};
int main(void){
	struct Data D[50];
	int M,T,P,R,m,t,p,j,i;
	while(1){
		scanf("%d %d %d %d",&M,&T,&P,&R);
		if(!M)
			break;
		memset(D,0,sizeof(D));
		for(i=0;i<T;i++)
			D[i].team=i+1;
		for(i=0;i<R;i++){
			scanf("%d %d %d %d",&m,&t,&p,&j);
			if(j){
				D[t-1].wrong[p-1]++;
			}
			else{
				D[t-1].solve++;
				D[t-1].time+=m+20*D[t-1].wrong[p-1];
			}
		}
		for(i=0;i<T-1;i++){
			for(j=T-1;j>i;j--){
				if(D[j-1].solve<D[j].solve||D[j-1].solve==D[j].solve&&D[j-1].time>D[j].time||D[j-1].solve==D[j].solve&&D[j-1].time==D[j].time&&D[j-1].team<D[j].team){
					struct Data tmp=D[j-1];
					D[j-1]=D[j];
					D[j]=tmp;
				}
			}
		}
		for(i=0;i<T-1;i++){
			printf("%d",D[i].team);
			if(D[i].solve==D[i+1].solve&&D[i].time==D[i+1].time)
				printf("=");
			else
				printf(",");
		}
		printf("%d\n",D[i].team);
	}
	return 0;
}

Measured memory_bytes: 604
import java.awt.geom.Point2D;
import java.io.*;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Scanner;

import javax.xml.crypto.Data;
public class Main {

	static PrintWriter out = new PrintWriter(System.out);
	static FastScanner sc = new FastScanner();
	static Scanner stdIn = new Scanner(System.in);

	public static void main(String[] args) {
		while(true) {
			int n = sc.nextInt();
			if(n == 0) break;
			int[] list = new int[7];
			for(int i = 0; i < n; i++) {
				list[c(sc.nextInt())]++;
			}
			for(int i = 0; i < 7; i++) {
				out.println(list[i]);
			}
			
		}
		out.flush();
	}
	
	public static int c(int a) {
		return Math.min(a/10, 6);
	}
}
		
//------------------------------//
//-----------//
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    
    public int nextInt() {
    	return (int)nextLong();
    }
    
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
    

}

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

int main(){
	// sengen
	int n,k;
	// nyuryoku
	cin >> n >> k;
	int p[n];
	for(int i=0;i<n;i++) cin >> p[i];
	// keisan
	double sum = 0;
	for(int i=0;i<k;i++){
		sum += p[i];
	}
	double ans = sum;
	for(int i=1;i<=n-k;i++){
		sum += p[k-1+i];
		sum -= p[i-1];
		ans = max(ans,sum);
	}
	ans += k;
	// syutsuryoku
	printf("%lf",ans/2);
}

Measured memory_bytes: 1024