akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

void Main(){
    int x; cin >> x;
    cout << (x ? 0 : 1) << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 3644
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	int n;
	cin>>n;
	vector<LL> a(n);
	FOR(i,0,n)cin>>a[i];
	sort(a.begin(),a.end());
	vector<pll> op(n-1);
	LL ans;
	if(a[n-1]<=0){//all 負
		op[0]=MP(a[n-1],a[n-2]);
		LL t=a[n-1]-a[n-2];
		FOR(i,0,n-2){
			op[i+1]=MP(t,a[n-3-i]);
			t=t-a[n-3-i];
		}
		ans=t;
	}else if(a[0]>=0){//all 正
		if(n==2){
			cout<<a[1]-a[0]<<endl;
			cout<<a[1]<<" "<<a[0]<<endl;
			return 0;
		}else{
			op[0]=MP(a[0],a[2]);
			LL t=a[0]-a[2];
			FOR(i,3,n){
				op[i-2]=MP(t,a[i]);
				t=t-a[i];
			}
			op[n-2]=MP(a[1],t);
			t=a[1]-t;
			ans=t;
		}
	}else{
		int pos=n-1;
		FOR(i,0,n-1){
			if(a[i]<=0)pos=i+1;
		}
		cerr<<pos<<endl;
		if(pos==n-1){
			LL t=a[n-1]-a[0];
			op[0]=MP(a[n-1],a[0]);
			FOR(i,1,n-1){
				op[i]=MP(t,a[i]);
				t=t-a[i];
			}
			ans=t;
		}else{
			LL t=a[0]-a[n-2];
			op[0]=MP(a[0],a[n-2]);
			int idx=1;
			FORD(i,n-2,pos){
				op[idx]=MP(t,a[i]);
				t=t-a[i];
				idx++;
			}
			op[idx]=MP(a[n-1],t);
			t=a[n-1]-t;
			idx++;
			FOR(i,1,pos){
				op[idx]=MP(t,a[i]);
				t=t-a[i];
				idx++;
			}
			ans=t;

		}

	}
	cout<<ans<<endl;
	FOR(i,0,n-1){
		cout<<op[i].ST<<" "<<op[i].ND<<endl;
	}
	return 0;
}


Measured memory_bytes: 4224
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
# fractions.gcd() を用いること
# math.log2()はatcoderでは対応していない．留意せよ．

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    a, b, c = map(int, input().strip().split())
    # 4ab < (c-a-b)**2
    if 4*a*b < (c-a-b)**2 and c-a-b >= 0:
        print("Yes")
        return
    else:
        print("No")
        return


if __name__ == '__main__':
    main()


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,b) FOR(i,0,b)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,b) ROF(i,0,b)

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define MOD(x,m) ((x)%(m)+(m))%(m)

typedef vector<int> vi;
typedef vector<vi> vvi;

const vvi nul = {{1},{1}}, e = {{1,0},{0,1}};
const int P = 998244353, maxn = 410;

int n, a[maxn], pow2[maxn], C[maxn][maxn];

void print(int i) {printf("%d",i);}
template<typename T>
void print(vector<T> v) {
	printf("{");
	for (auto i: v) print(i),printf(",");
	printf("}\n");
}

vvi dfs(int l, int r, int b) {
	int len = r-l+1;
	if (l == r) return nul;
	if (r-l == 1 && a[l] == b) return e;
	vvi dp = vvi(2, vi(len));
	FOR(i,l,r) if (a[i] == b) {
		auto dp1 = dfs(l, i, b), dp2 = dfs(i+1, r, b);
//		printf("%d %d %d\n", l, r, b);
//		print(dp1), print(dp2);
		F0R(j,i-l+1) F0R(k,r-i) {
			dp[0][j+k] = (dp[0][j+k]+1ll*dp1[0][j]*dp2[0][k])%P;
			dp[1][j+k+1] = (dp[1][j+k+1]+1ll*dp1[1][j]*dp2[1][k])%P;
		}
//		print(dp);
		return dp;
	}
	auto dp1 = dfs(l, r, b+1);
	F0R(i,len) dp[0][i] = dp1[1][i];
	F0R(i,len) FOR(j,i,len) {
		dp[1][i] = (dp[1][i]+1ll*dp1[1][j]*C[j][i]%P*pow2[len-1-j])%P;
	}
	F0R(i,len) FOR(j,i,len) {
		dp[0][i] = (dp[0][i]+1ll*dp1[0][j]*C[j][i]%P*(pow2[len-1-j]-(i==j)))%P;
	}
//	printf("%d %d %d\n", l, r, b);
//	print(dp);
	return dp;
}

int main() {
	C[0][0] = 1;
	FOR(i,1,maxn)
		F0R(j,i+1) {
			C[i][j] = j?(C[i-1][j-1]+C[i-1][j])%P:1;
//			printf("C[%d][%d] = %d\n", i, j, C[i][j]);
		}
	pow2[0] = 1;
	FOR(i,1,maxn) pow2[i] = 2*pow2[i-1]%P;

	cin >> n;
	F0R(i,n) cin >> a[i];
	auto dp = dfs(0, n, 0);
	cout << dp[0][0] << endl;
}


Measured memory_bytes: 3072
#include <iostream>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <stack>
#include <cstdio>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <iterator>
#include <sstream>
#define popcount(x) __builtin_popcount(x)
#define oddparity(x) __builtin_parity(x)
#define clz(x) __builtin_clz(x)
#define ctz(x) __builtin_ctz(x)
#define sf scanf
#define pf printf
#define ll long long int
using namespace std;

vector<int>value;
int i, root, c;
ll n;

int digit_count(int x)
{
    c = 0;
    while (x) {
        c++;
        x /= 10;
    }
    return c;
}

int main()
{
    sf("%lld", &n);
    root = sqrt(n);
    for (i = root; i > 0; i--) {
        if (n % i == 0) {
            value.push_back(max(digit_count(i), digit_count(n/i)));
        }
    }
    pf("%d\n", *min_element(value.begin(), value.end()));
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;


int main(){
    int n, x;
    cin >> n >> x;
    int M = 0, minM = 1001;
    for(int i = 0; i < n; i++){
        int y;
        cin >> y;
        M += y;
        minM = min(minM, y);
    }
    x -= M;
    cout << n + x / minM << endl;
}

Measured memory_bytes: 256
N, M, Q = map(int, input().split())
train = [[0]*(N+1) for _ in range(N+1)]

for i in range(M):
  a, b = map(int, input().split())
  train[a][b] += 1
  
for i in range(1, N+1):
  for j in range(1, N+1):
    train[i][j] += train[i][j-1]
    
for i in range(1, N+1):
  for j in range(1, N+1):
    train[j][i] += train[j-1][i]


for i in range(Q):
  l, r = map(int, input().split())
  print(train[r][r]-train[l-1][r]-train[r][l-1]+train[l-1][l-1])

Measured memory_bytes: 57304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a-1; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define rALL(x) x.rbegin(), x.rend()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

vector<vector<char>> g;
int main(){
    ll n;   cin >> n;
    vector<ll> dp(n+1, LINF);
    dp[0] = 0;
    int a[3] = {9, 6, 1};
    rep(i, 3){
        ll obj=a[i];
        while(obj<=n){
            rep(j, n+1){
                if(obj<=j) dp[j] = min(dp[j], dp[j-obj]+1);
            }
            if(obj==1) break;
            obj *= a[i];
        }
    }
    
    cout << dp[n] << endl;
}


Measured memory_bytes: 3960
#include<iostream>
using namespace std;
int main()
{
	long t,**q,**p,i,min,*y,flag,r,*l,c,max,*s,o,f,k,u;
	while(cin >> t && t!= 0)
	{
		q = new long*[t];
		p = new long *[t];
		y = new long[t];
		l = new long[t];
		s = new long[t];
		for( i=0; i<t;i++)
		{
			q[i] = new long[t];
			p[i] = new long[t];
		}

			for( r = 0; r< t; r++)
					for( c = 0; c < t;c++)
					{
						p[r][c] = 0;
						cin >> q[r][c];
					}
		for( r = 0; r < t; r++)
		{
			o=0;
			min = 1000000;
			l[o] = r;
			y [o]= 0;
			
		for( c = 0; c < t;c++)
		{
			if(q[r][c] <= min)
			{
				if(min == q[r][c])
				{
					o++;
				min = q[r][c];
				l[o]= r;
				y[o] =c;
				}
				else 
				{
				o = 0;
				min = q[r][c];
				l[o]= r;
				y[o] =c;
				}
			}
		}
		for(f = 0; f <= o;f++)
		p[l[f]][y[f]]++;
		}
		for( c = 0; c< t; c++)
		{
		
			max= -1;
			o=0;
			l[o] = 0;
			y[o] = c;
		for( r = 0; r < t;r++)
		{
			if(q[r][c] >= max)
			{
				if(max == q[r][c])
				{
					o++;
			      max = q[r][c];
				  l[o]= r;
				  y[o] =c;
				}
				else
				{
				o = 0;
				max = q[r][c];
				  l[o]= r;
				  y[o] =c;
				}
			}
		}
		for(f = 0; f <= o;f++)
		p[l[f]][y[f]]++;
		}
			flag = 0;
			long count = 0;
			for(c = 0 ; c < t; c++)
				for(r =0; r<t;r++)
				{
					if(p[c][r] == 2 )
					{
						for( u = 0; u < count ;u++)
						{
					     if (s[u] == q[c][r])
							 break;
						}
						if(u >= count)
						{
							flag++;
							s[count] = q[c][r];
							count++;
						    
						}
					}
				}
				if(flag == 0)
					cout << 0 << endl;
				else
				{
                    for(k = 0; k < count;k++)
					{
						cout << s[k];
						if(k < count -1)
							cout << " ";
						else
					   cout << endl;
					}
				}
				}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;

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;}

//pow(llpow,modpow)
template<class T> ll llpow(T x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main(){
    int n;
    cin>>n;
    ll res=0;
    rep(i,n)res+=i;
    cout<<res<<endl;
    return 0;
}




Measured memory_bytes: 384
#include<iostream>
using namespace std;
#define NUM 10	// ?±±?????°
#define TOP 3	// ??????TOP?????????????????????

int main(){
	int hight[NUM];	// ??\????????????
	int top[TOP];

	// ?????????????????????
	for(int i=0; i < NUM ; ){
		cin >> hight[i];
		// ?????¶ : 0 <= ?±±????????? <= 10000
		if(hight[i] < 0  ||  hight[i] > 10000){
			continue;
        }
        i++;
	}
    
	// ?????????????????????TOP???????????????
	top[0] = 0;
	for(int i=0; i < NUM ; i++){
		for(int j=0;j<TOP ; j++){
			// ???????????????????????????????????°???hight[i]???top[j]?????????????????\?????????
			if(hight[i] > top[j]){
				for(int k=TOP-1 ; k > j ; k--){
					top[k] = top[k-1];  // <- ????????§?????°?????????
				}
				top[j] = hight[i];
                break;
			}
		}
	}

	// ?????????TOP???????????????
	for(int i=0; i < TOP ; i++ ){
		cout << top[i] << '\n';
	}

	return 0;
}

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

#define pb push_back
#define all(a) (a).begin(), (a).end()

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

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

void solve() {
}

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int k; cin >> k;
    int ans = 0;
    for (int a = 1; a <= k; ++a) {
    	for (int b = 1; b <= k; ++b) {
    		for (int c = 1; c <= k; ++c) {
    			int g = __gcd(a, b);
    			g = __gcd(g, c);
    			ans += g;
    		}
    	}
    }

    cout << ans << "\n";
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <limits.h>
#define MAX_LENGTH 500000
int counter=0;
void Merge(int arr[], int left, int middle, int right)
{
    int n1 = middle - left;
    int n2= right - middle;
    int L[n1+1], R[n2+1];
    for(int i=0;i<n1;i++){L[i]=arr[left+i];}
    for(int i=0;i<n2;i++){R[i]=arr[middle+i];}
    L[n1] = INT_MAX;
    R[n2] = INT_MAX;
    int i=0;
    int j=0;
    for(int k=left;k<right;k++)
    {
        if(L[i]<=R[j])
        {
            arr[k] = L[i];
            i += 1;
        }
        else{
            arr[k] = R[j];
            j += 1;
        }
        counter++;
    }
}
void MergeSort(int arr[], int left, int right)
{
    if(left+1 < right)
    {
        int middle = (left + right)/2;
        MergeSort(arr, left, middle);
        MergeSort(arr, middle, right);
        Merge(arr, left, middle, right);
    }
}
int main() {
    int num=0;
    int A[MAX_LENGTH]={0};
    scanf("%d", &num);
    for(int i=0;i<num;i++){scanf("%d", &A[i]);}
    MergeSort(A, 0, num);
    for(int i=0;i<num;i++)
    {
        if(i!=num-1){printf("%d ", A[i]);}
        else{printf("%d\n", A[i]);}
    }
    printf("%d\n", counter);
    return 0;
}



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


/* Raiyan Noory Rady,CSE'17,RUET
Email:raiyannooryrady@gmail.com
Smile->Desire->Unity->Effort->Struggle->Success->Again smile :)
*/

#define ll long long int
#define pf push_front
#define mod  1000000007
#define inf  1000000000000000000
#define pi  acos(-1.0)
#define maxn  1000009
#define sorted(s)  sort(s.begin(),s.end())
#define sortarr(a) sort(a,a+n)
#define slc(n) scanf("%I64d", &n)
#define sl(n)  scanf("%lld", &n)
#define sf(n)  scanf("%lf", &n)
#define si(n)  scanf("%d", &n)
#define sch(n)  scanf(" %c", &n)
#define ss(n)  scanf("%s", n)
#define prf printf
#define pb  push_back
#define fr first
#define sc second
#define all(a)  a.begin(),a.end()
#define forl(n) for(i=0;i<n;i++)
/*STL library functions

sort(first_iterator, last_iterator) � To sort the given vector.

reverse(first_iterator, last_iterator) � To reverse a vector.

*max_element (first_iterator, last_iterator) � To find the maximum element of a vector.

*min_element (first_iterator, last_iterator) � To find the minimum element of a vector.

accumulate(first_iterator, last_iterator, initial value of sum) � Does the summation of vector elements

count(first_iterator, last_iterator,x) � To count the occurrences of x in vector.

find(first_iterator, last_iterator, x) � Points to last address of vector ((name_of_vector).end())
 if element is not present in vector.

binary_search(first_iterator, last_iterator, x) � Tests whether x exists in sorted vector or not.

lower_bound(first_iterator, last_iterator, x) � returns an iterator pointing to the first element in the range [first,last)
which has a value not less than �x�.

upper_bound(first_iterator, last_iterator, x) � returns an iterator pointing to the first element in the range [first,last)
 which has a value greater than �x�.

arr.erase(position to be deleted) � This erases selected element in vector and shifts and resizes the vector elements accordingly.

arr.erase(unique(arr.begin(),arr.end()),arr.end()) � This erases the duplicate occurrences in sorted vector in a single line.

distance(first_iterator,desired_position) � It returns the distance of desired position from the first iterator.
This function is very useful while finding the index.

next_permutation(first_iterator, last_iterator) � This modified the vector to its next permutation.

prev_permutation(first_iterator, last_iterator) � This modified the vector to its previous permutation.
*/

using namespace std;

int main()
{

    ll n,i;
    string s,t,res;
    cin>>n>>s>>t;

    for(i=0;i<n;i++)
        {
            res.pb(s[i]);
            res.pb(t[i]);
        }
        cout<<res<<endl;


    return 0;
}






Measured memory_bytes: 256
import fractions
from functools import reduce

N = int(input())
T = []
for i in range(N):
    T.append(int(input()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
    
print(lcm_list(T))

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

int main() {
    int n;
    while (cin >> n and n) {
        vector<string> v(n);
        rep(i, n) cin >> v[i];
        int m; cin >> m;
        bool s=false;
        rep(i, m) {
            string t;
            cin >> t;

            bool f=false;
            rep(j, n) {
                if (v[j] == t) {
                    f=true;
                    break;
                }
            }

            if (f) {
                if (s) {
                    cout << "Closed by " << t << endl;
                    s = !s;
                }
                else {
                    cout << "Opened by " << t << endl;
                    s = !s;
                }
            }
            else {
                cout << "Unknown " << t << endl;
            }

        }
    }
}

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

int main() {
    int k, s; cin >> k >> s;
    ll cnt = 0;
    for(int i=0; i<=k; i++){
        for(int j=0; j<=k; j++){
            if(s-i-j>=0 && s-i-j<=k){
                cnt++;
            }
        }
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque

class mf_graph:
    def __init__(self,N):
        self.N = N
        self.graph = [[] for _ in range(N)]
    
    def add_edge(self,v,w,cap):
        edge = [w,cap,None]
        edge[2] = rev_edge = [v,0,edge]
        self.graph[v].append(edge)
        self.graph[w].append(rev_edge)
    
    def bfs(self,s,t):
        self.level = [None]*self.N
        q = deque([s])
        self.level[s] = 0
        while q:
            v = q.popleft()
            nlevel = self.level[v]+1
            for w,cap,_ in self.graph[v]:
                if cap and self.level[w] is None:
                    self.level[w] = nlevel
                    q.append(w)
        return self.level[t] is not None
    
    def dfs(self,s,v,f):
        if v == s:
            return f
        for rev in self.it[v]:
            w,_,e = rev
            cap = e[1]
            if cap and self.level[w] is not None:
                if self.level[v] > self.level[w]:
                    d = self.dfs(s,w,min(f,cap))
                    if d:
                        e[1] -= d
                        rev[1] += d
                        return d
        return 0
    
    def flow(self,s,t,flow_limit=float('inf')):
        flow = 0
        while self.bfs(s,t):
            *self.it, = map(iter,self.graph)
            f = flow_limit
            while f:
                f = self.dfs(s,t,flow_limit-flow)
                flow += f
        return flow

    def min_cut(self,s):
        visited = [False]*self.N
        q = deque([s])
        while q:
            v = q.pop()
            visited[v] = True
            for w,cap,_ in self.graph[v]:
                if cap and not visited[w]:
                    q.append(w)


N,M = map(int, input().split())
S = [list(input()) for i in range(N)]
dc = mf_graph(N*M+2)

s =N*M
t = N*M+1
for i in range(N):
    for j in range(M):
        if (i+j) % 2 == 0:
            dc.add_edge(s,M*i+j,1)
        else:
            dc.add_edge(M*i+j,t,1)

for i in range(N):
    for j in range(M):
        if j+1 < M and S[i][j] == "." and S[i][j+1] == ".":
            u,v = M*i+j,M*i+j+1
            if (i+j) % 2 == 1:
                u,v = v,u
            dc.add_edge(u,v,1)
        if i+1 < N and S[i][j] == "." and S[i+1][j] == ".":
            u,v = M*i+j, M*(i+1)+j
            if (i+j) % 2 == 1:
                u,v = v,u
            dc.add_edge(u,v,1)

print(dc.flow(s,t,10**9))
for u in range(N*M+2):
    for v,cap,_ in dc.graph[u]:
        ui,uj = divmod(u,M)
        vi,vj = divmod(v,M)
        if (ui+uj) % 2 == 0 and cap == 0 and u != s and u != t and v != s and v!= t:
            if ui+1 == vi:
                S[ui][uj] = "v"
                S[vi][vj] = "^"
            elif ui == vi+1:
                S[ui][uj] = "^"
                S[vi][vj] = "v"
            elif uj+1 == vj:
                S[ui][uj] = ">"
                S[vi][vj] = "<"
            elif uj == vj+1:
                S[ui][uj] = "<"
                S[vi][vj] = ">"

for res in S:
    print("".join(res))


Measured memory_bytes: 86136
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int gcd(int a, int b)
{
    if(b == 0) return a;
    return gcd(b, a%b);
}
int main()
{
    int n, ans = 0;
    cin >> n;
    vector<int> a(n), f(n), b(n);
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
        f[i] = gcd(a[i], (i == 0 ? a[i] : f[i-1]));
    }
    for(int i = n - 1; i >= 0; i--){
        b[i] = gcd(a[i], (i == n-1 ? a[i] : b[i+1]));
    }
    for(int i = 0; i < n; i++){
        if(i == 0) ans = max(ans, b[i+1]);
        else if(i == n-1) ans = max(ans, f[i-1]);
        else ans = max(ans, gcd(f[i-1], b[i+1]));
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int N; cin >> N;
    vector<vector<int>> G(N);
    for(int i = 0; i < N - 1; ++i) {
        int a, b; cin >> a >> b;
        a--, b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    vector<vector<int>> V(2);
    vector<int> ans(N);
    auto dfs = [&](auto &&dfs, int cur, int pre, int col) -> void {
        V[col].push_back(cur);
        for(auto &to : G[cur]) {
            if(to != pre) dfs(dfs, to, cur, 1 - col);
        }
    };
    dfs(dfs, 0, 0, 0);
    if(V[0].size() > V[1].size()) swap(V[0], V[1]);
    if(V[0].size() <= N / 3) {
        int n = 3;
        for(auto &v : V[0]) {
            ans[v] = n;
            n += 3;
        }
        int m = n;
        n = 1;
        for(auto &v : V[1]) {
            ans[v] = n++;
            if(n % 3 == 0) n++;
            if(ans[v] > N) {
                ans[v] = m;
                m += 3;
            }
        }
    } else {
        int n = 1;
        for(auto &v : V[0]) {
            ans[v] = n;
            n += 3;
        }
        n = 2;
        for(auto &v : V[1]) {
            ans[v] = n;
            n += 3;
        }
        n = 3;
        for(auto &v : ans) {
            if(v > N) {
                v = n;
                n += 3;
            }
        }
    }

    for(auto &a : ans) cout << a << " ";
    cout << '\n';
    return 0;
}


Measured memory_bytes: 15988
#include<stdio.h>

int fib(int);
int F[45];

int main(){
  int n,i;

  scanf("%d",&n);

  for(i = 0; i <= n; i++)
    F[i] = 0;

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

  return 0;

}

int fib(int n){
  if(n == 0 || n == 1)
    return F[n] = 1;
  if(F[n] != 0)
    return F[n];
  return F[n] = fib(n-2) + fib(n-1);
}



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

int main(){
    int n;
    cin>>n;
    char s[100010];
    cin>>s;
    char tmp;
    int cnt=1;
    for(int i=0;i<n;i++){
        if(i==0){
            tmp=s[0];
        }
        else{
            if(s[i]!=tmp){
                cnt++;
                tmp=s[i];
            }
        }
    }
    cout<<cnt<<endl;
    return 0;
}

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

int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> s(M, vector<int>(N));
  rep(i, M){
    int k;
    cin >> k;
    s.at(i).resize(k);
    rep(j, k){
      cin >> s.at(i).at(j);
    }
  }
  vector<int> p(M);
  rep(i, M){
    cin >> p.at(i);
  }
  int ans = 0;
  for(int tmp=0; tmp<(1<<10); tmp++){
    bitset<10> o(tmp);
    bool x = true;
    rep(i, M){
      int on = 0;
      rep(j, s.at(i).size()){
        if(o.test(s.at(i).at(j)-1)){
          on++;
        }
      }
      if(on%2!=p.at(i)){
        x = false;
        break;
      }
    }
    if(x){
      ans++;
    }
  }
  int m = 1;
  rep(i, 10-N){
    m *= 2;
  }
  cout << ans/m;
  return 0;
}

Measured memory_bytes: 3544
INF=100000000
n=gets.to_i
h=gets.split.map(&:to_i)

dp=Array.new(100010,INF)

dp[1]=(h[1]-h[0]).abs
dp[0]=0
for i in 0..h.length-3
dp[i+2]=[dp[i+1]+(h[i+2]-h[i+1]).abs,dp[i]+(h[i+2]-h[i]).abs].min
end
#p dp[0..10]
p dp[h.length-1]

Measured memory_bytes: 20964
import java.util.Scanner;
public class Main {
    public static void main (String args[]){
    	Scanner str =new Scanner(System.in);
    	StringBuffer buf =new StringBuffer();
    	    int a = str.nextInt();
    	    int b = str.nextInt();
    	    int d = a/b;
    	    int r = a%b;
    	    double f =(double) a/b;
    	    buf.append(d).append(" ").append(r).append(" ").append(String.format("%6.5f",f));
    	    //String s=String.format("%.2f",r);
    	System.out.println(buf);
    	    //System.out.printf("%6.5f",f);
    }
}

Measured memory_bytes: 26220
#include<bits/stdc++.h>
using namespace std;
int main(){
   int n, i, j, ans=0;
   cin >> n;
   for(i=1;i<=n;i=i+2){
      int cnt=0;
      for(j=1;j<=sqrt(i)+1;j++){
         if(i%j==0) cnt+=2;
      }
      if(cnt==8) ans++;
   }
   cout << ans <<endl;
   return 0;
}



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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> F(M);
  for(int i=0; i<N; i++){
    int K;
    cin >> K;
    for(int j=0; j<K; j++){
      int A;
      cin >> A;
      F.at(A-1)++;
    }
  }
  int ans=0;
  for(int i=0; i<M; i++){
    if(F.at(i)==N) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	Scanner sc;
	int H, W;
	int D, Q;
	int x[], y[];
	int ary[];
	
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		init();
		calcDist();
		Q = sc.nextInt();
		for(int i=0; i<Q; i++) {
			System.out.println(-ary[sc.nextInt()-1] + ary[sc.nextInt()-1]);
		}
		sc.close();
	}
	
	void calcDist() {
		int n;
		for(int i=0; i<H; i++) {
			for(int j=0; j<W; j++) {
				n = sc.nextInt()-1;
				x[n] = j;
				y[n] = i;
			}
		}
		
		for(int i=D; i<H*W; i++) {
			ary[i] = ary[i-D] + Math.abs(x[i] - x[i-D]) + Math.abs(y[i] - y[i-D]);
		}
	}
	
	void init() {
		sc = new Scanner(System.in);
		H = sc.nextInt();
		W = sc.nextInt();
		D = sc.nextInt();
		x = new int[H*W];
		y = new int[H*W];
		ary = new int[H*W];
		ary[0] = 0;
	}
}

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

int main()
{
	int N, D;
	cin >> N >> D;
	if (N % (2 * D + 1) == 0)
	{
		cout << N / (2 * D + 1) << endl;
	}
	else
	{
		cout << N / (2 * D + 1) + 1 << endl;
	}

}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld double 
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define BOOST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define sl(a) a.size()
#define mod 1000000007 
#define lcm(a,b) (a*b)/__gcd(a,b)
#define MAX1 100006
#define f first
#define s second
#define pi 2*acos(0.0)
void solve()
{
    ll l,r;  cin>>l>>r;
    if(l<=2019 and 2019<=r) cout<<"0";
    else 
    {
        ll ans=2019;
        rep(i,l,r)
        {
            rep(j,i+1,r+1)
            {
                ans=min(ans,(i%2019*j%2019)%2019);
                if(ans==0) 
                {
                    cout<<ans;
                    return;
                }
            }
        }
        cout<<ans;
    }
}
int main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt","r",stdin);
    //for getting error from error.txt
    freopen("error.txt", "w", stderr);
    // for writing output to output.txt
    freopen("output.txt","w",stdout);
    #endif
    BOOST
    int T=1;  //cin>>T;
    while(T--) solve();
    cerr<<"Time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<"\n";
    cerr<<"My CLOCKS_PER_SEC= "<<CLOCKS_PER_SEC<<"\n";
    return 0;
}


Measured memory_bytes: 3772
z=int(input())
for _ in range(z):
    gx,gy = map(int,input().split())
    p=int(input())
    mat=[tuple(map(int,input().split())) for _ in range(p)]
    dp=[[0]*(gy+1) for _ in range(gx+1)]
    
    x0=gx
    y0=gy
    for x1,y1,x2,y2 in mat:
        if x1+x2==0: y0=min(y0,min(y1,y2))
        if y1+y2==0: x0=min(x0,min(x1,x2))
    for i in range(x0+1):
        dp[i][0]=1
    for i in range(y0+1):
        dp[0][i]=1
    
    for y in range(1,gy+1):
        for x in range(1,gx+1):
            a=0
            if (x-1,y,x,y) not in mat and (x,y,x-1,y) not in mat:
                a+=dp[x-1][y]
            if (x,y-1,x,y) not in mat and (x,y,x,y-1) not in mat:
                a+=dp[x][y-1]
            dp[x][y]=a
    print(dp[-1][-1] or "Miserable Hokusai!")


Measured memory_bytes: 5616
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        Dice dice=new Dice(scan.nextInt(),scan.nextInt(),scan.nextInt(),scan.nextInt(),scan.nextInt(),scan.nextInt());
        Dice dice2=new Dice(scan.nextInt(),scan.nextInt(),scan.nextInt(),scan.nextInt(),scan.nextInt(),scan.nextInt());
        	int ans=dice2.ans(dice, dice2);
        	if(ans==0) {
        		System.out.println("Yes");
        	}else if(ans==1) {
        		System.out.println("No");
        	}
    }
}

class Dice{
	int Top;	//1
	int S;		//2
	int N;		//5
	int W;		//4
	int E;		//3
	int Bo;		//6
	int tmp;
	
	Dice(int a,int b,int c,int d,int e,int f){
		Top=a;
		S=b;
		N=e;
		W=d;
		E=c;
		Bo=f;
	}
	
	void TrunS() {
		tmp=Top;
		Top=N;
		N=Bo;
		Bo=S;
		S=tmp;
	}void TrunN() {
		tmp=Top;
		Top=S;
		S=Bo;
		Bo=N;
		N=tmp;
	}void TrunW() {
		tmp=Top;
		Top=E;
		E=Bo;
		Bo=W;
		W=tmp;
	}void TrunE() {
		tmp=Top;
		Top=W;
		W=Bo;
		Bo=E;
		E=tmp;
	}
	int ans(Dice dice,Dice dice2) {		//DICEⅢの課題に対するメソッド
		int x=1;
		int count=0;
		if(dice.Top==dice2.W) {
			dice2.TrunE();
		}else if(dice.Top==dice2.N) {
			dice2.TrunS();
		}else if(dice.Top==dice2.E) {
			dice2.TrunW();
		}else if(dice.Top==dice2.S) {
			dice2.TrunN();
		}else if(dice.Top==dice2.Bo) {
			dice2.TrunS();
			dice2.TrunS();
		}								//ここでTop調整終了
	if(dice.Bo==dice2.Bo) {
	if(dice.S==dice2.N) {
		if(dice.E==dice2.W && dice.W==dice2.E) {
			x=0;;
		}
	}else if(dice.S==dice2.S) {
		if(dice.E==dice2.E && dice.W==dice2.W) {
			x=0;
		}
	}else if(dice.S==dice2.E) {
		if(dice.E==dice2.N && dice.W==dice2.S) {
			x=0;
		}
	}else if(dice.S==dice2.W) {
		if(dice.E==dice2.S && dice.W==dice2.N) {
			x=0;
		}
	}
	}
	else {
	if(dice.Top==dice2.Top) {
		count++;
	}if(dice.Bo==dice2.Bo) {
		count++;
	}if(dice.S==dice2.S) {
		count +=1;
	}if(dice.W==dice2.W) {
		count +=1;
	}if(dice.N==dice2.N) {
		count +=1;
	}if(dice.E==dice2.E) {
		count +=1;
	}if(4<=count && count<=6) {
		x=0;
	}
	}
	return x;
}
}


Measured memory_bytes: 26336
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
	out << '(' << p.first << ',' << p.second << ')';
	return out;
}

template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
	in >> p.first >> p.second;
	return in;
}

template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
	for (T &x : v)
		in >> x;
	return in;
}

template <class T>
ostream& operator << (ostream& out, const vector<vector<T>> &v)
{
	for (const vector<T> &x : v)
		out << x << '\n';
	return out;
}

template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
	for (const T &x : v)
		out << x << ' ';
	return out;
}

long long gcd (long long a, long long b)
{
	if (b > a)
		swap(a, b);
	return (b ? gcd(b, a % b) : a);
}

using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using tiii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;

#define F          first
#define S          second
#define First      first.first
#define Second     first.second
#define Third      second
#define mp         make_pair
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define per(i,b,a) for (int i = (b); i > (a); i--)
#define all(x)     x.begin(), x.end()
#define ret(x)     return cout << x, 0;
#define throwex    throw runtime_error ("Found the error.");

const int h = 1000000007;

signed main()
{
	ios::sync_with_stdio(false);
	#ifdef ONLINE_JUDGE
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.setstate(ios::failbit);
	#endif

	int n, m;
	cin >> n >> m;
	vvi M(n);
	rep(i,0,m)
	{
		int x, y;
		cin >> x >> y;
		x--, y--;
		M[x].push_back(y);
		M[y].push_back(x);
	}
	vi par(n, -1);
	par[0] = 0;
	queue<int> q;
	q.push(0);
	while(!q.empty())
	{
		int x = q.front();
		q.pop();
		for(int y : M[x])
		{
			if(par[y] == -1)
			{
				par[y] = x;
				q.push(y);
			}
		}
	}
	cerr << par << '\n';
	if(count(all(par), -1))
		ret("No");
	cout << "Yes\n";
	rep(i,1,n)
		cout << par[i] + 1 << '\n';
}


Measured memory_bytes: 10192
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<string>
using namespace std;
int main(){
char a[3][3];
cin>>a[0]>>a[1]>>a[2];
cout<<a[0][0]<<a[1][1]<<a[2][2]<<endl;
}


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

typedef long long ll;
using namespace std;
const int mod = 1e9 + 7;

ll quickpower(ll a, ll b) {
  ll res = 1;
  ll mod = 1e9 + 7;
  while (b) {
    if (b & 1) {
      res = (res * a) % mod;
    }
    b = b >> 1;
    a = (a * a) % mod;
  }
  return res % mod;
}

ll fact(ll x) {
  ll res = 1;
  for (ll i = x; i >= 1; i--) {
    res = res * i % mod;
  }
  return res;
}

long long combine(long long a, long long b) {
  //返回的是 aCb mod 1e9 + 7；
  return fact(a) * quickpower((fact(b) * fact(a - b) % mod), mod - 2) % mod %
         mod;
}

int main() {
  int x, y;
  cin >> x >> y;
  if ((x + y) % 3 != 0) {
    cout << 0 << endl;
  } else {
    long long m, n;
    m = x - (x + y) / 3;  // 解方程
    n = y - (x + y) / 3;
    if ((m < 0) || (n < 0))
      cout << 0 << endl;
    else
      cout << combine(m + n, m) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#https://atcoder.jp/contests/dp/tasks/dp_i
import math
N = int(input())
P_List = list(map(float,input().split()))
dp = [[0 for j in range(N + 1)] for i in range(N+1)]
std = math.ceil(N/2)
for i in range(N+1):
    if i == 0:
        dp[i][0] = 1
    else:
        Current_P = P_List[i - 1]
        for j in range(i + 1):
            if (N - i + j) < std:
                dp[i][j] = 0
            elif j == 0:
                dp[i][j] = dp[i - 1][j]*(1 - Current_P)
            elif j != i:
                dp[i][j] = (dp[i - 1][j]*(1 - Current_P)) + (dp[i - 1][j - 1]*Current_P)
            else:
                dp[i][j] = dp[i - 1][j - 1]*Current_P
    
print(sum(dp[N][math.ceil(std):]))

Measured memory_bytes: 224124
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define pb push_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false;}
const ll INF = 1e18;

ll n, res, xbit, ybit, cnt; 
V<> x(15), y(15), p(15), ans(16, INF), xp, yp;
VV<> xans(100000, V<>(15)), yans(100000, V<>(15));

void solve(string s){
    xp.clear(); yp.clear();
    res = xbit = ybit = cnt = 0;
    REP(i, n){
        if(s[i] == '1'){
            xp.pb(x[i]);
            xbit += (1 << i);
            cnt++;
        }
        if(s[i] == '2'){
            yp.pb(y[i]);
            ybit += (1 << i);
            cnt++;
        }
    }
    if(cnt > n) return;
    REP(i, n) if(s[i] == '0') res += min(xans[xbit][i], yans[ybit][i]);
    chmin(ans[cnt], res);
}

void dfs(string s){
    if(SZ(s) == n){
        solve(s);
        return;
    }
    dfs(s + "0");
    dfs(s + "1");
    dfs(s + "2");
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    REP(i, n) cin >> x[i] >> y[i] >> p[i];

    REP(bit, (1 << n)){
        V<> t, u;
        REP(i, n) if((bit >> i) & 1){
            t.pb(x[i]);
            u.pb(y[i]);
        }
        t.pb(INF); t.pb(-INF); t.pb(0);
        u.pb(INF); u.pb(-INF); u.pb(0);
        sort(all(t)); sort(all(u));
        REP(i, n){
            auto itr0 = lower_bound(all(t),x[i]);
            auto itr1 = itr0; itr1--;
            xans[bit][i] = min(*itr0 - x[i], x[i] - *itr1) * p[i];
            itr0 = lower_bound(all(u), y[i]);
            itr1 = itr0; itr1--;
            yans[bit][i] = min(*itr0 - y[i], y[i] - *itr1) * p[i];
        }
    }

    dfs("");
    REP(i, n + 1) cout << ans[i] << '\n';
}

Measured memory_bytes: 32980
#include<iostream>
#include<algorithm>
#include<utility>
#include<string>
#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;
typedef pair<ll, ll> P;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int M, D;
    cin >> M >> D;
    int m = 0, d = 0;
    int ans = 0;
    do {
        int d1 = (d + 1) % 10, d10 = (d + 1) / 10;
        if (d10 >= 2 && d1 >= 2 && d1 * d10 == m + 1) {
            ans++;
        }
        m = (m + (d + 1) / D) % M;
        d = (d + 1) % D;
    } while (!(m == 0 && d == 0));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import bisect


def main():
    n = int(input())
    l = [int(i) for i in input().split()]

    l.sort()
    ans = 0

    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            ans += bisect.bisect_left(l, l[i] + l[j]) - j - 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#pragma GCC optimize("Ofast")
#include<stdio.h>
#include<algorithm>
using namespace std;
long long num[3005],dp[3005][3005]={0},mod=998244353;
int main(){
	long long i,j,n,s;
	scanf("%lld%lld",&n,&s);
	for(i=1;i<=n;i++)
		scanf("%lld",&num[i]);
	dp[0][0]=1;
	for(i=1;i<=n;i++){
		for(j=0;j<=s;j++){
			dp[i][j]=dp[i-1][j]*2%mod;	
			if(j>=num[i])
				dp[i][j]=(dp[i][j]+dp[i-1][j-num[i]])%mod;
		}
	}
	printf("%lld\n",dp[n][s]);
}

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

using namespace std;

using llint = long long;

const int MAXN = 3e3+3;

int n, a[MAXN];
llint mem[MAXN][MAXN];
bool solved[MAXN][MAXN];

llint dp(int l, int r) {
  if (l > r) return 0;
  
  llint &ret = mem[l][r];
  if (solved[l][r]) return ret;
  solved[l][r] = 1;

  ret = ((n-(r-l)) % 2) == 1 ? 
    max(dp(l+1, r)+a[l], dp(l, r-1)+a[r]) :
    min(dp(l+1, r)-a[l], dp(l, r-1)-a[r]);
  return ret;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a+i);
  }

  printf("%lld\n", dp(0, n-1));
  return 0;
}


Measured memory_bytes: 78464
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            if (set.contains(a)) {
                set.remove(a);
            } else {
                set.add(a);
            }
        }
        System.out.println(set.size());
    }
}

Measured memory_bytes: 48124
#include<iostream>
#include<queue>

#define inf 1000000000

using namespace std;

int n,m;
int road[101][101];

class sint{
	public:
	int iti,now,tick;
	sint(){}
	sint(int a,int b,int c){iti=a;now=b;tick=c;}
	bool operator < (const sint &a)const{
		return now>a.now;
	}
};

int dike(int cick,int st,int en){
	priority_queue<sint> state;
	
	int sima[101][11];
	int visit[101][11];
	for(int i=0;i<101;i++){
		for(int j=0;j<11;j++){
			sima[i][j]=inf;
			visit[i][j]=0;
		}
	}
	state.push(sint(st,0,0));
	sima[st][0]=0;
	
	while(1){
		sint u=state.top();
		state.pop();
		
		visit[u.iti][u.tick]=1;
		if(u.iti==en){
			return u.now;
		}
		
		/*
		for(int i=0;i<cick;i++){
			for(int j=0;j<n;j++){
				printf("%d ",sima[j][i]);
			}puts("");
		}puts("");
		*/
		for(int i=1;i<=n;i++){
			if(road[u.iti][i]==inf || visit[i][u.tick]==1) continue;
			
			if(sima[u.iti][u.tick]+road[u.iti][i]<sima[i][u.tick]){
				sima[i][u.tick]=sima[u.iti][u.tick]+road[u.iti][i];
				state.push(sint(i,sima[i][u.tick],u.tick));
			}
			
			if(u.tick<cick){
				if(sima[u.iti][u.tick]+road[u.iti][i]/2 < sima[i][u.tick+1]){
					sima[i][u.tick+1]=sima[u.iti][u.tick]+road[u.iti][i]/2;
					state.push(sint(i,sima[i][u.tick+1],u.tick+1));
				}
			}
		}
	}
	
	return st;
}

int main(){
	while(1){
		int c,s,d;
		cin>>c>>n>>m>>s>>d;
		if(n==0)break;
		for(int i=0;i<101;i++){
			for(int j=0;j<101;j++){
				road[i][j]=inf;
			}
		}
		for(int i=0;i<m;i++){
			int a,b,e;
			cin>>a>>b>>e;
			road[a][b]=road[b][a]=e;
		}
		
		printf("%d\n",dike(c,s,d));
	}
}

Measured memory_bytes: 0
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    char a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a == b && c == d && a != c) cout << "Yes" << endl;
    else if (a == c && b == d && a != b) cout << "Yes" << endl;
    else if (a == d && b == c && a != b) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
program main
  implicit none
  integer :: N, K
  integer,allocatable :: d(:),A(:,:)
  logical,allocatable :: have(:)
  integer :: i,j
  
  read(*,*) N,K
  allocate(d(K))
  allocate(A(K,N))
  allocate(have(N))
  have(:) = .false.
  do i = 1,K
     read(*,*) d(i)
     read(*,*) A(i,1:d(i))
  end do
  
  do i = 1,K
     do j = 1,d(i)
        have(A(i,j)) = .true.
     end do
  end do

  write(*,'(i0)') count(.not.have)
  
end program main


Measured memory_bytes: 2876
#include <bits/stdc++.h>
using namespace std;
template<typename T1, typename T2>
inline bool cmn (T1& a, T2 b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<typename T1, typename T2>
inline bool cmx (T1& a, T2 b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  cin.tie(0); cin.sync_with_stdio(false);
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  auto erasable = [&] (const vector<int>& b, int M) {
    int cnt = count_if(b.begin(), b.end(), bind(less_equal<int>(), placeholders::_1, M));
    return max(0, min(cnt, (int)b.size() - k + 1));
  };
  constexpr int inf = 1 << 30;
  int ret = inf;
  for (auto m : a) {
    auto check = [&] (int M) {
      assert(m <= M);
      int now = 0;
      vector<int> tmp;
      auto discharge = [&] () {
        now += erasable(tmp, M);
        tmp = {};
      };
      for (auto crr : a) {
        if (crr >= m) tmp.push_back(crr);
        else discharge();
      }
      discharge();
      return now >= q;
    };
    if (!check(inf)) continue;
    int ok = inf, ng = m - 1, md;
    while (abs(ng - ok) > 1) {
      md = (ok + ng) >> 1;
      if (check(md)) ok = md;
      else ng = md;
    }
    assert(ok - m >= 0);
    cmn(ret, ok - m);
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int data[50000] = {};
  int size = sizeof(data) / sizeof(int);

  for (int i = 2; i < size; ++i)
    for (int j = i*2; j < size; j+=i)
      data[j] = 1;

  while (true) {
    int n;
    cin >> n;
    if (n == 0)
      break;

    int cnt = 0;
    for (int i = 2, i2 = n - 2; i <= i2; ++i, --i2)
      if ((data[i] == 0) && (data[i2] == 0))
        ++cnt;
    cout << cnt << endl;
  }
}


Measured memory_bytes: 3272
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <functional>
using namespace std;

typedef long long ll;
int main() {
	ll x, y; cin >> x >> y;
	cout << (abs(x - y) > 1 ? "Alice" : "Brown") << endl;
	return 0;
}

Measured memory_bytes: 256
str=gets.chomp
t=gets.chomp
length=str.length
i=-1
loop_count = 0
t.each_char do |char1|
    i=str.index("#{char1}",i+1)
  unless i
    i=str.index("#{char1}")
    loop_count += 1
    unless i
      puts -1
      exit
    end
  end
end

if i
printf "%d\n",length * loop_count + i + 1
end

Measured memory_bytes: 2172