akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in = new Scanner(System.in);
		while(in.hasNext())
		{
			char[] ch=in.next().toCharArray();
			for(int i=0;i<ch.length;i++)
			{
				if(ch[i]!='@')
					System.out.print(ch[i]);
				else if(ch[i++]=='@')
				{	
					int x=Integer.valueOf(ch[i++]+"");
					while(x-->0)
						System.out.print(ch[i]);
				}
			}
			System.out.println();
		}
	}

}

Measured memory_bytes: 11000
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  int r = 0;
  if(k<=a){
    r = k;
  }else if(k<=a+b){
    r = a;
  }else{
    r = a - (k-a-b);
  }
  cout << r << endl;
  return 0;
}

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

typedef long long ll;

const string YES = "Yes";
const string NO = "No";

void solve(std::string N){
  ll t = 0;
  for (char c : N) {
    t = (t+(c-'0')) % 9;
  }
  cout << ((t % 9 == 0) ? YES : NO) << endl;
}

int main() {
  std::string N;
  std::cin >> N;
  solve(N);
  return 0;
}


Measured memory_bytes: 3920
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
using namespace std;

int main() {
	int N,h[110],ans=0;
	cin >> N;
	h[0] = h[N + 1] = 0;
	for (int i = 1; i <= N; i++)cin >> h[i];
	int y=h[0];
	for (int i = 0; i <= N+1; i++) {
		if (h[i + 1] < h[i] && h[i - 1] < h[i])ans += h[i];
		if (h[i + 1] == h[i]) {
			y = i;
			while (h[i + 1] == h[i]) i++;
			if(h[y -1] < h[y]&& h[i + 1] < h[i])ans += h[i];
			if(h[y - 1] > h[y] && h[i + 1] > h[i])ans -= h[i];
		}
		if (h[i + 1] > h[i] && h[i - 1] > h[i])ans -= h[i];

	}
	cout << ans << endl;
}


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

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, P);
    CIN(int, Q);
    CIN(int, R);

    int ans;
    ans = min(P + Q, Q + R);
    ans = min(ans, R + P);

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define reg(i,a,b) for(int i=a;i<=b;i++)
#define reh(i,a,b) for(int i=a;i>b;i--)
#define in(x) scanf("%d",&x)
#define fro freopen("D:\\testdata.in", "r", stdin)
#define il inline
#define lson(q) q<<1
#define rson(q) q<<1|1
using namespace std;
typedef long long ll;
const int mx=1e5+10;


int main(){
	int a,n;
	cin>>a>>n;
	cout<<ceil(a*1.0/(n*2+1))<<endl; 
	
	
	return 0;
}




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

class Mondai
{
    struct Connection
    {
        public List<long[]> list;
        public Connection(int index)
        {
            list = new List<long[]>();
        }
    }
    static void Main()
    {
        var N = Int32.Parse(Console.ReadLine());
        var u = new int[N-1];
        var v = new int[N-1];
        var w = new long[N-1];
        for (int i = 0; i < N-1;++i)
        {
            var input = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray();
            u[i] = (int)input[0];
            v[i] = (int)input[1];
            w[i] = input[2];
        }
        var connection = new Connection[N];
        for (int i=0;i<N;++i) connection[i] = new Connection(i);
        for (int i=0;i<N-1;++i)
        {
            connection[u[i] - 1].list.Add(new long[] { v[i] - 1, w[i] });
            connection[v[i] - 1].list.Add(new long[] { u[i] - 1, w[i] });
        }
        //頂点からの距離
        var distance = new long[N];
        for (int i = 0; i < N; ++i) distance[i] = int.MaxValue;
        distance[0] = 0;
        //dfs
        var que = new Queue<long>();
        que.Enqueue(0);
        while (que.Any())
        {
            var vertex = que.Dequeue();
            for (int i=0;i<connection[vertex].list.Count;++i)
            {
                var target = connection[vertex].list[i][0];
                if (distance[target] == int.MaxValue)
                {
                    distance[target] = distance[vertex] + connection[vertex].list[i][1];
                    que.Enqueue(target);
                }
            }
        }
        for (int i=0;i<N;++i)
        {
            var output = distance[i] % 2;
            Console.Write(output);
            if (i != N - 1) Console.WriteLine();
        }
    }
}

Measured memory_bytes: 42312
import Control.Applicative
import Control.Monad
import Data.List

import Text.Parsec (parse, many1, digit, char)
import Text.Parsec.String

-- import Test.HUnit

main :: IO ()
-- main = runTestTT (TestList tests) >> return ()
main = do
  n <- readLn
  map solve <$> replicateM n (init <$> getLine) >>= mapM_ print

solve :: String -> Int
solve = either (const 0) id . parse expr ""

num :: Parser Int
num = read <$> many1 digit

fact :: Parser Int
fact = do
  sgn <- negate <$ char '-' <|> id <$ char '+' <|> return id
  sgn <$> (num <|> char '(' *> expr <* char ')')

term :: Parser Int
term = do
  f1 <- fact
  ops <- many $ do
    op <- flip (*) <$ char '*' <|> flip quot <$ char '/'
    op <$> fact
  return $ foldl' (flip ($)) f1 ops

expr :: Parser Int
expr = do
  t1 <- term
  ops <- many $ do
    op <- flip (+) <$ char '+' <|> flip (-) <$ char '-'
    op <$> term
  return $ foldl' (flip ($)) t1 ops
  
-- tests :: [Test]
-- tests = map f [
--   ("num1", parse num "" "00234", Right 234),
--   ("term1", parse term "" "23", Right 23),
--   ("term2", parse term "" "2*3", Right 6),
--   ("term3", parse term "" "7/3", Right 2),
--   ("term4", parse term "" "23*43/124", Right 7),
--   ("term5", parse term "" "352345/89/38", Right 104),
--   ("expr1", parse expr "" "345", Right 345),
--   ("expr2", parse expr "" "4*3*5/12", Right 5),
--   ("expr3", parse expr "" "2+3-1", Right 4),
--   ("expr4", parse expr "" "12-3+5", Right 14),
--   ("expr5", parse expr "" "2*3*3-12/3*2+5*8/2", Right 30),
--   ("fact1", parse fact "" "(3+5*2)", Right 13),
--   ("term6", parse term "" "(3+5*2)*(8-25/5)", Right 39),
--   ("expr6", parse expr "" "4-2*3", Right (-2)),
--   ("expr7", parse expr "" "4*(8+4+3)", Right 60),
--   ("expr8", parse expr "" "-3*-5+-60/5", Right 3),
--   ("fact2", parse fact "" "34", Right 34),
--   ("fact3", parse fact "" "+45", Right 45),
--   ("fact4", parse fact "" "-567", Right (-567)),
--   ("fact5", parse expr "" "(-99)/4", Right (-24)),
--   ("fact6", parse expr "" "-5++8*(23+4-2*3)-(-(35-2)*3)/4", Right 187)
--   ]
--   where 
--     f (ms, rv, ev) = ms ~: rv ~?= ev



Measured memory_bytes: 4452
#include<bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
const vector<vector<int>> dir4 = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
 
int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<bool>> hen(h + 2, vector<bool>(w + 2));
    for(int i = 1; i <= h; i++)for(int j = 1; j <= w; j++){
        char tmp; cin >> tmp; hen[i][j] = tmp == '.';
    }
    int res = 0;
 
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            for(int k = 1; k <= h; k++){
                for(int t = 1; t <= w; t++){
 
                    if(!hen[i][j] || !hen[k][t])continue;
                    vector<vector<int>> dist(h + 2, vector<int>(w + 2, -1));
                    queue<pair<int,int>> que;
                    dist[i][j] = 0;
 
 
                    que.push({i,j});
                    while(true) {
                        auto cur = que.front();
                        que.pop();
                        if(cur.first == k && cur.second == t){
                            res = max(res, dist[cur.first][cur.second]);
                            break;
                        }
 
                        for(int i = 0; i < 4; i++){
                            int y = cur.first + dir4[i][0], x = cur.second + dir4[i][1];
                            if(!hen[y][x] || dist[y][x] != -1)continue;
                            dist[y][x] = dist[cur.first][cur.second] + 1;
                            que.push({y,x});
                        }
                    }
 
                    
                }
            }
        }
    }
 
 
    cout << res << endl;
 
}

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

string S[1000];

struct Node
{
    ll x;
    ll y;
    ll cost;
    Node(ll x, ll y, ll c) : x(x), y(y), cost(c)
    {
    }
};

ll H, W, K;
ll x[4] = {1, 0, -1, 0};
ll y[4] = {0, 1, 0, -1};
ll M[805][805];

ll length(ll h, ll w)
{
    return std::min(std::min(h, H - 1 - h), std::min(w, W - 1 - w));
}

int main()
{
    cin >> H >> W >> K;
    REP(i, H)
    {
        cin >> S[i];
    }
    pll s;
    REP(i, H)
    {
        REP(j, W)
        {
            if (S[i][j] == 'S')
                s = pll(i, j);
            M[i][j] = INF;
        }
    }

    queue<Node> q;
    q.push(Node(s.first, s.second, 0));
    M[s.first][s.second] = 0;
    ll min = length(s.first, s.second);
    while (!q.empty())
    {
        auto t = q.front();
        q.pop();
        if (t.cost >= K)
            continue;
        REP(i, 4)
        {
            ll nx = t.x + x[i];
            ll ny = t.y + y[i];
            ll cost = t.cost + 1;
            if (nx < 0 || nx >= H || ny < 0 || ny >= W)
                continue;
            if (M[nx][ny] <= cost || S[nx][ny] == '#')
                continue;
            M[nx][ny] = cost;
            min = std::min(min, length(nx, ny));
            q.push(Node(nx, ny, cost));
        }
    }
    cout << (min + K - 1) / K + 1 << endl;
    return 0;
}

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

//#define li long int
#define INF 100000000
#define POW26 67108864

using namespace std;

int main() {
    vector < int > a(200001, 0), opt(200001, INF), dp(POW26, INF);
    int len;
    char c;

    //for (int i=0; i<POW26; i++) dp[i] = INF;
    //for (int i=0; i<200001; i++) opt[i] = INF;
    
    for (len=0; (c = getchar()) != '\n'; len++) {
        a[len+1] = a[len] ^ (1 << (c - 'a'));
        //cout << a[len] << endl;
    }
    
    opt[0] = 0;
    for (int i=1; i<=len; i++) {
        dp[a[i-1]] = min(dp[a[i-1]], opt[i-1]);

        opt[i] = dp[a[i]^0];
        for (int x = 1; x < POW26; x <<= 1) {
            opt[i] = min(opt[i], dp[a[i]^x]);
            //cout << (li)(a[i]^x) << ", " << dp[a[i]^x] << endl;
            //cout << i << ", " << dp[a[i]^x] << endl;
        }
        opt[i]++;
    }

    cout << opt[len] << endl;

    return 0;
}

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

using i64 = long long int;

struct Operation{
    int y, x, y_, x_;
};

vector<Operation> v;

int a[502][502]={0};

void add_operation(deque<pair<int, int>> &p){
    while(p.size() > 1){
        v.push_back((Operation){p[0].first, p[0].second, p[1].first, p[1].second});
        p.pop_front();
    }
    while(p.size() > 0)p.pop_front();
}

int main(){
    int h, w;
    cin >> h >> w;
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            cin >> a[i][j];
        }
    }

    bool flag = false;
    deque<pair<int, int>> p;
    for(int i=0;i<h;++i){
        if(i%2 == 0){
            for(int j=0;j<w;++j){
                if(flag)p.emplace_back(i, j);
                if(a[i][j]%2){
                    if(!flag){
                        p.emplace_back(i, j);
                        flag = true;
                    }else{
                        add_operation(p);
                        flag = false;
                    }
                }
            }
        }else{
            for(int j=w-1;j>=0;--j){
                if(flag)p.emplace_back(i, j);
                if(a[i][j]%2){
                    if(!flag){
                        p.emplace_back(i, j);
                        flag = true;
                    }else{
                        add_operation(p);
                        flag = false;
                    }
                }
            }
        }
    }

    cout << v.size() << endl;
    for(auto e : v){
        cout << e.y+1 << " " << e.x+1 << " " << e.y_+1 << " " << e.x_+1 << endl;
    }

    return 0;
}


Measured memory_bytes: 5232
#include<iostream>
#include<cstdio>
#define Abs(x) (x<0?-(x):(x))
#define FOR(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int N=5050,INF=1000010000;
int n,A,B,ca,cb,ans,a[N],b[N];
char s[N],t[N];
void work(int l,int r){
	if((ca^cb)!=(Abs(1-l)&1)) return;
	int ret=0;
	FOR(i,1,A){
		int x=i-l+1;
		if(x<1) ret+=a[i];
		if(x>B) ret+=n-a[i];
	}
	FOR(i,1,B){
		int x=i+l-1;
		if(x<1) ret+=b[i];
		else if(x>A) ret+=n-b[i];
		else ret+=Abs(b[i]-a[x]);
	}
	ans=min(ans,ret);
	//cout<<l<<' '<<r<<' '<<ans<<'\n';
}
int main(){
	//freopen("1.in","r",stdin);
	scanf("%d%s%s",&n,s+1,t+1);
	if(n<=2){
		cout<<(s[1]!=t[1])+(s[2]!=t[2])<<'\n';
		return 0;
	}
	FOR(i,2,n){
		if(s[i-1]!=s[i]) a[++A]=i-1;
		if(t[i-1]!=t[i]) b[++B]=i-1;
	}
	ca=s[a[1]]^48,cb=t[b[1]]^48;
	if(A>B) swap(A,B),swap(a,b);
	ans=INF;
	FOR(i,1-B,A+1) work(i,i+B-1);
	cout<<ans<<'\n';
}

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

int main() {
    ll n,r=0,g=0,b=0;
    string s;
    ll cnt1=0;
    cin >> n >> s;
    for (int i=0;i<n;i++) {
        if (s[i]=='R') r++;
        else if (s[i]=='G') g++;
        else if (s[i]=='B') b++;
    }
    cnt1=r*g*b;

    for (int i=0;i<n;i++) {
        for (int j=1;j<n;j++) {
            if (i+2*j>=n) {continue;}
            if (s[i]!=s[i+j] && s[i]!=s[i+j*2] && s[i+j]!=s[i+j*2])
                cnt1--;
        }
    }
    cout << cnt1;
}



Measured memory_bytes: 3516
import java.util.Scanner;
public class Main {
	static char[] s;
	static int id ;
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			for(int i=0; i<n; i++) {
				s = sc.next().toCharArray();
				id = 0;
				System.out.println(exp());
			}
			
		}
	}
	static int exp() {
		int res = term();
		while(s[id] == '+' || s[id] == '-') {
			if(s[id] == '+') {
				id++;
				res += term();
			}else {
				id++;
				res -= term();
			}
		}
		return res;
	}
	
	static int term() {
		int res = fact();
		while(s[id] == '*' || s[id] == '/') {
			if(s[id] == '*') {
				id++;
				res *= fact();
			}else{
				id++;
				res /= fact();
			}
		}
		
		return res;
	}
	
	static int fact() {
		int res = 0;
		if(s[id] == '(') {
			id++;
			res = exp();
			id++;
		}else if(s[id] == '+') {
			id++;
			res = fact();
		}else if(s[id] == '-') {
			id++;
			res = -fact(); 
		}else {
			res = num();
		}
		return res;
	}
	
	static int num() {
		int res = 0;
		if(Character.isDigit(s[id])) {
			while('0' <= s[id] && s[id] <= '9') {
				res *= 10;
				res += s[id] - '0';
				id++;
			}
		}
		
		return res;
	}
}






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

#define N 2000001

void change(int *, int);
void buildMaxHeap(int *, int);
void maxHeapify(int *, int);

int count = 0;

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

  int a[N];

  while(1) {
    char cmd[8];
    cin>>cmd;
    
    if(cmd[0] == 'i') {
      int x;
      cin>>x;
      count++;
      a[count] = x;
      change(a, count);
    } else if(cmd[1] == 'x') {
      cout<<a[1]<<endl;
      a[1] = a[count];
      count--;
      maxHeapify(a, 1);
    }else {
      break;
    }
  }

  return 0;
}

void change(int *a, int i) {
    int p = i % 2 == 0 ? i/2 : (i-1)/2;
    if(p >= 1 && a[i] > a[p]) {
        int tmp = a[i];
        a[i] = a[p];
        a[p] = tmp;
        change(a, p);
    }
}

void maxHeapify(int *a, int i) {

  int l = i*2;
  int r = i*2+1;

  int largest = i;
  if(l <= count && a[l] > a[largest])  largest = l;

  if(r <= count && a[r] > a[largest]) largest = r;

  if(largest != i) {
    int s = a[i];
    a[i] = a[largest];
    a[largest] = s;
    maxHeapify(a, largest);
  }
}



Measured memory_bytes: 7000
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <tuple>
using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}

template <class T>
T clampMax(const T& a, const T& b) { return min(a, b); }

template <class T>
T clampMin(const T& a, const T& b) { return max(a, b); }

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

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

#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

LL memo[410][410];
int visited[410][410];
LL a[410], b[410];

LL Get(int l, int r)
{
  LL res = b[r];
  if (l) res -= b[l - 1];
  return res;
}

LL Solve(int l, int r)
{
  if (l == r)
  {
    return 0;
  }

  if (visited[l][r])
  {
    return memo[l][r];
  }

  visited[l][r] = 1;

  LL ans = 1000000000000000010;
  for (int m = l; m < r; ++m)
  {
    ans = min(Solve(l, m) + Solve(m + 1, r) + Get(l, r), ans);
  }
  return memo[l][r] = ans;
}

int main()
{
  int N;
  cin >> N;
  REP(i, N) cin >> a[i];
  b[0] = a[0];
  REP(i, N - 1) b[i + 1] = b[i] + a[i + 1];
  cout << Solve(0, N - 1) << endl;
  return 0;
}

Measured memory_bytes: 2176
def f(a,b):
#a=7,5,3  b=0-7
#no=0, 3=1, 5=2, 7=4, all=7
    if a==7 and b>=4: return b
    if a==7 and b<4: return b+4
    if a==5 and b in (2,3,6,7): return b
    if a==5 and b not in (2,3,6,7): return b+2
    if a==3 and b in (1,3,5,7): return b
    if a==3 and b not in (1,3,5,7): return b+1

n=input()

#a,b=map(int, input().split())
#print(f(a,b))
l=[int(i) for i in "0"+n]
dp=[[[0]*9,[0]*9] for _ in "ww"]
dp[0][0][0]=1

chk=(7,5,3)
for i,j in enumerate(l):
    if i==0: continue
    elif i==1:
        if j in chk: dp[i%2][0][f(j,0)]=1
        if j not in chk: dp[i%2][0][0]=1
        if j>7: dp[i%2][1][4]+=1
        if j>5: dp[i%2][1][2]+=1
        if j>3: dp[i%2][1][1]+=1
        dp[i%2][1][0]=1
    else:
        dp[i%2][1][0]=1
        dp[i%2][1][4]+=1
        dp[i%2][1][2]+=1
        dp[i%2][1][1]+=1
        for k in range(8):
            if dp[i%2-1][0][k] and (k==0 or j not in chk): dp[i%2][0][0]=1
            elif dp[i%2-1][0][k] and j in chk: dp[i%2][0][f(j,k)]=1

            if dp[i%2-1][0][k] and k!=0:
                if j>7: dp[i%2][1][f(7,k)]+=1
                if j>5: dp[i%2][1][f(5,k)]+=1
                if j>3: dp[i%2][1][f(3,k)]+=1
            if dp[i%2-1][1][k] and k!=0:
                dp[i%2][1][f(7,k)]+=dp[i%2-1][1][k]
                dp[i%2][1][f(5,k)]+=dp[i%2-1][1][k]
                dp[i%2][1][f(3,k)]+=dp[i%2-1][1][k]
    for k in range(9):
        dp[i%2-1][0][k]=0
        dp[i%2-1][1][k]=0

print(dp[0][0][7]+dp[0][1][7]+dp[1][0][7]+dp[1][1][7])


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int INF=(1e9);
int n,m,tot,dis[450][450];
int num[30][30],ans;
char s[30][30];
int fx[4][2]={{-1,0},{0,-1},{1,0},{0,1}};
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(m);
	for (int i=1;i<=n;i++) scanf("%s",s[i]+1);
	for (int i=1;i<=n;i++)
	for (int j=1;j<=m;j++) num[i][j]=++tot;
	for (int i=1;i<=tot;i++)
	for (int j=1;j<=tot;j++) dis[i][j]=INF;
	for (int i=1;i<=tot;i++) dis[i][i]=0;
	for (int i=1;i<=n;i++)
	for (int j=1;j<=m;j++) {
		if (s[i][j]=='#') continue;
		for (int k=0;k<4;k++) {
			int x=i+fx[k][0],y=j+fx[k][1];
			if (x<1||y<1||x>n||y>m||s[x][y]=='#') continue;
			dis[num[i][j]][num[x][y]]=1;
		}
	}
	for (int k=1;k<=tot;k++)
	for (int i=1;i<=tot;i++)
	for (int j=1;j<=tot;j++)
		dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
	for (int i=1;i<=n;i++)
	for (int j=1;j<=m;j++)
	for (int x=1;x<=n;x++)
	for (int y=1;y<=m;y++)
		if (s[i][j]=='.'&&s[x][y]=='.') ans=max(ans,dis[num[i][j]][num[x][y]]);
	printf("%d\n",ans);
	return 0;
}
/*
  REMEMBER:
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Array size? Integer overflow? Time complexity? Memory usage? Precision error?
*/

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

typedef long long ll;
#define rep(i, s, n) for(int i=s;i<n;i++)
#define repeq(i,s,n) for(int i=s;i<=n;i++)
#define MOD 10e9+7

void max_self(int& a, int b) { a=a>b?a:b; }
void min_self(int& a, int b) { a=a<b?a:b; }

using namespace std;

int n, k;

int main() {


    cin >> n;

    cout << (3*n*n) << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> wa(N);
    vector<bool> ac(N);
    rep(i, M) {
        int p;
        string S;
        cin >> p >> S;
        if (ac[p - 1]) continue;
        if (S == "AC") ac[p - 1] = true;
        else wa[p - 1]++;
    }

    int pen = 0, ok = 0;
    rep(i, N) {
        if (ac[i]) {
            pen += wa[i];
            ok++;
        }
    }

    cout << ok << ' ' << pen << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,M,votes=0,ans=0;
    double minimum;
    cin>>N>>M;
        int items[N];
   for(int i=0;i<N;i++)
    {
        cin>>items[i];
        votes+=items[i];
    }
    minimum=votes*0.25*(1.0/M);
    //cout<<minimum<<endl<<votes;
    for(int i=0;i<N;i++)
    {
        if(items[i]>=minimum)
            ans++;
        if(ans==M)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
     cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define ms(a,v) memset(a,v,sizeof(a))
#define mp make_pair
#define write(x) cout<<(x)<<endl
using namespace std; typedef long long ll; typedef vector<int> vi;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; }return 0; }
const int INF = 1 << 28; const ll LINF = 1ll << 60;
const int MAX = 1e5 + 5; const int MOD = 1e9 + 7; const double EPS = 1e-6;
const int dy[4] = { 0,1,0,-1 }; const int dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

struct UnionFind {
    vector<int> parent;
    vector<int> rank;

    UnionFind() {}
    UnionFind(const int size) {
        parent.reserve(size);
        for (int i = 0; i < size; ++i) parent.emplace_back(i);
        rank.resize(size, 0);
    }

    int operator[](const int x) {
        return parent[x];
    }

    // 短絡効果付き
    int find(const int x) {
        if (parent[x] == x) return x;
        else return parent[x] = find(parent[x]);
    }

    bool same(const int x, const int y) {
        return find(x) == find(y);
    }

    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        else if (rank[x] < rank[y]) parent[x] = y;
        else {
            parent[y] = x;
            if (rank[x] == rank[y]) ++rank[x];
        }
        return true;
    }
};

ll N, M;
vi A, B;

int main() {
    cin >> N >> M;
    A.resize(M); B.resize(M);
    rep(i, M) {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }

    //reverse(all(A)); reverse(all(B));
    vector<ll> inconv(M);
    inconv[M - 1] = N * (N - 1) / 2;

    UnionFind uf(N);
    vi size(N, 1);

    for (int i = M - 1; i >= 1; --i) {
        int pa = uf.find(A[i]);
        int pb = uf.find(B[i]);

        ll sizea = size[pa];
        ll sizeb = size[pb];

        if (pa != pb) {
            inconv[i - 1] = inconv[i] - sizea * sizeb;
            uf.unite(pa, pb);
            size[pa] = size[pb] = sizea + sizeb;
        }
        else {
            inconv[i - 1] = inconv[i];
        }
    }

    rep(i, M) write(inconv[i]);
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
//#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}


inline void solve(){

    int n,l;

    cin >> n >> l;

    int sum=0,a[1000];
    int b;
    int amini = INF;
    FOR(i,n){
        a[i] = i+l;
        sum += a[i];
    }
    
    FOR(i,n){
        int tmp = sum - a[i];
        if(amini > abs(sum-tmp)){
            
            amini=abs(sum-tmp);
            b = i;
        }
    }
    
    cout << sum - a[b] fin;
    
}
struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;signed main(){solve();return 0;}


Measured memory_bytes: 256
N = int(input())
Alst = list(map(int, input().split()))
ans = 1
rec = True
if 0 in Alst:
    print(0)

else:
    for i in range(N):
        ans = ans * Alst[i]
        if ans > 10**18:
            rec = False
            break

    if rec:
        print(ans)
    else:
        print(-1)

Measured memory_bytes: 21672
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.Sumitrust_2019
{
    class E
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] array = ReadInts();
            long mask = 1000000000 + 7;
            long res = 1;
            int[] rgb = new int[3] { 0, 0, 0 };
            for(int i = 0; i < n; i++)
            {
                int first = -1;
                int cnt = 0;
                for(int j = 0; j < 3; j++)
                {
                    if (rgb[j] == array[i])
                    {
                        cnt++;
                        if (first == -1) first = j;
                    }
                }
                if (first == -1)
                {
                    WriteLine(0);
                    return;
                }
                rgb[first]++;
                res *= cnt;
                res %= mask;
            }
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 18656
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,d,e,f;
    cin>>a>>b>>c>>d;
    e=a*b;
    f=c*d;

    if(e>f){
        cout<<e<<endl;
    }else{
        cout<<f<<endl;

    }


    return 0;
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	string s;
	cin >> s;
	string hitachi = "hihihihihi";
	if(s.size() % 2 == 1)
	{
		cout << "No" << endl;
		return 0;
	}
	rep(i, s.size())
	{
		if(s[i] != hitachi[i])
		{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 int N;
 int K;
 cin >> N >> K;
 if(K>=N)cout << 0 << endl;
 else{
 int a[N];
 int i;
 long long int sum =0;
 for(i=0;i<N;++i){
   cin >> a[i];
   sum += a[i];
   }
 sort(a,a+N);
 for(i=0;i<K;i++)sum -= a[N-1-i];
 cout << sum << endl;
 }
 }

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define MOD 987654319 
#define INF 1000000000000000000
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		if(n % i == 0)
		{
			if(i <= 9 && n / i <= 9)
			{
				cout << "Yes";
				return 0;
			}
		}
	}
	cout << "No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define in_range(x, y, r, c) (x <= r && y <= c && x >= 0 && y >= 0)
#define MAXN 200100
#define ff first
#define ss second
using namespace std;
const int mod = 1e9+7;

int main(){
	int n, k, d[10] = {}, aux;
	cin >> n >> k;

	for (int i=0; i<k; i++ ){
		cin >> aux;
		d[aux] = 1;
	}
	for (int ans = n; ans <= n*100; ans++){
		bool check = true;
		int temp = ans;
	
		while (temp){
			if (d[temp%10]){
				check = false;
				break;
			}
			temp/= 10;
		}
		if (check){
			cout << ans << endl;
			break;
		}
	}
    return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
H=list(map(int,input().split()))
C=[0]*n
for i in range(1,n):
  c=C[i-1]+abs(H[i]-H[i-1])
  for j in range(2,min(k,i)+1):
    d=C[i-j]+abs(H[i]-H[i-j])
    if d<c:
      c=d
  C[i]=c
print(C[-1])

Measured memory_bytes: 52448
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        cs: String
    }
    let is: Vec<u32> = cs.chars().map(|c| c.to_digit(10).unwrap()).collect();

    // 1 << d := pow(2, d)
    let mut ret = 0_u64;
    for i in 0..1 << is.len() - 1 {
        let mut now = 0;
        for j in 0..is.len() {
            // iのj番目ビットが立っているか -> jがiに含まれるか
            if 1 << j & i == 0 {
                let mut vs = Vec::new();
                for k in now..j + 1 {
                    vs.push(is[k]);
                }
                let mut d = 1u64;
                let mut sum = 0u64;
                // for v in vs {
                loop {
                    if let Some(v) = vs.pop() {
                        sum += v as u64 * d;
                    } else {
                        break;
                    }
                    d *= 10;
                }
                now = j + 1;
                ret += sum;
            }
        }
    }
    println!("{}", ret);
}

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

using namespace std;

int main(){
    string s;
    cin >> s;
    int n,count=0;

    n=s.length()/2;

    for(int i=0;i<n;i++){
        if(s[i] != s[s.length()-i-1]){
            count++;
        }
    }
    cout << count <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, k;
string s;

int main(){
	cin >> n >> k >> s;
	
	ll cnt = 0;
	ll ans = 0;
	for(ll i = 0; i < n-1; i++){
		if(s[i] != s[i+1]){
			cnt++;
		}
		else{
			ans++;
		}
	}
	
	if(cnt/2 >= k){
		ans += 2*k;
	}
	else{
		ans = n-1;
	}
	
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) (long long)((a).size())
const double pi = 3.14159265358979323846;

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    ll i,j;
    vector<ll> a(5);
    for(i=0;i<5;i++) cin>>a[i];
    for(i=0;i<5;i++)
    {
        if(a[i]==0) {cout<<i+1;return 0;}
    }
}

Measured memory_bytes: 3584
def main(argv)
  (n, a, b) = gets.chomp.split(' ').map(&:to_i)

  if (b - a).even? then
    puts 'Alice'
  else # (b - a).odd?
    puts 'Borys'
  end
end

if self.to_s == 'main' then
  main(ARGV)
end

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

int n, w;
ll dp[102][100100];
ll val[110], wt[110];

int main() {
    cin >> n >> w;
    for (int i = 1; i <= n; ++i) cin >> wt[i] >> val[i];


    for (int pos = 1; pos <= n; ++pos) {
        for (int weight = 0; weight <= w; ++weight) {
            if ( weight == 0 ) {
                dp[pos][weight] = 0;
                continue;
            }
            dp[pos][weight] = dp[pos - 1][weight];
            if ( weight - wt[pos] >= 0 ) 
                dp[pos][weight] = max(dp[pos][weight], dp[pos - 1][weight - wt[pos]] + val[pos]);
        }
    }


    cout << dp[n][w] << endl;
    return 0;
}


Measured memory_bytes: 78464
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
typedef pair <int, int> P;

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

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

    vector <P> vec(n);
    for (int i = 0; i < n; i++) cin >> vec[i].first >> vec[i].second;

    sort(vec.begin(), vec.end());

    priority_queue<int> q;
    int index = 0;
    int ans = 0;

    for (int day = m - 1; day >= 0; day--) {
        while (index < n && vec[index].first + day <= m) {
            q.push(vec[index].second);
            index++;
        }

        if (!q.empty()) {
            ans += q.top();
            q.pop();
        }
    }

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

Measured memory_bytes: 1660
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){	
	int n,m;
	while(cin >> n >> m , n || m){ 
		int o_O[100] = {0};
		rep(i,n){
			rep(j,m){
				int t;
				cin >> t;
				o_O[j] += t;
			}
		}
		vector<int> srt[1001] ,ans;
		rep(i,m)srt[o_O[i]].push_back(i+1);
		rep(i,1001)ans.insert(ans.end(),srt[1000-i].begin(),srt[1000-i].end());
		rep(i,m)cout << ans[i] << (i==m-1?"\n":" "); 
	}
}

Measured memory_bytes: 912
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

bool a[100005];
int p[100005];

signed main() {
	int n, m;
	cin >> n >> m;
	rep(i, m) {
		int now;
		string s;
		cin >> now >> s;
		now--;
		if (s == "AC") {
			a[now] = true;
		}
		else {
			if (!a[now]) p[now]++;
		}
	}
	int x = 0, y = 0;
	rep(i, n) {
		if (a[i]) {
			x++;
			y += p[i];
		}
	}
	cout << x << " " << y << endl;

	return 0;
}


Measured memory_bytes: 1152
// https://atcoder.jp/contests/abc179/tasks/abc179_a

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

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    if (s[n - 1] == 's')
    {
        s += "es";
    }
    else
    {
        s += "s";
    }
    cout << s << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

ll n;
char c[3] = {'3','5','7'};

int fun(string str, int done){
  ll number = stoll(str);
  if(number<=n){
    ll t = 0;
    if(done==7) t++;
    for(int i=0;i<3;++i){
      string temp = str; temp.push_back(c[i]);
      t += fun(temp, done | (1<<i));
    }
    return t;
  }else return 0;
}

main(){
  cin >> n;
  ll ans = fun("3",1);
  ans += fun("7",4);
  ans += fun("5",2);
  cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
S = [0 for _ in range(N)]
SUM = 0
for n in range(N):
    next = int(input())
    SUM += next
    S.append(next)

if SUM % 10 != 0:
    print(SUM)
    exit()

S.sort()
for s in S:
    if s % 10 != 0:
        print(SUM-s)
        exit()

print(0)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

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

	int ans = 1005;
	rep(i, n) {
		int c, time;
		cin >> c >> time;
		if (time <= t) ans = min(ans, c);
	}
	if (ans < 1005) cout << ans << endl;
	else cout << "TLE" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define scf(n) scanf("%lld",&n)
#define rep1(n) for(int i=1;i<=n;i++)
#define prf(n) printf("%lld",n)
#define sci(n) scanf("%lld",&n)
#define pri(n) printf("%lld",n)

#define nl printf("\n")
#define spc printf(" ")
#define file freopen("in.txt","rt",stdin)
#define pii pair<int,int>
#define piii pair<pii,int>
#define MOD 10000007
using namespace std;

/*bool sortBySec(const pair<int,int> &a,const pair<int,int> &b)
{
    return (a.second < b.second);
}*/
void faster(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
/******************************************/

/***********************************/




int32_t main()
{


    /***********************************/
//#ifdef ONPC
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
//#endif
//    //faster();

    /*********************************/
    int n,m;
    sci(n);
    sci(m);

    int ans = abs(n-m-1);
    if(ans&1)
    {
        cout<<(n+m)/2<<endl;
    }
    else
        printf("IMPOSSIBLE\n");




    return 0;
}



Measured memory_bytes: 256
import java.util.*;

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

    String[] s = new String[1];
    s[0] = sc.next();
    s[0] = "1" + s[0];

    String[] a = {"dream", "dreamer", "erase", "eraser"};

    s[0] = rep(s, a[3]);
    s[0] = rep(s, a[2]);
    s[0] = rep(s, a[1]);
    s[0] = rep(s, a[0]);

    System.out.println(s[0].equals("1") ? "YES" : "NO");

  }

  public static String rep (String[] s, String a) {
    boolean ok = true;
    while (ok) {
      int n = s[0].indexOf(a);
      if (n == -1) {
        ok = false;
      } else {
        s[0] = s[0].replaceAll(a, "");
      }
    }
    return s[0];
  }
  
}

Measured memory_bytes: 28772
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    ll n;
    cin >> n;

    for(ll i = 1; i <= n; i++){
        ll cnt = 0;
        for(ll j = 1; j * j <= i; j++){
            for(ll k = 1; k * k <= i; k++){
                ld rest = pow(j, 2) + pow(k, 2) + j * k - i;
                ld b = j + k;
                if(pow(b, 2) - 4 * rest < 0) continue;
                ld x1 =  (-b + sqrt(pow(b, 2) - 4 * rest)) / 2.0;
                ld x2 = (-b - sqrt(pow(b, 2) - 4 * rest)) / 2.0;
                //cout << "x" << x1 << " " << x2 << endl;
                if((x1 > 0 && floor(x1) == ceil(x1)) || (x2 > 0 && x2 != 0 && floor(x2) == ceil(x2))){
                    cnt++;
                }


            }
        }
        cout << cnt << endl;

    }
}


Measured memory_bytes: 3564
#include <bits/stdc++.h> 
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std; 

struct act
{
    ll a,b,c;
};

int main()
{
    fast_io;

    ll n;
    cin>>n;
    vector<act> v(n+1);

    for(ll i=1;i<=n;i++)
    {
        cin>>v[i].a;
        cin>>v[i].b;
        cin>>v[i].c;
    }

    ll dp[n+1][3];
    //Base case
    dp[1][0] = v[1].a;
    dp[1][1] = v[1].b;
    dp[1][2] = v[1].c;

    //BU
    for(ll i=2;i<=n;i++)
    {
        dp[i][0] = v[i].a + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = v[i].b + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = v[i].c + max(dp[i-1][0], dp[i-1][1]);
    }

    cout<< max(dp[n][0], max(dp[n][1], dp[n][2])) <<endl;
    return 0;
}


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

int dp[21][11][156] = {0};

int main(){
    int n,k,s;
    for(int i=1;i<21;++i)
            dp[i][1][i] = 1;
    for(int i=1;i<21;++i){
        for(int j=1;j<11;++j){
            for(int l=1;l<156;++l){
                dp[i][j][l] += dp[i-1][j][l];
                if(l - i > 0)
                    dp[i][j][l] += dp[i-1][j-1][l-i];
            }
        }
    }
    while(scanf("%d %d %d",&n,&k,&s), n != 0 || k != 0 || s != 0){
        printf("%d\n",dp[n][k][s]);
    }

    return 0;
}


Measured memory_bytes: 3320