akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define srt(x) sort((x).begin(), (x).end())
#define rsrt(x) sort((x).rbegin(), (x).rend())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<long long>;
using vllvll = vector<vll>;
using vc = vector<char>;
using vs = vector<string>;
using um = unordered_map<long long, long long>;
template<class T>void print(T x) { cout << '\n' << "== " << x << " ==" << '\n'; }
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T>void precise(T x) { cout << setprecision(21) << x << '\n'; }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long double doublepi = M_PI * 2.0;
const long double halfpi = M_PI / 2.0;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long MOD = 1e9 + 7;



int main()
{
    ll N, M;
    cin >> N >> M;
    vll L(M), R(M);
    rep(i, 0, M) {
        cin >> L[i] >> R[i];
    }
    vll acc(N+1, 0);
    rep(i, 0, M) {
        acc[L[i]-1]++;
        acc[R[i]]--;
    }
    rep(i, 0, N) {
        acc[i+1] += acc[i];
    }
    ll cnt = 0;
    rep(i, 0, N+1) {
        if (acc[i] == M) {
            ++cnt;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#define fi first
#define se second
#define p_b push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define sset ordered_set
#define sqr(x) (x)*(x)
#define pw(x) (1ll << x)
#define delete _delete

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
const ll MAXN = 1123456;
const ll N = 1e6;
const ll mod = 1e9 + 7;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename T> void vout(T s){cout << s << endl;exit(0);}

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

    ll n;
    cin >> n;

    cout << 3 * n * n << "\n";

    cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
long long n,m,ans;
bool start()
{
    if(n==1&&m==1) {printf("1\n"); return 1;}
    if(n==1) {printf("%lld\n",m-2); return 1;}
    if(m==1) {printf("%lld\n",n-2); return 1;}
    return 0;
}
int main()
{
    cin>>n>>m;
    if(start()) return 0;
    ans=(n-2)*(m-2);
    printf("%lld\n",ans);
}

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

signed main() {
  int N, H;
  cin >> N >> H;
  
  vector<int> A(N);
  vector<int> B(N);
  for( int i = 0; i < N; i++ ) cin >> A.at(i) >> B.at(i);
  
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  reverse(B.begin(), B.end());
  
  int ans = 0;
  for( int i = 0; i < N; i++ ){
    if( B.at(i) < A.back() ) break;
    if( H <= 0 ) break;
    else{
      H -= B.at(i);
      ans++;
    }
  }
  
  if( H > 0 ){
    ans += ( H + A.back() - 1 ) / A.back();
  }
  cout << ans << endl;
    
}
  

Measured memory_bytes: 1792
// AtCoder ABC138: A - Red or Not
// 2019.8.26 bal4u

#include <stdio.h>

int main()
{
	int a;
	char s[15];
	
	scanf("%d%s", &a, s);
	if (a >= 3200) puts(s);
	else puts("red");
	return 0;
}

Measured memory_bytes: 128
n,k=map(int,input().split())
s=list(input())
l=0
c=0
for i in range(n):
    if s[i]==min(s):
        c+=1
        l=max(l,c)
    else:
        c=0
s.reverse()
if (2**(k-1))*l>n:
    print(min(s)*n)
else:
    for i in range(min(k,13)):
        t=list(reversed(s))
        u=t+s
        uu=u[:n]
        for j in range(1,n+1):
            x=u[j:j+n]
            if uu>x:
                uu=x
        s=uu
    print("".join(s))


Measured memory_bytes: 282760
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
const int ddx[4] = {1,1,-1, -1};
const int ddy[4] = {1,-1,-1,1};
//////////////////////////////////

int main(){
  int n; cin >> n;
  vector<int> a(n);
  bool f = true;
  for(int i=0; i<n; i++) {
    cin >> a[i];
    if(a[i]%2 == 0) {
      if (!(a[i]%3 == 0 || a[i]%5 == 0)) f = false; 
    }
  }
  if (f) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;


  return 0;
}

// EOF



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

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

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    map<int, bool> m;
    cin >> n;
    rep (i, n) {
        int a;
        cin >> a;
        m[a] = true;
    }
    if (m.size() == n) cout << "YES\n";
    else cout << "NO\n";
    return 0;
}

Measured memory_bytes: 9600
#include<iostream>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<stack>
#include<unordered_map>
#include<bitset>
#include<limits>
#include<array>
using namespace std;
#define MOD 1000000007
#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define REP(i,n) rep(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {//最大フロー求める Ford-fulkerson
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));//最小カットの場合逆辺は0にする
}

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

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

	constexpr ll mod = 998244353;

	ll n;
	cin >> n;
	Matrix grundy(3, Array(2000, 0));
	REP(i, 3) {
		ll m;
		cin >> m;
		Graph g(n);
		REP(j, m) {
			ll a, b;
			cin >> a >> b;
			a--; b--;
			add_edge(g, a, b, 1, true, 1);
		}
		Array temp(n, 0);
		for(int j=g.size()-1;j>=0;j--) {
			set<ll> st;
			ll now = 0;
			REP(k, g[j].size()) {
				ll to = g[j][k].to;
				if (to < j)continue;
				st.insert(temp[to]);
				while (st.count(now))now++;
			}
			temp[j] = now;
			(grundy[i][now] += mod_pow(10, 18*(j + 1), mod)) %= mod;
		}
	}
	ll ans = 0;
	REP(i, 1000) {
		REP(j, 1000) {
			ll temp = grundy[0][i] * grundy[1][j] % mod;
			(temp *= grundy[2][(i ^ j)]) %= mod;
			(ans += temp )%= mod;
		}
	}
	cout << ans << "\n";



	return 0;
}

Measured memory_bytes: 10252
import java.util.*;
public class Main {
	public static void main(String[] args){
		
		
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int h = sc.nextInt();
 
		// 出力
		System.out.println(  ((a+b)*h)/2   );
		
		
	}
}

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

int main() {
  int N; cin >> N;
  vector<P> p;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    p.push_back(make_pair(a,i+1));
  }
  sort(p.begin(), p.end());
  for (int i = 0; i < N; i++)
  {
    cout << p[i].second << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1780
/**
 * author: dhakad_123
**/

#include<bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
  
  
    int n;  
    cin >> n;
    
    if(n  < 4 || n == 5 || n == 6 || n == 9 || n == 10 || n == 13  || n == 17){
        cout << "No" << "\n";
    }
    else {
        cout<< "Yes" <<"\n";
    }
    
    return 0;
}

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


int main()
{


     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
    
    int t=1;
    while(t--)
    {
      
      int lim[2];
      int count[3];
      cin>>lim[0]>>lim[1]>>count[0]>>count[1]>>count[2];
      vector<pair<int,int>>nish;
      //vector<int>nish1,nish2,nish3;
      
     for(int i=0;i<3;i++)
     {
      for(int j=0;j<count[i];j++)
      {
        int first;
        cin>>first;
        nish.push_back({first,i});
      }
     }

     sort(nish.rbegin(),nish.rend());
     int total=lim[0]+lim[1];
     int siz=nish.size();
     long long int ans=0;
     for(int i=0;i<siz;i++)
     {
      if(total<=0) break;
      int second=nish[i].second;
      if(second<=1)
      {
          if(lim[second]<=0)continue;
          ans+=nish[i].first;
          lim[second]--;
          total--;
      }
      else
        ans+=nish[i].first,total--;

     }

     cout<<ans<<endl;

      
      


      }

return 0;

}

Measured memory_bytes: 6384
# -*- coding: utf-8 -*-
N = int(input())

A = list(map(int, input().split(' ')))
A = [ a - (i + 1) for i, a in enumerate(A)]
A.sort()

# print(A)
n = A[(len(A)+1)//2 - 1]
A = [abs(a - n) for a in A]

# print(A)
print(sum(A))



Measured memory_bytes: 26356
#include<stdio.h>

int main(void){
  int A, B;
  
  scanf ( "%d %d ", &A, &B);
  
  if( A + B == 3 ){
    printf( "3\n" );
  } else if ( A + B == 4 ){
    printf( "2\n" );
  } else {
    printf( "1\n" );
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
 
/*---------------------------------------------------*/

int main(){
    int a, b, c, x;
    int ans = 0;
    cin >> a >> b >> c >> x;
    rep(i, a + 1){
        rep(j, b + 1){
            rep(k, c + 1){
                if(i * 500 + j * 100 + k * 50 == x)ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		String S = scan.next();

		if (S.equals("RRR")) System.out.println("3");
		else if (S.equals("RRS") || S.equals("SRR")) System.out.println("2");
		else if (S.contains("R")) System.out.println("1");
		else System.out.println("0");

 	}
}

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

int main(){
  int i,a,b,z=0,x[5];
  scanf("%d %d",&a,&b);
  for(i=a;i<=b;i++){
    x[0]=i%10;
    x[1]=(i%100-i%10)/10;
    x[3]=(i%10000-i%1000)/1000;
    x[4]=i/10000;
    if(x[0]==x[4]&&x[1]==x[3]){
      z++;
    }
  }
  printf("%d",z);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>

using namespace std;
string s;

bool Rev(string &s, const char x) {
  string new_s = "";
  bool ret = false;
  for (int i = 0; i < s.size();i++) {
    if (s.substr(i, 3) == "ABC") {
      new_s.push_back(x);
      i += 2;
    } else {
      new_s.push_back(s[i]);
      ret |= (s[i] == x);
    }
  }
  ret = (ret || new_s == s);
  s = new_s;
  return ret;
}

void Solve(void) {
  while (true) {
    if (s == "ABC") {
      cout << "Yes" << endl;
      return;
    }
    if (s.size() <= 3) {
      break;
    }

    bool ret = false;
    if (s.substr(0, 3)=="ABC") { // 右がABC
      ret = Rev(s, 'A');
    } else if (s.substr(s.size()-3, 3) == "ABC") { // 左がABC
      ret =  Rev(s, 'C');
    } else {
      ret = Rev(s,  'B');
    }
    if (ret) break;
  }
  
  cout << "No" << endl;
}

signed main(void) {
  cin >> s;

  Solve();
}


Measured memory_bytes: 3236
fn main() {
    let mut a = String::new();
    std::io::stdin().read_line(&mut a).ok();
    let mut iter = a.trim().split_whitespace();

    let a: i32 = iter.next().unwrap().parse().unwrap();
    let b: i32 = iter.next().unwrap().parse().unwrap();

    println!("{}", a * b);
}


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

int main(){
  string s,ans="YES";
  cin >> s;
  reverse(s.begin(),s.end());
  int i=0;
  int n =s.size();
  while(i<n){
    if(i+4>=n){ans="NO";break;}
    string sub1 = s.substr(i,5);
    if(sub1=="maerd" or sub1=="esare"){i+=5;continue;}
    if(i+5>=n){ans="NO";break;}
    string sub2 = s.substr(i,6);
    if(sub2=="resare"){i+=6;continue;}
    if(i+6>=n){ans="NO";break;}
    string sub3 = s.substr(i,7);
    if(sub3=="remaerd"){i+=7;continue;}
    ans="NO";break;
  }
  cout << ans <<"\n";
  return 0;
}

Measured memory_bytes: 3748
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#define ll long long
using namespace std;

int main(void){
    string s[3];
    for(int i=0;i<3;i++){
        cin >> s[i];
    }
    cout << s[0][0] << s[1][0] << s[2][0] << endl;
    
    return 0;
}

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

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

using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;

template<i64 M>
struct modint {
    i64 x;

    constexpr modint(const i64 y = 0) noexcept : x(y >= 0 ? y % M : (M - (-y) % M) % M) {}

    constexpr modint operator-() const noexcept { return modint(-x); }
    constexpr modint operator+(const modint &rhs) const noexcept { return modint(*this) += rhs; }
    constexpr modint operator-(const modint &rhs) const noexcept { return modint(*this) -= rhs; }
    constexpr modint operator*(const modint &rhs) const noexcept { return modint(*this) *= rhs; }
    constexpr modint operator/(const modint &rhs) const noexcept { return modint(*this) /= rhs; }

    constexpr modint &operator+=(const modint &rhs) noexcept {
        x += rhs.x;
        if (x >= M) x -= M;
        return *this;
    }

    constexpr modint &operator-=(const modint &rhs) noexcept {
        if (x < rhs.x) x += M;
        x -= rhs.x;
        return *this;
    }

    constexpr modint &operator*=(const modint &rhs) noexcept {
        x = x * rhs.x % M;
        return *this;
    }

    constexpr modint &operator/=(const modint &rhs) noexcept {
        i64 a = rhs.x, b = M, u = 1, v = 0;
        while (b > 0) {
            i64 t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        *this *= u;
        return *this;
    }

    friend ostream &operator<<(ostream &os, const modint &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, modint &a) {
        i64 t;
        is >> t;
        a = modint(t);
        return is;
    }
};

constexpr i64 MOD = 1 ? 1'000'000'007 : 998'244'353;
using m64 = modint<MOD>;
constexpr m64 operator"" _m(unsigned long long n) { return m64(n); }

void solve() {
    i64 n;
    cin >> n;
    string s;
    cin >> s;

    vector<m64> dp(n, 1);
    for (i64 i = 0; i < n - 1; i++) {
        partial_sum(all(dp), begin(dp));
        if (s[i] == '>') continue;
        for (i64 j = 0; j < n - (i + 1); j++) {
            dp[j] = dp[n - (i + 1)] - dp[j];
        }
    }

    cout << dp[0] << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
using namespace std;

constexpr int INF       = 1000000000;/* 1e+9a */
constexpr int MODULO    = 1000000007;

typedef long long ll;

#define REP(i,f,n) for(int i=(f); i < (n); ++i)
#define PER(i,f,n) for(int i=(n-1); i >= f; --i)

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

template<typename STL> inline void print_STL(STL c, string ab = ""){
	cout << ab << '\n';
	for(auto t : c) cout << t << ' '; cout << '\n';}

template<typename VEC> inline void import_VEC(VEC& c, int n){
	typename VEC::value_type tmp;
	for(int i = 0; i < n; ++i){	cin >> tmp; c.push_back(tmp);} }

#define SPRE(x) setprecision(x) // 精度を指定

signed main()
{
	cin.tie(0);
    ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int t1, t2;
	cin >> t1 >> t2;
	ll taka = t1, aoki = t2;
	for(int i = 1; i < n; ++i)
	{
		/* cerr << taka << ',' << aoki << '\n'; */
		cin >> t1 >> t2;
		if(taka % t1 != 0)
		{
			taka += t1 - (taka % t1);
		}
		if(aoki % t2 != 0)
			aoki += t2 - aoki % t2;

		ll dif = taka/t1 - aoki/t2;
		if(dif > 0)
			aoki += t2 * dif;
		else if (dif < 0)
			taka += t1 * -dif;
	}
	cout << taka+aoki << '\n';


}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	string s,t;
	cin >> s >> t;
	cout << t << s << endl;
	return 0;
}


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

using namespace std;

typedef struct Point {
	double x;
	double y;
};

Point GetSPT(Point a,Point b) {
	Point retpt;
	if((a.x<0&&b.x<0)||(a.x>=0&&b.x>=0)) retpt.x = fabs(fabs(a.x)-fabs(-b.x));
	else retpt.x = fabs(fabs(a.x)+fabs(b.x));
	if((a.y<0&&b.y<0)||(a.y>=0&&b.y>=0)) retpt.y = fabs(fabs(a.y)-fabs(-b.y));
	else retpt.y= fabs(fabs(a.y)+fabs(b.y));
	return retpt;
}

double torad(double angle) {
	return (angle*PI)/(double)180.0;
}

int main(int argc,char ** argv) {
	int a,b,h,m;
	double anglet,angleb;
	scanf("%d %d %d %d",&a,&b,&h,&m);
	anglet=-(h*30.0);
	angleb=-(m*6.0);
	anglet=anglet+((double)(30.0/360.0)*angleb);
	angleb+=90.0;anglet+=90.0;
	Point pa,pb,ans;
	pa.x = cos(torad(anglet))*a;
	pa.y = sin(torad(anglet))*a;
	pb.x = cos(torad(angleb))*b;
	pb.y = sin(torad(angleb))*b;
	ans = GetSPT(pa,pb);
	printf("%.20lf",(double)sqrt(ans.x*ans.x+ans.y*ans.y));
	
	return 0;
} 

Measured memory_bytes: 4144
from math import ceil
N,K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))

A.sort()
F.sort(reverse=True)

def possible(x):
    k = K
    for i in range(N):
        if A[i]*F[i]>x:
            k -= ceil(A[i]-x/F[i])
        if k < 0:
            break
    return k >= 0


l = 0
r = 10**12
for i in range(45):
    m = (l+r)/2
    if possible(m):
        r = m
    else:
        l = m

print(round(m))

Measured memory_bytes: 120396
import math
N = int(input())
ans = 0
temp  = [ [-1] * (N + 1) for _ in range(N + 1)]
for i in range(1,N + 1):
    for j in range(i, N + 1):
        hoge = math.gcd(i,j)
        temp[i][j] =temp[j][i] = hoge


for i in range(1,N + 1):
    for j in range(1, N + 1):
        for k in range(1, N + 1):
            hoge = temp[i][j]
            ans += temp[hoge][k]

print(ans)

Measured memory_bytes: 9424
import java.util.Scanner;

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



		Scanner scanner = new Scanner(System.in);
		String N = scanner.next();
		int ans =0 ;
		for(int i = 0;i < N.length();i++){
			if(N.substring(i, i+1).equals("1")){
				ans++;
			}
		}
		System.out.println(ans);



	}


}

class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}



Measured memory_bytes: 22100
while 1:
    try:n=sorted(map(int,input().split(',')))
    except:break
    c=sum(n.count(x) for x in n)
    if c==17:c=3
    elif c in [13,11,9,7]:c-=5
    elif max(n)-min(n)==4 or (n[1] == 10 and n[0]==1):c=1
    else:c=0
    print(['null','straight','one pair','four card','two pair','','three card','','full house'][c])

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

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

  x = n * a;
  if ( x > b ) {
    cout << b << endl;
  } else {
    cout << x << endl;
  }
}

Measured memory_bytes: 256
import math
a, b, h, m = map(int, input().split())
ang_a = (360 * h / 12) + (0.5 * m)
ang_b = 360 * m / 60
ang = abs(ang_a - ang_b if ang_a > ang_b else ang_b - ang_a)
ans = math.sqrt((a ** 2 + b ** 2) - (2*a*b*math.cos(math.radians(ang))))
print(ans)


Measured memory_bytes: 9508
#include<stdio.h>
 #include<math.h>
 int main(void)
 {
     double A,B,C,K,S=0;

     scanf("%lf%lf%lf",&A,&B,&C);
     scanf("%lf",&K);

     if((A>B)&&(A>C)){
       S=A*(double)pow(2.0,K);
       printf("%.0lf\n",S+B+C);
       return 0;
     }
     if((B>A)&&(B>C)){
       S=B*(double)pow(2.0,K);
       printf("%.0lf\n",S+A+C);
       return 0;
     }
     if((C>A)&&(C>B)){
       S=C*(double)pow(2.0,K);
       printf("%.0lf\n",S+A+B);
       return 0;
     }
     if((A==B)&&(B<C)){
       S=C*(double)pow(2.0,K);
       printf("%.0lf\n",S+A+B);
       return 0;
     }
     if((A==B)&&(B>C)){
       S=B*(double)pow(2.0,K);
       printf("%.0lf\n",S+A+C);
       return 0;
     }
     if((A==C)&&(A>B)){
       S=A*(double)pow(2.0,K);
       printf("%.0lf\n",S+B+C);
       return 0;
     }
     if((A==C)&&(A<B)){
       S=B*(double)pow(2.0,K);
       printf("%.0lf\n",S+A+C);
       return 0;
     }
     if((B==C)&&(C>A)){
       S=C*(double)pow(2.0,K);
       printf("%.0lf\n",S+A+B);
       return 0;
     }
     if((B==C)&&(C<A)){
       S=A*(double)pow(2.0,K);
       printf("%.0lf\n",S+B+C);
       return 0;
     }
     if((A==B)&&(B==C)){
       S=A*(double)pow(2.0,K);
       printf("%.0lf\n",S+B+C);
       return 0;
     }
 }


Measured memory_bytes: 128
#include <stdio.h>

int main(void) {
  int d, n;

  scanf("%d %d", &d, &n);

  if (d == 2) {
    if (n == 100) {
      printf("1010000\n");
    }else {
      printf("%d\n", n * 10000);
    }
  }else if (d == 1) {
    if (n == 100) {
      printf("10100\n");
    }else {
      printf("%d\n", n * 100);
    }
  }else {
    if (n == 100) {
      printf("101\n");
    }else {
      printf("%d\n", n);
    }

  }

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

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

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

    int ans = 100010;
    for (int i = 0; i <= n; i++){
        int six = i, nine = n - i, cnt = 0;
        int power6 = 1, power9 = 1;
        while(power6 < six) power6 *= 6;
        while(six){
            cnt += six / power6;
            six %= power6;
            power6 /= 6;
        }

        while(power9 < nine) power9 *= 9;
        while(nine){
            cnt += nine / power9;
            nine %= power9;
            power9 /= 9;
        }

        ans = min(ans, cnt);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var S = ReadLine();
        var T = ReadLine();

        static string Rotate(string s, int n) => new string(Enumerable.Range(0, s.Length).Select(i => s[(i + n) % s.Length]).ToArray());

        var ans = Enumerable.Range(0, S.Length).Select(i => Rotate(S, i)).Contains(T) ? "Yes" : "No";

        WriteLine(ans);
    }
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}


Measured memory_bytes: 26748
#include<stdio.h>
#include<math.h>
 
int calc()
{   
    double ax,ay,ar,bx,by,br,d,r1,r2;
    scanf("%lf%lf%lf%lf%lf%lf",&ax,&ay,&ar,&bx,&by,&br);
    d=((ax-bx)*(ax-bx))+((ay-by)*(ay-by));
    r1=(ar+br)*(ar+br);
    r2=(ar-br)*(ar-br);
    if(d<=r1 && d>=r2)
        return 1;
    else if(d<r2 && ar>=br)
        return 2;
    else if(d<r2 && ar<=br)
        return -2;
    else
        return 0;
}
 
int main()
{
    int n;
    scanf("%d",&n);
    while((n--) > 0)
        printf("%d\n",calc());
    return 0;
}

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

int32_t main() {
 
	int n;	cin >> n;
	string s;	cin >> s;
	
	int cnt = 1;
	
	for(int x=1;x<n;x++){
		if(s[x] != s[x-1]){
			cnt++;
		}
	}
	
	cout << cnt;
 
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

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

    vector<int> b;
    inputVector(b, N);

    vector<int> ret;
    while (!b.empty()) {
        int num = -1;
        rep(i, b.size()) {
            if (b[i] == i + 1) {
                num = i;
            }
        }
        if (num == -1) {
            cout << -1 << endl;
            return 0;
        }
        ret.push_back(num + 1);
        b.erase(b.begin() + num);
    }

    reverse(all(ret));

    for (int num : ret) cout << num << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <cstdlib>
#include <set>
#include <stack>
#include <queue>
using namespace std;

#define X first
#define Y second
#define N 100010
#define M 400010
typedef long long ll;
typedef pair<int,int> pii;
const int Mod=1000000007;

int n,L;
int a[N];

int main()
{
	//freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
	
	bool flag=false; int d;
	scanf("%d%d",&n,&L);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<n;i++) if (a[i]+a[i+1]>=L) flag=true,d=i;
	if (!flag) printf("Impossible\n");
	else
	{
		printf("Possible\n");
		for (int i=1;i<d;i++) printf("%d\n",i);
		for (int i=n-1;i>=d;i--) printf("%d\n",i);
	}
	return 0;
}


Measured memory_bytes: 1152
s = input()
yymm = 1
mmyy = 1
yymm2 = 1
mmyy2 = 1
if int(s[0])*10 + int(s[1])>12 or int(s[0])*10 + int(s[1])<=0:
    mmyy = 0
else:
    yymm = 1
    mmyy = 1
if int(s[2])*10 + int(s[3])>12 or int(s[2])*10 + int(s[3])<=0:
    yymm2 = 0
else:
    yymm2 = 1
    mmyy2 = 1
ans1 = mmyy * mmyy2
ans2 = yymm * yymm2
if ans1 == 1 and ans2 == 0:
    print("MMYY")
elif ans1 == 0 and ans2 == 1:
    print("YYMM")
elif ans1 == 1 and ans2 == 1:
    print("AMBIGUOUS")
else:
    print("NA")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define PII pair<int, int>
#define LL long long
using namespace std;
const int MAXN = 500005;
const LL INF = (LL)1e9 + 5;
const LL MOD = 1000000007;

LL N, a[MAXN], sum[MAXN], dp[MAXN], ans;
LL dp_sum[1 << 20], cntz[MAXN], pre[1 << 20];

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

	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> a[i];
		sum[i] = sum[i - 1] ^ a[i];
	}
	
	dp[0] = 1;
	for (int i = 1; i <= N; i++) {
		if (pre[sum[i]] == 0) {
			dp[i] = 1;
		}
		else {
			dp[i] = ((dp[pre[sum[i]]] - 1) + dp_sum[sum[i]] * (cntz[i - 1] - cntz[pre[sum[i]] - 1])) % MOD;
//			cout << "Add " << dp_sum[sum[i]] * (cntz[i - 1] - cntz[pre[sum[i]] - 1]) << ' ' << dp[pre[sum[i]]] - 1 << '\n';
//			cout << "Before " << i << " get " << dp[i] << '\n';
			if (sum[i] == 0) dp[i] = (dp[i] - dp[pre[sum[i]]]) % MOD;
//			cout << "After " << i << " get " << dp[i] << '\n';
			dp[i] = (dp[i] + 1) % MOD;
//			dp[i] = 1;
//			for (int j = 1; j < i; j++) {
//				if (sum[j] == sum[i]) {
//					for (int k = j + 1; k < i; k++) {
//						if (sum[k] == 0) {
//							dp[i] = (dp[i] + dp[j]) % MOD;
//						}
//					}
//				}
//			}
		}
		
		pre[sum[i]] = i;
		cntz[i] = cntz[i - 1] + (sum[i] == 0);
		dp_sum[sum[i]] = (dp_sum[sum[i]] + dp[i]) % MOD;
		if (sum[N] == 0) ans += dp[i];
//		cout << "At " << i << " get " << dp[i] << '\n';
	}
	
	if (sum[N] != 0) ans = dp[N];
	cout << (ans % MOD + MOD) % MOD << '\n';

	return 0;
}

Measured memory_bytes: 32256
#include <iostream>

using namespace std;

int s(int n) {
    int s = 0;
    while (n != 0) {
        s += n % 10;
        n /= 10;
    }
    return s;
}

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

    if (n % s(n) == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <time.h> 
#include <algorithm>
#include <string>
using namespace std;

int main(){
    int i, j = 0, a, b, c;
    cin >> a >> b >> c ;
    for(i=a; i<b+1; i++){
        if(c%i == 0) j++;
    }
    cout << j << endl;
    return 0;
    
}

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

int a, b, c;

int hantei(int i, int j, int k){
    if(a+b==c || a+c==b ||b+c==a){
        return 1;
    }else{
        return 0;
    }
}

int main (){
    cin >> a >> b >> c;
    if(hantei(a,b,c)==1){
        cout << "Yes";
    }else{
        cout << "No";
    }
    
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if(n ==1){
            System.out.println("Hello World");
        }else{
        int a = sc.nextInt();
        int b = sc.nextInt();
            System.out.println(a+b);
        }
    }

}


Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>
#include<stack>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
ll a[70000]={0};
int main(){
	ll n;
	cin>>n;
	ll t=(ll)sqrt(n);
	t++;
	ll i,j,k;
	for(i=1;i<=t;i++)
		for(j=1;j<=t;j++)	
			for(k=1;k<=t;k++)
				a[i*i+j*j+k*k+i*j+i*k+j*k]++;
	for(i=1;i<=n;i++)
		cout<<a[i]<<endl;
}


Measured memory_bytes: 3836
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

void print_edge(int W) {
  cout << '#';
  REP(i, W) cout << '#';
  cout << '#' << endl;
}

int main() {
  int H, W;
  cin >> H >> W;
  print_edge(W);
  REP(i, H) {
    string a;
    cin >> a;
    cout << "#" << a << "#" << endl;
  }
  print_edge(W);
  return 0;
}


Measured memory_bytes: 3552
#include<iostream>
#include <string>
#include <vector>
#include<algorithm>

using namespace std;

int main(){
  int N;
  int d[1000000];
  cin >> N;
  for(int i=0;i<N;i++) cin >> d[i];
  int M = (int)(N/2);
  sort(d, d+N);
//  for(int i=0;i<N;i++) cout << d[i] << endl;
  cout << d[M]-d[M-1] << endl;

}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;


int main() {

    ll n,m; cin >> n >> m;
    ll ans = 1;
    if(n == m){
        for(int i = 1; i <= n; i ++){
            ans = (ans*i)%1000000007;
        }
        for(int i = 1; i <= m; i ++){
            ans = (ans*i)%1000000007;
        }
        cout << (ans*2)%1000000007;
    }else if(abs(n-m) == 1){
        for(int i = 1; i <= n; i ++){
            ans = (ans*i)%1000000007;
        }
        for(int i = 1; i <= m; i ++){
            ans = (ans*i)%1000000007;
        }
        cout << ans%1000000007;
    }else{
        cout << 0;
    }
    return 0;
}


Measured memory_bytes: 3552
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
#define nl '\n'

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

const int N=2e5+11;
const int M=1e5+1;
const int inf=2e9+1;
const ld EPS=1e-6;
const ll INF=1e18;
const ll mod=/*998244353*/1e9+7;
const int dx[8]={0,0,-1,1,-1,1,1,-1};
const int dy[8]={-1,1,0,0,1,-1,1,-1};

ll a[N];

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0),cout.tie(0);
  int n;
  cin>>n;
  ll sum=0;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    sum+=a[i];
    sum%=mod;
  }
  ll ans=0;
  for(int i=1;i<=n;i++){
    sum=(sum-a[i]+mod)%mod;
    ll res=(sum*a[i])%mod;
    ans=(ans+res)%mod;
  }
  cout<<ans;
}


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

#define OnlineJudge1

#define loop(x,a,n) for(int x = a;x < n;x++)
#define NumofDigits(n) ((int)log10(n)+1)
#define CountofNumber(array,n,x)  (upper_bound(array, array+n, x)-lower_bound(array, array+n, x))
#define readline(s) getline(cin,s)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define EPS 1e-7
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,ll> pill;
typedef pair<ll,ll> pll;

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

#define time__(d) \
    for ( \
        auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \
        blockTime.second; \
        debug("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false \
    )

void init(){
    cin.tie(0);
    ios::sync_with_stdio(0);
#ifdef OnlineJudge
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
}

int main(){
    init();

    double w, h, x, y;   cin >> w >> h >> x >> y;

    cout << fixed << setprecision(9) << (w * h) / 2 << " " << (w == x * 2 && h == y * 2);
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

//#include "stdafx.h"
#include "iostream"
#include "fstream"
#include "algorithm"
#include "iomanip"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "map"
#include "set"
#include "list"
#include "deque"
#include "complex"
#include "bitset"
#include "cmath"
#include "unordered_set"
#include "unordered_map"
#include "iterator"
#include <ctime>
#include <cassert>
#include "numeric"
#include <cstdio>
#include "random"
#include "chrono"
#include "cstring"

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target_ans("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

//#define f(i,n) for(int i=0; i<n;i++)
//#define rf(i, n) for(int i=n-1;i>=0;i--)
//#define forn(i, j, n) for(int i=j; i<n; i++)
//#define ff(i, j, n) f(i, n)f(j, n)
#define pb emplace_back
#define maxi(a,b) a = max(a, b);
#define mini(a,b) a = min(a, b);
#define endl '\n'

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;
//typedef long long ll;
typedef long double ld;

#define int long long
//#define int unsigned int
#define double ld
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef vector<char> vc;
typedef vector<vi> vvi;

template<class T>
void show(const vector<T> &a)
{
	for (T x : a)
		cout << x << " ";
	cout << endl;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

vi xx = { 1, 0, -1, 0 };
vi yy = { 0, 1, 0, -1 };
string dir = "LRUD";

const int N = 3e5 + 50, oo = 2e18 + 500;
//const int mod = 998244353;
const int mod = 1e9 + 7;
//const int mod = 1e9 + 9;
const double eps = 1e-6, PI = 2 * acos(0.0);
int n, m, k;
long long cnt = 0;
int lg = 18;
vi g[N];
//vi rg[N];
vi visit(N, 0);


signed main()
{
	ios::sync_with_stdio(0);
	cout.tie(0); cin.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	string s;
	cin >> s;

	n = SZ(s);
	vi pref(n, 0);
	vi suf_mn(n+1, oo);

	for (int i = 0; i < n;i++)
	{
		pref[i] = (s[i] == 'g' ? 1 : -1);
		if (i) pref[i] += pref[i - 1];
	}

	for (int i = n - 1; i >= 0; i--)
	{
		suf_mn[i] = pref[i];
		mini(suf_mn[i], suf_mn[i+1]);
	}

	cnt = 0;
	for (int i = 0; i < n; i++)
	{
		if (s[i] == 'g' && suf_mn[i] - cnt - 2 >= 0)
		{
			cnt += 2;
		}
	}

	cout << cnt/2;
}



Measured memory_bytes: 13812
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

int ans[55];

int main()
{
    int n,a,b;
    cin>>n;
    int result=0;
    for (int i=0;i<n;i++){
        cin>>a>>b;
        result+=b-a+1;
    }
    cout<<result<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	n= sizeof(a)/sizeof(a[0]);
	sort(a,a+n);
	double sum=0.0;
	sum=float(a[0]+a[1])/2;
	for(int i=2;i<n;i++)
	sum=(sum+a[i])/2;	
	cout<<fixed<<setprecision(6)<<sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000

int MOD=1000000007;
int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}

int gyaku(int n){
    return modpow(n,MOD-2);
}
////////////////////////////////////////////////////////////

signed main() {
  int k,s;
  cin>>k>>s;
  int ans=0;
  rep(i,k+1){
    rep(j,k+1){
      if(s-i-j>=0&&s-i-j<=k)ans++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N,M;
    cin >> N >> M;
    
    vector<int> A;
    vector<int> n;

    int a,b;
    for(int i=0;i<M;i++){
        cin >> a >> b;
        if(a==1)A.push_back(b);
        else if(b==N)n.push_back(a);
    }
    if(A.size()==0 || n.size()==0){
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    sort(A.begin(),A.end());
    sort(n.begin(),n.end());
    bool flag=false;
    for(int i=0;i<A.size();i++){
        auto itr=lower_bound(n.begin(),n.end(),A[i]);
        if(*itr==A[i]) {
            flag = true;
            break;
        }
    }
    if(flag) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
    
}

Measured memory_bytes: 1276
#include<stdio.h>
#define N 100
int main(){
  int a[N],x,i,flag=0,num,num1=0;

  scanf("%d",&x);
  for(i=0;i<x;i++)
    scanf("%d",&a[i]);
  while(1){
    flag=0;
    for(i=x-1;i!=0;i--){
      if(a[i]<a[i-1]){
	num=a[i-1];
	a[i-1]=a[i];
	a[i]=num;
	flag=1;
	num1++;
	continue;
      }
    }
    if(flag==0)
      break;
  }
  for(i=0;i<x;i++){
    if(i==x-1){
      printf("%d",a[i]);
      break;
    }
    printf("%d ",a[i]);
  }
  printf("\n");
  printf("%d\n",num1);
  return 0;
}
    



Measured memory_bytes: 2144
#!/usr/bin/env python
N, T = map(int, input().split())
B = [[int(i) for i in input().split()] for i in range(N)]

m = [e[0] for e in B if e[1] <= T]

if len(m) == 0:
    print('TLE')
else:
    print(min(m))

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

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define X first
#define Y second

using namespace std;

int solve();

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifdef DEBUG
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif // DEBUG
    solve();
    return 0;
}

ll n, p;
ll ans = 1;

ll Pow(ll x, ll y)
{
    if (y == 0)
        return 1;
    if (y % 2 == 0)
    {
        ll ans = Pow(x, y / 2);
        return ans * ans;
    }
    return Pow(x, y - 1) * x;
}

int solve()
{
    cin >> n >> p;
    if (n == 1)
    {
        cout << p << endl;
        return 0;
    }
    for (int i = 2; i * 1ll * i <= p; i++)
    {
        int cnt = 0;
        while (p % i == 0)
        {
            p /= i;
            cnt++;
        }
        cnt /= n;
        ans *= Pow(i, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <queue>

using namespace std;

const int hw_max = 1000 + 5;
char graph[hw_max][hw_max];
int sign[hw_max][hw_max];
int h, w, n, ans;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
struct node
{
    int x;
    int y;
    int time;
} start;

void BFS(node op, char ed)
{
    queue <node> process;
    process.push(op);
    sign[op.x][op.y] = 1;
    while(!process.empty())
    {
        node now = process.front();
        process.pop();
        for(int i = 0; i < 4; i ++)
        {
            node next = now;
            next.x += dx[i];
            next.y += dy[i];
            next.time ++;
            if(next.x >= 0 && next.x < h && next.y >= 0 && next.y < w && graph[next.x][next.y] != 'X' && !sign[next.x][next.y])
            {
                if(graph[next.x][next.y] == ed)
                {
                    ans += next.time;
                    next.time = 0;
                    start = next;
                        return;
                }
                else
                {
                    process.push(next);
                    sign[next.x][next.y] = 1;
                }
            }
        }
    }
}

int main()
{
    while(~scanf("%d %d %d", & h, & w, & n))
    {
        getchar();
        for(int i = 0; i < h; i ++)
        {
            for(int j = 0; j < w; j ++)
            {
                   scanf("%c", & graph[i][j]);
                   if(graph[i][j] == 'S')
                   {
                    start.x = i;
                    start.y = j;
                    start.time = 0;
                   }
            }
            getchar();
        }
        ans = 0;
        for(int i = 1; i <= n; i ++)
        {
            memset(sign, 0, sizeof(sign));
            BFS(start, '0' + i);
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 8108
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

// a^n%mod
template<class T=int64_t>
T bin_pow(T a,T n,T mod=1e9+7){
    T ans=1;
    while(n>0){
        if(n&1) ans=ans*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ans%mod;
}

//a^(-1)(mod)=a^(mod-2)
template<class T=int64_t>
T inv_mod(T a,T mod=1e9+7){
  return bin_pow(a,mod-2);
}

//a!%mod
template<class T=int64_t>
T fact(T a,T mod=1e9+7){
    T ans=1;
    for(int i=2;i<=a;++i){
        ans=ans*i%mod;
    }
    return ans;
}

//nCr%mod
template<class T=int64_t>
T comb(T n,T r,T mod=1e9+7){
    return fact(n)*inv_mod(fact(r)*fact(n-r)%mod)%mod;
}
//nCk%mod　kが小さいとき
template<class T=int64_t>
T nCk(T n,T k,T mod=1e9+7)
{
  if(n-k<k) k=n-k;
  int64_t ans=1;
  for (int64_t i = 0; i < k; ++i)
  {
    ans*=(n-i);
    ans%=mod;
  }
  for (int64_t i = 1; i <= k; ++i)
  {
    ans*=inv_mod(i);
    ans%=mod;
  }
  return ans%mod;
}

int main()
{
  int n,m;
  cin>>n>>m;
  int ans=0;
  if(n<=1&&m<=1) ans=0;
  else if(n<=1) ans=nCk(m,2);
  else if(m<=1) ans=nCk(n,2);
  else  ans=nCk(n,2)+nCk(m,2);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
mod = 10 ** 9 + 7
ans = 0
tmp = 0
for i in range(K-1):
  tmp += i
for i in range(K, N + 2):
  tmp += i - 1
  ans += i * N - tmp * 2 + 1
  ans = ans % mod
print(ans)

Measured memory_bytes: 9216