akhauriyash/Code-Regression huggingface dataset:
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "ctime"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 1e-8;

long long int N, M, K, H, W, L, R;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> N;
	set<string>st;
	char bef = '0';
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		if (bef == '0') {
			bef = s.back();
		}
		else if (bef != s.front()) {
			cout << "No\n";
			return 0;
		}
		bef = s.back();
		st.insert(s);
	}
	if (N != st.size()) {
		cout << "No\n";
		return 0;
	}
	cout << "Yes\n";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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 (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 200010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll ans = 1,n;
    cin >> n;
    rep(i,1,n+1){
        ans *= i;
        ans %= MOD;
    }
    PRINT(ans);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		int max = 0;
		int min = Integer.MAX_VALUE;
		for(int i=0;i<N;i++) {
			int A = (int)Math.abs(sc.nextInt());
			if(max < A) max = A;
			if(min > A) min = A;
		}
		System.out.println(max - min);
	}
}


Measured memory_bytes: 23252
#C問題
N,K=map(int,input().split())
ans=[0 for i in range(10**5)]
for i in range(N):
    a,b=map(int,input().split())
    ans[a-1]+=b
count=0
for i in range(10**5):
    count+=ans[i]
    if count >= K:
        print(i+1)
        break

Measured memory_bytes: 5928
#include<iostream>
#include<string>
#define M 10000
using namespace std;

int dp[2][2][3][10][550]; //dp[digit][bound][dec or else or inc][prv num][mod]

int zig(string s,int m){
  int n = s.size(),up,mod,ub;

  for(int j=0;j<3;j++)
    for(int k=0;k<10;k++)
      for(int l=0;l<m;l++)
	dp[0][0][j][k][l] = dp[0][1][j][k][l] = 0;
  dp[0][1][1][0][0] = 1;

  for(int i=0;i<n;i++){
    int odd = i&1;
    for(int j=0;j<3;j++)
      for(int k=0;k<10;k++)
	for(int l=0;l<m;l++)
	  dp[1-odd][0][j][k][l] = dp[1-odd][1][j][k][l] = 0;

    for(int j=0;j<2;j++){
      if(j==1)up = s[i]-'0';
      else up = 9;
      for(int k=0;k<3;k++){
	for(int l=0;l<10;l++){
	  for(int x=0;x<=up;x++){
	    if(k==0 && x<=l)continue;
	    if(k==2 && l<=x)continue;
	    for(int y=0;y<m;y++){
	      mod = (y*10 + x) % m;
	      if(j==1 && x==up)ub = 1;
	      else ub = 0;

	      if(k==1 && l==0){
		dp[1-odd][ub][1][x][mod] += dp[odd][j][k][l][y];
		dp[1-odd][ub][1][x][mod] %= M;
	      }else if(x<l){
		dp[1-odd][ub][0][x][mod] += dp[odd][j][k][l][y];
		dp[1-odd][ub][0][x][mod] %= M;
	      }else if(x>l){
		dp[1-odd][ub][2][x][mod] += dp[odd][j][k][l][y];
		dp[1-odd][ub][2][x][mod] %= M;
	      }
	    }
	  }
	}
      }
    }
  }
 
  int ans = 0;
  for(int i=0;i<2;i++)
    for(int j=0;j<3;j++)
      for(int k=0;k<10;k++){
	ans += dp[n&1][i][j][k][0];
	ans %= M;
      }
  return ans;
}

string dec(string a){
  int n = a.size() - 1;
  while(a[n]=='0'){
    a[n--] = '9';
  }
  a[n]--;
  if(a[n] == '0')a = a.substr(1,n-1);
  return a;
}

int main(){
  string a,b;
  int m;
  cin >> a >> b >> m;
  cout << (zig(b,m) - zig(dec(a),m) + M) % M << endl;
}

Measured memory_bytes: 1476
#include<bits//stdc++.h>
using namespace std;
int main(){
    int N,K;
    cin>>N>>K;
    int b[N];
    for(int i=0;i<N;i++){
        cin>>b[i];
    }
    sort(b,b+N);
    for(int l=0;l<N-K+1;l++){
        b[l]=b[l+K-1]-b[l];
    }
    sort(b,b+N-K+1);
    cout<<b[0]<<endl;
}


Measured memory_bytes: 640
import sys


fin = sys.stdin.readline
N, M = [int(elem) for elem in fin().split()]
cards = [[int(elem) - 1 for elem in fin().split()] for _ in range(M)]

num_cards_passes_at = [0] * N
for l, r in cards:
    num_cards_passes_at[l] += 1
    if r < N - 1:
        num_cards_passes_at[r + 1] -= 1

cur_state = 0
for i in range(N):
    cur_state += num_cards_passes_at[i]
    num_cards_passes_at[i] = cur_state

# print(num_cards_passes_at)
print(sum(state == M for state in num_cards_passes_at))

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

int main(){
  ll h,w;
  cin >> h >> w;
  char s[h][w];

  rep(i,0,h){
    rep(j,0,w){
      cin >> s[i][j];
    }
  }

  rep(i,0,h){
    rep(j,0,w){
      bool flag = false;
      if(s[i][j] == '.') continue;

      if(i > 0 && s[i-1][j] == '#'){
        flag = true;
      }

      if(i < h-1 && s[i+1][j] == '#'){
        flag = true;
      }

      if(j > 0 && s[i][j-1] == '#'){
        flag = true;
      }

      if(j < w-1 && s[i][j+1] == '#'){
        flag = true;
      }

      if(!flag){
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<utility>

using namespace std;

int main(){

	int n;
	cin>>n;
	int m[n];
	string s[n];
	int p[n];
	for(int i=0;i<n;i++){
		m[i]=i+1;
		cin>>s[i]>>p[i];
	}

	int p0,m0;
	string s0;
	for(int i=0;i<n;i++){
		for(int j=0;j<n-1;j++){
			if(s[j]>s[j+1]){
				s0 = s[j];
				s[j] = s[j+1];
				s[j+1] = s0;
				p0 = p[j];
				p[j] = p[j+1];
				p[j+1] = p0;
				m0=m[j];
				m[j]=m[j+1];
				m[j+1]=m0;
			}else if(s[j]==s[j+1]){
				if(p[j]<p[j+1]){
					p0 = p[j];
					p[j] = p[j+1];
					p[j+1] = p0;
					m0=m[j];
					m[j]=m[j+1];
					m[j+1]=m0;
				}
			}
		}
	}

	for(int i=0;i<n;i++)cout<<m[i]<<endl;

	return 0;
}


Measured memory_bytes: 764
#include <stdio.h>

int main(void){
	int n,i,j;
	int c[500], s[500], f[500];

	scanf("%d", &n);
	for (i = 0; i < n-1; i++){
		scanf("%d%d%d", &c[i], &s[i], &f[i]);
	}
	for (i = 0; i < n; i++){
		int t = 0;
		for (j = i; j < n - 1; j++){
			if (t < s[j])t = s[j];
			else if (t%f[j] == 0);
			else t = t + f[j] - t%f[j];
			t += c[j];
		}
		printf("%d\n", t);
	}

	return 0;
}

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

using namespace std;

typedef long long ll;

map<ll,ll> mp;

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

	int a[n];

	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		mp[a[i]]++;
	}

	int cnt=0;

	for(int i=0;i<n;i++)
	{
		if(mp[a[i]]>a[i])
		{
			cnt+=(mp[a[i]]-a[i]);
			mp[a[i]]=a[i];
		}
		else if(mp[a[i]]<a[i])
		{
			cnt+=mp[a[i]];
			mp[a[i]]=0;
		}	
	}
	cout<<cnt<<'\n';

	return 0;	
}

Measured memory_bytes: 6656
#include <bits/stdc++.h> //全てのヘッダファイルをインクルード

//ループ
#define REP(i, n) for(int i = 0; i < n; i++) //普通のループ
#define REPR(i, n) for(int i = n; i >= 0; i--) //逆ループ
#define FOR(i, m, n) for(int i = m; i < n; i++) //最初の数値を指定したループ

//型名省略
typedef long long ll;
//配列要素数
static const int MAX = 200000;
//値
static const ll MX = 1e18;

using namespace std;

//#include "./lib/generic/search.h"

#define M 1064527

int main(){
    string s;
    cin >> s;
    
    cout << s.substr(0, 3) << endl;

    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;cin>>n;
	long long a[n],i;int c=0;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]==0)
		c=1;
	}
	long long m=1;int flag=0;
	if(c==1)
	cout<<"0"<<endl;
	else
	{
		for(i=0;i<n-1;i++)
		{
			m=m*a[i];
			if(1000000000000000000/m<a[i+1])
			{
				flag=1;
				break;
			}
		}
		if(flag==0)
		cout<<m*a[n-1]<<endl;
		else
		cout<<"-1"<<endl;
	}
	return 0;
}

Measured memory_bytes: 4416
#include<stdio.h>

int main(){
  int n,q,i,j,k;
  int left,right,mid,cnt;
  int s[100000],t[50000];

  cnt = 0;
  
   scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&s[i]);
  }
  
  scanf("%d",&q);
  for(j=0;j < q;j++){
    scanf("%d",&t[j]);
  }
    
  for(k=0;k < q;k++){
    left = 0; right = n;
    while( left < right){
      mid = (left + right) / 2;
      if (s[mid] == t[k]){
	cnt++;
	break;
      } else if (s[mid] > t[k]){
	right = mid;
      } else {
	left = mid + 1;
      }
    }
  }
  printf("%d\n",cnt);
  return 0;
}




Measured memory_bytes: 2312
MOD = 1000000007
N, K = gets.split.map(&:to_i)

$c = Array.new(N+2).map{Array.new(N+2, 0)}

def init_c()
    $c[0][0] = 1
    for i in 0...$c.length-1
        for j in 0..i
            $c[i+1][j] += $c[i][j]
            $c[i+1][j+1] += $c[i][j]

            $c[i+1][j] %= MOD
            $c[i+1][j+1] %= MOD
        end
    end
end

def comb(a, b)
    return $c[a][b]
end

def f2(x, y)
    comb(x+y-1, y-1)
end

# x個の玉をy個のグループに分ける場合の数
def f(x, y)
    return 1 if x == 0 && y == 0
    return 0 if x < y
    return 0 if y < 1

    f2(x-y, y)
end

init_c()

for i in 1..K

    blue = f(K, i)

    red = 0
    red += f(N-K, i-1)
    red += f(N-K, i)
    red += f(N-K, i)
    red += f(N-K, i+1)
    red %= MOD

    ans = blue * red % MOD
    puts ans
end

Measured memory_bytes: 33276
#include <iostream>
#include <cstdio>
#include <queue>
#include <map>
#include <set>
using namespace std;
inline int read(){int tot=1;char c=getchar();while(c!='-'&&(c<'0'||c>'9'))c=getchar();if(c=='-')tot=-1,c=getchar();
int sum=0;while(c<='9'&&c>='0')sum=sum*10+c-'0',c=getchar();return sum*tot;}
int fa[100005];
set<int> s[100005];
set<int>::iterator it;
map<pair<int,int>,int> mp;
queue<pair<int,int> > q;
int find(int x){
	if(fa[x]!=x)return fa[x]=find(fa[x]);
	return fa[x];
}
int main()
{
	int n=read();
	for(int i=1;i<=(n-1)*2;i++){
		int x=read(),y=read();
		s[x].insert(y);s[y].insert(x);
		mp[make_pair(x,y)]++;mp[make_pair(y,x)]++;
		if(mp[make_pair(x,y)]==2)q.push(make_pair(x,y));
	}
	for(int i=1;i<=n;i++)fa[i]=i;
	while(!q.empty()){
		int x=q.front().first,y=q.front().second;q.pop();
//		cout<<x<<" "<<y<<endl;
		x=find(x),y=find(y);
		s[x].erase(y);s[y].erase(x);
		if(s[x].size()<s[y].size())swap(x,y);
		for(it=s[y].begin();it!=s[y].end();it++){
//			cout<<"aa";
			int j=(*it);
			s[j].erase(y);//s[y].earse(j)这样子写GG
			mp[make_pair(y,j)]=0;mp[make_pair(j,y)]=0;
			s[j].insert(x);s[x].insert(j);
			mp[make_pair(x,j)]++;mp[make_pair(j,x)]++;
			if(mp[make_pair(j,x)]==2)q.push(make_pair(j,x));
		}
		fa[y]=x;
        s[y].clear();//
	}
	int sum=0;
	for(int i=1;i<=n;i++){
		if(fa[i]==i)sum++;
//		cout<<fa[i]<<" ";
	}
	if(sum==1)puts("YES");
	else puts("NO");
	return 0;
}
//反过来做的思路 原图删除的最后一条边在新图中也以同样形式出现，维护一下就好了

Measured memory_bytes: 57984
package main

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

var (
	scanner *bufio.Scanner
	buffer  *bufio.Writer
	writer  io.Writer
)

func main() {
	defer flush()
	initWordScanner()
	initBufWriter()

	x := readInt()
	q := 8 - (x-400)/200
	println(q)
}

func initLineScanner() {
	scanner = bufio.NewScanner(os.Stdin)
	buf := make([]byte, 1e4)
	scanner.Buffer(buf, bufio.MaxScanTokenSize)
}

func initWordScanner() {
	initLineScanner()
	scanner.Split(bufio.ScanWords)
}

func readLine() string {
	if scanner.Scan() {
		return scanner.Text()
	}
	return ""
}

func readInt() int {
	scanner.Scan()
	n, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return n
}

func readFloat() float64 {
	scanner.Scan()
	n, err := strconv.ParseFloat(scanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func readRunes() []rune {
	scanner.Scan()
	var ns []rune
	for _, v := range scanner.Text() {
		ns = append(ns, v)
	}
	return ns
}

func readString() string {
	if scanner.Scan() {
		return scanner.Text()
	}
	return ""
}

func readStrings() []string {
	scanner.Scan()
	var ss []string
	for _, v := range scanner.Text() {
		ss = append(ss, string(v))
	}
	return ss
}

func initWriter() {
	buffer = nil
	writer = os.Stdout
}

func initBufWriter() {
	buffer = bufio.NewWriter(os.Stdout)
	writer = buffer
}

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

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

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func flush() {
	if writer != nil {
		buffer.Flush()
	}
}

func string2int(s string) int {
	n, e := strconv.Atoi(s)
	if e != nil {
		panic(e)
	}
	return n
}

func int2string(n int) string {
	s := strconv.Itoa(n)
	return s
}

func string2float(s string) float64 {
	n, e := strconv.ParseFloat(s, 64)
	if e != nil {
		panic(e)
	}
	return n
}

func sum(ns []int) int {
	s := 0
	for _, n := range ns {
		s += n
	}
	return s
}

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

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

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}


Measured memory_bytes: 1776
require 'pp'

n, m = gets.chomp!.split(" ").map(&:to_i)
x_m = gets.chomp!.split(" ").map(&:to_i).sort!

#pp x_m

if n >= m
    puts 0
    exit(0)
end

diff = []

x_m.each_cons(2) do |x|
    diff << x[1] - x[0]
end

pp diff.sort[0, (m - 1) - (n - 1)].inject(&:+)


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

int main() {
    int x, y;
    cin >> x >> y;
    int ans = (max(0, (4 - x)) + max(0, (4 - y))) * 100000;
    if (x == 1 && y == 1) ans += 400000;
    cout << ans << endl;
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
a = list(map(int,input().split()))
E = []
O = []
for k in range(N):
    if k%2 == 0:
        E.append(a[k])
    else:
        O.append(a[k])
e = Counter(E).most_common()
o = Counter(O).most_common()

if e[0][0] != o[0][0]:
    print(N-e[0][1]-o[0][1])
else:
    if len(e) >= 2 and len(o) >= 2:
        print(N-e[0][1]-max(e[1][1],o[1][1]))
    elif len(e) >= 2 and len(o) == 1:
        print(N//2-e[1][1])
    elif len(e) == 1 and len(o) >= 2:
        print(N//2-o[1][1])
    else:
        print(N//2)


Measured memory_bytes: 65388
//https://atcoder.jp/contests/abc139/tasks/abc139_b
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
    ll A,B; cin>>A>>B;    
    ll num=1;
    ll ans=0;
    while(num<B){
        num-=1;
        num+=A;
        ++ans;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int sa=0, sb=0;
  int n;
  for( int i=0;i<4;i++ ){
    cin >> n;
    sa+=n;
  }
  for( int i=0;i<4;i++ ){
    cin >> n;
    sb+=n;
  }
  cout << (sa>sb?sa:sb) << endl;

}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <typeinfo>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
int main(void){
    int n;
    cin >> n;
    ll ai;
    map<ll, int> count;
    for(int i=0; i<n; i++){
        cin >> ai;
        if(count.find(ai)!=count.end()){
            count[ai] += 1;
        }else{
            count[ai] = 1;
        }
        if(count.size()>3){
            cout << "No" << endl;
            exit(0);
        }
    }
    ll sx=0;

    if(n%3!=0){
        if(count.size()==1 and count.find(0) == count.begin()){
            cout << "Yes" << endl; 
        }else{
            cout << "No" << endl;
        }
    }else{
        if(count.find(0) != count.end()){
            if(count.size()==1){
                cout << "Yes" << endl;
            }else if(count.size()==2){
                if(count[0] == n/3){
                    cout << "Yes" << endl;
                }else{
                    cout << "No" << endl;
                }
            }else{
                cout << "No" << endl;
            }
        }else{
            if(count.size()==3){
                for(map<ll, int>::iterator it=count.begin(); it!=count.end(); it++){
                    sx = sx^(it->first);
                    if(it->second!=n/3){
                        cout << "No" << endl;
                        exit(0);
                    }
                }
                if(sx==0){
                    cout << "Yes" << endl;
                }else{
                    cout << "No" << endl;
                }
            }else{
                cout << "No" << endl;
            }
        }
    }
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#define INF 100000000
#define MOD 1000000007
using namespace std;


int main(){
    long long N;
    cin >> N;
    
    long long a[N*3];
    for(int i=0; i<N*3; i++){
        cin>>a[i];
    }
    
    sort(a,a+3*N);
    
    long long ans=0;
    for(int i=3*N-2; i>=N; i-=2){
        ans+=a[i];
    }
    
    cout<<ans<<endl;
    return 0;
}


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

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

	for(int n, s; cin >> n >> s, n;) {
		vector<int> r(n);
		for(int i = 0; i < n; ++i)
			cin >> r[i];

		sort(r.begin(), r.end());
		int ans = n * (n - 1) / 2;
		int j = n - 1;
		for(int i = 0; i < j; ++i) {
			while(i < j && r[i] + r[j] > s) --j;
			if(i < j)
				ans -= j - i;
		}

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1260
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;
const lli inf = 1e18;

void ud(lli x, lli &us, lli &ds, vector<lli> &s){
	auto sit = lower_bound(s.begin(), s.end(), x);
	if(sit == s.end()){
		us = inf;
		ds = abs(*(--sit) -x);
	}else if(*sit == x){
		us = ds = 0;
	}else if(sit == s.begin()){
		us = abs(*sit -x);
		ds = inf;
	}else{
		us = abs(*sit -x);
		ds = abs(*(--sit) -x);
	}
}

int main(){
	int a,b,q;
	cin >> a >> b >> q;
	vector<lli> s(a),t(b),x(q);
	for(int i=0; i<a; i++) cin >> s[i];
	for(int i=0; i<b; i++) cin >> t[i];
	for(int i=0; i<q; i++) cin >> x[i];
	
	for(int i=0; i<q; i++){
		lli us,ds,ut,dt;
		lli ans = inf;
		ud(x[i], us, ds, s);
		ud(x[i], ut, dt, t);
		ans = min(ans, us +dt +min(us, dt));
		ans = min(ans, ut +ds +min(ut, ds));
		ans = min(ans, max(us, ut));
		ans = min(ans, max(ds, dt));
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

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

typedef pair <ll,ll> P;

bool pairCompareF(const P& firstElof, const P& secondElof)
{
    return firstElof.first < secondElof.first;
}

bool pairCompareS(const P& firstElof, const P& secondElof)
{
    return firstElof.second < secondElof.second;
}

int main()
{
    string w;
    cin >> w;
    map<char, int> mp;
    rep(i, w.length()) {
        if (mp.find(w[i]) == mp.end()) {
            mp[w[i]] = 1;
        }else {
            mp[w[i]]++;
        }
    }
    for(pair<char, int> p:mp) {
        if (p.second % 2 == 1){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int N,D,X;
    int ans = 0;
    int B = 0;
    int A[102];
    cin >> N >> D >> X ;
    for(int i=0;i < N; i++){
        cin >> A[i];
        for(int j = 1;j <= D; j = j + A[i]){
            ans++;
        }
    }
    ans = ans + X;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int, int>P;
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<int> vec;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll qp(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

void solve() {
    ll l, m, n;
    cin  >> l >> m >> n;

    if(l+m+n > 21) cout << "bust";
    else cout << "win";
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed << setprecision(10);
    solve();
    // stop
        return 0;
}

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

int linearSearch(int A[],int n,int key){//A:探索対象の配列 n:番兵,key 探索対象の配列
    A[n]=key;
    int i=0;
    while(A[i]!=key) i++;
    return i!=n;
}

int main(){
    int A[10000+1];
    int n,q,key,ans=0;
    scanf("%d",&n);
    rep(i,n) scanf("%d",&A[i]);
    scanf("%d",&q);
    rep(i,q){
        scanf("%d",&key);
        ans+=linearSearch(A,n,key);
    }
    
    printf("%d\n",ans);

    return 0;
}


Measured memory_bytes: 3232
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int n = sc.nextInt();
		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			a[i] -= (i + 1);
		}
		Arrays.sort(a);
		int offset = a[n / 2];
		long ans = 0;
		for (int i = 0; i < n; i++) {
			a[i] = Math.abs(a[i] - offset);
			ans += a[i];
		}
		System.out.println(ans);
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

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

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(4000);
		}
	}
}

Measured memory_bytes: 47724
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
    

    ll n;
    cin >> n;
    vector <string> slis;
    vector <ll> tlis;
    for (ll i=0;i<n;i++){
        string s;
        ll t;
        cin >> s >> t;
        slis.push_back(s);
        tlis.push_back(t);
    }
    string x;
    cin >> x;
    ll ans = 0;
    bool flag = false;
    for (ll i=0;i<n;i++){
        if(flag){
            ans += tlis[i];
        }
        if(slis[i] == x){
            flag = true;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
#define fst first
#define snd second
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> inline int Log2(T& x) {int k; for(k=0; (T(1)<<k)<=x; ++k); return k;} // number of binary digits


// initialization
const int F_MAX = int(1e6)+10;
ll fac[F_MAX], finv[F_MAX], inv[F_MAX];
void binom_init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < F_MAX; ++i) {
    fac[i] = fac[i-1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
    finv[i] = finv[i-1] * inv[i] % MOD;
  }
}

// binom mod MOD
ll binom(int n, int k) {
  if (k < 0 || n < k) return 0;
  return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}



VV G;


// DP
struct ReRooting {
  // edit area start
  struct DP {
    ll dp;
    int size;
    DP(ll dp=1, int size=0) : dp(dp), size(size) {}
  };
  DP f_merge(DP a, DP b) {
    return DP((a.dp * b.dp) % MOD * binom(a.size + b.size, a.size) % MOD, a.size + b.size);
  }
  DP f_trans(DP a) {
    return DP(a.dp, a.size+1);
  }
  // edit area end

  vector<vector<DP>> dp;
  vector<DP> ans;
  vector<int> p_idx;

  ReRooting(int N) : dp(N), ans(N), p_idx(N) {}

  DP dfs(int u, int p=-1) {
    int d = G[u].size();
    dp[u] = vector<DP>(d);
    DP res;
    rep(i, d) {
      int v = G[u][i];
      if (v == p) {
        p_idx[u] = i;
        continue;
      }
      dp[u][i] = dfs(v, u);
      res = f_merge(res, dp[u][i]);
    }
    return f_trans(res);
  }

  void dfs2(int u, int p=-1) {
    int d = G[u].size();
    vector<DP> res_l(d+1), res_r(d+1);
    rep(i, d)  res_l[i+1] = f_merge(res_l[i], dp[u][i]);
    drep(i, d) res_r[i] = f_merge(res_r[i+1], dp[u][i]);

    ans[u] = res_l[d];

    rep(i, d) {
      int v = G[u][i];
      if (v == p) continue;
      dp[v][p_idx[v]] = f_trans(f_merge(res_l[i], res_r[i+1]));
      dfs2(v, u);
    }
  }

  void build() {
    dfs(0);
    dfs2(0);
  }
};


int main() {
  binom_init();
  int N; cin >> N;

  G = VV(N);
  for (int i = 0; i < N-1; ++i) {
    int u, v; cin >> u >> v;
    u--; v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }

  ReRooting reroot(N);
  reroot.build();

  rep(i, N) cout << reroot.ans[i].dp << endl;
  return 0;
}


Measured memory_bytes: 59636
#include "bits/stdc++.h"
using namespace std;
int main(){
    int m, f, r;
    while(true){
        cin >> m >> f >> r;
        if(m==-1 && f == -1 && r == -1) break;
        else if(m==-1 && f == -1) cout << "F" << endl;
        else if(m*f < 0) cout << "F" << endl;
        else if(m+f < 30) cout << "F" << endl;
        else if(m+f < 50){
            if(r >= 50) cout << "C" <<endl;
            else cout << "D"<< endl;
        }
        else if(m+f<65) cout << "C" << endl;
        else if(m+f <80) cout << "B" << endl;
        else cout << "A" << endl;
    }
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    int A[N];
    int B[N];
    int C[N-1];
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    for(int i=0;i<N;i++){
        cin >> B[i];
    }
    for(int i=0;i<N-1;i++){
        cin >> C[i];
    }

    int ans = B[A[0]-1];

    //cout << ans << endl;

    for(int i=1;i<N;i++){
        if(A[i] == A[i-1] + 1){
            ans += B[A[i] - 1] + C[A[i] - 2];
        }else{
            ans += B[A[i] - 1];
        }
        //cout << ans << endl;
    }

    //cout << "final " << ans << endl;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
let () =
  let n = read_int () in
  let rec doit i acc =
    if i > n then List.rev acc
    else if (i mod 3 = 0) then doit (i + 1) (i :: acc)
    else begin
      match
        try Some (String.index (string_of_int i) '3')
        with _ -> None
      with
      | None -> doit (i + 1) acc
      | Some _ -> doit (i + 1) (i :: acc)
    end
  in
  List.iter (fun x -> Printf.printf " %d" x) (doit 3 []);
  print_newline ()

Measured memory_bytes: 3740
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll;
typedef long double ld;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>

const double PI=acos(-1.0);
const double eps=1e-6;
const ll mod= 998244353;
const int inf=0x3f3f3f3f;
const int maxn=2e5+10;
const int maxm=100+10;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);


ll dp[maxn];
int vis[maxn];
int n,k;
int main()
{
    cin>>n>>k;
    vector<pii>e;
    for(int i = 1; i<=k; i++)
    {
        int l,r;
        cin>>l>>r;
        e.push_back(make_pair(l,r));
    }
    sort(e.begin(),e.end());
    dp[1] = 1;
    for(int i = 2; i<=n; i++)
    {
        for(int j = 0; j<e.size(); j++)
        {
            int l = e[j].fi;
            int r = e[j].se;
            if(i-l < 0)
            {
                break;
            }
            else if(i-r >= 1)
                dp[i] = (dp[i] + dp[i-l] - dp[i-r-1] + mod)%mod;
            else
                dp[i] = (dp[i] + dp[i-l])%mod;
        }
        dp[i] = (dp[i] + dp[i-1])%mod;
    }
    cout<<(dp[n]-dp[n-1]+mod)%mod<<endl;
}

Measured memory_bytes: 5172
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG abc/abc109/c.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    int N, X;
    cin >> N >> X;
    int x[N];
    rep(i, N){
        cin >> x[i];
        x[i] = abs(x[i] - X);
    }

    int ans = x[0];
    rep(i, N){
        ans = __gcd(ans, x[i]);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 640
# 全ての集合のペアに、共通の値を一つずつ入れる
# 集合が3個の場合はA,B,Cのペアである(A,B),(B,C),(C,A)にそれぞれ1,2,3の数字を割り振ることで
# (1,2),(2,3),(3,1)となる。
# 集合の数が4個の場合は同様に
# (1,2,3)(1,4,5)(2,4,6)(3,5,6)
# xC2で表現できるNの場合はこの構成が可能。(4C2 = 6なので、N = 6のとき可能)
# その際x個の集合ができる（上の場合4個）
# N = 10 ** 5のため、x * (x - 1) // 2 = たかだか10**5の数を2つずつ集合に割り振っていけば構成可能

N = int(input())
if N == 1:
  print("Yes")
  print(2)
  print(1,1)
  print(1,1)
  exit(0)
  
X = -1
for x in range(2,449):
  if (x * (x - 1) % 2) == 0 and (x * (x - 1) // 2) == N:
    X = x
    break
else:
  print("No")
  exit(0)
  
# X個の集合ができる
num = 1
ans = [[] for i in range(X)]
for i in range(len(ans)-1):
  for j in range(i+1,len(ans)):
    ans[i].append(num)
    ans[j].append(num)
    num += 1
    
print("Yes")
print(X)
for a in ans:
  print(len(a),*a)

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

int main(){
  int N;
  cin >> N;
  vector<int> d(N);
  for(int i=0; i<N; i++) cin >> d.at(i);
  int ans=0;
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      if(i!=j) ans+=d.at(i)*d.at(j);
    }
  }
  ans = ans/2;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

typedef tuple<long,long,long> TP;

int main() {
  int n;
  cin >> n;
  TP ans = TP(0,0,0);
  TP calc;
  vector<TP> re;
  for (int i=0; i<n; i++) {
    long x,y,h;
    cin >> x >> y >> h;
    re.push_back(TP(x,y,h));
    if (h>0) calc = re.back();
  }

  cerr << get<0>(calc) << " " << get<1>(calc) << " " << get<2>(calc) << endl;

  for (int cx=0; cx<=100; cx++) {
    for (int cy=0; cy<=100; cy++) {
      long h = get<2>(calc) + abs(get<0>(calc) - cx) + abs(get<1>(calc) - cy);
      bool f = true;
      for (auto r : re) {
        long x,y,hi;
        tie(x,y,hi) = r;
        if (hi != max(h-abs(x-cx)-abs(y-cy),0L)) {
          f = false;
          break;
        }
      }
      if (f && h>0) ans = TP(cx,cy,h);
    }
  }
  long x,y,h;
  tie(x,y,h) = ans;

  cout << x << " " << y << " " << h << endl;
}


Measured memory_bytes: 888
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


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


	int kotae[2001] = {};
	rep1(i, N) {
		for (int j = i + 1; j <= N; j++) {
			int tmp = j - i;
			chmin(tmp, abs(i - X) + 1 + abs(j - Y));
			chmin(tmp, abs(i - Y) + 1 + abs(j - X));
			kotae[tmp]++;
		}
	}

	rep1(i, N - 1) co(kotae[i]);


	Would you please return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <set>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;
typedef unsigned long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b+1;i++)
#define Per(i,b,a) for(int i=b;i>=a;i--)
int main(){
    ll N,A,B;
    cin>>N>>A>>B;
    ll hoge =  N/(A+B);
    ll hogehoge = N - (A+B)*hoge;
    // cout<<hoge<<" "<<hogehoge<<endl;
    cout<< (hoge*A+min(hogehoge,A))<<endl; 
    return 0;
}

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

using namespace std;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S, T;
  cin >> S >> T;
  vector<vector<int>> dp(S.size() + 1, vector<int>(T.size() + 1, 0));
  for (int i = 0; i < (int)S.size(); i++) {
    for (int j = 0; j < (int)T.size(); j++) {
      if (S[i] == T[j]) dp[i + 1][j + 1] = dp[i][j] + 1;
      chmax(dp[i + 1][j + 1], dp[i + 1][j]);
      chmax(dp[i + 1][j + 1], dp[i][j + 1]);
    }
  }
  string res = "";
  int i = (int)S.size(), j = (int)T.size();
  while (i > 0 && j > 0) {
    if (dp[i][j] == dp[i - 1][j]) {
      i--;
    } else if (dp[i][j] == dp[i][j - 1]) {
      j--;
    } else {
      res.push_back(S[i - 1]);
      i--, j--;
    }
  }
  reverse(res.begin(), res.end());
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000002

char show(int l,int n){
	cout<<"?";
	for(int i=0;i<n;i++){
		cout<<" "<<l+i;
	}
	cout<<endl;
	string s;
	cin>>s;
	return s[0];
}

char show2(int l,int n,int x){
	cout<<"?";
	for(int i=0;i<n;i++){
		cout<<" "<<l+i;
	}
	cout<<" "<<x<<endl;
	string s;
	cin>>s;
	return s[0];
}

char show(vector<int> t){
	cout<<"?";
	for(int i=0;i<t.size();i++){
		cout<<" "<<t[i];
	}
	cout<<endl;
	string s;
	cin>>s;
	return s[0];
}

void answer(string s){
	cout<<"! "<<s<<endl;
}

int main(){
	
	int N;
	cin>>N;
	
	char ret = show(1,N);
	
	char C = ret;
	
	int ok = 1,ng = N+1;
	
	while(ng-ok>1){
		int mid = (ok+ng)/2;
		ret = show(mid,N);
		if(ret==C)ok = mid;
		else ng = mid;
	}

	string ans(2*N,'.');
	
	for(int i=1;i<=2*N;i++){
		if(i>=ok+1&&i<=ok+N-1)continue;
		ans[i-1] = show2(ok+1,N-1,i);
	}
	
	for(int i=0;i<2*N;i++){
		if(ans[i]!='.')continue;
		vector<int> t;
		t.push_back(i+1);
		int R=0,B=0;
		for(int j=0;j<2*N;j++){
			if(ans[j]=='R'){
				if(R<N/2){
					R++;
					t.push_back(j+1);
				}
			}
			if(ans[j]=='B'){
				if(B<N/2){
					B++;
					t.push_back(j+1);
				}
			}
		}
		ans[i] = show(t);
	}
	
	answer(ans);

	return 0;
}

Measured memory_bytes: 3808
<?php
	fscanf(STDIN,'%d%d',$h,$w);
	for($i=0;$i<$h;$i++)$s[]=fgets(STDIN);
	$dx=array(0,1,0,-1,1,1,-1,-1);
	$dy=array(1,0,-1,0,1,-1,1,-1);
	for($i=0;$i<$h;$i++){
		for($j=0;$j<$w;$j++){
			if($s[$i][$j]=='#')continue;
			$c=0;
			for($r=0;$r<8;$r++){
				$x=$i+$dx[$r];
				$y=$j+$dy[$r];
				$c+=$x>=0&&$y>=0&&$x<$h&&$y<$w&&$s[$x][$y]=='#';
			}
			$s[$i][$j]=$c;
		}
		echo $s[$i];
	}

Measured memory_bytes: 3828
import heapq
N,M=map(int,input().split())
A=list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(A)

for i in range(M):
  x=heapq.heappop(A)
  y=(((-1)*x)//2)*(-1)  
  heapq.heappush(A,y)
print((-1)*sum(A))

Measured memory_bytes: 14180
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, w;
    cin >> n >> w;
    vector<ld> d(n);
    vi ww(n);
    rep(i, n) {
        int v;
        cin >> v >> ww[i];
        d[i] = (ld)v/ww[i];
    }

    vector<pair<ld, int> > pp(n);
    rep(i, n) {
        pp[i] = make_pair(d[i], ww[i]);
    }

    sort(rall(pp));

    ld ans = 0;
    rep(i, n) {
        if(w > pp[i].second) {
            w -= pp[i].second;
            ans += pp[i].first*pp[i].second;
        } else {
        ans += pp[i].first*w;
        break;
        }
    }

    cout << fixed << setprecision(10);
    cout << ans << endl;
}


Measured memory_bytes: 7820
import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		char c = 'c';
		int a[][] = new int[h][w];
		for(int i = 0;i < h;i++){
			int cnt = -1;
			char s[] = sc.next().toCharArray();
			for(int k = 0;k < w;k++){
				if(c == s[k]) cnt = 0;
				else if(cnt >= 0) cnt++;
				a[i][k] = cnt;
			}
		}
		for(int i = 0;i < h;i++){
			for(int k = 0;k < w;k++){
				if(k != w - 1) System.out.print(a[i][k] + " ");
				else System.out.println(a[i][k]);
			}
		}
	}
}

Measured memory_bytes: 35016
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

const int n = 9;

int main(void){
	int T; cin >> T;
	while(T--){
		vi num(n); for(auto & e : num) cin >> e;
		string color;
		rep(i, n){
			char c; cin >> c;
			color.push_back(c);
		}

		vi card[3];
		rep(i, n){
			int idx = color[i] == 'R' ? 0 : color[i] == 'G' ? 1 : 2;
			card[idx].push_back(num[i]);
		}

		rep(i, 3) sort(_all(card[i]));

		int res = 0;
		rep(i, 3){
			vi & hand = card[i];
			int len = hand.size();

			vi cnt(15);
			rep(i, len){
				cnt[hand[i]]++;
			}

			rep(i, 10){
				res += cnt[i] / 3;
				cnt[i] %= 3;

				while(cnt[i] >= 1 and cnt[i + 1] >= 1 and cnt[i + 2] >= 1){
					cnt[i]--, cnt[i + 1]--, cnt[i + 2]--;
					res++;
				}
			}
		}

		res = res == 3 ? 1 : 0;
		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 3128
import java.awt.*;import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);for(int t=s.nextInt(),n,c;t-->0;System.out.println(c)){Rectangle r=new Rectangle(s.nextInt()-1,s.nextInt()-1,s.nextInt()+2,s.nextInt()+2);for(n=s.nextInt(),c=0;n-->0;)c+=r.contains(s.nextInt(),s.nextInt())?1:0;}}}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<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; }
typedef long long ll;
using namespace std;
const ll mod=1e+9+7;
int main(void){
    ll n;cin>>n;
    ll p=1;
    rep(i,n){
        p*=(i+1);
        p%=mod;
    }
    cout<<p<<endl;
}


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

int N, M, K, p, q, cnt;

struct UnionFind {
  // 各ノードの根、そのコンストラクタ
  vector<int> par;
  explicit UnionFind(int n) : par(n, -1) {}

  // 根を返す。mergeで初期化され各ノードの根は自分自身となる。
  int root(int x) {
    if (par[x] < 0)
      return x;
    else
      return par[x] = root(par[x]);
  }

  // 根が同じかどうか
  bool same(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;

    // swap(x, y)。 vector以外のライブラリに拠らない構成にしてみた
    // swap使いたいなら #include<utility> 忘れないように
    if (par[x] > par[y]) {
      int tmp = x;
      x = y;
      y = tmp;
    }

    // 根を統一する。
    par[x] += par[y];
    par[y] = x;
    return true;
  }

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

int main() {
  cin >> N >> M >> K;
  vector<int> ans(N, -1);
  UnionFind uf(N);
  // 友人とブロック関係が同一になることがないからこうしたが
  // その条件がない場合はsetの方がいいかもしれない
  vector<vector<int>> minus(N, vector<int>(0));
  FOR(i, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    minus[a].emplace_back(b);
    minus[b].emplace_back(a);
    uf.merge(a, b);
  }

  FOR(i, K) {
    int c, d;
    cin >> c >> d;
    c--;
    d--;
    if (!uf.same(c, d)) continue;
    minus[c].emplace_back(d);
    minus[d].emplace_back(c);
  }

  FOR(i, N) ans[i] = uf.size(i) - minus[i].size() - 1;

  FOR(i, N - 1) cout << ans[i] << " ";
  cout << ans[N - 1] << endl;
  return 0;
}

Measured memory_bytes: 8320
#include <iostream>
using namespace std;
#define pi 3.14159265

int main()
{
	long long ans = 0, i = 0, j = 0, k = 0, N, M, X, Y, x[100], y[100];
	cin >> N >> M >> X >> Y;
	for (i; i < N; i++)cin >> x[i];
	for (j; j < M; j++)cin >> y[j];

	
	for (j = 0; j < N - 1; j++) {
		for (i = N - 1; i >= 1+j; i--) {
			if (x[i] > x[i - 1]) {
				int t = x[i];
				x[i] = x[i - 1];
				x[i - 1] = t;
			}
		}
	}
	for (j = 0; j < M - 1; j++) {
		for (i = M - 1; i >= 1 + j; i--) {
			if (y[i] < y[i - 1]) {
				int t = y[i];
				y[i] = y[i - 1];
				y[i - 1] = t;
			}
		}
	}

	if (x[0] >= y[0])k++;
	if (X >= Y)k++;
	if (x[0] + 1 > Y)k++;
	if (y[0] <= X)k++;

	if (k)
		cout << "War" << endl;
	else
		cout << "No War" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static Random rnd=new Random();
	
    public static void main(String args[]) throws Exception
    {
		long val1=sc.nextLong(),val2=sc.nextLong(),val3=sc.nextLong(),val4=sc.nextLong();
		out.println(Math.max(val1*val2,val3*val4));out.close();
    }
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }
	
    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
	
	public String next() throws Exception {
		return nextToken().toString();
	}
	
    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}

Measured memory_bytes: 8020
S = list(input())
a=int("".join(S[0:2]))
b=int("".join(S[2:4]))
ma = 0
mb = 0
if 1 <= a <= 12:
  ma = 1
if 1 <= b <= 12:
  mb = 1
if ma ==1 and mb == 1:
  print("AMBIGUOUS")
elif ma==1 and mb == 0:
  print("MMYY")
elif ma==0 and mb == 1:
  print("YYMM")
else:
  print("NA")

Measured memory_bytes: 3064