akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for(int i = 0; i < H; i++){
        cin >> S[i];
    }

    vector< vector<int> > cnt(H, vector<int>(W));
    for(int i = 0; i < H; i++){
        vector<int> done(W, 0);
        for(int j = 0; j < W; j++){
            if(S[i][j] == '#'){
                continue;
            }
            if(done[j] != 0){
                continue;
            }

            int l = 0;
            while(j + l < W){
                if(S[i][j+l] == '#'){
                    break;
                }
                l++;
            }
            for(int k = 0; k < l; k++){
                cnt[i][j+k] += l;
                done[j+k] = 1;
            }
        }
    }


    for(int j = 0; j < W; j++){
        vector<int> done(H, 0);
        for(int i = 0; i < H; i++){
            if(S[i][j] == '#'){
                continue;
            }
            if(done[i] != 0){
                continue;
            }

            int l = 0;
            while(i + l < H){
                if(S[i+l][j] == '#'){
                    break;
                }
                l++;
            }
            for(int k = 0; k < l; k++){
                cnt[i+k][j] += l;
                done[i+k] = 1;
            }
        }
    }

    int ans = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            ans = max(ans, cnt[i][j]-1);
        }
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 20096
n, a, b = map(int, input().split())
ans = n // (a+b)
ans *= a
if n % (a+b) != 0:
    ans += min(a, n % (a+b))
print(ans)
'''
i = 0
r = []
for _ in range(10*100):
    for _ in range(a):
        r.append('b')
    for _ in range(b):
        r.append('r')
    
print("".join(r[0:n]))
'''

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

void gen_prime(int n, vector<int> &p) {
  vector<bool> v;
  v.resize(n + 1);
  for (auto it = v.begin(); it != v.end(); ++it) {
    *it = true;
  }
  v[0] = v[1] = false;
  for (int i = 2; i * i <= n; ++i) {
    if (!v[i]) {
      continue;
    }
    for (int j = i + i; j <= n; j += i) {
      v[j] = true;
    }
  }

  p.clear();
  for (int i = 2; i <= n; ++i) {
    if (v[i]) {
      p.push_back(i);
    }
  }
}

bool judge_prime(int n, const vector<int> &p) {
  for (auto t : p) {
    if (t * t > n) {
      break;
    }
    if (!(n % t)) {
      return false;
    }
  }
  return true;
}

int main() {
  vector<int> p;
  gen_prime(10000, p);

  int N;
  cin >> N;

  int count = 0;
  for (int i = 0; i < N; ++i) {
    int t;
    cin >> t;
    if (judge_prime(t, p)) {
      ++count;
    }
  }

  cout << count << endl;

  return 0;
}

Measured memory_bytes: 3248
s = input()
n = len(s)
c = [ord(s[i]) for i in range(n)]
k = int(input())
ind = 0
while k > 0:
    if ind == n:
        break
    if c[ind] == 97:
        ind += 1
        continue
    elif 123 - c[ind] <= k:
        k -= 123-c[ind]
        c[ind] = 97
        ind += 1
    elif 123 - c[ind] > k:
        ind += 1
        continue

if k > 0:
    k %= 26
    c[-1] += k
    if c[-1] >= 123:
        c[-1] = 97 + (123-c[-1])

print(''.join([chr(c[i]) for i in range(n)]))

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

int main() {
  int N, K;
  cin >> N >> K;
  int sum = 0;
  for (int i = 0; i < N; i++){
    int x;
    cin >> x;
    int a, b;
    a = x;
    b = K - x;
    if (a <= b)
      sum += a * 2;
    else
      sum += b * 2;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val s = sc.next
    sc.close()

    s.sliding(2).toList.count(_.distinct.length == 1) match {
      case 0 => println("Good")
      case _ => println("Bad")
    }
  }
}

Measured memory_bytes: 25424
#include<bits/stdc++.h>
  using namespace std;
  #define ll  long long int
  #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
  int main()
  {

   

    fastio; 
   string s;
   cin>>s;
   ll n=s.size();
   ll sum=0;
   for(int i=0;i<n;i++)
   {
    sum+=s[i]-'0';
   }
   if(sum%9==0)
    cout<<"Yes";
  else
    cout<<"No";


  return 0;   
  }

Measured memory_bytes: 3736
N = int(input())
S = input()     
all = S.count("R") * S.count("G") * S.count("B")
reigai = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        k = 2 * j - i
        if k > N-1:
            break
        if S[i]!=S[j] and S[i]!=S[k] and S[j]!=S[k]:
            reigai += 1
print(all - reigai)            
            
            

Measured memory_bytes: 73592
#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;
    string S, T;
    cin >> S >> T;

    rep(i,N){
        cout << S[i] << T[i] ;
    }

    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
typedef long long ll;
ll fac[2000005], inv[2000005];
ll exp(ll a, int x){
    if (x == 0) return 1ll;
    ll p = exp(a,x/2);
    p = (p*p)%mod;
    if (x&1) p = (p*a)%mod;
    return p;
}
ll C(ll n, ll k){
    return ((fac[n]*inv[n-k])%mod * inv[k])%mod;
}
ll f(int n, int s, int k){
    //printf("f(%d,%d,%d):\n",n,s,k);
    ll ret= 0;
    for (int i = 0; i <= min(k,n); i++){
        int _s = s-i;
        if (_s % 2 != 0) continue;
        //printf("can take %d odd\n",i);
        ret += (C(n,i)*C(_s/2+n-1,n-1))%mod;
    }
    ret %= mod;
    //printf("%d elements %d sum %d odd -> %lld\n",n,s,k,ret);
    return ret;
}
int n,m;
int main(){
    ///X : sum = 3M
    ///Y : none > 2M
    ///Z : <= M odd
    scanf("%d%d",&n,&m);
    fac[0] = inv[0] = 1;
    for (int i = 1; i <= 2000000; i++){
        fac[i] = (fac[i-1]*i)%mod;
        inv[i] = exp(fac[i],mod-2);
    }
    ll XZ = f(n,3*m,m);
    ll XyZ1 = f(n,m,m);
    ll XyZ2 = f(n-1,m,m);
    ll XyZ = (n*(XyZ1 - XyZ2))%mod;
    ll ans = XZ - XyZ;
    ans = ((ans%mod)+mod)%mod;
    //printf("%lld %lld %lld\n",XZ,XyZ1,XyZ2);
    printf("%lld",ans);

}


Measured memory_bytes: 35048
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  int N; cin >> N;
  int ans = 0;
  rep(i, N) {
    int a;
    cin >> a;
    ans += a - 1;
  }
  cout << ans << endl;
  return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); ++i)

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

const int MAX = 1e5;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int N, K;
string S;

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

    vector<int> lr;
    char c = S[0];
    int cnt = 1, ans = 0;
    for (int i = 1; i < N; ++i) {
        if (c == S[i]) {
            cnt++;
        } else {
            lr.push_back(cnt);
            ans += cnt - 1;
            c = S[i];
            cnt = 1;
        }
    }
    lr.push_back(cnt);
    ans += cnt - 1;
    if (!lr[0]) lr.erase(lr.begin());

    rep(i, K){
        if (3 <= lr.size()) ans += 2;
        else if (2 == lr.size()) ans++;
        else break;
        lr.pop_back();
        lr.pop_back();
    }

    cout << ans << endl;
}

Measured memory_bytes: 1020
#include <stdio.h>
char s[11];
int n;
long long x[11], y, a;
int main() {
	scanf("%s", s);
	while (s[n] != NULL)n++;
	x[0] = 1;
	for (int i = 1; i < n; i++) {
		x[0] *= 10;
	}
	x[1] = x[0] / 10;
	for (int i = 2; i < n; i++) {
		x[i] = x[i - 1] / 5;
	}
	for (int i = 0; i < n; i++) {
		y = s[i] - '0';
		for (int j = i; j < n; j++) {
			a += y * x[j];
		}
		x[i + 1] += x[i] / 10;
	}
	printf("%lld\n", a);
}

Measured memory_bytes: 128
use std::collections::VecDeque;

pub fn read1<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn readn<T: std::str::FromStr>(delimiter: &str) -> Vec<T> {
    let s = read1::<String>();
    s.split(delimiter).map(|e| e.parse().ok().unwrap()).collect::<Vec<T>>()
}

fn main() {
    let hw = readn::<usize>(" ");
    let h = hw[0];
    let w = hw[1];

    let mut a = Vec::with_capacity(h);
    for _ in 0..h {
        a.push(read1::<String>().chars().collect::<Vec<char>>());
    }

    let mut black = 0;
    let mut q = VecDeque::new();
    for y in 0..h {
        for x in 0..w {
            if a[y][x] == '#' {
                black += 1;
                q.push_back((0, y, x));
            }
        }
    }

    if black == h * w {
        println!("0");
        return;
    }

    loop {
        let tyx = q.pop_front().unwrap();
        let t = tyx.0;
        let y = tyx.1;
        let x = tyx.2;

        if y + 1 < h && a[y + 1][x] == '.' {
            q.push_back((t + 1, y + 1, x));
            a[y + 1][x] = '#';
            black += 1;
        }
        if y >= 1 && a[y - 1][x] == '.' {
            q.push_back((t + 1, y - 1, x));
            a[y - 1][x] = '#';
            black += 1;
        }
        if x + 1 < w && a[y][x + 1] == '.' {
            q.push_back((t + 1, y, x + 1));
            a[y][x + 1] = '#';
            black += 1;
        }
        if x >= 1 && a[y][x - 1] == '.' {
            q.push_back((t + 1, y, x - 1));
            a[y][x - 1] = '#';
            black += 1;
        }

        if black == h * w {
            println!("{}", t + 1);
            return;
        }
    }
}

Measured memory_bytes: 32756
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>

using namespace std;

int main(void) {
	int N, M;
	cin >> N >> M;
	vector<long long> x(N), y(N), z(N);
	for (int i = 0; i < N; i++) cin >> x[i] >> y[i] >> z[i];
	long long int ans = 0;
	for (int i = 0; i < 8; i++) {
		int cx = (i & 4) ? 1 : -1;
		int cy = (i & 2) ? 1 : -1;
		int cz = (i & 1) ? 1 : -1;
		vector<long long> score(N);
		for (int j = 0; j < N; j++) score[j] = cx * x[j] + cy * y[j] + cz * z[j];
		sort(score.rbegin(), score.rend());
		long long subans = 0;
		for (int j = 0; j < M; j++) subans += score[j];
		ans = max(ans, subans);
	}
	cout << ans << endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1e18;

int main() {
  ll l,r;
  cin >> l >> r;
  ll count=0;
  ll ans=inf;
  for(ll i=l;i<r;i++) {
    if(count>2019*2019) break;
    for(ll j=i+1;j<=r;j++) {
      if(count>2019*2019) break;
      count++;
      ans=min(ans,i*j%2019);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
n = int(input())
es = [[0, 0]] * (n - 1)
for i in range(n - 1):
    u, v = map(lambda x: int(x) - 1, input().split())
    u, v = min(u, v), max(u, v)
    es[i] = [u, v]

sv = 0
for i in range(n):
    sv += (i + 1) * (n - i)
se = 0
for u, v in es:
    se += (u + 1) * (n - v)
print(sv - se)


Measured memory_bytes: 38900
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()

#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)

//関数定義
//最大公約数
ll gcd(ll a, ll b);

//最小公倍数
ll lcm(ll a, ll b);

int main() {
  // ========================================================
  int n, k;
  cin >> n >> k;
  int cnt = 0, inp;
  REP(i, n) {
    cin >> inp;
    if (inp >= k) cnt++;
  }
  cout << cnt << endl;
}

//最大公約数
ll gcd(ll a, ll b) {
  if (!b) return a;
  return gcd(b, a % b);
}

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
    int N;
    vector<int> A;
    vector<int> result;
    int counter=0;
    A.reserve(N);

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

    bool flag=false;

    while(true){
        for(int i=0;i<N;i++){
            if(A[i]%2!=0)flag=true;
        }
        if(flag) break;
        for(int i=0;i<N;i++){
            A[i]/=2;
        }
        counter++;
    }
    cout << counter ;
}

Measured memory_bytes: 3608
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string.h>
#include <deque>
#define REP(i,j,n) for(int i=j;i<n;i++)
#define SORT(x) sort(x.begin(),x.end())

using namespace std;

int main() {
	int n,count=0;
	cin >> n;
	vector<int> v(n);
	REP(i, 0, n) cin >> v[i];
	SORT(v);
	REP(i, 0, n) {
		if (v[i] == v[i + 1]) i++;
		else count++;
	}
	cout << count << endl;
	
	return 0;
}

Measured memory_bytes: 640
// finish date: 2019/2/22

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>>
        vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


//足し算
int add(int a, int b) {
    return (int) (((ll) a + b + bigmod) % bigmod);
}

//引き算
int sub(int a, int b) {
    return (int) (((ll) a - b + bigmod) % bigmod);
}


int main() {
    int N, K;
    cin >> N >> K;
    vi a(N);
    rep(i, N) cin >> a[i];
    vvi dp(N, vi(K + 2, 0));
    rep(i, a[0] + 1) dp[0][i] = 1;

    rep(i, N - 1) {
        rep(j, K + 1) {
            dp[i + 1][j] = add(dp[i + 1][j], dp[i][j]);
            dp[i + 1][min(K + 1, j + a[i + 1] + 1)] = sub(dp[i + 1][min(K + 1, j + a[i + 1]) + 1], dp[i][j]);
        }
        FOR(j, 1, K + 2) dp[i + 1][j] = add(dp[i + 1][j], dp[i + 1][j - 1]);
    }

    cout << dp[N - 1][K] << endl;

    return 0;
}

Measured memory_bytes: 39808
S = input()
A = False
C = False
ans = 'WA'
if S[0] == 'A':
  A = True
if S[2:-1].find('C') != -1 and S[2:-1].find('C') == S[2:-1].rfind('C'):
  S = S.lstrip('A')
  D = S[S.find('C')+1:]
  E = S[:S.find('C')]
  if D.islower() == True and E.islower() == True:
    C = True
if A == True and C == True:
  ans = 'AC'
print(ans)

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

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

    for (int i = 0; i < s.size() - 1; i++) {
        if (s[i] == s[i + 1]) {
            cout << i + 1 << " " << i + 2 << endl;
            return 0;
        }
    }
    for (int i = 0; i < s.size() - 2; i++) {
        if (s[i] == s[i + 2]) {
            cout << i + 1 << " " << i + 3 << endl;
            return 0;
        }
    }

    cout << "-1 -1" << endl;
    return 0;
}

Measured memory_bytes: 512
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }

void main() {
  auto I = readln.split.to!(long[]);
  auto N = I[0];
  auto R = I[1];

  long solve() {
    return N >= 10 ? R : R + 100 * (10 - N);
  }

  solve().writeln;
}


Measured memory_bytes: 256
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <cassert>
//#include <unordered_map>
//#include <unordered_set>
using namespace std;

typedef long long ll;
#define eps 1e-8
#define LL_INF 0x3fffffffffffffff
#define INF 1LL<<60
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define DE(val) cout<<#val<<": "<<val<<endl;

const int dx4[5] = { 0,-1,0,1,0 };
const int dy4[5] = { 0,0,1,0,-1 };
const int dx8[9] = { 0,-1,0,1,0,1,1,-1,-1 };
const int dy8[9] = { 0,0,1,0,-1,1,-1,1,-1 };
const int maxn = 2e5 + 5;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
ll po(ll a, ll b, ll mod) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a, ll b) { if (a == 0) { return b; } else { return gcd(b%a, a); } }
void YES() { puts("YES"); exit(0); }
void Yes() { puts("Yes"); exit(0); }
void NO() { puts("NO"); exit(0); }
void No() { puts("No"); exit(0); }
void one() { puts("-1"); exit(0); }

ll num[maxn];
int lowbit(int x)
{
	return x&(-x);
}
ll getsum(ll x)
{
	ll ans = 0;
	while (x>0)
	{
		ans += num[x];
		x -= lowbit(x);
	}
	return ans;
}
ll add(int x, int v)
{
	int up = maxn - 1;
	while (x <= up)
	{
		num[x] += v;
		x += lowbit(x);
	}
	return x;
}

ll n, k;
ll val[maxn], sum[maxn];
ll stmp[maxn], s[maxn];

void solve()
{
	scanf("%lld%lld", &n, &k);
	repp(i, 1, n)
	{
		scanf("%lld", &val[i]);
		val[i] -= k;
		sum[i] = sum[i - 1] + val[i];
		stmp[i] = sum[i];
	}
	sort(stmp + 1, stmp + n + 1);
	repp(i, 1, n)
	{
		s[i] = lower_bound(stmp + 1, stmp + n + 1, sum[i]) - stmp;
	}
	ll ans = 0;
	repp(i, 1, n)
	{
		if (sum[i] >= 0)ans++;
		ans +=  (getsum(s[i]));
		add(s[i], 1);
	}
	printf("%lld\n", ans);
}

int main()
{

	solve();
	//system("pause");
	return 0;
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
const long long p=1e9+7;
int main()
{
    int n=read(),tmp;
    long long x=0,y=0;
    for(int i=1; i<=n; i++) tmp=read(),x+=1LL*tmp*tmp,x%=p,y+=tmp,y%=p;
    y*=y,y%=p,y+=p,y-=x,y%=p,y*=(p+1)/2,y%=p;
    cout<<y<<endl;
    return 0;
}

Measured memory_bytes: 3636
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String args[]) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		long N = sc.nextLong();
		long x=0;
		long result=0;
		if(N%2==1) out.println(0);
		else {
			x=N/2;
			int i=1;
			while(x>=Math.pow(5, i)) {
				result+=x/(long)Math.pow(5, i);
				i++;
			}
			
			out.println(result);
		}


		out.flush();
	}


	public static long gcd(long a, long b) {
		if(b==0) {
			return a;
		}
		else {
			return gcd(b,a%b);
		}
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		}else{
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			}else if(b == -1 || !isPrintableChar(b)){
				return minus ? -n : n;
			}else{
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}
	public double nextDouble() { return Double.parseDouble(next());}
}



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

using namespace std;
using LLONG = long long;

int main()
{
    string S;
    cin >> S;
    int count = 0;
    for (char ch : S)
    {
        if (ch == '1') ++count;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

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

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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    ll N;
    cin >>N;
    ll i=0;
    ll sum=0;
    while(1){
      i++;
      sum=sum+i;
      if(sum>N){
        ll hanuke=sum-N;
        FOR(j,1,i){
          if(j!=hanuke){
            cout<<j<<endl;
          }
        }
        return 0;
      }else if(sum==N){
        FOR(j,1,i){
          cout<<j<<endl;
        }
        return 0;
    }
  }
 
  return 0;
}
 


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://atcoder.jp/contests/abc103/tasks/abc103_d

int main() {
    int N, M; cin >> N >> M;
    vector<P> ab;
    REP(i, M) {
        int a, b; cin >> a >> b;
        ab.push_back({b, a});
    }
    sort(ab.begin(), ab.end());

    int ans = 0;
    int now = 0;
    REP(i, M) {
        int l = ab[i].second;
        int r = ab[i].first;
        if (l >= now) {
            ans++;
            now = r;
        }
    }
    cout << ans << "\n";

    return 0;
}


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

int main() {
    int H;
    cin >> H;
    int W;
    cin >> W;
    
    for (int i = 0; i < W + 2; i++){
        cout << "#";
    }
    cout << endl;
    
    for (int j = 0; j < H; j++){
        cout << "#";
        for (int k = 0; k < W; k++){
            char a;
            cin >> a;
            cout << a;
        }
        cout << "#" << endl;
    }
    for (int m = 0; m < W + 2; m++){
        cout << "#";
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<climits>
typedef unsigned long long ull;
using namespace std;

int main(){
	int N, C;
	cin >> N >> C;
	int D[30*30];
	int c[3][30]={0};

	for(int i=0;i<C*C;i++)
		cin>>D[i];

	int size1=0,size2=0,size3=0;
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			int tmp;
			cin >> tmp;
			c[(i+j)%3][tmp-1]++;
		}
	}

	
	int min = INT_MAX;
	for(int i=0;i<C;i++){
		for(int j=0;j<C;j++){
			for(int k=0;k<C;k++){
				if(i!=j&&j!=k&&k!=i){
					int sum=0;
					for(int s=0;s<C;s++){
						sum+=c[0][s]*D[C*s+i];
						sum+=c[1][s]*D[C*s+j];
						sum+=c[2][s]*D[C*s+k];
					}
					if(sum<min)
						min=sum;
				}
			}
		}
	}
	cout << min << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
    vector<ll> v(3); 
    rep(i,3)cin>>v[i];
    int k;cin>>k;
    sort(v.begin(),v.end());
    ll p=pow(2,k);
    ll sum=v[0]+v[1]+(v[2]*p);
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 896
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    double n,m,d;
    cin>>n>>m>>d;
    if(d==0){
        cout<<(m-1)/n<<endl;
    }
    else{
        cout<<(m-1)*2*(n-d)/(n*n)<<endl;
    }
    
}

Measured memory_bytes: 256
# 貪欲法による
# > 000 ~ 999の1000通りをチェックする。
n = int(input())
s = input()
'''
for i in range(1000):
    a = '{0:03d}'.format(i)
    a1 = a[0]
    a2 =
'''
ans = 0

for i in range(10):
    #temp = s

    if (str(i) not in s):
        continue
    else:
        tar1 = s.find(str(i))

    for j in range(10):
        temp = s[tar1 + 1:]
        if (str(j) not in temp):
            continue
        else:
            tar2 = temp.find(str(j))

        for k in range(10):
            temp = s[tar1 + 1:]
            temp = temp[tar2 + 1:]

            if (str(k) not in temp):
                continue
            else:
                ans += 1


print(ans)


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

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

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

    int b[2] = {}, c[2] = {};
    for (int i = 0; i < n; i++) {
        if (a[i] == b[0] || a[i] == b[1]) {
            c[a[i] == b[1]]++;
        } else {
            if (b[0] == 0) b[0] = a[i], c[0]++;
            else if (b[1] == 0) b[1] = a[i], c[1]++;
            else break;
        }
    }
    if (b[0] < b[1]) swap(b[0], b[1]), swap(c[0], c[1]);

    if (c[0] + c[1] != n || !(c[1] == 0 || b[0] - b[1] == 1)) {
        cout << "No" << endl;
        quick_exit(0);
    }

    // 全部違う色のとき
    if (c[1] == 0 && b[0] == n - 1) {
        cout << "Yes" << endl;
        quick_exit(0);
    }

    // c[0]匹でユニークカラーなしでb[0]-c[1]色にできるか
    if (b[0] - c[1] > 0 && b[0] - c[1] <= c[0] / 2) {
        cout << "Yes" << endl;
        quick_exit(0);
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 768
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String [] args) {
        FastReader reader = new FastReader();
        int h = reader.nextInt(), w = reader.nextInt();
        int mod = 1_000_000_007;

        int [][] grid = new int [h][w];
        for (int i = 0; i < h; i++) {
            String row = reader.nextLine();
            for (int j = 0; j < w; j++) {
                char c = row.charAt(j);
                if (c == '.') {
                    grid[i][j] = 0;
                } else {
                    grid[i][j] = -1;
                }
            }
        }

        grid[0][0] = 1;
        int j = 1;
        for (int i = 0; i < h; i++) {
            for (; j < w; j++) {
                if (grid[i][j] == -1) {
                    grid[i][j] = 0;
                    continue;
                }
                if (i > 0) {
                    grid[i][j] = (grid[i][j] + grid[i - 1][j]) % mod;
                }
                if (j > 0) {
                    grid[i][j] = (grid[i][j] + grid[i][j - 1]) % mod;
                }
            }
            j = 0;
        }

        System.out.println(grid[h - 1][w - 1]);

    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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


Measured memory_bytes: 34644
def solve(n, m, AB, CD):
    ret = []
    for a, b in AB:
        minval = 10 ** 10
        minidx = -1
        for j, (c, d) in enumerate(CD):
            if abs(a - c) + abs(b - d) < minval:
                minval = abs(a - c) + abs(b - d)
                minidx = j
        ret.append(minidx + 1)
    return ret

_n, _m = map(int, input().split())
_AB = [list(map(int, input().split())) for _ in range(_n)]
_CD = [list(map(int, input().split())) for _ in range(_m)]
print(*solve(_n, _m, _AB, _CD), sep='\n')


Measured memory_bytes: 39280
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MAXSIZE 10000000;

bool comp(const pair<int,int> a, const pair<int,int> b) {
    return a.second < b.second;
}

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
    ll L,R;

    cin >>L>>R;

    if( (R - L)>= 2019){
      cout <<0<<endl;
    }
    else{
      ll minMod = 10000000;
      for(ll i = L;i<=R;i++){
        for(ll j = i+1;j<=R;j++){
          minMod = min(minMod,(i*j)%2019);
        }
      }
      cout <<minMod<<endl;
    }
    return 0;
}

/*Syakutori
while(cin >>b && b)){
      ll t = 1;
      long long int ansS = 1,ansT=0;
      long long int sum = 0;

      for(ll s = 1;s < 50000000;s++){

        while(t <  50000000 && sum+Rsum[t] < b){
          sum += Rsum[t];
          t++;
        }
        if(b == sum+Rsum[t]){
          if(ansT - ansS < t-s){
            ansS = s;
            ansT = t;
          }
          cout <<ansS<<" "<<ansT-ansS + 1<<endl;
          break;
        }
        if(t == s)++t;
        else sum -= Rsum[s];
        }
    }

//priority_queue<long long int,vector<long long int>, greater<long long int>> PQ;
//priority_queue<long long int> PQ1;

*/

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin >> s;
    
    int p = 0;
    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] == 'p')
        {
            p += 1;
        }
    }
    
    cout << s.length() / 2 - p << endl;
    
    return 0;
}


Measured memory_bytes: 512
//Never stop trying
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef string str;
typedef long long ll;
#define int ll
typedef double db;
typedef long double ld;
typedef pair<int, int> pi;
#define fi first
#define se second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<str> vs;
typedef vector<ld> vd;
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

const int MOD = 1e9 + 7; //998244353
const ll INF = 1e18;
const int MX = 2e5 + 10;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up

template<class T> using V = vector<T>;
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))

#define dbg(x) cerr << " - " << #x << " : " << x << endl;
#define dbgs(x,y) cerr << " - " << #x << " : " << x << " / " << #y << " : " << y << endl;
#define dbgv(v) cerr << " - " << #v << " : " << endl << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl;

void IO() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}


int32_t main() {
	boost; IO();

	int N,M; cin>>N>>M;
	vi a(N),b(N);
	FOR(i,0,N){
		cin>>a[i]>>b[i];
		a[i]--; b[i]--;
	}

	set <pi> s;
	multiset<int> ss;
	FOR(i,0,M) s.insert({i,i}),ss.insert(0);


	FOR(i,0,N){
		int l=a[i],r=b[i];
		auto it=s.lower_bound({l,-INF});
		vpi rmv;
		for(; it!=s.end() && (*it).fi<=r ; it++){
			rmv.pb((*it));
		}
		int mx=-1;
		for(auto x: rmv){
			ss.erase(ss.find(x.fi-x.se));
			s.erase(x);
			mx=max(mx,x.se);
		}
		int nxt=r+1; if(nxt>=M) nxt=INF;
		if(!rmv.empty()){
			s.insert({nxt,mx});
			ss.insert(nxt-mx);
		}	
		assert(sz(ss)>0);
		auto itr=ss.begin();
		int res=i+1+(*itr);
		if(res>=1e15) cout << -1 << endl;
		else cout << res << endl;
	}



	return 0;
}

/* Careful!!!
	.Array bounds
	.Infinite loops
	.Uninitialized variables / empty containers
	.Order of input

   Some insights:
	.Binary search
	.Graph representation
	.Write brute force code
	.Change your approach
*/


Measured memory_bytes: 28204
unittest
{
	assert( [ "1 2 3" ].parse.expand.solve == "3 1 2" );
	assert( [ "100 100 100" ].parse.expand.solve == "100 100 100" );
	assert( [ "41 59 31" ].parse.expand.solve == "31 41 59" );
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto xyz = input.front.split.to!( long[] );
	return tuple( xyz[ 0 ], xyz[ 1 ], xyz[ 2 ] );
}

auto solve( long x, long y, long z )
{
	swap( x, y );
	swap( x, z );
	return format( "%s %s %s", x, y, z );
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
 
#define mod(cans) cans%10**9+7
#define debug(x) cout << "Debug" << x << "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define cin_pl(n,x) rep(i,n){cin>>x[i];}
#define cins(s,n) rep(i,n)cin>>s.at[i];
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define prians(Answer) cout<<Answer<<"\n"
#define TF(X) X==1?cout<<"Yes\n":cout<<"No\n"
#define elcon else{continue;}
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vector<int> > matrix;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef greater<int> gi;
typedef vector<unsigned> vu;


ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
bool is_prime(const unsigned n){
    switch(n){
        case 0:
        case 1: return false;
        case 2: return true;
    }
 
 
    for(unsigned i=2;i<n;++i){
        if(n%i == 0) return false;
    }
 
    return true;
}

int main()
{

    int n;
    cin>>n;int sum=0;
    rep(i,n+1)
    sum+=i;
    cout<<sum;
}

Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<10)
#define MOD 1000000007
using ll = long long;
using namespace std;


int main() {
    int r;
    cin >> r;
    if (0 <= r && r < 1200)cout << "ABC" << endl;
    else if (1200 <= r && r < 2800)cout << "ARC" << endl;
    else cout << "AGC" << endl;
    return 0;
}


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

int main() {
  
  string s, t;
  cin >> s;
  
  for(int i = 0; i < s.size(); i++){
    if(i%2 == 0){
      t += s.at(i) ;
    }
  }
  
  cout << t << endl;
  
      
  
}

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

int main() {
    string s;
    string n;
    long long a;
    long long b;
    string u;
    cin >> s >> n >> a >> b >> u;
    long long  new_a = a - 1;
    long long  new_b = b - 1;
    if (u == s) {
        cout << new_a << " " << b << endl;
    }
    else {
        cout << a << " " << new_b << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int main()
{
    scanf("%d",&n);
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        if(i%3==0||i%5==0) continue;
        ans+=i;
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 3828
while(1):
    try:
        faces = [1 if i == "o" else 0 for i in list(input())]
        hori = [sum(faces[0:3]),sum(faces[3:6]),sum(faces[6:9])]
        vert = [sum(faces[0:7:3]),sum(faces[1:8:3]),sum(faces[2:9:3])]
        diag = [sum(faces[0:9:4]),sum(faces[2:7:2])]
        hori.extend(vert)
        hori.extend(diag)
        if 3 in hori:
            print("o")
        elif 0 in hori:
            print("x")
        else:
            print("d")
    except EOFError:
        break


Measured memory_bytes: 5568
#include <stdio.h>

int main(void)
{
	int S,h=0,m=0,s=0;
	scanf("%d",&S);
	h=S/3600;
	S=S%3600;
	m=S/60;
	S=S%60;
	s=S;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 1852
#include <cstdio>
#include<cmath>
#include<algorithm>

using namespace std;

int A[100001];
int B[100001];

int func(int b, int e, int v)
{
	int m = abs(v - A[b]) + B[b];
	for(int i=b+1;i<e;++i)
	{
		m = min(m, abs(v - A[i]) + B[i]);
	}
	return m;
}

int main()
{
	int n, k;
	scanf("%d %d", &n, &k);
	for(int i = 0;i<n;++i)
		scanf("%d", &A[i]);
	for (int i = 1; i < k; ++i)
		B[i] = func(0, i, A[i]);
	for (int i = k; i < n; ++i)
		B[i] = func(i - k, i, A[i]);
		printf("%d\n", B[n - 1]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long N, M;
    cin >> N >> M;
    vector<long long> x(N), y(N), z(N);
    for(int i = 0; i < N; i++) cin >> x[i] >> y[i] >> z[i];
    vector<long long> a(N);
    vector<long long> ans(8, 0);
    int j = 0;
    for(int i = 0; i < N; i++) a[i] = x[i] + y[i] + z[i];
    sort(a.begin(), a.end());
    for(int i = 0; i < M; i++) ans[j] += a[N - 1 - i];
    j++;
    for(int i = 0; i < N; i++) a[i] = x[i] + y[i] - z[i];
    sort(a.begin(), a.end());
    for(int i = 0; i < M; i++) ans[j] += a[N - 1 - i];
    j++;
    for(int i = 0; i < N; i++) a[i] = x[i] - y[i] + z[i];
    sort(a.begin(), a.end());
    for(int i = 0; i < M; i++) ans[j] += a[N - 1 - i];
    j++;
    for(int i = 0; i < N; i++) a[i] = -x[i] + y[i] + z[i];
    sort(a.begin(), a.end());
    for(int i = 0; i < M; i++) ans[j] += a[N - 1 - i];
    j++;
    for(int i = 0; i < N; i++) a[i] = x[i] - y[i] - z[i];
    sort(a.begin(), a.end());
    for(int i = 0; i < M; i++) ans[j] += a[N - 1 - i];
    j++;
    for(int i = 0; i < N; i++) a[i] = -x[i] + y[i] - z[i];
    sort(a.begin(), a.end());
    for(int i = 0; i < M; i++) ans[j] += a[N - 1 - i];
    j++;
    for(int i = 0; i < N; i++) a[i] = -x[i] - y[i] + z[i];
    sort(a.begin(), a.end());
    for(int i = 0; i < M; i++) ans[j] += a[N - 1 - i];
    j++;
    for(int i = 0; i < N; i++) a[i] = -x[i] - y[i] - z[i];
    sort(a.begin(), a.end());
    for(int i = 0; i < M; i++) ans[j] += a[N - 1 - i];
    long long res = ans[0];
    for(int i = 1; i < 8; i++) res = max(res, ans[i]);
    cout << res << endl;
}

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

int main()
{
  int n,m;
  string s,p;

  cin>>s>>p;

  n=s.length();
  m=p.length();
  for(int i=0;i<n-m+1;i++){
    if(s.substr(i,m)==p)cout<<i<<endl;
  }
  return 0;
}

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

int main() {
  string s;
  cin>>s;
  reverse(s.begin(),s.end());
  vector<string> S={"maerd","remaerd","esare","resare"};
  for(int i=0;i<s.size();){
    bool flag=true;
    for(int j=0;j<4;j++){
      string d=S[j];
      if(d==s.substr(i,d.size())){
        flag=false;
        i+=d.size();
        break;
      }
    }
     if(flag) {cout<<"NO"<<endl; return 0;}
  }
  cout<<"YES"<<endl;
}



Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		String[] d = new String[k];
		for (int i = 0; i < k; i++) {
			d[i] = sc.next();
		}
		sc.close();

		label:
		for (int i = n; ; i++) {
			String s = String.valueOf(i);
			for (int j = 0; j < k; j++) {
				if (s.indexOf(d[j]) != -1) {
					continue label;
				}
			}
			System.out.println(i);
			return;
		}
	}
}


Measured memory_bytes: 23760
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
int a, b, c, d, n1, n2;
int main() {
    DAU
    cin >> a >> b >> c >> d;
    n1 = c / b;
    if (c % b)
        ++n1;
    n2 = a / d;
    if (a % d)
        ++n2;
    if (n1 > n2)
        cout << "No";
    else cout << "Yes";
    PLEC
}


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int N, W;
  cin >> N >> W;

  const int INF = 1e9 + 5;

  vector<int> dp(1e5+1, INF); // dp[i] minimum weight to have i value
  // dp[i+1][item+1] = min(dp[i+1][item], dp[i+1-v[item+1]][item] + w[item+1])

  dp[0] = 0;

  for (int i = 0; i < N; ++i) {
    int w, v;
    cin >> w >> v;

    for (int val = 1e5; val >= v; --val) {
      dp[val] = min({dp[val], dp[val-v] + w, INF});
    }
  }

  for (int val = 1e5; true; --val) {
    if (dp[val] <= W) {
      cout << val << '\n';
      break;
    }
  }

  return 0;
}


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

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

  int A, B;
  cin >> A >> B;
  int first = A;
  int maxd = B - A;
  
  for(int i=0;i<N-2;i++){
    A = B;
    cin >> B;
    if(B - A > maxd) maxd = B - A;
  }

  if(K - B + first > maxd) maxd = K - B + first;
  
  cout << K - maxd << endl;
  
  return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
#define maxn 200010
#define LL long long
using namespace std;
int a[maxn],b[maxn],c[maxn],cnt,cnta,cntb;
LL sum;
struct node{
	int flag;
	int v;
}e[maxn*2];
int cmp(node a,node b){
	return a.v==b.v?a.flag<b.flag:a.v<b.v;
}
int main(){
	int n,i,good;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	for(i=1;i<=n;i++)b[i]=a[i]+i,c[i]=i-a[i];
	for(i=1;i<=n;i++)
		if(b[i]==c[i])sum--;
	//printf("sum=%lld\n",sum);
	for(i=1;i<=n;i++)
		e[++cnt].flag=0,e[cnt].v=b[i];
	for(i=1;i<=n;i++)
		e[++cnt].flag=1,e[cnt].v=c[i];
	sort(e+1,e+1+cnt,cmp);
	//for(i=1;i<=cnt;i++)printf("%d ",e[i].v);
	//printf("\n");
	e[0].v=2e9,cnta=0,cntb=0,good=0;
	for(i=1;i<=cnt;i++)
		if(e[i-1].v==e[i].v){
			if(e[i-1].flag==0&&e[i].flag==1)good=1;
			if(e[i].flag==0)cnta++;
			else cntb++;
		}else{
			if(good)sum+=(LL)cntb*(cnta+1);
			//printf("%d %d\n",cnta,cntb);
			cnta=0,cntb=0,good=0;
		}
	if(good)sum+=(LL)cntb*(cnta+1);
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 8692