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

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) (((a) >> (b)) & 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
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); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

string s;
int dp[4][101010];

signed main() {
  cin >> s;

  m0(dp);
  dp[0][0] = 1;

  for (int i = 1; i <= (int)s.size(); i++) {
    for (int j = 0; j < 4; j++) dp[j][i] = dp[j][i - 1];

    bool flag = (s[i - 1] == '?');
    if (s[i - 1] == 'A' || flag) dp[1][i] += dp[0][i - 1];
    if (s[i - 1] == 'B' || flag) dp[2][i] += dp[1][i - 1];
    if (s[i - 1] == 'C' || flag) dp[3][i] += dp[2][i - 1];

    if (flag) {
      for (int j = 0; j < 4; j++) {
        dp[j][i] += 2 * dp[j][i - 1];
        dp[j][i] %= MOD;
      }
    }

    for (int j = 0; j < 4; j++) dp[j][i] %= MOD;
  }

  cout << dp[3][s.size()] << endl;
  return 0;
}


Measured memory_bytes: 3584
#include <stdio.h>

int main(){
  int a, b, c;
  scanf("%d %d", &a, &b);
  if (((a+b)>=(a-b)) && ((a+b)>=(a*b))) c=a+b;
  else if (((a-b)>=(a+b)) && ((a-b)>=(a*b))) c=a-b;
  else c=a*b;
  printf("%d", c);
  return 0;
}


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

#define lld long long
#define pii pair<int,int>
#define pll pair<lld,lld>
#define pb push_back
#define next nextt
#define Inf 1000000000
#define Linf 1000000000000000000LL
#define Mod 1000000007

using namespace std;

int N,M;
int dv[100002];
bool checkv[100002];
map<int,int> d[100002];
vector<pii> edge[100002];
map<int,vector<int>> grp[100002];
priority_queue<pair<int,pii>,vector<pair<int,pii>>,greater<pair<int,pii>>> q;

int main(){
	scanf("%d %d",&N,&M);
	for(int i=1; i<=M; i++){
		int x,y,z;
		scanf("%d %d %d",&x,&y,&z);
		edge[x].pb({y,z});
		edge[y].pb({x,z});
		d[x][z] = d[y][z] = Inf;
		grp[x][z].pb(y); grp[y][z].pb(x);
	}
	for(int i=1; i<=N; i++) dv[i] = Inf;
	d[1][0] = dv[1] = 0;
	q.push({0,{1,0}});
	while(!q.empty()){
		int v,color,value;
		v = q.top().second.first;
		color = q.top().second.second;
		value = q.top().first;
		q.pop();
		if(value != d[v][color]) continue;
		if(!checkv[v]){
			checkv[v] = true;
			for(auto &i : edge[v]){
				dv[i.first] = min(dv[i.first],dv[v]+1);
				if(d[i.first][i.second] > dv[v]+1){
					d[i.first][i.second] = dv[v]+1;
					q.push({dv[v]+1,{i.first,i.second}});
				}
			}
		}
		for(auto &i : grp[v][color]){
			dv[i] = min(dv[i],value);
			if(d[i][color] > value){
				d[i][color] = value;
				q.push({value,{i,color}});
			}
		}
	}
	if(dv[N] == Inf) dv[N] = -1;
	printf("%d\n",dv[N]);

	return 0;
}


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

#define rep(i, n) for (int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

tuple<int, vector<int>> selectionSort(vector<int> a, int n){
  int swaps = 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 (a[minj] == a[i]) continue;
    int tmp = a[minj];
    a[minj] = a[i];
    a[i] = tmp;
    swaps++;
  }
  return forward_as_tuple(swaps, a);
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  vector<int> ans;
  int times;
  tie(times, ans) = selectionSort(a, n);
  rep(i, n) printf("%d%c", ans[i], i == n-1 ? '\n':' ');
  cout << times << endl;
  return 0;
}



Measured memory_bytes: 3240
N, P = map(int,input().split())
A = list(map(int,input().split()))
dp = [[0,0] for k in range(N+1)]
dp[0][0] = 1
for k in range(N):
    if A[k]%2 == 0:
        dp[k+1][0] = dp[k][0]*2
        dp[k+1][1] = dp[k][1]*2
    else:
        dp[k+1][0] = dp[k][0] + dp[k][1]
        dp[k+1][1] = dp[k][1] + dp[k][0]

print(dp[N][P])


Measured memory_bytes: 61936
let odd x = x mod 2 <> 0
                         
let solve a b c =
  let rec iter x y z acc =
    if (odd x) || (odd y) || (odd z) then acc
    else
      if (x = y) && (y = z) then (-1)
      else
        iter ((y+z) / 2) ((x+z) / 2) ((z+x) / 2) (acc + 1) in iter a b c 0

let () =
  let a, b, c = Scanf.scanf "%d %d %d" (fun x y z -> (x, y, z)) in
  print_endline @@ string_of_int @@ solve a b c


Measured memory_bytes: 384
import java.io.PrintWriter
import java.math.BigDecimal
import java.util.*

val pw = PrintWriter(System.out)
val sc = Scanner(System.`in`)

fun main(args: Array<String>) {
    val n = nextInt()
    val a = nextListOfLong()
    abc159d(n,a)
}

fun abc159d(n:Int, a:List<Long>){
    val cnt = a.toLongArray().groupBy { it }
        .mapValues { it.value.count().toLong() }

    var sum = 0L
    for ((key, value) in cnt){
       sum += (value*(value-1)/2)
    }
    for(i in 0 until n){
        val ans = sum - (cnt[a[i]]!! - 1)
        pw.println(ans)
    }
    pw.flush()

    //val dct = a.distinct()
    //val mupc: MutableMap<Int, Long> = mutableMapOf()
    //var sum = 0L
    //for (element in dct){
    //    val tmp = a.filter { num -> element == num }
    //    mupc[tmp.first()] = tmp.size.toLong()
    //    sum += tmp.size*(tmp.size-1)
    //}
    //for(i in 0 until n){
    //    if (mupc[a[i]] == 1L){
    //        println(sum/2)
    //    }else{
    //        println((sum - (2* mupc[a[i]]!! - 2 ))/2)
    //    }
    //}
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextListOfString() = next().split(" ")
fun nextListOfInt() = nextListOfString().map { it.toInt() }
fun nextListOfLong() = nextListOfString().map { it.toLong() }
fun nextListOfDouble() = nextListOfString().map { it.toDouble() }



Measured memory_bytes: 129620
#include<bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
  int n,k;
  string s;
  cin >> n >> s >> k;
  fr(i,n){
   if(s.substr(k-1, 1)!=s.substr(i, 1))
  s.replace(i, 1, "*");
  }
  cout << s << endl;
}


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

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

int main()
{
  long long n;
  long long a[100000];
  scanf("%lld%lld", &n, a);
  long long gl[100001];
  long long gr[100001];
  gl[0] = a[0];
  for (long long i = 1; i < n; ++i)
  {
    scanf("%lld", a + i);
    gl[i] = gcd(a[i], gl[i - 1]);
  }
  gr[n - 1] = a[n - 1];
  for (long long i = n - 2; i >= 0; --i)
  {
    gr[i] = gcd(a[i], gr[i + 1]);
  }
  long long ans = std::max(gl[n - 2], gr[1]);
  for (long long i = 1; i < n - 1; ++i)
  {
    ans = std::max(ans, gcd(gl[i - 1], gr[i + 1]));
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<cmath>

template <typename T=std::int64_t>
T factorial(T n){
	if(n <= 1){
		return 1;
	}
	return ((n % 1000000007) * factorial(n-1))% 1000000007;
}
int main(void){
	std::int64_t N,M;
	std::cin >> N;
	std::cin >> M;
	std::int64_t abs_a = abs(N-M);
	if(abs_a >= 2){
		std::cout << 0 << std::endl;
	}

	std::int64_t n = factorial(N);
	std::int64_t m = factorial(M);
	
	if(abs_a == 0){
		std::cout << (2 * n * m)%1000000007 << std::endl;
	}
	else if(abs_a == 1){
		std::cout <<  (n * m)%1000000007 << std::endl;
	}
	return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll X;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>X;
	ll ret=X/11*2;
	X%=11;
	if(X) {
		if(X<=6) ret++;
		else ret+=2;
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 256
//https://qiita.com/tanakh/
#[allow(unused_macros)]
macro_rules! input {
	(source = $s:expr, $($r:tt)*) => {
		let mut iter = $s.split_whitespace();
		let mut next = || { iter.next().unwrap() }; 
		input_inner!{next, $($r)*}
	};
	($($r:tt)*) => {

		let stdin = std::io::stdin();
		let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); 
		let mut next = move || -> String{
			bytes
				.by_ref()
				.map(|r|r.unwrap() as char) 
				.skip_while(|c|c.is_whitespace()) 
				.take_while(|c|!c.is_whitespace()) 
				.collect()
			};
	input_inner!{next, $($r)*} 
	};
}

#[allow(unused_macros)]
macro_rules! input_inner { 
	($next:expr) => {}; 
	($next:expr, ) => {};

	($next:expr, $var:ident : $t:tt $($r:tt)*) => { 
		let $var = read_value!($next, $t); 
		input_inner!{$next $($r)*}
	}; 
}
#[allow(unused_macros)]
macro_rules! read_value { 
	($next:expr, ( $($t:tt),* )) => {
		( $(read_value!($next, $t)),* ) 
	};
	
	($next:expr, [ $t:tt ; $len:expr ]) => {
		(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
	};

	($next:expr, chars) => {
		read_value!($next, String).chars().collect::<Vec<char>>()
	};
	
	($next:expr, bytes) => {
		read_value!($next, String).into_bytes()
	};
	
	($next:expr, usize1) => { 
		read_value!($next, usize) - 1
	};

	($next:expr, $t:ty) => {
		$next().parse::<$t>().expect("Parse error")
	};
}

fn gcdsaiki(a: i64, b: i64) -> i64{
	if b == 0{
		return a;
	} else {
		return gcdsaiki(b, a % b);
	}
}

fn main(){
	input!{
		a :i64,
		b :i64,
	}
	let mut ans : i64 = 0;
	ans = gcdsaiki(a,b); 
	println!("{}",ans);
}



Measured memory_bytes: 5036
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<vector>
using namespace std;



int main(){
    string key;
    cin >> key;
    int flag = 1;
    for(int i= 0; i<3; i++){
        if(key[i] == key[i+1]) flag = 0;
    }
    if(flag) cout << "Good" << endl;
    else cout << "Bad" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	while(1){
		int h,w;
		scanf("%d %d\n",&h,&w);
		if(h==0 && w==0){
			break;
		}else{
			int x,y;
			for(x=0;x<h;x++){
				for(y=0;y<w;y++){
					if(x==0 || x==h-1){
						printf("#");
					}else if(y==0 || y==w-1){
						printf("#");
					}else{
						printf(".");
					}
					if(y==w-1){
						printf("\n");
					}
				}
			}
		printf("\n");
		}
	}
}

Measured memory_bytes: 576
#include<iostream>

using namespace std;
 
void dist(int math, int eng, int jap){
  int av = (math + eng + jap) / 3;

  if(math == 100 || eng ==100 || jap ==100){
    cout << 'A' << endl;
  }else if((math + eng) / 2 >= 90){
    cout << 'A' << endl;
  }else if(av >= 80){
    cout << 'A' << endl;
  }else if(av >= 70){
    cout << 'B' << endl;
  }else if(av >= 50 && (math >= 80 || eng >= 80)){
    cout << 'B' << endl;
  }
  else{
    cout << 'C' << endl;
  }
       
}
 
int main(){
   
  int n,pm,pe,pj;
 
  while(cin >> n){
    if(n == 0){ 
      break;
    }
    for(int i = 0; i < n; i++){
      cin >> pm >> pe >> pj;
      dist(pm,pe,pj);
    }
  }
  return 0;
}

Measured memory_bytes: 1148
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();

		if((a + b) % 2 ==0)
			System.out.println((a + b) / 2);
		else
			System.out.println("IMPOSSIBLE\r\n" +
					"");
	}
}


Measured memory_bytes: 21716
#define _USE_MATH_DEFINES

#include<math.h>
#include<stdio.h>
#include<utility>
#include<algorithm>

int main() {
	int H, W, n, m, l;
	n = 1;
	m = 1;
	while (true) {
		scanf("%d %d", &H, &W);

		if (H + W == 0) {
			break;
		}
		else {
			while (m <= H) {
				while (n <= W) {
					l = n + m;
					if (l% 2 == 0) {
						printf("#");
						n++;
					}
					if (l % 2 == 1) {
						printf(".");
						n++;
					}
				}
				printf("\n");
				n = 1;
				m++;
			}
			printf("\n");
			n = 1;
			m = 1;
			H = 0;
			W = 0;
		}
	}
	return 0;
}

Measured memory_bytes: 2564
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

while True:
    N = int(input())
    ans_list = sorted(make_divisors(N))
    ans = 0
    #print(ans_list)
    for i in ans_list:
        m = N // i - 1
        if N < m * m:
            #print(i)
            #print(N // i - 1)
            ans += (N // i - 1)

    print(ans)
    break


Measured memory_bytes: 39152
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    int a[1000001]={0};
    int n;
    cin>>n;
    int b[n];
    for(int i=0;i<n;i++)
    {
        cin>>b[i];
        a[b[i]]++;
    }
    sort(b,b+n);
    for(int i=0;i<n;i++)
    {

        for(int j=b[i]+b[i];j<=b[n-1];j=j+b[i])
            {
                a[j]++;
            }

    }
    int count=0;
    for(int i=0;i<n;i++)
    {
        if(a[b[i]]==1)
            count++;
    }
    cout<<count;
    return 0;
}

Measured memory_bytes: 8320
#include<iostream>
using namespace std;
int pro(int c,int a,int n){
    int A,f;
    f=(c+a+n)/3;
    for(int i=0;i<f;i++){
        if(c>0&&a>0&&n>0){
            A++;c-=1;a-=1;n-=1;
        }else if(a==0){
            A++;c-=3;
            if(c<0){
                A--;break;
            }
        }else if(n==0){
            A++;c-=2;a-=1;
            if(c<0){
                A--;break;
            }
        }else break;
    }
    return A;
}
int main(void)
{
    int Q,c,a,n,A;
    cin>>Q;
    for(int i=0;i<Q;i++){
        cin>>c>>a>>n;
        if(c==0||c+a+n<3){
            cout<<"0\n";
        }else{
            A=pro(c,a,n);
            cout<<A<<"\n";
        }
    }
}

Measured memory_bytes: 1160
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int N;
int a[3][110];

int main(void){
	          int i;

	      	  cin.tie(0);  ios_base::sync_with_stdio(false);

	      	  cin >> N;
	      	  for(i=1;i<=N;i++){
	      		  cin >> a[1][i];
	      		  a[1][i]+=a[1][i-1];
	      	  }
	      	  for(i=1;i<=N;i++){
	      		  cin >> a[2][i];
	      		  a[2][i]+=a[2][i-1];
	      	  }

	      	  int ans=0;
	      	  for(i=1;i<=N;i++){
	      		  int mx=a[1][i]+a[2][N]-a[2][i-1];
	      		  ans=max(ans,mx);
	      	  }

	      	  cout << ans << endl;

	          return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) REP(i, 0, n)

using namespace std;

char buf[128], a[128], b[128], c[128];
char p[128], q[128], r[128];
int main()
{
	while (scanf("%s", buf) != EOF) {
		int al = strlen(strcpy(a, strtok(buf, "+=\n")));
		int bl = strlen(strcpy(b, strtok(NULL, "+=\n")));
		int cl = strlen(strcpy(c, strtok(NULL, "+=\n")));

		int d = 0;
		if (al > 1 && a[0] == 'X' || bl > 1 && b[0] == 'X' || cl > 1 && c[0] == 'X') d = 1;
		int len = max(al, max(bl, cl)) + 1;
		reverse(a, a+al); REP(i, al, len) a[i] = '0';
		reverse(b, b+bl); REP(i, bl, len) b[i] = '0';
		reverse(c, c+cl); REP(i, cl, len) c[i] = '0';

		int res = -1;
		for (int i = d; i < 10; ++i) {
			rep(j, len) p[j] = (a[j] == 'X') ? i : a[j] - '0';
			rep(j, len) q[j] = (b[j] == 'X') ? i : b[j] - '0';
			rep(j, len) r[j] = (c[j] == 'X') ? i : c[j] - '0';
			int t = 0;
			bool found = true;
			rep(j, len) {
				int s = p[j] + q[j] + t;
				if (s >= 10) { s -= 10; t = 1; } else { t = 0; }
				if (s != r[j]) { found = false; break; }
			}
			if (found) { res = i; break; }
		}
		if (res == -1) puts("NA"); else printf("%d\n", res);
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<=n;i++)
	{cin>>a[i];}
	int dp[n];
	memset(dp,0,sizeof(dp));
	dp[1]=abs(a[1]-a[0]);
	for(int i=2;i<n;i++)
	{
		dp[i]=min(dp[i-1]+abs(a[i-1]-a[i]),dp[i-2]+abs(a[i-2]-a[i]));
	}
	cout<<dp[n-1]<<endl;

	return 0;
}

Measured memory_bytes: 4380
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

#define INF 2e9

#define REP(i,n) for(int i = 0; i < n;++i)
#define REPA(i,a,n) for(int i = a; i < n; ++i)
#define ALL(a) a.begin, a.end()

using namespace std;

int main(void) {

	int N, K;

	cin >> N >> K;

	int height, count = 0;

	REP(i, N) {
		cin >> height;
		if (height >= K) count++;
	}

	cout << count << endl;

	return 0;
}

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

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef double ld;

int main()
{

	//ifstream cin("input.txt");
	//freopen("output.txt", "w", stdout);

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	ll x, y;
	cin >> x >> y;
	ll ans = min(x, y / 2);
	x -= ans, y -= 2 * ans;
	ans += y / 4;

	cout << ans << "\n";

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD (long long)(1E9+7)
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;
int checkBlWh(string s, bool wh) {
	int cnt = 0;
  	rep(i, s.size()){
		if(s[i] - '0' == wh) {
        	cnt++; 
        }
      	wh = !wh;
	}
  	return cnt;
}
int main(){
	string s;
	int t = 0;
	cin >> s;
  	t = checkBlWh(s, true);	
  	t = min(t, checkBlWh(s, false));
	cout << t << endl;
}


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

int main() {
  int n, count;
  cin >> n;
  count=0;
  int p[n];
  for(int i=0; i<n; i++) {
    cin >> p[i];
  }
  for(int i=1; i<n-1; i++) {
    if(p[i]<p[i-1]&&p[i]>p[i+1]) {
      count++;
    }
    else if(p[i]>p[i-1]&&p[i]<p[i+1]) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int x; cin >> x;
	if (x>=30) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int d = sc.nextInt();
		int n = sc.nextInt();
		double ans = 0;
      
      if (n == 100) {
      n++;
      }

		ans = Math.pow(100, d) * n;

		System.out.println((int)ans);

		sc.close();
	}
}


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

int main(){
    int n,p;
    cin>>n>>p;
    string s;
    cin>>s;
    if(p==2||p==5){
        ll ans=0;
        for(int i=0;i<n;i++){
            if((s[i]-'0')%p==0LL){
                ans +=i+1;
            }
            
        }
        cout<<ans<<endl;
    }
    else{
        vector<ll>U(n+1,0);
        map<int,int>mods;//各mod pに何個値があるか
        mods[0]=1;
        ll ans=0;
        int pw[n+1];
        pw[0]=1;
        for(int i=1;i<=n;i++) pw[i]=10*pw[i-1] %p;

        for(int i=n-1;i>=0;i--){
            //各Uを求める
            U[i]=(U[i+1]+(s[i]-'0')*pw[n-i-1])%p;
            //cout<<U[i]<<endl;
            ans+=mods[U[i]];
            mods[U[i]]++;
        }

        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3204
def resolve():
	n, k = map(int, input().split())
	h = list(map(int, input().split()))
	dp = [float('inf')]*n
	dp[0] = 0
	for i in range(n):
		for j in range(1, k+1):
			if i + j < n:
				dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j] - h[i]))
	print(dp[-1])
resolve()

Measured memory_bytes: 55136
def main():
  import sys
  sys.setrecursionlimit(500000)
  input = sys.stdin.readline

  N, Q = map(int, input().split())
  G = [[] for _ in range(N)]
  cnt = [0]*N
  visited = [0]*N

  for _ in range(N-1):
      a, b = map(int, input().split())
      a -= 1
      b -= 1
      G[a].append(b)
      G[b].append(a)

  for i in range(Q):
      node, x = map(int, input().split())
      node -= 1
      cnt[node] += x

  visited[0]=1
  st = [0]
  while st:
      v = st.pop()
      for u in G[v]:
          if visited[u]:
              continue
          visited[u] = 1
          cnt[u] += cnt[v]
          st.append(u)    

  print(*cnt)
if __name__ == '__main__':
    main()


Measured memory_bytes: 55824
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;


long long cnt;
int MAX = 1000000;
vector<int> G;

void insertSort(int A[], int n, int g) {
  int j, i, v;
  for ( i = g; i < n; i++ ) {
    v = A[i];
    j = i - g;
    while ( j >= 0 && A[j] > v ) {
      A[j + g] = A[j];
      j = j - g;
      cnt++;
    }
    A[j + g] = v;
  }
}

void shellSort(int A[], int n) {
  for (int h = 1; ; ) {
    if (h > n) break;
    G.push_back(h);
    h = 3*h + 1;
  }

  for ( int i = G.size()-1; i>=0; i--) {
    insertSort(A, n, G[i]);
  }
}

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

  cnt = 0;

  shellSort(A, n);

  printf("%lu\n", G.size());
  for ( int i = G.size()-1; i>=0; i--) {
    printf("%d", G[i]);
    if (i) printf(" ");
  }
  printf("\n");
  printf("%llu\n", cnt);
  for ( int i = 0; i < n; i++ ) printf("%d\n", A[i]);

  return 0;
}



Measured memory_bytes: 6664
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define DL double
#define MLL map<LL,LL>::iterator
#define MSL map<string,L>::iterator
#define MLS map<LL,string>::iterator
#define MSS map<string,string>::iterator
#define MCL map<char,LL>::iterator
#define SL set<LL>::iterator
#define SS set<string>::iterator
#define VL vector<LL>::iterator
#define G getline
#define SZ size()
#define IN insert
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
set<LL>v;
int main()
{
    FAST;
    LL n,m,i,j,k,p,q,o,l,s,t,z;
    cin>>n>>m>>o;
    for(i=n; i<(n+o); i++)
    {
        v.IN(i);
    }
    for(i=m; i>(m-o); i--)
    {
        v.IN(i);
    }
    for(SL it=v.B; it!=v.E; it++)
    {
        if(*it>m)
        {
            break;
        }
        if(*it>=n)
        {
            cout<<*it<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	int N, T; cin >> N >> T;
	vector<int>pluss(T + 1);
	for (int i = 0; i < N; ++i) {
		int l, r; cin >> l >> r;
		pluss[l]++;
		pluss[r]--;
	}
	vector<int>sums(T + 1);
	int ans = 0;
	for (int i = 0; i <= T; ++i) {
		sums[i + 1] = sums[i] + pluss[i];
		ans = max(ans, sums[i + 1]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3624
fun main(args :Array<String>) {
    val x = readInteger()
    when (x) {
        7, 5, 3 -> "YES"
        else -> "NO"
    }.let {
        println(it)
    }
}

fun readInteger() = readLine()!!.toInt()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 31832
//#pragma GCC optimize("-Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("avx2")  //Enable AVX
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//order_of_key(x) : number of items less than x
//find_by_order(x) : iterator to x

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()

const ld pi=3.14159265359;
ll INF=1e18+10;
ll MOD=998244353;
ll mod=1e9+7;

inline ll add(ll a,ll b,ll m){
    if(a+b>=m)return (a+b)-m;
    return a+b;
}

inline ll mul(ll a,ll b,ll m){
    if((a*b)<m)return a*b;
    return (a*b)%m;
}

int main()
{
    fastio;
    ll n,x,y;cin>>n>>x>>y;
    ll ans[n+1];mem(ans,0);
    rep(i,1,n+1)
    {
        rep(j,i+1,n+1)
        {
            ll dis=min(abs(j-i),abs(x-i)+1+abs(y-j));
            dis=min(dis,abs(y-i)+1+abs(x-j));
            ans[dis]++;
        }
    }
    rep(i,1,n)cout<<ans[i]<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }

int dp[2005];

int f(int s) {
  if(s < 0) return 0;
  if(s == 0) return 1;
  if(dp[s] != -1) return dp[s];
  int ret = 0;
  for(int i = s; i >= 3; i--) {
    ret = add(ret, f(s - i));
  }
  return dp[s] = ret;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  int s;
  cin >> s;
  memset(dp, -1, sizeof dp);
  cout << f(s);
}

Measured memory_bytes: 3656
<?php
list($n, $q) = explode(" ", trim(fgets(STDIN)));
$string_array = str_split(trim(fgets(STDIN)));
$array = [];
$count = 0;
for($i=0; $i<count($string_array); $i++){
	if($i!==0){
		if($string_array[$i-1] . $string_array[$i] == "AC"){
			$count += 1;
		}
	}
	$array[] = $count;
}
$ans_array = [];
for($i=0; $i<$q; $i++){
	list($num1, $num2) = explode(" ", trim(fgets(STDIN)));

	$ans_array[] = $array[$num2-1] - $array[$num1-1];
} 

foreach ($ans_array as $value) {
	echo $value . "\n";
}

Measured memory_bytes: 18040
N = int(input())

L = []
for i in range(1,N+1):
  L.append((i,int(input())))

o = L[0][1]
cnt = 1
while o != 2:
  o = L[o-1][1]
  cnt += 1
  if cnt > N:
    print(-1)
    exit()
    
print(cnt)

Measured memory_bytes: 16556
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000000+7;
const long long INF=-mod;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<long long,long long>;
using vl=vector<long long>;
//ショートカット
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,k,n) for(int i=k;i<n;i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
//入力
#define vin(v,N) for(long long i=0;i<N;i++) cin>>v.at(i)
#define lin(n) long long n;cin>>n
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)

//関数
//最大公約数
long long gcd(long long m,long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m,long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(long long x,long long N){
  long long ret=1;
  for(long long i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//nCr
long long C(long long n, long long r);
//nCr (mod)
long long modC(long long n, long long r) {
    vector<long long> f(n+1),inv(n+1),invf(n+1);
    f[0]=f[1]=1;
    invf[0]=invf[1]=1;
    inv[1]=1;
    for (long long i=2;i<n+1;i++) {
        f[i]=(i*f[i-1])%mod;
        inv[i]=mod-((mod/i)*inv[mod%i])%mod;
        invf[i]=(inv[i]*invf[i-1])%mod;
    }
    long long cmb=f[n]*(invf[r]*invf[n-r]%mod)%mod;
    if (n>=r) return cmb;
    else return 0;
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//メイン関数
int main(){
  //doubleの桁数
  cout<<fixed<<setprecision(10);
  
  lin(N);
  ll A=0,B=0;
  vector<P> dish(N);
  rep(i,N){
    ll a,b;cin>>a>>b;
    dish[i].first=a+b;
    dish[i].second=a;
  }
  
  sort(rall(dish));
  
  rep(i,N){
    if(i%2==0){
      A+=dish[i].second;
    }
    else{
      B+=dish[i].first-dish[i].second;
    }
  }
  
  cout<<A-B<<endl;
  //cout<<A<<" "<<B<<endl;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void){
    int L, R, d;
    int i;
    int count=0;

    


    scanf("%d%d%d", &L, &R, &d);

    for (i=L; i<=R; i++) {
        if (i%d==0) {
            count = count + 1;
        }
    }


        printf("%d\n", count);

    return 0;
}


Measured memory_bytes: 1732
def p(x):
 for i in[2,3,5,7,9,11,13,17,19,21,23]:
  if x%i==0:return [1,0][x>i]
 i=29
 while i<=x**.5:
  if x%i==0:return 0
  i+=2
 return 1
n=int(input())
print(sum([p(int(input()))for _ in range(n)]))

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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(lint i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(lint i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const lint inv = MOD - 2;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

int main(){
    lint a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    c *= 2;
    lint ans = a * x + b * y;
    rep(i, max(x, y) + 1){
        ans = min(ans, c * i + max(x - i, 0LL) * a + max(y - i, 0LL) * b);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int n, m;
  int r1, r2;
  vector<int> road(n);
  
  cin >> n >> m;
  for(int i=0;i<m;++i){
    cin >> r1 >> r2;
    road.at(r1-1)++; road.at(r2-1)++;
  }
  for(int i=0;i<n;++i){
    cout << road.at(i) << endl;
  }
}

Measured memory_bytes: 24832
#include<iostream>
#include<stack>
#include<string>
#include<cstdlib>
using namespace std;

int main(){
	stack<int> S;
	
	int a,b;
	string s;
	
	while(cin >> s){
		if (s[0] == '+'){
			a=S.top();
			S.pop();
			b=S.top();
			S.pop();
			S.push(a+b);
		}else if(s[0] == '-'){
			a=S.top();
			S.pop();
			b=S.top();
			S.pop();
			S.push(b-a);
		}else if(s[0]== '*'){
			a=S.top();
			S.pop();
			b=S.top();
			S.pop();
			S.push(a*b);
		}else{
			S.push(atoi(s.c_str()));
		}
	}
	
	cout << S.top() << endl;
	return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long 
#define FI first 
#define SE second
#define pb push_back 
#define eb emplace_back
#define mod 1000000007
#define all(c) (c).begin(),(c).end()
#define LB  lower_bound
#define UB  upper_bound
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF -1e18
#define INF 1e18
#define int ll int
#define OOK order_of_key  //no of elements less than
#define FBO find_by_order //iterator pointing kth element;indexing starts from 0
#define CK3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define CK4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl

typedef pair<int,int> PII;
typedef pair<pair<int,int>,int> PPII;
typedef pair<int,pair<int,int>> PIPI;
typedef map<int,int>MII;
typedef vector<int> VI;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

/*int power(int a, int b)
{int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;}
*/
//int modInverse(int a, int m) {return power(a, m-2);} //gcd(a,m)=1 


signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T=1,T1=0;//cin>>T;
while(T1++<T)
{
    int n,k;
    cin>>n>>k;
    int x1=n/k;
    int ans=min(n-x1*k,(x1+1)*k-n);
    cout<<ans<<endl;
}


return 0;
}





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

int main() {
  string N;
  cin >> N;
  
  int sum = 0;
  for (int i = 0; i < N.size(); i++) {
    sum += N[i] - '0';
  }

  if (stoi(N) % sum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  } 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

void test_case(){
	int n; cin >> n;
	while(n>0){
		n-=1000;
	}
	cout<<abs(n);
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T=1;
	//~ cin >> T;
	while(T--){
		test_case();
	}
	return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
int order[100001],cnt[100001];
int n;

void f(int x,int i){
  int j;
//  if(n+7<=x)return;
  if(cnt[x]>i){
    cnt[x]=i;
    if(order[x]==0)
      for(j=1;j<=6;j++)
        f(x+j,i+1);
    else f(x+order[x],i);
  }
}
      

int main(){
 int i;
 scanf("%d",&n);
 for(i=0;i<n;i++)
   scanf("%d",&order[i+1]);
 for(i=0;i<=n;i++)
   cnt[i]=100001;
 
 f(1,0);
 
 printf("%d\n",cnt[n]);
 
 return 0;
}

Measured memory_bytes: 1900
#include<stdio.h>
int main(){
  int i, n, count=0, next, f=-1;
  scanf("%d", &n);
  int an[100000];

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

  int flg[100000]={};

  next = an[0];

  while (next!=1 && next!=2 && flg[next-1]==0) {
    flg[next-1]=1;
    next = an[next-1];
    count++;
  }

  if(next==2){
    count++;
    printf("%d\n", count);
  }else{
    printf("%d\n", f);
  }

  return 0;
}

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

int main(){

    int N;
    scanf("%d",&N);

    int H,L;

    if(1 <= N / 100 && N / 100 <= 12){
        H = 1;
    }else{
        H = 0;
    }

    if(1 <= N % 100 && N % 100 <= 12){
        L = 1;
    }else{
        L = 0;
    }

    if(H == 1 && L == 1){
        cout << "AMBIGUOUS" << endl;
    }else if(H == 1 && L == 0){
        cout << "MMYY" << endl;
    }else if(H == 0 && L == 1){
        cout << "YYMM" << endl;
    }else{
        cout << "NA" << endl;
    }

    return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
#define REP(i, a, b) for (int i=a; i<b; i++)

int main()
{

string s;
cin >> s;
int len = s.length();

if(s[len-1] != 's')
{
 s = s + "s";
}
else{
    s = s + "es";
}

cout << s;

}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 112345;
struct UnionFind {
  vector<int> data; // 根の場合は集合の大きさ*-1、子の場合は親の番号が入る
  UnionFind(int size) : data(size, -1) { }
  bool link(int x, int y) { //新たな併合を行うとtrue
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  int root(int x) { // 代表元を返す
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) { // 要素xが含まれる集合の大きさ
    return -data[root(x)];
  }
};

struct Edge {
  int a;
  int b;
  ll w;
};
ll X[MAX_N];
ll S[MAX_N];
vector< pair<int,int> > g[MAX_N];

int memo[MAX_N];
set< pair<int,int> > ans;

void dfs(int v, int c) {
  if (memo[v] >= c) return;
  memo[v] = c;
  for (auto e : g[v]) {
    const int u = e.first;
    const int w = e.second;
    if (w <= c) {
      ans.insert( { min(u,v), max(u,v) } );
      dfs(u, c);
    }
  }
}

int main2() {
  REP(i, MAX_N) g[i].clear();
  int N = nextInt();
  int M = nextInt();
  REP(i, N) X[i] = nextInt();
  vector<Edge> edge;
  REP(i, M) {
    int a = nextInt() - 1;
    int b = nextInt() - 1;
    int y = nextInt();
    edge.push_back( (Edge){a, b, y} );
    g[a].push_back( {b, y} );
    g[b].push_back( {a, y} );
  }
  sort(ALL(edge), [](const Edge&a, const Edge&b) -> bool {
    return a.w < b.w;
  });
  vector<Edge> cand;
  REP(i, N) S[i] = X[i];
  UnionFind uf(N);
  for (Edge e : edge) {
    // cout << e.a << " " << e.b << " "<< e.w << endl;
    ll s1 = S[uf.root(e.a)];
    ll s2 = S[uf.root(e.b)];
    if (uf.link(e.a, e.b)) {
      S[ uf.root(e.a) ] = s1 + s2;
    }
    if (S[uf.root(e.a)] >= e.w) cand.push_back(e);
  }
  sort(ALL(cand), [](const Edge&a, const Edge&b) -> bool {
    return a.w > b.w;
  });

  CLR(memo, -1);
  ans.clear();
  for (Edge e : cand) {
    dfs(e.a, e.w);
  }
  cout << M - ans.size() << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 26992
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
int main() {
	int h, w, x, y;
	bool isOK;
	char a[8][9], s[16][16];
	scanf("%d%d", &h, &w);
	for (int i = 0; i < h; i++) {
		scanf("%s", a[i]);
	}
	for (int i = 0; i < 1 << (h + w); i++) {
		x = y = 0;
		isOK = true;
		memset(s, '.', sizeof(s));
		s[y][x] = '#';
		for (int j = 0; j < (h + w); j++) {
			if ((i >> j) & 1) {
				x++;
			} else {
				y++;
			}
			s[y][x] = '#';
		}
		for (int j = 0; j < h; j++) {
			for (int k = 0; k < w; k++) {
				if (a[j][k] != s[j][k]) {
					isOK = false;
					break;
				}
			}
		}
		if (isOK) {
			printf("Possible\n");
			return 0;
		}
	}
	printf("Impossible\n");
	return 0;
}

Measured memory_bytes: 128
#! /usr/bin/python

import sys
from string import ascii_lowercase, whitespace

def datasets():
    for line in sys.stdin:
        yield line.strip()

hints = ('the', 'this', 'that')

inclement_chars = lambda cs, n: ''.join(
    [succ_char(c, n) 
    if all([c not in case for case in (whitespace, '.', '\n')]) 
    else c 
    for c in cs])

make_picklist = lambda s: [inclement_chars(s, n) for n in range(1, 27)]

def main():
    for problem in datasets():
        picklist = make_picklist(problem)
        for n, candidate in enumerate(picklist, 1):
            if any([case in candidate for case in hints]):
                break
        print picklist[n-1]


def succ_char(c, n):
    succ_ord = ord(c)+n
    z = ord('z')
    if succ_ord > z:
        succ_ord = ord('a') + (succ_ord - z - 1)
    return chr(succ_ord)

if __name__ == '__main__':
    main()

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

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


int main(){
    int N; cin >> N;
    long long  a[100010];
    long long  b[100010];
    long long  c[100010];
    long long dp[100010][3];
    for(int i=0; i<N; i++){
        cin >> a[i]>> b[i]>> c[i];
    }

    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    for(int i=1;i<N;i++){
        dp[i][0] = max(dp[i-1][1]+a[i], dp[i-1][2]+a[i]);
        dp[i][1] = max(dp[i-1][0]+b[i], dp[i-1][2]+b[i]);
        dp[i][2] = max(dp[i-1][0]+c[i], dp[i-1][1]+c[i]);
    }
    long long  ans = 0;
    ans = max(dp[N-1][0],dp[N-1][1]);
    ans = max(ans, dp[N-1][2]);

    cout << ans << endl;
}



Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;

int main(){
  int sx,sy,tx,ty;
  cin>>sx>>sy>>tx>>ty;
  int x=tx-sx;
  int y=ty-sy;
  for(int i=0;i<y;i++){
    cout<<'U';
  }
  for(int i=0;i<x;i++){
    cout<<'R';
  }
  cout<<'U';
  for(int i=0;i<=x;i++){
    cout<<'L';
  }
  for(int i=0;i<=y;i++){
    cout<<'D';
  }
  for(int i=0;i<=x;i++){
    cout<<'R';
  }
  for(int i=0;i<y;i++){
    cout<<'U';
  }
  cout<<'R';
  for(int i=0;i<=y;i++){
    cout<<'D';
  }
  for(int i=0;i<=x;i++){
    cout<<'L';
  }
  cout<<'U'<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;
void solve(){
  int k, s, ans = 0; cin >> k >> s;
  for(int x = 0; x <= k; x++){
    for(int y = 0; y <= min(s - x, k); y++){
      if(s - x - y <= k) ans++;
    }
  }
  cout << ans << endl;
  return;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;

ll n,d,p[11][11],ans;
set< ll > sq;

ll fn( ll i, ll j ){
    ll sum = 0;
    for(ll k=0; k<d; k++) sum+=(p[i][k]-p[j][k])*(p[i][k]-p[j][k]);
    return sum;
}

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> d;
    for(ll i=0; i<=10000; i++) sq.insert( i*i );

    for(ll i=0; i<n; i++) for(ll j=0; j<d; j++) cin >> p[i][j];

    for(ll i=0; i<n; i++){
        for(ll j=i+1; j<n; j++){
            ll var = fn( i , j );
            if( sq.find( var )!=sq.end() ) ans++;
        }
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 768
n,k=map(int,input().split())
ans=0
for i in range(k,n+2):
    a=0.5*i*(i-1)
    b=0.5*n*(n+1)-0.5*(n-i)*(n-i+1)
    ans+=int(b-a+1)
    
    
print(ans%(10**9+7))

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    std::vector<int> cnt(n + 1);
    for (int i = 0; i < n; i++) {
        int a;
        std::cin >> a;
        cnt[a]++;
    }

    std::vector<int> v;
    for (auto e : cnt) if (e) v.push_back(e);
    std::sort(v.begin(), v.end());

    std::vector<int> ss { 0 };
    for (auto e : v) ss.push_back(ss.back() + e);

    int m = v.size();
    for (int i = 1; i <= n; i++) {
        if (m < i) {
            std::cout << 0 << std::endl;
            continue;
        }

        int l = 0, r = n + 1;
        while (r - l > 1) {
            i64 mid = (l + r) / 2;
            i64 j = std::lower_bound(v.begin(), v.end(), mid) - v.begin();
            i64 ssmall = ss[j], sbig = (m - j) * mid;
            if (mid * i <= n && (ssmall + sbig) >= i * mid) l = mid;
            else r = mid;
        }
        std::cout << l << std::endl;
    }

    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(ll i=x;i<y;i++)
#define frr(i,x,y) for(ll i=x-1;i>=y;i--)
#define inf 1e18+1
const ll mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve()
{
    ll a;
    cin>>a;
    double b;

    cin>>b;
    b*=100;
    ll x=1000-b;

    a=a*1000-a*x;
    a/=100;
    cout<<a<<endl;
    return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

Measured memory_bytes: 3744
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;


int a[6];


int main(){

	rep(i, 6)cin >> a[i];

	if (a[0] + a[1] * 5 + a[2] * 10 + a[3] * 50 + a[4] * 100 + a[5] * 500 >= 1000)cout << '1' << endl;
	else cout << '0' << endl;

	return 0;
}



Measured memory_bytes: 3112