akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    long h,w,d;
    long x,y,xy;
    long hikaku[3] = {999};
    while (1) {
        
        hikaku[0] = 999;
        hikaku[1] = 999;
        hikaku[2] = 8999999;
        scanf("%ld %ld",&h,&w);
        if (h==0 && w==0) {
            break;
        }
        
        d=(h*h)+(w*w);
        
        for (y=1; y<=150; y++) { //????????´???
            for (x=y+1;x<=150; x++) {
                xy = (x*x) + (y*y);
                
                if (h==y && w==x) {
                    continue;
                }

                if (d <= xy) {
                    
                    if (d == xy) {
                        
                        if (hikaku[2] > xy && y>=h) {
                            hikaku[0] = x;
                            hikaku[1] = y;
                            hikaku[2] = xy;
                        }
                        
                        if (y>=h && hikaku[1] > y) {
                            hikaku[0] = x;
                            hikaku[1] = y;
                            hikaku[2] = xy;
                        }
                    }
                    
                    if (hikaku[2] > xy && d < xy) {
                        hikaku[0] = x;
                        hikaku[1] = y;
                        hikaku[2] = xy;
                    }
                    
                }
            }
        }
    printf("%ld %ld\n",hikaku[1],hikaku[0]);
            
    }
    return 0;
}

Measured memory_bytes: 600
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var ns string
	fmt.Scanf("%s", &ns)

	n, err := strconv.Atoi(ns)
	if err != nil {
		panic(err)
	}
	parts := strings.Split(ns, "")
	sum := 0
	for _, p := range parts {
		i, err := strconv.Atoi(p)
		if err != nil {
			panic(err)
		}
		sum += i
	}

	if n%sum == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////

int main() {
	string S;
	cin >> S;
	bool can[11];
	for (int i = 0; i < 11; ++i)can[i] = false;
	for (int i = 0; i < S.size(); ++i) {
		if (S[i] == 'A' || S[i] == 'T' || S[i] == 'C' || S[i] == 'G') {
			can[i] = true;
		}
	}
	int ans = 0;
	for (int i = 0; i < S.size();) {
		int count = 0;
		if (can[i]) {
			while (can[i]&&i<S.size()) {
				count++;
				i++;
			}
			ans = max(ans, count);
		}
		else {
			i++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include <array>
using namespace std;

void bubbleSort(int arr_size, int* arr) {
    int tmp;
    for (int i = 0; i < arr_size; ++i) {
        for (int j = arr_size - 1; j > i; --j) {
            if(arr[j] < arr[j - 1]) {
                tmp = arr[j];
                arr[j] = arr[j - 1];
                arr[j - 1] = tmp;
            }
        }
    }
}

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

    int L[2000];
    for (int i = 0; i < N; ++i) cin >> L[i];
    bubbleSort(N, L);

    int num = 0;
    for (int i = 0; i < N - 2; ++i ) {
        for (int j = i + 1; j < N - 1; ++j) {
            for (int k = j + 1; k < N; ++k) {
                if (L[k] < L[j] + L[i]) {
                    ++num;
                } else {
                    break;
                }
            }
        }
    }

    std::cout << num << endl;
    return 0;
}

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

using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;

int main() {
	lli a;
	cin >> a;
	cout << (a - 1) * a / (lli)2 << endl;

	return 0;
}


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

int read();

int n;
int dis[202][202];
int fa[202], fw[202];
int find(int x) {
    if (fa[x] == x) return x;
    int ret = find(fa[x]);
    fw[x] ^= fw[fa[x]];
    return fa[x] = ret;
}

bool merge(int x, int y) {
    dis[x][y] = 1;
    int fx = find(x), fy = find(y);
    if (fx == fy) return fw[x] ^ fw[y];
    fa[fx] = fy, fw[fx] = fw[x] ^ fw[y] ^ 1;
    return 1;
}

void Floyd() {
    for (int k = 1; k <= n; ++k) {
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
            }
        }
    }
}

char s[202];
int main() {
    n = read();
    for (int i = 1; i <= n; ++i) {
        fa[i] = i;
        for (int j = i + 1; j <= n; ++j) dis[i][j] = dis[j][i] = 1000000;
    }

    for (int i = 1; i <= n; ++i) {
        scanf("%s", s + 1);
        for (int j = 1; j <= n; ++j)
            if (s[j] == '1')
                if (!merge(i, j)) return puts("-1"), 0;
    }

    Floyd();
    int res = 0;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j) res = max(res, dis[i][j]);
    printf("%d\n", res + 1);
    return 0;
}

int read() {
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <cstring>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF 1e18

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

const ll MOD = 1e9 + 7;

ll fastPow(ll x, ll n)
{
    if (n == 0)
        return 1;
    if (n % 2 == 0)
        return fastPow(x * x % MOD, n / 2);
    else
        return x * fastPow(x, n - 1) % MOD;
}

ll fac[112345];
void combInit(int mx)
{
    fac[0] = 0;
    fac[1] = 1;
    for (int i = 2; i <= mx; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
    }
}

ll modDiv(ll a, ll b)
{
    return a * fastPow(b, MOD - 2) % MOD;
}

int main()
{
    combInit(11234);

    ll perm[1010][1010];

    for (int i = 1; i <= 1000; i++)
    {
        perm[i][1] = i;
        for (int j = 2; j <= 1000; j++)
        {
            perm[i][j] = perm[i][j - 1] * (i - j + 1);
            perm[i][j] %= MOD;
        }
    }

    int n, a, b, c, d;

    cin >> n >> a >> b >> c >> d;

    ll dp[1010][1010];

    memset(dp, 0, sizeof(dp));

    for (int i = 0; i <= n; i++)
        dp[0][i] = 1;

    for (int i = 1; i <= n; i++)
    {
        for (int j = a; j <= b; j++)
        {
            dp[i][j] += dp[i][j - 1];
            dp[i][j] %= MOD;

            for (int k = c; k <= d; k++)
            {
                if (i - j * k < 0)
                    break;
                dp[i][j] += dp[i - j * k][j - 1] * modDiv(perm[n - i + j * k][j * k], fastPow(fac[j], k) * fac[k] % MOD);
                dp[i][j] %= MOD;
            }
        }
    }

    cout << dp[n][b] << endl;

    return 0;
}

Measured memory_bytes: 16256
#include <algorithm>
#include <bitset>
#include <climits>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <tuple>
#include <utility>
#include <valarray>
#include <vector>

#define rep(i, a, n) for(int i = (a);i < (n);i++)
#define REP(i, n)    rep(i, 0, n)
#define all(e)       (e).begin(), (e).end()

#ifdef LOCAL
#define show(x) cerr<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#else
#define show() true
#endif

using namespace std;
using ll=long long;
template<class T> using V=vector<T>;

template<class T, class U>
void chmin(T &t, const U u) { if (t > u) t = u; }

template<class T, class U>
void chmax(T &t, const U u) { if (t < u) t = u; }

const int INF = (1 << 30) - 1;
const ll INFL = (ll) 5e15;
const int MOD = 1000000007;

class Solver {
public:
    void solve() {
        cin >> S;

        for (int i = 1; i < S.size(); ++i) {
            string a = S.substr(0, i);
            string b = S.substr(i, S.size());
            string c = a;
            string d = b;
            reverse(all(a));
            reverse(all(b));
            st.insert(a + b);
            st.insert(c + b);
            st.insert(a + d);
            st.insert(c + d);
            st.insert(b + a);
            st.insert(d + a);
            st.insert(b + c);
            st.insert(d + c);
        }

        cout << st.size() << endl;

        return;
    }

private:
    string S;
    set<string> st;
};


int main() {

    int N;
    cin >> N;
    while (N--) {
        Solver().solve();
    }

    return 0;
}



Measured memory_bytes: 3260
N,K=map(int,input().split())
P=list(map(int,input().split()))
P=list(map(lambda x:x-1,P)) 
C=list(map(int,input().split()))
ans=-float("inf")
for i in range(N):
   st=i
   tmp=0
   for j in range(K):
      st=P[st]
      tmp+=C[st]
      ans=max(ans,tmp)
      if i==st:
         break
   s,v=divmod(K,j+1)
   if s>1 and v==0:
      s-=1
      v=j+1
   tmp*=s
   ans=max(ans,tmp)
   for j in range(v):
      st=P[st]
      tmp+=C[st]
      ans=max(ans,tmp)
print(ans)

Measured memory_bytes: 68580
n=int(input())
s=list(input() for _ in range(n))
d={}

res=0
for c in s:
    c=sorted(c)
    c=''.join(c)
    if c not in d:
        d[c]=1
    else:
        d[c]+=1
for i in d.values():
    res+=(i*(i-1))/2
print(int(res))

Measured memory_bytes: 72664
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll MOD=1e9+7;

void solve()
{
	ll n,a,b,ans=0,k=0;;
	cin>>n>>a>>b;
	ll c[n];
	for(ll i=0;i<n;i++)
		cin>>c[i];
	for(ll i=1;i<n;i++)
	{
		// cout<<(c[i]-c[i-1])*a<<" "<<ans<<endl;
		ans+=min(b,(c[i]-c[i-1])*a);
	}
	cout<<ans;
	return;
}
int main()
{
        fast;
        ll q;
        q=1;
        // cin>>q;
        while(q--)
        	solve();
        
        return 0;
}


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

using namespace std;

int main() {
  int K, S;
  cin >> K >> S;

  K = min(K, S);
  int cnt = 0;
  for (int i = max(0, S - 2 * K); i <= K; ++i) {
    cnt += min(K, S - i) - max(0, S - i - K) + 1;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
import sys
from itertools import accumulate
from bisect import bisect_left
read = sys.stdin.read

N, *A = map(int, read().split())
A = list(accumulate([0] + A))
a = A[-1] // 2
n = bisect_left(A, a) - 1

print(min(abs(2 * A[n] - A[-1]), abs(2 * A[n + 1] - A[-1])))

Measured memory_bytes: 25596
import sys, os
import collections

MOD = 10 ** 9 + 7

def solve(input_stream):
  N = read_int(input_stream)
  numbers = read_ints(input_stream)
  ans = 1.0
  mother = 0
  for value in numbers:
    mother += 1.0/value
  
  return [str(ans/mother)]


def read_ints(input_stream):
  return [i for i in map(int, input_stream.readline().strip().split())]

def read_int(input_stream):
  return int(input_stream.readline().strip())


if __name__ == "__main__":
    outputs = solve(sys.stdin)
    for line in outputs:
      print(line)

Measured memory_bytes: 38384
#include <cstddef>
#include <complex>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <limits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>
#include <bitset>

using ll = long long;
using ull = unsigned long long;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

int main()
{
    using namespace std;

    int n;
    cin >> n;
    vec<int> w(n);
    for (auto& e : w)
    {
        cin >> e;
    }

    int ans = 1000000000;

    for (int i = 1; i < w.size(); ++i)
    {
        auto l = accumulate(w.cbegin(), w.cbegin() + i, 0);
        auto r = accumulate(w.cbegin() + i, w.cend(), 0);

        ans = min(ans, abs(l - r));
        //cout << l << " " << r << endl;
    }

    cout << ans << endl;

    return 0;
}
 

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

void dfs(Int start, vector<pair<Int, Int> >& h, vector<vector<Int> >& table, vector<bool>& check) {
    /*
    cout << "START_DFS" << endl;
    for (Int j = 0; j < check.size(); ++j) {
        cout << check[j] << " ";
    }
    cout << endl;
    */
    for (Int i = 0; i < table[start].size(); ++i) {
        //cout << "POINT = " << start << " " << table[start][i] << endl;
        //cout << "HEIGHT = " << h[start].first << " "  << h[table[start][i]].first << endl;
        if (check[table[start][i]]) {
            //cout << "DFS" << endl;
            if (h[start].first == h[table[start][i]].first) {
                //cout << "IF" << endl;
                check[table[start][i]] = false;
                check[start] = false;
            } else if (h[start].first < h[table[start][i]].first) {
                //cout << "ELSE IF < " << endl;
                check[start] = false;
            } else if (h[start].first > h[table[start][i]].first) {
                //cout << "ELSE IF > " << endl;
                check[table[start][i]] = false;
            }
            dfs(table[start][i], h, table, check);
        }
    }
    //cout << "END_DFS" << endl;
    return;
}

int main(void) {
    Int n, m;
    cin >> n >> m;
    Int a, b;
    vector<pair<Int, Int> > h(n);
    for (Int i = 0; i < n; ++i) {
        h[i].second = i;
        cin >> h[i].first;
    }
    vector<vector<Int> > table(n);
    for (Int i = 0; i < m; ++i) {
        cin >> a >> b;
        --a; --b;
        table[a].push_back(b);
        table[b].push_back(a);
    }
    vector<bool> check(n, true);
    /*
       cout << "TABLE" << endl;
       for (Int i = 0; i < n; ++i) {
       for (Int j = 0; j < table[i].size(); ++j) {
       cout << table[i][j] << " ";
       }
       cout << endl;
       }
     */

    for (Int i = 0; i < n; ++i) {
        //cout << "START" << endl;
        if (check[i] == true) {
            //cout << h[i].second << " " << h[i].first << endl;
            dfs(h[i].second, h, table, check);
        }
        //cout << "END" << endl;
    }
    Int cnt = 0;
    for (Int i = 0; i < check.size(); ++i) {
        if (check[i]) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 13796
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <string>
#include <cmath>
#define REP(i,a,b) for (int i = a; i < (b); i++)
#define sz(t) int(t.size())
#define INF 1000000000
const int DIV = 1000000000 + 7;
using namespace std;
typedef long long ll;

#define MOD 10007

int main(void) {
    for (;;) {
        int n, m;
        cin >> n >> m;
        if (n == 0 && m == 0) {
            break;
        }
        vector<int> C;
        vector<int> X;
        REP(i, 0, m) {
            int c;
            cin >> c;
            C.push_back(c);
        }
        REP(i, 0, n) {
            int x;
            cin >> x;
            X.push_back(x);
        }

        vector<int> dp(256, INF);
        dp[128] = 0;
        REP(i, 0, n) {
            vector<int> new_dp(256, INF);
            REP(y, 0, 256) {
                for (auto c : C) {
                    int target = y + c;
                    if (target > 255) {
                        target = 255;
                    } else if (target < 0) {
                        target = 0;
                    }
                    new_dp[target] = min(new_dp[target], (int)(dp[y] + pow(X[i] - target, 2)));
                }
            }
            dp = new_dp;
        }
        int ans = INF;
        REP(i, 0, 256) {
            ans = min(ans, dp[i]); 
        }
        cout << ans << endl;
    }
}

// while True:
//     N, M = map(int, input().split())
//     if N == 0 and M == 0:
//         break

//     C = [0] * M
//     for i in range(M):
//         C[i] = int(input())
//     X = [0] * N
//     for i in range(N):
//         X[i] = int(input())

//     dp = [INF] * 256 
//     dp[128] = 0
//     for i in range(N):
//         new_dp = [INF] * 256
//         for val in range(0, 256):
//             for c in C:
//                 target = val + c
//                 if target > 255:
//                     target = 255
//                 elif target < 0:
//                     target = 0
//                 new_dp[target] = min(new_dp[target], dp[val] + (target - X[i]) ** 2)
//         dp = new_dp
//     print(min(dp))


Measured memory_bytes: 3248
#include<cstdio>

int main() {
  int n, Rt;
  int maxv = -2e9;
  int minv = 2e9;

  scanf("%d", &n);

  for ( int i = 0; i < n; i++ ) {
    scanf("%d", &Rt);
    if (maxv < Rt-minv) maxv = Rt-minv;
    if (minv > Rt) minv = Rt;
  }

  printf("%d\n", maxv);

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
#define fi first
#define se second
#define pb push_back

const int N = 102;
int x[N], y[N], n;

ld cost(pair <ld, ld> center) {
    ld ret = 0;
    for (int i = 0; i < n; i++) {
        ld dist = (center.fi - x[i]) * (center.fi - x[i]) + (center.se - y[i]) * (center.se - y[i]);
        ret = max(ret, dist);
    }
    return sqrt(ret);
}

ld ch(ld x_try) {
    ld ly = 0, ry = 1000;
    for (int i = 0; i < 100; i++) {
        ld mid1 = ly + (ry - ly) / 3;
        ld mid2 = ry - (ry - ly) / 3;
        if (cost({x_try, mid1}) < cost({x_try, mid2})) {
            ry = mid2;
        } else {
            ly = mid1;
        }
    }
    return ly;
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &x[i], &y[i]);
    }
    ld lx = 0, rx = 1000;
    for (int i = 0; i < 100; i++) {
        ld mid1 = lx + (rx - lx) / 3;
        ld mid2 = rx - (rx - lx) / 3;
        if (cost({mid1, ch(mid1)}) < cost({mid2, ch(mid2)})) {
            rx = mid2;
        } else {
            lx = mid1;
        }
    }
    printf("%.12Lf", cost({lx, ch(lx)}));
	return 0;
}


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

using namespace std;

typedef pair<long long , long long > P;

int main(){
    int n;
    cin >> n;
    if(n<10){
        cout << n << endl;
    }
    else if(10<=n && n<=99){
        cout << 9 << endl;
    }
    else if(100<=n && n<=999){
        cout << 9+n-99 << endl;
    }
    else if(1000<=n && n<=9999){
        cout << 909 << endl;
    }
    else if(10000<=n && n<=99999){
        cout << 909 + n-9999 << endl;
    }
    else{
        cout << 909 + 99999 - 9999 << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=1000005;
int num,head[maxn],t[maxn<<1],ne[maxn<<1],n;
bool vis[maxn];
int a[maxn],p[maxn],S[maxn],top,id,lst[maxn];
inline void addedge(int x,int y){
	ne[++num]=head[x];head[x]=num;t[num]=y;
}
inline void dfs(int x){
	forE(i,x)if(!vis[t[i]])dfs(t[i]);
	id++;
	forE(i,x)if(!vis[t[i]])lst[a[t[i]]]=id;
	a[x]=0;while(lst[a[x]]==id)a[x]++;
}
int main(){
	// judge();
	read(n);
	rep(i,1,n)head[i]=-1;
	rep(i,1,n){
		read(p[i]);
		addedge(p[i],i);
	}
	int x=1;
	while(!vis[x]){
		vis[x]=1;S[++top]=x;x=p[x];
	}int p=0;
	while(S[p]!=x)p++;
	S[top+1]=S[p];
	if((top-p+1)%2==0)return puts("POSSIBLE"),0;
	// return 0;
	memset(vis,0,sizeof(vis));
	rep(i,p,top)vis[S[i]]=1;
	rep(i,p,top)dfs(S[i]);
	rep(i,p,top)if(a[S[i]]!=a[S[i+1]])return puts("POSSIBLE"),0;
	puts("IMPOSSIBLE");
	return 0;
}


Measured memory_bytes: 22784
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int
const int MAX = 510000;


using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

vector<int> G[MAX];

bool used[MAX];

void dfs(int v, int before){
    used[v] = true;
    for(int s: G[v])if(!used[s]){
        dfs(s, v);
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin>> n >> m;
    P aa[m];
    rep(i, m){
        int a, b;
        cin >> a >> b;
        /*
        G[a].push_back(b);
        G[b].push_back(a);*/
        aa[i].first = a;
        aa[i].second = b;
    }
    int ans = 0;
    rep(i, n + 1) used[i] = false;
    int erased = 0;
    rep(j, m) {
        rep(i, m) {if(i != erased){
            int a, b;
            a = aa[i].first;
            b = aa[i].second;
            G[a].push_back(b);
            G[b].push_back(a);
        }}
        erased ++;
        rep(i, n + 1) used[i] = false;
        dfs(1, 0);
        rep(i, n + 4) G[i].clear();
        int all_connected = 0;
        for(int i = 1; i <= n; i ++){
            if(!used[i]){
                all_connected = 1;
                //cout << i << endl;
                }

        }
        if(all_connected == 1) ans ++;
    //cout << endl;
    }
    cout << ans << endl;

}

Measured memory_bytes: 12160
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
#include <numeric>
#include <cstdlib>
#include <string>
using namespace std;

void solve(long long N, std::vector<long long> W){
  vector<int> ans;
  long long s1 = 0;
  long long s2 = 0;
  long long partition = N - 2;
  
  for (int i = 0; i < N -1; i++) {
    auto iter = std::next(W.begin(), i + 1);
    s1 = std::accumulate( W.begin(), iter, 0);
    s2 = std::accumulate( iter, W.end(),  0);
    long long abs_num = s1 - s2;
    long long num = std::abs(abs_num);
    ans.push_back(num);
  }

  int a = *std::min_element(ans.begin(), ans.end());
  cout << a << endl;

}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> W(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&W[i]);
    }
    solve(N, std::move(W));
    return 0;
}


Measured memory_bytes: 256
from heapq import heappop,heappush

def main():
    inf=float("inf")
    v,e,r=map(int,input().split())

    con=tuple([] for _ in range(v))
    for i in range(e):
        s,g,w=map(int,input().split())
        con[s].append((w,g))

    weight=[inf]*v
    fixed=[0]*v
    weight[r]=0
    fixed[r]=1
    work=[]
    for x in con[r]:
        heappush(work,x)
        weight[x[1]]=x[0]

    while work:
        mn=heappop(work)
        #print(mn,weight)
        if fixed[mn[1]] : continue
        fixed[mn[1]]=1
        for x in con[mn[1]]:
            if fixed[x[1]] : continue
            if mn[0]+x[0]<weight[x[1]]:
                weight[x[1]]=mn[0]+x[0]
                heappush(work,(mn[0]+x[0],x[1]))
    
    for i in range(v):
        if weight[i]==inf : print("INF")
        else : print(weight[i])

main()


Measured memory_bytes: 91060
from itertools import product


n, m, x = map(int, input().split())

c = [0 for _ in range(n)]
a = [[] for _ in range(n)]
for i in range(n):
	inp = list(map(int, input().split()))
	c[i] = inp[0]
	a[i] = inp[1:]

ans = sum(c) + 10
for choose in product([0, 1], repeat=n):
	# print(choose)
	cost = 0
	good = True
	book = 0
	while good and book < m:
		sum_got = 0
		for buys in range(n):
			if choose[buys] == 1:
				sum_got += a[buys][book]
		# print("sum_got", sum_got)
		if sum_got < x:
			good = False
			break
		book += 1

	if good:
		for buys in range(n):
			if choose[buys] == 1:
				cost += c[buys]
		# print("cost", cost)
		if cost < ans:
			ans = cost
if ans != sum(c) + 10:
	print(ans)
else:
	print(-1)


Measured memory_bytes: 68136
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n, k;
map<int, int> m;

int main() {
    cin >> n >> k;
    rep(i, n) {
        int a; cin >> a;
        m[a]++;
    }

    vector<pair<int, int>> vp;
    for (auto kv: m) {
        vp.emplace_back(make_pair(kv.second, kv.first));
    }
    sort(vp.begin(), vp.end());

    int ans = 0;
    if (vp.size() > k) {
        for (int i = 0; i < vp.size() - k; i++) {
            ans += vp[i].first;
        }
    }
    cout << ans << endl;
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n=1,cnt=0,ans=0,a,b,c,cmp,data,m,h,x,y,xcmp=0,ycmp=0,sum=0;

char s[10][10];

vector<int> z;

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

       cin >> a >> b;
       rep(i,a){
           rep(j,b){
               cin >> s[i][j];
               if(s[i][j]=='#'){
                   cnt++;
               }
           }
       }
     if(cnt==a+b-1){
         Cout("Possible");
     }
     else{
         Cout("Impossible");
     }
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 
int main(){
    int n;
    cin >> n;
    string t, h;
    int st=0, sh=0;
    for(int i=0;i<n;i++){
        cin >> t >> h;
        if(t>h){
            st += 3;
        }else if(t<h){
            sh += 3;
        }else{
            st += 1;
            sh += 1;
        }
    }
    cout << st << " " << sh << endl;
}


Measured memory_bytes: 3208
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::iter::*;
#[allow(unused_imports)]
use std::*;

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
#[test]
        fn solve_test() {
            $(
                {
                    let mut out = Vec::<u8>::new();
                    solve($input,&mut out);
                    let out_str =str::from_utf8(&out).unwrap();
                    assert_eq!(&out_str, &$output);
                }
            )*
        }
    };
}
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
#[allow(unused_mut)]
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, isize1) => {
        read_value!($iter, isize) - 1
    };
    ($iter:expr,str) => {
        $iter.next().unwrap()
    };

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

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

#[allow(dead_code)]
fn to_yesno(yesno: bool) -> &'static str {
    if yesno {
        "Yes"
    } else {
        "No"
    }
}

fn main() {
    let mut out = std::io::stdout();

    solve(&stdin!(), &mut out);
}

#[allow(unused_mut)]
fn solve<W: std::io::Write>(src: &str, out: &mut W) {
    #[allow(unused_macros)]
    macro_rules! out {
        ($arg:expr) => {{
            let _ = out.write_fmt(format_args!("{}",$arg));
        }};
        ($fmt:expr, $($args:tt)*) => {{
            let _ = out.write_fmt(format_args!($fmt, $($args)*));
        }};
    }
    #[allow(unused_macros)]
    macro_rules! outln {
        ($arg:expr) => {{
            out!("{}\n",$arg);
        }};
        ($fmt:expr, $($args:tt)*) => {{
            out!(concat!($fmt, "\n"), $($args)*);
        }};
    }

    input! {
        source = src,
        d:usize,
        t:usize,
        s:usize,
    }
    let v = d / s;
    out!(to_yesno(v < t || (v == t && d % s == 0)));
}
test! {}


Measured memory_bytes: 2144
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); 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 all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }
using namespace std;

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

    }
    return 0;
}


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

    }
    return 0;
}

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    double ans = 0;
    reps(i, n){
       int j = 0;
       while(1){
           ll l = 1 << j;
           if(l * i >= k){
               ans += (1.0 /n ) * (1.0/ l);
               break;
           }
           j++;
       }
    }
    cout << setprecision(20) << ans << endl;
}


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

int main() {
  long long N;
  cin >> N;
  
  vector<long long>a(3*N);
  for (int i = 0; i < 3*N; i++) {
    cin >> a.at(i);
  }
  
  sort(a.begin(), a.end());
  long long A = 0;
  for (int i = N; i < 2*N; i++) {
    A += a.at(i);
  }
  long long B = 0;
  for (int i = N; i < 3*N; i += 2) {
    B += a.at(i);
  }
  
  if (A > B){
    cout << A << endl;
  }
  else {
    cout << B << endl;
  }
}

Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n,l,sum=0,m=100000;
  cin>>n>>l;
  for(int i=0;i<n;i++){
    sum += l+i;
    if(abs(m)>abs(l+i)) m=l+i;
  }
  
  cout<<sum-m<<endl;
  return 0;
}

Measured memory_bytes: 256
<?php
ini_set("memory_limit", "-1");

fscanf(STDIN, "%d", $input_count);
$cnt = 0;
for ($i = 0; $i < $input_count; ++$i) $target[] = intval(trim(fgets(STDIN)));

shell_sort($target);

echo "$cnt\n";
echo  implode("\n", $target) , "\n";

function insert_sort(&$target, $g){
    global $input_count;
    global $cnt;
    for ($i = $g; $i < $input_count; ++$i) {
        $j = $i-$g;
        $tmp = $target[$i];
        while($j >= 0 && $target[$j] > $tmp) {
            $target[$j+$g] = $target[$j];
            $j -= $g;
            ++$cnt;
        }
        $target[$j+$g] = $tmp;
    }
}

function shell_sort(&$target) {
    global $input_count;
    $G = [1, 4, 13, 40, 121, 364, 1093, 3280, 9841, 29524, 88573, 265720, 797161];
    $m = count($G);
    while ($G[$m - 1] > $input_count) --$m;
    echo $m, "\n";
    
    for ($i = $m - 1, $arr = array(); $i >= 0; --$i) $arr[] = $G[$i];
    echo implode(" ", $arr), "\n";
    
    for ($i = 0; $i < $m; ++$i) insert_sort($target, $arr[$i]);
}


Measured memory_bytes: 162032
#include <stdio.h>
#include <string.h>
int main()
{
char s[6];
	char s1[]={"Sunny"};
	char s2[]={"Cloudy"};
	char s3[]={"Rainy"};
	int l,p,d;
	gets(s);
	d=strcmp(s,s1);
	if(d==0){
		printf("%s\n",s2);}
		l=strcmp(s, s2);
		if(l==0){
			printf("%s\n",s3);}
			p=strcmp(s, s3);
		if(p==0){
			printf("%s\n",s1);
			}
			return 0;
			}

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

int main() {

    string S, T;
    cin >> S >> T;
    int count = 0;

    for (int i = 0; i < S.size(); i++) {
        if (S[i] != T[i]) {
            count++;
        }
    }

    cout << count;
}

Measured memory_bytes: 3868
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FOREACH(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define SIZE(v) ((int)(v).size())
#define zero(v) memset(v, 0, sizeof(v))
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define ll long long
#define pii pair<int, int>

const int MAX = 500100;

char s[MAX];
ll l[MAX], r[MAX];


int main() {
    scanf("%s", s);
    int len = strlen(s);

    l[0] = 0;
    r[len] = 0;
    REP(i, len) {
        l[i + 1] = s[i] == '>' ? 0 : l[i] + 1;
    }

    for(int i = len; i > 0; i--) {
        r[i - 1] = s[i - 1] == '<' ? 0 : r[i] + 1;
    }

    ll sum = 0;
    for(int i = 0; i <= len; i++) {
        sum += max(l[i], r[i]);
        //printf("%lld%c", l[i], i == len ? '\n' : ' ');
    }
    printf("%lld\n", sum);

}

Measured memory_bytes: 8576
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::HashMap;
#[allow(unused_imports)]
use std::collections::VecDeque;
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::mem::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::usize;

#[allow(unused_macros)]
macro_rules! read_cols {
    ($($t:ty),+) => {{
        let mut line = String::new();
        stdin().read_line(&mut line).unwrap();

        let mut it = line.trim()
            .split_whitespace();

        ($(
            it.next().unwrap().parse::<$t>().ok().unwrap()
        ),+)
    }}
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();
    line.trim().to_string().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();

    line.trim()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let s: String = read();

    if s.chars().last().unwrap() == 's' {
        println!("{}es", s);
    } else {
        println!("{}s", s);
    }
}


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


int main() {
    int cost = 0;
    int n,m; cin >> n >> m;
    vector<pair<long long, int>> a;
    for (int i = 0; i < n; i++){
        int x,y; cin >> x >> y;
        a.push_back(make_pair(x, y));
    }
    sort(a.begin(), a.end());
    int c = m;
    long long ret;
    for (int i = 0; i < n; i++){
        if (c <= 0) break;
        if (c >= a[i].second){
            c -= a[i].second;
            ret += a[i].first * a[i].second;
        } else if (c <= a[i].second) {
            ret += c * a[i].first;
            c = 0;
        }
        // cout << ret << endl;
        // cout << a[i].first << endl;
    }
    cout << ret << endl;
    return 0;
}


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

const int MAX = 2e5 + 111;

int n, k;

int a[MAX], b[MAX];

bool gg(int a) {
    for (int i = 0; i < 32; ++i) {
        if ((a & (1 << i)) && !(k & (1 << i)))
            return false;
    }
    return true;
}

bool good(int a, int id) {
    for (int i = 31; i > id; --i) {
        if ((a & (1 << i)) && !(k & (1 << i)))
            return false;
    }
    return !(a & (1 << id));
}

int main() {
#ifdef LOCAL
    freopen("xxx.in", "r", stdin);
    freopen("xxx.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
        if (gg(a[i]))
            ans += b[i];
    }
    for (int i = 0; i < 32; ++i) {
        if (!(k & (1 << i)))
            continue;
        ll cur = 0;
        for (int j = 0; j < n; ++j) {
            if (good(a[j], i))
                cur += b[j];
        }
        ans = max(ans, cur);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  ll n, m, k;
  cin >> n >> m >> k;
  for (ll x = 0; x <= n; ++x) {
    for (ll y = 0; y <= m; ++y) {
      if ((n-x) * y + x * (m-y) == k) {cout << "Yes" << endl; return 0;}
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
    int n, k;
    cin>>n>>k;
    string s;
    cin>>s;
    int i;
    vi front, back;
    i = 0;
    int pre = 0, pos = 0;
    int cv = 0;
    while(s[i]=='1'&&i<n)
    {
        pos++; i++;
        cv++;
    }
    while(i<n)
    {
        int cur = 0;
        pre = pos;
        pos = 0;
        while(s[i]=='0'&& i<n)
        {
            cur++;i++;
        }
        while(s[i]=='1'&& i < n)
        {
            pos++;
            i++;
        }
        front.push_back(cur+pre);
        back.push_back(cur+pos);
    }
    int si = front.size();
    if(si <= k) cout<<n;
    else 
    {
        int cur = 0;
        int ans = 0;
        FOR0(i, si)
        {
            //cout<<cv<<endl;
            if(cur==k)
            {
                cv -= front[i-k];
                cv += back[i];
                cur = k-1;
            }
            else
            {
                cv += back[i];
            }
            ans = MAX2(ans, cv);
            cur++;
        }
        cout<<ans;
    }
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 1024
#include <stdio.h>

int a,b, c,n,u,w[100][100],color[100],d[100];

int main(){
  int i,j,mincost,sum=0;
  scanf("%d",&n);
 for(i=0;i<n;i++)
   for(j=0;j<n;j++)w[i][j]=100008;

  for(i=0;i<n;i++){
    scanf("%d%d",&a,&c);
      for(j=0;j<c;j++){
scanf("%d",&b);
 scanf("%d",&w[a][b]);    
}
    }
 
  for(i=0;i<n;i++){
    d[i] =100008;
    color[i] =0;
  }
  d[0]=0;

  while (1){
    mincost=100008;    
for(i=0;i<n;i++){
      if (color[i] != 1 && d[i] < mincost){
	mincost = d[i];
	u = i;
      }
    }
    if (mincost ==100008)
      break;
    color[u] = 1;
    for (i=0;i<n;i++){
      if (color[i] != 1 && d[u]+w[u][i] < d[i]){
	d[i] = d[u]+w[u][i];
      }
    }
  }
 
 for (i=0;i<n;i++)
 printf("%d %d\n",i,d[i]); 

  return 0;
}

Measured memory_bytes: 640
using System;
class Program
{
 static void Main(string[] args)
 {
  string[] s = Console.ReadLine().Split(' ');
  int D = int.Parse(s[0]), N = int.Parse(s[1]); N = N == 100 ? 101 : N;
  Console.WriteLine((N * Math.Pow(100, D)).ToString());
 }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;

int main() {
	int N;
	cin >> N;
	string S1, S2;
	cin >> S1 >> S2;
	vector<ll> A(N);
	vector<bool> st(N, true); //縦置きがtrue
	int i = 0;
	while (i < N) {
		if (S1[i] == S2[i]) {
			if (i) {
				if (st[i - 1])
					A[i] = A[i - 1] * 2;
				else
					A[i] = A[i - 1];
			}
			else
				A[i] = 3;
			A[i] %= MOD;
			i++;
		}
		else {
			if (i) {
				if (st[i - 1])
					A[i] = A[i - 1] * 2;
				else
					A[i] = A[i - 1] * 3;
			}
			else
				A[i] = 6; //Debug #1
			A[i] %= MOD;
			A[i + 1] = A[i];
			st[i + 1] = false;
			i += 2;
		}
	}
	cout << A[N - 1] << endl;
}

Measured memory_bytes: 256
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,m,s = map(int,ipt().split())
    mac = 2500
    way = [[] for i in range(n+1)] #place,money,time
    for _ in range(m):
        u,v,a,b = map(int,ipt().split())
        way[u].append((v,a,b))
        way[v].append((u,a,b))
    for i in range(1,n+1):
        c,d = map(int,ipt().split())
        way[i].append((i,-c,d))
    ct = [[10**18]*2501 for i in range(n+1)]
    ct[1][min(s,mac)] = 0 #place,money//mintime
    hq = [(0,1,min(s,mac))] #time,place,money
    while hq:
        ti,pl,mo = hpq.heappop(hq)
        for dp,dm,dt in way[pl]:
            if mo >= dm and ct[dp][min(mo-dm,mac)] > ti+dt:
                 ct[dp][min(mo-dm,mac)] = ti+dt
                 hpq.heappush(hq,(ti+dt,dp,min(mo-dm,mac)))
    ans = [min(i) for i in ct[2::]]
    for i in ans:
        print(i)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 90908
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S,T;
  cin >> S>>T;
  int a=0;
  a = T.size();
  if(S==T.erase(a-1)) {
    cout << "Yes"<<endl;
  }
  else{
    cout << "No"<<endl;
  }

}


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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
ll calc(ll h){
	if(h==1)
		return 1;
	h=h/2;
	//cout<<h<<endl;
	return 2*calc(h)+1;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
#endif
	ll h;
	cin>>h;
	ll ans=calc(h);
	//ans=ans+h;
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)
def search(prev, start, stop):
    global nodes, edges
    for neigh in nodes[start]:
        if neigh==prev:
            continue
        if neigh==stop:
            return [stop,start]
        res=search(start,neigh,stop)
        if res!=False:
            res.append(start)
            return res
    return False

def size(prev, curr):
    su=1
    global nodes, edges
    for neigh in nodes[curr]:
        if neigh==prev:
            continue
        su+=size(curr,neigh)
    return su

n=int(input())
nodes=[[] for i in range (n)]
edges=[]
for i in range(n-1):
    line=input().split()
    a=int(line[0])-1
    b=int(line[1])-1
    edges.append([a,b])
    nodes[b].append(a)
    nodes[a].append(b)

res=search(-1,n-1,0)

fennec=(len(res)-1)//2
snuke=fennec+1
snuke=res[snuke]
fennec=res[fennec]
fennecsize=size(snuke,fennec)
snukesize=size(fennec,snuke)

if fennecsize>snukesize:
    print ("Fennec")
else:
    print("Snuke")


Measured memory_bytes: 119764