akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

string S;

bool ken (int str, int goal) {
  for (int i = str-1; i <= goal+1; i++) {
    int cnt = 0;
    while(S[i] == '.' && i <= goal+1) {
      cnt++;
      i++;
    }
    if (cnt >= 3) return true;
  }
  return false;
}

bool kenken(int str, int goal) {
  int now = str;
  for (now = str; now < goal; now++) {
    if (S[now+1] == '.') continue;
    else if (now+2 <= goal && S[now+1] == '#' && S[now+2] == '.') now++;
    else break;
  }
  return now == goal;
}

int main() { 
  int N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  --A; --B; --C; --D;
  cin >> S;
  bool snuke = kenken(A, C);
  bool fnuke = kenken(B, D);
  bool ok = true;
  if (C > D) ok = ken(B, D);
  if (snuke && fnuke && ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3740
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
using namespace std;

string ansFizzBuzz(int n) {
    string result;
    if (n % 15 == 0) {
        result = "FizzBuzz";
    } else if (n % 3 == 0) {
        result = "Fizz";
    } else if (n % 5 == 0) {
        result = "Buzz";
    } else {
        stringstream ss;
        ss << n;
        ss >> result;
    }
    return result;
}

int main() {
    while (true) {
        int m, n;
        cin >> m >> n;
        if ((m | n) == 0) {
            break;
        }
        vector<int> players(m);
        for (int i = 0; i < m; i++) {
            players[i] = i + 1;
        }
        vector<string> lines(n);
        for (int i = 0; i < n; i++) {
            cin >> lines[i];
        }
        int pos = 0;
        for (int i = 0; i < n; i++) {
            if (players.size() <= 1) {
                break;
            }
            if (lines[i] != ansFizzBuzz(i + 1)) {
                players.erase(players.begin() + pos);
            } else {
                pos++;
            }
            pos = pos % players.size();
        }
        string result;
        for (vector<int>::iterator it = players.begin(); it != players.end(); it++) {
            stringstream ss;
            ss << *it;
            result += " " + ss.str();
        }
        result.erase(0, 1);
        cout << result << endl;
    }
}

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

using namespace std;
using ll = long long;

int main() {
    int n;
    cin>>n;
    int m;
    cin>>m;
    for(int i = 0;i < m;++i) {
        int a;
        cin>>a;
        n-=a;
    }
    if(n<0)cout<<-1<<endl;
    else cout<<n<<endl;
    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
using namespace std;
int main(){
  int n, a, b;
  bool result=false;
  cin >> n >> a >> b;
  for(int i=a; i<=b; i++){
    if(i%n==0) result = true;
  }
  if(result) cout << "OK";
  else cout << "NG";
  return 0;
}

Measured memory_bytes: 3620
n = int(input())
a = list(map(int, input().split()))

p = list(range(n))
p.sort(key=lambda i: a[i])

dp = [0] * (n + 1)

for i in range(n):
    for j in range(n - i):
        dp[j] = max(dp[j]     + a[p[i]] * abs(p[i] - (j + i)),dp[j + 1] + a[p[i]] * abs(p[i] - j))

print(dp[0])


Measured memory_bytes: 9164
def getval():
    h,w = map(int,input().split())
    s = [input() for i in range(h)]
    return h,w,s

def main(h,w,s):
    #Find numbers of whites 
    whites = 0
    for i in s:
        for j in range(w):
            if i[j]==".":
                whites += 1

    #Find the shortest path
    d = [[-1 for i in range(w)] for j in range(h)]
    q = [[0,0,0]]
    d[0][0] = 0
    while q:
        idx = q.pop(0)
        adj = [[idx[0]+1,idx[1],idx[2]+1],[idx[0]-1,idx[1],idx[2]+1],[idx[0],idx[1]+1,idx[2]+1],[idx[0],idx[1]-1,idx[2]+1]]
        for i in adj:
            if i[0]<0 or i[1]<0 or i[0]>=h or i[1]>=w:
                continue
            if d[i[0]][i[1]]!=-1:
                continue
            if s[i[0]][i[1]]=="#":
                continue
            q.append(i)
            d[i[0]][i[1]] = i[2]

    dist = d[h-1][w-1]
    
    #Compute the score
    if dist==-1:
        print(-1)
    else:
        print(whites-dist-1)

if __name__=="__main__":
    h,w,s = getval()
    main(h,w,s)

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

using namespace std;

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

    if ((n[0] == n[1] && n[1] == n[2]) || (n[1] == n[2] && n[2] == n[3]))
        cout << "Yes\n";
    else
        cout << "No\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <deque>
#include <list>
#include <set>
#include <random>
#include <deque>
#include <unordered_set>

using namespace std;
using ll = long long;
const int BIG = 1000000007;


int main() {
    ll x;
    cin >> x;
    cout << ((x == 1) ? 0 : 1) << endl;
}




Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
int N, A[200010]; 
vector<int> E[200010]; 
int ans[200010]; 
int LIS[200010];
pair<int, int> backup[200010];   
int INF = 1145141919; 
void dfs(int v, int p){
	int a = lower_bound(LIS, LIS + N, A[v]) - LIS; 
	backup[v] = make_pair(a, LIS[a]); 
	LIS[a] = A[v]; 
	int b = lower_bound(LIS, LIS + N, INF) - LIS; 
	ans[v] = b; 
	for(auto i : E[v]){
		if(i == p) continue; 
		dfs(i, v); 
	}
	LIS[backup[v].first] = backup[v].second;  
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0); 
	cin >> N;  
	for(int i = 0; i < N; i++) cin >> A[i]; 
	for(int i = 0; i < N-1; i++){
		int u, v; cin >> u >> v; 
		u--; v--; 
		E[u].push_back(v); E[v].push_back(u); 
	}
	fill(LIS, LIS + 200005, INF); 
	dfs(0, -1); 
	for(int i = 0; i < N; i++) cout << ans[i] << "\n"; 
}

Measured memory_bytes: 32852
n,a,b = (int(i) for i in input().split())
x = list(int(i) for i in input().split())
ans = 0
for i in range(n-1):
 dist  = x[i+1]-x[i]
 move = dist*a
 if move <= b:
  ans += move
 else:
  ans += b
print(ans)
      
      

Measured memory_bytes: 14224
#include <stdio.h>

long long absu(long long  a){
  if(a > 0){
    return a;
  }
  return -a;
}

long long gcd(long long a,long long b){
  if(b > 0){
    gcd(b,a%b);
  }else{
    return a;
  }
}

int main(void){
  long N;
  long long X,data;
  scanf("%ld%lld",&N,&X);
  long long x[N];

  for(int i = 0;i < N;i++){
    scanf("%lld",&data);
    x[i] = absu(X-data);
  }

  long long ans = x[0];
  for(int i = 1;i < N;i++){
    ans = gcd(x[i],ans);
  }

  printf("%lld",ans);

  return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int dy[4]={1,0,-1,0};
int dx[4]={0,1,0,-1};
vector<vector<int>> graph;
bool sort_sec(const pair<int,int> &a,const pair<int,int> &b){
   if(a.second<b.second){
      return true;
   }
   return false;
}
int main(void){
   int N;
   cin>>N;
   vector<int> D(N);
   for(int i=0;i<N;i++){
      cin>>D[i];
   }
   int M;
   cin>>M;
   vector<int> T(M);
   for(int i=0;i<M;i++){
      cin>>T[i];
   }
   map<int,int> count1;
   map<int,int> count2;
   for(int i=0;i<N;i++){
      count1[D[i]]++;
   }
   for(int i=0;i<M;i++){
      count2[T[i]]++;
   }
   for(auto c:count2){
      if(count1[c.first]<c.second){
         cout<<"NO"<<endl;
         return 0;
      }
   }
   cout<<"YES"<<endl;
   return 0;
}

Measured memory_bytes: 20608
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main()
{
	string a[1000];
  	int n,l;
  	cin>>n>>l;
	for(int i=0;i<n;i++)
      cin>>a[i];
  	for(int i=0;i<n;i++)
    {
      	for(int j=n-1;j>i;j--)
        {
          	if(a[j]<a[j-1])
              swap(a[j],a[j-1]);
        }
   }
	for(int i=0;i<n;i++)
      cout<<a[i];

}

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

int d, g;
int p[100], c[100];

int main() {
	int i, j;
	
	cin >> d >> g;
	for (i = 0; i < d; i++) cin >> p[i] >> c[i];
	
	int ans = 114514;
	for (i = 0; i < (1 << d); i++) {
		int score = 0;
		int cnt = 0;
		
		//完答ボーナスを先に取る
		for (j = 0; j < d; j++) {
			if ((i >> j) & 1) {
				score += p[j] * 100 * (j + 1) + c[j];
				cnt += p[j];
			}
		}
		
		//配点が高い問題から解く
		for (j = d - 1; j >= 0; j--) {
			if ((i >> j) % 2 == 0) {
				int num = (g - score + 100 * (j + 1) - 1) / (100 * (j + 1));
				if (num < 0) num = 0;
				if (num > p[j]) num = p[j];
				score += num * 100 * (j + 1);
				cnt += num;
			}
		}
		if (score >= g) {
			ans = min(ans, cnt);
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);

    vector<vector<int>> g(N, vector<int>(N, -1));
    rep(i, N) {
        cin >> A[i];
        rep(j, A[i]) {
            int a, b;
            cin >> a >> b;
            --a;
            g[i][a] = b;
        }
    }

    int ans = 0;
    rep(bit, 1 << N) {
        vector<int> d(N);
        rep(i, N) if (bit >> i & 1) {
            d[i] = 1;
        }
        bool flag = true;
        rep(i, N) {
            if (d[i]) {
                rep(j, N) {
                    if (g[i][j] == -1)
                        continue;

                    if (g[i][j] != d[j])
                        flag = false;
                }
            }
        }
        if (flag)
            ans = max(ans, __builtin_popcount(bit));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N=int(input())
dp=[i for i in range(N+1)]

for i in range(1, N+1):
    n = 1
    while n <= i:
        dp[i] = min(dp[i], dp[i-n]+1)
        n*=6
    n = 1
    while n <= i:
        dp[i] = min(dp[i], dp[i-n]+1)
        n*=9

print(dp[N])

Measured memory_bytes: 7064
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

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

  int n, k;
  cin >> n >> k;
  int x[n];
  for(int i = 0; i < n; i++){
    cin >> x[i];
  }

  int sum = 0;
  for(int i = 0; i < n; i++){
    sum += min(x[i] * 2, abs(k - x[i]) * 2);
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    set<long long int>st;
    int q; cin>>q;
    for( int i=0; i<q; i++ )
    {
        int a; cin>>a;
        int x; cin>>x;
        if(a==0)
        {
            st.insert(x);
            cout<<st.size()<<endl;
        }
        else
        {
            int ps=st.size();
            st.insert(x);
            int s=st.size();
            if(ps==s) cout<<1<<endl;
            else
            {
                cout<<0<<endl;
                st.erase(x);
            }
        }

    }

}



Measured memory_bytes: 12392
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    A, B = LI()
    if (A+B)%2 != 0:
        print('IMPOSSIBLE')
    else:
        print((A+B)//2)

main()

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {
        public static void main(String[] args){
                final Scanner sc = new Scanner(System.in); 
                int n=sc.nextInt();
                int[][] graph=new int[n+1][n+1];
                for(int i=0;i<n;i++){
                        int u=sc.nextInt();
                        int k=sc.nextInt();
                        for(int j=0;j<k;j++){
                        graph[u][sc.nextInt()]++;
                        }
                }
                for(int i=1;i<=n;i++){
                        for(int j=1;j<=n;j++){
                                if(j==n) System.out.println(graph[i][j]);
                                else System.out.print(graph[i][j]+" ");
                        }
                }
        }
}

Measured memory_bytes: 33488
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}



int main() {

    int N; // 点の数
    int M; // 辺の数 
    cin >> N >> M;
    
    long a[M]; // 辺の繋がり開始点
    long b[M]; // 辺の繋がり終了点


    vector<int> nums;

    //vector<int> a_vec;
    //vector<int> b_vec;

    for (int i = 0; i < M ; i++) {
        //cin >> a[i] >> b[i];
        cin >> a[i] >> b[i];

        //a_vec.push_back(a[i]);
        //b_vec.push_back(b[i]);

        //cout << "aaa:  " << a[i] << "  bbb: " << b[i] <<  endl;

        //nums.push_back(i+1);
    }

    for (int i = 0; i < N ; i++) {

        nums.push_back(i+1);
    }

    // 頂点 1を始点として、全ての頂点を1度だけ訪れるパスは何通りありますか。
    // 1. 1 スタート
    // 2. 一度通った点は、２度訪れない
    // 3. N 個

    int cnt = 0;
    //int path_cnt = 0;


    // vector順列総当たりループ
    do {
        //printVector(nums);

        int path_cnt = 0;

        // vector要素数分の処理
        for (int i = 1; i < N ; i++) {
            // 1　スタートのみ
            if (nums.at(0) != 1){
                continue;
            }

            int now = nums.at(i-1);
            int next = nums.at(i);
            //cout << "now:  " << now << "  next: " << next <<  endl;

            // 辺の定義分ループ
            bool route_flg = false;
            for (int j = 0; j < M ; j++) {

                //cout << "a:  " << a_vec.at(j) << "  b: " << b_vec.at(j) <<  endl;

                //[now-next]間の辺の存在チェック
                if ((now == a[j] && next == b[j]) || (now == b[j] && next == a[j])){
                //if ((now == a_vec.at(j) && next == b_vec.at(j)) || (now == b_vec.at(j) && next == a_vec.at(j))){
                    route_flg = true;
                    //break;
                }
            }
            if(route_flg){
                 path_cnt++;
            }
        }

        if(path_cnt == N -1){
            //cout << "cnt up " << endl;
            cnt++;
        }
        //printVector(nums);

    } while (next_permutation(nums.begin()+1, nums.end()));


    cout << cnt << endl;

}

Measured memory_bytes: 3632
#include <stdio.h>
int main(void)
{
int x, y, r;
scanf("%d %d", &x, &y);
if(x > y){
while(y > 0){
        r = x % y;
        x = y;
        y = r;
}
printf("%d\n", x);
}
if(y >= x){
while(x > 0){
        r = y % x;
        y = x;
        x = r;
}
printf("%d\n", y);
}

return 0;
}

Measured memory_bytes: 2708
import java.security.KeyStore.TrustedCertificateEntry
import java.util
import java.util.{ArrayList, Collections, Comparator, List => JList}
import scala.math._

import scala.collection.mutable
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.util.{Failure, Success, Try}

object Main{
  val LINE_SEPARATOR = "\n"
  def main(args: Array[String]): Unit = {
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString(LINE_SEPARATOR);
      println(solve(input).trim());
    }
  }

  def init (nRows: Int, nCols: Int, default: Int) = Array.tabulate(nRows,nCols)( (x,y) =>  default)

  def sortIgnoreCase1(list: JList[String]): JList[String] = {
    val r = new ArrayList[String](list)
    Collections.sort(r, new Comparator[String] {
      override def compare(o1: String, o2: String): Int = o1.compareToIgnoreCase(o2)
    })
    r
  }

  def solve(input: String): String = {
    val a = input.split(" ").head.toInt
    val b = input.split(" ").tail.head.toInt
    val n = input.split(" ").tail.tail.head.toInt
    divisors(a).intersect(divisors(b)).reverse(n-1).toString
  }

  def divisors(n: Int): List[Int] =
    for (i <- (1 to n).toList if n % i == 0) yield i

  def gcd(m: Long, n: Long): Long = n match {
    case 0 => m
    case _ => gcd(n, m % n)
  }
  def lcm(a: Long, b: Long): Long = a * b / gcd(a, b)

  val tests=List(
    """8 12 2""".stripMargin -> """2
                                  |
                                   |""".stripMargin,
    """100 50 4""".stripMargin -> """5""".stripMargin,
    """1 1 1""" -> "1"
  )

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}
      .zipWithIndex.map{
      case ((input,outputExpect),i)=>{
        val output=solve(input).trim();
        s"test${i+1}:"+(if(output==outputExpect){
          "Passed"
        }else{
          s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
        })
      }}
      .mkString("\n");
  }
}

Measured memory_bytes: 25416
n, m = map(int,input().split())
H = list(map(int,input().split()))
AB = []
ans = 0
for i in range(m):
    AB.append(list(map(int,input().split())))
    AB[-1][0] -= 1
    AB[-1][1] -= 1
ok = [1]*n
for i in range(m):
    if H[AB[i][0]] >= H[AB[i][1]]:
        ok[AB[i][1]] = 0
    if H[AB[i][0]] <= H[AB[i][1]]:
        ok[AB[i][0]] = 0
for i in ok:
    if i:
        ans += 1
print(ans)

Measured memory_bytes: 31824
from collections import *
n=int(input())
c=Counter(map(int,input().split()))
x=y=0
for k,v in c.items():
    if v>=2 and k>y:
        if k>=x:
            if v>=4:
                x=y=k
            else:
                x,y=k,x
        else:
            y=k
print(x*y)

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

int main(){
    int h,w;
    cin >> h >>w;
    string s[h][w];
    string sub;
    string ans[h][w];
    for(int i=0;i<h;i++){
        cin >> sub;
        for(int j=0;j<w;j++){
            s[i][j]=sub[j];
        }
    }


    int count=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=="."){
                for(int u=max(0,i-1);u<=min(h-1,i+1);u++){
                    for(int t=max(0,j-1);t<=min(w-1,j+1);t++){
                        if(s[u][t]=="#"){
                            count+=1;
                        }
                    }
                }
                ans[i][j]=to_string(count);
                count = 0;                
            }
            if(s[i][j]=="#"){
                ans[i][j]="#";
            }
        }
    }

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout << ans[i][j];
        }
        cout << endl;
    }
    return 0;
}

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

using namespace std;

using ll = long long;

constexpr ll mod = 1e9 + 7;

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

  int h, w;
  cin >> h >> w;

  vector<vector<ll>> dp(h + 1, vector<ll>(w + 1));
  dp[1][1] = 1;
  for (int i = 0; i < h; ++i) {
    string row;
    cin >> row;
    for (int j = 0; j < w; ++j) {
      if (row[j] == '.') {
        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1] + dp[i + 1][j]) % mod;
      }
    }
  }

  cout << dp[h][w] << '\n';

  return 0;
}


Measured memory_bytes: 8192
#include <numeric>
#include <iostream>
#include <array>
#include <string>
#include <vector>
#include <cassert>
#include <algorithm>
#include <math.h> 
#include <set>
#include <map>
#include <utility>
#include <deque>
#include <queue>
#include <iomanip>

using namespace std;

#define ll long long int
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repp(i, n) for(ll i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define riverse(v) reverse((v).begin(), (v).end())
#define pb push_back
#define mp make_pair
#define all(a)  (a).begin(),(a).end()
using vi = vector<int>;
using vs = vector<string>;
using vc = vector<char>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vb = vector<bool>;
using vvb = vector<vb>;
const ll MOD = 1e9 + 7;
set<char> alphabet = { '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' };


int main() {
    ll H, W;
    cin >> H >> W;
    vector<vc> S(H+2,vc(W+2));
    repp(i, H) {
        repp(j, W) {
            cin >> S[i][j];
        }
    }
    rep(i, W + 2) {
        S[H + 1][i] = '#';
        S[0][i] = '#';
    }
    rep(i, H + 2) {
        S[i][0] = '#';
        S[i][W + 1] = '#';
    }
    vi ans;
    repp(a, H) {
        repp(s, W) {
            repp(k, H) {
                repp(l, W) {
                    if (S[a][s] == '#' || S[k][l] == '#')continue;
                    vvi dist(H + 2, vi(W + 2, -1));
                    dist[a][s] = 0;
                    queue<pair<int, int>> q;
                    q.push(make_pair(a, s));
                    while (!q.empty()) {
                        pair<int, int> p = q.front(); q.pop();
                        int i = p.first;
                        int j = p.second;
                        if (S[i + 1][j] == '.' && dist[i + 1][j] == -1) {
                            dist[i + 1][j] = dist[i][j] + 1;
                            q.push(make_pair(i + 1, j));
                        }
                        if (S[i - 1][j] == '.' && dist[i - 1][j] == -1) {
                            q.push(make_pair(i - 1, j));
                            dist[i - 1][j] = dist[i][j] + 1;
                        }
                        if (S[i][j + 1] == '.' && dist[i][j + 1] == -1) {
                            q.push(make_pair(i, j + 1));
                            dist[i][j + 1] = dist[i][j] + 1;
                        }
                        if (S[i][j - 1] == '.' && dist[i][j - 1] == -1) {
                            q.push(make_pair(i, j - 1));
                            dist[i][j - 1] = dist[i][j] + 1;
                        }
                    }
                    ans.push_back(dist[k][l]);
                }
            }
        }
    }
    sort(ans);
    riverse(ans);
    cout << ans[0] << endl;
}

Measured memory_bytes: 1404
#include <iostream>

using namespace std;

int main() {
    string s;
    char x;
    while (cin >> x) {
        s += x;
    }
    for (int i=0;i<s.length()/2;i++){
        char temp=s[i];
        s[i]=s[s.length()-i-1];
        s[s.length()-i-1]=temp;
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 1172
#include<bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
using namespace std;
int n;
int b[100500],a[100500];
bool jud(){
    int x=0,y=0,z=0;
    rep(i,1,n) if (b[1]==a[i]) x++;
    rep(i,1,n) if (b[2]==a[i]) y++;
    rep(i,1,n) if (b[3]==a[i]) z++;
    if (x!=y||y!=z||x!=z) return 0;
    if ((b[1]^b[2])==b[3]) return 1;
    return 0;
}
bool jud2(){
    int c=0,d=0;
    rep(i,1,n) if (a[i]==0) c++;
    rep(i,1,n) if (a[i]) d++;
    if (d==c*2) return 1;
    return 0;
}
int main(){
    scanf("%d",&n);
    rep(i,1,n) scanf("%d",&a[i]);
    rep(i,1,n) b[i]=a[i];
    sort(b+1,b+1+n);
    int cnt=unique(b+1,b+1+n)-b-1;
    if (cnt==1&&b[1]==0) puts("Yes");
    else if (cnt==2&&jud2()&&n%3==0) puts("Yes");
    else if (cnt==3&&jud()&&n%3==0) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

ll lcm(ll x, ll y) { return x/gcd(x, y)*y; }

int main(){
  int N;
  cin >> N;
  vector<ll> T(N);
  rep(i, N) cin >> T[i];
  rep(i, N-1) T[i+1] = lcm(T[i], T[i+1]);
  cout << T[N-1] << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>

using namespace std;

int main(){
    int N,M;
    cin>>N>>M;
    vector<int> num(N,0);
    int ans=0;

    for(int i=0; i<M; i++){
        int s,c;
        cin>>s>>c;
        s--;
    
        if(num[s]==0){
            num[s]=c;
        }else if(num[s]!=c){
            ans=-1;
            break;
        }
        if(s==0 && c==0 && N>1){
            ans=-1;
            break;
        }
        //cout<<num[s];
    }//cout<<endl;
    if(ans!=-1){
        if(num[0]==0 && N>1){
            num[0]=1;
        }
        
        int t=1;
        for(int i=0; i<N; i++){
            ans+=num[N-i-1]*t;
            t*=10;   
        }

        cout<<ans<<endl;
    }else{
        cout<<-1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
numbers = []

minv = int(input())
num = int(input())

max_r = num - minv

if(minv > num):
    minv = num

for i in range(2,n):
    num = int(input())
    if(max_r <(num - minv)):
        max_r = num - minv

    if(minv > num):
        minv = num

print(max_r)




Measured memory_bytes: 5612
s = list(input())
t = list(input())
ls = [[] for i in range(0,26)]
lt = [[] for i in range(0,26)]
alfa = "abcdefghijklmnopqrstuvwxyz"
for i in range(0,len(s)):
    ls[alfa.index(s[i])].append(i)
    lt[alfa.index(t[i])].append(i)
ans = "Yes"
for i in range(0,26):
    if len(ls[i]) == 0:
        continue
    ok = "false"
    for j in range(0,26):
        if len(lt[j]) == 0:
            continue
        if ls[i] == lt[j]:
            ok = "true"
            lt[j] = []
    if ok == "true":
        continue
    else:
        ans = "No"
print(ans)


Measured memory_bytes: 17192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 1000000001;

int main(){
  int a, b;
  cin >> a >> b;
  if(a==4||a==6||a==9||a==11){
    a=0;
  }else if(a!=2){
    a=1;
  }
  if(b==4||b==6||b==9||b==11){
    b=0;
  }else if(b!=2){
    b=1;
  }
  if(a==b) cout << "Yes"<<endl;
  else cout << "No" <<endl;
}

Measured memory_bytes: 256
import sys
A,B,C,D = map(int, input().split())
T = [A,B]
A = [C,D]

while True:
    for x in ['T', 'A']:
        if x == 'T':
            A[0] -= T[1]
        
        else:
            T[0] -= A[1]
            
        if T[0] <= 0:
            print('No')
            sys.exit()
        elif A[0] <= 0:
            print('Yes')
            sys.exit()

Measured memory_bytes: 9184
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define endl '\n'
const int mod=998244353;
const int inf=1e17+10;
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(),x.end()
#define si(a) a.size()
#define pii pair<int,int>
using namespace std;
//#if !defined(ONLINE_JUDGE)
//#include "debugging.h"
//#endif

int32_t main() {
   std::ios::sync_with_stdio(false);cin.tie(NULL);
   
   int n;
   cin>>n;
   vector<pii>a(n);
   
   for(auto &p:a)
   {
       cin>>p.F>>p.S;
   }
   
   sort(all(a));
   stack<pii>st;
   st.push({n,INT_MAX});
   int dp[n+1]={0};
   dp[n]=1;
   //dbg(a);
   for(int i=n-1;i>=0;i--)
   {
       //dbgm(i,st.top());
       while(a[i].F+a[i].S > st.top().S)st.pop();
       
       dp[i]=dp[i+1];
       dp[i]+=dp[st.top().F];
       dp[i]%=mod;
       st.push( {i,a[i].F} );
       //dbgm(dp[i],st.size());
   }
   cout<<dp[0]<<endl;
   return 0;
}


Measured memory_bytes: 6656
import scala.io.Source.stdin

object Main extends App {
  def gcd(m:Long,n:Long):Long = if(n==0) m else gcd(n, m % n)

  val l =
    for(s <- stdin.getLines.map(_.split(" ").map(_.toLong))) yield {
        val g = gcd(s(0),s(1))
        g + " " + (s(0)/g)*s(1)
    }
  println(l.toSeq.mkString("\n"))
}

Measured memory_bytes: 43948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005,INF=((1<<30)-1<<1)+1;

template<typename T,typename E>
struct LazySegmentTree{
    using F=function<T(T,T)>;
    using G=function<T(T,E)>;
    using H=function<E(E,E)>;
    
    int n;
    vector<T> dat;
    vector<E> lazy;
    F f;
    G g;
    H h;
    T ti;
    E ei;
    
    LazySegmentTree(int n_,F f,G g,H h,T ti,E ei) :f(f),g(g),h(h),ti(ti),ei(ei){
        n=1;
        while(n<n_) n*=2;
        dat.assign(2*n-1,ti);
        lazy.assign(2*n-1,ei);
    }
    
    LazySegmentTree(int n_,vector<T> &v,F f,G g,H h,T ti,E ei) :f(f),g(g),h(h),ti(ti),ei(ei){
        n=1;
        while(n<n_) n*=2;
        dat.assign(2*n-1,ti);
        
        for(int i=n-1;i-(n-1)<v.size();i++) dat[i]=v[i-(n-1)];
        
        for(int i=n-2;i>=0;i--) dat[i]=f(dat[i*2+1],dat[i*2+2]);
        
        lazy.assign(2*n-1,ei);
    }
    
    inline void eval(int k,int l,int r){
        
        if(lazy[k]==ei) return;
        
        dat[k]=g(dat[k],lazy[k]);
        
        if(r-l>1){
            lazy[k*2+1]=h(lazy[k*2+1],lazy[k]);
            lazy[k*2+2]=h(lazy[k*2+2],lazy[k]);
        }
        
        lazy[k]=ei;
    }
    
    void update_(int a,int b,E x,int k,int l,int r){
        
        eval(k,l,r);
        
        if(r<=a||b<=l) return;
        
        if(a<=l&&r<=b){
            lazy[k]=h(lazy[k],x);
            eval(k,l,r);
        }
        
        else{
            update_(a,b,x,2*k+1,l,(l+r)/2);
            update_(a,b,x,2*k+2,(l+r)/2,r);
            dat[k]=f(dat[2*k+1],dat[2*k+2]);
        }
        
    }
    
    void update(int a,int b,E x){
        return update_(a,b,x,0,0,n);
    }
    
    T query_(int a,int b,int k,int l,int r){
        
        eval(k,l,r);
        
        if(r<=a||b<=l) return ti;
        if(a<=l&&r<=b) return dat[k];
        
        T vl=query_(a,b,2*k+1,l,(l+r)/2);
        T vr=query_(a,b,2*k+2,(l+r)/2,r);
        return f(vl,vr);
    }
    
    T query(int a,int b){
        return query_(a,b,0,0,n);
    }
    
};

int main(){

    int N,Q;cin>>N>>Q;
    
    LazySegmentTree<ll,ll> seg(N,
                                [](ll a,ll b){return min(a,b);},
                               [](ll a,ll b){return b;},
                               [](ll a,ll b){return b;},
                                         INF,
                                         INF);
    
    while(Q--){
        int c;cin>>c;
        if(c==0){
            int s,t;ll x;cin>>s>>t>>x;
            seg.update(s,t+1,x);
        }else{
            int s,t;cin>>s>>t;
            cout<<seg.query(s,t+1)<<endl;
        }
    }
    
}



Measured memory_bytes: 7084
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

static long Gcd(long m, long n)
{
	long temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

static long Lcm(long m, long n)
{
	return m * n / Gcd(m,n);
}

int main(int argc, char* argv[])
{

	long N;

	cin >> N;

	cout << Lcm(N,2) << endl;

	return 0;
}

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

using namespace std;

int main() {
#ifdef wxh010910
  freopen("input.txt", "r", stdin);
#endif
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first;
    a[i].second = i + 1;
  }
  sort(a.begin(), a.end());
  vector<int> ans;
  --a.back().first;
  ans.push_back(a.back().second);
  int prev = a.back().second;
  for (int turns = 0; turns <= m; ++turns) {
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    int last = -1;
    for (auto &p : a) {
      if (p.second != prev) {
        --p.first;
        ans.push_back(p.second);
        last = p.second;
      }
    }
    prev = last;
  }
  for (auto p : a) {
    if (p.first < 0) {
      cout << -1 << "\n";
      return 0;
    }
  }
  cout << ans.size() << "\n";
  for (int i = 0; i < (int) ans.size(); ++i) {
    if (i) {
      cout << " ";
    }
    cout << ans[i];
  }
  cout << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const static int MAXN=5000+10; 
char str[MAXN];
long long arr[MAXN][2];
long long inv[MAXN][2];
int nnn;
inline long long pow ( long long a, long long b, long long m ) {
    long long res = 1 % m;
    a = a % m;
    while ( b ) {
        if ( b & 1 ) res = ( res * a ) % m;
        a = ( a * a ) % m;
        b >>= 1;
    }
    return res;
}

const long long mod1=1000000007;
const long long mod2=1000000009;
const long long base=31;


void pre()
{
	// nnn=strlen(str);
	long long p1=1,p2=1;
	long long a1=0,a2=0;
	for(int i=0;i<nnn;i++)
	{
		a1=(a1+p1*str[i])%mod1;p1=(p1*base)%mod1;
		a2=(a2+p2*str[i])%mod2;p2=(p2*base)%mod2;
		arr[i][0]=a1;
		arr[i][1]=a2;
	}
	inv[nnn-1][0]=pow(base,mod1-nnn,mod1);
	inv[nnn-1][1]=pow(base,mod2-nnn,mod2);
	for(int i=nnn-2;i>=0;i--)
	{
		inv[i][0]=(inv[i+1][0]*base)%mod1;
		inv[i][1]=(inv[i+1][1]*base)%mod2;
	}
}

inline long long getHash(int n,int m)
{
	if(n==0)return arr[m][0]*mod2+arr[m][1]*mod1;
	else
	{
		long long k1=(((((arr[m][0]-arr[n-1][0])%mod1)
			*inv[n][0])%mod1)+mod1)%mod1;
		long long k2=((((arr[m][1]-arr[n-1][1])
			*inv[n][1])%mod2)+mod2)%mod2;
		return k1*mod2+k2*mod1;
	}
}

inline bool solve(int k)
{
	unordered_map<long long,int> mp;
	for(int i=0;i+k-1<nnn;i++)
	{
		long long h=getHash(i,i+k-1);
		if(mp.find(h)==mp.end())mp[h]=i;
		else if(mp[h]+k<=i)return 1;
	}
	return 0;
}

int main(int argc, char const *argv[])
{
	scanf("%d %s",&nnn,str);
	pre();
	int l=0,r=nnn>>1;
	while(l<r)
	{
		int mid=l+r+1>>1;
		if(solve(mid))l=mid;
		else r=mid-1;
	}
	printf("%d\n",l);
	return 0;
}


Measured memory_bytes: 724
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s,ss;
    cin>>s;
    long long sum=0,sss;
    for(int i=0;i<s.size();i++){
        ss=s[i];
        sss=stoll(ss);
        sum+=sss;
    }
    if(sum%9==0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


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

int a[200005];
int b[200005];

int main(){
  int n;
  cin>>n;
  rep(i,n)cin>>a[i];
  int j=0;
  for(int i=n-1;i>=0;i-=2)
    b[j++]=a[i];
  for(int i=n&1;i<n;i+=2)
    b[j++]=a[i];
  rep(i,n){
    cout<<b[i];
    if(i!=n-1)cout<<" ";
    else cout<<"\n";
  }
  return 0;
}


Measured memory_bytes: 3712
#include <stdio.h>

#define MAX (100)

int main(void)
{
	char map[MAX][MAX + 1];
	int i;
	int x, y;
	int height;
	
	while (1){
		char flag_map[MAX][MAX + 1] = { 0 };
		
		scanf("%d %*d", &height);
		if (height == 0){
			break;
		}
		
		for (i = 0; i < height; i++){
			scanf("%s", map[i]);
		}
		
		x = y = 0;
		while (1){
			flag_map[y][x] = 1;
			if (map[y][x] == '>'){
			  	x++;
			}
			
			else if (map[y][x] == '<'){
			  	x--;
			}
				
			else if (map[y][x] == '^'){
			  	y--;
			}
				
			else if (map[y][x] == 'v'){
			  	y++;
			}
				
			else {
				printf("%d %d\n", x, y);
				break;
			}
			
			if (flag_map[y][x] == 1){
				printf("LOOP\n");
				break;
			}
		}
	}
	
	return (0);
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

#define MOD (int)(1e9+7)

typedef long long ll;
ll DP[100001][13];

int main()
{
	string S; cin >> S;
	reverse(S.begin(), S.end());
	int N = S.size();

	DP[0][0] = 1;
	int m13 = 1;
	for (int i = 0; i < N; i++)
	{
		if (S[i] == '?')
		{
			for (int x = 0; x < 10; x++)
			{
				for (int j = 0; j < 13; j++)
				{
					int y = (j + x * m13) % 13;
					DP[i + 1][y] += DP[i][j];
					DP[i + 1][y] %= MOD;
				}
			}
		}
		else
		{
			int x = S[i] - '0';

			for (int j = 0; j < 13; j++)
			{
				int y = (j + x * m13) % 13;
				DP[i + 1][y] += DP[i][j];
				DP[i + 1][y] %= MOD;
			}
		}

		m13 = (m13 * 10) % 13;
	}

	cout << DP[N][5] << endl;

	return 0;
}

Measured memory_bytes: 10624
#include <bits/stdc++.h>
using  namespace  std;
using ll=long long;
int main(){
  string a,b,c;
  cin>>a>>b>>c;
  if(a.at(a.size()-1)==b.at(0)&&b.at(b.size()-1)==c.at(0))
    cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int N, K;
int h[100000];

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

  cin >> N >> K;
  REP(i, N) {
    cin >> h[i];
  }

  sort(h, h + N);

  int mi = h[0];
  int ma = h[K-1];
  int ans = ma - mi;
  REP(i, N - K + 1) {
    mi = h[i];
    ma = h[i + K - 1];
    int sum = ma - mi;

    ans = min(sum, ans);
  }

  cout << ans << endl;
}


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

int main(){
  int N,K,R,S,P;
  string T;
  cin >> N >> K >> R >> S >> P >> T;
  char B[K+10];

  // long total = 0;
  // for(int i=0; i<N; ++i){
  //   if(B[i%K]!=T[i]){
  //     if(T[i]=='r')
  //       total += P;
  //     else if(T[i]=='s')
  //       total += R;
  //     else if(T[i]=='p')
  //       total += S;
  //     B[i%K] = T[i];
  //   }
  //   else{
  //     B[i%K] = ' ';
  //   }
    
  // }
  long ans = 0;
  for(int i=0; i<N; i++){
    if(i>=K && T[i] == T[i-K]){
      T[i] = 'q';
    }
    else{
      if(T[i]=='r') ans += P;
      else if(T[i]=='s') ans += R;
      else ans += S;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 512
import itertools
N = int(input())

sixs = [6, 36, 216, 1296, 7776, 46656]

ans = N
for ptn in itertools.product(range(6), repeat=6):
    money = ope = 0
    for s,p in zip(sixs,ptn):
        money += s*p
        ope += p
    if money > N: continue
    if ope > ans: continue
    rem = N - money
    while rem:
        ope += rem%9
        rem //= 9
    ans = min(ans, ope)
print(ans)

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

int main(){
    int n,p;
    int ans=0,m=0;

    cin >>n;

    for (int i = 0; i < n; i++){
        cin >> p;
        ans+=p;
        m = max(m,p);

    }
    ans -= m/2;
    
    
    //cout << ans <<endl;
    cout << ans <<endl;
    
    return 0;
}


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

int main() {
	string s;
	cin>>s;
	int l=0;
	string t=s;
	for(int u=0;u<t.size();u++){
		l=0;
		s.pop_back();
		
		if(s.size()%2) continue;
		for(int i=0;i<s.size()/2;i++)
		{
			if(s[i]!=s[s.size()/2+i])
			{ 
				l=1;
				break;
			}
		}
		
		if(l==0)
			{
				cout<<s.size()<<endl;
				return 0;
			}
	}		
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int h, w;
    while (cin >> h >> w && h) {
        for (int i=0; i<h; i++) {
            for (int j=0; j<w; j++)
                cout << ((i+j)&1 ? '.' : '#');
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3092
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<cctype>
using namespace std;

int main() {
	int n;
	cin >> n;
	cout << (n * (n + 1)) / 2 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{   
    int N,M; cin>>N>>M; 
    vint x(M); REP(i,M) cin>>x[i];
    sort(ALL(x));
    
    if(N>=M){
        cout<<"0"<<endl;
        return 0;
    }

    vint dx(M-1);
    REP(i,M-1) dx[i]=x[i+1]-x[i];
    sort(ALL(dx));

    int ans=0;
    REP(i,M-N) ans+=dx[i];
    cout<<ans<<endl;

}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n), cnt(n+1);
    rep(i,n){
        cin >> a[i];
        cnt[a[i]]++;
    }
    ll sum=0;
    rep(i,n+1){
        sum += (ll)cnt[i]*(cnt[i]-1)/2;
    }
    rep(i,n){
        ll ans = sum;
        ans -= cnt[a[i]]-1;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 4096
#include<iostream>
#include<cstdio>
#include<cassert>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1000005;
int n;
char str[N],s[N];
int cnt[4];
int id[4];
int pre[N],nxt[N];
void del(int i)
{
	pre[nxt[i]]=pre[i];
	nxt[pre[i]]=nxt[i];
	return;
}
int main()
{
	scanf("%s",str+1);
	for(size_t i=1;i<=strlen(str+1);i++)
		if(str[i]!=str[i-1]) s[++n]=str[i];
//	for(int i=1;i<=n;i++)
//		cerr<<s[i];
//	cerr<<endl;
	for(int i=1;i<=n;i++)
		cnt[s[i]-'A'+1]++;
	id[1]=1,id[2]=2,id[3]=3;
	sort(id+1,id+3+1,[=](const int &x,const int &y){return cnt[x]<cnt[y];});
	sort(cnt+1,cnt+3+1);
//	for(int i=1;i<=3;i++)
//		cerr<<(char)(id[i]+'A'-1)<<" ";
//	for(int i=1;i<=3;i++)
//		cerr<<(cnt[i])<<" ";
//	cerr<<endl;
	for(int i=1;i<=n;i++)
		nxt[i]=i+1,pre[i]=i-1;
	nxt[0]=1,pre[n+1]=n;
	int head=0,tail=n+1;
	for(int i=head;i!=tail&&cnt[2]<cnt[3];i=nxt[i])
		if(i&&nxt[i]&&s[i]==id[3]+'A'-1&&s[pre[i]]!=s[nxt[i]]) cnt[3]--,del(i);
//	for(int i=head;i!=tail;i=nxt[i])
//		printf("%c",s[i]);
//	cerr<<endl;
//	cerr<<"done1\n";
	if(cnt[2]<cnt[3])
	{
		for(int i=head;i!=tail&&cnt[2]<cnt[3];i=nxt[i])
			if(i&&pre[i]&&nxt[i]&&s[i]==id[3]+'A'-1&&s[pre[i]]==s[nxt[i]]&&s[pre[i]]==id[1]+'A'-1)
			{
				cnt[1]--,cnt[3]--;
				del(pre[i]),del(i);
			}
	}
	if(cnt[2]!=cnt[3]) return 0;
//	for(int i=1;i<=3;i++)
//		cerr<<(cnt[i])<<" ";
//	cerr<<endl;
//	for(int i=head;i!=tail;i=nxt[i])
//		printf("%c",s[i]);
//	cerr<<endl;
//	cerr<<"done2\n";
//	assert(cnt[2]==cnt[3]);
	if(cnt[1]<cnt[2])
	{
		for(int i=head;i!=tail&&cnt[1]<cnt[2];i=nxt[i])
		{
			if(i&&pre[i]&&s[pre[i]]!=id[1]+'A'-1&&s[i]!=id[1]+'A'-1)
			{
				if(s[pre[pre[i]]]==id[1]+'A'-1&&s[nxt[i]]==id[1]+'A'-1) continue;
				cnt[2]--,cnt[3]--;
				del(pre[i]),del(i);
//				cerr<<"Del"<<pre[i]<<" "<<i<<"\n";
			}
//			cerr<<"now"<<cnt[1]<<" "<<cnt[2]<<" "<<cnt[3]<<"\n";
		}
	}
//	for(int i=1;i<=3;i++)
//		cerr<<(cnt[i])<<" ";
//	cerr<<endl;
//	for(int i=head;i!=tail;i=nxt[i])
//		printf("%c",s[i]);
//	cerr<<endl;
//	cerr<<"done3\n";
	if(cnt[1]!=cnt[2]||cnt[2]!=cnt[3]) return 0;
	for(int i=head;i!=tail;i=nxt[i])
		if(i) printf("%c",s[i]);
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    int N;
    cin>>N;
    vector<pair<int,int>> red(N),blue(N);
    REP(i,N) cin>>red[i].fi>>red[i].se;
    REP(i,N) cin>>blue[i].fi>>blue[i].se;
    vector<pair<int,int>> bx(N);
    REP(i,N) {
        bx[i] = make_pair(blue[i].fi,i);
    }
    sort(ALL(bx));
    vector<pair<int,int>> ry(N);
    REP(i,N) {
        ry[i] = make_pair(red[i].se,i);
    }
    sort(ALL(ry));
    reverse(ALL(ry));
    vector<bool> used(N,false);
    int ans = 0;
    REP(i,N) {
        int bn = bx[i].se;
        REP(j,N) {
            int rn = ry[j].se;
            if (used[rn]) continue;
            if (blue[bn].fi > red[rn].fi && blue[bn].se > red[rn].se) {
                ans++;
                used[rn] = true;
                break;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static class Pair{
        int pos;
        int state;
        public Pair(int pos,int state){
            this.pos=pos;
            this.state=state;
        }
    }
    public static HashMap<Integer,ArrayList<Pair>>g=new HashMap<>();
    public static int[] x;
    public static boolean[] used;
    public static ArrayList<Integer>ans=new ArrayList<>();

    public static int lower_bound(Pair[] nums, Pair pair) {
        int l = 0, r = nums.length;
        while (l< r) { // l:ok, r:ng
            int m = (l + r) / 2;
            // if (mm < bombState) then m is ok.
            if (nums[m].pos == pair.pos
                    ? nums[m].state < pair.state
                    : nums[m].pos < pair.pos) {
                l = m+1;
            } else {
                r = m;
            }
        }
        return l;
    }

    public static int upper_bound(Pair[] nums,Pair pair) {
        int l = 0, r = nums.length;
        while (l< r) { // l:ok, r:ng
            int m = (l + r) / 2;
            // if (mm < bombState) then m is ok.
            if (nums[m].pos == pair.pos
                    ? nums[m].state <= pair.state
                    : nums[m].pos <= pair.pos) {
                l = m+1;
            } else {
                r = m;
            }
        }
        return l;
    }

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        Pair[] a=new Pair[n];
        x=new int[n+1];
        used=new boolean[n+1];
        for(int i=0;i<n;i++)
        {
           a[i]=new Pair(sc.nextInt(),sc.nextInt());
        }
        Arrays.sort(a, Comparator.comparingInt(c -> c.pos));
        x[0]=a[0].state;
        for(int i=0;i<n-1;i++)
        {
            x[i+1]=a[i].state^a[i+1].state;
        }
        x[n]=a[n-1].state;
        for(int i=0;i<m;i++)
        {
            int l=sc.nextInt();
            int r=sc.nextInt();
            l=lower_bound(a,new Pair(l,0));
            //System.out.println(l);
            r=upper_bound(a,new Pair(r,1));
            //System.out.println(r);
            if(l>r)continue;
            if(g.get(l)==null)g.put(l,new ArrayList<>());
            if(g.get(r)==null)g.put(r,new ArrayList<>());
            g.get(l).add(new Pair(r,i+1));
            g.get(r).add(new Pair(l,i+1));
        }
        for(int i=0;i<n+1;i++)
        {
            if(used[i])continue;

            if(dfs(i)==1){
                System.out.println(-1);
                return;
            }
        }
            System.out.println(ans.size());
            Collections.sort(ans);
            for (int num : ans) {
                System.out.print(num + " ");
            }
            System.out.println("");

    }
    public static int dfs(int v)
    {
        used[v]=true;
        int res=x[v];
        if(g.get(v)==null)return res;
        for(Pair p:g.get(v))
        {
            if(used[p.pos])continue;
            int r=dfs(p.pos);
            if(r==1) ans.add(p.state);
            res^=r;
        }
        return res;
    }
}


Measured memory_bytes: 203972
N, M = map(int, input().split())
H = list(map(int, input().split()))
g = [[] for i in range(N)]
for i in range(M):
  a, b = map(int, input().split())
  g[a-1].append(b-1); g[b-1].append(a-1)

ans = 0
for i in range(N):
  neighbors = g[i]
  h = H[i]
  res = True
  for node in neighbors:
    res *= h > H[node]
  ans += res

print(ans)


Measured memory_bytes: 92944
//Resting_Prince
#include<bits/stdc++.h>
#define mod 1000000007
#define inf 1e18
#define PI 3.141592653589
#define fi first
#define se second 
#define sv(v) sort(all(v));reverse(all(v))
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mk make_pair
#define en '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double ld;

ll n,grid[22][22]={0},dp[22][2500006];

ll fun(ll id,ll mask)
{
    if(id<0)return mask==0;
    if(dp[id][mask]!=-1)return dp[id][mask];
    dp[id][mask]=0;
        rep(j,0,n-1)
        {
            if(grid[id][j] && (mask & (1<<j)))
            {
                dp[id][mask]=(dp[id][mask]+fun(id-1,mask^(1<<j)))%mod;
            }
        }

    return dp[id][mask];
}

int main()
{   ios;
    ll i,j,k;
    cin>>n;
    rep(i,0,n-1)
    {
        rep(j,0,n-1)cin>>grid[i][j];
    }
    memset(dp,-1,sizeof(dp));
    cout<<fun(n-1,(1<<n)-1);
    return 0;
}



Measured memory_bytes: 429952