akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <iostream>
#include <unordered_map>

using namespace std;
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

#define ff first
#define ss second

const long long maxa = 1e6 + 1;
const long long MOD = 1e9 + 7;

long long mod_pow(long long a, long long b, long long p = MOD) { // = (a^b) % p //((a^-1) % p) = (a^(p-2)) % p;
	long long res = 1;
	a %= p;

	while (b > 0) {
		if ((b & 1) == 1) res = ((res % p) * (a % p)) % p;
		a = ((a % p) * (a % p)) % p;
		b >>= 1;
	}
	return res;
}

vector<bool> is_prime(maxa, true);
vector<long long> primes;
void sieve() {
	for (long long i = 2; i * i < maxa; i++) {
		if (is_prime[i] == true) {
			for (long long j = i * i; j < maxa; j += i) is_prime[j] = false;
		}
	}
	is_prime[0] = false;
	is_prime[1] = false;

	for (int i = 2; i <= maxa - 1; i++) if (is_prime[i]) primes.push_back(i);
	return;
}

long long  n;
vector<long long > a;

long long  __lcmMOD() {
	unordered_map<long long, long long> max_pow;

	for (auto i : a) {
		unordered_map<long long, long long> pfac;
		for (auto fac : primes) {
			if (fac * fac > i) break;
			while (i % fac == 0) {
				pfac[fac]++, i /= fac;
				max_pow[fac] = max(max_pow[fac], pfac[fac]);
			}
		}
		if (i > 1) pfac[i]++, max_pow[i] = max(max_pow[i], pfac[i]);;
	}

	long long  l = 1;
	for (auto i : max_pow) {
		l = (l % MOD * mod_pow(i.ff, i.ss)) % MOD;
	}
	return l;
}

int  main() {

	sieve();
	cin >> n;
	a.resize(n);
	for (long long  i = 0; i <= n - 1; i++) cin >> a[i];

	long long  k = __lcmMOD();

	long long  ans = 0;
	for (auto i : a) ans = (ans % MOD + (k % MOD * mod_pow(i, MOD - 2)) % MOD) % MOD;

	cout << ans % MOD;

	return 0;
}

Measured memory_bytes: 4128
import collections

n = int(input())
v = list(map(int, input().split()))

l1 = []
l2 = []
for i in range(n):
    if i % 2 == 0:
        l1.append(v[i])
    else:
        l2.append(v[i])

counter1 = collections.Counter(l1)
counter2 = collections.Counter(l2)

mode_v1 = counter1.most_common()
mode_v2 = counter2.most_common()
# print(mode_v1, mode_v2)

if mode_v1[0][0] != mode_v2[0][0]:
    print(n - mode_v1[0][1] - mode_v2[0][1])
else:
    if len(set(v)) == 1:
        print(n // 2)
    elif len(set(l1)) == 1:
        print(mode_v2[0][1])
    elif len(set(l2)) == 1:
        print(mode_v1[0][1])
    else:
        print(min(n - mode_v1[0][1] - mode_v2[1][1], n - mode_v1[1][1] - mode_v2[0][1]))

Measured memory_bytes: 24016
def CountingSort(A, B, k):
    C = [0] * (k + 1)
    for j in A:
        C[j] += 1
    for i in range(1, k + 1):
        C[i] += C[i - 1]
    for j in reversed(A):
        B[C[j]-1] = j
        C[j] -= 1


n = int(input())
A = list(map(int, input().split()))
B = [0] * n
CountingSort(A, B, max(A))
print(*B)


Measured memory_bytes: 224376
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
	#define errp(...)
	#define dbg(...)
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (const string& e_) { return "\"" + e_ + "\""; }
string to_string (char e_) { return "\'" + string(1, e_) + "\'"; }
string to_string (bool e_) { return e_ ? "true" : "false"; }
template <typename T> string to_string (T e_) {
	string s_ = "[ ";
	for (const auto& x_ : e_) s_ += to_string(x_) + " ";
	return s_ + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e_) {
	return "(" + to_string(e_.first) + ", " + to_string(e_.second) + ")";
}
void dbg_str () { errp(" \n"); }
template <typename U, typename... V> void dbg_str (U u, V... v) {
	errp(" %s", to_string(u).c_str()); dbg_str(v...);
}
/* --- */

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	/* --- */
	int n, m;
	vector<pair<ll,ll>> v;
	
	cin >> n >> m;
	ll x, y;
	for(int i = 0; i < n; i++){
		cin >> x >> y;
		v.push_back({x,y});
	}

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

	ll ans = 0;
	for(int i = 0; i < n; i++){
		if(m > 0){
			x = min(m,int(v[i].second));
			ans +=  x* v[i].first;
			m -= v[i].second;
		}
	}
	cout << ans;
}	


Measured memory_bytes: 2420
N = int(input())
et = 0
ex = 0
ey = 0
ans = 'Yes'
for i in range(N):
    t, x, y = map(int, input().split())
    T = t - et
    dist = x - ex + y - ey
    if T % 2 != dist % 2 or T < dist:
        ans = 'No'
        break
    et = t
    ex = x
    ey = y
print(ans)


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int bubbleSort(int A[], int N) {
    int flag = 1;
    int cnt = 0;
    while (flag) {
        flag = 0;
        for (int j = N-1; j > 0; j--) {
            if (A[j] < A[j-1]) {
                swap(A[j], A[j-1]);
                cnt++;
                flag = 1;
            }
        }
    }
    return cnt;
}

void trace(int A[], int N) {
    for (int k = 0; k < N; k++) {
        if (k > 0) cout << ' ';
        cout << A[k];
    }
    cout << endl;
}

int main() {
    int N, A[100], cnt;
    cin >> N;

    for (int i = 0; i < N; i++) cin >> A[i];

    cnt = bubbleSort(A, N);
    trace(A, N);
    cout << cnt << endl;

    return 0;

    
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int n;
  cin >> n;
  
  int ans = 0;
  int max_count = 0;
  
  for(int i = 0 ; i < n ; i++){
    int a;
    cin >> a;
    
    if(a >= max_count){
      ans++;
    }
    max_count = max(a,max_count);
  }
  
  cout << ans << endl;
}
    
    

Measured memory_bytes: 256
str = gets.chomp

n = str.length
(n-1).times do |i|
    if str[i] == str[i+1]
        puts "#{i+1} #{i+2}"
        exit
    end
end

(n-2).times do |i|
    if str[i] == str[i+2]
        puts "#{i+1} #{i+3}"
        exit
    end
end

puts "-1 -1"

Measured memory_bytes: 1916
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll mod = 1e9 + 7;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}

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


//////////////////////////////////////////////////////////////////////////////////////

struct UnionFind {
    vector<int> r;

    UnionFind(int N) {
        r = vector<int>(N, -1);
    }

    int root(int x){
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }

    bool unite(int x, int y){
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }

    int size(int x){
        return -r[root(x)];
    }

};

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

    UnionFind uf(n);
    for (int i = 0;i < m;i++){
        int a, b;
        cin >> a >> b;
        a -= 1;
        b -= 1;
        uf.unite(a, b);
    }

    int ans = 0;
    for (int i = 0;i < n;i++){
        ans = max(ans, uf.size(i));
    }

    cout << ans << endl;
}


Measured memory_bytes: 4052
a=[]
w=""
while(w!="-1 -1 -1"):
    w=input()
    a.append(w)
a.pop()
for st in a:
    s=st.split()
    m=int(s[0])
    f=int(s[1])
    r=int(s[2])
    if (m==-1 or f==-1):
        print("F")
    elif (m+f>=80):
        print("A")
    elif(m+f>=65):
        print("B")
    elif(m+f>=50):
        print("C")
    elif(m+f>=30 and r>=50):
        print("C")
    elif(m+f>=30 and r<50):
        print("D")
    else:
        print("F")

Measured memory_bytes: 5600
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define endl "\n"
#define int long long
#define pb push_back
#define getMat(v, n, m, val) vector<vector<int>> v(n,vector<int>(m, val))
#define lb lower_bound
#define up upper_bound
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define size(v) (int)v.size()
using namespace std;
const int mod = 1e9+7;

int32_t main(){
    fastio;
    
    string s; cin >> s;
    if(s.back()=='s'){
        s.append("es");
    }else{
        s.append("s");
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long int
#define INF INT_MAX
#define chutiyaap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
int main()
{
	chutiyaap;
	double n;cin>>n;
	double x=n*(180-(360.0)/n);
	cout<<x;
}


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

namespace c
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var k = int.Parse(_[0]);
            var n = int.Parse(_[1]);

            var a = Console.ReadLine().Split().Select(i => int.Parse(i)).ToList();
            a.Add(k + a[0]);

            var diff = Enumerable.Range(0,n).Select(i => a[i+1] - a[i]).ToList();
            var distance = diff.Sum() - diff.Max();
            Console.WriteLine(distance);
        }
    }
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

struct Res {
  string name;
  int p;
  int n;
  bool operator < (const Res& res) const {
    if(name != res.name) {
      return name < res.name;
    } else {
      return p > res.p;
    }
  }
  void input() {
    cin >> name >> p;
  }
};

const int MAX_N = 105;
int N;
Res res[MAX_N];

signed main()
{
  cin >> N;
  REP(n,N) {
    res[n].input();
    res[n].n = n+1;
  }

  sort(res, res+N);

  REP(n,N) {
    cout << res[n].n << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

// O(\sqrt{n})
vector<ll> divisor(ll n){
    vector<ll> res;
    for(ll i=1; i*i <= n; i++){
        if(n%i == 0){
            res.push_back(i);
            if(i != n / i) res.push_back(n / i);
        }
    }
    return res;
}

int main(void){
    ll n, m;
    cin >> n >> m;
    vector<ll> divs = divisor(m);
    sort(divs.begin(), divs.end());

    ll ans;
    for(ll i=0; i<divs.size(); i++){
        if(divs[i] * n <= m){
            ans = divs[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#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: 3100
#include<stdio.h>
#define DAY 3
int main(void) {
	int i;
	int rain_cnt=0;
	char weather[1000];
	scanf("%s", weather);
	if (weather[0] == 'R')rain_cnt++;
	for (i = 1; i < DAY; i++) {
		if (weather[i - 1] == 'R'&&weather[i]=='R')rain_cnt++;
		if (weather[i - 1] == 'S' && weather[i] == 'R')rain_cnt = 1;
	}
	printf("%d", rain_cnt);
	return 0;
}

Measured memory_bytes: 1720
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
int n,k;
int M=40;
long long a[1000005],sum[1000005];
vector<long long> V[55],v,v1;
long long er[105];
bool chk(int np)
{
	int sum=0;
	for(int i=0;i<v.size();i++)
	{
		if(v[i]&er[np])sum++;
	}
	if(sum<k)return 0;return 1;
}
void pro(int np)
{
	v1.clear();
	for(int i=0;i<v.size();i++)
	{
		if(v[i]&er[np])v1.push_back(v[i]);
	}
	v.clear();
	for(int i=0;i<v1.size();i++)
		v.push_back(v1[i]);
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	int nc=0;

	er[0]=1;
	for(int i=1;i<=40;i++)er[i]=er[i-1]*2;

	for(int i=1;i<=n;i++)for(int j=i;j<=n;j++)
	{
		nc++;
		if(i==j)sum[nc]=a[i];
		else sum[nc]=sum[nc-1]+a[j];
		for(int i=0;i<=M;i++)
		{
			if(sum[nc]&er[i])
			{
				V[i].push_back(sum[nc]);
			}
		}
	}
	int np=-1;
	for(int i=M;i>=0;i--)if(V[i].size()>=k)
	{
		np=i;
		break;
	}
	if(np==-1)
	{
		printf("0\n");
		return 0;
	}
	for(int i=0;i<V[np].size();i++)v.push_back(V[np][i]);
	long long ans=er[np];
	for(int i=np-1;i>=0;i--)
	{
		if(chk(i))pro(i),ans+=er[i];
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 82488
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin >> N;
  if (N == 1)
  {
    printf("%.10lf", 1.0);
  }
  else if (N % 2 == 0)
  {
    double a = (N / 2.0) / N;
    printf("%.10lf", a);
  }
  else
  {
    double b = ceil((N / 2.0)) / N;
    printf("%.10lf", b);
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;
typedef long long ll;
const int mod = 1000000007; // assert mod is prime

template<int M>
struct Mint {
	int x;
	Mint() : x(0) {}
	Mint(int y) : x(y >= 0 ? y % M : M - (-y) % M) {}
	Mint &operator += (const Mint &rhs) { if((x += rhs.x) >= M) x -= M; return *this; }
	Mint &operator -= (const Mint &rhs) { if((x += M - rhs.x) >= M) x -= M; return *this; }
	Mint &operator *= (const Mint &rhs) { x = 1LL * x*rhs.x % M; return *this; }
	Mint &operator /= (const Mint &rhs) { x = (1LL * x*rhs.inv().x) % M; return *this; }
	Mint operator - () const { return Mint(-x); }
	Mint operator + (const Mint &rhs) const { return Mint(*this) += rhs; }
	Mint operator - (const Mint &rhs) const { return Mint(*this) -= rhs; }
	Mint operator * (const Mint &rhs) const { return Mint(*this) *= rhs; }
	Mint operator / (const Mint &rhs) const { return Mint(*this) /= rhs; }
	bool operator < (const Mint &rhs) const { return x < rhs.x; }
	Mint inv() const {
		signed a = x, b = M, u = 1, v = 0, t;
		while(b) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
		return Mint(u);
	}
	Mint pow(long long t) const {
		Mint e = *this, res = 1;
		for(; t; e *= e, t >>= 1) if(t & 1) res *= e;
		return res;
	}
};
template <int M>
ostream &operator << (ostream &os, const Mint<M> &rhs) {
	return os << rhs.x;
}
template <int M>
istream &operator >> (istream &is, Mint<M> &rhs) {
	long long s; is >> s; rhs = Mint<M>(s); return is;
};

using mint = Mint<mod>;


ll modpow(ll x, ll y, ll m) {
	if(y == 0) return 1;
	ll res = modpow(x, y / 2, m);
	return res * res % m * (y & 1 ? x : 1) % m;
}

ll modinv(ll x, ll m) {
	return modpow(x, m - 2, m);
}

struct Comb {
	int sz;
	vector<mint> mfact, mfinv;
	Comb(int N) : sz(min(N, int(mod) - 1)), mfact(sz + 1), mfinv(sz + 1) {
		for(int i = 0; i <= sz; i++) mfact[i] = (i == 0 ? 1 : mfact[i - 1] * i);
		mfinv[sz] = mfact[sz].inv();
		for(int i = sz; i >= 1; i--) mfinv[i - 1] = mfinv[i] * i;
	}
	mint fact(int n, int& e) { // e に p の指数が入る
		// Wilson の定理
		e = 0;
		if(n <= sz) return mfact[n];
		mint res = fact(n / mod, e);
		e += n / mod;
		if(n / mod % 2 != 0) return -res * mfact[n % mod];
		return res * mfact[n % mod];
	}
	mint nPr(int n, int r) {
		int e; return fact(n, e) / fact(n - r, e);
	}
	mint nCr(int n, int r) {
		// Lucus の定理
		assert(n <= sz);
		if(n >= mod) return nCr(n%mod, r%mod) * nCr(n / mod, r / mod);
		return r > n ? 0 : mfact[n] * mfinv[n - r] * mfinv[r];
	}
	mint nHr(int n, int r) {
		return r == 0 ? 1 : nCr(n + r - 1, r);
	}
};

mint dp[100010];

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

	int H, W, A, B;
	cin >> H >> W >> A >> B;

	Comb c(1000010);

	mint ans = 0;
	dp[B] = c.nCr(H - A - 1 + B, B);
	ans += dp[B] * c.nCr(A + W - B - 1, A);
	for(int i = B + 1; i < W; i++) {
		dp[i] = c.nCr(H - A - 1 + i, H - A - 1) - c.nCr(H - A - 1 + i - 1, H - A - 1);
		ans += dp[i] * c.nCr(A + W - i - 1, A);
	}

	cout << ans << endl;
}

Measured memory_bytes: 8448
A, B, M = map(int, input().split())

price_A = list(map(int, input().split()))
price_B = list(map(int, input().split()))
min_A = min(price_A)
min_B = min(price_B)

ans = min_A + min_B
for i in range(M):
    x, y, c = map(int, input().split())
    ans = min(price_A[x-1]+price_B[y-1]-c,ans)

print(ans)


Measured memory_bytes: 18736
from fractions import gcd
from functools import reduce

def lcm_base(x,y):
    return (x * y) // gcd(x,y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers)
  
n = int(input())
t = [int(input()) for i in range(n)]
print(lcm_list(t))

Measured memory_bytes: 5588
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    string S;
    cin >> S;
    if (S == "SUN") cout << 7 << endl;
    else if (S == "MON") cout << 6 << endl;
    else if (S == "TUE") cout << 5 << endl;
    else if (S == "WED") cout << 4 << endl;
    else if (S == "THU") cout << 3 << endl;
    else if (S == "FRI") cout << 2 << endl;
    else if (S == "SAT") cout << 1 << endl;
    return 0;
}


Measured memory_bytes: 256
N,X,Y=map(int,input().split())
X-=1
Y-=1
E=[[] for _ in range(N)]
for i in range(N-1):
  E[i].append(i+1)
  E[i+1].append(i)
  if i==X:
    E[i].append(Y)
    E[Y].append(X)

cnt=[0]*N
for i in range(N):
  dist=[-1]*N
  dist[i]=0
  stack=[i]
  while stack:
    u=stack.pop(0)
    for v in E[u]:
      if dist[v]==-1:
        dist[v]=dist[u]+1
        cnt[dist[v]-1]+=1
        stack.append(v)
for i in range(N-1):
  print(cnt[i]//2)

Measured memory_bytes: 46300
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b;
    cin>>a>>b;
    ll c=b-a;
    ll d=c*(c+1)/2;
    cout << d-b<<endl;
    return 0;
}


Measured memory_bytes: 256
#define REP(i,n) for (int i=0;i<=(n);i++)
#include <algorithm>
#include <iostream>
using namespace std;

int main(){
	const int c[4] = {10,50,100,500};
	int price,fl = 0;
	while(cin >> price && price > 0){
		int k[4],a[4],pay,change_num,pay_num,coin_min;
		coin_min = 1000;
		REP(i,3){
			cin >> k[i];
		}
		REP(i,k[0]){
		REP(j,k[1]){
		REP(l,k[2]){
		REP(m,k[3]){
			pay = c[0]*i + c[1]*j + c[2]*l + c[3]*m;
			pay_num = i + j + l + m;
			if(pay - price >= 0){
				int change = pay - price;
				change_num = 0;
				for(int n=3;n>=0;n--){
						while(change - c[n] >= 0){
							change -=  c[n];
							change_num++;	
					}
				}
				if(coin_min > change_num - pay_num){
					coin_min = change_num - pay_num;
					a[0] = i;
					a[1] = j;
					a[2] = l;
					a[3] = m; 
				}
		}
		}
		}
		}
		}
		if(fl)
			cout << endl;
		else
			fl = 1;
		REP(i,3){
			if(a[i] > 0)
				cout << c[i] << " " << a[i] << endl;
		}
	
	}
}

Measured memory_bytes: 1164
// Best practice

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <functional> // for less 

#define int         long long
#define pb          emplace_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> pbds; 

#define fbo find_by_order
#define ook order_of_key

signed main() {
   tezz
   
    string s,ss;
    cin >> s >> ss;
    int n,m;
    cin >> n >> m;
    string t;
    cin >> t;
    if(s==t)n--;
    else m--;
    cout << n << " " << m << endl;
    
  
   return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define Mod 998244353
#define pi 3.14159265358979323846
#define endl '\n'
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;

bool ex[105];

int main()
{
    int x,n;
    cin>>x>>n;
    vi a(n);
    for(int i=0;i<n;i++) cin>>a[i],ex[a[i]]=true;

    for(int d=0;d<=100;d++)
    {
        if(x-d>=0 and !ex[x-d]){cout<<x-d<<endl;return 0;}
        if(x+d<=101 and !ex[x+d]){cout<<x+d<<endl;return 0;}
    }

    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int x[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << x[k-1] << "\n";
    return 0;
}

Measured memory_bytes: 256
/*Insertion sort*/
#include<stdio.h>


int main(){
	int n,i,j;
	scanf("%d",&n);
		int a[n];
		for(i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		printf("%d",a[0]);
		for(i=1;i<n;i++){
			printf(" %d",a[i]);
		}
		printf("\n");
		for(i=0;i<n-1;i++){
		    j=i+1;
			while(j>0 && a[j]<a[j-1]){
				a[j-1]^=a[j];
				a[j]^=a[j-1];
				a[j-1]^=a[j];
				j--;
			}
			printf("%d",a[0]);
            for(int k=1;k<n;k++){
                printf(" %d",a[k]);
            }
            printf("\n");
        }
	return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
   int n;
   cin >> n;
   int count = 0;
   vector<int> a(n);
   for(auto &it : a) cin >> it;
   for(int i = 0; i < n; i++){
       for(int j = 0; j < n; j++){
           for(int k = 0; k < n; k++){
               if(i < j && j < k){
                   if(a[i] == a[j]) continue;
                   if(a[j] == a[k]) continue;
                   if(a[k] == a[i]) continue;
                   if((ll)a[i] + a[j] + a[k] <= max({a[i], a[j], a[k]})*2) continue;
                   count++;
               }
           }
       }
   }
   cout << count << endl;
   

}



Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define fore(i, a) for (auto &i : a)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  n = n % 10;
  if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9)
    cout << "hon" << endl;
  if (n == 0 || n == 1 || n == 6 || n == 8)
    cout << "pon" << endl;
  if (n == 3)
    cout << "bon" << endl;
}


Measured memory_bytes: 3620
import math
from collections import deque
from collections import defaultdict

import itertools as it

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

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

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq
def get_sieve_of_eratosthenes(n):
	#data = [2]
	data = [0,0,0]
	for i in range(3,n+1,2):
		data.append(i)
		data.append(0)
	for i in range(len(data)):
		interval = data[i]
		if interval!=0:
			for j in range(i+interval,n-1,interval):
				data[j] = 0
	#ans = [x for x in data if x!=0]
	ans = data[:]
	return ans

s = input()
t = input()

s+=s

if t in s:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 3444
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int x,y,z; 
    cin>>x>>y>>z;
    cout<<(x-z)/(y+z)<<endl;
}


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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

template<typename T>
T vec_sum(V<T> v, T init_val=0){return accumulate(ALL(v),T(init_val));}

template<typename T>
T vec_max(V<T> v){return *max_element(ALL(v));}

const int INF = 1999999999;

int main(){
    int n,k;
    cin>>n>>k;
    Vi h(n);
    REP(i,n) cin>>h[i];

    sort(ALL(h));

    int min_d = INF;
    REP(i,n-k+1){
        min_d = min(min_d,h[i+k-1]-h[i]);
    }

    cout<<min_d<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
#include<stdlib.h>
#define ll long long

using namespace std;

const ll mod = 1000000007;
const ll maxn = 2000005;
ll fun[maxn];
ll infun[maxn];

ll qp(ll a,ll b){
    ll res=1;
    a%=mod;
    if(a==0)return 0;
    while(b){
        if(b&1){
            res=res*a%mod;
        }
        a=a*a%mod;
        b>>=1;
    }
    return res%mod;
}

void prepare(){
    fun[0]=fun[1]=1;
    for(int i=2;i<maxn;++i){
        fun[i]=fun[i-1]*i%mod;
    }
    infun[maxn-1]=qp(fun[maxn-1],mod-2);
    for(int i=maxn-2;i>=0;--i){
        infun[i]=infun[i+1]*(i+1)%mod;
    }
}

ll C(ll n,ll m){
    if(n<0||m<0||n<m)return 0;
    ll res = fun[n];
    res = res*infun[m]%mod;
    res = res*infun[n-m]%mod;
    return res;
}

int main(){
    ll k;
    cin>>k;
    string s;
    cin>>s;
    ll ans=0;
    ll n = s.length();
    prepare();
    for(int i=n;i<=n+k;++i){
        ll tmp = C(i-1,n-1);
        tmp = tmp*qp(25,max(0ll,i-n))%mod;
        tmp = tmp*qp(26,max(0ll,n+k-i))%mod;
        ans=(ans + tmp)%mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 35588
H,W,K=map(int,input().split())
x1,y1,x2,y2=map(int,input().split())
C=[]
nx=set([])

for _ in range(H):
    C.append(list(input()))

def keiro(x,y,k):
    i=1
    while True:
        if y+i>W-1 or C[x][y+i]!='.' or i>k:
            break
        else:
            if (x,y+i) not in nx:
                nx.add((x,y+i))
            i+=1
    
    i=1
    while True:
        if y-i<0 or C[x][y-i]!='.' or i>k:
            break
        else:
            if (x,y-i) not in nx:
                nx.add((x,y-i))
            i+=1
    
    i=1
    while True:
        if x+i>H-1 or C[x+i][y]!='.' or i>k:
            break
        else:
            if (x+i,y) not in nx:
                nx.add((x+i,y))
            i+=1
    
    i=1
    while True:
        if x-i<0 or C[x-i][y]!='.' or i>k:
            break
        else:
            if (x-i,y) not in nx:
                nx.add((x-i,y))
            i+=1

    return 0

C[x1-1][y1-1]=0
keiro(x1-1,y1-1,K)
taisho=nx.copy()
result=1
for j in nx:
    C[j[0]][j[1]]=result

while C[x2-1][y2-1]=='.':
    nx=set([])
    if len(taisho)==0 or result>10**6:
        result=-1
        break
    for l in taisho:
        keiro(l[0],l[1],K)
    result+=1
    for j in nx:
        C[j[0]][j[1]]=result
    taisho=nx.copy()

print(result)


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

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

	vector<long long> L(n, 0);
	vector<long long> R(n, 0);
	for (int i = 1; i <= n; ++i) {
		int a;
		cin >> a;

		int l = i + a;
		if (l < n) {
			++L[l];
		}

		int r = i - a;
		if (r > 0) {
			++R[r];
		}
	}

	long long s = 0;
	for (int i = 2; i < n; ++i) {
		s += L[i] * R[i];
	}

	cout << s;

	return 0;
}


Measured memory_bytes: 6380
// ctrl+shift+b
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll A, B; cin >> A >> B;
    if (A <= 8 && B <= 8){cout << "Yay!"<< endl;} else {cout << ":("<< endl;}
}

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


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

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

int main(){
	static int h,w,k;
	static char a[802][802];
	rep(i,802)rep(j,802)a[i][j] = '#';
	scanf("%d%d%d",&h,&w,&k);
	rep1(i,h){
		scanf("\n");
		rep1(j,w)scanf("%c",&a[i][j]);
	}
	
	static int d[802][802];
	static bool used[802][802];
	static queue<P> que;
	rep(i,802)rep(j,802){
		d[i][j] = INF;
		used[i][j] = false;
	}
	rep1(i,h)rep1(j,w){
		if(a[i][j] == 'S'){
			d[i][j] = 0;
			que.push(P(i,j));
		}
	}
	while(!que.empty()){
		P p = que.front(); que.pop();
		if(used[p.fr][p.sc])continue;
		used[p.fr][p.sc] = true;
		rep(i,4){
			if(a[p.fr+dx[i]][p.sc+dy[i]] == '#')continue;
			d[p.fr+dx[i]][p.sc+dy[i]] = d[p.fr][p.sc]+1;
			if(d[p.fr+dx[i]][p.sc+dy[i]] < k)que.push(P(p.fr+dx[i],p.sc+dy[i]));
		}
	}
	
	int ret = INF;
	rep1(i,h)rep1(j,w){
		if(d[i][j] == INF)continue;
		int D = min( i-1 , h-i );
		D = min( D , min( j-1 , w-j ) );
		ret = min( ret , (D+k-1)/k+1 );
	}
	cout << ret << endl;
}


Measured memory_bytes: 4096
#include <iostream>
#include <vector>
// #include <algorithm>
// #include <set>
// #include <string>
// #include <cmath>
// #include <map>
// #include <iomanip>

#define MOD 1000000007

using namespace std;
// typedef unsigned long long ull;
typedef long long ll;

void p() {
    cout << "\n";
}
template<class Head, class... Body>
void p(Head head, Body... body) {
    cout << head << ",";
    p(body...);
}


int main(int argc, char const *argv[]) {
    int x, y;
    cin >> x >> y;

    bool ans;
    if (x == 2) {
        ans = false;
    } else if (x == 4 || x == 6 || x == 9 || x == 11) {
        if (y == 4 || y == 6 || y == 9 || y == 11) {
            ans = true;
        } else {
            ans = false;
        }
    } else {
        if (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12) {
            ans = true;
        } else {
            ans = false;
        }
    }

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

    return 0;
}


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

#define fr(i,n) _back
#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int N = 1e5 + 3;
int h[N];
int dp[N];

int main() {
    ios_base::sync_with_stdio(false);
    memset(dp, INF, sizeof dp);
    int n; cin >> n;
    for(int i = 0; i < n; i++) cin >> h[i];

    dp[0] = 0;
    for(int i = 1; i < n; i++)
        for(int j = max(0,i-2); j < i; j++)
            dp[i] = min(dp[i], dp[j] + abs(h[i]-h[j]));

    cout << dp[n-1] << endl;
    return 0;
}


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

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

const int maxN = 5012;

int k, i, j;
string s, aux;
vector<string> data;

int main()
{
   // freopen("test.in","r",stdin);

    cin >> s >> k;
    for (i = 0; i < s.size(); i++) {
        aux.clear();
        for (j = 0; j < k && i + j < s.size(); j++) {
            aux.pb(s[i + j]);
            data.pb(aux);
        }

        if (data.size() > 100) {
            sort(data.begin(), data.end());
            data.resize(unique(data.begin(), data.end()) - data.begin());
            if (data.size() > k) data.resize(k);
        }
    }

    sort(data.begin(), data.end());
    data.resize(unique(data.begin(), data.end()) - data.begin());

    cout << data[k - 1];


    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
main(){
  int H,W,i,j;
  while(1){
    scanf("%d%d",&H,&W);
    if(H==0 && W==0) break;
    for(i=1;i<=H;i++){
      for(j=1;j<=W;j++){
        if(i==1||j==1||j==W||i==H) printf("#");
        else printf(".");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 572
#include <stdio.h>
#define MAX 100

int Hira[MAX][MAX], size[MAX], high[MAX];
 
void visit(int k, int t){
    int i;
    high[k] = t;
    for (i = 1; i <= size[k]; i++){
        if (high[Hira[k][i]] > t)visit(Hira[k][i], t + 1);
    }
}
 
int main()
{
  int i, j, n,k;
 
    scanf("%d", &n);
    for (i = 1; i <= n; i++){
        high[i] = 10000;
        for (j = 1; j <= n; j++)Hira[i][j] = 0;
    }
 
    for (i = 1; i <= n; i++){
        scanf("%d", &k);
        scanf("%d", &size[k]);
        for (j = 1; j <= size[k]; j++)scanf("%d", &Hira[k][j]);
    }
 
    visit(1, 0);
 
    for (i = 1; i <= n; i++){
        if (high[i] == 10000)high[i] = -1;
        printf("%d %d\n", i, high[i]);
    }
    return 0;
}

Measured memory_bytes: 640
#include"bits/stdc++.h"
using namespace std;
#define LL long long

LL N,M,K,ans,r,t,a;

string s,f;
int main() {
	cin >> N>>M;
	if (N < M)cout << 0 << endl;
	else cout << 10<<endl;

	return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string.h>
#include<complex>
using namespace std;
typedef long long int llint;

int main(){
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int x;
	if (a < b){
		x = a;
		a = b;
		b = x;
	}
	if (a < c){
		x = a;
		a = c;
		c = x;
	}
	for (int i = 0; i < k; i++){
		a *= 2;
	}
	cout << a + b + c << endl;
}

Measured memory_bytes: 256
import sys
import math
Q = sys.stdin.readline()
for _ in range(int(Q)):
    cnt = 0
    N = int(sys.stdin.readline())
    if N != 0:
        digLeng = int(math.log10(N)) + 1
    else:
        digLeng = 1
    while digLeng > 1:
        Nmax = 0
        for dig in range(digLeng):
            lNum = N // int(math.pow(10,dig))
            rNum = N % int(math.pow(10,dig))
            Nmax = max(Nmax,lNum * rNum)
        N = Nmax
        cnt += 1
        if N != 0:
            digLeng = int(math.log10(N)) + 1
        else:
            digLeng = 1
    print(cnt)

Measured memory_bytes: 6836
#include<bits/stdc++.h>
using namespace std;
int h,w;
int mas[91][91];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int dfs(int y,int x,int ans){
  int a=ans;
  for(int i=0;i<4;i++){
    int ny=y+dy[i];
    int nx=x+dx[i];
    if(0<=ny && ny<h && 0<=nx && nx<w && mas[ny][nx]==1){
      mas[ny][nx]=0;
      a=max(a,dfs(ny,nx,ans+1));
      mas[ny][nx]=1;
    }
  }
  return a;
}

int main(){
  while(1){
    cin>>w>>h;
    if(w==0 && h==0) break;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin>>mas[i][j];
      }
    }
    int ans=0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(mas[i][j]==1){
	  mas[i][j]=0;
	  ans=max(ans,dfs(i,j,1));
	  mas[i][j]=1;
	}
      }
    }
    
    cout<<ans<<endl;
    
  }
  return 0;
}

  

Measured memory_bytes: 1192
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

using namespace std;
#define int long long


class AApplePie {
public:
    void solve(std::istream &in, std::ostream &out) {
      int a, p;
      in >> a >> p;
      p += a * 3;
      int ans = 0;
      while (p >= 2) {
        ans++;
        p -= 2;
        p = max(0ll, p);
      }
      out << ans << endl;
    }
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
  AApplePie solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

ll moP(ll x, ll n) {
  ll res=1;
  while(n>0) {
    if(n&1) moC(res, *, x);
    moC(x, *, x);
    n>>=1;
  }
  return res;
}

ll fa[MAX*4], rf[MAX*4];

ll C(ll n, ll k) {
  if(k==0) return 1;
  if(n==k) return 1;
  return fa[n]*rf[k]%MOD*rf[n-k]%MOD;
}

int main(void) {
  ll N, K;
  cin >> N >> K;
  ll i;
  
  fa[0]=rf[0]=1;
  for(ll i=1; i<=400040; i++) {
    fa[i]=fa[i-1]*i%MOD;
    rf[i]=moP(fa[i], MOD-2);
  }
  
  if(N-1<=K) {
    pt(C(N+N-1, N));
    return 0;
  }
  
  ll ans=1;
  //i:0人の部屋の数
  for(i=0; i<=K; i++) {
    moC(ans, +, C(N, i)*C(N-1, N-i-1)%MOD);
    //pt(C(N, i)*C(N, N-i-1));
  }
  
  pt(ans-1);
}








Measured memory_bytes: 6528
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	string s;
	cin>>n>>s;
	int l=s.length();
	for(int i=0;i<l;i++)
	{
		s[i]=(((s[i]-'A')+n)%26)+'A';
	}
	cout<<s;
}

Measured memory_bytes: 256
//BISMILLAH
#include <bits/stdc++.h>
using namespace std;
#define sz 100007
long long int n;
long long int a[sz],b[sz],c[sz];
long long int dp[sz][4];
  long long int solve(long long int i,long long int fl){
      if(i == n) return 0;
      if(dp[i][fl] != -1) return dp[i][fl];
      long long int x = 0;
      if(fl == 0){
          x = max(x,a[i] + solve(i+1,1));
           x = max(x,b[i] + solve(i+1,2));
           x = max(x,c[i] + solve(i+1,3));
      }
      else if(fl == 1){
          x = max(x,b[i] + solve(i+1,2));
          x = max(x,c[i] + solve(i+1,3));
      }
      else if(fl == 2){
          x = max(x,a[i] + solve(i+1,1));
          x = max(x,c[i] + solve(i+1,3));
      }
      else if(fl == 3){
          x = max(x,a[i] + solve(i+1,1));
          x = max(x,b[i] + solve(i+1,2));
      }
      dp[i][fl] = x;
      return dp[i][fl];
  }
int main(){
    
    memset(dp,-1,sizeof(dp));
    
    long long int i,j;
    
    cin >> n;
    for(i = 0;i<n;i++){
        cin >> a[i] >> b[i] >> c[i];
    }
       cout << solve(0,0) << endl;
    return 0;
}

Measured memory_bytes: 16848
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main()
{
    int N, K;
    cin >> N >> K;
    int A[N];
    int index = 0;
    for(int i = 1; i < N;i++)
    {
        cin >> A[i];
        if (A[i] == 1)
        {
            index == i;
        }
    }
    //cout << index << endl;
    int ans = 0;
    int q = index / (K - 1);
    int r = index % (K - 1);
    if (r > 0) ++q;
    //cout << q << endl;
    ans += q;
    q = (N - index - 1) / (K - 1);
    r = (N - index - 1) % (K - 1);
    //cout << q << r << endl;
    if (r > 0) ++q;
    ans += q;
    //cout << q << endl;
    cout << ans << endl;   
    return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;
class Daikei
{
public:
    int a;
    int b;
    int h;
    int Ans;
    
    void daikei(){
        Ans = (a + b)* h * 0.5;
    };
    
};



int main(int argc, const char * argv[]) {
    
    Daikei practice;
    cin >>practice.a;
    cin >>practice.b;
    cin >>practice.h;
    
    practice.daikei();

    std::cout << practice.Ans;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<int> a(3*n); REP(i, 3*n) cin >> a[i];
  priority_queue<int, vector<int>, greater<int> > left;
  long long tmp = 0;
  REP(i, n) {
    left.push(a[i]);
    tmp += a[i];
  }
  vector<long long> left_sum(n+1);
  left_sum[0] = tmp;
  REP(i, n) {
    if (left.top() < a[n+i]) {
      tmp -= left.top();
      left.pop();
      tmp += a[n+i];
      left.push(a[n+i]);
    }
    left_sum[i+1] = tmp;
  }
  reverse(ALL(a));
  priority_queue<int> right;
  tmp = 0;
  REP(i, n) {
    right.push(a[i]);
    tmp += a[i];
  }
  vector<long long> right_sum(n+1);
  right_sum[0] = tmp;
  REP(i, n) {
    if (right.top() > a[n+i]) {
      tmp -= right.top();
      right.pop();
      tmp += a[n+i];
      right.push(a[n+i]);
    }
    right_sum[i+1] = tmp;
  }
  long long ans = -LINF;
  REP(i, n+1) ans = max(ans, left_sum[i] - right_sum[n-i]);
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3960
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/input.txt"
exit $?
'''
import sys

def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    n, m = _ia()
    ret = []
    if n % 2 == 1:
        ai, bi = 1, n
        for _ in range(m):
            ret.append(f"{ai} {bi}")
            ai+=1
            bi-=1
    else:
        ai = n // 2
        bi = ai + 1
        for _ in range(n//4):
            ret.append(f"{ai} {bi}")
            ai -= 1
            bi += 1

        rept = n - bi
        ai, bi = 1, n - 1
        for _ in range(rept):
            ret.append(f"{ai} {bi}")
            ai += 1
            bi -= 1

    return "\n".join(ret[:m])


if __name__ == "__main__":
    print(main())


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

int main() {
  int N;
  cin >> N;
  
  if (N < 2) {
    cout << 1 <<endl;
  }
  else if (N < 4) {
    cout << 2 <<endl;
  }
  else if (N < 8) {
    cout << 4 <<endl;
  }
  else if (N < 16) {
    cout << 8 <<endl;
  }
  else if (N < 32) {
    cout << 16 <<endl;
  }
  else if (N < 64) {
    cout << 32 <<endl;
  }
  else {
    cout << 64 <<endl; 
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
typedef long long ll;
typedef pair<int, int> P;
typedef struct{
  int first;
  int second;
  int third;
}T;

//昇順
bool comp_Se(T& l, T& r){
  return l.second < r.second;
}

vector<int> diff(int a, int b, int n){
  if(n==1) return (vector<int>) {a,b};
  int n_2 = pow(2,n);
  int n_2_ = pow(2,n-1);
  int digit;
  for(digit = 1; digit<n_2;digit*=2){
    if((a&digit) != (b&digit)) break;
  }
  int a_ = a&digit, b_ = b&digit;
  int A = a%digit + (a/(digit*2))*(digit);
  int B = b%digit + (b/(digit*2))*(digit);
  int C = A^1;
  vector<int> l = diff(A,C,n-1);
  vector<int> r = diff(C,B,n-1);
  int i;
  vector<int> L(n_2);
  REP(i,n_2){
   if(i<n_2_){
     L[i] = l[i]%digit + (l[i]/digit)*2*digit + a_;
   }else{
     L[i] = r[i-n_2_]%digit + (r[i-n_2_]/digit)*2*digit + b_;
   }
  }
  return L;
}

int N;

int main(void){
  int A,B;
  int n_A=0,n_B=0;
  cin >> N >> A >> B;
  int N_2 = pow(2,N);
  int digit;
  for(digit=1; digit < N_2; digit*=2){
    if(A&digit)n_A++;
    if(B&digit)n_B++;
  }
  if(abs(n_A-n_B)%2){
    cout << "YES" << endl;
    vector<int> l = diff(A,B,N);
    int i;
    REP(i,l.size()) cout << l[i] << " ";
    cout << endl;
  }else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 1648