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

int main(){
    ios::sync_with_stdio(false);    cin.tie(NULL);  cout.tie(NULL);
    int n;  cin >> n;   vector<int> vec(n);
    if(n==1){
        cout << 1;   return 0;
    }
    for(int i=0;n>i;i++){
        cin >> vec[i];
    }
    int ans=1, artis=0;
    for(int i=1;n>i;i++){
        if(!artis){
            if(vec[i]>vec[i-1]){
                artis=1;
            }
            else if(vec[i-1]>vec[i]){
                artis=2;
            }
        }
        else if(artis==1 and vec[i-1]>vec[i]){
            ans++;  artis=0;
        }
        else if(artis==2 and vec[i-1]<vec[i]){
            ans++;  artis=0;
        }
    }
    cout << ans;
}


Measured memory_bytes: 640
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
//vector<int> s(10);
int main(void){
    
    int n,ans=0;
    cin>>n;
    vector<int> s(n);
    //cout<<n<<endl;
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    sort(s.begin(),s.end());
    for(int i=0;i<n-1;i++){
        ans+=s[i];
        //cout<<s[i]<<endl;
    }
    ans+=s[n-1]/2;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define EVEL 1

#ifndef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
    ll N,ans,a;
int main(){
    cin>>N;
    ans=(N/11)*2;
    ans+=(N%11==0)?0:(N%11<=6?1:2);
    cout<<ans<<endl;
    return 0;
}


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

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=a;i--)
#define per(i,b) gnr(i,0,b)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define fs first
#define sc second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif
#define tmp template<class t>

tmp void chmax(t&a,t b){if(a<b)a=b;}
tmp void chmin(t&a,t b){if(a>b)a=b;}

tmp using vc=vector<t>;
tmp using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.fs<<","<<p.sc<<"}";
}

tmp ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

constexpr ll ten(int n){
	return n==0?1:ten(n-1)*10;
}

tmp void mkuni(vc<t>&v){
	sort(all(v));
	v.erase(unique(all(v)),v.ed);
}

ll read(){ll i;cin>>i;return i;}

using ld=long double;
using cm=complex<ld>;
#define x real()
#define y imag()
const ld eps=1e-12;
int sgn(ld a){return a<-eps?-1:(a>eps?1:0);}
auto cmcmp=[](const cm&a,const cm&b){
	if(sgn(a.x-b.x))return a.x<b.x;
	else return sgn(a.y-b.y)<0;
};

struct ln{
	cm a,b;
	cm dir(){return b-a;}
};
ld dot(cm a,cm b){return a.x*b.x+a.y*b.y;}
ld crs(cm a,cm b){return a.x*b.y-a.y*b.x;}
int ccw(cm a,cm b){return sgn(crs(a,b));}
int ccw(cm a,cm b,cm c){return ccw(b-a,c-a);}
int ccw(ln a,cm b){return ccw(a.a,a.b,b);}

//(-2)[a,-1](0)[b,1](2)
int bet(cm a,cm b,cm c){
	cm d=b-a;
	ld e=dot(d,c-a);
	if(sgn(e)<=0)return sgn(e)-1;
	return sgn(e-norm(d))+1;
}

ld tri2(cm a,cm b,cm c){
	return crs(b-a,c-a);
}

ld area2(const vc<cm>&a){
	int n=a.size();
	ld b=0;
	rep(i,n)
		b+=crs(a[i],a[(i+1)%n]);
	return b;
}

cm readcm(){
	ld a,b;
	cin>>a>>b;
	return cm(a,b);
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(1);
	
	int t=0;
	while(1){
		int n=read();
		if(n==0)break;
		vc<cm> s(n);
		rep(i,n)s[i]=readcm();
		cout<<++t<<" "<<abs(area2(s)/2)<<endl;
	}
}



Measured memory_bytes: 3272
#include "iostream"
#include "algorithm"
using namespace std;

int main()
{
	int minNum = 1000000000,minasCount=0;
	int N, a[100000], x[100000];
	long long ans = 0;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
		if (a[i] < 0)
		{
			minasCount++;
		}
		x[i] = abs(a[i]);
		minNum = min(minNum, x[i]);
	}
	for (int i = 0; i < N; i++)
	{
		ans += x[i];
	}
	if (minasCount % 2 == 1)
	{
		ans -= (minNum*2);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define l long long
using namespace std;
const l mod = 1000000007;

l my_pow(l m, int n){
	l res = 1;
	while(n>0){
	if(n&1)res = m*res % mod;
		n >>= 1;
		m = m*m % mod;
	}
	return res;
}
int main(){
	int m,n;
	cin >> m >> n;
	cout << my_pow(m,n) % mod<< endl;
	return 0;
}

Measured memory_bytes: 3104
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>
 
 
int main()
{
    int a, b; std::cin >> a >> b;
    int outlet = 1, ans = 0;
    while(outlet<b)
    {
        outlet--;
        outlet += a;
        ans++;
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
//うるるん
#include<stdio.h>
#include<string.h>
int main(void)
{
  int i,N;
  char ch[6];
 scanf("%s",ch);
  N=strlen(ch);
 
  
 
  for(i=0;i+1<N;i++){
    if(ch[i]=='A' && ch[i+1]=='C'){
      printf("Yes\n");
      return 0;
    }
  }
  printf("No\n");
 
  return 0;
}

Measured memory_bytes: 128
n,m=map(int,input().split())
ans=[10**10]*n
edge=[[]for _ in range(n)]
for _ in range(m):
  l,r,d=map(int,input().split())
  l-=1;r-=1
  edge[l].append((r,d))
  edge[r].append((l,-d))
for i in range(n):
  if ans[i]==10**10:
    ans[i]=0
    Q=[i]
    while Q:
      P=[]
      for j in Q:
        for k,d in edge[j]:
          if ans[k]==10**10:
            ans[k]=ans[j]+d
            P.append(k)
          elif ans[j]+d!=ans[k]:
            print("No");exit()
      Q=P
print("Yes")

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

"""

input:
6
1 2 2 3
2 2 3 4
3 1 5
4 1 6
5 1 6
6 0

output:
1 1 12
2 2 11
3 3 8
4 9 10
5 4 7
6 5 6

"""
import sys

UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2


def dfs(v_init):
    global timer

    # init the first node of overall graph iterations(times >= 1)
    stack = list()
    stack.append(v_init)
    d_time[v_init] += timer
    # init end

    while stack:
        current = stack[-1]
        v_table = adj_table[current]
        visited[current] = VISITED_IN_STACK
        # if adj is None, current's adj(s) have been all visited
        adj = v_table.pop() if v_table else None

        if adj:
            if visited[adj] is UNVISITED:
                visited[adj] = VISITED_IN_STACK
                timer += 1
                d_time[adj] += timer
                stack.append(adj)
        else:
            stack.pop()
            visited[current] = POPPED_OUT
            timer += 1
            f_time[current] += timer

    return None


def dfs_init():
    global timer
    for v in range(v_num):
        if visited[v + 1] == UNVISITED:
            timer += 1
            dfs(v + 1)


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    v_num = int(_input[0])
    vertices = map(lambda x: x.split(), _input[1:])

    # config length = (v_num + 1)
    # stack = []
    visited = [UNVISITED] * (v_num + 1)
    d_time, f_time = ([0] * (v_num + 1) for _ in range(2))
    adj_table = tuple([] for _ in range(v_num + 1))
    for v_info in vertices:
        v_index, adj_num, *adj_list = map(int, v_info)
        # assert len(adj_list) == adj_num
        adj_table[v_index].extend(sorted(adj_list, reverse=True))

    # timing start from 1
    timer = 0
    dfs_init()

    for index, time_info in enumerate(zip(d_time[1:], f_time[1:]), 1):
        print(index, *time_info)

Measured memory_bytes: 7768
#include<iostream>
#include<algorithm>

using namespace std;

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

int main(){
    int N,a[1100];
    cin >> N;
    REP(i,N){
        cin >> a[i];
    }
    sort(a,a + N);
    int total = 0;
    REP(i,N-1){
        total += (a[i+1] - a[i]);
    }
    cout << total << 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;
typedef unsigned long ul;
typedef pair<ul, ul> P;

const int INF = 1e9;
const int MOD =1e9+7;
const ll LINF = 1e18;

int main(){
    string S;
    cin >> S;

    int num = 0;
    num = S.size() - 2;

    cout << S[0] + to_string(num) + S[S.size() - 1] << endl;
} 

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

const int INF = 1e9;

int main() {
  long long m, k;
  cin>>m>>k;
  if (m == 1) {
    if (k == 0) {
      cout<<"0 0 1 1"<<endl;
    } else {
      cout<<-1<<endl;
    }
  } else if (k > (1LL << m) - 1) {
    cout<<-1<<endl;
  } else {
    vector<int> v;
    for (int i=0; i<(1<<m); i++) {
      if (i != k) {
        v.push_back(i);
      }
    }
    v.push_back(k);
    for (int i=(1<<m)-1; i>=0; i--) {
      if (i != k) {
        v.push_back(i);
      }
    }
    v.push_back(k);
    for (int i=0; i<v.size(); i++) {
      cout<<v[i];
      if (i != v.size() - 1) {
        cout<<" ";
      }
    }
    cout<<endl;
  }
}

Measured memory_bytes: 2932
#include <cstdio>

using namespace std;

bool IsSym(int n)
{
    if (n / 10000 == n % 10 && (n / 1000) % 10 == (n / 10) % 10)
        return true;
    return false;
}

int main()
{
    int a, b;
    scanf("%d %d", &a, &b);

    int cnt = 0;
    for (int i = a; i <= b; i++)
    {
        if (IsSym(i))
            cnt++;
    }
    printf("%d", cnt);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int n;
  cin >> n;
  if (n == 0) COUT(1);
  else COUT(0);

  return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
int main(void){
int a,b,c,i,x;
x=0;
scanf("%d %d %d",&a,&b,&c);
for(i=a;i<=b;i++){
if(c%i==0){
x++;
}
}
printf("%d\n",x);
return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

#define MAX_NUM (1000000007)
#define PI 3.14159265358979323846

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

template <typename T>
static inline T ArraySum(vector<T>& A) {
  T res = 0;
  for (auto itr = A.begin(); itr < A.end(); ++itr) res += *itr;
  return res;
}

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

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

i64 modinv(i64 a, i64 m) {
  i64 b = m, u = 1, v = 0;
  while (b) {
    i64 t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

i64 My_Comb(u64 n, u64 k, i64 m) {
  if (n < k) return 0;
  if (k == 0 || n == k) return 1;
  u64 res = 1;
  k = (n / 2 < k) ? n - k : k;
  for (u64 i = 1; i <= k; ++i)
    res = (((res * (n + 1 - i)) % m) * modinv(i, m)) % m;
  return res;
}

i64 My_Pow(u64 a, u64 n, i64 m) {
  u64 tmp = n, calc = 1;
  while (tmp > 0) {
    if (tmp % 2) {
      tmp--;
      calc *= a;
      calc %= m;
    } else {
      a *= a;
      a %= m;
      tmp /= 2;
    }
  }
  return calc;
}

int main() {
  cout << setprecision(18);
  i64 N;
  cin >> N;
  vector<i64> a(N);
  ArrayInput(a);

  i64 tmp = 0;
  for (u32 i = 0; i < N; ++i) {
    tmp += a[i];
  }
  tmp /= N;
  tmp--;
  i64 res = MAX_NUM;
  for (i64 k = 0; k < 3; ++k) {
    i64 calc = 0;
    for (u32 i = 0; i < N; ++i) {
      calc += (a[i] - (tmp + k)) * (a[i] - (tmp + k));
    }
    if (calc < res) res = calc;
  }

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 15
#define INF 1000000005
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000005;
const int MOD = 1000000007;
int main(){
    int n=50;
    ll k;
    cin>>k;
    int w=k%n;
    ll p=n;
    vector<ll>a(n);
    REP(i,w){
        a[i]=p+n-w;
    }
    for(int i=w;i<n;i++){
        a[i]=p-w-1;
    }
    ll r=k/n;
    REP(i,n)a[i]+=r;
    OUT(n);
    REP(i,n)OUT(a[i]);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,long long> pint;
typedef long long ll;
const ll mod= 1e9+7;
const ll  longinf = 1LL<<60;
const int inf=1e9+7;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};


int main(){
  int n,m;
  cin>>n>>m;
  cout<<(n-1)*(m-1)<<endl;

  return 0;
  }

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお
vector<long long> makedivisor(long long n) {
    vector<long long> divisor;
    long long tmp = pow(n, 0.5) + 1;
    for (long long i = 1; i < tmp; i++) {
        if (n % i == 0) {
            divisor.push_back(i);
            if (i != n / i) {
                divisor.push_back(n / i);
            }
        }
    }
    sort(divisor.begin(), divisor.end());
    return divisor;
}
bool IsPrime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum+1; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll A, B; cin >> A >> B;
    vector<ll> a = makedivisor(A);
    vector<ll> b = makedivisor(B);
    vector<ll> v;
    for (ll x : a) {
        for (ll y : b) {
            if (x == y) {
                v.push_back(x);
            }
        }
    }
    int cnt = 0;
    rep(i,v.size()) {
        if(v[i]%2!=0 || v[i]==2) {
            if(IsPrime(v[i])) cnt++;
        }
    }
    cout << cnt+1 << endl;


    return 0;
}

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

int main() {

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


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

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    input! {
    a:usize,
    b:usize,
    mut c:[usize;a],
    }
    let mut s:usize=1;
    let mut sum:usize=0;
    for i in 0..a {
        sum+=c[i];
        if sum<=b {s+=1;}
    }
    println!("{}",s)
}

Measured memory_bytes: 2128
object Main extends App {
  import scala.io.StdIn._

  val Array(n, a, b, c) = readLine.trim.split(' ').map(_.toInt)
  println(
    n - a - b + c
  )
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def let[A](func: T ⇒ A): A = func(value)
  }
}


Measured memory_bytes: 44044
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<unistd.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#define ST first
#define ND second
#define ll long long
#define ld long double
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using namespace std;
using namespace __gnu_pbds;

// replace ll  with pair if multiset needed
typedef tree<pair<ll,ll>, null_type, greater<pair<ll,ll> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ordered_set secik;

const ll  INF = 1e9 + 9;
const ll  MOD = 1e9 + 7;
const long long LINF = (ll)1e18 + 3;

// secik.insert({x, t++});
// secik.erase(secik.lower_bound({x,-1}));
// *secik.find_by_order(x)).first << "\n";
// secik.order_of_key(x)

//random_device device;
//mt19937 gener(device());
//uniform_int_distribution<ll > gen(0,n-1);
//gen(gener); // generate random number

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

	string s; cin >> s;
	int res = 0;
	if(s[0] == 'R' || s[1] == 'R' || s[2] == 'R') res = 1;
	if((s[0] == 'R' && s[1] == 'R') || (s[1] == 'R' && s[2] == 'R')) res = 2;
	if(s == "RRR") res = 3;
	cout << res;
	
	return 0;
}

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

int main() {
  int count =0;
  string N;
  cin >> N;
  if(N =="SRR"|| N =="RRS"){
    cout << 2 << endl;
  }
  else if(N =="RRR"){
    cout << 3 << endl;
  }
  else if(N =="SSS"){
   	cout << 0 << endl;
  }
   else{
    cout << 1 << endl;
   }
}


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

int main() {
  int N; cin >> N;
  vector<pair<int, int>> ans;
  int tmp = (N % 2 == 0) ? N : N-1;
  for (int i = 1; i < N; i++) {
    for (int j = i+1; j <= N; j++) {
      if (j == tmp) continue;
      ans.push_back(make_pair(i, j));
    }
    tmp--;
  }
  cout << ans.size() << endl;
  for (auto p : ans) cout << p.first << " " << p.second << endl;
}

Measured memory_bytes: 384
import Control.Monad
 
import Data.Ord
import Data.List
import Data.Function
import Data.Maybe
 
import qualified Data.ByteString.Char8 as BS
 
import Debug.Trace
 
tuplify2 :: [a] -> (a, a)
tuplify2 (x:y:_) = (x, y)
tuplify2 _ = undefined
 
readInt = read :: String -> Integer
readIntTuple = tuplify2 . map readInt . words
readIntList = map readInt . words
 
getInt = readInt <$> getLine
getIntList = readIntList <$> getLine
getIntMatrix = map readIntList . lines <$> getContents
getIntTuple = readIntTuple <$> getLine
getIntTuples = map readIntTuple . lines <$> getContents

main = do
  [n,l] <- getIntList
  print $ f n l

-- リンゴ1の味はl
-- リンゴnの味はl+n+1
-- 総計はn*l+(n-1)n/2
-- 絶対値最小のリンゴを引けば良い、それは両端のいずれか又は0
f n l
  | taste1 > 0 && tasteN > 0 = tasteSum-taste1
  | taste1 < 0 && tasteN < 0 = tasteSum-tasteN
  | otherwise = tasteSum
  where
    taste1 = l
    tasteN = l+n-1
    tasteSum = n*l + (n-1)*n `div` 2


Measured memory_bytes: 508
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B - Voting Judges
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_N];
ll ass[MAX_N + 1];

/* subroutines */

bool check(int n, int m, int v, int p, int u) {
  if (as[p] > as[u] + m) return false;
  ll x = (ll)(u - p) * (as[u] + m) - (ass[u] - ass[p]);
  ll y = (ll)(v - (p + (n - u))) * m;
  return x >= y;
}

/* main */

int main() {
  int n, m, v, p;
  scanf("%d%d%d%d", &n, &m, &v, &p);
  p--;

  for (int i = 0; i < n; i++) scanf("%d", as + i);
  sort(as, as + n, greater<int>());
  //for (int i = 0; i < n; i++) printf("%d ", as[i]); putchar('\n');

  for (int i = 0; i < n; i++) ass[i + 1] = ass[i] + as[i];

  int u = p;
  while (u < n && check(n, m, v, p, u)) u++;

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


Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//int a = sc.nextInt(), b = sc.nextInt(),c=sc.nextInt();
		//int x=sc.nextInt();//,k=sc.nextInt();
		long sum=0,count=0,flag=0,max=-999999,min=99999;
		//long[] array=new long[a];
		String s=sc.next(),t=sc.next();
		String buff;
		//String[] arrays = new String[a];
		count=Integer.parseInt(s+t);
		double g =Math.sqrt(count);
		sum=(int)g;
		if(g-sum==0)System.out.println("Yes");
		else System.out.println("No");



	}
	public static int sample(int n) {
		return n;
	}

}


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

int main(){
    string s;
    int ans=0;
    cin >> s;
    if(s.at(0)=='R'&&s.at(1)=='R'&&s.at(2)=='R'){
        ans=3;
    }
    else if(s.at(0)=='S'&&s.at(1)=='S'&&s.at(2)=='S'){
        ans=0;
    }
    else if((s.at(0)=='S'&&s.at(1)=='R'&&s.at(2)=='R')||(s.at(0)=='R'&&s.at(1)=='R'&&s.at(2)=='S')){
        ans=2;
    }
    else{
        ans=1;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    double a;
    double res=0;
    for(int i=0;i<n;i++)
    {
        cin >> a;
        res+=(1/a);
    }
    res=1/res;
    cout << fixed << setprecision(14) << res << endl;
    return 0;
}


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

int main(){
  int a,s,t,k,kk;
  cin>>a;
  s=0;
  k=0;
  kk=0;
  for(int i=1;i<=a;i++){
    t=i;
    while(true){
      if(t%2==0){
        t=t/2;
        k+=1;
      }
      else{
        break;
      }
    }
    if(k>=s){
      kk=i;
      s=k;
    }
    k=0;
  }
  cout<<kk<<endl;
}

Measured memory_bytes: 256
A,B,Q=map(int, input().split())
S=[-(10**10)]+[int(input()) for i in range(A)]+[2*(10**10)]
T=[-(10**10)]+[int(input()) for i in range(B)]+[2*(10**10)]
X=[int(input()) for i in range(Q)]
from bisect import bisect
for x in X:
    s=bisect(S,x)
    sl=S[s-1]
    sr=S[s]
    t=bisect(T,x)
    tl=T[t-1]
    tr=T[t]
    print(min((x-sl)+abs(tl-sl),(x-sl)+(tr-sl),\
        (sr-x)+abs(tr-sr),(sr-x)+(sr-tl),\
            (x-tl)+abs(tl-sl),(x-tl)+(sr-tl),\
                (tr-x)+abs(tr-sr),(tr-x)+(tr-sl)))

Measured memory_bytes: 16128
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define rt return 0
#define endln "\n"
#define all(v) v.begin(), v.end()
#define for1(i, a, b) for (long long int i = a; i < b; i++)
#define for2(i, a, b) for (long long int i = a; i > b; i--)
//  cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;typedef long long int i;
typedef long long int lli;
typedef pair<lli, lli> pll;
lli ans = 0;
int fun(vector<lli> &a, vector<string> &v, lli k, lli h, lli w, lli x)
{
    // cout << x << endl;
    if (x == h + w)
    {
        lli c = 0;
        for1(i, 0, h)
        {
            for1(j, 0, w)
            {
                if (v[i][j] == '#')
                {
                    c += 1;
                }
            }
        }
        if (c == k)
        {
            ans += 1;
        }
        return 0;
    }
    vector<string> v1;
    for1(i, 0, v.size())
    {
        v1.pb(v[i]);
    }
    vector<lli> b;
    for1(i, 0, a.size())
    {
        b.pb(a[i]);
    }
    b.pb(0);
    fun(b, v, k, h, w, x + 1);
    b[x] = 1;
    if (x < h)
    {
        for (int i = 0; i < w; i++)
        {
            v1[x][i] = '.';
        }
    }
    else
    {
        int y = x - h;
        for1(i, 0, h)
        {
            v1[i][y] = '.';
        }
    }

    fun(b, v1, k, h, w, x + 1);
 return 0;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli h, w, k;
    cin >> h >> w >> k;
    vector<string> v;
    for1(i, 0, h)
    {
        string s1;
        cin >> s1;
        v.pb(s1);
    }
    vector<lli> a;
    // a.resize(h+w+1);
    fun(a, v, k, h, w, 0);
    cout << ans << endl;
}

Measured memory_bytes: 3692
#include<cstdio>
#include<cctype>
#include<algorithm>
using namespace std;
const int maxn=100000;

int n,L,T,a[maxn+5],ans[maxn+5];

#define Eoln(x) ((x)==10||(x)==13||(x)==EOF)
inline char readc()
{
	static char buf[100000],*l=buf,*r=buf;
	if (l==r) r=(l=buf)+fread(buf,1,100000,stdin);
	if (l==r) return EOF;return *l++;
}
inline int readi(int &x)
{
	int tot=0,f=1;char ch=readc(),lst='+';
	while (!isdigit(ch)) {if (ch==EOF) return EOF;lst=ch;ch=readc();}
	if (lst=='-') f=-f;
	while (isdigit(ch)) tot=(tot<<3)+(tot<<1)+ch-48,ch=readc();
	return x=tot*f,Eoln(ch); 
}
int main()
{
	readi(n);readi(L);readi(T);int fst=0;
	for (int i=0,x,f;i<n;i++)
	{
		readi(x);readi(f);
		if (f==1) ans[i]=x+T,fst+=ans[i]/L,ans[i]%=L; else
		{ans[i]=x-T;fst+=ans[i]/L;ans[i]%=L;if (ans[i]<0) fst--,ans[i]+=L;}
	}
	sort(ans,ans+n);fst=(fst%n+n)%n;
	for (int i=fst;i<n;i++) printf("%d\n",ans[i]);
	for (int i=0;i<fst;i++) printf("%d\n",ans[i]);
	return 0;
}

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

int main(){
  string s;
  cin >> s;
  int len = s.length();
  bool ans = true;
  for(int i=0;i<(len-1)/2;i++){
    if (s[i]!=s[len-1-i]){
      ans = false;
      break;
    }
  }
  for(int i=0;i<(len-1)/2-1;i++){
    if(s[i]!=s[(len-1)/2-1-i]){
      ans = false;
      break;
    }
    if(s[i+(len-1)/2+1]!=s[len-1-i]){
      ans = false;
      break;
    }
  }

  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

int main() {
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for (int i = 0; i < n - 2; i++) {
        if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

/*
一番高い商品に一枚使うをM回繰り返せばいい
しかし愚直に実装するとO(NlogN * M)となってしまう
今N=10^5なので、O(NlogN)くらいにしないといけない
解説を読むと、優先度付きキューを使うと出てくる。
*/

int main()
{
  ll N,M;cin>>N>>M;
  vector<int> A(N);
  priority_queue<int> pq;
  for (int i=0;i<N;i++)
  {
    cin>>A[i];
    pq.push(A[i]);
  }
  
  for (int i=0;i<M;i++)
  {
    int top=pq.top();
    pq.pop();
    pq.push(top/2);
  }
  
  ll sum=0;
  for (int i=0;i<N;i++)
  {
     sum += pq.top();
     pq.pop();
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 1276
n = int(input())
state10 = 1
state9 = 1
state8 = 1
mod = 10**9 + 7
for _ in range(n):
  state10 *= 10
  state10 %= mod
  state9 *= 9
  state9 %= mod
  state8 *= 8
  state8 %= mod

ans = state10 - 2*state9 + state8
ans %= mod
print(ans)


Measured memory_bytes: 9172
import io.StdIn.readLine


object Main {
  def main(args: Array[String]): Unit = {
    val s = readLine()
    var ans = 0
    val win = s.zip(1 to s.length).map { case (c, i) =>
      if (i % 2 == 1) {
        if (c == 'p') ans = ans - 1
      } else {
        if (c == 'g') ans = ans + 1
      }
    }
    println(ans)
  }
}


Measured memory_bytes: 28872
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class Main {
	static List<List<Integer>> list;
	static int[] cnt;
	static int[] ans;
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int q = Integer.parseInt(sa[1]);
		list = new ArrayList<>(n);
		for (int i = 0; i < n; i++) {
			list.add(new ArrayList<>());
		}
		for (int i = 0; i < n - 1; i++) {
			sa = br.readLine().split(" ");
			int a = Integer.parseInt(sa[0]) - 1;
			int b = Integer.parseInt(sa[1]) - 1;
			list.get(a).add(b);
			list.get(b).add(a);
		}
		cnt = new int[n];
		for (int i = 0; i < q; i++) {
			sa = br.readLine().split(" ");
			int p = Integer.parseInt(sa[0]) - 1;
			int x = Integer.parseInt(sa[1]);
			cnt[p] += x;
		}
		br.close();

		ans = new int[n];
		dfs(0, -1, 0);

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < n; i++) {
			pw.println(ans[i]);
		}
		pw.flush();
	}

	static void dfs(int x, int p, int v) {
		v += cnt[x];
		ans[x] += v;
		for (int next : list.get(x)) {
			if (next != p) {
				dfs(next, x, v);
			}
		}
		v -= cnt[x];
	}
}


Measured memory_bytes: 134824
def s_y_n(x, y):
    if y == 0:
        return x
    else:
        return s_y_n(y, x % y)


def s_b_n(x, y):
    return x * y // s_y_n(x, y)


a, b, c, d = map(int, input().split())
bc = b // c
ac = (a-1) // c
bd = b // d
ad = (a-1) // d
bco = b // s_b_n(c, d)
aco = (a-1) // s_b_n(c, d)

print((b-a+1) - (bc-ac) - (bd-ad) + (bco-aco))


Measured memory_bytes: 3064
#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>;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}

int main() {
  int N, X;
  cin >> N >> X;
  vector<int> x(N);
  for (int i = 0; i < N; i++) {
    int y;
    cin >> y;
    x[i] = abs(y - X);
  }

  int ans = x[0];
  for (int i = 1; i < N; i++) {
    ans = gcd(ans, x[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
#define pi 3.141592653589793
#define mod 998244353
#define pb push_back
#define all(v) v.begin(),v.end()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, greater_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;

int main() {
	fast_io;
	ll n;
	cin >> n;
	vl a(n);
	for (int i = 0;i < n;i++)
		cin >> a[i];
	vl dp(n, 0);
	dp[0] = 0;
	dp[1] = abs(a[1] - a[0]);
	for (int i = 2;i < n;i++)
		dp[i] = min(dp[i - 2] + abs(a[i] - a[i - 2]), dp[i - 1] + abs(a[i - 1] - a[i]));
	cout << dp[n - 1] << '\n';
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int selection(int A[],int n)
{
    int c=0,minx;
    for(int i=0;i<n-1;i++)
    {
        minx=i;
        for(int j=i;j<n;j++)
        {
            if(A[j]<A[minx])
                {minx=j;}}
                swap(A[i],A[minx]);
                if(i!=minx)
                c++;
    }
    return c;
}
int main()
{
    int n,A[100],c;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>A[i];
    }
    c=selection(A,n);
    for(int i=0;i<n;i++)
    {
        if(i)cout<<" ";
        cout<<A[i];
    }
    cout<<endl;
    cout<<c<<endl;
}


Measured memory_bytes: 3096
#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()
typedef long long ll;

using namespace std;

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
//最大公約数
ll gcd(ll a, ll b) {
  while (a && b) {
    if (a >= b) a %= b;
    else b %= a;
  }
  return a + b;
}
//最小公倍数
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b;}



const int NM = 101001;//ここを問題の制約を見ながらいじる．配列の確保に使う．
int A[NM];//あまり褒められたことではないが関数の外側に配列を確保すると怒られにくい．

// Main program
void solve(){
  ll A,B,out;
  cin >> A;
  cin >> B;
 
  out = lcm(A,B);  
  
 cout << out;
  return;
}

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






Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n;
string s;
int main() {
    cin >> n;
    cin >> s;
    int count = 0;
    for (int i = 0; i < n - 2; i++) {
        if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<cstdio>
#define ll long long
#define mset(a,x) memset(a,x,sizeof(a))

using namespace std;
const double PI=acos(-1);
const int inf=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int mod=1e9+7;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}
ll Fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n;n=n*n;}return r;}
ll upd(ll x,ll v){x=x+v>=mod?x+v-mod:x+v;return x;}
struct node{
	int next,v,u,w;
}p[maxn];
int head[maxn],cnt,vis[maxn],n,k,maxx;

void add(int u,int v)
{
	p[cnt].v=v;
	p[cnt].next=head[u];
	head[u]=cnt++;
}

void dfs(int now,int fa,int step)
{
	maxx++;
	if(step==0)
	return ;
	for(int i=head[now];~i;i=p[i].next)
	{
		if(p[i].v==fa)
		continue;
		dfs(p[i].v,now,step-1);
	}
}

int main()
{
	int i,j,x,y;
	scanf("%d%d",&n,&k);
	for(i=0;i<=n;i++)
	head[i]=-1;
	for(i=0;i<n-1;i++)
	{
		scanf("%d%d",&x,&y);
		add(x,y);
		add(y,x);
	}
	int ans=0;
	if(k%2)    //k为奇数，枚举边，跑k/2的点 
	{
		for(i=1;i<=n;i++)
		{
			for(j=head[i];~j;j=p[j].next)
			{
				maxx=0;
				int t=p[j].v;
				dfs(t,i,k/2);
				dfs(i,t,k/2);
				ans=max(maxx,ans);
			}
		}
	}
	else      //k为偶数，枚举点，跑k/2的点 
	{
		for(i=1;i<=n;i++)
		{
			maxx=0;
			dfs(i,0,k/2);
			ans=max(maxx,ans);
		}
	}
	printf("%d\n",n-ans);
}

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main{

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

	private Scanner scan;

	private void mainrun() {
		scan = new Scanner(System.in);

		cal(scan.nextInt());

		scan.close();
	}

	private void cal(int n) {
		long sum,num,max,min;
		sum = 0;
		min = Long.MAX_VALUE;
		max = Long.MIN_VALUE;

		for(int i = 0;i < n;i++) {
			num = scan.nextLong();
			sum += num;
			min = Math.min(min, num);
			max = Math.max(max, num);

		}

		System.out.println(min + " " + max + " " + sum);
	}
}


Measured memory_bytes: 41988
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=30;
int n;
int a[maxn],x,ans,c[maxn];
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	for (int i=1;i<=n;i++) read(a[i]);
	for (int i=1;i<=n;i++) read(x),ans+=x;
	for (int i=1;i<n;i++) read(c[i]);
	for (int i=1;i<n;i++)
		if (a[i]+1==a[i+1])
			ans+=c[a[i]];
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

int main()
{
	string		W;
	int			Cnt = 0;

	auto ToUpper = [](string &st)
	{
		for (auto &it : st)
		{
			it = toupper(it);
		}
	};

	getline(cin, W);
	ToUpper(W);

	string	str;
	for (;;)
	{

		cin >> str;
		if (str == "END_OF_TEXT")	break;

		ToUpper(str);
		if (str == W)	Cnt++;
	}

	cout << Cnt << endl;

	return 0;
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())
#define all(a) (a).begin(), (a).end()

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;

int main(void){

	int D, T, S; cin >> D >> T >> S;
	double t = (double)D / S;
	if(t <= T) cout << "Yes" << endl;
	else cout << "No" << endl;




	return 0;

}


Measured memory_bytes: 3632
import sys
d = [1 << i for i in range(30, -1, -1)]
N = int(input())
points = [list(map(int, input().split())) for i in range(N)]
f = [0, 0]
for tmp in points:
    state = (abs(tmp[0]) + abs(tmp[1])) & 1
    f[state] = 1
if f[0] and f[1]:
    print(-1)
    sys.exit()

if f[0]:
    d.append(1)


def conAns(x, y):
    res = ''
    for i in d:
        if abs(x) > abs(y):
            if x > 0:
                x -= i
                res += 'R'
            else:
                x += i
                res += 'L'
        else:
            if y > 0:
                y -= i
                res += 'U'
            else:
                y += i
                res += 'D'
    return res


print(len(d))
print(d[0], end='')
for i in range(1, len(d)):
    print(' ' + str(d[i]), end='')
print("")
for tmp in points:
    x, y = tmp
    res = conAns(x, y)
    print(res)


Measured memory_bytes: 3316
/*
AizuOnline A0050
Apple and pearch
*/
#include <stdio.h>
#include <string.h>

char sentence[1001];

main()
{
  char *p;
  int  i,l;

  while(NULL!=fgets(sentence,1000,stdin))
    {
      l=strlen(sentence);

      for(i=0;i<l-5;i++)
	{
	  //if ((i==0 || !(isalpha(sentence[i-1]))) && !(isalpha(sentence[i+5])))
	    {
	      if (0==strncmp(&sentence[i],"apple",5))
		strncpy(&sentence[i],"peach",5);
	      else if  (0==strncmp(&sentence[i],"peach",5))
		strncpy(&sentence[i],"apple",5);
	    }
	}
      printf("%s",sentence);
    }
return(0);
}

Measured memory_bytes: 524
#include <iostream>
#include <stack>
using namespace std;
#define N (100)
#define WHITE (0)
#define GRAY (1)
#define BLACK (2)

int n,M[N][N];
int color[N],d[N],f[N],tt;
int nt[N];

int next(int u){
    for(int v=nt[u];v<n;v++){
        nt[u]=v+1;
        if(M[u][v])return v;
    }
    return -1;
}

void dfs_visit(int r){
    //for(int i=0;i<n;i++)nt[i]=0;
    stack<int> S;
    S.push(r);
    color[r]=GRAY;
    d[r]=++tt;
    
    while(!S.empty()){
        int u=S.top();
        int v=next(u);
        if(v!=-1){
            if(color[v]==WHITE){
                color[v]=GRAY;
                d[v]=++tt;
                S.push(v);
            }
        }else{
            S.pop();
            color[u]=BLACK;
            f[u]=++tt;
        }
    }
}

void dfs(){
    for(int i=0;i<n;i++){
        color[i]=WHITE;
        nt[i]=0;
    }
    tt=0;
    for(int u=0;u<n;u++){
        if(color[u]==WHITE)dfs_visit(u);
    }
    for(int i=0;i<n;i++){
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
}

int main(void){
    int u,k,v;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            M[i][j]=0;
        }
    }
    for(int i=0;i<n;i++){
        cin>>u>>k;
        u--;
        for(int j=0;j<k;j++){
            cin>>v;
            v--;
            M[u][v]=1;
        }
    }
    dfs();
    return 0;
}



Measured memory_bytes: 3148
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

int n;
string a,b;

int memo[16][1<<16];

int f(int pos,int bit){
	if(~memo[pos][bit]) return memo[pos][bit];
	
	if(bit == 0) return 0;
	int ans = 99999;
	for(int i = 0 ; i < n ; i++){
		if(bit>>i&1){
			for(int j = 0 ; j < n ; j++){
				if(i==j) continue;
				if(bit>>j&1){
					if(a[j] != a[i]){
						int dist1 = abs(pos - i);
						int dist2 = abs(i - j);
						ans = min(ans,f(j,bit&~((1<<i)|(1<<j)))+dist1+dist2);
					}
				}
			}
		}
	}
	return memo[pos][bit] = ans;
}
int main(){
	while(cin >> n && n){
		memset(memo,-1,sizeof(memo));
		cin >> a >> b;
		int bit = 0;
		for(int i = 0 ; i < n ; i++)
			if(a[i] != b[i]) bit |= (1<<i);
		int ans = 9999;
		for(int i = 0 ; i < n ; i++) ans = min(f(i,bit),ans);
		cout << ans << endl;
	}
}

Measured memory_bytes: 5024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }


/*
 1-index

 add : x に valを加算
 sum : [1,x] の総和を出力
 */
struct BIT {
    ll N;
    vector<ll> bit;
    BIT(ll N):N(N) {
        /* BITは[1..N]で扱う */
        bit.resize(N + 1, 0);
    }
    
    void add(int x, ll val){
        while (x <= N) {
            bit[x] += val;
            x += x & -x;
        }
    }
    
    ll sum(int x){
        if(x == 0) return 0;
        ll ret = 0;
        while (x) {
            ret += bit[x];
            x &= (x - 1);
        }
        return (ret);
    }
};

int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    ll ans1 = 0,ans2 = 0;
    int n; cin >> n;
    vector<int> a(n),b(n);
    for(int i = 0; i < n;i++) cin >> a[i] >> b[i];
    
    // Policy 1 ==== BEGIN ====
    BIT l(100001),r(100001);
    for(int i = 0; i < n;i++){
        l.add(b[i],1);
        r.add(a[i],1);
    }
    for(int i = 0; i < n;i++){
        ans1 = max(ans1,(ll)n - l.sum(a[i]) - (r.sum(100000) - r.sum(b[i]-1)));
    }
    // Policy 1 ====  END  ====
    // Policy 2 ==== BEGIN ====
    vector<ll> imos(100001);
    for(int i = 0; i < n;i++){
        imos[a[i]]++; imos[b[i]]--;
    }
    for(int i = 1; i <= 100000;i++){
        imos[i] += imos[i-1];
    }
    ans2 = *max_element(imos.begin(), imos.end());
    // Policy 2 ====  END  ====

    cout << ans1 << " " << ans2 << endl;
    return 0;
}



Measured memory_bytes: 6800
n,m = map(int,input().split())
a = [-1 for _ in range(n)]
wa = [0 for _ in range(n)]
for i in range(m):
  ps,s = input().split()
  pi = int(ps)
  if(a[pi-1] == 1):
    continue
  elif(s == 'WA'):
    wa[pi-1] += 1
  elif(s == 'AC'):
    a[pi-1] = 1
for l in range(n):
  if(a[l] == -1):
    wa[l] = 0
print(a.count(1),sum(int(i) for i in wa) )

Measured memory_bytes: 4760
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define rn(i,n) for(int i=1;i<=n;i++)
#define ll long long
const ll mod=1e9+7;

int main(){
  int n,q;
  string s;
  cin>>n>>q>>s;

  vector<int> l(q),rr(q),t(n+100);

  r(i,q){cin>>l.at(i)>>rr.at(i);}

  int cnt=0;

  for(int i=1;i<n;i++){
    if(s.at(i-1)=='A'&&s.at(i)=='C'){
      cnt++;
    }
    t.at(i)=cnt;
  }
  //r(i,n)cout<<t.at(i)<<" ";
  //cout<<endl;

  r(i,q){
    cout<<t.at(rr.at(i)-1)-t.at(l.at(i)-1)<<endl;
  }




return 0;

}


Measured memory_bytes: 2176
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    aoi<pair<i64, int>> col;
    aoi<i64> mon;
    for (int i = 0; i < a; i++)
    {
        i64 p;
        cin >> p;
        col.emplace(p, 0);
    }
    for (int i = 0; i < b; i++)
    {
        i64 p;
        cin >> p;
        col.emplace(p, 1);
    }
    for (int i = 0; i < c; i++)
    {
        i64 p;
        cin >> p;
        mon.emplace(p);
    }
    int red = 0, green = 0, mono = 0;
    i64 ans = 0;
    while (red + green + mono < x + y)
    {
        i64 ct = 0;
        int color = -1;
        if (!col.empty())
        {
            ct = col.top().first;
            color = col.top().second;
            col.pop();
        }
        i64 mt = 0;
        if (!mon.empty())
        {
            mt = mon.top();
            mon.pop();
        }
        if (color == 0 && red == x)
        {
            mon.push(mt);
            continue;
        }
        if (color == 1 && green == y)
        {
            mon.push(mt);
            continue;
        }
        if (mt <= ct)
        {
            ans += ct;
            if (color)
            {
                green++;
            }
            else
            {
                red++;
            }
            mon.push(mt);
        }
        else
        {
            ans += mt;
            mono++;
            col.emplace(ct, color);
        }
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 6384
# coding: utf-8
# 整数の入力
#a = int(raw_input())
# スペース区切りの整数の入力
import numpy as np
import itertools

def gcd(x, y):
    if x == y:
        return x
    elif x > y:
        return gcd(x-y, y)
    else:
        return gcd(y-x, x)

A, B, C = map(int, raw_input().split())
if (C % gcd(A, B)) == 0:
    print "YES"
else:
    print "NO"

Measured memory_bytes: 19432
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
    string a;
    cin>>a;
    string b=a;
    reverse(a.begin(),a.end());
    for(int i=0; i<a.size(); i++){
        if(a[i]=='b') a[i]='d';
        else if(a[i]=='d') a[i]='b';
        else if(a[i]=='p') a[i]='q';
        else if(a[i]=='q') a[i]='p';
    }
    if(a==b) cout<<"Yes";
    else cout<<"No";
    return 0;
}

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

use proconio::{input, fastout};
use proconio::marker::*;
use smallvec::alloc::collections::BinaryHeap;

#[fastout]
fn main() {
    input! {
    n: usize,
    m: usize,
    mut ab: [(usize, usize); n]
    }
    let mut d: Vec<Vec<usize>> = vec![vec![]; m + 1];
    for i in 0..n {
        let (a, b) = ab[i];
        if a > m { continue; }
        d[a].push(b);
    }
    let mut q = BinaryHeap::new();
    let mut ans = 0;
    for i in 1..=m {
        for &j in &d[i] {
            q.push((j, i))
        }
        if let Some(x) = q.pop() {
            ans += x.0;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 9848