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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N;
    Scd(N);

    char s3[5][5] = {
        "bbc",
        "a.c",
        "add"
    };

    char s4[6][6] = {
        "abcc",
        "abdd",
        "eegh",
        "ffgh"
    };

    char s5[7][7] = {
        "aabbc",
        "h.jjc",
        "hi..d",
        "gi..d",
        "gffee"
    };

    char s7[8][8] = {
        "n...ooz",
        "n...k.z",
        "i...kss",
        "iamm...",
        "sa.a...",
        "syya...",
        ".iinnoo"
    };

    pii dp[1012] = {};
    Rep(i,N+3) dp[i] = {0,-2};
    dp[3] = {3,-2};
    dp[6] = {3,3};
    dp[0] = {0,0};
    Rep(i,N){
        if( i == 3 ) continue;
        if( i == 6 ) continue;
        if( dp[i].second == -2 ) continue;
        if( dp[i+7].first == 0 ) dp[i+7].first = 7, dp[i+7].second = i;
        if( dp[i+4].first == 0 ) dp[i+4].first = 4, dp[i+4].second = i;
        if( dp[i+5].first == 0 ) dp[i+5].first = 5, dp[i+5].second = i;
    }

    if( N == 2 ) {
        printf ("%d\n", -1 );
        return 0;
    }

    char ans[1002][1002];

    Rep(i,N){
        Rep(j,N) ans[i][j] = '.';
    }

    int n = N;
    int m;
    int r,c;
    while(n>0){
        m = dp[n].first;
        Rep(i,m) Rep(j,m) {
            r = n-m+i, c = n-m+j;
            if( m == 3 ) ans[r][c] = s3[i][j];
            if( m == 4 ) ans[r][c] = s4[i][j];
            if( m == 5 ) ans[r][c] = s5[i][j];
            if( m == 7 ) ans[r][c] = s7[i][j];
        }
        n = dp[n].second;
    }

    Rep(i,N) printf ("%s\n", ans[i] );

    return 0;
}



Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        System.out.println(Math.min(A, B)+Math.min(C, D));
	}

}

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

using namespace std;

bool BinarySerach(const vector<int> &S,int &key)
{
	int start = 0;
	int end = S.size() - 1;
	int middle;
	
	while(1){
		middle = (end - start)/2 + start;
		if(S[middle] == key){
			return true;
		}else if(start == end){
			return false;
		}else if(S[middle] < key){
			start = middle + 1;
		}else if(S[middle] > key){
			end = middle;
		}
	}
} 

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n,q;
	vector<int> S;
	
	cin >> n;
	S.resize(n);
	
	for(int i=0; i<n; i++){
		cin >> S[i];
	}
	cin >> q;
	int count = 0;
	for(int i=0; i<q;i++){
		int key;
		cin >> key;
		if(BinarySerach(S,key)){
			count++;
//			cout << "key:" << key << endl;
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 1536
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

int main(void)
{
    int val;
    cin >> val;

    int dig1 = val%10;

    if(dig1 == 2 | dig1 == 4 | dig1 == 5| dig1 == 7 | dig1== 9){
        cout << "hon\n";
    } else if(dig1 == 0 | dig1 == 1 | dig1 == 6 | dig1 == 8){
        cout << "pon\n";
    } else {
        cout << "bon\n";
    }

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
using Graph = vector<vector<ll>>;
#define all(x) (x).begin(), (x).end() //string の sort とかはこれ
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

const ll MOD = 1000000007;
const ll INF = 1e18; //1*10^18
const double PI = 3.14159265;

int ctoi(char c)
{
  if (c >= '0' && c <= '9')
  {
    return c - '0';
  }
  return 0;
}

ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }
//最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//最小公倍数

ll powll(ll a, ll n)
{ //O(log n)
  ll res = 1;
  while (n > 0)
  {
    if (n & 1) //(n & 1)=(n % 2 !=0)
    {
      res = res * a;
    }
    a = a * a;
    n >>= 1; //(n & 1)=(n % 2 !=0)
  }
  return res;
}

ll modpow(ll a, ll n, ll mod) //O(log n)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1) //(n & 1)=(n % 2 !=0)
    {
      res = res * a % mod;
    }
    a = a * a % mod;
    n >>= 1; //(n>>=1)=(n/2)
  }
  return res;
}

int ReturnDigit(ll num)
{
  string number = to_string(num);
  return number.length();
}

const ll MAX = 1e6;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() //MODは素数じゃないとだよ！！
{
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++)
  {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k)
{
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind
{
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

  UnionFind(int N) : par(N)
  { //最初は全てが根であるとして初期化
    for (int i = 0; i < N; i++)
      par[i] = i;
  }

  int root(int x)
  { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x)
      return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y)
  {                   // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry)
      return;     //xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }

  bool same(int x, int y)
  { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main()
{
  // COMinit();
  // srand((unsigned int)time(NULL));//--> rand()
  ll i, j, k, l, ans = 0;
  ll x, yen = 100;
  cin >> x;

  i = 0;
  while (yen < x)
  {
    yen += yen / 100;
    i++;
  }
  cout << i << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    ld w,h,x,y; cin >> w >> h >> x >> y;
    cout<<w*h/2<<' '<<(x*2==w && y*2==h)<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int inputInt;
		int i = 1;
		while ( true ) {
			inputInt = Integer.parseInt ( sc.nextLine () );
			if ( inputInt == 0 ) {
				break;
			}

			sb.append ( "Case " + i + ": " + inputInt + "\n" );
			i++;
		}

		System.out.print ( sb );
	}
}

Measured memory_bytes: 58784
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int x;
  cin >> x;
  for(int i=1;i<954;++i){
    if(100*i<=x && x<=105*i && x <= 100000){
      cout << 1 << endl;
      return 0;
    }
  }
  cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 300001
using namespace std;
typedef long long ll;
ll n,q,S,T;

ll calc(ll a){
  if(a>0) return -a*S;
  return -a*T;
}


int main(){
  cin>>n>>q>>S>>T;

  ll A[N],B[N];
  for(int i=0;i<=n;i++)cin>>B[i];

  for(int i=1;i<=n;i++)A[i]=B[i]-B[i-1];
  
  ll ans=0;
  for(int i=0;i<=n;i++)ans+=calc(A[i]);
  
  while(q--){
    ll L,R,X;
    scanf("%lld%lld%lld",&L,&R,&X);
    ans -= calc(A[L])+calc(A[R+1]);
    A[L] += X;
    A[R+1] -=X;
    A[n+1] = 0;
    ans += calc(A[L])+calc(A[R+1]);
    printf("%lld\n",ans);
  }
  
  return 0;
}

Measured memory_bytes: 6332
from __future__ import  print_function
import sys

if sys.subversion[0] == "PyPy":
    import io, atexit

    sys.stdout = io.BytesIO()
    atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))

    sys.stdin = io.BytesIO(sys.stdin.read())
    input = lambda: sys.stdin.readline().rstrip()
RS = raw_input
RA = lambda x=int: map(x, RS().split())
RN = lambda x=int: x(RS())


def solve():
    num = 0
    visited = set()
    stack = []
    for i in range(h):
        for j in range(w):
            if (not s[i][j] == "#") and (not i*h + j in visited):
                visited.add(i*h + j)
                who[i][j] = num
                stack.append((i,j))
                while stack:
                    cur = stack.pop()
                    who[cur[0]][cur[1]] = num
                    for nb in getnb(cur[0], cur[1]):
                        ii = nb[0]
                        jj = nb[1]
                        if (not s[ii][jj] == "#") and (not ii*h + jj in visited):
                            stack.append(nb)
                            visited.add(ii*h + jj)
                num += 1
    #
    # for row in who:
    #     print(*row)
    edges = [set() for _ in range(num)]
    for i in range(h):
        for j in range(w):
            cg = who[i][j]
            if not cg == -1:
                for a in range(0, 3):
                    for b in range(-2, 3):
                        if 0 <= i+a < h and 0<= j+b < w:
                            ng = who[i+a][j+b]
                            if ng not in (-1, cg) and (ng not in edges[cg]):
                                edges[cg].add(ng)
                                edges[ng].add(cg)
    # final bfs
    start = who[ch-1][cw-1]
    goal = who[dh-1][dw-1]
    count = 0
    stack = [start]
    visited = set()
    while stack:
        new_stack = []
        for el in stack:
            if not el in visited:
                visited.add(el)
                if el == goal:
                    print(count)
                    exit()
                new_stack.extend(list(edges[el]))
        stack = new_stack
        count += 1
    print(-1)
    exit()

    return


def getnb(i, j):
    nb = []
    if i > 0:
        nb.append((i-1, j))
    if i < h-1:
        nb.append((i+1, j))
    if j > 0:
        nb.append((i, j -1))
    if j < w-1:
        nb.append((i, j +1))
    return nb








h, w = RA()
ch, cw = RA()
dh, dw = RA()
s = [list(raw_input()) for _ in range(h)]
who = [[-1 for _ in range(w)] for _ in range(h)]
solve()

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

int main() {
	// your code goes here
	long long int n = 0, m = 0, a = 0, b = 0, c = 0;
	cin >> n >> m;
	string s;
	cin >> s;
	s[m - 1] -= ('A' - 'a');
	cout << s << endl;
	
	

	return 0;
}

Measured memory_bytes: 256
IDENTIFICATION DIVISION.
       PROGRAM-ID. ATCODER.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  indata PIC X(100).
       01  a1 PIC 9(08).
       01  a2 PIC 9(08).
       01  a3 PIC 9(08).
       01  r pic 9(08).
       01 disp pic Z(10)9.
       PROCEDURE DIVISION.
        ACCEPT indata.
        
        UNSTRING indata DELIMITED BY SPACE INTO a1 a2 a3.

        COMPUTE r = a3 - (a1 - a2)

         IF a2 + a3 <= a1 THEN
           DISPLAY "0"
         ELSE
          MOVE FUNCTION TRIM(r) to disp
          DISPLAY disp
         END-IF


       STOP RUN.


Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>


using namespace std;
#define i64  long long

void solve(void)
{
  i64 N;
  cin>>N;

  string str;
  vector<string> v_str;

  
  for (i64 i = 0; i < N; i++)
  {
    cin>>str;
    sort(str.begin(),str.end());
    v_str.push_back(str);
  }

  i64 count = 0;
  i64 Comb_e = 1;
  i64 comb = 0;
  sort(v_str.begin(),v_str.end());
  for (i64 i = 0; i < N -1; i++)
  {
    if(v_str[i] == v_str[i+1])
    count++;
    else
    {
      Comb_e = count*(count +1 )/2;
      comb += Comb_e;
      count = 0;
    }
    
  }

      Comb_e = count*(count +1 )/2;
      comb += Comb_e;

  cout<<comb;
  
  
  
  return;
  
}
int main(int argc, const char *argv[])
{

  solve();

  return 0;
}


Measured memory_bytes: 5748
#include<iostream>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<stack>
#include<unordered_map>
#include<bitset>
#include<limits>
#include<complex>
#include<array>
#include<numeric>
#include<functional>

using namespace std;
#define ll long long
#define ull unsigned long long
#define rrep(i,m,n) for(ll (i)=(ll)(m);(i)>=(ll)(n);(i)--)
#define rep(i,m,n) for(ll (i)=(ll)(m);i<(ll)(n);i++)
#define REP(i,n) rep(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
constexpr long double m_pi = 3.1415926535897932L;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 61;
constexpr long double EPS = 1e-10;
template<typename T> using vector2 = vector<vector<T>>;
template<typename T> using vector3 = vector<vector2<T>>;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
string operator*(const string& s, int k) {
	if (k == 0) return "";
	string p = (s + s) * (k / 2);
	if (k % 2 == 1) p += s;
	return p;
}

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

template<typename T, typename F>
class SlidingWindowAggregation {
private:
	vector<T> back, front;
	vector<T> front_accum;
	T back_accum, identity;
	F merge;
public:
	SlidingWindowAggregation(F f, T id) :merge(f), identity(id) {
		back_accum = id;
		front_accum.push_back(id);
	};
	void push(T x) {
		back.push_back(x);
		back_accum = merge(back_accum, x);
	}
	bool pop() {
		if (front.size()) {
			front.pop_back();
			front_accum.pop_back();
			return true;
		}
		if (back.size() == 0)return false;
		while (back.size() != 1) {
			front.push_back(back.back());
			front_accum.push_back(merge(back.back(), front_accum.back()));
			back.pop_back();
		}
		back.pop_back();
		back_accum = identity;
		return true;
	}
	T fold_all() {
		return merge(front_accum.back(), back_accum);
	}
	int size() {
		return front.size() + back.size();
	}
};


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


	string s;
	cin >> s;
	ll n = s.size();

	Array sum(n + 1, 0);
	ll mx = 0;
	REP(i, n)sum[i + 1] = sum[i] + (s[i] == '1' ? 1 : -1), chmax(mx, sum[i + 1]);
	auto f = [](P a, P b)->P {return { max(a.first,b.first),min(a.second,b.second) }; };
	P id = { -INF,INF };

	auto calc = [&](ll mx) {
		SlidingWindowAggregation<P, decltype(f)> swag(f, id);
		REP(i, n)swag.push({ sum[i + 1],sum[i + 1] });
		ll mn = 0;
		ll d = 0;
		REP(i, n) {
			auto r = swag.fold_all();
			if (s[i] == '?' && r.first + d + 2 <= mx)d += 2;
			swag.pop();
			chmin(mn, sum[i + 1] + d);
		}
		return mx - mn;
	};
	ll ans = INF;
	chmin(ans, calc(mx));
	chmin(ans, calc(mx + 1));

	cout << ans << "\n";

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Q;
    string S;
    cin >> N >> S >> Q;
    vector<set<int>> m(26);
    for (int i = 0; i < N; i++) {
        m[S[i] - 'a'].insert(i);
    }
    while (Q--) {
        int type;
        cin >> type;
        if (type == 1) {
            int i;
            char c;
            cin >> i >> c;
            i--;
            m[S[i] - 'a'].erase(i);
            m[c - 'a'].insert(i);
            S[i] = c;
        } else {
            int l, r;
            cin >> l >> r;
            l--;
            r--;
            int val = 0;
            for (int i = 0; i < 26; i++) {
                auto lb = m[i].lower_bound(l);
                if (*lb <= r && lb != m[i].end()) {
                    val++;
                }
            }
            cout << val << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 25116
#include <stdio.h>
int main(void){
 int k, a, b;
 scanf("%d", &k);
 scanf("%d%d", &a, &b);

for(int i = a; i <= b; i++){
    if(i % k == 0){
        printf("OK");
        return 0;
    }
}

printf("NG");
return 0;
}

Measured memory_bytes: 1732
#define ll long long
#define ffor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;

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

	int n;
	cin >> n;
	int a[101];

	rep(i,n) cin >> a[i];

	map<string,int> mp;

	int gray=0,brown=0,green=0,sky=0,blue=0,yellow=0,orange=0,red=0,w=0;
	rep(i,n){
		if(1 <= a[i] && a[i] <= 399) gray = 1;
		else if(400 <= a[i] && a[i] <= 799) brown = 1;
		else if(800 <= a[i] && a[i] <= 1199) green = 1;
		else if(1200 <= a[i] && a[i] <= 1599) sky = 1;
		else if(1600 <= a[i] && a[i] <= 1999) blue = 1;
		else if(2000 <= a[i] && a[i] <= 2399) yellow = 1;
		else if(2400 <= a[i] && a[i] <= 2799) orange = 1;
		else if(2800 <= a[i] && a[i] <= 3199) red =1;
		else w += 1;
	}

	int count_0 = 0;

	if(gray == 0) count_0++;
	if(brown==0) count_0++;
	if(green==0) count_0++;
	if(sky==0) count_0++;
	if(blue==0) count_0++;
	if(yellow==0) count_0++;
	if(orange==0) count_0++;
	if(red == 0) count_0++;
	int count_1 = 8 - count_0;

	int ans_min,ans_max;
	int others = gray + brown + green + sky + blue + yellow + orange + red;
	if(w == 0){
		ans_min = others;
		ans_max = others;
	}
	else{
		if(others != 0){
			ans_min = others;
			ans_max = others + w;
		}
		else{
			ans_min = 1;
			ans_max = w;
		}
	}



	cout << ans_min << " "<< ans_max << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int a[4][100005];
int f[100005][4];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	   scanf("%d%d%d",&a[1][i],&a[2][i],&a[3][i]);
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=3;++j)
		{
			for(int k=1;k<=3;++k)
			{
				if(j==k) continue;
				f[i][j]=max(f[i][j],f[i-1][k] + a[k][i]) ;
			}
			//cout<<f[i][j]<<" ";
		}
		//cout<<endl;
	}
	int ans=0;
	for(int i=1;i<=3;++i) 
	   ans=max(ans,f[n][i]);
	printf("%d\n",ans);
	return 0;
 } 

Measured memory_bytes: 6548
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b,c,d,e,f;
  int A,B,C,mins,ans,ans2;
  while(1){
    cin>>a>>b>>c>>d>>e>>f;
    if(!a&&!b&&!c&&!d&&!e&&!f)break;
    A=a+d;
    B=b+e;
    C=c+f;
    mins=min(A,min(B,C));
    ans2=0;
    for(int i=0;i<2;i++){
      ans=0;
      ans+=(A-mins)/3;
      ans+=(B-mins)/3;
      ans+=(C-mins)/3;
      A=A-((A-mins)/3)*3;
      B=B-((B-mins)/3)*3;
      C=C-((C-mins)/3)*3;
      ans=max(ans+A/3+B/3+C/3,ans+mins);
      ans2=max(ans2,ans);
      if(mins>=1)mins--;
      else break;
      A=a+d;
      B=b+e;
      C=c+f;
    }
    cout<<ans2<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long   ll;
typedef unsigned long long   ull;
typedef long double ld;
typedef pair<ll, ll>    pll;
typedef pair<ull, ull>    pull;
typedef pair<ll, ll>  pii;
typedef pair<ld, ld>  pld;
ll n;
ll dp[25][(1<<21)+10];
vector<ll> g[25];
ll mod = 1e9+7;
ll f(ll idx, ll bit){
    if(dp[idx][bit] != -1)
        return dp[idx][bit];
    if(idx == 0 && bit == (1<<n)-1)
        return dp[idx][bit] = 1;
    if(idx == 0)
        return dp[idx][bit] = 0;
    dp[idx][bit] = 0;
    for(auto u : g[idx-1]){
        if((bit&(1<<u)) == 0){
            dp[idx][bit] += f(idx-1, bit + (1<<u));
            dp[idx][bit] %= mod;
        }
    }

    return dp[idx][bit]; 
}
int main() {
    

    cin >> n;
    int tmp;
    for(ll i = 0; i < n; ++i)
        for(ll j = 0; j < n; ++j){
            cin >> tmp;
            if(tmp == 1)
                g[i].pb(j);
        }
    dp[0][(1<<n)-1] = 1;
    ll ans = 0;
    for(ll i = 0; i <= n; ++i)
        for(ll j = 0; j < (1<<n); ++j)
            dp[i][j] = -1;
    cout << f(n, 0) << "\n";
}

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

// Shortening code
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;

// Macros
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = a; i >= b; i--)

const ll INF = 1e18;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    // Your code
    ll n, W;
    cin >> n >> W;

    vi w(n), v(n);
    int sum_value = 0;
    REP(i, 0, n)
    {
        cin >> w[i] >> v[i];
        sum_value += v[i];
    }
    // The minimum total weight of items with total value exactly i
    vector<ll> dp(sum_value + 1, INF);
    dp[0] = 0;
    REP(i, 0, n)
    {
        RREP(j, sum_value - v[i], 0)
        {
            dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]);
        }
    }
    ll maxIndex = 0;
    REP(i, 0, sum_value + 1)
    {
        if (dp[i] <= W)
        {
            maxIndex = max((ll)i, maxIndex);
        }
    }
    cout << maxIndex;
    return 0;
}

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

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

using ll = long long int;
const ll MOD = 1e9 + 7;

int main() {
  int N, M;
  std::cin >> N >> M;
  int cost = 0;
  rep(i, M) {
    int A;
    std::cin >> A;
    cost += A;
  }

  if(N < cost) {
    std::cout << "-1" << '\n';
    return 0;
  } else {
    std::cout << N - cost << '\n';
  }
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
	int n,m;
	cin>>n>>m;
	vi d(2*n);
	rep(i,0,2*n) d[i]=i;
	rep(i,0,m){
		int op;
		cin>>op;
		vi tmp(2*n);
		if(op==0){
			rep(i,0,n){
				tmp[2*i]=d[i];
			}
			rep(i,n,2*n){
				tmp[2*(i-n)+1]=d[i];
			}
		}else{
			rep(i,0,op){
				tmp[i+2*n-op]=d[i];
			}
			rep(i,op,2*n){
				tmp[i-op]=d[i];
			}
		}
		d=tmp;
	}
	rep(i,0,2*n) o(d[i]+1);
}

Measured memory_bytes: 1216
n,m = map ( int , input().split())
ml,mr = (1,n)
for i in range(m):
  l,r = map(int,input().split())
  l = max(ml,l)
  r = min(mr,r)
  ml,mr = (l,r)
ans = max(0,r - l + 1)
print(ans)

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

using namespace std;

#define int long long

int32_t main()
{
    int a,b,k;
    cin>>a>>b>>k;
    if(a<=k){
        int t=k-a;
        if(b-t<0)
        cout<<"0"<<' '<<"0"<<endl;
        else
        cout<<"0"<<' '<<b-t<<endl;
    }
    else{
        if(a-k<0)
        cout<<"0"<<' '<<b<<endl;
        else
        cout<<a-k<<' '<<b<<endl;
    }
}


Measured memory_bytes: 256
def f():
    if (A+B) <= C*2:
        return A*X+B*Y
    elif X==Y:
        return X*C*2
    else:
        if X > Y:
            if A > C*2:
                return (C*2)*(X-Y)+Y*C*2
            return A*(X-Y)+Y*C*2
        else:#Yの方が多い
            if B > C*2:
                return (C*2)*(Y-X)+X*C*2
            return B*(Y-X)+X*C*2
A,B,C,X,Y = map(int,input().split())
print(f())

Measured memory_bytes: 38384
#include <iostream>
using namespace std;
long long nc2(int s){
    long long x=1;
    for(int i=2; i<s; i++){
        x +=i;
    }
    return x;
}
int main()
{

    int n,m,b,g;
    cin>>n>>m;
    if (n==0||n==1){
        b=0;
        if(m==0||m==1){
            g=0;
        }else g =nc2(m);
    }else if (m==0||m==1){
        g=0;
        if(n==0||n==1){
            b=0;
        }else b =nc2(n);
    }else{ b =nc2(n);g =nc2(m);}
    cout<<b+g;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define ll long long
using namespace std;

int a[55];
ll C(ll a, ll n){
	ll ans = 1;
	for(ll i = 0; i < a; i ++){
		ans*=(n-i);
		ans/=(i+1);
	}
	return ans;
}
int main(){
	int n,p;
	cin>>n>>p;
	for(int i = 1; i <= n; i ++)cin>>a[i];
	ll aa = 0,bb = 0,ans = 0;
	for(int i = 1; i <= n; i ++){
		if(a[i]%2)aa++;
		else bb++;
	}
	if(p == 1){
		if(aa == 0){
			printf("0\n");
			return 0;
		}
		for(ll i = 1; i <= aa; i+=2){
			ans+=C(i,aa);
		}
		ll ans1 = 0;
		for(ll i = 0; i <= bb; i ++){
			ans1 += C(i,bb);
		}
		cout << ans*ans1 << endl;
	}else {
		for(ll i = 0; i <= bb; i++)
			ans+=C(i,bb);
		ll ans1 = 0;
		for(ll i = 0; i <= aa; i+=2)
			ans1+=C(i,aa);
		cout << ans1*ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
using namespace std;
int main(){
    int N;
    cin >> N;
    int a[N],m=0,sum=0;
    for(int i=0;i<N;i++){
        cin >> a[i];
        m = max(m,a[i]);
        sum = sum + a[i];
    }

    cout << sum - (m/2) << endl;
}


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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

const int MAX = 51000; //テーブルの数
const int MOD = 1e9 + 7; //mod宣言

long long fac[MAX], finv[MAX], inv[MAX];
// finv ->階乗割り算
// fac ->階乗掛け算

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    COMinit();
    ll n, k; cin >> n >> k;
    REP(i, 1, k+1){
        cout << (COM(n-k+1, i) * COM(k-1, i-1))%MOD << endl;
    }
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int ar[200005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    long long a,b,c=0,d,e,k=0,k1=0,i,j,n,m,s=0;
    set <long long> shit;

    cin >> n >> m >> k;

    if(abs(n-k)>abs(n-m)) cout << "A";
    else cout << "B";

}


Measured memory_bytes: 256
n=int(input())
s=input()

r=0
g=0
b=0
count=0

for i in s:
  if i == "R":
    r += 1
  elif i == "G":
    g += 1
  elif i == "B":
    b += 1

count = r*g*b

# k-j==j-iの場合を引く
for i in range(n-2):
  si = s[i]
  for j in range(i+1,i+(n-i-1)//2+1):
    if si != s[j]:
      sj = s[j]
      k = j+(j-i)
      if s[k] != si and s[k] != sj:
        count -= 1
        
print(count)

Measured memory_bytes: 73656
#include<iostream>
#include<algorithm>
using namespace std;
struct Tre{
    int w,l,r;
}num[30];
int n;
int tot=0;
int done[30];
void qx(int wz){
    cout<<" "<<wz;
    if(num[wz].l!=-1) qx(num[wz].l);
    if(num[wz].r!=-1) qx(num[wz].r);
}
void zx(int wz){
    if(num[wz].l!=-1) zx(num[wz].l);
    cout<<" "<<wz;
    if(num[wz].r!=-1) zx(num[wz].r);
}
void hx(int wz){
    if(num[wz].l!=-1) hx(num[wz].l);
    if(num[wz].r!=-1) hx(num[wz].r);
    cout<<" "<<wz;
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        cin>>num[a].l>>num[a].r;
        if(num[a].l!=-1) done[num[a].l]=1;
        if(num[a].r!=-1) done[num[a].r]=1;
    }
    int p=-1;
    for(int i=0;i<n;i++) if(!done[i]) p=i;
    cout<<"Preorder\n";
    qx(p);
    cout<<"\nInorder\n";
    zx(p);
    cout<<"\nPostorder\n";
    hx(p);
    cout<<"\n";
    return 0;
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod=1000000007;
#define pb  push_back
#define FOR(i,n) for(int i=0;i<(n);i++)
#define FORA(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define count_1(n)  __builtin_popcountll(n)
#define parity(n)   __builtin_parityll(n)   //Even parity 0 as output
void show    (int a[], int arraysize) { for (int i = 0; i < arraysize; ++i)  {cout << a[i] << " ";}	cout<<endl;}
int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
void sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}
int main()
{FAST

ll n,a,b,x,y,z;
cin>>n>>a>>b;
z=b+a;
x=n/z;
y=n%z;
if(y>=a)
{
	cout<<x*a+a;
}
else
{
	cout<<x*a+y;
}

return  0;
}




Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

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

using namespace std;

const int MOD = 1e9 + 7;

ll power(int n, int p)
{
    if (p == 0)
        return 1;
    ll res = 1;
    ll add = n;
    while (p > 0)
    {
        if (p & 1)
            res = (res * add) % MOD;
        p >>= 1;
        add = add*add%MOD;
    }
    return res;
}
      
ll count_ans(int keta, int beforeone) {
    ll ret = power(3, keta-1) + 1;
    ret = (ret * power(2, beforeone)) % MOD;
    return ret;

}


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

    int n = l.size();
    ll ans = 0;
    int cnt1 = 0;
    rep(i, n) {
        int num = l[i] - '0';
        if(num == 1) {
            ans = (ans + count_ans(n - i, cnt1)) % MOD;
            cnt1++;
        }
    }

    cout << ans + 1 << endl;

    return 0;
}

Measured memory_bytes: 1144
def remainder_minimization_2019(l, r)
  ans = (l * r) % 2019
  used = {}
  l.upto([l * 2, r - 1].min) do |i|
    next if used[i]
    (i + 1).upto(r) do |j|
      used[i * j] = true
      ans = [ans, (i * j) % 2019].min
      return 0 if ans.zero?
    end
  end
  ans
end

l, r = gets.split.map(&:to_i)
puts remainder_minimization_2019(l, r)


Measured memory_bytes: 8572
/* BISMILLAHIR RAHMANIR RAHIM */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    ll s, n;
    cin >> s >> n;
    ll x = 0;
    for(int i = 0, a; i < n; i++) {
    	cin >> a;
    	x += a;
    }
    cout << (x >= s ? "Yes\n" : "No\n");
}

Measured memory_bytes: 256
#include <cstdio>

#define MAX(X,Y) (((X)>(Y)) ? (X) : (Y))
#define MIN(X,Y) (((X)<(Y)) ? (X) : (Y))

int x[200000], y[200000];

int main(void) {
    int n,w,h;
    scanf("%d%d%d",&n,&w,&h);
    for(int i=0; i<n; i++) {
        int xi,yi,wi;
        scanf("%d%d%d",&xi,&yi,&wi);
        x[MAX(0,xi-wi)]++; x[MIN(xi+wi,w)]--;
        y[MAX(0,yi-wi)]++; y[MIN(yi+wi,h)]--;
    }
    bool flag = true;
    for(int i=0; i<w; i++) {
        x[i+1]+=x[i];
        if(x[i]<=0) flag=false;
    }
    bool flag2 = true;
    for(int i=0; i<h; i++) {
        y[i+1]+=y[i];
        if(y[i]<=0) flag2=false;
    }
    printf((flag || flag2) ? "Yes\n" : "No\n");
    return 0;
}

Measured memory_bytes: 3544
import math

def combination(n, k):
    return math.factorial(n) // math.factorial(k) // math.factorial(n - k)

def resolve():

    n, k = map(int, input().split())

    for i in range(1, k + 1):

        if i <= n - k + 1:
            print(combination(n-k+1,i) * combination(k-1,i-1) % 1000000007)
            
        else:
            print(0)

resolve()

Measured memory_bytes: 69976
#include<bits/stdc++.h>
using namespace std;
 
#define             ll  long long
#define            ull  unsigned long long
#define            P_B  push_back
#define            M_P  make_pair
#define         DBG(x)  printf("%s %d\n", #x, x)
#define       DBGLL(x)  printf("%s %lld\n", #x, x)
#define         SCI(x)  scanf("%d",&x)
#define         SCD(x)  scanf("%lf",&x)
#define         SCS(x)  scanf("%s",x)
#define         CLR(x)  memset(x, 0, sizeof(x))
#define        CLRN(x)  memset(x, -1, sizeof(x))
#define        SCLL(x)  scanf("%lld", &x)
#define      FOR(i, n)  for(int i = 0; i < n; i++)
#define  FORR(i, m, n)  for(int i = m; i < n; i++)
#define     SCI2(m, n)  scanf("%d%d", &m, &n)
#define  SCI3(m, n, o)  scanf("%d%d%d",&m, &n, &o)
#define     SCD2(m, n)  scanf("%lf%lf",&m,&n)
#define  SCD3(m, n, o)  scanf("%lf%lf%lf",&m,&n,&o)
#define    SCLL2(m, n)  scanf("%lld%lld", &m, &n)
#define SCLL3(m, n, o)  scanf("%lld%lld%lld",&m, &n, &o)
#define             vi  vector<int>
#define            vii  vector<pair<int, int> >
#define            vll  vector<pair<ll, ll> >
#define            Mod  998244353
#define            INF  1000000000
 
int n;
int w[105][2];
int m;
int dp[105];
int fl[105];

int main()
{
	CLR(fl);	
	SCI2(n, m);
	FOR(i, n)SCI2(w[i][0], w[i][1]);
	int x[100005];
	CLRN(x);
	FOR(i, n){
		for(int j = 100000; j > 0; j--){
			if(x[j] != -1){
				if(x[j] + w[i][0] <= m){
					if(x[j + w[i][1]] != -1)
						x[j + w[i][1]] = min(x[j] + w[i][0], x[j+w[i][1]]);
					else
						x[j + w[i][1]] = x[j] + w[i][0];
				}
			}
		}
		if(w[i][0] <= m){
			if(x[w[i][1]] != -1)x[w[i][1]] = min(x[w[i][1]], w[i][0]);
			else x[w[i][1]] = w[i][0];
		}
	}
	int y = 0;
	for(int i = 100000; i >= 0; i--) 
		if(x[i] > 0){
			y = i;
			break;	
		}
	printf("%d\n", y);
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
const int MAX = 100005;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int even[MAX];
int odd[MAX];
int e1,o1;
int maxe1,maxe2,maxo1,maxo2;

int main(){
    int n; cin >> n;
    int v[n];
    rep(i,n){
        cin >> v[i];
        if(i%2==0) even[v[i]]++;
        else odd[v[i]]++;
    }
    for(int i=0;i<MAX;i++){
        if(maxe1<even[i]){
            maxe2=maxe1;
            maxe1=even[i];
            e1=i;
        }else if(maxe2<even[i]){
            maxe2=even[i];
        }
        if(maxo1<odd[i]){
            maxo2=maxo1;
            maxo1=odd[i];
            o1=i;
        }else if(maxo2<odd[i]){
            maxo2=odd[i];
        }
    }
    int ans;
    if(e1!=o1) ans = n-maxe1-maxo1;
    else ans=min(n-maxe1-maxo2,n-maxe2-maxo1);
    
    cout << ans << endl;
}




Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<algorithm>
#define FOR(i,a,b) for(int i=(a);i<(b);++i) 
#define REP(i,n) FOR(i,0,n)
#define EACH(x,a) for(auto& (x):(a))
#define ALL(obj) (obj).begin(),(obj).end()
#define Yes(n) cout<<((n)?"Yes":"No")<<endl;
#define CO(x) cout<<(x)<<endl;
#define COSP(x) cout<<(x)<<" ";
#define DICIMAL(x) fixed<<setprecision(x)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
using namespace std;
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
const int INF=1e9;
const ll LINF=1e18;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    INIT;

    int N; cin>>N;
    int h;
    int t;
    int o;

    FOR(i, N, 1000){
        h = i/100;
        t = (i%100)/10;
        o = i%10;
        if((h==t) and (t==o)){
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}


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

using namespace std;
const int maxn = 105;
int f[maxn][maxn][2];
char a[maxn][maxn];
int n, m;
int calc(int i, int j, int typ) {
    if (i > n || j > m) return 1e9;
    if (i == n && j == m) return 0;
    int &res = f[i][j][typ];
    if (res != -1) return res;
    res = 1e9;
    int nxt = (a[i][j + 1] == '#');
    res = min(res, calc(i, j + 1, nxt) + (nxt == 1 && typ == 0));
    nxt = (a[i + 1][j] == '#');
    res = min(res, calc(i + 1, j, nxt) + (nxt == 1 && typ == 0));
    return res;
}
int main() {
#ifdef LDT
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        cin >> (a[i] + 1);
    memset(f, 255, sizeof(f));
    cout << calc(1, 1, a[1][1] == '.' ? 0 : 1) + (a[1][1] == '#');
    return 0;
}

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

int main(){
	int N;
	cin >> N;
	vector<long long> A(N);
	for(auto &i:A)cin >> i;
	sort(A.begin(),A.end(),greater<long long>());
	
	long long ans=0;
	queue<long long> com;
	com.push(A[0]);
	
	for(int i=1;i<N;i++){
		ans+=com.front();
		com.pop();
		com.push(A[i]);
		com.push(A[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6408
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

T binarySearch(alias pred, T)(T ok, T ng)
{ 
	while (abs(ok-ng) > 1)
	{
		auto mid = ok - (ok-ng) / 2;
		if (unaryFun!pred(mid))
			ok = mid;
		else ng = mid;
	}
	return ok;
}

void main()
{
	auto N = RD;
	auto M = RD;
	auto A = RDA;
	A.sort!"a > b"();

	auto b = new long[](N+1);
	foreach (i; 0..N)
		b[i+1] = b[i] + A[i];
	
	long ans;
	long ans2;
	bool f(long x)
	{
		long ans_t;
		long m = M;
		foreach (i; 0..N)
		{
			if (m == 0) break;
			auto y = x - A[i];
			auto r = binarySearch!((long a) => A[a] >= y)(-1, cast(int)N) + 1;
			auto cnt = min(r, m);
			ans_t += b[cnt];
			ans_t += A[i] * cnt;
			m -= cnt;
		}
		ans = ans_t;
		ans2 = m;
		return m == 0;
	}

	auto r = binarySearch!(f)(0L, (10L^^5)*2+1);
	f(r+1);
	ans += ans2 * r;

	writeln(ans);
	stdout.flush;
	debug readln;
}


Measured memory_bytes: 4464
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
use std::cmp::*;
fn main(){
let a:isize=read();
let b:isize=read();
let c:isize=read();
println!("{}",max(0,(b-c).abs()-a))
}

Measured memory_bytes: 4352
class DualSegmentTree():

    def __init__(self, n, op, e):
        """
        :param n: 配列の要素数
        :param op: 作用素（モノイド＝結合則＋単位元存在）
        :param e:  単位元
        """
        self.n = n
        self.op = op
        self.e = e
        self.depth = (self.n - 1).bit_length()
        self.size = 1 << self.depth
        self.lazy = [self.e] * ((self.size << 1) + 1)

    def built(self, array):
        """
        arrayを初期値とするセグメント木を構築
        """
        for i in range(self.n):
            self.lazy[self.size + i] = array[i]

    def update(self, l, r, x):
        """
        半開区間 [l, r) の各々の要素 a に op(x, a)を作用させる （ 0-indexed ）　（ O(logN) ）
        """
        l += self.size
        r += self.size
        self.propagate(l)
        self.propagate(r-1)
        while l < r:
            if r&1:
                r -= 1              # 半開区間なので先に引いてる
                self.lazy[r] = self.op(x, self.lazy[r])
            if l&1:
                self.lazy[l] = self.op(x, self.lazy[l])
                l += 1
            l >>= 1
            r >>= 1

    def propagate(self, i):
        """
        根から葉に伝搬させる。可換モノイドの場合は更新時の伝搬をサボれる。　（ O(logN) ）
        """
        for k in range(self.depth,0,-1):
            x = i>>k
            if self.lazy[x] == self.e:
                continue
            self.lazy[(x<<1)|1] = self.op(self.lazy[x], self.lazy[(x<<1)|1])
            self.lazy[x<<1] = self.op(self.lazy[x], self.lazy[x<<1])
            self.lazy[x] = self.e

    def get(self, i):
        """
        i 番目の値を取得（ 0-indexed ） ( O(logN) )
        """
        i += self.size
        self.propagate(i)
        return self.lazy[i]

    def __getitem__(self, i):
        return self.get(i)

    def __iter__(self):
        for x in range(1, self.size):
            if self.lazy[x] == self.e:
                continue
            self.lazy[(x<<1)|1] = self.op(self.lazy[x], self.lazy[(x<<1)|1])
            self.lazy[x<<1] = self.op(self.lazy[x], self.lazy[x<<1])
            self.lazy[x] = self.e
        for a in self.lazy[self.size:self.size+self.n]:
            yield a

    def __str__(self):
        for x in range(1, self.size):
            if self.lazy[x] == self.e:
                continue
            self.lazy[(x<<1)|1] = self.op(self.lazy[x], self.lazy[(x<<1)|1])
            self.lazy[x<<1] = self.op(self.lazy[x], self.lazy[x<<1])
            self.lazy[x] = self.e
        return str(self.lazy[self.size:self.size + self.n])

##################################################################################################################
import sys
from bisect import *
input = sys.stdin.readline

N, Q = map(int, input().split())

e = -1
op = lambda x, y: x if x != e else y
st = DualSegmentTree(Q, op, e)

Qu = [list(map(int, input().split())) for _ in range(N)]
Qu.sort(key=lambda x:x[2], reverse=True)

D = [int(input()) for _ in range(Q)]

for q in Qu:
    S, T, X = q
    L = bisect_left(D,S-X)
    R = bisect_left(D,T-X)
    st.update(L, R, X)
print(*st, sep="\n")

Measured memory_bytes: 143504
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;

char area[200][200];

typedef pair<int, int> P;
#define x first
#define y second
/* struct P{
	int x, y;
};*/

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};

int main()
{
	int w, h, area_sum;
	
	while (scanf("%d%d", &h, &w), h != 0 && w != 0){
		
		memset(area, 0, sizeof(area));
		
		area_sum = 0;
		for (int i = 1; i <= h; i++){
			for (int j = 1; j <= w; j++)scanf(" %c", &area[j][i]);
		}
		
		for (int i = 1; i <= h; i++){
			for (int j = 1; j <= w; j++){
				if (area[j][i]){
					queue<P> que;
					que.push(P(j, i));
					while (!que.empty()){
						P st = que.front();
						que.pop();
						if (!area[st.x][st.y])continue;
						for (int k = 0; k < 4; k++){
							if (area[st.x][st.y] == area[st.x + dx[k]][st.y + dy[k]]){
								que.push(P(st.x + dx[k], st.y + dy[k]));
							}
						}
						area[st.x][st.y] = 0;
						
					}
					area_sum++;
				}
			}
		}
		
		printf("%d\n", area_sum);
	}
}

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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a > b)
    {
        swap(a, b);
    }
    if(a > c)
    {
        swap(a, c);
    }
    if(b > c)
    {
        swap (b, c);
    }
    cout << a << " " << b << " " << c << endl;
    return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> p(n), q(n),x(n);
    rep(i,n){
        cin >> p[i];
    }
    rep(i,n){
        cin >> q[i];
    }
    rep(i,n){
        x[i] = i + 1;
    }
    int a, b,cnt=0;
    do{
        bool flag1 = true,flag2 = true;
        cnt++;
        rep(i,n){
            if(p[i]!=x[i]){
                flag1 = false;
            }
        }
        rep(i,n){
            if(q[i]!=x[i]){
                flag2 = false;
            }
        }
        if(flag1){
            a = cnt;
        }
        if(flag2){
            b = cnt;
        }


    } while (next_permutation(x.begin(), x.end()));
    cout << abs(b - a) << endl;
}

Measured memory_bytes: 256