akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1e9 + 7
#define INF 1e9
#define SENTINEL 2e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}
template <class T>
inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template <class T>
inline T GCD(T a, T b){if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) {return (a * b) / GCD(a, b);}

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> s(m);
    rep(i,m){
        int k;
        cin >> k;
        rep(j,k) {
            int S;
            cin >> S;
            S--;
            s[i].push_back(S);
        }
    }
    vector<int> p(m);
    rep(i, m) cin >> p[i];
    int count = 0;
    for (int bit = 0; bit < (1 << n); bit++){
        bool flag = true;
        rep(j,m){
            int cnt = 0;
            for (auto v : s[j]){
                if (bit & (1 << v))
                    cnt++;
            }
            if (cnt % 2 != p[j])
                flag = false;
        }
        if (flag)
            count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<map>
#include<set>
using namespace std;
string s, t;//s是待破解的代码，t是给出的子串
set<string> S;

void Work()
{
    int lens = s.size();
    int lent = t.size();
    for(int i = 0; i < lens; i++)
    {
        if(s[i] == '?' || s[i] == t[0])//如果字符相等
        {
            string tmp = s;              //构造判断子串之前的字符
            for(int j = 0; j < i; j++)
                if(tmp[j] == '?')//用a替代所有的"?"
                    tmp[j] ='a';
            bool can = false;//不满足要求
            for(int j = 0; j < lent; j++)    //判断是否为子串
            {

                if(tmp[i+j]!= '?' && tmp[i+j] != t[j])  //字符匹配
                    break;
                tmp[i+j] = t[j];
                if(j == lent - 1) can = true;
            }
            if(can)
            {
                for(int j = i + lent; j < lens; j++) if(tmp[j] == '?') tmp[j] = 'a';//处理匹配后的字符
                S.insert(tmp);  //压入容器
            }
        }
    }
    if(S.size() == 0) cout << "UNRESTORABLE" << endl;
    else cout << *S.begin() << endl;//如果有结果，直接输出全部
}
int main()
{
    cin >> s >> t;
    Work();
}



Measured memory_bytes: 256
use std::cmp::max;

const COSTS: [usize; 10] = [1000, 2, 5, 5, 4, 5, 6, 3, 7, 6];

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let m: usize = sc.read();
    let mut a: Vec<usize> = sc.vec(m);
    a.sort();
    a.reverse();

    let mut dp = vec![-1; n + 1];
    dp[0] = 0;
    for i in 0..n {
        if dp[i] < 0 {
            continue;
        }
        for &a in a.iter() {
            let cost = COSTS[a];
            if i + cost > n {
                continue;
            }
            dp[i + cost] = max(dp[i + cost], dp[i] + 1);
        }
    }

    let mut cur = n;
    while cur > 0 {
        for &a in a.iter() {
            let cost = COSTS[a];
            if cur >= cost && dp[cur] > 0 && dp[cur - cost] == dp[cur] - 1 {
                print!("{}", a);
                cur -= cost;
                break;
            }
        }
    }
    println!();
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include <cstdio>
#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <string>

using namespace std;
using ll = long long;

ll H, W, h, w;

void input() {
    cin >> H >> W >> h >> w;
}

void solve() {
    cout << (H - h) * (W - w) << endl;
}

int main() {
    input();
    solve();
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#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 REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    string s;
    int q;
    cin >> s >> q;
    int r = 0;
    deque<char> fr;
    deque<char> ba;
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            r++;
        } else {
            int f;
            char c;
            cin >> f >> c;
            if (f == 1) {
                if (r % 2 == 0) {
                    fr.emplace_front(c);
                } else {
                    ba.emplace_back(c);
                }
            } else {
                if (r % 2 == 0) {
                    ba.emplace_back(c);
                } else {
                    fr.emplace_front(c);
                }
            }
        }
    }
    if (r % 2 == 1) REV(s);
    if (r % 2 == 0) {
        for (char x : fr) cout << x;
    } else {
        REV(ba);
        for (char x : ba) cout << x;
    }
    cout << s;
    if (r % 2 == 0) {
        for (char x : ba) cout << x;
    } else {
        REV(fr);
        for (char x : fr) cout << x;
    }
    cout << endl;
}


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

# AtCoder Beginner Contest
# Problem C
large_number = 10 ** 9 + 7


def factorial(number: int) -> int:
    value = 1

    for i in range(1, number + 1):
        value = (value * i) % large_number
    return value


if __name__ == '__main__':
    n, m = list(map(int, input().split()))
    diff = abs(n - m)
    result = factorial(min(n, m))

    # See:
    # https://beta.atcoder.jp/contests/abc065/submissions/1654425
    if diff == 1:
        rate = 1
        print(((result * result * max(n, m) * rate) % large_number))
    elif diff == 0:
        rate = 2
        print(((result * result * rate) % large_number))
    else:
        print(0)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    vector<int>vec(5);
    for(int i=0;i<5;i++){
        cin >>vec.at(i);
    }
    sort(vec.begin(),vec.end());
    int A=9999999;
    int B=0;
    do{
        int B=0;
       for(int i=0;i<4;i++){
           if(vec.at(i)%10==0){
             B+=vec.at(i);
                 }
           else{
            B+=(vec.at(i)/10+1)*10;
            }  
    } 
    B+=vec.at(4);
    A=min(A,B) ; 
    }while(next_permutation(vec.begin(),vec.end()));
    cout << A <<endl;
}

Measured memory_bytes: 3536
k = int(input())

import queue

q = queue.Queue()

for i in range(1, 10):
    q.put(i)
    
c = 0

while c < k:
    x = q.get()
    
    r = x%10
    
    if r!=0 and r!=9:
        q.put(10*x+r-1)
        q.put(10*x+r)
        q.put(10*x+r+1)
        c += 1
    elif r==0:
        q.put(10*x)
        q.put(10*x+1)
        c+=1
    elif r==9:
        q.put(10*x+r-1)
        q.put(10*x+r)
        c+=1
    if c==k:
        print(x)
    

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

using namespace std;
#define ll long long
#define int long long

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "YES"
#define FALSE__ "NO"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
	#define lcout(a) cout << a;
	#define lcoutln(a) cout << a << endl;
	#define lcerr(a) cerr << a;
	#define lcerrln(a) cerr << a << endl;
#else
	#define lcout(a) 
	#define lcoutln(a) 
	#define lcerr(a) 
	#define lcerrln(a) 
#endif

int a[3];

signed main()
{
	int b[3] = {5, 5, 7};
	rep(i, 3) cin >> a[i];
	sort(a, a+3);
	rep(i, 3) {
		if (a[i] != b[i]) {
			PRINT(0);
			return 0;
		}
	}
	PRINT(1);
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<long double,long double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<61;
const double pi=acos(-1);
const double eps=1e-10;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

class Union_Find_Tree{
	public:
	vi Par,Rank;
	Union_Find_Tree(int n){
		Par=Rank=vi(n);
		for(int i=0;i<n;i++) Par[i]=i;
	}
	int Find_Par(int x){
		if(Par[x]==x) return x;
		return Par[x]=Find_Par(Par[x]);
	}
	bool Unite(int x,int y){
		x=Find_Par(x);
		y=Find_Par(y);
		if(x==y) return 0;
		if(Rank[x]<Rank[y]) Par[x]=y;
		else{
			Par[y]=x;
			if(Rank[x]==Rank[y]) Rank[x]++;
		}
		return 1;
	}
	bool Same(int x,int y){
		return Find_Par(x)==Find_Par(y);
	}
};

int n,m,k;
vi a;
vip e;

int main(){
	cin>>n>>m>>k;
	a=vi(n);
	e=vip(m);
	Union_Find_Tree uft(n+k);
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]) uft.Unite(i,n+a[i]-1);
	}
	for(int i=0;i<m;i++){
		int u,v,w;
		cin>>u>>v>>w;
		e[i]={w,{u-1,v-1}};
	}
	sort(e.begin(),e.end());
	ll res=0,cnt=k;
	for(int i=0;i<m&&cnt>1;i++){
		P p=e[i].second;
		int u=p.first,v=p.second;
		if(!uft.Same(u,v)){
			uft.Unite(u,v);
			res+=e[i].first;
			cnt--;
		}
	}
	if(cnt==1) cout<<res<<endl;
	else cout<<-1<<endl;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=600005,INF=1<<30;
int N;

vector<int> A;
int ans[MAX],rui[20];

void DFS(string &S){
    if(si(A)==N) return;
    
    int M=si(S);
    
    for(int i=0;i<3;i++){
        string T;
        int now=i;
        
        for(int j=0;j<M;j++){
            if(S[j]=='R'){
                now++;
                if(now==3){
                    now=0;
                    T+='R';
                }
            }else{
                if(j==M-1){
                    T+='S';
                    if(now) now=3-now;
                }
                else if(S[j+1]=='S') j++;
                else{
                    T+='S';
                    if(now) now=3-now;
                }
            }
        }
        
        A.push_back(i);
        
        int sum=0;
        for(int j=0;j<si(A);j++){
            sum+=A[j]*rui[j];
        }
        while(sum<rui[N]){
            ans[sum]+=now*rui[si(A)-1];
            sum+=rui[si(A)];
        }
        
        DFS(T);
        A.pop_back();
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N;
    string S;cin>>S;
    
    rui[0]=1;
    for(int i=1;i<18;i++) rui[i]=rui[i-1]*3;
    
    DFS(S);
    
    for(int i=0;i<rui[N];i++){
        cout<<ans[i]<<" ";
    }
    cout<<endl;
}


Measured memory_bytes: 6592
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#include<numeric>
#define INF 1e9
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define vecuni(a) (a).erase(unique((a).begin(),(a).end()),(a).end())

using namespace std;
using vi = std::vector<int>;
using vl = std::vector<long long>;
using vs = std::vector<string>;
using ll = long long;
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; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}

template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
  s << vv[i] << endl;
  }
  return s;
}

string s;
int K;
vs d;
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> s >> K;
  for(int i = 0 ; i < s.length() ; i++){
    for(int j = 1 ; j <= K ; j++){
      d.push_back(s.substr(i,j));
    }
  }
  sort(all(d));
  vecuni(d);
  cout << d[K-1] << endl;
  return 0;
}


Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
using namespace std;
typedef long long ll;
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
 
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll lcm(ll a,ll b){
	ll g=gcd(a,b);
	return a/g*b;
}
 
ll digitsum(ll a){
	ll x=0;
	while(a>0){
		x+=a%10;
		a/=10;
	}
	return x;
}
int main(){
	ll x,t;
	cin>>x>>t;
	if(x<=t)cout<<0<<endl;
	else cout<<x-t<<endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  int N;
  int M=0;
  cin>>S;
  N=S.size();
  for(int i=0;i<(N-1)/2;i++){
    if(S.at(i)!=S.at((N-1)/2+1+i)){
      M=1;
    }
  }
  if(M==1){
    cout<<"No"<<endl;
  }else{
    cout<<"Yes"<<endl;
  }
  
  
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <string>
using u8t = std::uint64_t;
using i8t = std::int64_t;
#define F(I,N) for(i8t I=0,I##_N=N;I<I##_N;I++)
#define FR(I,N) for(i8t I=N;I--;)
#define R(V) i8t V;std::cin>>V;
#define RV(V,N) std::vector<i8t> V;F(_i,N){R(_x)V.push_back(_x);}
#define RL1(line) std::getline(std::cin,line);
#define RL(line) std::string line;RL1(line)
#define RM(V,L,C) std::vector<char> V;F(_i,L){RL(_l)F(_j,C)V.push_back(_l[_j]);}
#define P(X) std::cout<<(X)<<std::endl;
int main() {
  R(N)R(K);
  std::vector<int> sunuke(N);
  F(I,K){
    R(d);
    F(J,d){
      R(A);
      sunuke[A-1]=1;
    }
  }
  int c=0;
  F(I,N){
    if(!sunuke[I])c++;
  }
  P(c)
  return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
long long w=10;
int n;
int ans=0;
char s[10];
int main(){
	cout << "? 10000000000" << endl;
    cin>>s;
    if (s[0]=='Y') {
        long long x=2;
        while(true) {
            cout<<"? "<<x<<endl;
            cin>>s;
            if (s[0]=='Y') {
                cout<<"! "<<x/2<<endl;
                return 0;
            }
            x*=10;
        }
    }
	while(1){
		cout<<"? "<<w<<"\n";
		cin>>s;
		if(s[0]=='N') break;
		w=w*10;
	}
	long long l=w/10,r=w-1,mid;
	while(l!=r){
		mid=(l+r)/2*1000000000;
		cout<<"? "<<mid<<"\n";
		cin>>s;
		if(s[0]=='Y') r=mid/1000000000;
		else l=mid/1000000000+1;
	}
	printf("! %lld\n",l);
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,A,B,L;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MOD = (1e+9) + 7;
const ll MAX_N = 100010;
typedef pair<ll,ll> P;

int main() {
    cin >> N;
    K = 0;
    M = N;
    while (N > 0) {
        ++K;
        N /= 10;
    }
    ll ans = 0;
    reps(i, 1, K + 1) {
        if (i % 2 == 0) continue;
        ll temp = 9;
        rep(j, i - 1) temp *= 10;
        if (i != K) {
            ans += temp;
        } else {
            ans += M - temp / 9 + 1;
        }
    }
    cout<<ans<<endl;
}


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


vector<int> vec[200001];
int N, M;
bool dfs(int pos = 1, int lim = 2) {
    if(pos == N) {
        return true;
    }
    if(lim == 0) {
        return false;
    }

    for (int i = 0; i < vec[pos].size(); i++) {
        if(dfs(vec[pos][i], lim-1))
            return true;
    }

    return false;
}


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

    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        vec[a].push_back(b);
    }

    if (dfs()) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
}



Measured memory_bytes: 8576
#include <stdio.h>
#include <math.h>

int main(int argc, const char * argv[])
{

    int l, a, b, c, d;
    int jday, mday, result;
    
    scanf("%d %d %d %d %d", &l, &a, &b, &c, &d);
    
    if (a % c == 0) {
        jday = a / c;
    } else {
        jday = (a / c) + 1;
    }
    
    if (b % d == 0) {
        mday = b / d;
    } else {
        mday = (b / d) + 1;
    }
    
    if (jday > mday) {
        result = l - jday;
    } else {
        result = l - mday;
    }
    
    printf("%d\n", result);
    
    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LLI long long int
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POS(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
#define Pos(i) cout<<(i?"Possible":"Impossible")<<endl
#define co(i) cout<<i<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
int main(){
    int n,m; cin>>n>>m;
    LLI x[3][1001]={};
    FOR(i,0,n){
        FOR(j,0,3){
            cin>>x[j][i];
        }
    }
    LLI ans=-10e16;
    for(int i=-1;i<=1;i+=2){
        for(int j=-1;j<=1;j+=2){
            for(int k=-1;k<=1;k+=2){
                vector<LLI> v;
                FOR(s,0,n){
                    v.PB(i*x[0][s]+j*x[1][s]+k*x[2][s]);
                }
                sort(v.rbegin(),v.rend());
                LLI sum=0;
                FOR(s,0,m) sum+=v[s];
                ans=max(ans,sum);
            }
        }
    }
    co(ans);
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

/*
bool isOK(int a, int b, int c, int d, int e, int f){
    bool isOK = true;
    if((100 * a + 100 * b + c + d) > f) isOK = false;
    if(((a + b) * e) < (c + d)) isOK = false;
    
    return isOK;
}
*/

bool isOK(int water, int sugar, int e, int f){
    if(water == 0) return false;
    else if((water + sugar) > f) return false;
    else if((water / 100 * e) < sugar) return false;
    else return true;
}

int main(){
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;

    int tmpWater = 0, tmpSugar = 0;
    int ansWater = 100 * a, ansSugar = 0;
    float maxConcentration = 0.0f;

    for(int i = 0; i <= f / (100 * a); i++){
        for(int j = 0; j <= f / (100 * b); j++){
            for(int k = 0; k <= (a * i + b * j) * e / c; k++){
                for(int l = 0; l <= (a * i + b * j) * e / d; l++){
                    tmpWater = 100 * a * i + 100 * b * j;
                    tmpSugar = c * k + d * l;
                    if(isOK(tmpWater, tmpSugar, e, f)){
                        if(maxConcentration < float(tmpSugar) / (tmpWater + tmpSugar)){
                            maxConcentration = float(tmpSugar) / (tmpWater + tmpSugar);
                            ansWater = tmpWater;
                            ansSugar = tmpSugar;
                        }
                    }
                }
            }
        }
    }

    cout << (ansWater + ansSugar) << " " << ansSugar << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 62;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
pl I[5010];
ll dp[2510][2510][2];

bool compare(const pl& p1, const pl& p2) {
	return (p1.sec + p1.fst) > (p2.sec + p2.fst);
}

void solve() {
	cin >> N;
	rep(i, 0, N) {
		ll l, r;
		cin >> l >> r;
		I[i] = pl(l, r);
	}
	sort(I, I + N, compare);

	int LN = (N - 1) / 2, RN = N / 2;

	rep(i, 0, LN + 1) {
		rep(j, 0, RN + 1) {
			dp[i][j][0] = linf;
			dp[i][j][1] = linf;
		}
	}

	dp[0][0][0] = 0;

	rep(i, 0, LN + 1) {
		rep(j, 0, RN + 1) {
			rep(k, 0, 2) {
				if(dp[i][j][k] == linf) continue;
				int id = i + j + k;
				ll l = I[id].fst, r = I[id].sec;
				if(i < LN) MIN(dp[i + 1][j][k], dp[i][j][k] + (l + r) * (i + 1) - l);
				if(j < RN) MIN(dp[i][j + 1][k], dp[i][j][k] + (l + r) * (j + 1) - r);
				if(k == 0) MIN(dp[i][j][k + 1], dp[i][j][k] + l * LN + r * RN);
			}
		}
	}
	cout << dp[LN][RN][1] << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 98688
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr <<__LINE__<< ": " << #x << " -> " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" -> ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while(1) {
        c -= b;
        if (c <= 0) {
            cout << "Yes" << endl;
            return;
        }
        a -= d;
        if (a <= 0) {
            cout << "No" << endl;
            return;
        }
    }
}

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


Measured memory_bytes: 3584
#include <algorithm>
//#define DEBUG
#define MAXN 10000000
#define LLMIN -922337203685477580
#define ll unsigned long long int 
#define PI 3.14159265
#include <bits/stdc++.h>
using namespace std;

int main() {
#ifdef DEBUG
    freopen("in.in", "r", stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);


    long double a, b, h, m;
    cin >> a >> b >> h >> m;
    const long double pi = std::acos(-1);
    cout.precision(17);

    long double radius = (((30*h) - 5.5*m)* pi / 180.0);
    long double temp = (a*a) + (b*b) - 2*a*b*cosl(radius);
    long double ans = sqrt(temp);

    cout << ans << endl;




    return 0;
}


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

int main(){
    int n; cin >> n;
    long long arr[45] = {1,1};
    if (n == 1 || n == 0) cout << 1 << endl;
    else {
        for(int i = 2; i <= n; ++i){
            arr[i] = arr[i-1] + arr[i-2];
        }
        cout << arr[n] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int a,b,c,n;

int main(){
	cin >> a >> b >> c >> n;
	
	int s = 0;
	REP(i,0,a+1){
		REP(j,0,b+1){
			REP(k,0,c+1){
				if(i*500 + j*100 + k*50 == n) s++;
			}
		}
	}
	
	cout << s << endl;
	return 0;
}


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

int main(void){
  int n, p, price = 0, max = INT_MIN;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> p;
    if(p > max) max = p;
    price += p;
  }
  cout << price - max/2 << endl;
  return 0;
}


Measured memory_bytes: 256
from bisect import bisect_left,bisect_right
n,q=map(int,input().split())
w=[list(map(int,input().split()))[::-1]for _ in range(n)]
p=[int(input())for _ in range(q)]
w.sort()
ans=[-1]*q
to=[-1]*q
for x,t,s in w:
  l,r=bisect_left(p,s-x),bisect_left(p,t-x)
  while l<r:
    if to[l]==-1:
      ans[l]=x
      to[l]=r
      l+=1
    else:
      l=to[l]
print(*ans)

Measured memory_bytes: 62536
import java.util.Scanner;
public class Main {
	int time;
	char[] hw;
	Scanner sc = new Scanner(System.in);

	void doit() {
		int ans[][] = new int[1000][1000];
		int h = sc.nextInt();
		int w = sc.nextInt();
		ctime(h, w, ans);

		//??????
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				if(j == w - 1){
					System.out.println(ans[i][j]);
				}else{
					System.out.print(ans[i][j]);
					System.out.print(" ");
				}
			}
		}
	}
	
	void ctime(int h, int w, int ans[][]){
		for(int i = 0; i < h; i++){
			char[] hw = sc.next().toCharArray();
			time = -1;
			for(int j = 0; j < w; j++){
				if(hw[j] == 'c'){
					time = 0;
				}
				ans[i][j] = time;
				if(time != -1){
					time++;
				}
			}
		}
		
	}

	public static void main(String[] args) {
		new Main() . doit();

	}

}

Measured memory_bytes: 40172
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;
 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;

int main ()
{
  prep();
  int n, c;
  cin >> n >> c;
  int a[n];
  int b[n];
  for (int i=0; i<n; i++){
      cin >> a[i];
  }
  for (int i=0; i<n; i++){
      cin >> b[i];
  }
  long long buckets[c+1] = {0};
  buckets[0] = 1;
  
  for (int i=n-1; i>=0; i--){
      int cura = a[i];
      int curb = b[i];
      long long newbuckets[c+1] = {0};
      for (int j=cura; j<=curb; j++){
          long long temp[c+1];
          temp[0] = buckets[0];
          newbuckets[0] += temp[0];
          newbuckets[0] %= mod;
          for (int k=1; k<=c; k++){
              temp[k] = mymod(buckets[k]+mymod(temp[k-1]*j));
              newbuckets[k] += temp[k];
              newbuckets[k] %= mod;
          }
      }
      
      for (int k=0; k<=c; k++){ 
          buckets[k] = newbuckets[k];
          //cout << buckets[k] << " ";
      }
      //cout << endl;
  }
  cout << buckets[c];
  return 0; 
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.root = [-1] * (n + 1)
    self.rnk = [0] * (n + 1)

  def Find_Root(self, x):
    if self.root[x] < 0:
      return x
    else:
      self.root[x] = self.Find_Root(self.root[x])
      return self.root[x]

  def Unite(self, x, y):
    x = self.Find_Root(x)
    y = self.Find_Root(y)
    if x == y:
      return 
    elif self.rnk[x] > self.rnk[y]:
      self.root[x] += self.root[y]
      self.root[y] = x
    else:
      self.root[y] += self.root[x]
      self.root[x] = y
      if self.rnk[x] == self.rnk[y]:
        self.rnk[y] += 1

  def isSameGroup(self, x, y):
    return self.Find_Root(x) == self.Find_Root(y)

  def Count(self, x):
    return -self.root[self.Find_Root(x)]
uf = UnionFind(N)
for _ in range(M):
  u, v = map(int, input().split())
  uf.Unite(u, v)
res = set()
for x in range(1, N + 1): res.add(uf.Find_Root(x))
print(len(res) - 1)

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

using namespace std;

int main() {
    int l, r, d;
    cin >> l >> r >> d;
    int ans = (r-l+1)/d;
    if(!(l%d) && !(r%d) && d != 1) ans++;
    cout << ans;
    return 0;
}


Measured memory_bytes: 3632
# n=gets.strip.to_i
# as=[]
# (1..n).each do
#     a=gets.strip.to_i
#     as.push(a)
    
# end
# as2=as.uniq
# puts as2.length

n=gets.to_i
as=n.times.map{gets.to_i}
puts as.uniq.length

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 100010;
int N;
vector<int> V[MC];
vector<int> S[MC];
int r;

bool dfs(int p , int q , int z){
	S[q].clear();
	for(auto u : V[q]){
		if(u==p) continue;
		if(!dfs(q,u,z)) return 0;
	}
	if(S[q].size()%2==0) S[q].PB(0);
	sort(S[q].begin(),S[q].end());
	int f = 0 , g = -1;
	deque<int> Q;
	repm(i,S[q].size()-1,-1){
		while(f<i && S[q][f]+S[q][i]<=z){
			Q.push_back(S[q][f]);
			++f;
		}
		if(f == i){
			Q.push_back(S[q][f]);
			break;
		}
		if(Q.empty()){
			if(~g) return 0;
			g = S[q][i];
		} else {
			Q.pop_back();
		}
	}
	int w = max(Q.empty()?0:Q.front(),g);
	if(p>0) S[p].PB(w+1);
	else if(w>z) return 0;
	return 1;
}

int BS(int x , int y){
	if(x-y<2) return x;
	int z = (x+y) / 2;
	return dfs(-1,r,z) ? BS(z,y) : BS(x,z);
}

int main(){
	cin >> N;
	repp(i,1,N){
		int a,b;
		cin >> a >> b;
		V[a].PB(b);
		V[b].PB(a);
	}
	int A = 1;
	repp(i,1,N+1){
		A += (V[i].size()-1)/2;
		if(V[i].size()==1) r = i;
	}
	cout << A << ' ' << (A==1?N-1:BS(N-1,0)) << endl;
	return 0;
}


Measured memory_bytes: 26752
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
using namespace std;

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

	vector<int32_t> A(N), B(N), C(N);
	for (int32_t i = 0; i < N; i++)
		cin >> A[i];
	for (int32_t i = 0; i < N; i++)
		cin >> B[i];
	for (int32_t i = 0; i < N; i++)
		cin >> C[i];
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	sort(C.begin(), C.end());

	int64_t res = 0;
	for (int32_t i= 0; i < N; i++) {
		decltype(A)::iterator it_A = lower_bound(A.begin(), A.end(), B[i]);
		int64_t cnt_A = it_A == A.end() ? (int32_t)A.size() : it_A - A.begin();

		decltype(C)::iterator it_C = upper_bound(C.begin(), C.end(), B[i]);
		int64_t cnt_C = it_C == A.end() ? 0 : C.size() - (it_C - C.begin());

		res += cnt_A * cnt_C;
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	int n;
	cin >> n;
	vi a(n);
	rep(i, n)cin >> a[i];
	sort(all(a));
	V<ll> sum(n + 1);
	rep(i, n)sum[i + 1] = sum[i] + a[i];

	int ans = 0;

	rep(i, n) {

		ll d = a[i];
		bool ok = false;

		while (true) {
			int k = upper_bound(all(a), 2 * d) - a.begin();
			if (k == n) { ok = true;break; }
			if (d == sum[k])break;
			d = sum[k];
		}
		if (ok) {
			ans = n - i;
			break;
		}

	}
	
	cout << ans << endl;

}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a;
	cin>>a;
	for(int i=0;i<100;i++)
	{
		for(int j=0;j<100;j++)
		{
			if(4*i+7*j==a)
			{
				cout<<"Yes";
				return 0;
			}
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;

template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);


int main(){
  FAST_IO  

  int row, col; cin >> row >> col;
  if(col < row) swap(row, col);
  if(row == col && row == 1) cout << "1\n";
  else if(col < 2) cout << "0\n";
  else if(row == 1) cout << col - 2 << "\n";
  else cout << (LL)(col - 2) * (row - 2) << "\n";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[1000010],x;
bool p[1000010],f[1000010],k;
vector<int> prime;
int main(){
	p[0]=p[1]=1;
	for (int i=2;i<=1000;i++) if (p[i]==0) for (int j=i+i;j<=1000;j+=i) p[j]=1;
	for (int i=0;i<=1000;i++) if (p[i]==0) prime.push_back(i);
	cin>>n;
	for (int i=0;i<1000010;i++) a[i]=1e9;
	for (int i=0;i<n;i++){
		cin>>x;
		for (int j=0;j<prime.size();j++){
			int num=0;
			while ((x%prime[j])==0){
				num++;
				x/=prime[j];
			}
			a[j]=min(a[j],num);
			if (f[j]==1&&num>0) k=1;
			if (num>0) f[j]=1;
		}
		if (x!=1) if (f[x]==1) k=1;
		if (x!=1) f[x]=1;
	}
	if (k==0)
		cout<<"pairwise coprime"<<endl;
	else{
		k=0;
		for (int i=0;i<=1000;i++)
			if (a[i]==0||a[i]==1000000000)
				continue;
			else
				k=1;
		if (k==1)
			cout<<"not coprime"<<endl;
		else
			cout<<"setwise coprime"<<endl;
	}
	return 0;
}

Measured memory_bytes: 8480
import math
from statistics import mean

N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
xs = [x for x, y in xy]
ys = [y for x, y in xy]


def get_circle_center_and_radius(x1, y1, x2, y2, x3, y3):
    """
    3点を通る円の中心と半径を取得
    """
    d = 2 * ((y1 - y3) * (x1 - x2) - (y1 - y2) * (x1 - x3))
    if d == 0:
        x, y, r2 = -1, -1, -1
    else:
        x = ((y1 - y3) * (y1 ** 2 - y2 ** 2 + x1 ** 2 - x2 ** 2) -
             (y1 - y2) * (y1 ** 2 - y3 ** 2 + x1 ** 2 - x3 ** 2)) / d
        y = ((x1 - x3) * (x1 ** 2 - x2 ** 2 + y1 ** 2 - y2 ** 2) -
             (x1 - x2) * (x1 ** 2 - x3 ** 2 + y1 ** 2 - y3 ** 2)) / -d
        r2 = (x - x1) * (x - x1) + (y - y1) * (y - y1)
    return (x, y), r2


def get_circle_center_and_radius_2p(x1, y1, x2, y2):
    x = (x1 + x2) / 2
    y = (y1 + y2) / 2
    r2 = (x - x1) * (x - x1) + (y - y1) * (y - y1)
    return (x, y), r2


def solve_naive(N, xy):
    if N < 2:
        return 0
    ret = math.inf
    for i in range(N):
        for j in range(N):
            (cx, cy), r2 = get_circle_center_and_radius_2p(
                xy[i][0], xy[i][1], xy[j][0], xy[j][1])
            for x, y in xy:
                if (x - cx) * (x - cx) + (y - cy) * (y - cy) > r2:
                    r2 = math.inf
                    break
            ret = min(ret, r2)
            for k in range(N):
                if i == j or j == k or k == i:
                    continue
                (cx, cy), r2 = get_circle_center_and_radius(
                    xy[i][0], xy[i][1], xy[j][0], xy[j][1], xy[k][0], xy[k][1])
                for x, y in xy:
                    if (x - cx) * (x - cx) + (y - cy) * (y - cy) > r2:
                        r2 = math.inf
                        break
                ret = min(ret, r2)
    return math.sqrt(ret)


ans = solve_naive(N, xy)
print(ans)


Measured memory_bytes: 80084
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main(void) {
	int R[MAX], n;
	
	cin >> n;
	for(int i=0;i<n;i++) cin >> R[i];
	
	int maxv = -2000000000;
	int minv = R[0];
	
	for(int i=1; i<n; i++) {
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}
	
	cout << maxv << endl;
	
	return 0;
}

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

#define LL long long
#define RG register

using namespace std;
template<class T> inline void read(T &x) {
	x = 0; RG char c = getchar(); bool f = 0;
	while (c != '-' && (c < '0' || c > '9')) c = getchar(); if (c == '-') c = getchar(), f = 1;
	while (c >= '0' && c <= '9') x = x*10+c-48, c = getchar();
	x = f ? -x : x;
	return ;
}
template<class T> inline void write(T x) {
	if (!x) {putchar(48);return ;}
	if (x < 0) x = -x, putchar('-');
	int len = -1, z[20]; while (x > 0) z[++len] = x%10, x /= 10;
	for (RG int i = len; i >= 0; i--) putchar(z[i]+48);return ;
}
const int N = 1e5 + 10;
int nxt[17][N], x[N], n, L, Q;
int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	read(n);
	for (int i = 1; i <= n; i++) read(x[i]);
	read(L);
	for (int i = 1; i <= n; i++)
		nxt[0][i] = upper_bound(x + 1, x + n + 1, x[i] + L) - x - 1;
	for (int i = 1; i <= 16; i++)
		for (int j = 1; j <= n; j++)
			nxt[i][j] = nxt[i - 1][nxt[i - 1][j]];
	read(Q);
	while (Q--) {
		int a, b;
		read(a); read(b);
		if (a > b) swap(a, b);
		if (a < b) {
			int ans = 0;
			for (int i = 16; i >= 0; i--)
				if (nxt[i][a] < b)
					a = nxt[i][a], ans += (1 << i);
			printf("%d\n", ans + 1);
		}
	}
	return 0;
}


Measured memory_bytes: 7808
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let mut a = read_vec::<i64>();
    a.sort();
    let mut pairs = vec![];
    for i in 0..m {
        let v = read_vec::<i64>();
        pairs.push((v[1], v[0]));
    }
    pairs.sort();
    pairs.reverse();
    let mut pointer = 0;
    'outer: for (c, b) in pairs {
        for i in 0..b {
            if c > a[pointer] {
                a[pointer] = c;
                pointer += 1;
            } else {
                break 'outer;
            }
            if pointer > a.len() - 1 {
                break 'outer;
            }
        }
    }

    println!("{:?}", a.iter().sum::<i64>());
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 11512
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string S;
    cin >> S;
    
    int l = S.size(), index;
    // 先頭が'A'
    if(S.at(0) != 'A'){
        cout << "WA" << endl;
        return 0;
    }
    // Cが含まれる
    bool flag = false;
    for(int i=2;i<l-1;i++){
        if(S.at(i) == 'C'){
            flag = true;
            index = i;
        }
    }
    if( !flag ){
        cout << "WA" << endl;
        return 0;        
    }
    // 'A', 'C'以外はすべて小文字
    for(int i=1;i<l;i++){
        char tmp = S.at(i);
        if(i != index && isupper(tmp)){
            cout << "WA" << endl;
            return 0;  
        }
    }
    
    cout << "AC" << endl;
 
}

Measured memory_bytes: 256
n=int(input())
dp=[[0]*3 for i in range(n+1)]
for i in range(1,n+1):
    a,b,c=map(int,input().split())
    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a
    dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b
    dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c
print(max(dp[-1]))

Measured memory_bytes: 22772
n=int(input())
l=[0]*n

for x in range(1,10**2+10):
    for y in range(1,10**2+10):
        for z in range(1,10**2+10):
            i=(x+y+z)**2-(x*y+y*z+x*z)
            if i<=n:
                l[i-1]+=1
print(*l,sep="\n")

Measured memory_bytes: 9156
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        long ans = 0;
        for (int i = 1; i <= n; i++) {
            if (i % 3 != 0 && i % 5 != 0) {
                ans += i;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35796
#nまでの素数を列挙
n = 55555

#is_prime[i]にはi-1画素数か否かを示すboolが入る，[0]に1の素数判定がある．
is_prime = [True]*(n+1)
is_prime[0] = False

for i in range(2, n+1):
    if is_prime[i-1]:
        j = 2 * i
        while j <= n:
            is_prime[j-1] = False
            j += i

table = [ i for i in range(1, n+1) if is_prime[i-1]]

N=int(input())

ans=[]
cnt=0
for i in range(len(table)):
    if table[i]%5==1:
        ans.append(table[i])
        cnt+=1
    if cnt==N:
        break
    
        
print(' '.join(map(str, ans)))
    








Measured memory_bytes: 40176
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x;
	cin >> x;
	int ans = 1;
	for(int i = 2; i <= x; ++i){
		int num = i;
		while(num <= x){
			num *= i;
			if(num <= x) chmax(ans, num);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<deque>
#include<cstdio>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>
#define PP pair<P,int>


int n,k,s;
int ans[111111];
const int MA=pow(10,9);

int main(){
    cin>>n>>k>>s;
    rep(i,n)ans[i]=1000000003;
    rep(i,n)ans[i]=s;
    for(int i=k;i<n;i++){
        if(s!=MA)ans[i]=s+1;
        else ans[i]=s-1;
    }
    rep(i,n){
        cout<<ans[i];
        if(i==n-1)cout<<endl;
        else cout<<" ";
    }

    return 0;
}


Measured memory_bytes: 1664
n = int(input())
l = list(map(int, input().split()))
ans = []
for i in range(n):
  for j in range(i,n):
    for k in range(j,n):
      if l[i]+l[j]+l[k]-2*max(l[i],l[j],l[k])>0 and 2<n and len(list(set([l[i],l[j],l[k]])))==3:
        m = sorted([l[i],l[j],l[k]])
        #if m not in ans:
        ans.append(m)
print(len(ans))

Measured memory_bytes: 28156
#include<stdio.h>
#include<string.h>

int main(void){
    int n, tp=0, hp=0;
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        char taro[101], hanako[101];
        scanf("%s %s", taro, hanako);
        if(!strcmp(taro, hanako)){tp++; hp++;}
        else{
            for(int j=0; j<strlen(taro) && j<strlen(hanako); j++){
                if(taro[j]>hanako[j]){tp+=3; break;}
                else if(taro[j]<hanako[j]){hp+=3; break;}
                if(j==strlen(taro)-1 || j==strlen(hanako)-1){
                    if(j==strlen(taro)-1) hp+=3;
                    else tp+=3;
                }
            }
        }
    }
    printf("%d %d\n", tp, hp);
    return 0;
}


Measured memory_bytes: 2028
n = int(input())
A = list(map(int, input().split()))
a = []
c = [0,0,0]
for a_i in A:
    cnt = 0
    while a_i % 2 == 0:
        a_i //= 2
        cnt = min(2,cnt+1)
    c[cnt] += 1
    a.append(cnt)

if (c[2] + c[1] // 2) >= (n // 2):
    print("Yes")
else:
    print("No")



Measured memory_bytes: 20016
#include <iostream>
#include<string>
#include<time.h>
#include<math.h>
#include<stdlib.h>
#include<map>
using namespace std;

//Remaining Balls
int main() {
	string S;
	cin >> S ;
	size_t size = S.length();
	int T,i,L,K;
	
	T = size;
	K = (T - 1) / 2;
	L = (T - 1) / 4;

	int A = 0, B = 0, C = 0;
	for (i = 0; i < (T - 1) / 2; ++i) {
		if (S[i] == S[T - 1 - i]) {
			A++;
		}
	}
	
	for (i = 0; i < L; ++i) {
		if (S[i] == S[K - 1 - i]) {
			B++;
		}
	}
	for (i = 0; i < L; ++i) {
		if (S[((T + 3) / 2) - 1+i] == S[T - 1 - i]) {
			C++;
		}
	}
	/*for (i = (( T + 3) / 2) - 1; i < L; ++i) {
		if (S[i] == S[T - 1 - i]) {
			C++;
		}
	}*/

	//cout << A << B << C << T << K << L;

	if (A == K && B == L && C == L) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	

	


	return 0;
}

Measured memory_bytes: 256