akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const int INF = 1000000000; // 10^9
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    ll H,W;
    cin >> H >> W;
    if(H == 1 || W == 1){
        cout << 1 << endl;
        return 0;
    }
    if(H % 2 == 0){
        cout << H * W / 2 << endl;
    } else if(H % 2 != 0 && W % 2 == 0){
        cout << H * W / 2 << endl;
    } else {
        cout << H * W / 2  + 1 << endl;
    }
}


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

bool d[14][7];
Int a[10][7];


Int cal(Int p,Int n){
  Int res=0;
  for(Int i=0;i<7;i++)
    if(!d[p][i])res+=a[n][i];
  return res;
}

Int uru(Int n){
  if(n%400==0)return 1;
  if(n%100==0)return 0;
  if(n%4==0)return 1;
  return 0;
}

signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n,K,p,q;

  a[0][0]=1;
  a[0][1]=1;
  a[0][2]=1;
  a[0][3]=0;
  a[0][4]=1;
  a[0][5]=1;
  a[0][6]=1;

  a[1][0]=0;
  a[1][1]=0;
  a[1][2]=1;
  a[1][3]=0;
  a[1][4]=0;
  a[1][5]=1;
  a[1][6]=0;

  a[2][0]=1;
  a[2][1]=0;
  a[2][2]=1;
  a[2][3]=1;
  a[2][4]=1;
  a[2][5]=0;
  a[2][6]=1;


  a[3][0]=1;
  a[3][1]=0;
  a[3][2]=1;
  a[3][3]=1;
  a[3][4]=0;
  a[3][5]=1;
  a[3][6]=1;

  
  a[4][0]=0;
  a[4][1]=1;
  a[4][2]=1;
  a[4][3]=1;
  a[4][4]=0;
  a[4][5]=1;
  a[4][6]=0;


  a[5][0]=1;
  a[5][1]=1;
  a[5][2]=0;
  a[5][3]=1;
  a[5][4]=0;
  a[5][5]=1;
  a[5][6]=1;

  a[6][0]=1;
  a[6][1]=1;
  a[6][2]=0;
  a[6][3]=1;
  a[6][4]=1;
  a[6][5]=1;
  a[6][6]=1;

  a[7][0]=1;
  a[7][1]=0;
  a[7][2]=1;
  a[7][3]=0;
  a[7][4]=0;
  a[7][5]=1;
  a[7][6]=0;

  a[8][0]=1;
  a[8][1]=1;
  a[8][2]=1;
  a[8][3]=1;
  a[8][4]=1;
  a[8][5]=1;
  a[8][6]=1;

  a[9][0]=1;
  a[9][1]=1;
  a[9][2]=1;
  a[9][3]=1;
  a[9][4]=0;
  a[9][5]=1;
  a[9][6]=1;
  

  cin>>n>>K;
  while(K--)cin>>p>>q,d[p][q]=1;

  Int c[13],cnt[100][2]={};
  c[4]=c[6]=c[9]=c[11]=30;
  c[1]=c[3]=c[5]=c[7]=c[8]=c[10]=c[12]=31;
  c[2]=28;
  
  for(Int i=1;i<=12;i++)
    for(Int j=1;j<=c[i];j++)
      for(Int k=0;k<=23;k++)
	for(Int l=0;l<=59;l++)
	  for(Int m=0;m<=59;m++){
	    Int res=0;
	    res+=cal(4,i/10);
	    res+=cal(5,i%10);
	    res+=cal(6,j/10);
	    res+=cal(7,j%10);
	    res+=cal(8,k/10);
	    res+=cal(9,k%10);
	    res+=cal(10,l/10);
	    res+=cal(11,l%10);
	    res+=cal(12,m/10);
	    res+=cal(13,m%10);
	    cnt[res][0]++;
	  }

  c[2]=29;
  for(Int i=1;i<=12;i++)
    for(Int j=1;j<=c[i];j++)
      for(Int k=0;k<=23;k++)
	for(Int l=0;l<=59;l++)
	  for(Int m=0;m<=59;m++){
	    Int res=0;
	    res+=cal(4,i/10);
	    res+=cal(5,i%10);
	    res+=cal(6,j/10);
	    res+=cal(7,j%10);
	    res+=cal(8,k/10);
	    res+=cal(9,k%10);
	    res+=cal(10,l/10);
	    res+=cal(11,l%10);
	    res+=cal(12,m/10);
	    res+=cal(13,m%10);
	    cnt[res][1]++;
	  }
  Int ans=0;
  for(Int i=0;i<=9999;i++){
    Int res =0;
    res+=cal(0,i/1000);
    res+=cal(1,i/100%10);
    res+=cal(2,i/10%10);
    res+=cal(3,i%10);
    if(res<=n)ans+=cnt[n-res][uru(i)];
  }
  cout<<ans<<endl;  
  return 0;
}



Measured memory_bytes: 3196
// https://atcoder.jp/contests/abc172/tasks/abc172_d

use proconio::input;

fn main() {
    input! { n: usize, }
    let sum = (1..=n).fold(0, |acc, a| {
        let y = n / a;
        acc + y * (y + 1) * a / 2
    });
    println!("{}", sum);
}


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

using namespace std;
typedef long long ll;
typedef pair <int, int> pp;
#define MAXR 300005
#define MAXP 25
#define A first
#define B second
#define MP make_pair
#define PB push_back
const ll INF = 2e9+13;
const ll MOD = 1e9+7;
int N;
int rec(int x) {
	int ret = 0;
	while(x) {
		ret += x%10;
		x /= 10;
	}
	return ret;
}
int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> N;
	int ans = 1000000;
	for(int i=1; i<N; i++) {
		ans = min(ans, rec(i) + rec(N-i));
	}
	cout << ans << endl;

	
}

Measured memory_bytes: 892
#include<stdio.h>
#include<iostream>
#include<list>
#include<map>
#include<vector>
#include<algorithm>
#include<string.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << x << endl;
using namespace std;

int main(){
    int x[6];
    int sum;

    while(cin >> x[0]){
        range(i,1,6){
            cin >> x[i];
        }
        sum = x[0] + x[1] * 5 + x[2] * 10 + x[3] * 50 + x[4] * 100 + x[5] * 500;
        if(sum >= 1000){
            cout << 1 << endl;
        }else{
            cout << 0 << endl;
        }
    }
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

ll N, M, K;
vector<ll> a;
vector<ll> b;

int main() {
    cin >> N >> M >> K;
    a.assign(N, 0);
    b.assign(M, 0);
    ll b_sum = 0;
    for (int i = 0; i < N; ++i) cin >> a[i];
    for (int i = 0; i < M; ++i) cin >> b[i];
    ll A[N + 1], B[M + 1];
    A[0] = 0; B[0] = 0;
    for (int i = 0; i < N; ++i) A[i + 1] = a[i] + A[i];
    for (int i = 0; i < M; ++i) B[i + 1] = b[i] + B[i];

    ll ans = 0;
    int j = M;
    for (int i = 0; i <= N && A[i] <= K; ++i) {
        while (A[i] + B[j] > K && j > 0) j--;
        ans = max(ans, (ll)(i + j));
    }
    cout << ans << endl;
}

Measured memory_bytes: 9532
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;

int mod = 1e9 + 7;
map<int,int> res;

void prime_factor(int n){
	for(int i=2;i*i<=n;i++){
		while(n%i==0){
			res[i]++;
			n/=i;
		}
	}
	if(n!=1) res[n]++;//	
}

signed main(){
    int n;
    cin >> n;
    rep(i, 2, n + 1){
        prime_factor(i);
    }
    int ans = 1;
    for(map<int, int>::iterator it = res.begin(); it != res.end(); it++){
        // cout << it -> first << " " << it -> second << endl;
        ans = ans * (it -> second + 1) % mod;
    }
    o(ans);
}

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

int main() {
  string str;
  while (getline(cin,str) and str != ".") {
    stack<char> s;
    bool f = true;
    for (char c : str) {
      if (c == '(' || c == '[') {
        s.push(c);
      } else if (c == ')') {
        if (s.empty()) f = false;
        else if (s.top() != '(') f = false;
        else s.pop();
      } else if (c == ']') {
        if (s.empty()) f = false;
        else if (s.top() != '[') f = false;
        else s.pop();
      }
    }
    cout << ((f && s.empty()) ? "yes" : "no") << endl;
  }
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
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; }

ll MOD = 1000000007;
ll INF =1<<30;

int dp[111][101011];
int main(){
    int N,W;
    cin >> N >> W;
    vector<int>w(N),v(N);
    rep(i,N) cin >> w[i] >> v[i];
    rep(j,101010) dp[0][j] = 1001000000;
    dp[0][0] = 0;
    rep(i,N+1){
        rep(j,101010){
            dp[i+1][j]=dp[i][j];
            if(j-v[i]>=0){
                dp[i+1][j] = min(dp[i+1][j],dp[i][j-v[i]]+w[i]);
            }
        }
    }
    int ans=0;
    rep(j,101010){
        if(dp[N][j]<=W){
            ans = j;
        }
    }
    cout << ans <<endl;
}


Measured memory_bytes: 43840
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;

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

  int W, H, N;
  cin >> W >> H >> N;
  int a1 = 0, a2 = W, a3 = 0, a4 = H;
  rep(i,N){
    int x, y, a;
    cin >> x >> y >> a;
    if(a == 1){
      a1 = max(a1, x);
    }
    if(a == 2){
      a2 = min(a2, x);
    }
    if(a == 3){
      a3 = max(a3, y);
    }
    if(a == 4){
      a4 = min(a4, y);
    }
  }
  cout << max((int)0, a2-a1) * max((int)0, a4-a3) << endl;
}

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

int main(){
	int n,cnt[100000] = {},ma = 0;
	cin >> n;
	for(int i = 0;i < n;i++){
		int a;
		cin >> a;
		cnt[a]++;
	}
	for(int i = 1;i < 99999;i++) ma = max(ma,cnt[i - 1] + cnt[i] + cnt[i + 1]);
	cout << ma << endl;
	return 0;
}

Measured memory_bytes: 640
// Nurbakyt Madibek
// Look at my code! IT'S AWESOME

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <cassert>
#include <unordered_map>
#include <bitset>
#include <unordered_set>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define mp make_pair
#define sz(a) (int)((a).size())
#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%lld"
#endif
#define fname "."

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;

const int mod = (int)1e9 + 7;
const int inf = (int)1e9 + 123;
const ll infl = (ll)1e18 + 123;
const double eps = 1e-10;

const int MAX_N = (int)3e5 + 123;

int main() {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    int a, b, c;
    int ptr = 0;
    cin >> a >> b >> c;
    while(1) {
        if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1)
            break;
        ptr++;
        if (ptr > 10000000) {
            ptr = -1;
            break;
        }
        int na = b / 2 + c / 2;
        int nb = a / 2 + c / 2;
        int nc = a / 2 + b / 2;
        a = na, b = nb, c = nc;
    }
    cout << ptr << endl;
    return 0;
}


Measured memory_bytes: 256
x = int(input())

# 自然数m以下の素数を返す
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n + 1):
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

def prime_numbers_under(m):
    # 素数を保持するset
    primes = set()

    # 2以上m以下の素数を数え上げる
    n = 2
    while n <= m:
        # 自身より小さい全ての素数で割り切れなければ、素数とみなせる
        if all(n % i != 0 for i in primes):
            primes.add(n)
        n += 1

    return primes

# 自然数m以上の素数を返す
def prime_numbers_over(m):
    # 素数を保持するset
    # primes = set()
    global p

    if m in p:
        return m

    while True:
        # 自身より小さい全ての素数で割り切れなければ、素数とみなせる
        if all(m % i != 0 for i in p):
            return m
        m += 1

# p = prime_numbers_under(x)
p = primes(x)

print(prime_numbers_over(x))

Measured memory_bytes: 40816
#include <stdio.h>

#define N 1000000007;

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  long int c[2001][2001], ans;
  c[0][0] = 1;
  for (size_t i = 1; i < 2001; i++) {
    c[i][0] = 1; c[i][i] = 1;
    for (size_t j = 1; j < i; j++) {
      c[i][j] = (c[i-1][j] + c[i-1][j-1])%N;
    }
  }
  for (size_t i = 1; i < k+1; i++) {
    if (n-k+1<i) {
      ans = 0;
    }else {
      ans = (c[k-1][i-1] * c[n-k+1][i])%N;
    }
    printf("%ld\n", ans);
  }
  return 0;
}


Measured memory_bytes: 31360
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    int n;
    cin>>n;
    int x=n-1;
    //1つ小さい数の約数の個数
    set<int>st;
    for (int i = 1; i*i <= x; i++)
    {
        if(x%i==0){
            st.insert(i);
            if(i*i!=x) st.insert(x/i);
        }
    }
    //1を除く
    int ans=st.size() -1 ;
    vector<int>v;
    for (int i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            v.push_back(i);
            if (i * i != n)
                v.push_back(n/i);
        }
    }
    sort(ALL(v));
    //show(v);
    int cnt=0;
    for (int i = 0; i < v.size(); i++)
    {
        if(v[i]==1) continue;
        int c=n;
        while(c >= v[i]){
            if(c%v[i]==0) c/=v[i];
            else c%=v[i];
            //cerr<<c<<endl;
        }
        if(c==1) cnt++;
    }
    cout<<ans+cnt<<endl;
    return 0;
}

Measured memory_bytes: 384
function Main(input){
  var n = input.split(" ");
  for(i=0;i<=2;i++){
    n[i] = parseInt(n[i],10);
  }
  var ns =n.sort(function(a,b){
    return a - b;
  });
  var mix = [];
  mix[0] = n.pop();
  mix[1] = n.pop();
  var answer = ns[0] + parseInt(mix.join(""),10);
  console.log(answer);
}
    Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 21192
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

ans = abs(T - 0.006 * H[0] - A)
sel = 1
for i in range(N):
    gap = abs(T - 0.006 * H[i] - A)
    if ans > gap:
        ans = gap
        sel = i+1
print(sel)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define MAXN 110
#define inf 0x7fffffff
int head[5+MAXN<<1],dep[5+MAXN<<1],num=-1,s,t,n,m,cur[5+MAXN<<1];
struct po
{
	int nxt,to,w;
}edge[MAXN*MAXN*2];
struct point
{
	int x,y;
}a[MAXN],b[MAXN];
inline void add_edge(int from,int to,int w)
{
	edge[++num].nxt=head[from];
	edge[num].to=to;
	edge[num].w=w;
	head[from]=num;
}
inline void add(int from,int to,int w)
{
	add_edge(from,to,w);
	add_edge(to,from,0);
}
inline bool bfs()
{
	memset(dep,0,sizeof(dep));
	queue<int>q;
	while(!q.empty()) q.pop();
	q.push(s); dep[s]=1;
	while(!q.empty()){
		int u=q.front(); q.pop();
		for(int i=head[u];i!=-1;i=edge[i].nxt){
			int v=edge[i].to;
			if(edge[i].w&&!dep[v]){
				dep[v]=dep[u]+1;
				if(v==t) return 1;
				q.push(v);
			}
		}
	}
	return 0;
}
inline int dfs(int u,int low)
{
	if(u==t) return low;
	int diss=0;
	for(int& i=cur[u];i!=-1;i=edge[i].nxt){
		int v=edge[i].to;
		if(edge[i].w>0&&dep[v]==dep[u]+1){
			int check=dfs(v,min(edge[i].w,low));
			if(check){
				diss+=check;
				low-=check;
				edge[i].w-=check;
				edge[i^1].w+=check;
				if(low==0) break;
			}
		}
	}
	return diss;
}
inline int dinic()
{
	int ans=0;
	while(bfs()){
		for(int i=s;i<=t;i++) cur[i]=head[i];
			while(int d=dfs(s,inf)) ans+=d;
	}
	return ans;
}
int main()
{
	memset(head,-1,sizeof(head));
	cin>>n;s=0,t=2*n+1;
	for(int i=1;i<=n;i++) cin>>a[i].x>>a[i].y,add(s,i,1);
	for(int i=1;i<=n;i++) cin>>b[i].x>>b[i].y,add(i+n,t,1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++) if(a[i].x<b[j].x&&a[i].y<b[j].y) add(i,j+n,1);
	cout<<dinic();
}

Measured memory_bytes: 384
import Data.List
main=do
    ctx<-getContents
    print $ length $ dup $ sort [read x::Int|x<-tail (lines ctx)]
dup :: [Int]->[Int]
dup []=[]
dup (x:y:xs)=if x==y then dup (xs) else x:dup (y:xs)
dup (x:[]) = [x]


Measured memory_bytes: 17660
N = int(input())
num_list=[]
for num in range(1,N+1):
  counter=0
  while True:
    if int(num/2)==num/2:
      num/=2
      counter+=1
    else:
      break
  num_list.append(counter)
print(num_list.index(max(num_list))+1)

Measured memory_bytes: 2940
#include <iostream>
#include <stdlib.h>

using namespace std;

int main(void){
    
    int A,B,C;
    cin >> A >> B >> C;

    if(C >= A and C<=B){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cstring>
#include <climits>
using namespace std;
#define ll long long
#define FOR(i,n) for(int i=0;i<n;i++)
#define sz(x) (int)(x.size())
#define all(x) (x).begin(),(x).end()
template<typename tp> void read(tp &x) {cin >> x;}
template<typename tp, typename... Args> void read(tp& x, Args&... args) {read(x);read(args...);}
const int mxN = (int)1e5,INF = (int)1e9,MOD = (int)1e9+7;

void solve()
{
	int n,k;
	string s;
	read(n,k,s);
	s[k-1] = tolower(s[k-1]);
	cout << s;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int test = 1;
	//read(test);
	while(test--)
		solve();
	return 0;
}



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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
 
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define form(i, n) for (size_t i = 0; i < size_t(n); ++i)
#define forn(i, n) for (size_t i = 1; i <= size_t(n); ++i)
template<class T> using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long mod(long long a, long long b) { return (a%b+b)%b; }
long long gcd(long long x, long long y) { return __gcd(x, y); }
long long lcm(long long x, long long y) { return x * 1ll * y / gcd(x, y); }
 
 
const unsigned long long MAXN = 7777777777777777777;
const long long SIZE = 3e5 + 5;
const long long MOD = 1e9 + 7;


int N, res;
string s;


int main() { speedhack()

	cin >> N;

	cin >> s;


	for (int i = N - 1, j = 0; i >= 0; i--) {
		if (s[i] == 'R') {
			while (s[j] == 'R' && j < N) ++j;
			if (j < i) { 
				swap (s[j++], s[i]);
				++res;
			} else 
				break;
		}
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 3772
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <bitset>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10



int main() {
	vector<int> a(3); cin >> a[0] >> a[1] >> a[2];
	int K; cin >> K;
	sort(a.begin(), a.end());
	REP(i, K) {
		a[2] *= 2;
	}
	print(a[0] + a[1] + a[2]);
	


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    int N,A,B; cin >> N >> A >> B; ll ans=0;
    int X[N]; rep(i,N) cin >> X[i];
    rep(i,N-1){
        int a=X[i+1]-X[i];
        if(a*A>B) ans+=B;
        else ans+=a*A;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

        int N = Integer.parseInt(sc.nextLine());
        String[] s = sc.nextLine().split(" ");
        List<Integer> xs = new ArrayList<>();
        for (String s1 : s) {
            xs.add(Integer.parseInt(s1));
        }

        int min = Integer.MAX_VALUE;
        for (int p = 1; p <= 100; p++) {
            int sum = 0;
            for (Integer x : xs) {
                sum += (x-p) * (x-p);
            }
            if(sum < min) {
                min = sum;
            }
        }
        System.out.println(min);
    }
}


Measured memory_bytes: 23380
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
static const double EPS = 1e-8;
typedef long long ll;


const int MAX = 100000;
const int mod = 100000007;

int dp5[MAX + 5], dp3[MAX + 3];
int dpp5[MAX + 6], dpp3[MAX + 4];

char buf[MAX + 1];

int main()
{
	dp5[0] = dp3[0] = 1;
	for (int i = 0; i < MAX; ++i)
	{
		for (int j = 1; j <= 5; ++j)
			(dp5[i + j] += dp5[i]) %= mod;
		for (int j = 1; j <= 3; ++j)
			(dp3[i + j] += dp3[i]) %= mod;
	}
	for (int i = 1; i <= MAX; ++i)
	{
		dpp5[i + 5] = ((dpp5[i] += dp5[i]) %= mod);
		dpp3[i + 3] = ((dpp3[i] += dp3[i]) %= mod);
	}

	while (scanf("%s", buf), *buf != '#')
	{
		char* p = buf;
		ll res = 1;

		char c = '@';
		int count = 1;
		do
		{
			if (*p == c)
				++count;
			else
			{
				if (c != '8' && c != '0')
					res *= dpp5[count];
				else
					res *= dpp3[count];

				res %= mod;
				c = *p;
				count = 1;
			}
		} while (*p++ != '\0');

		printf("%d\n", res);
	}

	return 0;
}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    ll d=0;
    
    string ans = "NO";
    for(int i=0; i < 256; i++){
        if(d%b==c) ans = "YES";
        d+=a;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,n) REP(i,0,n)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using namespace std;
typedef long long ll;

int main() {
    int k;
    cin >> k;
    if (k % 2 == 1)
        cout << (k / 2) * (k / 2 + 1) << endl;
    else
        cout << (k / 2) * (k / 2) << endl;
    return 0;
}



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

void solve() 
{
    int n;cin>>n;
    string s;int ab=0,a=0,b=0,ans=0;
    REP(i,n){
        cin>>s;
        REP(i,s.size()-2){
            if(s[i]=='A'&&s[i+1]=='B')ans++;
        }
        if(s[0]=='B')b++;
        if(s[s.size()-1]=='A')a++;
        if(s[0]=='B'&&s[s.size()-1]=='A')ab++;
    }
    cout<<ans+min(a,b)+(a==b&&b==ab&&ab!=0?-1:0)<<endl;
}

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

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
  int gx,gy;
  while(scanf("%d %d",&gx,&gy)){
    if(gx == 0 && gy == 0)break;
    int chizu[gy+2][gx+2];
    for(int i = 0;i < gy+1;i++)for(int j = 0;j < gx+1;j++)chizu[i][j] = 0;
    chizu[0][1] = 1;
    int n;
    scanf("%d",&n);
    int kx,ky;
    while(n--){
      scanf("%d %d",&kx,&ky);
      chizu[ky][kx] = 1000000;
    }

    chizu[0][1] = 1;
    
    for(int i = 1;i < gy+1;i++){
      for(int j = 1;j < gx+1;j++){
	/*for(int k = 0;k < gy+1;k++){
	  for(int l = 0;l < gx+1;l++){
	    cout << chizu[k][l];
	  }
	  cout << endl;
	  }
	  cout << endl;*/
	if(chizu[i][j] != 1000000){
	  if(chizu[i-1][j] == 1000000 && chizu[i][j-1] == 1000000){
	    chizu[i][j] = 0;
	  }
	  else if(chizu[i-1][j] == 1000000){
	    chizu[i][j] = 0+chizu[i][j-1];
	  }
	  else if(chizu[i][j-1] == 1000000){
	    chizu[i][j] = chizu[i-1][j]+0;
	  }
	  else chizu[i][j] = chizu[i-1][j]+chizu[i][j-1];
	}
      }
    }
    
    cout << chizu[gy][gx] << endl;
  }
}

Measured memory_bytes: 1208
#include<stdio.h>
 
int main()
{
  int t[4][14];
  int n, i,j,c;
  char m, d;
  for(i=0; i < 4; i++){
    for(j=0; j < 14; j++){
      t[i][j]=0;
    }
  }
 scanf("%d", &c);
  for(i = 0; i < c; i++){
    scanf("%c", &d);
    scanf("%c %d", &m, &n);
    if(m == 'S'){
      t[0][n] = 1;
    }
    else if(m == 'H'){
      t[1][n] = 1;
    }
    else if(m == 'C'){
      t[2][n] = 1;
    }
    else if(m == 'D'){
      t[3][n] = 1;
    }
  }
  for(j=1; j < 14; j++){
    if(t[0][j] != 1){
      printf("S %d\n", j);
    }
  }
 
 for(j=1; j < 14; j++){
    if(t[1][j] != 1){
      printf("H %d\n", j);
    }
  }
 
 for(j=1; j < 14; j++){
    if(t[2][j] != 1){
              printf("C %d\n", j);
    }
  }
 
 for(j=1; j < 14; j++){
    if(t[3][j] != 1){
      printf("D %d\n", j);
    }
  }
 return 0;
}
 



Measured memory_bytes: 2052
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
struct C {
    int x;
    int y;
    int r;
    bool operator<(const C& c) const
    {
        return r < c.r;
    }
};

inline bool contain(const C& c, const int x, const int y)
{
    return hypot(c.x - x, c.y - y) < c.r;
}

inline bool contain(const C& c1, const C& c2)  // c1 < c2
{
    return hypot(c1.x - c2.x, c1.y - c2.y) + c1.r < c2.r;
}

inline bool separate(const C& c1, const C& c2)
{
    return hypot(c1.x - c2.x, c1.y - c2.y) > c1.r + c2.r;
}

struct Graph {
    Graph(const int n)
    {
        edge.resize(n);
    }
    void addEdge(const int from, const int to)
    {
        edge[from].push_back(to);
    }
    vector<vector<int>> edge;
};


int main()
{
    while (true) {
        int N;
        cin >> N;
        if (N == 0) {
            break;
        }
        int sx, sy, gx, gy;
        cin >> sx >> sy >> gx >> gy;
        vector<C> s;
        vector<C> t;
        for (int i = 0; i < N; i++) {
            int x, y, r;
            cin >> x >> y >> r;
            C c{x, y, r};
            const bool S = contain(c, sx, sy);
            const bool T = contain(c, gx, gy);
            if (S and not T) {
                s.push_back(c);
            }
            if (T and not S) {
                t.push_back(c);
            }
        }
        sort(s.begin(), s.end());
        sort(t.begin(), t.end());
        const int S = s.size();
        const int T = t.size();
        Graph sg(S + 1);
        Graph tg(T + 1);
        for (int i = 1; i <= S; i++) {
            sg.addEdge(0, i);
        }
        for (int i = 1; i <= S; i++) {
            for (int j = i + 1; j <= S; j++) {
                if (contain(s[i - 1], s[j - 1])) {
                    sg.addEdge(i, j);
                }
            }
        }
        for (int i = 1; i <= T; i++) {
            tg.addEdge(0, i);
        }
        for (int i = 1; i <= T; i++) {
            for (int j = i + 1; j <= T; j++) {
                if (contain(t[i - 1], t[j - 1])) {
                    tg.addEdge(i, j);
                }
            }
        }
        vector<int> sdp(S + 1, 0);
        vector<int> tdp(T + 1, 0);
        int smax = 0;
        for (int i = 0; i <= S; i++) {
            for (const int to : sg.edge[i]) {
                sdp[to] = max(sdp[to], sdp[i] + 1);
                smax = max(smax, sdp[to]);
            }
        }
        int tmax = 0;
        for (int i = 0; i <= T; i++) {
            for (const int to : tg.edge[i]) {
                tdp[to] = max(tdp[to], tdp[i] + 1);
                tmax = max(tmax, tdp[to]);
            }
        }
        int ans = max(smax, tmax);
        for (int i = 0; i < S; i++) {
            for (int j = 0; j < T; j++) {
                if (separate(s[i], t[j])) {
                    ans = max(ans, sdp[i + 1] + tdp[j + 1]);
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 5544
let g = [| 0; 1; 3; 1; 2; 1; 2; 1; 1; 2; 1; 2; 1 |]

let solve a b = if g.(a) == g.(b) then "Yes" else "No"

let () = Printf.printf "%s\n" (Scanf.scanf "%d %d" solve)

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

int cnt = 2, seze = 5e4, A = 0, B = 1, tA, tB, A0, A1, B0, B1;
int pow2[110], wA[110], wB[110], tmp[110];

int main() {
	// freopen("in.txt", "w", stdout);
	puts("32926");
	puts("+ 0 1 3");
	puts("+ 3 3 3");
	puts("< 1 3 3");
	pow2[0] = ++cnt;
	for (int i = 1; i <= 30; ++i) pow2[i] = ++cnt, printf("+ %d %d %d\n", pow2[i - 1], pow2[i - 1], pow2[i]);
	tA = ++cnt, tB = ++cnt;
	printf("+ %d %d %d\n", A, pow2[0], tA);
	printf("+ %d %d %d\n", B, pow2[0], tB);
	A0 = ++seze, A1 = ++seze, B0 = ++seze, B1 = ++seze;
	for (int i = 30; ~i; --i) {
		printf("+ %d %d %d\n", pow2[i], A0, A1);
		wA[i] = ++cnt;
		printf("< %d %d %d\n", A1, tA, wA[i]);
		tmp[0] = ++seze;
		printf("+ %d %d %d\n", wA[i], tmp[0], tmp[0]);
		for (int j = 1; j <= i; ++j) tmp[j] = ++seze, printf("+ %d %d %d\n", tmp[j - 1], tmp[j - 1], tmp[j]);
		printf("+ %d %d %d\n", A0, tmp[i], A0);
	}
	for (int i = 30; ~i; --i) {
		printf("+ %d %d %d\n", pow2[i], B0, B1);
		wB[i] = ++cnt;
		printf("< %d %d %d\n", B1, tB, wB[i]);
		tmp[0] = ++seze;
		printf("+ %d %d %d\n", wB[i], tmp[0], tmp[0]);
		for (int j = 1; j <= i; ++j) tmp[j] = ++seze, printf("+ %d %d %d\n", tmp[j - 1], tmp[j - 1], tmp[j]);
		printf("+ %d %d %d\n", B0, tmp[i], B0);
	}
	for (int i = 0; i <= 30; ++i)
		for (int j = 0; j <= 30; ++j) {
			tmp[0] = ++seze;
			printf("+ %d %d %d\n", wA[i], wB[j], tmp[0]);
			printf("< %d %d %d\n", pow2[0], tmp[0], tmp[0]);
			for (int k = 1; k <= i + j; ++k) tmp[k] = ++seze, printf("+ %d %d %d\n", tmp[k - 1], tmp[k - 1], tmp[k]);
			printf("+ %d %d %d\n", 2, tmp[i + j], 2);
		}
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

ll f(ll X){
  ll res;
  if (X % 2 == 0){
    if ((X / 2) % 2 == 0) res = X;
    else res = 1^X;
  }
  else {
    if (((X + 1) / 2) % 2 == 0) res = 0;
    else res = 1;
  }
  return res;
}

int main(){
  ll A, B; cin >> A >> B;
  ll ans = f(A - 1)^f(B);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;

int main(){
    int N;
    int64_t A,B;
    cin>>N>>A>>B;
    int64_t X[100000];
    for(int i=0;i<N;i++){
        cin>>X[i];
    }
    int x = B/A;
    if(A*x >= B){
        x--;
    }
    int64_t res=0;
    for(int i=1;i<N;i++){
        int64_t t = X[i]-X[i-1];
        if(t <= x){
            res += A*t;
        }else{
            res += B;
        }
    }
    cout<<res<<endl;
    
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <math.h>
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
typedef long long ll;
using namespace std;

int main() {
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	
	string t;
	cin >> t;
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());
	
	if (s < t) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

using namespace std;

int main()
{
    int n, a[200000];
    long long int allsum = 0, partsum = 0;
    long long int ans = 1e10;
    cin >> n;

    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        allsum += a[i];
    }

    if(n == 2) {
        cout << abs(a[0] - a[1]) << endl;
        return 0;
    }
    
    partsum += a[0];

    for(int i = 1; i < n - 1; ++i) {
        ans = min(ans, abs(partsum - (allsum - partsum))); 
        partsum += a[i];
    }
    cout << ans << endl;
    return 0;
} 


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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch){
  if(ch == 'A') return 1;
  else if(ch == 'C')return 2;
  else if(ch == 'G') return 3;
  else if(ch == 'T') return 4;
  else return 0;
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for(i=0;i<strlen(str);i++){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M;}
int h2(int key){ return 1 + (key % (M-1));}

int find(char str[]){
  long long key, i, h;
  key = getKey(str);
  for(i=0;;i++){
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0) return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key, i, h;
  key = getKey(str);
  for(i=0;;i++){
    h = (h1(key) + i * h2(key)) %M;
    if(strcmp(H[h], str) == 0) return 1;
    else if(strlen(H[h]) == 0){
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}


int main(){
  int i, n, h;
  char str[L], com[9];
  for(i=0;i<M;i++) H[i][0] = '\0';
  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%s%s", com, str);

    if(com[0] == 'i'){
      insert(str);
    }else{
      if(find(str)){
	printf("yes\n");
      }else{
	printf("no\n");
      }
    }
  }
  return 0;
}

    



Measured memory_bytes: 16032
N = int(input())
H = list(map(int,input().split()))
ans = 0
c = 0
h = H[0]
for i in range(1,N):
    if h >= H[i]:
        c += 1
    else:
        ans = max(ans,c)
        c = 0
    h = H[i]
ans = max(ans,c)
print(ans)

Measured memory_bytes: 63984
import java.util.*;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		int M  = keyboard.nextInt();
		long K  = keyboard.nextLong();
		
		long[] A  = new long[N+1];
		long[] B  = new long[M+1];
		long Asum = 0;
		long Bsum = 0;
		int countA = 0;
		int countB = 0;
		int Max = 0;
			
		for(int i=1; i<=N; i++) {
			Asum += keyboard.nextInt();
			A[i] = Asum;
			if(Asum <= K) {
				countA++;
			}
		}
		
		for(int j=1; j<=M; j++) {
			Bsum += keyboard.nextInt();
			B[j] = Bsum;
		}
		
		for(int k= countA; k >=0 ; k--) {
			while(countB+1 <= M && A[k]+B[countB+1]<= K) {
				countB++;
			}
			if(Max < k + countB) {
				Max = k + countB;
			}
		}

		System.out.print(Max);
		keyboard.close();	
	}
}

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

ans =[[0,0] for _ in range(M)]

AB = [list(map(int,input().split())) for i in range(M)]

to_list = [[] for _ in range(N)]
prev = [0]*N
for a,b in AB:
  to_list[a-1].append(b-1)
  to_list[b-1].append(a-1)

que = [0]
marked = {0}
for i in que:
  for j in to_list[i]:
    if j in marked: 
      continue
    que.append(j)
    marked.add(j)
    prev[j] = i+1
print("Yes")
print(*prev[1:],sep = "\n")
      

Measured memory_bytes: 163656
#include<bits/stdc++.h>
using namespace std;
#define inf 100000000000000000
#define ll long long int
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}

int main(){
	//mahakal();fast;

	ll n ,ps=0;
	cin>>n ;
	map<string , ll> mp;
	for(ll i=0;i<n;i++){
		string str;
		cin>>str;
		if(mp.find(str) == mp.end())
            mp[str] = 0;
		mp[str]++;
		ps=max(ps,mp[str]);
	}
	for(auto x: mp){
		if(x.s==ps){
			cout<<x.f<<endl;
		}
	}


	return 0;
}

Measured memory_bytes: 25216
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
vector<ll> num;
vector<ll> p;

ll findNum(int N, ll X)
{
    if(N==0)
        return 1;

    if(X==1)
        return 0;
    else if(X<=num[N]/2)
    {
        return findNum(N-1, X-1);
    }
    else if(X==(num[N]/2+1))
    {
        return 1+p[N-1];
    }

    return 1 + p[N-1] + findNum(N-1, X-2-num[N-1]);

}

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

    num.resize(50);
    p.resize(50);

    num[0] = 1;
    p[0] = 1;
    for(int i=0; i<50; ++i)
    {
        num[i+1]= 2 * num[i] + 3;
        p[i+1] = 2 * p[i] + 1;
    }

    ll ans = findNum(N, X);

    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> L(N);
    REP(i,N) cin >> L[i];
    sort(L.begin(),L.end());
    ll ans = 0;
    int cnt = 0;
    REP(i,N) for(int j=i+1;j<N;j++){
        int cand = lower_bound(L.begin(),L.end(), L[i] + L[j]) - L.begin();
        cand -= (j + 1);
        if(cand > 0) ans+=cand;
    }
    cout << ans << endl;
}

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

#define INF (int(1e9)+1)
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=100005;
int n,ans;
pii dat[maxn];
int pre[maxn],suf[maxn]; 

int main(){
	scanf("%d",&n);
	REP(i,n)scanf("%d%d",&dat[i].fst,&dat[i].snd);
	sort(dat+1,dat+1+n);
	pre[0]=INF;
	REP(i,n)pre[i]=min(pre[i-1],dat[i].snd);
	suf[n+1]=INF;
	for(int i=n;i>=1;i--)suf[i]=min(suf[i+1],dat[i].snd);
	REP(i,n){
		int cl=i==n?dat[n-1].fst:dat[n].fst,cr=min(pre[i-1],suf[i+1]);
		ans=max(ans,dat[i].snd-dat[i].fst+1+max(0,cr-cl+1));
	}
	REP(i,n){
		int cur=max(pre[i]-dat[i].fst+1,0);
		if(i<n)cur+=max(suf[i+1]-dat[n].fst+1,0);
		ans=max(ans,cur);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1920
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

ll solve(){
    ll res = 0;
    ll A,B,C,X,Y; cin >> A >> B >> C >> X >> Y;
    ll minc = min(X,Y);
    res += min(A*minc + B*minc,C*minc*2);
    X-=minc; Y-=minc;
    
    if(X){
        res += min(A*X,C*X*2);
    }
    if(Y){
        res += min(B*Y,C*Y*2);
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;

#define SZ(x) ((int)x.size())

const ll base = (ll)1e9+7;
ll n, k, dp[5005];
vector<ll> d;

ll fast_pw(ll x, ll y) {
	if (y == 0) return 1;
	if (y == 1) return x;
	ll tmp = fast_pw(x, y / 2ll);
	tmp = (tmp * tmp) % base;
	if (y % 2ll) tmp = (tmp * x) % base;
	return tmp;
}

int main() {
	scanf("%lld%lld", &n, &k);
	for (ll i = 1; i*i <= n; ++i) if (n % i == 0) {
		d.push_back(i);
		if (n / i != i) d.push_back(n / i);
	}
	sort(d.begin(), d.end());
	ll ans = 0;
	for (int i = 0; i < SZ(d); ++i) {
		dp[i] = fast_pw(k, d[i] / 2 + d[i] % 2);
		for (int j = 0; j < i; ++j)
			if (d[i] % d[j] == 0)
				dp[i] = (dp[i] - dp[j] + base) % base;
		if (d[i] % 2 == 0) ans = (ans + dp[i] * (ll)(d[i] / 2) % base) % base;
		else ans = (ans + dp[i] * (ll)d[i] % base) % base;
	}
	printf("%lld", ans);
	return 0;
}

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

typedef vector<int> vi;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, i, s = 0, e;
	cin >> n;
	vi as(n);
	for (i = 0; i < n - 1; i++) {
		cin >> e;
		if (i == 0)
			as[i] = e;
		else
			as[i] = min(as[i], e);
		as[i + 1] = e;
	}

	for (i = 0; i < n; i++)
		s += as[i];
	
	cout << s << "\n";
	return 0;
}

Measured memory_bytes: 256
from collections import deque


'''UnionFindクラス'''
class UnionFind:

    def __init__(self, n):
        self.parent =  [-1 for _ in range(n)]

    def root(self, x):
        '''根を返す'''
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]

    def merge(self, x, y):
        '''xとyの根を結合する'''
        x = self.root(x)
        y = self.root(y)
        if x != y:
            if self.parent[x] > self.parent[y]:
                x, y = y, x
            self.parent[x] += self.parent[y]
            self.parent[y] = x
        return

    def is_same(self, x, y):
        '''xとyの根が同じかどうかを返す（根が同じ:True、根が異なる:False）'''
        return self.root(x) == self.root(y)

    def get_size(self, x):
        '''xが含まれる木の要素数を返す'''
        return -self.parent[self.root(x)]


n, m = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]

graph = [[] for i in range(n)]
for i in range(m):
    graph[info[i][0] - 1].append([info[i][1] - 1, info[i][2]])
    graph[info[i][1] - 1].append([info[i][0] - 1, info[i][2]])

uf = UnionFind(n)
visited = [False]*n
ans = 0
for i in range(n):
    if not visited[i]:
        ans += 1
        visited[i] = True
        q = deque()
        q.append(i)
        while q:
            pos = q.pop()
            for j, cost in graph[pos]:
                if not visited[j]:
                    visited[j] = True
                    q.append(j)
print(ans)


Measured memory_bytes: 64320
def main():
    N = int(input())
    R = []
    for _ in range(N):
        x, l = map(int, input().split())
        R.append((x - l, x + l))
    R.sort(key=lambda x: x[1])
    r = 0
    m = -10**10
    for xl, xr in R:
        if m <= xl:
            m = xr
            r += 1
    print(r)

main()


Measured memory_bytes: 18240
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;
#define IOS {ios :: sync_with_stdio(false); cin.tie(0);cout.tie(0); }
#define F first
#define S second
#define pb push_back
typedef long double ld;
#define deci(n) cout << fixed << setprecision(n);
typedef long long ll;

#define mem0(x)  memset(x,0,sizeof(x));
#define mem1(x)  memset(x,1,sizeof(x));
#define memm1(x) memset(x,-1,sizeof(x));
#define all(a) a.begin(), a.end()
#define pll pair<ll, ll>
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define fori2(n) for(ll i=1;i<=n;i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define forj2(n) for(ll j=1;j<=n;j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define fork2(n) for(ll k=1;k<=n;k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
const ll md = 1e9 + 7;

#define BSET(a, p) ((a) | (1ll << (p)))
#define BCHK(a, p) ((a) & (1ll << (p)))
#define BXOR(a, p) ((a) ^ (1ll << (p)));
#define BREM(a, p) (BCHK(a, p)?(BXOR(a, p)):(a))
#define BSHO(a, N) (bitset<N>(a))
// const ll N = 100005;
// ll fac[N] = {1};
// #define calfac for(ll i=1  ;i<N;i++) fac[i] = (fac[i-1]*i)%md;
// ll C[N+1][M+1]; 
// void  ncr(){
//     ll n = N,k = M; 
//     for (ll i = 0; i <= n; i++) { 
//         for (ll j = 0; j <= min(i, k); j++) { 
//             if (j == 0 || j == i)  C[i][j] = 1; 
//             else C[i][j] = C[i - 1][j - 1] +  C[i - 1][j]; 
//         } 
//     } 
// } 


#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update> 
// Ordered set docs:
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}
ll modInv(ll a)
{
    return pow(a,md-2);
}
 
// ll nCr(ll n,ll r)
// {
//     return (fac[n]*modInv((fac[r]*fac[n-r])%md))%md;
// }

 
ll po(ll x,ll n){
    if(n==0) return 1;
    if(n%2==1) return (x*po(x,n-1));
    else {
        ll k=po(x,n/2);
        return (k*k);
    }
}
 
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
}
const ll N = 3003; 
ld dp[N][N];
ld p[N];

int32_t main(){
    IOS;
    deci(12);
    ll i,j,k,n,m;
    cin >> n;
    fori2(n) cin >> p[i];
    dp[1][1] = p[1];
    dp[1][0] = 1 - p[1];
    if(n==1) {cout << dp[1][1]<<"\n";
    return 0;}
    ld ans =0 ;
    for(i = 2 ; i <= n ; i++){
        for(j = 0 ; j <= i ; j++){
            dp[i][j] = dp[i-1][j]*(1 - p[i]);
            if(j > 0){
                dp[i][j] += dp[i-1][j-1]*p[i];
            }
            if(i==n && j > i/2 ) ans += dp[i][j];
        }
    }
    cout << ans<<"\n";
} 

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

int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<int> r(a), g(b), no(c);
  rep(i, a) cin >> r[i];
  rep(i, b) cin >> g[i];
  rep(i, c) cin >> no[i];
  sort(r.begin(), r.end());
  sort(g.begin(), g.end());
  sort(no.begin(), no.end());
  int ri = a-x, gi = b-y, noi = c;
  while (noi > 0) {
    if ((ri < a) && (gi < b)) {
      if (min(r[ri], g[gi]) > no[noi-1]) break;
      noi--;
      if (r[ri] < g[gi]) ri++;
      else gi++;
    } else if (ri < a) {
      if (r[ri] < no[noi-1]) {ri++; noi--;}
      else break;
    } else if (gi < b) {
      if (g[gi] < no[noi-1]) {gi++; noi--;}
      else break;
    } else break;
  }
  ll ans = 0;
  for (int i=ri; i<a; i++) ans += r[i];
  for (int i=gi; i<b; i++) ans += g[i];
  for (int i=noi; i<c; i++) ans += no[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#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 PB push_back
#define ar2 array<int, 2>
typedef long long LL;
const LL P = 998244353;
const int N = 2e5+5;
mt19937 rng(time(0));

int n, a[N];

int main(){
	#ifndef ONLINE_JUDGE
	//freopen("test.in","r",stdin);
	#endif
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",a+i);
	
	LL sum = 0, ans = 1e14, tmp = 0;
	rep(i,1,n) sum += 1ll*a[i];
	rep(i,1,n) tmp += 1ll*a[i], ans = min(ans, abs(tmp+tmp-sum));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024