akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    for (int i = 0; i < h; ++i) {
        cin >> s[i];
    }
    vvi ret(h, vi(w, 0));
    vi count(h, 0);
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (s[i][j] == '#')
                count[i]++;
        }
    }
    int firsth = -1;
    for (int i = 0; i < h; ++i) {
        if (count[i] != 0) {
            firsth = i;
            break;
        }
    }
    int curr = 0;
    for (int i = firsth; i < h; ++i) {
        if (count[i] != 0) {
            int lmost = -1;
            for (int j = 0; j < w; ++j) {
                if (s[i][j] == '#') {
                    curr++;
                    if (lmost == -1)
                        lmost = j;
                    ret[i][j] = curr;
                } else
                    ret[i][j] = curr;
            }
            for (int j = lmost - 1; j >= 0; --j) {
                ret[i][j] = ret[i][j + 1];
            }
        } else {
            for (int j = 0; j < w; ++j) {
                ret[i][j] = ret[i - 1][j];
            }
        }
    }
    for (int i = firsth - 1; i >= 0; --i) {
        for (int j = 0; j < w; ++j) {
            ret[i][j] = ret[i + 1][j];
        }
    }
    for (int i = 0; i < h; ++i) {
        print(ret[i]);
    }

    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
using ll = long long;
using uint = unsigned int;
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 MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}

void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}

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

void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}

int main() {
    string L;
    cin >> L;
    ll N = L.size();
    ll memo[N][2];
    for (int xi = 0; xi < N; ++xi) {
        for (int yi = 0; yi < 2; ++yi) {
            memo[xi][yi] = -1;
        }
    }
    memo[N - 1][0] = 2;
    memo[N - 1][1] = 1;
    for (int i = N - 2; i >= 0; --i) {
        if(L[N - i - 1] == '1'){
            memo[i][0] = memo[i+1][0] * 2;
            memo[i][1] = memo[i+1][1] * 3 + memo[i+1][0];
        }else{
            memo[i][0] = memo[i+1][0];
            memo[i][1] = memo[i+1][1] * 3;
        }
        memo[i][0] %= MOD7;
        memo[i][1] %= MOD7;
    }
    cout << (memo[0][0] + memo[0][1]) % MOD7 << endl;

}


Measured memory_bytes: 2048
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        //var n = int.Parse(Console.ReadLine());
        int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();

        var ans = n[0] * n[1];
        
        // 出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 28232
import java.io.PrintWriter

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val (n, t) = readIntegerList()
    val aList = readLongList()

    val benefitArray = LongArray(n - 1)
    var minA = aList.first()
    for ((i, a) in aList.drop(1).withIndex()) {
        benefitArray[i] = a - minA
        minA = Math.min(minA, a)
    }
    val maxBenefit = benefitArray.max()!!
    println(benefitArray.count { it == maxBenefit })
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 55992
#include <iostream>
#include <vector>
#define REP(i, a, b) for (auto i = (a); i < (b); ++i)
using namespace std;

const long long inf = 1e18;

struct edge {
	int a, b;
	long long cost;
};

signed main() {
	long long n, m, p; cin >> n >> m >> p;

	vector<edge> e(m);
	REP(i, 0, m) {
		long long a, b, c; cin >> a >> b >> c;
		e[i].a = a - 1;
		e[i].b = b - 1;
		e[i].cost = - c + p;
	}

	vector<long long> d(n, inf);
	d[0] = 0;
	for (int i = 0; i < 2 * n; ++i) {
		for (int j = 0; j < m; ++j)
            if (d[e[j].a] < inf) {
                if (d[e[j].b] > d[e[j].a] + e[j].cost) {
                    if (i < n)
                        d[e[j].b] = max(-inf, min(inf, d[e[j].a] + e[j].cost));
                    else
                        d[e[j].b] = -inf;
                }
        }
	}

	if (d[n - 1] == -inf) cout <<  -1;
	else cout << max(0LL, -d[n - 1]);
}


Measured memory_bytes: 384
#include<iostream>
#include<climits>
using namespace std;
int main(){
  int N,bare[16],t[16][16],dp[1<<16];
  while(cin>>N,N){
    for(int i=0;i<N;i++){
      cin>>bare[i];
      for(int j=0;j<N;j++){
	cin>>t[i][j];
      }
    }
    for(int i=0;i<(1<<N);i++)dp[i]=INT_MAX;

    dp[0]=0;
    for(int i=0;i<(1<<N);i++){
      for(int next=0;next<N;next++){
	if(i & (1<<next))continue;
	int nextbit = i|(1<<next);
	dp[nextbit] = min(dp[i]+bare[next], dp[nextbit]) ;
	for (int use=0;use<N;use++){
	  if(!(i&(1<<use)))continue;
	  dp[nextbit] = min(dp[i]+t[next][use], dp[nextbit]);
	}
      }
    }

    cout<<dp[(1<<N)-1]<<endl;
  }
}

Measured memory_bytes: 1120
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int main()
{
    string s, p;
    stringstream ss, pp;
    int a, b, tmp1, tmp2, dem1=1, dem2=1;
    cin>>a>>b;
    tmp1=a;
    tmp2=b;
    while(dem1<b)
    {
        tmp1=tmp1*10+a;
        dem1++;
    }
    while(dem2<a)
    {
        tmp2=tmp2*10+b;
        dem2++;
    }
    ss<<tmp1;
    pp<<tmp2;
    s=ss.str();
    p=pp.str();
    if(s<=p)
    {
        cout<<s<<endl;
    }
    else
    {
        cout<<p<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define llint long long
#define inf 1e18

using namespace std;

llint n, t;
llint a[3005], b[3005];
llint ldp[3005][3005], rdp[3005][3005];
llint sum[3005];

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

  cin >> n >> t;
  for(int i = 1; i <= n; i++) cin >> a[i] >> b[i];

  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= t; j++){
      ldp[i][j] = -inf;
    }
  }
  ldp[0][0] = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j <= t; j++){
      if(j+a[i+1] <= t) ldp[i+1][j+a[i+1]] = max(ldp[i+1][j+a[i+1]], ldp[i][j] + b[i+1]);
      ldp[i+1][j] = max(ldp[i+1][j], ldp[i][j]);
    }
  }

  /*for(int i = 0; i <= n; i++){
    for(int j = 0; j <= t; j++){
      cout << ldp[i][j] << " ";
    }
    cout << endl;
  }*/

  for(int i = 0; i <= n+1; i++){
    for(int j = 0; j <= t; j++){
      rdp[i][j] = -inf;
    }
  }
  rdp[n+1][0] = 0;
  for(int i = n+1; i > 1; i--){
    for(int j = 0; j <= t; j++){
      if(j+a[i-1] <= t) rdp[i-1][j+a[i-1]] = max(rdp[i-1][j+a[i-1]], rdp[i][j] + b[i-1]);
      rdp[i-1][j] = max(rdp[i-1][j], rdp[i][j]);
    }
  }
  /*for(int i = 1; i <= n; i++){
    for(int j = 0; j <= t; j++){
      cout << rdp[i][j] << " ";
    }
    cout << endl;
  }*/

  llint ans = 0;
  for(int i = 1; i <= n; i++){
    sum[0] = rdp[i+1][0];
    for(int j = 1; j <= t; j++) sum[j] = max(sum[j-1], rdp[i+1][j]);
    //cout << sum[t] << endl;
    for(int j = 0; j <= t-1; j++){
      ans = max(ans, ldp[i-1][j] + sum[(t-1)-j] + b[i]);
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 141312
import sys, random
mod = 1000000007
def get_array(): return list(map(int, sys.stdin.readline().split()))
def get_ints(): return map(int, sys.stdin.readline().split())
def input(): return sys.stdin.readline()
def print_array(a): print(" ".join(map(str, a)))
def main():
        s = input().strip()
        l = len(s)
        flag = True
        for i in range(0, l):
                if (i % 2 == 0) and s[i] not in ['R', 'U', 'D']:
                        flag = False
                        break
                if i % 2 == 1 and s[i] not in ['L', 'U', 'D']:
                        flag = False
                        break
        print("Yes" if flag else "No")
if __name__ == "__main__":
        main()

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

using namespace std;

using ll = long long;

bool Solve() {
    int a, b;
    string s;
    cin >> a >> b >> s;

    int n = s.size();
    for (int i = 0; i < n; ++i) {
        if (i < a && !isdigit(s[i])) return false;
        else if (i == a && s[i] != '-') return false;
        else if (a < i && !isdigit(s[i])) return false;
    }
    return true;
}

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

    if (Solve()) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


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

int main(){
  int h,w;
  cin>>h>>w;
  vector<vector<char>> s(h+2, vector<char>(w+2));
  for(int i=0; i<w+2; i++)s.at(0).at(i)='.';
  for(int i=1; i<h+1; i++){
    s.at(i).at(0)='.';
    for(int j=1; j<w+1; j++)cin>>s.at(i).at(j);
    s.at(i).at(w+1)='.';
  }
  for(int i=0; i<w+2; i++)s.at(h+1).at(i)='.';

  for(int i=1; i<h+1; i++){
    for(int j=1; j<w+1; j++){
      if(s.at(i).at(j)=='.'){
        int x=0;
        if(s.at(i-1).at(j-1)=='#')x++;
        if(s.at(i-1).at(j)=='#')x++;
        if(s.at(i-1).at(j+1)=='#')x++;
        if(s.at(i).at(j-1)=='#')x++;
        if(s.at(i).at(j+1)=='#')x++;
        if(s.at(i+1).at(j-1)=='#')x++;
        if(s.at(i+1).at(j)=='#')x++;
        if(s.at(i+1).at(j+1)=='#')x++;
        s.at(i).at(j)='0'+x;
      }
    }
  }

  for(int i=1; i<h+1; i++){
    for(int j=1; j<w+1; j++){
      cout<<s.at(i).at(j);
    }
    cout<<endl;
  }
}


Measured memory_bytes: 256
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define LINF (LLONG_MAX / 2)
#define EPS (1.0e-8)
const int MGN = 10;
const int ARY_SZ_MAX = (int)1e7;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>;
using vc = vector<char>; using vvc = vector<vc>;
using vb = vector<bool>; using vvb = vector<vb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using psl = pair<string, ll>;


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


  string S,T; cin>>S>>T;

  string ans = T+S;
  cout << ans << endl;


  return 0;
}


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

int main() {
    ios_base :: sync_with_stdio(false);
    int n; cin >> n;

    vector<int> v(n);
    for(int i = 0; i < n; ++i)
        cin >> v[i];
    
    int mask = 0, rt = 0;
    int64_t ans = 0;

    for(int i = 0; i < n; ++i) {
        while(rt < n and (v[rt] & mask) == 0) {
            mask ^= v[rt];
            rt += 1;
        }
        ans += max(0, rt - i);
        mask ^= v[i];
    }

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

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

int main(int argc, char *argv[]) {
  int n;
  std::cin >> n;

  std::vector<int> xs(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> xs[i];
  }

  int count = 0;
  for (int i = 0; i < n - 2; ++i) {
    for (int j = i + 1; j < n - 1; ++j) {
      if (xs[i] == xs[j]) {
        continue;
      }
      for (int k = j + 1; k < n; ++k) {
        if (xs[i] == xs[k] || xs[j] == xs[k]) {
          continue;
        }
        std::vector<int> ys = {xs[i], xs[j], xs[k]};
        std::sort(ys.begin(), ys.end());
        if (ys[2] < ys[0] + ys[1]) {
          ++count;
        }
      }
    }
  }

  std::cout << count << std::endl;

  return 0;
}

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

#define int long long

#define _   int v, int tl, int tr, int l, int r
#define tm  (tl + tr >> 1)
#define sol v+v, tl, tm, l, r
#define sag v+v+1, tm+1, tr, l, r
#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef pair < int , int > pp;
const int mod = 1e9 + 7;
const int N   = 5e3 + 3;

vector < int > V[N];
int M[N][N][2], MM[N][2], P[N], sz[N];

void f(int x, int p){
    sz[x] = 1;
    M[x][1][1] = 1;
    M[x][1][0] = 0;
    for(int y, i=0; i<V[x].size(); i++)
        if(!sz[ y = V[x][i] ]){
            f(y, x);
            
            memset(MM , 0 , sizeof MM);
            for(int j=1; j<=sz[x]; j++)
                for(int k=0; k<=sz[y]; k++){
                    MM[j+k][0] = (MM[j+k][0] + M[x][j][1] * M[y][k][0] + M[x][j][0] * M[y][k][1]) % mod;
                    MM[j+k][1] = (MM[j+k][1] + M[x][j][0] * M[y][k][0] + M[x][j][1] * M[y][k][1]) % mod;
                }
                        
            sz[x] += sz[y];
            for(int j=1; j<=sz[x]; j++){
                M[x][j][0] = MM[j][0];
                M[x][j][1] = MM[j][1];
            }
		}
    
    for(int i=1; i<=sz[x]; i++){
        M[x][0][0] = (M[x][0][0] + M[x][i][1] * P[i]) % mod;
        M[x][0][1] = (M[x][0][1] + M[x][i][0] * P[i]) % mod;
    }
}

signed main(){
    int n;
    cin >> n;
    for(int i=1; i<n; i++){
        int x, y;
        scanf("%lld%lld", &x, &y);
        V[x].pb(y); V[y].pb(x);
    }
    
    P[2] = 1;
    for(int i=4; i<=n; i+=2)
    	P[i] = P[i-2] * (i-1) % mod;
    
    f(1,0);
    cout << (M[1][0][0] - M[1][0][1] + mod) % mod;
    return 0;
}

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

int main() {
    long long n, a, b;
    cin >> n >> a >> b;
    long long x[n], result = 0;
    for (long long i = 0; i < n; i++) {
        cin >> x[i];
    }
    for (long long i = 1; i < n; i++) {
        result += min(b, (x[i] - x[i - 1]) * a);
    }
    cout << result;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int h,w;
    cin >> h >> w;
    vector<string> str(h);
    bool x[1000][1000];
    string ans = "Yes";
    for(int i=0;i<h;i++){
        cin >> str[i];
    }
    
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(str[i].substr(j,1)=="#"){
               x[i][j]=true;
            }else{
                x[i][j]=false;
                }
    }
    }
    bool flag = true;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(x[i][j]==true){
                if(x[i-1][j]==false){
                    if(x[i][j-1]==false){
                        if(x[i+1][j]==false){
                            if(x[i][j+1]==false){
                                ans = "No";
                                flag =false;
                                break;
                            }
                        }
                    }
                }
            }
        }
        if(flag == false){
            break;
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <string.h>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i > 0; i--)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t int64;

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

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


class B {
	int x[4];
	int y[4];
public:
	B()
	{
		cin >> x[0] >> y[0] >> x[1] >> y[1];
	}
	void solve()
	{
		int vx{ x[1] - x[0] };
		int vy{ y[1] - y[0] };

		x[2] = x[1] - vy;
		y[2] = y[1] + vx;

		x[3] = x[2] - vx;
		y[3] = y[2] - vy;

		cout << x[2] << " " << y[2] << " " << x[3] << " " << y[3] << endl;
	}
};


int main()
{
	B solution;
	solution.solve();

	return 0;
}

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

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int h, w, k; cin >> h >> w >> k;
    vector<string> lis(h);
    vector<vector<int> > llis(h, vector<int>(w, 0));
    int ans = 0;
    REP(i, 0, h){cin >> lis[i];}
    REP(i, 0, h){
        REP(l, 0, w){
            if(lis[i][l] == '#'){
                llis[i][l] = 1;
            }else{
                llis[i][l] = 2;
            }
        }
    }
    REP(i, 0, (1 << h)){
        REP(l, 0, (1 << w)){
            vector<vector<int> > cllis = llis;
            int ci = i;
            REP(j, 0, h){
                if(ci % 2 == 1){
                   // cout << "OK" << endl;
                    REP(a, 0, w){
                        cllis[j][a] = 3;
                    }
                }
                ci /= 2;
            }
            int cl = l;
            REP(j, 0, w){
                if(cl % 2 == 1){
                    REP(a, 0, h){
                        cllis[a][j] = 3;
                    }
                }
                cl /= 2;
            }
            int mid = 0;
            REP(a, 0, h){
                REP(b, 0, w){
                    if(cllis[a][b] == 1){
                        mid++;
                    }
                }
            }
            if(mid == k){ans++;}
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(void){
  int h, w;
  string s[51];
  cin >> h >> w;
  for(int i = 0; i < h; i++) cin >> s[i];
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      int cnt = 0;
      if(s[i][j] == '#') cout << '#';
      else {
        for(int dx = -1; dx <= 1; dx++){
          for(int dy = -1; dy <= 1; dy++){
            int nx = j+dx;
            int ny = i+dy;
            if(0 <= nx && nx < w && 0 <= ny && ny < h){
              if(s[ny][nx] == '#') cnt++;
            }
          }
        }
        cout << cnt;
      }
    }
    cout << endl;
  }
  return 0;
}

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

int main(){
  int S;
  cin>>S;
  if(S%100>=1&&S%100<=12){
    if((S-S%100)/100>=1&&(S-S%100)/100<=12){
      cout<<"AMBIGUOUS"<<endl;
    }else{
      cout<<"YYMM"<<endl;
    }
  }else{
    if((S-S%100)/100>=1&&(S-S%100)/100<=12){
      cout<<"MMYY"<<endl;
    }else{
      cout<<"NA"<<endl;
    }
  }
    
}

Measured memory_bytes: 256
import sys

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


# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np
import math

def main():
	n=int(input())
	p=list(map(int,input().split()))
	q=list(map(int,input().split()))
	
	pl=list(range(n+1))
	pl.pop(0)
	ql=list(range(n+1))
	ql.pop(0)
	
	pp=0
	qq=0
	
	for i in range(n):
		ix=pl.index(p[i])
		pp+=ix*math.factorial(n-i-1)
		pl.remove(p[i])
	
	for i in range(n):
		ix=ql.index(q[i])
		qq+=ix*math.factorial(n-i-1)
		ql.remove(q[i])
	
	print(abs(pp-qq))
	
	
	
	



	
	
if __name__ == "__main__":
	main()


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n;cin>>n;

  if(n==1){
    cout<<"Yes"<<endl<<2<<endl<<"1 1"<<endl<<"1 1";
    return 0;
  }

  int size=0;
  for(int i=2; i<=(n+1)/2; i++){
    if(i*(i+1)==2*n){
      size = i;
      break;
    }
  }
  if(size==0){ cout << "No" <<endl; return 0; }

  vector<vector<int>> results(size+1, vector<int>());
  int c=1;
  rep1(i, size)rep1(j, i){
    results[i].push_back(c);
    c++;
  }

  c=1;
  rep1(i, size)rep(j, i){
    results[j].push_back(c);
    c++;
  }

  cout << "Yes" <<endl;
  cout<<size+1<<endl;
  
  rep(i, results.size()){
    cout<<size<<' ';
    rep(j, results[i].size()){
      cout<<results[i][j]<<' ';
    }
    cout<<endl;
  }

  return 0;
}

Measured memory_bytes: 2304
#include <stdio.h>

int main()
{
	int max, a, b, c, i;

	scanf("%d", &max);

	for(i=1; i<=max; i++){
		scanf("%d %d %d", &a, &b, &c);
		
		a *= a;
		b *= b;
		c *= c;
		
		if((a+b==c) || (a+c==b) || (b+c==a)){
			printf("YES\n");

		}else{
			printf("NO\n");
		}
	}

	return 0;
}

Measured memory_bytes: 576
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

int main(){
  int a,b;
  cin >> a >> b;
  puts((a*b)%2?"Odd":"Even");
  return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str;
		ArrayList<String> arr=new ArrayList<String>();
		while((str=br.readLine())!=null){
			if(!str.equals("0")){
				arr.add(str);
				/*System.out.println(arr.size());*/
			}
			else{
				System.out.println(arr.get(arr.size()-1));
				arr.remove(arr.size()-1);
			}
		}
	}

}

Measured memory_bytes: 24164
#include <iostream>
#include <math.h>
#define _ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

int main()
{_
    long long n, d, ans = 0; cin >> n >> d;
    while (n--)
    {
        long long x, y; cin >> x >> y;
        if (sqrt((x * x) + (y * y)) <= d) ++ans;
    }
    cout << ans;
}

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

using namespace std;
const double pi=acos(-1.0);
const int N=2e5+10;
int fa[N];
int a[N];
int find_fa(int x){

    while(fa[x]!=x){
        fa[x]=fa[fa[x]];
        x=fa[x];
    }
    return x;
}
int main()
{
    int n;
    cin>>n;
    int n1=n;
    n--;
    while(n--){
        int tmp;
        cin>>tmp;
        a[tmp]++;
    }
    for(int i=1;i<=n1;i++) cout<<a[i]<<" ";
}


Measured memory_bytes: 4360
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();
		
		if (B%A==0)
			System.out.println(A+B);
		else
			System.out.println(B-A);

		sc.close();
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define COUTDOUBLE(d,i) cout << setprecision((i)) << (d) << endl;
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}
#define MREP(i,m) for(auto i=(m).begin(); i != (m).end(); ++i) // auto key = i->first;auto value = i->second;

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;
I MAX = LONG_MAX;
I MIN = LONG_MIN;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

I a[1010][1010];
I c[1010]; // どこまで終わったか

int main(){
  I n;
  cin >> n;
  REP(i,n+1){
    if (i==0) continue;
    REP(j,n){
      if (j==0) continue;
      cin >> a[i][j];
    }
  }
  I d = 1;
  V l;
  REP(i,n+1){
    if (i==0) continue;
    l.push_back(i);
  }
  while (true){
    V v;
    bool chk = true;
    REP(j,l.size()){
      I i=l.at(j);
      if (i == a[a[i][c[i]+1]][c[a[i][c[i]+1]]+1]){
        v.push_back(i);
        v.push_back(a[i][c[i]+1]);
        chk = false;
      }
    }
    if (chk){
      break;
    }
    SORT(v);
    v.erase(unique(ALL(v)), v.end());
    REP(i,v.size()){
      c[v.at(i)]++;
    }
    d++;
    l = v;
  }
  REP(i,n+1){
    if (i==0) continue;
    if (c[i] != n-1){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << d-1 << endl;
  return 0;
}



Measured memory_bytes: 8192
H,W=map(int,input().split())
board=[[True]*(W+2)]
for i in range(H):
    board.append([True]+[a=='#' for a in input()]+[True])
board.append([True]*(W+2))

q=[]
for h in range(1,H+1):
    for w in range(1,W+1):
        if board[h][w]:
            q.append((h,w))

cnt=0
while q:
    nq=[]
    for h,w in q:
        if not board[h+1][w]:
            board[h+1][w]=True
            nq.append((h+1,w))
        if not board[h-1][w]:
            board[h-1][w]=True
            nq.append((h-1,w))
        if not board[h][w+1]:
            board[h][w+1]=True
            nq.append((h,w+1))
        if not board[h][w-1]:
            board[h][w-1]=True
            nq.append((h,w-1))

    q=nq
    cnt+=1

print(cnt-1)

Measured memory_bytes: 107996
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)
using Graph = vector<vector<int>>;

int main(){
    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    int time = h2*60+m2 - (h1*60+m1);
    int ans = time - k;
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
#隣接行列を書く
n,m = map(int,input().split())
ll = [[0]*n for _ in [0]*n]
for i in range(m):
  a,b = map(int,input().split())
  ll[a-1][b-1] = 1
  ll[b-1][a-1] = 1
#初期は1番目の点のみ訪問済み。かつ現在地は0番目
visit = [1]+[0]*(n-1)
place = 0
ans=0
#探索用関数
def search(visit,place):
  ans = 0
  if visit == [1]*n:
    return 1
  for i in range(n):
    if visit[i] == 0 and ll[place][i] == 1:
      tmpvisit = visit.copy()
      tmpvisit[i] = 1
      ans += search(tmpvisit,i)
  return ans
ans = search(visit,place)
print(ans)


Measured memory_bytes: 3064
"use strict"
function main(arg) {
    var data = arg.trim().split("\n")
    var n = data.shift().split(" ").map(Number)[0]
    data = data.map(e => {
        e = e.split(" ").map(Number)
        e[0] -= 1
        return e
    })
    if (data.length === 0 && n === 1) {
        console.log(0)
        return
    }
    var ans = solve(data, n)
    
    console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

function solve(data, n) {
    var N = new Array(n).fill(null)
    for (var i = 0; i < data.length; i++) {
        var key = data[i][0]
        var value = data[i][1]
        if (N[key] === value) {
            continue
        }
        if (N[key] !== null) {
            return -1
        }
        N[key] = value
    }
    var iniFlg = true
    for (var i = 0; i < N.length; i++) {
        if (N[i] === null) {
            if (i === 0) {
                N[i] = 1
            } else {
                N[i] = 0
            }
        }
    }
    
    if (N.join('') === String(Number(N.join('')))) {
        return Number(N.join(''))
    }
    return -1
}

Measured memory_bytes: 7500
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
constexpr double pi=3.14159265358979;

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;
}
using namespace std;

void solve(){
    int n;
    cin>>n;
    ll cnt=0;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    if(a[0]!=0){
        cout<<-1<<"\n";
        return;
    }
    for(int i=1;i<n;++i){
        while(i<n&&a[i-1]<=a[i]){
            cnt+=a[i];
            if(a[i]-a[i-1]>1){
                cout<<-1<<"\n";
                return;
            }
            else if(a[i]-a[i-1]==1)cnt-=a[i]-1;
            ++i;
        }
        if(i<n)cnt+=a[i];
    }
    cout<<cnt<<"\n";
}

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


Measured memory_bytes: 1792
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=1e9+7;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
ll ans, a, b, h, w;
ll fac[222222];
ll invfac[222222];

ll ncr(ll u, ll v)
{
	if(u<v || u<0 || v<0) return 0;
	ll ret=fac[u];
	ret=(ret*invfac[v])%mod;
	ret=(ret*invfac[u-v])%mod;
	return ret;
}

int main(void)
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>h>>w>>a>>b; ll i; fac[0]=invfac[0]=1;
	for(i=1 ; i<=222220 ; i++) fac[i]=(i*fac[i-1])%mod;
	for(i=1 ; i<=222220 ; i++) invfac[i]=exp(fac[i],mod-2);
	for(i=b+1 ; i<=w ; i++) ans+=(ncr(h-a-1+i-1,i-1)*ncr(a-1+w-i,w-i))%mod;
	ans%=mod; cout<<ans; return 0;
}

// it may be easier than you think
// it may be harder than you think
// ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

Measured memory_bytes: 3712
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func max(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}

func min(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v < ret {
			ret = v
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	h, w, n := nextInt(), nextInt(), nextInt()
	sr, sc := nextInt()-1, nextInt()-1
	s, t := next(), next()

	// 後手が勝てる駒の範囲
	// タテ方向
	u, d := 0, h
	if s[n-1] == 'U' {
		u++
	} else if s[n-1] == 'D' {
		d--
	}
	for i := n - 2; i >= 0; i-- {
		if t[i] == 'U' {
			d = min(d+1, h)
		} else if t[i] == 'D' {
			u = max(0, u-1)
		}
		if s[i] == 'U' {
			u++
		} else if s[i] == 'D' {
			d--
		}
		if u >= d {
			puts("NO")
			return
		}
	}
	if sr < u || d <= sr {
		puts("NO")
		return
	}

	// ヨコ方向
	l, r := 0, w
	if s[n-1] == 'L' {
		l++
	} else if s[n-1] == 'R' {
		r--
	}
	for i := n - 2; i >= 0; i-- {
		if t[i] == 'L' {
			r = min(r+1, w)
		} else if t[i] == 'R' {
			l = max(0, l-1)
		}
		if s[i] == 'L' {
			l++
		} else if s[i] == 'R' {
			r--
		}
		if l >= r {
			puts("NO")
			return
		}
	}
	if sc < l || r <= sc {
		puts("NO")
		return
	}

	puts("YES")
}


Measured memory_bytes: 2896
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

int gcd(int m, int n) {
    return n == 0 ? m : gcd(n, m % n);
}
int lcm(int m, int n) {
    return (m / gcd(m, n)) * n;
}

signed main() {
    cin >> H >> W;
    cin >> N;
    vi a(N);
    cin >> a;
    vvi c(H, vi(W));
    int i = 0;
    REP(h, H)
    REP(w, W) {
        if (a[i] == 0)
            i++;
        a[i]--;
        if (h & 1)
            c[h][w] = i + 1;
        else
            c[h][W - w - 1] = i + 1;
    }
    REP(h, H) {
        REP(w, W) {
            cout << c[h][w] << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 3680
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

N,u,v = MI()
Graph = [[] for _ in range(N+1)]

for i in range(N-1):
    a,b = MI()
    Graph[a].append(b)
    Graph[b].append(a)

dist_T = [-1]*(N+1)  # uからの最短距離
dist_A = [-1]*(N+1)  # vからの最短距離
dist_T[u] = 0
dist_A[v] = 0

from collections import deque
q1 = deque([u])
q2 = deque([v])
while q1:
    n = q1.pop()
    for d in Graph[n]:
        if dist_T[d] == -1:
            dist_T[d] = dist_T[n] + 1
            q1.appendleft(d)
while q2:
    n = q2.pop()
    for d in Graph[n]:
        if dist_A[d] == -1:
            dist_A[d] = dist_A[n] + 1
            q2.appendleft(d)

ans = 0
for i in range(1,N+1):
    if dist_T[i] < dist_A[i]:
        ans = max(ans,dist_A[i]-1)

print(ans)


Measured memory_bytes: 88876
#include <stdio.h>
#include <string.h>

int main()
{
	int N,A, B;

	if (scanf("%d", &N) == 1)
	{
		if (N==1) {
			printf("Hello World");
		}
		else {
scanf("%d %d", &A, &B);
printf("%d", A+B);
		}	
	}
	return 0;
}


Measured memory_bytes: 128
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int64_t N;
    std::cin >> N;

    std::vector<int64_t> A;
    int64_t prev = 0;

    int64_t max = 0;
    for (decltype(N) i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        A.push_back(t);
    }

    std::sort(std::begin(A), std::end(A));

    std::cout << std::max(max, std::abs(A[0] - A[N-1])) << std::endl;

    return 0;
}


Measured memory_bytes: 256
n=int(input())
l=[]
for i in range(n):
  x=[]
  a=int(input())
  x=[list(map(int,input().split())) for j in range(a)]
  l.append(x)

b=[]
for k in range(2**n):
  b.append(format(k,'0'+str(n)+'b'))
ans=[]
for i in range(2**n):
  ct1=0
  ct2=0
  for j in range(n):
    if b[i][j]=='1':
      ct1+=1
      ct=0
      for k in range(len(l[j])):
        if int(b[i][l[j][k][0]-1])!=l[j][k][1]:
          ct+=1
      if ct==0:
        ct2+=1
    else:
      ct2+=1
  if ct2==n:
    ans.append(ct1)
print(max(ans))

Measured memory_bytes: 49252
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(_,v.size()){rep(__,v[_].size())cout<<" "<<v[_][__];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 1e18+10 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU

signed main(){
	int n,m,c,s,t;
	while(cin>>n>>m>>c>>s>>t,n){
		vvp G(n);
		vvi cost(n,vi(n,inf));
		rep(i,n)cost[i][i]=0;
		rep(i,m){
			int a,b,co;
			cin>>a>>b>>co;
			a--;b--;
			G[a].pb({b,co});
			G[b].pb({a,co});
			cost[a][b]=cost[b][a]=co;
		}
		rep(k,n)rep(i,n)rep(j,n)
			cmin(cost[i][j],cost[i][k]+cost[k][j]);
		vvi in(c,vi(2));
		rep(i,c)rep(j,2)cin>>in[i][j];
		s--;
		vvi dp(1<<c,vi(c,inf));
		rep(i,c)dp[1<<i][i]=cost[s][in[i][0]-1]+in[i][1];
		rep(i,1<<c)rep(j,c)if(dp[i][j]-inf){
			rep(k,c)if((i&1<<k)==0)
				cmin(dp[i|1<<k][k],dp[i][j]+cost[in[j][0]-1][in[k][0]-1]+in[k][1]);
		}
		// show2d(dp);
		int out=0;
		rep(i,1<<c)rep(j,c)if(dp[i][j]+inf){
			int dist=dp[i][j]+cost[in[j][0]-1][s];
			if(dist<=t){
				int co=0;
				rep(k,c)if(i&1<<k)co++;
				cmax(out,co);
			}
		}
		cout<<out<<endl;
	}
}










Measured memory_bytes: 14620
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int sx, sy, tx, ty;
	scanf("%d %d %d %d", &sx, &sy, &tx, &ty);
	
	int i;
	for (i = sx; i < tx; i++) printf("R");
	for (i = sy; i < ty; i++) printf("U");
	printf("R");
	for (i = ty; i >= sy; i--) printf("D");
	for (i = tx + 1; i > sx; i--) printf("L");
	for (i = sy - 1; i < ty; i++) printf("U");
	for (i = sx; i < tx; i++) printf("R");
	printf("U");
	for (i = tx; i >= sx; i--) printf("L");
	for (i = ty + 1; i > sy; i--) printf("D");
	printf("R");
	
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    private static Scanner sc;

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

    private void run() {
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();

        if (A <= C && C <= B) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21844
#ABC 096 C - Grid Repainting 2
H, W = map(int, input().split())
S = [input() for i in range(H)]

s = [[0] * (W+2) for i in range(H+2)]
for h in range(H):
    for w in range(W):
        s[h+1][w+1] = S[h][w]

c = [[0] * (W+2) for i in range(H+2)]
for h in range(1,H+1):
    for w in range(1,W+1):
        if s[h][w] == '#':
            if s[h][w-1] == '#':
                c[h][w] += 1
                c[h][w-1] +=1
            if s[h][w+1] == '#':
                c[h][w] += 1
                c[h][w+1] +=1
            if s[h+1][w] == '#':
                c[h][w] += 1
                c[h+1][w] +=1
            if s[h-1][w] == '#':
                c[h-1][w] += 1
                c[h-1][w] +=1

for h in range(1,H+1):
    for w in range(1,W+1):
        if s[h][w] == '#':
            if c[h][w] == 0:
                print('No')
                exit()
print('Yes')

Measured memory_bytes: 3192
#include <bits/stdc++.h>
 
using namespace std;
 
#define forsn(i, s, n) for(int i=s;i<int(n);i++)
#define forn(i, n) forsn(i, 0, n)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
 
typedef long long tint;

const int INF = 1e6;
const long double PI = acos(-1);
 
int main() {
	string s; cin >> s;
	int mini = 10000;
	forn(i, s.size()){
		string a = s.substr(i, 3);
		int n = atoi(a.c_str());
		mini = min(mini, abs(753-n));
	}
	cout << mini << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    int sum = 0;
    for (int i = 1; i <= n; i++) {
      int len = String.valueOf(i).length();
      int digitSum = 0;
      for (int ii = 0; ii < len; ii++) {
        digitSum += Integer.parseInt(String.valueOf(i).substring(ii, ii + 1));
      }
      if (digitSum >= a && b >= digitSum) {
        sum += i;
      }
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 27604
#include <stdio.h>
#include <stdlib.h>
//#include <string.h>
#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

typedef struct queue
{
  int a;
  int b;
  struct queue *next;
} queue;

typedef struct Queue
{
  queue *front;
  queue *back;
  int size;
} Queue;

Queue *Queue_init()
{
  Queue *Q = malloc(sizeof(Queue));
  Q->front = NULL;
  Q->back = NULL;
  Q->size = 0;
  return Q;
}

queue *queue_create(int a, int b)
{
  queue *q = malloc(sizeof(queue));
  q->a = a;
  q->b = b;
  q->next = NULL;
  return q;
}

void queue_free(queue *q)
{
  if (q != NULL)
    free(q);
}

bool Queue_empty(Queue *Q)
{
  if (Q->size == 0)
    return true;
  return false;
}

void Queue_free(Queue *Q)
{
  if (Q != NULL)
  {
    if (Queue_empty(Q))
      free(Q);
    else
      printf("queue isn't empty.\n");
  }
  return;
}

queue *Queue_back(Queue *Q)
{
  return Q->back;
}

queue *Queue_front(Queue *Q)
{
  return Q->front;
}

void Queue_pop(Queue *Q)
{
  if (Queue_empty(Q))
    return;
  queue *qf = Q->front;
  Q->front = qf->next;
  Q->size--;
  queue_free(qf);
  return;
}

void Queue_push(Queue *Q, int a, int b)
{
  queue *aq = queue_create(a, b);
  if (Queue_empty(Q))
  {
    Q->front = aq;
    Q->back = aq;
    Q->size++;
    return;
  }
  queue *bq = Queue_back(Q);
  bq->next = aq;
  Q->back = aq;
  Q->size++;
  return;
}

int Queue_size(Queue *Q)
{
  return Q->size;
}

char s[51][51];
int h, w, cntdot = 0, c[51][51];
void scans() {
  for (int i=0; i<h; i++)
    scanf("%s", s[i]);
  for (int i=0; i<51; i++)
    for (int j=0; j<51; j++) {
      if (s[i][j] != '.') s[i][j] = '#';
      else cntdot++;
    }
  return ;
}

void enqueue(Queue *Q, int a, int b) {
  if (s[a][b] == '#') return ;
  if (a > 0 && s[a-1][b] == '.' && c[a-1][b] == -1) {
    Queue_push(Q, a-1, b);
    c[a-1][b] = c[a][b] + 1;
  }
  if (b > 0 && s[a][b-1] == '.' && c[a][b-1] == -1) {
    Queue_push(Q, a, b-1);
    c[a][b-1] = c[a][b] + 1;
  }
  if (s[a+1][b] == '.' && c[a+1][b] == -1) {
    Queue_push(Q, a+1, b);
    c[a+1][b] = c[a][b] + 1;
  }
  if (s[a][b+1] == '.' && c[a][b+1] == -1) {
    Queue_push(Q, a, b+1);
    c[a][b+1] = c[a][b] + 1;
  }
}

void bfs_init() {
  for (int i=0; i<51; i++)
    for (int j=0; j<51; j++)
      c[i][j] = -1;
  c[0][0] = 1;
}

void bfs() {
  Queue *Q = Queue_init();
  enqueue(Q, 0, 0);
  while (!Queue_empty(Q)) {
    queue *qf = Queue_front(Q);
    int a = qf->a;
    int b = qf->b;
    Queue_pop(Q);
    enqueue(Q, a, b);
  }
  return ;
}

int main() {
  scanf("%d %d", &h, &w);
  scans();
  bfs_init();
  bfs();
  if (c[h-1][w-1] == -1) printf("-1\n");
  else {
    int ans = cntdot - c[h-1][w-1];
    printf("%d\n", ans);
  }
  return 0;
}


Measured memory_bytes: 256