akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>

using namespace std;

constexpr int INF = 1000000000;/* 1e+9a */
constexpr int MODULO = 1000000007;

typedef int64_t ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while(cin >> n){
        if(n == 0)
            break;
        stack<char> op;
        map<int, stack<int>> num;
        int cd = 0;
        int ans = 0;
        char ch;
        for (int i = 0; i < n; ++i) {
            int d = 0;
            while(cin >> ch){
                if(ch != '.') break;
                else d++;
            }

            while(cd > d){
                char opc = op.top();
                op.pop();
                function<int(int, int)> operato = multiplies<int>();
                int res = 1;
                if(opc == '+') {
                    operato = plus<int>();
                    res = 0;
                }
                auto&& cdstack = num[cd];
                while(!cdstack.empty()){
                    res = operato(res, cdstack.top());
                    cdstack.pop();
                }
                cd--;
                num[cd].push(res);
//                cerr << cd << ": " << res << '\n';
            }

            if(ch == '+') op.push('+'), cd++;
            else if(ch == '*') op.push('*'), cd++;
            else num[d].push(ch - '0');
        }
        while(cd > 0){
            char opc = op.top();
            op.pop();
            function<int(int, int)> operato = multiplies<int>();
            int res = 1;
            if(opc == '+') {
                operato = plus<int>();
                res = 0;
            }
            auto&& cdstack = num[cd];
            while(!cdstack.empty()){
                res = operato(res, cdstack.top());
                cdstack.pop();
            }
            cd--;
            num[cd].push(res);
//            cerr << cd << ": " << res << '\n';
        }
        cout << num[0].top() << endl;
        num[0].pop();

    }
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const int INF = 100100100;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl

int main(){
  int N; cin >> N;
  vector<int> A(N); REP(i, N) cin >> A[i];
  vector<int> ANS(N);
  REP(i, N) ANS[A[i]-1] = i + 1; 
  REP(i, N) cout << ANS[i] << " ";
  cout << endl;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int len = s.length();
	int i =0,mid,count=0;
	if(len%2!=0)
		mid = len/2 + 1;
	else
		mid = len/2;
	
    for(int i=0;i<=mid;i++)
    {
    	if(s[i]!=s[len-i-1])
    	{
    		s[len-i-1] = s[i];
    		count++;
    	}

    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#!python3.4
# -*- coding: utf-8 -*-
# abc159/abc159_a
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, M = i2nn()
    n = N * (N - 1) // 2 if N > 1 else 0
    m = M * (M - 1) // 2 if M > 1 else 0
    print(n + m)
    return

main()


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };


int main() {
	int n = 0;
	string s;
	cin >> s;
	REP(i, 4) {
		if (s[i] == '+')n++;
		if (s[i] == '-')n--;
	}
	cout << n << endl;
}


Measured memory_bytes: 768
def f():
 global d
 p=[]
 for i in range(len(d)-1):
  a,b=d[i],d[i+1]
  r=(b-a)/3
  p+=[a,a+r,a+r+r*(1+3**.5*1j)/2,b-r]
 d=p+[d[-1]]
d=[0j,100+0j]
for _ in[0]*int(input()):f()
for e in d:print(e.real,e.imag)


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

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

    int i = 1;
    while(1) {
        if(N < i*i) {
            break;
        }
        i++;
    }

    int ans = (i-1)*(i-1);

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

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;
typedef pair<double,int> P;
double x[1010],y[1010],r[1010];
double D(int a,int b){
	double cnt=(x[a]-x[b])*(x[a]-x[b]);
	cnt+=(y[a]-y[b])*(y[a]-y[b]);
	cnt=(double)sqrt((double)cnt);
	return max(0.0,cnt-r[a]-r[b]);
}
int main(){
int n;
bool vis[1010];
priority_queue<P,vector<P>,greater<P> >Q;
	cin>>x[0]>>y[0]>>x[1]>>y[1]>>n;
	for(int i=2;i<n+2;i++)cin>>x[i]>>y[i]>>r[i];
	for(int i=0;i<=n+1;i++)vis[i]=false;
	Q.push(make_pair(0.0,0));
	while(!Q.empty()){
		double a=Q.top().first;int b=Q.top().second;
		Q.pop();
		if(!vis[b]){
			if(b==1){
				cout<<fixed<<setprecision(10)<<a<<endl;
			}
			vis[b]=true;
			for(int i=0;i<n+2;i++){
				if(vis[i]==false){
					Q.push(make_pair(a+D(i,b),i));
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 10604
#include<bits/stdc++.h>
using namespace std ;
#define Next( i, x ) for( register int i = head[x]; i; i = e[i].next )
#define rep( i, s, t ) for( register int i = (s); i <= (t); ++ i )
#define drep( i, s, t ) for( register int i = (t); i >= (s); -- i )
#define re register
#define int long long
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int N = 1e5 + 5 ; 
int n, A[N] ;  
bool check( int x ) {
	int u = A[x] ; 
	for( re int i = 1; i <= n; ++ i ) {
		if( x == i ) continue ; 
		if( u * 2 < A[i] ) return 0 ;
		u += A[i] ; 
	}
	return 1 ; 
} 
signed main()
{
	n = gi() ; 
	rep( i, 1, n ) A[i] = gi() ; 
	sort( A + 1, A + n + 1 ) ; 
	int l = 1, r = n, ans = n ;
	while( l <= r ) {
		int mid = ( l + r ) >> 1 ; 
		if( check(mid) ) r = mid - 1, ans = mid ; 
		else l = mid + 1 ; 
	} 
	printf("%lld\n", ( n - ans + 1 ) ) ; 
	return 0 ;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
// clang-format on

string S, T;

int main(void)
{
  cin >> S >> T;
  map<int, int> ms, mt;
  int n = S.size();

  set<char> st;
  REP(i, n) ms[S[i]]++, mt[T[i]]++, st.insert(S[i]), st.insert(T[i]);

  priority_queue<int> qs, qt;

  for (auto m : ms) qs.push(m.second);
  for (auto m : mt) qt.push(m.second);

  while (!qs.empty()) {
    int ss = qs.top();
    qs.pop();
    int tt = qt.top();
    qt.pop();
    if (ss != tt) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 1020
#include<cstdio>
#include<vector>
using namespace std;
int main(){
	int n;
	vector<int> G;
	scanf("%d",&n);
	if(n == 1){
		printf("%d: %d\n",n,n);
		return 0;
	}
	int a = n;
	for(int i = 2; i * i <= n; i++){
		while(a%i == 0){
			G.push_back(i);
			a /= i;
		}
	}
	if(a != 1)G.push_back(a);
	printf("%d:",n);
	for(int i = 0; i < G.size(); i++){
		printf(" %d",G[i]);
	}
	puts("");
	return 0;
}

Measured memory_bytes: 1060
import java.util.*;

class Main
{
    private static Scanner scan = new Scanner(System.in);

    public static void out(boolean flag)
    {
        if (flag)
        {
            System.out.println("Yay!");
        }
        else
        {
            System.out.println(":(");
        }
    }

    public static void main(String[] args)
    {
        int a = scan.nextInt();
        int b = scan.nextInt();
        boolean flag = false;

        if (a < 9 && b < 9)
        {
            flag = true;
        }

        out(flag);
    }
}

Measured memory_bytes: 21716
n = int(input())
s = [str(input()) for i in range(n)]
t = [s[0]]
alpha = s[0][-1]
a = True
for i in range(n-1):
    if s[i+1] not in t and alpha == s[i+1][0]:
        t.append(s[i+1])
        alpha = s[i+1][-1]
    else:
        a = False
        break
 
if a:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using vi=vector<int>;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using ld = long double;
const ld eps = 1.0e-9; // 許容される誤差

ld mysqrtl(ld x)
{
  ld a = sqrt((double)x); // 近似値
  do {
    a = (a + x/a) / 2.0L;
  } while (fabsl(x - a*a) > eps);
  return a;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ld a,b,c;
    cin >> a >> b >> c;
    ld eps = 1.0E-14;
    if(sqrt(a)+sqrt(b)+eps<sqrt(c)){
        cout << "Yes" << "\n";
        return 0;
    }else{
        cout << "No" << "\n";
        return 0;
    }
}   

Measured memory_bytes: 3772
a, b, c, d = map(int, input().split())

ans = 0

if a < c:
    if b > c:
        if b < d:
            ans = b - c
        else:
            ans = d - c
else:
    if d > a:
        if d < b:
            ans = d - a
        else:
            ans = b - a

print(ans)

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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  int n, x, y;
  cin >> n >> x >> y;

  vector<vector<int>> dist(n + 5, vector<int> (n + 5, 0));
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      dist[i][j] = abs(i-j);


  dist[x][y] = dist[y][x] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      dist[i][j] = min(dist[i][j], dist[i][x] + dist[x][j]);
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      dist[i][j] = min(dist[i][j], dist[i][y] + dist[y][j]);
    }
  }

  vector<int> fre(1e4, 0);
  for (int i = 1; i <= n; ++i)
    for (int j = i+1; j <= n; ++j)
      fre[dist[i][j]]++;

  for (int i = 1; i < n; ++i)
    cout << fre[i] << '\n';
}

Measured memory_bytes: 16128
def read_input():
    a, b, c = map(int, input().split())

    return a, b, c



if __name__ == '__main__':
    a, b, c = read_input()

    start = min(a, b)
    end = max(a, b)

    if start < c < end:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 2940
import java.util.*;
import java.math.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		sc.nextLine();
		BigDecimal d;
		BigDecimal g=new BigDecimal("1000000000");
		int[][] c=new int[19][19];
		long a;
		int t;
		int f;
		for(int i=0;i<n;i++){
			t=0;
			f=0;
			d=new BigDecimal(sc.nextLine());
			d=d.multiply(g);
			a=d.longValue();
			//System.out.println(a);
			while(a%2==0){
				t++;
              	//System.out.println(a);
				a=a/2;
			}
			while(a%5==0){
				f++;
              	//System.out.println(a);
				a=a/5;
			}
			if(t>18){
				t=18;
			}
			if(f>18){
				f=18;
			}
          	//System.out.println(t);
          	//System.out.println(f);
			c[t][f]++;
		}
		long[][] s=new long[20][20];
		for(int i=18;i>=0;i--){
			for(int j=18;j>=0;j--){
				s[i][j]=s[i+1][j]+s[i][j+1]-s[i+1][j+1]+c[i][j];
			}
		}
		long ans=0;
      	for(int i=0;i<=18;i++){
			for(int j=0;j<=18;j++){
				ans+=c[i][j]*s[18-i][18-j];
			}
		}
      	//System.out.println(ans);
      	ans-=s[9][9];
		ans=ans/2;
      	System.out.println(ans);
	}
}

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

using namespace std;

int main(){
  int h,w,x,y; cin>>h>>w>>x>>y;
  if(h*w%2==1&&(x+y)%2==1) cout <<"No";
  else cout <<"Yes";
  cout <<endl;
  
  
  return 0;
} 



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

int main() {
    ll n; cin >> n;
    vector<ll> a(n); REP(i, n) cin >> a[i];
    sort(a.begin(), a.end());

    ll ans = 1;

    if (a[0] == 0)
        ans = 0;
    else {
        REP(i, n) ans *= a[i];
        ll tmp = ans;
      	REP(i, n) tmp /= a[i];
        if (tmp != 1 || ans > (ll)1e18) ans = -1;
    }
  

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4000
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D, L, R;
  cin >> A >> B >> C >> D;
  L = A + B;
  R = C + D;

  if (L > R){
      cout << "Left" << endl;
  }
  else if (L < R){
      cout << "Right" << endl;
  } 
  else if (L == R){
      cout << "Balanced" << endl;
  } 
}

Measured memory_bytes: 256
from collections import deque

def main():
  n, m = map(int, input().split())
  ab = (map(int, input().split()) for i in range(m))
  
  ggg = [[] for i in range(n+1)]
  ff = [0] * (n+1)
  
  for a, b in ab:
    ggg[a].append(b)
    ggg[b].append(a)
    
  qq = deque()
  qq.append(1)
  ff[1] = 1
  
  while qq:
    a = qq.popleft()
    for b in ggg[a]:
      if not ff[b]:
        ff[b] = a
        qq.append(b)
  
  rr = ff[2:]
  y = all(rr)
  
  print('Yes' if y else 'No')
  if y:
    for r in rr:
      print(r)

if __name__ == '__main__':
  main()


Measured memory_bytes: 94536
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

    int K, X;
    cin >> K >> X;
    cout << ((500 * K >= X)?"Yes":"No") << endl;

    return 0;
}


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

void b_Papers_Please(const std::vector<int>& A_list)
{
    for (const auto& a : A_list)
    {
        if (a % 2 != 0)
            continue;

        if (a % 3 == 0)
            continue;

        if (a % 5 == 0)
            continue;

        std::cout << "DENIED";
        return;
    }
    std::cout << "APPROVED";
}


int main(int, char* [])
{
    int N;
    std::cin >> N;

    std::vector<int> A_list(N);
    for (int i = 0; i < N; ++i)
        std::cin >> A_list[i];

    b_Papers_Please(A_list);

    return 0;
}


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

int main()
{
    int N;
    cin >> N;
    int P[N];
    for (int i=0; i<N; ++i) cin >> P[i];

    int max = 0;
    int idx = 0;
    for (int i=1; i<N; ++i)
    {
        if (P[i] > max)
        {
            max = P[i];
            idx = i;
        }
    }

    int sum = 0;
    for (int i=0; i<N; ++i)
    {
        sum += i == idx ? P[i]/2 : P[i];
    }

    cout << sum << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <string.h>
#define rep(i,n) for (int i=0; i<n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>; 
 
ll a,b,c,d;
 
int main(){
  cin>>a>>b>>c>>d;
  ll m = a*c;
  m = max(m,a*d);
  m = max(m,b*c);
  m = max(m,b*d);
  cout<<m;
  return 0;
}

Measured memory_bytes: 3636
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;
int  main(){
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif
	ll a,b;
	cin>>a>>b;
	if(b==1){
		cout<<0<<endl;
		return 0;
	}
	int c=a,count=1;
	while(c<b){
		count++;
		c+=a-1;
	}
	cout<<count<<endl;
}

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

using namespace std;

const int maxn = 200010;
const int mod = 1e9+7;
const int inf = 0x7fffffff;

typedef long long ll;

/*
 边应该分为两类：
 第一类：同色。考虑与最小w连边。
 第二类：异色。
 考虑两种交换
 
 */

int n = 0, x, y;

int jc[maxn], inv[maxn], ijc[maxn];
int c[maxn], w[maxn], cnt[maxn];
vector<int> vec[maxn];
int fa[maxn];
int mn_c[maxn], mn_i[maxn];
int zx, cx;

int getroot(int x) {
    return (fa[x] == x) ? x : (fa[x] = getroot(fa[x]));
}

void Union(int x, int y) {
    int rx = getroot(x), ry = getroot(y);
    if (rx == ry) return;
    fa[rx] = ry;
}

int main() {
    scanf("%d%d%d", &n, &x, &y);
    for (int i = 1; i <= n; i++) fa[i] = i;
    jc[0] = ijc[0] = 1;
    for (int i = 1; i <= n; i++) {
        mn_c[i] = inf;
        jc[i] = 1ll*jc[i-1]*i%mod;
        if (i > 1) {
            inv[i] = mod-1ll*(mod/i)*inv[mod%i]%mod;
            ijc[i] = 1ll*ijc[i-1]*inv[i]%mod;
        } else inv[1] = ijc[1] = 1;
    }
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &c[i], &w[i]);
        if (w[i] < mn_c[c[i]]) {
            mn_c[c[i]] = w[i];
            mn_i[c[i]] = i;
        }
    }
    mn_c[0] = inf;
    for (int i = 1; i <= n; i++) {
        if (mn_c[i] <= mn_c[zx]) {
            cx = zx;
            zx = i;
        } else if (mn_c[i] < mn_c[cx])
            cx = i;
    }
    for (int i = 1; i <= n; i++) {
        int t = c[i];
        if (mn_c[t]+w[i] <= x) Union(i, mn_i[t]);
        if (t == zx) {
            if (cx) {
                if (mn_c[cx]+w[i] <= y) Union(i, mn_i[cx]);
            }
        } else {
            if (mn_c[zx]+w[i] <= y) Union(i, mn_i[zx]);
        }
    }
    int ans = 1;
    for (int i = 1; i <= n; i++) vec[getroot(i)].push_back(i);
    for (int i = 1; i <= n; i++) {
        int tot = (int)vec[i].size();
        int tmp = jc[tot];
        for (int j = 0; j < vec[i].size(); j++) cnt[c[vec[i][j]]] ++;
        for (int j = int(vec[i].size())-1; j >= 0; j--) {
            if (cnt[c[vec[i][j]]]) {
                tmp = 1ll*tmp*ijc[cnt[c[vec[i][j]]]]%mod;
            }
            cnt[c[vec[i][j]]] = 0;
        }
        ans = 1ll*ans*tmp%mod;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 17792
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int F =0;
  string color,result;
  for(int i=0;i<N;i++){
    cin >> color;
    if (color == "Y"){
      F =1;
    }
  }
  if (F==0){
    result ="Three";
  }
  else{
    result ="Four";
  }
 cout << result << endl;
}


Measured memory_bytes: 256
# Aizu Problem 0103: Baseball Simulation
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


N = int(input())
for n in range(N):
    bases = [0, 0, 0]
    outs = 0
    score = 0
    while outs < 3:
        event = input().strip()
        if event == "OUT":
            outs += 1
        elif event == "HOMERUN":
            score += 1 + sum(bases)
            bases = [0, 0, 0]
        elif event == "HIT":
            score += bases[2]
            bases[1:] = bases[:2]
            bases[0] = 1
    print(score)

Measured memory_bytes: 7632
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;

int main(){
  int N;
  cin >> N;
  vector<ll> a(N);
  int N_0=0,N_2=0,N_4=0;
  for(int i=0; i<N; i++){
    cin >> a[i];
    if(a[i]%4 == 0){
      N_4++;
    }else if(a[i]%2 == 0){
      N_2++;
    }else{
      N_0++;
    }
  }
  if(N_0 == 0){
    cout << "Yes" << endl;
    return 0;
  }
  if(N_2 == 0){
    if(N_0 <= N_4+1){
      cout << "Yes" << endl;
      return 0;
    }
  }else{
    if(N_0 <= N_4){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 1024
n =int(input())
ab = []

for i in range(n):
    a,b = map(int,input().split())
    ab.append([b,a])
ab.sort()
time = 0
ok = True
for i in range(n):
    a = ab[i][1]
    b = ab[i][0]
    if time + a > b:
        ok = False
        break
    time +=a
if ok :print('Yes')
else:print('No')
        
    

Measured memory_bytes: 76540
// Author: Amey Bhavsar
// IDE: Geany/Ubuntu
// Platform: MarathonForces #1

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

typedef long long ll;

#define rep(i,a,b) for(auto i=a;i<b;i++)
#define repD(i,a,b) for(auto i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

// to be used with algorithms that processes a container Eg: find(all(c),42)
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal
// traversal function to avoid long template definition
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)
//find version works for all containers. This is present in std namespace.
#define cpresent(c,x) (find(all(c),x) != (c).end())
// ll fe (ll x, ll y) {
	// ll ans = 1;
	// while (y>0) {
		// if (y&1) {
			// ans = (x*ans) % MOD;
		// }
		// y /= 2;
		// x = (x*x) % MOD;
	// }
	// return (ans % MOD);
// }

// ll modmul(ll a, ll b) {
    // return ((a%MOD) * (b%MOD)) % MOD;
// }

// ll modadd(ll a , ll b){
    // return((a%MOD)+(b%MOD)+MOD)%MOD;
// }

// ll modsub(ll a , ll b){
    // return((a%MOD) - (b%MOD) + MOD)%MOD;
// }
#define MOD 1000000007


int main() {
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	int a,b;
	cin >> a >> b;
	cout << (a<b ? "0" : "10");
	return 0;
}


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

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

  for (int i=a;i<=b;i++){
    if (c%i==0){
      t++;
    }
  }
  cout<<t<<endl;
  return 0;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
int main ()
{
	int i,c=0;
	string s;
	string t;
	cin>>s;
	cin>>t;
	for(i=0;i<s.size();i++)
	{
		if(s[i]==t[i])
		{
			c++;
		}
	}
	if((t.size() - s.size())==1 && c==s.size() )
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 3564
#include<stdio.h>

int A[100000];

int par(int *A,int p,int r){
  int x,i,j,tmp;
  x = A[r];
  i = p-1;
  for(j=p;j<=r-1;j++){
    if(A[j]<=x){
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  tmp = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp;

  return i+1;
}

int main(){
  int i,n,key;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  key = par(A,0,n-1);
  for(i=0;i<key;i++)
    printf("%d ",A[i]);

  printf("[%d] ",A[key]);
  for(i=key+1;i<n-1;i++)
    printf("%d ",A[i]);
  printf("%d\n",A[n-1]);
  
  return 0;
}



Measured memory_bytes: 2132
class ColorMgmt:
    from heapq import heappop, heappush
    def __init__(self, n):
        self.colors_hash = [set() for _ in range(n)]
        self.next_colors = [1] * n
    
    def set_color(self, v, c):
        self.colors_hash[v].add(c)
        while self.next_colors[v] in self.colors_hash[v]:
            self.next_colors[v] += 1
    
    def get_color(self, v):
        return self.next_colors[v]


N = int(input())
ab = [list(map(int, input().split())) for _ in range(N-1)]
edge = [[] for _ in range(N)]
edge_cnt = [0] * N
for idx, (a, b) in enumerate(ab):
    a, b = a-1, b-1
    edge[a].append([b, a, 0, idx])
    edge_cnt[a] += 1
    edge_cnt[b] += 1
K = max(edge_cnt)

next_list = []
now_list = [0]
color_mgmt = ColorMgmt(N)
while len(now_list) > 0:
    for v in now_list:
        for idx, nextv in enumerate(edge[v]):
            if v == nextv[0]:
                continue
            colors1 = color_mgmt.get_color(nextv[1])
            colors2 = color_mgmt.get_color(nextv[0])
            color = max(colors1, colors2)
            color_mgmt.set_color(nextv[1], color)
            color_mgmt.set_color(nextv[0], color)
            edge[v][idx][2] = color
            next_list.append(nextv[0])
    
    now_list = list(next_list)
    next_list = []

ret = []
for edges in edge:
    for e in edges:
        ret.append(e)
ret.sort(key=lambda x:x[3])
print(K)
for r in ret:
    print(r[2])


Measured memory_bytes: 120152
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 30)
using namespace std;

int main(){
    int n;
    while(cin >> n,n){
        int ans[2];
        ans[0] = 0;
        ans[1] = INF;
        rep(i,n){
            int sum = 0;
            rep(j,5){
                int inp;
                cin >> inp;
                sum+=inp;
            }
            ans[0] = max(ans[0], sum);
            ans[1] = min(ans[1], sum);
        }
        cout << ans[0] << ' ' << ans[1] << endl;
    }
}

Measured memory_bytes: 1160
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=b-1;i>=a;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll N,M,H[100007],ans[100007];

int main(){
  cin >> N >> M;
  rep(i,N){
    cin  >> H[i+1];
  }
  rep(i,M){
    ll X,Y;
    cin >> X  >> Y;
    if(H[X]>=H[Y]){
      ans[Y-1]=1;
    }
    if(H[X]<=H[Y]){
      ans[X-1]=1;
    }
  }
  ll X=0;
  rep(i,N){
    if(ans[i]==0){
      X++;
    }
  }
  cout<< X << endl;
}

Measured memory_bytes: 5192
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
using namespace std;
namespace mine
{
	typedef long long ll;
	#define pr pair<int,int>
	#define FR first
	#define SE second
	#define MP make_pair
	#define PB push_back
	#define vc vector
	#define mid (l+r)/2
	#define lc 2*x
	#define rc 2*x+1
	void chmax(int &x,const ll y) {x=(x>y?x:y);}
	void chmin(int &x,const ll y) {x=(x<y?x:y);}
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num)
	{
		if(num<0) putchar('-'),num=-num;
		if(num>=10) write(num/10);
		putchar('0'+num%10);
	}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	const int INF=0x3f3f3f3f;
	const int MOD=998244353;
	void add(ll &a,ll b){a+=b;if(a>=MOD)a-=MOD;if(a<=-MOD)a+=MOD;}
	ll qpower(ll x,ll e)
	{
		ll ans=1;
		while(e)
		{
			if(e&1) ans=ans*x%MOD;
			x=x*x%MOD;e>>=1;
		}
		return ans;
	}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int N=1e6+10;

	int bit[N];
	int lowbit(int x){return x&-x;}
	void add(int x,int c){while(x<N)bit[x]+=c,x+=lowbit(x);}
	int sum(int x){int ans=0;while(x>=1)ans+=bit[x],x-=lowbit(x);return ans;}

	vc<int> tt;int cnt[N][2][2];
	ll bin[N];pr pt[N];
    void main()
	{
		int n=qread();
		for(int i=1;i<=n;i++) {int x=qread(),y=qread();pt[i]=MP(x,y);tt.PB(x);tt.PB(y);}
		sort(tt.begin(),tt.end());sort(pt+1,pt+n+1);
		for(int i=1;i<=n;i++)
		{
			int x=lower_bound(tt.begin(),tt.end(),pt[i].FR)-tt.begin()+1;
			int y=lower_bound(tt.begin(),tt.end(),pt[i].SE)-tt.begin()+1;
			pt[i]=MP(x,y);
		}
		for(int i=1;i<=n;i++) cnt[i][0][1]=sum(pt[i].SE),cnt[i][0][0]=i-1-cnt[i][0][1],add(pt[i].SE,1);
		memset(bit,0,sizeof bit);
		for(int i=n;i>=1;i--) cnt[i][1][1]=sum(pt[i].SE),cnt[i][1][0]=n-i-cnt[i][1][1],add(pt[i].SE,1);

		bin[0]=1;for(int i=1;i<=n;i++) bin[i]=bin[i-1]*2%MOD;
		ll sum=-n;
		for(int i=1;i<=n;i++)
		{
			add(sum,bin[n]);
			add(sum,-(bin[ cnt[i][0][0]+cnt[i][0][1] ]));
			add(sum,-(bin[ cnt[i][0][0]+cnt[i][1][0] ]));
			add(sum,-(bin[ cnt[i][0][1]+cnt[i][1][1] ]));
			add(sum,-(bin[ cnt[i][1][0]+cnt[i][1][1] ]));
			add(sum,bin[cnt[i][0][0]]);add(sum,bin[cnt[i][0][1]]);
			add(sum,bin[cnt[i][1][0]]);add(sum,bin[cnt[i][1][1]]);
		}
		write((sum+MOD)%MOD);
	}
};
int main()
{
	srand(time(0));
	mine::main();
}


Measured memory_bytes: 18160
import sys
lines=sys.stdin.readlines()
for line in lines:
    H,W=map(int,line.split())
    if H == W == 0: break
    for i in range(H):
        if i==0 or i==H-1: print('#'*W)
        else: print('#'+('' if W==2 else '.'*(W-2))+'#')
    print('')

Measured memory_bytes: 7712
N, M, K = map(int, input().split()) 

A=list(map(int,input().split()))
B=list(map(int,input().split()))

a,b = [0], [0]

for i in range(N):
    a.append(a[i] + A[i])

for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M

for i in range(N+1):
    if a[i] > K:
        break

    while b[j]  > K - a[i]:
        j -= 1
    ans = max(ans, i+j)

print(ans)

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

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n; cin>>n;
    vector<ll> x(n);
    ll ox = 0;
    for(int i = 0; i<n; i++){
        cin>>x[i];
        ox = ox^x[i];
    }

    vector<ll> a(n);
    for(int i = 0; i<n; i++) a[i] = ox^x[i];

    for(ll p : a) cout<<p<<" ";
    cout<<"\n";
    return 0;
}

Measured memory_bytes: 6300
// ------------------------------------
// Date:2018/ 3/ 1
// Problem:ABC 056 GoHome c.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

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

int X;

ll solve()
{
}

int main()
{
  cin >> X;
  FOR (n, 1, 1e9) {
    if ((n + 1) * n >= 2 * X) {
      cout << n << endl;
      return 0;
    }
  }
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);
#if __cplusplus>=201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long a, long long b, long long x){
  if(2*x>(a*a)*b){
    long double len =(long double)2*b - (long double)x/(long double)(a*a)*2;
    cout<<setprecision(100)<<atan(len/a)*180/M_PI<<endl;
    return;
  }
  long double men = (long double)x/(long double)a;
  long double param=b*b/(men*2);
  dump(men);
  dump(param);
  cout<<setprecision(100)<<atan(param)*180/M_PI<<endl;

}

int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    long long x;
    scanf("%lld",&x);
    solve(a, b, x);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#define YEAR 6
using namespace std;

int main()
{
	int mouth[12] = {0, 3, 4, 0, 2, 5, 0, 3, 6, 1, 4, 6}, d, m, w;
	string week[7] = {"Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"};
	while (cin >> m >> d && m && d) {
		w = 5;
		w = w + d + mouth[m-1] + YEAR;
		w = w % 7;
		cout << week[w] << endl;
	}
}

Measured memory_bytes: 1196
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define fi first
#define se second

#define INF 2147483600

int main(){
  int arr[11];
  fill(arr, arr+11, 0);
  rep(i,3){
    int d;
    cin>>d;
    arr[d]++;
  }

  if(arr[5]==2 && arr[7]==1) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//#define eps 1e-8
//#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const int mod= 998244353;
ld PI = acosl(-1);
const ll infl = 5e18+100;
const int inf = 2e9;
const int nmax = 3e5+10;
const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;

int n,m;
vector<string>s;
int dst[105][105];
bool vis[105][105];

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

    cin>>n>>m;
    s.resize(n);
    for(string &x : s) cin>>x;

    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
            dst[i][j] = inf;

    queue<pii>q;
    q.push({0,0});
    dst[0][0] = 0;

    while(!q.empty()){
        int i = q.front().first, j = q.front().second;
        q.pop();
        if(vis[i][j]) continue;
        vis[i][j] = true;
        if(i+1<n){
            if(s[i][j] == s[i+1][j])
                dst[i+1][j] = min(dst[i+1][j], dst[i][j]);
            else
                dst[i+1][j] = min(dst[i+1][j], dst[i][j]+1);
            q.push({i+1,j});
        }
        if(j+1<m){
            if(s[i][j] == s[i][j+1])
                dst[i][j+1] = min(dst[i][j+1], dst[i][j]);
            else
                dst[i][j+1] = min(dst[i][j+1], dst[i][j]+1);
            q.push({i,j+1});
        }
    }

    int ans;
    if(s[0][0]=='#'){
        if(dst[n-1][m-1]%2==0) ans = dst[n-1][m-1]/2 + 1;
        else ans = (dst[n-1][m-1]+1)/2;
    }
    else{
        if(dst[n-1][m-1]%2==0) ans = dst[n-1][m-1]/2;
        else ans = (dst[n-1][m-1]+1)/2;
    }

    cout<<ans;
}


Measured memory_bytes: 384
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

#define N 100
#define F first
#define S second
typedef pair<int,int>pii;
typedef pair<int,pii>piii;

int u[N],r[N];

void init(int n){
    for(int i=0;i<n;i++){
        u[i]=i;r[i]=0;
    }
}
int find(int x){return x==u[x]?x:u[x]=find(u[x]);}

void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)return;
    if(r[x]<r[y])u[x]=y;
    else u[y]=x;
    r[x]+=(r[x]==r[y])?1:0;
}

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

int main(){
    int n,m;
    while(scanf("%d",&n),n){
        scanf("%d",&m);
        vector<piii>es(m);
        for(int i=0;i<m;i++){
            int a,b,c;
            scanf("%d,%d,%d",&a,&b,&c);
            c=c/100-1;
            es[i]=piii(c,pii(min(a,b),max(a,b)));
        }
        init(n);
        sort(es.begin(),es.end());
        int res=0;
        for(int i=0;i<m;i++){
            piii p=es[i];
            if(same(p.S.F,p.S.S))continue;
            unite(p.S.F,p.S.S);
            res+=p.F;
        }
        printf("%d\n",res);
    }
    return 0;

    return 0;
}

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

int A[300][300];
int check[300];

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

	int N, M;
	cin >> N >> M;
	for(int i = 0; i < N; i++) {
		for(int j = 0; j < M; j++) {
			cin >> A[i][j];
			A[i][j]--;
		}
	}

	int ans = 1e9;
	for(int loop = 0; loop < M ; loop++) {
		int cnt[300] = { 0 };
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < M; j++) {
				if(!check[A[i][j]]) {
					cnt[A[i][j]]++;
					break;
				}
			}
		}
		int idx = max_element(cnt, cnt + M) - cnt;
		check[idx] = 1;
		ans = min(ans, cnt[idx]);
	}

	cout << ans << endl;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int M = scan.nextInt();
		long sum = 1;
		if((int)Math.abs(N - M) == 0 || (int)Math.abs(N - M) == 1) {
			for(long i = 1; i <= N; i++) {
				sum = (sum * i) % 1000000007;
			}
			for(long i = 1; i <= M; i++) {
				sum = (sum * i) % 1000000007;
			}
			if((int)Math.abs(N - M) == 0) {
				sum = (sum * 2) % 1000000007;
			}
		} else {
			sum = 0;
		}
		System.out.println(sum);
		scan.close();
	}

}


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

#define ll long long
#define mod 1000000007
#define pll pair<long long,long long>
#define pdd pair<long double,long double>
#define vll vector<ll>
#define rep(i,j,n) for(int i=j;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define inf 1e17
#define N 100010
priority_queue<pll,vector<pll>,greater<pll> >pq;
priority_queue<ll,vector<ll>,greater<ll> >pq1;

ll result(ll a, ll b, ll p){
    ll ans=1;
    if(b==(-1))
        b=p-2;
    while(b){
        if(b&1){
            ans=(ans*a)%p;
        }
        a=(a*a)%p;
        b>>=1;
    }
    return ans;
}

ll T,n,m;

int main(){
    if(fopen("input.txt", "r"))
    freopen("input.txt", "r", stdin),
    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    cin >> n >> m;
    ll s =0,a;
    for(int i=0;i<m;i++){
    	cin >> a;
    	s += a;
    }
    if(s<=n)
    	cout << n-s;
    else
    	cout << "-1";
 
    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
struct Fast {Fast(){std::cin.tie(0);std::ios::sync_with_stdio(false);}} fast;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) v.begin(), v.end()

using namespace std;

ll mod = 1e9+7;
inline ll gcd(ll a, ll b){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

inline ll lcm(ll x, ll y)
{
    if(x == 0 || y == 0) {
        return -1;
    }
    
    return (x * y / gcd(x, y));
}

inline ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

inline ll nCr(ll n, ll r) {
    if ( r * 2 > n ) r = n - r;
    ll dividend = 1;
    ll divisor  = 1;
    for ( ll i = 1; i <= r; ++i ) {
        dividend *= (n-i+1);
        divisor  *= i;
    }
    return (dividend / divisor);
}

// 因数分解
inline vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
        if(n % i) continue;
        res.emplace_back(i, 0);
        while(n % i == 0){
            n /= i;
            res.back().second++;
        }
    }
    if(n != 1) res.emplace_back(n, 1);
    return res;
}

inline bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

//階乗
inline ll factorialMethod(ll k){
    ll sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

inline ll vector_finder(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
    if (index != vec.size()) { // 発見できたとき
        return 1;
    }
    else { // 発見できなかったとき
        return 0;
    }
}

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
  
    rep(i, n){
        cin >> a[i];
    }
    
    ll ans = 0;
    ll x = 1;
    rep(i, n){
        if(a[i] != x){
            ans ++;
        }else{
            x ++;
        }
    }
    
    if(ans == n){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 1792
N = int(input())

s = []
t = []

for i in range(N):
    s_i, t_i = input().split()
    s.append(s_i)
    t.append(int(t_i))

X = input()

total = 0
flag = 0

for i in range(N):
    if flag == 1:
        total += t[i]
    if s[i] == X:
        flag = 1

print(total)


Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
int foundwords(char s[],int flag)
{
    int L=0,g=0;
    char f[4]={'A','B','C'};
    for(int i=flag;f[g]!='\0';i++)
    {
        if(s[i]==f[g++]) L=1;
        else return 0;
    }
    return L;
}
int main()
{
    int n,count=0;
    char s[1000];
    scanf("%d",&n);
    scanf("%s",s);
    for(int i=0;i<strlen(s);i++)
        if(s[i]=='A')
            if(foundwords(s,i)) count++;
    printf("%d",count);
    return 0;
}


Measured memory_bytes: 128
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] h = new long[n];
		for(int i = 0; i < n; i++){
			h[i] = sc.nextLong();
		}
		long max = 0,count = 0;
		for(int i = 0; i < n-1; i++){
			
			if(h[i] >= h[i+1]){
				count += 1;
			}else{
				count = 0;
			}
			if(max < count){
				max = count;
			}
		}
		System.out.println(max);
	}
	
	}

Measured memory_bytes: 50296
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	ll n = in();
	ll maxa = -1, ans = 0;
	REP(i, n) {
		ll a = in(), b = in();
		if (maxa < a) {
			maxa = a;
			ans = a + b;
		}
	}
	cout << ans << endl;
}

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

def cumsum_2d(inlist,h,w):
    outlist = [ [ inlist[i-1][j-1] if i != 0 and j != 0 else 0 for i in range(k+1) ] for j in range(k+1) ]
    for i in range(1,h+1):
        tmp = 0
        for j in range(1,w+1):
            tmp += outlist[i][j]
            outlist[i][j] = tmp
    for i in range(1,w+1):
        tmp = 0
        for j in range(1,h+1):
            tmp += outlist[j][i]
            outlist[j][i] = tmp

    return outlist
    
n, k = [ int(v) for v in input().split() ]
hope = [ [ a for a in input().split() ] for i in range(n) ]

b_board = [ [ 0 for i in range(k)] for j in range(k) ]
w_board = [ [ 0 for i in range(k)] for j in range(k) ]



for h, w, c in hope:
    a1, a2 = divmod(int(w),k)
    b1, b2 = divmod(int(h),k)
    if (a1+b1) % 2 == 1:
        if c == "B":
            c = "W"
        else:
            c = "B"

    if c == "B":
        b_board[int(h)%k][int(w)%k] += 1
    else:
        w_board[int(h)%k][int(w)%k] += 1
    
b_board_3 = cumsum_2d(b_board,k,k)
w_board_3 = cumsum_2d(w_board,k,k)


total_b, total_w = b_board_3[k][k], w_board_3[k][k]
ans = 0

for i in range(1,k+1):
    for j in range(1,k+1):
        b1 = b_board_3[i][j] - b_board_3[0][j] - b_board_3[i][0]
        b2 = total_b - b_board_3[i][k] - b_board_3[k][j] + b_board_3[i][j]
        w1 = w_board_3[i][j] - w_board_3[0][j] - w_board_3[i][0]
        w2 = total_w - w_board_3[i][k] - w_board_3[k][j] + w_board_3[i][j]
        ans = max(b1+b2+(total_w-w1-w2),w1+w2+(total_b-b1-b2),ans)

print(ans)


Measured memory_bytes: 112860