akhauriyash/Code-Regression huggingface dataset:
#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>
#include <unordered_map>
using namespace std;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}
 
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
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 T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
 
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
 
 
 
int main() {
    int N;
    while (cin >> N) {
        vector<int> a(N+1);
        for (int i = 1; i <= N; ++i) cin >> a[i];
 
 
        vector<long long> res(N+1);
        for (int i = N; i >= 1; --i) {
            long long p = 0;
            for (int k = i*2; k <= N; k += i) p += res[k];
            p %= 2;
            if (a[i] == p) res[i] = 0;
            else res[i] = 1;
        }
 
        vector<long long> ans;
        for (int i = 1; i <= N; ++i) {
            if (res[i] == 1) ans.push_back(i);
        }
        cout << ans.size() << endl;
        for (auto r : ans) cout << r << " ";
        cout << endl;
    }
}

Measured memory_bytes: 4340
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
int point;
int anscost;
vector<int> Ans;
int edge[11][11];


void solve(vector<int> & Path,int pathpointer,int cost,int now,int n){
  if (cost > anscost){
    anscost=cost;
    Ans = Path;
#ifdef DEBUG
    cout << "cost update " << cost << endl;
    for(int i=0;i<pathpointer;i++){
      cout <<Ans[i] << " ";
    }
    cout << endl;
#endif

    point = pathpointer;
  }
  
  for(int i=1;i<n+1;i++){

    if ( edge[now][i] == -1)continue;
    Path[pathpointer]=i;
    int temp=edge[now][i];
    edge[now][i]=-1;
    edge[i][now]=-1;
    solve(Path,pathpointer+1,cost+temp,i,n);
    edge[now][i]=edge[i][now]=temp;
    
  }
  
  return;
}

main(){
  int n,r;
  while(cin >> n >> r && n){
    anscost = 0;
    point =0;
    Ans.resize(r);
    vector<int> Path(r,0);
    for(int i=0;i<11;i++){
      for(int j=0;j<11;j++){
        edge[i][j]=-1;
      }
    }
    for(int i=0;i<r;i++){
      int f,t,cost;
      cin >> f >> t >> cost;
      edge[f][t]=edge[t][f]=cost;
    }
    
    for(int i=1;i<n+1;i++){
      Path[0]=i;
      solve(Path,1,0,i,n);
    }
    
    cout << anscost << endl;
    for(int i=0;i<point;i++){
      if ( i)cout << " ";
      cout << Ans[i] ;
    }
    cout << endl;
    
  }
  return false;
}

Measured memory_bytes: 0
# 解説を参考に作成
# #11254823を参考


def solve():
    S = input()
    mod = 10 ** 9 + 7

    '''
    桁数毎・余りの数字ごとのdpを作成するにあたり、mapを作る.
    たとえば新しい数字Yは前の数字Xの右側に新たに桁を作って
        Y = X(前の数字) * 10 + i(0 <= i <= 9)
    と表せる.
    この Y の余りは、
        Y % 13 = ((X % 13) * 10 + i) % 13
    と表せるので、10 * 13 のマップであらかじめ計算しておくことができる.
    このマップを以下で作っている.
        modmap[新しい桁の数字i][新しい余り(Y % 13 = k)] = 前の数字の時の余り(X % 13 = j)
    '''
    modmap = []
    for i in range(10):
        modmap.append([0] * 13)
        for j in range(13):
            k = (j * 10 + i) % 13
            modmap[i][k] = j

    # なぜ最初を1にするのか？
    # → Sの先頭に 0 を固定でつけても結果は変化しない. また付けた場合の最初の計算では余り0となる.
    # → どんなパターンでも共通の初期状態として使用できる.
    dp = [1] + [0] * 12
    for s in S:
        if s == '?':
            dp = [sum(dp[l] for l in modlist) % mod for modlist in zip(*modmap)]
        else:
            modlist = modmap[int(s)]
            dp = [dp[modlist[l]] % mod for l in range(13)]

    print(dp[5])


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3188
#include <iostream>

using namespace std;

int main()
{
    long long int n,a,b;
    cin>>n>>a>>b;
    if(a+b==0)
    {
        cout<<0;
        return 0;
    }
    if(n%(a+b)<=a)
    cout<<(n/(a+b)*a)+n%(a+b);
    else
    {
        cout<<(n/(a+b)*a)+a;
    }
    return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]

#[macro_use]
mod _input {
    use std::fmt;
    use std::io::{self, Read};
    use std::str::{self, FromStr};

    macro_rules! input {
        ($($name:ident : $t:tt),*,) => {
            input!($($name: $t),*)
        };
        ($($name:ident : $t:tt),*) => {
            let mut _scanned = ::_input::Scanned::new(::std::io::stdin(), 1024);
            $(
                let $name = _read_value!(_scanned, $t);
            )*
        };
    }

    macro_rules! _read_value {
        ($scanned:expr, ($($t:tt),*)) => {
            ($(_read_value!($scanned, $t)),*)
        };
        ($scanned:expr, [$t:tt; $n:expr]) => {
            (0..$n).map(|_| _read_value!($scanned, $t)).collect::<Vec<_>>()
        };
        ($scanned:expr, _bytes) => {
            _read_value!($scanned, String).into_bytes()
        };
        ($scanned:expr, _1based) => {
            _read_value!($scanned, usize) - 1
        };
        ($scanned:expr, $t:ty) => {
            $scanned.next::<$t>()
        };
    }

    #[derive(Default)]
    pub struct Scanned {
        buf: Vec<u8>,
        pos: usize,
    }

    impl Scanned {
        pub fn new<R: Read>(mut input: R, estimated: usize) -> Self {
            let mut buf_ = Vec::with_capacity(estimated);
            let _ = io::copy(&mut input, &mut buf_).unwrap();
            if buf_.last() != Some(&b'\n') {
                buf_.push(b'\n');
            }
            debug_assert!(str::from_utf8(&buf_).is_ok());
            debug_assert!(buf_.iter().all(|&c| u32::from(c) <= 0x7F));
            Scanned { buf: buf_, pos: 0 }
        }

        #[inline]
        pub fn next<T: FromStr>(&mut self) -> T
        where
            T::Err: fmt::Debug,
        {
            let mut start = None;
            loop {
                match (self.buf[self.pos], start.is_some()) {
                    (b' ', true) | (b'\n', true) => break,
                    (_, true) | (b' ', false) | (b'\n', false) => self.pos += 1,
                    (_, false) => start = Some(self.pos),
                }
            }
            let target = &self.buf[start.unwrap()..self.pos];
            unsafe { str::from_utf8_unchecked(target) }.parse().unwrap()
        }
    }
}

use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::{self, BufWriter, Read, Stderr, StderrLock, Stdout, StdoutLock, Write};
use std::num::{ParseFloatError, ParseIntError};
use std::ops::{
    Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign,
    Mul, MulAssign, Neg, Not, Rem, RemAssign, Sub, SubAssign,
};
use std::str::{self, FromStr};
use std::{char, cmp, f32, f64, fmt, i16, i32, i64, i8, mem, thread, u16, u32, u64, u8};

fn main() {
    input! {
        t: f64,
        x: f64,
    }
    println!("{}", t / x);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cctype>
#include <map>
using namespace std;

int main() {
	map<char, int> cntMap;
	for (char c = 'a'; c <= 'z'; c++) {
		cntMap.emplace(c, 0);
	}

	char c;
	while (cin >> c) {
		c = tolower(c);
		if (cntMap.count(c)) {
			cntMap.at(c)++;
		}
	}
	
	for (auto& pair : cntMap) {
		cout << pair.first << " : " << pair.second << endl;
	}

	return 0;
}



Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool used[200005];
ll ans[200005]={0};
int main(){
  ll n,x;
  cin>>n>>x;
  ll m=2*n-1;
  if(x==1||x==m){
    cout<<"No"<<endl;
    return 0;
  }
  for(int i=1;i<=m;i++) used[i]=false;
  if(n==2){
    cout<<"Yes"<<endl;
    for(int i=1;i<=3;i++) cout<<i<<endl;
    return 0;
  }
  if(x==2){
    ans[n]=x;
    ans[n-1]=1;
    ans[n-2]=m-1;
    ans[n+1]=m;
    used[1]=true;
    used[x]=true;
    used[m-1]=true;
    used[m]=true;
  }
  else{
    ans[n]=x;
    ans[n-1]=m;
    ans[n-2]=2;
    ans[n+1]=1;
    used[x]=true;
    used[m]=true;
    used[1]=true;
    used[2]=true;
  }
  ll ps=1;
  for(int i=1;i<=m;i++){
    if(ans[i]>0) continue;
    while(used[ps]) ps++;
    ans[i]=ps;
    used[ps]=true;
  }
  cout<<"Yes"<<endl;
  for(int i=1;i<=m;i++) cout<<ans[i]<<endl;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int a,b,c,num;
  cin >>a >>b >>c;
  
  num = a+b+c;
  
  if(num>=22)  cout << "bust" << endl;
  
   if(num<=21)  cout << "win" << endl;
  
 
  
}

Measured memory_bytes: 256
#include<stdio.h>
#define INFINITY 1000000000

typedef struct {
  int a;
  char c;
}kouzou;

int partition(kouzou A[],int p,int r){
  int x,i,j;
  kouzou v;
  x=A[r].a;
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j].a<=x){
      i++;
      v=A[i];
      A[i]=A[j];
      A[j]=v;
    }
  }
  v=A[i+1];
  A[i+1]=A[r];
  A[r]=v;
  return i+1;
}


void quicksort(kouzou A[],int p,int r){
  int q;
  if(p<r){
    q=partition(A,p,r);
    quicksort(A,p,q-1);
    quicksort(A,q+1,r);
  }
}


void merge(kouzou A[],int left,int mid,int right){
  int n1,n2,i,k,j;
  n1=mid-left;
  n2=right-mid;

  kouzou l[n1+1],r[n2+1];
  for(i=0;i<n1;i++)l[i]=A[left+i];
  for(i=0;i<n2;i++)r[i]=A[mid+i];
  l[n1].a=INFINITY;
  r[n2].a=INFINITY;
  i=j=0;
  for(k=left;k<right;k++){
    if(l[i].a<=r[j].a){
      A[k]=l[i];
      i+=1;
    }
    else {
      A[k]=r[j];
      j+=1;
    }

  }
}

void mergesort(kouzou A[],int left,int right){

  int mid,i=0;
  if(left+1<right){
    mid=(left+right)/2;
    mergesort(A,left,mid);
    mergesort(A,mid,right);
    merge(A,left,mid,right);
  }
}
int main(){
  int n,i;
  kouzou A[100000],B[100000];
    scanf("%d",&n);
    for(i=0;i<n;i++)scanf(" %c %d",&A[i].c,&A[i].a);
    for(i=0;i<n;i++)B[i]=A[i];
    quicksort(A,0,n-1);
    mergesort(B,0,n);
    for(i=0;i<n;i++){
      if(A[i].c!=B[i].c){
        printf("Not stable\n");
        break;
      }
      if(i==n-1)printf("Stable\n");
    }
    for(i=0;i<n;i++)printf("%c %d\n",A[i].c,A[i].a);
    return 0;
}



Measured memory_bytes: 4140
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <sstream>
#include <list>
#include <array>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <iterator>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 1e5 + 10;
inline int lc(int x)  {return x << 1;}
inline int rc(int x)  {return x << 1 | 1;}



int main(void) {
    FAST_IO;
    
    ll a, b;
    cin >> a >> b;
    ll g = __gcd(a, b);
    vector<ll> v;
    for (ll i = 1; i * i <= g; i++) {
        if (g % i == 0) {
            v.push_back(i);
            if (i * i == g) continue;
            v.push_back(g / i);
        }
    }
    int cnt = v.size();
    // cout << cnt << endl;
    sort(v.begin(),v.end());
    for (int i = v.size() - 1; i > 0; i--) {
        for (int j = i - 1; j > 0; j--) {
            if (v[i] % v[j] == 0) {
                cnt--;
                // cout << v[j] << endl;
                break;  
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <cassert>
#include <unordered_map>

#define _(x) { cout << #x << " = " << x << " "; }

const double E = 1e-8;
const double PI = acos(-1);

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes\n";
        return 0;
    }

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



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

int main(){
  ll N;
  cin>>N;
  
  ll min=INF;
  for(ll i=0;i<=N;i++){
    ll sum=0;
    ll t=i;
    while(t>0){
      sum+=(t)%6;
      t/=6;
    }
    
    ll s=N-i;
    while(s>0){
      sum+=s%9;
      s/=9;
    }
    
    if(sum<min){
      min=sum;
    }
  }
  
  cout<<min<<endl;
  
}


  
  
  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int find(int x, auto &pa) { return pa[x] < 0 ? x : pa[x] = find(pa[x], pa); }
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, q; cin >> n >> q;
    vector<int> pa(n, -1);
    while (q--) {
        int t, u, v; cin >> t >> u >> v;
        int x = find(u, pa);
        int y = find(v, pa);
        if (t == 0) {
            if (x == y)
                continue;
            if (pa[x] > pa[y])
                swap(x, y);
            pa[x] += pa[y];
            pa[y] = x;
        } else {
            cout << (x == y) << '\n';
        }
    }
}

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

int main() {
    int n; cin >> n;
    int a[n], b[n], c[n-1];
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        a[i]--;
    }
    for(int i = 0; i < n; ++i) cin >> b[i];
    for(int i = 0; i < n - 1; ++i) cin >> c[i];

    int ans = 0;
    for(int i = 0; i < n; i++) {
        ans += b[a[i]];
        if(i != n - 1 && a[i + 1] - a[i] == 1) {
            ans += c[a[i]];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
works = []
for i in range(N):
    temp= list(map(int,input().split(" ")))
    works.append(temp)
works.sort(key=lambda x:x[1])
sche ={}
for work in works:
    if work[1] not in sche:
        sche[work[1]] = work[0]
    else:
        sche[work[1]] += work[0]
acc = 0
sche = sorted(sche.items(), key=lambda x:x[0])

for k,v in sche:
    acc += v
    if acc > k:
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 79952
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	long long ans=0,n,m;
	cin>>n>>m;
	for(int i=m;i<=n+1;i++)
	{
		ans+=i*(n+1-i)+1;
	}
	ans%=1000000007;
	cout<<ans;
	return 0;
 } 

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

int maxIndex(int x[],int n) {
	int retu = -1;
	int max = -1;
	for (int i = 0; i < n; ++i) {
		if (x[i] > max) {
			max = x[i];
			retu = i;
		}
	}
	return retu;
}

int main(void) {
	int n, k;
	int l[50];
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &l[i]);
	}
	int index = 0;
	int ans = 0;
	for (int i = 0; i < k; ++i) {
		index = maxIndex(l, n);
		ans += l[index];
		l[index] = 0;
	}
	printf("%d", ans);

	return 0;
}

Measured memory_bytes: 128
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0354

#include<bits/stdc++.h>
const int N = 2e5 + 5;
const int inf = 1e9 + 7;
using namespace std;

vector <int> mv[2];
int n, w, h, x[N], y[N], p[N], ans[N];
char s[N];

void cal(vector <int> & a, bool ck){
    if (a.size() == 0) return;
    queue <int> Q1, Q2;
    for (int i = 0; i < a.size(); i++) if (s[a[i]] == 'E') Q1.push(a[i]);
    for (int i = (int)a.size() - 1; i >= 0; i--) if (s[a[i]] == 'S') Q2.push(a[i]);

//    if (x[a[0]] + y[a[0]] == 6 && ck)
//    for (int i = 0; i < a.size(); i++)
//        cout << a[i] << " " << x[a[i]] << " " << y[a[i]] << " " << s[a[i]] << "\n";
//
//    cout << "\n";
    for (int i = 0; i < a.size(); i++){
        int E = ((Q1.size()) ? Q1.front() : inf), S = ((Q2.size()) ? Q2.front() : inf);
        if (E != inf && (S == inf || w - x[E] < h - y[S])){
            ans[a[i]] = w - x[E] + 1 + ck;
            Q1.pop();
        }
        else{
            ans[a.back()] = h - y[S] + 1 + ck;
            a.pop_back();
            Q2.pop(); i--;
        }
    }
//    cout << "\n";
}

void change(vector <int> & a){
    for (int i = 1; i < a.size(); i++){
        if (x[a[i]] == x[a[i-1]] && y[a[i]] == y[a[i-1]]) swap(s[a[i]], s[a[i-1]]), swap(a[i], a[i-1]);
    }
}

void solve(vector <int> & a, bool ck){
    vector <int> X, Y;
    for (int i = 0; i < a.size(); i++){
        int sum = x[a[i]] + y[a[i]];
        for (; i < a.size(); i++){
            if (x[a[i]] + y[a[i]] != sum) break;
            if (x[a[i]] % 2 == 0) X.push_back(a[i]);
            else Y.push_back(a[i]);
        }
        cal(X, ck); X.clear();
        cal(Y, ck); Y.clear();
        i--;
    }
}

bool cmp(int a, int b){
    if (x[a]+y[a] < x[b]+y[b]) return true;
    if (x[a]+y[a] == x[b]+y[b] && x[a] > x[b]) return true;
    if (x[a] == x[b] && y[a] == y[b] && s[a] == 'E') return true;
    return false;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> w >> h >> n;
    vector <int> vc;
    for (int i = 1; i <= n; i++) {
        cin >> x[i] >> y[i] >> s[i];
        if (s[i] == 'E') vc.push_back(w - x[i] + 1);
        else vc.push_back(h - y[i] + 1);
        if((x[i] + y[i]) % 2 == 1){
            if (s[i] == 'E') x[i]++;
            else y[i]++;
            mv[1].push_back(i);
        }
        else{
            mv[0].push_back(i);
        }
    }

    sort(mv[0].begin(), mv[0].end(), cmp);
    sort(mv[1].begin(), mv[1].end(), cmp);

    change(mv[1]);

    solve(mv[0], 0); solve(mv[1], 1);

    sort(vc.begin(), vc.end());

    for (int i = 1; i <= n; i++) p[i] = i;
    sort(p+1, p+1+n, [](int x, int y){return ((ans[x] < ans[y]) || (ans[x] == ans[y] && x < y));});
    for (int i = 1; i <= n; i++) cout <<  p[i] << "\n";
}



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

#define for0(i, n) for (ll i = 0; i < (ll)(n); ++i) // 0 based indexing
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (ll i = (ll)(l); i <= (ll)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (ll i = (ll)(n); i >= 1; --i) // reverse 1 based

#define ff first
#define ss second
#define pb push_back

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll a;
  	string s;
  	cin >> a >> s;
  	if( a >= 3200 ) cout << s << endl;
  else cout << "red" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
const long long MOD = 1000000007;

int A, B, Q;
ll s[100002];
ll t[100002];

int getl(ll (&ary)[100002], int C, ll x) {
    int l, r;
    l = 0;
    r = C + 1;
    while (r - l > 1) {
        int m = (l + r) / 2;
        if (ary[m] <= x) {
            l = m;
        } else {
            r = m;
        }
    }
    return l;
}

int getr(ll (&ary)[100002], int C, ll x) {
    int l, r;
    l = 0;
    r = C + 1;
    while (r - l > 1) {
        int m = (l + r) / 2;
        if (x <= ary[m]) {
            r = m;
        } else {
            l = m;
        }
    }
    return r;
}

void solve() {
    ll x;
    cin >> x;

    ll ans = 10000000000000;
    ll tmp;
    ll pos;

    pos = s[getr(s, A, x)];
    tmp = pos - x;
    tmp += min(pos - t[getl(t, B, pos)], t[getr(t, B, pos)] - pos);
    ans = min(ans, tmp);


    pos = s[getl(s, A, x)];
    tmp = x - pos;
    tmp += min(pos - t[getl(t, B, pos)], t[getr(t, B, pos)] - pos);
    ans = min(ans, tmp);

    pos = t[getr(t, B, x)];
    tmp = pos - x;
    tmp += min(pos - s[getl(s, A, pos)], s[getr(s, A, pos)] - pos);
    ans = min(ans, tmp);

    pos = t[getl(t, B, x)];
    tmp = x - pos;
    tmp += min(pos - s[getl(s, A, pos)], s[getr(s, A, pos)] - pos);
    ans = min(ans, tmp);


    cout << ans << endl;

}

int main() {
    cin >> A >> B >> Q;
    for (int i = 1; i <= A; i++) {
        cin >> s[i];
    }
    s[0] = -10000000000000;
    s[A + 1] = 10000000000000;

    for (int i = 1; i <= B; i++) {
        cin >> t[i];
    }
    t[0] = -10000000000000;
    t[B + 1] = 10000000000000;

    while(Q--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 2816
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define quickIO()	{cin.tie(0);	cout.sync_with_stdio(false);}
#define reach(i,a)	for(auto i:a)
#define rep(i,n)	for(int i=0;i<(int)n;i++)
#define REP(i,n)	for(int i=0;i<=(int)n;i++)
#define srep(i,a,n)	for(int i=a;i<(int)n;i++)
#define SREP(i,a,n)	for(int i=a;i<=(int)n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define pb	push_back
#define fst	first
#define scn second
int bitcnt(ll x) {
	x = ((x & 0xAAAAAAAAAAAAAAAA) >> 1) + (x & 0x5555555555555555);
	x = ((x & 0xCCCCCCCCCCCCCCCC) >> 2) + (x & 0x3333333333333333);
	x = ((x & 0xF0F0F0F0F0F0F0F0) >> 4) + (x & 0x0F0F0F0F0F0F0F0F);
	x = ((x & 0xFF00FF00FF00FF00) >> 8) + (x & 0x00FF00FF00FF00FF);
	x = ((x & 0xFFFF0000FFFF0000) >> 16) + (x & 0x0000FFFF0000FFFF);
	x = ((x & 0xFFFFFFFF00000000) >> 32) + (x & 0x00000000FFFFFFFF);
	return x;
}
int bitcnt(int x) {
	x = ((x & 0xAAAAAAAA) >> 1) + (x & 0x55555555);
	x = ((x & 0xCCCCCCCC) >> 2) + (x & 0x33333333);
	x = ((x & 0xF0F0F0F0) >> 4) + (x & 0x0F0F0F0F);
	x = ((x & 0xFF00FF00) >> 8) + (x & 0x00FF00FF);
	x = ((x & 0xFFFF0000) >> 16) + (x & 0x0000FFFF);
	return x;
}
ll sqrt(ll x) {
	ll left = 0, right = x;
	rep(i, 100) {
		ll mid = (left + right) >> 1;
		if (mid*mid <= x)	left = mid;
		else	right = mid;
	}
	return left;
}
ll gcd(ll a, ll b) {
	return a%b == 0 ? b : gcd(b, a%b);
}
#define debug(x)	printf("Case #%d: ", x)
#define DEBUG 0
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ld eps = 1e-9;
const int dx[] = { 1,0,-1,0,0 };
const int dy[] = { 0,1,0,-1,0 };

int main() {
	ll n, start;	cin >> n >> start;
	vector<ll> x(n);
	vector<ll> p(n);
	rep(i, n)	cin >> x[i] >> p[i];
	vector<ll> pos;
	int s = 0, t = n - 1;
	while (x[s]<start && start<x[t]) {
		if (p[s] < p[t]) {
			pos.push_back(x[s]);
			p[t] += p[s];
			s++;
		}
		else {
			pos.push_back(x[t]);
			p[s] += p[t];
			t--;
		}
	}
	while (s != t) {
		if (x[s] < start)	pos.push_back(x[s++]);
		else	pos.push_back(x[t--]);
	}
	pos.push_back(x[s]);
	ll cur = start, ret = 0;
	rrep(i, pos.size()) {
		ret += labs(pos[i] - cur);
		cur = pos[i];
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 2936
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int x = Integer.parseInt(st.nextToken());
        int a = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        if(Math.abs(x - a) < Math.abs(x - b))
            System.out.println("A");
        else System.out.println("B");
    }
}


Measured memory_bytes: 21076
import sys

n, m = map(int, input().split())
l, r = map(int, input().split())

sys.setrecursionlimit(100000)


def check(i, l, r):
    if i == m:
        return max(r - l + 1, 0)
    l_, r_ = map(int, input().split())
    nl = max(l, l_)
    nr = min(r, r_)
    return check(i + 1, nl, nr)


print(check(1, l, r))


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

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef set<int> si;
typedef set<ll> sll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;

const double pi = acos(-1.0);
const long long INF = 2e18;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define in insert
#define endl "\n"

#define sqr(a) ((a) * (a))
#define jor(a) !(a&1)// jor means EVEN number
#define bjor(a) (a&1)// bjor means ODD number

#define all(a)  a.begin(), a.end()
#define mem(arr, b) memset(arr, b, sizeof(arr)) //memset only for -1 and 0
//fill(a, a+n, 5) //fill for any value

#define for0(i,b) for(int i=0;i<(b);i++)
#define for1(i,b) for(int i=1;i<=(b);i++)
#define forab(i,a,b) for(int i=(a);i<=(b);i++)
#define forba(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))

#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fileRead freopen("input.txt", "r", stdin);
#define fileWrite freopen("output.txt", "w", stdout);

void print(int a[], int n){ // for testing or debugging
    for(int i=0;i<n;i++)cout<<a[i]<<" "; cout<<endl;
}

#define watch(x) cout << (#x) << " is " << (x) << endl

//-------------------------------------------------------------------


int main()
{
    FAST
    //fileRead
    int tc = 1;
    //cin>>tc;
    while(tc--)
    {
        int n; cin>>n;
        string s="ACL";
        for0(i,n) cout<<s;
    }
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
#define ll long long
#define debug(x) cerr << #x << ": " << x << endl
using namespace std;

int main(){
    ll N;  cin >> N;
    for(ll n=1; n<=3500; n++) for(ll h=1; h<=3500; h++){
        ll nume = N*h*n;
        ll deno = 4*h*n-N*n-N*h;
        if(deno > 0 && nume%deno==0){
            int w = nume/deno;
            cout << n << " " << h << " " << w << endl;
            return 0;
        }
    }
}


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

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

   ll sum = 0;

   for(int i=1;i<N+1;i++){
      if(i%15 != 0){
         if(i%5 != 0){
            if(i%3 != 0) sum += i;
         }
      }
   }
   cout << sum << endl;
   return 0;  
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}
const int INF = 1e18;

signed main() {
    int H, W;
    cin >> H >> W;
    map<char, int> mp;
    rep(i, H) rep(j, W) {
        char a;
        cin >> a;
        mp[a]++;
    }
    /*rep(i, 26) {
        cout << mp[char(i+'a')] << endl;
    }*/

    int f = (H/2) * (W/2);
    int t = (H%2 ? W/2 : 0) + (W%2 ? H/2 : 0);
    int o = (H%2 && W%2 ? 1 : 0);

    //cout << f  << " " << t << " " << o << endl;

    for(auto &p : mp) {
        if(4*f >= p.se) {
            f -= (p.se/4);
            mp[p.fi] = p.se%4;
        } else {
            mp[p.fi] -= 4*f;
            f = 0;
        }
        if(f==0) break;
    }
    for(auto &p : mp) {
        if(2*t >= p.se) {
            t -= (p.se/2);
            mp[p.fi] = p.se%2;
        } else {
            mp[p.fi] -= 2*t;
            t = 0;
        }
        if(t==0) break;
    }
    /*rep(i, 26) {
        cout << mp[char(i+'a')] << endl;
    }*/

    bool ok = false;
    if(o) {
    for(auto &p : mp) {
        if(ok) {
            if(p.se>=1) {
                ok = false;
                break;
            }
        } else {
            if(p.se==1) ok = true;
            else if(p.se>1) {
                ok = false;
                break;
            }
        }
    }
    } else {
        ok = true;
        for(auto &p : mp) {
            if(p.se) {
                ok = false;
                break;
            }
        }
    }

    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    

    return 0;
}

Measured memory_bytes: 256
N = int(input())
H_list = list(map(int,input().split()))

champ = 0
challenge = 0

for i,h in enumerate(H_list):
    #print(h)
    if i == len(H_list)-1:
        break
    elif h >= H_list[i+1]:
        #print("challengeに1足す")
        challenge += 1
        if challenge > champ:
            #print("champ更新")
            champ = challenge
    else:
        #print("challenge初期化")
        challenge = 0

print(champ)





Measured memory_bytes: 15020
from collections import deque
n,m = map(int,input().split())
e1 = [[] for i in range(n)]
e2 = [[] for i in range(n)]
l = []
for i in range(m):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    e1[a].append(b)
    e2[b].append(a)
    l.append([a,b,c])

def search(x,e):
    dis = [0]*n
    dis[x] = 1
    q = deque([])
    q.append(x)
    while q:
        now = q.popleft()
        for nex in e[now]:
            if dis[nex] == 0:
                dis[nex] = 1
                q.append(nex)

    return dis

dis1 = search(0,e1)
dis2 = search(n-1,e2)
dis = [0]*n
for i in range(n):
    if dis1[i] == 1 and dis2[i] == 1:
        dis[i] = 1

li = []
for i in range(m):
    a,b,c = l[i]
    if dis[a] == 1 and dis[b] == 1:
        li.append(l[i])

ans = [-float("INF")]*n
ans[0] = 0

for i in range(n):

    check = False
    for i,j,k in li:
        if ans[i]+k > ans[j]:
            ans[j] = ans[i]+k
            check = True
    
    if not check:
        print(ans[-1])
        exit()
print("inf")

Measured memory_bytes: 48104
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n = II()
B = [tuple(LI()) for _ in range(n)]

ans = 0
for a, b in B[::-1]:
    tmp = (a + ans) % b
    if tmp:
        ans += b - tmp

print(ans)


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

using namespace std;

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

    for (int i = 0; i < s.length(); i++) {
        if (s == t) {
            cout << "Yes" << endl;
            return 0;
        }
        s = s[s.length() - 1] + s;
        s.pop_back();
    }

    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int p[200005];
    p[n - 1] = 1;
    for(int i = n - 2; i >= 0; i--) p[i] = p[i + 1] * 10 % 2019;
    ll b[2019]{0};
    int k = 0;
    for(int i = n - 1; i >= 0; i--){
        k = (k + (s[i] - '0') * p[i]) % 2019;
        b[k]++;
    }
    ll ans = b[0] * (b[0] + 1) / 2;
    for(int i = 1; i < 2019; i++){
        ans += b[i] * (b[i] - 1) / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4552
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def debug(table, *args):
    ret = []
    for name, val in table.items():
        if val in args:
            ret.append('{}: {}'.format(name, val))
    print(' | '.join(ret), file=sys.stderr)


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True

def factorization(n):
    if n <= 1:
        return []

    ret = []
    while n > 2 and n % 2 == 0:
        ret.append(2)
        n //= 2
    i = 3
    while i <= math.sqrt(n):
        if n % i == 0:
            ret.append(i)
            n //= i
        else:
            i += 2
    ret.append(n)
    return ret


def main():
    X = I()

    for A in range(-200, 200):
        for B in range(-200, 200):
            if (A ** 5 - B ** 5) == X:
                print(A, B)
                return


if __name__ == '__main__':
    main()


Measured memory_bytes: 74852
using System;

namespace AtCoderDiverta2019_2A
{
    class Program
    {
        static void Main(string[] args)
        {
            int ans = 0;

            string[] s = Console.ReadLine().Split(' ');

            int N = int.Parse(s[0]);
            int M = int.Parse(s[1]);

            if (M == 1)
                ans = 0;
            else
                ans = N - M;

            Console.WriteLine(ans.ToString());
        }
    }
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()

const char newl = '\n';

using namespace std;
using ll = long long;

auto main() -> int
{
	cin.tie(0);
  	ios::sync_with_stdio(0);

	int N; cin >> N;
    string mozi; cin >> mozi;
    
    if(mozi.size() <= N) cout << mozi << newl;
    else cout << mozi.substr(0, N) << "..." << newl;
    
    return 0;
}

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

int main() {
  int n; cin >> n;
  vector<int> a(n+1), b(n);
  rep(i,n+1) cin >> a[i];
  rep(i,n) cin >> b[i];
  ll ans = 0;
  rep(i,n) {
    if (a[i] > b[i]) {
        a[i] -= b[i];
        ans += b[i];
    } else {
      ans += a[i];
      b[i] -= a[i];
      a[i] = 0;
      if (a[i+1] > b[i]) {
        ans += b[i];
        a[i+1] -= b[i];
        b[i] = 0;
      } else {
        ans += a[i+1];
        b[i] -= a[i+1];
        a[i+1] = 0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4056
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXH=800;
const int MAXW=800;
const int DX[]={-1,0,+1,0},DY[]={0,+1,0,-1};

int h,w,K;
char g[MAXH][MAXW+1];
int d[MAXH][MAXW];

int qx[MAXH*MAXW],qy[MAXH*MAXW],qhead,qtail;

void run() {
	scanf("%d%d%d",&h,&w,&K);
	REP(x,h) scanf("%s",g[x]);
	int sx=-1,sy=-1; REP(x,h) REP(y,w) if(g[x][y]=='S') g[x][y]='.',sx=x,sy=y; assert(sx!=-1&&sy!=-1);

	REP(x,h) REP(y,w) d[x][y]=INT_MAX;
	qhead=qtail=0; d[sx][sy]=0; qx[qhead]=sx,qy[qhead]=sy,++qhead;
	while(qtail<qhead) {
		int x=qx[qtail],y=qy[qtail]; ++qtail; if(d[x][y]>=K) continue;
		REP(k,4) {
			int nx=x+DX[k],ny=y+DY[k]; if(nx<0||nx>=h||ny<0||ny>=w||d[nx][ny]!=INT_MAX||g[nx][ny]=='#') continue;
			d[nx][ny]=d[x][y]+1; qx[qhead]=nx,qy[qhead]=ny,++qhead;
		}
	}
	//REP(x,h) { REP(y,w) printf("%2d ",d[x][y]); puts(""); } puts("");
	qhead=qtail=0; REP(x,h) REP(y,w) if(d[x][y]!=INT_MAX) qx[qhead]=x,qy[qhead]=y,++qhead;
	while(qtail<qhead) {
		int x=qx[qtail],y=qy[qtail]; ++qtail;
		REP(k,4) {
			int nx=x+DX[k],ny=y+DY[k]; if(nx<0||nx>=h||ny<0||ny>=w||d[nx][ny]!=INT_MAX) continue;
			d[nx][ny]=max(K,d[x][y])+1; qx[qhead]=nx,qy[qhead]=ny,++qhead;
		}
	}
	//REP(x,h) { REP(y,w) printf("%2d ",d[x][y]); puts(""); } puts("");
	int ret=INT_MAX; REP(x,h) REP(y,w) if(x==0||y==0||x==h-1||y==w-1) ret=min(ret,d[x][y]); printf("%d\n",(ret+K-1)/K);
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 8320
#include <stdio.h>
#include <iostream>
#define MOD 1000000007LL

using namespace std;

typedef long long ll;

int main() {
	int h,w,k;
	cin >> h >> w >> k;

	ll wtow[8][8] = {};
	for(int bits = 0; bits < (1<<(w-1)); bits++) {
		bool seiki = true;
		for(int i = 0; i < w-2; i++) {
			if((bits&(1<<i))!=0 && (bits&(1<<(i+1)))!=0) {
				seiki = false;
				break;
			}
		}
		if(seiki) {
			for(int i = 0; i < w; i++) {
				if((bits&(1<<i))!=0) {
					wtow[i][i+1]++;
					wtow[i+1][i]++;
					i++;
				}else {
					wtow[i][i]++;
				}
			}
		}
	}
/*
	for(int i = 0; i < 8; i++) {
		for(int j = 0; j < 8; j++) {
			printf("%d ",wtow[i][j]);
		}
		printf("\n");
	}
*/
	ll ans_arr[8][2] = {1};
	for(int i = 0; i < h; i++) {
		int ni = i%2;
		int ai = (i+1)%2;
		for(int j = 0; j < w; j++) {
			for(int k = 0; k < w; k++) {
				ans_arr[k][ai] += ans_arr[j][ni]*wtow[j][k];
			}
		}
		for(int j = 0; j < w; j++) ans_arr[j][ni] = 0;
		for(int j = 0; j < w; j++) ans_arr[j][ai] %= MOD;
	}
/*
	for(int i = 0; i < w; i++) {
		cout << ans_arr[i][(h)%2] << endl;
	}
*/
	cout << ans_arr[k-1][h%2] << endl;

	return 0;
}


Measured memory_bytes: 256
//#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>  
#include<cstdio>  
#include<fstream>  
#include<iomanip>
#include<algorithm>  
#include<cmath>  
#include<deque>  
#include<vector>  
#include<assert.h>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include<queue>  
#include<string>  
#include<cstring>  
#include<map>  
#include<stack>  
#include<time.h>
#include<set>
#include <random>
#define pb push_back
#define pii pair<int, int>
#define mod 1000000007
#define pi acos(-1)
#define eps 0.00000001
#define mst(a,i) memset(a,i,sizeof(a))
#define fore(i,fa,fb) for(i=fa;i<=fb;++i)
#define all(n) (n.begin(),n.end())
#define F first
#define S second
typedef long long ll;
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int i, j, k, m, n;
	char a, b;
	cin >> a >> b;
	if (a == b)
		cout << "H" << endl;
	else cout << "D" << endl;
	/*
	if (a == 'H')
	{
		if (b == 'H')
			cout << 'H';
		else cout << 'D';
	}
	else
	{
		if (b == 'H')
			cout << 'D';
		else cout << 'H';
	}
	*/
	return 0;
}

Measured memory_bytes: 256
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

K = int(input())

ans = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            ans += gcd(gcd(a, b),c)

print(ans)

Measured memory_bytes: 73456
/******************************************
* AHAM BRAHMASHMI ;) *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define F first
#define S second


int main()
{

#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
//ios_base& scientific (ios_base& str);

	ll h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	ll time;
	if (h2 == h1)
		time = abs(m2 - m1);
	else
		time  = abs(60 - m1) + abs(h2 - h1 - 1) * 60 + abs(m2);
	cout << max(time - k, 0ll) << "\n";
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  int l=1,r=1;
  int number=0;
  int i;
  for( i=0; i< N; i++){
    cin >> l >> r;
    number += r - l + 1;
  }
  
  cout << number << endl;
 
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var x, a, b float64
	fmt.Scan(&x, &a, &b)
	if math.Abs(a-x) < math.Abs(b-x) {
		fmt.Println("A")
	} else {
		fmt.Println("B")
	}
}


Measured memory_bytes: 512
#include <stdio.h>
#define N 1000

int main(void) {
	int n,i,j,k,m,l,hen[3];
	int idx;
	int tof[N];
	char *str[2] = {"YES","NO"};
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		for(j=0;j<3;j++){
			scanf("%d",&hen[j]);
		}
		m = hen[0];
		k = 0;
		for(l=1;l<3;l++){
			if(m<hen[l]){
				m = hen[l];
				k = l;
			}
		}
		switch(k){
			case 0:
				idx = hen[1]*hen[1]+hen[2]*hen[2];
				break;
			case 1:
				idx = hen[0]*hen[0]+hen[2]*hen[2];
				break;
			case 2:
				idx = hen[0]*hen[0]+hen[1]*hen[1];
				break;
		}
		if(m*m == idx){
			tof[i]=0;
		}else{
			tof[i]=1;
		}
	}
	for(k=0;k<n;k++){
		printf("%s\n",str[tof[k]]);
	}
	
	return 0;
}

Measured memory_bytes: 584
#include<iostream>
#include<vector>
#include<unordered_map>

using namespace std;

class UnionFind {
public:
  	vector<int> parents, ranks;
    UnionFind(int n) {
      	parents.resize(n);
      	ranks.resize(n);
        for (int i = 0; i < n; ++i)
            parents[i] = i;
    }
    
    int find(int x) {
        if (x != parents[x])
            parents[x] = find(parents[x]);
        return parents[x];
    }
    
    void unite(int x, int y) {
        int px = find(x);
        int py = find(y);
        if (px == py) return;
      
        if (ranks[px] > ranks[py])
            parents[py] = px;
        else if (ranks[px] < ranks[py])
            parents[px] = py;
        else {
            parents[py] = px;
            ranks[px]++;
        }
    }
};

int main() {
  int n, m, k, a, b;
  cin >> n >> m >> k;
  int ans[n] = {};
  UnionFind uf(n);
  vector<int> friendships(n), blockships(n);
  
  while(m--) {
    cin >> a >> b;
    friendships[a-1]++;
    friendships[b-1]++;
    uf.unite(a-1, b-1);
  }
  
  while(k--) {
    cin >> a >> b;
    if (uf.find(a-1) == uf.find(b-1)) {
      blockships[a-1]++;
      blockships[b-1]++;
    }
  }
  
  unordered_map<int, int> infos;
  for (int i = 0; i < n; ++i) infos[uf.find(i)]++;
  for (int i = 0; i < n; ++i)
    cout << infos[uf.parents[i]] - friendships[i] - blockships[i] - 1 << ' ';
  cout << '\n';
  
  return 0;
}

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

#define ll long long

int main() {
	ll n, a[20000], ans = 0, hoge;
	bool flag;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		hoge = a[i];
		flag = true;
		while (flag) {
			if (hoge % 2 == 0) {
				hoge = hoge / 2;
				ans++;
			}
			else flag = false;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include <vector>
#include <cstdio>
#include <algorithm>

namespace
{
	std::vector<unsigned int> altitude(10);
}

int main()
{
	for (unsigned int i = 0; i < 10; i++)
	{
		std::scanf("%u", &altitude[i]);
	}
	std::sort(altitude.begin(), altitude.end(), std::greater<unsigned int>());
	for (unsigned int i = 0; i < 3; i++)
	{
		std::printf("%u\n", altitude[i]);
	}
}


Measured memory_bytes: 2796
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
//#include <stack>
#include <climits>
#include <map>
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

int n;

int main() {
    cin >> n;
    vector<int> p(n);
    int sum = 0;
    Rep(i,n){
        cin >> p[i];
        sum += p[i];
    }
    sum -= *max_element(all(p))/2;
    put(sum);
    return 0;
}


Measured memory_bytes: 256
//2つの数の差は操作ごとに(-1)倍される
#include <iostream>
#define int long long
using namespace std;

signed main() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	if (k % 2) cout << b - a << endl;
	else cout << a - b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[])
{
    int n, i, j;
	cin >> n;
	vector<ll> h(n);
	int max = 0;
	for (i = 0; i < n; i++) 
		cin >> h[i];

	for (i = 0; i < n - 1;) {
		int tmp = 0;
		for (j = i + 1; j < n; j++) {
			if (h[j - 1] >= h[j])
				tmp++;
			else
				break;
		}
	    if (max < tmp)
			max = tmp;
		i = j;
	}

	cout << max << endl;
	return 0;
}


Measured memory_bytes: 1024
/*
 * atcoder ABC 135 : B. 0 or 1 Swap
 * Solution : editorial
 * 20 august 2019
 *
 */


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

int N;

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

	cin >> N;

	vector<int> v(N);
	rep(i,N) cin >> v[i];

	int k = 0;
	rep(i,N) if(v[i] != i+1) k++;

	if(k <= 2){
		cout << "YES" << '\n';
	}else cout << "NO" << '\n';

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

int main() {
	int n, l; cin >> n >> l;
	vector<int> a(n);
	rep(i, n) a[i] = l + i;

	int sum = 0;
	rep(i, n) sum += a[i];

	int ans = 1e9;
	rep(i, n) {
		int t = sum - a[i];
		if (abs(t - sum) < abs(ans - sum)) ans = t;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <set>
#include <map>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
static const ll MAX_L = (ll)1 << 62;

int main() {
	string s; cin >> s;
	reverse(s.begin(), s.end());

	ll i = 0;
	string t;

	while (i < s.size()) {
		t = s.substr(i, 5);
		if (t == "maerd") {
			i += 5;
			continue;
		}
		else if (t == "esare") {
			i += 5;
			continue;
		}

		t = s.substr(i, 6);
		if (t == "resare") {
			i += 6;
			continue;
		}

		t = s.substr(i, 7);
		if (t == "remaerd") {
			i += 7;
			continue;
		}
		cout << "NO" << endl;
		return 0;
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 512