akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;

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

    vector<vector<char>> grid(h + 2, vector<char>(w + 2, '#'));
    for (int i = 1; i <= h; i++) {
        string s;
        cin >> s;

        for (int j = 1; j <= w; j++) {
            grid[i][j] =  s[j - 1];
        }
    }

    int blk = 0;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (grid[i][j] == '#') {
                blk++;
            }
        }
    }

    int dy[] = { -1, 0, 0, 1 };
    int dx[] = { 0, -1, 1, 0 };
    vector<vector<int>> dist(h + 2, vector<int>(w + 2, 1000000000));
    dist[1][1] = 0;

    priority_queue<pair<int, pair<int, int>>,
            vector<pair<int, pair<int, int>>>,
            greater<pair<int, pair<int, int>>>> que;
    que.push(make_pair(0, make_pair(1, 1)));
    while (!que.empty()) {
        pair<int, int> p = que.top().second;
        que.pop();

        for (int i = 0; i < 4; i++) {
            if (grid[p.first + dy[i]][p.second + dx[i]] == '.'
                    && dist[p.first + dy[i]][p.second + dx[i]] > dist[p.first][p.second] + 1) {
                dist[p.first + dy[i]][p.second + dx[i]] = dist[p.first][p.second] + 1;
                que.push(make_pair(dist[p.first + dy[i]][p.second + dx[i]],
                        make_pair(p.first + dy[i], p.second + dx[i])));
            }
        }
    }

    cout << max(-1, h * w - dist[h][w] - blk - 1) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using str = string;
using ll = long long;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define RREP(i,n) for(int i=int(n)-1; i>=0; i--)
#define FOR(i,f,t) for(int i=int(f); i<=int(t); i++)
#define RFOR(i,f,t) for(int i=int(f); i>=int(t); i--)
#define ALL(vec) (vec).begin(),(vec).end()
#define ASORT(vec) sort(ALL(vec))
#define DSORT(vec) sort(ALL(vec), greater<int>());
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define YES(ans) if(ans) cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define Yes(ans) if(ans) cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define yes(ans) if(ans) cout<<"yes"<<endl; else cout<<"no"<<endl;
#define INF 1000000000000
#define NOD 1000000007
#define PI 3.141592653589793238462643

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

ll lcm(ll a, ll b) {
   return a * b / gcd(a, b);
}

int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
    cout << b - b/c - b/d + b/lcm(c, d) - (a-1) + (a-1)/c + (a-1)/d - (a-1)/lcm(c, d) <<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <deque>
#include <stack>
#include <iomanip>
#include <cmath>


using namespace std;


typedef long long ll;
typedef long double ld;


int N, K;
deque<int> num;
set<int> like, dislike;


void input() {
  cin >> N >> K;
  int tmp;
  for (int i = 0 ; i < K ; i++) {
    cin >> tmp;
    dislike.insert(tmp);
  }
}


void preprocess() {
  for (int i = 0 ; i <= 9 ; i++) {
    if (dislike.count(i) == 0) {
      like.insert(i);
    }
  }
  int tmp = N;
  while (tmp > 0) {
    num.push_back(tmp % 10);
    tmp /= 10;
  }
  reverse(num.begin(), num.end());
}


void solve() {
  for (int i = 0 ; i < (int)num.size() ; i++) {
    if (num[i] == 10) {
      for (int j = i ; j < (int)num.size() ; j++) {
        num[j] = 0;
      }
      if (i != 0) {
        num[i-1]++;
        i -= 2;
      } else {
        num.push_front(1);
        i -= 1;
      }
    } else {
      auto it = lower_bound(like.begin(), like.end(), num[i]);
      if (it != like.end()) {
        if (*it != num[i]) {
          for (int j = i+1 ; j < (int)num.size() ; j++) {
            num[j] = 0;
          }
        }
        num[i] = *it;
      } else {
        for (int j = i ; j < (int)num.size() ; j++) {
          num[j] = 0;
        }
        if (i != 0) {
          num[i-1]++;
          i -= 2;
        } else {
          num.push_front(1);
          i -= 1;
        }
      }
    }
  }
  for (auto x : num) {
    cout << x;
  }
}






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

  int T;
//  cin >> T;
  T = 1;

  for (int i = 0 ; i < T ; i++) {
    input();
    preprocess();
    solve();
  }

  return 0;
}


Measured memory_bytes: 256
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))

    ans = 0
    for i in range(N):
        if h[i] >= K:
            ans += 1

    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 11908
a,b,x = gets.split.map(&:to_i)
x.times{|i|
 if i.even? 
   if a.odd?
		a = a-1
     	b += a/2
     	a = a/2
     	else
     	    b += a/2
     	    a = a/2
   end
 end
  if i.odd? 
    if b.odd?
		b = b-1
      	a += b/2
      	b = b/2
      	else
      	    a += b/2
      	    b = b/2
    end
  end
  }
  puts "#{a} #{b}"

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

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
    scanf("%d", &a[i]);
  vector<int> b(a);
  sort(b.begin(), b.end());
  multiset<int> left, right;
  for (int i = 0; i < n; ++i)
    (i < n / 2 ? left : right).insert(b[i]);
  for (int i = 0; i < n; ++i)
    if (left.find(a[i]) != left.end())
      printf("%d\n", *right.begin());
    else
      printf("%d\n", *left.rbegin());
  return 0;
}

Measured memory_bytes: 13184
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cassert>
#define bogo_sort   std::sort
#define bozo_sort   std::stable_sort
#define alles(obj)  obj.begin(), obj.end()
#define elif        else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo        std::cout <<
#define read        std::cin >>
#define endl        std::endl
#define fin         << '\n'
#define bash        push_back
#define makePair    std::make_pair
#define _           << ' ' <<
// type-define
#define Stack       std::stack
#define Queue       std::queue
#define Set         std::set
#define PQueue      std::priority_queue
#define Vector      std::vector
#define Pair        std::pair
#define Map         std::map
#define UMap        std::unordered_map
#define Greater     std::greater
using String  =     std::string;
using llong   =     long long;
using boolean =     bool;
using Pii     =     Pair<int, int>;
using Vi      =     Vector<int>;
using Vii     =     Vector<Pii>;
// utils
constexpr int   dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int   dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int   INF  = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    llong power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    llong power ( llong x, llong n ) { return power( x, n, 1000000007 ); }
    llong gcd   ( llong x, llong y ) { return x % y ? gcd( y, x % y ) : y; }
    llong lcm   ( llong x, llong y ) { return ( x / gcd(x, y) * y ); }
    llong abs   ( llong n )          { return ( n < 0 ) ? -n : n; }
    template<class A, class B>inline bool chmax ( A &a, const B &b ) { return b > a ? a = b, true : false; }
    template<class A, class B>inline bool chmin ( A &a, const B &b ) { return b < a ? a = b, true : false; }
    boolean isMovable ( int x, int y, int w, int h ) {
        return ( x >= 0 && y >= 0 && x < w && y < h );
    }
}

namespace Rlyeh {

    Vii vii;
    PQueue<Pii> q;
    llong t, o;

    signed call_of_Cthulhu( signed datum ) {

        int n;
        read n;
        for ( int i = 0; i < n; i++ ) {
            int a, b;
            read a >> b;
            vii.bash(Pii(a, b));
            q.push( Pii ( a+b, i ) );
        }
        for ( int i = 0; i < n; i++ ) {
            int id = q.top().second;
            if ( i & 1 ) {
                o += vii[id].second;
            }
            else {
                t += vii[id].first;
            }
            q.pop();
        }
        echo ( t - o ) fin;
        return 0;
    }
}

signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); int main_result = Rlyeh::call_of_Cthulhu(114514); return 0;}


Measured memory_bytes: 2036
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define int ll int
#define debug(x) cout << ">>" << #x << ':' << x << endl;
#define endl "\n"
#define pb push_back
#define fo(i,n) for(int i=0 ; i<n ; i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define umap unordered_map
#define pii pair<int , int>
#define remove erase
#define all(v) v.begin() , v.end()   

const int mod = 1e9 + 7;

signed main()
{
	IOS
	int n;
	cin>>n;
	int arr[n];
	for(int i=0 ; i<n ; i++)cin>>arr[i];
	int kapa=0;
	for(int i=1 ; i<n ; i++)
	{
		if(arr[i] >= arr[i-1])continue;
		else
		{
			kapa = kapa + ( arr[i-1] - arr[i]);
			arr[i] = arr[i-1];
		}
	}
	cout<<kapa<<endl;
	
}



Measured memory_bytes: 5184
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
 
using namespace std;
 
//container util
//------------------------------------------
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
 
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).end()) i=(c).end(); i!=(c).begin(); --i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
 
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end(),greater<int>())
 
#define PB(a) push_back(a)
#define PF(a) pop_front(a)
 
#define MP(a,b) make_pair(a,b)
 
#define FS first
#define SE second
 
#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
#define MIN_EL(c) *min_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 
 
//------show vector---------
template <typename T>
void showV(vector < T > a){
  EACH(i,a){
    cerr << *i << ',';
  }  
  cerr << endl;
}
 
//------show matrix---------
template <typename T>
void showVV(vector < vector < T > > a){
  EACH(i,a){
    showV(*i);
  }  
}
//grobal var
//------------------------------------------
LL dp[2000][2000];
 
int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------
  int R;
  while(cin >> R){
    cout << 3*R*R << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

template<typename T>
T gcd(T a, T b)
{
	if (a < b) return gcd(b, a);
	T r;
	while (r = a % b)
	{
		a = b;
		b = r;
	}
	return b;
}

int main()
{
  int n, a;
  scanf("%d %d", &n, &a);
  for (int i = 0; i < n; ++i)
  {
    int b;
    scanf("%d", &b);
    a = gcd(a, b);
  }
  printf("%d\n", a);
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <iostream>
using namespace std;
 
int main() {

  int a;
  int b;
  int ans=0;

  cin >> a >> b;
  ans=a+b;
  ans= std::max(ans,a-b);
  ans= std::max(ans,a*b);

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

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

    long long ans = 1000000000000;

    vector<long long> ret;

    for (long long i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) {
                ret.push_back(n / i);
            }
        }
    }

    for (int j = 0; j < ret.size(); ++j) {
        long long temp = n / ret[j];
        if (ans > ret[j] + temp) ans = ret[j] + temp;
    }

    ans = ans - 2;

    cout << ans << endl;

    return 0;
}


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

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/* }}} */

fn main() {
    input! {
        a: u64,
        b: String
    }
    let mut sp = b.split('.');
    let b1 = sp.next().unwrap();
    let b2 = sp.next().unwrap();
    let mut b = String::new();
    b += b1;
    b += b2;
    let b: u64 = b.parse().unwrap();
    println!("{}", (a * b) / 100);
}
/* vim:set foldmethod=marker: */


Measured memory_bytes: 2128
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	d := nextInt()
	x := nextInt()
	al := make([]int, n)

	for i := 0; i < n; i++ {
		al[i] = nextInt()
	}

	choco := x

	for i := 0; i < n; i++ {
		for j := 0; j <= d; j++ {
			// 該当日だったら食べる (al[j]*N+1==i)
			if al[i]*j+1 <= d {
				choco++
			}
		}
	}

	fmt.Println(choco)

}

// ---- readfunc
func scanInit() {
	const cap = 64 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


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

int main(){
  int H, W;
  cin >> H >> W;
  char A[H+2][W+2];
  for(int i=0;i<=H+1;i++){
    for(int j=0;j<=W+1;j++){
      A[i][j] = '#';
    }
  }
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
    cin >> A[i][j];
    }
  }
  for(int i=0;i<=H+1;i++){
    for(int j=0;j<=W+1;j++){
      cout << A[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	string s;

	cin>>s;

	int size=(int)s.size(), ans;

	for(int i=size-2; i>=1; i-=2){
		s.erase(s.begin()+i+1); s.erase(s.begin()+i);
		string s2;
		for(int j=0; j<i/2; j++){
			s2.push_back(s[j]);
		}
		//cout<<s<<" "<<s2+s2<<endl;
		if(s==s2+s2){
			ans=s.size(); break;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static  Scanner in = new Scanner(System.in);
	
	public static void main(String[] args) {
		
		int n, sum = 0;
		n = in.nextInt();
		int arr[] = new int[n];
		for(int i = 0; i < n; i++)
		{
			arr[i]  = in.nextInt();
		}
		for(int i = 0; i < n; i++)
		{
			for(int j = i + 1; j < n; j++)
			{
				sum += arr[i] * arr[j];
			}
		}
		System.out.println(sum);
		
	}

}


Measured memory_bytes: 21844
//q098.cpp
//Wed Sep 16 20:16:46 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i,n) for (int i=0;i<(n);++i)

using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	ll ans = 1;
	vector<int> count(3,0);
	rep(i,n){
		ll a;
		cin >> a;
		ll tmp = 0;
		ll flag = 1;
		rep(j,3){
			if(count[j]==a){
				tmp++;
				if(flag){
					count[j]++;
					flag = 0;
				}
			}
		}
		ans = ans*tmp%MOD;
	}


	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 3576
/*
    SPFA ````
*/

#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>

using namespace std;
typedef long long ll;
const int N = 1e6+10;
int n,m,k,q,x,y;
int h[N],w[N],e[N],ne[N],idx;

ll dist[N];
bool st[N];

void add(int a,int b,int c)
{
    e[idx] = b,w[idx] = c,ne[idx] = h[a],h[a] = idx++;
}

void spfa()
{
    memset(dist,0x3f,sizeof dist);
    dist[k] = 0;
    queue<int>q;
    q.push(k);
    
    st[k] = true;
    
    while(q.size())
    {
        int t = q.front();
        q.pop();
        
        st[t] = false;
        
        for(int i = h[t];i!=-1;i=ne[i])
        {
            int j = e[i];
            if(dist[j]>dist[t] + w[i])
            {
                dist[j] = dist[t] + w[i];
                if(!st[j])
                {
                    q.push(j);
                    st[j] = true;
                }
            }

        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin >>n;
    memset(h,-1,sizeof h);
    m = n-1;
    while(m--)
    {
        int a,b,c;
        cin >>a>>b>>c;
        add(a,b,c);
        add(b,a,c);
    }
    
    cin >> q>>k;
    spfa();
    while(q--)
    {
        cin >>x >>y;
        cout << dist[x] + dist[y] << endl;
    }
    spfa();
    
    return 0;
}

Measured memory_bytes: 19200
/*input
8
8 2 7 3 4 5 6 1
*/
#include <bits/stdc++.h>
using namespace std;
 
#define all(a) (a).begin(), (a).end()
#define pb push_back
 
using ll = long long;
using pii = pair<int, int>;

int main() {
  ios::sync_with_stdio(false);cin.tie(nullptr);
  int n; cin >> n;
  vector<pii> a(n);
  for (int i = 0; i < n; ++i) {
  	cin >> a[i].first;
  	a[i].second = i;
  }
  sort(all(a));
  for (int i = 0; i < n; ++i) {
  	cout << a[i].second + 1 << " ";
  }
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define ll long long

using namespace std;

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

bool isprime(ll n) {
  vector<ll> y = divisor(n);
  if(y.size() == 2)
    return true;
  return false;
}

int main() {
  ll a, b;
  cin >> a >> b;
  vector<ll> ya = divisor(a), yb = divisor(b), y;
  set_intersection(ya.begin(), ya.end(), yb.begin(), yb.end(),
                   back_inserter(y));
  int p = 0;
  for(int i = 0; i < y.size(); i++)
    if(isprime(y.at(i)))
      p++;
  cout << p + 1 << endl;
}

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


int main(){
	string str;
	cin>>str;
	int ans;
	if(str=="SSS")ans=0;
	else if(str=="SSR")ans=1;
	else if(str=="SRS")ans=1;
	else if(str=="RSS")ans=1;
	else if(str=="RRS")ans=2;
	else if(str=="RSR")ans=1;
	else if(str=="SRR")ans=2;
	else ans=3;
	cout<<ans<<endl;
	return 0; 
}

Measured memory_bytes: 3616
import java.util.Scanner

object Main extends App {
  def param(n:Int):List[Int] = if (n > 0) sc.nextInt::param(n-1) else Nil
  val sc = new Scanner(System.in)
  val v = param(4)
  v match {
    case List(a,b,c,k) if a > k    => println(k)
    case List(a,b,c,k) if a+b > k  => println(a)
    case List(a,b,c,k) if a+b <= k => println(a - (k-a-b))
  }
}


Measured memory_bytes: 55348
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <vector>
#include <bitset>
#include <queue>
using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    a = (a+13) % 15;
    b = (b+13) % 15;
    if(a > b){
        cout << "Alice";
    }else if(a < b){
        cout << "Bob";
    }else{
        cout << "Draw";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
const int d = 365;
//const int d = 5;
int c[26];
int s[d][26];
int last[26] = {0};
bool llast[d][26] = {false};
vector<int> solution(d,-1);
int myscore = 0;

random_device seed_gen;
mt19937 mt(seed_gen());
uniform_int_distribution<int> con(0,26-1);
uniform_int_distribution<int> day(0,365-1);
uniform_real_distribution<double> pro(0,1);


int score(vector<int> t){
    vector<int> last(26,0);
    int ans = 0;
    rep(i,d){
        ans += s[i][t[i]];
        last[t[i]] = i+1;
        rep(j,26) ans -= c[j] * (i+1-last[j]);
        //cout << ans << endl;
    }
    return ans;
}

// p day contest changes q
void better(int p,int q,clock_t start,clock_t end){
    //cout << myscore << endl;
    int origin = solution[p];
    int newscore = myscore - s[p][origin] + s[p][q];
    int before_origin = 0,before_q = 0;
    int res = 0;
    for(int i=0;i<d;i++){
        if(llast[i][origin]) before_origin = i+1;
        if(llast[i][q]) before_q = i+1;
        res += (c[origin] * (i+1-before_origin) + c[q] * (i+1-before_q));
    }

    llast[p][q] = true;
    llast[p][origin] = false;
    before_origin = 0;
    before_q = 0;

    for(int i=0;i<d;i++){
        if(llast[i][origin]) before_origin = i+1;
        if(llast[i][q]) before_q = i+1;
        res -= (c[origin] * (i+1-before_origin) + c[q] * (i+1-before_q));
    }

    //cout << res << endl;

    double t = 1 - ((double)(end - start)/CLOCKS_PER_SEC)/1.6;
    //if(t > 0.5) cout << t << endl;

    newscore += res;
    if(newscore - myscore > 0 || exp(newscore - myscore/t) > pro(mt)){
        myscore = newscore;
        solution[p] = q;
    }else{
        llast[p][q] = false;
        llast[p][origin] = true;
    }
}




//day 1-index i_day 's contest is k
int nowscore(int i,int k){
    int res = s[i][k];
    int before = last[k];
    last[k] = i+1;
    rep(j,26) res -= c[j] * (i+1-last[j]);
    last[k] = before;
    return res;
}

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

    int tmp;
    cin >> tmp;
    rep(i,26) cin >> c[i];
    rep(i,d)rep(j,26) cin >> s[i][j];

    for(int i=0;i<d;i++){
        int id = -1;
        int mx = -INF;
        for(int j=0;j<26;j++){
            int res = nowscore(i,j);
            if(mx < res){
                id = j;
                mx = res;
            }
        }
        solution[i] = id;
        last[id] = i+1; 
        llast[i][id] = true;
        myscore += mx;
    }

    clock_t end = clock();

    while(((double)(end - start)/CLOCKS_PER_SEC) < 1.6){
        better(day(mt),con(mt),start,end);
        end = clock();
    }



    rep(i,d) cout << solution[i]+1 << endl;
    /*
    cout << myscore << endl;
    cout << (score(solution) + 1e6) << endl;
    cout << (myscore + 1e6) << endl;
    */


    return 0;
}

Measured memory_bytes: 4164
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
//#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define P pair<int,int>
using namespace std;

double dp[2][7000];//+3500して運用する
signed main() {
	dp[0][3500] = 1;
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		double p; cin >> p;
		for (int j = 0; j < 7000; j++) {
			dp[(i + 1) & 1][j] = 0;
		}
		for (int j = 2; j < 6995; j++) {
			dp[(i + 1) & 1][j - 1] += dp[i&1][j] * (1 - p);
			dp[(i + 1) & 1][j + 1] += dp[i&1][j] * p;
		}
	}
	double ans = 0;
	for (int i = 3501; i < 7000; i++) {
		ans += dp[n & 1][i];
	}
	printf("%.10lf\n", ans);
}

Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void) {
  //input
  int a,b;
  cin >> a >> b;
  int d,r;
  double fa,fb,f;
  fa = a;
  fb = b;

  d = a / b;
  r = a % b;
  f = fa / fb;

  printf("%d %d %.5f\n",(a/b),(a%b),(fa/fb));
//  cout << d << " " << r << " " << (double).5f << endl;
  return 0;
}



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

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> isac(n,0);
    vector<int> wanum(n,0);
    int acnt=0,pcnt=0;
    int p;
    string s;
    for(int i=0;i<m;i++){
        cin>>p>>s;
        if(s=="WA"&&isac[p-1]==0)wanum[p-1]++;
        if(s=="AC"&&isac[p-1]==0){
            acnt++;
            isac[p-1]=1;
        }
    }
    for(int i=0;i<n;i++){
        if(isac[i]==1)pcnt+=wanum[i];
    }
    printf("%d %d\n",acnt,pcnt);
    return 0;
}

Measured memory_bytes: 1024
X=input()
count=0
balance=0
for x in X:
  if balance==0 and x=="T":
    count+=1
  elif x=="S":
    balance-=1
  elif x=="T":
    balance+=1
X=X[::-1]
balance=0
for x in X:
  if balance==0 and x=="S":
    count+=1
  elif x=="T":
    balance-=1
  elif x=="S":
    balance+=1
print(count)

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

int main(void) {
    long long A, B, K;
    cin >> A >> B >> K;
    cout << max(0LL, A - K) << " " << max(0LL, B - (max(K - A, 0LL))) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int A=0,B=0;
int a,b;

void Total(){
	if(a>b)	A+=a+b;
	else if(a<b) B+=a+b;
	else {A+=b;B+=a;}
}

int main(){
	int n,i;
	for(;;){
		scanf("%d",&n);
		if(n!=0){
			for(i=0;i<n;i++){
				scanf("%d%d", &a, &b);
				Total();
			}
			printf("%d %d\n",A,B);
			A=B=0;
		}else break;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
    return 0;
}



Measured memory_bytes: 3208
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <bits/stdc++.h>  
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vl vector<ll>
#define N 100005
#define mod 1000000007
ll parent[200005];
ll len[200005];

ll find(ll v)
{
    if(v==parent[v])
    return v;
    return parent[v]=find(parent[v]);
}
void add (ll u,ll v)
{
    ll a=find(u);
    ll b=find(v); 
    if(a==b)
    return;
    if(len[a]<len[b])
    swap(len[a],len[b]);
    len[a]+=len[b];
    parent[b]=a;
}
int main()
{
    ll n,m;cin>>n>>m;
    for(ll i=1;i<=n;i++)
    {
        parent[i]=i;
        len[i]=1;
    }
    for(ll i=0;i<m;i++)
    {
        ll x,y;cin>>x>>y;
        add(x,y);
    }
    ll mx=0;
    for(ll i=1;i<=n;i++)
    mx=max(mx,len[i]);
    cout<<mx<<"\n";
    return 0;
}

Measured memory_bytes: 6732
la=list(input())
lb=list(input())
lc=list(input())

x = 'a'

while True:
  if x == 'a':
    if len(la) == 0:
      print('A')
      exit()
    x = la[0]
    la.remove(x)
  elif x == 'b':
    if len(lb) == 0:
      print('B')
      exit()
    x = lb[0]
    lb.remove(x)
  else:
    if len(lc) == 0:
      print('C')
      exit()
    x = lc[0]
    lc.remove(x)


Measured memory_bytes: 3064
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
using namespace std;
using ll = long long;
 
int main() {
	string s; cin >> s;
	int length = s.size();
	int K; cin >> K;
	vector<string> master;
	for (int l = 1; l <= K; l++) {
		for (int p = 0; p + l - 1 < s.size(); p++) {
			string sub = s.substr(p, l);
			if (master.size() < K) {
				master.push_back(sub);
 
				if (master.size() > 0) {
					sort(ALL(master));
					auto res = unique(ALL(master));
					master.erase(res, master.end());
				}	
			}
			else {
				if (sub < master.back()) {
					master.back() = sub;
 
					sort(ALL(master));
					auto res = unique(ALL(master));
					master.erase(res, master.end());
				}
			}
		}
	}
 
	sort(ALL(master));
	auto res = unique(ALL(master));
	master.erase(res, master.end());
 
	if (master.size() > 5) {
		master = { master[0],master[1],master[2],master[3],master[4] };
	}
 
	cout << master[K - 1] << endl;
 
    sysp;
}

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

int main(){
    int x, y;
    while(1){
        cin >> x >> y;
        if ((x == 0) && (y == 0)) break;
        else if (x <= y){
            cout << x << " " << y << endl;
        }
        else if (x > y){
            cout << y << " " << x << endl;
        }

    }
    return 0;
}


Measured memory_bytes: 3000
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from math import gcd
from functools import reduce
def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    M = max(A)

    if reduce(gcd, A) != 1:
        print("not coprime")
        return

    # linear sieve
    sieve = list(range(M + 1))
    primes = []
    for i in range(2, M + 1):
        if sieve[i] == i:
            primes.append(i)
        for p in primes:
            if sieve[i] < p or i * p > M:
                break
            sieve[i * p] = p

    # primes without duplicate
    f = list(range(M + 1))
    g = [1] * (M + 1)
    for i in range(2, M + 1):
        j = 0
        while j <= M:
            g[j] = i
            j += i * i
        f[i] = f[i // g[i]]

    # prime factorization
    used = [False] * (M + 1)
    for a in A:
        a = f[a]
        while a != 1:
            p = sieve[a]
            if used[p]:
                print("setwise coprime")
                return
            used[p] = True
            a //= p
    print("pairwise coprime")
resolve()

Measured memory_bytes: 205668
#include<cstdio>
int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a==b&&b==c) printf("1");
	else if (a==b) printf ("2");
	else if (a==c) printf ("2");
    else if (c==b) printf ("2");
	else printf("3");
	return 0;
}

Measured memory_bytes: 128
package main
import (
	"bufio"
	"fmt"
	"os"
)
var r = bufio.NewReader(os.Stdin)
func main() {
	var x int
	var y int
	fmt.Fscan(r, &x)
	fmt.Fscan(r, &y)
	
	fmt.Println(x*y, 2*(x+y))
}


Measured memory_bytes: 1108
package main

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

func main() {
	n := getInt()
	as := make([]int, n+2)
	ds := make([]int, n+1)
	ds2 := make([]int, n)
	sum := 0
	for i := range as {
		if (i == 0) || (i == n+1) {
			as[i] = 0
		} else {
			as[i] = getInt()
		}

		if i != 0 {
			ds[i-1] = abs(as[i] - as[i-1])
			sum += ds[i-1]
		}

		if i > 1 {
			ds2[i-2] = abs(as[i] - as[i-2])
		}
	}

	ans := make([]string, n)
	for i := range ans {
		ans[i] = strconv.Itoa(sum - (ds[i] + ds[i+1]) + ds2[i])
	}

	fmt.Println(strings.Join(ans, "\n"))
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
}

func getInt() int {
	i, err := strconv.Atoi(getString())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) (1 + (int)((a) - 1)/(int)(b))
//#define int long long

signed main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a + b >= c ? "Yes" : "No") << endl;
}

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

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

template <typename T, typename U>
bool chmin(T &a, const U &b){
  return (a > b ? a = b, true : false);
}

template <typename T, typename U>
bool chmax(T &a, const U &b){
  return (a < b ? a = b, true : false);
}

template <typename T, size_t N, typename U>
void fill_array(T (&a)[N], const U &v){
  std::fill((U*)a, (U*)(a + N), v);
}

template <typename T, size_t N, size_t I = N>
auto make_vector(const std::array<int, N> &a, T value = T()){
  static_assert(I >= 1);
  static_assert(N >= 1);
  if constexpr (I == 1){
    return std::vector<T>(a[N - I], value);
  }else{
    return std::vector(a[N - I], make_vector<T, N, I - 1>(a, value));
  }
}

template <typename T>
std::ostream& operator<<(std::ostream &s, const std::vector<T> &a){
  for(auto it = a.begin(); it != a.end(); ++it){
    if(it != a.begin()) s << " ";
    s << *it;
  }
  return s;
}

template <typename T>
std::istream& operator>>(std::istream &s, std::vector<T> &a){
  for(auto &x : a) s >> x;
  return s;
}


namespace haar_lib {}

namespace solver {
  using namespace haar_lib;

  constexpr int m1000000007 = 1000000007;
  constexpr int m998244353 = 998244353;

  void init(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(12);
    std::cerr << std::fixed << std::setprecision(12);
    std::cin.exceptions(std::ios_base::failbit);
  }

  void solve(){
    std::string S; std::cin >> S;
    if(S.back() == 's') S += 'e';
    S += 's';
    std::cout << S << "\n";
  }
}

int main(){
  solver::init();
  while(true){
    try{
      solver::solve();
    }catch(const std::istream::failure &e){
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 3924
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
long long q(long long n)
{
	if(n==0)
	{
		return 1;
	}
	else 
	{
		return (n*q(n-1))%mod;
	}
}

int main()
{
	long long  a,b;
	long long m,n;
	long long t; 
	scanf("%lld %lld",&a,&b);
	m=q(a)%mod;
	n=q(b)%mod;
	if(a-b>1||b-a>1)
	{ 
		cout<<0<<endl;
		return 0;
	} 
	if(a==b)
		cout<<(m*n*2)%mod<<endl;
	else 
		cout<<(m*n)%mod<<endl; 
	return 0;
} 
	 

Measured memory_bytes: 1792
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

#define ll long long
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll Mypow(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}


ll INFL = 1LL << 60;//10^18 = 2^60
int INF = 1 << 30;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};

int main(){
  int W, H, N; cin >> W >> H >> N;
  int l = 0, r = W, d = 0, u = H;
  rep(i, N){
    int x, y, a;
    cin >> x >> y >> a;
    if(a == 1) l = max(l, x);
    if(a == 2) r = min(r, x);
    if(a == 3) d = max(d, y);
    if(a == 4) u = min(u, y);
  }
  if(r-l < 0 || u-d < 0){
    cout << 0 << endl;
    return 0;
  }
  cout << (r-l) * (u-d) << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


int main(int argc, char* argv[])
{
    int n,k;
    scanf("%d%d", &n, &k);
    vector<int> a(n);
    int i;
    int i0=-1;
    for(i=0; i<n; i++) {
        scanf("%d", &a[i]);
        if(i0==-1 && a[i]>=0) i0=i;
    }
    if(i0<0) {
        i0=n;
    }
    
    ll ans=LINF;
    int tmp=i0-k;
    if(tmp>=0 && tmp<n) {
        ans=MIN(ans,abs(a[tmp]));
    }
    tmp=i0+(k-1);
    if(tmp>=0 && tmp<n) {
        ans=MIN(ans,abs(a[tmp]));
    }

    for(i=i0-k; i<i0; i++) {
        if(i<0 || i>=n) continue;
        int j=i+k-1;
        if(j>=n) continue;
        ans=MIN(ans,abs(a[i])+abs(a[j])*2);
        ans=MIN(ans,abs(a[i])*2+abs(a[j]));
    }
    printf("%lld\n", ans);

    return 0;
}



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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  vector<int> b(N,0);
  for(int i=0;i<N;i++) cin >> a.at(i);
  
  int tmp=0;
  int count=1;
  while(a.at(tmp)!=2){
    if(b.at(tmp)>0){
      count=-1;
      break;
    }
    b.at(tmp)++;
    count++;
    tmp=a.at(tmp)-1;
  }
  
  cout << count;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;
typedef long long int ll;
int main(void){
	int n; cin >> n;
	string str;
	int count = 0;
	for (int i = 1; i <= n; i++)
		if ((str = to_string(i)).length() % 2 == 1)
			count++;
	cout << count << endl;
	return 0;
}

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

int main(){
    int k;
    std::cin >> k;
    std::string S;
    std::cin >> S;
    if(S.size() <= k){
        std::cout << S << std::endl;
    }else{
        std::cout << S.substr(0, k) << "..." << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
int main(void)
{
  int a,b,c,d;
  char str[32];
  fgets(str,sizeof(str),stdin);
  sscanf(str,"%d%d%d%d",&a,&b,&c,&d);
  if((a*b) > (c*d))
  {
    printf("%d\n",a*b);
  }
  else
  {
    printf("%d\n",c*d);
  }
  return 0;
}

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


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include "E:\CP\Debugger\debugger.h"
#else 
#define debug(x...)
#endif
#define int long long
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define TC int tc; cin>>tc; for(int cn=1; cn<=tc; ++cn) 

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

    int ans = min(n%k, abs(k-(n%k)));

    cout<<ans<<"\n";
}

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

int n, A, B, C;
vector<int> v;

int MP(int cur, int a, int b, int c){
	if(cur == n){
		return min({a, b, c})==0? 1e9:abs(a-A)+abs(b-B)+abs(c-C)-30;
	}
	int pos1 = MP(cur+1, a, b, c);
	int pos2 = MP(cur+1, a+v[cur], b, c)+10;
	int pos3 = MP(cur+1, a, b+v[cur], c)+10;
	int pos4 = MP(cur+1, a, b, c+v[cur])+10;
	return min({pos1, pos2, pos3, pos4});
}

int main(){
	cin >> n >> A >> B >> C;
	for(int i = 0, k; i<n; i++){
		cin >> k;
		v.push_back(k);
	}
	cout << MP(0, 0, 0, 0) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <queue>
#include <stack>
#include <vector>
#define loop(n) for(ll i=0;i<n;i++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
typedef long long int ll;


int main()
{
    fastio;
    ll n;
    cin>>n;
    ll arr[n][3];
    for(ll i=0;i<n;i++)
		cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
		
    ll dp[n+1][3];
    
    dp[0][0] = 0;
    dp[0][1] = 0;
    dp[0][2] = 0;
    
    for(ll i=1;i<=n;i++)
    {
		
		for(ll j=0;j<3;j++)
		{
			dp[i][j] = arr[i-1][j] + max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]);
			//cout<<dp[i][j]<<" ";
		}
		//cout<<endl;
	}
	ll ans = dp[n][0] > dp[n][1] ? (dp[n][0] > dp[n][2] ? dp[n][0] : dp[n][2] ) : (dp[n][1] > dp[n][2] ? dp[n][1] : dp[n][2]);
	cout<<ans<<endl;
			
			
    return 0;
}


Measured memory_bytes: 8264
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int r, g, b;
  cin >> r >> g >> b;

  int num = 100 * r + 10 * g + b;
  if (num % 4 == 0){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }

}


Measured memory_bytes: 3536
# import numpy as np
# import gc

if __name__ == '__main__':
    n=int(input())
    l=list(map(int, input().split()))
    #v:vertex
    ans,v=0,0
    for i in range(1,n):
        v+=min(l[i-1],l[i])
    print(sum(l)-v)


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

int main() {
	int Q;

	cin >> Q;
	priority_queue<int> lq;
	priority_queue<int, vector<int>, greater<int>> rq;
	long long ans = 0;
	for( int i = 0; i < Q; i++ ) {
		int t, a, b;

		cin >> t;

		if( t == 1 ) {
			cin >> a >> b;

			ans += b;
			lq.push( a );
			rq.push( a );
			if( lq.top() > rq.top() ) {
				int l = lq.top();
				lq.pop();
				int r = rq.top();
				rq.pop();
				ans += abs( l - r );
				lq.push( r );
				rq.push( l );
			}
		}
		else {
			cout << lq.top() << " " << ans << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3828
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;


int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> row,mi,pu,a,b;
    int r;


    for(int i = 0; i < N;i++){
        cin >> r;
        if(r < 0){
            mi.push_back(r);
        }else{
            pu.push_back(r);
        }
        row.push_back(r);
    }
    VSORT(pu);
    VSORT(mi);
    VSORT(row);
    int sum = 0;
    if(mi.size() != 0){
        if(pu.size() != 0){
            for(int i = 0; i < N;i++){
                sum += abs(row[i]);
            }
            for(int i = pu.size()-1; i > 0;i--){
                int tmp = mi[mi.size()-1];
                mi.pop_back();
                a.push_back(tmp);
                b.push_back(pu[i]);
                mi.push_back(tmp-pu[i]);
                pu.pop_back();
            }
            int tmp = pu[0];
            for(int i = 0; i < mi.size();i++){
                a.push_back(tmp);
                b.push_back(mi[i]);
                tmp -= mi[i];
            }
            cout << sum << endl;
            for(int i = 0; i < a.size();i++){
                cout << a[i] << " " << b[i] << endl;
            }
            return 0;


        }else{
            for(int i = 0; i < N-1;i++){
                sum += abs(row[i]);
            }
            sum += row[N-1];

            int tmp = mi[mi.size()-1];
            for(int i = 0; i < mi.size()-1;i++){
                a.push_back(tmp);
                b.push_back(mi[i]);
                tmp -= mi[i];
            }
         
        }
    }else{
        if(pu.size() != 0){
            for(int i = 1; i < N;i++){
                sum += abs(row[i]);
            }
            sum -= row[0];

            int tmp = pu[0];
            for(int i = 1; i < pu.size()-1;i++){
                a.push_back(tmp);
                b.push_back(pu[i]);
                tmp -= pu[i];
            }
            b.push_back(tmp);
            a.push_back(pu[pu.size()-1]);
        }
    }
    cout << sum << endl;
    for(int i = 0; i < a.size();i++){
        cout << a[i] << " " << b[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3956