akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
#include <queue>
using namespace std;

int64_t min(int64_t a,int64_t b) {
    if (a > b)
    {
        return b ;
    }else
    {
        return a ;
    }
}


int main(){
    int a,b,c,x ;
    cin >> a >> b >> c >> x ;
    int ans = 0 ;

    for (int i = 0; i < a+1; i++)
    {
        for (int j = 0; j < b+1; j++)
        {
            for (int k = 0; k < c+1; k++)
            {
                if (500*i + 100*j + 50*k == x)
                {
                    ans ++ ;
                }
                
            }
            
        }
        
    }
    

    cout << ans << endl;
    
    
}


Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll a, b, x;
    cin >> a >> b >> x;

    if(x < a || a+b < x) {
        out("NO");
    }
    else {
        out("YES");
    }

    re0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=500000+5;

char str[maxn];
int n,q;
set<char >cnt;

struct tree{
	int l,r;
	set<char >s;
}t[maxn<<2];

void push_up(int rt){
	t[rt].s.clear();
	t[rt].s=t[rt<<1].s;
	t[rt].s.insert(t[rt<<1|1].s.begin(),t[rt<<1|1].s.end());
}

void build(int rt,int l,int r){
	t[rt].l=l,t[rt].r=r;
	if(l==r){
		t[rt].s.clear();
		t[rt].s.insert(str[r]);
		return;
	}
	int m=(l+r)>>1;
	build(rt<<1,l,m);
	build(rt<<1|1,m+1,r);
	push_up(rt);
}

void modify(int rt,int x,char c){
	int l=t[rt].l,r=t[rt].r;
	if(l==r){
		t[rt].s.clear();
		t[rt].s.insert(c);
		return ;
	}
	int m=(l+r)>>1;
	if(x<=m) modify(rt<<1,x,c);
	else modify(rt<<1|1,x,c);
	push_up(rt);
}

void sum(int rt,int l,int r){
	if(t[rt].l==l && t[rt].r==r){
		cnt.insert(t[rt].s.begin(),t[rt].s.end());
		return ;
	}
	int m=(t[rt].l+t[rt].r)>>1;
	if(r<=m) sum(rt<<1,l,r);
	else if(l>m)  sum(rt<<1|1,l,r);
	else sum(rt<<1,l,m),sum(rt<<1|1,m+1,r);
}


int main(){
	cin>>n;
	for(int i=1;i<=n;i++ ) cin>>str[i];
	build(1,1,n);
	cin>>q;
	for(int i=1;i<=q;i++){
		int x;
		cin>>x;
		if(x==1){
			int b;char c;
			cin>>b>>c;
			if(str[b]==c) continue;
			str[b]=c;
			modify(1,b,c); 
		}
		else {
			int b,c;
			cin>>b>>c;
			cnt.clear();
			sum(1,b,c);
			cout<<cnt.size()<<endl;
		}
	}
}

Measured memory_bytes: 249216
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n;
    cin >> n;
    ll a[n];
    rep(i,n)cin >> a[i];
    ll b[n], c[n];
    drep(i,n){
        if(i % 2 == 0){
            if(i + 2 >= n)b[i] = a[i];
            else b[i] = b[i+2] + a[i];
        }else{
            if(i + 2 >= n)c[i] = a[i];
            else c[i] = c[i+2] + a[i];
        }
    }
    ll sum[n] = {};
    rep(i,n){
        if(i <= 1)sum[i] = a[i];
        else sum[i] = sum[i-2] + a[i];
    }

    ll ans = -1001001001001001001;

        

    if(n % 2 == 0){
        ans = max(sum[n-1], sum[n-2]);
        srep(i,2,n){
            if(i % 2 == 1)continue;
            ans = max(ans, sum[i-2] + c[i+1]);
        }
    }else{
        ll dp[n];
        rep(i,n)dp[i] = -1001001001001001001;
        rep(i,n){
            if(i <= 1)dp[i] = a[i];
            else{
                if(i % 2 == 0){
                    dp[i] = dp[i-2] + a[i];
                }else{
                    dp[i] = max(dp[i-2], dp[i-3]) + a[i];
                }
            }
        }
        ll pd[n];
        rep(i,n)pd[i] = -1001001001001001001;
        drep(i,n){
            if(i + 2 >= n)pd[i] = a[i];
            else{
                if(i % 2 == 0){
                    pd[i] = pd[i+2] + a[i];
                }else{
                    pd[i] = max(pd[i+2], pd[i+3]) + a[i];
                }
            }
        }
        rep(i,n){
            if(i % 2 == 1)continue;
            ll tmp = 0;
            if(i >= 2){
                tmp += max(dp[i-1], dp[i-2]);
            }
            if(i + 2 < n){
                tmp += max(pd[i+1], pd[i+2]);
            }
            ans = max(ans, tmp);
        }
    }

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


Measured memory_bytes: 13008
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    ll k;
    cin >> k;
    ll now = 7;
    ll i = 2;
    if(now%k==0){
        cout << 1 << endl;
        return 0;
    }
    if(k%2==0||k%5==0){
        cout << -1 << endl;
        return 0;
    }
    while(1){
        now = (10*now + 7)%k;
        if(now%k==0){
            cout << i << endl;
            return 0;
        }
        ++i;
        if(i>=100000000){
            cout << -1 << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#define MAX 5000
using namespace std ;
 
vector<int> a, b, c;
int n, ma, mb;
int search(int sumA, int sumB, int sumC, int st, int opt){
    if(sumC>=opt){return opt;}   
    if((sumA+a[st])*mb==(sumB+b[st])*ma){
        if(sumC+c[st]<opt){opt=sumC+c[st];}
        if(st==n-1){return opt;}
        return min(opt, search(sumA, sumB, sumC, st+1, opt));
    }
    else{
        if(st==n-1){return opt;}
        opt=min(search(sumA, sumB, sumC, st+1, opt), opt);
        return min(opt, search(sumA+a[st], sumB+b[st], sumC+c[st], st+1, opt));
    }
}
int main(void){
    int opt=MAX;
    cin>>n>>ma>>mb;
    int ai,bi,ci;
    for(int i=0;i<n;i++){
        cin>>ai>>bi>>ci;
        a.push_back(ai);
        b.push_back(bi);
        c.push_back(ci);
    }
    opt=search(0,0,0,0,opt);
    if(opt>=MAX) opt=-1;
    cout<<opt<<endl;
}

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

int main() {
    int k;
    cin >> k;
    queue<ll> q;
    rep(i,9) q.push(i+1);
    ll x;
    while (k--) {
        x = q.front(); q.pop();
        for (int i = -1; i <= 1; i++) {
            int y = x % 10 + i;
            if (y < 0 || 9 < y) continue;
            q.push(x*10+y);
        }
    }
    cout << x << endl;
}

Measured memory_bytes: 1792
fn main() {
    let mut a_s: Vec<usize> = Vec::new();

    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    a_s.push(buf.trim().parse().unwrap());
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    a_s.push(buf.trim().parse().unwrap());
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    a_s.push(buf.trim().parse().unwrap());
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    a_s.push(buf.trim().parse().unwrap());
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    a_s.push(buf.trim().parse().unwrap());

    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let k: usize = buf.trim().parse().unwrap();

    if (a_s.iter().max().unwrap() - a_s.iter().min().unwrap()) > k {
        println!(":(");
    }
    else {
        println!("Yay!");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> void vdebug(vector<T> v){ cout << "vdebug" << endl; for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], ll n){ cout << "adebug" << endl; reps(i, 0, n){ cout << arr[i] << " "; } cout << endl; }
template<typename T1, typename T2> void mdebug(map<T1, T2> mp){ cout << "mdebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mldebug(multimap<T1, T2> mp){ cout << "mldebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mdebugr(map<T1, T2, greater<T1>> mp){ cout << "mdebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mldebugr(multimap<T1, T2, greater<T1>> mp){ cout << "mldebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


int h, w, tmpa;
int a[510][510];
int done[510][510];
vector<pair<ll, ll>> from;
vector<pair<ll, ll>> to;

void dfs(int x, int y){
    rep(i, 4){
        int dlx = x + dx[i];
        int dly = y + dy[i];
        if(dlx < 0 || dlx >= w || dly < 0 || dly >= h) continue;
        if(done[dlx][dly]) continue;
        if(a[x][y]%2 == 0){
            done[x][y] = 1;
            dfs(dlx, dly);
            break;
        }
        if(!done[x][y]){
            a[dlx][dly] += 1;
            a[x][y] -= 1;
            done[x][y] = 1;
            from.push_back(make_pair(y+1, x+1));
            to.push_back(make_pair(dly+1, dlx+1));
        }
        dfs(dlx, dly);
    }
}

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

    cin >> h >> w;
    rep(y, h){
        rep(x, w){
            cin >> a[x][y];
        }
    }

    Fill(done, 0);

    dfs(0, 0);

    cout << from.size() << endl;
    rep(i, from.size()){
        cout << from[i].first sp from[i].second sp to[i].first sp to[i].second << endl;
    }

    // cout << endl;
    // rep(y, h){
    //     rep(x, w){
    //         cout << a[x][y] << " ";
    //     }
    //     cout << endl;
    // }

    return 0;
}


Measured memory_bytes: 27748
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using ll = unsigned long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll n, k;
    cin >> n >> k;

    ll cnt(0);
    vector<ll> num;
    while (n>0)
    {
        num.push_back(n % k);
        n /= k, cnt++;
    }

    //sort(num.begin(), num.end());
    //for (auto i: num)
    //    cout << i;
    //cout << endl;

    cout << cnt << endl;

    return 0;
}


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


void solve(long long N, std::vector<long long> x, std::vector<long long> y){
    double total_paths = 0;
    for(int i=0; i < N; i++){
        for(int j=i+1; j < N; j++){
            double dx = x[i] - x[j];
            double dy = y[i] - y[j];
            total_paths += sqrt(dx*dx + dy*dy);
        }
    }
    double res = total_paths * 2 / N;
    printf("%.6f", res);
    // cout << res << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> x(N);
    std::vector<long long> y(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
        scanf("%lld",&y[i]);
    }
    solve(N, std::move(x), std::move(y));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define RFOR(i, m, n) for (ll i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << (ele) << "\n"
#define print10(ele) cout << fixed << setprecision(10) << (ele) << "\n"

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  int k, n;
  cin >> k >> n;
  ivec a(n);
  REP(i, n) cin >> a[i];

  a.push_back(a[0] + k);
  int l = 0;
  REP(i, n) { l = max(l, a[i + 1] - a[i]); }
  ll ans = k - l;
  print(ans);
  return 0;
}

Measured memory_bytes: 1792
n,d=map(int,input().split())
x=[]
for _ in range(n):
  x+=[list(map(int,input().split()))]
ans=0
for i in range(n):
  for j in range(i+1,n):
    l=0
    for k in range(d):
      l+=(x[i][k]-x[j][k])**2
    l=l**0.5
    if l.is_integer():
      ans+=1
print(ans)

Measured memory_bytes: 3188
#include <iostream>

#include <cmath>
#include <algorithm>

using namespace std;

#define MAX 100000
typedef long long llong;

int n,k;
llong T[MAX];


// k????????§????????????p?????????????£?????°??´§???
int check(llong P) {
    int i = 0;
    for(int j = 0; j < k;j++) {
        llong  s = 0;
        while(s+T[i] <= P) {
            s += T[i];
            i++;
            if(i == n) {
                return n;
            }
        }
    }

    return i;
}

int solve() {
    llong left = 0;
    llong right = 100000*10000;
    llong mid;
    while(left<right) {
        mid = (left+right)/2;
        int v = check(mid);
        if(v>=n) {
            right = mid;
        } else {
            left = mid+1;
        }
    }
    return right;
}

int main() {
    cin>>n>>k;
    for(int i = 0; i < n;i++) {
        cin>>T[i];
    }
    llong ans = solve();
    cout<<ans<<endl;
}

Measured memory_bytes: 3876
n,m=map(int,input().split())
par=[-1]*n
def find(n):
    if par[n]<0:
        return n
    else:
        par[n]=find(par[n])
        return par[n]
def union(x,y,s):
    x,y=find(x),find(y) 
    if x!=y:
        if x>y:
            x,y=y,x
        s-=par[x]*par[y]
        par[x]+=par[y]
        par[y]=x
    return s
        
M=[]
for i in range(m):
    a,b=map(int,input().split())
    M.append([a,b])
ANS=[n*(n-1)//2]
s=n*(n-1)//2
for i in reversed(range(1,m)):
    a,b=M[i][0],M[i][1]
    s=union(a-1,b-1,s)
    ANS.append(s)
for ans in ANS[::-1]:
    print(ans)
            

Measured memory_bytes: 27772
#include<stdio.h>
int main(void){
  int a,b;
  char op;
  scanf("%d %c %d",&a,&op,&b);
  //printf("%c\n",op);
  if(op=='+') printf("%d\n",a+b);
  else printf("%d\n",a-b);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
using namespace std;

int 
gcd ( int a, int b )
{
  int c;
  while ( a != 0 ) {
     c = a; a = b%a;  b = c;
  }
  return b;
}

int lcm(int a, int b)
{
    int temp = gcd(a, b);

    return temp ? (a / temp * b) : 0;
}

int main()
{
    int a,b;
    while(cin>>a>>b) {
		printf("%d %d\n",gcd(a,b),lcm(a,b));
    }
    return 0;
}

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

long long max(long long A,long long B){
    return A>B?A:B;
}

long long min(long long A,long long B){
    return A<B?A:B;
}

int main(void){
    char s[6];
    scanf("%s",s);
    if(s[0]==s[1] || s[1]==s[2]|| s[2]==s[3]){
        printf("Bad\n");
    } else {
        printf("Good\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
typedef long long ll;

int main()
{
	int n, m;
	cin >> n >> m;
	cout << (1900 * m + 100 * (n - m)) * pow(2, m) << endl;
	return 0;
}

Measured memory_bytes: 384
H = int(input())

import math
def get_depth(x):
  if math.floor(x/2) == 0:
    return 1
  else:
    return get_depth(math.floor(x/2)) + 1

depth = get_depth(H)

ans = 0
for i in range(depth):
  ans = ans + math.pow(2, i)

print(int(ans))

Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <cmath>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <queue>


using namespace std;
#define    ll  long long	
ll a,b,cnt=1,d;


ll gcd(ll A, ll B){
  return B ? gcd(B, A % B) : A;
}

int main(){
   cin>>a>>b;
   d=gcd(a,b);
   for(ll i=2;i*i<=d;i++)
   {
   	     if(d%i==0)cnt++;
		 while(d%i==0)d=d/i;
   }
   if(d>1)cnt++;
   cout<<cnt;
	return 0;
}


Measured memory_bytes: 256
s = input()[::-1]

sum_of_digits = 0

cnts = [0] * 2019

cnts[0] = 1

d = 1

for c in s:
    sum_of_digits += int(c) * d
    sum_of_digits %= 2019
    d *= 10
    d %= 2019
    cnts[sum_of_digits] += 1

ans = 0
    
for cnt in cnts:
    ans += cnt * (cnt - 1) // 2

print(ans)

Measured memory_bytes: 9332
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main() {

    ll a,b,x;
    cin >> a >> b >> x;
    double S = x/(double)a;
    double h,w,out;
    if(S<=a*b/2.0){
        h = b;
        w = 2.0*S/(double)b;
    }else{
        h = 2.0*(a*b-S)/(double)a;
        w = a;
    }
    out = atan(h/w)*180/M_PI;
    cout << fixed << setprecision(6) <<out << endl;
    return 0;
}


Measured memory_bytes: 384
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		int INF = 1 << 24;
		while (true) {
			int D = scanner.nextInt();
			int N = scanner.nextInt();
			if ((D | N) == 0)
				break;
			AER[] aer = new AER[N];
			for (int i = 0; i < N; i++) {
				aer[i] = new AER(scanner.nextInt(), scanner.nextInt(),
						scanner.nextInt());
			}
			int[][] dp = new int[D + 1][101];
			for (int[] d : dp)
				Arrays.fill(d, INF);
			dp[D][0] = 0;
			for (int i = D; i > 0; i--) {
				for (int j = 0; j < 101; j++) {
					if (dp[i][j] == INF)
						continue;
					for (AER a : aer) {
						if (j < a.r)
							continue;
						int aa = Math.max(0, i - a.a);
						int bb = Math.min(100, j + a.e);
						dp[aa][bb] = Math.min(dp[aa][bb], dp[i][j] + 1);
					}
				}

			}
			int ans = INF;
			for (int i = 0; i < 101; i++) {
				ans = Math.min(ans, dp[0][i]);
			}
			System.out.println(ans == INF ? "NA" : ans);
		}
	}

	class AER {
		int a, e, r;

		public AER(int a, int e, int r) {
			super();
			this.a = a;
			this.e = e;
			this.r = r;
		}

		@Override
		public String toString() {
			return "AER [a=" + a + ", e=" + e + ", r=" + r + "]";
		}

	}
}

Measured memory_bytes: 40776
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
def S(): return sys.stdin.readline().rstrip()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 998244353
INF = float("inf")
sys.setrecursionlimit(10**6+10)
input = sys.stdin.readline
S = S()
S = [S[i] for i in range(len(S))]
QS= deque(S)
S = QS
Q = I()
rev = False
for i in range(Q):
    q = LS()
    if q[0] == '1':
        rev = not rev
        continue
    if (q[1] == '1') ^ rev:
        S.appendleft(q[2])
    else:
        S.append(q[2])
if rev:
    ans = ''.join(reversed(S))
else:
    ans = ''.join(S)

print(ans)



Measured memory_bytes: 92460
#include <stdio.h>
int main()
{
  int i,place,cou,a;
  char o[3],t[3],sute[3];
  while(1){
    scanf("%d",&a);
    if(a==0)break;
    cou=0;
    place=0;
    for(i=0;i<a/2;i++){
      scanf("%s %s",o,t);
      //printf("%c %c\n",o[1],t[1]);///
      if(place==0&&o[1]=='u'&&t[1]=='u'){
	cou++;
	place=1;
      }else if(place==1&&o[1]=='d'&&t[1]=='d'){
	cou++;
	place=0;
      }
    }
    if(a%2==1)scanf("%s",sute);
    printf("%d\n",cou);
  }
  return 0;
}

Measured memory_bytes: 1032
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort(key = lambda x: x[0])
total = 0
i = 0
while True:
	total += ab[i][1]
	if total < m:
		i += 1
	else:
		break
ans = 0
for j in range(i):
	ans += ab[j][0] * ab[j][1]
ans += (m - sum(ab[p][1] for p in range(0,i))) * ab[i][0]
print(ans)

Measured memory_bytes: 29024
fun main(args: Array<String>) {
    var (a, b, k) = readLongArray()

    if (a >= k) {
        a -= k
        k = 0
    } else {
        k -= a
        a = 0
    }

    if (b >= k) {
        b -= k
    } else {
        b = 0
    }

    println("$a $b")
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerArray() = readStringList().map(String::toInt).toIntArray()
fun readLongArray() = readStringList().map(String::toLong).toLongArray()


Measured memory_bytes: 37872
N = int(input())
a = []
cnt_AC, cnt_WA, cnt_TLE, cnt_RE = 0,0,0,0
for i in range(N):
  a.append(input())
for i in a:
  if i == 'AC':
    cnt_AC += 1
  elif i == 'WA':
    cnt_WA += 1
  elif i == 'TLE':
    cnt_TLE += 1
  else:
    cnt_RE += 1
print('AC x',cnt_AC)
print('WA x',cnt_WA)
print('TLE x',cnt_TLE)
print('RE x',cnt_RE)

Measured memory_bytes: 16324
from collections import Counter

n = int(input())
s = list(str(input()) for _ in range(n))
c = Counter(s)

m = 0
for k, v in c.items():
    if m <= v:
        m = v

keys = [k for k, v in c.items() if v >= m]
for ans in sorted(keys):
    print(ans)


Measured memory_bytes: 104528
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll x,y;
    cin >> x >> y;
    if(x%y==0)cout << -1 << endl;
    else cout << x << endl;
}

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

int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    bool possible = true;
    if (a + b >= c) possible = false;
    else{
        ll x = 4 * a * b;
        ll y = (c - a - b) * (c - a - b);
        if (x >= y) possible = false;
    }
    if (possible) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    ll n,k;cin>>n>>k;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    rep(j,k){
        vector<ll> b(n,0);
        rep(i,n){
            int l=max((ll)0,i-a[i]);
            int r=min(n-1,i+a[i]);
            b[l]++;
            if(r+1<n)b[r+1]--;
        }
        rep(i,n-1)b[i+1]+=b[i];
        bool ok=true;
        rep(i,n){
            if(b[i]!=n)ok=false;
        }
        if(ok){
            rep(i,n)cout<<n<<" ";
            cout<<endl;
            return 0;
        }
        swap(a,b);
    }
    rep(i,n)cout<<a[i]<<" ";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 6732
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
H = sorted(LIST())

print(0 if K > N else sum(H[0:N-K]))

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

int main() {
    int h, a, b;
    cin >> h >> a;
    for(int i = 0; i < a; i++)
        cin >> b, h -= b;
    cout << (h > 0 ? "No" : "Yes") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
double s, t;
double dist(double x1, double y1, double x2, double y2)
{
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
void f(double x1, double y1, double x2, double y2, double x3, double y3)
{
	if ((x3 - x1) * (y2 - y1) == (x2 - x1) * (y3 - y1))
	{
		if (x1 == x2)
		{
			s = x1;
			double maxy, miny;
			maxy = miny = y1;
			if (maxy < y2)maxy = y2;
			if (maxy < y3)maxy = y3;
			if (miny > y2)miny = y2;
			if (miny > y3)miny = y3;
			t = (maxy + miny) / 2;
			return;
		}
		if (x1 > x2)
		{
			double f = x1;
			x1 = x2;
			x2 = f;
			f = y1;
			y1 = y2;
			y2 = f;
		}
		if (x1 > x3)
		{
			double f = x1;
			x1 = x3;
			x3 = f;
			f = y1;
			y1 = y3;
			y3 = f;
		}
		if (x2 > x3)
		{
			double f = x2;
			x2 = x3;
			x3 = f;
			f = y2;
			y2 = y3;
			y3 = f;
		}
		s = (x1 + x3) / 2;
		t = (y1 + y3) / 2;
		return;
	}
	t = (x2 * x2 + y2 * y2 - y1 * y1 - x1 * x1) * (x3 - x1) - (y3 * y3 + x3 * x3 - y1 * y1 - x1 * x1) * (x2 - x1);
	t /= 2 * ((y1 - y3) * (x2 - x1) - (y1 - y2) * (x3 - x1));
	if (x2 != x1)
	{
		s = 2 * t * (y1 - y2) + y2 * y2 + x2 * x2 - y1 * y1 - x1 * x1;
		s /= 2 * (x2 - x1);
	}
	else
	{
		s = 2 * t * (y1 - y3) + y3 * y3 + x3 * x3 - y1 * y1 - x1 * x1;
		s /= 2 * (x3 - x1);
	}
	return;
}
int main()
{
	int n;
	scanf("%d", &n);
	int i, j, k, l;
	double x[55], y[55];
	for (i = 0; i < n; i++)
		scanf("%lf %lf", &x[i], &y[i]);
	if (n == 2)
	{
		printf("%.20lf\n", dist(x[0], y[0], x[1], y[1]) / 2);
		return 0;
	}
	double ans = 10000000000000;
	double v;
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < n; j++)
		{
			if (i != j)
			{
				for (k = 0; k < n; k++)
				{
					if (i != k && k != j)
					{
						f(x[i], y[i], x[j], y[j], x[k], y[k]);
						v = 0;
						for (l = 0; l < n; l++)
							if (v < dist(x[l], y[l], s, t))
								v = dist(x[l], y[l], s, t);
						if (ans > v)
							ans = v;
					}
				}
			}
		}
	}
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < n; j++)
		{
			s = (x[i] + x[j]) / 2;
			t = (y[i] + y[j]) / 2;
			v = 0;
			for (k = 0; k < n; k++)
				if (dist(x[k], y[k], s, t) > v)
					v = dist(x[k], y[k], s, t);
			if (ans > v)
				ans = v;
		}
	}
	printf("%.20lf\n", ans);
	return 0;
}

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

using namespace std;

char a[15];

int main()
{
    int ans = 0;
    scanf("%s",a);
    int sum = 0;
    for(int i = 0;a[i] != '\0';i++)
    {
        if(a[i] == 'A' || a[i] == 'T' || a[i] == 'C' || a[i] == 'G')
            sum++;
        else
        {
            ans = max(sum,ans);
            sum = 0;
        }
    }
    ans = max(sum,ans);
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n,m;
  cin >> n >> m;
  vector<ll> x(n);
  vector<ll> y(n);
  vector<ll> z(n);
  for(int i = 0;i < n;i++)cin >> x[i] >> y[i] >> z[i];
  ll res = 0;
  for(int i = 0; i < (1<<3); i++){//2のa乗回繰り返す(0 ~ 2^a- 1)
    vector<ll> now(n);
    for(int j = 0;j < n;j++)now[j] = 0;
    for(int j = 0;j < n;j++){
      if(i & (1<<0))now[j] += x[j];
      else now[j] += x[j] * -1;
      if(i & (1<<1))now[j] += y[j];
      else now[j] += y[j] * -1;
      if(i & (1<<2))now[j] += z[j];
      else now[j] += z[j] * -1;
    }
    /*if(i == 7){
      for(auto item:now)cout << item << " ";
      cout << endl;
    }*/
    sort(now.rbegin(),now.rend());
    ll wa = 0;
    for(int j = 0;j < m;j++){
      wa += now[j];
      //cout << now[j] << " ";
    }
    //cout << endl;
    res = max(res,wa);
  }
  cout << res << endl;
}

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


int main() {
   int N;
   cin>>N;
   vector<int>A(N);
   int ans;
   rep(i,N){
       cin>>A[i];
       if(i==0){
           ans=A[0];
       }
       else{
           ans=__gcd(ans,A[i]);
           if(ans==1){
               break;
           }
       }
   }
   cout<<ans<<endl;
}


Measured memory_bytes: 3732
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int i,n,x,l[110];
  cin >> n >> x;
  for(i=0;i<n;i++){
    cin >> l[i];
  }
  int d=0,sum=1;
  for(i=0;i<n;i++){
    d=d+l[i];
    if(d<=x){
      sum++;
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define vi vector<int>
#define Vi vector<vector<int>>
#define ll long long
#define P pair<int,int>
#define vp  vector<P>
#define vs vector<string>
#define mod 1000000009
using namespace std;
int total_black=0,ans=0,k;
vi row_count(7,0);
vi col_count(7,0);
void calculate(vi row_index,vi col_index,vs &str){
	int temp=0;
	for(int i:row_index)
		temp+=row_count[i];
	for(int j:col_index)
		temp+=col_count[j];
	for(int i:row_index)
		for(int j:col_index)
			temp-=(str[i][j]=='#'?1:0);
	if(total_black-temp==k)
		ans++;
}
void util2(int cur_index,vi row_index,vi col_index,vs &str){
	int w=str[0].size();
	if(cur_index==w){
		calculate(row_index,col_index,str);
		return ;
	}
	util2(cur_index+1,row_index,col_index,str);
	col_index.push_back(cur_index);
	util2(cur_index+1,row_index,col_index,str);
}
void util1(int cur_index,vi row_index,vs &str){
	int h=str.size();
	if(cur_index==h){
		vi col_index;
		util2(0,row_index,col_index,str);
		return;
	}
	util1(cur_index+1,row_index,str);
	row_index.push_back(cur_index);
	util1(cur_index+1,row_index,str);
}
int main(){
	int h,w;
	cin>>h>>w>>k;
	vs str(h);
	for(int i=0;i<h;i++){
		cin>>str[i];
		for(int j=0;j<w;j++)
			if(str[i][j]=='#'){
				total_black++;
				row_count[i]++;
			}
	}
	for(int j=0;j<w;j++){
		for(int i=0;i<h;i++){
			if(str[i][j]=='#')
				col_count[j]++;
		}
	}
	vi row_index;
	util1(0,row_index,str);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3604
t = str(input())
s =""
for i in range(len(t)-1):
    if(i>=1):
        if(t[i]=='?'):
          if(s[-1]=="P"):
              s+="D"
          elif(t[i+1]=='D')or(t[i+1]=='?'):
              s += "P"
          elif(t[i+1]=='P'):
              s+="D"
        else:
          s+=t[i]
    else:
        if(t[i]=='?'):
          if(t[i+1]=='D')or(t[i+1]=='?'):
              s += "P"
          elif(t[i+1]=='P'):
              s+="D"
        else:
          s+=t[i]
if(t[len(t)-1]=="?"):
    s+="D"
else:
    s+=t[len(t)-1]
print(s)


Measured memory_bytes: 9588
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<math.h>
#include<map>
#include<unordered_map> 
#include<vector>
#include<queue>
#include<set>
#include<bits/stdc++.h>
#include<deque> 
#include<bitset>
#include<string>
#define N 40
#define K 300005
#define MOD 1e9+7
#define int long long 
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int max(int a, int b){
    if(a>b)
        return a;
    return b;
}
int mod = 1e9 + 7;
int ans = 0;
int vis[100005], dis[100005], in[100005];

int32_t main(){
	int h, w;
	cin>>h>>w;
	char a[h+1][w+1];
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>a[i][j];
		}
	}
	int dp[h+1][w+1];
	for(int i=0;i<=h;i++){
		for(int j=0;j<=w;j++){
			dp[i][j] = 0;
		}
	}
    dp[1][1] = 1;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
            if(i == 1 && j == 1)
                continue;
			if(a[i][j] == '#')
				continue;
			else{
				dp[i][j] = dp[i-1][j] + dp[i][j-1];
				if(dp[i][j] >= mod)
					dp[i][j] -= mod;
			}
		}
	}
	cout<<dp[h][w]<<endl;

}

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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

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

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li n;
    cin>>n;

    li a[n];

    u_map<li,li> m;

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

    li ans=0;

    for(auto it:m)
    {
        if(it.S>1)
        {
            ans+=(it.S*(it.S-1))/2;
        }
    }

    // cout<<ans<<endl;

    vi v(n,ans);

    f(i,0,n-1)
    {   
        if(m[a[i]]<=1)
            continue;

        v[i]-=(m[a[i]]*(m[a[i]]-1))/2;

        li tp=m[a[i]]-1;

        if(tp>1)
        {
            v[i]+=(tp*(tp-1))/2;
        }
    }

    for(li i:v)
        cout<<i<<endl;

    return 0;
}

Measured memory_bytes: 10696
import sys
sys.setrecursionlimit(10**9)
f=lambda:map(int,input().split())
n,st,sa=f()
st-=1
sa-=1
g=[[] for _ in range(n)]
for _ in range(n-1):
  a,b=f()
  g[a-1].append(b-1)
  g[b-1].append(a-1)
def dfs(v,p=-1,d=0):
  l[v]=d
  for c in g[v]:
    if c==p: continue
    dfs(c,v,d+1)
def dist(s):
  global l
  l=[0]*n
  dfs(s)
  return l
lt=dist(st)
la=dist(sa)
m=0
for i in range(n):
  if lt[i]<la[i]: m=max(m,la[i])
print(m-1)

Measured memory_bytes: 117048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main() {
    int a, b, x;
    cin >> a >> b >> x;

    if(0 <= x-a && x-a <= b){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }


    return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
list1=set([int(input()) for i in range(M)])
list2=[1]+[0]*N
if not 1 in list1:
    list2[1]=1
for i in range(N-1):
    if not i+2 in list1:
        list2[i+2]=(list2[i]+list2[i+1])%1000000007
print(list2[N])

Measured memory_bytes: 13216
#include<iostream>
#include<vector>
#include<cmath>
#include <numeric>
#include<climits>
#include<cfloat>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>

using namespace std;
typedef pair<int,bool> Pair;

int main(){

	int N;
	string S;
	int ans = 0;
	int i,j,k;

	cin >> N;
	cin >> S;

	for(i = 0;i < N; i = i + (k+1)){

		k = -1;

		for(j = i;j <= N && S[i] == S[j]; ++j) ++k;

		++ans;

	}


	cout << ans << endl;

return 0;

}


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

using namespace std;

typedef long long int ll;
typedef pair<int,int> ii;

const int N = 2e3 + 5;
const int M = 2e5 + 5;
const int SQ = 450;

int n,m,q,node[N][N],uedge[N][N],ledge[N][N];
char s[N][N];

inline int get_node(int lx,int ly,int rx,int ry) {
  return node[rx][ry] - node[rx][ly - 1] - node[lx - 1][ry] + node[lx - 1][ly - 1]; 
}

inline int get_u(int lx,int ly,int rx,int ry) {
  return uedge[rx][ry] - uedge[rx][ly - 1] - uedge[lx - 1][ry] + uedge[lx - 1][ly - 1]; 
}

inline int get_l(int lx,int ly,int rx,int ry) {
  return ledge[rx][ry] - ledge[rx][ly - 1] - ledge[lx - 1][ry] + ledge[lx - 1][ly - 1]; 
}

inline int get_edges(int lx,int ly,int rx,int ry) {
  return get_u(lx,ly,rx,ry) + get_l(lx,ly,rx,ry) - get_u(lx,ly,lx,ry) - get_l(lx,ly,rx,ly);
}


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> n >> m >> q;
  for (int i = 1 ; i <= n ; i++)
    for (int j = 1 ; j <= m ; j++) {
      cin >> s[i][j];
      node[i][j] = node[i - 1][j] + node[i][j - 1] - node[i - 1][j - 1] + (s[i][j] == '1');
    }

  for (int i = 1 ; i <= n ; i++)
    for (int j = 1 ; j <= m ; j++) {
      uedge[i][j] = uedge[i - 1][j] + uedge[i][j - 1] - uedge[i - 1][j - 1];
      ledge[i][j] = ledge[i - 1][j] + ledge[i][j - 1] - ledge[i - 1][j - 1];
      if (s[i][j] == '1') {
        if (s[i - 1][j] == '1')
          uedge[i][j]++;
        if (s[i][j - 1] == '1')
          ledge[i][j]++;
      }
    }

  for (int i = 1 ; i <= q ; i++) {
    int lx,ly,rx,ry;
    cin >> lx >> ly >> rx >> ry;
    cout << get_node(lx,ly,rx,ry) - get_edges(lx,ly,rx,ry) << "\n";
  }

}

Measured memory_bytes: 52864
n = gets.to_i
sum = 0
values = gets.chomp.split.map(&:to_i)
costs = gets.chomp.split.map(&:to_i)
n.times{|i|
    v = values[i]
    c = costs[i]
    sum += (v - c) if (v - c) > 0
}
puts sum

Measured memory_bytes: 1788
#include<iostream>
#include<cstdio>
using namespace std;
int n,a[110];
int t2(){
	int ans=0;
	for(int i=1;i<=n;++i){
		for(int j=i+1;j<=n;++j){
			for(int c=j+1;c<=n;++c){
				if(a[i]+a[j] > a[c]&&a[c]+a[j] > a[i]&&a[i]+a[c] > a[j]&&a[i]!=a[j]&&a[j]!=a[c]&&a[i]!=a[c]){
					ans++;
				}
			}
		}
	}
	return ans;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
	}
	printf("%d\n",t2());
	return 0;
}

Measured memory_bytes: 3824
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

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

# cの倍数
if a == 0:
    print(b - (b // c + b // d - b // lcm(c,d)))
else:
    c_wari = b // c - (a-1) // c
    
    d_wari = b // d - (a-1) // d
    
    cd_wari = b // lcm(c,d) - (a-1) // lcm(c,d)
    
    print((b-a+1) - (c_wari+d_wari-cd_wari))

Measured memory_bytes: 5304
W, H, N = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(N)]

X = [0, W]
Y = [0, H]

for l in lst:
    if l[2] == 1 and X[0] < l[0]:
        X[0] = l[0]
    elif l[2] == 2 and l[0] < X[1]:
        X[1] = l[0]
    elif l[2] == 3 and Y[0] < l[1]:
        Y[0] = l[1]
    elif l[2] == 4 and l[1] < Y[1]:
        Y[1] = l[1]

width = X[1] - X[0] if X[1] - X[0] > 0 else 0
height = Y[1] - Y[0] if Y[1] - Y[0] > 0 else 0

print(width * height)

Measured memory_bytes: 3064
X, Y, A, B, C = map(int, input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
p = p[:X]
q = q[:Y]
l = sorted(p + q + r, reverse=True)
print(sum(l[:X+Y]))

Measured memory_bytes: 23328
def solve(inp):
    N = int(inp.readline().strip())
    B = list(map(int, inp.readline().strip().split(' ')))

    A = [0 for i in range(N)]

    A[N - 1] = B[N - 2]
    for i in range(N - 2, 0, -1):
        A[i] = min(B[i - 1], B[i])
    A[0] = B[0]
    # print(A)

    return str(sum(A))


def test(s):
    from io import StringIO
    print(solve(StringIO(s)))


def main():
    import sys
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    # test('3\n2 5')
    # test('2\n3')
    # test('6\n0 153 10 10 23')
    main()


Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication59
{
    class Program
    {
        static void Main()
        {
            while (true)
            {
                string a = Console.ReadLine();
                if (a == null) break;
                int b = int.Parse(a);
                int c = 2;
                for(int d = 1;; d++)
                {
                    if (d == b) break;
                    c += d + 1;
                }
                Console.WriteLine(c);
            }
        }
    }
}

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

using namespace std;
using ll = long long;
ll mod = 1000000007;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin >> n;
    ll tot = 1, l1 = 1, l2 = 1;
    for(ll i = 0; i < n; i++) {
        tot *= 10;
        tot %= mod;
        l1 *= 9;
        l1 %= mod;
        l2 *= 8;
        l2 %= mod;
    }
    cout << (tot + l2 - 2 * l1 + 2 * mod) % mod;
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)

using namespace std;

const int N=15;
int n,m,x,y,cnt; char s[N][N];

int main(){
	scanf("%d%d",&n,&m);
	rep (i,1,n){
		scanf("%s",s[i]+1);
		rep (j,1,m) if (s[i][j]=='#') cnt++;
	}
	if (cnt!=n+m-1) return puts("Impossible"),0;
	x=y=1;
	if (s[1][1]!='#') return puts("Impossible"),0;
	while (x<n||y<m){
		int f1=x<n&&s[x+1][y]=='#';
		int f2=y<m&&s[x][y+1]=='#';
		if (f1||f2){
			if (f1&&f2) return puts("Impossible"),0;
			if (f1) x++; else y++;
		} else return puts("Impossible"),0;
	}
	puts("Possible");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define int long long
using namespace std;
int n,tot,ans;
const int N=2010,inf=0x3f3f3f3f;
int a[N],head[N],to[N<<1],nt[N<<1],mx[N],mn[N],siz[N];
char s[N];
void add(int f,int t)
{
	to[++tot]=t;nt[tot]=head[f];head[f]=tot;
}
void dfs(int x,int fa)
{
	int pos=0;
	mx[x]=mn[x]=0;siz[x]=a[x];
	for(int i=head[x];i;i=nt[i])
		if(to[i]!=fa)
		{
			dfs(to[i],x);
			mx[to[i]]+=siz[to[i]];mn[to[i]]+=siz[to[i]];
			siz[x]+=siz[to[i]];
			mx[x]+=mx[to[i]];
			if(mx[to[i]]>mx[pos])pos=to[i];
		}
	if(!pos)return;
	if(mn[pos]<=mx[x]-mx[pos])mn[x]=mx[x]&1;
	else mn[x]=mn[pos]-(mx[x]-mx[pos]);
}
signed main()
{
	cin>>n;scanf("%s",s+1);
	for(int i=1;i<=n;++i)a[i]=s[i]-'0';
	for(int i=1,x,y;i<n;++i)
		scanf("%lld%lld",&x,&y),add(x,y),add(y,x);
	ans=inf;
	for(int i=1;i<=n;++i)
	{
		dfs(i,0);
		if(!mn[i])ans=min(ans,mx[i]/2);
	}
	cout<<(ans==inf?-1:ans);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
using namespace std;

int main(){
  int N, K, H, ans = 0;
  cin >> N >> K ;
  for(int i=0;i<N;i++){
    cin >> H ;
    if(H >= K) ans++ ;
  }  
  cout << ans << endl ;
  return 0 ;
}

Measured memory_bytes: 256
#include <math.h>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265358979323846264338327950L
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {
  int N;
  string S, T;

  cin >> N >> S >> T;

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007



int main() {
	int N;
	cin >> N;
	if (N % 2 == 0)print(N);
	else print(N * 2);






	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;

/*bool IsPrime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) { // 素数ではない
			return false;
		}
	}
	// 素数である
	return true;
}*/
/*ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/
/*ll modpow(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}*/
/*ll keta(ll n) {
	ll res = 0;
	while (n >= 1) {
		res += n % 10; n /= 10;
	}
	return res;
}*/
/*ll nCk(ll n, ll k) {
	ll a = 1, b = 1;
	for (int h = n - k + 1; h <= n; h++) { a *= h; a %= mod; }
	for (int h = 1; h <= k; h++) { b *= h; b %= mod; }
	return a * modpow(b, mod - 2) % mod;
}*/
//printf("%.10f\n", n);

signed main() {
	string s, t;
	ll n, m, k, q, a = 0, b = 0, c = 0, d, x, y, ans = 0;
	cin >> n >> s;
	rep(i, n) {
		if (s[i] == 'R') { a++; }
	}
	rep(i, a) {
		if (s[i] != 'R') { ans++; }
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,a[10010];
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    int ans=0;
    for(int i=0;i<n;i++){
        while(a[i]%2==0){a[i]/=2;ans++;}
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
map = [['#'] + [s for s in input().strip()] + ['#'] for _ in range(h)]
n_white = sum(len([s for s in ss if s == '.']) for ss in map)
map = [['#' for _ in range(w+2)]] + map + [['#' for _ in range(w+2)]]

def wfs(next_xy, c):
  tmp_next = set()
  for x, y in next_xy:
    map[y][x] = '#'
    if x == w and y == h:
      return c + 1
    if map[y][x-1] == '.':
      tmp_next.add((x-1, y))
    if map[y][x+1] == '.':
      tmp_next.add((x+1, y))
    if map[y-1][x] == '.':
      tmp_next.add((x, y-1))
    if map[y+1][x] == '.':
      tmp_next.add((x, y+1))
  if len(tmp_next) == 0:
    return -1
  else:
    return wfs(tmp_next, c+1)

pathl = wfs([(1,1)], 0)
if pathl == -1:
  print(-1)
else:
  print(n_white - pathl)


Measured memory_bytes: 3316