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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};
// h(n, r) = c(n+r-1, r)
struct combination
{
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1)
  {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
    fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
    ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k)
  {
    if (k < 0 || k > n)
    return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main()
{
  string s; cin >> s;
  int n = s.size();
  reverse(ALL(s));
  vector<int> pow_10;
  int a = 1;
  rep(i, n) {
    pow_10.push_back(a);
    a = 10*a%2019;
  }

  vector<ll> div(2020, 0);
  div[0] = 1;
  int now = 0;
  rep(i, n) {
    now += pow_10[i]*(s[i]-'0');
    now %= 2019;
    ++div[now];
  }
  ll ans = 0;
  rep(i, 2020) ans += div[i]*(div[i]-1)/2;
  cout << ans << endl;
}

Measured memory_bytes: 4444
s=input()
s+='T'
x,y=map(int,input().split())
n=len(s)
f=0
d=0
xx=[]
yy=[]
for i in range(n):
    if s[i]=='F':
        f+=1
    else: #=='T'
        if f==0:
            0
        else:
            if d==0:
                xx.append(f)
                f=0
            else:
                yy.append(f)
                f=0
        d=1-d
#print(xx,yy)
def judg(a,b):
    if len(a)==0 and b==0:
        return True
    else:
        dp=set()
        pdp=set()
        for i in a:
            pdp=dp
            if len(pdp)==0:
                pdp.add(i)
                pdp.add(-i)
            else:
                dp=set()
                for j in pdp:
                    dp.add(j-i)
                    dp.add(j+i)
                    #print(dp)
        if b in dp:
            return True
        else:
            return False
    
if s[0]!='T' and len(xx)>0:
    t=xx[0]
    xx.remove(xx[0])
else:
    t=0



if judg(xx,x-t) and judg(yy,y):
    ans='Yes'
else:
    ans='No'
print(ans)
    


Measured memory_bytes: 45788
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

//const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 1'000'000'000'000'000'000ll + 7;
//const i64 inf = 1'000'000'007;

const long double eps = 1e-8;

const i64 MAXN = 1'000 + 5;

i64 T;

i64 n, k;

i64 a[MAXN];

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);
    cin >> n >> k;

    for (i64 i = 0; i < k; i++) {
        i64 c;
        cin >> c;

        for (i64 j = 0; j < c; j++) {
            i64 t;
            cin >> t;

            a[t] += 1;
        }
    }

    i64 c = 0;
    for (i64 i = 1; i <= n; i++) {
        if (!a[i]) {
            c += 1;
        }
    }

    cout << c << endl;

    return 0;
}

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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;
#define MAXN 201010
using namespace std;

vi t(2 * MAXN , 0);

int m;

void modify(int p , int val){
    for(t[p += m] = val ; p > 1 ; p /= 2){
        t[p / 2] = t[p] + t[p ^ 1];
    }
}
 
int sum(int l , int r){//[l , r)
    int res = 0;
    for(l += m , r += m ; l < r ; l /= 2 , r /= 2){
        if(l % 2){
            res += t[l];
            ++l;
        }
        if(r % 2){
            --r;
            res += t[r];
        }
    }
    return res;
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(0); 
	
	int n , k;
	cin >> n >> k;
	vi v(n);
	vector<ll> f(n);
	
	rep(i , n){
		cin >> v[i];
		f[i] = v[i];
		f[i] += i ? f[i - 1] : 0ll;
	}
	
	vector<ll> a(n + 1);
	
	rep(i , n){
		a[i + 1] = f[i] - 1ll * k * (i + 1);
	}

	vector<ll> aa = a;
	SORT(aa);
	
	int nxt = 1;
	map<ll , ll> used;
	
	rep(i , n + 1){
		if(used.find(aa[i]) == used.end()){
			used[aa[i]] = nxt;
			++nxt;
		}
	}
	
	
	ll ans = 0;
	
	m = MAXN - 10;
	
	rep(i , n + 1){
		a[i] = used[a[i]];
	}
	
	rep(i , n + 1){
		ans += sum(1 , a[i] + 1);
		int cur = sum(a[i] , a[i] + 1);
		modify(a[i] , cur + 1);
	}
	cout << ans;
	return 0;
}

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

const double PI = atan2(0, -1);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    double a, b, x;
    cin >> a >> b >> x;
    
    cout << fixed << setprecision(10);
    double s = x / a;
    if (s == a * b)
        cout << 0.0 << '\n';
    else{
        if (s > a * b / 2.0){ // Trapezoid
            double bu = 2.0 * s / a - b;
            double b2 = b - bu;
            cout << atan(b2 / a) * 180.0 / PI << '\n';
        }
        else{ // triangle
            double a2 = s * 2.0 / b;
            cout << atan(b / a2) * 180.0 / PI << '\n';
        }
        
    }

    return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/dp/tasks/dp_f

#include <bits/stdc++.h>
using namespace std;
typedef std::pair<int, int> ipair;
#define int long long
#define pb push_back
#define ff first
#define INF INT_MAX
#define ss second
#define fr(i, j, a) for (int i = j; i < a; i++)
#define cnt_ones(x) __builtin_popcount(x)
#define all(x) x.begin(), x.end()
#define sz size()
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<ipair>
#define mp make_pair
#define mod 1000000007
#define IOS                                                                    \
  std::ios::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
vector<vector<int>> g;
vector<int> dp;
int n, m;
int dfs(int u) {
  if (dp[u])
    return dp[u];
  for (int v : g[u]) {
    dp[v] = max(dp[v], dfs(v));
    dp[u] = max(dp[u], 1 + dp[v]);
  }
  if (!dp[u])
    dp[u] = 1;
  return 1;
}
void init() {
  cin >> n >> m;
  dp = vector<int>(n, 0);
  g.resize(n);
  while (m--) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    g[a].pb(b);
  }
  int mx = 0;
  for (int i = 0; i < n; i++) {
    dp[i] = max(dp[i], dfs(i));
    mx = max(mx, dp[i]);
  }
  cout << mx - 1 << endl;
}
int32_t main() {
  IOS;
  init();
  return 0;
}


Measured memory_bytes: 11476
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <complex>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,-1,0,1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
    if(a>b){
        a = b; return true;
    }
    else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
    if(a<b){
        a = b; return true;
    }
    else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
    cout << a << " " << b << " " << c << "\n";
}
const ll mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    ll n; cin >> n;
    vl a(n); rep(i,n) cin >> a[i];
    ll s = 0;
    ll minus = n * (n+1) / 2;
    rep(i,n) s += a[i];
    if(s % minus != 0) puts("NO");
    else{
        ll t = s / minus;
        ll cnt = 0;
        rep(i,n){
            ll b = a[i] + t;
            if(b < a[(i+1)%n] || (b - a[(i+1)%n]) % n != 0){
                puts("NO");
                return 0;
            }
            cnt += (b - a[(i+1)%n]) / n;
        }
        if(cnt == t) puts("YES");
        else puts("NO");
    }
}

Measured memory_bytes: 4056
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))

from collections import Counter

n = ii()
A = iil()
di = Counter(A)
A.sort()

ans = 0
l = set()
for item in A:
    if di[item] > 1:
        if item not in l:
            for i in range(1,1000000//item+1):
                l.add(item*i)
        continue
    if item not in l:
        for i in range(1,1000000//item+1):
            l.add(item*i)
        ans += 1
print(ans)


Measured memory_bytes: 103564
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        N: usize,
        A: usize,
        XX: [usize; N],
    }

    // 1枚も使わない場合を考慮するために先頭に0を追加しておく
    let mut X = vec![0;1];
    X.extend(XX);

    // dp[n][k][s] : n枚目までからk枚選んで合計をsにする場合の数
    let mut dp = vec![vec![vec![0; 2501]; N+1]; N+1];
    dp[0][0][0] = 1;

    // dpテーブルの更新
    for n in 1..N+1{
        for k in 0..n+1{
            for s in 0..50*k+1{
                // 配列外参照を防止、この場合はn枚目を使わないパターン
                if s < X[n]{
                    dp[n][k][s] = dp[n-1][k][s];
                // n枚目を使わない場合、使う場合で場合分け
                }else if s >= X[n] && k >= 1{
                    dp[n][k][s] = dp[n-1][k][s] + dp[n-1][k-1][s-X[n]];
                }
            }
        }
    }

    let mut Ans = 0 as u64;
    for i in 1..N+1{
        Ans += dp[N][i][A*i];
    }
    println!("{}",Ans);
}

Measured memory_bytes: 67836
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

#define v(type) vector<type>
#define p(type1, type2) pair<type1 , type2>
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

void solve() {
    int a , b , x;
    cin>>a>>b>>x;
    if(a == 0){
        cout<<b / x + 1<<endl;
    }else {
        cout<<(b / x) - ((a-1) / x)<<endl;
    }
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;
#define N 2009
#define LL long long
#define INF 0x7fffffff
#define mymin(x,y) (x>=y?y:x)
#define mymax(x,y) (x>=y?x:y)
int input[N], tong[N], tong2[N], two[N][N];
int main() {
	std::ios::sync_with_stdio(0); std::cin.tie(0);
	memset(tong, 0, sizeof(tong));
	memset(tong2, 0, sizeof(tong2));
	memset(two, 0, sizeof(two));
	int n, a, index = 0, ans = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a;
		input[index++] = a;
		tong[a]++;
		tong2[a] = 1;
	}
	for (int i = 1; i < N; i++) {
		//tong[i] += tong[i - 1];
		tong[i] += tong[i - 1];
	}
	sort(input, input + index);
	int decr = 1;
	for (int j = input[0]; j < N; j++) {
		two[0][j] = tong[j] - tong[input[0] - 1] - decr;
	}
	for (int i = 1; i <= index; i++) {
		if (input[i] == input[i - 1])
			decr++;
		else
			decr = 1;
		for (int j = input[i]; j < N; j++) {
			two[i][j] = tong[j] - tong[input[i] - 1] - decr;
		}
	}
	for (int i = 0; i < index; i++) {
		for (int j = i + 1; j < index - 1; j++) {
			ans += two[j][input[i] + input[j] - 1];
		}
	}
	cout << ans;
	return 0;
}

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

typedef pair <int, int> ii;

const int Maxn = 1005;

int n;
int B[Maxn];
vector <ii> neigh[Maxn][Maxn];
int in[Maxn][Maxn];
int was[Maxn];
int nxt[Maxn][Maxn];
int res;

ii Get(int a, int b) { return a < b? ii(a, b): ii(b, a); }

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < n - 1; j++) {
            scanf("%d", &B[j]);
            if (j) {
                ii a = Get(i, B[j - 1]), b = Get(i, B[j]);
                neigh[a.first][a.second].push_back(b);
                in[b.first][b.second]++;
            }
        }
    }
    vector <ii> Q;
    for (int i = 1; i <= n; i++)
        for (int j = i + 1; j <= n; j++) if (!in[i][j])
            Q.push_back(ii(i, j));
    for (int i = 0; i < Q.size(); i++) {
        ii p = Q[i];
        int d = max(nxt[p.first][p.second], max(was[p.first] + 1, was[p.second] + 1));
        res = max(res, d);
        was[p.first] = was[p.second] = d;
        for (int j = 0; j < neigh[p.first][p.second].size(); j++) {
            ii u = neigh[p.first][p.second][j];
            nxt[u.first][u.second] = max(nxt[u.first][u.second], d + 1);
            if (--in[u.first][u.second] == 0) Q.push_back(u);
        }
    }
    if (Q.size() != n * (n - 1) / 2) printf("-1\n");
    else printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 52976
s = input()
n = len(s) - 1  # スキマの数
sum_ = 0
keep = 0
for i in range(2**n):  # +かつなげるか
    p_or_no = [""] * n
    for j in range(n):
        if ((i >> j) & 1) == 1:
            p_or_no[n-1-j] = "+"

    for k in range(n):
        if p_or_no[k] == "+":
            sum_ += int(s[k]) + keep
            keep = 0
        else:
            keep = int(s[k]) * 10 + keep * 10
        if k == n-1:
            sum_ += int(s[-1]) + keep
            keep = 0
if len(s) == 1:
    sum_ = int(s)
print(sum_)

Measured memory_bytes: 40176
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::iter;
#[allow(unused_imports)]
use std::mem::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::usize;

#[allow(unused_macros)]
macro_rules! read_cols {
    ($($t:ty),+) => {{
        let mut line = String::new();
        stdin().read_line(&mut line).unwrap();

        let mut it = line.trim()
            .split_whitespace();

        ($(
            it.next().unwrap().parse::<$t>().ok().unwrap()
        ),+)
    }}
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();
    line.trim().to_string().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();

    line.trim()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let (n, m) = read_cols!(usize, usize);
    let mut a = read_vec::<i64>();

    assert_eq!(a.len(), m);

    a.sort();

    let mut dp = vec![None; 10001];
    dp[0] = Some(String::new());
    let result = a.iter().fold(dp, |mut dp, &aa| {
        let cost: usize = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6][aa as usize];
        for i in cost..10001 {
            let next = match dp[i - cost] {
                None => dp[i].clone(),
                Some(ref prev) => {
                    let candidate = aa.to_string() + prev;
                    match dp[i] {
                        None => Some(candidate),
                        Some(ref old) => {
                            if old.len() < candidate.len() {
                                Some(candidate)
                            } else if old.len() > candidate.len() {
                                Some(old.clone())
                            } else {
                                Some(max(old.clone(), candidate))
                            }
                        }
                    }
                }
            };
            dp[i] = next;
        }
        dp
    });
    let ans = &result[n];

    println!("{}", ans.as_ref().unwrap());
}


Measured memory_bytes: 30972
#include <stdio.h>

using namespace std;

int main(){
	int a,b;
	while(true){
		scanf("%d %d",&a,&b);
		if(a == 0 && b == 0) break;
		if(a > b) 
		printf("%d %d\n",b,a);
		else{
			printf("%d %d\n",a,b);
		}
	}
}


Measured memory_bytes: 2728
#include <bits/stdc++.h>
#define int long long
#define P(x) {if (debug) cout << x << endl;}
#define H(x) P(#x << ": " << (x))
#define FR(i,a,b) for (int i=(a); i<(b); i++)
#define F(i,n) FR(i,0,n)
#define DR(i,a,b) for (int i=(b); i-->(a);)
#define D(i,n) DR(i,0,n)
#define S(s) (int)(s).size()
#define ALL(v) v.begin(), v.end()
#define MI(a,v) a = min(a,v)
#define MA(a,v) a = max(a,v)
#define V vector
#define pb push_back
#define mt make_tuple
using namespace std;
template<class T> ostream& operator<<(ostream& os, V<T> v) {
    F(i,S(v)) os<<(i?" ":"")<<v[i]; return os;}
const bool debug = 1;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin>>n;
    V<int> a(n);
    F(i,n) cin>>a[i];
    sort(ALL(a));
    int best = a[0];
    for (int x : a) {
        if (abs(a.back()-2*x) < abs(a.back()-2*best))
            best = x;
    }
    cout<<a.back()<<" "<<best<<"\n";
}

Measured memory_bytes: 1024
N = int(input())

cnt = 0
for _ in range(N):
    D1, D2 = map(int, input().split())
    if D1 == D2:
        cnt += 1
        if cnt == 3:
            print('Yes')
            break
    else:
        cnt = 0

if cnt < 3:
    print('No')

Measured memory_bytes: 9044
/*
author: Apoorv Singh
*/

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

typedef vector <int> vi;
typedef vector <long long> vl;
typedef pair <int, int> pii;
typedef pair <long long, long long> pll;
#define ll long long
#define pb push_back   
#define all(c) c.begin(), c.end()
#define watch(x) cout << (#x) << " " << (x) << endl;
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second

ll modulo = 1e9 + 7;

template <class X>

void printarr(X arr[], int n)
{
    for (int i = 0; i < n; ++i)
        cout << arr[i] << " ";
    cout << endl;
}

ll fpow(ll a, ll n)
{
    ll ans = 1;
    while (n)
    {
        if (n&1)
            ans = (ans * a)%modulo;
        a = (a*a)%modulo;
        n = n >> 1;
    }
    return ans;
}

/*
const int M = 1e6 + 10;
int composite[M] = {0};

void sieve()
{
    FOR(i,2,M)
    {
        if (!composite[i])
        {
            for (int j = 2*i; j < M; j += i)
                composite[j] = max(composite[j], i);
        }
    }
}
*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    ll dp[n];
    FOR(i,0,n)
    	dp[i] = LLONG_MAX;
    dp[0] = 0;
    int arr[n];
    FOR(i,0,n)
    	cin >> arr[i];
    FOR(i,0,n)
    {
    	if (i+1 < n)
    		dp[i+1] = min(dp[i+1], abs(arr[i+1]-arr[i])+dp[i]);
    	if (i+2 < n)
    		dp[i+2] = min(dp[i+2], abs(arr[i+2]-arr[i])+dp[i]);
    }
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;


int main()
{
	char a;
	cin >> a;
	string v = "aiueo";
	if (v.find(a) < 5) {
		cout << "vowel" << endl;
	}
	else
		cout << "consonant" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;
using ll = long long;

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

int main()
{
    int n;
    long long h[100005];
    
    cin >> n;
    
    rep(i,n){
        cin >> h[i];
    }
    
    int ans = 0;
    int num = 0;
    
    rep(i,n-1){
        if (h[i] >= h[i+1]){
            num++;
        }
        else {
            ans = max(ans,num);
            num = 0;
        }
    }
    ans = max(ans,num);
    
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vl a(n);
	cin>>a;
	multiset<ll> s;
	rep(i,n){
		auto it=s.lower_bound(a[i]);
		if(it==s.begin()){
			s.insert(a[i]);
		}else{
			--it;
			ll val=*it;
			s.erase(it);
			s.insert(a[i]);
		}
		// for(auto&e:s)cout<<e<<",";cout<<endl;
	}
	puta(s.size());
	return 0;
}

Measured memory_bytes: 5760
#include<stdio.h>

int search(int *,int,int);

int main(){
  int S_num[10000];
  int T_num;
  int i;
  int num_in_1;
  int num_in_2;
  int key;
  int count=0;

  scanf("%d",&num_in_1);

  for(i=0;i<num_in_1;i++){
    scanf("%d",&S_num[i]);
  }
 
  scanf("%d",&num_in_2);
  
  for(i=0;i<num_in_2;i++){
    scanf("%d",&key);
    if(search(S_num,num_in_1,key)==1){
      count++;
    }
  }

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

int search(int S_num[],int num_in,int key){
  int i=0;

  S_num[num_in]=key;

  while(S_num[i]!=key){
    i++;
  }

  if(i==num_in){
    return 0;
  }else{
    return 1;
  }
}

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

const int N = 1e6 + 7;
struct E { int v, ne, dis; } e[N];
int dis[N], head[N], cnt;
bool inq[N];

inline void add(int u, int v, int dis) {
	e[++cnt].v = v; e[cnt].ne = head[u]; e[cnt].dis= dis; head[u] = cnt;
}

int main() {
	int k;
	scanf("%d", &k);
	for (int i = 0; i < k; i++) {
		add(i, (i + 1) % k, 1);
		add(i, i * 10 % k, 0);
	}
	memset(dis, 0x3f, sizeof(dis));
	dis[1] = 0;
	queue<int> que;
	que.push(1);
	inq[1] = 1;
	while (!que.empty()) {
		int u = que.front(); que.pop();
		inq[u] = 0;
		for (int i = head[u]; i; i = e[i].ne) {
			int v = e[i].v;
			if (dis[v] > dis[u] + e[i].dis) {
				dis[v] = dis[u] + e[i].dis;
				if (!inq[v]) {
					inq[v] = 1;
					que.push(v);
				}
			}
		}
	}
	printf("%d\n", 1 + dis[0]);
	return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int N; cin >> N;
    vector<ll> a(N+1);
    for(int i=1; i<=N; i++) cin >> a[i];

    ll inf = (1LL<<58);
    ll dp[N+1][2];
    dp[1][0] = a[1]+a[2];
    dp[1][1] = -dp[1][0];

    for(int i=2; i<=N-1; i++){
        dp[i][0] = max(dp[i-1][0]+a[i+1], dp[i-1][1]+a[i+1]);
        dp[i][1] = max(dp[i-1][0]-2*a[i]-a[i+1], dp[i-1][1]+2*a[i]-a[i+1]);
    }

    cout << max(dp[N-1][0], dp[N-1][1]) << endl;

    // for(int i=0; i<=N-1; i++) printf("%5lld ", dp[i][0]);
    // cout << endl;
    // for(int i=0; i<=N-1; i++) printf("%5lld ", dp[i][1]);
    // cout << endl;
    
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <memory.h>

int main(void) {
	int i, j, n, m;
	int x, y, d;
	char t;
	int p_x, p_y;
	int table[21][21];
	
	while(1) {
		scanf("%d\n", &n);
		if(n==0) break;
		memset((void*)table, 0x00, sizeof(table));
		
		for(i=0;i<n;i++) {
			scanf("%d %d\n", &x, &y);
			table[y][x] = 1;
		}
		
		p_x = p_y = 10;
		table[p_y][p_x] = 0;
		scanf("%d\n", &m);
		for(i=0;i<m;i++) {
			scanf("%c %d\n", &t, &d);
			switch(t) {
				case 'N':
					for(j=0;j<d;j++) {
						table[++p_y][p_x] = 0;
					}
				break;
				case 'S':
					for(j=0;j<d;j++) {
						table[--p_y][p_x] = 0;
					}
				break;
				case 'W':
					for(j=0;j<d;j++) {
						table[p_y][--p_x] = 0;
					}
				break;
				case 'E':
					for(j=0;j<d;j++) {
						table[p_y][++p_x] = 0;
					}
				break;
				default:
				break;
			}
		}
		
		m = 0;
		for(i=0;i<21;i++) {
			for(j=0;j<21;j++) {
				if(table[i][j] != 0) {
					m = 1;
					break;
				}
			}
			if(m==1) break;
		}

		if(m==1) {
			printf("No\n");
		} else {
			printf("Yes\n");
		}
		
	}
	
	return 0;
}

Measured memory_bytes: 588
#include <stdio.h>

void prim(int,int);

#define INF 10000
#define WHITE 0
#define BLACK 1
#define NIL -1


int d[100],color[100],w[100][100];

int main(){

  int g,r,i,j,answer=0;

  scanf("%d",&g);

  for(i=0;i<g;i++){
    for(j=0;j<g;j++){

      scanf("%d",&w[i][j]);
     
    }
  }

  //printf("wa-i\n");
  
  r=0;

   for(i=0;i<g;i++){
    for(j=0;j<g;j++){

      if(w[i][j]==-1) w[i][j]=INF;
     
    }
  }
  
  prim(g,r);

  for(i=0;i<g;i++){

    answer += d[i];

  }

  printf("%d\n",answer);

  return 0;
}

void prim(int G,int r){

  int u,mincost,i,pi[100],v,count=0;

  for(u=0;u<G;u++){

    d[u] = INF;
    pi[u] = NIL;
    color[u] = WHITE;
  }

  d[r] = 0;

  while(1){

    //printf("wa-i2\n");

    mincost = INF;

    for(i=0;i<G;i++){

      if(color[i] != BLACK && d[i] < mincost){

	mincost = d[i];
	u = i;

      }
    }

    if(mincost == INF)break;

    color[u] = BLACK;
    count++;

    for(v=0;v<G;v++){

      if(color[v] != BLACK && w[u][v] < d[v]){

	pi[v] = u;
	d[v] = w[u][v];

      }
    }

    if(count == G)break;
    

  }
}

Measured memory_bytes: 640
N = int(input())
count = 0
COUNT = 0
A = [int(i) for i in input().split()]
while 1:
  for i in range(N):
    if A[i]%2==0:
      A[i]/=2
      count+=1
  if count == N:
    COUNT+=1
    count = 0
  else:
    break
print(COUNT)

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Optional;

public class Main {

	public static void main(String[] args) {		

		try(BufferedReader br = new BufferedReader(new
		        InputStreamReader(System.in))) {
			String[] input = br.readLine().split("\\s");
			Optional<String> N = Optional.ofNullable(input[0]);
			Optional<String> K = Optional.ofNullable(input[1]);
			if(!K.isPresent()) {
				K = Optional.of(br.readLine());
			}
			
			int output = (Integer.parseInt(N.get()) - Integer.parseInt(K.get())) + 1;
			
			System.out.println(output);
		}catch(Exception e) {
			e.printStackTrace();
		}
	}

}


Measured memory_bytes: 21204
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <queue>
#include <array>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct TEMP_OMAZINAI_ { TEMP_OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } TEMP__omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void TEMP_INPUT_IMPL_() {};
template <class T, class... Args> void TEMP_INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; TEMP_INPUT_IMPL_(args...); }
void TEMP_OUTPUT_IMPL_() {};
template <class T, class... Args> void TEMP_OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); TEMP_OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; TEMP_INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define rsort_v(v) std::sort(v.rbegin(), v.rend())
#define unique_v(v) v.erase(std::unique(v.begin(), v.end()), v.end()) //必ずソート後に実行
#define out(...) (TEMP_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))
 
 // ^^^ Template ^^^ //

// 補足説明: loop(i, W) -> インデックス i を 区間 [0, W) でループ
// 変数名 _ は、規格上使うのは望ましくないが、使わない変数であることを明示するために用いている

int main() {
	in(ll, H, W, K);
	// DP遷移の係数
	// ここがarrayなのは初期化の関係上便利だから
	// 境界の処理が面倒なので少し多めに取る
	vector<array<ll, 3>> table(W+2); // [<- , V , ->]
	//bit全探索
	loop(i, 1ll << (W-1)){
		// 隣接するビットが立っていないことをチェック
		{
			ll t = i;
			bool valid = true;
			loop(_, W-1){
				if((t&1) && (t&2))
					valid = false;
				t >>= 1;
			}
			// だめならスキップ
			if(!valid) continue;
		}
		// DP遷移の係数に入れる
		loop(k, W){
			// iのkビット目が1なら
			// (ただし、一番右のやつだと必ず偽 (右に行けないのでそれはそう))
			if(i & (1<<k)){
				// 今の列は右に行く
				++table[k][2];
				// 次の列で本来下に行くはずだったのを左に行くように変更
				++table[k+1][0];
				--table[k+1][1];
			} else {
				// 今の列は下に行く
				++table[k][1];
			}
		}
	}
	// 長さWで0埋めされた配列
	vector<ll> current(W, 0);
	current[0] = 1; // 最初にスタート地点にいるのは1通り
	// DPする
	loop(_, H){
		vector<ll> next(W, 0);
		// 遷移する
		loop(i, W){
			if(i>0)   next[i-1] += current[i] * table[i][0];
			          next[ i ] += current[i] * table[i][1];
			if(i<W-1) next[i+1] += current[i] * table[i][2];
		}
		// MODを取る
		loop(i, W)
			next[i] %= 1000000007;
		// 遷移結果を新しいcurrentにする
		current = next;
	}
	cout << current[K-1] << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
double ans,x,y;
int a[15],i,b,c,d,t=0,f=0,own;
while(scanf("%d %d %d\n",&b,&c,&d)!=EOF){
for(i=1;i<11;i++){
a[i]=0;
}
a[b]=1,a[c]=1,a[d]=1;
own=b+c;
for(i=1;i<11;i++){
if(a[i]==0){
if(own+i<=20){
t++;
}
else{
f++;
}
}
}
x=t,y=f;
if(x/(x+y)>=0.5){
printf("YES\n");
}
else{
printf("NO\n");
}
t=0,f=0;
}
return 0;
}


Measured memory_bytes: 2076
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(int X = 0; X < N; X++)
#define pback push_back
#define mpair make_pair
#define MODN 1000000007

using namespace std;

int main(){

    //後ろ半分はaiの値そのまま、後ろから順にどん欲に求めていけるはず

    int n;
    cin >> n;

    vector<int> a;
    vector<int> v;

    rep(i,n){

        int tmp;
        cin >> tmp;
        a.pback(tmp);
        if(i >= n / 2){
            v.pback(tmp);
        }else{
            v.pback(0);
        }
    }

    int index = n / 2 - 1;

    for(int i = index; i >= 0; i--){

        int sum = 0;
        int boxn = i + 1;

        for(int j = boxn * 2 - 1; j < n; j = j + boxn){
            sum = sum + v[j];
        }

        if(a[i] - (sum % 2) != 0){
            v[i] = 1;
        }

    }

    vector<int> ans;

    rep(i,n){
        if(v[i] == 1) ans.pback(i + 1);
    }

    cout << ans.size() << endl;

    rep(i,ans.size()){
        cout << ans[i] << " ";
    }

    cout << endl;
    
    return 0;
}

Measured memory_bytes: 3564
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
#define LL long long

int n, m, k;
int b[10005];
int a[10005];

int main()
{
    while(~scanf("%d %d", &n, &m))
    {
        memset(b, 0, sizeof(b));
        memset(a, 0, sizeof(a));
        scanf("%d", &k);
        for(int i = 1; i <= k; ++i)
            scanf("%d", &a[i]);
        int z = 1;
        for(int i = 0; i < n * m; ++i)
        {
            int j;
            for(j = i; j < i + a[z]; ++j)
                *(b + j) = z;
            z++;
            i = j - 1;
        }
        //for(int i = 0; i < n * m; ++i) cout << b[i] << endl;
        int t[105][105], cnts = 0;;
        for(int i = 0; i < n; ++i)
            for(int j = 0; j < m; ++j)
                t[i][j] = b[cnts++];
        for(int i = 1; i < n; i += 2)
            for(int j = 0; j < m / 2; ++j)
                swap(t[i][j], t[i][m - 1 - j]);
        for(int i = 0; i < n; ++i)
        {
            printf("%d", t[i][0]);
            for(int j = 1; j < m; ++j)
                printf(" %d", t[i][j]);
            printf("\n");
        }
    }
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define reg register
#define ll long long
inline ll read()
{
	ll x=0,w=0;char ch=getchar();
	while(!isdigit(ch))w|=ch=='-',ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w?-x:x;
}
char s[1000],t[1000];
int main()
{
    scanf("%s%s",s,t);
    printf("%s%s",t,s);
	return 0;
}


Measured memory_bytes: 256
//

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n;cin>>n;
    vector<int>t(1000000,0);
    rep(i,1,100){
        rep(j,1,100){
            rep(k,1,100){
                t[i*i+j*j+k*k+i*j+j*k+k*i]++;
            }
        }
    }
    rep(i,1,n+1){
        cout<<t[i]<<nnn;
    }
    return 0;
}

Measured memory_bytes: 11020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 998244353;
int main(){
	int n,k;
	cin >> n >> k;

	vector<ll> dp(n+1,0);
	vector<ll> accum(n+1,0);

	vector<int> l(k);
	vector<int> r(k);

	for(int i = 0;i < k;i++){
		cin >> l[i] >> r[i];
	}

	dp[1] = 1;
	accum[1] = 1;
	for(int i = 2;i <= n;i++){
		for(int j = 0;j < k;j++){
			dp[i] += (accum[max(0,i-l[j])] - accum[max(0,i-r[j]-1)] + MOD) % MOD;
			dp[i] %= MOD;
		}
		accum[i] = (dp[i] + accum[i-1]) % MOD;
	}

	cout << dp[n] << endl;
}


Measured memory_bytes: 6416
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=1e5+10;
int gcd(int n,int m)
{
	if(n==0)
		return m;
	else
		return gcd(m%n,n);
}
int dp[N][4];
int a[N][4];
int n;
int32_t main()
{
	IOS;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=3;j++)
			cin>>a[i][j];
	}
	dp[1][1]=a[1][1];
	dp[1][2]=a[1][2];
	dp[1][3]=a[1][3];
	for(int i=2;i<=n;i++)
	{
		for(int j=1;j<=3;j++)
		{
			if(j==1)
			{
				dp[i][j]=max(dp[i-1][2],dp[i-1][3])+a[i][j];
			}
			else if(j==2)
			{
				dp[i][j]=max(dp[i-1][1],dp[i-1][3])+a[i][j];
			}
			else
			{
				dp[i][j]=max(dp[i-1][1],dp[i-1][2])+a[i][j];
			}
		}
	}
	cout<<max({dp[n][1],dp[n][2],dp[n][3]})<<endl;

}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
map<long long, int> fact(long long n){
  map<long long, int> rtn;
  for(long long i = 2; i * i <= n; ++i){
    while(n % i == 0){
      rtn[i]++;
      n /= i;
    }
  }
  if(n != 1) rtn[n]++;
  return rtn;
}
int main(){
  long long n, p; cin >> n >> p;
  map<long long, int> mp = fact(p);
  long long ans = 1;
  for(auto m: mp){
    for(int i = 0; i < m.second / n; ++i){
      ans *= m.first;   
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define ushi int
#define tapu main
#define nichia (
#define kunn void
#define wara )

using ll = long long;

const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main(){

	string s;
	scans(s);
	if (s.length() == 3)reverse(all(s));
	prints(s);

	Please AC;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args)  {
    int N = sc.nextInt();
    int T = sc.nextInt();
    int min = Integer.MAX_VALUE;
    int diff = 0;
    int[] A = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
      min = Math.min(min, A[i]);
      diff = Math.max(diff, A[i] - min);
    }
    min = Integer.MAX_VALUE;
    int max = 0;
    int minCount = 0;
    int maxCount = 0;
    int ans = 0;
    for (int i = 0; i < N; i++) {
      if (A[i] < min) {
        ans += Math.min(minCount, maxCount);
        min = A[i];
        minCount = 1;
        maxCount = 0;
      } else if (A[i] == min) {
        ++minCount;
      }
      if (A[i] == min + diff) {
        ++maxCount;
      }
    }
    ans += Math.min(minCount, maxCount);
    System.out.println(ans);
  }
}


Measured memory_bytes: 33144
#!/usr/bin/env python3
import sys
import numpy as np

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(H: int, W: int, s: "List[str]"):
    ans = YES
    for i in range(1, H-1):
        for j in range(1, W-1):
            if s[i][j] == "#" and s[i-1][j] == s[i+1][j] == s[i][j-1] == s[i][j+1] == ".":
                ans = NO
    print(ans)

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    H, W = map(int,input().split())  # type: int
    s = [input() for _ in range(H)]  # type: "List[str]"
    solve(H, W, s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 13200
using System;
 
public class AtCoder
{
    public static void Main()
    {
        int n;
        n = int.Parse(Console.ReadLine().Trim());
        string[] s;
        s = Console.ReadLine().Trim().Split(' ');
        int[] a = new int[n];
        int avg = 0;
        for (int i = 0; i < n; i++)
        {
            a[i] = n*int.Parse(s[i]);
            avg = avg + a[i];
        }
        avg = avg / n;
        int m,k;
        int ans = -1;
        m = 10000000;
        for (int i = 0; i < n; i++)
        {
            k = avg - a[i];
            if (k < 0) k = -k;
            if(k<m){
              ans = i;
              m = k;
            }
            
        }
 
 
            Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 100000000.0
#define EPS 1e-10
#define MOD 1000000007
using namespace std;
typedef pair<double,int> P;

int n, m;
int s, g;
double dp[40*900+30*30+30];
vector<P> e[40*900+30*30+30];

void solve(){
	cin >> s >> g;
	s--; g--;
	rep(i,40*900+30*30+30){
		dp[i] = INF;
		e[i].clear();
	}
	rep(i,m){
		int x, y, c;
		double d;
		cin >> x >> y >> d >> c;
		x--; y--;
		for(int j = 1; j <= c; j++) rep(k,n){
			if(k == y) continue;
			e[j*900+k*30+x].push_back(P(d/j,j*900+x*30+y));
			e[j*900+k*30+x].push_back(P(d/j,(j+1)*900+x*30+y));
			e[j*900+k*30+x].push_back(P(d/j,(j-1)*900+x*30+y));
		}
		for(int j = 1; j <= c; j++) rep(k,n){
			if(k == x) continue;
			e[j*900+k*30+y].push_back(P(d/j,j*900+y*30+x));
			e[j*900+k*30+y].push_back(P(d/j,(j+1)*900+y*30+x));
			e[j*900+k*30+y].push_back(P(d/j,(j-1)*900+y*30+x));
		}
	}
	priority_queue<P, vector<P>, greater<P> > que;
	que.push(P(0.0,1*900+s*30+s));
	dp[1*900+s*30+s] = 0.0;
	while(true){
		if(que.size() == 0) break;
		P q = que.top();
		que.pop();
		if(q.first > dp[q.second]) continue;
		rep(i,e[q.second].size()){
			P p = e[q.second][i];
			if(dp[p.second] > q.first+p.first){
				dp[p.second] = q.first+p.first;
				que.push(P(dp[p.second],p.second));
			}
		}
	}
	double ans = INF;
	rep(i,n) ans = min(ans,dp[0*900+i*30+g]);
	if(ans == INF) puts("unreachable");
	else printf("%.9f\n",ans);
}

int main(){
	while(cin >> n >> m){
		if(n == 0 && m == 0) break;
		solve();
	}
}

Measured memory_bytes: 59084
N = int(input())
a = [list(map(int,input().split())) for i in range(N)]
d = 0
for i in range(N-1):
    for j in range(i+1,N):
        d += ((a[i][0]-a[j][0])**2 + (a[i][1]-a[j][1])**2)**(1/2)
print(2*d/N)

Measured memory_bytes: 9360