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

long long arr[100000];

long long gcd(long long a,long long b) {
    if (b==0) {
        return a;
    }
    return gcd(b,a%b);
}

int main(void) {
    int n;
    scanf("%d",&n);
    long long sum=0;
    for(int i=0;i<n;i++) {
        scanf("%lld",&arr[i]);
        sum+=arr[i];
    }
    if (sum%2!=n%2) {
        printf("First");
        return 0;
    }
    int cnt=0;
    for(int i=0;i<n;i++) {
        cnt+=arr[i]%2;
    }
    if (cnt>1) {
        printf("Second");
        return 0;
    }
    bool turn=false;
    while (1) {
        bool flag=false;
        for(int i=0;i<n;i++) {
            if (arr[i]!=1) {
                flag=true;
            }
        }
        if (!flag) {
            printf("%s",turn?"First":"Second");
            return 0;
        }
        int cnt=0;
        long long sum=0;
        for(int i=0;i<n;i++) {
            if (arr[i]%2==1) {
                cnt++;
            }
            sum+=arr[i];
        }
        if (sum%2!=n%2) {
            printf("%s",turn?"Second":"First");
            return 0;
        }
        if (cnt>1) {
            printf("%s",turn?"First":"Second");
            return 0;
        }
        for(int i=0;i<n;i++) {
            if (arr[i]%2==1) {
                if (arr[i]==1) {
                    printf("%s",turn?"First":"Second");
                    return 0;
                }
                arr[i]--;
                break;
            }
        }
        long long val=0;
        for(int i=0;i<n;i++) {
            val=gcd(val,arr[i]);
        }
        for(int i=0;i<n;i++) {
            arr[i]/=val;
        }
        turn^=1;
    }
}

Measured memory_bytes: 1024
h,w = map(int, raw_input().split())
m = [ raw_input() for _ in range(h) ]
hl = [ True for _ in range(h) ]
wl = [ True for _ in range(w) ]
for y in range(h):
    for x in range(w):
        if m[y][x] == '#':
            hl[y] = False
            wl[x] = False
for y in range(h):
    if hl[y]:
        continue
    s = ""
    for x in range(w):
        if wl[x]:
            continue
        s += m[y][x]
    print s


Measured memory_bytes: 2568
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    val c = sc.nextInt()

    if ((b/a).toInt() >= c) {
        println(c)
    } else {
        println((b/a).toInt())
    }
}

Measured memory_bytes: 31264
n=int(input())
a=list(map(int,input().split()))
if n==1:
    print(a[0])
else:
    if n%2==0:
        b=a[n-1:0:-2]+a[0:n-1:2]
    else:
        b=a[n-1:0:-2]
        b.append(a[0])
        b+=a[1:n:2]
    ans=""
    ans+=str(b[0])
    for i in range(1,n):
        ans+=" "+str(b[i])
    print(ans)

Measured memory_bytes: 26180
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>

using namespace std;


bool solve(){

	for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			cout<< i<< "x"<< j<< "="<< i*j<< endl;
		}
	}
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

 

Measured memory_bytes: 1116
#include <iostream>
#include<cstdio>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<cstring>

using namespace std;

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<10;i++)
    {
        if(i*111>=n)
        {
            printf("%d\n",i*111);
            return 0;
        }
    }







    return 0;
}


Measured memory_bytes: 256
#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[i];
    }
    sort(a.begin(), a.end());
    int A[2] = {};
    for (int i = 0; i < N; i++) {
        A[i % 2] += a[i];
    }
    cout << abs(A[0]-A[1]) << endl;
}

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

int main() {
    int M, N; scanf("%d%d", &M, &N);
    int X[100000][2]; rep(i, N) rep(j, 2) scanf("%d", &X[i][j]);
    int P[100000]; rep(i, N) P[i] = i;
    auto cmpX = [&X](int l, int r)->bool {
        return make_pair(X[l][0], X[l][1]) < make_pair(X[r][0], X[r][1]);
    };
    sort(P, P + N, cmpX);
    LL ans[100000]; int p = 0, pp = -1;
    rep(i, N) {
        ans[P[i]] = (LL)X[P[i]][0] * 1000000;
        if (X[P[i]][0] != pp) { p = 0; pp = X[P[i]][0]; }
        p++;
        ans[P[i]] += p;
    }

    rep(i, N) printf("%.12lld\n", ans[i]);

    return 0;
}

Measured memory_bytes: 5784
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e10
using namespace std;
typedef pair<ll, ll> P;


int main(void) {
	int n, k;
	cin >> n >> k;
	vector<int>a(n);
	for (int i = 0;i < n;i++)cin >> a[i];
	int ans = 0, length = 0;
	while (true) {
		ans++;
		length += k;
		if (length >= n)break;
		else length--;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
#define REP(i, m, n) for(ll i = (ll)m; i < (ll)n; i++)
#define PER(i, m, n) for(ll i = (ll)m; i > (ll)n; i--)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define _GLIBCXX_DEBUG

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<1000000007>;

const double PI = 3.14159265358979323846;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

int main(){
    ll n;
    cin >> n;
    vector<ll> v(n);
    REP(i, 0, n) cin >> v[i];
    string ans = "No";
    ll cnt_4 = 0;
    ll odd = 0;

    REP(i, 0, n){
        if(v[i] % 2 == 1) odd++;
        if(v[i] % 4 == 0) cnt_4++;
    }

    if(odd+cnt_4 == v.size() && odd <= cnt_4+1 ) ans = "Yes";
    else if(odd == cnt_4) ans = "Yes";

    cout << ans << endl;
}


Measured memory_bytes: 3968
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String W=sc.next(),T;
		int num=0;
		while(true){
			T=sc.next();
			if(T.equals("END_OF_TEXT")==false){
				if(T.toLowerCase().equals(W)==true){
					num++;
				}
			}
			else{
				break;
			}
		}
		System.out.println(num);
	}
}


Measured memory_bytes: 26364
package main

import "fmt"

func main() {
	num, tmp := 0, ""
	in := map[string]int{}
	fmt.Scanf("%d", &num)
	for i := 0; i < num; i++ {
		fmt.Scanf("%s", &tmp)
		in[tmp]++
	}
	fmt.Println(len(in))
}


Measured memory_bytes: 22148
N,K = list(map(int,input().split()))
h = list(map(int,input().split()))
DP = [float("inf")]*N

for i in range(1,min(K+1,N)):
    DP[i] = abs(h[i]-h[0])

DP[1] = abs(h[1]-h[0])
for i in range(K+1,N):
    for k in range(1,K+1):
        DP[i] = min(DP[i],DP[i-k]+abs(h[i]-h[i-k]))
print(DP[N-1])

Measured memory_bytes: 54880
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int n,w;
int a[10001];
bool b[10001];
int main(){
	cin >> n >> w;
	for (int i=1;i<=n;i++){
		cin >> a[i];
	}
	sort(a+1,a+1+n);
	for (int i=1;i<=n;i++){
		if (a[i]>w){
			n=i-1;
			break;
		}
	}
//	for (int i=1;i<=n;i++) cout << a[i] << ' ';
//	cout << endl;
//	cout << "n=" << n << endl;
	int ans=0;
	int le=1,ri=n;
	while (le<=ri){
		int mi=(le+ri)/2;
		for (int j=1;j<=w;j++) b[j]=false;
		b[0]=true;
		for (int j=1;j<=n;j++){
			if (j!=mi){
				for (int k=w-1;k>=a[j];k--){
					b[k]=b[k] || b[k-a[j]];
				}
			}
		}
//		cout << mi << ' ' << a[mi] << '=' << endl;
//		for (int j=1;j<=w;j++) cout << b[j] << ' ';
//		cout << endl; 
		bool f=false;
		for (int j=w-a[mi];j<=w-1;j++){
			if (b[j]==true){
				ri=mi-1;
				f=true;
				break;
			}
		}
		if (f==false){
			if (ans<mi) ans=mi;
			le=mi+1;
		}
	}
	cout << ans;
	return 0;
}
/*
3 6
1 4 3
6 20
10 4 3 10 25 2
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

void	solve()
{
	string s, t;
	cin >> s >> t;

	int n = t.size();
	int ans = 0;
	rep(i, n) {
		if (t[i] != s[i])
			ans++;
	}
	cout << ans << endl;
}

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

	solve();
}



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

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int total = 0;
  for (int i = 1; i <= N; ++i) {
    int sum = findSumOfDigits(i); // i の各桁の和
    if (sum >= A && sum <= B) { //  i の各桁の和が A 以上 B 以下かどうか
      total += i;
    }
  }
  cout << total << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

ll mod = 998244353;

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

  vector<pair<ll,ll>> lr(k);
  for (auto &v : lr) {
    ll l, r;
    cin >> l >> r;
    v = make_pair(l, r);
  }


  vector<ll> vec1(5e5, 0), vec2(5e5, 0), vec3(5e5, 0);
  vec1[1] = 1;
  vec2[1] = 1;
  vec3[1] = 1;

  for (ll i = 1;  i < n; ++i) {
    for (auto &v : lr) {
      ll l = v.first;
      ll r = v.second;
      vec1[i + l] = (vec1[i + l] + vec3[i]) % mod;
      vec2[i + r] = (vec2[i + r] + vec3[i]) % mod;
    }
    vec3[i+1] = (vec3[i] - vec2[i]) % mod;
    if (vec3[i + 1] < 0)
      vec3[i+1] += mod;
    vec3[i+1] = (vec3[i+1] + vec1[i+1]) % mod;
  }

  cout << vec3[n] << endl;

}


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

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

  string res = "No";
  if (n % 2 == 0) {
    string s1 = s.substr(0, n / 2);
    string s2 = s.substr(n / 2, n);
    if (s1 == s2) res = "Yes";
  }

  cout << res << endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<int>arr(n+1);
	for(int i=1; i<=n; i++)
	 cin>>arr[i];
	int table[n+1];
	table[1]=0;
	for(int i=2; i<=n; i++){
		if(i==2)
		 table[i]=abs(arr[i]-arr[i-1]);
		else
		 table[i]=min(table[i-1]+abs(arr[i]-arr[i-1]),table[i-2]+abs(arr[i]-arr[i-2]));
	}
	cout<<table[n];
	return 0;
}

Measured memory_bytes: 4008
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] d = new int[n];
        for(int i = 0;i<n;i++){
            d[i] = sc.nextInt();
        }
        Arrays.sort(d);
        int count = d[(n-1)/2+1]-d[(n-1)/2];
        System.out.println(count);
    }
}

Measured memory_bytes: 51976
import math

# 素因数分解
def f(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

n = int(input())
mod = 10**9 + 7
ans = 1
cnt = [0] * (n+1)

for i in range(2,n+1):
    fac = f(i)
    for j in range(len(fac)):
        cnt[fac[j][0]] += fac[j][1]

for c in cnt:
    ans *= c+1
    ans %= mod
print(ans)

Measured memory_bytes: 3064
n,m=map(int, input().split())
x=list(map(int, input().split()))

x=sorted(x)
dis=[0]*(m-1)
for i in range(m-1):
    dis[i]=x[i+1]-x[i]
dis=sorted(dis,reverse=True)[(n-1):]
print(sum(dis))

Measured memory_bytes: 13960
#include <iostream>
#include <cstring>

int x[4], y[4];
int board[4][4];

using namespace std;

int rec(int card)
{
	int i, j, k, nx, ny, out = 0;

	if( card > 8 )
		return 1;
	
	for( j = 0; j < 4; j++)
	{
		for( i = 0; i < 4; i++ )
		{
			if(board[j][i] == 0)
				break;
		}
		
		if( i != 4 )
			break;
	}
	
	board[j][i] = 1;
	
	for( k = 0; k < 4 ; k++)
	{
		nx = i+x[k], ny = j+y[k];
	
		if(nx >= 0 && nx < 4 && ny >= 0 && ny < 4 && board[ny][nx] == 0 )
		{
			board[ny][nx] = 1;
			out += rec(card+1);
			board[ny][nx] = 0;
		}
	}
	
	board[j][i] = 0;
	
	return out;
}



int main()
{

	while(1)
	{
		
		memset(board, 0, sizeof(board));

		for( int i = 0; i < 4 ; i++)
		{
			cin >> x[i];
			
			if( x[i] > 4 )
				return 0;
			
			cin >> y[i];
		}
		
		int out = rec(1);
		
		cout << out << endl;
		
	}
	
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define il inline
#define outy printf("Yes\n")
#define outn printf("No\n")
#define outf printf("First\n")
#define outs printf("Second\n")
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FORD(a,b,c) for(int a=b;a>=c;a--)
#define FORL(a,b) for(int a=head[b];a;a=nxt[a])
#define in(a)  a=read()
#define in2(a,b)  a=read(),b=read()
#define in3(a,b,c)  a=read(),b=read(),c=read()
#define in4(a,b,c,d)  a=read(),b=read(),c=read(),d=read()
#define inl(a)  a=readl()
#define inl2(a,b)  a=readl(),b=readl()
#define inl3(a,b,c)  a=readl(),b=readl(),c=readl()
#define inl4(a,b,c,d)  a=readl(),b=readl(),c=readl(),d=readl()
#define out(a) printf("%d\n",a)
#define out2(a,b) printf("%d %d\n",a,b)
#define out3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define outl(a) printf("%lld\n",a)
#define outl2(a,b) printf("%lld %lld\n",a,b)
#define outl3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define outl4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define clr(x,y) memset(x,y,sizeof(x))
inline int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
inline ll readl(){
    char c;ll s=0;int t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
/*------------------------------------------------------------*/
#define mod 1000000007
#define maxn 100010
#define inf 0x7fffffff
/*------------------------------------------------------------*/
ll n,k;
ll a[maxn],b[maxn];
bool check(ll x){
	ll ans=0;
	FOR(i,1,n){
		if(x<a[i])continue;
		ans+=(x-a[i])/b[i]+1;
	}
	return ans>=k;
}
int main(){
	inl2(n,k);
	FOR(i,1,n)inl2(a[i],b[i]); 
	ll l=-1,r=2000000000000000000;
	while(l+1<r){
		ll m=(l+r)>>1;
		if(check(m))r=m;
		 else l=m;
	}
	outl(r);
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int id[200010];
int root(int i){
  return !id[i]?i:id[i]=root(id[i]);
}
int main(){
  int n,q; cin>>n>>q;
  while(q--){
    int t,u,v; cin>>t>>u>>v; u++, v++;
    if(t){
      cout<<(root(u)==root(v))<<"\n";
    } else{
      if(root(v)!=root(u))
      	id[root(v)]=root(u);
    }
  }
}

Measured memory_bytes: 4356
#include <cstdio>
#include <iostream>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

int n;
char buf[1000];

int main(void) {
  cin >> n >> buf;
  int cur = 0;
  int a = 0;
  int b = 0;
  REP(i, n) {
    if(buf[i] == '(') {
      cur++;
    } else {
      if(cur == 0) {
        ++a;
      } else {
        --cur;
      }
    }
  }
  b = cur;
  
  REP(i, a) {
    printf("%c", '(');
  }
  printf("%s", buf);
  REP(i, b) {
    printf("%c", ')');
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

struct dice {
	int up;
	int front;
	int right;
	int left;
	int back;
	int down;
};

int main(void)
{
	char a[101];
	int i, wk;
	struct dice d;
	
	scanf("%d%d%d%d%d%d", &d.up, &d.front, &d.right, &d.left, &d.back, &d.down);
	scanf("%s", a);
	for(i = 0; a[i] != 0x00; i++){
		switch(a[i]){
			case 'N':
				wk      = d.up;
				d.up    = d.front;
				d.front = d.down;
				d.down  = d.back;
				d.back  = wk;
				break;
			case 'E':
				wk      = d.left;
				d.left  = d.down;
				d.down  = d.right;
				d.right = d.up;
				d.up    = wk;
				break;
			case 'W':
				wk      = d.right;
				d.right = d.down;
				d.down  = d.left;
				d.left  = d.up;
				d.up    = wk;
				break;
			case 'S':
				wk      = d.back;
				d.back  = d.down;
				d.down  = d.front;
				d.front = d.up;
				d.up    = wk;
				break;
		}
	}
	printf("%d\n", d.up);
	
	return(0);
}



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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
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;}
const int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
 
    vector<ll> s(n + 1, 0);
    vector<ll> x(n + 1, 0);
    ll a;
    FOR(i, 1, n + 1) {
        cin >> a;
        s[i] = s[i - 1] + a;
        x[i] = x[i - 1] ^ a;
    }

    ll t = 0;
    ll r = 1;
    FOR(l, 1, n + 1) {
        t += r - l + 1;
        while (r < n && (s[r + 1] - s[l - 1]) == (x[r + 1] ^ x[l - 1])) {
            t++;
            r++;
        }
    }
    cout << t << endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define md 1000000007
#define ld long double
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n, i = 0, j= 0, k = 0, l = 0, m = 0, a = 0, b = 0, sum = 0, x = 0, y = 0, z = 0, c, p;
    ld e, f, g;
    cin >> a >> b >> c;
    if(c <= a+b){
        cout << "No";
        return 0;
    }
    x = c*c + a*a + b*b - 2*a*c - 2*a*b - 2*b*c;
    if(x <= 0){
        cout << "No";
        return 0;
    }
    cout << "Yes";

    return 0;
}


Measured memory_bytes: 256
use std::str::FromStr;
 
/*fn read<T: FromStr>() -> T{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
*/
fn read_vec<T: FromStr>() -> Vec<T>{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|x| x.parse().ok().unwrap()).collect()
}
 
fn get_rad(angle:&f64, size:&f64) -> Vec<f64>{
    
    let rad = std::f64::consts::PI / 180.0 * angle; 
    
    vec![size*&rad.sin(), size*&rad.cos()]
}
 
fn main(){
    let data:Vec<f64> = read_vec();
    
    let angle_min = 6.0 * &data[3];
    let angle_hour = 30.0 * &data[2] + angle_min / 12.0;
    
    let min = get_rad(&angle_min, &data[1]);
    let hour = get_rad(&angle_hour, &data[0]);
    let result = ((min[0] - hour[0]) * (min[0] - hour[0]) + (min[1] - hour[1]) * (min[1] - hour[1])).sqrt();
    println!("{}", result);
}

Measured memory_bytes: 2888
N, L = map(int, input().split())
aji_list = [L+i for i in range(N)]

if 0 in aji_list:
    aji_list.remove(0)
elif min(aji_list) > 0:
    aji_list.remove(min(aji_list))
else:
    aji_list.remove(max(aji_list))
print(sum(aji_list))

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

using namespace std;

bool comparejobs(pair<int,int> j1, pair<int,int> j2) {
    return j1.second < j2.second;
}

int main() {
    int N; cin >> N;
    int t1, t2;
    vector<pair<int,int>> Jobs(N);
    for(int i = 0; i < N; ++i) {
        cin >> t1 >> t2;
        Jobs[i] = make_pair(t1,t2);
    }
    sort(Jobs.begin(), Jobs.end(), comparejobs);
    /*cout << endl << endl;
    for(int i = 0; i < N; ++i) {
        cout << Jobs[i].first << " " << Jobs[i].second << endl;
    }*/
    int sumi = 0;
    bool succ = true;
    for(int i = 0; i < N; ++i) {
        sumi += Jobs[i].first;
        if(sumi > Jobs[i].second) {succ = false;}
    }
    
    if(succ) {cout << "Yes";}
    else{cout << "No";}
}

Measured memory_bytes: 4828
int main(){
	int N, K;
	scanf("%d", &N);
	scanf("%d", &K);
	int D, A;
	int count[N];
	for(int i=0; i<N;i++)
		count[i]=0;
	for(int i=0;i<K;i++){
		scanf("%d", &D);
		for(int j=0;j<D;j++){
			scanf("%d", &A);
			count[A-1]++;
		}
	}
	int c = 0;
	for(int i=0;i<N;i++)
		if(count[i]==0)
			c++;
	printf("%d", c);

	return 0;
}

Measured memory_bytes: 1728
// finish date: 2018/01/20
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define bigmod 1000000007
#define INF 500000000


int main() {
    int H, W;
    cin >> H >> W;
    string s;
    rep(i, W + 2) cout << "#";
    cout << endl;
    rep(i, H) {
        cin >> s;
        cout << "#";
        cout << s;
        cout << "#" << endl;
    }
    rep(i, W + 2) cout << "#";
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 101010101000;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
queue<pii> U;
char s[25][25];
int h,w;

int bfs(int x, int y){
  int dist[25][25];
  rep(i,h){
    rep(j,w){
      dist[i][j]=-1;
    }
  }
  dist[x][y]=0;
  int max=0;
  pii p = make_pair(x,y);
  U.push(p);
  while(!U.empty()){
    pii p_0 = U.front();
    U.pop();
    rep(i,4){
      int nx = p_0.first + dx[i];
      int ny = p_0.second + dy[i];
      if(nx>=h||nx<0||ny>=w||ny<0) continue;
      if(s[nx][ny]=='#') continue;
      if(dist[nx][ny]!=-1) continue;
      pii np = make_pair(nx,ny);
      dist[nx][ny]=dist[p_0.first][p_0.second]+1;
      if(dist[nx][ny]>max) max = dist[nx][ny];
      U.push(np);
    }
  }
  return max;
}

int main(){
  cin >> h >> w;
  rep(i,h){
    rep(j,w){
      cin >> s[i][j];
    }
  }
  ll max = 0;
  rep(i,h){
    rep(j,w){
      if(s[i][j]=='.'&&max<bfs(i,j)) max = bfs(i,j);
      //cout << bfs(i,j) << " ";
    }
    //cout << endl;
  }
  cout << max;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, ll> Pil;

ll a, b, c, d;

int main() {
    cin >> a >> b >> c >> d;

    ll ans = max(a*c, a*d);
    ans = max(ans, max(b*c, b*d));
    
    cout << ans << endl;
    
    return 0; 
}

Measured memory_bytes: 3596
n = int(input())
d = list(map(int, input().split()))
mod = 998244353

a = [0] * n
for d_ in d:
    a[d_] += 1

res = d[0] == 0 and a[0] == 1
for i, j in zip(a, a[1:]):
    res = res * i ** j % mod

print(res)

Measured memory_bytes: 14020
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

typedef pair<int, int> pii;
typedef pair<int, pii> pipii;

int main(){
	ios_base::sync_with_stdio(false);
	while(true){
		int n, m;
		cin >> n >> m;
		if(n == 0 && m == 0){ break; }
		vector<pipii> seq(m);
		for(int i = 0; i < m; ++i){
			int t, s, d;
			cin >> t >> s >> d;
			--s; --d;
			seq[i] = pipii(t, pii(s, d));
		}
		sort(seq.begin(), seq.end());
		vector<int> s(m), d(m);
		for(int i = 0; i < m; ++i){
			s[i] = seq[i].second.first;
			d[i] = seq[i].second.second;
		}
		vector<int> infect(n, -1);
		infect[0] = 0;
		for(int i = 0; i < m; ++i){
			if(infect[s[i]] >= 0){ infect[d[i]] = i; }
		}
		int answer = 0;
		for(int i = 0; i < n; ++i){
			if(infect[i] >= 0){ ++answer; }
		}
		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 1592
// B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<string>

using namespace std;

int main()
{
    string s, s1, s2;
    cin >> s;
    s1 = s.substr(0, 2);
    s2 = s.substr(2, 2);

    if ((s1 == "01" || s1 == "02" || s1 == "03" || s1 == "04" || s1 == "05" || s1 == "06" ||
        s1 == "07" || s1 == "08" || s1 == "09" || s1 == "10" || s1 == "11" || s1 == "12")&&
        (s2 == "01" || s2 == "02" || s2 == "03" || s2 == "04" || s2 == "05" || s2 == "06" ||
            s2 == "07" || s2 == "08" || s2 == "09" || s2 == "10" || s2 == "11" || s2 == "12")) {
        cout << "AMBIGUOUS" << endl;
    }
    else if (s1 == "01" || s1 == "02" || s1 == "03" || s1 == "04" || s1 == "05" || s1 == "06" ||
        s1 == "07" || s1 == "08" || s1 == "09" || s1 == "10" || s1 == "11" || s1 == "12") {
        cout << "MMYY" << endl;
    }
    else if (s2 == "01" || s2 == "02" || s2 == "03" || s2 == "04" || s2 == "05" || s2 == "06" ||
        s2 == "07" || s2 == "08" || s2 == "09" || s2 == "10" || s2 == "11" || s2 == "12") {
        cout << "YYMM" << endl;
    }
    else {
        cout << "NA" << endl;
    }

    return 0;

}



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

ll N;
string A, B, C;
ll ret = 0;

void input(){
    cin >> N >> A >> B >> C;
}
void solve(){
    for(ll i=0;i<N;i++){
        char a, b, c;
        a = A[i];
        b = B[i];
        c = C[i];
        if(a==b && b==c){
            continue;
        }else if(a==b || b==c || c==a){
            ret += 1;
        }else{
            ret += 2;
        }
    }
}

int main(void){
    input();
    solve();
    cout << ret << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int counter(string s,string t){
  int ans = 0;
  for(char c='a';c<='z';c++){
    bool found_s = false;
    bool found_t = false;
    for(int i=0;i<s.length();i++){
      if(s.at(i)==c){
        found_s = true;
      }
    }
    for(int j=0;j<t.length();j++){
      if(t.at(j)==c){
        found_t = true;
      }
    }
    if(found_s && found_t){
      ans++;
    }
  }
  return ans;
}
int main(){
  int n;
  string s;
  cin>>n>>s;
  int ans = 0;
  for(int i=1;i<n;i++){
    int count = counter(s.substr(0,i),s.substr(i));
    ans = max(ans,count);
  }
  cout<<ans<<endl;
  return 0;
}


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

#define ll long long
#define pii pair<int, int>
#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define FORD(i, a, b) for (int i=a; i>=b; i--)
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

using namespace std;

void solve() {
    float A, B;
    cin >> A >> B;
    float N = (B - 1) / (A - 1);
    int ans = ceil(N);
    print(ans);
}

signed main() {
    solve();
}


Measured memory_bytes: 384
#include<stdio.h>
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(a==7&&b==5&&c==5||b==7&&a==5&&c==5||c==7&&a==5&&b==5)
	printf("YES\n");
	else
	printf("NO\n");
	return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
#define llong long long
#define mkpr make_pair
#define riterator reverse_iterator
using namespace std;

inline int read()
{
	int x = 0,f = 1; char ch = getchar();
	for(;!isdigit(ch);ch=getchar()) {if(ch=='-') f = -1;}
	for(; isdigit(ch);ch=getchar()) {x = x*10+ch-48;}
	return x*f;
}

const int N = 1e6;
char a[N+3],b[N+3]; bool f[N+3];
char permu[3],permui[3]; int cnt[3],cnt2[3];
int n,n0;

bool cmp_cnt(int x,int y) {return cnt[x]<cnt[y];}

void reset()
{
	n0 = 0; for(int i=1; i<=n; i++) {if(!f[i]) b[++n0] = a[i];}
	n = n0; for(int i=1; i<=n; i++) a[i] = b[i];
}

int main()
{
	scanf("%s",a+1); n = strlen(a+1);
	for(int i=1; i<=n; i++) a[i] -= 'A';
	memset(f,false,sizeof(f));
	for(int i=2; i<=n; i++) if(a[i]==a[i-1]) f[i] = true;
	reset();
	
	for(int i=1; i<=n; i++) cnt[a[i]]++;
	for(int i=0; i<3; i++) permu[i] = i;
	sort(permu,permu+3,cmp_cnt); sort(cnt,cnt+3);
	for(int i=0; i<3; i++) permui[permu[i]] = i;
	for(int i=1; i<=n; i++) a[i] = permui[a[i]];
	
	int dif = cnt[2]-cnt[1];
	memset(f,false,sizeof(f));
	for(int l=(a[1]==0?2:1); l<=n;)
	{
		int r = l;
		while(r<n&&a[r+1]!=0) {r++;}
		if(dif>0&&!(l==r&&l>1&&r<n)&&!(a[l]==1&&a[r]==1))
		{
			if(a[l]==2&&dif>0) {f[l] = true; dif--;}
			if(r>l&&a[r]==2&&dif>0) {f[r] = true; dif--;}
		}
		l = r+2;
	}
	reset();
	
	if(dif>0)
	{
		memset(f,false,sizeof(f));
		for(int l=(a[1]==0?2:1); l<=n;)
		{
			int r = l;
			while(r<n&&a[r+1]!=0) {r++;}
			if(l==r&&a[l]==2&&l>1&&r<n&&dif>0) {f[l] = f[l-1] = true; dif--;}
			l = r+2;
		}
		reset();
	}
	
	memset(cnt,0,sizeof(cnt));
	for(int i=1; i<=n; i++) cnt[a[i]]++;
	dif = cnt[1]-cnt[0];
	memset(f,false,sizeof(f));
	for(int l=(a[1]==0?2:1); l<=n;)
	{
		int r = l;
		while(r<n&&a[r+1]!=0) {r++;}
		int rst = r-l+1;
		for(int i=l+1; i<=r; i++)
		{
			if(a[i]==2&&a[i-1]==1&&dif>0&&(l==1||r==n||rst>2)) {f[i] = f[i-1] = true; dif--; rst-=2;}
		}
		l = r+2;
	}
	reset();
	
	for(int i=1; i<=n; i++) printf("%c",permu[a[i]]+'A'); puts("");
	return 0;
}

Measured memory_bytes: 4096
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<list>
#include<numeric>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;
using namespace std;
template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

template<typename T>
T binarysearch(vector<T> A, T key) {
	ll left = 0;ll right = 4;ll mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (key == A[mid]) return 1;
		if (key > A[mid]) left = mid + 1;
		else if (key < A[mid]) right = mid;
	}
	return 0;
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)//階乗
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

template<typename T>
T keta(T a) {
	ll kazu = 1;
	while (1) {
		if (a / 10 != 0) { a /= 10;kazu++; }
		else break;
	}
	return kazu;
}//桁数


template<typename T>
T nCr(ll n, T r) {
	ll ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*/
int main() {
	double N,M;cin >> N>>M;
	vector<double>A(N);
	double sum = 0;
	ll ok=0;
	for (int i = 0;i < N;i++) {
		cin >> A[i];
		sum += A[i];
	}
	//bool ok = true;
	for (int i = 0;i < N;i++) {
		if ((A[i] / sum) >= 1 / (4 * M)) ok++;
	}
	if (ok >= M) cout << "Yes" << endl;
	else cout << "No" <<endl;
}

Measured memory_bytes: 256
import sys
h,w,m = map(int,input().split())
h_lst = [[0,i] for i in range(h)]
w_lst = [[0,i] for i in range(w)]
memo = []

for i in range(m):
  x,y = map(int,input().split())
  h_lst[x-1][0] += 1
  w_lst[y-1][0] += 1
  memo.append((x-1,y-1))

h_lst.sort(reverse = True)
w_lst.sort(reverse = True)
Max_h = h_lst[0][0]
Max_w = w_lst[0][0]
h_ans = [h_lst[0][1]]
w_ans = [w_lst[0][1]]
if h != 1:
  s = 1
  while s < h and h_lst[s][0] == Max_h:
    h_ans.append(h_lst[s][1])
    s+= 1  
if w!= 1:  
  t=1  
  while t < w and w_lst[t][0] == Max_w:
    w_ans.append(w_lst[t][1])
    t += 1
  

memo = set(memo)

#探索するリストは、最大を取るものの集合でなければ計算量はO(m)にはならない！             
for j in h_ans:
  for k in w_ans:
    if (j,k) not in memo:
      print(Max_h+Max_w)
      sys.exit()
print((Max_h+Max_w)-1)        
  



Measured memory_bytes: 137792
import math
a, b, C = map(int, input(). split())
S = (1/2)*a*b*math.sin(math.radians(C))
print(f'{S:.8f}')
L = a + b + (math.sqrt(a**2 + b**2 - 2*a*b*(math.cos(math.radians(C)))))
print(f'{L:.8f}')
h = (S*2)/a
print(f'{h:.8f}')


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

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

    int count = 0;
    for (int i = 0; i < S.size(); i++)
    {
        if (S.at(i) != T.at(i))
        {
            count++;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3860
n, x = map(int, input().split())
a = list(map(int, input().split()))

cnt = 0
for i in range(len(a)):
    if a[i] > x:
        cnt += a[i]-x
        a[i] = x

for i in range(1, len(a)):
    if a[i-1] + a[i] > x:
        cnt += a[i-1]+a[i] - x
        a[i] = a[i] - (a[i-1]+a[i] - x)

print(cnt)


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

int main(){
   int n,q,C=0;
   cin >> n;
   vector<int> S(n);
   for(int i=0;i<n;i++){
       cin >> S.at(i);
   }
   cin >> q;
   vector<int> T(q);
   for(int i=0;i<q;i++){
       cin >> T.at(i);
   }
   for(int i=0;i<q;i++){
       for(int j=0;j<n;j++){
           if(T.at(i)==S.at(j)){
               C++;
               break;
           }
       }
   }
   cout << C << endl;
}


Measured memory_bytes: 3140
#include<bits/stdc++.h>
//#define ll long long int32_t 
#define int long long int
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define rev(i,n,init) for(int i=n;i>=init;i--)
#define MAXN 200005
#define MOD2 998244353
#define MOD1 1e9+7
#define f first
#define s second
#define endl '\n'
#define pii pair<int,int>
#define piii pair<pii,int>
#define precise(i) cout<<fixed<<setprecision(i)
using namespace std;
const double PI = atan(1.0)*4;
const int64_t INF=1000000000000000003;
const int32_t LOG=21;
const int MOD=MOD1;
int dp[105][100005];
int weight[105];
int val[105];
int32_t main()
{ 
      getFaster;
      int tests=1;
      //cin>>tests;
      rep(ii,0,tests)
      {
         int n,w;
         cin>>n>>w;
         rep(i,1,n+1)cin>>weight[i]>>val[i];
         int sum_vals=0;
         rep(i,1,n+1)
         {
         	sum_vals+=val[i];
         	rep(j,0,100001)
         	{
         		if(j>sum_vals)dp[i][j]=INF;
         		else if(i==1)
         		dp[i][j]=weight[i];
         		else if(val[i]>=j)
         		dp[i][j]=min(dp[i-1][j],weight[i]);
         		else
         		dp[i][j]=min(dp[i-1][j],weight[i]+dp[i-1][j-val[i]]);	         			
         	}
         }
         int ans=0;
         rep(j,0,sum_vals+1)
         {
             if(dp[n][j]<=w)
             ans=j;	
         }
         cout<<ans<<endl;
      }
      return 0;     
}


Measured memory_bytes: 79488
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    int N;
    cin >> N;
    int A[N];
    REP(i,N) cin >> A[i];

    int count = 1;
    int ans = 0;
    REP(i,N){
        if(A[i] == count) count++;
    }
    if(count == 1) cout << -1 << endl;
    else cout << N-count+1 << endl;
}

Measured memory_bytes: 4416
#include<bits/stdc++.h>
using namespace std;
struct Point { double x,y;};
void koch(int n, Point a, Point b){
    if(n==0) return;
    Point s,t,u;
    double th = M_PI * 60.0 / 180.0;
    
    s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
    s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
    t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
    t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
    u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;
    
    koch(n-1,a,s);
    printf("%.8lf %.8lf\n", s.x, s.y);
    koch(n-1,s,u);
    printf("%.8lf %.8lf\n", u.x, u.y);
    koch(n-1,u,t);
    printf("%.8lf %.8lf\n", t.x, t.y);
    koch(n-1,t,b);
}

int main(){
    Point a,b;
    int n;
    cin>>n;
    a.x = 0;
    a.y = 0;
    b.x = 100;
    b.y = 0;
    
    printf("%.8lf %.8lf\n",a.x,a.y);
    koch(n,a,b);
    printf("%.8lf %.8lf\n",b.x,b.y);
    return 0;
}



Measured memory_bytes: 3172
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <cstdio> 
#define N 100000+10
using namespace std; 
int main(){
	int n;
	int s[N],t1[N], t2[N];
	cin >> n;
	for(int i=1; i<=n; i++){
		cin >> s[i];
	}
	int q;
	cin >> q;
	for(int i=1; i<=q; i++){
		cin >> t1[i] >> t2[i];
	}
	for(int i=1; i<=q; i++){
		int sum = 0;
//		sum += s[t[i]];
		for(int j=1; j<=n; j++){
			if(t1[i] == j) sum += t2[i];
			else{
				sum += s[j];
			}
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define black_tree tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define pair_black_tree tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update>
#define gp __gnu_pbds
#define INF 1e18
#define MOD 1000000007
#define MAX 200001
#define endl '\n'
#define ll long long
#define ld long double
#define lli long long int
#define ull unsigned long long
#define ulli unsigned long long int
#define pb push_back
#define pf push_front
#define ook order_of_key
#define fbo find_by_order
#define np next_permutation
#define mp make_pair
#define eb emplace_back 
#define mae max_element
#define mie min_element
#define lb lower_bound 
#define ub upper_bound
#define bs binary_search
#define ff first
#define ss second
using namespace std;
using namespace gp;
ll n,ans,a[MAX],b[MAX];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		b[i]=a[i];
	}
	for(int i=1;i<=n;i++){
		if(b[i]<b[i+1]){
			continue;
		}
		else{
			b[i+1]=b[i];
		}
	}
	for(int i=1;i<=n;i++){
		ans+=b[i]-a[i];
	}
	cout<<ans;
}

Measured memory_bytes: 6776
N, M = map(int,input().split())
interval=[[] for i in range(N)]
for i in range(M):
    l, r, a = map(int,input().split())
    interval[l-1].append((r-1, a))

# N: 処理する区間の長さ
INF = 10**30-1

LV = (N-1).bit_length()
N0 = 2**LV
data = [0]*(2*N0)
lazy = [0]*(2*N0)

def gindex(l, r):
    L = (l + N0) >> 1; R = (r + N0) >> 1
    lc = 0 if l & 1 else (L & -L).bit_length()
    rc = 0 if r & 1 else (R & -R).bit_length()
    for i in range(LV):
        if rc <= i:
            yield R
        if L < R and lc <= i:
            yield L
        L >>= 1; R >>= 1

# 遅延伝搬処理
def propagates(*ids):
    for i in reversed(ids):
        v = lazy[i-1]
        if not v:
            continue
        lazy[2*i-1] += v; lazy[2*i] += v
        data[2*i-1] += v; data[2*i] += v
        lazy[i-1] = 0

# 区間[l, r)にxを加算
def update(l, r, x):
    *ids, = gindex(l, r)
    propagates(*ids)

    L = N0 + l; R = N0 + r
    while L < R:
        if R & 1:
            R -= 1
            lazy[R-1] += x; data[R-1] += x
        if L & 1:
            lazy[L-1] += x; data[L-1] += x
            L += 1
        L >>= 1; R >>= 1
    for i in ids:
        data[i-1] = max(data[2*i-1], data[2*i])

# 区間[l, r)内の最大値を求める
def query(l, r):
    propagates(*gindex(l, r))
    L = N0 + l; R = N0 + r

    s = -INF
    while L < R:
        if R & 1:
            R -= 1
            s = max(s, data[R-1])
        if L & 1:
            s = max(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s

dp=[0]*N

for i in range(N-1, -1, -1):
    for j in range(len(interval[i])):
        r, a = interval[i][j]
        update(i, r+1, a)
    dp[i] = max(query(0, N), 0)
    if i>0: 
        update(i-1, i, dp[i])

print(dp[0])

Measured memory_bytes: 123944
#include <iostream>
#include <vector> 
#include <algorithm>
#include <functional>
using namespace std;

struct price{
    long long int money;
    long long int num;
};

int main(){
	std::vector<price> prices;
	int m,mon,x,y;
	long long int ans = 0;
	cin >> m >> mon;
	long long int remein_m = mon;
    for(int i = 0; i < m; i ++){
        cin >> x >> y;
        prices.push_back({x,y});
    }
    sort(prices.begin(), prices.end(), [](const price& x, const price& y) { return x.money < y.money;});
    
    for(int i = 0; i < m ; i ++){
        //cout << remein_m <<"|"  << ans << endl;
        if(prices[i].num >= remein_m){
            ans += remein_m*prices[i].money;
            break;
        }else{
            ans += prices[i].num*prices[i].money;
            remein_m -=prices[i].num;
        }
    }
    cout << ans << endl;
	return 0;
}



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

int n;
int a[101];
int s;
int dmin = 1e9;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=0; i<n; ++i)
		cin >> a[i];
	for(int i=0; i<n; ++i)
		s += a[i];
	for(int i=0; i<n; ++i)
		dmin = min(dmin, abs(s - a[i] * n));
	for(int i=0; i<n; ++i)
		if(abs(s - a[i] * n) == dmin){
			cout << i << "\n";
			return 0;
		}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<utility>
#define MAX_N 100001
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

P T[MAX_N];

int main() {
    ll N, C, K, t;
    cin >> N >> C >> K;
    for (ll i = 0; i < N; i++) {
        cin >> t;
        T[i] = MP(t, t + K);
    }
    sort(T, T + N);
    ll now_limit = T[0].second, now_capa = 1, ans = 0;
    for (ll i = 1; i < N; i++) {
        if (T[i].first <= now_limit && now_capa < C) now_capa++;
        else {
            ans++;
            now_capa = 1;
            now_limit = T[i].second;
        }
    }
    ans++;
    cout << ans << endl;
    return 0;
}

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


using namespace std;


int main(void){
  
  string s;
  
  cin >> s;
  
   
  if(s[3] == s[2] && s[4] == s[5]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  

  return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<algorithm>
#include<string>
using namespace std;
int a,b,k;
int main()
{
    cin>>a>>b;
    k=a*b;
    if(k%2==0)cout<<"Even"<<endl;
    if(k%2==1)cout<<"Odd"<<endl;
    return 0;
}

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

int main(void) {
	int N;
	cin >> N;
	bool success = true;
	int preH = 0;
	for (int i = 0; i < N; i++) {
		int H;
		cin >> H;
		if (preH < H) {
			preH = H-1;
		} else if (preH == H) {
		} else {
			success = false;
			break;
		}
	}
	if (success) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		while(true){
			int n = in.nextInt(), m = in.nextInt();
			if(n==0 && m==0) return ;
			int money[][] = new int[m][m], time[][] = new int[m][m];
			for(int i=0; i<m; i++)
				for(int j=0; j<m; j++)
					money[i][j] = time[i][j] = 1<<29;
			for(int i=0; i<n; i++){
				int a = in.nextInt()-1, b = in.nextInt()-1;
				money[a][b] = money[b][a] = in.nextInt();
				time[a][b] = time[b][a] = in.nextInt();
			}
			for(int k=0; k<m; k++)
				for(int i=0; i<m; i++)
					for(int j=0; j<m; j++){
						money[i][j] = Math.min(money[i][j], money[i][k] + money[k][j]);
						time[i][j] = Math.min(time[i][j], time[i][k] + time[k][j]);
					}
			int k = in.nextInt();
			for(int i=0; i<k; i++){
				int a = in.nextInt()-1, b = in.nextInt()-1, cmd = in.nextInt();
				if(cmd==0) System.out.println(money[a][b]);
				else System.out.println(time[a][b]);
			}
		}
	}
}

Measured memory_bytes: 14000
#include <bits/stdc++.h>
#define pb push_back
#define sz(a) int(a.size())
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
signed main()
{
	int n,ans=0;
	cin>>n;
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++){
			for (int k=1;k<=n;k++){
				ans+=gcd(gcd(i,j),k);
			}
		}
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long total = n*(n+1)/2;
  long long n3 = n/3;
  long long n5 = n/5;
  long long n15 = n/15;
  long long n31 = ((3+(3*n3))*n3)/2;
  long long n51 = ((5+(5*n5))*n5)/2;
  long long n151 = ((15+(15*n15))*n15)/2;
  //cout << total << endl;
  cout << total - n31 - n51 + n151 << endl;
}

Measured memory_bytes: 3628
using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;

public class Test
{
    public static void Main()
    {
        int[][] table = 
        {
            new int[] {2,2 },
            new int[] {1,3 }
        };

        Console.ReadLine();
        string s = Console.ReadLine();
        string t = Console.ReadLine();
        List<int> type = new List<int>();
        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] == t[i])
            {
                type.Add(0);
            }
            else
            {
                type.Add(1);
                i++;
            }
        }
        long res;
        if (type[0] == 0)
        {
            res = 3;
        }
        else
        {
            res = 6;
        }
        for (int i = 1; i < type.Count; i++)
        {
            res = (res * table[type[i - 1]][type[i]]) % 1000000007;
        }
        Console.WriteLine(res);
    }
}

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

int main(){
  int a,b,c,d,e,f,ant=0,anu=0;
  
  double ans=0;
  
  cin >>a >>b >>c >>d >>e >>f;
  
  for (int i=0;i<=f/(100*a);i++)
    for (int j=0;j<=f/(100*b);j++)
      
      for (int k=0;k<=f/c;k++)
        for (int l=0;l<=f/d;l++){
          
          if(i*a+j*b>0){
            int x=i*a*100+j*b*100;
            if(k*c+l*d>=0){
              
              int y=k*c+l*d;
              
              if(x+y<=f && x*e>=y*100){
                double anv=double(y)/double(x);
                if (ans<=anv){
                  ans=anv;
                  anu=x+y;
                  
                  ant=y;
                }
              }
            }
          }
        }
  cout << anu <<" "<< ant <<endl;

}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define MAX 20000000

int H,A[MAX+1];


void maxheapify(int i)
{
  int left;
  int right;
  int change;
  int large;
  
  left = 2*i;
  right = 2*i+1;
  
  if( left <= H && A[left] > A[i] ){
    large = left;
  }
  else{
    large = i;
  }
  
  if( right <= H && A[right] > A[large] ){
    large = right;
  }
  
  if( large != i ){
    change = A[i];
    A[i] = A[large];
    A[large] = change;
    maxheapify(large);
  }
}


int ex()
{
  int max;
  if( H < 1 ) return -1000000000;
		
  max = A[1];
  A[1] = A[H--];
  maxheapify(1);
  return max;
}

void increase(int i, int key)
{
  
  int change;
  
  if( key < A[i] )return;
  A[i] = key;
  while( i > 1 && A[i/2] < A[i] ){
    change = A[i];
    A[i] = A[i/2];
    A[i/2] = change;
    i = i / 2;
  }
}

void insert( int key )
{
  H++;
  A[H] = -1000000000;
  increase(H,key);
}

int main()
{
  int key;
  char com[10];

  while(1){
    scanf("%s",com);
    if( com[0] == 'e' && com[1] == 'n' )break;
    if( com[0] == 'i' ){
      scanf("%d",&key);
      insert(key);
    }
    else{
      printf("%d\n",ex());
    }
  }
  return 0;
}



Measured memory_bytes: 5624