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

using namespace std;
 
#define MD 1000000007
typedef long long int ll;

int main(){
    string s;
    cin>>s;
    int cnt_c=0,sum=0;
    for(int i=0;i<s.size();i++){
        if(s[0]!='A'){
            cout<<"WA"<<endl;
            return 0;
        }
        if(isupper(s[i])){//大文字の数をカウント
            sum++;
        }
        if(i>=2 && i<=s.size()-2){
            if(s[i]=='C'){
                cnt_c++;
            }
        }
    }
   
    if(sum==2 && cnt_c==1){
        cout<<"AC"<<endl;
    }else{
        cout<<"WA"<<endl;
    }
    return 0;
}

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

__int128 total_level[55];
__int128 total_party[55];

void scan(__int128 &x)//输入
{
    x = 0;
    int f = 1;
    getchar();
    char ch;
    if((ch = getchar()) == '-') f = -f;
    else x = x*10 + ch-'0';
    while((ch = getchar()) >= '0' && ch <= '9')
        x = x*10 + ch-'0';
    x *= f;
}

void print(__int128 x)
{
    if(x < 0)
    {
        x = -x;
        putchar('-');
    }
    if(x > 9) print(x/10);
    putchar(x%10 + '0');
}

__int128 solve(int N, __int128 X){
    if(N == 1){
        if(X == 0) return 0;
        if(X == 1) return 0;
        if(X == 2) return 1;
        if(X == 3) return 2;
        if(X == 4) return 3;
        if(X == 5) return 3;
    }
    if(X == total_level[N-1]+2) return total_party[N-1]+1;
    if(X ==  total_level[N-1] +1) return total_party[N-1];
    if(X == total_level[N] || X == total_level[N] - 1) return total_party[N];
    if(X < total_level[N-1]+1){
        return solve(N-1, X-1);
    }
    if(X > total_level[N-1]+2){
        return solve(N-1, X - total_level[N-1] -2 ) +1 + total_party[N-1];
    }
    
    
}

int main() {
//    freopen("./input.txt", "r", stdin);
    int N;
    __int128 X, ans;
    scanf("%d", &N);
    scan(X);
    
    total_level[1] = 5;
    total_party[1] = 3;
    for(int i= 2; i <= N; i++){
        total_level[i] = total_level[i-1]*2 + 3;
        total_party[i] = total_party[i-1]*2 + 1;
    }
    
    ans = solve(N,X);
    print(ans);
    printf("\n");
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int i=1,end,x[10000];
	while(i<=10000){
		scanf("%d",&x[i]);
		if(x[i]==0){
			break;
		}
		printf("Case %d: %d\n",i,x[i]);
		i++;	
	}
	return 0;
}

Measured memory_bytes: 1756
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    long p = 1000000007l;
    
    boolean check = false;
    if(A == B){
      check = true;
    }else if(A+1 == B || A-1 == B){
      check = false;
    }else{
      System.out.println(0);
      return;
    }
    
    long ans = 0;
    long n = 1;
    long m = 1;
    for(int i = 1; i <= A; i++){
      n = n * i % p;
    }
    for(int i = 1; i <= B; i++){
      m = m * i % p;
    }
    
    if(check){
      ans = (((2 * n) % p) * m) % p;
    }else{
      ans = (n * m) % p;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = 1e+14;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG

int n;
void path (vector<vector<int>> g, int now, vector<int> past,vector<vector<int>> &a){

    if(past.size()==n){
        a.push_back(past);
        return;
    }

    for (auto i: g[now]){
            past.push_back(i);
            path(g,i,past,a);
            past.pop_back();
        }

}

int main(){
    cin>>n;
    int m; cin>>m;
    vector<vector<int>> g(n);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<int> past;
    past.push_back(0);
    vector<vector<int>> a;

    path(g,0,past,a);
    int count=0;

    rep(i,a.size()){
        sort(a[i].begin(),a[i].end());
        
        bool judge=true;
        rep(j,n-1){
            if(a[i][j]==a[i][j+1]) judge=false;
        }
        if(judge) count++;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 61028
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N;
    cin >> N;
    vector<ll> a(N);
    rep(0, i, N)
    {
        cin >> a.at(i);
    }
    sort(all(a));
    cout << a.at(N - 1) - a.at(0) << endl;
}

Measured memory_bytes: 3588
#include <iostream>

int main(){
    int W,H,x,y,r;
    std::cin >> W >> H >> x >> y >> r;
    if(x-r >= 0 && x+r <= W && y-r >= 0 && y + r<= H) std::cout << "Yes" << std::endl;
    else std::cout << "No" << std::endl;
    return 0;
}


Measured memory_bytes: 3128
///Bismillahir Rahmanir Rahim
#define ll long long
#define ull unsigned long long
#define scf1(a)  scanf("%lld",&a)
#define scf2(a,b)  scanf("%lld %lld",&a,&b)
#define pf    printf
#define pb    push_back
#define rsrt(v) reverse(v.begin(),v.end())
#define srt(v) sort(v.begin(),v.end())
#define ff first
#define ss second
#define spd ios_base::sync_with_stdio(false)
#include<bits/stdc++.h>
using namespace std;
ll arr[100005];
ll dp[100005];
ll n,res,ans;
ll mincost(ll pos)
{
    if(pos>=n)return 0;

   if(dp[pos]!=-1)return dp[pos];


    ll res = abs(arr[pos]-arr[pos+1]) + mincost(pos+1);
     if(pos+2<=n)
     res = min(res,abs(arr[pos]-arr[pos+2]) + mincost(pos+2));

    dp[pos] = res;

    return dp[pos];
}
int main()
{
    spd;

    ll i,j,k;

    cin>>n;

    for(i=1;i<=n;i++)
    {
        cin>>arr[i];
    }

    memset(dp,-1,sizeof(dp));

    cout<<mincost(1)<<endl;
}


Measured memory_bytes: 4992
fun main(args:Array<String>) {
    val s = readLine()!!.map { it.toString().toInt() }
    val idx = readLine()!!.toLong() - 1
    if(idx <= 100 && s.take(idx.toInt()+1).all { it == 1 }) {
        println(1)
    } else {
        println(s.first { it != 1 })
    }
}

Measured memory_bytes: 35412
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n,m;
  cin >> n >> m;
  vi k(m),p(m);
  vector<vi> s(m,vi(10));
  rep(i,m){
    cin >> k[i];
    rep(j,k[i])cin >> s[i][j];
  }
  rep(i,m)cin >> p[i];
  int ans = 0;
  rep(b,1<<n){
    vi on(m,0);
    rep(i,m){
      rep(j,k[i]){
        on[i]+=(b>>(s[i][j]-1))&1;
      }
    }
    bool all = true;
    rep(i,m){
      all&=(p[i] == on[i]%2);
    }
    if(all)ans++;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

int main (void) {
    int A, B;

    scanf("%d%d", &A, &B);

    if (A+B <= 16 && A <= 8 && B <= 8) {
        printf ("Yay!\n");
    } else {
        printf (":(\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>

int main(void)
{
    int a,b;
    int q;
    char p[1000];
    char str[1001];
    char copy[1001];
    char n[1001];
    int length = 0;
    char str2[1001];

    scanf("%s", str);
    scanf("%d", &q);

    for(int i = 0; i < q; i++){
        scanf("%s", n);

        if (strcmp(n, "print") == 0){
            scanf("%d %d", &a,&b);
            for(int k = 0; k < (b - a) + 1; k++){
                str2[k] = str[a+k];
            }
            str2[b-a+1] = '\0';
            printf("%s\n", str2);
        }
        else if(strcmp(n, "reverse") == 0){
            scanf("%d %d", &a,&b);
            for(int j = 0; j < (b - a + 1) / 2; j++){
                int temp = str[a + j];
                str[a + j] = str[b - j];
                str[b - j] = temp;
            }
        }
        else if(strcmp(n, "replace") == 0){
            scanf("%d %d %s", &a, &b, p);
            for(int c = 0; c < (b - a) + 1; c++){
                str[a + c] = p[c];
            }
        }
    }
    return (0);
}



Measured memory_bytes: 2100
NUM_EAT = 3
_ = gets.to_i
a = gets.chomp.split.map(&:to_i)
h = Hash.new(0)
a.each{ h[_1] += 1 }
single = h.select { |_k, v| v == 1 }
dx = h.select { |_k, v| v > 1 }
loop do
  break if dx.size.zero?

  target = []
  dx.each do |k, v|
    rest = NUM_EAT - target.size
    if v <= rest
      [v, rest].min.times { target << k }
      dx.delete(k)
    else
      rest.times { target << k }
      dx[k] -= rest
      if dx[k] == 1
        single[k] = 1
        dx.delete(k)
      end
    end
    break if target.size == NUM_EAT
  end

  unless target.size == NUM_EAT
    single.each do |k, _v|
      target << k
      single.delete(k)
      break if target.size == NUM_EAT
    end
  end
  target.sort!
  add_k = target[1]
  if dx.key?(add_k)
    dx[add_k] += 1
  elsif single.key?(add_k)
    single.delete(add_k)
    dx[add_k] = 2
  else
    single[add_k] = 1
  end
end
puts single.size

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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long i64;
typedef pair<i64,i64> P;


double a,b;

int main(){
	cin >> a>> b;
	
	printf("%.10f\n", a/b);
	
	return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i > (b); --i)
#define SZ(a) a.size()
#define ll long long
#define ull unsigned long long
using namespace std;


int main() {

	int X = 0;
	int Y = 0;

	cin >> X >> Y;
	
	if (X%Y == 0) {
		cout << -1 << endl;
	}
	else {
		FOR(i, X, pow(10, 18)) {
			if (i % X == 0 && i % Y != 0) {
				cout << i << endl;
				break;
			}
		}
	}

	system("pause");
	return 0;
}

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

vector<int>v;

int main() {
	int n;
	while (cin >> n, n) {
		v.clear();
		v.push_back(10);
		for (int i = 0; i < n; i++) {
			int a;
			cin >> a;
			v.push_back(a);
		}
		v.push_back(10);

		int ans = n;

		for (int i = 1; i <= n; i++) {
			int sk = i, ek = i;//erased kukan
			int lp = 0;
			while (1) {
				int l = 0, r = 0;
				for (int j = ek + 1; j < v.size(); j++) {
					if (v[j] != v[ek + 1])break;
					r++;
				}
				for (int j = sk - 1; j > -1; j--) {
					if (v[j] != v[sk - 1])break;
					l++;
				}

				if (lp) {
					if (v[ek + 1] != v[sk - 1])break;
					if (l + r >= 4) {
						sk -= l;
						ek += r;
					}
					else break;
				}
				else {
					if (v[ek + 1] != v[sk - 1]) {
						if (l >= 3) {
							sk -= l;
						}
						else if (r >= 3 ) {
							ek += l;
						}
						else break;
					}
					else {
						if (l + r >= 4) {
							sk -= l;
							ek += r;
						}
						else break;
					}
				}
					lp++;
			}
		if(lp)ans = min(ans, n -( ek - sk+1));
		}
		cout << ans << endl;
	}
	return 0;
}

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

void solve()
{
    int x, y;
    cin >> x >> y;
    if (y >= x)
        cout << "unsafe";
    else
    {
        cout << "safe";
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	int sum = 0;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
		sum += a[i];
	}
	sort(a.rbegin(), a.rend());

	if (a[m - 1] >= ((double)sum / (4 * m)))cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}




//AAAAAAAAAAAAAAAAAAA
//int main() {
//	int x, y, z;
//	cin >> x >> y >> z;
//
//	cout << z << " " << x << " " << y << endl;
//
//
//	return 0;
//}

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

using namespace std;

int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  vector<tuple<int, int, int>> a;
  for (int i = 0; i < n - 1; i++) {
    int c, s, f;
    cin >> c >> s >> f;
    a.emplace_back(c, s, f);
  }
  for (int i = 0; i < n - 1; i++) {
    int now = 0;
    for (int j = i; j < n - 1; j++) {
      int C, S, F;
      tie(C, S, F) = a[j];
      now = max(now, S);
      while (now % F != 0) now++;
      now += C;
    }
    cout << now << endl;
  }
  cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        int temp;
        cin >> temp;
        a[i] = temp - i - 1;
    }
    sort(a.begin(), a.end());
    int b = a[n/2];
    long long ans = 0;
    for (int i = 0; i < n; i++)
    {
        ans += abs(a[i] - b);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  	int n;cin >> n;
  	string s;
  	cin >> s;
  	if(n%2==0){
      int n2 = n/2;
      int flag = 1;
      for(int i =0;i<n2;i++){
        if(s[i]!=s[n2+i])
          flag = 0;
      }
      
      cout << (flag?"Yes":"No") << endl;
    }
  	else	
    	cout << "No" << endl;
 	return 0; 
}

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

using namespace std;

int main() {
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> v(n, k - q);
    for (int i = 0; i < q; ++i) {
        int a;
        cin >> a;
        ++v[a - 1];
    }
    for (int i = 0; i < n; ++i) {
        if (v[i] > 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" <<  endl;
        }
    }
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
//#define DEBUG
using namespace std;

int main(){
    int a, b, c, d, e;
    int N = 5;
    cin >> a >> b >> c >> d >> e;
    vector<int> Time = { a, b, c, d, e};
    vector<int> index = {0, 1, 2, 3, 4};
    int bestTime = (int)1e9;
    // 0, 1, 2, 3, 4
    // 0, 1, 2, 4, 3
    //:
    do{
        int NowTime = 0;
        for(int i = 0; i < N; i++) {
            while(NowTime % 10 != 0)
                NowTime++;
            NowTime += Time.at(index.at(i));
       }

       #ifdef DEBUG
           for(int k = 0; k < index.size(); k++){
               cout << index.at(k) << " ";
           } cout << endl;
       #endif
       
       bestTime = min(NowTime, bestTime);
    } while(next_permutation(index.begin(), index.end()));
    cout << bestTime << endl;

}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
    int  s=100000;
 
    int n;
    scanf("%d",&n);
 
 
    for(;n--;){
        if(int(s*1.05)%1000==0){
            s=int(s*1.05);
        }else{
            s= int(s*1.05) + (1000- int(s*1.05) % 1000);
        }
    }
    printf("%d\n",s);
 
    return 0;
}

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

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

	int t=1;
	long n;
	ll temp;
	string s;

	while(t--)
	{
		cin>>n;
		cin>>s;
		long int wc = 0, rc =0, fwc=0, frc=0;
		long int i;
		for(i =0; i<n; i++)
		{
			if(s[i]!='R') break;
		}
		n--;
		while(s[n]=='W') n--;
		ll totalop = 0;
		char temp;
		while(i<=n)
		{
			while(s[i]=='R') i++;
			while(s[n]=='W') n--;
			if(n<i) break;

			temp = s[i];
			s[i] = s[n];
			s[n] = temp;
			totalop++;
		}
		cout<<totalop<<"\n";

	}

	return 0;
}

Measured memory_bytes: 3648
// -*- coding:utf-8-unix -*-

use proconio::{fastout, input};

// #[fastout]
fn main() {
    input! {
        n: usize,
        c_str: String,
    }
    let c = c_str.as_bytes();
    let mut count = 0;
    let mut leftptr = 0;
    let mut rightptr = c.len() - 1;
    'mainloop: while leftptr < rightptr && leftptr < c.len() {
        while c[leftptr] == b'R' {
            leftptr += 1;
            if leftptr >= c.len() {
                break 'mainloop;
            }
        }
        while c[rightptr] == b'W' {
            if rightptr == 0 {
                break 'mainloop;
            }
            rightptr -= 1;
        }
        if leftptr >= rightptr {
            break;
        }
        count += 1;
        leftptr += 1;
        rightptr -= 1;
    }
    println!("{}", count);
}


Measured memory_bytes: 2448
#include <bits/stdc++.h>
#define REP(i,n) for (long long i=0;i<(n);i++)
#define FOR(i,a,b) for (long long i=(a);i<(b);i++)
#define dump(x)  cerr << #x << " => " << (x) << endl
#define MIN(vec) *min_element(vec.begin(), vec.end())
#define MAX(vec) *max_element(vec.begin(), vec.end())
#define UNIQ(vec) vec.erase(unique(vec.begin(), vec.end()),vec.end()) //ソートの必要あり
#define IN(n,m)  (!(m.find(n) == m.end()))
#define FINDL(vec,x) (lower_bound(vec.begin(),vec.end(),x) - vec.begin())
#define FINDU(vec,x) (upper_bound(vec.begin(),vec.end(),x) - vec.begin())
#define EQ(a,b) (abs(a - b) < 1e-10)
using namespace std;
typedef long long LL;
constexpr LL dx[4] = {0,1,0,-1};
constexpr LL dy[4] = {1,0,-1,0};
constexpr long double pi = M_PI;
constexpr double eps = 1e-10;
constexpr long mod = 1000000007;
// LONG_MAX,LLONG_MAX
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (LL i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (LL i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class Key,class Value> ostream& operator << (ostream &s, map<Key,Value> M)
{ for ( auto itr = begin(M); itr != end(M); ++itr) { s << itr->first << ":" << itr->second; } return s;}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
    LL N;
    cin >> N;
    vector<LL> P(N);
    vector<LL> pos(N);
    for(LL i = 0;i < N;i++) {
        cin >> P[i];
        P[i]--;
        pos[P[i]] = i;
    }

    set<LL> S;
    S.insert(-2);
    S.insert(-1);
    S.insert(N);
    S.insert(N+1);
    LL ans = 0;
    for(LL i = N-1;i >= 0;i--) {
        auto it1 = S.lower_bound(pos[i]);
        it1 = prev(it1, 1);
        LL lr = *it1;
        it1 = prev(it1, 1);
        LL ll = *it1;
        auto it2 = S.upper_bound(pos[i]);
        LL rl = *it2;
        it2 = next(it2, 1);
        LL rr = *it2;
        if (lr != -1) {
            ans += (LL) ((lr - ll) * (rl - pos[i]) * (i+1));
        }
        if (rl != N) {
            ans += (LL) ((rr - rl) * (pos[i] - lr) * (i+1));
        }
        
        S.insert(pos[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int64_t N,K;
  cin >> N >> K;
  
  int64_t ans = 0;
  int chack = 1;
  
  if(N > K){
    if(N % K == 0){
      ans = 0;
      chack = -1;
    }
    else{
      int64_t a = abs(N - N/K * K);
      int64_t b = abs(N- (N/K +1) * K);
//      int64_t a = abs(K - K/N * N);
//      int64_t b = abs(K- (K/N +1) * N);
      N = min(a,b);
      //cout << "a=" << a << " b=" << b << endl;
    }
  }
  
  if(chack > 0){
    if(N > K-N){
      ans = K-N;
    }
    else{
      ans = N;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
si = sys.stdin.readline


def main():
    l = [int(e) for e in si().split()]
    Tcnt, Acnt = 0, 0
    while l[0] > 0:
        l[0] -= l[3]
        Tcnt += 1
    while l[2] > 0:
        l[2] -= l[1]
        Acnt += 1
    if Tcnt >= Acnt:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9188
# https://atcoder.jp/contests/abc062/tasks/arc074_a?lang=ja
# C - Chocolate Bar

H, W = list(map(int, input().split()))
area = H * W

# 最初の長方形を決める
p_list = []
hw_list = [(H, W)]

if H != W:
    # 縦横入れ替えた場合の探索
    hw_list.append((W, H))

for hw in hw_list:
    h, w = hw
    for h_i in range(h):
        a_area = h_i * w
        # 残りの面積をなるべく均等に分ける
        # 残りを縦に割る場合
        h2, amari = divmod((h-h_i), 2)
        area_list = [a_area, h2*w, (h2+amari)*w]
        p_1 = max(area_list) - min(area_list)

        # 残りを横に割る場合
        w2, amari = divmod(w, 2)
        area_list = [a_area, (h-h_i)*w2, (h-h_i)*(w2+amari)]
        p_2 = max(area_list) - min(area_list)
        p_list.append(min(p_1, p_2))

ans = int(min(p_list))
print(ans)

Measured memory_bytes: 9992
a, b, c, k = list(map(int, input().split()))

if a == b == c:
    print(0)
    exit()

if abs(a - b) >= 1e18:
    print("Unfair")
    exit()

if k % 2 == 0:
    print(a - b)
else:
    print((a - b) * -1)


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

int main(){
    int n;
    cin >> n;
    int a[n];
    int b[n];
    int c[n];
    
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for(int i = 1; i <= n; i++){
        cin >> b[i];
    }
    for(int i = 1; i < n; i++){
        cin >> c[i];
    }

    int ans = 0;
    for(int i = 1; i <= n; i++){
        ans += b[a[i]];
        if(a[i+1] - a[i] == 1) ans += c[a[i]];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
#define mods 1000000007LL
long long total[1005]={},ans=1;
bool prima[1005];
vector <int> primake;
long long modulo(long long angka)
{
	if(angka>=mods||angka<=-mods)
		angka%=mods;
	if(angka<0)
		angka+=mods;
	return angka;
}
void process(int angka)
{
	int idx=0;
	while(angka>1)
	{
		while(angka%primake[idx]==0)
		{
			angka/=primake[idx];
			total[idx]++;
		}
		idx++;
	}
}
int main()
{
	int input;
	memset(prima,true,sizeof(prima));
	for(int i=2;i*i<=1000;i++)
	{
		if(prima[i])
		{
			for(int j=i*i;j<=1000;j+=i)
				prima[j]=false;
		}
	}
	for(int i=2;i<=1000;i++)
	{
		if(prima[i])
			primake.push_back(i);
	}
	scanf("%d",&input);
	for(int i=2;i<=input;i++)
	{
		process(i);
	}
	for(int i=0;i<=1000;i++)
	{
		total[i]++;
		ans=modulo(ans*total[i]);
	}
	cout<<ans<<endl;
}

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

int main()
{
    int a, b, c, d;
    std::cin >> a >> b >> c >> d;
    while (1)
    {
        c -= b;
        if (c <= 0)
        {
            std::cout << "Yes" << std::endl;
            break;
        }
        a -= d;
        if (a <= 0)
        {
            std::cout << "No" << std::endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3592
import java.util.*

fun main(args: Array<String>) {
    val scn = Scanner(System.`in`)
    val N = scn.nextInt()

    var min = 999999999
    var cnt = 0

    for(i in 1..N){
        var p = scn.nextInt()

        if(p < min){
            cnt++
        }

        if(p <= min){
            min = p
        }
    }

    println(cnt)
}

Measured memory_bytes: 71332
#include <stdio.h>
int main(void)
{
    long int n,a,b,x,y;
    scanf("%ld%ld%ld",&n,&a,&b);
    x=n/(a+b);
    y=n%(a+b);
    if(y<=a) printf("%ld\n",x*a+y);
    else printf("%ld\n",x*a+a);
    return 0;
}

Measured memory_bytes: 1708
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner cin = new Scanner(System.in);
		int N = cin.nextInt();
		int M = cin.nextInt();
		int[] A = new int[1100];
		
		for(int i = 0;i<N;i++) A[i] = cin.nextInt();
		int sum = 0;
		for(int i = 0;i<N;i++) sum += A[i];

		int count = 0;
		for(int i = 0;i<N;i++) {
			int a = A[i]*4*M;
	
			if(a>=sum) count++;
		}
		
		if(count >= M) System.out.println("Yes");
		else System.out.println("No");

	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

struct Coord {
    Int x;
    Int y;
};
double CalcDist(Coord first, Coord second);
double CalcDistSum(vector<Coord>& coords, vector<Int>& coordId);
Int Factorial(Int n);


void PermutationLoop(Int n, vector<Coord>& coords) {
    vector<Int> v(n);
    for (Int i = 0; i < n; ++i) {
        v[i] = i;
    }

    double (*const calcDistSum[])(vector<Coord>&, vector<Int>&) = {CalcDistSum}; // 関数ポインタ
    /*
    // 関数オブジェクト(ラムダ式使用)
    auto calcDistSum = [&coords, &v]() {
        return CalcDistSum(coords, v);
    };
    */

    double sum = 0;
    do {
        sum += calcDistSum[0](coords, v); // 関数ポインタ
        //sum += calcDistSum(); // 関数オブジェクト
    } while (std::next_permutation(v.begin(), v.end()));
    cout << fixed << setprecision(10) << sum / (double)Factorial(n) << endl;
    return;
}


int main(void) {
    Int n;
    cin >> n;
    vector<Coord> coords(n);
    for (Int i = 0; i < n; ++i) {
        cin >> coords[i].x >> coords[i].y;
    }
    PermutationLoop(n, coords);
    return 0;
}

double CalcDist(Coord first, Coord second) {
    return sqrt((first.x - second.x) * (first.x - second.x) + (first.y - second.y) * (first.y - second.y));
}
double CalcDistSum(vector<Coord>& coords, vector<Int>& coordId) {
    Int size = (Int)coordId.size();
    double ret = 0;
    for (Int i = 0; i < size - 1; ++i) {
        ret += CalcDist(coords[coordId[i]], coords[coordId[i + 1]]);
    }
    return ret;
}
Int Factorial(Int n) {
    if (n == 1) {
        return 1;
    } else {
        return n * Factorial(n - 1);
    }
}



Measured memory_bytes: 3820
import Control.Monad
import Data.List

main = do
    n <- readLn
    sentences <- replicateM n getLine
    mapM_ putStrLn $ map hoshino2hosina sentences

hoshino2hosina :: String -> String
hoshino2hosina = swapWord "Hoshino" "Hoshina"

swapWord :: String -> String -> String -> String
swapWord before after str
  | length str < length before = str
  | before `isPrefixOf` str = after ++ swapWord before after (newstr)
  | otherwise               = head str : (swapWord before after $ tail str)
    where
        newstr = drop (length before) str

Measured memory_bytes: 4128
#include<bits/stdc++.h>
using namespace std;
int n,m,a[105],sum=0,p,x;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
	{
        cin>>a[i];
        sum+=a[i];
    }
    cin>>m;
    for (int i=1;i<=m;i++)
	{
        cin>>p>>x;
        cout<<sum-a[p]+x<<endl;
    }
    return 0;
}

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

int main() {
  string s; cin >> s;
  set<char> st;
  for (int i = 0; i < s.size(); i ++) st.insert(s[i]);
  if (st.size() == 2) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    long int N, A[101]={}, sum=0, MAX, WORK=0, i, j;
    cin >> N;
    
    for(i=1; i<=N; i++){
        cin >> A[i];
        sum += A[i];
    }
    
    //1日にできる最大の仕事
    MAX = sum / N;
    for(i = MAX; i>=1; i--){
        WORK=0;
        for(j=1; j<=N; j++){
            WORK += A[j];
            if(WORK < i) break;
            WORK -= i;
            if(j == N) break;
        }
        if(j == N) break;
    }
    cout << i << endl;
    return 0;
}



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

using namespace std;
typedef long long ll;

int n, m;
vector<int> S[15];
int P[15];

int main() {
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int k;
        cin >> k;
        while (k--) {
            int s;
            cin >> s;
            S[i].push_back(s);
        }
    }
    for (int i = 1; i <= m; i++) cin >> P[i];
    int ans = 0;
    for (int i = 0; i < (1 << n); i++) {
        int pos = 1;
        for (int j = 1; j <= m; j++) {
            int cnt = 0;
            for (int k : S[j]) {
                if ((i >> k - 1) & 1) cnt ^= 1;
            }
            if (cnt != P[j]) pos = 0;
        }
        ans += pos;
    }
    cout << ans;
}

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

int main() {
	
	string A,C;
	int count = 0;
	
	cin >> A;
	
	for(int i=0;i<A.length();i++)
	if( A[i] >= 'a' )
	A[i] -= 32;
	
	while( cin >> C) {
	
	if ( C == "END_OF_TEXT")
	break;
	
	for(int i=0;i<C.length();i++)
	if( C[i] >= 'a' )
	C[i] -= 32;
	
	if( A == C)
	count++;

}
	cout << count << "\n";
	return 0;
}


Measured memory_bytes: 3212
#include<iostream>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<unordered_set>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<tuple>
#include<iomanip>
#include<list>
#include<climits>
#define endl '\n'
#define ll long long
#define ld long double
#define mod 1000000007
#define mod1 998244353
#define PI acos(-1)
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	int n;
	cin>>n;
	set<string>st;
    for(int i=0;i<n;i++)
	{
		string str;
		cin>>str;
		st.insert(str);
	}
	cout<<st.size();
	
	return 0;
}

Measured memory_bytes: 19248
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

const int N=19;
const int M=20;
const int S=1<<N;
const int P=1000000007;

int res[M],val[M];
int f[2][N][S];
int n,m,K,ans,all;

inline void update(int &x,int y){(x+=y)%=P;}

inline void trans(int *tar,int *src,int id,int d)
{
	for (int s=0;s<=all;++s)
		if (src[s])
		{
			int bit=(s>>d)&1;
			for (int i=0;i<2;++i)
				if (!((res[id]>>d)&1)||!(((val[id]>>d)&1)^i))
					if (bit<i)
					{
						int rem=(s>>d+1)<<d+1,lb=rem&-rem;
						update(tar[s^lb^(1<<d)],src[s]);
					}
					else if (bit==i) update(tar[s],src[s]);
		}
}

void dp()
{
	for (int s_=all^res[0];s_;s_=(s_-1)&(all^res[0])) update(f[0][n-1][s_|val[0]],1);
	update(f[0][n-1][val[0]],1);
	for (int i=1,src,tar;i<m;++i)
	{
		tar=i&1,src=tar^1,memset(f[tar],0,sizeof f[tar]);
		trans(f[tar][0],f[src][n-1],i,0);
		for (int j=1;j<n;++j) trans(f[tar][j],f[tar][j-1],i,j);
	}
	ans=0;
	for (int s_=all^res[m-1];s_;s_=(s_-1)&(all^res[m-1])) update(ans,f[(m-1)&1][n-1][s_|val[m-1]]);
	update(ans,f[(m-1)&1][n-1][val[m-1]]);
}

int main()
{
	//freopen("zigzag.in","r",stdin),freopen("zigzag.out","w",stdout);
	scanf("%d%d%d",&n,&m,&K),--n,all=(1<<n)-1;
	for (int i=1,x,y,z;i<=K;++i) scanf("%d%d%d",&x,&y,&z),--x,--y,res[x]|=1<<y,val[x]|=(1<<y)*z;
	dp(),printf("%d\n",ans);
	//fclose(stdin),fclose(stdout);
	return 0;
}

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

typedef long long ll;

int N;
ll A,B,C,D;
ll upper[2][500010] = {0},lower[2][500010] = {0};

int main()
{
    scanf("%d%lld%lld%lld%lld",&N,&A,&B,&C,&D);
    upper[0][0] = upper[1][0] = A;
    lower[0][0] = lower[1][0] =  B;
    for(int i = 1; i < N - 1; i++)
    {
        upper[0][i] = upper[0][i - 1] + C;
        upper[1][i] = upper[1][i - 1] + D;
    }
    for(int i = 1; i < N - 1; i++)
    {
        lower[0][i] = lower[0][i - 1] + C;
        lower[1][i] = lower[1][i - 1] + D;
    }
    for(int i = 0; i < N - 1; i++)
    {
        if(upper[0][i] > lower[1][N - 1 - i] ||
           upper[1][i] < lower[0][N - 1 - i])continue;
        printf("YES\n");return 0;
    }
    printf("NO\n");return 0;
}


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

using namespace std;

/*

        Bismillahir Rahmanir Rahim
        Problem :
        Problem Link :
        Topics :
        Solver : Masud Parves
        I Love Code More than Sharks Love Blood <3
*/


#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define SZ(a)           (int)a.size()
#define all(a)  a.begin(), a.end()
#define allr(a)  a.rbegin(), a.rend()


#define sf(a)           scanf("%d",&a)
#define sff(a,b)        scanf("%d %d",&a,&b)
#define sfff(a,b,c)     scanf("%d %d %d",&a,&b,&c)

#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)

#define CIN ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define TEST_CASE(t) for(int zz=1 ; zz<=t ; zz++)
#define PRINT_CASE printf("Case %d: ",zz)
#define Debug(x)            cout<<#x " = "<<(x)<<endl
#define NOT_VISITED 0
#define IS_VISITED 1
#define WHITE 0
#define GRAY 1
#define BLACK 2



int fx[4]= {1,-1,0,0};
int fy[4]= {0,0,1,-1};

/*-----------------------Bitmask------------------*/
//int Set(int N,int pos){return N=N  (1<<pos);}
//int Reset(int N,int pos){return N= N & ~(1<<pos);}
//bool Check(int N,int pos){return (bool)(N & (1<<pos));}
/*------------------------------------------------*/


const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9+7;
const int maxn = (int)2e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<int, ll> pill;

int store[maxn][26];
int main() {
    CIN
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    string s,t;
    cin >> s >> t;

    int n = SZ(s);
    int m = SZ(t);
    s = "#"+s;
    t = "#"+t;


    for(int i=0 ; i<26 ; i++){
        store[n][i]=-1;
    }

    ///0 1 2 3 4 5 6 7
    ///# c o n t e s t
    for(int i=n-1 ; i>=0 ; i--){

        for(int j =0 ; j<26 ; j++){
            store[i][j] = store[i+1][j];
        }

        store[i][s[i+1]-'a'] = i+1;
    }

    int pre = 0;
    ll ans = 0LL;
    bool ok=1;
    for(int i=1; i<=m ;i++){
        int cur = t[i]-'a';
        //cout << cur <<" " << t[i]<< endl;
        int ret = store[pre][cur];
        //cout << -1 << endl;
        //cout << ret << endl;
        if(ret==-1){
            if(pre==0) {
                ok=0;
                break;
            }
            ans += (n-pre);
            //Debug(m);
            //Debug(pre);
            //cout << "-1 --->> "<< (n-pre) << endl;
            pre = 0;
            int _new = store[pre][cur];
            if(_new==-1){
                ok=0;
                break;
            }
            ans+=(_new-pre);
            //cout << "-1 ---> new " << _new-pre << endl;
            pre = _new;

        }else {
            ans +=(ret-pre);
            pre = ret;
        }
    }
    if(!ok)cout << "-1" << endl;
    else cout << ans << endl;


    return 0;
}



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

using namespace std;
typedef long long ll;

inline int at(ll x, int k){ return (x >> k) & 1; }
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)

map<ll,ll> prime;

class Calc
{
    // 宣言
    ll a;

    public:
        // 素因数分解
        void decompositPrime(ll a);
};

/*
 * 素因数分解
 */
void Calc::decompositPrime(ll n)
{
    // 割る数の初期値
    a = 2;
    // √n ≧ a ( n ≧ a * a ) の間ループ処理
    while (n >= a * a) {
        // a で割り切れたら、a は素因数
        // そして、割られる数を a で割る
        // a で割り切れなかったら、 a を 1 増加させる
        if (n % a == 0) {
          if(prime.count(a)>0){
            prime[a]++;
          }
          else{
            prime[a]=1;
          }
            n /= a;
        } else {
            a++;
        }
    }
    if(prime.count(n)>0){
      prime[n]++;
    }
    else{
      prime[n]=1;
    }
}

/*
 * メイン処理
 */
int main()
{
    ll  iNum;
    ll ans=0;
        Calc objCalc;
        cin  >> iNum;
        objCalc.decompositPrime(iNum);

        for (auto iter = prime.begin(); iter != prime.end(); iter++) {
          ll c=1;
          if(iter->first>1){
          while(1){
            iter->second -= c;
            if(iter->second>=0){
              ans++;
            }
            else{
              break;
            }
            c++;
          }
        }

    }
    cout << ans<< endl;


    // 正常終了
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vint a(n);
  deque<int> x;
  rep(i,n){
    cin>>a[i];
    if(n%2==0){
      if(i%2==1){
        x.push_front(a[i]);
      }
      else{
        x.push_back(a[i]);
      }
    }
    else{
      if(i%2==1){
        x.push_back(a[i]);
      }
      else{
        x.push_front(a[i]);
      }
    }
  }
  for(auto su: x){
    cout<<su<<' ';
  }
  return(0);
}


Measured memory_bytes: 3840
#include <iostream>
#include<vector> 
using namespace std;
int main()
{
	
	long long int n; 
	cin >> n;  
	long long int ans = 1; 
	long long int a = 1000000000 + 7;
	for (int i = 1; i <= n; i++)
	{
		ans = (i*ans) % a;
			
		
	} 
	cout << ans << endl;
	
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

struct State{
    int at;
    long long cost;
    State(int a, long long c) : at(a), cost(c){}
    bool operator>(const State& s) const{
        return cost > s.cost;
    }
};

struct Edge{
    int to;
    long long cost;
    Edge(int t, long long c) : to(t), cost(c){}
};

using Graph = vector<vector<Edge> >;
const long long INF = 1e15;

void dijkstra(int s, const Graph& G, vector<long long>& minc){
    minc.assign(G.size(), INF);
    priority_queue<State, vector<State>, greater<State> > pq;
    pq.emplace(s, 0);
    minc[s] = 0;

    while(!pq.empty()){
        State cur = pq.top();
        pq.pop();
        if(minc[cur.at] < cur.cost) continue;
        for(const Edge& e : G[cur.at]){
            long long cost = cur.cost + e.cost;
            if(minc[e.to] <= cost) continue;
            minc[e.to] = cost;
            pq.emplace(e.to, cost);
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int v, e, r;
    cin >> v >> e  >> r;
    Graph G(v);
    rep(i,e){
		int s, t;
		ll d;
		cin >> s >> t >> d;
		G[s].emplace_back(t, d);
	}
    vector<ll> dist(v, INF);
	dijkstra(r, G, dist);
	rep(i,v){
		if(dist[i] != INF) cout << dist[i] << endl;
		else cout << "INF" << endl;
	}
    return 0;
}


Measured memory_bytes: 19344
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,D,E,K;cin>>A>>B>>C>>D>>E>>K;
  if(abs(A-B)>K)
  {
    cout<<":("<<endl;
  }
  else if (abs(C-B)>K)
  {
    cout<<":("<<endl;
  }
   else if(abs(D-C)>K)
  {
    cout<<":("<<endl;
  }
  else if(abs(D-E)>K)
  {
    cout<<":("<<endl;
  }
   else if(abs(A-C)>K)
  {
    cout<<":("<<endl;
  }
   else if(abs(A-D)>K)
  {
    cout<<":("<<endl;
  }
   else if(abs(A-E)>K)
  {
    cout<<":("<<endl;
  }
   else if(abs(B-D)>K)
  {
    cout<<":("<<endl;
  }
   else if(abs(B-E)>K)
  {
    cout<<":("<<endl;
  }
   else if(abs(C-E)>K)
  {
    cout<<":("<<endl;
  }
  
  else
  {
    cout<<"Yay!"<<endl;
  }
}


  
    

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

int main(){
	int n,k;
	cin >> n >> k;
	int h[n];
	for(int i = 0; i < n; i++)cin >> h[i];
	sort(h, h + n);
	int min = 1e9;
	for(int i = 0; i < n - k + 1; i++){
		if(h[i + k - 1] - h[i] < min)min = h[i + k - 1] - h[i];
	}
	cout << min << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

ll n;
string s, MAX, MIN;


ll changei(string s){
	ll k;
	stringstream ss;
	ss << s;
	ss >> k;
	return k;
}

int main(){
	cin >> n;
	REP(i, n){
		ll ma, mi;
		cin >> s;
		sort(ALL(s),greater<int>());
		MAX = s;
		ma = changei(MAX);
		sort(ALL(s));
		MIN = s;
		mi = changei(MIN);
		cout << ma - mi << endl;
	}
}

Measured memory_bytes: 1240
#include <string>
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#define llint long long
#define inf 1000000000000000000

using namespace std;

struct SegTree{
	int size;
	vector<llint> seg;
	
	SegTree(){}
	SegTree(int size){
		this->size = size;
		seg.resize(1<<(size+1));
	}
	void init()
	{
		for(int i = 0; i < (1<<(size+1)); i++) seg[i] = inf;
	}
	void update(int i, llint val)
	{
		i += (1<<size);
		seg[i] = val;
		while(i > 1){
			i /= 2;
			seg[i] = min(seg[i*2], seg[i*2+1]);
		}
	}
	llint query(int a, int b, int k, int l, int r)
	{
		if(b < l || r < a) return inf;
		if(a <= l && r <= b) return seg[k];
		llint lval = query(a, b, k*2, l, (l+r)/2);
		llint rval = query(a, b, k*2+1, (l+r)/2+1, r);
		return min(lval, rval);
	}
	llint query(int a, int b)
	{
		return query(a, b, 1, 0, (1<<size)-1);
	}
};

llint n, L;
llint l[200005], r[200005];
vector<llint> comp;
llint dp[400005];
llint dif[400005], sum[400005];
vector<llint> vec[400005];
SegTree seg(19);

int main(void)
{
	cin >> n >> L;
	for(int i = 1; i <= n; i++) cin >> l[i] >> r[i];
	
	for(int i = 1; i <= n; i++) comp.push_back(l[i]), comp.push_back(r[i]);
	sort(comp.begin(), comp.end());
	comp.erase(unique(comp.begin(), comp.end()), comp.end());
	for(int i = 1; i <= n; i++) l[i] = lower_bound(comp.begin(), comp.end(), l[i]) - comp.begin() + 1;
	for(int i = 1; i <= n; i++) r[i] = lower_bound(comp.begin(), comp.end(), r[i]) - comp.begin() + 1;
	for(int i = 1; i <= n; i++) vec[r[i]].push_back(l[i]);
	
	llint m = comp.size();
	//cout << m << endl;
	
	//for(int i = 1; i <= n; i++) cout << l[i] << " " << r[i] << endl;
	
	seg.init();
	seg.update(1, 0);
	for(int i = 2; i <= m; i++){
		llint mn = inf;
		for(int j = 0; j < vec[i].size(); j++){
			mn = min(mn, seg.query(vec[i][j], i-1));
		}
		seg.update(i, mn+1);
	}
	llint ansx = seg.query(m, m);
	
	for(int i = 1; i <= n; i++){
		dif[l[i]]++, dif[r[i]]--;
	}
	llint ansy = inf;
	for(int i = 1; i < m; i++){
		sum[i] = sum[i-1] + dif[i];
		ansy = min(ansy, sum[i]);
	}
	//cout << ansy << endl;
	ansy = n - ansy + 1;
	
	cout << ansx << " " << ansy << endl;
	
	return 0;
}


Measured memory_bytes: 38272
package main

import "fmt"

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func main() {
	// Code for A - Ice Tea Store
	var Q, H, S, D int
	fmt.Scanf("%d %d %d %d", &Q, &H, &S, &D)

	var N int
	fmt.Scanf("%d", &N)

	ans := (N/2)*min(8*Q, min(4*H, min(2*S, D))) + N%2*min(4*Q, min(2*H, S))
	fmt.Println(ans)
}


Measured memory_bytes: 1832
high,wide,end=map(int,input().split())

dp=[[[-1,-1,-1] for _ in range(wide)] for _ in range(high)]
fb=[-1 for _ in range(8)]
fb[0]=1
fb[1]=1
def MakeFibo(i):
    if fb[i-1]==-1:
        fb[i-1]=MakeFibo(i-1)
    if fb[i-2]==-1:
        fb[i-2]=MakeFibo(i-2)
    fb[i]=fb[i-1]+fb[i-2]
    return fb[i]
MakeFibo(7)
#fit 0
wide-=1
high-=1
end-=1
mod=10**9+7
def NZ(x):  #NegativeZero
    if x<0:
        return 0
    else:
        return x


def amida(h,w,f):
    dp[h][w][2]=fb[NZ(w)]*fb[NZ(wide-w)]
    if f == 1: #go straight
        if h==high and w==end:
            dp[h][w][f]=1
        elif h==high:
            dp[h][w][f]=0
        else: #sum under
            if dp[h+1][w][1] == -1:
                amida(h+1,w,1)
            if dp[h+1][w][0] == -1:
                amida(h+1,w,0)
            dp[h][w][f]=dp[h+1][w][0]+dp[h+1][w][1]*dp[h+1][w][2]
    else: #f==0 go side
        dp[h][w][f]=0
        if w-1>=0: #sum left
            if dp[h][w-1][1]==-1:
                amida(h,w-1,1)
            dp[h][w][f]+=dp[h][w-1][1]*fb[NZ(w-1)]*fb[NZ(wide-w)]
        if w+1<=wide: #sum right
            if dp[h][w+1][1]==-1:
                amida(h,w+1,1)
            dp[h][w][f]+=dp[h][w+1][1]*fb[NZ(w)]*fb[NZ(wide-w-1)]
    dp[h][w][f]%=mod

amida(0,0,0)
amida(0,0,1)

print((dp[0][0][0]+dp[0][0][1]*dp[0][0][2])%mod)

Measured memory_bytes: 3192
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }


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

    // ifstream fin(".in");
    // ofstream fout(".in");

i64 n,a,b;
cin>>n>>a>>b;
cout<<min(a,b)<<" "<<max(0LL,a+b-n);


    return 0;
  }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

// 素数判定O(√n)
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

int main(){
    int n;
    cin>>n;
    vector<int> ans;
    for(int i=2;i<=55555;i++){
        if(is_prime(i) && i%5==1) ans.push_back(i); 
    }

    rep(i,n) cout<<ans[i]<<" ";
    cout<<endl;
}


 

Measured memory_bytes: 256