akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<int> c(n - 1), s(n - 1), f(n - 1); REP(i, n - 1) cin >> c[i] >> s[i] >> f[i];
  REP(start, n - 1) {
    int elapsed = s[start] + c[start];
    FOR(i, start + 1, n - 1) {
      if (elapsed < s[i]) elapsed = s[i];
      while (elapsed % f[i] != 0) ++elapsed;
      elapsed += c[i];
    }
    cout << elapsed << '\n';
  }
  cout << 0 << '\n';
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int dp[10000];
int main()
{
	int N, M;
	cin >> N >> M;
	pairs(C);
	fx(M) {
		int a, b;
		cin >> a >> b;
		int sum = 0;
		fy(b) {
			int c;
			cin >> c;
			sum += (1 << (c - 1));
		}
		pb(C,make_pair(a,sum))
	}
	fx(10000) {
		dp[x] = INT_MAX/2;
	}
	dp[0] = 0;

	fx(M) {
		fy(1<<N) {
			dp[y | C[x].second] = min(dp[y | C[x].second],dp[y]+C[x].first);
			//ce((y | C[x].second))
		}
	}

	if (dp[(int)pow(2,N)-1]==INT_MAX/2) {
		ce(-1)
	}
	else {
		ce(dp[(int)pow(2, N ) - 1])
	}
    return 0;
}



Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

macro_rules! read_value {
    ($next:expr, [graph1; $len:expr]) => {{
        let mut g = vec![vec![]; $len];
        let ab = read_value!($next, [(usize1, usize1)]);
        for (a, b) in ab {
            g[a].push(b);
            g[b].push(a);
        }
        g
    }};
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input!(a: chars);
    puts!("{}\n", if a[0] <= 'Z' { 'A' } else { 'a' });
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

ll N,C;
ll D[30][30];

ll t[500][500];

ll mem[3][30];

ll solve(ll id,ll nc){
  if(mem[id][nc]!=-1)
    return mem[id][nc];
  
  ll res=0;
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      if( (i+j)%3==id )
        res+= D[ t[i][j] ][nc];
  
  return mem[id][nc]=res;
}

ll solve(){
  ll res=(1LL<<60);
  for(int nc=0;nc<C;nc++)
    for(int nd=0;nd<C;nd++)
      if(nc!=nd)
        for(int ne=0;ne<C;ne++)
          if(nc!=ne)
            if(nd!=ne)
              res=min(res, solve(0,nc)+solve(1,nd)+solve(2,ne) );
  return res;
}

int main(){
  memset( mem, -1 , sizeof(mem) );
  
  cin>>N>>C;
  for(int i=0;i<C;i++){
    for(int j=0;j<C;j++){
      cin>>D[i][j];
    }
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      cin>>t[i][j];
      t[i][j]--;
    }
  }
  cout<< solve() <<endl;
  return 0;
}


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

int main() {
    int s;
    int h;
    int m;
    cin >> s;
    if (s >= 0 && s < 86400) {
        int h = s / 3600;
        s = s % 3600;
        int m = s / 60;
        s = s % 60;
        cout << h << ":" << m << ":" << s << endl;
    }
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;

int main(){
  int H,W;
  cin>>H>>W;
  vector<string> s(H);
  for(int i=0;i<H;i++){
    cin>>s[i];
  }
  vector<int> obsr[2010];
  for(int i=0;i<H;i++){
    obsr[i].push_back(-1);
    for(int j=0;j<W;j++){
      if(s[i][j]=='#') obsr[i].push_back(j);
    }
    obsr[i].push_back(W);
  }
  vector<int> obsc[2010];
  for(int i=0;i<W;i++){
    obsc[i].push_back(-1);
    for(int j=0;j<H;j++){
      if(s[j][i]=='#') obsc[i].push_back(j);
    }
    obsc[i].push_back(H);
  }
  int score[H][W];
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      score[i][j]=0;
    }
  }
  int cnt=0;
  for(int i=0;i<H;i++){
    cnt=0;
    for(int j=0;j<W;j++){
      if(s[i][j]=='.') score[i][j]+=obsr[i][cnt+1]-obsr[i][cnt]-1;
      else cnt++;
    }
  }

  for(int i=0;i<W;i++){
    cnt=0;
    for(int j=0;j<H;j++){
      if(s[j][i]=='.') score[j][i]+=obsc[i][cnt+1]-obsc[i][cnt]-1;
      else cnt++;
    }
  }

  int ans=0;
  for(int i=0;i<H;i++){
    
    for(int j=0;j<W;j++){
      ans=max(ans,score[i][j]);
      //cout<<"("<<i<<","<<j<<")="<<score[i][j]<<endl;
    }
  }
  cout<<ans-1<<endl;
}



Measured memory_bytes: 52096
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

void debug_out() { std::cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n)-1); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n)-1); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,u,v; cin >> n >> u >> v;
    u--; v--;
    graph g(n);
    rep(i,0,n-1){
        int a,b; cin >> a >> b;
        a--; b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    if(g[u].size()==1 && g[u][0] == v){
        cout << 0 << endl;
        return 0;
    }
    vector<int> c(n,-1);
    c[v] = 0;
    queue<int> que;
    que.push(v);
    while(!que.empty()){
        auto x = que.front();
        que.pop();
        for(auto nx: g[x]){
            if(c[nx]<0){
                que.push(nx);
                c[nx] = c[x]+1;
            }
        }
    }
    vector<int> d(n,-1);
    d[u] = 0;
    que.push(u);
    while(!que.empty()){
        auto x = que.front();
        que.pop();
        for(auto nx: g[x]){
            if(d[nx]<0){
                que.push(nx);
                d[nx] = d[x]+1;
            }
        }
    }
    int ans = 0;
    rep(i,0,n){
        if(c[i]>d[i]){
            chmax(ans,c[i]-1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6656
#include <iostream>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <sstream>
#include <vector>
#include <map>
#include <fstream>
using namespace std;

const int N = 3;

string str[N];
bool win_flag = false;
char win = NULL;

struct MAN {
	string str;
	int len;
	int head;
};

MAN man[N];

void dfs(int i);

int main()
{
	for (int i = 0; i < N; i++) {
		cin >> man[i].str;
		man[i].len = man[i].str.length();
		man[i].head = 0;
	}

	dfs(0);

	cout << win << endl;

	return 0;
}

void dfs(int i)
{
	int x = man[i].head;

	if (man[i].head < man[i].len) {
		man[i].head++;
		switch (man[i].str[x]) {
		case 'a':
			dfs(0);
			break;
		case 'b':
			dfs(1);
			break;
		case 'c':
			dfs(2);
			break;
		}
	}
	else {
		if (win_flag == false) {
			win_flag = true;
			switch (i) {
			case 0:
				win = 'A';
				break;
			case 1:
				win = 'B';
				break;
			case 2:
				win = 'C';
				break;
			}
		}
	}
}

Measured memory_bytes: 256
#include <iostream>


using namespace std;

long long min(long long array[],int n){
    long long min=array[0];
    for(int i=0;i<n;++i){
        if(array[i]<=min){
            min=array[i];
        }
    }
    return min;
}

long long max(long long array[],int n){
    long long max=array[0];
    for(int i=0;i<n;++i){
        if(array[i]>=max){
            max=array[i];
        }
    }
    return max;
}

long long sum(long long array[],int n){
    long long sum=0;
    for(int i=0;i<n;++i){
        sum+=array[i];
    }
    
    return sum;
}



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

    long long array[n];
    for(int i=0;i<n;++i){
        cin>>array[i];
    }
    
    cout<<min(array,n)<<" "<<max(array,n)<<" "<<sum(array,n)<<endl;
    
}






Measured memory_bytes: 3196
#include <stdio.h>
int main(void) {
    int n;
    int h[100000];
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &h[i]);
    }

    int max = 0;
    int cnt = 0;

    for (int i = 0; i < n - 1; i++) {
        if (h[i] >= h[i + 1]) {
            //printf("%d\n", h[i]);
            cnt++;
        } else {
            if (max < cnt) {
                max = cnt;
            }
            cnt = 0;
        }
        if (max < cnt) {
            max = cnt;
        }
    }
    printf("%d\n", max);
    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    
    int[] integer = new int[n];
    
    for (int i = 0; i < integer.length; i++) 
      integer[i] = sc.nextInt();
    
   	int count = 0;
    loop : while (true) {
	    for (int i = 0; i < integer.length; i++) {
          if (integer[i] % 2 == 0)
	          integer[i] /= 2;
          else 
            break loop;
        }
      	count++;
    }
    
    System.out.println(count);
  }
}
      

Measured memory_bytes: 21588
#include <bits/stdc++.h>
//#pragma comment(linker, "/STACK: 2000000")

using namespace std;

const int N = 2e6 + 5;

int n , m ;

int main() {

    cin>>n>>m;
    priority_queue<int> q;
    long long sol = 0;
    for(int i = 0;i<n;i++)
    {
        int t ; cin>>t;
        q.push(t);
    }
    while(m-- && q.size())
    {
        int add = q.top()/2;
        q.pop();
        if(add)
            q.push(add);
    }
    while(q.size())
    {
        sol+=q.top();
        q.pop();
    }
    cout<<sol;
    return 0;

}


Measured memory_bytes: 892
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
#define out(S) cout<<(S)<<endl;
#define REP(i,b) for(size_t i=0;i<(b);i++)
#define rREP(i,b) for(int i=(b)-1;i>=0;i--)
#define FOR(i,a,b) for(size_t i=(a);i<(b);i++)
#define rFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define Foreach(item,collection) for(auto item:collection)
#define mod(i) ((i) % (ll)(1e9 + 7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a * modpow((ll)b,(ll)(1e9 + 5))))
#define Yes out("Yes")
#define No out("No")
#define NO out("NO")
#define YES out("YES")
#define INF 1e10;
#define ShowAll(collection) for(auto i:collection){out(i);}
#define IfOut(condition,text) if((condition)){out(text);return 0;}
#define IfeOut(condition,itext,etext) if(condition){out(itext);return 0;}else{out(etext);return 0;}
#define Select(collection,condition,result) Foreach(i,collection){result+=condition;}
#define GetAuto(_N,vect) {cin>>_N;vect.resize(_N);REP(i,_N){cin>>vect[i];}}
#define beginend(vec) (vec).begin(),(vec).end()
#define pb(item) push_back(item)
#define removeAll(vec,deleg) auto itr=remove_if(beginend(vec),deleg);vec.erase(itr,vec.end());
void removeAt(string& s, int index) { s.erase(index, 1); }
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }
ll manhattanDistance(ll x1, ll y1, ll x2, ll y2) { return (abs(x2 - x1) + abs(y2 - y1)); }
vector<ll> sieveOfEratosthenes(int max) {ll prime;double sqrtmax = sqrt(max);vector<ll> primeVec, searchVec;FOR(i, 2, max + 1) searchVec.push_back(i);do{prime = searchVec[0];primeVec.push_back(prime);auto itr = remove_if(beginend(searchVec), [=](ll x)->bool {return x%prime == 0; });searchVec.erase(itr, searchVec.end());} while (prime < sqrtmax);primeVec.reserve(primeVec.size() + searchVec.size());primeVec.insert(primeVec.end(), beginend(searchVec));return primeVec;}

int solve(string S) {
	stack<char> st;
	bool f = true;
	Foreach(i, S) {
		if (i == '('||i=='[') st.push(i);
		if (i == ')' || i == ']') {
			if (st.size() == 0) { f = false; break; }
			auto p = st.top();
			if ((i == ')'&&p == '(') || (i == ']'&&p == '[')) st.pop();
			else { f = false; break; }
		}
	}
	IfeOut(st.size() == 0 && f, "yes", "no");
}

int main() {
	char S[105];
	while (cin.getline(S, sizeof(S)))
	{
		if (S[0]=='.'&&S[1]=='\0') break;
		solve(S);
	}
	return 0;
}

Measured memory_bytes: 3156
import java.awt.*;
import java.awt.geom.*;
import java.io.*;
import java.util.*;
class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if(n == 0) break;
			boolean[] a = new boolean[2*n+1];
			boolean[] b = new boolean[2*n+1];

			Arrays.fill(b, true);

			for(int i = 0; i < n; i++) {
				int in = sc.nextInt();
				a[in] = true;
				b[in] = false;
			}
			b[0] = false;
			ArrayList<Integer> A = new ArrayList<Integer>();
			ArrayList<Integer> B = new ArrayList<Integer>();

			for(int i = 0; i < 2*n+1; i++) {
				if(a[i]) A.add(i);
				if(b[i]) B.add(i);
			}

			Collections.sort(A);
			Collections.sort(B);

			int last = 0;

			while(!A.isEmpty() && !B.isEmpty()) {
				boolean ok = false;
				for(int i = 0; i < A.size(); i++) {
					if(A.get(i) > last) {
						last = A.get(i);
						A.remove(i);
						ok = true;
						break;
					}
				}
				if(!ok) {
					last = 0;
				}
				if(A.isEmpty()) break;
				ok = false;
				for(int i = 0; i < B.size(); i++) {
					if(B.get(i) > last) {
						last = B.get(i);
						B.remove(i);
						ok = true;
						break;
					}
				}
				if(!ok) {
					last = 0;
				}
			}

			int as = B.size();
			int bs = A.size();

			System.out.println(as + "\n" + bs);






		}

	}


}

Measured memory_bytes: 18664
#include <cstdio>

int main(){

  int x, y;
  int group[13] ={-1, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1}; 
  scanf("%d %d", &x, &y);

  if(group[x] == group[y])
    printf("Yes\n");
  else
    printf("No\n");

  return 0;
}

  


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>

int main(void){
  int i,j,n,ma,tmp;
  int *a;

  ma = -1;
  scanf("%d", &n);
  a = (int*)(malloc(sizeof(int)*n));
  scanf("%d", &a[0]);
  i=1;
  while(i<n){
    scanf("%d", &a[i]);
    tmp = a[0]-a[i]>0?a[0]-a[i]:a[i]-a[0];
    if(tmp > ma) ma = tmp;
    i++;
  }
  for(j=1; j<n; j++){
    for(i=0; i<n; i++){
      tmp = a[j]-a[i]>0?a[j]-a[i]:a[i]-a[j];
      if(tmp > ma) ma = tmp;
    }
  }
  printf("%d",ma);
}

Measured memory_bytes: 128
/*  -*- coding: utf-8 -*-
 *
 * 2904.cc: GuruGuru
 */

#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 = 1000;

/* typedef */

/* global variables */

char s[MAX_N + 4];

/* subroutines */

/* main */

int main() {
  scanf("%s", s);

  int cnt = 0, cdi = 0;
  bool sp = false;
  for (int i = 0; s[i]; i++) {
    int ndi = (cdi + (s[i] == 'R' ? 1 : 3)) & 3;

    if (cdi == 0) sp = (ndi == 1);
    else if (ndi == 0) {
      if (cdi == 3 && sp) cnt++;
      sp = false;
    }

    cdi = ndi;
  }

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



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

public class Main{
    public static void main(String args[])throws IOException{
      try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
        String str_input = br.readLine();
        String human = br.readLine();
        int result = 0;

        String[] str_array = str_input.split(" ", 0);
        String[] human_array = human.split(" ", 0);

        int num = Integer.parseInt(str_array[0]);
        int height = Integer.parseInt(str_array[1]);

        for(int i = 0; i < num; i++){
          int tmp_height = Integer.parseInt(human_array[i]);
          if(height <= tmp_height){
            result++;
          }
        }

        System.out.println(result);
      }
    }
}

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

#define int long long
#define ld long double

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repb(i,a,b) for(int i=a;i>b;i--)

#define pb push_back
#define mp make_pair
#define all(A) A.begin(),A.end()
#define allr(A) A.rbegin(),A.rend()
#define precise(i) fixed << setprecision(i)
#define fi first
#define se second

#define err() cout<<"\n==================================\n";
#define errA(A) for(auto i:A) cout<<i<<" "; cout<<"\n";
#define err1(a) cout<<#a<<" "<<a<<"\n";
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<"\n";
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<"\n";
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<"\n";

const int logN = 20;
const int M = 1000000007;
const int INF = 1e12;
#define PI 3.14159265;
const int N = 200005;

#define Pii pair<int,int>
#define Vi vector<int>
#define Vpii vector<Pii>

void solve()
{
       string s1,s2;
       cin>>s1>>s2;
       int ans=0;
       rep(c,0,s1.size())
       {
              if(s1[c]!=s2[c])
              {
                     ans++;
              }
       }
       cout<<ans;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--)
    {
           solve();
    }
    return 0;
}

Measured memory_bytes: 3772
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def get_z(factor):
    for f_list in factor:
        for i in range(f_list[1]):
            z = f_list[0] ** (i + 1)
            if z not in choice_list:
                choice_list.append(z)
                return z

choice_list = []
n = int(input())
factor = factorization(n)

while n > 1:
    z = get_z(factor)
    if z is None:
        break
#     print(z)
#     print(choice_list)
    n //= z
    factor = factorization(n)
#     print(z)
print(len(choice_list))

Measured memory_bytes: 63404
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    ll a, b;
    char op;
    cin >> a >> op >> b;
    if(op == '+'){
        cout << a + b << endl;
    } else {
        cout << a - b << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int a, b;

    scanf("%d %d", &a, &b);

    if (1 <= a && a <= 9 && 1 <= b && b <= 9) {
        printf("%d\n", a*b);
    }else {
        printf("-1\n");
    }

    return 0;
}


Measured memory_bytes: 128
/*
sonu_verma1
*/
#include <bits/stdc++.h>
// For policy based data structure
/*#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> */
using namespace std;
/*using namespace __gnu_pbds; 
typedef tree<int, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set;*/
 
#define MD 1000000007
#define X first
#define Y second
#define pb push_back
#define debug(val, ch) cout <<val <<ch
#define FOR(i, st, en, ch) for(register int i = (st); i <= (en) ; i += (ch))
#define RFOR(i, st, en, ch) for(register int i = (st); i >= (en) ; i -= (ch))
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
 
typedef long long int ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<int, bool> pib;
typedef pair<bool, int> pbi;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
/*********************************************************************/
void test(int r)
{
	int x;
	cin>>x;
	if(x<600)
		cout<<8;
	else if(x<800)
		cout<<7;
	else if(x<1000)
		cout<<6;
	else if(x<1200)
		cout<<5;
	else if(x<1400)
		cout<<4;
	else if(x<1600)
		cout<<3;
	else if(x<1800)
		cout<<2;
	else
		cout<<1;
	

}
/***********************************************************************/
int main()
{
	fast();
    int t=1,r;
    // cin>>t;
    for(r=1;r<=t;r++)
        test(r);
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;


signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  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<stdio.h>
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <functional>
#include <stdio.h>
#include <array>
#include <algorithm>
#include <string>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include <queue>
#include<iomanip>
#include<bitset>
#include<stack>
#include<set>
#include<limits>
#include <complex>
using namespace std;

const int mod = 1000000007;
struct Mod {
public:
	int num;
	Mod() : num(0) { ; }
	Mod(long long int n) : num((n % mod + mod) % mod) { ; }
	Mod(int n) : num((n % mod + mod) % mod) { ; }
	operator int() { return num; }
};

Mod operator+(const Mod a, const Mod b) { return Mod((a.num + b.num) % mod); }
Mod operator+(const long long int a, const Mod b) { return Mod(a) + b; }
Mod operator++(Mod &a) { return a + Mod(1); }
Mod operator-(const Mod a, const Mod b) { return Mod((mod + a.num - b.num) % mod); }
Mod operator-(const long long int a, const Mod b) { return Mod(a) - b; }
Mod operator--(Mod &a) { return a - Mod(1); }
Mod operator*(const Mod a, const Mod b) { return Mod(((long long)a.num * b.num) % mod); }
Mod operator*(const long long int a, const Mod b) { return Mod(a)*b; }
Mod operator+=(Mod &a, const Mod b) { return a = a + b; }
Mod operator+=(long long int &a, const Mod b) { return a = a + b; }
Mod operator-=(Mod &a, const Mod b) { return a = a - b; }
Mod operator-=(long long int &a, const Mod b) { return a = a - b; }
Mod operator*=(Mod &a, const Mod b) { return a = a * b; }
Mod operator*=(long long int &a, const Mod b) { return a = a * b; }
Mod operator^(const Mod a, const int n) {
	if (n == 0) return Mod(1);
	Mod res = (a * a) ^ (n / 2);
	if (n % 2) res = res * a;
	return res;
}
Mod inv(const Mod a) { return a ^ (mod - 2); }
Mod operator/(const Mod a, const Mod b) {
	assert(b.num != 0);
	return a * inv(b);
}
Mod operator/(const long long int a, const Mod b) {
	assert(b.num != 0);
	return Mod(a) * inv(b);
}
Mod operator/=(Mod &a, const Mod b) {
	assert(b.num != 0);
	return a = a * inv(b);
}

#define MAX_N 1024000

Mod fact[MAX_N], factinv[MAX_N];
void init() {
	fact[0] = Mod(1); factinv[0] = 1;
	for (int i = 0; i < MAX_N - 1; ++i) {
		fact[i + 1] = fact[i] * Mod(i + 1);
		factinv[i + 1] = factinv[i] / Mod(i + 1);
	}
}
Mod comb(const int a, const int b) {
	return fact[a] * factinv[b] * factinv[a - b];
}


Mod getans(int m, int p) {
	if (m == 0)return 1;
	Mod bb(comb(p+m, m) - comb(p + m, m - 1));
	return comb(p + m, m) - comb(p + m, m - 1);
}


int main() {
	init();
	int N, M, K; cin >> N >> M >> K;
	Mod totalans(0);
	for (int pxtime = N; pxtime <= N + K; ++pxtime) {
		int mxtime = pxtime - N;
		int pytime = M + (K-pxtime+N);
		int mytime = K - pxtime + N;
		Mod ans(1);
		ans *= getans(mxtime, pxtime);
		ans *= getans(mytime, pytime);
		ans *= comb(N + M + 2 * K, pxtime + mxtime);
		totalans += ans;
	}
	cout << totalans << endl;
	return 0;
}

Measured memory_bytes: 11100
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# 各日に対して、関数：残量 -> 最適な熱量 を持つことを考える
# これは折れ線。傾きが増加する部分 → マージしてまとめる
# 常に、傾きの減少列の形で持つことになる

from collections import deque

N,L = map(int,readline().split())
m = map(int,read().split())
TV = zip(m,m)

answer = []
INF = 10 ** 18

# 1日目
t,v = next(TV)
answer.append(t)
qT = deque([t])
qV = deque([v])
sum_q = t * v # 今持っている総熱量

for t,v in TV:
    qT.appendleft(t); qV.appendleft(v)
    sum_q += t * v
    # 右側からvだけ捨てる
    rest = v
    while qV[-1] <= rest:
        x = qV.pop()
        rest -= x
        sum_q -= x * qT.pop()
    qV[-1] -= rest
    sum_q -= rest * qT[-1]
    # 左側から傾きの増大部分をマージ
    while len(qT) >= 2:
        t0 = qT[0]; t1 = qT[1]
        if t0 > t1:
            break
        qT.popleft()
        v0 = qV.popleft(); v1 = qV[0]
        t2 = (t0 * v0 + t1 * v1) / (v0 + v1)
        qT[0] = t2; qV[0] += v0
    answer.append(sum_q/L)

print('\n'.join(map(str,answer)))

Measured memory_bytes: 114712
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
int main(){
	int n,q,a,b,c;
	scanf("%d",&n);
	vector<int>v(n);
	for(int i=0;i<n;i++)scanf("%d",&v[i]);
	for(scanf("%d",&q);q--;){
		scanf("%d%d%d",&a,&b,&c);rotate(v.begin()+a,v.begin()+b,v.begin()+c);
	}
	for(int i=0;i<n;i++)printf(i<n-1?"%d ":"%d\n",v[i]);
}



Measured memory_bytes: 2772
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - Kyu in AtCoder
 */

#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 */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  int q = 0;
  for (int p = 1800; x < p; p -= 200, q++);

  printf("%d\n", q + 1);
  return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 2e7 + 9, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
int main()
{
long long n;
cin>>n;
cout<<n*(n+1)/2;



    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName (string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const {return t;}
  string do_falsename() const {return f;}
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

int main() {
  int n, T;
  cin >> n >> T;
  vector<int> t(n);
  cin >> t;
  int s = T;
  for (int i = 1; i < n; ++i) s += min(T, t[i] - t[i - 1]);
  cout << s << endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size();
  int m = t.size();
  string ans = "~";
  rep(i, n - m + 1) {
    bool ok = true;
    string s2 = s;
    rep(j, m) {
      if(s2[i + j] != t[j] && s2[i + j] != '?') ok = false;
      s2[i + j] = t[j];
    }
    if(ok) {
      replace(all(s2), '?', 'a');
      ans = min(ans, s2);
    }
  }
  cout << (ans == "~" ? "UNRESTORABLE" : ans) << endl;
}

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a, b, h; cin >>a >> b >> h;
    cout << (a+b)*h/2 << endl;
    return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n,v,u,p[100010];
vector<int> G[100010],d_u,d_v;

void dfs(int s,int par,int d,vector<int> &D){
    D[s]=d;
    for(int t:G[s]){
        p[t]=s;
        if(t==par) continue;
        dfs(t,s,d+1,D);
    }
}


void solve(){
    cin >> n >> u >> v;
    d_u.resize(n,0);
    d_v.resize(n,0);
    u--;v--;
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(u,-1,0,d_u);
    dfs(v,-1,0,d_v);
    int ma=0,idx=-1;
    rep(i,n){
        //cout << d_v[i] << " " << d_u[i] << endl; 
        if (d_v[i]>d_u[i] && d_v[i]>ma) {
            ma=d_v[i];idx=i;
        }
    }
    if (idx==-1) {
        cout << 0 << endl;
        return;
    }
    int ta=d_u[idx],ao=d_v[idx],ans=0;
    while(true){
        if (ta!=0) ta--;
        else ta+=1;
        if (ta==ao) break;
        ao-=1;ans+=1;
        if (ta==ao) break;
    }
    cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 12032
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


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

	int n;
	cin >> n;
	vector<int> ans(10010);
	for (int x = 1; x <= 100; x++) {
		for (int y = 1; y <= 100; y++) {
			for (int z = 1; z <= 100; z++) {
				int val = x * x + y * y + z * z + x * y + y * z + z * x;
				if (val <= n) ans[val]++;
			}
		}
	}
	for (int i = 1; i <= n; i++) cout << ans[i] << '\n';
}

Measured memory_bytes: 3652
#include <stdio.h>

int GCD(int m, int n) {
  if(n==0) return(m);
  else return GCD(n,m%n);
}

int main(void) {
  int n, numa, numb, numc, key, i;
  if(scanf("%d",&n),n==2) {
    scanf("%d%d",&numa,&numb);
    key = GCD(numa,numb);
    for(i = 1; i <= key/2; i++ ) {
      if(key % i == 0) printf("%d\n",i);
    }
    printf("%d\n",key);
  } else {
    scanf("%d%d%d",&numa,&numb,&numc);
    key = GCD(numa,numb);
    key = GCD(numc,key);
    for(i = 1; i <= key/2; i++ ) {
      if(key % i == 0) printf("%d\n",i);
    }
    printf("%d\n",key);
  }
  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=55,M=N*N*2;
int n,tot,sum,x[N],y[N],head[N],nex[M],to[M],wi[M];
map<pair<int,int>,int>mp;
vector<int>v[N][M];
void add(int u,int v,int w)
{
    to[++tot]=v;nex[tot]=head[u];head[u]=tot;wi[tot]=w;
    to[++tot]=u;nex[tot]=head[v];head[v]=tot;wi[tot]=w;
}
bool vis[N];
void dfs(int u,int p)
{
    sum++;
    vis[u]=true;
    for(int i=0;i<v[u][p].size();i++)
    {
        int y=v[u][p][i];
        if(!vis[y])
            dfs(y,p);
    }
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d%d",&x[i],&y[i]);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
    {
        pair<int,int>s=make_pair(x[i]-x[j],y[i]-y[j]);
        int t=mp[s];
        if(!t) t=mp[s]=++tot;
        v[i][t].push_back(j);
        v[j][t].push_back(i);
    }
    int ans=n;
    for(int i=1;i<=tot;i++)
    {
        int res=0;
        memset(vis,false,sizeof(vis));
        for(int j=1;j<=n;j++)
            if(!vis[j])
        {
            res++;
            vis[j]=true;
            dfs(j,i);
        }
        ans=min(ans,res);
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, k; string s;
	cin >> n >> k >> s;
	int res = 0;
	for (int i = 1; i < s.length(); ++i)
		if (s[i] == s[i - 1])
			++res;
	for (int i = 1; i < s.length(); ++i) {
		if (s[i] != s[i - 1] && k) {
			--k; ++i; ++res;
			while (i < s.length() && s[i] == s[i - 1])
				++i;
			if (i < s.length() && s[i] != s[i - 1])
				++res;
		}
	}
	cout << res << '\n';
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
int main(void){
  int i,a,b,c,t=0;
  scanf("%d %d",&a,&b);
  for(i=0;i<b;i++)    {scanf("%d",&c);t=t+c;}
  if(t>a)             {printf("-1");}
  else                {printf("%d",a-t);}
  return 0; 
}

Measured memory_bytes: 1712
# include "iostream"
# include "cstdio"

using namespace std;

const int maxm=3e2+10;

int N;
long long Map[maxm][maxm];
bool Visit[maxm][maxm];

int main(){
	register int i,j,k;
	long long Ans=0;
	scanf("%d",&N);
	for(i=1;i<=N;i++){
		for(j=1;j<=N;j++){
			scanf("%lld",&Map[i][j]);
			Ans+=Map[i][j];
		}
	}
	for(k=1;k<=N;k++){
		for(i=1;i<=N;i++){
			if(i==k) continue;
			for(j=1;j<=N;j++){
				if(j==i || j==k) continue;
				if(Map[i][j]>Map[i][k]+Map[j][k]){
					printf("-1");
					return 0;
				}
				if(Visit[i][j]) continue;
				if(Map[i][j]==Map[i][k]+Map[k][j]){
                    Ans-=Map[i][j];
                    Visit[i][j]=1;
				}
			}
		}
	}
	Ans>>=1;
	cout<<Ans;
	return 0;
}

Measured memory_bytes: 1152
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] T = new int[N];
    int total =0;
    for (int i=0; i<N; i++) T[i] = sc.nextInt();
    for (int i=0; i<N; i++) {
      total += T[i];
    }
    int M = sc.nextInt();
    int[] P = new int[M];int[] X = new int[M];
    for (int i=0; i<M; i++) {
      P[i] = sc.nextInt();
      X[i] = sc.nextInt();
    }
    for (int i=0; i<M; i++) {
      int a = P[i];
      int ptotal;
      ptotal = total - T[a-1] + X[i];
      System.out.println(ptotal);
    }
  }
}

Measured memory_bytes: 21972
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
using namespace std;
int main() {
    string s;
    cin>>s;
    long k;
    cin>>k;
    bool flg=false;
    for (int i=0; i<k; i++){
        if(s[i]!='1'){cout<<s[i];flg=true;break;}
    }
    if(flg==false)cout<<1;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,A,B,C,D=map(lambda x: int(x)-1,input().split())
    N+=1
    S=list(input())
    S.append('#')
    if C>D:
        f=False
    else:
        f=True
    for i in range(A,C-1):
        if S[i]=='#' and S[i+1]=='#':
            print('No')
            exit()
        if D-1>=i>=B-1 and S[i]=='.' and S[i+1]=='.' and S[i+2]=='.':
            f=True
    for i in range(B,D-1):
        if S[i]=='#' and S[i+1]=='#':
            print('No')
            exit()
    print('Yes' if f==True else 'No')

if __name__ == '__main__':
    main()


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

int main() {
  int N, K;
  int ans = 1;
  cin >> N >> K;
  for(int i = 0; i < N; i++) {
  	ans = min(ans + K, ans * 2);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int ans = 0;
        for(int i=0;i<3;i++){
            if(S.charAt(i)=='1') ans++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int N,x=0,a=0,c=0;cin>>N;
  vector<long long int>A(N),B(N),C(N);
  for(int i=0;i<N;i++)cin>>A.at(i);
  for(int i=0;i<N;i++)cin>>B.at(i);
  for(int i=0;i<N;i++)cin>>C.at(i);
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  sort(C.begin(),C.end());
  for(int i=0;i<N;i++){
    a=distance(A.begin(),lower_bound(A.begin()+a,A.end(),B.at(i)));
    c=distance(C.begin(),upper_bound(C.begin()+c,C.end(),B.at(i)));
    x+=a*(N-c);
  }
  cout<<x<<endl;
}

Measured memory_bytes: 2560
unittest
{
	assert( [ "9 3", "8 3", "4 2", "2 1" ].parse.expand.solve == 4 );
	assert( [ "100 6", "1 1", "2 3", "3 9", "4 27", "5 81", "6 243" ].parse.expand.solve == 100 );
	assert( [ "9999 10", "540 7550", "691 9680", "700 9790", "510 7150", "415 5818", "551 7712", "587 8227", "619 8671", "588 8228", "176 2461" ].parse.expand.solve == 139815 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto hn = input.front.split.to!( long[] );
	auto abs = new long[ 2 ][ hn[ 1 ] ];
	foreach( ref ab; abs )
	{
		input.popFront;
		ab = input.front.split.to!( long[] );
	}
	return tuple( hn[ 0 ], abs );
}

auto solve( long h, long[ 2 ][] abs )
{
	// dp[ 与ダメージ合計 ] = 使用魔力合計
	auto ans = long.max;
	auto dp = new long[ 1 + h + 10L ^^ 4 ];
	dp[ 1 .. $ ] = long.max;
	foreach( d; 0L .. h )
	{
		foreach( ab; abs )
		{
			if( dp[ d ] == long.max ) continue;
			
			auto dd = d + ab[ 0 ];
			dp[ dd ] = min( dp[ dd ], dp[ d ] + ab[ 1 ] );
			if( h <= dd ) ans = min( ans, dp[ dd ] );
		}
	}
	return ans;
}


Measured memory_bytes: 2684
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;

int main() {
  int n, ans = 0;
  cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d[i];
  rep(i, n) {
    rep(j, n) {
      if (i == j) continue;
      ans += d[i] * d[j];
    }
  }
  ans /= 2;

  cout << ans << endl;

  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    long long w,h,x,y; cin >> w >> h >> x >> y;
    cout << w*h/2.0 << " ";
    if(w/2.0 == x && h/2.0 == y){
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

#define PLUS (0)
#define COUNT (1)
#define MAX_N (100100)
#define MAX_Q (100100)

using namespace std;

typedef long long lint;
typedef pair<lint, lint> P;

struct Edge {
	int to, cost;
	Edge(int to, int cost) : to(to), cost(cost){}
	Edge(){}
};

struct Query {
	lint fs, fg, idx, type;
};

bool operator < (const Query &a, const Query &b)
{
	if (a.fs - b.fs) return (a.fs < b.fs);
	return (a.type < b.type);
}

vector<Edge> g[MAX_N];
Query query[2 * MAX_Q];

int bit[2 * MAX_N + 1];
lint ds[MAX_N], dg[MAX_N];
int res[MAX_Q];

void add(int pos, int val)
{
	while (pos <= 2 * MAX_N){
		bit[pos] += val;
		pos += pos & -pos;
	}
}

int sum(int pos)
{
	int ret = 0;
	while (pos){
		ret += bit[pos];
		pos &= (pos - 1);
	}
	return (ret);
}

void dijkstra(int s, lint *mem)
{
	bool done[MAX_N];
	
	memset(done, false, sizeof(done));
	mem[s] = 0;
	
	priority_queue<P, vector<P>, greater<P> > pq;
	
	for (pq.push(P(0, s)); pq.size(); pq.pop()){
		P x = pq.top();
		if (done[x.second]) continue;
		mem[x.second] = x.first;
		done[x.second] = true;
		
		for (int i = 0; i < g[x.second].size(); i++){
			Edge e = g[x.second][i];
			
			pq.push(P(g[x.second][i].cost + x.first, g[x.second][i].to));
		}
	}
}

int main()
{
	int n, m, q;
	vector<lint> vs;
	map<lint, int> conv;
	
	scanf("%d %d", &n, &m);
	
	for (int i = 0; i < m; i++){
		int from, to, cost;
		scanf("%d %d %d", &from, &to, &cost);
		g[from].push_back(Edge(to, cost));
		g[to].push_back(Edge(from, cost));
	}
	
	dijkstra(0, ds);
	dijkstra(n - 1, dg);
	
	scanf("%d", &q);
	for (int i = 0; i < q; i++){
		scanf("%lld %lld", &query[i].fs, &query[i].fg);
		query[i].idx = i;
		query[i].type = COUNT;
		vs.push_back(query[i].fg);
	}
	for (int i = 0; i < n; i++){
		query[i + q].fs = ds[i]; query[i + q].fg = dg[i];
		query[i + q].type = PLUS;
		vs.push_back(query[i + q].fg);
	}
	
	sort(vs.begin(), vs.end());
	int idx = 0;
	conv[vs[0]] = idx++;
	for (int i = 1; i < q + n; i++){
		if (vs[i] != vs[i - 1]) conv[vs[i]] = idx++;
	}
	
	sort(query, query + q + n);
	
	for (int i = 0; i < q + n; i++){
		query[i].fg = conv[query[i].fg];
	}
	
	for (int i = 0; i < q + n; i++){
		if (query[i].type == PLUS) add((int)query[i].fg + 1, 1);
		else res[query[i].idx] = sum(2 * MAX_N) - sum((int)query[i].fg);
	}
	
	for (int i = 0; i < q; i++) printf("%d\n", res[i]);
	
	return (0);
}

Measured memory_bytes: 26768