akhauriyash/Code-Regression huggingface dataset:
n  = int(input())
cards = [[0]*13 for i in range(4)]
for i in range(n):
    sor,num = input().split()
    num = int(num)
    
    if sor == "S":
        cards[0][num-1] = num
    elif sor == "H":
        cards[1][num-1] = num
    elif sor == "C" :
        cards[2][num-1] = num
    else :
        cards[3][num-1] = num

for i in range(4):
    for j in range(13):
        if cards[i][j] ==0:
            if i ==0:
                sor = "S"
            elif i ==1:
                sor ="H"
            elif i ==2:
                sor = "C"
            else :
                sor = "D"
            print(sor,j+1)


Measured memory_bytes: 5608
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let x: i32 = sc.read();
    let y: i32 = sc.read();

    let __res = x + y/2;

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


Measured memory_bytes: 4352
//#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

//ifstream cin("tema.in");
//ofstream cout("tema.out");

int main() {
    int n, odd = 0, even = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        if (x % 2)
            odd++;
        else
            even++;
    }
    if (odd == 1 && even == 0) {
        cout << "YES\n";
        return 0;
    }
    if (odd % 2 == 0) {
        cout << "YES\n";
        return 0;
    }
    cout << "NO\n";
    return 0;
}



Measured memory_bytes: 256
#!/usr/bin/ruby
#
# 1029.rb: Traffic Analysis
#

### constant

MAX_INT = 1 << 30

### main

loop do
  n, m = gets.strip.split(' ').map(&:to_i)
  break if n == 0 && m == 0

  tls = (n > 0 ? gets.strip.split(' ').map(&:to_i) : []) + [MAX_INT]
  trs = (m > 0 ? gets.strip.split(' ').map(&:to_i) : []) + [MAX_INT]

  max_d = 0

  t0 = t1 = 0
  li = ri = 0

  loop do
    if tls[li] <= trs[ri]
      t1 = tls[li]
      li += 1
    else
      t1 = trs[ri]
      ri += 1
    end
    break if t1 >= MAX_INT

    d = t1 - t0
    max_d = d if max_d < d

    t0 = t1
  end

  puts max_d
end

Measured memory_bytes: 8636
o[9999];m[99][99];main(x,y,d,e){
for(d=0;~y;o[d++]=x)if(y=scanf("%d",&x),!y)getchar(),scanf("%d",&x);
for(d=(int)sqrt(d),e=x=0;x<d;x++)for(y=0;y<=x;y++)m[x-y][y]=o[e++];
for(x=d-2;~x;x--)for(y=0;y<=x;y++)m[d-1-y][d-1-(x-y)]=o[e++];
for(x=1;x<d;x++)m[x][0]+=m[x-1][0];
for(y=1;y<d;y++)m[0][y]+=m[0][y-1];
for(x=1;x<d;x++)for(y=1;y<d;y++)m[x][y]+=m[x-1][y]>m[x][y-1]?m[x-1][y]:m[x][y-1];
printf("%d\n",m[d-1][d-1]);exit(0);}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
int t[30];
int main() {
    ios_base::sync_with_stdio(0);
    int h, w;
    cin >> h >> w;
    char x;
    int ind = 0;
    for (int i = 0; i < h; i++) {
        for ( int j = 0; j < w; j++) {
            cin >> x;
            t[x - 'a']++;
        }
    }
    if ( h % 2 == 0 && w % 2 == 0) {
        for ( int i = 0; i <= 28; i++) {
            if ( t[i] % 4 != 0) {
                cout << "No";
                return 0;
            }
        }
        cout << "Yes";
        return 0;
    }
    if ( h % 2 != 0 && w % 2 != 0) {
        int cur1 = 0;
        int cur2 = 0;
        for ( int i = 0; i <= 28; i++) {
            if ( t[i] % 4 == 2) cur2++;
            if ( t[i] % 2 == 1) {
                    cur1++;
                    ind = i;
            }
        }
        if ( cur1 > 1) cout <<"No";
        else {
            if (t[ind] % 4 == 3 ) {
                cur2++;
            }
            if ( cur2 > h / 2 + w / 2) cout << "No";
            else if ( cur2  % 2 != (h / 2 + w / 2) % 2) cout << "No";
            else cout << "Yes";
        }
        return 0;
    }
    int cur1 = 0; int cur2 = 0;
    if ( h % 2 != 0) swap(h, w);
    for ( int i = 0; i <= 28; i++) {
            if ( t[i] % 4 == 2) cur2++;
            if ( t[i] % 2 == 1) cur1++;
        }
    if ( cur1 > 0) cout << "No";
    else if ( cur2 > h / 2) cout << "No";
    else if ( cur2 % 2 != (h / 2) % 2) cout << "No";
    else cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
M = 1000
DM = M * 2 + 1
 
def count(n):
    global M
    res = n + 1
    if n > M:
        res -= (n-M) * 2
    return res
 
def solve(n):
    cnt = 0
    for a in range(min(DM, n), -1, -1):
        b = n - a
        if b > DM:
            break
        cnt += count(a) * count(b)
    return cnt
 
while True:
    try:
        l = input()
    except EOFError:
        break
    nm = int(l)
    print(solve(nm))

Measured memory_bytes: 7748
#include <iostream>
#include<algorithm>
//#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
#define pb emplace_back
#define mp make_pair
#define MOD (int) 1e9+7
#define for0(i, n) for (int i = 0; i < n; i++)
#define ff first
#define ss second
#define endl "\n"
#define bits(n) __builtin_popcount(n)
#define ini(a, i) memset(a, i, sizeof(a))

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	// cin >> t;
	t  = 1;
	while (t--)
	{
		ll n;
		cin >> n;
		ll arr[n];
		ll p = 0;
		for (ll i = 0; i < n; i++)
		{
			cin >> arr[i];
			if (arr[i] == 0)
				p = 1;
		}
		if (p == 1)
		{
			cout << "0" << endl;
			return 0;
		}
		// sort(arr, arr + n);
		long double ans = 1;
		for (ll i = 0; i < n; i++)
		{
			// cout << arr[i] * ans << " " << (arr[i] * ans > (ll)1e18) << endl;
			if ((arr[i] * ans) > (ll)1e18 || (arr[i] * ans) < 0)
			{
				cout << "-1" << endl;
				return 0;
			}
			else
				ans = ans * arr[i];
		}
		cout << (ll)ans << endl;
	}
	return 0;
}
//|| (arr[i] * ans) < 0

Measured memory_bytes: 4444
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<map>
#include<vector>
using namespace std;

const int N=200005;

int n,sz,ans;
int a[N],b[N],c[N];
bool vis[N];
map<int,int> c1,c2;
vector<int> lev[N];

void dfs(int k){
	int j;
	vis[k]=1;
	for (j=0;j<lev[k].size();j++)
		if (!vis[lev[k][j]]) dfs(lev[k][j]);
}

int main(){
	int i;
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",&a[i]),a[n+1]^=a[i];
	for (i=1;i<=n;i++) scanf("%d",&b[i]),b[n+1]^=b[i];
	n++;
	for (i=1;i<=n;i++) c1[a[i]]++;
	for (i=1;i<=n;i++) c2[b[i]]++;
	for (i=1;i<=n;i++) if (c1[a[i]]!=c2[a[i]]){
		printf("-1\n");
		return 0;
	}
	for (i=1;i<=n;i++) c[++sz]=a[i];
	for (i=1;i<=n;i++) c[++sz]=b[i];
	sort(c+1,c+1+sz); sz=unique(c+1,c+1+sz)-c-1;
	for (i=1;i<=n;i++) a[i]=lower_bound(c+1,c+1+sz,a[i])-c;
	for (i=1;i<=n;i++) b[i]=lower_bound(c+1,c+1+sz,b[i])-c;
	for (i=1;i<n;i++) if (a[i]!=b[i]){
		lev[a[i]].push_back(b[i]);
		ans++;
	}
	lev[a[n]].push_back(b[n]);
	if (!ans){
		printf("0\n");
		return 0;
	}
	for (i=1;i<=n;i++)
		if (!vis[a[i]]&&lev[a[i]].size()){
			dfs(a[i]);
			ans++;
		}
	printf("%d\n",ans-1);
	return 0;
}

Measured memory_bytes: 22400
#include <bits/stdc++.h>
#define rep(i, ns, ne) for (int i = ns; i < ne; ++i)
using namespace std;

int main() {
  long long n, x, a, b, tmp, ans = 0;
  cin >> n >> x >> a;

  rep(i, 0, n) {
    if (i < n - 1) {
      cin >> b;
    } else {
      b = 0;
    }
    if (a + b > x) {
      tmp = a + b - x;
      b = b - tmp;
      ans += tmp;
    }
    a = b;
  }

  cout << ans << endl;
  getchar();
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int min(int x,int y)
{
	return (x<y)?x:y;
}
int main()
{
	int n,i;
	cin>>n;
	int h[n],table[n]={0};
	for(i=0;i<n;i++)
	{
		cin>>h[i];
	}
	table[1]=abs(h[0]-h[1]);
	for(i=2;i<n;i++)
	{
		table[i]=min(table[i-1]+abs(h[i]-h[i-1]),table[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<table[n-1];
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int MAX = 10000;
const int INF = 999999999;
int U[MAX];
int n, G[MAX][MAX];
struct Edge
{
	int u;
	int v;
	int w;
};
vector<Edge> E;
void init()
{
	for (int i = 0; i < n; i++)
		U[i] = i;
}
int getAncestor(int v)
{
	if (U[v] == v)
		return v;
	else
	{
		U[v] = getAncestor(U[v]);
		return U[v];
	}
}
bool merge(int s, int t)
{
	int a1 = getAncestor(s);
	int a2 = getAncestor(t);
	if (a1 != a2)
	{
		U[a2] = a1;
		return false;
	}
	return true;
}
bool cmp(Edge a, Edge b)
{
	return a.w < b.w;
}
int main()
{
	int m;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		int u, v, w;
		cin >> u >> v >> w;
		Edge e = { u,v,w };
		E.push_back(e);
	}
	init();
	sort(E.begin(), E.end(), cmp);
	int sum = 0;
	int edgeNum = 0;
	//cout << "MST的边为：\n";
	for (int i = 0; i < E.size(); i++)
	{
		Edge e = E[i];
		if (!merge(e.u, e.v))
		{
			sum += e.w;
			edgeNum++;
			//cout << e.u << "---" << e.v << " 权值为" << e.v << endl;
		}
		if (edgeNum == n - 1)
			break;
	}
	cout << sum << endl;
}


Measured memory_bytes: 4560
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    s = S()
    west = [0] * (N+1)
    east = [0] * (N+1)

    for i, c in enumerate(s):
        if c == 'W':
            west[i] = 1
        else:
            east[i] = 1

    for i in range(N):
        west[i+1] += west[i]

    for i in range(N)[::-1]:
        east[i] += east[i+1]

    min_c = inf
    ans_i = -1
    for i in range(N):
        if i == 0:
            tot = east[i+1]
        elif i == N-1:
            tot = west[i-1]
        else:
            tot = west[i-1] + east[i+1]

        min_c = min(min_c, tot)
    print(min_c)
main()



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

int main() {
	long N, M, D; cin >> N >> M >> D;
	long long P;
	if(D) P=(N-D)*2*(M-1);
	else P=N*(M-1);
	cout << P/(N*N) << '.';
	P=P%(N*N);
	for(int i=0; i<10; ++i){
	    P *= 10;
	    cout << P/(N*N);
	    P=P%(N*N);
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		long total = 0;
		long mod = 0;
		for (int i = 0; i < n; i++) {
			long a = sc.nextInt();
			if (a != 0) {
				a += mod; //一つ前の余りを足す
			}
			total += a / 2; //作れる限りペアを作る
			mod = a % 2; //ペアからあぶれた余りを次に渡す
		}
		System.out.println(total);
	}
}

Measured memory_bytes: 48152
#include<iostream>
using namespace std;
#define SIZE 10000000

bool isP[SIZE+1];
int ans[SIZE+1];

void make_table(){
  for(int i=0;i<=SIZE;i++)isP[i]=true;
  isP[0]=isP[1]=false;
  for(int i=2;i*i<=SIZE;i++){
    if(isP[i]==false)continue;
    for(int j=i*i;j<=SIZE;j+=i)isP[j]=false;
  }
  ans[13]=13;
  for(int i=14;i<=SIZE;i++){
    ans[i]=ans[i-1];
    if(isP[i]&&isP[i-2]&&isP[i-6]&&isP[i-8])ans[i]=i;
  }
}

int main(){
  make_table();
  int n;
  while(cin>>n&&n)cout<<ans[n]<<endl;
  return 0;
}

Measured memory_bytes: 49988
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();
		String[] a = new String[n];
		String[] b = new String[m];
		for (int i = 0; i < n; i++) {
			a[i] = scan.next();
		}
		for (int i = 0; i < m; i++) {
			b[i] = scan.next();
		}
		for (int i = 0; i <= n - m; i++) {
			for (int k = 0; k <= n - m; k++) {
				boolean flag = true;
				for (int j = 0; j < m; j++) {
					String temp = a[j + i].substring(k, k + m);
					if (!temp.equals(b[j])) {
						flag = false;
						break;
					}
				}
				if (flag) {
					System.out.println("Yes");
					return;
				}
				flag = true;
			}
		}
		System.out.println("No");
	}
}

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

ll i,j,k,l;

int main(){
    ll n,h,sum=0;cin>>n>>h;
    vector<ll> a(n),b(n);
    for(i=0;i<n;i++){
        cin>>a[i]>>b[i];
    }

    sort(a.begin(),a.end());
    sort(b.begin(),b.end());

    for(i=0;i<n;i++){
        if(b[i]<=a[n-1]){b[i]=-1;}//最大の通常攻撃より小さいdamageなら投げつけない
        else{sum+=b[i];}
    }

    ll ans=0,num=n-1;
    while(h>0 && num>=0 && b[num]!=-1){
        h-=b[num--];
        ans++;
    }

    if(h<=0){cout<<ans<<endl;return 0;}

    ans+=(h+a[n-1]-1)/a[n-1];

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

Measured memory_bytes: 1792
import java.util.Scanner;
public class Main{

    int a,b,c;
    int[] data;
    int size = 3;

    public void input(){
	Scanner scan = new Scanner(System.in);
        data = new int[3];
	for ( int i = 0; i < 3; i++ ){
	    data[i] = scan.nextInt();
	}
    }
 
    public void selsort(){
	for (int front = 0;front < size - 1;front++){

	    int minIndex = front;
            for (int j = front + 1;j < size;j++){
		if (data[j] < data[minIndex]){
                    minIndex = j;
		}
	    }
  
	    int tmp = data[front];
            data[front] = data[minIndex];
            data[minIndex] = tmp;
	}
    }

    public void output(){
	System.out.println(data[0]+" "+data[1]+" "+data[2]);

      
    }
 public static void main(String[] args){
     Main p = new Main();
     p.input();
     p.selsort();
     p.output();
 }
}
  

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    int a[n],b[n],c[n];
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<n;i++) cin >> b[i];
    for(int i=0;i<n-1;i++) cin >> c[i];
    int sp=0;
    for(int i=0;i<n;i++){
              sp+=b[a[i]-1];
	    if(a[i] == a[i+1]-1)  {
	sp+=c[a[i]-1];
    }
    }
    cout << sp << "\n";
}


Measured memory_bytes: 256
// {{{ by shik
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REP1(i, a, b) for (int i = (a); i <= int(b); i++)
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

namespace { namespace shik {

template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%" SCNd64, &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }

template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%" PRId64, x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }

#ifdef SHIK
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T, class F = less<T>> void sort_uniq(vector<T> &v, F f = F()) { sort(begin(v), end(v), f); v.resize(unique(begin(v), end(v)) - begin(v)); }
template<class T> inline T bit(T x, int i) { return (x >> i) & 1; }
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

// }}}

const int N=200010;
int n,m,a[N],b[N];
map<int,int> mp;
void main() {
    R(n);
    REP(i,n) R(a[i]);
    R(m);
    REP(i,m) R(b[i]);
    REP(i,n) mp[a[i]]++;
    REP(i,m) mp[b[i]]--;
    for ( auto i:mp ) if ( i.second<0 ) {
        W("NO");
        return;
    }
    W("YES");
}

// {{{ main
}}
int main() { shik::main(); return 0; }
// }}}


Measured memory_bytes: 11136
/**
 *    author:  Daredevil666
 *    institution: IIT Patna
**/
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define nl cout<<"\n";
#define ll long long int
#define IOS  ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const ll mod=1e18;
const ll MAXN=100200;
int main()
{
IOS
/*#ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
#endif // ONLINE_JUDGE*/
ll n,d;
cin>>n>>d;
ll cnt=0;
for(ll i=0;i<n;i++)
{
    ll x,y;
    cin>>x>>y;
    ll p=x*x+y*y;
    if(ceil((double)sqrt(p))<=d)
        cnt++;
}
cout<<cnt;
return 0;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

int main(){
 ll a,b,k ; cin>>a>>b>>k  ; 
  if(a<k){
    k-=a;
    if(b<k){
  cout<<0<<' '<< 0 <<endl;
    }
    else cout<<0<<' '<<b-k<<endl;
    }
  else {
  cout<<a-k<<' '<<b<<endl;
  }
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <ctime>
using namespace std;
 
int dp[30][30][30][30];
int memoa[30][30], memob[30][30];
int ori_rule[15], ori_s, orilen, ori_rulelen;
int n, m, stra[30], strb[30];
int rules[50000][3], rulelen, newvar;
 
void transform(int rule[], int start, int len){
  if(len == 2){
    rules[rulelen][0] = rule[0];
    rules[rulelen][1] = rule[1];
    rules[rulelen][2] = start;
    rulelen++;
  }
  else{
    rules[rulelen][0] = newvar++;
    rules[rulelen][1] = rule[len - 1];
    rules[rulelen][2] = start;
    rulelen++;
    transform(rule, newvar - 1, len - 1);
  }
}
 
void CYK(int str[], int len, int memo[30][30]){
  bool mark[30][30][700] = {0};
  for(int i = 0; i < len; i++) mark[i][1][str[i]] = true;
   
  for(int i = 2; i <= len; i++)
  for(int idx = 0; idx < len; idx++)
  for(int k = 1; k < i; k++)
  for(int r = 0; r < rulelen; r++)
    if(mark[idx][k][rules[r][0]] && mark[(idx + k) % len][i - k][rules[r][1]]) mark[idx][i][rules[r][2]] = true;
   
  for(int i = 0; i < len; i++)
  for(int j = 1; j <= len; j++){
    for(int k = 1; k <= 30; k++)
      if(mark[i][j][k]) memo[i][j] |= 1 << k;
  }
}
 
int main(){
  while(scanf("%d%d%d", &n, &m, &ori_rulelen) == 3 && (n || m || ori_rulelen)){
    newvar = 31;
    rulelen = 0;
    memset(memoa, 0, sizeof(memoa));
    memset(memob, 0, sizeof(memob));
    memset(dp, -1, sizeof(dp));
     
    for(int i = 0; i < n; i++) scanf("%d", stra + i);
    for(int i = 0; i < m; i++) scanf("%d", strb + i);
    for(int i = 0; i < ori_rulelen; i++){
      scanf("%d", &orilen);
      for(int i = 0; i < orilen; i++) scanf("%d", ori_rule + i);
      scanf("%d", &ori_s); 
      transform(ori_rule, ori_s, orilen);
    }
     
    CYK(stra, n, memoa);
    CYK(strb, m, memob);
     
    for(int i = 0; i < n; i++)
    for(int j = 0; j < m; j++) dp[i][0][j][0] = 0;
     
    for(int i = 0; i < n; i++)
    for(int j = 0; j < m; j++)
    for(int a = 1; a <= n; a++)
    for(int b = 1; b <= m; b++)
    for(int aa = 0; aa < a; aa++)
    for(int bb = 0; bb < b; bb++)
      if((memoa[(i + aa) % n][a - aa] & memob[(j + bb) % m][b - bb]) && dp[i][aa][j][bb] != -1)
        dp[i][a][j][b] = max(dp[i][a][j][b], dp[i][aa][j][bb] + 1);
     
    int ans = -1;
    for(int i = 0; i < n; i++)
    for(int j = 0; j < m; j++) ans = max(ans, dp[i][n][j][m]);
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 4824
#include<bits/stdc++.h>
using namespace std;
#define int long long
  
// driver code 
signed main() 
{ 
    int n;
    cin >> n;
    string str;
    cin >> str;
    vector<int> w, r;
    int i;
    for(i=0;i<n;i++)
        if(str[i] == 'R')
            r.push_back(i);
        else
            w.push_back(i);
    int ans = 0;
    for(auto j : w)
    {
        if(r.size() == 0)
            break;
        if(j < r.back())
            ans++, r.pop_back();
    }
    cout << ans;
} 

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin >> n;
  ll a[n][3];
  REP(i,n)REP(j,3)cin>>a[i][j];

  ll dp[n][3];
  REP(i,n)REP(j,3)dp[i][j]=LLINF;
  REP(i,3)dp[0][i]=a[0][i];

  REP1(i,n){
    REP(j,3){
      ll ye = 0;
      REP(k,3){
        if(j!=k)
          ye=max(ye,dp[i-1][k]);
      }

      dp[i][j]=ye+a[i][j];
    }
  }

  ll ans=0;
  REP(i,3)
    ans = max(dp[n-1][i],ans);
  cout << ans << endl;
}


Measured memory_bytes: 4992
#include<iostream>
#include<string>

int main(void){
    std::string s;
    int m,h;
    while(std::cin>>s){
        if(s=="-")break;
        std::cin>>m;
        while(m-->0){
            std::cin>>h;
            s=s.substr(h)+s.substr(0,h);
        }
        std::cout<<s<<std::endl;
    }
    return 0;
}


Measured memory_bytes: 3148
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n,p;
  string s;
  cin >> n;
  vector<tuple<string,ll,ll>> G;
  for(int i=1;i<n+1;i++){
    cin >> s >> p;
    G.push_back(make_tuple(s,-p,i));
  }

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

  for(int i=0;i<G.size();i++){
    cout << get<2>(G[i]) << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;
int main() {
    int H, W, x, y;
    scanf("%d %d %d %d", &H, &W, &x, &y);
    if (!((H*W)&1) || !((x+y)&1)) printf("Yes\n");
    else printf("No\n");
}



Measured memory_bytes: 2692
#include <iostream>
using namespace std;
#define SCALL 1000000
int main(){
int s;
int a[SCALL];
  
cin>>s;

for(int i=0;i<SCALL;i++){
if(i==0){
a[i]=s;
}
else{
if(a[i-1]%2==0){
a[i]=a[i-1]/2;
}
else{
a[i]=a[i-1]*3+1;
}
}
}
for(int i=0;i<SCALL;i++){
for(int j=0;j<SCALL;j++){
if(i!=j){
if(a[i]==a[j]){
cout<<j+1;
return 0;
}
}
}
}
  
}

Measured memory_bytes: 4096
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>

int main()
{
    double x1, y1, x2, y2;

    std::cin >> x1 >> y1 >> x2 >> y2;

    double distance = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));

    std::cout << std::fixed << std::setprecision(30) << distance << std::endl;

    return 0;
}


Measured memory_bytes: 3288
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
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; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


void Main(){
    ll D, N;
    cin >> D >> N;
    ll ans;
    if(N==100){
        ans = 101;
    }else{
        ans = N;
    }
    ans *= pow(100, D);
    cout << ans << el;
}



Measured memory_bytes: 3768
n = gets.to_s.to_i
@s = gets.to_s.chomp.bytes

@h = Hash.new{|h, k| h[k] = []}
@s.each.with_index(1){|c, i| @h[c] << i}
@s = @s.unshift(32)

def update(i, c)
  d = @s[i]
  return if c == d
  @s[i] = c
  @h[d].delete_at(@h[d].bsearch_index{|x| x >= i})
  @h[c].insert((@h[c].bsearch_index{|x| x >= i} || -1), i)
end

gets
readlines.each do |x|
    a, b, c = x.to_s.chomp.split
    b = b.to_i

    if a == '1'
        update(b, c.ord)
    else
        c = c.to_i
        puts @h.each_value.count {|e| (e.bsearch{|x| x >= b} or n+1) <= c}
    end
end

Measured memory_bytes: 15504
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

const ll MOD = (ll)1e9 + 7;
int N;
int T[100010], A[100010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> T[i];
  }  
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  int a[100010], b[100010];
  fill_n((int*)a, 100010, -1);
  fill_n((int*)b, 100010, -1);

  int tmp = -1;
  for (int i = 0; i < N; i++) {
    if (T[i] == tmp) continue;
    a[i] = tmp = T[i];
  }
  tmp = -1;
  for (int i = N - 1; i >= 0; i--) {
    if (A[i] == tmp) continue;
    b[i] = tmp = A[i];
  }

  for (int i = 0; i < N; i++) {
    if (a[i] < 0 && b[i] < 0) continue;
    if (a[i] < 0 && T[i] >= A[i]) continue;
    if (b[i] < 0 && T[i] <= A[i]) continue;
    if (a[i] == b[i]) continue;
    cout << 0 << endl;
    return 0;
  }
  ll ans = 1;
  for (int i = 0; i < N; i++) {
    if (a[i] >= 0 || b[i] >= 0) continue;
    ans = ans * min(T[i], A[i]) % MOD;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main()
{
  int a, b;
  cin >> a >> b;
  if (a < b)
    cout << "a < b" << endl;
  else if (a > b)
    cout << "a > b" << endl;
  else
    cout << "a == b" << endl;

  return 0;
}

Measured memory_bytes: 1156
r1, c1, r2, c2 = map(int, input().split())

p = 10 ** 9 + 7
size = 1010000 * 2
f_list = [1] * size
for i in range(1, size):
    f_list[i] = (f_list[i - 1] * i) % p

def cmb(n, r):
    return f_list[n + r] * pow(f_list[n], p-2, p) * pow(f_list[r], p-2, p) % p

hole = cmb(r2 + 1, c2 + 1) - 1
rect1 = cmb(r2 + 1, c1) - 1
rect2 = cmb(r1, c2 + 1) - 1
duplicate = cmb(r1, c1) - 1
ans = (hole - rect1 - rect2 + duplicate) % p
print(ans)

Measured memory_bytes: 82932
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 1000
int top,S[N];

void push(int x){
  S[++top] = x;
}
int pop(){
  top--;
  return S[top+1];
}

int main(){
  int a,b;
  top=0;
  char s[100];
  while(scanf("%s" ,s) != EOF){
    if(s[0] == '+'){
      a=pop();
      b=pop();
      push(a+b);
    }
    else if(s[0] == '-'){
      b=pop();
      a=pop();
      push(a-b);
    }
    else if(s[0] == '*'){
      a=pop();
      b=pop();
      push(a*b);
    }
    else{
      push(atoi(s));
    }
  }
  printf("%d\n" ,pop());

  return 0;
}



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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

const int MAX_N = 10;
int n;
int a[MAX_N+1][MAX_N+1];

int main()
{
  while((cin >> n) && n){
    rep(i, n+1) rep(j, n+1) a[i][j] = 0;
    rep(i, n)   rep(j, n)   cin >> a[i][j];

    rep(i, n)   rep(j, n)   a[n][j] += a[i][j];
    rep(i, n+1) rep(j, n)   a[i][n] += a[i][j];

    rep(i, n+1) rep(j, n+1) printf("%5d%s", a[i][j], (j==n ? "\n" : ""));
  }

  return 0;
}

Measured memory_bytes: 1160
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

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

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double d;
typedef long long ll;

const int N=2e5+5;
const int mod=1e9+7;

int power(ll x,int b){
    ll res=1;
    while(b){
        if(b&1) res=res*x%mod;
        x=x*x%mod;
        b>>=1;
    }
    return res;
}
signed main(){
    FastIO;
    int n;
    cin>>n;
    int a[n+5];
    map<int,int>f;
    rep(i,1,n){
        cin>>a[i];
        int tp=a[i];
        map<int,int>mp;
        rep(j,2,sqrt(tp)){
            while(tp%j==0){
                mp[j]++;
                tp/=j;
            }
        }
        if(tp>1) mp[tp]++;
        for(auto it:mp){
            f[it.F]=max(f[it.F],it.S);
        }
    }
    ll lcm=1,ans=0;
    for(auto it:f){
        rep(i,1,it.S) lcm=lcm*it.F%mod;
    }
    rep(i,1,n) ans=(ans+lcm*power(a[i],mod-2))%mod;
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <math.h>

using namespace std;

int main()
{
    int a[3][3][2];
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> a[i][j][0];
            a[i][j][1] = 0;
        }
    }

    int n;
    cin >> n;

    int b;
    bool f = false;
    for (int k = 0; k < n; k++)
    {
        cin >> b;
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                if (a[i][j][0] == b)
                {
                    a[i][j][1] = 1;
                }
            }
        }

        for (int i = 0; i < 3; i++)
        {
            if (a[i][0][1] + a[i][1][1] + a[i][2][1] == 3)
            {
                f = true;
                break;
            }
            else if (a[0][i][1] + a[1][i][1] + a[2][i][1] == 3)
            {
                f = true;
                break;
            }
        }

        if (a[0][0][1] + a[1][1][1] + a[2][2][1] == 3)
        {
            f = true;
        }
        else if (a[2][0][1] + a[1][1][1] + a[0][2][1] == 3)
        {
            f = true;
        }

        if (f)
        {
            break;
        }
    }

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

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	unordered_map<int, int>m;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		m[x]++;
	}
	ll ans = 0;
	for (auto k : m) {
		if (k.se > 0) {
			if (k.se < k.fi)
				ans += k.se;
			else if (k.se >= k.fi)
				ans += abs(k.se - k.fi);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 4260
#include <iostream>

using namespace std;

int main() {
	int f=0;
	int N,r1=0,r2=0,r3=0,r4=0;
	cin >> N;
	
	r1 = (N - (N % 1000))/1000;
	r2 = (N -r1*1000- (N % 100))/100;
	r3 = (N-r1*1000-r2*100 - (N % 10))/10;
	r4 = N-r1*1000-r2*100-r3*10;
	if ((r1 == r2) && (r2==r3) && (r3==r1)) {
		f++;
	}
	if ((r2 == r3) && (r3 == r4) && (r4 == r2)) {
		f++;
	}
	if (f >= 1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  string ans;
  if(A > 8 || B > 8) {
    ans = ":(";
  } else {
  	ans = "Yay!";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int a,b,h;
  cin>>a>>b>>h;
  cout<<(a+b)*h/2<<endl;



}


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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, x, y) for(decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y)); i += 1 - 2 * ((x) > (y)))
#define trav(i,a) for(auto& (i) : (a))
#define all(a) (a).begin(),(a).end()
#define sz(a) int((a).size())
#define clr(a,x) memset((a),(x),sizeof(a)) // array (0,-1)
#define dbg(x) cerr << "STDERR => " << __LINE__ << ": " << #x << " = " << (x) << "  :(\n";
#define pb push_back
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline void cpuTime() { cerr << "cpu time : " << double(clock())/CLOCKS_PER_SEC << "\n"; return; }
using ll = long long;
using ull = unsigned long long;
using F = float;
using D = double;
using vi = vector<int>;
using pii = pair<int,int>;



void solve(){

    ll n, a, b;
    cin >> n >> a >> b;

    ll ans = a*(n/(a+b));
    ans += min(a, n%(a+b));

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

/*
 read the question carefully ( what're the exact constraints? )
 look out for SPECIAL CASES (n=1?) and OVERFLOW (ll vs int?) ARRAY OUT OF BOUNDS
 Check datatypes
*/
int main(){

    fast_io;
    int t=1;
    // cin >> t;

    while(t--){
        solve();
    }

    cpuTime();
return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n;cin >> n;
    vl a(n);rep(i,n)cin >> a[i];
    ll ans=0;
    rep(i,n){
        while(i+1<n&&a[i]==a[i+1])i++;
        if(i+1<n&&a[i]<a[i+1]){
            while(i+1<n&&a[i]<=a[i+1])i++;
        }
        else if(i+1<n&&a[i]>a[i+1]){
            while(i+1<n&&a[i]>=a[i+1])i++;
        }
        ans++;
    }
    cout << ans <<endl;
}

Measured memory_bytes: 1024
import java.util.*;

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

        while (true) {
            int sum=0,max=0,min=1000;
            int n = sc.nextInt();
            if(n==0)break;
            for (int i = 0; i < n; i++) {
            int a=sc.nextInt();
            sum += a;
            if(a>max)max=a;
            if(a<min)min=a;
            }
            System.out.println((sum-(max+min))/(n-2));
        }
    }
}



Measured memory_bytes: 28448
require 'prime'
N = gets.to_i

MOD = 10 ** 9 + 7
table = Hash.new { 0 }
(1..N).each do |n|
  n.prime_division.each do |a, e|
    table[a] += e
  end
end
ans = table.values.reduce(1) do |acc, n|
  acc * (n + 1) % MOD
end
puts ans


Measured memory_bytes: 2300
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll X, K, D;
  cin>>X>>K>>D;
  X = abs(X);
  if(X/D>=K) cout<<X-K*D<<endl;
  else {
    if((X/D)%2==K%2) {
      cout<<X%D<<endl;
    }
    else {
      cout<<D-(X%D)<<endl;
    }
  }
}



Measured memory_bytes: 3628
H, W = map(int, input().split())
S = [input() for _ in range(H)]

N = W * H
E = [[0] * N  for _ in range(N)]


# for i, e in enumerate(E):
    # e[i] = 1

# print(E)

dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            for di, dj in dij:
                ni, nj = i + di, j + dj
                if 0 <= ni < H and 0 <= nj < W and S[ni][nj] == ".":
                    E[W * i + j][W * ni + nj] = 1

# print(E)

from scipy.sparse.csgraph import floyd_warshall
INF = float("inf")

A = floyd_warshall(E)
# print(A)
print(int(max(max(a if a != INF else 0 for a in a) for a in A)))


Measured memory_bytes: 18132
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
if (a < b) {
System.out.println("a < b");
} else if(a > b){
System.out.println("a > b");
} else System.out.println("a == b");
}
}


Measured memory_bytes: 26120
a,b=map(int,input().split())

if 0<a:
    print('Positive')
elif a==0:
    print('Zero')
elif a<0 and b>=0:
    print('Zero')
elif a<0 and b<0:
    if len(range(a,b+1))%2==1:
        print('Negative')
    else:
        print('Positive')

Measured memory_bytes: 3060
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<complex>
#include<list>
#include<cstdio>

#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 llong long long
#define pb(a) push_back(a)


using namespace std;

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




const int INF = 1e9+7;


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


vector<int> G[100005];
int pa[100005];
int d[100005];
int in[100005];

void dfs(int par, int now, int dpt) {

	if (pa[now] != -INF)return;

	pa[now] = par;
	d[now] = dpt;

	for (int nxt : G[now]) {

		if (pa[nxt] != -INF)continue;
		dfs(now, nxt, dpt + 1);
	}
}



int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int v, d;
		cin >> v >> d;

		for (int j = 0; j < d; j++)
		{
			int c;
			cin >> c;
			G[v].push_back(c);
			in[c]++;
		}
	}

	for (int i = 0; i < 100005; i++)
	{
		pa[i] = -INF;
	}

	int node = 0;
	for (int i = 0; i < 100005; i++)
	{
		if (in[i] == 0) {
			node = i;
			break;
		}
	}

	dfs(-1, node, 0);//（親番号，今いる番号，深さ）

	for (int i = 0; i < n; i++)
	{
		cout << "node " << i << ": parent = " << pa[i] << ", depth = " << d[i];

		if (d[i] == 0) {
			cout << ", root";
		}else if (G[i].size() == 0) {
			cout << ", leaf";
		}
		else
		{
			cout << ", internal node";
		}

		cout << ", ";
		cout << '[';

		int cnt = 0;
		for (int child:G[i])
		{
			if (cnt)cout << ", ";
			cout << child;
			cnt++;
		}
		cout << ']';
		cout << endl;
	}


	return 0;
}



Measured memory_bytes: 7440
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
const int MAX=1e5;
int n;
vector<vector<int>> dp(MAX,vector<int>(4));
vector<int> a(MAX);
vector<int> b(MAX);
vector<int> c(MAX);

int calc(int index,int bit){
    if(index==n){
        return 0;
    }
    if(dp[index][bit]!=-1){
        return dp[index][bit];
    }
    int ans;
    if(bit==0){
        ans=max(a[index]+calc(index+1,1),b[index]+calc(index+1,2));
        ans=max(ans,c[index]+calc(index+1,3));
    }
    else if(bit==1){
        ans=max(b[index]+calc(index+1,2),c[index]+calc(index+1,3));
    }
    else if(bit==2){
        ans=max(a[index]+calc(index+1,1),c[index]+calc(index+1,3));    
    }
    else{
        ans=max(b[index]+calc(index+1,2),a[index]+calc(index+1,1));
    }
    return dp[index][bit]=ans;
}
void solve(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i]>>c[i];
        dp[i][0]=dp[i][1]=dp[i][2]=dp[i][3]=-1;
    }
    int max_happ=calc(0,0);
    cout<<max_happ<<'\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 13184
while True:
    b=int(input())
    if b == 0: break
    # fee = (nf - 1)nf/2 + fl*nf
    # -> fl = (fee - (nf-1)nf/2) / nf
    nf = 1
    ans = (b,1)
    while True:
        d = b - (nf-1)*nf//2
        if d <= 0: break
        if d % nf == 0:
            ans = (d // nf, nf)
        nf += 1
    print("{0} {1}".format(ans[0],ans[1]))
    



Measured memory_bytes: 5600
K, N = map(int, input().split())
A = list(map(int, input().split()))

if N == 2:
    print(min(A[1] - A[0], K + A[0] - A[1]))

max_distance = 0

if N > 2:
    for i in range(N - 1):
        s = A[i + 1] - A[i]
        if s > max_distance:
            max_distance = s

    print(min(K - max_distance, A[N - 1] - A[0]))

Measured memory_bytes: 25840
void main() {
	auto ip = readln.split, S = ip[0], T = ip[1];
	auto ip2 = readAs!(int[]), A = ip2[0], B = ip2[1];
	auto U = rs;
	if(U == S) A--; else B--;
	writefln("%d %d", A, B);
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int INF=2147483647;
const double pi=3.1415926535897932384626;
inline ll read(){
	ll x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
const int maxn=2e5+5;
ll n,a[maxn],ans;
int main(){
	n=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
		ans^=a[i];
	}
	for(int i=1;i<=n;i++) printf("%lld ",ans^a[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 5252
n = int(input())
t, x, y = 0, 0, 0
t1, x1, y1 = 0, 0, 0
p = False
for i in range(n):
	t, x, y = t1, x1, y1
	t1, x1, y1 = map(int, input().split())
	s = t1 - t
	d = x1 + y1 - x - y
	p = x >= 0 and y >= 0 and (abs(s) >= abs(d)) and ((s - d) % 2 == 0)
	# print("{},{}".format(s, d))
	if p == False:
		break
print("Yes" if p else "No")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
//const int PI = acos(-1);
int main(){
	ll n,m;cin>>n>>m;
	ll sum=0;
	map<ll,ll>mo;
	rep(i,n){
		ll a;
		cin>>a;
		a%=m;
		sum +=a;
		sum%=m;
		mo[sum]++;
	}
	ll ans =0;
	mo[0]++;
	for(auto i  :mo){
		ll sm = i.second;
		ans+=(sm*(sm-1))/2;
	}
	cout<<ans<<endl;
	
}

Measured memory_bytes: 4224
def is_prime(n):
    if n == 1: return False
    for k in range(2, int(n**0.5) + 1):
        if n % k == 0:
            return False
    return True


while 1:
    n = int(input())
    if n==0: break
    cnt = 0
    for i in range(n+1, 2*n+1):
        if is_prime(i):
            cnt += 1
    print(cnt)



Measured memory_bytes: 5692
N, M = map(int, input().split())
pi = []
Si = []
for i in range(M):
    p, S = map(str, input().split())
    pi.append(p)
    Si.append(S)
score = 0
penalty = 0
now_num = 1
AC_problem = [True] * N
WA_problem = [True] * N
penalty_num = [0] * N
for i in range(M):
    if Si[i] == 'AC' and AC_problem[int(pi[i]) - 1]:
        score += 1
        AC_problem[int(pi[i]) - 1] = False
        WA_problem[int(pi[i]) - 1] = False
    elif WA_problem[int(pi[i]) - 1]:
        penalty += 1
        penalty_num[int(pi[i]) - 1] += 1

for i in range(N):
    if AC_problem[i]:
        penalty -= penalty_num[i]
        
print(str(score) + ' ' + str(penalty))


Measured memory_bytes: 18076