akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main() {
    int a, b;
    string str;
    while (true) {
        cin >> a >> str >> b;
        if (str == "?") {
            break;
        }
        if (str == "+") {
            cout << a + b << endl;
        } else if (str == "-") {
            cout << a - b << endl;
        } else if (str == "*") {
            cout << a * b << endl;
        } else {
            cout << a / b << endl;
        }

    }

    return 0;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    long double a,b,c;
    cin>>a>>b>>c;
    if(a+sqrt(a*b)*2.0+b>=c){
    	cout << "No" <<endl;
    }else{
    	cout << "Yes"  <<endl;
    }
    
    return 0;
}


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

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

  vector<ll> b(a);
  sort(a.begin(), a.end(), greater<>());
  for (ll i = 0; i < n; i++) {
    if (b[i] == a[0]) {
      cout << a[1] << endl;
    } else {
      cout << a[0] << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include<algorithm>
#include<map>

using namespace std;
 
int main(void){
	
	int count_x=0, count_o=0;
	string S;
	
	cin >> S;
	
	for(int i=0; i<S.length(); i++){
		if(S[i] == 'x'){
			count_x++;
		}else if(S[i] == 'o'){
			count_o++;
		}
	}
	
	if(15-S.length() >= 8-count_o){
		cout << "YES";
	}else{
		cout << "NO";
	}
	
	//cout << S.length();
	
	return 0;
}

Measured memory_bytes: 256
INT_MAX=10**18+7
MOD=10**9+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
#################################################################################
n=int(input())
A=INPUT()
ans=[0 for i in range(n+1)]
for i in range(n-1):
    #print(i)
    ans[A[i]]+=1
for i in range(1,n+1):
    print(ans[i])


Measured memory_bytes: 97552
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

vector<bool> sieve(int x) { // range...[0,x]
    vector<bool> flags(x + 1, true);
    flags[0] = false, flags[1] = false;
    for(int i = 2; i * i <= x; i++) {
        if(!flags[i])
            continue;
        for(int mult = i * i; mult < x; mult += i)
            flags[mult] = false;
    }
    return flags;
}

int main() {
    int X;
    cin >> X;
    vector<bool> flag = sieve(200000);
    flag[2] = true;
    int i = X;
    while(1) {
        if(flag[i]) {
            cout << i << endl;
            return 0;
        }
        i++;
    }
    return 0;
}

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

int main(void)
{
    int N,x,cnt = 0;
    cin >> N >> x;
    vector<int> a(N);

    rep(i, N){
        cin >> a[i];
    }

    sort(a.begin(),a.end());

    rep(i,N){

        if(x >= a[i]){
            x -= a[i];
            cnt++;
        }
    }

    if(x > 0 && cnt == N)
        cnt--;

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
#include <numeric>
#include <cstdint>

using llint = long long int;
using u64 = std::uint_fast64_t;

void solve(void){

  llint n, d;
  std::cin >> n >> d;

  int ret = 0;
  for(int i=0; i<n; i++){
    llint x, y;
    std::cin >> x >> y;
    if(d*d >= x*x + y*y) ret++;
  }
  std::cout << ret << std::endl;
}
int main(void){
  solve();
  return 0;
}





Measured memory_bytes: 3632
/*D*/
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans;

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

	ll N;
	cin >> N;

	vector<ll> A(N);
	rep(i, N) {
		cin >> A[i];
	}

	sort(A.begin(), A.end(),greater<ll>());


	ans = A[0];
	ll index = N / 2;
	repk(i, 1, index) {
		ans += A[i] * 2;
	}
	if (N % 2 != 0) {
		ans += A[N  / 2];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4776
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
if n >= m:
    print(0)
    exit()

cost = []
for i in range(m-1):
    cost.append(x[i+1] - x[i])

cost.sort()
ans = 0
for i in range(m-n):
    ans += cost[i]
print(ans)

Measured memory_bytes: 56872
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

template<typename T> //最大公約数
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T> //最小公倍数
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_MAX; i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}

long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}


// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

struct Coordinate {
    int y, x;
};

int main(){
    int N, K, R, S, P; cin >> N >> K >> R >> S >> P;
    string T; cin >> T;
    map<char, int> mp;
    mp['r'] = P; mp['s'] = R; mp['p'] = S;
    int ans = 0;
    for (int i = 0; i < N; i++){
        if (i < K){
            ans += mp[T[i]];
        } else {
            if (T[i] == T[i-K]){
                T[i] = 'x';
            } else {
                ans += mp[T[i]];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
let () =
  let open Hashtbl in
  let n = read_int () in
  let tbl = create ~random:true n in
  let rec doit i =
    if i >= n then ()
    else begin
      match Scanf.scanf "%s %s\n" (fun x y -> (x, y)) with
      | ("insert", x) -> (add tbl x true; doit (i + 1))
      | ("find", x) -> (print_endline (if mem tbl x then "yes" else "no"); doit (i + 1))
      | _ -> exit 1
    end
  in
  doit 0

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

using namespace std;

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

typedef long long ll;
typedef unsigned long long ull;

int main() {
    ll L, R;
    cin >> L >> R;
    ll num;
    ll subLR = R - L;
    subLR = min(subLR, (ll)2019);
    L %= 2019;
    R %= 2019;
    ll xmin = L * R;
    REP(i, L, L + subLR) {
        REP(j, i + 1, L + subLR + 1) {
            num = i * j;
            num %= 2019;
            xmin = min(num, xmin);
        }
    }
    cout << xmin % 2019 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
#define printll(a) printf("%lld\n", a)
#define printYes() printf("Yes\n")
#define printNo() printf("No\n")
#define scanll(a) scanf("%lld", &a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scan4Int(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
typedef long long ll;
using namespace std;

int main() {
    int n;
    scanInt(n);
    int a[n];
    rep(i, n) {
        cin >> a[i];
    }
    rep(i, n) {
        if (!(a[i] % 2) && a[i] % 3 && a[i] % 5) {
            printf("DENIED\n");
            return 0;
        }
    }
    printf("APPROVED\n");
    return 0;
}


Measured memory_bytes: 3676
#include <iostream>

using namespace std;

int main()
{

   char a;
   cin>>a;
   if(a=='A')
    cout<<'T';
   if(a=='T')
    cout<<'A';
   if(a=='C')
    cout<<'G';
   if(a=='G')
    cout<<'C';
       return 0;
}


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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define RREP(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))
#define endl '\n'

#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pb push_back
#define mp make_pair
#define Pi 3.14159265358979
#define A first
#define B second

typedef long long ll;
typedef vector <int> vi;
typedef vector<ll> vl;
typedef pair <int, int> pi;
typedef pair <ll, int> pl;
typedef pair <ll, ll> pll;
typedef pair <double, double> pd;

//change these according to prob constraints
const int INF = 0x3f3f3f3f;
const int MAX = 100005;
const int MAX1 = 1005;
const int MAX2 = 105;
const int LEN = 105;
const int BASE = 1000000000;
const double EPS = 1e-7;
const int MOD = 1000000007;
//g++ -std=c++11 your_file.cpp -o your_program

ll mypow(ll a, ll b){
	ll ans=1;
	while(b){
		if(b&1)
			ans=(ans*a)%MOD;
		b/=2;
		a=(a*a)%MOD;
	}
	return ans;
}

int main(void){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ifstream in("");
	ofstream out("");
	clock_t begin = clock();
	int n;
	cin >> n;
	int arr[MAX];
	REP(i, n){
		cin >> arr[i];
	}
	arr[0]--;
	FOR(i, 1, n - 1){
		if (arr[i - 1] == arr[i]) continue;
		else if (arr[i - 1] < arr[i] && (arr[i + 1] >= arr[i] or arr[i + 1] == arr[i] - 1)) arr[i]--;
		else {
			cout << "No" << endl;
			return 0;
		}
	}
	REP(i, n - 1){
		if (arr[i] > arr[i + 1]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	clock_t end = clock();
    double esecs = double(end - begin) / CLOCKS_PER_SEC;
    //cout << esecs << " seconds" << endl;
	return 0;	
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int main()
{
	int A, B;
	in >> A >> B;

	std::vector<std::vector<char>>ans(100, std::vector<char>(100));
	rep(i, 100) rep(j, 100) ans[i][j] = (i < 50 ? '#' : '.');
	--A; --B;
	for (int i = 1; i < 50; i += 2)
	{
		bool flag = true;
		for (int j = 1; j < 100; j += 2)
		{
			if (A == 0)
			{
				flag = false;
				break;
			}
			ans[i][j] = '.';
			--A;
		}
		if (!flag) break;
	}
	for (int i = 51; i < 100; i += 2)
	{
		bool flag = true;
		for (int j = 1; j < 100; j += 2)
		{
			if (B == 0)
			{
				flag = false;
				break;
			}
			ans[i][j] = '#';
			--B;
		}
		if (!flag) break;
	}

	out << 100 << " " << 100 << std::endl;
	rep(i, 100)
	{
		rep(j, 100) out << ans[i][j];
		out << std::endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

char S[3][102];
int idx[3];

int main(void)
{
	int i;

	for (i = 0; i < 3; ++i)
	{
		scanf("%s", S[i]);
	}

	i = 0;
	while (S[i][idx[i]])
	{
		i = S[i][idx[i]++] - 'a';
	}
	printf("%c\n", i + 'A');

	return 0;
}

Measured memory_bytes: 128
from fractions import gcd
n = int(input())
aaa = list(map(int, input().split()))
p = aaa[0]
f = [p]
for a in aaa[1:-1]:
    p = gcd(p, a)
    f.append(p)
aaa.reverse()
p = aaa[0]
b = [p]
for a in aaa[1:-1]:
    p = gcd(p, a)
    b.append(p)
b.reverse()

f = [b[0]] + f
b = b + [f[-1]]

print(max(gcd(p, q) for p, q in zip(f, b)))

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define forn(low,high,i) for(i = low;i < high;i++)
#define forrev(high,low,i) for(i = high; i >= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define line cout << __LINE__;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define decimal_digits cout << fixed << setprecision(15);
#define dbg2(a,b) cerr << #a << " = " << a << " " << #b << " = " << b << '\n';        
#define debug(x) cerr << __LINE__ << ' ' << #x << " = " << x << '\n';
#define dln cerr << '\n';
#define dsp cerr << ' ';
#define pln cout << '\n';
#define psp cout << ' ';

typedef unordered_map<int,int> umi;
typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int inf = 1e9;
const ll INF = 1e18;
const ll mod = 1e9 + 7;

clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

int main(){
  fastio
  ll n,i,j,k;
  cin >> n;
  vl a(n);
  forn(0,n,i){
    cin >> a[i];
  }
  multiset<int> last; 

  forn(0,n,i){ 

      auto it = last.lower_bound(a[i]); 

      if (it == last.begin()) 

          last.insert(a[i]); 

      else { 
          it--; 

          last.erase(it); 
          last.insert(a[i]);
      } 
  } 
  cout << (ll)last.size() << '\n';
  ktj();
}


Measured memory_bytes: 5760
n = int(input())
A = list(map(int,input().split()))
k = 0
m = 1000
flag = 0
for i in range(1,n):
    if flag:
        if A[i]>=A[i-1]:
            continue
        else:
            m += k*A[i-1]
            k = 0
            flag = 0
    else:
        if A[i]<=A[i-1]:
            continue
        else:
            k,m = divmod(m,A[i-1])
            flag = 1
if flag:
    m += A[-1]*k
print(m)

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

int X,Y, derived;
int main(){
  cin >> X >> Y;
  derived = Y - 2*X;
  if (derived == 0){
    cout << "Yes";
  }
  else if (derived - 2 >= 0 && derived % 2 == 0 && derived <= X*2){
    cout << "Yes";
  }
  else {
    cout << "No";
  }
  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
//関数
const long INF=1000000000000000;

int main(void){
    long H,W;
    cin>>H>>W;
    
    vector<vector<char>> a(H,vector<char>(W));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>a.at(i).at(j);
        }
    }
    
    vector<bool> remh(H,true),remw(W,true);
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(a.at(i).at(j)=='#'){
                remh.at(i)=false;
                remw.at(j)=false;
            }
        }
    }
    
    for(int i=0;i<H;i++){
        if(remh.at(i)) continue;
        for(int j=0;j<W;j++){
            if(!remw.at(j)) cout<<a.at(i).at(j);
        }
        cout<<endl;
    }
    
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using namespace std;

int main(){
  int n;cin>>n;
  int a[n],x[n][n],y[n][n];
  rep(i,n){
    cin>>a[i];
    rep(j,a[i])cin>>x[i][j]>>y[i][j];
  }
  int mx=0;
  for(int tmp=0;tmp<(1<<16);tmp++){
    bitset<15> s(tmp);
    int sum=0;
    bool hon = true;    
    rep(i,n){
      if(s.test(i)){
        sum++;
        rep(j,a[i]){
          if(s.test(x[i][j]-1)!=y[i][j]){
            hon=false;
            break;
          }//if
        }//rep

      }//if
    }//rep
    if(hon){mx=max(mx,sum);}
  }//for
  cout<<mx;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
typedef long long LL;
using namespace std;
const int N=4003;
const int mod=998244353;
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
#ifdef ztzshiwo
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
}
int n,ans,f[N];
bitset<N>X,G,C;
inline void Add(int &x,int y){x=x+y<mod?x+y:x+y-mod;}
inline int deg(bitset<N>&x)
{
	rFor(i,4000,0)if(x[i])return i;
	return -1;
}
inline void gcd()
{
	while(1)
	{
		int x=deg(G),y=deg(C);
		if(x==-1)swap(C,G),swap(x,y);
		if(y==-1)break;
		if(x<y)swap(C,G),swap(x,y);
		rFor(i,x,y)if(G[i])G^=C<<(i-y);
	}
}
int main()
{
	file();
	read(n);cin>>X;
	cin>>G;
	For(i,2,n)cin>>C,gcd();
	C.reset();
	int D=deg(X),d=deg(G);
	f[0]=1;For(i,1,D)Add(f[i]=f[i-1],f[i-1]);
	rFor(i,D,d)
	{
		if(X[i])Add(ans,f[i-d]);
		if(X[i]^C[i])C^=G<<(i-d);
	}
	Add(ans,1);
	rFor(i,4000,0)
	{
		if(X[i]>C[i])break;
		if(X[i]<C[i]){Add(ans,mod-1);break;}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
// #pragma GCC optimize "trapv" Uncomment when dealing with huge numbers
/*<----------PBDS---------->

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
template <typename T>
using order_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

order_set<datatype>oset;
Kth smallest : *oset.find_by_order(k-1); // 0 based index
No of elements less than k : oset.order_of_key(k);
Erase X : oset.erase(x)
<----------PBDS---------->*/
#include<iostream>
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define pb(x) push_back(x)
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define lcm(a,b) (a*b)/gcd(a,b)
#define bits(x) __builtin_popcountll(x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main()
{
    fast;
    int n,k;
    cin >> n >> k;
    int h[n+1];
	int dp[n+1];
    for(int i = 1; i<=n ; i++ ){
    	cin >> h[i];
    	dp[i] = INT_MAX;
	}
	
	dp[0] = 0;
	dp[1] = 0;
	for(int i = 2 ; i<=n ; i++ ){
		int pos = max(1LL,i-k);
		for(int j = i-1 ; j>=pos; j-- ){
			dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]));
		}
	}
	cout << dp[n];
}





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

int n,m;
int pos[100100];
int ball[100100];

main()
{
	scanf("%d %d",&n,&m);
	pos[1]=1;
	for(int i=1;i<=n;i++)
		ball[i]=1;
	for(int i=0;i<m;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		if(pos[a]==1)
		{
			pos[b]=1;
			ball[a]--;
			ball[b]++;
			if(ball[a]==0)
				pos[a]=0;
		}
		else
		{
			ball[a]--;
			ball[b]++;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(pos[i]==1)
			ans++;
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define setbits(x)  __builtin_popcount(x)
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;

//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
/*int find(int a){
     if(a==par[a])return a;
     return par[a]=find(par[a]);
}
void unite(int a,int b){
     a=find(a),b=find(b);
     if(a==b)return ;
     par[b]=a;
}
ll modexpo(ll a,ll b)
{
     ll ans=1LL;
     while(b>0)
     {
          if(b&1)ans=(ans*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return ans;
}
*/
int main(){
     int n;
     cin>>n;
     vector<string> vec(n);
     for(int i=0;i<n;i++){
          cin>>vec[i];
     }
     ll res=0;
     for(int k=0;k<n;k++){
          int a=0,b=k;
          char tmp[n][n];
          for(int i=0;i<n;i++){
               for(int j=0;j<n;j++){
                    tmp[i][j]=vec[(i+a)%n][(j+b)%n];
               }
          }
          int f=1;
          for(int i=0;i<n;i++){
               for(int j=i;j<n;j++){
                    if(tmp[i][j]!=tmp[j][i]){
                         f=0;
                    }
               }
          }
          if(f)res++;

     }
     cout<<res*n;
}
 
 
 
 

























Measured memory_bytes: 3800
import numpy as np
N, K = map(int, input().split())

p_list = np.array(list(map(int, input().split())))

ev_list =  np.array((p_list+1)/2)

max_num = sum(ev_list[0:K])
tmp = sum(ev_list[0:K])

for i in range(N-K):
    tmp = tmp - ev_list[i] + ev_list[i+K]
    if tmp > max_num:
        max_num = tmp

print(max_num)


Measured memory_bytes: 33964
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<cmath>

using namespace std;
void print(vector<int> a);
long long int gcd(long long int x,long long int y);
int isprime(long long int n);

int main(){
    int n,c = 0;
    cin >> n;
    for (int i=0;i<n;i++){
        long long int a;
        cin >> a;
        c += isprime(a);
    }
    cout << c << endl;


    return 0;
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}



long long int gcd(long long int x, long long int y){
    if (x < y) swap(x,y);
    while (y > 0){
        long long int r = x % y;
        x = y;
        y = r;
    }
    return x;
}

int isprime(long long int n){
    if (n == 2) return 1;
    for (int i=2;i < sqrt(n)+1;i++){
        if (n % i == 0) return 0;
    }
    return 1;
}

//Sum accumulate(v.begin(),v.end(),0);
//Sort sort(v.begin(),v.end())
//Power pow(base, e)
//Min min = *std::min_element(vec.begin(), vec.end());
//Max max = *std::max_element(vec.begin(), vec.end());



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

int main() {
	string s;cin>>s;
  	int cnt=0;
  	if(s[0]=='o') cnt++;
  	if(s[1]=='o') cnt++;
  	if(s[2]=='o') cnt++;
  	cout<<700+cnt*100<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;


int main() {
  string s;cin >> s;
  int N = s.length();
  debug((N-1)/2);
  int cnt=0;
  for(int i=(N-1)/2;i>=0;i--){
    if(s[i] !=s [(N-1)/2] || s[N-1-i] != s[(N-1)/2]){
      break;
    }
    cnt++;
  }
  debug(cnt);
  int ans = N-((N+1)/2-cnt);
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
    return arg1.first > arg2.first;
}

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

    vector<vector<int>> f(n, vector<int>(10));
    vector<vector<int>> p(n, vector<int>(11));
    // cout << f.at(0).size() << f.size() << endl;
    // cout << p.at(0).size() << p.size() << endl;
    for(int i=0;i<n;i++) {
        for(int j=0;j<10;j++) {
            cin >> f.at(i).at(j);
        }
    }
    for(int i=0;i<n;i++) {
        for(int j=0;j<11;j++) {
            cin >> p.at(i).at(j);
        }
    }

    //vector<int> nowf(10);
    int count, ans_tmp, ans = -2147483648, memo;
    for(int i=1;i<(1<<10);i++) {
        // for(int j=0;j<10;j++) {
        //     nowf.at(j)=(i>>j)&1;
        // }

        ans_tmp = 0;
        for(int j=0;j<n;j++) {
            count = 0;
            for(int k=0;k<10;k++) {
                if(((i>>k)&1) && f.at(j).at(k)) count++;
            }
            ans_tmp += p.at(j).at(count);
        }
        ans = max(ans, ans_tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] argv) {
		int n;
		Scanner in = new Scanner(System.in);
		n = in.nextInt();
		int[] heap = new int[n];
		for(int i = 0; i < n; i ++) {
			heap[i] = in.nextInt();
		}
		in.close();
		
		int pos = 1;
		for(int i = 0; i < n; i++) {
			System.out.print("node " + (i + 1) + ": key = " + heap[i] + ", ");
			if(i != 0) {
				System.out.print("parent key = " + heap[(int) Math.floor((i-1)/2)] + ", ");
			}
			if(pos < n) {
				System.out.print("left key = " + heap[pos] + ", ");
			}
			if(pos + 1 < n) {
				System.out.print("right key = " + heap[pos + 1] + ", ");
			}
			System.out.println();
			pos += 2;
		}
	}	
}


Measured memory_bytes: 26992
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;

int main(){
  ll n, m; cin >> n >> m;
  ll ans = 0;
  if(n*2 > m){
    ans = m/2;
  } else { //n < m/2 のとき
    m -= 2*n;
    m /= 4;
    ans = n + m;
  }

  cout << ans << endl;
  return 0;
}


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

int main()
{
	ios_base::sync_with_stdio(0);	cin.tie(0);	cout.tie(0);
	int i=0, n;
	while(i<5){
		cin>>n; if(n==0){
			cout<<i+1<<"\n";
			break;
		}
		i+=1;
	}
	return 0;
}

Measured memory_bytes: 3160
#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;
void calculate(double a,double b,double c,double d)
{
    double result=sqrt((a-c)*(a-c)+(b-d)*(b-d));
   printf("%.8lf",result);
}
int main()
{
    double x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    calculate(x1,y1,x2,y2);
}



Measured memory_bytes: 3208
package main

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

/*　入力方法
１、簡単に書く
fmt.Scan
2,たくさん読む()
bufio.Scanner
(テキストを1行ずつ読み込む。fileからscannerを生成し、scan()が末尾に達してfalseを返すまで読み込む。Text()を呼ぶことで文字列として取り出すことができる)
3,長い行を読む
bufio.ReadLine
4, スペース区切りのデータを読み込む
sc.Split(bufio.ScanWords)
#########バッファの最大読み込みの数を変更するには
sc.Buffer(buf,MaxBuf)#MAXBUFのところにサイズをしていする
*/

/* 書き込み
１、接頭辞F（前）
書き込み先を指定できる
2,接頭辞S(前)
出力ではなくフォーマットした結果を文字列で返す
3,接頭辞 f（後ろ）
フォーマット（文字列型など）を指定することができる
４、接頭辞 ln（後ろ）
オペランドの間に半角スペースが入り、文字列の最後に開業が追加

・interface{}型
どのような型がくるかわからないときに演算はできないが全ての型を受ける
new(T)
任意の型

*/
/*
フォーマット文字列
%c 1文字を出力　　　%d　　整数を10進む
%s 文字列を出力

指定子	対応する型	説明	使用例
%c	char	１文字を出力する
%s	char *	文字列を出力する
%d	int, short	整数を10進で出力する
%u	unsigned int, unsigned short	符号なし整数を10進で出力する
%o	int, short,unsigned int, unsigned short	整数を8進で出力する
%x	int, short,unsigned int, unsigned short	整数を16進で出力する
%f	float	実数を出力する
%e	float	実数を指数表示で出力する
%g	float	実数を最適な形式で出力する
%ld	long	倍精度整数を10進で出力する
%lu	unsigned long	符号なし倍精度整数を10進で出力する
%lo	long, unsigned long	倍精度整数を8進で出力する
%lx	long, unsigned long	倍精度整数を16進で出力する
%lf	double	倍精度実数を出力する
*/
/*
strconvパッケージ→　文字列と基本データ型の双方向変換を実装
func Atob(str string)(value bool,err os.Error)
文字列で表されている論理値を返す。それ以外のときはエラー

func Atof(s string)(f float,err os.Error)
floatのサイズによってAtof32またはAtof64を呼ぶ

func Atoi(s string(i int,error os.Error))

strconv.ParseInt(文字列、１０（１０進数）,64(ビット))
戻り値がint型を返す

*/
/*
配列の作り方
m=make(map[string]interface{})

*/
const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

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

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

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

/*strings.Splitで入力したものを分ける*/
func Scanner() []string {
	var s string
	if sc.Scan() {
		s = sc.Text()
	}
	slice := strings.Split(s, " ")
	return slice

}

/* ---------------IO-------------------*/
func next() string {
	sc.Scan()
	return sc.Text()

}

/*型変換*/
func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		/*panic関数　　強制的にエラーを発生させるもの*/
		panic(err)
	}
	return i

}

/* 整数型に型変換したものを配列に格納する*/
func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

var fp *os.File

/*"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""*/
func main() {
	var a, b, c int64
	var in = strings.Split(next(), " ")
	a, _ = strconv.ParseInt(in[0], 10, 64)
	b, _ = strconv.ParseInt(in[1], 10, 64)
	c, _ = strconv.ParseInt(in[2], 10, 64)

	if a == (b+c) || b == (a+c) || c == (a+b) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
	defer fp.Close()
}


Measured memory_bytes: 1776
n, l = map(int,input().split())
#ai = [[int(input()),i] for i in range(n)]
ai = [[] for _ in range(l)]
for i in range(n):
    ai[int(input())].append(i)
time = [0]*(n+2)

for i in range(l-1,0,-1):
    for j in ai[i]:
        time[j+1] = max(time[j],time[j+2]) + l - i

print(max(time))

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

using namespace std;

map<pair<int, int>, int> memo;
vector<int> G[32];
int hy[32], hx[32];
int ey, ex;
int cnt;

int sgn(int x)
{
    return (x ? (x < 0 ? -1 : 1) : 0);
}

int mp[32][32];
int getWay(int pos, int bit)
{
    if (bit == (1 << cnt) - 1){
        return (hy[pos] == ey || hx[pos] == ex);
    }
    
    if (__builtin_popcount(bit) <= 18 && memo.count(make_pair(pos, bit))){
        return (memo[make_pair(pos, bit)]);
    }
    
    int res = 0;
    
    for (int i = 0; i < G[pos].size(); i++){
        int e = G[pos][i];
        if (bit >> e & 1) continue;
        int sy = hy[pos], sx = hx[pos];
        bool ok = true;
        for (; sy != hy[e] || sx != hx[e]; sy += sgn(hy[e] - sy), sx += sgn(hx[e] - sx)){
            if (mp[sy][sx] == 1){
                ok = false; break;
            }
        }
        if (ok){
            mp[hy[e]][hx[e]] = 0;
            res += getWay(G[pos][i], bit | (1 << G[pos][i]));
            mp[hy[e]][hx[e]] = 1;
        }
    }
    
    if (__builtin_popcount(bit) <= 18){
        memo[make_pair(pos, bit)] = res;
    }
    return (res);
}

int dy[] = {1, 0, -1, 0}, dx[] = {0, 1, 0, -1};
bool valid(int p)
{
    for (int d = 0; d < 4; d++){
        int sy = hy[p], sx = hx[p];
        while (0 <= sy + dy[d] && 0 <= sx + dx[d] && sy + dy[d] <= 10 && sx + dx[d] <= 10){
            sy += dy[d]; sx += dx[d];
            if (mp[sy][sx] == 1) break;
            if (mp[sy][sx] == 2) return (true);
        }
    }
    return (false);
}

int main()
{
    int w, h;
    
    while (scanf("%d %d", &w, &h) && w){
        
        for (int i = 0; i < 32; i++) G[i].clear();
        memset(mp, 0, sizeof(mp));
        cnt = 0;
        memo.clear();
        
        for (int i = 0; i < h; i++){
            for (int j = 0; j < w; j++){
                scanf("%d", &mp[i][j]);
                if (mp[i][j] == 1){
                    hy[cnt] = i;
                    hx[cnt++] = j;
                }
                else if (mp[i][j] == 2){
                    ey = i;
                    ex = j;
                }
            }
        }
        
        for (int i = 0; i < cnt; i++){
            for (int j = i + 1; j < cnt; j++){
                if (hy[i] == hy[j] || hx[i] == hx[j]){
                    G[i].push_back(j);
                    G[j].push_back(i);
                }
            }
        }
        
        int ans = 0;
        
        for (int i = 0; i < cnt; i++){
            if (valid(i)){
                mp[hy[i]][hx[i]] = 0;
                ans += getWay(i, 1 << i);
                mp[hy[i]][hx[i]] = 1;
            }
        }
        
        printf("%d\n", ans);
    }
    
    return (0);
}

Measured memory_bytes: 65224
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

s = input().rstrip()
t = input().rstrip()
ns = len(s)
nt = len(t)

ans = 10**5 
for i in range(ns - nt + 1):
    ret = 0
    for cs, ct in zip(s[i:i+nt], t):
        if cs != ct:
            ret += 1
    ans = min(ans, ret)
print(ans)

Measured memory_bytes: 67772
using System;

class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split();
        long W = long.Parse(input[0]);
        long a = long.Parse(input[1]);
        long b = long.Parse(input[2]);

        long High = Math.Max(a, b);
        long Low = Math.Min(a, b);

        long ans;

        if (Low + W < High) ans = High - (Low + W);
        else ans = 0;

        Console.WriteLine(ans);

    }
}

Measured memory_bytes: 13140
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int zeroCnt = 0;
        int oneCnt = 0;
        int min = 0;
        for(int i = 0;i <S.length();i++){
            if(S.charAt(i) == '0'){
                zeroCnt++;
            }
        }
        oneCnt = S.length()-zeroCnt;
        min = Math.min(zeroCnt,oneCnt);
        System.out.println(min*2);
    }
}


Measured memory_bytes: 23792
X, K, D = map(int, input().split())
X = abs(X)


if X == 0:
    if K % 2 == 0:
        print(0)

    else:
        print(D)

else:
    if X - D*K <= 0:
        if (K - (X // D)) % 2 == 0:
            print(abs(X%D))
        else:
            print(abs(X%D-D))

    elif X - D * K > 0:
        print(abs(X - D * K))

Measured memory_bytes: 61500
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(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 llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;

#define ARRAY_MAX 101

int dp[30];

int main(){

    int n;
    
    REP(i,30){
        dp[i] = 0;
    }
    dp[0] = 1;
    dp[1] = 1;
    dp[2] = 2;
    for(int i = 3;i <= 30;i++){
        dp[i] = dp[i-1] + dp[i-2] + dp[i-3];
    }

    while(cin >> n,n){
        cout << (dp[n]-1)/3650+1 << endl;
    }

    return 0;
}


Measured memory_bytes: 3020
N, Y = map(int, input().split())
man = -1
gosen = -1
sen = -1
for i in range(0, N+1):
    for j in range(0, N+1-i):
        k = N-i-j
        total = 10000*i+5000*j+1000*k
        if total==Y:
            man = i
            gosen = j
            sen = k
print(man, gosen, sen)

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {

	private class Node<T> {
		T value;
		Node<T> left;
		Node<T> right;
		int pos;
		public Node(T value) {
			this.value = value;
			left = right = null;
			pos = -1;
		}
		public String toString() {
			return value.toString();
		}
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		int[] pre = new int[n];
		int[] in = new int[n];
		StringTokenizer st1 = new StringTokenizer(reader.readLine());
		StringTokenizer st2 = new StringTokenizer(reader.readLine());
		int rootId = 0;
		for (int i = 0; i < n; i++) {
			pre[i] = Integer.parseInt(st1.nextToken());
			in[i] = Integer.parseInt(st2.nextToken());
			if (i == 0) {
				rootId = pre[i];
			}
		}
		reader.close();
		
		Node<Integer> rootNode = new Node<Integer>(rootId);
		for (int i = 1; i < n; i++) {
			Node<Integer> current = new Node<Integer>(pre[i]);
			addNode(rootNode, current, in);
		}
		System.out.println(postOrder(rootNode));
	}

	private String postOrder(Node<Integer> rootNode) {
		StringBuilder sb = new StringBuilder();
		Stack<Node<Integer>> stack = new Stack<Node<Integer>>();
		Node<Integer> current = rootNode;
		Node<Integer> lastVisited = null;
		while (current != null || !stack.isEmpty()) {
			if (current != null) {
				stack.push(current);
				current = current.left;
			} else {
				Node<Integer> peekNode = stack.peek();
				if (peekNode.right != null && peekNode.right != lastVisited) {
					current = peekNode.right;
				} else {
					if (sb.length() != 0) {
						sb.append(" ");
					}
					sb.append(peekNode);
					lastVisited = stack.pop();
				}
			}			
		}
		return sb.toString();
	}

	private void addNode(Node<Integer> rootNode, Node<Integer> newNode, int[] in) {
		newNode.pos = findPos(in, newNode.value);
		Stack<Node<Integer>> stack = new Stack<Node<Integer>>();
		stack.push(rootNode);
		while (!stack.isEmpty()) {			
			Node<Integer> current = stack.pop();
			if (current.pos == -1) {
				current.pos = findPos(in, current.value);
			}
			if (newNode.pos < current.pos) {
				if (current.left == null) {
					current.left = newNode;
					return;
				} else {
					stack.push(current.left);
				}
			} else {
				if (current.right == null) {
					current.right = newNode;
					return;
				} else {
					stack.push(current.right);
				}
			}
		}
	}

	private int findPos(int[] in, int id) {
		for (int i = 0; i < in.length; i++) {
			if (in[i] == id) {
				return i;
			}
		}
		return -1;
	}
}



Measured memory_bytes: 24296
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

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

func main() {
	defer stdout.Flush()
	n := readInt()
	m := readInt()
	G := make([][]int, n)
	for i := 0; i < m; i++ {
		a := readInt() - 1
		b := readInt() - 1
		G[a] = append(G[a], b)
		G[b] = append(G[b], a)
	}

	queue := make([]int, 0)
	push := func(v int) {
		queue = append(queue, v)
	}
	pop := func() int {
		n := len(queue) - 1
		v := queue[n]
		queue = queue[:n]
		return v
	}

	dist := make([]int, n)
	for i := range dist {
		dist[i] = math.MaxInt32
	}
	push(0)
	dist[0] = 0
	ans := "IMPOSSIBLE"
	for len(queue) != 0 {
		v := pop()
		if v == n-1 {
			ans = "POSSIBLE"
			break
		}
		for _, u := range G[v] {
			d := dist[v] + 1
			if d < 3 && d < dist[u] {
				dist[u] = d
				push(u)
			}
		}
	}
	println(ans)
}

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


Measured memory_bytes: 18048
import sys
sys.setrecursionlimit(10000000)

class Graph:
    def __init__(self,n,side):
        self.side = side
        self.neighbor = [set() for i in range(n+1)]
        self.visited = [False]*(n+1)
        self.group =[0]*n
        self.product()
    def product(self):
        for a,b in self.side:
            self.neighbor[a].add(b)
            self.neighbor[b].add(a)
    def dfs(self,x,a):
        self.group[a] += 1
        self.visited[x] = True
        for i in self.neighbor[x]:
            if self.visited[i]:continue
            self.dfs(i,a)
    def all_dfs(self):
        a = 0
        for i in range(1,n+1):
            if not self.visited[i]:
                self.dfs(i,a)
                a += 1

n,m = map(int,input().split())
side = list(tuple(map(int,input().split()))for i in range(m))
graph1 = Graph(n,side)
graph1.all_dfs()
print(max(graph1.group))


Measured memory_bytes: 266172
def accmulate(arr):
    N = len(arr)
    cs = [0]*(N+1)
    for i in range(N):
        cs[i+1] = cs[i] + arr[i]
    return cs

# [l,r)
def query(cs, l, r):
    return cs[r] - cs[l]

N = int(input())
A = list(map(int,input().split()))

left = accmulate(A)
right = accmulate(A[::-1])[::-1]
ans = min(abs(l-r) for l, r in zip(left, right))
print(ans)

Measured memory_bytes: 34572
import java.io.*;
import java.math.*;
import java.util.*;
import java.lang.*;
public class Main { 
 
	public static void main(String[] args) { 
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int K = I.nextInt();
		int N = I.nextInt();
		int[] a = new int[N];
		int ans = 0;
		for (int i = 0; i < N; i++) a[i] = I.nextInt();
		Arrays.sort(a);
		int L = 0;
		int R = N-1;
		while (L<=R) { //Just overload statements to ensure no Runtime error
			if (L==R) {
				ans=a[L]-1;
				ans=Math.max(0, ans);
				break;
			}
			int min = Math.min(a[L], a[R]);
			a[L]-=min;
			a[R]-=min;
			if (a[L]==0) L++;
			if (a[R]==0) R--;
		}
		O.pln(ans);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(boolean x) {w.println(x);w.flush();}
	}
}


Measured memory_bytes: 25496
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
using namespace std;
int main(){
  string a,b;
  int c,d;
  int n[31];
  vector<int> score;
  for(int i=0;i<31;i++)n[i]=0;
  while(true){
    getline(cin,a,',');
    c=atof(a.c_str());
    getline(cin,b,'\n');
    d=atof(b.c_str());
    if(!c)break;
    n[d]++;
    score.push_back(d);
  }
  for(int i=30,k=1;i>=0;i--)if(n[i]>0)n[i]=k++;
  while(cin>>c){
    cout<<n[score[c-1]]<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int bcj1[200010],bcj2[200010];
int father1(int k)
{
    return bcj1[k]==k?k:bcj1[k]=father1(bcj1[k]);
}
void join1(int x,int y)
{
    int fa,fb;
    fa=father1(x);fb=father1(y);
    bcj1[fb]=fa;
}
int father2(int k)
{
    return bcj2[k]==k?k:bcj2[k]=father2(bcj2[k]);
}
void join2(int x,int y)
{
    int fa,fb;
    fa=father2(x);fb=father2(y);
    bcj2[fb]=fa;
}
struct haha
{
    int p,q,no,ans;
}pp[200010];
bool cmp1(haha a,haha b)
{
    if (a.p==b.p) return a.q<b.q;
    return a.p<b.p;
}
bool cmp2(haha a,haha b)
{
    return a.no<b.no;
}
int main()
{
    int n,k,l,a,b,i,j,m,cnt;
    cin>>n>>k>>l;
    for(i=1;i<=n;i++)
    {
        bcj1[i]=bcj2[i]=i;
        pp[i].ans=0;pp[i].no=i;
    }
    for(i=1;i<=k;i++)
    {
        scanf("%d%d",&a,&b);
        join1(a,b);
    }
    for(i=1;i<=l;i++)
    {
        scanf("%d%d",&a,&b);
        join2(a,b);
    }
    for(i=1;i<=n;i++)
    {
        bcj1[i]=father1(bcj1[i]);
        pp[i].p=bcj1[i];
        bcj2[i]=father2(bcj2[i]);
        pp[i].q=bcj2[i];
    }
    sort(pp+1,pp+1+n,cmp1);cnt=0;
    pp[0].p=pp[0].q=0;j=1;
    for(i=1;i<=n+1;i++)
    {
        if (i<=n && pp[i].p==pp[i-1].p && pp[i].q==pp[i-1].q) continue;
        for(m=j;m<=i-1;m++)
            pp[m].ans=i-j;
        j=i;
    }
    sort(pp+1,pp+1+n,cmp2);
    for(i=1;i<=n;i++)
        printf("%d ",pp[i].ans);
    cout<<endl;
    return 0;
}

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

int main(){
    using namespace std;
    constexpr unsigned long MOD = 1000000007;
    unsigned long N, K;
    cin >> N >> K;
    vector<vector<unsigned long>> edge(N);
    for(unsigned long i = 1, a, b; i < N; ++i){
        cin >> a >> b;
        --a;
        --b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    unsigned long ans{K};
    cout << [dfs = [&edge, &ans, &K](auto f, auto now, auto prev) -> unsigned long{
        auto t = K - 2 + (now == prev);
        for(const auto& i : edge[now])if(i != prev){
            (ans *= t--) %= MOD;
            f(f, i, now);
        }
        return ans;
    }](auto start){return dfs(dfs, start, start);}(0) << endl;
    return 0;
}

Measured memory_bytes: 9088
#include<iostream>
#include<vector>
using namespace std;
vector<vector<int>> c(100100,vector<int> (0));
int N;

void DFS(int p,int ans,vector<bool> &b,vector<int> &d){
  if(b.at(p)){return;}
  
  if(!b.at(p)){
    b.at(p)=true;
    d.at(p)=ans;
    for(int i=0;i<c.at(p).size();i++){
      DFS(c.at(p).at(i),ans+1,b,d);
    }
  }
  return;
}

vector<int> dist(int p){
  vector<bool> b(N,false);
  vector<int> d(N);
  DFS(p,0,b,d);
  return d;
}

int main(){
  int T,A,ans=0;
  
  cin>>N>>T>>A;
  T--;A--;
  
  int s,t;
  for(int i=0;i<N-1;i++){
    cin>>s>>t;
    s--;t--;
    c.at(s).push_back(t);
    c.at(t).push_back(s);
  }
  
  vector<int> Td(N),Ad(N);
  Td=dist(T);
  Ad=dist(A);
  
  for(int i=0;i<N;i++){
    if(Td[i]<Ad[i]){ans=max(ans,Ad[i]-1);}
  }
  cout<<ans;
}


Measured memory_bytes: 13432