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

using namespace std;

using int64 = long long;

template< typename Monoid, typename OperatorMonoid = Monoid >
struct LazySegmentTree
{
  using F = function< Monoid(Monoid, Monoid) >;
  using G = function< Monoid(Monoid, OperatorMonoid) >;
  using H = function< OperatorMonoid(OperatorMonoid, OperatorMonoid) >;
  using P = function< OperatorMonoid(OperatorMonoid, int) >;

  int sz;
  vector< Monoid > seg, lazy;
  const F f;
  const G g;
  const H h;
  const P p;
  const Monoid M1;
  const OperatorMonoid OM0;


  LazySegmentTree(int n, const F f, const G g, const H h, const P p, const Monoid &M1, const OperatorMonoid OM0)
      : f(f), g(g), h(h), p(p), M1(M1), OM0(OM0)
  {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
    lazy.assign(2 * sz, OM0);
  }

  void set(int k, const Monoid &x)
  {
    seg[k + sz] = x;
  }

  void build()
  {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void propagate(int k, int len)
  {
    if(lazy[k] != OM0) {
      if(k < sz) {
        lazy[2 * k + 0] = h(lazy[2 * k + 0], lazy[k]);
        lazy[2 * k + 1] = h(lazy[2 * k + 1], lazy[k]);
      }
      seg[k] = g(seg[k], p(lazy[k], len));
      lazy[k] = OM0;
    }
  }

  Monoid update(int a, int b, const OperatorMonoid &x, int k, int l, int r)
  {
    propagate(k, r - l);
    if(r <= a || b <= l) {
      return seg[k];
    } else if(a <= l && r <= b) {
      lazy[k] = h(lazy[k], x);
      propagate(k, r - l);
      return seg[k];
    } else {
      return seg[k] = f(update(a, b, x, 2 * k + 0, l, (l + r) >> 1),
                        update(a, b, x, 2 * k + 1, (l + r) >> 1, r));
    }
  }

  Monoid update(int a, int b, const OperatorMonoid &x)
  {
    return update(a, b, x, 1, 0, sz);
  }


  Monoid query(int a, int b, int k, int l, int r)
  {
    propagate(k, r - l);
    if(r <= a || b <= l) {
      return M1;
    } else if(a <= l && r <= b) {
      return seg[k];
    } else {
      return f(query(a, b, 2 * k + 0, l, (l + r) >> 1),
               query(a, b, 2 * k + 1, (l + r) >> 1, r));
    }
  }

  Monoid query(int a, int b)
  {
    return query(a, b, 1, 0, sz);
  }

  Monoid operator[](const int &k)
  {
    return query(k, k + 1);
  }
};


int main()
{
  int N, Q;
  scanf("%d %d", &N, &Q);

  auto f = [&](int a, int b) { return min(a, b); };
  auto g = [&](int a, int b) { return b < 0 ? a : b; };
  auto p = [&](int a, int b) { return a; };
  LazySegmentTree< int > seg(N, f, g, g, p, INT_MAX, -1);

  while(Q--) {
    int T, X, Y;
    scanf("%d %d %d", &T, &X, &Y);
    if(T == 0) {
      int Z;
      scanf("%d", &Z);
      seg.update(X, Y + 1, Z);
    } else {
      printf("%d\n", seg.query(X, Y + 1));
    }
  }
}



Measured memory_bytes: 4960
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rem(i, s, n) for (int i = (s); i >= (n); --i)
using ll = long long;
const int MAX = 1e9+7;

int main(){
    ll h, w, k;
    cin >> h >> w >> k;
    vector<vector<char>> c(h, vector<char>(w));
    rep(i, 0, h) rep(j, 0, w) cin >> c[i][j];
    
    ll ans = 0;
    rep(y, 0, (1 << h)){
        rep(x, 0, (1 << w)){
            int count = 0;
            rep(i, 0, h){
                if(y & (1 << i)) continue;
                rep(j, 0, w){
                    if(x & (1 << j)) continue;
                    if(c[i][j] == '#') count++;
                }
            }
            if(count == k) ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  llong H, W;
  cin >> H >> W;

  if (H == 1 || W == 1) {
    cout << 1 << endl;
  }
  else {
    cout << (H / llong{2}) * W + (H % llong{2} == 1 ? (W + llong{1}) / llong{2}: llong{0}) << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

int main(){

    string a, b;
    cin >> a >> b;
    while(a.size() < b.size())a = "0" + a;
    while(a.size() > b.size())b = "0" + b;
    if(a == b)cout << "EQUAL" << endl;
    if(a < b)cout << "LESS" << endl;
    if(a > b)cout << "GREATER" << endl;

    return 0;
}

Measured memory_bytes: 256
import sys, io, os, re
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque
from fractions import gcd
from functools import reduce
from itertools import groupby
from heapq import heapify, heappush, heappop

# sys.setrecursionlimit(5000)

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

def array1(n, d=0): return [d] * n
def array2(n, m, d=0): return [[d] * m for x in range(n)]
def array3(n, m, l, d=0): return [[[d] * l for y in xrange(m)] for x in xrange(n)]
def linc(A, d=1): return map(lambda x: x + d, A)
def ldec(A, d=1): return map(lambda x: x - d, A)

S = s1()
T = s1()

count = 0
for s, t in zip(S, T):
    if s != t:
        count += 1

print(count)

Measured memory_bytes: 74008
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int K = scanner.nextInt();
    int[] v = new int[N];
    for (int i = 0; i < N; i++) v[i] = scanner.nextInt();

    long max = 0;
    for (int i = 0; i <= N; i++) {
      for (int j = 0; j <= N - i; j++) {
        if (i + j > K) continue;
        List<Integer> list = new ArrayList<>();
        for (int k = 0; k < i; k++) list.add(v[k]);
        for (int k = N - 1; k >= N - j; k--) list.add(v[k]);
        Collections.sort(list);
        int k = K - i - j;
        long sum = 0;
        for (int l = 0; l < list.size(); l++) {
          int vv = list.get(l);
          if (vv > 0 || l >= k) sum += vv;
        }
        max = Math.max(max, sum);
      }
    }
    System.out.println(max);
  }
}


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

int main() {
	string S;
	cin >> S;

	if(S == "SSS") cout << 0 << endl;
	if(S == "SSR") cout << 1 << endl;
	if(S == "SRR") cout << 2 << endl;
	if(S == "RRR") cout << 3 << endl;
	if(S == "RSS") cout << 1 << endl;
	if(S == "RSR") cout << 1 << endl;
	if(S == "RRS") cout << 2 << endl;
	if(S == "SRS") cout << 1 << endl;

}



Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
#include<assert.h>
//#include<windows.h>
using namespace std;
 
//#define int ll
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
struct edge {int /*from,*/to,cost;};

signed main(){
    int a,b;
    cin >> a >> b;
    int t = 1;
    int bb = b;
    while(bb/10) t++,bb/=10;
    int s = (int)pow(10,t) * a + b;
    for(int i = 1;i*i<=s;i++){
        if(i*i==s){
            puts("Yes");
            return 0;
        }
    }
    puts("No");

    return 0;
}



Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    
    if (n == 0) {
      System.out.println(1);
    } else {
      System.out.println(0);
    }
  }
}


Measured memory_bytes: 35604
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
long long  i,count=0,ans=0;
    for(i=0; i<s.size(); i++)
    {
        if(s[i]=='B')
            count++;
        else if(s[i]=='W')
            ans=ans+count;
    }
    cout<<ans;
}

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

int main() {
  string S;
  int N=0;
  cin >> S;
  for(int i=0; i<S.size(); i=i+2){
    if(S.substr(i,2)!="hi"){
      N=1;
      break;
    }
  }
  if(N==1) cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
#define fi first
#define se second
#define show(x) cout << #x << " is " << x << "\n";
const ll inf = 9e18;
const ll mod = 1e9 + 7;
const ld pi = 3.141592653589793238462643383279502884;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
	if(y<=0) return 1;
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

//------------------------------------------------------------------------------------------

//const ll N = 1e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<<fixed<<setprecision(10);

	ll n,k;
	cin>>n>>k;

	vi a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}

  	for(int i=0;i<k;i++){
	    vector<int> v(n+1,0);
	    for(int i=0;i<n;i++){
	    	v[max(0ll,i-a[i])]++;
	    	v[min(n,i+a[i]+1)]--;
	    }
	    int op=0;
	    bool flag=false;
	    for(int i=0;i<n;i++){
			op+=v[i];
	    	if(a[i]!=op)
				flag=true;
	    	a[i]=op;
	    }
		if(!flag) break;
	}
  	
	for(int i=0;i<n;i++){
		cout<<a[i]<<" ";
	}
	cout<<"\n";

    return 0;
}


Measured memory_bytes: 5716
#include <iostream>
#include <string>
using namespace std;
int n;
void dfs(string s, char mx) {
    if (s.length() == n) {
        cout << s << endl;
        return ;
    }
        for (char c = 'a'; c <= mx+1; c++) {
            string t = s;
            t += c;
            dfs(t, max(mx,c));
        }
    }
int main() {
    cin >> n;
dfs("",'a'-1);
    return 0;
}



Measured memory_bytes: 1536
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

a, b = input().split()
a2 = a * int(b)
b2 = b * int(a)
print(min(a2, b2))



Measured memory_bytes: 7876
A, B, C, X = io.read("*n", "*l"), io.read("*n", "*l"), io.read("*n", "*l"), io.read("*n", "*l")
counter = 0
for i = 0, A do
    for j = 0, B do
        for k = 0, C do
            if 500*i+100*j+50*k == X then
                counter = counter+1
            end
        end
    end
end
print(counter)

Measured memory_bytes: 1012
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
 
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}
 
const ll big=998244353;
int exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x)%big;
    ll t=exp(x,y/2);
    return (t*t)%big;
}
 
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(0);
    /*--------------------------------*/
    
    ll a,b,v,w,t;cin >> a >> v >> b >> w >> t;
    v-=w;
    a=max(a,b)-min(a,b);
    if(t*(v)>=a)cout << "YES";
    else cout << "NO";
    cout << endl;
}

Measured memory_bytes: 3608
from itertools import product, chain

H, W, K = map(int, input().split())
C = [input() for _ in range(H)]

sum_num = 0

for y in range(1<<H):
    for x in range(1<<W):
        s = [list(c) for c in C]
        for k in range(H):
            if (y>>k)%2:
                s[k] = ["X"]*W
        for k in range(W):
            if (x>>k)%2:
                for l in range(H):
                    s[l][k] = "X"
        black = sum(c=="#" for c in chain(*s))
        if black == K:
            sum_num += 1

print(sum_num)

Measured memory_bytes: 74432
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;
const int INF = 1000000;

int cost[1000][1000];


inline int toIndex(int h, int w) {
    return h*1000+w;
}

inline int indexToH(int index) {
    return index/1000;
}

inline int indexToW(int index) {
    return index%1000;
}


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

    int H, W, Ch, Cw, Dh, Dw;
    cin >> H >> W >> Ch >> Cw >> Dh >> Dw;
    --Ch;
    --Cw;
    --Dh;
    --Dw;

    vector<string> S(H);
    rep(i, H) cin >> S[i];

    vector<int> cost(1000000, INF);

    priority_queue<pair<int, int>> pq;  //! <-cost, index>

    pq.push({0, toIndex(Ch, Cw)});
    cost[toIndex(Ch, Cw)] = 0;

    int goalIndex = toIndex(Dh, Dw);
    int ans = INF;
    while (!pq.empty()) {
        pair<int, int> curr = pq.top(); 
        pq.pop();
        int currIndex = curr.second;
        int currH = indexToH(currIndex);
        int currW = indexToW(currIndex);
        // cout << "at " << currH << ", " << currW << endl;

        int currCost = -curr.first;
        if (cost[currIndex] < currCost) continue;
        int warpCost = currCost+1;
        for (int ox = -1; ox <= 1; ++ox) for (int oy = -1; oy <= 1; ++oy) {
            if (ox && oy) continue;
            int x = currW+ox;
            int y = currH+oy;
            if (x < 0 || W <= x || y < 0 || H <= y) continue;
            if (S[y][x] == '.') {
                int index = toIndex(y, x);
                if (currCost < cost[index]) {
                    cost[index] = currCost;
                    // cout << "Walk to " << y << ", " << x << ", cost = " << currCost << endl;
                    pq.push({-currCost, index});
                }
            }
        }
        for (int ox = -2; ox <= 2; ++ox) for (int oy = -2; oy <= 2; ++oy) {
            int x = currW+ox;
            int y = currH+oy;
            if (x < 0 || W <= x || y < 0 || H <= y) continue;
            if (S[y][x] == '.') {
                int index = toIndex(y, x);
                if (warpCost < cost[index]) {
                    cost[index] = warpCost;
                    // cout << "WARP to " << y << ", " << x << ", cost = " << warpCost << endl;
                    pq.push({-warpCost, index});
                }
            }
        }
        ans = cost[goalIndex];
    } 
    if (ans == INF) {
        ans = -1;
    }

    cout << ans << endl;

    return 0;
}


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

vector<int> G[100000];

int dist[2000][2000];

void bfs(int s) {
	dist[s][s] = 0;
	queue<int> q;
	q.push(s);
	while(q.size()) {
		int v = q.front();
		q.pop();
		int d = dist[s][v];
		for(auto to : G[v]) {
			if(dist[s][to] > d + 1) {
				dist[s][to] = d + 1;
				q.push(to);
			}
		}
	}
}

int color[100000];
struct S {
	int v, rem, t, color;

	bool operator <(const S& x) const {
		return t < x.t;
	}
};

typedef pair<int, int> P;

int dp[100000][11];
int check[100000][11];

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

	int N, M, Q;
	cin >> N >> M;
	for(int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	cin >> Q;

	priority_queue<S> q;
	memset(dp, -1, sizeof dp);
	for(int i = 0; i < Q; i++) {
		int v, d, c;
		cin >> v >> d >> c;
		v--;
		q.push({ v, d, i, c });
		for(int r = 0; r <= d; r++) {
			dp[v][r] = i;
		}
	}

	while(q.size()) {
		int v, rem, t, c;
		v = q.top().v;
		rem = q.top().rem;
		t = q.top().t;
		c = q.top().color;
		q.pop();
		if(dp[v][rem] > t) continue;
		if(color[v] == 0) color[v] = c;
		if(rem == 0) continue;

		//cerr << "v : " << v << ", t : " << t << endl;
		for(auto u : G[v]) {
			if(dp[u][rem - 1] < t) {
				dp[u][rem - 1] = t;
				for(int i = 0; i <= rem - 1; i++) {
					check[u][rem - 1] = 1;
				}
				q.push({ u, rem - 1, t, c });
			}
		}
	}

	for(int i = 0; i < N; i++) {
		cout << color[i] << endl;
	}
}

Measured memory_bytes: 26348
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;

const int sz = 100010;
int dp[sz][3][3][2];

int main(){
  string data;
  while(cin >> data && data != "#"){
    fill(&dp[0][0][0][0], &dp[0][0][0][0] + 2 * 3 * 3 * sz, INF);
    REP(i, 3)REP(j, 3) dp[0][i][j][0] = dp[0][i][j][1] = 0;
    
    REP(i, data.size()){
      int num = (data[i] - '1') % 3;
      REP(b, 3)REP(a, b + 1){
        dp[i+1][a][num][1] = min(dp[i+1][a][num][1],
                                 min(dp[i][a][b][0], dp[i][a][b][1] + 1));
        dp[i+1][num][b][0] = min(dp[i+1][num][b][0],
                                 min(dp[i][a][b][1], dp[i][a][b][0] + 1));        
      }
    }
    int res = INF;
    REP(b, 3)REP(a, b + 1) {
      res = min(res, dp[data.size()][a][b][0]);
      res = min(res, dp[data.size()][a][b][1]);
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 8348
#include<iostream>
using namespace std;
int main(){
	int n,k,ans;
	int num=1;
	cin>>n>>k;
	for (int i = 1; i < n; i++) {
		num *= k - 1;
	}
	ans = k*num;
	cout << ans << endl;

	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
vector<int> dx = {0,0,1,-1};
vector<int> dy = {1,-1,0,0};

int main(){
    int h,w;
    cin >> h >> w;
    int sx,sy,gx,gy;
    cin >> sy >> sx >> gy >> gx;
    --sy;--sx;--gy;--gx;
    vector<string> maze(h);
    vector<vector<bool>> seen(h,vector<bool>(w,false));
    rep(i,h) cin >> maze[i];
    auto id = [&](int y,int x){return y*w+x;};
    deque<P> q;
    q.push_back(P(id(sy,sx),0));
    int ans = -1;
    while(!q.empty()){
        int y = q[0].first / w;
        int x = q[0].first % w;
        int c = q[0].second;
        q.pop_front();
        if(seen[y][x]) continue;
        if(y==gy&&x==gx){
            ans = c;
            break;
        }
        seen[y][x]=true;
        rep(i,4){
            int new_y = y + dy[i];
            int new_x = x + dx[i];
            if(0<=new_y&&new_y<h&&0<=new_x&&new_x<w){
                if(seen[new_y][new_x]) continue;
                if(maze[new_y][new_x]=='#') continue;
                q.push_front(P(id(new_y,new_x),c));
            }
        }
        for(int i=-2;i<=2;i++){
            for(int j=-2;j<=2;j++){
                int new_y = y + i;
                int new_x = x + j;
                if(0<=new_y&&new_y<h&&0<=new_x&&new_x<w){
                    if(seen[new_y][new_x]) continue;
                    if(maze[new_y][new_x]=='#') continue;
                    q.push_back(P(id(new_y,new_x),c+1));
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6040
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        k: usize,
        h: [i64; n],
    }
    let mut dp = vec![std::i64::MAX; n];
    dp[0] = 0i64;
    for i in 0..n {
        for j in 1..k+1 {
            if i + j < n {
                dp[i+j] = min(dp[i+j], dp[i] + (h[i] - h[i+j]).abs());
            }
        }
    }
    println!("{}", dp[n-1]);
}


Measured memory_bytes: 6396
#include <cstdio>
#include <string>
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vll;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
vi a;
int main(){


string n;
cin>>n;
for(int i=0;i<n.size();i++)
{
    a.push_back(n[i]-'0');

}
string s =n;
      stringstream geek(s);
    int x = 0;
    geek >> x;
int max1=a[0];
if(a[0]*111 <x)
    if( a[1]*111 >=x)
    {
        cout<<a[0]+1<<a[0]+1<<a[0]+1;
    }else
   {
     cout<<a[1]+1<<a[1]+1<<a[1]+1;
   }
else
{
    cout<<max1<<max1<<max1;
}

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int n, m, k;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> m >> k;

  for(int i = 0; i <= n; i++) {
    for(int j = 0; j <= m; j++) {
      if (i * j + (n - i) * (m - j) == k) {
        puts("Yes");
        return 0;
      }
    }
  }

  puts("No");

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        
        String[] w = {"Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"};
        int[] d = {31,29,31,30,31,30,31,31,30,31,30,31};
        int sum = 0;
        
        while(true){
            sum = 0;
        	int a = sc.nextInt();
        	int b = sc.nextInt();
            
            if(a ==0 && b == 0){
               	break;
            }
            
        	for(int i = 0;i < a-1; i++){
         		sum += d[i];
        	}
            
        	sum = sum + b;
            
         
       		System.out.println( w[sum % 7]);
            
    	}
	}
}
        


Measured memory_bytes: 25936
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
int main(void){
    // Your code here!
    char w[110];
    int a[26],x;
    bool b=true;
    for(int i=0;i<26;i++){
        a[i]=0;
    }
    scanf("%s",w);
    for(int i=0;i<strlen(w);i++){
        x = w[i]-97;
        a[x]++;
    }
    for(int i=0;i<26;i++){
        if(a[i]%2!=0)
            b=false;
    }
    if(b==true) printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define PAUSE \
    int t;    \
    cin >> t
#define int long long
#define vi vector<long long>
#define mapii map<long long, int>
#define mapci map<char, int>
#define append(x) push_back(x)
#define tcase          \
    long long t;       \
    scanf("%lld", &t); \
    while (t--)
#define maxheap priority_queue<int>
#define minheap priority_queue<int, vector<int>, greater<int>>
#define fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
// #define debug(x, y) cout << "case #" << x << " at itr #" << y << endl
// #define debug(x) cout << "case #" << x << endl
#define ff first
#define ss second
#define range(ini, x) for (int itr = ini; itr < x; itr++)
#define takearr(x)    \
    for (auto &i : x) \
    cin >> i
#define print(x)     \
    for (auto i : x) \
        cout << i << " ";
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define foreach(i, x) for (auto i : x)
#define double long double
#define setbitcount __builtin_popcount

// #define range(ini, x, step) for( int itr = ini, i < x; itr += step )
using namespace std;
// using namespace __gnu_pbds;
// template < class type > using oset=tree<type, null_type,less<type>, rb_tree_tag,tree_order_statistics_node_update>;
const int mmx = 2e5 + 1;
const int mnx = 1e4 + 1;
const int mmod = 1e9 + 7;

int dp[mmx];

int fx(vi &arr, int idx)
{
    int n = arr.size();

    if (dp[idx] != -1)
    {
        return dp[idx];
    }

    if (idx + 2 < n)
    {
        dp[idx] = min(abs(arr[idx] - arr[idx + 1]) + fx(arr, idx + 1),
                      abs(arr[idx] - arr[idx + 2]) + fx(arr, idx + 2));
        return dp[idx];
    }

    if (idx + 1 < n)
    {
        dp[idx] = abs(arr[idx] - arr[idx + 1]) + fx(arr, idx + 1);
        return dp[idx];
    }

    if (idx == n - 1)
    {
        dp[idx] = 0;
        return dp[idx];
    }

    return 0;
}

signed main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int tcases;
    // cin >> tcases;
    tcases = 1;

    for (int __case = 1; __case <= tcases; __case++)
    {
        //cout << "Case #" << __case << ":";
        /* Code */
        memset(dp, -1, sizeof(dp));
        int N;
        cin >> N;
        vi arr(N);
        takearr(arr);
        cout << fx(arr, 0) << endl;
    }

    return 0;
}


Measured memory_bytes: 9596
H, W = map(int, input().split())
S = [0]*(H+2)
S[0] = '#'*(W+2)
S[H+1] = '#'*(W+2)
for h in range(1,H+1):
  S[h] = '#' + input() + '#'
mod = 10**9+7
dp = [[0]*(W+1) for _ in range(H+1)]
dp[1][1] = 1
for h in range(1,H+1):
  for w in range(1,W+1):
    if h==1 and w==1:
      continue
    if S[h][w]=='#':
      continue
    dp[h][w] += dp[h][w-1]+dp[h-1][w]
    dp[h][w] %= mod
print(dp[-1][-1])

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

const long long MX =1e18;

int main() {
  int n;
  cin >> n;
  long long ans=1;
  bool ng = false;
  rep(i,n){
    long long a;
    cin >> a;
    if(a==0){
      cout << 0 <<endl;
      return 0;
    }
    if(ng || (MX+1)/ans <a || ans*a > MX){
      ng =true;
    }
    ans*=a;
  }
  if(ng) cout << -1 <<endl;
  else cout <<ans <<endl;
  return 0;
}



  



Measured memory_bytes: 3644
import java.io.*;
import java.util.*;
//import java.util.Map.Entry;
//import java.util.stream.*;
//import java.math.*;

public class Main {

    public static int gcd(int a, int b) {
        return (b == 0) ? a : gcd(b, a % b);
    }

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int array[] = new int[n];
        forl_0(n, array, sc);
        Arrays.sort(array);
        long sum = 0;
        for (int i = 0; i < k; i++) {
            sum += array[i];
        }
        System.out.println(sum);
        bw.flush();
    }
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//

    static class Pair implements Comparable<Pair> {

        int a, b;

        public Pair(int x, int y) {
            a = x;
            b = y;
        }

        @Override
        public int compareTo(Pair p) {
            return a - p.a;
        }
    }

    static void forl_0(int n, int[] array, Scanner sc) {
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
    }

    static void forl_1(int n, int[] array, Scanner sc) {
        for (int i = 1; i <= n; i++) {
            array[i] = sc.nextInt();
        }
    }

    static void two_d(int n, int m, int[][] array, Scanner sc) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                array[i][j] = sc.nextInt();
            }
        }
    }

    static boolean isPrime(long n) {
        if (n < 2) {
            return false;
        } else if (n == 2 || n == 3) {
            return true;
        } else if (n % 2 == 0 || n % 3 == 0) {
            return false;
        }
        long sqrtN = (long) Math.sqrt(n) + 1;
        for (long i = 6L; i <= sqrtN; i += 6) {
            if (n % (i - 1) == 0 || n % (i + 1) == 0) {
                return false;
            }
        }
        return true;
    }
}


Measured memory_bytes: 30076
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <iostream>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define tii tuple<int,int,int>
#define pq priority_queue<ll>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}
int main(){
    int n=in();
    vector<vecll> child(n);
    vector<vecll> len(n,vecll(n,INT_MAX));
    rep(i,n){
        string s=stin();
        rep(j,n){
            if(s[j]=='1'){
                child[i].pb(j);
                len[i][j]=1;
            }
        }
    }
    vec a(n);
    a[0]=1;
    queue<ll> que;
    que.push(0);
    while(!que.empty()){
        ll t=que.front();
        que.pop();
        REP(e,child[t]){
            if(a[e]!=0){
                if(a[e]*a[t]==1){
                    cout<<-1<<endl;
                    return 0;
                }
            }else{
                a[e]=a[t]==1?-1:1;
                que.push(e);
            }
        }
    }
    rep(k,n)rep(i,n)rep(j,n){
        if(i!=j)len[i][j]=min(len[i][k]+len[k][j],len[i][j]);
    }
    ll ans=0;
    rep(i,n)rep(j,n){
        if(len[i][j]<INT_MAX){
            ans=max(ans,len[i][j]);
        }
    }
    cout<<ans+1<<endl;
}



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

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

	int c0=0, c1=0;
	for (int i = 0;i < s.size();i++) {
		if (s[i] == '0') { c0++; }
		else { c1++; }

	}

	cout << 2 * min(c0, c1) << endl;

}

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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define PB push_back
#define F first
#define S second

int main(){
    double n; cin >> n;
    cout << 3.1415 * 2 * n;
    return 0;
}

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

long long calc(long long n, long long b) { return n < b ? n : calc(n / b, b) + n % b;}

int main() {
    long long n, s;
    scanf("%lld%lld", &n, &s);
    long long answer = 1e18;
    if (n == s) answer = n + 1;
    for (long long i = 2; i * i <= n; ++i) if (calc(n, i) == s) {
        answer = min(answer, i);
    }
    for (long long i = 1; i * i <= n; ++i) if ((n - s) % i == 0) {
        long long b = (n - s) / i + 1;
        if (b > 1 && calc(n, b) == s) answer = min(answer, b);
    }
    printf("%lld\n", answer == 1e18 ? -1 : answer);
    return 0;
}

Measured memory_bytes: 384
from collections import deque

H, W = map(int, input().split())
que = deque()
A = [input() for i in range(H)]

dist = [[-1]*W for i in range(H)]
dd = ((-1, 0), (0, -1), (1, 0), (0, 1))
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            dist[i][j] = 0
            que.append((i, j))

d = 0
while que:
    y, x = que.popleft()
    d = dist[y][x]
    for dx, dy in dd:
        nx = x + dx; ny = y + dy
        if not 0 <= nx < W or not 0 <= ny < H or dist[ny][nx] != -1:
            continue
        dist[ny][nx] = d+1
        que.append((ny, nx))
print(d)

Measured memory_bytes: 88668
import bisect
n = int(input())
l = list(map(int,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,n)-j-1
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
using ll = long long;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll memoW[105][105];
ll memoB[105][105];

int main() {
    ll H,W;
    cin >> H >> W;
    ll isW[H][W];
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            char c;
            cin >> c;
            if(c == '.'){
                isW[yi][xi] = true;
            }else{
                isW[yi][xi] = false;
            }

            memoW[yi][xi] = -1;
            memoB[yi][xi] = -1;
        }
    }
    memoW[0][0] = isW[0][0] ? 0 : 1;
    memoB[0][0] = !isW[0][0] ? 0 : 1;
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            if(memoW[yi][xi] != -1){
                continue;
            }
            if(isW[yi][xi]){
                if(yi == 0){
                    memoW[yi][xi] = min(memoB[yi][xi - 1] + 1,memoW[yi][xi - 1]);
                    memoB[yi][xi] = min(memoW[yi][xi - 1] + 1,memoB[yi][xi - 1] + 1);
                }else{
                    if(xi == 0){
                        memoW[yi][xi] = min(memoB[yi - 1][xi] + 1,memoW[yi - 1][xi]);
                        memoB[yi][xi] = min(memoW[yi - 1][xi] + 1,memoB[yi - 1][xi] + 1);
                    }else{
                        memoW[yi][xi] = min(min(memoB[yi][xi - 1] + 1,memoW[yi][xi - 1]),min(memoB[yi - 1][xi] + 1,memoW[yi - 1][xi]));
                        memoB[yi][xi] = min(min(memoW[yi - 1][xi] + 1,memoB[yi - 1][xi] + 1),min(memoB[yi][xi - 1] + 1,memoW[yi][xi - 1]));
                    }
                }
            }else{
                if(yi == 0){
                    memoW[yi][xi] = min(memoB[yi][xi - 1],memoW[yi][xi - 1] )+ 1;
                    memoB[yi][xi] = min(memoB[yi][xi - 1],memoW[yi][xi - 1] + 1);
                }else{
                    if(xi == 0){
                        memoW[yi][xi] = min(memoB[yi - 1][xi],memoW[yi - 1][xi]) + 1;
                        memoB[yi][xi] = min(memoB[yi - 1][xi],memoW[yi - 1][xi] + 1);
                    }else{
                        memoW[yi][xi] = min(min(memoB[yi - 1][xi],memoW[yi - 1][xi]),min(memoB[yi][xi - 1],memoW[yi][xi - 1] )) + 1;
                        memoB[yi][xi] = min(min(memoB[yi][xi - 1],memoW[yi][xi - 1] + 1),min(memoB[yi - 1][xi],memoW[yi - 1][xi] + 1));
                    }
                }
            }
        }
    }
    cout << memoW[H - 1][W - 1] << endl;

}



Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N, M;
  cin>>N>>M;
  ll ans = 0;
  for(ll i=1;i*i<=M;++i) {
    if(M%i==0) {
      if(M/i>=N) ans = max(ans, i);
      if(i>=N) ans = max(ans, M/i);
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3644
H,W,N=map(int, input().split())
D={}
for i in range(N):
  a,b=map(int, input().split())
  a-=1
  b-=1
  for j in range(3):
    for k in range(3):
      x,y=a-j,b-k
      if 0<=x and x+2<H and 0<=y and y+2<W:
        d=(x,y)
        if d not in D:
          D[d]=1
        else:
          D[d]+=1
A=[0]*10
for i in D.values():
  A[i]+=1
A[0]=(W-2)*(H-2)-sum(A)
for i in A:
  print(i)

Measured memory_bytes: 163980
(a, b, c, d) = map(int, list(input()))

if a+b+c+d == 7:
    print(str(a) + '+' + str(b) + '+' + str(c) + '+' + str(d) + '=7')
elif a+b+c-d == 7:
    print(str(a) + '+' + str(b) + '+' + str(c) + '-' + str(d) + '=7')
elif a+b-c+d == 7:
    print(str(a) + '+' + str(b) + '-' + str(c) + '+' + str(d) + '=7')
elif a-b+c+d == 7:
    print(str(a) + '-' + str(b) + '+' + str(c) + '+' + str(d) + '=7')
elif a+b-c-d == 7:
    print(str(a) + '+' + str(b) + '-' + str(c) + '-' + str(d) + '=7')
elif a-b+c-d == 7:
    print(str(a) + '-' + str(b) + '+' + str(c) + '-' + str(d) + '=7')
elif a-b-c+d == 7:
    print(str(a) + '-' + str(b) + '-' + str(c) + '+' + str(d) + '=7')
elif a-b-c-d == 7:
    print(str(a) + '-' + str(b) + '-' + str(c) + '-' + str(d) + '=7')

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

int main() {
    string s;
    cin >> s;
    int ans = 0;
    rep(i,3) {
        if(s[i] == '1') ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n; cin >> n;
    VI a(n); cin >> a;
    int ans = 0;
    FOR(i, 0, n) {
        int k = i;
        FOR(j, i + 1, n)if (a[k] > a[j])k = j;
        if (k != i) {
            ++ans;
            swap(a[i], a[k]);
        }
    }
    FOR(i, 0, n)cout << a[i] << ENDL(i, n);
    cout << ans << "\n";
}


Measured memory_bytes: 3172
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

typedef pair<int,int> P;

int main(){
	int n,x[500],a[500 * 500] = {};
	cin >> n;
	vector<P> vec;
	for(int i = 0;i < n;i++) {
		cin >> x[i];
		vec.push_back(P(x[i] - 1,i + 1));
	}
	sort(vec.begin(),vec.end());
	int pos = 0;
	for(int i = 0;i < n;i++){
		int index = vec[i].first,v = vec[i].second;
		for(int j = 0;j < v - 1;j++){
			while(pos < index && a[pos]) pos++;
			if(pos >= index){
				cout << "No" << endl;
				return 0;
			}
			a[pos] = v;
		}
		a[index] = v;
	}
	reverse(vec.begin(),vec.end());
	pos = n * n - 1;
	for(int i = 0;i < n;i++){
		int index = vec[i].first,v = vec[i].second;
		for(int j = 0;j < n - v;j++){
			while(pos > index && a[pos]) pos--;
			if(pos <= index){
				cout << "No" << endl;
				return 0;
			}
			a[pos] = v;
		}
	}
	cout << "Yes" << endl;
	for(int i = 0;i < n * n;i++) cout << (i ? " " : "") << a[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 2176
import sys


#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a, b):
    r = [1, 0, a]
    w = [0, 1, b]
    while w[2] != 1:
        q = r[2] // w[2]
        r2 = w
        w2 = [r[0] - q * w[0], r[1] - q * w[1], r[2] - q * w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0], w[1]]


# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a, m):
    x = extgcd(a, m)[0]
    return (m + x % m) % m


readline = sys.stdin.readline
MOD_NUM = 10**6 + 3

Q = int(readline())
q_array = [list(map(int, readline().split())) for i in range(Q)]
ans_array = []

factorial = [1] * MOD_NUM
factorial_inv = [1] * MOD_NUM

tmp = 1
for i in range(2, MOD_NUM):
    tmp = tmp * i % MOD_NUM
    factorial[i] = tmp
    factorial_inv[i] = mod_inv(tmp, MOD_NUM)

for q in q_array:
    x, d, n = q
    # print(x, d, n)
    if x == 0:
        ans_array.append("0\n")
        continue
    if d == 0:
        ans = pow(x, n, MOD_NUM)
        ans_array.append(str(ans) + "\n")
    else:
        x_start = x * mod_inv(d, MOD_NUM) % MOD_NUM
        if x_start + n > MOD_NUM:
            ans_array.append("0\n")
        else:
            ans = factorial[x_start + n - 1] * factorial_inv[
                x_start - 1] * pow(d, n, MOD_NUM) % MOD_NUM
            ans_array.append(str(ans) + "\n")

sys.stdout.writelines(ans_array)

Measured memory_bytes: 84252
A,B,K=map(int,input().split())
if A-K<=0 and A+B-K<=0:
    A=0
    B=0
elif A-K<=0 and A+B-K>0:
    B=A+B-K
    A=0
elif A-K>= 0:
    A=A-K
print(str(A)+" "+str(B))

Measured memory_bytes: 3060
#include <stdio.h>
#define loop(a,b) for(int i=a;i<b;i++)
#define loop2(a,b) for(int j=a;j<b;j++)
#define loop3(a,b) for(int k=a;k<b;k++)
int main(){
	
	int N;
	scanf("%d", &N);
	long long int arr[N];
	loop(0,N){
		scanf("%lld", &arr[i]);
	}
	int count=0;
	for(int i=0;i<N-2;i++){
		for(int j=i+1;j<N-1;j++){
			if(arr[i] == arr[j]){	
				continue;
			} else {
				for(int k=j+1;k<N;k++){
					if(arr[i]==arr[k] || arr[j]==arr[k]){
						continue;
					} else if(arr[i] + arr[k] <= arr[j] || arr[i] + arr[j] <= arr[k] || arr[j] + arr[k] <= arr[i]){
						continue;
					} else {
						count = count + 1;
					}
				}
			}		
		}
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 1732
#include <stdio.h>
#define N 100

int main(){

  int n,i,j,temp,flag=0;
  int array[N];

  scanf("%d",&n);

  for(i=0;i<n;i++)
    scanf("%d",&array[i]);

  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(array[j]<array[j-1]){

	temp=array[j];
	array[j]=array[j-1];
	array[j-1]=temp;
	flag++;

      }

    }
  }

  for(i=0;i<n-1;i++)
    printf("%d ",array[i]);

printf("%d",array[n-1]);
  printf("\n");
  printf("%d\n",flag);
  
  return 0;
}
  
  

Measured memory_bytes: 2704