akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n,k,q;
  cin >> n >> k >> q;
  int a[n];
  for(int i = 0; i < n; i++){
    a[i] = k-q;
  }
  for(int i = 0; i < q; i++){
    int p;cin >> p;
    a[p-1]++;
  }
  for(int i = 0; i < n; i++){
    if(a[i] > 0){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1024
#BinarySearchTree
class TreeNode():
    def __init__(self):
        self.key = None
        self.parent = None
        self.left = None
        self.right = None
    def inoder(self):
        r=[]
        if self.left:
            r += self.left.inoder()
        r += [self.key]
        if self.right:
            r += self.right.inoder()
        return r
 
    def preoder(self):
        r = [self.key]
        if self.left:
            r += self.left.preoder()
        if self.right:
            r += self.right.preoder()
        return r
 
class BinaryTree():
    def __init__(self):
        self.root = None
 
    def insert(self, z):
        y = None
        x = self.root
        while x != None:
            y = x
            if z.key < x.key:
                x = x.left
            else:
                x = x.right
        z.parent = y
        if y == None:
            self.root = z
        elif z.key < y.key:
            y.left = z
        else:
            y.right = z
 
    def show(self):
        x = self.root
        print(" " + " ".join(map(str, self.root.inoder())))
        print(" " + " ".join(map(str, self.root.preoder())))
 
    def find(self, key):
        currentNode = self.root
        while currentNode:
            if key == currentNode.key:
                return currentNode
            else:
                if key < currentNode.key:
                    currentNode = currentNode.left
                else:
                    currentNode = currentNode.right
        return False
    def next(self, key):
        return self.min(key.right)
    def min (self, key):
        while key.left is not None:
           key = key.left
        return key
     
    def delete(self, key):
        z = self.find(key)
        if z == False: return
        if z.left and z.right:
            y = self.next(z)
        else:
            y = z
            if z == self.root:
                self.root = None
         
        if z.left:
            x = y.left
        else:
            x = y.right

        if x:
            x.parent = y.parent
        if y.parent is None:
            self.root = x
        elif y == y.parent.left:
            y.parent.left = x
        else:
            y.parent.right = x
        if y != z:
            z.key = y.key

n = int(input())
Tree = BinaryTree()
for i in range(n):
    L = input().split()
    if L[0] == "insert":
        Node = TreeNode()
        Node.key = int(L[1])
        Tree.insert(Node)
    if L[0] =="print":
        Tree.show()
    if L[0] =="find":
        if Tree.find(int(L[1])) == False:
            print("no")
        else:
            print("yes")
    if L[0] =="delete":
        Tree.delete(int(L[1]))

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

int main()
{
    int n;
    cin>>n;
    vector<int> west(n,0), east(n,0);
    string s;
    cin>>s;
    for(int i = 1; i<n; i++){
        if(s[i-1]=='W'){
            west[i]=west[i-1]+1;
        }
        else{
            west[i]=west[i-1];
        }
    }
    for(int i = n-2; i>=0; i--){
        if(s[i+1]=='E'){
            east[i]=east[i+1]+1;
        }
        else{
            east[i]=east[i+1];
        }
    }
    int mini = n;
    for(int i = 0; i<n; i++){
        mini = min(mini, west[i]+east[i]);
    }
    cout<<mini;
    return 0;
}


Measured memory_bytes: 3204
#include<stdio.h>
int main()
{
	int a,b,c;
	scanf("%d %d",&a,&b);
	if(a<=b){
		c=b;
		b=b-1;
		if(a<=b){
			printf("%d\n",c+b);
		}
		else{
			printf("%d\n",c+a);
		}
	}
	else{
		c=a;
		a=a-1;
		if(a<=b){
			printf("%d\n",c+b);
		}
		else{
			printf("%d\n",c+a);
		}
	}
	return 0;
}


Measured memory_bytes: 1736
# -*- coding: utf-8 -*-

"""
・ダイクストラ(優先度付きキュー)
"""

from heapq import heappop, heappush

# 今回はダイクストラするので、データの持ち方は隣接リスト
N = int(input())
nodes = [[] for _ in range(N+1)]
for i in range(N-1):
    a, b, c = map(int, input().split())
    # nodes[出発ノード](到着ノード, コスト))
    nodes[a].append((b, c))
    nodes[b].append((a, c))

def dijkstra(nodes, start):
    # 最短距離メモ
    memo = [float('inf')] * (len(nodes))
    # 訪問済メモ
    visited = [False] * (len(nodes))
    # スタート位置
    que = [(0, start)]
    memo[start] = 0
    # キューが空になるまで
    while len(que) != 0:
        # startからの距離, 現在のノード
        dist, cur = heappop(que)
        # 訪問済にする
        visited[cur] = True
        # 出発ノードcurの到着ノードでループ
        for i in range(len(nodes[cur])):
            nxt, cost = nodes[cur][i]
            # 訪問済ではない時だけ
            if not visited[nxt]:
                memo[nxt] = min(memo[cur] + cost, memo[nxt])
                # 現在の移動距離をキューの優先度として、早い方から先に処理するようにする
                heappush(que, (memo[nxt], nxt))
    # ノードstartからの最短距離リストを返却
    return memo

Q, K = map(int, input().split())
# 引数：(ノードの隣接リスト, 出発ノード)
memo = dijkstra(nodes, K)

for i in range(Q):
    x, y = map(int, input().split())
    print(memo[x] + memo[y])


Measured memory_bytes: 46656
import math

if __name__ == '__main__':
    p = [0 for k in range(100000)]
    p[1] = 1
    for k in range(3, 100000, 2):
        f = 1
        for l in range(2, int(math.sqrt(k)) + 1):
            if k % l == 0:
                f = 0
                break
        if f == 1:
            p[k] = 1

    check = [0 for k in range(100000)]
    check[3] = 1
    for k in range(3, 100000, 2):
        if p[k] + p[(k + 1) // 2] == 2:
            check[k] = 1
    for k in range(1, 100000):
        check[k] += check[k - 1]
    for k in range(int(input())):
        l, r = map(int, input().split())
        print(check[r] - check[l - 1])


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

vector<double> xs, ys, v;

int main() {
  int n;
  cin >> n;
  xs.resize(n); ys.resize(n); v.resize(n);
  rep(i,n){
    cin >> xs[i] >> ys[i];
    v[i] = i;
  }
  
  auto dist = [&](int i, int j) {
    double dx = xs[i] - xs[j];
    double dy = ys[i] - ys[j];
    return sqrt(dx*dx + dy*dy);
  };
  
  int cnt = 0;
  double result = 0;
  do {
    cnt++;
    rep(i, n-1) {
      result += dist(v[i], v[i+1]);
    }
  } while(next_permutation(v.begin(), v.end()));
  result /= cnt;
  printf("%.10f\n", result);
  return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;

int main() {
  int H, W; std::cin >> H >> W;
  int h, w; std::cin >> h >> w;
  std::cout << (H - h) * (W - w) << std::endl;
}


Measured memory_bytes: 764
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
#define N 421
#define M 38300
int s[N][3],v[N][2],n,m,l[N][2],r[N][2],head[N],cur[N],cnt,in[N],vis[N];
char c[12];
long long dis[N],c1[N],as1,as;
struct edge{int t,next,v;long long c;}ed[M];
void adde(int f,int t,int v,long long c){ed[++cnt]=(edge){t,head[f],v,c};head[f]=cnt;ed[++cnt]=(edge){f,head[t],0,-c};head[t]=cnt;}
bool spfa(int s,int t)
{
	memset(dis,-0x3f,sizeof(dis));
	memcpy(cur,head,sizeof(cur));
	queue<int> tp;
	tp.push(s);dis[s]=0;in[s]=1;
	while(!tp.empty())
	{
		int r=tp.front();tp.pop();in[r]=0;
		for(int i=head[r];i;i=ed[i].next)
		if(ed[i].v&&dis[ed[i].t]<dis[r]+ed[i].c)
		{
			dis[ed[i].t]=dis[r]+ed[i].c;
			if(!in[ed[i].t])in[ed[i].t]=1,tp.push(ed[i].t);
		}
	}
	return dis[t]>-1e18;
}
int dfs(int u,int t,int f)
{
	if(!f||u==t)return f;
	vis[u]=1;
	int tp,as=0;
	for(int& i=cur[u];i;i=ed[i].next)
	if(!vis[ed[i].t]&&ed[i].v&&dis[ed[i].t]==dis[u]+ed[i].c&&(tp=dfs(ed[i].t,t,min(f,ed[i].v))))
	{
		ed[i].v-=tp;ed[i^1].v+=tp;
		f-=tp,as+=tp;as1+=ed[i].c*tp;
		if(!f){vis[u]=0;return as;}
	}
	vis[u]=0;return as;
}
int dinic(int s,int t){int tp=0;while(spfa(s,t))tp+=dfs(s,t,1e8);return tp;}
int main()
{
	scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d%d%lld",&v[i][0],&v[i][1],&c1[i]);
	scanf("%d",&m);for(int i=1;i<=m;i++){scanf("%s%d%d",c+1,&s[i][1],&s[i][2]);if(c[1]=='U')s[i][0]=0;if(c[1]=='D')s[i][0]=1;if(c[1]=='R')s[i][0]=2;if(c[1]=='L')s[i][0]=3;}
	for(int i=1;i<=n;i++)
	{
		cnt=1;for(int j=1;j<=402;j++)head[j]=0;
		for(int j=1;j<=i;j++)l[j][0]=1,l[j][1]=100,r[j][0]=1,r[j][1]=100;
		for(int j=1;j<=m;j++)if(i>s[j][2])
		{
			int tp=s[j][2];
			if(s[j][0]==1)
			{
				for(int k=1;k<=i-tp;k++)l[k][0]=max(l[k][0],s[j][1]+1);
			}
			if(s[j][0]==0)
			{
				for(int k=tp+1;k<=i;k++)l[k][1]=min(l[k][1],s[j][1]-1);
			}
			if(s[j][0]==3)
			{
				for(int k=1;k<=i-tp;k++)r[k][0]=max(r[k][0],s[j][1]+1);
			}
			if(s[j][0]==2)
			{
				for(int k=tp+1;k<=i;k++)r[k][1]=min(r[k][1],s[j][1]-1);
			}
		}
		int s1=401,t=402;
		for(int j=1;j<=i;j++)adde(s1,j,1,0);
		for(int j=1;j<=i;j++)
		for(int k=l[j][0];k<=l[j][1];k++)
		adde(j,k+100,1,0);
		for(int j=1;j<=n;j++)adde(v[j][1]+100,v[j][0]+200,1,c1[j]);
		for(int j=1;j<=i;j++)
		for(int k=r[j][0];k<=r[j][1];k++)
		adde(k+200,j+300,1,0);
		for(int j=1;j<=i;j++)adde(j+300,t,1,0);
		as1=0;int tp2=dinic(s1,t);
		if(tp2==i)as=max(as,as1);
	}
	printf("%lld\n",as);
}//

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

using namespace std;
#define ll long long


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int d, t, s;
    cin >> d >> t >> s;
    if (s * t >= d) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 3636
/* ALDS1_1_A */
import java.io.*;

class Main
{

  public static void main(String[] args)
  {
    try{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      int n = Integer.parseInt(br.readLine());
      String[] str = br.readLine().split(" ");
      int[] array = new int[n];

      for(int i = 0; i < n; i++){
        array[i] = Integer.parseInt(str[i]);
      }
      insertionSort(array, array.length);

    }catch(Exception e){
      System.out.println(e);
    }
  }

  public static void insertionSort(int[] A, int N)
  {
    StringBuilder sb = new StringBuilder();
    sb.append(show(A));

    for(int i = 1; i < N; i++){
      int v = A[i];
      int j = i - 1;
      while(j >= 0 && A[j] > v){
        A[j+1] = A[j];
        j--;
      }
      A[j+1] = v;
      sb.append(show(A));
    }
    System.out.print(sb);
  }

  public static String show(int[] B)
  {
    StringBuilder sb = new StringBuilder();

    for(int i = 0; i < B.length; i++){
      sb.append(B[i]).append(" ");
    }
    sb.deleteCharAt(sb.length() - 1);
    sb.append("\n");

    return sb.toString();
  }
}

Measured memory_bytes: 26692
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        d: usize,
    }
    let acc = d * 2 + 1;
    println!("{}", (n + acc - 1) / acc);
}


Measured memory_bytes: 4352
//  cd Desktop/Atcoder
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define rep(i,n) for(i=0;i<(n);i++)
#define ll long long
#define ull unsigned long long
#define MOD 1000000007

int main(){
    int num=0,ans=0;
    char s[200002]={},t[200002]={};
    scanf("%s",s);
    scanf("%s",t);
    while (s[num]!='\0')
    {
        if (s[num]!=t[num])
        {
            ans++;
        }
        num++;
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 2124
#include<bits/stdc++.h>
using namespace std ;
int a[1200000];
int main()
{
	int sum=0;
	cin>>sum;
	int flag=0;
	for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			if(i*j==sum)
			flag=1;
		}
	}
	if(flag==1){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}


Measured memory_bytes: 256
n,k=map(int,input().split())
a=[int(j) for j in input().split()]
a.sort(reverse=True)
def f(x):
    c=0
    for i in a:
        if i<x:
            break
        c+=-(-i//x)-1
        if c>k:
            return False
    return True
left=0
right=a[0]
while right-left>1:
    mid=(left+right)//2
    if f(mid):
        right=mid
    else:
        left=mid
print(right)

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

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

  int ans;
  if(s=="RRR") ans=3;
  else if(s=="SSS") ans=0;
  else if(s[1]=='S') ans=1;
  else if(s=="SRS") ans=1;
  else ans=2;

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
int main(void){
    // Your code here!
    int X,Y;
    
    scanf("%d%d",&X,&Y);
    
    for(int i = 1; i <= X; i++){
        if((4*X - Y == 2 * i) || (Y - 2*X == 2*i)){
            printf("Yes\n");
            return 0;
        }
    }
    
    printf("No\n");
}


Measured memory_bytes: 1644
from collections import defaultdict
n,k = map(int, input().split())
ans = 0
al = []
d = defaultdict(int)
for i in range(n):
  a,b = map(int, input().split())
  al.append(a)
  d[a] += b
al = list(set(al))  
al.sort()
for i in al:
  if k > d[i]:
    k -= d[i]
  else:
    print(i)
    break

Measured memory_bytes: 20284
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int   n = sc.nextInt();
        
        // 二分ヒープ
        int[] h = new int[n+1];
        
        h[0] = Integer.MIN_VALUE;
        for (int i = 1; i <= n; i++) {
            h[i] = sc.nextInt();
        }
        
        // 最大ヒープを構築する。
        for (int i = n/2; i >= 1; i--) {
            maxHeapify(h, i);
        }
        for (int i = 1; i <= n; i++) {
            System.out.print(" " + h[i]);
        }
        System.out.println();
    }
    
    static void maxHeapify(int[] h, int idx) {
        int n = h.length - 1;
        int l = l(idx);
        int r = r(idx);
        // 左の子、自分、右の子で値が最大のノードを選ぶ
        int maxNodeIdx = 0;
        if (l <= n && h[l] > h[idx]) {
            maxNodeIdx = l;
        } else {
            maxNodeIdx = idx;
        }
        if (r <= n && h[r] > h[maxNodeIdx]) {
            maxNodeIdx = r;
        }
        // 子の方が値が大きい場合
        if (maxNodeIdx != idx) {
            int temp = h[idx];
            h[idx]        = h[maxNodeIdx];
            h[maxNodeIdx] = temp;
            maxHeapify(h, maxNodeIdx);
        }
    }
    
    static int l(int i) {
        return 2*i;
    }
    static int r(int i) {
        return 2*i + 1;
    }
}



Measured memory_bytes: 167532
import sys
sys.setrecursionlimit(300000) #上限上げないと引っかかる
n,q = map(int, sys.stdin.readline().rstrip().split())
sco = [0]*(n+1)
G =[[] for _ in range(n+1)]
for i in range(n-1):
    a,b = map(int, sys.stdin.readline().rstrip().split())
    G[a].append(b)
    G[b].append(a)

for j in range(q):
    p,x = map(int, sys.stdin.readline().rstrip().split())
    sco[p]+=x


#本体
seen = [False for _ in range(n+1)]
def dfs(G,V,score):
    global sco
    sco[V] +=score

    seen[V] = True
    for next_V in G[V]:
        if (seen[next_V]):
            continue
        dfs(G, next_V,sco[V])

#入力受け取り
#例
dfs(G,1,0)
print(*sco[1:])
#単にdfs(G,0)だと、木構造でないとき(頂点1つでない時)不正解


Measured memory_bytes: 232444
// Try yahoo procon 2019 qual
// author: Leonardone @ NEETSDKASU 

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!();
    let k = get!();
    
    let p = (n + 1) / 2;
    
    if p >= k {
    	println!("YES");
    } else {
    	println!("NO");
    }
    
}

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

int main(){
	
	ll n;
	cin >> n;
	ll maxx,ans=0;
	for(ll i=0;i<n;i++){
		ll temp;
		cin >> temp;
		if(i==0){
			maxx = temp;
			ans++;
		} else {
			if(maxx<=temp){
				ans++;
				maxx = temp;
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include <math.h>
long long int dp[100005];
int p;
long long int h[100005];
long long int t[100005];

int k;

long long int least(int n);

long long int minn(int t1,int t2);

int main()
{
//    int n;
for(int i=0;i<100005;i++)
{
    dp[i]=-1;
}
    scanf("%d %d",&p,&k);
    for(int i=0;i<p;i++)
    {
        scanf("%lld",&h[i]);
    }
    long long ans=least(0);
    printf("%lld\n",ans);
    return 0;
}

long long int least(int n)
{
    if(n==p-2)
    {
        long long t=fabs(h[p-2]-h[p-1]);
        return t;
    }
    if(n==p-1)
    {
        return 0;
    }
    if(dp[n]==-1)
    {

//        t1 = fabs(h[n] - h[n + 1]) + least(n + 1);
//        t2 = fabs(h[n] - h[n + 2]) + least(n + 2);
        int j;
        for(j=1; j <= k; j++)
          {
              if(n+j==p)
                  break;
              t[j]=fabs(h[n] - h[n + j]) + least(n + j);
          }
          dp[n] = minn(1,j-1);
//          printf("Hi\n");
    }
    return dp[n];
}

long long int minn(int u,  int v)
{
    long long int umin=t[u];
    for(int i=u+1;i<=v;i++)
    {
        if(t[i]<umin)
            umin=t[i];
    }
    return umin;
    //return 0;
}


Measured memory_bytes: 7936
n = int(input())
s = input()
l = ""
for i in range(len(s)):
    if (int(ord(s[i])) + n) >= 91:
        l += chr((int(ord(s[i])) + n) - 26)
    else:
        l += chr(int(ord(s[i])) + n)
print(l)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
	final static long MODULO = 1_000_000_000 + 7;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		long[][][] dp = new long[2][N + 2][N + 2];// [何日目][1を含む連結成分のサイズ][全体の訪れた町のサイズ]
		dp[0][1][1] = 1;
		for (int i = 0; i + 1 <= M; ++i) {
			dp[(i + 1) % 2] = new long[N + 2][N + 2];
			for (int j = 0; j <= N; ++j) {
				for (int k = j; k <= N; ++k) {
					dp[(i + 1) % 2][j][k] += dp[i % 2][j][k] * (k - j) % MODULO;
					if (dp[(i + 1) % 2][j][k] >= MODULO)
						dp[(i + 1) % 2][j][k] -= MODULO;
					dp[(i + 1) % 2][k][k] += dp[i % 2][j][k] * j % MODULO;
					if (dp[(i + 1) % 2][k][k] >= MODULO)
						dp[(i + 1) % 2][k][k] -= MODULO;
					dp[(i + 1) % 2][j][k + 1] += dp[i % 2][j][k] * (N - k) % MODULO;
					if (dp[(i + 1) % 2][k][k] >= MODULO)
						dp[(i + 1) % 2][j][k + 1] -= MODULO;
				}
			}
		}
		System.out.println(dp[M % 2][N][N]);
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 81752
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())

using namespace std;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}

using ll = long long;
constexpr int mod = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u * v / gcd(u, v);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);

    string S;
    int K;
    cin >> S >> K;

    vector<string> subs;
    FOR(i, 0, S.length()) {
        FOR(j, 1, min(6, (int)S.length() - i + 1)) {
            subs.emplace_back(S.substr(i, j));
        }
    }
    SORT(subs);
    subs.erase(unique(ALL(subs)), subs.end());

    cout << subs[K - 1] << endl;
    return 0;

}

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

int main() {
    int64_t N, X, M;
    cin >> N >> X >> M;

    vector<int64_t> A(M);
    A[0] = X;
    rep(i, M - 1) A[i + 1] = A[i] * A[i] % M;

    vector<int64_t> cum(M + 1);
    rep(i, M) cum[i + 1] += cum[i] + A[i];

    if(N <= M) {
        cout << cum[N] << '\n';
        return 0;
    }

    int s = 0, l = 1;
    map<int64_t, int> id;
    rep(i, M) {
        if(id.find(A[i]) != id.end()) {
            s = id[A[i]];
            l = i - s;
            break;
        }
        id[A[i]] = i;
    }

    N -= s + l;
    int64_t ans = cum[s + l];
    ans += (cum[s + l] - cum[s]) * (N / l);
    ans += cum[s + N % l] - cum[s];
    cout << ans << '\n';
}


Measured memory_bytes: 7860
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  ll x;
  cin >> x;
  	    ll offset = x/11LL;
    if(x%11LL==0LL) cout << offset*2LL <<endl;
    else if(x%11LL<=6LL) cout << offset*2LL+1LL <<endl;
    else cout << offset*2LL+2LL << endl;



  
  



  
  return 0;
    

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int N;
LL A[214514];

void Calc(vector<LL> &dp) {
  dp.resize(N+1);

  stack<pll> st;
  LL cnt = 0;
  LL len = 1;
  dp[N] = 0;
  dp[N-1] = 0;
  rrep(i, N-1) {
    //printf("i=%d: cnt=%lld len=%lld\n", i, cnt, len);
    if (A[i] > A[i+1]) {
      LL t = A[i+1];
      LL num = 0;
      while (t < A[i]) {
        t *= 4;
        num++;
      }
      
      while (!st.empty() && num > 0) {
        if (st.top().X <= num) {
          cnt += st.top().X * len;
          num -= st.top().X;
          len += st.top().Y;
          st.pop();
        } else {
          cnt += num * len;
          st.top().X -= num;
          num = 0;
          break;
        }
      }
      cnt += num * len;
      ++len;
    } else {
      LL t = A[i];
      LL num = 0;
      while (1) {
        t *= 4;
        if (t > A[i+1]) break;
        num++;
      }
      
      if (num == 0) len++;
      else {
        st.push(pii(num, len));
        len = 1;
      }
    }
    dp[i] = cnt * 2;
  }
}

int main() {
  scanf("%d", &N);
  rep(i, N) {
    scanf("%lld",  &A[i]);
  }

  vector<LL> dp1, dp2;
  Calc(dp1);
  reverse(A, A+N);
  Calc(dp2);

  /*printf("dp1: ");
  rep(i, N+1) {
    printf("%lld ", dp1[i]);
  }puts("");
  printf("dp2: ");
  rep(i, N+1) {
    printf("%lld ", dp2[i]);
  }puts("");*/
  
  LL ans = -1;
  rep(i, N+1) {
    LL cand = dp1[i] + i + dp2[N-i];
    //printf("dp1[%d]: %lld, dp2[%d]: %lld\n", i, dp1[i], N-i, dp2[N-i]);
    if (ans == -1) ans = cand;
    else MN(ans, cand);
  }
  printf("%lld\n", ans);
}


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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll,int> ii;
typedef pair <ii,int> iii;

const int mod = 1e9 + 7;
const int N = 100005;

int main(){
	fastio;
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    ll mvs = x/d, pos = x%d;
    if(mvs > k)mvs = k, pos = x - k*d;
    k -= mvs;
    if(k % 2 == 0)cout << pos << '\n';
    else cout << min(pos+d, abs(pos-d)) << '\n';
	return 0;
}


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

int main() {
  int N,M;
  cin >> N >> M;
  int H[N];
  rep(i,N) {
    cin >> H[i];
  }

  int b[N];

  rep(i,N) {
    b[i] = 1;
  }

  rep(i,M){
    int tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    
    if (H[tmp1-1]>=H[tmp2-1]) {
      b[tmp2-1] = -1;
    }
    if (H[tmp2-1]>=H[tmp1-1]) {
      b[tmp1-1] = -1;
    }
  }
  int ans = 0;
  rep(i,N) {
    if (b[i]==1) {
      ans++;
    }
  }
  cout << ans << endl;
}



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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  for (auto& e : p) cin >> e;
  sort(p.begin(), p.end());

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


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
//fflush(stdout);
int n,m,i,j,l,r,mid,ans;
string st,st1;
int main()
{
	cin>>n;
	cout<<0<<endl;
	fflush(stdout);
	cin>>st;
	if (st=="Vacant") return 0;
	l=1;r=n;ans=1;
	while (l<r)
	{
		mid=(l+r)/2;
		cout<<mid<<endl;
		fflush(stdout);
		cin>>st1;
		if (st1=="Vacant") return 0;
		if ((mid&1)^(st1!=st))
		{
			r=mid;
		}
		else
		{
			l=mid;
			ans=mid+1;
		}
	}
	cout<<ans<<endl;
	fflush(stdout);
	cin>>st;
	if (st=="Vacant") return 0;
	cout<<ans-1<<endl;
	fflush(stdout);
	cin>>st;
	if (st=="Vacant") return 0;
	cout<<ans+1<<endl;
	fflush(stdout);
	cin>>st;
	if (st=="Vacant") return 0;
	return 1;
}

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

string f(ll n) {
  if(n == 0) return "";
  n--;
  return f(n/26) + string(1,'a'+ n%26);
}

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

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		int C = scanner.nextInt();
		if ((A == 7 && C + B == 10) || (B == 7 && A + C == 10) || (C == 7 && A + B == 10))
			System.out.println("YES");
		else
			System.out.println("NO");
		scanner.close();
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

#define rep(i, ns, ne) for (ll i = ns; i < ne; ++i)

ll N;
void input() { cin >> N; }

// powmod x^y (%mod)
ll pm(ll x, ll y) {
  ll ret = 1;
  rep(i, 0, y) ret = ret * x % MOD;
  return ret;
}

void solve() {
  ll ans = (pm(10, N) + pm(8, N) - pm(9, N) - pm(9, N));
  ans %= MOD;
  ans = (ans + MOD) % MOD;
  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  input();
  solve();
  getchar();
}

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

long long A[200000];
long long cum_sumA[200000];

int calc_boundary(int begin, int end){
    //前半の和が後半の和未満になるもの内前半の和が最大となる分け方の後半の最初のインデックスを返す
    int left = begin;
    int right = end;
    long long begin_base;
    if(begin == 0){
        begin_base = 0;
    } else {
        begin_base = cum_sumA[begin - 1];
    }

    if(A[right] > cum_sumA[right - 1] - begin_base){
        //rightが答え
        return right;
    }
    while(left + 1 < right){
        int next = (left + right) / 2;
        if(cum_sumA[next - 1] - begin_base < cum_sumA[end] - cum_sumA[next - 1]){
            left = next;
        } else {
            right = next;
        }
    }
    return left;
}

void set_sums(long long &P, long long &Q, int begin, int end, int boundary){
    long long begin_base;
    if(begin <= 0){
        begin_base = 0;
    } else {
        begin_base = cum_sumA[begin - 1];
    }
    long long first_P;
    long long first_Q;

    long long first_diff = LLONG_MAX;
    if(boundary > begin){
        first_P = cum_sumA[boundary - 1] - begin_base;
        first_Q = cum_sumA[end] - cum_sumA[boundary - 1];
        first_diff = max(first_P, first_Q) - min(first_P, first_Q);
    }

    long long second_P;
    long long second_Q;

    long long second_diff = LLONG_MAX;
    if(boundary + 1 <= end){
        second_P = cum_sumA[boundary] - begin_base;
        second_Q = cum_sumA[end] - cum_sumA[boundary];
        second_diff = max(second_P, second_Q) - min(second_P, second_Q);
    }

    if(first_diff > second_diff){
        P = second_P;
        Q = second_Q;
    } else {
        P = first_P;
        Q = first_Q;
    }

    return;
}

int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    cum_sumA[0] = A[0];
    for(int i = 1; i < N; i++){
        cum_sumA[i] = A[i] + cum_sumA[i - 1];
    }

    long long ans = LLONG_MAX;
    for(int i = 2; i < N - 1; i++){
        int PQ_boundary = calc_boundary(0, i - 1);
        int RS_boundary = calc_boundary(i, N - 1);

        long long P;
        long long Q;
        long long R;
        long long S;

        set_sums(P, Q, 0, i - 1, PQ_boundary);
        //cout << P << " " << Q << " " << 0 << " " << i - 1 << " " << PQ_boundary << endl;
        set_sums(R, S, i, N - 1, RS_boundary);

        //cout << i << endl;
        //cout << P << " " << Q << " " << R << " " << S << endl;
        //cout << PQ_boundary << " " << RS_boundary << endl;
        ans = min(ans, max(P, max(Q, max(R, S))) - min(P, min(Q, min(R, S))));
    }

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


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    char a, b;
    cin >> a >> b;
    if(a == b) cout << 'H' << endl;
    else cout << 'D' << endl;
    return 0;
}

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

using namespace std;

int main(void){
    string S;
    cin >> S;
    int ans = 0;
    for(int i = 0; 2 * i < S.length(); i++){
        if(S[i] != S[S.length() - i - 1]) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    int K, A, B;

    cin >> K;
    cin >> A >> B;

    if(A%K != 0 && B%K !=0 && A/K == B/K) cout << "NG" << endl;
    else cout << "OK" << endl;

    return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  200001

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
    
    int n, a[max]={0};
    int sum=0;
    
    scanf("%d", &n);
    rep(i, n){
        scanf("%d", &a[i]);
    }
    
    qsort(a, n, sizeof(int), down_comp);
    
    for (int i=0; i<n; i=i+2) {
        sum+=abs(a[i+1]-a[i]);
    }
    
    printf("%d", sum);
    
    return 0;
}


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

ll INF = 1LL << 60;

int 
main() {
  ll N; cin >> N;
  vector<ll> arr(N + 1, 0);
  vector<ll> order(N);
  rep(i, 0, N){
    ll tmp; cin >> tmp;
    arr[tmp]++;
    order[i] = tmp;
  }

  vector<ll> comp(N + 1);
  rep(i, 1, N + 1){
    ll num = arr[i];
    comp[i] = num * (num - 1) / 2;
  }

  ll sum = 0;
  rep(i, 1, N + 1) sum += comp[i];

  rep(i, 0, N){
    ll num = arr[order[i]];
    --num;
    ll tmp_comp = num * (num - 1) / 2;
    cout << sum - comp[order[i]] + tmp_comp << endl;
  }
}


Measured memory_bytes: 7940
import java.util.Scanner;
import java.util.stream.IntStream;
class Main{
    public static void main(String[]$){
        Scanner s=new Scanner(System.in);
        int n=s.nextInt(),k=s.nextInt();
        System.out.println(IntStream.range(0,n).map(i->s.nextInt()).sorted().skip(n-k).sum());
    }
}


Measured memory_bytes: 26704
#include <iostream>
using namespace std;
typedef long long ll;
ll ans, lens, lent;
string s, t;
int main(void){
    // Your code here!
    cin >> s >> t;
    lens = s.length();
    lent = t.length();
    for (ll i = lens - lent; i >= 0 ; i--) {
        ans = 0;
        for (ll j = 0; j < lent; j++) {
            if (s[i + j] == t[j] || s[i + j] == '?') ans++;
        }
        if (ans == lent) {
            for (ll j = 0; j < lens; j++) {
                if (s[j] == '?') s[j] = 'a';
            }
            for (ll j = 0; j < lent; j++) {
                s[i + j] = t[j];
            }
            cout << s << endl;
            return 0;
        }
    }
    cout << "UNRESTORABLE" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<complex>
#include<algorithm>
#include<vector>
#include<math.h>
#include<set>
#include<map>
#include<queue>

int main()
{
	int n, m, count{}, last = -1;
	std::priority_queue<int> btoa[100000];
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		btoa[b - 1].push(a - 1);
	}
	for (int i = 0; i < n; i++)
	{
		if (btoa[i].empty() || btoa[i].top() < last) continue;
		last = i;
		count++;
	}
	printf("%d\n", count);

	return 0;
}

Measured memory_bytes: 5632
#include<iostream>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<string>
#include<algorithm>

#define rep(i, a) for (int i = 0; i < a; i++)
#define reps(i, s, a) for (int i = s; i < a; i++)
#define llint long long int
using namespace std;

const int N_MAX = 505;
const llint INF = 999999999999999;

int sc[26], tc[26];

int main()
{
    string s, t;
    cin >> s >> t;
    int sz = s.size();
    //string::iterator sitr = s.begin(), titr = t.begin();


    
    rep(i, sz) {
        sc[s[i] - 97]++;
        tc[t[i] - 97]++;
    }

    sort(sc, sc + 26);
    sort(tc, tc + 26);

    /*rep(i, 26) cout << sc[i];
    cout << endl;
    rep(i, 26) cout << tc[i];*/

    int jdg = 0;
    rep(i, 26) if (sc[i] == tc[i]) jdg++;

    if (jdg == 26) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 776
mod = 998244353
rng = 300100
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
  finv.append(pow(fctr[i],mod-2,mod))
def cmb(n,k):
  if n<0 or k<0:
    return 0
  else:
    return fctr[n]*finv[n-k]*finv[k]%mod
n,a,b,k = map(int,input().split())
pair = []
for i in range(n+1):
  if (k-a*i)%b == 0 and (k-a*i)//b <= n:
    pair.append((i,(k-a*i)//b))
ans = 0
for x,y in pair:
  ans = (ans+cmb(n,x)*cmb(n,y))%mod
print(ans)

Measured memory_bytes: 66652
#include <stdio.h>

main()
{
int W,H,x,y,r;
int xl,xr,yl,yr;

scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

xl=r;
xr=W-r;
yl=r;
yr=H-r;

if((xl<=x) && (x<=xr) && (yl<=y) && (y<=yr)) printf("Yes\n");
else printf("No\n");
}

Measured memory_bytes: 1012
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	int n, m, l;
	cin >> n >> m >> l;
	vvi d(n, vi(n, INF));

	rep(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;b--;
		d[a][b] = c;
		d[b][a] = c;
	}

	rep(k, n)rep(i, n)rep(j, n)d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
	
	vvi sup(n, vi(n, INF));
	rep(i, n)rep(j, n)if (d[i][j] <= l)sup[i][j] = 1;
	rep(k, n)rep(i, n)rep(j, n)sup[i][j] = min(sup[i][j], sup[i][k] + sup[k][j]);

	int q;
	cin >> q;
	rep(i, q) {
		int s, t;
		cin >> s >> t;
		s--;t--;

		if (sup[s][t] == INF)cout << -1 << endl;
		else cout << sup[s][t] - 1 << endl;
	}

}

Measured memory_bytes: 4360
#include<cstdio>
#include<algorithm>
#include<vector>
#define N_ 201000
using namespace std;
int n, X, Y, F[N_], w[N_], C[N_], res;
int FF[N_], InvF[N_], Mod = 1000000007;
int UF[N_];
vector<int>G[N_];
int Find(int a){
    if(a==UF[a])return a;
    return UF[a] = Find(UF[a]);
}
void Make(int a, int b){
    if(a==b||b==-1)return;
    if(C[a]==C[b] && w[a]+w[b] > X)return;
    if(C[a]!=C[b] && w[a]+w[b] > Y)return;
    a = Find(a),b=Find(b);
    UF[a]=b;
}
int Pow(int a, int b){
    int r = 1;
    while(b){
        if(b&1)r=1ll*r*a%Mod;
        a=1ll*a*a%Mod;b>>=1;
    }
    return r;
}
int Get(vector<int>&P){
    sort(P.begin(),P.end());
    int i, m = P.size(), c = 0;
    int r = FF[m];
    for(i=0;i<m;i++){
        c++;
        if(i==m-1 || P[i]!=P[i+1]){
            r = 1ll*r*InvF[c]%Mod;
            c = 0;
        }
    }
    return r;
}
int main(){
    int i;
    scanf("%d%d%d",&n,&X,&Y);
    for(i=1;i<=n;i++){
        UF[i] = i;
        scanf("%d%d",&C[i],&w[i]);
        if(!F[C[i]] || w[F[C[i]]] > w[i]) F[C[i]] = i;
    }
    int M1 = 1e9, M2 = 1e9, t1 = -1, t2 = -1;
    for(i=1;i<=n;i++){
        if(!F[i])continue;
        if(M1 > w[F[i]]){
            M2 = M1, t2 = t1;
            M1 = w[F[i]], t1 = F[i];
        }
        else if(M2 > w[F[i]])M2 = w[F[i]],t2 = F[i];
    }
    for(i=1;i<=n;i++){
        Make(i, F[C[i]]);
        Make(i, t1);
        Make(i, t2);
    }
    FF[0] = 1;
    for(i=1;i<=n;i++)FF[i] = 1ll*FF[i-1]*i%Mod;
    InvF[n] = Pow(FF[n],Mod-2);
    for(i=n;i>=1;i--)InvF[i-1] = 1ll*InvF[i]*i%Mod;
    for(i=1;i<=n;i++){
        G[Find(i)].push_back(C[i]);
    }
    res = 1;
    for(i=1;i<=n;i++){
        if(!G[i].empty()) res = 1ll*res*Get(G[i])%Mod;
    }
    printf("%d\n",res);
}

Measured memory_bytes: 15488
#include <bits/stdc++.h>
#define ll long long
#define pi 3.14159265358979
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
const int INF = 1000100100;
 
 
int main(){
    ll n,a,b,cnt=0,flag=0;
    cin>>n;
    rep(i,n){
        cin>>a>>b;
        if(a==b){
            cnt++;
        }else{
            cnt=0;
        }
        if(cnt==3){
            flag=1;
        }
    }
    if(flag==1){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int N;
string S;
int main() {
    cin >> N;
    cin >> S;
    int max = 0;

    for(int i = 1; i < N; ++i) {
        int cnt = 0;
        vector<int> alpl(30, 0);
        vector<int> alpr(30, 0);
        // 前半の探索
        for(int j = 0; j < i; ++j) {
            if(alpl.at((int)S.at(j) - 97) == 0) {
                alpl.at((int)S.at(j) - 97) = 1;
            }
        }

        // 後半の探索
        for(int k = i; k < N; ++k) {
            if(alpr.at((int)S.at(k) - 97) == 0) {
                alpr.at((int)S.at(k) - 97) = 1;
            }
        }

        for(int i = 0; i < 26; ++i) {
            if(alpl.at(i) == 1 && alpl.at(i) == alpr.at(i)) {
                cnt++;
            }
        }

        if(max < cnt) {
            max = cnt;
        }
    }

    cout << max << endl;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#define pll              pair<long,long>
#define pii              pair<int,int>
#define scn(a)           scanf("%d", &a)
#define scn2(a, b)       scanf("%d%d", &a, &b)
#define scn3(a, b, c)    scanf("%d%d%d", &a, &b, &c)
#define pairl            pair<ll , ll >
#define scnl(a)          scanf("%lld", &a)
#define scnl2(a, b)      scanf("%lld%lld", &a, &b)
#define scnl3(a, b, c)   scanf("%lld%lld%lld", &a, &b, &c)
#define scns(s)          scanf("%s",s)
#define prts(s)          printf("%s\n",s)
#define prt(a)           printf("%d\n", a)
#define prtl(a)          printf("%lld\n", a)
#define prs(a)           printf("%d ", a)
#define prt2(a, b)       printf("%d %d\n", a, b)
#define prt3(a, b, c)    printf("%d %d %d\n", a, b, c)
#define prsl(a)          printf("%lld ", a)
#define prtl2(a, b)      printf("%lld %lld\n", a, b)
#define prtl3(a, b, c)   printf("%lld %lld %lld\n", a, b, c)
#define ptcs(a)          printf("Case %d: ", a)
#define pf               printf
#define sc               scanf
#define vi               vector<int >
#define vil              vector<ll >
#define pb               push_back
#define mem(a, b)        memset((a), (b), sizeof(a))
#define lg2(n)           (31-__builtin_clz(n))
#define N                300005
#define inf              9999999
#define ll               long long
#define ull              unsigned long long
#define MIN              INT_MIN
#define MAX              INT_MAX
#define fast             ios_base::sync_with_stdio(false),cin.tie(NULL)
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree<pair<int, int> , null_type, less<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update> odrst;
ll gcd(ll a, ll b){if(b==0) {return a;}return gcd(b, a % b);}
ll BigMod(ll B,ll P,ll M){     ll R=1; while(P>0)      {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;}
//___________________________________________________________________________________________________________________

int main()
{
    ll n,m,t,x,y,k;
    cin>>n;
    for(int i=n;;i++)
    {
        bool ok=true;
        for(int j=2;j<n;j++)
        {
            if(i%j==0)
            {
                ok=false;
                break;
            }
        }
        if(ok)
        {
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    long[] a = sc.nextLongArray(n);
    Arrays.sort(a);
    if (a[0] == 0L) {
      System.out.println(0);
      return;
    }
    BigInteger mul = BigInteger.valueOf(1L);
    BigInteger max = BigInteger.valueOf(1_000_000_000_000_000_000L);
    for (long ai: a) {
      mul = mul.multiply(BigInteger.valueOf(ai));
      if (mul.compareTo(max) > 0) {
        System.out.println(-1);
        return;
      }
    }
    System.out.println(mul.toString());
  }
}

Measured memory_bytes: 49704
r1 = list(map(int,input().split()))
r2 = list(map(int,input().split()))
r3 = list(map(int,input().split()))
c1 = [r1[0],r2[0],r3[0]]
c2 = [r1[1],r2[1],r3[1]]
c3 = [r1[2],r2[2],r3[2]]
d1 = [r1[0],r2[1],r3[2]]
d2 = [r1[2],r2[1],r3[0]]
l = [r1,r2,r3,c1,c2,c3,d1,d2]

n = int(input())
b = [int(input()) for i in range(n)]

def bingo(num):
    for i in l:
        try:
            i.remove(num)
        except:
            pass

        for j in l:
            if j == []:
                return True
    return False

for i in b:
    if bingo(i):
        print("Yes")
        exit()
else:
    print("No")

Measured memory_bytes: 3188
#include <iostream>

int main(int argc, char const* argv[])
{
	int a,b;
	std::cin >> a >> b;
	if (a==b) {
		std::cout << "a == b";
	}
	if (a > b) {
		std::cout << "a > b";
	}
	if (a < b) {
		std::cout << "a < b";
	}
	std::cout << std::endl;
	return 0;
}

Measured memory_bytes: 1156