akhauriyash/Code-Regression huggingface dataset:
#pragma region macro
#include <bits/stdc++.h>
using i64 = int_fast64_t;
#define repeat(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define rep(i, n) repeat(i, 0, n)

namespace std {
template <typename A, typename B>
string to_string(pair<A, B> p);

string to_string(const string &s) {
    return '"' + s + '"';
}

string to_string(const char *s) {
    return to_string((string)s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for(int i = 0; i < static_cast<int>(v.size()); i++) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for(size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
};  // namespace std
#pragma endregion

void solve() {
    int X, Y, Z, K;
    scanf("%d%d%d%d", &X, &Y, &Z, &K);
    std::vector<long long> A(X);
    rep(i, X) scanf("%lld", &A[i]);
    std::vector<long long> B(Y);
    rep(i, Y) scanf("%lld", &B[i]);
    std::vector<long long> C(Z);
    rep(i, Z) scanf("%lld", &C[i]);
    std::priority_queue<long long, std::vector<long long>, std::greater<long long>> AB;
    rep(i, X) {
        rep(j, Y) {
            AB.push(A[i] + B[j]);
        }
        while(AB.size() > K) AB.pop();
    }
    std::priority_queue<long long, std::vector<long long>, std::greater<long long>> ABC;
    while(!AB.empty()) {
        long long ab = AB.top();
        AB.pop();
        rep(i, Z) {
            ABC.push(ab + C[i]);
        }
        while(ABC.size() > K) ABC.pop();
    }
    std::vector<long long> ans(K);
    rep(i, K) {
        ans[i] = ABC.top();
        ABC.pop();
    }
    for(int i = K - 1; i >= 0; i--) {
        std::cout << ans[i] << '\n';
    }
}

int main() {
    // std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 384
import math
n = int(input())
a = int(math.sqrt(n))
for i in range(n):
    if a-i == 1:
        print(n-1)
        break
    elif n%(a+i) == 0:
        print(a+i+n//(a+i)-2)
        break
    elif n%(a-i) == 0:
        print(a-i+n//(a-i)-2)
        break


Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define deb(x) cout<<#x<<" "<<x<<"\n";
#define cr7 ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
int main() {
	cr7
	ll n,m;
	cin >> n >> m;
	ll arr[m];
	ll S=0;
	for(ll i=0;i<m;i++) cin>>arr[i],S+=arr[i];
	if(n-S >= 0)	cout<<n-S<<"\n";
	else cout<<"-1\n";
	
}

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


int main(){
    int a,b,x;
    cin >> a >> b >> x;
    if(x/a > a*b/2.0){
        double ans = atan(2.0*(a*a*b-x)/(a*a*a));
        ans  *= 180.0 / M_PI;
        printf("%.10f",ans);
    }
    else{
        double ans = atan(a*b*b/(2.0*x));
        ans  *= 180.0 / M_PI;
        printf("%.10f",ans);
    }
    return 0;
}

Measured memory_bytes: 256
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include<unordered_map>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) vdeb(da[i]);
    std::cout << std::endl;
}

using namespace std;
typedef pair<Pii,Pii> P;

int main(){
    ll a,b,n; cin>>a>>b>>n;
    ll ans = a*n/b - (n/b)*a;
    if(b-1 <= n){
        chmax(ans, (a*b-a)/b);
    }
    cout << ans << endl;
}

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

//a^b % modを求める
int64_t MODpow(int64_t a, int64_t b, int64_t mod) {
    int64_t result = 1;
    while (b) {
        if (b % 2 == 1) {
            result *= a;
            result %= mod;
        }

        b /= 2;
        a *= a;
        a %= mod;
    }

    return result;
}

class Combination {
public:
    Combination(int64_t max_num, int64_t mod) {
        fact_.resize(max_num + 1, 1);
        inv_fact_.resize(max_num + 1, 1);
        mod_ = mod;
        for (int64_t i = 2; i <= max_num; i++) {
            fact_[i] = i * fact_[i - 1] % mod_;
            inv_fact_[i] = MODpow(fact_[i], mod_ - 2, mod_);
            assert(fact_[i] * inv_fact_[i] % mod_ == 1);
        }
    }
    int64_t operator()(int64_t n, int64_t m) const {
        if (m < 0 || m > n) return 0;
        return fact_[n] * inv_fact_[n - m] % mod_ * inv_fact_[m] % mod_;
    }
private:
    vector<int64_t> fact_, inv_fact_;
    int64_t mod_;
};


int main() {
    int64_t S;
    cin >> S;
    constexpr int64_t MOD = 1e9 + 7;

    Combination comb(2 * S, MOD);

    int64_t ans = 0;
    for (int64_t term_num = 1; term_num <= S / 3; term_num++) {
        int64_t rem = S - term_num * 3;

        //remをterm_num個に分ける, remをterm_num - 1の仕切りで分割
        (ans += comb(rem + term_num - 1, rem)) %= MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3652
N,K=map(int,input().split())

A=list(map(int,input().split()))
B=[]
for i in range(2):
    for j in range(N):
        B.append(A[j])
b=len(B)


a=len(A)
counter=0
for i in range(a):
    for j in range(a-i):
        if B[i]>B[i+j]:
            counter+=1


count=0
for i in range(b//2):
    for j in range(b//2):
        if B[i]>B[b//2+j]:
            count+=1
#print(count)
#print(count)
#print(counter)
#print(count-2*counter)

#print(counter)
#print(count)
#ans=(counter*K+((count-2*counter)*(K-1)*K)//2)%(1000000007)
answer=(counter*K+(count*(K-1)*K)//2)%(1000000007)
#print(ans)
print(answer)


Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int n;
  int a[MAX];
  scanf("%d", &n);
  rep(i, 0, n) scanf("%d", &a[i]);

  qsort(a, n, sizeof(int), des);
  int ans = 0;
  rep(i, 0, n) {
    if (i % 2 == 0) ans += a[i];
    else ans -= a[i];
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
a = input().split()
min_data = None
for i in range(len(a)):
    for j in range(len(a)):
        if i == j:
            pass
        elif min_data is None:
            min_data = int(a[i])+int(a[j])
        else:
            min_data = min(min_data, int(a[i])+int(a[j]))
print(min_data)


Measured memory_bytes: 3064
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.immutable.Queue

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  @tailrec
  private def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}


object Main {
  def solve(sc: => Scanner): Unit = {
    val n = sc.nextInt
    if (n != 0) {
      val s = sc.next
      val A = Array.fill(n)(0)
      var stage = 0
      for (i <- Range(0, 100)) {
        s(i) match {
          case 'M' => A(i % n) += 1
          case 'L' => {
            A(i % n) += 1 + stage
            stage = 0
          }
          case 'S' => {
            stage += 1 + A(i % n)
            A(i % n) = 0
          }
        }
      }
      println(A.sorted.mkString(" ") + " " + stage)
      solve(sc)
    }
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}




Measured memory_bytes: 46884
#include<bits/stdc++.h>
#define ll long long int
#define ff first
#define ss second
#define eps 1e-9

using namespace std;

int main()
{

    ll t,n,m,f,a,b,c,l,r,q,k,x,y,z,ans,mn,mx,sum=0;
    string exp;
    cin>>n>>exp;

    char ch='#';
    c=0;

    for(int i=0;i<exp.size();i++)
    {
        if(exp[i]!=ch)
        {
            ch = exp[i];
            c++;
        }

    }
    cout<<c<<endl;


}


Measured memory_bytes: 3680
#include <stdio.h>
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;
typedef pair<int, int> P;

int N;
int x[10005], y[10005];
vector<pair<int, P> > vec;
int pos[10005][2];

int V;
const int Num = 1<<15;
vector<int> G[70005];
vector<int> revG[70005];

bool used[70005];
vector<int> topo;
int scc[70005];

void tpsort(int v, int prev)
{
	used[v] = true;
	for(int i = 0; i < G[v].size(); i++){
		if(used[G[v][i]]) continue;
		tpsort(G[v][i], v);
	}
	topo.push_back(v);
}

void dfs(int v, int prev, int id)
{
	used[v] = true;
	scc[v] = id;
	for(int i = 0; i < revG[v].size(); i++){
		if(used[revG[v][i]]) continue;
		dfs(revG[v][i], v, id);
	}
}

void query(int v, int a, int b, int k, int l, int r)
{
	if(b < l || r < a) return;
	if(a <= l && r <= b){
		G[v].push_back(k);
		return;
	}
	if(k*2 < V) query(v, a, b, k*2, l, (l+r)/2);
	if(k*2+1 < V) query(v, a, b, k*2+1, (l+r)/2+1, r);
}

void range(int v, int l, int r)
{
	if(l > r) return;
	 query(v, l, r, 1, 0, (1<<15)-1);
}

bool check(int d)
{
	for(int i = 1; i < V; i++) G[i].clear();
	for(int i = 1; i < Num; i++){
		if(i*2 < V) G[i].push_back(i*2);
		if(i*2+1 < V) G[i].push_back(i*2+1);
	}
	
	int l = 0, r = 0;
	for(int i = 0; i < 2*N; i++){
		int v = pos[vec[i].second.first][1-vec[i].second.second];
		while(vec[l].first < vec[i].first-(d-1)) l++;
		range(Num + v, l, i-1);
	}
	for(int i = 0; i < 2*N; i++){
		int v = pos[vec[i].second.first][1-vec[i].second.second];
		while(r < 2*N && vec[r].first <= vec[i].first+(d-1)) r++;
		range(Num + v, i+1, r-1);
	}
	
	for(int i = 1; i < V; i++) revG[i].clear();
	for(int i = 1; i < V; i++){
		for(int j = 0; j < G[i].size(); j++){
			revG[G[i][j]].push_back(i);
		}
	}
	
	for(int i = 1; i < V; i++) used[i] = false;
	topo.clear();
	for(int i = 1; i < V; i++) if(!used[i]) tpsort(i, -1);
	reverse(topo.begin(), topo.end());
	
	for(int i = 1; i < V; i++) used[i] = false;
	for(int i = 1; i < topo.size(); i++){
		if(!used[topo[i]]) dfs(topo[i], -1, i);
	}
	
	for(int i = 0; i < N; i++){
		if(scc[Num+pos[i][0]] == scc[Num+pos[i][1]]) return false;
	}
	return true;
}

int main(void)
{
	scanf("%d", &N);
	for(int i = 0; i < N; i++) scanf("%d %d", &x[i], &y[i]);
	
	for(int i = 0; i < N; i++){
		vec.push_back(make_pair(x[i], make_pair(i, 0)));
		vec.push_back(make_pair(y[i], make_pair(i, 1)));
	}
	sort(vec.begin(), vec.end());
	
	for(int i = 0; i < 2*N; i++){
		pos[vec[i].second.first][vec[i].second.second] = i;
	}
	V = 2*N + Num;
	
	int ub = 1e9+7, lb = 0, mid;
	while(ub - lb > 1){
		mid = (ub + lb) / 2;
		if(check(mid)) lb = mid;
		else ub = mid;
	}
	printf("%d\n", lb);
	return 0;
}

Measured memory_bytes: 18556
#ABC103-D Islands War
"""
問題：
一列にn個の島があり、n-1本の橋で左右の島がつながっている。
m個のクエリが与えられ、aとbの島を橋を取り除くことにより行き来できないようにしたい。
取り除かなければならない橋の本数の最小値を出力

解法：
橋をかけても良い島を探す。
クエリをソートしておいて、左端が入ったものから右端をheapに入れる。heapqで取り出したものが右端であるならば、
そこに橋をかけないものとして、heapをリセットする。(heapに入っている全ての条件がクリアされる為)
"""
import sys
import heapq
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n,m = map(int,readline().split())

g = []
for i in range(m):
    a,b = map(int,readline().split())
    a,b = a-1,b-1
    g.append((a,b))
g.sort()
heap = []
heapq.heapify(heap)
now = 0
count = 0
for i in range(n-1): #橋の数はn-1個
    while now < m:
        if g[now][0] == i: #クエリが左端に入った場合
            heapq.heappush(heap,g[now][1]) #右端をプッシュ
            now += 1
        else:
            break
    
    if len(heap):
        res = heapq.heappop(heap)
        if res == i+1: #橋を取り除く必要があるなら
            count += 1
            heap = []
            heapq.heapify(heap)
        else:
            heapq.heappush(heap,res)
    

print(count)

Measured memory_bytes: 62680
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
int mypow(int a,int b,int c){
	if(b==0)return 1;
	if(b%2)return mypow(a,b-1,c)*a%c;
	int z=mypow(a,b/2,c);
	return z*z%c;
}
int mutu(int a,int b){
	int z=1;
	for(int i=a;i>a-b;i--){
		z*=i;
		z%=mod;
	}
	f(i,b){
		z*=mypow(i+1,mod-2,mod);
		z%=mod;
	}
	return z;
}
signed main(){
	int a,b;
	cin>>a>>b;
	if((a+b)%3||a>b*2||b>a*2)puts("0");
	else{
		int z=(a+b)/3;
		cout<<mutu(z,min(a-z,b-z))<<endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    // 整数の入力
    int a;
    cin >> a;
    vector<int> data(a);
    for (int i=0;i<a;i++){
      cin >> data.at(i);
    }
    sort(data.begin(), data.end());
    reverse(data.begin(), data.end());
    int s = 0;
    for (int i=0;i<a;i++){
      s += data.at(i);
    }
    s -= int(data.at(0)/2);
    cout << s << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  long long int N,A,B,i,h[100000],K,left=0,right=1000000000,sum;

  scanf("%lld %lld %lld",&N,&A,&B);

  for(i=0;i<N;++i){
    scanf("%lld",&h[i]);
  }

  while(left!=right){
    K=(right+left)/2;
    sum=0;
    for(i=0;i<N;i++){
      if(h[i]-K*B > 0){
        // sum += (h[i]-K*B)%(A-B) ? (h[i]-B*K)/(A-B)+1 : (h[i]-B*K)/(A-B);
        if((h[i]-K*B)%(A-B)==0){
          sum += (h[i]-B*K)/(A-B);
        }else{
          sum += (h[i]-B*K)/(A-B)+1;
        }
      }
    }
    if(sum <= K){
      right=K;
    }else{
      left=K+1;
    }
  }

  printf("%lld\n", left);

  return 0;
}


Measured memory_bytes: 896
//https://codeforces.com/contest/1334/problem/A
//BROWNIE TK

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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()

#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en

#define le length()
#define mp make_pair
#define mt make_tuple
#define acc(v) accumulate(all(v), 0)
#define F first
#define S second

#define pll pair<lli, lli>
#define pii pair<int, int>
#define pil pair<int, lli>

#define forz(i, n) for (int i = 0; i < n; i++)
#define fore(i, m, n) for (int i = m; i <= n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rfore(i, m, n) for (int i = n; i >= m; i--)

#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define highll(n) __builtin_popcountll(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)

#define bset(a, p) ((a) | (1ll << (p)))
#define bchk(a, p) ((a) & (1ll << (p)))
#define bxor(a, p) ((a) ^ (1ll << (p)));
#define brem(a, p) (bchk(a, p) ? (bxor(a, p)) : (a))
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/

#define lb lower_bound
#define ub upper_bound
#define er equal_range

#define findnot find_first_not_of

#define maxe *max_element
#define mine *min_element

#define mod2 1000000007
#define mod 998244353
#define gcd __gcd
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define osetlli tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements sbtriectly lesser than k
//2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order

/*STD funcions*/
lli power(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
lli modi(lli a, lli m) { return power(a, m - 2, m); }
/*CODE BEGINS*/

int main()
{
    kira;
    lli n;
    cin>>n;
    lli b[n-1];
    forz(i,n-1)
    {
        cin>>b[i];
    }
    lli sum=0;
    sum+=b[n-2];
    for(int i=n-3;i>=0;i--)
    {
        sum+=min(b[i+1],b[i]);
    }
    sum+=b[0];
    p1(sum);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n,k,i,j;
  int v;
  int A[100];
  scanf("%d",&n);
  for(i=1;i<=n;i++)scanf("%d",&A[i]);

  for(j=1;j<=n;j++)
    {   
	      v = A[j];		
	      i = j-1;
	      while(i>0 && A[i]>v)
		{
		  A[i+1]=A[i];  
		  i = i-1;
		}
	      A[i+1] = v;
	      for(k=1;k<=n;k++){
		if(k == n)printf("%d\n",A[k]);
		else printf("%d ",A[k]);
	      }
    }
  
  return 0;
}



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

using namespace std;
typedef long long ll;
#define X first
#define Y second
typedef pair<int,int> P;
int a[5];
P dat[100005];
int n,m,res,lst=1<<30,pos;

bool cmp(P a,P b)
{
	if(a.Y!=b.Y) return a.Y>b.Y;
	return a.X>b.X;
}

int main()
{
//	cin>>a[1]>>a[2]>>a[3];
//	sort(a+1,a+4);
//	cout<<a[3]-a[1];
	
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++) scanf("%d%d",&dat[i].X,&dat[i].Y);
	sort(dat+1,dat+m+1,cmp);
	for(int i=1;i<=m;i++)
	{
		if(dat[i].Y<=lst)
			res++,lst=dat[i].X;
		else lst=max(lst,dat[i].X);
	}
	printf("%d",res);
	return 0;
}

Measured memory_bytes: 1024
from sys import exit

s = [input() for i in range(3)]

turn = 0
card = s[0][0]
sa,sb,sc = 0,0,0
while 1:
    if card == "a":
        if sa == len(s[0]):
            print("A")
            exit()
        card = s[0][sa]
        sa += 1
    if card == "b":
        if sb == len(s[1]):
            print("B")
            exit()
        card = s[1][sb]
        sb += 1
    if card == "c":
        if sc == len(s[2]):
            print("C")
            exit()
        card = s[2][sc]
        sc += 1


Measured memory_bytes: 9032
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<list>
#include<stack>
//#include<unordered_map>
using namespace std;
#define ll long long 
#define dd cout<<endl
#define lll __int128
const int inf=1e9+7;
const int mod=1e9+7;

const int maxn=1e5+10;

ll int num[maxn];

int main()
{
	//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);;
	
	int n,k,q;
	
	scanf("%d%d%d",&n,&k,&q);
	
	int x;
	
	for(int i=0;i<q;i++)
	{
		scanf("%d",&x);
		num[x]++;
	}
	
	/*
	dd;
	for(int i=1;i<=n;i++)
		cout<<num[i]<<" ";
	dd;
	*/
	
	for(int i=1;i<=n;i++)
	{

		if(num[i]-q+k>0)
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;
#define pb push_back
#define po pop_back
#define mp make_pair
#define mt make_tuple
#define F  first
#define S  second
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))
#define all(c) c.begin(),c.end()
#define str string
#define edl "\n"
#define add insert
#define cot continue
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
const double PI = acos(-1);
const ll LINF = LLONG_MAX;




int main() 
{

 fast();

  
  ll a;
  cin>>a;
  vec q(a);
  f(i,0,a)
  {
    cin>>q[i];

  }
  ll c=0;
  f(i,1,a-1)
  {
    if(q[i]>q[i-1]&&q[i]<q[i+1]||q[i]<q[i-1]&&q[i]>q[i+1])
      c++;
  }
  cout<<c;


    




    cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
    return 0;
}
 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j]
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
const int ma=1000000000;
int main(){
    int n,k,s; cin >> n >> k >> s;
    rep(i,k) cout << s << " ";
    if(s!=ma){
        rep(i,n-k) cout << ma << " ";
    }else{
        rep(i,n-k) cout << ma-1 << " ";
    }
}


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

vector<int> sieve(int n) {
  vector<int> prime(n);
  for(int i=2; i<n; i++) prime[i]=i;
  for(int i=2; i*i<n; i++) {
    if(prime[i]) {
      for(int j=i*i; j<n; j+=i) prime[j]=0;
    }
  }
  return prime;
}

int main() {
  vector<int> prime=sieve(1000000);
  int a,b,n;
  while(cin >> a >> b >> n) {
    if(a==0 && b==0 && n==0) break;
    while(n) {
      if(prime[a]!=0) n--;
      a+=b;
    }
    cout << a-b << endl;
  }
  return 0;
}


Measured memory_bytes: 4900
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

#include <set>

using namespace std;

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

    int N;
    cin >> N;

    bool check = true;
    for (int i = 0; i < N; i++)
    {
        int A;
        cin >> A;

        if (A % 2 == 0)
        {
            if (A % 3 != 0 && A % 5 != 0)
            {
                check = false;
                break;
            }
        }
    }

    if (check)
    {
        cout << "APPROVED";
    }
    else
    {
        cout << "DENIED";
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define UP(i,a,b) for(int i=(a); i<=(b); ++i)
#define DOWN(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) UP(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //NOTE: <a> must be sorted in advance

lng power(lng b, lng n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n

const int MOD = 1000000007; //10^9+7


/*********** variables ************/

/**********************************/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    char op;
    cin >> A >> op >> B;
    if(op=='+') cout << A+B << endl;
    else cout << A-B << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  long long K, A, B;

  std::cin >> K >> A >> B;

  if (A + 1 >= B) {
    std::cout << K + 1 << std::endl;
  }
  else if (K <= A) {
    std::cout << K + 1 << std::endl;
  }
  else {
    int c = K - (A + 1), q = c / 2, r = c % 2;
    
    std::cout << B + q * (B - A) + r << std::endl;
  }

  return 0;
}


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

using namespace std;
using ll = long long;

int main()
{
    ll N;
    cin >> N;

    if(N==1)
    {
        cout << 0 << endl;
        return 0;
    }

    ll ans = N*(N-1)/2;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int i,j,h,w,x,y,c,flag;
	char s[101][101],a[101][101];
	while(x=0,y=0,c=0,flag=0,scanf("%d%d%*c",&h,&w),h+w){
		for(i=0;i<h;i++)for(j=0;j<w;j++)a[i][j]=0;
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				scanf("%c",&s[i][j]);
			}scanf("%*c");
		}
		while(s[y][x]!='.'){
			if(a[y][x]==1){
				puts("LOOP");
				flag=1;
				break;
			}
			a[y][x]++;
			switch(s[y][x]){
				case '>':
					x++;
					break;
				case '<':
					x--;
					break;
				case '^':
					y--;
					break;
				case 'v':
					y++;
					break;
			}
		}
		if(flag==1){
			continue;
		}else{
			printf("%d %d\n",x,y);
		}
	}
	return 0;
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

int main(){
   int n,k;
   cin >> n >> k;
   vector<int> a;
   REP(i,n){
       int x;
       cin >> x;
       if(x < k) a.push_back(x);
   }

   int m = a.size();
   sort(all(a));

   bitset<5000> b[m][2];
   b[0][0] = 1;
   b[m - 1][1] = 1;
   REP(i, m - 1) b[i + 1][0] = b[i][0] | (b[i][0] << a[i]);
   REP(i, m - 1) b[m - i - 2][1] = b[m - i - 1][1] | (b[m - i -1][1] << a[m - i -1]);
 
   int ok = m,ng = -1;
   while(ok - ng > 1){
        int mid = (ok + ng)/2;
        bool flag = false;

        for(int i = k - a[mid]; i < k; i++){
            for(int j = 0; j < i + 1; j++){
                if(b[mid][0][j] && b[mid][1][i - j]){
                    flag=true;
                    break;
                }
            }
        }

       if(flag) ok = mid;
       else ng = mid;
   }
   cout << ok << endl;

   return 0;
}

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

int main()
{
    int n;

    while( cin >> n )
    {
        if( n == 0 )
            break;
        
        int min = 1000000, max = 0;
        for( int i = 0; i < n; i++ )
        {
            int d, sum = 0;
            for( int j = 0; j < 5; j++ )
            {
                cin >> d;
                sum += d;
            }
            if( sum > max )
                max = sum;
            if( sum < min )
                min = sum;
        }
        cout << max << " " << min << endl;
    }
    return 0;
}



Measured memory_bytes: 3096
#include<iostream>
using namespace std;
int main(){
  int a[4],b[4];
  while(cin >>a[0]){
    int hans = 0, bans = 0;
    for(int i=1; i<4; i++) cin >>a[i];
    for(int i=0; i<4; i++) cin >>b[i];
    for(int i=0; i<4; i++){
      if(a[i] == b[i]){
	hans++;
	a[i] = 10;
	b[i] = 11;
      }
    }
    for(int i=0; i<4; i++){
      for(int j=0; j<4; j++){
	if(a[i] == b[j]){
	  bans++;
	  a[i] = 10;
	  b[j] = 11;
	}
      }
    }
    cout <<hans<<" "<<bans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
import heapq

n,m=map(int,input().split())
a=[int(x) for x in input().split()]
h=[]

for i in range(n):
  heapq.heappush(h, -a[i])

for i in range(m):
  heapq.heappush(h, -((-heapq.heappop(h))//2))

t=0
for i in range(n):
  t -= heapq.heappop(h)

print(t)


Measured memory_bytes: 14180
def cal(ope,a,b):
    if ope=="+":
        return a+b
    if ope=="-":
        return a-b
    if ope=="*":
        return(a*b)

data=input().split()
ans=[]
for i in data:
    if i.isdecimal():
        ans.append(int(i))
    else:
        b=ans.pop()
        a=ans.pop()
        ans.append(cal(i,a,b))

print(ans[0])



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

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(ll N) : par(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

int main(void){
    ll N,M;
    cin>>N>>M;
    UnionFind tree(N);

    for(ll i=0;i<M;i++){
        ll a,b;
        cin>>a>>b;
        tree.unite(a,b);
    }

    ll count=0;
    for(ll i=0;i<tree.par.size();i++){
        if(tree.par[i]==i){
            count++;
        }
    }

    cout<<count-1<<endl;
}

Measured memory_bytes: 4000
#include<bits/stdc++.h>
#include<string>
#define int long long
using namespace std;
main()
{
	//freopen("input.txt","rt",stdin);
	string str;
	cin>>str;
	int n = str.length();
	int c =0;
	int p =1;
	for(int i=0;i<n;i++)
	{
		if(str[i]-'0' != p)
		{
			c++;
		}
		if(p == 0)
		{
			p = 1;
		}
		else {
			p = 0;
		}
	}
	p = 0;
	int c1 = 0;
	for(int i=0;i<n;i++)
	{
		if(str[i]-'0' != p)
		{
			c1++;
		}
		if(p == 0)
		{
			p = 1;
		}
		else {
			p = 0;
		}
	}
	cout<<min(c,c1)<<endl;
}

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

using namespace std;


#define ll long long
#define fn for(i=0;i<n;i++)
#define f(k,n) for(i=k;i<n;i++)
#define deb(x) cout<<#x<<" "<<x<<endl;
#define read(x) getline(cin,x)

typedef pair<int, int> pairii;
typedef vector<int> veci;
typedef set<int> seti;
typedef unordered_set<int> unseti;

template<typename... T>
void r(T&... args){
    ((cin>>args),...);
}

template<typename... T>
void w(T&&... args){
    ((cout<<args<<" "),...);
}

template<typename T>
void disp(T arr)
{
    for (ll i = 0; i < arr.size(); i++)
    {
        cout << arr[i] << " ";
    }
    cout << endl;
}




void solve(){
    ll n,m,x,temp=0,sum=0,sum1=0,sum2=0,cnt=0,in,i,j,k,flag=1;
    string s,s1s2;
    veci v,e,o,p;
    r(n,m);
    fn{
        r(in);
        v.push_back(in);
    }
    sort(v.begin(),v.end());
    for(i=0;i<m;i++)
        sum1+=v[i];
    cout<<sum1;
}


int main(){

    /*#ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif*/

    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    ll t=1;
    //cin >> t;

    while(t--)
        solve();
    return 0;
}



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

int main(){
  int n;
  cin >> n;
  int l[n],r[n];
  for(int i=0;i<n;i++){
    cin >> l[i] >> r[i];
  }
  int t[n];
  for(int i=0;i<n;i++){
    t[i]=r[i]-l[i]+1;
  }
  int ans=0;
  for(int i=0;i<n;i++){
    ans=ans+t[i];
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(N: int):
    return print((10**N - 2*9**N + 8**N)%MOD)

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 11012
#include<iostream>
#include<vector>

using namespace std;
const int MAXN = 1e5;
const int INF = 1e9 - 7;
typedef long long ll;
ll dp[MAXN + 2][4];
int n;
vector<ll> a,b,c;

ll happy(ll N, ll K){
	if(N == 0) return 0;
	if(dp[N][K] != -1) return dp[N][K];
	if(K == 3) return dp[N][K] = max(happy(N-1, 2) + b[N], happy(N-1, 1) + a[N]);
	if(K == 2) return dp[N][K] = max(happy(N-1, 1) + a[N], happy(N-1, 3) + c[N]);
	if(K == 1) return dp[N][K] = max(happy(N-1, 2) + b[N], happy(N-1, 3) + c[N]);
	if(K == 0) return dp[N][K] = max(happy(N-1, 1) + a[N], max(happy(N-1, 2) + b[N],happy(N-1, 3) + c[N]));
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;

	a = vector<ll>(n + 1);
	b = vector<ll>(n + 1);
	c = vector<ll>(n + 1);

	for(int i=0 ; i<=n ; i++)
		for(int j=0 ; j<=3 ; j++)
			dp[i][j] = -1;
	a[0] = INF;
	b[0] = INF;
	c[0] = INF;
	for(int i=1 ; i<=n; i++){
		cin >> a[i] >> b[i] >> c[i];
	}
	cout << happy(n, 0) <<"\n";
		
	return 0;
}


Measured memory_bytes: 12804
#!usr/bin/env python3

import sys


# def generate_buidlings(building, floor, room):
#     empty_buildings = {
#             key: [[0 for col in range(room)] for row in range(floor)]
#             for key in range(1, building+1)
#     }
#     return empty_buildings
#
#
# def occupy_buildings(empty_buildings):
#     occupied_buildings = generate_buidlings(4, 3, 10)
#     n = int(sys.stdin.readline())
#
#     for i in range(n):
#         lst = [int(num) for num in sys.stdin.readline().split()]
#         occupied_buildings[lst[0]][lst[1]-1][lst[2]-1] += lst[3]
#
#     return occupied_buildings

def generate_buidlings_with_residents(building, floor, room):
    buildings = {
        key: [[0 for col in range(room)] for row in range(floor)]
        for key in range(1, building+1)
    }

    n = int(sys.stdin.readline())
    for i in range(n):
        lst = [int(num) for num in sys.stdin.readline().split()]
        buildings[lst[0]][lst[1]-1][lst[2]-1] += lst[3]

    return buildings


def print_buildings():
    separator = '####################'
    buildings_with_residents = generate_buidlings_with_residents(4, 3, 10)

    for idx, (key, value) in enumerate(buildings_with_residents.items()):
        for floor in value:
            print(' %s %s %s %s %s %s %s %s %s %s' % tuple(floor))
        if key < len(buildings_with_residents):
            print(separator)


def main():
    print_buildings()


if __name__ == '__main__':
    main()

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a, b;  cin >> n >> a >> b;
    cout << min(a * n, b) << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXN = 3e2 + 5;
const int MAXM = 3e2 + 5;
const int mod = 1e9 + 7;

inline void add_mod(int &a,int b){ a+=b; if(a>=mod) a-=mod;}

int f[MAXM][MAXN][MAXN];

int main(void)
{
	int n,m;
	scanf("%d%d",&n,&m);
	
	f[0][1][1]=1;
	for(int k=0; k<m; ++k)
	{
		for(int i=1; i<=k+1; ++i)
			for(int j=1; j<=i; ++j)
			{
				ll now = f[k][i][j];
				add_mod(f[k+1][i+1][j], now*(n-i) %mod);
				add_mod(f[k+1][i][j], now*(i-j) %mod);
				add_mod(f[k+1][i][i], now*j %mod);
			}
	}
	printf("%d",f[m][n][n]);
	return 0;
}

Measured memory_bytes: 108800
/**
 *    author:  math2do
 *    created: 03.03.2020 11:24:05
**/

#include <bits/stdc++.h>

using namespace std;

template <typename T> 
inline void read(T &x) {
  char c = (char) getchar();
  bool f = false;
  for (x = 0; !isdigit(c); c = (char) getchar()) {
    if (c == '-') {
      f = true;
    }
  }
  for (; isdigit(c); c = (char) getchar()) {
    x = x * 10 + c - '0';
  }
  if (f) {
    x = -x;
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n = 3, m = 3;
  vector <vector <bool>> mat(n, vector <bool>(m));
  map <int, pair <int, int>> mp;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int val;
      read(val);
      mp[val] = {i, j};
    } 
  }
  int N;
  read(N);
  for (int i = 0; i < N; i++) {
    int val;
    read(val);
    auto it = mp.find(val);
    if (it != mp.end()) {
      int x = it->second.first;
      int y = it->second.second;
      mat[x][y] = true;
    } 
  } 
  // checking row
  for (int i = 0; i < n; i++) {
    if (mat[i][0] && mat[i][1] && mat[i][2]) {
      cout << "Yes" << endl;
      return 0;
    } 
  }
  // checking column
  for (int j = 0; j < m; j++) {
    if (mat[0][j] && mat[1][j] && mat[2][j]) {
      cout << "Yes" << endl;
      return 0;
    } 
  }
  // checking main diagonal
  if (mat[0][0] && mat[1][1] && mat[2][2]) {
    cout << "Yes" << endl;
    return 0;
  }

  // checking main diagonal
  if (mat[0][2] && mat[1][1] && mat[2][0]) {
    cout << "Yes" << endl;
    return 0;
  } 

  cout << "No" << endl; 
  return 0;
}


Measured memory_bytes: 256
#include<iostream>  
#include<string> 
using namespace std; 
int main() {
	 
	int t, a; 
	cin >> t >> a; 
	int k; 
	cin >> k; 
	for (int i = 0; i < k; i++)
	{
		if ((i+1) % 2 == 1) { 
			if (t % 2 == 1) {
				t = t - 1;
					a += t / 2; 
				t = t / 2;
			}  
			else
			{
				a += t / 2;
				t = t / 2;
			}
			
	}   
		else
		{
			if (a % 2 == 1) {
				a = a - 1;
				t += a / 2;
				a = a / 2;
			} 
			else
			{
				t += a / 2;
				a = a / 2;
			}
		}
		
	}
	 
	cout << t << " " << a << " \n";
}

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

int main() {
  int N,M;
  cin>>N>>M;
  int a,b;
  vector<int> vec(N);
  rep(i,M){
    cin>>a>>b;
    vec.at(a-1)++;
    vec.at(b-1)++;
  }
  rep(i,N){
    cout<<vec.at(i)<<endl;
  }
}


Measured memory_bytes: 256
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
sa1=(a1-b1)*t1
sa2=(a2-b2)*t2
if sa1>=0:
    sa1*=-1
    sa2*=-1
if sa1+sa2==0:
    print("infinity")
if sa1+sa2<0:
    print(0)
if sa1+sa2>0:
    ans=((-sa1)//(sa2+sa1))*2+1
    if sa1%(sa1+sa2)==0:
        ans-=1
    print(ans)


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

int main() {
  ll n,m,k;
  cin >> n >> m >> k;
  vector<ll> a(n+1), b(m+1);
  a[0] = 0;
  ll t = 0;
  for(int i=1;i<=n;i++){
    ll tmp;
    cin >> tmp;
    t += tmp;
    a[i] = t;
  }
  t = 0;
  b[0] = 0;
  for(int i=1;i<=m;i++){
    ll tmp;
    cin >> tmp;
    t += tmp;
    b[i] = t;
    
  }
  int ans=0;
  for(int i=0;i<=n;i++){
    ll amari = k-a[i];
    if(amari<0) continue;
    int left=-1, right=b.size();
    while(right-left > 1){
      int mid = left + (right-left)/2;
      if(b[mid] > amari) right = mid;
      else left = mid;
    }
    ans = max(ans, left+i);
  }
  cout << ans << endl;
}


Measured memory_bytes: 6420
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

char str[5];
void solve()
{
    scanf("%s", str);
    if (str[0] == '7' || str[1] == '7' || str[2] == '7') {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }



    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}



Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a;
  int b;
  cin>>a;
  cin>>b;
  int c;
  c=a-(2*b);
  if(c<=0)
  {
    c=0;
    cout<<c;
  }
  else
    cout<<c;

}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define move(i) for(int i=-1;i<=1;i+=2)
#define WHITE 0
#define GRAY 1 
#define BLACK 2
#define INF 1e9

using namespace std;
using P = pair<int,int>;

int h,w,M[50][50],C[50][50],D[50][50];

int main()
{
    int black=0;
    cin>>h>>w;
    rep(i,h){
        rep(j,w){
            char s;
            cin>>s;

            if(s=='.'){
                M[i][j] = 0;
            }else{
                M[i][j] = 1;
                black++;
            }

            C[i][j]=WHITE;
            D[i][j]=INF;
        }
    }

    //BFS
    queue<P> Q;
    D[0][0]=1;
    C[0][0]=GRAY;
    Q.push(make_pair(0,0));
    while(!Q.empty()){
        P p=Q.front(); Q.pop();
        //cout <<"~("<< p.first << "," << p.second << ")~"<<endl;
        move(x){
            int i=p.first+x, j=p.second;
            //cout <<"("<< i << "," << j << ")"<<endl;
            if((i>=0)&&(i<h)&&(j>=0)&&(j<w) ){
                //cout << M[i][j] << "," << C[i][j] << endl;
                if(M[i][j]==0 && C[i][j]==WHITE){
                    C[i][j]=GRAY;
                    D[i][j]=D[p.first][p.second]+1;
                    Q.push(make_pair(i,j));
                }
            }
        }

        move(y){
            int i=p.first, j=p.second+y;
            //cout <<"("<< i << "," << j << ")"<<endl;
            if((i>=0)&&(i<h)&&(j>=0)&&(j<w) ){
                //cout << M[i][j] << "," << C[i][j] << endl;
                if(M[i][j]==0 && C[i][j]==WHITE){
                    C[i][j]=GRAY;
                    D[i][j]=D[p.first][p.second]+1;
                    Q.push(make_pair(i,j));
                }
            }
        }

    }
    if(D[h-1][w-1]==INF){
        cout << -1 << endl;
    }else{
        cout << h*w-D[h-1][w-1]-black << endl;
    }



    return 0;
}


Measured memory_bytes: 256
/*
 * ALDS1_10_A.cpp
 *
 *  Created on: May 5, 2018
 *      Author: 13743
 */

#include<iostream>

using namespace std;

int F[44];

int fib(int n) {
	if(F[n] == 0) {
		F[n] = fib(n-2) + fib(n-1);
	}
	return F[n];
}

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

	F[0] = F[1] = 1;

	cout << fib(n) << endl;
}





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

using namespace std;

int main()
{
    int n, m, x=0, y=0, z=0;
    cin>>n>>m;
    if(n%2==0)
    {
       if(n==2)
       {
           z=1;
       }
       else if(n==4||n==6)
       {
           y=1;
       }
       else
       {
           x=1;
       }
    }
    else
    {
       if(n==9||n==11)
       {
           y=1;
       }
       else
       {
           x=1;
       }
    }
     if(m%2==0)
    {
       if(m==2)
       {
           z=1;
       }
       else if(m==4||m==6)
       {
           y=1;
       }
       else
       {
           x=1;
       }
    }
    else
    {
       if(m==9||m==11)
       {
           y=1;
       }
       else
       {
           x=1;
       }
    }
    if(x==1&&y==1)
    {
        cout<<"No"<<endl;
    }
    else if(x==1&&z==1)
    {
        cout<<"No"<<endl;
    }
    else if(z==1&&y==1)
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
A, B, M = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))

min_pr = min(A) + min(B)

for i in range(M):
    x, y, c = map(int, input().split())

    price = A[x-1] + B[y-1] - c
    min_pr = min(min_pr, price)

print(min_pr)

Measured memory_bytes: 70468
#include<iostream>
using namespace std;
int main(){
     int a,b,c;
     cin>>a>>b>>c;
     if(a<b){
        if(b<c){
         cout<<"Yes"<<endl;
     }else{
         cout<<"No"<<endl;
     }
     }else{
          cout<<"No"<<endl;
     }
    
     return 0;
}




Measured memory_bytes: 3120