akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
bool pertence_sequence(int i) { return ((i % 3 == 0) || (i % 5 == 0)); }
int main() {
	long long a, sum;
	while(cin >> a) {
		sum = 0;
		for(int i = 1; i <= a; i++) {
			if(!pertence_sequence(i)) {
				sum += i;
			}
		}
		cout << sum << endl;
	}
	return 0;	
}


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

int main() {
  int N;
  int ans = 2;
  int max = 1;
  cin >> N;

  if (N == 1) {
    cout << 1 << endl;
    return 0;
  }

  for (int i = 2; i <= N; i += 2) {
    int count = 0;
    int j = i;
    while (j % 2 == 0) {
      j = j / 2;
      count++;
    }

    if (max < count) {
      max = count;
      ans = i;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3584
/*
    アリナ・グレイが好きです。
*/

#include<bits/stdc++.h>
using namespace std;
#define itn int

int main(void){
    string n;
    cin >> n;
    if(n[0] == '7' || n[1] == '7' || n[2] == '7')cout << "Yes";
    else cout << "No";
}


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

ll mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  vector<ll> aSum(n);
  for (int i = n-1; i > 0; --i) {
    aSum[i-1] = aSum[i] + a[i];
    aSum[i-1] %= mod;
  }
  ll ans = 0;
  rep(i,n) {
    ans += (aSum[i] * a[i]) % mod;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6424
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
using ll = long long;
using namespace std;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
//sort(a, a + N, greater<ll>())   // descend
//sort(a, a+N)                    //  ascend

/* 
void comb(vector<vector <ll> > &v) {
	ll mod=1000000007;
	rep (i,0,v.size()) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	rep (k,1,v.size()) {
		rep (j,1,k) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%mod;
		}
	}
}
/*main内でnCn~nC0 生成 **
vector<vector<ll> > v(n + 1, vector<ll>(n + 1, 0));
comb(v);
*/


int main() {
	ll n;
	cin>>n;
	ll p3=0,p5=0,p7=0;
	ll ans=0;
	ll c=0;
	bool q=true;
	if(n>=800000000) ans=26484;
	else if(n>=500000000){
		ans=14384;
		rep(i,500000000,n+1){
		c=i;
		while(c!=0){
			if(c%10==3)p3++;
			else if(c%10==5)p5++;
			else if(c%10==7)p7++;
			else {q=false; break;}
			c/=10;
		}
		if(q && p3>0 && p5>0 && p7>0) ans++;
		p3=0,p5=0,p7=0;
		q=true;
		}
	}

	else if(n>=300000000){
		ans=8334;
		rep(i,300000000,n+1){
		c=i;
		while(c!=0){
			if(c%10==3)p3++;
			else if(c%10==5)p5++;
			else if(c%10==7)p7++;
			else {q=false; break;}
			c/=10;
		}
		if(q && p3>0 && p5>0 && p7>0) ans++;
		p3=0,p5=0,p7=0;
		q=true;
		}
	}
	//else if(n<300000000 && n>=100000000) ans=8334;
	else if(n<100000000){
		rep(i,1,n+1){
		c=i;
		while(c!=0){
			if(c%10==3)p3++;
			else if(c%10==5)p5++;
			else if(c%10==7)p7++;
			else {q=false; break;}
			c/=10;
		}
		if(q && p3>0 && p5>0 && p7>0) ans++;
		p3=0,p5=0,p7=0;
		q=true;
		}
	}
	cout<<ans;
} 

Measured memory_bytes: 256
// #pragma GCC optimize "trapv" Uncomment when dealing with huge numbers
/*<----------PBDS---------->

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
template <typename T>
using order_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

order_set<datatype>oset;
Kth smallest : *oset.find_by_order(k-1); // 0 based index
No of elements less than k : oset.order_of_key(k);
Erase X : oset.erase(x)
<----------PBDS---------->*/
#include<iostream>
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define pb(x) push_back(x)
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define lcm(a,b) (a*b)/gcd(a,b)
#define bits(x) __builtin_popcountll(x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int wt[100010];
int val[100010];
int n,w;
int dp[100010][110];
int solve(int n,int w){
	if(n==0||w==0){
		return dp[w][n]=0;
	}
	if(dp[w][n]!=-1){
		return dp[w][n];
	}
	if(w<wt[n-1]){
		return dp[w][n] = solve(n-1,w);
	}
	return dp[w][n] = max(val[n-1]+solve(n-1,w-wt[n-1]),solve(n-1,w));
}
int32_t main()
{
    fast;
    memset(dp,-1,sizeof(dp));
    cin >> n >> w;
    for(int i = 0 ; i<  n ;i++ ){
    	cin >> wt[i] >> val[i];
	}
    cout << solve(n,w);
}





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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 100000000000

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

	ll N, K;
	cin >> N >> K;

	vector<ll> A;
	ll tmp;
	ll mval = -1;
	rep(i, N) {
		cin >> tmp;
		A.push_back(tmp);
		mval = max(mval, tmp);
	}

	ll cnt[2];
	ll ans = 0;
	ll val = 0;
	bool include_k = false;
	for (int i = 50; i >= 0; i--) {
		cnt[0] = cnt[1] = 0;
		rep(j, N) {
			cnt[((A[j] >> i) & 1)]++;
		}
		if (cnt[0] < cnt[1] ) {
			if (((K >> i) & 1) == 1) {
				include_k = true;
			}
		}
		else {
			if (include_k || ((K >> i) & 1) == 1) {
				val |= (ll)1 << i;
			}
		}
	}

	rep(j, N) {
		ans += val ^ A[j];
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 1400
N = int(input())
a =list(map(int, input().split()))

ans = 0
import math
for i in range(N):
  if a[i] % 2 != 0:
    continue
  while a[i] % 2 == 0:
    a[i] = a[i] /2
    ans += 1
print(ans)

Measured memory_bytes: 4148
//******* It's LEVI_17 ***************

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define ff first
#define ss second
#define MP make_pair
#define mset(x,a) memset(x,a,sizeof(x))
#define max3(x,y,z) max(x,max(y,z))
#define min3(x,y,z) min(x,min(y,z))
#define sqr(a) (a)*(a)
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
#define f1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define vvll vector<vector<ll>>  
#define vll vector<ll> 
#define pll pair<ll,ll>
#define vpll vector<pll>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define cases ll t;cin >> t;while(t--)
#define rr return 0
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define deb(a)			std::cerr<<#a<<"="<<(a)<<"\n"
#define deb2(a,b)		std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define deb3(a,b,c)		std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
const int MOD = 1000 * 1000 * 1000 + 7;

//syntax for priority queue
// max queue -> priority_queue<ll>
// min queue -> priority_queue<ll,vector<ll>,greater<ll>>

//##############################################################################################

string getRes(string s1,string s2,ll n,ll m)
{
    vvll dp(n + 1, vll(m + 1, 0));
    string res = "";
    for (ll i = 1; i <= n; ++i)
    {
        for (ll j = 1; j <= m; ++j)
        {
            if (s1[i - 1] == s2[j - 1])
                dp[i][j] = 1 + dp[i - 1][j - 1];
            else
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }

    }
    ll x=n, y=m;
    while (x > 0 && y > 0)
    {
        if (s1[x - 1] == s2[y - 1])
        {
            res += s1[x - 1];
            x--;
            y--;
        }
        else
        {
            if (dp[x - 1][y] > dp[x][y - 1])
            {
                x--;
            }
            else
                y--;
        }
    }

    reverse(all(res));
    return res;
}

void solve()
{
    string s1, s2;
    cin >> s1 >> s2;
    ll n = s1.length();
    ll m = s2.length();

    string res = getRes(s1, s2, n, m);

    cout << res << "\n";
}

//###############################################################################################

int main()
{
    fast;
    ll t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    rr;
}


//Watashi wa tsuyoku modotte kimasu

Measured memory_bytes: 73664
import java.util.ArrayList;
import java.util.Scanner;
//import java.io.*;
//import java.util.Arrays;
public class Main {
	public static void main(String[] args) throws java.io.IOException {
		Scanner scan = new Scanner(System.in);
		//InputStreamReader is = new InputStreamReader(System.in);
		//BufferedReader br = new BufferedReader(is);
		//String text = scan.next();
		
		int x = 110000;
		ArrayList<Integer> searchList = new ArrayList<Integer>();
		ArrayList<Integer> primeList  = new ArrayList<Integer>();
		for(int i = 2; i <= x; i++) {
			searchList.add(i);
		}
		while(!searchList.isEmpty() && searchList.get(0) <= Math.sqrt(x)) {
			int primeNumber = searchList.get(0);
			primeList.add(primeNumber);
			
			for(int i = 0; i < searchList.size(); i++) {
				if(searchList.get(i) % primeNumber == 0) {
					searchList.remove(i);
					i--;
				}
			}
		}
		primeList.addAll(searchList);
		int[] sum = new int[primeList.size()];
		sum[0] = primeList.get(0);
		for(int i = 1; i < primeList.size(); i++) {
			sum[i] = sum[i-1] + primeList.get(i);
		}
		
		
        int n = scan.nextInt();
        while(n != 0){
            System.out.println(sum[n-1]);
            n = scan.nextInt();
        }
	}
}

Measured memory_bytes: 31528
class in{struct It{int it;const bool rev;explicit constexpr It(int it_, bool rev=false):it(it_),rev(rev){}int operator*(){return it;}bool operator!=(It& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const It i,n;public:explicit constexpr in(int n):i(0),n(n<0?0:n){}explicit constexpr in(int i,int n):i(i,n<i),n(n){}const It& begin(){return i;}const It& end(){return n;}};

#include <bits/stdc++.h>
using namespace std;

const int INF = 1e9;
vector<vector<int>> adj;
vector<int> num;
vector<pair<int, int>> range;
bool update(pair<int, int>& l, const pair<int, int>& r) {
    if(l.second < r.first || r.second < l.first) return false;
    bool ok = false;
    if(l.first <= r.first && r.second <= l.second) ok = true;
    if(r.first <= l.first && l.second <= r.second) ok = true;
    if(!ok) if((l.first & 1) == (r.first & 1)) ok = true;
    l.first = max(l.first, r.first);
    l.second = min(l.second, r.second);
    return ok;
}
bool dfs(int cur, int par) {
    auto& myRange = range[cur];
    if(num[cur] != INF) myRange = make_pair(num[cur], num[cur]);
    bool res = true;
    if(par != -1) res &= update(myRange, make_pair(range[par].first - 1, range[par].second + 1));
    pair<int, int> nRange(myRange.first - 1, myRange.second + 1);
    for(int nxt : adj[cur]) if(nxt != par) {
        res &= update(range[nxt], nRange);
        res &= dfs(nxt, cur);
        auto upRange = range[nxt];
        upRange.first--; upRange.second++;
        res &= update(myRange, upRange);
    }
    return res;
}
void dfs2(int cur, int par) {
    if(num[cur] == INF) {
        num[cur] = range[cur].first;
    }
    pair<int, int> nRange(num[cur] - 1, num[cur] + 1);
    for(int nxt : adj[cur]) if(nxt != par) {
        update(range[nxt], nRange);
        dfs2(nxt, cur);
    }
}
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    adj.assign(n, vector<int>());
    for(int _ : in(n - 1)) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        adj[u].emplace_back(v);
        adj[v].emplace_back(u);
    }
    num.assign(n, INF);
    int q;
    cin >> q;
    for(int _ : in(q)) {
        int v, p;
        cin >> v >> p;
        --v;
        num[v] = p;
    }
    range.assign(n, make_pair(-INF, INF));
    if(dfs(0, -1) == false) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes\n";
        dfs2(0, -1);
        for(int x : num) cout << x << '\n';
    }
    return 0;
}

Measured memory_bytes: 18560
line= [int(input()) for i in range(5)]
line_sec=[]
k=0
s=0
k_before=0
num_before=0
num=0
m=0
m_before=0
for i in range(5):
    # k_before = k
    # num_before=num
    # num=i
    m_before=m
    m=i
    k=line[i]%10
    if k>0:
        s=line[i]-k+10
    else:
        s=line[i]
    line_sec.append(s)
    # if k!=0 and k_before<k:
    #     k=k_before
    #     num=num_before
    num_before=num
    num=line_sec[i]-line[i]
    if num_before>num:
        num=num_before
        m=m_before

ans = (line_sec[0]+line_sec[1]+line_sec[2]+line_sec[3]+line_sec[4])-line_sec[m]+line[m]
print(ans)
# print('l',line)
# print('l_sec',line_sec)
# print(num)
# print(k)

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define prints(x, y) cout<<(x)<<" "<<(y)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define r_rep(i, n) for(int i = n; i >= 0; i--)
#define ll long long int
#define pb push_back
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

int main() {
  int N, L;
  cin >> N >> L;
  vector<string> a(N);
  rep(i, N){
    cin >> a[i];
  }
  sort(a.begin(), a.end());

  rep(i, N){
    cout << a[i];
  }
  cout << endl;
}


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

using namespace std;

int main(void)
{
  string s;
  int i, c=0, f=0;
  
  cin >> s;
  
  for(i=0; i<s.size();i++){
    if(s[i]=='C'){
		c = 1;
    }
    
    if(s[i]=='F' && c==1){
		f = 1;
    }
  }
  
  if(f == 1){
	cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
x,y,a,b,c = gets.chomp.split.map(&:to_i)
p = gets.chomp.split.map(&:to_i).sort.reverse
q = gets.chomp.split.map(&:to_i).sort.reverse
r = gets.chomp.split.map(&:to_i).sort

tmp_aka = p[0..x-1]
tmp_midori = q[0..y-1]
tmp_white = []

def white_checker?(aka, midori, white, tmp_white)
  aka_length, midori_length = [aka.length, midori.length]
  return false if aka_length == 0 && midori_length == 0
  if aka_length == 0
    if midori.last < white.last
      midori.pop
      tmp_white.push white.pop
      return true
    end
    return false
  elsif midori_length == 0
    if aka.last < white.last
      aka.pop
      tmp_white.push white.pop
      return true
    end
    return false
  else
    if aka.last < white.last || midori.last < white.last 
      if aka.last < midori.last
        aka.pop
      else
        midori.pop
      end
      tmp_white.push white.pop
      return true
    end
    return false
  end
end

while true do
  break if r.length == 0
  break if !white_checker?(tmp_aka, tmp_midori, r, tmp_white)
end

puts (tmp_aka + tmp_midori + tmp_white).inject(:+)


Measured memory_bytes: 29060
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a[10];
	int c[100005]={0},d[100005]={0};
	int m,n,b,x=0,y=0,z=0,i;
	scanf("%d%d",&m,&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d%s",&b,a);
		if(d[b]==-1)
		continue;
		if(a[0]=='A')
		{
			d[b]=-1;
			x++;
			z+=c[b];
			//printf("%d ",z);	
		} 
		if(a[0]=='W')
		{
			c[b]++;
		}
	}
	if(n==0)
	printf("0 0");
	else
	printf("%d %d",x,z);
}

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

using namespace std;

int main()
{
	string s;
	int start, end;
	cin >> s;

	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == 'A')
		{
			start = i;
			break;
		}
	}

	for (int i = s.size() - 1; i >= 0; i--)
	{
		if (s[i] == 'Z')
		{
			end = i;
			break;
		}
	}

	cout << s.substr(start, (end - start) + 1).size() << endl;

	return 0;
}


Measured memory_bytes: 772
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#define M 1000000007
typedef long long int ll;
#define INF 1000000000000000
int main()
{
   ll n,w;
   cin>>n>>w;
   ll W[n],V[n];
   ll i,j;
   for(i=0;i<n;i++)
   {
       cin>>W[i]>>V[i];
   }
   ll dp[n+1][w+1];
   memset(dp,0,sizeof(dp));
   if(W[0]<=w)
   {
       dp[1][W[0]]=V[0];
   }
   for(i=2;i<=n;i++)
   {
       for(j=1;j<=w;j++)
       {
           dp[i][j]=dp[i-1][j];
           if(j>W[i-1])
            {
                dp[i][j]=max(dp[i][j],dp[i-1][j-W[i-1]]+V[i-1]);
            }

       }
   }
   ll ans=0;
   for(i=1;i<=w;i++)
    ans=max(ans,dp[n][i]);

   cout<<ans;

}


Measured memory_bytes: 79104
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int a[85][85], b[85][85];
int dp[85][85][10000];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int h, w;
	cin >> h >> w;
	rep(i, h) rep(j, w) cin >> a[i][j];
	rep(i, h) rep(j, w) cin >> b[i][j];
	dp[0][0][abs(a[0][0] - b[0][0])] = 1;
	rep(i, h) rep(j, w){
		if(!i && !j) continue;
		rep(k, 10000){
			if(i) dp[i][j][abs(k - abs(a[i][j] - b[i][j]))] |= dp[i - 1][j][k];
			if(j) dp[i][j][abs(k - abs(a[i][j] - b[i][j]))] |= dp[i][j - 1][k];
			if(i) dp[i][j][abs(k + abs(a[i][j] - b[i][j]))] |= dp[i - 1][j][k];
			if(j) dp[i][j][abs(k + abs(a[i][j] - b[i][j]))] |= dp[i][j - 1][k];
		}
	}
	rep(i, 10000) if(dp[h - 1][w - 1][i]){
		cout << i << endl;
		return 0;
	}
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

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

Measured memory_bytes: 4840
import itertools

n = int(input())
m, a, r, c, h = [0] * 5
for i in range(n):
    s = input()
    if s[0] == "M": m += 1
    if s[0] == "A": a += 1
    if s[0] == "R": r += 1
    if s[0] == "C": c += 1
    if s[0] == "H": h += 1
x = [m, a, r, c, h]
y = ["M", "A", "R", "C", "H"]
ans = 0
for i in itertools.combinations(x, 3):
    ans += i[0] * i[1] * i[2]
print(ans)

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

int main() {
  int n;
  cin>>n;
  map<int, int> a;
  for (int i=0; i<n; i++) {
    int ai;
    cin>>ai;
    ++a[ai];
  }
  int ans = 0;
  int cnt_2 = 0;
  for (auto ai: a) {
    int v = ai.second;
    if (v % 2 == 1) {
      ++ans;
    } else {
      ++cnt_2;
    }
  }
  if (cnt_2 % 2 == 0) {
    cout<<ans + cnt_2<<endl;
  } else {
    cout<<ans + cnt_2 - 1<<endl;
  }
}

Measured memory_bytes: 4992
#include <stdio.h>
int main(void){
    int a, b;
    int slot;
    int count = 1;
    scanf("%d %d", &a, &b);
    slot = a;

    while(slot < b){
        slot += a;
        slot--;
        count++;
    }
    if(b <= 1){
        count = 0;
    }

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

    return 0;
}

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

int main()
{
    int n, k, x;
    cin >> n >> k;
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        ans += min(x * 2, abs(x - k) * 2);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3572
import java.util.*;

class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
      	long a = sc.nextLong();
      	long b = sc.nextLong();
      	long c = sc.nextLong();
      	long d = sc.nextLong();
      	sc.close();
      
		long min = count(a - 1, c, d);
		long max = count(b, c, d);
      	System.out.println(max - min);
    }
  
  	public static long count(long x, long c, long d) {
    	return (x - ((x / c) + (x / d) - (x / (lcm(c, d)))));
    }
  
  	public static long lcm(long a, long b) {
    	long g = gcd(a, b);
      	return (a * b) / g;
    }
  
  	public static long gcd(long a, long b) {
    	if (a > b) {
			long tmp = a;
          	a = b;
          	b = tmp;
        }
      	if (a == 0) return b;
      	return gcd(b % a, a);
    }
}

Measured memory_bytes: 25172
#include <stdio.h>
#include <stdlib.h>
#define INF 1000000000
int N,M,R,ans;
int r[9];
int visited[9]={0};
int d[201][201]={0};

int min(int x,int y){return x<y?x:y;}

void dfs(int n,int last,int dist){
	if(n==R+1){
		ans = min(ans,dist);
		return;
	}
	for(int i=1;i<=R;i++){
		if(visited[i]==0){
			visited[i]=1;
			if(last==-1)dfs(n+1,i,0);
			else dfs(n+1,i,dist+d[r[last]][r[i]]);
			visited[i]=0;
		}
	}
}

int main(void){
	scanf("%d%d%d",&N,&M,&R);
	for(int i=1;i<=R;i++)scanf("%d",&r[i]);
	for(int i=1;i<=N;i++){
		for(int j=1;j<=N;j++){
			if(j!=i)d[i][j] = INF;
		}
	}
	for(int i=1;i<=M;i++){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		if(d[a][b]>c)d[a][b] = d[b][a] = c;
	}
	for(int k=1;k<=N;k++){
		for(int i=1;i<=N;i++){
			for(int j=1;j<=N;j++){
				d[i][j] = min(d[i][k]+d[k][j],d[i][j]);
			}
		}
	}
	ans = INF;
	dfs(1,-1,0);
	printf("%d",ans);
	
	
	return 0;
}

Measured memory_bytes: 256
def solve():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))
    V *= 2
    ans = 0
    for i in range(N+1):
        for j in range(N-1,2*N):
            num = j-i+1
            if num>K or num>N or num == 0:
                continue
            lis = V[i:j+1]
            lis.sort()
            margin = K-num
            m = sum(lis)
            k = 0
            while k < margin and k < num and lis[k]<0 :
                m -= lis[k]
                k += 1
            ans = max(ans,m)
    return ans
print(solve())

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

int main()
{
    ll n, ans = 1, a[1000] = {0};
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        int k = i;
        for (int j = 2; j <= i; j++)
        {
            if (k % j == 0)
            {
                while (k % j == 0)
                {
                    a[j - 1]++;
                    k /= j;
                }
            }
        }
    }
    for (int i = 0; i < 1000; i++)
    {
        ans *= (a[i] + 1);
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from sys import stdin
import numpy as np
# import math
# import random
# import fractions
# import sys
# sys.setrecursionlimit(100000)
# N = int(stdin.readline().rstrip().split()[0])
# A = [int(x) for x in stdin.readline().rstrip().split()]
# N, X = [int(x) for x in stdin.readline().rstrip().split()]
# S = stdin.readline().rstrip().split()[0]
N, M = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]
A.sort()
BC = []
ans = []
for i in range(M):
  b, c = [int(x) for x in stdin.readline().rstrip().split()]
  BC.append([c, b])
  
BC.sort()
count = N
ans = 0
# 1:b
# 0:c
while(True):
  if len(A)==0:
    A=[0]
  if len(BC)==0:
    BC = [[0,0]]
  if BC[-1][0] > A[-1]:
    count -= BC[-1][1]
    if count<0:
      ans += BC[-1][0]*(BC[-1][1]+count)
      break
    else:
      ans += BC[-1][0]*BC[-1][1]
    BC.pop()
  else:
    count -= 1
    if count<0:
      ans  += A[-1]*(1+count)
      break
    else:
      ans += A[-1]
    A.pop()
print(ans)
  

  

Measured memory_bytes: 32976
#include <cstdlib>
#include <sstream>
#include <iostream>
#include <map>
#include <vector>
#include <string>

using namespace std;

void selection_sort(vector<int> &list, vector<int> &order) {
  for (int i = 0; i < list.size(); ++i) {
    int mini = i;
    for (int j = i + 1; j < list.size(); ++j) {
      if (list[j] < list[mini]) {
        mini = j;
      }
    }
    if (mini != i) {
      int tmp = list[mini];
      list[mini] = list[i];
      list[i] = tmp;
      int tmp_order = order[mini];
      order[mini] = order[i];
      order[i] = tmp_order;
    }
  }
}

void bubble_sort(vector<int> &list, vector<int> &order) {
  for (int i = 0; i < list.size(); ++i) {
    for (int j = list.size() - 1; j > i; --j) {
      if (list[j] < list[j-1]) {
        int tmp = list[j];
        list[j] = list[j-1];
        list[j-1] = tmp;
        int tmp_order = order[j];
        order[j] = order[j-1];
        order[j-1] = tmp_order;
      }
    }
  }
}

int main() {
  int N;
  cin >> N;
  cin.ignore();
  string str;
  getline(cin, str);
  string tmp;
  vector<string> v;
  istringstream istr(str);
  while (getline(istr, tmp, ' ')) {
    v.push_back(tmp);
  }
  vector<pair<string, int>> cards;
  for (auto elem : v) {
    pair<string, int> card;
    card.first = elem;
    card.second = atoi(&elem.at(1));
    cards.push_back(card);
  }
  vector<int> bubble_list;
  vector<int> selection_list;
  for (auto card : cards) {
    bubble_list.push_back(card.second);
    selection_list.push_back(card.second);
  }
  vector<int> selection_order;
  vector<int> bubble_order;
  for (int i = 0; i < cards.size(); ++i) {
    bubble_order.push_back(i);
    selection_order.push_back(i);
  }
  bubble_sort(bubble_list, bubble_order);
  selection_sort(selection_list, selection_order);
  for (int i = 0; i < bubble_list.size() - 1; ++i) {
    cout << cards[bubble_order[i]].first << " ";
  }
  cout << cards[bubble_order.back()].first << endl;
  cout << "Stable" << endl;
  for (int i = 0; i < selection_list.size() - 1; ++i) {
    cout << cards[selection_order[i]].first << " ";
  }
  cout << cards[selection_order.back()].first << endl;
  if (selection_order == bubble_order) {
    cout << "Stable" << endl;
  } else {
    cout << "Not stable" << endl;
  }
}

Measured memory_bytes: 1260
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
 
 
public class Main {
 
    private static final int BIG_NUM  = 2000000000;
 
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        long sum = 0;
        int minimum = BIG_NUM,maximum = -BIG_NUM;
 
        try {
 
            int N = Integer.parseInt(br.readLine());
 
            String first[] = br.readLine().split("[\\s]+");
            int array[] = new int[first.length];
 
            for(int i = 0; i < first.length; i++){
 
                array[i] = Integer.parseInt(first[i]);
                minimum = Math.min(minimum, array[i]);
                maximum = Math.max(maximum, array[i]);
                sum += array[i];
            }
 
            System.out.printf("%d %d %d\n",minimum,maximum,sum);
 
        } catch (IOException e) {
            e.printStackTrace();
        }
 
    }
}


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

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
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; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007

int main(){

    string input;
    cin >> input;
    int n = input.length();

    uset<string> strSet;

    string s[2] = {"","A"};

    for(int i=0;i<(1<<4);i++){
        strSet.insert(s[(i>>0)&1]+"KIH"+s[(i>>1)&1]+"B"+s[(i>>2)&1]+"R"+s[(i>>3)&1]);
    }


    if(strSet.find(input)!=strSet.end()){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }


    return 0;
}


Measured memory_bytes: 3524
# AtCoder
s = list(map(str, input()))
n = len(s)

for i in range(2**3):  # 2の選ぶものの個数乗
    ops = []
    for j in range(3):
        if ((i >> j) & 1):
            ops.append('+')
        else:
            ops.append('-')
    if eval(s[0]+ops[0]+s[1]+ops[1]+s[2]+ops[2]+s[3]) == 7:
        print(s[0]+ops[0]+s[1]+ops[1]+s[2]+ops[2]+s[3] + '=7')
        exit()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int main(){
  
  int i, cnt=0, cnt_=0;
  string S;
  cin>>S;
  
  for(i=0;i<3;i++){
    if(S[i]=='R'){
      cnt++;
    }else{
      cnt=0;
    }
    cnt_=max(cnt, cnt_);
  }
  
  cout<<cnt_<<endl;
  return 0;
}

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

int main() {
  int n, z, w;
  cin >> n >> z >> w;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  if (n == 1) {
    cout << abs(a[0] - w) << endl;
    return 0;
  }
  cout << max(abs(a[n - 1] - w), abs(a[n - 2] - a[n - 1])) << endl;
}


Measured memory_bytes: 256
def mp(): return map(int, input().split())
def lmp(): return list(map(int, input().split()))

n = int(input())
a = lmp()
a.sort()
ans = 1
for i in range(n):
    ans *= a[i]
    if ans > int(1e18):
        print(-1)
        exit()
print(ans)


Measured memory_bytes: 88828
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.rbegin(),a.rend())
#define lb(a,b) lower_bound(a.begin(),a.end(),b)
#define ub(a,b) upper_bound(a.begin(),a.end(),b)
#define MOD ((int)(1000000007))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double
#define sqrt sqrtl
#define cbrt cbrtl
typedef vector<int> vi;
typedef vector<float> vf;
typedef pair<float,int> fi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<fi> vfi;
typedef vector<vi> vvi;
typedef vector<vf> vvf;
typedef vector<vii> vvii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef priority_queue<fi> pqfi;
typedef priority_queue <int, vector<int>, greater<int> > rpqi; 
typedef priority_queue <ii, vector<ii>, greater<ii> > rpqii; 
typedef priority_queue <fi, vector<fi>, greater<fi> > rpqfi; 

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.rbegin(),a.rend())
#define lb(a,b) lower_bound(a.begin(),a.end(),b)
#define ub(a,b) upper_bound(a.begin(),a.end(),b)
#define MOD ((int)(1000000007))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double
#define sqrt sqrtl
#define cbrt cbrtl
typedef vector<int> vi;
typedef vector<float> vf;
typedef pair<float,int> fi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<fi> vfi;
typedef vector<vi> vvi;
typedef vector<vf> vvf;
typedef vector<vii> vvii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef priority_queue<fi> pqfi;
typedef priority_queue <int, vector<int>, greater<int> > rpqi; 
typedef priority_queue <ii, vector<ii>, greater<ii> > rpqii; 
typedef priority_queue <fi, vector<fi>, greater<fi> > rpqfi; 





int32_t main()
{
	IOS
	int n,d;cin>>n>>d;
	cout<<(n+2*d)/(2*d+1)<<endl;
	
	
}


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

using namespace std;

int main()
{
	int a[3][3],i,j,row1,row2,col1,col2;
	for(i=0;i<3;i++)
	  {   
	  	  for(j=0;j<3;j++)
	  	    {
	  	    	cin>>a[i][j];
	  	    }
	  	    
	  }
	  
	  row1=a[0][0]-a[0][1];
	  row2=a[0][1]-a[0][2];
	  col1=a[0][0]-a[1][0];
	  col2=a[1][0]-a[2][0];
	  if(row1==a[1][0]-a[1][1] && row1==a[2][0]-a[2][1])
	     {
	     	if(row2==a[1][1]-a[1][2] && row2==a[2][1]-a[2][2])
	     	  {
	     	  	  if(col1==a[0][1]-a[1][1] && col1==a[0][2]-a[1][2])
	     	  	     {
	    				if(col2==a[1][1]-a[2][1] && col2==a[1][2]-a[2][2])
	    				   cout<<"Yes";
	    				else
							 cout<<"No"<<" ";   				  
	     	  	     }
	     	  	   else
	     	  	     {
	     	  	     	 cout<<"No"<<" ";
	     	  	     }
	     	  }
	     	else
	     	   cout<<"No"<<" ";
	     }
	else     
	  cout<<"No"<<" ";    
	return 0;
}

Measured memory_bytes: 256
#include<iostream> 
#include<string> 
#include<vector> 
#include<algorithm> 
#include<cmath>
#include<set>
#include<utility>

using namespace std;

int main()
{
	string s;
	cin >> s;
	string a = "";
	if (s.at(5) != 0)
	{


		a += s.at(5);
		a += s.at(6);

		
	}
	else
	{
		a += s.at(6);
	}
	int q = stoi(a);
	if (q <=4)
	{
		cout << "Heisei" << endl;
	}
	else if (q > 4)
	{
		cout << "TBD" << endl;
	}
	


}


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

int main(){
    ll mod=1e9+7;
    vector<ll> a;
    int n;cin>>n;
    for(int i=0;i<n;i++){
        ll b;cin>>b;
        a.push_back(b%mod);
    }
    ll dp[n+1];
    ll sum=(a[0]+a[1])%mod;
    for(int i=0;i<=n;i++)dp[i]=0;
    dp[1]=a[0]*a[1]%mod;
    for(int i=1;i<n-1;i++){
        dp[i+1]=dp[i]+a[i+1]*sum%mod;
        dp[i+1]%=mod;
        sum+=a[i+1];
        sum%=mod;
    }
    cout <<dp[n-1];

}

Measured memory_bytes: 6392
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;
char kisuu[] = {'R', 'U', 'D'};
char guusuu[] = {'L', 'U', 'D'};
int main() {
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    bool flag = false;
    for (int j = 0; j < 3; j++) {
      if (i % 2 == 0) {
        if (kisuu[j] == s[i]) {
          flag = true;
          break;
        }
      } else {
        if (guusuu[j] == s[i]) {
          flag = true;
          break;
        }
      }
    }
    if (!flag) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 105;
int N, X,ans;
int dop[maxn];
int main()
{
	while (cin >> N >> X) {
		ans = 0; //init
		for (int i = 0; i < N; i++) {
			cin >> dop[i];
			X -= dop[i];
			ans++;
		}	
		sort(dop, dop + N);
		ans += X / dop[0];
		cout << ans << endl;
	}
	return 0;
}

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

ll x,y;

int main(){
    cin >> x >> y;

    
    for(long long i = 0; i <= x; i++){
        if(2 * i + 4 * (x-i) == y){
            put("Yes");
            return 0;
        }
    }
    put("No");
}

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

int main() {
    int N; cin >> N;
    vector<ll> A(N);
    REP(i, 0, N) cin >> A[i];

    vector<int> cnt(60, 0);
    REP(i, 0, N) {
        REP(j, 0, 60) {
            if (A[i] & (1LL << j)) cnt[j]++;
        }
    }

    ll ans = 0;;
    REP(i, 0, 60) {
        ans += (((ll)(N - cnt[i]) * cnt[i] % MOD) * ((1LL << i) % MOD)) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> s(m, vector<int>(n+1, 0));
    vector<int> dp(1<<m, n+1), v(n);
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        cin >> v[i];
        v[i]--;
        s[v[i]][i+1]++;
    }
    for(int i = 0; i < m; i++){
        for(int j = 1; j <= n; j++){
            s[i][j] += s[i][j-1];
        }
    }
    for(int t = 1; t < 1<<m; t++){
        for(int j = 0; j < m; j++){
            if(((t>>j)&1) == 0)   continue;
            int cnt = 0;
            for(int k = 0; k < m; k++){
                if(j == k)  continue;
                if((t>>k)&1)    cnt += s[k][n];
            }
            dp[t] = min(dp[t], dp[t-(1<<j)] + s[j][n]-(s[j][cnt+s[j][n]]-s[j][cnt]));
        }
    }
    cout << dp[(1<<m)-1] << endl;
    return 0;
}


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

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

    int A, B, C; cin>>A>>B>>C;
    int ans=0;
    while (A%2==0 && B%2==0 && C%2==0){
        A = A/2;
        B = B/2;
        C = C/2;
        ans++;
    }
    int par=A%2+B%2+C%2;
    if(ans!=0&&(par==0||par==3)){
        ans++;
    }
    if(ans!=0&&A==B&&B==C){
        ans = -1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc112/tasks/abc112_c

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))

int main() {
    string s;
    int n, h, h_max;
    vector<int> x, y, z;
    cin >> n;
    x.resize(n);
    y.resize(n);
    z.resize(n);

    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> z[i];
    }

    int x_min = *std::min_element(x.begin(), x.end());
    int x_max = *std::max_element(x.begin(), x.end());
    int y_min = *std::min_element(y.begin(), y.end());
    int y_max = *std::max_element(y.begin(), y.end());

    for (int i = x_min; i <= x_max; i++) {
        for (int j = y_min; j <= y_max; j++) {
            bool success = true;
            h = -1;
            h_max = INT32_MAX;
            for (int k = 0; k < n && success; k++) {
                // 中心からの距離
                int d = abs(i - x[k]) + abs(j - y[k]);
                // 高さが0より大きい場合
                if (z[k] > 0) {
                    int h1 = d + z[k];
                    if (h == -1) {
                        h = h1;
                    } else if (h != h1) {
                        success = false;
                    }
                } else {
                    h_max = min(d, h_max);
                }
            }
            if (success && h <= h_max) {
                cout << i << " " << j << " " << h << endl;
                return 0;
            }
        }
    }

    return 1;
}


Measured memory_bytes: 256
function main(input){
  input = input.split("\n");
  var n = parseInt(input[0]);

  var a = [];

  for (var i = 0; i < n; i++) {
    a[i] = {
      index : i,
      num : parseInt(input[i+1])
    };
  }

  a.sort(function(a,b){
    if(a.num>b.num) return -1;
    if(a.num<b.num) return 1;
    return 0;
  })

  max_index = a[0].index;
  max_num = a[0].num;

  for (var i = 0; i < n; i++) {
    if (i !== max_index) {
      console.log(max_num);
    }else {
      console.log(a[1].num);
    }
  }


}
 
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 64848
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}



signed main(){
	int n,m,q	; cin>>n>>m>>q;
	ll x[n+5][n+5]; memset(x,0L,sizeof(x));
	rep(i,m){
		int l,r; cin>>l>>r;
		x[l][r]++;
	}
	// reps(i,n){
	// 	reps(j,n) cerr<<x[i][j]<<' ';
	// 	cerr<<endl;
	// }
	ll w[n+5][n+5]; memset(w,0L,sizeof(w));
	reps(i,n){
		reps(j,n){
			if(j==1) w[i][j]=x[i][j];
			else w[i][j]=w[i][j-1]+x[i][j];
			// cerr<<w[i][j]<<' ';
		}
		// cerr<<endl;
	}
	rep(i,q){
		int a,b; cin>>a>>b;
		ll ret = 0;
		for(int i=a;i<=b;i++){
			if(a!=1) ret+=w[i][b]-w[i][a-1];
			else ret+=w[i][b];
			// for(int j=i;j<=b;j++){
			// 	ret+=x[i][j];
			// }
		}
		cout<<ret<<endl;
	}
	return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimization ("O2")
#pragma GCC target("popcnt")
#pragma GCC target ("avx2")
using namespace std;

int main(){
	int a,b,c,k,ans=0;
	cin >> a >> b >> c >> k;
	if(k >= a){
		k -= a;
		ans += a;
	}else{
		ans += k;
		k = 0;
	}
	if(k >= b){
		k -= b;
	}else{
		k = 0;
	}
	if(k >= c){
		k -= c;
		ans -= c;
	}else{
		ans -= k;
		k = 0;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3596
N = input()
A_list = list(map(int, input().split(' ')))
 
a_2 = [a for a in A_list if a%2==0]
flg = False
for a in a_2:
    if a % 3 ==0 or a % 5 ==0:
        continue
    else:
        print('DENIED')
        flg = True
        break
if flg == False:
    print('APPROVED')

Measured memory_bytes: 3064
#include <cstdio>
using namespace std;
typedef long long ll;
const int maxn=200010,mod=1e9+7;
template <typename Tp> inline int getmin(Tp &x,Tp y){return y<x?x=y,1:0;}
template <typename Tp> inline int getmax(Tp &x,Tp y){return y>x?x=y,1:0;}
template <typename Tp> inline void read(Tp &x)
{
    x=0;int f=0;char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') f=1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    if(f) x=-x;
}
int n,c[maxn],lst[maxn],head[maxn],f[maxn];
int pls(int x,int y){return x+y>=mod?x+y-mod:x+y;}
int main()
{
	read(n);
	for(int i=1;i<=n;i++)
	{
		read(c[i]);
		lst[i]=head[c[i]];
		head[c[i]]=i;
	}
	f[0]=1;
	for(int i=1;i<=n;i++)
	{
		f[i]=f[i-1];
		if(lst[i]&&lst[i]!=i-1) f[i]=pls(f[i],f[lst[i]]);
	}
	printf("%d\n",f[n]);
	return 0;
}

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

int main(void){
    int n,a,b;
    cin >> n >> a >> b;
    int p[n],num[3] = {};
    for(int i = 0;i < n;i++)cin >> p[i];
    for(int i = 0;i < n;i++){
        if(p[i] >= b+1)num[1]++;
        else if(p[i] >= a+1 && p[i] <= b)num[2]++;
        else num[0]++;
    }
    sort(num,num+3);
    cout << num[0];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define Pr(a) (#a)<<"="<<(a)<<" "
#define pr1(a) cerr<<Pr(a)<<endl
#define pr2(a,b) cerr<<Pr(a)<<Pr(b)<<endl
#define pr3(a,b,c) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<endl
#define pr4(a,b,c,d) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<endl
#define pr5(a,b,c,d,e) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<endl
#define pr6(a,b,c,d,e,f) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<Pr(f)<<endl
#define int long long
#define double long double
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  int n;
  cin>>n;
  vector<int> A(n);
  cin>>A;

  int q;
  cin>>q;
  while(q--){
    int b, m, e;
    cin>>b>>m>>e;
    rotate(A.begin() + b, A.begin() + m, A.begin() + e);
  }
  cout<<A<<endl;
  return 0;
}



Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int p[100];
	for(int i=0;i<n;i++){
		cin>>p[i];
	}
	int ans=0;
	for(int i=1;i<n-1;i++){
		if((p[i]<p[i-1]&&p[i]>p[i+1])||(p[i]>p[i-1]&&p[i]<p[i+1])){
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int mod;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n >> mod;
    vector<int> a(n), sum(n+1);
    rep(i, n) {
        cin >> a[i];
        sum[i+1] = sum[i] + a[i] - 1;
        sum[i+1] %= mod;
    }

    //rep(i, n) cout << sum[i+1] << (i == n-1?'\n':' ');

    map<int, int> mp;
    ll ans = 0;
    vector<int> check(n);
    rep(i, n) {
        check[i] = sum[i];
        mp[sum[i]]++;
        if(i >= mod-1) {
            mp[check[i-mod+1]]--;
        }
        ans += mp[sum[i+1]];
    }

    cout << ans << endl;
}

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

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

	map<int, int64_t> num;

	for (int i = 0; i < N; i++) {
		int a, b;
		cin >> a >> b;

		num[a] += b;
	}

	int64_t mid_sum = 0;
	for (auto i = num.begin(); i != num.end(); i++) {
		mid_sum += i->second;

		if (mid_sum >= K) {
			cout << i->first << endl;
			break;
		}
	}
}
		


Measured memory_bytes: 4224
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <fstream>
#include <sstream>

using namespace std;

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

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

	long long int n, m;

	int board[1001][1001] = { 0, };

	cin >> n >> m;

	if (n == 1 && m == 1)
	{
		cout << 1 << '\n';
	}
	else if (n == 1)
	{
		cout << m - 2 << '\n';
	}
	else if (m == 1)
	{
		cout << n - 2 << '\n';
	}
	else
	{
		cout << (n - 2)*(m - 2) << '\n';
	}

	/*
	memset(board, 0, sizeof(board));
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			board[i][j] = 1 - board[i][j];
			for (int k = 0; k < 8; k++)
			{
				int y = i + dy[k];
				int x = j + dx[k];
				if (y < 0 || y >= n || x < 0 || x >= m)
				{
					continue;
				}
					board[y][x] = 1 - board[y][x];
			}
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cout << board[i][j] << ' ';
		}
		cout << '\n';
	}
	*/

	return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 11451419194545;

int main() {

    string N; cin >> N;
    string S = N;
    reverse(S.begin(), S.end());

    ll ans = 0;
    for(ll i = 0; i < N.length(); i++){
        if(N[i] != S[i]){
            ans++;
        }
    }
    cout << ans / 2 << endl;
}

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

int main()
{
    int N,i,ans;
    scanf("%d",&N);

    for( i=N;;i++ ){
        if( i%2 == 0 && i%N == 0 ){
            ans = i;
            break;
        }
    }
    printf("%d\n",ans);


    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
	int n, x, i, j, k, num = 0;

	while (1)
	{
		scanf("%d %d", &n, &x);

		if (n == 0 && x == 0)
		{
			break;
		}
		num = 0;

		for (i = 1; i <= n; i++) {
			for (j = i + 1; j <= n; j++) {
				for (k = j + 1; k <= n; k++) {
					if ((i + j + k) == x) {
						num++;
					}
				}
			}
		}

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

	}
	return 0;
}


Measured memory_bytes: 2140