akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
  long long int a,sum[200001];
  int n,p;
  long ans=0;
  scanf("%d",&n);
  scanf("%lld",&a);
  sum[0]=a;
  for(int i=0;i<n;i++){
    scanf("%lld",&a);
    sum[i+1]=sum[i]+a;
  }
  sort(sum,sum+n);
  sum[n]=sum[n-1]+1;
  a=sum[0];
  p=0;
  for(int i=1;i<=n;i++){
    if(a!=sum[i]){
      ans+=(long)(i-p)*(i-p-1)/2;
      if(a==0)
        ans+=(long)(i-p);
      a=sum[i];
      p=i;
    }
  }
  printf("%ld\n",ans);
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ld long double
#define pii pair<int,int>
int const M=2e5+10,M2=300+10,inf=1e9+10,mod=1e9+7;
int a[M];
int32_t main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	int ans=0;
	for(int i=1;i<=n;i++)cin>>a[i];
	bool flag=1;
	for(int i=1;i<=n;i++)
	{
		if(!flag && a[i]==a[i-1])ans++,flag=1;
		else flag=0;
	}
	cout<<ans;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))

for i in range(n-1):
    if h[i] > h[i+1]:
        h[i] -= 1

    elif i != 0:
        if h[i]==h[i+1] and h[i-1]<=h[i]-1:
            h[i] -= 1


for j in range(n-1):
    if h[j] > h[j+1]:
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 14396
import java.util.Scanner;

public class Main {

    private static final int MAX_N = 100;
    private static final int INF = 1 << 21;
    private static final int WHITE = 0;
    private static final int GRAY = 1;
    private static final int BLACK = 2;

    private static int n;
    private static int[][] M = new int[MAX_N][MAX_N];


    private static void dijkstra() {
        // initialize
        int[] color = new int[MAX_N]; // visited or not
        int[] d = new int[MAX_N]; // min edge

        for (int i = 0; i < n; i++) {
            color[i] = WHITE;
            d[i] = INF;
        }

        // start node
        d[0] = 0;
        color[0] = GRAY;

        while (true){
            int u = -1;
            int minv = INF;

            // find minimum value vertex
            for (int i = 0; i < n; i++) {
                if (color[i] != BLACK && d[i] < minv){
                    minv = d[i];
                    u = i;
                }
            }

            // didn't find any vertex
            if (u == -1)
                break;
            color[u] = BLACK;

            // add new edges
            for (int v = 0; v < n; v++) {
                if (color[v] != BLACK && M[u][v] != INF){
                    if (d[v] > M[u][v] + d[u]) {
                        d[v] = M[u][v] + d[u];
                        color[v] = GRAY;
                    }
                }

            }

        }

        for (int i = 0; i < n; i++) {
            System.out.println(
                    i + " " + (d[i] == INF ? -1 : d[i])
            );
        }

    }

    private static void input() {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                M[i][j] = INF;
            }
        }

        for (int i = 0; i < n; i++) {
            int u = scanner.nextInt();
            int k = scanner.nextInt();
            for (int j = 0; j < k; j++) {
                M[u][scanner.nextInt()] = scanner.nextInt();
            }
        }
    }

    public static void main(String[] args){
        input();
        dijkstra();
    }
}

Measured memory_bytes: 40156
#include<iostream>
using namespace std;
int main()
{
	while(1){
		int n,x,counter=0;
		cin >> n >> x;
		if(n==0 && x==0)break;
		for(int i=1;i<=n;++i){
			for(int j=i+1;j<=n;++j){
				for(int k=j+1;k<=n;++k){
					if(i+j+k==x)counter+=1;
				}
			}
		}
		cout << counter << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		int max = 0;
		long ans = 0;
		string[] str = Console.ReadLine().Split();
		for(var i=0;i<N;i++){
			int a = int.Parse(str[i]);
			if(max>a){
				ans += max-a;
			}
			max = Math.Max(a,max);
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 43384
#include <stdio.h>

int main (void) {
    int n;
    int a[20];
    int b[50];
    int c[50];
    int sum = 0;

    scanf("%d", &n);

    for (int k = 0; k < n; k++) {
        scanf("%d", &a[k]);
    }
    for (int k = 0; k < n; k++) {
        scanf("%d", &b[k]);
    }
    for (int k = 0; k < n-1; k++) {
        scanf("%d", &c[k]);
    }

    for (int k = 0; k < n; k++) {
        sum += b[a[k]-1];
        if (a[k+1] == a[k]+1) {
            sum += c[a[k]-1];
        }
    }

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




}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  string s;
  cin >> n >> s;

  int count=1;
  char tmp=s.at(0);
  for(int i=1;i<n;i++){
  	if(s.at(i)!=tmp){
  		count++;
  	}
  	tmp = s.at(i);
  }
  cout << count << endl;
}

Measured memory_bytes: 512
N = int(input())
E = [set() for i in range(N)]
for i in range(N-1):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  E[a].add(b)
  E[b].add(a)
cs = list(map(int, input().split()))
cs.sort()
M = sum(cs[:-1])
ds = [-1]*N
ds[0] = cs.pop()
q = [0]
while q:
  c = q.pop()
  ns = E[c]
  for n in ns:
    if ds[n] < 0:
      ds[n] = cs.pop()
      q.append(n)
print(M)
print(" ".join(map(str, ds)))


Measured memory_bytes: 7276
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

constexpr int64_t DIV1097 = 1000000007LL;

using namespace std;

int main()
{
    int64_t H, W;
    std::cin >> H >> W;

    std::map<char, size_t> C;
    for (size_t i = 0; i < H*W; ++i) {
        char c;
        std::cin >> c;
        C[c]++;
    }

    int64_t f, t;
    f = t = 0;
    for (auto ac: C) {
        if (ac.second % 4 == 1) {
            f++;
        }
        if (ac.second % 4 == 3) {
            f++;
            t++;
        }
        if (ac.second % 4 == 2) {
            t++;
        }
    }

    if (H%2 == 1 && W%2 == 1) {
        if (f != 1) {
            std::cout << "No" << std::endl;
            return 0;
        }
        if (t > (H-1)/2 + (W-1)/2) {
            std::cout << "No" << std::endl;
            return 0;
        }
    }
    else if (H%2 == 0 && W%2 == 0) {
        if (f != 0 || t != 0) {
            std::cout << "No" << std::endl;
            return 0;
        }
    }
    else if (H%2 == 1 && W%2 == 0) {
        if (f != 0) {
            std::cout << "No" << std::endl;
            return 0;
        }
        if (t > std::abs(W/2)) {
            std::cout << "No" << std::endl;
            return 0;
        }
    }
    else {
        if (f != 0) {
            std::cout << "No" << std::endl;
            return 0;
        }
        if (t > std::abs(H/2)) {
            std::cout << "No" << std::endl;
            return 0;
        }
    }

    std::cout << "Yes" << std::endl;

    return 0;
}


Measured memory_bytes: 256
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on

void main()
{
    long H, W;
    scan(H, W);
    long ans = long.max;
    foreach (h; 1 .. H)
    {
        long a = h * W;
        long b = (H - h) * (W / 2);
        long c = (H - h) * (W - W / 2);
        if (a == 0 || b == 0 || c == 0)
            continue;
        dprint(a, b, c);
        ans = ans.min(max(a, b, c) - min(a, b, c));
    }
    foreach (h; 1 .. H)
    {
        long a = h * W;
        long b = ((H - h) / 2) * W;
        long c = ((H - h) - (H - h) / 2) * W;
        if (a == 0 || b == 0 || c == 0)
            continue;
        dprint(a, b, c);
        ans = ans.min(max(a, b, c) - min(a, b, c));
    }
    foreach (w; 1 .. W)
    {
        long a = w * H;
        long b = (W - w) * (H / 2);
        long c = (W - w) * (H - H / 2);
        if (a == 0 || b == 0 || c == 0)
            continue;
        dprint(a, b, c);
        ans = ans.min(max(a, b, c) - min(a, b, c));
    }
    foreach (w; 1 .. W)
    {
        long a = w * H;
        long b = ((W - w) / 2) * H;
        long c = ((W - w) - (W - w) / 2) * H;
        if (a == 0 || b == 0 || c == 0)
            continue;
        dprint(a, b, c);
        ans = ans.min(max(a, b, c) - min(a, b, c));
    }
    writeln(ans);
}


Measured memory_bytes: 3648
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;

public class Main {
    public static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

    public static int nextInt() {
        try {
            in.nextToken();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return (int) in.nval;
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        int n = nextInt(), a[] = new int[n + 1], num[] = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            a[i] = nextInt();
            num[a[i]]++;
        }
        long sum = 0;
        for (int i = 1; i <= n; i++) {
            if (num[i] > 1)
                sum += (long) num[i] * (num[i] - 1) / 2;
        }
        for (int i = 1; i <= n; i++) {
            int m = num[a[i]];
            if (m > 1)
                out.println(sum - m + 1);
            else {
                out.println(sum);
            }
        }
        out.flush();
    }

}


Measured memory_bytes: 53524
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

typedef tuple<ll, ll, ll> T;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s1,s2,s3;
    cin>>s1>>s2>>s3;
    cout<<char(toupper(s1[0]))<<char(toupper(s2[0]))<<char(toupper(s3[0]))<<endl;
}

Measured memory_bytes: 768
import sys
input = sys.stdin.readline
import bisect
from collections import deque

def main():
    N = int(input())
    use = deque([int(input())])
    for _ in range(N-1):
        num = int(input())
        index = bisect.bisect_left(use,num)
        if index == 0:
            use.appendleft(num)
        else:
            use[index-1] = num
    
    print(len(use))
    
if __name__ == "__main__":
    main()


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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var ss = Console.ReadLine().Split();
            var A = int.Parse(ss[0]);
            var B = int.Parse(ss[1]);

            var halfDiff = (Math.Max(A, B) - Math.Min(A, B)) / 2.0;
            if ((int)halfDiff != halfDiff)
            {
                Console.WriteLine("IMPOSSIBLE");
            }
            else
            {
                Console.WriteLine(halfDiff + Math.Min(A, B));
            }
        }
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll md=1e9+7;
ll pl(int x,int y){//Axy
if(y==0)
return 1;
ll ans=1;
	for(ll i=1;i<=y;i++){
	ans*=(x-i+1);
		ans%=md;
	}
	return ans%md;
}
int main(){
	ll n,m;
	cin>>n>>m;
	ll a,b;
	a=max(n,m);
	b=min(n,m);
	if(b<a-1){
		cout<<"0"<<endl;
		return 0;
	}
   ll ans=((pl(a,a))*(pl(b,a-1)))%md;
	ans=(ans*(pl(2,b-(a-1))))%md;
	cout<<ans<<endl;
	return 0;
	 
}

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

int n, c[200000];

int main() {
	cin >> n;
	for (int i = 0, a; i < n - 1; i++) {
		cin >> a;
		a--;
		c[a]++;
	}
	for (int i = 0; i < n; i++) {
		cout << c[i] << endl;
	}
}


Measured memory_bytes: 4404
//region Template
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
template<typename T> void debug_out(string name, T arg) { cerr<<name<<"="<<arg<<endl; }
template<typename T1, typename... T2> void debug_out(string name, T1 arg, T2... args) {
    cerr<<name.substr(0, name.find(','))<<"="<<arg<<", ";
    debug_out(name.substr(name.find(',') + 1), args...); }
#define debug(...) debug_out(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout<<fixed<<setprecision(12);
#define FOR(i, n) for(int i=0; i<int(n); i++)
#define RNG(i, f, t) for(int i=int(f); i<=int(t); i++)
#define REV(i, f, t) for(int i=int(f); i>=int(t); --i)
#define ALL(v) (v).begin(), (v).end()
#define EXIT(answer) { cerr<<"EXIT #"<<__LINE__<<endl; cout<<answer<<endl; exit(0); }
#define sz(v) int(v.size())
bool RELAXED = false;
template<int,typename T> struct MINMAX{ T val; MINMAX(T val) : val(val) {} };
template<typename T> MINMAX<1,T> MAX(T val) { return MINMAX<1,T>(val); };
template<typename T> MINMAX<2,T> MIN(T val) { return MINMAX<2,T>(val); };
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<1,U> rhs) { return lhs = (rhs.val > lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<2,U> rhs) { return lhs = (rhs.val < lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> istream& operator>>(istream& in, pair<T,U> &p) { in>>p.first>>p.second; return in; }
template<typename T> inline vector<T> READ(int n) { vector<T> vec(n); FOR(i,n) cin>>vec[i]; return vec; }
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T> >;
typedef signed long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
//endregion


const int MOD = 1e9+7;

ll inverseModulo(ll a, ll b){
    return 1<a ? b - inverseModulo(b % a, a) * b / a : 1;
}

int main() {
    FASTIO

    int N,K; cin>>N>>K;
    N++;
    ll ans=0;
    ll mn=0, mx=0;

    RNG(i,1,N) {
        mn += i-1;
        mx += N-i;
        if(i>=K)
            ans += max(0LL, mx-mn+1);
        ans %= MOD;
    }

    cout<<ans<<endl;

}

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

int main () {
  
  int N, M;
  cin >> N >> M;
  
  vector<pair<int , int>> war;
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    if (a > b) swap(a, b);
    war.push_back({b, a});
  }
  
  sort(war.begin(), war.end());
  
  int ans = 0;
  int count = -1;
  
  for (int i = 0; i < M; i++) {
    if (count <= war[i].second) {
      ans ++;
      count = war[i].first;
    }
  }
  
  cout << ans << endl;
  
}

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

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = n - 1; i < (int)n; --i)
#define FOR(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define RFOR(i, l, r) for (int i = (int)(r); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;
    vi a(n), b(n), c(n);
    REP(i, n) cin >> a[i];
    REP(i, n) cin >> b[i];
    REP(i, n) cin >> c[i];

    sort(all(a));
    sort(all(b));
    sort(all(c));

    ll ans = 0;
    for (auto eb : b) {
        ans += (ll)(lower_bound(all(a), eb) - a.begin()) * (ll)(c.end() - upper_bound(all(c), eb));
    }

    cout << ans << endl;

    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int d[1001] = {0};

void devide(int m) {
  int i = 2;
  while (m > 1) {
    bool flag = false;
    if (m % i == 0) {
      d[i]++;
      m /= i;
      flag = true;
    }
    if (!flag) i++;
  }
}

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

  FOR (i, 1, n + 1) {
    devide(i);
  }

  LL ans = 1;
  REP (i, 1001) {
    ans = ans * (d[i] + 1) % int(1e9 + 7);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P	  = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

constexpr ll INF = 1e16;
constexpr ll INM = 114514;
constexpr ll MOD = 1e9 + 7;
constexpr ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, ll t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};

ll a[214514], s[214514] = {};
map<ll, vector<ll>> b;

int main() {
	IOS();
	ll n, k;
	cin >> n >> k;
	b[0].push_back(0);
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
		a[i]--;
		s[i + 1] = s[i] + a[i];
		s[i + 1] %= k;
		b[s[i + 1]].push_back(i + 1);
	}
	ll ans = 0;
	for (ll i = 0; i < n; i++) {
		ll t   = s[i];
		ll tmp = lower_bound(b[t].begin(), b[t].end(), i + k) - lower_bound(b[t].begin(), b[t].end(), i);
		//dump(tmp);
		ans += tmp - 1;
	}
	dump(ans);
	return 0;
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
using Graph = vector<vector<int> >;
using GraphC = vector<vector<char> >;
const int INF = 1000000000;
typedef pair<int, int> P;
const int MAX_N = 1000000000;
typedef int64_t ll;
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 N;
	cin >> N;
	vector<int> T(N);
	int tmp = 0;
	rep(i, N) {
		cin >> T.at(i);
		tmp += T.at(i);
	}
	int M;
	cin >> M;
	vector<P> p(M);
	rep(i, M) {
		cin >> p.at(i).first >> p.at(i).second;
	}

	for (int i = 0; i < M; i++)
	{
		int ans = tmp;
		int m = p.at(i).first; m--;
		ans -= T.at(m);
		int add = p.at(i).second;
		ans += add;

		cout << ans << endl;
	}
	
}

Measured memory_bytes: 3576
//Patwari26
//#include template<t> as mine
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll n;
    cin>>n;
    if(n>=30) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    // time
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> P;
int mod = 1e9+7;

vector<P> prime_factorize(int N){
	vector<P> ans;
	for(int a = 2; a*a <= N; a++){
		if(N%a == 0){
			int ex = 0;
			while(N%a == 0){
				ex++;
				N /= a;
			}
			ans.push_back(P(a, ex));
		}
	}
	if(N != 1) ans.push_back(P(N, 1));
	return ans;
}

signed main(){
	int N; cin >> N;
	int mod = 1e9 + 7;
	vector<int> exp(N + 1, 0);
	for(int n = 2; n <= N; n++){
		vector<P> ans = prime_factorize(n);
		for(int i = 0; i < ans.size(); i++){
			P p = ans[i];
		    exp[p.first] += p.second;
		} 
	}
	int ans = 1;
	for(int i = 2; i <= N; i++){
		ans *= (exp[i] + 1);
		ans %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define chmax(a,b) if(a<b)a=b
const int N=2e5+5;

int n;
LL dp[N],c[N];
int a[N],b[N];
void update(int i,LL x)
{
	while(i<=n)
	{
		chmax(c[i],x);
		i+=i&(-i);
	}
}
LL getmx(int i)
{
	LL mx=0;
	while(i)
	{
		chmax(mx,c[i]);
		i-=i&(-i);
	}
	return mx;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",a+i);
	for(int i=1;i<=n;i++)
		scanf("%d",b+i);
	for(int i=1;i<=n;i++)
	{
		dp[i]=b[i]+getmx(a[i]);
		update(a[i],dp[i]);
	}
	printf("%lld\n",getmx(n));
	
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cerr << "[(" << __LINE__ << ") " << (#x) << "]: " << x << endl;

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

    int n, w;
    cin >> n >> w;

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

    vector<ll> dp(w+1);

    for (int i=0; i<n; i++) {
        for (int j=w; j>=a[i]; j--) {
            dp[j] = max(dp[j], dp[j-a[i]] + b[i]);
        }
    }
    cout << dp[w] << "\n";
}


Measured memory_bytes: 1024
#include <cstdio>
#include <deque>
#include <set>

std::set<int> edges[100005];
std::set<int> left[100005];
std::deque<int> seq;

void mark(int V){
  for(int W:edges[V]){
    left[W].erase(V);
  }
}

int main(){
  int N,M;
  scanf("%d %d",&N,&M);
  for(int i=0;i<M;i++){
    int A,B;
    scanf("%d %d",&A,&B);
    A--,B--;
    edges[A].insert(B);
    edges[B].insert(A);
    left[A].insert(B);
    left[B].insert(A);
  }
  int X=0,Y=*edges[0].begin();
  seq.push_front(X);
  seq.push_back(Y);
  mark(X);
  mark(Y);
  while(left[X].size()){
    int X2=*left[X].begin();
    mark(X2);
    seq.push_front(X=X2);
  }
  while(left[Y].size()){
    int Y2=*left[Y].begin();
    mark(Y2);
    seq.push_back(Y=Y2);
  }
  printf("%d\n",(int)seq.size());
  for(int i=0;i<seq.size();i++){
    if(i) printf(" ");
    printf("%d",seq[i]+1);
  }
  printf("\n");
  return 0;
}


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

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main() {
    int x;
    cin >> x;
    while(!IsPrime(x)) x++;
    cout << x <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using  namespace std;
int main(){
    long long n, m, ans;
    cin >> n >> m;
    if(n > m/2){
      	if((m-2*n)<0){
			ans = m/2;          
        }else{
        	ans = n;
        }
    }else{
        ans = n;
        ans += (m-2*n)/4;
    }
    cout << ans << endl;
 
}


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

#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
#define ll long long
#define bl bool
#define nn printf("\n");
#define mod 1000000007

using namespace std;

string Num2Str(int num)
{
	stringstream ss;
	ss << num;
	return ss.str();
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int a = 0, b = 0;
	while (cin >> a >> b)
	{
		int sum = a + b;
		string str;
		str = Num2Str(sum);
		printf("%d\n", str.size());
	}
	return 0;
}

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

int main(void)
{

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

    vector<int> result(n);
    if (n % 2 == 0)
    {
        for (int i = 0; i < n; i++)
        {
            if (i < n / 2)
            {
                result[i] = a[n - 2 * i - 1];
            }
            else
            {
                result[i] = a[2 * i - n];
            }
        }
    }
    else
    {
        for (int i = 0; i < n; i++)
        {
            if (i <= n / 2)
            {
                result[i] = a[n - 2 * i - 1];
            }
            else
            {
                result[i] = a[2 * i - n];
            }
        }
    }
    cout << result[0];
    for (int i = 1; i < n; i++)
    {
        cout << ' ' << result[i];
    }
    cout << endl;
    return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <LL,LL>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL n,q,v[300000],w[300000],dp[2100][100020],tot=0,depth,ww,vv;
vector <pii> dd;

void dfs(LL pos,LL d)
{
	if(d>depth/2||pos>=n) return;
	tot++;
	if(pos==0) dp[pos][w[pos]]=v[pos];
	else
	{
		LL lst=(pos-1)/2;
		rep(i,100005)
		{
			if(dp[lst][i]<0) continue;
			dp[pos][i]=max(dp[pos][i],dp[lst][i]);
			if(i+w[pos]<=100005) dp[pos][i+w[pos]]=max(dp[pos][i+w[pos]],dp[lst][i]+v[pos]);
		}
	}
	dfs(pos*2+1,d+1);
	dfs(pos*2+2,d+1);
}

LL getDepth(LL xx)
{
	LL ret=1;
	while(xx>0)
	{
		ret++;
		xx=(xx-1)/2;
	}
	return ret;
}

int main()
{
	cin>>n;
	depth=getDepth(n-1);
	rep(i,n) scanf("%lld%lld",&v[i],&w[i]);
	rep(i,595) rep(j,100010) dp[i][j]=-1;
	dp[0][0]=0;
	dfs(0,1);
	rep(i,max(tot,1LL)) repn(j,100003) dp[i][j]=max(dp[i][j],dp[i][j-1]);
	cin>>q;
	LL x,y;
	rep(qn,q)
	{
		scanf("%lld%lld",&x,&y);
		x--;
		LL d=getDepth(x);
		if(d<=depth/2) printf("%lld\n",dp[x][y]);
		else
		{
			dd.clear();
			rep(i,d-depth/2)
			{
				dd.pb(mpr(w[x],v[x]));
				x=(x-1)/2;
			}
			LL ans=0;
			rep(i,1<<dd.size())
			{
				ww=0;
				vv=0;
				rep(j,dd.size())
				{
					if((i&(1<<j))==0) continue;
					ww+=dd[j].fi;
					vv+=dd[j].se;
					if(ww>y) break;
				}
				if(ww>y) continue;
				ans=max(ans,vv+dp[x][y-ww]);
			}
			printf("%lld\n",ans);
		}
	}
	return 0;
}

Measured memory_bytes: 472876
#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 pbds tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define ii pair<int,int>
#define vii vector<ii>
#define vi vector<int>

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";

const int mxN = 3e5 + 7; 
int visited[mxN];

void solve(){
    int n; cin >> n;
    ll a[n];
    FOR(n) cin >> a[i];
    ll ans = 0;
    FOR(i,1,n){
        ll cur_sum = 0;
        int l = 0, r = n-1;

        while(r>i && visited[r] != i){
            cur_sum += a[l] + a[r];
            ans = max(ans,cur_sum);
            l+=i;
            r-=i;
            visited[l] = i;
        }
    }
    cout << ans;
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	solve();
	return 0;
}
 


Measured memory_bytes: 4684
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define fi first
#define se second
#define endl '\n'
// #define int int64_t
#define double long double
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using reverse_queue = priority_queue<T, vector<T>, greater<T>>;
mt19937_64 rnd(time(0));
const int64_t FIXED_RANDOM = rnd();
template<typename T> struct custom_hash{T operator()(T x)const{return (T) x^FIXED_RANDOM;}}; // check hash in whether int64 or int32
template<typename T1, typename T2> using hash_map = gp_hash_table<T1, T2, custom_hash<T1>>;
// Tao luyện kỹ thuật trong 8 năm mày luyện kỹ thuật trong buồng tắm nam
const int MAXN = (int) 2e5 + 2;
const int INF = numeric_limits<int>::max() >> 1;
const int MOD = (int) 1000000009;
signed main(){
  ios_base::sync_with_stdio(0); 
  cin.tie(0);
  // freopen("FDT.txt", "r", stdin);
  int n;
  cin >> n;
  vector<bool> a;
  for(int i = 0; i < n; i ++){
    int l, r;
    cin >> l >> r;
    a.push_back(l == r);
    if(i >= 2){
      if(a[i] == 1 && a[i - 1] == 1 && a[i - 2] == 1){
        cout << "Yes";
        return 0;
      }
    }
  }
  cout << "No";
}

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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define read            freopen("in.txt","r",stdin)
#define write           freopen("out.txt","w",stdout)
#define loop(i,a,b)     for (ll i = a; i <= b; i++)
#define rloop(i,a,b)    for (ll i = a; i >= b; i--)
#define ms(a,x)         memset(a,x,sizeof a)
#define ll              long long int
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define rall(a)         a.rbegin(),a.rend()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd((a),(b))
#define lcm(a,b)        ((a)*(b))/(gcd(a,b))
#define sq(a)           (a)*(a)
#define sz(a)           a.size()
#define mod             1000000007
#define PI              2*acos(0.0)


int main()
{
    IOS
    int T=1;
    //cin>>T;
    cout<<fixed<<setprecision(10);
    while(T--)
    {
        double a,b,x;
        cin>>a>>b>>x;
        if((a*a*b)/2==x)
        {
            cout<<"45.0000000000";
            continue;
        }
        if((a*a*b)/2<x)
        {
            double h=x/(sq(a));
            double hh=(b-h)*2.0;
            double kon=atan(a/hh);
            cout<<90-((180*kon)/3.1415926535897932);
        }
        else
        {
            double h=x/(sq(a));
            double hh=(b-h)*2.0;
            double k=(hh-b);
            a=((a*h*2)/b);
            double kon=atan(a/b);
            //debug(a,b,hh,h);
            cout<<90-((180*kon)/3.1415926535897932);

        }

    }
    return 0;
}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, n);
  for (;; ++n) {
    string s = to_string(n);
    bool ok = true;
    for (char c : s)
      if (c != s[0]) ok = false;
    if (ok) {
      out(n);
      return 0;
    }
  }
}


Measured memory_bytes: 3676
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

l = [A, B, C, D, E]
ll = []
ans = []
for i in range(5):
    if l[i] % 10 == 0:
        ll.append(11)
        ans.append(l[i])
    else:
        ll.append(l[i] % 10)
        ans.append(l[i] + (10 - l[i] % 10))

p = ll.index(min(ll))


if p == 11:
    print(sum(l))
else:
    print(sum(ans) - ans[p] + l[p])


Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

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

int main(){
    ll n,m,v,p;
    cin >> n >> m >> v >> p;
    vector<ll>a(n);
    rep(i,n)cin >> a[i];
    sort(all(a));
    vector<ll>s(n);
    for(int i=0;i<n;i++){
        s[i] += a[i];
        if(i!=0)s[i] += s[i-1];
    }
    ll t = a[n-p];
    int res = 0;
    for(int i=0;i<n;i++){
        if(a[i]+m<t)continue;
        if(i>=n-p){
            res++;
            continue;
        }
        ll T = a[i]+m;
        ll id = n-p;
        ll pid = upper_bound(all(a),a[i])-a.begin();
        pid--;
        ll tmp = 0;
        tmp += (pid+1) * m;
        if(pid!=0)tmp += T*(id-pid+1) - (s[id]-s[pid-1]);
        else tmp += T*(id-pid+1) - (s[id]);
        // cerr << i << " " << T << " " << pid << " " << id << " " << tmp << " " << m*v << endl;
        if(tmp >= m*(v-p+2)){
            res++;
        }
    }
    cout << res << endl;
    return 0;
}

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

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

//////////////////////////////////////////////////

#include <iostream>
#include <vector>
#include <limits.h>

template<typename T_uf_data>
class SegTree
{
private:
    int cnt;      // 実際の要素数
    int cnt_pow2; // 簡単のためサイズを 2 のべき乗になるように広げておく
    int size;     // 全体の要素数 (2 * cnt_pow2 - 1)
    T_uf_data default_value; // デフォルトの値（最小値を求める場合は大きい値というように消えるように）
    std::vector<T_uf_data>* data; // データ本体

    T_uf_data query_inner(T_uf_data a, T_uf_data b, int k, int l, int r)
    {
        // [a, b) と [l, r) が交差しなければ処理の過程で消える値を返す
        if(r <= a || b <= l) return default_value;
        if(a <= l && r <= b) {
            return (*data)[k];
        } else {
            T_uf_data vl = query_inner(a, b, k * 2 + 1, l, (l + r) / 2);
            T_uf_data vr = query_inner(a, b, k * 2 + 2, (l + r) / 2, r);
            return Calc(vl, vr);
        }
    }

    virtual T_uf_data Calc(T_uf_data a, T_uf_data b) = 0;

public:
    SegTree(int n, T_uf_data dv)
    {
        default_value = dv;
        cnt = n;
        cnt_pow2 = 1;
        while(cnt_pow2 < cnt) cnt_pow2 *= 2;
        size = 2 * cnt_pow2 - 1;

        // 一番上のノードがインデックス 0、そこからピラミッド状に広がり
        // 一番下のノードがインデックス cnt_pow2 - 1 ～ 2 * cnt_pow2 - 2 までとなる
        data = new std::vector<T_uf_data>(size);
        for(int i = 0; i < size; i++) {
            (*data)[i] = default_value;
        }
    }

    ~SegTree() { delete data; }

    void Update(int k, T_uf_data a)
    {
        if(k >= cnt) {
            std::cout << "index out of range: " << k << " -> " << a << std::endl;
            return;
        }

        // n - 1 を加算するとインデックス k を保存している一番下のノードが得られる
        k += cnt_pow2 - 1;
        (*data)[k] = a;

        // ピラミッドを上りながら更新
        while (k > 0) {
            k = (k - 1) / 2;
            (*data)[k] = Calc((*data)[k * 2 + 1], (*data)[k * 2 + 2]);
        }
    }

    // [a, b) の範囲であることに注意
    T_uf_data Query(T_uf_data a, T_uf_data b)
    {
        return query_inner(a, b, 0, 0, cnt_pow2);
    }

    // 内容を出力して確認
    void Show()
    {
        int c = 2;
        for(int i = 0; i < cnt_pow2 + cnt - 1; i++) {
            if(i == c - 1) {
                std::cout << std::endl;
                c *= 2;
            }
            std::cout << (*data)[i] << " ";
        }
        std::cout << std::endl;
    }

};

class SegTreeGCD: public SegTree<int>
{
private:
    int Calc(int a, int b) { return gcd(a, b); }
public:
    // デフォルト値は ∞（min を取ると消えるため）
    SegTreeGCD(int n): SegTree(n, 0) {}
    static int gcd(int a, int b) {
        if(b == 0) return a;
        return gcd(b, a % b);
    }
};

//////////////////////////////////////////////////

int main()
{
    int N, ans;
    cin >> N;

    SegTreeGCD A(N + 1);
    for(int i = 1; i <= N; i++) {
        int a;
        cin >> a;
        A.Update(i, a);
    }

    ans = 0;
    for(int i = 1; i <= N; i++) {
        ans = max(ans, SegTreeGCD::gcd(A.Query(1, i), A.Query(i + 1, N + 1)));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1280
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations

def main():
    N = int(input())
    K = int(input())
    X = int(input())
    Y = int(input())

    print(N * X) if N <= K else print(K*X + (N-K)*Y)

if __name__ == '__main__':
    main()

Measured memory_bytes: 10480
import java.io.*;
import java.util.*;

public class Main
{
    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok;

    public void go() throws IOException
    {
        ntok();
        int n = ipar();
        int sum = 0;
        for (int i = 1; i <= n; i++)
            for (int e = 1; e <= n; e++)
                for (int w = 1; w <= n; w++)
                    sum += gcd(gcd(i, e), w);
        out.println(sum);

        out.flush();
        in.close();
    }

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

    public void ntok() throws IOException
    {
        tok = new StringTokenizer(in.readLine());
    }

    public int ipar()
    {
        return Integer.parseInt(tok.nextToken());
    }

    public int[] iapar(int n)
    {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++)
        {
            arr[i] = ipar();
        }
        return arr;
    }

    public long lpar()
    {
        return Long.parseLong(tok.nextToken());
    }

    public long[] lapar(int n)
    {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++)
        {
            arr[i] = lpar();
        }
        return arr;
    }

    public double dpar()
    {
        return Double.parseDouble(tok.nextToken());
    }

    public String spar()
    {
        return tok.nextToken();
    }

    public static void main(String[] args) throws IOException
    {
        new Main().go();
    }
}


Measured memory_bytes: 32896
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>

using namespace std;

int main() {
	int n, d1, d2;
	cin >> n;

	int cnt = 0;
	bool ok = false;
	for (int i = 0; i < n; i++) {
		cin >> d1 >> d2;
		if (d1 == d2) {
			cnt++;
			if (cnt >= 3) {
				ok = true;
			}
		} else {
			cnt = 0;
		}
	}

	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 3132
#include<bits/stdc++.h> 
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c;
	cin>>d;
	if(a>=b&&a>=c){
		for(int e=0;e<d;e++){
			a=a*2;
		}
	}
		if(b>=c&&b>=a){
		for(int e=0;e<d;e++){
			b=b*2;
		}
	}
		if(c>=b&&c>=a){
		for(int e=0;e<d;e++){
			c=c*2;
		}
	}
	cout<<a+b+c;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
constexpr auto MOD = 1000000007;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;

string t;
long long n,k,r,s,p;

int main()
{
  cin >> n >> k >> r >> s >> p >> t;
  ll ans = 0;
  VI scr(100, 0);
  scr['r' - 'a'] = p;
  scr['s' - 'a'] = r;
  scr['p' - 'a'] = s;
  for (int i = 0; i < k; i++)
  {
    int cnt = 0;
    char now = 'a';
    for (int j = 0; j < 9999999; j++)
    {
      int iter = i + k * j;
      if(i+j*k>=n)
        break;
      if(now!=t[iter]){
        ans += scr[t[iter] - 'a'];
        cnt = 1;
        now = t[iter];
      }else{
        cnt++;
        if (cnt % 2)
        {
          ans += scr[t[iter] - 'a'];
        }
      }
    }
  }
  cout << ans << endl;

}


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

using namespace std;
#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++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

/*
左から見ていったときの最大値と右から見ていったときの最大値を比較する

*/
ll gcd(ll a, ll b)
{
    return a % b == 0 ? b : gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

// 1以上x以下の整数でcでもdでも割り切れないものの数を求める
ll helper(ll c, ll d, ll x)
{
    return (x - (x / c + x / d - x / lcm(c, d)));
}

int main()
{
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << helper(C, D, B) - helper(C, D, A - 1) << endl;
    return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

int main(){
    int n; cin>>n;
    map<string,long long> m;
    for(int i=0;i<n;i++){
        string s; cin>>s;
        sort(s.begin(),s.end());
        m[s]++;
    }

    long long ans=0;
    for(auto p:m){
        if(p.second>1) ans+=p.second*(p.second-1)/2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 11136
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <functional>
#include <stack>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <climits>

using namespace std;

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

const ll MOD = 1000000007;
const ll INF = LLONG_MAX;
const ll MAX_N = 100000;

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


int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << min(a, b) + min(c, d) << endl;
	return 0;
}

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


struct UnionFind {
  vector<int> par;
  vector<ll> nnum;
  UnionFind( int n ) {
    init(n);
  }
  void init( int n ) {
    par.resize(n);
    nnum.resize(n);
    for ( int i=0;i<n;++i ) par[i] = i;
    for ( int i=0;i<n;++i ) nnum[i] = 1;
  }
  int root( int a ) {
    if ( par[a] == a ) return a;
    return par[a] = root(par[a]);
  }
  ll merge( int a, int b ) {
    int ra = root(a);
    int rb = root(b);
    if ( ra == rb ) return 0;
    ll ret = nnum[ra] * nnum[rb];
    if ( nnum[ra] > nnum[rb] ) swap( ra, rb );
    par[ra] = rb;
    nnum[rb] += nnum[ra];
    return ret;
  }
};

int main() {
  int N,M;
  cin >> N >> M;
  UnionFind uf(N);
  vector<ll> ans(M+1);
  vector<int> A(M), B(M);
  REP(i,M) {
    cin >> A[i] >> B[i];
    A[i]--; B[i]--;
  }

  ans[M] = (ll)N * ((ll)N-1LL) / 2LL;
  for ( int i=M-1; i>0; --i ) {
    ans[i] = ans[i+1] - uf.merge( A[i], B[i] );
//    cout << i << " " << ans[i] << endl;
  }
  REP(i,M) {
    cout << ans[i+1] << endl;
  }
}



Measured memory_bytes: 4096
#include<stdio.h>
int main(void)
{
   char s[9999999];
   int m=0,n=0,i;
   scanf("%s",&s);
   for(i=0;s[i]!='\0';i++){
      if (s[i]=='1')        m++;
      else if (s[i]='0')    n++;
      }
   if(n<m) printf("%d",n*2);
   else printf("%d",m*2);
   return 0;
}


Measured memory_bytes: 2304