akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

const int MAX_N = 100010;
int s[MAX_N] = {0};

int main(){
	int n;
	cin >> n;
	for(int i=0 ; i < n ; i++ ){
		int a, b;
		cin >> a >> b;
		s[a]++, s[b+1]--;
	}
	
	for(int i=1 ; i < MAX_N ; i++ ){
		s[i] += s[i-1];
	}
	int ans = 1;
	for(int i=1 ; i < MAX_N ; i++ ){
		if( i-1 <= s[i] ) ans = i;
	}
	ans--;
	cout << ans << endl;
}

Measured memory_bytes: 1552
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int A,B; cin>>A>>B;
  char ans='x';
  if(A+B==15)
    ans='+';
  if(A*B==15)
    ans='*';
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

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

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

const mod = 1000000007

func mpow(a, b int) int {
	if b == 0 {
		return 1
	} else if b%2 == 0 {
		tmp := mpow(a, b/2)
		return tmp * tmp % mod
	}
	return mpow(a, b-1) * a % mod
}

var fracMemo = []int{1, 1}

func mfrac(n int) int {
	if len(fracMemo) > n {
		return fracMemo[n]
	}
	if len(fracMemo) == 0 {
		fracMemo = append(fracMemo, 1)
	}
	for len(fracMemo) <= n {
		size := len(fracMemo)
		fracMemo = append(fracMemo, fracMemo[size-1]*size%mod)
	}
	return fracMemo[n]
}

var ifracMemo = []int{1, 1}

func mifrac(n int) int {
	if len(ifracMemo) > n {
		return ifracMemo[n]
	}
	if len(ifracMemo) == 0 {
		fracMemo = append(ifracMemo, 1)
	}
	for len(ifracMemo) <= n {
		size := len(ifracMemo)
		ifracMemo = append(ifracMemo, ifracMemo[size-1]*mpow(size, mod-2)%mod)
	}
	return ifracMemo[n]
}

func nCr(n, r int) int {
	if n == r {
		return 1
	}
	if n < r || r < 0 {
		return 0
	}
	ret := 1
	ret *= mfrac(n)
	ret %= mod
	ret *= mifrac(r)
	ret %= mod
	ret *= mifrac(n - r)
	ret %= mod
	return (ret)
}

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

type pair struct {
	f, s int
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()

	zero := 0
	m := make(map[pair]pair)
	for i := 0; i < N; i++ {
		a, b := getInt(), getInt()
		if a == 0 && b == 0 {
			zero++
			continue
		}
		g := gcd(abs(a), abs(b))
		a /= g
		b /= g
		rotate := 0
		for !(a >= 0 && b > 0) {
			a, b = -b, a
			rotate++
		}
		x := m[pair{a, b}]
		if rotate%2 == 0 {
			x.f++
		} else {
			x.s++
		}
		m[pair{a, b}] = x
	}

	// out(zero)
	// for i, v := range m {
	// 	out(i, v)
	// }
	// out(m)
	ans := 1
	for _, v := range m {
		x := 1
		x += mpow(2, v.f)
		x %= mod
		// out(v)
		x--
		if x < 0 {
			x += mod
		}
		x += mpow(2, v.s)
		x %= mod
		x--
		if x < 0 {
			x += mod
		}
		x %= mod
		// out(v, x)
		// out(x)
		ans *= x
		ans %= mod
	}
	ans += zero
	ans %= mod
	ans -= 1
	if ans < 0 {
		ans += mod
	}
	ans %= mod
	out(ans)
}


Measured memory_bytes: 24480
import java.util.Scanner;

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

        int H, W;
        H = sc.nextInt();
        W = sc.nextInt();

        if(H == 0 && W == 0)
            return;

        while(H != 0 || W != 0){
            for(int i = 0; i < H; i++){
                for(int j = 0; j < W; j++){
                    if(i % 2 == j % 2 )
                        System.out.print("#");
                    else
                        System.out.print(".");
                }
                System.out.println("");
            }
            System.out.println("");

            H = sc.nextInt();
            W = sc.nextInt();
        }

    }
}



Measured memory_bytes: 33288
A, B, C, D = map(int, input().split())

def diff(x, y):
    time = x - y
    return time

if A < C:
    t = diff(B, C)
    if C > B:
        t = 0
    elif D < B:
        t = diff(D, C)
else:
    t = diff(D, A)
    if A > D:
        t = 0
    elif B < D:
        t = diff(B, A)

print(t)
    

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

#define FOR( i, m, n )   for( int i = m; i < n; i++ )
#define REP( i, n )      FOR( i, 0, n )
#define ALL( a )         (a).begin(), (a).end()

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

int main(){
  int x, y; cin >> x >> y;

  if( x < y ) swap( x, y );
  cout << x + y - gcd( x, y ) + 1 << endl; 
}



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

#define ll long long

using namespace std;

const ll inf = 1e9;
const ll mod = 1e9 + 7;

const int MAXN = 1e5 + 100;

ll fact[MAXN];
ll inv[MAXN];

ll bpow(ll a, ll n) {
    ll res = 1;
    while (n) {
        if (n & 1)
            res = (res * a) % mod;
        a = (a * a) % mod;
        n >>= 1;
    }
    return res;
}

void precalc() {
    fact[0] = fact[1] = 1;
    inv[0] = inv[1] = 1;
    for (ll i = 2; i < MAXN; ++i) {
        fact[i] = (fact[i - 1] * i) % mod;
        inv[i] = bpow(fact[i], mod - 2);
    }
}

ll C(ll n, ll k) {
    if (n < k)
        return 0;
    return (((fact[n] * inv[n - k]) % mod) * inv[k]) % mod;
}


int main() {
#ifdef __APPLE__
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    
    precalc();

    int n;
    scanf("%d", &n);
    vector<ll> a(n + 1);
    vector<ll> cnt(n + 1);
    ll v = -1;
    for (int i = 0; i <= n; ++i) {
        scanf("%lld", &a[i]);
        if (cnt[a[i]])
            v = a[i];
        ++cnt[a[i]];
    }
    ll p1 = -1, p2 = -1;
    for (int i = 0; i <= n; ++i) {
        if (a[i] == v) {
            if (p1 == -1)
                p1 = i;
            else
                p2 = i;
        }
    }
    ll s1 = p1, s2 = n - p2;
    for (ll i = 1; i <= (n + 1); ++i) {
        ll cur = C(n + 1, i);
        ll t = C(s1 + s2, i - 1);
        cur -= t;
        cur = (cur % mod + mod) % mod;
        printf("%lld\n", cur);
    }

    return 0;
}


Measured memory_bytes: 4352
n = int(input())
lis = list(map(int,input().split()))
dp = [10**10 for i in range(n+3)]
dp[0] = 0
for i in range(n-1):
  dp[i+1] = min(dp[i+1],dp[i] + abs(lis[i+1]-lis[i]))
  if i != n-2:
    dp[i+2] = min(dp[i+2],dp[i] + abs(lis[i+2]-lis[i]))
print(dp[n-1])


Measured memory_bytes: 13976
/*author: hyperion_1724
  date: 
*/

//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work
bool isprime(ll z)
{
    for (ll i = 2; i*i <= z; i++)
    {
        if (z%i==0)
        {
            return false;
        }
        
    }
    return true;
}

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

   
//-----------------------------------------------------------------------------------------------------------//

    READV(X);
    while (!isprime(X))
    {
        X++;
    }
    cout<<X<<endl;
    

//-----------------------------------------------------------------------------------------------------------//


   
    return 0;
}

Measured memory_bytes: 256
//******* It's LEVI_17 ***************

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define ff first
#define ss second
#define MP make_pair
#define mset(x,a) memset(x,a,sizeof(x))
#define max3(x,y,z) max(x,max(y,z))
#define min3(x,y,z) min(x,min(y,z))
#define sqr(a) (a)*(a)
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
#define f1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define vvll vector<vector<ll>>  
#define vll vector<ll> 
#define pll pair<ll,ll>
#define vpll vector<pll>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define cases ll t;cin >> t;while(t--)
#define rr return 0
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define deb(a)			std::cerr<<#a<<"="<<(a)<<"\n"
#define deb2(a,b)		std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define deb3(a,b,c)		std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
const int MOD = 1000 * 1000 * 1000 + 7;

//syntax for priority queue
// max queue -> priority_queue<ll>
// min queue -> priority_queue<ll,vector<ll>,greater<ll>>

//##############################################################################################

ll getRes(char grid[1001][1001],ll n,ll m)
{
    vvll dp(n + 1, vll(m + 1, 0));
    // dp[i][j] represents number of ways to reach cell [i][j] in grid.
    dp[0][0] = 1;
    for (ll i = 0; i < n; i++)
    {
        for (ll j = 0; j < m; j++)
        {

            if (i == 0 && j == 0)
                dp[i][j] = 1;
            if (grid[i][j] == '.')
            {
                if (i > 0 && grid[i - 1][j] != '#')
                    (dp[i][j] += dp[i - 1][j]%MOD) %= MOD;
                if (j > 0 && grid[i][j - 1] != '#')
                    (dp[i][j] += dp[i][j - 1] % MOD) %= MOD;
            }
        }
    }

    return dp[n - 1][m - 1] % MOD;
}

void solve()
{
    ll n, m;
    cin >> n >> m;
    char grid[1001][1001];
    f(i, n)
        f(j, m)
        cin >> grid[i][j];

    ll res = getRes(grid, n, m);

    cout << res % MOD << "\n";
}

//###############################################################################################

int main()
{
    fast;
    ll t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    rr;
}


//Watashi wa tsuyoku modotte kimasu

Measured memory_bytes: 12000
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;

char s[1000][1010];
int h,w,co[1000][1000],ans,visited[1000][1000];
queue<int> q;

void bfs(int x,int y){
    q.pop();
    ans=max(ans,co[x][y]);
    visited[x][y]=1;
    if(x>0&&co[x-1][y]>co[x][y]+1){
        co[x-1][y]=co[x][y]+1;
        q.push((x-1)*1000+y);
    }
    if(x<h-1&&co[x+1][y]>co[x][y]+1){
        co[x+1][y]=co[x][y]+1;
        q.push((x+1)*1000+y);
    }
    if(y>0&&co[x][y-1]>co[x][y]+1){
        co[x][y-1]=co[x][y]+1;
        q.push((x)*1000+y-1);
    }
    if(y<w-1&&co[x][y+1]>co[x][y]+1){
        co[x][y+1]=co[x][y]+1;
        q.push((x)*1000+y+1);
    }
}

int main(){
    scanf("%d %d",&h,&w);
    for(int i=0;i<h;i++){
        scanf("%s",s[i]);
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='.'){
                co[i][j]=10000000;
            }
            else{
                co[i][j]=0;
                q.push(i*1000+j);
            }
        }
    }
    while(!q.empty()){
        if(visited[q.front()/1000][q.front()%1000]==1){
            q.pop();
        }
        else{
            bfs(q.front()/1000,q.front()%1000);
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 13184
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#define int long long
using namespace std;
int test[213456], kai[123456];
signed main() {
	int n, r, g, b, ans = 0; string s; cin >> r >> g >> b >> n;
	for (int h = 0; h <= n / r; h++) {
		for (int i = 0; i <= n / g; i++) {
			if (h * r + g * i <= n && (n - (h * r + g * i)) % b == 0) {
				ans++;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int N;cin>>N;
  vector<int> B(N-1);
  for (int i=0;i<N-1;++i){
    cin>>B[i];
  }
  int ans=0;
  ans+=B[0];
  ans+=B[N-2];
  for (int i=0;i<N-2;++i){
    ans+=min(B[i],B[i+1]);
  }  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
def main():
    b = input()
    # a, b = [int(q) for q in input().split()]
    # print(2)
    if b == "A":
        print("T")
    if b == "T":
        print("A")
    if b == "C":
        print("G")
    if b == "G":
        print("C")


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define test int t; cin>>t; while(t--)
ll a[12]={0};
ll valid(ll x)
{

    while(x)
    {
        ll r=x%10;
        if(a[r]==1)
        {
            return 0;
        }
        x/=10;
    }
    return 1;
}
int main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);cout.tie(0);

   ll c,d,i,j,k;
   cin>>c>>d;
   for(i=0;i<d;i++)
   {
       cin>>j;
       a[j]=1;
   }
   for(i=c; ;i++)
   {
       if(valid(i))
       {
           cout<<i<<endl;
           return 0;
       }
   }

   return 0;
}


Measured memory_bytes: 3548
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std ;

int N , f[100005] ;

int main(){
	scanf( "%d" , &N ) ;
	for( int i = 1 ; i <= N ; i ++ ){
		f[i] = i ;
		for( int j = 6 ; j <= i ; j *= 6 )
			f[i] = min( f[i] , f[i-j] + 1 ) ;
		for( int j = 9 ; j <= i ; j *= 9 )
			f[i] = min( f[i] , f[i-j] + 1 ) ;
	} printf( "%d" , f[N] ) ;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

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


Measured memory_bytes: 256
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.arrayIteratorImpl=function(a){var b=0;return function(){return b<a.length?{done:!1,value:a[b++]}:{done:!0}}};$jscomp.arrayIterator=function(a){return{next:$jscomp.arrayIteratorImpl(a)}};$jscomp.makeIterator=function(a){var b="undefined"!=typeof Symbol&&Symbol.iterator&&a[Symbol.iterator];return b?b.call(a):$jscomp.arrayIterator(a)};
function main(a){var b=$jscomp.makeIterator(a.split(" "));a=b.next().value;b=b.next().value;a=parseInt(a);b=parseInt(b);return 0==(a+b)%2?console.log((a+b)/2):console.log("IMPOSSIBLE")}main(require("fs").readFileSync("/dev/stdin","utf8"));


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

#define rep(i,n) for(ll i = 0;i < n; i++)

typedef long long ll;

int main(){
    ll N,ans = 1;
    cin >> N;
    string S;
    cin >> S;
    
    ll cnt[26];
    rep(i,26) cnt[i] = 1;
    rep(i,N) cnt[S[i] - 'a']++;
    rep(i,26){
        ans *= cnt[i];
        ans%=1000000007;
    }
    cout << ans - 1 << endl;
}


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


acc=0
waa=0
tlee=0
ree=0

for i in range(N):
    t=input()
    if t=='AC':
        acc+=1
    elif t=='WA':
        waa+=1
    elif t=='TLE':
        tlee+=1
    else:
        ree+=1


print('AC x '+str(acc))
print('WA x '+str(waa))
print('TLE x '+str(tlee))
print('RE x '+str(ree))

Measured memory_bytes: 9204
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <numeric>

/* debug macros */
#ifdef WAFDAYO
#define DBG_LINE() {std::cerr<<"\e[2m[L"<<__LINE__<<"]\e[m ";}
#define DBG_PRINT(s,t,u) {std::cerr<<(s)<<" \e[2m=\e[m \e[1m"<<(t)<<"\e[m"<<(u);}
#define SELECT_7TH(x1,x2,x3,x4,x5,x6,x7,...) x7
#define dbg1(x1) DBG_PRINT(#x1,x1,std::endl)
#define dbg2(x1,x2) DBG_PRINT(#x1,x1,", ")dbg1(x2)
#define dbg3(x1,x2,x3) DBG_PRINT(#x1,x1,", ")dbg2(x2,x3)
#define dbg4(x1,x2,x3,x4) DBG_PRINT(#x1,x1,", ")dbg3(x2,x3,x4)
#define dbg5(x1,x2,x3,x4,x5) DBG_PRINT(#x1,x1,", ")dbg4(x2,x3,x4,x5)
#define dbg6(x1,x2,x3,x4,x5,x6) DBG_PRINT(#x1,x1,", ")dbg5(x2,x3,x4,x5,x6)
#define dbg(...) DBG_LINE()\
SELECT_7TH(__VA_ARGS__,dbg6,dbg5,dbg4,dbg3,dbg2,dbg1)(__VA_ARGS__)
#else
#define dbg(...) {}
#endif

/* utility functions */
struct read_item{read_item(){};
template<class T>operator T(){T t;std::cin>>t;return t;}};
char splf(int i,int n){return(i+1<n)?' ':'\n';};
template<bool up>
struct _RI{int i;_RI(int a):i(a){}
int operator*(){return i;}void operator++(){i+=(up?1:-1);}
bool operator!=(const _RI& r){return up?i<r.i:i>=r.i;}};
template<bool up>
struct _RX{_RI<up> x,y;_RI<up> begin(){return x;}_RI<up> end(){return y;}
_RX(int a,int b):x(up?a:(a-1)),y(b){}_RX(int a):_RX(up?0:a,up?a:0){}};
typedef _RX<true> range;
typedef _RX<false> revrange;

/* types and constants */
typedef int64_t i64;
typedef uint64_t u64;
const i64 inf = (i64)1.05e18;
// const int inf = (int)1.05e9;

using namespace std;

int main() {

	const int N = read_item();
	vector<int> A(N);
	for(auto i : range(N)) {
		A[i] = read_item();
	}
	vector<pair<int,int>> sorted(N);
	for(auto i : range(N)) {
		sorted[i] = {A[i], i};
	}
	sort(sorted.rbegin(), sorted.rend());

	vector<vector<i64>> dp(N + 1);
	for(auto& d : dp) {
		d.resize(N + 1, -inf);
	}
	dp[0][0] = 0;

	for(auto i : range(N)) {
		for(auto j : range(N)) {

			auto& a = dp[i + 1][j];
			const i64 v = sorted[i].first;
			const int pos = sorted[i].second;

			const int left = j - 1;
			const int right = N - (i + 1 - j);

			if(left >= 0) {
				const i64 b = dp[i][j - 1] + abs(pos - left) * v;
				a = max(a, b);
			}
			if(right < N) {
				const i64 b = dp[i][j] + abs(pos - right) * v;
				a = max(a, b);
			}
		}
	}

	i64 ans = dp[N][0];
	for(auto i : range(N + 1)) {
		ans = max(ans, dp[N][i]);
	}
	printf("%lld\n", ans);

	return 0;
}

/* wafdayo~~~ */


Measured memory_bytes: 35092
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
p = []
for i in a:
    for j in b:
        p.append(i+j)
p.sort(reverse=True)
p = p[:min(3001, x*y*z+1)]
q = []
for j in c:
    for i in p:
        q.append(i+j)
q.sort(reverse=True)
for i in range(k):
    print(q[i])

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

const ll mod = 1000000007;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

struct combination {
    vector<mint> fact, ifact;
    // init struct with "n" of "nCk" (maximum number in other words)
    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }
    // c(n,k) returns mint that contains nCk (mod p (= 1e9+7)) in x
    // i.e.) mint num = c(n,k), then num.x == nCk (mod p (= 1e9+7))
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
};

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

int main() {
    ll k;
    string s;
    cin >> k >> s;
    ll n = s.size();
    combination nck(n + k);

    mint ans(0);
    for (ll l = n; l <= n + k; l++) {
        ans += nck(l - 1, n - 1) * modpow(25, l - n) * modpow(26, n + k - l);
    }
    cout << ans.x << endl;
}

Measured memory_bytes: 35648
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a;
  cin >> a;
  if(count(a.begin(),a.end(),'R') == 3)
    cout << 3;
  else if(count(a.begin(),a.end(),'R') == 0)
    cout << 0;
  else if(count(a.begin(),a.end(),'R') == 2 && a.at(1)== 'R')
     cout << 2;
  else
    cout << 1;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=100005;
int n,m,a[N],s[N],v[N],k,ans,l,r,sz;
signed main()
{
	cin>>n>>a[1]>>m;
	s[1]=a[1];
	for(k=2;;k++)
	{
		a[k]=a[k-1]*a[k-1]%m;
		if(v[a[k]])
		{
			l=v[a[k]];
			r=k-1;
			sz=r-l+1;
			break;
		}
		s[k]=s[k-1]+a[k];
		v[a[k]]=k;
	}
	if(n<=l)
	{
		cout<<s[n]<<endl;
		return 0;
	}
	ans+=s[l-1];
	n-=l-1;
	ans+=n/sz*(s[r]-s[l-1]);
	ans+=s[l+n%sz-1]-s[l-1];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5208
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
    int n, k,mins=1000000000;
    cin >> n >> k;
    vector<int>h(n);
    rep(i, n)cin >> h[i];
    sort(all(h));
    rep(i, n - k+1) {
        mins = min(mins, abs(h[k-1+i] - h[i]));
        //mins = min(mins, abs(h[k] - h[k-i]));
    }
    cout << mins << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int v[100009][3];
int dp[100009][3];
int n;
int vacation(int i, int j)
{
    if(i==n-1)
        return dp[i][j]=v[i][j];
    if(i>=n || j>=3)
        return 0;
    if(dp[i][j]!=-1)
        return dp[i][j];
    int temp = INT_MIN;
        if(j==0)
        {
             temp = max(vacation(i+1,j+1)+v[i][j],temp);
        temp = max(vacation(i+1,j+2)+v[i][j],temp);
 return dp[i][j]= temp;
        }
      else  if(j==1)
        {
             temp = max(vacation(i+1,0)+v[i][j],temp);
        temp = max(vacation(i+1,2)+v[i][j],temp);
 return dp[i][j]= temp;
        }
        else
        {
             temp = max(vacation(i+1,1)+v[i][j],temp);
        temp = max(vacation(i+1,0)+v[i][j],temp);
         return dp[i][j]= temp;
        }
}

int main()
{
    cin>>n;
    memset(dp,-1,sizeof(dp));
    for(int i=0; i<n; i++)
        cin>>v[i][0]>>v[i][1]>>v[i][2];
    cout<<max(vacation(0,0),max(vacation(0,1),vacation(0,2)))<<endl;
}

Measured memory_bytes: 10604
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807

using namespace std;

long long GCD(long long a, long long b) {
	if (a < b)
		swap(a, b);
	if (b == 0) return a;
	else return GCD(b, a % b);
}
bool sosuu_check(int num) {
	int i;
	for (i = 2; i <= sqrt(num); ++i) {
		if (num%i == 0)
			return false;
	}
	return (num < 2) ? false : true;
}
int main() {
	int W, H, pi, i, j, MAX;
	vector<string> vec(52);
	string test;
	ll ans = 0;
	cin >> H >> W;
	REP(i, W + 2) {
		vec[0].append(".");
		vec[H + 1].append(".");
	}
	FOR(i, 1, H + 1) {
		vec[i] = ".";
		cin >> test;
		vec[i].append(test);
		vec[i].append(".");
	}
	FOR(i,1, H + 1)
		FOR(j, 1, W + 1) {
		if (vec[i][j] == '#' &&vec[i][j - 1] != '#' && vec[i][j + 1] != '#' && vec[i - 1][j] != '#' && vec[i + 1][j] != '#') {
			cout << "No" << endl;
			return 0;
		}

	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    ans = 0
    right = 0
    s = 0

    for left in range(N):
        while right < N and s & A[right] == 0:
            s ^= A[right]
            right += 1

        ans += right - left

        if left == right:
            right += 1
        else:
            s ^= A[left]

    print(ans)
    return


if __name__ == '__main__':
    main()


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

  int main() {
    int N; cin >> N;    // 青いカードの枚数
    vector<string> S(N);  // 青いカードの中身
    rep(i,N){cin >> S.at(i);}
    int M; cin >> M;    // 赤いカードの枚数
    vector<string> T(M);  // 青いカードの中身
    rep(i,M){cin >> T.at(i);}

    vector<int> ten(N); // 青いカード毎の点数
    int max = 0;  // 最大値

    rep(i,N){
      rep(j,N){ // 青いカードを全部見て、同じなら＋１
        if (S.at(i) == S.at(j)) { ten.at(i) +=1;}
      }
      rep(j,M){ // 青いカードを全部見て、同じなら＋１
        if (S.at(i) == T.at(j)) { ten.at(i) -=1;}
      }

      // 最大値の保管
      // cout << "ten:" << ten.at(i) << endl;
      if ( ten.at(i) > max ) { max = ten.at(i); }
    }
    cout << max << endl;
  }

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int n;
long long a,b,h[100005],ans,cnt;
int main()
{
	cin>>n>>a>>b;
	a-=b;
 	for (int i=0;i<n;i++)
  		cin>>h[i];
    long long low=1,high=1000000000,mid;
    while (low!=high)
    {
    	mid=(low+high)/2;
     	ans=0;
    	for (int i=0;i<n;i++)
    	{
    		cnt=b*mid;
    		if (cnt<h[i])
    			ans+=((h[i]-cnt-1)/a)+1;
    	}
    	if (ans<=mid) high=mid;
    	else low=mid+1;
    }
    cout<<low;
    return 0;
}

Measured memory_bytes: 1024
function main() {
  var
  i = 0, j, y, x,
  xy, cells, answers = {},
  dummy = [2,2,2,2,2,2,2,2,2,2,2,2,2,2,2];
  for (;;) {
    xy = input[i++].split(' ').map(parseFloat);
    cells = [];
    if (xy[0] === 0 && xy[1] === 0) break;
    
    for (j = 0; j < xy[1]; j++) {
      cells.push(input[i++].split(' ').map(parseFloat));
    }
    cells.push(dummy);
    
    answer = 0;
    answers = {};
    for (x = 0; x < xy[0]; x++) answers[[x, 0]] = cells[0][x] === 0 ? 1 : 0;
    for (y = 0; y < xy[1]; y++) {
      for (x = 0; x < xy[0]; x++) {
        answers[[x, y]] = answers[[x, y]] || 0;
        switch (cells[y][x]) {
        case 0:
          if (cells[y + 1][x - 1] !== 2) answers[[x - 1, y + 1]] = (answers[[x - 1, y + 1]] || 0) + answers[[x, y]];
          answers[[x, y + 1]] = (answers[[x, y + 1]] || 0) + answers[[x, y]];
          if (cells[y + 1][x + 1] !== 2) answers[[x + 1, y + 1]] = (answers[[x + 1, y + 1]] || 0) + answers[[x, y]];
          break;
        case 1:
          break;
        case 2:
          answers[[x, y + 2]] = (answers[[x, y + 2]] || 0) + answers[[x, y]];
          break;
        }
      }
    }

//    show(xy, answers);

    for (y = xy[1]; y <= xy[1] + 1; y++) {
      for(x = 0; x < xy[0]; x++) {
        answer += answers[[x, y]] || 0;
      }
    }

    console.log(answer);
  }
}


function show(xy, answers) {
  var
  x, y, line;
  for (y = 0; y <= xy[1]; y++) {
    line = [];
    for (x = 0; x < xy[0]; x++) {
      line.push(answers[[x, y]] || 0);
    }
    console.log(line.join(' '));
  }
}


var
input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});

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

int main() {
	int n,k;
    cin >> n >> k;
    if(n%2==1){
      n++;
    }
    if(n/2>=k){
      cout << "YES" << endl;
    }
    else{
      cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
def dfs(visted, graph, cur, count):
    n = len(visited)

    allNodeVisited = True
    for i in range(1, n):
        if visited[i] is False:
            allNodeVisited = False
            break

    if allNodeVisited:
        count += 1
        return count

    for i in range(1, n):
        if cur != i and visited[i] is False and graph[cur][i] == 1:
            visited[i] = True
            count = dfs(visited, graph, i, count)
            visited[i] = False

    return count


n, m = map(int, input().split())
visited = [False] * (n + 1)

graph = [[0 for _ in range(n + 1)] for _ in range(n + 1)]
for i in range(m):
    frm, to = map(int, input().split())
    graph[frm][to] = graph[to][frm] = 1


count = 0
visited[1] = True
count = dfs(visited, graph, 1, count)

print(count)


Measured memory_bytes: 3064
/*
      author  : nishi5451
      created : 12.08.2020 23:10:24
*/

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

ll mod = 1000000007;

ll m_factorial(ll n){
    ll res = 1;
    for(int i=1; i<=n; i++)
        res = (res*i)%mod;
    return res;
}

int main(){
    ll n;
    cin >> n;
    cout << m_factorial(n) << endl;
    return 0;
}

Measured memory_bytes: 3588
#include<iostream>
#include<set>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long li;
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define yn(i) print((i)?"Yes":"No")
#define rep(i,n) for(int i=0;i<(n);i++)

#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// pair 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const pair<T,S>& p){
  cout << "(" << p.first << "," << p.second << ")";
  return os;
}

// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}
// map 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const map<S,T>& mp){
  for(const pair<S,T>& x: mp){
    cout << "[" << x.first << "]=" << x.second << " ";
  }
  return os;
}

int main(){
  int n; cin >>n;
  vector<li> a(n);
  rep(i,n) cin >>a[i];
  map<li,int> dict;
  rep(i,n){
    dict[a[i]]++;
  }
  int i=0;
  for(auto& x:dict){
    x.second=i++;
    if(df)print(x);
  }
  if(df) print(dict);
  rep(i,n){
    a[i]=dict[a[i]];
  }
  if(df)print(a);
  int f=0,cnt=0;
  rep(i,n){
    if(df)print(a[i],f);
    if((a[i]^f)&1) cnt++;
    f^=1;
  }
  print(cnt/2);
}





Measured memory_bytes: 10360
import sys
input = sys.stdin.readline
A = [input().split() for i in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]

Bingo = [[0,0,0],[0,0,0],[0,0,0]]

for i in range(3) :
    for j in range(3) :
        if int(A[i][j]) in b :
            Bingo[i][j] = 1

if Bingo[0][0] == 1 and Bingo[0][1] == 1 and Bingo[0][2] ==1 :
    ans = "Yes"
elif Bingo[1][0] == 1 and Bingo[1][1] == 1 and Bingo[1][2] ==1 :
    ans = "Yes"
elif Bingo[2][0] == 1 and Bingo[2][1] == 1 and Bingo[2][2] ==1 :
    ans = "Yes"
elif Bingo[0][0] == 1 and Bingo[1][0] == 1 and Bingo[2][0] ==1 :
    ans = "Yes"
elif Bingo[0][1] == 1 and Bingo[1][1] == 1 and Bingo[2][1] ==1 :
    ans = "Yes"
elif Bingo[0][2] == 1 and Bingo[1][2] == 1 and Bingo[2][2] ==1 :
    ans = "Yes"
elif Bingo[0][0] == 1 and Bingo[1][1] == 1 and Bingo[2][2] ==1 :
    ans = "Yes"
elif Bingo[0][2] == 1 and Bingo[1][1] == 1 and Bingo[2][0] ==1 :
    ans = "Yes"
else :
    ans = "No"

print(ans)


Measured memory_bytes: 3188
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1


W, H, x, y = map(int, input().split())
area = (W * H) / 2
bl = (x * 2 == W and y * 2 == H)
ans = 1 if bl else 0

print('{:.6f} {}'.format(area, ans))




Measured memory_bytes: 3572
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <iostream>

using namespace std;

typedef long long ll;

const ll MAX_N = 1E+11;

ll N, S;

ll solve(ll n, ll s);
bool f(ll b, ll n, ll s);

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

    cin >> N >> S;

    cout << solve(N, S) << "\n";

    return 0;
}

ll solve(ll n, ll s)
{
    if (n == s) {
        return n + 1;
    } else {
        ll b = 2;
        for (; b * b <= n; b++) {
            if (f(b, n, s)) {
                return b;
            }
        }
        ll p;
        if (n == b * b) {
            p = b - 1;
        } else {
            p = b;
        }
        for (; p >= 1; p--) {
            b = (n - s + p) / p;
            if (b >= 2 && f(b, n, s)) {
                return b;
            }
        }
    }
    return -1;
}

bool f(ll b, ll n, ll s)
{
    ll sc = 0;
    while (n >= 1) {
        ll p = n / b;
        sc += n - p * b;
        n = p;
    }
    return (s == sc);
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define INF (1<<30)
#define LINF (1LL <<60)

int dy[8] = { 0,1,1,1,0,-1,-1,-1 };
int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
vector<vector<char>> masu(10, vector<char>(10, '.'));

int get_cookie(int h, int w, int dicy, int dicx, char c) {
	int ret = 0;
	for (int i = 0;;i++) {
		char C = masu[h + dicy*i][w + dicx*i];
		if (C == c) {
			ret++;
		}
		else if (C == '.') {
			return 0;
		}
		else {
			return ret;
		}
	}
}

void set_cookie(int h, int w, int dicy, int dicx, char c1,char c2) {
	for (int i = 0;;i++) {
		char C = masu[h + dicy*i][w + dicx*i];
		if (C == c1) {
			continue;
		}
		else if (C == '.') {
			return ;
		}
		else {
			for (int j = 0; j <= i;j++) {
				masu[h + dicy*j][w + dicx*j] = c2;
			}
			return ;
		}
	}
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	for (int i = 1; i <= 8;i++)for (int j = 1; j <= 8;j++) cin >> masu[i][j];

	bool f = true;
	while (f) {
		f = false;
		int mami[10][10] = { 0 };
		int mami_max = 0;
		for (int r = 0; r < 2; r++) {
			for (int i = 1; i <= 8;i++) {
				for (int j = 1; j <= 8;j++) {
					if (masu[i][j] != '.')continue;
					int Sum = 0;
					for (int k = 0; k < 8;k++) {
						if (masu[i + dy[k]][j + dx[k]] != 'x')continue;
						if (r == 0) {
							Sum += get_cookie(i + dy[k], j + dx[k], dy[k], dx[k], 'x');
						}
						else if (mami[i][j] == mami_max) {
							if (masu[i][j] != 'o') masu[i][j] = 'o';
							set_cookie(i + dy[k], j + dx[k], dy[k], dx[k], 'x', 'o');
						}
					}
					if (r == 0) {
						mami[i][j] = Sum;
						mami_max = max(mami[i][j], mami_max);
					}
					else if (mami[i][j] == mami_max) {
						f = true;
						r = 2; i = 9; j = 9;
					}
				}
			}
			if (mami_max == 0) break;
		}

		int majo[10][10] = { 0 };
		int majo_max = 0;
		for (int r = 0; r < 2; r++) {
			for (int i = 8; i >= 1;i--) {
				for (int j = 8; j >= 1;j--) {
					if (masu[i][j] != '.')continue;
					int Sum = 0;
					for (int k = 0; k < 8;k++) {
						if (masu[i + dy[k]][j + dx[k]] != 'o')continue;
						if (r == 0) {
							Sum += get_cookie(i + dy[k], j + dx[k], dy[k], dx[k], 'o');
						}
						else if (majo_max == majo[i][j]) {
							if (masu[i][j] != 'x') masu[i][j] = 'x';
							set_cookie(i + dy[k], j + dx[k], dy[k], dx[k], 'o', 'x');
						}
					}
					if (r == 0) {
						majo[i][j] = Sum;
						majo_max = max(majo[i][j], majo_max);
					}
					else if (majo_max == majo[i][j]) {
						f = true;
						r = 2; i = 0; j = 0;
					}
				}
			}
			if (majo_max == 0)break;
		}
	}

	for (int i = 1; i <= 8;i++) {
		for (int j = 1; j <= 8;j++) {
			cout << masu[i][j];
		}
		cout << endl;
	}
}

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

int main() {
  int x;
  cin>>x;
  int a=x/100;
  int b=x/105;
  bool d=false;
  for(int i=b;i<a+1;i++){
    int c=x-100*i;
    if(c<=5*i){
      d=true;
    }
  }
  if(d){
    cout<<1<<endl;
  }
  else{
    cout<<0<<endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  char s[8][10];
  int i, j, k, l;
  int dx[7][3] = {
    {1, 1, 0},
    {0, 0, 0},
    {1, 2, 3},
    {0, -1, -1},
    {1, 1, 2},
    {0, 1, 1},
    {1, -1, 0}
  }, dy[7][3] = {
    {0, 1, 1},
    {1, 2, 3},
    {0, 0, 0},
    {1, 1, 2},
    {0, 1, 1},
    {1, 1, 2},
    {0, 1, 1}
  };
  while(scanf("%s", s[0]) != EOF) {
    for(i = 1; i < 8; ++i) scanf("%s", s[i]);
    int t = 1;
    for(i = 0; i < 8; ++i) {
      for(j = 0; j < 8; ++j) {
        if(s[i][j] == '1') {
          for(k = 0; k < 7; ++k) {
            for(l = 0; l < 3; ++l) {
              if(i + dy[k][l] < 0 || i + dy[k][l] >= 8 || j + dx[k][l] < 0 || j + dx[k][l] >= 8 || s[i + dy[k][l]][j + dx[k][l]] == '0') break;
            }
            if(l == 3) {
              printf("%c\n", 'A' + k);
              break;
            }
          }
          t = 0;
          break;
        }
      }
      if(!t) break;
    }
  }
  return 0;
}


Measured memory_bytes: 2740
S = input()

def judge(S):
    for i in range(len(S)//2):
        if S[i] != S[len(S)-1-i]:
            return False
    return True

S0 = S[0:(len(S)-1)//2]
S1 = S[(len(S)+3)//2-1:len(S)]

if judge(S) and judge(S0) and judge(S1):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
using namespace std;
#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb(X) push_back(X)
#define x first
#define y second
#define all(x) (x).begin(), (x).end()
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
typedef long long ll;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef pair<int, int> pii;
//ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const int MX_H = 10, MX_W = 1e3;
int h, w, K, ans = 1e9;
string s[MX_H];
VI A[MX_W];

int main() {
	INIT
	cin >> h >> w >> K;
	rep (i, 0, h) {
		cin >> s[i];
	}
	for (int i = 0; i < 1 << h - 1; ++i) {
		int Temp = __builtin_popcount(i);
		bool flag = false;
		rep (j, 0, w) {
			int num = 0;
			rep (k, 0, h) {
				num += s[k][j] & 1;
				if (i >> k & 1) {
					A[j].pb(num);
					num = 0;
				}
			}
			A[j].pb(num);
			for (int it : A[j]) {
				if (it > K) {
					Temp = 1e9;
					flag = true;
					break;
				}
			}
		}
		if (flag) {
			rep (j, 0, w) {
				A[j].clear();
			}
			continue;
		}
		VI B(A[0].size()); 
	//	if (!i) for (int I = 0; I < A[0].size(); ++I) cout << I << ' ' << A[0][I] << ' ' << endl;
		rep (j, 0, w) {
			bool split = false;
			rep (k, 0, B.size()) {
				split |= B[k] + A[j][k] > K;
			}
			if (split) {
				++Temp;
				B = VI(B.size());
			}
			rep (k, 0, B.size()) {
				B[k] += A[j][k];
			}
			A[j].clear();
		}
		ans = min (ans, Temp);
	}
	cout << ans;
	return 0;
}

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

int main(){
  int a=0,b=0,c=0,i;
  string s;
  cin >> s;
  for(i=0;i<s.size();i++){
    if(s.at(i)=='a'){
      a++;
    }else if(s.at(i)=='b'){
      b++;
    }else{
      c++;
    }
  }
  if(abs(a-b)<=1&&abs(b-c)<=1&&abs(c-a)<=1){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c, d;
    cin >> a >> b >> c >>d;
    if(c % b == 0){
        if((c / b - 1) * d >= a) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
    else{
    if(c / b * d >= a) cout << "No" << endl;
    else cout << "Yes" << endl;
    }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

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

	vector<int> A(N + 1), B(N);
	for (int i = 0; i <= N; i++) cin >> A[i];
	for (int i = 0; i < N; i++) cin >> B[i];

	int64_t ret = 0;
	for (int i = 0; i < N; i++) {
		int d = B[i] - A[i];
		if (d >= 0) {
			ret += A[i];
			ret += min(d, A[i + 1]);
			A[i + 1] -= d;
			if (A[i + 1] < 0) A[i + 1] *= 0;
		}
		else {
			ret += B[i];
		}
	}

	cout << ret << endl;
}

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

const int N = 17;
R memo[N][1<<(N-1)], p[N][1<<(N-1)];

int m, n;

R rec(int ri, int used){
    R& ret = memo[ri][used];
    if(ret > -EPS) return ret;

    ret = 0.0;

    rep(i, m){
        R cur = 0.0;

        if(used & (1 << i)) continue;
        int nused = used | (1 << i);

        R won_p = 1.0;
        rep(nri, ri, n){
            cur += won_p * (1.0 - p[i][nri]) * rec(nri, nused);
            won_p *= p[i][nri];
        }
        cur += won_p;

        chmax(ret, cur);
    }

    return ret;
}

int main(void){
    cin >> m >> n;
    rep(i, m) rep(j, n) cin >> p[i][j];

    rep(i, n + 1) rep(j, 1 << m) memo[i][j] = -1;

    cout.precision(20);
    cout << fixed << rec(0, 0) << endl;

    return 0;
}

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

int main()
{
  int n, m;
  float kijun, sousu;
  string ans;
  int i;
  cin >> n;
  cin >> m;
  vector<int> a(n);
  sousu = 0;
  for(i=0; i<n; i++)
  {
    cin >> a[i];
    sousu += a[i];
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  kijun = sousu/(4*m);
  ans = "Yes";
  for(i=0; i<m; i++)
  {
    if(a[i] < kijun) ans = "No";
  }
  cout << ans << endl;
  return 0;
}

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

#define print(a) cout << res << endl;

int main(){
    int res = 0;
    int k, s; cin >> k >> s;

    for (int x = k;x>=0; x--){
        for (int y = k;y>=0; y--){
            if (s-x-y<=k && s-x-y>=0){
                res++;
            }
        }
    }

    print(a);

    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> rabbit(n+1);
    int ans = 0;
    for (int i = 1; i <= n; i++) cin >> rabbit[i];
    for (int i = 1; i<=n; i++){
        if (i == rabbit[rabbit[i]]) ans++;
    }
    cout << ans/2 << endl;
}


Measured memory_bytes: 640
# 入力
n, m, x = map(int, input().split())
a = list(map(int, input().split()))

goto_goal_0 = 0 # 0までのコスト
goto_goal_n = 0 # nまでのコスト

# x から 0 へ向かうコストを計算
for i in range(x - 1, 0, -1):   # x-1 番目から順番にデクリメントしながらforループ
    if i in a:
        goto_goal_0 += 1
        # print("0 is {}".format(goto_goal_0))

# x から n へ向かうコストを計算
for i in range(x, n + 1):   # x 番目から順番にインクリメントしながらforループ
    if i in a:
        goto_goal_n += 1
        # print("n is {}".format(goto_goal_n))

if goto_goal_0 < goto_goal_n:
    print(goto_goal_0)
else:
    print(goto_goal_n)


Measured memory_bytes: 9112
#include <stdio.h>
#include <queue>
using namespace std;

int main(){
    int n,q,query,x,t;;
    scanf("%d %d", &n,&q);
    queue<int> A[n];
    for (int i = 0; i < q; i++)
    {        
        scanf("%d %d", &query,&t);
        switch (query){
            case 0:
                scanf("%d",&x);
                A[t].push(x);                       
                break;
            case 1:
                if (!A[t].empty()) printf("%d\n",A[t].front());
                break;
            case 2:
                if (!A[t].empty()) A[t].pop();
                break;
            default:
                break;
        }
    }    
    return 0;
}


Measured memory_bytes: 3912
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;

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

    vector<bool> flg(3, true);
    flg[--a] = false; flg[--b] = false;

    rep(i, 3) if(flg[i]) cout << ++i << endl;
    
    return 0;
}



Measured memory_bytes: 256