akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = [int(x) for x in input().split()]

def gcd(x, y):
    #print('gcd({0},{1})'.format(x,y))
    if (y==0):
        return x
    else:
        return gcd(y, x%y)

def gcd_left(i):
    #print('gcd_left({0})'.format(i))

    if i<=-1:
        return 0
    else:
        if l[i]:
            return gcd(gcd_left(i-1), a[i])
        else:
            l[i] = gcd( gcd_left(i-1), gcd_right(i+1))


def gcd_right(i):
    #print('gcd_left({0})'.format(i))
    
    if i>=n:
        return 0
    else:
        return gcd( a[i], gcd_right(i+1))

def gcd_left_update(ls, i):
    #print('gcd_left({0})'.format(i))

    if i<0:
        return 0
    elif i==0:
        return a[i]
    else:        
        return gcd(ls[i-1], a[i])


def gcd_right_update(ls, i):
    #print('gcd_right({0})'.format(i))
    
    if i>=n:
        return 0
    elif i==n-1:
        return a[i]
    else:
        return gcd( a[i], ls[i+1])

def gcd_excepts(i):
    #print('gcd_excepts({0})'.format(i))
    return gcd( gcd_left(i-1), gcd_right(i+1))

def gcd_excepts2(i):
    #print('gcd_excepts2({0})'.format(i))
    left = 0
    right = 0
    if i-1<0:
        left = 0
    else:
        left = l[i-1]
    
    if i+1>=n:
        right = 0
    else:
        right = r[i+1]
        
    return gcd( left, right )

l = [None for i in range(n)]
for i in range(n):
    l[i] = gcd_left_update(l,i)

r = [None for i in range(n)]
for i in reversed(range(n)):
    r [i] = gcd_right_update(r,i)
    
m = [gcd_excepts2(i) for i in range(n)]

print(max(m))

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

int main(void) {
	int N, M, K;
	cin >> N >> M >> K;

	for (int p = 0; p <= N; ++p) {
		for (int q = 0; q <= M; ++q) {
			int bk = p * M + q * N - 2 * p * q;
			if (bk == K) {
				cout << "Yes\n";
				return 0;
			}
		}
	}

	cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数の個数*/int divisor_number(int n){auto p = prime_factor(n); int res = 1; for(auto x:p)res*=(x.second+1); return res;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n,a; cin >> n >> a;
    out(max(n*n-a,0LL));

    return 0;
}

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

int main() {
  ll x, y;
  cin >> x >> y;

  ll ans = 0;

  if (abs(x) > abs(y)) {
    if (x > 0) ans++;
    ans += abs(x) - abs(y);
    if (y > 0) ans++;
  } else if (abs(x) < abs(y)) {
    if (x < 0) ans++;
    ans += abs(y) - abs(x);
    if (y < 0) ans++;
  } else if (abs(x) == abs(y)) {
    if (x != y) ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3568
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

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

	int n;
	scanf("%d", &n);
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		int d = 0;
		for (int tmp = i; tmp > 0; tmp /= 10) d++;
		if (d%2) ans++;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-14 05:52:41
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  vector<int64> a(n); cin >> a;

  for (int i = 0; i < n; ++i) {
    a[i] -= (i + 1);
  }

  vector<int64> b = a;
  sort(all(b));
  debug(b, b[n / 2]);

  int64 ans = 0;

  for (int i = 0; i < n; ++i) {
    ans += abs(a[i] - b[n / 2]);
  }

  cout << ans << endl;

  return 0;
}

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

template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif

#define fast_cin() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 1000000
#define ll long long
#define db double
#define str string
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Forrev(i,s,e) for (ll i=(s); i>=(e); i--)
#define all(v) v.begin(),v.end()

#define vll vector<ll>
#define vs vector<string>
#define mapll map<ll,ll>
#define pll pair<ll,ll>
#define initialise(a, x) memset(a, x, sizeof(a))
#define maxheap priority_queue<ll>
#define minheap priority_queue<ll,vector<ll> ,greater<ll>>

#define ff first
#define ss second
#define endl "\n"
#define mp make_pair
const ll mod=1e9 + 7;

ll takemod(ll a) {
    return ((a%mod)+mod)%mod;
}

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

ll fast_exp(ll base, ll expo) {
    ll res=1;
    while(expo>0) {
        if(expo&1) res=(res*base)%mod;
        base=(base*base)%mod;
        expo>>=1;}
    return res;
}

ll modinv(ll a) {
    return takemod(fast_exp(takemod(a), mod-2));
}

void solve()
{
    ll n,k;
    cin>>n>>k;

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

    For(i,0,k)
    {
        ll size1;
        cin>>size1;
        For(j,0,size1)
        {
            ll temp;
            cin>>temp;
            arr[temp]++;
        }
    }

    ll ans=0;
    For(i,1,n+1)
    {
        if(arr[i]==0)
            ans++;
    }
    cout<<ans<<endl;
}

signed main() 
{
    fast_cin();
    // #ifndef ONLINE_JUDGE
    // freopen("C:/IO/in.txt", "r", stdin);
    // freopen("C:/IO/out.txt", "w", stdout);
    // #endif
    
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    
    
    return 0;    
}

Measured memory_bytes: 3672
#include<stdio.h>

int main(){
    int n;
    scanf("%d", &n);
    long long int t[n], a[n];
    for(int i=0; i<n; i++){
        scanf("%lld%lld", &t[i], &a[i]);
    }
    long long int tz = t[0], az = a[0];
    for(int i=1; i<n; i++){
        long long int r = tz/t[i], s = az/a[i];
        long long int p = 0, q = 0;
        if(r > s){
            p = r*t[i];
            q = r*a[i];
        }else{
            p = s*t[i];
            q = s*a[i];
        }
        while(p < tz || q < az){
            p += t[i];
            q += a[i];
        }
        tz = p;
        az = q;
        //printf("%lld %lld\n", tz, az);
    }
    printf("%lld\n", tz + az);

    return 0;
}


Measured memory_bytes: 256
///   Journey to the End of earth   ///
/// Gunjan Kumar ///
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// #include <functional> // for less 
// using namespace __gnu_pbds; 
using namespace std;
#define ll  long long
#define s(n) scanf("%d",&n)
#define ls(n) scanf("%lld",&n)
#define p(n) printf("%d",n)
// #define ln() printf("\n")
#define pln(n) printf("%d\n",n)
#define lpln(n) printf("%lld\n",n)
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rev(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define tc           ll t1; cin>>t1; while(t1--)
#define inp         ll n; cin>>n; ll arr[n]; rep(i,0,n) cin>>arr[i];
#define vect vector<ll>
#define sortv(v)       sort(v.begin(),v.end())
#define lower(v,n)    lower_bound(v.begin(),v.end(),n)-v.begin()
#define upper(v,n)    upper_bound(v.begin(),v.end(),n)-v.begin()
#define bitcount(n) __builtin_popcount(n)
#define ln <<endl
#define inf          LONG_MAX
#define ninf         LONG_MIN
#define fast         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const   ll mod=1e9+7;
const ll N=1e5+5;



int main()
{

        
        int x;
        cin >> x;
        int y=gcd(360,x);
        int lcm=(x*360)/y;
        cout<<lcm/x;
         
     return 0;
}



Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
struct edge
{
    int t , c , l;
};
vector<edge> E;
int L;
void add(int u,int v,int c)
{
    E.push_back((edge){u , v , c});
    return;
}
int main()
{
    cin>>L;L--;
    int t = 1;
    while((1<<t) - 1 <= L) {t++;}
    t--;
    for(int i = 1;i <= t-1;i++) {add(i , i + 1 , 1<<i-1);add(i , i + 1 , 0);}
    add(t , 20 , 0);
    add(t , 20 , 1<<t-1);
    //add(t + 1 , 20 , 0);
    int g = ((1<<t) - 1) + 1;
    //cout<<k<<endl;
    //cout<<g<<endl;
    while(g <= L){
        //k = t = 1;
        t = 1;
        while((1<<t) <= (L - g + 1)){t++;}t--;
        add(t + 1, 20 , g);
        g += (1<<t);
    }
    printf("20 %d\n",E.size());
    for(int i = 0;i < E.size();i++) printf("%d %d %d\n",E[i].t,E[i].c,E[i].l);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string n;
int ans;
bool t;
int main(){
    cin >> n;
    for(int i = 1; i < n.size(); i++){
        if(n[i] != '9') t = true;
    }
    ans = (n.size() - 1)*9 + (n[0]-'0') - 1;
    if(!t) ans++;
    printf("%d\n", ans);
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

      int a = sc.nextInt();
      int b = sc.nextInt();

      if(a-b<=0){
        System.out.println(0);
      }else{
          System.out.println(a-b);
      }
  }
}


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

int main() {
  int i=0,j,g,a;
  int N;
  int answer=0;
  string S;

  cin >> N >> S ;
  answer=N;

  for ( i = 1; i < N; i++)
  {
      if (S[i]==S[i-1])
      {
          answer-=1;
      }
      
  }
  
  

  cout << answer <<endl;
  
  
  return 0;
}

Measured memory_bytes: 512
use std::io::{self, BufRead};

fn main() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();
    let n = lines.next().unwrap().unwrap().parse::<usize>().unwrap();
    let mut degree: Vec<usize> = vec![0; n + 1];
    let mut edge_vertex: Vec<Vec<(usize, usize)>> = vec![vec![]; n + 1];
    for i in 1..n {
        let a_b = lines.next().unwrap().unwrap();
        let mut a_b = a_b.split_whitespace();
        let a = a_b.next().unwrap().parse::<usize>().unwrap();
        let b = a_b.next().unwrap().parse::<usize>().unwrap();
        degree[a] += 1;
        degree[b] += 1;
        edge_vertex[a].push((i, b));
        edge_vertex[b].push((i, a));
    }

    let (max_vertex, &max_degree) = degree.iter().enumerate().max_by_key(|&(_, d)| d).unwrap();

    let mut color: Vec<usize> = vec![0; n];
    let mut stack: Vec<(usize, usize)> = vec![(0, max_vertex)];

    while let Some((e, v)) = stack.pop() {
        if degree[v] == 1 && v != max_vertex {
            continue;
        }

        let prev_c = color[e];
        let mut c_iter = (1..).filter(|&c| c != prev_c);
        for &(next_e, next_v) in edge_vertex[v].iter().filter(|&&(next_e, _)| next_e != e) {
            color[next_e] = c_iter.next().unwrap();
            stack.push((next_e, next_v));
        }
    }

    println!("{}", max_degree);
    for c in color.iter().skip(1) {
        println!("{}", c);
    }
}


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

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

int main()
{
    ll i,j;
    ll n,m,k;
    cin >> n >> m >> k;
    vector<ll> a(n);
    vector<ll> b(m);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    for(i = 0;i < m;++i){
        cin >> b.at(i);
    }
    vector<ll> ruia(n+1);
    ruia.at(0) = 0;
    for(i = 1;i <= n;++i){
        ruia.at(i) = ruia.at(i-1) + a.at(i-1);
    }
    vector<ll> ruib(m+1);
    ruib.at(0) = 0;
    for(i = 1;i <= m;++i){
        ruib.at(i) = ruib.at(i-1) + b.at(i-1);
    }
    ll ans = 0;
    for(i = 0;i <= m;++i){
        ll tmp = i;
        ll cnt = ruib.at(i);
        if(cnt > k) continue;
        ll ind = upper_bound(all(ruia), k - cnt) - ruia.begin();
        if(ind == 0) ans = max(ans, tmp);
        else{
            tmp += ind-1;
            ans = max(ans, tmp);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9580
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *					# ll = deepcopy(l)
from heapq import *					# heappush(hp,x)
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize				# minn = -maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *				# pre = [0] + list(accumulate(l))
from decimal import Decimal 		# a = Decimal(a)	# use this for math questions
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''
4
RGRBG

[0,2]
[1,4]
[3,5]
'''

def solve(s):
	n = len(s)
	r,g,b = s.count('R'),s.count('G'),s.count('B')
	sub = 0
	for i in range(n):
		for j in range(i+1,n):
			k = 2*j - i
			if(k >= n):
				break
			if(len(set([s[i],s[j],s[k]])) == 3):
				sub += 1
	return r*g*b - sub


N = int(stdin.readline())
l = input()
ans = solve(l)
print(ans)



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

using namespace std;

int main(){
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++){
        if (i % k == 0){
            puts("OK");
            return 0;
        }
    }

    puts("NG");
}

Measured memory_bytes: 3636
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let a: i32 = read(&mut stdin_lock, &mut buf, b' ');
    let b: i32 = read(&mut stdin_lock, &mut buf, b'\n');
    let ans = if (a * b) % 2 == 0 { "Even" } else { "Odd" };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <cstdio>
typedef long long ll;
inline int rd(){
    int x=0,p=1;
    char a=getchar();
    while((a<48||a>57)&&a!='-')a=getchar();
    if(a=='-')p=-p,a=getchar();
    while(a>47&&a<58)x=(x<<1)+(x<<3)+(a&15),a=getchar();
    return x*p;
}
const int N=3002;
const ll mod=1e9+7;
int n,q;
int a[N];
ll f[N][N],ans;
inline ll fpow(ll b,ll p=mod-2){
	ll ans=1,tmp=b;
	while(p){
		if(p&1)ans=ans*tmp%mod;
		tmp=tmp*tmp%mod;
		p>>=1;
	}
	return ans;
}
int main(){
	n=rd(),q=rd();
	for(int i=1;i<=n;i++)a[i]=rd();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			f[i][j]=a[i]<a[j];
	ll inv=fpow(2);
	for(int i=1,x,y;i<=q;i++){
		x=rd(),y=rd();
		f[x][y]=f[y][x]=(f[x][y]+f[y][x])%mod*inv%mod;
		for(int j=1;j<=n;j++)
			if(j!=x&&j!=y){
				f[x][j]=f[y][j]=(f[x][j]+f[y][j])%mod*inv%mod;
				f[j][x]=f[j][y]=(f[j][x]+f[j][y])%mod*inv%mod;
			}
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<i;j++)
			ans=(ans+f[i][j])%mod;
	printf("%lld\n",ans*fpow(2,q)%mod);
    return 0;
}

Measured memory_bytes: 70656
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#include <bitset>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	ll cnt, x, y;
	cin >> x >> y;
	cnt = 0;
	while (x <= y){
		x *= 2;
		cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <map>

using namespace std;

map<string, int> dict;


int main(){
  int n;
  cin >> n;
  for (string x; n--; dict[x]++) {
    cin >> x;
    //cout << "string: " << x << ", times: " << dict[x] + 1 << endl;
  }
  //cout << n << endl;
  vector<vector<string>> s;
  for (auto i=dict.begin(); i!=dict.end(); i++) {
    vector<string> s_temp;
    s_temp.push_back(i->first);
    s_temp.push_back(to_string(i->second));
    s.push_back(s_temp);
  }
  stable_sort(s.begin(), s.end(), [](const vector<string> &x,const vector<string> &y){return x[0] < y[0];});
  stable_sort(s.begin(), s.end(), [](const vector<string> &x,const vector<string> &y){return stoi(x[1]) > stoi(y[1]);});
  for (int i=0; i<s.size(); i++){
    if (s[i][1] != s[0][1]) break;
    cout << s[i][0] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 51420
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int M, D, ans;
int main() {
	scanf("%d%d", &M, &D);
	if (D <= 21) {
		printf("0\n");
		return 0;
	}
	for (int m = 1; m <= M; m++) {
		for (int d = 22; d <= D; d++) {
			int dig1, dig2;
			dig1 = d / 10;
			dig2 = d % 10;
			if (dig1 * dig2 == m && dig1 >= 2 && dig2 >= 2) ans++;
		} 
	}
	printf("%d", ans);
	return 0;
} 

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

using namespace std;

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define debug(a) cout << #a << ": " << a << endl;

int main() {
  int N;
  cin >> N;
  vector<string> words(0);
  string word;
  cin >> word;
  words.push_back(word);
  string prevWord = word;
  rep(i, N - 1) {
    cin >> word;
    if ((int)word[0] - (int)prevWord[(int)prevWord.size() - 1] != 0) {
      cout << "No" << endl;
      return 0;
    }
    if (find(words.begin(), words.end(), word) != words.end()) {
      cout << "No" << endl;
      return 0;
    }
    words.push_back(word);
    prevWord = word;
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
	using namespace std;
	#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	#include <ext/pb_ds/assoc_container.hpp> 
	#include <ext/pb_ds/tree_policy.hpp> 
	using namespace __gnu_pbds; 
	#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
	
	#define all(a)      (a).begin(),(a).end()
	#define sz(x)       (int)x.size()
	
	#define ff first
	#define ss second
	#define mp make_pair
		 
	#define pb push_back
	#define endl "\n"
		 
	#define int long long 
	#define double long double
		 
	#define bp __builtin_popcountll
	#define inf 1e16
	
	const int N=1e5+5;
	const int M=1e6+6;
	const int MOD=1e9+7;
	
	void solve()
	{	
		int h,w,k;
		cin>>h>>w>>k;
		char X[h+1][w+1];
		for(int i=1;i<=h;i++)
		{
			for(int j=1;j<=w;j++)
			cin>>X[i][j];
		}
		int pre[h+2][w+2];
		for(int i=0;i<=h+1;i++)
		for(int j=0;j<=w+1;j++)
		pre[i][j]=0;
		for(int i=1;i<=w;i++)
		{
			for(int j=1;j<=h;j++)
			{
				pre[j][i]=pre[j-1][i]+(X[j][i]=='1');
			}
		}
		int tt=h-1;
		int ans=inf;
		for(int i=0;i<(1<<tt);i++)
		{
			vector<int> v;
			v.pb(0);
			for(int j=0;j<tt;j++)
			{
				if(i&(1<<j))
				v.pb(j+1);
			}
			v.pb(h);
			int cnt=v.size();
			int temp=bp(i);
			vector<int> sum(cnt-1,0);
			int du=0;
			for(int j=1;j<=w;j++)
			{
				bool flag=0;
				for(int p=1;p<cnt;p++)
				{
					sum[p-1]+=pre[v[p]][j]-pre[v[p-1]][j];
					if(sum[p-1]>k)
					{
						flag=1;
						break;
					}
				}
				if(flag==0)
				du++;
				if(flag==1 && du==0)
				{
					temp=inf;
					break;
				}
				else if(flag==1 && du!=0)
				{
					du=0;
					j--;
					for(int kkk=0;kkk<cnt-1;kkk++)
					{
						sum[kkk]=0;
					}
					temp++;
				}
				
			}
			//cout<<temp<<endl;
			ans=min(ans,temp);
		}
		cout<<ans<<endl;
	}

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


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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
inline int ctoi(char c) {if (c >= '0' && c <= '9') return (int)(c - '0'); return -1;}
inline int uatoi(char c) {if (c >= 'A' && c <= 'Z') return (int)(c - 'A'); return -1;}
inline int latoi(char c) {if (c >= 'a' && c <= 'z') return (int)(c - 'a'); return -1;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

vector<vector<ll>> combi(51, vector<ll>(51));
void init_comb(int n) {
    REP(i, n) REP(j, i + 1) {
        if (j == 0 || j == i) combi[i][j] = 1LL;
        else combi[i][j] = combi[i - 1][j - 1] + combi[i - 1][j];
    }
}

void solve() {
    int n, a, b;
    cin >> n >> a >> b;
    vector<long double> v(n);
    vector<long double> sum(n + 1, 0.0);
    map<long double, ll> m;
    REP(i, n) cin >> v[i];
    sort(ALL(v));
    reverse(ALL(v));
    long double mx = 0;
    REP(i, n) {
        m[v[i]]++;
        sum[i + 1] = sum[i] + v[i];
        //cout << i + 1 << "* " << v[i] << ":" << sum[i + 1] << "/" << sum[i + 1] / (i + 1) << EOL;
        if (i + 1 >= a && i + 1 <= b) chmax(mx, sum[i + 1] / (i + 1));
    }
    long double ans = 0;
    ll p = 0;
    // cout << mx << EOL;
    init_comb(51);
    FOR(i, a, b + 1) {
        if (fabs(mx - sum[i] / i) < DBL_EPSILON) {
            ll q = 1;
            auto itr = m.rbegin();
            int c = i;
            int d = (*itr).second;
            while (c > 0) {
                int e = min(d, c);
                q *= combi[d][e];
                //cout << i << ":" << c << "/" << d << "/" << q << EOL;
                c -= e;
                d -= e;
                if (d <= 0) {
                    itr++;
                    d = (*itr).second;
                }
            }
            p += q;
        }
    }
    cout << mx << EOL << p << EOL;
                
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int n;
	
	while(cin >> n, n){
		int ans = 0, temp = n;
		
		for(int i = n - 1; i > 0; i--){
				for(int j = i; j > 0; j--){
					temp -= j;
					if(temp == 0){
						ans++;
						break;
					}else if(temp < 0){
						break;
					}
				}
				
				temp = n;
		}
		
		cout << ans << endl;
	}
	
	return 0;
}

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

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

    vector< P > res;
    if (N % 2 != 0) {
        for (int l = 1, r = N - 1; l < r; ++l, --r) {
            res.emplace_back(P(l, r));
        }
    } else {
        bool flag = false;
        for (int l = 1, r = N - 1; l < r; ++l, --r) {
            if (!flag && r - l <= N / 2) {
                --r;
                flag = true;
            }
            res.emplace_back(P(l, r));
        }
    }

    rep(i, M) { printf("%d %d\n", res[i].first, res[i].second); }
}

Measured memory_bytes: 4148
n = int(input())

lst = [0]*100000

for i in range(1, 101):
  for j in range(1, 101):
    for k in range(1, 101):
      m = i**2 + j**2 + k**2 + i*j + j*k + k*i
      lst[m] += 1
      
for i in range(1, n+1):
  print(lst[i])
           

Measured memory_bytes: 75196
a,b,c = gets.chomp.split(" ").map(&:to_i)
count = 0

#if a == b && a == c
#  puts "-1"
#  exit
#end

while true
  if a.odd? || b.odd? || c.odd?
    puts count
    exit
  end
  ta = b/2 + c/2
  tb = a/2 + c/2
  tc = a/2 + b/2
  a = ta
  b = tb
  c = tc
  count+=1

  if a == b && a == c
    puts -1
    exit
  end
end

Measured memory_bytes: 1788
#include "bits/stdc++.h"
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}


signed main(void) {
	int N,M;
	int sum = 0;
	int a;
	cin >> N>>M;
	rep(i, M) {
		cin >> a;
		sum += a;
	}
	if(N-sum>=0)
		print(N-sum);
	else print(-1);
}

Measured memory_bytes: 3636
program prob1
    implicit none
    integer(8) :: a(4)
    read(*,*) a

    call msort(a)

    if(a(1) == 1 .and.a(2) == 4 .and.a(3) == 7 .and.a(4) == 9)then
        write(*,*) "YES"
    else
        write(*,*) "NO"
    end if


    stop
contains

  !
  ! swap two arguments
  !
subroutine swap(a, b)
    implicit none
    integer(8), intent(inout) :: a, b

    integer(8) :: c

    c = a
    a = b
    b = c

  end subroutine swap

  !
  ! merge sort
  !
  recursive subroutine msort(x)
    implicit none
    integer(8), intent(inout) :: x(:)

    integer(8) :: n, mid, i, j, k
    integer(8), allocatable :: tmp(:)
    
    n = size(x)
    
    if(n == 1) then
      return
    end if

    !
    ! 前半と後半に分けてソート
    ! 1~midとmid+1~nをそれぞれソート済みにする
    !
    mid = n / 2
    call msort(x(:mid))
    call msort(x(mid+1:))

    !
    ! tmpという配列にxを一時的に保管
    ! マージソートは外部ソート
    !
    allocate(tmp(n))
    tmp = x

    ! tmpの後半部分を左右反転
    do k = n, mid+1, -1
      tmp(k) = x(mid + n - k + 1)
    end do

    ! iは前半のリストのうちまだ見ていないものの最小値
    ! jは後半のリストのうちまだ見ていないものの最小値
    ! kは見た回数の合計
    i = 1
    j = n

    do k = 1, n
      !
      ! 一番左と一番右のうち小さい方をxに入れていく
      ! ここが等号つき不等号なので、安定ソートとなる
      !
      if(tmp(i) <= tmp(j)) then
        x(k) = tmp(i)
        i = i + 1
      else
        x(k) = tmp(j)
        j = j - 1
      end if
    end do
    
    deallocate(tmp)
    return
  end subroutine msort
end program prob1

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

using namespace std;

bool solve(int a, int b)
{
	if (a == 0 && b == 0)
		return true;

	if (a == 0 || b == 0)
		return false;
	else
		return true;
}

int main()
{
	string S;
	int dir[4];
	cin >> S;

	for (int i = 0; i < 4; i++)
		dir[i] = 0;

	for (int i = 0; i < S.size(); i++)
	{
		switch (S[i])
		{
		case 'N':
			dir[0]++;
			break;
		case 'W':
			dir[1]++;
			break;
		case 'S':
			dir[2]++;
			break;
		case 'E':
			dir[3]++;
			break;
		}
	}

	cout << ((solve(dir[0], dir[2]) && solve(dir[1], dir[3])) ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	double a,b,c,d;
	const double r = 6378.1;
	const double p = 3.14159265;
	cin >> a >> b >> c >> d;
	if(a==-1&&b==-1&&c==-1&&d==-1)break;
	a *= p / 180.0;
	b *= p / 180.0;
	c *= p / 180.0;
	d *= p / 180.0;
	/*
	if(b > 180.0) b -= 360.0;
	if(d > 180.0) d -= 360.0;
	if(a < c) swap(a,c);
	if(b < d) swap(b,d);
	*/
	double ans;
	double s = acos( cos(a) * cos(c) * cos(b - d) + sin(a)*sin(c) );
	ans = r * s;
	printf("%.f\n",ans);

    }
    return 0;
}

Measured memory_bytes: 1304
#include <stdio.h>
#include <string.h>

int main(void){
    char s[2*100000+1], t[2*100000+1];
    int result = 0;
    scanf("%s", s);
    scanf("%s", t);
    for (int i = 0; i < strlen(s); i++)
        if(s[i] != t[i]) result++;

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

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

bool is_prime(int n)
{
  if (n < 2)
    return 0;
  if (n == 2)
    return 1;
  if (n % 2 == 0)
    return 0;
  for (int i = 3, s_n = (int)sqrt(n); i <= s_n; i += 2)
  {
    if (n % i == 0)
      return 0;
  }
  return 1;
}

int main()
{
  int n, ans, i;
  cin >> n;
  i = n;
  while (1)
  {
    if (is_prime(i))
      break;
    i++;
  }
  cout << i << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
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 all(v) v.begin(), v.end()
#define F first
#define S second
#define INF 1000000000000
#define MOD 10000007
#define PI 3.14159265359
#define dij priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>
typedef long long ll;
//
int main(){
    ll x,k,d;cin>>x>>k>>d;
    ll ans;
    if(abs(x)/k>=d)ans=abs(x)-k*d;
    else{
        ll ret=1,mi=10000000000000000;
        ret=x/d;
        int ret2=ret+1;

        if(abs(x-d*ret2)<=x-d*ret)ret=ret2;
//        cout<<ret<<endl;
        if((k-ret)%(ll)2==0)ans=abs(x-d*ret);
        else ans=min(abs(x-d*ret)+d,abs(abs(x-d*ret)-d));
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3548
n = int(input())
vs = [[] for i in range(n)]
for i in range(n-1):
    u, v, w = list(map(int, input().split()))
    vs[u-1].append((v-1, w))
    vs[v-1].append((u-1, w))

stack = [0]
color = [-1] * n
color[0] = 0
while stack:
    v = stack.pop()
    for b, w in vs[v]:
        if color[b] == -1:
            color[b] = (color[v] + w) % 2
            stack.append(b)

print(*color, sep="\n")


Measured memory_bytes: 68640
#include<stdio.h>

int main(){
  int N, i;
  bool ans;
  ans = false;
  scanf("%d",&N);
  for(i=1;i<=9;i++){
    if(N%i==0 && N/i<=9){
      ans = true;
    }
  }
  if(ans){
    printf("Yes");
  }
  else{
    printf("No");
  }
  return 0;
}

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

typedef long long ll;

int main() {
#ifdef _test
    freopen( "in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, a, b;
    cin >> n >> a >> b;
    for (int i = a; i <=b; i++) {
        if ( i%n == 0) {
            cout << "OK" << '\n';
            return 0;
        }
    }
    cout << "NG" << '\n';
    return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
int main (void){
  int N;
  scanf("%d",&N);
  if(N/100==7){
    printf("Yes\n");
  }else if((N/10)%10==7){
    printf("Yes\n");
  }else if(N%10==7){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
   return 0;
}

Measured memory_bytes: 1664
#include <stdio.h>
int main(void){
    // Your code here!
    int row = 0;
    int colm = 0;
    int around = 0;
    int area = 0;
    scanf("%d %d", &row, &colm);
    
    //周長
    around = row*2 + colm*2;
    area = row*colm;
    
    printf("%d %d\n", area, around);
    return 0;
}



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

int calc(int n, int f[100][10], int p[100][11], int i) {
	int profit = 0;

	for (int j = 0; j < n; j++) {
		int count = 0;
		int l = 1;
		for (int k = 0; k < 10; k++) {
			if (f[j][k] == 1 && (i / l) % 2 == 1) {
				count++;
			}
			l *= 2;
		}

		profit += p[j][count];
	}

	return profit;
}

int main() {
	int n;
	int f[100][10];
	int p[100][11];
	int max;

	cin >> n;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> f[i][j];
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= 10; j++) {
			cin >> p[i][j];
		}
	}

	max = calc(n, f, p, 1);

	for (int i = 2; i <= 1023; i++) {
		if (calc(n, f, p, i) > max) {
			max = calc(n, f, p, i);
		}
	}

	cout << max << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long; // ll は long long　と同じとする。
int main () {
    int A , B , C , X , Y;
    cin >> A >> B >> C >> X >> Y;
    int ans = 1e9;
    for(int i = 0; i <= max(X , Y); i++){
        ans = min(ans , 2 * i * C + max(0 , X - i) * A + max(0 , Y - i) * B);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

void bubbleSort(int a[], int n) {
  int flag, i, tmp, count;
  flag = 1;

  count = 0;
  while (flag) {
    flag = 0;
    for ( i = n-1; i > 0; i-- ) {
      if ( a[i] < a[i-1] ) {
        tmp = a[i-1];
        a[i-1] = a[i];
        a[i] = tmp;
        count++;
        flag = 1;
      }
    }
  }

  for ( i = 0; i < n; i++ ) {
    printf("%d", a[i]);
    if ( i != n-1 ) printf(" ");
  }

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

int main() {
  int n, i, a[100];

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

  bubbleSort(a, n);

  return 0;
}



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

int main(void){
int N,Q;
scanf("%d %d",&N,&Q);
char str[N+1];
char s[2*N+1];
scanf("%s",str);
memcpy(s,str,N+1);
strcat(s,str);
int same_l;

int* p=(int*)calloc(1000,sizeof(int));
int* ps=p;
int k=0;
	for(int i=1;i<=N/2;i++){
				if(N%i==0){p[k]=i;k++;}
	}

for(int i=0;i<Q;i++){
int pi;char c;int iwa=0;

scanf("%d %c",&pi,&c);
//printf("pi-1=%d\nww3\n",pi-1);


if(i>=1 && s[pi-1]==c){
printf("%d\n",same_l);continue;
}else{
	s[pi-1]=c;
	s[N+pi-1]=c;
}


//printf("str=%s\n",s);

	for(int l=0;l<k;l++){
		iwa=0;	//printf("l=%d ",l);
//		if(N%l==0){
			for(int m=0;m<N/2;m++){
				//printf("m=%d ",m);
				if(s[m]!=s[m+p[l]]||s[N-m-1]!=s[N-m+p[l]-1]){iwa=1;break;}
			}
			if(iwa==0){printf("%d\n",p[l]);iwa=100;same_l=p[l];break;}
//		}
	}
	if(iwa!=100){same_l=N;;printf("%d\n",N);}
}

free(p);
return 0;
}



Measured memory_bytes: 2164
#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define fast  ios_base::sync_with_stdio(0); cin.tie(0);
#define f(i,k) for(i=0;i<k;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define input(i,n,arr) for(i=0;i<n;i++) cin>>j, arr.push_back(j)
#define vect_ll vector<long long>
#define vect_ll_it vector<long long>::iterator
#define pb(p) push_back(p)
#define endl "\n"
#define mod 1000000007
const ll inf = 1e18;
ll l[1000001], h[1000001], p[1000001];
unordered_map<ll, ll> m;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input1.txt" , "r" , stdin);
	freopen("output1.txt" , "w", stdout);
#endif
	fast
	int t = 1, test;
	//cin >> t;
	for (test = 1; test <= t; test++)
	{
		ll i, j, n, k;
		vect_ll a;
		a.clear();
		cin >> n >> k;
		input(i, n, a);
		ll dp[n + 1];
		dp[0] = 0;

		for (i = 1; i < n; i++)
		{
			dp[i] = INT_MAX;
			for (j = 1; j <= k && i - j >= 0; j++)
				dp[i] = min(dp[i - j] + abs(a[i] - a[i - j]), dp[i]);
		}
		cout << dp[n - 1] << endl;

	}
	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
	return 0;
}

Measured memory_bytes: 5020
import java.util.*;

public class Main {
    static double totalDist = 0;
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
		int[][] coord = new int[n][2];
        for(int i = 0; i < n; i++) {
        	coord[i][0] = sc.nextInt();
        	coord[i][1] = sc.nextInt();
        }
        List<Integer> posSet = new ArrayList<>();
        boolean[] visited = new boolean[n];
        dfs(coord, posSet, visited);
        
        int f = 1;
        for(int i = 1; i <= n; i++) {
        	f *= i;
        }
        
        System.out.println(totalDist / f);
    }

    private static void dfs(int[][] coord, List<Integer> posSet, boolean[] visited) {
    	if(posSet.size() == coord.length) {
    		totalDist += calDist(posSet, coord);
    		return;
    	}
    	for(int i = 0; i < coord.length; i++) {
    		if(visited[i])	continue;
    		visited[i] = true;
    		posSet.add(i);
    		dfs(coord, posSet, visited);
    		posSet.remove(posSet.size()-1);
    		visited[i] = false;
    	}
    }

    private static double calDist(List<Integer> pos, int[][] coord) {
    	double dist = 0;
    	for(int i = 1; i < pos.size(); i++) {
    	    int prevIdx = pos.get(i-1);
    	    int curIdx = pos.get(i);
    		dist += Math.hypot(coord[curIdx][0] - coord[prevIdx][0], 
    			coord[curIdx][1] - coord[prevIdx][1]
    		);
    	}
    	return dist;
    }
}


Measured memory_bytes: 23260
n = int(input())
total = 0
a = [int(v) for v in input().split()]
highest = a[0]
for i in range(1, len(a)):
    first = a[i - 1]
    second = a[i]
    if second < first:
        diff = first - second
        a[i] = second + diff
        total += diff
print(total)

Measured memory_bytes: 32068
#include<iostream>
#include <algorithm>
using namespace std;
int N_MAX = 2000;
typedef pair<int,int> P;
int main()
{
  int a,b,c;
  cin >> a >> b >> c;
  int res=a*b*c/(max({a,b,c})*2);
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
 
    int n;
    cin >> n;
    vector<int> a(n);
    int max_a = 0;

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

    for(int i = 0; i < n; ++i){
        if(a.at(i) == max_a){
            a.at(i) = 0;
            break;
        }
    }

    for(int i = 0; i < n; ++i){
        if(a[i] == 0)cout << *max_element(a.begin(), a.end()) << endl;
        else cout << max_a << endl;
    }

}

Measured memory_bytes: 2432
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<bitset>
#include<time.h>
#include<string>
#include<cmath>
#include<stack>
#include<map>
#include<set>
#define ui unsigned int
//ios::sync_with_stdio(false);
#define ull unsigned long long
#define endl "\n"
#define int long long
#define double long double
#define jn jnn
using namespace std;
#define PI  3.1415926535898
const double eqs = 1e-6;
const long long max_ = 200000 + 7;
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const long long INF = 1e18;
inline int read() {
	int s = 0, f = 1;
	char ch = getchar();
	while (ch<'0' || ch>'9') {
		if (ch == '-')
			f = -1;
		ch = getchar();
	}
	while (ch >= '0'&&ch <= '9') {
		s = s * 10 + ch - '0';
		ch = getchar();
	}
	return s * f;
}
inline void write(int x) {
	if (x < 0) {
		putchar('-');
		x = -x;
	}
	if (x > 9)
		write(x / 10);
	putchar(x % 10 + '0');
}
inline int min(int a, int b) {
	return a < b ? a : b;
}
inline int max(int a, int b) {
	return a > b ? a : b;
}
int value[3][2020];
char node[max_];
signed main() {
	cin >> node + 1;
	int len = strlen(node + 1);
	int ans = 0;
	int last = 0;
	for (int i = 1; i <= len; i++) {
		memset(value[last ^ 1], 0, sizeof(value[last ^ 1]));
		for (int j = 0; j <= 2018; j++) {
			if (((j * 10 + node[i] - '0') % 2019) == 0) {
				ans += value[last][j];
			}
			value[last ^ 1][((j * 10 + node[i] - '0') % 2019)] += value[last][j];
		}
		value[last ^ 1][node[i] - '0'] += 1;
		last ^= 1;
	}
	cout << ans;
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    int greater1 = 0, greater2 = 0;
    for(auto& i : a)
    {
        cin >> i;
    }
    vector<int> copy_a = a;
    sort(copy_a.begin(), copy_a.end(), greater<int>());
    greater1 = copy_a[0], greater2 = copy_a[1];
    for(auto i : a)
    {
        if(i == greater1)
        {
            cout << greater2 << endl;
        }
        else
        {
            cout << greater1 << endl;
        }
    }
}

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

int main(void) {
  int n;
  cin >> n;
  long long result = 0;
  long long height = 0;
  for (int i = 0; i < n; ++i) {
    long long a;
    cin >> a;
    if (height > a) {
      result += (height - a);
    } else {
      height = a;
    }
  }

  cout << result << endl;
  return 0;
}

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

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

    vector<int> c8(200, 0);

    int yaku = 0;
    for (int i=105; i<=200; i++) {
        for (int j=1; j<=i; j++) {
            if (i%j == 0 && j%2 == 1) {
                yaku++;
            }
        }
        if (yaku == 8) {
            c8[i-1]++;
        }
        yaku = 0;
    }

    cout << accumulate(c8.begin(), c8.begin() + N, 0);

    return 0;
}


Measured memory_bytes: 256
n=int(input())
a,b,ba,ans=0,0,0,0
for _ in range(n):
    s=input()
    for i in range(len(s)-1):
        if s[i]=="A" and s[i+1]=="B": ans+=1
    if s[0]=="B": b+=1
    if s[-1]=="A": a+=1
    if s[0]=="B" and s[-1]=="A": ba+=1
if ba==b==a!=0: ans-=1 
print(ans+min(a,b))

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

int main(){
	
	int n;
	
	while(cin>>n){
		if(n!=0){
			int max=0,min=500;
			vector < vector<int> > s(n,vector<int>(5));
			for(int i=0;i<n;i++){
				int u=0;
				for(int j=0;j<5;j++){
					cin>>s[i][j];
					u+=s[i][j];
				}
				if(max<u)
					max=u;
				if(min>u)
					min=u;
			}
			cout<<max<<" "<<min<<endl;
		}
		else
			break;
	}
}

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

int main(){
  int H, W, K; cin >> H >> W >> K;
  long dp[H+1][W];
  for(int i=0; i<=H; i++){
    for(int j=0; j<W; j++){
      dp[i][j] = 0;
    }
  }
  int p = 1000000007;
  dp[0][0] = 1;
  for(int i=1; i<=H; i++){
    for(int j=0; j<W; j++){
      for(int k=0; k<pow(2, W-1); k++){
        bool flag = false;
        for(int l=0; l<W-2; l++){
          if(((k>>l) & 1) && ((k>>(l+1)) & 1)){
            flag = true;
            break;
          }
        }
        if(flag) continue;
        if(j==0){
          dp[i][j] = (dp[i][j] + dp[i-1][j] * (1-(k&1)) + dp[i-1][j+1] * (k&1)) % p;
        }
        else if(j==W-1){
          dp[i][j] = (dp[i][j] + dp[i-1][j-1] * ((k>>(W-2))&1) + dp[i-1][j] * (1-(k>>W-2)&1)) % p;
        }
        else{
          dp[i][j] = (dp[i][j] + dp[i-1][j-1] * ((k>>(j-1))&1) + dp[i-1][j+1] * ((k>>j)&1)) % p;
          if(!((k>>(j-1))&1) && !((k>>j)&1)) dp[i][j] = (dp[i][j] + dp[i-1][j]) % p;
        }
      }
    }
  }
  cout << dp[H][K-1] << endl;
}

Measured memory_bytes: 256