akhauriyash/Code-Regression huggingface dataset:
from heapq import heappop, heappush

#input
x,y,z,k=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]

#sort
a=sorted(a,reverse=True)
b=sorted(b,reverse=True)
c=sorted(c,reverse=True)

q=[]
heappush(q,(-(a[0]+b[0]+c[0]),0,0,0))
s={(0,0,0)}

for n in range(k):
    p,h,i,j=heappop(q)
    
    if  (h+1<x) and ((h+1,i,j) not in s):
        heappush(q,(-(a[h+1]+b[i]+c[j]),h+1,i,j))
        s.add((h+1,i,j))
        
    if  (i+1<y) and ((h,i+1,j) not in s):
        heappush(q,(-(a[h]+b[i+1]+c[j]),h,i+1,j))
        s.add((h,i+1,j))
        
    if  (j+1<z) and ((h,i,j+1) not in s):
        heappush(q,(-(a[h]+b[i]+c[j+1]),h,i,j+1))        
        s.add((h,i,j+1))
        
    print(-p)

Measured memory_bytes: 4952
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;

int main () {

    int K;
    cin >> K;

    queue<long long> q;
    for (int i = 1; i <= 9; i++) {
        q.push(i);
    }

    long long val;
    for (int i = 1;; i++) {
        val = q.front();
        q.pop();
        if (i == K) {
            break;
        }

        if (val % 10 != 0) {
            q.push(10*val + (val % 10) - 1);
        }
        q.push(10*val + (val % 10));
        if (val % 10 != 9) {
            q.push(10*val + (val % 10) + 1);
        }
    }
    cout << val << endl;

    return 0;
}

Measured memory_bytes: 1792
def main():
    n = int(input())
    a = list(map(int,input().split()))
    l = [0 for i in range(n)]
    for a_i in a:
        l[a_i - 1] += 1
    all = 0
    for x in l:
        all +=  x * (x - 1) // 2
    for y in a:
        print(all - l[y - 1] + 1)


if __name__ == "__main__":
    main()


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

#define rng(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define urng(i, a, b) for(int i = int(b) - 1; i >= int(a); i--)
#define urep(i, b) urng(i, 0, b)
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed

int main() {
  int n, a, b, ans = 0;
  //string s;
  cin >> a >> b;
  //vector<int> v(n), c(n);
  //if(1) {}
  rep(i, 1100){
    if(floor(double(i) * 0.08) == a && floor(double(i) * 0.1) == b) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

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

    #define ll long long
    #define ff first
    #define ss second
    #define pb push_back
    #define vll vector<ll>
    #define mll map<ll,ll>
    #define MOD 1000000007
    #define pll pair<ll,ll>
    #define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
    int main() {
        fastio;
        int n,k;
        cin>>n>>k;
        vll v;
        for(int i=0;i<n;i++)
        {
            int x;
            cin>>x;
            v.pb(x);

        }

        sort(v.begin(),v.end());
        ll s=0;
        for(int i=0;i<n-k;i++)
           s=s+v[i];
       cout<<s<<endl;
    }

Measured memory_bytes: 2420
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

func main() {
	sc.Split(bufio.ScanWords)
	x := nextInt()
	happiness := 0
    //500円硬貨に両替した後、残りの金額を5円硬貨で両替する
	happiness += x / 500 * 1000
	x %= 500
	happiness += x / 5 * 5
	fmt.Println(happiness)
}


Measured memory_bytes: 640
n, m = map(int, input().split())
x = list(map(int, input().split()))
x=sorted(x)
y=[]
for i in range(m-1):
  y.append(x[i+1]-x[i])
y=sorted(y,reverse=True)
if m <= n:
  print(0)
else:
  print(sum(y[n-1:]))

Measured memory_bytes: 13960
import math
def is_integer(n):
    try:
        float(n)
    except ValueError:
        return False
    else:
        return float(n).is_integer()


l = int(input())
if is_integer(math.sqrt(l)):
    print(l)
else:
    for i in range(l):
        l=l-1
        if is_integer(math.sqrt(l)):
            print(l)
            break


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

int main(){
  int n,i;
  cin>>n;
  vector<int> d(n);
  for(i=0;i<n;i++){
    cin>>d.at(i);
  }
  sort(d.begin(),d.end());
  cout<<d.at(n/2)-d.at(n/2-1);
}

Measured memory_bytes: 640
import itertools

N, M = map(int, input().split())
s = [list(map(int, input().split())) for i in range(M)]
k = [s[i].pop(0) for i in range(M)]
p = list(map(int, input().split()))

#ON, OFFの全組み合わせ
c = list(itertools.product(range(2), repeat = N))

#電球の付き方がj(y)のとき電球i(x)が光るか否か
def l(x, y):
    switch_on = 0
    for i in range(k[x]):
        switch_on += c[y][s[x][i] - 1]
    if switch_on % 2 == p[x]:
        return 1
    else:
        return 0

ans = 0
for j in range(2 ** N):
    light_on = 0
    for i in range(M):
        light_on += l(i, j)
    if light_on == M:
        ans += 1
    else:
        pass

print(ans)

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

#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384


int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;} 
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}    //最大公約数
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}     //最小公倍数
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;} //コンビネーション
int nHr(int a,int b){return nCr(a+b-1,b);}       // 重複組み合わせ
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}  //階乗
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;} // a~bまでの階乗
int dsum(int x){int r=0;while(x){r+=(x%10);x/=10;}return r;}   //数字の各位の和
int dsumb(int x,int b){int r=0;while(x){r+=(x%b);x/=b;}return r;}  // b進数の各位の和？
int sankaku(int x){return ((1+x)*x)/2;} //三角数 xまでの和

//以下long long ver
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llnHr(long long a,long long b){return llnCr(a+b-1,b);}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long lldsum(long long x){long long r=0;while(x){r+=(x%10);x/=10;}return r;}
long long lldsumb(long long x,long long b){long long r=0;while(x){r+=(x%b);x/=b;}return r;}
long long llsankaku(long long x){return ((1+x)*x)/2;}

//double
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}


typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) ; for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
bool is_prime (int x){
  if (x<=1) return false ;
  for (int i=2 ; i*i<=x ; i++){
    if (x%i==0) return false ;
  }
   return true;
}

 
/*CODE START HERE*/
int main() {
  string s;
  cin >> s;
  int min_ans = 1002 ;
  forn(i,s.size()-2){
    int a,b,c;
    a = (int)(s.at(i)-'0');
    b = (int)(s.at(i+1)-'0');
    c = (int)(s.at(i+2)-'0');
    int d = 100*a + 10 * b + c ;
    min_ans = min ( abs ( d-753) , min_ans) ;
  }
  cout << min_ans << endl;
}

Measured memory_bytes: 3620
#include<iostream>
using namespace std;
main(){
  int x,y,s;
  int max;
  int t1,t2;
  while(cin >> x >> y >> s,x || y || s){
    x+=100;
    y+=100;
    max=-1;
    for(int s1=1;s1<s;s1++){
      for(int s2=1;s2<s;s2++){
	if((int)s1*x/100+(int)s2*x/100==s){
	  t1=s1*y/100;
	  t2=s2*y/100;
	  if(t1+t2>max || max==-1) max=t1+t2;
	}
      }
    }
    cout << max << endl;
  }
}

Measured memory_bytes: 1160
{-# LANGUAGE OverloadedStrings #-}
module Main where

import Data.List
import Data.Bits
import Data.Char (digitToInt)
import Control.Monad
import Debug.Trace
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust, fromMaybe)
import qualified Data.Map.Strict as M
import qualified Data.Vector.Unboxed as V
import qualified Data.Set as S


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

bcAsInt :: BC.ByteString -> Int
bcAsInt  = fst . fromJust . BC.readInt

readIntBC :: IO (Int, BC.ByteString)
readIntBC = do
    [a, b] <- BC.words <$> BC.getLine
    return (fst . fromJust . BC.readInt $ a, b)

bitSearch :: Int -> [[Bool]]
bitSearch keta = each <$> [0..2^keta - 1] where
    each :: Int -> [Bool]
    each bits = (\d -> shift bits (negate d) .&. 1 == 1) <$>  [0..(keta - 1)]

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as = let
    (fo, la) = span f as
    las = case la of
        [] -> []
        xs -> split f $ tail xs
    in
        case fo of
            [] -> las
            xs -> xs : las

fastPowerMod :: Int -> Int -> Int -> Int
fastPowerMod b 0 _ = 1
fastPowerMod b 1 modnum = b `mod` modnum
fastPowerMod b n modnum
            | even n = (fastPowerMod b (n `div` 2) modnum ^ 2) `mod` modnum
            | otherwise = (fastPowerMod b (n - 1) modnum * b) `mod` modnum

solve :: BC.ByteString -> Int
solve n = let
    numList = fmap digitToInt . BC.unpack $ n
    kanouseiList = bitSearch $ length numList - 1
    go kanousei = let
        (first:latter) = numList
        initial = (0, first)
        lst = zip kanousei latter
        inner (total, stack) (True, num) = (total + stack, num)
        inner (total, stack) (False, num) = (total, stack * 10 + num)
        (total, stack) = foldl' inner initial lst
        in
        total + stack
    in
    sum $ go <$> kanouseiList


main :: IO ()
main = do
    n <- BC.getLine
    print $ solve n




Measured memory_bytes: 892
import sys
f = sys.stdin

figures = {'A':['11','11'],
'B':['1','1','1','1'],
'C':['1111'],
'D':['01','11','10'],
'E':['110','011'],
'F':['10','11','01'],
'G':['011','110']}

def figure_in_board(figure, board):
    for i in range(len(board)):
        index = board[i].find(figure[0])
        if index != -1 and i + len(figure) <= len(board):
            for j in range(1, len(figure)):
                if index != board[i + j].find(figure[j]):
                    return False
            return True
    return False

while True:
    board = [f.readline().strip() for _ in range(8)]
    for k, v in figures.items():
        if figure_in_board(v, board):
            print(k)
            break
    
    if f.readline() == '':
        break

Measured memory_bytes: 6732
#include <bits/stdc++.h>
 
int main() {
    std::vector<int> x(5);
    for (int i = 0; i < 5; ++i) {
        std::cin >> x[i];
    }       

    const int ret =
        x[0] == 0 ? 1:
        x[1] == 0 ? 2:
        x[2] == 0 ? 3:
        x[3] == 0 ? 4:
        5;

    std::cout << ret << std::endl;
}


Measured memory_bytes: 3592
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a: u32 = read();
    let b: u32 = a*a;
    println!("{}", b);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int mod = 998244353;

const int N = 4004;
int dp[N][N];

int main(){
    string s;
    cin >>s;
    int n = s.size();

    vector<int> r,b;
    rep(i,n){
        if(s[i]=='0') rep(j,2) r.pb(i);
        else if(s[i]=='1'){
            r.pb(i);
            b.pb(i);
        }
        else rep(j,2) b.pb(i);
    }

    int R = r.size(), B = b.size();

    rep(i,R-1) r[i+1] = max(r[i+1], r[i]+1);
    rep(i,B-1) b[i+1] = max(b[i+1], b[i]+1);

    dp[0][0] = 1;
    rep(i,2*n)rep(rr,R+1)if(dp[i][rr]>0){
        int bb = i-rr;
        if(rr<R && r[rr]<=i) (dp[i+1][rr+1] += dp[i][rr]) %= mod;
        if(bb<B && b[bb]<=i) (dp[i+1][rr] += dp[i][rr]) %= mod;
    }
    cout << dp[2*n][R] << endl;
    return 0;
}


Measured memory_bytes: 60544
#include <bits/stdc++.h>
using namespace std;
#define maxn 250005
#define ll long long
#define mod 1000000007

typedef pair<double, int> P;

ll power(ll x, ll k)
{
    ll res = 1;
    while (k)
    {
        if (k & 1)
            res = res * x % mod;
        x = x * x % mod;
        k /= 2;
    }
    return res;
}
ll inv(ll x)
{
    return power(x, mod - 2);
}

const int MAX = 1000005;
bool notprime[MAX];
int first[MAX]; //first[n]為n的最小質因數
int p[MAX];
int top = 0; //質數個數
void build()
{
    for (int i = 2; i < MAX; i++)
    {
        if (!notprime[i])
        {
            first[i] = i;
            p[top] = i;
            top++;
        }
        for (int j = 0; i * p[j] < MAX && j < top; j++)
        {
            first[i * p[j]] = p[j];
            notprime[i * p[j]] = 1;
            if (i % p[j])
                continue;
            else
                break;
        }
    }
}

int n;
int a[maxn];
int cnt[MAX];

int main()
{
    build();
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int x;
        scanf("%d", &a[i]);
        x = a[i];
        while (x > 1)
        {
            int f = first[x];
            int now = 0;
            while (x % f == 0)
            {
                x /= f;
                now++;
            }

            cnt[f] = max(cnt[f], now);
        }
    }
    ll lcm = 1;
    for (int i = 1; i < MAX - 1; i++)
        lcm = lcm * power(i, cnt[i]) % mod;

    ll ans = 0;
    for (int i = 0; i < n; i++)
        ans = (ans + lcm * inv(a[i]) % mod) % mod;
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 11648
#include "iostream"
#include "math.h"
#include "algorithm"
#include "string"
#include "vector"
using namespace std;

int gcd(int a, int b) {
	if (a < b) {
		swap(a, b);
	}
	while (b) {
		int r = a % b;
		a = b;
		b = r;
	}
	return a;
}

int main() {
	int x, y;
	cin >> x >> y;
	cout << gcd(x, y) << endl;
}


Measured memory_bytes: 3084
#pragma region 
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<cstring>
#include<string>
typedef long long ll;
template <typename T>void read(T &x){x=0;char ch=getchar();ll f=1;while(!isdigit(ch)){if(ch=='-')f*=-1;ch=getchar();}while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}x*=f;}
#define IO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
#pragma endregion
const int maxn = 1e5 + 5;
int h[maxn];
vector<int> g[maxn];

int main() {
    IO;
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n;++i)
        cin >> h[i];
    while (m--) {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    int ans = 0;
    for (int i = 1; i <= n;++i) {
        int flag = 1;
        for (auto v:g[i]) {
            if (h[i]<=h[v]) {
                flag = 0;
                break;
            }
        }
        ans += (flag == 1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 9188
/*  ***  In The Name of God ... ***  */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

//#define int long long
#define all(v) v.begin() , v.end()

template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}

const int N = 300 + 10 ; 

int n , k , dp [ N ] [ N ] [ N ] ;
string s ; 

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> s >> k ;
	n = ( int ) s . size ( ) ;
	for ( int i = 0 ; i < n ; ++ i )
		dp [ i ] [ i ] [ 0 ] = 1 ;
	for ( int i = 0 ; i < n - 1 ; ++ i ) {
		if ( s [ i ] == s [ i + 1 ] )
			dp [ i ] [ i + 1 ] [ 0 ] = 2 ;
		else
			dp [ i ] [ i + 1 ] [ 1 ] = 2 , dp [ i ] [ i + 1 ] [ 0 ] = 1  ; 
	}
	for ( int want = 1 ; want <= k ; ++ want ) {
		for ( int i = 0 ; i < n ; ++ i ) { 
			smax ( dp [ i ] [ i ] [ want ] , dp [ i ] [ i ] [ want - 1 ] ) ;
			smax ( dp [ i ] [ i + 1 ] [ want ] , dp [ i ] [ i + 1 ] [ want - 1 ] ) ;
		}
	}
	for ( int sz = 3 ; sz <= n ; ++ sz ) {
		for ( int i = 0 ; i + sz - 1 < n ; ++ i ) {
			int j = i + sz - 1 ;
			int eq = ( s [ i ] == s [ j ] ) * 2 ;
			for ( int want = 0 ; want <= k ; ++ want ) {
				dp [ i ] [ j ] [ want ] = max (  { dp [ i + 1 ] [ j - 1 ] [ want ] + eq ,
								dp [ i + 1 ] [ j ] [ want ] ,
							dp [ i ] [ j - 1 ] [ want ] } ) ;
				if ( want )
					smax ( dp [ i ] [ j ] [ want ] , dp [ i + 1 ] [ j - 1 ] [ want - 1 ] + 2 ) ;
				if ( want )
					smax ( dp [ i ] [ j ] [ want ] , dp [ i ] [ j ] [ want - 1 ] ) ; 
			}
		}
	}
	int res = 0 ;
	for ( int want = 0 ; want <= k ; ++ want )
		smax ( res , dp [ 0 ] [ n - 1 ] [ want ] ) ; 
	cout << res << endl ; 
}


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

#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC optimize("-funroll-loops")
#pragma GCC target("avx,sse4")

#define mms(a,n) memset(a,0,sizeof((a)[0])*(n))
#define mmp(a,b,n) memcpy(a,b,sizeof((b)[0])*(n))
#define lowbit(x) ((x)&-(x))
#define pb push_back
#define fi first
#define se second
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define fo(i,l,r) for(register int i=l,_lim_=r;i<=_lim_;i++)
#define fd(i,r,l) for(register int i=r,_lim_=l;i>=_lim_;i--)
#define fos(i,l,r,d) for(register int i=l,_lim_=r;i<=r;i+=d)
#define fol(i,l,r) for(register ll i=l,_lim_=r;i<=_lim_;i++)
#define fdl(i,r,l) for(register ll i=r,_lim_=l;i>=_lim_;i--)
#define fosl(i,l,r,d) for(register ll i=l,_lim_=r;i<=r;i+=d)
#define Clear(a) memset(a,0,sizeof(a))
#define Copy(a,b) memcpy(a,b,sizeof(b))
#define ALL(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define sqr(x) ((x)*(x))

using namespace std;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ldb;
typedef double db;
typedef pair<int,int> pi;
typedef vector<int> VI;
typedef vector<VI> VII;

namespace Main{

const int N=105,P=1e9+7;

inline int fpow(int a,int t){
	static int r;
	for(r=1;t;t>>=1,a=(ll)a*a%P)if(t&1)r=(ll)r*a%P;
	return r;
}

int f[N][N],v[N][N];
int Solve1D(int a,int A){return a;}
int Solve2D(int a,int A,int b,int B){
	return (((ll)a*fpow(Solve1D(b,B),A/a)+(ll)b*fpow(Solve1D(a,A),B/b)-(ll)a*b)%P+P)%P;
}
int Solve3D(int a,int A,int b,int B,int c,int C){
	if(A%a||B%b||C%c)return 0;
	// trival cases
	int ae=A/a,be=B/b,ce=C/c;
	int ret=(
	((ll)a*fpow(Solve2D(b,B,c,C),ae)
	+(ll)b*fpow(Solve2D(a,A,c,C),be)
	+(ll)c*fpow(Solve2D(a,A,b,B),ce)
	-(ll)a*b*fpow(Solve1D(c,C),ae*be)
	-(ll)a*c*fpow(Solve1D(b,B),ae*ce)
	-(ll)b*c*fpow(Solve1D(a,A),be*ce)
	+(ll)a*b*c)%P+P)%P;
	// non-trival cases
	fo(i,**v=1,max(ae,be))fo(j,*v[i]=1,i)v[i][j]=(v[i-1][j-1]+v[i-1][j])%P;
	fd(i,ae,1)fd(j,be,1){
		f[i][j]=(ll)v[ae][i]*v[be][j]%P*fpow(c,(ae-i)*(be-j))%P;
		fo(k,i,ae)fo(t,j,be)if(k>i||t>j)f[i][j]=(f[i][j]-(ll)f[k][t]*v[k][i]%P*v[t][j]%P+P)%P;
		int p=fpow(b,i),q=fpow(a,j),w=((fpow(p+q-1,ce)-fpow(p,ce)-fpow(q,ce)+1)%P+P)%P;
		if(i<ae||j<be)ret=(ret+(ll)a*b*c*f[i][j]%P*w)%P;
	}
	return ret;
}

}

int a,b,c,A,B,C;

int main(){
	cin>>a>>b>>c>>A>>B>>C;
	cout<<Main::Solve3D(a,A,b,B,c,C);
	return 0;
}

Measured memory_bytes: 384
N=int(input())
dp=[ [0,0,0] for i in range(N) ]

a,b,c=map(int,input().split())
dp[0][0],dp[0][1],dp[0][2]=a,b,c
for i in range (1,N):
  a,b,c=map(int,input().split())
  da,db,dc=dp[i-1][0],dp[i-1][1],dp[i-1][2]
  dp[i][0]=max(db+a,dc+a)
  dp[i][1]=max(da+b,dc+b)
  dp[i][2]=max(da+c,db+c)
print(max(dp[-1]))

Measured memory_bytes: 22756
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007LL;
string A,B,C;
ll tk[10003];
ll pk[10003];
ll pk2[10003];
ll sk[10003];

int solve(string &X){
  if( X.size()-1 < C.size() ) return 0;
  
  pk[0] = X[0]-'0';
  for(int i=1;i<(int)X.size();i++){
    ll x = X[i] - '0';    
    pk[i] = ( pk[i-1] * 10LL + x ) % MOD;
  }
  sk[0] = X[X.size()-1] - '0';
  for(int i=1;i<(int)X.size();i++){
    ll x = X[X.size()-1-i]-'0';
    sk[i] = ( sk[i-1] + x * tk[i] ) % MOD;
  }

  ll res = 0;
  if( C == "0" ){
    res = 1;
    for(int i=2;i<=(int)X.size()-(int)C.size();i++){
      string a = X.substr(i,1);
      //    cout << "comp " << a << " " << C << endl;
      if( a > C ){
	res += ( pk[i-1] * tk[X.size()-i-C.size()] ) % MOD;
      } else {
	res += ( (pk[i-1]+MOD-1)%MOD * tk[X.size()-i-C.size()] + ( ((int)X.size()-i-(int)C.size()-1<0)?0:sk[X.size()-i-C.size()-1] ) + 1 ) % MOD;

	//cout << pk[i-1]-1 << " " << tk[X.size()-i-C.size()] << " "<< " " << (((int)X.size()-i-(int)C.size()-1<0)?1:sk[X.size()-i-C.size()-1])  << endl;     
      }
      res %= MOD;
    }
  } else {
    for(int i=1;i<=(int)X.size()-C.size();i++){
      string a = X.substr(i,C.size());
      if( a < C ){
	res += ( pk[i-1] * tk[X.size()-i-C.size()] ) % MOD;
      } else if( a > C ){
	res += ((pk[i-1]+1) * tk[X.size()-i-C.size()]) % MOD;
      } else {

	res += ( (pk[i-1] * tk[X.size()-i-C.size()])%MOD + ( ((int)X.size()-i-(int)C.size()-1<0)?0LL:sk[X.size()-i-C.size()-1] ) + 1LL ) % MOD;
      }
      res %= MOD;    
    }
  }
  //  cout << X<< endl;
  //cout << res << endl;
  return res;
}

int main(){
  cin >> B >> A >> C;
  tk[0] = 1LL;
  for(int i=1;i<=10000;i++){
    tk[i] = (tk[i-1] * 10LL) % MOD;
  }

  A = "0" + A;
  B = "0" + B;

  B[B.size()-1]--;
  for(int i=(int)B.size()-1;i>0;i--){
    if( B[i] < '0' ){
      B[i] = '9';
      B[i-1]--;
    }
    else break;
  }

  if( B[0] < '0' )
    cout << solve( A ) << endl;
  else {
    ll b = solve( B );
    ll a = solve( A );
    //cout << a << " "  << b << endl;
    cout << (a + MOD - b)%MOD << endl;
  }
}

Measured memory_bytes: 1488
#include <iostream>
#include <algorithm>
using namespace std;
 
int main() {
    int N;
  	int ans = 0;
  	int Alice = 0;
  	int Bob = 0;
  	int max = 0;
  	cin >> N;
  	int a[N];
  	for(int i = 0; i < N; ++i){
      	cin >> a[i];
  	}
  	sort(a, a + N, greater<int>());
 	for(int i = 0; i < N; ++i){
		if(i % 2 == 0) Alice += a[i];
      	else Bob += a[i];
    }
  	ans = Alice - Bob;
    cout << ans << endl;
}

Measured memory_bytes: 384
from itertools import accumulate


def main(s, k, n):
    candidate = []
    prev = "1"
    count = 0
    for char in s:
        if prev == char:
            count += 1
        else:
            candidate.append(count)
            count = 1
        prev = char

    candidate.append(count)
    if prev == "0":
        candidate.append(0)

    w = 2 * k + 1
    if len(candidate) <= w:
        return len(s)

    acc = [0] + list(accumulate(candidate))
    score = 0
    for i in range(0, len(candidate) - w + 1, 2):
        score = max(score, acc[i + w] - acc[i])

    return score


n, k = list(map(int, input().split()))
s = input()

print(main(s, k, n))

Measured memory_bytes: 8820
#include <stdio.h>

int prime[1000000];

int main(void)
{
    int n;
    int i, j;

    prime[2] = 1;
    for (i = 3; i < 1000000; i += 2){
        prime[i] = 1;
    }

    for (i = 3; i * i < 1000000; i += 2){
        if (prime[i] == 0){
            continue;
        }
        for (j = i * i; j < 1000000; j += i){
            prime[j] = 0;
        }
    }

    for (i = 3; i < 1000000; i++){
        prime[i] += prime[i - 1];
    }

    while (scanf("%d", &n) == 1){
        printf("%d\n", prime[n]);
    }

    return (0);
}

Measured memory_bytes: 4500
ENV[Z='RUBY_THREAD_VM_STACK_SIZE']||exec({Z=>?5*8},'ruby',$0)
N,M=gets.split.map &:to_i
H=Hash.new{|h,k|h[k]=[]}
M.times{a,b=gets.split.map &:to_i;H[a]<<b;H[b]<<a}
V=[1,1,1]
def r s;z=1;H[s].each{|e|!V[e]&&(V[e]=1;z+=r e)};z end
g=[r(1),r(2)].min
p N*~-N/2-g*(N-g)-M

Measured memory_bytes: 225996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
#define pi 3.141592653589793
#define mod 1000000007
#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.begin(), v.end(), greater<ll>()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;
using namespace std;
int main() {
    ll n, k;
    cin >> n;
    cin >> k;
    ll ct = 0;
    while(n) {
        ++ct;
        n /= k;
    }
    cout << ct;
}


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

int main(void) {
  int a, b;
  cin >> a >> b;
  cout << (a-1)*(b-1) << endl;
  return 0;
}


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

using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int m = n%1000;
    //int val = n-m;
    int m1 = n/1000;
    if(m>0){
        m1 = m1*1000+1000;
    }else{
       m1 = m1*1000;
    }
    cout<<m1-n<<endl;




    return 0;
}




Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
//#include<cmath>
//#include <set>
//#include <fstream>

#define ll long long int
using namespace std;

void Solve()
{
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) cout << "Yes";
    else cout << "No";
}

int main()
{
    ios_base::sync_with_stdio( false );
    cin.tie( nullptr );
    //freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
   // int t;
    //cin >> t;
    //while(t--)
    {
        Solve();
        cout << '\n';
    }
    return 0;
}



Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
  int N; cin >> N;
  long long ans = 0LL;
  vector<int> p(N);
  for(int i = 0; i < N; ++i) {
    cin >> p[i];
  }
  for(int i = 0; i < N; ++i) {
    if(p[i] == i+1) {
      swap(p[i], p[i+1]);
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
#define ll long long int
#define mod 1000000007
#define vec vector<long long int>
#define fi first
#define se second
#define pb push_back
int main()
{
    ll x, k, d;
    cin >> x >> k >> d;

    x = abs(x);
    // cout << x << endl;
    ll ans;

    ll p = x / d;
    //  cout << p;
    if (p >= k)
    {
        unsigned ll q = k * d;
        ans = x - q;
    }
    else
    {
        k = k - p;
        ll curr = x - (p * d);
        x = x - (p * d);

        ll curr1 = abs(x - d);
        //  cout << curr1 << endl;
        if (curr < curr1 && k % 2 == 0)
        {
            ans = curr;
        }
        else if (curr > curr1 && k % 2)
        {
            ans = curr1;
        }
        else if (curr > curr1 && k % 2 == 0)
        {
            ans = curr;
        }
        else
        {
            ans = curr1;
        }
    }
    cout << ans << endl;
}

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

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

    vector<int> vec(n);
    for(int i; i < n; i++){
        cin >> vec.at(i);
    }

    sort(vec.rbegin(),vec.rend());

    int ans = 0;
    for(int i; i < n; i++){
        if(i % 2 == 0){
            ans += vec.at(i);
        }else{
            ans -= vec.at(i);
        }
    }

    cout << ans << endl;

}

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

int main() {
  int a, b;
  cin >> a >> b;
  
  int c = b - a;
  
  int ans = 0;
  
  for (int i = 1; i <= c; i++) {
    ans += i;
  }
  
  cout << ans - b << endl;
  
  
  
}

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


int main(){
  
  char c;
  map<char, int> S;
  
  for(int i = 0; i < 4; i++){
    
    cin >> c;
    S[c]++;
  }
  if(S.size() == 2 && S[c] == 2){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;
int test = 0 ;
ll prefix[3005][3005];
void print_mat(int n)
{
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
			cout<<prefix[i][j]<<" ";
		cout<<endl;
	}
}
int main()
{
	ll n;
	cin>>n;

	string s;
	cin>>s;

	memset(prefix,0,sizeof(prefix));
	prefix[1][1] = 1;
	ll total[n+1]={0};
	total[1] = 1;

	for(int i=2;i<=n;i++)
	{
		if(s[i-2] =='<')
		{
			prefix[i][1] = 0;
			for(int j=2;j<=i;j++)
			{
				prefix[i][j] = (prefix[i-1][j-1]+prefix[i][j-1])%mod;
			}
			total[i] = prefix[i][i];
		}
		else
		{
			prefix[i][1] = total[i-1];
			for(int j=2;j<=i;j++)
			{
				prefix[i][j] = ((total[i-1] - prefix[i-1][j-1])+prefix[i][j-1])%mod;
			}
			total[i] = prefix[i][i];
		}
	}
	if(test) print_mat(n);

	ll ans = prefix[n][n]%mod;
	if(ans < 0) ans+=mod;
	cout<<ans<<endl;
}

Measured memory_bytes: 70784
#include<stdio.h>
#define N 100
int A[100],B[100],C[100];
int main(void){
    int n,x,y,z;
    int i,t,a,b,c;

    scanf("%d",&n);
    scanf("%d",&x);
    for(i=0;i<x;i++){
	scanf("%d",&t);
	A[--t]=1;
    }
    scanf("%d",&y);
    for(i=0;i<y;i++){
	scanf("%d",&t);
	B[--t]=1;
    }
    scanf("%d",&z);
    for(i=0;i<z;i++){
	scanf("%d",&t);
	C[--t]=1;
    }

    a=b=c=0;
    for(i=0;i<n;i++){
	if(!A[i] && C[i]) a++;
	if(B[i] && C[i]) b++;
	if(!A[i] && B[i] && C[i]) c++;
    }

    printf("%d\n",a+b-c);
    return 0;
}

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

int main()
{
  char s;
  
  scanf("%c",&s);
  
  if(s=='a'||s=='i'||s=='u'||s=='e'||s=='o')
  {
    printf("vowel\n");
  }
  else
  {
      printf("consonant\n");
  }
  
  return 0;
}
  

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll n;
  cin >> n;
  
  vector<ll> ans(n);
  
  reps1(x, ll(sqrt(n))) {
    reps1(y, ll(sqrt(n))) {
      reps1(z, ll(sqrt(n))) {
        ll tmp = x*x + y*y + z*z + x*y + y*z + z*x;
        if (tmp <= n) ans[tmp]++;
      }
    }
  }
  
  reps1(i, n+1) cout << ans[i] << endl;
  
  /*
  
  reps1(i, n+1) {
  ll ans = 0;
  reps1(x, ll(sqrt(i))) {
  reps1(y, ll(sqrt(i))) {
  ll judge = (x+y)*(x+y) - 4 * (x*x + y*y + x*y - i);
  // cout << i << " " << x << " " << y << " " << judge << endl;
  if (ll(sqrt(judge)) * ll(sqrt(judge)) != judge) continue;
  // cout << "a";
  if (-(x+y)*(x+y) + judge <= 0) continue;
  // cout << "b";
  // cout << -(x+y)*(x+y) + judge << endl;
  if ((-(x+y)*(x+y) + judge) % 2 != 0) continue;
  // cout << "c" << endl;
  ans++;
  
}
}
cout << ans << endl;
}
*/

return 0;
}


Measured memory_bytes: 3680
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int x[210000];
int y[210000];
set<int> S[210000];
int main(){
	int a,b,c;scanf("%d%d%d",&a,&b,&c);
	for(int i=0;i<c;i++){
		scanf("%d%d",x+i,y+i);
		x[i]--;y[i]--;
		S[y[i]].insert(x[i]);
	}
	for(int i=0;i<b;i++){
		S[i].insert(a);
	}

	int ret=mod;
	int ss=0;

	for(int i=0;i<b;i++){
		int nx=*(S[i].lower_bound(ss));
		if(ss+1==nx){
			ret=min(ret,nx);
			break;
		}else{
			ret=min(ret,nx);
		}
		while(1){
			if(S[i].count(ss+1)){
				i=b;break;
			}
			ss++;
			if(i<b-1&&S[i+1].count(ss)==0){
				break;
			}
		}
	}
	printf("%d\n",ret);
}


Measured memory_bytes: 30336
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int a[233333],b[233333];
int main()
{
	int n,f=0,bb=2147483647,aa;
	long long res=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
		res=res+a[i];
		if(a[i]>b[i])
		{
			if(b[i]<bb)bb=b[i];
		}
		if(a[i]!=b[i])f=1;
	}
	printf("%lld",f?res-bb:0);
	return 0;
}

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

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

	for(int i=0;i<=k;i++){
		for(int j=i;j<=k;j++){
			z = s - i - j;
			if(z <= k && z >= 0){
				++ans;
				if(i!=j)++ans;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

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

    vector<int> s1(26),t1(26);

    for(int i=0;i<s.size();i++){
        int tmps = s[i] - 'a';
        s1[tmps]++;
        int tmpt = t[i] -'a';
        t1[tmpt]++;
    }
    sort(s1.begin(),s1.end());
    sort(t1.begin(),t1.end());

    for(int i=0;i<26;i++){
        if(s1[i]!=t1[i]){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
}


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int gr[13] = {0,1,3,1,2,1,2,1,1,2,1,2,1};

    int x,y;
    Scd2(x,y);

    YesNo(gr[x] == gr[y]);

    return 0;
}



Measured memory_bytes: 256
n = int(input())
t = list(map(int, input().split())) + [0]
v = list(map(int, input().split())) + [0]
m = sum(t)*2
g = [10**10]*(m+1)
l = [(0, 0, 0)]
for x, y in zip(t, v):
  l.append((l[-1][1], l[-1][1] + x*2, y))
for x, y, c in l:
  for i in range(m + 1):
    d = c
    if i < x:
      d += (x - i)*.5
    elif y < i:
      d += (i - y)*.5
    if g[i] > d:
      g[i] = d
print(sum(g)/2)

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

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

	if ((a + b) > (c + d)) cout << "Left" << endl;
	if ((a + b) == (c + d)) cout << "Balanced" << endl;
	if ((a + b) < (c + d)) cout << "Right" << endl;

	return 0;
}

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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int zero = 0;
    int one = 0;
    for(int i=0; i<n; i++){
        if(s.at(i) == '0') zero++;
        else one++;
    }
    cout << min(zero,one) * 2 << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


const string ALERT = "alert";
const string SAFE = "safe";
const string WARNING = "warning";

string solve( string s ) {
    replace( s.begin(), s.end(), ':', ' ' );
    ISS iss( s );
    int hh, mm;
    iss >> hh >> mm;

    double ang1 = 360.0 * ( (double)hh * 60.0 + (double)mm ) / 720.0;
    double ang2 = 360.0 * (double)mm / 60.0;
    double diff = fabs( ang1 - ang2 );

    if ( diff > 180.0 ) diff = 360.0 - diff;
    if ( diff < 30.0 ) return ALERT;
    if ( diff >= 90.0 ) return SAFE;
    return WARNING;
}

int main() {
    int n;
    cin >> n;
    for ( int i = 0; i < n; ++ i ) {
        string s;
        cin >> s;
        cout << solve( s ) << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#define mp make_pair
using namespace std;
map <int,int> ma;
int n,m;
int a;
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a;
		ma[a]++;
	}
	cin>>m;
	for (int j=0;j<m;j++){
		cin>>a;
		ma[a]--;
		if (ma[a]<0){
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
	return 0;
}

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

#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;

TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM T> inline istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; return is; }
TPL<TNM V, TNM H> void resize(vector<V>& _v, const H _h) { _v.resize(_h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& _v, const H& _h, const T& ... _t) { _v.resize(_h); for (auto& __v : _v) resize(__v, _t ...); }
TPL<TNM V, TNM T> TNM enable_if<!is_class<V>::value>::type fill(vector<V>& _v, const T &_t) { std::fill(ALL(_v), _t); }
TPL<TNM V, TNM T> TNM enable_if<is_class<V>::value>::type fill(vector<V>& _v, const T &_t) { for (auto &_e : _v) fill(_e, _t); }
TPL<TNM T> inline void UNIQUE(vector<T>& _v) { sort(ALL(_v)); _v.erase(unique(ALL(_v)), _v.end()); }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(6); } } pre__;

int main(void) {
	int N;
	cin >> N;
	vector<int> W(N);
	for (int i = 0; i < N; ++i) {
		cin >> W[i];
	}
	int ans = 1000000;
	for (int t = 1; t < N; ++t) {
		int s1 = 0;
		for (int i = 1; i <= t; ++i) {
			s1 += W[i - 1];
		}
		int s2 = 0;
		for (int i = t + 1; i <= N; ++i) {
			s2 += W[i - 1];
		}
		ans = min(ans, abs(s1 - s2));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

static class P
{
    static void Main()
    {
        var hw = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var h = hw[0];
        var w = hw[1];
        var s = Enumerable.Repeat(0, h).Select(_ => Console.ReadLine()).ToArray();
        UnionFind[] columnUF = Enumerable.Repeat(0, h).Select(_ => new UnionFind(w)).ToArray();
        UnionFind[] rowUF = Enumerable.Repeat(0, w).Select(_ => new UnionFind(h)).ToArray();

        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w - 1; j++)
            {
                if (s[i][j] == '#' || s[i][j + 1] == '#') continue;
                columnUF[i].TryUnite(j, j + 1);
            }
        }

        for (int i = 0; i < w; i++)
        {
            for (int j = 0; j < h - 1; j++)
            {
                if (s[j][i] == '#' || s[j + 1][i] == '#') continue;
                rowUF[i].TryUnite(j, j + 1);
            }
        }

        int max = 0;
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if (s[i][j] != '.') continue;
                max = Max(max, columnUF[i].GetSize(j) + rowUF[j].GetSize(i));
            }
        }
        Console.WriteLine(max - 1);
    }
}


class UnionFind
{
    public int Size { get; private set; }
    public int GroupCount { get; private set; }
    List<int> Sizes;
    List<int> Parent;
    public UnionFind(int count)
    {
        Size = 0;
        GroupCount = 0;
        Parent = new List<int>(count);
        Sizes = new List<int>(count);
        ExtendSize(count);
    }
    public bool TryUnite(int x, int y)
    {
        int xp = Find(x);
        int yp = Find(y);
        if (yp == xp) return false;
        if (Sizes[xp] < Sizes[yp])
        {
            var tmp = xp;
            xp = yp;
            yp = tmp;
        }
        GroupCount--;
        Parent[yp] = xp;
        Sizes[xp] += Sizes[yp];
        return true;
    }
    public IEnumerable<int> AllRepresents => Parent.Where(x => x == Parent[x]);
    public int GetSize(int x) => Sizes[Find(x)];
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int Find(int x)
    {
        while (x != Parent[x])
        {
            Parent[x] = Parent[Parent[x]];
            x = Parent[x];
        }
        return x;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void ExtendSize(int treeSize)
    {
        if (treeSize <= Size) return;
        Parent.Capacity = treeSize;
        Sizes.Capacity = treeSize;
        while (Size < treeSize)
        {
            Parent.Add(Size);
            Sizes.Add(1);
            Size++;
            GroupCount++;
        }
    }
}

Measured memory_bytes: 92976
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define int long long
using namespace std;
int b[200005],c[200005];//b为a[i]出现的次数，c为贡献
signed main()
{
    int n;
    cin>>n;
    int *a;
    a=new int[n];
    int sum=0;
    memset(b,0,sizeof(b));
    memset(c,0,sizeof(c));
    rep(i,0,n)
    {
        cin>>a[i];
        b[a[i]]++;
    }
    rep(i,0,n)
    {
        if(b[a[i]]>=2)
        c[a[i]]=(b[a[i]]-1)*(b[a[i]])/2;
    }
    rep(i,0,200005)
    {
        sum+=c[i];
    }
    rep(i,0,n)
    {
        cout<<sum-(b[a[i]]-1)<<endl;
    }
}


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

int main(void){
    ll N, W;
    cin >> N >> W;

    ll w[N], v[N];
    rep(i, N){
        cin >> w[i] >> v[i];
    }

    ll dp[N][W+1];
    rep(i, N){
        rep(j, W+1){
            if(i == 0){
                if(j >= w[i]){
                    dp[i][j] = v[i];
                }else{
                    dp[i][j] = 0;
                }
            }else if(j < w[i]){
                dp[i][j] = dp[i-1][j];
            }else{
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
            }
        }
    }

    cout << dp[N-1][W] << endl;
    return 0;
}


Measured memory_bytes: 78336
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
 
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())

typedef long long ll;

int main() {

	ll N; cin >> N;
	vector < ll > a(N);
	REP(i,N) cin >> a[i];

	vector < ll > b = a;
	sort(b.begin(), b.end());

	int min_idx = -1;
	int max_idx = -1;
	REP(i,a.size()) {
		if (a[i] == b[0]) min_idx = i + 1;
		if (a[i] == b.back()) max_idx = i + 1;
	}

	vector < pair < int,int > > ans;
	if (abs(b[0]) > abs(b.back()) && b[0] < 0 && b.back() >= 0) {
		ans.push_back(make_pair(min_idx, 1));
		ans.push_back(make_pair(min_idx, 1));
		for (int i = N; i >= 2; i--) {
			ans.push_back(make_pair(1, i));
			ans.push_back(make_pair(1, 1));
		}
	} else if (abs(b[0]) < abs(b.back()) && b[0] < 0 && b.back() >= 0) {
		ans.push_back(make_pair(max_idx, N));
		ans.push_back(make_pair(max_idx, N));
		for (int i = 1; i < N; i++) {
			ans.push_back(make_pair(N, i));
			ans.push_back(make_pair(N, N));
		}
	} else if (b[0] < 0 && b.back() < 0) {
		ans.push_back(make_pair(min_idx, 1));
		ans.push_back(make_pair(min_idx, 1));
		for (int i = N; i >= 2; i--) {
			ans.push_back(make_pair(1, i));
			ans.push_back(make_pair(1, 1));
		}
	} else {	
		ans.push_back(make_pair(max_idx, N));
		ans.push_back(make_pair(max_idx, N));
		for (int i = 1; i < N; i++) {
			ans.push_back(make_pair(N, i));
			ans.push_back(make_pair(N, N));
		}
	}

	cout << ans.size() << endl;
	REP(i,ans.size()) {
		cout << ans[i].first << " " << ans[i].second << endl;
	}

	return 0;
}

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


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int max = 0;
        int maxn = 1;
        for (int i = 1; i <= n; i++) {
            int k = i;
            int count = 0;
            while (k % 2 == 0) {
                count++;
                k /= 2;
            }
            if (count > max) {
                max = count;
                maxn = i;
            }
        }
        System.out.println(maxn);
    }
}

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

int main() {
  int N, n, x;
  x=0;
  cin >> N;
  n=N;
  
  for(int i=0; i<9; i++){
    if(n>=10){
      x+=n%10;
      n/=10;
    }
    else{
      x+=n;
      break;
    }
  }
   if(N%x == 0){
     cout << "Yes" << endl;
   }
   else{
     cout << "No" << endl;
   }
}


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

int main() {
    int n, l;
    cin >> n >> l;
    vector<string> v(n);
    rep(i, n) cin >> v.at(i);
    sort(v.begin(), v.end());
    rep(i, n) cout << v[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 256