akhauriyash/Code-Regression huggingface dataset:
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns          #-}
{-# LANGUAGE CPP                   #-}
{-# LANGUAGE LambdaCase            #-}
{-# LANGUAGE MagicHash             #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE MultiWayIf            #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE TupleSections         #-}
{-# LANGUAGE TypeFamilies          #-}
{-# LANGUAGE ViewPatterns          #-}

import           Control.Applicative
import           Control.Exception
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString             as B
import qualified Data.ByteString.Char8       as C
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import qualified Data.Foldable               as F
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import qualified Data.List                   as L
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           GHC.Exts
import           Unsafe.Coerce

main :: IO ()
main = do
    [h, w] <- map read.words <$> getLine :: IO [Int]
    m <- U.unfoldrN (h * w) (C.readInt.C.dropWhile isSpace) <$> C.getContents
    let moves = solve h w m
    print $ length moves
    putStr.unlines $ map show moves

data Move = Move !Int !Int !Int !Int

instance Show Move where
    show (Move y x y' x') = unwords $ map (show.succ) [y, x, y', x']

solve :: Int -> Int -> U.Vector Int -> [Move]
solve h w m = go (-1, -1) False . U.toList . U.generate (h * w) $ \xy ->
    case unIx xy of
        (x, y)
            | even x -> (x, y)
            | otherwise -> (x, w - 1 - y)
  where
    go (!prevX, !prevY) !hasCarry ((x, y):xys)
        | hasCarry
            = Move prevX prevY x y : go (x, y) (not isOdd) xys
        | otherwise = go (x, y) isOdd xys
      where
        isOdd = testBit (U.unsafeIndex m (ix x y)) 0
    go _ _ [] = []

    ix x y = x * w + y
    unIx xy = quotRem xy w


Measured memory_bytes: 27772
import java.util.*;
import java.io.*;

public class Main {

	private static void solve(){
		//Implement solution here.
		int n = ni();
		char[] s = next().toCharArray();
		int tmp = 0;
		int result = 0;
		for(int i = 0; i < n; i++) {
			char c = s[i];
			if(tmp == 0) {
				if(c == 'A') tmp++;
			}else if(tmp == 1) {
				if(c == 'B') {
					tmp++;
				} else if(c == 'A') {
					tmp = 1;
				} else {
					tmp = 0;
				}
			} else {
				if(c == 'C') result++;
				tmp = 0;
			}		
		}
		System.out.println(result);
	}

	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (long long  i=a;i<n;i++)
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
int n, k;
ll b[100000];
//区间和最大
ll solve(VI &a,int beg,int end) {

	//int a[] = { 1,2,3,4,-5,10,-1,-1 };  // 原数组
	//int* b = (int*)malloc(sizeof(a)); // 数组b，和原数组等长

									  // 初始化
	b[beg] = a[beg];

	// 遍历构造，注意i的边界
	
	for (int i = beg; i < end; i++) {
		b[i + 1] = b[i] + a[i + 1] > a[i + 1] ? b[i] + a[i + 1] : a[i + 1];
	}

	// 然后找出b中的最大值
	ll max = b[beg];
	for (int i = beg+1; i <= end; i++)
		if (b[i] > max)
			max = b[i];
	return max;
}
void solve() {
	cin >> n >> k;
	VI a(n+1), c(n+1);
	rep(i, 0, n)cin >> a[i+1];
	rep(i, 0, n)cin >> c[i+1];
	VI vis(n+1, 0);
	vector<VI> loop;
	rep(i, 1, n+1) {
		if (vis[i])continue;
		int beg = i;
		VI lp;
		while (!vis[i]) {
			vis[i] = 1;
			lp.push_back(c[i]);
			i = a[i];
		}
		loop.push_back(lp);
	}
	ll ans = -ll(1e18);
	for (auto &lp : loop) {
		int n = sz(lp);
		ll full = 0;
		ll sum = 0;
		rep(i, 0, n)sum += lp[i];
		rep(i, 0, n)lp.push_back(lp[i]);
		for (ll i = 0; i < n; i++) {
			int end = min(i + n - 1, 1LL * sz(lp) - 1);
			full = max(full, solve(lp, i, end));
			if (end >= sz(lp) - 1) {
				break;
			}
		}
		
		if (sum > 0) {
			int K = k%n;
			if (K == 0) {
				ans = max(ans, sum*(k / n));
			}else
			for (ll i = 0; i < sz(lp); i++) {
				int end = min(i + K - 1, 1LL * sz(lp) - 1);
				ans = max(ans, sum*(k/n) + solve(lp, i, end));
				if (end >= sz(lp) - 1) {
					break;
				}
			}
			if(full > sum)
			if (k / n >= 1) {
				ans = max(ans, sum*(k / n - 1) + full);
			}
		}
		for (ll i = 0; i < sz(lp); i++) {
			int end = min(i + k - 1, 1LL * sz(lp) - 1);
			ans = max(ans, solve(lp, i, end));
			if (end >= sz(lp) - 1) {
				break;
			}
		}
	}
	
	cout << ans << endl;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T_ = 1;
	//cin >> T_;
	for (int i = 0; i < T_; i++)solve();
	return 0;
}



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

using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int mod = 1e9+7;
const int MAX = 1e3+5;


#define lowbit(x)    x&-x
#define sz(s)        (int)(s.size())
#define mk           make_pair
#define inf          0x3f3f3f3f
#define lson         l,mid,i<<1
#define rson         mid+1,r,i<<1|1
#define rep(i,s,e)   for(int i=s;i<=e;++i)
#define rev(i,s,e)   for(int i=e;i>=s;--i)

int n,m,k;

int sum(int x)
{
	int s = 0;
	while (x)
	{
		s += x %10;
		x/=10;
	}
	return s;
}


int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin>>n;
	int minn = inf;
	for(int i=1;i<=n/2;++i)
	{
		int j = n - i;
		minn = min(minn,sum(i) + sum(j));
	}
	cout<<minn<<endl;
	return 0;
}






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

int main(void){
  int N; string S;
  cin >> N >> S;
  if(N%2 != 0){
    cout << "No" << endl;
    return 0;
  }
  for(int i = 0; i < N/2; i++){
    if(S[i] != S[N/2+i]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  int one = n % 10;
  
  if (one == 3)
    cout << "bon" << endl;
  else if (one == 0 || one == 1 || one == 6 || one == 8)
    cout << "pon" << endl;
  else
    cout << "hon" << endl;
}

Measured memory_bytes: 3592
//Apparat : drobucs, aleonov, vit_72
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <iomanip>
#include <algorithm>
#include <string>
#include <queue>
#include <numeric>

//pragma warning(disable : 4996)
//#pragma GCC optimize("O3")

#define nptr nullptr
#define all(x) (x).begin(), (x).end()
#define drobucs ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define ff first
#define ss second
#define pb push_back

using namespace std;

typedef long long ll;

const int maxn = (int)2e5 + 13;
const ll INFL = 9223372036854775807;
const int INF = 2147483647;
const ll MOD = (int)1e9 + 7, MOD2 = 1e9 + 21;//1e9 + 21, 1e9 + 33, 1e9 + 87, 1e9 + 93
const ll base = 101, base2 = 37;
const long double pi = 3.1415926535897932;

ll b[maxn], a[maxn];

int main() {
	drobucs;
	
	ll n;
	cin >> n;
	for (int i = 1; i <= n - 1; ++i)cin >> b[i];
	ll ans = 0;
	a[1] = a[2] = b[1];

	for (int i = 3, j = 2; i <= n; ++i, ++j) {
		if (a[i - 1] <= b[j]) a[i] = b[j];
		else {
			a[i - 1] = a[i] = b[j];
		}
	}
	for (int i = 1; i <= n; ++i)ans += a[i];
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#define bigas(a,b) if(a<b){a=b;}
using namespace std;
int main(void){
	int h=0,i=0,j=0,m=0,ex=0,ans=0,V,E,K,x,y,z;
	static int ya[20][150][150]={0};//ya[i][x][y]???x??????y???2^i??¬???????????´????????¢??°?????????
	static int gen[150]={0};//gen[x]???x??´??????????????§?????°
	static int ima[150]={0};
	static int pre[101][150]={0};//??????????????\??????
	static int poi[101][150]={0};//??????
	for(h=0;h<20;h++){
		for(i=0;i<150;i++){
			for(j=0;j<150;j++){
				ya[h][i][j]=-(1<<30);
				if(i==j){ya[h][i][j]=0;}
			}
		}
	}
	scanf("%d %d %d",&V,&E,&K);
	for(i=0;i<E;i++){
		scanf("%d %d %d",&x,&y,&z);
		bigas(ya[0][x][y],z);
	}
	for(h=1;h<101;h++){
		for(i=0;i<V;i++){
			for(j=0;j<V;j++){
				if(poi[h][j]<poi[h-1][i]+ya[0][i][j]){
					poi[h][j]=poi[h-1][i]+ya[0][i][j];
					pre[h][j]=i;
					if(poi[h][j]>=K){ex=1;K=poi[h][j];ans=j;}
				}
			}
		}
		if(ex==1){break;}
	}
	if(ex==1){
		printf("%d\n",h);
		ima[h]=ans;
		for(i=h-1;i>=0;i--){
			ima[i]=pre[i+1][ima[i+1]];
		}
		for(i=0;i<=h;i++){
			printf("%d ",ima[i]);
		}
		return 0;
	}
	h=0,i=0,j=0,m=0,ex=0,ans=0;
	
	//??????????????§????????????????§£???
	for(h=1;h<20;h++){//2^i??¬????±???????
		for(i=0;i<V;i++){//i??????
			for(j=0;j<V;j++){//j?????§
				for(m=0;m<V;m++){//m????????£???
					bigas(ya[h][i][j],ya[h-1][i][m]+ya[h-1][m][j]);
				}
			}
		}
	}
	//??????????????¬??°??????????????§????±???????
	for(h=19;h>=0;h--){
		for(i=0;i<V;i++){
			for(j=0;j<V;j++){
				bigas(ima[j],gen[i]+ya[h][i][j]);
				if(ima[j]>=K){ex=1;break;}
			}
		}
		if(ex==0){
			ans+=(1<<h);
			for(i=0;i<V;i++){
			gen[i]=ima[i];
			}
		}else{
			for(i=0;i<V;i++){
			ima[i]=gen[i];
			}
		}
		ex=0;
	}
	ans++;
	if(ans+500<(1<<20)){printf("%d\n",ans);}else{printf("-1\n");}
}

Measured memory_bytes: 4628
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int D;
    R(D);
    printf("Christmas");
    REPP(i,D,25)printf(" Eve");
    W("");
    return 0;
}


Measured memory_bytes: 256
num_code, num_character, const_correct = map(int, input().split(' '))
multiplier = [int(x) for x in input().split(' ')]

num_correct = 0
for i in range(0, num_code):
    numbers = [int(y) for y in input().split(' ')]
    multiplied = [x*y for x, y in zip(multiplier, numbers)]

    if sum(multiplied) + const_correct > 0:
        num_correct += 1

print(num_correct)
exit(0)


Measured memory_bytes: 3060
import math
a,b,x=map(int,input().split())

bb=x/(a*a)
b1=((2*x)/(a**2))-b
if b1>0 and b1<bb:
    d=math.degrees(math.atan((2*b-(2*x)/(a*a))/a))
elif a*a*b/2 == x:
    d=math.degrees(math.atan(b/a))
elif x==a*a*b:
    d=0
else:
    d=math.degrees(math.atan(b/((2*x)/(a*b))))
print(d)


Measured memory_bytes: 38384
#include <iostream>
using namespace std;
int main(){
  int a,b,c,x;
  int d=0;
  cin>>a>>b>>c>>x;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        if(500*i+100*j+50*k==x)
          d++;
      }
    }
  }
  cout<<d<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <iostream>

#define fio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)

using namespace std;

typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t i32;
typedef int64_t i64;

int main() {
    fio;

    i32 n;
    cin >> n;
    string c;
    cin >> c;

    vector<i32> r(n + 1);
    r[0] = 0;
    for (i32 i = 0; i < n; i++) {
        r[i + 1] = r[i] + (c[i] == 'W');
    }

    i32 res = n;
    for (i32 i = 0; i <= n; i++) {
        i32 curr = max(r[i], n - i - (r[n] - r[i]));
        res = min(res, curr);
    }
    cout << res;

    return 0;
}


Measured memory_bytes: 4412
#include <stdio.h>
#include <stdbool.h>

int main(void)
{
    int n;
    int pm, pe, pj;
    int ave;
    while (true) {
        scanf("%d", &n);
        if (n == 0) {
            break;
        } else {
            for (int i = 0; i < n; ++i) {
                scanf("%d %d %d", &pm, &pe, &pj);
                ave = (pm + pe + pj) / 3;
                if (pm == 100 || pe == 100 || pj == 100) {
                    printf("A\n");
                } else if ((pm + pe) / 2 >= 90) {
                    printf("A\n");
                } else if (ave >= 80) {
                    printf("A\n");
                } else if (ave >= 70) {
                    printf("B\n");
                } else if (ave >= 50 && (pm >= 80 || pe >= 80)) {
                    printf("B\n");
                } else {
                    printf("C\n");
                }
            }
        }
    }
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    
    vector<char> s(n);
    rep(i,n) cin >> s[i];
    
    int ans = 0;
    for(int i = 1; i < n; i++){
        int cnt = 0;
        
        for(char c = 'a'; c <= 'z'; c++){
            bool left = false;
            bool right = false;
            
            for(int j = 0; j < i; j++){
                if(s[j] == c){
                    left = true;
                }
            }
            
            for(int j = i; j < n; j++){
                if(s[j] == c){
                    right = true;
                }
            }
            
            if(left&&right) cnt++;
            
            ans = max(ans,cnt);
        }
    }
    
    cout << ans;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n,money;
	cin>>n>>money;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=n-i;j++)
		{
			for(int k=0;k<=n-i-j;k++)
			{
				if(i+j+k==n&&10000*i+1000*k+5000*j==money)
				{
					cout<<i<<" "<<j<<" "<<k<<endl;
					return 0;
				}
			}
		}
	}
	cout<<-1<<" "<<-1<<" "<<-1<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    long n, h;
    cin >> n >> h;
    vector<long> a(n), b(n);
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
    sort(a, greater<long>());
    sort(b, greater<long>());
    long atk = 0;
    while (atk < n && a[0] < b[atk] && 0 < h) h -= b[atk++];
    if (0 < h) atk += (h + a[0] - 1) / a[0];
    cout << atk << endl;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"

using namespace std;
using LL = long long;


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

    string s;
    cin >> s;

    int result = 0;
    string x, y;

    for (int i = 0; i < s.size(); i ++) {
        y.push_back(s[i]);
        if (x != y) {
            result ++;
            x = y;
            y.clear();
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define MOD2 998244353
#define MOD3 1000000009
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("in.in");ofstream coutt("out.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), is_sorted(),


signed main(){
    FASTER;
    int n;cin>>n;
    vi v(n);cin>>v;
    for(int &i:v)i--;
    int cnt=0;
    for(int i=0;i<n;i++){
        cnt+=(i!=v[i]);
    }
    if(cnt==0 || cnt==2){
        cout<<"YES";
    }else cout<<"NO";
}



Measured memory_bytes: 3640
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    int N, K;
    cin >> N >> K;
    // 距離2のペアは最大でも(N-1)(N-2)/2組しかつくれない
    if (K > (N - 1) * (N - 2) / 2)
    {
        cout << -1 << endl;
        return 0;
    }
    // 1つの頂点から(N-1)頂点へと結ぶとペア数は(N-1)(N-2)/2
    // そこからペア数がKになるまで(N-1)頂点間を結んでいく
    int rem = (N - 1) * (N - 2) / 2 - K;
    // M = (N-1) + rem
    cout << N - 1 + rem << endl;
    // 1つの頂点(番号1)から残りの(N-1)頂点へと結ぶ
    for (int i = 2; i <= N; ++i)
    {
        cout << 1 << ' ' << i << endl;
    }
    // 残りの(N-1)頂点間をrem本だけ結ぶ
    for (int i = 2; i <= N; ++i)
    {
        if (rem == 0) break;
        for (int j = i + 1; j <= N; ++j)
        {
            cout << i << ' ' << j << endl;
            --rem;
            if (rem == 0) break;
        }
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}

int t[100005];

int check(int a){
    if(t[a]==-1)return -1;
    if(a==1)return 0;
    int b=t[a];
    t[a]=-1;
    b=check(b);
    if(b==-1)return -1;
    return b+1;
}

int main(){
    int n,m;
    int i,j,k;
    int a,b,c;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>t[i];
        t[i]--;
    }
    cout<<check(0)<<endl;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int K;
  cin >> K;
  ll A[K];
  for (int i = 0; i < K; i++) cin >> A[i];
  ll mi = 2;
  ll ma = 2;
  if (A[K-1] != 2) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = K-1; i >= 1; i--) {
    ma = ((ma + A[i] - 1) / A[i-1]) * A[i-1];
    mi = ((mi + A[i-1] - 1) / A[i-1]) * A[i-1];
    if (mi > ma) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << mi << " " << ma + A[0]  - 1 << endl;
  return 0;
}

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

int main(){
  int array[30];
  for(int i=0;i<30;i++){
    array[i] = i+1;
  }
  int w, n;
  scanf("%d", &w);
  scanf("%d", &n);
  for(int i=0;i<n;i++){
    int a,b;
    scanf("%d,%d", &a, &b);
    swap(array[a-1],array[b-1]);
  }
  for(int i=0;i<w;i++){
    printf("%d\n",array[i]);
  }
}

Measured memory_bytes: 1188
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int N;
    cin >> N;
    vector<ll> a(N);
    for(int i = 0; i < N; ++i)  cin >> a[i];
    vector<vector<ll>> dp(N + 1, vector<ll>(N + 1, -1));
    auto MemoRec = [&](auto&& self, int left, int right) -> ll {
        if(dp[left][right] != -1)   return dp[left][right];
        if(left == right)   return dp[left][right] = 0;
        ll res = a[left] - self(self, left + 1, right);
        chmax(res, a[right - 1] - self(self, left, right - 1));
        return dp[left][right] = res;
    };
    cout << MemoRec(MemoRec, 0, N) << endl;
}

Measured memory_bytes: 73868
#include<iostream>
using namespace std;
int main(){

int p,q,r;
cin>>p>>q>>r;

int n,m;

if(p>q){
n=q;
if(p>r){
m=r;
}else{
m=p;
}


}else{
n=p;
if(q>r){
m=r;
}else{
m=q;
}
}

cout<<n+m;

}

Measured memory_bytes: 888
#include<iostream>
#include<algorithm>
#include<vector>
using lint=long long;
using namespace std;

lint N;
lint A[200010]={};

int main()
{
	vector<lint> v;
	lint ans=0;
	
	cin >> N;
	for(lint i=1;i<=N;i++)
	{
		cin >> A[i];
		v.push_back(A[i]-i);
	}
	sort(v.begin(),v.end());
	
	lint B=v[int(v.size())/2];
	for(lint i=1;i<=N;i++)
		ans+=abs(A[i]-(B+i));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3444
#include<stdio.h>
int main(void){

int p,q,r;
int max;
int wa;

scanf("%d %d %d",&p,&q,&r);
  
max=p;
if(max<q){
max=q;
}
if(max<r){
max=r;
}
  
wa=p+r+q;
printf("%d",wa-max);
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    vector<int> sum(1000);
    sum.at(0)=0;
    for(int i=1;i<1000;i++){
        sum.at(i)=sum.at(i-1)+i;
    }
    int a,b;
    cin >> a >> b;
    cout << sum.at(b-a)-b << endl;
    return 0;
}
 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
typedef long long ll;

template<typename T>
T extgcd(T a, T b, T &x, T &y) {
    T d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1;
        y = 0;
    }
    return d;
}

map<ll, int> prime_factor(ll n) {
    map<ll, int> ret;
    for (ll i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1) ret[n] = 1;
    return ret;
}

int main() {
    ll n;
    cin >> n;
    if (n == 1) {
        cout << 1 << endl;
        return 0;
    }

    if (n % 2 == 0) n *= 2;
    auto ma = prime_factor(n);

    vector<ll> factors;
    for (auto it = ma.begin(); it != ma.end(); ++it) {
        ll x = 1;
        for (int i = 0; i < it->second; i++)x *= it->first;
        factors.push_back(x);
    }

    int k = factors.size();
    ll ret = n - 1;
    for (int bit = 1; bit < (1 << k) - 1; bit++) {
        ll a = 1, b = 1;
        for (int i = 0; i < k; i++) {
            if (bit & (1 << i))a *= factors[i];
            else b *= factors[i];
        }

        ll x, y;
        extgcd(a, b, x, y);

        a *= x, b *= y;
        if (a < 0) a = -a;
        else b = -b;

        ret = min(ret, min(a, b));
    }

    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>

using namespace std;

#define Whats(x) cout<<#x<<" is "<<x<<endl

const int N=5000;

int MOD;

int Mul(int a,int b)
{
	unsigned long long x=(long long)a*b;
	unsigned xh=(unsigned)(x>>32),xl=(unsigned)x,d,m;
	asm
		(
		 "divl %4;\n\t"
		 :"=a"(d),"=d"(m)
		 :"d"(xh),"a"(xl),"r"(MOD)
		);
	return m;
}

int U(int x,int y)
{
	return ((x+=y)>=MOD)?(x-MOD):x;
}

void SU(int& x,int y)
{
	((x+=y)>=MOD)?(x-=MOD):0;
}

int Qpow(int x,int y=MOD-2)
{
	int res=1;
	for(;y;y>>=1,x=Mul(x,x))if(y&1)
		res=Mul(res,x);
	return res;
}

int n,C[N][N],S[N][N],ppw[N],pw[N];

void Prework()
{
	for(int i=0;i<=n;++i)
	{
		C[i][0]=1;
		for(int j=1;j<=i;++j)
			C[i][j]=U(C[i-1][j-1],C[i-1][j]);
	}
	S[0][0]=1;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			S[i][j]=U(S[i-1][j-1],Mul(j,S[i-1][j]));
	pw[0]=1;
	for(int i=1;i<=n;++i)
		pw[i]=U(pw[i-1],pw[i-1]);
	ppw[0]=2;
	for(int i=1;i<=n;++i)
		ppw[i]=Mul(ppw[i-1],ppw[i-1]);
}

int main()
{
	scanf("%d%d",&n,&MOD);
	Prework();
	int ans=0;
	for(int i=0,sum;i<=n;++i)
	{
		sum=0;
		for(int k=0;k<=i;++k)
			SU(sum,Mul(Qpow(pw[n-i],k),U(Mul(k+1,S[i][k+1]),S[i][k])));
		if(i&1)
			SU(ans,MOD-Mul(C[n][i],Mul(ppw[n-i],sum)));
		else
			SU(ans,Mul(C[n][i],Mul(ppw[n-i],sum)));
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 120704
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define pi 3.14159265358979323846
#define ll long long
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  int n, x, t, a;
  cin >> n >> x >> t;
  if(n % x == 0){
    a = n / x;
  }
  else{
    a = n / x + 1;
  }
  
  cout << a * t << "\n";
}
  
  
  
  
  
  
  
  

Measured memory_bytes: 3640
#include <iostream>

int a[3], min1 = 1000000, kekka, tmp;
int main()
{
	for(int i = 0; i < 3; i++)
	{
		std::cin >> a[i];
		/*if(a[i] < min)
		{
			min = a[i];
			b = i;
		}*/
	}
	for(int i = 0; i < 3; i++)
	{
		for(int j = i+1; j < 3; j++)
		{
			if(a[j] < a[i])
			{
				tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;

			}
		}
		kekka = a[1] - a[0];
		kekka = kekka + a[2] - a[1];
	}
	std::cout << kekka;
}	

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define lamsort(v,p) sort(v.begin(),v.end(),[](p a, p b){return a.num < b.num;});
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
const long long LLINF = 1LL<<60;
const int INF = 1e9;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

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

    vector<ll> v(n);
    ll all = 0;

    rep(i,n) {
        cin >> v[i];
        all += v[i];
    }
    ll ans = LLINF;
    ll left = 0,right = all;
    rep(i,n-1) {
        left += v[i];
        right -= v[i];
        ans = min(ans,max(left,right)-min(left,right));
    }
    cout << ans << endl;

    return 0;
}

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

int main(){
  int n,x,y;
  cin>>n>>x>>y;
  vector<vector<int>> g(n);
  x--; y--;
  g[x].push_back(y);
  g[y].push_back(x);
  rep(i,n-1){
    g[i].push_back(i+1);
    g[i+1].push_back(i);
  }
  
  vector<int> ans(n);
  rep(p,n){
    vector<int> dist(n,-1);
    queue<int> que;
    
    dist[p] = 0;
    que.push(p);

    while(!que.empty()){
      int v = que.front();
      que.pop();
      for(auto nv : g[v]){
        if(dist[nv] != -1) continue;
        dist[nv] = dist[v]+1;
        que.push(nv);
      }
    }
    rep(i,n){
      ans[dist[i]]++;
    }
  }
        
  for(int i =1;i<n;i++) cout << ans[i]/2 << endl;
  
}
  
  

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
    long long int t,n,a,b,c,d,i,j,k,l,m,cnt,flag,cnt1,flag1;
    string s;
    cin>>n;
    map<string,int>mp;
    for(i=1;i<=n;i++)
    {
        cin>>s;
        mp[s]++;
    }
    l=mp.size();
    cout<<l<<endl;
    return 0;
}


Measured memory_bytes: 19228
#define _CRT_SECURE_NO_WARNINGS
#include "stdio.h"
#include <math.h>

int main()
{
    int a, b, c, d;
    scanf("%d %d %d %d", &a,&b,&c,&d);
    if(abs(a - c) <= d
       || (abs(a - b) <= d && abs(b - c) <= d))
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 128
// in the name of Allah

#include <bits/stdc++.h>

#define endl '\n'
#define ll long long
#define pb push_back
#define ld double
#define sz(x) ((int) (x.size()))

#define max_n 5123456
#define mod 1000000007
// #define mod 998244353
#define myPrime 97654321

#define fr first
#define se second

using namespace std;

ll add(ll a, ll b) {
	a += b;
	if(a >= mod) return a - mod;
	return a;
}

ll mul(ll a, ll b) {
	a *= b;
	if(a >= mod) return a % mod;
	return a;
}

ll power(ll x, ll y) {
	if(y == 0) return 1;
	ll foo = power(x, y/2);
	foo = mul(foo, foo);
	if(y&1) return mul(x, foo);
	return foo;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n, T, A, H;
	cin >> n >> T >> A >> H; A *= 1000; T *= 1000;
	int idx = 0;
	ll val = abs(A - (T - 6 * H));
	for(int i=1; i<n; i++) {
	    cin >> H;
	    ll foo = abs(A - (T - 6 * H));
	    if(foo < val) {
	        val = foo;
	        idx = i;
	    }
	}
	cout << idx + 1 << endl;
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

string s;

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

  cin>>s;
  int k=s.size();
  int cnt=0;
  rep(i,k)if(s[i]=='o')cnt++;
  cnt+=15-k;

  if(cnt>=8)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;

#define rep(i,s,n) for(ll (i)=(s);(i)<(n);(i)++)
#define repd(i,s,n) for(ll (i)=(n-1);(i)>=(s);(i)--)
#define all(x) x.begin(),x.end()
#define size(x) ((ll)(x).size()
#define PB push_back

int main(){
   double n,m;
   double s = 0;
   double count = 0;
   cin >> n >> m;
   vector<int> a(n);

   rep(i,0,n){
     cin >> a[i];
     s+=a[i];
   }
   double ans = s/(4*m);

   rep(i,0,n){
     if(a[i]>=ans)
     count++;
   }

   


   if(count>=m)
   cout << "Yes" << endl;
   else
   cout << "No" << endl;
   return 0;
}


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

int main(){
  int N;cin>>N;
  long long res=0;
  long long s=0;
  for(int i=0;i<N;i++){
    int a;cin>>a;
    if(a==0){
      res+=s/2;
      s=0;
    }
    else
      s+=a;
  }
  
  res+=s/2;
  
  cout<<res;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[n-1];

        for (int i=0; i<n; i++) a[i] = sc.nextInt()-1;
        for (int i=0; i<n; i++) b[i] = sc.nextInt();
        for (int i=0; i<n-1; i++) c[i] = sc.nextInt();


        long sum = 0;

        int z = -10;

        for (int i=0; i<n; i++){
            int j = a[i];
            sum += b[j];
            if (z+1==j){
                sum += c[j-1];
            }
            z = j;
        }
        System.out.println(sum);


    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main(){
  int N;
  string name, old_name[110];
  cin >> N;
  cin >> name;

  for(int i = 0 ; i < N ; i++){
    cin >> old_name[i];
  }
  
  int ans = 0;

  for(int i = 0 ; i < N ; i++){
    bool f = false;
    for(int j = 1 ; j <= old_name[i].size()/(name.size()-1) ; j++){ // Kankaku
      for(int k = 0 ; k < old_name[i].size() ; k++){ // Start
	string t = "";
	for(int l = k ; ; l += j){
	  if(t.size() == name.size() || old_name[i].size() < l) break;
	  t += old_name[i][l];
	}
	//cout << t << endl;
	if(t == name){
	  //cout << "find " << i << endl;
	  f = true;
	  ans++;
	}
	if(f) break;
      }
      if(f) break;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 1240
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int firstNum = scanner.nextInt();
    int secondNum = scanner.nextInt();
    int sumOne = firstNum;
    for(int i=1; i<secondNum; i++){
      sumOne = sumOne * 10 + firstNum;
    }
    int sumTwo = secondNum;
    for(int i=1; i<firstNum; i++){
      sumTwo = sumTwo * 10 + secondNum;
    }
    if(sumOne > sumTwo) System.out.println(sumOne);
    else System.out.println(sumTwo);
  }
}

Measured memory_bytes: 22484
import math
N = 10**5

Q = int(input())


def eratosthenes(n):
    """n以下の素数をエラトステネスの篩によって求める."""
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]


_primes = eratosthenes(N)

primes = [False] * (10**5 + 1)

for p in _primes:
    primes[p] = True

like_2017 = [False] * (10**5 + 1)

for p in _primes:
    if primes[(p + 1) // 2]:
        like_2017[p] = True


c = 0
C = [0]
for i in range(1, 10**5 + 1):
    if like_2017[i]:
        c += 1
    C.append(c)


for _ in range(Q):
    left, right = map(int, input().split())
    print(C[right] - C[left - 1])


Measured memory_bytes: 10648
// eddy1021
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define mod9 1000000009LL
#define mod7 1000000007LL
#define INF  1023456789LL
#define INF16 10000000000000000LL
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else 
#define debug(...)
#endif
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add( LL _x , LL _y , LL _mod = mod7 ){
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline LL sub( LL _x , LL _y , LL _mod = mod7 ){
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline LL mul( LL _x , LL _y , LL _mod = mod7 ){
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
LL mypow( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 1LL;
  LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = mul( _ret , _a , _mod );
  return _ret;
}
LL mymul( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 0LL;
  LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = add( _ret , _a , _mod );
  return _ret;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
void sleep( double sec = 1021 ){
  clock_t s = clock();
  while( clock() - s < CLOCKS_PER_SEC * sec );
}
#define Bye exit(0)
int __ = 1 , _cs;
/*********default*********/
void build(){

}
int n;
void init(){
  n = getint();
}
int query( int xi ){
  printf( "%d\n" , xi );
  fflush( stdout );
  char buf[ 64 ];
  scanf( "%s" , buf );
  if( buf[ 0 ] == 'V' ) exit(0);
  return (buf[ 0 ] == 'M');
}
int ret[ 20 ];
void solve(){
  if( n < 20 ){
    for( int i = 0 ; i < n ; i ++ )
      query( i );
  }
  ret[ 0 ] = query( 0 );
  ret[ 1 ] = query( n / 2 );
  int l , r , lr , rr;
  if( ((n / 2 + 1) % 2 == 0 and (ret[ 0 ] == ret[ 1 ]) ) or
      ((n / 2 + 1) % 2 == 1 and (ret[ 0 ] != ret[ 1 ]) )){
  //if( ret[ 0 ] == ret[ 1 ] ){
    l = 1 , r = n / 2 - 1;
    lr = ret[ 0 ];
    rr = ret[ 1 ];
  }else{
    l = n / 2 + 1 , r = n - 1;
    lr = ret[ 1 ];
    rr = ret[ 0 ];
  }
  for( int i = 2 ; i < 20 ; i ++ ){
    int mid = (l + r) >> 1;
    ret[ i ] = query( mid );
    if( ( (mid - l + 1) % 2 == 0 and (ret[ i ] != lr) ) or
        ( (mid - l + 1) % 2 == 1 and (ret[ i ] == lr) ) ){
      r = mid - 1;
      rr = ret[ i ];
    }else{
      l = mid + 1;
      lr = ret[ i ];
    }
  }

  assert( false );
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


Measured memory_bytes: 852
n,x = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
for i in range(n):
    if a[i] >= x:
        ans += a[i]-x
        a[i] = x
for j in range(n-1):
    if a[j] + a[j+1] >= x:
        d = a[j]+ a[j+1] - x
        ans += d
        a[j+1] -= d
print(ans)


Measured memory_bytes: 63984
n, m = map(int,input().split())
A = []
C = []
for i in range(m):
    ab = list(map(int,input().split()))
    A.append(ab)
    cc = list(map(int,input().split()))
    C.append(cc)
T = []
for i in range(m):
    t = 0
    for j in C[i]:
        t += 2**(j-1)
    T.append(t)


n2 = 2**n

DP = [[float("inf") for i in range(n2)] for j in range(m+1)]
for i in range(m+1):
    DP[i][0] = 0

for i in range(1,m+1):
    t = T[i-1]
    for j in range(n2):
        # print(i,j,t)
        # print(DP[i][j|t], DP[i-1][j|t], DP[i-1][j] + A[i-1][0])
        DP[i][j|t] = min(DP[i][j|t], DP[i-1][j|t], DP[i-1][j] + A[i-1][0])
        DP[i][j] = min(DP[i][j], DP[i-1][j])
        # print(DP[i][j|t])

ans = DP[-1][-1]
if ans == float("inf"):
    ans = -1
print(int(ans))

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

int main()
{
  int K, A, B;
  cin >> K;
  cin >> A >> B;
  while(A <= B)
  {
    if(A % K == 0)
    {
      cout << "OK" << endl;
      return 0;
    }
    else
    {
      A++;
    }
  }
  cout << "NG" << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>
typedef long long ll;

int
main(int argc, char *argv[])
{
  ll x;
  scanf("%lld", &x);
  ll y = x - (x / 11) * 11;
  ll ans = 2 * (x / 11);
  if(0 < y && y <= 6) ++ans;
  else if(6 < y) ans += 2;
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
 
int board[4][4];
 
bool inField(int x,int y){
    return (0 <= x && x < 4 && 0 <= y && y < 4);
}
 
int solve(int idx,int *x,int *y){
    if(idx == 8){ return 1; }
    int sx,sy;
    for(int i = 0 ; i < 4 ; i++){
	bool found = false;
	for(int j = 0 ; j < 4 ; j++){
	    if(board[i][j] == -1){
		sx = j; sy = i;
		found = true;
		break;
	    }
	}
	if(found){ break; }
    }
    int res = 0;
    for(int i = 0 ; i < 4 ; i++){
	int tx = sx+x[i],ty = sy+y[i];
	if(!inField(tx,ty) || board[ty][tx] != -1){
	    continue;
	}
	board[sy][sx] = board[ty][tx] = idx;
	res += solve(idx+1,x,y);
	board[sy][sx] = board[ty][tx] = -1;
    }
    return res;
}
 
int main(){
    int x[4],y[4];
    while(cin >> x[0] >> y[0], x[0] < 4){
	for(int i = 1 ; i < 4 ; i++){
	    cin >> x[i] >> y[i];
	}
	memset(board,-1,sizeof(board));
	cout << solve(0,x,y) << endl;
    }
    return 0;
}

Measured memory_bytes: 2992
# -*- coding: utf-8 -*-
from collections import deque
h,w = map(int, input().split())
al = [input() for _ in range(h)]

inf = 10**9
m = [[inf]*w for _ in range(h)]
q = deque([])
for hi in range(h):
    for wi in range(w):
        if al[hi][wi]=="#":
            m[hi][wi] = 0
            q.append((hi,wi))

while len(q)>0:
    ch,cw = q.popleft()
    c = m[ch][cw]
    for hi,wi in [[ch+1,cw],[ch,cw+1],[ch-1,cw],[ch,cw-1]]:
        if h>hi>=0 and w>wi>=0 and m[hi][wi]>c+1:
            m[hi][wi] = c+1
            q.append((hi,wi))

res = max([max(m[i]) for i in range(h)])
print(res)

Measured memory_bytes: 88796
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
#ifdef DEBUG
#define display(x) cerr << #x << " = " << x << endl;
#define displaya(a, st, n)\
	{cerr << #a << " = {";\
	for(int qwq = (st); qwq <= (n); ++qwq) {\
		if(qwq == (st)) cerr << a[qwq];\
		else cerr << ", " << a[qwq];\
	} cerr << "}" << endl;}
#define displayv(v) displaya(v, 0, (int)(v).size() - 1)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define display(x) ;
#define displaya(a, st, n) ;
#define displayv(v) ;
#define eprintf(...) if(0) fprintf(stderr, "...")
#endif
template<typename T> bool chmin(T &a, const T &b) { return a > b ? a = b, true : false; }
template<typename T> bool chmax(T &a, const T &b) { return a < b ? a = b, true : false; }

int main() {
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	cout << (n - 2) * 180 << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a,dem=0;
string s;
int main()
{
  	cin >> a ;
  	cin >> s ;
  	for(int i = 0;i < a; i++)
    {
        if(s.find("ABC",i) <1000 && s.find("ABC",i-1) != s.find("ABC",i)) dem++;
    }
    cout<<dem;
  	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int  main(){
	int n;
	int a[100];
cin>>n;
	for(int i=0;i<n;i++)
	cin>>a[i];
	for(int j=n-1;j>=0;j--){
		if(j!=0)
	cout<<a[j]<<' ';
		else cout<<a[j]<<endl;
	} 
	return 0;
}


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

using namespace std;

typedef long long ll;

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; }
const ll LINF = 1e18;

double p[3010];
double dp[3010][3010];

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

  dp[0][0] = 1.0;

  for (int i = 0; i < N; ++i) {
    for (int j = 0; j <= N; ++j) {
      dp[i+1][j] += dp[i][j] * (1 - p[i]);
      dp[i+1][j+1] += dp[i][j] * p[i];
    }
  }

  double result = 0.0;
  for (int i = (N + 1) / 2; i <= N; ++i) {
    result += dp[N][i];
  }

  cout << fixed << setprecision(10) << result << endl;
}

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


int main()
{
    int x=1;
    //cin>>t;
    while( x-- )
    {
        string s,t;
        cin>>s>>t;
        ll n=s.size();
        ll m=t.size();
        ll ans=INT_MAX;

        ll chk=0;
        for( int i=0 ; i<=n-m ; i++ )
        {
            ll ctr=0;
            for( int j=i ; j<i+m ; j++ )
            {
                if( s[j]!=t[chk] )
                {
                    ctr++;
                }
                chk++;
            }
            chk=0;
            ans=min( ans,ctr );
        }

        cout<<ans;
    }
    return 0;
}


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

ll a,b;
int main(){
    cin >> a >> b;

    if(b==0){
        cout << a*a << endl;
        return 0;
    }
    ll ans = 0;
    // x ：割る数、あまりにはxの周期あり
    for(int x = b + 1; x <= a; ++x){
        // b + n*x ~ n * x - 1(<= a) : あまりがb以上になる区間
        ll n = (a+1) / x; // a = 5, b = 2 のとき、最初のループでn=2
        ans += n * (x - b); // x-b = 1周期にあるかず 
        ans += max(0LL, a - (b + n*x - 1));
    }
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

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

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl



int main(){
    int a,b;
    cin>>a>>b;
    if(b>0 && a<0){
        cout<<"Zero"<<endl;
        return 0;
    }
    if(a>0){
        cout<<"Positive"<<endl;
        return 0;
    }
    
    if((b-a)%2){
        cout<<"Positive"<<endl;
    }else{
        cout<<"Negative"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256