akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 1000000000 + 7;

bool gt(pii x, pii y){
  return x.first > y.first;
}

int main(){
  cout << setprecision(10);
  priority_queue<int> q;

  int N,M;
  cin >> N >> M;

  vector<pii> v(N);
  for(int i = 0; i < N; i++){
    int tmp1,tmp2;
    cin >> tmp1 >> tmp2;
    v.at(i) = make_pair(tmp1, tmp2);
  }

  sort(v.rbegin(), v.rend(), gt);
  // cerr << v.at(0).first << endl;
  ll ans = 0;
  int index = 0;
  for(int i = 1; i <= M; i++){
    while(index < N && v[index].first <= i ){
      q.push(v[index].second);
      index++;
    }
    if(!q.empty()){
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
}


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

int main(){
 	
  int n,c;
  cin>>n>>c;
  
  long long w[n+1],v[n+1];
  
  for(int i=1;i<=n;i++)
    cin>>w[i]>>v[i];
  
  long long dp[n+1][100005];

  for(int i=0;i<=n;i++){
   for(int j=0;j<=100000;j++){
    if(j == 0){
      dp[i][j] = 0;
      continue;
    }
   	if(i == 0){
     dp[i][j] = 1000000000001;
     continue;
    }
    dp[i][j] = dp[i-1][j];
    if(v[i]<=j && dp[i-1][j-v[i]] != 1000000000001)
      dp[i][j] = min(dp[i][j],w[i]+dp[i-1][j-v[i]]);
   }
  }

  int ans = 0;
  
  for(int i=0;i<=100000;i++)
     if(dp[n][i]<=c)
         ans = i;
         
  cout<<ans;                        
  
}


Measured memory_bytes: 79104
#include <iostream>
#include <algorithm>
#include <complex>
#include <cstdio>
#define EPS 1e-10
#define EQ(a,b) (abs(a - b) < EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
using namespace std;

typedef complex<double> P;

double cross (P a, P b) {
    return (a.real() * b.imag() - a.imag() * b.real());
}

int is_intersected_ls(P a1, P a2, P b1, P b2) {
    return ( cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS ) &&
        ( cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS );
}

int main ()
{
    double ax, ay, bx, by, cx, cy, dx, dy;
    while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &ax, &ay, &bx, &by, &cx, &cy, &dx, &dy) != EOF) {
        P a = P(ax, ay);
        P b = P(bx, by);
        P c = P(cx, cy);
        P d = P(dx, dy);

        if (EQ(is_intersected_ls(a, c, d, b), 0.0)) cout << "NO" << endl;
        else cout << "YES" << endl;
    }

    return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
int main(void) {
    int N;
    cin >> N;
    double p[N+1][N+1],in;
    cin >> in;
    p[1][0]=1.0-in;
    p[1][1]=in;
    for(int j=2;j<=N;j++){
        p[1][j]=0.0;
    }
    for(int i = 2; i <= N; i++) {
        cin >> in;
        p[i][0]=p[i-1][0]*(1.0-in);
        for(int j=1;j<=N;j++){
            if(j<=i){
                p[i][j]=p[i-1][j-1]*in+p[i-1][j]*(1.0-in);
            }
            else{
                p[i][j]=0.0;
            }
        }
    }
    double answer=0.0;
    for(int i=0;i<=N;i++){
        if(i>N/2){
        answer += p[N][i];
        }
    }
    cout << setprecision(15) << answer << endl;
    return 0;
}


Measured memory_bytes: 70528
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, K;
int x[110];

signed main() {
    cin >> N >> K;
    int ans = 0;
    rep(i,0,N) {
        cin >> x[i];
        ans += 2 * min(x[i], K - x[i]);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

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

    long long X, Y, n = 0;
    cin >> X >> Y;

    while (X <= Y) {
        X *= 2;
        n++;
    }

    cout << n << endl;

    return 0;
}


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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < (n); i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define REP(i, vec) for(auto i = vec.begin(); i != vec.end(); ++i)

const int mod = 1000000007;
const int inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

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; }
template<class T> inline T GCD(T a, T b) { return b ? GCD(b, a % b) : a; }
template<class T> inline T LCM(T a, T b) { return (a + (b - 1)) / b; }

int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};

struct combination {
    vector<mint> fact, ifact;
    combination(int n) :fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
};

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

    combination c(n);
    for (int i = 1; i <= k; ++i) {
        if (i > n - k + 1) {
            cout << 0 << endl;
        }
        else {
            mint ans = c(n - k + 1, n - k - i + 1) * c(k - 1, k - i);
            cout << ans.x << endl;
        }
    }
}

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

#define ll long long int
#define mod 1000000007

using namespace std;


int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int a, b;
    cin >> a >> b;
    if(2 * b >= a)
    cout << 0;
    else
    cout << a - 2 * b;
}









Measured memory_bytes: 3588
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int h, w;
		int i = 0;
		int j = 0;
		h = sc.nextInt();
		w = sc.nextInt();
		String str[] = new String[h];

		for (i = 0; i < h; i++)
			str[i] = sc.next();

		for (i = 0; i < h + 2; i++) {
			for (j = 0; j < w + 2; j++) {
				if (i == 0 || i == h + 1)
					System.out.print("#");
				else {
					if (j == 0) {
						System.out.print("#");
						System.out.print(str[i - 1]);
					}
					if (j == w + 1)
						System.out.print("#");
				}
			}
			System.out.println();
		}

	}

}


Measured memory_bytes: 22788
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>
#include <map>   
#include <stdio.h>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define PB push_back
#define ull unsigned long long
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define sortR(a,b) sort(a, b, greater<int>())

using namespace std;

//最大公約数

ll mod = pow(10, 9) + 7;


int main() {
	int N, H,i,a,b,a_max=0,ans=0;
	cin >> N >> H;
	vector<int> B(100000);
	REP(i, N) {
		cin >> a >> b;
		a_max = max(a_max, a);
		B[i] = b;
	}
	sort(B.begin(), B.begin() + N);
	i = N - 1;
	int sum = 0;
	while (i>=0) {
		if (sum >= H) {
			cout << ans << endl;
			return 0;
		}
		if (B[i] > a_max) {
			sum += B[i];
			ans++;
		}
		else
			break;
		i--;
	}
	cout << ans + (H - sum+a_max-1) / a_max << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int n;
ll m;
int d[10000], p[10000];
int main() {
    while(scanf("%d%lld",&n,&m)&&(n!=0||m!=0)) {
        for (int i=0; i<n; i++) scanf("%d%d",&d[i],&p[i]);
        vector<P> v;
        for (int i=0; i<n; i++) v.push_back(P(p[i], d[i]));
        sort(v.rbegin(), v.rend());
        int res = 0;
        for (int i=0; i<n; i++) {
            if (v[i].second <= m) m -= v[i].second;
            else {
                res += (v[i].second - m) * v[i].first;
                m = 0;
            }
        }
        printf("%d\n",res);
    }
}

Measured memory_bytes: 1396
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

int main() {
    string S;
    cin >> S;

    int n, s, w, e;
    n = s = w = e = 0;
    for (char c : S) {
        if (c == 'N') {
            ++n;
        } else if (c == 'S') {
            ++s;
        } else if (c == 'W') {
            ++w; 
        } else if (c == 'E') {
            ++e;
        }
    }

    if ((n + s == 0 || n * s > 0) && (w + e == 0 || w * e > 0)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;



void add1_2(int* x) {
    *x += 2;
}

void add2_1(int* x, int* y) {
    *x += 1;
    *y += 1;
}

int main() {

    int m = 0;

    int A, B, C;
    cin >> A >> B >> C;


    bool A_Even, B_Even, C_Even;

    if (A % 2 == 0) A_Even = true;
    else  A_Even = false;

    if (B % 2 == 0) B_Even = true;
    else B_Even = false;

    if (C % 2 == 0) C_Even = true;
    else  C_Even = false;

    if ((A_Even == B_Even) & (C_Even == B_Even) & (A_Even == C_Even)) {
        ;
    } else if (A_Even == B_Even) {
        add2_1(&A, &B);
        m += 1;
    } else if (A_Even == C_Even) {
        add2_1(&A, &C);
        m += 1;
    } else {
        add2_1(&B, &C);
        m += 1;
    }

    if ((B <= A) & (C <= A)) {
        m += (A - B)/2;
        m += (A - C)/2;
    } else if ((A <= B) & (C <= B)) {
        m += (B - A)/2;
        m += (B - C)/2;
    } else {
        m += (C - A)/2;
        m += (C - B)/2;
    }

    cout << m << "\n";

    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

const ll INFLL = (1ll << 60); 

vector<ll> solve(const vector<ll> &X){
	ll N = X.size();
	vector<ll> A(N);
	REP(i, N) A[i] = X[i];
 	stack<pll> st;
 	st.push({N-1, INFLL});
	vector<ll> res(N+1, 0);

	for(int i=N-2;i>=0;i--){
		ll cnt = res[i+1];
		if(A[i] <= A[i+1]){
			ll tmp = A[i];
			ll yoyu = 0;
			while(1){
				if(tmp*4 > A[i+1]) break;
				tmp *= 4;
				yoyu++;
			}
			if(yoyu > 0)st.push({i, yoyu});
		}else{
			ll tmp = A[i+1];
			ll tarinai = 0;
			while(1){
				if(tmp >= A[i]) break;
				tmp *= 4;
				tarinai++;
			}
			while(tarinai > 0){
				cnt += (st.top().first - i);
				st.top().second--;
				if(st.top().second == 0) st.pop();
				tarinai--;
			}
		}
		res[i] = cnt;
	}
	return res;
}

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

    ll N;
    cin >> N;
    vector<ll> A(N), B(N);
    REP(i, N) cin >> A[i];
    REP(i, N) B[i] = A[N-i-1];

    auto jun = solve(A);
    auto gyaku = solve(B);
    ll res = INFLL;
    //cout << jun << endl;
    //cout << gyaku << endl;
    REP(i, N+1){
    	ll tmp = 2*jun[i] + 2*gyaku[N-i] + i;
    	res = min(res, tmp);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 8036
import heapq
N, M = map(int, input().split())
lst = []
for _ in range(N):
    A, B = map(int, input().split())
    lst.append([A, -B])
lst.sort()

ans = 0
index = 0
hq = []
for i in range(M):
    while index < N and lst[index][0] <= i + 1:
        heapq.heappush(hq, lst[index][1])
        index += 1
    #heaqpはソートではないから順番は降順にはならないこともあるが最小値は先頭に来る
    if len(hq) > 0:
        ans -= heapq.heappop(hq)
    # print ('ans, i', ans, i)
print(ans)

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// }}} 1

int main() {

    int n,k,x,y;
    Scd2(n,k);
    Scd2(x,y);

    int ans;
    ans = (n>k) ? ( x * k + (n-k) * y ) : x * n;

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

    return 0;
}



Measured memory_bytes: 256
let () =
  let d = Array.make 4 0 in
  for i = 0 to 2 do
    Scanf.scanf "%d %d\n" @@ fun a b ->
      d.(a - 1) <- 1 + d.(a - 1);
      d.(b - 1) <- 1 + d.(b - 1)
  done;
  print_endline @@ if
    List.length (List.filter (fun d -> d mod 2 = 1) (Array.to_list d)) = 2
  then "YES"
  else "NO"


Measured memory_bytes: 2432
import sys
from pprint import *
N,K=map(int,input().split())
input=sys.stdin.readline
dpb=[[0 for _ in range(2*K+1)] for _ in range(2*K+1)]
def getmatnum(x1,y1,x2,y2,mat):#左上を(x1,y1)右下を(x2,y2)にしてmatの中の左上~右下の領域の和を算出
    if (x2==0)or(y2==0):
        return 0
    else:
        if (x1==-1):
            x1=0
        if (y1==-1):
            y1=0
        return mat[y2][x2]-mat[y1][x2]-mat[y2][x1]+mat[y1][x1]

for i in range(N):
    x,y,c=input().split()
    x=int(x)
    y=int(y)
    #print(x,y,c)
    if c=="W":
        dpb[(y%(2*K))+1][((x+K)%(2*K))+1]=dpb[(y%(2*K))+1][((x+K)%(2*K))+1]+1
    else:
        dpb[(y % (2*K))+1][(x % (2*K))+1] = dpb[(y % (2*K))+1][(x % (2*K))+1] + 1
#pprint(dpw)
#pprint(dpb)

for i in range(1,2*K+1):
    for j in range(1,2*K+1):
        dpb[i][j]=dpb[i][j-1]+dpb[i][j]

for i in range(1,2*K+1):
    for j in range(1,2*K+1):
        dpb[i][j]=dpb[i-1][j]+dpb[i][j]

ans=0
for i in range(K):
    for j in range(K):
        k=i+K
        l=j+K
        b1=getmatnum(-1,-1,i,j,dpb)+getmatnum(k,-1,2*K,j,dpb)+getmatnum(i,j,k,l,dpb)+getmatnum(-1,l,i,2*K,dpb)+getmatnum(k,l,2*K,2*K,dpb)
        b2=getmatnum(i,-1,k,j,dpb)+getmatnum(-1,j,i,l,dpb)+getmatnum(k,j,2*K,l,dpb)+getmatnum(i,l,k,2*K,dpb)
        ans=max(ans,b1,b2)

        #print(i,j,k,l)
print(ans)
        #
#pprint(dpw)
#pprint(dpb)

Measured memory_bytes: 109560
// https://atcoder.jp/contests/practice2/tasks/practice2_a?lang=ja

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

int main()
{
    long n, q;
    cin >> n >> q;

    dsu d(n);

    for (long i = 0; i < q; ++i)
    {
        long t, u, v;
        cin >> t >> u >> v;
        if (t == 0)
        {
            d.merge(u, v);
        }
        else
        {
            cout << (d.same(u, v) ? 1 : 0) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3948
import Text.Printf
main = do
  str<-getLine
  let [h,w]=map read $ words $ str::[Int]
  if(h==0 && w==0)
  then return ()
  else do
    putStrLn $ replicate w '#'
    putStr $ concat $ replicate (h-2) $ "#"++(replicate (w-2) '.')++"#\n"
    putStrLn $ replicate w '#'
    putStrLn ""
    main

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

int main(){

  int sum;
  vector<int> vec(3);
  for(int i=0;i<3;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  sum =vec.at(0) + vec.at(1) + vec.at(2)*10;
  cout << sum << endl;
}
    

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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cout.tie(0);
	
	int a, b;
	cin >> a >> b;
	int c = b - a;
	cout << (1 + c) * c / 2 - b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k; cin >> n >> k;
    int ans = 0;
    rep(i,n) {
        int num; cin >> num;
        if(num>=k) ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <queue>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <set>
#include <map>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repl(i, n) for(LL i = 0; i < (LL)(n); i++)

int main(void){
  LL N;

  cin >> N;
  int sqrtN = sqrt(N);
  int b = N;

  for (LL i = 1; i <= sqrtN; i++) {
    if (N % i == 0) {
      b = N / i;
    }
  }

  cout << int(log10(b)) + 1 << '\n';

  return 0;
}

Measured memory_bytes: 256
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    # a = list(map(int, input().split()))
    # n = int(input())
    a, b = map(int, input().split())
    print(a *b )

main()


Measured memory_bytes: 9488
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define wzh(x) cerr<<#x<<'='<<x<<endl;
int s;

const int mod=1e9+7;
void add(int &x,int y){
  x+=y;
  if(x>=mod)x-=mod;
}
int dp[N];
int main() {
  ios::sync_with_stdio(false);
  cin>>s;dp[0]=1;
  for(int i=0;i<=s;i++){
    for(int j=3;j+i<=s;j++){
      add(dp[j+i],dp[i]);
    }
  }
  cout<<dp[s]<<'\n';
  return 0;
}


Measured memory_bytes: 3580
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll MOD=(ll)998244353;
//}}}

int main(){
  set<string> st;
  int n;
  cin >> n;
  string cur;
  string bef;
  bool ans = true;
  rep(i, n){
    cin >> cur;
    st.insert(cur);
    if(i != 0){
      if(bef[bef.size()-1] != cur[0]) ans = false;
    }
    bef = cur;
  }
  if(st.size() != n) ans = false;
  puts(ans ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 256
N,H=gets.split.map &:to_i
a,b=N.times.map{gets.split.map &:to_i}.transpose
a=a.max
b=[0]+b.sort.reverse
(1...b.size).each{|i|b[i]+=b[i-1]}
p b.size.times.map{|i|i+[0,(H-b[i]+a-1)/a].max}.min

Measured memory_bytes: 13808
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin >> a.at(i);
  }
  int j = 0;
  int c = 0;
  while( j != 1 && c < N){
    j = a.at(j)-1;
    c++;
  }
  if( c >= N ){
    c = -1;
  }
  cout << c;
}

Measured memory_bytes: 3788
r, c = list(map(int, input().split(" ")))
A = [[0 for _ in range(c)] for _ in range(r)]

A_sum = 0
for i in range(r):
    a_line = list(map(int, input().split(" ")))
    for j, a in enumerate(a_line):
        print("%d "%a, end="")
        A[i][j] = a
        A_sum += a
    print("%d"%sum(a_line))

A_T = list(map(list, zip(*A)))
for a_t in A_T:
    print ("%d "%(sum(a_t)), end="")

print (A_sum)

Measured memory_bytes: 7736
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
#include <bitset>

using namespace std;
typedef long long ll;



int main(){

    const ll N = 200000;
    bitset<N> sosu;
    int ans[10000];
    int cnt = 0;
    int sum = 0;
    
    sosu.set();
    
    for(ll i = 2;i < N; ++i){
        if(sosu.test(i)){
            sum += i;
            ans[cnt] = sum;
            ++cnt;
            if(cnt == 10000)break;
            for(ll j = i*i; j < N; j += i){
                sosu.reset(j);
            }
        }
    }
    
    ll n;
    while(1){
        cin >> n;
        if(!n)break;
        
        cout << ans[n-1] << endl;
    }
    
    return 0;
}

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

#define   ipr         	pair<int, int>
#define   pb            push_back
#define   ff            first
#define   ss            second
#define   fr(i, j, k)   for (int i = j; i < k; i++)
#define   rf(i, j, k)   for (int i = j; i >= k;i--)
#define   int           long long
#define   ll 			unsigned long long
#define   ld            long double
#define   all(x)        x.begin(), x.end()
#define   rall(x)       x.rbegin(),x.rend()
#define   mp            make_pair
#define   inf           INT_MAX
#define   read_file();	freopen("input.txt", "r", stdin);	freopen("output.txt", "w", stdout);
#define   IOS           std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int Maxn  =  10000;
const ld  pi   =  acos(-1);
const int mod =  1000000007;


template<class T> ostream& operator <<(ostream &out,vector<T> &A){for(auto x:A) out<<x<<" ";return out;}
template<class T> ostream& operator <<(ostream &out,set<T> &A){for(auto x:A) out<<x<<" ";return out;}
template <class T1,class T2>T1 powr(T1 a,T2 b){T1 res = 1;fr(i,1,b+1)res = res*a;return res;}

bool palindrome(string t){
   int flag=0;
   int f=t.length();
   fr(i,0,f/2){
   if(t[i]!=t[f-i-1]){
      flag=1;
      
      break;
   }
}
if(flag==0)return true;
else if(flag==1)return false;
}


int32_t main(){IOS
string s;
cin>>s;
int x=s.length();;
string y=s.substr(0,(x-1)/2);
string z=s.substr((x+3)/2-1,(x-1)/2);

if(palindrome(s) && palindrome(y) && palindrome(z))cout<<"Yes"<<endl;
else cout<<"No"<<endl;



}



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

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

Measured memory_bytes: 61636
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl

//ここから編集する
ll f(ll b, ll n) {
    if (n < b) {
        return n;
    } else {
        return f(b, (n / b)) + (n % b);
    }
}


int main() {
    ll n, s;
    cin >> n >> s;
    ll b = INFl;
    for (ll i = 2LL; i * i <= n; i++) {
//        cout << "finished :" << i <<endl;
        if (f(1LL * i, n) == s) {
            b = min(b, 1LL * i);
        }
    }


//    for (ll i = 1LL; n / i * n / i > n; i++) {
    for (ll i = 1LL; n / i > (ll) sqrt(n); i++) {
        ll bi = n / i;
        ll fbin = f(bi, n);

        ll bunshi = i * bi + fbin - s;
        if (bunshi % i == 0) {
            if (bunshi / i <= (n / i) && bunshi / i > (n / (i + 1))) {
                b = min(b, bunshi / i);
            }
        }
//        if(b == -19){
//            cout << " "<< endl;
//        }
    }


    if (b == INFl) {

        if(n == s){
            cout << n + 1 << endl;
        }else{
            cout << -1 << endl;
        }
    }else {
        cout << b << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define INF 1e9
int main(){
	int H,N;
	cin >> H >> N;
	vector<int> dp(H + 1, INF);
	dp[0] = 0;
	//dp[x] : min total cost to get value x 
	//dp[i] -> dp[ i + value ]
	while(N--){
		int value,cost;
		cin >> value >> cost;
		for(int i = 0; i<=H; i++){
			int j = min(H , i+value);
			dp[j] = min(dp[j],dp[i]+cost);
		}
	}
	cout << dp[H] << endl;
}


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

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

    ll N;
    cin >> N;
    ll t = N / 1000;
    ll x = ((t + 1) * 1000LL - N) % 1000;
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
#include <assert.h>
typedef int64_t ll;
typedef uint64_t ull;
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.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)

#define MAXN (200000)
#define MOD (1000000007)


int main(void)
{
    ll n,k;
    scanf("%ld %ld",&n,&k);

    ll m = (n-1)*(n-2)/2;
    if(k>m)
    {
        printf("-1\n");
        return 0;
    }

    printf("%ld\n",(n-1)+(m-k));
    for(int i=2;i<=n;i++)
    {
        printf("%d %d\n",1,i);
    }
    ll s = m;
    for(int i=2;i<=n;i++) for(int j=i+1;j<=n;j++)
    {
        if(s==k) break;
        printf("%d %d\n",i,j);
        s--;
    }

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  int k, x;
  cin >> k >> x;
  int l = x - (k-1);
  int r = x + (k-1);

  REP2(i,l,r+1){
    cout << i << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtC
{
    class Program
    {
        static void Main(string[] args)
        {
            long H = long.Parse(Console.ReadLine());
            long tmp = 1;
            long count = 0;
            while (true)
            {
                if (tmp > H) break;
                tmp = tmp * 2;
                count++;
            }
            long ans = 0;
            tmp = 1;
            while (count > 0)
            {
                ans += tmp;
                tmp = tmp * 2;
                count--;
            }
            Console.WriteLine(ans);
            Console.ReadLine();

        }
    }
}


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

int main(){
    string a;
    int A,B,C;
    cin >> A >> a;
    C = A;
    for(B==0;B<A-1;B++){
        if(a.at(B)==a.at(B+1)){
            C = C - 1;
        }
    }
    cout << C << endl;
    
}

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


int main(void)
{
    int m,n,l,r,i,a1,a2;
    cin>>n>>m;
    a1=0;a2=n;
    for(i=0;i<m;i++)
    {
        cin>>l>>r;
        a1=max(a1,l);
        a2=min(a2,r);
        if(a1>a2)
        {
            cout<<0;
            return 0;
        }
    }
    cout<<a2-a1+1;
    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
deg = [0 for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    deg[a-1] += 1
    deg[b-1] += 1

res = 'YES'
for d in deg:
    if d % 2 == 1:
        res = 'NO'
print(res)

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

int main() {
	
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n){
		cin >> a[i];
		printf("%d%c", a[i], (i == n - 1) ? '\n': ' ');
	}
	for(int i = 1; i < n; i++){
		int v = a[i];
		int j = i - 1;
		while(j >= 0 && a[j] > v){
			a[j+1] = a[j];
			j--;
		}
		a[j+1] = v;
		rep(k, n) printf("%d%c", a[k], (k == n - 1) ? '\n': ' ');
	}
	
	return 0;
}


Measured memory_bytes: 3188
#include <algorithm>
#include <climits>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

int main() {
	int n, a, b, c;
	while (cin >> n, n) {
		vector<vector<pair<int, int>>> d(10);
		for (int i = 0; i < n; ++i) {
			cin >> a >> b >> c;
			d[a].emplace_back(b, c);
			d[b].emplace_back(a, c);
		}
		vector<pair<int, int>> ans(10);
		for (int i = 0; i < 10; ++i) {
			priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> e;
			e.emplace(0, i);
			vector<bool> f(10);
			vector<int> g(10, INT_MAX);
			g[i] = 0;
			while (!e.empty()) {
				pair<int, int> h = e.top();
				e.pop();
				f[h.second] = true;
				for (pair<int, int>& j : d[h.second]) {
					if (!f[j.first]) {
						if (g[h.second] + j.second < g[j.first]) {
							g[j.first] = g[h.second] + j.second;
							e.emplace(g[j.first], j.first);
						}
					}
				}
			}
			for_each(g.begin(), g.end(), [](int& a) { if (INT_MAX == a) a = 0; });
			ans[i] = make_pair(accumulate(g.begin(), g.end(), 0), i);
		}
		for_each(ans.begin(), ans.end(), [](pair<int, int>& a) { if (0 == a.first) a.first = INT_MAX; });
		sort(ans.begin(), ans.end());
		cout << ans.front().second << ' ' << ans.front().first << endl;
	}
}


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

int main() {
	static int N, A[300000];
	cin >> N;
	for (int i = 0; i < pow(2, N); i++) {
		cin >> A[i];
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j < pow(2, N - i); j++) {
			if (A[j * 2] != A[j * 2 + 1]) A[j] = abs(A[j * 2] - A[j * 2 + 1]);
			else A[j] = A[j * 2];
		}
	}
	cout << A[0];
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vl = vector<ll>;  // long longの1次元の型に vl という別名をつける
using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける
int MOD = 1000000007; //10^9 + 7

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

// 無限大の値
const ll  LINF = 1LL << 60;
const int iINF = 1 << 29;

int main(void){
  int a,b,h;
  cin >> a >> b >> h;
  int ans = (a + b) * h /2; 
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;


class UnionFind {
    int n;
public:
    vector<int> uni;
    explicit UnionFind(int n) : uni(static_cast<u32>(n), -1) , n(n){};

    int root(int a){
        if (uni[a] < 0) return a;
        else return (uni[a] = root(uni[a]));
    }

    bool unite(int a, int b) {
        a = root(a);
        b = root(b);
        if(a == b) return false;
        if(uni[a] > uni[b]) swap(a, b);
        uni[a] += uni[b];
        uni[b] = a;
        return true;
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> e(n);
    vector<pair<int, int>> G;
    for (int i = 0; i < m; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        e[a-1]++; e[b-1]++;
        G.emplace_back(a-1, b-1);
    }
    int c = 0, p = 0;
    for (int i = 0; i < n; ++i) {
        if(e[i]&1){
            puts("No");
            return 0;
        }
    }
    for (int i = 0; i < n; ++i) {
        if(e[i] >= 6){
            puts("Yes");
            return 0;
        }else if(e[i] == 4) {
            c++;
            p = i;
        }
    }
    if(c >= 3){
        puts("Yes");
        return 0;
    }else if(c <= 1){
        puts("No");
        return 0;
    }
    UnionFind uf(n);
    for (int i = 0; i < m; ++i) {
        if(G[i].first != p && G[i].second != p){
            uf.unite(G[i].first, G[i].second);
        }
    }
    int sz = -uf.uni[uf.root(p == 0 ? 1 : 0)];
    puts(sz == n-1 ? "No" : "Yes");
    return 0;
}


Measured memory_bytes: 1784
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   int N;
   cin >> N;
   int A[N];
   int B[N];
   vector<pair<int,int>> v;
   vector<pair<int,int>> u;
   for(int i=0;i<N;i++)cin>>A[i];
   for(int i=0;i<N;i++)cin>>B[i];
   for(int i=0; i<N; i++){
      v.push_back(make_pair(B[i],A[i]));
   }
   sort(A,A+N);
   sort(B,B+N);
   sort(v.begin(),v.end());
   for(int i=0;i<N;i++){
      u.push_back(make_pair(v[i].second,i));
   }
   sort(u.begin(),u.end());
   for(int i=0;i<N;i++){
      if(A[i]>B[i]){
         cout <<"No" << endl;
         return 0;
      }
   }
   bool ok = false;
   int cur = 0;
   bool arrived[N];
   memset(arrived,false,sizeof(arrived));
   for(int i=0;i<N;i++){
      if(arrived[cur]){
         ok=true;
         break;
      }
      arrived[cur]=true;
      cur = u[cur].second;
   }
   for(int i=0;i<N;i++){
      if(i+1<N&&A[i+1]<=B[i]){
         ok=true;
         break;
      }
   }
   if(ok){
      cout <<"Yes"<< endl;
   }
   else{
      cout << "No" << endl;
   }
   return 0;
}


Measured memory_bytes: 3316
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main(){
    int N,K;
    cin >> N >> K;
    std::vector<int> A;
    for(int a = 0;a < N;a++){
        int c;
        cin >> c;
        A.push_back(c);
    }
    int nums = 0,count = 0;
        std::vector<int> a;
        a= A;
        std::sort(a.begin(),a.end());
        a.erase( unique(a.begin(), a.end()), a.end() );
        nums = a.size();

        std::vector<std::pair<int,int>> wows;
        std::vector<int> vec;
        vec = A;
        std::sort(vec.begin(),vec.end());
        int s = 0;
        int r;
        for(int moke:vec){
            if(s == 0){
                std::pair<int,int> f;
                f.second = moke;f.first++;
                wows.push_back(f);
            }else
                if(r == moke){
                    wows.back().first++;
                }else{
                    std::pair<int,int> a;
                    a.second = moke;a.first++;
                    wows.push_back(a);
                }
            r = moke;
            s++;
        }
        if(nums <= K){
            
        }else{
            std::sort(wows.begin(),wows.end());
            int s = 0;
            for(pair<int,int>a:wows){
                if(s == nums - K )break;
                count += a.first;
                //cout<<count<<endl;
                s++;
            }
        }
   cout <<count<<endl;
    return 0;
}


Measured memory_bytes: 4724
import Control.Monad
import Control.Applicative
--import Data.Functor
import Data.List

judge [m,f,r]
  | m==(-1) || f==(-1) = "F"
  | c>=80 = "A"
  | c>=65 = "B"
  | c>=50 || (c>=30 && r>=50) = "C"
  | c>=30 = "D"
  | otherwise = "F"
  where c = m + f

main = do
    --d <- fmap (map judge . takeWhile (all (==(-1))) . map (map read . words) . lines) $ getContents 
    d <- map judge . takeWhile (any (/=(-1))) . map (map read . words) . lines <$> getContents 
    mapM_ putStrLn d

Measured memory_bytes: 4056
import numpy as np
N, M =[int(i) for i in input().split()]
isfinish=[0]*N
isfail=[0]*N
for i in range(M):
    p, S = input().split()
    p=int(p)
    if isfinish[p-1]==1:
        continue
    elif S=="AC" and isfinish[p-1]==0:
        isfinish[p-1] = 1
    elif S=="WA" and isfinish[p-1]==0:
        isfail[p-1] +=1

isfinish=np.array(isfinish)
isfail=np.array(isfail)
print(str(sum(isfinish)) + " "+ str(sum(isfail[isfinish==1])))


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


int main() {
    int M1, D1, M2, D2;
    cin >> M1 >> D1 >> M2 >> D2;

    int mon[] = {31, 28, 31, 30, 30, 31, 30, 31, 30, 31, 30, 31};

    if (M1 == 1 && D1 == 31) cout << 1 << endl;
    else if (M1 == 2 && D1 == 28) cout << 1 << endl;
    else if (M1 == 3 && D1 == 31) cout << 1 << endl;
    else if (M1 == 4 && D1 == 30) cout << 1 << endl;
    else if (M1 == 5 && D1 == 31) cout << 1 << endl;
    else if (M1 == 6 && D1 == 30) cout << 1 << endl;
    else if (M1 == 7 && D1 == 31) cout << 1 << endl;
    else if (M1 == 8 && D1 == 31) cout << 1 << endl;
    else if (M1 == 9 && D1 == 30) cout << 1 << endl;
    else if (M1 == 10 && D1 == 31) cout << 1 << endl;
    else if (M1 == 11 && D1 == 30) cout << 1 << endl;
    else if (M1 == 12 && D1 == 31) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;

}

Measured memory_bytes: 256
package main

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

func solve() {
	n, m := getInt(), getInt()
	d := abs(n - m)
	if d > 1 {
		fmt.Fprintln(wr, 0)
		return
	}

	ans := 1
	for x := 1; x <= n; x++ {
		ans = (ans * x) % mod
	}
	for x := 1; x <= m; x++ {
		ans = (ans * x) % mod
	}
	if d == 0 {
		ans = (ans * 2) % mod
	}
	fmt.Fprintln(wr, ans)
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

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

const (
	inf = 1 << 60
	mod = 1000000007
)

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

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRunes() []rune {
	return []rune(getString())
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>

int inD;
int c[27] = {0};
int s[366][27] = {0};
int t[366] = {0};
int last[366] = {0};

long long int cal_manzoku(void);
void input_A(void);
void input_t(void);
long long int exec_query(int &d, int &q);
void print_t(void);

int main(){

    input_A();
    // input_t();
    for(auto i=1; i<=inD; ++i){
        t[i] = rand() % 26 + 1;
    }
    long long int man = cal_manzoku();
    // printf("%lld\n", man);
    print_t();

    // int m;
    // scanf("%d", &m);
    // for(int i=1; i<=m; ++i){
    //     int d,q;
    //     scanf("%d %d", &d, &q);
    //     man = exec_query(d, q);
    //     print_t();
    //     printf("%lld\n", man);
    // }

}

void print_t(void){
    for(int i=1; i<=inD; ++i){
        printf("%d\n", t[i]);
    }
    // printf("\n");
}

void input_A(){
    scanf("%d", &inD);
    for(int i=1; i<=26; ++i){
        scanf("%d", &c[i]);
    }
    
    // // Test
    // for(int i=1; i<=26; ++i){
    //     printf("%d ", c[i]);
    // }
    // printf("\n\n");

    for(int i=1; i<=inD; ++i){
        for(int j=1; j<=26; ++j){
            scanf("%d", &s[i][j]);
        }
    }
    // // Test
    // for(int i=1; i<=inD; ++i){
    //     for(int j=1; j<=26; ++j){
    //         printf("%d ", s[i][j]);
    //     }
    //     printf("\n");
    // }
    // printf("\n\n");

    return;
}

void input_t(){

    // 問題B入力
    for(int i=1; i<=inD; ++i){
        scanf("%d", &t[i]);
    }

    // // Test
    // for(int i=1; i<=inD; ++i){
    //     printf("%d ", t[i]);
    // }
    // printf("\n\n");
}

long long int cal_manzoku(){

    long long int manzoku=0;

    for(int day=1; day<=inD; ++day){
        long long int down = 0;
        last[t[day]] = day;
        for(int i=1; i<=26; ++i){
            down += c[i]*(day - last[i]);
            // printf("down %d %lld %d %d\n", day, down, c[i], last[i]);
        }

        manzoku = manzoku + s[day][t[day]] - down;
        // printf("manzoku %d %d %lld %d %lld\n", day, t[day], manzoku, s[day][t[day]], down);
        // printf("last %d %d\n", t[day], last[t[day]]);

        // printf("%lld\n", manzoku);
    }

    return(manzoku);

}

Measured memory_bytes: 1776
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const int INF = numeric_limits<int>::max();

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

int main()
{
    long double a, b, c; cin >> a >> b >> c;
    long double  left = sqrt(a) + sqrt(b) + 1.0E-14;
    if (left < sqrt(c))
        cout << "Yes" << endl;
    else
         cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <cmath>
#include <deque>
#include <unordered_set>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)

using namespace std;

class D {
	int rows, columns;
	vector<vector<bool>> field;
	int n_odd{ 0 };

public:
	D()
	{
		cin >> rows >> columns;
		field.resize(rows);
		int val;
		REP(y, rows)
		{
			field[y].resize(columns, false);
			REP(x, columns)
			{
				cin >> val;
				if (val & 1)
				{
					field[y][x] = true;
					++n_odd;
				}
			}
		}
	}

	void solve()
	{
		int ans_n{ 0 };
		int moves{ 0 };
		int flag{ false };
		int odds_remaining{ n_odd };

		for(int y{0}; y < rows && odds_remaining > 1; y++)
		{
			if (y & 1)
			{
				for (int x{ columns - 1 }; x >= 0 && odds_remaining > 1; x--)
				{
					if (field[y][x])
					{
						if (flag)
						{
							ans_n += ++moves;
							moves = 0;
							flag = false;
							odds_remaining -= 2;
						}
						else
						{
							flag = true;
						}
					}
					else
					{
						if (flag)
						{
							++moves;
						}
					}
				}
			}
			else
			{
				for (int x{ 0 }; x < columns && odds_remaining > 1; x++)
				{
					if (field[y][x])
					{
						if (flag)
						{
							ans_n += ++moves;
							moves = 0;
							flag = false;
							odds_remaining -= 2;
						}
						else
						{
							flag = true;
						}
					}
					else
					{
						if (flag)
						{
							++moves;
						}
					}
				}
			}
		}

		cout << ans_n << endl;
		odds_remaining = n_odd;
		flag = false;
		int last_x{ 0 }, last_y{ 0 };

		for (int y{ 0 }; y < rows && odds_remaining > 1; y++)
		{
			if (y & 1)
			{
				for (int x{ columns - 1 }; x >= 0 && odds_remaining > 1; x--)
				{
					if (flag)
					{
						cout << last_y + 1 << " " << last_x + 1 << " " << y + 1 << " " << x + 1 << endl;
					}
					if (field[y][x])
					{
						if (flag)
							odds_remaining -= 2;
						flag = !flag;
					}
					last_x = x;
					last_y = y;
				}
			}
			else
			{
				for (int x{ 0 }; x < columns && odds_remaining > 1; x++)
				{
					if (flag)
					{
						cout << last_y + 1 << " " << last_x + 1 << " " << y + 1 << " " << x + 1 << endl;
					}
					if (field[y][x])
					{
						if (flag)
							odds_remaining -= 2;
						flag = !flag;
					}
					last_x = x;
					last_y = y;
				}
			}
		}
	}
};


int main()
{
	D solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 2176
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(1, n-1):
	if p[i-1] < p[i] and p[i] < p[i+1]:
		ans += 1
	elif p[i-1] > p[i] and p[i] > p[i+1]:
		ans += 1
	
print(ans) 

Measured memory_bytes: 3060