akhauriyash/Code-Regression huggingface dataset:
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<class T>
vector<T> make_vec(size_t s, T val) { return vector<T>(s, val); }
template<class... Size>
auto make_vec(size_t s, Size... tail) {
	return vector<decltype(make_vec(tail...))>(s, make_vec(tail...));
}

template <class T>
ostream &operator<<(ostream &os, const set<T> &st) {
	for (const auto &e : st) os << e << " ";
	return os;
}

template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}

template <class T1, class T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
	for (const auto &e : mp) os << e << " ";
	return os;
}

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

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, Q;
	cin >> N >> Q;

	// t = x - D_i と x = X_j (S_j <= t <= T_j) が交わるD_iの範囲を計算しておく
	vector <pair<pair<int, int>, int>> stx(N);
	for (int i = 0; i < N; i++) {
		int s, t, x;
		cin >> s >> t >> x;
		stx[i] = { { max(0, s - x), t - x }, x };
	}
	sort(stx.begin(), stx.end());

	set<pair<int,int>> st;
	vector<int> ans(Q, INF);
	auto first = stx.begin();
	for (int i = 0; i < Q; i++) {

		int d;
		cin >> d;

		// add
		auto last = upper_bound(stx.begin(), stx.end(), make_pair(make_pair(d, INF), INF));
		for (auto itr = first; itr != last; itr++) st.emplace(itr->second, itr->first.second);
		first = last;

		//erase
		vector<pair<int, int>> memo;
		DMP(st);
		for (const auto &e : st) {
			if (d < e.second) {
				chmin(ans[i], e.first);
				break;
			}
			else memo.emplace_back(e);
		}
		DMP(memo);
		for (const auto e : memo) st.erase(e);
		DMP(st);
	}

	for (const auto &e : ans) cout << (e == INF ? - 1 : e) << "\n";

	return 0;
}

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

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;
int mop(int x, int y)
{
    int res = 1;
    while (y > 0)
        res *= x, --y;
    return res;
}
void solve(void)
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int res;
    if (a > b && a > c)
        res = a * mop(2, k) + b + c;
    else if (b > a && b > c)
        res = b * mop(2, k) + a + c;
    else
        res = c * mop(2, k) + a + b;
    cout << res << endl;
}
int main(void)
{
    solve();
}

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


int main()
{
	ll x,k,d;
	cin>>x>>k>>d;
	if(x == 0)
	{
		if(k%2 == 0)
		{
			cout<<0<<endl;
		}
		else
		{
			cout<<d<<endl;
		}
	}
	else
	{
		if(abs(x) <= d)
		{
			if(k%2 == 0)
			{
				cout<<abs(x)<<endl;
			}
			else
			{
				cout<<abs(abs(x) - d)<<endl;
			}
		}
		else
		{
			if(abs(x)/d >= k )
			{
				cout<<abs(x) - d*k<<endl;
			}
			else
			{
				int temp = (abs(x)/d);
				x = abs(x)%d;
				k = k-temp;
				if(k%2 == 0)
				{
				cout<<abs(x)<<endl;
				}
				else
				{
				cout<<abs(abs(x) - d)<<endl;
				}
				
			}
		}
	}
	
}

Measured memory_bytes: 3632
#include<stdio.h>
int main(void){
  int a[4][3][10]={};
  int n;
  int i,j,k;
  int data[4];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d %d %d",&data[0],&data[1],&data[2],&data[3]);
    a[data[0]-1][data[1]-1][data[2]-1] += data[3];
  }
  for(i=0;i<4;i++){
    for(j=0;j<3;j++){
      printf(" ");
      for(k=0;k<10;k++){
	printf("%d",a[i][j][k]);
	if(k!=9)printf(" ");
      }
      printf("\n");
    }
    if(i!=3){
      printf("####################\n");
    }
  }
  return(0);
}

Measured memory_bytes: 1796
iipt=lambda:int(input())
miipt=lambda:list(map(int,input().split(" ")))

s=" "+input()
S=len(s)
s+="_"*1123
t=" "+input()
T=len(t)
t+="_"*1123
dp=[[1123]*1123 for i in range(1123)]
# dp[s][t]
dp[0][0]=0
for i in range(S):
    for j in range(T):
        dp[i+1][j]= min(dp[i+1][j], dp[i][j]+1)
        dp[i][j+1]= min(dp[i][j+1], dp[i][j]+1)
        dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]+(s[i+1]!=t[j+1]))
print(dp[S-1][T-1])


Measured memory_bytes: 45172
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if(n==0)break;
			int m = sc.nextInt();
			sc.useDelimiter(",|\n");
			Edge[] es = new Edge[m];
			UnionFind uf = new UnionFind(n);
			for (int i = 0; i < m; i++) {
				int s = sc.nextInt();
				int e = sc.nextInt();
				int d = sc.nextInt();
				es[i] = new Edge(s, e, d);
			}
			Arrays.sort(es, new Comparator<Edge>() {
				public int compare(Edge a, Edge b) {
					return a.d - b.d;
				}
			});
			int sum=0;
			for(int i=0;i<m;i++){
				int a = es[i].s;
				int b = es[i].e;
				int d = es[i].d;
				if(!uf.same(a,b)){
					uf.unite(a,b);
					sum+=d/100-1;
				}
			}
			System.out.println(sum);
		}
	}
}

class Edge {
	public int s;
	public int e;
	public int d;

	Edge(int s, int e, int d) {
		this.s = s;
		this.e = e;
		this.d = d;
	}
}

class UnionFind {
	public int par[];
	public int rank[];

	UnionFind(int n) {
		par = new int[n];
		rank = new int[n];
		for (int i = 0; i < n; i++) {
			par[i] = i;
		}
	}

	public int find(int x) {
		if (par[x] == x)
			return x;
		else
			return par[x] = find(par[x]);
	}

	public void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)
			return;

		if (rank[x] < rank[y]) {
			par[x] = y;
		} else {
			par[y] = x;
			if (rank[x] == rank[y])
				rank[x]++;
		}
	}

	public boolean same(int x, int y) {
		return find(x) == find(y);
	}
}

Measured memory_bytes: 13000
#include<stdio.h>
#include<string.h>

int main(){
	char s[85];
	int i;
	memset(s,'0',sizeof(s));
	while(fgets(s,83,stdin)){

		while(1){
			for(i=0;i<81;i++){
				switch(s[i]){
				case '.':
				case ' ':
				case '0':
				case '\0':
				case 10:
				case 13:
					continue;
				}
				s[i]='a'+(s[i]-'a'+1)%26;
			}
			if((NULL!=strstr(s,"the")) || (NULL!=strstr(s,"this")) || (NULL!=strstr(s,"that"))){
				printf("%s",s);
				memset(s,'0',sizeof(s));
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
int main ()
{
	
	char abjad;
	scanf("%c",&abjad);
	
	
	
		if(abjad >= 'A' && abjad <= 'Z')
		{
		
			printf("A");
		}
	
		else if (abjad>='a' && abjad<='z')
		{
			printf("a");
				
		}
		return 0;
}




Measured memory_bytes: 1516
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,k;
  cin >> a >> b >> k;
  if(a+k-1>=b-k+1){
    for(int i=a;i<=b;i++){
      cout << i << endl;
    }
  }
  else{
    for(int i=a;i<a+k;i++){
      cout << i << endl;
    }
    for(int i=b-k+1;i<=b;i++){
      cout << i << endl;
    }
  }
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let s = i.read_line().as_bytes();
    let r = if solve(s) { "YES" } else { "NO" };

    writeln!(o, "{}", r).unwrap();
}
fn solve(s: &[u8]) -> bool {
    let key = b"keyence";
    let mut l0 = key.len();
    let mut l1 = 0;

    while l0 != 0 && !s.starts_with(&key[..l0]) {
        l0 -= 1;
    }
    while l1 != key.len() && !s.ends_with(&key[l1..]) {
        l1 += 1;
    }
    l0 + (key.len() - l1) >= key.len()
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }
    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }

}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<queue>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int h,a;
  cin >> h >> a;
  cout << (h+a-1)/a << endl;
}


Measured memory_bytes: 888
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <iomanip>
#include <string>
#include <queue>
#include <algorithm>
#include <cctype>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const double pi=acos(-1);

int a,v1,v2,ans;
char t;
vi l(10);

int main(){
	while(cin>>a){
		l[0]=a;
		for(int i=1;i<10;i++) cin>>t>>l[i];
		cin>>t>>v1>>t>>v2;
		int lon=0;
		for(int i=0;i<10;i++) lon+=l[i];
		double num=lon*((double)v1/(v1+v2));
		for(int i=0;i<10;i++){
			if(num<=l[i]){
				ans=i+1;
				break;
			}
			num-=l[i];
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int h,w,n;
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>h>>w>>n;
	if(h<w) swap(h,w);
	cout<<(n+h-1)/h<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

vector<int> divisor(int n) {
	vector<int> res;
	for (int i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			res.emplace_back(i);
			if (i != n / i) res.emplace_back(n / i);
		}
	}
	return res;
}

bool C(int mid, vector<int>& a, vector<int>&f,int k){
	rep(i,a.size()){
		double x = a[i] * f[i] - mid;
		if(x <= 0) continue;
		k -= ceil(x / f[i]);
		if(k < 0) return false;
	}
	return true;
}

signed main() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n), f(n);
	cin >> a >> f;
	sort(all(a));
	sort(all(f), greater<int>());

	
	int right = 1e18, left = 0;
	rep(i,100){
		int mid = (right + left) / 2;
		if(C(mid, a,f,k)) right = mid;
		else left = mid;
	}
	cout << right << endl;
}


Measured memory_bytes: 3328
module ArrayL = ArrayLabels
module ListL = ListLabels

let dbg = Printf.printf "[debug]%s"

let max_num = 100_000_000_000

let id = fun x -> x
let tuple2 x y = (x,y)
let tuple3 x y z = (x,y,z)
let succ x = x + 1
let pred x = x - 1

let (++) n m =
  let rec aux i =
    if i = m then [m]
    else i :: aux (i+1) in
  if n > m then [] else aux n

let (++^) n m = n ++ (m-1)

let scan fmt f = Scanf.sscanf (read_line ()) fmt f

let scan_list f =
  read_line ()
  |> Str.split (Str.regexp " +")
  |> ListL.map ~f:f

let scan_lines n fmt f =
  List.map (fun _ -> scan fmt f) (0++^n)

let scan_matrix n m e conv =
  let arr = Array.make_matrix n m e in
  Array.iteri (fun i line ->
      let s = Scanf.Scanning.from_string @@ read_line () in
      Array.iteri (fun j _ ->
          arr.(i).(j) <- Scanf.bscanf s " %s" conv;
        ) line) arr; arr

let between n x m = n <= x && x < m

let string_to_list s =
  List.map (String.get s) (0 ++^ String.length s)

module UnionFind = struct
  type elem = {root: int; size: int}

  let empty n = Array.init n (fun i -> {root=i; size=1})

  let root t n =
    let rec aux c =
      if c = t.(c).root then c
      else let p = aux t.(c).root in
        t.(c) <- {root=p; size=t.(c).size}; p in
    aux n

  let size t v =
    let v0 = root t v in
    t.(v0).size

  let unite t v0 v1 =
    let w0 = root t v0 in
    let w1 = root t v1 in
    t.(w1) <- {root=w0; size=(size t w0)+(size t w1)}

  let same t v0 v1 =
    root t v0 = root t v1
end

let (n, q) =scan "%d %d" tuple2
let uf = UnionFind.empty n

let () =
  ListL.iter (0 ++^ q) ~f:(fun _ ->
      let (q, a, b) = scan "%d %d %d" tuple3 in
      if q = 0 then
        UnionFind.unite uf a b
      else
      if UnionFind.same uf a b then
        Printf.printf "1\n"
      else Printf.printf "0\n")



Measured memory_bytes: 10348
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int A, B, C; cin >> A >> B >> C;
    int ma = max({A, B, C});

    int ans = 0;
    while(ma >= A+2) ans++, A += 2;
    while(ma >= B+2) ans++, B += 2;
    while(ma >= C+2) ans++, C += 2;

    // printf("A = %lld, B = %lld, C = %lld\n", A, B, C);
    if(A != B || B != C || C != A) {
        vector<int> v = {A, B, C};
        sort(v.rbegin(), v.rend());

        if(v[0] != v[1]) ans++;
        else ans += 2;
    }

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

Measured memory_bytes: 256
use whiteread::parse_line;

fn main() {
    let n: i32 = parse_line().unwrap();

    let s: Vec<String> = (0..n).map(|_| parse_line().unwrap()).collect();
    let mut ac = 0;
    let mut wa = 0;
    let mut tle = 0;
    let mut re = 0;

    for x in s {
        match x.as_str() {
            "AC" => ac += 1,
            "WA" => wa += 1,
            "TLE" => tle += 1,
            "RE" => re += 1,
            _ => (),
        }
    }

    println!("AC x {}", ac);
    println!("WA x {}", wa);
    println!("TLE x {}", tle);
    println!("RE x {}", re);
}


Measured memory_bytes: 7608
#include<bits/stdc++.h>
using namespace std;
#define RI register int
char mp[505][505];
int a[505][505],b[505][505],n,m;
int main()
{
	scanf("%d%d",&n,&m);
	for(RI i=1;i<=n;++i) scanf("%s",mp[i]+1);
	for(RI i=1;i<=n;++i)
		for(RI j=1;j<=m;++j) if(mp[i][j]=='#') a[i][j]=b[i][j]=1;
	for(RI j=1;j<=m;++j) a[1][j]=b[n][j]=1;
	for(RI i=2;i<n;++i)
		for(RI j=2;j<m;++j)
			if(j&1) a[i][j]=1;
			else b[i][j]=1;
	for(RI i=1;i<=n;++i) {
		for(RI j=1;j<=m;++j)
			putchar(a[i][j]?'#':'.');
		puts("");
	}
	puts("");
	for(RI i=1;i<=n;++i) {
		for(RI j=1;j<=m;++j)
			putchar(b[i][j]?'#':'.');
		puts("");
	}
	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int K;
    string S;
    cin>>K>>S;
    if(S.size()<=K){
        cout << S << endl;
        return 0;
    }
S=S.substr(0,K);
S=S+"...";
cout << S << endl;

    return 0;
}

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

int main(){
  string C1; string C2;
  getline(cin,C1);
  getline(cin,C2);

  if (C1[0] == C2[2] and C1[1] == C2[1] and C1[2] == C2[0]){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}



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

using namespace std;
typedef long long ll;

int main(){
    ll a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); ++i){
        if((i == a && s.at(i) != '-') || 
           (i != a && (s.at(i) < '0' || '9' < s.at(i)))){
                cout << "No" << endl;
                return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin>>n;
  double d;
  for(int i=1;i<=n;i++){
    double s;
    cin>>s;
    d+=1/s;
  }
  printf("%.8f\n",(double)1/d);
}


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

int main()
{
	int r, g, b;
	cin >> r >> g >> b;

	int box = 0;
	
	box += (r * 100);
	box += (g * 10);
	box += (b);

	if (box % 4 == 0)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}


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

int main(){
    string str,s;
    int cnt=0;
    cin >> s;
    for(int i=0,l=s.size(); i<l; i++){
        if(s[i]>='A'&&s[i]<='Z'){
            s[i]+=('a'-'A');
        }
    }
    while(cin >> str){
        if(str=="END_OF_TEXT")break;
        for(int i=0, l=str.size(); i<l; i++){
            if(str[i]>='A'&&str[i]<='Z'){
                str[i]+=('a'-'A');
            }
        }if(s==str) cnt++;
    }
    cout << cnt << endl;
}



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

int main(){
  string S; 
  cin >> S;
  
  int count = 0;
  int answer = 0;
  for(int i = 0; i < S.size(); i++){
    if(S.at(i) == 'A' || S.at(i) == 'C' || S.at(i) == 'T' || S.at(i) == 'G'){
      count+=1;
    }
    else{
      if(answer < count){
      	answer = count;
      }
      count = 0;
    }
  }
  if(answer < count){
    answer = count;
  }
  
  cout << answer << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;

int main()
{
    ciosup;
    int n;
    cin >> n;
    unordered_map<int, int> sosuu;
    FOR(i,1,n+1)
    {
        int now = i;
        for (int j = 2; j <= i; ++j)
        {
            while (now % j == 0){
                ++sosuu[j];
                now /= j;
            }
        }
    }
    ll twon=0, fourn=0, fourteenn=0, twentyfourn=0,seventyfourn=0;
    for (auto ite = sosuu.begin(); ite != sosuu.end(); ++ite)
    {
        if (ite->SE >= 2){
            twon++;
        }
        if (ite->SE >= 4){
            fourn++;
        }
        if (ite->SE >= 14){
            fourteenn++;
        }
        if (ite->SE >= 24)
        {
            twentyfourn++;
        }
        if (ite->SE >= 74){
            seventyfourn++;
        }
    }
    ll ans = 0, temp = 0;
    temp = (twon - 2) * (fourn * (fourn - 1) / 2);
    if (temp > 0)
        ans += temp;
    temp = twentyfourn * (twon - 1);
    if (temp > 0)
        ans += temp;
    temp = fourteenn * (fourn - 1);
    if (temp > 0)
        ans += temp;
    temp = seventyfourn;
    if (temp > 0)
        ans += temp;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

struct edge{int to,cost;};
vector<edge> G[100000];
vector<int> dist(100000,0);

int dfs(int cur, int prev){
    int maxi = 0;
    for(auto e:G[cur]){
        if(e.to==prev)continue;
        maxi = max(maxi,dfs(e.to,cur)+e.cost);
    }
    return dist[cur] = maxi;
}


vector<int> diameter(100000,0);

void dfs2(int cur, int prev, int d_par){
    vector<pii> v{pii(0,-1),pii(0,-1)};
    
    for(auto e:G[cur]){
        if(e.to==prev)v.pb(pii(d_par+e.cost,e.to));
        else v.pb(pii(dist[e.to]+e.cost,e.to));
    }
    sort(all(v),greater<pii>());
    diameter[cur] = v[0].first+v[1].first;
    
    for(auto e:G[cur]){
        if(e.to==prev)continue;
        else if(v[0].second==e.to)  dfs2(e.to,cur,v[1].first);
        else                        dfs2(e.to,cur,v[0].first);
    }
}

int main(){
    int n;
    cin>>n;
    rep(i,n-1){
        int s,t,w;
        cin>>s>>t>>w;
        G[s].pb(edge{t,w});
        G[t].pb(edge{s,w});
    }
    int root = n/2;
    dfs(root,-1);
    
    dfs2(root,-1,0);
    
    int ans = 0;
    rep(i,n)ans = max(ans,diameter[i]);
    
    cout<<ans<<endl;
}

Measured memory_bytes: 17576
#include<stdio.h>
int main(void)
{
	int i,j,z[5001],a,b[5001],c[5001],d[5001],e[5001],f[5001],x=0;
	scanf("%d",&a);
	x=(a*(a-1))/2;
	for(i=1;i<=x;i++){
		scanf("%d %d %d %d",&b[i],&c[i],&d[i],&e[i]);
	}
	for(i=1;i<=x+1;i++){
		f[i]=0;
		z[i]=1;
	}
	for(i=1;i<=x;i++){
		if(d[i]>e[i]){
			f[b[i]]+=3;
		}
		else if(d[i]<e[i]){
			f[c[i]]+=3;
		}
		else if(d[i]==e[i]){
			f[b[i]]++;
			f[c[i]]++;
		}
	}
	for(i=1;i<=a;i++){
		for(j=i+1;j<=a;j++){
			if(f[i]>f[j]){
				z[j]++;
			}
			if(f[i]<f[j]){
				z[i]++;
			}
		}
	}
	for(i=1;i<=a;i++){
		printf("%d\n",z[i]);
	}
	return 0;
}

Measured memory_bytes: 1144
#include <stdio.h>

int main(void)
{
	int n;
	int k;
	int i;
	int x, y, t;
	int c;
	
	scanf("%d", &n);
	scanf("%d", &k);
	
	for (i = 0; i < k; i++){
		scanf("%d%d", &x, &y);
		
		if (x > y){
			t = x;
			x = y;
			y = t;
		}
		
		if (x > (n + 1) / 2){
			x = n + 1 - x;
		}
		
		if (y > (n + 1) / 2){
			y = n + 1 - y;
		}

		if (y > x){
			c = ((x - 1) % 3) + 1;
		}
		else {
			c = ((y - 1) % 3) + 1;
		}
		
		printf("%d\n", c);
	}
	
	return (0);
}

Measured memory_bytes: 596
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
const int MAX_N = 100000;
int bit[MAX_N + 1];
int N;

int sum(int idx) {
    int s = 0;
    while (idx > 0) {
        s += bit[idx];
        idx -= idx & -idx;
    }
    return s;
}

void add(int idx, int val) {
    while (idx <= N) {
        bit[idx] += val;
        idx += idx & -idx;
    }
}

signed main() {
    int q;
    cin >> N >> q;
    for (int i = 0; i < q; i++) {
        int c, x, y;
        cin >> c >> x >> y;
        if (c == 0) {
            add(x, y);
        } else {
            cout << sum(y) - sum(x-1) << endl;
        }
    }
}


Measured memory_bytes: 3868
#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 for1(i, m, n) for (int i = m; i < n; i++)
#define ll long long
#define endl '\n'
using namespace std;

class DisjointSet {
public:
    // rankは木の高さ(この数)，pは親
    vector<int> rank, p;

    DisjointSet() {}
    DisjointSet(int size)
    {
        // ベクターrankとpの大きさをsizeとして，足りない要素は0で補う
        rank.resize(size, 0);
        p.resize(size, 0);
        // すべての値を初期化する
        for (int i = 0; i < size; i++) {
            MakeSet(i);
        }
    }

    void MakeSet(int x)
    {
        // x番目の要素の親を自分自身にする
        // 木の高さ(子の数)も0で初期化する
        p[x] = x;
        rank[x] = 0;
    }

    bool same(int x, int y)
    {
        return findSet(x) == findSet(y);
    }

    void unite(int x, int y)
    {
        link(findSet(x), findSet(y));
    }

    void link(int x, int y)
    {
        // 木の高さが高い方に木の高さが小さい方の親の親を設定する
        if (rank[x] > rank[y]) {
            // xの方が高いときはyの代表の親をxにする
            p[y] = x;
        } else {
            // それ以外はyをxの代表の親にする
            p[x] = y;
            if (rank[x] == rank[y]) {
                // 高さが同じ時は高さを一つ高くする
                rank[y]++;
            }
        }
    }

    int findSet(int x)
    {
        if (x != p[x]) { // xが代表でない(xの親がxでない)時
            p[x] = findSet(p[x]); // xの親の親が代表か調べる(これを再帰)
        }
        return p[x];  // xの属する集団の代表を返す
    }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a, b, q;
    int t;

    cin >> n >> q;
    DisjointSet ds = DisjointSet(n);

    for (int i = 0; i < q; i++) {
        cin >> t >> a >> b;
        if (t == 0) {
            ds.unite(a, b);
        } else if (t == 1) {
            if (ds.same(a, b)) {
                cout << 1 << endl;
            } else {
                cout << 0 << endl;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3312
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cstdlib>
using namespace std;

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

    int ans = 0;
    for (int i = a; i <= b; i++){
        int s = i % 10; //1の位
        int t = (i / 10) % 10;  //10
        int u = (i / 1000) % 10;  //1000
        int v = (i / 10000) % 10;  //10000
        if ((s == v) && (t == u)) ans++;
    }
    cout << ans << endl;
}

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

int main(){
    int n,ans=1; cin>>n;
    bool inc = false, dec = false;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin>>a[i];
    for(int i=0; i<n-1; i++) {
        if(a[i] < a[i+1]) inc = true;
        else if(a[i] > a[i+1]) dec = true;
        if(inc && dec) {
            ans++;
            inc = false;
            dec = false;
        }
    }
    printf("%d", ans);
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<iostream>
#define ll long long 
#define ull unsigned long long 
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair
#define all(v) v.begin(),v.end()
#define BP(n) __builtin_popcount(n)
#define bs(v,x) binary_search(all(v),x)
#define rep(i,n) for(i=0;i<n;i++)
#define rep1(j,n) for (j=1;j<n;j++)
#define Unique(v) vector<string>::iterator it; sort(all(v)); it= unique(all(v)); v.resize(distance(v.begin(),it))
#define PI 3.14159265358979323846
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL) 
using namespace std;
/*void input(vector<ll>& v,ll n){ ll i; ll io; rep(i,n) { cin>>io; v.pb(io);} }
void output(vector<int> v) { int i; rep(i,v.size()) cout<<v.at(i)<<" "; }
map<string,int>  frequency(vector<string> v){  int i; map<string,int> m; rep (i,v.size()) {  if (m.find(v[i])==m.end()) m.insert({v.at(i),1}); else m[v.at(i)]++; } return m; }
bool perfsq(ll n){ return (ceil(sqrt(n))==floor(sqrt(n))); }
bool ispower2(ll n) { if (n&(n-1)==0) return true; else return false; }
bool binary_pred(int a,int b){ return a==b; }*/

int main() {
	fastio;
	int l,r,d,c=0;
	cin>>l>>r>>d;
	for (int i=l;i<=r;i++) {
		if (i%d==0)
			c++;
	}
	cout<<c<<endl;
} 	

Measured memory_bytes: 3648
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 100000

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

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int parent[MAX_N+1];
ll d[MAX_N+1];

int root(int num){
  if(parent[num]==num)return num;
  int p = root(parent[num]);
  d[num] += d[parent[num]];
  return parent[num] = p;
}

bool same(int l, int r){
  return root(l)==root(r);
}

void unite(int l, int r, ll dis){
  dis+=d[l]-d[r];
  l = root(l);
  r = root(r);
  parent[r] = l;
  d[r] = dis;
}

int main(){
  int n, m;cin>>n>>m;
  rep(i, n){parent[i]=i;d[i]=0LL;}
  bool ans=true;
  rep(i, m){
    int l, r;ll dis;cin>>l>>r>>dis;
    l--;r--;
    if(same(l, r)){
      if(dis!=d[r]-d[l]){
        ans=false;
      }
    }else{
      unite(l, r, dis);
    }
  }
  cout<<(ans?"Yes":"No")<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 1408
import heapq
n,m = map(int,input().split())
A = list(map(int,input().split()))
L = []
for i in range(n):
  L.append([A[i],1])
for i in range(m):
  a,b = map(int,input().split())
  L.append([b,a])
L.sort()
L.reverse()
s = 0
t = 0
ans = 0
while s < n:
  if L[t][1]+s <= n:
    ans += L[t][1]*L[t][0]
    s += L[t][1]
    t += 1
  else:
    ans += L[t][0]*(n-s)
    s = n
    t += 1
print(ans)

Measured memory_bytes: 34740
a, b, h, m = map(int, input().split())
import math

th_a = math.pi / 6 * h + math.pi / 6 * m / 60
th_b = math.pi / 30 * m

l = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(th_a - th_b))

print(l)

Measured memory_bytes: 9496
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
int main() {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> a(n,0);
    for (int i = 1; i<n; i++) {
        a[i] = a[i-1];
        if (s[i] == 'C' && s[i - 1] == 'A') {
            a[i]++;
        }
    }
    rep(i, q) {
        int l,r;
        cin >> l >> r;
        cout << a[r - 1] - a[l-1] << endl;
    }
    return 0;
}


Measured memory_bytes: 3844
W, H, N = map(int, input().split())

xMin = 0
xMax = W
yMin = 0
yMax = H
for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        xMin = x if x > xMin else xMin
    if a == 2:
        xMax = x if x < xMax else xMax
    if a == 3:
        yMin = y if y > yMin else yMin
    if a == 4:
        yMax = y if y < yMax else yMax
ans = 0
if xMin >= xMax or yMin >= yMax:
    ans = 0
else:
    ans = (xMax - xMin) * (yMax - yMin)
print(ans)

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

int main(void){
   long long n, m;
   cin >> n >> m;
   
   long long ans = 1;
   
   for (long long i = 1; i *i <= m; i++){
       if (m % i != 0) continue;
       
       long long a = i;
       long long b = m / i;
       
       //cout << a << b << endl;
       
       if (a * n <= m) ans = max(ans,a);
       if (b * n <= m) ans = max(ans,b);
   }
   cout << ans << endl;
}

/*
考え方
Mの約数 dのうち、Nd≤Mを満たす最大のdを求めれば良い
*/

/*
corner case: n = 10^5, m = 10^9 (overflow)
time complexity: O(Nsqrt(m))
space complexity: O(1)
*/


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
from collections import deque

N,u,v=map(int, sys.stdin.readline().split())

al=[ [] for i in range(N+1) ]	#隣接リスト

for _ in range(N-1):
    a,b=map(int, sys.stdin.readline().split())
    al[a].append(b)
    al[b].append(a)

dist_t=[ 0 for _ in range(N+1) ] #高橋君のスタート地点からの各頂点までの距離
dist_a=[ 0 for _ in range(N+1) ] #青木君のスタート地点からの各頂点までの距離

#print "al :: ",al

#高橋君のスタート地点からの各頂点までの距離
Visit=[ 0 for _ in range(N+1) ]
q=deque()
q.append(u)
Visit[u]=1

while q:
    fro=q.popleft()
    for to in al[fro]:
        if Visit[to]==0:
            Visit[to]=1 #訪問済みに1をセット
            dist_t[to]=dist_t[fro]+1 #距離を計算
            q.append(to)

#print "dist_t :: ",dist_t

#青木君のスタート地点からの各頂点までの距離
Visit=[ 0 for _ in range(N+1) ]
q=deque()
q.append(v)
Visit[v]=1

while q:
    fro=q.popleft()
    for to in al[fro]:
        if Visit[to]==0:
            Visit[to]=1 #訪問済みに1をセット
            dist_a[to]=dist_a[fro]+1 #距離を計算
            q.append(to)

#print "dist_a :: ",dist_a

ans=0
max_a=0
for t,a in zip(dist_t,dist_a):
    if t<a:
        ans=max(ans,a)

print ans-1

Measured memory_bytes: 52764
K = int(input())
ans = -1
sup = 7
if 7 % K == 0:
    print(1)
    import sys
    sys.exit()
for i in range(2, K+2):
    sup = 10 * sup + 7
    sup %= K
    if sup == 0:
        ans = i
        break
print(ans)

Measured memory_bytes: 63348
#include <bits/stdc++.h>
#define int long long
using namespace std;

/*Starry Sky Tree*/
/*Range Add Min(Max) Query*/
/*区間加算、区間Min,区間Max*/

class RSUQ{
public: 
  
  //遅延用の型  
  struct T{
    bool type; //0 - empty   , 1 - update
    int value;
    T():type(0),value(0){}
    T(bool type,int value):type(type),value(value){}
  };

  //マージ可能な主データ型
  struct D{
    int value;
    D():value(0){} /*適切な値にする!!!!!!*/
    D(int value):value(value){}
    bool operator < (D a)const {return value < a.value;} //merge用
  };
  
  int n;
  vector<D> dat;
  vector<T> td;
  D returnD = D(0); // 範囲外の時に返す値。
  
  RSUQ(){n=-1;}
  RSUQ(int n_){
    n=1;
    while(n<n_)n*=2;
    td.resize(2*n-1,T());
    dat.resize(2*n-1,D());
  }
  
  D merge(D a,D b){return a.value + b.value;}
  
  void delay(int k,int len){
    if(td[k].type==0) return;
    int v = td[k].value;
    td[k].type = 0;
    td[k].value = 0;
    
    len /= 2;
    int l = k*2+1,r = k*2+2;
    dat[l].value = v * len; td[l].type = 1; td[l].value = v;
    dat[r].value = v * len; td[r].type = 1; td[r].value = v;
  }

  D update(int k,int x, int len){
    dat[k].value = x * len;
    td[k].type = 1;
    td[k].value = x;
    return dat[k];
  }
  
  //[a,b)の値をx変更　add(a,b,x)
  D query(int a,int b,int x,bool flg=true,int k=0,int l=0,int r=-1){
    if(r==-1) r=n, assert(a <= n && b <= n);
    if(r<=a||b<=l) return flg? dat[k]:returnD;
    if(a<=l&&r<=b) return flg? update(k, x, r - l):dat[k];
    
    delay(k, r - l);
    D vl = query(a,b,x,flg,k*2+1,l,(l+r)/2);
    D vr = query(a,b,x,flg,k*2+2,(l+r)/2,r);
    if(flg) dat[k] = merge(vl,vr);
    return merge(vl,vr);
  }
  
  //[a,b)の合計値を得る　find(a,b);
  int find(int a,int b){
    D res = query(a,b,0,false);
    return res.value;
  }
};


signed main(){
  int n,q;
  cin>>n>>q;
  
  RSUQ rsuq(n);
  while(q--){
    int cmd;
    cin>>cmd;
    if(cmd == 0){
      int s,t,x;
      cin>>s>>t>>x;
      rsuq.query(s,t+1,x);
    }
    if(cmd == 1){
      int s,t;
      cin>>s>>t;
      cout<<rsuq.find(s,t+1)<<endl;
    }
  }
  
  return 0;
}



Measured memory_bytes: 8928
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int mod=1e9+7;

int main() {
  int N;
  cin>>N;
  vector<int>P(N),Q(N),A(N);
  for(int i=0;i<N;i++){
    cin>>P[i];
  }
  for(int i=0;i<N;i++){
    cin>>Q[i];
  }
  for(int i=0;i<N;i++){
    A[i]=i+1;
  }
  int cnt=0;
  int a=0,b=0;

  do{
    if(A==P){a=cnt;}
    if(A==Q){b=cnt;}
    cnt++;
  }while(next_permutation(A.begin(),A.end()));

  cout<<abs(a-b)<<endl;
  return 0;  
}

Measured memory_bytes: 3636
import math
n = int(input())
x, y = [int(e) for e in input().split()], [int(e) for e in input().split()]
D1 = D2 = D3 = 0; D4 = []
for x1, y1 in zip(x, y):
    D1 += abs(x1-y1)
    D2 += abs(x1-y1)**2
    D3 += abs(x1-y1)**3
    D4.append(abs(x1-y1))
print('{0:.6f}'.format(D1))
print('{0:.6f}'.format(math.sqrt(D2)))
print('{0:.6f}'.format(math.pow(D3, (1/3))))
print('{0:.6f}'.format(max(D4)))



Measured memory_bytes: 5700
#include <cstdio>
const int MAXN = 1E5+5;
int array[MAXN]{ };
int visit[MAXN]{ };
int Ans=0, M, N, U, V;

int main()
{
	scanf(" %d%d", &N, &M);
	for(int i = 1; i <= N; ++i)
		array[i] = 1;
	visit[1]=true;
	for(int i = 0; i < M; ++i)
	{
		scanf(" %d%d", &U, &V);
		if(visit[U])
			visit[V] = true;
		++array[V];
		--array[U];
		if(!array[U])
			visit[U] = false;
	}
	for(int i = 1; i <= N; ++i)
		if(visit[i])
			++Ans;
	printf("%d\n", Ans);
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  string s;
  cin>>s;
  int a = 0;
  for(int i=0;i<s.size()-2;i++)
  {
    if(s.at(i)=='A'&&s.at(i+1)=='B'&&s.at(i+2)=='C')
    {
      a++;
    }
  }
  cout<<a<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  long long n;
  long long a_z[1000]={0};
  string str;
  cin>>n;
  cin>>str;
  
  for(int i=0;i<n;i++){
    a_z[str[i]-'a']++;
  }
  
  long long ans=1;
  for(int i=0;i<='z'-'a';i++){
    ans=ans*(a_z[i]+1)%1000000007;
  }
  cout<<ans-1<<endl;
  return(0);
}


Measured memory_bytes: 512
namespace ABC128.B
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using static System.Console;
    using static System.Math;
    public class Program
    {
        public static void Main(string[] args)
        {
            var n = ReadInputAsInt();
            var w = ReadInputsAsInt().ToList();
            WriteLine(Solve(n, w));
        }

        public static int Solve(int n, List<int> w)
        {
            return Enumerable.Range(1, n - 1).Select(k => Abs(w.Take(k).Sum() - w.Skip(k).Sum())).Min();
        }
        static IEnumerable<int> ReadInputsAsInt() => ReadLine().Split(' ').Select(x => int.Parse(x));
        static int ReadInputAsInt() => int.Parse(ReadLine());
    }
}


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

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

    int n;
    cin >> n;
    vector<int> h(n+1);
    rep(i,n) cin >> h[i+1];
    
    vector<int> dp(n+1, INF);
    dp[0] = dp[1] = 0;
    dp[2] = abs(h[1] - h[2]);
    
    for(int i=3; i<=n; i++){
        dp[i] = min(dp[i-1]+abs(h[i] - h[i-1]), dp[i-2]+abs(h[i] - h[i-2]));
    }
    
    cout << dp[n] << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;


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

  int x = 0;
  int max_x = 0;
  for(int i = 0; i < n; i++){
    if(s[i] == 'I'){
      x++;
    }
    else{
      x--;
    }
    if(x > max_x){
      max_x = x;
    }
  }
  cout << max_x << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>

using namespace std;

typedef long long ll;

int p[100002];

void init(int n){
    for (int i = 0; i < n; ++i) {
        p[i]=i;
    }
}


int find(int x){
	if(x != p[x]){
		p[x] = find(p[x]);
    }
    return p[x];
    }
     
void union_set(int x,int y){
	x = find(x);
	y = find(y);
	if(x==y) return;
	p[x]=y;
	return ;
}
int main(){
	int n;
	cin >> n;
	vector<pair<ll,int > > x,y;
	for(int i=0;i<n;i++){
		ll tmpx,tmpy;
		cin >> tmpx >> tmpy;
		x.push_back(make_pair(tmpx,i));
		y.push_back(make_pair(tmpy,i));
	}
	sort(x.begin(),x.end());
	sort(y.begin(),y.end());
	vector<pair<ll,pair<int,int> > > dx,dy;
	for(int i=0;i<n-1;i++){
		dx.push_back(make_pair(x[i+1].first-x[i].first,make_pair(x[i+1].second,x[i].second)));
		dy.push_back(make_pair(y[i+1].first-y[i].first,make_pair(y[i+1].second,y[i].second)));
	}
	sort(dx.begin(),dx.end());
	sort(dy.begin(),dy.end());
	init(n);
	int px=0,py=0;
	bool flag[100001]={};
	ll ans=0;
	while(1){
		if(px==n-1&&py==n-1)break;
		if(px<n-1&&py<n-1){
			if(dx[px].first<=dy[py].first){
				if(find(dx[px].second.first)!=find(dx[px].second.second)){
					union_set(dx[px].second.first,dx[px].second.second);
					ans += dx[px].first;
				}
				px +=1;
			}else{
				if(find(dy[py].second.first)!=find(dy[py].second.second)){
					union_set(dy[py].second.first,dy[py].second.second);
					ans += dy[py].first;
				}
				py +=1;
			}
		}else if(px==n-1){
			if(find(dy[py].second.first)!=find(dy[py].second.second)){
				union_set(dy[py].second.first,dy[py].second.second);
				ans += dy[py].first;
			}
			py +=1;
		}else{
			if(find(dx[px].second.first)!=find(dx[px].second.second)){
				union_set(dx[px].second.first,dx[px].second.second);
				ans += dx[px].first;
			}
			px +=1;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8804
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <cmath>

int main(void) {

	int n, count = 0;

	std::cin >> n;

	std::vector<int> v(n);

	for (size_t i = 0; i < n; i++) {
		std::cin >> v[i];
	}

	for (size_t i = 1; i < n; i++) {
		if (v[i] == v[i - 1]) {
			v[i] = -1;
			count++;
		}
	}

	std::cout << count << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<string>
#include<cassert>

using namespace std;

#define N 4
#define N2 16
#define LIMIT 100

static const int dx[4]={0, -1, 0, 1};
static const int dy[4]={1, 0, -1, 0};
static const char dir[4]={'r', 'u', 'l', 'd'};
int MDT[N2][N2];

struct Puzzle {int f[N2], space, MD; };

Puzzle state;
int limit;
int path[LIMIT];

int getAllMD(Puzzle pz){
  int sum=0;
  for(int i=0; i<N2; i++){
    if(pz.f[i]==N2)continue;
    sum += MDT[i][pz.f[i]-1];
  }
  return sum;
}

bool isSolved(){
  for(int i ; i<N2 ; i++)if(state.f[i]!=i+1)return false;
  return true;
}

bool dfs(int depth, int prev){
  if(state.MD==0)return true;
  if(depth+state.MD>limit)return false;
  int sx=state.space/N;
  int sy=state.space%N;
  Puzzle tmp;
  for(int r=0 ; r<4 ; r++){
    int tx=sx+dx[r];
    int ty=sy+dy[r];
    if(tx<0 || ty<0 || tx>=N || ty>=N)continue;
    if(max(prev, r)-min(prev, r)==2)continue;
    tmp=state;
    state.MD-=MDT[tx*N+ty][state.f[tx*N+ty]-1];
    state.MD+=MDT[sx*N+sy][state.f[tx*N+ty]-1];
    swap(state.f[tx*N+ty], state.f[sx*N+sy]);
    state.space=tx*N+ty;
    if(dfs(depth+1,r)){path[depth]=r; return true; }
    state=tmp;
  }
  return false;
}

string iterative_deppending(Puzzle in){
  in.MD=getAllMD(in);

  for(limit=in.MD ; limit<=LIMIT ; limit++){
    state=in;
    if(dfs(0, -100)){
      string ans="";
      for(int i=0 ; i<limit ; i++)ans+=dir[path[i]];
      return ans;
    }
  }
 return "unsolvabe";
}

int main(){
 for(int i=0 ; i<N2 ; i++)
   for(int j=0 ; j<N2 ; j++)
     MDT[i][j]=abs(i/N-j/N)+abs(i%N-j%N);
 Puzzle in;

 for(int i=0 ; i<N2 ; i++){
   cin>>in.f[i];
   if(in.f[i]==0){
     in.f[i]=N2;
     in.space=i;
   }
 }
 string ans=iterative_deppending(in);
 cout << ans.size() << endl;

 return 0;
}



Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m;
ll f(ll cur){
    if(cur < 0) return 0;
    if(cur%4 == 1) return 1;
    if(cur%4 == 2) return cur+1;
    if(cur%4 == 3) return 0;
    return cur;
}
int main(){
    scanf("%lld %lld",&n,&m);
    printf("%lld",f(m) ^ f(n-1));
}


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


int main(){
  int H,N;
  cin >> H >> N;
  vector<int> A(N);
  rep(i,N){
    cin >> A[i];
  }
  int sum = 0;
  rep(i,N){
    sum += A[i];
  }
  if(sum >= H) cout << "Yes" << endl;
  else cout << "No" << endl;

}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    string N; cin >> N;
    if(N[1] == N[2] && (N[0] == N[1] || N[3] == N[2])) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

    solve();

    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<queue>
#include<stack>
#include<utility>
#include<vector>
using namespace std;

typedef long long lint;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0 ; i < n ; i++){
        cin >> a[i];
    }
    int ans = 0;
    for(int i = 0 ; i < n ; i++){
        int cnt = 0;
        while(a[i] % 2 == 0){
            a[i] /= 2;
            cnt++;
        }
        ans += cnt;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n;
    cin>>n;
    ll min=n;
    for(ll i=1;i<=(ll)sqrt(n);i++){
        if(n%i==0){
            min=n/i;
        }
    }
    cout<<min+n/min-2<<endl;
    return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn

object Main {
  def main(args: Array[String]): Unit = {
    val inputs = Iterator.continually(StdIn.readLine()).takeWhile(_ != null)
    for{
      in <- inputs
      val Array(h, w, _*) = in.split(" ").map(_.toInt)
      }{
        if(h != 0 && w != 0){
          for{i <- 0 until h; j <- 0 until w}{
            print("#")
            if(j == w-1)println()
          }
          println()
        }
      }
  }
}

Measured memory_bytes: 54792
#!/usr/bin/python3
import itertools
import math
from functools import reduce


def gcd(a, b, c):
    return math.gcd(math.gcd(a, b), c)

K = int(input()) + 1
sum = 0

List = [ i for i in range(1, K)]

for v in itertools.combinations_with_replacement(List, 3):
    g = gcd(v[0],v[1],v[2])
    if v[0] == v[1] and v[1] == v[2]:
        sum += g
    elif v[0] == v[1] or v[0] == v[2] or v[1] == v[2]:
        sum += g * 3
    else:
        sum += g * 6

print(sum)

Measured memory_bytes: 9588