akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}

int main(){
	ll a,b,c;
	scanf("%lld%lld%lld",&a,&b,&c);
	printf("%lld",a+b+c-max(a,max(b,c)));
}

Measured memory_bytes: 128
from collections import deque
h,w=map(int,input().split())
maze=[input() for i in range(h)]
visited=[[-1]*w for i in range(h)]
aw=0
for i in range(h):
  aw+=maze[i].count('.')
def bfs(maze,visited):
  q=deque([[0,0]])
  visited[0][0]=1
  while q:
    x,y=q.popleft()
    if [x,y]==[h-1,w-1]:
      return True,visited[x][y]
    for i,j in [[0,1],[1,0],[0,-1],[-1,0]]:
      newx,newy=x+i,y+j
      if 0<=newx<h and 0<=newy<w:
        if maze[newx][newy]!='#' and visited[newx][newy]==-1:
          visited[newx][newy]=visited[x][y]+1
          q.append([newx,newy])
  return False,-1
ok,path=bfs(maze,visited)
if ok:
  print(aw-path)
else:
  print(path)

Measured memory_bytes: 3316
from collections import deque
s = input()
q = int(input())

text = deque(s)
readleft = True


for _ in range(q):
  query = input().rstrip().split()
  if query[0] == "1":
    readleft = not(readleft)
  else:
    addtop = 2 - int(query[1])
    addleft = (addtop == readleft)
    if addleft:
      text.appendleft(query[2])
    else:
      text.append(query[2])

if readleft:
  while text != deque():
    print(text.popleft(), end="")
  print()
else:
  while text != deque():
    print(text.pop(), end="")
  print()

Measured memory_bytes: 7664
input = readlines()

n, m = input.shift.chomp.split("\s").map{|x| x.to_i}
list = input.shift.chomp.split("\s").map{|x| x.to_i}

total = list.sum

selected = []
thres = total.to_f / (4 * m).to_f
list.each do |l|
  selected.push(l) unless l < thres
end

puts selected.length >= m ? 'Yes' : 'No'

Measured memory_bytes: 14388
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

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

void Main(){
	ll a, b;
	cin >> a >> b;
	ll g = gcd(a,b);
	// cout << g << endl;
	int p = 2;
	int cnt = 1;
	int r = sqrt(g);
	while(g > 1){
		if(p > r) {
			++cnt;
			break;
		} 
		else if(g%p == 0) {
			++cnt;
			while(g%p == 0) g /= p;
        }
		else {
			if(p == 2) p++;
			else p += 2;
        }
	}
	cout << cnt << endl;
	return;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    char a,c,d;
    int b=0;
    cin>>a>>c>>d;
    if(a=='R'){
        b++;
        if(c=='R'){
            b++;
            if(d=='R'){
                b++;
            }
        }
    }else if(c=='R'){
        b++;
        if(d=='R'){
            b++;
        }
    }else if(d=='R'){
        b++;
    }
    cout<<b<<endl;
    //cout<<a<<c<<d<<endl;
}

Measured memory_bytes: 3616
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n, i := intScanner(), intScanner()
	fmt.Println(n + 1 - i)
}


Measured memory_bytes: 1776
#include<stdio.h>
int main()
{
    int a,b,c,n,i,g,m,s;



    scanf("%d%d%d",&a,&b,&c);
    if(a>=b&&b>=c)
        {g=a;
        m=b;
        s=c;}
    else if(c>=a&&a>=b)
        {g=c;
        m=a;
        s=b;}
    else if(b>=c&&c>=a)
        {g=b;
        m=c;
        s=a;}
    else if(b>=a&&a>=c)
        {g=b;
        m=a;
        s=c;}
    else if(a>=c&&c>=b)
        {g=a;
        m=c;
        s=b;}
    else if(c>=b&&b>=a)
        {g=c;
        m=b;
        s=a;}

     n=(g*10)+m+s;
    printf("%d",n);
}

Measured memory_bytes: 128
#include <stdio.h>
#include <inttypes.h>

int N;
int64_t D;
int64_t X[271828], Y[271828];

int main(void) {
	int i;
	int mizuhasu = 0;
	if(scanf("%d%" SCNd64, &N, &D) != 2) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%"SCNd64 "%" SCNd64, &X[i], &Y[i]) != 2) return 1;
	}
	for (i = 0; i < N; i++) {
		if(X[i] * X[i] + Y[i] * Y[i] <= D * D) mizuhasu++;
	}
	printf("%d\n", mizuhasu);
	return 0;
}


Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
char ch[55][55];
int n,m;
int main()
{
    scanf("%d %d",&n,&m);
    for(int i=0;i<n;i++)
    {
        scanf("%s",ch[i]);
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(ch[i][j]=='#')
                printf("#");
            else
                {
                    int sum=0;
                    for(int k=-1;k<=1;k++)
                    {
                        for(int k1=-1;k1<=1;k1++)
                        {
                            if(k==0&&k1==0)
                                continue;
                            if(i+k<0||j+k1<0||i+k>=n||j+k1>=m)
                                continue;
                            if(ch[i+k][j+k1]=='#')
                                sum++;
                        }
                    }
                    printf("%d",sum);
                }
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 256
import Control.Applicative

main = do (n:m:l) <- map read . words <$> getLine
          abs <- map (map read . words) . lines <$> getContents
          let as = fst $ splitAt n abs
          let bs = snd $ splitAt n abs
          putStr . unlines . map (unwords . map show) $ solve as bs

solve :: [[Int]] -> [[Int]] -> [[Int]]
solve as bs = map (makeRow bs) as

makeRow :: [[Int]] -> [Int] -> [Int]
makeRow bs a = map (dot a) $ tra bs

dot :: [Int] -> [Int] -> Int
dot a b = sum $ zipWith (*) a b

tra :: [[Int]] -> [[Int]]
tra ([]:_) = []
tra bs = (map head bs) : (tra $ map tail bs)

Measured memory_bytes: 12208
while True:
    w, h = map(int, input().split())
    if w == 0 and h == 0:
        break
    cnt = 0
    maps = [list(map(int, input().split())) for _ in range(h)]
    for x in range(w):
        for y in range(h):
            if maps[y][x] == 0:
                continue
            else:
                cnt += 1
                maps[y][x] = 0
                stack = [(y, x)]
                while stack:
                    f_y, f_x = stack.pop()
                    for dy in range(-1, 2):
                        for dx in range(-1, 2):
                            t_y = f_y + dy
                            t_x = f_x + dx
                            if 0 <= t_y <= h - 1 and 0 <= t_x <= w - 1 and maps[t_y][t_x] == 1:
                                maps[t_y][t_x] = 0
                                stack.append((t_y, t_x))
    print(cnt)


Measured memory_bytes: 5620
from sys import stdin
input = stdin.readline

class Unionfind():
    def __init__(self, n):
        self.n = n
        self.parent = [-1]*n
    
    def find(self, x):
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parent[x] > self.parent[y]:
            x, y = y, x

        self.parent[x] += self.parent[y]
        self.parent[y] = x

    def size(self, x):
        return -self.parent[self.find(x)]

N,M = map(int, input().split())

uf = Unionfind(N)
for i in range(M):
    a,b = map(lambda x: int(x) - 1, input().split())
    uf.union(a,b)
lis = uf.parent
print(-min(lis))

Measured memory_bytes: 14544
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

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

    map<int,int> m;
    for(int x=1;x<=100;x++){
        for(int y=1;y<=100;y++){
            for(int z=1;z<=100;z++){
                int tmp=x*x+y*y+z*z+x*y+y*z+z*x;
                m[tmp]++;
            }
        }
    }

    for(int i=1;i<=n;i++) cout<<m[i]<<endl;
}


Measured memory_bytes: 5416
using System; //Console, IComparable
using System.IO; //StreamWriter 
using System.Linq; //Select(), Where(), OrderBy(), Count()
using System.Collections.Generic; //List<T>
using System.Reflection; //PropertyInfo[], GetProperties[]
using static System.Console; using static NNN.CInput;

namespace NNN{
    public class CRun{
        private static class gv{
            public static int X {get; set;} = 0;
            public static int Y {get; set;} = 0;
            public static int A {get; set;} = 0;
            public static int B {get; set;} = 0;
            public static int C {get; set;} = 0;
            public static int[] p, q, r;
        }
    
        public void build(){ string[] input;
            input = _stringa;
            var pi = typeof(gv).GetProperties();
            for (int i = 0; i < 5; i++) {
                pi[i].SetValue(typeof(gv), int.Parse(input[i]));
            }
            gv.p = _inta;
            gv.q = _inta;
            gv.r = _inta;
        }
        
        public void solve(){ StreamWriter stream_out = new StreamWriter(Console.OpenStandardOutput());
            Array.Sort(gv.p, (x,y) => y - x);
            Array.Sort(gv.q, (x,y) => y - x);
            Array.Sort(gv.r, (x,y) => y - x);
            
            var pCnt = 0;
            var qCnt = 0;
            var rCnt = 0;
            var ans = 0L; //long
            var cntDown = gv.X + gv.Y;
            
            while (true) {
                
                if (cntDown <= 0) break;
                
                var pNow = (pCnt < gv.X ? gv.p[pCnt] : -1);
                var qNow = (qCnt < gv.Y ? gv.q[qCnt] : -1);
                var rNow = (rCnt < gv.r.Length ? gv.r[rCnt] : -1);
                
                //WriteLine($"{pCnt}, {qCnt}, {rCnt}");
                //WriteLine($"{pNow}, {qNow}, {rNow}");
                
                if (rNow >= pNow && rNow >= qNow) {
                    ans += rNow;
                    rCnt++;
                }
                else if (pNow >= qNow) {
                    ans += pNow;
                    pCnt++;
                }
                else {
                    ans += qNow;
                    qCnt++;
                }
                
                cntDown -= 1;
            }
            
            WriteLine(ans);
            
        }
    }

    class Program { 
        static void Main() { 
            var run = new CRun();
            run.build();
            run.solve();
        } 
    }

    public static class CInput{
        public static string _string{get{return Console.ReadLine();}}
        public static string[] _stringa{get{return (Console.ReadLine().Split());}}
        public static int _int{get{return int.Parse(Console.ReadLine());}}
        public static int[] _inta{get{return Console.ReadLine().Split().Select(x=>int.Parse(x)).ToArray();}}
        public static long _long{get{return long.Parse(Console.ReadLine());}}
        public static long[] _longa{get{return Console.ReadLine().Split().Select(x=>long.Parse(x)).ToArray();}}
    }
}



Measured memory_bytes: 35420
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
//#define endl '\n'

using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 2e5 + 5, LG = 19, MOD = 998244353;
const int SQ =225;
const long double EPS = 1e-6;
int V[1 << 18];
int W[1 << 18];
int n, q;
int len[1 << 18];
int ans[1<<9][100001];
int sum[1<<9];
int val[1<<9];
int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

  cin >> n;
  for(int i = 1; i <= n; i++){
    cin >> V[i] >> W[i];
    len[i] = len[i >> 1] + 1;
    if(len[i] <= 9){
      for(int j = 100000;j >= 0; j--){
        ans[i][j] = ans[i>>1][j];
        if(j >= W[i])ans[i][j] = max(ans[i][j], ans[i>>1][j-W[i]] + V[i]);
      }
      for(int j = 1; j <= 100000; j++)ans[i][j] = max(ans[i][j], ans[i][j-1]);
    }
  }

  int q;
  cin >> q;

  while(q--){

    int node, weight;
    cin >> node >> weight;
    if(len[node] <= 9){
      cout << ans[node][weight] << endl;
    } else {
      vector<ii> vx;
      for(; len[node] > 9; node >>= 1){
        vx.push_back(make_pair(W[node], V[node]));
      }
      int out = ans[node][weight];
      for(int i = 0; i < vx.size(); i++){
        sum[1<<i] = vx[i].F;
        val[1<<i] = vx[i].S;
      }
      for(int mask = 1; mask < (1 << vx.size()); mask++){
        sum[mask] = sum[mask-(mask&-mask)] + sum[mask&-mask];
        val[mask] = val[mask-(mask&-mask)] + val[mask&-mask];
        if(sum[mask] <= weight)
          out = max(out, val[mask] + ans[node][weight - sum[mask]]);
      }
      cout << out << '\n';
    }


  }


  return 0;
}


Measured memory_bytes: 206324
#include <stdio.h>

int N, M;
int d[128], v[128];

int hayamisaori[128];

int main(void) {
	int i;
	while (scanf("%d%d", &N, &M) == 2 && (N|M) != 0) {
		int hanazawakana = 0;
		for (i = 1; i <= M; i++) hayamisaori[i] = 0;
		for (i = 0; i < N; i++) {
			if (scanf("%d%d", &d[i], &v[i]) != 2) return 1;
			if (v[i] > hayamisaori[d[i]]) hayamisaori[d[i]] = v[i];
		}
		for (i = 1; i <= M; i++) {
			hanazawakana += hayamisaori[i];
		}
		printf("%d\n", hanazawakana);
	}
	return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int N;

int main(void) {

	string ans = "No";

	cin >> N;

	while (N > 0) {
		if (N % 10 == 7) { ans = "Yes"; }
		N /= 10;
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderMake.ABC170
{
    class ABC170C
    {
        static void Main(string[] args)
        {
            var xn = Console.ReadLine().Split().Select((x) => int.Parse(x)).ToArray();
            
            var pmap = new Dictionary<int,int>();
            int min = 0;
            int max = 101;
            int ans=0;
            if (xn[1] != 0)
            {
                var pi = Console.ReadLine().Split().Select((x) => int.Parse(x)).ToArray();

                foreach (int p in pi)
                {
                    pmap.Add(p, 0);
                }
            }
            for(int i = xn[0]; i >= 0; i--)
            {
                if (pmap.ContainsKey(i)==false)
                {
                    min = i;
                    break;
                }
            }
            for (int i = xn[0]; i <= 101; i++)
            {
                if (pmap.ContainsKey(i)==false)
                {
                    max = i;
                    break;
                }
            }
            if (xn[0] - min > max - xn[0])
            {
                ans = max;
            }
            else
            {
                ans = min;
            }
            Console.WriteLine(ans);
        }
        
    }
}


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

long long int N, a, A;

int main(){
    scanf("%lld", &N);
    for(int i = 0; i < N; ++i){
        scanf("%lld", &a);
        A += a - 1;
    }
    cout << A << endl;
    return 0;
}

Measured memory_bytes: 256
r, c = map(int,input().split())
h = [list(map(int,input().split()))for i in range(r)]
total = []

for i in range(r):
    h[i].append(sum(h[i]))
    
for i in range(c+1):
    t = 0
    for j in range(r):
        t += h[j][i]
    total.append(t)
    
for i in range(r):
    print(*h[i])

print(*total)


Measured memory_bytes: 6228
import java.util.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = Integer.parseInt(sc.next(), 16);
	int b = Integer.parseInt(sc.next(), 16);
    String ret = "=";
	if (a > b) {
      ret = ">";
    } else if (a < b) {
      ret = "<";
    }
    System.out.println(ret);
  }
}

Measured memory_bytes: 25172
#include<bits/stdc++.h>
using namespace std;
long long arr[100010][6];

int main(){
	long long a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,tmp,ans,cnt;
	scanf("%lld %lld",&n,&c);
	for(i=1;i<=n;i++){
		scanf("%lld %lld",&arr[i][0],&arr[i][1]);
	}
	arr[0][4]=0;
	arr[n+1][5]=0;
	cnt=0;
	for(i=1;i<=n;i++){
		cnt+=arr[i][1];
		arr[i][2]=cnt-arr[i][0];
		arr[i][4]=max(arr[i-1][4],arr[i][2]);
	}
	cnt=0;
	for(i=n;i>=1;i--){
		cnt+=arr[i][1];
		arr[i][3]=cnt-(c-arr[i][0]);
		arr[i][5]=max(arr[i+1][5],arr[i][3]);
	}
	ans=max(arr[n][4],arr[1][5]);
	cnt=0;
	for(i=1;i<=n;i++){
		cnt+=arr[i][1];
		ans=max(ans,cnt-arr[i][0]*2+arr[i+1][5]);
	}
	cnt=0;
	for(i=n;i>=1;i--){
		cnt+=arr[i][1];
		ans=max(ans,cnt-(c-arr[i][0])*2+arr[i-1][4]);
	}
	printf("%lld",ans);
}

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

const int INF =1e9 + 5;

int main(){
	int n;
	cin>>n;
	int h[n];

	for(int i=0;i<n;i++)
		cin>>h[i];

	vector<int> dp(n, INF);
	
	dp[0]=0;
	
	for(int i=0;i<n;++i){

		for( int j: {i+1,i+2}){
			if(j<n)
				dp[j]=min( dp[j], dp[i] + abs(h[i]-h[j]) );
		}
	}

	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>

using namespace std;

void sort(int *a,int n)
{
	int i = 0, j = n - 1;
	int pivot = a[(i+j)/2];

	while(true)
	{
		while(a[i] < pivot)i++;
		while(a[j] > pivot)j--;

		if(i >= j)break;

		int hold = a[i];
		a[i] = a[j];
		a[j] = hold;

		i++;
		j--;
	}

	if(i > 1)sort(a,i);
	if(n-j-1 > 1)sort(a+j+1,n-j-1);
}

int main()
{
	int N,C,K;
	int *T;
	int *cnt;

	cin >> N >> C >> K;
	T = new int[N];

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

	sort(T,N);

	int start = 0;
	int sum = 0;
	int ans = 0;

	for(int i=0;i<N;i++)
	{
		if(sum == 0)
		{
			start = T[i] + K;
			sum++;
		}
		else
		{
			if(start >= T[i])
			{
				sum++;
			}
			else
			{
				ans++;
				sum = 1;
				start = T[i]+K;
			}
		}

		if(sum == C)
		{
			sum = 0;
			start = 0;
			ans++;
		}
	}

	if(start != 0)
	{
		ans++;
	}

	delete(T);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
  int k,a=0; cin>>k;
  int b[1001001]={0};
  for(int i=1;i<1000001;i++){
    a=((10*a)%k+7%k)%k;
    if(++b[a]>1) break; 
    if(!a){
      cout<<i;
      return 0;
    }
  }
  cout<<-1;
}

Measured memory_bytes: 7552
//Problem link - https://atcoder.jp/contests/dp/tasks/dp_b

#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define INF 0x3f3f3f3f
#define mod 1000000007

int main()
{
	fast;
	ll n,k;
	cin>>n>>k;
	ll arr[n+5];
	for(ll i=0;i<n;i++)
		cin>>arr[i];
	ll dp[n+5];
	dp[n-1]=0;
	for(ll i=n-2;i>=0;i--)
	{
	    dp[i]=INF;
		for(ll j=1;j<=k;j++)
		{
			if(i+j<n)
				dp[i]=min(dp[i],abs(arr[i]-arr[i+j])+dp[i+j]);
		}
	}
	cout<<dp[0];
	return 0;
}

Measured memory_bytes: 1792
import math

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

bunshi = 0
bumbo = 2 ** math.ceil(math.log(k, 2)) * n

for i in range(1, n + 1):
    bunshi += 2 ** (math.ceil(math.log(k, 2)) - max(math.ceil(math.log(k / i, 2)), 0))

print(bunshi / bumbo)

Measured memory_bytes: 3060
def main():
    N, K = (int(x) for x in input().split())
    scores = [int(x) for x in input().split()]

    first, last = 0, K-1

    while last < N-1:
        last += 1
        if scores[first] < scores[last]: print('Yes')
        else: print('No')
        first += 1

if __name__ == '__main__':
    main()

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

using namespace std;

#define ll long long

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

    int n, d, a;
    cin >> n >> d >> a;
    vector<pair<ll, ll>> x(n);

    for (int i = 0; i < n; i++) cin >> x[i].first >> x[i].second;

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

    int range = 2 * d;

    int prev = 0;

    ll ans = (x[0].second + a - 1) / a;

    ll shots = 0;
    deque<pair<int, ll>> q;
    if (n > 1 && x[0].first + range >= x[1].first) {
        shots += ans;
        q.emplace_back(x[0].first + range, ans);
    }

    for (int i = 1; i < n; i++) {
        if (x[i].second > shots * a || x[i].first > x[prev].first + range) {
            ll shot = (x[i].second - shots * a + a - 1) / a;
            ans += shot;
            shots += shot;
            q.emplace_back(x[i].first + range, shot);
            prev = i;
        }
        if (i != n - 1) {
            while (!q.empty()) {
                if (q.front().first < x[i + 1].first) {
                    shots -= q.front().second;
                    q.pop_front();
                } else break;
            }
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 4992
h,n = map(int,input().split())

ab_input = [list(map(int,input().split())) for i in range(n)]

max_d = max(a for a,b in ab_input)

dp =[0]*(h+max_d)
for i in range(1,h+max_d):#dp[i-a]でi-a<0のとき影響がでないようにmax_dを足す
    dp[i]=min(dp[i-a]+b for a,b in ab_input)#モンスターの体力を i 減らすため消耗する魔力の最小値

print(dp[h])

Measured memory_bytes: 68620
import math

max = 1000000
candidates = [True for x in xrange(0, max + 1)]
candidates[0] = False
candidates[1] = False

for i in xrange(2, int(math.sqrt(max))):
    if not candidates[i]:
        continue

    j = i + i
    while True:
        if max < j:
            break
        candidates[j] = False
        j += i

while True:
    try:
        n = int(raw_input())
        print len([i for i in candidates[0:n+1] if i])
    except Exception:
        break

Measured memory_bytes: 20832
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)


int main() {
    ll N;
    cin >> N;
    vector<ll> B(N-1);
    rep(i,N-1){
        cin >> B[i];
    }

    vector<ll> A;
    A.push_back(B[0]);

    rep(i,N-2){
        A.push_back(min(B[i],B[i+1]));
    }

    A.push_back(B[N-2]);

    ll ans=0;
    rep(i,N){
        ans += A[i];
    }
    cout << ans << endl;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

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



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

const int N = (int) 1e5 + 5;

int n;
int nprime;
int p[N], f[N];

void sieve() {
	int LIM = 55555;
	for  (int i = 2; i <= LIM; i++) {
		if (f[i] == 0) f[i] = p[++nprime] = i;
		int j = 0;
		while (j < nprime && p[j] < f[i] && p[j + 1] * i <= LIM) {
			f[p[j + 1] * i] = p[j + 1];
			j++;
		}
	}
}

int main() {
	//freopen(".inp", "r", stdin); freopen(".out", "w", stdout);
	sieve();
	cin >> n;
	for (int i = 1; i <= nprime; i++)
		if (p[i] % 5 == 1) {
			cout << p[i] << " ";
			n--;
			if (n == 0) break;
		}
	return 0;
}

Measured memory_bytes: 512
/* 
 * Author: aps
 * Time: 2019-07-28 19:43:46
**/
#include<bits/stdc++.h>
 
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
 
using namespace std;
 
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef pair<int,int> pii;
 
const ll inf = 1e18;
const ll mod = 1e9+7;
 
inline ll add(ll x, ll y) { x += y; if (x >= mod) x -= mod; return x;}
inline ll sub(ll x, ll y) { x -= y; if (x < 0) x += mod; return x;}
inline ll mul(ll x, ll y) { return ((x % mod) * (y % mod)) % mod;}
inline ll power(ll a, ll b) {
    ll x = 1;
    while (b) {
        if (b & 1) x = mul(x, a);
        a = mul(a, a);
        b >>= 1;
    }
    return x;
}
inline ll inv(ll a) { return power(a, mod - 2);}

const int N = 1e5+5;

ll dp[N][13];

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    string s; cin >> s;
    int n = (int)s.length();

    dp[0][0] = 1LL;
    for(int i=0;i < n;i++){
        if(s[i] == '?'){
            for(int d=0;d<10;d++){
                for(int pd=0; pd < 13; pd++){
                    int rem = (pd*10 + d)%13;
                    dp[i+1][rem] = add(dp[i+1][rem],dp[i][pd]);
                }
            }
        } else {
            int d = s[i] - '0';
            for(int pd = 0; pd < 13; pd++){
                int rem = (pd*10 + d)%13;
                dp[i+1][rem] = add(dp[i+1][rem],dp[i][pd]);
            }
        }
    }

    cout << dp[n][5] << endl;
    return 0;
}


Measured memory_bytes: 10704
#include <iostream>
#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>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, init, n) for(int i = init; i <(int)(n); i++)

int main() {

    ll N, Y;
    cin >> N >> Y;

    rep(i, 0, N + 1)rep(j, 0, N - i + 1){
        int k = N - i - j;
        ll tmp = i * 10000 + j * 5000 + k * 1000;
        if (tmp == Y){
            cout << i << " " << j << " " << k << endl;
            return 0;
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;

    return 0;
}

Measured memory_bytes: 384
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import Counter

h,w,m=nii()

h_bomb=[0 for i in range(h)]
w_bomb=[0 for i in range(w)]

l=set()
for i in range(m):
  th,tw=nii()
  th-=1
  tw-=1
  h_bomb[th]+=1
  w_bomb[tw]+=1
  l.add((th,tw))

h_max=max(h_bomb)
w_max=max(w_bomb)

h_cand=[]
w_cand=[]

for i in range(len(h_bomb)):
  if h_bomb[i]==h_max:
    h_cand.append(i)

for i in range(len(w_bomb)):
  if w_bomb[i]==w_max:
    w_cand.append(i)

for i in h_cand:
  for j in w_cand:
    if (i,j) not in l:
      print(h_max+w_max)
      exit()

print(h_max+w_max-1)


Measured memory_bytes: 83812
#include <algorithm>
#include <iostream>
#include <vector>
#include <bitset>
#include <unordered_map>
using namespace std;
const int N = 512;

int n, m;

void solve(vector<bitset<N>> &recipe) {
    unordered_map<bitset<N>, int> cur;
    bitset<N> zero;
    cur[zero] = 0;
    for (int i = 0; i < n; i++) {
        unordered_map<bitset<N>, int> nxt = cur;
        for (auto p: cur) {
            auto &tmp = nxt[p.first ^ recipe[i]];
            tmp = max(tmp, p.second + 1);
        }
        swap(cur, nxt);
    }
    cout << cur[zero] << endl;
}

int main() {
    while (cin >> n >> m, n) {
        vector<bitset<N>> recipe(n);
        for (auto &e: recipe) {
            string s; cin >> s; e = bitset<N>(string(N - m, '0') + s);
        }
        solve(recipe);
    }
    return 0;
}


Measured memory_bytes: 166788
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
typedef pair<ll, ll> p;

char f(char a, char b){
  if(a > b) swap(a, b);
  if(a == 'G' && b == 'R') return 'B';
  if(a == 'B' && b == 'G') return 'R';
  if(a == 'B' && b == 'R') return 'G';
  return '@';
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin >> n >> s;
  vector<int> r, g, b;
  rep(i, n){
    if(s[i] == 'R') r.push_back(i);
    if(s[i] == 'G') g.push_back(i);
    if(s[i] == 'B') b.push_back(i);
  }


  ll res = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i+1; j < n-1; ++j) {
      if(s[i] == s[j]) continue;
      // cout << i << ' ' << j << endl;
      char t = f(s[i], s[j]);
      int x = j - i;
      int num = 0;
      if(t == 'R'){
        num = int(r.size()) - (upper_bound(ALL(r), j) - r.begin());
        if(j+x < n && s[j+x] == 'R') num--;
      }
      if(t == 'G'){
        num = int(g.size()) - (upper_bound(ALL(g), j) - g.begin());
        if(j+x < n && s[j+x] == 'G') num--;
      }
      if(t == 'B'){
        // cout << upper_bound(ALL(b), j) - b.begin() << endl;
        num = int(b.size()) - (upper_bound(ALL(b), j) - b.begin());
        if(j+x < n && s[j+x] == 'B') num--;
      }
      // cout << num << endl;
      res += num;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 3648
from sys import stdin, setrecursionlimit
input = stdin.buffer.readline
setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 18

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

root = [i for i in range(N + 1)]
size = [1] * (N + 1)
 
def find(x):
  y = root[x]
  if x == y:
    return x
  else:
    z = find(y)
    root[x] = z
    return z

def union(x, y):
  rx = find(x)
  ry = find(y)
  sx = size[rx]
  sy = size[ry]
  if rx == ry:
    return 0
  else:
    if sx >= sy:
      root[ry] = rx
      size[rx] = sx + sy
    else:
      root[rx] = ry
      size[ry] = sx + sy
    return sx * sy

cnt = [0] * (N + 1)

for a, b in AB:
    union(a, b)
for i in range(1, N + 1):
    cnt[find(i)] += 1

print(max(cnt))

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


class Main {
    public static void main(String[] args) {
        Scanner scr = new Scanner(System.in);
//        int t = scr.nextInt();
//        while (t-- > 0)
        solve(scr);
    }


    static void solve(Scanner scr) {
        int N = scr.nextInt();
        int M = scr.nextInt();
        long a = N * (N - 1) / 2;
        long b = M * (M - 1) / 2;
        System.out.println(a+b);
    }


}





Measured memory_bytes: 22868
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define viit(a) vector<int>::iterator a
#define IT iterater
#define REP(i,a,n) for(ll i=a;i<(n);i++)
#define FOR(i,a,n) for(ll i=a;i<=(n);i++)
#define V vector
#define RE return
#define B(s) s.back()
#define all(a) a.begin(),a.end()
#define ER1(a) a.erase(a.begin())
#define ER0(a) a.erase(a.end())
#define Fill(a,b) memset(a,b,sizeof(a))
#define SO(a) sort(all(a))
#define pb push_back
#define pii pair<int,int>
#define pause system("PAUSE")
#define cls system("CLS")
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
	int tou,jiao;
	cin>>tou>>jiao;
	int he,wu;
	if((4*tou-jiao)<0||(4*tou-jiao)%2){
		cout<<"No";
		return 0;
	}
	else {
		he=(4*tou-jiao)/2;
		wu=tou-he;
	}
	if((jiao-2*tou)<0||(jiao-2*tou)%2){
		cout<<"No";
		return 0;
	}
	else {
		wu=(jiao-2*tou)/2;
		he=tou-wu;
	}
	if(he*2+wu*4==jiao)
	cout<<"Yes";
	else cout<<"No";
    return 0;
}


Measured memory_bytes: 3652
/* Filename: ABC073A.java
 * Author: Mushiyo
 */

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		
		while(input.hasNext()){
			int N = input.nextInt();
			boolean has9 = false;
			
			while(N > 0){
				int mod = N % 10;
				if(mod == 9){
					has9 = true;
					break;
				} else {
					N /= 10;
				}
			}
			
			if(has9){
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}

}


Measured memory_bytes: 20820
import numpy as np

N = int(input())
A = np.array(list(map(int,input().split())))
B = np.array(list(map(int,input().split())))
Bsi = np.argsort(B)
A2 = A[Bsi]
Bs = B[Bsi]
A2si = np.argsort(A2)
As = A2[A2si]
C = Bs-As
if any(C[C<0]):
    ans = 'No'
else:
    if all(As[1::]-Bs[:-1:] > 0):
        pi = 0
        i = 0
        while i<N-1:
            pi = A2si[pi]
            if pi == 0:
                ans = 'Yes'
                break
            else:
                i += 1
        else:
            ans = 'No'
    else:
        ans = 'Yes'
        
print(ans)


Measured memory_bytes: 24048
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vint a(n*3);
  rep(i,n*3){
    cin>>a[i];
  }
  sort(all(a),greater<int>());
  ll ans=0;
  rep(i,n*3-n){
    i++;
    ans+=a[i];
  }
  cout<<ans<<'\n';
  return(0);
}


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

int main() {
  ll x, k, d;
  cin >> x >> k >> d;

  ll ans = abs(x);
  ll quo = ans / d;
  ll rem = ans % d;

  if (quo < k) {
    ans = rem;
    k -= quo;
  } else {
    ans -= d*k;
    k = 0;
  }

  if (k%2 != 0) {
    if (ans > 0) {
      ans -= d;
    } else {
      ans += d;
    }
  }

  cout << abs(ans) << endl;

  return 0;
}


Measured memory_bytes: 3576
use std::collections::HashSet;
use std::cmp::Ordering;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub trait BinarySearch<T> {
    fn lower_bound(&self, &T) -> usize;
}

impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less => {
                    low = mid + 1;
                }
                Ordering::Equal | Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
}

fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let mut a = read_vec::<u64>();
    let mut b = read_vec::<u64>();
    a.sort();
    b.sort();
    let big_int = 1000_000_000 + 7;

    for i in 1..n {
        if a[i] == a[i - 1] {
            println!("0");
            return;
        }
    }

    for i in 1..m {
        if b[i] == b[i - 1] {
            println!("0");
            return;
        }
    }
    let dict_a = a.iter().cloned().collect::<HashSet<_>>();
    let dict_b = b.iter().cloned().collect::<HashSet<_>>();

    let mut ans = 1u64;
    for i in (1..n * m + 1).rev() {
        let i = i as u64;
        if dict_a.contains(&i) && dict_b.contains(&i) {
            continue;
        }
        if dict_a.contains(&i) {
            ans *= (m - b.lower_bound(&i)) as u64;
        } else if dict_b.contains(&i) {
            ans *= (n - a.lower_bound(&i)) as u64;
        } else {
            ans *= ((m - b.lower_bound(&i)) * (n - a.lower_bound(&i)) - (n * m - i as usize)) as u64;
        }
        // println!("{:?}", ans);
        ans %= big_int;
        if ans <= 0 {
            break;
        }
    }
    println!("{:?}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(void)
{
int N;
int KAZU=0; // 行う処理の回数
cin>>N;
vector < vector <int> > super;

for(int i=0;i<N;i++)
{
    int X,Y,Z;
    vector <int> a;
    cin>>X>>Y>>Z;
    a.push_back(X);
    a.push_back(Y);
    a.push_back(Z);
    sort(a.begin(),a.end());
    super.push_back(a);
}

sort(super.begin(),super.end());
super.erase(unique(super.begin(),super.end()),super.end());

cout<<N-super.size()<<endl;
}


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

int main(){
	int a,b,c;
  	cin >> a >> b >> c;
  	if((a==b && a!=c) || (b==c && a!=c) || (a==c && b!=a)){
    	cout << "Yes";
    }else{
    	cout << "No";
    }
    
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    if(a % 2 == b % 2) cout << (a + b)/2 << endl;
    else cout << (a+b)/2 + 1 << endl;

	return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <string>

using namespace std;

long long Si(string s)
{
    long long sum = 0ll;
    for (int i = 0; i < s.size(); ++i)
        sum = sum * 10 + (s[i] - '0');
    return sum;
}

long long Solve(string s, int index, long long sum)
{
    if (index == s.size())
    {
        return sum;
    }
    long long res = 0ll;
    for (int i = index; i < s.size(); ++i)
    {
//        cout << s.substr(index, i - index + 1) << "\n";
        res += Solve(s, i + 1, sum + Si(s.substr(index, i - index + 1)));
    }
    return res;
}

int main()
{
    string s;
    cin >> s;
    cout << Solve(s, 0, 0);
}


Measured memory_bytes: 3572
x,y,z,k = map(int,input().split())

info = [list(map(int,input().split())) for i in range(3)]

li = []
ans = []
li_append = li.append 
ans_append = ans.append

for i in info[0]:
  for j in info[1]:
    li_append(i+j)
li = sorted(li,reverse=True)

for i in li[:3000]:
  for j in info[2]:
    ans_append(i+j)
ans = sorted(ans,reverse = True)

for i in range(k):
  print(ans[i])

Measured memory_bytes: 163556
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}


//for(int i = ; i < ; i++){}

int main(){
  int n,m;
  cin>>n>>m;
  set <pair<int, int> > v;
  for(int i = 0; i < m; i++){
    int a,b;
    cin>>a>>b;
    a--; b--;
    pair<int, int> x1 = make_pair(a,b);
    pair<int, int> x2 = make_pair(b,a);
    v.insert(x1);
    v.insert(x2);
    }
    for(int i = 1; i < n-1; i++){
      pair<int, int> x1 = make_pair(0,i);
      pair<int, int> x2 = make_pair(i,n-1);
      if(v.count(x1)&&v.count(x2)){
        cout<<"POSSIBLE"<<endl;
        return 0;
      }
    }
    cout<<"IMPOSSIBLE"<<endl;
    return 0;
  }
  



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

#define PI 3.14159265358979

int main(){
 int a,b,c;
 double s,l,h;

 cin >> a >> b >> c ;

 s=a*b*sin(PI*c/180)/2;
 l=a+b+sqrt(a*a+b*b-2*a*b*cos(c*PI/180));
 h=b*sin(c*PI/180);

 cout << fixed << s << endl << l << endl << h << endl ;

 return 0;
}

Measured memory_bytes: 3472
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n, k;
    cin >> n >> k;
    ll kmax = (n-1) * (n-2) / 2;
    if(kmax < k) {
        cout << -1 << endl;
        return 0;
    }

    ll l = kmax - k;
    cout << n - 1 + l << endl;
    rep(i, 2, n+1) cout << 1 << " " << i << endl;
    rep(i, 2, n+1) rep(j, 2, n+1) {
        if (i >= j) continue;
        if (l > 0) {
            cout << i << " " << j <<endl;
            l--;
        }
    }
}

Measured memory_bytes: 256
import heapq
n,m= map(int,input().split())
a=list(map(int,input().split()))
move=list(tuple(map(int, input().split())) for _ in range(m))
heapq.heapify(a)
move.sort(key=lambda x:x[1],reverse=True)
for i in range(m):
    b=move[i][0]
    c=move[i][1]
    for i in range(b):
        res=heapq.heappop(a)
        if res<c:
            heapq.heappush(a,c)
        else:
            heapq.heappush(a,res)
            break
print(sum(a))

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

#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i=0;i<N;i++) cin >> A[i];
    int possess = 0;
    int money = 1000;
    for (int i=0;i<N-1;i++){
        if (possess && A[i] > A[i+1]) {
            money += possess*A[i];
            possess = 0;
        } else if (possess && A[i] < A[i+1]) {
            continue;
        } else if (!possess && A[i] > A[i+1]) {
            continue;
        } else if (!possess && A[i] < A[i+1]) {
            possess = money/A[i];
            money -= possess*A[i];
        }
    }
    money += possess*A[N-1];
    cout << money << "\n";
}

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

ll a[200005];
int b[200005];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    for(int i=0;i<=200002;i++)a[i]=0;
    ll n;
    ll tot=0;
    cin>>n;
    rep(i,n){
      int tmp;
      cin>>tmp;
      b[i]=tmp;
      a[tmp]++;
    }
    rep(i,n)tot+=a[i]*(a[i]-1)/2;

    rep(i,n){
      if(a[b[i]]!=0)cout<<tot-a[b[i]]+1<<endl;
      else cout<<tot<<endl;
    }
    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>  
#include <vector>    
#include <string>
using namespace std;
int main(){
   string str;
   cin >> str;
   if(str == ""){
       str = "aaa";
   }
   bool flag = false;
   int leng;
       while(flag == false){
           leng = str.length();
           string end;
           if(leng <5){
               flag = true;
               break;
           }else if(leng <6){
               end = str.substr(leng-5,leng); 
               if(end == "erase"){
               str.replace(leng-5,5,"");
               }else if(end == "dream"){
               str.replace(leng-5,5,"");
               }else{break;}
           }else if(leng <7){
               end = str.substr(leng-6,leng); 
               if(end == "eraser"){
               str.replace(leng-6,6,"");
               }else if(end.substr(1,5) == "erase"){
               str.replace(leng-5,5,"");
               }else if(end.substr(1,5) == "dream"){
               str.replace(leng-5,5,"");
               }else{break;}
           }else{
               end = str.substr(leng-7,leng);
               if(end.substr(1,6) == "eraser"){
               str.replace(leng-6,6,"");
               }else if(end.substr(2,6) == "erase"){
               str.replace(leng-5,5,"");
               }else if(end.substr(2,6) == "dream"){
               str.replace(leng-5,5,"");
               }else if(end == "dreamer"){
               str.replace(leng-7,7,"");
               }else{break;}
       }
       }
   if(str == ""){
   cout << "YES" << endl;
   }else{
   cout << "NO" << endl;
   }
   }

Measured memory_bytes: 512
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

int main(){
  string s;cin >> s;
  sort(all(s));
  if(s == "abc")cout << "Yes" << endl;
  else cout << "No" << endl;
 }


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#define maxn 100010
using namespace std;
typedef long long ll;
int n;
int a[maxn];
int b[maxn];
int x[maxn];
int y[2*maxn];
int ans;
bool check(int p)
{
    x[0]=n;
    memset(y,0,sizeof(y));
    y[n]=1;
    for (int i=1;i<=n;i++)
    {
        if(a[i]>=p)x[i]=x[i-1]+1;
        else x[i]=x[i-1]-1;
    }
    ll sum=0;
    ll t=0;
    for (int i=1;i<=n;i++)
    {
        if (x[i]>x[i-1])t-=(ll)y[x[i]];
        else t+=(ll)y[x[i-1]];
        sum+=t;
        y[x[i]]++;
    }
    ll tmp=(ll)n*(ll)(n+1)/4LL+1LL;
    tmp=(ll)n*(ll)(n+1)/2LL-tmp;
    t=(ll)n*(ll)(n+1)/2LL-sum;
    return t>=tmp;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)  cin>>a[i];
    for(int i=1;i<=n;i++)  b[i]=a[i];
    sort(b+1,b+n+1); 
    int l=1,r=n;
    while(l<=r)
    {
        int mid=(l+r)/2;
        if(check(b[mid])==true)
        {
            l=mid+1;
            ans=mid;
        }
        else r=mid-1;
    }
    printf("%d\n",b[ans]);
    return 0;
}

Measured memory_bytes: 2176
n = int(input())
h = list(map(int, input().split()))

c = [1e9 for _ in range(n)]
c[0] = 0

for i in range(1, n):
    c[i] = min(c[i], c[i - 1] + abs(h[i] - h[i - 1]))
    if 1 < i:
        c[i] = min(c[i], c[i - 2] + abs(h[i] - h[i - 2]))
print(c[-1])

Measured memory_bytes: 55496
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	long int x,a,b;
	cin>>x>>a>>b;
	if(b<=a)
		{
			cout<<"delicious\n";
			return 0;
		}
	else if(b-a<=x)
	{
		cout<<"safe\n";
		return 0;
	}
	else
	{
		cout<<"dangerous\n";
	}
	return 0;
}

Measured memory_bytes: 256