akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
vector<vector<int>>edge;
auto TopologicalSort(int n){
    vector<int>v(n,false);
    vector<int>out(n);
    int idx = n-1;
    function<void (int)>dfs = [&](int u) -> void{
        v[u] = true;
        for(int i = 0; i < edge[u].size();i++){
            int nv = edge[u][i];
            if(!v[nv])dfs(nv);
        }
        out[idx--] = u;
    };
    for(int i = 0; i < v.size();i++){
        if(!v[i])dfs(i);
    }
    return out;
}
signed main(){
    int n,m;
    cin >> n >> m;
    edge = vector<vector<int>>(n);
    vector<vector<int>>rev(n);
    rep(i,n+m-1){
        int x,y; cin >> x >> y;
        --x,--y;
        edge[x].push_back(y);
        rev[y].push_back(x);
    }
    auto v = TopologicalSort(n);
    vector<int>dp(n,0LL);
    for(auto e : v){
        rep(j,edge[e].size()){
            int nv = edge[e][j];
            cmax(dp[nv],dp[e]+1);
        }
    }
    vector<vector<int>>mp(n+m);
    rep(i,dp.size())mp[dp[i]].push_back(i);
    rep(i,dp.size()){
        if(dp[i] == 0LL) cout << 0 << endl;
        else {
            rep(j,rev[i].size()){
                int nv = rev[i][j];
                if(dp[i]-1 == dp[nv]){
                    cout << nv+1 << endl;
                }
            }
        }
    }
}




Measured memory_bytes: 23024
import Control.Monad
import Control.Applicative
import Data.List
import qualified Data.Map as Map
import Data.Array
import qualified Data.ByteString.Char8 as BC
import Data.Maybe
import qualified Data.Set as Set
import qualified Data.Sequence as Sq
import qualified Data.Map as Map
import qualified Data.IntMap as IMap
import Data.Sequence (ViewL(..),ViewR(..),(><),(<|),(|>),Seq)

bsreadInt :: BC.ByteString -> Int
bsreadInt = fst . fromJust . BC.readInt


main = do
    x <- readLn :: IO Int
    print $ head $ [i | i <- [1..100000] , i * (i+1) >= 2 * x]

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

int main() {
	int a, b, c;
	int res = 3;

	cin >> a >> b >> c;

	if (a == b | a == c | b == c) {
		if (a == b && b == c) res = 1;
		else res = 2;
	}
	cout << res << endl;
}



Measured memory_bytes: 888
// ※※※ 解答不能 ※※※
// 解き直し.
// ABC 133解説
// https://img.atcoder.jp/abc133/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const LL MOD = 1e9 + 7;

// 深さ優先探索(depth-first search).
// https://ja.wikipedia.org/wiki/深さ優先探索
// @param K: 色の数.
// @param G: グラフ.
// @param c: 探索する頂点番号.
// @param p: 探索する頂点の親頂点番号.
// @return : 着色可能数を返却.
LL dfs(LL K, const vector<vector<LL>> &G, LL c, LL p){

    // 1. 着色可能数設定.
    LL color;
    if(p == -1) color = K - 1;
    else        color = K - 2;
    
    // 2. グラフに着色していく.
    if(G[c].size() > K){
        return 0;
    }else{
        LL n = 1;
        for(auto e : G[c]){
            if(e == p) continue;
            n *= color;
            color--;
            n %= MOD;
        }
        for(auto e : G[c]){
            if(e == p) continue;
            n *= dfs(K, G, e, c);
            n %= MOD;
        }
        return n;
    }
}

int main() {
    
    // 1. 入力情報取得.
    LL N, K;
    scanf("%lld %lld", &N, &K);
    vector<vector<LL>> graph(N);
    for(LL i = 0; i < N - 1; i++){
        LL u, v;
        scanf("%lld %lld", &u, &v);
        u--, v--;
        // u -> v
        graph[u].push_back(v);
        // v -> u
        graph[v].push_back(u);
    }
    
    // 2. 塗り分け方を計算.
    LL ans = K * dfs(K, graph, 0, -1);
    ans %= MOD;
    
    // 3. 出力 ～ 後処理.
    printf("%lld\n", ans);
    return 0;
    
}

Measured memory_bytes: 11520
#include "bits/stdc++.h"
using namespace std;
 
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
 
typedef long long Int;
typedef vector<int> VI;
typedef pair<int, int> PII;
 
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const Int LINF = INF * (Int) INF;
const int MAX = 100007; 

const int MOD = 998244353;

int U[MAX];
VI G[MAX];

vector<PII> res;

int dfs(int v, int p)
{
    U[v] = 1;
    int c = 0;
    for(auto to: G[v])
    {
        if (to == p)
            continue;
        if (U[to] == 0)
        {
            c ^= dfs(to, v);
        }
        else
        {
            if (U[to] == 1)
            {
                c ^= 1;
                res.push_back(MP(v, to));
            }
        }
    }
    U[v] = 2;
    if (c == 1)
    {
        if (p != -1)
            res.push_back(MP(v, p));
        return 0;
    }
    else
    {
        if (p != -1)
            res.push_back(MP(p, v));
        return 1;
    }
}

int main(int argc, char* argv[])
{
	// freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);
    int n , m;
    cin >> n >> m;
    FOR(i,0,m)
    {
        int a , b;
        cin >> a >> b;
        --a;--b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    
    if (m % 2 == 1)
    {
        cout << -1 << endl;
        return 0;
    }
    dfs(0, -1);
    FOR(i,0,SZ(res))
    {
        cout << res[i].first + 1 << ' ' << res[i].second + 1 << endl;
    }

    // cerr << 1.0 * clock() / CLOCKS_PER_SEC << ' ' << eval(res) << endl;
}

Measured memory_bytes: 15988
#include <stdio.h>

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

    int i, tmp=1, ans=1;
    // for(i=1; i<N+1; i++) {

    // }

    while(tmp<N) {
        tmp *= 2;
        if(tmp>N) {
            ans = tmp/2;
        } else {
            ans = tmp;
        }
    }

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

    return 0;

}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int maxm = 1e6 + 10;
const int maxn = 3e5+10;
typedef long long ll;
struct node {
	int s, e, c, w, next;
}edge[maxn];
int head[maxn], len;
int n, q;
void init() {
	memset(head, -1, sizeof(head));
	len = 0;
}
void add(int s, int e, int c, int w) {
	edge[len].s = s;
	edge[len].e = e;
	edge[len].w = w;
	edge[len].c = c;
	edge[len].next = head[s];
	head[s] = len++;
}
int son[maxn], top[maxn], tid[maxn], fat[maxn], siz[maxn], dep[maxn], rak[maxn];
int dfx;
void dfs1(int x, int fa, int d) {
	siz[x] = 1, son[x] = -1, fat[x] = fa, dep[x] = d;
	for (int i = head[x]; i != -1; i = edge[i].next) {
		int y = edge[i].e;
		if (y == fa)
			continue;
		dfs1(y, x, d + 1);
		siz[x] += siz[y];
		if (son[x] == -1 || siz[y] > siz[son[x]])
			son[x] = y;
	}
}
void dfs2(int x, int c) {
	top[x] = c; tid[x] = ++dfx; rak[dfx] = x;
	if (son[x] == -1)
		return;
	dfs2(son[x], c);
	for (int i = head[x]; i != -1; i = edge[i].next) {
		int y = edge[i].e;
		if (y == fat[x] || y == son[x])
			continue;
		dfs2(y, y);
	}
}
int cnt, root[maxn], ls[maxn * 40], rs[maxn * 40], num[maxn * 40], val[maxn * 40];
struct C {
	int color, dis;
}a[maxn];
void build(C k, int l, int r, int& i) {
	num[++cnt] = num[i] + 1, val[cnt] = val[i] + k.dis, ls[cnt] = ls[i], rs[cnt] = rs[i];
	i = cnt;
	if (l == r)
		return;
	int mid = l + r >> 1;
	if (k.color <= mid)
		build(k, l, mid, ls[i]);
	else
		build(k, mid + 1, r, rs[i]);
}
C query(int u, int v, int k, int l, int r) {
	if (l == r) {
		return { num[v] - num[u],val[v] - val[u] };
	}
		
	int mid = l + r >> 1;
	if (k <= mid)
		return query(ls[u], ls[v], k, l, mid);
	else
		return query(rs[u], rs[v], k, mid + 1, r);
}
int solve(int cr, int dis, int x, int y) {
	C ans = { 0,0 };
	int sum = 0;
	while (top[x] != top[y]) {
		if (dep[top[x]] < dep[top[y]])
			swap(x, y);
		C t = query(root[tid[top[x]] - 1], root[tid[x]], cr, 1, n);
		sum += val[root[tid[x]]] - val[root[tid[top[x]] - 1]];
		ans.color += t.color, ans.dis += t.dis;
		x = fat[top[x]];
	}
	
	if (x != y) {
		if (dep[x] < dep[y])
			swap(x, y);
		C t = query(root[tid[son[y]] - 1], root[tid[x]], cr, 1, n);
		sum += val[root[tid[x]]] - val[root[tid[son[y]] - 1]];
		ans.color += t.color, ans.dis += t.dis;
	}
	//cout << sum << " " << ans.color << " " << ans.dis << endl;
	return sum - ans.dis + ans.color * dis;
}
void dfs(int l, int r, int i) {
	if (l == r) {
		printf("%d#%d ", num[i], val[i]);
		return;
	}
	int mid = l + r >> 1;
	dfs(l, mid, ls[i]);
	dfs(mid + 1, r, rs[i]);
}
int main() {
	scanf("%d%d", &n, &q);
	init();
	for (int i = 1, x, y, c, d; i < n; i++) {
		scanf("%d%d%d%d", &x, &y, &c, &d);
		add(x, y, c, d);
		add(y, x, c, d);
	}
	dfs1(1, 0, 1);
	dfs2(1, 1);
	for (int i = 0; i < len; i += 2) {
		int x = edge[i].e;
		int y = edge[i].s;
		if (dep[x] < dep[y])
			swap(x, y);
		a[tid[x]] = { edge[i].c, edge[i].w };
	}
	for (int i = 2; i <= dfx; i++) {
		root[i] = root[i - 1];
		build(a[i], 1, n, root[i]);
		//dfs(1, n, root[i]);
	}
	while (q--) {
		int x, y, u, v;
		scanf("%d%d%d%d", &x, &y, &u, &v);
		printf("%d\n", solve(x, y, u, v));
	}
}

Measured memory_bytes: 59520
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

ll N, A, B, C, D;
map<ll,ll> mp;
ll f(ll now){
  if(now == 0) return 0;
  if(now == 1) return D;
  if(mp.count(now)>0) return mp[now];
  ll left2 = (now/2)*2;
  ll right2 = ((now+1)/2)*2;
  ll left3 = (now/3)*3;
  ll right3 = ((now+2)/3)*3;
  ll left5 = (now/5)*5;
  ll right5 = ((now+4)/5)*5;
  ll res = 1e18;
  if(now < res/D) res = now * D;
  chmin(res, abs(left2-now)*D+A+f(left2/2));
  chmin(res, abs(right2-now)*D+A+f(right2/2));
  chmin(res, abs(left3-now)*D+B+f(left3/3));
  chmin(res, abs(right3-now)*D+B+f(right3/3));
  chmin(res, abs(left5-now)*D+C+f(left5/5));
  chmin(res, abs(right5-now)*D+C+f(right5/5));
  mp[now] = res;
  return res;
}

int main(){
  int T; cin >> T;
  rep(t,T){
    cin >> N >> A >> B >> C >> D;
    cout << f(N) << endl;
    mp.clear();
  }
  return 0;
}


Measured memory_bytes: 4436
#include <stdio.h>
int main(){
	int a,b,x;
	scanf("%d %d %d",&a,&b,&x);
	if(a>x){
		printf("NO");
		return 0;
	}
	if(a+b<x){
		printf("NO");
		return 0;
	}else{
		printf("YES");
		return 0;
	}
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			char[] s = scanner.next().toCharArray();
			switch (s[s.length - 1]) {
			case '0':
			case '1':
			case '6':
			case '8':
				System.out.println("pon");
				break;
			case '2':
			case '4':
			case '5':
			case '7':
			case '9':
				System.out.println("hon");
				break;
			default:
				System.out.println("bon");
			}
		}
	}
}


Measured memory_bytes: 35560
using System;

namespace ABC_149_A_Csharp_ver
{
    class Program
    {
        static void Main(string[] args)
        {
            var word = Console.ReadLine().Split(' ');
            string S = word[0];
            string T = word[1];
            Console.WriteLine(T + S);
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
N=int(input())
li=list(map(int,input().split()))
two_count=0
four_count=0
for n in range(N):
    if li[n]%4==0:
        four_count+=1
    elif li[n]%2==0:
        two_count+=1
S=max(four_count*2+1,four_count*2+two_count)
if S>=N:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,int> pii;
#define x first
#define y second
#define mp make_pair
#define pb push_back
template <typename TYPE> inline void chkmax(TYPE &x,TYPE y){x<y?x=y:0;}
template <typename TYPE> inline void chkmin(TYPE &x,TYPE y){y<x?x=y:0;}
template <typename TYPE> void readint(TYPE &x)
{
    x=0;int f=1;char c;
    for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
    for(;isdigit(c);c=getchar())x=x*10+c-'0';
    x*=f;
}
const int MAXN=205;

int n;
ll a[MAXN];
char b[MAXN];
ll c[MAXN];
void insert(ll x)
{
	for(int i=60;i>=0;--i)
		if((1ll<<i)&x)
		{
			if(!c[i]){c[i]=x;break;}
			x^=c[i];
		}
}
bool query(ll x)
{
	for(int i=60;i>=0;--i)
		if((1ll<<i)&x)
		{
			if(!c[i])return 0;
			x^=c[i];
		}
	return 1;
}
void solve()
{
	memset(c,0,sizeof(c));
	readint(n);
	for(int i=1;i<=n;++i)readint(a[i]);
	scanf("%s",b+1);
	for(int i=n;i;--i)
		if(b[i]-'0'==0)insert(a[i]);
		else if(!query(a[i])){printf("1\n");return;}
	printf("0\n");
}

int main()
{
	int T;
	readint(T);
	while(T--)solve();
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
#define REP(i,n) for (int i = 0; i <(n); ++i)
//debug 
#ifdef _DEBUG
#define debug(var)  do{cout << #var << " :";view(var);}while(0)
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }


int main(){
  string s;
  cin >> s;
  int cnt = 0;
  REP(i,s.size()){
    if(s[i] == '1') cnt++;
  }
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long sum=0,i,n;

   cin>>n;
   long long a[n];
   for(i=0;i<n;i++)
   {
       cin>>a[i];
   }
    for(i=1;i<n;i++)
   {
       if(a[i]<a[i-1])
       {
           sum=sum+a[i-1]-a[i];
           a[i]=a[i-1];
       }
   }
    cout<<sum<<endl;
}


Measured memory_bytes: 5196
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

string IntegerToNbaseString(Int base, Int target, char start_alphabet) {
    string s = "";
    while (target != 0) {
        Int quo = target / base;
        Int rem = target % base;
        if (rem == 0) {
            rem = base;
            --quo;
        }
        s += char(start_alphabet + rem - 1);
        target = quo;
    }
    reverse(s.begin(), s.end());
    return s;
}

int main(void) {
    Int n;
    cin >> n;
    cout << IntegerToNbaseString(26, n, 'a') << endl;
    return 0;
}



Measured memory_bytes: 3628
using System;

namespace MyProgram{
    class AtCoder{
        public static void Main(string[] args){
            long [] input = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
            long A = input[0];
            long B = input[1];
            long K = input[2];
            if(A>=K){
                A -= K;
            }else{
                B -= K-A;
                if(B<0){
                    B=0;
                }
                A=0;
            }
            Console.WriteLine("{0} {1}",A,B);
        }
    }
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  int n, k;
  cin >> n >> k;
  vi h(n);
  rep(i,n) cin >> h[i];
  sort(all(h));
  int ans = inf;
  for(int i = 0; i+k-1 < n; i++) {
    int mn = h[i];
    int mx = h[i+k-1];
    ans = min(ans, mx - mn);
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<bool> inc;
  rep(i, n-1) {
    int tmp = a[i+1]-a[i];
    if (tmp)
      inc.push_back(tmp > 0);
  }
  int ans = 1;
  for (int i = 1; i < inc.size(); i++) {
    if (inc[i] != inc[i-1]) {
      ans++;
      i++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
import sys
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(input())
A = list(map(int, input().split()))

NUM = defaultdict(int)

for a in A:
    NUM[a] += 1

s = 0
for v in NUM.values():
    s += v * (v - 1) // 2

#print(s)

ans = []
for a in A:
    r = NUM[a]
    t = s - (r - 1)
    ans.append(t)

print("\n".join(map(str, ans)))


Measured memory_bytes: 39344
def cmb(n, r):
    import math
    if n < r:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def solve(N, As):
    A_map = [0] * (N + 1)

    # make map
    for A in As:
        A_map[A] += 1

    # calc 'not remove' cmb
    g = 0
    for am in A_map:
        g += cmb(am, 2)

    # print result
    for A in As:
        if A > 0:
            print(g - (A_map[A] - 1))


if __name__ == '__main__':
    N = int(input())
    As = [int(i) for i in input().split()]
    solve(N, As)


Measured memory_bytes: 26140
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>


using namespace std;

long long res;

int main(){

    int n,i,j,f,r,s,m;
    cin>>n;

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

    sort(l,l+n);

        for(i=n-1;i>1;i--) {
            f = 0;
            r = i-1;
            while(r>f){
                if(l[r]+l[f]>l[i]){
                    res += r-f;
                    r--;
                }
                else {
                    f++;
                }
            }
        }

   
    cout<<res;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

// 素数と個数を求める
vector<pair<ll,ll>> factorize(ll n){
  vector<pair<ll,ll>> res;
  for(ll i=2L; i*i<=n; ++i){
    if (n%i) continue;
    res.emplace_back(i,0);
    while(n%i == 0){
      n /= i;
      res.back().second++;
    }
  }
  if(n != 1) res.emplace_back(n,1L);
  return res;
}

int main(){
	ll X; cin>>X;

	rp(a, -200, 200+1){ // [-200,200]
		ll a5 = (ll)a*a*a*a*a;
		ll b5 = a5 - X;
		ll sign = 1;
		if(b5 < 0){
			b5 = -b5;
			sign = -1;
		}

		vector<pair<ll,ll>> pc = factorize(b5);

		ll b = 1;
		if(b5 == 0) b = 0;
		for(auto x:pc){
			ll p,c; tie(p,c) = x;
			if(c == 5) b *= p;
			else break;
		}

		if(b*b*b*b*b == b5){
			cout<<a<<" "<<sign*b<<endl;
			break;
		}

	}

}


Measured memory_bytes: 3608
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef long long LL;
LL a, b, ans, x, cheng;
LL q;

int main()
{
	scanf("%lld", &q);
	while(q--)
	{
		scanf("%lld %lld", &a, &b);
		cheng = a * b;
		x = sqrt(a * b);
		if(x * (x + 1) < cheng) ans = x * 2 - 1;
		else if(x * x == cheng)
		{
			if(a != b) ans = (x - 1) * 2 - 1;
			else ans = (x - 1) * 2;
		}
		else ans = (x - 1) * 2;
		printf("%lld\n", ans);
	}
	return 0;
}

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

public class Main {
	public static void main(String[] args) {
		// The first input line gives us the size of our graph
		Scanner in = new Scanner(System.in);
		int n = Integer.parseInt(in.nextLine());
		// Initialize our matrix
		int[][] weights = new int[n][n];
		for (int i = 0; i < n; i++) {
			
			String[] row = in.nextLine().split(" ");
			// Now that we have the row, we will initialize said row in the matrix
			// For some reason, aizu includes a space before the line (strange), so the index of row for column j will be j+1
			for (int j = 0; j < n; j++) {
				weights[i][j] = Integer.parseInt(row[j+1]);
			}
		}
		Main test = new Main();
		System.out.println(test.MSTbuilder(weights, n));
		
	}
	
	public int MSTbuilder(int[][] weights, int size) {
		int weight = 0;
		boolean[] mstSet = new boolean[size];
		int max = Integer.MAX_VALUE;
		int[] keyVals = new int[size];
		// First vertex gets picked first
		keyVals[0] = 0;
		for (int i = 1; i < size; i++) {
			keyVals[i] = max;
			mstSet[i] = false;
		}
		for (int i = 0; i < size; i++) {
			int u = getMin(keyVals, mstSet);
			mstSet[u] = true;
			for (int j = 0; j < size; j++) {
				// If the value in the weights is -1, then the vertices are not connected
				if (weights[u][j] == -1) {}
				// if we've already seen this vertex, skip over it
				else if (mstSet[j]) {}
				else {
					keyVals[j] = Math.min(keyVals[j], weights[u][j]);
				}
			}
		}
		for (int i : keyVals) {
			weight += i;
		}
		return weight;
	}
	
	// Returns the index of the value with the smallest number in an array that has not already been visited
	public int getMin(int[] nums, boolean[] visited) {
		int minVal = Integer.MAX_VALUE;
		int minIndex = -1;
		for (int i = 0; i < nums.length; i++) {
			if (nums[i] < minVal && !visited[i]) {
				minIndex = i;
				minVal = nums[i];
			}
		}
		return minIndex;
	}
}



Measured memory_bytes: 29640
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

h,w = MI()
a = LS(h)

# pprint(a)

rc = []
rr = []

for i in range(h):
    r = a[i]
    if r == ['.']*len(a[0]):
        rr.append(i)
# print(rr)

na = []
for i in range(h):
    if i not in rr:
        na.append(a[i])
# pprint(na)

for i in range(w):
    c = mycol(na,i)
    if c == ['.']*len(na):
        rc.append(i)
# print(rc)

ans = []
for i in range(len(na)):
    row = na[i]
    new_row = []
    for j in range(len(na[0])):
        if j not in rc:
            new_row.append(row[j])
    ans.append(new_row)
# pprint(ans)

for i in range(len(ans)):
    myoutput(ans[i],space=False)

Measured memory_bytes: 77256
#include<iostream>
#include<algorithm>
using namespace std;
int n,k,a[1000],b[1000],c[100010],s[1000],sum,cnt,ans;
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;++i)
		cin>>a[i],sum+=a[i];
	for(int i=1;i*i<=sum;++i)
		if(sum%i==0)
			c[++cnt]=i,c[++cnt]=sum/i;
	if(c[cnt]==c[cnt-1])
		cnt--;
	sort(c+1,c+cnt+1);
//	for(int i=1;i<=cnt;++i)
//		cout<<c[i]<<" ";
	for(int i=cnt;i>=1;--i)
	{
		int x=c[i];
		for(int i=1;i<=n;++i)
			b[i]=a[i]%x;
		sort(b+1,b+n+1);
		for(int i=1;i<=n;++i)
			s[i]=s[i-1]+b[i];
		for(int i=1;i<=n;++i)
			if(s[i]==(n-i)*x-(s[n]-s[i]))
			{
				if(k>=s[i])
				{
					cout<<x<<endl;
					return 0;
				}
				else
					goto xx;
			}
		xx:;
	}
	cout<<1<<endl;
	return 0;
}

Measured memory_bytes: 256
n,k,q=map(int,input().split())
point=[]
for i in range(n):
    point.append(k-q)
for i in range(q):
    a=int(input())
    point[a-1]+=1

for i in range(n):
    if point[i]>0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 7916
N,A,B = list(map(int,input().split()))
S = input()
kokunai = 0
kaigai = 0
cnt = 0
for s in S:
    if s == "a":
        if cnt < A + B:
           print("Yes")
           cnt += 1
        else:
            print("No")
    
    elif s == "b":
        kaigai += 1
        if cnt < A + B and kaigai <= B:
            print("Yes")
            cnt += 1
        else:
            print("No")
    else:
        print("No")
   

Measured memory_bytes: 9268
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
	string S;
	cin >> S;
	ll ans = 0;
  	ll countw = 0;
  	ll count = 0;
  	for(int i = 0; i < S.size(); ++i){
      if (S[i] == 'W') countw++;
        
    }
  	for(int i = 0; i < S.size(); ++i){
      if (S[i] == 'W') {
        ans+=i - count;
        ++count;
      }
      if(count == countw) break;
      
    }
  	
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<long long, long long>;
const long long INF = 1001001001;
const long long MOD = 1000000007;
const double EPS = 1e-10;
struct Edge { int from, to; long long cost; };
using Graph = vector<vector<Edge>>;

template<typename T = long long>
T mod_pow(T a, T x, T md) {
    T res = 1;
    while(x) {
        if(x & 1) res = res * a % md;
        a = a * a % md;
        x >>= 1;
    }
    return res;
}

long long inv_com(int n, int r, long long md) {
    if(n - r < r) r = n - r;
    long long x = 1, y = 1;
    for(int i = 2; i <= r; i++) x = (x * i) % md;
    for(int i = n - r + 1; i <= n; i++) y = (y * i) % md;
    return y * mod_pow(x, md - 2, md) % md;
}

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

    int x,y;
    cin>>x>>y;
    if((x+y)%3){
        cout<<0<<endl;
        return 0;
    }
    int z=0;
    for(;;z++){
        int tx=x-z;
        int ty=y-2*z;
        if(tx<0||ty<0){
            cout<<0<<endl;
            return 0;
        }
        if(tx==ty*2)break;
    }
    cout<<inv_com((x+y)/3,z,MOD)<<endl;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <cstring>

using namespace std;

#define MOD (100000)

int memo[128][128][2];
int x, y;

int countWay(int ny, int nx, int dir)
{
	if (ny >= y - 1 && nx >= x - 1) return (1);
	else if (ny > y - 1 || nx > x - 1) return (0);
	
	if (memo[ny][nx][dir] >= 0) return (memo[ny][nx][dir]);
	
	return (memo[ny][nx][dir] = (countWay(ny + 1 + (dir != 1), nx, 1) + countWay(ny, nx + 1 + (dir != 0), 0)) % MOD);
}

int main()
{
	while (scanf("%d %d", &x, &y), y){
		memset(memo, -1, sizeof(memo));
		printf("%d\n", (countWay(0, 1, 0) + countWay(1, 0, 1)) % MOD);
	}
	
	return (0);
}

Measured memory_bytes: 1172
while 1:
    m,n=map(int,input().split())
    if m==0:break
    a,i,c=list(range(1,m+1)),0,0
    while i<n:
        i+=1
        b,f=input(),0
        if m<2:continue
        if i%15==0:
            if b!='FizzBuzz':
                del a[c]
                f=1
        elif i%5==0:
            if b!='Buzz':
                del a[c]
                f=1
        elif i%3==0:
            if b!='Fizz':
                del a[c]
                f=1
        elif b!=str(i):
            del a[c]
            f=1
        if f:m-=1
        else:c+=1
        c%=m
    print(*a)

Measured memory_bytes: 7932
//#define _CRT_SECURE_NO_WARNINGS
//#include <bits/stdc++.h>
#include "bits/stdc++.h"

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

#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
#define MAX_N (100001)
typedef long long ll;

using namespace std;



signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b, c, d; cin >> a >> b >> c >> d;
	while (0 < a && 0 < c) {
		a -= d;
		c -= b;
	}
	if (c <= 0)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }
template<class T> inline void printYesNo(const T& t) { cout << (t ? "Yes" : "No") << CRLF; }
template<class T = int64_t> T modpow(T N, T P, T M) { T ret{1}; N %= M; while (P) { if (P & 0x01) { ret *= N; ret %= M; } P >>= 1; N *= N; N %= M; } return ret; }

/** code for assert debug begin */
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }else{ ; }
/** code for assert debug end */

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  int K, T; cin >> K >> T;
  vector<int> A(T);
  for (auto& a : A) { cin >> a; }
  auto m = *boost::max_element(A);
  if (m < (K+1) / 2) {
    cout << 0 << CRLF;
    return;
  }
  auto okDay = (K-m)*2+1;
  auto ans = K - okDay;
  cout << ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    reverse(a.begin(),a.end());
    for(int i=0;i<n;i++){
        cout << a[i];
        if(i==n-1){
            cout<<endl;
            return 0;
        }else{
            cout<< " ";
        }
    }
return 0;
}


Measured memory_bytes: 3084
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

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; }
typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

lint readL(){
  lint res;
#ifdef ONLINE_JUDGE
  scanf("%I64d",&res);
#else
  scanf("%lld",&res);
#endif
  return res;
}
void printL(lint res){
#ifdef ONLINE_JUDGE
  printf("%I64d",res);
#else
  printf("%lld",res);
#endif
}

//const int INF=5e8;
int n,m;
int ar[100005];

map<int,int> cnt[100005];
int main(){
  cin>>n>>m;
  REP(i,n){
    cin>>ar[i];
    cnt[ar[i]%m][ar[i]]++;
  }
  int res=0;
  REP(i,m/2+1){
    if(i==0 || i*2==m){
      int all=0;
      for(auto e:cnt[i]){
        all+=e.sc;
      }
      res+=all/2;
    }else{
      int odd1=0,odd2=0;
      int tot1=0,tot2=0;
      for(auto e:cnt[i]){
        tot1+=e.sc;
        if(e.sc&1) ++odd1;
      }
      for(auto e:cnt[m-i]){
        tot2+=e.sc;
        if(e.sc&1) ++odd2;
      }
      if(odd1>odd2){
        swap(odd1,odd2);
        swap(tot1,tot2);
      }
      while(odd2-odd1>=2 && (tot1-odd1)>=2){
        res+=2;
        odd2-=2;
        tot2-=2;
        tot1-=2;
      }
      res+=(tot1-odd1)/2+(tot2-odd2)/2+min(odd1,odd2);
    }
  }
  cout<<res<<endl;
  return 0;
}





Measured memory_bytes: 10112
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let mut H = read![[usize]];

    H[0] -= 1;

    for i in 0..N - 1 {
        if H[i] < H[i + 1] {
            H[i + 1] -= 1;
        }
    }

    let ok = H.windows(2).all(|w| w[0] <= w[1]);

    println!("{}", if ok { "Yes" } else { "No" })
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ss second
#define ff first
ll dp[101][100001];
ll n,w;
ll s[101][3];
ll go(int idx,int rem)
{
    if(idx>=n)
        return 0;
    ll &ret=dp[idx][rem];
    if(ret!=-1)
        {return ret;}
    ret=0;
        if(rem-s[idx][0]>=0)
       {ret=max(ret,s[idx][1]+go(idx+1,rem-s[idx][0]));
      // cout<<idx<<' '<<rem<<' '<<go(idx+1,rem-s[idx][0])<<endl;
       }
    ret=max(ret,0LL+go(idx+1,rem));
    //cout<<idx<<' '<<rem<<' '<<ret<<endl;
return ret;
}
int main(){
    memset(dp,-1,sizeof dp);
    cin>>n>>w;
    for(int i=0;i<n;i++)
        scanf("%lld%lld",&s[i][0],&s[i][1]);

    go(0,w);
    cout<<dp[0][w];
}


Measured memory_bytes: 79104
#include <iostream>
#include <vector>
#include <tuple>

using vec = std::vector<int>;
using Graph = std::vector<vec>;
using edge = std::tuple<int, int, int>;

Graph calc_minimum_dists(Graph g)
{
    Graph min_dist = g;
    int N = g.size();
    for (int k = 0; k < N; k++)
        for (int i = 0; i < N; i++)
            for (int j = 0; j < N; j++)
                min_dist[i][j] =
                    std::min(min_dist[i][j], min_dist[i][k] + min_dist[k][j]);

    return min_dist;
}

int calc_unuse_edge_count(
    Graph &d, std::vector<edge> &es
)
{
    int N = d.size();
    int unuse_edge_count = 0;
    for (auto e : es) {
        int a = std::get<0>(e);
        int b = std::get<1>(e);
        int c = std::get<2>(e);

        if (d[a][b] != c)
            unuse_edge_count += 1;
    }
    return unuse_edge_count;
}

int main()
{
    int N, M;
    std::cin >> N >> M;
    Graph d(N, vec(N, 1e9));
    std::vector<edge> e;

    for (int i = 0; i < N; i++)
        d[i][i] = 0;

    for (int i = 0; i < M; i++) {
        int a, b, c;
        std::cin >> a >> b >> c;
        a--; b--;
        d[a][b] = d[b][a] = c;
        e.emplace_back(a, b, c);
    }

    Graph min_dist = calc_minimum_dists(d);
    std::cout << calc_unuse_edge_count(min_dist, e) << std::endl;
    return 0;
}

Measured memory_bytes: 384
N = int(input())
S = list(input())
list = [0]*10
code_list = []

#for i in range(9):
#    for j in range(len(S)):
#        if str(i) == S[j]:
#            list[i] = list[i] + 1

def check_match(word,str_cnt):
    global S
    ret = -1

    for i in range(str_cnt,len(S)):
        if S[i] == word:
            ret = i
            break

    return ret

#貪欲法
password = [0]*3
ans_cnt = 0
for num in range(1000):
    ret = 0
    password = str(num)
    password = password.zfill(3)

    ret = check_match(password[0],ret)
    if ret != -1:
        ret = check_match(password[1],ret+1)
        if ret != -1:
            ret= check_match(password[2],ret+1)
            if ret != -1:
                ans_cnt = ans_cnt + 1

print (ans_cnt)
#print (password[1])




Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

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

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int n,s,w,q;

void solve(){
	int a[100010],pow10[100010] = {1};
	int g = s;
	for(int i = 0;i < n;i++){
		a[i] = (g / 7) % 10;
		if(g % 2 == 0) g /= 2;
		else g = ((g / 2) ^ w);
	}
	for(int i = 1;i < n;i++) pow10[i] = pow10[i - 1] * 10 % q;
	map<int,int> cnt;
	if(a[0]) cnt[0]++;
	int ans = 0,sum = 0;
	for(int i = 0;i < n;i++){
		sum = (sum * 10 + a[i]) % q;
		int tmp = sum * pow10[n - i - 1] % q;
		if((q != 2 && q != 5) || a[i] % q == 0) ans += cnt[tmp];
		if(i == n - 1 || a[i + 1]) cnt[tmp]++;
	}
	cout << ans << endl;
}

signed main(){
	while(cin >> n >> s >> w >> q,n) solve();
}


Measured memory_bytes: 10292
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ
int n; char s[333][333];
int main()
{
	scanf("%d",&n);
	map<int,int> ms;
	for(int i=0;i<n;++i)
		for(int j=0;j<n;++j)
			ms[i-j]++;
	for(int i=0;i<n;++i)
		cin>>s[i];
	int ans=0;
	for(auto a:ms)
	{
		int x=a.fi,gg=1;
		for(int p=0;p<n;++p)
			for(int q=0;q<n;++q)
				if(s[p][q]!=s[(q+x+n)%n][(p+n-x)%n])
					gg=0;
		ans+=gg*a.se;
	}
	cout<<ans<<"\n";
}


Measured memory_bytes: 384
#include <cstdio>

int main()
{
    int a, b, d, r;
    double f;
    scanf("%d %d", &a, &b);
    d = a / b;
    r = a % b;
    f = (double)a / b;
    printf("%d %d %.5f\n", d, r, f);
}


Measured memory_bytes: 2708
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello{
    public static void Main(){
        var input = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToList();
        var n = input[0];
        var m = input[1];
        var h = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToList();
        var good = new List<bool>(n);
        for(var i = 0; i < n; ++i){
            good.Add(true);
        }

        for(var i = 0; i < m;++i){
            var a_b = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToList();
            if(h[a_b[0] - 1] <= h[a_b[1] - 1]){
                good[a_b[0] - 1] = false;
            }
            
            if(h[a_b[1] - 1] <= h[a_b[0] - 1]){
                good[a_b[1] - 1] = false;
            }
        }
        
        var ret = good.Where(x => x).ToList();
        
        Console.WriteLine(ret.Count);
    }
}


Measured memory_bytes: 33416
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (int i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (int i = x.size()-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define fst first
#define scd second
#define nextline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    cout<<max(c - (a - b), 0)<<endl;

    return 0;
}


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

int main(){
	int i,n,a,b;
	long apoint=0,bpoint=0;
	while(1){
		cin >> n;
		if(!n) break;
		for(i=0;i<n;i++){
			cin >> a;
			cin >> b;
			if(a>b){apoint+=a;apoint+=b;}
			else if(b>a){bpoint+=a;bpoint+=b;}
			else {apoint+=a;bpoint+=b;}
		}
		cout << apoint <<' ' << bpoint << endl;
		apoint=0;bpoint=0;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,ma=0,ans=0;
char ch;
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> ch;
		if (ch == 'I') ans++;
		else ans--;
		if (ans > ma) ma = ans;
	}
	cout << ma;
	return 0;
}

Measured memory_bytes: 256
from sys import exit

A, B = [int(x) for x in input().split()]

x = -(-A // 0.08)
y = B // 0.1

min_result = int(max(x, y))

while int(min_result * 0.08) <= A or int(min_result * 0.1) <= B:
    if int(min_result * 0.08) == A and int(min_result * 0.1) == B:
        print(int(min_result))
        exit()
    min_result += 1

print(-1)


Measured memory_bytes: 9132
#include <iostream>

using namespace std;

int A, B, C;

int main(void) {

	cin >> A >> B;

	bool ans = false;
	
			for (int k = 1; k <= 3; k++) {
				if ((A*B*k) % 2 == 1) { ans = true; }
			}
		

	if (ans) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }
	//system("pause");
	return 0;
}

Measured memory_bytes: 256