akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
 
# 整数の入力
n = int(input())
k = int(input())
x = int(input())
y = int(input())

# 計算
sum = 0
for num in range(n) :
    if num <= k-1 :
        sum += x
    else :
        sum += y

# 出力
print(sum)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

#define int long long 

signed main() {
  string s;
  cin >> s;
  int cnt = 0;
  int ans = 0;

  for(int i = 0;i < s.size();i++) {
    if(s[i] == 'W') {
      ans += i - cnt;
      cnt++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1152
#include<iostream>
using namespace std;
int i,n;
long long s,l,c1,c2,a[200005];
long long ab(long long a,long long b)
{
	if(a>b)return a-b;
	return b-a;
}
int main(){
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>a[i];
		s+=a[i];
	}
	s-=a[1];
	c1=ab(s,a[1]);
	l=a[1];
	for(i=2;i<n;i++){
		l+=a[i];
		s-=a[i];
		c2=ab(l,s);
		if(c2<c1)c1=c2;
	}
	cout<<c1;
}

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

long long Gcd(long long m, long long n){
	long long temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

int main(){
  long long A, B, C, D, E, F, G, maxSp, minMt, tmp, result;
  cin >> A >> B >> C >> D;
  result = 0;
  E = max(C, D);
  F = min(C, D);

  
  maxSp = Gcd(E, F);
  minMt = C * D / maxSp;


  result = B-A+1 - (B/C - (A-1)/C) - (B/D - (A-1)/D) + (B/minMt - (A-1)/minMt);
  cout << result << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	s := fmt.Sprint(n)
	for i := 0; i < len(s); i++ {
		if s[i] == '9' {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}


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


int main() {
	
	int N, l, inf=100000000;
	cin >> N >> l;
	for(int i=1; i<=N; i++){
		if(abs(inf)>abs(l+i-1)) inf = l+i-1;
	}
	cout << N*(l-1) + N*(N+1)/2 -inf << endl;
	
	
	return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define show(x) cerr << #x << " " << x << endl

typedef long long ll;
typedef unsigned long long ull;

constexpr const int INT_INF=0x3f3f3f3f; // 1061109567
constexpr const ll LL_INF=0x3f3f3f3f3f3f3f3f; // 4557430888798830399

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

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

// INT
#define GCD(a, b) __gcd(a, b)
template <typename T> T LCM(T a, T b) {return a / GCD(a, b) * b;}
template <typename T> T EXTGCD(T a, T b, T& x, T& y) {
    T d = a;
    if (b != 0) {d=EXTGCD(b,a%b,y,x);y-=(a/b)*x;}
    else x=1,y=0;
    return d;
}
template <typename T> bool is_prime(T a) {
    for(int i=2;i*i<=a;i++)if(a%i==0)return 1;
    return 0;
}

// MOD
const ll MOD = 1000000000 + 7;
#define add(a, b) ((a % MOD) + (b % MOD)) % MOD
#define mul(a, b) ((a % MOD) * (b % MOD)) % MOD
#define sub(a, b) ((a % MOD) + MOD - (b % MOD)) % MOD
template <typename T> T mod_inverse(T a, T mod, bool prime){ // if mod is prime, "prime" is true.
    if(prime){
        T tmp=mod-2,now=a,res=1;while(tmp){if(tmp&1)res=mul(res,now);now=mul(now,now);tmp>>=1;}
        return res;
    }else{T x,y;EXTGCD(a,mod,x,y);return (mod+x%mod)%mod;}
}
#define divide(a, b) ((a % MOD) * (mod_inverse(b, MOD, true))) % MOD

//LLの数値をつかう時は最後にLをつける癖をつけよう
//
//  　　┓　　　┏
//  　＊┗┓　┏┛
//  　　　┫　┣　＊
//  　┏┳┻━┻┳┓
//  　┗┫　　　┣┛
//  ＊　┣　　━┃　＊        Merry Christmas!!
//  　┏┛　　〃┃
//  　┃●　　　┣━┳┓
//  　┗┻┳━━┛　┣┛
//  　＊　┃┏┓┣┓┃
//WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW

string s;
ll a[30];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    FILE *stream1;
    //FILE *stream2;
    stream1 = freopen("/Users/aim_cpo/CLionProjects/competitive/in.txt", "r", stdin);
    //stream2 = freopen("out.txt", "w", stdout);
    if (stream1 == nullptr) return 0;
    //if (stream2 == NULL) return 0;
#endif
    cin >> s;
    ll n = (ll)s.size();
    for (int i = 0; i < n; i++) {
        a[s[i] - 'a']++;
    }
    ll sum = n * (n + 1) / 2L - n;
    for (int i = 0; i < 30; i++) {
        if (a[i] < 2) continue;
        sum -= a[i] * (a[i] - 1) / 2L;
    }
    cout << sum + 1L << endl;
#ifdef  LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
#endif
    return 0;
}

Measured memory_bytes: 720
def solve():
    H,N = map(int,input().split())
    ap = []
    mp = []

    for _ in range(N):
        a,b = map(int,input().split())
        ap.append(a)
        mp.append(b)
    
    ap_max = max(ap)
    
    dp = [[float('inf')] * (H+ap_max+1) for _ in range(N+1)]
    for i in range(N+1):
        dp[i][0] = 0
    
    for i in range(N):
        for sum_h in range(H+ap_max+1):
            if sum_h - ap[i] >= 0:
                dp[i+1][sum_h] = min(dp[i][sum_h-ap[i]] + mp[i], dp[i][sum_h])
                dp[i+1][sum_h] = min(dp[i+1][sum_h-ap[i]] + mp[i], dp[i][sum_h])
            dp[i+1][sum_h] = min(dp[i+1][sum_h], dp[i][sum_h])
    
    ans = float('inf')
    for sum_h in range(H, H+ap_max+1):
        ans = min(ans,dp[N][sum_h])

    print(ans)

if __name__ == '__main__':
    solve()

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

class UnionFind {
public:
    vector<LL> parent;
    vector<LL> member;

    UnionFind(LL N) {
        parent.resize(N);
        REP(i, N) {
            parent[i] = i;
        }
        member.resize(N, 1);
    }

    int root(LL x) {
        if(x == parent[x]) {
            return x;
        }
        return parent[x] = root(parent[x]);
    }

    bool same(LL x, LL y) {
        return root(x) == root(y);
    }

    LL size(LL x) {
        return member[root(x)];
    }

    void unite(LL x, LL y) {
        if(root(x) == root(y)) {
            return;
        }
        member[root(y)] += member[root(x)];
        parent[root(x)] = root(y);
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    UnionFind uf(N + 1);
    REP(i, M) {
        int x, y, z;
        cin >> x >> y >> z;
        uf.unite(x, y);
    }
    map<int, bool> dic;
    int res = 0;
    FOR(i, 1, N + 1) {
        int r = uf.root(i);
        if(!dic[r]) {
            dic[r] = true;
            res++;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 6528
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int a,b,c,x,ans;
int main()
{
    ans = 0;
    cin>>a>>b>>c>>x;
    for (int i = 0 ; i <= a; i++)
        for (int j = 0; j <= b; j++)
            for (int k = 0; k <= c; k++)
                if(i * 500 + j * 100 + k * 50 == x)
                    ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
public class Main{
  
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    
    String S = sc.next();
    String ans;
    Pattern p1 = Pattern.compile("^k.*eyence$");
    Pattern p2 = Pattern.compile("^ke.*yence$");
    Pattern p3 = Pattern.compile("^key.*ence$");
    Pattern p4 = Pattern.compile("^keye.*nce$");
    Pattern p5 = Pattern.compile("^keyen.*ce$");
    Pattern p6 = Pattern.compile("^keyenc.*e$");
    Pattern p7 = Pattern.compile(" *.keyence$");
    Pattern p8 = Pattern.compile("^keyence.* ");
    Matcher m1 = p1.matcher(S);
    Matcher m2 = p2.matcher(S);
    Matcher m3 = p3.matcher(S);
    Matcher m4 = p4.matcher(S);
    Matcher m5 = p5.matcher(S);
    Matcher m6 = p6.matcher(S);
    Matcher m7 = p7.matcher(S);
    Matcher m8 = p8.matcher(S);
    
      if(m1.find() == true){
          System.out.println("YES");
          return;
      }else{
          ans = "NO";
      }
         
      if(m2.find() == true){
          System.out.println("YES");
          return;
      }else{
          ans = "NO";
      }
         
      if(m3.find() == true){
          System.out.println("YES");
          return;
      }else{
          ans = "NO";
      }
         
      if(m4.find() == true){
          System.out.println("YES");
          return;
      }else{
         ans = "NO";
      }
         
      if(m5.find() == true){
          System.out.println("YES");
          return;
      }else{
          ans = "NO";
      }
         
      if(m6.find() == true){
          System.out.println("YES");
          return;
      }else{
         ans = "NO";
      }
      
       if(m7.find() == true){
          System.out.println("YES");
          return;
      }else{
         ans = "NO";
      }
      
       if(m8.find() == true){
          System.out.println("YES");
          return;
      }else{
         ans = "NO";
      }
    
      System.out.println(ans);
    
  }  
}

Measured memory_bytes: 35724
#include <iostream>
using namespace std;
int main(void){
    long long n,a,b;
    cin>>n>>a>>b;
    long long mi=a*(n-1)+b,ma=a+b*(n-1);
    if(a>b||(n==1&&a!=b))cout<<0<<endl;
    else if(a==b)cout<<1<<endl;
    else cout<<ma-mi+1<<endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
#include <vector>
using namespace std;
int test[101];
int main() {
	long long n, a,ans = 0; cin >> n;
	for (int h = 0; h < n; h++) {
		cin >> a; test[h] = a;
	}
	for (int h = 0; h < n; h++) {
		if (test[h] > test[h + 1]) {
			ans += test[h] - test[h + 1];
		}
	}
	cout << ans << endl;
	cin >> n;
}

Measured memory_bytes: 256
public class Main{
  static int infi = 100;
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int[] a;
    int n, i;
    long sum;

    for(;;){
      n = sc.nextInt();
      if(n == 0)break;
      a = new int[n];
      for(i = 0;i < n;i++)a[i] = sc.nextInt();
      mergesort(a, 0, n);
      sum = 0;
      for(i = 0;i < n - 1;i++)sum += a[i] * (n - 1 - i);
      out.println(sum);
      for(i = 0;i < n;i++)a[i] = 0;
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
  private static void mergesort(int[] a, int l, int r){
    int m, c;
    if(l + 1 >= r)return;
    else{
      m = (l + r) / 2;
      mergesort(a, l, m);
      mergesort(a, m, r);
      merge(a, l, m, r);
      return;
    }
  }
  private static void merge(int[] a, int l, int m, int r){
    int nl, nr, count;
    int i, j, k;
    int[] al, ar;

    nl = m - l; nr = r - m;
    al = new int[nl + 1]; ar = new int[nr + 1];
    for(i = 0;i < nl;i++){
      al[i] = a[l + i];
    }
    for(i = 0;i < nr;i++){
      ar[i] = a[m + i];
    }
    al[nl] = infi; ar[nr] = infi;

    i = 0;j = 0;count = 0;

    for(k = l;k < r;k++){
      if(al[i] < ar[j])a[k] = al[i++];
      else a[k] = ar[j++];
    }
    return;
  }

}

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

g1 = [1, 1] #元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
mod = 10**9+7
for i in range( 2, n + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

for i in range(1,k+1):
    c = cmb(n-k+1,i)
    x = cmb(k-1,i-1)
    print(c*x%mod)



Measured memory_bytes: 74656
import java.util.*;
public class Main {
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args) {
 
    int t = kbd.nextInt();
    boolean[][] card = new boolean[13][4];
        //0:S 1:H 2:C 3:D
    int i;
    int j;
    for(i=0; i<t; i++){
        String m = kbd.next();
        int n = kbd.nextInt();
        card[n-1][mark(m)] = true;
    }
 
    for(j=0; j<4; j++){
        for(i=0; i<13; i++){
        if(card[i][j]==false)
            System.out.println(mark(j)+" "+(i+1));
        }
    }
    }
    static int mark(String m){
    if(m.equals("S")) return 0;
    if(m.equals("H")) return 1;
    if(m.equals("C")) return 2;
    return 3;
    }
    static String mark(int j){
    if(j==0) return "S";
    if(j==1) return "H";
    if(j==2) return "C";
    return "D";
    }
}

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

#define rep(i,n)  for(int i=0;i<n;++i)
#define per(i,n)  for(int i=n-1;i>=0;--i)
#define sc1(a)  scanf("%d",&a)
#define sc2(a,b)  scanf("%d %d",&a,&b)
#define sc3(a,b,c)  scanf("%d %d %d",&a,&b,&c)
#define sl1(a)  scanf("%lld",&a)
#define sl2(a,b)  scanf("%lld %lld",&a,&b)
#define sl3(a,b,c)  scanf("%lld %lld %lld",&a,&b,&c)
#define PI 3.1415926535897932


int main(){
    for(;;) {
        char a[201],b[201];
        int m,l;
        scanf("%s",a);
        if (a[0]=='-') break;
        sc1(m);
        strcpy(b,a);
        l=strlen(a);

        rep(i,m) {
            int h;
            sc1(h);
            for(int j=h;j<l;j++) {
                b[j-h]=a[j];
            }
            for(int j=l-h;j<l;j++) {
                b[j]=a[j+h-l];
            }
            strcpy(a,b);
        }
        printf("%s\n",b);
    }
    return 0;
}



Measured memory_bytes: 3148
from collections import defaultdict, deque
def main():
  N, M, *L = map(int, open(0).read().split())
  dic = defaultdict(list)
  par =  [None]*N
  cnt = [0]*(N+1)
  for a,b in zip(*[iter(L)]*2):
    dic[a] += [b]
    cnt[b] += 1

  for i in range(1,N+1):
    if cnt[i]==0:
      q = deque([i])
      par[i-1] = '0'
      break
  
  while q:
    m = q.popleft()
    for c in dic[m]:
      cnt[c] -= 1
      if cnt[c]==0:
        par[c-1] = str(m)
        q.append(c)

  ans = '\n'.join(par)
  print(ans)
  
if __name__== '__main__':
  main()


Measured memory_bytes: 37228
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(),i.end()
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyz"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;


int main() {
  ll N,D;
  cin>>N>>D;
  ll x[N][D];
  rep(i,N){
    rep(j,D){
      cin>>x[i][j];
    }
  }
  ll ans=0;
  ll dist=0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      for(int k=0;k<D;k++){
        dist+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
      }
      for(int k=1;k<200;k++){
        if(k*k==dist){
          ans++;
          dist=0;
          break;
        }
      }
      dist=0;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <cmath>
#include <string> 
#include <cstdint>
#include <cstring>
#include <queue> 
#include <climits>
#include <unordered_map>
//https://qiita.com/ofutonfuton/items/92b1a6f4a7775f00b6ae
 
using namespace std;
typedef long long ll;
std::unordered_map<ll, std::vector<pair<ll,ll>>> connection;
ll N;
int result = 0;

ll getConnectionCost(ll a, ll b){
    for(pair<ll,ll> pair : connection[a]){
        if(pair.first == b){
            return pair.second;
        }
    }
    return -1;
}

int main()
{
    cin >> N;
    ll* a = new ll[N];
    ll* b = new ll[N];
    ll* c = new ll[N];

    for(ll i = 0; i < N - 1; i ++){
        cin >> a[i] >> b[i] >> c[i];
        a[i] --;
        b[i] --;
        connection[a[i]].push_back(make_pair(b[i], c[i]));
        connection[b[i]].push_back(make_pair(a[i], c[i]));
    }

    //ダイクストラ
    priority_queue<pair<ll,ll> >pq;
    // weight[v]に始点sからvまでの最短コストを保存する
    ll weight[N];
    // 訪問状態を記録
    bool searched[N];
    for(ll i = 0; i < N; i ++){
        searched[i] = false;
        weight[i] = LLONG_MAX;
    }

    ll Q, K;
    ll* x;
    ll* y;
    cin >> Q >> K;
    K --;
    x = new ll[Q];
    y = new ll[Q];
    for(ll i = 0; i < Q; i ++){
        cin >> x[i] >> y[i];
        x[i] --; 
        y[i] --;
    }

    pq.push(make_pair(0, K));

    // priority_queue dicstra
    while(!pq.empty()){
        pair<ll,ll> first = pq.top();
        pq.pop();
        ll node = first.second;
        ll u = -first.first;
        //cout << node << "/" << u << endl;
        searched[node] = true;

        for(pair<ll,ll> target : connection[node]){
            ll targetNode = target.first;
            ll targetCost = target.second;
            if(searched[targetNode]) continue;
            if(targetCost + u < weight[targetNode]){
                //cout << i << "/" << node << ":" << targetCost << "," << u << endl;
                weight[targetNode] = targetCost + u;
                pair<ll,ll> newPair = make_pair(weight[targetNode] * -1, targetNode);
                pq.push(newPair);
            }
        }
    }

    for(ll i = 0; i < Q; i ++){
        cout << (weight[x[i]] + weight[y[i]]) << endl;
    }

    
    return 0;
}

Measured memory_bytes: 19364
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        str: chars,
        num: usize,
    }

    let mut index = None;
    for (i, s) in str.iter().enumerate() {
        if *s != '1' {
            index = Some(i);
            break;
        }
    }
    if let Some(n) = index {
        //println!("n : {}, num : {}", n, num);
        if num < n+1 {
            println!("{}", 1);
        } else {
            println!("{}", str[n]);
        } 
    } else {
        println!("{}", str[0]);
    }
}


Measured memory_bytes: 4352
/******************************************
* AUTHOR : AMAN SAXENA *
* Nick : blue-meth *
* "There's some good in this world, and it's worth fighting for." *
* INSTITUTION : KIET Group of Institutions *
******************************************/
#include <bits/stdc++.h>

const long long MODULO=1000000007;
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define FOR1(i,a,n) for(int i=a;i<=n;i++)
#define FOR2(i,a,n) for(int i=a;i>=n;i--)
#define pb push_back
#define mp make_pair
#define ll long long 
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pi 3.14159265359

using namespace std;

ll amanpower(ll a, ll b) {
    ll r = 1;
    while (b > 0) 
    {
        if (b & 1) r = r * a;
        a = a * a;
        b >>= 1;
    }
    return r;
}

ll amanlcm(ll a, ll b)
{
     return a*(b/__gcd(a,b));
}


//********* CODE START *********


void solve()
{
    int n;
    cin >> n;

    if(n>=400 && n<=599)
    {
        cout << 8;
    }
    else if(n>=600 && n<=799)
    {
        cout << 7;
    }
    else if(n>=800 && n<=999)
    {
        cout << 6;
    }
    else if(n>=1000 && n<=1199)
    {
        cout << 5;
    }
    else if(n>=1200 && n<=1399)
    {
        cout << 4;
    }
    else if(n>=1400 && n<=1599)
    {
        cout << 3;
    }
    else if(n>=1600 && n<=1799)
    {
        cout << 2;
    }
    else if(n>=1800 && n<=1999)
    {
        cout << 1;
    }

}

void test()
{
    int t;
    cin>>t;
    while(t--) //for(int j=1;j<=t;j++) cout << "Case #" << j << ": ";
    {
        solve();
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //#endif
    
    // test();
    solve();

    
    return 0;
}

Measured memory_bytes: 3644
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define alli(a, n, k) (a+k),(a+n+k)
#define REP(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)
#define REPI(i, a, b, k) for(__typeof(a) i = a;i > b;i -= k)
#define REPITER(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)

#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
template<class T> inline T gcd(T x, T y) { if (!y) return x; return gcd(y, x%y);}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector< pair<int, int> > VPII;
typedef vector< pair<int, PII > > VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;
int main(int argc, char* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int arr[n+1][3];
    for(int i=0;i<n;++i)
    for(int j=0;j<3;++j)
    cin>>arr[i][j];
    int dp[n+1][3];
    for(int i=0;i<3;++i)
    dp[0][i]=arr[0][i];
    for(int i=1;i<n;++i)
    {
        dp[i][0]=arr[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=arr[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=arr[i][2]+max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl


int main() {
    string S;  cin >> S;

    int cnt = 0;
    // 010101...
    if (S[0] == '0') {
        rep(i, S.size()) {
            if (i % 2 == 0) {
                if (S[i] == '1') ++cnt;
            } else {
                if (S[i] == '0') ++cnt;
            }
        }
    // 101010...
    } else {
        rep(i, S.size()) {
            if (i % 2 == 0) {
                if (S[i] == '0') ++cnt;
            } else {
                if (S[i] == '1') ++cnt;
            }
        }
    }

    print(cnt);
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
/************************************************/
using namespace std;
long long n;
vector<pair<ll,ll> > v;
int main(){
	cin>>n;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0)
		v.pb(mp(i,(n/i)));
	}
	long long ans=10000000000000;
	for(int i=0;i<sz(v);i++){
		ll x=v[i].fr,y=v[i].se;
		ans=min(ans,x-1+y-1);
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int min = 1000, cnt = 0, i, n, k, m, u;
    char S[1000], T[1000];
    scanf("%s", S);
    scanf("%s", T);
    
    /* 文字数をカウント */
    for(i=0; S[i]!='\0'; ++i);
    /* 文字数を出力 */
    //printf("入力した文字列Sは「%d」文字です。\n",i);
    
    /* 文字数をカウント */
    for(n=0; T[n]!='\0'; ++n);
    /* 文字数を出力 */
    //printf("入力した文字列Tは「%d」文字です。\n",n);

    for(m = 0;m<=i-n;m++){
        for(k = 0;k<n;k++){
            if(S[m+k] == T[k]){
                //printf("s[%d]%cはt[%d]%cと一致します。\n",m+k , S[m+k], k, T[k]);
            } else{
                //printf("s[%d]%cはt[%d]%cと一致しません。\n",m+k, S[m+k], k, T[k]);
                cnt++;
            }
        }
        if(cnt<=min)
            min = cnt;
        cnt = 0;
    }
    //printf("cnt = %d\n", cnt);
    printf("%d\n", min);
}




Measured memory_bytes: 1724
using System;

namespace abc140
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] a = Console.ReadLine().Split(' ');
            string[] b = Console.ReadLine().Split(' ');
            string[] c = Console.ReadLine().Split(' ');
            int ans = 0;
            int tmp = 0;
            for(int i = 0; i<N; i++){
                ans += int.Parse(b[int.Parse(a[i]) - 1]);
                if(tmp != 0 && (tmp == int.Parse(a[i]))){
                    ans += int.Parse(c[int.Parse(a[i]) - 2]);
                }
                tmp = int.Parse(a[i]) + 1;
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>

using namespace std;

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

int main() {
	int a[100];
	int n;
	
	cin >> n;
	REP(i, n) scanf("%d", &a[i]);
	
	int ans = INF;
	
	FOR(i, -100, 101) {
		int now = 0;
		REP(j, n) now += (i - a[j]) * (i - a[j]);
		ans = min(ans, now);
	}
	
	cout << ans << endl;
	return 0;
}

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

int main(){
  string S;
  cin >> S;
  vector<int> retu;
  
  for(int i=0; i<S.size(); i++){
    if(S.at(i) == '0'){
      retu.push_back(0);
    }
    else if(S.at(i) == '1'){
      retu.push_back(1);
    }
    else if(S.at(i) == 'B' && retu.size() != 0){
      retu.pop_back();
    }
    else continue;
  }
  for(int i=0; i<retu.size(); i++){
    cout << retu.at(i);
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define ff first
#define ss second
#define setbits(x)          __builtin_popcountll(x)
#define lp(a,n) for(ll i=a; i<n; i++)
#define lpi(a,n) for(int i=a; i<n; i++)
#define w(t) int t; cin>>t; while(t--)
#define vi vector<int> 
#define vll vector<ll>
#define pll pair<ll, ll>
#define pii pair<int, int>
#define inf 1e9
#define LB lower_bound
#define UB upper_bound
const int mod = 1000000007;
using namespace std;
ll gcd(ll a,ll b){
    if(a==0)return b;
    return gcd(b%a,a);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}

int prime[100007];
void SieveOfEratosthenes(int n) 
{ 
    memset(prime, -1, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
         
        if (prime[p] == -1) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = p; 
        } 
    } 
    
} 
int lps(string s){
    int len = 0;
    int n = s.length();
    int dp[n];
    dp[0] = 0;
    for(int i=1; i<n; i++){
        if(s[i] == s[len]){
            len++;
            dp[i] = len;
            continue;
        }
        if(len!=0){
            len = dp[len-1];
            i--;
            continue;
        }
        dp[i]=0;
    }
    return dp[n-1];
}
 
ll power(unsigned ll x,unsigned  ll y) 
{ 
    ll res = 1;     
    while (y > 0) 
    { 
        if (y & 1) 
            res = res*x; 
   
        y = y>>1;
        x = x*x;  
    } 
    return res; 
}

//to calculate p1^x  *  p2^x2  *p3^x3 ----------
//i.e. prime factorization and store pi and xi in vector 
vector<pair<ll, ll>> pFactor;

void factorize(long long n) 
{ 
    int count = 0; 
  
    // count the number of times 2 divides  
    while (!(n % 2)) { 
        n >>= 1; // equivalent to n=n/2; 
        count++; 
    } 
  
    // if 2 divides it 
    if (count) 
        pFactor.pb({2,count}); 
  
    // check for all the possible numbers that can  
    // divide it 
    for (long long i = 3; i <= sqrt(n); i += 2) { 
        count = 0; 
        while (n % i == 0) { 
            count++; 
            n = n / i; 
        } 
        if (count) 
            pFactor.pb({i,count});
    } 
  
    // if n at the end is a prime number. 
    if (n > 2) 
        pFactor.pb({n,1}); 
} 



int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
   int n;
   cin>>n;
   int a[n];
   lp(0,n){
       cin>>a[i];
   }
   int ans=0;
   lp(0,n){
       if((i+1)%2!=0 and a[i]%2!=0){
           ans++;
       }
   }
   cout<<ans;
}


Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n + 1];
        int b[] = new int[n + 1];
        int c[] = new int[n + 1];
        for (int i = 1; i < n + 1; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            c[i] = sc.nextInt();
        }
        // 0 a 1 b 2 c
        int dp[][] = new int[n + 1][3];
        dp[1][0] = a[1];
        dp[1][1] = b[1];
        dp[1][2] = c[1];
        for (int i = 2; i < n + 1; i++) {
            dp[i][0] = Math.max(dp[i - 1][1] + a[i], dp[i - 1][2] + a[i]);
            dp[i][1] = Math.max(dp[i - 1][0] + b[i], dp[i - 1][2] + b[i]);
            dp[i][2] = Math.max(dp[i - 1][0] + c[i], dp[i - 1][1] + c[i]);
        }
        int max = Math.max(dp[n][0], dp[n][1]);
        max = Math.max(max, dp[n][2]);
        System.out.println(max);
    }
}

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

#define pb push_back
#define ff first
#define ss second

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

const int MAXN = 100 * 1000 + 17;

ll n, a[MAXN], ans;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 1; i < n; i++) {
		if (a[i] % 2 && a[i + 1]) {
			ans++;
			a[i]--;
			a[i + 1]--;
		}
	}
	for (int i = 1; i <= n; i++)
		ans += a[i] / 2;
	cout << ans << endl;
	return 0;
}


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

        using namespace std;

        #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        #define FOR(i,a,b) for(int i = (a); i < (b); i++)
        #define rep(i,n) FOR(i,0,n)
        #define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
        #define ITER(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
        #define FILL(a,value) memset(a, value, sizeof(a))

        #define SZ(a) (int)a.size()
        #define ALL(a) a.begin(),a.end()
        #define PB push_back
        #define MP make_pair
        #define in insert
        #define er erase
        #define fs first
        #define sc second


        typedef long long LL;
        typedef vector<int> VI;

        typedef vector<bool> VB;
        typedef vector<LL> VL;
        typedef pair<int,int> PII;
        typedef pair<LL,LL> PLL;
        typedef vector<PII> VPI;
        typedef vector<VL>VVL;
        typedef vector<VI>VVI;
        typedef vector<string>VS;

        typedef vector<vector<PII>> VVPI;
        typedef vector<vector<PLL>> VVPL;



        const double PI = acos(-1.0);
        const int INF = 1000 * 1000 * 1000 + 7;
        const LL LINF = INF * (LL)INF;

        const int MAX = 305;

        const int MAS = 1e5 + 10 ;
        const int MOD = 1000 * 1000 * 1000 + 7;
        const double EPS = 1e-8;


        vector<vector<int >> g(MAS);


        vector<int>dp(MAS);

         pair<LL,LL > dfs(int v,int p =-1)
         {
             LL all_white = 1;
             LL black  = 0 ;
             rep(i,g[v].size())
             {

                 int to =g[v][i];
                 if(to ==  p )continue;
                 pair<LL,LL> p = dfs(to,v);
                 LL oldall_white = all_white;
                 all_white = (all_white * p.second)%MOD;
                 black  = ((oldall_white * p.first) %MOD + (black * (p.first + p.second))%MOD)%MOD;
             }
             return {all_white ,(all_white + black)%MOD};
         }
        int main() {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
            //  freopen("skateboard.in","r",stdin);
            //  freopen("skateboard.out","w",stdout);
            int n;
            cin >> n;
            rep(i,n -1 )
            {
                int x,y;
                cin >> x >> y;
                --x,--y;
                g[x].PB(y);
                g[y].PB(x);
            }
            pair<LL,LL> ans  = dfs(0);
            cout << (ans.first + ans.second)%MOD;
        }

Measured memory_bytes: 13056
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <utility>
#define llint long long
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;

struct edge{
	llint to, id;
	edge(llint a, llint b){
		to = a, id = b;
	}
};

llint n, m;
llint a[100005], b[100005], d[100005];
llint l[200005], r[200005];
P p[100005];

vector<edge> G[100005];
bool used[100005];
llint parity[100005];
llint ans[200005];

bool dfs(llint v, llint id)
{
	used[v] = true;
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i].id == id) continue;
		if(used[G[v][i].to]) continue;
		dfs(G[v][i].to, G[v][i].id);
	}
	if(id == -1) return d[v] == parity[v];
	if(d[v] != parity[v]){
		ans[id] = 1;
		parity[l[id]] = (parity[l[id]]+1) % 2;
		parity[r[id]] = (parity[r[id]]+1) % 2;
	}
	return true;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	for(int i = 1; i <= n; i++){
		cin >> a[i] >> b[i];
		p[i] = P(a[i], b[i]);
	}
	sort(p+1, p+n+1);
	
	for(int i = 1; i <= n; i++) a[i] = p[i].first;
	for(int i = 1; i <= n; i++) b[i] = p[i].second;
	
	for(int i = 1; i <= m; i++){
		cin >> l[i] >> r[i];
		l[i] = lower_bound(a+1, a+n+1, l[i]) - a;
		r[i] = upper_bound(a+1, a+n+1, r[i]) - a - 1;
		r[i]++;
	}
	
	for(int i = 1; i <= n+1; i++) d[i] = (b[i-1]+b[i]) % 2;
	for(int i = 1; i <= m; i++){
		if(l[i] > r[i]) continue;
		G[l[i]].push_back(edge(r[i], i));
		G[r[i]].push_back(edge(l[i], i));
	}
	
	for(int i = 1; i <= n+1; i++){
		if(used[i]) continue;
		if(!dfs(i, -1)){
			cout << -1 << endl;
			return 0;
		}
	}
	
	vector<llint> vec;
	for(int i = 1; i <= m; i++) if(ans[i]) vec.push_back(i);
	sort(vec.begin(), vec.end());
	
	cout << vec.size() << endl;
	for(int i = 0; i < vec.size(); i++) cout << vec[i] << " ";
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 26876
/*
 * author :Sadik Hassan
 *
*/
#include "bits/stdc++.h"
using namespace std;
using   ll =          long long;
#define nl            "\n"
#define pb            push_back
#define fi            first
#define se            second
#define PI            (acos(-1.0))
#define repp(i,a,n)   for(int i=a;i<n;i++)
#define rep(i,n)      for(int i=0;i<n;i++)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
#define w(t)          int t;cin>>t;while(t--)
#define TSFL(s)       transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSFH(s)       transform(s.begin(),s.end(),s.begin(),::tolower);
#define _SAD()     	  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),cout<<fixed<<setprecision(15);
typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;
/*---------------------------------------------------------------------*/

const int N = 2e5+5;
const int MOD =(int)1e9+7;
const int INF = (int)1e9+5;
int aa[200];
int main()
{
    _SAD()
    int x,n;
    cin>>x>>n;
    if(n==0)
    {
        cout<<x<<nl;return 0;
    }
    //vi a(n);
    rep(i,n)
    {
        int pp;cin>>pp;
        aa[pp]=1;
    }
    int ans=300,sap=0;
    for(int i=-200;i<=300;i++)
    {
        if(aa[i]==0&&abs(i-x)<ans)
        {
            ans=abs(i-x);
            sap=i;
        }
    }
    cout<<sap<<nl;
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll A[100];
ll dp[101][100005];
int main() {
    init();
    ll N, K;
    cin >> N >> K;
    rep(i, N) cin >> A[i];

    ll sum = 0;
    dp[0][0] = 1;
    rep(i,N){
        sum = min(sum + A[i], K);
        rep(j, sum)(dp[i][j + 1] += dp[i][j]) %= MOD;
        rep(j,sum+1){
            if(j-A[i] <= 0)
                dp[i + 1][j] = dp[i][j];
            else
                (dp[i + 1][j] = dp[i][j] - dp[i][j - A[i] - 1] + MOD) %= MOD;
        }
    }

    cout << dp[N][K] << endl;
}

Measured memory_bytes: 79232
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
using ii = pair<int, int>;
 
void solve();
 
clock_t start_time;
double get_current_time() {
	return (double)(clock() - start_time) / CLOCKS_PER_SEC;
}
 
int main() {
	// freopen("substring.in", "r", stdin);
	// freopen("substring.out", "w", stdout);
 
	ios_base::sync_with_stdio(false);
	solve();
}
 
/* ========== actual code starts here ========== */
 
#define fi first
#define re return
#define se second
#define in insert
#define pb push_back
#define eb emplace_back
#define y1 y123123123123
#define all(x) x.begin(), x.end()
#define hash hash123s
 
#define repx(i, x, n) for (int i = x; i < (n); i++)
#define repd(i, n, d) for (int i = 0; i < (n); i += d)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepd(i, n, d) for (int i = (n) - 1; i >= 0; i -= d)
#define rep(i, n) for (int i = 0; i < (n); i++)

template<class t>
void print(t x, int end = 1){
	cout << x << (end == 1 ? "\n" : " ");
}

template<class T>
void print(const vector<T> &v, int end = 1) {
	rep(i, (int) v.size()) {
		print(v[ i ], 0);
	}
	cout << endl;
}

template<class T>
void print(const set<T> &v, int end = 1) {
	for(auto to = v.begin(); to != v.end(); to++) {
		print(*to);
	}
	cout << endl;
}

template<class T>
void print(const map<T, T> &v, int end = 1) {
	for(auto to : v) {
		print(to.fi, 0);
		cout << ": ";
		print(to.se);
	}
}

template<class t>
void errprint(t x, int end = 1){
	cerr << x << (end == 1 ? "\n" : " ");
}

#ifdef artem
	#define debug(x) x
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define debug(x)
#endif

void solve() {
	string s;
	cin >> s;
	int n = s.size();
	int p = 0, g = 0;
	int ans = 0;
	
	for(int i = 0; i < n; i++) {
		if(s[ i ] == 'p') {
			if(p + 1 <= g) {
				++p;
			} else {
				++g;
				--ans;
			}
		} else {
			if(p + 1 <= g) {
				++p;
				++ans;
			} else {
				++g;
			}
		}
	}
	print(ans);
}

Measured memory_bytes: 3720
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	p := iSScan(n)
	q := iSScan(n)
	r := make([]int, n)
	copy(r, p)
	perm := Permute(r)
	for x := n - 1; x >= 0; x-- {
		sort.SliceStable(perm, func(i, j int) bool { return perm[i][x] < perm[j][x] })
	}
	a, b := -1, -1
	for i, v := range perm {
		if fmt.Sprint(p) == fmt.Sprint(v) {
			a = i
		}
		if fmt.Sprint(q) == fmt.Sprint(v) {
			b = i
		}
	}
	fmt.Println(abs(a - b))
}
func Permute(nums []int) [][]int {
	n := factorial(len(nums))
	ret := make([][]int, 0, n)
	permute(nums, &ret)
	return ret
}

func permute(nums []int, ret *[][]int) {
	*ret = append(*ret, makeCopy(nums))
	n := len(nums)
	p := make([]int, n+1)
	for i := 0; i < n+1; i++ {
		p[i] = i
	}
	for i := 1; i < n; {
		p[i]--
		j := 0
		if i%2 == 1 {
			j = p[i]
		}

		nums[i], nums[j] = nums[j], nums[i]
		*ret = append(*ret, makeCopy(nums))
		for i = 1; p[i] == 0; i++ {
			p[i] = i
		}
	}
}

func factorial(n int) int {
	ret := 1
	for i := 2; i <= n; i++ {
		ret *= i
	}
	return ret
}

func makeCopy(nums []int) []int {
	return append([]int{}, nums...)
}


Measured memory_bytes: 12468
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    n = ni()
    a = n * (n + 1) * (n + 2) // 6
    for i in range(n-1):
        u, v = nm()
        if u > v:
            u, v = v, u
        a -= u * (n - v + 1)
    print(a)
    return

solve()


Measured memory_bytes: 9216
import sys
import itertools
import numpy as np
from collections import Counter

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

K = int(input())
S = input()


if len(S) > K:
    print(S[0:K]+'...')
    exit()
else:
    print(S)


Measured memory_bytes: 27136
import java.util.Scanner;

class Main {
	    public static void main(String[] args) {
	        Scanner sc = new Scanner(System.in);
	        int a = sc.nextInt();
	        int sec = a%60;
	        int m = a/60;
	        int min = m%60;
	        int hour = m/60;

	        System.out.println(hour+":"+min+":"+sec);
	    }
	}


Measured memory_bytes: 26180
import java.io.BufferedReader;
import java.io.InputStreamReader;

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

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int h = scanner.nextInt(); //行数
        int w = scanner.nextInt(); //列数

        String[][] picture = new String[h][w];
        for (int i=0;i<h;i++) {
        	picture[i] = scanner.next().split("");
        }

        boolean flg = true;
        for (int i =0;i<h;i++) {
        	if (flg == false) {
        		break;
        	}
        	for (int j=0;j<w;j++) {
        		if (picture[i][j].equals("#")) {
        			if (i!=0) {
        				if(picture[i-1][j].equals("#")) {
        					continue;
        				}
        			}
        			if (i!=(h-1)) {
        				if(picture[i+1][j].equals("#")) {
        					continue;
        				}
        			}
        			if (j!=0) {
        				if(picture[i][j-1].equals("#")) {
        					continue;
        				}
        			}
        			if (j!=(w-1)) {
        				if(picture[i][j+1].equals("#")) {
        					continue;
        				}
        			}
        			System.out.println("No");
        			flg = false;
        			break;
        		}
        	}
        }
        if (flg==true) {
        	System.out.println("Yes");
        }

    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}


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

class C {
    public static void main(String... args) {
        final Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        final int[] A = new int[N];
        Arrays.setAll(A, i -> sc.nextInt());
        Arrays.sort(A);
        long up = 0; {
            int i = 0;
            int j = N - 1;
            for(; j - i > 2; i++, j--)
                up += A[j] * 2 - A[i] - A[i + 1];
            if(j - i == 1) {
                up += A[j] - A[0];
            } else {
                up += A[j] - A[i] + A[i + 1] - A[0];
            }
        }
        long down = 0; {
            int i = 0;
            int j = N - 1;
            for(; j - i > 2; i++, j--)
                down += A[j] + A[j - 1] - A[i] * 2;
            if(j - i == 1) {
                down += A[N - 1] - A[i];
            } else {
                down += A[j] - A[i] + A[N - 1] - A[j - 1];
            }
        }
//        System.err.println(up + " " + down);
        System.out.println(Math.max(up, down));
    }
}
public class Main {
    public static void main(String...args) {
        C.main();
    }
}


Measured memory_bytes: 62840