akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int n;
long int ans;
int main() {
  for(;;) {
    scanf("%d", &n);
    if(n == 0) break;
    vector<int> v(n);
    for(int i = 0; i < n; ++i) scanf("%d", &v[i]);
    sort(begin(v), end(v));
    v[n - 1] = 0, v[0] = 0;
    for(int i = 0; i < n; ++i) ans+=v[i];
    ans /= n - 2;
    printf("%ld\n", ans);
    n = 0, ans = 0;
    v.clear();
  }
  return 0;
}

Measured memory_bytes: 3160
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;
 
void Main()
{
	long long N;
  
  	cin >> N;
  
  long long S = 0;
  
  for(int i = 1; i <= N; i++){
  if(i % 3 != 0 && i % 5 != 0){
    S += i;
  }
  }
  
  printf("%lld", S);
	
	
}
 
int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define endl "\n"

const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

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

    char c;
    cin >> c;

    if (islower(c))
        cout << 'a' << endl;
    else
        cout << "A" << endl;
}

Measured memory_bytes: 3636
/*zhen hao*/
#include <bits/stdc++.h>
using namespace std;

#define lson l, m, rt*2
#define rson m + 1, r, rt*2+1
#define xx first
#define yy second

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> pii;

const int N = 1e5 + 10;
int a[N * 3];

int main() {
#ifdef JUDGE
  freopen("case.in", "r", stdin);
#endif
  int n;
  cin >> n;
  for (int i = 0; i < 3 * n; i++) {
    scanf("%d", a + i);
  }
  sort(a, a + n * 3);
  LL r1 = 0, r2 = 0;
  for (int i = n; i < 2 * n; i++) {
    r1 += a[i];
  }
  for (int i = 0, j = 3 * n - 2; i < n; i++, j -= 2) {
    r2 += a[j];
  }
  cout << max(r1, r2) << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll inf =1LL << 62;

int main(void){
	int n;
	while(cin >> n,n){
		int sum=0;
		for(int i=1;i*i<=n;i++){
			if(n%i==0){
				int a=i;
				int b=n/i;
				if(a!=n)
					sum+=a;
				if(a!=b&&b!=n)
					sum+=b;
			}
				
		}
		if(sum>n)
			cout << "abundant number" << endl;
		else if(sum==n)
			cout << "perfect number" << endl;
		else
			cout << "deficient number" << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int X=scan.nextInt();
		if(X==7)
		{
			System.out.println("YES");
		}
		else if(X==5)
		{
			System.out.println("YES");
		}
		else if(X==3)
		{
			System.out.println("YES");
		}
		else
		{
			System.out.println("NO");
		}
	}

}

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

int count(int i) {
  int counter = 0;
  for (int j=2; j<i+1; j*=2) {
    if (i%j == 0) {
      counter++;
    }
    else {
      break;
    }
  }
  return counter;
}

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i=0; i<N; i++) {
    cin >> a.at(i);
  }
  int answer = 0;
  for (int i=0; i<N; i++) {
    answer += count(a.at(i));
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
x = int(raw_input())
s = raw_input().split(" ")
s.insert(0, "0")

def cost(a, b):
 return abs(int(a)-int(b))

totalCost = cost(s[-1], s[0])
skipGain = [None] * (x+1)

costPrev = cost(s[0], s[1])
for i in range(0, x):#i=0 skipping 1st one, prev=0-1, post=1-2
 costThisOne = cost(s[i+1], s[0 if i==x-1 else i+2])
 totalCost += costPrev
 skipGain[i+1] = cost(s[i], s[0 if i==x-1 else i+2]) - costPrev - costThisOne
 costPrev = costThisOne

for i in range(1, x+1):
 print totalCost + skipGain[i]


Measured memory_bytes: 14548
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=998244353;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
    return powmod(a, MOD-2);
}
ll dp[3030][3030];
ll s[3030];
int main()
{
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    dp[a][b]=1;
    for(int i=a; i<=c; i++){
        for(int j=b; j<=d; j++){
            (dp[i+1][j]+=dp[i][j]*j)%=MOD;
        }
        s[0]=0;
        ll x=inv(i), xp=x, yp=i;
        for(int j=1; j<=d; j++){
            s[j]=dp[i][j]*xp%MOD;
            (s[j]+=s[j-1])%=MOD;
            (xp*=x)%=MOD;
        }
        for(int j=1; j<=d; j++){
            (dp[i+1][j]+=s[j-1]*yp)%=MOD;
            (yp*=i)%=MOD;
        }
    }
    ll ans=0;
    for(int i=b; i<=d; i++){
        (ans+=dp[c][i]*powmod(c, d-i))%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 74416
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n)    for(int i=a; i<=n; ++i)
#define rep1(i,a,n)   for(int i=a; i>=n; --i)
#define pb            push_back
#define int           long long
#define fr            first
#define sc            second
#define vc            vector
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define M             1000000007
#define MM            998244353
#define PI            3.14159265358979
#define INF           1000000000000000

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;

int n,m,ans; string str;

int dp[100005][2];
int solve(){
    cin>>n;
    int h[n+1]; rep(i,1,n) cin>>h[i];
    dp[1][0]=0; dp[1][1]=0;
    dp[2][0]=abs(h[2]-h[1]); dp[2][1]=abs(h[2]-h[1]);
    rep(i,3,n){
        dp[i][0]=INF; dp[i][1]=INF;
        dp[i][0]=min(dp[i][0],dp[i-1][0]+abs(h[i]-h[i-1]));
        dp[i][0]=min(dp[i][0],dp[i-1][1]+abs(h[i]-h[i-1]));
        dp[i][1]=min(dp[i][1],dp[i-2][0]+abs(h[i]-h[i-2]));
        dp[i][1]=min(dp[i][1],dp[i-2][1]+abs(h[i]-h[i-2]));
    }
    cout<<min(dp[n][0],dp[n][1]);
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 2560
from sys import stdin
import numpy as np
from numba import njit
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    s=readline().strip()
    ans=s.count("R")*s.count("G")*s.count("B")
    s=np.array([0 if s[i]=="R" else 1 if s[i]=="G" else 2 for i in range(n)],dtype=np.int64)

    print(f(n,ans,s))

@njit("i8(i8,i8,i8[:])",cache=True)
def f(n,ans,s):
    for i in range(n):
        for j in range(i+1,n):
            k=2*j-i
            if k>=n: break
            if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
                ans-=1
    return ans

if __name__=="__main__":
    main()

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

using namespace std;

#define ll long long
#define pb push_back
#define pf push_front
#define loop(i, n) for(int i = 0 ; i < n ; ++i)
#define LOOP(i, a, b) for(int i = a ; i < b ; ++i)
#define max3(a, b, c) max(a, max(b,c))
#define max4(a, b, c, d) max3(a, b, max(c, d))
#define ff first
#define ss second
#define mkp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define vii vector<pii>
#define vvii vector<vii>
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define nmbr(c) (int)(c-'0')
#define ltr(c) (int)(c-'a')
#define INF 1e18
#define inf 1e9
#define MOD 1000000007 //check
#define _69e27 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

int n, k0, v[102], dp[100005][2];
string ans[] = {"First", "Second"};
int game(int k, int i)
{
	if(k < v[0]) return i^1;
	int &ans = dp[k][i];
	if(ans != -1) return ans;
	int arr[] = {0, 0};
	loop(j, n)
	{
		if(k < v[j]) break;
		++arr[game(k-v[j], i^1)];
	}
	if(arr[i]) ans = i;
	else ans = i^1;
	return ans;
}
int main() {
	_69e27;
	memset(dp, -1, sizeof(dp));
	cin >> n >> k0;
	loop(i, n) cin >> v[i];
	cout << ans[game(k0, 0)] << endl;
	return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;

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

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

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

  ll ans = 0;
  for (;;)
  {
    rep(i, a)
    {
      if (k == 0)
      {
        cout << ans << endl;
        return 0;
      }

      ans++;
      k--;
    }

    rep(i, b)
    {
      if (k == 0)
      {
        cout << ans << endl;
        return 0;
      }

      k--;
    }

    rep(i, c)
    {
      if (k == 0)
      {
        cout << ans << endl;
        return 0;
      }

      ans--;
      k--;
    }
  }

  return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		double c = Double.parseDouble(a+b);
		double ans = Math.sqrt(c);
		int num = (int) ans;
		if(ans - num == 0) {
			System.out.println("Yes");
		} else if (ans - num !=0) {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21716
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <tuple>
#include <cmath>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
using namespace std;

int N;
int h[100000 + 10];
ll dp[100000 + 10];

int main(void) {
    cin >> N;
    REP(i, 1, N) {
        cin >> h[i];
    }
    
    dp[1] = 0;
    dp[2] = abs(h[2] - h[1]);
    
    REP(i, 3, N) {
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
    }
    
    cout << dp[N] << endl;
    
    return 0;
}




Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
using namespace std;
typedef long long ll;

int main() {
    int a, b, c; cin >> a >> b >> c;
    int mx = max(a, max(b, c));
    a = mx-a;
    b = mx-b;
    c = mx-c;
    int ans = 0;
    ans += a/2;
    ans += b/2;
    ans += c/2;
    a %= 2;
    b %= 2;
    c %= 2;
    int num[2]= {0};
    num[a]++;
    num[b]++;
    num[c]++;
    if (num[1] == 2) ans++;
    if (num[1] == 1) ans+=2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u){
  int v;
  color[u]=GRAY;
  d[u]=++tt;
  for(v=0;v<n;v++){
    if(M[u][v]==0) continue;
    if(color[v]==WHITE){
      dfs_visit(v);
    }
  }
  color[u]=BLACK;
  f[u]=++tt;
}
void dfs(){
  int u;
  for(u=0;u<n;u++) color[u]=WHITE;
  tt=0;
  for(u=0;u<n;u++){
    if(color[u]==WHITE) dfs_visit(u);
  }
  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}
int main(){
  int u,v,k,i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++) M[i][j]=0;
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }
  dfs();
  return 0;
}
  



Measured memory_bytes: 2108
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll ret = 0;
    if (k < a)
    {
        cout << k << endl;
        return 0;
    }

    if (k <= (a + b))
    {
        cout << a << endl;
        return 0;
    }
    k -= (a+b);
    cout << a-k << endl;
}

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

int isPalindrom(string s) {
    int n = s.length();
    for (int i = 0; i < n / 2; i++) {
        if (s[i] != s[n-i-1]) return 0;
    }
    return 1;
}

int main() {
    string s;
    cin >> s;
    int n = s.length();

    string s1 = s.substr(0, (n - 1) / 2);
    string s2 = s.substr((n + 3) /2 - 1);

    if (isPalindrom(s) && isPalindrom(s1) && isPalindrom(s2)) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 3632
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int cal[10][10];
int check(int a, int b, int c, int d, int err) {
  FOR(i,0,10) {
    if(cal[cal[cal[cal[cal[0][i]][b]][c]][d]][err] == 0 && i != a) {
      return -1;
    }
  }
  FOR(i,0,10) {
    if(cal[cal[cal[cal[cal[0][a]][i]][c]][d]][err] == 0 && i != b) {
      return -1;
    }
  }
  FOR(i,0,10) {
    if(cal[cal[cal[cal[cal[0][a]][b]][i]][d]][err] == 0 && i != c) {
      return -1;
    }
  }
  FOR(i,0,10) {
    if(cal[cal[cal[cal[cal[0][a]][b]][c]][i]][err] == 0 && i != d) {
      return -1;
    }
  }
  FOR(i,0,10) {
    if(cal[cal[cal[cal[cal[0][a]][b]][c]][d]][i] == 0 && i != err) {
      return -1;
    }
  }

  if(cal[cal[cal[cal[cal[0][b]][a]][c]][d]][err] == 0 && a != b) return -1;
  if(cal[cal[cal[cal[cal[0][a]][c]][b]][d]][err] == 0 && b != c) return -1;
  if(cal[cal[cal[cal[cal[0][a]][b]][d]][c]][err] == 0 && c != d) return -1;
  if(cal[cal[cal[cal[cal[0][a]][b]][c]][err]][d] == 0 && d != err) return -1;

  return 1;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  FOR(i,0,10) FOR(j,0,10) cin >> cal[i][j];
  int ans = 0;
  FOR(a,0,10) {
    FOR(b,0,10) {
      FOR(c,0,10) {
        FOR(d,0,10) {
          int err = cal[cal[cal[cal[0][a]][b]][c]][d];
          if(check(a,b,c,d,err) == -1) ans++;
        }
      }
    }
  }
  cout << ans << endl;
  return  0;
}

Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
    cin>>s;
    if((s[0]==s[s.size()-1] && s.size()%2==0) || (s[0]!=s[s.size()-1] && s.size()%2)){
		cout<<"First"<<endl;
	}
    else{
		cout<<"Second"<<endl;
	}
    return 0;
}

Measured memory_bytes: 512
/*
 *  Created on: 2 / 5 / 2020
 *  Author:     Eslam Waheed
 */
#include <bits/stdc++.h>
//#include <bits/BIGINT.h>
//#include <bits/Int128.h>
using namespace std;

//#define _CRT_SECURE_NO_WARNINGS
//#define __USE_MINGW_ANSI_STDIO
#define Eslam__Waheed ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);

#define ll   long long
#define ull  unsigned ll
#define dd   double
#define ld   long dd
#define ss   string

#define pb      push_back
#define all(c)  c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define stp(n)  cout << fixed << setprecision(n);
#define iq(v)   v.resize(unique(v.begin(),v.end())-v.begin())
#define sz(s)   (ll)(s.size())
#define endl    '\n'

#define loop(i,m,n)  for(ll i=m;i<n;i++)

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

//const ll mod = 1e9 + 7;
//__int128
/*
 you can ^_^ (•‿•)

( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما )
*/
int main()
{
    //stp(0)
    Eslam__Waheed
        ll a, b, n; cin >> a >> b >> n;
    ll ans = 0;
    if (n < b)
    {
        ans = floor((a * n) / b);
    }
    else
    {
        n = b - 1;
        ans = floor((a * n) / b);
    }
    cout << ans;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    if (v.size() > 0) {
        os << v[v.size() - 1] << endl;
    }
    return os;
}

int main() {
    int n;
    cin >> n;
    vint a(n);
    cin >> a;
    unordered_map<int,int> ma;
    ll nowsum = 0;
    REP(i,n){
        ma[a[i]]++;
        nowsum += a[i];
    }
    int q;
    cin>>q;
    REP(i,q){
        int b,c;
        cin>>b>>c;
        int curnum = ma[b];
        ma[b] = 0;
        ma[c] += curnum;
        nowsum += (c - b) * curnum;
        cout << nowsum << endl;
    }
}

Measured memory_bytes: 7520
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main() {
    int R[MAX], n;

    cin >> n;
    for (int i = 0; i < n; i++) cin >> R[i];

    int maxv = -2000000000; //???????°??????????????????????????¨????
    int minv = R[0];

    for (int i = 1; i < n; i++) {
        maxv = max(maxv, R[i] - minv); // ?????§????????´??°
        minv = min(minv, R[i]); // ???????????§???????°???????????????????
    }

    cout << maxv << endl;

    return 0;
}

Measured memory_bytes: 3868
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
????????????????????????????????? ??§?????§  
??????????????? ??§?????§ ???????´<_??? ?????? Welcome to My Coding Space!
???????????? ??? ?´_???`??????/??? ???i     
?????????????????????????????? ???  |???|     
????????? /?????? /??£??£??£??£/??????|  
??? ???_(__??????/???    ???/ .| .|????????????  
??? ????????????/????????????/??????u??????  
---------------------------------------------------------------------------------------------------*/
 

typedef long long ll;
int N; ll T, H[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> T;
    rep(i, 0, N) cin >> H[i];

    ll atop = 0, blast = 0;
    rep(i, 0, N) {
        ll btop = max(atop + H[i], blast);
        ll len = btop - atop;
        ll rest = T - atop;

        ll ans = 1;
        if (0 < rest) {
            ans = rest / len + 1;
            ll d = rest % len;
            if (H[i] <= d) ans++;
        }

        printf("%lld\n", ans);

        atop += H[i];
        blast = btop + H[i];
    }
}

Measured memory_bytes: 4000
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int R,G;
	scanf("%d%d",&R,&G);
	printf("%d\n",2*G-R);
	return 0;
}


Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

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

  map<P,int> M;
  for(int i=0,x,y,c;i<n;i++)cin>>x>>y>>c,M[P(x,y)] += c;

  map<P,int>::iterator it;
  int mx=0;
  int dx[2][3] = {{1,1,0},{-1,-1,0}};
  int dy[2][3] = {{0,1,1},{0,1,1}};
  for(it=M.begin();it!=M.end();it++){
    int x = it->first.first;
    int y = it->first.second;
    for(int k=0;k<2;k++){
      int num = it->second;
      for(int i=0;i<3;i++){
	int nx=x+dx[k][i];
	int ny=y+dy[k][i];
	if(!M.count(P(nx,ny)))continue;
	num+=M[P(nx,ny)];
      }
      mx=max(mx,num);
    }
  }
  cout<<mx<<" / 1"<<endl;
  return 0;
}

Measured memory_bytes: 9348
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		sc.close();
		int ans = 11;
		int buf = 0;
		int a = 0;
		int b = 0;
		for (long i=1; i<=Math.sqrt(n); i++) {
			if (n % i == 0) {
				a = String.valueOf(i).length();
				b = String.valueOf(n/i).length();
				if (a>b) break;
				if (ans > b) ans = b;
				if (a==b) break;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll a[200005];

// ------------------------------------
// 1 is true
// 0 is false
// ------------------------------------

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

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  const ll k = 1000000007;
  ll sumai = 0, sumaisq = 0, minvtwo = binexp(2, (k - 2), k);
  for (int i = 0; i < n; i++) {
    sumai += a[i] % k;
    sumaisq += ((a[i] % k) * (a[i] % k)) % k;
    sumai = sumai % k;
    sumaisq = sumaisq % k;
  }

  cout << (minvtwo * ((sumai * sumai - sumaisq) % k)) % k << endl;
}


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

int main() {
  int n;cin>>n;
  int ans=1;
  for(int i=2;i<n+1;i++){
    int power=i*i;
    for(int j=2;;j++){
      if(power>n)break;
      ans=max(ans,power);
      power*=i;
    }
  }
  cout<<ans<<endl;
}

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

int main()
{
  int n;
  cin >> n;
  unordered_map<int, int> m;
  ll ans = 0;
  rep(i, n)
  {
    int a;
    cin >> a;
    ans += m[a-i];
    m[-a-i]++;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
    ll n, d;
    cin >> n >> d;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ll x, y;
        cin >> x >> y;
        if (x*x + y*y <= d*d) ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextInt();
    int k = sc.nextInt();
    long a = 0;
    int count = 0;
    for(int i=0 ; i<n ; i++){
      a = (long)Math.pow(k,i);
      if(n/a>0){
        count++;
      }else{
        count++;
        break;
      }
    }
    if(count==1){
      System.out.println(count);
    }else{
      System.out.println(count-1);
    }

  }
}


Measured memory_bytes: 21460
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    int n;
    cin >> n;
    ll c;
    cin >> c;
    vector<ll> x(n + 2), v(n + 1), sum(n + 1), a(n + 1), b(n + 2);
    for (int i = 1; i <= n; ++i) {
        cin >> x[i] >> v[i];
        sum[i] = sum[i - 1] + v[i];
    }
    for (int i = 1; i <= n; ++i) {
        a[i] = max(a[i - 1], sum[i] - x[i]);
        b[n - i + 1] = max(b[n - i + 2], sum.back() - sum[n - i] - (c - x[n - i + 1]));
    }
    ll ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans = max({ans, a[i], b[i], sum[i] - 2 * x[i] + b[i + 1], sum.back() - sum[i - 1] - 2 * (c - x[i]) + a[i - 1]});
    }
    cout << ans << endl;
    return 0;
}

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

using PP = pair<int, int>;

struct Query {
  int a;
  int b;
  int c;
  int d;
  int m;
};

int N, Q;
vector<PP> G[100000];
int C[100000];
int D[100000];
Query V[100000];
vector<int> qs[100000];
int memo_dist[100000];
unordered_map<int, int> memo_cnt[100000];
unordered_map<int, int> memo_sum[100000];

int dep[100000];
int par[21][100000];
void pre_rec(int from, int prev, int d) {
  par[0][from] = prev;
  dep[from] = d;
  for (PP e : G[from]) {
    int to = e.first;
    if (to == prev) continue;
    pre_rec(to, from, d + 1);
  }
}

void pre() {
  pre_rec(0, -1, 0);
  for (int k = 0; k < 20; ++k) {
    for (int i = 0; i < N; ++i) {
      int p = par[k][i];
      par[k + 1][i] = p == -1 ? -1 : par[k][p];
    }
  }
}

int lca(int u, int v) {
  if (dep[u] > dep[v]) return lca(v, u);
  int diff = dep[v] - dep[u];
  for (int k = 20; k >= 0; --k) {
    if ((1 << k) <= diff) {
      v = par[k][v];
      diff -= (1 << k);
    }
  }
  if (u == v) return u;

  for (int k = 20; k >= 0; --k) {
    if (par[k][u] != par[k][v]) {
      u = par[k][u];
      v = par[k][v];
    }
  }
  return par[0][u];
}

int cnt[100000];
int sum[100000];
void rec(int from, int prev, int dist) {
  memo_dist[from] = dist;
  for (int q : qs[from]) {
    memo_cnt[from][q] = cnt[q];
    memo_sum[from][q] = sum[q];
  }
  
  for (PP e : G[from]) {
    int to = e.first;
    int idx = e.second;
    if (to == prev) continue;
    int c = C[idx];
    int d = D[idx];
    ++cnt[c];
    sum[c] += d;
    rec(to, from, dist + d);
    sum[c] -= d;
    --cnt[c];
  }
}

long val(int v, int c, int d) {
  return memo_dist[v] - memo_sum[v][c] + d * memo_cnt[v][c];
}

int main() {
  cin >> N >> Q;
  for (int i = 0; i < N - 1; ++i) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    --a; --b; --c;
    G[a].push_back(PP(b, i));
    G[b].push_back(PP(a, i));
    C[i] = c;
    D[i] = d;
  }
  
  for (int k = 0; k < Q; ++k) {
    int a, b, c, d;
    cin >> c >> d >> a >> b;
    --a; --b; --c;
    V[k] = Query{ a, b, c, d, 0 };
  }
  
  pre();
  
  for (int k = 0; k < Q; ++k) {
    int a = V[k].a;
    int b = V[k].b;
    int m = lca(a, b);
    V[k].m = m;
    int c = V[k].c;
    qs[a].push_back(c);
    qs[b].push_back(c);
    qs[m].push_back(c);
  }
  
  rec(0, -1, 0);
  
  for (int k = 0; k < Q; ++k) {
    int a = V[k].a;
    int b = V[k].b;
    int c = V[k].c;
    int d = V[k].d;
    int m = V[k].m;
    long ans = val(a, c, d) + val(b, c, d) - 2 * val(m, c, d);
    cout << ans << endl;
  }
}

Measured memory_bytes: 62840
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

int main(){
  
  int n,q;
  cin>>n>>q;
  string s;
  cin>>s;
  char t[q], d[q];
  REP(i,q){
    cin>>t[i]>>d[i];
  }
  
  int l = 0, r = n+1;//(l,r]:左から落ちない範囲
  while(r-l>1){
    int m = (l+r)/2;
    int now = m;
    REP(i,q){
      if(now == 0 || now == n+1)break;
      if(s[now-1] == t[i]){
        if(d[i] == 'L'){
          now--;
        }else{
          now++;
        }
      }else{
        continue;
      }
    }
    if(now == 0){
      l = m;
    }else{
      r = m;
    }
  }
  int left = r;
  
  l = 0, r = n+1;//[l,r):右から落ちない範囲
  while(r-l>1){
    int m = (l+r)/2;
    int now = m;
    REP(i,q){
      if(now == 0 || now == n+1)break;
      if(s[now-1] == t[i]){
        if(d[i] == 'L'){
          now--;
        }else{
          now++;
        }
      }else{
        continue;
      }
    }
    if(now == n+1){
      r = m;
    }else{
      l = m;
    }
  }
  int right = l;
  
  int ans;
  if(left == n+1){
    ans = 0;
  }else if(right == 0){
    ans = 0;
  }else if(left > right){
    ans = 0;
  }else{
    ans = right - left + 1;
  }
    
  cout<<ans<<endl;
  return 0; 
}


Measured memory_bytes: 900
using System;
using System.Collections.Generic;
public class CFRP_A {
    public static void Main() {
        long K, A, B, ans = 0, ab, ka;
        string[] str = System.Console.ReadLine().Split(' ');
        K = long.Parse(str[0]);
        A = long.Parse(str[1]);
        B = long.Parse(str[2]);
        ab = A - B;
        if (A >= K) System.Console.WriteLine(1);
        else if (ab <= 0) System.Console.WriteLine(-1);
        else {
            ka = K - A;
            ans = ka / ab;
            if (ka % ab != 0) ans++;
            System.Console.WriteLine(ans * 2 + 1);
        }
    }
}

Measured memory_bytes: 13140
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

unsigned long long int C[100000][10] = {0};

unsigned long long int combination(unsigned long long int n,unsigned long long int r){
	if(C[n][r] != 0) return C[n][r];
//	cout << n <<endl;
	//cout << n << " " << r << " " <<C[n][r] <<endl;
	if( n < r) return 0;
	if (r == 0 || r == n || n == 1 )
        return (1);
    else if (r == 1)
        return (n);
	C[n][r] = (combination(n - 1, r - 1) + combination(n - 1, r));
    return C[n][r];
}



int main(){
	unsigned long long int n;
	cin >> n;
	vector<string> vs(n);
	
	for(int i=0;i<n;++i){
		string s;
		cin >> s;
		sort(s.begin(),s.end());
		//cout << s <<endl;
		vs[i] = s;
	}
	
	sort(vs.begin(),vs.end());
	unsigned long long int res = 0;
	unsigned long long int tmp = 1;
	for(int i=0;i<n;++i){
//		cout << vs[i] << " " << vs[i+1];
		if(i+1 < n && vs[i] == vs[i+1]){
			tmp++;
		}else{
			//cout << tmp << " " <<  combination(tmp,2) <<endl;
			unsigned long long int c = combination(tmp,2);
			if( c != 0) res += c;
			tmp = 1;
		}
	}
	
	cout << res << endl;
	
	return 0;
}



Measured memory_bytes: 18176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fi first
#define se second
#define endl '\n'
#define y1 holyshit
#define all(x) x.begin(),x.end()
const int inf=0x3f3f3f3f;
const ll mod=1000000007;

int K;

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

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>K;
    ll ans=0;
    for(int i=1;i<=K;i++) for(int j=1;j<=K;j++) for(int k=1;k<=K;k++) ans+=gcd(i,gcd(j,k));
   	cout<<ans;
    return 0;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int N,Q,c[300010],ans[300010];
int p[601];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>N>>Q;
	rep(i,N)cin>>c[i];
	sort(c,c+N);
	
	fill(p+1,p+601,N-1);
	for(int i=300000;i>=601;i--){
		rep2(j,1,601){
			while(p[j]>=0 && c[p[j]] >= i*j) p[j]--;
			if(p[j]>=0) ans[i]=max(ans[i],c[p[j]]-i*(j-1));
		}
	}
	
	rep2(i,1,601){
		rep(j,N)ans[i]=max(ans[i],c[j]%i);
	}
	
	rep(i,Q){
		int q;
		cin>>q;
		cout<<ans[q]<<endl;
	}
}

Measured memory_bytes: 3564
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>

#define MIN(x,y) (((x)<(y))?(x):(y))
#define MAX(x,y) (((x)>(y))?(x):(y))

int x[50],y[50];
int N,K;

long long calc(int p0,int p1,int p2,int p3);

int main(void){
  int j,i[4];
  long long S=LLONG_MAX,ans;
  scanf("%d%d",&N,&K);
  for(j=0;j<N;j++) scanf("%d%d",&x[j],&y[j]);
  for(i[0]=0;i[0]<N;i[0]++){
    for(i[1]=i[0];i[1]<N;i[1]++){
      for(i[2]=i[1];i[2]<N;i[2]++){
	for(i[3]=i[2];i[3]<N;i[3]++){
	  ans=calc(i[0],i[1],i[2],i[3]);
	  if(S>ans) S=ans;
	}
      }
    }
  }
  printf("%Ld\n",S);
  return 0;
}

long long calc(int p0,int p1,int p2,int p3){
  int xmin,xmax,ymin,ymax;
  int i,j,k=0;
  xmin=MIN(MIN(x[p0],x[p1]),MIN(x[p2],x[p3]));
  xmax=MAX(MAX(x[p0],x[p1]),MAX(x[p2],x[p3]));
  ymin=MIN(MIN(y[p0],y[p1]),MIN(y[p2],y[p3]));
  ymax=MAX(MAX(y[p0],y[p1]),MAX(y[p2],y[p3]));

  for(i=0;i<N;i++)
    if(xmin<=x[i] && x[i]<=xmax && ymin<=y[i] && y[i]<=ymax) k++;

  if(k<K) return LLONG_MAX;
  return (long long)(xmax-xmin)*(long long)(ymax-ymin);  
}


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

int main(){
    int n;
    cin >> n;
    string k = to_string(n);
    int size = k.size()-1;
    char hon = k[size];
    int j = 0;
    j = (int)(hon - '0');
    if (j == 2 || j == 5 || j == 4 || j == 7 || j == 9) cout << "hon" << endl;
    else if (j == 0 || j == 1 || j == 6 || j == 8) cout << "pon" << endl;
    else cout << "bon" << endl;
    return 0;
}   

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

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb puah_back

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

int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(){
    int a, b, c; cin >> a >> b >> c;
    cout << max(0, c - (a-b)) << endl;
}

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

int main() {
    int N, K;
    string S;
    cin >> N >> K >> S;

    int ans = 0;
    int pre = S[0] - '0';
    vector<int> res = {};

    int cou = 1;
    for (int i = 1; i < N; i++) {
        if (S[i] - '0' != pre) {
            res.push_back(cou);
            cou = 1;
            pre = S[i] - '0';
        }
        else cou++;
    }
    res.push_back(cou);

    for (int i = 1; i < res.size(); i++) res[i] += res[i - 1];
    res.insert(res.begin(), 0);

    if (S[0] - '0' == 0) {
        if (res.size() <= 2 * K) ans = N;
        else {
            ans = res[2 * K] - res[0];
            for (int i = 2 * K; i < res.size(); i += 2) {
                ans = max(ans, res[i] - res[i - 2 * K - 1]);
            }
            if (res.size() % 2 == 0) ans = max(ans, res[res.size() - 1] - res[res.size() - 1 - 2 * K]);
        }
    }
    else {
        if (res.size() <= 2 * K + 1) ans = N;
        else {
            for (int i = 2 * K + 1; i < res.size(); i += 2) {
                ans = max(ans, res[i] - res[i - 2 * K - 1]);
            }
            if (res.size() % 2 == 1) ans = max(ans, res[res.size() - 1] - res[res.size() - 1 - 2 * K]);
        }
    }
    cout << ans << endl;
}

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

int main(){
    int a,b;
    cin >> a;
    int x;
    int y = -999999999;
    for(int i = 0;i < a;i++){
        cin >> b;
        if(i == 0){
            x = b;
            continue;
        }
        y = max(y,b - x);
        x = min(x,b);
    }
    cout << y << endl;
}


Measured memory_bytes: 3124
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <sstream>
#include <math.h>
#include <algorithm>
#include <queue>
using namespace std;
//for (int i = 0; i < N; i++){}
//for (int i = 0; i < N; i++){}

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

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

    int maxs = H[0];

    int res=1;
    for (int i = 1; i < N; i++){
//        cout << H[i] << "-" << maxs << endl;
        if(H[i] >= maxs){
            res++;
        }
        maxs = max(maxs, H[i]);
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const ll inf = 1e18;

// union-find
vint par;
vint depth;

void init (int n) {
    rep(i,n) {
        par[i] = i;
        depth[i] = 0;
    }
}

int find(int x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (depth[x] < depth[y]) par[x] = y;
    else {
        par[y] = x;
        if (depth[x] == depth[y]) depth[x]++;
    }
}

bool same(int x, int y) {return find(x) == find(y);}

int main() {
    int n, m;
    cin >> n >> m;
    par.resize(n);
    depth.resize(n);
    vint a(m), b(m);
    init(n);
    int ct = 0;
    rep(i,m) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        a[i] = x; b[i] = y;
    }
    rep(i,m) {
        rep(j,m) {
            if (i == j) continue;
            unite(a[j],b[j]);
        }
        if (!same(a[i],b[i])) ct++;
        init(n);
    }
    cout << ct << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#define int int64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
using namespace std;

int func(int b, int n) {
	if (n < b)return n;
	return func(b, n / b) + (n % b);
}

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

	int n, s;
	cin >> n >> s;

	if (n < s) {
		cout << -1 << endl;
		return 0;
	}
	if (n == s) {//nをn+1進法1桁で表すとnになり、sに一致する
		cout << n + 1 << endl;
		return 0;
	}

	set<int>answer;

	//3桁以上になるようなbを全探索する。
	for (int b = 2; b * b <= n; b++)if (func(b, n) == s)answer.insert(b);

	//これ以降は、2桁で表せるかについてのみ考える。
	//nをb進法2桁で表すとPQ（ただしP<b,Q<b）になるとすると、
	//b*P+Q==n
	//P+Q==S
	//が成り立つ必要がある。

	for (int P = 1; P * P < n && P <= s; P++) {
		int Q = s - P;
		if ((n - Q) % P == 0)
		{
			int b = (n - Q) / P;
			if(P < b && Q < b)answer.insert(b);
		}
	}
	if (!answer.empty()) {
		cout << *answer.begin() << endl;
		return 0;
	}
	cout << -1 << endl;
}

Measured memory_bytes: 256
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N,ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;

int main() {
	int x, y, z; cin >> x >> y >> z;
	printf("%d %d %d", z, x, y);
}

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

int main(void){
	int N, M, X, Y;
	int lx = -101, sy = 101;
	cin >> N >> M >> X >> Y;
	vector<int> x = vector<int>(N, 0);
	vector<int> y = vector<int>(M, 0);
	for(int cnt = 0; cnt < N; cnt++){
		cin >> x[cnt];
		if(lx < x[cnt]) lx = x[cnt];

	}
	for(int cnt = 0; cnt < M; cnt++){
		cin >> y[cnt];
		if(sy > y[cnt]) sy = y[cnt];
	}
	if(lx < sy &&  X < sy && Y > lx ) cout << "No War" << endl;
	else cout << "War" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MOD=1000000007;
int main(){
  string S;cin>>S;long N=S.length();
  vector<vector<long>>DP(N,vector<long>(13,0));
  //左からi桁埋めた時にあまりがjである個数
  for(long i=0;i<N;i++){
    if(S[i]=='?'){
      for(long x=0;x<10;x++){ 
        if(i==0)DP[i][x%13]+=1;
        else for(int j=0;j<13;j++){
          DP[i][(10*j+x)%13]=(DP[i][(10*j+x)%13]+DP[i-1][j])%MOD;
        }
      }
    }
    else{
      long x=(int)S[i]-48;
      if(i==0)DP[i][x%13]+=1;
      else for(int j=0;j<13;j++){
        DP[i][(10*j+x)%13]=(DP[i][(10*j+x)%13]+DP[i-1][j])%MOD;
      }
    }
  }
  cout<<DP[N-1][5];
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
#define int long long
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, r, l) for (int i = r; i >= l; i--)
#define IMAX 0x3f3f3f3f
#define LLMAX 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
typedef double db;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}

ll a,b,n;

signed main() {
  a = read(), b = read(), n = read();
  printf("%lld\n", a * std::min((b - 1), n) / b);
  return 0;
}


Measured memory_bytes: 3764
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using System.Threading.Tasks;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int[] X = new int[N];
        int[] Y = new int[N];
        int[] T = new int[N];

        for (int i = 0; i < N; i++)
        {
            T[i] = cin.nextInt();
            X[i] = cin.nextInt();
            Y[i] = cin.nextInt();
        }

        int preT = 0;
        int preX = 0;
        int preY = 0;
        for (int i = 0; i < N; i++)
        {
            int Time = T[i] - preT;
            int Need = Math.Abs(X[i] - preX) + Math.Abs(Y[i] - preY);
            if(Time < Need || (Time-Need)%2 == 1)
            {
                Console.WriteLine("No");
                return;
            }
        }

        Console.WriteLine("Yes");
    }
    
}




class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}



Measured memory_bytes: 14156
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n,a,b=parseMap(split(readline()))
    println(max((n-1)b+a-(b+(n-1)a)+1,0))
end
main()

Measured memory_bytes: 110092