akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define print(x) cout << x << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll MOD = 1000000007;

int main()
{
    ll N, K;
    string S;
    cin >> N >> K >> S;
    S += "1";
    vector<ll> zero_end;
    for (ll i = 1; i <= N; i++)
    {
        if (S[i-1] == '0' & S[i] == '1') {
            zero_end.push_back(i);
        }
    }
    ll k_cnt = 0;
    ll start = 0;
    ll ma = 0;
    for (ll i = 1; i < N; i++)
    {
        if (S[i-1] == '1' & S[i] == '0') {
            if (k_cnt < K) {
                continue;
            } else {
                ma = max(ma, i - start);
                start = zero_end.front();
                zero_end.erase(zero_end.begin());
                k_cnt--;
            }
        } else if (S[i-1] == '0' & S[i] == '1') {
            k_cnt++;
        }
    }
    ma = max(ma, N - start);
    print(ma);
    return 0;
}


Measured memory_bytes: 1020
#include <stack>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <string>
using namespace std;
#define N 100
int n, m[N][N];
int color[N], d[N], f[N], tt;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int mod = 1000000000 + 7;
void dfs_visit(int i){
    color[i] = 1;
    d[i] = ++tt;
    for(int j = 0; j < n; j++){
        if(m[i][j] == 0){
            continue;
        }
        if(color[j] == 0){
            dfs_visit(j);
        }
    }
    color[i] = 2;
    f[i] = ++tt;
}
void dfs(){
    for(int i = 0; i < n; i++){
        color[i] = 0;
    }
    tt = 0;
    for(int i = 0; i < n; i++){
        if(color[i] == 0){
            dfs_visit(i);
        }
    }
    for(int i = 0; i < n; i++){
        cout << i+1 << " "<<  d[i] << " " << f[i] << endl;
    }
}
int main(){
    //std::stack<int> stack;
    int u, k, v;
    cin >> n;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            m[i][j] = 0;
        }
    }
    for(int i = 0; i < n; i++){
        cin >> u >> k;
        u --;
        for(int j = 0; j < k; j++){
            cin >> v;
            v--;
            m[u][v] = 1;
        }
    }
    dfs();
    //cout << masu << endl;
    return 0;
}






Measured memory_bytes: 3108
import bisect

n = int(input())
l = input().split(' ')
l = [int(i) for i in l]
l.sort()

cnt = 0
for i in range(n):
    for j in range(i+1, n):
        num = l[i] + l[j]
        index = bisect.bisect_left(l, num)
        # print(index, j)
        # print(index-2)
        cnt += (index-j-1)

print(cnt)


Measured memory_bytes: 3188
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

N = int(input())
childs = [list(map(int, input().split())) for _ in range(N)]

childs.sort(reverse=True)
count = 0
pre_c = 0
for c in childs:
    if not pre_c == c:
        count += 1
    pre_c = c
print(count)


Measured memory_bytes: 2940
package main

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

const Mod = int(1e9) + 7

func main() {
	N := ReadInt()
	A := ReadInts(N)
	ans := 1
	c := make([]int, 3)
	for i := 0; i < N; i++ {
		v := 0
		lastJ := 0
		for j := 0; j < 3; j++ {
			if c[j] == A[i] {
				v++
				lastJ = j
			}
		}
		if v == 0 {
			fmt.Println(0)
			return
		}
		c[lastJ]++
		ans = ans * v % Mod
	}
	fmt.Println(ans)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 3244
import java.util.*;

public class Main{

    int w,h;
    char[][] l,r;
    int lx,ly,rx,ry;
    boolean found;
    boolean[][][][] v;
    int[] dx = {0,0,1,-1};
    int[] dy = {1,-1,0,0};

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            w = sc.nextInt();
            h = sc.nextInt();
            if(w==0 && h==0) break;

            l = new char[h][w];
            r = new char[h][w];
            for(int i=0; i<h; i++){
                String s1 = sc.next();
                String s2 = sc.next();
                s2 = new StringBuffer(s2+"").reverse().toString();

                l[i] = s1.toCharArray();
                r[i] = s2.toCharArray();
                for(int j=0; j<w; j++){
                    if(l[i][j]=='L'){
                        lx = j; ly = i;
                    }
                    if(r[i][j]=='R'){
                        rx = j; ry = i;
                    }
                }
            }

            found = false;
            v = new boolean[w][h][w][h];
            bfs();

            if(found) System.out.println("Yes");
            else System.out.println("No");
        }
    }

    void bfs(){
        LinkedList<int[]> list = new LinkedList<int[]>();
        list.add(new int[]{lx,ly,rx,ry});
        
        while(list.size()>0){
            int[] lr = list.poll();
            int xl = lr[0], yl = lr[1], xr = lr[2], yr = lr[3];

            if(l[yl][xl]=='%' && r[yr][xr]=='%'){
                found = true;
                return;
            }
            if(l[yl][xl]=='%' || r[yr][xr]=='%') continue;

            if(v[xl][yl][xr][yr]) continue;
            v[xl][yl][xr][yr] = true;

            for(int i=0; i<4; i++){
                int nxl = xl+dx[i], nyl = yl+dy[i], nxr = xr+dx[i], nyr = yr+dy[i];
                if(nxl<0 || nxl>=w || nyl<0 || nyl>=h || l[nyl][nxl]=='#'){
                    nxl = xl; nyl = yl;
                }
                if(nxr<0 || nxr>=w || nyr<0 || nyr>=h || r[nyr][nxr]=='#'){
                    nxr = xr; nyr = yr;
                }
                if(nxl==xl && nyl==yl && nxr==xr && nyr==yr) continue;
                list.add(new int[]{nxl,nyl,nxr,nyr});
            }
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

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

int main() {
  int n;
  cin >> n;
  int curmax = 1000000;
  int ans = 0;
  rep(i, n) {
    int tmp;
    cin >> tmp;
    if(tmp < curmax) {
      ans++;
      curmax = tmp;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n) cin >> p.at(i);
  sort(p.begin(), p.end());
  int ans = 0;
  rep(i, k){
    ans += p.at(i);
  }
  cout << ans << endl;
  return 0;
}

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

const long double PI = acos(-1);
 
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

int main(){
    ll n, m;
    cin >> n >> m;

    cout << (1900 * m + 100 * (n - m)) * pow(2, m) << endl;
    return 0;
}

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

bool compare(pair<int, pair<string, int> > a, pair<int, pair<string, int> > b) {
    if (a.second.first < b.second.first) {
        return true;
    }
    if (a.second.first > b.second.first) {
        return false;
    }
    return a.second.second > b.second.second;
}

int main() {

    int n;
    cin >> n;
    vector<pair<int, pair<string, int> > > vc;
    for (int i=0; i<n; i++) {
        string a;
        int sc;
        cin >> a >> sc;
        vc.push_back(make_pair(i, make_pair(a, sc)));
    }
    sort(vc.begin(), vc.end(), compare);
    for (int i=0; i<vc.size(); i++) {
        cout << vc[i].first+1 << endl;
    }

}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;

string my_readln() { return chomp(readln()); }

long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }

void main()
{
	auto tokens = my_readln.split;
	auto N = tokens[0].to!long;

	ulong[] six, nine;

	uint x = 6;
	while (x <= N)
	{
		six ~= x;
		x *= 6;
	}
	uint y = 9;
	while (y <= N)
	{
		nine ~= y;
		y *= 9;
	}

	auto dp = new ulong[](N+1);
	fill(dp, ulong.max);
	dp[0] = 0;
	foreach (i; 0..N)
	{
		if (dp[i] == ulong.max) continue;

		foreach (e; six)
		{
			auto j = i + e;
			if (j <= N)
			{
				dp[j] = min(dp[j], dp[i] + 1);
			}
		}
		foreach (e; nine)
		{
			auto j = i + e;
			if (j <= N)
			{
				dp[j] = min(dp[j], dp[i] + 1);
			}
		}
		dp[N] = min(dp[N], dp[i] + N - i);
	}

	writeln(dp[N]);
	stdout.flush();
}

Measured memory_bytes: 2684
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    for (int i = k; i <= n; i++) {
        if (i == 0) {
            continue;
        }
        ans += (n / i) * (i - k);
        if (n % i > 0) {
            if (k == 0) {
                ans += n % i;
            }
            else {
                if ((n % i) - k + 1 > 0) {
                    ans += (n % i) - k + 1;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from bisect import bisect, bisect_left
def inpl(): return list(map(int, input().split()))
N, K = inpl()
if K%2==0:
    X = N//K
    Y = N//(K//2) - X
    print(Y**3 + X**3)
else:
    X = N//K
    print(X**3)

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};


signed main(){
    gearup;
    int n,a; cin >> n >> a;
    out(n*n-a);
}



Measured memory_bytes: 256
//
//  AT2584 [ABC064B] Traveling AtCoDeer Problem.cpp
//  Algorithm
//
//  Created by SkyGao on 2020/2/13.
//  Copyright © 2020 skygao. All rights reserved.
//

#include <stdio.h>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#define re register
using namespace std;
int n,a[105];
int main()
{
    scanf("%d",&n);
    for(re int i=1;i<=n;++i)
        scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    printf("%d",a[n]-a[1]);
    return 0;
}


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

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

  int N; cin >> N;
  vector<int> A(N+2);
  for (int i = 1; i <= N; i++) cin >> A[i];

  vector<int> cs(N+2);
  for (int i = 1; i <= N+1; i++)
    cs[i] = cs[i-1] + abs(A[i]-A[i-1]);

  for (int i = 1; i <= N; i++) {
    cout << cs[i-1] + (cs.back()-cs[i+1]) + abs(A[i+1]-A[i-1]);
    cout << "\n";
  }
}

Measured memory_bytes: 2048
import java.util.*;

class Main {

	static int MAX = 1000000;
	static boolean isPrime[] = new boolean[MAX+2];

	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		seive();
		for(;;){
			int n = in.nextInt(), ub = in.nextInt();
			if(n==0 && ub==0) return ;
			int a[] = new int[n];
			for(int i=0; i<n; i++){
				a[i] = in.nextInt();
			}
			int ans = solve(a, ub);
			if(ans < 0) System.out.println("NA");
			else System.out.println(ans);
		}
	}
	
	static int solve(int[] a, int ub){
		boolean ok[] = new boolean[ub+1];
		ok[0] = true;
		for(int i=0; i<ub; i++)if(ok[i]){
			for(int j=0; j<a.length; j++)if(i+a[j] <= ub){
				ok[i + a[j]] = true;
			}
		}
		int ans = -1;
		for(int i=ub; i>0; i--)if(ok[i] && isPrime[i]){
			ans = i;
			break;
		}
		
		return ans;
	}
	
	static void seive(){
		for(int i=1; i<=MAX; i++) isPrime[i] = true;
		for(int i=2; i*i<=MAX; i++)if(isPrime[i]){
			for(int j=2*i; j<=MAX; j+=i)
				isPrime[j] = false;
		}
	}
}

Measured memory_bytes: 0
#include<iostream>

using namespace std;

int N;

int main() {
	cin >> N;

	int miss = 0;
	for (int i = 0; i < N; i++) {
		int p;
		cin >> p;
		if (p != i + 1) { miss++; }
	}

	if (miss == 0 || miss == 2) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import numpy as np
H,W,K=map(int,input().split())

D=np.zeros([H,W])

for i in range(H):
    C=input()
    for j in range(W):
        if C[j]=="#":
            D[i,j]=1


ans=0

for i in range(2**H):
    h="{:06b}".format(i)
    for j in range(2**W):
        w="{:06b}".format(j)

        d=D.copy()
        for hi in range(H):
            if h[5-hi]=="1":
                d[hi,:]=0
        for wi in range(W):
            if w[5-wi]=="1":
                d[:,wi]=0
        #print(d.sum())
        if d.sum()==K: ans+=1



print(ans)

Measured memory_bytes: 26976
n = int(input())
minis = []
maxis = []
for i in range(n):
    a,b = map(int, input().split())
    minis.append(a)
    maxis.append(b)

minis.sort()
maxis.sort()

if(n%2 == 0):
    bottom = (minis[n//2-1] + minis[n//2])
    top = (maxis[n//2-1] + maxis[n//2])
    if(top >= bottom):
        print(top - bottom + 1)
    else:
        print('0')
if(n%2 == 1):
    bottom = minis[(n-1)//2]
    top = maxis[(n-1)//2]
    if(top >= bottom):
        print(top - bottom + 1)
    else:
        print('0')


Measured memory_bytes: 25552
fun main(args: Array<String>) {
    codefestival2016qualac()
}

fun codefestival2016qualac() {
    val s = readLine()!!.toCharArray()
    val k = readLine()!!.toInt()

    var remainChange = k
    for (i in s.indices) {
        if (remainChange <= 0) break
        if (s[i] == 'a') continue
        val costToA = 'z' + 1 - s[i]
        if (remainChange >= costToA) {
            s[i] = 'a'
            remainChange -= costToA
        }
    }

    if (remainChange > 0) {
        s[s.lastIndex] = ((s.last() - 'a' + remainChange) % 26 + 'a'.toInt()).toChar()
    }

    val answer = s.joinToString("")

    println(answer)
}


Measured memory_bytes: 39948
#include<iostream>
using namespace std;
int main(){
	char s;
	while(cin >> s){
		if(s >= 'a' && s <= 'z'){
			cout << "a" << endl;
		}
		else if(s >= 'A' && s <= 'Z'){
			cout << "A" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3000
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define nl '\n'
#define mp make_pair
#define debug1(x) cout <<#x<<" "<<x<<'\n';
#define debug2(x,y) cout <<#x<<" "<<x <<" "<<#y<<" "<<y <<'\n';
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<'\n';
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define inf 1e18
const int mod = (int)1e9 + 7;
pair<ll, ll>s4[4] = {{ -1, 0}, {1, 0}, {0, -1}, {0, 1}};
pair<ll, ll>s8[8] = {{ -1, -1}, { -1, 0}, { -1, 1}, {0, -1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}};

void judge() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

void solve() {
	char x;
	cin >> x;
	if (x >= 'A' && x <= 'Z') {
		cout << 'A' << nl;
	}
	else {
		cout << 'a' << nl;
	}
}

signed main() {
	judge();
	boost;
	solve();
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
using vc = vector<char>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()


int main(){
 int n;
 cin >> n;
 vl a(n);
 rep(i,n) cin >> a[i];
 sort(all(a));
 long l = a[n-1];
 long r = 0;
 rep(i,n-1){
   r = max(r, min(a[i], l-a[i]));
 }
 cout << l << " ";
 rep(i,n-1){
   if(a[i] == r){
     cout << r << endl;
     return 0;
   }else if(a[i] == l-r){
     cout << l-r << endl;
     return 0;
   }
 }
}

Measured memory_bytes: 4004
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int n, prev, cur, ans = 0, tmp = 0;
   cin >> n >> prev;
   for (int i = 1; i < n; i++)
   {
      cin >> cur;
      if (cur <= prev)
      {
         tmp++;
      }
      else
      {
         ans = max(ans, tmp);
         tmp = 0;
      }
      prev = cur;
   }
   ans = max(ans, tmp);
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <math.h>
using namespace std;

typedef long long signed int ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(obj) (obj).begin(),(obj).end()

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
int maiz[50][50]={-3};
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
    int H,W;
    cin>>H>>W;
    int wh=0;
    REP(j,H){
        REP(i,W){
            char a;
            cin>>a;
            if(a=='#')maiz[i][j]=-2;//wall
            else{ 
                maiz[i][j]=-1;
                wh++;
            }//road
        }
    }
    queue<int> quex,quey;

    quex.push(0); // 0 を橙色頂点にする
    quey.push(0);
    maiz[0][0]=0;
    // BFS 開始 (キューが空になるまで探索を行う)
    while (!quex.empty()) {
        int x = quex.front(); // キューから先頭頂点を取り出す
        int y = quey.front(); // キューから先頭頂点を取り出す
        quex.pop();
        quey.pop();
        int l=maiz[x][y];
        if(x>=0&&x<W&&y>=0&&y<H&&maiz[x+1][y]==-1){
            quex.push(x+1);
            quey.push(y);
            maiz[x+1][y]=l+1;
        }
        if(x>=0&&x<W&&y>=0&&y<H&&maiz[x-1][y]==-1){
            quex.push(x-1);
            quey.push(y);
            maiz[x-1][y]=l+1;
        }
        if(x>=0&&x<W&&y>=0&&y<H&&maiz[x][y+1]==-1){
            quex.push(x);
            quey.push(y+1);
            maiz[x][y+1]=l+1;
        }
        if(x>=0&&x<W&&y>=0&&y<H&&maiz[x][y-1]==-1){
            quex.push(x);
            quey.push(y-1);
            maiz[x][y-1]=l+1;
        }
    }
    if(maiz[W-1][H-1]<0) cout<<-1<<endl;
    else cout<<wh-maiz[W-1][H-1]-1<<endl;
	return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//
 
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
 
template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

struct UnionFind {
	vector<size_t> parent;
	vector<size_t> rank;
	size_t find_parent(size_t x) {
		if (parent[x] == x) {
			return x;
		} else {
			parent[x] = find_parent(parent[x]);
			return parent[x];
		}
	}
	explicit UnionFind(size_t size) {
		parent.resize(size);
		rank.resize(size);
		for (size_t i = 0; i < size; i++) {
			parent[i] = i;
			rank[i] = 0;
		}
	}
	virtual ~UnionFind() {}
	void unite(size_t x, size_t y) {
		size_t px = find_parent(x);
		size_t py = find_parent(y);
		if (px == py) {
			return;
		}
		if (rank[px] < rank[py]) {
			parent[px] = py;
		} else if (rank[px] > rank[py]) {
			parent[py] = px;
		} else {	// rank[px] == rank[py]
			parent[py] = px;
			rank[px]++;
		}
	}
	bool is_same(size_t x, size_t y) {
		return find_parent(x) == find_parent(y);
	}
	unordered_map<size_t, set<size_t>> create_map_parent_to_elements() {
		unordered_map<size_t, set<size_t>> ans;
		for (size_t i = 0; i < parent.size(); i++) {
			ans[find_parent(i)].insert(i);
		}
		return ans;
	}
};
 
int main() {
	ll N;
	cin >> N;
	struct Point {
		ll idx;
		ll x;
		ll y;
		ll cost(Point rhs) {
			return min(abs(x-rhs.x), abs(y-rhs.y));
		}
	};
	vector<Point> pts;
	for (ll i = 0; i < N; i++) {
		ll x, y;
		cin >> x >> y;
		pts.push_back({i, x, y});
	}
	struct Edge {
		ll idx0;
		ll idx1;
		ll cost;
		static bool comp(Edge lhs, Edge rhs) {
			return lhs.cost > rhs.cost;
		}
	};
	priority_queue<Edge, vector<Edge>, decltype(&Edge::comp)> edges(&Edge::comp);
	sort(pts.begin(), pts.end(), [](Point lhs, Point rhs){
		return lhs.x < rhs.x || (lhs.x == rhs.x && lhs.y < rhs.y);
	});
	for (ll i = 0; i < N-1; i++) {
		edges.push({pts[i].idx, pts[i+1].idx, pts[i].cost(pts[i+1])});
	}
	sort(pts.begin(), pts.end(), [](Point lhs, Point rhs){
		return lhs.y < rhs.y || (lhs.y == rhs.y && lhs.x < rhs.x);
	});
	for (ll i = 0; i < N-1; i++) {
		edges.push({pts[i].idx, pts[i+1].idx, pts[i].cost(pts[i+1])});
	}
	UnionFind tree(N);
	ll ans = 0;
	while (true) {
		if (edges.empty()) {
			break;
		}
		Edge e = edges.top();
		edges.pop();
		if (tree.is_same(e.idx0, e.idx1)) {
			continue;
		}
		tree.unite(e.idx0, e.idx1);
		ans += e.cost;
	}
	cout << ans << endl;
}

Measured memory_bytes: 10988
A,B = map(int,input().split())
S = input()
result = "Yes"
for i,s in enumerate(S):
    if i < A or A < i:
        if(s == '-'): 
            result =  "No"
            break
    else:
        if(s != '-'):
            result =  "No"
            break
print(result)

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

int n,A,B,C;

int dfs(int u , int a , int b , int c , vector<int> cont){
  if(u == n+1){
    if(a == 0 || b == 0 || c == 0){
      return 1000000009;
    }else{
      return abs(a - A) + abs(b - B) + abs(c - C) - 30;
    }
  }
  
  int ra = dfs(u+1 , a , b , c , cont);
  int rb = dfs(u+1 , a + cont.at(u) , b , c , cont) + 10;
  int rc = dfs(u+1 , a , b + cont.at(u) , c , cont) + 10;
  int rd = dfs(u+1 , a , b , c + cont.at(u) , cont) + 10;
  
  return min(min(ra,rb) , min(rc , rd));
}
  
int main(){
  
  cin >> n >> A >> B >> C;
  
  vector<int> cont(n+1);
  
  for(int i = 1 ; i <= n ; i++){
    cin >> cont.at(i);
  }
  
  cout << dfs(0 , 0 , 0 , 0 , cont) << endl;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    string s;
    cin >> s;
    ll n = s.size();
    vector<pair<ll,ll>> a;
    char tmp = s.at(0);
    ll num = 1;
    for(i = 1;i < n;++i){
        if(s.at(i) == tmp) ++num;
        else{
            if(tmp == '<'){
                a.emplace_back(num, 1);
            }else{
                a.emplace_back(num, -1);
            }
            tmp = s.at(i);
            num = 1;
        }
    }
    if(tmp == '<'){
        a.emplace_back(num, 1);
    }else{
        a.emplace_back(num, -1);
    }
    ll ans = 0;
    vector<ll> b;
    if(a.size() == 1){
        cout << a.at(0).first*(a.at(0).first+1)/2 << endl;
        return 0;
    }
    for(i = 0;i + 1 < a.size();i += 2){
        if(i == 0 && a.at(i).second == -1){
            b.push_back(a.at(i).first);
            --i;
        }else{
            ll t = max(a.at(i).first, a.at(i+1).first);
            ll s = min(a.at(i).first, a.at(i+1).first);
            b.push_back(t);
            b.push_back(s-1);
        }
    }
    if(a.back().second == 1){
        b.push_back(a.back().first);
    }
    for(i = 0;i < b.size();++i){
        ans += (b.at(i)+1)*b.at(i)/2;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8692
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int check(int x, int y, const vector<vector<char>> &flag,
          const vector<vector<char>> &filter) {
    int res = 0;
    int M = flag.size();
    int N = flag[0].size();
    for(int i = y - 1; i <= y; i++) {
        for(int j = x - 1; j <= x; j++) {
            if(i == -1 || j == -1 || i == M - 1 || j == N - 1)
                continue;
            bool ok = 1;
            rep(ii, 2) {
                rep(jj, 2) {

                    if(flag[i + ii][j + jj] != filter[ii][jj])
                        ok = 0;
                }
            }
            res += ok;
        }
    }
    return res;
}

int main() {
    int M, N;
    cin >> M >> N;
    vector<vector<char>> flag(M, vector<char>(N));
    vector<vector<char>> filter(2, vector<char>(2));
    rep(i, M) rep(j, N) cin >> flag[i][j];
    rep(i, 2) rep(j, 2) cin >> filter[i][j];
    int old = 0;
    rep(i, M - 1) rep(j, N - 1) {
        int ok = 1;
        rep(ii, 2) rep(jj, 2) {
            if(filter[ii][jj] != flag[i + ii][j + jj])
                ok = 0;
        }
        old += ok;
    }
    int res = old;
    for(int y = 0; y < M; y++) {
        for(int x = 0; x < N; x++) {
            int base = check(x, y, flag, filter);
            if(flag[y][x] == 'J') {
                int after;
                flag[y][x] = 'O';
                after = check(x, y, flag, filter);
                res = max(res, old - base + after);
                flag[y][x] = 'I';
                after = check(x, y, flag, filter);
                res = max(res, old - base + after);
                flag[y][x] = 'J';
            } else if(flag[y][x] == 'O') {
                int after;
                flag[y][x] = 'J';
                after = check(x, y, flag, filter);
                res = max(res, old - base + after);
                flag[y][x] = 'I';
                after = check(x, y, flag, filter);
                res = max(res, old - base + after);
                flag[y][x] = 'O';
            } else {
                int after;
                flag[y][x] = 'O';
                after = check(x, y, flag, filter);
                res = max(res, old - base + after);
                flag[y][x] = 'J';
                after = check(x, y, flag, filter);
                res = max(res, old - base + after);
                flag[y][x] = 'I';
            }
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3964
n,k=map(int,input().split())
s=input()
u=s+s[::-1]
u=min((u[i:i+n])for i in range(n))
for i in range(n):
  if u[i]!=u[0]:break
c=i
for _ in range(k-1):
  c*=2
  if c>n:break
print((u[0]*c+u[i:])[:n])

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<tuple>
#include<numeric>
#include<map>
#include<cmath>
#define ll long long
#define rep(i,n) for(int i=1;i<=(int) (n);i++)
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;

  cout<<n*(n-1)/2+m*(m-1)/2;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int n;
ll a[55];

vector<pii> go(int l,int r)
{
	if(l>=r)
	{
		vector<pii> v;
		return v;
	}
	ll mx=-1,id;
	rep(i,l,r)
	{
		if(abs(a[i])>mx)
		{
			mx=abs(a[i]);
			id=i;
		}
	}
	if(a[id]==0)
	{
		vector<pii> v;
		return v;
	}
	if(a[id]<0)
	{
		vector<pii> v=go(id+1,r);
		ll b[55];
		rep(i,1,n)b[i]=a[i];
		tr(v,it)
		{
			int x=it->ff,y=it->ss;
			b[y]+=b[x];	
		}
		ren(i,id,l)
		{
			if(i==r)continue;
			while(1)
			{
				if(b[i+1]>=b[i])break;
				v.pb(mp(i+1,i));
				b[i]+=b[i+1];
			}
		}
		return v;
	}
	else
	{
		vector<pii> v=go(l,id-1);
		ll b[55];
		rep(i,1,n)
		{
			b[i]=a[i];
		}
		tr(v,it)
		{
			int x=it->ff,y=it->ss;
			b[y]+=b[x];
		}
		rep(i,id,r)
		{
			if(i==l)continue;
			while(1)
			{
				if(b[i]>=b[i-1])break;
				v.pb(mp(i-1,i));
				b[i]+=b[i-1];
			}
		}
		return v;
	}
}

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

cin>>n;
rep(i,1,n)cin>>a[i];
vector<pii> ans=go(1,n);
ol(ans.size());on;
tr(ans,it)
{
	o2(it->ff,it->ss);on;
}
return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N,M;
    cin >> N >> M;
    pr((1900*M+100*(N-M))*pow(2,M));
}

Measured memory_bytes: 256
import bisect
import heapq
N = int(input())
vals = {}
for i in range(N):
	s,p = input().split()
	p = int(p)
	if s in vals.keys():
		vals[s].append([p,i+1])
	else:
		vals[s] = [[p,i+1]]

keys = []
for k in vals.keys():
	vals[k].sort(key = lambda x: -x[0])
	keys.append(k)

keys.sort()
for k in keys:
	for v in vals[k]:
		print(v[1])


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

int main() {
  string s;
  ll k;
  cin >> s >> k;

  rep(i, s.size()) {
    if (i == k - 1) {
      cout << s[i] << endl;
      return 0;
    }

    if (s[i] != '1') {
      cout << s[i] << endl;
      return 0;
    }
  }

  return 0;
}

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

int main()
{
    int N;
    int n = 100000;
    long long K;
    cin >> N >> K;

    vector<long long> nums(n, 0);
    for (int i = 0; i < N; i++)
    {
        int a, b;
        cin >> a >> b;
        nums.at(a - 1) += b;
    }

    int counter = 0;
    while (K > 0)
    {
        K -= nums.at(counter);
        counter++;
    }

    cout << counter << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(void){
long long int a,b;
long long int m,n;
long long int tmp;
    while(scanf("%lld %lld",&a,&b)!=EOF){
        m=(a>b)?a:b;
        n=(a>b)?b:a;
        while(m%n!=0){
            tmp=m%n;
            m=n;
            n=tmp;
        }
        printf("%lld %lld\n",n,a*b/n);
    }
    return 0;
}

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

int main(){
  while(1){
    int m,f,r;
    string am;
    
    cin>>m>>f>>r;
    if(m==-1 && f==-1 && r==-1)break;
    if(m==-1 || f==-1)am="F";
    else if(m+f<30)am="F";
    else if(m+f<50 && r>=50)am="C";
    else if(m+f<50)am="D";
    else if(m+f<65)am="C";
    else if(m+f<80)am="B";
    else {am="A";}

    cout<<am<<endl;
  }	   
  
}


Measured memory_bytes: 3128
S = raw_input()

T = '01' * (len(S) / 2) + ('0' if len(S) % 2 == 1 else '')
U = '10' * (len(S) / 2) + ('1' if len(S) % 2 == 1 else '')

t, u = 0, 0
for i in xrange(len(S)):
    if S[i] != T[i]:
        t += 1
    if S[i] != U[i]:
        u += 1

print min(t, u)

Measured memory_bytes: 2948
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    # 等間隔のダイスとコインなので、dの目ごとの勝利確率をだし、平均すると答。
    n, k = map(int, input().split())

    pro = 0
    for i1 in range(1, n + 1):
        if i1 >= k:
            pro += 1
        else:
            pro_t = 1
            while i1 < k:
                pro_t /= 2
                i1 *= 2
            pro += pro_t
    r = pro / n
    print(r)

if __name__ == '__main__':
    main()


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

struct Graph
{
    int n;
    vector<vector<int>> g;
    
    Graph(int n) : n(n){
        g.resize(n);
    }
    
    void add_edge(int from, int to){
        g[from].push_back(to);
    }
};

bool dfs(int u, Graph &g, int *a){
    for(int v : g.g[u]){
        if(a[v] < a[u]){
            if(!dfs(v, g, a)) return true;
        }
    }
    return false;
}

int main()
{
    int n;
    cin >> n;
    int a[3005];
    for(int i = 0; i < n; i++) cin >> a[i];
    Graph g(n);
    for(int i = 0; i < n - 1; i++){
        int u, v;
        cin >> u >> v;
        u--; v--;
        g.add_edge(u, v);
        g.add_edge(v, u);
    }
    for(int i = 0; i < n; i++){
        if(dfs(i, g, a)) cout << i + 1 << " ";
    }
    cout << endl;
}


Measured memory_bytes: 3788
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
using namespace std;
int main()
{
	int N;
	vector<int>NN;
	vector<int>ANS;
	cin >> N;

	for(int i=0;i<N;i++){
		int t;
		cin >> t;
		NN.push_back(t);
		ANS.push_back(0);
	}
	for(int i=0;i<N;i++)
	{
		ANS[NN[i]-1]=i+1;
	}
	for(int i=0;i<N;i++)
	{
		cout << ANS[i] << " ";
	}
	cout << endl;
}

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

int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    if(b%a==0)
        printf("%d\n",a+b);
    else
        printf("%d\n",b-a);
    return 0;
}


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

using namespace std;

int main() {
    map<string, int> kv;
    kv["SUN"] = 7;
    kv["MON"] = 6;
    kv["TUE"] = 5;
    kv["WED"] = 4;
    kv["THU"] = 3;
    kv["FRI"] = 2;
    kv["SAT"] = 1;

    string S;
    cin >> S;
    cout << kv[S] << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScan in = new MyScan(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, MyScan in, PrintWriter out) {
            String s = in.next();

            long[] res = new long[3];

            long ta = 1;
            for (char x : s.toCharArray()) {
                switch (x) {
                    case 'A':
                        res[0] = (res[0] + ta) % Util._m;
                        break;
                    case 'B':
                        res[1] = (res[1] + res[0]) % Util._m;
                        break;
                    case 'C':
                        res[2] = (res[1] + res[2]) % Util._m;
                        break;
                    case '?': {
                        res[2] = (3 * res[2] + res[1]) % Util._m;
                        res[1] = (3 * res[1] + res[0]) % Util._m;
                        res[0] = (3 * res[0] + ta) % Util._m;
                        ta = (ta * 3) % Util._m;
                        break;
                    }
                }

            }
//        out.println(Arrays.toString(res));
            out.println(res[2]);

        }

    }

    static class Util {
        public static final long M07 = 1000_000_007;
        public static final long _m = M07;

    }

    static class MyScan {
        private final InputStream in;
        private byte[] inbuf = new byte[1024];
        public int lenbuf = 0;
        public int ptrbuf = 0;

        public MyScan(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (lenbuf == -1) throw new InputMismatchException();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = in.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (lenbuf <= 0) return -1;
            }
            return inbuf[ptrbuf++];
        }

        public boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }

        public int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        }

        public String next() {
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while (!(isSpaceChar(b))) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

    }
}



Measured memory_bytes: 21588
#include <stdio.h>

int sosu(int n){
    if(n==1)return 0;
    for(int i=2;i*i<=n;i++){
        if(n%i==0)return 0;
    }
    return 1;
}

int main(void){
    int a[55];
    int count=0;
    for(int i=11;;i+=10){
        if(sosu(i)){a[count]=i;count++;}
        if(count==55)break;
    }
    int N;
    scanf("%d",&N);
    for(int i=0;i<N;i++)printf("%d ",a[i]);
    return 0;
}


Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG       // Iterator safety; out-of-bounds access for Containers, etc.
//#pragma GCC optimize "trapv" // abort() on (signed) integer overflow.

#include <bits/stdc++.h>

//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
 
using namespace std;
//using namespace __gnu_pbds;
//typedef tree< pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>
//ordered_set;
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& DEFINES &&&&&&&&&&&&&&&&&&&&&&&&&&&

#define int long long int 
#define ld long double
#define X first
#define Y second
#define all(i) i.begin(), i.end()
#define sz(a) (int)a.size()
 
const ld PI  = 3.141592653589793238463;
const int dx4[4] = {0, 1, 0, -1};
const int dy4[4] = {-1, 0, 1, 0};
const int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& DEBUG &&&&&&&&&&&&&&&&&&&&&&&&&&&
 
#define XOX
vector<string> vec_splitter(string s) {
    for(char& c: s) c = c == ','?  ' ': c;
    stringstream ss; ss << s;
    vector<string> res;
    for(string z; ss >> z; res.push_back(z));
    return res;
}
 
void debug_out(vector<string> __attribute__ ((unused)) args, __attribute__ ((unused)) int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
    if(idx > 0) cerr << ", ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, T...);
}
 
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
#else
#define debug(...) 42
#endif
 
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& CODE &&&&&&&&&&&&&&&&&&&&&&&&&&&


void solve(){
    int s, w; cin >> s >> w;
    if( w >= s){
        cout << "unsafe\n";
    } else {
        cout << "safe\n";
    }
   
}
 
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); 
    int T = 1; 
    //cin >> T;
    for(int i = 1; i <= T; ++i){
        solve();
    }
    return 0;
}
/*
Sample inp
*/

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

int main() {
  int a, b;
  cin >> a >> b;
  if (a * b  % 2 == 0) {
    cout << "Even" << endl;
  }
  
  else {
    cout << "Odd" << endl;
  }
  
}  
 


Measured memory_bytes: 256
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const inputs = input.trim().split('\n');

const COLORS = ['r','g','b'];
class Worm {
  constructor(id, seconds) {
    this.id = id;
    this.seconds = seconds;
  }
  getNextWormIds() {
    const nextWormIds = [];
    for (let i = 0; i < this.id.length - 1; i++) {
      const [ current, next ] = this.id.substr(i, 2);
      if (current === next) {
        continue;
      }
      const changed = COLORS.find(color => color !== current && color !== next);
      const changedId = this.id.substr(0, i) + changed.repeat(2) + this.id.substr(i + 2);
      nextWormIds.push(changedId);
    }
    return nextWormIds;
  }
}

class Graph {
  constructor() {
    this.map = new Map();
  }
  bfs(wormId) {
    this.queue = [];
    this.map.set(wormId, new Worm(wormId, 0));
    this.queue.push(wormId);
    while(this.queue.length) {
      const wormId = this.queue.shift();
      const worm = this.map.get(wormId);
      const wormIds = worm.getNextWormIds();
      // 全部同じ色のときwormIdsが存在せず、そのときのwormを返す
      if (!wormIds.length) {
        return worm;
      }
      wormIds.forEach(wormId => {
        if (this.map.has(wormId)) {
          return;
        }
        this.map.set(wormId, new Worm(wormId, worm.seconds + 1));
        this.queue.push(wormId);
      })
    }
  }
}

inputs.forEach(wormId => {
  if (wormId === '0') {
    return;
  }
  const graph = new Graph();
  const worm = graph.bfs(wormId);
  console.log(worm ? worm.seconds : 'NA');
});



Measured memory_bytes: 55732
#include <stdio.h>
 
int main(){
    int a,aa,aaa;
   
  	scanf("%d%d%d", &a, &aa, &aaa);
    
    if(a==aa && a==aaa){
        printf("No");}
  
  else if(a!=aa && a!=aaa && aa!=aaa){
    printf("No");}
    
  else{
        printf("Yes");}
   
  return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import sys


S = list(input())
N = len(S)
MOD = 2019
#%%
A = [0]*(N+1)
R = [0]*(2030)

R[0] += 1
base = 1
for i in range(N):
    A[i+1] = A[i] + base*int(S[N-1-i])
    base *= 10
    base %= MOD
    A[i+1] %= MOD
    R[A[i+1]] += 1

ans = 0
for r in R:
    ans += r*(r-1)//2
print(ans)
    

Measured memory_bytes: 84540
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL)

const int N = 1e5+10;

int a[N][3];
int dp[N][3];
int n;
int func(int ind, int activity){
	if(ind < 0)
		return 0;
	if(activity != -1 && dp[ind][activity] != -1)
		return dp[ind][activity];
	int points = 0;
	for(int i = 0; i < 3; ++i){
		if(activity == i)
			continue;
		points = max(a[ind][i] + func(ind-1, i),points);
	}
	return dp[ind][activity] = points;
}

int main(){
	FIO;
	cin >> n;
	memset(dp, -1,sizeof(dp));
	for(int i = 0; i < n; ++i){
		cin >> a[i][0] >> a[i][1] >> a[i][2];
	}
	cout << func(n-1, -1);
}

Measured memory_bytes: 10368
#include<iostream>
#include<algorithm>
using namespace std;
int n,a[110000],b[110000];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i],b[i]=a[i];
	int ans1=0,ans2=0;
	for(int i=1;i<n;i++)
		if(a[i]==i)swap(a[i],a[i+1]),ans1++;
	for(int i=n;i>1;i--)
		if(b[i]==i)swap(b[i],b[i-1]),ans2++;
	if(a[n]==n)swap(a[n-1],a[n]),ans1++;
	if(b[1]==1)swap(b[1],b[2]),ans2++;
	cout<<min(ans1,ans2)<<endl;
}


Measured memory_bytes: 1024