akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define get0(x)     (get<0>(x))
#define get1(x)     (get<1>(x))
#define get2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       9223372036854775807LL
#define LLMIN       -9223372036854775808LL
#define IMAX        2147483647
#define IMIN        -2147483648
typedef long long LL;
using namespace std;

int *buildRMQ(int *a, int n) {
  int logn = 1;
  for (int k = 1; k < n; k *= 2) ++logn;
  int *r = new int[n * logn];
  int *b = r; copy(a, a+n, b);
  for (int k = 1; k < n; k *= 2) {
    copy(b, b+n, b+n); b += n;
    REP(i, n-k) b[i] = min(b[i], b[i+k]);
  }
  return r;
}
int minimum(int x, int y, int *rmq, int n) {
  int z = y - x, k = 0, e = 1, s; // y - x >= e = 2^k なる最大 k
  s = ( (z & 0xffff0000) != 0 ) << 4; z >>= s; e <<= s; k |= s;
  s = ( (z & 0x0000ff00) != 0 ) << 3; z >>= s; e <<= s; k |= s;
  s = ( (z & 0x000000f0) != 0 ) << 2; z >>= s; e <<= s; k |= s;
  s = ( (z & 0x0000000c) != 0 ) << 1; z >>= s; e <<= s; k |= s;
  s = ( (z & 0x00000002) != 0 ) << 0; z >>= s; e <<= s; k |= s;
  return min( rmq[x+n*k], rmq[y+n*k-e+1] );
}

int N,A[200000];
map<int,int> id;
int *RMQ;

LL rec(int l,int r,int x){
    if(l+1==r)
        return A[l];
    int p=id[x];
    LL res=0;
    res=(LL)(p+1-l)*(LL)(r-p)*(LL)x;
    if(l<p)
        res+=rec(l,p,minimum(l,p-1,RMQ,N));
    if(p+1<r)
        res+=rec(p+1,r,minimum(p+1,r-1,RMQ,N));
    return res;
}

int main(void){
    cin>>N;
    REP(i,N){
        cin>>A[i];
        id[A[i]]=i;
    }
    RMQ=buildRMQ(A,N);
    cout<<rec(0,N,1)<<endl;
    return 0;
}

Measured memory_bytes: 44032
# coding: utf-8

A, B, C, X, Y = map(int, input().split())
pt1 =(A*X)+(B*Y)
pt2 = 2*C*max(X,Y)
pt3 = 2*C*min(X,Y)+((A*(X-Y)) if X>Y else B*(Y-X))

print(min(pt1,pt2,pt3))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    string S;
    cin >> S;
    for(char c='a';c<='z';c++){
        if(S[0]==c){
            cout << "a" << endl;
        }
    }
    for(char c='A';c<='Z';c++){
        if(S[0]==c){
            cout << "A" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args)  {

		Scanner scaner = new Scanner( System.in );

		int first = Integer.parseInt( scaner.next() );
		int second= Integer.parseInt( scaner.next() );
		int third = Integer.parseInt( scaner.next() );

		int [] nums = { first, second, third };

		bobleSort( nums );

	    System.out.println( nums[0] + " " + nums[1] + " " + nums[2] );

		scaner.close();
	}

	public static void bobleSort( int [] nums ) {

		for ( int i = 0; i < nums.length - 1; i++ ) {
			for ( int j = nums.length - 1; j > i; j-- ) {
				if ( nums[ j ] < nums[ j - 1 ] ) {
					swap( nums, j, j - 1 );
				}
			}
		}
	}

	public static void swap( int [] nums, int i , int j ) {
		int remain = nums[ i ];
		nums[ i ]  = nums[ j ];
		nums[ j ]  = remain;
	}

}

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

template <typename TYPE>
void swap(TYPE* a, TYPE* b)
{
	TYPE temp;
	temp = *a;
	*a = *b;
	*b = *a;
}

int main(void)
{
	int n[3];
	for (int i = 0; i < 3; i++) cin >> n[i];

	for (int i = 0; i < 3-1; i++)
	{
		for (int j = i + 1; j < 3; j++)
		{
			if (n[i] > n[j]) swap(n[i], n[j]);
		}
	}
	for (int i = 0; i < 2; i++) cout << n[i] << " ";
	cout << n[2] << endl;
	return 0;
}


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

using namespace std;

struct Dsu {
    int n;
    vector<int> p;
    
    Dsu(int _n) { n = _n; p.resize(n); init(); }
    inline void init() {
        for (int i = 0; i < n; i++) {
            p[i] = i;
        }
    }
    inline int find(int x) {
        return p[x] == x ? x: p[x] = find(p[x]);
    }
    inline bool join(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        p[y] = x; return true;
    }
    inline bool check(int x, int y) {
        return find(x) == find(y);
    }
};

void solve() {
    int n, m;
    cin >> n >> m;
    Dsu d(n+1);
    while (m--) {
        int x, y, z;
        cin >> x >> y >> z;
        d.join(x, y);
    }
    set<int> f;
    for (int i = 1; i <= n; i++) {
        f.emplace(d.find(i));
    }
    int res = f.size();
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int n, k; cin >> n >> k;
    int a[n];
    rep(i,n) cin >> a[i];

    int dp[k+1];
    rep(i,k+1) dp[i] = 0;

    for(int i=1; i<=k; i++){
        rep(j,n){
            if(i-a[j]>=0 && dp[i-a[j]] == 0) dp[i] = 1;
        }
    }
    if(dp[k]) cout << "First" << endl;
    else cout << "Second" << endl;

}

Measured memory_bytes: 3952
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const int M=3010;
int main(){
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	long long ret=0;
	long long ks=1;
	for(int i=0;i<a;i++)for(int j=0;j<a;j++){
		printf("? %d %d %d %d\n",i,j,i,j);
		fflush(stdout);
		int t;
		scanf("%d",&t);
		if(t)ret=(ret+ks)%d;
		ks=ks*2%d;
	}
	char *p = new char[1000000];
	for(int i=0;i<1000000;i++)p[i]='e';
	printf("! %lld\n",ret);
}

Measured memory_bytes: 1620
#include<bits/stdc++.h>
using namespace std;
int arr[10];
int main() {
		int a;
  cin>>a;
  string s;
  cin>>s;
  
  if (a>=3200) {
    cout<<s<<endl;
      return 0;
  }
  
  else {
   cout<<"red"<<endl;
    return 0;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
typedef long long ll;
using namespace std;
int main()
{
  string a;
  cin >> a;
  int ans = 0;
  cout << 700 + 100*(a[0] == 'o')+ 100*(a[1] == 'o') + 100*(a[2] == 'o')<< endl;
}


Measured memory_bytes: 256
/*            AUTHOR - SHIVAM GUPTA
                       Jalpaiguri Govt. Engg College             */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
vector<ll> ve[100005];
ll vis[100005],z;
ll a[100005][5],dp[100005][5],n,k;

ll f(ll x,ll picked)
{
    if(dp[x][picked]!=-1)
    return dp[x][picked];
    
    ll z=0;
    if(x>=n)
    return 0;
    
    if(picked==1)
    z=max({a[x][2]+f(x+1,2),a[x][3]+f(x+1,3)});
    else if(picked==2)
    z=max({a[x][1]+f(x+1,1),a[x][3]+f(x+1,3)});
    else if(picked==3)
    z=max({a[x][2]+f(x+1,2),a[x][1]+f(x+1,1)});
    
    return dp[x][picked]=z;
}

void solve()
{
    ll m=0,i=0,j=0,c=0,l=0,r=0,p=0,q=0,x=0,y=0,z=0,flag=0,sum=0;
    string s,t;
    cin>>n;
    for(i=0;i<n;i++)
    for(j=1;j<4;j++)
    cin>>a[i][j];
    memset(dp,-1,sizeof(dp));
    z=max({a[0][1]+f(1,1),a[0][2]+f(1,2),a[0][3]+f(1,3)});
    cout<<z<<endl;
    
}
bool imp=false;int main()
{
    fio;
    int t=1;
    if(imp)
	cin>>t;
	ll j=t;
    while(t--){
    // cout<<"Case #"<<j-t<<": ";
    solve();}
    return 0;
}

Measured memory_bytes: 15872
import sys
# input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import math
import heapq
from collections import defaultdict, Counter, deque
from bisect import bisect_left
MOD = 10**9 + 7
INF = 1 << 20


def main():
    n = getN()
    s = input().strip()

    rs = []
    gs = []
    bs = []
    for i, c in enumerate(s):
        if c == "R":
            rs.append(i)
        elif c == "G":
            gs.append(i)
        else:
            bs.append(i)


    lr, lg, lb = len(rs), len(gs), len(bs)
    ans = 0
    # print(s, s[1])
    tgt = {"R": rs, "G":gs, "B": bs }
    idxs = {"R": lr, "G": lg, "B": lb}
    for i in range(n-1):
        first = s[i]
        for j in range(i+1, n):
            # first = s[i]
            second = s[j]
            # print(i, j)
            if first == second:
                continue
            else:
                # print(first, second)
                rem = ["R", "G", "B"]
                rem.remove(first)
                rem.remove(second)
                remm = rem[0]
                # print(i, j, remm)
                ans += idxs[remm] - bisect_left(tgt[remm], j)
                if (2*j - i) < n and s[2*j - i] == remm:
                    ans -= 1
                    # print("substracted")
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 69092
LI = lambda: list(map(int, input().split()))

N, X = LI()
L = LI()


def main():
    ans = 1
    d = 0
    for l in L:
        d += l
        if d > X:
            break
        ans += 1
    print(ans)


if __name__ == "__main__":
    main()


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    int n, m;
    cin >> n >> m;
    map<int, int> mp;
    for(int i = 0; i <= 100000; i++){
        mp[i] = 0;
    }
    for(int i = 1; i <= n; i++){
        int in;
        cin >> in;
        mp[in]++;
    }
    int odds[100500];
    int evens[100500];
    for(int i = 0; i <= 100000; i++){
        odds[i] = 0;
        evens[i] = 0;
    }
    for(int i = 1; i <= 100000; i++){
        int number = i % m;
        evens[number] += (mp[i] / 2) * 2;
        if(mp[i] % 2 == 1){
            odds[number]++;
        }
    }
    int ans = 0;
    //for(int i = 1; i <= 1; i++){
    for(int i = 1; i * 2 < m; i++){
        int number = min(odds[i], odds[m - i]);
        ans += number;
        odds[i] -= number;
        odds[m - i] -= number;
        //cout << ans << endl;
        number = min(odds[i], evens[m - i]);
        ans += number;
        //cout << ans << endl;
        odds[i] -= number;
        evens[m - i] -= number;
        number = min(evens[i], odds[m - i]);
        ans += number;
        //cout << ans << endl;
        evens[i] -= number;
        odds[m - i] -= number;
        ans += evens[i] / 2;
        ans += evens[m - i] / 2;
        //cout << i << " " << ans << endl;
    }
    ans += odds[0] / 2;
    evens[0] += (odds[0] % 2);
    ans += evens[0] / 2;
    if(m % 2 == 0){
        int check = m / 2;
        ans += odds[check] / 2;
        evens[check] += (evens[check] % 2);
        ans += evens[check] / 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5888
#include<bits/stdc++.h>
using namespace std;
bool palin(string s){
  for(int i=0;i<s.length()/2;i++){
  		if(s[i]!=s[s.length()-1-i])
          return false;
  }
  return true;
}
int main(){
  string s;
  cin>>s;
  int n=s.length();
  int p=(n-1)/2;
  int q=(n+3)/2-1;
  int r=n-q;
  string a=s.substr(0,p);
  string b=s.substr(q,r);
  if(palin(s)&&palin(a)&&palin(b))
    cout<<"Yes";
    else
        cout<<"No";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)


int main(){
   int n;
   string s;
   cin >> s;
   rep(i,3){
      if (s[i] == '7'){
         cout << "Yes" << endl;
         return 0;
      }
   }
   cout << "No" << endl;
   
   return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>
#include<limits>
#include<map>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vii vector<vector<int>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
using namespace std;

void prob138() {
	int N; cin >> N;
	priority_queue<double,vector<double>,greater<double>> pq;
	for (int i = 0; i < N; i++) {
		double x;
		cin >> x;
		pq.push(x);
	}

	for (int i = 0; i < N - 1; i++) {
		double x = pq.top(); pq.pop();
		double y = pq.top(); pq.pop();
		double z = (x + y) / 2;
		pq.push(z);
	}

	printf("%.10lf\n", pq.top());
}

void prob136() {
	int N; cin >> N;
	int max = 0, min = int_INF;
	bool flag = false;
	rep(i, N) {
		int x; cin >> x;
		if (x > max) {
			max = x; min = int_INF;
		}
		x <= min ? min = x : 1;
		if (max - min > 1) {
			flag = true;
			break;
		}
	}

	if (flag) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
}

void prob140() {
	int N; cin >> N;
	vector<int> B(N + 1);
	B[0] = int_INF; B[N] = int_INF;
	for (int i = 1; i < N; i++) {
		cin >> B[i];
	}
	ll ans = 0;
	for (int j = 0; j < N; j++) {
		ans += min(B[j], B[j + 1]);
	}

	cout << ans << endl;
}
int main() {
	prob140();
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input_byline {
    ($($r:tt)* ) => {
        let stdin = std::io::stdin();
        let mut q = std::collections::VecDeque::new();
        let mut next = || {
            if q.is_empty() {
                let mut s = String::new();
                stdin.read_line(&mut s);
                for v in s.split_whitespace() {
                    q.push_back(v.to_string());
                }
            }
            q.pop_front().unwrap()
        };
        input_inner!{next, $($r)*}
    };

}

#[allow(unused_macros)]
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

trait Printable {
    fn p(&self);
}

impl<T: std::fmt::Display> Printable for T {
    fn p(&self) {
        println!("{}", self);
    }
}

impl<T: std::fmt::Display> Printable for [T] {
    fn p(&self) {
        for i in 0..self.len() {
            if i != 0 {
                print!(" ");
            }
            print!("{}", self[i]);
        }
        println!("");
    }
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn main() {
    input! {
        n: usize,
        s: chars,
    }

    if n & 1 == 1 {
        println!("No");
        return;
    }

    for i in 0..n / 2 {
        if s[i] != s[n / 2 + i] {
            println!("No");
            return;
        }
    }
    println!("Yes");
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;

template<class T> inline
void read(T& x) {
	int f = 1; x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9')   {if (ch == '-') f = -1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}

/*============ Header Template ============*/

const int N = 3000 + 5;
const int mo = 1000000007;

int n, m, num;
char str[N];
int f[N][N], vis[N][N], s[N];
int L[N], R[N], W[N];
int C[N][N];

int solve(int x, int k) {
	if (vis[x][k]) return f[x][k];
	if (k < 0 || k > W[x]) {printf("fuck %d %d\n", x, k);}
	vis[x][k] = 1;
	int ans = 0, ALL = s[R[x]] - s[L[x] + W[x] - 1] + k;
	if (x == num) return f[x][k] = C[R[x] - L[x] + 1][ALL];
	int LS = max(0, ALL + W[x + 1] - (R[x] - L[x] + 1));
	int RS = min(W[x + 1], ALL);
	for (int i = LS; i <= RS; i++) {
		ans = (ans + 1LL * solve(x + 1, i) * C[R[x] - L[x] + 1 - W[x + 1]][ALL - i] % mo) % mo;
	}
	return f[x][k] = ans;
}

int fish(int a, int b) {
	int ls = max(L[a], L[b]), rs = min(R[a], R[b]);
	return max(0, rs - ls + 1);
}

int main() {
	read(n), read(m);
	scanf("%s", str + 1); n = strlen(str + 1);
	for (int i = 1; i <= n; i++) s[i] = s[i - 1] + (str[i] == '1');
	for (int i = 0; i <= n; i++) {
		C[i][0] = C[i][i] = 1;
		for (int j = 1; j < i; j++) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mo;
	}
	int mx = 0; num = 0;
	for (int i = 1, ls, rs; i <= m; i++) {
		read(ls), read(rs);
		if (rs <= mx) continue;
		num++; L[num] = ls; R[num] = rs; mx = rs; W[num] = fish(num - 1, num);
	}
	int ans = solve(1, 0);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 70784
#include <stdio.h>
#include <string.h>
int main(){

	int ntable;
	int a[62];
	int b[62];
	int nchar;
	char c;
	int ca;
	char str[10];
	
	int i,j;
	
	while(scanf("%d\n",&ntable)!=EOF){
	if(!ntable)break;
		for(i=0;i<ntable;i++){
			scanf("%[^\n]\n",str);
			a[i]=str[0];b[i]=str[2];
		}
	
		scanf("%d\n",&nchar);
		for(i=1;i<=nchar;i++){
			scanf("%[^\n]\n",str);
			c=str[0];
			for(j=0;!(a[j]==c || j>=ntable);j++);
			printf("%c",j<ntable?b[j]:c);
		}
		printf("\n");
		
	
	}

	return 0;
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a, b, x;
	cin >> a >> b >> x;
	if (a>x){cout << "NO" << endl;}
	else if (a+b>=x){cout << "YES" << endl;}
	else {cout << "NO" << endl;}
}

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

using namespace std;

int main()
{
  int N;
  string S;

  cin >> N;
  cin >> S;

  int A = 0, B = 0;
  for(int i = 0; i < S.size(); i++) {
    if(S[i] == '<') ++A;
    else break;
  }
  for(int i = S.size() - 1; i >= 0; i--) {
    if(S[i] == '>') ++B;
    else break;
  }
  cout << N - min(A, B) << endl;
}

Measured memory_bytes: 3316
from collections import deque
from copy import deepcopy
h, w = map(int, input().split())
table = [[] for _ in range(h)]
for i in range(h):
    table[i] = list(input())

steps = [0, 1, 0, -1, 0]
ans = 0
for y in range(h):
    for x in range(w):
        if table[y][x] == "#":
            continue
        t = deepcopy(table)
        t[y][x] = 0
        queue = deque()
        queue.append((y, x))
        while len(queue) > 0:
            cur = queue.popleft()
            for i in range(4):
                ny, nx = cur[0] + steps[i], cur[1] + steps[i + 1]
                if 0 <= ny and ny < h and 0 <= nx and nx < w and t[ny][
                        nx] == ".":
                    t[ny][nx] = t[cur[0]][cur[1]] + 1
                    queue.append((ny, nx))
        tmp = 0
        for i in range(h):
            for j in range(w):
                if str(t[i][j]).isnumeric():
                    tmp = max(tmp, t[i][j])
        ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 3444
///----> bismillahir rahmanir rahim <---- -- { ^ _ ^ }
///     { ^_^ }   { ^ _ ^ }
#include<bits/stdc++.h>
#include<bits/stdc++.h>
using namespace std;

//<--------------------------------------------typo section--------------------------------------------->
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;
typedef priority_queue<int>piwi;
typedef queue<int>kiwi;
typedef map<int,int>mi;
typedef map<string,int>mis;
typedef multimap<int,int>muli;
typedef multimap<string,int>muls;
typedef multiset<int>si;

//<----------------------------------------------------Narcos----------------------------------------------->
#define endl "\n"
#define Y cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define yes cout<<"Yes"<<endl;
#define no cout<<"No"<<endl;
#define sp " "
#define PB push_back
#define F first
#define S second
#define as(a) (a).begin(),(a).end()
#define ras(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()
#define ki 1LL
#define MOD 1000000007
#define over return 0;
#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))
#define test int t;cin>>t;while(t--)


//<-----------------------------------------------------Const--------------------------------------------------->
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;


//<--------------------------------------------------------------------------------------------------->
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

const long long MAX_SIZE = 1000001; vector<long long >isprime(MAX_SIZE , true); vector<long long >prime; vector<long long >SPF(MAX_SIZE); void manipulated_seive(int N) { isprime[0] = isprime[1] = false ; for (long long int i=2; i<N ; i++) { if (isprime[i]) { prime.push_back(i); SPF[i] = i; } for(int j=0;j < (int)prime.size() && i*prime[j] < N && prime[j] <= SPF[i]; j++) { isprime[i*prime[j]]=false; SPF[i*prime[j]] = prime[j] ; } } }
int man_seive(int n){ manipulated_seive(n); for(int i=0;i<prime.size() && prime[i]<=n;i++)
cout<<prime[i]<<endl;
}
ll gcd ( ll a, ll b ) { return __gcd ( a, b ); }
ll lcm ( ll a, ll b ) { return a * ( b / gcd ( a, b ) ); }

//continue;

//-----------------------------> YOUR JOURNEY STARTS HERE ------------------------------------>>

int main(){
    optimize();
    int n;
    cin>>n;
    string h;cin>>h;
    string l;cin>>l;
    string ans;
    for(int i=0;i<n;i++){
        ans+=h[i];
        ans+=l[i];
    }
    cout<<ans<<endl;

over
}


Measured memory_bytes: 18616
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

ll fac[400007],finv[400007],inv[400007];
void cominit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<400007;i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
ll com(ll n,ll k){
    if(n<k)return 0;
    if(n<0 || k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    cominit();
    ll n,k;
    cin>>n>>k;
    if(k>=n){
        cout << com(2*n-1,n) <<endl;
        return 0;
    }
    ll ans=0;
    for(ll i=0LL;i<=k;i++){
        ans+=(com(n,i)*com(n-1,i))%mod;
        ans%=mod;
    }
    cout << ans<<endl;
    return 0;
}


Measured memory_bytes: 9600
#include<stdio.h>

int main()
{
  char s[11];
  int d[10][11], i, j;
  while(scanf("%s", s) != -1)
  {
    for(i = 0; i < 10; i++)
      d[0][i] = s[i] - '0';
    for(i = 0; i < 10; i++)
      for(j = 0; j < 9 - i; j++)
        d[(i + 1) % 2][j] = (d[i % 2][j] + d[i % 2][j + 1]) % 10;
    printf("%d\n", d[1][0]);
  }
  return 0;
}

Measured memory_bytes: 540
import sys
input = sys.stdin.readline

N, M = (int(i) for i in input().split())

def soin(N):
	res = []
	i = 2
	while i < round(N**(1/2)) + 3:
		if N%i == 0:
			res.append(i)
			N = N//i
			i = 2
		else:
			i += 1
	if N != 1:
		res.append(N)
	return res

def power(a, b):
	if b == 0:
		return 0
	elif b == 1:
		return a % 1000000007
	elif b % 2 == 0:
		return (power(a, b//2) ** 2) % 1000000007
	else:
		return (power(a, b//2) ** 2 * a) % 1000000007

def divide(a, b):
	return (a * power(b, 1000000005)) % 1000000007

def combination(a, b):
	res = 1
	for i in range(b):
		res *= a - i
		res = res % 1000000007
	for i in range(b):
		res = divide(res, i+1)
	return res
if M == 1:
	res = 1
else:
	L = soin(M)
	cc = 1
	res = 1
	for i in range(len(L) -1):
		if L[i] == L[i+1]:
			cc += 1
		else:
			res *= combination(N + cc -1, cc)
			res = res % 1000000007
			cc = 1
	res *= combination(N+cc -1, cc)
	res = res % 1000000007
print(res)

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

using namespace std;
typedef long long ll;

string s;
ll ans = 0;

ll f(string now) {
  ll res = 0;
  string cur = "";
  for (size_t i = 0; i < now.size(); ++i) {
    if (now[i] == '+') {
      res += stoll(cur.c_str());
      cur = "";
    } else {
      cur += now[i];
    }
  }
  res += stoll(cur.c_str());
  return res;
}

void rec(int cur, string now) {
  if (cur < 0) {
    ans += f(now);
    return;
  }

  rec(cur - 1, now);
  if (cur > 0) {
    now.insert(cur, "+");
    rec(cur - 1, now);
  }
}

int main() {
  cin >> s;
  rec(s.size() - 1, s);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    int N, K, ans;
    cin >> N >> K;
    ans = 0;
    while ( N > 0 ){
        N /= K;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    C = input()
    if C in ['a', 'i', 'u', 'e', 'o']:
        print('vowel')
    else:
        print('consonant')


if __name__ == '__main__':
    main()


Measured memory_bytes: 8892
n,m = map(int,input().split())
cut = []
for _ in range(m):
  a,b = map(int,input().split())
  cut.append((a,b))
cut.sort(key = lambda x:x[1])

ex_b  = cut[0][1]
count = 0
for a,b in cut[1:]:
  if a >= ex_b:
    count += 1
    ex_b = b
print(count+1)



Measured memory_bytes: 18204
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  vector<int>vec(5);
  rep(i,5) {
    cin >>vec.at(i);
  }
 int time=0;
  int a=0;
  if(vec.at(0)%10 !=0) {
    a=vec.at(0)%10;
  }
  else {
    a=inf;
  }
 
  int b=0;
  if(vec.at(1)%10 !=0) {
    b=vec.at(1)%10;
  }
  else {
    b=inf;
  }
  int c=0;
  if(vec.at(2)%10 !=0) {
    c=vec.at(2)%10;
  }
  else {
    c=inf;
  }
  int d=0;
  if(vec.at(3)%10 !=0) {
    d=vec.at(3)%10;
  }
  else {
    d=inf;
  }
  int e=0;
  if(vec.at(4)%10 !=0) {
    e=vec.at(4)%10;
  }
  else {
    e=inf;
  }
  
  int x1=min(a,b);
  int x2=min(min(c,d),e);
  int x=min(x1,x2);
  int a1;
  if(vec.at(0)%10 !=0) {
    a1=((vec.at(0)+10)/10)*10;
  }
else {
  a1=vec.at(0);
}

            int a2;
  if(vec.at(1)%10 !=0) {
    a2=((vec.at(1)+10)/10)*10;
  }
else {
a2=vec.at(1);
}
            int a3;
  if(vec.at(2)%10 !=0) {
a3=((vec.at(2)+10)/10)*10;
  }
  else {
a3=vec.at(2);
  }

            int a4;
  if(vec.at(3)%10 !=0) {
a4=((vec.at(3)+10)/10)*10;
  }
else {
a4=vec.at(3);
}
            int a5;
  if(vec.at(4)%10 !=0) {
    a5=((vec.at(4)+10)/10)*10;
  }
else {
a5=vec.at(4);
}
            
            if(x==a) {
      cout <<a2+a3+a4+a5+vec.at(0);
            }
else if (x==b) {
      cout <<a1+a3+a4+a5+vec.at(1);
            }
           else if  (x==c) {
      cout <<a2+a1+a4+a5+vec.at(2);
            }
           else if (x==d) {
      cout <<a2+a3+a1+a5+vec.at(3);
            }
           else if (x==e) {
      cout <<a2+a3+a4+a1+vec.at(4);
            }
            }
            
            
            
            
  
  
  
  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (a); i < n; i++)
#define print(x) cout << x << endl;
using namespace std;
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; }
typedef long long ll;

int main()
{
    int N, A[3][3], b[10];
    bool appear[3][3];

    rep(i, 0, 3) {
        rep(j, 0, 3) {
            cin >> A[i][j];
        }
    }
    cin >> N;
    rep(i, 0, N) {
        cin >> b[i];
    }

    rep(i, 0, 3) {
        rep(j, 0, 3) {
            appear[i][j] = false;
            rep(k, 0, N) {
                if (A[i][j] == b[k]) appear[i][j] = true;
            }
        }
    }

    string ANS = "No";
    rep(i, 0, 3) {
        if (appear[i][0] && appear[i][1] && appear[i][2]) ANS = "Yes";
    }
    rep(i, 0, 3) {
        if (appear[0][i] && appear[1][i] && appear[2][i]) ANS = "Yes";
    }
    if (appear[0][0] && appear[1][1] && appear[2][2]) ANS = "Yes";
    if (appear[0][2] && appear[1][1] && appear[2][0]) ANS = "Yes";

    cout << ANS << endl;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc115/tasks/abc115_d

N, X = map(int, input().split())

l = [1]
p = [1]

for i in range(N):
    l.append(l[i] * 2 + 3)  # 各レベルの長さ
    p.append(p[i] * 2 + 1)  # 各レベルのパティの数


def f(n, x):
    if n == 0:
        return 0 if x <= 0 else 1
    elif x <= 1 + l[n-1]:
        return f(n-1,x-1)
    else:
        return p[n-1] + 1 + f(n-1, x-2-l[n-1])


print(f(N, X))

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
N = int(input())
edge = [[] for _ in range(N)]
for i in range(N-1):
  a = int(input())
  edge[i+1].append(a-1)
  edge[a-1].append(i+1)

def dfs(start):
  stack = [start]
  parent = [N]*N
  parent[start] = -1
  #記録したい値の配列を定義
  while stack:
    v = stack[-1]
    marker = 0
    lis = []
    for u in edge[v]:
      if u==parent[v]:
        continue
      if parent[u]==N: #子へ降ろす
        marker = 1
        parent[u]=v
        stack.append(u)
      else: #子から吸い上げる
        #吸い上げる際の個々の処理
        lis.append(ans[u])
    if marker==0:
      stack.pop()
      lis.sort(reverse=True)
      for i,l in enumerate(lis):
        ans[v] =  max(ans[v],i+1+l)
  return

ans = [0]*N
dfs(0)
print(ans[0])


Measured memory_bytes: 94788
using System;
class c
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var ta = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int ans = 0;
        double df = double.MaxValue;
        for (int i = 0; i < n; i++)
        {
            if (df >= Math.Abs(ta[1] - (ta[0] - 0.006 * h[i])))
            {
                df = Math.Abs(ta[1] - (ta[0] - 0.006 * h[i]));
                ans = i + 1;
            }
        }
        Console.WriteLine(ans);
    }
}

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

 int main() {
 string s, t;
 cin >> s >> t;
 int ans = 0;
  if(s[0] == t[0]) ans++;
 if(s[1] == t[1]) ans++;
 if(s[2] == t[2]) ans++;
 cout << ans << endl;
 return 0;
 }

Measured memory_bytes: 3620
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<algorithm>
#include<vector>
#include<queue>
#define ll long long
ll read()
{
	ll tmp=0;char c=getchar(),f=1;
	while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9'){tmp=tmp*10+c-48;c=getchar();}
	return tmp*f;
}
using namespace std;
char s[20];
int main()
{
	int i;
	scanf("%s",s);
	int flag=0,n=strlen(s);
	for(i=0;i<n;i++)
		if(s[i]=='9')flag=1;
	if(flag)printf("Yes");else printf("No");
}

Measured memory_bytes: 128
#!/usr/bin/env python3


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N = int(input())
    c = list(input())
    nR = c.count("R")
    nW = c.count("W")
    # print(c)
    rightR = c[nR:].count("R")
    leftW = c[:nR].count("W")
    print(max(rightR,leftW))

if __name__ == '__main__':
    main()


Measured memory_bytes: 80008
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    string s;cin>>s;
    ll num=0,f=0;
    for(int i=0;i<(int)s.length();i++){
        num *=10; num += s[i]-'0';
        f += s[i] - '0';
    }
    if(num%f==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    private static boolean IsValid(String password){
        if (password.length() < 6) {
            return false;
        }
        if (!password.matches(".*[0-9].*")) {
            return false;
        }
        if (!password.matches(".*[A-Z].*")) {
            return false;
        }

        return password.matches(".*[a-z].*");
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String password;
        while(sc.hasNext()) {
            password = sc.nextLine();
            if(IsValid(password)) {
                System.out.println("VALID");
            } else {
                System.out.println("INVALID");
            }
        }
    }
}


Measured memory_bytes: 26288
import sys
input = sys.stdin.readline


def main():
    N, Y = [int(x) for x in input().split()]

    for i in range(N + 1):
       for j in range(N + 1):
            k = N - i - j
            if k < 0:
                continue
            if i * 10000 + j * 5000 + k * 1000 == Y:
                print(i, j, k)
                exit()

    print(-1, -1, -1)






if __name__ == '__main__':
    main()



Measured memory_bytes: 3060
class UnionFind(object):#0~n-1であることに注意
    def __init__(self, size):
        self.parent = [i for i in range(size)]#親の番号を保存
        self.rank = [0 for _ in range(size)]#ランクを保存


    def find(self, x):#根の番号を返す
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])


    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):#根が同じか調べる
        return self.find(x) == self.find(y)
n, m = map(int, input().split())
p=list(map(int, input().split()))
xy=[list(map(int, input().split())) for i in range(m)]    
U=UnionFind(n)
for i in range(m):
    x, y = xy[i]
    U.unite(x-1, y-1)
ans=0
for i in range(n):
    if U.same(p[i]-1, i):
        ans+=1
print(ans)


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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,N,j) for(int i = (N-1);i >= (j);i--)
#define _rec(i,N,j) for(int i = (N);i >=(j);i--)
#define ALL(x) x.begin(),x.end()
#define MEM(a,n) memset(a,n,sizeof(a))
#define fst first
#define scd second
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

int get_int(){int x;scanf("%d",&x);return x;}
LL get_ll(){LL x;scanf("%lld",&x);return x;}
double get_db(){double x;scanf("%lf",&x);return x;}

template<typename T> int chmin(T &a,T b){if(a > b){a = b;return 1;}else return 0;}
template<typename T> int chmax(T &a,T b){if(a < b){a = b;return 1;}else return 0;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {_for(i,0,v.size()) os << v[i] << " ";return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){for(auto a:v) os << a <<" ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){os << v.fst <<" "<<v.scd << " ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& v){for(auto a:v) cout << a << endl;return os;}

static const int dx[8] = { -1,  0, 1, 0,  1, -1,  1, -1};
static const int dy[8] = {0,  1, 0,  -1,  1, -1, -1,  1};
const double pi  = acos(-1.0);
const double eps = 1e-8;
//const LL  INF  = 0x3f3f3f3f3f3f3f3f;
const int inf  = 0x3f3f3f3f;

const int maxn = 1e5+5;

LL N,X,D;

struct line{
    LL st,ed;
    line(LL s = 0, LL e = 0):st(s),ed(e){;}
    bool operator<(line &o){
        if( (st % D + D)%D == (o.st % D + D)%D){
            if(st == o.st) return ed < o.ed;
            else return st < o.st;
        }else return (st % D + D)%D < (o.st % D + D)%D;
    }
};


vector<line> vl;

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

    if(D == 0){
        if(X)
            cout << N + 1 << endl;
        else
            cout << 1 << endl;
        return 0;
    }

    if(D < 0){
        X = -X;
        D = -D;
    }

    vl.push_back(line(0,0));

    for(LL i = 1; i <= N; i++){
        LL a = i * X;
        LL beg = a + (i*(i-1))/2 * D;
        LL ed = a + D * ((2*N - i - 1)*i)/2;
        vl.push_back(line(beg,ed));
    }

    sort(ALL(vl));

    int sz = vl.size();
    LL ans = 0;
    int l = 0;int r = 0;

    while(l < sz){
        LL q = (vl[l].st % D + D)%D;
        while(r < sz && ( (vl[r].st % D + D)%D == q)) r++;

        int k = l;
        LL b = vl[k].st;
        LL e = vl[k].ed;

        while(k < r){
            while(k < r && vl[k].st <= e){
                e = max(e,vl[k].ed);
                k++;
            }
            ans += (e - b)/D + 1;
            if(k < r){
                b = vl[k].st;
                e = vl[k].ed;
            }
        }

        l = r;
    }

    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 6512
s = input()
check = 0
for i in range(len(s)):
  # 奇数文字目
  if (i+1) % 2 == 1:
    if s[i] == "L":
      check += 1
  # 偶数文字目
  if (i+1) % 2 == 0:
    if s[i] == "R":
      check += 1
      
if check == 0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
def main():
    import sys
    N,M=list(map(int,sys.stdin.readline().split()))
    dic={}
    st=set()
    for i in range(M):
        p,S=sys.stdin.readline().split()
        p=int(p)
        if S=='AC':
            st.add(p)
            try:
                dic[p]+=0
            except:
                dic[p]=0
        else:
            if p not in st:
                try:
                    dic[p]+=1
                except:
                    dic[p]=1
    
    pena=sum([dic[x] for x in list(st)])
    ac=len(list(st))
    print(' '.join([str(ac),str(pena)]))

main()


Measured memory_bytes: 64348
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, C, X, Y; cin >> A >> B >> C >> X >> Y; C *= 2;
  cout << (long)min(min(max(X, Y) * C, X * C + max(Y - X, 0) * B), min(Y * C + max(X - Y, 0) * A, X * A + Y * B)) << endl;
}

Measured memory_bytes: 256
fun main() {
    val MOD = 1_000_000_007
    val s = nextInt()
    if (s < 3) {
        println(0)
        return
    }
    var a0 = 1L
    var a1 = 0L
    var a2 = 0L
    (3..s).forEach {
        val n = (a0 + a2).rem(MOD)
        a0 = a1
        a1 = a2
        a2 = n
    }
    println(a2)
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)

// ## Array
inline fun <reified T> sizedArray(size: Int, default: T) = Array(size) { default }
inline fun <reified T> sized2DArray(row: Int, column: Int, default: T) = Array(row) { Array(column) { default } }

// ## mod^-1
//    [NOTE] CANNOT use this for 0, mod, 2mod, 3mod ...(return wrong value)
fun modinv(num: Long, mod: Long): Long {
    var a = num
    var b = mod
    var u = 1L
    var v = 0L
    while (b > 0) {
        val t = a.div(b)
        a -= t * b
        a = b.also { b = a } // swap a and b
        u -= t * v
        u = v.also { v = u } // swap u and v
    }
    u %= mod
    if (u < 0) u += mod
    return u
}

fun gcd(x: Int, y: Int): Int {
    fun innerGcd(x: Int, y: Int): Int {
        return if (x % y == 0) y else innerGcd(y, x % y)
    }
    return if (x >= y) innerGcd(x, y) else innerGcd(y, x)
}

fun gcd(x: Long, y: Long): Long {
    fun innerGcd(x: Long, y: Long): Long {
        return if (x % y == 0L) y else innerGcd(y, x % y)
    }
    return if (x >= y) innerGcd(x, y) else innerGcd(y, x)
}

// classes
class UnionFindTree(val size: Int) {
    private val r = sizedArray(size, -1)
    fun root(x: Int): Int {
        if (r[x] < 0) return x
        return root(r[x])
    }

    fun unite(x: Int, y: Int) {
        var rx = root(x)
        var ry = root(y)
        if (rx == ry) return
        if (r[rx] > r[ry]) {
            rx = ry.also { ry = rx }
        }
        r[rx] += r[ry]
        r[ry] = rx
    }

    fun size(x: Int) = -r[root(x)]

    override fun toString(): String {
        return r.joinToString(separator = ", ")
    }
}

Measured memory_bytes: 34676
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

ll ds(ll a) {
	ll res = 0;
	while (a) {
		res += a % 10;
		a /= 10;
	}
	return res;
}

int main() {
	int k;
	cin >> k;
	vector<ll> res;
	res.push_back(1);
	REP(i, k - 1) {
		ll t1 = res.back() + 1;
		ll t2 = t1;
		vector<ll> cand;
		ll t3 = 1;
		while (t2) {
			ll t4 = (t1 / t3 + 1) * t3 - 1;
			cand.push_back(t4);
			t2 /= 10;
			t3 *= 10;
		}
		ll t4 = (t1 / t3 + 1) * t3 - 1;
		cand.push_back(t4);
		int t5 = 0;
		ll t6 = cand[t5];
		ll t7 = ds(t6);
		REP(j, cand.size()) {
			ll t8 = ds(cand[j]);
			if (t6*t8>cand[j]*t7) {
				t6 = cand[j];
				t7 = t8;
				t5 = j;
			}
		}
		res.push_back(cand[t5]);
	}
	REP(i, res.size()) {
		put(res[i]);
	}
	return 0;
}

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


using namespace std;


typedef struct
{
	int x,y;
}rect;

int area(rect r)
{
	return r.x * r.y;
}


int main()
{
	while(1)
	{
		int n,w,h;
		cin >> n >> w >> h;
		if(n == 0&&w == 0&&h == 0)break;
		
		vector<rect> v;
		v.resize(1);
		v[0].x = w;
		v[0].y = h;
		
		for(int i= 0;i < n;i++)
		{
			int p,s;
			scanf("%d %d",&p,&s);
			p--;//o-index???????????????
			
			//??????????????¢?????¨???
			rect f = v[p];
			
			//??????????????¢?????????
			s%=(f.x+f.y)*2;
			
			rect r1,r2;
			
			if(s<f.x)
			{
				r1.x = s;r1.y = f.y;
				r2.x = f.x - s;r2.y = f.y; 
			}
			else if(s < f.x+f.y)
			{
				r1.x = f.x;r1.y = s - f.x;
				r2.x = f.x;r2.y = f.x+f.y-s;
			}
			else if(s < 2*f.x + f.y)
			{
				r1.x = 2*f.x + f.y - s;r1.y = f.y;
				r2.x = s - (f.x+f.y);r2.y = f.y;
			}
			else
			{
				r1.x = f.x;r1.y = 2*(f.x + f.y) - s;
				r2.x = f.x;r2.y = s - (2* f.x + f.y);
			}
			
			v.erase(v.begin() + p);
			
			if(area(r1)>area(r2))
			{
				v.push_back(r2);
				v.push_back(r1);
			}
			else
			{
				v.push_back(r1);
				v.push_back(r2);
			}
			
		}
		
		vector<int> ans;
		for(int i = 0;i < v.size();i++)
		{
			ans.push_back(area(v[i]));
		}
		sort(ans.begin(),ans.end());
		

		for(int i= 0;i < ans.size();i++)
		{
			if(i)putchar(' ');
			printf("%d",ans[i]);
		}
		
		puts("");
	}
	
	return 0;
}
			
			
				

Measured memory_bytes: 3236
#include "bits/stdc++.h"

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007

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

using namespace std;

string rev(string s) {
	string t = "";
	RREP(i, s.size()) {
		t += s[i];
	}
	return t;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int m;
	cin >> m;
	REP(i, m) {
		int cnt = 0;
		set<string> a;
		string s;
		cin >> s;
		FOR(i,1, s.size()) {
			string s1 = s.substr(0, i);
			string s2 = s.substr(i);
			if (a.insert(s1 + s2).second) cnt++;
			if (a.insert(s2 + s1).second) cnt++;
			if (a.insert(s1 + rev(s2)).second) cnt++;
			if (a.insert(rev(s2) + s1).second) cnt++;
			if (a.insert(rev(s1) + s2).second) cnt++;
			if (a.insert(s2 + rev(s1)).second) cnt++;
			if (a.insert(rev(s1) + rev(s2)).second) cnt++;
			if (a.insert(rev(s2) + rev(s1)).second) cnt++;
 		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 3256