akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

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

fn main() {
    let n = read::<i64>();
    let big_int = 1000_000_000 + 7;
    let primes = get_primes(n);
    let mut factor_all = HashMap::new();
    for i in 1..n + 1 {
        let factors = factorize(i, &primes);
        for &key in factors.keys() {
            *factor_all.entry(key).or_insert(0) += factors[&key];
        }
    }
    let mut ans = 1i64;
    for &v in factor_all.values() {
        ans *= 1 + v;
        ans %= big_int;
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn get_primes(n: i64) -> Vec<i64> {
    let mut is_prime = vec![true; n as usize + 1];
    let mut primes = Vec::new();
    is_prime[0] = false;
    is_prime[1] = false;

    for i in 2..n + 1 {
        if is_prime[i as usize] {
            primes.push(i);
            let mut j = 2 * i;
            while j < n {
                is_prime[j as usize] = false;
                j += i;
            }
        }
    }
    primes
}

fn factorize(mut num: i64, primes: &Vec<i64>) -> std::collections::HashMap<i64, i64> {
    // max_primes >= (num)^(1/2)
    let mut dict = std::collections::HashMap::new();
    for &p in primes.iter() {
        while num % p == 0 {
            *dict.entry(p).or_insert(0) += 1i64;
            num /= p;
        }
        if num == 1 {
            break;
        }
    }
    if num != 1 {
        dict.insert(num, 1);
    }
    dict
}

fn pow(n: i64, mut p: i64) -> i64 {
    let mut r = n;
    let mut ret = 1;
    while p > 0 {
        if p % 2 == 0 {
            r = r * r;
            p /= 2;
        } else {
            ret = ret * r;
            p -= 1;
        }
    }
    ret
}


Measured memory_bytes: 4352
import math


def run(n):
    ret = 0
    if n == 1:
        return n
    while True:
        ret += n % 10
        n = math.floor(n / 10)
        if n == 0:
            if ret == 1:
                return 10
            else:
                return ret


def read_line():
    n, = input().split()
    n = int(n)
    return n


def main():
    n = read_line()
    print(run(n))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import heapq
import sys
from itertools import accumulate

n,m,s,t = map(int,next(sys.stdin).split(" "))
inf = 1000000000000000
gyen = [dict() for _ in range(n)]
gsnuk = [dict() for _ in range(n)]

for _ in range(m):
        u,v,a,b = map(int,next(sys.stdin).split(" "))
        gyen[u-1][v-1] = gyen[v-1][u-1] = a
        gsnuk[u-1][v-1] = gsnuk[v-1][u-1] = b

def dijkstra(graph, start):
        dist = [inf for _ in range(n)]
        dist[start] = 0
        q = [(0,start)]
        while q:
                du, u = heapq.heappop(q)
                if dist[u] < du:
                        continue
                for v,d in graph[u].items():
                        if dist[v] > du+d:
                                dist[v] = du+d
                                heapq.heappush(q, (dist[v], v))
        return dist

yen = dijkstra(gyen,s-1)
snuke = dijkstra(gsnuk,t-1)

ans = list(accumulate([y+s for y,s in zip(yen,snuke)][::-1],min))
[print(inf-ans[i]) for i in range(n-1,-1,-1)]

Measured memory_bytes: 100040
// Problem : C - H and V
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_c
// Memory Limit : 1024 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

// Mere bas ka nahi hai
// still i'm trying
// apna time aayega
//
//        .--------------.  
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |  
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'                          		  
//
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll power(ll x,ll y,ll m){if(y==0)return 1;ll p=power(x,y/2,m)%m;p=(p*p)%m;return (y%2==0)?p:(x*p)%m;}
ll nCr(ll n,ll r,ll m){if(r>n)return 0;ll a=1,b=1,i;for(i=0;i<r;i++){a=(a*n)%m;--n;}while(r){b=(b*r)%m;--r;}return (a*power(b,m-2,m))%m;}
#define Test int t;cin>>t;while(t--)
#define endl '\n'
void solve()
{
	int n,m,k;
	cin >> n >>m >> k;
	vector<string> v(n);
	for(int i=0;i<n;++i)
	cin >> v[i];
	vector<int> row(n),col(m);
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<m;++j)
		{
			if(v[i][j]=='#')
			{
				row[i]++;
				col[j]++;
			}
		}
	}
	int cnt=0;
	for(int i=0;i<n;++i) cnt+=row[i];
	int ans=0;
	for(int i=1;i<=power(2,n,(ll)10000);++i)
	{
		for(int j=1;j<=power(2,m,(ll)10000);++j)
		{
			int temp=cnt;
			int a=i,b=j;
			vector<int> ro(n),co(m);
			for(int r=0;r<n;++r)
			{
				if(a&1)
				ro[r]=1;
				a=a>>1;
			}
			for(int c=0;c<m;++c)
			{
				if(b&1)
				co[c]=1;
				b=b>>1;
			}
			for(int r=0;r<n;++r)
			{
				for(int c=0;c<m;++c)
				{
					if(ro[r]==1 || co[c]==1)
					{
						if(v[r][c]=='#')
						temp--;
					}
				}
			}
			if(temp==k)
			ans++;
		}
	}
	cout << ans << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//Test
	solve();
	return 0;
}


Measured memory_bytes: 3604
#include<iostream>
using namespace std;
#include <cstdio>
#include <cmath>
#include <cstring> 
#include <algorithm>
#include <stack> 
#define ll long long

int f(int h)
{
	int num=0;
	for(int x=1;x<=sqrt(h);x++)
	{
		for(int y=1;y<=sqrt(h-x*x);y++)
		{
			for(int z=1;z<=sqrt(h-x*x-y*y);z++)
			{
				if(x*x+y*y+z*z+z*x+z*y+x*y==h)
				{
					num++;
				}
				if(x*x+y*y+z*z+z*x+z*y+x*y>h)
				{
					break;
				}									
			}
		}
	}
	return num;
}
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cout<<f(i)<<endl;
	}
	return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<vector>
#include<set>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>

using namespace std;
using ll = long long;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    ll n, m, x;
    cin >> n >> m;
    set<ll> a;
    rep(i, m) {
        cin >> x;
        a.insert(x);
    }
    vector<ll> dp(n+1,0);
    dp[0] = 1;
    rep(i, n) {
        if (a.count(i+1) > 0)
            dp[i+1] = 0;
        else if (i > 0)
            dp[i+1] = (dp[i] + dp[i-1]) % 1000000007;
        else
            dp[i+1] = dp[i];
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 5760
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n, a[200000] = {}, ans = 0;
map<ll, ll>m;

int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		ans += m[i-a[i]];
		m[i + a[i]]++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 27900
# 入力
a,b=map(int,input().split())

# 初期状態（1口）
n=1

# タップの数
ans=0

# タップを1つずつ差していく
# 差すことでa口増えるが、差した口も1つ減る
while True:
  # b口以上になったら終了
  if n>=b:
    print(ans)
    exit()
    
  n+=a
  n-=1
  ans+=1
  

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n,m;
    cin>>n>>m;
    int k[m],s[m][20];
    rep(i,m){
        cin>>k[i];
        rep(j,k[i]){
            cin>>s[i][j];
            s[i][j]--;
        }
    }
    int p[m];
    rep(i,m) cin>>p[i];
    int ans=0;
    for(int bit=0;bit<(1<<n);bit++){
        int a=0;
        rep(i,m){
            int cnt=0;
            rep(j,k[i]) if(bit&(1<<s[i][j])) cnt++;
            if(cnt%2==p[i]) a++;
        }
        if(a==m) ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 3628
#include <iostream>
#include <assert.h>
#include <algorithm>
#include <vector>
#include <cmath>


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

  int64_t N;
  std::cin >> N;
  std::vector<int64_t> A(N);
  for (auto& i : A) {
    std::cin >> i;
  }
  std::vector<int64_t> num_dig(60);
  for (int64_t i = 0; i < N; i++) {
    int64_t val = A[i];
    for (int32_t dig = 0; dig < 60; dig++) {
      if ((val & 1) == 1) {
        num_dig[dig]++;
      }
      val = (val >> 1);
    }
  }

  int64_t MOD = 1000000007;
  int64_t sum = 0;
  int64_t base = 1;
  for (int32_t i = 0; i < 60; i++) {
    int64_t cmb = num_dig[i] * (N - num_dig[i]);
    cmb %= MOD;
    int64_t base_mod = base % MOD;
    sum += base_mod * cmb;
    sum %= MOD;
    base = base << 1;
  }
  std::cout << sum << std::endl;

  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb(t) push_back(t)
#define pt(num) cout << num << "\n"
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;


int main(void) {
    ll N;
    cin >> N;
    string s;
    cin >> s;
    ll i;
    ll cnt[26]={};
    
    ll ans=1;
    
    for(i=0; i<N; i++) {
        cnt[s[i]-'a']++;
    }
    
    for(i=0; i<26; i++) {
        moC(ans, *, 1+cnt[i]);
    }
    ans--;
    pt(max(ans, 1));
    
}




Measured memory_bytes: 512
### main

ws = 10.times.map{gets.strip.to_i}
ks = 10.times.map{gets.strip.to_i}

w_score = ws.sort{|a, b| b <=> a}[0..2].inject(:+)
k_score = ks.sort{|a, b| b <=> a}[0..2].inject(:+)

puts [w_score, k_score].join(' ')

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

signed main(void)
{
	int n, ans;
	cin >> n;
	ans = 0;
	rep(i, n)
	{
		int a;
		cin >> a;
		while(a % 2 == 0)
		{
			a /= 2;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <list>
#include <algorithm>
using namespace std;

int main()
{
	int n, k;
	char s[15];
	list<int> l;

	scanf("%d", &n);
	while (n--) {
		scanf("%s", s);
		if (*s == 'i') {
			scanf("%d", &k);
			l.push_front(k);
			continue;
		}
		switch (*(s + 6)) {
		case 'F': l.pop_front(); break;
		case 'L': l.pop_back(); break;
		default:
			scanf("%d", &k);
			auto e = l.end(), r = find(l.begin(), e, k);
			if (r != e)
				l.erase(r);
		}
	}

	int &f = l.front();
	for (int &x: l)
		printf("%s%d", (&f == &x ? "" : " "), x);
	puts("");
}


Measured memory_bytes: 33944
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define lld long long double
#define pb push_back



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

    int n;
    cin>>n;
    unsigned long long prod=1;
    vector<unsigned long long>arr(n);
    for(int i=0 ; i<n ; i++)
    {
        cin>> arr[i];
    }
    sort(arr.begin(),arr.end());
    if(arr[0]==0){cout<<0;return 0;}
    for(long long i=0 ; i<n ; i++)
    {
        if(arr[i]>1000000000000000000/prod){cout << -1;return 0;}
        prod=prod*arr[i];
    }
    //if(prod<0) {cout <<-1;return 0;}
    cout << prod;

}





Measured memory_bytes: 3952
N, K = map(int, input().split())
A = list(map(int, input().split()))

A_neg = []
A_pos = []

for i in range(N):
  if A[i] <= 0:
    A_neg.append(-A[i])
  else:
    A_pos.append(A[i])

A_neg.sort(reverse=True)
A_pos.sort(reverse=True)

ans = 1

if K == N:
  for i in range(N):
    ans *= (A[i]%1000000007)
    ans %= 1000000007
  print(ans)

elif K%2==1 and len(A_pos)==0:
  for i in range(1, K+1):
    ans *= ((-A_neg[-i])%1000000007)
    ans %= 1000000007
  print(ans)

else:
  if K%2==1:
    ans *= A_pos.pop(0)
    K -= 1
  buf = []
  if len(A_pos)>=2:
    for i in range(len(A_pos)//2):
      buf.append(A_pos[2*i]*A_pos[2*i+1])
  if len(A_neg)>=2:
    for i in range(len(A_neg)//2):
      buf.append(A_neg[2*i]*A_neg[2*i+1])
  buf.sort(reverse=True)
  for i in range(K//2):
    ans *= (buf[i]%1000000007)
    ans %= 1000000007
  print(ans)
  



Measured memory_bytes: 31740
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long int ll;
typedef unsigned long long ull;
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;}
typedef pair<ll,ll> P;


int main()
{
    int n,m;
    ll k;
    cin>>n>>m>>k;
    vector<ll>a(n+1),b(m+1);  
    int ans=0,N=0,M=0;
    a[0]=0;
    b[0]=0;
    rep(i,n){
        cin>>a[i+1];
        a[i+1]+=a[i];
    }
    rep(i,m){
        cin>>b[i+1];
        b[i+1]+=b[i];
    }
    int o=m;
    for(int i=0;i<=n;i++){
        while(a[i]+b[o]>k&&o>=0){
            o--;
        }
        //cout<<ans<<endl;
        if(o>=0)ans = max(ans,i+o);
        else break;
    }
    cout<<ans<<endl;
    return 0; 
}


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

int main(int qtd, char* nome[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);

	int a, b;
	cin >> a >> b;
	if(a >= 1 && a <= 9 && b >= 1 && b <= 9)
		cout << a*b << endl;
	else
		cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.141592653289793;
using namespace std;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
#define lld long double
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> vp;
typedef vector<tuple<ll, ll, ll>> vt;
//vector<vector<ll>> vv(n, vector<ll>(n));

int main()
{
	string s1, s2;
	cin >> s1 >> s2;
	if (s1[0] == s2[2] && s1[1] == s2[1] && s1[2] == s2[0]) cout << "YES" << endl;
	else cout << "NO" << endl;
}

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

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> l(m);
    vector<int> r(m);
    rep(i,m) cin>>l[i]>>r[i];

    sort(l.begin(),l.end(),greater<int>());
    sort(r.begin(),r.end());

    int ans=r[0]-l[0]+1;
    if(ans<0) ans=0;
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 4052
n = int(input())
A = list(map(int, input().split()))

money = 1000
stock = 0

schedule = []
for i in range(n-1):
    if A[i] < A[i+1]:
        schedule.append(i)

for i in schedule:
    stock, money = divmod(money, A[i])
    money = money+stock*A[i+1]
print(money)


Measured memory_bytes: 9188
# 解けなかった...orz

N = int(input())
A = [int(i) for i in input().split()]
abs_A = list(map(abs, A))

SUM = sum(abs_A)

minus = len(list(filter(lambda a: a < 0, A)))
if minus % 2 == 0:
    print(SUM)
else:
    m = min(abs_A)
    print(SUM - 2*m)

Measured memory_bytes: 14284
//Akash Kumar Mondol
//Department of ICE,University of Rajshahi,Bangladesh
#include<bits/stdc++.h>
using namespace std;
#define pr(x) cerr << "\n" << (#x) << " is " << (x) << endl
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define scd(x) scanf("%lf",&x)
#define pfi(x) printf("%d",x)
#define pfl(x) printf("%lld",x)
#define pfd(x) printf("%lf",x)
#define pfc(x) printf("Case %d: ",x)
#define ps printf(" ")
#define pn printf("\n")
#define mod 1000000007
#define Toggle(n,i) (n^(1<<i))
#define Check(n,i) (n&(1<<i))
#define Set(n,i) (n|(1<<i))
#define Reset(n,i) (n&(~(1<<i)))
//#define valid(nx,ny) nx>=0&& nx<r && ny>=0 && ny<c
//memset(a, 0, sizeof(a));
//freopen("file_name.txt","read_or_write",stdout_or_stdin);
int main()
{
    //freopen("file_name.txt","w",stdout);
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    sci(n);
    string s,str;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        int val=s[i]-'A';
        val+=n;
        str.push_back((char)(val)%26+'A');
    }
    cout<<str<<endl;
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=18;
int a[N],m=0,f[N][2];ll n;
int main(){
  cin>>n;
  ll x=n;
  while(x)a[++m]=x%10,x/=10;
  reverse(a+1,a+m+1); 
  for(int i=0;i<=a[1];i++)f[1][i<a[1]]=max(f[i][i<a[1]],i);
  for(int i=1;i<m;i++){
    for(int j=0;j<=9;j++)
      f[i+1][1]=max(f[i+1][1],f[i][1]+j);
    for(int j=0;j<=a[i+1];j++)
      f[i+1][j<a[i+1]]=max(f[i+1][1],f[i][0]+j);
  }
  printf("%d\n",max(f[m][0],f[m][1]));
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
using namespace std;
int n,m;
long long val[100010];
int col[100010];
bool vis[100010];
vector<pair<int,long long> >G[100010];
long long mark;
long long mn=1LL;
long long mx=1e18;
long long myabs(long long x)
{
	return x<0?-x:x;
}
bool dfs(int x,int c)
{
	col[x]=c;
	for(int i=0;i<G[x].size();i++)
	{
		int y=G[x][i].first;
		long long w=G[x][i].second;
		if(col[y])
		{
			if(col[y]!=3-c)
			{
				mark=myabs((val[y]-(w-val[x]))/2LL);
				return false;
			}
		}
		else
		{
			val[y]=w-val[x];
			if(!dfs(y,3-c))return false;
		}
	}
	return true;
}
bool solve(int x)
{
	vis[x]=true;
	for(int i=0;i<G[x].size();i++)
	{
		int y=G[x][i].first;
		long long w=G[x][i].second;
		if(vis[y])
		{
			if(val[y]!=w-val[x])return false;
		}
		else
		{
			val[y]=w-val[x];
			if(!solve(y))return false;
		}
	}
	return true;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int a,b;
		long long c;
		scanf("%d%d%lld",&a,&b,&c);
		G[a].push_back(make_pair(b,c));
		G[b].push_back(make_pair(a,c)); 
	}
	if(!dfs(1,1))
	{
		if(!mark)
		{
			printf("0");
			return 0;
		}
		val[1]=mark;
		if(!solve(1))
		{
			printf("0");
			return 0;
		}
		for(int i=1;i<=n;i++)
		{
			if(val[i]<=0)
			{
				printf("0");
				return 0;
			}
		}
		printf("1");
	}
	else
	{
		if(!solve(1))
		{
			printf("0");
			return 0;
		}
		for(int i=1;i<=n;i++)
		{
			if(col[i]==1)
			{
				mn=max(mn,-val[i]+1LL);
			}
			else
			{
				mx=min(mx,val[i]-1LL);
			}
		}
		printf("%lld",max(0LL,mx+1-mn));
	}
	return 0;
}

Measured memory_bytes: 13824
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        List<Integer[]> edgeList = new ArrayList<>();
        for (int i = 0; i < m; i++) {
            int a = Integer.parseInt(sc.next());
            int b = Integer.parseInt(sc.next());
            edgeList.add(new Integer[] { a, b });
        }
        sc.close();

        // 主処理
        Map<Integer, HashSet<Integer>> graph = createGraph(n, edgeList);

        PriorityQueue<Integer> countQueue = new PriorityQueue<>(Collections.reverseOrder());
        boolean[] used = new boolean[n + 1];
        for (int i = 1; i < n; i++) {
            if (!used[i]) {
                PriorityQueue<Integer> pq = new PriorityQueue<>();
                pq.add(i);

                int count = 0;
                while (!pq.isEmpty()) {
                    int num = pq.poll();
                    if (!used[num]) {
                        count++;
                        pq.addAll(graph.get(num));
                        used[num] = true;
                    }
                }
                countQueue.add(count);
                used[i] = true;
            }
        }
        int result = countQueue.peek();

        // 出力
        System.out.println(result);
    }

    public static Map<Integer, HashSet<Integer>> createGraph(int nodeSize, List<Integer[]> edgeList) {
        Map<Integer, HashSet<Integer>> graph = new HashMap<>();
        for (int i = 1; i <= nodeSize; i++) {
            graph.put(i, new HashSet<>());
        }
        for (Integer[] edge : edgeList) {
            graph.get(edge[0]).add(edge[1]);
            graph.get(edge[1]).add(edge[0]);
        }
        return graph;
    }
}


Measured memory_bytes: 137344
using System;
using System.Linq;

namespace Myatcoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int[] A = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            Array.Sort(A);
            Array.Reverse(A);
            int ans = 0;
            for (int i = 0; i < A.Length - 1; i++) {
                ans += Math.Abs(A[i] - A[i + 1]);
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13396
using System.Linq;
using System;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            var result = GettingStarted.Range();
            System.Diagnostics.Trace.WriteLine(result);
            Console.WriteLine(result);
        }
    }

    public static class GettingStarted
    {
        public static string Range()
        {
            var input = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            return input[0] < input[1] && input[1] < input[2] ? "Yes" : "No";
        }
    }
}

Measured memory_bytes: 5676
/* ex9_2
   TakayukiY*/

#include <stdio.h>
#include <stdlib.h>

//リストのノード（スタック内の各データ）の定義
typedef struct node
{
    char elem;
    struct node *next;
} node;

//スタックにデータを追加
void push(node **first, char elem)
{
    node *new = calloc(1, sizeof(node));
    if (new == NULL)
        exit(1);
    new->elem = elem;
    new->next = *first;
    *first = new;
}

//スタックからデータを取り出す
char pop(node **first)
{
    char elem;
    node *tmp = *first;
    if (tmp == NULL)
        return '\0';
    elem = tmp->elem;
    *first = tmp->next;
    free(tmp);
    return elem;
}

void free_stack(node **first)
{
    node *tmp = *first, *next;
    while (tmp != NULL)
    {
        next = tmp->next;
        free(tmp);
        tmp = next;
    }
}

int main(void)
{
    char input[100000 + 1], *ptr;
    node *first = NULL;
    int count = 0;

    scanf("%s", input);
    ptr = input;

    while (*ptr != '\0')
    {
        if (first==NULL)
        {
            push(&first, *ptr);
        }
        else
        {
            if (first->elem == *ptr)
            {
                push(&first, *ptr);
            }
            else
            {
                pop(&first);
                count+=2;
            }
        }
        ptr++;
    }

    printf("%d", count);

    return 0;
}

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


using namespace std;


#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()


ll sum(int n);


void go(){
	string s;cin>>s;
	if(sz(s)==3) reverse(all(s));
	cout << s;
}
int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}

ll sum(int n){                
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	ll x,cost;
};
int main() {

	int n;
	int x[101];
	ll t[101]={};
	cin>>n;
	rep(i,n){
		cin>>x[i];
		for(int j=1; j<101; j++)t[j]+=(x[i]-j)*(x[i]-j);
	}
	ll mi=INF;
	for(int i=1; i<101; i++)mi=min(mi,t[i]);
	cout<<mi<<endl;
	return 0;
}


Measured memory_bytes: 256
import itertools

N, M = map(int, input().split())
X = [tuple(map(int, input().split())) for _ in range(N)]

ans = 0
for i0, i1, i2 in itertools.product([1, -1], repeat=3):
    X.sort(key=lambda x: i0 * x[0] + i1 * x[1] + i2 * x[2], reverse=True)
    ans = max(ans, sum([i0 * x[0] + i1 * x[1] + i2 * x[2] for x in X[:M]]))

print(ans)


Measured memory_bytes: 3296
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d",&a);
    scanf("%d",&b);
    if(a<10 && a>=0)
    {
    b=b+(100*(10-a));
    printf("%d",b);
    }
    else
    {
        printf("%d",b);
    }


    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
  {int X, N; cin >> X >> N;
  vector<bool> bs(102, true); while (N--) {int p; cin >> p; bs[p] = false;}
  pair<int, int> m{200, 200}; for (int i{}; i < 102; ++i) if (bs[i]) m = min(m, {abs(X - i), i});
  cout << m.second;}

Measured memory_bytes: 3624
require("fs").readFileSync("/dev/stdin","utf8").split('\n').map(function(i){for(t=1;t<26;t+=2)for(s=26;s--;)r=i.replace(/[\w]/g,function(j){return String.fromCharCode((j.charCodeAt(0)*t+s)%26+97)}),r.match(/th(is|at)/)?console.log(r):0})

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

using namespace std;
typedef long long ll;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    ll res = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int k = 1; k <= n; k++) {
                res += gcd(gcd(i, j), k);
            }
        }
    }
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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 T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



int a[25], b[25];

int main() {
    for (int i = 0; i < 10; ++i) cin >> a[i];
    for (int i = 0; i < 10; ++i) cin >> b[i];
    sort(a, a+10, greater<int>());
    sort(b, b+10, greater<int>());
    
    cout << a[0] + a[1] + a[2] << " " << b[0] + b[1] + b[2] << endl;
    
    return 0;
}


Measured memory_bytes: 1180
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;

int main() {
	int A,B;
	cin >> A >> B;
	
	int k = 1;
	int ans = 0;
	while(k < B){
		ans += 1;
		k -= 1;
		k += A;
	}

	cout << ans;
}

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 2005;

int N;
int L[MAX_N];

signed main()
{
  cin >> N;
  REP(n,N) {
    cin >> L[n];
  }

  sort(L, L+N);

  int ans = 0;
  REP(i,N) {
    FOR(j,i+1,N) {
      int minC = L[i] + L[j];
      ans += (lower_bound(L+j+1,L+N,minC) - L) - j - 1;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 200009 /// Still trying to be normal
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int n2=n-1;
    vector<int> sub[maxn];
    rep(i,0,n2){
        int a;
        cin>>a;
        sub[a].push_back(1);
    }
    rep(i,1,n+1){
        cout<<sub[i].size()<<'\n';
    }
    return 0;   
}           


Measured memory_bytes: 14560
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>
#include <unordered_map>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    ll N;
    string S;
    vector<string> ans;
    unordered_map<string, ll> ma;
    cin>>N;
    rep(i, N){
        cin>>S;
        if(ma[S]!=0) ma[S]++;
        else ma[S]=1;
    }
    ll Maxim=0;
    for(auto itr = ma.begin(); itr != ma.end(); ++itr) {
        Maxim=max(Maxim, itr->second);
    }
    for(auto itr = ma.begin(); itr != ma.end(); ++itr) {
        if(Maxim==itr->second) ans.push_back(itr->first);
    }
    sort(all(ans));
    rep(i, ans.size()){
        cout<<ans[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 26692
#include <bits/stdc++.h>
using namespace std;
typedef long long				ll;
typedef pair<int,int >			pii;
#define V						vector
#define SYNC					ios_base::sync_with_stdio(0);cin.tie(0);
#define rep(i,b)				for(int i=0;i<b;i++)
#define repn(i,n)				for(int i=1;i<=n;i++)
#define ALL(x)					(x).begin(),(x).end()
#define fi						first
#define se						second
#define pb						push_back
#define dzx						cerr<<"here";
const ll MOD=1e9+7,INF=9e18;
const int inf=2e9;
/* Equinox */
V<V<int> > g;
int findg(int c,int p){
	int ch=g[c].size();
	if(p)
		ch--;
	if(ch==0)
		return 0;
	int cur=0;
	for(auto i:g[c]){
		if(i!=p)
			cur^=(findg(i,c)+1);
	}
	return cur;
}
int main(){SYNC
	int n;
	cin>>n;
	g.resize(n+1);
	rep(i,n-1){
		int u,v;
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	cout<<((findg(1,0)!=0)?"Alice":"Bob");
	return 0;
}

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

int main(){
    int a,b,h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <math.h>
#include <unordered_map>
#include <numeric>
using namespace std;

int isEven(int a){
  return (a%2 == 0)? 1:0;
}

int main()
{
	int ans;
	int x;

	cin >> x;

	if(isEven(x))
		ans = x/2 * x/2;
	else
		ans = (x+1)/2 * (x-1)/2;

	std::cout  << ans << '\n';

	return 0;
}


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

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define MOD 1000000007

bool vis[200005];
set<ll> adj[200005];
ll dfs(ll cur){
	vis[cur]=1;
	ll temp=1;
	for(auto& child:adj[cur]){
		if(vis[child])
			continue;
		temp+=dfs(child);
	}
	return temp;
}
int main(){
	ll N,M;
	cin>>N>>M;
	for(ll i=0;i<M;i++){
		ll a,b;
		cin>>a>>b;
		a--;b--;
		adj[a].insert(b);
		adj[b].insert(a);
	}
	ll ans=1;
	for(ll i=0;i<N;i++){
		if(vis[i])
			continue;
		ans=max(ans,dfs(i));
	}
	cout<<ans<<endl;
}

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

int main() {
  int N;cin>>N;
  vector<int> a(N);//0
  vector<int> b(N);//1
  vector<int> c(N);//2
  for(int i=0;i<N;i++){
    cin>>a[i]>>b[i]>>c[i];
  }
  vector<vector<int>> dp(N,vector<int>(3,0));
  dp[0][0]=a[0];dp[0][1]=b[0];dp[0][2]=c[0];
  for(int i=1;i<N;i++){
    dp[i][0]=max({dp[i][0],dp[i-1][1]+a[i],dp[i-1][2]+a[i]});
    dp[i][1]=max({dp[i][1],dp[i-1][0]+b[i],dp[i-1][2]+b[i]});
    dp[i][2]=max({dp[i][2],dp[i-1][0]+c[i],dp[i-1][1]+c[i]});
  }
  cout<<max({dp[N-1][0],dp[N-1][1],dp[N-1][2]})<<endl;
}

Measured memory_bytes: 6912
N,A,B=map(int,input().split())
count_sum=0
for i in range(1,N+1):
    i_str=list(str(i))
    i_int=[int(j) for j in i_str]
    i_sum=sum(i_int)
    if A<=i_sum<=B:
        count_sum=count_sum+i
print(count_sum)

Measured memory_bytes: 3060
# ABC 141 B

S = input()
res = 'Yes'

for i in range(len(S)):
    if (i + 1) % 2 == 0: # even
        if S[i] == 'R':
            res = 'No'
            break
    else: # odd
        if S[i] == 'L':
            res = 'No'
            break

print(res)            

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

int main() {
  int N;
  cin >> N;
  vector<long long> A(N); 
  for(int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  cout << A.at(N-1) - A.at(0) << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N, K = map(int, input().split())
A = list(map(int, input().split()))

num_in = 0
for i in range(0, N):
    for j in range(i+1, N):
        if A[i] > A[j]:
            num_in += 1

A_s = sorted(A)
num_out = 0
for i in range(0, N):
    for j in range(i+1, N):
        if A_s[i] < A_s[j]:
            num_out += 1

MOD = int( 1e9 + 7 )

print((K*(K-1)//2*num_out+K*num_in)%MOD)



Measured memory_bytes: 3188
#include <stdio.h>

int linersearch(int n,int A[],int key){
  int i=0;
  for(i=0;i<n-1;i++){
    if(A[i]==key)return 1;
  }
    return 0;
}

int main(){
  int n,q,A[10000],key;
  int i,count=0;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    count=count+linersearch(n,A,key);
  }
  printf("%d\n",count);

  return 0;
}



Measured memory_bytes: 2108
N = int(input())
flag = 0
x = 0
y = 0
z = 0
for h in range(N//4+1,3501):
    for n in range((N*h)//(4*h-N)+1,3501):
        a = N*h*n
        b = 4*h*n-N*(h+n)
        if a%b==0:
            x = h
            y = n
            z = a//b
            flag=1
            break
    if flag==1:break
print(x,y,z)

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

unsigned GCD(unsigned a, unsigned b)
{
    if (!b) return a;
    return GCD(b, a%b);
}

unsigned LCM(unsigned a, unsigned b)
{
    return a / GCD(b, a-b) * b;
}

int main(void)
{
    unsigned a, b;
    while (scanf("%u %u", &a, &b) != EOF) {
        if (a < b) swap(a, b);
        printf("%u %u\n", GCD(a, b), LCM(a, b));
    }

    return 0;
}

Measured memory_bytes: 1196
def main():
    n=int(input())
    a=list(map(int,input().split()))
    a_max=a[0]
    ans=0
    for ai in a[1:]:
        if ai<a_max:
            ans+=a_max-ai
        a_max=max(a_max,ai)
    return ans

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


Measured memory_bytes: 94140
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long int c,n;
	cin>>n;
	c=n*3;
	long long int i,a[c],s=0,x=0;
	for(i=0;i<c;i++)
	{
		cin>>a[i];
	}
	sort(a,a+c);
	for(i=c-2;i>=0;i=i-2)
	{
		s=s+a[i];
		x++;
		if(x>=n)
		{
			break;
		}
	}
	cout<<s<<endl;
	
}

Measured memory_bytes: 5944
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<iostream>
#include<stack>
#include<queue>
#include<map>
#include<cmath>
const int maxn = 5e5 + 5;
using namespace std;

char s[maxn];

int main(){
	scanf("%[^/n]", s);
	int n = strlen(s);
	printf("A");
	for(int i = 0; i < n; i++){
		if(s[i] == ' '){
			printf("%c",s[i + 1]);
			break;
		}
	}
	printf("C\n");
	return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
c=list(map(int,input().split()))

dp=[[0]*(n+1) for i in range(m)]#dp[i][j]はi番目の硬貨までを使ってj円払う最小の枚数
for i in range(n+1):
    dp[0][i]=i
for j in range(m):
    dp[j][0]=0
    dp[j][1]=1
for i in range(1,m):
    for j in range(n+1):
        if(j-c[i]>=0):
            dp[i][j]=min(dp[i-1][j],dp[i][j-c[i]]+1)
        else:
            dp[i][j]=dp[i-1][j]
print(dp[m-1][n])


Measured memory_bytes: 43208
#include <iostream>

using namespace std;


long long gcd( long long a, long long b)
{
	while ( 1 ) {
		if ( a < b ) swap( a, b );
		if ( !b ) break;
		a %= b;
	}

	return a;
}

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

	long long *A = new long long [N];
	for ( int i = 0; i < N; i ++ ) {
		cin >> A[i];
	}

	long long gmax = 0;

	long long *LGCD = new long long [N];
	long long *RGCD = new long long [N];
	long long last;
	
	last = A[0];
	LGCD[0] = 0;
	for ( int i = 1; i < N; i ++ ) {
		last = gcd( last, A[i] );
		LGCD[i] = last;
	}

	last = A[N-1];
	RGCD[N-1] = 0;
	for ( int i = N-2; i >= 0; i -- ) {
		last = gcd( last, A[i]);
		RGCD[i] = last;
	}

//for ( int i = 0; i < N; i ++ ) cout << LGCD[i] << " ";
//cout << endl;
//for ( int i = 0; i < N; i ++ ) cout << RGCD[i] << " ";
//cout << endl;


	for ( int skip = 0; skip < N; skip ++ ) {
//cout << "skip " << skip << ":";
		// 0 - skip-1
		long long lgcd = 0;
		if ( skip == 0 ) {

		} else if ( skip == 1 ) {
			lgcd = A[0];
		} else if (  skip >= 2 ) {
			lgcd = LGCD[skip - 1];
		}

		// skip+1  - N-1
		long long rgcd = 0;
		if ( skip == N-1 ) {

		} else if ( skip == N-2 ) {
			rgcd = A[N-1];
		} else if ( skip <= N-3 ) {
			rgcd = RGCD[skip+1];
		}
		
		long long g;
		if ( lgcd == 0 ) {
			g = rgcd;
		} if ( rgcd == 0 ) {
			g = lgcd;
		} else {
			g = gcd( lgcd, rgcd );
		}

		if ( g > gmax ) gmax = g;

//cout << lgcd << " " << rgcd << " " << g << endl;


	}

	cout << gmax << endl;

	return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); ++i)
 
int main(void) {
    string s;
    int K, n;
    cin >> s >> K;
    n = s.size()-1;
    rep(i, n) {
        int p = 'z'-s[i]+1;
        if(s[i] != 'a' && K >= p) {
            K -= p;
            s[i] = 'a';
        }
    }
    s[n] = 'a' + (s[n]-'a'+K)%26;
    cout << s << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#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;

int ans=n*(n-1)/2+m*(m-1)/2;
cout << ans <<endl;

}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int M = 1e5 + 5;
int a[M];
int main(){
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	int minn = 999999999;
	for(int i=0;i+k-1<n;i++){
		minn = min(minn,a[i+k-1]-a[i]);
	}
	cout<<minn<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<time.h>
#include<ctime>
#include<functional>
using namespace std;
typedef long long ll;
int inf = 1000000000;
template<typename T>
T GCD(T a, T b) {
	while (max(a, b) % min(a, b)) {
		if (a > b)a = a % b;
		else b = b % a;
	}
	return min(a, b);
}
template<typename T>
T LCM(T a, T b) {
	return a / GCD(a, b)*b;
}
int main() {
	int n, h, a[100000], b[100000], ans = 0;
	cin >> n >> h;
	for (int i = 0; i<n; i++)cin >> a[i] >> b[i];
	sort(a, a + n);
	sort(b, b + n);
	for (int i = n - 1; i >= 0; i--) {
		if (a[n - 1]<b[i]) {
			h -= b[i];
			ans++;
			if (h <= 0) {
				cout << ans << endl;
				return 0;
			}
		}
		else {
			ans += (h + a[n - 1] - 1) / a[n - 1];
			cout << ans << endl;
			return 0;
		}
	}
	ans += (h + a[n - 1] - 1) / a[n - 1];
	cout << ans << endl;
	return 0;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

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

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

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

  int N, K, Q;
  cin >> N >> K >> Q;
  vint A(N);
  rep(i, N) cin >> A[i];

  int ans = inf;
  rep(i, N) {
    int l = 0, r = 0;
    vint vec;
    while(l < N) {
      priority_queue<int, vector<int>, greater<int> > que;
      while(r < N && A[i] <= A[r]) {
	que.push(A[r]);
	++r;
      }
      while((int)que.size() >= K) {
	vec.push_back(que.top());
	que.pop();
      }
      ++r;
      l = r;
      //cout<<i<<" "<<r<<endl;
    }
    if((int)vec.size() < Q) continue;
    sort(all(vec));
    //cout<<i<<endl;
    //cout<<vec[Q-1]<<" "<<vec[0]<<endl;
    chmin(ans, vec[Q-1]-vec[0]);
  }
  cout << ans << endl;

  return 0;
}


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

string a,b;
int cnt=1;
vector<char> v;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>a>>b;
	auto A=a.begin();
	auto B=b.begin();
	while(A!=a.end() || B!=b.end()){
		if(cnt%2!=0){
			v.push_back(*A);
			++A;
		}
		else{
			v.push_back(*B);
			++B;
		}
		cnt++;
	}
	for(auto it=v.begin();it!=v.end();++it)
		cout<<*it;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
int n;
string s;
inline char ck(char c)
{
	if (((int)c)+n<='Z') return (char)((int)c+n);
	return (char)((int)c-26+n);
}
int main()
{
	
	scanf("%d",&n);
	cin>>s;
	int len=s.size();
	for (int i=0;i<len;i++) printf("%c",ck(s[i])); puts("");
	return 0;
}

Measured memory_bytes: 256
# ABC177
# B Substring
# 文字列sの中に文字列tを作る時、何回修正が必要か？
# 全探索で文字列sを文字列t文字づつ抜き出して
# 一番、不一致文字数が少ないのが答え
s = input()
t = input()
ls = len(s)
lt = len(t)
ans = 10000

# ls-lt+1文字列tのlt文字に、後ろが足りないのは探索しない
for i in range(ls - lt + 1):
    score = 0
    U = s[i:i + lt]  # チェック用文字列Uはs[i]からs[i+lt]までの文字列
    for j in range(lt):  # lt文字数分チェックする
        # U文字列とT文字列を1文字目から全文字不一致かチェック
        if U[j] != t[j]:
            score += 1  # 不一致なら1を足す（最後は不一致な文字数がscoreになる）
    ans = min(ans, score)  # ansとscoreの小さい方を返す

print(ans)


Measured memory_bytes: 9116
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S divup_L(S a, T b){
  return (a+b-1)/b;
}
int main(){
  int A, B, res;
  rd(A);
  rd(B);
  res =divup_L((B-1),(A-1));
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190902-1

// --- original code ---
// {
//   int A, B, res;
//   rd(A,B);
//   res = (B-1) /+ (A-1);
//   wt(res);
// }


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

constexpr int dh[4] = {0, 1, 0, -1};
constexpr int dw[4] = {1, 0, -1, 0};
struct Pos {
    int h, w;
};


int main() {
    int H, W;
    cin >> H >> W;
    vector<string> s(H);
    for (int i = 0; i < H; ++i) cin >> s[i];

    int ans = 0;
    for (int h = 0; h < H; ++h) {
        for (int w = 0; w < W; ++w) {
            vector<vector<int>> dist(H, vector<int>(W, -1));
            if (s[h][w] == '#' or dist[h][w] != -1) continue;
            // BFS //
            queue<Pos> que; que.push({h, w});
            dist[h][w] = 0;
            while(not que.empty()) {
                const Pos now = que.front(); que.pop();
                for (int i = 0; i < 4; ++i) {
                    const int nh = now.h + dh[i];
                    const int nw = now.w + dw[i];
                    if (nh < 0 or nh >= H) continue;
                    if (nw < 0 or nw >= W) continue;
                    if (s[nh][nw] == '#') continue;
                    if (dist[nh][nw] != -1) continue;
                    dist[nh][nw] = dist[now.h][now.w] + 1;
                    que.push({nh, nw});
                }
            }
            for (int i = 0; i < H; ++i) {
                for (int j = 0; j < W; ++j) {
                    ans = max(ans, dist[i][j]);
                }
            }
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612