akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
using namespace std;
const long long INF = 1LL << 60;    // 1.15x10^18

// ------ graph ------ //
using Weight = long long;
using Flow = int;
struct Edge {
    int src, dst;
    Weight weight;
    Flow cap;
    Edge() : src(0), dst(0), weight(0) { }
    Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) { }
};
bool operator < (const Edge &e, const Edge &f) {
    return e.weight != f.weight ? e.weight > f.weight : // pqが降順のため
        e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
using Edges = vector<Edge>;
struct Graph {
    vector<Edges> adj;
    Graph(int n) : adj(n) { }
    int size() { return adj.size(); }
    Edges operator [] (int v) { return adj[v]; }
    void add_edge(int a, int b, Weight w = 1) { // graph
        adj[a].emplace_back(a, b, w);
        adj[b].emplace_back(b, a, w);
    }
    void add_arc(int a, int b, Weight w = 1) {  // digraph
        adj[a].emplace_back(a, b, w);
    }
};
using Array = vector<Weight>;
using Matrix = vector<Array>;

// ------ dijkstra ------ //
vector<Weight> dijkstra(Graph &g, int s) {
    int n = g.size();
    using state = tuple<Weight, int>;
    priority_queue<state> q;
    vector<Weight> dist(n, INF);
    dist[s] = 0;
    q.emplace(0, s);
    while (!q.empty()) {
        Weight d; int v;
        tie(d, v) = q.top(); q.pop(); d *= -1;
        if (dist[v] < d) continue;
        for (auto &e : g[v]) {
            if (dist[e.dst] > dist[v] + e.weight) {
                dist[e.dst] = dist[v] + e.weight;
                q.emplace(-dist[e.dst], e.dst);
            }
        }
    }
    return dist;
}
//---------------------------------------------------------------

int main() {
    int n; cin >> n;
    Graph G(n);
    for (int i = 0; i < n - 1; i++) {
        int u, v, w; cin >> u >> v >> w; u--, v--;
        G.add_edge(u, v, w);
    }
    vector<Weight> d = dijkstra(G, 0);
    for (int i = 0; i < n; i++) {
        cout << d[i] % 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 10112
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
 
 
signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
 
  int N, H, W;
  cin>>N>>H>>W;
  vector<int> x(N);
  cin>>x;
 
  vector<int> cnt( N * W + 100);
  for(int i=0;i<N;i++){
    if(i % 2 == 0) cnt[W * i + x[i]]++, cnt[W * i + x[i] + W]--;
    else cnt[W * i - x[i]]++, cnt[W * i - x[i] + W]--;
  }
  for(int i=1;i<N * W;i++) cnt[i] += cnt[i-1];
  int c = 0;
  for(int i=0;i<N * W;i++) if(cnt[i] == 0) c++;
  int ans = c * H;
  cout<<ans<<endl;
   
 
  return 0;
}


Measured memory_bytes: 3268
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define rep(n) for(int i=0;i<n;i+=1)
#define fill(c,v) memset(c,v,sizeof(c));
#define prarr(a,n) rep(n) cout<<a[i]<<" \n"[i==n-1]; 
#define sc(a) scanf("%d",&a);
#define scl(a) scanf("%lld",&a);
#define scf(a) ascanf("%f",&a);
#define ff first
#define ss second
#define pu push_back
#define inf 1000000001
#define MOD 1000000007 
#define INF 100000000000001
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll a,b,n;
    cin>>a>>b;
    n = (b-a)-1;
    cout<<(n*(n+1))/2 - a<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string S;
int main(){
    cin>>S;
    if(S.find("KIHABAR")!=string::npos){
        if(S!="KIHABAR"s&&S!="AKIHABAR"s&&S!="KIHABARA"s&&S!="AKIHABARA"s)
            cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    else if(S.find("KIHABR")!=string::npos){
        if(S!="KIHABR"s&&S!="AKIHABR"s&&S!="KIHABRA"s&&S!="AKIHABRA"s)
            cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    else if(S.find("KIHBAR")!=string::npos){
        if(S!="KIHBAR"s&&S!="AKIHBAR"s&&S!="KIHBARA"s&&S!="AKIHBARA")
            cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    else if(S.find("KIHBR")!=string::npos){
        if(S!="KIHBR"s&&S!="AKIHBR"s&&S!="KIHBRA"&&S!="AKIHBRA"s)
            cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
int main(){
  int n,ptr=0,res=0;
  cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++) cin>>v[i]; 
  sort(v.begin(),v.end());
  while(ptr<n){
    int cc=v[ptr],f=0;
    while(v[ptr]==cc){
      f++;
      ptr++;
    }
    res+=f%2;
  }
  cout<<res<<endl;
}

Measured memory_bytes: 640
#include <iostream>

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

typedef long long ll;

using namespace std;

int main(){
  ll x, y;
  cin >> x >> y;
  
  int ans = 0;
  while(x<=y){
    x *= 2;
    ans++;
  }
  cout << ans << endl;
}

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


int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  if(s.size()%2!=0){
    cout<<"No"<<endl;
    return 0;
  }
  rep(i,n/2){
    if(s.at(i)!=s.at(i+n/2)){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}
    
  

        
    
     
      
    
  
  
  
 



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

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

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

    int ans = 0;
    for (int j = 0; j < n; j++)
    {
        if (h[j] >= k)
            ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll H; cin>>H;
  ll ans=0,num=1;
  while(H>0){
    H=H/2;
    ans+=num;
    num*=2;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

ll counting = 0;

ll calc(ll num) {
  // cout << num << endl;
  // cout << "---" << endl;

  if (num >= 1e5) {
    counting += 5;
    num %= (ll)1e5;
  }
  if (num < 2) {
    return 1;
  } else {
    ll ans = 0;
    if (num * calc(num - 2) % (ll)1e5 == num * calc(num - 2)) {
      ans = num * calc(num - 2);
    } else {
      ans = num * calc(num - 2) % (ll)1e5;
      counting += 5;
    }
    return ans;
  }
}

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

  if (n % 2 == 1) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = 0, count = n / 2;
  while (count != 0) {
    count /= 5;
    ans += count;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main()
{
    unsigned long long k, a, b;
    cin >> k >> a >> b;

    if (a >= b - 2) {
        cout << k + 1 << endl;
        return 0;
    }

    if (k <= a - 1 + 1) {
        cout << k + 1 << endl;
        return 0;
    }

    unsigned long long count = 0;
    unsigned long long one = 1;
    unsigned long long two = 2;

    count = a + ((b - a) * ((k - a + one) / two)) + ((k - a + one) % two);

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 384
from collections import deque
s = input()
q = int(input())

s = deque(s)
t = 0
for _ in range(q):
  query = list(map(str, input().split()))
  if query[0] == "1": t = 1 - t
  else:
    if t == 0:
      if query[1] == "1": s.appendleft(query[2])
      elif query[1] == "2": s.append(query[2])
    elif t == 1:
      if query[1] == "1": s.append(query[2])
      elif query[1] == "2": s.appendleft(query[2])
if t == 1:print("".join(s)[::-1])
else: print("".join(s))

Measured memory_bytes: 14324
S=input()
N=len(S)+1
A=[0]*N
B=[0]*N
for i in range(1,N):
  if S[i-1]=="<":
    A[i]=A[i-1]+1
for i in range(N-1)[::-1]:
  if S[i]==">":
    B[i]=B[i+1]+1
ans=[max(A[i],B[i]) for i in range(N)]
print(sum(ans))

Measured memory_bytes: 86092
#include <iostream>

using namespace std;

int main(){
  int a,b,t;
  cin >> a >> b >> t;

  int c_time = 0;
  int ans = 0;
  while(c_time <= t-a){
    c_time += a;
    ans += b;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> anys;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(anys{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	int N, M;
	ll S;
	cin >> N >> M >> S;
	vector<int> U(M), V(M), A(M), B(M);
	for(int i=0; i<M; i++){
		int u, v;
		ll a, b;
		cin >> u >> v >> a >> b;
		u--; v--;
		U[i] = u;
		V[i] = v;
		A[i] = a;
		B[i] = b;
	}
	vector<ll> C(N), D(N);
	for(int i=0; i<N; i++){
		cin >> C[i] >> D[i];
	}

	ll Xmax = 5010;
	vector<vector<pair<int, ll>>> graph(N*Xmax);
	for(int i=0; i<N; i++){
		for(int x=0; x<Xmax; x++){
			if(x>0) graph[i+x*N].push_back({i+(x-1)*N, 0});
			graph[i+x*N].push_back({i+min(Xmax-1, (x+C[i]))*N, D[i]});
		}
	}

	for(int i=0; i<M; i++){
		for(int x=0; x<Xmax; x++){
			if(x-A[i]>=0){
				graph[U[i]+x*N].push_back({V[i]+(x-A[i])*N, B[i]});
				graph[V[i]+x*N].push_back({U[i]+(x-A[i])*N, B[i]});
			}
		}
	}

	vector<ll> dist(N*Xmax, 1e18);
	priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> que;
	int s = min(S, Xmax-1)*N;
	dist[s] = 0;
	que.push({0, s});
	while(!que.empty()){
		auto p=que.top();
		int u = p.second;
		ll d = p.first;
		que.pop();
		if(dist[u] < d) continue;
		for(auto q: graph[u]){
			if(dist[u]+q.second<dist[q.first]){
				dist[q.first] = dist[u]+q.second;
				que.push({dist[q.first], q.first});
			}
		}
	}

	for(int i=1; i<N; i++){
		ll ans = 1e18;
		for(int x=0; x<Xmax; x++){
			ans=min(ans, dist[i+x*N]);
			if(x<10) debug(i, x, dist[i+x*N]);
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 49560
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""


N =  int(sys.stdin.readline())
S =  list(sys.stdin.readline().rstrip())

if 'Y' in S:
    print("Four")
else:
    print("Three")



Measured memory_bytes: 63980
import sys
input=sys.stdin.readline

N = int(input())
P = []
for i in range(N):
    n,v = input().split()
    P.append((n, int(v), i+1))
P = sorted(P, key=lambda x:x[1], reverse=True)
P = sorted(P, key=lambda x:x[0])
for n,v,i in P:
    print(i)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    a = root(a);
    return -Parent[a];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(a < b) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }

  bool issame(int a, int b){
    return root(a) == root(b);
  }
};

int main(){
  int n; cin >> n;
  vi a(n); rep(i,n) cin >> a[i];

  int color = 1e5;
  int ans = 0;
  rep(i,n-1) {
    if(a[i] == a[i+1]){
      a[i+1] = color--;
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-

# abc123_a

# input
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
# output
ans = e-a <= k
ans = 'Yay!' if ans else ':('
print(ans)


Measured memory_bytes: 3060
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: isize,
        b: isize
    }
    let ans = if a * b % 2 == 0 { "Even" } else { "Odd" };
    println!("{}", ans);
}


Measured memory_bytes: 4352
package main

import (
        "bufio"
        "fmt"
        "os"
        "strconv"
        "strings"
)

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
        sc.Scan()
        return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
        buf := make([]byte, 0, 1000000)
        for {
                l, p, e := rdr.ReadLine()
                if e != nil {
                        panic(e)
                }
                buf = append(buf, l...)
                if !p {
                        break
                }
        }
        return string(buf)
}

func strSprit(str string) []string {
        cols := strings.Split(str, " ")
        return cols
}

func parseInt(str string) int {
        n, _ := strconv.Atoi(str)
        return n
}

func intSprit(str string) []int {
        strs := strSprit(str)
        cols := make([]int, len(strs))
        for i, v := range strs {
                cols[i] = parseInt(v)
        }
        return cols
}

type SortSlice []int

func (s SortSlice) Len() int {
        return len(s)
}

func (s SortSlice) Swap(i, j int) {
        s[i], s[j] = s[j], s[i]
}

func (s SortSlice) Less(i, j int) bool {
        return s[i] < s[j]
}

func reverseString(str string) string {
        buf := []rune(str)
        for i, j := 0, len(buf)-1; i < j; i, j = i+1, j-1 {
                buf[i], buf[j] = buf[j], buf[i]
        }
        return string(buf)
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////

func main() {
        line := nextLine()
        N := parseInt(line)

        line = nextLine()
        a1 := intSprit(line)

        line = nextLine()
        a2 := intSprit(line)

        candy := 0

        tmpcandy := 0
        for i := 0; i < N; i++ {
                tmpcandy += a1[i]
                loopcandy := tmpcandy
                for j := i; j < N; j++ {
                        loopcandy += a2[j]
                }
                if candy < loopcandy {
                        candy = loopcandy
                }
        }

        fmt.Println(candy)
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
int main(){
  int N; cin >> N;
  int MY[N];
  for(int i=0;i<N;i++){
    cin >> MY[i];
  }
  int L[N];
  int R[N];
  L[0]=MY[0];
  R[N-1]=MY[N-1];
  for(int i=1;i<N;i++){
    L[i]=gcd(L[i-1], MY[i]);
  }
  for(int i=N-2;i>=0;i--){
    R[i]=gcd(R[i+1], MY[i]);
  }
  int ans=max(L[N-2], R[1]);
  int GCD=0;
  for(int i=1;i<N-1;i++){
    GCD=gcd(L[i-1], R[i+1]);
    ans=max(GCD,ans);
  }
  cout << ans << endl;
}
    

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<bool> one_to_i(n, false);
  vector<bool> i_to_n(n, false);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (a == 1)
      one_to_i[b - 1] = true;
    else if (b == n)
      i_to_n[a - 1] = true;
  }
  bool ans = false;
  for(int i = 0; i < n; i++) {
    if (one_to_i[i] == true && i_to_n[i] == true) ans = true;
  }
  if (ans)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <deque>
using namespace std;
using P = pair<int,int>;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

int main(){
    int n; cin >> n;
    vector<int>h(n),x(n);
    rep(i,n){
         cin >> h[i];
         x[i] = h[i];
    }
    sort(x.begin(),x.end());
    int cnt = 0;
    rep(i,n){
        if(h[i]!=x[i]){
            cnt++;
        }
    }
    if(cnt==2 || cnt ==0)cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}




Measured memory_bytes: 256
import qualified Data.Set as S
main=do
 n<-readLn
 p<-words<$>getLine
 q<-words<$>getLine
 print(abs((f n n (S.fromList p) p 0)-(f n n (S.fromList q) q 0)))
  where f n m s p i |m==0      =i
                    |otherwise =f n (m-1) (S.delete (head p) s) (tail p) (i*m+(S.findIndex(head p)s))

Measured memory_bytes: 508
#include <iostream>
#include <string>
using namespace std;
int main(){
    long x;
    long src = 0;
    cin >> x;
    src += (int)(x / 500) * 1000;
    x = x % 500;
    src += (int)(x / 5) * 5;
    cout << src << endl;
    return 0;
}

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

typedef long long ll;


int N = 26;
int D;

vector<int> c(N+1);
vector<vector<int>> s;
vector<int> t;

ll now_score = 0;

ll greedy(){
    vector<int> last(N+1, 0);
    ll greedy_score=0;
    for(int d = 1; d <= D; d++){
        ll max_score = -1e9;
        vector<int> max_last;
        for(int n = 1; n <= N; n++){
            ll tmp_score = 0;
            vector<int> tmp_last(N+1);
            tmp_last = last;
            
            tmp_score +=  s[d][n];
            tmp_last[n] = d;
     
            int penalty = 0;
            for(int i = 1; i <= N; i++){
                penalty += c[i]*(d-tmp_last[i]);    
                
            }
            
            tmp_score -= penalty;

            if(max_score < tmp_score){
                max_score = tmp_score;
                max_last = tmp_last;
                t[d] = n;
            }                    
            
        }
        
        last = max_last;
        greedy_score += max_score;
    }

    return greedy_score;
}


ll scoring(){
    vector<int> last(N+1, 0);
    ll score = 0;
    for(int d = 1; d <= D; d++){

        score += s[d][t[d]];
        last[t[d]] = d;

        int penalty = 0;
        for(int i = 1; i <= N; i++){
            penalty += c[i]*(d-last[i]);    
        }
        
        score -= penalty;            
    }
    return score;
}


void exchange(int d, int x){
    swap(t[d], t[d+x]);

    ll swap_score = scoring();
    
    if(now_score >= swap_score){
        swap(t[d], t[d+x]);
    }else{
        now_score = swap_score;
    }

}

void pachinko(){
    srand((unsigned) time(NULL)); /* Use Mersenne Twister */
    for(int i=1; i<=D; i++){
        int pre = t[i];
        t[i] = rand()%26+1;

        ll pachi_score = scoring();
        if(now_score >= pachi_score){
            t[i] = pre;
        }else{
            now_score = pachi_score;
        }        
    }

}

int main(){
    clock_t start = clock();

    cin>> D;

    s.resize(D+1);
    for(int i=0; i<=D; i++){
        s[i].resize(N+1);
    }
    t.resize(D+1);

    for(int i=1; i<=N; i++){
        cin>>c[i];
    }
 
    for(int i=1; i<=D; i++){
        for(int j=1; j<=N; j++){
            cin>>s[i][j];
        }
    }
    for(int i=1; i<=D; i++){
        cin>>t[i];
    }

    now_score = greedy();

    clock_t now_time = clock();
    while((now_time - start)/CLOCKS_PER_SEC < 1){
  
        //乱数パチンコ
        pachinko();
        //解交換
        for(int x=1; x<D; x++){
            for(int d=1; d<=D-x; d++){
                exchange(d, x);
            }
        }
        now_time = clock();
    }

    for(int i=1; i<=D; i++){           
        cout<<t[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N ;
  vector<int> p(N);
  for(int i = 0; i< p.size(); i++)cin >> p.at(i);
  
  sort(p.begin(),p.end());

  int count = 1;
  int x = p.at(0);

  for(int i = 1; i<p.size(); i++){
    if(x != p.at(i)){
      if(i == N-1){
        count++;
      }
      
      else{
      x = p.at(i);
      count++;
    }
    }
  }
  cout << count << endl;
}
    

Measured memory_bytes: 256
# B - 105

def yakusu_rekkyo(n):
    yakusu = set()
    for i in range(1, int(pow(n, 0.5)+1)):
        if n%i == 0:
            yakusu.add(i)
            yakusu.add(n//i)
    return yakusu

N = int(input())
ans = 0
for i in range(105, N+1, 2):
    Y = yakusu_rekkyo(i)
    if len(Y) == 8:
        ans += 1
        
print(ans)

Measured memory_bytes: 9456
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A;
  cin  >> A;
  if(A==25) cout << "Christmas" << endl;
  else if(A==24) cout << "Christmas Eve" << endl;
  else if(A==23) cout << "Christmas Eve Eve" << endl;
  else cout << "Christmas Eve Eve Eve" << endl;
}
  


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> xs(n);
    for (int& x : xs) {
        cin >> x;
    }
    if (n % 3 != 0) {
        for (int x : xs) {
            if (x != 0) {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
        return 0;
    }
    sort(xs.begin(), xs.end());
    for (int j = 0; j < 3; ++j) {
        if (xs[j * n /3] != xs[(j+1) * n / 3 - 1]) {
            cout << "No" << endl;
            return 0;
        }
    }
    if ((xs[0] ^ xs[n/3] ^ xs[2*n/3]) == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


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

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    int ans = 0;
    int tmp2 = n;
    while(tmp2 > 0){
        int tmp = tmp2 % 10;
        tmp2 /= 10;
        ans += tmp;
    }
    if((n % ans==0)) cout<< "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
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 FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
typedef priority_queue<ll> PQ_HIGH;
typedef priority_queue<ll,VL,greater<ll>> PQ_LOW;//昇順

int main(){
  ll n;cin>>n;
  set<string> data;
  for(ll i=0;i<n;i++){
    string tmp;cin>>tmp;
    data.insert(tmp);
  }
  cout<<data.size()<<endl;
}

Measured memory_bytes: 19252
#include<bits/stdc++.h>
#define fr(i,x,y) for(int i=x;i<=y;++i)
#define rf(i,x,y) for(int i=x;i>=y;--i)
#define LL long long
using namespace std;
const int N=410,mod=1e9+7;
int a[N],b[N];
LL f[N][N],jc[N],qz[N][N];

void Mul(LL &x,LL y){
	x=(x*y)%mod;
}

void Add(LL &x,LL y){
	x=(x+y)%mod;
}

LL mul(LL x,LL y){
	return x*y%mod;
}

LL add(LL x,LL y){
	return (x+y+mod)%mod;
}

int main(){
	int n,c;scanf("%d%d",&n,&c);
	fr(i,1,n) scanf("%d",&a[i]);
	fr(i,1,n) scanf("%d",&b[i]);
	fr(i,1,N-1) jc[i]=1,qz[0][i]=qz[0][i-1]+1;
	fr(i,1,c)
		fr(j,1,N-1) Mul(jc[j],j),qz[i][j]=add(qz[i][j-1],jc[j]);
	f[0][0]=1;
	fr(i,1,n) fr(j,0,c){
		fr(k,0,j) Add(f[i][j],mul(f[i-1][j-k],add(qz[k][b[i]],-qz[k][a[i]-1])));
	}
	printf("%lld\n",f[n][c]);
	return 0;
}

Measured memory_bytes: 2816
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <time.h>

#include <string>

const int MAX_N = 200050;
int N;
long long x[MAX_N], XG;

long long coeff[MAX_N];

long long energy(const int num) {
    long long ret = 0;
    for (int i = 0; i < N; i++) {
        ret += x[N-i] * coeff[i/num];
    }
    ret += XG * num;
    ret += XG * N;
    return ret;
}

int main(int argc, char **argv) {
    std::cin >> N >> XG;

    for (int i = 1; i <= N; i++) {
        std::cin >> x[i];
    }

    coeff[0] = 5;
    for (int i = 1; i <= N; i++) {
        coeff[i] = i * 2 + 3;
    }

    long long ret = energy(1);
    if (N <= 2000) {
        for (int i = 2; i <= N; i++) {
            //std::cout << i << " " << energy(i) << std::endl;
            ret = std::min(ret, energy(i));
        }
    } else {
        if (energy(1) < energy(2) && energy(N-1) < energy(N)) {
            ret = energy(1);
        } else if (energy(1) > energy(2) && energy(N-1) > energy(N)) {
            ret = energy(N);
        } else {
            int lb = 1;
            int ub = N;
            while (lb + 2 < ub) {
                int mid = (lb + ub) / 2;

                long long v1 = energy(mid - 1);
                long long v2 = energy(mid);
                long long v3 = energy(mid + 1);

                ret = v2;

                if (v1 == v3) {
                    //ret = v2;
                    lb = mid - 1;
                    ub = mid + 1;
                    break;
                } else if (v1 < v2 && v2 < v3) {
                    ub = mid;
                } else if (v1 > v2 && v2 > v3) {
                    lb = mid;
                } else {
                    lb = mid - 1;
                    ub = mid + 1;
                    //ret = v2;
                    break; // 本当か？
                }
            }
            for (int i = std::max(1, lb - 5); i <= std::min(ub + 5, N); i++) {
                ret = std::min(ret, energy(i));
            }
        }
    }

    std::cout << ret << std::endl;
    
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = (int)1e6 + 34;
//const ll INF = (ll)1e18 + 41;
const int INF = (int)1e9 + 41;
const ll MD = (ll)1e9 + 7;

int dp[N];
void solve() {
    ll a, b;
    cin >> a >> b;
    cout << !!(a % b) << "\n";
}

int main() {
#ifdef MADE_BY_SERT
    freopen("a.in", "r", stdin);
    solve();
    solve();
#endif // MADE_BY_SERT
    solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
using P = pair<long long, long long>;

int main() {
  long long N, M;
  vector<long long> a;
  cin >> N >> M;
  rep(i, N) {
    long long temp;
    cin >> temp;
    a.push_back(temp);
  }

  long long sum = 0;
  rep(i, a.size()) {
    sum += a[i];
  }

  sort(a.begin(), a.end());
  long long ans = 0;
  rep(i, M) {
    long long key = a[a.size()-1];
    long long m = (key + 1) / 2;
    ans += m;
    key -= m;
    vector<long long>::iterator ind;
    ind = lower_bound(a.begin(), a.end(), key);
    a.pop_back();
    a.insert(ind, key);
  }

  // cout << ans << endl;

  ans = sum - ans;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4332
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
using namespace std;

int syc(long i,long Min,long Max){
	if(Min <= i && i <= Max){
		return 1;
	}else{
		exit(1);
		//return 0;
	}
}


int main(){
	
	int n,d;
	int count=0;
	double dist =0;
	int i,j,k;
	cin >> n >> d;
	syc(n,2,10);
	syc(d,1,10);
	int a[n][d];

	for(i=0;i<n;i++){
		for(j=0;j<d;j++){
			cin >> a[i][j];
		}
	}
	i=0;
	j=0;
	
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			for(k=0;k<d;k++){
				dist += (a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
			}
			if(round(sqrt(dist))==sqrt(dist)){
				count++;
			}
			dist = 0;
		}
	}
	
	cout << count << endl;
	
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}


class Item implements Comparable<Item> {

    public String S;
    public int P;
    public int idx;


    public Item (int idx, String name, int point) {
        this.idx = idx;
        this.S = name;
        this.P = point;
    }

    @Override
    public int compareTo(Item other) {
        int ret1 = S.compareTo(other.S);
        if (ret1 != 0) return ret1;

        return -Integer.compare(P, other.P);
    }
    
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        List<Item> list = new ArrayList<Item>();
        for (int i = 0; i < N; i++) {
            list.add(new Item(i + 1, sc.next(), sc.nextInt()));
        }

        Collections.sort(list);

        for (Item e : list) {
            System.out.println(e.idx);
        }

        return;
    }

}

Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n, m;
	cin >> n >> m;
	vector<int> a(m), b(m);
	vector<vector<int>> graph(n, vector<int>());
	rep(i, m) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		graph[a[i]].pb(b[i]);
		graph[b[i]].pb(a[i]);
	}
	int q;
	cin >> q;
	vector<int> v(q), d(q), c(q);
	rep(i, q) cin >> v[i] >> d[i] >> c[i];
	vector<int> ans(n);
	vector<int> cnt(n, -1);
	queue<P> que;
	for (int i = q - 1; i >= 0; i--) {
		vector<bool> flag(n);
		que.push(P(v[i] - 1, 0));
		while (!que.empty()) {
			P p = que.front(); que.pop();
			if (!chmax(cnt[p.first], d[i] - p.second)) continue;
			flag[p.first] = true;
			if(!ans[p.first]) ans[p.first] = c[i];
			if (p.second == d[i]) continue;
			for (int i : graph[p.first]) {
				if (!flag[i]) que.push(P(i, p.second + 1));
			}
		}
	}
	for (int i : ans) cout << i << endl;
}

Measured memory_bytes: 14068
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
using namespace std; 

int main() {
  int N;
  cin >> N;
  vector<int> h(N);
  rep(i, 0, N) cin >> h[i];
  
  vector<int> dp(N);
  dp[1] = abs(h[1] - h[0]);
  rep(i, 2, N) dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
  
  cout << dp[N - 1] << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>

using namespace std;

int main()
{
	int x, y;
	cin >> x >> y;
	
	int ans = 0;
	if (x == 1) {
		ans += 300000;
	} else if (x == 2) {
		ans += 200000;
	} else if (x == 3) {
		ans += 100000;
	}

	if (y == 1) {
		ans += 300000;
	} else if (y == 2) {
		ans += 200000;
	} else if (y == 3) {
		ans += 100000;
	}

	if (x == 1 && y == 1)
		ans += 400000;

	cout << ans << endl;
}


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


#define base 1000000007LL
#define ll long long
// unsigned long long int t = 10000000000000000003ULL;
#define ulint unsigned long long int
#define ld long double
#define X first
#define Y second
#define pb push_back
#define EPS 1e-15
#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())

#define ms(s, n) memset(s, n, sizeof(s))

#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define sqr(a) (a)*(a)

#define foru(i,a,b) for (ll i = (a); i <= (b); i++)
#define ford(i,a,b) for (ll i = (a); i >= (b); i--)
#define cbit(a) __builtin_popcount(a)
#define uni(a) (a).resize(unique(all(a)) - (a).begin())
#define cprint(n) printf("%.6lf + %.6lfi\n", (n).real(), (n).imag())

#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it !=(a).end(); it++)


using namespace std;
typedef pair<ll, ll> II;
typedef pair<int, int> ii;



struct Edge{
    ll u,v,w;
    Edge(ll u=0, ll v=0, ll w=0): u(u),v(v),w(w) {}
    bool operator < (Edge a){return w<a.w;}
};

const int M=1e5+7;
const int MM=4*M;
const ll MOD=base;
const int MAX=1e9;


inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll power(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = r * n % p; n = n * n % p;} return r;}
inline ll inverse(ll n, ll p=MOD){return power(n,p-2);}
ll search(ll a[], ll N, ll x){ ll l = 0, r = N - 1; while (l <= r){ ll mid = (l + r) / 2; if (x == a[mid]){ return 1; } else if (x < a[mid]){ r = mid - 1; } else if (x > a[mid]){ l = mid + 1; } } return -1; }

ll n;
ll a[M];
ll x;

int main(){
    ios::sync_with_stdio(0);
	cin >> n >> x;
	a[0] = x;
	for(int i=1;i<=n;i++){
		cin >> a[i];
	}
	sort(a, a + n + 1);
	if(n == 1){
		cout << a[1] - a[0]; return 0;
	}
	ll res = a[1] - a[0];
	for (int i = 2; i <= n; i++){
		res = gcd(res, a[i] - a[i-1]);
	}
	cout << res;
    return 0;
}





Measured memory_bytes: 1024
n,p=map(int,input().split())
S=input()
M=[0]*p
M[0]=1
ans=0

if p==2 or p==5: #最下位だけで決まるとき
    for i in range(n):
        s=int(S[i])
        if s%p==0:
            ans+=i+1
    
else: #それ以外は末尾に0をつけても割り切れるかが一致する
    cnt=10%p #10の累乗の剰余を記録しておく
    for i in range(n):
        s=int(S[n-1-i]) #右からi+1桁目を取り出す
        if i==0:
            r=s%p #剰余
        else:
            r=(cnt*s+r)%p #前の剰余にs*cntをたす
            cnt=cnt*10%p #更新
        if M[r]>=1: #同じ余りどうしで引き算すると割り切れる
            ans+=M[r]
        M[r]+=1

print(ans)

Measured memory_bytes: 3500
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
using namespace std;

int main() {
	bool m = false,y=false;
	char S[5];
	cin >> S;
	if ((S[2]=='0'&&S[3]!='0')|| (S[2] == '1'&&((S[3] == '0'|| S[3] == '1'|| S[3] == '2'))))m = true;
	if ((S[0] == '0'&&S[1] != '0') || (S[0] == '1' && ((S[1] == '0' || S[1] == '1' || S[1] == '2'))))y = true;
	if (m&&y)cout << "AMBIGUOUS";
	else if (m)cout << "YYMM";
	else if (y)cout << "MMYY";
	else cout << "NA";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define INF 1e9
typedef long long ll;

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

int main(void){
  int i,N;cin>>N;
  ll v[N];
  ll succ[N+1],pred[N+1];
  succ[0] = 0;
  pred[N] = 0;
  REP(i,N) cin >> v[i];
  REP(i,N){
    int I=N-i;
    succ[i+1] = gcd(v[i],succ[i]);
    pred[I-1] = gcd(v[I-1],pred[I]);
  }
  ll max_gcd=0;
  REP(i,N){
    ll gcd_i = gcd(succ[i],pred[i+1]);
    if(gcd_i > max_gcd) max_gcd = gcd_i;
  }
  cout << max_gcd << endl;
  return 0;
}


Measured memory_bytes: 2560
#!/usr/bin/env python
# -*- coding: utf-8 -*-

n = int(input().rstrip())
x_list = []
l_list = []
start_end_list = []

for i in range(n):
    xi, li = map(int, input().split())
    x_list.append(xi)
    l_list.append(li)

    start = xi - li
    if start < 0:
        start = 0
    end = xi + li

    start_end_list.append([start, end])

# endでソートする。二次元配列の二つ目の要素でソートする
# sortメソッドでラムダ式を使う
start_end_list.sort(key=lambda x: x[1])

past_end = 0
remain_machine = 0
for st_en in start_end_list:
    start, end = st_en
    if start >= past_end:
        past_end = end
        remain_machine += 1

print(remain_machine)



Measured memory_bytes: 75480
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
long long int lis[300000];
long long int kazu[300000];
long long int ans=0;
int N;
int main(){
    cin>>N;
    for(int i=0;i<N;i++){
        long long int a;
        cin>>a;
        ans+=a;
        lis[i]=a;
        kazu[a]++;
    }
    int Q;
    cin>>Q;
    for(int i=0;i<Q;i++){
        long long int a,b;
        cin>>a>>b;
        ans-=a*kazu[a];
        ans+=b*kazu[a];
        kazu[b]+=kazu[a];
        kazu[a]=0;
        cout<<ans<<endl;
    }

    return 0;
}


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

using namespace std;

bool isPrime[100005];

int cnt[100005];

void initSieve(){
	isPrime[2]=isPrime[3]=isPrime[5]=isPrime[7]=true;
	for(int i=5;i<100005;i+=2){
		for(int j=3;j*j<=i;j+=2){
			if(i%j==0)
				break;
			if((j+2)*(j+2)>i)
				isPrime[i]=true;
		}
	}
}

void solve(){

	for(int i=1;i<100005;i++){
		if(isPrime[i] and isPrime[(i+1)/2])
			cnt[i] = cnt[i-1]+1;
		else cnt[i]=cnt[i-1];
	}
}



int main() {

	int q;
	cin >> q;
	initSieve();
	solve();
	while(q--){
		int l,r;
		cin >> l >> r;
		int ans = cnt[r]-cnt[l];
		if(isPrime[l] and isPrime[(l+1)/2])
			ans++;
		cout << ans << endl;
	}


}

Measured memory_bytes: 1152
from collections import deque

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
res = deque([A[0]])
ans = 0
for i in range(1, N):
    ans += res.popleft()
    res.append(A[i])
    res.append(A[i])
print(ans)

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

all_vote = sum(A)

cnt = 0
for a in A:
    if a * 4 * m >= all_vote:
        cnt += 1

if cnt >= m:
    print("Yes")
else:
    print("No")
        
    

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, P;
    cin >> N >> P;
    int odd = 0, even = 0;
    REP(i,N){
        int A;
        cin >> A;
        if(A & 1) odd++;
        else even++;
    }
    ll ans = 0;
    if(odd == 0){
        if(P == 1) ans = 0;
        else ans = (1LL << N);
    }
    else ans = 1LL << (N-1);
    cout << ans << endl;
}

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


int main(){
    int n;
    ll h;
    cin >> n >> h;
    vector<ll> b(n);
    ll a = 0;
    rep(i, n){
        ll tmp;
        cin >> tmp;
        a = max(tmp, a);
        cin >> b.at(i);
    }
    sort(b.begin(), b.end(), greater<ll>());
    ll res = 0;
    ll i = 0;
    while (res < h) {
        if(i < n){
            res += max(b[i], a);
            i ++;
        }
        else{
            ll tmp = (h - res + a - 1) / a;
            i += tmp;
            break;
        }
    }
    cout << i << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define maxn 500000
int n, K, ans, a[maxn];

int read()
{
	int x = 0, k = 1;
	char c; c = getchar();
	while(c < '0' || c > '9') { if(c == '-') k = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * k;
}

struct edge
{
	int cnp, to[maxn], last[maxn], head[maxn];
	edge() { cnp = 2; }
	void add(int u, int v)
	{ to[cnp] = v, last[cnp] = head[u], head[u] = cnp ++; }
}E1;

int dfs(int u)
{
	int ret = 0;
	for(int i = E1.head[u]; i; i = E1.last[i])
	{
		int v = E1.to[i];
		ret = max(ret, dfs(v)); 
	}
	if(a[u] != 1 && u != 1 && ret + 1 - (u == 1) >= K) { ans ++; return 0; }
	return ret + 1;
}

int main()
{
	n = read(), K = read();
	for(int i = 1; i <= n; i ++)
	{
		a[i] = read();
		if(i != 1) E1.add(a[i], i);
	}
	dfs(1);
	printf("%d\n", ans + (a[1] != 1));
	return 0;
}

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

using namespace std;

using ll = long long;

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

    int n, k;
    cin >> n >> k;

    vector<int> l(n);
    for (int i = 0; i < n; ++i) cin >> l[i];
    sort(l.begin(), l.end(), greater<int>());

    int sum = 0;
    for (int i = 0; i < k; ++i) sum += l[i];

    cout << sum << endl;

    return 0;
}


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

int main(void) {
    int N, L;
    cin >> N >> L;

    int Before=0;
    vector<int> A(N);
    for(int i=0;i<N;i++) {
        A.at(i) = L+i;
        Before += L+i;
    }

    int After, ans=1<<21;
    for(int i=0;i<N;i++) {
        After = 0;
        for(int j=0;j<N;j++) {
            if(i!=j) After += A.at(j);
        }
        if(abs(ans-Before)>abs(After-Before)) ans = After;
    }

    cout << ans << endl;

    return (0);
}


Measured memory_bytes: 256