akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}
struct multi {
  ll first;
  ll second;
  ll third;
  multi(ll first, ll second, ll third)
      : first(first), second(second), third(third) {}
};
bool multicomp(const multi &a, const multi &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vector<vector<char>> S = VV(char, N, N, 0);
  REP(i, N) REP(j, N) cin >> S[i][j];
  ll ans = 0;
  REP(k, N) {
    bool ok = true;
    REP(i, N - 1) FOR(j, i + 1, N) {
      if (S[(i + k) % N][j] != S[(j + k) % N][i]) {
        ok = false;
      }
    }
    if (ok)
      ans++;
  }
  cout << ans * N << endl;

  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

int main(){
	int N, A, B, C, D; cin >> N >> A >> B >> C >> D;
	A--; B--; C--; D--;
	string S; cin >> S;

	int a = A, b = B;
	vector<pair<int, int> > br;
	bool bg = false;

	bool reachable = true;
	for(int i = A; i < D; ++i){
		if(S[i] == '#' && S[i+1] == '#') reachable = false;
	}	

	if(!reachable) { cout << "No" << endl; return 0; }

	if(C > B){
		if(C < D){
			if(reachable) { cout << "Yes" << endl; return 0; }
		}else{
			for(int i = b; i <= D; ++i){
				if(S[i-1] == '#' || S[i+1] == '#'){
					br.push_back(make_pair(i, 0));
				} else {
					br.push_back(make_pair(i, 1)); bg = true;
				}

				if(S[i+1] == '#') { i++; }
			}
          
			if(bg) cout  << "Yes" << endl;
			else cout << "No" << endl;
		}
	}else{
		if(reachable) cout << "Yes" << endl;
	}

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define debug printf("bug!!!\n");
typedef long long ll;
const int MAXN=1e4+10;
const ll MOD=1e9+7;

int main(){
    int n;
    cin>>n;
    int m=n/1000;
    m++;
    m*=1000;
    cout<<(m-n)%1000<<endl;



    return 0;
}



Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int main()
{
    int m, f, b;
    cin >> m;
    cin >> f;
    cin >> b;

    if (m >= b)
    {
        cout << 0 << endl;
        return 0;
    }

    if (m+f >= b)
    {
        cout << b-m << endl;
        return 0;
    }

    cout << "NA" << endl;
}

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

public class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var N = vals[0];
        var M = vals[1];
        var p = new int[M];
        var S = new string[M];
        for (int i = 0; i < M; i++)
        {
            var str = Console.ReadLine().Split(' ');
            p[i] = int.Parse(str[0]);
            S[i] = str[1];
        }

        var ok = 0;
        var penalty = 0;
        var wa = new int[N + 1];
        var ac = new bool[N + 1];
        for (int i = 0; i < M; i++)
        {
            var id = p[i];
            var isAC = S[i] == "AC";
            if (isAC && !ac[id])
            {
                penalty += wa[id];
                ac[id] = true;
                ok++;
            }
            if (!isAC)
            {
                wa[id]++;
            }
        }

        Console.WriteLine($"{ok} {penalty}");
    }
}

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, __VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

#define MOD 1000000007
#define INF 1000000000
#define MAX_N 100010

// 取れる場所ならどこ取っても結果変わらない説

string S;

// s : 現在の文字列
// player : 取る番の人
// 0 ... first 1 ... second
int dfs(string s, int player) {
    int next = (player == 0) ? 1 : 0;
    if(s.length() <= 2) { return next; }
    for(int i = 1; i < s.length() - 1; ++i) {
        if(s[i-1] != s[i+1]) {
            s.erase(s.begin() + i);
            return dfs(s, next);
        }
    }
    return next;
}

int main()
{
    cin >> S;
    //if(dfs(S, 0) == 0) { printf("First\n"); }
    //else { printf("Second\n"); }
    size_t getable = 0;
    if(S[0] != S[S.length()-1]) {
        // 両端が違う文字 → 残り 2 文字までいける
        getable = S.length() - 2;
    } else {
        // 両端が同じ文字
        set<char> alph;
        for(int i = 0; i < S.length(); ++i) {
            alph.insert(S[i]);
        }
        if(alph.size() >= 3) {
            // 3 種類以上あるなら n-1 取れる
            getable = S.length() - 3;
        } else {
            getable = 0;
        }
    }
    if(getable % 2 != 0) { printf("First\n"); }
    else { printf("Second\n"); }

    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

void display(int A[], int N) {
  for(int i = 0; i < N; i++) {
    if(i > 0) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

void insertionSort(int A[], int N) {
  int v, j;
  for(int i = 1; i < N; i++) {
    v = A[i];
    j = i - 1;
    while (j >= 0 && A[j] > v) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    display(A, N);
  }
}

int main() {
  int n, A[100];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &A[i]);
  display(A, n);
  insertionSort(A, n);
  return 0;
}


Measured memory_bytes: 2756
N, K = list(map(int, input().split()))
A = set(map(int, input().split()))

dp = [False]*(K+1)
dp[0] = False
for i in range(K):
    if dp[i]:
        continue
    for s in A:
        if i+s <= K:
            dp[i+s] = True
# print(dp)
if dp[K]:
    print('First')
else:
    print('Second')


Measured memory_bytes: 67964
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int mod = 1000000007;
const int inf = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int n, t;
    cin >> n >> t;
    vector<P> p(n);
    rep(i,n) cin >> p[i].first >> p[i].second;
    int dp[n+1][t+1];
    repn(i,n) fill(dp[i], dp[i]+t+1, 0);
    sort(p.begin(), p.end());
    int ans = 0;
    rep(i,n){
        rep(j,t){ 
            chmax(dp[i+1][j], dp[i][j]);
            int nj = j + p[i].first;
            if(nj < t) chmax(dp[i+1][nj], dp[i][j]+p[i].second);
        }
        int now = dp[i][t-1] + p[i].second;
        chmax(ans, now);
    }
    cout << ans << endl;
}

Measured memory_bytes: 35456
#include <iostream>
#include <stack>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
using namespace std;
typedef pair<int,int> P;

int main(){
    string l;
    getline(cin,l);
    stack<int> bef;
    vector<P> ps;
    for(int i=0;i<l.size();i++){
        if(l[i]=='\\') bef.push(i);
        if(l[i]=='/' && !bef.empty()){
            ps.push_back(P(bef.top(),i));
            bef.pop();
        }
    }
    sort(begin(ps),end(ps));
    ps.push_back(P(l.size(),l.size()));
    vector<int> ls;
    int end=-1,now=0;
    for(int i=0;i<ps.size();i++){
        int nf=ps[i].first,ns=ps[i].second;
        if(nf>end){
            if(now>0) ls.push_back(now);
            now=0;
            end=ns;
        }
        now+=ns-nf;
    }
    printf("%d\n%d",accumulate(ls.begin(),ls.end(),0),ls.size());
    for(int i=0;i<ls.size();i++){
        printf(" %d",ls[i]);
    }
    printf("\n");
}

Measured memory_bytes: 1388
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

int main(){
	ll n,k;
	cin>>n>>k;
	ll arr[n+1];
	for(ll i=0;i<n;i++){
		cin>>arr[i];
	}
	ll dp[n+1];
	memset(dp,0,sizeof(dp));
	//for(ll i=0;i<n;i++){
	//	dp[i]
	//}
	dp[0]=0;
	for(ll i=1;i<n;i++){
		//if(i>=1){
			dp[i]=dp[i-1]+abs(arr[i]-arr[i-1]);
	//	}
	//	if(i>=2){
			
	//	}
		
		for(ll j=2;j<=k;j++){
			if(i>=j){
				dp[i]=min(dp[i],dp[i-j]+abs(arr[i]-arr[i-j]));
			}
		}
		
	//	cout<<dp[i]<<' ';
	}
	//cout<<'\n';
	cout<<dp[n-1];
	
}

Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<limits>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9)+7)

int main(){
  int a,b,m;
  cin >> a >> b >> m;
  vector<int> A;
  vector<int> B;
  for(int i = 0;i < a;i++)
  {
    int p;
    cin >> p;
    A.push_back(p);
  }
  for(int i = 0;i < b;i++)
  {
    int p;
    cin >> p;
    B.push_back(p);
  }
  vector<int> x;
  vector<int> y;
  vector<int> C;
  for(int i = 0;i < m;i++)
  {
    int p,q,r;
    cin >> p >> q >> r;
    x.push_back(p);
    y.push_back(q);
    C.push_back(r);
  }

  int min_1 = 1000000;

  for(int i = 0;i < m;i++)
  {
    if(min_1 > A[x[i]-1]+B[y[i]-1]-C[i])
    {
      min_1 = A[x[i]-1]+B[y[i]-1]-C[i];
    }
  }

  sort(A.begin(),A.end());
  sort(B.begin(),B.end());

  cout << min(A[0]+B[0],min_1) << endl;
}


Measured memory_bytes: 2552
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let mut a = vec![0; n];
    let mut cnt = 0;

    for i in 0..n {
        a[i] = read::<i64>();
        while a[i] % 2 == 0 {
            a[i] /= 2;
            cnt+=1;
        }
    }
    println!("{}", cnt);
}

Measured memory_bytes: 4352
import collections

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

if __name__ == "__main__":
    N = int(input())
    c = collections.Counter(prime_factorize(N))
    l = list(c.values())
    counter = 0
    for f in l:
        num = 1
        while f >= num:
            f -= num
            num += 1
            counter += 1
    print(counter)


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

int main(void){
	int h, w;

	while(cin >> h >> w){
		if(h == 0 && w == 0) break;
		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				if(i==0 || i==h-1 || j==0 || j== w-1)printf("#");
				else printf(".");
			}
			puts("");
		}
		puts("");
	}

	return 0;
}

Measured memory_bytes: 1120
S = input()
T = ''
t = ''
result = 'YES'
dream_list = ['maerd', 'remaerd', 'esare', 'resare']

for i in range(1, len(S)+1):
    t += S[-i]
    if t in dream_list:
        T += t
        t = ''

    if len(t) >7:
        result = 'NO'
        break

if t != '':
    result = 'NO'

print(result)

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

int main(int argc, char const *argv[])
{
    int i, j, k, n, m, x;
    int **skills, *costs;
    int beki = 1;
    int mincost = 0;
    int cost, skill_lv, lv_shortage_flag, suc_flag=0;
    scanf("%d %d %d", &n, &m, &x);

    costs = (int*)malloc(sizeof(int) * n);
    skills = (int**)malloc(sizeof(int*) * n);
    for(i = 0; i < n; i++) {
        skills[i] = (int*)malloc(sizeof(int) * m);
    }

    for(i = 0; i < n; i++) {
        scanf("%d", &costs[i]);
        mincost += costs[i];
        for(j = 0; j < m; j++) {
            scanf("%d", &skills[i][j]);
        }
    }
    
    for(i = 0; i < n; i++) {
        beki *= 2;
        mincost += costs[i];
    }
    for(i = 0; i < beki; i++) {
        lv_shortage_flag = 0;
        cost = 0;
        for(k = 0; k < n; k++) {
            if((i >> k) % 2) cost += costs[k];
        }
        if(cost > mincost) continue;

        for(j = 0; j < m; j++) {
            skill_lv = 0;
            for(k = 0; k < n; k++) {
                if((i >> k) % 2) skill_lv += skills[k][j];
            }
            if(skill_lv < x) {
                lv_shortage_flag = 1;
                break;
            }
        }
        if(!lv_shortage_flag) {
            mincost = cost;
            suc_flag = 1;
        }
    }

    if(!suc_flag) printf("-1\n");
    else printf("%d\n", mincost);
    return 0;
}

Measured memory_bytes: 1692
using System;

class Program
{
    public static void Main(string[] args)
    {
        string[] str = Console.ReadLine().Split(' ');
        int a = int.Parse(str[0]);
        int b = int.Parse(str[1]);

        if (a * b % 2 == 0)
            Console.WriteLine("Even");
        else
            Console.WriteLine("Odd");
    }
}

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

// {
#define debug(var)  do{ std::cout << #var << " : "; view(var); }while(0)
using ll = long long;
using ld = long double;
inline int num (const std::string& S, int idx) noexcept { return S.at(idx) - '0'; }
inline int ctoi(char c) noexcept { return c - '0'; }
inline bool isNumber(char c) noexcept { return ('0'<c && c<'9'? true : false); }
inline int safeCtoi(char c) { if(isNumber(c)) { return ctoi(c); } else { throw 1; } }
inline char itoc(int i) noexcept { return i + '0'; }
inline unsigned int bitMask(int i) noexcept { return (1 << i); }
inline bool isTrue(unsigned int bit, int i) noexcept { return bit & bitMask(i); }
inline bool isEven(int num) noexcept { return !num%2; }
inline bool isOdd(int num) noexcept { return num%2; }
template<typename T> inline short sgn(T num) noexcept { return (num==0? 0 : (num>0? 1 : -1) ); }
template<typename T> inline bool isZero(T num) noexcept { return (num==0? true : false); }
template<typename T> inline bool isPositive(T num) noexcept { return (num>0? true : false); }
template<typename T> inline bool isNegative(T num) noexcept { return (num<0? true : false); }
template<typename T> void view(T e) noexcept { cout << e; }
template<typename T> void view(std::vector<T> v) noexcept { for(const auto& e : v) cout << e << " "; }
template<typename T> void view(std::vector<std::vector<T>> vv) noexcept { for(const auto& v : vv) view(v); }
//}


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	n %= 10;
	switch(n){
		case 2:
		case 4:
		case 5:
		case 7:
		case 9:
			cout << "hon" << endl;
			break;
		case 0:
		case 1:
		case 6:
		case 8:
			cout << "pon" << endl;
			break;
		case 3:
			cout << "bon" << endl;
			break;
	}
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i=0; i<(int)(n); ++i)
#define rep2(i, a, b) for(int i=a; i<=(int)(b); ++i)
#define all(v) v.begin(),v.end()
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int k, s, ans = 0;
  cin >> k >> s;
  rep2(i, 0, k) {
    int tmp = s-i;
    if (tmp < 0 || tmp > 2*k) continue;
    if (tmp > k) ans += 2*k-tmp+1;
    else ans += (tmp + 1);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
	ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	ll n, a, b, var, count[3] = {0};
	cin >> n >> a >> b;
	while(n--) {
		cin >> var;
		if(var <= a)
			++count[0];
		else if(var <=b)
			++count[1];
		else
			++count[2];
	}
	sort(count, count + 3);
	cout << count[0];
	return 0;
}

Measured memory_bytes: 256
H, W, K = gets.split(' ').map(&:to_i)
MOD = 10 ** 9 + 7

dp = Array.new(H + 1){Array.new(W + 2, 0)}
dp[0][1] = 1
lines = []

if W == 1
  puts 1
else
  [0, 1].repeated_permutation(W - 1) do |line|
    valid = true
    0.upto(W - 2) do |i|
      valid = false if line[i] == 1 && line[i + 1] == 1
    end
    lines.push([0] + line + [0]) if valid
  end
  1.upto(H) do |h|
    lines.each do |line|
      1.upto(W) do |j|
        if line[j - 1] == 1
          dp[h][j] += dp[h - 1][j - 1]
        elsif line[j] == 1
          dp[h][j] += dp[h - 1][j + 1]
        else
          dp[h][j] += dp[h - 1][j]
        end
        dp[h][j] %= MOD
      end
    end
  end
  puts dp[H][K]
end

Measured memory_bytes: 1788
using System;

public class Class1
{
	public static void Main()
	{
        int N = int.Parse(Console.ReadLine());
        string slimes = Console.ReadLine();
        int cnt = 1;
        for(int i = 1; i < N; i++)
        {
            if(slimes[i-1] != slimes[i])
            {
                cnt++;
            }
        }
        Console.WriteLine(cnt);
    }
}


Measured memory_bytes: 11232
#include<iostream>
#include<vector>
#include<algorithm>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll n,k;
  vector<vector<ll>> dp(101,vector<ll>(100001,0));
  vector<vector<ll>> dsum(101,vector<ll>(100001,0));
  cin >> n >> k;
  ll a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  dp[n][0]=1;
  fill(dsum[0].begin(),dsum[0].end(),1);
  for(int i=0;i<n;i++){
    for(int j=0;j<=k;j++){
      if(j-a[i]>0){
        dp[i+1][j]=dsum[i][j]-dsum[i][j-a[i]-1];
      }else{
        dp[i+1][j]=dsum[i][j];
      }
      dp[i+1][j]%=MOD;
    }
    dsum[i+1][0]=dp[i+1][0];
    for(int j=1;j<=k;j++){
      dsum[i+1][j]=dp[i+1][j]+dsum[i+1][j-1];
    }
  }
  /*
  for(int i=0;i<=n;i++){
    for(int j=0;j<=k;j++){
      cout << dp[i][j]<<" ";
    }
    cout << endl;
  }
  cout << endl;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=k;j++){
      cout << dsum[i][j]<<" ";
    }
    cout << endl;
  }
  */
  cout << dp[n][k]%MOD<<endl;
}


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

const int N=105;
int n;

main()
{
    cin>>n;
    int res=0;
    for(int i=1;i<=n;i++)
    {
        int num=n/i;
        if(n%i==0) num--;
        res+=num;
    }
    cout<<res;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};


  
int main(){
  
  int n;
  cin>>n;
  int h[n];
  bool flag = true;
  REP(i,n){
    cin>>h[i];
  }
  for(int i=n-2;i>=0;i--){
    if(h[i]<=h[i+1]){
      continue;
    }else{
      h[i]--;
      if(h[i]>h[i+1]){
        flag = false;
        break;
      }
    }
  }
  if(flag){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

map<int, int> fs;
void prime_factors(int n) {
	if(n == 1) { // n=1 の素因数分解は n^1
		fs[n]++;
		return;
	}
	for(int i = 2, _n = n; i*i <= _n; ++i) {
		while(n % i == 0) {
			++fs[i]; // 素因数i^{res[i]}
			n /= i;
			}
		}
	if(n != 1) fs[n]++; // nが素数のとき
	return;
}

map<int, int> prime_factors2(int n) {
	map<int, int> res;
	if(n == 1) { // n=1 の素因数分解は n^1
		res[n] = 1;
		return res;
	}
	for(int i = 2, _n = n; i*i <= _n; ++i) {
		while(n % i == 0) {
			++res[i]; // 素因数i^{res[i]}
			n /= i;
			}
		}
	if(n != 1) res[n] = 1; // nが素数のとき
	return res;
}

int main() {
	int n; cin >> n;
	FOR(i, 2, n+1) prime_factors(i);
    int s75 = 0, s25 = 0, s15 = 0, s5 = 0, s3 = 0;
	for(const auto& p: fs) {
        if (p.se>=74) s75++;
        if (p.se>=24) s25++;
        if (p.se>=14) s15++;
        if (p.se>=4) s5++;
        if (p.se>=2) s3++;
    }
    debug(s75, s25, s15, s5, s3);
    int ans = 0;
    ans += s75;
    ans += s25 * (s3-1);
    ans += s15 * (s5-1);
    ans += s5*(s5-1)/2 * (s3-2);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	char str[1001];
	int ans;
	for (;;) {
		scanf("%s", str);
		if (str[0] == '0') {
			break;
		}
		ans = 0;
		for (int i = 0; str[i] != '\0'; i++) {
			ans += str[i] - '0';
		}
		printf("%d\n", ans);
	}
}



Measured memory_bytes: 2120
/**
 * File    : A.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-11-9 17:09:19
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  if (A + B >= C)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

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

#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
const int MAXN = 1e6+5;
const int MOD= 998244353;

int main(){
    int n;
    while(cin>>n){
        cout<<ceil(1.0*n/2)<<endl;
    }
}


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

class F
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var rs = new int[n - 1].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();
		map = rs.Concat(rs.Select(r => new[] { r[1], r[0] })).ToLookup(r => r[0], r => r[1]).ToDictionary(g => g.Key, g => g.ToArray());

		tour = new int[n + 1].Select(_ => new List<int>()).ToArray();
		Dfs(1, 0);

		Console.WriteLine((tour.Select(l => Hole(l, n - 1)).Aggregate((x, y) => x + y) / 2).V);
	}

	static Dictionary<int, int[]> map;
	static List<int>[] tour;
	static int c;
	static void Dfs(int p, int p0)
	{
		foreach (var x in map[p])
		{
			if (x == p0) continue;
			tour[x].Add(++c);
			Dfs(x, p);
			tour[p].Add(++c);
		}
	}

	static MInt Hole(List<int> l, int m)
	{
		if (l.Count < 2) return 0;

		MInt allWhite = 1, bSum = 0;
		for (int i = 0; i < l.Count; i++)
		{
			var c = ((l[(i + 1) % l.Count] - l[i]) / 2 + m) % m;
			var w = 1 / ((MInt)2).Pow(c);

			allWhite *= w;
			bSum += 1 / w - 1;
		}
		return 1 - allWhite * (1 + bSum);
	}
}

struct MInt
{
	const int M = 1000000007;
	public long V;
	public MInt(long v) { V = (v %= M) < 0 ? v + M : v; }

	public static implicit operator MInt(long v) => new MInt(v);
	public static MInt operator +(MInt x) => x;
	public static MInt operator -(MInt x) => -x.V;
	public static MInt operator +(MInt x, MInt y) => x.V + y.V;
	public static MInt operator -(MInt x, MInt y) => x.V - y.V;
	public static MInt operator *(MInt x, MInt y) => x.V * y.V;
	public static MInt operator /(MInt x, MInt y) => x * y.Inv();

	public MInt Pow(int i) => MPow(V, i);
	public MInt Inv() => MPow(V, M - 2);

	static long MPow(long b, int i)
	{
		for (var r = 1L; ; b = b * b % M)
		{
			if (i % 2 > 0) r = r * b % M;
			if ((i /= 2) < 1) return r;
		}
	}
}


Measured memory_bytes: 88520
N,Y=map(int,input().split())
for x in range(N+1):
    for y in range(N-x+1):
        z=N-x-y
        if 0<=z<=2000 and 10000*x+5000*y+1000*z==Y:
            print(x,y,z)
            exit()
print(-1,-1,-1)


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

int gcd(int &a, int &b, int &c){
  int s = min(a, min(b, c));
  for(int i = s; i >= 1; i--){
    if(a%i==0 && b%i==0 && c%i==0) return i;
  }
}

int main(){
  int K;
  cin >> K;
  
  int sum = 0;
  
  for(int a=1; a <= K; a++){
    for(int b=1; b <= K; b++){
      for(int c=1; c <= K; c++){
        
        sum += gcd(a,b,c);
        
      }
    }
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 3648
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

K,A,B = imn()

tmp = A-1
cnt = (K-tmp)
ans = (cnt//2)*B
ans -= (cnt//2-1)*(A)
ans += cnt%2

print(max(K+1, ans))

Measured memory_bytes: 5556
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define REP(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define TF(flag) (flag)?1:0
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ================================================

// Template End ======================================================

int main(void){
  string s; cin>>s;
  cout<<s.substr(0,5)<<" "<<s.substr(6,7)<<" "<<s.substr(14,5);
}














Measured memory_bytes: 256
import java.util.Scanner;
import java.util.HashMap;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        int H = scan.nextInt();
        int W = scan.nextInt();
        
        for(int i = 0; i < H+2; i++) {
            if(i == 0 || i == H+1) {
                for(int j = 0; j < W+2; j++) {
                    System.out.print("#");
                }
                System.out.println();
            } else {
                System.out.println("#" + scan.next() + "#");
            }
        }
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

const int MOD = 1e9+7;

long long extGCD(long long a, long long b, long long* x, long long* y){
    if(b == 0){
        *x = 1;
        *y = 0;
        return a;
    }

    long long s, t;
    long long d = extGCD(b, a % b, &s, &t);
    *x = t;
    *y = (s - ((a / b) * t) % MOD + MOD) % MOD;
    
    return d;
}

int main(){

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

    if(N == 2){
        cout << x[1] - x[0] << endl;
    }
    else{
        long long p = 1;
        for(int i = 1; i <= N - 1; i++){
            p = (p * i) % MOD;
        }
        long long ans = (p * (x[N - 1] - x[0])) % MOD;
        long long xx, yy;
        long long temp = 0;
        for(int i = 1; i < N - 1; i++){
            extGCD(i + 1, MOD, &xx, &yy);
            temp = (temp + xx) % MOD;

            long long plus = (temp * (x[i + 1] - x[i])) % MOD;
            ans = (ans + (p * plus) % MOD) % MOD;
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#define ll long long
using namespace std;
ll a,b,c;
int main()
{
	scanf("%lld%lld%lld",&a,&b,&c);
	if (a%2==0 || b%2==0 || c%2==0)
		printf("0\n");
	else
	{
		if (b>c) swap(b,c);
		if (a>c) swap(a,c);
		printf("%lld\n",a*b);
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int n,tmp,odd=1;
    cin>>n;
    for(int i = 0; i < n; i++){cin>>tmp;if(!(tmp%2))odd*=2;}
    cout<<pow(3,n)-odd<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
using Graph = vector<vector<int>>;



int main(){
    int A[11] ={0};
    rep(i,3){
        int x;
        cin >> x;
        A[x]++;
    }
    if(A[5]==2&&A[7]==1) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
from itertools import accumulate

def getRangeSum(accXs, iFr, iTo):
    return accXs[iTo+1] - accXs[iFr]

def getAns(accXs, accRevXs, Xs, revXs):
    ans = 0
    for i in range(N):
        num = (N-i)//2
        dist = 2 * getRangeSum(accXs, i, i + num-1)
        dist += 2 * getRangeSum(accRevXs, 0, num-1)
        if (N-i)%2 == 0:
            dist -= revXs[num-1]
        else:
            dist += Xs[i + num]
        ans = max(ans, dist)
    return ans

L, N = map(int, input().split())
Xs = [int(input()) for _ in range(N)]

revXs = [L-X for X in reversed(Xs)]
accXs = [0] + list(accumulate(Xs))
accRevXs = [0] + list(accumulate(revXs))

print(max(getAns(accXs, accRevXs, Xs, revXs), getAns(accRevXs, accXs, revXs, Xs)))


Measured memory_bytes: 39328
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
static const int giga = pow(10,9);

int main(void){
  string s1,s2,s3;
  cin >> s1 >> s2 >> s3;
  char a,b,c;
  a = (s1[0] - 'a') + 'A';
  b = (s2[0] - 'a') + 'A';
  c = (s3[0] - 'a') + 'A';
  cout << a << b << c << endl;

  return 0;
}

Measured memory_bytes: 256
<?php
list($h,$w)=explode(" ",trim(fgets(STDIN)));
$ans=str_split(strtoupper("abcdefghijklmnopqrstuvwxyz"));
$i=1;
while($i<=$h){
  $s=explode(" ",trim(fgets(STDIN)));
  if(array_keys($s,"snuke")){
    $k=array_keys($s,"snuke");
    $key=$k[0];
    echo $ans[$key].$i;
    exit;
  }
  ++$i;
}

Measured memory_bytes: 4856
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    int a,b,c;
    cin >> a>> b >> c;
    if (a+b >= c) {
        cout << "Yes" << endl;
    }  
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3632
#!/usr/bin/env python
"""AtCoder Beginner Contest 168: A - 
https://atcoder.jp/contests/abc168/tasks/abc168_a
"""

__author__ = 'bugttle <bugttle@gmail.com>'


def main():
    N = input()

    v = int(N[-1]) % 10
    if v in {2, 4, 5, 7, 9}:
        print('hon')
    elif v in {0, 1, 6, 8}:
        print('pon')
    elif v in { 3}:
        print('bon')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9188
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <string>

using namespace std;

int main() {

	int a,b; 
	cin >> a >> b;
	string tmp = to_string(a) + to_string(b);
	int tmp1 = stoi(tmp);
	int cnt = 0;
	int tmp2 = 1000;
	
	for (int i = 1; i <= tmp2; ++i) {
		if (tmp1 == i*i) {
			cout << "Yes" << endl;
			cnt++;
		}
	}

	if (cnt == 0) {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
/**
*    author:  boutarou
*    created: 21.06.2020 21:01:58
**/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define fcout cout << fixed << setprecision(15)
using lint = long long;
using P = pair<int, int>;

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

const double PI = 3.1415926535897932;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int  n, k;
    int a[1005];
    cin >> n >> k;
    rep(i, n) cin >> a[i];
    sort(a,a + n);
    int ans = 0;
    rep(i, k) ans += a[i];
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3676
#include <stdio.h>

int main(){
  int n;
  long int sum=0;
  
  scanf("%d",&n);
  
  for(int i=1; i<=n; i++){
    if(i%3!=0 && i%5!=0) sum+=i;
  }
  
  printf("%ld",sum);
  
  return 0;
}

Measured memory_bytes: 1704
#include<iostream>
 
using namespace std;
 
int L[100005], R[100005];
const int INF = 100000007;
 
void merge(int a[], int left, int mid, int right)
{
	int n1 = mid - left, n2 = right - mid;
	int i, j, k;
	for (i = 0; i < n1; i++)L[i] = a[left + i];
	for (i = 0; i < n2; i++)R[i] = a[mid + i];
	L[n1] = R[n2] = INF; i = j = 0;
	for (k = left; k < right; k++)
	{
		if (L[i] <= R[j])
		{
			a[k] = L[i];
			i++;
		}
		else
		{
			a[k] = R[j];
			j++;
		}
	}
	return;
}
 
void mergesort(int a[], int left, int right)
{
	if (left + 1 < right)
	{
		int mid = (left + right) / 2;
		mergesort(a, left, mid);
		mergesort(a, mid, right);
		merge(a, left, mid, right);
	}
}
 
int main()
{
	int w, h;
	cin >> w >> h;
	int* p = new int[w+1];
	int* q = new int[h+1];
	for (int i = 0; i < w; i++)cin >> p[i];
	for (int i = 0; i < h; i++)cin >> q[i];
	mergesort(p, 0, w);
	mergesort(q, 0, h);
	long sum = 0;
	int longp = w + 1;
	int longq = h + 1;
	p[w] = q[h] = 100000007;
	int s = 0, t = 0;
	while (s < w || t < h)
	{
		if (p[s] < q[t])
		{
			sum += 1L*longq*p[s];
			longp--; s++;
		}
		else
		{
			sum += 1L*longp*q[t];
			longq--; t++;
		}
	}
	cout << sum << endl;
	return 0;
}

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

#define int long long
#define pb push_back
#define ins insert
#define pii pair<int,int>
#define fs first
#define sc second
#define mpr make_pair
#define iter iterator
#define all(X) X.begin(),X.end()
#define sau(X) sort(all(X)),X.resize(unique(all(X))-X.begin())
#define exist(X,ele) binary_search(all(X),ele)
#define y0 I_love_Ryougi_Shiki_0
#define y1 I_love_Ryougi_Shiki_1

template<typename T1,typename T2>
ostream& operator << (ostream& out,const pair<T1,T2>& X)
{
	out<<"{"<<X.fs<<","<<X.sc<<"}";
	return out;
}

template<typename T>
ostream& operator << (ostream& out,const vector<T>& X)
{
	for(auto i:X) out<<i<<" ";
	return out;
}

inline void cmin(int& x,int y)
{
	x=min(x,y);
}

inline void cmax(int& x,int y)
{
	x=max(x,y);
}

const int inf=5000000000000000ll;

int N,M,V,P;
vector<int> a;

bool chk(int id)
{
//	cout<<"Checking "<<id<<endl;
	if(a[id]+M<a[N-P]) return false;
	int nv=V-(P-1)-id-1; // cout<<"  nv="<<nv<<endl;
	if(nv<=0) return true;
	// 0..id-1 | id(+M) | ? | N-P+1..N-1
	int canv=0;
	for(int i=id+1;i<=N-P;i++)
	{
//		cout<<"  i="<<i<<" Canv+="<<min(M,a[id]+M-a[i])<<endl;
		canv+=min(M,a[id]+M-a[i]);
	}
	return (canv>=nv*M);
}

main()
{
	ios::sync_with_stdio(false);
	
	cin>>N>>M>>V>>P;
	a.resize(N);
	for(int i=0;i<N;i++)
	{
		cin>>a[i];
	}
	sort(all(a)); // cout<<a<<endl;
	int L=0,R=N-1,mid;
	while(R-L>10)
	{
		mid=(L+R)/2;
		if(chk(mid)) R=mid;
		else L=mid;
	}
	for(int i=L;i<=R;i++)
	{
		if(chk(i))
		{
			cout<<N-i<<endl;
			return 0;
		}
	}
	cout<<"0"<<endl;
	return 0;
}






















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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define erev(i, m, n) for(int (i)=(m); (i)>=n; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

const int MAX_N = 100;
const int MAX_W = 10000;
int N, W;
int v[MAX_N];
int w[MAX_N];
int dp[MAX_W+1];

// 荷物ひとつずつだけ？
int main()
{
  cin >> N >> W;
  rep(i, N) cin >> v[i] >> w[i];

  rep(i, N) erev(j, W, w[i]) maxup(dp[j], dp[j-w[i]] + v[i]);

  cout << dp[W] << endl;

  return 0;
}

Measured memory_bytes: 1200
#include<stdio.h>

int main(){
  long n,m,a,b,i;
  int g[2][200001]={};
  scanf("%ld %ld",&n,&m);
  for(i=0;i<m;i++){
    scanf("%ld %ld",&a,&b);
    if(a==1)
      g[0][b]=1;
    else if(b==1)
      g[0][a]=1;
    else if(a==n)
      g[1][b]=1;
    else if(b==n)
      g[1][a]=1;
  }
  for(i=2;i<n;i++)
    if(g[0][i]==1&&g[1][i]==1){
      printf("POSSIBLE\n");
      return 0;
    }
  printf("IMPOSSIBLE\n");
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define int long long int
#define ull unsigned long long int
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define rev(i,n,init) for(int i=n;i>=init;i--)
#define MAXN 200005
#define MOD 1000000007
#define f first
#define s second
#define endl '\n'
#define pii pair<int,int>
#define precise(i) cout<<fixed<<setprecision(i)
using namespace std;
const double PI = atan(1.0)*4;
const int64_t INF=100000000000000003;
const int32_t LOG=21;
const int BIG=pow(2,20);
const int N=100005;
 int32_t main(){
          getFaster;
          int r;
          cin>>r;
          cout<<r*r<<endl;
          return 0;
}

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

using namespace std;

int main()
{
    int N;
    cin >> N;
    long long int ans = 0;

    int k = 0;
    for (int i = 0; i < N; i++)
    {
        k++;
        if (k % 3 == 0 || k % 5 == 0)
            continue;
        ans += k;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using piii = pair<int, pair<int, int>>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

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

    int X;
    cin >> X;

    ll ans = (ll)(X / 500) * 1000;
    X %= 500;
    ans += (ll)(X / 5) * 5;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;


void solve()
{
	ll n,m,k;
	cin>>n>>m>>k;
	vector<ll>a(n);
	vector<ll>b(m);
	rep(i,n)cin>>a[i];
	rep(i,m)cin>>b[i];
	a.pb(INF);b.pb(INF);
	vector<ll>suma(n+1),sumb(m+1);
	rep(i,n)suma[i+1]=suma[i]+a[i];
	rep(i,m)sumb[i+1]=sumb[i]+b[i];
	ll ans=0;
	rep(i,n+1){
			ll kk=k-suma[i];
			if(kk<0)continue;
			ll pos=prev(upper_bound(all(sumb),kk))-sumb.begin();
			chmax(ans,pos+i);
	}
	rep(i,m+1){
		ll kk=k-sumb[i];
		if(kk<0)continue;
			ll pos=prev(upper_bound(all(suma),kk))-suma.begin();
			chmax(ans,pos+i);
	}
	cout<<ans;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 9392
n = int(input())
musics = [list(map(str, input().split())) for _ in range(n)]
x = input()

ans = 0
flag = False
for i in range(n):
  if flag:
    ans += int(musics[i][1])
  if musics[i][0] == x:
    flag = True

print(ans)

Measured memory_bytes: 9136
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  
  int n; rd(n);
  auto as=readln.split.to!(int[]);

  sort!"a>b"(as);
  int x=0, y=0;
  foreach(i, a; as){
    i%2==0 ? x : y += a;
  }

  writeln(x-y);
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}


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

int used[110];
int W, Q;

int sleep(int id, int w){
  for(int i = 0 ; i < W ; i++){
    if(used[i] == -1){
      bool ok = true;
      for(int j = i ; j < i+w ; j++){
	if(used[j] != -1 || j >= W){ ok = false; break; }
      }
      if(ok){
	for(int j = i ; j < i+w ; j++) used[j] = id;
	return i;
      }
    }
  }
  return -1;
}

void wakeup(int id){
  for(int i = 0 ; i < W ; i++){
    if(used[i] == id) used[i] = -1;
  }  
}

int main(){

  while(cin >> W >> Q, W|Q){

    fill(used, used+110, -1);
    
    char op;
    int id, w;
    while(Q--){
      cin >> op >> id;
      if(op == 's'){
	cin >> w;
	int res = sleep(id, w);
	if(res == -1) cout << "impossible" << endl;
	else cout << res << endl;
      }
      else{
	wakeup(id);
      }
    }
    cout << "END" << endl;
  }  
  return 0;
}

Measured memory_bytes: 1160