akhauriyash/Code-Regression huggingface dataset:
{-# OPTIONS_GHC -O2 #-}

import           Control.Applicative
import           Control.Monad
import           Control.Monad.ST
import qualified Data.ByteString.Char8       as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import           Data.Function
import           Data.Primitive.MutVar
import qualified Data.Vector                 as V
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM

main :: IO ()
main = do
    [v, e] <- map read.words <$> getLine
    edges <- U.unfoldrN e (readInt2.B.dropWhile isSpace) <$> B.getContents
    print . fromEnum . solve $ directedGraph v edges

solve :: Graph -> Bool
solve gr = hasCycle gr

------------------------------------------------------------------------------

readInt2 :: B.ByteString -> Maybe ((Int,Int), B.ByteString)
readInt2 bs = Just ((x,y),bsy)
  where
    Just (x, bsx) = B.readInt bs
    Just (y, bsy) = B.readInt $ B.unsafeTail bsx

whenM :: Monad m => m Bool -> m () -> m ()
whenM mb f = mb >>= flip when f
{-# INLINE whenM #-}

unlessM :: Monad m => m Bool -> m () -> m ()
unlessM mb f = mb >>= flip unless f
{-# INLINE unlessM #-}

type Vertex = Int
type Edge = (Int, Int)
type Graph = V.Vector (U.Vector Vertex)

directedGraph :: Int -> U.Vector Edge -> Graph
directedGraph numV edges = V.map U.fromList
    . V.unsafeAccumulate (flip (:)) (V.replicate numV [])
    $ U.convert edges

vertices :: Graph -> U.Vector Vertex
vertices gr = U.generate (V.length gr) id

hasCycle :: Graph -> Bool
hasCycle gr = runST $ do
    visited <- UM.replicate (V.length gr) False
    onStack <- UM.replicate (V.length gr) False
    res <- newMutVar False
    U.forM_ (vertices gr) $ \root ->
        unlessM (UM.unsafeRead visited root) $
            flip fix root $ \dfs v -> do
                whenM (UM.unsafeRead onStack v) $
                    writeMutVar res True
                unlessM (UM.unsafeRead visited v) $ do
                    UM.unsafeWrite visited v True
                    UM.unsafeWrite onStack v True

                    U.mapM_ dfs $ V.unsafeIndex gr v

                    UM.unsafeWrite onStack v False

    readMutVar res

Measured memory_bytes: 4156
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 1010;

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

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

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

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll dp[101010];
ll a[101010];

//long longしか使わない
//素数は1より大きい
int main() {
	ll n, x;
	cin >> n >> x;
	rep(i, n) {
		cin >> a[i];
	}
	vector<ll>box(n + 1);
	ll target = 0;
	ll ans = 0;
	for (ll i = 0;i < n - 1;++i) {
		ll res = a[i] + a[i + 1];
		if (res > x) {
			ans += min(a[i + 1], res - x);
			a[i + 1] = max(ll(0), a[i + 1] + x - res);
			res = a[i] + a[i + 1];
			if (res > x) {
				ans += res - x;
				a[i] = x;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n;
    int cnt=0;
    cin >> n;
    
    for(int i=1; i<=n; i++){
        if(i%2 == 1){
            int yakusu =0;
            for(int j=1; j<=i; j++){
            if(i%j == 0) yakusu++;
            }
            if (yakusu == 8)  cnt ++;
        }
    }

 cout << cnt << endl;
}


Measured memory_bytes: 256
#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> P;
const int INF = 1e9;

int main()
{
    int k, r;
    cin >> k >> r;
    if (k >= 10) {
        cout << r << endl;
        return 0;
    } else {
        int a = 100 * (10 - k);
        cout << r + a << endl;
        return 0;
    }

    return 0;
}

Measured memory_bytes: 256
import sys

def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    L, R, d = MI()
    ans = 0
    for i in range(L, R+1):
        if i%d==0:
            ans += 1

    

    
    print(ans)

if __name__ == "__main__":
	main()

Measured memory_bytes: 9188
import math
n = int(input())
p_list = list(map(int, [input() for _ in range(n)]))
max_p = max(p_list)
argmax_p = p_list.index(max_p)
discount_price = int(max_p / 2)
p_list[argmax_p] = discount_price
total_price = sum(p_list)
print(total_price)

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n;
    cin >> n;
    if (n == 1)
        cout << "Hello World" << endl;
    else
    {
        int a, b;
        cin >> a >> b;
        cout << a + b << endl;
    }
}


Measured memory_bytes: 256
import numpy as np
n = int(input())
l = np.array(list(map(int,input().split())))

def counter(l):
  count = 1
  nc = 'True'
  for i in l:
    if i > 0:
      nc = 'False'
    elif i <= 0 and nc == 'False':
      count += 1
      nc = 'True'
  if l[-1] <= 0:
    count -=1
  return count

ans = 0
while any([i>0 for i in l]):
  ans +=  counter(l)
  l = l - np.ones(n)
print(ans)

Measured memory_bytes: 12500
N,K=map(int,input().split())
A=list(map(int,input().split()))
visited=[0 for i in range(N)]
visited[0]=1
tour=[1]

while True:
    goto=A[tour[-1]-1]
    tour.append(goto)
    if visited[goto-1]:
        break
    visited[goto-1]=1

#print(tour)
    
before=0
shuuki=1
for i in range(len(tour)):
    if tour[i]==tour[-1]:
        before=i
        shuuki=len(tour)-i-1
        break

#print(before,shuuki)

if K<len(tour):
    print(tour[K])
else:
    K-=before
    K%=shuuki
    print(tour[before+K])

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

int main(){
	set<int> ans ;
	int n,m ;
	cin >> n >> m ;
	for(int i=1;i<=m;i++) ans.insert(i) ;
	for(int i=0;i<n;i++){
		int k ; cin >> k ;
		set<int> sub ;
		for(int j=0;j<k;j++){
			int a ; cin >> a ;
			if(ans.count(a)) sub.insert(a) ;
		}
		ans = sub ;
	}
	cout << ans.size() << endl ;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << “\t:“;for(const auto& xxx : v){std::cerr << xxx << ” “;}std::cerr << “\n”;}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << ” ” << xxx.second << “\n”;}}

//配るDP

using LL = long long;

int main() {

    int N;
    cin >> N;

    vector<vector<int>> abc(N, vector<int>(3));
    for (int i = 0; i < N; i++) for (int j = 0; j < 3; j++) cin >> abc[i][j];

    vector<vector<int>> dp(N, vector<int>(3, 0));
    for (int i = 0; i < 3; i++)dp[0][i] = abc[0][i];

    for (int i = 1; i < N; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j != k) dp[i][k] = max(dp[i][k], dp[i - 1][j] + abc[i][k]);
            }
        }
    }

    int ans = *max_element(dp[N - 1].begin(), dp[N - 1].end());
    cout << ans << endl;

    return 0;
}































Measured memory_bytes: 11136
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())


mi = min(A, B, C, D, E)

s = 0 if N % mi == 0 else 1
ans = 5 if mi > N else 4+N//mi+s
print(ans)

Measured memory_bytes: 3064
import numpy as np
import sys
sys.setrecursionlimit(100000)



def acinput():
    return list(map(int, input().split(" ")))





D,G=acinput()


s=[]
for i in range(D):
    s.append(acinput())

#s=s.reverse()

res=10**9
for i in range(2**D):
    d = list(map(int,list(bin(i)[2:].zfill(D))))
    #print(d)
    resid=False
    nquestions=0
    sm=0
    for k in range(D):                
        if d[k]==1:
            sm+=s[k][0]*(100*(k+1))+s[k][1]
            nquestions+=s[k][0]
        else:
            resid=k+1

    needs=0
    if G>sm:
        needs=np.ceil((G-sm)/(100*resid))
        if needs>=s[resid-1][0]:
            continue

    res=min(res,nquestions+needs)
    #print(res)



print(int(res))



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

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin>>n;
    ll ans=10000000000005;
    for(ll i=1;i*i<=n;i++){
        if(0==n%i){
            ll temp=max(i,n/i);
            int calc=to_string(temp).length();
            if(ans>calc){
                ans=calc;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N, K, S = read_ints()
INF = 10 ** 9
MIN = 1

ans = []
for _ in range(K):
    ans.append(S)

if S != INF:
    for _ in range(N - K):
        ans.append(INF)
else:
    for _ in range(N - K):
        ans.append(MIN)


print(*ans)


Measured memory_bytes: 6720
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repbit(n) for(ll bit=0,bit<(1<<n),bit++)
inline constexpr int intpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans*(b&1?a:1);
}
int main(){
    int n;
    cin>>n;
    vector<int> bits(n);
    vector<vector<ll>> f(n,vector<ll>(10)),p(n,vector<ll>(11));
    ll ans=-1e18;
    rep(i,0,n){
        rep(j,0,10){
            cin>>f[i][j];
        }
    }
    rep(i,0,n){
        rep(j,0,11){
            cin>>p[i][j];
        }
    }
    rep(i,0,n) rep(j,0,10) bits[i] |= (f[i][j]<<(9-j));
    rep(bit,1,(1<<10)){
        ll sum=0;
        rep(i,0,n){
            ll k=bit;
            k&=bits[i];
            sum+=p[i] [ __builtin_popcount(k)];
        }
        ans=max(ans,sum);
    }
    cout<<ans;
}

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

using namespace std;

int main(){
	string s; cin >> s;
	int l, r;
	for(int i = 0; i < s.size(); ++i){
		if(s[i] == 'A'){
			l = i;
			break;
		}
	}
	for(int i = s.size()-1; i >= 0; --i){
		if(s[i] == 'Z'){
			r = i;
			break;
		}
	}
	cout << r - l + 1 << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int mx = 1e5+5;
vector<pair<int,int> >tree[mx];
int visited[mx];
int node[mx];
void dfs(int n,int l,int p)
{
	if(n == 1)
	{
		node[n] = l;
    }
	else
	{
		if(l%2 == 0 && node[p] == 0)
		{
			node[n] = 0;
	    }
		else if(l%2 != 0 && node[p] == 1)
		{
			node[n] =0;
		}
		else
		{
			//cout<<" n "<<n<<endl;
			node[n] =1;
		}
		
	}
	visited[n] = 1;
	for(int i=0;i<tree[n].size();i++)
	{
		if(!visited[tree[n][i].first])
		{
			dfs(tree[n][i].first,tree[n][i].second,n);
		}
	}
}
main()
{
	//freopen("input.txt","rt",stdin);
	int n;
	cin>>n;
	for(int i=1;i<n;i++)
	{
		int p,q,w;
		cin>>p>>q>>w;
		tree[p].push_back(make_pair(q,w));
		tree[q].push_back(make_pair(p,w));	
	}
	dfs(1,0,1);
	for(int i=1;i<=n;i++)
	{
		cout<<node[i]<<endl;
	}
}

Measured memory_bytes: 8704
#include<stdio.h>

int main(){
	
int i,x,y,z;

for(i=1; 1; i++){
scanf("%d%d",&x,&y);
if(x==0 && y==0) break;

if(x>y){
z=x;
x=y;
y=z;	}

printf("%d %d\n",x,y);

}

return 0;

}

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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int a[100000];

int main() {
	int n,k,s; cin >> n >> k >> s;
	
	if (s == 1000000000) {
		for (int i=0;i<k;i++) a[i]=s;
		for (int i=k;i<n;i++) a[i]=1;
	} else {
		for (int i=0;i<k;i++) a[i]=s;
		for (int i=k;i<n;i++) a[i]=1000000000;
	}
	
	for (int i=0;i<n;i++) cout<<a[i]<<" \n"[i+1==n];
}


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

int main()
{
    string s;
    cin >> s;
    int i = 0, n=(int)s.size();
    while(i<n)
    {
        if(s.substr(i, 6)=="eraser")
        {
            if(i+6<n)i+=6;
            else if(i+6==n)
            {
                cout << "YES";
                return 0;
            }
        }
        else if(s.substr(i, 7)=="dreamer")
        {
            if(s.substr(i+5, 6)=="eraser" or s.substr(i+5, 5)=="erase") goto a;
            if(i+7<n)i+=7;
            else if(i+7==n)
            {
                cout << "YES";
                return 0;
            }
        }
        else if(s.substr(i, 5)=="dream" or s.substr(i, 5)=="erase")
        {
            a:
            if(i+5<n)i+=5;
            else if(i+5==n)
            {
                cout << "YES";
                return 0;
            }
        }
        else
        {
            cout << "NO";
            return 0;
        }
    }
}


Measured memory_bytes: 3760
N, sita, ue = map(int,input().split())
wa = 0
for i in range(N+1):
    # 数値を文字列に変換
    n = str(i)
    # １文字ずつ数値化し配列にする。
    array = list(map(int, n))
    # 合計値を返す
    kei = sum(array)
    if kei <=ue and kei>= sita:
        wa += i
print(wa)

Measured memory_bytes: 3188
lin = input()
l = lin.split(" ")
w = int(l[0])
h = int(l[1])
x = int(l[2])
y = int(l[3])
r = int(l[4])

def hantei(limit, me):
    if (me - r) < 0:
        return False
    elif (me + r) > limit:
        return False
    else:
        return True        
    
if hantei(w, x) == True and hantei(h, y) == True:
    print("Yes")
else:
    print("No")   

Measured memory_bytes: 7804
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>
using namespace std;
#define All(v) (v).begin(),(v).end()
const long long mod = 1000000007;
const long long inf = mod*mod;
const int MAXS = 114514;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
signed main(){
    int n,k;
    cin>>n>>k;
    vector<int> x(n);
    for(int i=0;i<n;i++)cin>>x[i];
    int res = 1<<30;
    for(int i=0;i<n-k+1;i++){
        int m = x[i];
        int M = x[i+k-1];
        if(m>=0)res=min(res,M);
        else if(M<=0)res=min(res,abs(m));
        else res=min({res,2*abs(m)+M,abs(m)+2*M});
    }
    cout<<res<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n;
    cin >> n;
    vector<int> v(n), u(n+1, -1);
    for (auto &&i : v) scanf("%d", &i);
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if(u[v[i]-1] == -1) u[v[i]] = 1;
        else u[v[i]] = u[v[i]-1] + 1;
        ans = max(ans, u[v[i]]);
    }
    cout << n-ans << "\n";

    return 0;
}


Measured memory_bytes: 1792
n,m=(int(i) for i in input().split())
x=[int(i) for i in input().split()]
x.sort()
y=[x[i+1]-x[i] for i in range(m-1)]
y.sort()
ans=0
for i in range(m-1-(n-1)):
  ans+=y[i]
  
print(ans)

Measured memory_bytes: 13840
#include<bits/stdc++.h>
using namespace std;
int n,a[10002],i,j,ans=0,x,y;
int main()
{
	cin>>n;
	for(i=1;i<=n;i++)
	cin>>a[i];
	for(i=1;i<=n;i++)
	{
		sort(a,a+n+1);
	}
	for(i=n;i>=1;i-=2)
	{
		x+=a[i],y+=a[i-1];
	}
	cout<<x-y;
}

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

typedef long long LL;

template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar.size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}


int main(int argc, char const* argv[])
{
    LL n, m;
    cin >> n >> m;
    if ((n == 1) && (m == 1) ) {
        cout << 1 << endl;
    }else if ((n == 1) || (m == 1)){
        cout << n*m -2 << endl;
    }else {
        cout << n*m - 2*(m + n-2) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
// In The Name Of Allah
// Mehrkish Makuei

#include <bits/stdc++.h>

#define pb push_back
#define debug1(x) cerr << #x << " : " << x << endl;
#define debug2(x, y ) cerr << #x << " : " << x << "  " << #y << " : " << y << endl;

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef vector <ll> vll;
typedef set <char> sch;
typedef set <ll> sll;

const ll MOD = 1e9 + 7;
const ll MAXN = 1e3 + 19;

ll a, b, c, d;

int main(){
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> a >> b >> c >> d;
	cout << max( a * b, c * d ) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
using  namespace std;
template <class T>
inline void read(T &x)
{
   x=0; char c=getchar(); int f=1;
   while(!isdigit(c)){if(c=='-')f=-1; c=getchar();}
   while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=1e5+10;
int main()
{
	int flg=1,n,x;
	read(n);
	for(int i=1;i<=n;i++)
	{
		read(x);
		if(x&1) flg=0;
	}
	if(flg) printf("second");
	else printf("first");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d;
int main()
{
	cin>>a>>b>>c>>d;
	a--;
	cout<<(b-b/c-b/d+b/(c*d/__gcd(c,d)))-(a-a/c-a/d+a/(c*d/__gcd(c,d)))<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int seisu[100]={0},input,i,j,endflag=0;
	
	while(scanf("%d",&input) != EOF){
		seisu[input-1]+=1;
	}
	for(i=100;i > 0;i--){
		for(j=0;j < 100;j++){
			if(seisu[j] == i){
				printf("%d\n",j+1);
				endflag = 1;
			}
		}
		if(endflag == 1) break;
	}
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <iomanip>
#include <ios>
using namespace std;

void make(int area[15][15], int &h, int &w, int n, int count){
	h++;
	w++;
	if(h >= n) h = 0;
	if(w >= n) w = 0;
	while(area[h][w]){
		h++;
		w--;
		if(h >= n) h = 0;
		if(w < 0) w = n - 1;
	}
	area[h][w] = count;
}

int main(){
	int n;
	int area[15][15];
	while(cin >> n){
		if(n == 0) break;
		int count = 1;
		for(int i = 0; i < n; i++)
			for(int j = 0; j < n; j++)
				area[i][j] = 0;
		int h = n / 2 + 1;
		int w = n / 2;
		area[h][w] = count++;
		do{
			make(area, h, w, n, count);
			count++;
		}while(count <= n * n);
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cout << setw(4) << area[i][j];
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
N,M,Q = map(int,input().split())
X = [[0]*N for _ in range(N)]
for i in range(M):
  L,R = map(int,input().split())
  L-=1;R-=1
  X[L][R] +=1
#print(X)
S = [[0]*(N+1) for _ in range(N+1)]
for i in range(N):
  for j in range(N):
    S[i+1][j+1] = S[i][j+1] + S[i+1][j] -S[i][j] + X[i][j]
#print(S)
for i in range(Q):
  p,q = map(int,input().split())
  p-=1
  ans = S[q][q]-S[p][q]-S[q][p]+S[p][p]
  print(ans)
  



Measured memory_bytes: 20720
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

char buf[200000+10];

int main(void) {
  scanf("%s", buf);
  int len = strlen(buf);
  int bg = 0;
  int ed = 0;
  REP(i, len) {
    if(buf[i] == 'A') {
      bg = i;
      break;
    }
  }
  REP(i, len) {
    if(buf[len-i-1] == 'Z') {
      ed = len-i;
      break;
    }
  }
  printf("%d\n", ed-bg);
  
  
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
void solve(){
    int x, k, d;
    cin>>x>>k>>d;
    x=abs(x);
    int xx=x/d;
    if(xx<=k){
        k-=xx;
        if(k%2)cout<<abs(x-d*(xx+1));
        else cout<<abs(x-d*xx);
    }
    else  cout<<abs(x-d*k);
}
signed main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)solve();
}

Measured memory_bytes: 3652
import java.util.*;

public class Main{
      public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            if(a > b && a > c){
              System.out.println(b * c / 2);
            } else if(b > a && b > c){
              System.out.println(a * c / 2); 
            } else {
              System.out.println(a * b / 2);
            }
        }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef long long ll;
typedef pair<int,int>P;
#define MAX 1e9
struct edge{int to,cost;};

int H,W;
char memo[20][20];//meironokatachi
int dy[4]={0,1,0,-1};
int dx[4]={1,0,-1,0};
int bfs(int sty,int stx){
	queue<P> que;
	int d[20][20];
    rep(i,20){rep(j,20){d[i][j]=-1;}}
    que.push(P(sty,stx));
    d[sty][stx]=0;
  	int res=0;
	while(!que.empty()){
    	P p=que.front();que.pop();
      	res=max(res,d[p.first][p.second]);
    	for(int i=0;i<4;i++){
        	int ny= p.first+dy[i];
        	int nx= p.second+dx[i];
          	if(0<=ny&& ny<H&& 0<=nx&& nx<W&&memo[ny][nx]=='.'&&d[ny][nx]==-1){
            	que.push(P(ny,nx));
              	d[ny][nx]=d[p.first][p.second]+1;
            }
        }
    }
  return res;
}



int main() {
  	
    cin >>H>>W;
  	//迷路=memo
  	rep(i,H){
      rep(j,W){
        cin >>memo[i][j];
      }  
    }
  	
  	int answer=0;
    for(int i=0;i<H;i++){
     for(int j=0;j<W;j++){
      	if(memo[i][j]=='#')continue;
       	answer=max(answer,bfs(i,j));
     }
    }
    cout<<answer<<endl;
}

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

if N == 2:
  print(*(max(A),min(A)))
  exit()
  
m = max(A)/2
nearest=-1
for i in range(N):
  if abs(A[i]-m)<abs(nearest-m):
    nearest = A[i]

print(*(max(A),nearest))

Measured memory_bytes: 20128
import sys


def input(): return sys.stdin.readline().strip()


def resolve():
    s1, s2, t1, t2 = map(int, input().split())
    l = []
    yoko = t1 - s1
    tate = t2 - s2
    if yoko>0:
        a,c,f,h='R','L','L','R'
    else:
        yoko=-yoko
        a,c,f,h='L','R','R','L'
    if tate>0:
        b,d,e,g='U','D','D','U'
    else:
        tate=-tate
        b,d,e,g='D','U','U','D'
    l.append(a*yoko+b*tate+c*yoko+d*tate)
    l.append(e+a*(yoko+1)+b*(tate+1)+f)
    l.append(g+c*(yoko+1)+d*(tate+1)+h)
    print(''.join(l))
resolve()

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <iostream>

using namespace std;
typedef long long ll;

int main(){
    string in;
    int J=0,O=0,I=0,ans=0;
    
    cin >> in;
    
    for(int i=0;i<in.size();i++){
        switch (in[i]) {
            case 'J':
                if(O>0){
                    J=1;
                    O=0;
                    I=0;
                }else{
                    J++;
                }
                break;
                
            case 'O':
                if(J>0 && J>O && I==0){
                    O++;
                }else{
                    J=0;
                    O=0;
                    I=0;
                }
                break;
                
            case 'I':
                if(O>I){
                    I++;
                }else{
                    J=0;
                    O=0;
                    I=0;
                }
                break;
        }
        if(O==I)
            ans=max(ans,O);
    }
    
    printf("%d\n",ans);
    
    return 0;
}

Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007
#define sz 100005
ll inf = 1e16;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
} 
ll dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int main()
{
 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
  ll n;
  cin>>n;
  ll a[n];
  for(ll i=0;i<n;i++)
    cin>>a[i];
  ll exor=a[0];
  for(ll i=1;i<n;i++)
  {
    exor=a[i]^exor;
  }
  for(ll i=0;i<n;i++)
  {
    ll c=a[i]^exor;
    cout<<c<<" ";
  }
  cout<<'\n';
  
  return 0;
}

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

long long power(long long a, long long b,long long m) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a %m;
        a = a * a %m;
        b >>= 1;
    }
    return res;
}

vector<vector<int>> adj;

int cnt=0;
int vis[200005];
void dfs(int ver)
{
    vis[ver]=1;
    cnt++;
    for(auto i:adj[ver])
    {
        if(!vis[i])
        {
            dfs(i);
        }
    }
}


signed main()
{

ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif      

    int n,m;
    cin>>n>>m;
    int x,y;
    adj.resize(n+1);
    for(int i=0;i<m;i++)
    {
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    int mx=0;
    for(int i=1;i<=n;i++)
    {
        if(!vis[i])
        {
            cnt=0;
            dfs(i);
            mx=max(mx,cnt);
        }
    }
    cout<<mx;
}

Measured memory_bytes: 21992
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<string, ll> PS;
typedef vector<ll> V;

long long n, ans = 1;

int main(){
	cin >> n;
	FOR(i, 1, n+1)ans *= i;
	cout << ans << endl;
}

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

using namespace std;
using LL = long long;
using P = pair<int,int>;

int main(){
	int N;
	cin >> N;
	vector<int> a(N);
	rep(i,N) cin >> a[i];
	int ans=0;
	rep(i,N){
		if(i%2==0 and a[i]%2==1) ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3492
n = int(input())
a = list(map(int,input().split()))

ans = 0
yen = 1000;kabu = 0
for i in range(n-1):
    if a[i] < a[i+1]:
        kabu += yen // a[i]
        yen %= a[i]
    else:
        yen += a[i]*kabu
        kabu = 0
yen += a[-1]*kabu
print(yen)

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

int main() {
  int N;
  cin >> N;
  
  int num;
  vector<int> array;
  for(int i = 0; i < N; ++i)
  {
    cin >> num;
    array.push_back(num);
  }
  sort(array.begin(), array.end());
  reverse(array.begin(), array.end());

  int A = 0;
  int B = 0;
  for(int i = 0;i < N; ++i){
    if(0 == (i % 2)){
      A += array[i];
    }
    else{
      B += array[i];
    }
  }
  
  int rst = A - B;
  cout << rst << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	int a;
	cin >> a;
	cout << 3 * a*a << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(void)
{
	int i,len,t=0,max=0;
	char s[11];
	scanf("%s",s);
	len=strlen(s);
	for(i=0;i<len;i++){
		if((s[i]=='A' || s[i]=='T')||(s[i]=='G'||s[i]=='C'))
			t++;
		else{
			if(t>max)
				max=t;
			t=0;
		}
	}
	if(t>max)
		max=t;
	printf("%d",max);
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int inf=1<<29;
const ll Maxn=1e6;
const double pi=3.1415926536;
const ll MOD=1e6+7;

int a[Maxn];

int main(){
	int x;
	cin>>x;
	int ans=0;
	int la=1;
	for(int i=1;i<=33;i++){
		for(int j=1;j<=10;j++){
			la*=i;
			if(la<=1000 && la>0){
			ans++;
			a[ans]=la;
			}
		}
		la=i+1;
	}
	sort(a+1,a+1+ans);
	int flag=0;
	for(int i=1;i<=ans;i++){
		if(x>=a[i]) continue;
		else{
			flag=i-1;
			break;
		}
	}
	if(flag==0) printf("%d",a[ans]);
	else printf("%d",a[flag]);
}


Measured memory_bytes: 256
from collections import defaultdict as ddic, deque, Counter
from itertools import permutations, combinations, product
import bisect, heapq

rr = raw_input
rri = lambda: int(raw_input())
rrm = lambda: map(int, raw_input().split())

def solve(N, M, A, ops):
    A.sort()
    ops.sort(key = lambda z: z[1], reverse = True)
    i = 0
    for B, C in ops:
        for _ in xrange(B):
            A[i] = max(A[i], C)
            i += 1
            if i == N: return sum(A)
    return sum(A)
        

N, M = rrm()
A = rrm()
ops = [rrm() for _ in xrange(M)]
print solve(N, M, A, ops)


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

int n;
int a[20];
int dp[20*2000*+1+2000];

bool rep(int ans,int val,int pos){

    if(ans == val){
        return true;
    }
    if(pos == n){
        return false;
    }

    return rep(ans,val,pos+1) || rep(ans,val+a[pos],pos+1);

}

int main() {

    cin >> n;

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

    int q;

    cin >> q;

    int m;

    for(int i=0;i<20*2000+1;i++){
        dp[i] = 0;
    }

    for(int i=0;i<n;i++){
        for(int j=20*2000;j!=-1;j--){
            if(dp[j]!=0){
                dp[j+a[i]] = 1;
                //cout << j << endl;
            }
        }
        dp[a[i]] = 1;
    }

    for(int i=0;i<q;i++){
        cin >> m;
        if(dp[m]!=0){
            cout << "yes" << endl;
        }
        else{
            cout << "no" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3248
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;



int arr[3005][3005];
int dp[3005][3005][4];

int32_t main()
{


    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS

    int r,c,k;
    cin >> r >> c >> k;

    
    

    // dp[r][c][i] means picked i items from the row




    for(int i = 1; i <= k; i++)
    {
      int x,y,val;
      cin >> x >> y >> val;
      arr[x][y] = val;
      dp[x][y][1] = val;
    } 



    

    for(int i = 1; i <= r; i++)
    {
      for(int j = 1; j <= c; j++)
      {
        for(int k = 0; k <= 3; k++)
        {
           dp[i][j+1][k] = max(dp[i][j+1][k],dp[i][j][k]);
           if(k < 3)
           {
            dp[i][j+1][k+1] = max(dp[i][j+1][k+1],dp[i][j][k] + arr[i][j+1]);
           }
           if(i+1 <= r)
            {
              dp[i+1][j][0] = max(dp[i+1][j][0],dp[i][j][k]);
              dp[i+1][j][1] = max(dp[i+1][j][1],dp[i][j][k] + arr[i+1][j]);
            }


        }



      }
    }

    int ans = 0;

    for(int i = 0; i <= 3; i++)
    {
      ans = max(ans,dp[r][c][i]);
    }

    cout << ans;






    return 0;
}


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


#define MAX 100000

struct node{
  int p, r, l;
};

node d[MAX+1];

void pre_print(int x){
  if(x == -1) return;
  cout << " " << x;
  pre_print(d[x].l);
  pre_print(d[x].r);
}

void in_print(int x){
  if(x == -1) return;
  in_print(d[x].l);
  cout << " " << x;
  in_print(d[x].r);
}

void post_print(int x){
  if(x == -1) return;
  post_print(d[x].l);
  post_print(d[x].r);
  cout << " " << x;
}

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

  for(int i = 0; i < n; i++){
    d[i].l = -1;
    d[i].r = -1;
    d[i].p = -1;
  }

  for(int i = 0; i < n; i++){
    int id, c1, c2;
    cin >> id >> c1 >> c2;
    d[id].l = c1;
    d[id].r = c2;
    if(c1 != -1) d[c1].p = id;
    if(c2 != -1) d[c2].p = id;
  }

  int x;

  for(int i = 0; i < n; i++){
    if(d[i].p == -1) x = i;
  }


  cout << "Preorder" << endl;
  pre_print(x);
  cout << endl;
  cout << "Inorder" << endl;
  in_print(x);
  cout << endl;
  cout << "Postorder" << endl;
  post_print(x);
  cout << endl;

}

Measured memory_bytes: 1164
#import<iostream>
#import<vector>
#import<bitset>
using namespace std;main(){int n,i,m,x,y,z,w,Z,W;for(;cin>>n,n;cout<<m<<endl){vector<int>p(n*=2);vector<bitset<5001> >b(5001);for(m=i=0;i<n;b[p[i]].set(p[i+1]),i+=2)cin>>p[i]>>p[i+1];for(;n;)for(i=n-=2;i;z<0|z>5e3|w<0|w>5e3|Z<0|Z>5e3|W<0|W>5e3?0:b[z][w]&b[Z][W]?m=max(m,x*x+y*y):0)i-=2,x=p[i]-p[n],y=p[i+1]-p[n+1],z=p[n]-y,w=p[n+1]+x,Z=p[i]-y,W=p[i+1]+x;}}

Measured memory_bytes: 0
N=int(input())
numbers=[]
for _ in range(N):
    A=int(input())
    number=[]
    for _ in range(A):
        x,y=map(int,input().split())
        number.append([x,y])
    numbers.append(number)
answers=[]
for i in range(2**N):
    number=[]
    for j in range(N):
        if ((i>>j)&1):
            number.append(j+1)
    answers.append(number)
del answers[0]
ans=0
for answer in answers:
    kouho=[]
    num=0
    flag=0
    for a in answer:
        kouho+=numbers[a-1]
    for k in kouho:
        if k[1]==1 and k[0] not in answer:
            flag=1
            break
        elif k[1]==0 and k[0] in answer:
            flag=1
            break
    if flag==0:
        num=len(answer)
    ans=max(ans,num)
print(ans)



Measured memory_bytes: 80440
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 200009 /// I wanna be the wind
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
ll vet[maxn],segt[4*maxn];
void build(ll id ,ll l,ll r){
    if(l==r)segt[id]=vet[l];
    else{
        ll mid=(l+r)>>1;
        build(id<<1,l,mid);
        build(id<<1|1,mid+1,r);
        segt[id]=segt[id<<1]+segt[id<<1|1];
    }
}
void update(ll id,ll l,ll r,ll pos,ll val){
    if(l==r){
        segt[id]=val;
    }
    else{
        ll mid=(l+r)>>1;
        if(pos<=mid)update(id<<1,l,mid,pos,val);
        else update(id<<1|1,mid+1,r,pos,val);
        segt[id] = max(segt[id<<1],segt[id<<1|1]);
    }
}
ll query(ll id,ll l,ll r,ll x,ll y){
    if(l>r)return 0;
    if(x<=l && r<=y)return segt[id];
    else if(l>y || r<x)return 0;
    else{
        ll mid=(l+r)>>1;
        return max(query(id<<1,l,mid,x,y),query(id<<1|1,mid+1,r,x,y));
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    vector<ll> h(n),b(n);
    rep(i,0,n){
        cin>>h[i];
    }
    rep(i,0,n){
        cin>>b[i];
    }
    ll dp[maxn];
    memset(dp,0,sizeof dp);
    rep(i,0,n){
        dp[i] = b[i];
    }
    rep(i,0,n){
        dp[i] = max(query(1,1,n,1,h[i]-1)+b[i],dp[i]);
        update(1,1,n,h[i],dp[i]);
    }
    ll ans=0;
    rep(i,0,n+2){
        ans=max(ans,dp[i]);
    }
    cout<<ans<<'\n';
    return 0;  
}   

Measured memory_bytes: 12128
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    int k, q;
    cin >> k >> q;
    ll d[k]; for (auto &di:d) cin >> di;
    ll n[q], x[q], m[q];
    for (int i=0; i<q; i++) cin >> n[i] >> x[i] >> m[i];
    ll rui[k+1];
    for (int i=0; i<q; i++) {
        rui[0] = 0;
        for (int j=0; j<k; j++) {
            rui[j+1] = rui[j] + (d[j] + m[i] - 1) % m[i] + 1;
        }
        ll last = x[i] + ((n[i]-1) / k) * rui[k] + rui[(n[i]-1) % k];
        cout << n[i] - 1 - (last / m[i] - x[i] / m[i]) << '\n';
    }
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

void QueryJ(string&);
void QueryC(string&);
void QueryE(string&);
void QueryA(string&);
void QueryP(string&);
void QueryM(string&);
bool IsNumber(const char);

int main(){
  int i, j, n;
  string data, str;

  cin >> n;

  for(i=0; i<n; ++i){
    cin >> data >> str;

    for(j=data.size()-1; j>=0; --j){
      if(data[j] == 'J') QueryJ(str);
      else if(data[j] == 'C') QueryC(str);
      else if(data[j] == 'E') QueryE(str);
      else if(data[j] == 'A') QueryA(str);
      else if(data[j] == 'P') QueryP(str);
      else if(data[j] == 'M') QueryM(str);
    }

    cout << str << endl;
  }
  return 0;
}

void QueryJ(string& str){
  char c;
  c = str[str.size()-1];
  str.erase(str.end()-1);
  str.insert(str.begin(), c);
}

void QueryC(string& str){
  char c;
  c = str[0];
  str.erase(str.begin());
  str.push_back(c);
}

void QueryE(string& str){
  string s;
  if(str.size()%2 == 0){
    copy(str.begin()+str.size()/2, str.end(), back_inserter(s));
  }else{
    copy(str.begin()+str.size()/2+1, str.end(), back_inserter(s));
    s.push_back(str[str.size()/2]);
  }
  copy(str.begin(), str.begin()+str.size()/2, back_inserter(s));
  str = s;
}

void QueryA(string& str){
  int i;
  string s;
  for(i=str.size()-1; i>=0; --i){
    s.push_back(str[i]);
  }
  str = s;
}

void QueryP(string& str){
  string::iterator i;
  i = str.begin();
  while(1){
    i = find_if(i, str.end(), IsNumber);
    if(i == str.end()) break;
    if(*i == '0') *i = '9';
    else --(*i);
    ++i;
  }
}

void QueryM(string& str){
  string::iterator i;
  i = str.begin();
  while(1){
    i = find_if(i, str.end(), IsNumber);
    if(i == str.end()) break;
    if(*i == '9') *i = '0';
    else ++(*i);
    ++i;
  }
}

bool IsNumber(const char c){
  if(c >= '0' && c <= '9')
    return true;
  else
    return false;
}

Measured memory_bytes: 0
// https://atcoder.jp/contests/practice2/tasks/practice2_a

#include <bits/stdc++.h>

using namespace std;

// template <typename T>
// class FenwickTree {
//  private:
//   std::vector<T> tree;

//  public:
//   FenwickTree(const std::size_t n) : tree(n + 1, 0) {}

//   FenwickTree(const std::vector<T> vec) : tree(vec.size() + 1) {
//     for (std::size_t i = 0; i < vec.size(); i++) {
//       add(i, vec[i]);
//     }
//   }

//   std::size_t size() const { return tree.size() - 1; }

//   void add(const std::size_t idx, const T x) {
//     for (std::size_t i = idx + 1; i < tree.size(); i += i & (~i + 1)) {
//       tree[i] += x;
//     }
//   }

//   T query(const std::size_t idx) {
//     T res = 0;
//     for (std::size_t i = idx; i != 0; i &= i - 1) {
//       res += tree[i];
//     }
//     return res;
//   }

//   T query(const std::size_t l, const std::size_t r) { return query(r) - query(l); }
// };

template <typename T>
class FenwickTree {
 private:
  std::vector<T> ft;

 public:
  FenwickTree(int sz) : ft(sz + 1, 0) {}

  void add(int idx, T x) {
    for (int i = idx + 1; i < static_cast<int>(ft.size()); i += i & -i) {
      ft[i] += x;
    }
  }

  T operator()(int idx) const {
    T res = 0;
    for (int i = idx + 1; i > 0; i -= i & -i) {
      res += ft[i];
    }
    return res;
  }
};

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int N, Q;
  std::cin >> N >> Q;
  FenwickTree<int64_t> ft(N);
  for (int i = 0; i < N; i++) {
    int a;
    std::cin >> a;
    ft.add(i, a);
  }
  for (int i = 0; i < Q; i++) {
    int t;
    std::cin >> t;
    if (t == 0) {
      int idx, x;
      std::cin >> idx >> x;
      ft.add(idx, x);
    } else {
      int l, r;
      cin >> l >> r;
      std::cout << ft(r - 1) - ft(l - 1) << '\n';
    }
  }
  return 0;
}


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

bool is(char c){return c=='A'||c=='T'||c=='G'||c=='C';}

int main(){
  string s;cin>>s;
  int i=0,ans=0;
  int sz=s.size();
  while(i<sz){
    while(i<sz&&!is(s[i]))++i;
    int cnt=0;
    while(i<sz&&is(s[i])){++i;++cnt;}
    if(cnt>ans)ans=cnt;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
use proconio::*;
use proconio::marker::{Bytes, Chars};
use std::*;

#[warn(unused_imports)]
const MOD: i128 = 100_000_007;

#[fastout]
fn main() {
    input!{
        x : usize,
        y : usize
    };
    let ans = if x * 2 <= y && x * 4 >= y && y % 2 == 0 {
        "Yes"
    } else {
        "No"
    };
    println!("{}",ans);
}


Measured memory_bytes: 2128
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int be = sc.nextInt();
		int ans = 0;
		boolean check1 = false, check2 = false;
		for(int i = 1; i < N; i++){
			int ch = sc.nextInt();
			if(be < ch) {
				if(check1 == true) ans++;
				check1 = true;
				check2 = false;
			}else if(be > ch) {
				if(check2 == true) ans++;
				check1 = false;
				check2 = true;
			}else {
				check1 = false;
				check2 = false;
			}
			be  = ch;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include "bits/stdc++.h"
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2386
#define ll long long
#define INF (1<<30)
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int N; cin >> N;
	ll ans = 0;
	vector<vector<ll>> C(N, vector<ll>(N,0));
	for (int i = 0; i < N;i++) {
		for (int j = 0; j < N;j++) {
			cin >> C[i][j];
		}
	}
	
	for (int i = 0; i < N;i++) {
		for (int j = i + 1;j < N;j++) {
			ans += min(C[i][j], C[j][i]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3200
#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define dup(x) x.erase(unique(x.begin(), x.end()),x.end())
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
// https://atcoder.jp/contests/abc172/tasks/abc172_a
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll a;
    cin >> a;
    cout << a + pow(a,2) + pow(a,3);

	return 0;
}

Measured memory_bytes: 4308
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

r,g,b,n = li()
ans = 0
for ri in range(0, n+1, r):
    for gi in range(0, n+1, g):
        if ri+gi > n:
            continue
        elif (n-ri-gi) % b:
            continue

        ans += 1

print(ans)

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

int main()
{
	int a, h, m, s;
	cin >> a;
	h = a / 3600;
	m = (a - (3600 * h)) / 60;
	s = a - (3600 * h + 60 * m);
	cout << h << ":" << m << ":" << s << endl;
	getchar();
}



Measured memory_bytes: 3084
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

//macro
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define EPS (1e-8)
#define equals(a,b)(fabs((a)-(b))<EPS)

using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvll = vector<vll>;
//func
template<typename A, typename T>void assign2d(A&arr, ll H, ll W, T t) { arr.resize(H); REP(i, H) arr[i].assign(W, t); }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); REP(i, n)os << v[i] << (i == n - 1 ? "" : " "); return os; }
template <class T = int> inline T IN() { T x; cin >> x; return x; }
template<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); /*cout << fixed << setprecision(6);*/ } } pre__;

int main() {
	int A, B;
	cin >> A >> B;
	OUT((A + B) % 24);
}

Measured memory_bytes: 256