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

using namespace std;


#define ll long long int


#define repab(i,a,b) for(int i=(a);i<=(b);i++)
#define reprab(i,a,b) for(int i=(a);i>=(b);i--)
#define repll(i,a,b) for(ll i=(a);i<=(b);i++)
#define rep(i,n) for(int i=(0);i<(n);i++)
#define repr(i,n) for(int i=(n);i>=0;i--)


ll max(ll a,ll b)
{
    if(a>b)return a;return b;
}
ll min(ll a,ll b)
{
    if(a<b)return a;return b;
}

//..............................!!!!!!Get ready to fight!!!!!!............................
ll solve(ll val[],ll wt[],ll n,ll w){
    ll dp[n+1][w+1];
    memset(dp,0,sizeof(dp));
    ll i,j;
    for(i=1;i<n+1;i++){
        for(j=1;j<w+1;j++){
            if(j>=wt[i-1])
            dp[i][j]=max(val[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j]);
            else
            dp[i][j]=dp[i-1][j];
        }
    }
    return dp[n][w];
}

int main()
{   
    
    ll n,w;
    cin>>n>>w;
    ll wt[n],val[n];
    rep(i,n){
        cin>>wt[i]>>val[i];
    }
    cout<<solve(val,wt,n,w);
    
    return 0;
}

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

int main() {

	long long n, m;
	scanf("%lld %lld", &n, &m);
	if(n == 1 || m == 1) {
		printf("%d", 1);
	}else {
		printf("%lld\n", (n * m + 1) / 2);
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <time.h>
#include <chrono>
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(ll i=a;i>b;i--)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,l,r) for(int i=(1);i<(r);i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = (1LL << 31) - 1;
const ll mod = 1e9 + 7;

ll K;


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


	ll cur = 7;

	cin >> K;
	FOR(i, 1, K + 1) {
		if (cur%K == 0) {
			cout << i << endl;
			break;
		}
		cur = cur * 10 + 7;
		cur %= K;

		if (i == K)cout << -1 << endl;
	}


	return 0;
}

Measured memory_bytes: 3644
N = int( input() )
A = list( map( int, input().split() ) )
B = list( map( int, input().split() ) )
C = list( map( int, input().split() ) )
sum = 0
A.append(-1)
for i in range(N):
    sum += B[A[i] - 1]
    if A[i + 1] == A[i] + 1:
        sum += C[A[i] - 1]
print(sum)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>/*toupperとかが入っている*/
#include<vector>/*可変長配列vectorのインクルード*/
 
const int MOD=1000000007;/* 1,000,000,007 で割った余りを出力する　のとき使う*/
using namespace std;/*標準名前空間を利用する。cinやcoutはこれによって利用可能になる*/

int N, X, Y;
int A[2005][2005];
int B[2005][2005];
int C[2005][2005];
int L[2005];

int main(void) {
  cin >> N >> X >> Y;

  /*距離の初期化*/
  for(int i=0; i<N-1; i++){
    for(int j=i+1; j<N; j++){
      A[i][j] = j-i;
    }
  }
  
  X=X-1;
  Y=Y-1;
  
  /*追加した辺を使う距離1*/  
  for(int i=0; i<N-1; i++){
    for(int j=i+1; j<N; j++){
      B[i][j] = abs(Y-i)+1+abs(X-j);
    }
  }
  
  /*追加した辺を使う距離2*/  
  for(int i=0; i<N-1; i++){
    for(int j=i+1; j<N; j++){
      C[i][j] = abs(X-i)+1+abs(Y-j);
    }
  }  
  
  /*距離の修正*/  
  for(int i=0; i<N-1; i++){
    for(int j=i+1; j<N; j++){
      if(A[i][j] > B[i][j]) A[i][j] = B[i][j];
      if(A[i][j] > C[i][j]) A[i][j] = C[i][j];
    }
  }    
  
  /*距離の出力*/  
  for(int i=0; i<N-1; i++){
    for(int j=i+1; j<N; j++){
      L[A[i][j]]++;
    }
  }
  for(int i=1; i<N; i++) cout << L[i] << endl;
  
  return 0;
}

Measured memory_bytes: 47360
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

int main() {
	int n;
	cin >> n;
	int G[100][100];
	for (int i = 0; i < 100; ++i)
		fill_n(G[i], 100, 0);
	int u, k, v;
	for (int i = 0; i < n; ++i) {
		cin >> u >> k;
		for (int j = 0; j < k; ++j) {
			cin >> v;
			G[i][v-1] = 1;
		}
	}
	for (int i = 0; i < n; ++i) {
		int ifs = 0;
		for (int j = 0; j < n; ++j) {
			if (ifs == 1)
				cout << " ";
			cout << G[i][j];
			ifs = 1;
		}
		cout << endl;
	}

	return 0;
}

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

#define MOD 1000000007

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


template <class T>
ostream &operator<<(ostream &o, const vector<T>&obj) {
    o << "["; for (int i = 0; i < (int)obj.size(); ++i) o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const vector<vector<T>>&obj) {
    o << "[" << endl; for (int i = 0; i < (int)obj.size(); ++i) o << "  " << obj[i] << endl; o << "]"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U>&obj) {
    o << "(" << obj.first << ", " << obj.second << ")"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const set<T>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const multiset<T>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const queue<T>&obj) {
    queue<T> obj_cp = obj;
    bool first = true;
    o << "{";
    while (!obj_cp.empty()) { o << (!first ? ", " : "") << obj_cp.front(); obj_cp.pop(); first = false; }
    o << "}"; return o;
}

void print() {
    cout << "\n";
}
template<class Head, class... Body>
void print(Head head, Body... body) {
    cout << head << " ";
    print(body...);
}


ll count(map<int, int> facts) {
    ll ret = 1;
    for (auto x : facts) {
        ret *= x.second + 1;
    }
    return ret;
}

ll N;
vector<ll> primes;

void set_primes() {
    vector<bool> is_prime(N+1, true);
    is_prime[2] = true;
    for (int i = 2; i * i <= N; ++i) {
        if (!is_prime[i]) continue;
        for (int j = 2; i*j <= N; ++j) {
            is_prime[i*j] = false;
        }
    }
    for (int i = 2; i <= N; ++i) {
        if (is_prime[i]) {
            primes.push_back(i);
        }
    }
}

ll dfs(ll n, map<int, int> state, int p_idx) {
    ll ret = n * count(state);
    // print(n, state, count(state), ret);
    for (int i = p_idx; i < primes.size(); i++) {
        ll p = primes[i];
        if (n * p <= N) {
            map<int, int> s = state;
            if (s.count(p) > 0) {
                s[p] += 1;
            } else {
                s[p] = 1;
            }
            ret += dfs(n*p, s, i);
        } else if (n * p > N) {
            break;
        }
    }
    return ret;
}


int main(int argc, char const *argv[]) {
    cin >> N;

    set_primes();
    map<int, int> state;
    ll ans = dfs(1, state, 0);
    print(ans);
    
    return 0;
}


Measured memory_bytes: 12856
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstdlib>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

using namespace std;

typedef long long int ll;

const ll INF=(ll)1e18;
int H,W;

int main(){
  cin >> H >> W;
  vector<vector<int> > s1(H);
  vector<vector<int> > s2(W);

  REP(i,W)s2[i].push_back(0);

  REP(i,H){
    string str;
    cin >> str;
    s1[i].push_back(0);
    REP(j,str.size()){
      if(str[j] == '#'){
        s1[i].push_back(j+1);
        s2[j].push_back(i+1);
      }
    }
    s1[i].push_back(W+1);
  }

  REP(i,W)s2[i].push_back(H+1);


  vector<vector<int> > t;
  t = vector<vector<int> >(H, vector<int>(W, 0));

  FOR(i,1,H+1){
    int k=0;
    FOR(j,1,W+1){
      if(s1[i-1][k+1]==j){
        k+=1;
        continue;
      }else{
        t[i-1][j-1] = (s1[i-1][k+1] - j) + (j - s1[i-1][k]) - 1;
      }
    
    }
  }

  FOR(i,1,W+1){
    int k=0;
    FOR(j,1,H+1){
      if(s2[i-1][k+1]==j){
        k+=1;
        continue;
      }else{
        
        t[j-1][i-1] += (s2[i-1][k+1] - j) + (j - s2[i-1][k]) - 1;
      }
      
    }
  }

  int ans=0;
  REP(i,H){
    REP(j,W){
      ans = max(ans,t[i][j]);
    }
  }

  cout << ans - 1 << endl;

}

Measured memory_bytes: 50176
MOD = 10**9+7

def mat_dot(one, two, mod):
	return [[sum([(one[i][k]*two[k][j])%mod for k in range(max(len(two), len(one[0])))])%mod for j in range(len(two[0]))] for i in range(len(one))]

def mat_pow(mat, exp, mod):
	size = len(mat)
	res = [[0 for _ in range(size)] for _ in range(size)]
	for i in range(size):
		res[i][i] = 1
	cnt = 0
	while (1<<cnt) <= exp:
		if (exp>>cnt)&1:
			res = mat_dot(res, mat, mod)
		mat = mat_dot(mat, mat, mod)
		cnt += 1
	return res

n, k = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = mat_pow(a, k, MOD)
print(sum([sum(x) for x in b]) % MOD)

Measured memory_bytes: 46684
#include<iostream>

using namespace std;

int main(){
 int x,y;
  cin>>x>>y;
  for(int turtle=0;turtle<=x;turtle++){
   int sturu = x - turtle;
    if(turtle*4 + sturu*2 == y){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <complex>
#include <cassert>
#include <random>
#include <cstring>
#include <numeric>
#define ll long long
#define ld long double
#define null NULL
#define all(a) a.begin(), a.end()
#define forn(i, n) for (int i = 0; i < n; ++i)
#define sz(a) (int)a.size()
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
template<class T> int gmax(T &a, T b) { if (b > a) { a = b; return 1; } return 0; }
template<class T> int gmin(T &a, T b) { if (b < a) { a = b; return 1; } return 0; }
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
    int a, b;
    while(~scanf("%d %d", &a, &b)) {
        printf("%d\n", max(max(a + b, a - b), a * b) );
    }
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)

N,Q=map(int,input().split())
par=[i for i in range(N+1)]
def find(x):
    if par[x] ==x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
def same(x,y):
    return find(x) == find(y)
def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    par[x]=y
for i in range(Q):
    a,b=map(int,input().split())
    unite(a,b)
ans=dict()
for i in par:
    tmp=find(i)
    if tmp in ans:
        ans[tmp]+=1
    else:
        ans[tmp]=1
print(max(ans.values()))

Measured memory_bytes: 174276
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int s;
    cin >> s;
    vector<int> f;
    int temp;

    temp = s;
    f.push_back(temp);

    for (int i = 2; i < 200; i++)
    {

        // s is even
        if (temp % 2 == 0)
        {
            temp = temp / 2;
        }

        // s is odd
        else if (temp % 2 == 1)
        {
            temp = 3 * temp + 1;
        }

        // cout << "a" << i << "=" << temp << endl;

        if (std::find(f.begin(), f.end(), temp) != f.end())
        {
            cout << i;
            break;
        }
        else
            f.push_back(temp);
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1000000007;

string s1,s2,s3;
int a,b;
int main()
{
    ios::sync_with_stdio(false);
    cin>>s1;
    for(int i=0;i<s1.size();i++)
        cout<<"x";
    return 0;
}


Measured memory_bytes: 256
# -*- coding:utf-8 -*-
class BellmanFord():
    """ベルマンフォード法で最短経路を求める"""
    def __init__(self, s, V):
        """
        Args:
            s(int): 始点
            V(int): 頂点数
        """
        self.graph = {}
        for i in range(V):
            self.graph[i] = []
        self._V = V
        self.dst = [float("inf") for _ in range(V)]
        self.dst[s] = 0

    @property
    def dist(self):
        return self.dst

    @property
    def V(self):
        return self._V

    def add(self, a, b, cost):
        """頂点aから頂点bへのコストはcost"""
        self.graph[a].append((b, cost))

    def shortest_path(self):
        """始点sからの最短経路を求める
        Returns:
            (bool): 負の閉路が存在する(True) / 存在しない(False)
        """
        for t in range(self.V):
            update = False
            for u in range(self.V):
                if self.dst[u] == float("inf"): continue
                for v, cost in self.graph[u]:
                    if self.dst[v] > self.dst[u] + cost:
                        self.dst[v] = self.dst[u] + cost
                        update = True

                        if t == self.V-1 and v == self.V-1:
                            return True

            if not update:
                break

        return False


def solve():
    N, M = map(int, input().split())
    bf = BellmanFord(0, N)

    for _ in range(M):
        a, b, c = map(int, input().split())
        bf.add(a-1, b-1, -c)

    nloop = bf.shortest_path()

    if nloop:
        print("inf")
    else:
        print(-bf.dist[N-1])


if __name__ == "__main__":
    solve()


Measured memory_bytes: 3444
//Christmas Party
#include <iostream>

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    int score[N + 1], A[M];
    for(int i = 1; i < N + 1; i++){
        score[i] = 0;
    }
    for(int i = 0; i < M; i++) {
        cin >> A[i];
    }

    int b;
    for(int i = 0; i < M; i++) {
        for(int j = 1; j < N + 1; j++){
            cin >> b;
            if(b == A[i]) score[j]++;
            else score[A[i]]++;
        }
    }

    for(int i = 1; i < N + 1; i++){
        cout << score[i] << endl;
    }
}


Measured memory_bytes: 3124
import sys
import math

#https://atcoder.jp/contests/agc008/submissions/15248942
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
K = ini()
X = ini()
Y = ini()

if N > K:
    print(K*X+(N-K)*Y)
else:
    print(N*X)


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

int main(){
   int n,h;
   cin>>n>>h;
   int a[n],b[n];
   for(int i=0; i<n; i++){
       cin>>a[i]>>b[i];
   }
   sort(a,a+n);
   sort(b,b+n);
   ll ans=0;
   for(int i=n-1;i>=0;i--){
       if(b[i]>a[n-1]){
           ans++;
           h-=b[i];
           if(h<=0){
               cout<<ans<<endl;
               return 0;
           }
       }
   }
   if(h%a[n-1]==0) ans+=(h/a[n-1]);
   else ans+=(h/a[n-1]+1);
   cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define MOD 1000000007
int main(){
    int n;cin>>n;
    vector<ll> a(3*n);
    for(int i=0;i<3*n;i++)cin>>a[i];
    priority_queue<ll> mque;
    priority_queue<ll,vector<ll>,greater<ll>> que;
    vector<ll> Lmax(3*n,0),Rmin(3*n,0);
    for(int i=0;i<n;i++){
        Lmax[n]+=a[i];//右半開
        que.push(a[i]);
    }
    for(int i=2*n;i<3*n;i++){
        Rmin[2*n]+=a[i];//右半開
        mque.push(a[i]);
    }
    for(int i=n;i<2*n;i++){
        if(a[i]>que.top()){
        Lmax[i+1]=Lmax[i]+a[i]-que.top();
        que.pop();
        que.push(a[i]);
        }
        else{
            Lmax[i+1]=Lmax[i];
        }
    }
    for(int i=2*n-1;i>=n;i--){
        if(a[i]<mque.top()){
        Rmin[i]=Rmin[i+1]+a[i]-mque.top();
        mque.pop();
        mque.push(a[i]);
        }
        else{
            Rmin[i]=Rmin[i+1];
        }
    }
    ll ans=LLONG_MIN;
    for(int i=n;i<=2*n;i++){
        //cout<<Lmax[i]<<endl;
        //cout<<Rmin[i]<<endl;
        ans=max(ans,Lmax[i]-Rmin[i]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 9588
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define INF 999999999
typedef long long ll;
using namespace std;
int main() {
    string s;
    cin >> s;
    int cnt = 0;
    REP(i, s.length()) {
        if(s[i] == '1') cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
MOD = 10**9 + 7
N = input()
A = [int(hoge) for hoge in input().split()]
S = 0
Scube = 0
for a in A:
    S += a
    Scube += a**2
    S %= MOD
    Scube %= MOD
Double = S**2 - Scube
Double %= MOD
if Double%2:
    Double += MOD
    Double //= 2
else:
    Double //= 2
print(Double)

Measured memory_bytes: 94172
#include <bits/stdc++.h>
using namespace std;
int k;
string s;
int main()
{
#ifdef MY
    freopen("input.txt","r",stdin);
#else
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    #define endl '\n';
#endif
    cin>>k>>s;
    if(s.size()<=k)
        cout<<s;
    else{
        string a;
        for(int i=0;i<k;i++)
            a.push_back(s[i]);
        a.push_back('.');
        a.push_back('.');
        a.push_back('.');
        cout<<a;
    }
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int dsu[200005];
// ------------------------------------
// 1 is true
// 0 is false
// ------------------------------------

int find(int a) {
  if (dsu[a] < 0) {
    return a;
  } else {
    return dsu[a] = find(dsu[a]);
  }
}

void merge(int a, int b) {
  a = find(a);
  b = find(b);
  if (a == b) {
    return;
  }
  dsu[a] += dsu[b];
  dsu[b] = a;
}

int main() {
  int n, m, a, b, ans = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    dsu[i] = -1;
  }
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    merge(a, b);
  }
  for (int i = 1; i <= n; i++) {
    ans = max(ans, -dsu[find(i)]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 4956
x, k, d = map(int, input().split())
x = abs(x)
if x >= k * d:
    print(x - k * d)
else:
    cnt = x // d
    if cnt % 2 == k % 2:
        point = x - x // d * d
    else:
        point = x - (x // d + 1) * d
    print(abs(point))


Measured memory_bytes: 9180
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
Asort = sorted(A)[:: -1]
L = [0] * N  #左からi番目までのgcdをメモった配列
R = [0] * N  #右からi番目までのgcdをメモった配列
L[0] = A[0]
R[0] = A[N - 1]
for i in range(1, N):
	L[i] = gcd(L[i - 1], A[i])
	R[i] = gcd(R[i - 1], A[N - 1 - i])
ans = max(L[N - 2], R[N - 2])
for j in range(1, N - 1):
	ans = max(ans, gcd(L[j - 1], R[N - j - 2]))
print(ans)


Measured memory_bytes: 16152
#include<iostream>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    
    if (a<b){
    cout << "a < b"<<endl;
    }
    else if (a > b){
    cout << "a > b"<<endl;
    }
    else if (a == b){
    cout <<"a == b"<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3016
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] h = new int[n];
        for(int i = 0; i < n; i++) h[i] = scan.nextInt();
        int out = 0;
        int max = -1;
        for(int i = 1; i < n; i++){
            if(h[i - 1] >= h[i]){
                out++;
            }else{
                max = Math.max(max, out);
                out = 0;
            }
        }
        System.out.println(Math.max(max, out));
    }

    public static void main(String[] args){
        new Main().solve();
    }
}


Measured memory_bytes: 59668
import bisect
from operator import mul

N = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
# 中段より小さいパーツの個数
A_arr = [bisect.bisect_left(A, b) for b in B]
# 中段より大きいパーツの個数
C_arr = [N - bisect.bisect_right(C, b) for b in B]
# 組み合わせの総数
p = map(mul, A_arr, C_arr)
print(sum(p))


Measured memory_bytes: 23988
#include<iostream>
#include<algorithm>
#include<math.h>
#include <iterator>
#include <map>
#include<cmath>
using namespace std;


int main (){
    int x,temp=0,counter=0,ans=0,flag=0;
    cin>>x;
    temp=x;
    while(temp)temp/=10,counter++;
    if(counter%2==0)
     flag=1;
     int i=1;
       temp=counter;
     while (counter&&flag){
     if(i%2!=0)
        ans+=pow(10,i)-pow(10,i-1);
        counter--;
        i++;
     }
     if(flag)cout<<ans<<endl;
     temp=counter;
    while(counter-1&&!flag){
        if(i%2!=0)
               ans+=pow(10,i)-pow(10,i-1);


        counter--;
        i++;
    }

    if(!flag)cout<<ans+(x-pow(10,temp-1))+1<<endl;

	return 0;
}











Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    int n, h, w;
    cin >> n >> h >> w;

    int ans = (n-h+1)*(n-w+1);

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int sum1= n*(n-1)/2;
        int sum2 = m*(m-1)/2;
        System.out.println(sum1+sum2);
    }
}


Measured memory_bytes: 21716
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
int a[100010];

ll mod_pow(ll x, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = (res * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return res;
}

ll solve() {
    int k[n];
    memset(k, 0, sizeof(k));
    for (int i = 0; i < n; i++) {
        k[a[i]]++;
    }
    if ((n%2==0 && k[0] > 0) || (n%2==1 && k[0] != 1)) return 0;
    for (int i = n-1; i > 0; i-=2) {
        if (k[i] != 2)
            return 0;
    }
    return mod_pow(2, n/2);
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}

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

int check(string a, string b) {
  vector<int> v1(26), v2(26);
  for (int i = 0; i < a.size(); i++) {
    v1.at(a.at(i) - 'a')++;
  }
  for (int i = 0; i < b.size(); i++) {
    v2.at(b.at(i) - 'a')++;
  }
  int cnt = 0;
  for (int i = 0; i < 26; i++) {
    if (v1.at(i) > 0 && v2.at(i) > 0) {
      cnt++;
    }
  }
  return cnt;

}



int main(){
  int n;
  string s;
  cin >> n >> s;
  string a, b;
  int tmp = 0;
  for (int i = 1; i < n; i++) {
    a = s.substr(0, i);
    b = s.substr(i, n - i);
    tmp = max(tmp, check(a, b));
  }
  cout << tmp << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
using namespace std;
char s[101];
bool ans;
int main(){
	scanf("%s",s);
	for(int i=0;s[i];i++)
		if(!ans && s[i]=='C')
			ans=true;
		else if(ans && s[i]=='F')
			return printf("Yes"),0;
	printf("No");
	return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			if (line.equals(".")) break;

			Deque<Character> rev = new ArrayDeque<Character>();
			Deque<Character> out = new ArrayDeque<Character>();
			int shift = 0;

			for (char c : line.toCharArray()) {
				switch (c) {
					case '[':
						out.offer(c);
						break;
					case ']':
						char d = out.removeLast();
						while (d != '[') {
							rev.push(d);
							d = out.removeLast();
						}
						// reverse
						while (!rev.isEmpty()) {
							out.offer(rev.removeLast());
						}
						break;
					case '+':
						shift++;
						break;
					case '-':
						shift--;
						break;
					case '?':
						out.offer('A');
						shift = 0;
						break;
					default:
						if (shift != 0) {
							shift %= 26;
							c += shift;
							if (c < 'A') {
								c += 26;
							} else if (c > 'Z') {
								c -= 26;
							}
							out.offer((char) c);
							shift = 0;
						} else {
							out.offer(c);
						}
						break;
				}
			}
			StringBuilder sb = new StringBuilder();
			while (!out.isEmpty()) {
				sb.append(out.poll());
			}
			System.out.println(sb.toString());
		}
	} //end while
} //end main

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

#define PI 3.141592653589793238

int main(void) {
  int r;
  scanf("%d", &r);
  printf("%f\n", (float) r * (float) 2 * (float) PI);

  return 0;
}


Measured memory_bytes: 1752
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
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; }

struct edge { int to; int cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int n,m;
int g[10][10];

int main() {
	cin >> n >> m;
	rep(i,m){
		int a,b;
		cin >> a >> b;
		g[a][b] = g[b][a] = 1;
	}

	vi x;
	for(int i = 2; i <= n; i++) x.push_back(i);

	int cnt = 0;
	do{
		int flag = 1;
		for(int i = 0; i < x.size(); i++){
			int y = (i == 0 ? 1 : x[i-1]);
			if(!g[y][x[i]]) flag = 0;
		}
		if(flag) cnt++;
	}while(next_permutation(all(x)));
	
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()

void solve();

signed main () {
    clock_t beg = clock();
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1; 
    // cin >> t;    
    int tt = t;
    while (t--) { 
        solve();
    }
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
    return 0;
}
const int N = 405;
int dist[N][N];
bool taken[N][N];
const int INF = 1e18;
int n, m;
bool valid (int i, int j) {
    return i >= 1 and i <= n and j >= 1 and j <= m;
}
int get (int i, int j) {
    return m * (i - 1) + j;
}
void solve() {
    memset(taken, false, sizeof taken);
    for(int i=0;i<N;++i)
        for (int j=0;j<N;++j)
            dist[i][j]=INF;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            char c;
            cin >> c;
            if (c == '#')
                taken[i][j] = true;
        }
    }
    int dx[] = {1, -1, 0, 0};
    int dy[] = {0, 0, 1, -1};
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (taken[i][j])
                continue;
            dist[get(i,j)][get(i,j)] = 0;
            for (int k = 0; k < 4; ++k) {
                int ii = i + dx[k];
                int jj = j + dy[k];
                if (!valid(ii, jj))
                    continue;
                if (taken[ii][jj])
                    continue;
                dist[get(i,j)][get(ii,jj)] = 1;
            }
        }
    }
    for (int k = 1; k <= n * m; ++k) {
        for (int i = 1; i <= n * m; ++i) {
            for (int j = 1; j <= n * m; ++j) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    int ans = -INF;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            for (int ii = 1; ii <= n; ++ii) {
                for (int jj = 1; jj <= m; ++jj) {
                    if (!taken[i][j] and !taken[ii][jj])
                        ans = max(ans, dist[get(i, j)][get(ii, jj)]);
                } 
            }
        }
    }
    cout << ans;
}

Measured memory_bytes: 1792
H,N = map(int,input().split())

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

dp = [[10000000000000]*(H+1) for _ in range(N+1)]

for y in range(N):
    a,b = AB[y]
    for x in range(H+1):
        if x <= a:
            dp[y+1][x] = min(dp[y][x], b)
        else:
            dp[y+1][x] = min(dp[y][x], dp[y+1][x-a]+b)
print(dp[-1][-1])

Measured memory_bytes: 146136
n, q = map(int, input().split())

task_list = []
for i in range(0, n):
    name, time = input().split()
    task_list.append((name, int(time)))

current_time = 0
while True:
    if len(task_list) == 0:
        break
    process_name, remaining_time = task_list.pop(0)
    if remaining_time > q:
        task_list.append((process_name, remaining_time - q))
        current_time = current_time + q
    else:
        current_time = current_time + remaining_time
        print(process_name + ' ' + str(current_time))



Measured memory_bytes: 12084
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  ll n,k;
  cin>>n>>k;
  for(int i=0;i<n;i++)
  {
    int x;
    cin>>x;

  }
  n-=1;
  k-=1;
  int ans=ceil(n/double(k));
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 6)

def main():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    T = [True] * N
    for _ in range(M):
        A, B = map(int, input().split())
        if H[A-1] <= H[B-1]:
            T[A-1] = False
        if H[B-1] <= H[A-1]:
            T[B-1] = False
    print(len([1 for t in T if t]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 86792
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N,K;
	cin >> N>>K;
	if (K == 1) {
		cout << 0 << endl;
	}
	else {
		cout << N - K << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
  int a, b;
  cin >> a >> b;
  if ((a*b) % 2 == 0) {
    cout << "Even";
  } else {
    cout << "Odd";
  }
  return 0;
}

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

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

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

	int ret = 0;
	for (int i = 0; i < n; ++i) {
		if (0 < vv[i] - cv[i]) {
			ret += vv[i] - cv[i];
		}
	}

	cout << ret << endl;
	return 0;
}

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

const long long mod = 1000000007;
long long kai[100010];

long long mpow(long long a, long long n){
  long long res = 1;
  while (n > 0) {
      if (n & 1) res = res * a % mod;
      a = a * a % mod;
      n >>= 1;
  }
  return res;
}

long long comb(long long n, long long r){
  long long res = kai[n] * mpow((kai[r]*kai[n-r])%mod,mod-2);
  return res%mod;
}

int main() {
  long long N,K;
  cin >> N >> K;
  vector<long long> A(N);
  for(int i=0;i<N;i++) cin >> A[i];
  sort(A.begin(),A.end());
  
  kai[0] = 1;
  for(int i=1;i<=N;i++){
    kai[i] = kai[i-1]*i;
    kai[i] %= mod;
  }
  
  long long mins=0,maxs=0;
  for(int i=0;N-i>=K;i++){
    long long x = (A[i] * comb(N-i-1,K-1)) % mod;
    if(x<0) x += mod;
    mins += x;
    mins %= mod;
  }
  reverse(A.begin(),A.end());
  for(int i=0;N-i>=K;i++){
    long long x = (A[i] * comb(N-i-1,K-1)) % mod;
    if(x<0) x += mod;
    maxs += x;
    maxs %= mod;
  }
  
  long long ans = (maxs-mins) % mod;
  if(ans<0) ans += mod;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;
int main(){
    long long a,b,c;
    cin >> a >> b >> c;
    long long ans=0;
    long long at=a,bt=b,ct=c;
    if(a==b&&b==c&&c==a){
        if(a%2==0){
            ans = -1;
        }else{
            ans = 0;
        }
    }else{
        while(a%2==0&&b%2==0&&c%2==0){
        a = (bt+ct)/2;
        b = (at+ct)/2;
        c = (at+bt)/2;
        at = a;
        bt = b;
        ct = c;
        ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
//using System.Collections.Generic;
//using System.Linq;

namespace solution
{
  class Class1
  {
    static void Main()
    {
      int turn = int.Parse(Console.ReadLine());

      int taroPoint = 0;
      int hanakoPoint = 0;

      for (int i = 0; i < turn; i++)
      {
        int f = 0;
        var word = Console.ReadLine().Split();
        if (word[0] == word[1]) { taroPoint++; hanakoPoint++; continue; }

        int length = (word[0].Length < word[1].Length) ? word[0].Length : word[1].Length;
        for (int j = 0; j < length; j++)
        {
          if (word[0][j] > word[1][j]) { taroPoint += 3; f = 1; break; }
          else if (word[0][j] < word[1][j]) { hanakoPoint += 3; f = 1; break; }
        }
        if (f == 1) continue;
        if (word[0].Length > word[1].Length) taroPoint += 3;
        else if (word[0].Length < word[1].Length) hanakoPoint += 3;
      }
      Console.WriteLine("{0} {1}", taroPoint, hanakoPoint);
    }
  }
}


Measured memory_bytes: 9280
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string.h>
using namespace std;

const int N = 1e5+10;;
int a[N], b[N], c[N];
int main ()
{
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    for(int i = 0; i < n; i++)
    {
        scanf("%d", &b[i]);
    }
    for(int i = 0; i < n; i++)
    {
        scanf("%d", &c[i]);
    }
    sort(a, a+n);
    sort(b, b+n);
    sort(c, c+n);
    long long ans = 0;
    for(int i = 0, j = 0, k = 0; i < n; i++)
    {
        while(b[i]>a[j] && j <= n-1)
        {
            j++;
        }
        while(b[i]>=c[k] && k <= n-1)
        {
            k++;
        }
        ans += (long long )j * (n-k);
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h> 
#define pb push_back 
#define gc getchar 
#define mp make_pair
#define pii pair<int,int> 
#define pll pair<lli,lli>
#define vi vector<int>
#define vc vector<char>
#define pdd pair<double,double>
#define rep(i,n) for(int i=0;i<n;i++)
#define repi(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define vvi vector<vector<int> >
#define vvli vector<vector<long long int> >
#define vli vector<long long int> 
#define pq priority_queue 
#define lli long long int
#define li long int
#define f first
#define len length
#define p(x) cout<<x<<" "
#define pline(x) cout<<x<<"\n"
#define pcase(test) cout<<"Case #"<<test<<": "
#define take(x) cin>>x
#define s second
#define arrtake(n,inp) rep(i,n){int x;cin>>x;inp.pb(x);}
#define ins insert
#define lb lower_bound
#define ub upper_bound
#define M 1000000007
#define PI 3.14159265358979323
using namespace std;
     /*ios_base::sync_with_stdio(false);
         cin.tie(NULL);*/
template <typename T>
void printvec(vector<T>& vec){
   rep(i,vec.size()){
       cout<<vec[i]<<" ";
   }
   cout<<endl;
}



int main() {

    ios_base::sync_with_stdio(false);

   	lli n;
   	cin>>n;

   	lli tot = 0;

   	lli maxi = -1;


   	rep(i,n)
   	{
   		lli x;
   		cin>>x;
   		if(maxi==-1)
   		{
   			maxi = x;
   		}
   		else
   		{
   			if(maxi>x)
   			{
   				tot += maxi-x;
   			}
   			else
   			{
   				maxi = x;
   			}
   		}
   	}


   	cout<<tot<<"\n";

}



Measured memory_bytes: 3652
n = int(input())
m = list(map(int, input().split()))
ans = m[0] * 2
for i in range(n-2):
    if m[i] > m[i+1]:
        ans += 2 * m[i+1]
        ans -= m[i]
        continue
    ans += max(m[i], m[i+1])
print(ans)

Measured memory_bytes: 8896
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;

#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return(0)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(e, elem) for(auto& (e) : (elem))
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define all(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e);
using ll = long long;
using ull = unsigned long long;

int main() {
    FAST;

    string s;
    cin >> s;
    string h{};
    rep(i, 5){
        h += "hi";
        if(h == s){
            println("Yes");
            stop;
        }
    }

    println("No");
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,X=map(int,input().split())
    L=list(map(int,input().split()))
    ans=1
    D=0
    for i in L:
        D+=i
        if D<=X:
            ans+=1
        else:
            break
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization("unroll-loops")

#include "bits/stdc++.h"
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl '\n'
#define f first
#define s second
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define cf ll testcases;cin>>testcases;while(testcases--)
#define prn(x) if(x) cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define minel(x) (*min_element(all(x)))
#define maxel(x) (*max_element(all(x)))
#define cou dbg=1;cout
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef vector<ld> vd;
typedef vector<pi> vp;
ll dbg=0;
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p);
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p);
template<typename A> istream& operator>>(istream& cin, vector<A> &v);
int dx[] = {-1, -1, -1,  0, 0,  1, 1, 1};
int dy[] = {-1,  0,  1, -1, 1, -1, 0, 1};

void solve(){
    ll n;
    cin>>n;
    vi arr(n);
    cin>>arr;
    ll ans=0;
    for(ll i=0;i<n-1;i++)
    {
        if(arr[i]>arr[i+1]){
            ans+=arr[i]-arr[i+1];
            arr[i+1]=arr[i];
        }
    }
    cout<<ans<<endl;
}

int main(){
    IO;
    // cf
    solve();
    return 0;
}


template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { 
    if(dbg){
        dbg=0;
        return cout << "(" << p.f << ", " << p.s << ")"; 
    }else{
        return cout<<p.f<<' '<<p.s;
    }}
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
    if(dbg){
        dbg=0;
        cout << "["; for(ll i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
    }else{
        for(ll i=0;i<v.size()-1;i++) cout<<v[i]<<' ';
        return cout<<v[v.size()-1];
    }
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
   cin >> p.first;
   return cin >> p.second;
}
template<typename A> istream& operator>>(istream& cin, vector<A> &v) {
   for(ll i=0;i<v.size()-1;i++) cin>>v[i];
   return cin >> v[v.size()-1];
}

Measured memory_bytes: 4764
import java.util.*;
public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      long a = sc.nextLong();
      long b = sc.nextLong();
      long c = sc.nextLong();
      if(4*a*b<(c-a-b)*(c-a-b)&&c-a-b>0){
        System.out.println("Yes");
      }else{
        System.out.println("No");
      }
    }
}

Measured memory_bytes: 35736
fun <T> calcPermutationList(sortedList: List<T>): List<List<T>> {
    val permutationList = mutableListOf<List<T>>()
    val queue = mutableListOf(listOf<T>())
    while (queue.isNotEmpty()) {
        val p = queue.removeAt(0)

        if (p.size == sortedList.size) {
            permutationList += p
        } else {
            queue += (sortedList - p).map { p + it }
        }
    }

    return permutationList
}

fun main(args: Array<String>) {
    val n = readInteger()
    val p = readIntegerList()
    val q = readIntegerList()

    calcPermutationList((1..n).toList())
        .let { it.indexOf(p) - it.indexOf(q) }
        .let(Math::abs)
        .let(::println)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p){
    return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n,m; cin >> n >> m;
    vl l(m), r(m), c(m);
    vector<tuple<ll,ll,ll>> v;
    rep(i,m){
        cin >> l[i] >> r[i] >> c[i];
        l[i]--; r[i]--;
        v.emplace_back(l[i], i, 1);
        v.emplace_back(r[i], i, -1);
    }
    v.emplace_back(n, -1, -1);
    sort(all(v));

    vl d(n, INFL);
    d[0] = 0;
    int now = 0;
    multiset<pll> st;
    rep(pos,n){
        if(st.size() > 0){
            d[pos] = min(d[pos], st.begin()->fi);
        }
        while(get<0>(v[now]) == pos){
            ll p = get<0>(v[now]);
            ll i = get<1>(v[now]);
            ll flg = get<2>(v[now]);
            if(flg == 1){
                st.insert(pll(d[l[i]] + c[i], i));
            }else{
                st.erase(st.find(pll(d[l[i]] + c[i], i)));
            }
            now++;
        }
    }
    if(d[n-1] == INFL) cout << -1 << endl;
    else cout << d[n-1] << endl;
    return 0;
}

Measured memory_bytes: 13944
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <queue>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    int a;
    for (int i = 0; i < n; i++) {
        cin >> a;
        ans += --a;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    string N;
    cin >> N;
    if(N[N.size()-1] == '2' || N[N.size()-1] == '4' || N[N.size()-1] == '5' || N[N.size()-1] == '7' || N[N.size()-1] == '9'){
        cout << "hon";
    }else if(N[N.size()-1] == '3'){
        cout << "bon";
    }else{
        cout << "pon";
    }
}

Measured memory_bytes: 3632