akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(){

  int i = 1;
  while(1){
    int x; cin >> x;
    if(x == 0) break;
    cout << "Case " << i << ":" << " " << x << '\n';
    i++;
  }

  return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#define _USE_MATH_DEFINES
#include <cmath>

using namespace std;

void solve()
{
	int m;
	while(cin >>m, m)
	{
		double angle_remain1 = 360;
		double angle1;
		double sum1 = 0;
		for(int i = 1; i < m; ++i)
		{
			cin >> angle1;
			angle_remain1 -= angle1;
			sum1 += sin(angle1 / 180 * M_PI);
		}
		sum1 += sin(angle_remain1 / 180 * M_PI);
		int n;
		cin >> n;
		double angle_remain2 = 360;
		double angle2;
		double sum2 = 0;
		for(int i = 1; i < n; ++i)
		{
			cin >> angle2;
			angle_remain2 -= angle2;
			sum2 += sin(angle2 / 180 * M_PI);
		}
		sum2 += sin(angle_remain2 / 180 * M_PI);
		if(fabs(sum1 - sum2) < 0.000000001)
		{
			cout << 0 << endl;
		}
		else if(sum1 > sum2)
		{
			cout << 1 << endl;
		}
		else if(sum1 < sum2)
		{
			cout << 2 << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
#pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define test(s) \
  if (!(s))     \
    cout << "Line " << __LINE__ << ": [" << #s << "] is false" << endl;
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
#pragma endregion

signed main() {
  int A, V;
  cin >> A >> V;
  int B, W;
  cin >> B >> W;
  int T;
  cin >> T;


  int D = abs(A - B);
  int VV = V - W;

  bool ok = T * VV >= D;
  if (ok)
    cout << "YES\n";
  else
    cout << "NO\n";
}

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

int main()
{
	int x,i;

	i = 0;
	
	while (true)
	{
		cin >> x;
		if (x==0)
		{
			break;
		}

		i++;
		cout<<"Case "<< i <<": "<< x << endl;
	}
	
	return 0;
}



Measured memory_bytes: 2996
def rec(S, i):
    if len(S) < i+1:
        return [S]
    # add + dont add
    return rec(S[:i] + "+" + S[i:], i+2) + rec(S, i+1) + [S[:i] + "+" + S[i:], S]


S = raw_input()
print sum([eval(s) for s in list(set(rec(S, 1)))])


Measured memory_bytes: 2692
#include<iostream>

int main()
{
    char a[3][3];
    for(int i=0; i<3; i++)
    {
        for(int j=0; j<3; j++)
        {
            std::cin >> a[i][j];
        }
    }
    std::cout << a[0][0] << a[1][1] << a[2][2] << std::endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
void InsertSort(int arr[], int n);
void Print(int arr[], int n, bool flag = true)
{
	for (int i = 0; i != n - 1; ++i)
	{
		printf("%d ", arr[i]);
	}
	printf("%d", arr[n - 1]);
	if (flag)
		printf("\n");
}
int main(void)
{
	int N;
	int arr[105];
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	cin >> N;
	for (int i = 0; i != N; ++i)
		scanf("%d", &arr[i]);
	InsertSort(arr, N);
	//system("pause");
	return 0;
}

void InsertSort(int arr[], int n)
{
	
	for (int i = 1; i < n; ++i)
	{
		Print(arr, n);
		int j = i - 1, elem = arr[i];
		while (arr[j] > elem && j >= 0)
		{
			arr[j + 1] = arr[j];
			--j;
		}
		arr[j + 1] = elem;
	}
	Print(arr, n);
}

Measured memory_bytes: 3196
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, c = LS()
    if a[-1] == b[0] and b[-1] == c[0]:
        print("YES")
    else:
        print("NO")
    return

#B
def B():
    a, b, c = LI()
    for i in range(1, b):
        if a * i % b == c:
            print("YES")
            return
    print("NO")
    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()


Measured memory_bytes: 38512
s=input()

l=[0]
ans=[0]*(len(s))
for i in range(len(s)-1):
    if s[i]=="L" and s[i+1]=="R":
        l.append(i+1)
       
n=len(l)+1
l.append(len(s))
#print(set(s[l[0]:l[1]]))

for i in range(n-1):
    #print(s[l[i]:l[i+1]])
    for j in range(len(s[l[i]:l[i+1]])-1):
        p=len(s[l[i]:l[i+1]])
        if s[l[i]]=="L":
            ans[l[i]]=p
            break
        if s[l[i+1]-1]=="R":
            ans[l[i+1]-1]=p
            break
        if s[l[i]:l[i+1]][j]=="R" and s[l[i]:l[i+1]][j+1]=="L":
            if j%2==1:
                ans[l[i]+j]=p//2
                ans[l[i]+j+1]=p-p//2
                break
            else:
                ans[l[i]+j]=p-p//2
                ans[l[i]+j+1]=p//2
                break
print(*ans)


            
  


Measured memory_bytes: 8260
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod=1e9+7;
const int INF=1001001001;

int main() {
  int K,S;
  cin>>K>>S;
  int cnt=0;
  for(int x=0;x<=K;x++){
    for(int y=0;y<=K;y++){
      int z=S-x-y;
      if(z>=0&&z<=K){cnt++;}
    }
  }
  cout<<cnt<<endl;
  return 0;  
}

Measured memory_bytes: 3600
n, m = [int(i) for i in input().split()]
count=0
list=list([])
while count < n:
    list.append([int(i) for i in input().split()])
    count+=1
count=0
amount=0
for l in sorted(list):
    c = l[1] if m-count>l[1] else m-count
    amount += l[0]*c
    count += c
    if count == m:
        break
print(amount)


Measured memory_bytes: 22380
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve(){
	int n;
	cin >> n;
	map<int, int> A, B, Merge;
	rep(i,n){
		int a;
		cin >> a;
		++A[a];
		++Merge[a];
	}
	rep(i,n){
		int b;
		cin>> b;
		++B[b];
		++Merge[b];
	}
	vector<P> cnter;
	for(auto x : Merge){
		if(x.second > n){
			cout << "No" << endl;
			return;
		}
		cnter.push_back(P(x.second, x.first));
	}
	sort(cnter.rbegin(), cnter.rend());
	vector<P> Left, Rights(n, P(-1, -1));
	int itr_zero = 0, itr_one = 0;
	rep(i,cnter.size()){
		rep(q,A[cnter[i].second]){
			if(Left.size() != n){
				Left.push_back(P(cnter[i].second, 0));
			}
			else{
				while(Left[itr_one].second == 0) itr_one++;
				Rights[itr_one++] = P(cnter[i].second, 0);
			}
		}
		rep(q,B[cnter[i].second]){
			if(Left.size() != n){
				Left.push_back(P(cnter[i].second, 1));
			}
			else{
				while(Left[itr_zero].second == 1) itr_zero++;
				Rights[itr_zero++] = P(cnter[i].second, 1);
			}
		}
	}
	vector<P> ans;
	rep(i,Left.size()){
		if(Left[i].second == 1) swap(Left[i], Rights[i]);
		ans.emplace_back(Left[i].first, Rights[i].first);
	}
	sort(ans.begin(), ans.end());
	cout << "Yes" << endl;
	rep(i,n) cout << ans[i].second << " ";
	cout << endl;
}

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


Measured memory_bytes: 39076
S = input()
T = ''
U = ['dreamer', 'dream', 'eraser', 'erase']
answer = 'NO'
list = [T]
done = 0

while done == 0:
    for l in list:
        list.remove(l)
        for u in U:
            if S.startswith(l + u):
                if S == l + u:
                    answer = 'YES'
                    done = 1
                list.append(l + u)
    if list == []:
        done = 1
print(answer)

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

int main() {
  int A , B , C , D ;
  cin >> A >> B >> C >> D ;

  if (A+B > C+D) {
    cout << "Left" << endl;
  }
 else if (A+B == C+D) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

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

using namespace std;
int v[200002];
int main()
{
    int n;
    long long cnt=0;
    cin>>n;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        if(i+x<n){
            v[i+x]++;
        }
        if(i-x>=0){
            if(v[i-x]!=0){
                cnt+=v[i-x];
            }
        }
    }
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 4408
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    string s; cin>>s;
    int ans=0;
    for(int i=s.size()/2-1;i>=1;i--){
        for(int j=0;j<i;j++){
            if(s[j]!=s[j+i]) break;
            if(j==i-1){
                ans=i*2; goto last;
            }
        }
    }
    last:
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

H = int(sys.stdin.buffer.readline())
ans = 2**H.bit_length() - 1
print(ans)


Measured memory_bytes: 25316
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

long long MOD = 1e9+7;
int MAX_INT = 1e9;

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

  int X, Y;
  cin >> X >> Y;

  int get_price_code = X < 4 ? (4 - X) * 100000 : 0;
  int get_price_implement = Y < 4 ? (4 - Y) * 100000 : 0;
  int won_both = (X == 1 && Y == 1 ? 400000 : 0);

  cout << get_price_code + get_price_implement + won_both << endl;

  return 0;
}


Measured memory_bytes: 3640
// ---------- begin SegmentTree Range update Point query ----------
mod segment_tree {
    pub struct RUPQ<T, F> {
        n: usize,
        b: usize,
        a: Vec<T>,
        id: T,
        op: F,
    }
    impl<T: Copy, F: Fn(T, T) -> T> RUPQ<T, F> {
        pub fn new(n: usize, id: T, op: F) -> RUPQ<T, F> {
            let mut k = 0;
            while (1 << k) < n {
                k += 1;
            }
            RUPQ {
                n: 1 << k,
                b: k,
                a: vec![id; 2 << k],
                id: id,
                op: op,
            }
        }
        fn down(&mut self, x: usize) {
            let k = x + self.n;
            let a = &mut self.a;
            for i in (1..(self.b + 1)).rev() {
                let y = k >> i;
                a[2 * y] = (self.op)(a[2 * y], a[y]);
                a[2 * y + 1] = (self.op)(a[2 * y + 1], a[y]);
                a[y] = self.id;
            }
        }
        pub fn update(&mut self, mut l: usize, mut r: usize, v: T) {
            self.down(l);
            self.down(r - 1);
            l += self.n;
            r += self.n;
            let a = &mut self.a;
            while l < r {
                if (l & 1) == 1 {
                    a[l] = (self.op)(a[l], v);
                    l += 1;
                }
                if (r & 1) == 1 {
                    r -= 1;
                    a[r] = (self.op)(a[r], v);
                }
                l >>= 1;
                r >>= 1;
            }
        }
        pub fn find(&mut self, mut x: usize) -> T {
            x += self.n;
            let mut y = self.a[x];
            x >>= 1;
            while x > 0 {
                y = (self.op)(y, self.a[x]);
                x >>= 1;
            }
            y
        }
    }
}
// ---------- end SegmentTree Range update Point query ----------

use proconio::*;

fn run() {
    input! {
        n: usize,
        q: usize,
        ask: [(u8, usize); q],
    }
    let mut ans = (n - 2).pow(2);
    let mut row = segment_tree::RUPQ::new(n + 2, std::usize::MAX, |a, b| std::cmp::min(a, b));
    let mut col = segment_tree::RUPQ::new(n + 2, std::usize::MAX, |a, b| std::cmp::min(a, b));
    for i in 2..n {
        row.update(i, i + 1, n - 2);
        col.update(i, i + 1, n - 2);
    }
    for (op, x) in ask {
        if op == 1 {
            let v = row.find(x);
            ans -= v;
            col.update(0, 3 + v, x - 2);
        } else {
            let v = col.find(x);
            ans -= v;
            row.update(0, 3 + v, x - 2);
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


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

const int KMAX = 1000;
int black[3*KMAX][3*KMAX];
int white[3*KMAX][3*KMAX];

int getAcc(int acc[][3*KMAX], int x, int y, int K){
    x += K-1;
    y += K-1;
    int ret = acc[x][y];
    if(x-K >= 0) ret -= acc[x-K][y];
    if(y-K >= 0) ret -= acc[x][y-K];
    if(x-K >= 0 && y-K >= 0) ret += acc[x-K][y-K];
    return ret;
}

void go(int acc[][3*KMAX], int K){
    for(int i=0;i<3*K;i++) for(int j=0;j<3*K;j++){
        if(i>0) acc[i][j] += acc[i-1][j];
        if(j>0) acc[i][j] += acc[i][j-1];
        if(i>0 && j>0) acc[i][j] -= acc[i-1][j-1];
    }
}

char buff[11];

int main(){
    int N, K; scanf("%d%d",&N,&K);
    for(int i=0;i<N;i++){
        int x, y; scanf("%d%d%s", &x, &y, buff);
        x %= 2*K, y %= 2*K;

        auto target = (buff[0]=='W' ? white : black);
        target[x][y]++;
        if(x+2*K < 3*K) target[x+2*K][y]++;
        if(y+2*K < 3*K) target[x][y+2*K]++;
        if(x+2*K < 3*K && y+2*K < 3*K) target[x+2*K][y+2*K]++;
    }

    go(black, K), go(white, K);

    int ans = 0;
    for(int i=0;i<K;i++) for(int j=0;j<K;j++){
        int cur1
            = getAcc(white, i, j, K)
            + getAcc(white, i+K, j+K, K)
            + getAcc(black, i+K, j, K)
            + getAcc(black, i, j+K, K);

        int cur2
            = getAcc(black, i, j, K)
            + getAcc(black, i+K, j+K, K)
            + getAcc(white, i+K, j, K)
            + getAcc(white, i, j+K, K);

        ans = max({ans, cur1, cur2});
    }

    printf("%d", ans);
}


Measured memory_bytes: 70528
#include "bits/stdc++.h"
using namespace std;

#define fi first
#define se second
#define pb push_back
//#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

//const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 1005;

int ctr;
int n, m;
int cx, cy;
int dx, dy;
char s[N][N];
int a[N][N];
int cc[N][N];
int st, en;

vector<int> vis(1000001);
vector<int> g[1000001];

void go(int x, int y) {
    cc[x][y] = ctr;
    if (x == cx and y == cy) st = ctr;
    if (x == dx and y == dy) en = ctr;
    if (x + 1 <= n and s[x + 1][y] == '.' and !cc[x + 1][y]) go(x + 1, y);
    if (y + 1 <= m and s[x][y + 1] == '.' and !cc[x][y + 1]) go(x, y + 1);
    if (x - 1 >= 1 and s[x - 1][y] == '.' and !cc[x - 1][y]) go(x - 1, y);
    if (y - 1 >= 1 and s[x][y - 1] == '.' and !cc[x][y - 1]) go(x, y - 1);
}

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    cin >> n >> m;
    cin >> cx >> cy;
    cin >> dx >> dy;
    
    for (int i = 1; i <= n; i++) {
        cin >> (s[i] + 1);
    }
    
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (s[i][j] == '#' or cc[i][j]) continue;
            ++ctr;
            go(i, j);
        }
    }
    
    if (st == 0 or en == 0) {
        cout << "-1";
        return 0;
    }
    
    if (st == en) {
        cout << "0";
        return 0;
    }
    
    map<pii, bool> done;
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++) {
            if (s[i][j] == '#') continue;
            for (int ii = -2; ii <= 2; ii++) {
                for (int jj = -2; jj <= 2; jj++) {
                    if (1 <= i - ii and i - ii <= n and 1 <= j - jj and j - jj <= m and cc[i][j] != cc[i - ii][j - jj] and cc[i - ii][j - jj]) {
                        int x = cc[i][j];
                        int y = cc[i - ii][j - jj];
                        if (done[{x, y}]) continue;
                        g[x].pb(y);
                        done[{x, y}] = 1;
                    }
                }
            }
        }
    }
    
    //for (int i = 1; i <= n; i++) {
        //for (int j = 1; j <= m; j++) {
            //cout << cc[i][j] << " ";
        //}
        //cout << "\n";
    //}
    
    //for (int i = 1; i <= 5; i++) {
        //cout << "g[" << i << "]: ";
        //for (int j: g[i]) {
            //cout << j << " ";
        //}
        //cout << "\n";
    //}
    
    queue<pii> Q;
    Q.push({st, 0});
    vis[st] = 1;
    
    while (!Q.empty()) {
        pii p = Q.front();
        if (p.fi == en) {
            cout << p.se;
            return 0;
        }
        Q.pop();
        
        for (int y: g[p.fi]) {
            if (!vis[y]) {
                vis[y] = 1;
                Q.push({y, p.se + 1});
            }
        }
    }
    
    cout << "-1";
}


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

int main() {
   int n, k;
   cin >> n;
   int count = 0; 
   k = n / 7;
   for (int i = 0; i < k + 1; i++) {
      if ((n-7*i)%4 == 0) count++;
   }
   if (count != 0) cout << "Yes" << endl;
   else cout << "No" << endl;

   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main()
{
    int n,k;
    cin >> n >> k;
    cout << ((n+1)/2 >= k ? "YES" : "NO") << endl;
    return 0;
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if ((A == B && B != C) || (B == C && C != A) || (C == A && A != B)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll mod=998244353;
int main(void){
  ll n,k; cin>>n>>k;
  vector<int> l(k),r(k);
  for(int i=0; i<k; ++i) cin>>l[i]>>r[i];
  vector<ll> dp(n,0),sdp(n+1,0);
  dp[0]=sdp[1]=1;
  for(int i=1; i<n; ++i){
    for(int j=0; j<k; ++j){
      ll left=max(0,i-r[j]);
      ll right=max(0,i-l[j]+1);
      dp[i]=dp[i]+sdp[right]-sdp[left];
      if(dp[i]>=mod) dp[i]-=mod; else if(dp[i]<0) dp[i]+=mod;
    }
    sdp[i+1]=(sdp[i]+dp[i])%mod;
  }
  cout<<dp[n-1];
  return 0;
}

Measured memory_bytes: 6296
#include <stdio.h>

int main(void)
{
	int a, b, c, d;
	int p;
	int com_x, com_y;
	
	scanf("%d %d %d %d %d", &a, &b, &c, &d, &p);
	
	com_x = a * p;
	
	if (c >= p){
		com_y = b;
	}
	else if (c < p){
		com_y = b + (p - c) * d;
	}
	
	if (com_x < com_y){
		printf("%d\n", com_x);
	}
	else {
		printf("%d\n", com_y);
	}
	
	return (0);
}

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

int main(){
    int a,b;
    cin >> a >> b;
    if(a%3 == 0 || b%3 == 0 || (a+b)%3 == 0) puts("Possible");
    else puts("Impossible");
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll n;
string s;
ll dp[300010][3][2][3];

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

  cin>>s;
  n=s.size();
  dp[0][0][0][0]=1;
  rep(i,n)rep(j,3)rep(k,2)rep(l,3){
    if(dp[i][j][k][l]==0)continue;
    // dbg(i); dbg(j); dbg(k); dbg(l); dbg(dp[i][j][k][l]);
    if(s[i]=='1'||s[i]=='?'){
      if(j==0){
        if(l==0){
          if(k==0){
            (dp[i+1][0][1-k][l+1]+=dp[i][j][k][l])%=mod;
          }else{
            (dp[i+1][0][1-k][l]+=dp[i][j][k][l])%=mod;
          }
        }else if(l==1){
          if(k==1){
            (dp[i+1][0][1-k][l+1]+=dp[i][j][k][l])%=mod;
          }else{
            (dp[i+1][0][1-k][l]+=dp[i][j][k][l])%=mod;
          }
        }else if(l==2){
          (dp[i+1][0][1-k][l]+=dp[i][j][k][l])%=mod;
        }
      }if(j==1){
        (dp[i+1][0][k][l]+=dp[i][j][k][l])%=mod;
      }else if(j==2){
        (dp[i+1][0][1-k][l]+=dp[i][j][k][l])%=mod;
      }
    }
    if(s[i]=='0'||s[i]=='?'){
      if(j==0||j==2) (dp[i+1][1][k][l]+=dp[i][j][k][l])%=mod;
      else (dp[i+1][2][k][l]+=dp[i][j][k][l])%=mod;
    }
  }
  ll res=0;
  rep(j,3)rep(k,2)(res+=dp[n][j][k][2])%=mod;
  (res+=dp[n][0][1][1])%=mod;
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 42900
#include<bits/stdc++.h>
using namespace std;
int main(){
 int n;
  cin>>n;
  vector<long long > arr(n);
 long long  ans=1;
  for(int i=0;i<n;i++){
   cin>>arr[i];
  }
  sort(arr.begin(),arr.end());
  long long g=pow(10,18);
  for(int i=0;i<n;i++){
    if(arr[i]!=0&&ans>g/arr[i])
    {
      ans=-1;
      break;
    }
    if(ans==0)
      break;
    ans=ans*arr[i];
  }
  cout<<ans<<"\n";
}

Measured memory_bytes: 3976
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int a[105];
int cnt;
int main()
{
    int n,d,x;
    cin>>n>>d>>x;
    for(int i=0;i<n;i++){
        cin>>a[i];
        for(int j=1;j<=d;j+=a[i])
            cnt+=1;
    }
    cnt+=x;
    cout<<cnt;    
system("pause");
return 0;
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll dp[10000005];
int main()
{
    ll n;
    cin >> n;
    for(ll i=1;i<=n;i++)
    {
        dp[i]=1;
    }
    for(ll x=2;x<=n;x++)
    {
        if(dp[x]!=1)
        {
            continue;
        }
        for(ll u=x+x;u<=n;u+=x)
        {
            ll count=0;
            ll temp=u;
            while(temp%x==0)
            {
                temp/=x;
                count++;
            }
            dp[u]*=(count+1);
        }
        
    }
    ll ans=1;
    for(ll i=2;i<=n;i++)
    {
        if(dp[i]==1)
        {
            dp[i]++;
        }
        ans+=(dp[i]*i);
    }
    cout << ans;

}


Measured memory_bytes: 81752
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

#define INF LLONG_MAX / 5
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define enld endl

signed main() {
	int N;
	cin >> N;
	vector<double>p(N);
	rep(i, N) {
		cin >> p[i];
	}
	vector<vector<double>>dp(N + 1, vector<double>(2 * N + 3));
	rep(i, N + 1) {
		for (int j = (-1) * N; j <= N; j++) {
			if (i == 0) {
				if (j == 0) {
					dp[i][N+1+j] = 1;
				}
				else {
					dp[i][N+1+j] = 0;
				}
			}
			else {
				dp[i][N + 1 + j] = dp[i - 1][N + j] * (1 - p[i - 1]) + dp[i - 1][N + 2 + j] * p[i - 1];
			}
		}
	}

	/*
	rep(i, N + 1) {
		for (int j = (-1) * N; j <= N; j++) {
			cout << dp[i][N + 1 + j] << ' ';
		}
		cout << endl;
	}
	*/

	
	double ans = 0;
	rep(i, N + 1) {
		for (int j = (-1) * N; j <= N; j++) {
			if (i == N && j < 0) {
				ans += dp[i][N + 1 + j];
			}
		}
	}
	cout << fixed << setprecision(20) << ans << endl;
	//cout << ans << endl;
	
}

Measured memory_bytes: 144040
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
    double tmp[3],a,b,mini,n;
    while(true){
        for(int i=0;i<3;i++){
            cin >> tmp[i];
            if(tmp[2] == 0 && tmp[1] == 0 && tmp[2] == 0) return 0;
        }
        sort(tmp,tmp+3); a = tmp[0]; b = tmp[1];
        mini = sqrt(a*a+b*b);
        cin >> n;
        while(n--){
            cin >> a;
            cout << ((a*2 > mini)? "OK" : "NA") << endl;
        }
    }
}

Measured memory_bytes: 1232
from collections import deque
n,q=map(int, input().split())
l=[[] for i in range(n+1)]
ans=[0]*(n+1)

for i in range(n-1):
    a,b=[int(j) for j in input().split()]
    l[a].append(b)
    l[b].append(a)
for i in range(q):
    p,x=[int(j) for j in input().split()]
    ans[p]+=x

que=deque()
que.append(1)
ll=[0]*(n+1)
while que:
    y=que.popleft()
    ll[y]=1
    for i in l[y]:
        if ll[i]==1:
            continue
        ans[i]+=ans[y]
        que.append(i)
print(*ans[1:])

Measured memory_bytes: 56156
import sys

N, X, Y = map(int, sys.stdin.readline().split())

ans = [0] * (N-1)
for i in range(1, N):
    for j in range(i+1, N+1):
        k = min((j - i, abs(X - i) + 1 + abs(j - Y), abs(X - j) + 1 + abs(i - Y)))
        # print(k)
        ans[k-1] += 1

# print(ans)
for i in range(N-1):
    print(ans[i])

Measured memory_bytes: 9348
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL;
int n,tot=0,f1[200001],f2[200001],w[200001],head[200001];
LL ans=0,min0=1e18;
struct data {
	int next,num;
	LL w;
}edge[200001];
void add(int u,int v,int w) {
	edge[++tot].next=head[u];
	edge[tot].num=v;
	edge[tot].w=w;
	head[u]=tot;
}
void dfs(int x,int fa) {
	w[x]=1;
	f1[x]=f2[x]=0;
	for (int i=head[x];i!=-1;i=edge[i].next) {
		int kx=edge[i].num;
		if (kx==fa) continue;
		dfs(kx,x);
		if (w[kx]>f1[x]) {
			f2[x]=f1[x];
			f1[x]=w[kx];
		}
		else if (w[kx]>f2[x]) f2[x]=w[kx];
		ans+=2ll*edge[i].w*min(w[kx],n-w[kx]);
		w[x]+=w[kx];
	}
}
void dfs2(int x,int fa) {
	for (int i=head[x];i!=-1;i=edge[i].next) {
		int kx=edge[i].num;
		if (kx==fa) continue;
		dfs2(kx,x);
		if (w[kx]>n-w[kx]) {
			int nowk=(w[kx]*2-n)/2;
			if (w[kx]-f1[kx]-1<nowk) continue;
			min0=min(min0,edge[i].w);
		}
		else {
			int nowk=(n-w[kx]*2)/2;
			int max0=f1[x];
			if (f1[x]==w[kx]) max0=f2[x];
			if (n-w[x]>max0) max0=n-w[x];
			max0=n-w[kx]-max0-1;
			if (max0<nowk) continue;
			min0=min(min0,edge[i].w);
		}
	}
}
int main() {
	memset(head,-1,sizeof(head));
	scanf("%d",&n);
	for (int i=1;i<n;i++) {
		int u,v,w;
		scanf("%d%d%d",&u,&v,&w);
		add(u,v,w);
		add(v,u,w);
	}
	dfs(1,-1);
	dfs2(1,-1);
	printf("%lld\n",ans-min0);
	return 0;
}

Measured memory_bytes: 11648
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
using VB = vector<bool>;
using VVB = vector<VB>;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
	//i=m -> n-1(昇順)
#define RREP(i,m,n) for(int i=(m);i>=(n);i--)
	//i=m -> n(降順)

int n,m,q,ans=0;

void dfs(int s, VI &A, VVI &info){
  if(A.size() == n){
    int cnt = 0;
    REP(i,0,q){
      if(A[info[i][1]] - A[info[i][0]] == info[i][2]){
        cnt += info[i][3];
      }
    }
    ans = max(ans,cnt);
    A.pop_back();
  }
  else{
    REP(i,s,m+1){
      A.push_back(i);
      dfs(i,A,info);
    }
    if(!A.empty()){A.pop_back();}
  }
}

int main(){
  cin >> n >> m >> q;
  VVI info(q, VI(4));
  REP(i,0,q){
    cin >> info[i][0] >> info[i][1] >> info[i][2] >> info[i][3];
    info[i][0]--;
    info[i][1]--;
  }
  
  VI A(0);
  
  dfs(1,A,info);
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3648
a, b, c, x = [int(input()) for i in range(4)]

cnt = 0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if i * 500 + j * 100 + k * 50 == x:
        cnt += 1
        
print(cnt)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vpi = vector<pii>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpl = vector<pll>;
using vs = vector<string>;

int main()
{
    int n;
    cin >> n;
    vi as;
    as.resize(n-1);
    for(int i=0; i<n-1; i++) cin >> as.at(i);
    vi nums(n, 0);
    for(auto a : as)
    {
        nums.at(a-1)++;
    }
    for(auto num : nums)
    {
        cout << num << endl;
    }
    return 0;
}


Measured memory_bytes: 4776
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f

using namespace std;
typedef long long ll;
typedef vector <int> vec;
typedef pair <int,int> Pair;
struct Node
{
	int s,t;
	Node(){}
	Node(int a,int b)
	{
		s=a;
		t=b;
	}
	bool operator <(const Node &A) const
	{
		return s<A.s or(s==A.s and t<A.t);
	}
	bool operator >(const Node &A) const
	{
		return s>A.s or(s==A.s and t>A.t);
	}
};
priority_queue <Node,vector<Node>,greater<Node> > q;
int n,m;
void Init()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		q.push(Node(a,b));
	}
}
int res;
void Solve()
{
	while(q.size()>1)
	{
		Node p1=q.top();
		q.pop();
		Node p2=q.top();
		q.pop();
		if(p1.t>p2.s)
		{
			q.push(Node(max(p1.s,p2.s),min(p1.t,p2.t)));
		}
		else
		{
			res++;
			q.push(p2);
		}
	}
	printf("%d\n",res+1);
}
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
	Init();
	Solve();
	return 0;
}


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

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

    int n, m;
    cin >> n >> m;
    vector<int> A(n);
    REP(i, n) cin >> A[i];

    vector<long long> B(n + 1);
    B[0] = 0;
    REP(i, n){
        if(i > 0) B[i + 1] = (B[i] + A[i]) % m;
        else B[i + 1] = A[i] % m;
    }

    unordered_map<long long, long long> mp;
    REP(i, n + 1){
        mp[B[i]]++;
    }

    long long ans = 0;
    for(auto x : mp){
        ans += x.second * (x.second - 1) / 2;
    }

    cout << ans << endl;

    return 0;
}

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

#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)

using ll = long long;
#define INF 1e9

int main(){ 
  int A, B, C;
  cin >> A >> B >> C;
  cout << max(0, C - (A-B)) << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <numeric>
#include <list> 
#include <cmath>
#include <stdio.h>

using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(),x.end()
#define INF (1e9)

typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> P;

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

int main() {
	int N;
	cin >> N;
    int A, B;
    cin >> A >> B;
    vi P(3, 0);
    REP(i, N) {
        int p;
        cin >> p;
        if (p <= A) {
            P[0] += 1;
        } else if (p <= B) {
            P[1] += 1;
        } else {
            P[2] += 1;
        }
    }
    int min = *std::min_element(ALL(P));
    printf("%d", min);
}

Measured memory_bytes: 256
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
INF = 10**10+5
#入力
n,k = map(int,input().split())
a = list(map(int,input().split()))
#解答
maxa = max(a)
num = [0]*(maxa)
for i in range(len(a)):
    num[a[i]-1]+=1
cnt = len(set(a))
ans = 0

if cnt<k:
    print(ans)
else:
    for i in range(len(num)):
        if num[i] == 0:
            num[i] = INF
    num.sort()

    i = 0
    while True:
        if cnt == k:
            break
        ans += num[i]
        i+=1
        cnt -= 1

    print(ans)

Measured memory_bytes: 35036
def b_rot_n(): 
    N = int(input())
    S = input()
    for znaczek in S: 
        if ord(znaczek)+N <= ord('Z'):
            print(chr(ord(znaczek)+N),end='')
        else: 
            print(chr(ord(znaczek)+N - 26), end='')
    print('')
b_rot_n()

Measured memory_bytes: 44780
#include "bits/stdc++.h"
using namespace std;
#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 all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define SZ(x) (int)x.size()
#define e_b emplace_back
using ll = long long;
const ll LINF=1LL<<60;
const int INF=1<<30;

int V,E;
vector<vector<int>> G;

struct LowLink{
	const vector<vector<int>> &G;
	vector<int> ord,low,used;
	vector<pair<int,int>> bridge;
	vector<int> articulation;
	
	LowLink(vector<vector<int>> &g):G(g),ord(g.size()),low(g.size()),used(g.size()){}
	
	void dfs(int u,int par,int &k){
		ord[u]=low[u]=k++;
		used[u]=true;
		bool is_articulation=false;
		int cnt=0;
		for(auto &v:G[u]){
			if(!used[v]){
				cnt++;
				dfs(v,u,k);
				low[u]=min(low[u],low[v]);
				if(ord[u]<low[v]){
					bridge.e_b(u,v);
				}
				if(par!=-1&&ord[u]<=low[v]) is_articulation=true;
			}else if(v!=par){
				//back edge
				low[u]=min(low[u],ord[v]);
			}
		}
		if(par==-1&&cnt>1) articulation.e_b(u);
		else if(par!=-1&&is_articulation) articulation.e_b(u);
	}
	
	void build(){
		int k=0;
		for(int i=0;i<G.size();++i){
			if(!used[i]) dfs(i,-1,k);
		}
	}
};

int main(){
	cin>>V>>E;
	G.resize(V);
	rep(i,E){
		int s,t;
		cin>>s>>t;
		G[s].e_b(t);
		G[t].e_b(s);
	}
	
	LowLink lowlink(G);
	lowlink.build();
	
	sort(all(lowlink.articulation));
	for(auto &e:lowlink.articulation) cout<<e<<endl;
}
	



Measured memory_bytes: 4544
#include <stdio.h>
int main(void){
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    for(int i=1; i<=b; i++){
        if((a*i)%b==c){
            puts("YES");
            return 0;
        }
    }
    puts("NO");
    return 0;
}

Measured memory_bytes: 1640
import java.util.*;

public class Main {
    private static final Scanner scn = new Scanner(System.in);
    
    public static void main(String[] args) {
        ArrayList<Integer> ali = new ArrayList<>();
        for(int i = 0, n = scn.nextInt(); i < n; i++) {
            ali.add(scn.nextInt());
        }
        Collections.reverse(ali);
        for(int i = 0; i < ali.size() - 1; i++) {
            System.out.print(ali.get(i) + " ");
        }
        System.out.println(ali.get(ali.size() - 1));
    }
}

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

using namespace std;

class combination {
    vector<long long> inv;
    vector<long long> frac;
    vector<long long> frac_inv;
    long long mod;

public:
    combination(int n, int m) {
        inv = vector<long long>(n + 1, 0);
        frac = vector<long long>(n + 1, 0);
        frac_inv = vector<long long>(n + 1, 0);
        mod = m;

        inv[1] = 1;
        frac[0] = frac[1] = 1;
        frac_inv[0] = frac_inv[1] = 1;
        for (int i = 2; i <= n; i++) {
            inv[i] = mod - inv[mod % i] * (mod / i) % mod;
            frac[i] = frac[i - 1] * i % mod;
            frac_inv[i] = frac_inv[i - 1] * inv[i] % mod;
        }
    }

    int calc(int n, int k) {
        return frac[n] * frac_inv[k] % mod * frac_inv[n - k] % mod;
    }
};

class permutation {
    vector<long long> inv;
    vector<long long> frac;
    vector<long long> frac_inv;
    long long mod;

public:
    permutation(int n, int m) {
        inv = vector<long long>(n + 1, 0);
        frac = vector<long long>(n + 1, 0);
        frac_inv = vector<long long>(n + 1, 0);
        mod = m;

        inv[1] = 1;
        frac[0] = frac[1] = 1;
        frac_inv[0] = frac_inv[1] = 1;
        for (int i = 2; i <= n; i++) {
            inv[i] = mod - inv[mod % i] * (mod / i) % mod;
            frac[i] = frac[i - 1] * i % mod;
            frac_inv[i] = frac_inv[i - 1] * inv[i] % mod;
        }
    }

    int calc(int n, int k) {
        return frac[n] * frac_inv[n - k] % mod;
    }
};

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

    long long mod = 1000000007;
    combination nck(n, mod);
    permutation npk(m, mod);

    long long res = 0;
    for (int i = 0; i <= n; i++) {
        long long a = nck.calc(n, i);
        long long b = npk.calc(m, i);
        long long c = npk.calc(m - i, n - i);

        if (i % 2 == 0) {
            res = (res + a * b % mod * c % mod * c % mod) % mod;
        } else {
            res = (res - a * b % mod * c % mod * c % mod + mod) % mod;
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 26504
#include<stdio.h>
void shou(int *a,int *b);
int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  printf("%d %d ",a/b,a%b);
  shou(&a,&b);
  return 0;
}
void shou(int *a,int *b){
  double c,d;
  c=*a;
  d=*b;
  printf("%f\n",c/d);
}

Measured memory_bytes: 632
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1e09+7;



#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back




int bfs(int place, vector<vector<char>> &data){
  int h=int(data.size());
  int w=int(data.at(0).size());
  vi dis(h*w,-1);
  dis.at(place)=0;
  queue<int> q;
  q.push(place);
  while (!q.empty()){
    int tmp=q.front();
    q.pop();
    int i=tmp/w, j=tmp%w;
    if (i>=1 and data.at(i-1).at(j)!='#' and dis.at(tmp-w)==-1){
      q.push(tmp-w);
      dis.at(tmp-w)=dis.at(tmp)+1;
    }
    if (i<=h-2 and data.at(i+1).at(j)!='#' and dis.at(tmp+w)==-1){
      q.push(tmp+w);
      dis.at(tmp+w)=dis.at(tmp)+1;
    }
    if (j>=1 and data.at(i).at(j-1)!='#' and dis.at(tmp-1)==-1){
      q.push(tmp-1);
      dis.at(tmp-1)=dis.at(tmp)+1;
    }
    if (j<=w-2 and data.at(i).at(j+1)!='#' and dis.at(tmp+1)==-1){
      q.push(tmp+1);
      dis.at(tmp+1)=dis.at(tmp)+1;
    }
  }
  
  sort(ALL(dis));
  return dis.at(h*w-1);
}



int main(){


  int h,w;
  cin>>h>>w;
  
  vector<vector<char>> data(h,vector<char>(w));
  
  rep(i,h){
    string tmp;
    cin>>tmp;
    rep(j,w){
      data.at(i).at(j)=tmp.at(j);
    }
  }
  
  int answer=0;
  
  rep(k,h*w){
    int x=k/w,y=k%w;
    if (data.at(x).at(y)=='.'){
      answer=max(answer,bfs(k,data));
    }
  }
  
  cout<<answer<<endl;
  
      
    
  
    
  
  

}




















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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

typedef pair<int,int> pii;
int main() {
  int N;
  cin >> N;
  while(N--) {
    int gx,gy;
    cin >> gx >> gy;
    int ng[gy+1][gx+1][2];
    memset(ng,0,sizeof(ng));
    int p;
    cin >> p;
    REP(i, p) {
      int x1,y1,x2,y2;
      cin >> x1>>y1>>x2>>y2;
      pii p1(x1,y1);
      pii p2(x2,y2);
      if (p1>p2)swap(p1,p2);
      if (p1.second==p2.second) {
        ng[p1.second][p1.first][0] = 1;
      } else {
        ng[p1.second][p1.first][1] = 1;
      }
    }
    int dp[gy+1][gx+1];
    memset(dp,0,sizeof(dp));
    dp[0][0] = 1;
    REP(i, gy+1) {
      REP(j, gx+1) {
        //cout << dp[i][j] << " ";
        if (j<gx && !ng[i][j][0]) {
          dp[i][j+1] += dp[i][j];
        }
        if (i<gy && !ng[i][j][1]) {
          dp[i+1][j] += dp[i][j];
        }
      }
      //cout << endl;
    }
    if (dp[gy][gx] == 0)
      cout << "Miserable Hokusai!" << endl;
    else
      cout << dp[gy][gx] << endl;
  }
}

Measured memory_bytes: 0
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        x: [i64; 5]
    }

    for i in 0..5 {
        if x[i] == 0 {
            println!("{}", i+1);
        }
    }
}


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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var a = int.Parse(Console.ReadLine());
        var b = int.Parse(Console.ReadLine());

        Console.WriteLine(6 - a - b);
    }
}


Measured memory_bytes: 13140
n,m = map(int,input().split())
l = [[int(i)for i in input().split()]for _ in [0]*n]

def g(k):
  a = [(x[0]if k&1 else -x[0])+(x[1]if k&2 else -x[1])+(x[2]if k&4 else -x[2])  for x in l]
  a.sort(reverse=True)
  return sum(a[:m])
print(max([g(i)for i in range(8)]))

Measured memory_bytes: 3304
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using pll = pair<long long, long long>;

int main() {
	int N, M; cin >> N >> M;
	vector<pll> v;
	for (int i = 0; i < N; i++) {
		int a; cin >> a;
		v.push_back({ a, 1 });
	}
	for (int i = 0; i < M; i++) {
		int b, c; cin >> b >> c;
		v.push_back({ c, b });
	}
	sort(v.begin(), v.end(), greater<pll>());

	long long num = 0;
	long long res = 0;
	for (auto p : v) {
		if (num + p.second <= N) {
			res += p.first *= p.second;
			num += p.second;
		}
		else {
			res += p.first * (N - num);
			num = N;
			break;
		}
	}
	cout << res << endl;

	return 0;
}

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

int dp[207][207];
int judge(const string &a, const string &b){
    memset(dp, 0, sizeof(dp));
    for(int i=0; i<a.size(); ++ i){
        for(int j=0; j<b.size(); ++ j){
            if(dp[i] == dp[j])
                dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1);
            else
                dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
        }
    }
    return dp[a.size()][b.size()];
}



int main() {

    ios::sync_with_stdio(false);

    string str;
    cin >> str;
    int mx = 0;
    for(int i=1; i<str.size(); ++ i){
        if((i + 1) & 1)
            continue;

        int t = (i + 1) / 2, flag = 0;
        for(int j = 0; j<t; ++ j){
            if(str[j] != str[j+t])
                flag = 1;
        }
        if(flag == 0 && (i+1) != str.size())
            mx = i+1;
    }
    cout << mx << endl;
    return 0;
}


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

using ll = long long;

#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                     \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define check(s) cerr << s << endl

#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 all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
void yesOrNo(bool flg) {
  if (flg)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

void solve(ll X, ll Y) {
  bool result = X * 2 <= Y && Y <= X * 4 && Y % 2 == 0;
  yesOrNo(result);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll X;
  scanf("%lld", &X);
  ll Y;
  scanf("%lld", &Y);
  solve(X, Y);
  return 0;
}


Measured memory_bytes: 3720
/*
   Aizu Vol-1 0119: Taro's Obsession
   2017.8.16 bal4u@uu
   ???????????????????????????
*/
#include <stdio.h>

#define MAX 20
char tbl[MAX+5][MAX+5];
int  Q[MAX+5], top, end;
int  count[MAX+5];

void topologicalSort(int size)
{
	int i, j;

//	memset(count, 0, sizeof(count));
	top = end = 0;
	for (i = 0; i < size; i++) for (j = 0; j < size; j++) if (tbl[i][j]) count[j]++;
	for (i = 0; i < size; i++) if (!count[i]) Q[end++] = i;
	while (top < end) {
		i = Q[top++];
		printf("%d\n", i + 1);
		for (j = 0; j < size; j++) {
			if (tbl[i][j]) if (--count[j] == 0) Q[end++] = j;
		}
	}
}

int main(void)
{
	int m, n;
	int i, j;

	scanf("%d%d", &m, &n);
//	memset(tbl, 0, sizeof(tbl));
	while (n-- > 0) {
		scanf("%d%d", &i, &j);
		tbl[i - 1][j - 1] = 1;
	}
	topologicalSort(m);
	return 0;
}

Measured memory_bytes: 596
/*
Wai u read my code xD
*/
#include <bits/stdc++.h>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vi vector <ll> 
#define qu queue <ll>
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


void solve()
{
    int n; cin >> n;
    string a[n]; for (int i = 0; i < n; i++) cin >> a[i];
    sort(a,a+n);
    set <string> ans;
    vector <pair<int,int>> v;
    int cnt = 1;
    for (int i = 1; i < n; i++)
    {
        if (a[i]!=a[i-1])
        {
            v.pb(mp(cnt,i-1));
            cnt = 1;
        }
        else cnt++;
    }
    v.pb(mp(cnt,n-1));
    sort(v.begin(),v.end());
    int k = v[v.size()-1].first;
    for (int i = v.size()-1; i >= 0; i--)
    {
        if (v[i].first!=k) break;
        ans.insert(a[v[i].second]);
    }
    for (auto u: ans) nout(u);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 23920