akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define MAX 500005

void MaxHeapify(int[],int);
void BuildMaxHeap(int[]);

int n;

int main(){
  int i,A[MAX];
  scanf("%d",&n);
  for(i=1;i<=n;i++) scanf("%d",&A[i]);
  BuildMaxHeap(A);
  for(i=1;i<=n;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}

void MaxHeapify(int A[],int i){
  int l,r,Est,tmp;
  l=2*i;
  r=(2*i)+1;
  if(l<=n && A[l]>A[i]){
    Est=l;
  } else Est=i;
  if(r<=n && A[r]>A[Est]) Est=r;
  if(Est!=i){
    tmp=A[i]; 
    A[i]=A[Est];
    A[Est]=tmp;
    MaxHeapify(A,Est);
  }
}

void BuildMaxHeap(int A[]){
  int i;
  for(i=n/2;i>=1;i--) MaxHeapify(A,i);
}

Measured memory_bytes: 2552
#include <iostream>
#include <string>
#include <vector>
#include <bitset>
#include <math.h>

#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;

int main(void) {
	int ans[10050];
	for (int i = 0; i < 10050; i++) {
		ans[i] = 0;
	}
	int max = 101;
	for (int x = 1; x < max; x++) {
		for (int y = 1; y < max; y++) {
			for (int z = 1; z < max; z++) {
				int test = x * x + y * y + z * z + x * y + y * z + z * x;
				if (test < 10050) ans[test]++;
			}
		}
	}
	int N;
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3176
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n, m;
int in[5001];
bool win[5001][5001];
bool used[5001];
vector<int> to[5001];
vector<int> ans;

void dfs(int x){
	used[x] = true;
	for(auto u : to[x]){
		if(!used[u]) dfs(u);
	}
	ans.push_back(x);
}

int main(){
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int a, b;
		cin >> a >> b;
		to[a].push_back(b);
		win[a][b] = true;
		in[b]++;
	}
	for(int i = 1; i <= n; i++){
		if(in[i] == 0) dfs(i);
	}
	reverse(ans.begin(), ans.end());
	for(int i = 0; i < n; i++){
		cout << ans[i] << endl;
	}
	bool flag = false;
	for(int i = 1; i < n; i++){
		if(!win[ans[i - 1]][ans[i]]) flag = true;
	}
	cout << (flag ? 1 : 0) << endl;
	return 0;
}


Measured memory_bytes: 28400
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int N;
	int L;

	cin >> N >> L;
	vector<string> S(N);

	for (int i = 0; i < N; i++) {
		cin >> S.at(i);
	}
	
	sort(S.begin(), S.end());

	for (int i = 0; i < N; i++) {
		cout << S.at(i);
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{
    string s;
    cin >> s;
    
    int N = int(s.length());
    int g = 0;
    int win = 0;
    
    rep(i,N){
        if(s[i] == 'g'){
            if(g > 0) win++,g--;
            else g++;
        }else{
            if(g > 0) g--;
            else g++,win--;
            
        }
    }
    

    out(win);
    
    
    
    

    return 0;
}


Measured memory_bytes: 512
################AUTHOR:@electivire##############
###############CODECHEF TEMPLATE @PYTHON########

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians,gcd
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, bisect_right
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
#import pandas as pd 
import numpy as np 
import os
import datetime
import statistics
import platform 
import fractions
import decimal
# def input(): return sys.stdin.readline().strip()
# def INT(): return int(input())
# def MAP(): return map(int, input().split())
# def LIST(): return list(map(int, input().split()))
# def ZIP(n): return zip(*(MAP() for _ in range(n)))
#modd=10**9+7
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
# For getting input from input.txt file 
if __debug__ and platform.platform()=='Darwin-18.7.0-x86_64-i386-64bit':
	sys.stdin = open('input.txt', 'r')  
	  
	# Printing the Output to output.txt file 
	sys.stdout = open('out.txt', 'w') 

#--------------------MAIN FUNCTION STARTS----------------------
def main():
    s,w=map(int,input().split())
    if w>=s:
    	print("unsafe")
    else:print("safe")

if __name__ == '__main__':
    main()





















































Measured memory_bytes: 27696
#include <stdio.h>

int main(void) {
  int dice[6],i,j,upside,front,q,diceside[4];
  for(i = 0; i < 6; i++)scanf("%d",&dice[i]);
  scanf("%d",&q);

  for(i = 0; i < q; i++){
    scanf("%d %d",&upside,&front);
    if(upside == dice[0] || upside == dice[5]){
      diceside[0] = dice[1];
      diceside[1] = dice[2];
      diceside[2] = dice[4];
      diceside[3] = dice[3];
    }
    else if(upside == dice[1] || upside == dice[4]){
      diceside[0] = dice[0];
      diceside[1] = dice[3];
      diceside[2] = dice[5];
      diceside[3] = dice[2];
    }
    else{
      diceside[0] = dice[0];
      diceside[1] = dice[1];
      diceside[2] = dice[5];
      diceside[3] = dice[4]; 
    }

    if(upside <= dice[2]){
      if(front == diceside[3])printf("%d\n",diceside[0]);
      else{
        for(j = 0; j < 3; j++){
          if(diceside[j] == front)printf("%d\n",diceside[j + 1]);
        }
      }
    }
    else{
      if(front == diceside[0])printf("%d\n",diceside[3]);
      else{
        for(j = 3; j > 0; j--){
          if(diceside[j] == front)printf("%d\n",diceside[j - 1]);
        }
      }
    }
  }
  return 0;
}


Measured memory_bytes: 2084
w = int(input())
alst = list(map(int, input().split()))
INF = 10 ** 20
acc = -INF
left = []
for i in range(w):
  a = alst[i]
  if a == 0:
    acc = INF
  elif a > 0:
    acc -= 1
  elif a < 0:
    acc = min(acc - 1, -a)
  left.append(acc)

acc = -INF
right = []
for i in range(w):
  a = alst[w - i - 1]
  if a == 0:
    acc = INF
  elif a > 0:
    acc -= 1
  elif a < 0:
    acc = min(acc - 1, -a)
  right.append(acc)
right.reverse()

print(sum([max(0, min(alst[i], max(left[i], right[i]))) for i in range(w)]))



Measured memory_bytes: 20404
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }

int main(){
    string S;
    cin >> S;
    int zero=0, ichi=0;
    for(auto aaa: S){
        if(aaa=='0') zero++;
        else ichi++;
    }
    cout << min(ichi, zero)*2 << endl;
    return 0;
}


Measured memory_bytes: 3716
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
long long ans=1,n,k;
using namespace std;
int main()
{
	cin>>n>>k;
	while(n--)
	{
		long long t=min(ans,k);
		ans+=t;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
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):
  if a[i+1]-a[i]==1:
    ans=ans+c[a[i]-1]
print(sum(b)+ans)
    

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

using namespace std;
typedef long long ll;
typedef long double ld;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define pcnt __builtin_popcount
#define pcntll(x) __builtin_popcountll(x)
#define DMAX DBL_MAX;
#define IMIN INT_MIN;
#define IMAX INT_MAX;

//const ll MOD = 1e9+7;
//const ll MOD = 998244353;
//const ll MAX = 3e5+1;
//const ll INF = 1e18;
//const ld PI = acos(-1L);

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    rep(i, 5) {
        int tmp;
        in(tmp);
        if (tmp == 0) out(i+1);
    }

    return 0;
}


Measured memory_bytes: 3600
import sys
sys.setrecursionlimit(1000000)
n,u,v=map(int,input().split())
E=[[] for _ in range(n+1)]
for _ in range(n-1):
    a,b=map(int,input().split())
    E[a].append(b)
    E[b].append(a)
depth=[-1]*(n+1)
dis=[-1]*(n+1)
def dsf_1(p,d):
    depth[p]=d
    for c in E[p]:
        if depth[c]==-1:
            dsf_1(c,d+1)
dsf_1(v,0)
def dsf_2(p,d):
    dis[p]=d
    for c in E[p]:
        if dis[c]==-1:
            dsf_2(c,d+1)
dsf_2(u,0)
ans=0
for i in range(1,n+1):
    if len(E[i])==1 and i!=v:
        if dis[i]<depth[i]:
           ans=max(ans,depth[i]-1)
print(ans)

Measured memory_bytes: 98604
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Int
import Data.Foldable
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Debug.Trace

iscanl :: (Int -> a -> b -> a) -> a -> V.Vector b -> V.Vector a
iscanl !k !a !v = V.scanl' (\(!x) (!i, !v) -> k i x v) a (V.indexed v)

iscanlU
  :: (VU.Unbox a, VU.Unbox b)
  => (Int -> a -> b -> a)
  -> a
  -> VU.Vector b
  -> VU.Vector a
iscanlU !k !a !v = VU.scanl' (\(!x) (!i, !v) -> k i x v) a (VU.indexed v)

solve :: Int -> Int -> V.Vector (VU.Vector Bool) -> Int32
solve !h !w !ahw = dp V.! h VU.! (w - 1)
 where
  add !x !y = (x + y) `mod` (10 ^ 9 + 7)

  dp :: V.Vector (VU.Vector Int32)
  dp = iscanl
    ( \(!i) (!acc) (!row) -> VU.tail $ iscanlU
      (\(!j) (!prev) (!ch) -> if ch then 0 else acc VU.! j `add` prev)
      0
      row
    )
    (VU.generate w (\(!i) -> if i == 0 then 1 else 0))
    ahw

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  (h, w) <-
    (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
  ahw <-
    V.replicateM h
    $   VU.unfoldrN w (\bs -> Just (B.head bs == '#', B.tail bs))
    <$> B.getLine
  print $ solve h w ahw


Measured memory_bytes: 5884
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let [n;k;q] = reads int
    let xs = List.init q (fun _ -> read int)
    let ps = Array.create n k
    let qs = Array.create n 0

    let gs = List.countBy id xs
    for (i, j) in gs do
        qs.[i-1] <- qs.[i-1] + j

    for i = 0 to n - 1 do
        ps.[i] <- ps.[i] - (q - qs.[i])

    for i in ps do
        if i <= 0 then
            printfn "No"
        else
            printfn "Yes"

    0

Measured memory_bytes: 26056
#include <bits/stdc++.h>
using namespace std;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};

int n, m;
bool field[100][100], visited[100][100];

int rec(int i, int j){
    visited[i][j] = true;
    int res = 1;
    for(int k=0;k<4;k++){
        int ni = i+di[k], nj = j+dj[k];
        if(ni<0 || ni>=n) continue;
        if(nj<0 || nj>=m) continue;
        if(!field[ni][nj] || visited[ni][nj]) continue;
        res = max(res, rec(ni, nj)+1);
    }
    visited[i][j] = false;
    return res;
}


int main() {
    while(cin >> m >> n, n){
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                cin >> field[i][j];
            }
        }
        int ans = 0;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
               if(field[i][j]){
                   ans = max(ans, rec(i,j));
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}



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

int main() {
    //
    int num;
    int tmp;
    int cnt;
    int kekka = 0;

    cin >> num;

    vector<int> vec(num);

    cnt = 0;
    for (int i = 1; i <= num; i++) {
        //
        cin >> tmp;
        if (tmp == i) {
            cnt++;
        } else {
            vec.push_back(cnt);
            cnt = 0;
        }
    }

    if (cnt >= 0) vec.push_back(cnt);
    
    for (int i = 0; i < vec.size(); i++) kekka += (vec.at(i) + 1) / 2;

    cout << kekka;
}

Measured memory_bytes: 4736
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;
    
    string S;
    io.read(S);
    int ans = 0;
    for(int i = 0; i < S.size(); i++){
        if(S[i] == '+') ans++;
        else ans--;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2003;
int n,m,ans,f1[N][N],f2[N][N],f3[N][N],f4[N][N];
char mp[N][N];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%s",mp[i]+1);
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	if(mp[i][j]=='.')f1[i][j]=f1[i-1][j]+1,f2[i][j]=f2[i][j-1]+1;
	for(int i=n;i;i--)
	for(int j=m;j;j--)
	if(mp[i][j]=='.')f3[i][j]=f3[i+1][j]+1,f4[i][j]=f4[i][j+1]+1;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	if(mp[i][j]=='.')ans=max(ans,f1[i][j]+f2[i][j]+f3[i][j]+f4[i][j]-3);
	printf("%d\n",ans);
}

Measured memory_bytes: 66816
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 1001

int capacity[NUM],table[NUM];

int main(){

	int N;
	scanf("%d",&N);

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

	int Q;
	scanf("%d",&Q);

	int command,apple_id,num;

	for(int loop = 0; loop < Q; loop++){
		scanf("%d %d %d",&command,&apple_id,&num);

		if(command == 1){
			table[apple_id] += num;
			if(table[apple_id] > capacity[apple_id]){
				printf("%d\n",apple_id);
				return 0;
			}
		}else{
			table[apple_id] -= num;
			if(table[apple_id] < 0){
				printf("%d\n",apple_id);
				return 0;
			}
		}

	}

	printf("0\n");

	return 0;
}



Measured memory_bytes: 3224
#include<stdio.h>



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

		avg += a < 40 ? 40 : a ;
	}

	printf( "%d\n" ,avg / 5 ) ;


	return 0 ;
}

Measured memory_bytes: 1796
#include<iostream>

using namespace std;
int main()

{
char a,b;
cin>>a>>b;

if(a=='H'&&b=='H'){
    cout<<"H"<<endl;
}
else if(a=='D'&&b=='H'){
    cout<<"D"<<endl;
}

else if(a=='H'&&b=='D'){
    cout<<"D"<<endl;
}

else if(a=='D'&&b=='D'){
    cout<<"H"<<endl;
}


return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
 
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
 
        int Y = X / 500;
        int Z = (X-Y*500)/5;
 
 
 
 
 
        System.out.println( Y*1000 + Z*5 );
    }
}

Measured memory_bytes: 22868
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 10010010010010;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

int main() {
    string S;cin >> S;
    int A,B,C;
    A = count(S.begin(),S.end(),'a');
    B = count(S.begin(),S.end(),'b');
    C = count(S.begin(),S.end(),'c');
    if(abs(A - B) <= 1 && abs(A - C) <= 1 && abs(B - C) <= 1){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}


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

const int maxn = 5010, P = 1000000007;
int n, fact[maxn], p[maxn], fa[maxn], sz[maxn], f[maxn];
bool chk[maxn];

int find(int x) {
    return x == fa[x] ? x : fa[x] = find(fa[x]);
}

void unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return;
    fa[x] = y, sz[y] += sz[x];
}

int qp(int x, int y) {
    int z = 1;
    for (; y; y >>= 1, x = 1LL * x * x % P) {
        if (y & 1) z = 1LL * z * x % P;
    }
    return z;
}

int main() {
    scanf("%d", &n);
    int num = 0, cnt = 0;
    for (int i = fact[0] = 1; i <= n; i++) {
        fa[i] = i, sz[i] = 1;
        fact[i] = 1LL * i * fact[i - 1] % P;
    }
    for (int i = 1; i <= n; i++) {
        scanf("%d", &p[i]);
        if (~p[i]) unite(i, p[i]);
        else num++;
    }
    for (int i = 1; i <= n; i++) {
        if (!~p[i]) chk[find(i)] = 1;
    }
    for (int i = f[0] = 1; i <= n; i++) if (i == find(i)) {
        if (!chk[i]) { cnt++; continue; }
        for (int j = num; j; j--) {
            f[j] = (f[j] + 1LL * sz[i] * f[j - 1]) % P;
        }
    }
    int ans = 1LL * cnt * qp(n - 1, num) % P;
    f[1] = (f[1] - num + P) % P;
    for (int i = 1; i <= num; i++) {
        ans = (ans + 1LL * fact[i - 1] % P * f[i] % P * qp(n - 1, num - i)) % P;
    }
    printf("%d\n", (1LL * n * qp(n - 1, num) - ans + P) % P);
    return 0;
}

Measured memory_bytes: 3844
import java.util.*;
class Main{
  static Map<Integer,List<Integer>> graph=new HashMap<>();
  static Map<Integer,Integer> dist=new HashMap<>();
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int e=sc.nextInt();
    for(int i=0;i<e;i++){
      populate(sc.nextInt(),sc.nextInt());
    }
    Set<Integer> visited=new HashSet<>();
    int ans=0;
    for(int i:graph.keySet()){
      if(!visited.contains(i)) {
        ans=Math.max(ans,dfs(i,visited));
      }
    }
    System.out.println(ans-1);
  }
  public static int dfs(int src,Set<Integer> visited){
        if(dist.containsKey(src)) return dist.get(src);
        visited.add(src);
        int current=0;
        for(int nei:graph.getOrDefault(src,new ArrayList<>())){
            if(!visited.contains(nei)) current=Math.max(current,dfs(nei,visited));
            current=Math.max(current,dist.get(nei));
        }
    	dist.put(src,1+current);
        return 1+current;
    }
    public static void populate(int i,int j){
            graph.putIfAbsent(i,new ArrayList<>());
            graph.get(i).add(j); 
    }
}

Measured memory_bytes: 97076
n = int(input()) - 1
l = []
for i in range(n):
  l.append(list(map(int, input().split())))

for i in range(n):
  total = l[i][0] + l[i][1]
  for j in range(i+1, n):
    if total <= l[j][1]:
      total = l[j][1]
    elif total % l[j][2] >= 1:
      total += l[j][2] - (total % l[j][2])
    total += l[j][0]
  print(total)

print(0)

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

using namespace std;

int main(void) {
    long n, k;
    cin >> n >> k;
    vector<long> h(n);
    for(auto &e: h) cin >> e;
    sort(h.rbegin(), h.rend());

    long r = 0;
    for(int i=k; i<n; i++)
        r += h[i];
    cout << r << endl;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
    static int MAX = 10010017;  // (1 ≦ k ≦ n ≦ 10^7 程度)
    static int MOD = 998244353;
    static long[] fac;  // 階乗
    static long[] finv;
    static long[] inv;  // 逆元
    
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        
        int r = n - k;
        int b = k;
        
        COMinit();
        
        // ans_i: m色の玉をn個並べる時、隣り合う組で同じ色のものがi組あるパターン数
        // ex. m = 7, n = 5, i = 2;
        // -> (1-7) * (前以外) * (前以外) ... = m * (m-1)^(n-1)
        // -> 「3個は決めてしまって、2個は後から同じ色を入れる」とする
        // -> "123"なら、1の右、2の右、3の右に同じ色を入れる
        // -> 仕切りが2つでボールが2つ = n-i-1+iCi
        // -> ans_i = m * (m-1)^(n-1-i) * nCi
        
        long ans = 0;
        
        for (int i = 0; i <= k; i++) {
            long ans_i = ((long)m * modpow(m-1, n-1-i) % MOD) * nCkMOD(n-1, i);
            ans_i %= MOD;
            
            ans += ans_i;
            ans %= MOD;
            // System.out.println(nCkMOD(n, i));
        }
        System.out.println(ans);
    }
    
    // テーブルを作る前処理
    public static void COMinit() {        
        fac = new long[MAX];
        finv = new long[MAX];
        inv = new long[MAX];
        
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++){
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }
    
    // 二項係数計算(1 ≦ k ≦ n ≦ 10^7 程度)
    public static long nCkMOD(int n, int k){
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
    
    public static long modpow(long a, long n) {
        long res = 1;
        while (n > 0) {
            long tmp = n & 1;
            if (tmp > 0) res = res * a % MOD;
            a = a * a % MOD;
            n >>= 1;
        }
        return res;
    }
}

Measured memory_bytes: 271176
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    int n;
    cin >> n;

    vector<double> v(n);
    for(auto &x:v)cin >> x;

    sort(v.begin(),v.end());

    double val=0;
    for(int i=0;i<n-1;i++){
        val=(v[i]+v[i+1])/2;
        v[i+1]=val;
    }

    cout << v[n-1] << endl;

    return 0;
}


Measured memory_bytes: 3836
import numpy as np

n = int(input())
a = np.array([int(x) for x in input().split()])

aa = a[a%2 == 0]
aaa = aa[(aa%3 == 0) | (aa%5 == 0)]

if len(aa) == len(aaa):
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 20144
from bisect import bisect_left
n = int(input())
l = list(map(int,input().split()))
l.sort()

ans = 0
for i in range(n-2):
  for j in range(i+1,n-1):
   ans += bisect_left(l,l[i] + l[j]) - j - 1
print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=998244353;
const int INF=2e9;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i]; 
    sort(a.begin(),a.end());
    int ans=0;
    rep(i,k) ans+=a[i];
    cout << ans << endl;
     
    return 0;   
}

Measured memory_bytes: 3652
#include<stdio.h>
int main(void)
{
    unsigned short arr[3];
    unsigned short five_count=0;
    unsigned short seven_count=0;
    scanf("%hu%hu%hu",&arr[0],&arr[1],&arr[2]);
    for(int i=0;i<3;i++)
    {
        if(arr[i]==5)
        {
            five_count++;
        }
        if(arr[i]==7)
        {
            seven_count++;
        }
    }
    if(five_count==2 && seven_count==1)
    {
        printf("YES\n");
    }
    else
    {
        printf("NO\n");
    }
    
    return 0;
}

Measured memory_bytes: 1620
#include<stdio.h>
#include<algorithm>
#define MAX_N 200005
using namespace std;
int cnt[MAX_N],n,k,arr[MAX_N],ans,m;
int main(){
	int i,x;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++){
		scanf("%d",&x);cnt[x]++;
	}
	m=0;
	for(i=1;i<=n;i++){
		if(!cnt[i])	continue;
		arr[m++]=cnt[i];
	}
	sort(arr,arr+m);
	x=0;
	while(m>k){	ans+=arr[x++];m--;}
	printf("%d\n",ans);
	return 0;
}

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


int bubbleSort(int A[],int N){
    int sw = 0;
    bool flag = 1;
    for(int i = 0; flag;i++){
        flag = 0;
        for(int j = N - 1;j >= i + 1;j--){
            if(A[j] < A[j-1]){
                
                swap(A[j],A[j-1]);
                flag = 1;
                sw++;
            }
        }
    }
    return sw;
}

int main(){
    int A[100],N,sw;
    cin >> N;
    for(int i = 0;i < N;i++) cin >> A[i];
    
    sw = bubbleSort(A,N);
    
    for(int i = 0;i < N;i++){
        if(i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << sw << endl;
    
    return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
	bool ans = true;
	string s, t;

	// input
	cin >> s >> t;

	for (int i = 0; i < t.length(); i++) {
		if ((t[i] < 'a') || ('z' < t[i])) {
			ans = false;
			break;
		}
	}
	if (ans) {
		if (s != (t.substr(0, t.length() - 1))) {
			ans = false;
		}
	}

	// output
	cout << ( ans ? "Yes" : "No" );
	cout << endl;

	return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    ll n,m,x;
    cin >> n >> m >> x;
    vector<ll> price(n,0);
    vector<vector<ll>> rikaido(n,vector<ll>(m,0));
    rep(i,n){
        cin >> price[i];
        rep(j,m)cin >> rikaido[i][j];
    }
    //bit全探索
    ll res = LONG_LONG_MAX;
    bool b = 0;
    for(int bit = 0;bit < (1LL << n);bit++){
        ll p = 0;
        vector<ll> ri(m,0);
        for(int i = 0;i<n;i++){
            if(bit & (1 << i)){
                p += price[i];
                for(int j = 0;j<m;j++)ri[j] += rikaido[i][j];
            }
        }
        bool c = 1;
        for(auto a : ri)if(a < x){
            c = 0;
            break;
        }
        if(c){
            res = min(res,p);
            b = 1;
        }
    }
    if(b)cout << res << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<string> s(2);
	while(cin>>s[0]>>s[1]) {
		ll N=s[0].size()+s[1].size();
		string ans;
		REP(i, s[0].size()) {
			REP(j, 2) if(i<s[j].size()) ans.PB(s[j][i]);
		}
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
def resolve():
    n, k = map(int, input().split())
    a = [int(x) - 1 for x in input().split()]
    dist = [-1] * n
    dist[0] = 0
    now = 0
    road = [0]
    while True:
        nxt = a[now]
        if dist[nxt] < 0:
            dist[nxt] = dist[now] + 1
            now = nxt
            road.append(now)
        else:
            first = dist[now] + 1
            roop = first - dist[nxt]
            break
    if k < first:
        print(road[k] + 1)
        return
    k -= first - roop
    k %= roop
    print(road[first - roop + k] + 1)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 32336
import sys


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


def resolve():
    s1, s2, t1, t2 = map(int, input().split())
    l = []
    x = t1 - s1
    y = t2 - s2
    ans='R'*x+'U'*y+'L'*x+'D'*y
    ans+='D'+'R'*(x+1)+'U'*(y+1)+'L'
    ans+='U'+'L'*(x+1)+'D'*(y+1)+'R'
    print(ans)
resolve()

Measured memory_bytes: 3060
int a[114514];
//int a[1145141919];
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    cout<<a[n-1]-a[0]<<endl;
}

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

int main () {
  int N;
  cin >> N;
  
  string ans = "No";
  bool a = false;
  if (N <= 81) {
    for (int i = 1; i <= 9; i++) {
      for (int j = 1; j <= 9; j++) {
        if (i*j == N) {
          ans = "Yes";
          a = true;
          break;
        }
      }
      if (a) {
        break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int N;string s;
    cin>>N>>s;
    string ans[4]={"SS","SW","WS","WW"};
    rep(i,1,N) REP(j,4){
        if(s[i]=='o'){
            if(ans[j][i]=='S') ans[j].push_back(ans[j][i-1]);
            else ans[j].push_back(ans[j][i-1]=='S'?'W':'S');
        }
        else{
            if(ans[j][i]=='S') ans[j].push_back(ans[j][i-1]=='S'?'W':'S');
            else ans[j].push_back(ans[j][i-1]);
        }
    }
    REP(i,4) if(ans[i][0]==ans[i][N]){
        if(ans[i][0]=='S'){
            if(s[0]=='o'&&ans[i][1]!=ans[i][N-1]) continue;
            if(s[0]=='x'&&ans[i][1]==ans[i][N-1]) continue; 
        }
        if(ans[i][0]=='W'){
            if(s[0]=='o'&&ans[i][1]==ans[i][N-1]) continue;
            if(s[0]=='x'&&ans[i][1]!=ans[i][N-1]) continue;
        }
        ans[i].pop_back();
        cout<<ans[i]<<endl;
        return 0;
    }
    cout<<-1<<endl;
}


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

#define A_MAX 10000

int main() {
	int n, m, a[A_MAX], sum = 0;
	cin >> n >> m;
	for (int i = 0;i < m;i++) {
		cin >> a[i];
		sum += a[i];
	}
	if (n - sum >= 0) {
		cout << n - sum;
	}
	else {
		cout << -1;
	}
}

Measured memory_bytes: 3232
#n個の都市を好きな都市から出発してすべての都市を１度だけ訪れる最短時間
#全ての都市の組i,jについてi,jを結ぶ道がある

import itertools
n=int(input())
A=[]
for i in range(n):
  A.append(list(map(int,input().split())))
  
def kaijo(x):
  if x==1:
    return x
  return x*kaijo(x-1)

def dist(x,y):
  return ((A[x][0]-A[y][0])**2+(A[x][1]-A[y][1])**2)**(1/2)

DIST=[[0 for i in range(n)] for j in range(n)]
for i in range(n):
  for j in range(n):
    DIST[i][j]=dist(i,j)
    
ans=[]   
for Q in itertools.permutations([i for i in range(n)]):
  t=0
  for i in range(n-1):
    t+=DIST[Q[i]][Q[i+1]]
  ans.append(t)
  
print(sum(ans)/kaijo(n))


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

int main(){
    int N, K, x[100];
    cin >> N >> K;

    for (int i=0; i<N; i++) cin >> x[i];

    int sum=0;

    for (int i=0; i<N; i++){
        if((K-x[i]) > x[i]) sum += 2*x[i];
        else sum += 2*(K-x[i]);
    }

    cout << sum << endl;
}

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

#define MAX 100

void initialize(void);
int isEmpty(void);
int isFull(void);
int push(int);
int pop(void);

int top;
int S[MAX];

int main(){
  int x,a,b;
  char s[100];

  initialize();

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      a = pop();
      b = pop();
      push(b+a);
    } else if ( s[0] == '-' ){
      a = pop();
      b = pop();
      push(b-a);
    } else if ( s[0] == '*' ){
      a=pop();
      b=pop();
      push(b*a);
    } else {
      x = atoi(s);
      push(x);
    }
  }

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

  return 0;
}

void initialize(void){
  top = 0;
}

int isEmpty(void){

  if(top == 0){
    return 1;
  }
  else return 0;
}

int isFull(void){

  if(top > MAX - 1){
    return 1;
  }
  else return 0;
}
int push(int x){

  if(isFull()){
    fprintf(stderr,"Overflow\n");
    exit(1);  
  }
  top++;
  S[top] = x;
}

int pop(){
  if(isEmpty()){
    fprintf(stderr,"Underflow\n");
    exit(2);
  }
  top--;
  return S[top+1];
}

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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()

bool check(i64 c, i64 N, i64 M, vector<i64> A){
    i64 sum = 0;
    rep(i, N){
        i64 l = -1, r = N;
        while(r - l > 1){
            i64 mid = (r + l) / 2;
            if(A[i] + A[mid] >= c) r = mid;
            else l = mid;
        }
        sum += N - r;
    }
    return sum >= M;
}

void solve(long long N, long long M, std::vector<long long> A){
    sort(all(A));
    i64 l = -1, r = 10000000000;
    while(r - l > 1){
        i64 mid = (r + l) / 2;
        if(check(mid, N, M, A)) l = mid;
        else r = mid;
    }
    i64 b = l, cnt = 0, ans = 0;
    vector<i64> wa(N + 1);
    rep(i, N) wa[i + 1] = wa[i] + A[i];
    //cout << b << endl;
    rep(i, N){
        l = -1; r = N;
        while(r - l > 1){
            i64 mid = (r + l) / 2;
            if(A[mid] + A[i] > b) r = mid;
            else l = mid;
        }
        ans += wa[N] - wa[r] + (N - r) * A[i];
        cnt += N - r;
        //cout << l << " " <<  r << endl;
    }
    //cout << cnt << endl;
    ans += (M - cnt) * b;
    cout << ans << endl;
}

struct IoSetup {
    IoSetup() {
        // cin.tie(nullptr);
        // ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, M, std::move(A));
    return 0;
}


Measured memory_bytes: 1808
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(void){
	ll la,lb,i,j,cnt,mx,p,pp,ii;
	char a[4001],b[4001],aa[4001],bb[4001];
	while(scanf("%s",a)!=EOF){
		cin>>b;
		la=strlen(a);
		lb=strlen(b);
		if(la<=lb){
			strcpy(aa,a);
			strcpy(bb,b);
		}
		else{
			swap(la,lb);
			strcpy(bb,a);
			strcpy(aa,b);
		}
		mx=0;
//		cout<<"AAAAAAAAAAAAAAAAAAAAAAAAA"<<endl;
		for(i=1;lb-i>=0;i++){
			cnt=0;
			for(j=0;j<i;j++){
				if(bb[lb-i+j]==aa[j]) cnt++;
				else cnt=0;
				mx=max(mx,cnt);
			}
		}
		for(i=1;i<la;i++){
			cnt=0;
			for(j=0;j<lb-i;j++){
				if(aa[i+j]==bb[j]) cnt++;
				else cnt=0;
				mx=max(mx,cnt);
			}
		}
		cout<<mx<<endl;
	}
	return 0;
}


Measured memory_bytes: 3136
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    using T = tuple<int, int, char, ll, string>;
    vector<T> v(n);
    rep(i, n) {
        int a, b; char c; ll d; string e;
        cin >> a >> b >> c >> d >> e;
        v[i] = T{a, b, c, d, e};
    }
    sort(all(v));
    rep(i, n) {
        int a, b; char c; ll d; string e;
        tie(a, b, c, d, e) = v[i];
        printf("%d %d %c %lld %s\n", a, b, c, d, e.c_str());
    }
}



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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i=0;i<(n);i++)
#define rep2(i, m, n) for(int i=m;i<(n);i++)
#define rrep(i, n, m) for(int i=n;i>=(m);i--)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N;
    string S;
    cin >> N >> S;
    ll cnt = 0;
    ll ans = 1;

    for (int i = 0; i < 2 * N; ++i) {
        if (S[i] == 'W') {
            if (cnt == 0) {
                cout << 0 << endl;
                return;
            }
            if(cnt%2 == 0){
                ans *= cnt;
                ans %= MOD;
                cnt --;
            }else{
                cnt ++;
            }
        } else {
            if (cnt % 2 == 0){
                cnt ++;
            }else{
                ans *= cnt;
                ans %= MOD;
                cnt --;
            }
        }
    }

    if (cnt != 0) {
        cout << 0 << endl;
    } else {
        for (ll i = 1; i <= N; ++i) {
            ans *= i;
            ans %= MOD;
        }
        cout << ans << endl;
    }

}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}


Measured memory_bytes: 720
#include "bits/stdc++.h"
using namespace std;
#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__) << "] "

using ll = long long;

// dp[i] - TRUE if the first player wins if there are i stones remaining

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    vector<int> a(n);
    for(int& x : a) {
        scanf("%d", &x);
    }
    vector<bool> dp(k + 1);
    for(int stones = 0; stones <= k; ++stones) {
        for(int x : a) {
            if(stones >= x && !dp[stones-x]) {
                dp[stones] = true;
            }
        }
    }
    
    puts(dp[k] ? "First" : "Second");
}


Measured memory_bytes: 256
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,child,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

int main(){
  int a, b;
  cin >> a >> b;
  int ans = 0;
  if(b % a == 0){
    ans = b + a;
  }else{
    ans = b - a;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
#define rrep(i, n) for(i = n - 1; i >= 0; i--)
using namespace std;

int mod = 1000000007;
int m;
string c;
int ad[10];

void print(vector<int> perm) {
	int i;
	rep(i, c.length()) {
		int num = perm[c[i] - '0'];
		cout << num;
	}
	cout << endl;
}

signed main() {
	int i;
	
	cin >> m >> c;
	
	int p10 = 1;
	rrep(i, c.length()) {
		ad[c[i] - '0'] += p10;
		ad[c[i] - '0'] %= mod;
		p10 *= 10;
		p10 %= mod;
	}
	
	vector<int> perm;
	rep(i, 10) perm.push_back(i);
	do {
		if (c.length() >= 2 && perm[c[0] - '0'] == 0) continue;
		int res = 0;
		rep(i, 10) {
			res += ad[i] * perm[i];
			res %= mod;
		}
		if (res == m) { print(perm); return 0; }
	} while (next_permutation(perm.begin(), perm.end()));
	
	cout << -1 << endl;
	return 0;
}


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

//Constants
const long long INF = std::numeric_limits<long long>::max();
const long long MOD = 1e9 + 7;
const long double PI = 3.141592653589793;

//MACROS
#define pb push_back
#define fi first
#define se second
#define rep(i, begin, end) for (int i = (begin); i < (end); i++)
#define per(i, begin, end) for (int i = (begin) - 1; i >= (end); i--)
typedef long long LL;
typedef pair <int,int> PII;

int main() {
    long long n, m, ans = 1;
	cin >> n >> m;
	if (n > m) swap(n,m);
	if (n + 1 < m) cout << 0;
	else {
        rep(i,1,n+1) ans = ans * i % MOD * i % MOD;
        if (n == m) cout << ans * 2 % MOD;
        else cout << ans * m % MOD;
	}
}


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

int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d[i];

  sort(d.begin(), d.end());

  cout << d[n/2] - d[n/2-1] << endl;

}


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

int main() {
  int n,k;
  cin>>n>>k;
  vector<int>a(n+1);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  if(k>=n){
    for(int i=0;i<n;i++){
      if(i!=n-1)cout<<n<<" ";
      else cout<<n<<endl;
    }
    return 0;
  }else{
    for(int j=0;j<k;j++){
      vector<int>b(n+1,0);
      for(int i=0;i<n;i++){
        int x=i-a[i];
        int l=max(0,x);
        int y=i+a[i]+1;
        int r=min(n,y);
        //cout<<l<<" "<<r<<endl;
        if(l!=r){
          b[l]++;
          b[r]--;
        }
      }
      for(int i=1;i<=n;i++){
        b[i]+=b[i-1];
      }
      bool hantei=true;
      for(int i=0;i<n;i++){
        a[i]=b[i];
        if(a[i]!=n)hantei=false;
      }
      if(hantei==true)break;
    }
    for(int i=0;i<n;i++){
      if(i!=n-1)cout<<a[i]<<" ";
      else cout<<a[i]<<endl;
    }
  }
  return 0;
}

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

int main() {
  double w, h, x, y;
  cin >> w >> h >> x >> y;
  double cx = w/2, cy = h/2;

  double s = w*h/2;
  int d = (x == cx && y == cy) ? 1 : 0;

  printf("%f %d\n", s, d);
  return 0;
}

Measured memory_bytes: 256