akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long int
#define ull long long int
#define float long double
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ALL(a) a.begin(),a.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define DEBUG(x) cout<<" x is "<<x<<"\n"
using namespace std;

//inline size_t key( int a,int b,int c,int d) {return a*b*c*d-7707;}
//unordered_map<size_t,bool >vismap;


/*int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; */  // 2 Direction
/*int dx[] = {1,0} , dy[] = {0,1};     */  // 4 Direction
/* int dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; */ // 8 Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; */ // Knight Direction
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; */ // Hexagonal Direction
/*
struct myClass{

    int sum;
    int x;
    int y;

    bool operator < (myClass t) const{
        return sum<t.sum;
    }

};
 */
/*
ll fast_expo(ll a,ll b,ll m){
	if(b==0){
		return 1;
	}
	else{
		ll x=fast_expo(a,b/2,m);
		x*=x;
		x%=m;
		if(b%2==0){
			return x;
		}
		else{
			return (x*a)%m;
		}
	}
}

ll inverse(ll a,ll m){
	return fast_expo(a,m-2,m);
}
*/

/*

void prime_precomputation(vector<ll> &primes,int n){
	vector<int> v(n+10,0);
	v[0]=1;v[1]=1;
	for(int i=2;i*i<=n;i++){
		if(v[i]==0){
			for(int j=2*i;j<=n;j+=i){
				v[j]=1;
			}
		}
	}


}

*/

/*
void FTdfs(int src,vector<vector<int> > &adj, vector<int > & vis,stack<int> &Ftime){
	vis[src]=1;
	for(int i=0;i<adj[src].size();i++){
		int x=adj[src][i];
		if(vis[x]==0){
			FTdfs(x,adj,vis,Ftime);
		}
	}
	Ftime.push(src);
}

void dfs(int src,vector<vector<int> > &adj,vector<int> &vis ,int sc){
	vis[src]=1;
	um[src]=sc;
	scc[sc].pb(src);
	for(int  i=0;i<adj[src].size();i++){
		int x=adj[src][i];
		if(vis[x]==0){
			dfs(x,adj,vis,sc);
		}
	}
}

*/

/*

vector<pair<int,int> > compress(vector<int> &v){
	sort(v.begin(),v.end());
	int n=v.size();
	int cnt=0;
	vector<pair<int,int> > ret;
	for (int i=0;i<n;i++){
		if (i>0&&ar[i]!=ar[i-1]){
			ret.push_back(make_pair(ar[i-1],cnt));
			cnt=0;
		}
		cnt++;
	}
	ret.push_back(make_pair(ar[n-1],cnt));
	return ret;
}






*/

int main(){
	 fast
    cout<<fixed;
    cout<<setprecision(10);
    int q;
   // cin>>q;
    q=1;
    while(q--){
     ll n;
      cin>>n;
      cout<<n*2/__gcd(n,2ll)<<"\n";


    }
	return 0;
}


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

int main() {
  string s;
  cin >> s;
  int q;
  cin >> q;
  string t;
  rep(qi, q){
    int ty;
    cin >> ty;
    if(ty == 1) {
      swap(s, t);
    }
    else {
      int f; char c;
      cin >> f; cin >> c;
      if(f == 1){
        t += c;
      }
      else {
        s += c;
      }
    }
  }
  reverse(t.begin(), t.end());
  t += s;
  
  cout << t << endl;
  return 0;
}


Measured memory_bytes: 1128
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::collections::BTreeMap;

fn main() {
    input! {
        n: usize,
        k: usize,
        td: [(usize1, i64); n],
    }

    let mut mm = BTreeMap::new();
    for &(t, d) in td.iter() {
        mm.entry(t).or_insert(vec![]).push(d);
    }

    let mut bests = vec![];
    let mut rests: Vec<i64> = vec![];

    for (_, ref mut v) in mm.iter_mut() {
        if v.len() >= 1 {
            v.sort();
            v.reverse();
            bests.push(v[0]);
            rests.extend(v[1..].iter());
        }
    }

    bests.sort();
    bests.reverse();
    rests.sort();
    rests.reverse();
    let mut racc = vec![0; rests.len() + 1];

    for i in 0..rests.len() {
        racc[i + 1] = racc[i] + rests[i];
    }

    let mut ans = 0;
    let mut bacc = 0;
    for (i, &b) in bests.iter().enumerate() {
        let i = i + 1;
        bacc += b;
        if i <= k && k - i < racc.len() {
            let cur = (i as i64).pow(2) + bacc + racc[k - i];
            ans = std::cmp::max(ans, cur);
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 16636
#include "bits/stdc++.h"
using namespace std;

typedef long long int ll;
const ll N = 1000010;

vector <ll> v1[N];
ll dis[N];

int main()
{
    ll  n, m; cin >> n >> m;
    while (m--){
        ll u,v; cin >> u >> v;
        v1[u].push_back(v);
        v1[v].push_back(u);
    }

    queue <ll> q1;
    q1.push(1);
    memset(dis, -1 , sizeof dis);
    dis[1] = 0;
    while (!q1.empty()){
        ll u = q1.front();
        q1.pop();
        for (int i = 0; i < v1[u].size(); i ++){
            ll  v = v1[u][i];
            if (dis[v] == -1){
                dis[v] = dis[u] + 1;
                q1.push(v);
            }
        }
    }

    if (dis[n] <= 2 && dis[n] != -1) cout << "POSSIBLE\n";
    else cout << "IMPOSSIBLE\n";

    return 0;
}


Measured memory_bytes: 40168
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;
	VAR(int, n);
	FOR(i, n, n * 100) {
		bool ok = true;
		REP(j, to_string(i).size() - 1) {
			ok &= (to_string(i)[j + 1] == to_string(i)[j]);
		}
		if (ok) {
			OUT(i)BR;
			break;
		}
	}
  
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for(int i=0; i<n; i++) cin >> p[i];
  
  int ans=0;
  for(int i=1; i<n-1; i++) {
    if(p[i-1]<p[i] && p[i]<p[i+1] ||
      p[i-1]>p[i] && p[i]>p[i+1]) ++ans;
  }
  cout << ans <<endl;
}

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

int main() {
  
  int k;
  string s;
  cin >> k >> s;
  
  if(k>=s.size()){
    cout << s << endl;
  }
  else{
    for(int i=0; i<k; i++){
      cout << s.at(i);
    }
    cout << "..." << endl;
  }
    
}


Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
template<typename T> ostream& operator<< (ostream& s, vector<T> &P)
{ for(int i=0; i<P.size(); i++){if(i){s<<" ";} s<<P[i];} return s; }

struct RSQ{
    int N;
    vector<int> Tree;
    RSQ(int size){
        N=1;
        while(N<size) N*=2;
        Tree.resize(2*N-1, 0);
    }

    void update(int pos, int val){
        pos += N-1;
        Tree[pos] += val;
        while(pos>0){
            pos = (pos-1)/2;
            Tree[pos] = Tree[pos*2+1] + Tree[pos*2+2];
        }
    }

    int getSum(int a, int b, int k=0, int l=0, int r=-1){
        if(r<0) r = N;
        if(r<=a or b<=l) return 0;
        if(a<=l and r<=b) return Tree[k];
        else{
            int lval = getSum(a, b, 2*k+1, l, (l+r)/2);
            int rval = getSum(a, b, 2*k+2, (l+r)/2, r);
            return lval + rval;
        }
    }
};

int main(){
    int N, Q;
    cin>>N>>Q;
    RSQ rsq(N);
    for(int i=0; i<Q; i++){
        int c, x, y;
        cin>>c>>x>>y;
        if(c==0){
            x--;
            rsq.update(x, y);
        }
        else {
            x--, y--;
            cout << rsq.getSum(x, y+1) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3824
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

int main() {
    string s;
    cin >> s;
    string s1 = s.substr(0,(s.size()-1)/2);
    string s2 = s.substr((s.size()+3)/2-1,(s.size()-1)/2);
    string sr = s, s1r = s1, s2r = s2;
    reverse(sr.begin(),sr.end());
    reverse(s1r.begin(),s1r.end());
    reverse(s2r.begin(),s2r.end());
    if (s == sr && s1 == s1r && s2 == s2r) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

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

using namespace std;

const int N = 2e5 + 5;
const int M = 4e3 + 5;
const int _C = 2000;
const int P = 1e9 + 7;

typedef long long LL;

#define f(x, y) F[(x) + _C + 1][(y) + _C + 1]
#define m(x, y) wap[(x) + _C + 1][(y) + _C + 1]
#define C(x, y) ((x >= y && y >= 0) ? (frac[x] * inv_frac[(x) - (y)] % P * inv_frac[y] % P) : 0)

int wap[M][M], n;
int F[M][M], ans;
LL frac[N], inv_frac[N];

inline LL ksm(LL base, LL x) {
    LL res = 1;
    while(x) {
        if(x & 1) res *= base, res %= P;
        x >>= 1, base *= base, base %= P;
    }
    return res;
}

void init() {
    int a, b;
    scanf("%d", &n);
    frac[0] = 1;
    for(int i = 1; i < N; i++) frac[i] = frac[i - 1] * i % P;
    inv_frac[N - 1] = ksm(frac[N - 1], P - 2);
    for(int i = N - 2; i >= 0; i--) inv_frac[i] = inv_frac[i + 1] * (i + 1) % P;
    for(int i = 1; i <= n; i++) {
        scanf("%d%d", &a, &b);
        ans += P - C(a + a + b + b, a + a);
        ans %= P;
        m(-a, -b) ++;
        f(-a, -b) ++;
        m(a, b) --;
    }
    for(int i = -_C; i <= _C; i++) {
        for(int j = -_C; j <= _C; j++) {
            f(i, j) += (f(i - 1, j) + f(i, j - 1)) % P;
            f(i, j) %= P;
            //if(f(i, j)) printf("f(%d, %d) = %lld\n", i, j, f(i, j));
            if(m(i, j) < 0) ans += (LL)-m(i, j) * f(i, j) % P, ans %= P;
        }
    }
    if(ans % 2 == 0) ans /= 2;
    else ans += P, ans /= 2;
    cout << ans << endl;
}

int main() {
    init();
    return 0;
}


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

char s[105],t[105];
int l;
int main()
{
	cin>>s>>t;
	l=strlen(s);
	for(int i=0;i<l;i++)
	for(int j=0,z=i;j<l;j++)
	{
		if(t[z]!=s[j])
		break;
		z++;
		if(z==l) z=0;
		if(j==l-1)
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

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

int main() {
  
  int n, k, x, y;
  cin >> n >> k >> x >> y;
  
  int ans = min(n,k)*x;
  
  if (n > k) ans += (n-k)*y;
  
  cout << ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mem(a,v) memset(a,v,sizeof a)
#define ll long long
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define max3(x,y,z) max(x,max(y,z))
#define min3(x,y,z) min(x,min(y,z))
#define f first
#define s second
#define fr(i,n) for(int j=i;j<n;j++)
#define rev(a) reverse(a.begin(),a.end())
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lb(a,v) lower_bound(all(a),v)
#define ub(a,v) upper_bound(all(a),v)
#define ins(v) insert(v)
#define pb(v) push_back(v)
#define sz(x) (int)(x).size()
#define MOD 1000000007
#define sf1(a) scanf("%d",&a)
#define sf2(a,b) scanf("%d %d",&a,&b)
#define sf3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sf4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
using namespace std;
int main() {
	int n,x;
	ll s=0,remain=0,remain2=0;
	sf1(n);
	int arr[n+1];
	for(int i=0;i<n+1;i++)	sf1(arr[i]);
	for(int i=0;i<n;i++)
	{
		sf1(x);
		int mn=min(x,arr[i]);
		x-=mn;
		arr[i]-=mn;
		s+=mn;
		mn=min(x,arr[i+1]);
		s+=mn;
		arr[i+1]-=mn;
	}
	printf("%lld\n",s);
	return 0;
}

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

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

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[]) {
    string s;
    int k;
    cin >> k >> s;
    if (SIZE(s) <= k)
    {
        cout << s << endl;
    } else
    {
        REP(i,k)
            cout << s[i];
        cout << "..." << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>

int main(void){
    int i, j, k;
    int n, x;
    int count;
    
    while(1){
        scanf("%d %d",&n, &x);
        if(n == 0 && x == 0) break;
        count = 0;
        for(i = 1; 3 * i + 3 <= x; i++){
            for(j = i + 1; i + 2 * j + 1 <= x; j++){
                for(k = n; k > j; k--){
                    if(x == i + j + k){
                        count++;
                        break;
                    }else if(x >= i + j + k){
                        break;
                    }
                }
            }
        }
        printf("%d\n",count);
    }
    return 0;
}


Measured memory_bytes: 2060
import sys
lines = sys.stdin.readlines()
for n, line in enumerate(lines):
  if n == 0:
    A = int(line.strip())
  elif n == 1:
    B = int(line.strip())
  elif n == 2:
    C = int(line.strip())
  elif n == 3:
    X = int(line.strip())
  else:
    break

cnt = 0
for a in range(A+1):
  for b in range(B+1):
    for c in range(C+1):
      if a * 500 + b * 100 + c * 50 == X:
        cnt += 1

print(cnt)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(max(a,max(b,c))==a+b+c-max(a,max(b,c)))cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll x = 1e9 + 0.5;
  ll A, B, V, W, T;
  cin >> A >> V;
  cin >> B >> W;
  cin >> T;
  if (A > B) {
    cout << ((A - V * T <= B - W * T) ? "YES" : "NO") << endl;
  } else
    cout << ((A + V * T >= B + W * T) ? "YES" : "NO") << endl;
}

Measured memory_bytes: 3652
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define each(i, x) for (auto &&i : x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) ((int)a.size())
#define pow2(n) (n * n)
#define int ll
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using p_queue = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-8;
ll mod = static_cast<ll>(1e9 + 7);
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class F>
class FixPoint : private F {
public:
    explicit constexpr FixPoint(F &&f) : F(std::forward<F>(f)) {}
    template <class... Args>
    constexpr decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, std::forward<Args>(args)...); }
};
template <class F>
constexpr decltype(auto) funcs(F &&f) { return FixPoint<F>{std::forward<F>(f)}; }
template <class T>
std::vector<T> vecs(int n, T &&val) { return std::vector<T>(std::forward<int>(n), std::forward<T>(val)); }
template <class... Args>
decltype(auto) vecs(int n, Args &&... args) { return std::vector<decltype(vecs(std::forward<Args>(args)...))>(std::forward<int>(n), vecs(std::forward<Args>(args)...)); }
template <class V, class T>
void fill(V &x, const T &val) { x = val; }
template <class V, class T>
void fill(vector<V> &vec, const T &val) {
    for (auto &&v : vec)
        fill(v, val);
}

void solve() {
    int n;
    cin >> n;
    if (n >= 30)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

Measured memory_bytes: 3656
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
constexpr double pi=3.14159265358979;
 
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;
}
using namespace std;

void solve(){
  ll n,m,q;
  cin>>n>>m>>q;
  vector<vector<ll>>v(n,vector<ll>(n));
  rep(i,m){
    ll l,r;
    cin>>l>>r;
    l--;r--;
    v[l][r]++;
  }
  vector<vector<ll>>sum(n+1,vector<ll>(n+1));
  rep(i,n){
    rep(j,n){
      sum[i][j+1]=sum[i][j]+v[i][j];//1次元累積和でも間に合う
    }
  }
  rep(i,q){
    ll x,y;
    cin>>x>>y;
    x--;y--;
    ll ans=0;
    for(int j=x;j<=y;++j){
      ans+=sum[j][y+1]-sum[j][x];
    }
    cout<<ans<<"\n";
  }
  return;
}
 
signed main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
  cout<<fixed<<setprecision(20);
	solve();
	return 0;
}

Measured memory_bytes: 4864
import math
n = int(input())
def pos_num(l):
    l_sort = l.copy()
    l_len = len(l)
    l_sort.sort()
    if l_len == 1:
        an = 0
    else:
        #print(l_sort.index(l[0])+1)
        an = (l_sort.index(l[0]))*math.factorial(l_len-1)
    #print(an)
    return an 

    

ls = list(map(int, input().split()))
an = 0
for i in range(n-1):
    b = pos_num(ls[i:])
    an += b
    #print(an)
    

ll = list(map(int, input().split()))
bn = 0
for i in range(n-1):
    b = pos_num(ll[i:])
    bn += b
    #print(bn)

print(abs(an-bn))

Measured memory_bytes: 9020
#include <bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define mp make_pair
#define cont continue  
#define rep(i, n) for(int i = 0 ; i < (n) ; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF = 2147483646;
const double pi = 3.141592653589793;

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

  int n;
  string s;
  cin >> n;
  cin >> s;
  for(int i = 0 ; i < s.size() ; i++) {
    s[i] += n;
    if(s[i] > 'Z') {
      s[i] -= 26;
    }
  }
  cout << s << endl;
} 

Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = long.Parse(line[0]);
        var c = long.Parse(line[1]);
        var k = long.Parse(line[2]);
        var a = new int[n];
        for (int i = 0; i < n; i++) a[i] = int.Parse(Console.ReadLine().Trim());
        Array.Sort(a);
        var tcount = 0;
        var bcount = 1;
        var startmax = a[0] + k;
        for (int i = 1; i < n; i++)
        {
            if (bcount == 0) { bcount++; startmax = a[i] + k; }
            else
            {
                if (a[i] <= startmax && bcount + 1 == c) { tcount++; bcount = 0; }
                else if (a[i] <= startmax && bcount + 1 < c) bcount++;
                else { tcount++; bcount = 1; startmax = a[i] + k; }
            }
        }
        if (bcount > 0) tcount++;
        Console.WriteLine(tcount);
    }
}


Measured memory_bytes: 15328
/*
	  Author : @evenbao
	  Created : 2020 / 07 / 26
*/

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

#define pii pair<int , int>
#define mp make_pair
#define fi first
#define se second

const int MAXN = 55;
const int MAXM = 1 << 18;

int N , M , K , S , T , msk;
set < int > s , t;
int b[MAXN] , c[MAXN];
LL f[MAXN][MAXN] , g[MAXN][MAXN];

template <typename T> inline void chkmax(T &x , T y) { x = max(x , y); }
template <typename T> inline void chkmin(T &x , T y) { x = min(x , y); }
template <typename T> inline void read(T &x) {
    T f = 1; x = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
    for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
    x *= f;
}

int main() {
		
		read(N); read(K); read(S); read(T);
		for (int i = 1; i <= N; ++i) {
				int x; read(x);
				s.insert(x);
		}
		for (int i = 18; i >= 0; --i) {
				if ((S >> i & 1) && !(T >> i & 1)) {
						printf("0\n");
						return 0;
				}
				if ((S >> i & 1) && (T >> i & 1)) {
						t.clear();
						for (int x : s)
								if (x >> i & 1) 
										t.insert(x);
						s.clear();
						for (int x : t)
								s.insert(x);
				}
				if (!(S >> i & 1) && !(T >> i & 1)) {
						t.clear();
						for (int x : s) 
								if (!(x >> i & 1))
										t.insert(x);
						s.clear();
						for (int x : t)
								s.insert(x);
				}
				if (!(S >> i & 1) && (T >> i & 1)) 
						msk |= 1 << i;
		}
		for (int x : s) 
				b[++M] = x;
		for (int i = 0; i <= N; ++i) {
				f[i][0] = 1;
				for (int j = 1; j <= N; ++j)
						f[i][j] = (LL) f[i - 1][j] + f[i - 1][j - 1];
		}
		for (int i = 1; i <= N; ++i)
		for (int j = 1; j <= N; ++j)
				g[i][j] = j ? g[i][j - 1] + f[i][j] : 1;
		LL ans = 0;
		for (int now = msk; ; now = (now - 1) & msk) {
				for (int i = 1; i <= M; ++i) 
						c[i] = b[i] & now;
				sort(c + 1 , c + 1 + M); LL cur = 0;
				for (int i = 1 , j = 1; i <= M; i = j) {
						while (j <= M && c[i] == c[j]) ++j;
						cur += g[j - i][K];
				}
				if (__builtin_popcount(now) & 1) ans -= cur;
				else ans += cur;
				if (now == 0) break;
		}
		cout << ans << '\n';
	  return 0;
}



Measured memory_bytes: 3604
using namespace std; 
#include<bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define vect vector<ll>
#define maap map<ll,ll>  
#define MOD 1000000007
#define mit map::iterator
#define pii pair<ll,ll>
#define rep(i,a,b)	for(ll i=a;i< b;i++)
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
typedef  long long   int  ll;
//stringstream convert; 
  //  convert << number; 
  //  string s = convert.str();
 ll fact[500005],invfact[500005]; 
 ll power(ll x, ll y)
{
	ll z = 1;
	while(y > 0)
	{
		if(y % 2 == 1)
			z = (z*x)%MOD;
		x = (x*x)%MOD;
		y /= 2;
	}
	return z;
}
 ll inv(ll x)
{
	return power(x,MOD-2);
}
ll divide(ll x, ll y)
{
	return (x*inv(y))%MOD;
}
ll C(ll n, ll k)
{
	if(k > n) return 0;
	return divide(fact[n], (fact[n - k]*fact[k])%MOD);
}
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
bool isPrime(int n) {
 
    if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    return true;
} 
void init(){
	ll p=MOD;
	fact[0]=1;
	ll i;
	for(i=1;i<500005;i++){
		fact[i]=(i*fact[i-1])%p;
	}
	i--;
	invfact[i]=power(fact[i],p-2);
	for(i--;i>=0;i--){
		invfact[i]=(invfact[i+1]*(i+1))%p;
	}
}
ll s;
ll fun(ll a)
{
	if(a==0)
	return 0;
	return a+fun(a-1);
}
priority_queue < pair<ll,ll> , vector<pair<ll,ll> >,greater<pair<ll,ll> > > gq;

#define MAXN   10000001 
ll spf[MAXN]; 
void sieve() 
{ 
    spf[1] = 1; 
    for (ll i=2; i<MAXN; i++) 
        spf[i] = i; 
    for (ll i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
    for (ll i=3; i*i<MAXN; i++) 
    {
        if (spf[i] == i) 
        { 
            for (ll j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
set<ll> getFactorization(ll x) 
{ 
    set<ll> ret; 
    while (x != 1) 
    { 
        ret.insert(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
}
ll sm(ll n)
{
	ll i;
	ll k=0;
	while(n>0)
	{
		k=k+n%10;
		n=n/10;
	}
	return k;
}
void ghost()
{   
  	ll i=0,j=0,k=0,l=0,n,r=0,q=0,t=0,y=100000000000,m,w;
    	cin>>n>>k;
    	ll a[n];
    	ll b[n];
    	for(i=0;i<n;i++)
    	{
    		cin>>a[i]>>b[i];
    		t=t+b[i];
		}
		ll dp[n+1][t+1];
		for(i=0;i<=n;i++)
		{
			for(j=0;j<=t;j++)
			dp[i][j]=100000000000;
		}
		for(i=0;i<=n;i++)
		{
			for(j=0;j<=t;j++)
			{
				if(j==0)
				dp[i][j]=0;
				else if(i==0)
				continue;
				else if(j>=b[i-1])
					dp[i][j]=min(dp[i-1][j-b[i-1]]+a[i-1],dp[i-1][j]);
				else
					dp[i][j]=dp[i-1][j];
				}
			}
			for(i=0;i<=n;i++)
			{
		   for(j=0;j<=t;j++)
		   {
		   	if(dp[i][j]<=k)
		   	r=max(r,j);
		   }
	}
	cout<<r<<endl;
	}
signed main()
{int test=1;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
fast
//cin>>test;
while(test--)
ghost();
return 0;
}

  


Measured memory_bytes: 82388
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
//V<ll>fac,rfac;void setFac(int n,int mod){fac=rfac=V<ll>(++n);fac[0]=1;FOR(i,1,n)fac[i]=fac[i-1]*i%mod;rfac[n-1]=modInv(fac[n-1],mod);FORR(i,n-1,1)rfac[i-1]=rfac[i]*i%mod;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n, d;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> d;
  n--;
  d = d*2+1;
  cout << n/d+1 << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int>data(n+2);
  vector<int>sum(n+2);
  for(int i = 1;i <= n;i++){
    cin >> data[i];
    sum[i] = sum[i-1]+abs(data[i]-data[i-1]);
  }
  sum[n+1] = sum[n]+abs(data[n]);
  for(int i = 1;i <= n;i++){
    cout << sum[n+1]-(abs(data[i]-data[i-1])+abs(data[i]-data[i+1]))+abs(data[i-1]-data[i+1]) << endl;
  }
}


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

struct Problem {

    double P[1000][2];
    double D[1000][1000];
    double dp[1001][1001];

    void Solve() {
        UL N; scanf("%d", &N);
        rep(i, N) scanf("%lf%lf", &P[i][0], &P[i][1]);
        rep(i, N) rep(j, N) {
            double dx = P[i][0] - P[j][0];
            double dy = P[i][1] - P[j][1];
            D[i][j] = sqrt(dx * dx + dy * dy);
        }
        rep(i, N) rep(j, N) dp[i][j] = 1e10;
        dp[0][0] = 0.0;
        rep(i, N - 1) rep(j, N - 1) {
            UL tg = max(i, j) + 1;
            dp[tg][j] = min(dp[tg][j], dp[i][j] + D[i][tg]);
            dp[i][tg] = min(dp[i][tg], dp[i][j] + D[j][tg]);
        }
        double ans = 1e10;
        rep(i, N - 1) ans = min(ans, dp[i][N - 1] + D[i][N - 1]);
        rep(i, N - 1) ans = min(ans, dp[N - 1][i] + D[i][N - 1]);
        printf("%f\n", ans);
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    p->Solve();
    return 0;
}



Measured memory_bytes: 18292
import sys
from itertools import permutations, combinations
  
def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [[int(a) for a in input().split()] for _ in range(N)]

    length = 0
    possible = True
    for a in range(N):
        for b, l in enumerate(A[a]):
            for k in range(N):
                if k != a and k != b:
                    if l >  A[a][k] + A[k][b]:
                        possible = False
                        break
                    elif l ==  A[a][k] + A[k][b]:
                        break
            else: length += l
        if not possible:
            print(-1)
            break
    else: print(length // 2)
    
    return 0
  
if __name__ == "__main__":
    solve()


Measured memory_bytes: 42716
#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>;
const int INF = 1001001001;

int main() {
    string S; cin >> S;

    string ans = "Yes";

    for (int i = 0; i < S.size(); i++) {
        if (S[i] != S[S.size() - 1 - i]) {
            ans = "No";
        }
    }

    for (int j = 0; j < (S.size() - 1) / 2; j++) {
        if (S[j] != S[(S.size() - 1) / 2 - 1 - j]) {
            ans = "No";
        }
    }

    for (int k = (S.size() + 3) / 2 - 1; k < S.size(); k++) {
        if (S[k] != S[S.size() + (S.size() + 3) / 2 - 1 - k - 1]) {
            ans = "No";
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N, K ;
    cin >> N >> K;
    
    vector<ll> A;
    
    rep(i,N){
        ll inp;
        cin >> inp;
        if(inp == 0){
            K--;
            continue;
        }
        A.pb(inp);
    }
    K++;
    A.pb(0);
    sort(all(A));
    
    ll l = 0;
    ll r = K-1;
    
    ll ans = 1e9;
    while(r != A.size()){
        if(A[l] < 0 && A[r] < 0){
            l++, r++;
            continue;
        }
        if(A[l] > 0 && A[r] > 0){
            break;
        }
        
        ll a = abs(A[l]);
        ll b = abs(A[r]);
        
        ans = min(ans, a*2+b);
        ans = min(ans, a+b*2);

        l++, r++;
        
    }
    
    cout << ans << endl;
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}/*char to int*/
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}/*MAX*/
int lcm(ll a,ll b){return a*b/gcd(a,b);}/*MIN*/
bool primecheck(ll n){/*sosuu*/if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int  main(){
string s,t;
cin >> s >> t;
reverse(s.begin(),s.end());
reverse(t.begin(),t.end());
if(s.size()<t.size()){
    cout <<"UNRESTORABLE"<<endl;
    return 0;
}
bool ans = false;
for(int i=0;i<s.size();i++){
    string z;
    if(ans)break;
    for(int j=0;j<t.size();j++){
        if(i+j>=s.size())continue;
        z+=s.at(i+j);
    }
    bool che = true;
    if(z.size()!=t.size())continue;
  
    for(int j=0;j<t.size();j++){
        if(z.at(j)=='?')continue;
        if(z.at(j)!=t.at(j))che=false;
    }
    if(che){
    for(int j=0;j<t.size();j++){
        s.at(i+j)=t.at(j);
    }
        ans = true;
    }
    }

if(!ans){
    cout <<"UNRESTORABLE"<<endl;
    return 0;
}
reverse(s.begin(),s.end());
for(int i=0;i<s.size();i++){
    if(s.at(i)=='?')s.at(i)='a';
}
cout << s << endl;
}





Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * 2791.cc: Cabbage
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000;

/* typedef */

/* global variables */

int ds[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, m, a, b;
  scanf("%d%d%d%d", &n, &m, &a, &b);

  for (int i = 0; i < n; i++) scanf("%d", ds + i);

  int rn = 0;
  while (rn < n && ds[rn] >= a) rn++;
  //printf("rn=%d\n", rn);
  if (n - rn < m)
    while (rn > 0 && ds[rn - 1] <= b) rn--;
  printf("%d\n", rn);
  return 0;
}



Measured memory_bytes: 3220
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
A = np.array([0] + lr())
Acum = A.cumsum()
sum_range = Acum[:, None] - Acum[None, :]
sum_range = sum_range[sum_range>0]

def check(x):
    return np.sum(sum_range&x == x) >= K

answer = 0
for i in range(40, -1, -1):
    if check(answer + (1 << i)):
        answer += 1 << i

print(answer)


Measured memory_bytes: 25192
def main():
    N = int(input())
    ans = ''
    while N != 0:
        if N % 2 == 0:
            ans = '0' + ans
        else:
            ans = '1' + ans
            N -= 1
        N //= -2
    if ans == '':
        ans = '0'
    print(ans)


main()


Measured memory_bytes: 2940
import sys
def q(a,h):
 d[a]=h
 for b in t[a]:q(b,h+1)
t,p,d={},{},{}
input()
for e in sys.stdin:
 e=e.split()
 t[e[0]]=e[2:]
 for i in e[2:]:p[i]=e[0]
r=(set(t)-set(p)).pop()
p[r]='-1'
q(r,0)
print('\n'.join(f"node {i}: parent = {p[i]}, depth = {d[i]}, {'root'if'-1'==p[i]else'internal node'if t[i]else'leaf'}, [{', '.join(t[i])}]"for i in map(str,sorted(map(int,t)))))


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

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

	int n;
	int m;
	cin >> n >> m;
	vector<vector<long long>> ab(n,vector<long long>(2));
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 2; j++){
			cin >> ab[i][j];
		}
	}
	sort(ab.begin(),ab.end());

	long long ans = 0;
	int cnt = 0;
	for(int i = 0;cnt < m; i++){
		if(cnt + ab[i][1] < m){
			ans += (long long)(ab[i][0]*ab[i][1]);
			cnt += ab[i][1];
		}else if(cnt + ab[i][1] >= m){
			ans += (long long)(ab[i][0]*(m-cnt));
			break;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

ll mod = 1e9+7;

//edutorial の解法を実装して二分探索を復習

//f_p(x) := x - x % p
//g(x) := f_a[1](f_a[2](...(f_a[n](x))))

//答えは g(n) == 2 なる n の最小値と最大値
//f : 単調 より g : 単調なので二分探索が有効

//check : 条件を満たすか確認するやつ
bool check(ll x, vll &a, ll type){
	for(auto q : a){
		x -= x % q;
	}
	if(type == 1){
		if(x >= 2) return true;
		else return false;
	}
	else{
		if(x <= 2) return true;
		else return false;
	}
}

//1つめ : g(n) >= 2 となる最小の n を二分探索
ll search_min(vll &a){
	ll ng = 0;
	ll ok = 1e18;

    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if (check(mid, a, 1)) ok = mid;
        else ng = mid;
    }
    return ok;
}

//2つめ : g(n) <= 2 となる最大の n を二分探索
ll search_max(vll &a){
	ll ng = 1e18;
	ll ok = 0;

    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if (check(mid, a, 2)) ok = mid;
        else ng = mid;
    }
    return ok;
}

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

	ll k;
	cin >> k;
	vll a(k);
	REP(i, k) cin >> a[i];

	ll mi = search_min(a);
	ll ma = search_max(a);

	if(mi > ma){
		cout << -1 << endl;
		return 0;
	}

	cout << mi << " " << ma << endl;
    return 0;
}

Measured memory_bytes: 1024
import numpy as np

n,m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
d = 2**18

f = np.zeros(d,dtype=int)
for i in a:
    f[i]+=1

tf = np.fft.fft(f)
f = np.fft.ifft(tf*tf)
f = [int(i+0.5) for i in f]

ans=0
for i in range(len(f)-1,0,-1):
    if f[i]<=m:
        ans+=i*f[i]
        m-=f[i]
    elif f[i]>m:
        ans+=i*m
        break
print(ans)

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

#define N 100
#define INF 0x3f3f3f3f

int main() {
	static int aa[N];
	int n, i, x, sum, sum1, min;

	scanf("%d", &n);
	sum = 0;
	for (i = 0; i < n; i++) {
		scanf("%d", &aa[i]);
		sum += aa[i];
	}
	min = INF;
	sum1 = 0;
	for (i = 0; i < n; i++) {
		sum1 += aa[i];
		if (min > (x = abs(sum1 - (sum - sum1))))
			min = x;
	}
	printf("%d\n", min);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;

#define N 100000

int main() {
	string s;

	cin >> s;

	if (s == "SUN") cout << 7;
	else if (s == "MON") cout << 6;
	else if (s == "TUE") cout << 5;
	else if (s == "WED") cout << 4;
	else if (s == "THU") cout << 3;
	else if (s == "FRI") cout << 2;
	else if (s == "SAT") cout << 1;


	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

void dfs_init(int,int,int*,int*,int*);
void dfs(int,int,int*,int*,int*);

int M[N][N];
int time;

int main(void){
  int n,maxval=0,color[N],d[N],f[N];
  int u,k,v;
  int i,j;

  scanf(" %d",&n);

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      M[i][j] = 0;
    }
  }
  
  for(i = 0; i < n; i++){
    scanf(" %d",&u);
    if(u-1 > maxval) maxval = u-1;
    scanf(" %d",&k);
    for(j = 0; j < k; j++){
      scanf(" %d",&v);
      if(v-1 > maxval) maxval = v-1;
      M[u-1][v-1] = 1;
    }
  }

  dfs_init(n,maxval,color,d,f);

  for(i = 0; i < n; i++){
    if(d[i] != 0){
      printf("%d %d %d\n",i+1,d[i],f[i]);
    }
  }
  
  
  return 0;
}

void dfs_init(int n, int maxval, int *color, int *d, int *f){
  int i;
  for(i = 0; i < n; i++){
    color[i] = WHITE;
  }
  for(i = 0; i < n; i++){
    d[i] = f[i] = 0;
  }

  time = 0;
  
  for(i = 0; i < n; i++){
    if(color[i] == WHITE) dfs(i,maxval,color,d,f);
  }
}

void dfs(int u, int maxval, int *color, int *d, int *f){
  int i,v;
  
  color[u] = GRAY;
  d[u] = ++time;
  for(v = 0; v <= maxval; v++){
    if(M[u][v] && color[v] == WHITE){
      dfs(v,maxval,color,d,f);
    }
  }
  color[u] = BLACK;
  f[u] = ++time;
}



Measured memory_bytes: 2112
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    S = input()
    ym1 = int(S[0:2])
    ym2 = int(S[2:4])

    yymm = (1 <= ym2 and ym2 <= 12)
    mmyy = (1 <= ym1 and ym1 <= 12)

    if yymm and mmyy:
        ans = 'AMBIGUOUS'
    elif yymm:
        ans = 'YYMM'
    elif mmyy:
        ans = 'MMYY'
    else:
        ans = 'NA'

    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
        int n, k;
        scanf("%d%d", &n, &k);
        int ans = n, sum = 0;
        vector<int> a(n);
        for (int i = 0; i < n; i ++) scanf("%d", &a[i]);
        sort(a.begin(), a.end());
        for (int i = n - 1; i >= 0; i --) {
                if (sum + a[i] < k) sum += a[i];
                else ans = i;
        }
        printf("%d\n", ans);
        return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int i,j,n,p[100],cnt,sc;
	scanf("%d",&n);
	for(i=0;i<n;i++)	scanf("%d",&p[i]);
	for(i=100;i>=1;i--)	{
		cnt=0;
		for(j=0;j<n;j++)	{
			if(p[j]>=i)	cnt++;
		}
		if(cnt>=i)	break;
	}
	printf("%d\n",i);
	return 0;
}


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

    #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
    #define mod 1000000007
    #define qmod 998244353
    #define M 10000001
    #define endl "\n"
    #define all(a) (a).begin(),(a).end()
    #define rep(i,a,b) for(int i=a;i<b;++i)
    #define repr(i,a,b) for(int i=a;i>=b;--i)
    #define F first
    #define S second
    #define pb push_back
    #define mp make_pair

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

    int main(){ 
                            
  /*  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin); 
    freopen("output.txt","w",stdout);   
    #endif */

        fast;   
        int t=1;
        // cin>>t; 
        while(t--){ 
            int n;
            cin>>n;
            if(n%1000==0) cout<<0;
            else{
                int m=n;
                n/=1000;
                n++;
                cout<<n*1000-m;
            }
        }  
        return 0;       
    }       


    // First, solve the problem. Then, write the code. 
    

Measured memory_bytes: 3524
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;
using MIte = multimap<long, long, greater<long> >::iterator;

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

	int N;
	cin >> N;

	multimap<string, multimap<int, int, greater<int> > > mm;
	for (int i = 0; i != N; ++i) {
		string S;
		int P;
		cin >> S >> P;
		multimap<string, multimap<int, int, greater<int> > >::iterator it = mm.find(S);
		if (it == mm.end()) {
			multimap<int, int, greater<int> > mtmp;
			mtmp.insert(make_pair(P, i+1));
			mm.insert(make_pair(S, mtmp));
		}
		else {
			it->second.insert(make_pair(P, i+1));
		}
	}

	for (multimap<string, multimap<int, int, greater<int> > > ::iterator it1 = mm.begin(); it1 != mm.end(); ++it1) {
		for (multimap<int, int, greater<int> >::iterator it2 = it1->second.begin(); it2 != it1->second.end(); ++it2) {
			cout << it2->second << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   ll n, k, ans;
   cin >> n >> k;
   ll n1 = n / k, n2 = (n - k / 2) / k + 1;
   ans = pow(n1, 3LL);
   if (k % 2 == 0 && n >= k / 2)
   {
      ans = pow(n1, 3LL) + pow(n2, 3LL);
   }

   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 256