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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define FOR(i, n, m) for(ll i = (ll)n; i < (ll)(m); i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define PRINT(x) std::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; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dx[8] = {0,1,0,-1, 1, -1, 1, -1}, dy[8] = {1,0,-1,0,1,1,-1,-1};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) os << v[i] << " ";  
    return os; 
}

template <typename T1, typename T2> 
ostream& operator<<(ostream& os, const map<T1, T2>& m) 
{ 
    for (auto p : m) os << "<" << p.first << ", " << p.second << "> "; 
    return os; 
}



map<ll, ll> primeFactors(ll n)
{
    map<ll, ll> ret;
    while (n % 2 == 0) {
        ret[2]++;
        n = n / 2;
    }
    for (ll i = 3; i <= sqrt(n); i = i+2) {
        while (n%i == 0) {
            ret[i]++;
            n = n / i;
        }
    }
    if (n > 2) {
        ret[n]++;
    }
    return ret;
}

int main()
{
  ll A, B;
  cin >> A >> B;
  PRINT(A * B);
  return 0;
} 

Measured memory_bytes: 3720
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    
    string S, T;
    cin >> S >> T;
    
    int ans = 0;
    
    for(int i = 0; i < S.size(); i++){
        if(S[i] != T[i]) ans++;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 3456
import java.util.*;
public 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+c==17){
        	System.out.println("YES");
        } else {
        	System.out.println("NO");
        }
    }
}

Measured memory_bytes: 35580
#include <iostream>
using namespace	std;
int main(){

  long long k,s,a,l;
  cin>>k;
  s=k/50+50;
  l=k%50;
  a=s-l-1;
  cout<<"50"<<endl;
  for(int i=0;i<50;i++){
    if(i)cout<<" ";
    cout<<(i<l?s:a);
  }
  cout<<endl;
  return 0;

}







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

using namespace std;
using namespace std::chrono;

#define rep(i,a,b) for(int i = a;i<(b);++i)
#define trav(a,v) for(auto& a : v)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;

const ll big = 1000000007ll;
const ll big2 = 1000000009ll;
ll n,m,k,q,w,h,T;

ll DP[2001][2001][3] = {0};
bool DPC[2001][2001][3] = {0};

ll FAC[5000] = {0};
ll INV[5000] = {0};

ll CSA[2001][2001] = {0};
ll CSB[2001][2001] = {0};

ll mod(ll i){
    if(i<0)return mod(big-mod(-i));
    if(i<big)return i;
    return i%big;
}

ll upp(ll i, ll j){
    if(j == 0)return 1;
    if(j%2 == 0){
        ll h = upp(i,j/2);
        return mod(h*h);
    }
    return mod(i*upp(i,j-1));
}

ll bin(ll i, ll j){
    if(i < 0 || j < 0 || i < j)return 0;
    return mod(FAC[i]*mod(INV[j]*INV[i-j]));
}

void setup(){
    ll t = 1;
    for(ll c1 =0 ; c1 < 5000; c1++){
        FAC[c1] = t;
        INV[c1] = upp(t,big-2);
        t *= c1+1;
        t = mod(t);
    }

    for(ll c1 = 0; c1 < 2001; c1++){
        CSA[c1][0] = 1;
        for(ll c2 = 1; c2 < 2001; c2++){
            CSA[c1][c2] = mod(CSA[c1][c2-1] + bin(c1,c2));
        }
    }

    for(ll c1 = 0; c1 < 2001; c1++){
        CSB[c1][0] = 1;
        for(ll c2 = 1; c2 < 2001; c2++){
            CSB[c1][c2] = mod(CSB[c1][c2-1] + CSA[c1][c2]);
        }
    }

}

ll dp(ll a, ll b, ll era){
    if(a < 0 || b < 0)return 0;
    if(a*b*era == 0)return 1;
    if(era == 1)return CSB[b-1][a];
    if(DPC[a][b][era])return DP[a][b][era];
    ll ans = dp(a-1,b,era);
    for(ll c1 = 0; c1 < b; c1++){
        ans += bin(b-1,c1)*dp(a-c1,c1,1);
        ans = mod(ans);
    }
    DPC[a][b][era] = 1;
    DP[a][b][era] = ans;
    return ans;
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,d;

    setup();
    cin >> n >> m;
    cout << dp(n,m,2) << "\n";

    return 0;
}


Measured memory_bytes: 168320
import java.util.*;

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

        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0;i < n;i++){
            a[i] = sc.nextInt();
        }

        int q = sc.nextInt();
        for(int i = 0;i < q;i++){
            int b = sc.nextInt();
            int m = sc.nextInt();
            int e = sc.nextInt();
            int[] tmp = a.clone();

            for(int k = 0;k < e - b;k++){
                a[b + ((k + (e - m)) % (e - b))] = tmp[b + k];
            }
        }

        for(int i = 0;i < n;i++){
            if(i != 0)  System.out.print(" ");
            System.out.print(a[i]);
        }
        System.out.println();
    }
}


Measured memory_bytes: 42100
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int 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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> S(H, vector<char>(W));
    REP(i, H) {
        REP(j, W) { cin >> S[i][j]; }
    }
    REP(i, H) {
        REP(j, W) {
            if(S[i][j] == '.') {
                int cnt = 0;
                if(i - 1 >= 0) {
                    if(S[i - 1][j] == '#') {
                        cnt++;
                    }
                    if(j - 1 >= 0) {
                        if(S[i - 1][j - 1] == '#') {
                            cnt++;
                        }
                    }
                }
                if(i + 1 < H) {
                    if(S[i + 1][j] == '#') {
                        cnt++;
                    }
                    if(j + 1 < W) {
                        if(S[i + 1][j + 1] == '#') {
                            cnt++;
                        }
                    }
                }
                if(j - 1 >= 0) {
                    if(S[i][j - 1] == '#') {
                        cnt++;
                    }
                    if(i + 1 < H) {
                        if(S[i + 1][j - 1] == '#') {
                            cnt++;
                        }
                    }
                }
                if(j + 1 < W) {
                    if(S[i][j + 1] == '#') {
                        cnt++;
                    }
                    if(i - 1 >= 0) {
                        if(S[i - 1][j + 1] == '#') {
                            cnt++;
                        }
                    }
                }
                S[i][j] = '0' + cnt;
            }
        }
    }
    REP(i, H) {
        REP(j, W) { cout << S[i][j]; }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>
#include <cstdio>

int main() {
	long long a, b;

	std::cin >> a >> b;

	long long ans = (long long)((a + 1) / 2) * (long long)((b + 1) / 2) + a / 2 * (b / 2);
	
	if (a == 1 || b == 1) ans = 1;

	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
  
  public static void main(String args[])
  {

    Scanner sc=new Scanner(System.in);
    int k=sc.nextInt();
    int n=sc.nextInt();
    int m=sc.nextInt();
    int flag=0;
    for(int i=n;i<=m;i++)
    {
      if(i%k==0){
        flag=1;
        break;
      }
    }
    
    if(flag==1)
    {
        System.out.println("OK");
    }
    else
          System.out.println("NG");
  }
}
        
    
    
    
  
  

Measured memory_bytes: 27040
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };




signed main() {
	int n, m, h, w, k;
	vector<vector<int>>mat(1005, vector<int>(1005, 0));
	vector<string>slist;
	vector<int>list(1000,0);
	int num;
	string s;
	stack<int>st;


	//while (cin >> s) {
	if (std::getline(std::cin, s)) {
		std::istringstream ss(s);
		string s3;
		while (ss >> s3) {
			slist.push_back(s3);
		}
	}

	for(int i = 0; i<slist.size(); i++){
		if (slist[i] == "*") {
			int num1 = st.top();
			st.pop();
			int num2 = st.top();
			st.pop();
			st.push(num2*num1);
		}
		else if (slist[i] == "+") {
			int num1 = st.top();
			st.pop();
			int num2 = st.top();
			st.pop();
			st.push(num2+num1);
		}
		else if (slist[i] == "-") {
			int num1 = st.top();
			st.pop();
			int num2 = st.top();
			st.pop();
			st.push(num2-num1);
		}
		else {
			st.push(stoll(slist[i]));

		}



	}

	//cout << "aa" << endl;
	cout << st.top() << endl;



	return 0;
}


Measured memory_bytes: 10608
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
struct vode
{
	int wns;
	int id;
}a[1000005];
bool cmp(vode x,vode y)
{
	return x.wns<y.wns;
}
int main()
{
	int n;
	int ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i].wns);
		a[i].id=i;
	}
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=n;i++)
	{
		cout<<a[i].id<<" ";
	}
	cout<<endl;
	return 0;
} 

Measured memory_bytes: 1536
import java.util.Scanner;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) {
		Scanner a = new Scanner(System.in);
		int numbers[] = new int[3];
		for(int i =0; i < 3; i ++) {
			numbers[i] = a.nextInt();
		}
		Arrays.sort(numbers);
		int A = numbers[1] - numbers[0];
		int B = numbers[2] - numbers[1];
		int C = A + B ;
		String s = String.valueOf(C);
		System.out.println(s);
   }
}

Measured memory_bytes: 23380
/*
    Author: isaf27 (Ivan Safonov)
*/

#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

//defines
typedef long long ll;
typedef long double ld;
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define fastIO ios_base::sync_with_stdio(0)
#define nul point(0, 0)
#define str_to_int(stroka) atoi(stroka.c_str())
#define str_to_ll(stroka) atoll(stroka.c_str())
#define str_to_double(stroka) atof(stroka.c_str())
#define what_is(x) cerr << #x << " is " << x << endl
#define solve_system int number; cin >> number; for (int i = 0; i < number; i++) solve()
#define solve_system_scanf int number; scanf("%d", &number); for (int i = 0; i < number; i++) solve()

//permanent constants
const ld pi = 3.141592653589793238462643383279;
const ld log23 = 1.58496250072115618145373894394781;
const ld eps = 1e-8;
const ll INF = 1e18 + 239;
const ll prost = 239;
const int two = 2;
const int th = 3;
const ll MOD = 1e9 + 7;
const ll MOD2 = MOD * MOD;
const int BIG = 1e9 + 239;
const int alf = 26;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int dig = 10;
const string str_alf = "abcdefghijklmnopqrstuvwxyz";
const string str_alf_big = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int bt = 31;
const int fr = 4;

//easy functions
template< typename T >
inline T gcd(T a, T b) { return a ? gcd(b % a, a) : b; }
template< typename T >
inline T lcm(T a, T b) { return (a / gcd(a, b)) * b; }
inline bool is_down(char x) { return ('a' <= x && x <= 'z'); }
inline bool is_upper(char x) { return ('A' <= x && x <= 'Z'); }
inline bool is_digit(char x) { return ('0' <= x && x <= '9'); }
ll power(ll a, int k)
{
    if (k == 0) return 1;
    ll t = power(a, k >> 1);
    t = (t * t) % MOD;
    if (k & 1) t = (t * a) % MOD;
    return t;
}

//random
mt19937 rnd(239);

//constants
const int M = 2 * 1e5 + 239;
const int N = 2 * 1e3 + 239;
const int L = 20;
const int T = (1 << 20);
const int B = trunc(sqrt(M)) + 1;
const int X = 2010;

int main()
{
    #ifdef ONPC
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fastIO;
    int a, b;
    cin >> a >> b;
    if (a <= 0 && b >= 0)
    {
        cout << "Zero\n";
        return 0;
    }
    if (a > 0)
    {
        cout << "Positive\n";
        return 0;
    }
    if ((b - a) & 1)
    {
        cout << "Positive\n";
        return 0;
    }
    cout << "Negative\n";
    return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll ans = 0, b = 0;
  string s;
  cin >> s;
  int n = s.size();
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'B') ++b;
    else ans += b;
  }
  cout << ans << '\n';
}


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

using namespace std;

#define MAXN 3123

string str1, str2;
int vis[MAXN][MAXN];
int dp[MAXN][MAXN];
int dpr[MAXN][MAXN];

int LCS(int i1, int i2)
{
    if (i1 == str1.size() || i2 == str2.size())
        return 0;

    if(vis[i1][i2])
    {
        return dp[i1][i2];
    }
    vis[i1][i2] = 1;

    if (str1[i1] != str2[i2])
    {
        int cima = LCS(i1 + 1, i2);
        int baixo = LCS(i1, i2 + 1);

        if (cima > baixo)
        {
            dp[i1][i2] = cima;
            dpr[i1][i2] = 1;
        }
        else
        {
            dp[i1][i2] = baixo;
            dpr[i1][i2] = 2;
        }

        return dp[i1][i2];
    }
    else
    {
        dpr[i1][i2] = 3;
        return dp[i1][i2] = 1 + LCS(i1 + 1, i2 + 1);
    }
}

int main()
{
    cin >> str1 >> str2;
    int sz = LCS(0, 0);

    int i1 = 0, i2 = 0;
    string res;
    while (res.size() < sz)
    {
        if (dpr[i1][i2] == 3)
        {
            res.push_back(str1[i1]);
            ++i1;
            ++i2;
        }
        else if (dpr[i1][i2] == 1)
        {
            ++i1;
        }
        else
        {
            ++i2;
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 113280
def solve():
    S = input()
    N = len(S)
    ans = 0
    cnt = 0
    for i in range(N-1,-1,-1):
        if S[i] == 'B':
            ans += N - i - (1 + cnt)
            cnt += 1
    
    print(ans)

if __name__ == '__main__':
    solve()

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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 = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vpll xy(n);
  rep(i,n){
    ll x,y; cin>>x>>y;
    xy[i]={x,y};
  }
  vsort(xy);
  ll fact=1;
  reps(i,n) fact*=i;
  double sum=0;
  do{
    double tmp=0;
    ll px=xy[0].first, py=xy[0].second;
    irep(i,1,n){
      ll X=px-xy[i].first, Y=py-xy[i].second;
      tmp+=sqrt(X*X+Y*Y);
    }
    sum+=tmp;
  }while(next_permutation(all(xy)));
  coutd(sum/fact);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,d;
    while(cin>>a>>b>>c>>d)
        {
            int ans=0;
            for(int i=0; i<=100; i++)
                {
                    if((i>=a && i<=b)&&(i>=c&&i<=d))
                        ans++;
                }
            printf("%d\n",ans-1>=0?ans-1:0);
        }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdlib.h>
#include<math.h>

using namespace std;

int main(){
  int A, B;
  cin >> A >> B;
  if( A%3 == 0 || B%3 == 0 || (A+B)%3 == 0 ){
	cout << "Possible" << endl;
  }else{
	cout << "Impossible" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
// atcoder.cpp.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<stdio.h>
#include<string.h>
#include <math.h>
#include<stdlib.h>
#include<time.h>
#include<random>

using namespace std;
//std::random_device rnd;

//グロ変

int main()
{
    
    int h1, m1, h2, m2, k;
    int ans = 0;
    char enter[100];
    char* enpo;

/*    cin >> enter;
         h1= strtol(enter, &enpo, 10);
         m1= strtol(enpo, &enpo, 10);
         h2= strtol(enpo, &enpo, 10);
         m2= strtol(enpo, &enpo, 10);
         k= strtol(enpo, &enpo, 10);*/
    cin >> h1;
    cin >> m1;
    cin >> h2;
    cin >> m2;
    cin >> k;


         //cout << h1 << m1 << h2 << m2 << k;
    ans = (h2 * 60 + m2) - (h1 * 60 + m1) - k;
    cout << ans;


   
}




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

int main(){
  ll n,m,k,aa,bb,ans,f_ans,jj;
  cin>>n>>m>>k;
  vector<ll>a(n+1);
  vector<ll>b(m+1);
  f_ans = 0;
  bool answer = false;
  rep(i,n+1){
      
      if(i==0) a[i]=0;
      else {
          cin>>aa;
          a[i]=a[i-1]+aa;
          }
  }
  rep(i,m+1){
      if(i==0) b[i]=0;
      else{
      cin>>bb;
      b[i]=b[i-1]+bb; 
      }     
  }
  ll j = m;
  rep(i,n+1){
      if(k<a[i]) break;
      while (b[j]>k-a[i]) j--;
      f_ans = max(f_ans,i+j);
  }
  cout<<f_ans<<endl;
}

Measured memory_bytes: 6396
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ユニークなvectorにする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
   int N;
   cin >> N;
   vector<int> T;
   rep(i, N) {
       int Ti;
       cin >> Ti;
       T.pb(Ti);
   }

   int M;
   cin >> M;
   rep(i, M) {
       int p, x;
       cin >> p >> x;

       int sum = 0;
       rep (i, N) {
         if ((p - 1) == i) {
             sum += x;
         } else {
             sum += T[i];
         }
       }
       cout << sum << endl;
   }



}


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

using namespace std;

#define ll long long

#define inf 1e15

int main(){
	ll n;
	scanf("%lld",&n);
	vector<ll> arr(n);
	for(int i=0;i<n;i++)scanf("%lld",&arr[i]);
	
	vector<vector<ll> > dp(n+1,vector<ll>(n+1,inf));
	
	ll size[n][n];
	
	for(int i=0;i<n;i++){
		for(int j=i;j<n;j++){
			if(i==j)
				size[i][i]=arr[i];
			else
				size[i][j]=size[i][j-1]+arr[j];
		}
	}
	
	for(int l=n;l>=0;l--){
		for(int r=l;r<n;r++){
			if(l==r)
				dp[l][r]=arr[l];
			else{
				for(int i=l;i<r;i++){
					dp[l][r]=min(dp[l][r],size[l][i]+size[i+1][r]+dp[l][i]+dp[i+1][r]);
				}
			}
		}
	}
	printf("%lld",dp[0][n-1]-size[0][n-1]);
}


Measured memory_bytes: 2816
N = int(input())
S = []
for i in range(N):
  S.append(input())

M = int(input())
T = []
for i in range(M):
  T.append(input())

X = {}
for s in S:
  if s in X:
    X[s] += 1
  else:
    X[s] = 1

for t in T:
  if t in X:
    X[t] -= 1

print(max(max(X.values()),0))


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

int main() {
	int s;
	cin >> s;
	int	h = s / 3600;
	int m = (s % 3600) / 60;
	s = s % 60;
	//int m = s /60- h * 60;
	//	s = s- m * 60 -h * 3600
		
	
	cout <<h <<":" <<m <<":"<<s<< endl;
	
	return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
const unsigned long long h = 1e9+7;
typedef pair<ll,ll> P;
const ll MAX = 100010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int ta,ao;
    if (c%b) ta = c/b+1;
    else ta = c/b;
    if (a%d) ao = a/d+1;
    else ao = a/d;
    Yes(ta <= ao);
}    


Measured memory_bytes: 3640
//MM
#include<iostream>
using namespace std;

int main()
{
	int n, m, l;
	int a[100][100], b[100][100];
	long c[100][100];
	cin >> n >> m >> l;
	for(int i = 0; i < 100; i++)
		for(int j = 0; j < 100; j++){
			c[i][j] = 0;
			a[i][j] = 0;
			b[i][j] = 0;
		}
	
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			cin >> a[i][j];
	
	for(int i = 0; i < m; i++)
		for(int j = 0; j < l; j++)
			cin >> b[i][j];
	
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			for(int k = 0; k < l; k++)
				c[i][k] += a[i][j]*b[j][k];
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < l-1; j++)
			cout << c[i][j] << " ";
	cout << c[i][l-1] << endl;
	}
			
	return 0;
}


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

#define all(x) (x).begin(),(x).end()

#define MOD 1000000007

using namespace std;

int main(){
	long long int a, b, n;	cin >> a >> b >> n;
	int ans = 0;

	if( b == 1 )	ans = 0;
	else if( b > n )	ans = floor( (a * n) / b );
	else	ans = floor( (a * (b - 1) / b) );

	cout << ans << endl;

	return 0;
}


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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    int l, f;
    l = n % 10;
    f = n / 100;
    if (l == f) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


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

int main() {
    int n;

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

    sort(v.begin(), v.end());
    cout << v[(n/2)] - v[(n/2)-1] << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    ll N,A,B;
    cin >> N >> A >> B;

    ll X = A*(N/(A+B));
    if(A<N%(A+B)){
        X += A;
    }else{
        X += N%(A+B);
    }
    cout <<X<<endl;

    return 0;    
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stdio.h>
#include<cmath>
#include<string.h>

using namespace std;

int main(void)
{
	char a, b;
	cin >> a >> b;
	if ((int)a < (int)b)
	{
		cout << '<' << endl;
	}
	else if ((int)a == (int)b)
	{
		cout << '=' << endl;
	}
	else if ((int)a > (int)b)
	{
		cout << '>' << endl;
	}
	return 0;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

vector<pair<int,int>> G[SIZE];
int dist[SIZE];

void dfs(int now, int back = -1, int d = 0) {
  dist[now] = d;

  for (auto p : G[now]) {
    if (p.first == back) continue;
    dfs(p.first, now, d + p.second);
  }
}

int main() {
  int N;

  scanf("%d", &N);

  for (int i=0; i<N-1; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    u--; v--; w &= 1;
    G[u].push_back({v, w});
    G[v].push_back({u, w});
  }

  dfs(0);

  for (int i=0; i<N; i++) {
    printf("%d\n", dist[i] & 1);
  }

  return 0;
}


Measured memory_bytes: 10752
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        long ans = 0;
        int n = sc.nextInt();
        long [] a = new long[n];
        for (int i = 0; i < n; i++) a[i] = sc.nextInt();
        long cur = 0;
        for (int i = 0; i < n; i++) {
            if (cur > a[i]) {
                ans += (cur - a[i]);
            }
            cur = Math.max(cur, a[i]);
        }
        out.println(ans);
        out.close();
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

Measured memory_bytes: 55716
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];

int main(){
  int N;
  cin >> N ;
  vector <string> W(N) ;
  cinf(N,W) ;
  bool A = false ;
  for(int i=0;i<N-1;i++){
    if(W[i].back() != W[i+1].front())
      A = true ;
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(W[i] == W[j] && i != j)
        A =true ;
    }
  }
  if(A)
    cout <<"No" << endl;
  else
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#define int long long
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> P;
const int mod=1000000007;


int mpow(int a,int x);
int m_inv(int n){return mpow(n,mod-2);}

int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}

signed main(){
    int N;cin>>N;
    if(N%10==9||N/10==9) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

int mpow(int a,int x){
	int ans=1;
	while(x>0){
		if(x%2==1) (ans*=a)%=mod;
		(a*=a)%=mod;
		x>>=1;
	}
	return ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lson(x) (x<<1)
#define rson(x) ((x<<1)|1)
using namespace std;

typedef long long ll;
typedef vector<int> vii;

const int maxn=200003;
const int inf=0x3f3f3f3f;

int n,k,b[maxn];
ll pre[maxn],a[maxn],res,sum[maxn<<2];

void update(int id,int l,int r,int pos){
	++sum[id];
	if(l==r) return ;
	int mid=(l+r)/2;
	if(mid>=pos) update(lson(id),l,mid,pos);
	else update(rson(id),mid+1,r,pos);
}

ll query(int id,int l,int r,int L,int R){
	if(l>=L&&r<=R) return sum[id];
	if(l>R||L>r) return 0;
	int mid=(l+r)/2;
	return query(lson(id),l,mid,L,R)
		  +query(rson(id),mid+1,r,L,R);
}

int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i){
		scanf("%lld",&pre[i]);
		pre[i]-=k;
		pre[i]+=pre[i-1];
		a[i]=pre[i];
		if(a[i]>=0) ++res;
	}
	sort(a+1,a+n+1);
	int U=unique(a+1,a+n+1)-a-1;
	for(int i=1;i<=n;++i)
		b[i]=lower_bound(a+1,a+U+1,pre[i])-a;
	for(int i=1;i<=n;++i){
		res+=query(1,1,n,1,b[i]);
		update(1,1,n,b[i]);
	}
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 10368
import sys
n=int(input())
c=list(map(int,input().split()))
mod=10**9+7
if n==1:
  print(c[0]*2%mod)
  sys.exit()
c.sort()
c.reverse()
ans=0
x=pow(2,n-2,mod)
for i in range(n):
  ans+=c[i]*(i+2)*x
  ans%=mod
ans*=pow(2,n,mod)
ans%=mod
print(ans)

Measured memory_bytes: 87500
#include<stdio.h>

int main(void)
{
  unsigned long long int a,b,x;
  scanf("%lld%lld%lld",&a,&b,&x);

  if(a==0){
    printf("%lld",b/x+1);
    return 0;
  }else{
    a = (a-1)/x;
  }
  b = b/x;
  
  printf("%lld",b-a);

  


  return 0;
}


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

int main(){
  int N;
  std::cin >> N;
  int min = 1000000;
  for(int i = 0; i < N; i++){
    int c;
    std::cin >> c;
    int cnt = 0;
    for(;;){
      if(c%2==0){
        c /= 2;
        cnt++;
      }else{
        break;
      }
    }
    if(min > cnt)min = cnt;
  }
  std::cout << min << std::endl;
  return 0;
}

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

using namespace std;

typedef long long ll;

const ll INF = 1LL << 60;


int main(){
ll N,K; cin >> N >> K;
  vector<pair<ll,ll>> AB(N);
  vector<ll> C(N);
  for(int i = 0; i < N; i++){ cin >> AB[i].first >> AB[i].second;}

  sort(AB.begin(),AB.end()); C[0] = AB[0].second;
  for(int i = 1; i < N; i++){
    C[i] = C[i - 1] + AB[i].second;}

  int j = lower_bound(C.begin(),C.end(), K) - C.begin();

 cout << AB[j].first << endl; return 0;}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define upperlimit 1000100
#define INF 1000000100
#define INFL 1000000000000000100
#define eps 1e-8
#define endl '\n'
#define sd(n) scanf("%d",&n)
#define slld(n) scanf("%lld",&n)
#define pd(n) printf("%d",n)
#define plld(n) printf("%lld",n)
#define pds(n) printf("%d ",n)
#define pllds(n) printf("%lld ",n)
#define pdn(n) printf("%d\n",n)
#define plldn(n) printf("%lld\n",n)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define pb push_back
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define F first
#define S second
#define clr(a) memset(a,0,sizeof(a))
using namespace std;

ll gcd(ll n1,ll n2){
    if(!n1)return n2;
    if(!n2)return n1;
    if(n1%n2==0)return n2;
    return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent){
    base%=mod;
    ll ans=1;
    while(exponent){
        if(exponent&1)ans=(ans*base)%mod;
        base=(base*base)%mod;
        exponent/=2;
    }
    ans%=mod;
    return ans;
}
int main()
{
    int n;
    sd(n);
    if((n/100)==(n%10))cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
using static System.Math;
using System;

public class hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < n; i++)
        {
            var s1 = Console.ReadLine().Trim();
            var s2 = Console.ReadLine().Trim();
            var ans = goDP(s1, s2);
            Console.WriteLine(ans);
        }
    }
    static int goDP(string s1, string s2)
    {
        var s1L = s1.Length;
        var s2L = s2.Length;
        var dp = new int[s1L + 1, s2L + 1];
        for (int i = 0; i < s1L; i++)
            for (int j = 0; j < s2L; j++)
                if (s1[i] == s2[j]) dp[i + 1, j + 1] = dp[i, j] + 1;
                else dp[i + 1, j + 1] = Max(dp[i, j + 1], dp[i + 1, j]);
        return dp[s1L, s2L];
    }
}




Measured memory_bytes: 35024
#include<iostream>

int calc(int a, int b){

	if (b == 0)return a;

	return calc(b, a%b);

}

long long calc3(int a, int b){

	long long c = calc(a, b);
	
	return c*a / c*b / c;

}

int calc2(int a, int b){

	int c = 1, d = 0;

	do{
		c = a*c % b;
		d++;
	} while (c != 1);

	return d;
}

int main(){
	int a1, m1, a2, m2, a3, m3;

	while (std::cin >> a1 >> m1 >> a2 >> m2 >> a3 >> m3, a1, m1, a2, m2, a3, m3){

		int ca, cb, cc;

		ca = calc2(a1, m1);

		cb = calc2(a2, m2);

		cc = calc2(a3, m3);

		std::cout << calc3(calc3(ca, cb), calc3(ca, cc)) << std::endl;
	}

	return 0;
}

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

int main(){
  int n, m;
  cin >> n >> m;
  int c[m];
  rep(i,m) cin >> c[i];
  vector<int> dp(n+1,INF);
  dp[0] = 0;
  rep(i,m) {
    rep(j,n+1) {
      if(j-c[i] >= 0) dp[j] = min(dp[j],dp[j-c[i]]+1);
    }
  }
  cout << dp[n] << endl;
  return 0;
}


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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

int main() {
    int N; cin >> N;
    vector<int> a(N), b(N);
    rep(i, N) cin >> a[i];
    rep(i, N) cin >> b[i];
    ll A = 0, B = 0;
    rep(i, N) {
        A += a[i];
        B += b[i];
    }
    if (A < B) {
        cout << -1 << endl;
        return 0;
    }
    ll fusoku = 0;
    int ans = 0;
    rep(i, N) if (a[i] < b[i]) {
        fusoku += b[i] - a[i];
        ans++;
    }
    priority_queue<int> pq;
    rep(i, N) if (a[i] > b[i]) pq.push(a[i] - b[i]);
    while (fusoku > 0) {
        int x = pq.top(); pq.pop();
        fusoku -= x;
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1408
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)

a, b = 0, 0
idx = 0
while idx < len(A) - 1:
    if A[idx] == A[idx + 1]:
        if a == 0:
            a = A[idx]
            idx += 1
        else:
            b = A[idx]
            break

    idx += 1

print(a * b)


Measured memory_bytes: 14608
#include<stdio.h>

int main(){
  int h1,m1,h2,m2,k,time1,time2;
  scanf("%d%d%d%d%d",&h1,&m1,&h2,&m2,&k);
  
  time1=60*h1+m1;
  time2=60*h2+m2;
  
  printf("%d",time2-time1-k);
  return 0;
}

Measured memory_bytes: 1736
import sys
from math import gcd
from fractions import Fraction
mod = 1000000007

def solve():
    input = sys.stdin.readline
    N = int(input())
    F = [[int(i) for i in input().split()] for _ in range(N)]
    D = dict()
    zero, inf, ng = 0, 0, 0
    for x, y in F:
        if x == 0 and y == 0: ng += 1
        elif x == 0: inf += 1
        elif y == 0: zero += 1
        else: 
            g = gcd(abs(x), abs(y))
            if x < 0:
                y *= -1
                x *= -1
            x //= g
            y //= g
            tan = (y, x)
            if tan in D: D[tan] += 1
            else: D[tan] = 1

    ans = 1
    ans *= (pow(2, zero, mod) + pow(2, inf, mod) - 1) % mod
    ans %= mod
    used = set()
    for key in D:
        if key not in used:
            this = D[key]
            used |= {key}
            y, x = key
            rev = ((-x, y) if y > 0 else (x, -y))
            op = (0 if rev not in D else D[rev])
            used |= {rev}
            select = (pow(2, this, mod) + pow(2, op, mod) - 1) % mod
            ans *= select
            ans %= mod
    ans += ng
    ans %= mod
    ans = (ans - 1 + mod) % mod
    #print(D)
    print(ans)
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 176408
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    int n,m;
    cin>>n;
    vint h(n+1, 0);
    rep(i, n)cin>>h[i];
    int cou = 0;
    while(1){
        bool f = false;
        int first = 0;
        rep(i, n+1){
            if(h[i]==0&&f){
                cou++;
                f = false;
                first++;
            }
            if(h[i]>0){
                h[i]--;
                f = true;
            }
        }
        if(first == 0){
            break;
        }
    }
    cout << cou << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cmath>
using namespace std;
int n, d, x[15][15], cnt=0, xy=1;
int main()
{
	cin>>n>>d;
	for(int i=1; i<=n; i++)
		for(int j=1; j<=d; j++)
			cin>>x[i][j];
	for(int i=1; i<=n; i++)	
		for(int j=n; j>i; j--)
		{
			int dis=0;
			for(int k=1; k<=d; k++)
			{
				dis+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
			}
			int a=int(sqrt(dis));
			if(a*a==dis)
				cnt++;
		}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    n, m = map(int, input().split())
    num_list = list(map(int, input().split()))

    sum_count = 0
    for i in range(m):
        sum_count += num_list[i]

    print(n-sum_count if n >= sum_count else -1)

if __name__ == '__main__':
    main()

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

typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

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

const ll INF = 1e18;
const ll MOD = 998244353;
const ll MX = 80;

int H, W;
ll a[MX][MX], b[MX][MX], c[MX][MX];
bool dp[MX][MX][30000];

// Directions
int dy[2] = {0, 1}, dx[2] = {1, 0};

void solve() {
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> a[i][j];
		}
	}
	
    for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> b[i][j];
		}
	}
	
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			for (int k = 0; k < 30000; k++) {
				dp[i][j][k] = false;
			}
		}
	}
	
	dp[0][0][15000 + a[0][0] - b[0][0]] = true;
	dp[0][0][15000 + b[0][0] - a[0][0]] = true;
	
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			for (int k = 0; k < 30000; k++) {
				if (!dp[i][j][k]) continue;
				if (i < H - 1) {
					dp[i + 1][j][k + a[i + 1][j] - b[i + 1][j]] = true;
					dp[i + 1][j][k + b[i + 1][j] - a[i + 1][j]] = true;
				}
				if (j < W - 1) {
					dp[i][j + 1][k + a[i][j + 1] - b[i][j + 1]] = true;
					dp[i][j + 1][k + b[i][j + 1] - a[i][j + 1]] = true;
				}
			}
		}
	}
	
	int ans = 100000;
	for (int i = 0; i < 30000; i++) {
		if (dp[H - 1][W - 1][i]) {
			// cout << abs(15000 - i) << "\n";
			chmin(ans, abs(15000 - i));
		}
	}
	cout << ans;
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    ll testCases = 1; // cin >> testCases;
    while (testCases--) solve();
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 187904
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  //input
  int N, M, C;
  cin >> N >> M >> C;
  vector <int> B(M);
  vector< vector<int> > A (N, vector<int>(M) );
  rep(i,M) cin >> B[i];
  rep(i,N){
    rep(j,M){
      cin >> A[i][j];
    }
  }

 //solve
 int ans = 0;  //正答するソースコードの個数
 rep(i,N){
   int sum = 0;  //正答のための条件となる不等式の左辺 - C
   rep(j,M){
     sum += A[i][j] * B[j];
   }
   if (sum > - C) ans ++;
 }

 //output
 cout << ans << endl;

}


Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
//#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
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 a, b, c;
int main(void) {
    cin >> a >> b >> c;
    (a <= c && c <= b ? cout << "Yes" << endl : cout << "No" << endl);
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
bool p[100001];
int main()
{
	int n,a,b;
	unsigned long long s=0;
	cin>>n;
	for(int i=1;i<=n;++i)
	{
		cin>>a>>b;
		for(int j=a;j<=b;++j)
			p[j]=true;
	}
	for(int i=0;i<=100001;++i)
		if(p[i]==1)
			++s;
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int fr[100005];
long kq[100005];
long n;

int main()
{
	long q, l, r, res;

	fr[1] = 1;
	for (long i = 2; i < 100001; ++i)
		if (!fr[i])
		{
			for (long j = i + i; j < 100001; j += i)
				fr[j] = 1;
		}

	kq[1] = 0;
	for (long i = 3; i < 100000; i += 2)
		if (!fr[i] && !fr[(i + 1) / 2])
			kq[i] = kq[i - 2] + 1;
		else
			kq[i] = kq[i - 2];

	cin >> q;

	while (q)
	{
		cin >> l >> r;

		--q;
		if (l == 1)
			res = kq[r] - kq[l];
		else
			res = kq[r] - kq[l - 2];

		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 1792