akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in).useDelimiter("[\\s,]+");
		while (true) {
			n = scanner.nextInt();
			if (n == 0)
				break;
			m = scanner.nextInt();
			e = new Edge[m];
			for (int i = 0; i < m; i++) {
				int from = scanner.nextInt();
				int to = scanner.nextInt();
				int cost = scanner.nextInt() / 100 - 1;
				e[i] = new Edge(from, to, cost);
			}
			System.out.println(kruskal());
		}
	}

	private int kruskal() {
		Arrays.sort(e);
		int ans = 0;
		Union union = new Union(n);
		for (int i = 0; i < m; i++) {
			Edge edge = e[i];
			if (union.isSame(edge.from, edge.to))
				continue;
			ans += edge.cost;
			union.unit(edge.from, edge.to);
		}

		return ans;
	}

	int n, m;
	Edge[] e;

	class Union {
		int[] par, rank;

		public Union(int n) {
			par = new int[n];
			rank = new int[n];
			for (int i = 0; i < n; i++)
				par[i] = i;
		}

		int find(int x) {
			if (par[x] == x)
				return x;
			return par[x] = find(par[x]);

		}

		boolean isSame(int x, int y) {
			return find(x) == find(y);
		}

		void unit(int x, int y) {
			x = find(x);
			y = find(y);
			if (x == y)
				return;
			if (rank[x] < rank[y])
				par[x] = y;
			else {
				par[y] = x;
				if (rank[x] == rank[y])
					rank[x]++;
			}
		}
	}

	class Edge implements Comparable<Edge> {
		int from, to, cost;

		public Edge(int from, int to, int cost) {
			super();
			this.from = from;
			this.to = to;
			this.cost = cost;
		}

		@Override
		public String toString() {
			return "Edge [from=" + from + ", to=" + to + ", cost=" + cost + "]";
		}

		@Override
		public int compareTo(Edge o) {
			return cost - o.cost;
		}

	}
}

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

int N, M;
vector<vector<int>> g(N);   
// sからtにたどり着けるか、bfsにて判定する
bool bfs(int s, int t) {
    vector<int> c(N, 0);
    queue<int> Q;
    Q.push(s);
    while(!Q.empty()) {
        int v1 = Q.front(); Q.pop();
        c[v1] = 1;
        for(int i=0; i<g[v1].size(); ++i){
            int v2 = g[v1][i];
            if(v2==t) return true;
            if(c[v2]==0) Q.push(v2);
        }
    }
    return false;
}

int main() {
    cin >> N >> M;
    g.resize(N);
    int cnt = 0;
    vector<pair<int, int>> p(M); // 辺の情報を格納する
    for(int i=0; i<M; ++i) {
        int a, b; cin >> a >> b; --a; --b;
        g[a].push_back(b);
        g[b].push_back(a);
        p[i].first = a;
        p[i].second = b;
    }

    for(int i=0; i<M; ++i) {
        int s = p[i].first;
        int t = p[i].second;

        // 指定された辺を削除
        for(auto it=g[s].begin(); it!=g[s].end();) {
            if(*it==t) {
                it = g[s].erase(it);
            }
            else ++it;
        }
        for(auto it=g[t].begin(); it!=g[t].end();) {
            if(*it==s) {
                it = g[t].erase(it);
            }
            else ++it;
        }
        for(int i=0; i<N; ++i) {
            g[i].shrink_to_fit();
        }
        if(!bfs(s, t)) ++ cnt;

        // チェックが終わったら辺をもとに戻す
        g[s].push_back(t);
        g[t].push_back(s);        
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
int factorial(int n);
int factorial(int n)
{
    if(n==1)
    {
        return 1;
    }
    else
    {
        return n*factorial(n-1);
    }

}

bool is_prime(ll n) {
    // Assumes that n is a positive natural number
    // We know 1 is not a prime number
    if (n == 1) {
        return false;
    }

    ll i = 2;
    // This will loop from 2 to int(sqrt(x))
    while (i*i <= n) {
        // Check if i divides x without leaving a remainder
        if (n % i == 0) {
            // This means that n has a factor in between 2 and sqrt(n)
            // So it is not a prime number
            return false;
        }
        i += 1;
    }
    // If we did not find any factor in the above loop,
    // then n is a prime number
    return true;
}
int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
typedef unsigned long long  ull;

int check(int x,vector <int> a,int n)
{  int county=0;
  map <int,int> mapa;
    for(int i=0;i<n;i++)
    {
        mapa.insert(pair<int,int>(a[i],0));
    }
    for(int i=0;i<n;i++)
    {
        mapa[a[i]]++;
    }
   // cout<<mapa[1]<<mapa[2]<<mapa[3]<<mapa[4]<<mapa[5]<<endl;
    for(int i=0;i<a.size();i++)
    {   mapa[a[i]]--;
        if(mapa[abs(a[i]-x)]>0)
        {
            county++;


            mapa[abs(a[i]-x)]--;
        }


    }
    return county;
}

typedef unsigned int ui;

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

string s;
cin>>s;
ull sum=0;
for(int i=0;i<s.size();i++)
{
    sum+=s[i]-'0';
}
if(sum%9==0)
{
    cout<<"Yes"<<endl;
}
else
{
    cout<<"No"<<endl;
}





}


Measured memory_bytes: 3772
# coding: utf-8
class Case03

  def initialize
  end

  def show
    p self.instance_variables
        .map{ |sym| [sym, self.instance_variable_get(sym)] }
        .to_h
  end
  
  # 実行する
  def execute
    read
    solve
    output
  end

  # 読込
  def read
    @n, @k, @q = gets.chomp.split.map(&:to_i)
    @a = []
    @player = Array.new(@n, 0)
    @q.times do
      @a << gets.chomp.to_i
    end
  end

  # 回答
  def solve
    @a.each do |x|
      @player[x-1] += 1
    end
  end
  
  # 出力
  def output
    @player.each do |y|
      puts (y - @q + @k > 0) ? 'Yes' : 'No'
    end
  end

end

Case03.new.execute if $0 == __FILE__



Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long A, long long B)
{
    ll ans = 0;
    if (A < B)
    {
        ans += B;
        B--;
    }
    else
    {
        ans += A;
        A--;
    }
    if (A < B)
    {
        ans += B;
        B--;
    }
    else
    {
        ans += A;
        A--;
    }
    cout << ans << endl;
}

int main()
{
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    solve(A, B);
    return 0;
}


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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;


signed main() {
    int n;
    cin >> n;
    rep(i, n) {
        int a;
        cin >> a;
        if (a % 2 == 0) {
            if (a % 3 && a % 5) {
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 998244353;
ll dp[305][305][305];

int main(void){
    string s;
    int k;
    cin >> s >> k;
    // REP(i,100) s += "011";
    // s = string(100, '0') + string(200, '1');
    // k = 500;
    VI a;
    int cnt = 0, sum = 0;
    for (char c : s){
        if (c == '1'){
            cnt++;
            sum++;
        }else{
            a.push_back(cnt);
            cnt = 0;
        }
    }
    a.push_back(cnt);
    reverse(ALL(a));
    int n = a.size();

    // REP(i,n) cout << a[i] << endl;

    dp[0][0][0] = 1;
    int p = 0;
    REP(i,n){
        p += a[i];
        REP(j,p+1) REP(k,p+1){
            REP(x,sum+1){
                if (j + x > p) break;
                (dp[i + 1][j + x][k + min(x, a[i])] += dp[i][j][k]) %= mod;
            }
        }
    }

    // REP(i,n+1){
    //     cout << i << endl;
    //     REP(j,sum+1){
    //         REP(k,sum+1) cout << dp[i][j][k] << " ";
    //         cout << endl;
    //     }
    //     cout << endl;
    // }

    ll ans = 0;
    REP(x,sum+1) if (sum - x <= k) (ans += dp[n][sum][x]) %= mod;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 57116
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code ---*/
	M := nextInt()
	D := nextInt()
	ans := 0
	for d := 22; d <= D; d++ {
		d1 := d % 10
		d10 := d / 10
		if d1 < 2 || d10 < 2 {
			continue
		}
		if d1*d10 <= M {
			ans++
		}
	}
	fmt.Fprintln(out, ans)
}

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// Genericsがないので筋肉で...
// interfaceでの取扱がようわからんし
func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// mapからkeysとvaluesを返す感じのやつ
// なんかしらんけどmap[interface{}]interface{}しか受け付けない。なんのためのinterface{}やねん
// なので呼ぶときのmapはmap[int]stringとかじゃダメ
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
	return
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
/*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
ll ncd(ll n,ll d){
    ll x = 1,y=1;
    for(int i=0;i<d;i++){
        x = x*(n-i)%mod;
        y = y*(i+1)%mod;
    }
    return x*modpow(y,mod-2,mod)%mod;
}
int main() {
    ll n,a,b;
    cin >> n >> a >> b;
    ll ans = modpow(2,n,mod)-1 -ncd(n,a)-ncd(n,b);
    ans%=mod;
    while(ans<0){
        ans+=mod;
    }
    cout <<ans <<endl;
}
    



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

int main() {
  int N;
  string S;
  cin >> N;
  cin >> S;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C') {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <sstream>
#include <cstdlib>
using namespace std;
int main(){
    int n,m,A[101][101]={0},b[101]={0},c[101]={0},i,j,k;
    cin>>n>>m;
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            cin>>A[i][j];
        }
    }
    for(k=0;k<m;k++){
        cin>>b[k];
    }
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            c[i]+=A[i][j]*b[j];
        }
    }
    for(i=0;i<n;i++){
        cout<<c[i]<<endl;
    }

        return 0;
    }



Measured memory_bytes: 3128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) 
{
    os << "{ ";
    for(auto& y : x) 
    {
        os << y << " ";
    }
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) 
{
    return os << "[" << p.ff << ", " << p.ss << "]";
}

ll gcd(ll a, ll b)
{
    if(b==0)
    {
        return a;
    }

    return gcd(b, a%b);
}

ll modexp(ll a, ll b, ll c)
{   
    a%=c;

    ll ans = 1;

    while(b)
    {
        if(b&1)
        {
            ans = (ans*a)%c;
        }

        a = (a*a)%c;
        b >>= 1;
    }

    return ans;
}

ll nxt()
{
    ll x;
    cin >> x;
    return x;
}

const ll L = 50+5;
const ll mod = 1e9 + 7;

typedef struct Matrix {
    ll mat[L][L];
} matrix;

matrix multiply(matrix A, matrix B, ll mod)
{
    Matrix ans;

    for(ll i=0; i<L; i++)
    {
        for(ll j=0; j<L; j++)
        {
            ans.mat[i][j] = 0;

            for(ll k=0; k<L; k++)
            {
                ans.mat[i][j] += ((A.mat[i][k] * B.mat[k][j])%mod);
                ans.mat[i][j] %= mod;
            }
        }
    }

    return ans;
}

matrix identity()
{
    matrix ans;

    for(ll i=0; i<L; i++)
    {
        for(ll j=0; j<L; j++)
        {
            ans.mat[i][j] = 0;

            if(i == j)
            {
                ans.mat[i][j]++;
            }
        }
    }

    return ans;
}

matrix modexp(matrix A, ll b, ll mod)
{
    matrix ans = identity();

    while(b)
    {
        if(b & 1)
        {
            ans = multiply(ans, A, mod);
        }

        A = multiply(A, A, mod);
        b >>= 1;
    }

    return ans;
}

void solve()
{
    ll n = nxt(), k = nxt();

    matrix a;

    for(ll i=0; i<n; i++)
    {
        for(ll j=0; j<n; j++)
        {
            cin >> a.mat[i][j];
        }
    }

    matrix ans = modexp(a, k, mod);

    ll total = 0;

    for(ll i=0; i<n; i++)
    {
        for(ll j=0; j<n; j++)
        {
            total += ans.mat[i][j];
            total %= mod;
        }
    }

    cout << total << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    ll T = 1;
    // T = nxt();

    while(T--)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 512
<?php



function checkMonth($n){
    $n = (int)$n;
    if($n > 0 && $n < 13){
        return(true);
    }   else{
        return(false);
    }
}
$n = 0;
$k = 0;
# 整数の入力
fscanf(STDIN, "%d %d", $n, $k);
$ans =0;
for($i=1; $i <= $n; $i++){
    if($i < $k){
        $log = $k / $i;
        $kaisuu = ceil(log($log, 2));
        $ans += (1/$n) * pow(0.5, $kaisuu);
    }else{
        $ans += (1/$n);
    }
}
echo $ans;

Measured memory_bytes: 4728
n,k = map(int,input().split())
P = list(map(int,input().split()))

total = 0
ans = 0
for i,a in enumerate(P):
    total += (a+1)/2
    if i >= k:
        total -= (P[i-k]+1)/2
    if i >= k-1:
        ans = max(total,ans)
    
print(ans)
     

Measured memory_bytes: 24812
import java.util.*;
class Main{
  static int n;
  public static void main(String args[])throws Exception{
    Scanner sc = new Scanner(System.in);
    int count = 0;
    int number = 0;
    n = sc.nextInt();
    int array_s [] = new int[n];
    for(int i =0; i<n; i++){
      array_s[i] = sc.nextInt();
    }

    int q = sc.nextInt();
    int t;
    for(int i = 0; i<q; i++){
      t = sc.nextInt();
      //二分探索
      count += binarysearch(t, array_s);
    }
    System.out.println(count);
  }

  static int binarysearch(int k , int a[]){
    int left = 0;
    int right = n;
    int mid;
    while(left<right){
      mid = (left+right)/2;
      if(k==a[mid])return 1;
      else if(k<a[mid])right=mid;
      else left = mid+1;
    }
    return 0;
  }
}


Measured memory_bytes: 68812
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int x;
    cin>>x;
    int count=0;
    int sum=0;
    int i=1;
    while(sum<x){
        sum+=i;
        count++;
        ++i;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
//Name: Chocolate
//Level: 2
//Category: 動的計画法,DP
//Note:

/**
 * あるピースを食べるためには、その真上に存在するピースは必ず食べられている必要がある。
 * また、端以外のピースでは、少なくともその左右どちらかのピースが食べられている必要がある。
 *
 * これらの事実より、まず、上から順に1行ずつ食べていっても結果は変わらないことがわかる。
 * 次に、ある行を食べていくときは、両端のうち少なくとも片方は反転させずに食べる必要があることがわかる。
 * 同様の考察を繰り返すと、ある行に含まれるほとんどのピースは反転させた状態で食べることになり、反転させずに食べられるピースは以下の2通りのどちらかである。
 * (1) 両端から食べ進めていき、最後に列iのピースのみが残るようにする。
 *     このとき、両端と列iのピースが反転されていない状態で食べられる。
 * (2) 一方の端から食べ進めていき、反対側の端まで食べる。
 *     このとき、最初に選んだピースのみが反転されていない状態で食べられる。
 * したがって、各行に対して、どちらの戦略を取ったほうが得であるかを個別に判定していけばよい。
 *
 * 幅が2以下のとき、(1)の食べ方は不可能であることに注意。
 * オーダーは O(NM)。
 */
#include <iostream>
#include <string>
#include <vector>

using namespace std;

bool solve() {
    int M, N;
    if(!(cin >> M >> N)) return false;

    int score = 0;
    for(int i = 0; i < M; ++i) {
        int subsum = 0;
        int edge_1 = 0;
        int mid_1 = 0;
        for(int j = 0; j < N; ++j) {
            int p;
            cin >> p;
            if(i > 0) p ^= 1;
            subsum += p^1; // すべてのピースは反転させてから食べるとして、後で調整する
            if(j == 0 || j == N-1) edge_1 += p;
            else mid_1 += p;
        }
        // Pattern (1)
        // 端について
        // ・両端とも辛ければ-2
        // ・片方だけ甘ければ+0
        // ・両方とも甘ければ+2
        // さらに、中間で(mid_1 > 0 ? 1 : -1)だけ増える
        // （両端以外で甘いピースがない場合、わざわざ辛いピースのままで食べることになるため）
        const int s1 = score + subsum + (edge_1-1) * 2 + (mid_1 > 0 ? 1 : -1);
        // Pattern (2)
        // edge_1が0のとき、どちらかは辛いままで食べる必要があるので1だけ減る。
        // edge_1が1のとき、甘い方から食べていけば1増える。
        // edge_1が2のとき、どちらかを甘いままで食べられるので1だけ増える。
        const int s2 = score + subsum + (edge_1 > 0 ? 1 : -1);
        score = max(score, s2);
        if(N > 2) score = max(score, s1);
    }
    cout << score << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

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

int main() {
	int n,k;
	cin>>n>>k;
	
	int a,b,x,y,ans;
	int half=n-n/2;
	for(int i=0;i<k;i++){
		cin>>a>>b;
		
		if(a>half){
			if(a==n){
				x=1;
			} else{
				x=half-a%half;
				if(n%2==0){
					x+=1;
				}
			}
		} else{
			x=a;
		}
		if(b>half){
			if(b==n){
				x=1;
			} else{
				y=half-b%half;
				if(n%2==0){
					y+=1;
				}
			}
		} else{
			y=b;
		}
		
		if(x>y){
			ans=y%3;
		} else{
			ans=x%3;
		}
		
		if(ans){
			cout<<ans<<endl;
		} else{
			cout<<3<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 9 * (long long int)pow(10, 13);

int N,M;

int main() {
	cin >> N >> M;
	cout << (N + M) % 24 << endl;
	return 0;
}


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

int main() {
	ll n,cnt=0,sum=0,suma=0,last;
	cin>>n;
	ll arr[n+1],brr[n];
	for(ll i=0;i<=n;i++)
	{
		cin>>arr[i];
		suma=suma+arr[i];
	}
	for(ll i=0;i<n;i++)
	{
		cin>>brr[i];
	}
	for(ll i=0;i<n;i++)
	{
		 if(brr[i]<arr[i])
		 sum=sum+brr[i];
		 else
		 {
		 	sum=sum+arr[i];
		 	if(arr[i+1]>=brr[i]-arr[i])
		 	{
		 	sum=sum+brr[i]-arr[i];
		 	arr[i+1]=arr[i+1]+arr[i]-brr[i];
		 	}
		 	else
		 	{
		 		sum=sum+arr[i+1];
		 		arr[i+1]=0;
		 	}
		 }
	}
	cout<<min(sum,suma);
	return 0;
}

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

int main(){
    string s;
    int k;
    cin >> s >> k;
    set<string> x;
    int n = s.length();
    for(int i = 0; i < n; i++){
        string t = "";
        for(int j = 0; j < 5 && i+j < n; j++){
            t += s[i+j];
            x.insert(t);
        }
    }
    auto it = x.begin();
    while(k-- > 1)  it++;
    cout << *it << endl;
    return 0;
}

Measured memory_bytes: 1664
#include<stdio.h>
#include<string.h>
int main()
{
	char inp[11];
	scanf("%s",inp);
	int j=0;
	char out[11]={'\0'};
	int len = strlen(inp);
	for(int i = 0; i < len; i++)
	{
		if(inp[i]=='0')
		{
			out[j]='0';
			j++;
		}
		else if(inp[i]=='1')
		{
			out[j]='1';
			j++;
		}
		else if(inp[i]=='B')
		{
			if(j!=0)
			{
				j--;
				out[j]='\0';
			}
		}
	}
	printf("%s", out);
 	return 0;   
}

Measured memory_bytes: 1704
N, M = gets.split.map(&:to_i)
H = gets.split.map(&:to_i)
H.unshift nil
paths = M.times.map { gets.split.map(&:to_i) }
res = Array.new(N+1) { true }
res[0] = false

paths.each do |a, b|
  if H[a] > H[b]
    res[b] = false
  elsif H[a] < H[b]
    res[a] = false
  else
    res[a] = false
    res[b] = false
  end
end

puts res.count(true)


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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) {
        freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);
        //freopen("d:\\code\\cpp\\contests\\stdout", "w", stdout);
    }

    int n;
    cin >> n;

    bool sol = 1;
    FOR(i, n){
        int ai;
        cin >> ai;
        if (ai%2==0)
            sol &= ai%3 == 0 || ai%5==0;
    }
    if (sol)
        cout << "APPROVED" << endl;
    else
        cout << "DENIED" << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int X, Y;
    cin >> X >> Y;
    if(Y>X*4){
        cout << "No"; 
    }else if(Y<X*2){
        cout << "No";
    }else if(Y%2==1){
        cout << "No";
    }else{
        cout << "Yes";
    }
}

Measured memory_bytes: 3600
import sys
from math import ceil, log2
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
N, K = tuple(li())
total = 0
for i in range(1, N + 1):
    if i < K:
        total += 2 ** -ceil(log2(K/i))
    else:
        total += 1
print(total/N)


Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

char map[60][60];
int used[60][60];
void dfs(int x, int y) {
  if (x < 0 || y < 0 || 50 < x || 50 < y) {
    return;
  }
  if (used[x][y] == 1) {
    return;
  }
  if (map[x][y] == '#') {
    used[x][y] = 1;
  } else {
    char count = '0';
    for (int i = -1; i != 2; i++) {
      for (int j = -1; j != 2; j++) {
        if (0 <= x + i && x + i < 50 && 0 <= y + j && y + j < 50) {
          count += map[x + i][y + j] == '#';
        }
      }
    }
    map[x][y] = count;
    used[x][y] = 1;
  }

  dfs(x, y + 1);
  dfs(x, y - 1);
  dfs(x + 1, y);
  dfs(x - 1, y);
}

int main() {
  int count = 0;
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> map[i][j];
    }
  }
  dfs(0, 0);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cout << map[i][j];
    }
    cout << endl;
  }
  return 0;
}


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t n, k;
    cin >> n >> k;

    vector p(n, 0L);
    for (auto&& pp : p) {
        cin >> pp;
    }

    sort(p.begin(), p.end());
    p.resize(k);

    cout << accumulate(p.begin(), p.end(), 0L) << endl;
}

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

using namespace std;

typedef long long ll;
#define int ll
typedef long double ld;

typedef pair<int,int> pii;
#define x first
#define y second

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

    int a,b;
    cin>>a>>b;
    cout<<a*b;
}


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

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

#define INF INT_MAX/3
#define PB push_back
#define pb push_back
#define all(a) (a).begin(),(a),end()
#define pll pair<lli,lli>

int main(){
  lli H,W;

  while(1){
    cin>>H>>W;
    if(H==0 and W==0)break;

    rep(i,H){
      rep(j,W){
	if((i+j)%2==0)
	  cout<<"#";
	else
	  cout<<".";
      }
      cout<<endl;
    }
    cout<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3064
#include <stdio.h>
int main(void){
  int N, L[100], i, j, k, count = 0;
  scanf("%d",&N);
  for(i=0; i<N; i++){
    scanf("%d",&L[i]);
  }
  for(i=0; i<N; i++){
    for(j=i+1; j<N; j++){
      for(k=j+1; k<N; k++){
        if(L[i] + L[j] > L[k] && L[j] + L[k] > L[i] &&
           L[k] + L[i] > L[j] && L[i] != L[j] &&
           L[j] != L[k] && L[k] != L[i]){
          count++;
        }
      }
    }
  }
  printf("%d",count);
  return 0;
}

Measured memory_bytes: 1728
H, W, K = map(int, input().split())
MODN = int(1e9+7)

# A[i][j] i=Hまでで、j=Kにいける通り数（MOD）
A = [[0] * (W+2) for i in range(H+1)]

A[0][1] = 1

# N本の縦棒にひとつの高さで引ける組み合わせ数
def multip(N):
  tempa = [1,1,1,2,3,5,8,13,21,34,55]
  return(tempa[N+1])
  
for i in range(1,H+1):
  for j in range(1,W+2):
    if j < 1 or j > W:
      A[i][j] = 0
    else:
      A[i][j] = (A[i-1][j-1]*(multip(j-2) * multip(W-j)) + A[i-1][j]*(multip(j-1) * multip(W-j))+ A[i-1][j+1]*(multip(j-1) * multip(W-j-1))) % MODN
      
print(A[H][K])


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

constexpr int nax = 1e5;

int n, m;
int cnt[nax + 1];
bool red[nax + 1];

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

    cin >> n >> m;

    fill(begin(cnt), end(cnt), 1);
    red[1] = true;

    for (int i = 0; i < m; ++i)
    {
        int p, q; cin >> p >> q;
        if (red[p])
            red[q] = true;
        --cnt[p], ++cnt[q];
        if (not cnt[p])
            red[p] = false;
    }

    int cnt = 0;
    for (int i = 1; i <= n; ++i)
        cnt += red[i];

    cout << cnt << '\n';
}

Measured memory_bytes: 768
<?php
fscanf(STDIN, '%d', $n);
$cnt = [];
for ($i = 0; $i < 10; $i++) {
    $cnt[] = array_fill(0, 10, 0);
}

for ($i = 1; $i <= $n; $i++) {
    $keta_last = $i % 10;
    $keta_first = intval(substr(strval($i), 0, 1));
    $cnt[$keta_last][$keta_first]++;
}
$ans = 0;
for ($i = 1; $i <= 9; $i++) {
    for ($j = 1; $j <= 9; $j++) {
        $ans += ($cnt[$i][$j] ?? 0) * ($cnt[$j][$i] ?? 0);
    }
}
echo $ans . PHP_EOL;

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

inline int read()
{
	int ret=0; char c=getchar();
	while(c<48||c>57)c=getchar();
	while(c>=48 && c<=57)ret=ret*10+c-48,c=getchar();
	return ret;
}
int n,a[400077],m2,m;
int main()
{
	n=read();
	for(int i=1;i<=n;++i)
	{
		a[i]=read();
//		++ma[a[i]];
		if(a[i]>m)m2=m,m=a[i];
		else if(a[i]>m2)m2=a[i];
	}
	for(int i=1;i<=n;++i)if(m==a[i])printf("%d\n",m2);
	else printf("%d\n",m);
	
}

Measured memory_bytes: 2432
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#define MN 800
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
char st[MN+5][MN+5];
int n,m,K,d[MN+5][MN+5],top=0,vis[MN+5][MN+5];
pair<int,int> q[MN*MN+5];
const int dis[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
int main()
{
    n=read();m=read();K=read();
    for(int i=1;i<=n;++i) scanf("%s",st[i]+1);
    for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) if(st[i][j]=='S') q[++top]=make_pair(i,j),vis[i][j]=1;
    for(int i=1;i<=top;++i)
    {
        int x=q[i].first,y=q[i].second;
        for(int k=0;k<4;++k)
        {
            int nx=x+dis[k][0],ny=y+dis[k][1];
            if(nx<1||ny<1||nx>n||ny>m||vis[nx][ny]||st[nx][ny]=='#') continue;
            vis[nx][ny]=1;q[++top]=make_pair(nx,ny);d[nx][ny]=d[x][y]+1;
        }
    }
    int ans=1e9;
    for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) if(vis[i][j]) ans=min(ans,max(1,(d[i][j]+K-1)/K)+(min(min(i-1,n-i),min(j-1,m-j))+K-1)/K);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 10880
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int d = scan.nextInt();
		
		if(a != c) {
			System.out.println(1);
		}else {
			System.out.println(0);
		}
	}

}


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

#define ll long long
#define ul 100000
// #define ul 10
#define fo(i,a,b) for(int i=a;i<b;++i)
#define mod 1000000007
#define sff fflush(stdout)

int A[ul+5];
int B[ul+5];

bool comp(const pair<int,int> &a, const pair<int,int> &b)
{
    return (a.second < b.second);
}

int main()
{
	int n;
	cin>>n;
	ll SA=0,SB=0;
	fo(i,0,n) {cin>>A[i];SA+=A[i];}
	fo(i,0,n) {cin>>B[i];SB+=B[i];}
	ll num = SB-SA;
	if(num<0) cout<<"No\n";
	else
	{
		ll xa=0,xb=0;
		bool flag = false;
		fo(i,0,n)
		{
			if(A[i]<B[i]) xa+=(B[i]-A[i]+1)/2;
			else if(B[i]<A[i]) xb+= A[i]-B[i];
			if(xa>num||xb>num) flag=true;
		}
		if(flag)cout<<"No\n";
		else cout<<"Yes\n";
	}
}



Measured memory_bytes: 384
//bismillahir rahmanir rahim            //Author:Fayed Anik
 
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
 
/*
template <typename T>  using ordered_set =
    tree<T, null_type, less<T>,   /// greater<T> for sorting decreasingly
    rb_tree_tag, tree_order_statistics_node_update>;
*/

#define         ll                          long  long
#define         lf                          double
#define         pb(x)                       push_back(x)
#define         ull                         unsigned long long
#define         sfl(a)                      scanf("%lld",&a)
#define         sf(a)                       scanf("%d",&a)
#define         pf(a)                       printf("%d\n",a)
#define         pfl(a)                      printf("%lld\n",a)
#define         FOR(x,n)                    for(ll x=1;x<=n;++x)
#define         pii                         pair< ll , ll >
#define         mp(a,b)                     make_pair(a,b)
#define         mod                         1000000007
#define         INF                         2e18
#define         f1                          first
#define         f2                          second
#define         all(v)                      v.begin(),v.end()
#define         PI                          acos(-1)
#define         printminusone               printf("-1\n")
#define         bug                         printf("bug")
#define         FILEIN                      freopen("in.txt","r",stdin)
#define         FILEOUT                     freopen("out.txt","w",stdout)
 
//ll SET(ll mask,ll pos){ return mask = (mask | (1ll<<pos)); }
//ll RESET(ll mask,ll pos){ return mask = mask & ~(1ll<<pos); }
//bool CHECK(ll mask,ll pos) { return (bool) (mask & (1ll<<pos)); }
//priority_queue <ll, vector<ll>, greater<ll> > pq;

#define lim 100005

ll a[lim],dp[lim][2],n;

ll solve(ll pos,ll ck){
    if(pos==n){
        if(ck){
            return a[pos];
        }
        else{
            return a[pos]*(-1);
        }
    }
    ll &ret = dp[pos][ck];
    if(ret != -1) return ret;

    if(pos==1){
        ret = a[pos]+solve(pos+1,1);
        ret = max(ret,(-1)*a[pos]+solve(pos+1,0));
    }
    else{
        ll val;
        if(ck){
            val = a[pos];
        }
        else{
            val = a[pos]*(-1);
        }

        ret = val + solve(pos+1,1);
        ret = max(ret,(-1)*val+solve(pos+1,0));
    }
    return dp[pos][ck]=ret;
}
int main(){
    sfl(n);
    for(ll i=1;i<=n;i++){
        sfl(a[i]);
    }
    memset(dp,-1,sizeof dp);
    ll ans = solve(1,1);
    pfl(ans);
    return 0;
}

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

int main() {
  int n;
  cin>>n;
  string s,t;
  cin>>s;
  t=s;
  
  int a=0,b=0;
  rep(i,n){
    if(s[i]=='(') a++;
    else b++;
    if(b>a){
      t = '('+t;
      a = 0;
      b = 0;
    }
  }
  if(a>b) rep(i,a-b) t = t+')';
  cout << t;
}




Measured memory_bytes: 256
h, w = map(int, input().split())
l = list('.' + input() + '.' for _ in range(h))
l = ['.'*(w+2)] + l + ['.'*(w+2)]

for i in range(1, h+1):
    ans = ''
    for j in range(1, w+1):
        if l[i][j] == '#':
            ans += '#'
        else:
            _tmp = l[i-1][j-1:j+2] + l[i][j-1:j+2] + l[i+1][j-1:j+2]
            ans += str(_tmp.count('#'))
    print(ans)

Measured memory_bytes: 3064
# input here
_INPUT = """\
5
4 4 9 7 5
"""

def main():
    N = int(input())
    sido = list(map(int, input().split()))
    triangle = list(itertools.combinations(sido, 3))
    #print(triangle)

    # 三角形の成立条件
    j = 0
    for i in range(len(triangle)):
        if len(triangle[i]) != len(set(triangle[i])):
            continue

        if ((triangle[i][0] + triangle[i][1] > triangle[i][2])
           & (triangle[i][1] + triangle[i][2] > triangle[i][0])
           & (triangle[i][0] + triangle[i][2] > triangle[i][1])):
           j += 1
           #print(triangle[i])
    print(j)


if __name__ == '__main__':
    import io
    import sys
    import math
    import itertools

    # sys.stdin = io.StringIO(_INPUT)
    main()

Measured memory_bytes: 87756
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    a = input()
    if a.islower():
        print('a')
    else:
        print('A')
resolve()

Measured memory_bytes: 61880
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<cmath>
#include<string>

#define ls (t<<1)
#define rs ((t<<1)+1)
#define mid ((l+r)>>1)
#define fi first
#define se second
#define mk make_pair
#define pb push_back

#define N 100005
#define M 200005
#define seed 23333
#define Mo 998244353

using namespace std;
int i,j,m,n,p,k,a,b,c;
int main()
{
	 scanf("%d%d%d",&a,&b,&c); 
	 if(a%2==0||b%2==0||c%2==0) puts("0");
	 else cout<<min(1ll*a*b,min(1ll*a*c,1ll*b*c));
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    sort(p.begin(),p.end());
  
    int sum = 0;
    rep(i,k){
        sum += p[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;

    vector<P> p(n);
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        p[i] = make_pair(b, a);
    }
    sort(all(p));

    ll t = 0;
    rep(i, n) {
        t += p[i].second;
        if(t > p[i].first) {
            out("No");
            re0;
        }
    }
    
    out("Yes");
    re0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define fr first
#define se second
#define r_0 return 0;
#define ll long long
#define pb push_back
#define TIME ios_base::sync_with_stdio(0)
using namespace std;
vector<ll>V,L,Q;
vector<string>P;
map<int,int>M;
set<char>S;
set<char>:: iterator it;
ll n,m,a,b,c,d,e,f,cnt,x,y,z,t;
string   s,p,ans,temp;
ll   arr[10001];
bool xy=0;
char bd;
int main()
{
    TIME;
    cin>>n;
    for (int i =0; i <=n; i ++ )
        cin>>a,V.pb(a);
    for (int i =0; i <n; i ++ )
    {
        cin>>a;
        if (a>=V[i])
            a-=V[i],cnt+=V[i];
        else
            cnt+=a,a=0;
        if (a>=V[i+1])
            cnt+=V[i+1],V[i+1]=0;
        else
            cnt+=a,V[i+1]-=a;
    }
    cout<<cnt;

}


Measured memory_bytes: 1400
#include <cstdio>
#include <algorithm>
#include <cstdlib>

int main(void){
  long long a, x, max, min, i, sum;
  sum = 0;
  scanf("%lld", &a);
  scanf("%lld", &x);
  max=min=x;
  sum = x;
  for(i=0; i<a-1; i++){
    scanf("%lld", &x);
    if(max<x) max=x;
    if(min>x) min=x;
    sum+=x;
  }
  printf("%lld %lld %lld\n", min, max, sum);
  return 0;
}


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

typedef long long ll;

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

    int n, ans = 0;
    cin >> n;
    string s;
    cin >> s;
    for(int i = 0; i <= n-3; i++){
        if(s.substr(i, 3) == "ABC"){
            ans += 1;
        }
    }
    cout << ans << endl;
      
}

Measured memory_bytes: 256
l=list(map(int,raw_input().split()))
x=int(l[0])
k=int(l[1])
d=int(l[2])
s = 0
e = (k/2)

ans = int(1e32)

while s<=e :
    m = (s+e)/2
    curr = abs(x+(k-2*m)*d)
    ans = min(curr,ans)
    left = abs(x+(k-2*(m-1))*d)
    right = abs(x+(k-2*(m+1))*d)

    if(left < curr or right < curr):
        if(left<right):
            e=m-1
        else:
            s=m+1
    else:
        break 

s=0
e=(k/2)
ans2= int(1e32)
#negative
while s<=e :
    m = (s+e)/2
    curr = abs(x-(k-2*m)*d)
    ans2 = min(curr,ans2)
    left = abs(x-(k-2*(m-1))*d)
    right = abs(x-(k-2*(m+1))*d)

    if(left < curr or right < curr):
        if(left<right):
            e=m-1
        else: 
            s=m+1
    else:
        break 

ans = min(ans2,ans)

print(ans)


    


Measured memory_bytes: 64548
S = input().strip()
N = len(S)
T = input().strip()
k = len(T)
cmin = N
for i in range(N-k+1):
    cnt = 0
    for j in range(k):
        if S[i+j]!=T[j]:
            cnt += 1
    cmin = min(cmin,cnt)
print(cmin)

Measured memory_bytes: 72760
const line = require('fs').readFileSync('/dev/stdin', 'utf-8').split('\n');

const newNode = (id, left, right) => {

    const degree = left === -1 && right === -1 ? 0
                 : left === -1 || right === -1 ? 1
                 : 2;

    return {
        id : id,
        parent : -1,
        left : left,
        right : right,
        degree : degree,
        depth : null,
        height : 0,
        sibling : -1,
        type : ''
    };
};

const setDepth = tree => {
    const root = tree.filter(x => x.parent === -1)[0];
    const helper = (node, n) => {
        node.depth = n;
        if (node.left !== -1) helper(tree[node.left], n+1);
        if (node.right !== -1) helper(tree[node.right], n+1);
    };
    helper(root, 0);
};

const setType = node => {
    node.type = node.parent === -1 ? 'root'
              : node.left === -1 && node.right === -1 ? 'leaf'
              : 'internal node';
};

const setHeight = (tree, id, n) => {
    if (id === -1) return n-1;
    return Math.max(setHeight(tree, tree[id].left, n+1), setHeight(tree, tree[id].right, n+1));
};

const setSibling = (tree) => {
    tree.forEach(x => {
        if (x.left !== -1) tree[x.left].sibling = x.right;
        if (x.right !== -1) tree[x.right].sibling = x.left;
    });
};

const preorder = tree => {
    const root = tree.filter(x => x.type === 'root')[0];
    const helper = id => {
        if (id === -1) return [];
        return [id, ...helper(tree[id].left), ...helper(tree[id].right)];
    };

    return helper(root.id).join(' ');
};

const inorder = tree => {
    const root = tree.filter(x => x.type === 'root')[0];
    const helper = id => {
        if (id === -1) return [];
        return [...helper(tree[id].left), id, ...helper(tree[id].right)];
    };

    return helper(root.id).join(' ');
};

const postorder = tree => {
    const root = tree.filter(x => x.type === 'root')[0];
    const helper = id => {
        if (id === -1) return [];
        return [...helper(tree[id].left), ...helper(tree[id].right), id];
    };

    return helper(root.id).join(' ');
};

const nodeToString = node => {
    return `node ${node.id}: parent = ${node.parent}, sibling = ${node.sibling}, degree = ${node.degree}, depth = ${node.depth}, height = ${node.height}, ${node.type}`;
};

const n = parseInt(line[0]);
const data = line.slice(1, n+1)
                 .map(x => x.split(' ').map(Number));
const tree = data.map(xs => newNode(xs[0], xs[1], xs[2]));
tree.sort((a, b) => a.id - b.id);
tree.forEach(x => {
    if (x.left !== -1) tree[x.left].parent = x.id;
    if (x.right !== -1) tree[x.right].parent = x.id;
});
tree.forEach(x => setType(x));
setDepth(tree);
tree.forEach(x => {
    x.height = setHeight(tree, x.id, 0);
});
setSibling(tree, 0);

console.log(`Preorder\n ${preorder(tree)}`);
console.log(`Inorder\n ${inorder(tree)}`);
console.log(`Postorder\n ${postorder(tree)}`);



Measured memory_bytes: 16416
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w;;
    while(cin >> h >> w){
        if(h==0&&w==0){
            return 0;
        }
        vector<vector<int>> a(h,vector<int>(w));
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cin >> a[i][j];
            }
        }
        int ans=0;
        for(int i=1;i<h-1;i++){
            for(int j=1;j<w-1;j++){
                for(int k=i;k<h-1;k++){
                    for(int l=j;l<w-1;l++){
                        int t=10;
                        for(int x=i-1;x<=k+1;x++){
                            for(int y=j-1;y<=l+1;y++){
                                if(x>=i&&x<=k&&y>=j&&y<=l){
                                    continue;
                                }
                                chmin(t,a[x][y]);
                            }
                        }
                        bool f=true;
                        int sum=0;
                        for(int x=i;x<=k;x++){
                            for(int y=j;y<=l;y++){
                                if(a[x][y]>=t){
                                    f=false;
                                }
                                sum+=t-a[x][y];
                            }
                        }
                        if(f){
                            chmax(ans,sum);
                        }
                    }
                }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3120