akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	int h, w;
	cin >> h >> w;
	char s[51][51];
	rep(i, h) {
		rep(j, w) {
			cin >> s[i][j];
		}
	}
	int xx[] = { 0,1,0,-1 };
	int yy[] = { 1,0,-1,0 };
	rep(i, h) {
		rep(j, w) {
			if (s[i][j] == '.')continue;
			int ok = false;
			rep(k, 4) {
				int ni = i + xx[k];
				int nj = j + yy[k];
				if (ni < 0 || h < ni)continue;
				if (nj < 0 || w < nj)continue;
				if (s[ni][nj] == '#')ok =true;
			}
			if (!ok) {
				print("No");
				return 0;
			}
		}
	}
	print("Yes");
}

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

int main() {
    int n , m; cin>>n>>m;
    int s = 0 ; 
    for(int i = 0 ; i < m; ++i){
        int x; cin >>x;
        s += x;
    }
    cout<<((n - s >= 0)?(n - s):-1)<<"\n";
}


Measured memory_bytes: 3612
# 2020/07/04
# AtCoder Beginner Contest 071 - C

# Input
n = int(input())
a = list(map(int,input().split()))

a.sort()

h_long = 0
h_short = 0
i = n - 1

#for i in range(n-1, 0, -1):
while i > 0:
    if a[i-1] == a[i]:
        if h_long == 0:
            h_long = a[i]
            i = i - 1
        else:
            h_short = a[i]
            break
    i = i - 1

ans = h_short * h_long

# Output
print(ans)


Measured memory_bytes: 20016
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,a,b;
	cin>>n>>m>>a>>b;
	for(register int i=1;i<=n-b;++i){
		for(register int j=1;j<=m-a;++j)putchar('1');
		for(register int j=m-a+1;j<=m;++j)putchar('0');
		putchar('\n'); 
	}
	for(register int i=n-b+1;i<=n;++i){
		for(register int j=1;j<=m-a;++j)putchar('0');
		for(register int j=m-a+1;j<=m;++j)putchar('1');
		putchar('\n'); 
	}
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll mod = 1e9+7;
#define rep(i,n) for(int i = 0;i<n;i++)

int main(){
	double a,b,h,m;
	cin >> a >> b>>h>>m;
	 static const double pi = 3.141592653589793;

	double Atheta = h*30+m/2.0;
	double Btheta = m*6;
	double theta = abs(Atheta - Btheta);

	double costheta = cos(theta/180*pi);

	double ans = sqrt(a*a+b*b-2*a*b*costheta);
	printf("%.11lf\n", ans);

	return 0;
}

Measured memory_bytes: 4256
#include <stdio.h>
#include <math.h>

double minko(int n, double p, double *v1, double *v2)
{
	double s = 0;
	for (int i = 0; i < n; i++)
		s += pow(fabs(v1[i] - v2[i]), p);

	return pow(s, 1/p);
}

double cheby(int n, double *v1, double *v2)
{
	double s = 0;

	for (int i = 0; i < n; i++) {
		double a = fabs(v1[i] - v2[i]);
		if (s < a)
			s = a;
	}

	return s;
}

int
main(void)
{
	int n;
	double vec[2][100];

	scanf("%d", &n);

	for (int i = 0; i < 2; i++)
		for (int j = 0; j < n; j++)
			scanf("%lf", &vec[i][j]);

	printf("%lf\n", minko(n, 1, vec[0], vec[1]));
	printf("%lf\n", minko(n, 2, vec[0], vec[1]));
	printf("%lf\n", minko(n, 3, vec[0], vec[1]));
	printf("%lf\n", cheby(n,    vec[0], vec[1]));

	return 0;
}



Measured memory_bytes: 2140
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")
MOD = 10 ** 9 + 7


def debug(*x):
    print(*x, file=sys.stderr)


def solve(S, T):
    buf = []
    for i in range(len(S) - len(T) + 1):
        diff = 0
        for j in range(len(T)):
            if S[i + j] != T[j]:
                diff += 1
        buf.append(diff)
    return min(buf)


def main():
    # parse input
    S = input().strip()
    T = input().strip()
    print(solve(S, T))


# tests
T1 = """
cabacc
abc
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
1
"""

T2 = """
codeforces
atcoder
"""
TEST_T2 = """
>>> as_input(T2)
>>> main()
6
"""

T3 = """
aaa
bbb
"""
TEST_T3 = """
>>> as_input(T3)
>>> main()
3
"""


def _test():
    import doctest
    doctest.testmod()
    g = globals()
    for k in sorted(g):
        if k.startswith("TEST_"):
            doctest.run_docstring_examples(g[k], g, name=k)


def as_input(s):
    "use in test, use given string as input file"
    import io
    f = io.StringIO(s.strip())
    g = globals()
    g["input"] = lambda: bytes(f.readline(), "ascii")
    g["read"] = lambda: bytes(f.read(), "ascii")


input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

if sys.argv[-1] == "-t":
    print("testing")
    _test()
    sys.exit()

main()


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/27  Problem: 074_arc_b / Link: https://abc062.contest.atcoder.jp/tasks/arc074_b?lang=en  ----- */
/* ------問題------

N を 1 以上の整数とします。
長さ 3N の数列 a=(a1,a2,…,a3N) があります。 すぬけ君は、a からちょうど N 個の要素を取り除き、残った 2N 個の要素を元の順序で並べ、長さ 2N の数列 a' を作ろうとしています。 このとき、a' のスコアを (a'の前半N要素の総和)−(a'の後半N要素の総和) と定義します。
a' のスコアの最大値を求めてください。

-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	cin >> N;
	VI a(3 * N);
	FOR(i, 0, 3 * N) {
		cin >> a[i];
	}

	VL dp1(3 * N, 0);
	{
		priority_queue<int, VI, greater<int>>pq;
		LL sum = 0;
		FOR(i, 0, 3 * N) {

			sum += a[i];
			pq.push(a[i]);
			if (SZ(pq)== (N + 1)) {
				LL val = pq.top(); pq.pop();
				sum -= val;
			}
			dp1[i] = sum;
		}
		//FOR(i, 0, 3 * N) {
		//	cout << dp1[i] << " ";
		//}cout << endl;
	}
	VL dp2(3 * N, 0);
	{
		priority_queue<int>pq;
		LL sum = 0;
		FORR(i, 3*N-1, 0-1) {

			sum += a[i];
			pq.push(a[i]);
			if (SZ(pq) ==(N + 1)) {
				LL val = pq.top(); pq.pop();

				sum -= val;
			}
			dp2[i] = sum;
		}
		//FOR(i, 0, 3 * N) {
		//	cout << dp2[i] << " ";
		//}cout << endl;
	}
	ans = -LINF;
	FOR(i, N-1, 2 * N) {
		ans = max(ans, dp1[i] - dp2[i+1]);
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 7028
x = int(input())
li = list(map(int, input().split()))
k = 1
s = 0
for i in range(len(li)):
    if k == li[i] :
        k += 1
        s += 1
    if i == len(li)-1 and k == 1:
        s = len(li) + 1
print(len(li)-s)

Measured memory_bytes: 26268
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
//ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
//ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve() {
  string s;
  cin>>s;
  if(s=="ABC") out("ARC");
  else out("ABC");
}

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


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
using namespace std;

int main(){
  string S;
  cin >> S;
  int N = S.size();
  vector<int> s(N);
  for(int i = 0; i < N; i++){
    s.at(i) = S.at(i) - '0';
  }

  for(int bit = 0; bit < (1 << N - 1); bit++){
    int sum = 0;
    bitset<3> bs(bit);
        // cout << bs << endl;
    for(int i = 0; i < N - 1; i++){
      if(bs.test(i)){
        // cout << sum + s.at(N - 1 - i) << " = " << sum  << " + " << s.at(N - 1 - i) << endl;
        sum += s.at(N - 1 - i);
      }else{
        // cout << sum - s.at(N - 1 - i) << " = " << sum  << " - " << s.at(N - 1 - i) << endl;
        sum -= s.at(N - 1 - i);
      }
    }
    // cout << sum + s.at(0) << " = " << sum  << " + " << s.at(0) << endl;
    sum += s.at(0);
    // cout << sum << endl;
    if(sum == 7){
      for(int i = 0; i < N - 1; i++){
        cout << s.at(i);
        if(bs.test(N - 1 - (i + 1))){
          cout << "+";
        }else{
          cout << "-";
        }
      }
      cout << s.at(N - 1) << '=' << sum << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
s=input()
t=input()
schar=[]
tchar=[]
for i in range(len(s)):
  schar.append(ord(s[i]))
for i in range(len(t)):
  tchar.append(ord(t[i]))
schar.sort()
tchar.sort(reverse=True)
flag=0
for i in range(min(len(s),len(t))):
  if schar[i]==tchar[i]:
    continue
  elif schar[i]>tchar[i]:
    flag=1
    break
  else:
    flag=-1
    break
if flag==1:
  print("No")
elif flag==-1:
  print("Yes")
else:
  if len(s)<len(t):  
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 3064
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
a = a[::-1]

if n % 3 == 0:
    if n % 2 == 0:
        print(a[0] + sum(a[1:n//2]) * 2)
    else:
        print(a[0] + sum(a[1:n//2]) * 2 + a[n//2])
elif n % 3 == 2:
    if n % 2 == 0:
        print(a[0] + sum(a[1:n//2]) * 2)
    else:
        print(a[0] + sum(a[1:n//2]) * 2 + a[n//2])
else:
    if n % 2 == 0:
        print(a[0] + sum(a[1:n//2]) * 2)
    else:
        print(a[0] + sum(a[1:n//2]) * 2 + a[n//2])


Measured memory_bytes: 93920
def solve(N, Y):
  res = '-1 -1 -1'
  for i in range(0, N + 1):
    for j in range(0, N + 1):
      if i * 10000 + j * 5000 + (N - i - j) * 1000 == Y and N - i - j >= 0:
        res = '{0} {1} {2}'.format(i, j, N - i - j)
        return res
  return res
N, Y = map(int, input().split(' '))
print(solve(N, Y))

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

int main(int argc, char const *argv[])
{
    long a;
    string s;
    char c[3];
    cin >> a >> s;
    c[0] = s[0];
    c[1] = s[2];
    c[2] = s[3];
    long b = atoi(c);
    long r = (a * b) / 100;
    cout << r << endl;

    return 0;
}


Measured memory_bytes: 3624
n, m = map(int, input().split())
ab = []
for i in range(m):
  ab.append(list(map(int, input().split())))
count = 0
while len(ab) > 0:
  c = float('inf')
  for i in range(len(ab)):
    if ab[i][1] < c:
      c = ab[i][1]
  count += 1
  tmp = []
  for i in range(len(ab)):
    if ab[i][0] >= c:
      tmp.append(ab[i])
  ab = tmp
print(count)

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

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

        sum = sum + a[i];
    }
    if (sum > n){
        cout << -1 << endl;
    }else{
        cout << n - sum << endl;
    }
    return 0;
}

Measured memory_bytes: 3760
#pragma warning(disable:4996)
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<time.h>
#include<iomanip>
using namespace std;
typedef unsigned long long ull;


int main() {
	int n;
	int count = 0;
	cin >> n;
	if (n % 2 == 1)++n;
	for (int i = 1; i < n / 2; ++i) {
		++count;
	}
	cout << count << endl;
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    int m = 100; // unit:k
    for(int i = 0; i < n; i++){
        m = (int)ceil(m * 1.05);
    }
    cout << m << "000" << endl;
    return 0;
}

Measured memory_bytes: 1168
while True:
  try:
    caesar = input()
  except EOFError:
    break
  for i in range(26):
    raw_letters = []
    for j in range(len(caesar)):
      if caesar[j] == " " or caesar[j] == ".":
        raw_letters.append(caesar[j])
      else:
        letter = ord(caesar[j])+(i+1)
        # 122 is ASCII 'z'
        if letter > 122:
          raw_letters.append(chr(letter-26))
        else:
          raw_letters.append(chr(letter))
    raw_strings = "".join(raw_letters)
    if ('the' in raw_strings) or ('this' in raw_strings) or ('that' in raw_strings):
      print(raw_strings)
      break


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

int main()
{
ll n , m ;
cin >> n >> m ;
string s , t ;
cin >> s >> t ;
ll a=__gcd(n,m);
rep(i,a){
  if(s[n*i/a]!=t[m*i/a]){
    cout << -1 << endl;
    return 0;
  }
}

cout << n*m/a << endl;
return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const long double PI =(acos(-1));

int main(){
    int n,x;
    int s=1;
    while(s){
        int cnt=0;
        cin >> n >> x;
        if(n==0 && x==0){
            s=0;
            break;
        }
        for(int i=1;i<=n;++i){
            for(int j=i+1;j<=n;++j){
                for(int k=j+1;k<=n;++k){
                    if(i+j+k==x) cnt++;
                }
            }
        }
        cout << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 3080
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define alli(a, n, k) (a+k),(a+n+k)
#define REP(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)
#define REPI(i, a, b, k) for(__typeof(a) i = a;i > b;i -= k)
#define REPITER(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)

#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
template<class T> inline T gcd(T x, T y) { if (!y) return x; return gcd(y, x%y);}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector< pair<int, int> > VPII;
typedef vector< pair<int, PII > > VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;
int main(int argc, char* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    ll dp[n+1][k+1];
    int a[n+1];
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=n;++i)
    {
        cin>>a[i];
        dp[i][0]=1;
    }
    dp[0][0]=1;

    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=k;++j)
        {
            dp[i][j]=(dp[i][j-1]+dp[i-1][j])%MOD;
            if(j-a[i]>=1)
            dp[i][j]=(dp[i][j]-dp[i-1][j-a[i]-1]+MOD)%MOD;
            //cout<<dp[i][j]<<' ';
        }
        //cout<<endl;
    }
    cout<<dp[n][k]%MOD;

    return 0;
}

Measured memory_bytes: 79104
# include<iostream>
# include<algorithm>
# include<cctype>
# include<cstdio>
# include<cstring>
# include<sstream>
# include<cmath>
# include<limits.h>
using namespace std;
int main()
{
      int n, r;
      cin >> n >> r;
      if (n>=10) cout << r << endl;
      else cout << r+100*(10-n) << endl;
      return 0;
}



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

int main() {
  int n;
  while ( cin >> n ) {
    int dp[ (int)2e5+5 ]; fill( dp, dp+(int)2e5+5, 1 << 30 );
    dp[0] = 0;
    
    for (int i = 0; i < n; ++i) {
      dp[ i+1 ] = min( dp[ i+1 ], dp[i]+1 );
      dp[ i+6 ] = min( dp[ i+6 ], dp[i]+1 );
      dp[ i+9 ] = min( dp[ i+9 ], dp[i]+1 );
      dp[ i+36 ] = min( dp[ i+36 ], dp[i]+1 );
      dp[ i+81 ] = min( dp[ i+81 ], dp[i]+1 );
      dp[ i+216 ] = min( dp[ i+216 ], dp[i]+1 );
      dp[ i+729 ] = min( dp[ i+729 ], dp[i]+1 );
      dp[ i+1296 ] = min( dp[ i+1296 ], dp[i]+1 );
      dp[ i+6561 ] = min( dp[ i+6561 ], dp[i]+1 );
      dp[ i+7776 ] = min( dp[ i+7776 ], dp[i]+1 );
      dp[ i+46656 ] = min( dp[ i+46656 ], dp[i]+1 );
      dp[ i+59049 ] = min( dp[ i+59049 ], dp[i]+1 );
    }
    cout << dp[n] << '\n';
  }
  return 0;
}

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

using namespace std;

struct node {
	int left;
	int right;
};

int n,ind,nop;
vector<node> tree;
vector<int> pre,in;

void reconstruct(int left, int right) {
	if (ind > n || left == right) {
		return;
	}
	int rind,root = pre[ind];
	++ind;
	for (int i = left; i < right; ++i) {
		if (root == in[i]) {
			if (i > left) {
				tree[root].left = pre[ind]; 
			}
			else {
				tree[root].left = -1;
			}
			rind = i;
			break;
		}
	}
	reconstruct(left,rind);
	if (rind < right-1) {
		tree[root].right = pre[ind];
		reconstruct(rind+1,right);
	}
	else {
		tree[root].right = -1;
	}
	return;
}

void postorder_walk(int now) {
	if (now < 0) {
		return;
	}
	postorder_walk(tree[now].left);
	postorder_walk(tree[now].right);
	cout << now+1;
	++nop;
	if (nop < n) {
		cout << " ";
	}
	else {
		cout << endl;
	}
	return;
}


int main(void) {
	cin >> n;
	tree = vector<node>(n);

	pre = in = vector<int>(n);
	for (int i = 0; i < n; ++i) {
		cin >> pre[i];
		--pre[i];
	}
	for (int i = 0; i < n; ++i) {
		cin >> in[i];
		--in[i];
	}

	ind = 0;
	reconstruct(0,n);
	nop = 0;
	postorder_walk(pre[0]);

	return 0;
}



Measured memory_bytes: 3168
#include<iostream>
#include<vector>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define arep(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    vector<int> row, col;
    rep(i, 1, 12) {
        row.push_back(8 * (i % 11));
    }
    rep(i, 1, 6) {
        col.push_back((9 * (i + 1)) % 11);
    }
    ll ans = 0;
    rep(i, 0, min(11LL, N - 2)) rep(j, 0, 5) {
        int now_mod = (row[i] + col[j]) % 11;
        if (now_mod == K) {
            ans += (N - 2) / 11;
            if (((N - 2) % 11) && i + 1 <= (N - 2) % 11) {
                ++ans;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
int n,m,a,b;
cin>>n>>m>>a>>b;

rep(i,0,n-1)
{
	
	rep(j,0,m-1)
	{
		int x=0;
		if(i>=b)x^=1;
		if(j>=a)x^=1;
		ol(x);
	}
	on;
}

return 0;
}



Measured memory_bytes: 1280
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <functional>
#include <unordered_map>
#include <set>

#include <cassert>
using namespace std;

int main(void){

	string s;
	cin >> s;
	vector<vector<short>> n(s.size()+2);

	int dx,dy;
	cin >> dx >> dy;

	int ofx=0;
	int i;
	for(i=2;i<n.size();++i){
		int si_now = i-2;
		if(s[si_now]=='T'){
			dx = abs(dx);
			dy = abs(dy);
			i+=1;
			break;
		}else{
			dx-=1;
		}
	}
	
	int d = 1; //0=x,1=y,最初は1回方向転換済みなのでy
	int ix=1,iy=0;
	n[0].push_back(0); //y
	n[1].push_back(0); //x
	for(;i<n.size();++i){
		int si_now = i-2;
		if (s[si_now]=='T'){
			d = 1 - d;
		}else{ // 'F'
			auto id = (d==0)?ix:iy;
			auto dd = (d==0)?dx:dy;
			if(s[si_now-1]=='T'){
				set<short> nnext;
				for(int k=0;k<n[id].size();++k){
					const auto &v = n[id][k];
					auto in1=v+1,in2=v-1;
					nnext.insert(in1);
					nnext.insert(in2*-1);
				}
				n[i].reserve(nnext.size());
				for(auto it=nnext.begin();it!=nnext.end();++it){ n[i].push_back(*it); }
			}else{
				n[i].resize(n[i-1].size());
				for(int k=0;k<n[i].size();++k){
					const auto &v = n[id][k];
					n[i][k] = v+1;
				}
				sort(n[i].begin(),n[i].end());
				n[i].erase( unique(n[i].begin(), n[i].end()), n[i].end());
			}
			if(d==0){ ix=i; }else{ iy=i; }
		}
	}

	if(binary_search(n[ix].begin(),n[ix].end(),dx) && binary_search(n[iy].begin(),n[iy].end(),dy)){
		std::cout << "Yes" << endl;
	}else{
		std::cout << "No" << endl;
	}

	return 0;
}

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

#define endl "\n"

#define pi 2*acos(0)
#define INF 1e16
#define MIN 1e-9
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))
#define m_p make_pair
#define p_b push_back
#define ff first
#define ss second
#define n_p(a) next_permutation(all(a))
#define all(v) v.begin(),v.end()
#define ii pair<int, int>
#define vi vector<int>
#define vii vector<ii>
#define vvi vector<vi>
#define rev(s) reverse(all(s))
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define mem(a,k) memset(a,k,sizeof a)
#define REP(i, a, b) for (int i = int(a); i <= int(b); i++)
#define u_b(X,V) upper_bound(X.begin(),X.end(),V)
#define l_b(X,V) lower_bound(X.begin(),X.end(),V)
#define cnt(s,c) count(all(s),c)

//bitwise helpers
#define isOn(S, j) (S & (1 << j))
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define lowBit(S) (S & (-S))
#define setAll(S, n) (S = (1 << n) - 1)

#define modulo(S, N) ((S) & (N - 1))
#define isPowerOfTwo(S) (!(S & (S - 1)))
#define nearestPowerOfTwo(S) ((int)pow(2.0, (int)((log((double)S) / log(2.0)) + 0.5)))
#define turnOffLastBit(S) ((S) & (S - 1))
#define turnOnLastZero(S) ((S) | (S + 1))
#define turnOffLastConsecutiveBits(S) ((S) & (S + 1))
#define turnOnLastConsecutiveZeroes(S) ((S) | (S - 1))

using namespace std;

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

    int t;

    //cin >> t;
    t = 1;
    for(int test = 1; test <= t ; test++) {
        string s;
        cin >> s;
        int n = s.size();
        int res = 0;
        for(int i = 0; i < n; i++) {
            for(int j = i; j < n; j++) {
                string str = s.substr(i, j - i + 1);
                bool cond = true;
                for(int k = 0; k < str.size(); k++) {
                    if(str[k] != 'A' && str[k] != 'C' && str[k] != 'G' && str[k] != 'T') {
                        cond = false;
                        break;
                    }
                }
                if(cond)
                    res = max(res, str.size());
            }
        }
        cout << res << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main() {
    int n;
    while ( scanf("%d", &n) != EOF ) {
          int x = 0;
          for (int a = 0; a < 10; a++) {
              for (int b = 0; b < 10; b++) {
                  for (int c = 0; c < 10; c++) {
                      for (int d = 0; d < 10; d++) {
                          if ( (a + b + c + d) == n ) {
                               x++;
                          }
                      }
                  }
              }
          }
          printf("%d\n", x);
    }
    return 0; 
}

Measured memory_bytes: 1024
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N = INT()
S = input()
 
tmp_W = 0
tmp_E = 0
 
cnt = [0]*len(S)
for i in range(len(S)):
	if S[i] == "W":
		tmp_W += 1
	cnt[i] += tmp_W
 
for i in range(len(S)-1, -1, -1):
	if S[i] == "E":
		tmp_E += 1
	cnt[i] += tmp_E
 
print(min(cnt)-1)

Measured memory_bytes: 19496
#include<stdio.h>
main()
{
    int a,i, b , c, d, e, f, count;
    scanf ("%d %d %d", &a, &b, &c);
    count=0;
    for (i=a; i<=b; i++)
    {
        if(c%i==0) count++;


    }
      printf("%d\n", count);
}



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

using namespace std;

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

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

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

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int n;
  cin>>n;
  vi a(n);
  REP(i,n)cin>>a[i];
  sort(ALL(a));
  int x = a.back(); a.pop_back();
  int best = 0;
  REP(i,a.size()){
    int y = a[i];
    if(abs(2*y-x) < abs(2*best-x))best = y;
  }
  printf("%d %d\n",x,best);
  return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>

typedef long long int lli;
lli s[20000], t[2000];

int main(void) {
    int n,q;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
        scanf("%lld",&s[i]);
    scanf("%d",&q);
    for(int i=0; i<q; i++)
        scanf("%lld",&t[i]);

    std::sort(s, s+n);
    std::sort(t, t+q);

    lli *ps=s, *pt=t;
    int res=0;
    while(ps<s+n && pt<t+q) {
        if(*ps == *pt)
            res++, ps++, pt++;
        else if (*ps < *pt)
            ps++;
        else
            pt++;
    }
    printf("%d\n",res);

    return 0;
}

Measured memory_bytes: 2840
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

double calc_dist( double x1, double x2, double y1, double y2) {
    double diff_x = x1 - x2;
    double diff_y = y1 - y2;
//    cout << diff_x << " " << diff_y << endl;
    return sqrt( diff_x * diff_x + diff_y * diff_y );
}

int main(){
    int n;
    cin >> n;
    vector<pair<double, double>> xy(n);
    rep(i, n) {
        double x, y;
        cin >> x >> y;
        xy[i] = {x, y};
    }
    vector<int> num(n);
    double sum = 0.0;
    rep(i, n) num[i] = i;
    int pattern_num = 0;
    do {
        rep(i, n-1) {
            sum += calc_dist( xy[num[i]].first, xy[num[i+1]].first, xy[num[i]].second, xy[num[i+1]].second );
        }
//        cout << sum << endl;
//        for ( auto tmp_num : num ) {
//            cout << tmp_num << " ";
//        }
//        cout << endl;
        ++pattern_num;
    } while(next_permutation(num.begin(), num.end()));
//    cout << pattern_num << endl;
    printf("%.7lf\n", sum / (double)pattern_num);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
#include<assert.h>
#include<random>
using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


//BELOW
//-----CODE------//

void solve(void)
{
  int N,M; cin>>N; cin>>M;
  vector<int> vec (M,0);
  for (int i = 0; i < M; i++)
  {
    cin>>vec[i];
  }
  vector<int> dist (M-1,0);
  sort(ALL(vec));
  for (int i = 1; i < M; i++)
  {
    dist[i-1] = vec[i] - vec[i-1];
  }
  sort(ALL(dist));
  // DEBUG(dist);
  // N--;
  int res = 0;
  for (int i = 0; i < max(0LL,M - N ); i++)
  {
    res += dist[i];
  }
  cout<<res<<endl;
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


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

int main(){
    int A,B,a(0),b(0),x; cin >> A >> B >> x;
    if(x%500 != 0 ){
        x = (x/500+1)*500;
    }
    
    if(A<B){
        a = x/1000;
        if(x%1000 != 0){
            a++;
        }

    }else if(A>2*B){
        b = x/500;

    }else{
        if((x/500)%2 != 0){
            x--; b++;
        }
        a = x/1000;
    }

    cout << (a*A)+(b*B) << endl;
}


Measured memory_bytes: 3124
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace Atcoder
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var input = ReadTexts();
            string result;

            long takahasiHP = input[0].ToLong();
            long takahasiATK = input[1].ToLong();
            long aokiHP = input[2].ToLong();
            long aokiATK = input[3].ToLong();

            if (((aokiHP / takahasiATK) + (aokiHP % takahasiATK == 0 ? 0 : 1)) <= ((takahasiHP / aokiATK) + (takahasiHP % aokiATK == 0 ? 0 : 1)))
            {
                result = "Yes";
            }
            else
            {
                result = "No";
            }

            return result;
        }

        #region Console

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }

        #endregion
    }

    public static class CastExtention
    {
        public static long ToLong(this string a) { return long.Parse(a); }
    }
}



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

int main(){
    ll x;
    cin >> x;
    ll money = 100;
    for(int i = 1; ; i++){
        money += money / 100;
        if(money >= x){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3636
sa = input()
sb = input()
sc = input()
t = 'a'
s = 0
while s == 0:
  if t == 'a':
    if len(sa) == 0:
      print('A')
      break
    t = sa[0]
    sa = sa[1:]
  elif t == 'b':
    if len(sb) == 0:
      print('B')
      break
    t = sb[0]
    sb = sb[1:]
  else:
    if len(sc) == 0:
      print('C')
      break
    t = sc[0]
    sc = sc[1:]

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second

const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll n;
	cin >> n;
	Vec c(n-1), s(n-1), f(n-1);
	rep(i, n-1) cin >> c[i] >> s[i] >> f[i];

	rep(i, n-1){
		ll ans = s[i]+c[i];
		REP(j, i+1, n-1){
			if(ans < s[j]) ans = s[j];
			else while(ans%f[j]) ans++;
			ans += c[j];
		}
		co(ans);
	}
	co(0);

	return 0;
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args) {
            string Key = Console.ReadLine();
            string Target = Console.ReadLine();
            Key += Key;
            Console.WriteLine(Key.Contains(Target) ? "Yes" : "No");
        }
    }
}


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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

  ll n, h, w;
  cin >> n >> h >> w;
  cout << (n-h+1) * (n-w+1) << endl;

  return 0;
}

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

int main()
{
	int N = 0, ans = 0;
	int b = 0;

	std::cin >> N;
	std::vector<int> d(N);

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

	for (int i = N; i > 1; i--)
	{
		b += d[i - 1];
		ans += d[i - 2] * b;
	}

	std::cout << ans << std::endl;

	return 0;
}

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

int main(){
    // 制約見て！！！デカかったらlong longにすること！
    string s;
    cin >> s;
    int s1 = stoi(s.substr(0,2));
    int s2 = stoi(s.substr(2,4));
    
    bool yymm = s2 <=12 && s2>0;
    bool mmyy = s1 <=12 && s1>0;

    if(yymm && mmyy){
        cout << "AMBIGUOUS" <<endl;
    }else if(yymm){
        cout << "YYMM" << endl;
    }else if(mmyy){
        cout << "MMYY" << endl;
    }else{
        cout << "NA" << endl;
    }
}

Measured memory_bytes: 256
N,W=map(int,input().split())
wv=[list(map(int,input().split())) for _ in range(N)]
dp=[[0 for _ in range(W+1)] for _ in range(N+1)]
for i in range(1,N+1):
    for j in range(1,W+1):
        if wv[i-1][0]<=j:
            dp[i][j]=max(dp[i-1][j],dp[i-1][max(0,j-wv[i-1][0])]+wv[i-1][1])
        else:
            dp[i][j]=dp[i-1][j]
print(dp[-1][-1])

Measured memory_bytes: 217916
use std::cmp::min;
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let mut itr = s.split_whitespace().map(|e| e.parse().unwrap());

    let h: usize = itr.next().unwrap();
    let w: usize = itr.next().unwrap();
    let k: usize = itr.next().unwrap();
    let k = k as u64;

    let mut v = vec![Vec::new(); h];

    for row in 0..h {
        let mut s = String::new();
        stdin().read_line(&mut s).ok();
        v[row] = s
            .trim()
            .chars()
            .map(|e| e.to_digit(10).unwrap() as u64)
            .collect();
    }

    let g: u64 = 1 << h - 1;
    let mut ans = 10000;

    'outer: for i in 0..g {
        let mut table = [0u64; 11];
        let mut tvert = 0;
        for col in 0..w {
            let mut t = [0u64; 11];
            let mut idx = 0;
            for row in 0..h {
                t[idx] += v[row][col];
                if 0 < (i >> row) & 1 {
                    idx += 1;
                }
            }

            for &j in &t {
                if j > k {
                    continue 'outer;
                }
            }

            tvert += f(&mut table, &t, k);
        }

        ans = min(ans, tvert + i.count_ones() as u64);
    }

    println!("{}", ans);
}

fn f(table: &mut [u64; 11], t: &[u64; 11], k: u64) -> u64 {
    for i in 0..table.len() {
        if table[i] + t[i] > k {
            *table = *t;

            return 1;
        }
    }

    for i in 0..table.len() {
        table[i] += t[i];
    }

    0
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int N; cin >>N;
  vector<ll> A(N),B(N); rep(i, N) cin >>A[i] >>B[i];
  ll res = 0;
  for (int i=N-1; i>=0; i--){
    A[i] += res; A[i] %= B[i];
    res += (B[i] - A[i]) % B[i];
  }
  cout <<res <<endl;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		long n = 0;
		long result = 0;

		n = N / K;
		result = n * n * n;

		if(K % 2 == 0) {
			n = (N + K / 2) / K;
			result += n * n * n;
		}

		System.out.println(result);

		return;
	}
}


Measured memory_bytes: 22868
# -*- coding: utf-8 -*-

n = int(input())

lucas = [0] * 100
lucas[0] = 2
lucas[1] = 1

for i in range(2,n+1):
    lucas[i] = lucas[i-1] + lucas[i-2]
    if n == i:
        print(lucas[i])
        break

if n == 1:
    print(1) 


Measured memory_bytes: 2940
n=int(input())
l=list(map(int,input().split()))
count=0
new=[]
s=set()
d={}
for i in range(0,len(l)):
    new.append(i+1-l[i])
    s.add(i+1+l[i])
    if i+1+l[i] in d.keys():
        d[i+1+l[i]]+=1
    else:
        d[i+1+l[i]]=1
for i in range(0,len(new)):
    if new[i] in s:
        count+=d[new[i]]
print(count)

Measured memory_bytes: 59572
def main48():
    n = int(input())
    k = int(input())
    data = input().split()
    x = []
    for i in range(n):
        x.append(int(data[i]))
    result = 0
    for i in range(n):
        if x[i] < k-x[i]:
            result = result + x[i] * 2
        else:
            result = result + (k-x[i]) * 2
    print(result)

if __name__ == "__main__":
    main48()

Measured memory_bytes: 3064
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iomanip>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

// 1-indexed
template <class T, class Op, T unit>
struct Bit {
  int n;
  vector<T> dat;
  Op op;
  Bit(int n) : n(n), dat(n + 1, unit) {
  }
  Bit(const vector<T> &arr) : n(arr.size()), dat(arr.size() + 1) {
    copy(arr.begin(), arr.end(), dat.begin() + 1);
    for(int i=1; i<n; i++) {
      dat[i + (i & -i)] = op(dat[i + (i & -i)], dat[i]);
    }
  }
  void operate(int k, T a) {
    while(k <= n) {
      dat[k] = op(dat[k], a);
      k += k & -k;
    }
  }
  T accum(int k) {
    T sum = unit;
    while(k > 0) {
      sum = op(sum, dat[k]);
      k -= k & -k;
    }
    return sum;
  }
};

struct line {
  double A;
  double B;
  double C;
};

const int ITER = 70;

int inversion(const vector<pair<double, int>> &ps) {
  int N = ps.size();
  Bit<int, plus<int>, 0> bit(N);
  int inv = 0;
  FOR(p,ps) {
    inv += bit.accum(p.second + 1);
    bit.operate(p.second + 1, 1);
  }
  return inv;
}

double find_x(const vector<line> &ls, int idx) {
  int N = ls.size();
  double l = -2e8;
  double r = 2e8;
  vector<pair<double, int>> ps(N);
  REP(i,0,ITER) {
    double x = (l + r) / 2;
    REP(i,0,N) {
      const line &l = ls[i];
      ps[i] = {(l.C - l.A * x) / l.B, i};
    }
    sort(ps.rbegin(), ps.rend());
    int inv = inversion(ps);
    if(inv < idx) {
      l = x;
    } else {
      r = x;
    }
  }
  return l;
}

double find_y(const vector<line> &ls, int idx) {
  int N = ls.size();
  double l = -2e8;
  double r = 2e8;
  vector<pair<double, int>> ps(N);
  REP(i,0,ITER) {
    double y = (l + r) / 2;
    REP(i,0,N) {
      const line &l = ls[i];
      ps[i] = {(l.C - l.B * y) / l.A, i};
    }
    sort(ps.rbegin(), ps.rend());
    int inv = inversion(ps);
    if(inv < idx) {
      l = y;
    } else {
      r = y;
    }
  }
  return l;
}
  

int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<line> ls(N);
  FOR(l,ls) {
    cin >> l.A >> l.B >> l.C;
  }
  int idx = (N * (N-1) / 2 + 1) / 2;
  sort(ls.begin(), ls.end(), [](const line &l1, const line &l2) {
      return l1.A / l1.B < l2.A / l2.B;
    });
  double x = find_x(ls, idx);
  sort(ls.begin(), ls.end(), [](const line &l1, const line &l2) {
      return l1.B / l1.A < l2.B / l2.A;
    });
  double y = find_y(ls, idx);
  cout << setprecision(15) << x << " " << y << endl;

  return 0;
}


Measured memory_bytes: 2048
import java.util.*;

class Main{
    static long digits(long n){
        long res = 0;
        while(n > 0){
            res++;
            n /= 10; 
        }
        return res;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();

        long f = 0;
        long ans = Long.MAX_VALUE;
        for(long i = 1; i*i <= N; i++){
            if(N % i == 0){
            f = Math.max(digits(i), digits(N / i));
            ans = Math.min(ans, f);
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <cstdio>
#include <algorithm>

using i8 = std::int8_t;
using u8 = std::uint8_t;
using i16 = std::int16_t;
using u16 = std::uint16_t;
using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;
using isize = std::intptr_t;
using usize = std::uintptr_t;


i32 cnt[100001];

auto main() -> i32 {
	i64 n;
	scanf("%ld", &n);
	i64 ans = 0;
	for (i32 i = 0; i < n; ++i) {
		i32 a;
		scanf("%d", &a);
		cnt[a] += 1;
		ans += i64(a);
	}
	i32 q;
	scanf("%d", &q);
	for (i32 i = 0; i < q; ++i) {
		i32 b, c;
		scanf("%d%d", &b, &c);
		ans = ans - i64(b) * i64(cnt[b]) + i64(c) * i64(cnt[b]);
		cnt[c] += cnt[b];
		cnt[b] = 0;
		printf("%ld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 2108