akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main()
{
    ll h, w, ans = LONG_MAX;
    cin >> h >> w;
    for (ll i = 1; i < h; i++)
    {
        ll bh = ceil((h - i) / 2.0);
        vector<ll> s;
        s.push_back(w * i);
        s.push_back(w * bh);
        s.push_back(w * (h - i - bh));
        sort(ALL(s));
        ans = min(ans, s[2] - s[0]);
        ll bw = ceil(w / 2.0);
        vector<ll> t;
        t.push_back(w * i);
        t.push_back((h - i) * bw);
        t.push_back((h - i) * (w - bw));
        sort(ALL(t));
        ans = min(ans, t[2] - t[0]);
    }
    swap(h, w);
    for (ll i = 1; i < h; i++)
    {
        ll bh = ceil((h - i) / 2.0);
        vector<ll> s;
        s.push_back(w * i);
        s.push_back(w * bh);
        s.push_back(w * (h - i - bh));
        sort(ALL(s));
        ans = min(ans, s[2] - s[0]);
        ll bw = ceil(w / 2.0);
        vector<ll> t;
        t.push_back(w * i);
        t.push_back((h - i) * bw);
        t.push_back((h - i) * (w - bw));
        sort(ALL(t));
        ans = min(ans, t[2] - t[0]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc092/tasks/arc093_a
# C - Traveling Plan

N = int(input().split()[0])
a_list = list(map(int, input().split()))
a_list = [0] + a_list + [0]
total_cost = 0
for x, y in zip(a_list[:-1], a_list[1:]):
    total_cost += abs(x - y)

diff_list = []

for i in range(1, N + 1): # 10 ** 5
    before = abs(a_list[i-1] - a_list[i]) + abs(a_list[i] - a_list[i+1])
    after = abs(a_list[i-1] - a_list[i+1])
    diff_list.append(before - after)

ans = '\n'.join([str(total_cost - d) for d in diff_list])
print(ans)


Measured memory_bytes: 18980
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string.h>
#include <set>
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int N,M;

struct Info{
	char from[9],to[9];
	int rank;
	bool erased;
};

struct Data{
	char from[9],to[9],message[51];
};

bool strCmp(char* base, char* comp){
	int length1 = 0,length2 = 0;
	for(int i=0;base[i] != '\0'; i++)length1++;
	for(int i=0;comp[i] != '\0'; i++)length2++;
	if(length1 != length2)return false;

	for(int i=0;base[i] != '\0'; i++){
		if(base[i] != comp[i])return false;
	}
	return true;
}


bool ambiguousCmp(char* base, char* comp){

	bool FLG = true;
	for(int i=0;base[i] != '\0'; i++){
		if(base[i] != comp[i]){
			if(base[i] == '?'){
				//Do nothing
			}else{
				FLG = false;
				break;
			}
		}
	}
	if(FLG)return true;
	else{
		return false;
	}
}

void strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}

void func(){

	int ok_index = 0,not_index = 0;
	Info OK[N],NOT[N];
	for(int i = 0; i < N; i++){
		OK[i].erased = false;
		NOT[i].erased = false;
	}

	char buf[10],from[9],to[9];
	bool FLG;

	for(int i = 0; i < N; i++){
		scanf("%s %s %s",buf,from,to);
		if(buf[0] == 'p'){

			strcpy(OK[ok_index].from,from);
			strcpy(OK[ok_index].to,to);
			OK[ok_index].rank = i;
			ok_index++;
		}else{

			strcpy(NOT[not_index].from,from);
			strcpy(NOT[not_index].to,to);
			NOT[not_index].rank = i;
			not_index++;
		}
	}

	for(int i = not_index -1; i >= 0; i--){
		for(int k = ok_index-1; k >= 0; k--){
			if(NOT[i].rank < OK[k].rank || OK[k].erased == true)continue;

			if(strCmp(NOT[i].from,OK[k].from) == true && strCmp(NOT[i].to,OK[k].to) == true){
				OK[k].erased = true;
			}
		}
	}

	for(int i = ok_index -1; i >= 0; i--){
		if(OK[i].erased == true)continue;
		for(int k = not_index-1; k >= 0; k--){
			if(OK[i].rank < NOT[k].rank || NOT[k].erased == true)continue;

			if(strCmp(OK[i].from,NOT[k].from) == true && strCmp(OK[i].to,NOT[k].to) == true){
				NOT[k].erased = true;
			}
		}
	}


	queue<Data> Q;

	for(int loop = 0; loop < M; loop++){
		Data data;

		scanf("%s %s %s",data.from,data.to,data.message);

		FLG = false;

		for(int i = 0; i < ok_index; i++){
			if(OK[i].erased == true)continue;
			if(ambiguousCmp(OK[i].from,data.from) == true &&  ambiguousCmp(OK[i].to,data.to) == true){
				FLG = true;
				break;
			}
		}

		if(!FLG)continue;

		FLG = true;

		for(int i = 0; i < not_index; i++){
			if(NOT[i].erased == true)continue;
			if(ambiguousCmp(NOT[i].from,data.from) == true &&  ambiguousCmp(NOT[i].to,data.to) == true){
				FLG = false;
				break;
			}
		}

		if(FLG){
			Q.push(data);
		}
	}

	printf("%d\n",Q.size());

	while(!Q.empty()){
		printf("%s %s %s\n",Q.front().from,Q.front().to,Q.front().message);
		Q.pop();
	}

}

int main(){

	while(true){
		scanf("%d %d",&N,&M);
		if(N == 0 && M == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define endl '\n'
using namespace std;
int dy[4] = { 1, 0, -1, 0 }, dx[4] = { 0, 1, 0, -1 };
typedef pair<ll, ll> P;

struct UnionFind {
    vector<int> par;

    UnionFind(int n)
        : par(n, -1)
    {
    }
    void init(int n) { par.assign(n, -1); }

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

    bool issame(int x, int y)
    {
        return root(x) == root(y);
    }

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

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    vector<ll> A(M), B(M);
    rep(i, M)
    {
        cin >> A[i] >> B[i];
        A[i]--, B[i]--;
    }
    UnionFind uf(N);
    ll cur = N * (N - 1) / 2;
    vector<ll> res;
    for (int i = 0; i < M; i++) {
        res.push_back(cur);
        int a = A[M - 1 - i], b = B[M - 1 - i];
        if (uf.issame(a, b)) {
            continue;
        }
        ll sa = uf.size(a), sb = uf.size(b);
        cur -= sa * sb;
        uf.merge(a, b);
    }

    reverse(res.begin(), res.end());
    rep(i, res.size())
    {
        cout << res[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 4212
n = int(input())
x = list(map(int, input().split()))
top = x[0]
und = x[0]
add = x[0]
for i in range(1, n):
    if top < x[i]: top = x[i]
    if und > x[i]: und = x[i]
    add += x[i]
print(und, top, add)


Measured memory_bytes: 6588
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <sstream>
#include <map>
#include <deque>
#include <queue>
#include <set>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b>=c) cout<<"Yes"<<endl;
	else cout<<"No"<<endl; 
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
#include <time.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 2147483600;
const ll infl = 1e17;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin >> s;
    int n = s.size();
    vvll dp(n, vll(2, 0));
    vll ans(n);
    rep(i, n) dp[i][0] = 1;
    rep(i,n-1){
        if (s[i]=='L')
            continue;
        if (s[i+1]=='R'){
            dp[i + 1][0] += dp[i][1];
            dp[i + 1][1] += dp[i][0];
        }
        else{
            ans[i + 1] += dp[i][1];
            ans[i] += dp[i][0];
        }
    }
    repr(i,n-1,0){
        if (s[i]=='R')
            continue;
        if (s[i-1]=='L'){
            dp[i - 1][0] += dp[i][1];
            dp[i - 1][1] += dp[i][0];
        }
        else{
            ans[i - 1] += dp[i][1];
            ans[i] += dp[i][0];
        }
    }
    rep(i, n) cout << ans[i] << " ";
    cout << endl;
}


Measured memory_bytes: 6864
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define N 200010
int a[N],b[N];
int main()
{
    int n,i,j,k,l,r,mid,ans,res;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(i=1;i<=n;i++)
        scanf("%d",&b[i]);
    ans=0;
    for(k=(1<<28);k!=0;k=k/2)
    {
    for(i=1;i<=n;i++)
    {
        a[i]=a[i]&(k*2-1);
        b[i]=b[i]&(k*2-1);
    }
    sort(a+1,a+1+n);
    sort(b+1,b+1+n);

    res=0;
    l=1;
    r=1;
    mid=1;
    for(i=n;i>=1;i--)
    {
        while(l <= n && a[i] + b[l] < k) l++;
        while(mid <= n && a[i] + b[mid] < 2 * k) mid++;
        while(r <= n && a[i] + b[r] < 3 * k) r++;
        res += mid - l + n - r + 1;
        res &= 1;
    }
    if(res) ans += k;
    }
    printf("%d\n",ans);

}


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

int main() {
	unsigned long int h, m;
	long double  cc, a, b, w, ww,v,z;
	cin >> a >> b >> h >> m;

	long double lon;
	lon = (long double)((360 * m) / 60);
	long double sot;
	sot = ((long double)(h * 60 + m) / 2);
	w = abs(lon - sot);
	v = abs(360 - w);
	z = min(w, v);
	ww = (asin(1) / 90);

	cc = powl(a, 2) + powl(b, 2) - (long double)2 * a * b * cos(ww * z);

	long double ans;
	ans = sqrtl(cc);
	cout << fixed;
	cout << setprecision(15) << ans << endl;

	return 0;
}

Measured memory_bytes: 4156
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
  
using namespace std;
 
const ll inf = 1e17;
const ll N = 2e5+100;
const ll bits = 35;
const ll mod = 1e9+7;
const ld pi = 3.14159265358979323846;
 

int main(){
    FASTIO;
    PRECISION;

    ll a=0,b=0;

    string s;
    cin>>s;

    for(auto x: s){
        if(x=='A'){
            a++;
        }else{
            b++;
        }
    }

    if(a&&b){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }



    
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

	int i, j, n, a;
	int card[5][16] = {0};

	scanf("%d", &n);
		for(i = 1;i <= n;i++) {
			char c;
		scanf(" %c %d", &c, &a);
			if(c == 'S') {
				card[0][a-1]=1;
			}

		else if(c == 'H') {
			card[1][a-1]=1;
		}

		else if(c == 'C') {
			card[2][a-1]=1;
		}

		else{
			card[3][a-1]=1;
		}
	}
	for(i = 0;i < 4;i++) {
		for(j = 0;j < 13;j++) {
			char m;
			if(card[i][j] == 0) {
				if(i == 0) {
					m='S';
				}

				else if(i == 1) {
					m='H';
				}

				else if(i == 2) {
					m='C';
				}

				else {
					m='D';
				}
				printf("%c %d\n", m, j + 1);
			}
		}
	}

	return 0;
}

Measured memory_bytes: 596
import java.util.*;

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

    int answer = 0;

    for (int i = 0; i <= a; i++) {
      for (int j = 0; j <= b; j++) {
				int kk = x - 500 * i - 100 * j;
				int k = kk / 50;
				if (k >= 0 && k <= c && kk % 50 == 0) {
					answer++;
				}
      }
    }
    System.out.println(answer);
  }
}


Measured memory_bytes: 23636
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
long l, r;
		l = s.nextInt();
		r = s.nextInt();
		long ans = 2019;
		for (long i = l; i <= r; i++) {
			for (long j = i+1; j <= r; j++) {
				ans = Math.min(ans, (i * j) % 2019);
                if(ans==0)break;
			}
          if(ans==0)break;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;





int main()
{
    
    string s;
    cin >> s;
    s+='.';
    string S = "";
    
    for (int i = 0; i < int(s.length())-1; i++) {
        if(s[i] == 'A') S+='X';
        else if(s[i] == 'B' && s[i+1] == 'C'){
            S+='Y';
            i++;
        }
        else S+=s[i];
    }
    
    //cout << S << endl;
    
    ll an = 0;
    ll ans = 0;
    int n = int(S.length());
    
    for (int i = n-1; i >= 0; i--) {
        if(S[i] == 'Y') an++;
        else if(S[i] == 'X') ans += an;
        else an = 0;
    }
    
    cout << ans << endl;
    
    
    return 0;
}



Measured memory_bytes: 776
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <math.h>

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using PL = pair<ll, ll>;
using V = vector<int>;
using VL = vector<ll>;

int main()
{
    int n;
    cin >> n;
    VL h(n);
    REP(i, n)
    {
        cin >> h[i];
    }
    int mlength = 0;
    int length = 0;
    REP(i, n - 1)
    {
        if(h[i] >= h[i + 1])
        {
            length++;
        }else{
            mlength = max(mlength, length);
            length = 0;
        }
    }
    mlength = max(mlength, length);
    cout << mlength << endl;
}

Measured memory_bytes: 1024
package main

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

// 文字列を1行入力
func StrStdin() (stringReturned string) {
	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	stringReturned = scanner.Text()

	stringReturned = strings.TrimSpace(stringReturned)
	return
}

// 空白や空文字だけの値を除去したSplit()
func SplitWithoutEmpty(stringTargeted string, delim string) (stringReturned []string) {
	stringSplited := strings.Split(stringTargeted, delim)

	for _, str := range stringSplited {
		if str != "" {
			stringReturned = append(stringReturned, str)
		}
	}
	return
}

// デリミタで分割して文字列スライスを取得
func SplitStrStdin(delim string) (stringReturned []string) {
	// 文字列で1行取得
	stringInput := StrStdin()

	// 空白で分割
	// stringSplited := strings.Split(stringInput, delim)
	stringReturned = SplitWithoutEmpty(stringInput, delim)

	return
}

// デリミタで分割して整数値スライスを取得
func SplitIntStdin(delim string) (intSlices []int, err error) {
	// 文字列スライスを取得
	stringSplited := SplitStrStdin(" ")

	// 整数スライスに保存
	for i := range stringSplited {
		var iparam int
		iparam, err = strconv.Atoi(stringSplited[i])
		if err != nil {
			return
		}
		intSlices = append(intSlices, iparam)
	}
	return
}

func main() {
	input, _ := SplitIntStdin(" ")

	output := []int{}
	output = append(output, input[2])
	output = append(output, input[0])
	output = append(output, input[1])

	fmt.Printf("%d %d %d", output[0], output[1], output[2])
}

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

// GCD, LCM
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main()
{
    int N,K,d,A[100]={},x[110]={};

    cin>>N>>K;

    for(int i=1;i<=K;i++){
        cin>>d;
        for(int i=1;i<=d;i++){
            cin>>A[i];
            x[A[i]]++;
        }
    }

    int ans=0;
    for(int i=1;i<=N;i++){
        if(x[i]<1)ans++;
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main()
{
int a , b;
cin>>a>>b;
int mult = a*b;
int sum = a+b;
int mod = a-b;
if (mult==0 && sum==0 && mod==0 )
    cout<<"0";
else if(mult>=sum && mult>mod) cout<<mult;
else if(sum>mult && sum>=mod) cout<<sum;
else if(mod>sum && mod>=mult) cout<<mod;


    return 0;
}


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

int main()
{
	int m = 0, f = 0, b = 0;
	cin >> m >> f >> b;
	if (b < m)
		cout << 0 << endl;
	else if (m + f < b)
		cout << "NA" << endl;
	else
		cout << b - m << endl;

    return 0;
}


Measured memory_bytes: 3112
# A - HonestOrDishonest

# 正直者は常にほんとうのことを言い、嘘つきは常に嘘を言います

#  文字 a  と  b  が入力として与えられます。
#  これらはそれぞれ H か D のどちらかです

# すべて AtCoDeer君の発言
# a = H or D    私が H or D
# b = H or D    TopCoDeer 君が H or D

# TopCoDeer が　正直者なら H 嘘つきなら D を出力

# 文字列 a b を標準入力から得る
a, b = map(str, input().split())
# print(a, b)

# a ⇔ H の時、 b を代入
# そうでなく、 b ⇔ H の時、 D を代入
# 上記以外の場合、 H を代入

if a == "H":
    answer = b
elif b == "H":
    answer = "D"
else:
    answer = "H"

# 結果を出力
print(answer)


Measured memory_bytes: 9020
# frozen_string_literal: true

def bsf(x)
  (x & -x).bit_length - 1
end

cnt2 = bsf(998244353 - 1)
e = 3.pow((998244353-1) >> cnt2, 998244353)
ie = e.pow(998244353 - 2, 998244353)

es = [0]*(cnt2-1)
ies = [0]*(cnt2-1)
cnt2.downto(2){ |i|
  es[i-2] = e
  ies[i-2] = ie
  e = e*e % 998244353
  ie = ie*ie % 998244353
}
now = inow = 1

@sum_e = [0]*(cnt2-2)
@sum_ie = [0]*(cnt2-2)
(cnt2-2).times{ |i|
  @sum_e[i] = es[i]*now % 998244353
  now = now*ies[i] % 998244353
  @sum_ie[i] = ies[i]*inow % 998244353
  inow = inow*es[i] % 998244353
}

def convolution(a, b)
  n = a.size
  m = b.size
  return [] if n==0 || m==0

  h = (n+m-2).bit_length
  z = 1 << h

  a = a+[0]*(z-n)
  b = b+[0]*(z-m)

  batterfly(a, h)
  batterfly(b, h)

  c = (0 ... z).map{ |i| a[i]*b[i] % 998244353 }

  batterfly_inv(c, h)

  iz = z.pow(998244353-2, 998244353)
  return c[0,n+m-1].map{ |c| c*iz % 998244353 }
end

def batterfly(a, h)
  1.upto(h){ |ph|
    w = 1 << (ph-1)
    p = 1 << (h-ph)
    now = 1
    w.times{ |s|
      offset = s << (h-ph+1)
      offset.upto(offset+p-1){ |i|
        l = a[i]
        r = a[i+p]*now % 998244353
        a[i] = l+r
        a[i+p] = l-r
      }
      now = now*@sum_e[bsf(~s)] % 998244353
    }
  }
end

def batterfly_inv(a, h)
  h.downto(1){ |ph|
    w = 1 << (ph-1)
    p = 1 << (h-ph)
    inow = 1
    w.times{ |s|
      offset = s << (h-ph+1)
      offset.upto(offset+p-1){ |i|
        l = a[i]
        r = a[i+p]
        a[i] = l+r
        a[i+p] = (l-r)*inow % 998244353
      }
      inow = inow*@sum_ie[bsf(~s)] % 998244353
    }
  }
end

_, a, b = $<.map{ |e| e.split.map &:to_i }

puts convolution(a, b).join(?\s)


Measured memory_bytes: 135684
#include<stdio.h>
#include<stdlib.h>
#define MAX_ELEMENTS 100001

typedef struct {
  int start;
  int end;
} Time;

int n;

int cmp(const void *a, const void *b) {
  Time *A = (Time *)a;
  Time *B = (Time *)b;
  return A->end - B->end;
}

void ActiveSelect(Time *A){
    int cnt=1,i,j;
    qsort(A, n, sizeof(Time), cmp);
    for(i=1,j=0;i<n;i++){
        if(A[i].start>A[j].end){
            j = i;
            cnt++;
        }
    }
    printf("%d\n",cnt);
}


int main(void){

    int i;
    Time A[MAX_ELEMENTS];

    scanf("%d", &n);
    for(i=0; i<n; i++){
    scanf("%d %d", &A[i].start , &A[i].end);
    }

    ActiveSelect(A);
    return 0;
}


Measured memory_bytes: 3016
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

// ---------------------
// repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

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

// ---------------------
#define INF 922337203685477580
#define IINF (1<<21)
typedef long long ll;

int V, E;
vector<pair<int, int> > G[10100];

int main() {
  cin >> V >> E;

  int visited[V];
  int d[V];
  int p[V];

  REP(i, E) {
    int s, t, w;
    cin >> s >> t >> w;

    G[s].push_back(make_pair(t, w));
    G[t].push_back(make_pair(s, w));
  }
  REP(i, V) {
    visited[i] = 0;
    p[i] = -1;
    d[i] = IINF;
  }


  d[0] = 0;

  REP(_, V) {
    int mincost = IINF;
    int minv = -1;
    REP(v, V) {
      if (!visited[v] && d[v] < mincost) {
        minv = v;
        mincost = d[v];
      }
    }
    visited[minv] = 1;

    for (vector<pair<int, int> >::iterator it = G[minv].begin(); it != G[minv].end(); it++) {
      int v = it->first;
      int w = it->second;

      if (!visited[v] && w < d[v]) {
        d[v] = w;
        p[v] = minv;
      }
    }
  }

  ll sum = 0;
  REP(i, V) {
    if (p[i] != -1) {
      for (vector<pair<int, int> >::iterator it = G[i].begin(); it != G[i].end(); it++) {
        if (it->first == p[i]) {
          sum += it->second;
          break;
        }
      }
    }
  }

  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 5992
def main(N,xs):
    # type: (int, List[int]) -> None
    xs.sort()
    xs.reverse() # 降順
    alice = 0
    bob = 0
    for i,x in enumerate(xs):
        if i % 2 == 0:
            alice += x
        else:
            bob += x
    print(alice-bob)
    return

if __name__ == '__main__':
    N = int(input())
    xs = list(map(int,input().split()))
    main(N,xs)


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<unordered_set>
using namespace std;
typedef long long ll;
#define N 1010
ll n;
unordered_set<ll> s;
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
	ll p[3];
	for(int j=0;j<3;j++)cin>>p[j];
	sort(p,p+3);
	ll x=p[0]*N*N+p[1]*N+p[2];
	s.insert(x);
    }
    cout<<n-s.size()<<endl;
    return 0;
}



Measured memory_bytes: 3212
package main

import "fmt"

func main(){
	var a,n int
	flag := true
	fmt.Scan(&n)
	for i := 0 ; i < n ; i++ {
		fmt.Scan(&a)
		if a % 2 == 0 {
			if a % 3 != 0 && a % 5 != 0 {
				flag = false
			}
		}
	}
	if flag {
		fmt.Println("APPROVED")
	} else {
		fmt.Println("DENIED")
	}
}


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

int main()
{
    int K;
    cin >> K;
    string ans = "";
    rep(i, K)
    {
        ans += "ACL";
    }

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

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
bool comp(pair<long long int,long long int>a,pair<long long int,long long int>b)
{
    if(a.first==b.first)
    {
        if(a.second<=b.second)
        return true;
        else
        return false;
    }
    if(a.first>b.first)
    return true;
    else return false;
}
long long int gcd(long long int bdda,long long int chota)
{
    if(chota==0)
        return bdda;
    return gcd(chota,bdda%chota);
}
void solve()
{
    int n;
    cin>>n;
    map<string,int>mp;
    string prev;
    cin>>prev;
    mp[prev]=1;
    for(int i=1;i<n;i++)
    {
        string s;
        cin>>s;
        if(s[0]!=prev[prev.length()-1])
        {
            cout<<"No";return;
        }
        prev=s;
        if(mp[prev]==1)
        {
            cout<<"No";return;
        }
        else
        mp[prev]=1;
    }
    cout<<"Yes";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;    
    t=1;

    //cin>>t;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N, A, ans;
	cin >> N;
  	cin >> A;
  	ans = N % 500;
	if(ans - A <= 0){
      cout << "Yes" << endl;
    }
  	else{
      cout << "No" << endl;
    }
}

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

int main() {
    // 制約見て！！！デカかったらlong longにすること！
    int N;
    cin >> N;
    int a;
    rep(i, N) {
        cin>>a;
        if(a % 2 == 0) {
            if(a % 5 != 0 && a % 3 != 0) {
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int>l(n);
  vector<int>a(1001);
  for(int i=0;i<n;i++){
    cin >> l.at(i);
    a.at(l.at(i))++;
  }
  int64_t ans=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      if(i!=j){
      for(int k=abs(l.at(i)-l.at(j))+1,x=min(1001,(l.at(i)+l.at(j)));k<x;k++){
        ans+=a.at(k);
        if(k==l.at(i)) ans--;
        if(k==l.at(j)) ans--;
      }
      }
    }
  }
  cout << ans/3 << endl;
  return 0;
}

Measured memory_bytes: 3656
n = int(input())
t = []
for i in range(n):
  m = int(input())
  t.append({})
  for j in range(m):
    x, y = map(int, input().split())
    t[-1][x-1] = y == 1
res = 0
for i in range(1 << n):
  s = [(i & (1 << j)) > 0 for j in range(n)]
  good = True
  for j in range(n):
    if (s[j] and any(t[j][x] != s[x] for x in t[j])) or (not s[j] and all(t[j][x] == s[x] for x in t[j])):
      good = False
      break
  if good:
    res = max(res, sum(1 for x in s if x))
print(res)
      

Measured memory_bytes: 59100
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define show(x) cout<<#x<<"="<<x<<"\n"
using namespace std;

int n;
ll t[1001],a[1001];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("/home/aim_cpo/CLionProjects/untitled/in.txt", "r", stdin);
    freopen("/home/aim_cpo/CLionProjects/untitled/out.txt","w",stdout);
#endif
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>t[i]>>a[i];
    }
    ll nowt=t[0],nowa=a[0];
    for(int i=1;i<n;i++){
        if(nowt<=t[i] && nowa<=a[i]){
            nowt=t[i];
            nowa=a[i];
        }
        else{
            ll temp1=(nowa%a[i]==0?nowa/a[i]:nowa/a[i]+1);
            ll temp2=(nowt%t[i]==0?nowt/t[i]:nowt/t[i]+1);
            nowt=t[i]*max(temp1,temp2);
            nowa=a[i]*max(temp1,temp2);
        }
        //show(nowt);
        //show(nowa);
    }
    cout<<nowa+nowt<<"\n";
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;

int main() {
	char a, b;
	cin >> a >> b;
	if (a == 'H') cout << b << endl;
	else {
		if (b == 'H') cout << 'D' << endl;
		else cout << 'H' << endl;
	}
	return 0;
}

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

using namespace std;


int main()
{
	int n;
	cin >> n;
	vector<int> w(n);
	vector<int> k(n);
	int answer = 0;

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

	for (int i = 0; i < n; i++) {
		if (w[i] - k[i] > 0) answer += w[i] - k[i];
	}

	cout << answer << endl;

    return 0;
}

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

int main() {
  int n;
  int h1, m1, s1;
  int h2, m2, s2;

  while(cin >> n, n!=0){
    int res = 0;
    signed int time[24*3600+60*60+60] = {0};
    for(int i = 0; i < n; i++) {
      scanf("%d:%d:%d", &h1, &m1, &s1);
      scanf("%d:%d:%d", &h2, &m2, &s2);
      time[h1*3600+m1*60+s1]++;
      time[h2*3600+m2*60+s2]--;
    }

    for(int i = 0; i < 24*3600+59*60+59; i++) {
      time[i+1]+=time[i];
      if(res < time[i+1])
        res = time[i+1];
    }
    cout << res << endl;
  }
  return 0;
}



Measured memory_bytes: 3468
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#include <stdexcept>
#include<queue>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
int ceil(int a,int b){// a以上bの倍数の最小値//
     return (a+b-1)/b*b;
 }
int stoii(string s){//stoi関数の代用 文字列⇒int型//
    return atoi(s.c_str());
}

char maze[51][51];
int n,m;
int sx,sy,gx,gy;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
int d[51][51];
int bfs(){
	queue<P> que;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			d[i][j]=inf;
		}
	}
	que.push(P(sx,sy));
	d[sx][sy]=0;

	while(que.size()){
		P p=que.front();
		que.pop();
		if(p.first==gx && p.second==gy) break;
		for(int i=0;i<4;i++){
			int nx=p.first+dx[i],ny=p.second+dy[i];

			if(0<=nx && nx<n && 0<=ny && ny<m && maze[nx][ny]!='#'&&d[nx][ny]==inf){
				que.push(P(nx,ny));
				d[nx][ny]=d[p.first][p.second]+1;
			}
		}
	}
	return d[gx][gy];
}
int main(){	
	int n;
	cin>>n;
	if(n<1200) cout<<"ABC"<<endl;
	else if(n<2800) cout<<"ARC"<<endl;
	else cout<<"AGC"<<endl;
	
	return 0;
}

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

public class Prime{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
         
        var primeFactors = PrimeFactors(n);
         
        string output = primeFactors.Count() == 0 
                        ? n.ToString() 
                        : string.Join(" ", primeFactors.Select (f => f.ToString()).ToArray()); //AOJ??¨
                        //:string.Join(" ", primeFactors);
        Console.WriteLine("{0}: {1}", n, output);
    }
     
    public static IEnumerable<int> PrimeFactors(int n)
    {
        int i = 2;
        int tmp = n;
         
        while (i <= tmp)
        {
            if(tmp % i == 0){
                tmp /= i;
                yield return i;
            }else{
                i++;
            }
             
            if(i > Math.Sqrt(n)){
                i = int.MaxValue; //???????????????
                yield return tmp;
            }
        }
    }
}

Measured memory_bytes: 20320
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;

#define ll long long int
#define MOD 1000000007
#define INF 1e9 + 1
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define vi vector<int>
#define vl vector<long>
#define vll vector<long long>
#define pb push_back

struct item {
	int wt,val;
};

int solve(vector<item> ar, int N, int W) {
	
	int maxval = N * 1000;
	ll dp[N+1][maxval + 1];

	for(int v = 0; v <= maxval; v++) {
		dp[1][v] = INF;	
	}
	dp[1][0] = 0;
	dp[1][ar[1].val] = ar[1].wt;
	

	for(int i = 2; i <= N; i++) {
		for(int v = 0; v <= maxval; v++) {
			dp[i][v] = dp[i-1][v];
			if(ar[i].val > v) continue;
			dp[i][v] = min(ar[i].wt + dp[i-1][v-ar[i].val],dp[i][v]);
			
		} 
	}
	int ans = 0;
	for(int x = 0; x<= maxval; x++) {
		if(dp[N][x] <= W) ans = x; 
	}
	return ans;
}


int main() {
	fast
	int t = 1;
	// cin>>t;
	while(t--) {
		int n,w;
		cin>>n>>w;
		vector<item> ar(n+1);
		for(int i = 1; i <= n; i++) cin>>ar[i].wt>>ar[i].val;


		cout<<solve(ar,n,w)<<"\n";

	}
	return 0;
}


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

int main(void){
    int N;
    int result = 0;
    vector<int> v,w;
    cin >> N;
    for(int i = 0;i < N; i++){
        int a;
        cin >> a;
        v.push_back(a);
    }
    for(int i = 0;i < N; i++){
        int a;
        cin >> a;
        w.push_back(a);
    }

    for(int i =0; i<N;i++){
        int now=0;
        for(int j = 0; j<=i;j++){
            now += v[j];
        }
        for(int j=i; j<N; j++ ){
            now += w[j];
        }
        if(now > result){
            result = now;
        }
    }


    cout << result << endl;
    return 0;
}

Measured memory_bytes: 384
import Data.Int (Int64)

computeMin :: Integral a => a -> a -> [a] -> a
computeMin a b = sum . fmap f . diff
    where f d = min b $ d * a

diff :: Num a => [a] -> [a]
diff xs = zipWith (-) (tail xs) (init xs)

main :: IO ()
main = do
    [_, a, b] <- fmap read . words <$> getLine :: IO [Int64]
    xs <- fmap read . words <$> getLine :: IO [Int64]
    print $ computeMin a b xs


Measured memory_bytes: 36220
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>

using namespace std;

int main(int argc, char* argv[])
{

	string S;
	int sum=0;

	cin >> S;

	for(int i=0;i<S.length();i++){
		if(S[i]=='1'){
			sum++;
		}
	}

	cout << sum << endl;

	return 0;

}

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

int main() {
	int a , b , c;
	cin >> a >> b;
  	c = a + b;
  	double d;
    d = a + b;
      cout << c / 2 + (d / 2 - c / 2) / 0.5 << endl;// ここにプログラムを追記
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n,r=-1;
vector<int>g[100005];
int dp[100005][2];
void dfs(int v,int p){
    int s=0,m=0;
    for(int i=0;i<g[v].size();i++){
        int u=g[v][i];
        if(u!=p){
            dfs(u,v);
            s+=dp[u][1];
            m=max(m,dp[u][1]-dp[u][0]);
        }
    }
    dp[v][1]=s-m;
    dp[v][0]=s-m;
    if(s-m==0){
        dp[v][1]=1;
    }
}
int main(void){
    cin>>n;
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for(int i=0;i<n;i++){
        if(g[i].size()>2)r=i;
    }
    if(r<0){
        cout<<1<<endl;
        return 0;
    }
    dfs(r,-1);
    cout<<dp[r][1]<<endl;
}


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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<long long> vl;

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int n;
    cin >> n;
    string s;
    cin >> s;

    // 処理
    int x    = 0;
    int maxV = 0;
    rep(i, s.size()) {
        if (s[i] == 'I') {
            x++;
        } else {
            x--;
        }
        maxV = max(maxV, x);
    }
    // 出力
    cout << maxV << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <queue>
using namespace std;

long long N, A, B;

int main() {
	cin >> N >> A >> B;
	long long S = N / (A + B);
	long long V1 = S * A;
	long long V2 = min(A, N % (A + B));
	cout << V1 + V2 << endl;
	return 0;
}

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

int main() {

    string S, T;
    cin >> S >> T;

    int ans = 0;
    rep(i, S.length()) {
        if (S[i] != T[i]) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3916
n, m = map(int, input().split(" "))
s = []
for i in range(m):
    s.append(tuple(input().split()))
tmp_ac = [0 for _ in range(n+1)]
tmp_pn = [0 for _ in range(n+1)]
end = set()
for i, x in s:
    if x == 'AC':
        if i in end:
            continue
        else:
            tmp_ac[int(i)] += 1
            end.add(i)
    else:
        if i not in end:
            tmp_pn[int(i)] += 1
        else:
            continue
for i in range(n+1):
    if tmp_ac[i] == 0:
        tmp_pn[i] = 0
ac = sum(tmp_ac)
pn = sum(tmp_pn)
print(str(ac) + " " + str(pn))

Measured memory_bytes: 29024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	
	while(true){
		int N;
		int Num[200];
		scanf("%d",&N);
		if(N==0)break;
		for(int i=0;i<2*N;i++)scanf("%d",&Num[i]);
		bool G[200][200];
		for(int i=0;i<2*N;i++){
			for(int j=0;j<2*N;j++){
				G[i][j]=false;
			}
		}
		for(int i=0;i<N;i++){
			if(Num[i]==0){
				for(int k=i+N;k<i+N+3&&k<2*N;k++){
					if(Num[k]==1){
						int j=k;
						while(j<2*N&&Num[j]==1){
							j++;
						}
						G[i][j-1]=true;
					}
					else if(Num[k]==2){
						int j=k;
						while(j>=N+1&&Num[j]==2){
							j--;
						}
						G[i][j]=true;
					}
					else{
						G[i][k]=true;
					}
				}
			}
			else if(Num[i]==1){
				int l=i;
				while(l<N&&Num[l]==1){
					l++;
				}
				l--;
				for(int k=l+N;k<l+N+3&&k<2*N;k++){
					if(Num[k]==1){
						int j=k;
						while(j<2*N&&Num[j]==1){
							j++;
						}
						G[i][j-1]=true;
					}
					else if(Num[k]==2){
						int j=k;
						while(j>=N+1&&Num[j]==2){
							j--;
						}
						G[i][j]=true;
					}
					else{
						G[i][k]=true;
					}
				}
			}
			else{
				int l=i;
				while(l>=1&&Num[l]==2)l--;
				for(int k=l+N;k<l+N+3&&k<2*N;k++){
					if(Num[k]==1){
						int j=k;
						while(j<2*N&&Num[j]==1){
							j++;
						}
						G[i][j-1]=true;
					}
					else if(Num[k]==2){
						int j=k;
						while(j>=N+1&&Num[j]==2){
							j--;
						}
						G[i][j]=true;
					}
					else{
						G[i][k]=true;
					}
				}
			}
		}
		for(int i=N;i<2*N;i++){
			if(Num[i]==0){
				for(int k=i-N;k<i-N+3&&k<N;k++){
					if(Num[k]==1){
						int j=k;
						while(j<N&&Num[j]==1){
							j++;
						}
						G[i][j-1]=true;
					}
					else if(Num[k]==2){
						int j=k;
						while(j>=1&&Num[j]==2){
							j--;
						}
						G[i][j]=true;
					}
					else{
						G[i][k]=true;
					}
				}
			}
			else if(Num[i]==1){
				int l=i;
				while(l<2*N&&Num[l]==1){
					l++;
				}
				l--;
				for(int k=l-N;k<l-N+3&&k<N;k++){
					if(Num[k]==1){
						int j=k;
						while(j<N&&Num[j]==1){
							j++;
						}
						G[i][j-1]=true;
					}
					else if(Num[k]==2){
						int j=k;
						while(j>=1&&Num[j]==2){
							j--;
						}
						G[i][j]=true;
					}
					else{
						G[i][k]=true;
					}
				}
			}
			else{
				int l=i;
				while(l>=N+1&&Num[l]==2)l--;
				for(int k=l-N;k<l-N+3&&k<N;k++){
					if(Num[k]==1){
						int j=k;
						while(j<N&&Num[j]==1){
							j++;
						}
						G[i][j-1]=true;
					}
					else if(Num[k]==2){
						int j=k;
						while(j>=1&&Num[j]==2){
							j--;
						}
						G[i][j]=true;
					}
					else{
						G[i][k]=true;
					}
				}
			}
		}
		int SS[200];
		for(int i=0;i<200;i++)SS[i]=1000;
		SS[0]=0;SS[N]=0;
		if(Num[0]==1){
			int I=0;
			while(Num[I]==1&&I<N){
				SS[I]=0;
				I++;
			}
			SS[I]=1000;
		}
		if(Num[N]==1){
			int I=N;
			while(Num[I]==1&&I<2*N){
				SS[I]=0;
				I++;
			}
			
			SS[I]=1000;
		}
		for(int k=0;k<2*N;k++){
			for(int i=0;i<2*N;i++){
				for(int j=0;j<2*N;j++){
					if(G[j][i]){
						SS[i]=min(SS[i],SS[j]+1);
					}
				}
			}
		}
		
		int ans=min(SS[N-1],SS[2*N-1]);
		if(ans==1000)printf("NA\n");
		else printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1240
import queue

h, w = map(int, input().split())
s = '#'*(w+2)
for _ in range(h):
    s += '#' + input() +'#'
s += '#'*(w+2)

ans = 0
for i in range((w+2)*(h+2)):
    if s[i] == '#':
        continue
    dist = [10**10]*(w+2)*(h+2)
    dist[i] = 0
    q = queue.Queue()
    q.put(i)
    while not q.empty():
        x = q.get()
        for j in (1, -1, w+2, -w-2):
            if s[j+x] =='#':
                continue
            if dist[j+x] > dist[x] + 1:
                dist[j+x] = dist[x] + 1
                ans = max(ans, dist[j+x])
                q.put(j+x)

print(ans)



Measured memory_bytes: 3952
/*
	カードゲーム
	http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_9_C&lang=jp
*/

package main

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

// 標準入力を取得するScannerのインスタンスを作成
var sc = bufio.NewScanner(os.Stdin)

// 標準入力で各行を読み込み文字列として返す
func readLine() string {
	if sc.Scan() {
		return sc.Text()
	}
	return ""
}

//　カードの一覧を渡し、nターン分の勝負判定を行う
// 二人の得点を返す
func judged(t, h []string) (tp, hp int) {
	n := len(t)
	for i := 0; i < n; i++ {
		if t[i] > h[i] {
			tp += 3
		} else if t[i] < h[i] {
			hp += 3
		} else {
			tp++
			hp++
		}
	}
	return tp, hp
}

func main() {
	// 改行区切りから単語(スペース)区切りで読み込むように変更する
	sc.Split(bufio.ScanWords)

	// カード枚数を取得する
	n, _ := strconv.Atoi(readLine())

	// 太郎のカード
	t := make([]string, 0, n)

	// 花子のカード
	h := make([]string, 0, n)

	// カードの情報を読み込む
	for n > 0 {
		t = append(t, readLine())
		h = append(h, readLine())
		n--
	}
	fmt.Println(judged(t, h))
}


Measured memory_bytes: 1128
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
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;}
ll ceilll(ll a, ll b) {return (a + b-1) / b;} // if(a%b == 0) (a/b) + 1
ll get_digit(ll a) {ll digit = 0; while(a != 0){a /= 10; digit++;} return digit;} // a != 0
template<typename T> void vecdbg(vector<T>& v){ rep(i, v.size()){cout << v[i] << " ";} br;}
template<typename T> void vecvecdbg(vector<vector<T>>& v){ rep(i, v.size()){rep(j, v[i].size()){cout << v[i][j] << " ";} br;}}

// 0 false, 1 true 
// string number to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp
// global vector -> 0 initialization

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll d, t, s; cin >> d >> t >> s;
    if((d + s-1) / s <= t){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 3612
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#include<random>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (int)(Y);++(X))
#define reps(X,S,Y) for (int (X) = (int)(S);(X) < (int)(Y);++(X))
#define rrep(X,Y) for (int (X) = (int)(Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (int)(Y)-1;(X) >= (int)(S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
const ll MOD=1e9+7; //998244353

map<ll,ll> memo;
vector<ll> coef(10);

ll fun(ll n){
	if(n==0) return 0;
	if(memo.count(n)) return memo[n];
	__int128 re=n; re*=coef[0];
	// if(re<0){
	// 	out(re,1);
	// 	exit(0);
	// }
	for(int x:{2,3,5}){
		ll rem=n%x;
		MN<__int128>(re,fun(n/x)+coef[x]+rem*coef[0]);
		// if(re<0){
		// 	out(fun(n/x)+coef[x]+rem*coef[0],1);
		// 	exit(0);
		// }
		if(rem && (n+x-1)/x<n){
			MN<__int128>(re,fun((n+x-1)/x)+coef[x]+(x-rem)*coef[0]);
			// if(re<0){
			// 	out(fun((n+x-1)/x)+coef[x]+(x-rem)*coef[0],1);
			// 	exit(0);
			// }
		}
	}
	return memo[n]=ll(re);
}

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	int T;
	cin>>T;
	while(T--){
		ll n,a,b,c,d;
		cin>>n>>a>>b>>c>>d;
		coef[2]=a;
		coef[3]=b;
		coef[5]=c;
		coef[0]=d;
		memo.clear();
		cout<<fun(n) NL;;
	}
  return 0;
}


Measured memory_bytes: 4428
from collections import deque

n, q = map(int, input().split())

tree = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

counter = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    counter[p-1] += x

que = deque()

for a in tree[0]:
  que.append([0,a])
  #[親ノード,子ノード].ここでは頂点1に隣接している頂点の組をキューに加えている

while que:
    parent, node = que.popleft()
    #親ノードのカウンターは子ノードに遺伝する
    counter[node] += counter[parent]
    for leaf in tree[node]:
      if leaf != parent:
        que.append([node, leaf]) #子ノードの葉をキューに加える　      

print(*counter)


Measured memory_bytes: 63156
#include <iostream>
#include <algorithm>

using namespace std;

int main() {

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

    sort(v, v+N);

    float a = v[0];

    for (int i = 1; i < N; i++) {
        a = (a + v[i]) / 2;
    }

    cout << a;

    return 0;
}



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

std::pair<int,int> ans[1000010];
int p =1;
int main()
{
	int a;
	scanf("%d",&a);
	if(a%2==0)
	{
		for(int i=1;i<=a;i++)
		{
			for(int j=i+1;j<=a;j++)
			{
				if(i+j==a+1) continue;
				ans[p++] = std::make_pair(i,j);
			}
		}
	}
	else
	{
		for(int i=1;i<=a;i++)
		{
			for(int j=i+1;j<=a;j++)
			{
				if(i+j==a) continue;
				ans[p++] = std::make_pair(i,j);
			}
		}
	}
	printf("%d\n",p-1);
	for(int i=1;i<p;i++) printf("%d %d\n",ans[i].first,ans[i].second);
}

Measured memory_bytes: 256
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include <math.h>
using namespace std;
# define maxn 100000 

int main(){
  double sum(0);
  int N,K;
  cin>>N>>K;
  for(int i(1);i<=N;i++){
    int tmp=i;
    int cnt(0);
    for(int j(1);j<=K;j++){
      if (tmp>=K){
        break;
      }
      tmp*=2;
      cnt+=1;
    }
    sum += 1.0/powl(2.0,cnt);
  }
  cout << setprecision(15)<< sum/N;
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w;
  cin >> h >> w;
  int n;
  cin >> n;
  VI a(n);
  VVI ans(h, VI(w));
  rep(i, n) cin >> a[i];
  int count = 0;
  rep(i, n) rep(j, a[i]) {
    int hh = count / w;
    int ww;
    hh % 2 == 0 ? ww = count % w : ww = w - 1 - count % w;
    ans[hh][ww] = i + 1;
    count++;
  }
  rep(i, h) {
    rep(j, w) {
      cout << ans[i][j] << ' ';
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 384
S=list(input())
N=len(S)

for i in range(1,N):
  if S[i-1]==S[i]:
    print(i,i+1)
    exit()
    
for i in range(2,N):
  if S[i-2]==S[i]:
    print(i-1,i+1)
    exit()
    
print(-1,-1)

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int x, n; cin >> x >> n;
    vector<int> cnt(n + 10, 0);
    for (int i = 0; i < n; ++i) {
        int p; cin >> p;
        cnt[p]++;
    }

    int ans = -1;
    int ab = INF;
    for (int i = -100; i <= 200; ++i) {
        if (cnt[i] == 0) {
            int t = abs(x - i);
            if (t < ab) {
                ans = i;
                ab = t;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3648