akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define NOT_FOUND -1

int array1[10000],array2[500],num1;

int linear_search(int);


int main(){  //線型探索

  int i,num2,count=0;
  
  scanf("%d",&num1);

  for(i=0;i<num1;i++){
    scanf("%d",&array1[i]);
  }
  
  scanf("%d",&num2);

  for(i=0;i<num2;i++){
    scanf("%d",&array2[i]);
  }
   for(i=0;i<num2;i++){
    if(linear_search(array2[i])==NOT_FOUND);
    else count++;
  }
  
    printf("%d\n",count);
  
  return 0;
}

int linear_search(int key){

  int i=0;
  array1[num1]=key;
  while(array1[i]!=key){
    i++;
  }
  if(i==num1){
    return -1;
  }
  return i;
}



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

string s;

int main(){
    cin>>s;
    ll cnt=0;
    ll ans=0;
    rep(i,s.size()){
        if(s[i]=='B') cnt++;
        else ans+=cnt;
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3744
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

void solveSingleCase(int caseNo)
{
    int N;
    cin >> N;
    string S;
    cin >> S;

    int ret = 0;
    FOR(i, 1, N) {
        string a = S.substr(0, i);
        string b = S.substr(i);

        set<char> aset(ALL(a)), bset(ALL(b));

        int cnt = 0;
        for (char c = 'a';c <= 'z'; c++)
            if (aset.count(c) && bset.count(c))
                cnt++;

        ret = max(ret, cnt);
    }

    cout << ret << endl;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int T = 1;
    // cin >> T;
    FOR(tcase, 1, T + 1) {
        solveSingleCase(tcase);
    }
    return 0;
};


Measured memory_bytes: 256
n = int(input())
t,a = map(int,input().split())
lis = list(map(int,input().split()))
cou = 10 ** 10
for i in range(n):
  if cou > abs(a - (t-lis[i]*0.006)):
    cou = abs(a - (t-lis[i]*0.006))
    ans = i+1
print(ans)

Measured memory_bytes: 3060
N=int(input())
C=[list(map(int,input().split())) for _ in range(N-1)]

for i in range(N-1):
 c,s,f=C[i]
 A=s+c
 for j in range(i+1,N-1):
    nc,ns,nf=C[j]
    if A<ns:A=ns
    elif (A-ns)%nf!=0:A+=nf-(A-ns)%nf
    A+=nc
 print(A)
print(0)

Measured memory_bytes: 9120
#include<iostream>
#include<stack>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main(void){
    stack<int> S1;
    stack<pair<int, int> > S2;
    char ch;
    int sum = 0;
    for(int i = 0; cin >> ch; i++){
        if(ch == '\\'){
            S1.push(i);
        }else if(ch == '/' && S1.size() > 0){
            int j = S1.top();
            S1.pop();
            sum += i-j;
            int a = i-j;
            while(S2.size() > 0 && S2.top().first > j){
                a += S2.top().second;
                S2.pop();
            }
            S2.push(make_pair(j, a));
        }

    }

    vector<int> ans;
    while(S2.size() > 0){
        ans.push_back(S2.top().second);
        S2.pop();
    }
    reverse(ans.begin(), ans.end());
    cout << sum << endl;
    cout << ans.size();
    for(int i = 0; i < ans.size(); i++){
        cout << " ";
        cout << ans[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
int a[105];
signed main()
{
	int n;
	cin>>n;
	int ans=0;
	for (int i=0;i<n;i++){
		cin>>a[i];
		for (int j=0;j<i;j++){
			for (int k=j+1;k<i;k++){
				if (a[i]!=a[j] && a[j]!=a[k] && a[i]!=a[k] && max(max(a[i],a[j]),a[k])*2<a[i]+a[j]+a[k]){
					ans++;
				}
				//cout<<i<<' '<<j<<' '<<k<<' '<<ans<<'\n';
			}
		}
	}
	cout<<ans;
	re 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
#define MOD (int)(1e9+7)

int CNT[1001];

int main()
{
	int n; cin >> n;

	for (int i = 2; i <= n; i++) {
		int a = i;
		for (int j = 2; j*j <= a; j++) {
			if (a%j == 0) {
				while (a%j == 0) {
					a /= j;
					CNT[j]++;
				}
			}
		}
		if (a != 1)CNT[a]++;
		
	}

	long long ans = 1;
	for (int i = 1; i <= n; i++) {
		ans = ans*(CNT[i] + 1) % MOD;
	}
	cout << ans << endl;

    return 0;
}


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

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}

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

  ll A, B ; cin  >> A >> B ;
  if((A%3)*(B%3)*((A+B)%3) == 0) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
  
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

const int MAX_N = 102;
ll a[MAX_N][MAX_N];
ll sum[MAX_N][MAX_N];
int n;

void solve()
{
    sum[0][0] = a[0][0];
    for (int i = 1; i < n; ++i) {
        sum[0][i] = sum[0][i - 1] + a[0][i];
        sum[i][0] = sum[i - 1][0] + a[i][0];
    }
    for (int i = 1; i < n; ++i)
        for (int j = 1; j < n; ++j)
            sum[i][j] = sum[i - 1][j] + sum[i][j - 1]
                - sum[i - 1][j - 1] + a[i][j];

   ll ans = sum[0][0];
   for (int y1 = 0; y1 < n; ++y1) {
       for (int y2 = y1; y2 < n; ++y2) {
           ll v = -1e9;
           for (int x = 0; x < n; ++x) {
               ll area = sum[y2][x];
               if (x != 0)
                   area -= sum[y2][x - 1];
               if (y1 != 0)
                   area -= sum[y1 - 1][x];
               if (x != 0 && y1 != 0)
                   area += sum[y1 - 1][x - 1];

               v = max(v + area, area);
               ans = max(ans, v);
           }
       }
   }
   cout << ans << endl;
}

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

    if (n == 1)
        cout << a[0][0] << endl;
    else
        solve();

    return 0;
}

Measured memory_bytes: 1324
k, n = map(int, input().split())

arr = list(map(int, input().split()))
# arr.append(arr[0])

maxv = -float('inf')

for i in range(len(arr) - 1):
    maxv = max(maxv, arr[i + 1] - arr[i])

maxv = max(maxv, k - arr[-1] + arr[0])

print (k - maxv)


Measured memory_bytes: 25964
#include <iostream>
using namespace std;
int main(void){
    int N, L[11];
    cin >> N;
    int longest = 0;
    for(int i=0; i<N; i++){
        cin >> L[i];
        longest = max(longest, L[i]);
    }
    int sum = 0;
    int count=0;
    for(int i=0; i<N; i++){
        if(L[i]==longest&&count==0) {
            count++;
            continue;
        }
        sum += L[i];
    }
    if(longest<sum){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
}


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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

void gen_sosuu(int sosuu[]){
  REP(i,100010){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(100000)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=100000;j++){
      //printf("%d %d %d\n",i*j,i,j);
      sosuu[i*j] =false;
    }
  }
}

char s[201];

int main(){
  scanf("%s",s);
  int cnt = 0;
  int len = strlen(s)-2;
  while(len>=0){
    bool flag = true;
    int half = len/2;
    for(int i = 0;i<half;i++){
      if(s[i]!=s[i+half]){
        flag = false;
      }
    }
    if(flag){
      printf("%d\n",len);
      return 0;
    }
    len-=2;
    cnt+=2;
  }
}


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

int main() 
{
    int N, R;
    
    cin >> N >> R;

    int innner_rate;

    if(N < 10)
    {
        innner_rate = R + 1000 - 100*N;
    }
    else
    {
        innner_rate = R;
    }

    cout << innner_rate << endl;

    return 0;
}


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

#define ll long long int
#define vi vector<int>
#define ii pair< int , int >
#define vii vector<ii>
#define FOR(i, n) for(ll i = 0; i < (ll)n; i++)
int MAX(int a, int b){return (a > b) ? a:b;}
int MIN(int a, int b){return (a < b) ? a:b;}
int ABS(int x){return (x > 0) ? x:-x;}
int left(int x){return (x<<1);}
int right(int x){return (x<<1)+1;}
int lsone(int x){return (x&(-x));}

const int maxn = 1e5 + 5;
int n, k = 2, h[maxn];
int ans[maxn];
bool found[maxn];

int dp(int pos){
	if(pos == n) return 0;
	if(found[pos]) return ans[pos];
	found[pos] = true;
	ans[pos] = 2e9;
	for(int i = 1; i <= k && pos+i <= n; i++){
		ans[pos] = min(ans[pos], dp(pos+i) + abs(h[pos]-h[pos+i]));
	}
	return ans[pos];
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%d", &h[i]);
	}
	printf("%d\n", dp(1));
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void print() { cout << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) { cout << x << " "; print(args...);}
void debug_out() { cout << "\n"; }
template <class T, class... Args> void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

const ll INF = 1LL<<60;

vector<ll> dijkstra(int n, int s, const vector<vector<P>> &G) {
  priority_queue<P, vector<P>, greater<P> > que;
  vector<ll> d(n,INF);
  d[s] = 0;
  que.push(P(0,s));
  while(!que.empty()) {
    P p = que.top(); que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (int i = 0; i < (int)G[v].size(); ++i) {
      int to = G[v][i].first;
      ll cost = G[v][i].second;
      if (d[to] > d[v] + cost) {
        d[to] = p.first + cost;
        que.push(P(d[to], to));
      }
    }
  }
  return d;
}

int get_v(int station, int ginka) {
  return 2500*station + ginka;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n,m;
  ll s;
  cin >> n >> m >> s;
  vector<ll> a(m), b(m), c(n), d(n);
  vector<vector<P> > G(n);
  rep(i,m) {
    int u, v;
    cin >> u >> v >> a[i] >> b[i];
    u--; v--;
    G[u].emplace_back(P(v,i));
    G[v].emplace_back(P(u,i));
  }
  rep(i,n) cin >> c[i] >> d[i];

  vector<vector<P> > cost(n*2505); //各駅に対して2499頂点
  rep(i,n) { //両替の辺を張る
    rep(ginka, 2500) {
      if (ginka + c[i] >= 2500) continue;
      int to = get_v(i, ginka + c[i]);
      cost[get_v(i,ginka)].emplace_back(P(to, d[i])); 
    }
  }
  rep(i,n) { //移動の辺を張る
    for (auto p : G[i]) {
      rep(ginka, 2500) {
        if (ginka - a[p.second] < 0) continue; //足りない
        int to_st = p.first; //行先
        int to = get_v(to_st, ginka-a[p.second]);
        cost[get_v(i,ginka)].emplace_back(P(to, b[p.second])); 
      }
    }
  }
  int start_ginka = min(s, 2499LL);
  vector<ll> dist = dijkstra(n*2500, get_v(0, start_ginka), cost);
  for (int i = 1; i < n; ++i) {
    ll ans = 1LL<<60;
    rep(ginka,2500) {
      chmin(ans, dist[get_v(i,ginka)]); //到達した中でのmin
    }
    print(ans);
  }
  return 0;
}

Measured memory_bytes: 23716
from collections import OrderedDict
n = int(input())
abet = "abcdefghijklmnopqrstuvwxyz"
foo = OrderedDict.fromkeys(abet)
for _ in range(n):
    line = input()
    for c in abet:
        bar = line.count(c)
        if (foo[c] is None or bar < foo[c]):
            foo[c] = bar
res = ''
for c in abet:
    # print(foo[c])
    res += c * foo[c]
print(res)


Measured memory_bytes: 3444
import java.util.Scanner;

public class Main{

	public static void main (String[] args) {

		Scanner sc = new Scanner (System.in);

		int  N = sc.nextInt();
		int L = sc.nextInt();

		boolean flag = true;
		int[] list = new int [N];

		for (int index=0; index<N; index++) {
			int temp = index+L;
			if (temp==0) {
				flag = false;
			}
			list[index]=temp;
		}

		if (flag) {
			if (list[0]>0) {
				list[0]=0;
			} else {
				list[N-1]=0;
			}
		}

		int sum = 0;
		for (int index=0; index<N; index++) {
			sum+=list[index];
		}

		System.out.println(sum);
	}
}

Measured memory_bytes: 23380
n,k = gets.chomp.split.map(&:to_i)
as = gets.chomp.split.map(&:to_i)
mod = 1e9+7.to_i
order = 0
trans = 0
as.each_with_index do |a,i|
  (i..n-1).each do|k|
      if a > as[k]
        trans += 1
      end
      if a < as[k]
        order += 1
      end
  end
end
num1 = k*(k+1)/2
num2 = k*(k-1)/2
puts (trans*num1 + order*num2)%mod.to_i

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

using namespace std;

using ll=long long;
const int INF = 1e9+5;

void max_self(ll &a, ll b){
    a=max(a,b);
}

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

    int n,w;
    cin>>n>>w;
    vector<ll>dp(w+1);
    // for(int i=0; i<n; i++)cin>>n;
    for(int i=0; i<n; i++){
        int wei, val;
        cin>>wei>>val;
        for(int curr=w-wei; curr>=0; curr--){
            max_self(dp[curr+wei],dp[curr]+(ll)val);
        }
    }
    cout<<dp[w]<<endl;

    return 0;
}

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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int M = (1e9)+7;
const int N = 300005;

int row[N],col[N];

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int n,m,k;
        cin>>n>>m>>k;
        set<pii> s;
        while(k--)
        {
            int x,y;
            cin>>x>>y;
            s.insert({x,y});
            row[x]++;
            col[y]++;
        }
        int mr = 0,mc = 0;
        for(int i=1;i<=n;i++)mr = max(mr,row[i]);
        for(int i=1;i<=m;i++)mc = max(mc,col[i]);

        vector<int> r1,r2,c1,c2;
        for(int i=1;i<=n;i++)
        {
            if(row[i] == mr)r1.pb(i);
            if(row[i] == mr-1 && mr-1>0)r2.pb(i);
        }
        for(int i=1;i<=m;i++)
        {
            if(col[i] == mc)c1.pb(i);
            if(col[i] == mc-1 && mc-1>0)c2.pb(i);
        }
        int ans = 0,chk = mr + mc;
        for(int x:r1)for(int y:c1)
        {
            ans = max(ans, row[x]+col[y]-(s.find({x,y}) != s.end()));
            if(ans == chk)return cout<<ans,0;
        }
        /*for(int x:r1)for(int y:c2)ans = max(ans, row[x]+col[y]-(s.find({x,y}) != s.end()));
        for(int x:r2)for(int y:c1)ans = max(ans, row[x]+col[y]-(s.find({x,y}) != s.end()));
        for(int x:r2)for(int y:c2)ans = max(ans, row[x]+col[y]-(s.find({x,y}) != s.end()));*/
        cout<<ans<<endl;
    }
    return 0;
}


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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

template<typename T>
T gcd(T x, T y)
{
	return y ? gcd(y, x % y) : x;
}

void hawawa()
{
	int h, w;
	cin >> h >> w;
	for (int i = 1; i <= h; i++) {
		for (int j = 0; j < w; j++) {
			string str;
			cin >> str;
			if (str == "snuke") {
				cout << static_cast<char>('A' + j) << "" << i << "\n";
				return;
			}
		}
	}
}

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


Measured memory_bytes: 256
import itertools

n, m = map(int, input().split())
graph = {i + 1 : set() for i in range(n)}
for i in range(m):
    a, b = map(int, input().split())
    graph[a] |= set([b])
    graph[b] |= set([a])
count = 0
node = [i + 2 for i in range(n - 1)]
for i in itertools.permutations(node):
    route = [1] + list(i)
    flag = True
    for j in range(n - 1):
        if route[j + 1] not in graph[route[j]]:
            flag = False
            break
    if flag == True:
        count += 1
print(count)

Measured memory_bytes: 3064
object Main {
	def main(args: Array[String]): Unit = {
	  val in = new java.util.Scanner(System.in)
	  val n =  in.nextInt
	  call(1,n)
	}
	def call(n : Int,lim:Int): Unit = {
	  if (lim < n){
	    println("")
	    return
	  }
	  val i = n
	  if(i % 3 == 0){
	    printf(" "+i)
	  }else{
	    callRec(i,i)
	  }
	  call(i+1,lim)
	}
	def callRec(ori:Int,n:Int):Unit={
	  if(n == 0) return
	  if(n % 10 == 3) {
	    printf(" "+ori)
	    return
	  }
	  callRec(ori,n/10)
	}
}

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

int main(void) {
	string S;
	int cnt[3];

	cin >> S;
	for (int i = 0; i < 3; ++i)
		cnt[i] = 0;
	for (int i = 0; i < 3; ++i) {
		int c = (int)(S[i] - 'a');
		++cnt[c];
	}

	bool ans = true;
	for (int i = 0; i < 3; ++i) {
		if (cnt[i] != 1) {
			ans = false;
			break;
		}
	}

	cout << (ans ? "Yes\n" : "No\n");
	return 0;
}


Measured memory_bytes: 256
n=int(input())
l=[0 for i in range(n)]
for i in range(n):
  ka=int(input())
  r,w=[],[]
  for k in range(ka):
    x,y=map(int,input().split())
    r.append(x-1) if y else w.append(x-1)
  l[i]=(set(r),set(w))
ans=0
for j in range(2**n):
  v=format(j,"b").zfill(n)
  R,W=set(),set()
  RR={t for t in range(n) if v[t]=="1"}
  for h in RR:
    r,w=l[h]
    R|=r
    W|=w
  WW=set(range(n))-RR
  if len(RR&W) or len(WW&R) or len(R&W) :continue
  else:ans=max(ans,len(RR))
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};

int N;
vector<int> arr;
int ans = 0;

void input(void){
    cin >> N;
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        arr.emplace_back(a);
    }
}

void solve(void){
    for(int i = 0; i < N; i++) ans += (arr[i] -1);
    cout << ans << endl;
}

int main(void){

    input();
    solve();

    return 0;
}


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

#define F(i, a, b) for (int i = a; i <= b; i ++)
#define G(i, a, b) for (int i = a; i >= b; i --)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define mx(a, b) ((a) = max(a, b))
#define mn(a, b) ((a) = min(a, b))
#define mem(a, b) memset(a, b, sizeof a)
#define mec(a, b) memcpy(a, b, sizeof a)
#define low(x) ((x) & (- (x)))
#define abs(x) max((x), - (x))
#define outarr(a, L, R) { printf(#a"[%d..%d] = ", L, R); F(i, L, R) W(a[i]), putc(' '); putc('\n'); }
#define outtag(x) { printf(#x" = "), W(x); putc('\n'); }
#define outline(x) { puts("--------------------"#x"-----------------------"); }
#define putc putchar
#define get getchar()

using namespace std;

#define ll long long
#define ld long double

template <typename Int>
void Re(Int &x) {
	char c = get; x = 0; Int t = 1;
	for (; !isdigit(c); c = get) t = (c == '-' ? - 1 : t);
	for (; isdigit(c); x = (x << 3) + (x << 1) + c - '0', c = get); x *= t;
}
template <typename Int>
void Wr(Int x) {
	if (x < 0) { putc('-'); x = - x; }
	if (x > 9) Wr(x / 10); putc(x % 10 + '0');
}

const int N = 3e5 + 10;
int w, h, n, Ans;
struct node {
	int x, y;
	friend bool operator < (node a, node b) { return (a.x < b.x || ((a.x == b.x) && (a.y < b.y))); } 
} d[N], L[N], R[N];
struct Segment_Tree {
	int mx, tag;	
} tr[4 * N];

#define Ls (x << 1)
#define Rs (Ls | 1)
#define Md ((st + en) >> 1)
void Update(int x, int st, int en, int l, int r, int add) {
	if (l > en || r < st) return;
    if (l <= st && en <= r) {
        tr[x].tag += add, tr[x].mx += add;
        return;
    }
    if (tr[x].tag) {
    	tr[Ls].tag += tr[x].tag, tr[Ls].mx += tr[x].tag;
	    tr[Rs].tag += tr[x].tag, tr[Rs].mx += tr[x].tag;
	    tr[x].tag = 0;
	}
	Update(Ls, st, Md, l, r, add);
	Update(Rs, Md + 1, en, l, r, add);
    tr[x].mx = max(tr[Ls].mx, tr[Rs].mx);
}

void Solve() {
	mem(tr, 0), sort(d + 1, d + n + 1);
//	F(i, 1, n)
//		printf("%d %d\n", d[i].x, d[i].y);
    int l = 0, r = 0;
    F(i, 1, n - 1) {
        int tmp = i - 1;
        if (d[i].y <= h / 2) {
            while (l && d[i].y > L[l].y) {
                Update(1, 1, n, L[l].x, tmp, L[l].y - d[i].y);
                tmp = L[l].x - 1;
                -- l;
            }
			L[++ l] = {tmp + 1, d[i].y};
        }
		else {
            while (r && d[i].y < R[r].y) {
                Update(1, 1, n, R[r].x, tmp, d[i].y - R[r].y);
                tmp = R[r].x - 1;
                -- r;
            }
			R[++ r] = {tmp + 1, d[i].y};
        }
        L[++ l] = {i, 0}, R[++ r] = {i, h};
        Update(1, 1, n, i, i, h - d[i].x);
        mx(Ans, 2 * (d[i + 1].x + tr[1].mx));
    }
}

int main() {
	Re(w), Re(h), Re(n);
	F(i, 1, n) Re(d[i].x), Re(d[i].y);

	d[++ n] = {0, 0};
	d[++ n] = {w, h};

	Solve();

	swap(w, h);
	F(i, 1, n) swap(d[i].x, d[i].y);

	Solve();

	Wr(Ans);
}

Measured memory_bytes: 16640
#include<cstdio>
#include<algorithm>
#include<vector>

using namespace std;

int n,m;
vector<int> data;

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		data.push_back(a*60+b);
	}
	scanf("%d",&m);
	for(int i=n;i<n+m;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		data.push_back(a*60+b);
	}
	sort(data.begin(),data.end());
	data.erase(unique(data.begin(),data.end()),data.end());
	for(int i=0;i<data.size();i++)printf("%d:%02d%c",data[i]/60,data[i]%60,i==data.size()-1?'\n':' ');
	return 0;
}

Measured memory_bytes: 1064
#include <iostream>
#include <deque>
#include <vector>
#include<string>
using namespace std;
using P = pair<int, int>;

const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main()
{
    int h, w;
    cin >> h >> w;
    int si, sj;
    cin >> si >> sj;
    int ti, tj;
    cin >> ti >> tj;
    --si; --sj; --ti; --tj;
    vector<string> s(h);
    for(int i=0; i<h; i++) cin >> s[i];
    const int INF = 1e9;
    vector<vector <int> > dist(h, vector<int>(w, INF));
    deque<P> q;
    dist[si][sj] = 0;
    q.emplace_back(si, sj);
    while(!q.empty()){
        int i = q.front().first;
        int j = q.front().second;
        int d = dist[i][j];
        q.pop_front();
        if(dist[i][j] != d) continue;

        for(int v = 0; v<4; v++){
            int ni = i+di[v], nj = j+dj[v];
            if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
            if(s[ni][nj] == '#') continue;
            if(dist[ni][nj] <= d) continue;
            dist[ni][nj] = d;
            q.emplace_front(ni, nj);
        }
        for (int ei = -2; ei <= 2; ++ei) {
            for (int ej = -2; ej <= 2; ++ej) {
                int ni = i+ei, nj = j+ej;
                if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
                if (s[ni][nj] == '#') continue;
                if (dist[ni][nj] <= d+1) continue;
                dist[ni][nj] = d+1;
                q.emplace_back(ni,nj);
            }
        }
    }
    
    int ans = dist[ti][tj];
    if(ans == INF) ans = -1;
    cout << ans << endl;

    return 0;

}

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

int rcnt[300300], ccnt[300300];

int main() {
    int h, w, m;
    cin >> h >> w >> m;
    
    int hi[m], wi[m];
    for (int i = 0; i < m; ++i) {
        cin >> hi[i] >> wi[i];
        hi[i]--, wi[i]--;
        rcnt[hi[i]]++, ccnt[wi[i]]++;
    }

    int rmx = 0, rmxcnt = 0;
    for (int i = 0; i < h; ++i) {
        if(rmx < rcnt[i]) {
            rmx = rcnt[i];
            rmxcnt = 1;
            continue;
        }
        if(rmx == rcnt[i]) rmxcnt++;
    }

    int cmx = 0, cmxcnt = 0;
    for (int i = 0; i < w; ++i) {
        if(cmx < ccnt[i]) {
            cmx = ccnt[i];
            cmxcnt = 1;
            continue;
        }
        if(cmx == ccnt[i]) cmxcnt++;
    }

    int bbs = 0;
    for (int i = 0; i < m; ++i) {
        if(rcnt[hi[i]] == rmx && ccnt[wi[i]] == cmx) bbs++;
    }

    cout << rmx + cmx + (bbs == rmxcnt * cmxcnt ? -1 : 0) << endl;
}


Measured memory_bytes: 8280
#include<stdio.h>
int main(){
	int x,y,tmp;
	while(1){
		scanf("%d %d",&x,&y);
		if(x==0&&y==0)break;
		if(x>y){
			tmp=x;
			x=y;
			y=tmp;
		}
		printf("%d %d\n",x,y);
	}

	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <functional>
#include <algorithm>
using namespace std;
typedef long long ll;
double dp[301][301][301];
int main()
{
	int n;
	scanf("%d", &n);
	int f[4] = {};
	for (int x, i = 0; i < n; ++i) {
		scanf("%d", &x);
		++f[x];
	}
	for (int i = 0; i <= n; ++i)
		for (int j = 0; i + j <= n; ++j)
			for (int k = 0; i + j + k <= n; ++k) {
				int w = n - (i + j + k);
				if (w == n)
					continue;
				if (i)
					dp[i][j][k] += i*(1 + dp[i - 1][j + 1][k]) / n;
				if (j)
					dp[i][j][k] += j*(1 + dp[i][j - 1][k + 1]) / n;
				if (k)
					dp[i][j][k] += k*(1 + dp[i][j][k - 1]) / n;
				dp[i][j][k] += w / double(n);
				dp[i][j][k] /= 1 - w / double(n);
			}
	printf("%.9lf\n", dp[f[3]][f[2]][f[1]]);
	return 0;
}

Measured memory_bytes: 213376
#include <bits/stdc++.h>
#define long long long
#define up(i,a,b) for (int i=a; i<=b; i++)
#define down(i,a,b) for (int i=a; i>=b; i--)
#define endl '\n'
#define X first
#define Y second
#define II pair<int, int>
#define III pair<int, pair<int, int> >
#define debug(X) cerr<< #X << " = " <<X << endl
#define debug2(X,Y) cerr<< #X << " = " <<X << ","<<#Y<<" = "<<Y<<endl
#define show(X,a,b) {cerr << #X << " = "; up(__,a,b) cerr << X[__] << ' '; cerr << endl;}
#define gc getchar
#define pc putchar
using namespace std;

inline void read(int &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for (;((c<48 || c>57) && c != '-') ;c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}
inline void writeln(int x){

         char buffor[21];
         register int i=0;
         int neg=0; if (x<0) {neg=1; x= -x;}
         do{
               buffor[i++]=(x%10)+'0';
               x/=10;
            } while(x);
           i--;
           if (neg) pc('-');
           while(i>=0) pc(buffor[i--]);
           pc('\n');
       }
const int N= 510;
int n;
int a[N*N];
int pos[N], List[N];
int em[N];
vector<int> Move;
void input()
{
    cin>>n;
    up(i,1,n) cin>>pos[i], a[pos[i]]= i;
}
bool bypos(int a, int b)
{
	return pos[a]< pos[b];
}
void solve()
{
	up(i,1,n) List[i]= i;
    sort(List+1, List+1+n, bypos);// val List[1] have the minimum pos

    up(i,1,n)
    {
		int val= List[i]; Move.clear(); //debug(i); debug2(val, pos[val]);
		int cnt0= 0;
		up(j,1,pos[val]-1)
		 if (a[j]== 0)
		 {
		 	if (cnt0== val-1) break;
		 	em[++cnt0]= j;
		 }

        if (cnt0== val- 1) up(j,1,val-1) a[em[j]]= val;
        else
		{
            up(j,1,pos[val]-1)
            {
                if (a[j]!=0 and j> pos[a[j]] )
				{
					em[++cnt0]= j; Move.push_back(a[j]);
				}
                if (cnt0== val-1) break;
            }
            if (cnt0< val-1) { cout<<"No"; return; }
            up(j,1,val-1) a[em[j]]= val;//fill the left
            int cur= pos[val]+1;
            for (auto u: Move)//push the Move to the right
			{
				while (cur<=n*n and a[cur]!=0) cur++;
				if (cur== n*n+1) { cout<<"No"; return; }
				a[cur]= u;
			}
		}

		int cur= pos[val]+1;
        up(j,val+1,n)
        {
        	while (cur<= n*n and a[cur]!=0) cur++;
        	if (cur== n*n+1) {cout<<"No"; return; }
        	a[cur]= val;
        }

    }

    cout<<"Yes"<<endl;
    up(i,1,n*n) cout<<a[i]<<" ";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);// don't use when interactive

    #ifdef I_Love_Pork
    #define TASK "agc008_d"
    freopen(TASK".inp","r",stdin);
    freopen(TASK".out","w",stdout);
	  #endif

    input();
    solve();

    return 0;
}


Measured memory_bytes: 2176
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <numeric>
#include <cassert>
#include <cmath>
#include <map>
#include <set>

using namespace std;
typedef long long LL;
typedef double LD;
typedef pair<LD, LD> PLD;
typedef pair<PLD, PLD> PPLD;

#define FOR(k,a,b) for(int k(a); k < (b); ++k)
#define FORD(k,a,b) for(int k(b-1); k >= (a); --k)
#define REP(k,a) for(int k=0; k < (a); ++k)
#define ABS(a) ((a)>0?(a):-(a))
#define EPS 1e-9
#define P45 acos(0.0)/2
#define P90 acos(0.0)

LD cross(PLD a, PLD b) { return a.first * b.second - a.second * b.first; }
LD area2(PLD a, PLD b, PLD c) { return cross(a, b) + cross(b, c) + cross(c, a); }

struct CIRCLE
{
	LD x, y, R;
	CIRCLE() {}
	CIRCLE(LD _x, LD _y, LD _R) : x(_x), y(_y), R(_R) {}
	void Read()
	{
		double _x, _y;
		scanf("%lf %lf", &_x, &_y);
		x = _x, y = _y, R = -1;
	}

	PPLD InterSection(const CIRCLE& other)
	{
		LD lx = x, ly = y, lR = R, ox = other.x, oy = other.y, oR = other.R;
		LD d = (lx - ox)*(lx - ox) + (ly - oy)*(ly - oy);
		d = sqrt(d);
		if (ABS(lR + oR - d) < EPS)
			return PPLD(PLD((x + other.x) / 2, (y + other.y) / 2), PLD(x, y));
		if (d < lR + oR)
		{
			LD a = (lR * lR - oR*oR + d*d) / (2.0*d);
			LD h = sqrt(lR*lR - a*a);
			PLD tp1(lx + a*(ox - lx) / d, ly + a*(oy - ly) / d);
			PLD p1(tp1.first + h*(oy - ly) / d, tp1.second - h*(ox - lx) / d);
			PLD p2(tp1.first - h*(oy - ly) / d, tp1.second + h*(ox - lx) / d);
			return PPLD(p1, p2);
		}
		return PPLD(PLD(x, y), PLD(x, y));
	}	
	bool IsIn(const PLD& p) const
	{
		return ABS((p.first - x)*(p.first - x) + (p.second - y)*(p.second - y)) <   R * R + EPS;
	}
};


int main() {
	int N, M;
	scanf("%d", &N);
	M = N;
	vector<CIRCLE> v(N);
	REP(i, N)
		v[i].Read();
	LD lo = 0, hi = 2000;
	while (ABS(hi - lo) > 0.0000001)
	{
		LD actR = (hi + lo) / 2;
		REP(i, N)
			v[i].R = actR;
		int mx = 0;
		REP(i, N) FOR(j,i+1,N)
		{
			PPLD ip = v[i].InterSection(v[j]);
			CIRCLE c1,c2;
			c1.x = ip.first.first, c1.y = ip.first.second, c1.R = actR;
			int db1 = 0, db2 = 0;
			REP(k, N)
			{
				if (c1.IsIn(make_pair(v[k].x, v[k].y)))
					++db1;
			}
			c2.x = ip.second.first, c2.y = ip.second.second, c2.R = actR;
			REP(k, N)
			{
				if (c2.IsIn(make_pair(v[k].x, v[k].y)))
					++db2;
			}
			mx = max<int>(max<int>(db1, db2),mx);
		}
		if (mx >= M)
			hi = actR;
		else
			lo = actR;
	}
	printf("%.10lf\n", lo);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), string{})
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << "\n"; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

int main(void){
    Cin(int, n, _);
    Cins(string, n, s);
    Sort(s);
    Cout(Sum(s));
}


Measured memory_bytes: 256
N = int(input())
L = list(map(int, input().split()))
list.sort(L)
c = 0

for i in range(0, N):
        for j in range(i + 1, N):
                for k in range(j + 1, N):
                        if L[i] != L[j] and L[j] != L[k] and L[k] != L[i]:
                                if L[i] + L[j] > L[k]:
                                        c += 1

print(c)

Measured memory_bytes: 9188
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

ll fact(ll x){
	if(x<=1) return 1;
	ll r = 1;
	rep(i, x) r = r*(i+1)%mod;
	return r;
}

int main(){
	ll a, b;
	cin>>a>>b;
	if(a>b) swap(a, b);
	if(a+1<b){
		cout<<0<<endl;
	} else if(a==b){
		cout<<2*fact(a)*fact(b)%mod<<endl;
	} else {
		cout<<fact(a)*fact(b)%mod<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <cstring>
#include <set>
#include <map>
using namespace std;
#define ld long double
#define F first
#define S second
#define ll long long
#define int ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define pb push_back
#define p1 1000000007
#define p 998244353
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
const int N=1e2+10;
const int W=1e5+3;
const int inf=1e17+10;
int n;
int v[N],w[N];
int dp[N][W];
int rec(int i,int c)
{
    if(i<=0||c<=0) return 0;
    if(dp[i][c]!=-inf) return dp[i][c];
    if(c-w[i]>=0)
    return dp[i][c]=max(rec(i-1,c),rec(i-1,c-w[i])+v[i]);
    else return dp[i][c]=rec(i-1,c);
    
}
int32_t main()
{
  int c;
  cin>>n>>c;
  for(int i=1;i<N;i++)
  for(int j=1;j<W;j++)
  dp[i][j]=-inf;
  for(int i=1;i<=n;i++)
      cin>>w[i]>>v[i];
  cout<<rec(n,c);

}


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


int main(){
    string s;
    cin >> s;
    int i=s.size();
    int j=0;
    bool play=true;
    while ((j<i)&&(play==true)){

        if ((j%2==0)&& (s[j]=='L')){
            play=false;
        }else if((j%2==1)&&(s[j]=='R')){
            play=false;
        }

        j++;
    }
    if (play==true){
        cout << "Yes";
    }else{
        cout << "No";
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD7 1000000007
#define MOD9 1e9 + 9
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
typedef long long ll;
typedef long double ld;
typedef string str;
typedef double d;
typedef unsigned u;
typedef unsigned long long ull;

const long long BIGINF = 2e18 + 7;
const int INF = 2e9 + 7;

long long dp[200005];
vector<pair<int, int>> v;


int binSearch(int target,int low, int high) {
	int ans = -1;
	while (low <= high) {
		int mid = low + (high - low)/2;
		if (v[mid].first == target)
			return mid;
		else if (v[mid].first < target) {
			ans = max(mid, ans);
			low = mid + 1;
		}
		else high = mid - 1;
	}
	return ans;
}



int main () {
	/*#ifndef ONLINE_JUDGE
		freopen("inputf.txt", "r", stdin);
		freopen("outputf.txt", "w", stdout);
	#endif*/
	int n, range, damage;
	SCD(n);
	SCD(range);
	SCD(damage);
	int x, h;
	for (int i = 0; i < n; i++) {
		SCD(x);
		SCD(h);
		v.emplace_back(x, h);
	}
	sort(v.begin(), v.end());
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		//printf("%d %d\n", v[i].first, v[i].second);
		dp[i] = dp[i] + (i > 0? dp[i - 1] : 0);
		//printf("dp[%d] = %lld, ", i, dp[i]);
		if (v[i].second - dp[i] <= 0) {
			//puts("");
			continue;
		}
		v[i].second -= dp[i];
		long long dam = v[i].second / damage;
		if (v[i].second % damage != 0) dam++;
		ans += dam;
		dam = 1LL * dam * damage;
		int end = binSearch(v[i].first + range*2, i, n-1);
		//printf("end = %d ", end);
		end = (end != -1? end + 1: n); 
		dp[i] += dam;
		dp[end] -= dam;
		//printf("ans = %lld, dam = %lld, end = %d\n", ans, dam, end);
	}
	printf("%lld\n", ans);
    return 0;
}



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

using namespace std;
#define ll long long 
int main(){
	ll n,s;
	cin>>n>>s;
	ll v[n];
	ll w[n];
	for(int i=0;i<n;i++){
		cin>>w[i]>>v[i];
	}
	ll dp[n+1][s+1];
	for(int i=0;i<=n;i++){
		dp[i][0]=0;
	}
	for(int i=0;i<=s;i++){
		dp[0][i]=0;
	}

	for(int i=1;i<=n;i++){
		for(int j=1;j<=s;j++){
			if(w[i-1]<=j) dp[i][j]=max(dp[i-1][j],v[i-1]+dp[i-1][j-w[i-1]]);
			else dp[i][j]=dp[i-1][j];
		}
	}
	cout<<(ll)dp[n][s]<<endl;



}


Measured memory_bytes: 81964
// sum_d sum_s sum_{t s.t. d(s,t) = d} C(1) + 2 C(2) + ... + d C(d)
//
// C(1) >= C(2) >= ...
//
// (s, t) such that s[i1] != t[i1], ..., s[ik] != t[ik] について
//   C(i1) + 2 C(i2) ... + k C(ik)
// を全部の (s,t) で足しあげたい
//
// C(i) の contribution. j < i に k 回違うのがあると k C(i)
// そういうのは (i-1 choose k-1) 2^{i-1} 4^{n-i} k C(i)
//
// これを k について総和すると 4^{n-1} (i+1) C(i)
//
use proconio::input;

#[derive(Copy,Clone,Eq,PartialEq)]
struct ModInt {
  val: isize,
}
impl ModInt {
  const MOD: isize = 1_000_000_007;
  fn new(val: isize) -> Self {
    Self { val } 
  }
  fn pow(self, mut e: isize) -> Self {
    let mut a = self.val;
    let mut x = 1;
    while e > 0 {
      if e % 2 == 1 { 
        x = (x * a) % ModInt::MOD;
      }
      a = (a * a) % ModInt::MOD;
      e /= 2;
    }
    Self { val: x }
  }
}
impl std::ops::Add for ModInt {
  type Output = Self;
  fn add(self, other: Self) -> Self { 
    Self { 
      val: (self.val + other.val) % ModInt::MOD 
    }
  }
}
impl std::ops::Mul for ModInt {
  type Output = Self;
  fn mul(self, other: Self) -> Self { 
    Self { 
      val: (self.val * other.val) % ModInt::MOD
    }
  }
}

fn main() {
  input! {
    n: usize,
    mut c: [isize; n],
  }
  c.sort();
  c.reverse();

  let mut ans = ModInt::new(0);
  for i in 0..n {
    ans = ans + ModInt::new(i as isize + 2) * ModInt::new(c[i]);
  }
  ans = ans * ModInt::new(4).pow(n as isize -1);
  println!("{}", ans.val);
}


Measured memory_bytes: 6244
#!/usr/bin/env python3
import sys
from collections import defaultdict, deque


class Node:
    def __init__(self, label, index):
        self.label = label
        self.index = index

    def __eq__(self, other):
        return (self.label == other.label) and (self.index == other.index)

    def __str__(self):
        return "(" + ",".join(map(str, [self.label, self.index])) + ")"

    def __repr__(self):
        return self.__str__()


def solve(N: int, M: int, u: "List[int]", v: "List[int]", S: int, T: int):
    if M == 0:
        print(-1)
        return
    a = defaultdict(list)
    b = defaultdict(list)
    c = defaultdict(list)
    edge = [a, b, c]
    for i in range(M):
        edge[0][u[i]].append(Node(1, v[i]))
        edge[1][u[i]].append(Node(2, v[i]))
        edge[2][u[i]].append(Node(0, v[i]))
    start_node = Node(0, S)
    end_node = Node(0, T)

    class BFSearch:
        def __init__(self):
            self.queue = deque()
            a = [0] * (M + 1)
            b = [0] * (M + 1)
            c = [0] * (M + 1)
            self.steps = [a, b, c]

        def search(self, node):
            self.queue.append(node)
            while self.queue:
                node_now = self.queue.popleft()
                step_now = self.steps[node_now.label][node_now.index]
                next_nodes = edge[node_now.label][node_now.index]
                for next_node in next_nodes:
                    s = self.steps[next_node.label][next_node.index]
                    if s > 0:
                        continue
                    if next_node == end_node:
                        return step_now + 1
                    self.steps[next_node.label][next_node.index] = step_now + 1
                    self.queue.append(next_node)
            return -1

    dfs = BFSearch()
    ans = dfs.search(start_node)
    print(ans // 3 if ans % 3 == 0 else -1)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    u = [int()] * (M)  # type: "List[int]"
    v = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        u[i] = int(next(tokens))
        v[i] = int(next(tokens))
    S = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    solve(N, M, u, v, S, T)


if __name__ == "__main__":
    main()


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

int main() {
  int n, limit;
  cin >> n >> limit;
  vector<vector<int>> adj;
  adj.resize(n);
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v, --u, --v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }

  function<int(int, int, int)> dfs = [&](int u, int father, int height) {
    int answer = height < 0;
    for (int v : adj[u]) {
      if (v != father) {
        answer += dfs(v, u, height - 1);
      }
    }
    return answer;
  };

  int answer = n;
  if (~limit & 1) {
    for (int u = 0; u < n; ++u) {
      answer = min(answer, dfs(u, -1, limit / 2));
    }
  } else {
    for (int u = 0; u < n; ++u) {
      for (int v : adj[u]) {
        int a = dfs(u, v, limit / 2);
        int b = dfs(v, u, limit / 2);
        answer = min(answer, a + b);
      }
    }
  }
  cout << answer << endl;

  return 0;
}

Measured memory_bytes: 512
while True:
    n = int(input())
    if n == 0:
        break
    score = [0, 0]
    for _ in range(n):
        A, B = map(int, input().split())
        if A == B:
            score[0] += A
            score[1] += B
        else:
            score[A < B] += A+B
    print(*score)

Measured memory_bytes: 5616
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char temp1[],temp2[];
        int hit, blow;
        while (sc.hasNext()){
            temp1 = sc.next().toCharArray();
            temp2 = sc.next().toCharArray();
            if (temp1.length==1&&temp2.length==1&&temp1[0]=='0'&&temp2[0]=='0')break;
         
            hit = 0;
            blow=0;
            for (int i=0;i<4;i++) {
                if (temp1[i]==temp2[i])hit++;
                
            }
            for (int i=0;i<4;i++) {
                for (int j=0;j<4;j++) {
                    if (i!=j&&temp2[i]==temp1[j])blow++;
                }
            }
            System.out.println(hit + " " + blow);
        }
    }
}

Measured memory_bytes: 43928
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << x << endl

ll aI, aO, aT, aJ, aL, aS, aZ;

signed main(){
    while(cin >> aI >> aO >> aT >> aJ >> aL >> aS >> aZ){
        ll ans = 0;
        int km = min({aI, aJ, aL});
        for(int k = km; k >= max<ll>(0, km - 3); --k){
            ll cand = aO*2;
            ll aI = ::aI;
            ll aJ = ::aJ;
            ll aL = ::aL;
            aI -= k;
            aJ -= k;
            aL -= k;
            cand += k * 6;
            cand += aI/2 * 4;
            cand += aJ/2 * 4;
            cand += aL/2 * 4;
            ans = max(cand, ans);
        }
        cout << ans/2 << endl;
    }
}


Measured memory_bytes: 384