akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

using namespace std;

int
main()
{
    string s;
    cin >> s;

    int n = s.length();
    string k1 = s.substr(0, n/2);
    string k2 = s.substr(((n+3)/2)-1, n);

    if(k1 == k2)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
typedef long unsigned int size_t;
extern int printf (const char *__restrict __format, ...);
extern int scanf (const char *__restrict __format, ...) ;
extern int getchar (void);
extern int putchar (int __c);
int nextInt(){int f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
char nextChar(){char f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
short nextShort(){short f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
long nextLong(){long f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
void println(){putchar(10);}
void print(char *f){while(*f){putchar(*f);f++;}}
void printInt(int f){if(f==0x80000000){print("-2147483648");return;}char c[11];if(!f){putchar(48);return;}if(f<0){f=-f;putchar(45);}char i=0;while(f){c[++i]=(f%10)+48;f/=10;}while(i){putchar(c[i--]);}}
void printLong(long f){if(f==0x8000000000000000){print("-9223372036854775808");return;}char c[20];if(!f){putchar(48);return;}if(f<0){f=-f;putchar(45);}char i=0;while(f){c[++i]=(f%10)+48;f/=10;}while(i){putchar(c[i--]);}}
int min2(int a, int b){return a>b?b:a;}
int n, g, i;
int a, min;
long sum;
int main(void){
 n=nextInt();
 min=0x0FFFFFFF;
 for(i=0; i<n; i++){
  a=nextInt();
  if(a<0){
   sum -= a;
   g++;
   min = min2(min, -a);
  }else{
   sum += a;
   min = min2(min, a);
  }
 }
 if(g&1){
  printLong(sum-2*min);
 }else{
  printLong(sum);
 }
 println();
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <numeric>

int main() {
  int32_t n, k;
  std::cin >> n >> k;

  std::vector<int32_t> a(n);
  for (int32_t i = 0; i < n; ++i) {
    std::cin >> a.at(i);
  }

  int64_t first = std::accumulate(a.begin(), a.begin() + k, 1LL);
  int64_t second;
  for (int32_t i = k + 1; i <= n; ++i) {
    second = first - a.at(i - k - 1) + a.at(i - 1);

    if (second > first) {
      std::cout << "Yes" << std::endl;
    } else {
      std::cout << "No" << std::endl;
    }

    first = second;
  }

  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define INF 100000000
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    rep(i, 20){
        rep(j, 20){
            if(i * 4 + j * 7 == n){
                cout << "Yes" << '\n';
                return 0;
            }
        }
    }
    cout << "No" << '\n';
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int X = scanner.nextInt();
    int[] x = new int[N + 1];
    for (int i = 0; i < N; i++) x[i] = scanner.nextInt();
    x[N] = X;
    Arrays.sort(x);

    int ans = x[1] - x[0];
    for (int i = 1; i < N; i++) {
      int n = x[i + 1] - x[i];
      ans = gcd(ans, n);
    }
    System.out.println(ans);
  }

  private static int gcd(int i, int j) {
    if (i > j) return gcd(j, i);
    if (i == 0) return j;
    int r = j % i;
    return gcd(r, i);
  }
}


Measured memory_bytes: 50456
#coding:utf-8
import queue

N,M,X = map(int,input().split())

cost = -1
score = -1
shan = -1

book_c = []
book_a = []
index = [i for i in range(M)]

def judge(c,a):
    m = min(a)
    jud = -1
    if m >= X:
        jud = c
    return jud
    
for i in range(N):
    b = input().split()
    book_c.append(int(b[0]))
    b = b[1:]
    box = []
    for j in b:
        box.append(int(j))
    book_a.append(box)

q = queue.Queue()
q.put('0')
q.put('1')
mak = q.get()
order = len(mak)

while order < N:
    mallo = '0' + mak
    mally = '1' + mak
    q.put(mallo)
    q.put(mally)
    mak = q.get()
    order = len(mak)

q.put(mak)

while not q.empty():
    score = 0
    mak = q.get()
    nas = [int(k) for k in mak]
    anad = [0] * M
    
    for c,kk in zip(book_c,nas):
        score += (c * kk)

    for asa,kk in zip(book_a,nas):
        for ind,kok in enumerate(asa):
            anad[ind] += (kok * kk)

    shan = judge(score,anad)
    if cost == -1:
        cost = shan
    elif shan != -1:
        cost = min(cost,shan)
            

print("{}".format(cost))

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
using Graph = vector<vector<ll>>;
#define all(x) (x).begin(), (x).end() //string の sort とかはこれ
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

const ll MOD = 1000000007;
const ll INF = 1e18; //1*10^18
const ll MAX = 1e6;
const double PI = 3.14159265;

int ctoi(char c)
{
  if (c >= '0' && c <= '9')
  {
    return c - '0';
  }
  return 0;
}

ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }
//最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//最小公倍数

ll powll(ll a, ll n)
{ //O(log n)
  ll res = 1;
  while (n > 0)
  {
    if (n & 1) //(n & 1)=(n % 2 !=0)
    {
      res = res * a;
    }
    a = a * a;
    n >>= 1; //(n & 1)=(n % 2 !=0)
  }
  return res;
}

ll modpow(ll a, ll n, ll mod) //O(log n)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1) //(n & 1)=(n % 2 !=0)
    {
      res = res * a % mod;
    }
    a = a * a % mod;
    n >>= 1; //(n>>=1)=(n/2)
  }
  return res;
}

int ReturnDigit(ll num)
{
  string number = to_string(num);
  return number.length();
}

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() //MODは素数じゃないとだよ！！
{
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < 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;
  }
}

// 二項係数計算
long long COM(int n, int k)
{
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind
{
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

  UnionFind(int N) : par(N)
  { //最初は全てが根であるとして初期化
    for (int i = 0; i < N; i++)
      par[i] = i;
  }

  int root(int x)
  { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x)
      return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y)
  {                   // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry)
      return;     //xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }

  bool same(int x, int y)
  { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main()
{
  // COMinit();
  // srand((unsigned int)time(NULL));//--> rand()
  ll i, j, k, l, ans = 0;
  ll n, a;
  cin >> n;
  for (i = 0; i < n; i++)
  {
    cin >> a;
    if (a % 2 == 1)
    {
      cout << "first";
      return 0;
    }
  }

  cout << "second" << endl;
}


Measured memory_bytes: 256
N, L=map(int, input().split())

taste = []

def checkio(numbers_array):
    return sorted(numbers_array, key=lambda x: abs(x))

for i in range(N):
    x=0
    x=(i+1)+L-1
    taste.append(x)

target = checkio(taste)
perfect = sum(taste)
ans = perfect - target[0]
print(ans)

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

using namespace std;

typedef long long int ll;

const ll MAXN = 1e4 + 5;

vector < vector < ll > > adj(MAXN, vector < ll > ());
vector < ll > val(MAXN), v;

ll ans = 0;
void dfs(ll u, ll p){
  val[u] = v.back();
  v.pop_back();
  for(auto to : adj[u]){
    if(to != p){
      dfs(to, u);
      ans += min(val[to], val[u]);
    }
  }
}

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

  ll n;
  cin >> n;
  vector < ll > deg(n + 1, 0);
  set < ll > score;
  for(int i = 0; i < n - 1; i++){
    ll u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
    deg[u]++;
    deg[v]++;
  }
  for(int i = 0; i < n; i++){
    ll a; cin >> a;
    v.push_back(a);
  }
  sort(v.begin(), v.end());

  dfs(n, -1);

  cout << ans << '\n';
  for(int i = 1; i <= n; i++) cout << val[i] << " ";
  cout << '\n';
}


Measured memory_bytes: 1664
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
const int maxn = 1005;
using namespace std;
double max(double a, double b){
	if (a > b) return a;
	else return b;
}
int n; double x[maxn], y[maxn], r[maxn];
priority_queue <pair<double, int> > q;
double dis[maxn];
double D(int a, int b){
	double d = sqrt((x[a] - x[b]) * (x[a] - x[b]) + (y[a] - y[b]) * (y[a] - y[b]));
	return max(0, d - r[a] - r[b]);
}
bool vis[maxn];
void Dijkstra(int S){
	q.push(make_pair(0, S)); memset(vis, 0, sizeof vis);
	for (int i = 1; i <= n + 1; i++) dis[i] = 0x3f3f3f3f3f3f; dis[0] = 0;
	while (!q.empty()){
		int cur = q.top().second; q.pop();
		if (vis[cur]) continue; vis[cur] = 1;
		for (int i = 1; i <= n + 1; i++){
			if (i != cur && dis[i] > dis[cur] + D(cur, i)){
				dis[i] = dis[cur] + D(cur, i);
				if (!vis[i])
					q.push(make_pair(-dis[i], i));
			}
		}
	}
}
int main(){
	scanf("%lf%lf%lf%lf", x, y, x + 1, y + 1);
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%lf%lf%lf", x + i + 1, y + i + 1, r + i + 1);
	Dijkstra(0);
	printf("%.10lf\n", dis[1]);
	return 0;
}

Measured memory_bytes: 6128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
#include<cmath>
#include<vector>
#include<queue>

using namespace std;

#define INF 2<<29

int main(){
  char c,ans;
  scanf("%c",&c);

  if(c=='A'){
    ans='T';
  }else if(c=='T'){
    ans='A';
  }else if(c=='G'){
    ans='C';
  }else{
    ans='G';
  }

  printf("%c\n",ans);
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define y1 A2Dalek
#define y0 Cyberman
#define yn RoseTyler
#define j1 JackHarkness
#define fs first
#define sd second
const int N=5e5;
const int oo=1e9+5;
int du[]={-1,0,0,1};
int dv[]={0,-1,1,0};
const long long mod=1e9+7;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
long long sqr(long long x) {return x*x;}
int getbit(int state, int i) {return ((state>>i)&1);}

string s,t;
int q,cnt1[N+5],cnt2[N+5];
int main()
{
	//freopen("TrBBnsformBBtion.inp","r",stdin);
	//freopen("TrBBnsformBBtion.out","w",stdout);
	ios_base::sync_with_stdio(false);
    cin>>s; s=" "+s;
    cin>>t; t=" "+t;
    for (int i=1;i<s.length();i++)
    {
        cnt1[i]=cnt1[i-1];
        if (s[i]=='A') cnt1[i]++; else cnt1[i]--;
    }
    for (int i=1;i<t.length();i++)
    {
        cnt2[i]=cnt2[i-1];
        if (t[i]=='A') cnt2[i]++; else cnt2[i]--;
    }
    cin>>q;
    for (int i=1;i<=q;i++)
    {
        int l,r,u,v;
        cin>>l>>r>>u>>v;
        int val=cnt1[r]-cnt1[l-1]-(cnt2[v]-cnt2[u-1]);
        if (val%3==0) cout<<"YES"<<endl; else cout<<"NO"<<endl;
    }
	return 0;
}


Measured memory_bytes: 1644
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	_ = nextInt()
	S := nextLine()
	// index := suffixarray.New([]byte(S))
	var ans int
	for i := 0; i <= 9; i++ {
		f := strconv.Itoa(i)
		fi := strings.Index(S, f)
		if fi == -1 || fi == len(S)-1 {
			continue
		}
		for j := 0; j <= 9; j++ {
			s := strconv.Itoa(j)
			si := strings.Index(S[fi+1:], s)
			// fmt.Println("fi", fi, S[fi+1:])
			if si == -1 || si == len(S[fi+1:])-1 {
				continue
			}
			for k := 0; k <= 9; k++ {
				t := strconv.Itoa(k)
				ti := strings.Index(S[fi+1:][si+1:], t)
				// fmt.Println("si", si, S[fi+1:][si+1:])
				if ti == -1 {
					continue
				}
				ans++
			}
		}
	}
	fmt.Println(ans)
}

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

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

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}

// ここから拝借
// https://shoman.hatenablog.com/entry/2020/02/25/185456
// Stackは[]intのエイリアス
type Stack []int

// Push adds an element
func (s *Stack) Push(v int) {
	*s = append(*s, v)
}

// Pop removes the top element and return it
func (s *Stack) Pop() (int, error) {
	if s.Empty() {
		return 0, fmt.Errorf("stack is empty")
	}

	v := (*s)[len(*s)-1]
	*s = (*s)[:len(*s)-1]
	return v, nil
}

// Peek returns the top value
func (s *Stack) Peek() (int, error) {
	if s.Empty() {
		return 0, fmt.Errorf("stack is empty")
	}

	return (*s)[len(*s)-1], nil
}

// Size returns the length of stack
func (s *Stack) Size() int {
	return len(*s)
}

// Empty returns true when stack is empty
func (s *Stack) Empty() bool {
	return s.Size() == 0
}

// NewStack generates stack
func NewStack() *Stack {
	s := new(Stack)
	return s
}


Measured memory_bytes: 1868
#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 Would
#define you
#define please

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

	int A, B;
	cin >> A >> B;

	int kotae = 0;
	for (int i = A; i <= B; i++) {
		string S = to_string(i);
		string S0 = S;
		rep(i, S.size() / 2) {
			swap(S[i], S[S.size() - 1 - i]);
		}
		if (S0 == S) kotae++;
	}
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 256
def f(a, d):
    b = 1
    cnt = 1
    while True:
        b += a
        if d < b:
            break
        cnt += 1

    return cnt


def main():
    n = int(input())
    d, x = map(int, input().split())
    ans = 0

    for _ in range(n):
        a = int(input())
        ans += f(a, d)

    print(ans + x)


if __name__ == "__main__":
    main()


Measured memory_bytes: 63308
s=[]
t=[]

n=int(input())
for i in range(n):
    s.append(input())
m=int(input())
for i in range(m):
    t.append(input())

word=set(s)

max_point = -101


for w in word:
    tmp=s.count(w)-t.count(w)
    if tmp >= max_point:
        max_point = tmp

if max_point < 0:
    print(0)
else:
    print(max_point)


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
using namespace std;
char a[20];
int main(){
	//freopen("scoreboard.in", "r", stdin);

	int sum=0;
	int p=0;
	while(scanf("%c",&a[++p])!=EOF&&a[p]!='\n');

	p--;
	//printf("%d\n", a[1]);
	//printf("%d\n", p);
	bool f=1;
	for(int i=2;i<=p;i++){
		if(a[i]!='9'){
			f=0;
			break;
		}
	}
	if(f==0)
	sum=a[1]-1-'0'+(p-1)*9;
	else 
	sum=(p-1)*9+a[1]-'0';

	printf("%d\n", sum);
}		

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);

        int n=scan.nextInt();
        int k=scan.nextInt();
        int x=scan.nextInt();
        int y=scan.nextInt();
        int sum=0;
        for(int i=0;i<n;i++){
            if(i<k)
                sum+=x;
            else
                sum+=y;
        }
        System.out.println(sum);

    }
}


Measured memory_bytes: 10068
#include <bits/stdc++.h>
using namespace std;
#define int long long int 
signed main()
{
    int n, k, m;
    cin >> n >> m >> k;

    int i, j, l;
    vector<int> a(n), b(m);

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

    vector<int> d(m);
    d[0] = b[0];
    for (i = 1; i < m; i++)
    {
        d[i] = d[i - 1] + b[i];
    }

    int ans = 0;
    int sum = 0;

    for (i = 0; i <= n; i++)
    {

        if (i > 0)
        {
            sum += a[i - 1];
        }

        if (sum > k)
            continue;
        int iss = i;

        int rem = k - sum;
        auto it = lower_bound(d.begin(), d.end(), rem);

        if (it != d.end())
        {
            if ((*it) == rem)
            {
                iss += (it - d.begin() + 1);
            }
            else
            {
                iss += (it - d.begin());
            }
        }
        else
        {
            iss += (it - d.begin());
        }
        ans=max(ans,iss);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 7960
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const double PI=acos(-1);
typedef pair<int,int>P;
const int mod =1e9+7;
const int INF = 99999999;
const ll LINF = 9999999999999;
const int di[]={-1,0,1,0},dj[]={0,-1,0,1};

int main()
{
    int h,w;
    cin>>h>>w;
    int ch,cw,dh,dw;
    cin>>ch>>cw;
    cin>>dh>>dw;
    ch--,cw--,dh--,dw--;
    vector<vector<char>> s(h,vector<char>(w));
    vector<vector<ll>> cost_map(h,vector<ll>(w,LINF));
    rep(i,h)
    {
        rep(j,w)
        {
            cin>>s[i][j];
            cost_map[i][j]=LINF;
        }
    }

    deque<tuple<int,int,ll>> deque;
    deque.emplace_back(make_tuple(ch,cw,0));
    while(!deque.empty())
    {
        tuple<int,int,ll> now=deque.front();
        deque.pop_front();
        int now_h=get<0>(now);
        int now_w=get<1>(now);
        ll now_cost=get<2>(now);
        cost_map[now_h][now_w]=now_cost;
        if(now_h==dh && now_w==dw)
        {
            break;
        }

        rep(i,4)
        {
            int next_h=now_h+di[i];
            int next_w=now_w+dj[i];
            ll next_cost=now_cost;
            if(next_h>=0 && next_h<h && next_w>=0 && next_w<w && cost_map[next_h][next_w]>now_cost && s[next_h][next_w]=='.')
            {
                deque.push_front(make_tuple(next_h,next_w,next_cost));
            }

        }

        rep(i,5)
        {
            rep(j,5)
            {
                int ddh=i-2;
                int ddw=j-2;
                int next_h=now_h+ddh;
                int next_w=now_w+ddw;
                if(next_h>=0 && next_h<h && next_w>=0 && next_w<w && cost_map[next_h][next_w]>now_cost+1 && s[next_h][next_w]=='.')
                {
                    deque.push_back(make_tuple(next_h,next_w,now_cost+1));
                }
            }
        }

    }

    if(cost_map[dh][dw]==LINF)
    {
        cout<<-1;
        return 0;
    }
    else
    {
        cout<<cost_map[dh][dw];
        return 0;
    }

    
}


Measured memory_bytes: 15348
#include <bits/stdc++.h>
#define MAXN 100005

int height[MAXN];
int dp[MAXN];

using namespace std;
int main(){
    int N, K;
  	cin >> N;
    cin >> K;
	for(int i = 0; i < N; i++){
    	cin >> height[i];
  }
  dp[0] = 0;
  for(int i = 1; i < K; i++){
    dp[i] = dp[i-1] + abs(height[i] - height[i-1]);
    for(int j = 2; j <= i; j++){
      if(dp[i] > dp[i-j] + abs(height[i] - height[i-j])){
        dp[i] = dp[i-j] + abs(height[i] - height[i-j]);
      }
    }
  } 
  for(int i = K; i < N; i++){
    dp[i] = dp[i-1] + abs(height[i] - height[i-1]);
    for(int j = 2; j <= K; j++){
      if(dp[i] > dp[i-j] + abs(height[i] - height[i-j])){
        dp[i] = dp[i-j] + abs(height[i] - height[i-j]);
      }
    }
  }
  cout << dp[N-1];
}

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

#define LIM_S 200002
#define LIM_N 200001
#define DIV 998244353

char str[LIM_S];

int N;
int V[LIM_N];
int C[LIM_N];

int b[LIM_N];
int sum;

void receive_input() {
	fgets(str, sizeof(str), stdin);
	sscanf(str, "%d", &N);

	for (size_t i = 0; i < N; i++) {
		scanf("%d", &V[i]);
	}

	for (size_t i = 0; i < N; i++) {
		scanf("%d", &C[i]);
	}
}

void initialize() {
	sum = 0;
	for (size_t i = 0; i < N; i++) {
		b[i] = V[i] - C[i];
		sum += b[i] > 0 ? b[i] : 0;
	}
}


int main(void) {
	receive_input();
	initialize();

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

	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main()
{
	int N, K, X, Y;
	int i, j;
	int total = 0;

	scanf("%d", &N);
	scanf("%d", &K);
	scanf("%d", &X);
	scanf("%d", &Y);

	for ( i = 0; i < N; i++)
	{
		if( i < K)
			total += X;
		else
			total += Y;
	}

	printf("%d\n", total);

	return 0;

}


Measured memory_bytes: 128
package main

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

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

func main() {
	/*//TODO:!!!!!!!テスト用!!!!!!!!!
		sc = bufio.NewScanner(strings.NewReader(`
		7
	14 14 2 13 56 2 37`))
		//TODO:!!!!!!!テスト用!!!!!!!!!*/

	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */

	n := nextInt()
	x := nextInts(n)
	start := x[0]
	end := x[0]
	ans := 10000000000
	for i := 1; i < n; i++ {
		if start > x[i] {
			start = x[i]
		}
		if end < x[i] {
			end = x[i]
		}
	}
	for i := start; i <= end; i++ {
		p := 0
		for _, xx := range x {
			p += (i - xx) * (i - xx)
		}
		if ans > p {
			ans = p
		}
	}
	fmt.Fprintln(out, ans)
}

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

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

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

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}


Measured memory_bytes: 640
import sys
input = sys.stdin.readline

n,k = map(int,input().split())
T = [int(input()) for _ in range(n)]

left = 0
right = 100000*10000

def check(p):
    i = 0
    for j in range(k):
        s = 0
        while s + T[i] <= p:
            s += T[i]
            i += 1
            if i == n:
                return n
    return i

while right - left > 1:
    mid = (left + right) //2
    v = check(mid)
    if v>=n:
        right = mid
    else:
        left = mid
print(right)
    


Measured memory_bytes: 9560
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(int i=0;i<(n); ++i)
using namespace std;
typedef long long ll;


int main()
{
	ll n;
	double sum = 0;
	cin >> n;
	vector<double>v(n);
	rep(i, n) {cin >> v[i];}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	rep(i, n) {
		if (i == n-2){
			sum += (v[n-2] + v[n-1]) * pow(0.5, n-1);
			break;
		}
		sum += v[i] * pow(0.5, i+1);
	}
	cout << fixed << setprecision(10) << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX 3005
#define reg register

using namespace std;

int N;
int stone[MAX];
int head[MAX], to[MAX << 1], nex[MAX << 1], tote;

inline int Rd() {
	int x = 0; char ch = getchar();
	while(ch < '0' || ch > '9') ch = getchar();
	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	return x;
}
inline void add_edge(int u, int v) {
	nex[++tote] = head[u], to[tote] = v, head[u] = tote;
	nex[++tote] = head[v], to[tote] = u, head[v] = tote;
	return;
}
bool dfs(int str, int fa) {
	for(int i = head[str]; i; i = nex[i]) {
		if(to[i] == fa) continue;
		if(stone[to[i]] < stone[str]) {
			if(!dfs(to[i], str)) return true;
		}
	}
	return false;
}

int main() {
	N = Rd();
	int u , v;
	for(reg int i = 1; i <= N; ++i) stone[i] = Rd();
	for(reg int i = 1; i < N; ++i) {
		u = Rd(), v = Rd();
		add_edge(u, v);
	}
	for(reg int i = 1; i <= N; ++i)
		if(dfs(i, 0)) printf("%d ", i);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
template< int id > struct CompTupleBy
{
  template<class T> 
  bool operator()( const T& a, const T& b ) const {
    return std::get<id>(a) < std::get<id>(b);
  }
};

using namespace std;

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

    int n;
    cin >> n;
    vector<ll> A;
    vector<ll> B;
    vector<ll> C;
    rep(i,n){
        ll tmp;cin >> tmp;
        A.push_back(tmp);
    }
    rep(i,n){
        ll tmp;cin >> tmp;
        B.push_back(tmp);
    }
    rep(i,n){
        ll tmp;cin >> tmp;
        C.push_back(tmp);
    }
    sort(all(A));
    sort(all(C));
    ll ans = 0;
    for(ll b : B){
        auto a_idx = lower_bound(all(A),b);
        auto c_idx = upper_bound(all(C),b);
        ll size_a = distance(A.begin(),a_idx);
        ll size_c = distance(c_idx,C.end());
        ans += (size_a * size_c);
    }
    cout << ans << endl;

    
    
}

Measured memory_bytes: 3316
N=int(input())
F=[]
P=[]
for _ in range(N):
    F.append(list(map(int,input().split())))
for _ in range(N):
    P.append(list(map(int,input().split())))

m=2**10
gain=-10**10
for i in range(1,2**10):
    x=list(map(int,format(i,'b').zfill(10)))
    sumP=0
    for j in range(N):
        total=sum([a*b for a,b in zip(x,F[j])])
        sumP+=P[j][total]
    gain=max(gain,sumP)
print(gain)


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}
void debug(istringstream&){}
template <char sep=',', class Head, class... Tail>
void debug(istringstream& iss, Head&& head, Tail&&... tail)
{
  string name;
  getline(iss, name, ',');
  cerr << sep << name << "=" << head;
  debug(iss, forward<Tail>(tail)...);
}
#define DEBUG(...) \
  do{ \
    istringstream ss(#__VA_ARGS__); \
    debug<' '>(ss, __VA_ARGS__); \
    cerr<<endl; \
  }while(0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

LL dp[100000+10][2];
LL solve(VVI& G, int u, int p){
  dp[u][0] = dp[u][1] = 1;

  for(int to: G[u]){
    if(to == p) continue;
    (dp[u][0] *= solve(G, to, u)) %= MOD;
    (dp[u][1] *= dp[to][0]) %= MOD;
  }

  return (dp[u][0] + dp[u][1]) % MOD;
}

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

  int N;
  cin >> N;
  VVI G(N);
  REP(i,N-1){
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    G[x].PB(y);
    G[y].PB(x);
  }

  cout << solve(G, 0, -1) << endl;

  return 0;
}


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long N, long long Q, std::string S, std::vector<long long> l, std::vector<long long> r){
    VI memo(N+1, 0);
    REP(i, N-1) {
        if(S[i] == 'A' && S[i+1] == 'C') {
            memo[i+1]++;
        }
        memo[i+2] = memo[i+1];
    }

    // ACAC
    // 0 1 0 1 0
    // 0 1 1 2 2
    REP(i, Q) {
        cout << memo[r[i]-1] - memo[l[i]-1] << endl;
    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long Q;
    scanf("%lld",&Q);
    std::string S;
    std::cin >> S;
    std::vector<long long> l(Q);
    std::vector<long long> r(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&l[i]);
        scanf("%lld",&r[i]);
    }
    solve(N, Q, S, std::move(l), std::move(r));
    return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */

int main() {
  ll n; cin >> n;
  if(n>=1000){
    cout << "ABD";
  }else{
    cout << "ABC";
  }
  cout << endl;
}


Measured memory_bytes: 256
from collections import deque

modulo = 10 ** 9 + 7

N, K = map(int, input().split())
adj = {a: [] for a in range(1, N + 1)}
for i in range(N - 1):
    a, b = map(int, input().split())
    adj[a].append(b)
    adj[b].append(a)

def P(n, k):
    if n < k:
        return 0
    f = 1
    for i in range(n, n - k, -1):
        f = f * i % modulo
    return f

visited = set()
q = deque([1])
ncoloring = K  # num of coloring of the root

while len(q) > 0:
    u = q.popleft()
    visited.add(u)

    # coloring of the children
    children = [c for c in adj[u] if c not in visited]
    ncoloring *= P(K - 1 if u == 1 else K - 2, len(children))
    ncoloring %= modulo

    q.extend([c for c in children])

print(ncoloring)


Measured memory_bytes: 81512
n, m = map(int, input().split())
l = list(map(int, input().split()))
cor = [[] for i in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    cor[a].append(b)
    cor[b].append(a)

ans = 0
for i in range(n):
    max_h = l[i]
    cnt = 1
    co = list(set(cor[i]))
    for j in range(len(co)):
        if l[co[j]] >= max_h:
            cnt = 0
            break
    ans += cnt

print(ans)





Measured memory_bytes: 31960
x,n=map(int,input().split())
l=list(map(int,input().split()))
num=[]
for i in range(-100,102):
    num.append(i)
for i in l:
    num.remove(i)
dif=101
ans=[]
for i in num:
    if dif>abs(i-x):
        dif=abs(i-x)
        ans=[i]
    elif dif==abs(i-x):
        ans.append(i)
print(min(ans))

Measured memory_bytes: 9200
#include <iostream>
using namespace std;
int main(void){
  int N;
  std::cin >> N;
  int a[N][3];
  for(int i = 0; i < N; i++) std::cin >> a[i][0] >> a[i][1] >> a[i][2]; 
  int dp[N+1][3];
  for(int i = 0; i < N+1; i++){
    for(int j = 0; j < 3; j++){
      dp[i][j] = 0;
    }
  }
  for(int i = 0; i < N; i++){
    for(int j = 0; j < 3; j++){
      dp[i+1][j] = max(dp[i][(j+1)%3]+a[i][j], dp[i][(j+2)%3]+a[i][j]);
    }
  }
  cout << max(max(dp[N][0], dp[N][1]), dp[N][2]) << endl;
}



Measured memory_bytes: 2560
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<(int)(n);i++)
#define N 200000

int main() {
	long long x, y, z;
	int s, ans;
	scanf("%lld %lld", &x, &y);
  if(x>y)swap(x,y);
  if(x==1){
   printf("1\n");
    return 0;
  }
	z = (x*y);
	z = (z + 1) / 2;
	printf("%lld\n", z);


	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=9999999999;

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    for(int i=0;i<1000;i++){
        c-=b;
        if(c<=0){
            cout<<"Yes"<<endl;
            break;
        }
        a-=d;
        if(a<=0){
            cout<<"No"<<endl;
            break;
        }
    }
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k, s;
    cin >> n >> k >> s;
    rep(i,k) cout << s << " ";
    if(s == 1000000000){
        rep(i,n-k) cout << 999999999 << " ";
    }
    else{
        rep(i,n-k) cout << s+1 << " ";
    }
    cout << endl;
	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(ll i=0;i<n;i++)
#define Rip(i,n) for(ll i=1;i<=n;i++)
#define all(V) V.begin(),V.end()
#define ll long long
#define ld long double
#define MOD 1000000007
#define mod 998244353
#define sec setprecision
#define Pair pair<ll,ll>
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
constexpr double eps = 1e-9;
constexpr double pi = 3.141592653589793238462643383279;
using namespace std;
ll gcd(ll a, ll b)
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
ll pow(ll x, ll n) {
	x %= mod;
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return (pow((x * x)%mod , n / 2)%mod);
	else
		return (x * pow(x, n - 1))%mod;
}
int main() {
	int n;
	cin >> n; 
	if (n % 1000 != 0)cout << (1000 - n % 1000) << endl;
	else cout << 0 << endl;
}

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

int main() {
  int h,w;
  cin >> h >> w;
  string board[h];
  for(int i=0; i<h; i++) cin >> board[i];
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      if(board[i][j]=='.'){
        int count =0;
        if (i>0){
          if (board[i-1][j] == '#') count++;
          if (board[i-1][j+1] == '#') count++;
      	}
        if (j>0){
          if (board[i][j-1] == '#') count++;
          if (board[i+1][j-1] == '#') count++;
      	}
        if (j>0 && i>0){
          if (board[i-1][j-1] == '#') count++;
      	}
        if (w > j){
          if (board[i][j+1] == '#') count++;
        }
        if (h > i){
          if (board[i+1][j] == '#') count++;
        }
        if (h > i && w > j){
          if (board[i+1][j+1] == '#') count++;
        }
        board[i][j] = '0' + count;
      }
    }
  }
  for(int i=0; i<h; i++) cout << board[i] << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        double a=fs.nextDouble();
        double b=fs.nextDouble();
        double h=fs.nextDouble();
        double m=fs.nextDouble();

        double cos=Math.cos(Math.toRadians( (h*30+m*0.5) -m*6));
        double ans= Math.pow(a, 2)+ Math.pow(b, 2)- 2 * a * b * cos;

        System.out.println(Math.sqrt(ans));
    }
}

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

    private boolean hasNextByte() {
        if (ptr < buflen)
            return true;
        else
            ptr = 0;
        try {
            buflen = in.read(buffer);
        } catch (final 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(final int c) {
        return 33 <= c && c <= 126;
    }

    private void skipUnprintable() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
    }

    public boolean hasNext() {
        skipUnprintable();
        return hasNextByte();
    }

    public String next() {
        final StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public int nextInt() {
        return (int) nextLong();
    }

    public double nextDouble() {
        return (double) nextLong();
    }

    public long nextLong() {
        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();
        }
    }
}

Measured memory_bytes: 33096
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
int a[100010];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') ch=getchar(),o=-1;
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int main() {
    int n,L,x=0;
    cin>>n>>L;
    for(int i=1;i<=n;i++) {
	a[i]=gi();
	if(a[i]+a[i-1]>=L) x=i-1;
    }
    if(!x) return puts("Impossible"),0;
    puts("Possible");
    for(int i=1;i<x;i++) printf("%d\n",i);
    for(int i=n-1;i>x;i--) printf("%d\n",i);
    cout<<x;
    return 0;
}

Measured memory_bytes: 1152
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let r: i32 = input();
    let d: i32 = input();
    let x2000: i32 = input();

    let mut temp = x2000;
    for _ in 2001..2011 {
        temp = r * temp - d;
        println!("{}", temp);
    }
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <stdlib.h>
#define MAX 100
int compare_int(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}

int main(void) {
    int n, i, j, min=1000000, sum=0, left, right;
    int a[MAX];
    scanf("%d", &n);
    
    for(i=0; i<n; i++) {
        scanf("%d", &a[i]);
    }
    
    qsort(a, n, sizeof(int), compare_int);
    left = a[0];
    right = a[n-1];
    for(i=left; i<=right; i++) {
        sum = 0;
        for(j=0; j<n; j++)
            sum += (a[j]-i) * (a[j]-i);
        if(sum<=min)
            min = sum;
    }
    printf("%d\n", min);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    
    int n;
    cin >> n;
    int t = 0;
    int x = 0;
    int y = 0;
    for (int i = 0; i < n; ++i)
    {
        int tt, xx, yy;
        cin >> tt >> xx >> yy;
        int len = fabs(xx - x) + fabs(yy - y);
        int used = fabs(tt - t);
        if (len > used || ((used - len) % 2 != 0))
        {
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
    
    return 0;
}

Measured memory_bytes: 256
import sys
M = 998244353

n = int(input())
d = list(map(int, input().split()))
idx = [0]*n
ans = 1
for i in range(n):
    idx[d[i]] += 1

if not d[0] == 0 or not idx[0] == 1:
    print(0)
else:
    for i in range(1,n):
        if idx[i-1] == 0:
            if not idx[i] == 0:
                print(0)
                sys.exit()
        else:
            ans *= idx[i-1]**idx[i]%M
    else:
        print(ans%M)


Measured memory_bytes: 14396
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a), i##_end = (b); i < i##_end; ++i)
#define per(i, a, b) for (int i = (a), i##_end = (b); i >= i##_end; --i)

using namespace std;

int main()
{
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	printf("%d\n", min(a+b, min(b+c, c+a)));
	return 0;
}


Measured memory_bytes: 256
import std.stdio,std.conv, std.algorithm, std.container,std.array,std.range,std.string,std.typecons,std.numeric,std.math,std.random,std.concurrency;
const dx = [1,0,-1,0], dy = [0,1,0,-1];
const readMixin = q{ auto line = readln().split();foreach(i,ref arg; args){ if (i >= line.length) return;arg = line[i].to!(typeof(arg));}};
void read(T...)  (auto ref T args){ mixin(readMixin);}
void readArray(T)(auto ref T args){ mixin(readMixin);}
int read(){int n;read(n);return n;}
void times(int n,void delegate() stmt){foreach(i;iota(n))stmt();}
auto dot(R1,R2)(R1 a,R2 b){ElementType!(R1) res=0;for(;!a.empty&&!b.empty;a.popFront(),b.popFront())res+=a.front*b.front;return res;}
struct infIota{
	int i = 0;
	enum empty = false;
	int front() { return i; }
	void popFront() { i++; }
}

int calc(int n){
	if (n < 10) return 0;
	int [] ns;
	while(n){ns ~= n % 10;n /= 10;}
	int [] res;
	auto tens = ()=> infIota().map!"10^^a";
	foreach(i;1 .. ns.length){
		res ~= ns[0..i].dot(tens()) * ns[i..$].dot(tens());
	}
	return 1 + calc(res.reduce!(max));
}
void main(){ 
	read().times({ read().calc.writeln; });
}

Measured memory_bytes: 2980
#include <iostream>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
#include<cassert>
using namespace std;
typedef long long ll;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX_N 200100
#define MAX_B 1001001//6
#define MAX_S 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
#define MOD 1000000007
#define INF 1<<30
#define INFTY 1000000000000000001LL
#define MAX_INT INT_MAX
#define Endl '\n'
#define mian() main()
#define greater greater<int>()
VI findAll(string S,string pattern){VI P;ll pos=(ll)S.find(pattern);
while(pos!=string::npos){P.push_back(pos);pos=(ll)S.find(pattern,pos+1);}return P;}
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
bool is_prime(ll n){if(n<2)return 0;for(int i=2;i*i<n;i++)if(n%i==0)return 0;return 1;}
inline void eratosthenes(VB& p){rep(i,SZ(p))p[i]=1;p[0]=p[1]=0;
rep(i,SZ(p)/2+1){if(p[i])for(ll j=i+i;j<SZ(p);j+=i)p[j]=0;}}
inline ll mod_add(ll a,ll b){return (a+b)%MOD;}
inline ll mod_sub(ll a,ll b){return (a+MOD-b)%MOD;}
inline ll mod_mul(ll a,ll b){return ((a%MOD)*(b%MOD))%MOD;}
inline ll mod_pow(ll x,ll n,ll mod=(ll)MOD){ll res=1;while(n>0){
if(n&1)res=res*x%mod;x=x*x%mod;n>>=1;}return res;}
inline ll mod_inv(ll x){return mod_pow(x,MOD-2);}
inline ll mod_div(ll a, ll b){return mod_mul(a,mod_inv(b));}

using Graph=vector<vector<P> >;
int n,m,q;
int a[50],b[50],c[50],d[50];
int ans=0;

void dfs(VI &buf,int i,const int size,const int range_start,const int range_end){
    if(i==size){
        int score=0;
        rep(k,q){
            if(buf[b[k]]-buf[a[k]]==c[k])score+=d[k];
        }
        ans=max(ans,score);
        return;
    }
    else{
        for(int j=range_start;j<=range_end;++j){
            buf[i]=j;
            dfs(buf,i+1,size,j,range_end);
            //第4引数にjを入れると増加列,range_startを入れると全通り
        }
    }
}
int main(){
    cin>>n>>m>>q;
    rep(i,q){cin>>a[i]>>b[i]>>c[i]>>d[i];a[i]--;b[i]--;}
    VI buf(n);
    dfs(buf,0,n,1,m);
    cout<<ans<<endl;
}

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

int N;
string ds = ".#";


int main(){
  cin >> N;

  string s1 = "", s2 = "";
  bool LR = false;
  while( true ){

    string ns1 = s1, ns2 = s2;
    bool ok = false;
    for( char c1 : ds ){
      for( char c2 : ds ){
        if( LR ) {
          ns1 = c1 + s1; ns2 = c2 + s2;
        } else {
          ns1 = s1 + c1; ns2 = s2 + c2;
        }
        cout << ns1 << endl;
        cout << ns2 << endl;

        string res; cin >> res;
        if( res == "end" ) return 0;
        else if( res == "T" ) {
          ok = true;
          s1 = ns1; s2 = ns2;
          goto loop;
        }         
      }
    }


  loop:;
    if( !ok ) LR = true;
  }
  
}


Measured memory_bytes: 716