akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public final class Main {

    static class Solver {
        long[] factorial;
        long[] facInverse;
        long[] inverse;

        void solve(int n, int m, int k) {
            init(n);
            int sum = 0;
            for (int i = 0; i <= k; i++) {
                final long edge = ncr(n - 1, i);
                sum = (int) ((sum + (edge * (m * modpow(m - 1, n - 1 - i) % MOD)) % MOD) % MOD);
            }
            System.out.println(sum);
        }

        void init(int n) {
            final int MAX = n + 2;
            factorial = new long[MAX];
            facInverse = new long[MAX];
            inverse = new long[MAX];
            factorial[0] = factorial[1] = 1;
            facInverse[0] = facInverse[1] = 1;
            inverse[1] = 1;
            for (int i = 2; i < MAX; i++) {
                factorial[i] = factorial[i - 1] * i % MOD;
                final long inv = inverse[i] = MOD - inverse[MOD % i] * (MOD / i) % MOD;
                facInverse[i] = facInverse[i - 1] * inv % MOD;
            }
        }

        long ncr(int n, int r) {
            if (n < r) { return 0; }
            if (n < 0 || r < 0) { return 0; }
            return factorial[n] * (facInverse[r] * facInverse[n - r] % MOD) % MOD;
        }

        long modpow(long a, long n) {
            long res = 1;
            while (n > 0) {
                if (n % 2 == 1) {
                    res = res * a % MOD;
                }
                a = a * a % MOD;
                n /= 2;
            }
            return res;
        }
    }

    private static final int MOD = (int) (1e9 + 7);

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int k = Integer.parseInt(in.nextLine());
        final int n = in.nextLine().length();
        final Solver solver = new Solver();
        solver.init(2 * (int) 1e6);
        long res = 0;
        for (int i = 0; i <= k; ++i) {
            final long add = solver.modpow(26, k - i) *
                             solver.ncr(n - 1 + i, i) % MOD *
                             solver.modpow(25, i) % MOD;
            res = (res + add) % MOD;
        }
        System.out.println(res % MOD);
    }

    // Duplicates
    // https://www.hackmath.net/en/calculator/combinations-and-permutations?n=26&k=5&order=0&repeat=1
    public static long nhr(Solver s, int n, int r) {
        return (n | r) == 0 ? 1 : s.ncr(n + r - 1, r);
    }
}


Measured memory_bytes: 104220
// https://atcoder.jp/contests/ddcc2020-qual/tasks/ddcc2020_qual_c
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    int H, W, K;
    cin >> H >> W >> K;
    vector<vector<char>> s(H, vector<char>(W));
    vector<vector<int>> a(H, vector<int>(W, 0));
    int num = 1;
    REP(i, H) REP(j, W)
    {
        cin >> s[i][j];

        // イチゴが乗っている箇所に番号を振る
        if ('#' == s[i][j])
        {
            a[i][j] = num++;
        }
    }

    REP(i, H)
    {
        // 左から右へ走査
        int left = a[i][0];
        REP(j, W)
        {
            // 0 の場合は左の数を採用する
            if (0 == a[i][j])
            {
                a[i][j] = left;
            }
            else
            {
                left = a[i][j];
            }
        }

        // 右から左へ走査(左から右への走査だけでは左側が埋まらない場合があるため)
        int right = a[i][W - 1];
        for (int j = W - 1; j >= 0; --j)
        {
            if (0 == a[i][j])
            {
                a[i][j] = right;
            }
            else
            {
                right = a[i][j];
            }
            
        }
    }

    REP(j, W)
    {
        // 上から下へ走査
        int up = a[0][j];
        REP(i, H)
        {
            if (0 == a[i][j])
            {
                a[i][j] = up;
            }
            else
            {
                up = a[i][j];
            }
            
        }

        // 下から上への走査
        int down = a[H - 1][j];
        for (int i = H - 1; i >= 0; --i)
        {
            if (0 == a[i][j])
            {
                a[i][j] = down;
            }
            else
            {
                down = a[i][j];
            }
            
        }
    }

    // 答えを出力
    for (int i = 0; i < H; ++i)
    {
        for (int j = 0; j < W; ++j)
        {
            printf("%d", a[i][j]);
            if (j != W - 1) printf(" ");
            else printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 4196
def bfs(field,H,W,start_x,start_y,tmp_N):
    direction = [[-1,0],[1,0],[0,-1],[0,1]]
    que = []
    que.append([start_x,start_y])
    INF = 1000000
    min_path = [[INF] * W for i in range(H)]
    min_path[start_y][start_x] = 0
    while len(que) != 0:
        current = que.pop(0)
        for d in direction:
            nx = current[0] + d[0]
            ny = current[1] + d[1]
            if 0 <= nx < W and 0 <= ny < H and field[ny][nx] != "X" and min_path[ny][nx] == INF:
                min_path[ny][nx] = min_path[current[1]][current[0]] + 1
                if field[ny][nx] == tmp_N:
                    return nx,ny,min_path[ny][nx]
                else:
                    que.append([nx,ny])

def getField():
    matrix = []
    first = input().strip()
    H,W,N = map(int,first.split())
    for i in range(H):
        row = list(input().strip())
        for j in range(W):
            if row[j].isdigit():
                row[j] = int(row[j])
        matrix.append(row)
    return matrix,H,W,N

def getStart(field):
    for y in range(len(field)):
        for x in range(len(field[0])):
            if field[y][x] == "S":
                return x,y

def main():
    matrix,H,W,N = getField()
    sx,sy = getStart(matrix)
    distance = 0
    tmp_x,tmp_y,tmp_dist = bfs(matrix,H,W,sx,sy,1)
    distance += tmp_dist
    tmps = [tmp_x,tmp_y]
    for k in range(N-1):
        tmp_x,tmp_y,tmp_dist = bfs(matrix,H,W,tmps[0],tmps[1],k+2)
        distance += tmp_dist
        tmps = [tmp_x,tmp_y]
    print(distance)

if __name__=='__main__':
    main()

Measured memory_bytes: 36940
import numpy as np

n = int(input())
a1 = list(map(int, input().split(" ")))
a2 = list(map(int, input().split(" ")))

if(n == 1):
   max = sum(a1) + sum(a2)
   print(max)
   exit()

max = 0
for i in range(n):

    num = sum(a1[:i]) + sum(a2[(i-1):])
    if(max < num):
        max = num

print(max)

Measured memory_bytes: 21540
from enum import Enum
import sys
import math
 
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
 
 
N = int(input())
 
ans = 0
 
for loop in range(N):
    num = int(input())
 
    if num == 1:
        ans += 1
    if num <= 3:
        continue
    elif num%2 == 0:
        ans += 1
    else:
        tmp_num = 3
        while True:
            if tmp_num*tmp_num > num:
                break
            if num%tmp_num == 0:
                ans += 1
                break
            tmp_num += 2
 
print("%d"%(N-ans))


Measured memory_bytes: 6376
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ii getmx(ii a, ii b)
{
	ld A = ld(a.fi)/ld(a.se);
	ld B = ld(b.fi)/ld(b.se);
	if(A<B) return b;
	else return a;
}

ii reduce(ii a)
{
	ll g=__gcd(a.fi,a.se);
	a.fi/=g; a.se/=g;
	return a;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	vector<pair<ll,ii> > v[2];
	ll sumD=0;
	for(int i=0;i<n;i++)
	{
		ll x,y; cin>>x>>y; //vec.pb({y,y-x});
		if(y>=x) sumD+=y-x;
		v[0].pb({y-max(y-x,0LL),{y,y-x}});
		v[1].pb({y+max(0LL,-(y-x)),{y,y-x}});
	}
	sort(v[0].begin(),v[0].end());
	sort(v[1].begin(),v[1].end());
	ii mx = mp(0,1);
	for(int z=0;z<2;z++)
	{
		/*
		cerr<<'\n';
		for(int i=0;i<n;i++)
		{
			cerr<<v[z][i].se.fi<<' '<<v[z][i].se.se<<'\n';
		}
		cerr<<'\n';
		*/
		/*
		for(int i=0;i<n;i++)
		{
			if(sumB+v[z][i].se.fi<=maxD)
			{
				sumB+=v[z][i].se.fi;
				continue;
			}
			else
			{
				ll L = sumB; ll R = sumB+v[z][i].se.fi;
				ll len=v[z][i].se.fi;
				//i + (maxD-L)/len
				ii newtmp = mp(i*len+maxD-L,len*1LL*n);
				newtmp=reduce(newtmp);
				mx=getmx(mx,newtmp);
				break;
			}
			sumB+=v[z][i].se.fi;
		}
		*/
		ll posD=0; ll negD=0; ll sumB=0; 
		int bestid=0;
		for(int i=0;i<n;i++)
		{ 
			ll b = v[z][i].se.fi; ll d = v[z][i].se.se;
			sumB+=b;
			if(d>0) posD+=d;
			else negD+=abs(d);
			if(sumB<=max(posD,sumD-negD))
			{
				bestid=i+1; continue;
			}
			else
			{
				/*
				ll L = sumB; ll R = sumB+v[z][i].se.fi;
				ll len=v[z][i].se.fi;
				//i + (maxD-L)/len
				ii newtmp = mp(i*len+max(posD,sumD-negD)-L,len*1LL*n);
				newtmp=reduce(newtmp);
				mx=getmx(mx,newtmp);
				break;
				*/
			}
		}
		if(bestid==n)
		{
			mx=getmx(mx,mp(1LL,1LL));
			continue;
		}
		if(z==1)
		{
			ll minK=0;
			for(int i=0;i<bestid;i++)
			{
				minK+=v[z][i].fi;
			}
			ll minK2=0;
			for(int i=0;i<bestid+1;i++)
			{
				minK2+=v[z][i].fi;
			}
			for(int i=0;i<n;i++)
			{
				ll b=v[z][i].se.fi;
				ll b2=v[z][i].fi;
				if(i<bestid)
				{
					//bestid+1-
					ll bsum=minK2;
					mx=getmx(mx,mp((bestid+1)*b-bsum+sumD,b*n));
				}
				else
				{
					ll bsum=minK+b2;
					mx=getmx(mx,mp((bestid+1)*b-bsum+sumD,b*n));
				}
			}
		}
		else
		{
			ll minK=0;
			for(int i=0;i<bestid;i++)
			{
				minK+=v[z][i].fi;
			}
			if(minK<=0)
			{
				for(int i=0;i<n;i++)
				{
					ll b=v[z][i].se.fi;
					mx=getmx(mx,mp(bestid*b+abs(minK),b*n));
				}
			}
		}
		//mx=max(mx,mp(1LL*bestid,n*1LL));
	}
	mx=reduce(mx);
	cout<<mx.fi<<' '<<mx.se<<'\n';
}	


Measured memory_bytes: 7208
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
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; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


void Main(){
    int S, W;
    cin >> S >> W;
    cout << (W>=S?"unsafe":"safe") << el;
}



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

int main(){
    int N, Y;
    cin >> N >> Y;
    int res10000 = -1, res5000 = -1, res1000 = -1;
    for (int a = 0; a <= N; a++)
    {
        for (int b = 0; b+a <= N; b++)
        {
            int c = N - a - b;
            int total = 10000*a + 5000*b + 1000*c;
            if(total == Y){
                res10000 = a;
                res5000 = b;
                res1000 = c;
            }
        }
        
    }
    cout << res10000 << ' ' << res5000 << ' ' << res1000 << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N, t0 = 0, x0 = 0, y0 = 0, t1, x1, y1;
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> t1 >> x1 >> y1;
		int k = (t1 - t0) - ((x1 - x0) + (y1 - y0));
		if(k<0 || k%2){
			cout << "No\n";
			return 0;
		}
		t0 = t1; x0 = x1; y0 = y1;
	}
	cout << "Yes\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	int A,B,C,D,E,F;
	int w = 0;
	int s = 0;
	double p = -1;

	cin >> A >> B >> C >> D >> E >> F;

	for(int i=0;;i++)
	{
		if(A*i*100 > F)break;

		for(int j=0;;j++)
		{
			int water = (A*i + B*j)*100;
			int limit = E*(A*i + B*j);
			if(water > F)break;

			for(int k=0;;k++)
			{
				if(C*k > limit)break;

				for(int l=0;;l++)
				{
					int suger = C*k + D*l;
					if(suger > limit || suger+water > F)break;

					if(suger+water == 0)continue;

					double per = (double)(suger*100)/(double)(suger+water);

					if(per > p)
					{
						w = water;
						s = suger;
						p = per;
					}
				}
			}
		}
	}

	cout << w+s <<" "<< s << endl;

	return 0;
}

Measured memory_bytes: 256
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();
		int C = sc.nextInt();
		sc.close();
		if(A <= C && B >= C) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}

}

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

using namespace std;

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

    int n;
    cin >> n;

    vector<int> a(n) , b(n) , t(n);

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

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

    iota(t.begin() , t.end() , 1);

    int mn = 1e9 , mx = -1e9 , ind = 1;
    do {
        if (t == a || t == b) {
            mn = min(mn , ind);
            mx = max(mx , ind);
        }

        ind++;
    } while (next_permutation(t.begin() , t.end()));

    cout << mx - mn;
}

Measured memory_bytes: 256
master = [(mark, number) for mark in ['S', 'H', 'C', 'D'] for number in range(1, 14)]
n = int(input())
cards = set()
for x in range(n):
    mark, number = input().split()
    cards.add((mark, int(number)))
lack = sorted((set(master) - cards), key = master.index)

for x in lack:
    print('%s %d' % x)

Measured memory_bytes: 7752
import java.util.Scanner;


	public class Main {
		
		

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			char[] a = sc.next().toCharArray();
			char[] b = sc.next().toCharArray();
			char[] c = sc.next().toCharArray();
			
			int an= a.length;
			int bn = b.length;
			int cn = c.length;
			
			char turn = 'a';
			
			while(true) {
				if(turn=='a') {
					if(an==0) {
						System.out.println("A");
						return;
					}
					turn = a[a.length-an];
					an--;
				}
				
				if(turn=='b') {
					if(bn==0) {
						System.out.println("B");
						return;
					}	
					turn = b[b.length-bn];
					bn--;
				}
				
				if(turn=='c') {
					if(cn==0) {
						System.out.println("C");
						return;
					}
					turn = c[c.length-cn];
					cn--;
				}
			}
			
		}
		
	}


Measured memory_bytes: 35652
program sample
    implicit none
  
    integer(8) :: i,j,m,n,s,t,u
    integer(8),allocatable :: a(:),y(:)
  
    read(*,*) n
    allocate(a(n))
    read(*,*)a
    s=sum(a)
    t=0
    u=s

    do i=1,n
        t=u
        !t=t+a(i)
        u=u-2*a(i)


        if (u<0)then
            if (abs(u)>t)then
                write(*,*)t
            else
                write(*,*)abs(u)
            end if
            exit
        end if
    end do

  
    stop
end program sample
  



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

int main() {
  int n;
  cin >> n;
  int count = 0;
  for(int i=1;i<=n;i++){
    string s = to_string(i);
    if (s.size()%2!=0) count += 1 ;
  }
  cout << count << endl;
}

Measured memory_bytes: 384
n, k = map(int, input().split())
max_k = k.bit_length()
A = [0] + list(map(int, input().split()))

DB = [[0] * (n + 1) for _ in range(max_k + 1)]
# DB[i][j] 2**i乗回考えた時にjが移動する数
for j in range(1, n + 1):
    DB[0][j] = A[j]
for i in range(max_k):
    for j in range(1, n + 1):
        num = DB[i][j]
        DB[i + 1][j] += DB[i][num]
bit = bin(k)
num = 1
for i in range(max_k):
    if bit[-(i + 1)] == "1":
        num = DB[i][num]
print(num)


Measured memory_bytes: 174956
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors


N = int(input())
ans = 0
for i in range(1, N+1):
    if i % 2 == 0:
        continue
    tmp = make_divisors(i)
    if len(tmp) == 8:
        ans += 1
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+100;
typedef long long ll;
int n;
int w[maxn];
int v[maxn];
ll dp[maxn];
int W;
int main(){
    scanf("%d%d",&n,&W);
    for (int i=0;i<n;i++){
        scanf("%d%d",w+i,v+i);
    }
    memset(dp,0x3f3f3f3f3f3f3f3fLL,sizeof dp);
    dp[0] = 0;
    for (int i=0;i<n;i++){
        for (int j=100000;j>=v[i];j--){
            dp[j] = min(dp[j],dp[j-v[i]] + w[i]);
        }
    }
    int ans =0;
    for (int i=1;i<=100000;i++){
        if (dp[i] <= W)ans = i;
    }
    cout<<ans<<endl;
    return 0;
}

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

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

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

const long long MOD = 1000000007;
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
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;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint dp[100005][2];
void solve(string L){
  ll n = L.size();
  dp[0][0] = 1;
  rep(i,n) {
    if(L[i]=='0') {
      // a + b = 0
      dp[i+1][0] += dp[i][0];
      dp[i+1][1] += dp[i][1];
      // a + b = 1
      dp[i+1][1] += dp[i][1]*2;
    } else {
      // a + b = 0
      dp[i+1][1] += dp[i][1]+dp[i][0];
      // a + b = 1
      dp[i+1][0] += dp[i][0]*2;
      dp[i+1][1] += dp[i][1]*2;
    }
  }
  std::cout << dp[n][0]+dp[n][1] << std::endl;
}

int main(){
  string L;
  cin>>L;
  solve(L);
  return 0;
}


Measured memory_bytes: 2048
N = int(input())

# print(N)

A_list = list(map(int, input().split()))

dct = {}

for i in range(len(A_list)):
    a = A_list[i]
    # print(A_list[i])
    
    key = a
    value = i + 1
    
    dct[key] = value
    
# print(dct)

dct2 = dict(sorted(dct.items(), key=lambda x: x[0]))
# print(dct2)

list1 = dct2.values()
# print(list1)

print(' '.join(map(str, list1)))

Measured memory_bytes: 35932
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
int main(){
  ll Q,A,B;
  cin>>Q;
  rep(i,Q){
    cin>>A>>B;
    ll ans;
    if(A==B||abs(A-B)==1) ans=2*min(A,B)-2;
    else{
      ll X=A*B;
      ll C=sqrt(X);
      if(C*C==X) C--;
      ans=2*C-2;
      if(C*(C+1)<X) ans++;
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

const int MAX = 200007;
const int MOD = 1000000007;

void solve() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int res = 0;
    if (k <= a) {cout << k;}
    else if (k <= a + b) {cout << a;}
    else {
        cout << a - (k - a - b);
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //int tt; cin >> tt; for (int i = 1; i <= tt; i++) {solve(); cout << endl;}
    solve();
}

Measured memory_bytes: 3664
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<algorithm>
#include <cstring>
#include<set>
#include<cmath>
# define ll long long 
using namespace std;

int main()
{
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	int flag=0;
	while(a>0 && c>00)
	{
		if(flag==0)
		{
			c=c-b;
			flag=1;
		}
		else
		{
			a=a-d;
			flag=0;
		}
	}
	if(flag==1)
		cout<<"Yes\n";
	else
		cout<<"No\n";
}

Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int a = Integer.parseInt(in.readLine());
    int b = Integer.parseInt(in.readLine());
    int h = Integer.parseInt(in.readLine());
    System.out.println((a+b)*h/2);
  }
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);

  int n_mask;
  cin >> n_mask;

  vector<bitset<64>> mask(n_mask);
  int n_bit, tmp;
  for (int i = 0; i < n_mask; i++) {
    cin >> n_bit;
    for (int j = 0; j < n_bit; j++) {
      cin >> tmp;
      mask[i].set(tmp);
    }
  }

  int n;
  cin >> n;
  int cmd;

  bitset<64> bs(0);
  int val;
  for (int i = 0; i < n; i++) {
    cin >> cmd;
    switch (cmd) {
      case 0:
        cin >> val;
        cout << bs.test(val) << endl;
        break;

      case 1:
        cin >> val;
        bs |= mask[val];
        break;

      case 2:
        cin >> val;
        bs &= ~mask[val];
        break;

      case 3:
        cin >> val;
        bs ^= mask[val];
        break;

      case 4: {  //  all
        cin >> val;
        bitset<64> temp(0);
        temp = bs & mask[val];
        if (temp == mask[val]) {
          cout << 1 << endl;
        } else {
          cout << 0 << endl;
        }
        break;
      }

      case 5:  // any
      {
        cin >> val;
        bitset<64> temp(0);
        temp = bs & mask[val];
        if (temp != 0) {
          cout << 1 << endl;
        } else {
          cout << 0 << endl;
        }
        break;
      }

      case 6:  // none
      {
        cin >> val;
        bitset<64> temp(0);
        temp = bs & mask[val];
        if (temp == 0) {
          cout << 1 << endl;
        } else {
          cout << 0 << endl;
        }
        break;
      }

      case 7: {
        cin >> val;
        bitset<64> temp(0);
        temp = bs & mask[val];
        cout << temp.count() << endl;
        break;
      }

      case 8: {
        cin >> val;
        bitset<64> temp(0);
        temp = bs & mask[val];
        cout << temp.to_ullong() << endl;
        break;
      }
    }
  }
}




Measured memory_bytes: 3228
import os


def alpha2num(alpha):
    num=0
    for index, item in enumerate(list(alpha)):
        num += pow(26,len(alpha)-index-1)*(ord(item)-ord('A')+1)
    return num

def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

def main():
	n = int(input())
	s = input()
	result = ""
	for i in s:
		num = alpha2num(i)
		if num + n > 26:
			num = num + n - 26
		else:
			num += n
		string = num2alpha(num)
		result += string
	print(result)
	

if __name__ == "__main__":
	main()


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
    int n, k;
    double answer = 0.0;
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        int score = i + 1;
        double d = 1.0 / n;
        while (score < k) {
            d /= 2.0;
            score <<= 1;
        }
        answer += d;
    }
    cout << fixed << setprecision(12) << answer << endl;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
    long long k;
    cin >> k;
    long long a[51];
    for(int i = 1; i <= 50; i++){
        a[i] = 49 + (k / 50) - (k % 50);
    }
    for(int i = 1; i <= (k % 50); i++){
        a[i] += 50 + 1;
    }
    cout << 50 << endl;
    for(int i = 1; i <= 49; i++){
        cout << a[i] << " ";
    }
    cout << a[50] << endl;
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))

c = [None] * 200000
cc = set()
p = 0
st = 0
ed = 0
i = 0
while True:
    c[i] = p
    cc.add(p)
    i += 1
    p = a[p]
    if p in cc:
        st = c.index(p)
        ed = i
        break
if k < ed:
    print(c[k] + 1)
else:
    k -= st
    k %= ed - st
    print(c[st + k] + 1)

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    vector<vector<pair<int, int>>> testimony(n, vector<pair<int, int>>());
    int x, y;
    rep(i, n)
    {
        cin >> a[i];
        rep(j, a[i])
        {
            cin >> x >> y;
            x--;
            testimony[i].push_back({x, y});
        }
    }
    int cnt_max = 0;
    bool honesty;
    bool hone_check;
    for (int bit = 0; bit < (1 << n); ++bit)
    {
        bool check_ok = true;
        rep(i, n)
        {
            if (bit & (1 << i))
                honesty = true;
            else
                honesty = false;
            rep(j, testimony[i].size())
            {
                hone_check = bit & (1 << testimony[i][j].first);
                if (honesty)
                {
                    if (hone_check != bool(testimony[i][j].second))
                        check_ok = false;
                }
            }
        }
        if (check_ok)
            cnt_max = MAX(cnt_max, __builtin_popcount(bit));
    }
    cout << cnt_max << endl;
    return 0;
}

Measured memory_bytes: 3544
#include <iostream>

typedef long long ll;

using namespace std;

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

    ll A;
    cin >> A;
    ll height = A;
    ll ans = 0;
    for (int i = 0; i < N - 1; ++i) {
        cin >> A;
        if (height > A) {
            ans += height - A;
        }
        else {
            height = A;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


int main() {
  int n, m;
  cin >> n >> m;
  vi s(m), c(m);
  rep(i, m) cin >> s[i] >> c[i];

  vi val(n, -1);
  rep(i, m){
    s[i] -= 1;
    if (val[s[i]] == -1) val[s[i]] = c[i];
    else if (val[s[i]] != c[i]){
      cout << -1 << endl;
      return 0;
    }
  }

  if (n == 1 and (val[0] == 0 or val[0] == -1)){
    cout << 0 << endl;
    return 0;
  }
  if (val[0] == 0){
    cout << -1 << endl;
    return 0;
  }

  if (val[0] == -1) val[0] = 1;
  rep(i, n){
    if (val[i] != -1) cout << val[i];
    else cout << 0;
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>
#include<queue>
#include<set>
#include<utility>
#include <iomanip>
#include <limits>
#include <thread>
#include <map>
#include <stack>
#include <numeric>
#include <cassert>
#include <random>
#include <chrono>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <list>
#include <functional>
#include <bitset>
#include <tuple>

#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1; i<n+1; i++)
#define repr(i,n) for(int i=n-1; i>=0; i--)
#define repr1(i,n) for(int i=n; i>0; i--)

#define elif else if

using namespace std;
typedef long long ll;
typedef vector<int>  vi;
typedef vector<vi>  vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double D;


const ll llINF =  numeric_limits<ll>::max();
const int intINF = numeric_limits<int>::max();
const double doubleINF = numeric_limits<double>::infinity();
const ll MOD = 1000000007;


template <class... A>
void prints() { cout << "\n"; }
template <class... A>
void prints_rest() { cout << "\n"; }
template <class T, class... A>
void prints_rest(const T &first, const A &... rest) { cout << " " << first; prints_rest(rest...); }
template <class T, class... A>
void prints(const T &first, const A &... rest) { cout << first; prints_rest(rest...); }


vi divisor(int n) {
  vi ret;
  for(int i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret), greater<int>());
  return (ret);
}




int a[505];

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

  int n,k;
  int s = 0;

  cin >> n >> k;
  rep(i,n) cin >> a[i];
  rep(i,n) s += a[i];
  vi yakusuu = divisor(s);

  int ans = 0;
  int adif[n];
  rep(j,yakusuu.size()){
    int dif=0;
    ans = yakusuu[j];
    rep(i,n) adif[i] = a[i]% ans;
    rep(i,n) if(adif[i] > ans/2) adif[i] -= ans;
    int spos = 0;
    int sneg = 0;
    rep(i,n) {
      if(adif[i] > 0){spos+=adif[i];}
      else{sneg += adif[i];}
    }
    int sdif = spos + sneg;
    sort(adif, adif + n, greater<>());
    if(sdif == 0){if (spos <= k) {prints(ans);break;}}
    elif(sdif > 0){
      int itr = sdif/ans;
      rep(i,itr)spos-=adif[i];
      if (spos <= k) {prints(ans);break;}
    }
    else{
      int itr = abs(sdif)/ans;
      for(int i = n-1;i>n-1-itr; i--)sneg-=adif[i];
      if (abs(sneg) <= k) {prints(ans);break;}
    }
  }




  return 0;

}


Measured memory_bytes: 256
function Main(input) {
    input = input.split("\n");
    const tmp = input[0].split(" ");
    const x = parseInt(tmp[0], 10);
    const n = parseInt(tmp[1], 10);
    if(n === 0){
        console.log(x);
        return;
    }
    const p_str = input[1].split(" ");
    let p = [];
    for(let i = 0;i < n ; i++){
        p[i] = parseInt(p_str[i], 10);
    }

    p.sort();
 
    for(let i = 0;i < 100 ; i++){
        if( p.indexOf(x - i) === -1 ){
            console.log(x - i);
            return;
        }
        if( p.indexOf(x + i) === -1 ){
            console.log(x + i);
            return;
        }
             
    }
   

}
 
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
template<class T> inline T isqrt(T k) {T r = sqrt(k) + 1; while (r * r > k) r--; return r;}
template<class T> inline T icbrt(T k) {T r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}

const int maxn = 100000 + 10;
int n, k;
int a[maxn];
long long prf[maxn];
long long suf[maxn];
long long sum[maxn];

void solve() {
	cin >> n >> k;
	FOR(i, 1, n + 1) cin >> a[i], sum[i] = sum[i - 1] + a[i];
	FOR(i, 1, n + 1) {
		prf[i] = prf[i - 1] + max(0, a[i]);
	}
	FORd(i, n + 1, 1) {
		suf[i] = suf[i + 1] + max(0, a[i]);
	}
	long long ans = 0;
	FOR(i, 0, n - k + 1) {
		int j = i + k + 1;
		chkmax(ans, prf[i] + suf[j] + max(0LL, sum[j - 1] - sum[i]));
	}
	cout << ans << "\n";
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL_
	freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout);
#endif
	solve();
#ifdef _LOCAL_
	//printf("\nTime elapsed: %dms", 1000 * clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}

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

int main()
{
	int64_t n;
	cin >> n;
	vector<int64_t> ds(n);
	for (auto &&d : ds)
	{
		cin >> d;
	}

	int64_t ans = 0;

	for (int64_t i = 0; i < n; i++)
	{
		for (int64_t j = i + 1; j < n; j++)
		{
			ans += ds[i] * ds[j];
		}
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

int n,m,a[1000005],mx;
long long cnt;

int main () {
	cin >> n >> m;
	for (int i = 1; i <= n;i++){
		cin >> a[i];
	}
	if (n - m <= 0){
		cout << 0;
		return 0;
	}
	sort(a + 1,a + n + 1);
	for (int i = 1; i <= n - m; i++){
		cnt+=a[i];
	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ps push_back
using namespace std;
const long long inf=9999999999999;
long long dp[52][2502];
struct nex{
    int x,cost,tim;
};
struct node{
    int x, s, t;
    bool operator<(const node& a)const{
        return t>a.t;
    }
};
priority_queue<node>que;
vector<nex>edg[52];
int c[52],d[52];
int book[52][2502];
int main()
{
    int u, v, a, b, s, n, m, i, j, k;
    cin>>n>>m>>s;
    
    nex tmp;
    int ma=0;
    while(m--)
    {
        scanf("%d%d%d%d", &u,&v,&a,&b);
        ma=max(a,ma);
        tmp.x=v,tmp.cost=a,tmp.tim=b;
        edg[u].ps(tmp);
        tmp.x=u;
        edg[v].ps(tmp);
    }
    ma*=n;
    s=min(ma, s);
    for(int i=1; i<=n; i++)scanf("%d%d", &c[i], &d[i]);
    for(i=0; i<=n; i++)
    {
        for(j=0; j<=ma; j++)
        {
            dp[i][j]=inf;
        }
    }
    dp[1][s]=0;
    node top;
    top.x=1;top.t=0;top.s=s;
    que.push(top);
//    top.x=2;top.t=1;top.s=s;
//    que.push(top);
//    printf("%d\n",que.top().x);
    while(!que.empty())
    {
        top=que.top();
        que.pop();
        int now=top.x, coin=top.s;
//        if(coin<10)printf("now%d coin%d %d\n", now, coin, dp[now][coin]);
        int nc=min(ma, coin+c[now]);
//        if(book[now][coin])continue;
//        book[now][coin]=1;
        if(dp[now][nc]>dp[now][coin]+d[now])
        {
            dp[now][nc]=dp[now][coin]+d[now];
//            if(book[now][nc])printf("%d %d %d\n", now, nc);
//            if(book[now][nc]==0){
            top.x=now,top.s=nc;
            top.t=dp[top.x][top.s];
            que.push(top);
//            }
        }
//        if(i<10)printf("nc%d %d\n", nc, dp[now][nc]);
        nex tmp;
        for(k=0; k<edg[now].size(); k++)
        {
            tmp=edg[now][k];
            j=coin;
//            if(i<10)printf("%d %d\n%d %d\n", now, tmp.x,j-tmp.cost, dp[tmp.x][j-tmp.cost]);


            if(j-tmp.cost>=0 && dp[now][j]+tmp.tim<dp[tmp.x][j-tmp.cost])
            {

                dp[tmp.x][j-tmp.cost]=dp[now][j]+tmp.tim;
//                if(book[tmp.x][j-tmp.cost]==0){
                    top.x=tmp.x;
                    top.s=j-tmp.cost;
                    top.t=dp[top.x][top.s];
                    que.push(top);
//                }
            }
        }

    }
    for(i=2; i<=n; i++)
    {
        long long mi=inf;
        for(j=0; j<=ma; j++)
        {
            mi=min(mi,dp[i][j]);
        }
        printf("%lld\n", mi);
    }
    return 0;
}


Measured memory_bytes: 10472
#include <bits/stdc++.h>
#define eps 1e-3
#define pi acos(-1.0)
#define inf 0x3f3f3f3f
#define debug1 cout<<"&&";
#define debug2 cout<<"**";
#define pb push_back
#define ms(a, x) memset(a, x, sizeof(a))
#define forn(i, n) for(int i = 0; i < n; ++i)
#define for1(i, n) for(int i = 1; i <= n; ++i) 
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int mod = 1e9;
const int N = 1e5+10;
/*=======================================================================*/

ll n, W, w[N], v[N], f[N];
int main() {
  cin >> n >> W;
  for (int i = 1; i <= n; i++) cin >> w[i] >> v[i];

  for (int i = 1; i <= n; i++) {
     for (int l = W; l >= w[i]; l--) {
      //   debug1
      //   cout << i << endl;
      //   cout << f[l - w[i]] + v[i] << " " << f[l] << endl;
        if (f[l - w[i]] + v[i] > f[l]) {
            f[l] = f[l - w[i]] + v[i];
            // debug1
            // cout << i << " " << l << endl;
         }
     }
   //   cout << i << " " << n << endl;
  }
    
      
  cout << f[W] << endl;
  return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  int a, b; string s;
  cin >> a >> b >> s;
  bool f = true;
  rep(i, a){
    if(s[i] < '0' || s[i] > '9') f = false;
  }
  if(s[a] != '-'){
     f = false;
  }
  for(int i = a + 1; i < a + 1 + b; i++){
    if(s[i] < '0' || s[i] > '9') f = false;
  }

  if(f) cout << "Yes" << ln;
  else cout << "No" << ln;

}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n,m,arr[10010],sum=0,result;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        cin>>arr[i];
    }
    for(int i=0;i<m;i++)
    {
        sum = sum + arr[i];
        result= n-sum;

    }
    if(sum>n)
        cout<<"-1"<<endl;
    else
        cout<<result<<endl;
    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <stdlib.h>

using namespace std;

int main(){
	int a,b,c,k;
	cin >> a >> b >> c >> k;
	int ans = 0;
	if(k <= a) ans = k;
	else if(k <= a+b) ans = a;
	else ans = a - (k-(a+b));
	cout << ans << endl;
}

Measured memory_bytes: 3600
using System;
using System.Collections.Generic;//list用
using System.Text.RegularExpressions;//正規表現用
using System.Text;//StringBuilder用
using System.Collections;
class Program
{
    static List<int> s = new List<int>();
    static long result;
static Hashtable ht=new Hashtable();
    public static int CountChar(string s, char c)
    {
        return s.Length - s.Replace(c.ToString(), "").Length;
    }

    static void Main()
    {
        string tmp1 = Console.ReadLine();
        int x = int.Parse(tmp1);
        string[] tmp2 = new string[x];
      string[] kazu=new string[10];
        for (int i = 0; i < x; i++) { 
          tmp2[i]=Console.ReadLine();
          for(int j=0;j<10;j++){kazu[j]=tmp2[i][j].ToString();}
          Array.Sort(kazu);
          tmp2[i]=kazu[0]+kazu[1]+kazu[2]+kazu[3]+kazu[4]+kazu[5]+kazu[6]+kazu[7]+kazu[8]+kazu[9];
        }
      result=0;
      long temp;
      for(int i=0;i<x;i++){
if(ht.ContainsKey(tmp2[i])){
  temp=(long)ht[tmp2[i]]+1;
  result+=temp;
ht[tmp2[i]]=temp;
}else{ht[tmp2[i]]=(long)0;}
      }
            Console.WriteLine(result.ToString());
    }
}

Measured memory_bytes: 34600
#include<stdio.h>
int main(void){
	int N,M;
	scanf("%d%d",&N,&M);
	int a,b;
	int K;
	int A;
	int num[30]={};
	for(a=0;a<N;a++){
		scanf("%d",&K);
		for(b=0;b<K;b++){
			scanf("%d",&A);
			num[A-1]++;
		}
	}
	int like=0;
	for(a=0;a<30;a++){
		if(num[a]==N){
			like++;
		}
	}
	printf("%d",like);
return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void){
    int N;
    cin >> N;
    int p[N];
    for(int i = 0; i < N; i++){
        cin >> p[i];
    }
    
    int ans = 0;
    int ma = p[0];
    int mi = p[0];
    for(int i = 0; i < N - 2; i++){
        ma = p[i];
        mi = p[i];
        ma = max(p[i], p[i+1]);
        ma = max(ma, p[i+2]);
        mi = min(p[i], p[i+1]);
        mi = min(mi, p[i+2]);
        if(p[i+1] != ma && p[i+1] != mi)
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
void Say(bool say, string a = "Yes", string b = "No"){cout << (say ? a : b) << endl;};

int main(){

    ll ans = 0;
    ll N;
    cin >> N;
    vector<ll>v(N, 0);
    for(ll i = 0; i < N; i++)cin >> v[i];
    ans = 1;
    for(ll i = 1; i < N; i++)if(v[i-1] > v[i])ans = 0;
    for(ll i = 0; i < N; i++){
        for(ll j = i + 1; j < N; j++){
            swap(v[i], v[j]);
            ll tmp = 1;
            for(ll k = 1; k < N; k++)if(v[k - 1] > v[k])tmp = 0;
            if(tmp)ans = 1;
            swap(v[i], v[j]);
        }
    }
    Say(ans, "YES", "NO");

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	uint[] GU => Strs.Select(uint.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	static ulong One(int k) => 1ul << k;
	static ulong All(int k) => One(k) - 1;
	static bool Has(ulong s, int k) => (s & One(k)) != 0;
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		int X = I[0], Y = I[1], Z = I[2], K = I[3];
		var A = GL;
		var B = GL;
		var C = GL;
		Array.Sort(A);
		Array.Reverse(A);
		Array.Sort(B);
		Array.Reverse(B);
		Array.Sort(C);
		Array.Reverse(C);
		var sums = new List<long>();
		var mx = Min(K, X);
		for (var i = 0; i < mx; i++)
			for (var j = 0; j < Y; j++)
			{
				var p = (i + 1) * (j + 1);
				if (p > K) break;
				var s = A[i] + B[j];
				for (var k = 0; k < Z; k++)
				{
					if (p * (k + 1) > K) break;
					sums.Add(s + C[k]);
				}
			}
		sums.Sort();
		sums.Reverse();
		foreach (var s in sums.Take(K)) WriteLine(s);
	}
}


Measured memory_bytes: 15968
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

struct UnionFind {
  vector<int> par;
  vector<int> sizes;

  UnionFind(int N) : par(N), sizes(N, 1) {
    for(int i = 0; i < N; i++) par.at(i) = i;
  }

  int find(int x) { 
    if (par.at(x) == x) return x;
    return par.at(x) = find(par.at(x));
  }

  void unite(int x, int y) {
    int rx = find(x); 
    int ry = find(y); 
    if (rx == ry) return; 
    if (sizes.at(rx) < sizes.at(ry)) swap(rx,ry);
    par.at(ry) = rx;
    sizes.at(rx) += sizes.at(ry);    
  }

  bool same(int x, int y) {
    return find(x) == find(y);
  }

  int size(int x){
    return sizes.at(find(x));
  }

  int num_of_connected_components(){
    int ret = 0;
    for(int i = 0; i < par.size(); i++){
      if(find(i) == i) ret++;
    }
    return ret;
  }
};

int main(){
  ll n; cin >> n;
  const ll M = 1e5;
  UnionFind uft(2*M);
  REP(i,n){
    ll x,y; cin >> x >> y;
    x--; y--;
    uft.unite(x,y+M);
  }
  vector<ll> cntx(2*M,0), cnty(2*M,0);
  REP(i,2*M){
    ll k = uft.find(i);
    if(i<M) cntx[k]++;
    else cnty[k]++;
  }
  ll ans = 0;
  REP(i,2*M) ans += cntx[i] * cnty[i];
  ans -= n;
  cout << ans << endl;
}



Measured memory_bytes: 4992
# -*- coding: utf-8 -*-

N = int(input())

ans = 1
for i in range(N):
    # 調整の処理は都度行っても端数の側に影響を与えないので問題ない
    ans = (ans * (i + 1)) % (10 ** 9 + 7) 

# 大き過ぎる値を調整する
# ans = ans % (10 ** 9 + 7) 

print(ans)

Measured memory_bytes: 2940
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int r = sc.nextInt();
    if(n >= 10){
      System.out.println(r);
    }else{
      System.out.println(r + 100 * (10 - n));
    }
  }
}


Measured memory_bytes: 23252
#include<stdio.h>

int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  if((a-b) >= (a+b)){
    if((a-b) >= (a*b)){
      printf("%d\n",a-b);
    }else{
      printf("%d\n",a*b);
    }
  }else{
      if((a+b) >= (a*b)){
        printf("%d\n",a+b);
      }else{
        printf("%d\n",a*b);
      }
  }
  return 0;
}

Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        char[] s;
        String m=sc.next();
        s=m.toCharArray();
        boolean c=false;
        boolean f=false;
        for (int i = 0; i < s.length; i++) {
            if (s[i]=='C') {
                c=true;
            }
            if (c&&s[i]=='F') {
                f=true;
            }
        }
        if (c&&f) {
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 9556
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

int main(){
	ll a,b,c;
	scanf("%lld%lld%lld",&a,&b,&c);
	rep(i,0,100)if((60*i+c)%(a+b)<=a){
		printf("%lld\n",60*i+c);
		return 0;
	}
	puts("-1");
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,d;

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

if(a*b>c*d){
    cout<<a*b;
}
else if(a*b<c*d){
    cout<<c*d;

}
else if((a*b)==(c*d)){
    cout<<a*b;
}
}


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

void solve();

signed main () {
    cout.precision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1; 
    // cin >> t;	
    int tt = t;
    while (t--) { 
        solve();
    }
    return 0;
}

void solve() {
	int x;
	cin >> x;
	int t = x / 100;
	if (t * 100 <= x and t * 105 >= x) 
		cout << 1;
	else
		cout << 0; 
}     	

Measured memory_bytes: 256