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

int main() {
  int N,M;
  cin>>N>>M;
  vector<vector<int>> G(N);
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    a--,b--;
    G[a].push_back(b);
  }
  int S,T;
  cin>>S>>T;
  S--,T--;
  vector<int> seen(N,-1);
  vector<int> ichi(N,-1);
  vector<int> ni(N,-1);
  queue<int> q;
  q.push(S);
  seen[S]=0;
  while(!q.empty()){
    int a=q.front();
    q.pop();
    queue<int> I;
    queue<int> NI;
    for(int x:G[a]){
      if(ichi[x]==-1){
        ichi[x]=0;
        I.push(x);
      }
    }
    while(!I.empty()){
      int b=I.front();
      I.pop();
      for(int x:G[b]){
        if(ni[x]==-1){
          ni[x]=0;
          NI.push(x);
        }
      }
    }
    while(!NI.empty()){
      int b=NI.front();
      NI.pop();
      for(int x:G[b]){
        if(seen[x]==-1){
          seen[x]=seen[a]+1;
          q.push(x);
        }
      }
    }
  }
  cout<<seen[T]<<endl;
}




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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acos(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

//#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int n; cin >> n;
	vector<P> a(n);
	rep(i, n) cin >> a[i].first;
	rep(i, n) a[i].second = i;

	sort(all(a), [](P &a, P &b){ return a.first > b.first; });

	#ifdef DEBUG
	for(auto out : a)
	{
		cerr << out.first << ' ' << out.second << endl;
	}
	#endif

	rep(i, n)
	{
		if(a[0].second == i)
		{
			cout << a[1].first << endl;
		}
		else
			cout << a[0].first << endl;
	}
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> piipi;
typedef pair<pii, pii> piipii;

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back

int main(){
    ll x;
    scanf("%lld", &x);
    ll ans = x/11*2;
    x %= 11;
    if(1 <= x && x <= 6) ans++;
    else if(x != 0) ans += 2;

    printf("%lld\n", ans);
}

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

const long long N=1000010;
long long a[100001],b[100001];

int main(){
	
ios_base::sync_with_stdio(false);

long long n,i,ans=0,k;

cin>>n;

for(i=0;i<n;i++)
	cin>>a[i];

for(i=0;i<n;i++){

k=a[i];

if((i>0)&&(i<(n-1))){

b[0]=a[i-1];
b[1]=a[i];
b[2]=a[i+1];

sort(b,b+3);

if(b[1]==k)
ans++;}}

cout<<ans<<endl;

return 0;}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  for(int i=0; i<n; i++) {
    cin >> a.at(i);
    b.at(i) = a.at(i);
  }
  sort(b.begin(), b.end());
  int max = b.at(n-1);
  for(int i=0; i<n; i++) {
    if(a.at(i) != max) {
      cout << max << endl;
    } else {
      cout << b.at(n-2) << endl;
    }
  }
}

Measured memory_bytes: 3200
def create_koho(X):
    koho = [1]
    koho_sum = 1
    i = 1
    while koho_sum < X:
        i += 1
        koho.append(i)
        koho_sum += i

    return koho


X = int(input())
koho = create_koho(X)
nokori = X
ans = 0
for i in reversed(koho):
    if nokori >= i:
        nokori -= i
        ans += 1

print(len(koho))


Measured memory_bytes: 4884
#include <algorithm>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  set<string> st;
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    st.insert(S);
  }
  cout << (st.size() == 3 ? "Three" : "Four") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> point;
typedef pair<point,point> line;
const double EPS=1e-8;

//テ・ツ??ァツゥツ?
double dot(point a,point b){
  return real(conj(a)*b);
}

//テ・ツ、ツ姪ァツゥツ?
double cross(point a,point b){
  return imag(conj(a)*b);
}

int ccw(point a,point b,point c){
  point d=b-a;
  point e=c-a;
  if(cross(d,e)>0)return 1;//テ・ツキツヲテ・ツ?エ
  if(cross(d,e)<0)return -1;//テ・ツ渉ウテ・ツ?エ
  if(dot(d,e)<0)return 2;//onlineback
  if(abs(d)<abs(e))return -2;//onlinefront
  return 0;//onsegment
}

point crosspoint_ll(line l1, line l2){
  double a=cross(l1.second-l1.first,l2.second-l2.first);
  double b=cross(l1.second-l1.first,l1.second-l2.first);
  if(fabs(a)<EPS&&fabs(b)<EPS)return l2.first;
  else if(fabs(a)>=EPS) return l2.first+b/a*(l2.second-l2.first);
}

vector<point> Convex_Cut(vector<point> polygon,line l){
  vector<point> res;
  for(int i=0;i<polygon.size();i++){
    point a=polygon[i],b=polygon[(i+1)%polygon.size()];
    if(ccw(l.first,l.second,a)!=-1)res.push_back(a);
    if(ccw(l.first,l.second,a)*ccw(l.first,l.second,b)<0)
      res.push_back(crosspoint_ll(line(a,b),l));
  }
  return res;
}

double get_area(vector<point> polygon){
  double res=0;
  for(int i=0;i<polygon.size();i++)
    res+=cross(polygon[i],polygon[(i+1)%polygon.size()]);
  return res/2;
}

int n,d,V,x,y;

double bynary_search(vector<point> polygon,point a,point b){
  b-=a;
  for(int i=0;i<n;i++)
    polygon[i]-=a,polygon[i]=polygon[i]*conj(b)/abs(b);
  double l=0,r=(1e9),m;
  while(l+EPS<r){
    m=(l+r)/2;
    point A=point(abs(b),m),B=point(0,m);
    if(get_area(Convex_Cut(polygon,line(A,B)))*d<V)l=m+EPS;
    else r=m;
  }
  return l;
}

int main(){
  vector<point> polygon;
  while(1){
    double ans=0;
    cin>>n>>d>>V;
    if(!n&&!d&&!V)break;
    for(int i=0;i<n;i++)
      cin>>x>>y,polygon.push_back(point(x,y));
    for(int i=0;i<n;i++){
      point a=polygon[i],b=polygon[(i+1)%n];
      ans=max(ans,bynary_search(polygon,a,b));
    }
    printf("%.9f\n",ans);
    polygon.clear();
  }
  return 0;
}

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

int main()
{
	int al,bl;
	char a[11],b[11],c[11];
	scanf("%s %s %s",a,b,c);

	al = strlen(a);
	bl = strlen(b);

	if (a[al-1] == b[0] && b[bl-1] == c[0]) printf("YES\n");
	else printf("NO\n");

	return 0;
}


Measured memory_bytes: 128
def solve(yy,mm):
    if 1<=yy<=12:
        if 1 <= mm <=12:
            return 'AMBIGUOUS'
        else:
            return 'MMYY'
    else:
        if 1<= mm <= 12:
            return 'YYMM'
        else:
            return "NA"


s = input()
yy = int(s[:2])
mm = int(s[2:])
print(solve(yy,mm))

Measured memory_bytes: 9128
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */


template<class Type>
Type solve(Type res = Type()){
    ll N,K; cin >> N >> K;
    vector<int> P(N);
    vector<ll> C(N);
    for(auto& in:P){ cin >> in; in--; }
    for(auto& in:C) cin >> in;

    res = numeric_limits<ll>::min();
    
    
    res = numeric_limits<ll>::min();
    function<void(int,ll,ll,int,vector<ll>&)> dfs = [&](int n,ll dep,ll sum,int s,vector<ll>& score){
        score.emplace_back(sum);
        if(dep >= K) return;
        if(n == s && dep != 0){
            
            ll cnt = (K+dep-1)/dep - 1;
            
            ll T = sum*cnt;
            ll leaf = K - dep*cnt;
            
            
            int x = n;
            res = max(res,T);
            for(int i = 0; i < leaf; i++){
                x = P[x];
                T += C[x];
                
                res = max(res,T);
            }
            return;
        }

        int next = P[n];
        sum += C[next];

        res = max(res,sum);
        dfs(next,dep+1,sum,s,score);
    };

    res = numeric_limits<ll>::min();
    for(int i = 0; i < N;i++){
        vector<ll> score;
        dfs(i,0,0,i,score);
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 4240
S = str(input())
K = int(input())
N = len(S)

count1 = 0
x = "A"
con = 1
#仮に1回でもダメなやつ
for i in range(N):
  if x == S[i]:
    con += 1 
  else:
    x = S[i]
    if con != 1:
      count1 += con //2
    con = 1
  #print(count1, i)
if con != 1:
  count1 += con //2
  
if con == N:
  print(N * K // 2)
  quit()
#print(count1)
count2 = 0
count0 = 0
countf = 0
if S[0] == S[-1]:
  p = 0
  q = 0
  count0 = 1
  countf = 1
  i = 0
  j = -1
  while p == 0:
    if S[i] == S[i + 1]:
      count0 += 1
      i += 1
    else:
      p = 1
  while q == 0:
    if S[j] == S[j - 1]:
      countf += 1
      j -= 1
    else:
      q = 1

if (count0 % 2 == 1) and (countf % 2 == 1):
  count2 = 1
print(count1 * K + count2 * (K - 1))
    

Measured memory_bytes: 38384
# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()

def resolve():
    import sys
    input = sys.stdin.readline

    o = input().rstrip()
    e = input().rstrip()

    ans = ""
    for i in range(len(o)):
        ans += o[i]
        if i < len(e):
            ans += e[i]

    print(ans)

if __name__ == "__main__":
    resolve()


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


int main() {
    int n; cin >> n;
    vector<ll> a(n+1),b(n);
    rep(i,n+1){
        cin >> a.at(i);
    }    
    rep(i,n){
        cin >> b.at(i);
    }
    ll sum=0;

    rep(i,n){
        ll now=min(a.at(i),b.at(i));
        sum+=now;
        b.at(i)-=now;
        if(b.at(i)>0){
            now=min(b.at(i),a.at(i+1));
            a.at(i+1)-=now;
            sum+=now;
        }
    }

    cout << sum << endl;
}

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

int main() {
    int n, c, x;
    vector<int> v;
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> c;
        if(c == 0) {
            cin >> x;
            v.push_back(x);
        } else if(c == 1) {
            cin >> x;
            cout << v[x] << '\n';
        } else {
            v.pop_back();
        }
    }
}



Measured memory_bytes: 3928
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,l,r) for(int i=l;i<r;i++)
const int inf=2e9+10;
const int INF=9e18+10;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

const ll MOD=1e9+7;

int main(){
    int n,q;cin>>n>>q;
    vector<int> a(n),b(n);
    rep(i,n)a[i]=b[i]=n-1;
    int h,w;
    h=w=n-1;
    ll ans=ll(n-2)*(n-2);
    while(q--){
        int x,y;
        cin>>x>>y;
        x--;y--;
        if(x==0){
            if(w>y){
                repl(i,y,w)a[i]=h;
                w=y;
            }
            ans-=a[y]-1;
        }
        else{
            if(y<h){
                repl(i,y,h)b[i]=w;
                h=y;
            }
            ans-=b[y]-1;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 4840
#[allow(dead_code)]
fn main() {
    let (n, p) = i::u2();
    let a = i::uv(n);
    let odd = a.iter().filter(|&i| i % 2 == 1).count();
    let even = a.iter().filter(|&i| i % 2 == 0).count();

    let mut odd_comb = Vec::new();
    odd_comb.push(1);
    for i in 1..odd + 1 {
        let k = odd_comb[i - 1] * (odd - i + 1) / i;
        odd_comb.push(k);
    }
    //  dbg!(&odd_comb, &odd);

    if p == 1 {
        if odd < 1 {
            println!("{}", 0);
            return;
        }
        let mut odd_p = 0;
        let mut i = 1;
        while i <= odd {
            odd_p += odd_comb[i];
            i += 2;
        }
        let mut even_p = (0..even).fold(1usize, |u, _| u * 2);
        println!("{}", odd_p * even_p);
        //  dbg!(odd_p, even_p);
        return;
    }

    let mut odd_p = 0;
    let mut i = 0;
    while i <= odd {
        odd_p += odd_comb[i];
        i += 2;
    }
    let mut even_p = (0..even).fold(1usize, |u, _| u * 2);

    println!("{}", odd_p * even_p);
    // dbg!(odd_p, even_p);
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


Measured memory_bytes: 4352
#include <iostream>

namespace myspace{
	
	class vector{
	public:
		void push_back(int);
		int size();
		int &operator[](int);
		vector();
		vector(const vector&);
		~vector();
	private:
		int s;
		int* box;
	};
	
	vector::vector()
	{
		box = NULL;
		s = 0;
	}
	
	vector::vector(const vector &X)
	{
		s = X.s;
		box = new int[X.s];
		for(int i=0; i<X.s; i++)box[i] = X.box[i];
	}
	
	vector::~vector()
	{
		if(box)delete[] box;
	}
	
	int &vector::operator[](int i)
	{
		return box[i];
	}
	
	int vector::size()
	{
		return s;
	}
	
	void vector::push_back(int input)
	{
		int* box2 = box;
		box = new int[s+1];
		for(int i=0; i<s; i++)box[i] = box2[i];
			
		box[s] = input;
		s++;
		delete[] box2;
	}
}//??????????????????myspac

using namespace myspace;
using namespace std;

void Output(vector A)
{
    int i;
    for(i=0;i<A.size()-1;i++){
        cout << A[i] << " ";
    }
    cout << A[i] << endl;
}
 
void InsertionSort(vector A,int n)
{
    for(int i=0;i<n;i++)
    {
        int v = A[i];
        int j = i - 1;
        while(j>=0 && A[j]>v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        Output(A);
    }
}
 
int main()
{   
    int n;
    cin >> n;
     
    vector A;
	for(int i=0;i<n;i++){
		int a;
		cin >> a;
		A.push_back(a);
	}
    InsertionSort(A, n);
     
    return 0;
}

Measured memory_bytes: 1196
#include <stdio.h>
#include <iostream>
using namespace std;
void fun(int x, int y){
    int z;
    z = x*y;
    if (z%2 == 0){
        cout<<"Even"<<endl;
    }
    else
        cout<<"Odd"<<endl;
}

int main()

{
    int a,b;
    cin>>a>>b;
    fun(a,b);
    return 0;
}


Measured memory_bytes: 256
//Partition(Quick Sort)

#include<stdio.h>
#include<stdlib.h>

void swap(int*,int*);

int main(void){
  int n,pivot;
  int *A;
  int i,j;

  scanf("%d",&n);

  A=(int*)malloc(n*sizeof(int));

  for(i=0;i<n;i++) scanf("%d",&A[i]);

  pivot=A[n-1];
  
  j=0;
  for(i=0;i<n-1;i++){
    if(A[i]<=pivot){
      swap(&A[j],&A[i]);
      j++;
    }
  }
  swap(&A[j],&A[n-1]);

  if(j==0) printf("[%d]",A[0]);
  else printf("%d",A[0]);

  for(i=1;i<n;i++){
    if(i==j) printf(" [%d]",A[i]);
    else printf(" %d",A[i]);
  }
  printf("\n");

  free(A);

  return 0;
}


void swap(int *a,int *b){
  int work;

  work=*a;
  *a=*b;
  *b=work;
}

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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

class UnionFind {
    public:
    int n;
    vector<int> par, rank;

    UnionFind(int n) {
        rep(n) {
            par.push_back(i);
            rank.push_back(0);
        }
    }

    int find(int x) {
        return ((par[x] == x) ? x : par[x] = find(par[x]));
    }

    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]++;
        }
        return;
    }

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

int main() {
    int n, k, l, a, b;
    cin >> n >> k >> l;
    UnionFind uf_train = UnionFind(n), uf_road = UnionFind(n);

    rep(k){
        cin >> a >> b;
        a--; b--;
        uf_road.unite(a, b);
    }
    rep(l){
        cin >> a >> b;
        a--; b--;
        uf_train.unite(a, b);
    }

    map<Pii, int> mp;
    rep(n){
        mp[Pii(uf_train.find(i), uf_road.find(i))]++;
    }
    rep(n) cout << mp[Pii(uf_train.find(i), uf_road.find(i))] <<" ";
    cout << endl;
}



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

int main() {
  int N;
  cin >> N;
  vector<double> a(N);
  for (int i = 0;i < N; i++) {
    cin >> a.at(i);
  }
  double k;
  double ans = 0.0;
  for (double x: a) {
    k = 1/x;
    ans += k;
  }
  
  cout << fixed << setprecision(10);
  
  cout << 1/ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#define mod 1000000007
using namespace std;
typedef long long ll;
bool chmax(ll &a,ll b){
    if(a>b)return 0;
    a=b; return 1;
}
bool chmin(ll &a,ll b){
    if(a<b)return 0;
    a=b; return 1;
}

#define N 100010
ll n,m,k;
ll col[N];
struct edge{
    ll a,b,cost;
    bool operator<(const edge&key)const{
	return this->cost<key.cost;
    }
};
vector<edge> v;

namespace uf{
    ll p[2*N];
    bool t[2*N];
    ll rank;
    ll par(ll x){
	return p[x]=(x==p[x]?x:par(p[x]));
    }
    ll unite(ll a,ll b,ll cost){
	a=par(a),b=par(b);
	if(a==b){
	    return 0;
	}
	p[a]=b;
	rank--;
	return cost;
    }
}
int main(){
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++){
	cin>>col[i];
    }
    for(int i=0;i<m;i++){
	edge e;
	cin>>e.a>>e.b>>e.cost;
	v.push_back(e);
    }
    sort(v.begin(),v.end());
    uf::rank=k-1;
    for(int i=0;i<2*N;i++){
	uf::p[i]=i;
    }
    ll ans=0;
    for(auto e:v){
	if(uf::rank<=0){
	    cout<<ans<<endl;
	    return 0;
	}
	if(col[e.a]>0)e.a=col[e.a]+N;
	if(col[e.b]>0)e.b=col[e.b]+N;
	ans+=uf::unite(e.a,e.b,e.cost);
    }
    if(uf::rank<=0)cout<<ans<<endl;
    else cout<<-1<<endl;
}



Measured memory_bytes: 5492
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

int n;
ll A, B;

int main()
{
    ll ans = 0;
    scanf("%d%lld%lld", &n, &A, &B);
    int x;
    scanf("%d", &x);
    for (int i = 1; i < n; i++)
    {
        int y;
        scanf("%d", &y);
        ans += min(B, A * (y - x));
        x = y;
    }
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 256
i,j,k,n,x,t;
main(){
    for(;scanf("%d%d",&n,&x),n+x;printf("%d\n",t))
        for(i=1,t=0;i<=n;i++)
            for(j=i+1;k=x-i-j,j<=n;j++)
                if(j<k&&k<=n)t++;
}

Measured memory_bytes: 1848
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define Would
#define you
#define please

int main() {


	int A, B, K;
	cin >> A >> B >> K;

	rep(i, K) if (A + i <= (A + B) / 2) co(A + i);
	rep(i, K) if (B + i - K + 1 > (A + B) / 2) co(B + i - K + 1);

	Would you please return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <math.h>
#include <set>
#include <iomanip>
#include <time.h>
#include <list>
#include <stdio.h>
#include <queue>
#include <map>
#include <algorithm>
#include <assert.h>
#include <memory.h>

#define mk make_pair
#define sc second
#define fr first
#define pb emplace_back
#define all(s) s.begin(), s.end()
#define sz(s) ( (int)s.size() )

using namespace std;

const int N = 1e5 + 5;

int n, ar[N], k;

map <int, int> mp;

inline void finish_false()
{
    puts("IMPOSSIBLE");
    exit(0);
}
inline void finish_true()
{
    puts("POSSIBLE");
    exit(0);
}

main ()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &ar[i]);
        mp[ ar[i] ] = 1;
    }

    sort(ar + 1, ar + n + 1);

    if (k > ar[n])
        finish_false();

    for (int i = 0; i <= n; i++)
    {
        if (mp.count( ar[i] + k ) )
            finish_true();
    }
    for (int i = 1; i <= n; i++)
    {
        if ( mp.count(ar[i] - 1) || mp.count(ar[i] + 1) )
            finish_true();
    }
    finish_false();
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 300010
using namespace std;
ll h,w,m,cnt[N],cnt2[N],ans=0;
bool vis1[N],vis2[N];
vector<ll> mxr,mxc;
vector<pair<ll,ll> > vt;
int main(){
	ll i,x,y,mx,num=0;
	scanf("%lld%lld%lld",&h,&w,&m);
	for(i=0;i<m;i++)
	{
		scanf("%lld%lld",&x,&y);
		x--;
		y--;
		vt.push_back(make_pair(x,y));
		cnt[x]++;
		cnt2[y]++;
	}
	mx=0;
	for(i=0;i<h;i++)
	{
		if(mx<cnt[i])
		{
			mx=cnt[i];
			mxr.clear();
			mxr.push_back(i);
		}
		else if(mx==cnt[i])
		{
			mxr.push_back(i);
		}
	}
	ans+=mx;
	mx=0;
	for(i=0;i<w;i++)
	{
		if(mx<cnt2[i])
		{
			mx=cnt2[i];
			mxc.clear();
			mxc.push_back(i);
		}
		else if(mx==cnt2[i])
		{
			mxc.push_back(i);
		}
	}
	ans+=mx;
	for(i=0;i<mxr.size();i++)
	{
		vis1[mxr[i]]=true;
	}
	for(i=0;i<mxc.size();i++)
	{
		vis2[mxc[i]]=true;
	}
	for(i=0;i<m;i++)
	{
		if(vis1[vt[i].F]&&vis2[vt[i].S])
		{
			num++;
		}
	}
	if(num==(mxr.size()*mxc.size()))
	{
		ans--;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 22000
#include<iostream>
#include<cstdio>
#define MAX 500000+5
using namespace std;
int heap[MAX];
int num;
void maxheapify(int i){
	int largest;
	int left=i*2;int right=i*2+1;
	if(left<=num&&heap[left]>heap[i]){
		largest=left;
	}else{
		largest=i;
	}
	if(right<=num&&heap[largest]<heap[right]){
		largest=right;
	}
	if(largest!=i){
		swap(heap[largest],heap[i]);
		maxheapify(largest);
	}
	return;
}
int main(){
	scanf("%d",&num);
	for(int i=1;i<=num;i++){
		scanf("%d",&heap[i]);
	}
	for(int i=num/2;i>=1;i--){
		maxheapify(i);
	}
	for(int i=1;i<=num;i++){
		cout<<" "<<heap[i];
	}
	cout<<endl;
}


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

int main(){
  int N,K;
  cin >> N >> K;
  vector<double> v(N+1);
  v.at(0)=0;
  for(int i=1;i<=N;i++){
    int p;
    cin >> p;
    v.at(i)=v.at(i-1)+(1+p)/2.0;
  }
  double ma=0;
  for(int i=K;i<=N;i++){
    double e=v.at(i)-v.at(i-K);
    if(ma<e){
      ma=e;
    }
  }
  cout << fixed << setprecision(12) << ma << endl;
  return 0;
}


Measured memory_bytes: 1792
import sys
mod = pow(10, 9) + 7
sys.setrecursionlimit(pow(10, 8))

def power(x, y):
    if   y == 0: return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y//2)**2 % mod
    else: return power(x, (y-1)//2)**2 * x % mod
    
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def div(a, b):
    return mul(a, power(b, mod-2))
def div2(a, b):
    return mul(a, modinv(b))

def modinv(a):
    b, u, v = mod, 1, 0
    while b:
        t = a//b
        a, u = a-t*b, u-t*v
        a, b, u, v = b, a, v, u
    u %= mod
    return u

def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

NNN = (10**6)
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, NNN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
H, W, A, B = map(int, input().split())

r = 0
for i in range(H-A):
#    (0, 0) -> (i, B-1)
#    (i, B) -> (H-1, W-1)
    r = (r + mul(cmb(i+B-1, i), cmb(H-1-i+W-1-B, H-1-i)))%mod
print(r)



Measured memory_bytes: 127432
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

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

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

    vector<int> P(N+1);
    for(int i = 1;i <= N;i++) {
        int p;
        cin>>p;
        P[i] = p;
    }

    int ans = 0;
    for(int d = 2;d < N;d++) {
        vector<int> T;
        T.push_back(P[d-1]);
        T.push_back(P[d]);
        T.push_back(P[d+1]);
        sort(T.begin(),T.end());
        if(P[d] == T[1])
            ans++;
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
----
-- https://www.youtube.com/watch?v=nYFd7VHKyWQ
-- https://github.com/mission-peace/interview/blob/master/python/recursion/stringpermutation.py

-- For simplicity, this algorithm does not allow duplicate elements.

local function permute(seq)
    local inuse = {}
    local result = {}
    local function rec(level)
        if level > #seq then
            --print(table.concat(result, ""))
            coroutine.yield(result)
            return
        end
        for i=1,#seq do
            if not inuse[i] then
                result[level] = seq[i]
                inuse[i] = true
                rec(level + 1)
                inuse[i] = false
            end
        end
    end
    local function start()
        rec(1)
    end
    return coroutine.wrap(start)
end
----
-----
local N = read.n()
local A = {}
for i=1,N do
    A[i] = i
end
local function test()
    for k in permute(A) do
        print(table.concat(k,""))
    end
end
--test()
local P, Q = {}, {}
for i=1,N do
    P[i] = read.n()
end
for i=1,N do
    Q[i] = read.n()
end

local function sameseq(a, b)
    return table.concat(a, " ") == table.concat(b, " ")
end

local a, b
local i = 1
for k in permute(A) do
    if sameseq(k, P) then
        a = i
    end
    if sameseq(k, Q) then
        b = i
    end
    i = i + 1
end
print(math.abs(a-b))

Measured memory_bytes: 888
import java.util.*;

class Main {
    final Scanner sc = new Scanner(System.in);

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

    private void run() {
        int x = sc.nextInt();
        for (int i = x;; i++) {
            if (isPrime(i)) {
                System.out.println(i);
                break;
            }
        }

    }

    private boolean isPrime(int a) {
        for (int i = 2; i*i < a; i++) {
            if (a % i == 0) return false;
        }
        return true;
    }
}


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

#define endl '\n'
#define ll  long long
#define modd(a,b) ((a+2*b)%b)
#define ioso ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define debug(a) cout << #a << ": " << (a) << "\n"
#define ffe freopen("input.txt","r",stdin), freopen("output.txt","w",stdout)
ll calc(ll f) {
	ll ans = 1;
	for(int i=0;i<5;i++) {
		ans*=f;
	}
	return ans;
}
int main() {
	ioso;
	#ifndef ONLINE_JUDGE
	ffe;
	#endif
	ll n; cin >> n;
	ll cn=0;
	ll a[200010];
	for(int i=0;i<=500;i++) {
		a[i] = calc(i); 
	}

	for(int i=-500;i<=500;i++) {
		for(int j=-500;j<=500;j++) {
			ll k = ((j<0) ? (-a[abs(j)]) : a[j]);
			ll k1 = ((i<0) ? -a[abs(i)] : a[i]);
			if(k1-k == n) {
				cout << i << " " << j << endl; return 0;
			} 
		}
	}
	
		
}

Measured memory_bytes: 3624
import "dart:io";


main(List<String> args) {
  int A = int.parse(stdin.readLineSync());
  int B = int.parse(stdin.readLineSync());
  int C = int.parse(stdin.readLineSync());
  int X = int.parse(stdin.readLineSync());
  int ans = 0;
  for (var i = 0; i <= A; i++) {
    for (var j = 0; j <= B; j++) {
      for (var k = 0; k <= C; k++) {
        if (X == 500 * i + 100 * j + 50 * k) ans++;
      }
    }
  }
  print(ans);
}

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

using namespace std;

const int INF = 100000000;
int N, M, R;
int ds[200][200],dl[200][200];//ship walk
int list[1000];
int dp[1000][200];

int main() {
	while (cin >> N >> M, N + M) {
		for (int i = 0; i < N; i++)for (int j = 0; j < N; j++)
		{
			if (i == j)dl[i][j] = ds[i][j] = 0;
			else dl[i][j] = ds[i][j] = INF;
		}
		for (int i = 0; i < M; i++) {
			int a, b, cost;
			char c;
			cin >> a >> b >> cost >> c;
			a--, b--;
			if (c == 'L') dl[a][b] = min(cost, dl[a][b]), dl[b][a] = dl[a][b];
			else ds[a][b] = min(cost, ds[a][b]), ds[b][a] = ds[a][b];
		}
		cin >> R;
		for (int i = 0; i < R; i++)cin >> list[i],list[i]--;
		//???????????£??????????????????
		for (int k = 0; k < N; k++) {
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < N; j++) {
					ds[i][j] = min(ds[i][j], ds[i][k] + ds[k][j]);
					dl[i][j] = min(dl[i][j], dl[i][k] + dl[k][j]);
				}
			}
		}
		for (int i = 0; i < R; i++)for (int j = 0; j < N; j++)dp[i][j] = INF;
		//dp[i][j] := i???????????????????????°??§???j?????????????????¨??????????????¨?????????????????????????????????
		for (int i = 0; i < N; i++) {
			dp[0][i] = ds[list[0]][i] + dl[i][list[0]];
		}
		for (int i = 1; i < R; i++) {
			for (int j = 0; j < N; j++) {
				for (int k = 0; k < N; k++) {
					if (j == k)dp[i][j] = min(dp[i][j], dp[i - 1][k] + dl[list[i]][list[i - 1]]);
					else {
						dp[i][j] = min(dp[i][j], dp[i - 1][k] + dl[list[i - 1]][k] + ds[k][j] + dl[j][list[i]]);
					}
				}
			}
		}
		int ans = INF;
		for (int i = 0; i < N; i++)ans = min(ans, dp[R - 1][i]);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 4200
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#define rep(i,s,n) for (int i=s;i<n;++i)
#define drep(i,s,n) for (int i=n;i>=s;--i)
#define all(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define print(x) cout<<(x)<<endl
using namespace std;
typedef long long ll;

int gcd(int a,int b)
{if (a%b == 0) return(b);
 else          return(gcd(b,a%b));}
int lcm(int a,int b)
{return a*b/gcd(a,b);}
void printv(vector<auto> v) {cout<<'[';rep(i,0,v.size()){cout<<v[i]<<',';}cout<<']'<<endl;}
void printvv(vector<vector<auto>> vv)
{
  cout<<'['<<endl;
  rep(q,0,vv.size()){cout<<'[';rep(p,0,vv.at(q).size())cout<<vv.at(q).at(p)<<',';cout <<']'<<endl;}
  cout<<']'<<endl;
}
void solve(); int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}
int step_x[] = {-1,0,0,1};
int step_y[] = {0,-1,1,0};
//------------------------------------------------------------
ll n,m,ans=0;

void solve() {
  cin>>n>>m;
  ll sum = 0;
  rep(i,0,m) 
  {
    int num=0; cin >> num;
    sum += num;
  }
  ans = n - sum;

  if(ans<0) print(-1);
  else print(ans);

  return;
}


Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	int x; cin >> x;
	if (x < 1200)cout << "ABC" << endl;
	else cout << "ARC" << endl;
	return 0;
}

Measured memory_bytes: 256
/*
    Life Before Death, Strength Before Weakness, Journey Before Destination
    ------------------------------------------------------------------------
    You don't become great by trying to be great.
    You become great by wanting to do something,
    and then doing it so hard that you become great in the process.
    */
 
    //#pragma comment(linker, ack:200000000")
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include <bits/stdc++.h>
    using namespace std;
    
    #define TRACE
    
    #ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
      cerr << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
      const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
    #else
    #define trace(...)
    #endif
    
    #define rep(i, n)    for(ll i = 0; i < (n); ++i)
    #define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
    #define repD(i, a, n)  for(ll i = a; i >= (n); --i)
    #define trav(a, x) for(auto& a : x)
    #define all(x) x.begin(), x.end()
    #define sz(x) (int)(x).size()
    #define fill(a)  memset(a, 0, sizeof (a))
    #define fst first
    #define snd second
    //#define mp make_pair
    #define pb push_back
    #define PI           3.141592653589793238462643383279502884197169399  /* pi */
    #define te  ll ti;   cin >> ti;  while(ti--) solve();  
    typedef long double ld;
    typedef long long ll;
    typedef pair<ll, ll> pii;
    typedef vector<ll> vi;
    const int maxN = 200100;

    void solve(){
        ll n, k, g = 0;
        cin >> n >> k;
        ll a[n];
        rep(i, n) cin >> a[i], g = __gcd(g, a[i]);
        ll m = *max_element(a, a+n);
        if(k > m) {
            cout << "IMPOSSIBLE" << endl;
            return;
        }
        cout << (k%g ? "IMPOSSIBLE" : "POSSIBLE") << endl;
    }
 
    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
     /*
      #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
      #endif
     */
      //te
      solve();
      return 0;
    } 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N;
  cin >> N;
  vector<int> q(N);
  int e = 0;
  for(long long i = 0; i < N; i++) {
    e++;
    q.at(i) += e;
  }
  for(long long i = 0; i < N; i++) {
    if((i + 1) % 3 == 0) {
      q.at(i) -= q.at(i);
    }
    if((i + 1) % 5 == 0) {
      q.at(i) -= q.at(i);
    }
  }
  long long t = 0;
  for(long long i = 0; i < N; i++) {
    t += q.at(i);
  }
  cout << t << endl;
}

Measured memory_bytes: 7056
#include<iostream>
#include<stack>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;

int main()
{
    stack<int> S1;
    stack< pair<int,int> > S2;
    char ch;
    int sum=0;
    for(int i=0;cin>>ch;i++)
    {
        if(ch=='\\') S1.push(i);
        else if(ch=='/' && S1.size()>0)
        {
            int j=S1.top();S1.pop();
            sum +=i-j;
            int a=i-j;
            while(S2.size()>0 && S2.top().first>j)
            {
                a+=S2.top().second;S2.pop();
            }
            S2.push(make_pair(j,a));
        }
    }

    vector<int> ans;
    while(S2.size()>0){
        ans.push_back(S2.top().second);
        S2.pop();
    }
    reverse(ans.begin(),ans.end());
    cout<<sum<<endl;
    cout<<ans.size();
    for(int i=0;i<ans.size();i++)
    {
        cout<<" ";
        cout<<ans[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3184
<?php
$n = intval(trim(fgets(STDIN)));
$x = array_map("intval", explode(" ", trim(fgets(STDIN))));
$pos = round(array_sum($x) / sizeof($x));
$i = 0;
foreach ($x as $val) {
  $i += pow($val - $pos, 2);
}
echo $i . PHP_EOL;


Measured memory_bytes: 3828
//file_name:ABC84_B.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


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

    string s;
    cin >> s;

    rep(i,a){
        int aa = s[i];
        //cout << aa;
        if(aa<48||aa>57){
            puts("No");
            return 0;
        }
    }
    if(s[a]!='-'){
        puts("No");
        return 0;
    }
    srep(i,a+1,a+b+1){
        int aa = s[i];
        if(aa<48||aa>57){
            puts("No");
            return 0;
        }
    }



    cout << "Yes" << endl;
    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
void tv(int sum,int *a,int *b,int *c);
void output(int a,int b,int c);
main(){
  int a,b,c,sum;
  while(1){
    cin >> a >> b >> c;
    if(a == -1 && b == -1 && c == -1)break;
    /* 標準録画 */
    sum = (7200 - ((a*3600)+(b*60)+c));
    tv( sum , &a , &b , &c );
    output( a , b , c );
    /* ３倍録画 */
    // 出力
    sum *= 3;
    tv( sum , &a , &b , &c );
    output( a , b , c );
  }
}
void tv(int sum,int *a,int *b,int *c){
  *a = sum / 3600;
  sum = (sum % 3600);
  *b = sum / 60;
  sum = sum % 60;
  *c = sum;
  return ;
}
void output(int a,int b,int c){
  if(a<10)printf("0%d:",a);
  else printf("%d:",a);
  if(b<10)printf("0%d:",b);
  else printf("%d:",b);
  if(c<10)printf("0%d\n",c);
  else printf("%d\n",c);
  return;
}

Measured memory_bytes: 1140
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

lli h, w;
vector<vector<lli>> a;

int main(void){
    cin >> h >> w;
    a.resize(h);
    rep(i, h){
        a[i].resize(w);
        rep(j, w){
            cin >> a[i][j];
        }
    }
    vector<lli> d, e, f, g;
    lli x, y;
    rep(i, h){
        if(i%2 == 0){
            for(int j = 0; j < w-1; j++){
                if(a[i][j]%2 == 0) continue;
                a[i][j]--;
                a[i][j+1]++;
                x = i+1;
                y = j+1;
                d.push_back(x);
                e.push_back(y);
                f.push_back(x);
                g.push_back(y+1);
            }
            if(i < h-1 && a[i][w-1]%2 == 1){
                a[i][w-1]--;
                a[i+1][w-1]++;
                x = i+1;
                y = w;
                d.push_back(x);
                e.push_back(y);
                f.push_back(x+1);
                g.push_back(y);
            }
        }else{
            for(int j = w-1; j >= 1; j--){
                if(a[i][j]%2 == 0) continue;
                a[i][j]--;
                a[i][j-1]++;
                x = i+1;
                y = j+1;
                d.push_back(x);
                e.push_back(y);
                f.push_back(x);
                g.push_back(y-1);
            }
            if(i < h-1 && a[i][0]%2 == 1){
                a[i][0]--;
                a[i+1][0]++;
                x = i+1;
                y = 1;
                d.push_back(x);
                e.push_back(y);
                f.push_back(x+1);
                g.push_back(y);
            }
        }
    }
    cout << d.size() << endl;
    rep(i, d.size()){
        cout << d[i] << " " << e[i] << " " << f[i] << " " << g[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 9368
N, M = list(map(int,input().split()))
 
d = int(M/N)

def solve():
    # ans = 1
    # for i in range(M//N+1, 0, -1):
    #     if M % i == 0:
    #         if (M // i) >= N:
    #             print(i)
    #             break
    for i in range(d+1,0,-1):
    	if M%i == 0:
    		print(i)
    		break

	# i = 0
	# while True:
	# 	if M%(N+i+1) == 0:
	# 		print(int(M/(N+i+1)))
	# 		break
	# 	i += 1

if M%N == 0:
	print(d)
else:
	solve()

Measured memory_bytes: 2940
from collections import deque
n = int(input())
A = list(map(int, input().split()))
B = deque()

for i in range(n):
    if i%2 == 0:
        B.append(A[i])
    else:
        B.appendleft(A[i])
B = list(B)        
if n%2 != 0:
    B = B[::-1]
print(*B)



Measured memory_bytes: 32516
n = int(input())
u = list(input())
v = list(input())

mod = 10**9+7

l = []

pointer = 0
while pointer < n:
    if u[pointer] == v[pointer]:
        pointer += 1
        l.append(0)
    else:
        pointer += 2
        l.append(1)


a = 1
for i,x in enumerate(l):
    if i == 0:
        if x == 0:
            a *= 3
        else:
            a *= 6
    else:
        if x == 0:
            if l[i-1] == 0:
                a *= 2
            else:
                pass
        else:
            if l[i-1] == 0:
                a *= 2
            else:
                a *= 3
    a %= mod

print(a)

Measured memory_bytes: 3064
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A[] = new int[N];
    for(int i=0;i<N;i++){
      A[i] = sc.nextInt();
    }
    int ans=0;
    for(int i=0;i<N;i++){
      int minj = i;
      for(int j=i;j<N;j++){
        if(A[j]<A[minj]){
          minj = j;
        }
      }
      if(i!=minj){
        int tmp = A[i];
        A[i] = A[minj];
        A[minj] = tmp;
        ans++;
      }
    }
    for(int i=0;i<N;i++){
      if(i>0){
        System.out.print(" ");
      }
      System.out.print(A[i]);
    }
    System.out.print("\n");
    System.out.println(ans);
  }
}



Measured memory_bytes: 26368
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  int A,B,C;
  int array[101];
  cin >>N;
  int i=0;
  for(i=0;i<N;i++)cin >> array[i];
  int count=0;
  for(i=0;i<N;i++){
      if(array[i]%2==0){
          if(array[i]%3!=0 && array[i]%5!=0){
              count++;
          }
      }
      if(count>0){
          cout<<"DENIED\n";
          break;
      }
  }

  if(count==0)cout <<"APPROVED\n";
  
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
using namespace std;
typedef long long ll;
ll dx[] = { 1,1,0,-1,-1,-1,0,1 };
ll dy[] = { 0,1,1,1,0,-1,-1,-1 };
ll prime(ll x) {
	ll i;
	if (x < 2)return 0;
	else if (x == 2) return 1;
	if (x % 2 == 0) return 0;
	for (i = 3; i*i <= x; i += 2) {
		if (x%i == 0) return 0;
	}
	return 1;
}
ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}

ll MOD = 1000000007;
int main() {
	string X;
  	cin>>X;
  	ll x=0,y=0;
  	for(ll i=0; i<X.size(); i++){
      if(X[i]=='S')x++;
      else if(x>0) x--,y++;
    }
  cout<<X.size()-y*2<<endl;
  
  
}

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

int main() {
    int n, q, l, r;
    string s;
    cin >> n >> q >> s;
    int cs[n];
    cs[0] = 0;
    for (int i = 1; i < n; i++) {
        cs[i] = cs[i - 1];
        if (s[i - 1] == 'A' && s[i] == 'C') cs[i]++;
    }
    for (int i = 0; i < q; i++) {
        cin >> l >> r;
        cout << cs[r - 1] - cs[l - 1] << endl;
    }
}

Measured memory_bytes: 1408