akhauriyash/Code-Regression huggingface dataset:
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
      ArrayList<String> s = nextCharArray();
      ArrayList<String> t = nextCharArray();
      if(s.get(0).equals(t.get(2)) && s.get(1).equals(t.get(1)) && s.get(2).equals(t.get(0))){
        myout("YES");
      }else{
        myout("NO");
      }
	}
	//Method addition frame start



	//Method addition frame end
}


Measured memory_bytes: 33152
def main():
    n, m, q = map(int, input().split())
    a = [0] * q
    b = [0] * q
    c = [0] * q
    d = [0] * q
    for i in range(q):
        a[i], b[i], c[i], d[i] = map(int, input().split())

    def cal(A):
        ans = 0
        for ai, bi, ci, di in zip(a, b, c, d):
            if A[bi-1] - A[ai-1] == ci:
                ans += di
        return ans

    def dfs(A):
        if len(A) == n:
            return cal(A)
        res = 0
        pre = A[-1] if len(A) > 0 else 1
        for i in range(pre, m+1):
            A.append(i)
            res = max(dfs(A), res)
            A.pop()
        return res

    print(dfs([]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 9240
n,m = map(int,input().split())
X = list(map(int,input().split()))
X.sort()

X_diff = [X[i+1]-X[i] for i in range(m-1)]
X_diff.sort(reverse=True)

if n >= m:
    print(0)
else:
    print(X[-1] - X[0] - sum(X_diff[:n-1]))

Measured memory_bytes: 57384
#include <stdio.h>
#define MAX 45
 
int answer(int);
int fib[MAX];
 
int main(){
  int x;
 
  scanf("%d" ,&x);
  printf("%d\n" ,answer(x));
  return 0;
}
 
int answer(int x){
  if(fib[x] > 0){
    return fib[x];
  }

  if(x <= 1){
    return 1;
  }

  else{
    return fib[x] = answer(x-1) + answer(x-2);
  }
}

Measured memory_bytes: 596
#include <stdio.h>

int main() {
    int i,j;
    int N = 0;
    int count=0;
    int temp;
    int data[110];

    scanf("%d",&N);
    for (i = 0; i < N; ++i){
        scanf("%d",&data[i]);
    }

    for(i = 0; i < N ; i++){
        for(j = N - 1; j > i ; --j) {
            if (data[j] < data[j - 1]) {
                temp = data[j];
                data[j] = data[j - 1];
                data[j - 1] = temp;
                ++count;
            }
        }
    }
    for(i = 0; i < N-1; ++i){
        printf("%d ",data[i]);
    }
    printf("%d",data[N-1]);
    putchar('\n');
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 2140
D, N = map(int,input().split())

def f(x):
  if x % 100 != 0:
    return 0
  else:
    return f(x // 100) + 1

cnt = 0
i = 1
while True:
    if f(i) == D:
        cnt += 1
        if cnt == N:
            ans = i
            break
    i += 1

 
print(ans)

Measured memory_bytes: 3060
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# --------------------------------------------

dp = None

def main():
    N = int(input())
    S = input()

    ans = 0

    div = 1
    while div < len(S) - 1:
        front, rear = set(list(S[:div])), set(list(S[div:]))
        kind = len(front & rear)

        ans = max(ans, kind)

        div += 1

    print(ans)

main()


Measured memory_bytes: 4928
fun main(){
    var (n, k) = readLine()!!.split(" ").map { it.toLong() }
    val a = intArrayOf(0) + readLine()!!.split(" ").map { it.toInt() }.toIntArray()
    var m = a[1]
    var mm = a[a[1]]
    while(m != mm){
        m = a[m]
        mm = a[a[mm]]
    }
    var lambda = 0L
    var first = 1
    while (first != m){
        first = a[first]
        m = a[m]
        lambda++
    }
    m = a[first]
    mm = a[a[first]]
    var myu = 1L
    while(m != mm){
        m = a[m]
        mm = a[a[mm]]
        myu++
    }
    if(k >= lambda){
        k -= lambda
        repeat((k % myu).toInt()){
            m = a[m]
        }
    }else{
        m = 1
        repeat(k.toInt()){
            m = a[m]
        }
    }

    println(m)
}

Measured memory_bytes: 64748
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 55);

int main(){
  int n;
  cin >> n;
  bool ok = true;
  int pt = 0, px = 0, py = 0;
  while (n--) {
    int t, x, y;
    cin >> t >> x >> y;
    int dt = t - pt, dx = abs(x - px), dy = abs(y - py);
    ok &= ((dt >= dx + dy) && (dt % 2 == (dx + dy) % 2));
    pt = t, py = y, px = x;
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long A,B,Q,s[100002],t[100002],i,j,k,x,c,d,ans,INF=1e18;
main(){
  cin>>A>>B>>Q;
  for(i=1;i<=A;i++)cin>>s[i];
  s[0]=-INF;s[A+1]=INF;
  for(i=1;i<=B;i++)cin>>t[i];
  t[0]=-INF;t[B+1]=INF;
  for(i=0;i<Q;i++){
    cin>>x;
    c=lower_bound(s,s+A+2,x)-s;
    d=lower_bound(t,t+B+2,x)-t;
    ans=INF;
    for(j=c-1;j<c+1;j++){
      for(k=d-1;k<d+1;k++){
        ans=min(ans,abs(x-s[j])+abs(s[j]-t[k]));
        ans=min(ans,abs(x-t[k])+abs(t[k]-s[j]));
      }
    }
    cout<<ans<<endl;
  }
}


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

using namespace std;
map<string,int> mp={};
signed main(){
  long long n , ans=0 ,a=0;
  string t;
  cin>>n;
  for(int i=0;i<n;i++){
	cin>>t;
    for(int j=0;j<t.size()-1;j++){
      for(int k=j+1;k<t.size();k++){
        if(t[k] > t[j]){
          swap(t[k],t[j]);
        }
      }
    }
    ans+=mp[t];
    mp[t]++;
  }
  
  cout<<ans<<endl;
  return(0);
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
using Graph = vector<vector<int>>;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}

vector<bool> prime_table(int n){
    vector<bool> prime(n+1,true) ;

    prime.at(0) = false ;
    prime.at(1) = false ;

    for(int i=2;i*i<=n;i++){
        if(prime.at(i)){
            int j = i+i ;
            while(j<=n){
                prime.at(j) = false ;
                j += i ;
            }
        }
    }

    return prime ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<bool> isprime = prime_table(100000+1) ;
  vector<int> sum(100000+1) ;
  sum[0] = 0 ;
  for(int i=1;i<100000+1;i++){
    if(isprime[i] && isprime[(i+1)/2]){
      sum[i] = sum[i-1]+1 ;
    }
    else{
      sum[i] = sum[i-1] ;
    }
  }
  int q ;
  cin >> q ;
  REP(i,q){
    int l, r ;
    cin >> l >> r ;
    cout << sum[r]-sum[l-1] <<endl ;
  }
    
  
  
  
  return 0 ;
}




Measured memory_bytes: 1024
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

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())

n = ni()
xy = []
for _ in range(n):
    x,y = li()
    xy.append((x,y))
    
exist = True
    
eo = (xy[0][0]+xy[0][1]) % 2
for x,y in xy[1:]:
    if (x+y)%2 != eo:
        exist = False
    
if not exist:
    print(-1)
    
else:
    if eo == 1:
        arms = [2**i for i in range(40)]
        print(40)
        print(*arms[::-1])
        
    else:
        arms = [1] + [2**i for i in range(39)]
        print(40)
        print(*arms[::-1])
        
    for x,y in xy:
        u,v = x-y, x+y
        ucur, vcur = 0,0
        ans = ""
        for am in arms[::-1]:
            if ucur >= u and vcur >= v:
                ucur -= am
                vcur -= am
                ans += "L"
                
            elif ucur <= u and vcur <= v:
                ucur += am
                vcur += am
                ans += "R"
                
            elif ucur >= u and vcur <= v:
                ucur -= am
                vcur += am
                ans += "U"
                
            elif ucur <= u and vcur >= v:
                ucur += am
                vcur -= am
                ans += "D"
                
        print(ans)

Measured memory_bytes: 3188
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val s = sc.next()
  val reverse = (c: Char) => if (c != '1') '1' else '0'
  println {
    Seq('1', '0').map { start =>
      s.foldLeft(start -> 0) {
          case ((c, count), next) =>
            if (c == next) (reverse(c), count + 1) else (next, count)
        }
        ._2
    }.min
  }
}


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

using namespace std;
using namespace __gnu_pbds; 
  
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int mod = (int)1e9 + 7;
const int MX = (int)1e5 + 10;

void add_self(int &x, int y){x += y; if(x >= mod) x -= mod;}
void sub_self(int &x, int y){x -= y; if(x < 0) x += mod;}
void mul(int &x, int y){x = x * 1LL * y % mod;}

int main(){

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

	string s;
	cin >> s;
	if(s == "ARC") puts("ABC");
	else puts("ARC");

	return 0;
}

Measured memory_bytes: 3640
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ n, m ] <- readInts
	ss <- map ( map pred . tail ) <$> replicateM m readInts
	ps <- readInts
	print $ length $ do
		assignment <- replicateM n [ 0, 1 ]
		let
			ks = map ( check assignment ) ss
		guard $ ps == ks
		return ()

check assignment = ( `mod` 2 ) . sum . map ( assignment !! )

Measured memory_bytes: 1020
k = int(input())

dist_string = input()
l = dist_string.split()
a = int(l[0])
b = int(l[1])

counter = 0

for number in range(a,b+1):
    if number % k == 0:
        print("OK")
        counter += 1
        break

if counter == 0:
    print("NG")


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

int main(){
    double a, b, c, d;
    while(cin >> a >> b >> c >> d, a + 1 || b + 1 || c + 1 || d + 1)
    {
        a *= M_PI / 180;
        b *= M_PI / 180;
        c *= M_PI / 180;
        d *= M_PI / 180;
        printf("%d\n", (int)(acos(cos(a) * cos(b) * cos(c) * cos(d) + cos(a) * sin(b) * cos(c) * sin(d) + sin(a) * sin(c)) * 6378.1 + 0.5));
    }
    return 0;
}

Measured memory_bytes: 1256
#โชว์การ sort ในแต่ละบรรทัด
def show (seqs):
    for i in range(len(seqs)):
        if i!=len(seqs)-1:
            print(seqs[i],end=' ')
        else :
            print(seqs[i])

num = int(input())
seqs = list(map(int,input().split()))

show(seqs) #โชว์ข้อมูลที่รับ input มา

for i in range(1,num):#วน loop เริ่มจาก 1 จนถึงจำนวนข้อมูล
    element = seqs[i] #ให้ element = ข้อมูลในตำแหน่งที่ i ซึ่ง iเป็นได้ 0ถึงจำนวนข้อมูล-1
    j = i-1 
    while (j>=0 and seqs[j]>element): #ถ้าข้อมูลตัวด้านซ้ายมีค่ามากกว่าข้อมูลที่อยู่ด้านขวา
        seqs[j+1] = seqs[j] # swap ข้อมูลที่น้อยที่สุดไปยังด้านซ้ายสุดเสมอ
        j -=1
    #ถ้าหลุด loop while ทำการเปลี่ยนขa้อมูลให้เป็นข้อมูลของตัวที่ได้สลับไปก่อนหน้านี้    
    seqs[j+1]=element
    show(seqs)



Measured memory_bytes: 5980
n = int(input())
sum1 = 0
ti = float("inf")
for i in range(n):
  a,b = map(int,input().split())
  if a > b:
    ti = min(ti,b)
  sum1 += a
if ti == float("inf"):
  print(0)
else:
  print(sum1 - ti)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
map<string,int>s;
int n,m;
vector<string>ans;
int main() {
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;i++){
        string b;
        cin>>b;
        s[b]++;
        if(s[b]>m){
            m=s[b];
            ans.clear();
            ans.pb(b);
        }else if(s[b]==m){
            ans.pb(b);
        }
    }
    sort(ans.begin(),ans.end());
    for(auto k:ans)cout<<k<<'\n';
    return 0;
}


Measured memory_bytes: 25456
N=int(input())
A=list(map(int, input().split()))
counter=[]
for num in range(len(A)):
  counter.append(0)
for num in range(len(A)):
  while A[num]%2==0:
    A[num]=A[num]/2
    counter[num]+=1
print(sum(counter))
  

Measured memory_bytes: 10164
import java.io.*;
import java.util.Scanner;
public class Main {


	public static void main(String[] args) {
		
		//int n;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i;
		for(i = 1;i <= n; i++){
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();
		if(x*x+y*y==z*z||x*x+z*z==y*y||z*z+y*y==x*x)
			System.out.println("YES");
		else 
			System.out.println("NO");
		}
			
		
		
		
		

	}

}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n,m,k,h[100000],ch[100000],a,b,c,ans,H,cost;
map<ll,ll>mp[100000];
priority_queue<P,vector<P>,greater<P>>que;
int main(void){
  cin>>n>>m>>k;
  for(int i=0;i<n;i++)cin>>h[i];
  for(int i=0;i<m;i++){
    cin>>a>>b>>c;
    a--,b--;
    mp[a][b]=c;
    mp[b][a]=c;
  }
  que.push({0,0});
  while(!que.empty()){
    auto q=que.top();
    que.pop();
    if(ch[q.S])continue;
    H=max(0LL,k-q.F);
    ch[q.S]=1;
    if(q.S==n-1){
      cost=q.F;
      break;
    }
    for(P x:mp[q.S]){
      if(h[q.S]<x.S||ch[x.F])continue;
      ll cost=q.F;
      if(H-x.S<0)cost+=x.S-H;
      else if(H-x.S>h[x.F])cost+=H-x.S-h[x.F];
      cost+=x.S;
      que.push({cost,x.F});
    }
  }
  if(ch[n-1]==0)cout<<-1<<endl;
  else cout<<h[n-1]-H+cost<<endl;
}



Measured memory_bytes: 50652
#include <bits/stdc++.h>                                                                              
using namespace std;                                                                                  
using ll = long long;                                                                                 
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }               
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }               
                                                                                                      
int main() {                                                                                          
  int n;                                                                                              
  cin >> n;                                                                                           
  vector<int> h(n);                                                                                   
  for (int i=0; i<n; i++) {                                                                           
    cin >> h[i];                                                                                      
  }                                                                                                   
  int dp[n+2]; // dp[i][j] represents min cost to i when time == j                                    
  for (int i=0; i<n; i++) {                                                                           
    dp[i] = INT_MAX;                                                                                  
  }                                                                                                   
  // dp initialization                                                                                
  dp[0] = 0;                                                                                          
  for (int i=0; i<n; i++) {                                                                           
    dp[i+1] = min(dp[i+1], dp[i]+abs(h[i]-h[i+1]));                                                   
    dp[i+2] = min(dp[i+2], dp[i]+abs(h[i]-h[i+2]));                                                   
  }                                                                                                   
  cout << dp[n-1] << endl;                                                                            
  return 0;                                                                                           
}            

Measured memory_bytes: 1024
#include <iostream>

#define MAX ((int)10010)
#define endl '\n'

using namespace std;

int DP[ MAX ], aux[ MAX ], auxV[ MAX ];

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

    int n, W, v, w, m, head, tail, now;
    cin >> n >> W;
    for(int i = 0 ; i < n ; i++){
        cin >> v >> w >> m;
        for(int k = 0 ; k < w ; k++){
            head = tail = 0;
            for(int j = 0 ; j * w + k <= W ; j++){
                now = DP[ j * w + k ] - j * v;
                while(head < tail && auxV[ tail - 1 ] <= now)
                    tail--;
                aux[ tail ] = j;
                auxV[ tail++ ] = now;
                DP[ j * w + k ] = auxV[ head ] + j * v;
                if(aux[ head ] == j - m)
                    head++;
            }
        }
    }
    cout << DP[ W ] << endl;
    return 0;
}


Measured memory_bytes: 3332
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define PB push_back
#define SP << " " <<

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;

__attribute__((constructor))
void initial(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed <<setprecision(15);
}

int binary(int bina,int K){
    int ans = 0;
    int i0 = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%K)*pow(10,i);
        bina = bina/K;
        i0 =i;
    }
    return i0+1;
}

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

    cout<<binary(N,K)<<endl;

    return 0;
}


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

long oddsolve(long a){return (a+1)/2%2;}
long solve(long a){
    if(a%2==1)return oddsolve(a);
    else return oddsolve(a+1)^(a+1);
}
int main(){
    long A,B;cin>>A>>B;
    cout<<(solve(B)^solve(A-1))<<endl;
}

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


int main() {
  int N;
  cin>>N;
  vector<int> V(N);
  rep(i,N)cin>>V[i];
  sort(V.begin(),V.end());
  double ans=V[0];
  rep(i,N-1){
    ans=(ans+V[i+1])/2;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3796
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

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

ll lcm(ll a, ll b){
    ll g = gcd(a, b);
    return a / g * b;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    a--;
    ll ac = a/c, ad = a/d, acd = a / lcm(c, d);
    ll bc = b/c, bd = b/d, bcd = b / lcm(c, d);
    ll ans = b - (bc + bd - bcd) - (a - (ac + ad - acd));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

mod = 10**9+7

n,a,b = map(int, input().split())

def comb(n, k):
    c = 1
    for i in range(n - k + 1, n + 1):
        c *= i
        c %= mod

    for i in range(1, k + 1):
        c *= pow(i, mod - 2, mod)
        c %= mod

    return c

ans = pow(2, n, mod) - 1 - comb(n, a) - comb(n, b)
print(ans % mod)


Measured memory_bytes: 9092
s = gets.chomp
q = gets.chomp.to_i

right = ''
left = ''
is_reverse = false
q.times do |i|
  t, f, c = gets.chomp.split(' ')
  if t == '1'
    is_reverse = !is_reverse
  else
    if f == '1'
      is_reverse ? right << c : left << c
    else
      is_reverse ? left << c : right << c
    end
  end
end
ans = left.reverse + s + right
# binding.pry
ans.reverse! if is_reverse

puts ans

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 100001
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;


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

    vector<int> ans(n);

    rep(re, 2) {
        int cnt = 0;
        rep(i, n) {
            if (s[i] == 'R') {
                cnt++;
            } else {
                ans[i] += cnt/2;
                ans[i-1] += (cnt+1)/2;
                cnt = 0;
            }
        }

        reverse(ans.begin(), ans.end());
        reverse(s.begin(), s.end());
        rep(i, n) {
            if(s[i] == 'R') s[i] = 'L';
            else s[i] = 'R';
        }
    }

    rep(i, n) {
        cout << ans[i] << endl;
    }
}



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

int main() {
  int N,A,B;
  cin >> N >> A >> B;
  int M = 1;

  vector<int> sum(N+1,0);
  for (int i = 1; i < N+1; i++) {
    M = i;
    while (M != 0){
      sum.at(i) += M % 10; 
      M = (M - M % 10)/10;
    }
  }
  
  long long Sum = 0;
  for (int i = 1; i < N+1; i++) {
    if (sum.at(i) >= A && sum.at(i) <= B){
      Sum += i;
    }
  }
  cout << Sum << endl;
}
  

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

int main(){
  int D, G;
  cin >> D >> G;
  int p[D], c[D];
  int psum=0;
  REP(i, D) {
    cin >>p[i] >>c[i];
    psum+=p[i];
  }
  int wmax;

  int dp[D+1][psum+1]={}; //スコア[p[i]のiまで][解いた問題数]
  for(int i=1; i<D+1; ++i){
    for(int j=1; j<psum+1; ++j){
      wmax=dp[i-1][j];
      for(int k=j-1; k>(j-p[i-1]-1); --k){
        wmax=max(wmax, dp[i-1][k] + (j-k)*100*i);
        if(k == j-p[i-1]) wmax=max(wmax, dp[i-1][k] + (j-k)*100*i + c[i-1]);
        if (k==0) break;
      }
      dp[i][j] = wmax;
    }
  }

  REP(i, psum+1) {
    if(dp[D][i] >= G){
      cout << i << endl;
      break;
    }
  }
  //REP(i, D+1){
  //  REP(j, psum+1){
  //    cout << dp[i][j] << " ";
  //  }
  //  cout <<endl;
  //}


  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

fun main (args : Array<String>) {
  val input = Scanner(System.`in`)
  
  while (input.hasNext()) {
    val N = input.nextInt()
    val a = IntArray(N)
    var sum = 0
    
    for (i in a.indices) {
      a[i] = input.nextInt()
      sum += a[i]
    }
    
    val avg = a.average()
    val avgCeil = Math.ceil(avg).toInt()
    val avgFloor = Math.floor(avg).toInt()
    var totalCostCeil = 0
    var totalCostFloor = 0
    
    for (i in a.indices) {
      var dist = avgCeil - a[i]
      totalCostCeil += dist * dist
      
      dist = avgFloor - a[i]
      totalCostFloor += dist * dist
    }
    
    println(Math.min(totalCostCeil, totalCostFloor))
  }
}

Measured memory_bytes: 40768
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}

bool cmp(pi x,pi y)
{
    return x.fi-x.si<y.fi-y.si;
}
 main()

{
    fast
    int x,y,z,n,csum=0,lft=0,rgt=0;
    cin>>x>>y>>z;
    n=x+y+z;
    vector<pi>v(n);
    vector<int>biggest_lft(n),biggest_rgt(n);
    priority_queue<int>bam,dan;
    f(i,0,n-1)
    {
        cin>>v[i].fi>>v[i].si;
        int c;
        cin>>c;
        v[i].fi-=c;
        v[i].si-=c;
        csum+=c;
    }
    sort(v.begin(),v.end(),cmp);
    f(i,0,n-1)
    {
        bam.push(-v[i].si);
        lft+=v[i].si;
        if(bam.size()>y)lft+=bam.top(),bam.pop();
        biggest_lft[i]=lft;
    }
    rf(i,n-1,0)
    {
        dan.push(-v[i].fi);
        rgt+=v[i].fi;
        if(dan.size()>x)
        {
            rgt+=dan.top();
            dan.pop();
        }
        biggest_rgt[i]=rgt;
    }
    int ses=-inf;
    f(i,y,n-x)
    {
        ses=max(ses,biggest_lft[i-1]+biggest_rgt[i]);
    }
    cout<<ses+csum<<endl;
    return 0;

}













Measured memory_bytes: 4728
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}


ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

int main(){
  int n ;cin >>n;
  bool ok=false ;
  for(int i=1 ; i<10;i++){
    for(int j=1;j<10;j++){
      if(i*j ==n){
        ok=true;
        break;
      }
    }
  }
  if(ok) cout<<"Yes"<<endl;
  else cout <<"No"<<endl;
  
}
  

Measured memory_bytes: 256
import java.util.*;
class Main {
  public static void main (String[] args) throws Exception {
    
    Scanner sc=new Scanner(System.in);
    
    long a = sc.nextLong();//解毒まずい
    long b = sc.nextLong();//解毒美味しい
    long c = sc.nextLong();//有毒美味しい
    
    long ans=0;
    
    if(a+b>=c)ans = b+c;
    else ans = a+b+1+b;
    
    System.out.println(ans);

  }
}

Measured memory_bytes: 23636
#define DEBUG 0

/**
 * File    : D.cpp
 * Author  : Kazune Takahashi
 * Created : 2019-3-30 21:18:07
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(10101010));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

const int MAX_SIZE = 1000010;
const long long MOD = 1000000007;

long long inv[MAX_SIZE];
long long fact[MAX_SIZE];
long long factinv[MAX_SIZE];

void init()
{
  inv[1] = 1;
  for (int i = 2; i < MAX_SIZE; i++)
  {
    inv[i] = ((MOD - inv[MOD % i]) * (MOD / i)) % MOD;
  }
  fact[0] = factinv[0] = 1;
  for (int i = 1; i < MAX_SIZE; i++)
  {
    fact[i] = (i * fact[i - 1]) % MOD;
    factinv[i] = (inv[i] * factinv[i - 1]) % MOD;
  }
}

long long C(int n, int k)
{
  if (n >= 0 && k >= 0 && n - k >= 0)
  {
    return ((fact[n] * factinv[k]) % MOD * factinv[n - k]) % MOD;
  }
  return 0;
}

long long power(long long x, long long n)
{
  if (n == 0)
  {
    return 1;
  }
  else if (n % 2 == 1)
  {
    return (x * power(x, n - 1)) % MOD;
  }
  else
  {
    long long half = power(x, n / 2);
    return (half * half) % MOD;
  }
}

long long gcd(long long x, long long y)
{
  return y ? gcd(y, x % y) : x;
}

int N;
ll X;
ll S[210];
ll DP[100010];

int main()
{
  init();
  cin >> N >> X;
  for (auto i = 0; i < N; i++)
  {
    cin >> S[i];
  }
  sort(S, S + N);
  fill(DP, DP + 100010, 0);
  int ind = N;
  DP[X] = 1;
  for (auto i = X; i >= 0; i--)
  {
#if DEBUG == 1
    if (i < 100)
    {
      cerr << "P[" << i << "] = " << (DP[i] * fact[N]) % MOD << endl;
    }
#endif
    while (S[ind - 1] > i)
    {
      ind--;
    }
    if (ind == 0)
    {
      break;
    }
    for (auto j = 0; j < ind; j++)
    {
      DP[i % S[j]] += (DP[i] * inv[ind]) % MOD;
      DP[i % S[j]] %= MOD;
    }
    DP[i] = 0;
  }
  ll ans = 0;
  for (auto i = 0LL; i <= X; i++)
  {
    ans += (i * DP[i]) % MOD;
    ans %= MOD;
  }
  ans *= fact[N];
  ans %= MOD;
  cout << ans << endl;
}

Measured memory_bytes: 24448
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define ll long long 
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		int a[10000]={0};
		for(int i=0;i<n;i++)
		{
			scanf("%d",&a[i]); 
		}
		sort(a,a+n);
		ll num=0;
		for(int i=0;i<n-2;i++)
		{
			for(int j=i+1;j<n-1;j++)
			{
				int sum=a[i]+a[j];
				int k=lower_bound(a+j+1,a+n,sum)-a;
//				printf("i==%d j=%d  k==%d\n",i,j,k);
				if(k!=n+1)
				{
					num+=(k-j-1);
				}
			}
		}
		printf("%d\n",num);
	}
	 
}

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

using namespace std;

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

    sort(a, a + N, greater<int>());
    int Alice = 0;
    int Bob = 0;
    for (int i = 0; i < N; ++i) {
        if (i % 2 == 0) {
            Alice += a[i];
        }
        else {
            Bob += a[i];
        }
    }
    cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<utility>
    
using namespace std;

int main()
{ 
      ios::sync_with_stdio(0);
      cin.tie(0);
      
      int i,n,cnt=0;cin>>n;
      vector<int> a(n);
      
      for(i=0;i<n;i++)
     {
         cin>>a[i];
        
         if(((i+1)%2)!=0 && (a[i]%2)!=0)
         cnt++;
    
     }
    
     cout<<cnt;

                          
     return 0;
}

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

int N, X;

long long cost(vector<long long> S, int k) {  //ゴミ捨てk回でかかるコスト
    long long cost = 5 * (S[N] - S[N - k]);
    for (int i = 1; i * k < N ; i++) {
        int j = max(N - (i + 1) * k, 0);
        cost += (2 * i + 3) * (S[N - i * k] - S[j]);
    }
    return cost + 1ll * k * X;
}

long long binary(vector<long long> S, int left, int right) {
    if (left + 2 > right) {
        return min(cost(S, left), cost(S, right));
    }
    
    int mid = (left + right) / 2;
    
    long long lcost = cost(S, left);
    long long mcost = cost(S, mid);
    long long rcost = cost(S, right);
    if (lcost <= mcost && mcost <= rcost) {
        return binary(S, left, mid);
    } else if (lcost >= mcost && mcost >= rcost) {
        return binary(S, mid, right);
    } else {
        return min(binary(S, left, mid), binary(S, mid, right));
    }
}

int main() {
    cin >> N >> X;
    vector<long long> S(N + 1, 0);   //座標の累積和
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        S[i + 1] = S[i] + x;
    }
    
    cout << binary(S, 1, N) + 1ll * N * X << endl;
}

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

using namespace std;
typedef long long ll;
int main(){
	int n,w;
	cin>>n>>w;
	int a[n],wi[n];
	for(int i=0;i<n;i++){
		cin>>a[i]>>wi[i];}
	ll dp[2][w+1];
	for(int i=0;i<w+1;i++){
		dp[0][i]=0;
		dp[1][i]=0;}
	for(int i=1;i<n+1;i++){
		for(int j=1;j<w+1;j++){
			if(i%2==1){
			if(j-a[i-1]>=0)
			dp[1][j]=max(dp[0][j],dp[0][j-a[i-1]]+wi[i-1]);
			else 
				dp[1][j]=dp[0][j];
		}
		else if(i%2==0){
			if(j-a[i-1]>=0)
			dp[0][j]=max(dp[1][j],dp[1][j-a[i-1]]+wi[i-1]);
			else 
				dp[0][j]=dp[1][j];}
		}
	}
	 cout<<max(dp[0][w],dp[1][w])<<endl;
	}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":"\n");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        #define endl "\n"
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int A, B, K;
    cin >> A >> B >> K;
    set<int> ans;
    REPF(i, A, A + K) {
        ans.insert(min(i, B));
    }
    REPF(i, B - K + 1, B + 1) {
        ans.insert(max(A, i));
    }
    FORE(x, ans) {
        cout << x << endl;
    }
    return 0;
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans=0
for i in range(N-1):
    ans+=B[A[i]-1]
    if A[i+1] == A[i]+1:
        ans+=C[A[i]-1]
    
ans+=B[A[N-1]-1]
print(ans)

Measured memory_bytes: 38516
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;
typedef vector<pii> vpii;
#define reps(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define all(g) (g).begin(),(g).end()
#define pb push_back
const int mod = 1e9 + 7;
#define INF 1<<25
/*
input case
output case
*/

string s,ans;

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

    rep(i,s.size()){
        if (s[i] == '0'){
            ans.append("0");
        }else if(s[i] == '1'){
            ans.append("1");
        }else{
            if (!ans.empty()){
                ans.erase(--ans.end());
            }
        }
    }
    cout << ans << endl;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, int> PILL;
typedef pair<ll, ll> PLL;

const int MAX_N = 1e5+5;
const int M = 1e6;
const ll INF = (ll)(1e18);
const int inf = 1e9;
const ll MOD = 1000000007LL;

void solve() {

}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    map<int, int> mp;
    int a, b, c;
    cin >> a >> b >> c;

    mp[a]++;
    mp[b]++;
    mp[c]++;

    if (mp.size() == 2) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }








    return 0;
}


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

class Main{       
   public static void main(String[] args){

      Scanner sc = new Scanner(System.in);
         
      String S = sc.next();
      
      if(S.contains("AC")){
          System.out.println("Yes");
          return;
      }else{
          System.out.println("No");
          return;
      }     
      
   }
}

Measured memory_bytes: 22228
#include<stdio.h>
#define ABS(x) (x>0?(x):(x)*-1)
#define MIN(x,y) ((x<y)?(x):(y))

int main(){
  int h,m,c;
  double dh,dm;
  scanf("%d",&h);
  while(scanf("%d:%d",&h,&m)!=EOF){
    dm=(double)m/60.0;
    dh=(dm+(double)h)/12.0;
    c=MIN(ABS(dh*360.0-dm*360.0),
	  360.0-ABS(dh*360.0-dm*360.0));
    if(c<30.0){
      printf("alert\n");
    }else if(c>=90&&c<=180){
      printf("safe\n");
    }else{
      printf("warning\n");
    }
  }
  return 0;
}

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

#define PI 3.14159265358979323846264338327950L

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK" << "\n";
            return 0;
        }
    }
    cout << "NG" << "\n";
    return 0;


}


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

using namespace std;

#define int long long

const int INF = 1e18;
const int DIM = 1e5 + 7;

int v[DIM];
int pre[DIM];


int check(int x, int n, int m)
{
	int sum = 0;
	
	for(int i = n; i >= 1 && m; i--)
	{
		int l = 1;
		int r = n;
		
		int pos = 0;
		
		while(l <= r)
		{
			int mid = (l + r) / 2;
			
			if(v[i] + v[mid] >= x)
			{
				r = mid - 1;
				pos = mid;
			}
			else
			{
				l = mid + 1;
			}
		}
		
		if(pos == 0)
			break;
		
		int dif = (n - pos + 1);
	
		if(dif > m)
			pos += (dif - m);
		
		if(pos > n)
			break;
		
		m -= (n - pos + 1);
		
		sum += pre[n] - pre[pos - 1];
		sum += (n - pos + 1) * v[i];
	}
	
	if(m == 0)
		return sum;
	
	return -1;
}

main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	string a, b;
	cin >> a >> b;
	
	cout << b << a;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
L=[0]*(10**5)
S=sum(A)
for i in A:L[i-1]+=1
for i in range(Q):
    B,C=map(int,input().split());B-=1;C-=1
    S+=((C+1)-(B+1))*L[B]
    L[C]+=L[B];L[B]=0
    print(S)

Measured memory_bytes: 20880
N,X = map(int,input().split())
src = list(map(int,input().split()))

ans = 0
for i in range(1,N):
    if src[i-1] + src[i] <= X: continue
    eat = src[i-1] + src[i] - X
    src[i] = max(0, src[i] - eat)
    ans += eat
print(ans)


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

vector<long long> p;
vector<long long> c; 

int d(int a, int b){return abs(a - b);}

int main(){
	int n; cin >> n;
	long long sum = 0;
	p.push_back(0);
	for(int i = 0; i <  n; i++){
		int tmp;
		cin >> tmp;
		sum += d(p[i], tmp);
		p.push_back(tmp);
	}
	p.push_back(0);
	sum += d(p[n], 0);
	for(int i = 1; i < n + 1; i++){
		c.push_back((long long)0 - d(p[i - 1], p[i]) - d(p[i +1], p[i]) + d(p[i - 1], p[i + 1])); 
	}
	//cout << c.size() << " " << p.size() << " " << sum << endl;
	for(int i = 0; i < n; i++){
		//cout << c[i] << endl;
		cout << (sum + c[i]) << endl;
	}
	return 0;
}

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

int main() {
  int N;
  string s;
  cin>>N>>s;
if(N%2!=0){
  cout<<"No"<<endl;
  return 0;
}
string s1=s.substr(0,N/2);
string s2=s.substr(N/2,N/2);
if(s1==s2) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
  }


Measured memory_bytes: 256
#include <iostream>
#include <string>
	int main() {
		std::string c;
		std::cin >> c;
		if (c == "a") {
			std::cout << "vowel" << std::endl;
		}
		else if (c == "i") {
			std::cout << "vowel" << std::endl;
		}
		else if (c == "u"){
			std::cout << "vowel" << std::endl;
		}
		else if (c == "e") {
			std::cout << "vowel" << std::endl;
		}
		else if (c == "o") {
			std::cout << "vowel" << std::endl;
		}
		else {
			std::cout << "consonant" << std::endl;
		}
		return 0;
	}

Measured memory_bytes: 256
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define ull       unsigned long long
#define sd(x)     scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100005
#define maxn 	  200005
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000
#define MOD		  1000000007
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main()
{
	int n;
	cin >> n;
	int ans = 0;
	for (int i=1 ; i<=n ; i++)
	{
		ans+=(n-1)/i;
//		cerr << imie(ans);
	}
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<cstring>
using namespace std;
 
int main(){

  int q, l, r, ans[100002]={0};
  bool f[100001]={false};
  cin >> q;

  for(int i=2; i<=100000; i++){
    if(!f[i]){
      for(int j=2*i; j<=100000; j+=i){
        f[j]=true;
      }
    }
  }

  for(int i=3; i<=100000; i+=2){
    if(!f[i] && !f[(i+1)/2]){
      ans[i]++;
    }
  }

  for(int i=3; i<=100000; i++){
    ans[i]+=ans[i-1];
  }

  while(q--){
    cin >> l >> r;
    cout << ans[r]-ans[l-1] << endl;
  }


  return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define int long long
string lcs(char *s1,char *s2)
{
    string s="";
    int n1=strlen(s1);
    int n2=strlen(s2);
    int dp[n1+1][n2+1];
    for(int i=0;i<=n1;i++)
    {
        for(int j=0;j<=n2;j++)
        {
            if(i==0||j==0)
            {
                dp[i][j]=0;
            }
            else if(s1[i-1]==s2[j-1])
            {
                dp[i][j]=1+dp[i-1][j-1];
            }
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
  while(n1>0&&n2>0)
  {
      if(s1[n1-1]==s2[n2-1])
      {
          s+=s1[n1-1];
      n1--;
      n2--;
      
      }
      else if(dp[n1-1][n2]>dp[n1][n2-1])
      {
          n1--;
      }
      else
      {
          n2--;
      }
  }
  reverse(s.begin(),s.end());
  return s;

    
}
int32_t main()
{
    string s1,s2,s3;
    cin>>s1>>s2;
    s3=lcs((char*)s1.c_str(),(char*)s2.c_str());
    cout<<s3;
    
}

Measured memory_bytes: 70656