akhauriyash/Code-Regression huggingface dataset:
#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;
#define RET(ans) {cout<<ans<<endl;return 0;} 

    // 二次元ベクターの基本
    /*
    vector<vector<int>> dp; // 宣言
    dp.resize(n); // 1次元めの要素数決定
    dp[i].push_back(int); // プッシュバック
    rep(i,n){
        sort(dp[i].begin(),dp[i].end()); // 二次元めを昇順ソート
    }
    */

    // 整数スキャン（複数）
    /*
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s; cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s; cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    string s; cin >> s;
    int n;
    cin >> n;
    rep(i,s.size()){
        if(s[i]=='a')continue;
        int a = s[i];
        int z = 'z';
        if(n>=z-a+1){
            s[i] = 'a';
            n -= z-a+1;
        }
    }
    n %= 26;
    int x = s[s.size()-1];
    x += n;
    s[s.size()-1] = (char)x;
    cout << s << endl;

    return 0;
}
 
 


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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<int, int> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  char s;
  cin >> s;
  if(s == 'A'){
    cout << 'T' << endl;
  }else if(s == 'T'){
    cout << 'A' << endl;
  }else if(s == 'C'){
    cout << 'G' << endl;
  }else if(s == 'G'){
    cout << 'C' << endl;
  }
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

/**
 * コイン問題
 * @author nobu
 * @see <a href="http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_A&lang=ja">DPL_1_A</a>
 */
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int c[] = new int[m];
		int t[] = new int[50001];

		for (int i = 0; i < m; i++) {
			c[i] = sc.nextInt();
		}

		Arrays.fill(t, Integer.MAX_VALUE);
		t[0] = 0;

		for (int i = 0; i < m; i++) {
			for (int j = 0; j + c[i] <= n; j++) {
				t[j + c[i]] = Math.min(t[j] + 1, t[j + c[i]]);
			}
		}

		System.out.println(t[n]);

	}

}



Measured memory_bytes: 26776
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
using namespace std;
using Edge = pair<int, int>; // 辺番号, 隣接頂点
using Node = vector<Edge>; // 頂点から伸びる辺のリスト
using NodeList = vector<Node>;
int main() {
    int n, m;
    cin >> n >> m;
    auto nodes = NodeList(n, Node(0));
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        nodes[a].push_back(Edge(i, b));
        nodes[b].push_back(Edge(i, a));
    }
    auto ans = 0;
    rep(i, m) { // 各辺 i について，その辺だけを除いた新しいグラフをそれぞれ構築して連結性を判定
        auto graph = NodeList(0); // 新しいグラフを作り上げる
        for (auto &node : nodes) { // 元のグラフの全ノードについて
            Node newNode = Node(0); // 新グラフの対応ノード
            for (auto &edge : node) { // 元のノードから伸びる各辺について
                if (edge.first != i) newNode.push_back(edge); // 辺番号が i でなければ新グラフの対応ノードにも追加
            }
            graph.push_back(newNode); // 新グラフに対応ノードを追加
        }
        // 新グラフの連結性判定(DFS)
        auto flags = vector<bool>(n, false); // 訪問済みフラグ
        function<void(int, int)> reach = [&graph, &flags, &reach](int index, int prev) {
            flags[index] = true; // 訪問済みフラグを立てる
            auto &edges = graph[index]; // 隣接リスト
            for (auto edge : edges) {
                auto nextIndex = edge.second;
                if (nextIndex == prev) continue; // 一つ前のノードに戻らない
                if (flags[nextIndex]) continue; // 訪問済みノードはスキップ
                reach(nextIndex, index); // 隣接ノードに訪問済みフラグを立ててゆく
            }
        };
        reach(0, -1); // ノード0を起点にして隣接全頂点をDFSで訪問
        if (any_of(flags.begin(), flags.end(), [](auto x) { return x == false; })) { // 未訪問ノードが残って入れば不連結
            ans++; // 辺番号 i は橋
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

int n;
ll a[200005];
ll a2[200005];
ll sum[200005];
ll sum2[200005];

int main(void){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
        assert(a[i]>=0LL);
        a2[i]=-a[i]*2LL;
    }
    ll prev=a[n-1];
    stack<P> st;
    st.push(P(1,0));
    for(int i=n-2;i>=0;i--){
        sum[i]+=sum[i+1];
        ll len=0;
        while(prev<a[i]){
            while(st.size()>0){
                if(st.top().second==0LL){
                    len+=st.top().first;
                    st.pop();
                }else{
                    st.top().second--;
                    break;
                }
            }
            sum[i]+=len*2LL;
            //printf("go i %d %lld %lld %lld %d\n",i,prev,len,sum[i],st.size()==0?-1:st.top().first);
            prev*=4LL;
        }
        if(len>0){
            st.push(P(len,0));
        }
        ll cnt=0;
        ll po=a[i];
        while(prev>=po){
            cnt++;
            po*=4LL;
        }
        cnt--;
        if(cnt==0LL){
            st.top().first++;
        }else{
            st.top().second+=cnt;
            st.push(P(1,0));
        }
        //printf("push %lld\n",cnt);
        prev=a[i];
    }
    //printf(" go\n");
    for(int i=1;i<=n;i++){
        sum2[i]=1;
    }
    while(st.size())st.pop();
    prev=a2[0];
    st.push(P(1,0));

    for(int i=1;i<n;i++){
        sum2[i+1]+=sum2[i];
        ll len=0;
        while(prev>a2[i]){
            while(st.size()>0){
                if(st.top().second==0LL){
                    len+=st.top().first;
                    st.pop();
                }else{
                    st.top().second--;
                    break;
                }
            }
            sum2[i+1]+=len*2LL;
            //printf("go i %d %lld %lld %lld %d\n",i,prev,len,sum2[i],st.size()==0?-1:st.top().first);
            prev*=4LL;
        }
        if(len>0){
            st.push(P(len,0));
        }
        ll cnt=0;
        ll po=a2[i];
        while(prev<=po){
            cnt++;
            po*=4LL;
        }
        cnt--;
        if(cnt==0LL){
            st.top().first++;
        }else{
            st.top().second+=cnt;
            st.push(P(1,0));
        }
        //printf("push %lld\n",cnt);
        prev=a2[i];
    }

    ll ans=sum[0]+sum2[0];
    for(int i=0;i<=n;i++){
        //printf("i %d %lld %lld\n",i,sum[i],sum2[i]);
        if(sum[i]<0 || sum2[i]<0)continue;
        ans=min(ans,sum[i]+sum2[i]);
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 6528
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	long long a,b,c,count=0;
	cin>>a>>b>>c;
	while(1)
	{
		if(a==b&&b==c&&a%2==0){count=-1;break;}
		if(a==b&&b==c&&a%2==1){count=0;break;}
		while(a%2==0&&b%2==0&&c%2==0)
		{
			long long aa,bb,cc;
			aa=b/2+c/2;
			bb=a/2+c/2;
			cc=a/2+b/2;
			count++;
			a=aa;b=bb;c=cc;
		}
		break;
	}
	cout<<count<<endl;
	return 0;
}


Measured memory_bytes: 256
"""
マージソート
分割統治法に基づく高速なアルゴリズム。
merge(A, left, mid, right)
  n1 = mid - left;
  n2 = right - mid;
  L[0...n1], R[0...n2] を生成
  for i = 0 to n1-1
    L[i] = A[left + i]
  for i = 0 to n2-1
    R[i] = A[mid + i]
  L[n1] = INFTY
  R[n2] = INFTY
  i = 0
  j = 0
  for k = left to right-1
    if L[i] <= R[j]
      A[k] = L[i]
      i = i + 1
    else 
      A[k] = R[j]
      j = j + 1

mergeSort(A, left, right)
  if left+1 < right
    mid = (left + right)/2;
    mergeSort(A, left, mid)
    mergeSort(A, mid, right)
    merge(A, left, mid, right)
"""

def merge(A,left,mid,right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    L = A[left:left+n1] + [10**9+7]
    R = A[mid:mid+n2] + [10**9+7]
    i = 0
    j = 0
    for k in range(left, right):
        cnt += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

def mergeSort(A, left, right):
    if left+1 < right:
        mid = (left + right)//2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A,left,mid,right)

n = int(input())
As = list(map(int, input().split()))
cnt = 0
mergeSort(As,0,n)
print(*As)
print(cnt)


Measured memory_bytes: 63700
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;

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)*}
    };
}

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)*}
    };

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

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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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 main() {
    input! {
        n: usize,
        s: chars,
    }
    let mut cnt = 0;

    for i in 0..1000 {
        let acc = format!("{:>03}", i);
        let mut idx = 0;
        for ch in s.iter() {
            if ch == &acc.chars().nth(idx).unwrap() {
                idx += 1;
            }
            if idx == 3 {
                cnt += 1;
                break;
            }
        }
    }
    println!("{}", cnt);
}


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

int main() {
  int input;
  string out = "Good";
  cin >> input;
  int a,b,c,d;
  a = input / 1000;
  b = (input - a * 1000) / 100;
  c = (input - (a * 1000) - (b * 100)) / 10;
  d = input - (a * 1000) - (b * 100) - (c * 10);
  if(a == b | b == c | c == d){
    out = "Bad";
  }
  cout << out << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int linear_Search( int , int* );

int main( void ){
	int i, n, q, count;
	
	scanf("%d", &n );
	
	int s[n+1];
	
	for( i = 0; i < n; i++ ){
		scanf("%d", &s[i] );
	}
	
	scanf("%d", &q );
	
	int t[q];
	
	for( i = 0; i < q; i++ ){
		scanf("%d", &t[i] );
	}
	
	count = 0;
	for( i = 0; i < q; i++ ){
		s[n] = t[i];
		count += linear_Search( n, s );
	}
	
	printf("%d\n", count );
	
	return 0;
}
	
int linear_Search( int n, int* s){
	int i;
	
	for( i = 0; i < n; i++ ){
		if( s[i] == s[n] ){
			return 1;
		}
	}
	
	return 0;
} 


Measured memory_bytes: 2092
#include <stdio.h>

int main(){
    int n,c,k=0,a;
    scanf("%d%d",&n,&c);
    int i;
    for(i=0;i<c;i++){
        scanf("%d",&a);
        k+=a;
    }
    if(k%(n+1)!=0) k+=(n+1);
    
    printf("%d\n",k/(n+1));
    
    return 0;
}


Measured memory_bytes: 2136
#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)
#define pint pair<int,int>
#define pll pair<ll,ll>
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int w[30][100020];
int x[100010];

int main(){
  int n,C;
  cin >> n >> C;
  rep(i,n){
    int x,y,z;
    cin >> x >> y >> z;
    x--,y--,z--;
    w[z][x]--;
    w[z][y]++;
  }
  rep(i,30){
    rep(j,100010){
      if(w[i][j]==-1){
        int temp=j+1;
        while(temp<100010 && w[i][temp]!=1){
          temp++;
        }
        if(w[i][temp]==1){
          x[j]++;
          x[temp+1]--;
        }
      }
    }
  }
  int ans=0;
  int temp=0;
  rep(i,100005){
    temp+=x[i];
    ans=max(ans,temp);
  }
  cout << ans << endl;
return 0;}

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

int dfs(const vector<vector<int>> &G, int v, int prev, int &ans, const int K){
  int d = 0, c = 0;
  for(auto v_ : G[v]){
    if(v_ == prev) continue;
    ++c;
    int d_ = dfs(G,v_,v,ans,K)+1;
    if(d_ == K and v != 0) ++ans;
    else d = max(d,d_);
  }
  return d;
}

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  vector<vector<int>> G(N);
  for(int i = 0; i < N; ++i){
    int a;
    cin >> a;
    --a;
    A[i] = a;
    if(i > 0)
      G[a].push_back(i);
  }
  int ans = (A[0] != 0);
  dfs(G,0,-1,ans,K);
  cout << ans << endl;
}


Measured memory_bytes: 13952
def main():
    takahashi_cookie, aoki_cookie, operation = map(int, input().split())
    for i in range(operation):
        if i % 2 == 0:
            if takahashi_cookie % 2:
                takahashi_cookie -= 1
            aoki_cookie += takahashi_cookie // 2
            takahashi_cookie //= 2
        else:
            if aoki_cookie % 2:
                aoki_cookie -= 1
            takahashi_cookie += aoki_cookie // 2
            aoki_cookie //= 2
    print(takahashi_cookie, aoki_cookie)


if __name__ == '__main__':
    main()



Measured memory_bytes: 3060
#include <iostream> 
#include <cstdio> 
#include <cstring> 
using namespace std; 
int main()
{
 char a[50],b[50],c[100]; while(cin>>a>>b)
{
 int i,j; c[0]=a[0]; 
for(i=1,j=0;i<=100;i++)
{
 if(i%2!=0) {c[i]=b[j];j++;} 
else 
c[i]=a[j]; 
}
 cout<<c<<endl;
 } 
return 0; 
} 


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

int main() {
	long long int a, b, c, min, MAX;
		cin >> a >> b >> c;
		min = MAX = a;
		if(min>b)
			min = b;
		if(min>c)
			min = c;
		if(MAX<b)
			MAX = b;
		if(MAX<c)
			MAX = c;
	cout << min << " " << MAX << endl;	
	return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main(){
    fastio;
    int n;
    cin >> n;
    if(n%1000){cout << 1000-n%1000 <<"\n";}
    else{cout << 0 <<"\n";}
    return 0;
}


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

typedef long long ll;

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

    string s; cin >> s;
    int n = s.size();
    int cnt1,cnt2,cnt3;
    cnt1 = cnt2 = cnt3 = 0;
    for(int i=0;i<n;i++){
        if(s[i]==s[n-i-1]) cnt1++;
    }
    if(cnt1!=n){
        cout << "No" << endl;
        return 0;
    }
    for(int i=0;i<n/2;i++){
        if(s[i]==s[n/2-1-i]) cnt2++;
    }
    if(cnt2!=n/2){
        cout << "No" << endl;
        return 0;
    }
    int j = n - 1;
    for(int i=(n+3)/2-1;i<n;i++){
        if(s[i]==s[j--]) cnt3++;
    }
    if(cnt3!=n/2){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

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

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt(), b = scan.nextInt(), c = scan.nextInt();
        if(a == b && b == c || a != b && b != c && a != c) System.out.println("No");
        else System.out.println("Yes");
    }
}


Measured memory_bytes: 23764
require('fs').readFileSync(0, 'UTF-8').split('\n').some(input => {
  const [x, y] = input.trim().split(' ').map(Number)
  if (x === 0 && y === 0) { return true }
  if (x < y) {
    console.log(x, y)
  } else {
    console.log(y, x)
  }
})



Measured memory_bytes: 21592
package main

import "fmt"

func reverseStr(s string) string {

	runes := []rune(s)

	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}

	return string(runes)
}

func main() {
	// Code for A - Rotation
	var S1, S2 string
	fmt.Scanf("%s\n%s", &S1, &S2)

	if reverseStr(S1) == S2 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 1832
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int l; cin >> l;
	double x = (double)l / 3;
	cout << fixed << setprecision(10) << x * x * x << "\n";
}

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

using namespace std;
const int base = 1e9 + 7;
long long fastPow(long long a, long long n) {
    long long res = 1;
    for (; n > 0; n >>= 1, a = a * a % base) 
        if (n & 1)
            res = res * a % base;
    return res;
}
long long f[100005];
int main() {
#ifdef LDT
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    long long res  = 0;
    for (int i = k; i >= 1; --i) {
        f[i] = 1ll * fastPow(k / i, n) % base;
        for (int j = i + i; j <= k; j += i)
            f[i] -= f[j];
        f[i] %= base;
        if (f[i] < 0) f[i] += base;
        res += 1ll* i * f[i];
        res %= base;
    }
    cout << res;
    return 0;
}

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

using namespace std;

template <typename T>
using V = vector<T>;

typedef long double ld;
typedef long long ll;

#define FO(i, N) for (int (i) = 0; (i) < (N); ++(i))
#define FOll(i, N) for (ll (i) = 0; (i) < (N); ++(i))
#define READALL(c) for (auto &e : c) { cin >> e; }
#define PRINTALL(c) for (const auto &e : c) { cout << e << "\t"; } cout << "\n";
#define MP(x, y) (make_pair((x), (y)))
#define MT(...) make_tuple(__VA_ARGS__)
#define G(i, x) get<i>(x)
#define ALL(x) begin(x), end(x)

V<int> sts[500], ens[500];

int cnt[500][500], st[200000], en[200000], events[500];

bool open[200000];


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

	int N, M, Q, l, r;
	cin>>N>>M>>Q;
	FO(i, M) {
		cin>>st[i]>>en[i];
		--st[i];--en[i];
		sts[st[i]].push_back(i);
		ens[en[i]].push_back(i);
	}

	FO(i, N) {
		int s = 0;
		for (int j = i; j < N; ++j) {
			for (int e : sts[j]) open[e] = 1;
			for (int e : ens[j]) if (open[e]) ++s;
			cnt[i][j] = s;
		}
		for (int j = i; j < N; ++j)
			for (int e : sts[j]) open[e] = 0;
	}
	FO(i, Q) {
		cin >> l >> r;
		--l;--r;
		cout << cnt[l][r] << endl;
	}
}

Measured memory_bytes: 6272
import sys


def solve(N: int, S: "List[str]"):

    S = set(S)

    print(len(S))

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 35548
#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<long long>> VVLL;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

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

const int MOD = 1000000007;

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;
}

void debug(VI &arr){
	int n=arr.size();
	rep(i,n){
		cout<<arr.at(i)<<endl;
	}
}

void debug(VVI &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout << board.at(i).at(j) << " ";
		}
		cout<<endl;
	}
}

void debug(VVLL &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout<<board.at(i).at(j)<<" ";
		}
		cout<<endl;
	}
}

void debug(VS &board){
	int h = board.size();
	rep(i,h){
		cout<<board.at(i)<<endl;
	}
	return;
}

LL gcd(LL a,LL b){
	return b==0?a:gcd(b,a%b);
}

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

int main(){
	//cout<<fixed;
	//cout<<setprecision(9)<<...
	string s;cin>>s;
	int n = s.size();
	rep(i,n)cout<<"x";
	cout<<endl;
	return 0;
}


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

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N, K;

struct Jewel {
    LL value;
    int color;
    Jewel(LL value_, int color_) {
	value = value_;
	color=  color_;
    }
    bool operator<(const Jewel &y) const {
	return value != y.value ? value > y.value : color < y.color;
    }
};

VI G[100011];
const LL INF = 1LL<<60;
int C[100011];

void MAIN() {
    scanf("%d%d", &N, &K);
    REP (i, N) {
	int c, v;
	scanf("%d%d", &c, &v);
	c--;
	G[c].push_back(v);
    }

    vector<Jewel> J;
    multiset<Jewel> X, Y, Z;
    REP (k, K) if (!G[k].empty()) {
	VI &v = G[k];
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	REP (t, 2) J.emplace_back(v[0] + v[1], k);
	for (int a=2; a<(int)v.size(); a++) J.emplace_back(v[a]*2, k);

	Y.emplace(v[0]+v[1], k);
	if (G[k].size() >= 3u) {
	    Z.emplace((v[0]+v[1]+v[2])*2, k);
	}
    }
    sort(J.begin(), J.end());

    LL min_value = INF;
    LL min_pair = INF;
    LL sum = 0;
    for (int i=0; i<N; i++) {
	LL value = J[i].value;
	int color = J[i].color;
	LL ans = -2;

	if (C[color] == 0) {
	    if (!X.empty()) {
		amax(ans, sum + X.begin()->value);
	    }
	    if (!Y.empty()) {
		amax(ans, sum - min_value + Y.begin()->value * 2);
	    }
	    if (!Z.empty()) {
		amax(ans, sum - min_pair + Z.begin()->value);
	    }

	    Y.erase(Y.find(J[i]));
	    if (G[color].size() >= 3u) {
		Jewel key((LL)(G[color][0] + G[color][1] + G[color][2])*2, color);
		Z.erase(Z.find(key));
	    }
	} else {
	    ans = sum + value;;
	    if (C[color] == 1) {
		for (int p=2; p<(int)G[color].size(); p++) {
		    X.insert(Jewel(G[color][p]*2, color));
		}
		amin(min_pair, value * 2);
	    }
	    if (C[color] >= 2) {
		X.erase(X.find(J[i]));
		amin(min_value, value);
	    }
	}
	C[color]++;
	sum += value;

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

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



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

using namespace std;

int main(){
    int N,count=0;
    cin >>N;
    string a;
    a=to_string(N);
    int A=a.length();
    if(A==2){
        cout <<9;
    }else if(A==4){
        cout <<909;
    }else if(A==6){
        cout <<90909;
    }else if(A==1){
        cout <<N;
    }else if(A==3){
        cout <<9+N-99;
    }else if(A==5){
        cout <<9+900+N-9999;
    }
    return 0;
}

Measured memory_bytes: 256
a, b, x = gets.split.map(&:to_i)
m = a * a * b
if m / 2.0 > x
  n = x.to_f / a * 2 / b
  p Math.atan(b / n) * 180 / Math::PI
else
  y = (m - x).to_f
  n = y / a * 2 / a
  p Math.atan(n / a) * 180 / Math::PI
end


Measured memory_bytes: 3836
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 998244353
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
    if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
    }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




int main() {

  ll n,m,k;
  cin>>n>>m>>k;
  
  if(m==1){
    if(k==n-1) {
    cout << 1 << endl;
    return 0;
    }
    else {
    cout << 0 << endl;
    return 0;
    }
  }
  
  
  ll x=jou(m-1,n-1);
  ll ans=x;
  
  ll gyaku = jou(m-1,mod-2);
  
  for(ll i=1;i<=k;i++){
    x *= gyaku;
    x %= mod;
    x *= (n-i);
    x %= mod;
    x *= jou(i,mod-2);
    x %= mod;
    ans+=x;
    ans%=mod;
  }
  
  
  cout << (m*ans)%mod << endl;
}

Measured memory_bytes: 3636
from collections import deque

H, W = map(int, input().split())
C0, C1 = map(int, input().split())
D0, D1 = map(int, input().split())

LARGEST = 999999999
ARR = []

for i in range(H):
    ARR.append(input())


def calculate(h, w, c0, c1, d0, d1, arr):
    c0 = c0 - 1
    c1 = c1 - 1
    d0 = d0 - 1
    d1 = d1 - 1

    status = []
    for i in range(H):
        tmp = [LARGEST] * W
        status.append(tmp)

    status[c0][c1] = 0
    q = deque()

    q.append((c0, c1))

    while len(q) > 0:
        hIndex, wIndex = q.popleft()


        sss = [(hIndex, wIndex - 1), (hIndex, wIndex + 1), (hIndex - 1, wIndex), (hIndex + 1, wIndex)]

        for sH, sW in sss:
            if sH < 0 or sH >= h or sW < 0 or sW >= w:
                continue

            if arr[sH][sW] == '#':
                continue

            if status[sH][sW] > status[hIndex][wIndex]:
                status[sH][sW] = status[hIndex][wIndex]
                q.insert(0, (sH, sW))

        for _hIndex in range(hIndex - 2, hIndex + 3):
            for _wIndex in range(wIndex - 2, wIndex + 3):
                if (_hIndex < 0) or (_hIndex >= h) or (_wIndex < 0) or (_wIndex >= w):
                    continue

                if arr[_hIndex][_wIndex] == '#':
                    continue

                tmpIndex = status[hIndex][wIndex]+1
                if status[_hIndex][_wIndex] > tmpIndex:
                    status[_hIndex][_wIndex] = tmpIndex
                    q.append((_hIndex, _wIndex))

    if status[d0][d1] == LARGEST:
        print(-1)
    else:
        print(status[d0][d1])


calculate(H, W, C0, C1, D0, D1, ARR)


Measured memory_bytes: 94500
#include<iostream>
#include<set>
using namespace std;int Q,N,a,p,M,t;main(){for(cin>>Q;Q-->0;cout<<a<<endl){set<int>u;for(cin>>N,a=0;N/10&&~a;N=M)for(u.count(N)&&(a=-2),u.insert(N),a++,p=M=1;p<N;p*=10,M=t>M?t:M)t=(N/p)*(N%p);}}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
int main() {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    s1[0] = toupper(s1[0]);
    s2[0] = toupper(s2[0]);
    s3[0] = toupper(s3[0]);
    cout << s1[0] << s2[0] << s3[0] << endl;
    return 0;
}

Measured memory_bytes: 3584
package main
import (
   "fmt"
   
)

func abs(x int) int{
  if x < 0 {
    return -x
  } else {
    return x
  }
  
}
func main() {
	var x int
	fmt.Scan(&x)
	a := make([]int, x)
	for i := 0; i < x ; i++ {
  		fmt.Scan(&a[i])
	}
	max := 0
  for i := 0; i < x; i++ {
    if max < a[i] {max = a[i]}
  }
	m := 2000000001
	ans := 0
	for _,i := range a {
  		if max == i {
    		continue
    	}
 		if m > abs(i*2 - max) {
    		ans = i
    		m = abs(i*2 - max)
  		}
	}
	fmt.Printf("%d %d", max, ans)
}

Measured memory_bytes: 5504
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define MAX 100
#define LMAX 1000
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INF MAX*LMAX

int n, m;
int e[MAX][MAX], d[MAX][MAX];
bool used[MAX][MAX];

void floyd(){
	for(int k=0; k<n; k++){
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				d[i][j]=min(d[i][j], d[i][k]+d[k][j]);
			}
		}
	}
	return;
}

int main(){
	cin >> n >> m;
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			e[i][j]=INF;
			used[i][j]=false;
			if(i==j) d[i][j]=0;
			else d[i][j]=INF;
		}
	}
	for(int i=0; i<m; i++){
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		e[a][b]=e[b][a]=c;
		d[a][b]=d[b][a]=c;
	}
	floyd();

	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			if(e[i][j]==INF) continue;
			for(int k=0; k<n; k++){
				for(int l=k+1; l<n; l++){
					if(d[k][i]==INF || d[j][l]==INF) continue;
					if(d[k][i]+e[i][j]+d[j][l]==d[k][l]){
						used[i][j]=true;
					}
				}
			}
		}
	}
	int cnt=0;
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			if(used[i][j]) cnt++;
		}
	}
	cout << m-cnt << endl;
	return 0;
}

Measured memory_bytes: 384
N = int(input())
A = []
B = []
for _ in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
from statistics import median
Am = median(A)
Bm = median(B)
if N%2==1:
    ans = Bm-Am+1
    print(ans)
else:
    ans = int((Bm-Am)*2+1)
    print(ans)

Measured memory_bytes: 28940
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

int main() {
  int n; cin >> n;
  vector<int> A(n);
  loop(i,0,n) cin >> A[i];
  sort(A.begin(), A.end());
  cout << A[n/2] - A[n/2-1] << endl;
  return 0;
}


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

using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
	cin >> n;
	int a[n];
	for(int i=0;i<n;i++){
		int x;
		cin >> x;
		a[x-1] = i+1;
	}
	for(int i=0;i<n;i++){
		cout << a[i] << " ";
	}
    
	return 0;
}


Measured memory_bytes: 1280
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		String S=stdIn.next();
		String T="";
		for(int i=0;i<S.length();i++){
			T+="x";
		}
		System.out.println(T);
	}
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;
const int mxn=1e5+5;
const int inf=1e9;
int main() {
	ll d,t,s;
	cin>>d>>t>>s;

	if(t*s>=d)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 3588
#include<stdio.h>
int main(void)
{
   int a,b,c,x,s;

   scanf("%d%d%d",&a,&b,&x);
   s=a+b;
   if((s>=x) && (a<=x))
   printf("YES\n");
   else 
   printf("NO\n");
   return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)      x.begin(), x.end()
#define SIZE(x)     static_cast<i64>(x.size())
#define rep(i,n)    for (i64 i = 0, i ## _limit = (n); i < i ## _limit; ++i)
#define reps(i,s,t) for (i64 i = (s), i ## _limit = (t); i <= i ## _limit; ++i)
#define repr(i,s,t) for (i64 i = (s), i ## _limit = (t); i >= i ## _limit; --i)

#ifdef DBG
#define trace(...) _trace(#__VA_ARGS__, __VA_ARGS__);
#else
#define trace(...)
#endif

using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template<class T, class U>inline bool chmax(T &a, const U &b){return b>a && (a=b, true);}
template<class T, class U>inline bool chmin(T &a, const U &b){return b<a && (a=b, true);}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template<class T>
ostream& operator<< (ostream &os, const vector<T> &vec) {
    rep(i, vec.size()) os << vec[i] << (i+1 == vec.size() ? "" : " ");
    return os;
}

template<class T, class U>
ostream& operator<< (ostream &os, const pair<T, U> &p) {
    return os << p.first << ' ' << p.second;
}

template<class Itr>
ostream& printContainer(Itr begin, Itr end, const string &separator = " ", ostream &os = cout) {
    const auto rbegin = std::prev(end);
    for (; begin != rbegin; ++begin) os << *begin << separator;
    os << *rbegin;
    return os;
}

ostream& operator<< (ostream &os, ostream&) {
    return os;
}

template <class T>
void _trace(const char *s, T&& x) {
    clog << '{';
    while(*s != '\0') clog << *(s++);
    clog << ":" << setw(3) << x << '}' << endl;
}

template <class Head, class... Tail>
void _trace(const char *s, Head&& head, Tail&&... tail) {
    clog << '{';
    while(*s != ',') clog << *(s++);
    clog << ":" << setw(3) << head << "}, ";
    for (++s; !isgraph(*s); ++s);
    _trace(s, std::forward<Tail>(tail)...);
}
// }}} End Header

signed main()
{
    // ios::sync_with_stdio(false); cin.tie(nullptr);
    int H, W, h, w;
    cin >> H >> W >> h >> w;

    cout << H * W - (h * W) - (H * w) + h * w << endl;

    return 0;
}


Measured memory_bytes: 256
#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 ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N;
	cin >> N;
	double P[3000];
	rep(i, N) cin >> P[i];

	double dp[3000][3000] = {};
	dp[0][0] = 1.0;

	rep(i, N) {
		rep(j, i + 1) {
			dp[i + 1][j + 1] += dp[i][j] * P[i];
			dp[i + 1][j] += dp[i][j] * (1 - P[i]);
		}
	}

	double kotae = 0;
	for (int i = N / 2 + 1; i <= N; i++) {
		kotae += dp[N][i];
	}
	cout << setprecision(15) << kotae << endl;

	Would you please return 0;
}

Measured memory_bytes: 70656
/*
ID: properl1
LANG: C++
TASK: beads
*/

#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i].st
#define yol g[node][i].nd
#define mod 1000000007
#define inf 1000000009
#define N 1005
using namespace std;

typedef long long ll;
typedef pair < int , int > ii;

int n, ans;
string s;

int basamak(int x){
	int bas = 0;
	while (x > 0) {
		bas++;
		x = x/10;
	}
	return bas;
}

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);

	// freopen("beads.in", "r", stdin);
	// freopen("beads.out", "w", stdout);

	cin >> n;

	for (int i = 1; i <= n; i++) {
		if (basamak(i) % 2 != 0) {
			ans++;
		}
	}

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


Measured memory_bytes: 256
#ifdef _WIN32
#include "XOR.h"
#endif

#include <stdio.h>

#include <iostream>
#include <vector>
#include <array>

constexpr int64_t MOD = 1'000'000'007;
constexpr int64_t help = 1;

#define ll long long int

void fastscan(ll& number) {
	//variable to indicate sign of input number 
	int c;

	number = 0;

	// extract current character from buffer 
	c = getchar();

	// Keep on extracting characters if they are integers 
	// i.e ASCII Value lies from '0'(48) to '9' (57) 
	for (; (c > 47 && c < 58); c = getchar())
		number = number * 10 + c - 48;

	// if scanned input has a negative sign, negate the 
	// value of the input number 
}
#ifdef _WIN32
namespace XOR
{
#endif 

	int main() {
		ll n;

		fastscan(n);


		std::array<ll, 62> bits{};
		for (ll i = 0; i < n; i++) {
			ll d;
			fastscan(d);
			for (ll b = 0; b < 62; b++) {
				bits[b] += !!(d & (help << b));
			}
		}

		ll ans = 0;

		for (ll b = 0; b < 62; b++) {
			ll p = (help << b) % MOD;
			ans += (bits[b] * (n - bits[b]) % MOD) * p;
			ans %= MOD;
		}

		std::cout << ans;
	}
#ifdef _WIN32
}
#endif 


Measured memory_bytes: 3640
#include<iostream>
#define ll int
using namespace std;
	int n;
ll a[105];
ll eval(int m){
	ll ret = 0;
	for(int i = 0;i<n;i++){
		ret+=(m-a[i]) * (m-a[i]);
	}
	return ret;
}
int main(){
	cin>>n;
	for(int i = 0;i<n;i++) cin>>a[i];
	ll ans = 1e9;
	for(int i =1;i<=100;i++){
		ans = min(ans, eval(i));
	}
	cout<<ans<<"\n";
	return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}

struct UnionFindTree{
    vector<int32_t>par,sz;
    UnionFindTree(int32_t n=0):par(n),sz(n){
        for(int32_t i=0;i<n;i++){
            par[i]=i;
            sz[i]=1;
        }
    }
    int32_t find(int32_t x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int32_t x,int32_t y){
        x=find(x);y=find(y);
        if(x==y)return;
        if(sz[x]<sz[y])swap(x,y);
        sz[x]+=sz[y];
        par[y]=x;
    }
    bool same(int32_t x,int32_t y){
        return find(x)==find(y);
    }
    int32_t size(int32_t x){
        return sz[find(x)];
    }
};

int N,M;
int X[111111];
int A[111111],B[111111],C[111111];

int ch[111111][2];
int sum[111111];

int score[111111];
int last[111111];
bool ok[111111];
void dfs(int v){
    if(v==-1)return;
    if(score[v]>=C[v])return;
    ok[v]=false;
    dfs(ch[v][0]);
    dfs(ch[v][1]);
}
signed main(){
    scanf("%lld%lld",&N,&M);
    rep(i,N)scanf("%lld",&X[i]);
    rep(i,M){
        scanf("%lld%lld%lld",&A[i],&B[i],&C[i]);
        A[i]--;B[i]--;
    }
    vint ord(M);iota(all(ord),0);
    sort(all(ord),[&](int i,int j){
        return C[i]<C[j];
    });

    UnionFindTree uf(N);



    memset(last,-1,sizeof(last));
    rep(i,N)sum[i]=X[i];
    for(auto i:ord){
        int a=A[i],b=B[i];
        if(uf.same(a,b))continue;
        ok[i]=true;

        a=uf.find(a);
        b=uf.find(b);
        uf.unite(a,b);
        if(uf.find(a)!=a)swap(a,b);
        sum[a]+=sum[b];
        score[i]=sum[a];

        ch[i][0]=last[a];
        ch[i][1]=last[b];
        last[a]=i;
    }

    dfs(last[uf.find(0)]);
    uf=UnionFindTree(N);
    rep(i,N)sum[i]=X[i];
    for(auto i:ord)if(ok[i]){
        int a=A[i],b=B[i];
        a=uf.find(a);b=uf.find(b);
        uf.unite(a,b);
        if(uf.find(a)!=a)swap(a,b);
        sum[a]+=sum[b];
    }

    int cnt=0;
    rep(i,M){
        if(!uf.same(A[i],B[i])||sum[uf.find(A[i])]<C[i])cnt++;
    }
    cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 11776
import math
def sieve (n):
	prime = [0,0]
	prime += [1 for i in range(n-1)]
	ub = math.sqrt(n) + 1
	d = 2
	while d <= ub:
		if prime[d] == 0:
			d += 1
			continue
		prod = 2
		while d * prod <= n:
			prime[d*prod] = 0
			prod += 1
		d += 1
	return prime
prime = sieve(50000)
while 1:
	m,a,b = map(int,raw_input().split(" "))
	if (m,a,b) == (0,0,0):
		break
	rect_max = (0,0,0)
	q = m / 2
	while q >= 2:
		if prime[q] == 0:
			q -= 1
			continue
		p = min(m / q + 1, q)
		while p * b >= q * a:
			if prime[p] == 0 or p * q > m:
				p -= 1
				continue
			if rect_max[0] <= p*q:
				rect_max = (p*q,p,q)
			p -= 1
		q -= 1
	print rect_max[1], rect_max[2]

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

using namespace std;
using ll = long long;

ll solve() {
  ll H, W;
  cin >> H >> W;

  if (H == 1 || W == 1) {
    return 1;
  }

  return (H / 2 + H % 2) * (W / 2 + W % 2) + (H / 2) * (W / 2);
}

int main() {
  cout << solve() << endl;

  return 0;
}


Measured memory_bytes: 256
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)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n: usize,
        s: [i64; n],
    }
    let mut s = s;
    let mut time = 0;
    for j in 0..n {
        while s[j] % 2 == 0 && s[j] != 0 {
            s[j] /= 2;
            time+=1;
        } 
    }
    println!("{}", time);
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

bool in(ll y, ll x, ll h, ll w){
	return 0 <= y && y < h && 0 <= x && x < w;
}

int main(){
	ll h,w; cin >> h >> w;
	char s[55][55];
	rep(i,h) rep(j,w) cin >> s[i][j];
	char ans[55][55];
	rep(i,h) rep(j,w) ans[i][j] = '0';
	rep(i,h){
		rep(j,w){
			if(s[i][j]=='#'){
				rep(k,8){
					ll ny = i + dy[k];
					ll nx = j + dx[k];
					if(in(ny,nx,h,w)){
						if(ans[ny][nx]!='#') ans[ny][nx]++;
					}
				}
				ans[i][j] = '#';
			}
		}
	}
	rep(i,h){
		rep(j,w) cout << ans[i][j];
		cout << endl;
	}
}

Measured memory_bytes: 256
//                                              Question ki ma ki chut !!
#include<bits/stdc++.h>
using namespace std;
#define Going_supersonic ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(a) a.begin(),a.end()
#define allr(v) v.rbegin(),v.rend()
#define sz() size()
#define l() length()
#define lli long long int
#define ed endl
#define iv vector<lli>
#define bg() begin()
#define e() end()
#define ff first
#define ss second
lli sti(string s)
{
    lli num=0;
    lli p=1;
    for(lli it=s.l()-1;it>=0;p*=10)
        num+=(s[(it--)]-48)*p;
    return num;
}
lli n,m,cnt,mx,mn,l,sm,r;
map<pair<lli,lli>,lli> dp;
lli solve(iv &a,iv &b,lli n,lli w)
{
    //cout<<b[n]<<" "<<" "<<n<<" "<<w<<ed;
    if(n==0||w==0)
    {
        if(w>=a[n])
            return b[n];
        else
            return 0;
    }
    if(dp[{n,w}])
        return dp[{n,w}];
    if(w>=a[n]){
           return dp[{n,w}]=max(b[n]+solve(a,b,n-1,w-a[n]),solve(a,b,n-1,w));
    }
    else
    {
        return solve(a,b,n-1,w);
    }
}
int main(){
    Going_supersonic
    lli T=1;
    //cin>>T;
    while(T--){
            lli i,j,k,p,w;
            cin>>n>>w;
            iv a(n),b(n);
            lli dp[n+1][w+1];
            memset(dp,0,sizeof(dp));
            for(i=0;i<n;i++)
            {
                cin>>a[i]>>b[i];
            }
            for(i=1;i<=n;i++)
            {
                for(j=1;j<=w;j++)
                {
                    if(j>=a[i-1])
                    {
                        dp[i][j]=max(b[i-1]+dp[i-1][j-a[i-1]],dp[i-1][j]);
                    }
                    else
                    {
                        dp[i][j]=dp[i-1][j];
                    }
                }
            }
            cout<<dp[n][w];

    }

    return 0;
}


Measured memory_bytes: 82368