akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
  int N,M;
  cin>>N>>M;
  int left=1;
  int right=N;
  int L,R;
  for(int i=0;i<M;++i){
    cin>>L>>R;
    if(left<L){
      left=L;
    }
    if(right>R){
      right=R;
    }
  }
  int ans;
  ans=max(right-left+1,0);
  cout<<ans<<"\n";
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	string c[3];
	for(int i=0; i<3; i++){
		cin >> c[i];
	}
	cout << c[0][0] << c[1][1] << c[2][2] << endl;
	return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int main(){
	cin.sync_with_stdio(false);
	int n;
	cin >> n;


	set<int> set;
	rep(i, n) {
		int a;
		cin >> a;
		set.insert(a);
	}
	if (set.size() % 2) {
		cout << set.size() << endl;
	} else {
		cout << set.size() - 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 4992
N = int(input())
A = [[int(inp),i] for inp,i in zip(input().split(), range(N))]

from operator import itemgetter
def main():
    Ans = [0]*N
    A.sort(key = itemgetter(0))
    for i in range(N):
        Ans[i] = A[i][1] + 1
    print(*Ans,sep =" ")
    return
if __name__ == "__main__":
    main()

Measured memory_bytes: 26112
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int N_MAX = 200000;
typedef pair<int,int> P;
int main()
{
  int n,a,i,m1=0,m2=0,i1;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> a;
    if(a>m1){
      m2=m1;
      m1=a;
      i1=i;
    } else if(a>m2){
      m2=a;
    }
  }
  for(i=0;i<n;i++){
    if(i!=i1)
      cout << m1 << endl;
    else
      cout << m2 << endl;
  }
  return 0;
}


Measured memory_bytes: 1664
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i,s,n) for(int i=s; i<(n); ++i)
#define ALL(n) begin(n),end(n)
using ll = long long;
const ll INF = 1e18;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(){
    int N; cin >> N;
    vector<ll> A(N); REP(i, 0, N) cin >> A[i];

    REP(i, 0, N){
        if (A[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }

    ll MAX=1000000000000000000LL;

    ll tmp = 1LL;
    ll tmp_prev = 1LL;
    REP(i, 0, N){
        if (MAX / tmp < A[i]){
            cout << -1 << endl;
            return 0;
        }
        tmp *= A[i];
    }
    cout << tmp << endl;

    return 0;
}


Measured memory_bytes: 4032
from collections import deque

h, w = map(int, input().split())
ch,cw = map(int, input().split())
dh, dw = map(int, input().split())
ls = [input() for _ in range(h)]


widou = []
for i in range(-2,3):
    for j in range(-2, 3):
        widou.append((i, j))
widou.remove((0,0))
widou.remove((1,0))
widou.remove((0,1))
widou.remove((-1,0))
widou.remove((0,-1))


start = (ch-1, cw-1)
goal = (dh-1, dw-1)

explored = set()
tempexplored = set()

ytemp= deque()
ytemp.append(start)

wap = 0

while ytemp:
    now = ytemp.popleft()

    if now == goal:
        print(wap)
        exit(0)

    x = now[0]
    y = now[1]

    explored.add((x, y))
    tempexplored.add((x, y))

    idou = [(1,0), (0,1), (0,-1), (-1,0)]
    for i, j in idou:
        a = x + i
        b = y + j
        if 0 <= a < h and 0 <= b < w:
            if ls[a][b] == '.':
                if (a, b) not in explored:
                    ytemp.append((a,b))
                    explored.add((a,b))
                    tempexplored.add((a,b))

    if len(ytemp) ==0:
        wap += 1
        tempx = set()
        for s,t in tempexplored:
            for i, j in widou:
                a = s + i
                b = t + j
                if 0 <= a < h and 0 <= b < w:
                    if ls[a][b] == '.':
                        if (a, b) not in explored:
                            ytemp.append((a, b))
                            explored.add((a, b))
                            tempx = set()
        tempexplored = tempx
print('-1')

Measured memory_bytes: 148996
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin>>k;
	cout<<a[k-1]<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

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

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

struct UnionFind {
  vector<ll> par, siz;

  UnionFind(ll n):par(n),siz(n,1) {
    for (ll i = 0; i < n; ++i) par[i] = i; 
  }

  ll root(ll x) {
    if (par[x] == x) return x;
    else return par[x] = root(par[x]);
  }

  void merge(ll x, ll y) {
    ll rx = root(x);
    ll ry = root(y);
    if (rx == ry) return;
    if (siz[rx] < siz[y]) swap(rx, ry);
    par[rx] = ry;
    siz[ry] += siz[rx];
  }

  bool same(ll x, ll y) {
    return root(x) == root(y);
  }

  ll size(ll x) {
    return siz[root(x)];
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  vector<P> g(m);
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    g[i] = P(a,b);
  }
  int ans = 0;
  rep(i,m) {
    UnionFind tree(n);
    rep(j,m) {
      if (i == j) continue;
      tree.merge(g[j].first, g[j].second); 
    }
    bool sameunion = true;
    rep(j,n) {
      if (!tree.same(g[i].first, j) || !tree.same(g[i].second, j)) {
        sameunion = false;
        break;
      }
    }
    if (!sameunion) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

#define fast ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define fl(i,a,n) for(int i=a; i<=n; i++)
#define ll long long 
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define test()  int tt;  cin>>tt;  while(tt--)
#define nl  cout<<"\n"
#define pii pair<int,int>
#define sz(v) ((int)(v).size())
#define get(a,st,en)  fl(i,st,en)       cin>>a[i]
#define pr(a,st,en)     fl(i,st,en)     cout<<a[i]<<" \n"[i==en]

const int MOD = 1e9+7;
void solve()    {
        int x, y;       cin>>x>>y;
        if(y >= 2*x && y <= 4*x)    {
                y -= 2*x;
                if(y>=0 && y%2==0)      cout<<"Yes";
                else    cout<<"No";
        }
        else    cout<<"No";
}
int main()  {
    fast;
    //test()
        solve();
}
// credits @Benq
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/



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

int main(){
  string s,t;
  cin >>s>>t;
  
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  if(s<t) cout<<"Yes"<<endl;
  else cout << "No"<<endl;
 
  return 0;
}


Measured memory_bytes: 3572
#include <stdio.h>
int main (void){
    int a,b,i,j,r,l,ball[11],ans;
    scanf("%d",&a);
    for(i=0;i<a;i++){
        r=0,l=0,ans=0;
        for(j=0;j<10;j++){
            scanf("%d",&b);
            ball[j]=b;
        }
        for(j=0;j<10;j++){
            if(j==0){
                r=ball[0];
            }
            if(r>ball[j]&&l<ball[j]){
                l=ball[j];
                ans++;
            }
            else if(ball[j]-r>ball[j]-l&&ball[j]-r>0){
                l=ball[j];
                ans++;
            }
            else if(ball[j]-r<ball[j]-l&&ball[j]-l>0){
                r=ball[j];
                ans++;
            }
            if(j==ans){
                printf("NO\n");
                break;
            }
            if(j==9){
                printf("YES\n");
            }
        }
    }
return 0;
}

Measured memory_bytes: 580
#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>;
using namespace std;

int main()
{
    int n;
    cin >> n;
    int sum = 0;
    vector<int> tmp(n);

    rep(i, n) {
        cin >> tmp.at(i);
    }
    rep(i, n) {
        for(int j = i + 1; j < n; ++j) {
            sum += tmp[i] * tmp[j];
        }
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
N, A, B = map(int, input().split())
S = input()
T = []
Answer = []
Acount = 0
Tcount = 0

for i in range(N):
  if S[i] == "a":
    if A + B > Acount:
      Answer.append("Yes")
      Acount += 1
    else:
      Answer.append("No")
  elif S[i] == "b":
    if A + B > Acount and B > Tcount:
      Answer.append("Yes")
      T.append("Yes")
      Acount +=1
      Tcount +=1
    else:
      Answer.append("No")
  else:
    Answer.append("No")
  print(Answer[i])

Measured memory_bytes: 5688
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <string>

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

int main()
{
  char b, ans;

  cin >> b;

  if (b == 'A')
  {
    ans = 'T';
  }
  else if (b == 'T')
  {
    ans = 'A';
  }
  else if (b == 'G')
  {
    ans = 'C';
  }
  else
  {
    ans = 'G';
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <math.h>
#include <vector>
using namespace std;
int main()
{

	int res = 10000000000000;

    int N;
	cin >> N;
	vector<int> X(N);
	for (int t = 0; t < N; t++) {
		cin >> X[t];
	}

	for (int i = 1; i < 101; i++) {
		int ans=0;
		for (int t = 0; t < N; t++) {
			ans += pow(X[t]-i, 2);
		}
		if (ans < res) {
			res = ans;
		}
	}
	cout << res;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<fstream>
#include<utility>
#include<bitset>
#include<map>
#include<deque>
#include<cmath>
#include<random>
#include<string.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

int main() {
	makes(s);
	cout << s.front() << s.size() - 2 << s.back() << endl;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int N, M, ans = 0; 
    cin >> N >> M;
    vector<pair<int, int>> a;
    vector<pair<int, int>> b;
    a.resize(N);
    b.resize(M);
    for (int n = 0; n < N; ++n) {
        cin >> a[n].first;
        cin >> a[n].second;
    }

    for (int m = 0; m < M; ++m) {
        cin >> b[m].first;
        cin >> b[m].second;
    }

    pair<int, long long> answer;
    for (int n = 0; n < N; ++n) {
        for (int m = 0; m < M; ++m) {
            long long temp = abs(a[n].first - (b[m].first)) + abs(a[n].second - (b[m].second));
            if (m == 0) {
                answer.second = temp;
                answer.first = m;
            } else {
                if (answer.second != temp) {
                    answer.second = min(answer.second, temp);
                    if (answer.second == temp) answer.first = m;
                }
            }
        }
        cout << (answer.first + 1) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, ans = 0;
    ll m = 10;
    cin>>n;
    if(n & 1)
    {
    	cout<<0<<endl;
    	return 0;
    }
    while(1)
    {
    	if(n/m == 0)
    		break;
    	ans += n/m;
    	m = m*5;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;


int main(void){
  int x,y,z,k,i,j;
  ll a[1005],b[1005],c[1005];
  
  cin >> x >> y >> z >> k;
  for (i=0;i<x;i++) cin >> a[i];
  for (i=0;i<y;i++) cin >> b[i];
  for (i=0;i<z;i++){
    cin >> c[i];
    c[i]*=-1;
  }
  
  sort(c,c+z);
  
  int sum;
  ll l,r,mid,trg;
  ll *p;
  l=0;
  r=3e10+1;
  while (r-l>1){
    mid=(l+r)/2;
    sum=0;
    for (i=0;i<x;i++) for (j=0;j<y;j++){
      p=lower_bound(c,c+z,-(mid-a[i]-b[j])+1);
      sum+=p-c;
    }
    if (sum>=k) l=mid;
    else r=mid;
  }
  trg=l;
  
  vector<ll> ans;
  for (i=0;i<x;i++) for (j=0;j<y;j++){
    p=lower_bound(c,c+z,-(trg-a[i]-b[j])+1);
    if (p==c) continue;
    p--;
    while (p!=c){
      ans.push_back(a[i]+b[j]-*p);
      p--;
    }
    ans.push_back(a[i]+b[j]-c[0]);
  }
  
  sort(ans.begin(),ans.end(),greater<ll>());
  
  for (i=0;i<k;i++) cout << ans[i] << endl;
  
  return 0;
}

Measured memory_bytes: 133468
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
cnt = 0
for i in T:
    left = 0
    right = n
    flag = 0
    while left < right:
        mid = (left + right) // 2
        if S[mid] == i:
            flag = 1
            break
        elif S[mid] > i:
            right = mid
        else:
            left = mid+1
    if flag:
        cnt+=1
print(cnt)


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

# define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
# define reps(i, n) for(int(i)=1;(i)<=(n);(i)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<typename T> void dump(T e){std::cout << e << std::endl;}
template<typename T> void dump(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void dump(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ dump(v); } }
typedef long long ll;


int main(){
  int n;cin >> n;
  int ap=0,bp=0;
  rep(i,n) {
    string a,b;
    cin >> a >> b;
    if (a == b) {
      ap++;
      bp++;
    } else if (a > b) {
      ap = ap + 3;
    } else {
      bp = bp + 3;
    }
  }
  cout << ap << " " << bp << endl;
}



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

using namespace std;

typedef long long ll;

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 (a>b) { a=b; return 1; } return 0; }

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

	ll n;
	cin >> n;

	vector<ll> dp(n, 0);
	for(ll i = 1; i <= n - 1; i++){
		for(ll j = i; j <= n - 1; j += i){
			dp[j]++;
		}
	}

	ll ans = 0;
	rep(i, n) ans += dp[i];
	cout << ans << endl;
}


Measured memory_bytes: 11064
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

ll H[100100];
int main(){
    int N,K;
    cin >> N >> K;
    REP(i,N){
        ll h;
        cin >> h;
        H[i] = h;
    }
    sort(H,H+N);

    ll h_min = LLONG_MAX;
    for(int i = 0; i+K-1 < N; i++){
        ll low = H[i];
        ll high = H[i+K-1];
        h_min = min(h_min, high-low);
    }
    cout << h_min << endl;
    return 0;
}


Measured memory_bytes: 1024
;; E - Crested Ibis vs Monster

(defun solve (h ab)
  (let* ((min-mp (make-array (1+ h))))
    (setf (aref min-mp 0) 0)
    (loop for i from 1 to h
       do (setf (aref min-mp i)
                (loop for (a . b) in ab
                      for j = (max 0 (- i a))
                      minimize (+ (aref min-mp j) b))))
    (aref min-mp h)))

(let* ((h (read))
       (n (read))
       (ab (loop repeat n collect (cons (read) (read)))))
  (princ (solve h ab)))


Measured memory_bytes: 19172
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iostream>
#define INF 1000001LL
#define INF2 100000001000000LL
using namespace std;

typedef long long ll;
typedef vector<ll> cord;

#define N 100000

ll dis(cord &a, cord &b){
  if(a.size() != b.size())return INF;
  ll res = 0;
  for(int i=0;i<a.size();i++)res += (a[i]-b[i]) * (a[i]-b[i]);
  return res;
}

struct KDTree{
  int n,d;
  vector<cord> v;

  void heap(int l,int r,int &k){
    if(r-l<=1)return;
    int now,nxt;
    for(int i=1;i<r-l;i++){
      now = i;
      while(now){
	nxt = (now-1)>>1;
	if(v[l+nxt][k] < v[l+now][k])swap(v[l+nxt],v[l+now]);
	else break;
	now = nxt;
      }
    }

    for(int i=r-l-1;i>0;i--){
      swap(v[l+i],v[l]);
      now = 0; nxt = (now+1)<<1;
      while(nxt-1 < i){
	if(v[l+now][k] < v[l+nxt-1][k]){
	  if(nxt<i && v[l+nxt-1][k] < v[l+nxt][k]){
	    swap(v[l+now],v[l+nxt]);
	    now = nxt;
	  }else{
	    swap(v[l+now],v[l+nxt-1]);
	    now = nxt-1;
	  }
	}else if(nxt<i && v[l+now][k] < v[l+nxt][k]){
	  swap(v[l+now],v[l+nxt]);
	  now = nxt;
	}else break;
	nxt = (now+1)<<1;
      }
    }
  }

  void compose(int l, int r, int depth){
    if(r-l<1)return;
    heap(l,r,depth);

    compose(l,(l+r)/2,(depth+1)%d);
    compose((l+r)/2+1,r,(depth+1)%d);
  }

  void search(int l,int r,vector<ll>& b, cord& p, int depth, ll& dist){
    if(r-l<1)return;

    int mid = (l+r)/2;
    ll tmp;
    dist = min(dist,dis(p,v[mid]));

    for(int i=0;i<d;i++){
      tmp = b[2*i]-p[i];
      if(tmp>0 && tmp*tmp >= dist)return;
      tmp = b[2*i+1]-p[i];
      if(tmp<0 && tmp*tmp >= dist)return;
    }

    for(int i=0;i<3;i++){
      if(p[depth]>v[mid][depth] && i==2)continue;
      if(p[depth]<=v[mid][depth] && i==0)continue;
      int f = i&1;
      tmp = b[2*depth+f];
      b[2*depth+f] = v[mid][depth]; 
      if(f)search(l,mid,b,p,(depth+1)%d,dist);
      else search(mid+1,r,b,p,(depth+1)%d,dist);
      b[2*depth+f] = tmp;
    }
  }
};

int n,q,m;
cord p(3),r(3);
KDTree kd;

int main(){
  vector<ll> box;
  for(int i=0;i<3;i++){
    box.push_back(-INF); 
    box.push_back(INF);
  }

  while(scanf("%d%d",&n,&q)!=EOF,n||q){
    kd.v.resize(n);
    kd.n = n; kd.d = 3;

    for(int i=0;i<n;i++){
      kd.v[i].resize(3);
      for(int j=0;j<3;j++)scanf("%lld",&kd.v[i][j]);
    }

    kd.compose(0,n,0);

    for(int i=0;i<q;i++){
      scanf("%d",&m);
      double ans = 0;
      ll now,prv;

      for(int j=0;j<3;j++)scanf("%lld",&p[j]);
      prv = INF2;
      kd.search(0,n,box,p,0,prv);

      for(int j=1;j<m;j++){
	for(int k=0;k<3;k++)scanf("%lld",&r[k]);
	now = INF2;
	kd.search(0,n,box,r,0,now);

	ans += min( sqrt(prv) + sqrt(now), sqrt(dis(p,r)) );
	prv = now; p = r;
      }
      printf("%.9lf\n",ans);
    }
  }
}

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

using namespace std;

int main(){
    string S;
    cin >> S;
    int ans=0;
    if(S=="SSS"){
        ans=0;
    }
    else if(S=="SSR" || S=="SRS" || S=="RSS" || S=="RSR"){
        ans=1;
    }
    else if(S=="SRR"|| S=="RRS"){
        ans=2;
    }
    else{
        ans=3;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3584
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

char a,b;

int main()
{
	in>>a>>b;
	if(a<b)out<<"<"<<std::endl;
	else if(a>b)out<<">"<<std::endl;
	else out<<"="<<std::endl;
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int man = 1e6+10;
#define IOS ios::sync_with_stdio(0)
template <typename T>
inline T read(){T sum=0,fl=1;int ch=getchar();
for(;!isdigit(ch);ch=getchar())if(ch=='-')fl=-1;
for(;isdigit(ch);ch=getchar())sum=sum*10+ch-'0';
return sum*fl;}
template <typename T>
inline void write(T x) {static int sta[35];int top=0;
do{sta[top++]= x % 10, x /= 10;}while(x);
while (top) putchar(sta[--top] + 48);}
template<typename T>T gcd(T a, T b) {return b==0?a:gcd(b, a%b);}
template<typename T>T exgcd(T a,T b,T &g,T &x,T &y){if(!b){g = a,x = 1,y = 0;}
else {exgcd(b,a%b,g,y,x);y -= x*(a/b);}}
#ifndef ONLINE_JUDGE
#define debug(fmt, ...) {printf("debug ");printf(fmt,##__VA_ARGS__);puts("");}
#else
#define debug(fmt, ...)
#endif
typedef long long ll;
const ll mod = 1e9+7;
string str;
int dp[man][2];

int main() {
    #ifndef ONLINE_JUDGE
        //freopen("in.txt", "r", stdin);
        //freopen("out.txt","w",stdout);
    #endif
    cin >>str;
    reverse(str.begin(),str.end());
    //cout <<str<<endl;
    dp[0][0] = str[0] - '0';
    dp[0][1] = 10 - str[0] + '0';
    int len = str.size();
    str[len] = '0';
    for(int i = 1;i <= len;i++){
        dp[i][0] = min(dp[i-1][0],dp[i-1][1] + 1) + str[i] - '0';   
        dp[i][1] = min(dp[i-1][0] + 10 - (str[i] - '0'),dp[i-1][1] + 10 - (str[i] - '0' + 1 ));
        //cout << dp[i][0] << " " << dp[i][1] << endl;
    }
    //cout <<dp[len-1][0] << " " << dp[len-1][1] <<endl;
    cout << min(dp[len][0],dp[len][1]) << endl;
    return 0;
}

Measured memory_bytes: 9220
#include<bits/stdc++.h>
using namespace std;
int main(){
	int ans=0,a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	ans=ans+abs(a[0]-a[1])+abs(a[1]-a[2]);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def r_sort(a) a.sort{|a,b|b<=>a} end

n =gets.to_i
t = ARGF.map(&:to_i)
max2 = max = 0
t.each do |d|
  if(d > max)
    max2 = max
    max = d
    next
  end
  if(d > max2)
    max2 = d
  end
end
t.each do |d|
  puts (d==max)? max2:max
end


Measured memory_bytes: 4860
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
int32_t main()
{
	#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
	#endif
	int n;
	cin>>n;
	string s;
	cin>>s;
	vector<int> dot(n),h(n);
	if(s[0]=='#')h[0]=1;if(s[n-1]=='.')dot[n-1]=1;
	for(int i=1;i<n;i++)
	{
		h[i]=h[i-1]+(s[i]=='#');
	}
	
	for(int i=n-2;i>=0;i--)
		dot[i]=dot[i+1]+(s[i]=='.');
	
	int ans=min(h[n-1],dot[0]);
	for(int i=0;i<n-1;i++)ans=min(ans,h[i]+dot[i+1]);
	cout<<ans;
}

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

using namespace std;

int main(void)
{
    int n;
    cin >>n;
    string s;
    cin >>s;

    map<char, int> mp;
    mp['R'] = 0;
    mp['G'] = 1;
    mp['B'] = 2;

    vector<vector<int> > colors(3, vector<int>());
    for(int i = 0; i < n; i++){
        colors[mp[s[i]]].push_back(i);
    }

    long long sum = colors[0].size() * colors[1].size() * colors[2].size();

    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n && (j-i)+j < n; j++){
            int k = (j-i)+j;
            if(k < j){ continue;}
            if(s[i] != s[j] && s[i] != s[k] && s[k] != s[j]){
                sum--;
            }
        }
    }

    printf("%lld\n", sum);
    return 0;
}

Measured memory_bytes: 3724
#include <iostream>

int main( void )
{
    int a, b, c;
    std::cin >> a >> b >> c;
    if ( ( a < b ) && ( b < c ) )
    {
        std::cout << "Yes" << std::endl;
    }
    else
    {
        std::cout << "No" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;

struct UnionFind
{
    int n, num;
    vector<int> r, p;
    UnionFind() {}
    UnionFind(int sz) : n(sz), num(sz), r(sz, 1), p(sz, 0) { iota(p.begin(), p.end(), 0); }
    int find(int x)
    {
        return (x == p[x] ? x : p[x] = find(p[x]));
    }
    bool same(int x, int y)
    {
        return find(x) == find(y);
    }
    void unite(int x, int y)
    {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (r[x] < r[y])
            swap(x, y);
        r[x] += r[y];
        p[y] = x;
        num--;
    }
    int size(int x)
    {
        return r[find(x)];
    }
    int count() const
    {
        return num;
    }
};

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

    int n, k, l;
    cin >> n >> k >> l;
    UnionFind uf1(n), uf2(n);
    rep(i, k)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        uf1.unite(a, b);
    }
    rep(i, l)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        uf2.unite(a, b);
    }
    map<P, int> cnt;
    rep(i, n) cnt[P(uf1.find(i), uf2.find(i))]++;
    rep(i, n) cout << cnt[P(uf1.find(i), uf2.find(i))] << " ";
    cout << endl;
}

Measured memory_bytes: 18176
#include <bits/stdc++.h>
using namespace std;
#define INF 1001001001001001

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    vector<int> d(N+1);
    d[0] = 0;
    for(int i=1; i<=N; ++i) {
        if(S[i-1] == '(') d[i] = d[i-1] + 1;
        else d[i] = d[i-1] - 1;
    }
    int dn = d[N];
    sort(d.begin(), d.end());
    int dmin = d[0];

    for(int i=0; i>dmin; --i) cout << '(';
    cout << S;
    for(int i=0; i<dn-dmin; ++i) cout << ')';
    cout << endl;
}

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

using namespace std;

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

    if((k % 2 == 0) || (k % 5 == 0)) {
        cout << -1 << endl;
        return 0;
    }

    if(k % 7 == 0) {
        k /= 7;
    }

    long long a = 1;
    long long count = 1;
    while(1) {
        if(a % k == 0) {
            cout << count << endl;
            return 0;
        }
        a = (a * 10 + 1) % k;
        count++;
    }
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

string change(string s, int n)
{
    string ret = "";
    rep(i, s.size() - 1)
    {
        if (s[i] == n || s[i + 1] == n)
        {
            ret.push_back(n);
        }
        else
        {
            ret.push_back(s[i]);
        }
    }
    return ret;
}
bool is_monochar(string s)
{
    int n = s[0];
    rep(i, s.size())
    {
        if (s[i] != n)
        {
            return false;
        }
    }
    return true;
}

signed main()
{
    string s;
    cin >> s;
    string alphabet = "abcdefghijklmnopqrstuvwxyz";
    int ans = 1000;
    for (auto &a : alphabet)
    {
        string ss = s;
        bool f = true;
        int cnt = 0;
        while (!is_monochar(ss))
        {
            cnt++;
            ss = change(ss, a);
        }
        chmin(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <utility>
using namespace std;
typedef long long int lli;
typedef pair<int, int> pii;
typedef pair<lli, lli> pll;
const lli inf = 1e18;

int main(){
	int n,m;
	cin >> n >> m;
	vector<int> x(n+2, 0);
	for(int i=0; i<m; i++){
		int a,b;
		cin >> a >> b;
		x[a]++;
		x[b+1]--;
	}
	for(int i=0; i<n+1; i++){
		x[i+1] += x[i];
	}
	int ans = 0;
	for(int i=0; i<n+1; i++){
		if(x[i] == m) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
using namespace std;

int main() {
  string musi;
  while(cin >> musi, musi != "0") {
    string tonum;
    for(int i=0; i<musi.size(); i++) {
      if(musi[i] == 'r')
        tonum.push_back('1');
      if(musi[i] == 'g')
        tonum.push_back('2');
      if(musi[i] == 'b')
        tonum.push_back('3');
    }
    queue< pair<string, int> > q;
    pair<string, int> p;
    p.first = tonum;
    p.second = 0;
    q.push(p);
    bool flg = true;
    set<string> memo;
    int test = 0;
    while(q.size()) {
      p = q.front();
      q.pop();
      int cnt = 0;
      for(int i=1; i<p.first.size(); i++) {
        if(p.first[i-1] != p.first[i]) {
          pair<string, int> p2;
          p2 = p;
          int n = (int)p.first[i-1] + (int)p.first[i] - '0' - '0';
          if(n==3) {
            p2.first[i-1] = '3';
            p2.first[i] = '3';
          }
          else if(n==4) {
            p2.first[i-1] = '2';
            p2.first[i] = '2';
          }
          else if(n==5) {
            p2.first[i-1] = '1';
            p2.first[i] = '1';
          }
          if(memo.find(p2.first) == memo.end()) {
            p2.second++;
            q.push(p2);
            memo.insert(p2.first);
          }
        }
        else cnt++;
      }
      if(cnt == p.first.size()-1) {
        flg = false;
        cout << p.second << endl;
        break;
      }
    }
    if(flg) cout << "NA" << endl;
  }
  return 0;
}

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

int n, m, q;
vector<string> s;
vector<vector<int>> node, edgel, edgeu;

int calc(int l, int r, int u, int d, vector<vector<int>> &v);

int main() {
  cin >> n >> m >> q;
  s.resize(n);
  node.assign(n + 1, vector<int>(m + 1, 0));
  edgel.assign(n + 1, vector<int>(m + 1, 0));
  edgeu.assign(n + 1, vector<int>(m + 1, 0));
  for (auto &t : s) cin >> t;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      node[i + 1][j + 1] =
          s[i][j] - '0' + node[i + 1][j] + node[i][j + 1] - node[i][j];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      if (j != 0 && s[i][j] == '1' && s[i][j] == s[i][j - 1])
        ++edgel[i + 1][j + 1];
      edgel[i + 1][j + 1] += edgel[i + 1][j] + edgel[i][j + 1] - edgel[i][j];
    }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      if (i != 0 && s[i][j] == '1' && s[i][j] == s[i - 1][j])
        ++edgeu[i + 1][j + 1];
      edgeu[i + 1][j + 1] += edgeu[i + 1][j] + edgeu[i][j + 1] - edgeu[i][j];
    }
  for (int i = 0; i < q; ++i) {
    int u, l, d, r;
    cin >> u >> l >> d >> r;
    cout << calc(l, r, u, d, node) - calc(l + 1, r, u, d, edgel) -
                calc(l, r, u + 1, d, edgeu)
         << endl;
  }
  return 0;
}

int calc(int l, int r, int u, int d, vector<vector<int>> &v) {
  --l, --u;
  return v[d][r] - v[u][r] - v[d][l] + v[u][l];
}

Measured memory_bytes: 58352
// Created by ...
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'

#define vll vector< ll >
#define M 100000
#define MD 1000000007
#define pb push_back
#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 pii pair<ll,ll> 
#define vec(a) vector<a >
#define all(a) a.begin(),a.end()
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;
using ll = long long;
ll md=MD;

ll exp(ll a,ll b){ll r=1ll;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll Min(ll a,ll b){if(a<b)return a; return b;}
ll Max(ll a,ll b){if(a>b)return a; return b;}
int32_t main() {
    IOS;

        string s; cin>>s;
        int n=s.size(),i=0,j=n-1,ans=0;
        while(i<j)
        {
        	if(s[i]!=s[j])++ans;
        	++i;--j;
        }
        cout<<ans;


        cout<<'\n';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
  int n;
  string s;
  cin >> n;
  cin >> s;
  int m = s.size();
  rep(i, m){
    int num = s[i] - 'A';
    num = (num + n) % 26;
    char c = 'A' + num;
    cout << c;
  }
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int ans=1;

		for(int i = 1 ; i <= B ; i++) {
			ans = K * i;
			if(ans >= A && ans <= B) {
				System.out.println("OK");
				break;
			}else if(ans > B){
				System.out.println("NG");
				break;
			}
		}



		sc.close();

	}

}


Measured memory_bytes: 35572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
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; }

int main() {
    ll H, W; cin >> H >> W;
    vector<vector<char>> MS(55, vector<char>(55));
    reps(i, H) {
        reps(j, W) cin >> MS[i][j];
    }

    reps(i, H) {
        reps(j, W) {
            if (MS[i][j] == '#') cout << '#';
            else {
                ll bomb = 0;
                if (MS[i - 1][j - 1] == '#') bomb++;
                if (MS[i - 1][j] == '#') bomb++;
                if (MS[i - 1][j + 1] == '#') bomb++;
                if (MS[i][j - 1] == '#') bomb++;
                if (MS[i][j + 1] == '#') bomb++;
                if (MS[i + 1][j - 1] == '#') bomb++;
                if (MS[i + 1][j] == '#') bomb++;
                if (MS[i + 1][j + 1] == '#') bomb++;
                cout << bomb;
            }
        }
        cout << endl;
    }
}

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

int main(){
  int N, Y;
  cin>>N >> Y;
  int res10k=-1, res5k=-1, res1k=-1;

  for(int a=0;a<=N;a++){
    for(int b=0;b<=N;b++){
      int c =N-a-b;
      int total =10000*a + 5000*b + 1000*c;
      if(total == Y && c>=0){
        res10k = a;
        res5k = b;
        res1k = c;
      }
    }
  }
  cout << res10k << " " << res5k << " " << res1k << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main ( void )
{
  puts ( "1x1=1\n1x2=2\n1x3=3\n1x4=4\n1x5=5\n1x6=6\n1x7=7\n1x8=8\n1x9=9\n2x1=2\n2x2=4\n2x3=6\n2x4=8\n2x5=10\n2x6=12\n2x7=14\n2x8=16\n2x9=18\n3x1=3\n3x2=6\n3x3=9\n3x4=12\n3x5=15\n3x6=18\n3x7=21\n3x8=24\n3x9=27\n4x1=4\n4x2=8\n4x3=12\n4x4=16\n4x5=20\n4x6=24\n4x7=28\n4x8=32\n4x9=36\n5x1=5\n5x2=10\n5x3=15\n5x4=20\n5x5=25\n5x6=30\n5x7=35\n5x8=40\n5x9=45\n6x1=6\n6x2=12\n6x3=18\n6x4=24\n6x5=30\n6x6=36\n6x7=42\n6x8=48\n6x9=54\n7x1=7\n7x2=14\n7x3=21\n7x4=28\n7x5=35\n7x6=42\n7x7=49\n7x8=56\n7x9=63\n8x1=8\n8x2=16\n8x3=24\n8x4=32\n8x5=40\n8x6=48\n8x7=56\n8x8=64\n8x9=72\n9x1=9\n9x2=18\n9x3=27\n9x4=36\n9x5=45\n9x6=54\n9x7=63\n9x8=72\n9x9=81" );

  return ( 0 );
}

Measured memory_bytes: 0
n,m=map(int,raw_input().split())
a,b=[],[]
for i in range(n):a.append(map(int,raw_input().split()))
for i in range(m):b.append(input())
for i in range(n):
    ans=0
    for j in range(m): ans+=a[i][j]*b[j]
    print ans

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

using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)
#define MOD 1000000007

//debug
#define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<<x<<" ";cerr<<endl;

int main(){
  ll H, W, K;
  cin >> H >> W >> K;
  vector<string> S(H);
  rep(i, H) cin >> S[i];

  ll ans = H + W;
  rep(bit, 1 << (H-1)){
    ll count = 0;
    rep(b, H-1) count += (bit >> b) % 2;
    ll sum_white[H] = {};
    rep(w, W){
      ll tmp = 0;
      ll n_white[H] = {};
      bool cut_flg = false;
      rep(h, H){
        if(h == 0 || (bit >> (h-1)) % 2) tmp = S[h][w] - '0';
        else tmp += S[h][w] - '0';
        n_white[h] += tmp;
        if(n_white[h] > K) count = H + W;
        if(n_white[h] + sum_white[h] > K) cut_flg = true;
      }
      if(cut_flg){
        rep(h, H) sum_white[h] = n_white[h];
        count++;
      }
      else{
        rep(h, H) sum_white[h] += n_white[h];
      }
    }
    if(ans > count) ans = count;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <cassert>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <cstdlib>
#include <string>
#include <unordered_map>
#include <map>
#include <sstream>
#include <bitset>
#include <random>
#include <tuple>
#include <array>
#include <tgmath.h>
#include <functional>
#include <climits>
#include <complex>
#include <unistd.h>
using namespace std;

typedef long long int lli;
typedef pair<int, int> pii;
typedef pair<lli, lli> plli;
typedef unsigned char byte;
typedef unsigned int uint;
typedef unsigned long long int ulli;

int arr[200100];

int main() {
    int n;
    scanf("%d", &n);
    int i;
    for (i=0; i<n; ++i) {
        scanf("%d", arr+i);
        arr[i] -= i + 1;
    }
    sort(arr, arr+n);
    int mid = arr[n/2];
    lli s = 0;
    for (i=0; i<n; ++i) {
        s += abs(arr[i] - mid);
    }
    printf("%lld\n", s);
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
int main(){
	int n=read(),m=2*n;
	long double a=read(),d=read(),ans=0;
	REP(i,1,n){
		ans+=a+d*(m-1)/2;
		a=(a*(m+2)+5*d)/m;
		d=(m+4)*d/m;
		m-=2;
	}
	printf("%.15Lf\n",ans);
	return 0;
}


Measured memory_bytes: 256
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

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

	ll q, h, s, d;
	ll n;
	ll ans=0;
	ll a;
	cin >> q >> h >> s >> d;
	cin >> n;

	n *= 100;
	
	h = min(h, q * 2);
	s = min(s, h * 2);
	d = min(d, s * 2);

	if (n >= 200) {
		a = n / 200;
		n -= 200*a;
		ans += a * d;
	}
	if (n >= 100) {
		a = n / 100;
		n -= 100 * a;
		ans += a * s;
	}
	if (n >= 50) {
		a = n / 50;
		n -= 50 * a;
		ans += a * h;
	}
	if (n >= 25) {
		a = n / 25;
		n -= 25 * a;
		ans += a * q;
	}
	cout << ans << endl;
	return 0;
}





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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}
template<typename T,typename U>
ll FindErase(T &v,U tar){
  ll cnt = 0;
  for(auto it = v.begin(); it != v.end();){
    if(*it == tar){
      it = v.erase(it);
      ++cnt;
    }
    else{
      ++it;
    }
  }
  return cnt;
}

template<typename T>
bool SuffixErase(T &v,size_t suf){
  if(suf > v.size()) return false;
  for(auto it = v.begin(); it != v.end();){
    if(distance(v.begin(),it) == suf){
      v.erase(it);
      return true;
    }
    else{
      ++it;
    }
  }
  return false;
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vary(int,v,2 * N,0);
  rep(i,2 * N){
    cin >> v[i];
  }
  sort(all(v));
  ll ans = 0;
  rep(i,N){
    ans += v[2 * i];
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <functional>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -----------------------------------------------------------------------*/
#define ALL(a)				(a).begin(),(a).end()
#define REP(i, n)			for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)		for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF					(1000 * 1000 * 1000 * 2)
#define MOD					(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)			(((((x))+((n)-1))/n))	/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)			(((((x))+((n)-1))/n)*n)	/* Nの倍数に切り上げ */
#define FloorN(x, n)		((x)-(x)%(n))			/* Nの倍数に切り下げ */
#define IsOdd(x)			(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)			(!IsOdd((x)))						
#define	BitSetV(Val,Bit)	((Val) |= (Bit))			
#define	BitTstV(Val,Bit)	((Val) & (Bit))				
#define M_PI				3.14159265358979323846
typedef long long			ll;
typedef pair<ll, ll>		P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
// メイン
int main()
{
	ll N, K;
	cin >> N >> K;
	vector<ll> A(N);
	REP(i, N) cin >> A[i];

	vector<ll> bitSum(60, 0);
	REP(i, N) {
		REP(j, 60) {
			if (A[i] & ((ll)0x1 << j)) {
				bitSum[j]++;
			}
		}
	}

	ll harf;
	if (IsOdd(N)) {
		harf = N / 2;
	} else {
		harf = N / 2 - 1;
	}

	ll mask = 0;
	bool isSmallFind = false;
	for (ll i = 60; 0 <= i; i--) {
		bool isOn = false;
		if (bitSum[i] <= harf) {
			if (K & (ll(0x1) << i)) {
				isOn = true;
			} else {
				isOn = isSmallFind;
			}
		} else {
			if (K & (ll(0x1) << i)) {
				isSmallFind = true;
			}
		}

		if (isOn) {
			mask += (ll)0x1 << i;
		}
	}

	ll ans = 0;
	REP(i, N) {
		ans += A[i] ^ mask;
	}

	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>

#pragma comment(linker, "/STACK:336777216")  

using namespace std;

int N;

long long Gcd(long long A, long long B)
{
	return (A == 0) ? B : Gcd(B, B % A);
}

void Work()
{
	scanf("%d", &N);
	for (long long a = 1; a <= 3500; a ++)
		for (long long b = 1; b <= 3500; b ++)
		{
			long long u = 4LL * a * b - N * (a + b);
			long long d = N * a * b;
			if (u <= 0)
				continue;
			if (d % u == 0)
			{
				printf("%lld %lld %lld\n", a, b, d / u);
				return;
			}
		}
}

int main()
{
	Work();
	return 0;
}

Measured memory_bytes: 256