akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>

using namespace std;

using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

int main()
{
	int n;
	scanf("%d", &n);

	vector<int> arr(n + 1);

	for (int i = 1; i <= n; i++)
		scanf("%d", &arr[i]);

	vector<i64> sum(n + 1);

	for (int i = 1; i <= n; i++)
		sum[i] = sum[i - 1] + arr[i];

	int lc = 1;
	int rc = 3;

	i64 ans = sum[n];

	for (int cut = 2; cut <= n - 2; cut++)
	{
		//1 ~ cut / cut + 1 ~ n 양쪽으로 분할해서 생각
		// 각 양쪽 구간에서 최대한 min max 차이를 줄인다.
		i64 lsum = sum[cut];
		i64 rsum = sum[n] - lsum;

		while (lc < cut - 1)
		{
			i64 nowg = llabs(lsum - 2 * sum[lc]);
			i64 nextg = llabs(lsum - 2 * sum[lc + 1]);

			if (nowg <= nextg)
				break;

			lc++;
		}

		while (rc < n - 1)
		{
			i64 nows = sum[rc] - lsum;
			i64 nexts = sum[rc + 1] - lsum;

			i64 nowg = llabs(rsum - 2 * nows);
			i64 nextg = llabs(rsum - 2 * nexts);

			if (nowg <= nextg)
				break;

			rc++;
		}

		i64 p = sum[lc];
		i64 q = sum[cut] - p;
		i64 r = sum[rc] - sum[cut];
		i64 s = sum[n] - sum[rc];

		ans = min(ans, max({ p,q,r,s }) - min({ p,q,r,s }));
	}

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

	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::setprecision(15);}}fIO;
template<typename T> using V = std::vector<T>;
template<typename T> void fill(V<T>&v) { for(T&e:v) std::cin >> e; }
/*-*/

int main() {
	constexpr int N=1e6+1;
	V<int> factor(N,0);
	for(int i=2;i<N;i++) {
		if(factor[i]) continue;
		for(int j=1;j*i<N;j++) {
			factor[i*j]=i;
		}
	}

	int n;
	std::cin >> n;
	V<int> a(n);
	fill(a);
	if([&]()->int{
		V<int> pr(N,0);
		for(int e:a) {
			while(e>1) {
				int x=factor[e];
				if(pr[x]) {
					return 0;
				}
				pr[x]++;
				while(e%x==0) e/=x;
			}
		}
		return 1;
	}()) {
		print("pairwise coprime");
		return 0;
	}
	int g=0;
	for(int e:a) g=std::gcd(g,e);
	if(g==1) print("setwise coprime");
	else print("not coprime");
}


Measured memory_bytes: 15076
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する


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


    vector<int> v;
    for(int i = 111; i <= 999; i += 111){
        v.push_back(i);
    }

    int n;
    cin >> n;
    cout << *lower_bound(all(v),n) << endl;

    return 0;
}


Measured memory_bytes: 888
#define _USE_MATH_DEFINES
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<climits>
using namespace std;

const int dy[6] = {-1, -1, 0, 1, 1, 0};
const int dx[2][6] = { {-1, 0, 1, 0, -1, -1}, {0, 1, 1, 1, 0, -1} };

struct Data{
	int y, x;
	bool is_deven;
	Data(){}
	Data(int _y, int _x, bool _is_deven){
		y = _y; x = _x; is_deven = _is_deven;
	}
};

int main(){
	int N, M, S, T, X[10], Y[10], P, Q;
	while(cin >> M >> N, M || N){
		cin >> S;
		for(int i = 0; i < S; i++){
			cin >> X[i] >> Y[i];
			X[i]--; Y[i]--;
		}

		cin >> T;
		int ans = 0;
		for(int i = 0; i < T; i++){
			cin >> P >> Q;
			P--; Q--;

			queue<Data> q;
			Data q_front;
			bool used[100][100] = {};
			int deven_scope = 0;
			
			for(int j = 0; j < S; j++){
				q.push( Data(Y[j], X[j], false) );
			}
			q.push( Data(Q, P, true) );

			while( !q.empty() ){
				q_front = q.front(); q.pop();

				if(used[q_front.y][q_front.x]) continue;
				used[q_front.y][q_front.x] = true;

				if(q_front.is_deven) deven_scope++;
				
				for(int j = 0; j < 6; j++){
					int ny = q_front.y + dy[j];
					int nx = q_front.x + dx[q_front.y&1][j];
					
					if(ny < 0 || N <= ny || nx < 0 || M <= nx) continue;

					q.push( Data(ny, nx, q_front.is_deven) );
				}
			}
			ans = max(ans, deven_scope);
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1220
import sys
def bellmanford(G,s):
    n = len(G)
    dist = [float("inf") for i in range(n)]
    dist[s]=0
    for k in range(n):
        flag = False
        for u in range(n):
            for v in range(len(G[u])):
                if dist[G[u][v][0]]>dist[u]+G[u][v][1]:
                    dist[G[u][v][0]]=dist[u]+G[u][v][1]
                    flag = True
        if(not flag):break
    for k in dist:
        if(k==float("inf")):print("INF")
        else:print(k)
                    
                        
def main():
    T =[int(x) for x in sys.stdin.readline().strip().split()]
    V = T[0]
    E = T[1]
    s = T[2]
    G = [[] for i in range(V)]
    
    for i in range(E):
        line = [int(x) for x in sys.stdin.readline().strip().split()]
        G[line[0]].append((line[1],line[2]))
    bellmanford(G,s)
main()
    
        



Measured memory_bytes: 85892
#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 1145141919
#define ll long long
//#define scanf scanf_s
bool p[1000005];
int main()
{

	REP(i, 1000000) p[i] = true;
	p[0] = p[1] = false;
	for (int i = 2; i*i <= 1000000; i++)
	{
		if (p[i] == true)
		{
			for (int j = 2; j*i <= 1000000; j++)
			{
				p[i*j] = false;
			}
		}
	}
	int n;
	while (cin >> n)
	{
		int cnt = 0;
		REP(i, n + 1)
		{
			if (p[i] == true) cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 2136
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

const vector<string> p3 = {
    ".aa",
    "a..",
    "a.."
};
const vector<string> p4 = {
    "aacd",
    "bbcd",
    "dcbb",
    "dcaa"
};
//const vector<string> p5 = {
//    "aabaa",
//    "b.bcc",
//    "bac..",
//    ".ac.b",
//    "bbaab"
//};
const vector<string> p5 = {
    "aabba",
    "b.cca",
    "bc..b",
    "ac..b",
    "abbaa"
};
const vector<string> p7 = {
    "aabb..a",
    ".cc.cca",
    "a...abb",
    "a..ba..",
    ".aab.aa",
    "a..ab..",
    "a..ab.."
};
//const vector<string> p7 = {
//    ".aabbcc",
//    "a.dd.dd",
//    "ad..d..",
//    "bd..d..",
//    "b.dd.dd",
//    "cd..d..",
//    "cd..d.."
//};

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

    if (N == 2) {
        write(-1);
        return 0;
    }

    vector<string> ans(N);
    rep(i, N) ans[i] = string(N, '.');

    if (N == 3) ans = p3;
    else if (N == 4) ans = p4;
    else if (N == 5) ans = p5;
    else if (N == 6) {
        rep(i, 3) rep(j, 3) {
            ans[i][j] = ans[3 + i][3 + j] = p3[i][j];
        }
    }
    else if (N == 7) ans = p7;
    else {
        int k4 = (N - 8) / 4;
        rep(k, k4) {
            rep(i, 4) rep(j, 4) {
                ans[4 * k + i][4 * k + j] = p4[i][j];
            }
        }
        int M = 4 * k4;

        if (N - M == 8) {
            rep(i, 4) rep(j, 4) {
                ans[M + i][M + j] = p4[i][j];
            }
            M += 4;
            rep(i, 4) rep(j, 4) {
                ans[M + i][M + j] = p4[i][j];
            }
        }
        else if (N - M == 9) {
            rep(i, 9) rep(j, 9) {
                ans[M + i][M + j] = p3[i % 3][j % 3];
            }
        }
        else if (N - M == 10) {
            rep(i, 5) rep(j, 5) {
                ans[M + i][M + j] = p5[i][j];
            }
            M += 5;
            rep(i, 5) rep(j, 5) {
                ans[M + i][M + j] = p5[i][j];
            }
        }
        else if (N - M == 11) {
            rep(i, 4) rep(j, 4) {
                ans[M + i][M + j] = p4[i][j];
            }
            M += 4;
            rep(i, 7) rep(j, 7) {
                ans[M + i][M + j] = p7[i][j];
            }
        }
    }

    rep(i, N) write(ans[i]);
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define DEBUG(a) cerr<<#a<<"="<<a<<endl
#define DEBUG_ARRAY(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define DEBUG(a) 
#define DEBUG_ARRAY(a,n) 
#endif
#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> P;
typedef pair<ll,P> PP;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

const long long MOD = 998244353;
/*bool operator < (const vector<long long> &a,const vector<long long> &b){
    bool ret=false;
    DEBUG("called");
    for(long long i = 0; i < a.size(); i++){
        if(a[i]>b[i]){
            ret=false;
            break;
        }else if(a[i]<b[i]){
            ret=true;
            break;
        }
    }
    return ret;
}
*/
ll cache_pow[600];
ll mpow(ll a){
    static bool flag=false;
    if(flag){
        DEBUG("True");
        return cache_pow[a];
    }else{
        cache_pow[0]=1;
        for(long long i = 1; i < 600; i++){
            cache_pow[i]=(cache_pow[i-1]*2)%MOD;
        }
        flag=true;
        return cache_pow[a];
    }
}
void solve(long long N, long long M, std::vector<std::vector<long long>> a){
    ll index=0;

    vector<bitset<300>> A;
    for(long long i = 0; i < a.size(); i++){
        A.push_back(bitset<300>(0));
        for(long long k = 0; k < a[i].size(); k++){
            A[i][k]=(a[i][k]==1);
        }
    }
    ll rank=0;
    for(long long i = 0; i < N; i++){
        DEBUG(i);
        for(; index < M; index++){
            DEBUG(index);
            for(long long j = i; j < N; j++){
                if(A[j][index]==1){
                    if(j!=i)
                        swap(A[j],A[i]);
                    goto OUT;
                }
            }
        }
        OUT:
        if(index==M){
            break;
        }
        rank++;
        for(long long j = i+1; j < N; j++){
            if(A[j][index]==1){
                A[j]^=A[i];
            }
        }
    }
    DEBUG(rank);
    cout<<(mpow(M+N-1)-mpow(M+N-1-rank)+MOD)%MOD<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<std::vector<long long>> a(N, std::vector<long long>(M));
    for(int i = 0 ; i < N ; i++){
        for(int j = 0 ; j < M ; j++){
            scanf("%lld",&a[i][j]);
        }
    }
    solve(N, M, std::move(a));
    return 0;
}


Measured memory_bytes: 1024
import math


def gcd(x, y):
    while y:
        x, y = y, x % y
    return x


def lcm(x, y):
    return x * y // gcd(x, y)


a, b, c, d = map(int, input().split())
ALL = b - a +1
G = lcm(c, d)
num = math.floor(b // c) - math.floor((a-1) // c) + math.floor(b // d) - math.floor((a-1) // d) - (math.floor(b // G) - math.floor((a-1) // G))
print(ALL - num)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9+7;
const int maxn = (int)-1;

#define IO(x) freopen(x".in", "r", stdin); freopen(x".out", "w", stdout);

const db eps = 1e-6;
bool eq(const db &a, db const &b) { return fabs(a - b) < eps; }
bool ls(const db &a, db const &b) { return a + eps < b; }
bool le(const db &a, db const &b) { return eq(a, b) || ls(a, b); }

vi son[55];
bool vis[55][55];
bool v[55];

int main ()
{
    int n, m;
    scanf("%d%d", &n, &m);
    memset(vis, false, sizeof(vis));
    rep(i, 1, n + 1) son[i].clear();
    rep(i, 0, m) {
        int u, v;
        scanf("%d%d", &u, &v);
        son[u].pb(v);
        son[v].pb(u);
        if (u > v) swap(u, v);
        vis[u][v] = true;
    }
    int ans = 0;
    rep(i, 1, n) {
        rep(j, i + 1, n + 1) {
            if (!vis[i][j]) continue;
            queue <int> Q;
            Q.push(i);//de(i);
            int cnt = 0;
            memset(v, false, sizeof(v));
            while (!Q.empty()) {
                int t = Q.front(); Q.pop();
                if (v[t]) continue;
                v[t] = true;
                cnt++;
                rep(k, 0, sz(son[t])) {
                    int temp = son[t][k];
                    if (t == i && temp == j) continue;
                    if (!v[temp])
                        Q.push(temp);
                }
            }
            if (cnt != n) ans++;
        }
    }
    printf("%d\n", ans);
    return 0;
}


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

int main() {
	long long a, b, c, n, m, x, y;
	cin >> n;
	b = 0;
	for(int i = 0; i < n; i++){
		cin >> a;
		while(a % 2 == 0 && a != 0){
			a = a / 2;
			b++;
		}
	}
	cout << b << endl;
	return 0;
	
}

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

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1;i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

#define LL long long int
#define LD long double

#define PI 3.14159265358979

#define _CRT_SECURE_NO_WARNINGS

using namespace std;

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

LL func(LL x, LL y) {
	if (x == 0) return -y;
	else return (y / x)*x * 2 + func(y%x, x);
}

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

	LL N, X; cin >> N >> X;
	printf("%lld\n", func(X, N - X) + N);
	return 0;
}

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

int main() {
    string r, a;
    while (cin >> r >> a, r != "0") {
        int hit = 0, blow = 0;
        for (int i=0; i<4; ++i) {
            for (int j=0; j<4; ++j) {
                if (r[i] == a[j]) {
                    if (i == j) ++ hit;
                    else ++ blow;
                }
            }
        }
        cout << hit << " " << blow << endl;
    }
    return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
#include<cstring>
using namespace std;
int main()
{
 string s;
 cin>>s;
 if(s[0]==s[1]&& s[1]==s[2])
    cout<<"No"<<endl;
 else
    cout<<"Yes"<<endl;
   return 0;
}


Measured memory_bytes: 3600
#include<stdio.h>
int main()
{
long long int n,i,ans,d,def;
  ans=0;
  scanf("%lld %lld",&n,&d);
  def=d*d;
 long long int x[n],y[n];
  unsigned long long int dd[i];
  for(i=0;i<n;++i)
  {scanf("%lld %lld",&x[i],&y[i]);
   dd[i]=x[i]*x[i]+y[i]*y[i];
   
   if(dd[i] <= def) ans++;
  }
   printf("%d",ans);
   
return 0;
}

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

using namespace std;

void print(string A[], int size){
    cout << A[0];
    if(size > 1)for(int i = 1; i < size; i++)cout << " " << A[i];
    cout << endl;
}

int main(void){
    int N; cin >> N;
    string cards[N];
    string bubbleCards[N];
    for(int i = 0; i < N; i++){
      cin >> cards[i];
      bubbleCards[i] = cards[i];
    }
    bool frag = true;
    while(frag){
        frag = false;
        for(int i = 1; i < N; i++){
            if(bubbleCards[i-1][1] > bubbleCards[i][1]){
                string temp = bubbleCards[i];
                bubbleCards[i] = bubbleCards[i-1];
                bubbleCards[i-1] = temp;
                frag = true;
            }
        }
    }
    print(bubbleCards, N);
    cout << "Stable" << endl;
    for(int i = 0; i < N; i++){
        int minj = i;
        for(int j = i; j < N; j++){
            if(cards[minj][1] > cards[j][1]){
                minj = j;
            }
        }
        string temp = cards[minj];
        cards[minj] = cards[i];
        cards[i] = temp;
    }
    print(cards, N);
    bool isStable = true;
    for(int i = 0; i < N; i++){
        if(cards[i] != bubbleCards[i]){
            isStable = false;
            break;
        }
    }
    string ans = isStable? "Stable" : "Not stable";
    cout << ans << endl;
    return 0;
}


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

int main() {
  ll x,y;cin>>x>>y;
  ll ans=0;
  while(x<=y){
    x*=2;
    ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3644
k = int(input())
if k < 10:
	print(k)
else:
	dp = [[0 for _ in range(10)] for _ in range(30)] #確認
	for i in range(10):
		dp[1][i] = 1
	for i in range(2, 30):
		for j in range(10):
			if j == 0:
				dp[i][j] = dp[i-1][j] + dp[i-1][j+1]
			elif j == 9:
				dp[i][j] = dp[i-1][j] + dp[i-1][j-1]
			else:
				dp[i][j] = dp[i-1][j] + dp[i-1][j+1] + dp[i-1][j-1]

	#print(dp)
	cnt = 0
	for i in range(1, 30):
		for j in range(1, 10):
			cnt += dp[i][j]
			#print(cnt)
			if cnt >= k:
				keta = i
				num = j
				break
		else:
			continue
		break

	left = k - cnt + dp[keta][num]


	ans = [num]
	while keta != 1:
		if num == 0:
			li = [0, 1]
		elif num == 9:
			li = [-1, 0]
		else:
			li = [-1, 0, 1]
		for i in li:
			#print(li, i)
			if left > dp[keta-1][num+i]:
				left -= dp[keta-1][num+i]
			else:
				num += i
				ans.append(num)
				keta -= 1
				break
	ansl = []
	for i in range(len(ans)):
		ansl.append(str(ans[i]))
	anss = ''.join(ansl)
	print(anss)


Measured memory_bytes: 38320
#include<stdio.h>
    
    int main(){
    	int n,k,i,j,tmp;
		int result = 0;
    	scanf("%d%d",&n,&k);
        int l[n];

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


	 	for (i = 0; i < n; ++i) {
    		for (j = i+1; j < n; ++j) {
      			if (l[i] > l[j]) {
        			tmp =  l[i];
        			l[i] = l[j];
        			l[j] = tmp;
      			}
    		}
 		}

		for(i = n-1 ; i > n-k-1; --i){

			result = result + l[i];

		}

		printf("%d",result);

		return 0;

	}

Measured memory_bytes: 128
main :: IO ()
main = do
    [r,g,b,n] <- map read . words <$> getLine :: IO [Int]
    print . sum
        $ [ 1
          | i <- [0..(n`div`r)]
          , j <- [0..((n-r*i)`div`g)]
          , let k = n-r*i-g*j in k `rem` b == 0
          ]

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


Measured memory_bytes: 2056
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let (n, a, b) = get!(usize, usize, usize);
    let x = get!([usize]);
    let mut sum = 0;
    for i in 0..(n-1) {
        sum += if a*(x[i+1]-x[i]) < b {
            a*(x[i+1]-x[i])
        } else {
            b
        };
    }
    println!("{}", sum);
}


Measured memory_bytes: 10620
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()

def main():
  N, K = map(int, input().split())

  ary = set([i+1 for i in range(N)])
  mem = set([])
  for i in range(K):
    sumN = int(input())
    for i in list(map(int, input().split())):
      mem.add(i)

  print(len(ary - mem))

if __name__ == '__main__':
  main()

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

typedef long long ll;

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    map<string, int> m;
    map<string, int>:: iterator itr;

    
    int n = 0;
    cin >> n;

    string temp;
    int mx = -1;
    for(int i = 0; i < n; i++) {
        cin >> temp; 
        itr = m.find(temp);

        if(itr != m.end()) {
            itr -> second++;
            mx = max(mx, itr -> second);
        }
        else {
            m[temp] = 1;
            mx = max(mx, 1);
        }
    }   

    vector<string> ans;
    for(itr = m.begin(); itr != m.end(); itr++) {
        if(itr -> second == mx) {
            ans.push_back(itr -> first);
        }
    }

    sort(ans.begin(), ans.end());

    for(int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 25584
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

long long n;

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

Measured memory_bytes: 256
def equalfind(A):#配列中の等しい要素の組をカウント　オーダーはO(NlogN)
    A.sort()
    s=1
    count=0
    if len(A)==1:
        return count
    else:
        for i in range(0,len(A)-1):
            if A[i]==A[i+1]:
                s+=1
            else:
                count+=s*(s-1)//2
                s=1
        return count+s*(s-1)//2

S=input()
N=len(S)
mod=2019
data=[(int(S[-i-1])*pow(10,i,mod)) for i in range(0,N)]

for i in range(1,N):
    data[i]+=data[i-1]
    data[i]%=mod

data=[0]+data
data.sort()
print(equalfind(data))


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

int main(){
    int n;
    cin >> n;
    vector<int> w(n);
    for(int i = 0; i < n; i++)  cin >> w[i];
    int r = accumulate(w.begin(), w.end(), 0)-w[0];
    int l = w[0];
    int ans = abs(r-l);
    for(int i = 1; i < n-1; i++){
        l += w[i];
        r -= w[i];
        ans = min(ans, abs(r-l));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << x << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int main(){
    int n,C;
    cin >> n >> C;
    int d[30][30];
    rep(i,C)rep(j,C)cin >> d[i][j];
    int c[500][500];
    rep(i,n)rep(j,n){
        cin >> c[i][j];
        c[i][j]--;
    }
    int a[3][30];
    rep(i,n){
        rep(j,n){
            rep(k,C){
                if(c[i][j]!=k){
                    a[(i+j)%3][k]+=d[c[i][j]][k];
                }
            }
        }
    }
    int ans = INT_MAX;
    rep(i,C){
        rep(j,C){
            rep(k,C){
                if(i==j or j == k or k == i)continue;
                ans = min(ans,a[0][i]+a[1][j]+a[2][k]);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1280
from collections import deque

def bfs(i):
    global ans
    q = deque()
    c = [0] * n
    d = [0] * n
    c[i] = 1
    d[i] = 0
    q.append(i)
    while q:
        p = q.popleft()
        if p != 0:
            if c[p - 1] == 0:
                q.append(p - 1)
                d[p - 1] += d[p] + 1
                c[p - 1] = 1
                ans[d[p - 1]] += 1
        if p != n - 1:
            if c[p + 1] == 0:
                q.append(p + 1)
                d[p + 1] += d[p] + 1
                c[p + 1] = 1
                ans[d[p + 1]] += 1
        if p == x:
            if c[y] == 0:
                q.append(y)
                d[y] = d[x] + 1
                c[y] = 1
                ans[d[y]] += 1
        if p == y:
            if c[x] == 0:
                q.append(x)
                d[x] = d[y] + 1
                c[x] = 1
                ans[d[x]] += 1
    #print(ans)
    #print(d)


n, x, y = map(int, input().split())
x -= 1
y -= 1
ans = [0] * n
for i in range(n):
    bfs(i)

for i in range(1, n):
    print(ans[i] // 2)

Measured memory_bytes: 50012
n,h=map(int,input().split())
l=list(map(int,input().split()))
c=[10**9]*n
c[0]=0
c[1]=abs(l[0]-l[1])
for i in range(2,n):
    c[i]=min( c[j]+abs(l[i]-l[j]) for j in range(max(0,i-h),i) )
print(c[-1])


Measured memory_bytes: 53216
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
#define met(a,b) memset(a,b,sizeof(a))

int a[100005];
int even[100005],odd[100005];

bool cmp(int a,int b)
{
    return a>b;
}

int main()
{
    int n,x=0,y=0,Maxe=-1,Maxo=-1,ei=-1,oi=-1;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(i&1){
            even[a[i]]++;
            if(Maxe<even[a[i]]){
                Maxe=max(Maxe,even[a[i]]);
                ei=i;
            }
        }
        else{
            odd[a[i]]++;
            if(Maxo<odd[a[i]]){
                Maxo=max(Maxo,odd[a[i]]);
                oi=i;
            }
        }
    }
    if(a[oi]!=a[ei]) printf("%d\n",n-odd[a[oi]]-even[a[ei]]);
    else{
        sort(odd,odd+100001,cmp);
        sort(even,even+100001,cmp);
        printf("%d\n",min(n-odd[0]-even[1],n-odd[1]-even[0]));
    }
    return 0;
}

Measured memory_bytes: 1408
n=int(input())
a=[[int(s)for s in input().split()]for _ in range(n)]
def f():
 for i in range(n-1):
  d=a[i][:];d[3],d[4]=d[4],d[3]
  for j in range(i+1,n):
   e=a[j][:];e[3],e[4]=e[4],e[3]
   for p in([0,1,2,3,4,5],[1,5,2,0,4,3],[2,1,5,3,0,4],[3,0,2,5,4,1],[4,1,0,3,5,2],[5,1,4,3,2,0]):
    f=[d[k]for k in p]
    if f[0]==e[0]and f[5]==e[5]:
     f=f[1:5]*2
     for k in range(4):
      if f[k:k+4]==e[1:5]:return'No'
 return'Yes'
print(f())


Measured memory_bytes: 5616
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define all(i) i.begin(),i.end()
#define fix(i) fixed<<setprecision((i))
#define Max( i , j ) (i)=max((i),(j))
#define Min( i , j ) (i)=min((i),(j))
#define pii pair<int,int>
using namespace std;

const long long maxn = 1e5+100;
const long long INF = 3e18+1191;
const long long mod = 1e9+7;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

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

  int H, W;
  cin >> H >> W;

  char sheet[H][W];
  int visited[H][W];
  int count_black = 0;
  for(int i = 0;i<H;i++) {
    for(int j = 0;j<W;j++) {
      cin >> sheet[i][j];
      if (sheet[i][j] == '#') count_black++;
      visited[i][j] = -1;
    }
  }
  visited[0][0] = 0;

  queue<pair<int, int>> Q;
  Q.push(make_pair(0, 0));
  while (!Q.empty()) {
    pair<int, int> cur = Q.front();
    Q.pop();
    for(int i = 0;i<=3;i++)
      {
      int ny = cur.first + dy[i], nx = cur.second + dx[i];
      if (0 <= ny && ny < H && 0 <= nx && nx < W &&
	  sheet[ny][nx] == '.' && visited[ny][nx] == -1) {
	Q.push(make_pair(ny, nx));
	visited[ny][nx] = visited[cur.first][cur.second] + 1;
      }
    }
  }

  if (visited[H - 1][W - 1] != -1) {
    cout << H * W - visited[H - 1][W - 1] - count_black - 1 << endl;
  } else {
    cout << -1 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
pupils = []

while True:
    l = list(map(int, input().split()))
    if sum(l) == -3:
        break
    pupils.append(l)

for pupil in pupils:
    score = pupil[0] + pupil[1]
    if pupil[0] == -1 or  pupil[1] == -1:
        rank = 'F'
    elif score >= 80:
        rank = 'A'
    elif score >= 65:
        rank = 'B'
    elif (score >= 50) or (score >= 30 and pupil[2] >= 50):
        rank = 'C'
    elif score >= 30:
        rank = 'D'
    else:
        rank = 'F'
    print(rank)

Measured memory_bytes: 7520
s=list(input())
out=[]
for i in range(len(s)):
  if s[i]=="1":
    out.append(s[i])
  if s[i]=="0":
    out.append(s[i])
  if len(out)!=0 and s[i]=="B":
    del(out[-1])
print("".join(out))

Measured memory_bytes: 3060
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
string f(ll n)
{
	if(n==0)
	{
		return " ";
	}
	n--;
	return f(n/26) + string(1,'a'+n%26);
}


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

Measured memory_bytes: 3620
# C - Green Bin

from collections import Counter

N = int(input())
S = [str(input()) for _ in range(N)]
for i in range(N):
    S[i] = ''.join(sorted([s for s in S[i]]))
counter = Counter(S)
ans = 0
for i in counter.values():
    tmp = 0
    for j in range(1, i):
        tmp += j
    ans += tmp

print(ans)


Measured memory_bytes: 19824
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static boolean solve() {
		int l = in.nextInt();
		if (l == 0) return false;

		int x = 0;
		boolean f = false;

		for (int i=0; i<12; i++) {
			int m = in.nextInt();
			int n = in.nextInt();
			x += (m - n);
			if (!f && x >= l) {
				out.println((i+1));
				f = true;
			}
		}

		if (!f) {
			out.println("NA");
		}

		return true;
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		while(solve());
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    vector<int32> a(n), b(n), c(n-1);
    REP(i,n)cin >> a[i];
    REP(i,n)cin >> b[i];
    REP(i,n-1)cin >> c[i];
    int64 ans = 0;
    REP(i,n){
        ans += b[a[i]-1];
        if(i > 0 && a[i] == a[i-1] + 1){
            ans += c[a[i-1]-1];
        }
    }
    ANS(ans);
    return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	es := make([][]Edge, n)
	for i := 0; i < n; i++ {
		es[i] = make([]Edge, 0)
	}

	for i := 0; i < n-1; i++ {
		a := nextInt() - 1
		b := nextInt() - 1
		c := nextInt()
		es[a] = append(es[a], Edge{b, c})
		es[b] = append(es[b], Edge{a, c})
	}

	q := nextInt()
	k := nextInt() - 1

	ds := make([]int, n)
	for i := 0; i < n; i++ {
		ds[i] = -1
	}
	ds[k] = 0
	que := make([]int, 0)
	que = append(que, k)

	for len(que) > 0 {
		v := que[0]
		que = que[1:]
		for _, e := range es[v] {
			if ds[e.to] != -1 {
				continue
			}
			ds[e.to] = ds[v] + e.cost
			que = append(que, e.to)
		}
	}

	for i := 0; i < q; i++ {
		x := nextInt() - 1
		y := nextInt() - 1
		fmt.Println(ds[x] + ds[y])
	}
}

// Edge .
type Edge struct {
	to, cost int
}

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 15488
#include <iostream>
#include <cmath>
#include <queue>

using namespace std;

typedef struct Point {
    double x;
    double y;
} Point;

Point rotate(Point a, Point b, double deg)
{
    double rad = M_PI * deg / 180;
    double x = (b.x - a.x) * cos(rad) - (b.y - a.y) * sin(rad) + a.x;
    double y = (b.x - a.x) * sin(rad) + (b.y - a.y) * cos(rad) + a.y;

    return Point{x, y};
}

Point internally_dividing_point(Point a, Point b, double m, double n)
{
    double x = (n * a.x + m * b.x) / (m + n);
    double y = (n * a.y + m * b.y) / (m + n);
    return Point{x, y};
}

queue<Point> koch_curve(int n)
{
    queue<Point> new_curve;
    new_curve.push(Point{0.0,0.0});

    if (n == 0) {
        new_curve.push(Point{100.0,0.0});
        return new_curve;
    } else {
        auto curve = koch_curve(n-1);
        auto length = curve.size();

        for (size_t i = 0; i < length - 1; i++) {
            auto a = curve.front();
            curve.pop();
            auto b = curve.front();

            auto s = internally_dividing_point(a, b, 1, 2);
            auto t = internally_dividing_point(a, b, 2, 1);
            auto u = rotate(s, t, 60);

            new_curve.push(s);
            new_curve.push(u);
            new_curve.push(t);
            new_curve.push(b);
        }

        return new_curve;
    }
}

void print_curve(queue<Point> curve)
{
    for (auto a = curve.front(); !curve.empty() ; curve.pop(), a = curve.front())
        cout << a.x << " " << a.y << endl;
}

int main(void)
{
    int n;
    cin >> n;
    print_curve(koch_curve(n));
    return 0;
}

Measured memory_bytes: 1356
/// referenced: https://beta.atcoder.jp/contests/abc108/submissions/3147976
#include<bits/stdc++.h>
#define int int64_t
using namespace std;
int N,K,ans;
main(){
  cin>>N>>K;
  int n_zero=N/K;
  if(K%2){
    ans=n_zero*n_zero*n_zero;
  }else{
    for(int i=1;i<=N;++i){
      if(i%K==0){
        ans+=n_zero*n_zero;
      }else if(i%K==K/2){
        if(N%K>=K/2){
          ans+=(n_zero+1)*(n_zero+1);
        }else{
          ans+=n_zero*n_zero;
        }
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string s;
	cin >> s;


	if (s=="SUN") {

		cout << 7 << "\n";

	}
	else if (s=="MON") {
		cout << 6 << "\n";
	}
	else if (s=="TUE") {
		cout << 5 << "\n";
	}
	else if (s=="WED") {
		cout << 4 << "\n";
	}
	else if (s=="THU") {
		cout << 3 << "\n";
	}
	else if (s=="FRI") {
		cout << 2 << "\n";
	}
	else if (s=="SAT") {
		cout << 1 << "\n";
	}
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int Apple, Pieces;
	scanf("%d %d", &Apple, &Pieces);
	
	int ApplePie = 0;
	Apple *= 3;
	Pieces += Apple;
	for(int i = 0; Pieces > 1; i++){
		Pieces -= 2;
		ApplePie++;
	}
	
	printf("%d", ApplePie);
	
	return 0;
}

Measured memory_bytes: 1704
#include<stdio.h>
#include<string.h>
#define MAX 1000
int max(int x,int y){
  if(x>=y) return x;
  else return y;
}
int lcs(char *X,char *Y){
  int c[MAX+1][MAX+1];
  int x,y,i,j;
  x=strlen(X);
  y=strlen(Y);
  int maxl=0;

  for(i=0;i<=x;i++) c[i][0]=0;
  for(j=1;j<=y;j++) c[0][j]=0;

  for(i=1;i<=x;i++){
    for(j=1;j<=y;j++){
      if(X[i-1]==Y[j-1]) c[i][j]=c[i-1][j-1]+1;
      else c[i][j]=max(c[i-1][j],c[i][j-1]);
      maxl=max(maxl,c[i][j]);
    }
  }
  return maxl;
}
int main(){
  int n,i;
  char X[MAX],Y[MAX];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",X);
    scanf("%s",Y);
    printf("%d\n",lcs(X,Y));
  }
}



Measured memory_bytes: 5640
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

LL R,C,N;
inline bool is_edge(LL X,LL Y){
	if( (0==X) || (R==X) || (0==Y) || (C==Y) ){
		return true;
	}
	return false;
}
void solve(){
	
	cin >> R >> C >> N;
	vector< vector<LL> > Top,Right,Down,Left;
	vector< vector<LL> > pos(2,vector<LL>(2));
	for(int i=0;i<N;++i){
		for(int j=0;j<2;++j){
			cin >> pos[j][0] >> pos[j][1];
		}

		if( is_edge(pos[0][0],pos[0][1]) &&
			is_edge(pos[1][0],pos[1][1]) ){
			for(int j=0;j<2;++j){
				vector<LL> temp(3);
				temp[0] = pos[j][0];
				temp[1] = pos[j][1];
				temp[2] = i;
				if( temp[0] == 0 ){
					Left.push_back( temp );
				}else if( temp[0] == R ){
					Right.push_back( temp );
				}else if( temp[1] == 0 ){
					Down.push_back( temp );
				}else if( temp[1] == C ){
					Top.push_back( temp );
				}
			}
		}
	}
	sort(Down.begin(), Down.end() );
	sort( Right.begin(), Right.end() );
	sort( Top.begin(), Top.end() );
	sort( Left.begin(), Left.end() );
	stack<LL> visit;
	int size = Down.size();
	for(int i=0;i<size;++i){//Down[i]
		int v = Down[i][2];
		if( !visit.empty() && v == visit.top() ){
			visit.pop();//取り出す。
		}else{
			visit.push( v );
		}
	}
	size = Right.size();
	for(int i=0;i<size;++i){
		//Right[i]
		int v = Right[i][2];
		if( !visit.empty() && v == visit.top()){
			visit.pop();
		}else{
			visit.push( v );
		}
	}

	size = Top.size();
	for(int i=size-1;i>=0;--i){//Top
		int v = Top[i][2];
		if( !visit.empty() && v == visit.top()){
			visit.pop();
		}else{
			visit.push( v );
		}
	}

	size = Left.size();
	for(int i=size-1;i>=0;--i){
		int v = Left[i][2];
		if( !visit.empty() && v == visit.top() ){
			visit.pop();
		}else{
			visit.push( v );
		}
	}
	
	if( visit.size() ){
		cout << "NO" << endl;
	}else{
		cout << "YES" << endl;
	}
}
#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	
	
	solve();
}
#pragma endregion //main()


Measured memory_bytes: 13796
from fractions import gcd
def lcm(list):
    if len(list) == 1:
        return list[0]
    if len(list) == 2:
        [a, b] = list
        return a*b//gcd(a,b)
    x = list.pop()
    y = lcm(list)
    return x*y//gcd(x,y)

N = int(input())
li = []
for i in range(N):
    li.append(int(input()))
print(lcm(li))

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

int main() {
  double a, b, h, m, ans2, s;
  cin >> a >> b >> h >> m;
  s = (60*h-11*m)*M_PI/360;
  ans2 = a*a + b*b -2.0*a*b*cos(s);
  cout << fixed << setprecision(10) << sqrt(ans2) << endl;
  


  return 0;
}

Measured memory_bytes: 4252
// coding on smartphone
#include<iostream>
using namespace std;

int main(){
	int a, b;
	while(cin >> a >> b){
		int deg[101] = {};
		deg[a]++, deg[b]++;
		while(cin >> a >> b, a+b) deg[a]++, deg[b]++;
		bool judge = deg[1]%2 == 1 && deg[2]%2 == 1;
		for(int i = 3; i < 51; i++) if(deg[i]%2) judge = false;
		if(judge) cout << "OK" << endl;
		else         cout << "NG" << endl;
	}
	return 0;
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define chmin(x,y) if(x>y)x=y
#define chmax(x,y) if(x<y)x=y
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
ll inf=100100100100;
const int mod=1000000007;
int main(){
   ll n;cin>>n;
   ll ans=0;
   vi a(n),b(n),c(n);
   rep(i,n)cin>>a[i];
   rep(i,n)cin>>b[i];
   rep(i,n)cin>>c[i];
   sort(all(a));
   sort(all(b));
   sort(all(c));
   rep(i,n){
       ll k=lb(a,b[i]);
       ll j=n-lb(c,b[i]+1);
       ans+=j*k;
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 2560
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <queue>
#include <math.h>
#include <iterator>
using namespace std;
int main() {
	while (true) {
		int n;
		scanf("%d", &n);
		if (n == 0) goto end;
		for (int fu = 0;fu < n;++fu) {
			int x[2] = {}, y[2] = {}, z[2] = {}, w[2] = {};
			int ki = 0,kj = 0,ji = 0, kazu = 0, i = 0, j = 0, k = 0, i2 = 0, ij = 0, ik = 0, j2 = 0, jk = 0, k2 = 0;
				for (int q = 0;q < 2;++q) {
				scanf("%d%d%d%d", &x[q], &y[q], &z[q], &w[q]);
			}
				kazu = x[0] * x[1];
				i = (x[0] * y[1]);
				j = (x[0] * z[1]);
				k = (x[0] * w[1]);
				i += (y[0] * x[1]);
				i2 += (y[0] * y[1]);
				ij += (y[0] * z[1]);
				ik += (y[0] * w[1]);
				j += (z[0] * x[1]);
				ji += (z[0] * y[1]);
				j2 += (z[0] * z[1]);
				jk += (z[0] * w[1]);
				k += (w[0] * x[1]);
				ki += (w[0] * y[1]);
				kj += (w[0] * z[1]);
				k2 += (w[0] * w[1]);
				kazu -= (i2+j2+k2);
				k += ij;
				j -= ik;
				k -= ji;
				i += jk;
				j += ki;
				i -= kj;
				printf("%d %d %d %d\n", kazu, i, j, k);
		}
	}
end:;
}


Measured memory_bytes: 1032
#include "bits/stdc++.h"
#include "math.h"
#include "string.h"
#include "algorithm"
 
using namespace std;
typedef int64_t ll;
typedef vector<int64_t> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())
const int INF=INT_MAX;
int main(){
  int n,m;
  cin>>n>>m;
  vll a(n,INF);
  int ans1=0,ans2=0;
  REP(i,m){
    int p;
    cin>>p;
    p--;
    string s;
    cin>>s;
    if(s=="AC"){
      if(a[p]!=INF){
        ans2+=a[p];
      }
      a[p]=0;
    }
    else{
      if(a[p]==INF){
        a[p]=1;
      }
      else{
        if(a[p]==0){
          continue;
        }
        else{
          a[p]++;
        }
      }
    }
  }
  REP(i,n){
    if(a[i]==0){
      ans1++;
    }
  }
  cout<<ans1<<" "<<ans2<<endl;
}


Measured memory_bytes: 1024
N,M = map(int,input().split())
H = list(map(int,input().split()))
AB = []
good = [1] * N

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

for i in range(M):
  A = AB[i][0] - 1
  B = AB[i][1] - 1
  if H[A] > H[B]:
    good[B] = 0
  elif H[A] < H[B]:
    good[A] = 0
  else:
    good[A] = 0
    good[B] = 0
  
good = [i for i in good if i == 1]
  
ans = len(good)
print(ans)

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

int n, l, r, ans;

int main(void) {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256