akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;

ll a[100011];
ll b[100011];

struct DSU
{
	int S;
	
	struct node
	{
		int p; ll sum;
	};
	vector<node> dsu;
	
	DSU(int n)
	{
		S = n;
		for(int i = 0; i < n; i++)
		{
			node tmp;
			tmp.p = i; tmp.sum = 0;
			dsu.pb(tmp);
		}
	}
	
	void reset(int n)
	{
		dsu.clear();
		S = n;
		for(int i = 0; i < n; i++)
		{
			node tmp;
			tmp.p = i; tmp.sum = 0;
			dsu.pb(tmp);
		}
	}
	
	int rt(int u)
	{
		if(dsu[u].p == u) return u;
		dsu[u].p = rt(dsu[u].p);
		return dsu[u].p;
	}
	
	void merge(int u, int v)
	{
		u = rt(u); v = rt(v);
		if(u == v) return ;
		if(rand()&1) swap(u, v);
		dsu[v].p = u;
		dsu[u].sum += dsu[v].sum;
	}
	
	bool sameset(int u, int v)
	{
		if(rt(u) == rt(v)) return true;
		return false;
	}
	
	ll getstat(int u)
	{
		return dsu[rt(u)].sum;
	}
};

bool used[100001];
bool req[100001];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	vector<ll> v1,v2;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		a[n]^=a[i];
		v1.pb(a[i]);
	}
	v1.pb(a[n]);
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
		b[n]^=b[i];
		v2.pb(b[i]);
	}
	v2.pb(b[n]);
	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());
	for(int i=0;i<=n;i++)
	{
		if(v1[i]!=v2[i])
		{
			cout<<-1<<'\n';
			return 0;
		}
	}
	//swap a[n] with a[i] how many times to reach b?
	v1.erase(unique(v1.begin(),v1.end()),v1.end());
	int ans=0;
	for(int i = 0; i <= n; i++)
	{
		a[i]=lower_bound(v1.begin(),v1.end(),a[i])-v1.begin();
		b[i]=lower_bound(v1.begin(),v1.end(),b[i])-v1.begin();
		if(i<n&&a[i]!=b[i]) ans++;
		if(a[i]!=b[i])
		{
			req[a[i]]=req[b[i]]=1;
		}
	}
	DSU dsu(int(v1.size()));
	for(int i=0;i<=n;i++)
	{
		dsu.merge(a[i],b[i]);
	}
	for(int i=0;i<v1.size();i++)
	{
		if(dsu.rt(i)==i)
		{
			used[i]=1;
		}
	}
	int holy1 = dsu.rt(a[n]);
	int holy2 = dsu.rt(b[n]);
	for(int i=0;i<v1.size();i++)
	{
		if(i!=holy1&&i!=holy2&&req[i]&&used[i]) ans++;
	}
	cout<<ans<<'\n';
}


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

using namespace std;

int main(void) {
    int N, T;
    cin >> N >> T;
    int c[N], t[N];
    for (int i = 0; i < N; i++) {
        cin >> c[i] >> t[i];
    }

    int min = 2000;
    for (int i = 0; i < N; i++) {
        if (t[i] <= T && c[i] < min) {
            min = c[i];
        }
    }

    if (min == 2000) {
        cout << "TLE" << endl;
    } else {
        cout << min << endl;
    }
}

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

using namespace std;
using ll = long long;

int n;
ll C;
ll ans = 0;
const int maxn = 1e5 + 10;
const ll oo = 0x3f3f3f3f3f3f3f3f;

struct Point{
    ll x;
    int v;
};

Point p[maxn];
ll sum[maxn];

bool cmp(Point p1 , Point p2){
    return p1.x < p2.x;
}

void solve(){
    //sort(p + 1 , p + n + 1 , cmp); 
    sum[0] = 0;
    ll cur = 0 , mx = 0; 
    for(int i = 1 ; i <= n ; ++ i){
	cur += p[i].v - (p[i].x - p[i - 1].x);
	if(cur > mx) mx = cur;
	sum[i] = mx;
    }
    ans = max(ans , sum[n]);
    ll now = 0;
    for(int i = n ; i >= 1 ; -- i){
        now += p[i].v;
        ans = max(ans , (sum[i - 1] + now) - 2 * (C - p[i].x));
    } 
}

int main(){
    ios::sync_with_stdio(0);
    cin >> n >> C;	
    for(int i = 1 ; i <= n ; ++ i)
	cin >> p[i].x >> p[i].v;
    solve();
    for(int i = 1 ; i <= n ; ++ i) {
	p[i].x = C - p[i].x;
    }
    for(int i = 1; i <= n/2; i++) {
	swap(p[i], p[n-i+1]);
    }
    solve();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
def ABC_154_A():
    S,T = map(str, input().split())
    A,B = map(int, input().split())
    U = input()

    if U == S:
        print(str(A-1)+' '+str(B))
    else:
        print(str(A)+' '+str(B-1))

if __name__ == '__main__':

    ABC_154_A()

Measured memory_bytes: 2940
s=list(input())
n=len(s)
t=n-1
while t>=0:
    if s[t]=='r':
        if t<5:
            print('NO')
            exit()
        elif s[t-1]=='e' and s[t-2]=='s' and s[t-3]=='a' and s[t-4]=='r' and s[t-5]=='e':
            t-=6
        elif t<6:
            print('NO')
            exit()
        elif s[t-1]=='e' and s[t-2]=='m' and s[t-3]=='a' and s[t-4]=='e' and s[t-5]=='r' and s[t-6]=='d':
            t-=7
        else:
            print('NO')
            exit()
    elif s[t]=='e':
        if t<4:
            print('NO')
            exit()
        elif s[t-1]=='s' and s[t-2]=='a' and s[t-3]=='r' and s[t-4]=='e':
            t-=5
        else:
            print('NO')
            exit()
    elif s[t]=='m':
        if t<4:
            print('NO')
            exit()
        elif s[t-1]=='a' and s[t-2]=='e' and s[t-3]=='r' and s[t-4]=='d':
            t-=5
        else:
            print('NO')
            exit()
    else:
        print('NO')
        exit()
print('YES')
        
            

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

typedef long long ll;
typedef pair< int, int > PII;
typedef pair< ll, ll > PLL;

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define PI 3.14159265358979323846
#define INF 1000000006
#define LINF 1000000000000000006
#define DINF 1e300
#define FI first
#define SE second
#define X FI
#define Y SE
#define PB push_back
#define MP make_pair

const int N = 20;

ll ans;
int d[ N ];
bool f[ N ];
string s;

void init() {
  cin >> s;
  for ( int i = 0 ; i < s.size() ; ++i ) 
    d[ i ] = s[ i ] - '0';
}
void cal( int now ) {
  if ( now == s.size() - 1 ) {
    ll num = 0;
    for ( int i = 0 ; i < s.size() ; ++i ) {
      num = num * 10 + d[ i ]; 
      if ( i == s.size() - 1 )  
        ans += num;
      else if ( f[ i ] == true ) {
        ans += num;
        num = 0;
      }
    }
    return;
  }
  f[ now ] = false;
  cal( now + 1 );
  f[ now ] = true;
  cal( now + 1 );
}
void solve() {
  cal( 0 );

  cout << ans << endl;
}
int main() {
  IOS;
  int __ = 1;
  //cin >> __;
  while ( __-- ) {
    init();
    solve();
  }
  return 0;
}


Measured memory_bytes: 256
class Integer

  # O(min(n-k,k) log m)
  # combination: nPk / k! (mod p), note: m must be a prime number
  def cmb(k, m=10**9+7)
    n = self
    return 0 if k < 0 || n < k
    k = n - k if k > n - k
    n.prm(k, m) * k.prm(k,m).modinv(m) % m
  end

  # mod must be a prime number
  # O(log m)
  def modinv(mod = 10**9+7)
    pow(mod-2, mod)
  end

  # O(log n)
  def pow(n , mod = nil )
    a = self
    res = 1
    while n > 0
      if (n & 1) != 0
        res *= a
        res %= mod if mod
      end
      a *= a
      a %= mod if mod
      n >>= 1
    end
    res
  end

  # O(k)
  def prm(k, mod = nil)
    (0...k).reduce(1) do |res,i|
      res *= (self - i )
      res %= mod if mod
      res
    end
  end
end

class Facts

  def initialize(mod=10**9+7, n_max=1)
    @mod = mod
    @n_max = n_max
    @fact = [1, 1]
    @inv = [0,1]
    @factinv = [1, 1]
    setup_table(n_max) if 1 < @n_max
  end

  def cmb(n,r)
    return 0 if r < 0 || n < r
    setup_table(n) if @n_max < n
    @fact[n] * (@factinv[r] * @factinv[n-r] % @mod) % @mod
  end

  def factorial(n)
    setup_table(n) if @n_max < n
    @fact[n]
  end

  def prm(n,k)
    setup_table(n) if @n_max < n
    @fact[n] * @factinv[n-k] % @mod
  end

  private
    # O(t)
    def setup_table(t)
      (@n_max+1).upto(t) do |i|
        @fact.push( @fact[-1] * i % @mod )
        @inv.push( -@inv[@mod % i] * (@mod / i) % @mod )
        @factinv.push( @factinv[-1] * @inv[-1] % @mod )
      end
      @n_max = t
    end
end

mod = 998244353

n, m, k = gets.to_s.split.map{|e|e.to_i}

b = Array.new(k+1)
b[-1] = m * (m-1).pow(n-1-k, mod)

k.times do |i|
  b[-2-i] = b[-1-i] * (m-1) % mod
end

ans = 0

f = Facts.new(mod)

(k+1).times do |i|
  ans += f.cmb(n-1, i) * b[i] % mod
end

puts ans % mod

Measured memory_bytes: 20836
/*
      author : Nishikawa
      created: 07.08.2020 15:34:49
*/

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

int main(){
    int N;
    cin >> N;
    ll product=1;
    ll tmp;
    vector<ll> a(N);
    for(int i=0; i<N; i++) cin >> a[i];
    for(int i=0 ;i<N; i++) if(a[i]==0){
        cout << "0" << endl;
        return 0;
    }
    for(int i=0; i<N; i++){
        ll input=a[i];
        ll cnt=1;
        ll now=0;
        while(input){
            now+=product*(input%10)*cnt;
            input/=10;
            cnt*=10;
            if(now>MAX){
                cout << "-1" << endl;
                return 0;
            }
        }
        product=now;
    }
    cout << product << endl;

    return 0;
}

Measured memory_bytes: 4056
s = input()
n = input()

char_list = list(n)
length = len(char_list)
result = []
if s != '0':
    for i in range(0,length):
        x = ord(char_list[i]) + int(s)
        if x > 90:
            x = x - 26
        result.append(chr(x))
        
elif s == '0':
    result = char_list
resultstr = ''.join(result)
print(resultstr)

Measured memory_bytes: 3188
// {{{ Templates
#include <bits/stdc++.h>

#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

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


constexpr ll MOD = (ll)1e9 + 7LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

// }}}

struct Graph {
    Graph(const int n)
    {
        edge.resize(n);
    }
    void addEdge(const int from, const int to)
    {
        edge[from].push_back(to);
    }
    vector<vector<int>> edge;
};

int dp_dfs(const Graph& g, const int s, const vector<int>& X)
{
    if (g.edge[s].empty()) {
        return 0;
    }
    unordered_map<int, int> prev;
    unordered_map<int, int> dp;
    prev[0] = 0;
    for (const int to : g.edge[s]) {
        const int Y = dp_dfs(g, to, X);
        for (const auto& e : prev) {
            if (e.first + X[to] <= X[s]) {
                const int v = e.first + X[to];
                if (dp.find(v) != dp.end()) {
                    dp[v] = min(dp[v], e.second + Y);
                } else {
                    dp[v] = e.second + Y;
                }
            }
            if (e.first + Y <= X[s]) {
                const int v = e.first + Y;
                if (dp.find(v) != dp.end()) {
                    dp[v] = min(dp[v], e.second + X[to]);
                } else {
                    dp[v] = e.second + X[to];
                }
            }
        }
        prev = dp;
        dp.clear();
    }
    int mini = INF<int>;
    for (const auto& e : prev) {
        mini = min(mini, e.second);
    }
    return mini;
}

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

    int N;
    cin >> N;
    Graph g(N);
    for (int i = 1; i < N; i++) {
        int from;
        cin >> from;
        from--;
        g.addEdge(from, i);
    }
    vector<int> X(N);
    for (int i = 0; i < N; i++) {
        cin >> X[i];
    }
    const int Y = dp_dfs(g, 0, X);

    if (Y == INF<int>) {
        cout << "IMPOSSIBLE" << endl;
    } else {
        cout << "POSSIBLE" << endl;
    }

    return 0;
}


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

int main() {

    int n,m;
    cin >> n;
    vector<string> s(n);
    for(int i = 0; i < n; i++)  
        cin >> s[i];

    cin >> m;
    vector<string> t(m);
    for(int i = 0; i < m; i++)  
        cin >> t[i];

    int max = 0;

    for(int i = 0; i < n; i++){

        int prize = 0;

        for(int j = i; j < n ; j++){
            if(s[i] == s[j])
                prize++;
        }

        for(int k = 0; k < m; k++){
            if(s[i] == t[k])
                prize--;
        }
        

        if(prize > max)
             max = prize;

    }

    cout << max;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
 
using namespace std;
using namespace __gnu_pbds;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


 
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
		
	int n;
	cin >> n;

	vector<ll> h(n + 1);
	for(int i = 1; i <= n; i++)
		cin >> h[i];

	ll ans = 0;
	map<ll, ll> mp;

	for(int i = 1; i <= n; i++){
		ll x = i - h[i];
		if(mp.count(x))
			ans += mp[x];
		mp[h[i] + i]++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 17104
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

#define INF 10000000

int main() {
    string n;
    cin >> n;
    n = '0' + n;
    int len = n.size(),
        low = 0, up = 0,
        plow = 0, pup = 0;
    for (int i=0; i<len; i++) {
        int digit = n[i] - '0';
        low = min(plow + digit, pup + 10 - digit);
        up  = min(plow + digit + 1, pup + 10 - digit - 1);
        plow = low; pup = up;
    }
    cout << low << '\n';
    return 0;
}

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

int main() {
  int a , b , c;
  cin >> a;
  c = a / 100;
  b = (a - c * 100) / 10;
  a = a - c * 100 - b * 10;
  cout << a + b + c << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;

import org.omg.Messaging.SyncScopeHelper;

public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
		new Test_100().doIt();
	}
	class Test_100{
		void doIt() {
			String str = sc.next();
			 int a = 0;
			 int b = 0;
			 int c = 0;
			 for(int i = 0;i < str.length();i++) {
				 char ch = str.charAt(i);
				 if(ch == 'a')a = 1;
				 else if(ch == 'b')b = 1;
				 else if(ch == 'c')c = 1;
			 }
			 int ans = a + b + c;
			 if(ans == 3)System.out.println("Yes");
			 else System.out.println("No");
		}
	}
}


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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;

int main() {
    lli n;
    cin1(n);
    lli l[n];
    ncin1(n, l);
    lli max_n = 0;
    lli ans = 0;
    REP(i,0,n) {
        max_n = max(max_n, l[i]);
        ans += l[i];
    }
    ans -= max_n;
    if (ans > max_n)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define all(x) x.begin(), x.end()

int main(){
    
    // 1. 入力情報.
    char s[101010];
    int Q;
    scanf("%s %d", s, &Q);
    string S(s);
    
    // 2. 文字列を, Q回操作.
    int t, f;
    char c[11];
    bool flip = false;
    rep(i, Q){
        scanf("%d", &t);
        // 2-1. 文字列 S の前後を反転.
        if(t == 1) flip = !flip;
        
        // 2-2. 文字列 S の先頭, 末尾を操作.
        if(t == 2){
            scanf("%d %s", &f, c);
            string C(c);
            
            // 2-3. 文字列 S の先頭に C を追加.
            if(f == 1){
                if(flip) S.append(C);
                else     S.insert(0, C);
            }
            
            // 2-4. 文字列 S の末尾に C を追加.
            if(f == 2){
                if(flip) S.insert(0, C);
                else     S.append(C);
            }
        }
    }
    
    // 3. 反転チェック.
    if(flip) reverse(all(S));
    
    // 4. 出力.
    printf("%s\n", S.c_str());
    return 0;
    
}

Measured memory_bytes: 1080
//#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <queue>

using namespace std;

#define pb push_back
#define mp make_pair
#define eb emplace_back


typedef long long ll;
typedef long double ld;


const ll inf = 2e9;
const ll base = 998244353;
ll mod = 1e9 + 7;


int n;


vector<int> int_to_vec(int a) {
    vector<int> res;
    while(a > 0)  {
        res.pb(a & 1);
        a /= 2;
    }
    while(res.size() < n) res.pb(0);
    return res;
}




int main() {
//    srand(time(NULL));
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    auto start = clock();


    cin >> n;
    vector<vector<pair<int, int>>> a(n);
    for (int i = 0; i < n; ++i) {
        int s; cin >> s;
        for (int j = 0; j < s;  ++j) {
            int person, kind; cin >> person >> kind;
            --person;
            a[i].pb({person, kind});
        }
    }
    int ans = 0;
    for (int i = 0; i < 1<<n; ++i) {
        auto vec = int_to_vec(i);
        bool flag = true;
        for (int i = 0; i < n; ++i) {
            if (vec[i] == 1) {
                for (auto c : a[i]) {
                    int person = c.first;
                    int kind = c.second;
                    if (vec[person] != kind) flag = false;
                }
            }
        }
        if (flag) {
            int cnt = 0;
            for (auto c : vec) cnt += c;
            ans = max(cnt, ans);
        }
    }
    cout << ans << endl;


    std::cerr << double(clock() - start) / CLOCKS_PER_SEC << std::endl;
    return 0;
}

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

struct Node{
  int p, l, r;
};

Node T[100010];
int depth[100010];

void rec( int s, int d = 0 ){
  depth[s] = d;
  if( T[s].r != -1 ) rec( T[s].r, d );
  if( T[s].l != -1 ) rec( T[s].l, d + 1 );
}



int main(){
  int N; cin >> N;
  for( int i = 0; i < 100010; i++ ) T[i].p = T[i].l = T[i].r = -1;

  for( int i = 0; i < N; i++ ){
    int id, k; cin >> id >> k;

    int l;
    for( int j = 0; j < k; j++ ){
      int c; cin >> c;
      if( j == 0 ) T[id].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = id;
    }
  }

  for( int i = 0; i < N; i++ ){
    if( T[i].p == -1 ){
      rec( i );
      break;
    }
  }
  
  for( int i = 0; i < N; i++ ){
    cout << "node " << i << ": " << "parent = " << T[i].p << ", "
	 << "depth = " << depth[i] << ", ";

    if( T[i].p == -1 ) cout << "root, ";
    else if( T[i].l != -1 ) cout << "internal node, ";
    else cout << "leaf, ";

    cout << "[";
    for( int c = T[i].l; c != -1; c = T[c].r ){
      cout << c;
      if( T[c].r != -1 ) cout << ", "; 
    }
    cout << "]" << endl;;
    
  }
  
}



Measured memory_bytes: 7680
#include <vector>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;

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

int main(int argc, const char * argv[]) {
    int N;
    cin >> N;
    cout << N * N * N << endl;
    return 0;
    
}


Measured memory_bytes: 256
from sys import stdin
import itertools
def main():
    #入力
    readline=stdin.readline
    N,M,Q=map(int,readline().split())
    a=[]
    b=[]
    c=[]
    d=[]
    for i in range(Q):
        li=list(map(int,readline().split()))
        a.append(li[0])
        b.append(li[1])
        c.append(li[2])
        d.append(li[3])

    li_2=list(itertools.combinations_with_replacement(list(range(1,M+1)),N))
    
    max_res=0
    for i in range(len(li_2)):
        A=li_2[i]
        res=0
        for j in range(Q):
            if A[b[j]-1]-A[a[j]-1]==c[j]:
                res+=d[j]
        max_res=max(max_res,res)
    print(max_res)
if __name__=="__main__":
    main()

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

int main(){
	int n,x;
	int *m;
	int m_min;
	int m_sum;
	int y;
	
	cin >> n >> x;
	
	m = new int[n];
	m_min=1000;
	m_sum=0;
	for(int i=0; i<n;i++){
		cin >> m[i];
		if(m[i]<m_min){
			m_min=m[i];
		}
		m_sum+=m[i];
	}
	y=n+(x-m_sum)/m_min;
	cout << y << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){fastio
    ll n,a,b;cin>>n>>a>>b;
    ll x[n];rep(i,0,n-1)cin>>x[i];
    ll ans=0;
    rep(i,1,n-1){
        if((x[i]-x[i-1])*a<=b){
            ans+=(x[i]-x[i-1])*a;
        }else{
            ans+=b;
        }
    }
    cout<<ans<<endl;
    
    return 0;
}





Measured memory_bytes: 4444
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

long double dp[333][333][333];
int n;
long double rec(int x,int y,int z){
    if(dp[x][y][z]!=0)return dp[x][y][z];
    if(!x&&!y&&!z)return 0;
    long double ret=0;
    if(x)ret+=rec(x-1,y+1,z)*(long double)x/n;
    if(y)ret+=rec(x,y-1,z+1)*(long double)y/n;
    if(z)ret+=rec(x,y,z-1)*(long double)z/n;
    ret+=1.0;
    return dp[x][y][z]=ret*n/(x+y+z);
}

int main(){
    cin>>n;
    int x=0,y=0,z=0;
    rep(i,n){
        int a;cin>>a;
        if(a==3)++x;
        if(a==2)++y;
        if(a==1)++z;
    }
    cout<<fixed<<setprecision(12)<< rec(x,y,z)<<endl;
    return 0;
}

Measured memory_bytes: 520320
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P;
typedef vector<int> Vi;
int const MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { return a = b; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { return a = b; } return false; }

int dp[3001][3001];

int main(){
  cin.tie(0); ios::sync_with_stdio(false);
    
  string s1,s2,ans=""; cin>>s1>>s2; int n=s1.size(),m=s2.size();
  for (int i = 0; i < n; i++){
    for (int j = 0; j < m; j++){
      if(s1[i]==s2[j]){
        dp[i+1][j+1]=dp[i][j]+1;
      }else{
        chmax(dp[i+1][j+1],max(dp[i+1][j],dp[i][j+1]));
      }
    }
  }
  while(dp[n][m]!=0){
    if(dp[n][m]==dp[n-1][m])n--;
    else if(dp[n][m]==dp[n][m-1])m--;
    else if(dp[n][m]-1==dp[n-1][m-1]){n--; m--; ans+=s1[n];}
  }
  reverse(ans.begin(),ans.end());
  cout<<ans<<'\n';
}

Measured memory_bytes: 35456
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
    result=(result*base)%modulus;
    exponent=exponent>>1;
    base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
  if(N<K)return 0;
  if(K==0)return 1;
  if(N==0)return 0;

  ll den=1;
  for(ll i=1;i<=K;i++)den*=i;
  ll num=1;
  while(K--){
    num*=N;
    if(num%den==0){
      num/=den;
      den=1;
    }
    N--;
  }

  return num;
}
*/
ll n,m;
int main(){FAST;
  cin>>n>>m;
  ll sum = 0;
  for(ll i=1;i<=m;++i){
    ll x;cin>>x;
    sum+=x;
  }
  cout<<max(-1LL,n-sum);
return 0;
}

/*
 WA? check edge cases, N=1,M=1 etc. Read code fully once and check all variables.
 Read the question again and see what you might have missed.
 Consider changing your solution or find more cases.
 */


Measured memory_bytes: 3660
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;
// const int mod = 998244353;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

inline void work() {
    int a;
    cin >> a;
    a = a * a * a + a * a + a;
    cout << a;
}

int main() {
    // freopen(".txt", "r", stdin);
    quickread();
    work();
    return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <string.h>
 
int main () {
	char S[15], T[15], A[15];
	int B, U;
	scanf ("%s %s", S, T);
	scanf ("%d %d", &B, &U);
	scanf ("%s", A);
	int tes = strcmp (S,A); 
	if (tes == 0) {
		B--;
	} else U--;
	printf ("%d %d\n", B, U);
}

Measured memory_bytes: 1720
#define ll long long

#include "bits/stdc++.h"

using namespace std;
static const int INF = (1 << 21);

int main() {
	char c[6];
	for (int i = 0;i < 6;i++) cin >> c[i];
	if (c[0] == c[5] && c[1] == c[4] && c[2] == c[3]) cout << "YES" << endl;
	else cout << "NO" << endl;

}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static int gcd(int a , int b){
		if(a < b ){
			return gcd(b, a);
		}
		if(b == 0){
			return a;
		}
		return gcd(b , a % b);
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		long ret = 0;
		for(int a = 1 ; a <= K ; ++a){
			for(int b = 1 ; b <= K ; ++b){
				int g1 = gcd(a , b);
				for(int c = 1 ; c <= K ; ++c){
					int g2 = gcd(g1 , c);
					ret += g2;
				}
			}
		}
		System.out.println(ret);
	}
}


Measured memory_bytes: 27304
//ABC085-B(Kagami Mochi)
#include<iostream>
#include<set>
using namespace std;

//setを使う(重複する値は削除されるので単純)


int main(){
    int n,d;
    cin>>n;
    
    set<int> S;
    
    for(int i=0; i<n; i++){
        cin>>d;
        S.insert(d);
    }
    
    cout<<S.size()<<endl;
    
    return 0;
}

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

using namespace std;

int main() {
    string S;
    cin >> S;
    int n = S.length();
    int l = 0, r = n - 1;
    int ans = 0;
    bool ok = true;
    while (l < r) {
        if (S[l] == S[r]) {
            ++l;
            --r;
        } else if (S[l] == 'x') {
            ans += 1;
            ++l;
        } else if (S[r] == 'x') {
            ans += 1;
            --r;
        } else {
            ok = false;
            break;
        }
    }

    if (ok) cout << ans << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;
 
int main(){

    int N,ans=0;
    string S;

    cin>>N>>S;

    for(int i=0;i<(N-2);i++){
        if(S[i]=='A'
        &&S[i+1]=='B'
        &&S[i+2]=='C')ans++;
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); --i)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)x.size())
using pii = pair<int, int>;
using vvi = vector<vector<int>>;
using vi  = vector<int>;
constexpr int INF = 1001001001001001001LL;

struct MinCostFlow {
    struct edge { int to, cap, cost, rev; };
    int V;
    vector<vector<edge>> G;
    vi dist, prevv, preve;

    MinCostFlow(int V) : V(V), G(V), dist(V), prevv(V), preve(V) {}

    void add_edge(int from, int to, int cap, int cost) {
        G[from].push_back((edge){ to,   cap, cost, sz(G[to])       });
        G[to  ].push_back((edge){ from, 0,  -cost, sz(G[from]) - 1 });
    }

    // 流せない場合は-1を返す
    int get(int s, int t, int f) {
        int res = 0;
        while (f > 0) {
            fill(all(dist), INF);
            dist[s] = 0;
            bool update = true;
            while (update) {
                update = false;
                rep(v, 0, V) {
                    if (dist[v] == INF) continue;
                    rep(i, 0, sz(G[v])) {
                        auto &e = G[v][i];
                        if (e.cap > 0 && dist[e.to] > dist[v] + e.cost) {
                            dist[e.to] = dist[v] + e.cost;
                            prevv[e.to] = v;
                            preve[e.to] = i;
                            update = true;
                        }
                    }
                }
            }

            if (dist[t] == INF) {
                return -1;
            }

            int d = f;
            for (int v = t; v != s; v = prevv[v]) {
                d = min(d, G[prevv[v]][preve[v]].cap);
            }
            f -= d;
            res += d * dist[t];
            for (int v = t; v != s; v = prevv[v]) {
                auto &e = G[prevv[v]][preve[v]];
                e.cap -= d;
                G[v][e.rev].cap += d;
            }
        }
        return res;
    }
};

signed main() {
    int V, E, F;
    cin >> V >> E >> F;
    MinCostFlow min_cost_flow(V);
    rep(i, 0, E) {
        int vs, vt, cap, cost;
        cin >> vs >> vt >> cap >> cost;
        min_cost_flow.add_edge(vs, vt, cap, cost);
    }
    cout << min_cost_flow.get(0, V - 1, F) << endl;
}



Measured memory_bytes: 3268
import Control.Monad

printLineN :: Int -> Char -> IO ()
printLineN n c = do
  replicateM n $ putChar c
  putChar '\n'

printRectangle :: Int -> Int -> IO ()
printRectangle h w = do
  replicateM h $ printLineN w '#'
  return ()

main :: IO ()
main = do
  input <- getLine
  let [h, w] = map read $ words input
  if h == 0 && w == 0
    then do return ()
    else do
    printRectangle h w
    putChar '\n'
    main

Measured memory_bytes: 4088
#![allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
const T: i64 = 1e18 as i64;
fn solve() -> i64 {
    let _: usize = read();
    let a: Vec<i64> = read_vec();
    if a.contains(&0) {
        return 0;
    }
    let mut sum = 1i64;
    for i in a {
        if let Some(v) = sum.checked_mul(i) {
            sum = v;
        }
        else {
            return -1;
        }
    }
    if sum > 1e18 as i64 { -1 } else { sum }
}
fn main() {
    println!("{}", solve());
}

Measured memory_bytes: 5824
n,m = map(int,input().split())
a = set(int(input()) for _ in range(m))

mod = 10**9 + 7

ans = [0] * (n+2)
ans[0] = 0
ans[1] = 1
for i in range(2,n+2):
    if(i-1 in a):
        continue
    for j in [-1,-2]:
        ans[i] += ans[i+j]
    ans[i] = ans[i] % mod

print(ans[-1])

Measured memory_bytes: 58200
# C - Guess The Number

N, M = map(int, input().split())
num = [-1] * N
ans = True

for _ in range(M):
    s, c = map(int, input().split())
    if num[s - 1] != -1 and num[s - 1] != c:
        ans = False
        break
    num[s - 1] = c

if 1 < N and num[0] == 0:
    ans = False

if 1 < N and num[0] == -1:
    num[0] = 1

if N == 1 and num[0] == -1:
    num[0] = 0

for i in range(N):
    if num[i] == -1:
        num[i] = 0

print(''.join([str(n) for n in num]) if ans else -1)


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

#define int long long
using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    int n, sum = 0; cin >> n;
    for (int i = 1;i <= n; i++){
        for (int j = 1;j <= n; j++){
            for (int k = 1;k <= n; k++)
                sum += __gcd(i, __gcd(j,k));
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <tuple>
#include <math.h>
#include <set>
#include <map>
using namespace std ;
using ll = long long ;
using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
using vb = vector<bool> ;
using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end() 
const ll INF = 1e18 ;
const ll mod = 1e9+7 ;
const double pie = acos(-1); 
vll dx4 = {-1,0,1,0} ;
vll dy4 = {0,-1,0,1} ;
vll dx8 = {-1,0,1,1,1,0,-1,-1} ;
vll dy8 = {-1,-1,-1,0,1,1,1,0} ; 

void fix_cout(){cout << fixed << setprecision(20) ; }
ll gcd(ll a,ll b){if(b==0) return a ; return gcd(b,a%b) ; }
ll lcm(ll a,ll b){return a/gcd(a,b)*b ; }
void chmax(ll &a,ll b){if(a<b) a = b ; }
void chmin(ll &a,ll b){if(a>b) a = b ; }

int main(){
	ll n ; cin >> n ;
	ll mx = -1 ;
	ll sum = 0 ;
	for(int i=0;i<n;i++){
		ll a ; cin >> a ;
		sum += a ;
		chmax(mx,a) ;
	}
	cout << sum-mx/2 << endl ;
}

Measured memory_bytes: 3596
#include<stdio.h>
int main(){
  int x,y;
  while(1){
  scanf("%d %d",&x,&y);
  if(x==0 && y==0)break;
  if(x>y)printf("%d %d\n",y,x);
  else if(x<y)printf("%d %d\n",x,y);
  else printf("%d %d\n",x,y);
  }
  return 0;
}

Measured memory_bytes: 600
A, B, C = map(int, input().split())

count = 0
if C - B < 0:
    count = C + B
elif C - B >=0:
    if C - B - A <=0:
        count = C + B
    elif C - B - A >0:
        count = A + 2*B  +1
    
print(count)


Measured memory_bytes: 3068
#include <stdio.h>
int main()
{
    int a,b,c,d,e;
    scanf("%d",&a);
    b=a%10;
    a=a/10;
    c=a%10;
    a=a/10;
    d=a%10;
    a=a/10;
    e=a%10;
    a=a/10;
    if((b==c && c==d) || (c==d && d==e)){
        printf("Yes\n");
    }
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    int a, b, sum, mul, sub;
    cin>>a>>b;

    sum=a+b;
    mul=a*b;
    sub=a-b;

    if(sum>=mul && sum>=sub) cout<<sum<<endl;
    else if(mul>=sum && mul>=sub) cout<<mul<<endl;
    else if(sub>=sum && sub>=mul) cout<<sub<<endl;


    return 0;
}



Measured memory_bytes: 3584
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line = gets();
    let mut it = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<usize>().unwrap());
    let (n, k) = (it.next().unwrap(), it.next().unwrap());
    let mut v = vec![0; n];
    for _ in 0..k {
        let line = gets();
        let _d1 = line.trim().parse::<u32>().unwrap();
        let line = gets();
        let it = line
            .trim()
            .split_whitespace()
            .map(|x| x.parse::<usize>().unwrap());
        for i in it {
            v[i - 1] += 1;
        }
    }
    println!("{}", v.iter().filter(|&&x| x == 0).count());
}


Measured memory_bytes: 2092
#include<bits/stdc++.h>
const int M=1e9+7;// M=1e9+7;//M=300000;//
const int N=2e6+5;
typedef long long int ll;
using namespace std;
 
ll cnt(0),sum(0),n,x,y,t,i,j,temp,k,ans(0),mn(M),mx(-9e9);
map<ll,ll> m;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n;
	ll a[n+1];
	for(i=0;i<n;i++)
	{
		cin>>x;
		ans+=m[i-x];
		m[i+x]++;
	}
	
	cout<<ans;
}

Measured memory_bytes: 26312
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int n;
string s;
int p=0;
int Solve(){
    vector<int> v;
    if(s[p]=='['){//最初が[だった場合
        while(s[p]=='['){
            p++;
            v.push_back(Solve());
            p++;
        }
        sort(v.begin(),v.end());
        int ans=0;
        for(int i=0;i<(v.size()+1)/2;i++){
            ans+=v[i];
        }
        return ans;
    }else{//最初が数字だった場合
        int l=p;
        for(;s[p]!=']';p++);
        return (stoi(s.substr(l,p-l))+1)/2;
    }
}

int main(){
    cin>>n;
    while(n>0){
        cin>>s;
        p=0;
        cout<<Solve()<<endl;
        n--;
    }
    return 0;
}


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

#define int long long
#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define endl "\n"
#define ends " "
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
#define debugV(v) cerr << #v << ": [ "; for(int __ = 0; __ < v.size(); __++) cerr << v[__] << ((__ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugVP(v) cerr << #v << ": [ "; for(int ___ = 0; ___ < v.size(); ___++) cerr << '{' << v[___].first << ", " << v[___].second << '}' << ((___ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugA(a, n) cerr << #a << ": [ "; for(int ____ = 0; ____ < n; ____++) cerr << a[____] << ((____ != n - 1) ? ", " : ends); cerr << ']' << endl
#define print(args...) fprintf (stderr, args)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
const int INF = 1e9, MOD = INF + 7 /* INF - 1755647 */;

/////////////////////////////////////////////////////////////////////

const int N = 1e3 + 20;

int dis[N][N];
int dx[] = {+1, -1, 0, 0};
int dy[] = {0, 0, +1, -1};
char a[N][N];
int n, m;

bool isVal(int i, int j) { return 0 < i && i <= n && 0 < j && j <= m; }

int32_t main() {

    sync;

    cin >> n >> m;
    queue<pii> q;
    for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) dis[i][j] = INF;
    for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) {
        cin >> a[i][j];
        if (a[i][j] == '#') q.push(make_pair(i, j)), dis[i][j] = 0;
    }
    while(!q.empty()) {
        pii v = q.front(); q.pop();
        int x = v.first, y = v.second;
        for(int i = 0; i < 4; i++) {
            int xx = x + dx[i], yy = y + dy[i];
            if (isVal(xx, yy) && dis[x][y] + 1 < dis[xx][yy]) {
                dis[xx][yy] = dis[x][y] + 1;
                q.push(make_pair(xx, yy));
            }
        }
    }

    int mx = 0;
    for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) mx = max(mx, dis[i][j]);

    cout << mx << endl;
    
    return 0;
}


Measured memory_bytes: 25652
def main():
    n = int(input())
    h = list(map(int, input().split()))
    maxv = 0
    cnt = 0
    for i in range(n-1):
        if h[i+1] <= h[i]:
            cnt += 1
        else:
            maxv = max(maxv, cnt)
            cnt = 0    
    maxv = max(maxv, cnt)
    print(maxv)
     
if __name__ == '__main__':
    main()

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

using namespace std;

bool ok(string s){
  ll n = s.size();
  for (int i = 0; i < n/2; i++){
    if (s[i] != s[n - 1 - i]){
      return 0;
    }
  }
  for (int i = 0; i < n/4; i++){
    if (s[i] != s[n/2 - 1 - i])
      return 0;
  }
  for (int i = 0; i < n/4; i++){
    if (s[i + (n + 1)/2] != s[n - 1 - i])
      return 0;
  }

  return 1;
}

int main(void){
  string s;
  cin >> s;
  
  if (ok(s))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
    

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int n,d;
	while(cin>>n>>d,n+d){
		vvi G(n);
		vi sum(n);
		rep(i,n){
			int m;
			cin>>m;
			rep(j,m){
				int a;
				cin>>a;
				sum[i]+=a;
				G[i].pb(a);
			}
		}
		int ma=-1;
		while(1){
			bool h=false;
			rep(i,n)if(G[i].size()){
				int ma=-1;
				rep(j,n)if(i!=j)ma=max(ma,sum[j]);
				int m=G[i].size()-1;
				if(sum[i]-G[i][m]+d>=ma){
					sum[i]-=G[i][m];
					G[i].erase(G[i].begin()+m);
					ma=-1;
					h=true;
				}
			}
			if(!h)break;
		}
		bool h=false;
		rep(i,n)if(G[i].size())h=true;
		if(h)cout<<"No"<<endl;
		else cout<<"Yes"<<endl;
	}
}

Measured memory_bytes: 1260
#include"bits/stdc++.h"

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7

ll mul(ll& l, ll r) {
	l = (l*r) % MOD;
	return l;
}

int main()
{
	ll N, tmp;
	cin >> N;
	vector<pair<ll, bool>> pos;
	REP(i, N) {
		cin >> tmp;
		pos.push_back({ tmp,true });
	}
	REP(i, N) {
		cin >> tmp;
		pos.push_back({ tmp,false });
	}
	sort(pos.begin(), pos.end());

	ll res = 1;
	ll cnt = 0;
	for (auto p : pos) {
		if (cnt > 0) {
			if (p.second)cnt++;
			else {
				mul(res, cnt);
				cnt--;
			}
		}
		else if (cnt == 0) {
			cnt = (p.second ? 1 : -1);
		}
		else {
			if (p.second) {
				mul(res, -cnt);
				cnt++;
			}
			else cnt--;
		}
	}
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 6512
n = int(input())
a = list(map(int,input().split(" ")))
b = list(map(int,input().split(" ")))
c = list(map(int,input().split(" ")))

s = 0
for num in b:
    s += num

for i in range(len(a)-1):
    if a[i] + 1 == a[i+1]:
        s += c[a[i]-1]

print(s)

Measured memory_bytes: 3060
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    string S; 
    ll K;
    string answer = "1";
    ll tri5 = 5e15;
    cin >> S >> K;

    rep(i, K){
        if (S[i] != '1'){answer = S[i]; break;}
    }

    cout << answer << endl;

    return 0;
}

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

using namespace std;
using ll = long long;


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

    ll res = 0;
    ll sum = 0;
    int right = 0;

    for(int left = 0; left < n; left++){
        while(right < n && sum + a[right] == (sum xor a[right])){
            sum += a[right];
            right++;
        }

        res += (right - left);

        if(right == left)right++;
        else sum -= a[left];
    }

    cout << res << endl;
}

Measured memory_bytes: 1024
N, M = gets.split.map(&:to_i)

HArray = gets.split.map(&:to_i)
ABArray = readlines.map(&:chomp!).map { |e| e.split.map(&:to_i) }

hash = []
ABArray.each do |pair|
  if hash[pair[0] - 1]
    hash[pair[0] - 1] << pair[1] - 1
  else
    hash[pair[0] - 1] = [pair[1] - 1]
  end

  if hash[pair[1] - 1]
    hash[pair[1] - 1] << pair[0] - 1
  else
    hash[pair[1] - 1] = [pair[0] - 1]
  end
end

count = 0
HArray.each_with_index do |h, index|
  if hash[index]
    if h > HArray.values_at(*hash[index]).max
      count += 1
    end
  else
    count += 1
  end
end

puts count


Measured memory_bytes: 31796
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

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

   int x;
   cin >> x;
   int ans = 0;
   ans += x / 500 * 1000;

   x %= 500;
   ans += x / 5 * 5;
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256