akhauriyash/Code-Regression huggingface dataset:
//A B C D H F E I G K L M N P S O Q R J U Z Y X T V W
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define int unsigned long long int 
#define pb push_back
#define mp make_pair
#define pq priority_queue<int> 
#define pqs priority_queue<int,vector<int>, greater<int>>
#define setbits(x) __builtin_popcountll(x)  // no of ones in setbit
#define zrobits(x) __builtin_ctzll(x)       //101000 here 3..no of 0 aftrer 1sr right one 
#define mod 1000000007
#define inf 1e18
#define ps(x,y)  fixed<<setprecision(y)<<x  // ans upto 5 decimal place 
#define mk(ar,n,type) type *arr=new type[n];
#define w(x) int x;cin>>x;while(x--)
//int arr[100001][4] ; 
int dp[110][100011]; 
 



int Top_down(int weight [], int n, int cap, int price[])
{
	if(n==0 || cap==0)
	{
		return 0 ;
	}

	if(dp[n][cap] !=-1)
	{
		return dp[n][cap] ; 
	}

	// take it 
	int inc=0 ;
	int exc= 0 ; 
	if(weight[n-1]<=cap)
	 inc=price[n-1]+Top_down(weight, n-1, cap-weight[n-1], price); 
	
	// exclude
		exc=Top_down(weight , n-1, cap, price); 

	return  dp[n][cap]=  max(inc, exc);   

}

 

 
int32_t main()
{
	int n,w ; 
	cin>>n>>w ; 
	 
 	// vector<pair<int, int>> v;
 	int weight[n+1];
 	int price[n+1] ; 

 	for(int i=0 ; i<n; i++)
 	{
 		int x, y; 
 		cin>>x>>y; 
 		// v.push_back(make_pair(x,y));
 		weight[i]=x; 
 		price[i]= y;  
 	}
 	// for(int )

 	for(int i=0 ; i<110; i++)
 	{
 		for(int j=0 ; j<100011; j++)
 		{
 			dp[i][j]=-1 ; 
 		}
 		
 	}

 	cout<<Top_down(weight, n, w, price);   
	
 
}

Measured memory_bytes: 86272
#include <stdio.h>

long long int lucas(int n)
{
    long long int a = 2, b = 1, c, i;

    if (n == 0)
        return a;

    for (i = 2; i <= n; i++) {
        c = a + b;
        a = b;
        b = c;
    }

    return b;
}

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

    printf("%lld\n", lucas(n));
    return 0;
}

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

const int inf = 1e9;
const ll linf = 1e18;

int main()
{
    int n, a; cin >> n >> a;
    cout << ((n%500 <= a) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

const int N = 1e6 + 9;
const int MOD = 1e9 + 7;

int add(int a, int b) {
	return (a + b) % MOD;
}

int sub(int a, int b) {
	return (a - b + MOD) % MOD;
}

int mul(int a, int b) {
	return (a * b) % MOD;
}

int binpow(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1) res = mul(res, a);
		a = mul(a, a);
		b >>= 1;
	}
	return res;
}

int divv(int a, int b) {
	return mul(a, binpow(b, MOD - 2));
}

int f[N];

void init() {
	f[0] = 1;
	for (int i = 1; i < N; i++) {
		f[i] = mul(i, f[i - 1]);
	}
}

int C(int n, int k) {
	if (n < k) return 0;
	if (0 > k) return 0;
	return divv(f[n], mul(f[k], f[n - k])); 
}

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

	init();

	int n;
	cin >> n;
	n++;
	vector<int> pr(n, -1);
	int len = -1;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		x--;
		if (pr[x] != -1) {
			len = (i - pr[x] + 1);
		}
		pr[x] = i;
	}
	for (int i = 1; i <= n; i++) {
		int all = C(n, i);
		all = sub(all, C(n - len, i - 1));
		cout << all << '\n';
	}
}

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

using namespace std;

int gcd(int a, int b, int c) {
	return __gcd(__gcd(a, b), c);
}

int main () {

	ios::sync_with_stdio(0);
	cin.tie(0);

	int k, sum = 0;
	cin >> k;
	for (int i = 1; i <= k; i++) {
		for (int j = 1; j <= k; j++) {
			for (int l = 1; l <= k; l++) {
				sum += gcd(i, j, l);
			}
		}
	}
	cout << sum;
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const ll ber = 1e18;

//桁数計算
int check(unsigned long long ans){
    unsigned digit=0;
    while(ans!=0){
        ans /= 10;
        digit++;
    }
    return digit;
}

int main() {
  bool judge = false;
  int N;
  cin >> N;
  unsigned long long A[N];
  ll ans = 1;
  for(int i = 0; i < N; i++){
    cin >> A[i];
    if(A[i] == 0){//0の時点で終わり
      cout << 0 << endl;
      return 0;
    }
  }
  
  for(int j = 0; j < N; j++){
    //オーバーフロー対策
    if(check(ans) + check(A[j]) > 20 || ber/ans < A[j]){
      judge = true;
      break;
    }
    ans *= A[j];
  }
  if(judge || ans > ber){
      cout << "-1" << endl;
    }else{
  	  cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 4416
import java.util.*

class Scanner(`in`: java.io.InputStream) {
    private val reader = java.io.BufferedReader(java.io.InputStreamReader(`in`))
    private var tokenizer: StringTokenizer? = null

    fun next(): String {
        if (tokenizer?.hasMoreTokens() != true) {
            tokenizer = StringTokenizer(reader.readLine())
        }
        return tokenizer!!.nextToken()
    }

    fun nextLine(): String {
        return if (tokenizer?.hasMoreTokens() != true) {
            reader.readLine()
        } else tokenizer!!.nextToken("\n")
    }
}

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

////////////////////////////////////////////////////////////////////////

fun dprint(v: Any?, indent: Int = 0) {
    val indentStr = (1..indent).joinToString("") { " " }
    when (v) {
        is Iterable<*> -> {
            System.err.println("$indentStr[")
            v.forEach { dprint(it, indent + 1) }
            System.err.println("$indentStr]")
        }
        is Array<*> -> {
            System.err.println("$indentStr[")
            v.forEach { dprint(it, indent + 1) }
            System.err.println("$indentStr]")
        }
        is IntArray -> System.err.println(indentStr + "[" + v.joinToString(",") + "]")
        is LongArray -> System.err.println(indentStr + "[" + v.joinToString(",") + "]")
        is DoubleArray -> System.err.println(indentStr + "[" + v.joinToString(",") + "]")
        else -> System.err.println(indentStr + v)
    }
}

fun <A : Comparable<A>> min(a: A, b: A) = if (a < b) a else b
fun <A : Comparable<A>> min(vararg a: A) = a.reduce { acc, x -> min(acc, x) }
fun <A : Comparable<A>> max(a: A, b: A) = if (a > b) a else b
fun <A : Comparable<A>> max(vararg a: A) = a.reduce { acc, x -> max(acc, x) }

////////////////////////////////////////////////////////////////////////

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val S = Array(N) { sc.next() }
        val S1 = mutableListOf<Pair<Long, Long>>()
        val S2 = mutableListOf<Pair<Long, Long>>()
        S.forEach { s ->
            var min = 0L
            var sum = 0L
            s.forEach { c ->
                if (c == '(') sum++ else sum--
                if (min > sum) min = sum
            }
            when {
                sum >= 0 -> S1.add(Pair(sum, min))
                else -> S2.add(Pair(-sum, min - sum))
            }
        }
        S1.sortBy { -it.second }
        S2.sortBy { -it.second }
        val check1 = check(S1)
        val check2 = check(S2)
        if (check1 >= 0 && check2 >= 0 && check1 == check2) {
            pw.println("Yes")
        } else {
            pw.println("No")
        }
    }

    private fun check(a: List<Pair<Long, Long>>): Long {
        var n = 0L
        a.forEach {
            val sum = it.first
            val min = it.second
            if (n + min < 0) {
                return -1
            }
            n += sum
        }
        return n
    }
}


Measured memory_bytes: 143764
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cassert>
#include <cinttypes>

#define fi first
#define se second

using namespace std;

typedef int64_t ll;
typedef uint64_t ull;

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

typedef pair<int, int> P;
inline P operator+(const P& p1, const P& p2) {
  return P(p1.first + p2.first, p1.second + p2.second);
}

int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  int a = ty - sy;
  int b = tx - sx;

  for (int i = 0; i < a; i++) {
    cout << 'U';
  }
  for (int i = 0; i < b; i++) {
    cout << 'R';
  }
  for (int i = 0; i < a; i++) {
    cout << 'D';
  }
  for (int i = 0; i < b; i++) {
    cout << 'L';
  }

  cout << 'L';
  for (int i = 0; i < a + 1; i++) {
    cout << 'U';
  }
  for (int i = 0; i < b + 1; i++) {
    cout << 'R';
  }
  cout << 'D';

  cout << 'R';
  for (int i = 0; i < a + 1; i++) {
    cout << 'D';
  }
  for (int i = 0; i < b + 1; i++) {
    cout << 'L';
  }
  cout << 'U';

  cout << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;


int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    ll x,a,b; cin>>x>>a>>b;
    if(b<=a) cout << "delicious";
    else if(b<=a+x) cout << "safe";
    else cout << "dangerous";
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef pair<char, int> P;
 
int idx, N;
 
int solve(vector<P> &v)
{
    char c = v[idx].first, d = v[idx].second;
     
    idx++;
    if (isdigit(c)) {
        return c - '0';
    } else {
        int res = (c == '*');
        while (idx < N && d < v[idx].second) {
            if (c == '*') {
                res *= solve(v);
            } else {
                res += solve(v);
            }
        }
        return res;
    }
}
 
int main()
{
    while (cin >> N, N) {
        vector<P> v(N);
        string s;
        for (int i = 0; i < N; i++) {
            cin >> s;
            v[i] = P(s.back(), s.size()-1);
        }
        idx = 0;
        cout << solve(v) << endl;
    }
    return 0;
}

Measured memory_bytes: 3140
import os
import sys

import numpy as np


def solve(inp):
    def bit_add(arr, n, i, x):
        while i <= n:
            arr[i] += x
            i += i & -i

    def bit_sum(arr, i):
        result = 0
        while i > 0:
            result += arr[i]
            i ^= i & -i
        return result

    n = inp[0]
    q = inp[1]
    ccc = inp[2:2 + n] - 1
    lll = inp[2 + n::2] - 1
    rrr = inp[3 + n::2] - 1

    bit = np.zeros(n + 2, dtype=np.int64)
    appeared = np.full(n, -1, dtype=np.int64)
    ans = np.zeros(q, dtype=np.int64)

    p = 0
    for i in np.argsort(rrr):
        while p <= rrr[i]:
            c = ccc[p]
            before_appeared = appeared[c]
            if before_appeared != -1:
                bit_add(bit, n + 2, before_appeared + 2, -1)
            bit_add(bit, n + 2, p + 2, 1)
            appeared[c] = p
            p += 1

        ans[i] = bit_sum(bit, rrr[i] + 2) - bit_sum(bit, lll[i] + 1)

    return ans


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC

    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()
    exit()

if os.name == 'posix':
    # noinspection PyUnresolvedReferences
    from my_module import solve
else:
    from numba import njit

    solve = njit('(i8[:],)', cache=True)(solve)
    print('compiled', file=sys.stderr)

inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
ans = solve(inp)
print('\n'.join(map(str, ans)))


Measured memory_bytes: 97716
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
  int N,K;
  int kind = 0;
  int n[200000] = {};

  cin >> N >> K;
  for(int i = 0; i < N; i++){
    int tmp;
    cin >> tmp;
    if(n[tmp-1] == 0) kind++;
    n[tmp-1]++;
  }
  //  cout << "kind: " << kind << endl;
  sort(n, &n[200000]);
 
  int replace = 0; // replace times
  for(int i = 0; i < 200000; i++){
    //    cout << "n[" << i << "]: " << n[i] << endl;
    if(n[i] != 0){
      //      cout << "check1" << endl;
      replace += n[i];
      kind--;
    }
    //    cout << "check2" << endl;
    if(kind <= K) break;
  }

  cout << replace << "\n";

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll W, H, x, y;
  cin >> W >> H >> x >> y;
  double s = (double) W * H / 2.0;
  if (W % 2 == 1 || H % 2 == 1) {
    printf("%f %d", s, 0);
    return 0;
  }
  if ((H / 2 == x && W / 2 == y) || (H / 2 == y && W / 2 == x)) {
    printf("%f %d", s, 1);
  } else {
     printf("%f %d", s, 0);
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#define ll long long int
#define lim 100010
#define INF 1e9
#define mod 1000000007
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define ABS(x) ((x)>0?(x):-(x))

typedef struct{
	int i,p;
	char s[11];
}data;

int comp(const void *a, const void *b){
	if(strcmp(((data*)a)->s,((data*)b)->s)==0){
		if(((data*)a)->p >((data*)b)->p){
			return -1;
		}else return 1;
	}
	if(strcmp(((data*)a)->s,((data*)b)->s) <0){
		return -1;
	}
	return 1;
	
}


int main(void){
	int n;
	scanf("%d",&n);
	data mise[n];
	for(int i=0;i<n;i++){
		scanf("%s",&mise[i].s);
		scanf("%d",&mise[i].p);
		mise[i].i=i+1;
	}
	qsort(mise,n,sizeof(data),comp);
	for(int i=0;i<n;i++){
		printf("%d\n",mise[i].i);
	}
	
	
	return 0;
}

Measured memory_bytes: 128
bit = [0 for _ in range(252525)]

def get(r):
    r += 1

    res = 0
    while r > 0:
        res += bit[r]
        r -= r & -r
    
    return res

def update(k, x):
    k += 1

    while k < 252525:
        bit[k] += x
        k += k & -k
    
    return

n, k = map(int, input().split())

a = [int(input()) for _ in range(n)]

v = [0]

for i in range(n):
    v.append(v[i] + a[i])

for i in range(n + 1):
    v[i] -= i * k

st = sorted(list(set(v)))
mp = {t:i for i, t in enumerate(st)}

ans = 0

for i in range(n + 1):
    ans += get(mp[v[i]])
    update(mp[v[i]], 1)

print(ans)

Measured memory_bytes: 53272
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static Scanner in = new Scanner(System.in);
    public static void main(String[] args) {
        int N = in.nextInt();
        int[] c = new int[9];
        Arrays.fill(c, 0);
        for(int i = 0; i < N;c[Math.min(in.nextInt() / 400, 8)]++, i++);
        int sum = (int)Arrays.stream(Arrays.copyOf(c, 8)).filter(a -> a > 0).count();
        System.out.println((sum == 0 ? 1 : sum) + " " + (sum + c[8]));
    }
}

Measured memory_bytes: 28372
#include <bits/stdc++.h>
#include <iterator>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <math.h>
#define vi vector<int>
#define vvi vector<vector<int> > 
#define vl vector<long long>
#define vpi vector<pair<int,int> >
#define ll long long 
#define all(x) x.begin(),x.end()
#define vpl vector<pair<long long,long long> > 
#define F first
#define S second
#define mp make_pair
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pci pair<char,int>
#define un unsigned
# define M_PI           3.14159265358979323846  /* pi */
// #define mod 998244353
#define mod 1000000007
#define MAXN  1000001
using namespace std; 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)


void solve()
{
    string a,b;
    cin>>a>>b;
    for(int i = 0 ; i < a.length() ; i++)
    {
        if(a[i] != b[i])
        {
            cout<<"No"<<endl;
            return;
        }
    }
    cout<<"Yes"<<endl;
}


int main()
{
    fast;
    int t;
    t = 1;
    while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 3624
import sys

n, m = map(int, sys.stdin.readline().split())
s = [set(map(int, sys.stdin.readline().split()[1:])) for _ in range(m)]
*p, = map(int, sys.stdin.readline().split())

def main():
    combs = 0
    for i in range(2 ** n):
        t = set([j + 1 for j in range(n) if i >> j & 1])
        for k in range(m):
            if len(s[k] & t) & 1 != p[k]:
                break
        else:
            combs += 1
    
    return combs

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
using namespace std;
 
int main() {
    char c;
    while (true) {
        scanf("%c", &c);
        if (c == '\n') {
            cout << endl;
            break;
        }
        if (isupper(c)) {
            c = tolower(c);
            cout << c;
        }
        else if (islower(c)) {
            c = toupper(c);
            cout << (c);
        }
        else
            cout << c;
    }
    return 0;
}

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

double x[200],y[200];
double ans[2000];

int main(){
	int n;scanf("%d",&n);
	rep(i,n)scanf("%lf%lf",&x[i],&y[i]);
	double R=1e11;
	double K=100000;
	rep(i,K){
		double rad=2*M_PI*i/K;
		double X=cos(rad)*R,Y=sin(rad)*R;
		double Min=INFINITY;
		int id=-1;
		rep(j,n){
			double d=pow(X-x[j],2)+pow(Y-y[j],2);
			if(d<Min){
				Min=d;id=j;
			}
		}
		ans[id]+=1/K;
	}
	rep(i,n){
		printf("%.7lf\n",ans[i]);
	}
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long ll;
const long double PI = (acos(-1));
const long long MOD = 1000000007;
#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(int i=x;i<n;++i)

///////////////////////////////////////////////////
// -------------------- I/O -------------------- //
///////////////////////////////////////////////////
// https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords
template<typename T> void outputVec(const std::vector<T>& vec, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	for (auto it = vec.begin(); it != vec.end() - 1; ++it) { std::cout << *it << " "; }
	std::cout << *(vec.end() - 1) << "\n";
}
template<typename T> void outputVal(const T& res, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	std::cout << res << "\n";
}
template<typename T> T inputVal() { T a; std::cin >> a; return a; }
template<typename T> std::vector<T> inputVec(int N) {
	std::vector<T> vec(N);
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
	return vec;
}
template<typename T> void inputVec(std::vector<T>& vec) {
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
}

///////////////////////////////////////////////////
// ------------------- utils ------------------- //
///////////////////////////////////////////////////
// change min/max
template<class T> inline bool chMin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chMax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

///////////////////////////////////////////////////
// ------------------- main -------------------- //
///////////////////////////////////////////////////
void Main() {
	const int A = inputVal<int>();
	const int P = inputVal<int>();
	const int nb = (A * 3 + P) / 2;
	outputVal(nb);
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout << std::fixed << std::setprecision(15);
	Main();

	double tmp;
	cin >> tmp;

	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <array>
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <utility>
#include <assert.h>
#include <regex>
using namespace std;

typedef unsigned long long ull;
typedef signed long long ll;
#define INF (1LL << 48)

struct PT { ll x; ll y; };
string to_s(ull x) { return to_string(x); }
string to_s(ll x) { return to_string(x); }
ll to_ll(const string& x) { return stoll(x); }
ull to_ull(const string& x) { return stoull(x); }




int main(int argc, char* argv[])
{
	for (;;) {
		string S;
		cin >> S;
		if (cin.fail()) break;

		S = std::regex_replace(S, std::regex("eraser"), "");
		S = std::regex_replace(S, std::regex("erase"), "");
		S = std::regex_replace(S, std::regex("dreamer"), "");
		S = std::regex_replace(S, std::regex("dream"), "");
		puts(S.empty() ? "YES" : "NO");
	}

	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pll         pair<long long,long long>
#define vll          vector<long long>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (long long)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define ubnd        upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main(){
	ll n;cin>>n;
	cout<<(n*(n-1)/2)<<endl;
}

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

int main() {
  string N;
  cin >> N;
  int n = N.length();
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += (N[i] - '0');
  }
  if (ans % 9 == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3728
from fractions import gcd

A,B=map(int,input().split())
p=set([1])
g=gcd(A,B)
for d in range(2,g):
    while g%d==0:
        p.add(d)
        g//=d
    if (d*d>=g): break
if g>=2:
    p.add(g)
print(len(p))


Measured memory_bytes: 10624
#include<iostream>
#define INF 100000000
using namespace std;
int min(int a,int b){
  return a<b?a:b;
}
int main(){
  int n,m;
  while(cin>>n>>m){
    if(n==0&&m==0) break;
    int d0[m+1][m+1],d1[m+1][m+1];
    for(int i=1;i<=m;i++){
      for(int j=1;j<=m;j++){
	d0[i][j] = INF;
	d1[i][j] = INF;
      }
    }
    int a,b,cost,time;
    for(int i=0;i<n;i++){
      cin >> a >> b >> cost >> time;
      d0[a][b] = cost;
      d0[b][a] = cost;
      d1[a][b] = time;
      d1[b][a] = time;
    }
    for(int i=1;i<=m;i++){
      for(int j=1;j<=m;j++){
	for(int k=1;k<=m;k++){
	  d0[j][k] = min(d0[j][k],d0[j][i]+d0[i][k]);
	  d1[j][k] = min(d1[j][k],d1[j][i]+d1[i][k]);
	}
      }
    }
    int s,p,q,r; 
    cin >> s;
    for(int i=0;i<s;i++){
      cin >> p >> q >> r;
      if(r==0) cout << d0[p][q] << endl;
      else cout << d1[p][q] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;
 
int main() {
    ios::sync_with_stdio(false);
    int d, n;
    cin >> d >> n;
    if (n == 100) {
        if (d == 0) cout << 101;
        else if (d == 1) cout << 10100;
        else cout << 1010000;
        return 0;
    }
    if (d == 0) cout << n;
    else if (d == 1) cout << n * 100;
    else cout << n * 10000;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
  
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
const ll MOD = 1000000007;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}
  
int main()
{
  int i,j;
  int n;
  ll k;
  ll ans = 0;
  cin >> n >> k;
  int a[n];
  inputArray(a,n);

  rep(i,n){
      ll left=0,right=0,left_mod=0,right_mod=0;
      rep(j,n){
          if(i>j && a[i]>a[j]){left++;}
          if(i<j && a[i]>a[j]){right++;}
      }
      left_mod = k*(k-1)/2; left_mod %= MOD;
      right_mod = k*(k+1)/2; right_mod %= MOD;
      left *= left_mod; left%=MOD;
      right *= right_mod; right%=MOD;
      ans += left + right;
      ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;
#pragma endregion
int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int N, M, C;
	cin >> N >> M >> C;
	vector<int> correct(M);
	rep(i, M)
	{
		cin >> correct[i];
	}

	int ans = 0;

	rep(i, N)
	{
		vector<int> code(M, 0);
		int sum = 0;
		rep(j, M)
		{
			cin >> code[j];
			sum += correct[j] * code[j];
		}
		if (sum + C > 0)
			ans++;
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
<?php
	fscanf(STDIN, "%d", $n);

	for ($i = 1; $i <= 9; $i++) {
		for ($j = 1; $j <= 9; $j++) {
			if ($i * $j === $n) {
				echo 'Yes';
				return;
			}
		}
	}

	echo 'No';
?>


Measured memory_bytes: 4604
#include <stdio.h>

#define MAX 100

int SelectionSort(int [],int);
void swap(int [],int,int);

int main(){
  int A[MAX],N;
  int answer;
  int i;

  scanf("%d",&N);

  for (i = 0;i < N;i++)
    scanf("%d",&A[i]);

  answer = SelectionSort(A,N);
  
  for (i = 0;i < N;i++){
    if (i)
      printf(" ");

    printf("%d",A[i]);
  }

  printf("\n%d\n",answer);
  
  return 0;
}

int SelectionSort(int A[],int N){
  int minj,cnt = 0;
  int i,j;

  for (i = 0;i < N - 1;i++){
    minj = i;
    
    for (j = i;j < N;j++)
      if (A[j] < A[minj])
	minj = j;

    if (minj != i){
    swap(A,i,minj);
    cnt++;
    }
    
  }

  return cnt;
}

void swap(int A[],int i,int minj){
  int temp;

  temp = A[i];
  A[i] = A[minj];
  A[minj] = temp;
}



Measured memory_bytes: 2120
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <cstdlib>
#include <vector>
#include <string>
#include <bitset>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
 
typedef long long ll;
typedef long double ld;
 
const ll MOD = 1e9 + 7, INF = 1e18 + 1;
 
using namespace std;

vector <int> g[1000000];

string s;

int n;

int main ()
{
	cin >> s;

	n = s.length ();

	s = '0' + s;

	for (int i = 0; i <= n; i++)
		if (s[i] != s[n - i])
		{
			cout << "-1";
			return 0;
		}

	if (s[1] == '0')
	{
		cout << "-1";
		return 0;
	}

	int x = 1, ptr = 1;

	for (int i = 1; i < n; i++)
	{
		g[x].push_back (++ptr);

		if (s[i] == '1') x = ptr;
	}

	for (int i = 0; i <= ptr; i++)
		for (int a : g[i])
			printf ("%d %d\n", i, a);
}


Measured memory_bytes: 28028
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;

const int MAXN = 1e5 + 5;

int vis[MAXN + 5];

int N, M;

int main()
{
    scanf("%d %d", &N, &M);
    for(int i = 1; i <= M; i++){
        int u, v;
        scanf("%d %d", &u, &v);
        vis[u]++, vis[v]++;
    }
    int ok = 1;
    for(int i = 1; i <= N; i++){
        if(vis[i] % 2 != 0) ok = 0;
    }
    if(ok) printf("YES\n");
    else printf("NO\n");
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define DEBUG(x)           cout << '>' << #x << ':' << x << endl;
#define forn(i,n)          for(int i=0;i<(int)n;++i)
#define for1(i,n)          for(int i=1;i<=(int)n;++i)
#define forr(i,n)          for(int i=(int)n-1;i>=0;--i)
#define forre(i,a,b)       for(int i=(int)b;i>=(int)a;--i)
#define fore(i,a,b)        for(int i=(int)a;i<=(int)b;++i)
#define input(arr,n)       for(int i=0;i<n;i++)cin>>arr[i]
#define output(arr,n)      for(int i=0;i<n;i++)cout<<arr[i]<<" "
#define for_each(arr)      for(auto& it:arr)cout<<it<<" "
#define ff                 first
#define ss                 second
#define PI                 acos(-1.0)
#define all(a)             a.begin(),a.end()
#define rall(a)            a.rbegin(),a.rend()
#define Unique(a)          sort(all(a)),a.erase(unique(all(a)),a.end())
#define pb(x)              push_back(x)
#define eb(x)              emplace_back(x) 
#define ppb(x)             pop_back(x)
#define pf(x)              push_front(x)
#define ppf(x)             pop_front(x)
#define in(x,y)            insert({x,y})
#define Sort(a)            sort(a.begin(),a.end())
#define mem(arr,a)         memset(arr,a,sizeof arr)
#define ins(a)             insert(a)
#define max2(a,b)          max(a,b)
#define max3(a,b,c)        max(a,max(b,c))
#define max4(a,b,c,d)      max(a,max3(b,c,d))
#define min2(a,b)          min(a,b)
#define min3(a,b,c)        min(a,min(b,c))
#define min4(a,b,c,d)      min(a,min3(b,c,d))
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<char> vc;
typedef vector<double> vd;
/*inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void Set(int & n, int b) { n |= two(b); }
inline void Reset(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }*/
/*int fx1[]={+1,-1,+0,+0};
int fy1[]={+0,+0,+1,-1};
int fx2={+0,+0,+1,-1,-1,+1,-1,+1};
int fy2={-1,+1,+0,+0,+1,+1,-1,-1};
*/

ll a,b,c,n,ans,cn1,cn2,cn3,t;
string s,s1,s2;


int main()
{
    FIO;
    ///#ifndef ONLINE_JUDGE
   // freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
  //  #endif
    map<string,int>mp;
    mp["SUN"]=1;
    mp["MON"]=2;
    mp["TUE"]=3;
    mp["WED"]=4;
    mp["THU"]=5;
    mp["FRI"]=6;
    mp["SAT"]=7;
    cin>>s;
    cout<<7-mp[s]+1<<endl;

    
   	
    #ifdef ONLINE_JUDGE
    cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
    #endif
   return 0;
}
 


Measured memory_bytes: 256
M, D = gets.split.map(&:to_i)
cnt = 0
(1..M).each do |m|
    (1..D).each do |d|
        d1 = d % 10
        d10 = d / 10
        cnt += 1 if d1>=2 && d10>=2 && d1*d10==m
    end
end
puts cnt


Measured memory_bytes: 1788
import numpy as np

i = input().split(' ')
H = int(i[0])
W = int(i[1])

arr = []

for h in range(0,H):
    s = input().replace('\n', "")
    s = s.replace('.', "0")
    s = s.replace('#', "1")
    arr.append(list(s))

arr = np.array(arr, dtype=int)
able = "Yes"

for i in range(0,H):
    for j in range(0,W):
        if arr[i,j] == 0:
            continue
        localAble = 0
        if 0<=i-1:
            if arr[i-1,j] == 1:
                localAble = 1
        if i+1<H:
            if arr[i+1,j] == 1:
                localAble = 1
        if 0<=j-1:
            if arr[i,j-1] == 1:
                localAble = 1
        if j+1<W:
            if arr[i,j+1] == 1:
                localAble = 1
        if localAble == 0:
            #print("{} {}".format(i,j))
            #print(arr[i,j])
            able = "No"

print(able)


Measured memory_bytes: 12504
#include<stdio.h>
int main(){
	int i, j, ans = 0, N,cnt;
	scanf("%d", &N);
	for (i = 1; i <= N; i+=2) {
		cnt = 0;
		for (j = 1; j <= i; j++) {
			if (i%j == 0) {
				cnt++;
			}
		}
		if (cnt == 8) {
			ans++;
		}
	}

	printf("%d\n", ans);
}

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

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        String[] a = line.split("");
        line = br.readLine();
        String[] b = line.split("");
        int al = 0;
        int bl = 0;
        if(a.length > b.length) {
            System.out.println("GREATER");
        } else if(b.length > a.length) {
            System.out.println("LESS");
        } else {
            for(int i = 0; i < a.length; i++) {
                al = Integer.parseInt(a[i]);
                bl = Integer.parseInt(b[i]);
                if(al > bl) {
                    System.out.println("GREATER");
                    break;
                } else if(bl > al) {
                    System.out.println("LESS");
                    break;
                }
                if(i == a.length - 1) {
                    System.out.println("EQUAL");
                }
            }
        }
    }
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
#define mid (tl+tr)/2
#define mod 1000000007
#define fain(arr) for(ll i=0;i<n;i++)cin>>arr[i];
#define all(x) x.begin(),x.end()
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define bugv(n1) if(DEBUG)cout<<#n1<<" is "<<n1<<'\n';
#define buga(A) cout<<#A<<" is :"<<endl ; for(auto x:A)cout<<x<<" "; cout<<endl;
#define FILE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define endl '\n'
#define ll long long 
#define pii pair<ll,ll>
#define pll pair<long long ,long long >
#define pi acos(-1)
#define sz(x) ((ll)x.size())
#define clr(x) memset(x, 0, sizeof(x))
#define init(x, a) memset(x, a, sizeof(x))
#define DEBUG true
using namespace std;




int main(){
	// FILE;
	SPEED;	
	
	ll n;
	cin>>n;

	ll arr[n];
	fain(arr);

	ll brr[n+1]={0};

	for(auto x:arr)brr[x]++;

	ll total=0;
	unordered_map<ll,ll> crr;
	for(auto x:brr){total+=(x*(x-1))/2;crr[x]=(x*(x-1))/2;}

	for(int i=0;i<n;i++){
		ll x=brr[arr[i]];
		cout<<total-crr[x]+((x-2)*(x-1))/2<<endl;
	}

	 


}


Measured memory_bytes: 7552
#include <stdio.h>

  int main()
  {
    int is,ish,ism;
    int h,m,s;
    scanf("%d",&is);
    h = (is/3600);
    ish = (is - (3600*h));
    m = (ish/60);
    s = (ish - (60*m));
    printf("%d:%d:%d\n",h,m,s);
    return 0;
  }


Measured memory_bytes: 2056
a = ['2','3','4','5','6','7','8','9','10','11','12','13','1']
al,bo = map(str,raw_input().split())
if a.index(al) > a.index(bo):
    print 'Alice'
elif a.index(al) < a.index(bo):
    print 'Bob'
else:
    print 'Draw'


Measured memory_bytes: 2568
target = input().split()
target = [int(i) for i in target]
try:
  arr = input().split()
  arr = [int(i) for i in arr]
except:
  arr = []

if len(arr)==0:
  print(target[0])
else:
  i=0
  while(1):
    if target[0]-i in arr and target[0]+i in arr:
      i+=1
    elif target[0]-i not in arr:
      print(target[0]-i)
      break
    elif target[0]+i not in arr:
      print(target[0]+i)
      break

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

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
char capitalize(char c) { return static_cast<char>(std::toupper(static_cast<unsigned char>(c))); }
// template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
// template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

#define int long long
#define YES "YES"
#define NO  "NO"
#define MOD 1000000000+7
#define forit(v) for(auto it = v.begin(); it != v.end(); ++it)

using namespace std;

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

  int num = 0;
  // num = numeric_limits<int>::max();
  // num = numeric_limits<int>::min();
  bool flag = false;
  // flag = true;

  int a; cin >> a;
  int b; cin >> b;
  int c; cin >> c;
  int x; cin >> x;

  for (int i = 0; i <= a; ++i) {
    for (int j = 0; j <= b; ++j) {
      for (int l = 0; l <= c; ++l) {
        int tmp = i * 500 + j * 100 + l * 50;
        if (tmp == x) ++num;
      }
    }
  }

  cout << num << endl;
  // cout << (flag ? YES : NO) << endl;
  
  return 0;
}


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

int main()
{
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  cout << (h2 * 60 + m2 - h1 * 60 - m1) - k << endl;
  return 0;
}


Measured memory_bytes: 3636
S = input()

n = 7
if S == "SAT":
    n = 1
elif S == "FRI":
    n = 2
elif S == "THU":
    n = 3
elif S == "WED":
    n = 4
elif S == "TUE":
    n = 5
elif S == "MON":
    n = 6
print(n)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define int long long



int findx(int p[], vector<int> ko[], int oya, int co){
    if(ko[co].size()==1)return p[co];
    
    int sum=0,t,maxs=0;
    for(int i=0;i<ko[co].size();i++){
        if(ko[co][i]!=oya){
            t=findx(p,ko,co,ko[co][i]);
            if(t==-1)return -1;
            maxs=max(maxs,t);
            sum+=t;
        }
    }
    if(2*p[co]<sum)return -1;
    maxs=max(maxs,2*p[co]-sum);
    if(maxs>p[co])return -1;
    return 2*p[co]-sum;
}

signed main(){
    int n;

    cin >>n;
    int p[n];
    for(int i=0;i<n;i++)cin >>p[i];
    vector<int> ko[n];
    int a,b;
    for(int i=1;i<n;i++){
        cin >> a>>b;
        ko[a-1].push_back(b-1);
        ko[b-1].push_back(a-1);
    }
    if(n==2){
        if(p[0]==p[1])cout << " YES ";
        else cout << " NO ";

    }
    else{
        int k=0;
        while(ko[k].size()<=1)k++;
        if(findx(p,ko,-1,k)==0)cout <<" YES ";
        else cout <<" NO ";

    }
    


    return 0;
}

Measured memory_bytes: 14464
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;



int main() {
    ios_base::sync_with_stdio(false); 

    string s;
    cin >> s;
    int ans=0,g=0,p=0;
    rep(i,s.size()) {
        if (s[i]=='g') {
            if (p+1<=g) {
                ++ans;
                ++p;
            } else {
                ++g;
            }
        } else {
            if (p+1<=g) {
                ++p;
            } else {
                --ans;
                ++g;
            } 
        }
    } 
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#define N 100
using namespace std;

int main(){
  int n,a[N];
  
  cin>>n;
  for(int i=0;i<n;i++) cin>>a[i];
  for(int j=n-1;j>=0;j--){
    if(j==0) cout<<a[j]<<endl;
    else cout<<a[j]<<" ";
  }
  return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define INF 100000000
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)

int main() {
  int T,A,B;
  int ans = 0;
  cin >> A >> B >> T;
  T /= A;
  ans = T*B;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)

MOD = 1000000007  # type: int

def solve(N: int, S: str):
    tmp = 0
    p = 1
    for c in S:
        if c == 'B':
            if tmp % 2 == 0:
                tmp += 1
            elif tmp > 0:
                p *= tmp
                p %= MOD
                tmp -= 1
            else:
                print(0)
                return
        if c == 'W':
            if tmp % 2 == 1:
                tmp += 1
            elif tmp > 0:
                p *= tmp
                p %= MOD
                tmp -= 1
            else:
                print(0)
                return
    if tmp > 0:
        print(0)
        return

    ret = 1
    for i in range(1, N + 1):
        ret *= i
        ret %= MOD
    ret *= p
    ret %= MOD
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


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

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

    int ans = 0;
    for (int i = 1; i <= n; i += 2) {
        int cnt = 0;
        for (int j = 1; j <= i; j++) {
            if (i % j == 0) {
                cnt++;
            }
        }
        if (cnt == 8) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

vvll to;
vll len;

ll dfs(ll u){
  if (len[u] != -1) return len[u];
  len[u] = 0;
  for (ll v : to[u]) {
    dfs(v);
    chmax(len[u], len[v] + 1);
  }
  return len[u];
}

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, m;
  cin >> n >> m;
  to.resize(n);
  rep(i, m) {
    ll x, y;
    cin >> x >> y;
    x--, y--;
    to[x].push_back(y);
  }

  len.assign(n, -1);
  ll soz = 0;
  rep(i, n) chmax(soz, dfs(i));

  cout << soz << endl;

  return 0;
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a > b) {
    swap(a, b);
  }
  if (b > c) {
    swap(b, c);
  }
  if (a > b) {
    swap(a, b);
  }
  cout << a << " " << b << " " << c << endl;

  return 0;
}


Measured memory_bytes: 3116
# -*- coding: utf-8 -*-
"""
Created on Sun Feb  9 20:50:13 2020

@author: H_Hoshigi
"""

S, T = input().split()
A, B = map(int, input().split())
U = input()

if S == U:
    A -= 1
else:
    B -= 1

print("{} {}".format(A, B))



Measured memory_bytes: 3060
a, b, c, x, y = map(int, input().split())

if x < y:
    print(min(2*c*y, 2*c*x+b*(y-x), a*x+b*y))
else:
    print(min(2*c*x, 2*c*y+a*(x-y), a*x+b*y))

Measured memory_bytes: 61416
#include<iostream>
#include<algorithm>
#include<array>
#include<queue>
#include<map>
using namespace std;
bool check(array<int,30>a)
{
	bool flag=1,t=1;
	for(int i=0;i<9;i++)t&=a[0]==a[i];
	flag&=t;
	flag&=a[9]==a[10]&&a[9]==a[11];
	flag&=a[12]==a[13]&&a[12]==a[14];
	flag&=a[15]==a[16]&&a[15]==a[17];
	flag&=a[18]==a[19]&&a[18]==a[20];
	t=1;
	for(int i=21;i<30;i++)t&=a[21]==a[i];
	flag&=t;
	return flag;
}
main()
{
	int n;cin>>n;
	for(;n--;)
	{
		array<int,30>u;
		queue<pair<array<int,30>,int> >P;
		map<array<int,30>,bool>M;
		for(int i=0;i<30;i++)cin>>u[i];
		P.push(make_pair(u,0));
		M[u]=true;
		while(!P.empty())
		{
			array<int,30>a=P.front().first;
			int cnt=P.front().second;
			P.pop();
			if(check(a))
			{
				cout<<cnt<<endl;
				break;
			}
			array<int,30>b;
			for(int i=0;i<30;i++)b[i]=a[i];
			swap(b[0],b[23]);
			swap(b[3],b[26]);
			swap(b[6],b[29]);
			swap(b[9],b[20]);
			swap(b[15],b[17]);
			if(!M[b])
			{
				M[b]=true;
				P.push(make_pair(b,cnt+1));
			}
			for(int i=0;i<30;i++)b[i]=a[i];
			swap(b[6],b[21]);
			swap(b[7],b[22]);
			swap(b[8],b[23]);
			swap(b[12],b[17]);
			swap(b[9],b[11]);
			if(!M[b])
			{
				M[b]=true;
				P.push(make_pair(b,cnt+1));
			}
			for(int i=0;i<30;i++)b[i]=a[i];
			swap(b[2],b[21]);
			swap(b[5],b[24]);
			swap(b[8],b[27]);
			swap(b[11],b[18]);
			swap(b[12],b[14]);
			if(!M[b])
			{
				M[b]=true;
				P.push(make_pair(b,cnt+1));
			}
			for(int i=0;i<30;i++)b[i]=a[i];
			swap(b[0],b[27]);
			swap(b[1],b[28]);
			swap(b[2],b[29]);
			swap(b[14],b[15]);
			swap(b[18],b[20]);
			if(!M[b])
			{
				M[b]=true;
				P.push(make_pair(b,cnt+1));
			}
		}
	}
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, K;
  cin >> A >> B >> K;
  vector<int> CD;
  if (A>B) swap(A,B);
  for (int i=1; i<B+1; i++){
    if(A%i==0 && B%i==0){
      CD.push_back(i);
    }
  }
  reverse(CD.begin(),CD.end());
  cout << CD.at(K-1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    int sum = 0;
    REP(i,N){
        cin >> A[i];
        sum += A[i];
    }
    int cnt = 0;
    REP(i,N){
        if(sum <= 4 * M * A[i]) cnt++;
    }
    if(cnt >= M) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 256
n,m=map(int,input().split())
card =[list(map(int,input().split())) for i in range(m)]
r = card[0][0]
R = card[0][1]
for i in range(m):
    if  r < card[i][0]:
        r = card[i][0]
for i in range(m):
    if card[i][1] < R:
        R = card[i][1]
ans = max(0,R - r + 1)
print(ans)

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

int main(){
  int N,D;
  cin >> N >> D;
  vector<vector<int>> X(N,vector<int>(D));
  for(int i=0; i<N; i++){
    for(int j=0; j<D; j++){
      cin >> X.at(i).at(j);
    }
  }
  
  int count=0;
  for(int i=0; i<N-1; i++){
    for(int j=i+1; j<N; j++){
      double dis=0;
      for(int k=0; k<D; k++){
        dis+=(X.at(i).at(k)-X.at(j).at(k))*(X.at(i).at(k)-X.at(j).at(k));
      }
      dis=sqrt(dis);
      int d=dis;
      if(dis==d){
        count++;
      }
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <numeric>

using namespace std;

const uint64_t MOD = 1000000000 + 7;

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

	int cnt = 1;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a.at(i);
	}

	int out = -1;
	int s = a.at(0);
	for (int i = 0; i < n; i++)
	{
		if (s == 2)
		{
			out = cnt;
			break;
		}
		else
		{
			s = a.at(s - 1);
			cnt++;
		}
	}

	cout << out << endl;
}


Measured memory_bytes: 640