akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define eps 1e-3
#define pi acos(-1.0)
#define inf 0x3f
#define INF 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define debug1 cout<<"&&";
#define debug2 cout<<"**";
#define ms(a, x) memset(a, x, sizeof(a))
#define for0(i, n) for(int i = 0; i < n; ++i)
#define for1(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;
typedef pair<long long, long long> pll;
const int mod = 1e9 + 7;
const int N = 4e2 + 10;
const int M = 1e5 + 10;
/*=================================================================================*/

ll dp[N][N];
int n, a[N];

ll w(int i, int j) {
   ll ans = 0;
   for(int k = i; k <= j; ++k) ans+=a[k];
   return ans;
}

int main() {
   scanf("%d", &n);
   for1(i, n) scanf("%d", &a[i]);
   ms(dp, 0);
   for(int len = 2; len <= n; ++len) {
      for(int i=1; i+len-1 <= n; ++i) {
         int j = i+len-1;
         dp[i][j] = INF;
         for(int k = i; k < j; ++k) {
            dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + w(i, j));
            // debug1 printf("%d %d %lld %lld %lld %lld\n", i, j, dp[i][j], dp[i][k], dp[k+1][j], w(i, j));
         }
      }
   }
   cout<<dp[1][n]<<endl;
}

Measured memory_bytes: 5076
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define RFOR(i, a, b) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using vi = vector<int>;
using vd = vector<double>;
using i64 = int64_t;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

template <typename T>
void print(vector<T> &v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

struct Node {
  int key;
  shared_ptr<Node> right, left, parent;
};

shared_ptr<Node> root, NIL;

void insert(int k) {
  auto y = NIL;
  auto x = root;
  auto z = make_shared<Node>();
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL) {
    y = x;
    x = (z->key < x->key) ? x->left : x->right;
  }
  z->parent = y;
  if (y == NIL) {
    root = z;
  } else {
    if (z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void inorder(shared_ptr<Node> &u) {
  if (u == NIL) return;
  inorder(u->left);
  cout << " " << u->key;
  inorder(u->right);
}

void preorder(shared_ptr<Node> &u) {
  if (u == NIL) return;
  cout << " " << u->key;
  preorder(u->left);
  preorder(u->right);
}

int main() {
  int n, i, x;
  string com;
  cin >> n;
  REP(i, n) {
    cin >> com;
    if (com == "insert") {
      cin >> x;
      insert(x);
    } else if (com == "print") {
      inorder(root);
      cout << endl;
      preorder(root);
      cout << endl;
    }
  }
}


Measured memory_bytes: 42144
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
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 INF = 1e9;
const ll MOD = 1000000007;
const double pi = 3.141592653589;
using Graph = vector<vector<int>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
	int n;cin>>n;
	string s;
	s = to_string(n);
	if (s[s.size()-1]-'0' == 2 || s[s.size()-1]-'0' == 4 || s[s.size()-1]-'0' == 5 || s[s.size()-1]-'0' == 7 || s[s.size()-1]-'0' == 9) {
		ct("hon");
	} else if (s[s.size()-1]-'0' == 0 || s[s.size()-1]-'0' == 1 || s[s.size()-1]-'0' == 6 || s[s.size()-1]-'0' == 8) {
		ct("pon");
	} else if (s[s.size()-1]-'0' ==3) {
		ct("bon");
	}
}

Measured memory_bytes: 3708
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N,a,b;
	cin >> N >> a >> b;
	cout << min(N*a, b) << endl;
	return 0;
}



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

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

  vector<long long> a(n);
  for (auto& u : a) cin >> u;

  sort(a.begin(), a.end());

  long long sum = 0;
  int ans = 0;
  for (int i = 0; i < n - 1; ++i) {
    sum += a[i];
    if (2 * sum >= a[i + 1]) ans++;
    else ans = 0;
  }
  ans++;

  cout << ans << endl;
}


Measured memory_bytes: 1024
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e9
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main() {
	while (true) {
		int w, h;
		cin >> w >> h;
		if (w == 0) return 0;
		int gogo[51][51] = {};
		REP(i, h) {
			REP(q, w) {
				cin >> gogo[i][q];
			}
		}
		int xe[8] = { -1,-1,-1,0,0,1,1,1 };
		int ye[8] = { 1,0,-1,1,-1,1,0,-1 };
		queue<pair<int, int>> next;
		int visited[51][51] = {};
		int ans = 0;
		REP(i, h) {
			REP(q, w) {
				if (visited[i][q] == 0&&gogo[i][q] == 1) {
					visited[i][q] = 1;
					ans++;
					next.push(make_pair(i, q));
					while (next.empty() == false) {
						pair<int, int> now = next.front();
						next.pop();
						REP(q, 8) {
							int now_x = now.first + xe[q];
							int now_y = now.second + ye[q];
							if (now_x >= 0 && now_x < h && now_y >= 0 && now_y < w) {
								if (visited[now_x][now_y] == 0 && gogo[now_x][now_y] == 1) {
									visited[now_x][now_y] = 1;
									next.push(make_pair(now_x, now_y));
								}
							}
						}
					}
				}
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3136
input = input()
n = 2
an = 0
splited = [input[i:i+n] for i in range(0, len(input), n)]
for ahd in splited:
  if splited[an] == "hi":
    an+=1
  else:
    break
if int(an) == int(len(splited)):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 38384
//Be Name Khoda
/*
ID: aminra81
PROG: :)))
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MOD = (int)1e9 + 7;
const ll inf = (ll)1e18;
const int infint = (int)2e9;
const int MAXN = 1e6 + 7;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	ll a, b;
	cin >> a >> b;
	if(a <= 0 and b >= 0)
		return cout << "Zero", 0;
	if(a > 0)
		return cout << "Positive", 0;
	int neg = min(-1 - a + 1, b - a + 1);
	if(neg % 2)
		cout << "Negative";
	else
		cout << "Positive";
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
mx = max(a)
flag = [True]*(mx+1)
c = Counter(a)
a.sort()
ans = 0
for i in range(n):
    if flag[a[i]]:
        if c[a[i]] == 1: ans += 1
        for j in range(a[i],mx+1,a[i]): flag[j] = False
print(ans)

Measured memory_bytes: 125080
#include <iostream>
#include <string>

using namespace std;

int main()
{
	for (;;)
	{
		int a, b;
		string op;

		cin >> a >> op >> b;

		int ans;

		if (op == "?")
		{
			break;
		}
		else if (op == "+")
		{
			ans = a + b;
		}
		else if (op == "-")
		{
			ans = a - b;
		}
		else if (op == "*")
		{
			ans = a * b;
		}
		else if (op == "/")
		{
			ans = a / b;
		}

		cout << ans << endl;
	}
}


Measured memory_bytes: 3140
#include <iostream>

int main() {

	int N = 0;
	double a = 0;
	double tmp = 0;
	char k1,k2,k3;
	std::cin >> N;
	for (int i = 0; i < N; i++) {

		std::cin >> tmp >> k1>>k2>>k3;

		if(k1=='J'&&k2=='P'&&k3=='Y')a += tmp;
		else a += (tmp * 380000);

	}

	std::cout << a << std::endl;

	return 0;
}

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

void print_vec(vector<int> A)
{
	for(int i = 0 ; i < A.size() ; i++)
	{
		cout<<A[i]<<" ";
	}
	cout<<endl;
}


int main()
{
  int n;
  cin>>n;
  
  cout<<pow(n,3)<<endl;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int X = sc.nextInt();

		int x[] = new int[N+1];
		x[0] = X;

		for (int i = 1; i <= N; i++) {
			x[i] = sc.nextInt();
		}
		Arrays.sort(x);

		int dif[] = new int[N];
		for (int i = 0; i < N; i++) {
			dif[i] = x[i+1] - x[i];
		}

		if (N == 1) {
			System.out.println(dif[0]);
			return;
		}

		int ans = gcd(dif[0],dif[1]);
		for (int i = 2; i < dif.length; i++) {
			ans = gcd(ans, dif[i]);
		}
		System.out.println(ans);
	}

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


Measured memory_bytes: 47940
A = 7175816845464090776455207507270117755723765735430536804658747273399161802972634276448409301356909248005606116656073561929444931323143190717332175076262060295351620527202705615498306139275508555689509950694997345595674093104433020700546656778950085095645658807229584194806623377338842753774743833376783450229118372573460572454731223569400078753907185233376010906274531347459925723690095854183385568140762360863180004465626012327328449425540345922055914421850333689171725134946657507151835356233535112180627200151906292121106447641907908790376379132422532166122413876168625333717615295123397246508335105
N = int(input())
print(1 if N >= 2000 else A>>N & 1)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,A,B;
  cin >> a >> b;
  A = a % 2;
  B = b % 2;
  if (A == 0 || B ==0) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
a,b=map(int,input().split())
c=[]
for i in range(a):
  g=input()
  if "#" not in g:
    continue
  d=list(g)
  c.append(d)
l=len(c)
p=[]
for i in range(b):
  for j in range(l):
    if c[j][i]=="#":
      p.append(i)
      break
for i in range(l):
  for j in range(len(p)):
    if j == len(p)-1:
      print(c[i][p[j]])
    else:
      print(c[i][p[j]],end="")



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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	int A,B; cin >> A >> B;

	cout << max(0,A-B) << endl;

	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t h;
  cin >> h;
  
  int64_t a=0;
  while(h/2!=0){
    h = h/2;
    a++;
  }
 
  int64_t i=0;
  int64_t ans=1;
  while(i<a+1){
    ans = ans * 2;
  i++;
  }
  

  cout << ans-1 << endl;
}


Measured memory_bytes: 256
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();

    if(a * b % 2 == 0){
      System.out.println("Even");
    }else{
      System.out.println("Odd");
    }
  }
}


Measured memory_bytes: 21716
N,P = map(int,input().split())
A = list(map(int,input().split()))
odd = 0
even = 0
for i in range(N):
  if A[i] % 2 == 0:
    even += 1
  else:
    odd += 1
if odd == 0:
  print(0) if P==1 else print(2**N)
else:
  N -=1
  print(2**N)

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

int main() {
  string n;
  cin >> n;
  int sum = 0;
  rep(i, (int)n.size()) {
    sum += (int)(n[i] - '0');
  }

  if (sum%9 == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 3752
# -*- coding: utf-8 -*-

a, b, c, d = map(int, input().split())

a_b = abs(a-b)
a_c = abs(a-c)
b_c = abs(b-c)

if a_c <= d or (a_b <= d and b_c <= d):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9116
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int N, K; string S;
int main() {
  cin >> N >> K >> S;
  int t[100005];
  if(S[0] == '0') t[0] = 1;
  for(int i = 0; i < N; ++i) {
    if(S[i] == '1' && S[i+1] == '0') t[i+1] = t[i]+1;
    else t[i+1] = t[i];
  }
  int ans = 0;
  for(int i = 0; i < N; ++i) {
    int l = i, r = N;
    while(r-l > 1) {
      int m = (l+r)/2;
      int diff = t[m]-t[i];
      if(S[i] == '0') ++diff;
      if(diff > K) r = m;
      else l = m;
    }
    ans = max(ans, l-i+1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#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--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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 maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}

vector<ll> pw2(51,1);vector<ll> pw10(19,1);
int main(){
    {rep1(i,50) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll r; cin>>r;
    cout<<r*r<<endl;
    
}




Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

ll modpow(ll x, ll b){
  ll res = 1;
  while(b){
    if(b&1)res = res * x % MOD;
    x = x * x % MOD;
    b>>=1;
  }
  return res;
}

ll modinv(ll x){
  return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
  if(was_output)cout << " ";
  cout << a;
  was_output = true;
}
void outendl(){
  was_output = false;
  cout << endl;
}
ll in(){
  ll res;
  scanf("%lld", &res);
  return res;
}

template<class t>
istream& operator>>(istream&is, vector<t>&x){
  for(auto &i:x)is >> i;
  return is;
}

template<class t, class u>
istream& operator>>(istream&is, pair<t, u>&x){
  is >> x.first >> x.second;
  return is;
}

template<class t>
void in(t&x){
  cin >> x;
}

bool func(){
  string str;
  in(str);
  rep(i,3){
    rep(j,3){
      if(str[i]!=str[j])return true;
    }
  }
  return false;
}

int main(){
  cout << (func()?"Yes":"No") << endl;

  return 0;
}


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


int* mallocint(int si)
{
    return (int*) malloc(si * sizeof(int));
}

int* inputint(int n)
{
    int *ans = mallocint(n);
    for( int i = 0; i < n; i++ ) cin >> ans[i];
    return ans;
}

int main()
{
    int x, n;
    cin >> x >> n;
    int *p = inputint(n);
    int tmp[101];
    for( int i = 0; i <= 100; i++)
    {
        tmp[i] = 0;
    }

    for(int j = 0; j < n; j++)
    {
        tmp[p[j]] = 1;
    }

    for( int d = 0; d < 100; d++ )
    {
        for( int s = -1; s <= 1; s++ )
        {
            int index = x + s * d;
            if( index < 0 || index > 100 || tmp[index] == 0 )
            {
                cout << index;
                return 0;
            }
        }
    }
    return 0;    
}

Measured memory_bytes: 3644
#include <stdio.h>


int main(){
	
	long long  int a[88];
	int i,n;
	
	scanf("%d",&n);
	
	a[0]=2;
	a[1]=1;
	
	for(i=2;i<=n;i++){
		a[i]=a[i-1]+a[i-2];
	}
	
	printf("%lld\n",a[n]);
	
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <sysexits.h>
#include <math.h>
int main(void){
  int a,b,sum;
  if(scanf("%d",&a)!=1){
exit(0);
}
  if(scanf("%d",&b)!=1){
exit(0);
}

  if(a==b){
    sum= a+b;
    printf("%d",sum);
  }
  else if(a>b){
    sum = a+a-1;
    printf("%d",sum);
  }
  else{
    sum=b+b-1;
    printf("%d",sum);
  }
  return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = INF; // no mod
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

ll nck(ll n, ll k) {
    ll ret = 1;
    for (ll i = n; i > n - k; --i) {
        ret *= i;
        ret /= n - i + 1;
    }
    return ret;
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    vl v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    sort(v.begin(), v.end(), greater<ll>());
    ll sum = 0;
    ll lastVal = v[a - 1];
    ll numLastValTotal = 0;
    ll numLastValUsed = 0;
    for (int i = 0; i < n; ++i) {
        if (i < a) {
            sum += v[i];
        }
        if (v[i] == lastVal) {
            if (i < a)
                numLastValUsed++;
            numLastValTotal++;
        }
    }
    ll comb = nck(numLastValTotal, numLastValUsed);
    if (v[0] == lastVal) {
        for (int i = a + 1; i <= b; ++i) {
            numLastValUsed++;
            if (numLastValUsed > numLastValTotal)
                break;
            comb += nck(numLastValTotal, numLastValUsed);
        }
    }

    cout << fixed << setprecision(10) << sum / double(a) << "\n";
    cout << comb << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

int main(){
  std::string s;
  std::cin >> s;
  long long mod = 1000000007;

  int T[6][10];
  int r=1;
  for(int i=0; i<6; ++i){
    for(int j=0; j<10; ++j){
      T[i][j] = (j*r)%13;
    }
    r*=10;
  }

  long long _dp1[13], _dp2[13];
  long long *dp = _dp1, *dp_new = _dp2, *dp_swap;
  dp[0]=1;
  for(int i=1; i<13; ++i) dp[i]=0;

  int k = s.size()-1;
  for(int i=0; i<s.size(); ++i, --k){
    for(int j=0; j<13; ++j) dp_new[j]=0;

    if(s[i]=='?'){
      for(int r=0; r<10; ++r){
        int m = T[k%6][r];
        for(int n=0; n<13; ++n) dp_new[(n+m)%13] += dp[n];
      }
    }else{
      int m = T[k%6][(int)(s[i]-'0')];
      for(int n=0; n<13; ++n) dp_new[(n+m)%13] = dp[n];
    }

    dp_swap = dp_new; dp_new = dp; dp = dp_swap;
    for(int j=0; j<13; ++j) dp[j]%=mod;
  }

  std::cout << dp[5] << std::endl;
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h> 
using namespace std; 
long long n,f[49],x=1;
int main()
{
    cin>>n;
    f[0]=1;
    f[1]=1;
    for(int i=2;i<=n;i++)
        f[i]=(f[i-1]+f[i-2]);
    
    cout<<f[n]<<endl;
}


Measured memory_bytes: 3092
#include <iostream>

using namespace std;
bool IsHarshad(int sourceNum);

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

  if (IsHarshad(N)) cout << "Yes\n"; 
  else cout << "No\n"; 
}

bool IsHarshad(int sourceNum) 
{
  int f = 0;
  int num = sourceNum;

  while (num)
  {
    f += num % 10;
    num /= 10;
  }

  if (!(sourceNum % f)) return true;
  else return false;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define MANX MAXN


const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
    freopen("a.in","r",stdin);
    #endif
    ll a,v,b,w,t;
    cin>>a>>v>>b>>w>>t;
    ll dist=abs(a-b);
    ll f=v-w;
    if (f<=0)
    {
        cout<<"NO\n";
    }
    else
    {
        if ((dist+f-1)/f<=t)
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }


    //n=1 ?
    //recursion - matrix exponential
    //linear algebra - just a joke
    //check ios_base, MAXN, mod1 before submit
    //if debug more than 15 minutes - write stress
    //compression
}

Measured memory_bytes: 3652
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

int main()
{
    int n, m, ai, bi, sum=0;
    vector<vector<int> > AB;
    cin >> n >> m;
    AB.assign(m+1, vector<int>());

    for(int i=0;i<n;i++){
        cin >> ai >> bi;
        if(ai < m+1){
            AB[ai].push_back(bi);
        }
    }

    priority_queue<int> pQ;

    for(int i=1;i<m+1;i++){
        for(int bi : AB[i]){
            pQ.push(bi);
        }
        if(pQ.empty()) continue;
        sum += pQ.top();
        pQ.pop();
    }

    cout << sum << endl;
}

Measured memory_bytes: 5504
#include<iostream>

using namespace std;
int main(){
	
	int N,A,B,C,X;
	int Y[10000];
	while(cin>>N>>A>>B>>C>>X){
		for(int i=0;i<N;i++)
			cin>>Y[i];
		
		int n=0;
		int j=0;
		for(int i=0;i<=10000;i++){
			if(Y[n]==X)
				n++;
			if(n==N){
				j=i;
				break;
			}
			X=(A*X+B)%C;
			
		}
		if(N!=0){
		if(n==N)
			cout<<j<<endl;
		else
			cout<<-1<<endl;
		}
	}
	
	
}

Measured memory_bytes: 1164
n,m = map(int,input().split())
h = list(map(int,input().split()))
ans = 0
mt = [0] * n

for i in range(m):
    s,e = map(int,input().split())
    
    if h[s-1] > h[e-1]:
        if mt[s-1] == 0 or mt[s-1] == 'good':
            mt[s-1] = 'good'
        else:
            mt[s-1] = 'bad'
    else:
        mt[s-1] = 'bad'
    # mt[s-1] = 'good' if h[s-1] > h[e-1] else 'bad'
    
    if h[e-1] > h[s-1]:
        if mt[e-1] == 0 or mt[e-1] == 'good':
            mt[e-1] = 'good'
        else:
            mt[e-1] = 'bad'
    else:
        mt[e-1] = 'bad'

#print(mt)

for i in mt:
    if (i == 0) or (i == 'good'):
        ans = ans + 1
        
print(ans)

Measured memory_bytes: 19928
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>

#define MAX 1000000000
#define MIN -10000000000

using namespace std;
int main() {
    int b,n,i,j;
    long long maxx=MIN,minx=MAX,sum=0;
    cin>>n;
    vector<int> a(n);
    for(i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
        if(maxx<a[i])maxx=a[i];
        if(minx>a[i])minx=a[i];
    }

    cout<< minx << " " << maxx << " " << sum <<endl;


    return 0;
}


Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,i,count=0,ans=0;
	cin>>n;
	string s;
	cin>>s;
	for(i=0;i<n;i++)
	{
		if(s[i]=='W') count++;
	}
	for(i=n-count;i<n;i++)
	{
		if(s[i]=='R') ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3752
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<stack>
#include<cmath>
  
using namespace std;
  
#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)


#define X real()
#define Y imag()
typedef complex<double> P;

class L:public vector<P>{
	public:
	L(P a, P b){
		push_back(a);
		push_back(b);
	}
};

template<class T> T sq(T x){return x*x;}
double dot(P a, P b){return a.X*b.X + a.Y*b.Y;} 


P projection_LP(L a, P p){
	P e = (a[1]-a[0])/abs(a[1]-a[0]);
	double d = dot(p-a[0], e);
	return a[0]+d*e;
}

P refrection_LP(L a, P p){
	P b = projection_LP(a,p);
	P c = b-p;
	return p+c+c;
}


int main(){
	double xa,ya,xb,yb,xc,yc;
	
	while(scanf("%lf,%lf,%lf,%lf,%lf,%lf",&xa,&ya,&xb,&yb,&xc,&yc)!=EOF){
		P ans = refrection_LP(L(P(xa,ya),P(xb,yb)), P(xc,yc));
		
		printf("%.9lf %.9lf\n",ans.X,ans.Y);
	}
}

Measured memory_bytes: 1260
import re
compiled = re.compile(r"(R*)(RL)(L*)")
s=input()
ans = [0 for i in range(len(s))]
matched=list(compiled.findall(s))
pos=0

for i in range(len(matched)):
    m=matched[i]
    pos+=len(m[0])
    ans[pos]+=1
    ans[pos+1]+=1
    if(len(m[0])%2):
        ans[pos]+=+len(m[0])//2
        ans[pos+1]+=1+len(m[0])//2
    else:
        ans[pos]+=len(m[0])//2
        ans[pos+1]+=len(m[0])//2
    if(len(m[2])%2):
        ans[pos]+=1+len(m[2])//2
        ans[pos+1]+=+len(m[2])//2
    else:
        ans[pos]+=len(m[2])//2
        ans[pos+1]+=len(m[2])//2
    pos+=2+len(m[2])

print(" ".join(map(str,ans)))


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int ui32;
const long long INFLL = 1e18;

using namespace std;

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

    int n;
    cin >> n;

    map<ll, int> was;

    ll ans = 0;

    ll sum = 0;

    was[0] = 1;

    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;

        sum += x;

        ans += was[sum];

        ++was[sum];
    }

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

Measured memory_bytes: 12800
// Last Change: 05/03/2020 00:45:38.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll N, M;
  cin >> N >> M;

  vector<pair<ll, ll>> ans;
  vector<int> used(N, 0);

  ll left = 0;
  ll right = M + 1;
  for (ll i = M; i >= 1; --i) {
    if (M % 2 == 0) {
      if (i % 2 == 0) {
        ans.push_back(make_pair(left, left + i));
        ++left;
      } else {
        ans.push_back(make_pair(right, right + i));
        ++right;
      }
    } else {
      if (i % 2 == 1) {
        ans.push_back(make_pair(left, left + i));
        ++left;
      } else {
        ans.push_back(make_pair(right, right + i));
        ++right;
      }
    }
  }
  for (auto &&e : ans) {
    cout << e.first + 1 << " " << e.second + 1 << endl;
  }
}


Measured memory_bytes: 5500
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <iomanip>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(int i = 0;i < n;++i)
long long value[200000] = {};
int main() {
	long long n;
	cin >> n;
	REP(i, n) {
		long long a;
		cin >> a;
		value[i] = a;
	}
	long long ans = 0;
	for (int i = 0;i < n;++i) {
		if (value[i] % 2 == 0) {
			if (i != 0 && value[i - 1] % 2 == 1 && value[i] != 0) {
				value[i - 1]--;
				value[i]--;
				ans++;
			}
		}
		if (i != n-1&&value[i] % 2 == 1 && value[i + 1] % 2 == 1) {
			value[i]--;
			value[i + 1]--;
			ans++;
		}
	}
	REP(i, n) {
		ans += value[i] / 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"

using ll = long long;
using P = pair<int, int>;

const long long MOD = 1e9+7;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

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

    if (p == 2 || p == 5) {
        ll ans = 0;
        rep(i, n) {
            int num = s.at(i) - '0';
            if (num % p == 0) ans += i + 1;
        }
        cout << ans << endl;
        return 0;
    }

    vector<int> suff(n);
    int res = 0;
    int base = 1;
    revrep(i, n) {
        int num = s.at(i) - '0';
        res += num * base;
        res %= p;
        suff.at(i) = res;
        base *= 10;
        base %= p;
    }

    ll ans = 0;
    map<int, int> mp;
    mp[0] = 1;
    rep(i, n) {
        ans += mp[suff.at(i)];
        mp[suff.at(i)]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1668
#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <iostream>
typedef unsigned long ul;
using namespace std;

int main(){
    string s;
    int count=0;

    cin >> s;
    for(int i=0; i<s.length(); i++){
        if(s[i]=='o') count++;
    }
    //cout << s.length() << endl;
    if((15 - s.length()) < (8 - count)) cout << "NO" << endl;
    else cout << "YES" << endl;
    return 0;
}



Measured memory_bytes: 256
#ifndef _WIN32
#include<iostream>
#endif // !_WIN32

#include<algorithm>
#include<vector>
#include<string>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
using namespace std;
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
struct S {
	int id, lb, ub,nxt,prv;
};

S s[112345];
stack<int> pool;
const int ED = -2;
const int BG = -3;
void is(int i,int rest,int new_id) {
	if (rest <= 0)return;
	S& now = s[i];
	if (now.id != -1) {
		is(now.nxt, rest, new_id);
		return;
	}
	int n = now.ub - now.lb;
	if (n <= rest) {
		now.id = new_id;
		is(now.nxt, rest - n, new_id);
	}
	else {
		int p = pool.top(); pool.pop();
		S& x = s[p];
		S& y = now;
		x.prv = y.prv;
		x.nxt = i;
		x.id = new_id;
		x.lb = y.lb;
		x.ub = x.lb + rest;
		y.prv = p;
		s[x.prv].nxt = p;
		y.lb += rest;
	}
}
void dl(int i, int id) {
	S& now = s[i];
	if (now.id == ED)return;
	if (now.id == id)now.id = -1;
	dl(now.nxt, id);
}
int get(int i, int pos) {
	S& now = s[i];
	if (now.lb <= pos&&pos < now.ub)return now.id;
	return get(now.nxt,pos);
}
void clear(int i) {
	S& now = s[i];
	if (now.id != ED)clear(now.nxt);
	pool.push(i);
}



int main() {
	REP(i, 112345) {
		pool.push(i);
	}
	int n;
	while (cin >> n, n) {
		int a,b,c;
		a = pool.top(); pool.pop();
		b = pool.top(); pool.pop();
		c = pool.top(); pool.pop();
		s[a].nxt = b;
		s[b].prv = a;
		s[b].nxt = c;
		s[c].prv = b;
		s[a].id = BG;
		s[b].id = -1;
		s[c].id = ED;
		s[b].lb = 0;
		s[b].ub = 1e9 + 10;
		REP(i, n) {
			string x;
			cin >> x;
			if (x == "W") {
				int id, need;
				cin >> id >> need;
				is(s[a].nxt, need, id);
			}
			if (x == "D") {
				int id;
				cin >> id;
				dl (s[a].nxt, id);
			}
			if (x == "R") {
				int pos;
				cin >> pos;
				cout << get(s[a].nxt,pos) << endl;
			}

		}
		clear(a);
		cout << endl;
	}

}

Measured memory_bytes: 3540
///
// File:  alds1_3_b.cpp
// Author: ymiyamoto
//
// Created on Fri Oct  6 01:08:23 2017
//

#include <cstdint>
#include <iostream>

using namespace std;
#define SIZE 200000
static pair<string, int32_t> que[SIZE];
static uint32_t top;
static uint32_t bottom;

static void push(pair<string, int32_t> val)
{
  que[bottom] = val;
  bottom++;
  bottom %= SIZE;
}

static pair<string, int32_t> pop()
{
  pair<string, int32_t> val = que[top];
  top++;
  top %= SIZE;
  return val;
}

static bool empty()
{
  return top == bottom;
}

int32_t main()
{
  int32_t n, q;
  cin >> n >> q;
  for (int32_t i = 0; i < n; i++) {
    string str;
    int32_t val;
    cin >> str >> val;
    push({str, val});
  }

  uint64_t current_time = 0;
  while (!empty()) {
    auto val = pop();
    if (val.second - q <= 0) {
      current_time += val.second;
      cout << val.first << " " << current_time << endl;
    } else {
      current_time += q;
      push({val.first, val.second - q});
    }
  }

  return 0;
}

Measured memory_bytes: 8600
#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;
ll Max = 10 + 1e12;
int N = 5 + 1e5;
int main()
{
	int n;
	cin >> n;
	vector<double> vv(n);
	rep(i, n) cin >> vv[i];
	sort(vv.begin(), vv.end());
	rep(i, n - 1) {
		double sum = (vv[0] + vv[1]) / 2;
		vv[0] = N;
		vv[1] = N;
		vv.push_back(sum);
		sort(vv.begin(), vv.end());
	}
	cout << vv[0];

}

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

using namespace std;

int main() {
//        freopen("input.txt", "r", stdin);
//        freopen("output.txt", "w", stdout);
        int n;
        scanf("%d", &n);
        vector<int> a(n);
        int ans = 0;
        for (int i = 0; i < n; i++) {
                scanf("%d", &a[i]);
                ans = __gcd(ans, a[i]);
        }
        vector<int> left(n + 10, 0), right(n + 10, 0);
        left[0] = a[0], right[n - 1] = a[n - 1];
        for (int i = 1; i < n; i++) {
                left[i] = __gcd(a[i], left[i - 1]);
                right[n - 1 - i] = __gcd(a[n - 1 - i], right[n - i]);
        }
        for (int i = 0; i < n; i++) {
                int mx = (i > 0 ? left[i - 1] : 0);
                mx = (i + 1 < n ? __gcd(mx, right[i + 1]) : mx);
                ans = max(ans, mx);
        }
        printf("%d\n", ans);
        return 0;
}


Measured memory_bytes: 1408
N,X=(int(x) for x in input().split())
L=list(map(int,input().split()))
D=[0]*(N+1)
c=1
for n in range(N):
    D[n+1]=D[n]+L[n]
    if D[n+1]>X:
        break
    c=c+1
print(c)


Measured memory_bytes: 2940
/*************************************************************************
> File Name: test.cpp
> Author: Akira 
> Mail: qaq.febr2.qaq@gmail.com 
************************************************************************/

//#pragma comment(linker, "/STACK:102400000,102400000")
#include<bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) ((a)*(a))
#define ALL(a) a.begin(), a.end()
#define mp make_pair
#define pb push_back
using namespace std;                                                                                              

#define MaxN 305
#define MaxM MaxN*10
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
const int mod = 1E9+7;
const double eps = 1e-6;
#define bug cout<<88888888<<endl;
#define debug(x) cout << #x" = " << x << endl;
template<typename T> T abs(T val){return val>0?val:-val;}
inline int max2(int a, int b) {return ((a > b)? a : b);}
inline int min2(int a, int b) {return ((a < b)? a : b);}
inline int max3(int a, int b, int c) {return max2(a, max2(b, c));}
inline int min3(int a, int b, int c) {return min2(a, min2(b, c));}
template <class T> inline void read(T &ret) {char c; ret=0;while((c=getchar())<'0'||c>'9');while(c>='0'&&c<='9') ret=ret*10+(c-'0'),c=getchar();}
template <class T> inline void out(T x) {if(x>9) out(x/10);putchar(x%10+'0');}

int n; //总点数
LL dis[MaxN][MaxN];  //dis[i][j]存储i到j的最短路
bool no[MaxN][MaxN];
bool nis[MaxN][MaxN];
void Floyd()
{
    CLR(no);CLR(nis);
    for(int k=1;k<=n;k++)
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
            {
                if(dis[i][j] > dis[i][k]+dis[k][j])
                {
                    // debug(i) debug(j)
                    nis[i][j] = true;
                }
                if(i==j || i==k || j==k) continue;
                if(dis[i][j] == dis[i][k]+dis[k][j]) 
                    no[i][j] = true;
            }
    LL ans = 0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(!no[i][j]) ans += dis[i][j];
            // debug(i) debug(j) debug(is[i][j])
            if(nis[i][j] )
            {
                puts("-1");
                return;
            }
        }
    }
    printf("%lld\n", ans/2);
}

int main()
{
    while(~scanf("%d", &n))
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                scanf("%d", &dis[i][j]);
            }
        }
        Floyd();
    }
}

Measured memory_bytes: 1152
#include <cstdio>
#include <vector>

using namespace std;

void get(vector <int> &A, int &max_1, int &max_2)
{
    for(int i = 0; i < A.size(); i++)
    {
        if(A[i] >= A[max_1])
        {
            max_2 = max_1;
            max_1 = i;
        }
        else if(A[i] > A[max_2])
        {
            max_2 = i;
        }
    }
}

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

    const int MAX_N = 1e5 + 5;
    vector <int> odd_frequency(MAX_N, 0);
    vector <int> even_frequency(MAX_N, 0);

    for(int i = 1; i <= no_of_elements; i++)
    {
        int element;
        scanf("%d", &element);

        if(i%2 == 0)
        {
            even_frequency[element]++;
        }
        else if(i%2 == 1)
        {
            odd_frequency[element]++;
        }
    }

    int most_frequent_even_element = 0, second_most_frequent_even_element = 0;
    get(even_frequency, most_frequent_even_element, second_most_frequent_even_element);

    int most_frequent_odd_element = 0, second_most_frequent_odd_element = 0;
    get(odd_frequency, most_frequent_odd_element, second_most_frequent_odd_element);

    int even_changes = 0, odd_changes = 0;
    if(most_frequent_even_element != most_frequent_odd_element)
    {
        even_changes = no_of_elements/2 - even_frequency[most_frequent_even_element];
        odd_changes = no_of_elements/2 - odd_frequency[most_frequent_odd_element];
    }
    else if(most_frequent_even_element == most_frequent_odd_element)
    {
        if(even_frequency[most_frequent_even_element] > odd_frequency[most_frequent_odd_element])
        {
            even_changes = no_of_elements/2 - even_frequency[most_frequent_even_element];
            odd_changes = no_of_elements/2 - odd_frequency[second_most_frequent_odd_element];
        }
        if(even_frequency[most_frequent_even_element] < odd_frequency[most_frequent_odd_element])
        {
            even_changes = no_of_elements/2 - even_frequency[second_most_frequent_even_element];
            odd_changes = no_of_elements/2 - odd_frequency[most_frequent_odd_element];
        }
      if(even_frequency[most_frequent_even_element] == odd_frequency[most_frequent_odd_element])
        {
            if(odd_frequency[second_most_frequent_odd_element]<even_frequency[second_most_frequent_even_element])
            {
              even_changes = no_of_elements/2 - even_frequency[second_most_frequent_even_element];
            odd_changes = no_of_elements/2 - odd_frequency[most_frequent_odd_element];
            }
        else
        {
          even_changes = no_of_elements/2 - even_frequency[most_frequent_even_element];
            odd_changes = no_of_elements/2 - odd_frequency[second_most_frequent_odd_element];
        }
        }
    }

    int changes = even_changes + odd_changes;
    printf("%d\n", changes);
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<chrono>
 
using namespace std;
using namespace std::chrono;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
ll mod=1000000007;
const int MX=0x3f3f3f;

int fac(int n){
    int res=1;
    while(n) res=res*n--;
    return res;
}
int main(){
	IOS;
    int n,i,temp,j,c;
    cin>>n;
    int a=0,b=0;
    int p[n]={0};
    REP(i,0,n-1){
        c=0;
        cin>>temp;
        p[temp-1]=-1;
        REP(j,0,temp-1) if(p[j]!=-1) c++; 
        a+=(c)*fac(n-i-1);
    }
    memset(p,0,sizeof(p));
    REP(i,0,n-1){
        c=0;
        cin>>temp;
        p[temp-1]=-1;
        REP(j,0,temp-1) if(p[j]!=-1) c++;
        b+=(c)*fac(n-i-1);
    }
    
    cout<<abs(a-b);
	return 0;
}

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

using namespace std;

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


const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()

int main(){
    ll H,N,sum=0;
    cin>>H>>N;
    vector<int> A(N);
    rep(i,N){
        ll X;
        cin>>X;
        sum+=X;
    }
    if(H<=sum){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }



    return 0;
}

//a=97,z=122

Measured memory_bytes: 640
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

int bfs(vs &f,pii start,char goal,int h,int w){
	vvi cnt(h,vi(w,-1));
	queue<pii> q;
	q.push(start);
	cnt[start.first][start.second]=0;
	while(!q.empty()){
		pii p=q.front();q.pop();
		REP(d,4){
			int y=p.first+dy[d];
			int x=p.second+dx[d];
			if(y>=0&&x>=0&&y<h&&x<w&&f[y][x]!='X'){
				if(f[y][x]==goal){
					gp=make_pair(y,x);
					return cnt[p.first][p.second]+1;
				}else if(cnt[y][x]==-1){
					q.push(make_pair(y,x));
					cnt[y][x]=cnt[p.first][p.second]+1;
				}
			}
		}
	}
	assert(0);
}

int main(){
	int h,w,n;
	cin>>h>>w>>n;
	vs f(h);
	pii start;
	REP(i,h){
		cin>>f[i];
		REP(j,w){
			if(f[i][j]=='S')start=make_pair(i,j);
		}
	}
	pii cur=start;
	int cnt=0;
	FOR(i,1,n+1){
		cnt+=bfs(f,cur,'0'+i,h,w);
		cur=gp;
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 6060
from collections import Counter
N,M=list(map(int,input().split()))
cards=list(map(int,input().split()))
all_c=Counter(cards)

for i in range(M):
    time,val=list(map(int,input().split()))
    try:
        all_c[val]+=time
    except:
        all_c[val]=time

tmp=list(all_c.keys())
tmp.sort(reverse=True)
total=0
sum_time=0
for i in tmp:
    if sum_time>=N:
        break
    sum_time+=all_c[i]
    if sum_time<N:
        total+=i*all_c[i]
    else:
        total+=i*(all_c[i]+N-sum_time)
print(total)


Measured memory_bytes: 32448
import java.util.*;
import java.math.BigDecimal;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);    //scanner
        BigDecimal  a = new BigDecimal(sc.next());      // A:整数
        BigDecimal  b = new BigDecimal(sc.next());      // B:小数点以下は二桁

        a = a.multiply(b);  // AxB
        a = a.setScale(0, BigDecimal.ROUND_DOWN);
        System.out.println(a);    // output
    }
}

Measured memory_bytes: 35800
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	int A[a], B[b], C[c];
	for(int i=0;i<a;i++) cin>>A[i];
	for(int i=0;i<b;i++) cin>>B[i];
	for(int i=0;i<c;i++) cin>>C[i];
	
	sort(A,A+a, greater<int>());
	sort(B,B+b, greater<int>());
	
	vector<int>v;
	for(int i=0;i<x;i++) v.push_back(A[i]);
	for(int i=0;i<y;i++) v.push_back(B[i]);
	for(int i=0;i<c;i++) v.push_back(C[i]);
	
	sort(v.begin(),v.end(), greater<int>());
	
	long long sum=0;
	for(int i=0;i<x+y;i++) sum+=v[i];
	
	cout<<sum;
}

Measured memory_bytes: 3572
<?php
list($N, $M) = explode(" ", fgets(STDIN));
for($i = 0; $i < $M; $i++){
    list($a, $b) = explode(" ", trim(fgets(STDIN)));
    $path[$a][] = $b;
    $path[$b][] = $a;
}
echo dfs(1, []);

function dfs($cp, $route){
    global $path, $N;
    $route[] = $cp;
    if(count($route) == $N)return 1;
    $sum = 0;
    foreach($path[$cp] as $np){
        if(!in_array($np, $route)){
            $sum += dfs($np, $route);
        }
    }
    return $sum;
}


Measured memory_bytes: 4856