akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    t = input().strip()
    s = []
    # A = 0
    ans = []
    prevA = 0
    for i in range(len(t)):
        if t[i] == '\\':
            s.append(i)
        elif len(s) > 0 and t[i] == '/':
            p = s.pop()
            k = i - p
            ans.append((p, k))
            q = 0
            while len(ans) > 0:
                # print(ans)
                g, h = ans[-1]
                if g >= p:
                    q += h
                    ans.pop()
                else:
                    break
            # for j in range(len(ans) - len(s)):
            #     print('i: ', i)
            #     print('j: ', j)
            #     print('ans: ', ans)
            #     q += ans.pop()
                # print('q: ', q)
            if q != 0:
                ans.append((p, q))
        # elif len(s) > 0 and t[i] == '_':
        #     A += 1

    v = 0
    for i in range(len(ans)):
        v += ans[i][1]
    print(v)
    print(len(ans), end='')
    for i in range(len(ans)):
        print(' {}'.format(ans[i][1]), end='')
    print('')

if __name__ == '__main__':
    main()



Measured memory_bytes: 6496
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
 
void solve();

signed main () {
	cout.precision(10);
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	int t = 1; 
	// cin >> t;
	int tt = t;
	while (t--) { 
		solve();
	}
	return 0;
}

void solve() {
	int n, k;
	cin >> n >> k;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		if (x >= k)
			ans += 1;
	}
	cout << ans;
}		


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

int main() 
{
  int n;
  cin >> n;
  int x = n;
  int fx = 0;
  while(n > 0)
  {
    fx += n % 10;
    n /= 10;
  }
  if(x % fx == 0)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  
}


Measured memory_bytes: 256
import java.util.Scanner;
 
class Main {
	public static void main(String[] args) {
 
	    Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt();
	    int senen = 1000;
	    
	    while (true) {
	      if (N <= 0) { break; }
	      N = N - senen;
	    }
	    
	    System.out.println(Math.abs(N));
  }
}

Measured memory_bytes: 35668
#include <bits/stdc++.h>
using namespace std;
#define rep(it,st,en) for(int it=(st);it<(int)(en);++it)
#define allof(c) (c).begin(), (c).end()
#define mt make_tuple
#define mp make_pair
#define pb push_back
#define X first
#define Y second
typedef long long int ll; 
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
const int INF=(int)1e9; 
const double EPS=(ld)1e-7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    vector<ll> v(n);
    ll sm = 0, mx = 1e18, x = 0;
    rep(i,0,n) cin>>v[i], sm+=v[i];
    rep(i,0,n-1) {
        x += v[i];
        sm -= v[i];
        if(abs(x-sm) < mx) mx = abs(x-sm);
    }
    cout<<mx<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
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);
    int n;
    cin >> n;
    struct G {
        int to;
        ll cost;
    };
    vector<vector<G>> g(n);
    rep(i,n-1) {
        int a,b,c;
        cin >> a >> b >> c;
        a--;b--;
        g[a].push_back({b,c});
        g[b].push_back({a,c});
    }
    int q,k;
    cin >> q >> k;
    k--;
    using P = pair<ll,ll>;
    const ll INF = INT64_MAX>>2;
    priority_queue<P, vector<P>, greater<P>> pq;
    vector<ll> d(n,INF);
    d[k] = 0;
    pq.emplace(make_pair(0,k));
    while(!pq.empty()) {
        P now = pq.top();
        pq.pop();
        int v = now.second;
        if(d[v] < now.first) continue;
        for(auto next: g[v]) {
            if(d[next.to] > d[v] + next.cost) {
                d[next.to] = d[v] + next.cost;
                pq.emplace(make_pair(d[next.to], next.to));
            }
        }
    }
    rep(i,q) {
        int x,y;
        cin >> x >> y;
        x--;y--;
        cout << d[x] + d[y] << endl;
    }
}


Measured memory_bytes: 11120
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	int n,m,x,a[110],sum=0,ans=0;
	cin>>n>>m>>x;
	sum+=x;
	REP(i,n){
		cin>>a[i];
	}
	REP(i,n){
		for(int j=1;j<=m;j+=a[i]){
			sum++;
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func digitSum(x int) int {
	s := 0
	for x > 0 {
		s += x % 10
		x /= 10
	}

	return s
}

func main() {
	n, a, b := nextInt(), nextInt(), nextInt()

	s := 0
	for i := 1; i <= n; i++ {
		d := digitSum(i)
		if a <= d && d <= b {
			s += i
		}
	}

	fmt.Println(s)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int k, x;
  cin >> k >> x;
  if(500 * k >= x) cout << "Yes" << endl;
  else cout << "No" << endl;

}


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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  read::<String>().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
  (0..n).map(|_| read_vec()).collect()
}

fn main() {
  let s: String = read();

  let s: Vec<char> = s.chars().collect();

  let mut count: i8 = 0;
  let mut s_last_index = s.len()-1;
  for i in 0..s.len()/2 {
    if s[i] != s[&s_last_index-i] {
      count += 1;
    }
  }

  println!("{}", count);
}

Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


vector<int> v[202020];
int dist[202020];
void dfs(int x,int p){
    for(auto to : v[x]){
        if(to==p)continue;
        dist[to]=dist[x]+1;
        dfs(to,x);
    }
}
int main(){
    int n;
    cin>>n;
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        --a;--b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    dfs(0,-1);
    int x=-1,ma=0;
    rep(i,n)if(dist[i]>ma)x=i,ma=dist[i];
    dist[x]=0;
    dfs(x,-1);
    ma=0;
    rep(i,n)ma=max(ma,dist[i]);
    if(ma%3==1)cout<<"Second"<<endl;
    else cout<<"First"<<endl;
    return 0;
}

Measured memory_bytes: 21376
N = int(input())
C = input()

a, b = 0, 0
a = C.count('R')
ans = a

for i in range(N):
	if C[i] == 'R': a -= 1
	else: b += 1
	now = max(a, b)
	ans = min(ans, now)

print(ans)

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

int g;
int prior[128];
int lft[16];
string s;
int pos;

void expr(int pr, deque<char> &res){
	if( pr == g ){
		if( s[pos] == '(' ){
			++pos;
			expr(0, res);
			++pos;
		}
		else{
			res.push_back( s[pos] );
			++pos;
		}
	}
	else{
		deque<char> dq;

		expr(pr + 1, dq);

		while( prior[s[pos]] == pr ){
			dq.push_front('(');
			dq.push_back( s[pos] );
			++pos;
			expr(pr + lft[pr], dq);
			dq.push_back(')');
		}
		
		res.insert( res.end(), dq.begin(), dq.end() );
	}
}

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

	int d, m, n;
	char a, p;
	
	prior['('] = prior[')'] = -1;
	
	cin >> d;
	while( d-- ){
		cin >> g;
		for(int i = 0; i < g; ++i){
			cin >> a >> m;
			lft[i] = (a == 'L');
			
			for(int j = 0; j < m; ++j){
				cin >> p;
				prior[p] = i;
			}
		}
		
		cin >> n;
		for(int i = 0; i < n; ++i){
			cin >> s;
			s = '(' + s + ')';
			pos = 0;
			deque<char> res;
			expr(g, res);
			cout << string(res.begin(), res.end()) << '\n';
		}
		
		if( d ) cout << '\n';
	}
}

Measured memory_bytes: 1344
#include <bits/stdc++.h>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define all(v)   v.begin(), v.end()
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define THINK_TWICE_CODE_ONCE cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define isOdd(n)    (n&1)
#define LLMAX LLONG_MAX
#define LLMIN LLONG_MIN
#define IMN INT_MIN
#define IMX INT_MAX
#define pow(n, m) power((ll)n, (ll)m)
#define numOfDigits(n)  ((n)? (ll)(log10(n)+1) : 1)
#define mem(x, val)    memset(x, val, sizeof(x))

typedef long long ll;
typedef long double ld;
typedef double dd;
typedef string str;
typedef pair<int, int> pii;


vector<int> v;
int dp[(int)1e5];
int n, k;
int jump(int i){
    if(i==n-1) return 0;
    if(i>=n) return 1e9;

    int &ret = dp[i];

    if(~ret) return ret;

    int cnt = 1e9;
    for(int j = 1; j<=k; j++){
        if(i+j<n) cnt = min(cnt, abs(v[i] - v[i+j]) + jump(i+j));
    }

    return ret = cnt;
}
int main()
{
    THINK_TWICE_CODE_ONCE
    //freopen("test cases\\.txt", "r", stdin) ;
    cin>>n>>k;
    v.resize(n);
    for(int &i: v) cin>>i;
    mem(dp, -1);
    cout<<jump(0);
    return 0;
}






Measured memory_bytes: 8832
#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 a,b;
  cin >> a >> b;
  
  if(a>8 | b>8){
    cout << ":(" << endl;
  }
  else
  {
    cout << "Yay!" << endl;
  }
  


  
  return 0;
}

Measured memory_bytes: 256
H,W=map(int,input().split())

x=[["a"]*W for i in range(H)]
y=[[set() for i in range(W)] for j in range(H)]

done=set()
for i in range(H):
  x[i]=input()

for i in range(H):
  for j in range(W):
    if x[i][j]==".":
      if i>0:
        if x[i-1][j]==".":
          y[i][j].add(W*(i-1)+j)
      if i<H-1:
        if x[i+1][j]==".":
          y[i][j].add(W*(i+1)+j)
      if j>0:
        if x[i][j-1]==".":
          y[i][j].add(W*(i)+j-1)
      if j<W-1:
        if x[i][j+1]==".":
          y[i][j].add(W*(i)+j+1)
maxleng=0          
for i in range(H):
  for j in range(W):
    done={W*i+j}
    leng=0
    nxt=[set() for k in range(H*W)]
    nxt[0]=set(y[i][j])
    for k in range(H*W):
      done|=nxt[k]
      while len(nxt[k])>0:
        a=nxt[k].pop()
        nxt[k+1]|=y[a//W][a%W]
      nxt[k+1]=set(nxt[k+1]&(nxt[k+1]^done))
      if len(nxt[k+1])==0:
        if maxleng<k:
          maxleng=k
        break
print(maxleng+1)

Measured memory_bytes: 44764
#include<stdio.h>
#include<algorithm>

int s[10000];

int main() {
	int n;
	int q;
	int cnt = 0;

	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &s[i]);
	}
	scanf("%d", &q);
	for (int i = 0; i < q; ++i) {
		int t;
		scanf("%d", &t);
		for (int i2 = 0; i2 < n; ++i2) {
			if (t == s[i2]) {
				++cnt;
				break;
			}
		}
	}

	printf("%d\n", cnt);
}

Measured memory_bytes: 2708
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    int X;
    cin >> X;
    if(X>=30) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
string s,t;
int g[26][26];
int main(){
    ios::sync_with_stdio(false);
    cin>>s>>t;
    int n = s.length();
    for(int i=0;i<n;i++){
        g[s[i]-'a'][t[i]-'a']=1;
    }
    for(int i=0;i<26;i++){
        for(int j=0;j<26;j++){
            //if(g[i][j])
              //  g[j][i]=1;
        }
    }
    int cnt = 0;
    for(int i=0;i<26;i++){
        int num1 = 0;
        int num2 = 0;
        for(int j=0;j<26;j++){
            num1+=g[i][j];
            num2+=g[j][i];
        }
        if(num1>=2||num2>=2){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
}



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


string s;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s.substr(i,2)=="AC"){
            return cout<<"Yes",0;
        }
    }
    cout<<"No";
}


Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <iostream>
#include <cstdio>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
 
#define ll long long
#define pb push_back
#define vi vector<int>
#define sz(a) (int((a).size()))
#define mp make_pair
#define f first
#define s second
#define pii pair<int, int>
 
using namespace std;
 
const int mod = 998244353;
const int inf = (int)2e9;
const ll INF = (ll)2e18;
const int N = 100100;

int n, l;
string a[N];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> l;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; i++) cout << a[i];
	cout << "\n";

	return 0;
}

Measured memory_bytes: 1024
# import itertools
# import math
import sys
sys.setrecursionlimit(500*500)
# import numpy as np
# from collections import deque
# import heapq

# N = int(input())
# S = input()
# n, *a = map(int, open(0))
N, Q = map(int, input().split())
# A = list(map(int, input().split()))
# A = list(map(lambda x: int(x)*(-1), input().split()))
# B = list(map(int, input().split()))
# A_B = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

edges = [list(map(int,input().split())) for _ in range(N - 1)]
tree = [[] for _ in range(N + 1)]

for edge in edges:
    tree[edge[0]].append(edge[1])
    tree[edge[1]].append(edge[0])

depth = [-1] * (N + 1)
depth[1] = 0
count = [0] * (N + 1)

for i in range(Q):
    p, x = map(int, input().split())
    count[p] += x

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + 1
#             dfs(tree, l[0])
# dfs(tree, 1)
def dfs(tree, s):
    for l in tree[s]:
        if depth[l] == -1:
            depth[l] = 0
            count[l] += count[s]
            dfs(tree, l)
dfs(tree, 1)


for i in count[1:]:
    print(i, end = ' ')

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr



# bfs
# tree = [[] for _ in range(N + 1)]
# edges = [list(map(int,input().split())) for _ in range(M)]

# for edge in edges:
#     tree[edge[0]].append(edge[1])
#     tree[edge[1]].append(edge[0])

# depth = [-1] * (N + 1)
# depth[1] = 0

# d = deque()
# d.append(1)

# ans = [0] * (N + 1)
# while d:
#  v = d.popleft()
#  for i in tree[v]:
#    if depth[i] != -1:
#      continue
#    depth[i] = depth[v] + 1
#    ans[i] = v
#    d.append(i)

# # ans = depth[2:]
# print('Yes')
# print(*ans[2:], sep="\n")

Measured memory_bytes: 258180
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n,m,h;
	cin >> n >> m;
	h=min(n,m/2);
	m-=n*2,n=0;
	m=max(m,n);
	cout << h+m/4 << endl;
	return 0;
}

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

using namespace std;

string a[100];

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

	int ans = 0;

	for (int i = 0; i < n; ++i) {
		string s; cin >> s;
		int len = s.length();
		for (int j = 1; j < len; ++j) {
			for (int k = 0; k < len; ++k) {
				int cnt = 0;
				int idx = 0;
				int now;
				for (now = k; now < len; now += j) {
					if (s[now] == S[idx]) {
						idx++;
						cnt++;
					} else {
						idx = cnt = 0;
						break;
					}

					if (cnt == S.length()) {
						ans++;
						goto next;
					}
				}
			}
		}
next:;
	}

	printf("%d\n", ans);
}

Measured memory_bytes: 1204
N, Q = map(int, input().split())
S = input()
L = [list(map(int, input().split())) for _ in range(Q)]
t, I = 0, [0]
for i in range(1, N):
  if S[i-1]=="A":
    if S[i]=="C":
      t += 1
  I.append(t)
for l in L:
  print(I[l[1]-1]-I[l[0]-1])

Measured memory_bytes: 29880
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n,l;
	cin>>n>>l;
	vector<int> a(n);
	int sum=0;
	rep(i,n){
		a[i]=l+i;
		sum+=a[i];
	}
	int ans=INF;
	int cnt;
	rep(i,n){
		int now=sum-a[i];
		if(chmin(ans,abs(now-sum))){
			cnt=now;
		}
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter

n = int(readline())
d = list(map(int, readline().split()))
counter = Counter(d)
mod = 998244353
ans = 1
if d[0] != 0 or counter[0] != 1:
    print(0)
    exit()
for i in range(1, max(d) + 1):
    ans *= pow(counter[i - 1], counter[i], mod)
    ans %= mod
print(ans)


Measured memory_bytes: 20424
#include <stdio.h>
#include <stdlib.h>
#define MAX 101

int n;
int main(){
  int i,j,u,v,k,Adj[MAX][MAX];


  scanf("%d",&n);

  for(i=1 ; i<=n ; i++){
    for(j=1 ; j<=n ; j++){
      Adj[i][j]=0;
    }
  }

  for(i=0 ; i<n ; i++){
    scanf("%d %d",&u,&k);
    for(j=0 ; j<k ; j++){
      scanf("%d",&v);
      Adj[u][v]=1;
    }
  }
  for(i=1 ; i<=n ; i++){
    for(j=1 ; j<=n ; j++){
      if(j<n)printf("%d ",Adj[i][j]);
      if(j==n)printf("%d",Adj[i][j]);
    }
    printf("\n");
  }
  return 0;
}
   


  

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

using namespace std;

typedef long long ll;

string itos(ll x) {
	stringstream ss; ss << x;
	string res; ss >> res;
	return res;
}

ll count(ll x) {
	return x/5 + x/3 - x/15;
}
ll count(ll l, ll r) { // [l, r]
	return count(r) - count(l-1);
}
ll f(ll x) {
	ll res = 0;
	res += x / 5 * 4; // Fizz
	res += x / 3 * 4; // Buzz
	for (ll i = 1, k = 1; k <= x; ++i, k *= 10) {
		ll l = k, r = min(x, k*10-1);
		res += ((r-l+1) - count(l, r)) * i;
	}
	return res;
}

int main() {
	ll s; cin >> s; --s;
	ll l = 1, r = s+2;
	for (int t = 0; t < 100; ++t) {
		ll m = (l + r) / 2;
		if ( f(m) >= s ) {
			r = m;
		}
		else {
			l = m;
		}
	}
	ll start = l;
	s -= f(l-1);
	string str = "";
	for (ll i = start; str.size() <= s+20; ++i) {
		if (i % 3 == 0) {
			str += "Fizz";
		}
		if (i % 5 == 0) {
			str += "Buzz";
		}
		if (i % 3 && i % 5) {
			str += itos(i);
		}
	}
	cout << str.substr(s, 20) << endl;
}

Measured memory_bytes: 1228
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <utility>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

using namespace std;

int main(){
	int n;
	cin >> n;
	int a[n+1];
	vector<int> ans;///output
	rep(i,1,n+1) cin >> a[i];
	rel(i,n+1,1){
		for(ll j=i*2;j<=n;j+=i) a[i] ^= a[j];
		if(a[i]) ans.push_back(i);
	}
	cout << ans.size() << endl;
rep(i,0,ans.size()) cout << ans[i] << endl;

}


Measured memory_bytes: 2424
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int cnt[12 + 1] = {1};

int dfs(int num, vector<int> v){
	if(num == 13){
		sort(v.begin(), v.end());
		int ret = 1e5;
		for(int i = 0; i < v.size() - 1; ++i) ret = min(ret, min((int)abs(v[i] - v[i + 1]), 24 - (int)abs(v[i] - v[i + 1])));
		ret = min(ret, min((int)abs(v[v.size() - 1] - v[0]), 24 - (int)abs(v[v.size() - 1] - v[0])));
		return ret;
	}
	if(!cnt[num]){
		return dfs(num + 1, v);
	}else if(cnt[num] == 2){
		v.push_back(num);
		v.push_back(24 - num);
		return dfs(num + 1, v);
	}else{
		vector<int> tmp = v;
		tmp.push_back(num);
		int ret = dfs(num + 1, tmp);
		v.push_back(24 - num);
		ret = max(ret, dfs(num + 1, v));
		return ret;
	}
}

int main(){
	int n; cin >> n;
	int d[n];
	for(int i = 0; i < n; ++i) cin >> d[i];
	for(int i = 0; i < n; ++i){
		++cnt[d[i]];
		if(cnt[d[i]] >= 3 || !d[i]){
			cout << 0 << endl;
			return 0;
		}
	}
	vector<int> v;
	v.push_back(0);
	cout << dfs(1, v) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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;
}

vector<int> as;

// pos_for_bit[i] contains indexes which contains bit i
vector<vector<int>> pos_for_bit;

ll solve(const int N) {
    ll ans = 0;

    for (int i = 0; i < N; i++) {
        const int start = i;
        int end = N;
#ifdef DEBUG
        printf("start: %d\n", start);
#endif
        for (int bit = 0; bit < 20; bit++) {
            if (as[i] & (1 << bit)) {
                auto it = upper_bound(pos_for_bit[bit].begin(), pos_for_bit[bit].end(), i);
                chmin(end, *it);
#ifdef DEBUG
                printf("  bit: %d, %d\n", bit, *it);
#endif
            } else {
                auto it = upper_bound(pos_for_bit[bit].begin(), pos_for_bit[bit].end(), i);
                it++;
                chmin(end, *it);
#ifdef DEBUG
                printf("  bit: %d, %d\n", bit, *it);
#endif
            }
        }
#ifdef DEBUG
        printf("  end: %d\n", end);
#endif
        ans += end - start;
    }

    return ans;
}

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

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

    pos_for_bit.resize(20, vector<int>());
    for (int i = 0; i < 20; i++) {
        for (int j = 0; j < N; j++) {
            if (as[j] & (1 << i)) {
                pos_for_bit[i].push_back(j);
            }
        }

        // sentinel
        pos_for_bit[i].push_back(N);
        pos_for_bit[i].push_back(N);
    }

#ifdef DEBUG
    printf("pos_for_bit: \n");
    for (int i = 0; i < 20; i++) {
        printf("  bit %d: ", i);
        for (auto x : pos_for_bit[i]) {
            printf("%d ", x);
        }
        printf("\n");
    }
#endif

    cout << solve(N) << endl;

    return 0;
}


Measured memory_bytes: 9208
import java.util.*;
import java.lang.*;
import java.math.*;

class Main {
    
    void run() {
        for (int i=1;i<10;i++) {
            for (int j=1;j<10;j++) 
                System.out.println( i + "x" + j + "="  + i*j);
        }
        return;
    }
    
    public static void main( String[] args) {
       new Main().run();
    }
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

int main() {
    rep(i,4){
        char s;cin>>s;
        cout<<s;
    }
    cout<<' ';

    string t;cin>>t;

    cout<<t<<endl;

}


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

const long long INF = 1e18;
struct edge{
    int to;
    long long cost;
};

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

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

    vector<edge> G[n];
    for(int i = 0; i < m; i++){
        int a, b;
        long long c;
        cin >> a >> b >> c;
        a--; b--;
        G[a].push_back({b, -c});
    }

    long long D[n];
    for(int i = 0; i < n; i++){
        D[i] = INF;
    }
    D[0] = 0;

    for(int i = 0; i < n * 2; i++){
        bool f = true;
        for(int j = 0; j < n; j++){
            for(int k = 0; k < G[j].size(); k++){
                edge e = G[j][k];
                if(D[e.to] > D[j] + e.cost){
                    if(e.to == n - 1) f = false;
                    D[e.to] = D[j] + e.cost;
                }
            }
        }
        if(i > n and !f){
            cout << "inf" << endl;
            return 0;
        }
    }

    cout << -D[n - 1] << endl;

    return 0;
}

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

#define debug(...) recursive_debug(#__VA_ARGS__, __VA_ARGS__)

void recursive_debug(string) { cerr << endl; }

template<class H,class... T>
void recursive_debug(string s, H h, T... t) {
    int comma = s.find(',');
    cerr << s.substr(0,comma) << " = " << h << ", ";
    recursive_debug(s.substr(comma+1), t...);
}

template<class T,class U>
ostream& operator<<(ostream& ost, const pair<T,U> &p) {
    ost << "(" << p.first << ", " << p.second << ")";
    return ost;
}

template<class T>
ostream& operator<<(ostream &ost, const vector<T> &v) {
    ost << "[";
    for(T t : v) ost << t << ",";
    ost << "]";
    return ost;
}

struct State {
    ll score;
    vector<int> types;
    bool operator<(const State& rhs) const {
        return (score < rhs.score);
    }
    bool operator>(const State& rhs) const {
        return (score > rhs.score);
    }
};


int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int D, M = 26;
    cin >> D;
    vector<ll> c(M);
    rep(i,M) cin >> c[i];
    vector<vector<ll>> s(D, vector<ll>(M));
    rep(d,D) rep(i,M) cin >> s[d][i];

    set<State> cur_states = {{0, {}}};
    size_t SIZE = 1000;

    rep(d,D) {
        set<State> nxt_states;
        for (auto &cur_itr : cur_states) {
            const State state = cur_itr;
            vector<int> last(M, -1);
            rep(i,state.types.size()) {
                last[state.types[i]] = i;
            }
            ll minus_score = 0;
            rep(i,M) {
                minus_score -= c[i] * (d - last[i]);
            }
            rep(i,M) {
                State nxt_state {
                    state.score + s[d][i] + minus_score + c[i] * (d - last[i]),
                    state.types
                };
                nxt_state.types.push_back(i);
                
                nxt_states.insert(nxt_state);
                if (nxt_states.size() > SIZE) {
                    nxt_states.erase(nxt_states.begin());
                }
            }
        }

        cur_states = std::move(nxt_states);
    }

    for (int t : cur_states.begin()->types) {
        cout << t+1 << endl;
    }
    debug(cur_states.begin()->score);

    return 0;
}


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

#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define FORW(a, b, c) for(int a = b; a >= c; --a)
#define fi first
#define se second
#define pb push_back
#define SZ(a) ((int)a.size())
#define int long long




typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int N = 5e5 + 100;
const int mod = 998244353;
const int Maxn = 1e5;
const int oo = 1e18;
const double PI = ((double)2.00 * (double)asin(1));

struct query {
	int lef, rig, x;
} q[N];
int n, m, k;
int dp[N], g[N], a[N], lst[N];
vector<ii> even, odd, tmp;

int add(int x, int y) { return (x + y + 2 * mod) % mod; }
int mul(int x, int y) { return (x * y) % mod; }

int pw(int x, int y) {
	int res = 1;
	while(y) {
		if(y % 2) res = mul(res, x);
		x = mul(x, x);
		y >>= 1;
	}
	return res;
}

int solve()	{

	memset(dp, 0, sizeof dp);
	for(auto v: odd) {
		a[v.fi] ++, a[v.se + 1] -= 1;
	}

	FOR(i, 1, n) a[i] += a[i - 1];
	FOR(i, 1, n) {
		a[i] = min(a[i], 1ll);
		//cout << a[i] << ' ';
	}  //cout << '\n';

	

	sort(tmp.begin(), tmp.end()); 	
	for(auto v: tmp) {
		while(SZ(even) > 0 && even.back().se >= v.se) even.pop_back();
		even.pb(v);
	}

	if(!SZ(even)) {
		int res = 1;
		FOR(i, 1, n) if(!a[i]) res = mul(res, 2);
		return res;
	}

	//for(auto v: even) cout << v.fi << ' ' << v.se << '\n'; cout << '\n';
	int pos = 0, pos1 = 0;
	FOR(i, 1, n) {
		while(pos < SZ(even) && even[pos].se < i) pos += 1;
		if(pos > 0) lst[i] = even[pos - 1].fi;
		else lst[i] = 0;
	}
	dp[0] = g[0] = 1;
	FOR(i, 1, n) {
		if(a[i]) {
			g[i] = g[i - 1];
			dp[i] = 0;
		} else {
			// set a[i] = 0
			if(lst[i] == 0) dp[i] = g[i - 1];
			else dp[i] = add(g[i - 1], -g[lst[i] - 1]);
			g[i] = add(dp[i], g[i - 1]);
		}
		//cout << dp[i] << ' ';
	} //cout << '\n';
	
	int res = 0;

	FOR(i, 1, n) if(even.back().fi <= i)
		res = add(res, dp[i]);

	return res;
}

signed main() {
	#ifdef TEST
	freopen("test.inp", "r", stdin);
	//freopen("athletic.in", "r", stdin);
	//freopen("athletic.out", "w", stdout);
	#endif //TEST

	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	
	int even = m / 2, odd = (m + 1) / 2;
	FOR(i, 1, odd) cout << i << ' ' << 2 * odd - i + 1 << '\n';
	FOR(i, 1, even) cout << 2 * odd + i << ' ' << 2 * odd + 2 * even + 1 - i + 1 << '\n';
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
struct state{int p,y,x,a,b,c,d;};
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

int n;
int  t[367][4][4];
bool visited[367][3][3][8][8][8][8];

int solve(){
  int K=7;
  if(t[0][1][1]||t[0][1][2]||t[0][2][1]||t[0][2][2])return 0;
  
  memset(visited,0,sizeof(visited));    
  queue< state > Q;    
  Q.push((state){0,1,1,1,1,1,1});
  while(!Q.empty()){
    state s=Q.front();Q.pop();
    if(s.p==n-1)return 1;
    
    for(int i=0;i<4;i++){
      for(int j=0;j<=2;j++){
        int np=s.p+1;
        int ny=s.y+dy[i]*j;
        int nx=s.x+dx[i]*j;        
        if(ny<0 || 2<ny)continue;
        if(nx<0 || 2<nx)continue;
        if(t[np][ny][nx])continue;
        if(t[np][ny+1][nx])continue;
        if(t[np][ny][nx+1])continue;
        if(t[np][ny+1][nx+1])continue;
        int na=s.a+1,nb=s.b+1,nc=s.c+1,nd=s.d+1;          
        if(ny==0&&nx==0)na=0;
        else if(ny==0&&nx==2)nb=0;
        else if(ny==2&&nx==0)nc=0;
        else if(ny==2&&nx==2)nd=0;
        if(na==K||nb==K||nc==K||nd==K)continue;
        if(visited[np][ny][nx][na][nb][nc][nd])continue;
        visited[np][ny][nx][na][nb][nc][nd]=true;
        Q.push((state){np,ny,nx,na,nb,nc,nd});
      }
    }
  }
  return 0;
}

int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    memset(t,0,sizeof(t));
    for(int i=0;i<n;i++)
      for(int j=0;j<4;j++)
        for(int k=0;k<4;k++)
          cin>>t[i][j][k];
    cout<<solve()<<endl;
    
  }
  return 0;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    string S;
    while(cin>>S,S!="#"){
        S+="/";
        vector<vint>fld;
        vint vec;
        rep(i,S.size()){
            if(isdigit(S[i])){
                rep(j,S[i]-'0')vec.pb(0);
            }
            else if(S[i]=='b')vec.pb(1);
            else{
                fld.pb(vec);
                vec.clear();
            }
        }
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        a--;b--;c--;d--;
        swap(fld[a][b],fld[c][d]);
        string ans;
        rep(i,fld.size()){
            int cur=0;
            while(cur<fld[i].size()){
                if(fld[i][cur]==1){
                    ans+="b";
                    cur++;
                }
                else{
                    int next=cur;
                    while(next<fld[i].size()&&fld[i][next]==0)next++;
                    ans+='0'+next-cur;
                    cur=next;
                }
            }
            if(i+1!=fld.size())ans+="/";
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3220
#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 all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N;
	cin >> N;
	VV<int> G(N);
	rep(i,N-1){
		int x,y;
		cin >> x >> y;
		x--,y--;
		G[x].pb(y);
		G[y].pb(x);
	}
	V<int> d(N);
	function<void(int,int)> dfs = [&](int v,int p){
		if(p != -1) d[v] = d[p] + 1;
		else d[v] = 0;
		for(int u:G[v]) if(u!=p) dfs(u,v);
	};
	dfs(0,-1);
	int far = 0;
	rep(i,N) if(d[far] < d[i]) far = i;
	dfs(far,-1);
	int dia = 0;
	rep(i,N) chmax(dia,d[i]);
	cout << (dia%3 == 1 ? "Second" : "First") << endl;
}


Measured memory_bytes: 24448
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  auto r = readln.chomp.to!int;
  writeln(r * r);
}


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

using namespace std;

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

	int ans = 0;
	const string goal = "CODEFESTIVAL2016";
	map<char, char> r;
	for (size_t i = 0; i < S.length(); ++i) {
		if (S[i] != goal[i]) {
			++ans;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
// READ & UNDERSTAND
// ll, int overflow, array bounds
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int const mxn=1e5+5;

ii a[mxn];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n,m;
	cin >> n >> m;
	for(int i=0; i<n; i++){
		cin >> a[i].fi >> a[i].se;
	}
	sort(a,a+n);
	ll cnt=0,ans=0;
	for(int i=0; i<n; i++){
		int cur = a[i].se;
		if(cur+cnt>m){
			cur = m-cnt;
		}
		if(cur==0)break;
		cnt += cur;
		ans += ll(cur)*a[i].fi;
	}
	cout << ans << endl;
}	


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<(k) ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=(k) ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define TIME(i) Timer i(#i)
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
class Timer {
private:
    string scope_name;
    chrono::high_resolution_clock::time_point start_time;
public:
    Timer (string name) : scope_name(name) {
        start_time = chrono::high_resolution_clock::now();
    }
    ~Timer () {
        auto stop_time = chrono::high_resolution_clock::now();
        auto length = chrono::duration_cast<chrono::microseconds>(stop_time - start_time).count();
        double mlength = double(length) * 0.001;
        debug(scope_name, mlength);
    }
};
#else
#define TIME(i)
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
const ll MAXN = 100005;

int n, m, acs,pen[MAXN];
bool ac[MAXN];
/********** Good Luck :) **********/
int main () {
    TIME(main);
    IOS();

    cin >> n >> m;
    REP (i, m) {
        int p;
        string s;
        cin >> p >> s;
        if (!ac[p]) {
            if (s[0] == 'A') {
                ac[p] = true;
                acs++;
            } else {
                pen[p]++;
            }
        }
    }

    int was = 0;
    REP1 (i, n) {
        if (ac[i]) {
            was += pen[i];
        }
    }

    cout << acs << " " << was << endl;
    return 0;
}


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

int main(){
	long long int prime[50040];
	long long int ptr=0;
	unsigned long counter = 0;
	prime[ptr++] = 2;
	prime[ptr++] = 3;
	
	for(int no =3 ; no <= 50040 ; no += 2){
		int flag=0;
		for(int i=1 ; prime[i] * prime[i] <= no ; i++){
			counter++;
			if(no % prime[i] == 0){
				flag = 1;
				break; 
			}
		}
		if(!flag)
			prime[ptr++] = no;
	}
	
	long long int n;
	while(cin>>n){
		int i;
		for(i=0;i<50040;i++){
			if(n<prime[i])break;
		}
		if(n==3){
			cout<<2;	
		}else{
			if(prime[i-1]==n)cout<<prime[i-2];
			else cout<<prime[i-1];
		}
		//printf("%d %d",prime[i-1],prime[i-2]);
		cout<<" "<<prime[i]<<endl;
	}
	
}

Measured memory_bytes: 1208
while line = gets
  a, b, c, d, e, f = line.split.map(&:to_f)
  x = Rational(b*f - c*e, b*d - a*e)
  y = Rational(a*f - d*c, a*e - b*d)
  printf "%.3f %.3f\n", x, y
end

Measured memory_bytes: 6156
s = list(str(input()))
q = int(input())
o = ['']*q
for i in range(q):
    o[i] = str(input())
     
for i in range(q):
    order = o[i].split(' ')
    if order[0] == 'print':
        a,b = int(order[1]),int(order[2])
        for i in range(a,b+1):
            print(s[i],end = '')
        print('')
 
    elif order[0] == 'reverse':
        a,b = int(order[1]),int(order[2])
        tmp = s[a:b+1]
        tmp.reverse()
        s[a:b+1] = tmp        
         
    elif order[0] == 'replace':
        a,b,p = int(order[1]),int(order[2]),list(order[3])
        for i in range(b-a+1):
            s[a+i] = p[i]


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

int main () {
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >>r;
    if ((x - r) < 0 || (x + r) > W || (y - r) < 0 || (y + r) > H) cout << "No\n";
    else cout << "Yes\n";    
}

Measured memory_bytes: 1124
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
int main(){
	double a,b,c,d,e,f,x,y;
	while(cin>>a){
		cin>>b>>c>>d>>e>>f;
		x=(c*e-b*f)/(a*e-b*d);
		y=(c*d-a*f)/(b*d-a*e);
		if(x==-0)
			x=0;
		if(y==-0)
			y=0;
		cout<<fixed<<setprecision(3)<<x<<" ";
		cout<<fixed<<setprecision(3)<<y<<endl;
	}
	return 0;
}

Measured memory_bytes: 1280
n = int(input())
*A, = map(int, input().split())
m = max(A)
C = [0 for a in range(m + 1)]
for a in A:
    C[a] += 1
s = 0
for a in range(2, m + 1):
    s = max(s, sum(C[a::a]))
if s < 2:
    print('pairwise coprime')
elif s < n:
    print('setwise coprime')
else:
    print('not coprime')


Measured memory_bytes: 127544
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<utility>
#include<array>
#include<cassert>
#include<list>
#include<experimental/any>
#include<cstring>
#include<cctype>
#include<ctime>
#include<cstdbool>
#include<cstdint>
#include<cstddef>
#include<set>
#include<unordered_set>
#include<bitset>
 
using namespace std;
using experimental::any;
 
#define SPEEDY cin.tie(0);ios::sync_with_stdio(false);
 
#define REP(i,n) for(int i=0;i<(n);i++)
#define ARREP(i,n,X) for(int i=0;i<(n);i++)cin>>X[i]
#define FOR(i,X,n) for(int i=(X);i<(n);i++)
#define EREP(i,n) for(int i=1;i<=n;i++)
#define BitFOR(N) REP(Bit,1<<(N))
 
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define TFDEB(f) (f)? cout<<"true ":cout<<"false ";
#define FORDEB(n,X) for(int i=0;i<(n);i++)ARDEB(i,X)
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define ARDEB(i,X) {}
#define TFDEB(f) {}
#define FORDEB(n,X) {}
#define END {}
#endif
 
typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
#define ALL(X) X.begin(),X.end()
struct edge{int to,cost;};
//struct edge{int from,cost,to;};
struct P2{int x,y;};
#define BIT(Bit,n) bitset<n>(Bit)
#define Endl endl
#define YN(f) cout<<((f)?"Yes":"No")<<endl
 
const int MOD7=1000000007;
const int INF=100000000;
const int SET=1000; 

int main(){
	int a,b;
	cin>>a>>b;
	if(a+b>=10){
		cout<<"error"<<endl;
	}
	else cout<<a+b<<endl;
	return 0;
}

Measured memory_bytes: 256
from collections import Counter
K, N = map(int, input().split())
mod = 998244353
frac = [1]*5010
for i in range(2,5010):
    frac[i] = i * frac[i-1]%mod
fraci = [None]*5010
for i in range(5010):
    fraci[i] = pow(frac[i], mod-2, mod)
def comb(a, b):
    if not a >= b >= 0:
        return 0
    return frac[a]*fraci[b]*fraci[a-b]%mod
A = Counter()
def calc(x):
    if A[x]:
        return A[x]
    res = 0
    for i in range(N//2+1):
        res = (res + (-1)**i*comb(x, i)*comb(N+K-1-2*i, N-2*i))%mod
    A[x] = res
    return res
for j in range(2, 2*K+1):
    print(calc(min(j, (2*K+2-j))//2))

Measured memory_bytes: 50268
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  priority_queue<pair<int, int>> q;
  rep(i, n){
    cin >> a.at(i);
    q.push({a.at(i), i*-1});
  }
  vector<ll> ans(n, 0);
  int used = 0;
  while(!q.empty()){
    auto [mx, now] = q.top(); q.pop();
    now *= -1;
    used++;
    while(!q.empty() && q.top().first == mx){
      used++;
      q.pop();
    }
    vector<int> backs;
    while(!q.empty() && q.top().second*-1 > now){
      backs.push_back(q.top().first);
      q.pop();
    }
    if(q.empty() == true){
      ans.at(now) += (ll)mx*used;
    }else{
      ll d = mx - q.top().first;
      ans.at(now) += d*used;
    }
    for(auto i : backs){
      int mi = 0;
      if(!q.empty()) mi = q.top().first;
      ans.at(now) += i - mi;
      used++;
    }
  }
  for(auto i : ans){
    cout << i << endl;
  }
  return 0;
}

Measured memory_bytes: 6024