akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include <string>
#include <utility>
#include<array>
#include<set>
#define EPS (1e-7)
using namespace std;




int main() {


	int  A, B, C;
	cin >> A >> B >> C;
	int count = 0;

	while (true) {
		if (A < B && A < C) {
			A += 2;
			count += 1;
		}
		if (B < A && B < C) {
			B += 2;
			count += 1;
		}
		if (C < A && C < B) {
			C += 2;
			count += 1;
		}
		if (A == B && A < C) {
			A += 1;
			B += 1;
			count += 1;
		}
		if (A == C && A < B) {
			A += 1;
			C += 1;
			count += 1;
		}
		if (B == C && B < A) {
			B += 1;
			C += 1;
			count += 1;
		}
		if (A == B && B == C)break;

	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
n,w = map(int,input().split())
weight = []
value = []
for i in range(n):
  a,b= map(int,input().split())
  weight.append(a)
  value.append(b)

dp = [[0]*(w+1) for i in range(n+1)]
for i in range(n):
  for j in range(w+1):
    if j - weight[i] >= 0:
      dp[i+1][j] = max(dp[i][j],dp[i][j-weight[i]] + value[i])
    else:
      dp[i+1][j] = dp[i][j]

print(dp[n][w])


Measured memory_bytes: 120300
#include<iostream>

using namespace std;

int main(){
 int x1,y1,x2,y2;
  cin >> x1 >> y1 >> x2 >> y2;
  
  cout << x2+(y1-y2) << " "<< y2-(x1-x2) << " "<< x1+(y1-y2) << " "<< y1-(x1-x2) << endl;

}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        int x = in.nextInt();
        int y = in.nextInt();

        if (x > 8 || y > 8) {
            out.println(":(");
        } else {
            out.println("Yay!");
        }
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}


Measured memory_bytes: 22612
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  char *s = (char *) calloc (n + 1, sizeof (char));
  scanf ("%s", s);
  i32 q;
  scanf ("%" SCNi32, &q);
  while (q--) {
    i32 k;
    scanf ("%" SCNi32, &k);
    i64 ans = 0;
    i32 cntD = 0;
    i32 cntM = 0;
    i64 cntDM = 0;
    for (i32 i = 0; i < k; ++i) {
      if (s[i] == 'D') {
	cntD++;
      } else if (s[i] == 'M') {
	cntM++;
	cntDM += cntD;
      } else if (s[i] == 'C') {
	ans += cntDM;
      }
    }
    for (i32 i = k; i < n; ++i) {
      if (s[i - k] == 'D') {
	cntDM -= cntM;
	cntD--;
      } else if (s[i - k] == 'M') {
	cntM--;
      }
      if (s[i] == 'D') {
	cntD++;
      } else if (s[i] == 'M') {
	cntM++;
	cntDM += cntD;
      } else if (s[i] == 'C') {
	ans += cntDM;
      }
    }
    printf("%" PRIi64 "\n", ans);
  }
}

int main (void) {
  run ();
  return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

#define PI 3.141592653589793238
#define INF 1050000000

using namespace std;



//cout << fixed << setprecision(15) << << endl;
//cout << << endl;

int main() {

	int A,B;

	cin >> A>>B;

	if (A == B) {
		cout << "Draw" << endl;
	}
	else if (A == 1) {
		cout << "Alice" << endl;
	}
	else if (B == 1) {
		cout << "Bob" << endl;
	}
	else if (A > B) {
		cout << "Alice" << endl;
	}
	else {
		cout << "Bob" << endl;
	}


	return 0;
}

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

int main(){
  ll n;
  std::cin >> n;

  std::vector<int> a;


  while(n>0){
    a.push_back(n%26);
    if(n%26==0)n--;
    n/=26;

  }



  for(int i=a.size()-1; i>=0 ; i--){
    if(a[i]==0)std::cout << "z";
    else  std::cout << (char)(a[i]+'a'-1);
  }

  std::cout  << '\n';


  return 0;
}


Measured memory_bytes: 3584
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>

#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(a) (a).begin(), (a).end()

using namespace std;

int main() {
    long long A, B, C, n;
    cin >> A >> B >> C >> n;

    int sign = (n % 2 == 1) ? -1 : 1;
    long long res = sign * A - sign * B;

    if (abs(res) >= 1000000000000000000LL)
        cout << "Unfair" << endl;
    else
        cout << res << endl;

    return 0;
}


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

string s;

int main(void){
	cin >> s;
	int n = s.size();
	vector<bool> used(26);
	rep(i, n) used[s[i]-'a'] = true;
	int ans = 1e9;
	rep(i, 26){
		if(!used[i]) continue;
		char p = 'a'+i;
		int j = 0;
		int maxlen = 0;
		while(j < n){
			int len = 0;
			while(j < n && s[j] != p) j++, len++;
			maxlen = max(maxlen, len);
			j++;
		}
		ans = min(ans, maxlen);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3544
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    a,b,c,x=[parseInt(readline()) for i in 1:4]
    ans=0
    for i in 0:a,j in 0:b,k in 0:c
        if 500*i+100*j+50*k==x
            ans+=1
        end
    end
    println(ans)

end
main()

Measured memory_bytes: 169236
s = input()
t = input()

n = len(s)
m = len(t)
if n < m:
  print("UNRESTORABLE")
  exit()
x = -1
for i in range(n-m+1):
  for j in range(m):
    if s[n-j-i-1] == "?" or s[n-j-i-1] == t[m-j-1]:
      continue
      #print("{} {}".format(i,j))
    else:
      #print("break1")
      #print(j)
      #print(s[n-j-i])
      #print(t[m-j-1])
      break
  else:
    x = i
    #print("break2")
    break
#print(x)
if x == -1:
  print("UNRESTORABLE")
else:
  ans = s[:n-m-x]+t+s[n-x:]
  #print(ans)
  for i in range(n):
    if ans[i] == "?":
      ans = ans[:i] + "a" + ans[i+1:]
  print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

int main() {
    int H, W; cin >> H >> W;
    string a[H]; REP(0, i, H) cin >> a[i];

    // REP(0, i, H) cout << a[i] << endl;

    int h[H], w[W];
    REP(0, i, H) h[i] = 0;
    REP(0, i, W) w[i] = 0;

    REP(0, i, H) REP(0, j, W) {
        if (a[i][j] == '#') {
            // cout << i << ", " << j << endl;
            h[i] = 1;
            w[j] = 1;
        }
    }

    REP(0, i, H) {
        REP(0, j, W) {
            if (h[i] == 1 && w[j] == 1) {
                printf("%c", a[i][j]);
            }
        }
        if (h[i] == 1) printf("\n");
    }

    return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int Y = sc.nextInt();
    int judge = 0;
    
    while(X>=0&&Y>=0){
      if(Y/4==X&&Y%4==0){
        judge = 1;
        break;
      }
      X = X-1;
      Y = Y-2;
    }
    if(judge==1){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

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

int main(){
  ll h;
  cin >> h;
  ll cnt = 0;
  while(h != 0){
    h /= 2;
    cnt++;
  }
  ll ans = pow(2, cnt) -1;
  cout << ans << endl;
}


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

#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;

using vecint = vector<int>;
using ll = int64_t;

int main()
{
  int n;
  cin>>n;
  vector<ll> v(3*n);
  REP(i,3*n) cin>>v[i];
  sort(ALL(v), greater<ll>());
  ll sum = 0;
  REP(i,n) sum += v[2*i+1];
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 2688
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
int maxn[200001],maxnnn=-1,amax[200002],d[200001];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1; i<=n; ++i)
		scanf("%d",&d[i]);
	maxn[1]=d[1],maxnnn=d[1];
	for(int i=2; i<=n; ++i) {
		maxn[i]=maxn[i-1];
		if(d[i-1]>maxnnn)
			maxn[i]=d[i-1],maxnnn=d[i-1];
	}
	maxn[1]=0;
	amax[n]=d[n],maxnnn=d[n];
	for(int i=n-1; i>=1; --i) {
		amax[i]=amax[i+1];
		if(d[i+1]>maxnnn)
			amax[i]=d[i+1],maxnnn=d[i+1];
	}
	amax[n]=0;
	for(int i=1; i<=n; ++i)
		printf("%d\n",max(maxn[i],amax[i]));
	return 0;
}

Measured memory_bytes: 3840
var
    a,b,c,i,ans:longint;
    a1:array[1..100000]of longint;
begin
    read(a,b,c);
    for i:=1 to a do
    begin
        read(a1[i]);
        if(a1[i]<b)or(a1[i]>=c)then inc(ans);
    end;
    writeln(ans);
end.

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

using ull = unsigned long long;
using ll = long long;
using ld = long double;

const int mod = 1e9 + 7;
const int inf = INT_MAX;
const int N = 3e5 + 5;

template <typename T>
class SegmentTree {
public:
    using F = function<T(const T&, const T&)>;

    int n;
    vector<T> t;
    T e;
    F f;
    SegmentTree() : n(), t(), e(), f() {}

    template <typename U>
    SegmentTree(const U& arr, int n, T e, F f): n(n), t(4 * n), e(e), f(f) {
        build(arr, 1, 0, n - 1);
    }

    template <typename U>
    void build(const U& arr, int i, int l, int r) {
        if (l == r) {
            t[i] = T(arr[l]);
            return;
        }
        int mid = (l + r) >> 1;
        build(arr, i << 1, l, mid);
        build(arr, i << 1 | 1, mid + 1, r);

        t[i] = f(t[i << 1], t[i << 1 | 1]);
    }

    template <typename U>
    void update(int idx, U val) {
        updateHelper(idx, val, 1, 0, n - 1);
    }

    template <typename U>
    void updateHelper(int idx, U val, int i, int l, int r) {
        if (l == r) {
            t[i] = T(val);
            return;
        }
        int mid = (l + r) >> 1;
        if (idx <= mid)
            updateHelper(idx, val, i << 1, l, mid);
        else updateHelper(idx, val, i << 1 | 1, mid + 1, r);

        t[i] = f(t[i << 1], t[i << 1 | 1]);
    }

    T query(int ql, int qr) {
        return queryHelper(ql, qr, 1, 0, n - 1);
    }

    T queryHelper(int ql, int qr, int i, int l, int r) {
        if (ql > r or qr < l)
            return e;
        if (ql <= l and r <= qr)
            return t[i];
        int mid = (l + r) >> 1;
        T x = queryHelper(ql, qr, i << 1, l, mid), y = queryHelper(ql, qr, i << 1 | 1, mid + 1, r);
        return f(x, y);
    }
};

int n, a[N], k;

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

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

    SegmentTree<int> st(vector<int>(N), N, 0, [&] (int x, int y) {
        return x > y ? x : y;
    });

    for (int i = 0; i < n; i++) {
        int l = max(0, a[i] - k), r = min(N - 1, a[i] + k);
        st.update(a[i], 1 + st.query(l, r));
    }

    cout << st.t[1] << '\n';
    return 0;
}

Measured memory_bytes: 10340
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;

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

signed main(void){
  
    long double n,a,b; cin>>n>>a>>b;
    vector <int> nums(n);
    vector <vector<int>> com(52,vector <int>(52));
    
    com[0][0] = 1;
    for (int i = 1; i < 51; ++i) {
        for (int j = 0; j <= i; ++j) {
            com[i][j] += com[i-1][j];
            if (j > 0) com[i][j] += com[i-1][j-1];        
        }
    }
    rep(i,n) cin>>nums[i];
    sort(nums.begin(),nums.end());
    reverse(nums.begin(),nums.end());
    int f,l;
    f = nums[0], l = nums[a-1];
    //cout<<setprecision(10)<<accumulate(nums.begin(), nums.begin() + a,0.0)/a<<endl;
    printf("%.10Lf\n",accumulate(nums.begin(), nums.begin() + a,0.0)/a);
    
    if(f == l){
        int cnt = count(all(nums), f);
        
        int ans = 0;
        for(int i=a;i<=b;i++){
            ans += com[cnt][i];
            //cout<<com[cnt][i]<<endl;
        }
        cout<<ans<<endl;
    }else{
        int cnt = 0, call=0;
        rep(i,a){
            if(l == nums[i]) cnt++;
        }
        rep(i,n) if(l==nums[i]) call++;
        cout<<com[call][cnt]<<endl;
    }
}


Measured memory_bytes: 384
(let ((a (read))
    (b (read))
    (ans 0))
    (setq ans (+ a b))
    (if (> (- a b) ans)
        (setq ans (- a b))
    )
    (if (> (* a b) ans)
        (setq ans (* a b))
    )
    (princ ans)
)

Measured memory_bytes: 24204
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main() {
  int n;
  cin>>n;
  vector<P>a,b;
  rep(i,n){
    int s,t;
    cin>>s>>t;
    a.push_back(P(s,t));
  }
  rep(i,n){
    int s,t;
    cin>>s>>t;
    b.push_back(P(s,t));
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  int ans=0;
  vector<bool>ch(n);
  rep(i,n){
    int now=1001001001;
    int co=-1;
    rep(j,n){
      if(!ch[j]&&a[i].first<b[j].first&&a[i].second<b[j].second){
        if(now>b[j].second){
          now=b[j].second;
          co=j;
        }
      }
    }
    if(co>=0){
      ans++;
      ch[co]=true;
    }
  }
  
  cout<<ans<<endl;
}



Measured memory_bytes: 3668
#include <iostream>

#define MOUNTAINS 10
#define RANK 3

using namespace std;

void InsertToRank(int *rank, int idx, int height);

int main(void)
{
    int i, j;
    int rank[RANK] = {0};
    int height;
    
    for (i = 0; i < MOUNTAINS; i++) {
        cin >> height;
        for (j = 0; j < RANK; j++) {
            if (rank[j] < height) {
                InsertToRank(rank, j, height);
                break;
            }
        }
    }
    
    for (i = 0; i < RANK; i++) {
        cout << rank[i] << endl;
    }
    
    return 0;
}

void InsertToRank(int *rank, int idx, int height)
{
    int i;
    
    for (i = 2; i > idx; i--) {
        rank[i] = rank[i - 1];
    }
    rank[idx] = height;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int N, u, v;
vector<vector<int>> graph(100000);
vector<vector<int>> Ko(100000);
vector<int> Oya(100000);
vector<int> deaph(100000, 0);

int M = 0;

void KI(int n) {
    for (int x : graph[n]) {
        if (x != Oya[n]) {
            Ko[n].push_back(x);
            Oya[x] = n;
            deaph[x] = deaph[n] + 1;
            KI(x);
        }
    }
    return;
}

void f(int n) {
    M = max(M, deaph[n]);
    for (int x : Ko[n]) f(x);
    return;
}

int main() {
    cin >> N >> u >> v;
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        graph[a - 1].push_back(b - 1);
        graph[b - 1].push_back(a - 1);
    }
    
    --u;
    --v;
    Oya[v] = v;
    KI(v);
    
    int d = deaph[u];
    int s = (d - 1) / 2;
    int now = u;
    rep(i, s) now = Oya[now];
    f(now);
    
    int ans = M - deaph[now] + s;
    if (d % 2 == 0) ++ans;
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;
typedef pair<ll,ll> P;

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

int main()
{
  string S, T;
  cin >> S >> T;
  rep(i,0,S.length()){
    // cout << S << endl;
    if (S == T){
      cout << "Yes" << endl;
      return 0;
    }
    char A = S[0];
    rep(j,0,S.length()-1){
      S[j] = S[j+1];
    }
    S[S.length()-1] = A;
  }
  // cout << S << endl;
  if (S == T){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}


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

signed main(){
	using P = pair<int,int>;
	int n;
	cin >> n;
	vector<P> vecUp,vecDown;
	for(int i = 0;i < n;i++){
		string s;
		cin >> s;
		int cnt = 0,mi = 0;
		for(int j = 0;j < s.length();j++){
			if(s[j] == '(') cnt++;
			else cnt--;
			mi = min(mi,cnt);
		}
		if(cnt >= 0) vecUp.emplace_back(-mi,cnt - mi);
		else vecDown.emplace_back(-mi,cnt - mi);
	}
	sort(vecUp.begin(),vecUp.end());
	sort(vecDown.begin(),vecDown.end(),[](const P &p1,const P &p2){
		return p1.second > p2.second;
	});
	int cnt = 0,mi = 0;
	for(P p : vecUp){
		cnt -= p.first;
		mi = min(mi,cnt);
		cnt += p.second;
	}
	for(P p : vecDown){
		cnt -= p.first;
		mi = min(mi,cnt);
		cnt += p.second;
	}
	if(cnt || mi < 0) cout << "No" << endl;
	else cout << "Yes" << endl;
}


Measured memory_bytes: 3232
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    string s;
    cin >> s;
    cout << s.at(0) << s.size()-2 << s.at(s.size()-1) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
#define endl '\n'
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#pragma endregion
#define MAX 222222


bool visited[MAX];
ll dp[MAX];
vll edge[MAX], tps;

void dfs(ll cur) {
  if (visited[cur]) return;
  visited[cur] = true;
  rep(i, edge[cur].size()) if (!visited[edge[cur][i]]) dfs(edge[cur][i]);
  tps.pb(cur);
}

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


  cin >> n >> m;
  rep(i, m) {
    ll x, y;
    cin >> x >> y;
    edge[x].pb(y);
  }
  FOR(i, 1, n + 1) dfs(i);
  reverse(all(tps));
  rep(i, tps.size()) {
    rep(j, edge[tps[i]].size()) dp[edge[tps[i]][j]] = max(dp[edge[tps[i]][j]], dp[tps[i]] + 1);
  }
  FOR(i, 1, n + 1) ans = max(ans, dp[i]);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 12152
-- modules to import --

import qualified Data.ByteString.Char8
import qualified Data.Maybe
import           Prelude

-- functions for this task --

readInteger'    = Prelude.fst . Data.Maybe.fromJust . Data.ByteString.Char8.readInteger
readListInteger = Prelude.map readInteger' . Data.ByteString.Char8.words

getInteger     = readInteger'    <$> Data.ByteString.Char8.getLine
getListInteger = readListInteger <$> Data.ByteString.Char8.getLine

task_A :: Integer -> Integer -> Data.ByteString.Char8.ByteString
task_A num_piece_a num_piece_b = Data.ByteString.Char8.pack $ if (stat_a && stat_b) then "Yay!" else ":("
        where
                stat_a = num_piece_a <= (8 :: Integer)
                stat_b = num_piece_b <= (8 :: Integer)

-- the main process is as follows --

main :: IO ()
main = do

        -- STEP.01
        -- read out the given data
        [num_piece_a, num_piece_b] <- getListInteger

        -- STEP.02
        -- calculate & output the answer of this task
        Data.ByteString.Char8.putStrLn $ task_A (num_piece_a) (num_piece_b)

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

int main(){
	int m, f, r;
	
	while(1){
		cin >> m >> f >> r;
		if(m == -1 && f == -1 && r == -1){
			break;
		}
		
		if(m == -1 || f == -1){
			cout << 'F' << endl;
		}else if(m + f >= 80){
			cout << 'A' << endl;
		}else if(m + f >= 65){
			cout << 'B' << endl;
		}else if(m + f >= 50){
			cout << 'C' << endl;
		}else if(m + f >= 30){
			if(r >= 50){
				cout << 'C' << endl;
			}else{
				cout << 'D' << endl;
			}
		}else{
			cout << 'F' << endl;
		}
	}
    return 0;
}

Measured memory_bytes: 3092
//includes
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#include<numeric>
#include<assert.h>
#include<cstring>
#include<unordered_map>
#include<bitset>

//macros and consts
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define FORE(i,a) for(auto &i : a)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define accm accumulate
#define Fi first
#define Se second
#define INF 1e9
#define llINF (1LL<<60)
#define mINF -1e9
#define mllINF -(1LL<<60)
#define endl "\n"
#define CONT continue
#define BRK break
#define modulo(n, m) (((n)%(m)+(m))%m)

//shorter types
using namespace std;
using ll = long long;
using vi = std::vector<int>;
using vc = std::vector<char>;
using vll = std::vector<long long>;
using vs = std::vector<string>;
using Mi = map<int,int>;
using Mll = map<ll,ll>;
using UMi = unordered_map<int,int>;
using UMll = unordered_map<ll,ll>;
using Pi = pair<int,int>;
using Pll = pair<ll,ll>;
using vPi = vector<Pi>;
using vPll = vector<Pll>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using pqgi = priority_queue<int,vector<int>,greater<int>>;
using pqsi = priority_queue<int,vector<int>,less<int>>;
using pqgll = priority_queue<int,vector<int>,greater<int>>;
using pssll = priority_queue<int,vector<int>,less<int>>;
template<class T>
using vec = vector<T>;
#define int long long

double dist(pair<int,int> a,pair<int,int> b){
	return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second));
}

//here begins your code
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int N;
  vector<pair<int,int>> xy;

  cin >> N;
  xy.resize(N);
  for(int i = 0 ; i < N ; i++){
  	cin >> xy[i].first >> xy[i].second;
  }

  vector<int> arr;
  for(int i = 0 ; i < N ; i++){
  	arr.push_back(i);
  }
  double sum = 0;
  int ctr = 0;
  do{
  	for(int i = 0 ; i < N - 1 ; i++){
  		sum += dist(xy[arr[i]],xy[arr[i+1]]);
  	}
  	ctr++;
  }while(next_permutation(all(arr)));


  cout << setprecision(10) << sum / (double) ctr << endl;
  //check types
  //do not eb if you resize
  //resize before you access by idx
  return 0;
} 

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include<sstream>
#include<numeric>
#include<queue>
#include<cstdio>
#include<iterator>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ull = unsigned long long;

#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb(x) push_back(x)
ll mod = 1e9 + 7;
ll inf = 1e9 + 7;
template<typename T, typename U>
T binpow(T a, U n) {
    if (n == 0)
        return 1;
    if (n % 2 == 1)
        return (binpow(a, n - 1) * a) % mod;
    else {
        ll b = binpow(a, n / 2) % mod;
        return (b * b) % mod;
    }
}
template<typename T>
T gcd(T a, T b) {
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}
template<typename T>
istream& operator>>(istream& str, vector<T>& vec) {
    for (auto& w : vec) str >> w;
    return str;
}
template<typename T>
ostream& operator<<(ostream& str, vector<T>& vec) {
    for (auto& w : vec) str << w << ' ';
    return str;
}

struct segtree {
    vector<set<ll>>mn;
    vector<ll>tree;
    size_t size = 1;
    //void build(ll x, ll lx, ll rx, vector<ll>& vec);
    void build(ll size_) {
        while (size < size_) {
            size *= 2;
        }
        tree.resize(size * 2 - 1);
        mn.resize(size * 2 - 1);
    }
    void update(ll i, ll x, ll v, ll lx, ll rx) {
        if (rx - lx == 1) {
            tree[x] = v;
            return;
        }
        ll m = (lx + rx) / 2;
        if (i < m) {
            update(i, 2 * x + 1, v, lx, m);
        }
        else {
            update(i, 2 * x + 2, v, m, rx);
        }
        tree[x] = tree[2 * x + 1] + tree[2 * x + 2];
    }

    ll get(ll l, ll r, ll x, ll lx, ll rx) {
        if (l <= lx && rx <= r) return tree[x];
        if (rx <= l || lx >= r) return 0;
        ll m = (lx + rx) / 2;
        return get(l, r, 2 * x + 1, lx, m) + get(l, r, 2 * x + 2, m, rx);
    }
};



signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    string s, t;
    cin >> s >> t;
    int minn = 1e9;
    for (int i = 0; i <= s.size() - t.size(); ++i) {
        int cur = 0;
        for (int j = 0; j < t.size(); ++j) {
            if (s[i + j] != t[j])
                cur++;
        }
        minn = min(minn, cur);
    }
    cout << minn;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef unsigned long long ll;
int N, n;
vector<int> v(0);

int main(){
    int x,y;
    int ans = 0;
    cin >> x >> y;
    if(x == 1) ans += 300000;
    else if(x == 2) ans += 200000;
    else if(x == 3) ans += 100000;
        if(y == 1) ans += 300000;
    else if(y == 2) ans += 200000;
    else if(y == 3) ans += 100000;
    if(x == 1 & y == 1) ans += 400000;
    cout << ans; 
}



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

int main() {
 long int a;
 cin >> a;
 int b = 0;
 int c[a];
  for(int i=0;i<a;i++){
    cin >> c[i];
  }
  for(int i=0;i<a;i++){
    for(int j = i+1;j<a;j++){
      for(int k = j+1;k<a;k++){
        if(c[i]+c[j]>c[k]&&c[j]+c[k]>c[i]&&c[k]+c[i]>c[j]&&c[i]!=c[k]&&c[k]!=c[j]&&c[j]!=c[i]) b++;
      }
    }
  }
  cout << b << endl;
   }



Measured memory_bytes: 3572
import numba
import numpy as np
N = int(input())
P = np.array([int(c)-1 for c in input().split()])

#from random import shuffle
#N = 500
#P = list(range(N*N))
#shuffle(P)
#P = np.array(P)

@numba.njit("void(i8,i8[:])")
def proc(N, P):
    ans = 0
    Removed = np.zeros((500, 500), dtype=np.int8)
    Mat = np.zeros((500, 500), dtype=np.int16)
    Dy, Dx = [1,0,-1,0], [0,1,0,-1]

    for y in range(N):
        for x in range(N):
            Mat[y, x] = min(y, N-1-y, x, N-1-x)
    #print(Mat)
    for i in range(N*N):
        p = P[i]
        y, x = divmod(p, N)
        ans += Mat[y,x]
        Removed[y,x] = 1
        st = [(y, x)]
        while st:
            vy, vx = st.pop()
            vr = Removed[vy,vx]
            val = Mat[vy,vx]
            #for dy, dx in zip(Dy, Dx):
            for j in range(4):
                dy,dx = Dy[j],Dx[j]
                uy = vy + dy
                ux = vx + dx
                if not (0<=uy<N and 0<=ux<N):
                    continue
                ur = Removed[uy,ux]
                if vr:
                    if Mat[uy,ux] >= val+1:
                        Mat[uy,ux] = val
                        st.append((uy, ux))
                else:
                    if Mat[uy,ux] >= val+2:
                        Mat[uy,ux] = val+1
                        st.append((uy, ux))
    # for m in Mat:
    #     print(m)
    print(ans)
proc(N, P)



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

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		var p = Input().ToInt();
		int h = p[0];
		int w = p[1];
		int n = Console.ReadLine().ToInt();
		var a = Input().ToInt();
		int[,] grid = new int[w, h];
		int cur = 1;
		int cnt = 0;
		for(int i = 0; i < h * w; i++)
		{
			int x = i / h;
			int y = (x % 2 == 0 ? (i % h) : (h - (i % h) - 1));
			grid[x, y] = cur;
			cnt++;
			if(cnt == a[cur-1])
			{
				cnt = 0;
				cur++;
			}
		}
		for(int y = 0; y < h; y++)
		{
			for(int x = 0; x < w; x++)
			{
				Console.Write("{0} ", grid[x,y]);
			}
			Console.WriteLine();
		}
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		int[] r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
	
}

Measured memory_bytes: 13280
"use strict";

const main = arg => {
    const input = arg.trim().split("\n");

    const N = Number(input[0].split(" ")[0]);
    const M = Number(input[0].split(" ")[1]);
    const A = input[1].split(" ").map(n => Number(n));
    const total = A.reduce((acc, curr) => acc+curr)
    const thresh = 1*total / (4*M)
    A.sort((a,b) => b-a)
    if(A[M-1] < thresh) console.log("No")
    else console.log("Yes")
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));  


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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;

LL n;

int main()
{
	cin >> n;
	
	LL res = 1LL;
	for (LL i = 1LL; i <= (n - 1LL) / i; i ++ )
		if ((n - 1LL) % i == 0LL)
		{
			if (i > 1LL) res ++ ;
			if ((n - 1LL) / i != i) res ++ ;
		}
		
	for (LL i = 2LL; i <= n / i; i ++ )
		if (n % i == 0LL)
		{
			LL t = n;
			while (t % i == 0LL) t /= i;
			if (t % i == 1LL) res ++ ;
		}
	
	cout << res << endl;
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> v(n), c(n);
    rep(i,n) cin >> v[i];
    rep(i,n) cin >> c[i];
    int ans = 0;
    rep(i,n) {
      ans += max(v[i]-c[i], 0);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3588
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Main main = new Main();
		main.solveC();
	}

	private void solveC() {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		for (int i = n - 1; i >= 0; i -= 2) {
			System.out.print(a[i] + " ");
		}
		for (int i = n % 2; i < n; i += 2) {
			System.out.print(a[i]);
			if (i < n - 2) {
				System.out.print(" ");
			}
		}
	}
}

Measured memory_bytes: 94064
#include <cstdio>
#include <vector>
#include <algorithm>
#include <tuple>
using namespace std;

class union_find{
public:
  vector<int> uf;
  union_find(int n){
    uf=vector<int>(n);
    for(int i=0;i<n;i++){
      uf[i]=-1;
    }
  }
  int root(int i)
  {
    return uf[i]<0?i:uf[i]=root(uf[i]);
  }
  void unite(int i,int j)
  {
    if(-uf[i]<-uf[j]){
      uf[i]=j;
    }
    else if(-uf[i]>-uf[j]){
      uf[j]=i;
    }
    else{
      uf[i]=j;
      uf[j]--;
    }
  }
};

int main()
{
  int n,h,w;
  scanf("%d%d%d",&n,&h,&w);
  vector<tuple<long long,int,int> > E(n);
  for(int i=0;i<n;i++){
    int r,c;
    long long A;
    scanf("%d%d%lld",&r,&c,&A);
    r--,c--;
    E[i]=make_tuple(A,r,h+c);
  }
  sort(E.begin(),E.end());
  long long ans=0ll;
  union_find uf(h+w);
  vector<int> tree(h+w,true);
  for(int i=n-1;i>=0;i--){
    long long A=get<0>(E[i]);
    int a=get<1>(E[i]),b=get<2>(E[i]);
    a=uf.root(a),b=uf.root(b);
    if(a!=b&&(tree[a]||tree[b])){
      bool t=(tree[a]&&tree[b]);
      uf.unite(a,b);
      tree[uf.root(a)]=t;
      ans+=A;
      //printf("%d %d %lld\n",a,b,A);
    }
    else if(tree[a]){
      tree[a]=false;
      ans+=A;
      //printf("%d %d %lld\n",a,b,A);
    }
  }
  printf("%lld\n",ans);
  return 0;
}


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

vector<pair<int,int>> merge(vector<pair<int,int>> v, pair<int,int> add){
	for(int unsigned i=0;i<v.size();i++){
		if(	(v[i].first <= add.first && add.first <= v[i].second) ||
			(v[i].first <= add.second && add.second <= v[i].second) ||
			(add.first <= v[i].first && v[i].second <= add.second) ){
			v[i] = make_pair(min(v[i].first, add.first), max(v[i].second, add.second));
			return v;
		}
	}
	v.emplace_back(add);
	return v;
}

int main(){
	int N,M;
	while(cin >> N >> M,N!=0&&M!=0){
		int r;
		cin >> r;
		vector<vector<pair<int,int>>> user(M);
		vector<pair<int,int>> user_login(M,make_pair(0,0));
		for(int i=0;i<r;i++){
			int t,n,m,s;
			cin >> t >> n >> m >> s;
			m--;
			if(s && user_login[m].first == 0){
				user_login[m].second = t;
			}
			if(s) user_login[m].first++;
			else user_login[m].first--;
			if(user_login[m].first == 0){
				user[m] = merge(user[m], make_pair(user_login[m].second, t));
			}
		}
		/*for(unsigned int i=0;i<user.size();i++){
			cout << i << ": ";
			for(unsigned int j=0;j<user[i].size();j++){
				cout << "(" << user[i][j].first << ", " << user[i][j].second << ") ";
			}
			cout << endl;
		}*/

		int q;
		cin >> q;
		for(int i=0;i<q;i++){
			int s,e,m;
			cin >> s >> e >> m;
			m--;
			sort(user[m].begin(), user[m].end());
			int ans = 0;
			for(auto x:user[m]){
				if(s <= x.first && x.second <= e){
					//cout << x.second << " " << x.first << endl;
					ans += x.second - x.first;
				} else if(s <= x.first && x.first <= e){
					//cout << e << " " << x.first << endl;
					ans += e - x.first;
				} else if(s <= x.second && x.second <= e){
					//cout << x.second << " " << s << endl;
					ans += x.second - s;
				} else if(x.first <= s && e <= x.second){
					//cout << e << " " << s << endl;
					ans += e - s;
				}
			}
			cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3304
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#include<bitset>
#include<stack>
#include<time.h>



#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define ALL(x) x.begin(),x.end()
#define sz(a) ((int)a.size())
#define getmid ((l+r)>>1)
#define mst(var,val) memset(var,val,sizeof(var))
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define lowbit(x) x&(-x)
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ls rt<<1
#define rs rt<<1|1
using namespace std;
#ifdef local
#define dbg(args...) cout << #args << " -> ", err(args);
void err(){ cout << endl; }
template<typename T, typename... Args>
void err(T a, Args... args){ cout << a << ' '; err(args...); }
#else
#define dbg(args...)
#endif // local

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <double, double> pdd;
const int inf=0x3f3f3f3f;
const long long INF=0x3f3f3f3f3f3f3f3fLL;
const double PI=acos(-1.0);
const long double eps=1e-8;
const int mod=1e9+7;
const int MAXN=2e3+100;
const int N=1e6+1000;
const int M=500+10;
const ll mm=(1LL<<32);

template <class T>
inline void read(T &x)
{
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar())
        f ^= c == '-';
    for (; isdigit(c); c = getchar())
        x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x)
{
    if (x < 0)
    {
        putchar('-');
        x = -x;
    }
    T y = 1;
    int len = 1;
    for (; y <= x / 10; y *= 10)
        ++len;
    for (; len; --len, x %= y, y /= 10)
        putchar(x / y + 48);
}
ll qpow(ll a,ll b,ll mod)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return ans;
}


int main()
{
#ifdef local
    freopen("in.txt","r",stdin);
#endif // local
    IOS;cout.tie(0);
    int x;cin>>x;
    if(x<=599) cout<<8;
    else if(x<=799) cout<<7;
    else if(x<=999) cout<<6;
    else if(x<=1199) cout<<5;
    else if(x<=1399) cout<<4;
    else if(x<=1599) cout<<3;
    else if(x<=1799) cout<<2;
    else cout<<1;
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
const int mod=1e9+7;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
ll qpow(ll a,ll b){ll ans=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)ans=ans*a%mod;a=a*a%mod;}return ans;}
ll gcd(ll a,ll b){return b>0?gcd(b,a%b):a;}

int a[maxn];

int main(){
    int y,m,d;
    scanf("%d/%d/%d",&y,&m,&d);
    if(y<2019){
        cout<<"Heisei"<<endl;
    }else if(y==2019){
        if(m<4){
            cout<<"Heisei"<<endl;
        }else if(m==4){
            if(d<=30){
                cout<<"Heisei"<<endl;
            }else{
                cout<<"TBD"<<endl;
            }
        }else{
                cout<<"TBD"<<endl;
            }
    }else{
                cout<<"TBD"<<endl;
    }

    return 0;
}



Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let s: Vec<char> = iterator.next().unwrap().chars().collect();

    let mut t: Vec<char> = Vec::new();
    let mut indexes: Vec<usize> = Vec::new();
    for i in 0..s.len() {
        if s[i] != 'x' {
            t.push(s[i]);
            indexes.push(i);
        }
    }

    if t.len() == 0 {
        return "0".to_string()
    }

    if !is_kaibun(&t) {
        return "-1".to_string();
    }

    let (l, r) = if indexes.len() % 2 == 0 {
        (indexes[indexes.len() / 2 - 1], indexes[indexes.len() / 2])
    } else {
        (indexes[indexes.len() / 2], indexes[indexes.len() / 2])
    };
    // println!("l = {}, r = {}", l, r);

    // 中心から左方向に見ていく
    let mut counts_l: Vec<isize> = Vec::new();
    let mut c = 0;
    for i in (0..l).rev() {
        // println!("{}", s[i]);
        if s[i] == 'x' {
            c += 1;
        } else {
            counts_l.push(c);
            c = 0;
        }
    }
    counts_l.push(c);
    // println!("{:?}", counts_l);

    // 中心から右方向に見ていく
    let mut counts_r: Vec<isize> = Vec::new();
    let mut c = 0;
    for i in (r + 1)..s.len() {
        // println!("{}", s[i]);
        if s[i] == 'x' {
            c += 1;
        } else {
            counts_r.push(c);
            c = 0;
        }
    }
    counts_r.push(c);

    // println!("{:?}", counts_r);

    let mut ans = 0;
    for (l, r) in counts_l.iter().zip(counts_r.iter()) {
        ans += (*l - *r).abs();
    }
    return ans.to_string();
}

fn is_kaibun(t: &Vec<char>) -> bool {
    for i in 0..(t.len() / 2) {
        if t[i] != t[t.len() - 1 - i] {
            return false;
        }
    }
    return true;
}


Measured memory_bytes: 8444
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s=sc.next();
		char c[]=s.toCharArray();
		if(c[0]==c[1]||c[1]==c[2]||c[2]==c[3]){
			System.out.println("Bad");
		}else{
			System.out.println("Good");
		}

	}}

Measured memory_bytes: 22100
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 10010010010
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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


int main(){
    ll N;
    cin>>N;
    ll M0 = -INF,m0 = INF,M1 = -INF,m1 = INF;
    rep(i,0,N){
        ll x,y;
        cin>>x>>y;
        if(M0 < x-y)M0 = x-y;
        if(m0 > x-y)m0 = x-y;
        if(M1 < x+y)M1 = x+y;
        if(m1 > x+y)m1 = x+y;
    }
    //cout<<M0<<m0<<M1<<m1<<endl;
    cout<<max(M0-m0, M1-m1);

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << - 1 << endl;}
void unhap() {cout << ":(" << endl;}

int main() {
  int x;
  cin >> x;
  if (x == 7 || x == 5 || x == 3) YES();
  else NO();
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0; 
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

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

void solve(){
	int n = scan!int, x = scan!int, t = scan!int;
	int ans = (n + x - 1) / x * t;
  	ans.writeln;
}

Measured memory_bytes: 3268
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define MAX 300005
int m,n,A,B;
int a,b,C=~(1<<31),M=(1<<16)-1;
 
int r() {
  a = 36969 * (a&M) + (a>>16);
  b = 18000 * (b&M) + (b>>16);
  return (C&((a<<16)+b))%1000000;
}
 
int x[MAX],y[MAX],z[MAX];
set< P > t[MAX];
 
 
void insert(set<P> &s,P p){
  set<P> :: iterator it;
  while(1){
    it=s.upper_bound(p);
    if(it==s.end())break;
 
    if( p.first <= it->first &&
        p.second <= it->second ){
      s.erase(it);
    }else{
      break;
    }
  }
  s.insert(p);
}
 
bool check(set<P> &s,P p){
  set<P> :: iterator it;
  it=s.upper_bound(p);
  int cc=0;
  while(it!=s.begin()){
    cc++;
    if(cc>3)break;
 
    it--;
    if(it->first < p.first)
      if(it->second < p.second)
        return true;
  }
  return false;
}
 
int calc(P p){
  int left=0,right=m+n,mid;
  while(left<right){
    mid=(left+right)/2;
    if(check(t[mid],p))left=mid+1;
    else right=mid;
  }
  return left;
}
 
 
vector<P> G[1000005];
 
int solve(){
  int ans=1;
 
  for(int i=0;i<=m+n;i++){
    t[i].clear();
  }
  t[0].insert(P(-1,-1));
  set<int> st;
 
  for(int i=0;i<m+n;i++){
    st.insert( z[i] );
    G[ z[i] ].push_back( P(x[i],y[i]) );
  }
 
  for( int i : st ){
    vector<int> v( G[i].size() );
    for(int j=0;j<(int)G[i].size();j++){
      v[j]=calc(G[i][j]);
      ans=max(ans,v[j]);
    }
    for(int j=0;j<(int)G[i].size();j++){
      if(check( t[ v[j] ] , G[i][j])==false)
        insert(t[ v[j] ],G[i][j]);
    }
    G[i].clear();    
  }
  /*
  for(int i=0;i<=ans;i++){
    cout<<i<<" :"<<endl;
    for(P p:t[i]){
      cout<<p.first<<' '<<p.second<<endl;
    }
    cout<<endl;
    cout<<endl;
  }
  cout<<endl;
  */
  return ans;
}
 
int main(){
  while(1){
    scanf("%d %d %d %d",&m,&n,&A,&B);
    if(m==0&&n==0&&A==0&&B==0)break;
 
    a=A,b=B;
     
    for(int i=0;i<m;i++){
      scanf("%d %d %d",&x[i],&y[i],&z[i]);
    }
 
    for(int i=m;i<m+n;i++){
      x[i]=r();
      y[i]=r();
      z[i]=r();
    }
    printf("%d\n",solve());
 
 
  }
}

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

int shoki;
int year;

int fukuri(double p, int c) {
  int A = shoki;
  int B;
  for (int i=0; i<year; i++) {
    B = A * p;
    A = A + B - c;
  }
  return A;
}

int tanri(double p, int c) {
  int A = shoki;
  int sum = 0;
  for (int i=0; i<year; i++) {
    sum +=  A * p;
    // cerr << "sum: " << sum << endl;
    A -= c;
  }
  return A+sum;
}

int main() {
  int d;
  scanf("%d", &d);
  for (int t=0; t<d; t++) {
    int n;
    scanf("%d%d%d", &shoki, &year, &n);
    // // cerr << n << endl;
    int max = shoki;
    for (int i=0; i<n; i++) {
      int tanpuku;
      double p;
      int c;
      scanf("%d%lf%d", &tanpuku, &p, &c);
      int gold;
      if (tanpuku) {
	gold = fukuri(p, c);
	// cerr << "fukuri" << endl;
      } else {
	gold = tanri(p, c);
	// cerr << "tanri" << endl;
      }
      // cerr << "gold: " << gold << endl;
      if (gold > max) {
        max = gold;
      }
    }
    printf("%d\n", max);
  }
}

Measured memory_bytes: 1204
from collections import deque
H, W = map(int, input().split())
S_raw = [list(input()) for _ in range(H)]
m = 0
def calc(h,w):
    S = [list(S_raw[i][j] for j in range(W)) for i in range(H)]
    S[h][w]=0
    queue = deque([(h,w)])
    while queue:
        q = queue.popleft()
        for x in ((q[0]-1, q[1]),(q[0]+1, q[1]), (q[0], q[1]-1), (q[0], q[1]+1)):
          if 0<=x[0]<=H-1 and 0<=x[1]<=W-1:
            if S[x[0]][x[1]]==".":
              S[x[0]][x[1]] = S[q[0]][q[1]]+1
              queue.append(x)
    return max(S[h][w] for w in range(W) for h in range(H) \
                    if str(S[h][w]).isdigit())    
for h in range(H):
  for w in range(W):
    if S_raw[h][w]==".":
        m = max(m, calc(h,w))
print(m)

Measured memory_bytes: 9228