akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 100001
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<int,ll>Pil;
typedef pair<P1,ll> P2;
typedef list<int> li;
typedef list<li> lli;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	ll a;
	int b;
};
ll t=0;

int main(){

	int n;
	cin>>n;
	for(int i=1; i<n; i++){
		for(int j=1; j<n; j++){
			if(i*j>=n)break;
			t++;
		}
	}
	cout<<t<<endl;

	return 0;
}


Measured memory_bytes: 3672
S=input()
for i in range(len(S)-1):
  if(S[i]==S[i+1]):
    print(i+1,i+2);exit()
for i in range(len(S)-2):
  if(S[i]==S[i+2]):
    print(i+1,i+3);exit()
print(-1,-1)

Measured memory_bytes: 3188
N = int(input())
lstA = list(map(int, input().split()))

cntMinus = sum([1 for a in lstA if a < 0])
lstB = [abs(a) for a in lstA]

if cntMinus % 2 == 0:
    ans = sum(lstB)
else:
    ans = sum(lstB) - 2 * min(lstB)
print(ans)

Measured memory_bytes: 14332
N, Q = map(int, input().split())
S = input()

c = [0] * N

for i in range(N-1):
    if S[i:i+2] == 'AC':
        c[i+1] = c[i] + 1
    else:
        c[i+1] = c[i]

for _ in range(Q):
    l, r = map(int, input().split())
    print(c[r-1] - c[l-1])

Measured memory_bytes: 6060
#include <bits/stdc++.h>
using namespace std;
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl

string s,t;
int l1,l2;
int dp[3001][3001];
int path[3001][3001];
int rec(int b,int e)
{
   if(b==l1 or e==l2)
   {
        return 0;
   }
   if(dp[b][e] == -1)
   {
        if(s[b] == t[e])
        {
            path[b][e] = 0;
            dp[b][e] = 1 + rec(b+1,e+1);
        }
        else
        {
            dp[b][e] = rec(b+1,e);
            path[b][e] = 1;
            if(dp[b][e] < rec(b,e+1))
            {
                dp[b][e] = rec(b,e+1);
                path[b][e] = 2;
            }
        }
        return dp[b][e];
   }
   else
    return dp[b][e];
}
void pathprint(int b,int e)
{
    if(b == l1 or e == l2)
        return;
    if(s[b] == t[e])
        cout<<s[b];
    if(path[b][e] == 0)
        pathprint(b+1,e+1);
    if(path[b][e] == 1)
        pathprint(b+1,e);
    if(path[b][e] == 2)
        pathprint(b,e+1);
}
int main()
{
        
        cin>>s>>t;
        l1=s.length();
        l2=t.length();
        memset(dp,-1,sizeof(dp));
        rec(0,0);
        pathprint(0,0);
    
    return 0;
}

Measured memory_bytes: 70912
#include<bits/stdc++.h>
using namespace std;
int a[10000000];
int main()
{
    int h,n;
    cin>>h>>n;
    int sum=0;
    for (int i = 0; i < n; ++i) {
        cin>>a[i];
        sum+=a[i];
    }
    if(sum>=h) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 640
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==
*/

main :-
    get_number(N, A),
    X is N * N - A,
    writeln(X).


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

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        long long x;
        cin >> x;
        while (1)
        {
            if (x % 2 != 0) break;
            ans++;
            x = x / 2;
        }
    }

	cout << ans << "\n";
	return 0;
}


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

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    string s; cin >> s;
    string bad = "Bad";
    string good = "Good";
    if (s[0] == s[1] or s[1] == s[2] or s[2] == s[3]){
        cout << bad << endl;
    } else {
        cout << good << endl;
    }
    return 0;
}

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

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> H(N);
    for(int i= 0; i < N; i++){
        cin >> H.at(i);
    }

    long long int A = 0;
    sort(H.begin(), H.end());
    reverse(H.begin(), H.end());

    for(int i = K; i < N; i++){
        A += H.at(i);
    }

    cout << A << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[5];
    int i,p;
    for(i=0; i<5; i++)
        cin>>a[i];
    for(i=0; i<5; i++)
    {
        if(a[i]==0)
        {
            p=i+1;
            break;
        }
    }
    cout<<p;
    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define lli long long int
#define pb push_back
#define mod 1000000007
#pragma GCC optimize ("-O3")
#define mod2 998244353
#define MAXN 1000000000
#define v32 vector<int>
#define v64 vector<lli>
#define v1024 vector <vector <int>>
#define v4096 vector <vector <lli>>
#define vt vector
#define f(x, y, z) for (lli x = y; x < z; x++)
#define fd(x, y, z) for (lli x = y; x > z; x--)
#define lb lower_bound
#define ld long double
#define m64 map<lli,lli>
#define m32 map<int,int>
#define m64it map<lli,lli>::iterator
#define m32it map<int,int>::iterator
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ist insert
#define endl "\n"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define p_q priority_queue 
#define min_p_q priority_queue <int,vt <int>,greater <int>>
using namespace std;
using namespace __gnu_pbds; 
template <typename T> 
void DEBUG_ARR(vt<T> a,char c)
{
	f(i,0,a.size())cout<<a[i]<<c;
	cout<<"\n";
}

lli tmod(lli x,lli m){return (x%m+m)%m;}//USE AT YOUR OWN RISK
lli power(lli x, lli y) 
{
    lli res = 1;  
   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1; 
        x = (x*x)%mod;  
    }
    if(res<0)
       res+=mod; 
    return res; 
}


// lli fact[2000009];
// lli ncr(lli n,lli r){
//     lli ans=fact[n];
//     if(r>n)return 0;
//     ans=(ans*power(fact[n-r],mod-2))%mod;
//     ans=(ans*power(fact[r],mod-2))%mod;
//     return ans;
// }

int main() 
{ 
    fastio;
    // fact[0]=1;
    // f(i,1,2000009)fact[i]=(fact[i-1]*i)%mod;
    int t;
    // cin>>t;
    t=1;
    // int temp=t;
    while(t--){
      ld l;cin>>l;
      cout<<setprecision(18)<<(l/3)*(l/3)*(l/3)<<"\n";
    }

    return 0; 	
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def SMI(): return input().split()
def SLI(): return list(input())

def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')

# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

from fractions import gcd

def solve():
    N = II()
    A = LI()

    # 左から累積和的gcd
    L = [1] * N
    L[0] = A[0]
    for i in range(1, N):
        L[i] = gcd(A[i], L[i-1])

    # 右から累積和的gcd
    R = [1] * N
    R[-1] = A[-1]
    for i in range(N-2, -1, -1):
        R[i] = gcd(A[i], R[i+1])

    # print(L)
    # print(R)
    ans = 1
    for i, a in enumerate(A):
        l = i - 1
        r = i + 1
        if l < 0:
            ans = max(ans, R[r])
        elif r >= N:
            ans = max(ans, L[l])
        else:
            ans = max(ans, gcd(L[l], R[r]))
    print(ans)

if __name__ == '__main__':
    solve()


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

int main() {
  int n;
  cin >> n;
  getchar();
  for(int i = 0; i < n; i++) {
    string snake;
    getline(cin, snake);

    string ans = "NA";
    if(snake[0] == '>' && snake[1] == '\'' && snake.length() >= 6) {
      int shape = 0;
      for(int i = 2; i < snake.length(); i++) {
	if(i+1 >= snake.length()) {
	  if(snake[i] == '~') ans = "A";
	} else {
	  if(snake[i] != '=' && snake[i] != '#') break;
	  if(snake[i] == '#') {
	    if(shape == 1) break;
	    else {
	      shape++;
	      if(i-2 != (double)(snake.length()-4)/2) break;
	    }
	  }
	}
      }
    } else if(snake[0] == '>' && snake[1] == '^' && snake.length()%2 == 0 && snake.length() >= 6) {
      for(int i = 3; i < snake.length(); i+=2) {
	if(i+2 >= snake.length()) {
	  if(snake[i-1] == '~' && snake[i] == '~') ans = "B";
	} else {
	  if(snake[i-1] != 'Q' || snake[i] != '=') break;
	}
      }
    }

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

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

int main() {
	ll N, A, B;
	cin >> N >> A >> B;
	ll sml = N * A + (B - A);
	ll lrg = N * B - (B - A);
	if(A > B || (N == 1 && A != B)) cout << 0 << endl;
	else cout << lrg - sml + 1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>//stayCalmNeverSettle
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define endl "\n"
using namespace std;
typedef long long ll;

void solve(){
    int n;
    cin >> n;
    vector<ll> a(n);
    int i;
    for(i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end(),greater<ll>());
    vector<ll> b;
    b.push_back(a[0]);
    for(i=1;i<n;i++){
        b.push_back(a[i]);
        b.push_back(a[i]);
    }
    ll ans = 0;
    for(i=0;i<n-1;i++){
        ans+=b[i];
    }
    cout << ans << endl;
}   
    
int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
    //     freopen("output.txt","w",stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

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

int main(){
    int N;
    int total = 1, part = 1;
    cin >> N;
    for(int i = 0; i < N; ++i){
        int a;
        cin >> a;
        total *= 3;
        if(a % 2 == 0) part *= 2;
    }
    cout << total - part << endl;
    return 0;
}


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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
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 (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;
char canvas[50][50];
int h,w;
int dfs(int x,int y,int depth){
    if(x<0||y<0||x>=w||y>=h){
        return depth-1;
    }
    if(canvas[y][x]=='.'){
        return  depth-1;
    }
    depth++;
    canvas[y][x]='.';
    return max(max(dfs(x+1,y, depth+1),dfs(x-1,y, depth+1)),
            max(dfs(x,y+1, depth+1),dfs(x,y-1, depth+1)));
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cin>>h>>w;

rep(i,h){
    rep(j,w){
        cin>>canvas[i][j];
    }
}
string ans="Yes";
rep(i,h){
    rep(j,w){
        if(canvas[i][j]=='#'){
            if(!dfs(j,i,-1)){
                canvas[i][j]='#';
                ans="No";
            }
        }
    }
}
cout<<ans<<endl;
return 0;
}

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

using namespace std;

typedef long long ll;

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

	string s;
	cin >> s;

	int n = s.size();
	vector<ll> a(n, 0);

	char c = 'x';
	int cnt = 1;
	for(int i = n - 1; i >= 0; i--){
		if(c == s[i]){
			cnt++;
		} else{
			cnt = 1;
			c = s[i];
		}
		a[i] = cnt;
	}

	ll ans = 0;
	ll tmp = 0;
	if(s[0] == '<'){
		ans += 0;
	}else{
		tmp = a[0];
		ans += tmp;
	}

	rep(i, n){
		if(i < n - 1 && s[i] == '<' && s[i+1] == '>'){
			tmp = max(tmp + 1, a[i+1]);
		}else if(i > 0 && s[i-1] == '<' && s[i] == '>'){
			tmp = min(tmp - 1, a[i] - 1);
		}else if(s[i] == '<'){
			tmp++;
		}else if(s[i] == '>'){
			tmp--;
		}
		if(s[i] == '>' && s[i+1] == '<'){
			tmp = 0;
		}

		// cout << tmp << " ";
		ans += tmp;
	}
	// cout << endl;

	cout << ans << endl;
}


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

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

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

int isprime(int x){
  if(x<=1) return 0;
  for(int i=2;i*i<=x;i++)
    if(x%i==0) return 0;
  return 1;
}

int solve(){
  vi like;
  rep(x, 1, 100000){
    if (x%2==0) continue;
    if (isprime(x) and isprime((x+1)/2)){
      like.pb(x);
    }
  }

  dump(like);

  int q;cin>>q;
  int l,r;
  rep(i, q){
    cin>>l>>r;
    int d=upper_bound(all(like), r) - lower_bound(all(like), l);
    cout << d << endl;
  }

  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


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

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

    bool even = true;
    rep(i, n) {
        ll a;
        cin >> a;
        if (a % 2 != 0) even = false;
    }

    if (even)
        cout << "second" << endl;
    else
        cout << "first" << endl;
    return 0;
}


Measured memory_bytes: 256
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p){ os << "(" << p.first << ", " <<  p.second << ")"; return os; }

int a, b;
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a >> b;
    cout << max({a + b, a - b, a * b}) << endl;
}


Measured memory_bytes: 256
a = []

n = gets.to_i
a = gets.split.map(&:to_i)
q = gets.to_i

for i in 0...q
	b, m, e = gets.split.map(&:to_i)
	c = []
	for i in 0...(e-b)
		c[i] = a[b+i]
	end
	for i in 0...(e-b)
		j = (i+e-m) % (e-b)
		a[b+j] = c[i]
	end
end

for i in 0...(n-1)
	print "#{a[i]} "
end

print "#{a[n-1]}\n"


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

int main(){

    string s;
    cin >> s;
    bool ok = 0;
    char ch = 'C';
    for(int i=0;i<s.size();i++){
        if(s[i]==ch){
            if(ch=='C') ch = 'F';
            else {
                ok = 1;
                break;
            }
        }
    }
    if(ok){
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }

}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;

// 繰り返し二乗法 (O(logn))
ll power(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % MOD;
    }
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}

int m, n;

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_B&lang=jp
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> m >> n;

  cout << power(m, n) << endl;
  return 0;
}


Measured memory_bytes: 3192
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

ll n, k, now, ans;
vector<ll> a, b;
bool solve(ll index) { //条件判定
	ll now = 0;
	REP(i, n) {
		now += max(0ll, a[i] - index / b[i]);
	}
	if (now <= k)return true;
	return false;
}

ll nibutan() { //めぐる式

	ll ng = -1; //最大値ならs.size()
	ll ok = 1e13; // 最大値なら0

	while (abs(ok - ng) > 1) {
		ll mid = (ok + ng) / 2;

		if (solve(mid)) ok = mid;
		else ng = mid;
	}
	return ok; //満たさない最大ならng
}
int main() {
	cin >> n >> k;
	a.resize(n);
	b.resize(n);
	REP(i, n)cin >> a[i];
	REP(i, n)cin >> b[i];
	sort(ALL(a));
	sort(ALL(b), greater<ll>());
	cout << nibutan() << endl;
}

Measured memory_bytes: 3328
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 

	public static void main(String[] args) { 
		Scanner input = new Scanner(System.in);
		String x = input.next();
		for (int i = 0; i < x.length(); i++) {
			if (x.charAt(i)=='?') System.out.print("D");
			else System.out.print(x.substring(i,i+1));
		}
	}	
}

Measured memory_bytes: 47220
#include<bits/stdc++.h>
using namespace std;
string s1,s2;
int a[27],b[27];
bool yong[27];
int c[100005],shu;
int main()
{
    cin>>s1>>s2;
    int len1=s1.size();
    for(int i=0;i<len1;i++)
    {
        if(a[s1[i]-'a'+1]==0)
        {
                if(s1[i]==s2[i])
                {
                    a[s1[i]-'a'+1]=s2[i]-'a'+1;
                    yong[s2[i]-'a'+1]=1;
                }
                else
                {
                    if(yong[s2[i]-'a'+1]==1)
                    {
                        printf("No");return 0;
                    }
                    else
                    {
                    a[s1[i]-'a'+1]=s2[i]-'a'+1;
                    yong[s2[i]-'a'+1]=1;
                    }
                }
        }
        else
        {
            if(a[s1[i]-'a'+1]!=s2[i]-'a'+1)
            {
                    printf("No");return 0;

            }
        }
    }
    printf("Yes");
}


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

int main(){
    int i;
    int c[26] = {};
    string w;
    cin >> w;
    for(i=0; i<w.size(); i++){
        c[(int)w[i]-'a']++;
    }
    for(i=0; i<26; i++){
        if(c[i]%2 == 1){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 256
// Last Change: 06/17/2019 19:05:29.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

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

  ll dist = 0, ipt, ans = 1;
  for (int i = 0; i < N; ++i) {
    cin >> ipt;
    dist += ipt;
    if (dist <= X) {
      ++ans;
    }
  }
  cout << ans << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 888
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

s = input()
t = input()

A = [[] for i in range(26)]

for i in range(len(s)):
    A[ord(s[i]) - ord("a")].append(i+1)

from bisect import bisect_left as bl
'''index  =  bl(list,num)'''
nagasa = len(s)
ans = 0
ima = 0
mae = 0
for i in range(len(t)):
    tmp = bl(A[ord(t[i]) -ord("a")],ima+1)
    if tmp == len(A[ord(t[i]) -ord("a")]):
        ans += nagasa - ima
        ima = 0
        tmp = bl(A[ord(t[i]) -ord("a")],ima+1)
        if tmp == len(A[ord(t[i]) -ord("a")]):
            print(-1)
            exit()
    mae = ima
    ima = A[ord(t[i]) -ord("a")][tmp]
    ans += ima - mae
print(ans)



Measured memory_bytes: 45680
get = lambda: int(raw_input().strip())
getl = lambda: raw_input().strip()
gets = lambda: map(int, raw_input().strip().split())
getss = lambda n: [gets() for _ in xrange(n)]

a, b = gets()
print a * b if 1 <= a <= 9 and 1 <= b <= 9 else -1

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

#define int long long
#define forn(i,a,n) for (int i=a; i<n; i++)

int a[200001],b[200001];
int cnt=0;

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

	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	int n,k;
	cin>>n>>k;
	forn(i,0,n){
		cin>>a[i]>>b[i];
		double x=a[i]*a[i]+b[i]*b[i];
		x=sqrt(x);
		if (x<=k)
			cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 6816
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll X;
  cin >> X;
  ll ans = 1;
  for (ll i = 2; i <= 100; ++i) {
    ll check = 2;
    while (pow(i, check) <= X) {
      ans = max((ll)(pow(i, check)), ans);
      check += 1;
    }
  }
  cout << ans << "\n";
}


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

using namespace std;

const int inf = (int)1e9 + 7;

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

    string s;

    cin >> s;

    bool ans = false;

    for (size_t i = 1; !ans && i < s.size (); i++)
        ans |= (s.substr (i - 1, 2) == "AC");

    cout << (ans ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define MOD 1000000007 
#define MOD2 998244353
#define INF 100000000
//#define MOD 922337203685419LL
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <bitset>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <functional>
#include <algorithm>
#include <iterator>
#include <cstdio>
#include <utility>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <chrono>
#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
#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 REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n-1,-1)
#define ALL(obj) (obj).begin(), (obj).end()

inline ll madd(ll a, ll b) {
	a %= MOD;b %= MOD;
	return (a + b) % MOD;
}
inline ll msub(ll a, ll b) {
	a %= MOD;b %= MOD;
	a += MOD;
	return (a - b) % MOD;
}
inline ll mmul(ll a, ll b) {
	a %= MOD;b %= MOD;
	return (a*b) % MOD;
}
inline ll mpow(ll a, ll r) {
	long long res = 1;
	while (r > 0) {
		if (r & 1) res = res * a % MOD;
		a = a * a % MOD;
		r >>= 1;
	}
	return res;
}
inline ll minv(ll a) {
	a %= MOD;
	ll b = MOD, u = 0, v = 1;
	while (a) {
		ll t = b / a;
		b -= t * a; swap(a, b);
		u -= t * v; swap(u, v);
	}
	if (u < 0) u += MOD;
	return u;
}
inline ll mdiv(ll a, ll b) {
	a %= MOD;
	a *= minv(b);
	return a%MOD;
}


//ll fact[]
//inline ll combi(int a, int b) {
//	return mmul(fact[a], mmul(fact_inv[b], fact_inv[a - b]));
//}

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

struct edge { ll to, cost; };


int main() {
	ll power[2501];
	power[0] = 1;
	ll power2[2501];
	power2[0] = 1;
	REP(i, 2500) {
		power[i + 1] = (power[i] * 29) % MOD;
		power2[i + 1] = (power2[i] * 29) % MOD2;
	}

	int n;
	cin >> n;
	char s[5001];
	scanf("%s", s);

	vll hash_list(n + 1);
	vll hash_list2(n + 1);
	ll ha = 0;
	ll ha2 = 0;
	REP(i, n) {
		ha *= 29;
		ha += s[i] - 'a' + 2;
		ha %= MOD;
		ha2 *= 29;
		ha2 += s[i] - 'a' + 2;
		ha2 %= MOD2;
		hash_list[i+1]=ha;
		hash_list2[i+1]=ha2;
	}


	RFOR(j, n/2, 0) {
		unordered_map<ll, int> ma;
		REP(i, n - j + 1) {
			ll x = (hash_list[i + j]+MOD-(hash_list[i]*power[j])%MOD)%MOD;
			if (ma.find(x) == ma.end()) ma[x] = i;
			else if (i >= ma[x] + j) {
				if(((hash_list2[i + j]+MOD2-(hash_list2[i]*power2[j])%MOD2)%MOD2)==((hash_list2[ma[x] + j]+MOD2-(hash_list2[ma[x]]*power2[j])%MOD2)%MOD2)){
					cout << j;
					return 0;
				}
			}
		}
	}

	cout << "0";
	return 0;
}

Measured memory_bytes: 692
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
int check(int x,int y, vvi ch) {
  int flg = 1;
  REP(i,8) {
    if(ch[x][i]==1) {
      flg=0;
      break;
    }
    if(ch[i][y]==1)  {
      flg=0;
      break;
    }
    if(x+i<8&&y+i<8) {
      if(ch[x+i][y+i]==1)  {
      flg=0;
      break;
    }
    }
    if(x-i>=0&&y+i<8) {
      if(ch[x-i][y+i]==1)  {
      flg=0;
      break;
    }
    }
    if(x+i<8&&y-i>=0) {
      if(ch[x+i][y-i]==1)  {
      flg=0;
      break;
    }
    }
    if(x-i>=0&&y-i>=0) {
      if(ch[x-i][y-i]==1)  {
      flg=0;
      break;
    }
    }
  }
  return flg;
}

int main() {
  ll n;
  cin >> n;
  vll a(n),b(n),c(n);
  REP(i,n) cin >> a[i];
  REP(i,n) cin >> b[i];
  REP(i,n) cin >>c[i];
  sort(ALL(a));
  sort(ALL(b));
  sort(ALL(c));
  ll cnt =0;
  REP(i,n) {
    ll x=b[i];
    auto iter1 = lower_bound(ALL(a), x);
    ll s=iter1-a.begin();
    auto iter2 = upper_bound(ALL(c), x);
    ll t=c.end()-iter2;
    cnt+=s*t;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 2688
N = int(input())
S = input()


r = 0
ans = 0
for l in range(N):

    while True:
        # print(S.rfind(S[l:r+1]), S[l:r+1], l, r)
        
        if S.rfind(S[l:r+1]) >= r+1:
            r += 1
            ans = max(ans, r-l)
        else:
            break

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#define llint long long

using namespace std;

llint N;
llint a[200005], b[200005];
vector<llint> vec;

int main(void)
{
	cin >> N;
	for(llint i = 1; i <= N; i++) cin >> a[i];
	for(llint i = 1; i <= N; i++) cin >> b[i];
	
	llint ans = 0;
	for(llint i = 1; i <= 29; i++){
		vec.clear();
		for(llint j = 1; j <= N; j++) vec.push_back( a[j] % (1<<i) );
		sort(vec.begin(), vec.end());
		
		//for(llint j = 0; j < vec.size(); j++) cout << vec[j] << " "; cout << endl;
		
		llint sum = 0;
		for(llint j = 1; j <= N; j++){
			llint B = b[j]%(1<<i);
			if(((1<<(i-1)) - B) >= 0){
				auto l = lower_bound(vec.begin(), vec.end(), ((1<<(i-1)) - B));
				auto r = lower_bound(vec.begin(), vec.end(), ((1<<i) - B));
				sum += r - l;
				sum %= 2;
			}
			else{
				auto l = lower_bound(vec.begin(), vec.end(), ((1<<i) - (B - (1<<(i-1)))));
				sum += vec.end() - l;
				auto r = lower_bound(vec.begin(), vec.end(), (1<<i) - B);
				sum += r - vec.begin();
			}
		}
		sum %= 2;
		ans |= (sum<<(i-1));
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5620
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]

import copy
MAX_SCORE = -float('inf')
MAX_ANS = -1
for K in range(26):
    v = 0
    ans = [0]*D
    L = [0]*26
    for i in range(1, D+1):
        max_score = -float('inf')
        max_idx = 0
        for j in range(26):
            temp = v
            temp += S[i-1][j]
            L_ = copy.copy(L)
            L_[j] = i
            for k in range(26):
                for l in range(i, min(i+K+1, D+1)):
                    temp -= C[k]*(l-L_[k])
            if temp >= max_score:
                max_score = temp
                max_idx = j
        v += S[i-1][max_idx]
        L[max_idx] = i
        for k in range(26):
            v -= C[k]*(i-L[k])
        ans[i-1] = max_idx+1
    if v >= MAX_SCORE:
        MAX_SCORE = v
        MAX_ANS = ans
print(*MAX_ANS, sep='\n')


Measured memory_bytes: 71040
import sys


def main(lines=None):
    # ここは変えない
    if not lines:
        lines = sys.stdin.readlines()
    lines = [line.split() for line in lines]
    a, b, c = [int(e) for inner_list in lines for e in inner_list]
    # ここまで

    answer = 0
    for i in range(a, b + 1):
        if c % i == 0:
            answer += 1
    print(answer)
    # returnするときはstr型にする
    return str(answer)

    # 改行で複数項目をtest出力したい場合
    # print("\n".join(answers))
    # return "\n".join(answers)


def test_main():
    test_inputs = """
1 1 1
""".strip()
    test_inputs = test_inputs.split("\n")
    answer = main(test_inputs)
    expect = """
1
""".strip()

    assert answer == expect


if __name__ == "__main__":
    main()



Measured memory_bytes: 5624
#include <iostream>
#include<cmath>
#include<iomanip>
using namespace std;
#define EPS (1e-10)
bool equals(double x,double y)
{
    return fabs(x-y)<EPS;
}
class Point
{
public:
    double x,y;
    Point(double x=0,double y=0):x(x),y(y) {}
    Point operator+(Point p)
    {
        return Point(x+p.x,y+p.y);
    }
    Point operator-(Point p)
    {
        return Point(x-p.x,y-p.y);
    }
    Point operator*(double k)
    {
        return Point(x*k,y*k);
    }
};
typedef Point Vector;
struct Segment
{
    Vector p1,p2;
};
double norm(Vector a)
{
    return a.x*a.x+a.y*a.y;
}
double abs(Vector a)
{
    return sqrt(norm(a));
}
double dot(Vector a,Vector b)
{
    return a.x*b.x+a.y*b.y;
}
Point projection(Segment s,Point p)
{
    Vector base=s.p2-s.p1;
    double r=dot(p-s.p1,base)/norm(base);
    return s.p1+(base*r);
}
int main()
{
    Segment s;
    cin>>s.p1.x>>s.p1.y>>s.p2.x>>s.p2.y;
    int n;
    cin>>n;
    while(n--)
    {
        Vector p;
        cin>>p.x>>p.y;
        Vector ans;
        ans=projection(s,p);
        cout <<fixed;
        cout<<setprecision(10)<<ans.x<<" "<<setprecision(10)<<ans.y<<endl;
    }
    return 0;
}

Measured memory_bytes: 3276
n, p = gets.chomp.split.map(&:to_i)

if n == 1
  p p
  exit
end

if p == 1
  p 1
  exit
end

i = 0

while true
  if (i+1) ** n > p
    break
  end

  i += 1
end

i.downto(1) do |u|
  if p % (u ** n) == 0
    p u
    exit
  end
end


Measured memory_bytes: 1788
#include<bits/stdc++.h>
 
using namespace std;
 
int main()
{
  long long a,b;
  cin>>a>>b;
  if(a==b)
    cout<<0<<'\n';
  else
  {
  long long k = (a+b)/2;  
  if(abs(a-k)==abs(b-k))
    cout<<k<<'\n';
  else
    cout<<"IMPOSSIBLE"<<'\n';  }
  return 0;
}

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

int K;
string S;

int main(){
  cin >> K >> S;
  if (S.size() > K){
    S = S.substr(0, K);
    S += "...";
  }
  cout << S << endl;
}


Measured memory_bytes: 3636
import collections
N=int(input())
s=[input() for i in range(N)]
M=int(input())
t=[input() for i in range(M)]

table=collections.defaultdict(int)
for x in s:
  table[x]+=1
for x in t:
  table[x]-=1
table=table.values()
table=[x for x in table if x >= 0]
table.append(0)
print(max(table))


Measured memory_bytes: 3316
/*
Problem

Category
二分探索

URL:
https://atcoder.jp/contests/abc077/tasks/arc084_a

考察:
N^2 * log(N)^2 という方法を思いついたが当然間に合わない。

前処理が必要。

scoreB[i]: B[i]より大きい C[j] の数
を求める。 O(N log(N))

これで色々すると
O(N * log(N))
で求りそう

テクニカルな問題として
lower_bound() で入手したイテレータのインデックスが何番目かわからない。
この情報を持つマップを先に作らないとダメそう


Date: 2020/04/12
*/

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long

/* ==== declarations ====== */
// functions
void solve();
void getInput();

// global variables
int N;
vector<int> A, B, C;

/* ======================== */

signed main(){
    getInput();
    solve();
    return 0;
}

void getInput() {
    cin>>N;
    A = vector<int>(N);
    B = vector<int>(N);
    C = vector<int>(N);
    for(int i=0; i<N; ++i) {
        cin>>A[i];
    }
    for(int i=0; i<N; ++i) {
        cin>>B[i];
    }
    for(int i=0; i<N; ++i) {
        cin>>C[i];
    }
}

void solve() {
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    // print(A, B, C);
    
    map<int, int> CtoI;
    
    int ci = 0;
    int bc = 0;
    for(int c: C) {
        if(c==bc) {ci++; continue;}
        CtoI[c] = ci++;
        bc = c;
    }
    // print(CtoI);
    map<int, int> scoreB;
    for(int b: B) {
        auto c = upper_bound(C.begin(), C.end(), b);
        if (c==C.end()) {
            scoreB[b] = 0;
            continue;
        }
        // print(b, *c);
        int idx = CtoI[*c];
        int score = N - idx;
        scoreB[b] = score;
    }

    map<int, int> cumScoreB;
    auto rB = B;
    reverse(rB.begin(), rB.end());

    int cum = 0;
    for(int b: rB) {
        cum += scoreB[b];
        cumScoreB[b] = cum;
    }
    // print(scoreB);
    // print(cumScoreB);

    int ans = 0;
    for(int a: A) {
        auto b = upper_bound(B.begin(), B.end(), a);
        if (b == B.end()) continue;
        ans += cumScoreB[*b];
    }
    cout<<ans<<endl;
    


}




Measured memory_bytes: 22144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  string s[N];
  rep(i,N) cin >> s[i];
  int M;
  cin >> M;
  string t[M];
  rep(i,M) cin >> t[i];
  int useds[N];
  int usedt[M];
  rep(i,N) useds[i]=0;
  rep(i,M) usedt[i]=0;
  int c=0;
  int ans=0;
  rep(i,N){
    if(!useds[i]){
    c=1;
    for(int j=i+1; j<N; j++){
      if(!useds[j]){
	if(s[i].size()==s[j].size()){
	  rep(k,s[i].size()){
	    if(s[i][k]!=s[j][k]) break;
	    if(k==s[i].size()-1){
	      c++;
	      useds[j]=1;
	    }
	  }
	}
      }
    }
    rep(j,M){
      if(!usedt[j]){
	if(s[i].size()==t[j].size()){
	  rep(k,s[i].size()){
            if(s[i][k]!=t[j][k]) break;
            if(k==s[i].size()-1){
	      c--;
              usedt[j]=1;
            }
	  }
	}
      }
    }
    if(c>0) ans=max(c,ans);    
    }
    //    cout << ans << endl;
  }
  cout << ans << endl;   	
  



  
  return 0;
    

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<29;

int main(){
  ll N, M; cin >> N >> M;

  vector<bool> is_acc(N, false);
  vector<ll> n_acc(N, 0), n_pen(N, 0);
  for (ll i = 0; i < M; ++i){
    ll p; string S;
    cin >> p >> S;
    p--;
    if (!is_acc[p]){
      if (S == "WA") n_pen[p]++;
      else {
        is_acc[p] = true;
        n_acc[p]++;
      }
    }
  }
  ll res_acc = 0, res_pen = 0;
  for (int i = 0; i < N; ++i){
    if (is_acc[i]){
      res_acc += n_acc[i];
      res_pen += n_pen[i];
    }
  }
  cout << res_acc << " " << res_pen << endl;
}


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

using namespace std;
using ll = long long;

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

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

  map<char, vector<int>> idx;
  rep(i, s.size()) { idx[s[i]].push_back(i); }

  int cur = -1, loop = 0;
  rep(i, t.size()) {
    auto it = lower_bound(idx[t[i]].begin(), idx[t[i]].end(), cur + 1);
    if (it != idx[t[i]].end()) {
      cur = *it;
    } else {
      cur = -1;
      auto it = lower_bound(idx[t[i]].begin(), idx[t[i]].end(), cur + 1);
      if (it == idx[t[i]].end()) {
        cout << -1 << endl;
        return 0;
      }
      cur = *it;
      ++loop;
    }
  }

  ll ans = (ll)loop * s.size() + cur + 1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1216
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

struct CustomCompare{
    bool operator()(const double& lhs, const double& rhs){
        return lhs > rhs;
    }
};

int main(){
    int n;
    cin >> n;
    priority_queue<double, vector<double>, CustomCompare> queue;
    double a;
    for(int i = 0; i < n; i++){
        cin >> a;
        queue.push(a);
    }
    while(queue.size() != 1){
        double a = queue.top();
        queue.pop();
        double b = queue.top();
        queue.pop();
        queue.push((a + b) / 2.0);
    }
    cout << queue.top() << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include<functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <stack>
#include <deque>
#include <tuple>

#define LL long long
#define pii pair<int,int>
#define pLL pair<LL,LL>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<LL>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<LL>
#define vecpii vector<pii>
#define vecpLL vector<pLL>
#define vecbL vector<bool>
#define endl "\n"
#define REP(e,v) for(auto e:v)
#define rep(i, a, n) for(LL i = a; i < n;i++)



using namespace std;


struct edge {
    LL to,cost;
} ;


struct vertex{
	LL key;
    vector<edge> edges;
};

edge edge_init(LL t,LL cos){
	edge e = {.to = t, .cost = cos};

	return e;

}

typedef vector<vertex> graph;

vector<vertex> graph_init(LL V, LL key[],vector<edge> E[]){

	graph G;

	rep(i,0,V){
		vertex v;
		v.key = key[i];
		rep(j, 0, E[i].size()){
			v.edges.push_back(E[i][j]);
		}
		G.push_back(v);
	}

	return G;

}

void dijkstra(LL s,LL V,vector<vertex> G, LL d[]) {

    priority_queue<pLL, vector<pLL>, greater<pLL> > que;

    fill(d,d+V,LLONG_MAX);
    d[s] = 0;
    que.push(pLL(0, s));

    while (!que.empty()) {
        pLL p = que.top();
        que.pop();
        LL v = p.second;
        if (d[v] < p.first) continue;

        rep(i,0, G[v].edges.size()) {
            edge e = G[v].edges[i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(pLL(d[e.to], e.to));
            }
        }
    }

    return;
}



int inp(){
	int x;
	scanf("%d",&x);
	return x;
}
LL linp(){
	LL x;
	scanf("%lld",&x);
	return x;
}

void outp(int i){
	printf("%d",i);
}

void loutp(LL i){
	printf("%lld",i);
}

LL mod(LL i){
	return i % 1000000007;
}


LL gcd(LL i,LL j){
	if(j != 0)
		return gcd(j, i % j);
	else
		return i;

}

LL A(){

	return 0;
}

LL B(){

	return 0;
}

LL C(){

	return 0;
}

LL D(){
	 LL V, X, Y;

	 cin >> V >> X >> Y;

	 graph G;

	 LL key[V] = {0};
	 vector<edge> E[V];


	 rep(i,0,V-1){
		E[i].push_back(edge_init(i+1,1));
		E[i+1].push_back(edge_init(i,1));
	 }

	 E[X-1].push_back(edge_init(Y-1,1));
	 E[Y-1].push_back(edge_init(X-1,1));
	 G = graph_init(V,key,E);

	 LL d[V][V];//d[i][j]はiからjへの最短距離が入る
	 LL count[V] = {0};

	 rep(i,0,V){
		 dijkstra(i,V,G,d[i]);

	 }

	 rep(i,0,V){
		 rep(j,i+1,V){
			  count[d[i][j]]++;

		 }
	 }

	 rep(i,1,V){
		 cout << count[i] << endl;
	 }

	return 0;
}

LL E(){

	return 0;
}

signed main() {
	//A();
	//B();
	//C();
	D();
	//E();
	return 0;
}


Measured memory_bytes: 32000
#include<bits/stdc++.h>
using namespace std;
long long N,K,h[100001];
int main()
{
	cin>>N>>K;
	for(int i=1;i<=N;i++)
	{
		cin>>h[i];
	}
	h[0]=INT_MAX;
	long long DP[100001];
	DP[1]=0;
	DP[0]=0;
	for(int i=2;i<=N;i++)
	{
		DP[i]=INT_MAX;
		for(int j=1;j<=K&&i-j>0;j++)
		{
			DP[i]=min(DP[i-j]+abs(h[i-j]-h[i]),DP[i]);
		}
	}
	cout<<DP[N]<<endl;
}

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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const ll Mod = 998244353;
const int Maxn = 3e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;
ll Base = 101;

ll mul(ll a, ll b){
	return (a * b) % Mod;
}
bool fl[Maxn];


int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n;
	cin >> n;
	str s;
	cin >> s;
	ll rn = 0;
	ll gn = 0;
	ll bn = 0;
	ll r = 0;
	ll g = 0;
	ll b = 0;
	
	ll rem = n;
	ll ans = 1;
	for(int i = n + n + n - 1; i >= 0; i--){
		char x = s[i];
		if(x == 'R') r++;
		if(x == 'G') g++;
		if(x == 'B') b++;
		if(min({r,g,b}) == 1){
			fl[i] = 1;
			g--;
			b--;
			r--;
		}
	}
	
	r = 0;
	g = 0;
	b = 0;
	ll pa = 0;
	for(int i = 0; i < n + n + n; i++){
		char x = s[i];
		
		if(x == 'R') r ++;
		if(x == 'G') g ++;
		if(x == 'B') b ++;
		
		
		if(fl[i]){
			if(x == 'R') rn++;
			if(x == 'G') gn++;
			if(x == 'B') bn++;
		}
		
		if(min({r,g,b}) == 1){
			ans = mul(ans, mul(rem, pa));
			pa --;
			r--;
			g--;
			b--;
			rem --;
		} else {
			if(!fl[i]){
				if(rn) ans = mul(ans, rn--), pa++;
				else if(gn) ans = mul(ans, gn--), pa++;
				else ans = mul(ans, bn--), pa++;
			}
		}
		//cerr << r << ' ' << g << ' ' << b << ' ' << rem << '\n';
	}
	cout << ans;
	return 0; 
}

/*

                                 ____              ,----..               ,----..
   ,---,                       ,'  , `.           /   /   \             /   /   \
  '  .' \                   ,-+-,.' _ |          /   .     :           /   .     :
 /  ;    '.              ,-+-. ;   , ||         .   /   ;.  \         .   /   ;.  \
:  :       \            ,--.'|'   |  ;|        .   ;   /  ` ;        .   ;   /  ` ;
:  |   /\   \          |   |  ,', |  ':        ;   |  ; \ ; |        ;   |  ; \ ; |
|  :  ' ;.   :         |   | /  | |  ||        |   :  | ; | '        |   :  | ; | '
|  |  ;/  \   \        '   | :  | :  |,        .   |  ' ' ' :        .   |  ' ' ' :
'  :  | \  \ ,'        ;   . |  ; |--'         '   ;  \; /  |        '   ;  \; /  |
|  |  '  '--'          |   : |  | ,             \   \  ',  /          \   \  ',  /
|  :  :                |   : '  |/               ;   :    /            ;   :    /
|  | ,'                ;   | |`-'                 \   \ .'              \   \ .'
`--''                  |   ;/                      `---`                 `---`
                       '---'

*/

Measured memory_bytes: 916