akhauriyash/Code-Regression huggingface dataset:
N, A, B, C = map(int, input().split())
L = [int(input()) for _ in range(N)]


def f(a, b, c, i):
    if i == N:
        if min(a, b, c) == 0:
            return float('inf')
        return abs(A - a) + abs(B - b) + abs(C - c) - 30
    al = f(a + L[i], b, c, i + 1) + 10
    bl = f(a, b + L[i], c, i + 1) + 10
    cl = f(a, b, c + L[i], i + 1) + 10
    dl = f(a, b, c, i + 1)
    return min(al, bl, cl, dl)


def main():
    print(f(0, 0, 0, 0))


main()


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

int main() {
    multimap<int, int> mp;
    int n;
    cin >> n;
    vector<int> vec(n);
    rep(i, n) cin >> vec[i];
    sort(all(vec), greater<int>());
    ll cnt = 0;
    mp.insert(make_pair(vec[0], vec[0]));
    rep(i, n-1){
      	auto itr = mp.end();
        --itr;
        int a = (*itr).first;
        int b = (*itr).second;
        mp.erase(itr);
        mp.insert(make_pair(min(vec[i+1], a), max(vec[i+1], a)));
        mp.insert(make_pair(min(vec[i+1], b), max(vec[i+1], b)));
        cnt += a;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 13548
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
int N;
vector<int> G[200000];
int d[200000];
int res=0;
int M=0;
void dfs(int x){
    d[x]=res;
    M=max(M,res);
    res++;
    for(auto to: G[x]){
        if(d[to]<0) dfs(to);
    }
    res--;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N;
    rep(i,0,N-1){
        int a,b;
        cin>>a>>b;
        a--; b--;
        G[a].pb(b); G[b].pb(a);
    }
    rep(i,0,N) d[i]=-1;
    dfs(0);
    int pos=-1;
    rep(i,0,N){
        if(d[i]==M){
            pos=i;
            break;
        }
    }
    rep(i,0,N) d[i]=-1;
    res=0;
    dfs(pos);
    cout <<(M%3==1?"Second":"First")<<"\n";
}

Measured memory_bytes: 18176
from bisect import bisect_left
X = int(input())
A = [pow(i,5) for i in range(-1000,1001)]
B = A[:]
for i,a in enumerate(A):
    bi = bisect_left(B,a-X)
    if B[bi]==(a-X):
        print(i-1000,bi-1000)
        break

Measured memory_bytes: 9272
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		//		String line = reader.readLine();
		String[] str = reader.readLine().split(" ");
		int[] ab = new int[str.length];
		for (int i = 0; i < str.length; i++) {
			ab[i] = Integer.parseInt(str[i]);
		}
		int ans = ab[0] - ab[1] + 1;
		System.out.println(ans);
	}
}


Measured memory_bytes: 22484
/*author: hyperion_1724
  date: 
*/

//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

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

    READV(A);
    READV(B);
    cout<<A*B/__gcd(A,B)<<endl;


    return 0;
}

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

int main() {
    int n, k;
    scanf("%d %d", &n, &k);
    //long ans = 10000000000000000;
    double ans = 0;
    for (int i = 1; i <= n; i++) {
        long p = 1000000000000000 / n;
        for (int j = i; j < k; j *= 2) {
            p *= 0.5;
        }
        ans += p;
    }
    ans /= 1000000000000000;
    printf("%.10lf\n", ans);
    return 0;
}


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


int main(void){
        int N, P;
        cin >> N >> P;
        int a[2] = {0,0};
        rep(i,N) {
                int A;
                cin >> A;
                a[A%2]++;
        }

        ll ans;
        if (a[1] == 0) {
                if ( P == 0) ans = (ll)pow(2,N);
                else ans = 0;
        }
        else ans = (ll)pow(2,N-1);

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

Measured memory_bytes: 4076
void main() {
	auto ip = readAs!(string[]), A = ip[0].to!int, B = ip[2].to!int, op = ip[1];
	if(op == "+") {
		writeln(A + B);
	} else {
		writeln(A - B);
	}
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long       ll;
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define mt                make_tuple
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define fore(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define forr(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define deb(x)			  cerr << "# " << (#x) << " = " << (x) << endl;
#define sz(x)             (int)x.size()
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
const int INF = 1234567890;

ll dp[2010];
ll MOD = 1e9 + 7;

ll pref[2010];

ll f(int s) {
    if (s == 0) return 1;
    if (s < 0) return 0;
    ll &res = dp[s];
    if (res != -1) return res;
    res = 0;
    fore(i, 3, s+1) {
        res += f(s - i);
        res %= MOD;
    }
    return res;
}

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    int s;
    cin >> s;
    clr(dp, -1);
    cout << f(s) << '\n';
    return 0;
}
// Dinosaurs are cool!

Measured memory_bytes: 3680
#include <stdio.h>

int main(){
  
  int N,D,X,ans = 0;
  scanf("%d%d%d",&N,&D,&X);
  
  int i,A[N],day[N]; //day[N]:i番目の人間が何日間チョコを食べるか
  for(i = 0 ; i < N ; i++){
    scanf("%d",&A[i]);
  }
  
  for(i = 0 ; i < N ; i++){
    day[i] = (D - 1) / A[i] + 1;
  }
  
  int sum = 0;
  for(i = 0 ; i < N ; i++){
    sum += day[i];
  }
  
  ans = sum + X;
  printf("%d",ans);
  
  return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3
import math

a, b, x = list(map(int, input().split()))

if 2*x >= a*a*b:
    tan_theta = 2*(b*a*a-x)/(a*a*a)
else:
    tan_theta = a*b*b/(2*x)

print(math.atan(tan_theta)/math.pi*180)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#define debug(x) cout << #x " => " << (x) << endl
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int h, n;
  cin >> h >> n;
  vector<int> a(n);
  rep (i, n) cin >> a[i];
  cout << (accumulate(all(a), 0) >= h ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int main(){
    char str[1000];
    int n;
    char instruct[100];
    char str_re[1000];

    int a, b;
    int i;

    scanf("%s", str);
    scanf("%d", &n);
    //cin >> n;

    for(i = 0; i < n; i++){
        //printf("n is %d\n", n);
        scanf("%s", instruct);
        //printf("n is %d\n", n);
        //printf("instruct ok\n");
        //printf("n is %d\n", n);

        if(strcmp(instruct, "replace") == 0){
            //printf("n is %d\n", n);
            cin >> a >> b;
            //printf("n is %d\n", n);
            //printf("a b ok\n");
            scanf("%s", str_re);
            //printf("str_re ok %s\n", str_re);

            for(int j = a; j <= b; j++){
                str[j] = str_re[j - a];
            }
            //printf("replace %s\n", str);

        }

        else if(strcmp(instruct, "reverse") == 0){
            cin >> a >> b;
            reverse(&str[a], &str[b+1]);
            //printf("reverse %s\n", str);
        }

        else if(strcmp(instruct, "print") == 0){
            cin >> a >> b;

            for(int j = a; j <= b; j++){
                printf("%c", str[j]);
            }
            cout << endl;
        }
        //printf("n is %d\n", n);
        //printf("i : %d\n", i);
        //printf("n is %d\n", n);
    }
    return 0;

}


Measured memory_bytes: 3248
// 二分探索, SegmentTree
package main

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

type segmentTree struct {
	data   []int
	offset int
}

func newSegmentTree(n int) segmentTree {
	var result segmentTree
	t := 1
	for t < n {
		t *= 2
	}
	result.offset = t - 1
	result.data = make([]int, 2*t-1)
	return result
}

func (st segmentTree) updateAll(a []int) {
	for i, v := range a {
		st.data[st.offset+i] = v
	}
	for i := st.offset - 1; i > -1; i-- {
		st.data[i] = st.data[i*2+1] + st.data[i*2+2]
	}
}

func (st segmentTree) add(index, value int) {
	i := st.offset + index
	st.data[i] += value
	for i >= 1 {
		i = (i - 1) / 2
		st.data[i] = st.data[i*2+1] + st.data[i*2+2]
	}
}

func (st segmentTree) update(index, value int) {
	i := st.offset + index
	st.data[i] = value
	for i >= 1 {
		i = (i - 1) / 2
		st.data[i] = st.data[i*2+1] + st.data[i*2+2]
	}
}

func (st segmentTree) query(start, stop int) int {
	result := 0
	l := start + st.offset
	r := stop + st.offset
	for l < r {
		if l&1 == 0 {
			result += st.data[l]
		}
		if r&1 == 0 {
			result += st.data[r-1]
		}
		l = l / 2
		r = (r - 1) / 2
	}
	return result
}

type t struct {
	X int
	H int
}
type byX []t

func (a byX) Len() int           { return len(a) }
func (a byX) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a byX) Less(i, j int) bool { return a[i].X < a[j].X }

func main() {
	N := readInt()
	D := readInt()
	A := readInt()
	XH := make([]t, N)
	for i := 0; i < N; i++ {
		XH[i].X = readInt()
		XH[i].H = (readInt() + A - 1) / A
	}

	sort.Sort(byX(XH))
	result := 0
	st := newSegmentTree(N + 1)
	for i := 0; i < N; i++ {
		x, h := XH[i].X, XH[i].H
		h -= st.query(0, i+1)
		if h <= 0 {
			continue
		}
		result += h
		st.add(i, h)

		ok := i
		ng := N
		for ng-ok != 1 {
			m := ok + (ng-ok)/2
			if XH[m].X <= x+2*D {
				ok = m
			} else {
				ng = m
			}
		}
		st.add(ng, -h)
	}
	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 13076
from math import sqrt

n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]

count = 0

for i in range(n):
    for j in range(i+1, n):
        tmp = 0
        for k in range(d):
            tmp += (x[i][k] - x[j][k]) ** 2
        s = sqrt(tmp)
        if s - int(s) == 0:
            count += 1

print(count)

Measured memory_bytes: 38256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 2e5 + 5, M = 2 * N + 5;


int main(){
    IO;
    int n, m;
    cin >> n >> m;
    int l = m - n + 1;
    int r = m + n - 1;
    while(l <= r)cout << l++ << " "; cout << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * B - String Palindrome
 * 長さが奇数である文字列 S が以下の条件をすべて満たすとき、S は「強い回文」であるといいます。
 *  ・S は回文である。
 *  ・N を S の長さとするとき、S の 1 文字目から (N−1)/2 文字目まで(両端含む)からなる文字列は回文である。
 *  ・S の (N+3)/2 文字目から N 文字目まで(両端含む)からなる文字列は回文である。
 * S が強い回文かどうかを判定してください。
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // 文字列S
        String s = sc.next();

        String result = "No";
        StringBuilder sbs = new StringBuilder( s );
        // 回文であるか
        if( s.equals( sbs.reverse().toString() ) ) {
            String n = s.substring( 0, ( s.length() - 1 ) / 2 );
//            System.out.println( "n:" + n );
            StringBuilder sbn = new StringBuilder( n );
            // 前の文字が回文であるか
            if( n.equals( sbn.reverse().toString() ) ) {
                String nLast = s.substring( ( s.length() - 1 ) / 2 + 1 );
 //               System.out.println( "nLast:" + nLast );
                StringBuilder sbnLast = new StringBuilder( nLast );
                // 前の文字が回文であるか
                if( nLast.equals( sbnLast.reverse().toString() ) ) {
                    result = "Yes";
                }
            }
        }
        System.out.println( result );

        sc.close();
    }
}

Measured memory_bytes: 24020
#include<stdio.h>

int main(){
  int x,y,a=1,temp;
  scanf("%d%d",&x,&y);
  if(x<y){
    temp=x;
    x=y;
    y=temp;
  }
  while(a!=0){
    a=x%y;
    x=y;
    y=a;
  }
  printf("%d\n",x);
  return 0;
}



Measured memory_bytes: 2072
WV = $<.read.split.map(&:to_i).each_slice(2).to_a
N,W = WV.shift
WV.sort_by! {|w,v| w>W ? 1<<60 : (v<<30)+w}
I = [0]
tv=tw = 0
i = WV.each_with_index {|(w,v),i|
  break 0...i  if w > W
  I << I[-1]=[v,i]   if I[-1][0] < v
  tv+=v; tw+=w
}.size
I[-1] = [1<<60,i]
A = Array.new(tv+1, [tw, -1])
A[0] = [0,0]
l = tw > W ? 0 : tv
l.upto(tv-1) {|n|
  c,b = A[n]
  l = n if c <= W
  next  if c >= W
  0.upto(I.size-2) {|i|
    j = I[i+1][1]
    next  if b[j-1] > 0
    v,i = I[i]
    next  if A[v+n][0] <= c + WV[i][0]
    if j > i+9
      i = (i...j).bsearch {|x| b[x] == 0}
    else
      i += 1  while b[i] > 0
    end
    w = c + WV[i][0]
    x = b | b+(1<<i)
    A[v+n] = [w,x]  if A[v+n][0] > w
  }
}
p l

Measured memory_bytes: 9336
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace std;
int comp(const void *a, const void *b)
{
	if (*((float*)a) < 0 && *((float*)b) > 0){
		return -1;
	} else if (*((float*)a) > 0 && *((float*)b) < 0){
		return 1;
	}
	float ans = *((float*)b + 1) / *((float*)b) - *((float*)a + 1) / *((float*)a);
	if (ans > 0){
		return 1;
	} else if (ans == 0){
		return 0;
	} else{
		return -1;
	}
}

int main(){
	int n, w, cnt;
	float a[100000][2];
	double ans = 0, sum = 0;

	cin >> n >> w;
	for (int i = 0; i < n; i++){
		int b, c;
		cin >> b >> c;
		if (b >= 0 && c <= 0){
			i--;
			n--;
			continue;
		} else if (b <= 0 && c >= 0){
			sum += b;
			ans += c;
			i--;
			n--;
			continue;
		} else if (b <= 0 && c <= 0){
			sum += b;
			ans += c;
			b *= -1;
			c *= -1;
		}
		a[i][0] = (float)b;
		a[i][1] = (float)c;
	}
	qsort(a, n, sizeof(float) * 2, comp);
	for (cnt = 0; cnt < n; cnt++){
		sum += a[cnt][0];
		if (sum > w){
			sum -= a[cnt][0];
			break;
		}
	}
	for (int i = 0; i < cnt; i++){
		ans += a[i][1];
	}
	if (cnt < n){
		if ((w - sum) / a[cnt][0] > 1){
			ans += a[cnt][1];
		} else{
			double tmp = (w - sum) * a[cnt][1];
			tmp /= a[cnt][0];
			ans += tmp;
		}
	}
	printf("%.4f\n", ans);
	return 0;
}

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

using namespace std;

#define int long long

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    string s;
    cin >> s;
    if (s == "Sunny")
    {
        cout << "Cloudy" << endl;
    }
    if (s == "Cloudy")
    {
        cout << "Rainy" << endl;
    }
    if (s == "Rainy")
    {
        cout << "Sunny" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <sstream>

#define DEBUG 0
#define fi first
#define se second
#define pb push_back
#define fore(i,a,b) for (int i = (a), _b = (b); i < (_b); ++i)
#define fort(i,a,b) for (int i = (a), _b = (b); i <= (_b); ++i)
#define ford(i,a,b) for (int i = (a), _b = (b); i >= (_b); --i)

using namespace std;

typedef long long LL;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int INF = 1e9 + 3;
const int MOD = 1e9 + 7;

int main() {
    if (DEBUG) {
        freopen("CP.inp", "r", stdin);
        freopen("CP.out", "w", stdout);
    }
    ios_base::sync_with_stdio(false); cin.tie(0);
    int a; string s; cin >> a >> s;
    if (a >= 3200) {
        cout << s << '\n';
    } else {
        cout << "red\n";
    }
    return 0;
}



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

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

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

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

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

int main(){
  int A,B,M,a[100000],b[100000];
  cin>>A>>B>>M;
  int mina(1e9),minb(1e9);
  for (int i(0);i<A;i++) {
    cin>>a[i];
    mina = min(mina,a[i]);
  }
  for (int i(0);i<B;i++){
    cin>>b[i];
    minb = min(minb,b[i]);
  }
  int ans(1e9);
  for (int i(0);i<M;i++){
    int x,y,c;
    cin>>x>>y>>c;
    ans = min(ans,a[x-1] + b[y-1] - c);
  }
  cout << min(ans,mina+minb) << endl;
  return 0;
}



Measured memory_bytes: 1024
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N, X = get_ints

@ax = [1]
N.times do
  @ax.push(@ax.last * 2 + 3)
end

@px = [1]
N.times do
  @px.push(@px.last * 2 + 1)
end

def dfs(x, n)
  return x > 0 ? 1 : 0 if n == 0

  if x * 2 >= @ax[n]
    @px[n-1] + 1 + dfs(x - @ax[n]/2 - 1, n-1)
  else
    dfs(x-1, n-1)
  end
end

puts dfs(X, N)


Measured memory_bytes: 14440
from fractions import gcd
A, B, C, D = map(int, input().split())
lcm = int((C*D) / gcd(C, D))
print((B - (B//C + B//D - B//lcm)) -
      ((A-1) - ((A-1)//C + (A-1)//D - (A-1)//lcm)))

Measured memory_bytes: 64620
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <iomanip>
# define M_PIl        3.141592653589793238462643383279502884
using namespace std;

typedef long long ll;
typedef long double ld;



int main(){
  ll n;
  cin >> n;
  vector<ll> arr(n);
  vector<ll> count(n+1);
  for(ll i=0;i<n;i++){
    cin >> arr[i];
    count[arr[i]]++;
  }
  ll total=0;
  for(ll i=1;i<=n;i++){
    if(count[i]>=2){
      total+=((count[i])*(count[i]-1))/2;
    }
  }
  
  for(ll i=0;i<n;i++){
    ll ans=total;
    ans-=((count[arr[i]])*(count[arr[i]]-1))/2;
    if(count[arr[i]]-1>=2){
      ans+=((count[arr[i]]-1)*(count[arr[i]]-2))/2;
    }
    cout << ans << endl;
    
  }
}

Measured memory_bytes: 5760
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#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 INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;

 
int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    vector<int> a(n);
    int i;
    for(i=0; i<n; i++) {
        scanf("%d", &a[i]);
    }

    ll ans=LINF;
    for(i=-100; i<=100; i++) {
        ll sum=0;
        int k;
        for(k=0; k<n; k++) {
            sum+=(a[k]-i)*(a[k]-i);
        }
        ans=MIN(ans,sum);
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <utility>
using namespace std;
#define REP(I,N) for (I=0;I<N;I++)
#define rREP(I,N) for (I=N-1;I>=0;I--)
#define rep(I,S,N) for (I=S;I<N;I++)
#define rrep(I,S,N) for (I=N-1;I>=S;I--)
#define FOR(I,S,N) for (I=S;I<=N;I++)
#define rFOR(I,S,N) for (I=N;I>=S;I--)
#define upd(X,Y) X=(X+Y)%MOD
typedef unsigned long long ull;
typedef long long ll;
const int INF=0x3f3f3f3f;
const ll INFF=0x3f3f3f3f3f3f3f3fll;
const ll M=1e6+3;
const ll maxn=1e5+7;
const int MAX=2e5+7;
const ll MOD=1e9+7;
const double eps=0.00000001;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
inline ll powMM(ll a,ll b){
    ll ret=1;
    while (b){
        if (b&1) ret=ret*a%M;
        b>>=1;
        a=a*a%M;
    }
    return ret;
}
int n,m;
bool vi1[MAX],vi2[MAX];
int main()
{
    scanf("%d%d",&n,&m);
    int i,j;
    FOR(i,1,m)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        if(x==1)
            vi1[y]=true;
        if(y==n)
            vi2[x]=true;
    }
    FOR(i,1,n)
    {
        if(vi1[i]&&vi2[i])
            return 0*printf("POSSIBLE\n");
    }
    return 0*printf("IMPOSSIBLE\n");
}




Measured memory_bytes: 640
n = int(input())
t = list(str(input()))
if n%2 == 1:
    print("No")
else:
    ans = True
    a = ["" for i in range(int(n/2))]
    b = ["" for i in range(int(n/2))]
    for i in range(int(n/2)):
        a[i] = t[i]
        b[i] = t[int(n/2)+i]
    for i in range(int(n/2)):
        ans = ans and a[i] == b[i]
    if ans:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e6+1;
const int mod = 1e9+7;

int main() {
        int x;
        cin >> x;
        int a,b,coun=0;
        cin >> a >> b;
        for(int i = a; i<=b; i++){
            if(i%x==0){
            coun++;
            }
        }
        if(coun > 0){
            cout << "OK" << endl;
        }
        else
            cout << "NG";
	return 0;
}


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

int main() {
	int N, L;
	cin >> N >> L;
	vector<string> S(N);
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}

	sort(S.begin(), S.end());
	string answer;
	for (int i = 0; i < N; i++) {
		answer += S[i];
	}
	cout << answer << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define sz(x) (int)(x).size();
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
int h[10]={0,2,5,5,4,5,6,3,7,6};
int32_t main()
{
	int n=in();int m=in();
	vector<char> a(m);
	trav(i,a)cin>>i;
	vector<string> dp(n+10);
	//dp[i] best answer with i sticks
	//making only given digits from a(m)
	dp[0]="";
	for(int i=0;i<m;i++)
	{
		dp[h[a[i]-'0']]=max(dp[h[a[i]-'0']],(string)""+a[i]);
	}
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(dp[i]=="")continue;
			if((i+h[a[j]-'0'])>n)continue;
			if(dp[i+h[a[j]-'0']].size()>dp[i].size()+1)continue;
			if(dp[i+h[a[j]-'0']].size()<dp[i].size()+1)
			{
				dp[i+h[a[j]-'0']]=dp[i]+a[j];
			}
			else
			dp[i+h[a[j]-'0']]=max(dp[i]+a[j],dp[i+h[a[j]-'0']]);
			
		}
	}
	cout<<dp[n];
	
	
}

Measured memory_bytes: 61748
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int n = in.nextInt();
            int trueN = (n / 100 == 1 ? 900 : 100) + ((n % 100) / 10 == 1 ? 90 : 10) + (n % 10 == 1 ? 9 : 1);
            System.out.println(trueN);
        }
    }
}


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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,N,j) for(int i = (N-1);i >= (j);i--)
#define _rec(i,N,j) for(int i = (N);i >=(j);i--)
#define ALL(x) x.begin(),x.end()
#define MEM(a,n) memset(a,n,sizeof(a))
#define fst first
#define scd second
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

int get_int(){int x;scanf("%d",&x);return x;}
LL get_ll(){LL x;scanf("%lld",&x);return x;}
double get_db(){double x;scanf("%lf",&x);return x;}

template<typename T> int chmin(T &a,T &b){if(a > b){a = b;return 1;}else return 0;}
template<typename T> int chmax(T &a,T &b){if(a < b){a = b;return 1;}else return 0;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {_for(i,0,v.size()) os << v[i] << " ";return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){for(auto a:v) os << a <<" ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){os << v.fst <<" "<<v.scd << " ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& v){for(auto a:v) cout << a << endl;return os;}

static const int dx[8] = { 1,  0, -1,  0,  1, -1,  1, -1};
static const int dy[8] = { 0,  1,  0, -1,  1, -1, -1,  1};
const double pi  = acos(-1.0);
const double eps = 1e-8;
const LL  INF  = 0x3f3f3f3f3f3f3f3f;
const int inf  = 0x3f3f3f3f;


int get_input(){
    return 1;
}
void output(){;}

const int maxn = 300*300*2;
int h, w;
int nh, nw;

bool Input()
{
    cin >> h >> w;
    if(!h && !w) return false;
    else return true;
}

void solve()
{
    int M = maxn;
    int d = h*h +w*w;
   for(int i = 1; i <= 151; i++)
    for(int j = i+1; j <= 151; j++)
   {
       int d1 =  i*i + j*j;
       if((d1 > d || d1==d && i > h) && d1 < M) { M = d1; nh = i; nw = j; }
   }
}

int main()
{
    while(1)
    {
        if(!Input()) break;
        solve();
        cout << nh << " " << nw << endl;
    }
    return 0;
}



Measured memory_bytes: 3088
#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, a, b;
    cin >> n >> a >> b;

    if((b-a)%2 == 1) {
        out("Borys");
    }
    else {
        out("Alice");
    }
    
    re0;
}

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

using namespace std;

typedef long long ll;

struct lst
{
private:
    int n;
    vector<ll> node;
    vector<ll> lazy;
    vector<bool> lflg;

    void lazy2node(int k, int l, int r)
    {
        if(lflg[k])
        {
            node[k]=(r-l+1)*lazy[k];
            prop(lazy[k], k, l, r);
            lazy[k]=0;
            lflg[k]=false;
        }
    }

    void prop(ll v, int k, int l, int r)
    {
        if(r-l>0)
        {
            lazy[2*k+1]=lazy[2*k+2]=v;
            lflg[2*k+1]=lflg[2*k+2]=true;
        }
    }

public:
    lst(int sz)
    {
        n=1; while(n<sz) n*=2;
        node.resize(2*n-1, 0);
        lazy.resize(2*n-1, 0);
        lflg.resize(2*n-1, false);
    }
    void update(int qa, int qb, ll v, int k=0, int l=0, int r=-1)
    {
        if(r<0) r=n-1;
        lazy2node(k, l, r);
        if(qb<l || r<qa) return; 
        if(qa<=l && r<=qb)
        {
            node[k]=(r-l+1)*v;
            prop(v, k, l, r);
        }
        else
        {
            int m=(l+r)/2;
            update(qa, qb, v, 2*k+1, l, m);
            update(qa, qb, v, 2*k+2, m+1, r);
            node[k]=node[2*k+1]+node[2*k+2];
        }
    }

    ll get(int qa, int qb, int k=0, int l=0, int r=-1)
    {
        if(r<0) r=n-1;
        lazy2node(k, l, r);
        if(qb<l || r<qa) return 0;
        if(qa<=l && r<=qb) return node[k];
        else
        {
            int m=(l+r)/2;
            ll ls=get(qa, qb, 2*k+1, l, m);
            ll rs=get(qa, qb, 2*k+2, m+1, r);
            return ls+rs;
        }
    }
};

int main()
{
    int n, q;
    scanf("%d %d", &n, &q);
    lst tree=lst(n);
    for(int i=0; i<q; i++)
    {
        int c;
        scanf("%d", &c);
        if(c)
        {
            int s, t;
            scanf("%d %d", &s, &t);
            printf("%lld\n", tree.get(s,t));
        }
        else
        {
            int s, t, v;
            scanf("%d %d %d", &s, &t, &v);
            tree.update(s,t, (ll)v);
        }
    }
    return 0;
}


Measured memory_bytes: 7064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<double> VL;
typedef vector<string> VS;
typedef vector<PLL> VP;
typedef vector<ll> VLL;
const static int INF = 1000000000;
const static int MOD = 1000000007;
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; } //charを整数に
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i];

int main()
{
    int N, M;
    cin >> N >> M;
    int ans=1;
    rep(i,M){
        ans*=2;
    }
    cout << (1900*M+100*(N-M))*ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    string input, output;
    int count =0;
    cin >> input;
    for(int i=0; i<4; i++){
        if(input[i] == '+') count++;
        else count--;
    }
    cout << count << endl;
    return 0;
    
}	

Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner()
	N, A := sc.NextInt(), sc.NextInt()
	B := N % 500
	if B <= A {
		fmt.Printf("Yes")
	} else {
		fmt.Printf("No")
	}

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>

int main(){
  int H,W; cin>>H>>W;
  int N; cin>>N;
  int a[N+1];
  for(int i=1;i<=N;++i){
    cin >> a[i];
  }
  int board[H][W];
  
  int color = 1;
  REP(i,H){
    if(i%2==0){
      REP(j,W){
        board[i][j] = color;
        if(--a[color]==0){
          ++color;
        }
      }
    }else{
      REPR(j,W-1){
        board[i][j] = color;
        if(--a[color]==0){
          ++color;
        }
      }
    }
    
    REP(j,W){
      cout << board[i][j] << ((j<W-1)?" ":"\n");
    }
  }
  
  
}

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

typedef pair<int,int> pii;

int N,R,C;
vector<pii> V;
stack<int> S;
bool used[100010] = {0};

bool judge(int x,int y)
{
    if(x == 0 || x == R || y == 0 || y == C)return true;
    return false;
}

int main()
{
    scanf("%d%d%d",&R,&C,&N);
    for(int i = 0; i < N; i++)
    {
        int x1,x2,y1,y2;
        scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
        if(judge(x1,y1) && judge(x2,y2))
        {
            pii res;
            res.second = i;
            if(x1 == 0)res.first = y1;
            else if(y1 == C)res.first = C + x1;
            else if(x1 == R)res.first = 2 * C + R - y1;
            else res.first = 2 * C + 2 * R - x1;
            V.push_back(res);
            if(x2 == 0)res.first = y2;
            else if(y2 == C)res.first = C + x2;
            else if(x2 == R)res.first = 2 * C + R - y2;
            else res.first = 2 * C + 2 * R - x2;
            V.push_back(res);
        }
    }
    sort(V.begin(),V.end());
    for(int i = 0; i < V.size(); i++)
    {
        pii now = V[i];
        if(used[now.second])
        {
            if(S.top() == now.second)S.pop();
            else {printf("NO\n");return 0;}
        }
        else {S.push(now.second);used[now.second] = 1;}
    }
    printf("YES\n");
    return 0;
}


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

typedef long long int ll;
typedef long double ld;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define MOD (ll)(1e9 + 7)
#define vi vector<int>
#define vii vector<vector<int> >
#define vl vector<ll>
#define vll vector<vector<ll> >
#define vc(T, nm) vector<T> nm
#define pb push_back
#define popb pop_back
#define si set<int>
#define sl set<ll>
#define F first
#define S second
#define pii pair<int, int>
#define mp make_pair
#define ins insert
#define ers erase
#define endl "\n"
#define mul(a, b) ((a % MOD) * (b % MOD)) % MOD
#define adr(a, b) ((a % MOD) + (b % MOD)) % MOD
#define FORA(x, s, e, inc) for(ll x = s; x != e; x += inc)
#define ROFA(x, s, e, inc) for(ll x = s; x != e; x -= inc)
#define FOR(x, s, e) FORA(x, s, e, 1)
#define ROF(x, s, e) ROFA(x, s, e, 1)
#define loop(x, n) FOR(x, 0, n)
#define rd1(t, a) 					t a; cin >> a;
#define rd2(t, a, b) 				rd1(t, a); rd1(t, b); 
#define rd3(t, a, b, c) 			rd2(t, a, b); rd1(t, c);
#define rd4(t, a, b, c, d) 			rd3(t, a, b, c); rd1(t, d);
#define rd5(t, a, b, c, d, e) 		rd4(t, a, b, c, d); rd1(t, e);
#define rd6(t, a, b, c, d, e, f) 	rd5(t, a, b, c, d, e); rd1(t, f);
#define rdA(t, nm, len)				t nm[len]; loop(i, len) {cin >> nm[i];}
#ifdef DEBUG
	#define deb(v) cout << endl << #v << ": " << v << endl
	#define db1(v) cout << endl << #v << ": " << "[ "; for(auto x: v) {cout << x << " ";}; cout << "]" << endl;
	#define db2(v) cout << endl << #v << ": " << endl; for(auto r: v) {cout << "[ "; for(auto x: r) {cout << x << " ";}; cout << "]" << endl;};
	#define dbl cout << "-------------------------------" << endl
#else
	#define deb(v)
	#define db1(v)
	#define db2(v)
	#define dbl
#endif

void solve() {
	rd1(ll, k);
	rd1(string, s);
	
	if(k >= s.size()) {
	    cout << s;
	    return;
	}
	
	string ans = "";
	for(int i = 0; i < k; i++) {
	    ans += s[i];
	}
	ans += "...";
	
	cout << ans;
	
}

int main() {
	
	fastio;

// 	rd1(ll, t);
	ll t = 1;

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

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define Pi pair<int,int>
#define all(V) V.begin(),V.end()

int R;
set<int> ans,E;
stack<int> st;
vector<int> r(8);
vector<vector<pair<int, int>>> T(200);
vector<vector<int>> Cost(200, vector<int>(200, -1));

void sts() {
	auto sta = st;
	int a, b, c = 0;
	while (1) {
		a = sta.top();
		sta.pop();
		if (sta.empty()) break;
		b = sta.top();
		c += Cost[a][b];
	}
	ans.insert(c);
}

void Pa() {
	for (int i = 0;i < R;i++) {
		if (E.count(r[i])) continue;
		E.insert(r[i]);
		st.push(r[i]);
		Pa();
		if (st.size() == R) sts();
		st.pop();
		E.erase(r[i]);
	}
}

int main() {
	int N, M, a, b, c;
	cin >> N >> M >> R;
	for (int i = 0;i < R;i++) {
		cin >> a;
		r[i] = a - 1;
	}
	for (int i = 0;i < M;i++) {
		cin >> a >> b >> c;
		a--;b--;
		T[a].push_back({ c,b });
		T[b].push_back({ c,a });
	}
	priority_queue<Pi, vector<Pi>, greater<Pi>> Q;
	Pi p;
	for (int i = 0;i < N;i++) {
		Q.push({ 0,i });
		while (!Q.empty()) {
			a = Q.top().first;
			b = Q.top().second;
			Q.pop();
			if (Cost[i][b]<0 || Cost[i][b]>a) {
				Cost[i][b] = a;
				for (Pi k : T[b])
					Q.push({ a + k.first,k.second });
			}
		}
	}
	Pa();
	cout << *(ans.begin()) << endl;
}

Measured memory_bytes: 1532
#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int CASES = 3;

void solve() {
    ll A; string B;
    cin >> A >> B;
    ll tmp = (ll)(B[0] - '0')*100;
    tmp += (ll)(B[2] - '0')*10 + (ll)(B[3] - '0');
    ll t = A * tmp;
    ll ans = t/100;
    cout << ans << endl;
}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt", "input5.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
#else

    solve();

#endif
    return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}

const ll MOD = 998244353;

const int V = 1000001;
ll inv[V];

vector<int> primes;
bool isPrime[V];

void make_primes() {
  if (primes.size() > 0) return;
  memset(isPrime, true, sizeof(isPrime));
  isPrime[0] = isPrime[1] = false;
  for (int i = 2; i * i < V; i++)
    if (isPrime[i])
      for (int j = i * i; j < V; j += i)
        isPrime[j] = false;
  REP(i, V) if (isPrime[i]) primes.push_back(i);
}

/* 約数の列挙 */
vector<int> divisors(int n) {
  vector<int> ds;
  for(int d = 1; d * d <= n; d++) {
    if (n % d == 0) {
      ds.push_back(d);
      if (d * d != n) ds.push_back(n/d);
    }
  }
  sort(ds.begin(), ds.end());
  return ds;
}


const int MAX_N = 212345;
ll A[MAX_N];
ll w[V];
ll S[V];

int main2() {
  CLR(S, 0);

  int N = nextInt();
  REP(i, N) A[i] = nextInt();

  REP(i, N) {
    for (int d : divisors(A[i])) {
      S[d] += A[i];
      if (S[d] >= MOD) S[d] -= MOD;
    }
  }

  ll ans = 0;
  for (int d = 1; d <= V; d++) {
    ans += w[d] * S[d] % MOD * S[d] % MOD;
    ans %= MOD;
  }
  ll id = 0;
  REP(i, N) id += A[i];
  id %= MOD;
  ans -= id;
  ans = (ans % MOD + MOD) % MOD;
  ans = (ans * inv[2]) % MOD;
  cout << ans << endl;
  return 0;
}


int main() {
  inv[1] = 1;
  for (int i = 2; i < V; i++) inv[i] = inv[(int) (MOD % i)] * (MOD - MOD / i) % MOD;

  for (int i = 1; i <= V; i++) w[i] = inv[i];
  for (int i = 1; i <= V; i++) {
    for (int j = i * 2; j <= V; j += i) {
      w[j] -= w[i];
      if (w[j] < 0) w[j] += MOD;
    }
  }

  make_primes();

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 26744
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  int cnt = 0;
  cin >> S;
  //cout << S.length() << endl;
  for (int l=0, r=S.length()-1; l<r; l++, r--) {
    if (S[l] != S[r]) {
      S[l] = S[r];
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 140_D
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int K = sc.nextInt();
		sc.nextLine();
		String S = sc.nextLine();
		// Scannerクラスのインスタンスをクローズ
		sc.close();

		int i=0;

		int happy = 0;

		for(i=0; i<N-1; i++) {
			if(S.substring(i, i+1).equals(S.substring(i+1, i+2))){
				happy++;
			}
		}
		happy += 2*K;
		if(happy>=N) {
			happy = N-1;
		}

		System.out.println(happy);

	}
}


Measured memory_bytes: 49396
N, M = map(int, input().split())

H_list = list(map(int, input().split()))

road_list = []

for i in range(M):
    road = list(map(int, input().split()))
    road_list.append(road)

ans_list = [0 for i in range(N)]

for i in range(M):
    #print(i, road_list[i][0]-1)
    if H_list[road_list[i][0]-1] > H_list[road_list[i][1]-1]:
        ans_list[road_list[i][1]-1] = -1
    elif H_list[road_list[i][0]-1] < H_list[road_list[i][1]-1]:
        ans_list[road_list[i][0]-1] = -1
    elif H_list[road_list[i][0]-1] == H_list[road_list[i][1]-1]:
        ans_list[road_list[i][1]-1] = -1
        ans_list[road_list[i][0]-1] = -1
        
#print(ans_list)    
print(ans_list.count(0))

Measured memory_bytes: 32008