akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

class Main {
  public static void main(String[] args) throws Exception{
    try (Scanner sc = new Scanner(System.in)){
      String S = sc.next();
      Double K = sc.nextDouble();
      if (K < 1.5) {
        System.out.println(S.charAt(0));
      } else {
        int i = 0;
        while(i < S.length()-1 && S.charAt(i) == '1') {
          i++;
        }
        if (K < 101.0 && i == K.intValue()) {
          System.out.println('1');
        } else {
          System.out.println(S.charAt(i));
        }
      }
    }
  }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)

int main(){
 
 
  string s;
  cin>>s;
  ll n=s.size();
  rep(i,n){
      if(s[i]!=s[n-1-i]){
          cout<<"No"<<endl;
          return 0;
      }
  }
  
  rep(i,(n-1)/2){
     if(s[i]!=s[(n-1)/2-1-i]){
          cout<<"No"<<endl;
          return 0;
      } 
  }
  
  cout<<"Yes"<<endl;
  
  
 
}



Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, c, d; cin >> a >> b >> c >> d;
	vector<int>v(10000, 0);
	v[a]++; v[b]--; v[c]++; v[d]--;
	rep(i, 1, v.size())v[i] += v[i - 1];
	int cnt(0);
	rep(i, 0, v.size())if (v[i] == 2)cnt++;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
use proconio::input;
use proconio::marker::Bytes;
use std::collections::HashMap;

type i64 = i128;
const A:i64 = 1e5 as i64 +2;
const M:i64 = 1e18 as i64 +9;
fn main(){
    input! {
        n:usize,
        s:Bytes
    };
    
    let mut lb = 0;
    let mut ub = n+1;

    while ub-lb>1 {
        let mid = (lb+ub)/2;

        let mut fnd = false;

        let mut sum = 0;
        let mut am =1;
        for i in 0..(mid-1) {
            sum = (sum*A+(s[i] as i64))%M;
            am = am*A%M;
        }
        let am = am;

        let mut hm:HashMap<i64,usize> = HashMap::new();
        for i in (mid-1)..n {
            sum = (sum*A+(s[i] as i64))%M;
            if hm.contains_key(&sum) {
                fnd = fnd || i-hm[&sum]>=mid;
            }
            hm.entry(sum).or_insert(i);
            sum = ((sum - am*(s[i-(mid-1)] as i64))%M+M)%M;
        }

        if fnd {
            lb=mid;
        } else {
            ub=mid;
        }
    }
    println!("{}",lb);
}



Measured memory_bytes: 2540
//Leonidas
#pragma GCC optimize("Ofast")
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container'.',hpp>
//#include <ext/pb_ds/tree_policy'.',hpp>
//typedef tree < int , null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> TREE;
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define pss pair<short,short>
#define pld pair<long double,long double >
#define ld long double
#define piii  pair<pii,int>
#define vii vector<pair<int,int> >
#define st first
#define nd second
#define pll pair<ll,ll>
#define speed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define M_PI 3.14159265358979323846
//#define int long long
const int mod=1000000007;
//const int mod=1009;
//const int mod=998244353;
const int inf=1000000009;
const long long INF=1000000000000000009;
const long long big=1000000000000000;
const long double eps=0.000000000000000000001;
using namespace std;
int T[100005];
int32_t main()
{
    speed
    int n,q;
    cin>>n;
    ll suma=0;
    for(int i=1;i<=n;i++)
    {
        int a;
        cin>>a;
        T[a]++;
        suma+=a;
    }
    cin>>q;
    for(int i=1;i<=q;i++)
    {
        int a,b;
        cin>>a>>b;
        suma-=(ll)a*T[a];
        suma+=(ll)b*T[a];
        T[b]+=T[a];
        T[a]=0;
        cout<<suma<<"\n";
    }
    return 0;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

// G13E_6.cpp

template<int N> void mat_prod(LL a[N][N], LL b[N][N], LL c[N][N], LL MOD) { // a = b * c;
	LL d[N][N];
	inc(i, N) {
	inc(j, N) {
		d[i][j] = 0;
	}
	}
	
	inc(i, N) {
	inc(j, N) {
	inc(k, N) {
		(d[i][j] += b[i][k] * c[k][j]) %= MOD;
	}
	}
	}
	
	inc(i, N) {
	inc(j, N) {
		a[i][j] = d[i][j];
	}
	}
	
	return;
}

template<int N> void mat_exp(LL a[N][N], LL b[N][N], LL c, LL MOD) { // a = b ^ c;
	LL t[60][N][N];
	inc(i, N) {
	inc(j, N) {
		t[0][i][j] = b[i][j];
	}
	}
	inc(i, 60 - 1) {
		mat_prod<N>(t[i + 1], t[i], t[i], MOD);
	}
	
	inc(i, N) {
	inc(j, N) {
		a[i][j] = 0;
	}
	}
	inc(i, N) { a[i][i] = 1; }
	inc(i, 60) {
		if((c >> i) % 2 == 1) {
			mat_prod<N>(a, a, t[i], MOD);
		}
	}
	
	return;
}

// ----

LL n, m, x[100002];
const LL MOD = 1000000007;

int main() {
	cin >> n >> m;
	inc1(i, m) { cin >> x[i]; }
	x[0] = 0;
	x[m + 1] = n + 1;
	
	LL a[3][3] = { { 2, 1, 1 }, { 2, 1, 0 }, { 1, 1, 1 } };
	LL b[3][3] = { { 1, 0, 0 }, { 2, 1, 0 }, { 1, 1, 1 } };
	LL c[3][3] = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
	LL d[3][3];
	
	inc(i, m + 1) {
		if(i != 0) { mat_prod<3>(c, b, c, MOD); }
		mat_exp<3>(d, a, x[i + 1] - x[i] - 1, MOD);
		mat_prod<3>(c, d, c, MOD);
	}
	
	cout << c[2][0] << endl;
	
	return 0;
}


Measured memory_bytes: 1024
package main

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

var sc = bufio.NewScanner(os.Stdin)
var ReadString func() string
var ReadLine func() string
var ReadInt64 func() int64
var ReadInt func() int
var ReadIntSlice func(int) []int
var ReadInt64Slice func(int) []int64
var GetIntAbs func(int) int
var Atoi func(string) int
var FindMin func([] int) int
var FindMax func([] int) int
var StrReverse func(string) string

func init() {
	ReadString = newReadString()
	ReadLine = readLine
	ReadInt64 = readInt64
	ReadInt = readInt
	ReadIntSlice = readIntSlice
	FindMin = findMin
	FindMax = findMax
	StrReverse = strReverse
	GetIntAbs = getIntAbs
}

func main() {
	n := ReadInt()
  if (n == 1) {
    fmt.Println(1)
  } else {
	fmt.Println(n * n * n)
  }
}

func strReverse(s string) string {
	runes := []rune(s)
	l := len(runes)
	for i, j := 0, l-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}


func newReadString() func() string {
	sc.Buffer(make([]byte, 202400), 404800)
	sc.Split(bufio.ScanWords)
	return func() string {
		if !sc.Scan() {
			panic("scanできなかった")
		}
		return sc.Text()
	}
}

func readLine() string {
	if !sc.Scan() {
		panic("line をscanできなかった")
	}
	return sc.Text()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		fmt.Println("parseInt失敗")
		panic(err.Error())
	}
	return int64(i)
}

func readInt() int {
	i := ReadInt64()
	return int(i)
}

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

func readInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt64()
	}
	return arr
}

/*------ number util ------*/

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

func atoi(a string) int {
	i, err := strconv.Atoi(a)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func findMin(arr []int) int {
	if len(arr) == 0 {
		return 0
	}
	min := arr[0]
	for _, v := range arr {
		if v < min {
			min = v
		}
	}
	return min
}

func findMax(arr []int) int {
	if len(arr) == 0 {
		return 0
	}
	max := arr[0]
	for _, v := range arr {
		if v > max {
			max = v
		}
	}
	return max
}


Measured memory_bytes: 640
n  = int(input())

a = list(map(lambda x: int(x)-1, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
for i in range(n):
    ans += b[i]
    if i > 0 and a[i] - a[i-1] == 1:
        ans += c[a[i-1]]

print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

ll knapsnack(ll v[],int w[],vector<vector<ll>> &dp,int n,int i,int wt)
{
	if(i>=n)
	{
		return 0;
	}
	if(dp[i][wt]!=-1)
	{
		return dp[i][wt];
	}
	ll ans=0;
	if(w[i]<=wt)
	{
		ans=v[i]+knapsnack(v,w,dp,n,i+1,wt-w[i]);
	}
	return dp[i][wt]=max(ans,knapsnack(v,w,dp,n,i+1,wt));
}

int main()
{
	int i,n,wt;
	cin>>n>>wt;
	ll v[n];
	int w[n];
	for(i=0;i<n;i++)
	{
		cin>>w[i]>>v[i];
	}
	vector<vector<ll>> dp(n,vector<ll>(wt+1,-1));
	cout<<knapsnack(v,w,dp,n,0,wt);
}

Measured memory_bytes: 82272
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
using namespace std;
typedef long long ll;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
int main(){/*
    freopen("in","r",stdin);
    freopen("out","w",stdout);*/
    fast;
    int n,m;
    cin >> n >> m;
    int v[n + 1];
    fore(i,0,n)cin >> v[i];
    int cnt = 0;
    int sum = 0;
    fore(i,0,n){
        sum += v[i];
    }
    fore(i,0,n){
        if(v[i] * 4 * m >= sum)
            cnt++;
    }
        cout << (cnt >= m? "Yes":"No") << '\n';
    return 0;   
}

Measured memory_bytes: 256
# AtCoder Beginner Contest 174
# C - Repsept

K=int(input())

modsevens=[7]

if K==7 or K==1:
    print(1)
    exit()
else:
    pass

for i in range (1,K):
    a=(modsevens[-1] *10+7)%K
    
    if a==0:
        print(i+1)
        exit()
    else:
        modsevens.append(a)

print(-1)

Measured memory_bytes: 48632
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_EQ(i,a,b) for(int i = (a); i <= (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
#define rep_eq(i,n) FOR_EQ(i,0,n)
#define rep_re(i,n) FOR_RE(i,n,0)
//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int divisor_count;
    int ans = 0;
    cin >> n;
    for(int i = 1; i <= n; i += 2){
        divisor_count = 2;
        for(int j = 3; j < i; j += 2){
            if(i % j == 0)  divisor_count++;
        }
        if(divisor_count == 8)  ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;
int d1[2505][10005]; 
int d2[2505][10005]; 
int n, k, x, a[2505];
int main()
{
	for(int i=0; i<=2500; i++)
	{
		int s[10005] = {};
		if(i > 0)
			for(int j=1; j<=10000; j++) s[j] = (s[j-1] + d1[i-1][j]) % mod;
		
		for(int j=1; j<=10000; j++)
		{
			if(j <= 2 * i + 1) d2[i][j]++;
			d2[i][j] += s[j-1] - s[max(0, j-2*i-1)] + mod;
			d2[i][j] %= mod;
		}
		for(int j=1; j<=10000; j++) s[j] = (s[j-1] + d2[i][j]) % mod;
		for(int j=1; j<=10000; j++)
		{
			if(j <= 2 * i + 2) d1[i][j]++;
			d1[i][j] += s[j-1] - s[max(0, j-2*i-3)] + mod;
			d1[i][j] %= mod;
		}
	}
	cin >> n >> k >> x;
	for(int i=0; i<k; i++) cin >> a[i];
	lint ret = 1;
	for(int i=1; i<k; i++)
	{
		if(x - i < 0) ret = 0;
		else ret *= d1[x-i][a[i] - a[i-1]];
		ret %= mod;
	}
	cout << ret << endl;
}

Measured memory_bytes: 195968
#include<stdio.h>
int a(int x){return x<0?-x:x;}
int main(){
  int p[90001][2],t,i,j,h,w,d,q,l,r,c[90001]={};
  scanf("%d%d%d",&h,&w,&d);
  for(i=0;i<h;i++)for(j=0;j<w;j++){scanf("%d",&t);p[t][0]=i;p[t][1]=j;}
  scanf("%d",&q);
  for(i=1;i<=d;i++)for(j=i+d;j<=h*w;j+=d)c[j]=c[j-d]+a(p[j][0]-p[j-d][0])+a(p[j][1]-p[j-d][1]);
  for(i=0;i<q;i++){scanf("%d%d",&l,&r);printf("%d\n",c[r]-c[l]);}
}


Measured memory_bytes: 2764
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define watch(x) cout<<"->"<<#x<<" : "<<x<<endl;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c)) 
typedef long long ll;
typedef unsigned long long llu;
const double PI = 2*acos(0.0);
#define int long long 
signed main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;	
	cin>>n;
	int res = (n/11)*2;
	if(n%11>6)
		res+=2;
	else if(n%11>0)
		res+=1;
	cout<<res<<endl;
	return 0;
}

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

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    while(n) {
        if(n%10 == 7) {
            cout << "Yes\n";
            return 0;
        }
        n=n/10;
    }
    cout << "No\n";
    return 0;
}

Measured memory_bytes: 3640
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n, m;
        cin >> n >> m;
        if(n == 0)
            return 0;

        vector<pair<int, int> > a(n);
        for(int i=0; i<n; ++i)
            cin >> a[i].second >> a[i].first;
        sort(a.rbegin(), a.rend());

        int ret = 0;
        for(int i=0; i<n; ++i){
            ret += max(0, a[i].second - m) * a[i].first;
            m -= min(m, a[i].second);
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 1276
# -*- coding: utf-8 -*-

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7

class BIT:

    def __init__(self, n):
        # 0-indexed
        nv = 1
        while nv < n:
            nv *= 2
        self.size = nv
        self.tree = [0] * nv

    def sum(self, i):
        """ [0, i]を合計する """
        s = 0
        i += 1
        while i > 0:
            s += self.tree[i-1]
            i -= i & -i
        return s

    def add(self, i, x):
        """ 値の追加：添字i, 値x """
        i += 1
        while i <= self.size:
            self.tree[i-1] += x
            i += i & -i

    def get(self, l, r=None):
        """ 区間和の取得 [l, r) """
        # 引数が1つなら一点の値を取得
        if r is None: r = l + 1
        res = 0
        if r: res += self.sum(r-1)
        if l: res -= self.sum(l-1)
        return res

N, K = MAP()
# 予め-Kした状態で用意しておく
A = [a-K for a in LIST(N)]

# 累積和
acc = [0] + list(accumulate(A))
# 座標圧縮
zip_acc = {}
for i, a in enumerate(sorted(set(acc))):
    zip_acc[a] = i

bit = BIT(len(zip_acc))
cnt = 0
for a in acc:
    # 自分より左にある、自分の値以下の数(転倒数の数え上げ)
    cnt += bit.sum(zip_acc[a])
    bit.add(zip_acc[a], 1)
print(cnt)


Measured memory_bytes: 53168
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	int H, W;
	cin >> H >> W;
	vector<string> S(H);
	for (auto &x : S) {
		cin >> x;
	}

	vector<vector<int>> L(H, vector<int>(W, 0));
	vector<vector<int>> R(H, vector<int>(W, 0));
	vector<vector<int>> U(H, vector<int>(W, 0));
	vector<vector<int>> D(H, vector<int>(W, 0));

	for (int y = 0; y < H; ++y) {
		for (int x = 1; x < W; ++x) {
			if (S[y][x] == '.' && S[y][x - 1] == '.') {
				L[y][x] = L[y][x - 1] + 1;
			}
		}
		for (int x = W - 2; x >= 0; --x) {
			if (S[y][x] == '.' && S[y][x + 1] == '.') {
				R[y][x] = R[y][x + 1] + 1;
			}
		}
	}
	for (int x = 0; x < W; ++x) {
		for (int y = 1; y < H; ++y) {
			if (S[y][x] == '.' && S[y - 1][x] == '.') {
				U[y][x] = U[y - 1][x] + 1;
			}
		}
		for (int y = H - 2; y >= 0; --y) {
			if (S[y][x] == '.' && S[y + 1][x] == '.') {
				D[y][x] = D[y + 1][x] + 1;
			}
		}
	}

	int ans = 0;
	for (int y = 0; y < H; ++y) {
		for (int x = 0; x < W; ++x) {
			if (S[y][x] == '.') {
				int tmp = 1 + L[y][x] + R[y][x] + U[y][x] + D[y][x];
				ans = max(ans, tmp);
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 69248
#include <assert.h>
#include <limits.h>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cout << i << "\n"

//const ll MOD = 998244353;
const ll MOD = 1e9+7;


 
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll n,k;
  std::cin>>n>>k;
  std::vector<ll> a(n);
  rep(i,0,n)std::cin>>a[i];
  std::sort(all(a));

  ll left=-1,right=n;
  std::vector<std::vector<bool>> dp(n, std::vector<bool>(k, false));
  while(right-left>1){
    ll mid=left+(right-left)/2;
    bool flag = false;

    if(a[mid]>=k){
      flag=true;
    }else{
      rep(i,1,k)dp[0][i]=false;
      dp[0][0]=true;
      rep(i,0,n-1){
        ll temp=i;
        if(temp>=mid)temp++;
        rep(j,0,k){
          dp[i+1][j]=dp[i][j]|dp[i][(j-a[temp]>=0)?j-a[temp]:j];
        }
      }
      rep(i,k-a[mid],k)flag=(flag|dp[n-1][i]);
    }
    if(flag)right=mid;
    else left=mid;
  }

  std::cout<<left+1;
  return 0;
}

Measured memory_bytes: 3584
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// #include <functional> 
// using namespace __gnu_pbds;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
#define MaX 300005
using namespace std;

 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1e18;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void doc()
{
   	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
// typedef tree<int, null_type, less<int>, rb_tree_tag, 
//              tree_order_statistics_node_update> 
//     new_data_set; 
bool isprime(ll n) 
{ 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}



int main()
{
	fast();
	ll a;
	cin>>a;
	cout<<a+a*a+a*a*a;
}




/*
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀⠀⠀⠀⠀
⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀⠀⠀
⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄⠀
⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿⠀
⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸⠀
⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂⠀⠀⠀
⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁⠀⠀⠀⠀⠀
*/

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF=1e18;
const int MOD=1e9+7;
const double pi=acos(-1);

int main(){
  int h,w;
  cin >> h >> w;

  ll c[10][10]={};
  rep(i,10){
    rep(j,10){
      cin >> c[i][j];
    }
  }
  rep(k,10){
    rep(i,10){
      rep(j,10){
        c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
      }
    }
  }
  ll ans=0;
  rep(i,h){
    rep(j,w){
      ll a;
      cin >> a;
      if(a==-1 || a==1)continue;
      else ans+=c[a][1];
    }
  }
  cout << ans << endl;
}

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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    string s; cin >> s;
    int max = 0;
    int cnt = 1;
    for(int i=0; i<s.length(); i++){
        if(s[i]=='A' || s[i]=='T' || s[i]=='G' || s[i]=='C'){
            int tmp = i;
            while(true){
                tmp++;
                if(tmp>s.length()-1) break;
                else if(s[tmp]=='A' || s[tmp]=='T' || s[tmp]=='G' || s[tmp]=='C'){
                    cnt++;
                }
                else break;
            }
            if(cnt>max) max = cnt;
        }
        cnt = 1;
    }
    
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int sx, sy, tx, ty;

int main(){
  cin >> sx >> sy >> tx >> ty;
  rep(i, ty-sy) cout << "U";
  rep(i, tx-sx) cout << "R";
  rep(i, ty-sy) cout << "D";
  rep(i, tx-sx) cout << "L";
  cout << "L";
  rep(i, ty-sy+1) cout << "U";
  rep(i, tx-sx+1) cout << "R";
  cout << "D";
  cout << "R";
  rep(i, ty-sy+1) cout << "D";
  rep(i, tx-sx+1) cout << "L";
  cout << "U" << endl;
  return 0;
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto N = RD;
	auto M = RD;
	auto Q = RD;
	auto abcd = new long[][](Q);
	foreach (i; 0..Q)
	{
		abcd[i] = [RD-1, RD-1, RD, RD];
	}
	
	long dfs(long[] arr)
	{
		if (arr.length == N)
		{
			long score;
			foreach (i; 0..Q)
			{
				auto a = abcd[i][0];
				auto b = abcd[i][1];
				auto c = abcd[i][2];
				auto d = abcd[i][3];
				if (arr[b]-arr[a] == c)
					score += d;
			}
			return score;
		}

		long res;
		foreach (i; arr[$-1]..M+1)
		{
			res.chmax(dfs(arr ~ i));
		}
		return res;
	}

	long ans;
	foreach (i; 1..M+1)
	{
		ans.chmax(dfs([i]));
	}

	writeln(ans);
	stdout.flush;
	debug readln;
}


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

int n,q;
int indeg[MAX];
bool color[MAX];
vector<int> G[MAX];
vector<int> R;

void bfs(int point){
    queue<int> q;
    q.push(point);
    color[point] = false;
    while(!q.empty()){
        int u = q.front();
        q.pop();
        R.push_back(u);
        for(int i=0;i<G[u].size();++i){
            int v = G[u][i];
            indeg[v]--;
            if(indeg[v]==0&&color[v]==true){
                color[v] = false;
                q.push(v);
            }
        }
    }
}


int main(){
    int v, e, s, t;
    scanf("%d %d",&v,&e);
    for(int i=0;i<v;++i){
        indeg[i] = 0;
        color[i] = true;
    }
    for(int i=0;i<e;++i){
        scanf("%d %d",&s,&t);
        indeg[t]++;
        G[s].push_back(t);
    }
    for(int i=0;i<v;++i){
        if(indeg[i]==0 && color[i]==true){
            bfs(i);
        }
    }
    for(int i=0;i<R.size();++i){
        printf("%d\n",R[i]);
    }
    return 0;
}



Measured memory_bytes: 3968
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N; cin >> N;
    int ans = 1;
    REP(i, N + 1)ans *= i;
    vector<int>P(N);
    vector<int>Q(N);
    rep(i, N)cin >> P[i];
    rep(i, N)cin >> Q[i];
    vector<int>A(N);
    int a, k;
    REP(i, N + 1)A[i - 1] = i;
    sort(A.begin(), A.end());
    rep(j, ans) {
        bool b = false;
        bool o = false;
        rep(i, N - 1) {
            if (A[i] != P[i])b = true;
            if (A[i] != Q[i])o = true;
            if (b == false && i == N - 2)a = j;
            if (o == false && i == N - 2)k = j;
        }
        next_permutation(A.begin(), A.end());
    }
    cout << max(a, k) - min(a, k) << endl;
}

Measured memory_bytes: 3640
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
for i in range(N):
    k = A[i]
    ans += B[k-1]
    if i < N-1:
        if A[i+1] == k+1 and k != N:
            ans += C[k-1]
        else:
            pass
    else:
        pass
print(ans)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
int c;
cin >>c;
int a1;
a1=c%10;
int a2;
a2=c/10;
if(a1==9){
cout << "Yes";
}
else if(a2==9){
cout <<"Yes";
}
else{
cout <<"No";
}
return 0;
}

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

B = [0] * 55
P = [0] * 55
P[0] = 1
for i in range(N):
    B[i + 1] = B[i] * 2 + 2
    P[i + 1] = P[i] * 2 + 1

def len(i):
    return B[i] + P[i]

def f(l, x):
    if l == 0:
        return 1
    if x == 1:
        return 0
    if x <= len(l - 1) + 1:
        return f(l - 1, x - 1)
    if x == len(l - 1) + 2:
        return P[l - 1] + 1
    if x <= len(l - 1) * 2 + 2:
        return P[l - 1] + f(l - 1, x - (len(l - 1) + 2)) + 1
    return P[l]

print(f(N, X))


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
const int N=10e5;
struct node{
	int a,b;
}s[N+7];
bool cmp(node x,node y){
	return  x.a<y.a;
}
int main(){
	int n;
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> s[i].a;
		s[i].b=i;
	}
	sort(s+1,s+1+n,cmp);
	for(int i=1;i<=n;i++)
		cout << s[i].b <<" ";
	
	return 0;
} 

Measured memory_bytes: 1536
class UnionFind(object):
    def __init__(self, size):
        self.parent = [i for i in range(size)]
        self.rank = [0 for _ in range(size)]


    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])


    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)
n, m = map(int, input().split())
U=UnionFind(n)
for i in range(m):
    x, y, z = map(int, input().split())
    U.unite(x-1, y-1)
cnt=0
for i in range(n):
    if U.find(i)==i:
        cnt+=1
print(cnt)

Measured memory_bytes: 7856
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
#define Endl endl
const int INF=100000000;
int main(){
	string s;
	cin>>s;
	cout<<((s[0]=='9'||s[1]=='9')?"Yes":"No")<<endl;
	return 0;
}

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

int main(){
	int n;
	cin >> n;
	while(n % 10 != 0 && n >1000){
		n = n-1111;
		}
	if(n % 111 == 0 || n % 1000 == 0 || (0 < n && n < 10)){
		cout << "Yes" << endl;
		}
	else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
def readInt():
    return list(map(int, input().split()))

ac = 0
wa = 0
tle = 0
re = 0
n = int(input())
for i in range(n):
    s = input()
    if s=='AC':
        ac += 1
    elif s=='WA':
        wa += 1
    elif s=='TLE':
        tle += 1
    else:
        re += 1
print('AC x {}'.format(ac))
print('WA x {}'.format(wa))
print('TLE x {}'.format(tle))
print('RE x {}'.format(re))

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

using namespace std;

#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    FOREACH(x, v) { cout << x << " "; }                                        \
    cout << "\n";

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, V, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

ll N;
map<ll, ll, greater<ll>> memo;

ll mypow(ll x, ll n) {
    ll res = 1;
    while(n > 0) {
        if(n & 1) res = res * x;
        x *= x;
        n >>= 1;
    }
    return res;
}

int main() {
    cin >> N;
    REP(i, N) memo[IN()]++;
    ll ans = 1, cnt = 0;
    FOREACH(m, memo) {
        if(m.second / 2) {
            ll tmp = min(2 - cnt, m.second / 2);
            ans *= mypow(m.first, tmp);
            cnt += tmp;
        }
        if(cnt >= 4) break;
    }
    if(ans==1) cout << 0 <<"\n";
    else cout << ans << "\n";
}

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

using namespace std;

int main(){
  int D,N; cin>>D>>N;
  int num=0,ans=0;
  num=pow(100,D);
  for(int i=0;i<N;i++){
    if((ans+num)%(num*100)!=0) ans+=num;
    else ans+=(2*num);
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, cnt = 0;
string s;
char c;
int main () {
	cin >> n >> s;
	for(int i = 0; i < n; i++) {
		if(c != s[i]) {
			cnt++;
			c = s[i];
		}
	}
	cout << cnt;
}

Measured memory_bytes: 512
using System;
namespace inonoa{
    class Ino{
        static void Main(){
            string[] x_y = Console.ReadLine().Split();
            long x = long.Parse(x_y[0]);
            long y = long.Parse(x_y[1]);

            long ans = 1;
            while(true){
                x *= 2;
                if(y<x){
                    Console.WriteLine(ans);
                    return;
                }
                ans ++;
            }
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <math.h>
#include <string>

using namespace std;

int main(){
	string s, t;
	cin >> s >> t;
	
	for(int i = 0; i < 100; ++i){
		for(int j = i + 1; j < 101; ++j){
			if(s.size() > j && s[i] > s[j]){
				char tmp = s[i];
				s[i] = s[j];
				s[j] = tmp;
			}

			if(t.size() > j && t[j] > t[i]){
				char tmp = t[i];
				t[i] = t[j];
				t[j] = tmp;
			}
		}
	}

	string ans = "";
	for(int i = 0; i < 101; ++i){
		if(s.size() <= i){
			if(s.size() == t.size()){
				ans = "No";
			} else {
				ans = "Yes";
			}
			break;
		} else if(t.size() <= i){
			ans = "No";
			break;
		}

		int s_num = (s[i] - 'a'), t_num = (t[i] - 'a');
		if(s_num == t_num){
			continue;
		} else if(s_num < t_num){
			ans = "Yes";
			break;
		} else if(s_num > t_num){
			ans = "No";
			break;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
import scala.io.{StdIn => in}

object Main extends App {
  val Array(h, w) = in.readLine.split(" ").map(_.toInt)
  val maze = Iterator.continually(in.readLine)
    .take(h)
    .map(_.map(ch => if(ch == '.') true else false).toArray)
    .toArray

  val white = maze.map(_.count(_ == true)).sum
  
  val res = {
    val Array(sy, sx, gy, gx) = Array(0, 0, h-1, w-1)
    val dx = Array( 0, 1, 0,-1)
    val dy = Array( 1, 0,-1, 0)
    val map = Array.ofDim[Int](h,w)
    val que = collection.mutable.Queue.empty[(Int,Int)]
    val s = (sy,sx)
    que += s
    maze(sy)(sx) = false

    while(!que.isEmpty) {
      val(y,x) = que.dequeue

      if(y == gy && x == gx) que.clear
      else {
        for(i <- 0 until 4) {
          val nx = x + dx(i)
          val ny = y + dy(i)
          if(0 <= nx && nx < w && 0 <= ny && ny < h && maze(ny)(nx)) {
            map(ny)(nx) = map(y)(x) + 1
            maze(ny)(nx) = false
            val next = (ny, nx)
            que += next
          }
        }
      }
    }
    // map.foreach(e => println(e.mkString))
    map(gy)(gx)
  }

  val ans = if(res == 0) -1 else white - res -1
  println(ans)
}

Measured memory_bytes: 27188
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define frw(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpii vector<pii>
#define vpiii vector<piii>
#define vpll vector<pll>
#define vplll vector<plll>
#define mo 1000000007
#define mems(a,x) memset(a,x,sizeof(a))
inline ll modpow(ll x,ll n){if(n==0)return 1;if(n==1)return(x%mo);ll u=(modpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll modinv(ll x){return modpow(x,mo-2);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return(((a-b)%mo+mo)%mo);}
inline ll mmul(ll a,ll b){    if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=modinv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
vector<ll>v[100005];


int main() {
	ll n,k;
	cin>>n>>k;
	vector<ll>v(n);
	for(int i=0;i<n;i++)
		cin>>v[i];
	ll ans=-1022222222;
	for(int i=0;i<n+1;i++)
		for(int j=0;j<n+1;j++)
		{
			if(i+j>n||i+j>k) continue;
			vector<ll>a;
			for(int l=0;l<i;l++)
				a.push_back(v[l]);
			for(int m=0;m<j;m++)
				a.push_back(v[n-1-m]);
			sort(a.begin(),a.end());
			ll sum=0;
			for(int l=0;l<a.size();l++)
			{
				if(a[l]<0&&l<k-i-j)
					continue;
				sum+=a[l];
				//cout<<a[l]<<" ";
			}
			//cout<<endl;
			ans=max(ans,sum);

		}
	cout<<ans;

}


Measured memory_bytes: 2560
def max(a,b); a > b ? a : b; end
def min(a,b); a < b ? a : b; end

def extract_cycle(s, used)
  cycle = []
  u = s
  until used[u]
    used[u] = true
    cycle << u  
    u = P[u]
  end
  return cycle
end

N, K = gets.split.map(&:to_i)
P = gets.split.map(&:to_i).tap{|array| array.unshift(0) }
C = gets.split.map(&:to_i).tap{|array| array.unshift(0) }

used = Array.new(N + 1)
ans = (1 .. N).inject(-1e20) do |max_score, s|
  next max_score if used[s]
  # sを始点とする閉路を抽出
  cycle = extract_cycle(s, used)
  z = cycle.size
  
  # 閉路の各頂点から最大2周分のスコアを計算できるように事前準備
  score = Array.new(3 * z + 1, 0)
  (1 .. z * 3).each do |i|
    v = cycle[i % z]
    score[i] = score[i - 1] + C[v]
  end

  # 閉路上の任意の点 s を始点としたときの最大スコアを計算
  
  sz = max(0, score[z])
  k = min(K, z + K % z)
  r = (K - k) / z

  cycle_score = (0 ... z).map{|s| r * sz + score[s + 1, k].max - score[s]}.max

  max(max_score, cycle_score)
end

puts ans


Measured memory_bytes: 15392
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;

int main(){
	int N,M,X;
	cin>>N>>M>>X;
	int A[100];
	rep(i,M)cin>>A[i];
	int up=0,down=0;
	rep(i,M){
		if(A[i]<X)up++;
		else down++;
	}
	cout<<min(up,down)<<endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int              { return readIntArray()[0] }
func readInt2() (int, int)      { a := readIntArray(); return a[0], a[1] }
func readInt3() (int, int, int) { a := readIntArray(); return a[0], a[1], a[2] }
func readIntArray() []int {
        a := make([]int, 0, 1000)
        sc.Scan()
        for _, v := range strings.Split(sc.Text(), " ") {
                vv, _ := strconv.Atoi(v)
                a = append(a, vv)
        }
        return a
}
func readString() string        { return readStringArray()[0] }
func readStringArray() []string { sc.Scan(); return strings.Split(sc.Text(), " ") }

func main() {
        a := readInt()
        b := readInt()

        fmt.Println(6 - a - b)
}

Measured memory_bytes: 640
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int i, j;
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int q = sc.nextInt();
			ArrayList<Deque<Integer>> array = new ArrayList<>();
			for(i = 0; i < n; i++) {
				array.add(new ArrayDeque<Integer>());
			}
			for(i = 0; i < q; i++) {
				int order_number = sc.nextInt();
				int t = sc.nextInt();
				if(array.get(t).isEmpty() && order_number != 0) {
					continue;
				}
				switch(order_number) {
				case 0 :
					array.get(t).add(sc.nextInt());
					break;
				case 1 :
					System.out.println(array.get(t).peekLast());
					
					break;
				case 2 :
					array.get(t).removeLast();
					break;
				}
//				for (Deque<Integer> output : array) {
//					System.out.print(output);
//				}
			}

		}
	}
}



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

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    int v = 0, c;
    for(int i=0;i<n;++i) {
        cin >> c;
        v |= c;
    }

    c = 0;
    for(;(v&1)==0;++c) v >>= 1;

    cout << c << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static int N=0;
	static long count=0L;
	static long max=0L;
	public static void main(String args[]) {
		try(Scanner sc = new Scanner(System.in)){
			N = Integer.parseInt(sc.next());
			Long a[] = new Long[N]; 
			for(int i=0;i<N;i++) {
				a[i] = Long.parseLong(sc.next());
			}
			for(int i=0;i<N;i++) {
				if(max<a[i]) {
					max = a[i];
				} else {
					count += max-a[i];
				}
				
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 66044