akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define int long long
#define MOD 1000000007


#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b) - 1; i >= (a); i--)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define all(i) (i).begin(),(i).end()
#define rall(i) (i).begin(),(i).end(),greater<int>()
using namespace std;

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T> void print(T x) { std::cout << x << '\n'; }
 
//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

int N;
vector<int>V;
vector<int>C;

signed main(){
 
    cin>>N;
    V.resize(N);
    C.resize(N);

    rep(i,N){
        cin>>V[i];
    }
    rep(i,N){
        cin>>C[i];
    }

    vector<int> v_c;
    rep(i,N){
        v_c.pb(V[i]-C[i]);
    }

    sort(all(v_c),greater<>());

    int ans=0;

    rep(i,N){
        if(v_c[i]>0){
            ans+=v_c[i];
        }
        else{
            break;
        }
    }


    cout<<ans<<endl;

    return 0;
 
}


Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

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

    int a[3];
    for (int i = 0; i < 3; i++) cin >> a[i];
    sort(a, a + 3);
    int ans = abs(a[1] - a[0]) + abs(a[2] - a[1]);
    cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
flag = 0
ans = False
for _ in range(N):
    d1,d2 = map(int,input().split())
    if d1==d2:
        flag += 1
        if flag==3:
            ans = True
            break
    else:
        flag = 0
print('Yes' if ans else 'No')

Measured memory_bytes: 62160
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,k;
	cin>>a>>b>>k;
	int com[110];
	int x=0;
	for(int i=min(a,b);i>=1;i--){
		if(a%i==0&&b%i==0)
		{
			x++;
			com[x]=i;
		}
	}
	cout<<com[k]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void){
    int n,i,x=0;
    char s[50];
    scanf("%d",&n);
    scanf("%s",s);
    for(i=0;i<n;i++){
        if(s[i]=='A'){
            if(s[i+1]=='B'){
                if(s[i+2]=='C')
                x++;
            }
        }
    }
    printf("%d",x);
    return 0;
}

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

int main(){
	int height[10];
	for (int i=0;i<10;i++){
		cin >> height[i];
	}
	for (int h = 0;h<9;h++){
	for (int i=0;i<9;i++){
		if (height[i]<height[i+1]){
			int a;
			a = height[i];
			height[i]=height[i+1];
			height[i+1] = a;
		}
	}
	}
	for (int i =0;i<3;i++){
		cout << height[i] <<endl;
	}
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pr(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100005
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PA;
typedef map<ll, ll> Map;

ll N;
ll ans=0;

void dfs(ll s, ll d) {
    if(s>N) return;
    
    ll cnt[11]={};
    
    for(ll i=0; i<d; i++) {
        cnt[s/(ll)pow(10, d-1-i)%10]++;
    }
    
    if(cnt[3]>0 && cnt[5]>0 && cnt[7]>0) ans++;
    
    for(ll i=3; i<=7; i+=2) {
        dfs(s*10+i, d+1);
    }
    
}


int main(void) {
    cin >> N;
    
    dfs(0, 0);
    
    pr(ans);
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);

void solve(){
    ll n; cin >> n;
    vector<ll> l(n+1, 0);
    l[0] = 2;
    l[1] = 1;
    for(int i=2; i<=n; i++){
        l[i] = l[i-1] + l[i-2];
    }
    cout << l[n] << endl;
}

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

Measured memory_bytes: 256
import heapq

n = int(input())
s = list(map(int, input().split()))

# 中央値より左・右の管理
l=[]
r=[]
heapq.heapify(l)
heapq.heapify(r)
lenl=0
lenr=0
# 中央値
x = s[1]

# b含めた答え
ans = s[2]

for i in range(n-1):
    q = list(map(int,input().split()))
    if q[0]==1:
        ans += q[2]
        if (lenl+lenr)%2==0:
            lenr+=1
            ans+=abs(x-q[1])
            if x<=q[1]:
                heapq.heappush(r,q[1])
            else:
                heapq.heappush(l,-q[1])
                heapq.heappush(r,x)
                x = -heapq.heappop(l)
        else:
            lenl+=1
            if x<q[1]:
                heapq.heappush(l,-x)
                heapq.heappush(r,q[1])
                x=heapq.heappop(r)
            else:
                heapq.heappush(l,-q[1])
            ans+=abs(x-q[1])
    if q[0]==2:
        print(x, ans)

Measured memory_bytes: 88920
#include <iostream>

using namespace std;

int main() {
    int n1, n2, n3, n4;
    bool first = false, second = false, third = false, fourth = false;

    cin >> n1 >> n2 >> n3 >> n4;

    if (!first) {
        if (n1 == 1) first = true;
        else if (n2 == 1) first = true;
        else if (n3 == 1) first = true;
        else if (n4 == 1) first = true;

        if (!second) {
            if (n1 == 9) second = true;
            else if (n2 == 9) second = true;
            else if (n3 == 9) second = true;
            else if (n4 == 9) second = true;

            if (!third) {
                if (n1 == 7) third = true;
                else if (n2 == 7) third = true;
                else if (n3 == 7) third = true;
                else if (n4 == 7) third = true;

                if (!fourth) {
                    if (n1 == 4) fourth = true;
                    else if (n2 == 4) fourth = true;
                    else if (n3 == 4) fourth = true;
                    else if (n4 == 4) fourth = true;
                }
            }
        }
    }

    if (first && second && third && fourth) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>
#include <cstdlib>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;
using Graph = Vvec<int>;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

int main()
{
    int N, M;
    string s;
    cin >> N >> M >> s;
    Graph graph(N);
    for(int i=0; i<M; i++){
        int u, v;
        cin >> u >> v;
        u--; v--;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    vector<int> A(N), B(N);
    for(int i=0; i<N; i++){
        if(s[i] == 'A'){
            for(auto j: graph[i]) A[j]++;
        }else{
            for(auto j: graph[i]) B[j]++;
        }
    }

    // debug(A);
    // debug(B);
    queue<int> q;
    set<int> st;
    for(int i=0; i<N; i++){
        if(A[i] == 0 || B[i] == 0) q.push(i);
        else st.insert(i);
    }

    while(!q.empty()){
        int i = q.front();
        q.pop();
        if(s[i] == 'A'){
            for(auto j: graph[i]){
                if(st.find(j) == st.end()) continue;
                A[j]--;
                if(A[j] == 0){
                    st.erase(j);
                    q.push(j);
                }
            }
        }else{
            for(auto j: graph[i]){
                if(st.find(j) == st.end()) continue;
                B[j]--;
                if(B[j] == 0){
                    st.erase(j);
                    q.push(j);
                }
            }
        }
    }

    cout << ((st.empty()) ? "No" : "Yes") << "\n";
    // cout << st.size() << endl;
}

Measured memory_bytes: 16644
import math

input_str = input().split(' ')
a = int(input_str[0])
b = int(input_str[1])
theta = int(input_str[2]) * math.pi / 180
c = math.sqrt(a*a-2*a*b*math.cos(theta)+b*b)

h = b * math.sin(theta)
S = a * h / 2
L = a + b + c

print('%.8f'%S)
print('%.8f'%L)
print('%.8f'%h)

Measured memory_bytes: 7888
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
#include <iomanip>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;


int main(){
    long double x;
    cin >> x;
    ll ans = 0;
    for(ll i = 100; i < x; ){
        ans++;
        i = floor(i*1.01);
    }
    //ans = floor(log(x/100.0) / log(1+0.01));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3772
# ABC043C - いっしょ / Be Together (ARC059C)
def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    ans = []
    for i in range(min(A), max(A) + 1):
        cnt = sum((i - a) ** 2 for a in A)
        ans += [cnt]
    print(min(ans))


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
using namespace std;
inline int D()
{
	int t;
	scanf("%d",&t);
	return t;
}
inline ll llD(){
	ll t;
	scanf("%lld",&t);
	return t;
}
const int N=2e5+9;

int arr[N],in[N];
int main(){
    int a=D();
    int b=D();
    int cnt=0;
    for(int i =0 ;i <=a;i++)
        for(int j =0 ;j <=a;j++)
        {
        if(b-(i+j)<=a)
            if(b-(i+j)>=0)
        cnt++;
      ///  cout<<a<<" "<<b<<endl;
     ///   cout<<i<<" "<<j<<" "<<cnt<<endl;
        }

        cout<<cnt;

    }

/**
bool ok(int val){
  int cntm=0,cntp=0;
  for(int i=0;i<n-val;i++)
  {
      cntm=0;cntp=0;
      for(int j=i;j<val;j++)
      {
      (arr[j]==1)?cntp++:cntm++;
      }
      if(cntp==cntm)
        break;
  }
  return cntp==cntm;
}
int binarySearch(){
  int low = 0, med, hi =n;
  while(low<hi){
    med = (low+hi+1)>>1;
    cout<<med<<" "<<hi<<" "<<low<<endl;
    if(ok(med))  low = med;
    else  hi = med-1;
  }
  return low;
}*/



/**
  int power1(int b, int p){               //O(p)
    if(!p)  return 1;
    return b*power1(b, p-1);
  }
  int power2(int b, int p){               //O(Log(p))
    if(!p)  return 1;
    int ret = power2(b, p/2);
    return (p&1 ? ret*ret*b : ret*ret);
  }
   int mul(int a, int b, int m){
      return (a%m * b%m) % m;
  }

*/


/**
void seive()
{
    bitset<N>iscomp;
    iscomp[0]=iscomp[1]=1;
    for(long long i=2; i<=N; ++i)
    {
        if(!iscomp[i])
        {
            a.push_back(i);
            for(long long j=i*i; j<=N; j+=i)
                iscomp[j]=1;
        }
    }
}
3
abc
abc
*/

    /**


    */


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    double n,d,x,ans=0;
    cin>>n>>d>>x;
    for(;n>0;n--){
	ans+=d+(n-0.5)*x;
	d+=(d+x*2.5)/n;
	x*=(2/n+1);
    }
    printf("%.9lf\n",ans);
    return 0;
}


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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

const ll INF = 1LL << 60;

ll mod=1000000007;

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


int main() {
  int n;cin>>n;
  vector<int> c(4,0);
  rep(i,n){
    string s;cin>>s;
    if(s=="AC")c[0]++;
    if(s=="WA")c[1]++;
    if(s=="TLE")c[2]++;
    if(s=="RE")c[3]++;
  }

  cout<<"AC x "<<c[0]<<endl;
  cout<<"WA x "<<c[1]<<endl;
  cout<<"TLE x "<<c[2]<<endl;
  cout<<"RE x "<<c[3]<<endl;
}

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

using namespace std;

int main(void) {
  int N, max, i, tmp;
  vector<int> H;
  cin >> N;
  for(i = 0; i < N; i++) {
    cin >> tmp;
    H.push_back(tmp);
  }
  
  max = 0;
  for(i = 0; i < N; i++) {
    tmp = 0;
    while(i < N-1 && H[i] >= H[i+1]) {
      i++;
      tmp++;
    }
    if(max < tmp) {
      max = tmp;
    }
  }
  
  cout << max << endl;
  return 0;
}

Measured memory_bytes: 892
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (a < b && b < c) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 26240
/*
dreamerer
*/
#include <bits/stdc++.h>
using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; const int N = 5e5 + 5, M = 998244353, INF = 0x3f3f3f3f; const ll LNF = 0x3f3f3f3f3f3f3f3f; void Main();
void debug() { cerr << endl; } template <typename T, typename... Ts> void debug(T x, Ts... y) { cerr << "\033[31m" << x << "\033[0m"; if (sizeof...(y) > 0) cerr << ' '; debug(y...); } template <typename T> void debug(const T& a, int l, int r, char c) { for (int i = l; i <= r; ++i) cerr << "\033[31m" << a[i] << "\033[0m" << (i == r ? '\n' : c); }
void print() { cout << '\n'; } template <typename T, typename... Ts> void print(T x, Ts... y) { cout << x; if (sizeof...(y) > 0) cout << ' '; print(y...); } template <typename T> void print(const T& a, int l, int r, char c) { for (int i = l; i <= r; ++i) cout << a[i] << (i == r ? '\n' : c); }
void input() {} template <typename T, typename... Ts> void input(T& x, Ts&... y) { cin >> x; input(y...); } template <typename T> void input(T* a, int l, int r) { for (int i = l; i <= r; ++i) cin >> a[i]; } template <typename T> void input(vector<T>& a, int l, int r) { for (int i = l; i <= r; ++i) cin >> a[i]; }
template <typename T> void Max(T& a, T b) { if (a < b) a = b; } template <typename T> void Min(T& a, T b) { if (a > b) a = b; } template <typename T> void Add(T& a, T b) { a += b; if (a > M) a -= M; if (a < 0) a += M; } template <typename T> void Mul(T& a, T b) { a = a * b % M; } template <typename T> T Mod(T a) { return (a % M + M) % M; }
int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); /* cout << setprecision(10) << fixed; */
#ifdef Zmm
    if (argc) { freopen((string(*(argv)).substr(2, string(*(argv)).size() - 6) + string(".cpp")).c_str(), "r", stdin); string x; cin >> x; }
#endif
    Main();
}
// void replace(string& s, const string& t) {
    
// }
// bool replace(std::string& str, const std::string& from, const std::string& to) {
//     size_t start_pos = str.find(from);
//     if(start_pos == std::string::npos)
//         return false;
//     str.replace(start_pos, from.length(), to);
//     return true;
// }
void replaceAll(std::string& str, const std::string& from, const std::string& to) {
    if(from.empty())
        return;
    size_t start_pos = 0;
    while((start_pos = str.find(from, start_pos)) != std::string::npos) {
        str.replace(start_pos, from.length(), to);
        start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx'
    }
}
/*
s=input()
s=s.replace('eraser','')
s=s.replace('erase','')
s=s.replace('dreamer','')
s=s.replace('dream','')
if s=='':
    print("YES")
else :
    print("NO")
*/
void Main() {
    string s;
    input(s);
    replaceAll(s, "eraser", "");
    replaceAll(s, "erase", "");
    replaceAll(s, "dreamer", "");
    replaceAll(s, "dream", "");
    print(s.size() == 0 ? "YES" : "NO");
}

Measured memory_bytes: 3708
import Control.Applicative ((<$>))

fi = fromIntegral

main :: IO ()
main = do
  [n,k] <- map read . words <$> getLine :: IO [Int]
  print $ if min (ceiling (fi n/fi k)*k-n) (n-(n`div`k)*k) > 0
    then 1
    else 0

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

int cnt, m;
std::vector<int> G;

void insertionSort(std::vector<int>&a, int n, int g){
    for(int i = g; i < n; i++){
        int v = a[i];
        int j = i - g;
        while(j >= 0 && a[j] > v){
            a[j+g] = a[j];
            j = j - g;
            cnt++;
        }
        a[j+g] = v;
    }
    //cnt++;

}

void shellSort(std::vector<int>& a, int n){
    cnt = 0;
    //std::vector<int> G;
    int x = 1;
    G.push_back(x);
    while(true){
        x = 3 * x + 1;
        if(x >= n){
            break;
        }else{
            G.push_back(x);
        }
    }
    std::reverse(G.begin(), G.end());
    m = G.size();
    for(int i = 0; i < m; i++){
        insertionSort(a, n, G[i]);
    }
}

void displayVector(std::vector<int> a, int n){
    for(int i = 0; i < n; i++){
        std::cout << a[i];
        if(i != n-1){
            std::cout << " ";
        }
    }
    std::cout << std::endl;
}

int main(void){
    
    int n, g;

    scanf("%d", &n);
    std::vector<int> a(n);
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }

    shellSort(a, n);
    insertionSort(a, n, g);

    std::cout << m << std::endl;
    displayVector(G, m);
    std::cout << cnt << std::endl;
    for(int i = 0; i < n; i++){
        std::cout << a[i];
        //if(i != n - 1){
            std::cout << std::endl;
        //}
    }
    return 0;
}


Measured memory_bytes: 6776
import java.io.*;
import java.util.*;
import java.util.function.*;

final class Solver {
	void solve(Supplier<String> sc) {
		int N = Integer.parseInt(sc.get());
		int M = Integer.parseInt(sc.get());
		int K = Integer.parseInt(sc.get());
		int[] A = new int[N];
		Arrays.setAll(A, $ -> Integer.parseInt(sc.get()));
		int[] B = new int[M];
		Arrays.setAll(B, $ -> Integer.parseInt(sc.get()));
		var cumA = new long[N];
		cumA[0] = A[0];
		for (int i = 1; i < N; i++) {
			cumA[i] = cumA[i - 1] + A[i];
		}
		var cumB = new long[M];
		cumB[0] = B[0];
		for (int i = 1; i < M; i++) {
			cumB[i] = cumB[i - 1] + B[i];
		}
		int max = 0;
		for (int i = N - 1; i >= 0; i--) {
			long time = cumA[i];
			if (time > K) continue;

			int ok = -1;
			int ng = M;
			while (Math.abs(ok - ng) > 1){
				int mid = (ng + ok) / 2;
				if (time + cumB[mid] <= K) ok = mid;
				else ng = mid;
			}
			if (ok < 0){
				max = Math.max(max, i + 1);
			}else max = Math.max(max, i + ok + 2);
		}
		for (int i = B.length - 1; i >= 0; i--) {
			long time = cumB[i];
			if (time > K) continue;
			max = Math.max(max, i + 1);
			break;
		}
		System.out.println(max);
	}
}

class Main {
	public static void main(String... args) {
		System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		var reader = new BufferedReader(new InputStreamReader(System.in));
		new Solver().solve(new Supplier<>() {
			StringTokenizer line;

			public String get() {
				while (line == null || !line.hasMoreTokens()) try {
					line = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
				return line.nextToken();
			}
		});
		System.out.flush();
	}
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(3*N);
  for(int i=0; i<3*N; i++){
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  
  long sum=0;
  for(int i=N-1; i>=0; i--){
    sum+=a.at(N+2*i);
  }
  cout << sum << endl;
}

Measured memory_bytes: 1408
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
	ios::sync_with_stdio(false); cin.tie(0);
	string s;
  cin >> s;
  int y = stoi(s.substr(0, 4));
  int m = stoi(s.substr(5, 2));
  string ans;
  if (y > 2019) ans = "TBD";
  else if (y == 2019 && m > 4) ans = "TBD";
  else ans = "Heisei";
  cout << ans << endl;
	return 0;	 
}

Measured memory_bytes: 256
m, k = map(int, input().split())
if m == 1:
    if k == 0:
        print(0, 0, 1, 1)
    else:
        print(-1)
else:
    s = 2 ** m
    if k >= s:
        print(-1)
    else:
        ans = [k]
        for i in range(s):
            if i != k:
                ans.append(i)
        ans.append(k)
        for i in range(s - 1, -1, -1):
            if i != k:
                ans.append(i)
        print(*ans)


Measured memory_bytes: 19312
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tll;

/**
 * 最大公約数 
 */
ll gcd(ll numA, ll numB)
{
    return numB ? gcd(numB, numA % numB) : numA;
}

/** 
 * 最小公倍数
 */
ll lcm(ll x, ll y)
{
    return x / gcd(x, y) * y;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> nums(N);
    for (int i = 0; i < N; i++)
    {
        cin >> nums.at(i);
    }
    ll answer = 0;
    for(int i = 0; i < N; i++)
    {
        answer += nums.at(i) - 1;
    }
    cout << answer << endl;
    return 0;
}


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

int main() {
    int N;
    long long K;
    cin >> N >> K;
  
   long long int A[100010];
  
    for (int i = 0; i < N; ++i) cin >> A[i];
        
    long long ans = 0;
  
    for (int d = 60; d >= -1; d--) { 
        if (d != -1 && !(K & (1LL<<d))) continue;
        
        long long tmp = 0;
        for (int e = 60; e >= 0; e--) {
            long long x = 1LL<<e;
            int num = 0;
            for (int i = 0; i < N; ++i) if (A[i] & x) ++num;
            
            if (e > d) {
                if (K & x) tmp += x* (N - num);
                else tmp += x * num;
            }
            else if (e == d) {
                tmp += x * num;
            }
            else {
                tmp += x * max(num, N - num);
            }
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(){
  int a,b,i,j=0;
  scanf("%d%d",&a,&b);
  for(i=a;i<=b;i++){
    if(i/10000==i%10&&(i/1000)%10==(i/10)%10)j++;
  }
  printf("%d",j);
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void){
	int i,j;
	int n,cube,tetra;
	int max;

	while(scanf("%d",&n) && n){
		max = 0;
		for(i=0;(cube=i*i*i)<=n;i++){
			for(j=0;cube+(tetra=j*(j+1)*(j+2)/6)<=n;j++){
				if(cube + tetra > max) max = cube + tetra;
			}
		}
		printf("%d\n",max);
	}

	return 0;
}

Measured memory_bytes: 0
let partition (a : int array) p r =
  let i = ref p in
  for j = p to r - 1 do
    if a.(j) <= a.(r) then begin
      let tmp = a.(!i) in
      a.(!i) <- a.(j);
      a.(j) <- tmp;
      incr i;
    end
  done;
  let tmp = a.(!i) in
  a.(!i) <- a.(r);
  a.(r) <- tmp;
  !i

let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun i -> i)) in
  let k = partition a 0 (n - 1) in
  print_int a.(0);
  for i = 1 to n - 1 do
    if i = k then (print_string " ["; print_int a.(i); print_string "]")
    else (print_string " "; print_int a.(i))
  done;
  print_newline ()

Measured memory_bytes: 5336
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include<iomanip>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n, k; cin >> n >> k;
	double a = n;
	double res = 0;
	rep(i, 1, n)
	{
		int x = i;
		double temp = 1.0 / a;
		while (x < k)
		{
			x *= 2;
			temp *= 0.5;
		}
		res += temp;
	}
	cout << setprecision(10) << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int u32;
typedef pair<int, int> p;
int Inf = 1000000000;
ll inf = 1000000000000;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main(){
	int n,m;
	cin >> n >> m;
	int ans = n / m;
	if (n % m > 0) ans++;
	cout << ans;
	return(0);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

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

  if (n / 100 > 12 || n / 100 == 0) { // ue no month
    if (n % 100 > 12 || n % 100 == 0) { // sita no month
      P("NA");
    } else {
      P("YYMM");
    }
  } else if (n % 100 > 12 || n % 100 == 0) { // sita no month
    P("MMYY");
  } else {

    P("AMBIGUOUS");
  }

  return 0;

}

Measured memory_bytes: 256
import java.util.*;

class Main {
    private static final Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        // ??\????????????
        // ??¬??\??§????????°???????????§????????´???????????????????????°???????????°?????????????????\????????????
        int[] a = new int[3];
        for (int i = 0;i < 3;i++) {
            a[i] = sc.nextInt();
        }
        // ?????????
        Arrays.sort(a);
        // ??????
        for (int i = 0;i < 3;i++) {
            // ?????????
            System.out.print(a[i]);
            // ?????????????°???????????????????
            if (i==2) break;
            // ????§???????????????\??????
            System.out.print(" ");
        }
        // ??????
        System.out.println("");
    }
}

Measured memory_bytes: 26244
H, W = map(int, input().split())
field = []
for i in range(0, H):
	field.append(input())
countwhite = 0
for i in range(0, H):
	for j in range(0, W):
		if field[i][j] == '.':
			countwhite += 1
minfield = []
for i in range(0, H):
	lst = []
	for j in range(0, W):
		lst.append(5000000000000000)
	minfield.append(lst)
queue = [[1, [0, 0]]]
while queue != []:
	now = queue.pop(0)
	if now[0] < minfield[now[1][0]][now[1][1]]:
		minfield[now[1][0]][now[1][1]] = now[0]
		for i in range(0, 2):
			nexth = now[1][0] - 1 + 2*i
			if 0 <= nexth and nexth < H:
				if field[nexth][now[1][1]] == '.':
					queue.append([now[0]+1, [nexth, now[1][1]]])
			nextw = now[1][1] - 1 + 2*i
			if 0 <= nextw and nextw < W:
				if field[now[1][0]][nextw] == '.':
					queue.append([now[0]+1, [now[1][0], nextw]])
if minfield[H-1][W-1] == 5000000000000000:
	print(-1)
else:
	print(countwhite-minfield[H-1][W-1])

Measured memory_bytes: 41328
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <cctype>
#include <sstream>
#include <algorithm>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define pr(a) cout << (a) << endl
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000000;

vector<P> D(int n) {
  vector<P> v;
  for(int i=1; i*i<=n; i++) {
    if(n%i==0) v.pb(P(i,n/i));
  }
  return v;
}
int main() {
  int n,m;
  while(cin >> n >> m && (n||m)) {
    vector<P> a=D(n),b=D(m);
    int ans=MAX;
    rep(i,a.size()) {
      rep(j,b.size()) {
	int d[4];
	d[0]=a[i].first;
	d[1]=a[i].second;
	d[2]=b[j].first;
	d[3]=b[j].second;
	sort(d,d+4);
	int sum=0;
	rep(k,3) {
	  sum+=(d[k+1]-d[k])*(d[k+1]-d[k]);
	}
	ans=min(ans,sum);
      }
    }
    pr(ans);
  }
  return 0;
}


Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(v) v.begin(), v.end()
using namespace std;

ll n,k,d,a;
set< ll > ans;

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> k;
    for(ll i=0; i<k; i++){
        cin >> d;
        for(ll j=0; j<d; j++) cin >> a , ans.insert( a );
    }

    cout << n-ans.size();

    return 0;
}


Measured memory_bytes: 3604
from collections import defaultdict

N = int(input())
P = map(int, input().split())

Kcost = [min(row, N - 1 - row, clm, N - 1 - clm) for row in range(N) for clm in range(N)]

Sitting = [1] * (N * N)
Kcount = 0


def Kcheck(qsn, cdsn):
    if Kcost[cdsn] > Kcost[qsn] + Sitting[qsn]:
        Kcost[cdsn] = Kcost[qsn] + Sitting[qsn]
        queue.append(cdsn)


for sn in P:
    csn = sn - 1
    Kcount += Kcost[csn]
    Sitting[csn] = 0
    queue = [csn]

    while queue:
        qsn = queue.pop()
        div, mod = divmod(qsn, N)
        if mod: Kcheck(qsn, qsn - 1)
        if mod != N - 1: Kcheck(qsn, qsn + 1)
        if div: Kcheck(qsn, qsn - N)
        if div != N - 1: Kcheck(qsn, qsn + N)

print(Kcount)


Measured memory_bytes: 137196
#include <iostream>
#include <vector>
#include <math.h>

using namespace std;

int main(){
  while(1){
    int d,w,h,n;
    vector<int> r;
    int a,b,c;
    int small;

    cin>>d>>w>>h>>n;

    if(d==0 && w==0 && h==0)
      break;
    
    r.resize(n);

    a=d*d+w*w;
    a=sqrt(a);
    b=w*w+h*h;
    b=sqrt(b);
    c=d*d+h*h;
    c=sqrt(c);
    
    for(int i=0;i<r.size();i++){
      cin>>r[i];
      if(r[i]*2>a || r[i]*2>b || r[i]>c)
        cout<<"OK"<<endl;
      else if(r[i]*2<=a && r[i]*2<=b && r[i]*2<=c)
        cout<<"NA"<<endl;
    }
  }
}



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

using namespace std;

using ll= long long;

#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _set(x) __builtin_popcount(x)

ll mod= (998244353);
ll bp(ll a,ll b){
  ll res=1;
  while(b){
    if(b&1){
      res = res*a%mod;
    }
    a = a*a%mod;
    b>>=1;
  }
  return res;
}

int32_t main(){
	IOS
	// freopen("input.txt","r",stdin);
	int _;
	// cin>>_;
	_=1;
	while(_--){
    ll n,m,k;
    cin>>n>>m>>k;
    ll ans=0;
    ll now =1;
    for(ll i=0;i<=k;i++){
      ans+= (m*(now)%mod)*(bp(m-1,n-1-i))%mod;
      now= (now*(n-1-i)%mod)*bp(i+1,mod-2)%mod;
      ans %= mod;
    }
    cout<<ans<<"\n";
  }
	return 0;
}

/*
   check for overflows int long long
   correct size of array
*/

Measured memory_bytes: 3584
while True:
    m,f,r = map(int, input().split())
    if m==f==r==-1:
        break
    if m ==-1 or f == -1:
        print("F")
    elif (m+f) >=80:
        print("A")
    elif (m+f) >=65:
        print("B")
    elif (m+f) >=50:
        print("C")
    elif( m+f)>=30 and r >=50:
        print("C")
    elif (m+f)>=30:
        print("D")
    else:
        print("F")


Measured memory_bytes: 5596
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
#define all(x) (x).begin(),(x).end()

int N;
vector<int> C, S, F;

//スタート駅を渡すとN番目の駅までの時間を返す
int func(int start){
  int time = 0;
  for(int i=start; i<N-1; i++){
    if(time <= S[i]) time = S[i];
    else{
      int x = time - S[i], a = x / F[i], b = x % F[i];
      if(b == 0) time = S[i] + F[i] * a;
      else time = S[i] + F[i] * (a + 1);
    }
    time += C[i];
  }
  return time;
}


int main() {
   cin >> N;
   C.resize(N); S.resize(N); F.resize(N);
   for(int i=0; i<N-1; i++){
     cin >> C[i] >> S[i] >> F[i]; 
   }

   for(int i=0; i <N; i++){
     cout << func(i) << ln;
   }
 }


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N = 0;
    int i=0,j=0;
    string S,X,Y;
    cin >> N;
    cin >> S;
    int ans = 0;
    int tmp = 0;
    int a = 'a';
    for(i=1;i<N;i++){
        tmp=0;
        for(j=0;j<26;j++){
            if(S.substr(0,i).find((char)a+j)!=string::npos && S.substr(i,N-i).find((char)a+j)!=string::npos) tmp++;
        }
        ans = max(tmp,ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long n,q,idx;
long long val,lazy[1000005],st_max[1000005],st_sum[1000005];
void update(long id,long l,long r,long i,long j,long long x){
	if(lazy[id]!=0){
		st_max[id]=lazy[id];
		st_sum[id]=(r-l+1)*lazy[id];
		if(l<r){
		    lazy[2*id]=lazy[id];
		    lazy[2*id+1]=lazy[id];
		}
		lazy[id]=0;
	}
	if(l>j||r<i||i>j){
		return;
	}
	if(l>=i&&r<=j){
		st_max[id]=x;
		st_sum[id]=(r-l+1)*x;
		if(l<r){
		    lazy[2*id]=x;
		    lazy[2*id+1]=x;
		}    
		return;
	}
	long mid=(l+r)/2;
	update(2*id,l,mid,i,j,x);
	update(2*id+1,mid+1,r,i,j,x);
	st_max[id]=max(st_max[2*id],st_max[2*id+1]);
	st_sum[id]=st_sum[2*id]+st_sum[2*id+1];
}
long long get_max(long id,long l,long r,long i,long j){
	if(lazy[id]!=0){
		st_max[id]=lazy[id];
		st_sum[id]=(r-l+1)*lazy[id];
		if(l<r){
		    lazy[2*id]=lazy[id];
		    lazy[2*id+1]=lazy[id];
		}
		lazy[id]=0;
	}
	if(l>j||r<i||i>j){
		return -1e18;
	}
	if(l>=i&&r<=j){
		return st_max[id];
	}
	long mid=(l+r)/2;
	return max(get_max(2*id,l,mid,i,j),get_max(2*id+1,mid+1,r,i,j));
}
long long get_sum(long id,long l,long r,long i,long j){
	if(lazy[id]!=0){
		st_max[id]=lazy[id];
		st_sum[id]=(r-l+1)*lazy[id];
		if(l<r){
		    lazy[2*id]=lazy[id];
		    lazy[2*id+1]=lazy[id];
		}
		lazy[id]=0;
	}
	if(l>j||r<i||i>j){
		return 0;
	}
	if(l>=i&&r<=j){
		return st_sum[id];
	}
	long mid=(l+r)/2;
	return get_sum(2*id,l,mid,i,j)+get_sum(2*id+1,mid+1,r,i,j);
}
long search(long l,long r,long i,long long val){
	while(l<r){
		long mid=(l+r)/2;
		if((get_max(1,1,n,mid,i)*(i-mid+1)-get_sum(1,1,n,mid,i))<=val){
			r=mid;
		}else{
			l=mid+1;
		}
	}
	return l;
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>n>>q;
	for(int vl=1;vl<=q;vl++){
		cin>>idx>>val;
		long pos=search(1,idx,idx,val);
		long long dm=get_max(1,1,n,pos,idx);
		long long dm3=idx-pos+1;
		val-=dm*dm3-get_sum(1,1,n,pos,idx);
		update(1,1,n,pos,idx,dm);
		long long dm1=val/dm3;
		long long dm2=val%dm3;
		update(1,1,n,pos,idx,dm+dm1);
		update(1,1,n,pos,pos+dm2-1,dm+dm1+1);
	}
	for(int i=1;i<=n;i++){
		cout<<get_max(1,1,n,i,i)<<endl;
	}
}


Measured memory_bytes: 13952
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let s: String = read(&mut stdin_lock, &mut buf, b' ');
    let t: String = read(&mut stdin_lock, &mut buf, b'\n');

    println!("{}{}", t, s);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  ll sum = 0;
  rep(i, n){
    int a, b;
    cin >> a >> b;
    sum += b - a + 1;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long account=0;
        long account2=0;
        
        for(int i=0;i<N;i++){
            account+=1;
            if(account%15==0){
                account2-=account;
            }else if(account%5==0){
                account2-=account;
            }else if(account%3==0){
                account2-=account;
            }
            account2+=account;
        }
        System.out.println(account2);
    }
}

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

#define LL long long
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<LL>
#define VVL vector<vector<LL>>
#define VVVL vector<vector<vector<LL>>>
#define VB vector<bool>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14

template<class T> T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> void print(T x) { std::cout << x << std::endl; }

const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy = { 0, -1, 0, 1 }, dx = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）

using namespace std;


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

    while (true) {
        int X, Y;
        cin >> X >> Y;
        if (X == 0 and Y == 0) { break; }

        VVI field(Y, VI(X, 0));
        FOR(y, 0, Y) {
            FOR(x, 0, X) {
                int c;
                cin >> c;
                field[y][x] = c;
            }
        }

        VVI dp(Y, VI(X, 0));
        FOR(x, 0, X) {
            dp[0][x] = (field[0][x] == 0 ? 1 : 0);
        }

        FOR(y, 0, Y - 1) {
            FOR(x, 0, X) {
                // 移動可能なマス
                if (field[y][x] == 0) {
                    if (0 <= x - 1 and field[y + 1][x - 1] == 0) {
                        dp[y + 1][x - 1] += dp[y][x];
                    }
                    if (field[y + 1][x] != 1) {
                        dp[y + 1][x] += dp[y][x];
                    }
                    if (x + 1 < X and field[y + 1][x + 1] == 0) {
                        dp[y + 1][x + 1] += dp[y][x];
                    }
                // ジャンプ台
                } else if (field[y][x] == 2) {
                    if (y + 2 >= Y) {
                        dp[Y -1][x] += dp[y][x];
                    }
                    else if (y + 2 < Y and field[y + 2][x] != 1) {
                        dp[y + 2][x] += dp[y][x];
                    }
                }
            }
        }
        print(SUM(dp[Y - 1]));
    }

    return 0;
}


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

int main()
{
    char c1, c2;
    cin >> c1 >> c2;
    if (c1 == c2)
    {
        cout << "=" << endl;
    }
    else if (c1 < c2)
    {
        cout << "<" << endl;
    }
    else
    {
        cout << ">" << endl;
    }
    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
char str[100100];
bool a[2010][2010];
int sum[2010][2010];
int cnt1[2010][2010],cnt2[2010][2010];
int zlt[2010][2010];
int main(){
	int n,m,q;
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",str+1);
		for(int j=1;j<=m;j++)
		{
			if(str[j]=='1')
				a[i][j]=1;
			else
				a[i][j]=0;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			zlt[i][j]=zlt[i-1][j]+zlt[i][j-1]-zlt[i-1][j-1];
			sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
			if(a[i][j])
			{
				sum[i][j]=sum[i][j]+a[i][j-1]+a[i-1][j];
				zlt[i][j]++;
			}
		}
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cnt2[i][j]=cnt2[i][j-1]+(a[i][j]==1&&a[i-1][j]==1);

	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cnt1[i][j]=cnt1[i-1][j]+(a[i][j]==1&&a[i][j-1]==1);
			
	int sx,sy,tx,ty;
	int ans,res;
	while(q--)
	{
		scanf("%d%d%d%d",&sx,&sy,&tx,&ty);
		ans=sum[tx][ty]-sum[sx-1][ty]-sum[tx][sy-1]+sum[sx-1][sy-1];
		ans=ans-(cnt2[sx][ty]-cnt2[sx][sy-1]);
		ans=ans-(cnt1[tx][sy]-cnt1[sx-1][sy]);
		res=zlt[tx][ty]-zlt[sx-1][ty]-zlt[tx][sy-1]+zlt[sx-1][sy-1];
		printf("%d\n",res-ans);
	}
	return 0;
}

Measured memory_bytes: 68864
N, X = map(int, input().split())
m = []
count = N

for i in range(N):
    m.append(int(input()))

sum = 0
for i in range(N):
    sum += m[i]

while True:
    if X >= (sum + min(m)):
        sum += min(m)
        count += 1
    else:
        break
print(count)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
constexpr int INF = 1e9+7, MX = 100005;
using T = tuple<int,int,int>;
int p[MX];
long long ans[MX], laz[MX];
vector<int> ch[MX];
T ts[MX];
int n, a, b, c;

int main(){
	scanf("%d", &n);
	rep(i,n-1){
		scanf("%d%d%d", &a, &b, &c);
		ts[i] = T{c,a-1,b-1};
	}
	sort(ts, ts+n-1, greater<T>());
	rep(i,n) ch[i].emplace_back(p[i] = i);
	rep(i,n-1){
		tie(c, a, b) = ts[i];
		a = p[a]; b = p[b];
		if(ch[a].size() < ch[b].size()) swap(a,b);
		long long sd = ch[a].size() - ch[b].size();
		for(int d: ch[b]){
			p[d] = a;
			ans[d] += laz[b] + sd * c - laz[a];
			ch[a].emplace_back(d);
		}
		laz[a] += (long long) ch[b].size() * c;
	}
	rep(i,n) printf("%lld\n", ans[i] + laz[p[0]]);
}

Measured memory_bytes: 13560
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
#define N 500002
const int p=1e9+7;
int n,k,m,a[N],ans,dp[27002][413],s[413],f[27002][413],sf[413];
int fac[N],finv[N],inv[N],cz[N];
bool vis[N];
inline int ksm(int d,int tk)
{int ret=1;while(tk){if(tk&1)ret=1ll*ret*d%p;d=1ll*d*d%p;tk>>=1;}return ret;}
int main()
{
	scanf("%d%d%d",&n,&k,&m);if(k>n){puts("0");return 0;}
	for(int i=1;i<=m;i++)scanf("%d",&a[i]);
	ans=1ll*(n-m+1)*ksm(k,n-m)%p;
	fac[0]=finv[0]=fac[1]=finv[1]=inv[1]=1;
	for(int i=2;i<=100000;i++)
	{
		inv[i]=1ll*(p-p/i)*inv[p%i]%p;
		fac[i]=1ll*fac[i-1]*i%p;finv[i]=1ll*finv[i-1]*inv[i]%p;
	}
	bool flag=true;
	for(int i=1;i<=m;i++)
	{
		if(vis[a[i]]){flag=false;}
		vis[a[i]]=1;
	}
	for(int i=1;i+k-1<=m;i++)
	{
		for(int j=1;j<=k;j++)vis[j]=0;
		for(int j=i;j<=i+k-1;j++)vis[a[j]]=1;
		bool tf=true;
		for(int j=1;j<=k;j++)if(!vis[j]){tf=false;break;}
		if(tf){printf("%d\n",ans);return 0;}
	}
	if(flag)
	{
		if(m==k){printf("%d\n",ans);return 0;}
		dp[0][0]=1;s[0]=1;
		for(int i=1;i<k;i++)s[i]=(s[i-1]+dp[0][i])%p;
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<k;j++)
			{
				dp[i][j]=1ll*dp[i-1][j-1]*(k-j+1)%p;
				dp[i][j]=(1ll*dp[i][j]+s[k-1]-s[j-1]+p)%p;
				f[i][j]=1ll*f[i-1][j-1]*(k-j+1)%p;
				f[i][j]=(1ll*f[i][j]+sf[k-1]-sf[j-1]+p)%p;
				if(j>=m)f[i][j]=(f[i][j]+dp[i][j])%p;
			}
			s[0]=0;
			for(int j=1;j<k;j++)s[j]=(s[j-1]+dp[i][j])%p;
			sf[0]=0;
			for(int j=1;j<k;j++)sf[j]=(sf[j-1]+f[i][j])%p;
		}
		int tt=0;
		for(int i=1;i<k;i++)tt=(tt+f[n][i])%p;
		tt=1ll*tt*finv[k]%p*fac[k-m]%p;
		printf("%d\n",(ans-tt+p)%p);return 0;
	}
	memset(vis,0,sizeof(vis));int frl;
	for(int i=1;i<=m;i++)
	{
		if(!vis[a[i]])vis[a[i]]=1;
		else {frl=i-1;break;}
	}
	dp[0][frl]=1;s[0]=dp[0][0];
	for(int i=1;i<k;i++)s[i]=(s[i-1]+dp[0][i])%p;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<k;j++)
		{
			dp[i][j]=1ll*dp[i-1][j-1]*(k-j+1)%p;
			dp[i][j]=(1ll*dp[i][j]+s[k-1]-s[j-1]+p)%p;
		}
		s[0]=dp[i][0];
		for(int j=1;j<k;j++)s[j]=(s[j-1]+dp[i][j])%p;
	}
	memset(vis,0,sizeof(vis));int lal;
	for(int i=m;i;i--)
	{
		if(!vis[a[i]])vis[a[i]]=1;
		else{lal=m-i;break;}
	}
	f[0][lal]=1;sf[0]=f[0][0];
	for(int i=1;i<k;i++)sf[i]=(sf[i-1]+f[0][i])%p;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<k;j++)
		{
			f[i][j]=1ll*f[i-1][j-1]*(k-j+1)%p;
			f[i][j]=(1ll*f[i][j]+sf[k-1]-sf[j-1]+p)%p;
		}
		sf[0]=f[i][0];
		for(int j=1;j<k;j++)sf[j]=(sf[j-1]+f[i][j])%p;
	}
	int ans2=0;
	for(int i=0;i<=n-m;i++)
	{
		int c1=0,c2=0;
		for(int j=0;j<k;j++)c1=(c1+dp[i][j])%p;
		for(int j=0;j<k;j++)c2=(c2+f[n-m-i][j])%p;
		ans2=(ans2+1ll*c1*c2%p)%p;
	}
	printf("%d\n",(ans-ans2+p)%p);
}
/*
5 3 2
3 1
*/

Measured memory_bytes: 85576
while 1:
    m,f,r = map(int,input().split())
    if m == -1 and f == -1 and r == -1:
        break

    if m == -1 or f == -1 or m + f < 30:
        print("F")
    elif 80 <= m + f :
        print("A")
    elif 65 <= m + f < 80:
        print("B")
    elif 50 <= m + f < 65:
        print("C")
    elif 30 <= m + f < 50:
        if r >= 50:
            print("C")
        else:
            print("D")

Measured memory_bytes: 7688
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int a = sc.nextInt();
            String op = sc.next();
            int b = sc.nextInt();

            switch (op) {
            case "+":
                System.out.println(a + b);
                break;
            case "-":
                System.out.println(a - b);
                break;
            case "*":
                System.out.println(a * b);
                break;
            case "/":
                System.out.println(a / b);
                break;
            case "?":
                break;
            default:
                throw new IllegalArgumentException();
            }
        }
        sc.close();
    }
}


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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(auto i=(a);i<(b);++i)
#define RFOR(i,a,b) for(auto i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;
typedef std::vector<PII> VPII;

int N;
VPII v;

const int MOD = 1e9 + 7;
int main() {
    std::cin >> N;
    v.reserve(2*N);
    REP(k, 2) {
        REP(i, N) {
            int x;
            std::cin >> x;
            v.emplace_back(std::make_pair(x, k));
        }
    }
    SORT(v);

    int cnt = 0;
    LL ans = 1;
    for(auto x: v) {
        if(x.snd == 1) {
            if(cnt > 0) {
                ans = ans * cnt % MOD;
            }
            --cnt;
        } else {
            if(cnt < 0) {
                ans = ans * (-cnt) % MOD;
            }
            ++cnt;
        }
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 1792