akhauriyash/Code-Regression huggingface dataset:
module Main where

import Debug.Trace
import Data.List
import qualified Data.Sequence as S
import qualified Data.ByteString.Char8 as B
import Data.Int
import Data.Char
import Data.Array
import Data.Maybe
import qualified Data.Map as M
import Data.Ord
import Data.Functor
import Control.Applicative
import Control.Monad
import Text.Printf

data Tree a = Nil | Node a a (Tree a) (Tree a) deriving (Show)
data Command = Print | Delete Int | Find Int | Insert Int Int deriving (Show)
data Order = Preorder | Inorder deriving (Eq, Show)

sDelete = B.pack "delete"
sFind   = B.pack "find"
sInsert = B.pack "insert"
sPrint  = B.pack "print"

solve :: [Command] -> [String]
solve = iter Nil where
    iter :: Tree Int-> [Command] -> [String]
    iter _ [] = []
    iter rt (c:cs) = case c of
        Print    -> (inorder rt):(preorder rt):(iter rt cs)
        Delete x -> iter (delete x rt) cs
        Find x   -> (find x rt):(iter rt cs)
        Insert x p -> iter (insert x p rt) cs

    delete x = iter where
        iter Nil = Nil 
        iter t@(Node y q l r)             
            | x < y  = Node y q (iter l) r
            | x > y  = Node y q l (iter r)
            | x == y = case (l, r) of
                (Nil, Nil) -> Nil
                (Nil, r)   -> iter $ leftRotate t 
                (l, Nil)   -> iter $ rightRotate t
                (Node _ lq _ _, Node _ rq _ _) -> iter $ if lq > rq then rightRotate t else leftRotate t

    leftRotate  (Node x p a (Node y q b c)) = Node y q (Node x p a b) c

    rightRotate (Node y q (Node x p a b) c) = Node x p a (Node y q b c)

    find x = iter where
        iter (Node y q l r)
            | x == y = "yes"
            | x <  y = iter l
            | x >  y = iter r 
        iter Nil = "no"

    insert x p = iter where
        iter (Node y q l r)
            | x < y     = case iter l of
                t@(Node _ q' _ _)
                    | q < q'    -> rightRotate (Node y q t r)
                    | otherwise -> Node y q t r
            | otherwise = case iter r of
                t@(Node _ q' _ _)
                    | q < q'    -> leftRotate (Node y q l t)
                    | otherwise -> Node y q l t
        iter Nil = Node x p Nil Nil 

    preorder = toString . (toList Preorder)
    inorder  = toString . (toList Inorder)

toList :: Order -> Tree a -> [a]
toList ord = iter where
    iter Nil = []
    iter (Node id p l r)
        | ord == Preorder = id:(iter l) ++ iter r
        | ord == Inorder  = (iter l) ++ id:iter r

toString:: [Int] -> String
toString [] = []
toString (x:xs) = ' ':(show x)++ toString xs

toInt :: B.ByteString -> Int
toInt = fst . fromJust . B.readInt
                    
readIntLn:: IO Int
readIntLn = toInt <$> B.getLine

readCommand:: IO Command
readCommand = do
    l <- B.words <$> B.getLine
    return $ case l of
        [cmd, n, m]
            | cmd == sInsert -> Insert (toInt n) (toInt m)
        [cmd, n]
            | cmd == sDelete -> Delete (toInt n)
            | cmd == sFind   -> Find   (toInt n)
        [sPrint]     -> Print

main :: IO() 
main = do
    n <- readIntLn
    l <- replicateM n readCommand
    mapM_ putStrLn $ solve l



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

int main(){
    int a,b;
    char c;
    while(1){
      //  cin >> a >> c >> b;  
        scanf("%d %c %d",&a,&c,&b);
       // printf("%d %c %d\n",a,c,b);
        if(c=='?') break;
        if(c=='+') cout << a+b << endl;
        else if(c=='-') cout << a-b << endl;
        else if(c=='*') cout << a*b << endl;
        else if(c=='/') cout << a/b << endl;
    }
    return 0;
}


Measured memory_bytes: 3172
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		sc.close();

		int max = (n - 1) * (n - 2) / 2;
		if (k > max) {
			System.out.println(-1);
			return;
		}

		int m = n - 1 + max - k;
		System.out.println(m);
		for (int i = 2; i <= n; i++) {
			System.out.println("1 " + i);
		}

		int rem = max - k;
		for (int i = 2; i < n; i++) {
			for (int j = i + 1; j <= n; j++) {
				if (rem > 0) {
					System.out.println(i + " " + j);
				}
				rem--;
			}
		}
	}
}


Measured memory_bytes: 24532
#include<bits/stdc++.h>
using namespace std;
int a[555555],l[555555],r[555555],n;
char s[555555];
long long ans;
int main()
{
	scanf("%s",s);
	n=strlen(s);
	l[n+1]=0;r[n+1]=1e9;
	for (int i=n;i>=1;i--)
	{
		if (s[i-1]=='>') 
		{
			l[i]=l[i+1]+1;
			r[i]=r[i+1]+1;
		}
		else
		{
			l[i]=0;
			r[i]=max(0,r[i+1]-1);
		}
	}
	a[1]=l[1];
	for (int i=2;i<=n+1;i++) 
	{
		if (s[i-2]=='<') a[i]=max(a[i-1]+1,l[i]);
		else a[i]=l[i];
	}
	for (int i=1;i<=n+1;i++) ans+=a[i];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 7040
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#define N 4010
#define mod 998244353
ll f[N][N],c[N],d[N];
int main(){
  string s;cin>>s;
  for(int i=0;i<N;i++)c[i]=d[i]=1e17;
  c[0]=0; for(int i=0;i<s.size();i++)c[i+1]=c[i]+(s[i]-'0');
  d[0]=0; for(int i=0;i<s.size();i++)d[i+1]=d[i]+('2'-s[i]);
  for(int i=0;i<N;i++)for(int j=0;j<N;j++) f[i][j]=0; f[0][0]=1;
  for(int i=0;i<=c[s.size()];i++)for(int j=0;j<=d[s.size()];j++){
    ll k=i+j+1;
    if(c[k]>i)f[i+1][j]=(f[i+1][j]+f[i][j])%mod;
    if(d[k]>j)f[i][j+1]=(f[i][j+1]+f[i][j])%mod;
  }
  cout<<f[c[s.size()]][d[s.size()]]<<endl;
  return 0;
}


Measured memory_bytes: 125952
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
//const lint MOD = pow(10, 9) + 7;

int main() {
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			cout << i << 'x' << j << '=' << i * j << endl;
		}
	}
}


Measured memory_bytes: 3088
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<iterator>
#include<stack>
#include<queue>
#include<utility>
#include<functional>
#include<bitset>
#include<numeric>
#include<cstring>
#include<tuple>
using namespace std;

int n, k, pos, mod = 1e9 + 7;
long long dp[ 105 ][ 100005 ], sum[ 105 ][ 100005 ];
vector< int > arr( 105 );

int main( void )
{
	ios :: sync_with_stdio( 0 );
	cin.tie( 0 );
	
	cin >> n >> k;
	for( int i = 1; i <= n; ++i )
	{
		cin >> arr[ i ];		
	}
	memset( sum, 0, sizeof( sum ) );
	memset( dp, 0, sizeof( dp ) );
	for( int j = 0; j <= arr[ 1 ]; ++j )
	{
		dp[ 1 ][ j ] = 1;
		sum[ 1 ][ j ] = dp[ 1 ][ j ];
	}
	for( int j = 1; j <= 1e5 + 2; ++j )
	{
		sum[ 1 ][ j ] += sum[ 1 ][ j - 1 ];
	}
	for( int i = 2; i <= n; ++i )
	{
		for( int j = 0; j <= 1e5 + 2; ++j )
		{
			dp[ i ][ j ] = sum[ i - 1 ][ j ];
			pos = j - min( arr[ i ], j );
			if( pos != 0 )
			{
				dp[ i ][ j ] -= sum[ i - 1 ][ pos - 1 ];
				dp[ i ][ j ] += mod;
				dp[ i ][ j ] %= mod;
			}
			sum[ i ][ j ] = dp[ i ][ j ];
		}
		for( int j = 1; j <= 1e5 + 2; ++j )
		{
			sum[ i ][ j ] += sum[ i ][ j - 1 ];
			sum[ i ][ j ] %= mod;
		}
	}	
	cout << dp[ n ][ k ] << "\n";
	return 0;
}

Measured memory_bytes: 164352
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD =  998244353;

     signed main(){
      
      string s;
      cin>>s;
      for(int i=0;i<3;i++)if(s[i]=='7'){
           cout<<"Yes";
           return 0;
      }
      cout<<"No";

      }

        


Measured memory_bytes: 3628
import java.util.*;

public class Main {
	
	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		int result = a + b;
		if(result >=24) result -= 24;
		System.out.println(result);

	}

}


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


int main(){
    int n,m; cin >> n >> m;
    for(int i=0;i<m;i++){
        int a; cin >> a;
        n-=a;
    }
    cout << max(n,-1) << endl;
    return 0;
}

Measured memory_bytes: 3632
a,b = list(map(int,input().split()))

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

def factorize(n):
    b = 2
    factor=[]
    while b * b <= n:
        while n % b == 0:
            n //= b
            factor.append(b)
        b += 1
    if n > 1:
        factor.append(n)
    return factor

print(len(set(factorize(gcd(a, b))))+1)

Measured memory_bytes: 3060
package main

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

const size = 1000000
var reader = bufio.NewReaderSize(os.Stdin,size)
func NextLine() string {
  var line,buffer []byte
  var isPrefix bool = true
  var err error
  for ;isPrefix; {
    line,isPrefix,err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
  }
  return string(buffer)
}
func NextInt() int {
  var n int
  n,_ = strconv.Atoi(NextLine())
  return n
}
func NextIntArray() []int {
  var s []string = strings.Split(NextLine()," ")
  var n int = len(s)
  var a []int = make([]int,n)
  for i:=0;i<n;i++ {
    a[i],_ = strconv.Atoi(s[i])
  }
  return a
}

func main() {
  var n int = NextInt()
  var a []int = NextIntArray()
  m := map[int]int{}
  for i:=0;i<n;i++ { m[a[i]]++ }
  var s int
  for _,v := range m {
    if v%2 == 0 { s++ }
  }
  fmt.Println(len(m)-s%2)
}

Measured memory_bytes: 7424
#include<bits/stdc++.h>
#define ll long long
#define F(type, i, a, b) for(type i = a; i <= b; i ++)
#define RF(type, i, a, b) for(type i = a; i >= b;i --)
#define sz(a) sizeof(a)
#define deb(a) cerr<<" ["<<#a<<"->"<<a<<"] "
#define next_line cerr<<'\n'
#define all(a) a.begin(), a.end()
#define iter(it, s) for(auto it = s.begin(); it != s.end(); it ++)

using namespace std;

typedef pair<ll,ll> pii;
typedef pair<ll,ll> pll;

void solve()
{
    //If you cannot approach a problem
    //directly in the way it is proposed then try to think from backwards
    ll n, k, ans;
    cin>>n>>k;
    vector<ll> A(n);
    for(ll &i: A) cin>>i;
    ll l = 1LL, r = 1e9;
    while(l <= r){
        //deb(l);deb(r);next_line;
        ll mid = (l + r ) >> 1;
        ll oper = 0LL;
        for(ll i: A){
            if((i % mid) == 0LL)
                oper += ((i / mid) - 1LL);
            else
                oper += (i / mid);
            if(oper > k){
                break;    
            }
        }
        if(oper > k){
            l = (mid + 1LL);
        }else{
            ans = mid;
            r = mid - 1LL;
        }
    }
    cout<<ans<<'\n';
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        freopen("Debug.txt", "w", stderr);
    #else
    #endif
        solve();
}


Measured memory_bytes: 4720
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define PI (acos(-1))

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;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<ll> a(n+1),sum(n+1,0);
	FOR(i,1,n+1){
		cin>>a[i];
		sum[i]=sum[i-1]+a[i];
	}
	vector<vector<ll>> dp(n+2,vector<ll>(n+2,inf));
	function<ll(int,int)> dfs=[&](int l,int r){
		if(dp[l][r]!=inf) return dp[l][r];
		if(r-l==1){
			return dp[l][r]=0;
		}
		ll ret=inf;
		FOR(i,l+1,r){
			chmin(ret,dfs(l,i)+dfs(i,r)+sum[r-1]-sum[l-1]);
		}
		return dp[l][r]=ret;
	};
	cout<<dfs(1,n+1)<<endl;
}

Measured memory_bytes: 1664
#include<iostream>
#include<vector>
#include<list>
#include<set>
#include<algorithm>
#include<map>
#include<string>
#include<unordered_map>
#include<math.h>
#include<random>
#include<unordered_set>
#include<set>
#include<stdlib.h>
#include<memory>

using namespace std;

int main(void) {
	vector<int> in;
	list<int> list;

	in.resize(3);

	cin >> in[0] >> in[1] >> in[2];

	for (const auto& x : in) {
		if (find(list.begin(), list.end(), x)==list.end()) {
			list.push_back(x);
		}
	}

	cout << list.size() << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, a[100008], sum;

int main(){
	cin >> n;
	for(ll i = 1; i <= n; i++){cin >> a[i];}

	sum = 0;
	ll ans1 = 0;
	for(ll i = 1; i <= n; i++){
		sum += a[i];
		if(i%2 == 0 && sum <= 0){
			ans1 += -sum+1;
			sum = 1;
		}
		if(i%2 == 1 && sum >= 0){
			ans1 += sum+1;
			sum = -1;
		}
	}	
	
	sum = 0;
	ll ans2 = 0;
	for(ll i = 1; i <= n; i++){
		sum += a[i];
		if(i%2 == 1 && sum <= 0){
			ans2 += -sum+1;
			sum = 1;
		}
		if(i%2 == 0 && sum >= 0){
			ans2 += sum+1;
			sum = -1;
		}
	}
	
	cout << min(ans1, ans2) << endl;
	return 0;
}

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

using namespace std;
const int N=3e5+5;
int cnt [N];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,x,y;
    cin>>n>>x>>y;
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
        {
            int mn=j-i;
            mn=min(mn,abs(x-i)+abs(y-j)+1);
            mn=min(mn,abs(y-i)+abs(x-j)+1);
            cnt[mn]++;
        }
    for(int i=1;i<n;i++)
        cout<<cnt[i]<<'\n';
    return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
a=[[]for i in range(n+1)]
b=[""]*(n+1)
for i in range(m):
    l,r,d=map(int,input().split())
    a[l].append([r,d])
    a[r].append([l,-d])
for i in range(1,n+1):
    if b[i]=="":
        b[i]=0
        k=[i]
        while k:
            s=k.pop()
            for x,y in a[s]:
                if b[x]=="":
                    k.append(x)
                    b[x]=b[s]+y
c="Yes"
for i in range(1,n+1):
    for p,q in a[i]:
        if b[i]+q!=b[p]:
            c="No"
print(c)

Measured memory_bytes: 77612
/*

*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/hash_policy.hpp>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
#define int long long 
#define LL long long 
#define ull unsigned long long 
#define rg register 
#define pt(x) printf("%d ", x);
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 22)], *p1 = buf, *p2 = buf;
//char obuf[1<<24], *O = obuf;
//void print(int x) {if(x > 9) print(x / 10); *O++ = x % 10 + '0';}
//#define OS  *O++ = ' ';
using namespace std;
//using namespace __gnu_pbds;
const int MAXN = 1e6 + 10, INF = 1e9 + 10, mod = 1e9 + 7;
const double eps = 1e-9;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
map<string, bool> mp;
int N;
string s[MAXN];
main() {
	int N = read();
	
	for(int i = 1; i <= N; i++) {
		cin >> s[i];
		if(mp.find(s[i]) != mp.end()) {puts("No"); return 0;}
		if(i > 1) {
			int l = s[i - 1].length();
			if(s[i][0] != s[i - 1][l - 1]) {puts("No"); return 0;
			}
		}
		mp[s[i]] = 1;
	}
	puts("Yes");

    return 0;
}
/*
2 2 1
1 1
2 1 1
*/

Measured memory_bytes: 8064
# x が1 か 2N - 1の場合、中央値としてこれらが上がってくることはないため"No"
# それ以外の場合、
# x = Nの場合、順列そのまま1,2,3...2N-1でOK
# x < Nの場合、xを真ん中に置き、その左に1を置く。
# あとは左から順に1,2,3...と埋めていけばOK
# x > Nの場合、xを真ん中に置き、その右に2N - 1を置く。
# あとは左から順に1,2,3...と埋めていけばOK

import sys
readline = sys.stdin.readline

N,x = map(int,readline().split())

if x == 1 or x == 2 * N - 1:
  print("No")
  exit(0)
elif x == N:
  A = [i + 1 for i in range(2 * N - 1)]
elif x < N:
  A = [0 for i in range(2 * N - 1)]
  A[N - 1] = x
  A[N - 2] = 1
  ind = 0
  for num in range(2,2 * N):
    if num in (1,x):
      continue
    if A[ind] != 0:
      ind += 2
    A[ind] = num
    ind += 1
elif x > N:
  A = [0 for i in range(2 * N - 1)]
  A[N - 1] = x
  A[N] = 2 * N - 1
  ind = 0
  for num in range(1,2 * N):
    if num in (x,2 * N - 1):
      continue
    if A[ind] != 0:
      ind += 2
    A[ind] = num
    ind += 1

print("Yes")
for a in A:
  print(a)

Measured memory_bytes: 12556
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include <cmath>
#include<map>

using namespace std;

int i,j,k,n,m,N,A[200001]={0},ans;

char S[200001];



int main()
{
  cin>>S;
  
  N=strlen(S);
  
  n=0;
  m=1;
  for(k=N-1;k>=0;k--)
  {
    n+=(S[k]-'0')*m;
    n%=2019;
    A[n]++;
    m*=10;
    m%=2019;
  }
  ans=A[0]*(A[0]+1)/2;
  for(k=1;k<2019;k++)
  {
    if(A[k]>=2)
    {
      ans+=A[k]*(A[k]-1)/2;
    }
  }

  
  cout <<ans;
}

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

using namespace std;

typedef pair<int,int> P;
#define INF 1000000

int dx[4]={1,0,0,-1}, dy[4]={0,1,-1,0};
int d[1010][1010];
char r[1010][1010];
char point[10]={'S','1','2','3','4','5','6','7','8','9'};
int H,W,N;
int res=0;

int bfs(int ah,int aw,int bh,int bw){
  queue<P> que;
  for(int i=0;i<H;i++)
    for(int j=0;j<W;j++)
      d[i][j]=INF;

  d[ah][aw]=0;
  que.push(P(ah,aw));

  while(que.size()){
    P p= que.front();
    que.pop();
    if(p.first==bh && p.second==bw) break;

    for(int i=0;i<4;i++){
      int nh=p.first+dx[i], nw=p.second+dy[i];

      if(0<=nh && nh<H && 0<=nw && nw<W && r[nh][nw]!='X' && d[nh][nw]==INF){
        que.push(P(nh,nw));
        d[nh][nw]=d[p.first][p.second]+1;
      }
    }
  }
  return d[bh][bw];
}

void solve(){
  queue<P> kyu;
  for(int k=0;k<=N;k++){
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        if(r[i][j]==point[k])
          kyu.push(P(i,j));
      }
    }
  }

  for(int i=0;i<N;i++){
    P p1=kyu.front();
    kyu.pop();
    P p2=kyu.front();
    res+=bfs(p1.first,p1.second,p2.first,p2.second);
  }

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

}


int main(){
  scanf("%d%d%d",&H,&W,&N);

  for(int i=0;i<H;i++)
    scanf("%s",&r[i]);

  solve();

  return 0;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
#define ll long long
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define endl "\n"
using namespace std;
const int N=2e5;
vector<ll> adj[N];
int vis[N],ans[N];
void bfs()
{
    queue<ll> q;
    vis[1]++;
    q.push(1);
    while(!q.empty())
    {
        ll t=q.front();
        q.pop();
        for(auto k:adj[t])
        {
            if(!vis[k])
            {
                vis[k]++;
                ans[k]=t;
                q.push(k);
            }
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll n,m;cin>>n>>m;
    f(i,0,m)
    {
        ll u,v;cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    bfs();
    int f=0;
    f(i,2,n+1)
    {
        if(!vis[i])
        {
            cout<<"No\n";
            return 0;
        }
    }
    cout<<"Yes\n";
    f(i,2,n+1) cout<<ans[i]<<endl;
}


Measured memory_bytes: 15320
s = input()
n = len(s)
ans = 0
if (n%2 == 0):
  nh = int(n/2)
  for i in range(nh):
    if (s[i] != s[n - i - 1]):
      ans = ans + 1
else:
  nh = int((n - 1)/2)
  for i in range(nh):
    if (s[i] != s[n - i - 1]):
      ans = ans + 1
print(ans)

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

int main(){
  string s; cin>>s;
  int n=s.size();
  vector<int> ans(n,0);
  for(int i=0;i<n;i++){
    int c=0,pos=i;
    char dir=s[pos];
    while(dir==s[pos]){
      pos++;
      c++;
    }ans[pos-1]+=c/2+c%2;
    ans[pos]+=c/2;
    i+=c;
    c=0;
    while(dir!=s[pos]){
      pos++;
      c++;
      if(pos==n) break;
    }
    ans[pos-c]+=c/2+c%2;
    ans[pos-c-1]+=c/2;
    i+=c-1;
  }cout<<ans[0];
  for(int i=1;i<n;i++){
    cout<<' '<<ans[i];
  }cout<<endl;
}

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

vector<int> KMP(const string& S) {
	int N = S.size();
	vector<int> A(N + 1);
	A[0] = -1;
	for (int i = 0, j = -1; i < N; i++) {
		while (j >= 0 && S[i] != S[j]) {
			j = A[j];
		}
		j++;
		A[i + 1] = (i + 1 == N ? '*' : S[i + 1]) == (j == N ? '*' : S[j]) ? A[j] : j;
	}
	return A;
}

vector<int> StringSearch(const string& S, const string& T) {
	auto A = KMP(T);
	int N = T.size();
	vector<int> res;
	for (int i = 0, j = 0; i < (int)S.size(); i++) {
		while (j >= 0 && S[i] != T[j]) {
			j = A[j];
		}
		j++;
		if (j == N) {
			res.push_back(i - N + 1);
			j = A[j];
		}
	}
	return res;
}

int main()
{
	cin.sync_with_stdio(false);
	string T, P;
	cin >> T >> P;
	for (auto ans : StringSearch(T, P)) {
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 8872
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
using namespace std;
int dx[5]={1,0,-1,0,0},dy[5]={0,1,0,-1,0};
long long gcd(long long a,long long b){if(a%b==0){return b;}else return gcd(b,a%b);}
long long lcm(long long a,long long b){if(a==0){return b;} return a/gcd(a,b)*b;}
#define INF 2000000000
#define MOD 1000000007
#define sym cout<<"---------"<<endl;
#define ll long long
#define mk make_pair
#define en endl
#define RE return 0
#define int ll
#define P pair<int,int>

signed main(){
	string s1,s2; cin>>s1>>s2;
	
	int n=s1.length(),m=s2.length();
	vector<vector<int> > dp(n+1,vector<int>(m+1,INF));
	for(int i=0; i<=n; i++) dp[i][0]=i;
	for(int i=0; i<=m; i++) dp[0][i]=i;
	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++){
			dp[i][j]=min(dp[i][j],dp[i-1][j]+1);
			dp[i][j]=min(dp[i][j],dp[i][j-1]+1);
			dp[i][j]=min(dp[i][j],dp[i-1][j-1]+(s1[i-1]!=s2[j-1]));
		}
	}
	cout<<dp[n][m]<<en;
}







Measured memory_bytes: 10892
def dis(a, b, c, d):
    num = abs(a - c) + abs(b - d)
    return num

n,m = map(int,input().split())
a = [0] * n
b = [0] * n
c = [0] * m
d = [0] * m

for i in range(n):
    a[i], b[i] = map(int,input().split())
for i in range(m):
    c[i], d[i] = map(int, input().split())

for i in range(n):
    ans = []
    for j in range(m):
        ans.append(dis(a[i],b[i],c[j],d[j]))
    print(ans.index(min(ans)) + 1)



Measured memory_bytes: 9164
#include<iostream>
#include<string.h>
int main(){int m,n=999999,o,c=n/2+1,d,i,e;bool*v=new bool[c];memset(v,1,c);for(i=m=1;i<499;){for(m=i++;!v[m];)m++;for(o=m*2+1,d=o*3;d<n+1;d+=o*2)v[d/2]=0;}for(;!(std::cin>>n).eof();){e=n>1;n&1?n:--n;for(i=1;i<n/2+1;)e+=v[i++];printf("%d\n",e);}delete[]v;}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

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

    vector<int> a(N, 0);
    int b = 1000000;


    if(s[0] == '(') a[0] = 1;
    else a[0] = -1;
    b = min(b, a[0]);

    for(int i=1; i<N; i++){
        if(s[i] == '(') a[i] = a[i-1]+1;
        else a[i] = a[i-1]-1;

        b = min(b, a[i]);
    }

    if(b < 0){
        for(int i=0; i<-b; i++) s = '(' + s;
        a[N-1] = a[N-1]-b;
    }
    for(int i=0; i<a[N-1]; i++) s += ')';

    cout << s << endl;
}

Measured memory_bytes: 256
S = input()
N = len(str(S))
P = 2019
list_a = [0] * P
list_a[0] += 1
counter = 0
temp = 0
power = 1
for i in range(N):
    temp += pow(10, i, P) * int(S[N - i - 1])
    temp %= P
    counter += list_a[temp]
    list_a[temp] += 1
print(counter)




Measured memory_bytes: 68052
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    arms = []
    for i in range(N):
        x, l = map(int,input().split())
        t = min(x+l,10**9)
        s = max(x-l,0)
        arms.append((t,s))
    arms.sort()

    ans = 0
    tmp = -1

    for t,s in arms:
        if s >= tmp:
            tmp = t
            ans += 1

    print(ans)

main()

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    long long A[N], dp[N + 1][2];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        dp[i][0] = 0;
        dp[i][1] = 0;
    }
    dp[0][1] = -1000000007;
    for (int i = 0; i < N; i++) {
        dp[i + 1][0] = max(dp[i][0] + A[i], dp[i][1] - A[i]);
        dp[i + 1][1] = max(dp[i][0] - A[i], dp[i][1] + A[i]);
    }
    cout << dp[N][0] << endl;
}

Measured memory_bytes: 2560
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto abc = readln.split.to!(long[]);
    sort(abc);
    auto A = abc[0];
    auto B = abc[1];
    auto C = abc[2];

    if (A%2 == 0 || B%2 == 0 || C%2 == 0) {
        writeln(0);
    } else {
        writeln(A * B);
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	int x, n; cin >> x >> n;
	vector<int> black(n);
	for( auto &k : black ) cin >> k;
	sort( black.begin(), black.end() );
	int ans = inf;
	for( int i = -10; i <= 110; ++i ){
		if( !binary_search( black.begin(), black.end(), i ) ){
			ans = min( abs(x-i), ans );
		}
	}
	if( binary_search( black.begin(), black.end(), x-ans ) ){
		cout << x+ans << endl;
	} else cout << x-ans << endl;
}

Measured memory_bytes: 3604
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>

using namespace std;

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

    queue<long> q;

    for (long i = 1; i < 10; i ++){
        q.push(i);
    }

    long ans = 0;
    for (long i = 1; i <= K; i++){
        ans = q.front();
        q.pop();
        if (ans % 10 != 0){
            q.push(10 * ans + ans % 10 - 1);
        }
        q.push(10 * ans + ans % 10);
        if (ans % 10 != 9){
            q.push(10 * ans + ans % 10 + 1);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;

int a[111111];

int main(){
    int n; scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",a+i);

    sort(a,a+n,greater<int>());

    int x=0;
    while(x+1<n&&(x+1)<a[x+1]) x++;

    int y = x;
    while(y+1<n&&x<a[y+1]) y++;
    if((y-x)%2 || (a[x]-1-x)%2) printf("First");
    else printf("Second");
}


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

int main (){
	int n ,q, a,k=0;
	cin>>n;
	vector<int> A;
	for(int i = 0;i<n;i++){
		cin>>a;
		A.push_back(a);
	}
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>a;
		for(int j=0;j<n;j++){
			if(A[j]==a) {k++;break;}
		}
	}
	if(k==0) cout<<"0"<<endl;
	else cout<<k<<endl;;
	return 0;
}


Measured memory_bytes: 3144
import java.io.IOException;
import java.util.NoSuchElementException;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int N = Integer.parseInt(sc.next());
        String r = "No";
        for (int i = 1; i <= 9; i++) {
            if (N % i == 0 && N / i <= 9) {
                r = "Yes";
                break;
            }
        }
        System.out.println(r);
    }
}

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

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

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

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

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

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

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

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

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

Measured memory_bytes: 22356
#include <iostream>

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    if(((n % 1000) % 111 == 0) || ((n / 10) % 111 == 0)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 504
#include <stdio.h>
int main(void)
{
	int i, j;
	int w, h;
	w = 0;
	h = 0;
	while (1)
	{
		scanf("%d%d", &w, &h);
		if (w == 0 && h == 0)
			break;
		for (i = 1;i <=w;i++)
		{
			for (j = 1;j <=h;j++)
			{
				if (i != 1 && i != w && j != 1 && j != h)
				{
					printf(".");
				}
				else
				{
					printf("#");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2104
n = int(input())
o = list(map(int, input().split()))
m = list(map(int, input().split()))
a = list(map(int, input().split()))

b = -2
ans = 0
for i, name in enumerate(o):
    if name == b + 1:
        ans += a[name - 2]
    ans += m[name-1]
    b = name

print(ans)

Measured memory_bytes: 3060
from math import gcd

N = int(input())
A = list(map(int,input().split()))

setgcd = A[0]
for i in range(N):
    setgcd = gcd(setgcd,A[i])
is_set = True
if setgcd != 1:
    is_set=False

M = max(A)
is_prime=[1]*(M+1)#Mまで行きたい
is_inA=[0]*(M+1)
for i in range(N):
    is_inA[A[i]]=1

is_pair = True
is_prime[0]=0
is_prime[1]=0
for i in range(2,M+1):
    count = 0
    if is_inA[i]==1:
        count=1
    if is_prime[i]==1:
        for j in range(2*i,M+1,i):
            is_prime[j]=0
            if is_inA[j]==1:
                count+=1
    if count >= 2:
        is_pair = False

if is_set and is_pair:
    print("pairwise coprime")
elif is_set:
    print("setwise coprime")
else:
    print("not coprime")

Measured memory_bytes: 212836
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#define unordered_map __fast_unordered_map
template<class Key, class Value, class Hash = std::hash<Key>>
using unordered_map = __gnu_pbds::gp_hash_table<Key, Value, Hash>;

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif


int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);

  int N;
  cin >> N;
  vector<int> lengths(N);
  for (int &x : lengths) { cin >> x; }

  auto CanHave = [&](int A) {
    vector<PII> cur_string{PII{1, lengths[0]}};
    int cur_len = lengths[0];

    auto Trim = [&](int len) {
      while (cur_len - cur_string.back().nd >= len) {
        cur_len -= cur_string.back().nd;
        cur_string.pop_back();
      }
      cur_string.back().nd -= cur_len - len;
      cur_len = len;
    };

    auto AddOne = [&](int to_len) {
      if (to_len == cur_len) { return; }
      if (cur_string.back().st == 1)
        cur_string.back().nd += to_len - cur_len;
      else
        cur_string.emplace_back(1, to_len - cur_len);
      cur_len = to_len;
    };

    for (int i = 1; i < N; ++i) {
      const int len = lengths[i];

      if (len > cur_len) {
        AddOne(len);
      } else {
        Trim(len);
        while (!cur_string.empty() && cur_string.back().st == A) {
          cur_len -= cur_string.back().nd;
          cur_string.pop_back();
        }
        if (cur_string.empty()) { return false; }
        if (cur_string.back().nd == 1) {
          ++cur_string.back().st;
        } else {
          --cur_string.back().nd;
          cur_string.emplace_back(cur_string.back().st + 1, 1);
        }
        AddOne(len);
      }

      if (A == 2)
        debug(i, cur_string, cur_len);
    }

    return true;
  };

  int min_a = 0, max_a = N + 1;
  while (max_a - min_a > 1) {
    const int mid = (min_a + max_a) / 2;
    if (CanHave(mid))
      max_a = mid;
    else
      min_a = mid;
  }

  cout << max_a << "\n";

}



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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

using ll = long long int;
using P = pair<int,int>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const ll INF=(ll)1e19;
//const int INF=(1<<30);
//const int INF=(1<<29);

int main(){
  int h,w,a,b;
  cin >> h >> w >> a >> b;
  REP(i,h)REP(j,w){
    if((i < b && j < a) || (i >= b && j >= a)){
      cout << 0;
    }else{
      cout << 1;
    }

    if(j==w-1)cout<<endl;
  }
}



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

string s;
ll K;

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

    // set<string> st = {"b", "abc", "a", "ba"};
    // for (auto iter = st.begin(); iter != st.end(); iter++) {
    // }

    set<string> st;
    for (ll k = 1; k <= 5; k++) {
        if (s.size() < k) break;
        for (ll i = 0; i <= s.size() - k; i++) {
            st.insert(s.substr(i, k));
        }
    }

    ll ans_idx = 0;
    for (auto iter = st.begin(); iter != st.end(); iter++) {
        if (ans_idx == K - 1) {
            cout << *iter << endl;
            break;
        }
        ans_idx++;
    }
}

Measured memory_bytes: 1664
#include<iostream>
#include<string>
#include<algorithm>
#include<stdlib.h>
using namespace std;
int main() {
	int n;
	int a[200000];

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

	int old = 0;
	int dif;
	long long addif = 0;
	for (int i = 0; i < n; i++) {
		if (old > a[i]) {
			dif = abs(old - a[i]);

			a[i] += dif;
			addif += dif;
		}
		old = a[i];
	}
	cout << addif << endl;
	return 0;
}

Measured memory_bytes: 3848
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n, k;
int a[200000];
int t[60][200000];

signed main() {
	int i, j;
	
	cin >> n >> k;
	rep(i, n) { cin >> a[i]; a[i]--; }
	rep(i, n) t[0][i] = a[i];
	
	rep(i, 59) {
		rep(j, n) {
			t[i + 1][j] = t[i][t[i][j]];
		}
	}
	
	int p = 0;
	rep(i, 60) {
		if ((k >> i) & 1) {
			p = t[i][p];
		}
	}
	cout << p + 1 << endl;
	return 0;
}

Measured memory_bytes: 98948
#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "Yes"
no = "No"

def main():
    l = ii()
    print((l/3)**3)


main()





Measured memory_bytes: 5628
# https://atcoder.jp/contests/agc009/tasks/agc009_a

import sys
input=sys.stdin.readline

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

ans=0
for a,b in reversed(ab):
    a+=ans
    res=a%b
    if res:
        ans+=b-res
print(ans)

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

int main(){
  string S;
  cin >> S;
  if(S[0]==S[1] or S[1]==S[2] or S[2]==S[3]) cout << "Bad" << endl;
  else cout << "Good" << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    if(n&1):
        print("No")
        return

    S=input()
    print("Yes" if(S[:n//2]==S[n//2:]) else "No")
resolve()

Measured memory_bytes: 38256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = 1e9 + 7;


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

const ll MOD = 1e9 + 7;



//ユークリッド互除法
template<typename T>
T gcd(T x, T y) {

	if (y == 0) {
		return x;
	}
	else {
		return gcd(y, x % y);
	}
}
/*最小公倍数*/
template<typename T>
T lcm(T x, T y) {
	T tmp = gcd(x, y);
	return (x / tmp) * y;
}


/******************************************************************************************/

int r[2055][2055];
int l[2055][2055];
int u[2055][2055];
int d[2055][2055];

char mp[2005][2005];


int main() {

	int h, w;
	cin >> h >> w;
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++) {
			cin >> mp[i][j];
			if (mp[i][j] == '#') {
				r[i][j] = 0;
				l[i][j] = 0;
				u[i][j] = 0;
				d[i][j] = 0;
			}
			else
			{
				r[i][j] = 1;
				l[i][j] = 1;
				u[i][j] = 1;
				d[i][j] = 1;
			}
		}
	}

	//右
	for (int i = 0; i < h; i++) {
		for (int j = w-1; j > 0; j--) {

			if (r[i][j - 1] == 0) {
				continue;
			}
			else
			{
				r[i][j - 1] += r[i][j];
			}

		}
	}

	//左
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {

			if (l[i][j + 1] == 0) {
				continue;
			}
			else
			{
				l[i][j + 1] += l[i][j];
			}

		}
	}


	//上
	for (int j = 0; j < w; j++) {
		for (int i = h-1; i > 0; i--) {

			if (u[i - 1][j] == 0) {
				continue;
			}
			else
			{
				u[i - 1][j] += u[i][j];
			}

		}
	}


	//下
	for (int j = 0; j < w; j++) {
		for (int i = 0; i < h; i++) {

			if (d[i + 1][j] == 0) {
				continue;
			}
			else
			{
				d[i + 1][j] += d[i][j];
			}

		}
	}

	int maxi = 0;

	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++) {

			if (mp[i][j] == '#') {
				continue;
			}

			maxi = max(maxi, r[i][j] + l[i][j] + u[i][j] + d[i][j] - 3);
		}
	}

	cout << maxi << endl;

	return 0;
}


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

using namespace std;


int main() {
    string s;
    cin >> s;
    vector<int> v(26);
    for(int i = 0; i < 4; i++) {
        v[s[i]-'A']++;
    }
    for(int i = 0; i < 26; i++) {
        if(v[i] == 1 || v[i] == 3 || v[i] == 4) {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  int n = s.size();
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += s[i] != t[i] ? 1 : 0;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3808
from collections import deque
import bisect
import sys
sys.setrecursionlimit(10**9)


def main():
    N = int(input())
    X = deque()

    for _ in range(N):
        a = int(input())
        j = bisect.bisect_left(X,a)

        if j == 0:
            X.appendleft(a)
        else:
            X[j-1] = a


    print(len(X))


if __name__ == "__main__":
  main()


Measured memory_bytes: 47960
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
 
bool win[100100];
int N,K,A[101];
 
int main()
{
	scanf ("%d %d",&N,&K);
	for (int i=0;i<N;i++) scanf ("%d",&A[i]);
	for (int i=1;i<=K;i++){
		for (int j=0;j<N;j++) if (i >= A[j]){
			if (!win[i-A[j]]){
				win[i] = true;
				break;
			}
		}
	}
	puts(win[K]?"First":"Second");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.000001
#define pi 3.141592653589793
#define pii pair<int , int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define sti stack <int>
#define stll stack <ll>
#define mseti set <ll>
#define msetd multiset <ll, greater <ll> >
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define stp setprecision(20)//use fixed before stp
#define endl '\n'
int main()
{  
    FAST
    ll n,k;
    cin>>n>>k;
    ll dp[n][k+1];
    ll a[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<=k;j++)
        {
            dp[i][j]=0;
        }
    }
    for(ll i=0;i<=a[0];i++)
    {
        dp[0][i]=1;
    }
    for(ll i=1;i<n;i++)
    {
        ll q=0;
        for(ll j=0;j<=k;j++)
        {
            q+=dp[i-1][j];
            if(j>a[i])
                q-=dp[i-1][j-a[i]-1];
          q%=mod;
          q+=mod;
          q%=mod;
            dp[i][j]=q;
        }
    }
    cout<<dp[n-1][k];
}

Measured memory_bytes: 78336
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    ll n; cin >> n;
    map<ll,ll> map_;
    rep(i,n){
        ll a; cin >> a;
        map_[a]++;
    }
    ll ans = 0;
    for(auto itr = map_.begin(); itr != map_.end(); itr++){
        if((*itr).second & 1)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6528
#include <iostream>

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

	b = a / 3600;
	std::cout << b << ":";
	a = a - (b * 3600);
	b = a / 60;
	std::cout << b << ":";
	b = a - (b * 60);
	std::cout << b << std::endl;
}


Measured memory_bytes: 3096