akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;
const int N = 110;
int a[N],b[N];
int main()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n ; i++)
    {
        cin >> a[i] >> b[i];
    }
    for(int i = 1; i <= n - 2; i++)
    {
        if(a[i] == b[i] && a[i+1] == b[i+1] && a[i+2] == b[i+2])
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3636
H,W=map(int,input().split())
L=[]
for i in range(H):
    l=input()
    L.append(l)
dp=[[0]*(W+1) for i in range(H+1)]
dp[1][1]=1
for i in range(1,H+1):
    for j in range(1,W+1):
        if L[i-1][j-1]==".":
            dp[i][j]=dp[i][j]+dp[i][j-1]+dp[i-1][j]
print(dp[-1][-1]%(10**9+7))



Measured memory_bytes: 270236
use std::io;


fn main() {
    let mut c = read::<usize>();
    c.sort();
    println!("{}", c[0] + c[1]);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include <stdio.h>

int main(void){

  long n;
  scanf("%ld", &n);
  long number = n;
  long f_n = 0;
  while (number > 0) {
    f_n += number%10;
    number /= 10;
  }
  if (n%f_n == 0) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    long n, k;
    cin >> n >> k;
    long ans;
    if (n == k) {
        ans = 0;
    } else if (n > k) {
        ans = min(n % k, abs(n % k - k));
    } else {
        ans = min(k - n, n);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{   int a,b,c,x,y,z,min;
    scanf("%d %d %d",&a,&b,&c);
    if (1<=a&&a<=10000&&1<=b&&b<=10000&&1<=c&&c<=10000)
    {
        x=a+b;
        y=a+c;
        z=b+c;
        min=x>=y?y:x;
        min=min>=z?z:min;
        printf("%d",min);
    }
    return 0;
}


Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
class Main {
	public static void main(String[]args) {
		Scanner scan = new Scanner(System.in);
		int n =scan.nextInt();
		int m = scan.nextInt();
		int arr[] = new int[n];
		Set<Integer> s = new HashSet<>();
		for(int i = 0 ; i < n ; i++) {

			ArrayList<Integer> a = new ArrayList<>();
			int u = scan.nextInt();
			for(int j = 0 ; j <u ; j++){
			     if(i == 0) {
			    	 s.add(scan.nextInt()) ;
			     }else {
			    	 a.add(scan.nextInt()) ;
			     }
			}
			if(i!=0)
				s.retainAll(a);
		}
		
		System.out.println(s.size());
		

	}
}

Measured memory_bytes: 22484
def dif(n,ab):
    c=[[sum(i),i] for i in ab]
    c.sort(reverse=True)

    a=[c[i][1][0] for i in range(n) if i%2==0]
    b=[c[i][1][1] for i in range(n) if i%2!=0]

    return sum(a)-sum(b)

n=int(input())
print(dif(n,[list(map(int,input().split())) for i in range(n)]))

Measured memory_bytes: 38804
K, N = map(int, input().split())
A = list(map(int, input().split()))
diff = []
for i in range(N):
    if A[i-1] > A[i]:
        diff.append(A[i]-(A[i-1]-K))
    else:
        diff.append(A[i]-(A[i-1]))

print(sum(sorted(diff)[:-1]))

Measured memory_bytes: 32364
import numpy as np
 
h, w = map(int, input().split())
 
up = np.zeros((h, w), dtype=int)
down = np.zeros((h, w), dtype=int)
right = np.zeros((h, w), dtype=int)
left = np.zeros((h, w), dtype=int)
 
map = np.array([list(input()) for i in range(h)]) == "."
 
for i in range(1, h):
    up[i] = (up[i-1] + 1) * map[i-1]
    down[h-1-i] = (down[h-i] + 1) * map[h-i]
for j in range(1, w):
    left[:,j] = (left[:,j-1] + 1) * map[:,j-1]
    right[:,w-1-j] = (right[:,w-j] + 1) * map[:,w-j]

print(((up+down+right+left+1) * map).max())

Measured memory_bytes: 219816
h,w = map(int, input().split())
stage = [list(input()) for i in range(h)]
ans = [0 for i in range(2*h)]
for i in range(h):
    ans[2*i] = stage[i]
    ans[2*i+1] = stage[i]
for i in ans:
    for j in i:
        print(j, end = "")
    print()

Measured memory_bytes: 4596
def solve():
    import sys
    input = sys.stdin.readline
    n=int(input())
    a=list(map(int,input().split()))
    dp=a[:]
    for i in range(1,n):
        for j in range(i-1,-1,-1):
            dp[j]=max(a[i]-dp[j],a[j]-dp[j+1])
    print(dp[0])
solve()

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

#define X first
#define Y second
#define ll long long
#define MP make_pair
#define PB push_back

using namespace std;

const int MAXN=1e5;
ll MOD=1e9+7;

ll n,a,b;
ll bio[MAXN+5];
vector <ll> sus[MAXN+5];
ll dp[3][MAXN+5];

void resi(ll x){
	dp[0][x]=1;
	dp[1][x]=1;
	bio[x]=1;
	for(int i=0; i<sus[x].size(); i++){
		if(bio[sus[x][i]]==0){
			resi(sus[x][i]);
			dp[0][x]*=(dp[0][sus[x][i]]+dp[1][sus[x][i]]);
			dp[0][x]%=MOD;
			dp[1][x]*=(dp[0][sus[x][i]]);
			dp[1][x]%=MOD;
		}
	}
}

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

	cin>>n;
	for(int i=0; i<n-1; i++){
		cin>>a>>b;
		sus[a].PB(b);
		sus[b].PB(a);
	}
	resi(1);
	cout<<(dp[0][1]+dp[1][1])%MOD;
	
	return 0;
}

Measured memory_bytes: 18296
import math
n_in = int(input())


def sgs(n, a, s, s_temp):
    if a == math.ceil(math.log(n, 10)):
        c = 0
        for i in s:
            i_listed = list(map(int, list(str(i))))
            if 3 in i_listed and 5 in i_listed and 7 in i_listed:
                if i <= n:
                    c += 1
    else:
        a += 1
        temp = []
        for i in s_temp:
            s.append(10 * i + 3)
            s.append(10 * i + 5)
            s.append(10 * i + 7)
            temp.append(10 * i + 3)
            temp.append(10 * i + 5)
            temp.append(10 * i + 7)
        s_temp = temp
        c = sgs(n, a, s, s_temp)
    return c


ans = sgs(n_in, -1, [3, 5, 7], [3, 5, 7])
print(ans)


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

int main(){
    int N;
    cin >> N;
    vector<bool> S(13,false),H(13,false),C(13,false),D(13,false);
    for(int i = 0; i < N; i++){
        char A;
        int n;
        cin >> A >> n;
        switch (A)
        {
        case 'S':
            S[n-1] = true;
            break;
        case 'H':
            H[n-1] = true;
            break;
        case 'C':
            C[n-1] = true;
            break;
        case 'D':
            D[n-1] = true;
            break;
        default:
            break;
        }
    }
    for(int i = 0; i < S.size(); i++){
        if(S[i] == false){
            cout << "S " << i+1 << endl;
        }
    }
    for(int i = 0; i < H.size(); i++){
        if(H[i] == false){
            cout << "H " << i+1 << endl;
        }
    }
    for(int i = 0; i < C.size(); i++){
        if(C[i] == false){
            cout << "C " << i+1 << endl;
        }
    }
    for(int i = 0; i < D.size(); i++){
        if(D[i] == false){
            cout << "D " << i+1 << endl;
        }
    }
}


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

#undef false
#undef true

using namespace std;

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

/* [💭] [💡] [🎈] */

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

    int n, r;
    cin >> n >> r;
    cout << r + 100 * max(0, 10 - n);

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
#define ll long long
int gcd(int a,int b){return a%b?gcd(b,a%b):b;}
int main(){
    int n,x;
    cin>>n>>x;
    vector<int> a(n+1);
    for(int i=0;i<n;i++)cin>>a.at(i);
    a.at(n)=x;
    sort(a.begin(),a.end());
    int res=a.at(1)-a.at(0);
    for(int i=1;i<n;i++){
        res=gcd(res,a.at(i+1)-a.at(i));
    }
    cout<<res<<endl;
}

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

#define llong long long
#define inf 999999999
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<PP, int> PPP;
typedef struct data{
	int now;
	int cost;
}data;
int nh[4] = {1, 0, -1, 0};
int nw[4] = {0, 1, 0, -1};





int main(){
	for(int i= 0; i < 3; i++){
		int sum = 0, sum2 = 0, in;
		for(int i = 0; i < 6; i++){
			cin >> in;
			if(i < 3){
				if(i%3 == 0) sum += in * 3600;
				else if(i %3 == 1) sum += in * 60;
				else sum += in;
			}else{
				if(i%3 == 0) sum2 += in * 3600;
				else if(i%3 == 1) sum2 += in * 60;
				else sum2 += in;
			}
		}
		int sa = sum2 - sum;
		cout << sa/3600 << " " << sa%3600/60 << " " << sa%60 << endl;
	}	

	return 0;
}


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

int main(){
  long long  int N,W;
  cin >>N>>W;
  vector<vector<long long int>>dp(N+1,vector<long long int>(100001,1000000000000));
  vector<long long int>w(N+1);
  vector<long long int>v(N+1);
  dp[0][0]=0;
  for(int i=1;i<=N;i++){
  cin >>w[i]>>v[i];
  dp[i][0]=0;
  }
  
  for(int i=1;i<=N;i++){
  	for(int j=1;j<=100000;j++){
    	if(j>=v[i]){
        dp[i][j]=min(dp[i-1][j-v[i]]+w[i],dp[i-1][j]);
        }
    	else{dp[i][j]=dp[i-1][j];}
      
    }
  }
  long long int ans=0; 
  for(int j=1;j<=100000;j++){
  if(dp[N][j]<=W){ans=j;}
  }
  cout <<ans;
}

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

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

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

  ll n, w;
  cin >> n >> w;
  vector<ll> weight(110), value(110);
  rep(i, n) cin >> weight[i] >> value[i];

  // dp[i-1][sumW] := i-1 番目までの品物を重さが sumW を超えないように選んだときの最大価値
  ll dp[110][100010] = {};
  rep(i, n) {
    for(int sumW = 0; sumW <= w; ++sumW) {
      if(sumW-weight[i] >= 0) {
        chmax(dp[i+1][sumW], dp[i][sumW-weight[i]] + value[i]);
      }
      chmax(dp[i+1][sumW], dp[i][sumW]);
    }
  }
  cout << dp[n][w] << '\n';

  return 0;
}


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

typedef vector<int> v;
typedef v::iterator vi;

v L;

long msc(vi l, vi r)
{
	long c = 0;
	if (l + 1 < r) {
		vi m = l + (r - l) / 2;
		c = msc(l, m) + msc(m, r);

		vi cend = L.begin() + (m - l);
		copy(l, m, L.begin());
		vi cp = L.begin();

		vi i = l;
		for (; cp != cend && m != r; i++)
			if(*cp < *m)
				*i = *cp++;
			else
				*i = *m, c += m++ - i;

		copy(cp, cend, i);
	}
	return c;
}

static inline int in()
{
    int c, n = 0;
    while ((c = getchar_unlocked()) >= '0' && c <= '9')
		n = 10 * n + (c - '0');
    return n;
}

int main()
{
	int	n = in();

	v a(n);
	L = v(n);

	for (int &x: a)
		x = in();

	printf("%ld\n", msc(a.begin(), a.end()));
}



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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

void solve() {
    //const i64 mod = 1'000'000'007;
    
    i64 N,M,C;
    cin >> N >> M >> C;
    
    vector<i64> B(M);
    rep(i,0,M){
        cin >> B[i];
    }
    
    i64 ans=0;
    rep(i,0,N){
        i64 sum=C;
        rep(j,0,M){
            i64 a;
            cin >> a;
            sum+=a*B[j];
        }
        if(sum>0){
            ++ans;
        }
    }
    
    cout << ans << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
import bisect

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()

ablist = [0]*N
r = 0

for i in range(N):
  ablist[i] = bisect.bisect_left(A, B[i]) + ablist[i-1]

for i in range(N):
  a = bisect.bisect_left(B, C[i])
  if a > 0:
    r += ablist[a-1]
  
print(r)

Measured memory_bytes: 23360
#include<stdio.h>
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include <typeinfo>
#define rep(i,n) for(int i = 0; i < (n); i++) 
using namespace std;
int long long ll;

int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

int main() {

    string str,ss;
    //const char ss;
    int ans=0;
    cin >> str;

    rep(i,str.length()){
        ans += ctoi(str[i]);
    }
    
    if (stoi(str)%ans == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#if 0

#endif
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <valarray> 
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int n; 
struct Matrix {
    valarray<int> a;
    Matrix() : a(n * n) { a = 0; }
};
void showMatrix(const Matrix& Mat) {
    int j = 0;
    for (const auto& e : Mat.a) {
        if (j == n) {
            cout << endl; 
            j=0;
        }
        cout << e << " ";
        ++j;
    }
    cout << endl;
}
void showVec(const valarray<int>& vec) {
    cout << "(";
    for (auto e : vec) cout << " " << e << " ";
    cout << ")" << endl;
}
bool isEqual( const std::valarray< bool >& aResult ) {
    bool equals = true;
    for (auto e : aResult) {
        equals &= e;
    }
    return equals;
}
Matrix multiply(const Matrix& A, const Matrix& B) { 
    Matrix C;
    for (int i = 0; i < n; ++i)
        for (int j=0; j < n; ++j) {
            C.a[i*n+j] = min((A.a[slice(i*n, n, 1)] * B.a[slice(j, n, n)]).sum(), 1); 
        }
    return C;
}
Matrix unitMat() {
    Matrix unit;
    for (int i = 0; i < n; ++i) unit.a[i * n + i] = 1;
    return unit;
}
Matrix expMat(const Matrix& Mat, const ll num) {
    if (num == 0) return unitMat();
    else if (num == 1) return Mat;
    else if (num % 2) return multiply(Mat, expMat(Mat, num - 1));
    else return expMat(multiply(Mat, Mat), num / 2);
}
valarray<int> linearMap(const Matrix& M, const valarray<int>& vec) {
    valarray<int> R(n);
    for (int i = 0; i < n; ++i) R[i] = min((vec * M.a[slice(i*n, n, 1)]).sum(), 1);
    return R;
}
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    #define ll int

    ll N, M, Z, s1, d1;

    while (cin >> N >> M >> Z) {
        if (N == 0 && M == 0 && Z == 0) {
            break;
        }
        n = M * 2;
        Matrix edgeToEdge;
        vector<pair<ll, ll> > edge;
        valarray<int> startEdge(M * 2), goalEdge(M * 2);
        for (int i = 0; i < M; ++i) {
            cin >> s1 >> d1;
            edge.push_back(make_pair(s1, d1));
        }
        for (int i = 0; i < M; ++i) {
            for (int j = 0; j < M; ++j) {
                if (edge[i].second == edge[j].first) {
                    edgeToEdge.a[2 * j * 2 * M + 2 * i] = 1;
                    edgeToEdge.a[(2 * i + 1) * 2 * M + 2 * j + 1] = 1;
                } else if (i != j && edge[i].first == edge[j].first) {
                    edgeToEdge.a[2 * j * 2 * M + 2 * i + 1] = 1;
                } else if (i != j && edge[i].second == edge[j].second) {
                    edgeToEdge.a[(2 * j + 1) * 2 * M + 2 * i] = 1;
                }
            }
            if (edge[i].second == N) goalEdge[2 * i] = 1;
            if (edge[i].second == 1) startEdge[2 * i + 1] = 1; 
            if (edge[i].first == 1) startEdge[2 * i] = 1;
            if (edge[i].first == N) goalEdge[2 * i + 1] = 1;
        }

        Matrix totalMat = expMat(edgeToEdge, Z - 1);
        startEdge = linearMap(totalMat, startEdge);

        if ((startEdge * goalEdge).sum() > 0) cout << "yes" << endl;
        else cout << "no" << endl;
    }

    return 0;
}


Measured memory_bytes: 4216
#include <iostream>

using namespace std;


void call(int n) {
	int i = 1;
CHECK_NUM:
	int x = i;
	if (x % 3 == 0) {
		cout << " " << i;
		goto END_CHECK_NUM;
	}
INCLUDE3:
	if (x % 10 == 3) {
		cout << " " << i;
		goto END_CHECK_NUM;
	}
	x /= 10;
	if (x) goto INCLUDE3;
END_CHECK_NUM:
	if (++i <= n) goto CHECK_NUM;

	cout << endl;
}


int main() {
	
	int a;
	cin >> a;
	call(a);

	return 0;
}





Measured memory_bytes: 3084
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N, K = sc.nextInt()
  @scala.annotation.tailrec
  def loop(m: Int, count: Int): Int = if (N / m == 0) count else loop(m * K, count + 1)
  println(loop(K, 1))
}


Measured memory_bytes: 55240
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    ll n;
    cin >> n;
    matrix a(n,Vi(n));
    rp(i,n){
        rp(j,n){
            cin >> a[i][j];
        }
    }
    ll sum=0;
    rp(i,n){
        repi(j,i+1,n){
            ll detour=INF;
            rp(k,n){
                if(k==i||k==j) continue;
                chmin(detour,a[i][k]+a[k][j]);
            }
            if(detour<a[i][j]){
                print(-1);
                return;
            }
            if(detour>a[i][j]){
                sum+=a[i][j];
            }
        }
    }
    print(sum);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 3964
#include <bits/stdc++.h>
#include <regex>
#ifdef _DEBUG
#include "debug.h"
#endif
#define int ll
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define all(v) (v).begin(),(v).end()
#define mkpr make_pair
#define mktp make_tuple
#define tv(tp, i) get<(i)>(tp)
#define CLEAR(obj) obj = decltype(obj)()
#define var auto
#define OUT(type) type &
#define IN(type) const type &
#define self (*this)
#define in :
#define True true
#define False false
using namespace std; using int32 = int32_t; using str = string; using cstr = const str;
using ll = long long; using ull = unsigned long long; using cint = const int; using cll = const ll;
using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>;
using vb = vector<bool>; using vvb = vector<vb>; using vd = vector<double>; using vvd = vector<vd>;
using vc = vector<char>; using vvc = vector<vc>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<double, double>; using psl = pair<string, ll>;
using tiii = tuple<int, int, int>; using tlll = tuple<ll, ll, ll>;
static const int MGN = 10; static const int ARYSZ_MAX = (int)1e7;
static const ll LINF = LLONG_MAX/2;
#ifdef int
static const int INF = LINF;
#else
static const int INF = INT_MAX/2;
#endif
static double EPS = 1e-9;
#define FASTCIN() cin.tie(0);ios::sync_with_stdio(false);
#ifdef IMPORT_SAMPLE
#define DEBUG_IMPORT(file) vs args(argv, argv+argc);str sample = make_sample(args, file);ifstream ifs(sample); cin.rdbuf(ifs.rdbuf());
#else
#define DEBUG_IMPORT(file)
#endif
static inline bool DBLEQ(double a, double b) {return abs(a - b) < EPS;}
static inline void EPR(str msg) {cerr << msg << endl;}
static inline void AST(bool exp, str msg) {if(!exp){EPR(msg);} assert(exp);}
static inline void TAST(bool exp, str msg) {if(!exp){EPR(msg);} while(!exp){}}


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


int multiple(int x, int d) {
    return x/d;
}


int32 main(int32 argc, char* argv[]) {
    FASTCIN();
    DEBUG_IMPORT("sample-1");


    int A,B,C,D; cin>>A>>B>>C>>D;

    // [A, B]
    // x%C != 0 and x%D != 0
    int cmult = multiple(B, C) - multiple(A-1, C);
    int dmult = multiple(B, D) - multiple(A-1, D);
    int lc = lcm(C, D);
    int cdmult = multiple(B, lc) - multiple(A-1, lc);

    int ans = B-A+1 - cmult - dmult + cdmult;

    cout << ans << endl;


    return 0;
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")
int table[365][26];
int main()
{
int D;
	cin >> D;
	vec(C);
	vec(Las);
	fx(26) {
		vecp(C);
		Las.push_back(0);
	}

	fx(D) {
		fy(26) {
			cin >> table[x][y];
		}
	}

	vec(T);
	fx(D) {
		pb(T, x % 26 + 1);
	}
	ll sum = 0;
	fx(100000) {
		int d, q;
		d = rand() % D + 1, q = rand() % 26 + 1;
		int pre = T[d - 1];
		T[d - 1] = q;
		ll ans = 0;

		fy(26) {
			Las[y] = 0;
		}
		fw(D) {

			ans += table[w][T[w] - 1];
			Las[T[w] - 1] = w + 1;
			fz(26) {
				ans -= C[z] * (w + 1 - Las[z]);
			}
		}
		if (ans>sum) {
			sum = ans;
		}
		else {
			T[d - 1] = pre;
		}
	}

	fx(D) {
		ce(T[x])
	}

	
    return 0;
}



Measured memory_bytes: 3652
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)





int main() {
    ll n, c;
    cin >> n >> c;
    
    while(n != 0 || c != 0){
        vector<ll> a(n), b(c);
        REP(i, n){
            REP(j, 16){
                ll t;
                cin >> t;
                a[i] = (a[i] << 1) + ((t)? 1 : 0);
            }
        }
        REP(i, c){
            REP(j, 16){
                ll t;
                cin >> t;
                b[i] = (b[i] << 1) + ((t)? 1 : 0);
            }
        }
        
        vector<vector<ll>> dp(n + 1, vector<ll>(1 << 16, -1));
        dp[0][a[0]] = 0;
        REP(i, n){
            REP(j, 1 << 16){
                if(dp[i][j] != -1){
                    REP(k, c){
                        ll t = j | a[i], sum = 0;
                        REP(l, 16){
                            if((t & (1 << l)) & (b[k] & (1 << l))){
                                sum++;
                                t ^= (1 << l);
                            }
                        }
                        dp[i + 1][t] = max(dp[i + 1][t], dp[i][j] + sum);
                    }
                }
            }
        }
        
        ll ans = 0;
        REP(i, 1 << 16){
            ans = max(ans, dp[n][i]);
        }
        cout << ans << endl;
        
        cin >> n >> c;
    }
}



Measured memory_bytes: 19532
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n;
    cin >>n;
    vector<long long> arr(n);
    for(long long i = 0; i < n; i++)
        cin >>arr[i];
    long long sum = 0;
    long long mn = LLONG_MAX;
    long long cnt = 0;
    for(long long i = 0; i < n; i++){
        mn = min(mn, abs(arr[i]));
        sum += abs(arr[i]);
        if(arr[i] < 0)
            cnt++;
    }
    if(cnt % 2 == 0)
        cout <<sum;
    else 
        cout <<sum - (2 * mn);
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int 
#define p 10000000000000000
using namespace std;
bool solve(ll curr,ll check,int k){
    
    
}
int main(){
    int n;cin >> n;
    int arr[100001];
    for(int i=0;i<n;i++) cin >>arr[i];
    ll ans[100001];
    for(int i=0;i<n;i++) ans[i]=0;
    ans[0]=0;
    //ans[1]=arr[0];
    for(int i=1;i<n;i++){
        if(i==1){
            ans[i]=abs(arr[i]-arr[i-1]);
        }
        else{
            ans[i]=min(ans[i-2]+abs(arr[i]-arr[i-2]),ans[i-1]+abs(arr[i]-arr[i-1]));
        }
    }
    cout <<ans[n-1]<<endl;
}



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

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int N, A, B; cin >>N>>A>>B;

    cout << ((B-A) % 2 ? "Borys" : "Alice") << endl;
}


Measured memory_bytes: 256
def main():
    a, b, c, x = map(int, open(0).read().split())
    l = [
        500*x + 100*y + 50*z
        for x in range(a+1)
            for y in range(b+1)
                for z in range(c+1)
    ]
    print(l.count(x))


if __name__ == "__main__":
    main()


Measured memory_bytes: 8276
N, a, b = map(int, input().split())
S = list(input())
ia = 0
ib = 0
for s in S:
    if s == "a" and ia+ib < a+b:
        print("Yes")
        ia += 1
        continue
    if s == "b" and ia+ib < a+b and ib < b:
        print("Yes")
        ib += 1
        continue
    print("No")

Measured memory_bytes: 4708
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  int n, m;
  cin >> n >> m;

  vector<int> a(n + 2, 0);
  int l, r;

  for (int i = 0; i < m; i++){
    cin >> l >> r;
    a[l]++;
    a[r + 1]--;
  }
  int s = 0;
  for (int i = 0; i < n; i++){
    a[i + 1] += a[i];
    if (a[i + 1] == m)
      s++;
  }


  cout << s << endl;

  return 0;
}


Measured memory_bytes: 640
while True:
  m, f, r = map(int, input().split())

  if m == -1 and f == -1 and r == -1:
    break

  if m == -1 or f == -1:
    print("F")
  elif m + f >= 80:
    print("A")
  elif m + f >= 65:
    print("B")
  elif m + f >= 50:
    print("C")
  elif m + f >= 30:
    if r >= 50:
      print("C")
    else:
      print("D")
  else:
    print("F")



Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define pii pair<ll,ll>
#define ff first
#define ss second
#define sfi(a) scanf("%d",&a)
#define sfi2(a,b) scanf("%d %d",&a,&b)
#define sfi3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sfll(a) scanf("%lld",&a)
#define all(a) a.begin(),a.end()
#define keepu(a) a.erase(unique(all(a)),a.end())
#define inf 1e7
#define m_p make_pair
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define mem(x,val) memset(x,val,sizeof(x))
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)
#define FAST  ios_base::sync_with_stdio(0);cout.tie(0)
#define sqr(x) ((x)*(x))

typedef long long ll;
const ll mod = 1e9+7;
const int sz = 500;


int main(){

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

    for(int i=1;i<=1000;i++){
        int x = ((i*1.0) * 0.08);
        int y = ((i*1.0) * 0.1);
        if(x==a && y==b){
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define gt getchar()
#define ll long long
#define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
typedef std::pair<int,int> P;
#define mk std::make_pair
#define fr first
#define sc second
inline int in()
{
	int k=0;char ch=gt;bool p=1;
	while(ch<'-')ch=gt;if(ch=='-')ch=gt,p=0;
	while(ch>'-')k=k*10+ch-'0',ch=gt;
	return p?k:-k;
}
const int YL=1e9+7,N=1e6+5;
inline void add(int &x,int y){if((x+=y)>=YL)x-=YL;}
int dp[N],sum[N];
int main()
{
	int n=in(),r=1ll*(n-1)*(n-1)%YL;dp[1]=n,dp[2]=1ll*n*n%YL;
	sum[1]=sum[2]=dp[1],add(sum[2],dp[2]);
	for(int i=3;i<=n;++i)
	{
		sum[i]=sum[i-1];
		add(dp[i],dp[i-1]);
		add(dp[i],r);
		add(dp[i],sum[i-3]);
		add(dp[i],n-i+2);
		add(sum[i],dp[i]);
	}
	printf("%d\n",dp[n]);
	return 0;
}


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

using namespace std;

int main() {
    string S,T;
    cin>>S>>T;
    int ans=0;
    REP(i,3){
        if(S[i]==T[i]){
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<map>
#include<queue>
#include<assert.h>
#include<stdio.h>
#include<stack>
#include<cstring>
#include<fstream>
using namespace std;
#define goup(i,a,b) for(int i=a;i<b;i++)
#define Goup(i,a,b) for(int i=a;i<=b;i++)
#define godown(i,a,b) for(int i=a;i>b;i--)
#define Godown(i,a,b) for(int i=a;i>=b;i--)
#define Gohead(i,a,b) for(int i=a;i;i=b)
typedef long long ll;
const int MaxDegree = 0x3f3f3f;
const double Mod = 1e9 + 7;
const double PI = acos(-1);
int book[1005][1005];
int main()
{
	int T, element[45] = { 0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	while (cin >> T)
	{
		cout << element[T] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vint p(n);
  rep(i,n){
    cin>>p[i];
  }
  int count=0;
  bool fg=false;
  rep(i,n){
    if(p[i]==i+1){
      if(fg){
        fg=false;
      }
      else{
        fg=true;
        count++;
      }
    }
    else
      fg=false;
  }
  cout<<count<<'\n';
  return(0);
}


Measured memory_bytes: 640
n = int(input())
sequence = [int(x) for x in input().split(' ')]

def pretty_sequence(sequence):
    n = len(sequence)
    for i in range(n-1):
        print(format(sequence[i]) + ' ', end='')
    print(sequence[n - 1])

def bubleSort(n, sequence):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for i in range(n-1, 0, -1):
            if sequence[i] < sequence[i-1]:
                tmp_val = sequence[i]
                sequence[i] = sequence[i-1]
                sequence[i-1] = tmp_val
                count += 1
                flag = 1
    return sequence, count

sequence, count = bubleSort(n, sequence)
pretty_sequence(sequence)
print(count)

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

int main () {
  int n,k;cin>>n>>k;
  for(int i=0;i<k;++i){
    double x,y;cin>>x>>y;x-=0.5+n*0.5;y-=0.5+n*0.5;
    x=x<0?-x:x; y=y<0?-y:y; x=ceil(x); y=ceil(y);
    int max=x<y?y:x;
    cout<<1+(n/2-max)%3<<endl;
  }
}

Measured memory_bytes: 3216
#include <iostream>

using namespace std;

int main()
{
    int n, c[20], v[20];
    cin >> n;

    for (int i = 0; i < n; i++) cin >> v[i];
    for (int i = 0; i < n; i++) cin >> c[i];

    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        if (v[i] > c[i]) ans += v[i] - c[i];
    }

    cout << ans;

    return (0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;
const ll MINF = LLONG_MIN;
const int INT_INF = INT_MAX;
using Tree = vector<pair<int, int>>;
int main()
{
    ll a, b, k;
    cin >> a >> b >> k;
    ll ansa, ansb;
    if (a >= k)
    {
        cout << a - k << " " << b << endl;
    }
    else
    {
        cout << 0 << " " << max(b - (k - a), 0ll) << endl;
    }
}


Measured memory_bytes: 256
from math import sqrt
res = 0

def isprime(x) :
    if x == 2 : return 1
    if (x < 2) or (x % 2 == 0) : return 0

    i = 3
    while i <= sqrt(x) :
        if x % i == 0 : return 0
        i = i + 2

    return 1

for mak in range(int(input())) :
    res += isprime(int(input()))
print(res)

Measured memory_bytes: 7740
x,y=map(int,input().split())
m=0
if x==1:
    m+=300000
elif x==2:
    m+=200000
elif x==3:
    m+=100000

if y==1:
    m+=300000
elif y==2:
    m+=200000
elif y==3:
    m+=100000

if x==1 and y==1:
    m+=400000

print(m)


Measured memory_bytes: 3060
#include<stdio.h>

int main() {
	int i,x,n;
	scanf("%d", &n);
	for(i = 1; i <= n; i++) {
		x = i;
		if(x % 3 == 0) {
			printf(" %d", i);
		}else{
			while(x != 0) {
				if(x % 10 == 3) {
					printf(" %d", i);
					break;
				}
				x /= 10;
			}
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 600
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

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

using namespace std;
typedef vector<int> veci;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define foreach(i, n) for (typeof(n) i = 0; i < (n); ++i)
#define foreach_eq(i, n) for (typeof(n) i = 0; i <= (n); ++i)
#define foreach_from(i, m, n) for (typeof(n) i = m; i < (n); ++i)
#define foreach_eq_from(i, m, n) for (typeof(n) i = m; i <= (n); ++i)

int dirctions[4][2] = {{0,-1}, {0,1}, {-1,0}, {1,0}};

#define BALL_NUM 10

int N;
int balls[BALL_NUM];

bool recur(int ix, int left, int right) {
    if (ix < 10) {
        return (left  < balls[ix] && recur(ix + 1, balls[ix], right))
            || (right < balls[ix] && recur(ix + 1, left, balls[ix]));
    } else {
        return true;
    }
}

int main() {
    cin >> N;
    foreach (n, N) {
        foreach (i, BALL_NUM) cin >> balls[i];
        cout << (recur(0,0,0) ? "YES" : "NO") << endl;
    }
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef complex<double> pnt;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, pii> pp;
typedef double ld;
typedef long double lld;
#define INF 0x3f3f3f3f // for int
#define LL_INF 0x3f3f3f3f3f3f3f3f // for ll
#define ms(x, y) memset(x, y, sizeof(x))
//coordinate compression:sort(val.begin(), val.end());
//		val.resize(unique(val.begin(), val.end()) - val.begin());
#define nl '\n'
typedef unsigned long long ull;
const lld pi = 3.14159265358979323846;
const int MOD = 1e9 + 7;

//remember to remove ios stuff if i use scanf

//printf("%05lld\n", x); --> print last 5 digits including 0's
//printf("%02d:%02d", h, m); --> time
ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll pwmd(ll b, ll exp) {
    ll ret = 1;
    while (exp > 0) {
        if (exp % 2 == 1) ret = (ret * b) % MOD;
        exp /= 2;
        b = (b * b) % MOD;
    }
    return ret;
}
//void RotateArr(int X) {
//    for (int n=0; n<X; n++) {
//        for (int i=0; i<N/2; i++) {
//            for (int j=0; j<N; j++) {
//                swap(a[i][j], a[N-i-1][j]);
//            }
//        }
//        for (int i=0; i<N; i++) {
//            for (int j=i+1; j<N; j++) {
//                swap(a[i][j], a[j][i]);
//            }
//        }
//    }
//}

/*
 * string input;
 *
 * stringstream ss(input);
 *- if the input contains '\n', separate lines with: string line; while (getline(ss, line))
 * - clear() to clear the stream
 * - >> : read smth from stringstream object ie. while (s >> word)
 */

struct pair_hash { //--> for unordered_set<pair<ll, ll>>
    //initialize the set with unordered_set<pair<ll, ll>, pair_hash>st
    inline std::size_t operator()(const std::pair<ll,ll> & v) const {
        return v.first*31+v.second;
    }
};
/* for dijkstra:
 * bool operator < (const E &other) const {
        return this->w > other.w;
    }
 */

ll a, b, c, d;

void solve(int tc) {

    cin >> a >> b >> c >> d;
    ll ans = -LL_INF;
    ans = max(ans, a * c);
    ans = max(ans, a * d);
    ans = max(ans, b * c);
    ans = max(ans, b * d);
    cout << ans << nl;

}

//you should really read the stuff at the bottom

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int tc = 1; //cin >> tc;
    for (int t = 1; t <= tc; t++) solve(t);

    return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
// Did you read the bounds?
// Did you make typos?
// Are there edge cases (N=1?)
// Are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
// Integer overflow?
// DS reset properly between test cases?
// Is using long longs causing TLE?
// Are you using floating points?
*/

Measured memory_bytes: 3644
#define f(X) for(c=0;c<X;c+=v[p++]);if(c-X)goto L;
n,v[50],s,p,c,a[9];main(){for(;n=atoi(gets(a));){for(s=0;s<n;v[++s]=strlen(gets(a)));s=0;L:p=++s;f(5)f(7)f(5)f(7)f(7)printf("%d\n",s);}}

Measured memory_bytes: 524
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <list>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <numeric>
#include <cmath>
#include <memory.h>
#include <algorithm>
#include <cassert>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef pair<ll, int> pli;
typedef vector<vector<int>> vvi;
#define mod 10000
#define PI acos(-1.0)
#define eps 1e-8
#define e 2.71828

typedef long long ll;

ll n, k, cnt;
vector<ll> nums, foo;
unordered_map<ll, ll> helper;

ll lowbit(ll x) {return x & -x;}

void add(ll x) {
    while (x <= cnt) {
        ++foo[x];
        x += lowbit(x);
    }
}

ll sum(ll x) {
    ll res = 0;
    while (x) {
        res += foo[x];
        x -= lowbit(x);
    }
    return res;
}

int main() {
    cin >> n >> k;
    vector<ll> tmp;
    ll s = 0;
    nums.push_back(0);
    tmp.push_back(0);
    for (int i = 1; i <= n; ++i) {
        ll num;
        scanf("%lld", &num);
        s += num;
        nums.push_back(s - k * i);
        tmp.push_back(s - k * i);
    }
    sort(tmp.begin(), tmp.end());
    cnt = 0;
    for (int i = 0; i <= n; ++i) {
        if (i == 0 || tmp[i] != tmp[i - 1]) {
            helper[tmp[i]] = ++cnt;
        }
    }
    for (int i = 0; i <= n; ++i) {
        nums[i] = helper[nums[i]];
    }
    foo.resize(cnt + 1);

    ll res = 0;
    for (int i = 0; i <= n; ++i) {
        res += sum(nums[i]);
        add(nums[i]);
    }
    cout << res;

    return 0;
}

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

h,w = map(int,input().split())
c = [list(input()) if i % 2 == 0 else [] for i in range(2*h)]

for i in range(h):
    c[2*i+1] = c[2*i]
for i in range(2*h):
    print(''.join(c[i]))


Measured memory_bytes: 3060
#include <iostream>
#define MOD 1000000007
using namespace std;
int len, tp[100002];
long long dp[100002][13];
string s;
long long f(int x, int y){
    if(dp[x][y] != -1)return dp[x][y];
    int d = (int)(s[len-x]-'0');
    long long res = 0;
    if(x == 1){
        if((s[len-x] == '?' && y <= 9)|| d == y){
            res = 1;
        }
        return dp[x][y] = res;
    }
    for(int i=0;i<10;i++){
        if(s[len-x] != '?' && d != i)continue;
        int z = y + (13 - i) * tp[x-1];
        res += f(x-1, z%13);
        
    }
    return dp[x][y] = res%MOD;
}
int main(void){
    cin >> s;
    len = s.length();
    for(int i=0;i<=len;i++){
        for(int j=0;j<13;j++){
            dp[i][j] = -1;
        }
        if(i==0)tp[0] = 1;
        else tp[i] = (tp[i-1]*10)%13;
    }
    cout << f(len, 5) << endl;
    for(int i=0;i<10;i++){
        //cout << i << " : " << f(len-1, i) << endl;
    }
}


Measured memory_bytes: 18816
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <climits>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <atcoder/all>
using namespace atcoder;
using namespace std;

using Pair = pair<int, int>;
using lint = long long;

#define rep(i, n) for (int i = 0; i < (n); i++)

// const int mod = 1e9 + 7;
// const int mod = 998244353;

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...));
}
int op(int a,int b){
    return max(a, b);
}
int e(){
    return 0;
}

int main() {
    int n, k;
    cin >> n >> k;
    segtree<int,op,e> s(300010);
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    rep(i,n){
        s.set(a[i],s.prod(max(0, a[i] - k), min(300010, a[i] + k + 1))+1);
    }
    cout << s.all_prod() << endl;
}


Measured memory_bytes: 8556
function main(input){
    var tmp = input.split(/\r\n|\r|\n/);
    var N = Number(tmp[0]);
    var K = Number(tmp[1]);

    var res = 1;
    var tmp2;
    for(var i=0; i<N; i++){
        tmp2 = res*2;
        res += K;
        if(tmp2<res){
            res = tmp2;
        }
    }

    console.log(res);

}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#define _USE_MATH_DEFINES
#define INF 100000000

#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

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

static const double EPS = 1e-8;

int main(){
	string str;
	int L;
	while(cin >> str >> L){
		if(L==0) break;
		map<string,int> freq;
		int idx = 0;
		int i,j,num;
		while(1){
			map<string,int>::iterator it;
			if((it = freq.find(str)) == freq.end()) freq[str] = idx;
			else {
				i = it->second;
				num = stoi(it->first);
				j = idx;
				break;
			}

			while(str.size() < L) str = "0" + str;
			string maxs = str;
			string mins = str;
			sort(maxs.begin(),maxs.end(),greater<char>());
			sort(mins.begin(),mins.end());

			int maxv = stoi(maxs);
			int minv = stoi(mins);

			int v = maxv - minv;
			string next = "";
			while(v > 0){
				next += (v % 10) + '0';
				v /= 10;
			}

			if(next.size()==0) next = "0";
			reverse(next.begin(),next.end());
			str = next;
			idx++;
		}

		printf("%d %d %d\n",i,num,j-i);
	}
}

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

int main(){
  int a;
  cin >> a;
  
  if ((a % 1000) % 111 == 0 || (a / 10) % 111 == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}

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

class Program
{
    static void Main()
    {
        const int inf = 1145141919;

        var n = int.Parse(Console.ReadLine());
        var d = new Dictionary<char, int>();

        for (var i = 'a'; i <= 'z'; i++)
            d.Add(i, inf);

        for (var i = 0; i < n; i++)
        {
            var s = Console.ReadLine();
            var td = new Dictionary<char, int>();

            for (var j = 'a'; j <= 'z'; j++)
                td.Add(j, 0);

            foreach (var c in s)
                td[c]++;

            for (var j = 'a'; j <= 'z'; j++)
                if (td[j] < d[j]) d[j] = td[j];
        }
        foreach (var p in d)
        {
            if (p.Value == inf) continue;

            for (var i = 0; i < p.Value; i++)
                Console.Write(p.Key);
        }
        Console.WriteLine();
    }
}

Measured memory_bytes: 11220