akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

// 小数点以下桁数
// fixed << setprecision(i)

int64_t gcd(int64_t a,int64_t b){return (a%b==0?b:gcd(b, a%b));}
int64_t lcm(int a,int b){return (int64_t)a*b/gcd(a, b);}
int factorial(int a){int b=1;while(a){b*=a--;}return b;} //13以下対応
bool is_prime(int a){if(a<=1)return false;for(int i=2;(int64_t)i*i<=a;i++){if(a%i==0)return false;}return true;}
int get_adp(double x, int n){return (int)round((x-(int)x)*pow(10,n))%10;} // 小数点以下の指定桁の値を取得
int64_t sigma(int64_t s, int64_t n){return n*(2*s+n-1)/2;}

//順列の全列挙
// vector<int> v(N);
// iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
// do {
//	for(auto x : v) cout << x << " "; cout << "\n";     // v の要素を表示
// } while( next_permutation(v.begin(), v.end()) ); 

//bit全探索
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//	bitset<ビット数> s(tmp);
//	// (ビット列sに対する処理)
// }

int main()
{
  int64_t n, ans = 0;

  cin >> n;
  for (int64_t i = 1; i < n; i++)
  {
    ans += n / i;
    if (n % i == 0)
      ans--;
  }
  cout << ans << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; ++i) cin >> a.at(i);
  
  bool can = true;
  for(int i = 0; i < n; ++i){
    if(a.at(i) % 2) continue;
    if(a.at(i) % 3 == 0) continue;
    if(a.at(i) % 5 == 0) continue;
    can = false;
  }
  
  if(can) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
}

Measured memory_bytes: 256
// Shift-JIS（シフトジス）

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

int N;
int d[100000];

int main()
{
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> d[i];
    }
    sort(d, d + N);
    cout << d[N / 2] - d[N / 2 - 1] << endl;
}

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

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    int N;
    vector<real> rs;
    void input() {
        cin >> N;
        rs.resize(N); cin >> rs;
    }

    real d(int i, int j) {
        int a = rs[i], b = rs[j];
        return real(2.0) * sqrt(a * b);
    }

    void solve() {
        vector<real> xs(N, 0);
        for (int i = 0; i < N; i++) {
            real c = rs[i];
            for (int j = 0; j < i; j++) {
                c = max(c, xs[j] + d(j, i));
            }
            xs[i] = c;
        }
        real ans = 0;
        for (int i = 0; i < N; i++) {
            ans = max(ans, xs[i] + rs[i]);
        }
        cout << fixed << setprecision(12) << ans << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}

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

int main()
{
	int m[10];
	int i, j, n;
	for(i=0; i<10; i++)
		cin >> m[i];

	for(j=0; j<10; j++)
	{
		for(i=j; i<10; i++)
		{
			if(m[j] < m[i])
			{
				n = m[i];
				m[i] = m[j];
				m[j] = n;
			}
		}
	}

	for(i=0; i<3; i++)
		cout << m[i] << endl;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  string s;
  cin >> s;

  cout << (s == "ABC" ? "ARC" : "ABC") << endl;
  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string s;
    cin>>s;
    if(s[0]=='a'||s[0]=='e'||s[0]=='i'||s[0]=='o'||s[0]=='u'){
        cout<<"vowel"<<endl;
    }else{
        cout<<"consonant"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import string
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

H, W = list(map(int, sys.stdin.readline().split()))
C = [sys.stdin.readline().rstrip() for _ in range(H)]

for r in C:
    print(r)
    print(r)


Measured memory_bytes: 23296
/*Country Road*/
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> p;

int main(void){
  int o;
  cin >> o;
  for(int i=0;i<o;i++){
    int p,n;
    cin >> p >> n;
    vector<int> v(p,0),l(p,0);
    for(int j=0;j<p;j++){
      cin >> v[j];
    }
    for(int j=0;j<p-1;j++){
      l[j]=v[j+1]-v[j];
      //cout << l[j] <<endl;
    }
    int sum=accumulate(l.begin(),l.end(),0);
    //cout << sum << endl;
    sort(l.begin(),l.end());
    reverse(l.begin(),l.end());
    for(int j=0;j<n-1;j++){
      sum=sum-l[j];
      //cout << sum << ' ' << l[j] << endl;
    }
    if(sum<0)cout << 0 << endl;
    else cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 3628
import java.util.Arrays;
import java.util.Optional;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説どおりに作成したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			Point[] blues = new Point[n], reds = new Point[n];
			IntStream.range(0, n).forEach(i -> reds[i] = new Point(scanner.nextInt(), scanner.nextInt()));
			IntStream.range(0, n).forEach(i -> blues[i] = new Point(scanner.nextInt(), scanner.nextInt()));
			Arrays.sort(blues, (a, b) -> a.x - b.x);
			System.out.println(IntStream.range(0, n).map(i -> {
				Optional<Point> first = Arrays.stream(reds)
						.filter(point -> (!point.visited) && (point.x < blues[i].x) && (point.y < blues[i].y))
						.sorted((a, b) -> b.y - a.y).findFirst();
				if (first.isPresent()) {
					first.get().visited = true;
					return 1;
				} else {
					return 0;
				}
			}).sum());
		}
	}

	/**
	 * 点を表すクラス
	 */
	private static class Point {
		/** X座標 */
		int x;
		/** Y座標 */
		int y;
		/** すでにペアリングしているかどうか */
		boolean visited = false;

		/**
		 * コンストラクタ
		 * 
		 * @param x
		 * @param y
		 */
		Point(int x, int y) {
			super();
			this.x = x;
			this.y = y;
		}
	}
}


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  vector<string> v = {"Sunny", "Cloudy", "Rainy"};
  string s;
  cin >> s;
  ll p = 0;
  rep(i,3) if (s == v[i]) p = i;
  p = (p+1) % 3;
  cout << v[p] << endl;
  return 0;
}


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

using namespace std;

int main(void){

    int a, b, c;
    cin >> a >> b >> c;
    
    for(int i=1; i<=100; i++) {
        if((a*i)%b==c) {
            cout << "YES" << endl;
            return 0;
        }
    }
    
    cout << "NO" << endl;

    return 0;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define int long long
const int N = 1e6;

int n;
int a[N];
int cnt[N];
int used[N];
set<pair<int, int> > mm, mm2;
vector<int> ans;

int get2(int x)
{
    auto it = mm2.lower_bound({x, -1});
    return (*it).second;
}

int ch(int lst, int x, int t)
{
    if (a[lst] == x)
    {
        return 0;
    }
    int cn = get2(x);
    mm.erase({cn, x});
    mm2.erase({x, cn});
    if (t == 0)
    {
        int nxt = a[x];
        if (!used[nxt])
        {
            int cnnxt = get2(nxt);
            mm.erase({cnnxt, nxt});
            mm.insert({cnnxt - 1, nxt});
            mm2.erase({nxt, cnnxt});
            mm2.insert({nxt, cnnxt - 1});
        }
        return 1;
    }
    auto it = mm.end();
    it--;
    if ((*it).first == mm.size())
    {
        mm.insert({cn, x});
        mm2.insert({x, cn});
        return 0;
    }
    mm.insert({cn, x});
    mm2.insert({x, cn});
    return 1;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        cnt[a[i]]++;
    }
    for (int i = 1; i <= n; i++)
    {
        mm.insert({cnt[i], i});
        mm2.insert({i, cnt[i]});
    }
    for (int i = n; i >= 5; i--)
    {
        int lst = 0, t = n + 1;
        if (ans.size()) lst = ans.back();
        auto it1 = mm.end();
        it1--;
        auto it2 = mm.end();
        it2--;
        it2--;
        auto it3 = mm2.begin();
        auto it4 = mm2.begin();
        it4++;
        pair<int, int> i1 = *it1;
        pair<int, int> i2 = *it2;
        pair<int, int> i3 = *it3;
        pair<int, int> i4 = *it4;
        if (ch(lst, i1.second, 1)) t = min(t, i1.second);
        if (ch(lst, i2.second, 1)) t = min(t, i2.second);
        if (ch(lst, i3.first, 1)) t = min(t, i3.first);
        if (ch(lst, i4.first, 1)) t = min(t, i4.first);
        if (t == n + 1) cout << -1, exit(0);
        ch(lst, t, 0);
        used[t] = 1;
        ans.push_back(t);
    }
    vector<int> p;
    int lst = 0;
    if (ans.size()) lst = ans.back();
    for (int i = 1; i <= n; i++) if (used[i] == 0) p.push_back(i);
    while (1)
    {
        int t = 1;
        if (a[lst] == p[0]) t = 0;
        for (int i = 1; i < p.size(); i++)
            if (a[p[i - 1]] == p[i]) t = 0;
        if (t)
        {
            for (int i = 0; i < p.size(); i++)
                ans.push_back(p[i]);
            break;
        }
        if (!next_permutation(all(p)))
        {
            cout << -1, exit(0);
        }
    }
    for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
}


Measured memory_bytes: 22272
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()
    ret = MOD
    for n in range(len(S) - 2):
        ret = min(ret, abs(753 - int(S[n:n + 3])))
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3832
#include<cstdio> 
#include<cstring>
#include<iostream> 
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	int n,num=0,a;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a;
		if(a!=i)
		num++;
	}
	if(num==0||num==2)
	cout<<"YES";
	else cout<<"NO";
	return 0;
} 

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

int main() {
    string S;
    cin >> S;
    vector<int> v(26);
    for (int i = 0; i < 4; i++)
        v[S[i] - 'A']++;

    int cnt = 0;
    for (int i = 0; i < 26; i++) {
        if (v[i] == 2)
            cnt++;
    }
    if (cnt == 2)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;

}

Measured memory_bytes: 256
/*****************************************************

@author: vichitr
Compiled On: 27th April 2019

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

#include<bits/stdc++.h>
#define MAX 9223372036854775807
#define endl "\n"
#define ll long long
#define int long long
#define pb push_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define ip pair<int, int>

#define loop(i,n) for(int i=0;i<n;i++)
#define fast ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
using namespace std;

const ll MOD = 1e9+7;
const ll SZ = 107;
const ll N = 2e5+7;

int pow(int x, int y)
{
    ll r = 1LL;
    while(y)
    {
        if(y&1)
            r = (r * x);
        y >>= 1;
        x = (x * x);
    }
    return r;
}

void solve()
{
    int n;cin>>n;
    int a[n], c= 0, m;
    for(int i=0;i<n;i++){ 
        cin>>a[i];
        if(a[i]<0){
            c++;
            a[i] *= -1;
        }
    }
    m = a[0];
    for(int i=0;i<n;i++)
    {
        m = min(m, a[i]);
    }
    int ans = accumulate(a, a+n, 0ll);
    if(c%2)
        cout<<ans-2*m;
    else
        cout<<ans;
}

signed main()
{
    int t=1;
    // cin >>t;
    while(t--){
        solve();
    }
    return 0;
}

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


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

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

long long int result[100001][13] = {};

int main()
{
	string s;
	cin >> s;
	result[0][0] = 1;
	for(int i = 1; i <= s.length(); i++){
		for(int j = 0; j < 13; j++){
			if(s[i - 1] == '?'){
				for(int k = 0; k < 10; k++){
					result[i][(j * 10 + k) % 13] += result[i - 1][j];
					result[i][(j * 10 + k) % 13] %= mod;
				}
			} else {
				result[i][(j * 10 + s[i - 1] - '0') % 13] += result[i - 1][j];
				result[i][(j * 10 + s[i - 1] - '0') % 13] %= mod;
			}
		}
	}
	cout << result[s.length()][5] << endl;
}

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

using namespace std;

int main()
{
    int n, x;
    int a[105];

    cin >> n >> x;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    sort(a, a + n);

    int i = 0;
    int ans = 0;
    while (i < n - 1) {
        if (a[i] <= x) {
            x -= a[i];
            ans++;
        }
        i++;
    }

    if (a[n - 1] == x) {
        ans++;
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

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

typedef long long ll;

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

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

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

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;  cin >> a >> b;
    if (a + b >= 24) {
      cout << a + b - 24 << endl;
    } else {
      cout << a + b << endl;
    }

    return 0;
}


Measured memory_bytes: 256
use std::io;
use std::cmp::Ordering;
use std::collections::BinaryHeap;


fn main() {
    let (n, m, s, t) = {
        let i = read::<usize>();
        (i[0], i[1], i[2] - 1, i[3] - 1)
    };

    let mut vec_s = vec![Vec::new(); n];
    let mut vec_t = vec![Vec::new(); n];

    for _ in 0..m {
        let (u, v, a, b) = {
            let i = read::<usize>();
            (i[0] - 1, i[1] - 1, i[2], i[3])
        };

        vec_s[u].push(Edge { node: v, cost: a });
        vec_s[v].push(Edge { node: u, cost: a });
        vec_t[u].push(Edge { node: v, cost: b });
        vec_t[v].push(Edge { node: u, cost: b });
    }

    let dist_s = dijkstra(&vec_s, s);
    let dist_t = dijkstra(&vec_t, t);

    let mut ans = vec![::std::usize::MAX; n];
    for i in (0..n).rev() {
        ans[i] = dist_s[i] + dist_t[i];
        if i + 1 < n {
            ans[i] = ::std::cmp::min(ans[i], ans[i + 1]);
        }
    }
    for a in ans {
        println!("{}", 1_000_000_000_000_000 - a);
    }
}

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
struct State {
    cost: usize,
    pos: usize,
}

impl Ord for State {
    fn cmp(&self, other: &State) -> Ordering {
        match other.cost.cmp(&self.cost) {
            Ordering::Less => Ordering::Less,
            Ordering::Greater => Ordering::Greater,
            Ordering::Equal => {
                self.pos.cmp(&other.pos)
            }
        }
    }
}

impl PartialOrd for State {
    fn partial_cmp(&self, other: &State) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}


#[derive(Debug, Copy, Clone, Eq, PartialEq)]
struct Edge {
    node: usize,
    cost: usize,
}

fn dijkstra(adj: &Vec<Vec<Edge>>, s: usize) -> Vec<usize> {
    let mut dist = (0..adj.len()).map(|_| ::std::usize::MAX)
        .collect::<Vec<usize>>();

    let mut q = BinaryHeap::new();
    dist[s] = 0;
    q.push( State { cost: 0, pos: s });

    while let Some( State { cost, pos }) = q.pop() {

        if cost > dist[pos] { continue; }

        for e in &adj[pos] {
            let s = State { cost: cost + e.cost, pos: e.node };
            if s.cost < dist[s.pos] {
                q.push(s);
                dist[s.pos] = s.cost;
            }
        }
    }

    dist
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define SIZE(x) ((ll)(x).size()) 
#define MAX(x) *max_element(ALL(x)) 
#define MIN(x) *min_element(ALL(x)) 
#define ALL(x) (x).begin(),(x).end() 

#define INF 1000000000000 
#define MOD 1000000007 
#define MAXR 100000 

#define PB push_back 
#define MP make_pair 
#define F first 
#define S second 



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    //vector<int> a(100005);
  	vector<int> a(200005);
    REP(i, n) cin >> a[i];
    //vector<int> b(100005, 0);
  	vector<int> b(200005, 0);
    REP(_, min(k, 42)){
        vector<int> b(200005, 0);
        REP(i, n){
            int l = max(0, (int)i-a[i]);
            int r = min(n-1, (int)i+a[i]);
            b[l] += 1;
            b[r+1] -= 1;
        }
        REP(i, n-1) b[i+1] += b[i];
        REP(i, n) a[i] = b[i];
    }
    REP(i, n) cout << a[i] << " ";
  	cout<<endl;
}


Measured memory_bytes: 5748
void main() {
	auto N = ri;
	auto ip = readAs!(int[]), T = ip[0], A = ip[1];
	auto H = readAs!(int[]);
	
	ulong res;
	real tmp = 4302413;
	foreach(v, i; H) {
		auto t = abs(A - (T - 0.006*i));
		if(tmp > t) {
			res = v;
			tmp = t;
		}
	}
	(1+res).writeln;
}

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

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

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

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

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

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 2300
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */



// Taken from: https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ull> vul;
typedef vector<ll> vl;
typedef vector<pii> vpii;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i,0,a)
#define trav(a, x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1e9 + 7; // 998244353; // = (119<<23)+1
const int MX = 2e5 + 5;

template<class T>
bool ckmin(T &a, const T &b) {
    return a > b ? a = b, 1 : 0;
}

template<class T>
bool ckmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());


//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element: vec) {
        is >> element;
    }
    return is;
}

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class AStudyScheduling {
public:
    void solve(std::istream &in, std::ostream &out) {
        int h1, m1, h2, m2, k;
        in >> h1 >> m1 >> h2 >> m2 >> k;
        int res = (h2 - h1) * 60 + m2 - m1 - k;
        out << res << '\n';
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    AStudyScheduling solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3584
#include <cstdio>
#include <cstring>
#include <climits>
#include <set>
#include <algorithm>
using namespace std;
typedef long long ll;
ll dist[10][10];
int main() {
    int n;
    while (scanf("%d",&n)!=EOF) {
        if (!n) break;
        for (int i=0; i<10; i++) for (int j=0; j<10; j++) {
            if (i==j) dist[i][j]=0;
            else dist[i][j]=INT_MAX;
        }
        set<int> town;
        int a, b, c;
        for (int i=0; i<n; i++) {
            scanf("%d%d%d",&a,&b,&c);
            dist[a][b]=c;
            dist[b][a]=c;
            town.insert(a); town.insert(b);
        }
        int sz=town.size();
        for (int k=0; k<sz; k++) {
            for (int i=0; i<sz; i++) {
                for (int j=0; j<sz; j++) {
                    dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
                }
            }
        }
        int rpos, res=INT_MAX;
        for (int i=0; i<sz; i++) {
            int sum=0;
            for (int j=0; j<sz; j++) if (dist[i][j]!=INT_MAX) sum+=dist[i][j];
            if (sum<res) {
                rpos=i;
                res=sum;
            }
        }
        printf("%d %d\n",rpos,res);
    }
}

Measured memory_bytes: 0
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=200005;
int n;
int a[maxn],pre[maxn],pos[maxn];
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++){
        if(i==0){
            pre[i]=a[i];
        }else{
            pre[i]=__gcd(pre[i-1],a[i]);
        }
        
    }
    for(int i=n-1;i>=0;i--){
        if(i==n-1){
            pos[i]=a[i];
        }else{
            pos[i]=__gcd(pos[i+1],a[i]);
        }
    }
    int ans=max(pos[1],pre[n-2]);
    for(int i=1;i<n-1;i++)
    {
        ans=max(ans,__gcd(pre[i-1],pos[i+1]));
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  int kk = 2*k;
  vector<vector<int>> l(2*kk, vector<int>(k, 0));
  for(int i = 0; i < n; i+=1) {
    int x, y;
    char ch;
    cin >> x >> y >> ch;
    if(ch == 'B') {
      x += k;
    }
    x %= kk;
    y %= kk;
    if(y >= k) {
      y -= k;
      if(x >= k) {
        x -= k;
      } else {
        x += k;
      }
    }
    l[x][y] += 1;
    l[x+kk][y] += 1;
  }
  vector<vector<int>> syl(2*kk, vector<int>(k,0));
  for(int i = 0; i < kk; i+=1) {
    for(int j = 0; j < k; j+=1) {
      syl[i][0] += l[i][j];
    }
    syl[i+kk][0] = syl[i][0];
    for(int j = 0; j < k-1; j+=1) {
      syl[i][j+1] = syl[i][j] - l[i][j] + l[i+k][j];
      syl[i+kk][j+1] = syl[i][j+1];
    }
  }
  int m = 0;
  for(int j = 0; j < k; j+=1) {
    int s = 0;
    for(int i = 0; i < k; i+=1) {
      s += syl[i][j];
    }
    if(m<s) {
      m = s;
    }
    for(int i = 0; i < kk-1; i+=1) {
      s = s - syl[i][j] + syl[i+k][j];
      if(m<s) {
        m = s;
      }
    }
  }
  cout << m << endl;
  return 0;
}


Measured memory_bytes: 31872
#include <iostream>
#include <string>

using namespace std;

struct elem {
    string name;
    int time;
};

template <class T>
class Queue {
public:
    Queue(int n) : xs {new T[n]}, maxsize {n}, head {}, tail {0} {};
    void enqueue(T v){
        xs[tail++] = v;
    };
    T dequeue(){
        return xs[head++];
    };
    int begin(){
        return head;
    };
    int end(){
        return tail;
    };
    int size(){
        return tail-head;
    };
    T at(int i){
        return xs[i];
    };
private:
    T* xs;
    int maxsize;
    int head;
    int tail;
};

int main(){
    int n, q;
    cin >> n >> q;
    auto que = Queue<elem>(1000000);
    string str;
    int t;
    for(int i = 0; i < n; ++i){
        cin >> str >> t;
        que.enqueue(elem{str, t});
    }

    int sum = 0;
    while(int s = que.size()){
        for(int i = 0; i < s; ++i){
            elem e = que.dequeue();
            if(e.time <= q){
                sum += e.time;
                cout << e.name << ' ' << sum << '\n';
            } else {
                sum += q;
                e.time -= q;
                que.enqueue(e);
            }
        }
    }
}

Measured memory_bytes: 19172
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var s = parseInt(input[0], 10);
	var w = parseInt(input[1], 10);
    if (s <= w) {
	//出力
	console.log('unsafe');
    }
   else if(s > w)
   {
     console.log('safe')
   }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29436
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
using namespace std;
typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)x.size()
#define int ll

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
  int n;
  cin >> n;
  multiset<int> st;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    st.insert(x);
  }
  int lst = *st.rbegin();
  st.erase(--st.end());
  if (lst != *st.rbegin()) {
    cout << "Impossible\n";
    exit(0);
  }
  st.erase(--st.end());
  if (lst & 1) {
    for (int i = lst - 1; i >= (lst + 1) / 2; i--) {
      for (int j = 0; j < 2; j++) {
        if (st.find(i) == st.end()) {
          cout << "Impossible\n";
          exit(0);
        }
        st.erase(st.find(i));
      }
    }
    if (st.empty() || *st.begin() > (lst + 1) / 2) {
      cout << "Possible\n";
    }
    else {
      cout << "Impossible\n";
    }
  }
  else {
    for (int i = lst - 1; i > lst / 2; i--) {
      for (int j = 0; j < 2; j++) {
        if (st.find(i) == st.end()) {
          cout << "Impossible\n";
          exit(0);
        }
        st.erase(st.find(i));
      } 
    }
    if (st.find(lst / 2) == st.end()) {
      cout << "Impossible\n";
      exit(0);
    }
    st.erase(st.find(lst / 2));
    if (st.empty() || *st.begin() > lst / 2) {
      cout << "Possible\n";
    }
    else {
      cout << "Impossible\n";
    } 
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 

#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define clr(x) memset((x),0,sizeof(x));
#define pb push_back
#define mp make_pair
#define sf(n) scanf("%d",&n)
#define pf(n) printf("%d",&n)
#define sor(v) sort(v.begin(),v.end())

typedef long long ll;
typedef unsigned long long ull;
typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
typedef map<int,int> mii;
typedef map<st,int> msi;
typedef set<int> si;
typedef set<st> ss;
typedef pair<int,int> Pii;
#define fr first
#define sc second

int main()
{
	int x;
	cin >> x;
	int cube = x*x*x;
	cout << cube << endl;
	return 0;
}

Measured memory_bytes: 3092
'use strict'
const lines = require('fs').readFileSync(0, 'utf8').split('\n')
const s = lines[0]
const t = lines[1]
let dp = []
for(var i=0;i<=s.length;i++){
  dp.push(Array(t.length+1).fill(""));
}

for (let i=1;i <= s.length;i++) {
  for (let j=1;j <= t.length;j++) {
    if (s.charAt(i-1) == t.charAt(j-1)) {
      const newStr = dp[i-1][j-1] + s.charAt(i-1)
      if (newStr.length > dp[i-1][j].length && newStr.length > dp[i][j-1].length) {
        dp[i][j] = newStr
      } else if (dp[i-1][j].length > dp[i][j-1].length) {
        dp[i][j] = dp[i-1][j]
      } else {
        dp[i][j] = dp[i][j-1]
      }
    } else {
      if (dp[i-1][j].length > dp[i][j-1].length) {
        dp[i][j] = dp[i-1][j]
      } else {
        dp[i][j] = dp[i][j-1]
      }
    }
  }
}
console.log(dp[s.length][t.length])

Measured memory_bytes: 131480
X = int(input())
i = 1
ok = False
while i * i <= X and not ok:
  if X % i == 0:
    for x in (i, X//i):
      A = -10000
      while A <= 10000:
        if A**5-(A-x)**5 == X:
          print(A, A-x)
          ok = True
          break
        A += 1
      if ok:
        break
  i += 1


Measured memory_bytes: 68056
/*
Contest: -
Problem: ARC 074C
Author: tzc_wk
Time: 2020.6.22
*/
#include <bits/stdc++.h>
using namespace std;
#define fi			first
#define se			second
#define fz(i,a,b)	for(int i=a;i<=b;i++)
#define fd(i,a,b)	for(int i=a;i>=b;i--)
#define foreach(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(a)		a.begin(),a.end()
#define giveup(...) return printf(__VA_ARGS__),0;
#define fill0(a)	memset(a,0,sizeof(a))
#define fill1(a)	memset(a,-1,sizeof(a))
#define fillbig(a)	memset(a,0x3f,sizeof(a))
#define fillsmall(a) memset(a,0xcf,sizeof(a))
#define mask(a)		(1ll<<(a))
#define maskx(a,x)	((a)<<(x))
#define _bit(a,x)	(((a)>>(x))&1)
#define _sz(a)		((int)(a).size())
#define filei(a)	freopen(a,"r",stdin);
#define fileo(a)	freopen(a,"w",stdout);
#define fileio(a) 	freopen(a".in","r",stdin);freopen(a".out","w",stdout)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define put(x)		putchar(x)
#define eoln        put('\n')
#define space		put(' ')
#define y1			y1010101010101
#define y0			y0101010101010
typedef pair<int,int> pii;
inline int read(){
	int x=0,neg=1;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')	neg=-1;
		c=getchar();
	}
	while(isdigit(c))	x=x*10+c-'0',c=getchar();
	return x*neg;
}
inline int qpow(int x,int e,int _MOD){
	int ans=1;
	while(e){
		if(e&1)	ans=ans*x%_MOD;
		x=x*x%_MOD;
		e>>=1;
	}
	return ans;
}
const int MOD=1e9+7;
int n=read(),m=read();
int l[305],r[305],x[305];
vector<int> tr[305];
int dp[305][305][305];
inline bool check(int i,int j,int k){
	bool flg=1;
	foreach(it,tr[i]){
		int ind=*it;
		int cnt=1;
		if(j>=l[ind])	cnt++;
		if(k>=l[ind])	cnt++;
		if(cnt!=x[ind])	flg=0;
	}
	return flg;
}
signed main(){
	fz(i,1,m)	l[i]=read(),r[i]=read(),x[i]=read(),tr[r[i]].push_back(i);
	if(check(1,0,0))	dp[1][0][0]=1;
	fz(i,2,n){
		fz(j,0,i-1){
			fz(k,0,j){
				if(j==k&&j)	continue;
				if(!check(i,j,k))	continue;
				dp[i][j][k]=dp[i-1][j][k];
				if(j==i-1||k==i-1){
					for(int l=0;l<i-1;l++){
						if(l<k)	dp[i][j][k]=(dp[i][j][k]+dp[j][k][l])%MOD;
						else	dp[i][j][k]=(dp[i][j][k]+dp[j][l][k])%MOD;
					}
				}
//				cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k]<<endl;
			}
		}
	}
	int ans=0;
	for(int i=0;i<n;i++)	for(int j=0;j<i;j++){
		ans=(ans+dp[n][i][j])%MOD;
	}
	ans=ans*6ll%MOD;
	ans=(ans+dp[n][0][0]*3)%MOD;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 58296
N = int(input())
F = [[] for i in range(N)]
P = [[] for i in range(N)]
for i in range(N):
    f = list(map(int, input().split()))
    F[i] = f

for i in range(N):
    p = list(map(int, input().split()))
    P[i] = p

num = -float("inf")
for i in range(1, 1 << 10):
    tmp = 0
    for k in range(N):
        rec = 0
        for j in range(10):
            if i & 1 << j and F[k][j]:
                rec += 1
        tmp += P[k][rec]
    num = max(num, tmp)

print(num)

Measured memory_bytes: 3064
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;
int arr[105];

int main() {
    // freopen("in.txt", "r", stdin);
    int n;
    scanf("%d", &n);
    n *= 2;
    for (int i = 0; i < n; ++i) scanf("%d", arr + i);
    sort(arr, arr + n);
    reverse(arr, arr + n);
    int ans = 0;
    for (int i = 1; i < n; i += 2) ans += arr[i];
    printf("%d", ans);
  return 0;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
A=list(map(int,input().split()))
B=[0]*(N+1)
B[0]=1;c=0;d=0
if B[0] in A:c=B[0]
for i in range(1,N+1):
  B[i]=A[B[i-1]-1]

d=B.index(B[-1])+1
if K<=N:print(B[K]);exit()
#if (K+1-d)%(N+1-d)==0:print(B[-1])
print(B[d-1+(K+1-d)%(N+1-d)])


Measured memory_bytes: 32236
import sys
import queue

# input
n = int(input())
tree = [[] for _ in range(n)]
for _ in range(n - 1):
    s, t, w = map(int, sys.stdin.readline().strip().split())
    tree[s].append((t, w))
    tree[t].append((s, w))


def search(current):
    distance = [0] * n
    foot_print = [False] * n

    que = queue.LifoQueue()
    que.put((current, 0))

    while not que.empty():
        current_node, current_dist = que.get()
        # print(f'corrent_node: {current_node}, current_dist: {current_dist}')
        distance[current_node] = current_dist
        foot_print[current_node] = True

        for node, dist in tree[current_node]:
            # print(f'node: {node}, dist: {dist}')
            if foot_print[node] is True:
                continue
            que.put((node, dist + current_dist))

    return distance


dist = search(0)  # 適当な点から開始
furthest_node = dist.index(max(dist))  # 最遠点の取得
dist = search(furthest_node)  # 最遠点からの距離の取得
diameter = max(dist)
print(diameter)


Measured memory_bytes: 47472
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct{
  int id;
  int k;
  int *child;
  int parent;
}node;

int d=0;
node *T;
int depth(int i){
  if(T[i].parent == -1) return d;
  else{
    d++;
    return depth(T[i].parent);
  }
}

int main(){
  int i, j=0, n, id, k;
  char str[20];
  scanf("%d", &n);
  T = malloc(sizeof(node)*n);
  for(i = 0; i<n; i++) T[i].parent = -1;
  for(i = 0; i < n; i++){
    scanf("%d%d", &id, &k);
    T[id].child = malloc(sizeof(int)*k);
    T[id].id = id;
    T[id].k = k;
    for(j = 0; j < T[id].k; j++){
      scanf("%d",&T[id].child[j]);
      T[T[id].child[j]].parent = id;
    }
    
  }
//print
  
  for(i = 0; i < n; i++){
    if(T[i].parent == -1) strcpy(str,"root");
    else if(T[i].k == 0) strcpy(str,"leaf");
    else strcpy(str,"internal node");
    printf("node %d: parent = %d, depth = %d, %s, ",i, T[i].parent,depth(i),str);
    d=0;
    printf("[");
    for(j=0; j<T[i].k; j++){
    if(j > 0) printf(", ");
    printf("%d",T[i].child[j]);
    }
    printf("]\n");
    
  }
  
  return 0;
}

Measured memory_bytes: 6476
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>
#include <map>   
#include <stdio.h>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define PB push_back
#define ull unsigned long long
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define sortR(a,b) sort(a, b, greater<int>())

using namespace std;

//最大公約数

ll mod = pow(10, 9) + 7;


int main() {
	int i,a,N;
  	ll ret=1;
	cin >> N;
	vector<int> ans(100000,0);
	REP(i, N) {
		cin >> a;
		ans[a] += 1;
	}
	i = (N % 2) ? 0 : 1;
	for (i; i < N; i += 2) {
		if (!(ans[i] == 2 || (i == 0 && ans[i] == 1))) {
			cout << 0 << endl;
			return 0;
		}
	}
	for (int i = 0; i < N / 2; i++) {
		ret *= 2;
		ret %= mod;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 640
#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 long long
#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 prDouble(x)  cout<<fixed<<setprecision(10)<<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--)
double dp[3001][3001]; 



double fn(vector<double>& arr , int i ,int x )
{

	if(x==0 )
	{
		return 1 ; 
	}
	if(i==0 )
	{
		return 0 ; 
	}

	if(dp[i][x] > -0.9  )
	{
		return dp[i][x] ; 
	}
	return dp[i][x]= arr[i]*fn(arr, i-1,x-1)+ (1-arr[i])*fn(arr, i-1, x) ; 

	
}

int32_t main()
{
	int n ; 
	cin>>n; 
	std::vector<double> arr(n+1);
	for(int i=1 ; i<=n; i++)
	{
		cin>>arr[i]; 
	}
	memset(dp, -1, sizeof(dp)) ; 

	int x; 
	 x=(n+1)/2 ; 
	
	 prDouble(fn(arr, n, x)) ; 
 

}

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


int main () {
  int N ;
  cin >> N ;
  
  vector<int> line(N) ;
  
  for(int i = 0 ; i < N ; i++ ) cin >> line[i] ;
  sort(line.begin(),line.end()) ;
  reverse(line.begin(),line.end()) ;
  
  int ans = 0 ;
  
  for(int i = 0 ; i < N ; i++ ) {
    if( i % 2 == 0 ) ans += line[i] ;
    else ans -= line[i] ;
  }
  cout << ans << endl ;
}

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

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

int main(){

    ll x; cin >> x;

    rep2(i, 2, x){
        if(x%i==0){
            x++;
            i = 1;
        }
    }

    cout << x << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

const int INF = 10000010;
const int N = 4040;

int n, k;
int ans = N;
int topQ;
int q[N];
int dist[N];
vector<int> G[N];

void BFS() {

	rep(k, topQ) {
		int v = q[k];
		for(auto u : G[v]) {
			int w = dist[v] + 2;
			if(dist[u] <= w) {
                continue;
            } 
			dist[u] = w;
			q[topQ++] = u;
		}
	}

	return;
}
 
int solveVertex(int v) {

	rep(i, n) {
        dist[i] = INF;
    }

	dist[v] = 0;
	topQ = 0;
	q[topQ++] = v;

	BFS();

	int res = 0;
	rep(i, n) {
        if(dist[i] > k) {
            res++;
        }
    }
		
	return res;
}

int solveEdge(int v, int u) {

	rep(i, n) {
		dist[i] = INF;
	}
		
	dist[v] = dist[u] = 1;
	topQ = 0;
	q[topQ++] = v;
	q[topQ++] = u;

	BFS();

	int res = 0;
	rep(i, n) {
		if(dist[i] > k) {
			res++;
		}
	}
		
	return res;
}
 
int main() {

	cin >> n >> k;

	rep(i, n-1) {
		int a, b;
		cin >> a >> b;
		a--;  b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	rep(v, n) {
		ans = min(ans, solveVertex(v));
	}

	rep(v, n) {
		for(auto u : G[v]) {
			if(u > v) {
				ans = min(ans, solveEdge(v, u));
			}
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#define N 500005
using namespace std;

string a;
long long n, ans, i, s[N], l[N], r[N];
int main()
{
	cin >> a;
	n = a.size();
	for (i = 1; i <= n; i++) {
		if (a[i - 1] == '<') l[i] = l[i - 1] + 1;
		else l[i] = 0;
	}
	for (i = n - 1; i >= 0; i--) {
		if (a[i] == '>') r[i] = r[i + 1] + 1;
		else r[i] = 0;
	}
	for (i =0; i <= n; i++) ans += max(l[i], r[i]);
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9092
#include<bits/stdc++.h>                                                                        
using namespace std;
int main()
{
  int r,D,x_2000;
  cin >> r >> D >> x_2000;
  vector<int> x(10);
  for(int i=0; i<10; i++){
    if(i==0){
      x.at(i)=r*x_2000-D;
    }
    else{
      x.at(i)=r*x.at(i-1)-D;
    }
  }
  for(int i=0; i<10; i++){
    cout << x.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int a, b, c, d, e, k; cin >> a >> b >> c >> d >> e >> k;
    if (e - a <= k) cout << "Yay!" << endl;
    else cout << ":(" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#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() {
  int n,p;
  string s;
  cin >> n >> p >> s;
  reverse(s.begin(),s.end());

  if(10%p==0){
    ll ans = 0;
    rep(i,n) if((s[i]-'0')%p==0) ans += n-i;
    cout << ans << endl;
    return 0;
  }

  vector<int> d(n+1);
  int dig = 1;
  rep(i,n){
    int x = (s[i]-'0')*dig;
    x += d[i];
    d[i+1] = x%p;
    dig = dig * 10 % p;
  }

  ll ans = 0;
  vector<int> m(p);
  rep(i,n+1) ans += m[d[i]]++;
  cout << ans << endl;
}


Measured memory_bytes: 1404
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_157
{
    class A
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            WriteLine(n % 2 == 0 ? n / 2 : n / 2 + 1);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

int main(){
	int a;
	cin >> a;
	if (a == 25)cout << "Christmas" << endl;
	if (a == 24)cout << "Christmas Eve" << endl;
	if (a == 23)cout << "Christmas Eve Eve" << endl;
	if (a == 22)cout << "Christmas Eve Eve Eve" << endl;

	return 0;
}

	
	

	

Measured memory_bytes: 256
H,W = map(int, input().split())
A = []
for _ in range(H):
    row = list(input())
    A.append(row)

blacks = []
cnt = 0

for i in range(H):
    for j in range(W):
        a = A[i][j]
        if a == '#':
            cnt += 1
            blacks.append((i,j))

res = 0

DIRS = [(1,0),(-1,0),(0,1),(0,-1)]

while cnt < H*W:
    res += 1
    new_blacks = []
    for black in blacks:
        for dir in DIRS:
            i = black[0]+dir[0]
            j = black[1]+dir[1]
            if i < 0 or i >= H:
                continue
            if j < 0 or j >= W:
                continue
            if A[i][j] == '.':
                new_blacks.append((i,j))
                A[i][j] = '#'
                cnt += 1
    blacks = new_blacks

print(res)

Measured memory_bytes: 125636
#include <stdio.h>
#include <math.h>

int main() {
	int N, A[100000];
	int even,odd,i;

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

	even=0;odd=0;
	for(i=0;i<N;i++){
		if(A[i]%2 == 0){
			even++;
		}else{
			odd++;
		}
	}
	if(odd%2==1){
		printf("NO\n");
	}else{
		printf("YES\n");
	}

}

Measured memory_bytes: 512
import sys
import operator

n, g = map(int, input().split())
cards = [[int(x) for x in sys.stdin.readline().rstrip().split()] for _ in range(g)]

cards.sort(key=operator.itemgetter(0))
lmx = cards[g - 1][0]
cards.sort(key=operator.itemgetter(1))
rmn = min(cards[0][1], n)

print(max(0, rmn - lmx + 1))


Measured memory_bytes: 22800
#include <iostream>
#include <memory>

int main(int argc, char *argv[]) {
  std::string o, e;
  std::cin >> o >> e;
  if (o.size() < e.size())
    std::swap(o, e);
  for (size_t i = 0; i < o.size(); ++i) {
    std::cout << o.at(i);
    if (i != e.size())
      std::cout << e.at(i);
  }
}


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

int main(){
  int N,k=0,l=0;
  cin>>N;
  for(int i=0;i<N;i++){
    int j;
    cin>>j;
    if(j>=k){
      l++;
      k=j;
    }
  }
  cout<<l<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  	string s;	cin >> s;
  	int sd = s.size();
  	bool fct = true;
  	rep(i,sd){
    	if(i%2 == 1){
        	if(s.at(i) != 'L' && s.at(i) != 'U' && s.at(i) != 'D') fct = false;
        }
      	if(i%2 == 0){
        	if(s.at(i) != 'R' && s.at(i) != 'U' && s.at(i) != 'D') fct = false;
        }
    }
  	if(fct) cout << "Yes" << endl;
  	else cout << "No" << endl;
}

Measured memory_bytes: 256