akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)


int main(){
    ll N, K; cin >> N >> K;
    vector<int> P(N);
    rep(i, N){
        cin >> P[i];
    }
    vector<double> exp(N, 0);
    rep(i, N){
        exp[i] = (P[i] + 1) / 2.0;
    }
    vector<double> cnt(N+1, 0);
    for(int i = 1; i <= N; ++i){
        cnt[i] = cnt[i-1] + exp[i-1];
    }
    double ans = cnt[K] - cnt[0];
    for(int i = K+1; i <= N; ++i){
        double tmp = cnt[i] - cnt[i - K];
        ans = max(tmp, ans);
    }
    cout << setprecision(8);
    cout << fixed;
    cout << ans << endl;
}

Measured memory_bytes: 4096
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

void dout() { cerr << '\n'; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << " " << H;
    dout(T...);
}

#ifdef LOCAL
    #define dbg(...) cerr << #__VA_ARGS__, dout(__VA_ARGS__)
#else
    #define dbg(...) ;
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;

const int N = 1003;
int n, a[N];

int main() {
    ios_base::sync_with_stdio(false), cin.tie(NULL);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif

    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    ll ans1 = 0, ans2 = 0;
    vector <int> odd, even;
    for (int i = 1; i <= n; i += 2) {
        if (a[i] >= 0) {
            odd.pb(i);
            ans1 += a[i];
        }
    }
    if (odd.empty()) {
        int mx = 1;
        for (int i = 1; i <= n; i += 2) {
            if (a[i] > a[mx]) {
                mx = i;
            }
        }
        odd.pb(mx);
        ans1 += a[mx];
    }
    for (int i = 2; i <= n; i += 2) {
        if (a[i] >= 0) {
            even.pb(i);
            ans2 += a[i];
        }
    }
    if (even.empty()) {
        int mx = 2;
        for (int i = 2; i <= n; i += 2) {
            if (a[i] > a[mx]) {
                mx = i;
            }
        }
        even.pb(mx);
        ans2 += a[mx];
    }
    vector <int> res;
    if (ans1 > ans2) {
        int x = 0;
        for (int i = 1; i < odd[0]; i++) {
            res.pb(1);
            x++;
        }
        n -= x;
        for (int & i : odd) {
            i -= x;
        }
        while (n > odd.back()) {
            res.pb(n);
            n--;
        }
        while (odd.size() > 1) {
            int mid = odd[odd.size() - 1] + odd[odd.size() - 2] >> 1;
            for (int i = mid; i > odd[odd.size() - 2]; i--) {
                res.pb(i);
            }
            odd.ppb();
        }
    }   else {
        int x = 0;
        for (int i = 1; i < even[0]; i++) {
            res.pb(1);
            x++;
        }
        n -= x;
        for (int & i : even) {
            i -= x;
        }
        while (n > even.back()) {
            res.pb(n);
            n--;
        }
        while (even.size() > 1) {
            int mid = even[even.size() - 1] + even[even.size() - 2] >> 1;
            for (int i = mid; i > even[even.size() - 2]; i--) {
                res.pb(i);
            }
            even.ppb();
        }
    }
    cout << max(ans1, ans2) << '\n';
    cout << res.size() << '\n';
    for (int i : res) {
        cout << i << '\n';
    }
}


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

using namespace std;

int main(){

	int N;
  	cin >> N;
  	int ans = 0;
  	if(N>=10) ans += 9;
  	if(N>=1000) ans += 900;
  	if(N>=100000) ans += 90000;
  	if(N>=1 && N<=9) ans += N; 
  	if(N>=100 && N<=999) ans += (N-99);
    if(N>=10000 && N<=99999) ans += (N-9999);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <random>
#include <set>
#include <bitset>
#include <cassert>

using namespace std;

int f(int n, int k) {
  if (n / k == 0) return 0;
  if (n % k == 0) return n / k;
  // n = kq + r
  int q = n / k;
  int r = n % k;
  // f(kq + r) = f((k-1)q + r - 1)
  //           = f(kq + r - q - 1)
  r %= q + 1;
  if (r == 0) return q;
  return f(k * q + r - q - 1, k);
}

void test() {
  vector<int> dp(2500);

  int k = 4;

  for (int i = k; i < 2500; i++) {
    set<int> st;
    for (int j = 1; j <= i / k; j++) {
      st.insert(dp[i - j]);
    }
    while (st.count(dp[i])) dp[i]++;
  }

  for (int i = 0; i < 100; i++) {
    assert(dp[i] == f(i, k));
  }
}

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

  int res = 0;
  while (n--) {
    int a, k;
    cin >> a >> k;
    res ^= f(a, k);
  }

  if (res != 0) {
    cout << "Takahashi" << endl;
  } else {
    cout << "Aoki" << endl;
  }
}

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

int main() {
    int n;
    cin >> n;
    int a[n][3];
    rep (i, n) rep (j, 3) cin >> a[i][j];

    vector <int> scores(n, 0);
    rep (i, 3) {
        map <int, int> mp;
        rep (j, n) mp[a[j][i]]++;
        rep (j, n) {
            scores[j] += a[j][i] * (mp[a[j][i]] == 1);
        }
    }

    rep (i, n) cout << scores[i] << endl;
    return 0;
}


Measured memory_bytes: 3096
N, K = gets.chomp.split.map(&:to_i)

K2 = 2 * K
imos = Array.new(K2){Array.new(K, 0)}

N.times do |i|
    x, y, c = gets.chomp.split
    x = x.to_i % K2
    y = y.to_i % K2

    # change condition to
    # 0 <= x < KX, 0 <= y < KY, 'B'
    if c == 'B'
        if y >= K
            x = (x + K) % K2
            y -= K
        end
    else
        if y >= K
            y -= K
        else
            x = (x + K) % K2
        end
    end

    # imos count for each rectangle
    #
    # ..###.
    # ..*##.
    # ##...#    # main, left-bottom, right-bottom
    #
    # #...##
    # #...*#
    # .###..    # main, left-bottom, further-left
    
    # main
    imos[x][y] += 1
    imos[x + K][y] -= 1 if x < K

    # left-bottom
    if y > 0 && x > 0
        lbx = [0, x - K].max
        imos[lbx][0] += 1
        imos[x][y] += 1
        imos[x][0] -= 1
        imos[lbx][y] -= 1
    end

    # right-bottom
    if y > 0 && x < K
        imos[x + K][0] += 1
        imos[x + K][y] -= 1
    end

    # further-left
    if x > K + 1
        imos[0][y] += 1
        imos[x - K][y] -= 1
    end

end

(1...K2).each do |i|
    (0...K).each do |j|
        imos[i][j] += imos[i - 1][j]
    end
end

(0...K2).each do |i|
    (1...K).each do |j|
        imos[i][j] += imos[i][j - 1]
    end
end

max = 0
(0...K2).each do |i|
    (0...K).each do |j|
        max = imos[i][j] if max < imos[i][j]
    end
end

print max

Measured memory_bytes: 17788
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var dict = new Dictionary<int, int>();

            for (var i = 0; i < N; i++)
            {
                if (dict.ContainsKey(array[i]))
                    dict[array[i]]++;
                else
                    dict[array[i]] = 1;
            }

            var total = 0L;
            foreach (var d in dict)
            {
                if (d.Value >= d.Key) total += d.Value - d.Key;
                else total += d.Value;
            }

            Console.WriteLine(Math.Min(total, N));
        }
    }
}


Measured memory_bytes: 26720
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(n,v) cout<<#v<<":";for(int i=0;i<n;i++)cout<<v[i]<<" ";cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    ll n;cin>>n;
    vector<ll> idx(200010,-1),dp(n+1,0),a(n+1);
    rep(i,n){
        cin>>a[i];
    } 
    dp[0]=1ll;
    for(ll i=0;i<n;i++){
        ll clr=a[i];
        if(idx[clr]==-1||idx[clr]==i-1) dp[i+1]=dp[i];
        else dp[i+1]=(dp[i]+dp[idx[clr]+1])%mod;
        idx[clr]=i;
    }
    cout<<dp[n]%mod<<endl;
    return 0;
}

Measured memory_bytes: 4992
import collections
s = input()
l = len(s)
for i in range(l-1):
	t = s[i:i+3]
	c = collections.Counter(t)
	if s[i] == s[i+1]:
		print (i+1,i+2)
		exit()
	if c.most_common()[0][1] >= 2:
		print (i+1,i+3)
		exit()
print (-1,-1)

Measured memory_bytes: 3444
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
ll N;
  ll K;
  cin >>N>>K;
  vl x(N);
  rep(i,N) {
    cin >>x.at(i);
  }
  
 vl vec(N-K+1);
  
  rep(i,N-K+1) {

    ll a=abs(x.at(i))+abs(x.at(i+K-1)-x.at(i));
    ll b=abs(x.at(i+K-1))+abs(x.at(i+K-1)-x.at(i));
    ll c=min(a,b);
             vec.at(i)=c;
             }
             
             
             sort(all(vec));
             cout<<vec.at(0)<<endl;
             }
             
    
  
  
  

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

typedef long long ll;
const long long LINF = 1LL << 60;
const long long LMINF = 1LL << 63;
const int INF = 1 << 30;

#define REP(i,n) for(int i = 0;i < n;++i)
#define REPS(i,x) for(int i = 1;i <= (int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i >= 0;i--)
#define RREPS(i,x) for(int i=((int)(x));i > 0;i--)
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << ": " << x << "\n"

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



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

    int ans;
    if(x <= 599){
        ans = 8;
    }else if(x >= 600 && x <= 799){
        ans = 7;
    }else if(x >= 800 && x <= 999){
        ans = 6;
    }else if(x >= 1000 && x <= 1199){
        ans = 5;
    }else if(x >= 1200 && x <= 1399){
        ans = 4;
    }else if(x >= 1400 && x <= 1599){
        ans = 3;
    }else if(x >= 1600 && x <= 1799){
        ans = 2;
    }else if(x >= 1800 && x <= 1999){
        ans = 1;
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <string>
#include <math.h>
using namespace std;

int main (){
    string s;
    int x = 700;
    cin >> s;
    for(int i=0;i<s.length();i++){
        if(s[i]=='o'){
            x+=100;
        }
    }
    cout << x;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int w, h, x, y, r;
    scanf("%d%d%d%d%d", &w, &h, &x, &y, &r);
    if (0 <= x - r && x + r <= w && 0 <= y - r && y + r <= h) printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 2680
import java.util.Scanner;

public class Main {
            public static void main(String[] args) {
				Scanner sc = new Scanner(System.in);
				int a = sc.nextInt();
				int b = sc.nextInt();
				if (a < b) {
					System.out.println("a < b");
				} else if (a > b) {
					System.out.println("a > b");
				} else if (a == b) {
					System.out.println("a == b");
				}
			}
}



Measured memory_bytes: 26188
n = int(input())

a = list(map(int,input().split()))
b = sorted(a)
c = b.copy()
Mave = max(c)/2
del b[n-1]

hantei =[]
for i in b:
    hantei.append(abs(Mave-i))

print(str(max(c))+' '+str(b[hantei.index(min(hantei))]))


Measured memory_bytes: 14428
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

const ll inf = 1LL<<60;

// cnt[i] := n!が素数iを因数に何個もつか
int cnt[110];

// n!をi回以上割れる素因数の数
int num(int k){
    int res = 0;
    for(int i=2; i<110; ++i) if(cnt[i] >= k) ++res;
    return res;
}

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

    int n; cin >> n;

    for(int i=2; i<=n; ++i){
        int t = i;
        for(int j=2; j*j<=t; ++j){
            while(t%j == 0){
                ++cnt[j];
                t /= j;
            }
        }
        if(t != 1) ++cnt[t];
    }

    cout << num(74) + num(14)*(num(4)-1) + num(24)*(num(2)-1) + num(4)*(num(4)-1)/2*(num(2)-2) << endl;
    
    
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
using namespace std;
int main(){
  map<int,int> pset;
  int n,m,d,t;
  bool can=true;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> d;
    pset[d]++;
  }
  cin >> m;
  for(int i=0;i<m;i++){
    cin >> t;
    if(pset[t]>0){
      pset[t]--;
    }else{
      can=false;
    }
  }
  if(can) cout << "YES\n";
  else cout <<"NO\n";
}


Measured memory_bytes: 9600
#include <stdio.h>
#include <stdlib.h>
int num(int p,int q[]){
    int i,j,cnt=0;
    for(i=0;i<p-1;i++){
        for(j=i;j<p;j++){
            if(q[i]>q[j]) cnt++;
        }
        cnt*=p-i-1;
    }
    return cnt;
}
int main(void){
    int n,i,a[8],b[8];
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&a[i]);
    for(i=0;i<n;i++) scanf("%d",&b[i]);
    printf("%d",abs(num(n,a)-num(n,b)));
    return 0;
    
}


Measured memory_bytes: 128
N,M,L = map(int,input().split())

A = [list(map(int,input().split()))for i in range(N)]
B = [list(map(int,input().split()))for i in range(M)]
ANS = [[0]*L for i in range(N)]

for x in range(N):
    for y in range(L):
        for z in range(M):
            ANS[x][y]+=B[z][y]*A[x][z]
            
for row in range(N):
    print("%d"%ANS[row][0],end="")
    for col in range(1,L):
        print(" %d"%(ANS[row][col]),end="")
    print()


Measured memory_bytes: 7052
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;

int main()
{
	int n;
	cin >> n;
	vector<ll> A(n),B(n),Z(n);
	rep(i,n)cin >> A[i];
	rep(i,n)cin >> B[i];

	rep(i,n)Z[i]=A[i]-B[i];
	sort(ALL(Z));
	//rep(i,n)cout<<Z[i]<<ndl;
	int left=0,right=n-1;
	ll now = 0;
	int ans = 0;
	while(Z[left]<0)
	{
		if(now+Z[left]<0)
		{
			now += Z[right--];
			ans ++;
		}
		now +=Z[left++];
		ans ++;
	}
	if(now<0)
	cout<<-1<<endl;
	else
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

#define TIMES(i) while(i--)
#define REP(i, n) for ( int i = 0; i < n; i++ )

using namespace std;

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

    TIMES(n) {
        // ??\???
        double ax, ay, ar, bx, by, br;
        cin >> ax >> ay >> ar >> bx >> by >> br;

        // ?????¢????±???????
        double dis_x = abs(ax-bx),
            dis_y = abs(ay-by),
            dist = sqrt(dis_x * dis_x + dis_y * dis_y);

        // cout << dis_x << " " << dis_y << " " << dist << endl;

        // ??¢????????????
        if ( dist > ar + br ) {
            cout << 0;

        // a????????????????????????
        } else if ( dist + ar < br ) {
            cout << -2;

        // b????????????????????????
        } else if ( dist + br < ar ) {
            cout << 2;

        // ????????£?????????
        } else {
            cout << 1;
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  int cnt = 0;
  REP(i,n){
    if(i%2==0 && a[i]%2==1) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s,t; cin>>s>>t;
  int ans=s.size();
  for(int i=0;i<=s.size()-t.size();i++){
    string subStr=s.substr(i,t.size());
    int cnt=0;
    for(int j=0;j<t.size();j++){
      if(subStr[j]!=t[j]) cnt++;
    }
    ans=min(ans,cnt);
  }
  cout<<ans;
}

Measured memory_bytes: 3632
#include<stdio.h>
int main()
{
  int n,a,b,i,r,s,t=0;
  scanf("%d %d %d",&n,&a,&b);
   for(i=1;i<=n;i++)
{
    s=0;r=0;
    int temp=i;
    while(temp!=0)
    {
        r=temp%10;
        s=s+r;
        temp=temp/10;


    }
    if(s>=a&&s<=b)
    {
        t=t+i;
    }

}
printf("%d\n",t);
return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

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

    int mi = 1e9;
    for(ll i=1LL; i*i<=n;i++){
        if(n%i!=0) continue;
        int A=i,B=n/i;

        int cntA=0, cntB=0;
        while(A!=0) {
            A/=10;
            cntA++;
        }
        while(B!=0) {
            B/=10;
            cntB++;
        }
        mi = max(cntA, cntB);
    }
    cout << mi << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define MOD 1000000007

int main(){
    int N;
    cin >> N;
    string S1,S2;
    cin >> S1;
    cin >> S2;
    // aa -> true;
    // a
    // a -> false;
    vector<bool> pttn;
    int L = S1.length();
    REP(i,L){
        if(S1[i] == S2[i])
            pttn.push_back(false);
        else if(i+1 < L && S1[i] == S1[i+1]){
            pttn.push_back(true);
            i++;
        }
        else
            cout << "error" << endl;
    }

    int X = pttn.size();
    ull num = 1;
    bool type;
    REP(i,X){
        if(i == 0){
            if(pttn[i]){
                num *= 6;
                type = true;
            }
            else {
                num *= 3;
                type = false;
            }
        }    
        else{
            if(type){
                if(pttn[i]){
                    num *= 3;
                    type = true;
                }
                else{
                    num *= 1;
                    type = false;
                }
            }
            else{
                if(pttn[i]){
                    num *= 2;
                    type = true;
                }
                else{
                    num *= 2;
                    type = false;
                }
            }
        }
        num = num % MOD;
    }
    cout << num << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=998244353;
//const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
    ll n,d;
    cin>>n>>d;
    d*=d;
    int ans=0;
    for(int i=0;i<n;i++){
        ll a,b;
        cin>>a>>b;
        if(d>=a*a+b*b)ans++;
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 3648
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    cin >> a >> b;
    
    if (a == 0 ) {
        if (1868<=b && 1911>=b) cout<< "M"<<(-1868+b+1) << endl;
        else if (1912<=b && 1925 >=b) cout<<"T"<<(-1912+b+1)<< endl;
        else if (1926<=b && 1988>=b) cout <<"S"<<(-1926+b+1)<<endl;
        else cout <<"H"<<(-1989+b+1)<<endl;
    }
    
    else if(a == 1)  cout << 1867+b <<endl;
    else if(a == 2)  cout <<  1911+b <<endl;
    else if(a == 3)  cout << 1925+b <<endl;
    else cout << 1988+b <<endl;
    
    
    }


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#include <stdio.h>
#define ff(i,x,y)for(int i=x;i<y+1;i++)
#define fs(i,x,y)for(int i=x;i>y-1;i--)
#define all(x) x.begin(),x.end()
#define Ins(x) inserter(x,x.begin())
//set<int>::iterator it
using namespace std;
typedef long long ll;
ll n, dp[310][310], ans;
int main()
{
	scanf("%lld", &n);
	ff(i, 1, n)
	{
		ff(j, 1, n)
		{
			scanf("%lld", &dp[i][j]);
			//ans+=dp[i][j];
		}
	}
	int pan = 1;
	ff(i, 1, n)
	{
		ff(j, 1, n)
		{
			if (i == j)
				continue;
			int flag = 1;
			ff(k, 1, n)
			{
				if (k == i || k == j)
					continue;
				if (dp[i][j]>dp[i][k] + dp[k][j])
				{
					pan = 0;
					break;
				}
				else if (dp[i][j] == dp[i][k] + dp[k][j])
					flag = 0;
			}
			if (pan == 0)
				break;
			if (flag == 1)
				ans += dp[i][j];
		}
		if (pan == 0)
			break;
	}
	if (pan == 0)
		printf("-1");
	else
		printf("%lld\n", ans / 2);
	return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<stack>
#include<set>
using namespace std;
#define pb push_back
#define POP pop_back()
#define ll long long
#define db double
#define POP pop_back()
#define endl '\n'
#define PII pair<int,int>
#define FI first
#define SE second
#define VI vector<int>
#define QI queue<int>
#define SI stack<int>
#define debug cout<<"debug"<<endl;
#define PLL pair<ll,ll>
#define PDD pair<double,double>
#define ULL unsigned long long
#define fo(i,a,b) for (int i=a;i<=b;++i)
#define fd(i,a,b) for (int i=a;i>=b;--i)
#define mem(x,a) memset(x,a,sizeof(x))
const int maxn = 2e5 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int main(){
	int x;cin >> x;
	ll ans = x/500;
	ans *= 1000;
	x -= x/500 * 500;
	ans += x/5*5;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) a[i] = scanner.nextInt();

    if (possible(a)) System.out.println("Yes");
    else System.out.println("No");
  }

  private static boolean possible(int[] a) {
    Map<Integer, Integer> freq = new HashMap<>();
    for (int n : a) freq.put(n, freq.getOrDefault(n, 0) + 1);

    Integer[] keys = freq.keySet().toArray(new Integer[]{});
    if (keys.length == 1) return keys[0] == 0;

    int p = keys[0];
    int c = keys[1];
    dec(freq, c);
    while (!freq.isEmpty()) {
      int n = p ^ c;
      if (!dec(freq, n)) return false;
      p = c;
      c = n;
    }
    return true;
  }

  private static boolean dec(Map<Integer, Integer> map, int key) {
    int f = map.getOrDefault(key, 0);
    if (f == 0) return false;
    if (f == 1) map.remove(key);
    else map.put(key, f - 1);
    return true;
  }
}


Measured memory_bytes: 54212
def NotsoDiverse(n , k , al):

    lis = [0]*(n + 1)

    for i in range(n):
        lis[al[i]] += 1

    lis.sort(reverse=True)

    ans = sum(lis[k:])
    return ans

def main():
    n , k = map(int , input().split())
    al = list(map(int , input().split()))
    print(NotsoDiverse(n , k , al))

if __name__ == '__main__':
    main()


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

typedef long long ll;
ll memo[200];

int N;
int A;
int ans = 10000000;

int main()
{
    memo[0] = 1;
    for(int i = 1;memo[i - 1] < 1000000000;i++)
    {
        memo[i] = memo[i - 1] * 2LL;
    }

    cin >> N;
    for(int i = 0;i < N;i++)
    {
        cin >> A;
        int j;
        for(j = 0;j < 200;j++)
        {
            if(A % memo[j] != 0) break;
        }
        j--;
        ans = min(ans,j);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  bool ans = 1;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  for(int i=0;i<n;i++){
    if(a.at(i)%2 == 0 && a.at(i)%3 != 0 && a.at(i)%5 != 0){
      ans = 0;
      break;
    }
  }
  if(ans){
    cout << "APPROVED" << endl;
  }
  else{
    cout << "DENIED" << endl;
  }
}

Measured memory_bytes: 3648
p = 1000000000 + 7

pdp = [[0 for _ in range(2001)] for _ in range(2001)]
pdp[0][0] = 1
for i in range(1, 2001):
  for j in range(0, i + 1):
    if j - 1 >= 0:
      pdp[i][j] = pdp[i-1][j] + pdp[i-1][j-1]
    else:
      pdp[i][j] = pdp[i-1][j]

N, K = map(int, input().split())

for i in range(1, K+1):
  ans = pdp[N-K+1][i] * pdp[K-1][i-1]
  print(ans % p)

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

void Main()
{
	int N; cin >> N;
	vector<int> L(2 * N);
	rep(i, 2 * N) cin >> L[i];
	sort(ALL(L));
	int res = 0;
	rep(i, 2 * N) {
		if (i % 2 == 1) continue;
		res += L[i];
	}
	cout << res << endl;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 256
h, w = [int(x) for x in input().split()]
grid = [[b for b in input()] for i in range(h)]
result = []
for i in range(h):
    row = ''
    for j in range(w):
        if grid[i][j] == '#':
            row += '#'
        else:
            row += str(sum([area[max(0, j - 1):min(w, j + 2)].count('#')
                            for area in grid[max(0, i - 1):min(h, i + 2)]]))
    result.append(row)
print('\n'.join(result))


Measured memory_bytes: 3064
#include<cstdio>
int main(){
	int a,b;
	char c[5]={0};
	while(~scanf("%d",&a))
	{
		getchar();
		scanf("%c",c);
		scanf("%d",&b);
		if(c[0]=='+'){
			printf("%d\n",a+b);
		}else {
			printf("%d\n",a-b);
		}
	}
	return 0;
}

Measured memory_bytes: 128
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n = int(input())
  lc = list(input().strip())
  
  i = 0
  j = n - 1
  cnt = 0
  while i < j:
    while i < n:
      if lc[i] == 'R':
        i += 1
      else:
        break
    while 0 < j:
      if lc[j] == 'W':
        j -= 1
      else:
        break        
    if i < j:
      cnt += 1
    i += 1
    j -= 1
    
  print(cnt)

if __name__=='__main__':
  main()



Measured memory_bytes: 10636
import re
N,K = map(int,input().split())
S = input()

O = re.findall(r"(R+|L+)",S)
for j in range(min(len(O)//2,K)):
    k = j * 2 + 1
    OO = O[k]
    O[k] = ("R" if OO[0] == "L" else "L")*len(OO)

Sdash = ''.join(O)
def happy(i):
    j = i + (-1 if Sdash[i] == "L" else 1)
    return (0 <= j < N) and (Sdash[i] == Sdash[j])

print(sum(map(happy,range(N))))

Measured memory_bytes: 5272
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int h,w;
  cin>>h>>w;
  vector<string> a(h);
  REP(i,h){
    cin>>a[i];
  }
  int x=0,y=0;
  int dx[]={1,0,-1,0};
  int dy[]={0,1,0,-1};
  bool down=false,right=false;
  bool flag=true;
  int nx,ny;
  set<pair<int,int> > path;
  path.insert(make_pair(0,0));
  while(x != h-1 || y != w-1){
    down = false;right=false;
    REP(i,4){
      nx = x+dx[i];
      ny = y+dy[i];
      if(0<=nx && nx<h && 0<=ny && ny<w){
        if(a[nx][ny]=='.'){
          continue;
        }else{
          if(i>=2){
            if(path.find(make_pair(nx,ny))!=path.end()){
              continue;
            }else{
              flag = false;
              break;
            }
          }else{
            if(i==0){
              down = true;
            }else{
              right = true;
            }
          }
        }
      }
    }
    if(!flag){
      break;
    }
    if((down && right) || (!down && !right)){
      flag = false;
      break;
    }else if(down){
      path.insert(make_pair(x+1,y));
      x = x+1;
    }else{
      path.insert(make_pair(x,y+1));
      y = y+1;
    }
  }
  if(flag){
    if(a[h-1][w-2]=='#' && a[h-2][w-1]=='#'){
      cout<<"Impossible"<<endl;
    }else{
      cout<<"Possible"<<endl;
    }
  }else{
    cout<<"Impossible"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node { int p, l, r; };
struct Node T[MAX];
int n;

void preParse(int u) {
	if (u == NIL) return;
	printf(" %d", u);
	preParse(T[u].l);
	preParse(T[u].r);
}
void inParse(int u) {
	if (u == NIL)return;
	inParse(T[u].l);
	printf(" %d", u);
	inParse(T[u].r);
}
void postParse(int u) {
	if (u == NIL) return;
	postParse(T[u].l);
	postParse(T[u].r);
	printf(" %d", u);
}

int main() {
	int i, v, l, r, root;
	scanf("%d", &n);
	for (i = 0; i < n; i++)T[i].p = NIL;
	for (i = 0; i < n; i++) {
		scanf("%d %d %d", &v, &l, &r);
		T[v].l = l;
		T[v].r = r;
		if (l != NIL) T[l].p = v;
		if (r != NIL) T[r].p = v;
	}
	for (i = 0; i < n; i++) if (T[i].p == NIL)root = i;
	printf("Preorder\n");
	preParse(root);
	printf("\n");
	printf("Inorder\n");
	inParse(root);
	printf("\n");
	printf("Postorder\n");
	postParse(root);
	printf ("\n");
	return 0;
}


Measured memory_bytes: 2720
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007
#define INF 1000000009
typedef long long int lli;

int main(void) {
  int n, m;
  scanf("%d %d", &n, &m);

  printf("%d\n", (n-1) * (m-1));
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    for(int i = 1;i <= 50000; i++){
        double p = i * 1.08;
        int q = (int) p;
        if(n == q){
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 3564
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
ret, tmp_temp = 1, h[0]
for i, height in enumerate(h):
    x = t - height*0.006
    if abs(a-x) <= abs(a-tmp_temp):
        tmp_temp = x
        ret = i+1
print(ret)  

Measured memory_bytes: 62696
#include<stdio.h>
int main()
{
    int a,b,c,d,area1,area2;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    area1=a*b;
    area2=c*d;
    if(area1>=area2)
    {
        printf("%d\n",area1);
    }
    if(area2>area1)
    {
        printf("%d\n",area2);
    }

    return 0;

}


Measured memory_bytes: 1732
import os
import heapq
import sys,threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10**5)
from io import BytesIO, IOBase
def gcd(a,b):
    if b==0:

        return a
    else:
        return gcd(b,a%b)
def power(x, p,m):
    res = 1
    while p:
        if p & 1:
            res = (res * x) % m
        x = (x * x) % m
        p >>= 1
    return res
def inar():
    return [int(k) for k in input().split()]

def lcm(num1,num2):
    return (num1*num2)//gcd(num1,num2)

def main():
    n=int(input())
    st1,st2=input().strip().split(" ")
    res=[]
    for i in range(n):
        res.append(st1[i])
        res.append(st2[i])
    print("".join(res))




BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()
    #threadin.Thread(target=main).start()


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

using namespace std;


int main()
{
  int P, Q;
  cin >> P >> Q;
  Q /= __gcd(P, Q);
  long long ret = 1;
  for(int i = 2; i * i <= Q; i++) {
    if(Q % i == 0) {
      ret *= i;
      while(Q % i == 0) Q /= i;
    }
  }
  cout << ret * Q << endl;
}


Measured memory_bytes: 3100
/**/

#include <bits/stdc++.h>

using namespace std;

int N, M, P;
vector<tuple<int, int, long long>> grafo;
long long resp;

void BellmanFord(int inicio)
{
     vector<long long> distancia(N + 1, LONG_LONG_MAX);
     distancia[inicio] = 0;

     //Verifica o looping negativo (não há máximo)
     vector<bool> verifica(N + 1, false);
     verifica[N] = true;

     int primeiro, segundo;
     long long moedas;

     //Verifica o máximo possível, exceto os casos de looping negativo
     for (int i = 1; i < N; i++)
     {
          for (int j = 0; j < M; j++)
          {
               tie(primeiro, segundo, moedas) = grafo[j];

               if (distancia[primeiro] != LONG_LONG_MAX &&
                   distancia[primeiro] + moedas < distancia[segundo])
               {
                    distancia[segundo] = distancia[primeiro] + moedas;
               }

               //Salvando o vértice percorrido
               if(verifica[segundo] == true)
               {
                    verifica[primeiro] = true;
               }
          }
     }

     //Salvando a resposta máxima atual
     resp = max((long long)0, -distancia[N]);

     //Percorrendo o grafo e verificando se há o looping negativo
     for(int i = 0; i < M; i++)
     {
          tie(primeiro, segundo, moedas) = grafo[i];

          if (distancia[primeiro] != LONG_LONG_MAX &&
              distancia[primeiro] + moedas < distancia[segundo] &&
              verifica[segundo] == true)
          {
               //Looping negativo = impossível
               resp = -1;
               break;
          }     
     }
     

}

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

     for (int i = 0; i < M; i++)
     {
          int primeiro, segundo;
          long long moedas;
          cin >> primeiro >> segundo >> moedas;

          grafo.push_back({primeiro, segundo, P - moedas});
     }

     BellmanFord(1);
     cout << resp << endl;

     return 0;
}

Measured memory_bytes: 3752
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct node{
  struct node *r;
  struct node *l;
  struct node *p;
  int key;
};
typedef struct node * Node;
#define NIL NULL
Node root;
Node min(Node x);
Node max(Node x);
Node search(Node u, int k);
Node successor(Node x);
void delete(Node z){};
void insert(int k);
void inorder(Node u);
void preorder(Node u);
int main(){
  int n,i,x;
  Node t;
  char com[20];;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",com);
    if (com[0]=='f'){
      scanf("%d",&x);
       t= search(root,x);
      if(t!=NIL) printf("yes\n");
      else printf("no\n");
    }
    else if(com[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }
    else if(com[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    
    else if(com[0]=='d'){
      scanf("%d",&x);
      delete(search(root,x));
    }
  }
  return 0;
}
Node min(Node x){
  while(x->l!=NIL){
    x= x->l;}
  return x;
}
Node max(Node x){
  while(x->r!=NIL){
    x=x->r;
  }
  return x;
}
Node search(Node u,int k){
  while(u!=NIL &&u->key!=k){
    if (k>u->key){
      u=u->r;
    }
    else u=u->l;
  }
  return u;
}
Node successor(Node x){
  Node y;
  if(x->r!=NIL) return min(x->r);
  y=x->p;
  while(y!=NIL && x==y->r){
    x=y;
    y=y->p;
  }
  return x;
}
void insert (int k){
  Node y= NIL;
  Node x=root;
  Node z;
  
  z=malloc(sizeof(struct node));
  z->key=k;
  z->l=NIL;
  z->r=NIL;
  
  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->l;
    }  else x=x->r;
  }
  z->p=y;
  if(y==NIL) root=z;
  else if(z->key<y->key){
    y->l=z;
  }
  else y->r=z;
}

void inorder(Node u){
  if(u==NIL )return ;
  inorder(u->l);
  printf(" %d",u->key);
  inorder(u->r);
}

void preorder(Node u){
  if(u==NIL)return ;
  printf(" %d",u->key);
  preorder(u->l);
  preorder(u->r);
}



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

int main(void) {
	int n; cin >> n;
	int a[n], i, count = 0, m=1; bool flag = false;
	for (i = 0; i < n; i++) {
		cin >> a[i];
	}

	for (i = 0; i < n;i++) {
		m = a[m-1];
		count += 1;
		if (m == 2 && flag == false) { cout << count << endl; flag = true; }
	}

	if (flag==false) { cout << "-1" << endl; }

	return 0;
}


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

const ll NMAX = 1e5;

vector<vector<ll>> g(NMAX);
vector<ll> len(NMAX, -1);

ll dfs(ll now) {
  if (len[now] != -1) return len[now];

  ll result = 0;
  for (auto next : g[now]) {
    result = max(result, dfs(next) + 1);
  }
  len[now] = result;
  return result;
}

int main() {
  ll n, m;
  cin >> n >> m;

  ll x, y;
  for (ll i = 0; i < m; i++) {
    cin >> x >> y;
    x--; y--;
    g[x].push_back(y); 
  }

  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    ans = max(ans, dfs(i));
  }

  cout << ans << endl;
}


Measured memory_bytes: 8576
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

ll n, W, w[105], v[105];
unordered_map<ll, ll> dp[105];

ll f(int num, ll ww) {
	if(ww < 0) return -INF;
	if(num >= n) return 0;
	if(dp[num].count(ww)) return dp[num][ww];
	auto& memo = dp[num][ww];
	return memo = max(f(num+1, ww), f(num+1, ww-w[num]) + v[num]);
}

signed main(void)
{
	cin >> n >> W;
	REP(i, n) cin >> w[i] >> v[i];
	cout << f(0, W) << endl;

	return 0;
}


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

const int Nmax=200010;

int main() {
	int c[3][3];
	for(int i=0;i < 3;i++){
		for(int j=0;j < 3;j++){
			cin >> c[i][j];
		}
	}
	
	for(int i=0;i < 2;i++){
		set<int> set;
		for(int j=0;j < 3;j++){
			set.insert(c[j][i]-c[j][i+1]); //J=0 b1がすべて同じか調べる
		}					//b1,b2,b3が良ければa1,a2,a3も条件を満たす
		if(set.size() >= 2){ cout << "No" << endl; return 0;}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
N, x = map(int, input().split())
a = [int(i) for i in input().split()]

ans = 0
for i in range(1, N):
    candy = a[i-1] + a[i]
    if candy > x:
        ans += candy - x
        tmp = a[i]
        if tmp >= candy - x:
            a[i] -= candy - x
        else:
            a[i] = 0

print(ans)

Measured memory_bytes: 14472
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto L = readln.chomp.to!int;

    if (L <= 60) {
        writeln(2, " ", L);
        foreach (l; 0..L) {
            writeln("1 2 ", l);
        }
        return;
    }

    int[] AS, BS, CS;

    int k, l = 1;
    while (l*2 <= L) {
        ++k;
        l *= 2;
    }
    int x = 1;
    foreach (_; 0..k) {
        l /= 2;
        AS ~= [x, x];
        BS ~= [x+1, x+1];
        CS ~= [l, 0];
        x += 1;
    }

    auto d = 2^^k;
    auto r = L - d;
    while (r) {
        if (r == 1) {
            AS ~= 1;
            BS ~= k+1;
            CS ~= L-1;
            break;
        }
        l = 2;
        foreach_reverse (y; 1..k+1) {
            if (l*2 > r) {
                AS ~= 1;
                BS ~= y;
                CS ~= d;
                r -= l;
                d += l;
                break;
            }
            l *= 2;
        }
    }

    writeln(k+1, " ", AS.length);
    foreach (i; 0..AS.length) writeln(AS[i], " ", BS[i], " ", CS[i]);
}

Measured memory_bytes: 2676
#include"bits/stdc++.h"
using namespace std;

//typedef
//------------------------------------------
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())
#define COUT(x) cout<<x<<endl

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
const ULL INF = 1e18;
const int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };

//function
//--------------------------------------------
LL gcd(LL, LL);
bool isEven(LL);
void coutY();
void coutN();
LL ave(LL, LL);

int main() {
	string s, t; cin >> s >> t;
	reverse(t.begin(), t.end());
	int ans = 0;
	REP(i, 3) {
		if (s[i] == t[i])ans++;
	}
	if (ans == 3)cout << "YES";
	else cout << "NO";
}

LL gcd(LL a, LL b) {
	if (a == 0 || b == 0)return 0;
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	else gcd(b, a % b);
}
bool isEven(LL a) {
	return !((bool)(a % 2));
}
void coutY() {
	cout << "Yes" << endl;
	return;
}
void coutN() {
	cout << "No" << endl;
	return;
}
LL ave(LL a, LL b) {
	return (a + b) / 2;
}

Measured memory_bytes: 256
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1e9+7;



int main(){

int A,B,C,X,count=0;
cin>>A>>B>>C>>X;
rep(i,A+1)rep(j,B+1)rep(k,C+1)if(i*500+j*100+k*50==X)count++;
cout<<count<<endl;
return 0;
}

Measured memory_bytes: 3544
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int a[100];
int n, ans = 0;
int main(){
	cin >> n;
	n *= 2;
	for(int i = 0;i < n;i++)cin >> a[i];
	sort(a, a + n);
	for(int i = 0;i < n;i += 2){
		ans += a[i];
	}
	cout << ans << endl;
	return 0;
}

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

#define SZ 55
char s[SZ], st[SZ];

int main(){

    int i, len, len2;
    int siz;

    scanf("%s %s", s, st);
    //puts(s);
    //puts(st);
    len = strlen(s);
    len2 = strlen(st);

    if(len > len2){
        siz = len;
    }else siz = len2;

    for(i = 0; i < siz; i++){
        if(s[i]) putchar(s[i]);
        if(st[i]) putchar(st[i]);
    }

    putchar('\n');

    return 0;

}


Measured memory_bytes: 256