akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
struct Bipartite_Matching
{
  vector< vector< int > > graph;
  vector< int > match, alive, used;
  int timestamp;
 
  Bipartite_Matching(int n)
  {
    timestamp = 0;
    graph.resize(n);
    alive.assign(n, 0);
    used.assign(n, 0);
    match.assign(n, -1);
  }
 
  void add_edge(int u, int v)
  {
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
 
  bool dfs(int v)
  {
    used[v] = timestamp;
    for(int i = 0; i < graph[v].size(); i++) {
      int u = graph[v][i], w = match[u];
      if(alive[u] == 0) continue;
      if(w == -1 || (used[w] != timestamp && dfs(w))) {
        match[v] = u;
        match[u] = v;
        return (true);
      }
    }
    return (false);
  }
 
  int bipartite_matching()
  {
    int ret = 0;
    for(int i = 0; i < graph.size(); i++) {
      if(alive[i] == 0) continue;
      if(match[i] == -1) {
        ++timestamp;
        ret += dfs(i);
      }
    }
    return (ret);
  }
 
  int add(int k)
  {
    alive[k] = 1;
    ++timestamp;
    return (dfs(k));
  }
 
};
 
int main()
{
  int N, A[150000], idx[150000];
  vector< int > g[150000];
  bool dep[150000] = {};
 
  cin >> N;
  ++N;
  for(int i = 1; i < N; i++) {
    cin >> idx[i];
    g[idx[i]].push_back(i);
    dep[i] = dep[idx[i]] ^ 1;
  }
 
  Bipartite_Matching flow(N);
  vector< int > left, right;
  for(int i = 0; i < N; i++) {
    if(dep[i]) left.push_back(i);
    else right.push_back(i);
  }
 
  for(int i = 1; i < N; i++) {
    int oi, beet;
    if(dep[i]) oi = lower_bound(begin(left), end(left), i) - begin(left);
    else oi = (int) (lower_bound(begin(right), end(right), i) - begin(right)) + left.size();
 
    if(dep[idx[i]]) beet = lower_bound(begin(left), end(left), idx[i]) - begin(left);
    else beet = (int) (lower_bound(begin(right), end(right), idx[i]) - begin(right)) + left.size();
 
    flow.add_edge(oi, beet);
  }
  flow.alive[(int) (lower_bound(begin(right), end(right), 0) - begin(right)) + left.size()] = true;
 
  flow.bipartite_matching();
  int ret = 0;
  for(int i = 1; i < N; i++) {
    int oi;
    if(dep[i]) oi = lower_bound(begin(left), end(left), i) - begin(left);
    else oi = (int) (lower_bound(begin(right), end(right), i) - begin(right)) + left.size();
    ret += flow.add(oi);
    cout << ret << endl;
  }
 
 
}

Measured memory_bytes: 7084
//
// Created by Tzyark on 2018/10/10.
//
#include <iostream>
using namespace std;
int H, W;
char C[101][101];
int main() {
    cin >> H >> W;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            cin >> C[i][j];
        }
    }
    for (int i = 1; i <= 2*H; i++) {
        for (int j = 1; j <= W; j++) {
            cout << C[(i+1)/2][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
# ABC080
# C. Shopping Street

n = gets.chomp.to_i

f_ = []
n.times do 
  f_ << gets.chomp.split(" ").map(&:to_i)
end

p_ = []
n.times do 
  p_ << gets.chomp.split(" ").map(&:to_i)
end

profits = []
1.upto((1<<10) - 1) do |b|
  prft = 0
  n.times do |i|
    # Store
    c = 0
    10.times do |j|
      # Time
      if (((b >> j) & 1) & f_[i][j]) == 1 then
        c += 1
      end
    end
    prft += p_[i][c]
  end
  profits << prft
end

puts profits.max

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)

typedef long long ll;

class Node {
 public:
  int key;
  Node* parent;
  Node* left;
  Node* right;

  Node() {}
};

Node* NIL;
Node* root;

void Insert(const int& key) {
  Node* y = NIL;
  Node* x = root;
  Node* z = new Node();
  z->key = key;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL) {
    y = x;
    if (z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;
  if (y == NIL) {
    root = z;
  } else if (z->key < y->key) {
    y->left = z;
  } else {
    y->right = z;
  }
}

void PrintInorder(const Node* node) {
  if (node == NIL) return;
  PrintInorder(node->left);
  cout << " " << node->key;
  PrintInorder(node->right);
}

void PrintPreorder(const Node* node) {
  if (node == NIL) return;
  cout << " " << node->key;
  PrintPreorder(node->left);
  PrintPreorder(node->right);
}

int main() {
  root = NIL;
  int n;
  cin >> n;
  FOR(i, 0, n) {
    string str;
    cin >> str;
    if (str == "insert") {
      int key;
      cin >> key;
      Insert(key);
    } else if (str == "print") {
      PrintInorder(root);
      cout << endl;
      PrintPreorder(root);
      cout << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 26600
package main

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

func bisectLeft(a []int, x int) int {
	lo := 0
	hi := len(a)
	for lo < hi {
		mid := (lo + hi) / 2
		if a[mid] < x {
			lo = mid + 1
		} else {
			hi = mid
		}
	}
	return lo
}

func main() {
	N := readInt()
	L := make([]int, N)
	for i := 0; i < N; i++ {
		L[i] = readInt()
	}

	sort.Sort(sort.IntSlice(L))
	result := 0
	for i := 0; i < N-2; i++ {
		for j := i + 1; j < N-1; j++ {
			x := L[i] + L[j]
			result += bisectLeft(L, x) - (j + 1)
		}
	}
	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


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

int n, m, j = 0;
int a[100000], b[100001];
const int D = 1000000007;

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

	for (int i = 0; i < m; i++)
		cin >> a[i];

	b[0] = 1;

	for (int i = 1; i <= n; i++) {
		if (i == a[j]) {
			b[i] = 0;
			if(j < m - 1)
				j++;
		}
		else if (i == 1)
			b[i] = b[0];
		else
			b[i] = (b[i - 1] + b[i - 2]) % D;
	}

	cout << b[n] << endl;

	return 0;
}

Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    long long N, T; cin >> N >> T;
    vector<long long> t(N);
    for (int i = 0; i < N; i++) cin >> t[i];
    long long ans = 0;
    for (int i = 1; i < N; i++) ans += min(T, t[i] - t[i-1]);
    ans += T;
    cout << ans << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 4740
n, m = (int(x) for x in input().split())
A = []
for i in range(n):
    A.append([int(j) for j in input().split()])
b = []
for i in range(m):
  b.append(int(input()))

B = [0 for i in range(n)]
for i in range(n):
    for j in range(m):
        B[i] += A[i][j] * b[j]

for v in B:
    print(v)


Measured memory_bytes: 6012
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main {

	static Scanner sc = new Scanner(System.in);

	static class FastScanner {
		private final InputStream in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		public FastScanner(InputStream source) {
			in = source;
		}

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte()) return buffer[ptr++];
			else return -1;
		}

		private static boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		public boolean hasNext() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
			return hasNextByte();
		}

		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

		public int nextInt() {
			long nl = nextLong();
			if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
				throw new NumberFormatException();
			return (int) nl;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	public static void main(String[] args){

		solve_abc162_a();
	}
  
  
	public static void solve_abc162_a(){

		FastScanner sc = new FastScanner(System.in);
		
		String s = sc.next();
		
		boolean b = false;
		
		for(int i=0;i<3;i++){
			
			if(s.charAt(i) == '7') b = true;
		}
		
		if(b) System.out.println("Yes");
		else System.out.println("No");
		
		
	}
}

Measured memory_bytes: 27040
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;

    map<ll, ll> mp;
    rep(i, n) {
        ll a;
        cin >> a;
        mp[a]++;
    }

    vl v;
    for(auto p : mp) {
        if(p.second >= 4) {
            rep(i, 2) {
                v.pb(p.first);
            }
        }
        else if(p.second >= 2) {
            v.pb(p.first);
        }
    }
    sort(rall(v));

    if(v.size() < 2) {
        out(0);
    }
    else {
        out(v[0]*v[1]);
    }
    
    re0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c,x,s=0;
  cin>>a>>b>>c>>x;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        if(500*i+100*j+50*k==x) s++; 
      }
    }
  }
  cout<<s<<endl;
}

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

int main() {
    int i=0, n, red=0, blue=0;
    char str[101];
    scanf("%d", &n);
    scanf("%s", str);
    
    while(i < n) {
        if (str[i] == 'R') {red++;}
        else {blue++;}
        i++;
    }

    if (red > blue) {puts("Yes");}
    else {puts("No");}

    return 0;
}

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

int main() {
  string s;
  cin >> s;
  bool flag = false;
  for(int i = 1; i < s.size(); i++) {
    if(s[i-1] == s[i]) flag = true;
  }
  if(flag) cout << "Bad" << endl;
  else cout << "Good" << endl;
}

Measured memory_bytes: 3632
#!/usr/bin/env python3

x, y = [int(x) for x in input().split()]
p = [300000, 200000, 100000]
if x == 1 and y == 1:
    print(1000000)
elif x <= 3 and y <= 3:
    print(p[x - 1] + p[y - 1])
elif x <= 3:
    print(p[x - 1])
elif y <= 3:
    print(p[y - 1])
else:
    print(0)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    System.out.println(solve(n));
    sc.close();
  }
  
  public static long solve(long h) {
    if(h == 1) return 1;
    return 2*solve(h/2)+1;
  }
}

Measured memory_bytes: 35628
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    int n;
    cin >> n;
    int cnt = 0;
    rep(i,n) {
        int a, b;
        cin >> a >> b;
        if (a == b) cnt++;
        else cnt = 0;
        if (cnt == 3) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3616
import java.util.*;
import java.lang.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        if(x<1200){
            System.out.println("ABC");
        }else{
            System.out.println("ARC");
        }
        sc.close();
    }
}

Measured memory_bytes: 22868
import math
[a,b,x]=list(map(int,input().split()))
if a*a*b/2<=x:
	A=b/a
	B=x/(a*a*a)
	tan=((A**2-B**2)/(A+B))*2
	thita=math.atan(tan)
	dosu=math.degrees(thita)
else:	
	tan=2*x/(a*b*b)
	thita=math.atan(tan)
	dosu=90-math.degrees(thita)
print(dosu)

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

int main() {
    while(true) {
        int x, y, s;
        cin >> x >> y >> s;
        if(x == 0) break;
        int ans = 0;
        for(int x0 = 1; x0 < s; x0++) {
            for(int y0 = 1; y0 < s; y0++) {
                int newx = x0 * (100 + x) / 100;
                int newy = y0 * (100 + x) / 100;
                if(newx + newy != s) continue;
                int newsum = x0 * (100 + y) / 100 +y0 * (100 + y) / 100;
                ans = max(ans, newsum);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> g(h);
    rep(i, h) cin >> g[i];

    int res = 0;

    rep(i, 1 << h) rep(j, 1 << w) {
        int cnt = 0;
        rep(y, h) rep(x, w) {
            if ((i >> y) & 1) continue;
            if ((j >> x) & 1) continue;
            if (g[y][x] == '#') cnt++;
        }
        if (cnt == k) res++;
    }

    cout << res << endl;
    return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;

  if(a<b){
    for(int i=0;i<b;i++){
      cout << a;
    }
    cout << endl;
  }
  else{
    for(int i=0;i<a;i++){
      cout << b;
    }
    cout << endl;
  }

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;


int main() {
    int a, b, k;
    cin >> a >> b >> k;

    int tmp = 0;

    int min;
    if (a > b) {
        min = b;
    } else {
        min = a;
    }

    int ans;
    for (int i = min; i >= 1; --i) {
        if (a % i == 0 && b % i == 0) {
            tmp++;
            if (tmp == k) {
                ans = i;
                break;
            }
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)	cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
#define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 200005
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 1005;
const long double epsilon = 1e-9;
ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinvfermat(ll a, ll m)
{
	return binexp(a, m - 2, m);
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}
vl fact(500005);
ll ncrmodp(ll n, ll r, ll p)
{
	ll res = fact[n] % MOD;
	res = (res % MOD * modinvfermat(fact[r], MOD) % MOD) % MOD;
	res = (res % MOD * modinvfermat(fact[n - r], MOD) % MOD) % MOD;
	return res;
}
signed main() {

	fast
	ll n, m;
	cin >> n >> m;
	fact[0] = 1;
	FOR(i, 1, m + 1)
	{
		fact[i] = (fact[i - 1] % MOD * i % MOD) % MOD;
	}
	ll r, s = 0;
	r = (ncrmodp(m, n, MOD) % MOD * fact[n] % MOD) % MOD;
	// cout << r << END;
	loop(j, n + 1)
	{
		ll val = ncrmodp(n, j, MOD);
		val = (val * ncrmodp(m - j, n - j, MOD)) % MOD;
		val = (val * fact[n - j]) % MOD;
		// cout << val << END;
		if (j & 1)
			s = (s - val + MOD) % MOD;
		else
			s = (s + val) % MOD;
		s = (s + MOD) % MOD;
	}
	ll ans = (r % MOD * s % MOD) % MOD;
	cout << ans << END;




	return 0;
}


Measured memory_bytes: 6968
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (unsigned long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (unsigned long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end())
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl

// gcc拡張マクロ
#define gcd __gcd
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    int n;
    cin >> n;

    // ceil(N/2)部グラフ、それぞれの部は和が等しくN+1-N%2になるように
    vector<pair<int, int>> ans;
    if (n % 2) {
        RANGE(i, 1, n-1) ans.emplace_back(i, n);
        n--;
    }
    RANGE(i, 1, n/2) {
        const int j = n - i + 1;
        RANGE(p, 1, n) {
            if (p == i || p == j) continue;
            ans.emplace_back(i, p);
            ans.emplace_back(j, p);
        }
    }

    // 被った辺は削除
    for (auto &p : ans) if (p.first > p.second) swap(p.first, p.second);
    sort(ALL_OF(ans));
    UNIQUE(ans);

    // 出力
    cout << ans.size() << endl;
    for (const auto &p : ans) {
        cout << p.first << " " << p.second << endl;
    }

    
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#define lli long long int
#include<climits>
#define pb push_back
using namespace std;


int main()
{
    
    int h,w,i,j;
    cin>>h>>w;
    
    vector<vector<int>>dp1(h+1,vector<int>(w+1));
    vector<vector<int>>dp2(h+1,vector<int>(w+1));
    vector<vector<int>>dp3(h+1,vector<int>(w+1));
    
    for(i=1;i<=h;i++)
        for(j=1;j<=w;j++)
            cin>>dp1[i][j];
    
    for(i=1;i<=h;i++)
        for(j=1;j<=w;j++)
            cin>>dp2[i][j];
    
    for(i=1;i<=h;i++)
        for(j=1;j<=w;j++)
            dp3[i][j] = abs(dp1[i][j]-dp2[i][j]);
    
    vector<vector<vector<int>>>dp(h+1,vector<vector<int>>(w+1,vector<int>(12801,0)));
    
    dp[h][w][abs(dp3[h][w])] = 1;
    
    for(i=h,j=w-1;j>=1;j--)
        for(int k=0;k<=12801;k++)
            if(dp[i][j+1][k]==1)
            {
                dp[i][j][abs(k+dp3[i][j])] = 1;
                dp[i][j][abs(k-dp3[i][j])] = 1;
            }
    
    for(i=h-1;i>=1;i--)
    {
        for(j=w;j>=1;j--)
        {
            if(j==w)
            {
                for(int k=0;k<=12801;k++)
                    if(dp[i+1][j][k]==1)
                    {
                        dp[i][j][abs(k+dp3[i][j])] = 1;
                        dp[i][j][abs(k-dp3[i][j])] = 1;
                    }
            }
            
            else
            {
                for(int k=0;k<=12801;k++)
                {
                    if(dp[i+1][j][k]==1)
                    {
                        dp[i][j][abs(k+dp3[i][j])] = 1;
                        dp[i][j][abs(k-dp3[i][j])] = 1;
                    }
                    if(dp[i][j+1][k]==1)
                    {
                        dp[i][j][abs(k+dp3[i][j])] = 1;
                        dp[i][j][abs(k-dp3[i][j])] = 1;
                    }
                }
            
            }
        }
    }
    
    
    int mymin = INT_MAX;
    for(int k=0;k<=12801;k++)
    {
        if(dp[1][1][k]==1) mymin = min(k,mymin);
        
    }
    cout<<mymin<<endl;
    
    
    
}



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

using namespace std;
using ll = long long int;

int main(void){
  int n; cin >> n;
  vector<int> a(n);
  ll ver = 0, hol = 0;
  
  for(int i = 0;i < n;i++) cin >> a[i];
  
  sort(a.begin(), a.end(), greater<int>());
  
  for(int i = 0;i < n-1;i++){
    if(a[i] == a[i+1]){
      if(ver == 0) ver = a[i];
      else if(hol == 0) hol = a[i];
      i++;
    }
  }
  
  cout << ver * hol << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#define MAX_N 10010
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
struct edge
{
    int to, cost;
};
int n;
vector<edge> G[MAX_N];
void dijkstra()
{
    priority_queue<P, vector<P>, greater<P>> que;
    vector<int> d(MAX_N, INF);
    d[0] = 0;
    que.push(P(0, 0));
    while(!que.empty())
    {
        P p = que.top(); que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(int i = 0; i < G[v].size(); i++)
        {
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost)
            {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
    for(int i = 0; i < n; i++) cout << i << " " << d[i] << endl;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        int u, k;
        cin >> u >> k;
        for(int j = 0; j < k; j++)
        {
            int v, c;
            cin >> v >> c;
            edge e = {v, c};
            G[u].push_back(e);
        }
    }
    dijkstra();
    return 0;
}




Measured memory_bytes: 8116
n = int(input())
a = list(map(int, input().split()))

'''
a b c d e

ab + ac + ad + ae + bc + bd + be + cd + ce + de
=
a(b+c+d+e) + b(c+d+e) + c(d+e) + d(e)
=
(a+b+c+d)e + (a+b+c)d + (a+b)c + a(b)
'''
l = 0
s = 0
for i in range(n-1):
    l += a[i]
    s += l*a[i+1]
    s %= 1000000007
print(s)


Measured memory_bytes: 31412
N = int(input())

endwithA = 0
startwithB = 0
BandA = 0
ABCount = 0
ans = 0

for i in range(N):
    s = input()

    if s[0] == "B":
        if s[-1] == "A":
            BandA += 1
        else:
            startwithB += 1
    elif s[-1] == "A":
        endwithA += 1

    for index in range(len(s)):
        if index == 0:
            continue
        elif s[index-1] == "A" and s[index] == "B":
            ABCount += 1

# Bで終わりAで始まっている個数と、A終了とB開始の数を比較
if BandA > 0:
    if startwithB > 0:
        ans += 1
        startwithB -= 1
    if endwithA > 0:
        ans += 1
        endwithA -= 1
    ans += BandA - 1

ans += min(startwithB,endwithA)
ans += ABCount

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
#define EPS (1e-10)
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

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

signed main(){
	int n; cin>>n;
	VL a(n); rep(i,n) cin>>a[i];
	VL b(n); ll r=0LL;	rep(i,n) b[i]=a[i]+r, r=b[i];
	
	ll l=b[n-1];
	ll ans=LINF;
	rep(i,n) chmin(ans, abs(b[i]-(l-b[i])));
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3456
#include <cstdio>

int main()
{
	int a,b,c;
	scanf("%d %d %d", &a, &b, &c);
	if(a*b<c)
	{
		printf("%d", a*b);
	}
	else if(a*b<=c)
	{
		printf("%d", c);
	}
	else if(a*b>c)
	{
		printf("%d", c);
	}
	else if(a*b>=c)
	{
		printf("%d",c);
	}
}
	
	
	

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

#define int long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define all(c) (c).begin(),(c).end()
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;
const ld PI = acos(-1.0);

int32_t main(){
	fast;
	int n;
	
	cin >> n;
	
	map<pair<int,int> , int> m;
	
	for(int i=1 ; i <= n ;i++)
	{
		string s = to_string(i);
		int l = s[0] - '0';
		int r = s[s.size() - 1] - '0';
		m[{l,r}]++;
	}
	
	int ans = 0;
	for(auto x : m)
	{
		int l = x.F.F;
		int r = x.F.S;
		
		ans += x.S * m[{r,l}];
	}
	
	cout << ans;
}



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

int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b==c+d)cout<<"Balanced"<<endl;
  else if(a+b>c+d)cout<<"Left"<<endl;
  else cout<<"Right"<<endl;
  return 0;
}


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

struct UnionFind {
    vector<int> par;

    UnionFind(int N) : par(N){
        rep(i,N)par[i]=i;
    }

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

    void unite(int x, int y){
        if(root(x)==root(y))return;
        par[root(x)]=root(y);
    }

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

int main(){
    int N,M; cin>>N>>M;
    priority_queue<tuple<int,int,int>,vector<tuple<int,int,int>>,greater<tuple<int,int,int>>> E;
    rep(i,M){
        int a,b,c;
        cin>>a>>b>>c;
        tuple<int,int,int> q=tuple<int,int,int>(c,a,b);
        E.push(q);
    }
    UnionFind tree(N);
    int ans=0;

    while(!E.empty()){
        tuple<int,int,int> v = E.top();
        E.pop();
        if(!tree.same(get<1>(v),get<2>(v))){
            ans+=get<0>(v);
            tree.unite(get<1>(v),get<2>(v));
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 4532
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void) {
	string s, t;
	cin >> s >> t;
	vector<string> words;
	if (s.size() >= t.size()) {
		for (int i = 0; i <= s.size() - t.size(); ++i) {
			string w = s;
			bool ok = true;
			for (int j = i; j < i + t.size(); ++j) {
				if (w[j] != t[j - i] && w[j] != '?')
					ok = false;
			}
			if (ok) {
				for (int j = i; j < i + t.size(); ++j)
					w[j] = t[j - i];
				for (int j = 0; j < s.size(); ++j)
					if (w[j] == '?') w[j] = 'a';
				words.push_back(w);
			}
		}
	}
	string ans = "UNRESTORABLE";
	if (words.size() > 0) {
		sort(words.begin(), words.end());
		ans = words[0];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		int A,B;
		Scanner sc = new Scanner(System.in);
		A = sc.nextInt();
		B = sc.nextInt();
		Main main = new Main();
		main.Count(A, B);
	}

	private void Count(int A,int B) {
		if (B==1) {
			System.out.println(0);
			return;
		}
		if (B<=A) {
			System.out.println(1);
			return;
		}
		int now = A;
		for (int i=1;i<100;i++) {
			now +=A-1;
			if (now >=B) {
				System.out.println(i+1);
				return;
			}
		}
	}
}


Measured memory_bytes: 23764
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//数値計算 個数以外はdouble
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//過半数：N/2.0で判定
//優先度付きキュー
//priority_queue<
//ll,
//vector<ll>
//> q;
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
#define PI 3.14159265358979323846264338327950L
using namespace std;


//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

ll RS(ll N, ll P, ll M) {
	if (P == 0) return 1;
	if (P % 2 == 0) {
		ll t = RS(N, P / 2, M);
		return t * t % M;
	}
	return N * RS(N, P - 1, M);
}

int main() {
	double A, B; cin >> A >> B;
	double H, M; cin >> H >> M;

	double th1 = 2 * PI * (M / 60.0);
	double th2 = 2 * PI * (H / 12.0) + PI / 6.0 * (M / 60.0);
	double th = abs(th1 - th2);
	if (th > PI) th = 2 * PI - th;
	
	cout << setprecision(20) << sqrt(A * A + B * B - 2 * A * B * cos(th)) << endl;
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
     cin >> x;
     if(x % 7 == 0)Cout("thu");
     else if(x % 7 == 1)Cout("fri");
     else if(x % 7 == 2)Cout("sat");
     else if(x % 7 == 3)Cout("sun");
     else if(x % 7 == 4)Cout("mon");
     else if(x % 7 == 5)Cout("tue");
     else if(x % 7 == 6)Cout("wed");
     

       
return 0;
}



Measured memory_bytes: 3252
#include<stdio.h>

int main()
{
    int N,i,sum=0;
    scanf("%d", &N);
    int A[N],B[N];
    for(i=0;i<N-1;i++){
        scanf("%d", &B[i]);
    }
    A[0]=B[0];
    A[N-1]=B[N-2];
    for(i=1;i<N-1;i++){
        if(B[i]>B[i-1]){
            A[i]=B[i-1];
        }
        else{
            A[i]=B[i];
        }
    }
    for(i=0;i<N;i++){
        sum=sum+A[i];
    }
    printf("%d\n", sum);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;

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

int main(){
    int a, b; cin>>a>>b;
    int ans=0;
    for(int i=a; i<=b; i++){
        string s=to_string(i);

        bool can_count=true;
        for(int j=0; j<5; j++){
            if(s[j]!=s[4-j]) can_count=false;
        }

        if(can_count) ans++;
    }
    cout << ans << endl;
}


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

signed main() {
	int n;
	cin >> n;
	vector<int> a(n);

	for (auto &e : a) cin >> e;

	int mine = INT_MAX, maxe = INT_MIN, sum = 0;

	for (auto e : a) {
		mine = min(mine, e);
		maxe = max(maxe, e);
		sum += e;
	}

	cout << mine << ' ' << maxe << ' ' << sum << endl;
}



Measured memory_bytes: 3148
a,b=map(int,input().split())
 
x=(a*100)//8
x=x-10

flag=0
for i in range(1,1009):
  if int(i*0.08)==a and int(i*0.1)==b:
    print(i)
    flag=1
    break

if flag==0:
  print(-1)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
#include <set>
using namespace std;
using Int = int64_t;
const Int INF = 1<<30;
const Int MOD = (Int)1e9 + 7;
const Int MAX_N = (Int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    string s; cin >> s;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == '?') s[i] = 'D';
    }
    cout << s << endl;
}

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

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

int main(void){
    int h,w,m;
    cin >> h >> w >> m;
    vector<pair<int,int>> t;
    vector<long>a(h),b(w),e(h),f(w);
    rep(i,m){
        int c,d;
        cin >> c >> d;
        c--;d--;
        t.emplace_back(c,d);
        a[c]++;
        b[d]++;
    }
    long maxh=0,maxw=0,k=0,l=0;
    rep(i,h) maxh = max(maxh,a[i]);
    rep(i,w) maxw = max(maxw,b[i]);
    rep(i,h){
        if(a[i]==maxh){
            e[i]=1;
            k++;
        } 
    }
    rep(i,w){
        if(b[i]==maxw){
            f[i]=1;
            l++;
        }
    }
    long cnt = l*k;
    for(auto i:t){
        if(e[i.first]&&f[i.second]) cnt--;
    }
    if(cnt==0) cout << maxh+maxw-1 << endl;
    else cout << maxw+maxh << endl;
}

Measured memory_bytes: 16840
N=int(input())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))

answer=0
for i in range(N):
  dmg=min(alist[i],blist[i])    
  alist[i]-=dmg
  blist[i]-=dmg
  answer+=dmg

  dmg=min(alist[i+1],blist[i])
  alist[i+1]-=dmg
  blist[i]-=dmg
  answer+=dmg
    
print(answer)

Measured memory_bytes: 19116
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF = 1000000;
char ch[21][21];
int d[21][21];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int search(int sx, int sy, int h, int w){
  int res = 0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++) d[i][j] = INF;
  }

  queue<P> que;
  que.push(P(sx, sy));
  d[sx][sy] = 0;

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

      if(0<=nx && nx<h && 0<=ny && ny<w && ch[nx][ny]=='.' && d[nx][ny]==INF){
        que.push(P(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
        res = max(res, d[nx][ny]);
      }
    }
  }
  return res;
}

int main(){
  	int H, W;
    cin >> H >> W;
    
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++) cin >> ch[i][j];
    }

    int ans = 0;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        if(ch[i][j]=='.') ans = max(ans, search(i, j, H, W));
      }
    }

    cout << ans <<endl;


  	return 0;
}


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

int main() {
  int A, B, H, M;
  cin >> A >> B >> H >> M;
  double radH = (double)(H * 30 + 0.5 * M) * 2 * acos(-1) / 360;
  double radM = M * 6 * 2 * acos(-1) / 360;
  double Ax = A * cos(radH), Ay = A * sin(radH);
  double Bx = B * cos(radM), By = B * sin(radM);
  cout << setprecision(15) << sqrt(pow(Ax - Bx, 2) + pow(Ay - By, 2));
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n; cin >> n;
  int nt = 0;
  int nx = 0,ny = 0;
  bool f = true;
  for(int i = 0; i < n; ++i){
    int t,x,y; cin >> t >> x >> y;
    int num = ((t - nt) - (abs(x-nx) + abs(y-ny)));
    tie(nt,nx,ny) = tie(t,x,y);
    f &= num >= 0 && num % 2 == 0;    
  }
  cout << (f ? "Yes" : "No") << endl;
}



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


int main (){

    int N,M;
    cin >> N >> M;
    long long int a[N],b[N],c[M],d[M],count[N],ans[N];
    for(int i = 0; i < N; i++) {
        cin >> a[i] >> b[i];
    }
    for(int i = 0;  i < M; i++) {
        cin >> c[i] >> d[i];
    }

    for(int i = 0; i < N; i++) {
        count[i] = abs(a[i] - c[0]) + abs(b[i] - d[0]);
        ans[i] = 1;
        for(int j = 1; j < M; j++) {
            if(count[i] != abs(a[i] - c[j]) + abs(b[i] - d[j])) {
                count[i] = min(count[i], abs(a[i] - c[j]) + abs(b[i] - d[j]));
                if (count[i] == abs(a[i] - c[j]) + abs(b[i] - d[j])) {
                    ans[i] = j + 1;
                }
            }
        }
        cout << ans[i] << endl;
    }

    return 0;
}


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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

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

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	int a,b,k;
	cin >> a >> b >> k;
	vector<int> v;
	for(int i = 1; i <= min(a,b); i++)
		if(a%i == 0 && b%i == 0)
			v.push_back(i);

	cout << v[v.size()-k] << endl;

	return 0;
}

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

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

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

	if (N % 2 == 1 || d[N/2-1] == d[N/2]){
		
		cout << 0 << endl;
		return 0 ;
	}

	cout << d[N / 2] - d[N / 2 - 1] <<endl;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool prime(ll n) {
  if (n == 1) {
    return false;
  } else {
    for (ll i = 2; i <= (ll)pow(n, 0.5); i++) {
      if (n%i == 0) return false;
    }
  }
  return true;
}
ll RepeatSquaring(ll n, ll p, ll m) {
  if (p == 0) return 1;
  if (p%2 == 0) {
    ll t = RepeatSquaring(n, p/2, m);
    return (t*t)%m;
  }
  return (n*RepeatSquaring(n, p-1, m))%m;
}

int main() {
  ll n, m;
  cin >> n >> m;
  vector <ll> v(n+1, 0);
  ll sum = 0;
  rep(i, n) {
    ll a;
    cin >> a;
    sum += a;
    v.at(i+1) = sum%m;
  }
  map <ll, ll> score;
  vector <ll> u;
  rep(i, n+1) {
    if (score.count(v.at(i))) {
      score.at(v.at(i))++;
    } else {
      score[v.at(i)] = 1;
      u.push_back(v.at(i));
    }
  }
  ll ans = 0;
  rep(i, u.size()) {
    ll tmp = score.at(u.at(i));
    ans += tmp * (tmp-1) / 2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5496
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priotity_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
string s,w="AKIHABARAz";

int main(){
	cin >> s;
	
	int c=0,cou=0; bool f=(s.size()<=9);
	while(1){
		if(s[cou]==w[c]) c++,cou++;
		else if(s[cou]!=w[c] and w[c]=='A') c++;
		else if(s[cou]!=w[c] and w[c]!='A') f=false,cou=s.size();
		
		if(c>9) c=9;
		if(cou==s.size() and c<8){f=false; break;}
		else if(cou==s.size()) break;
	}
	
	cout << (f?"YES":"NO") << endl;
	return 0;
}


Measured memory_bytes: 256
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()
	n := readInt()
	a := readInt()
	b := readInt()
	x := make([]int, n)
	for i := 0; i < n; i++ {
		x[i] = readInt()
	}

	dp := make([]int64, n)
	//println(n, a, b, x)
	for i := 1; i < n; i++ {
		dp[i] = minInt64(
			int64(a)*int64(x[i]-x[i-1]),
			int64(b),
		) + dp[i-1]
		//println(dp[i])
	}
	println(dp[n-1])
}


Measured memory_bytes: 3840
from collections import defaultdict
import string
s = input()
K = int(input())
location = defaultdict(list)
for i, s_i in enumerate(s):
    location[s_i].append(i)
count = 0
s_list = []
for c in string.ascii_lowercase[:26]:
    if location[c] == []:
        continue
    for idx in location[c]:
        for i in range(K):
            if idx + i + 1 > len(s):
                break
            if s[idx:idx+i+1] in s_list:
                continue
            s_list.append(s[idx:idx+i+1])
    count += 1
    if count == K:
        break
s_list.sort()
print(s_list[K-1])

Measured memory_bytes: 3952