akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int a, b;
	while (cin >> a >> b, a)
	{
		int c = b - a;
		int x, y, z;
		x = c / 1000;
		c %= 1000;
		y = c / 500;
		c %= 500;
		z = c / 100;
		cout << z << " " << y << " " << x << endl;
	}
	return 0;
}

Measured memory_bytes: 3064
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = sum(a)
B = sum(b)

# 最大試行回数
n = B - A
r_a = 0
r_b = 0
cnt = 0

for i, j in zip(a, b):
    if i < j:
        if (j - i) % 2 == 1:
            if r_b:
                r_b -= 1
            else:
                cnt += 1
                r_a += 1
            j += 1
        d = (j - i) // 2
        if d <= r_a:
            r_a -= d
        else:
            d -= r_a
            r_a = 0
            cnt += d
            r_b += d
    elif i > j:
        d = i - j
        if d <= r_b:
            r_b -= d
        else:
            d -= r_b
            r_b = 0
            cnt += d
            r_a += d

if cnt <= n:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 4596
import re
import math

def f(S):
    n = len(S)
    if n == 0 or n == 1:
        return 0
    elif n == 2:
        return 1 if S[0] == S[1] else 0
    else:
        if S[-1] == S[-2] and S[-2] == S[-3]:
            return f(S[0:-2]) + 1
        elif S[-1] == S[-2] and S[-2] != S[-3]:
            return f(S[0:-1]) + 1
        else:
            return f(S[0:-1])

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

reg_exp = S[0] + '+'
l = len( re.match(reg_exp, S).group() ) # 最初の文字が連続する長さ

reg_exp = S[-1] + '+$'
r = len( re.findall(reg_exp, S)[0] ) # 最後の文字が連続する長さ

if len(S) == l: # 全て同じ文字
    result = math.floor(len(S) * K / 2)
elif S[0] == S[-1] and l % 2 == 1 and r % 2 == 1:
    result = K * f(S) + K - 1
else:
    result = K * f(S)

print(result)

Measured memory_bytes: 3188
#include<map>
#include<iostream>
#include<iomanip>
//#include<conio.h>
#include<algorithm>
#include<vector>
#include<set>
#include<cmath>
#include<stdio.h>
#include<fstream>
#include<assert.h>
#include<time.h>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<sstream>
#include<string.h>
#define mp make_pair
#define ll long long
#define all(v) v.begin(),v.end()
#define memset(a,b) memset(a,b,sizeof(a))
using namespace std;
const int INF=1e9;
inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
inline void rd(int &val){
    int x=0;
    int f=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-'){
		f=-1;
		ch=getchar();
	}
    while(ch>='0'&&ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    val=x*f;
}
inline void quickSort(int s[],int l,int r)  {
    if(l<r){
        int i=l,j=r,x=s[l];
        while(i<j){
            while(i<j&&s[j]>=x) j--;
            if(i<j) s[i++]=s[j];
            while(i<j&&s[i]<x) i++;
            if(i<j) s[j--] = s[i];
        }
        s[i]=x;
        quickSort(s, l, i - 1);
        quickSort(s, i + 1, r);
    }
}
int x,y;
vector<int> S[777],T[777],v[777],b[777];
bool dp[777];
int can[777][777],n,m;
int col[777],cha,best;
int cnt[2],add,ta,tb;
inline int rds(int x){return ((x-1)*x)/2;}
inline void dfs(int x,int co){
//	cout<<x<<' '<<co<<endl;
	if(col[x]==(!co)){
		write(-1);
		putchar('\n');
		exit(0);
	}
	if(col[x]==co) return;
	col[x]=co;
    cnt[co]++;
	for(int i=0;i<b[x].size();i++) dfs(b[x][i],!co);
	return; 
}
int main(){
	ios_base::sync_with_stdio(false);
	int i,j,x,y;
	rd(n),rd(m);
	for(i=1;i<=m;i++){
		rd(x),rd(y);
		can[x][y]=1;
		can[y][x]=1;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(!can[i][j]&&i!=j) b[i].push_back(j),b[j].push_back(i);
	memset(col,-1);
	dp[0]=1;
	for(i=1;i<=n;i++){
		if(col[i]==-1){
//			for(j=1;j<=n;j++) cout<<col[j]<<' ';
//			cout<<endl;
			cnt[0]=0;
			cnt[1]=0;
			dfs(i,0);
			if(cnt[0]>cnt[1]) swap(cnt[0],cnt[1]);
	        add+=cnt[0];
    	    cha=cnt[1]-cnt[0];
    	    for(j=n+1;j>=cha;j--) if(dp[j-cha]) dp[j]=1;
		}
	}
//	for(i=1;i<=n;i++) cout<<dp[i]<<' ';
//	cout<<endl;
	best=pow(n,2);
	for(i=0;i<=n;i++){
		if(dp[i]) {
        	ta=add+i,tb=n-ta;
        	best=min(best,rds(ta)+rds(tb));
    	}
	}
	write(best);
	putchar('\n');
	return 0;
}


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

using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int mv = max(a, max(b, c));
  int res = -1;
  for (int target = mv; target < mv + 5; ++target) {
    for (int ab = 0; ab <= target; ++ab) {
      for (int bc = 0; bc <= target; ++bc) {
        for (int ac = 0; ac <= target; ++ac) {
          int d_a = target - a - ab - ac;
          int d_b = target - b - ab - bc;
          int d_c = target - c - ac - bc;
          if (d_a >= 0 && d_a % 2 == 0 && d_b >= 0 && d_b % 2 == 0 && d_c >= 0 && d_c % 2 == 0) {
            int cur = ab + bc + ac + d_a / 2 + d_b / 2 + d_c / 2;
            if (res == -1 || res > cur) res = cur;
          }
        }
      } 
    } 
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
/*input
*/
#include <bits/stdc++.h>
using namespace std;
 
#define all(a) (a).begin(), (a).end()
#define pb push_back
 
using ll = long long;
using pii = pair<int, int>;

const int N = 12, M = 1e3 + 2;
const int inf = 1e9;
int dp[M][1 << N];
vector<pii> keys;
int n, m;

int solve(int idx, int mask) {
	if (mask == ((1 << n) - 1)) {
		return 0;
	}
	if (idx == m - 1) {
		if ((mask | keys[idx].second) == ((1 << n) - 1)) {
			return dp[idx][mask] = keys[idx].first;
		}
		return inf;
	}
	if (dp[idx][mask] != -1)
		return dp[idx][mask];
	int ans = 1e9;
	ans = min(ans, solve(idx + 1, mask));
	ans = min(ans, keys[idx].first + solve(idx + 1, mask | keys[idx].second));
	return dp[idx][mask] = ans;
}

int main() {
	ios::sync_with_stdio(false);cin.tie(nullptr);
	cin >> n >> m;
	keys.resize(m);
	int poss = 0;
	for (int i = 0; i < m; ++i) {
		int a, b; cin >> a >> b;
		keys[i].first = a;
		keys[i].second = 0;
		for (int j = 0; j < b; ++j) {
			int c; cin >> c;
			--c;
			keys[i].second |= (1 << c);
		}
		poss |= keys[i].second;
	}
	if (poss + 1 != (1 << n)) {
		cout << -1 << "\n";
		return 0;
	}
	//sort(all(keys));
	memset(dp, -1, sizeof(dp));
	int ans = solve(0, 0);
	cout << ans << "\n";
}

Measured memory_bytes: 16384
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<pair<int, int>> w(n);
    for(auto&& i : w){
        cin >> i.second >> i.first;
    }
    sort(begin(w), end(w));
    long long now = 0;
    for(auto&& i : w){
        now += i.second;
        if(i.first < now){
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public void main(Scanner sc) {
        int n = sc.nextInt();
        int map[][] = new int[2][n];
        int sum[][] = new int[2][n];

        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < n; j++) {
                map[i][j] = sc.nextInt();
            }
        }

        sum[0][0] = map[0][0];
        for (int j = 1; j < n; j++) {
            sum[0][j] = sum[0][j - 1] + map[0][j];
        }

        sum[1][0] = sum[0][0] + map[1][0];
        for (int j = 1; j < n; j++) {
            sum[1][j] = Math.max(sum[0][j], sum[1][j - 1]) + map[1][j];
        }

        System.out.println(sum[1][n - 1]);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        new Main().main(sc);
        sc.close();
    }
}


Measured memory_bytes: 21716
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int P[] = new int[N];
        for(int i=0; i<N; i++){
            P[i] = scanner.nextInt();
        }

        int min = N + 1;
        int count = 0;
        for(int i=0; i<N; i++){
            if(P[i] <= min){
                count ++;
                min = P[i];
            }
        }
        System.out.println(count);
    }
}

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

int main(){
    ios::sync_with_stdio(false);    cin.tie(NULL);  cout.tie(NULL);
    int n;  cin >> n;   int dp[100005][4];
    dp[0][1]=dp[0][2]=dp[0][3]=0;
    for(int i=1;n>=i;i++){
        cin >> dp[i][1] >> dp[i][2] >> dp[i][3];
        dp[i][1]+=max(dp[i-1][2], dp[i-1][3]);
        dp[i][2]+=max(dp[i-1][1], dp[i-1][3]);
        dp[i][3]+=max(dp[i-1][1], dp[i-1][2]);
    }
    cout << max(dp[n][1], max(dp[n][2], dp[n][3]));
}

Measured memory_bytes: 1792
r, g, b, n = map(int, input().split())
count = 0
for i in range(n // r + 1):
  rs = r * i
  for j in range((n - rs) // g + 1):
    gs = g * j
    if (n - rs - gs) % b == 0:
      count += 1
print(count)

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

long long n = 0;

long long getCount(int k)
{
    long long divCount = 0;
    while(true)
    {
        if(n % k == 0)
        {
            divCount++;
            n = n / k;
        }
        else
        {
            break;
        }
    }
    
    long long i = 1;
    long long count = 0;
    while(true)
    {
        if(i <= divCount)
        {
            divCount -= i;
            count++;
            i++;
        }
        else
        {
            break;
        }
    }
    
    return count;
}

int d()
{
    std::cin >> n;
    
    long long end = (long long)(sqrt(n) + 1);
    
    if(n == 1)
    {
        std::cout << 0 << std::endl;
        return 0;
    }
    
    long long count = 0;
    for(int i = 2; i <= end; i++)
    {
        if(n % i == 0)
        {
            count += getCount(i);
        }
    }
    
    if(n != 1)
    {
        count++;
    }
    
    std::cout << count << std::endl;
    
    return 0;
}

int main(int argc, const char * argv[])
{
    d();
    return 0;
}


Measured memory_bytes: 3680
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string a, b, c;
    cin >> a >> b >> c;
    int lena = a.length(), lenb = b.length();
    if (a[lena - 1] == b[0] && b[lenb - 1] == c[0]) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;


int main(void){
	          int i;

	      	  cin.tie(0);  ios_base::sync_with_stdio(false);

	      	  int N;
	      	  cin >> N;

	      	  vector<int> d(N+1),e(N+1);
	      	  d[0]=0; e[0]=0;
	      	  for(i=1;i<=N;i++){
	      		  cin >> d[i];
	      		  e[i]=d[i];
	      	  }

	      	  sort(d.begin(),d.end());
	      	 sort(e.begin(),e.end());


	      	  for(i=1;i<=N;i++){
	      		  if(i%2==1){
	      			  d[i]=min(d[i],24-d[i]);
	      		  }else{
	      			  d[i]=max(d[i],24-d[i]);
	      		  }
	      	  }

	      	  int mn=1e9;
	      	  for(i=1;i<=N;i++){
	      		  int x=abs(d[i]-d[i-1]);
	      		  if(i==1) mn=d[i];
	      		  if(i>=2) mn=min(min(mn,abs(d[i]-d[i-2])),min(x,24-x));
	      	  }




	      	  cout << mn << endl;



	          return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>

int main(){
  int N, M;
  scanf("%d", &N);
  scanf("%d", &M);
  std::vector<int > A(N);
  int sum = 0;
  for (int i=0; i<N; i++){
    scanf("%d", &A[i]);
    sum += A[i];
  }
  std::sort(A.begin(), A.end(), std::greater<int>());
  bool ok = true;
  for (int i=0; i<M; i++){
    //printf("%d %d\n", A[i]*4*M,sum);
    if (A[i]*4*M<sum){
      ok = false;
      break;
    }
  }
  printf("%s\n", ok?"Yes":"No");
  return 0;
}


Measured memory_bytes: 888
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			String oct = Integer.toOctalString(n);
			char[] trans = new char[]{'0', '1', '2', '3', '5', '7', '8', '9'};
			
			
			for(char c : oct.toCharArray()){
				System.out.print(trans[c - '0']);
			}
			System.out.println();
		}
		
	}

}

Measured memory_bytes: 60504
import math

a, b, C = map(int, input().split())

s = 1/2 * a * b * math.sin(math.radians(C))

c2 = a**2 + b**2 - 2*a*b * math.cos(math.radians(C))
c = c2 ** 0.5
L = a + b + c

h = 2*s / a

print(s, L, h)


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

#define fi first
#define se second

using ll = long long;

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

    int n;cin>>n;

    map<int,int> m;

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

    vector<ll> v;
    for(auto mm:m)
    {
        if(mm.se>=2)v.push_back(mm.fi);
    }

    sort(v.begin(),v.end(),greater<ll>());

    ll ans=0;

    if(v.size()>=2)
    {
        if(m[v[0]]>=4)ans=v[0]*v[0];
        else ans=v[0]*v[1];
    }
    else if(v.size()==1)
    {
        if(m[v[0]]>=4)ans=v[0]*v[0];
    }
    
    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 8296
fn main() {
    proconio::input! {
        n: usize,
        x: String,
    }

    let bp = x.match_indices('1').count() as u32;
    let p = if bp == 1 { [2, 1] } else { [bp + 1, bp - 1] };

    let xr: Vec<char> = x.chars().rev().collect();

    let mut pows = vec![[1, 1]; n];
    let mut xv = if xr[0] == '1' { [1, 1] } else { [0, 0] };
    for i in 1..n {
        for j in 0..=1 {
            pows[i][j] = (pows[i - 1][j] * 2) % p[j];
            if xr[i] == '1' {
                xv[j] = (xv[j] + pows[i][j]) % p[j];
            }
        }
    }

    for i in (0..n).rev() {
        if bp == 1 && xr[i] == '1' {
            println!("0");
        } else {
            let xi = if xr[i] == '0' {
                let j = 0;
                (xv[j] + pows[i][j]) % p[j]
            } else {
                let j = 1;
                let p = if xv[j] >= pows[i][j] { 0 } else { p[j] };
                xv[j] + p - pows[i][j]
            };
            println!("{}", 1 + pop_pop_count(xi));
        }
    }
}

fn pop_pop_count(mut v: u32) -> u32 {
    let mut r = 0;
    while v > 0 {
        v %= v.count_ones() as u32;
        r += 1;
    }
    r
}


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

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    int n, d;
    cin >> n >> d;
    d = d+d+1;
    cout << (n+d-1)/d << '\n';
}


Measured memory_bytes: 256
#include <math.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;

using ll = long long;
typedef pair<ll, ll> P_ll;
typedef pair<int, int> P;

const ll INF_ll = 1e17;
const int INF = 1e8;

int main() {
  int x;
  int ans;
  for (int i = 0; i < 5; i++) {
    cin >> x;
    if (x == 0) {
      ans = i + 1;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, x, y;
  cin >> a >> b >> x >> y;
  if (b <= a) {
  cout << b*x+(a-b)*y << endl;
  }
  else {
    cout << a * x << endl;
  }
}


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

using namespace std;

int main()
{
  int A,B,C,X;
  cin>> A>> B>> C>> X;

  int ret=0;
  for(int i=0;i<=A;i++)
  for(int j=0;j<=B;j++)
  for(int k=0;k<=C;k++)
  {
    if(500*i+100*j+50*k==X)ret++;
  }
  cout<< ret<< endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <sstream>
#include <ostream>
#include <bitset>
#include <list>
#include <deque>
#include <complex>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cfloat>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <climits>

using namespace std;

#define MAX 60010
#define MAX_C 20
#define INF 1e9
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define FOR(i,a,b) for(int i = a ; i < b ; i++)
#define all(p) (p).begin(),(p).end() 

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

int N,M;
int c[MAX_C];

int solve(){
  int dp[MAX];
  fill(dp,dp+MAX,INF);
  dp[0] = 0;
  rep(i,M){
    FOR(j,c[i],N+1){
      dp[j] = min(dp[j],dp[j-c[i]] + 1);
    }
  }
  return dp[N];
}

int main(){
  scanf("%d%d",&N,&M);
  rep(i,M){
    scanf("%d",&c[i]);
  }
  printf("%d\n",solve());
  return 0;
}

Measured memory_bytes: 1420
using System;

namespace ARC067_D___Walk_and_Teleport
{
    class Program
    {
        static void Main(string[] args)
        {
            var NAB = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            var N = NAB[0];
            var A = NAB[1];
            var B = NAB[2];
            var Xi = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            long result = 0;
            for (int i = 1; i < N; i++) result += Math.Min(B, (Xi[i] - Xi[i - 1]) * A);
            Console.WriteLine(result);
        }
    }
}


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

int N, K;
string S;
void solve()
{
	S[K-1] = 'a' + S[K-1] -'A';
  	cout << S << endl;
}
int main()
{
  	cin >> N >> K;
  	cin >> S;
  	solve();
	return 0;
}

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

using namespace std;

void failure () {
  cout << "Impossible" << endl;
  exit(0);
}

int main () {
  ios::sync_with_stdio(false);

  int n, m;
  cin >> n >> m;

  if (m == 1) {
    int a;
    cin >> a;

    if (a == 1) {
      cout << a << endl;
      cout << 1 << endl;
      cout << 1 << endl;
      return 0;
    }
    cout << a << endl;
    cout << 2 << endl;
    cout << a - 1 << " " << 1 << endl;    
    return 0;
  }

  vector<int> odds;
  vector<int> evs;
  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;

    if (a % 2 == 0) evs.push_back(a);
    if (a % 2 == 1) odds.push_back(a);
  }

  if ((int) odds.size() > 2) failure();
  
  vector<int> A;
  if (!odds.empty()) {
    A.push_back(odds.back());
    odds.pop_back();
  }
  for (int u : evs) {
    A.push_back(u);
  }
  if (!odds.empty()) {
    A.push_back(odds.back());
    odds.pop_back();
  }

  for (int i = 0; i < (int) A.size(); i++) {
    cout << A[i] << " ";
  }
  cout << endl;

  vector<int> B;
  B.push_back(A[0] + 1);
  for (int i = 1; i < (int) A.size() - 1; i++) {
    B.push_back(A[i]);
  }
  B.push_back(A.back() - 1);
  if (B.back() == 0) B.pop_back();

  cout << (int) B.size() << endl;
  for (int b : B) {
    cout << b << " ";
  }
  cout << endl;
}


Measured memory_bytes: 3652
n = int(input())
s = list(input())
cnt = 0
cnt += s.count('R')*s.count('G')*s.count('B')
for i in range(1,n-1):
    for j in range(1,min(i,n-i-1)+1):
        if s[i-j]!=s[i] and s[i]!=s[i+j] and s[i+j]!=s[i-j]:
            cnt -= 1
print(cnt)

Measured memory_bytes: 9160
import sys
import time
import math
import itertools as it
def inpl():
    return list(map(int, input().split()))
st = time.perf_counter()
# ------------------------------

N, M = inpl()
ac = [False] * (N+10)
wa = [0] * (N+10)

a = 0
w = 0
for _ in range(M):
    p, S = input().split()
    p = int(p)
    if S == 'WA':
        if not ac[p]:
            wa[p] += 1
    else:
        if not ac[p]:
            ac[p] = True
            a += 1
            w += wa[p]

print(a, w)

# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)


Measured memory_bytes: 10252
#include <iostream>
#include <queue>

using namespace std;

class node
{
public:

	node(int a_, int b_, int c_, int cost_)
		: a(a_), b(b_), c(c_), cost(cost_)
	{
	}

	int a;
	int b;
	int c;
	int cost;
};

queue<node> q;

void push(node n)
{
	if (n.a == n.b && n.b == n.c)
	{
		cout << n.cost << endl;
		exit(0);
	}

	q.push(n);
}

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

	push(node(a, b, c, 0));

	while (!q.empty())
	{
		node n = q.front();
		q.pop();

		if (n.b == n.c && n.a < n.b) push(node(n.a + 2, n.b, n.c, n.cost + 1));
		if (n.a == n.c && n.b < n.a) push(node(n.a, n.b + 2, n.c, n.cost + 1));
		if (n.a == n.b && n.c < n.a) push(node(n.a, n.b, n.c + 2, n.cost + 1));

		if (n.a < n.c && n.b < n.c) push(node(n.a + 1, n.b + 1, n.c, n.cost + 1));
		if (n.a < n.b && n.c < n.b) push(node(n.a + 1, n.b, n.c + 1, n.cost + 1));
		if (n.c < n.a && n.b < n.a) push(node(n.a, n.b + 1, n.c + 1, n.cost + 1));
	}

	return 0;
}


Measured memory_bytes: 256
N = int(input())
T = [0] * N
XY = [0] * N
for i in range(N):
    t,x,y = map(int, input().split())
    T[i] = t
    XY[i] = [x,y]

x,y = 0,0
t = 0
for i in range(N):
    nx,ny = XY[i]
    nt = T[i]
    distance = abs(x-nx) + abs(y-ny)
    if distance <= nt - t and ((nt - t) - distance) %2 == 0:
        x,y = nx,ny
        t = nt
    else:
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 20340
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T & a, U & ... b) { cin >> a; IN_(b ...); };
template<typename T> void OUT(T && a) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

int main() {
	IN(int, n);
	IN(string, s);
	LL r = 0, g = 0, b = 0;
	RF(e, s) {
		if(e == 'R') { r++; }
		if(e == 'G') { g++; }
		if(e == 'B') { b++; }
	}
	LL ans = r * g * b;
	inc(i, n) {
		inc1(j, n) {
			if_not(0 <= i - j && i + j < n) { continue; }
			set<char> se;
			se.insert(s[i]);
			se.insert(s[i - j]);
			se.insert(s[i + j]);
			if(SI(se) == 3) { ans--; }
		}
	}
	OUT(ans);
}


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

using namespace std;

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

    int n;
    cin >> n;

    for (int i = 9; i >= 1; i--) {
        if (n % i == 0) {
            int m = n / i;
            if (m <= 9) {
                cout << "Yes";
            }
            else {
                cout << "No";
            }
            break;
        }
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  ll n, m; cin >> n >> m;
  vector<pair<ll, ll>> p(n);
  for(int i=0;i<n;++i) {
    cin >> p[i].first >> p[i].second;
  }
  sort(p.begin(), p.end());
  ll su = 0;
  int cnt = 0;
  for(int i=0;i<n;++i) {
    while(cnt < m && p[i].second > 0) {
      su += p[i].first;
      p[i].second--;
      cnt++;
    }
  }
  cout << su << endl;
}


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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int n, w[1010], s[1010], ind[10001];

int main() {
	cin >> n;
	
	for_(i,0,n) {
		cin >> w[i];
		s[i] = w[i];
		ind[w[i]] = i;
	}
	
	sort(s, s + n);
	
	int ans = 0;
	
	for_(i,0,n) {
		if (w[i] == s[i]) continue;
		
		int piv = w[i], cur = i, sum = w[i], cnt = 0;
		w[i] = s[i];
		
		while ((cur = ind[s[cur]]) != i) {
			piv = min(piv, w[cur]);
			sum += w[cur];
			++cnt;
			w[cur] = s[cur];
		}
		
		ans += min((sum - piv) + piv * cnt, 2 * (piv + s[0]) + (sum - piv) + s[0] * cnt);
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main(){
    int h, w, k, now = 1, fi=-1;
    cin >> h >> w >> k;
    vector<vector<char>> s((h), vector<char>(w));
    vector<vector<int>> ans((h), vector<int>(w, -1));
    vector<int> num(h, 0);
    rep(i, h){
        rep(j, w){
            cin >> s[i][j];
            if(s[i][j] == '#'){
                num.at(i)++;
                ans[i][j] = now;
                now++;
            }
        }
        if(num.at(i) != 0 && fi == -1)fi = i;
    }
    now = 1;
    rep(i, h){
        if(num.at(i) > 0){ 
            ll cnt = 0;
            rep(j, w){
                if(j == 0 && s[i][j] == '.')ans[i][j] = now;
                else if(s[i][j] == '.')ans[i][j] = ans[i][j-1];
                else {
                    if(cnt != num.at(i) && cnt > 0)now++;
                    cnt++;
                }
            }
            now++;
        }
    }
    rep(i, h){
        if(num.at(i) == 0){
            rep(j, w){
                if(i <= fi) ans[i][j] = ans[fi][j];
                else ans[i][j] = ans[i-1][j];
            }
        }
    }
    rep(i, h){
        rep(j, w)cout << ans[i][j] << " ";
        cout << endl;
    }
}   


Measured memory_bytes: 1280
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
int n;
double p[4005], dp[4005][4005];
int main() {
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> p[i];
	dp[0][0] = 1;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j <= i; j++) {
			dp[i+1][j] += dp[i][j] * (1.0 - p[i]);
			dp[i+1][j+1] += dp[i][j] * p[i];
		}
	}
	double ans = 0;
	for(int i = (n+1)/2; i <= n; i++) {
		ans += dp[n][i];
	}
	cout << fixed << setprecision(15) << ans;
	return 0;
}


Measured memory_bytes: 92672
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int main(){
    string s;
    cin>>s;
    
    set<char> st;
    for(auto ch:s)st.insert(ch);
    
    int ans = INF;
    for(auto ch:st){
        vector<int> v;
        rep(i,s.size()){
            if(s[i]==ch)v.pb(i);
        }
        v.pb(s.size());
        int d = 0;
        rep(i,v.size()-1)d = max(d,v[i+1]-v[i]-1);
        ans = min(ans, max(v[0],d));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
from collections import defaultdict
N, M = map(int, input().split())
a = [int(c)%M for c in input().split()]
L = [0]
for i in range(N):
  L += [(L[-1]+a[i])%M]
log = defaultdict(int)
log[0] = 1
ans = 0
for i in range(1,N+1):
  x = L[i]%M
  ans += log[x]
  log[x] += 1
print(ans)

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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define m_p make_pair

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

    ll a,n,ans=0;
    cin >> n;
    vector<ll> sum(n+1,0);
    rep(i,n){
        cin >> a;
        sum[i+1] = sum[i];
        sum[i+1] += a;
    }
    map<ll,ll> mp;
    rep(i,n+1){
        // n_C_2 = 1 + 2 + ... + n-1
        ans += mp[sum[i]];
        mp[sum[i]]++;
    }
    cout << ans << "\n";
    return 0;
}

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

using namespace std;
int main(){
int N;
cin >>N;
int a[N+1];
int Min=100000;
int Max=2;
long long ans=0;
for(int i=1;i<=N;i++){
    cin >>a[i];
    ans+=a[i]-1;
    //Min=min(Min,a[i]);
    //Max=max(Max,a[i]);
}
//long long ans=0;
/*long long sum=0;
for(int i=Min+1;i<Max;i++){
    sum=0;
    for(int l=1;l<=N;l++){
    sum+=i%a[l];
    }
    ans=max(ans,sum);
}
*/

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

Measured memory_bytes: 384
N, K = list(map(int, input().split()))
p = list(map(int, input().split()))

def kitai(n):
    return (1+n) /2

temp = 0
S = [0]

for i in range(N):
    S.append(S[-1] + kitai(p[i]))
    
    
temp = 0

for i in range(N-K+1):      
    add = S[i+K] - S[i]
    if add > temp:
        temp = add
    
print(temp)

Measured memory_bytes: 25060
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ld pie=3.1415926535;
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,ans=0; cin>>n;
    map<string,int> q;
    rep(i,n){
        string s; cin>>s;
        if(q.count(s)) q[s]++;
        else q[s]=1;
    }
    int m; cin>>m;
    rep(i,m){
        string s; cin>>s;
        if(q.count(s)) q[s]--;
        else q[s]=-1;
    }
    for(auto p:q){
        ans=max(ans,p.second);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <queue>
#include <vector>
#include <cstdlib>
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
const int DMAX=100000+5;
const int MOD=1000000000+7;
template<class T> inline void read(T &x){
	x=0;
	T f=1;
	char ch=getchar();
	while(ch<'0' || ch>'9'){
		if(ch=='-'){
			f=-1;
		}
		ch=getchar();
	}
	while(ch<='9' && ch>='0'){
		x=x*10+(ch-'0');
		ch=getchar();
	}
	x*=f;
}
int main(){
	string s;
	cin>>s;
	if(s[2]==s[3] && s[4]==s[5]){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
N=gets.to_i
S=gets.strip.codepoints
W="W".codepoints[0]
B="B".codepoints[0]

def time(n)
    out=1
    for i in 1..n
        out*=i
        out=out % (10**9+7)
    end
    out
end

ls=S.map.with_index{|e,i| i%2==0 ? (e==W ? B : W) : e}
lcnt=0
ans=1
ls.each do |e|
    if e==W
        lcnt+=1
    else
        ans*=lcnt
        lcnt-=1
    end
    ans=ans % (10**9+7)
end
ans=0 if lcnt!=0
ans=ans * time(N) % (10**9+7)
puts ans


Measured memory_bytes: 5244
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#define ll long long int

using namespace std;

int n,a,b,cnt=0,f=0;

int main()
{
    ///freopen("INA.txt","r",stdin);
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>> n;
    for(int i=1;i<=n;i++){
        cin>> a >> b;
        if(cnt>0){
            if(a==b){
                cnt++;
            }
            else{
                cnt=0;
            }

            if(cnt==3){
                f=1;
            }
        }
        else{
            if(a==b){
                cnt++;
            }
        }
    }

    if(f==1){
        cout<< "Yes" << endl;
    }
    else{
        cout<< "No" << endl;
    }

    return 0;
}



Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define        fast        ios_base::sync_with_stdio(false);cin.tie(NULL)
#define        ll          long long int
#define        End         return 0
#define        st          string
#define        sz(x)       (int)x.size()
#define        nl          '\n'
int main()
{
    fast;
    int k;
    st s="ACL",t="";
    cin>>k;
    while(k--)
        t=t+s;
    cout<<t;
    End;
}


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

vector<int> to[1000000];
vector<int> ans;

void dfs(int v, int p=-1){
    for(int u : to[v]){
        if(u == p) continue;
        ans[u] += ans[v];
        dfs(u, v);
    }
}

int main(){
    int n, q;
    cin >> n >> q;
    for(int i = 0; i < n - 1; ++i){
        int a, b;
        cin >> a >> b;
        --a; --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ans.resize(n);
    for(int i = 0; i < q; ++i){
        int p, x;
        cin >> p >> x;
        --p;
        ans[p] += x;
    }
    dfs(0);
    for(int i = 0; i < n-1; ++i){
        cout << ans[i] << " ";
    }
    cout << ans[n-1] <<  endl;
    return 0;
}


Measured memory_bytes: 43012
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>func(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}

int main() {
  int x,a,b;
  cin>>x>>a>>b;
  if(abs(a-x)>abs(b-x)){cout<<'B'<<endl;}
  else{cout<<'A'<<endl;}
  return 0;
}

Measured memory_bytes: 3592
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <map>

using namespace std;

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

typedef vector<int> vi;

int main()
{
	double highest = -1.0, lowest = -1.0;
	double h;
	while(scanf("%lf", &h) != EOF){
		if(highest == -1.0 || highest < h)
			highest = h;
		if(lowest == -1.0 || h < lowest)
			lowest = h;
	}

	printf("%f\n", highest-lowest);

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);++i)
#define rep1(i, n) for(int i=1;i<=(int)(n);++i)
#define irep(i, a, n) for(int i=a;i<(int)(n);++i)
#define rrep(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define allrep(V, v) for(auto&& V:v)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const int INF=1<<29;
const double EPS=1e-9;
using namespace std;


vector<lint> total, patty;

lint solve(int n, lint w)
{
  if(n == 0){
    return 1;
  }else if(w == 1){
    return 0;
  }else if(w <= total[n-1]+1){
    return solve(n-1, w-1);
  }else if(w == total[n-1]+2){
    return patty[n-1] + 1;
  }else if(w < total[n-1]*2+2){
    return solve(n-1, w-total[n-1]-2) + patty[n-1] + 1;
  }else{
    return patty[n-1] * 2 + 1;
  }
}

int main(void)
{
  int n; cin>>n;
  lint w; cin>>w;
  total.resize(n+1); patty.resize(n+1);
  total[0]=1; patty[0]=1;
  rep1(i,n){
    total[i]=total[i-1]*2+3;
    patty[i]=patty[i-1]*2+1;
  }
  cout << solve(n, w) << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define maxn 100005
using namespace std;
int n,m;
long long ans;
priority_queue<int,vector<int>,greater<int> >q;
struct node
{
	int x,y;
}a[maxn];
bool cmp(node tx,node ty)
{
	return tx.y>ty.y;
}
int main()
{
	int x,y;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d",&x),q.push(x);
	for(int i=1;i<=m;i++)scanf("%d %d",&a[i].x,&a[i].y);
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=m;i++)
	{
		while(a[i].y>q.top()&&(a[i].x--))
		{
			q.pop();
			q.push(a[i].y);
		}
	}
	while(!q.empty())ans+=q.top(),q.pop();
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4640
#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvld;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

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

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

    vi w(N), v(N);
    rep(i, N) cin >> w[i] >> v[i];

    vvll dp(N + 1, vll(W + 1));
    
    rep(i, N)
    {
        reple(j, 0, W)
        {
            //取らなかった場合
            chmax(dp[i + 1][j], dp[i][j]);

            if(j - w[i] >= 0) chmax(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
        }
    }

    cout << dp[N][W] << endl;

    return 0;
}

Measured memory_bytes: 83184
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppll pair <pll, pll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#pragma 03
using namespace std;
using namespace __gnu_pbds;
ll dp[2000005];
ll mod = 1e9 + 7;
int main(){
	ll n, h, d; cin >> n >> h >> d;
	ll x = 1, y = 0;
	for (ll i = 1; i<=n; i++){
		(x *= i) %= mod; (y += x) %= mod;
	}
	dp[0] = x;
	for (ll i = 0; i<=h; i++){
		if (!i){
			(dp[i+1] += dp[i]) %= mod;
			(dp[i+d+1] += mod - dp[i]) %= mod;
		}
		if (i){
			(dp[i+1] += dp[i]) %= mod;
			(dp[i+1] += y * dp[i] % mod) %= mod;
			(dp[i+d+1] += (mod - y * dp[i] % mod)) %= mod;
		}
	}
	cout << dp[h] << endl;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;

int main(){
  string s; cin >> s;
  int n = s.size();
  for(int i=2;i<=n;i+=2){
    string str = s.substr(0,n-i-1);
    string str1 = str.substr(0,(n-i)/2-1);
    string str2 = str.substr((n-i)/2);

    if(str1==str2){
      cout << n-i << endl;
      return 0;
    }
  }
}


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

int cnt[26];

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

	string s;
	cin >> s;
	for(auto c : s) {
		cnt[c - 'a']++;
	}

	int odd = 0;
	for(int i = 0; i < 26; i++) {
		if(cnt[i] % 2) odd++;
	}

	if(odd <= 1) {
		cout << 0 << endl;
	}
	else {
		cout << min(odd - 1, odd / 2) << endl;
	}
}

Measured memory_bytes: 3212
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	int c;
	cin>>c;
	vi in(n);
	rep(i,n)if(s[i]=='0'&&c){
		c--;
		in[i]=true;
		s[i]='1';
	}
	for(int i=n-1;i>=0;i--)if(c&&!in[i]){
		c--;
		s[i]='0';
	}
	cout<<s<<endl;
}

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

using namespace std;

int main() {
  int N, ans = 0;
  vector<int> B;
  
  cin >> N;
  
  for (int i = 0; i < N - 1; i++) {
    int inB;
    
    cin >> inB;
    
    B.push_back(inB);
  }
  
  ans += B[N - 2] + B[0];
  
  for (int i = N - 3; i >= 0; i--) {
    ans += min(B[i], B[i + 1]);
  }
  
  cout << ans << endl;
  
  return 0;
}

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second

Int INF = 1e18;
Int mod = 1e9+7;
//Int mod = 998244353;

int main() {
    Int n;
    cin >> n;
    vector<Int> a(n);
    Int sum = 0;
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    Int mi = INF;
    Int p_sum = 0;
    for (Int i = 0; i < n; i++) {
        Int rest = sum - p_sum - a[i];
        if (rest != p_sum) {
            mi = min(mi, abs(abs(rest - p_sum) - a[i]));
        }
        p_sum += a[i];
    }
    dump(mi);
    return 0;
}

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

const int maxn=2e5+10;

int n,m,cnt;
int F[maxn];
int cost[maxn];
std::vector<int> right[maxn];

int minv[maxn<<2];
int get(int r,int L,int R,int Lu,int Ru){
	if (L>Ru||R<Lu)return 0x3F3F3F3F;
	if (L>=Lu&&R<=Ru)return minv[r];
	int Mid=(L+R)>>1;
	return std::min(get(r<<1,L,Mid,Lu,Ru),get(r<<1|1,Mid+1,R,Lu,Ru));
}

void insert(int r,int L,int R,int p,int v){
	if (L==R)return minv[r]=v,void();
	int Mid=(L+R)>>1;
	if (p<=Mid)insert(r<<1,L,Mid,p,v);
	else insert(r<<1|1,Mid+1,R,p,v);
	minv[r]=std::min(minv[r<<1],minv[r<<1|1]);
}

int main (){
#ifdef LOCAL
	freopen("input","r",stdin);
#endif
	std::cin >> n;
	for (int i=1,x;i<=n;i++){
		std::cin >> x;
		cnt+=(x==0);
		cost[i]=x>0?1:-1;
	}
	std::cin >> m;
	for (int i=1,L,R;i<=m;i++){
		std::cin >> L >> R;
		right[L].push_back(R);
	}
	memset(F,0x3F,sizeof(F));
	memset(minv,0x3F,sizeof(minv));
	F[0]=0;
	for (int i=1,tmp;i<=n;i++){
		F[i]=std::min(F[i],F[i-1]+cost[i]);
		for (int R:right[i]){
			tmp=std::min(F[i-1],get(1,1,n,std::max(i-1,1),R));
			if (tmp<F[R])
				insert(1,1,n,R,F[R]=tmp);
		}
	}
	std::cout << F[n]+cnt << '\n';
	return 0;
}



Measured memory_bytes: 13568
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>

using namespace std;

int f(int pos, int k, const vector<int>& h, vector<int>& res) {
  if (pos == 0) {
    return 0;
  }

  if (res[pos] == -1) {
    int out = INT32_MAX;
    for (int i = 1; i <= k; i++) {
      int from = pos - i;
      if (from < 0) {
        break;
      }
      out = min(out, f(from, k, h, res) + abs(h[from] - h[pos]));
    }
    res[pos] = out;
  }

  return res[pos];
}

int main() {
  int n, k = 2;
  cin >> n;
  // cin >> k;

  // lets start from 0, to n-1
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }

  vector<int> res(n, -1);

  cout << f(n - 1, k, h, res) << endl;

  return 0;
}


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

using namespace std;

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

    string res = "";
    for (auto& s: S) {
        char cur = ((int) s + N - 65) % 26 + 65;
        res += cur;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
int main(){
	//mahakal(),fast;
	ll n , k ;
	cin>> n >> k ;
	vector<ll> vec[n+1];
	for(ll i=0;i<k ;i++){
		ll d ;
		cin>> d ;
		for(ll j=0;j<d ; j++){
			ll a ;
			cin>> a ;
			vec[a].pb(i);
		}
	}
	ll ans=0;
	for(ll i=1;i<=n ;i++){
		if(vec[i].size()==0)ans++;
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3672
def main():
    k = int(input())
    a, b = [int(i) for i in input().split()]
    if a % k == 0:
        print('OK')
        exit()
    if b % k == 0:
        print('OK')
        exit()
    if b // k > a // k:
        print('OK')
    else:
        print('NG')

if __name__ == '__main__':
    main()



Measured memory_bytes: 9160
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	const n = parseInt(input[0], 10);
	// 処理
  	const d = 10**9 + 7;
  	let val = 1;
	for (let i = 1; i <= n; i++) {
		val = val * i;
      	if(val>d) val%=d;
	}
  	console.log(val%d);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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




    int main(){
        int n, d;
        std::cin >>  n >> d;
        int ans = (n + d * 2) / (d * 2 + 1);
        std::cout <<  ans << "\n";
        return 0;
    }


Measured memory_bytes: 256