akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
//解説
int Max = 10000000;
int main()
{
	int n, m; cin >> n >> m;
	vector<int> x(m);
	int ans = 0;
	rep(i, m) cin >> x[i];
	vector<int> d(m - 1);
	
		sort(x.begin(), x.end());
		rep(i, m - 1) d[i] = x[i + 1] - x[i];
		sort(d.begin(), d.end());
		rep(i, m - n) ans += d[i];
	cout << ans;
}

Measured memory_bytes: 4028
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();
  int x = a%2;
  int y = b%2;
  if(a>b){
      if((x==0 && y==0)||(x!=0 && y!=0)){
        int ak = (a-b)/2;
        int k = a-ak;
        System.out.println(k);
      }else{
        System.out.println("IMPOSSIBLE");
      }
  }else{
      if((x==0 && y==0)||(x!=0 && y!=0)){
        int bk = (b-a)/2;
        int k = b-bk;
        System.out.println(k);
      }else{
        System.out.println("IMPOSSIBLE");
      }
    }
  }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define st first
#define nd second

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

int main(){
	int  a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	swap(a, b); swap(c,d );
	for(int i = 1;b > 0 && d > 0;i++){
		if(i%2){
			d -= a;
			if(d <= 0) printf("Yes");
		}
		else{
			b -= c;
			if(b <= 0) printf("No");
		}
	}


}

Measured memory_bytes: 3828
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int N;
    vector<int> A;
    vector<int> B;
    vector<int> C; 
    cin >> N;
    for(int i =0; i < N; i++){
        int tmp;
        cin >> tmp;
        A.push_back(tmp);
    }
    
    for(int i =0; i < N; i++){
        int tmp;
        cin >> tmp;
        B.push_back(tmp);
    }
    
    for(int i =0; i < N - 1; i++){
        int tmp;
        cin >> tmp;
        C.push_back(tmp);
    }
    int sum = 0;
    
    for(int i =0; i < N; i++){
        sum += B[A[i]-1];
        //cout << B[A[i]-1] << "," << endl;
        if(i < N-1){
            if(A[i]+1 == A[i+1]){
                //cout << ":" << i << endl;
                sum += C[A[i]-1];
            }
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>

#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define ALL(X)      (X).begin(),(X).end()
typedef long long LL;

using namespace std;
int K,T,a[100+1];

int main(void){
    scanf("%d%d",&K,&T);
    REP(i,T)
        scanf("%d",a+i);
    sort(a,a+T);
    REP(i,T-1)
        a[T-1]-=a[i];
    a[T-1]--;
    if(0<a[T-1])
        printf("%d\n",a[T-1]);
    else
        printf("0");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
#define PI 3.14159265358979323846264338327950L

int main() {
	string s;
  	cin>>s;
  
  	int n=s.size();
  
  	int ans=999;
  	
  	for(int i=0;i<=n-3;i++){
    	int num=(s[i]-'0')*100+(s[i+1]-'0')*10+s[i+2]-'0';
      	ans =min(ans,abs(num-753));
    }
  
  cout<<ans<<endl;
  


}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <regex>

#define rep(i, n) for(int i=0;i<(int)(n);i++)

using namespace std;

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;
}

long long a, b, x;

int main() {
    cin >> a >> b >> x;

    // 0以上b以下の整数のうちxで割り切れるものの個数
    long long bx = b / x + 1;

    // 0以上a-1以下の整数のうちxで割り切れるものの個数
    long long ax = 0;
    if (a > 0) {
        ax = (a - 1) / x + 1;
    }

    cout << bx - ax << endl;
}



Measured memory_bytes: 256
using System;

namespace i18n
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int len = str.Length;
            char[] c1 = str.ToCharArray();

            Console.Write(c1[0]);
            Console.Write(len-2);
            Console.Write(c1[len-1]);
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
	int W, a, b;
	cin >> W >> a >> b;
	if (W > abs(a - b)) {
		cout << 0 << endl;
	}
	else {
	if (a >= b) {
		cout << a - b - W << endl;
	}
	else {
		cout << b - a - W << endl;
	}
}
    return 0;
}

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

string s;

int main()
{
	cin>>s;
	if(s=="MON") cout<<6;
	if(s=="TUE") cout<<5;
	if(s=="WED") cout<<4;
	if(s=="THU") cout<<3;
	if(s=="FRI") cout<<2;
	if(s=="SAT") cout<<1;
	if(s=="SUN") cout<<7;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int a[200005],b[200005];
   int n,k;
   cin>>n>>k;
   for(int i=0;i<n;i++)
   {
       a[i]=999999;
   }
   for(int i=0;i<n;i++)
   {
       cin>>b[i];
       if(a[b[i]-1]==999999) a[b[i]-1]=1;
       else a[b[i]-1]++;
   }
   sort(a,a+n);
   int sum=0,f=0;
   for(int i=n-1;i>=0;i--)
   {
       if(a[i]==999999) continue;
       f++;
       if(f>k) sum+=a[i];
   }
   cout<<sum;
}


Measured memory_bytes: 1792
N, K = map(int, input().split())
*h, = map(int, input().split())
dp = [float('inf') for _ in range(N)]
dp[0] = 0
for i in range(N-1):
  for j in range(max(0, i+1-K), i+1):
    dp[i+1] = min(dp[i+1], dp[j]+abs(h[i+1]-h[j]))
  
print(dp[N-1])

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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cout << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;

const int MOD = (int)1e9 + 7;
int n;

VI sieve()
{
	VB prime(n + 1, true);
	prime[0] = prime[1] = false;

	int m = sqrtl(n);
	for(int i = 2; i <= m; ++i)
		if(prime[i])
			for(int j = i * i; j <= n; j += i)
				if(prime[j]) prime[j] = false;

	VI ret;
	for(int i = 2; i <= n; ++i)
		if(prime[i])
			ret.emplace_back(i);
	return ret;
}

ULL solve()
{
	VI primes = sieve();
	ULL ret = 1;
	for(int i = 0; i < sz(primes); ++i)
	{
		ULL p = primes[i];

		ULL exp = 0;
		while(p <= n)
		{
			exp += (n / p);
			p *= primes[i];
		}

		ret = (ret * (exp + 1ll)) % MOD;
	}
	return ret;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
//	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	cin >> n;

	cout << solve() << endl;

	return 0;
}

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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
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 (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin>>n;
vector<int>a(n);
int cnt=0;
rep(i,n){
    cin>>a[i];
    if(a[i]%2!=0 &&(i+1)%2!=0){
        cnt++;
    }
}
cout<<cnt<<endl;

return 0;
}

Measured memory_bytes: 3612
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    li s;
    cin >> s;
    li a = sqrt((long double) s);
    li d = a;

    while (true) {
        li ad = a * d;
        if (ad < s) {
            if (a == d) {
                a += 1;
            } else {
                d += 1;
            }
            continue;
        }

        li b = 1;
        li c = ad - s;
        cerr << ad - b * c << endl;
        cout << 0 << " " << 0 << " " << a << " " << b << " " << c << " " << d << endl;
        return 0;
    }

    return 0;
}

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

int main(){
    int N, M; cin >> N >> M;
    vector<long long> stair(N+1);
    for( int i = 0; i < M; i++ ){
        int a; cin >> a;
        stair[a] = -1LL;
    }


    stair[0]++; stair[1]++;
    for( int i = 2; i <= N; i++ ){
        if( stair[i] == -1 )continue;
        if( stair[i-1] != -1){
            stair[i] += stair[i-1];
        }
        if( stair[i-2] != -1){
            stair[i] += stair[i-2];
        }
        stair[i] %= 1000000007;
    }

    cout << stair[N] << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=2e5+5;
int a[maxn][5];
int dp[maxn][5];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>a[i][1]>>a[i][2]>>a[i][3];
	dp[1][1]=a[1][1];
	dp[1][2]=a[1][2];
	dp[1][3]=a[1][3];
	for(int i=2;i<=n;++i)
		{
			dp[i][1]+=max(dp[i-1][2],dp[i-1][3])+a[i][1];
			dp[i][2]+=max(dp[i-1][1],dp[i-1][3])+a[i][2];
			dp[i][3]+=max(dp[i-1][1],dp[i-1][2])+a[i][3];
		}
		cout<<max(dp[n][3],max(dp[n][2],dp[n][1]))<<endl;
	return 0;
} 

Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
void printvector(vector<long long int> &v){
	for(int i=0;i<v.size();i++){
		cout<<v[i]<<" ";
	}
	cout<<endl;
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    //write your code here
		int n, w;
		cin>> n>> w;
		vector<vector<long long int> > v(n, vector<long long int > (2,0));
		for(int i=0;i<n;i++){
			cin>>v[i][0]>> v[i][1];
		}
		vector<vector<long long int > > dp(n+1, vector<long long int > (w+1,0));
		for(int i=1;i<=n;i++){
			for(int j=1;j<=w;j++){
				dp[i][j]= max(dp[i-1][j], dp[i][j]);
				if(j- v[i-1][0]>=0)
					dp[i][j] = max(dp[i][j], dp[i-1][j-v[i-1][0]]+ v[i-1][1]);
			}
		}
		// for(int i=0;i<=n;i++){
		// 	printvector(dp[i]);
		// }
		cout<<dp[n][w]<<endl;
    return 0;
}


Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
string copy(const string s){return s;}

int main(){
	string s;cin>>s;
	bool q = true;
	for(int i = 1; i < s.size(); i++) {
		if (s[i] == s[i - 1]){continue;}
		else{q = false;}
	}
	if (q){
		cout << 0 << endl;
		return 0;
	}
	int res = INF;
	for(int i = 0; i < 26; i++) {
		char c = 'a' + i;
		int ans = 0;
		string s1 = copy(s);
		while(1){
			bool flag = false;
			string tmp = "";
			for(int i = 1; i < s1.size(); i++) {
				if ((s1[i] == c) || (s1[i - 1] == c)){
					tmp += c;
				}
				else{
					flag = true;
					tmp += '*';
				}
			}
			ans++;

			if (flag){
				s1 = tmp;
			}
			else{
				break;
			}
		}
		res = min(res,ans);
	}
	
	cout << res << endl;
	return 0;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

void solve() {
  int n, k; scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) {
    int a; scanf("%d", &a);
  }
  printf("%d", (n-1+k-2)/(k-1));
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3844
#include <iostream>

int main(){
    int H, W = 0;
    while(std::cin >> H >> W){
        if(H==0&&W==0) break;
        for(int h=0; h<H; h++){
            for(int w=0; w<W; w++){
                if(h==0 || h==H-1 || w==0 || w==W-1){
                    std::cout << "#";
                }else{
                    std::cout << ".";
                }
            }
            std::cout << "\n";
        }
        std::cout << std::endl;
    }
    return 0;
}



Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
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(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M; cin >> N >> M;
  ll mod = 1e9 + 7;
  vector<bool> a(N+1, true);
  REP(i, M){
    int tmp; cin >> tmp;
    a[tmp] = false;
  }
  
  vector<ll> dp(N+1, 0);
  dp[0] = 1;
  if(a[1]) dp[1] = 1;
  for(int i = 2; i <= N; i++){
    if(a[i]){
      dp[i] += dp[i-1];
      dp[i] += dp[i-2];
      dp[i] = dp[i] % mod;
    }else{
      dp[i] = 0;
    }
  }
  
  cout << dp[N] << endl;
}

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

constexpr int64_t DIV1097 = 1000000007LL;

using namespace std;

int main()
{
    int64_t N;
    std::cin >> N;

    int64_t count = 0;
    for (decltype(N) i = 0; i < N; ++i) {
        int t;
        std::cin >> t;

        for (;;) {
            auto q = t / 2;
            auto r = t % 2;
            if (r != 0) {
                break;
            }
            t = q;
            count++;
        }
    }

    std::cout << count << std::endl;

    return 0;
}


Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

int main() {
    int N;
    double T, A;
    cin >> N >> T >> A;
    vector<int> H(N);
    rep(i, N) cin >> H.at(i);

    double minDiff = 1000000;
    int ans = 0;
    rep(i, N) {
        double temp = T - H.at(i) * 0.006;
        double diff = abs(temp - A);
        if (minDiff > diff) {
            minDiff = diff;
            ans = i + 1;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3764
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <map>
using namespace std;
 
 
int main() {
    int n;
    cin>>n;
    vector<vector<int> > a(2, vector<int>(n));
    for(int i=0; i<2; ++i) {
        for(int j=0; j<n; ++j) {
            cin>>a[i][j];
        }
    }

    int ans=-1;
    for(int i=0; i<n; ++i) {
        int sum=0;
        for(int j=0; j<n; ++j) {
            if(i==j) sum+=a[0][j]+a[1][j];
            else if(j<i) sum+=a[0][j];
            else sum+=a[1][j];
        }
        ans=max(ans,sum);
    }
    cout<<ans<<endl;
    
    return 0;
}

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

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr int inf = 1<<30;
constexpr int mo2 = 998244353;
constexpr ll infl = 1ll<<60;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c >= 22) cout << "bust" << endl;
    else cout << "win" << endl;
    return 0;
}



Measured memory_bytes: 256
x,m = map(int, input().split())
s=[-1]*m
c=[-1]*m
for i in range(m):
    s[i], c[i] = map(int, input().split())
if x ==1:
    start = 0
else:
    start = 10**(x-1)

for j in range(start, 1000):
    num = str(j)
    for k1, k2 in zip(s, c):
        if num[k1-1] != str(k2):
            break
    else:  #すべて一致したとき
        print(j)
        break
else:
    print(-1)

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

typedef long long ll;

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

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

    ll A, B, C, D;
    cin>>A>>B>>C>>D;

    ll m1 = B/C - A/C;
    ll m2 = B/D - A/D;

    ll lcm = (C*D);
    lcm /= gcd(max(C,D), min(C,D));

    ll m3 = B/lcm - A/lcm;

    if (A%lcm == 0) m3++;

    if (A%C == 0) m1++;
    if (A%D == 0) m2++;

    cout<<B-A+1-m1-m2+m3<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define int ll 
#define FOR(i,s,e) for(ll i = s; i <= (ll)e; ++i)
#define DEC(i,s,e) for(ll i = s; i >= (ll)e; --i)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n"
#define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n"
#define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{"  << ite.f << ',' << ite.s << "} "; cerr << "\n"
#define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "LINE: " << __LINE__ << "\n";
typedef pair <ll, ll> pi;
typedef tuple<ll,ll,ll> ti3;
string cts(char x) {string t(1,x); return t;}
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 500;
const long long oo = (ll)1e18 + 500;
template <typename T> void chmax(T& a, T b) { a = max(a, b); }
template <typename T> void chmin(T& a, T b) { a = min(a, b); }
const int MAXN = -1;
#ifndef LOCAL
#define cerr if(0)cout
#endif

int32_t main() 
{
	IAMSPEED
	int d,t,s; cin >> d >> t >> s;
	if(d/s < t || (d%s == 0 && d/s == t)) {
		cout << "Yes";
	} else {
		cout << "No";
	}
}



Measured memory_bytes: 3656
<?php

class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;

    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        ++$this->pointer;

        return $result;
    }

    public function hasNext()
    {
        return $this->pointer < $this->count;
    }

    public function nextInt()
    {
        return (int) $this->next();
    }

    public function nextDouble()
    {
        return (float) $this->next();
    }
}

$sc = new Scanner();
$n = $sc->next();
$sum = 0;
$result = "";

$array = str_split($n);
$length = count($array);
for($i=0;$i<$length;$i++){
    $sum += $array[$i];    
}

if($sum%9==0){
  $result = "Yes";
} else {
  $result = "No";
}

echo $result.PHP_EOL;

Measured memory_bytes: 28564
#include <stdio.h>
int getgcd(int n, int m)
{
int r;
if (n > m) {
int t = m;
m = n;
n = t;
}
while ((r = m % n) != 0) {
m = n;
n = r;
}
return n;
}

int main(void)
{
int k;
  scanf("%d", &k);

int gcd;
  long long ans = 0;

for(int a = 1;a < k+1;a++){
	for(int b = 1;b< k+1;b++){
	for(int c = 1;c < k+1;c++){
	gcd = getgcd(getgcd(a, b), c);
     ans += gcd;
	}
	}
}

printf("%lld\n",ans);
return 0;
}

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

using namespace std;


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

    long n, k;
    cin >> n >> k;
    long res_0 = 0;
    long res_half = 0;
    for (long i = 1; i <= n; ++i) {
        res_0 += (i % k == 0);
        res_half += (i % k == (k * 1.0 / 2) );
    }
    long long result = pow(res_0, 3) + pow(res_half, 3);
    cout <<  result << '\n';

    return 0;
}


Measured memory_bytes: 256
def main():
    a, b, k = map(int,input().split())
    cnt = 0
    for i in range(max(a,b), 0, -1):
        if a % i == 0 and b % i == 0:
            #print(i)
            cnt += 1
            if cnt == k:
                print(i)
                return

if __name__ == "__main__":
    main()

Measured memory_bytes: 9116
N, M, K = map(int, input().split())

mod = 10 ** 9 + 7


class comb(object):
    def __init__(self, N, mod):
        self.mod = mod
        self.fac = [1] * N
        for i in range(1, N):
            self.fac[i] = (self.fac[i - 1] * i) % mod
        self.inv = [1] * N
        self.inv[N - 1] = pow(self.fac[N - 1], mod - 2, mod)
        for i in range(N - 1, 0, -1):
            self.inv[i - 1] = (self.inv[i] * i) % mod

    def calc(self, n, k):
        return self.fac[n] * (self.inv[k] * self.inv[n - k] %
                              self.mod) % self.mod


ans = 0
for d in range(1, N):
    ans += d * (N - d) * M**2
for d in range(1, M):
    ans += d * (M - d) * N**2
ans *= comb(N * M, mod).calc(N * M - 2, K - 2)
print(ans % mod)


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

int N;
int A[200010];

int main(void) {
    cin >> N;

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

    sort(A, A + N);

    bool result = true;
    for (int i = 1; i < N; ++i) {
        if (A[i] == A[i - 1]) {
            result = false;
            break;
        }
    }

    if (result) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
n=int(input())
inf=10**15;d=[inf]*n;d[0]=0
node=[[]for _ in range(n)]
for i in range(n):
	x=list(map(int,input().split()))
	for j in range(x[1]):
		node[i].append((x[j*2+2],x[j*2+3]))
from heapq import heappush,heappop
pq=[]
visited=[False]*n
heappush(pq,(0,0))#dis,num
while pq:
	u=heappop(pq)#1回あたりO(log|V|)がO(|V|)回ある
	u_dis=u[0];u_num=u[1]
	visited[u_num]=True
	for x in node[u_num]:
		x_dis=x[1];x_num=x[0]
		if visited[x_num]==False:
			if d[u_num]+x_dis<d[x_num]:
				d[x_num]=d[u_num]+x_dis
				heappush(pq,(d[x_num],x_num))
				#1回あたりO(log|V|)がO(|E|)回ある
for i in range(n):
	print(i,d[i])


Measured memory_bytes: 68840
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;

int main(){
    int N;cin>>N;
    vector<ll> A(N),S(N);
    cin>>A[0];S[0]=A[0];
    for(int i=1;i<N;i++){
        cin>>A[i];
        S[i]=+S[i-1]+A[i];
    }
    ll ans=pow(10,18);
    for(int i=1;i<N-2;i++){
        ll S0=S[i],S1=S[N-1]-S[i];

        ll X[5];
        auto itr0=lower_bound(S.begin(),S.end(),(S0+1)/2);
        ll X00=*itr0,X01=S0-*itr0;
        X[0]=X00,X[1]=X01;
        if(itr0!=S.begin()){
            itr0--;
            ll X10=*itr0,X11=S0-*itr0;
            if(abs(X10-X11)<abs(X[0]-X[1])){
                X[0]=X10,X[1]=X11;
            }
        }
        auto itr1=lower_bound(S.begin(),S.end(),S0+(S1+1)/2);
        ll Y00=*itr1-S0,Y01=S1-Y00;
        X[2]=Y00,X[3]=Y01;
        itr1--;
        ll Y10=*itr1-S0,Y11=S1-Y10;
        if(abs(Y10-Y11)<abs(Y00-Y01)){
            X[2]=Y10,X[3]=Y11;
        }
        ll M=max(X[0],max(X[1],max(X[2],X[3])));
        ll m=min(X[0],min(X[1],min(X[2],X[3])));
        ans=min(ans,M-m);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3328
# -*- coding: utf-8 -*-
"""
Created on Sat Sep  7 21:01:43 2019

@author: doppe
"""

N = int(input())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

score = 0
before = -99
for i in range(0, len(A)):
    score += B[A[i] - 1]
    if (before == A[i] - 1):
        score += C[A[i] - 2]
    before = A[i]
print(score)

Measured memory_bytes: 3064
s, = gets.split.map(&:to_i)
nums = gets.split.map(&:to_i)

count = 0
(s - 2).times do |i|
  arr = nums[i..i+2].uniq.sort
  next if arr.size < 2
  count += 1 if nums[i + 1] == arr[1]
end

puts count


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main() {
int i,j,l,t,a[200000],k,p=0,x,n=0;
string s;
 cin>>s;
 for(i=0;i<s.size();i++){
    p+=s[i]-'0';
    n=n*10+s[i]-'0';
 }
  if(n%p==0){cout<<"Yes\n";}
  else{cout<<"No\n";}





}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=0;i<b;i++)
#define REP(i,a,b) for(int i=0;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout <<(f?"Yes":"No")<<endl//fが真の場合Yesを出力、偽の場合Noを出力
#define yes(f) cout <<(f?"yes":"no")<<endl
#define YES(f) cout <<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())

using namespace std;

const int mod=1e9+7;

signed main(){
    int a,b,c;
    cin >> a >> b >> c;
    int five,seven;
    five = seven = 0;
    if(a==5)five++;
    if(a==7)seven++;
    if(b==5)five++;
    if(b==7)seven++;
    if(c==5)five++;
    if(c==7)seven++;

    YES(five==2&&seven==1);
}



Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<string>
#include<set>
#include<cmath>
#include<tuple>
#include<utility>
#include<functional>
#include<algorithm>

#define LL long long

using namespace std;

int n,m;

int main() {
	cin>>n>>m;
	int ans=0;
	ans+=n*(n-1)/2;
	ans+=m*(m-1)/2;
	cout<<ans<<endl;
	return 0;
}



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

#define FOR1(n) for(int i=0;i<n;i++)
#define FOR2(j, n) for(int j=0;j<n;j++)
#define FOR3(i, m, n) for(int i=m;i<=n;i++)
#define ALL(c) c.begin(), c.end()
#define SCANF(x) scanf("%lld", &x)
#define MOD 1000000007
#define MAX 1000000001
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
struct edge{int from, to; ll cost;};

/*
逆順ソート sort(ALL(vec), greater<ll>());
ペア定義 P pair = make_pair(100, 200);
集合find set.find(item);
小さい順に取り出したい優先度付きキュー
priority_queue<int, vector<int>, greater<int> > que;
配列の最大要素 *std::max_element(ALL(vec))
*/

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll n;
	cin >> n;
	ll i = 0;
	ll tbefore = 0, abefore = 0;
	while(i < n){
		ll t, a;
		cin >> t >> a;
		ll rate = (ll)ceil(max((long double)tbefore/t, (long double)abefore/a));
		tbefore = t;
		abefore = a;
		if(rate > 1){
			tbefore *= rate;
			abefore *= rate;
		}
		//cout << tbefore << " " << abefore << endl;
		i++;
	}
	
	cout << tbefore+abefore;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
dn = [[int(n) for n in input().split()] for _ in range(M)]

for i in range(0, 10**N):
	if len(str(i)) == N:
		b = True
		for j in range(M):
			if str(i)[dn[j][0]-1] != str(dn[j][1]):
 				b = False
		if b:
			print(i)
			break
else:
	print(-1)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

typedef struct Node {
	int val;
	Node *parent = NULL;
	Node *left = NULL;
	Node *right = NULL;
} Node;


Node *Tree = NULL; //树 

void insert(int key) {
	Node *cur = Tree;
	Node *parent = NULL;
	while (cur != NULL) {
		parent = cur;
		if (key < cur->val) {
			cur = cur->left;
		} else {
			cur = cur->right;
		}
	}
	if (parent == NULL) {
		Tree = new Node;
		Tree->val = key;
		return;
	}
	Node *t = new Node;
	t->val = key;
	t->parent = parent;
	if (key < parent->val) {
	   parent->left = t;
    } else {
    	parent->right = t;
	}
}

void find(int key) {
	Node *cur = Tree;
	bool found = false;
	while (cur != NULL && !found) {
		if (key < cur->val) {
			cur = cur->left;
		} else if (key > cur->val) {
			cur = cur->right;
		} else {
			found = true;
		}
	}
	if (found) {
		cout << "yes" << endl;
	} else {
		cout << "no" << endl;
	}
	
}

void printPre(Node * node) {
	cout  << " " << node->val;
	if (node->left != NULL) {
		printPre(node->left);
	}
	
	if (node->right != NULL) {
		printPre(node->right);
	}
}

void printIn(Node * node) {

	if (node->left != NULL) {
		printIn(node->left);
	}
	cout  << " " << node->val;
	if (node->right != NULL) {
		printIn(node->right);
	}
}

int main() {
	int n;
	cin >> n;
	for (int i=0;i<n;i++) {
		string s;
		cin >> s;
		if (s[0] == 'i') {
			long long key;
			cin >> key;
			insert(key);
		} else if (s[0] == 'f') {
			long long key;
			cin >> key;
			find(key);
		} else if (s[0] == 'p') {
			printIn(Tree);
			cout << endl;
			printPre(Tree);
			cout << endl;
		}
	}
	return 0;
	
}


Measured memory_bytes: 21876
//
// Created on 2019-02-03.
//
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=b; }

#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

#define PB push_back
#define INF 1e9
#define MOD 1e9+7
#define EPS 1e-9

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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


    int N, M, t;
    cin >> N >> M;

    vi v;
    REP(i,M) { cin >> t; v.emplace_back(t); }
    sort(ALL(v));


    vi diff(M-1);
    REP(i, M-1) { diff[i] = abs(v[i+1] - v[i]); }
    //for (int n : diff) cout << n << " " ;
    sort(ALL(diff));

    int ans = 0;
    REP(i, M-1-(N-1)) {
        ans += diff[i];
    }
    cout << ans << endl;


}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  int R = 0, B = 0;
  rep(i,s.size()){
    if(s[i] == 'R') R++;
    else B++;
  }

  if(R > B) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>
#include <deque>

using namespace std;

int main(){
    int n;
    string s;
    cin >> n >> s;
    bool ans=n%2==0;
    for(int i=0; i<n/2; ++i){
        ans=ans && s[i]==s[i+n/2];
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  ll n, m; cin >> n >> m;
  if(n > m)swap(n, m);
  if(n == 1 && m == 1){
    cout << 1 << endl;
  }
  else if(n == 1){
    cout << m-2 << endl;
  }
  else{
    cout << (n-2)*(m-2) << endl;
  }
  system("pause");
}


Measured memory_bytes: 504
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
using namespace std;
int main()
{
  int i,n;
  cin>>n;
  double one = 1.0;
  double sum = 0.0;
  double x;
  for(i=0;i<n;i++)
  {
    cin>>x;
    x = one/x;
    sum += x;
  }
  sum = one/sum;
  cout<<setprecision(12)<<sum<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

int main(){
    LL n;
    LL a;
    LL tmp;
    LL ans=0;
    cin >> n >> a;
    tmp=a;
    vector<LL> x(n);
    for(LL i=0; i<n; i++){
        cin >> x[i];
        tmp=max(tmp,x[i]);
    }

    tmp=tmp*n;

    vector<vector<vector<LL>>> dp(n+1, vector<vector<LL>>(n+1, vector<LL>(tmp+1)));

    for(LL i=0; i<=n; i++){
        for(LL j=0; j<=n; j++){
            for(LL k=0; k<=tmp; k++){
                //cout << i << " " << j << " " << k << endl;
                if(i==0 && j==0 && k==0){
                    dp[i][j][k]=1;
                }else if(i>=1 && k<x[i-1]){
                    dp[i][j][k]=dp[i-1][j][k];
                }else if(i>=1 && j>=1 && k>=x[i-1]){
                    dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-x[i-1]];
                }else{
                    dp[i][j][k]=0;
                }
            }
        }
    }

    for(LL i=1; i<=n; i++){
        ans+=dp[n][i][i*a];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 55192
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

ll N, K;
ll a[1010];
ll sum(ll l, ll r){
    return a[r] - a[l - 1];
}
V v;
ll check(ll x){
    ll cnt = 0;
    rep(i, v.size())if((v[i] & x) == x)cnt++;
    return cnt >= K;
}
int main(){

    cin >> N >> K;
    rep1(i, N){
        cin >> a[i];
        a[i] += a[i - 1];
    }
    rep1(l, N)for(ll r = l; r <= N; r++)v.push_back(sum(l, r));
    ll ans = 0;
    for(ll j = 42; j >= 0; j--){
        ll tmp = ans | (1LL << j);
        if(check(tmp))ans = tmp;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 6384
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int a; cin>>a;
    int zenhan=a/100;
    int kouhan=a%100;
    //mmyy form
    if(1<=zenhan && zenhan<=12){
        if(1<=kouhan && kouhan<=12){
            cout<<"AMBIGUOUS"<<endl;
        }
        else cout<<"MMYY"<<endl;
    }
    else{
        if(1<=kouhan && kouhan<=12){
            cout<<"YYMM"<<endl;
        }
        else cout<<"NA"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define NIL NULL

typedef struct node{
  int key;
  struct node *right,*left,*p;
} Node;

Node *root;

void insert(int);
void prep(Node *);
void inp(Node *);

int main(){
  char c[20];
  int n,i,j,x;
  

  scanf("%d",&n);

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

    if(c[0] == 'i'){
      scanf("%d",&x);
      insert(x);
    }
   
    else if(c[0] == 'p'){
      inp(root);
      printf("\n");
      prep(root);
      printf("\n");
    }
  }

  return 0;
}

void insert(int k){
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;

    if(z->key < x->key) x = x->left;

    else x = x->right;
  }

    z->p = y;

    if(y == NIL)root = z;

    else{
      
    if(z->key < y->key) y->left = z;

    else y->right = z;
  }

}

void prep(Node *p){
  if(p == NIL) return;
  printf(" %d",p->key);
  prep(p->left);
  prep(p->right);
}

void inp(Node *p){
  if(p == NIL) return;
  inp(p->left);
  printf(" %d",p->key);
  inp(p->right);
}

  



Measured memory_bytes: 25136
#include <stdio.h>

int main(void)
{
        int a,b,c,d,max,min;
        scanf("%d%d%d%d",&a,&b,&c,&d);

        if(a>c)max=a;
        else max=c;
        if(b<d)min=b;
        else min=d;
        if(min>=max)printf("%d\n",min-max);
        else printf("0\n");
        return 0;
}


Measured memory_bytes: 1728
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include<iomanip>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define ffrvs(ii,nn,mm) for(int ii=nn;ii>=mm;ii--)
#define srt(vvv) sort(vvv.begin(),vvv.end())
#define srtrvs(vvv) reverse(vvv.begin(),vvv.end())
#define Graph vector<vector<int>>

i64 inf = 1000000007;
i64 giant = 4000000000000000037;

using namespace std;

i64 cup(i64 xxx, i64 yyy) {//切り上げ
	return (xxx + yyy - 1) / yyy;
}

//メモリ置き場
int n, k;

//inputします
void input() {
	cin >> n >> k;
}

//ライブラリ置き場


//main
int main() {
	input();
	int ans = 0;
	while (1) {
		if (n == 0)break;
		n /= k;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int f(int b){
  int ans = 0;
  while(b > 0){
    ans += b % 10;
    b /= 10;
  }
  return ans;
}

int main(){
  int n;
  scanf("%d",&n);
  if(n % f(n) > 0){
    printf("No");
  }else{
    printf("Yes");
  }
  return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

struct line
{
	ll a, b;
	  line(ll m, ll c)
	{
		a = m;
		b = c;
	}
	ll operator[] (int x)
	{
		return a * x + b;
	}
	double operator*(line const &o)
	{
		return double (b - o.b) / (o.a - a);
	}
};

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

	int n;
	ll c;
	cin >> n >> c;
	deque < pair < line, ll > >dp;
	for (int i = 0; i < n; ++i)
	{
		ll x;
		cin >> x;
		while (dp.size() > 1 && dp[0].first[x] >= dp[1].first[x])
			dp.pop_front();
		auto v = i ? dp.front().first[x] + (x * x + c) : 0;
		auto l = line(-2 * x, v + x * x);
		while (dp.size() > 1
			   && (dp.back().first * dp[dp.size() - 2u].first) >= (l * dp[dp.size() - 2u].first))
			dp.pop_back();
		dp.emplace_back(l, v);
	}
	cout << dp.back().second;
}

Measured memory_bytes: 3584
#include<iostream>
    using namespace std;
    int main()
    {
        string s;
        int count = 0;
        cin >> s;
        if(s[0] == '1') ++count;
        if(s[1] == '1') count = count +1;
        if(s[2] == '1') count += 1;
        cout << count <<endl;
    }

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

class BIT:
  def __init__(self, n):
    self.bit = [0] * n

  def add(self, i, x):
    i += 1
    while i <= len(self.bit):
      self.bit[i-1] += x
      i += i & -i

  def sum_sub(self, i):
    a = 0
    i += 1
    while i:
      a += self.bit[i-1]
      i -= i & -i
    return a

  def sum(self, i, j):
    a = 0
    if j != 0:
      a += self.sum_sub(j-1)
    if i != 0:
      a -= self.sum_sub(i-1)
    return a

n,q=map(int,input().split())
a=list(map(int,input().split()))
Bit=BIT(n)
for i in range(n):
  Bit.add(i,a[i])
for i in range(q):
  t,a,b=map(int,input().split())
  if t==0:
    Bit.add(a,b)
  else:
    print(Bit.sum(a,b))

Measured memory_bytes: 65076
#include <iostream> 
#include <cstdlib> 
#include <cstdio> 
#include <cstring> 
#define NILL 2000000010 
using namespace std;
 struct node{ node *p, *l,*r; int key; };
 node *root; node * mk_node(int key,node *l,node *r,node *p){ node *n=(node *)malloc(sizeof(node)); n->key=key; n->r=r; n->l=l; n->p=p; return n; } void insert(node *z){ node *y=mk_node(NILL,NULL,NULL,NULL); node *x=root; while(x!=NULL){ y=x; if((z->key)<(x->key)) x=x->l; else x=x->r; } z->p = y; if(y->key==NILL)root = z; else if(z->key < y->key) y->l=z; else y->r=z; } void print(node *pos, int flg){ if(flg)cout <<" "<<pos->key; if(pos->l!=NULL)print(pos->l,flg); if(!flg)cout <<" "<<pos->key; if(pos->r!=NULL)print(pos->r,flg); } node * find(node *pos,int key){ if(pos==NULL)return pos; if(pos->key>key) return find(pos->l,key); if(pos->key<key) return find(pos->r,key); return pos; } node *treeMinimum(node *x){ while(x->l!=NULL) x=x->l; return x; } node * treeSuccessor(node *x){ if(x->r!=NULL) return treeMinimum(x->r); node *y=x->p; while(y!=NULL&&x==y->r)x=y,y=y->p; return y; } void del(node *z){ node *y; if(z->l==NULL||z->r==NULL) y = z; else y=treeSuccessor(z); node *x; if(y->l!=NULL) x=y->l; else x=y->r; if(x!=NULL) x->p=y->p; if(y->p==NULL) root=x; else if (y==y->p->l) y->p->l=x; else y->p->r=x; if( y!=z) z->key=y->key; } char str[1000]; int main(){ root=mk_node(NILL,NULL,NULL,NULL); int n; cin>>n; while(n--){ node *x=mk_node(NILL,NULL,NULL,NULL); int a; scanf("%s",str); if(str[0]=='i'){ scanf("%d",&x->key); insert(x); } else if(str[0]=='p'){ print(root,0);cout <<endl; print(root,1);cout <<endl; } else if(str[0]=='f'){ cin>>a; cout <<(find(root,a)!=NULL? "yes":"no")<<endl; } else if(str[0]=='d'){ cin>>a; del(find(root,a)); } } return 0; } 


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

int ds = 6;

void dprint( int a[] ){
	for( int i = 0; i < ds; i++ ) {
		cout << a[i] << ":";
	}
	cout << endl;

	return; 
}

void dsort( int a[], int i0, int i1, int i2, int i3 ) {
	int ta[] = { a[i0], a[i1], a[i2], a[i3] };
	int min = ta[0];
	for( int i = 0; i < 4; i++ ) {
		if( min < ta[i] ) {
			min = ta[i];
		}
	}

	int t = 0;
	while( true ) {
		if( a[i0] == min ) {
			break;
		}
		t = a[i0];a[i0]=a[i1];a[i1]=a[i2];a[i2]=a[i3];a[i3]=t;
	}

	return;
}

bool dcomp( int a[], int b[] )
{
	for( int i = 0; i < ds; i++ ) {
		if( a[i] != b[i] ) {
			return false;
		}
	}

	return true;
}

bool drollcomp( int a[], int b[], int i0, int i1, int i2, int i3 )
{
	bool ret = false;
	int t = 0;
	for( int i = 0; i < 4; i++ ) {
		t = b[i0];b[i0]=b[i1];b[i1]=b[i2];b[i2]=b[i3];b[i3]=t;
		ret = dcomp( a, b );
		if( ret == true ) {
			break;
		}
	}
	return ret;
}

bool dcheck( int a[], int b[] ) {
	bool ret = false;

	ret = dcomp( a, b );
	if( ret == true ) {
		return ret;
	}
	return ret;

	ret = drollcomp( a, b, 1, 2, 4, 3 );
	if( ret == true ) {
		return ret;
	}

	ret = drollcomp( a, b, 0, 1, 5, 4 );
	if( ret == true ) {
		return ret;
	}

	ret = drollcomp( a, b, 0, 3, 5, 2 );
	if( ret == true ) {
		return ret;
	}

	return ret;
}

int main()
{
	int dx[ds], dy[ds];

	for( int i = 0; i < ds; i++ ) {
		cin >> dx[i];
	}
	dsort( dx, 0, 1, 5, 4 );
	dsort( dx, 0, 3, 5, 2 );
	dsort( dx, 1, 2, 4, 3 );

	for( int i = 0; i < ds; i++ ) {
		cin >> dy[i];
	}
	dsort( dy, 0, 1, 5, 4 );
	dsort( dy, 0, 3, 5, 2 );
	dsort( dy, 1, 2, 4, 3 );

//	dprint( dx );
//	dprint( dy );

	bool ret = false;
	ret = dcheck( dx, dy );
	cout << ( ret?"Yes":"No" ) << endl;

	return 0;
}


Measured memory_bytes: 3128
// #include<bits/stdc++.h>
// using namespace std;
// #define F first
// #define S second
// #define PB push_back
// #define MP make_pair
// #define REP(i,a,b) for (int i = a; i <= b; i++)

// typedef long long ll;
// typedef vector<int> vi;
// typedef pair<int,int> pii;

// int main() {
//   ios::sync_with_stdio(0);
//   cin.tie(0);
//   freopen("input.txt", "r", stdin);
//   freopen("output.txt", "w", stdout);
//   //(a + b) mod m = (a mod m + b mod m) mod m;
//   //(a - b) mod m = (a mod m - b mod m) mod m;
//   //(a * b) mod m = (a mod m * b mod m) mod m;
//   // x = x % m;
//   // if (x < 0) x += m;
// }

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	//freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);

  int h, w,k;
  cin >> h >> w>>k;
  //vector< vector<char> > nums(h,'a');
  vector<vector<char> > nums( h , vector<char> (w, 'a'));

  int ans = 0;
  FOR(i,0,h) {
    FOR(j, 0, w)
    {
      cin >> nums[i][j];
    }
  }
  //cout << nums[0][0];
  int black = 0;
  FOR(maskr, 0, 1 << h)
  {
    FOR(maskc, 0, 1<<w) {
      black = 0;
      FOR(i,0,h){
        FOR(j,0,w){
            if ((((maskr >> i) & 1) == 0 )&& (((maskc >> j) & 1) == 0) && (nums[i][j] == '#'))
              black = black + 1;
        }
      }
      if (black==k)
        ans++;
    }
  }
  cout << ans;
  return 0;
}

// read the question correctly (ll vs int)
// template by bqi343




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

using namespace std;

int N,K;
vector<int> P;

void input(){
  cin >> N >> K;
  P.resize(N);
  int p;
  for(int i=0;i<N;i++){
    cin >> p;
    P.push_back(p);
  }
}

int main(){
  input();  
  sort(P.begin(),P.end(),greater<int>());
  int ans=0;
  for (int i=0;i<=K;i++){
    ans+=P[N-i];
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  char a,b;
  int x,y;
  cin >> a >> b;
  if(a=='A')
    x=0;
  if(a=='B')
    x=1;
  if(a=='C')
    x=2;
  if(a=='D')
    x=3;
  if(a=='E')
    x=4;
  if(a=='F')
    x=5;
  if(b=='A')
    y=0;
  if(b=='B')
    y=1;
  if(b=='C')
    y=2;
  if(b=='D')
    y=3;
  if(b=='E')
    y=4;
  if(b=='F')
    y=5;
  if(x==y)
    cout << "=";
  if(x<y)
    cout << "<";
  if(x>y)
    cout << ">";
}

Measured memory_bytes: 256
import math
#####sorting a dictionary#####
def dict_sort(ans):
    ans=sorted(ans.items(),reverse=True,key=lambda kv:(kv[1]))
def is_prime(n,k):
    if n==1:
        return 0
    for i in range(2,int(math.sqrt(n))+1):
        if n%i==0:
            res=i
            break
    return res
def inp():
    ls=list(map(int,input().split()))
    return ls
a,b,h,m=map(int,input().split())
hangl=0.5*(60*h+m)
mangl=6*m
angl=abs(mangl-hangl)
if angl>180:
    angl=360-angl
c=math.sqrt(a*a+b*b-2*a*b*math.cos((angl*math.pi)/180))
print(c)


Measured memory_bytes: 9440