akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

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

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int n;
	cin>>n;
	vector<ll> a(n+1),b(n);
	for (int i = 0; i <= n; i++){
		cin>>a[i];
	}
	for (int i = 0; i < n; i++){
		cin>>b[i];
	}
	ll ans = 0;
	for (int i = 0; i < n; i++){
		ans += min(a[i]+a[i+1],b[i]);
		a[i+1] -= max(b[i]-a[i],0LL);
		a[i+1] = max(0LL,a[i+1]);
	}
	cout<<ans<<endl;
	return 0;
}

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

struct st {
	int a, b, c;
};
int s[200000], par[200000];
st v[200000];
ll sum = 0;
int find(int x) {
	if (par[x] == x)return x;
	return par[x] = find(par[x]);
}
void unite(int x, int y, int c) {
	x = find(x); y = find(y);
	if (x == y)return;
	sum += c*(ll)s[x] * s[y];
	par[y] = x; s[x] += s[y];
}
int main() {
	int n; scanf("%d", &n);
	rep(i, n) {
		s[i] = 1; par[i] = i;
	}
	rep(i, n - 1) {
		int a, b, c; scanf("%d%d%d", &a, &b, &c);
		v[i] = { a,b,c };
	}
	sort(v, v + n - 1, [](st&a, st&b) {return a.c < b.c; });
	rep(i, n - 1) {
		unite(v[i].a, v[i].b, v[i].c);
	}
	printf("%lld\n", sum);
}

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

using namespace std;

int main(void){
    string s;
    int K;
    cin >> s >> K;
    set<string> v;
    for(int i=0; i<s.length(); i++){
        for(int n=1; n<=5; n++){
            v.insert(s.substr(i, n));
        }
    }

    decltype(v)::iterator it = v.begin();
    for(int i=0;i<K-1;i++) {it++;}
    cout << *it << endl;
    return 0;
}

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

int main(){
	int N, ans;
	ans = 0;
	cin >> N;
	int d[N];
	for(int i = 0; i < N; i++){
		cin >> d[i];
	}
	for(int i = 0; i < N-1; i++){
		for(int j = i+1; j < N; j++){
			ans += d[i]*d[j];
		}
	}
	cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);i++)

int n,m;
int p[125252];
int a[125252], b[125252], c[125252];
int cnt[125252];

int main(){
  scanf("%d%d",&n,&m);
  REP(i,m)scanf("%d",&p[i]),p[i]--;
  REP(i,n-1)scanf("%d%d%d",&a[i],&b[i],&c[i]);
  fill(cnt,cnt+n,0);
  REP(i,m-1){
    int s,t;
    s=min(p[i],p[i+1]);
    t=max(p[i],p[i+1]);
    cnt[s]++;
    cnt[t]--;
  }
  REP(i,n)cnt[i+1]+=cnt[i];
  ll ans = 0;
  REP(i,n-1){
    ans += min((ll)cnt[i]*a[i], (ll)cnt[i]*b[i]+c[i]);
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 3160
import java.util.Scanner;

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

        while(true) {
        	String str = sc.next();
        	int sum = 0;

        	if(str.equals("0")) {
        		break;
        	}

        	for(int i = 0; i < str.length(); i++) {
        		sum += Integer.parseInt(str.substring(i, i+1));
        	}

        	System.out.println(sum);
        }
    }
}


Measured memory_bytes: 26668
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<=(b);++i)
#define ROF(i,a,b) for (int i=(a);i>=(b);--i)
typedef long long ll;
inline int read() {
	int x=0,s=1; char ch=getchar();
	while (ch<'0'||ch>'9') { if (ch=='-') s=-1; ch=getchar(); }
	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
	return s*x;
}

const int MAXN=400005,Mo=1000000007;
multiset<int> S;
ll f[MAXN],g[MAXN];
int n,m,q,a[MAXN],b[MAXN];
int main(){
	n=read();
	FOR(i,1,n*3) a[i]=read();
	S.clear();
	ll sum=0;
	FOR(i,1,n) sum+=a[i],S.insert(a[i]);
	f[0]=sum;
	FOR(i,n+1,n*2) {
		sum+=a[i]; S.insert(a[i]);
		auto x=S.begin();
		sum-=*x; S.erase(x);
		f[i-n]=sum;
	}
	sum=0,S.clear();
	FOR(i,1,n) sum+=a[i+n*2],S.insert(-a[i+n*2]);
	g[0]=sum;
	ROF(i,n*2,n+1) {
		sum+=a[i]; S.insert(-a[i]);
		auto x=S.begin();
		sum+=*x; S.erase(x);
		g[n*2+1-i]=sum;
	}
	ll ans=-1e18;
	FOR(i,0,n) ans=max(ans,f[i]-g[n-i]);
	cout<<ans<<endl;
	
	return 0;
}

/*
*/


Measured memory_bytes: 9472
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const LL mod = 1000000007ll;

LL N,K;
LL A[100000];

LL ans = 0;

void solve(){
	while(1){
		if(N==0) break;
		N = N/K;
		ans++;
	}
}
 
int main(){
	cin >> N >> K;
 
	solve();

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

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define MAX_N 1000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

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

static const double eps = 1e-8;

int main(){
	int n;
	while(~scanf("%d",&n)){
		if(n==-1) break;
		stack<int> stk;
		while(n>0){
			stk.push(n%4);
			n/=4;
		}

		if(stk.empty()) {
			printf("0\n");
			continue;
		}

		while(!stk.empty()){
			printf("%d",stk.top());
			stk.pop();
		}

		printf("\n");
	}
		
}

Measured memory_bytes: 0
N = int(input())
R = [0]*N
C = [0]*N
for i in range(N):
    R[i], C[i] = map(int, input().split())

INF = 10**18
dp = [[INF]*N for i in range(N)]
for i in range(N):
    dp[i][i] = 0
for l in range(1, N):
    for i in range(N-l):
        a0 = R[i]
        c0 = C[i+l]
        dp[i][i+l] = min(a0*C[j]*c0 + dp[i][j] + dp[j+1][i+l] for j in range(i, i+l))
print(dp[0][N-1])



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

using namespace std;

int main()
{
    int n;
    scanf("%d", &n);
    string u;
    double x, sum = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> x >> u;
        if (u == "BTC")
            sum += x * 380000.0;
        else
            sum += x;
    }

    printf("%f\n", sum);

    return 0;
}


Measured memory_bytes: 256
import itertools

N, A, B, C = map(int,input().split())
length_list = [int(input()) for i in range(0, N)]

use_flag = ['0', '1', '2', '-1']
use_list = list(itertools.product(use_flag, repeat=len(length_list)))

costs = []

for ls in use_list:
    if len(set(ls)&{'0','1', '2'}) == 3:
        #print(ls)
        A_diff = 0
        B_diff = 0
        C_diff = 0
        for length, use_for in zip(length_list, list(ls)):
            #print(length, use_for)
            if use_for == '0':
                A_diff += length
                #print(A_diff)
            elif use_for == '1':
                B_diff += length
                #print(B_diff)
            elif use_for == '2':
                C_diff += length
                #print(C_diff)
            #print('-----')
        costs.append(abs(A-A_diff) + abs(B-B_diff) + abs(C-C_diff) + 10*max(ls.count('0') - 1, 0) + 10*max(ls.count('1') - 1, 0) + 10*max(ls.count('2') - 1, 0))
print(min(costs))
#print(len(costs))

Measured memory_bytes: 12872
while True:
    a,op,b = input().split()
    if op == "?": break
    a = int(a)
    b = int(b)
    if op == "+": print(a+b)
    elif op == "-": print(a-b)
    elif op == "*": print(a*b)
    elif op == "/": print(a//b)


Measured memory_bytes: 5592
use std::collections::*;
use std::cmp::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn gcd(x: i32, y: i32) -> i32 {
    if y == 0 {
        x
    } else {
        gcd(y, x%y)
    }
}

fn main() {
    input!{
        k: i32,
    }

    let mut res = 0;
    for a in 1..k+1 {
        for b in 1..k+1 {
            for c in 1..k+1 {
                res += gcd(a, gcd(b, c));
            }
        }
    }

    println!("{}", res);

}


Measured memory_bytes: 2148
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n + 1), b(n);
  for (int i = 0; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  int64 ret = 0;
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    int cur = min(a[i - 1], x);
    ret += cur;
    x -= cur;
    cur = min(a[i], x);
    a[i] -= cur;
    ret += cur;
  }
  printf("%lld\n", ret);
  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		int n;
		int b,f,r,v;
		int[][][] house = new int[4][3][10];
		for(int i=0;i<4;i++)
			for(int j=0;j<3;j++)
				for(int k=0;k<10;k++)
					house[i][j][k]=0;
		
		Scanner scan = new Scanner(System.in);
		n=scan.nextInt();
		
		for(int i=0;i<n;i++){
			b=scan.nextInt();
			f=scan.nextInt();
			r=scan.nextInt();
			v=scan.nextInt();
			house[b-1][f-1][r-1]+=v;
		}
		
		for(int i=0;i<4;i++){
			for(int j=0;j<3;j++){
				for(int k=0;k<10;k++){
					System.out.print(" " + house[i][j][k]);
				}
				System.out.println();
			}
			if(i!=3){
				for(int s=0;s<20;s++){
					System.out.print("#");
				}
				System.out.println();
			}
		}
	}
}


Measured memory_bytes: 29156
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
          Copyright                    */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas:
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz(a) int((a).size())
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,x,y) for(int i=(x);i<(y);i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 400010;
const int mod = 1000000007;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 2000000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Test.insert(x)late ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b % mod;
    int pwur = qpow(b,e>>1);
    return (pwur * pwur) % mod;
}
int modinv(int x){
    return qpow(x,mod-2);
}
/// My Code -------------------------------------------------

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));
    //freopen("a.in","r",stdin);
    //freopen("a.in","w",stdout);
    int n;
    cin>>n;
    vi v(n),S(n);
    rep(i,n){
        cin>>v[i];
    }
    S[0]=v[0];
    rep2(i,1,n){
        S[i]=S[i-1]+v[i];
    }
    int ans=inf;
    rep(i,n-1){
        ans=min(ans,abs(S[i]-(S[n-1]-S[i])));
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 6340
#include<cstdio>

#define MAX 2000000

int A[MAX + 1]; // 1オリジン
int H; // 要素数

// 節点iを根とする部分木がmaxヒープになるようA[i]の値を下降させる
void maxHeapify(int i)
{
	int v = A[i];
	int p = i;

	while (true)
	{
		int cl = p * 2;
		int cr = p * 2 + 1;

		if (cl > H) break;

		int child;
		if (cr <= H && A[cl] < A[cr])
		{
			child = cr;
		}
		else
		{
			child = cl;
		}

		if (v >= A[child])break;

		A[p] = A[child];
		p = child;
	}
	A[p] = v;
}

/*
要素1から順に出力する
 16 14 10 8 7 9 3 2 4 1
*/
int main()
{
	scanf("%d", &H);
	for (int i = 1; i <= H; i++)
	{
		scanf("%d", &A[i]);
	}
	for (int i = H / 2; i >= 1; i--)
	{
		maxHeapify(i);
	}
	for (int i = 1; i <= H; i++)
	{
		printf(" %d", A[i]);
	}
	printf("\n");
}


Measured memory_bytes: 4652
import heapq

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

heapq.heapify(v)
a = heapq.heappop(v)
b = heapq.heappop(v)
tmp = (a+b) / 2
heapq.heappush(v, tmp)

while len(v) != 1:
    heapq.heapify(v)
    a = heapq.heappop(v)
    b = heapq.heappop(v)

    tmp = (a+b) / 2
    heapq.heappush(v, tmp)
print(v[-1])

Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cmath>
#include<assert.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define INF 0x3f3f3f3f
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
const ll mod=1000000007;
const double PI = acos(-1.0);
const double epsilon = PI / 180.0;//角度转弧度 
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const int N = 2e3+10, M = 1e6+10;
struct TIII {
	int x, y, z;
};
int n;
int a[N * 3]; 
int dp[N][N];
int maxa[N];
int mx, ex;
void init() {
	memset(dp, -INF, sizeof dp);
	memset(maxa, -INF, sizeof maxa);
	mx = 0;
	ex = 0;
}
int main() {
	init();
	cin>>n;
	for(int i = 1;i <= n * 3;i++) cin>>a[i];
	dp[a[1]][a[2]] = 0;
	dp[a[2]][a[1]] = 0;
	maxa[a[1]] = 0;
	maxa[a[2]] = 0;
	vector<TIII> upd;
	for(int i = 3;i <= n * 3;i += 3) {
		int x = a[i], y = a[i + 1], z = a[i + 2];
		if(x == y&&y == z) {
			ex++;
			continue;
		}
		for(int j = 0;j < 3;j++) {
			int m = max(dp[z][z] + 1, mx);
			upd.pb({x, y, m});
			for(int k = 1;k <= n;k++) {
				int m = maxa[k];
				if(x == y) m = max(m, dp[k][x] + 1);
				upd.pb({k, z, m});
			}
			swap(x, y);swap(y, z);
		}
		for(int k = 0;k < upd.size();k++) {
			int x = upd[k].x, y = upd[k].y, m = upd[k].z;
			mx = max(mx, m);
			maxa[x] = max(maxa[x], m);
			maxa[y] = max(maxa[y], m);
			dp[x][y] = max(dp[x][y], m);
			dp[y][x] = max(dp[y][x], m);
		}
		upd.clear();
	}
	//cout<<mx<<"\n";
	cout<<mx + ex<<"\n";
	return 0;
}

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

int main(void)
{
  std::string a, b, c;
  std::cin >> a >> b >> c;

  std::string ans;
  char now_str = 'a';
  size_t A = 0;
  size_t B = 0;
  size_t C = 0;

  while (true) {
    if (now_str == 'a') {
      if (A == a.size()) {
        ans = "A";
        break;
      }

      now_str = a.at(A);
      A++;
    }
    else if (now_str == 'b') {
      if (B == b.size()) {
        ans = "B";
        break;
      }

      now_str = b.at(B);
      B++;
    }
    else {
      if (C == c.size()) {
        ans = "C";
        break;
      }

      now_str = c.at(C);
      C++;
    }
  }

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 3588
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextLine()) {
			String ss = sc.nextLine();
			if (ss.equals("#")) {
				break;
			}
			ss = ss.replace(" ", "");
			char[] s = ss.toCharArray();
			int n = s.length;
			int i = 0;
			long num = -1;
			Deque<Long> stack = new ArrayDeque<Long>();
			stack.offer(-1L);
			while(i < n) {
				if (s[i] == 'S') {
					i+=2;
					stack.push(-1L);
					continue;
				}
				if (Character.isDigit(s[i])) {
					num = 0;
					while(i<n) {
						if (Character.isDigit(s[i])) {
							num*=10;
							num+=s[i]-'0';
							i++;
						}else{
							break;
						}
					}
				}
				if ((i < n) && (i+2 >= n || s[i+2] == '>')) {
					long b = stack.pop();
					if (b >= 0) {
						if (num < 32) {
							num = b >> num;
						}else{
							num = 0;
						}
					}
					num = (num * num) % 1000000007;
					//stack.push(num);
					i++;
				}
				if (i >= n || (i+2 < n && s[i+2] != '>')) {
					long b = stack.pop();
					if (b >= 0) {
						if (num < 32) {
							num = b >> num;
						}else{
							num = 0;
						}
					}
					stack.push(num);
					i+=2;
				}
			}
			System.out.println(num);
		}
	}

}

Measured memory_bytes: 59904
import math

a, b, h, m = map(int, input().split())
x_a = a * math.sin(math.radians((60 * h + m) / 2))
y_a = a * math.cos(math.radians((60 * h + m) / 2))
x_b = b * math.sin(math.radians(6 * m))
y_b = b * math.cos(math.radians(6 * m))
ans = math.sqrt((x_a - x_b) ** 2 + (y_a - y_b) ** 2)
print(ans)

Measured memory_bytes: 9580
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

#ソート
b2 =[0 for i in range(n)]

for i in range(n):
    b2[i] = b[a[i]-1]

out = b2[0]
pre = a[0]

for i in range(1,n):
    out += b2[i]
    #print("-",pre,a[i],a[i]-pre)
    if a[i]-pre == 1:
        out += c[a[i]-2]
    pre = a[i]
        
print(out)
    

Measured memory_bytes: 3064
import java.util.*;
public class Main{
	public static void main(String arg[]){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		if(a>=13)
			System.out.println(b);
		else if(a>=6&&a<=12)
			System.out.println(b/2);
		else System.out.println("0");
	}
}

Measured memory_bytes: 21844
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
const LL mod=1e9+7;

LL n,m;
LL ans;

LL calc(LL p)
{
	LL ans=1;
	for(LL i=1;i<=p;i++)
		(ans*=i)%=mod;
	return ans;
}

int main()
{
	scanf("%lld%lld",&n,&m);
	ans=(calc(n)*calc(m))%mod;
	if (abs(n-m)>1)
		ans*=0;
	else if (abs(n-m)==0)
	    ans=(ans*2)%mod;
	
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll=long long;
ll a,b,c,d;
int main(){
  cin>>a>>b>>c;
  if(!(a&1)&&a==b&&b==c)return cout<<-1,0;
  while(!(a&1)&&!(b&1)&&!(c&1)){
    d++;
    a/=2;
    b/=2;
    c/=2;
    ll a1=b+c;
    ll b1=a+c;
    ll c1=b+a;
    a=a1,b=b1,c=c1;
  }
  cout<<d<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans = a * n < b ? a * n : b;
        System.out.println(ans);
    }
}


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

int main(){
  int A, B;
  cin >> A >> B;
  
  if (A != 0 && A <= 9){
    if (B != 0 && B <= 9){
      cout << A*B << endl;
    }
    else{
      cout << -1 << endl;
    }
  }
  else{
    cout << -1 << endl;
  }
      
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
const ll M = 1000000007;

int N;
string S[2];

int main () {
  cin >> N >> S[0] >> S[1];
  vector<bool> V;
  for (auto i = 0; i < N; ++i) {
    if (S[0][i] == S[1][i]) {
      V.push_back(true);
    } else {
      V.push_back(false);
      i++;
    }
  }
  ll ans;
  if (V[0]) {
    ans = 3;
  } else {
    ans = 6;
  }
  for (auto i = 0; i < (int)V.size()-1; ++i) {
    if (V[i]) {
      ans *= 2;
    } else if (!V[i+1]) {
      ans *= 3;
    }
    ans %= M;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

vll A;
ll B;
ll C;
ll N;
ll M;
ll K;

ll ltmp;
string stmp;
double dtmp;

ll getPower(ll value,ll shisu,ll mod){
    ll ans = 1;
    ll cnt = shisu;
    while(cnt>0){
        if(cnt%2==1){
            ans = ans * value % mod;
        }
        value = value * value % mod;
        cnt = cnt/2;
    }
    return ans;
}

int main(){

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

    cin >> N;
    rep(ni,N){
        cin >> ltmp;
        A.push_back(ltmp);
    }
    int base=1;
    ll ans = 0;

    sort(A.begin(),A.end());
    ll maxi = A.size()-1;
    while( A[maxi] > 0 ){
        ll cnt[2]={};
        rep(ai,A.size()){
            ll flag = A[ai]%2;
            cnt[flag]++;
            A[ai]=A[ai]/2;
        }
        ans = ans + (cnt[0] * cnt[1] % MOD) * base;
        ans = (ans+MOD) % MOD;
        base = (base * 2) % MOD;
    }

    //ll ans = A^B;
    cout << ans << endl;

}

Measured memory_bytes: 7320
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func putSlice(s []int) {
	n := len(s)
	putf("%d ", n)
	for i := 0; i < n-1; i++ {
		putf("%d ", s[i])
	}
	if n > 0 {
		puts(s[n-1])
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := nextInt()

	k := 0
	for i := 1; i*(i-1) <= 2*n; i++ {
		if i*(i-1) == 2*n {
			k = i
		}
	}
	if k == 0 {
		puts("No")
		return
	}

	puts("Yes")
	puts(k)

	ans := make([][]int, k)
	ans[0] = make([]int, 0)
	for i := 1; i < k; i++ {
		ans[0] = append(ans[0], (i*i+i)/2)
	}
	for i := 1; i < k; i++ {
		ans[i] = make([]int, 0)
		s := 1
		if i > 1 {
			s = ans[0][i-2] + 1
		}
		// ヨコ
		for s < ans[0][i-1] {
			ans[i] = append(ans[i], s)
			s++
		}
		// タテ
		for t, j := s, i; t <= n; j++ {
			ans[i] = append(ans[i], t)
			t += j
		}
	}

	for i := range ans {
		putSlice(ans[i])
	}
}


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,sum=0;
	string s;
	cin>>n;
	vector<ll>v(6);
	for(int i=0;i<n;i++){
		cin>>s;
		if(s.substr(0,1)=="M")v.at(0)++;
		if(s.substr(0,1)=="A")v.at(1)++;
		if(s.substr(0,1)=="R")v.at(2)++;
		if(s.substr(0,1)=="C")v.at(3)++;
		if(s.substr(0,1)=="H")v.at(4)++;
	}
	sum+=v.at(0)*v.at(1)*v.at(2);
	sum+=v.at(0)*v.at(1)*v.at(3);
	sum+=v.at(0)*v.at(1)*v.at(4);
	sum+=v.at(0)*v.at(2)*v.at(3);
	sum+=v.at(0)*v.at(2)*v.at(4);
	sum+=v.at(0)*v.at(3)*v.at(4);
	sum+=v.at(1)*v.at(2)*v.at(3);
	sum+=v.at(1)*v.at(2)*v.at(4);
	sum+=v.at(1)*v.at(3)*v.at(4);
	sum+=v.at(2)*v.at(3)*v.at(4);
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char ct[6][6];
int c[6][6];
int main(){
    int h,w,k;
    cin >> h >> w >> k;
    for (int i = 0; i < h; i++){
        for (int j =0;  j < w; j++) {
            scanf(" %c",&ct[i][j]);
            c[i][j] = (ct[i][j] == '.')?0:1;
        }
    }
    int ans = 0;
    for (int i = 0; i < (1<<h); i++){
        for (int j = 0; j < (1<<w); j++){
            int s = 0;
            for (int k = 0; k < h; k++){
                for (int l = 0; l < w; l++){
                    if ((i & (1<<k)) || (j & (1<<l))) continue;
                    s += c[k][l];
                }
            }
            if (s == k) ans++;
        }
    }
    printf("%d ",ans);

}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;

const int maxn = 123;
int n , a[maxn] , dp[maxn][10009];


int calc(int x , int have)
{
	if(x == n)
	{
		if(have % 10 == 0) return 0;
		else return have;
	}
	if(dp[x][have] != -1) return dp[x][have];
	int ret = 0;
	ret = max(calc(x + 1 , have) , calc(x + 1 , have + a[x]));
	return dp[x][have] = ret;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(NULL);
	memset(dp,-1,sizeof(dp));
	cin >> n;
	for(int i=0;i<n;i++) cin >> a[i];		
	cout << calc(0 , 0) << endl;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define all1(i) begin(i),end(i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false


int main(void){
    string S,T;
    cin >> S >> T;
    ll Ans = INF;
    REP(i,S.size()-T.size()+1){
        ll num=0;
        REP(j,T.size()){
            if(S[i+j]!=T[j]){
                num++;
            }
        }
        Ans=min(Ans,num);
    }
    cout << Ans << endl;
    
    return 0;
}



Measured memory_bytes: 3584
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int a, b, c, d;

  cin >> a >> b >> c >> d;

  if(abs(a-c) <= d || (abs(a-b) <= d && abs(b-c) <= d))
    puts("Yes");
  else
    puts("No");

  return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())

if m%2 == 0:
    gu_max, ki_max = m, m-1
else:
    gu_max, ki_max = m-1, m
gu_start = 1
ki_start = 1 + gu_max + 1

for sa in range(m)[::-1]:
    sa += 1
    if sa%2 == 0:
        print(gu_start, gu_start+sa)
        gu_start += 1
    else:
        print(ki_start, ki_start+sa)
        ki_start += 1

Measured memory_bytes: 9212
#include<iostream>
#define SIZE 2000000
using namespace std;
struct dList{
  int head,tail;
  int list[SIZE];
  void init()
  {
    head=-1;
  }
  void insertX(int x)
  {
    if(head==-1){
      head=SIZE;
      tail=SIZE-1;
    }
    head--;
    list[head]=x;
  }
  void deleteFirst()
  {
    if(head==tail){
      head=-1;
    }else{
      while(list[head+1]<0){
	head++;
      }
      head++;
    }
  }
  void deleteLast()
  {
    if(head==tail){
      deleteFirst();
    }else{
      while(list[tail-1]<0){
	tail--;
      }
      tail--;
    }
  }
  void deleteX(int x)
  {
    bool isExist=false;
    if(list[head]==x){
      deleteFirst();
    }else{
      for(int i=head+1;i<tail;i++){
	if(list[i]==x){
	  list[i]=-1;
	  isExist=true;
	  break;
	}
      }
      if(!isExist){
	if(list[tail]==x) deleteLast();
      }
    }
  }
};

int main()
{
  int n,value;
  cin>>n;
  string op;
  dList dlist;
  dlist.init();
  for(int i=0;i<n;i++){
    cin>>op;
    if(op=="deleteFirst"){
      dlist.deleteFirst();
    }else if(op=="deleteLast"){
      dlist.deleteLast();
    }else{
      cin>>value;
      if(op=="insert"){
	dlist.insertX(value);
      }else if(op=="delete"){
	dlist.deleteX(value);
      }else{
	cout<<"ERROR(operation "<<op<<" DOESNOT exist"<<endl;
      }
    }
  }
  
  for(int i=dlist.head;i<=dlist.tail;i++){
    if(dlist.list[i]>=0){
      if(i==dlist.tail){
	cout<<dlist.list[i]<<endl;
      }else{
	cout<<dlist.list[i]<<' ';
      }
    }
  }
  return 0;
} 


Measured memory_bytes: 6988
#include<cstdio>
using namespace std;
int main(){
  int n,dp[200]={};
  scanf("%d",&n);
  dp[0]=1;
  for(int i=0;i<n;i++)
    if(dp[i]){
      dp[i+4]=dp[i+7]=1;
    }
  if(dp[n]==1)
    printf("Yes\n");
  else
    printf("No\n");
}

Measured memory_bytes: 128
import sys
N = int(input())
array = list(map(int,input().split()))

if not ( 1 <= N <= 20 ): sys.exit()
ceil = 0
count = 0
for I in array:
    if not ( 1 <= I <= 100 ): sys.exit()
    if I >= ceil: 
        ceil = I
        count += 1
print(count)

Measured memory_bytes: 9112
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e6 * 2 + 10, INF = 1e9 + 10;

vector<ll> vec;

ll check(ll mid) {
	ll cnt = 0;
	for (int i = 0; i < vec.size(); i++) {
		if (vec[i] <= mid) continue;

		ll k = (vec[i] - 1) / mid + 1;
		cnt += (k - 1);
	}

	return cnt;
}

int main()
{
	fastInp;

	ll n, k;
	cin >> n >> k;

	vec.resize(n);

	for (int i = 0; i < n; i++) cin >> vec[i];

	ll l = 0, r = INF;

	while (r - l > 1) {
		ll mid = (l + r) / 2;
		if (mid <= 7) {
			cout << "";
		}
		if (check(mid) <= k) {
			r = mid;
		}
		else {
			l = mid;
		}
	}

	cout << r;

	return 0;
}

Measured memory_bytes: 4704
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

unordered_map<long, unordered_set<long>> one_step;
unordered_map<long, unordered_set<long>> visited;

void solve() {
  long N, M;
  cin >> N >> M;
  rep (i, M) {
    long u, v;
    cin >> u >> v;
    one_step[u].insert(v);
  }
  long S, T;
  cin >> S >> T;
  queue<pair<long, long>> q;
  q.push(make_pair(S, 0));
  while (q.size() > 0) {
    auto command = q.front();
    q.pop();
    bool visited_flag = false;
    for (auto it: visited[command.first]) {
      if (it % 3 == command.second % 3) visited_flag = true;
    }
    if (visited_flag) continue;
    visited[command.first].insert(command.second);
    if (command.first == T and command.second % 3 == 0) {
      cout << command.second / 3 << endl;
      return;
    }
    for (auto it: one_step[command.first]) {
      q.push(make_pair(it, command.second + 1));
    }
  }
  cout << -1 << endl;
}

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


Measured memory_bytes: 38308
#include<iostream>
#include<cstdio>
using namespace std;
int n,a[1000100],b[1000100];
int aabs(int x){ return x<0?-x:x;}
int calc(int x,int y,int dp)
{
	if(y>x) return 0;
	if(dp==0) return 1;
	int ln=1<<dp;
	if(x>ln) x-=ln;
	if(y>ln) y-=ln;
	return calc(x,y,dp-1);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%1d",&a[i]);
	if(n==1) return  printf("%d\n",a[1]),0;
	for(int i=1;i<n;i++)
	b[i]=aabs(a[i]-a[i+1]);
	int fl=1;
	for(int i=1;i<n;i++)
	if(b[i]==1) fl=0;
	int ans=0;
	if(!fl)
	{
		for(int i=1;i<n;i++)
		if(b[i]==1) ans^=calc(n-1,i,20);
		printf("%d\n",ans);
	}
	else
	{
		for(int i=1;i<n;i++)
		if(b[i]==2) ans^=calc(n-1,i,20);
		printf("%d\n",ans*2);
	}
	return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0 ; i<(n) ; ++i)
typedef long long ll;
using namespace std;
const ll MAX = 2500LL;
typedef pair <ll, ll> P;
const double PI=3.14159265358979323846;

ll nc2(ll x){
  return x*(x-1)/2;
}
int main(){
  int n;
  cin >> n;
  vector<int> a(n), d(n);
  rep(i,n){
    cin >> a[i];
    a[i]--;
  }
  rep(i,n){
    d[a[i]]++;
  }
  ll sum=0;
  rep(i,n){
    sum += nc2(d[i]);
  }
  rep(i,n){
    ll ans = sum;
    ans -= nc2(d[a[i]]);
    ans += nc2(d[a[i]]-1);
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 4096
def main():
    n = int(input())
    sch = []
    for _ in range(n):
        sch.append(list(map(int,input().split())))
    sch.sort(key=lambda a: a[1])
    res,t = 0,-1
    for i in range(n):
        if t<sch[i][0]:
            t = sch[i][1]
            res+=1
    print (res)

if __name__ == '__main__':
    main()




Measured memory_bytes: 24356
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;





int main(){

	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);

	if(b-a == c-b){

		printf("YES\n");

	}else{

		printf("NO\n");
	}

	return 0;
}


Measured memory_bytes: 256
def resolve():
    N = int(input())
    v = list(map(int, input().split()))
    if len(v) == 1:
        print(v[0])
        return

    v.sort()
    while len(v) >= 2:
        new = (v[0] + v[1]) / 2
        v.pop(0)
        v.pop(0)
        v.append(new)
        v.sort()

    print(v[0])

resolve()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int h,w;
  cin>>h>>w;
  string s[h];
  for(int i=0;i<h;i++) cin>>s[i];
  bool e[h+10][w+10];
  memset(e,0,sizeof(e));
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      e[h-i-1][j]=s[i][j]=='#';
  /*//
    for(int i=h-1;i>=0;i--)
    for(int j=0;j<w;j++)
    cout<<e[i][j]<<" \n"[j==w-1];
  //*/
  int ans=2;
  
  time_t start=clock();
  srand((unsigned)time(NULL));
  int k=0;
  while((double)(clock()-start)/CLOCKS_PER_SEC<1.8&&k<=max(w,h)){
    k++;
    for(int i=1;i<=h+k;i++){
      int x=0,y=0,tmp=e[0][0],p;
      while(x<=w&&y<=h){
	//if(i==4&&k==2) cout<<y<<" "<<x<<endl;
	p=e[y][x];
	if((i*(x+1))%(w+k)==0) x++,y++;
	if((i*(x+1))/(w+k)==y) x++;
	else y++;
	if(!p&&e[y][x]) tmp++;
      }
      //cout<<i<<":"<<tmp<<endl;
      //if(i==4&&k==2) cout<<tmp<<endl;
      ans=max(ans,tmp+1);
    }
    for(int j=1;j<=w+k;j++){
      int x=0,y=0,tmp=e[0][0],p;
      while(x<=w&&y<=h){
	p=e[y][x];
	if((j*(y+1))%(h+k)==0) x++,y++;
	else if((j*(y+1))/(h+k)==x) y++;
	else x++;
	if(!p&&e[y][x]) tmp++;
      }
      //cout<<j<<" "<<tmp<<endl;
      ans=max(ans,tmp+1);
    }
  }
  //cout<<k<<endl;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 4024
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#つまりlist[i] < x となる i の個数
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#つまりlist[i] <= x となる i の個数
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！
def maze_solve(S_1,S_2,maze_list):
    d = deque()
    d.append([S_1,S_2])
    dx = [0,0,1,-1]
    dy = [1,-1,0,0]
    while d:
        v = d.popleft()
        x = v[0]
        y = v[1]
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if nx < 0 or nx >= h or ny < 0 or ny >= w:
                continue
            if dist[nx][ny] == -1:
                dist[nx][ny] = dist[x][y] + 1
                d.append([nx,ny])
    return max(list(map(lambda x: max(x), dist)))
h,w = MI()
if h==1 and w == 2:
  print(1)
elif h == 2 and w == 1:
  print(1)
else:
  ans = 0
  maze = [list(input()) for _ in range(h)]
  dist = [[-1]*w for _ in range(h)]
  start_list = []
  for i in range(h):
      for j in range(w):
          if maze[i][j] == "#":
              dist[i][j] = 0
          else:
              start_list.append([i,j])
  dist_copy = deepcopy(dist)
  for k in start_list:
      dist = deepcopy(dist_copy)
      ans = max(ans,maze_solve(k[0],k[1],maze))
  print(ans+1)

Measured memory_bytes: 10140
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a=0,b=0,c=0,x=0,y=0,z=0;
	scanf("%d%d%d",&a,&b,&c);
	while(x<a){
		x+=b;y+=c;
	}
	printf("%d",y);
} 


Measured memory_bytes: 3828
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

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

LL moddev(LL a, LL b){
	return a * modinv(b) % MOD;
}

void Main()
{
    int a[] = {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 n;cin>>n;

    cout<<a[n-1]<<endl;

	return;
}

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

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

#define MAX 100005

using namespace std;

int x, y, N;
int total;
vector< pair<int, pair<int, int> > > V;
vector< pair<int, int> > X, Y;
int depth[MAX];
int T[MAX];

int find(int x)
{
	if (T[x]==x) return x;
	return T[x] = find(T[x]);
}

void unite(int cost, int x, int y){		//T木に要素を追加
	x = find(x);
	y = find(y);
	if (x == y) return;
	total += cost;
	if (depth[x] < depth[y]) { 
		T[x] = y;
		depth[y]++;
	}
	else {
		T[y] = x;
		depth[x]++;
	}
}

int main()
{
	cin >> N;
	for (int i = 1; i <= N; i++)
	{
		T[i] = i;
		depth[i] = 1;
		cin >> x >> y;
		X.push_back(make_pair(x, i));
		Y.push_back(make_pair(y, i));
	}
	sort(X.begin(), X.end());
	sort(Y.begin(), Y.end());
	for (int i = 0; i< N - 1; i++)
	{
		V.push_back(make_pair(X[i + 1].first - X[i].first, make_pair(X[i].second, X[i + 1].second))); //(距離, i, i+1)
		V.push_back(make_pair(Y[i + 1].first - Y[i].first, make_pair(Y[i].second, Y[i + 1].second)));
	}
	sort(V.begin(), V.end());

	total = 0;

	for (int i = 0; i < V.size(); i++){
		unite(V[i].first, V[i].second.first, V[i].second.second);
	}
	cout << total << endl;

	return 0;
}

Measured memory_bytes: 7912
#include <iostream>
using namespace std;
#define INF 1000000001

int N, N2, L, a[2097152];

int find(int s, int t, int i, int l, int r) {
  if (s <= l && r <= t) return a[i];
  if (t <= l || r <= s) return INF;
  int cl, cr;
  cl = find(s, t, i * 2, l, (l + r) / 2);
  cr = find(s, t, i * 2 + 1, (l + r) / 2, r);
  return min(cl, cr);
}

int main() {
  int i;
  cin >> N >> L;
  N2 = 1;
  while (N > N2) N2 *= 2;
  for (i = 0; i < N; i++) cin >> a[N2 + i];
  for (; i < N2; i++) a[N2 + i] = INF;

  for (i = N2 - 1; i > 0; i--) {
    a[i] = min(a[i * 2], a[i * 2 + 1]);
  }

  for (i = 0; i < N - L; i++) {
    cout << find(i, i + L, 1, 0, N2) << " ";
  }
  cout << find(N - L, N, 1, 0, N2) << endl;

  return 0;
}


Measured memory_bytes: 11296
#include <bits/stdc++.h>
#define int long long
#define moder (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % moder;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), moder - 2, moder) % moder * mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/

vector<int>divisors(int x) {
	vector<int>res;
	for (int i = 1; i * i <= x; i++) {
		if (i * i == x)res.push_back(i);
		else if (x % i == 0) {
			res.push_back(i);
			res.push_back(x / i);
		}
	}
	return res;
}
signed main() {
	int n, m;
	cin >> n >> m;
	int ans = 0;
	for (auto a : divisors(m)) {
		if (m / a >= n) {
			ans = max(ans, a);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef unsigned long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)

class Solve
{
	public:

		int k, x;

		void input()
		{
			cin >> k >> x;
		}

		void solve()
		{

		}

		void output()
		{
			for(int i = x-k+1; i < x+k; i++)
			{
				cout << i << ' ';
			}
        }
};

Solve s;
int main()
{
    s.input();
	s.solve();
	s.output();
	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
K = []
A = []
for i in range(N):
    S = list(map(int, input().split()))
    K.append(S[0])
    A.extend(S[1:])
ans = 0
for i in range(M):
    if A.count(i+1) == N:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
char s[100005];
int len;
int main(){
    scanf("%s", s), len = strlen(s);
    if (s[0] == s[len - 1]) puts(len & 1 ? "Second" : "First");
    else puts(len & 1 ? "First" : "Second");
}

Measured memory_bytes: 256
using System;

namespace Aizu
{
    class Program
    {
        static void Main()
        {
            string[] str = Console.ReadLine().Split(' ');
            var a = int.Parse(str[0]);
            var b = int.Parse(str[1]);
            Console.WriteLine($"{a*b} {a*2+b*2}");
        }
    }
}



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

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> vec(h);
    for (int i = 0; i < h; i++)
    {
        cin >> vec.at(i);
    }

    for (int i = 0; i < h + 2; i++)
    {
        if (i == 0 || i == h + 1){
            rep(j, w + 2)
            {
                cout << "#";
                if (j == w + 1)
                {
                    cout << "" << endl;
                }
                
            }
        }
        else
        {
            rep(j, 3)
            {
                if (j == 0 || j == 2)
                {
                    cout << "#";
                    if (j == 2)
                    {
                        cout << "" << endl;
                    }
                    
                }
                else
                {
                    cout << vec.at(i - 1);
                }
                
                
            }
        }
        
    }
    
    
}

Measured memory_bytes: 3608
n = int(input())
box = list(map(int, input().split()))
q = int(input())
for _ in range(q):
    b, e, t = map(int, input().split())
    for k in range(e-b):
        box[t+k],box[b+k] = box[b+k],box[t+k]
            
print(*box)


Measured memory_bytes: 5832
#include<bits/stdc++.h>
using namespace std;
int a, b, k, flag;
int main(){
	cin>> k>> a>> b;
	for(int i=a; i<=b; i++){
		if(i%k==0){
			flag=1;
			break;
		}
	}
	if(flag) cout<< "OK";
	else cout<< "NG";
	return 0;
}

Measured memory_bytes: 3624