akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES 
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <math.h>
#include <unordered_set>
#include <iomanip>
#include <cmath>
#include <set>
#include <locale>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
ll Lgcd(ll a, ll b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
ll Llcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
using Graph = vector<vector<int>>;
//cout << fixed << setprecision(6);
//cout << setfill('0') << right << setw(2);


int main() {
	int n, m, p[10], ans = 0;
	vector<int> v[10];
	cin >> n >> m;
	rep(i, m) {
		int k; cin >> k;
		rep(j, k) {
			int l; cin >> l;
			v[i].push_back(l);
		}
	}
	rep(i, m) cin >> p[i];


	int pattern = (int)pow(2, n);

	rep(i, pattern) {
		bool f = true;
		rep(j, m) {
			int c = 0;
			rep(k, v[j].size()) if (i >> (v[j][k] - 1) & 1) c++;
			if (c % 2 != p[j]) f = false;
		}
		if (f) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
MOD = 10**9+7

def modpow(base, pow, mod):
  res = 1
  while pow > 0:
    if pow & 1:
      res = res * base % mod
    base = base**2 % mod
    pow >>= 1
  return res

def modmul(a, b, mod):
  return a*b % mod

def solve(h,w,a,b):
  fact = [0]*(h+w+1)
  fact[0] = 1
  fact_inv = [0]*(h+w+1)
  fact_inv[0] = 1
  for i in range(1, h+w):
    fact[i] = fact[i-1]*i % MOD
    fact_inv[i] = modpow(fact[i], MOD-2, MOD)

  ans = 0
  for col_idx in range(b, w):
    before_checkpoint = modmul(modmul(fact[h-a-1+col_idx], fact_inv[h-a-1], MOD), fact_inv[col_idx], MOD)
    from_checkpoint = modmul(modmul(fact[(a-1) + (w-col_idx-1)], fact_inv[w-col_idx-1], MOD), fact_inv[a-1], MOD)
    ans = (ans + modmul(before_checkpoint, from_checkpoint, MOD)) % MOD

  return ans

if __name__ == "__main__":
  h,w,a,b = map(int, input().split())
  print(solve(h,w,a,b))


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

int main() {
  int N, D;
  cin >> N >> D;
  int count = 0; 
  for (int i = 0; i < N; ++i) {
    int x, y;
    cin >> x >> y;
    double dist = sqrt(pow(x,2)+pow(y,2));
    if (dist <= D) {
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3576
//package atcoder;
 
import java.util.*;
//import java.math.BigDecimal;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		for(int i=0;i<3;i++) {
		System.out.print(S.charAt(i));
		}
	}
}

Measured memory_bytes: 35668
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split();
	long MaxSum(List<long> a) => a.Where(i => i >= 0).Sum();
	bool Good(List<long> a) => a.Any(i => i >= 0);
	long ans;
	List<int> del = new List<int>();
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		WriteLine(ans);
		WriteLine(del.Count);
		foreach (var x in del) WriteLine(x + 1);
		Out.Flush();
	}
	void Solve()
	{
		var N = F;
		var a = G;
		var ev = new List<long>(N / 2);
		var od = new List<long>(N / 2);
		for (var i = 0; i < N; i++) if (i % 2 == 0) ev.Add(a[i]); else od.Add(a[i]);
		bool gev = Good(ev), god = Good(od);
		if (!gev && !god)
		{
			var m = ans = a.Max();
			int i = 0, j = N;
			while (a[i] != m) i++;
			for (var k = 0; k < i; k++) { del.Add(0); j--; }
			while (j > 1) del.Add(--j);
			return;
		}
		long mev = MaxSum(ev), mod = MaxSum(od);
		ans = Max(mev, mod);
		var l = new LinkedList<bool>();
		if (mev >= mod && gev) for (var i = 0; i < N; i++) l.AddLast(i % 2 == 0 && ev[i / 2] >= 0);
		else for (var i = 0; i < N; i++) l.AddLast(i % 2 == 1 && od[i / 2] >= 0);
		while (l.Count > 2)
		{
			var n = l.First;
			if (!n.Value) { del.Add(0); l.RemoveFirst(); }
			else if (!l.Last.Value) { del.Add(l.Count - 1); l.RemoveLast(); }
			else if (n.Next.Next.Value)
			{
				del.Add(1);
				l.RemoveFirst();
				l.RemoveFirst();
			}
			else
			{
				del.Add(2);
				l.Remove(n.Next);
				l.Remove(n.Next);
			}
		}
		if (l.Count > 1) del.Add(l.First.Value ? 1 : 0);
	}
}


Measured memory_bytes: 13684
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define pie 3.141592653589793238462643383279
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y, int m) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y, int m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int n;
P x[4010];
int a[2010], b[2010];
int cnt1[2010][2010], cnt2[2010][2010];
bool bl1[2010], bl2[2010];
int d[4010][2010];

signed main() {
	cin >> n;
	for (int i = 1; i <= 2 * n; i++) {
		char c; int p; cin >> c >> p;
		if (c == 'W')a[p] = i, x[i] = make_pair(p, 0);
		else b[p] = i, x[i] = make_pair(p, 1);
	}
	for (int i = 2 * n; i >= 1; i--) {
		if (x[i].second == 0) {
			int cnt = 0;
			for (int j = 1; j < x[i].first; j++)if (bl1[j])cnt++;
			for (int j = 0; j <= n; j++) {
				if (bl2[j])cnt++;
				cnt1[x[i].first][j] = cnt;
			}
			bl1[x[i].first] = true;
		}
		else {
			int cnt = 0;
			for (int j = 1; j < x[i].first; j++)if (bl2[j])cnt++;
			for (int j = 0; j <= n; j++) {
				if (bl1[j])cnt++;
				cnt2[x[i].first][j] = cnt;
			}
			bl2[x[i].first] = true;
		}
	}
	for (int i = 0; i <= 2 * n; i++)for (int j = 0; j <= n; j++)d[i][j] = 1000000000;
	d[0][0] = 0;
	for (int i = 1; i <= 2 * n; i++) {
		for (int j = 0; j <= min(i - 1, n); j++)d[i][j] = min(d[i][j], d[i - 1][j] + cnt2[i - j][j]);
		for (int j = 1; j <= min(i, n); j++)d[i][j] = min(d[i][j], d[i - 1][j - 1] + cnt1[j][i - j]);
	}
	cout << d[2 * n][n] << endl;
}

Measured memory_bytes: 126336
#include <iostream>
#include <cstdio>
#define inv2 500000004
#define Base 2001
#define Maxx 4005
#define Mod 1000000007ll
#define ll long long
using namespace std;
int n;
ll ans,a[200010],b[200010],f[4010][4010],g[4010][4010];

int main() {
	scanf("%d",&n);
	for (int i=1; i<=n; i++) {
		scanf("%d%d",&a[i],&b[i]);
		++g[Base-a[i]][Base-b[i]];
	}
	f[1][1]=1;
	for (int i=1; i<Maxx; i++)
		for (int j=1; j<Maxx; j++) 
			if (i!=1 || j!=1) {
				g[i][j]=(g[i][j]+g[i-1][j]+g[i][j-1])%Mod;
				f[i][j]=(f[i-1][j]+f[i][j-1])%Mod;
			}
	for (int i=1; i<=n; i++)
		ans=(ans+g[Base+a[i]][Base+b[i]]-f[a[i]*2+1][b[i]*2+1]+Mod)%Mod;
	printf("%lld",ans*inv2%Mod);
}

Measured memory_bytes: 254592
package main

import "fmt"

func main() {
	var N, A int
	fmt.Scan(&N, &A)
	x := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&x[i])
	}
	var dp [51][51][3000]int
	dp[0][0][0] = 1
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			for k := 0; k < 2500; k++ {
				dp[i+1][j][k] += dp[i][j][k]
				dp[i+1][j+1][k+x[i]] += dp[i][j][k]
			}
		}
	}
	r := 0
	for i := 1; i <= N; i++ {
		r += dp[N][i][A*i]
	}
	fmt.Println(r)
}


Measured memory_bytes: 62336
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> t(n+1);
	rep(i,m){
		int a, b;
		cin >> a >> b;
		t[a]++;
		t[b]++;
	}
	loop(i, 1, n+1) cout << t[i] << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (long long i = 0; i < (n); ++i)
#define rep(i, a, b) for (long long i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

typedef long long ll;

int main(void)
{
    map<int, vector<int>> mp;
    map<int, vector<int>> mp2;
    int n;
    cin >> n;
    int a[n];
    REP(i, n)
    cin >> a[i];
    long long ans = 0;
    REP(i, n)
    {
        // i + 1 + Ai
        int x = i + 1 + a[i];
        mp[x].push_back(i + 1);
        // i + 1 - Ai
        x = i + 1 - a[i];
        mp2[x].push_back(i + 1);
    }

    for (auto i : mp)
    {
        sort(i.second.begin(), i.second.end());
    }
    for (auto i : mp2)
    {
        sort(i.second.begin(), i.second.end());
    }

    for (auto i : mp)
    {
        int x = i.first;
        // cout << "x " << x << endl;
        vector<int> pair = i.second;
        for (auto j : pair)
        {
            int val = j;
            // cout << "i " << val << endl;

            auto it = upper_bound(mp2[x].begin(), mp2[x].end(), val);
            int dist = distance(it, mp2[x].end());
            ans += dist;
            /*
            for (int k = 0; k < mp2[x].size(); k++)
            {
                if (mp2[x][k] > val)
                {
                    //cout << "j " << k << endl;
                    ans++;
                }
            }
            */
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 58672
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
    ll X;
    int flag=0;
    cin>>X;
    for(int i=0;i<100000;i++){
        if(100*i<=X&&X<=105*i){
            flag=1;
        }
    }
    if(flag==1){
        cout<<1;
    }else{
        cout<<0;
    }
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
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); }
// clang-format on

main {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0) break;
    vector<int> c(m), x(n);
    cin >> c >> x;
    auto dp = vectors(n + 1, 256, INF);
    dp[0][128] = 0;
    rep(i, n) rep(j, 256) {
      if (dp[i][j] == INF) continue;
      rep(k, m) {
        int y = max(0LL, min(255LL, j + c[k]));
        cmin(dp[i + 1][y], dp[i][j] + (x[i] - y) * (x[i] - y));
      }
    }
    cout << *min_element(all(dp[n])) << endl;
  }
}



Measured memory_bytes: 43664
R,G,B,N=map(int,input().split())
R,G,B=sorted([R,G,B])
ans=0
for b in range(1+N//B):
      for g in range(1+(N-b*B)//G):
            if  (N-b*B-g*G)%R==0:
                  ans+=1
print(ans)

Measured memory_bytes: 40300
#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 np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#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; }
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  string s;
  int n;
  cin >> s>>n;
  
  rep(i,s.size()){
    if(i%n==0) cout << s[i];
  }
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i=0; i<n; i++){
			a[i] = sc.nextInt();
		}
		sc.close();
		for(int i=n-1; i>=0; i--){
			System.out.print(a[i]);
			if(i != 0){
				System.out.print(" ");
			}
		}
		System.out.println();
	}

}

Measured memory_bytes: 26368
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <cmath>
using namespace std;

int main(int argc, const char * argv[]) {
  int n, d, x;
  cin >> n >> d >> x;
  int sum = 0;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
    sum++;
  }
  for(int i = 0; i < n; i++){
    for(int j = 2; j <= d; j++){
      if((j - 1)%(a.at(i))==0){
        sum++;
      }
    }
  }
  cout << sum + x << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
      
      if(a<9&&b<9){
         System.out.println("Yay!");
      }else{
         System.out.println(":(");
      }
        
    }
}

Measured memory_bytes: 23764
import java.util.*;
import java.util.TreeMap;
import java.util.Map;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Collections;
 
class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
 
        int S = sc.nextInt();
        int W = sc.nextInt();
 
        if(S>W){
            System.out.println("safe");
        }
        else{
            System.out.println("unsafe");
        }
    }
}

Measured memory_bytes: 35780
#include <bits/stdc++.h>
using namespace std;
#define MAX_N 505
typedef long long int64;
typedef pair<int, int> PII;

int64 f(int64 x, int64 A, int64 B){
	return floor(1.0 * A * x / B) - A * floor(1.0 * x / B);
}

int main() {
	int64 A, B, N;
	scanf("%lld %lld %lld", &A, &B, &N);
	printf("%lld\n", f(min(B - 1, N), A, B));
}

Measured memory_bytes: 3756
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void)
{
	char S[101];
	int s;
	scanf("%s", S);
	s = strlen(S);
	for(int i = 0; i < s; i++) {
		printf("x");
	}
	printf("\n");
	
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())

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

const int n = 110;
const int INF = 1e7;

int H, W;
bool A[n][n];
int D[n][n];

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> H >> W;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      char c;
      cin >> c;
      A[i][j] = c == '.';
      D[i][j] = INF;
    }
  }
  priority_queue<pii> Q;
  D[0][0] = A[0][0] ? 0 : 1;
  Q.push(make_pair(D[0][0], 0));
  while(!Q.empty()){
    auto p = Q.top(); Q.pop();
    int r, c, d; tie(d, r) = p;
    c = r%W; r /= W;
    if(D[r][c] != d)
      continue;
    //cout << r << " " << c << ": " << d << endl;
    if(r < H){
      int newd = d + ((A[r+1][c] || !A[r][c]) ? 0 : 1);
      if(newd < D[r+1][c]){
        D[r+1][c] = newd;
        Q.push(make_pair(D[r+1][c], (r+1)*W+c));
      }
    }
    if(c < W){
      int newd = d + ((A[r][c+1] || !A[r][c]) ? 0 : 1);
      if(newd < D[r][c+1]){
        D[r][c+1] = newd;
        Q.push(make_pair(D[r][c+1], r*W+c+1));
      }
    }
  }
  cout << D[H-1][W-1] << endl;

  return 0;
}


Measured memory_bytes: 384
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    S = input()
    K = int(input())
    nums = []
    a = ord("a")
    for s in S:
        nums.append(ord(s) - a)

    for i in range(len(S)):
        if nums[i] == 0:
            continue
        diff = 26 - nums[i]
        if diff <= K:
            nums[i] = 0
            K -= diff

    if K > 0:
        nums[-1] = (nums[-1] + K) % 26

    ans = ""
    for n in nums:
        ans += chr(n + a)
    print(ans)


if __name__ == "__main__":
    main()


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


int main()
{
  int n, m;
  cin >> n >> m;
  vector<vector<int>> s(m);
  rep(i, m)
  {
    int k;
    cin >> k;
    s[i].resize(k);
    rep(j, k)
    {
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  vector<int> p(m);
  rep(i, m)
    cin >> p[i];
  int ans = 0;
  rep(i, 1<<n)
  {
    int lu = 0;
    rep(j, m)
    {
      int c = 0;
      for (int k : s[j])
        if (i>>k&1)
          c++;
      if (c % 2 == p[j])
        lu |= 1<<j;
    }
    if (lu == (1<<m) - 1)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;


int main(){
    string s;
    cin >> s;
    ll N=s.size();
    char C='a';
    ll ans=s.size();
    for(ll i=0;i<26;i++){
        string s3=s;
        string s2="";
        ll counter=0;

      for(ll k=0;k<N;k++){
            //単一文字かcheck
            bool check=1;
        for(ll j=0;j<s3.size();j++){
             if(s3[j]!=C){check=0;break;}
         ;}
         if(check){ans=min(ans,counter);break;}

         for(ll j=0;j<s3.size()-1;j++){
            if(s3[j]==C||s3[j+1]==C){s2+=C;}
            else s2+=C+1;
         ;}
         s3=s2;
         s2="";
         counter++;

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


Measured memory_bytes: 256
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    s=STR()
    ct=999
    for i in range(len(s)-2):
        ct=min(abs(753-int(s[i:i+3])),ct)
    print(ct)
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
#include<iostream>
 #include<cmath>
 #define LIMIT 50000
 using namespace std;
 int a, b , d, mx, my;
 
 void update( int x, int y, int &mx, int &my ){
     if ( y < 0 ) return;
     if ( x + y == mx + my && a*x + b*y < a*mx + b*my ){
         mx = x; my = y;
     } else if ( x + y < mx + my ){
         mx = x; my = y;
     }
 }

 main(){
     while( cin >> a >> b >> d, (a || b || d) ){
         mx = my = LIMIT;
         for ( int y, x = 0; x <= b + d; x++ ){
             if ( (a*x - d)%b == 0 ){
                 y = (a*x - d)/b; update( x, y, mx, my );
             }
             if ( (a*x + d)%b == 0 ){
                 y = (a*x + d)/b; update( x, y, mx, my );
             }
             if ( (d - a*x)%b == 0 ){
                 y = (d - a*x)/b; update( x, y, mx, my );
             }
         }
         cout << mx << " " << my << endl;
     }
 }

Measured memory_bytes: 864
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int n, m;
    cin >> n >> m;
    vector<double> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    double sum = accumulate(a.begin(), a.end(), 0);
    double div = sum / 4 / m;
    int cnt = 0;
    for (int i = 0; i < n; i++)
        if (a[i] >= div) cnt++;
    if (cnt >= m) cout << "Yes" << '\n';
    else cout << "No" << '\n';
}


Measured memory_bytes: 256
#include <cstdio>

const int mod = 998244353;
const int MAXN = 2e6 + 5;

template<typename _T>
void read( _T &x )
{
	x = 0;char s = getchar();int f = 1;
	while( s > '9' || s < '0' ){if( s == '-' ) f = -1; s = getchar();}
	while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();}
	x *= f;
}

template<typename _T>
void write( _T x )
{
	if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; }
	if( 9 < x ){ write( x / 10 ); }
	putchar( x % 10 + '0' );
}

template<typename _T>
void swapp( _T &x, _T &y )
{
	_T t = x; x = y, y = t;
}

int fac[MAXN], ifac[MAXN];
int N, M;

int qkpow( int, int );
int inv( const int a ) { return qkpow( a, mod - 2 ); }
void add( int &x, const int v ) { x = ( x + v >= mod ? x + v - mod : x + v ); }
int C( const int n, const int m ) { return 1ll * fac[n] * ifac[m] % mod * ifac[n - m] % mod; }
int invC( const int n, const int m ) { return 1ll * ifac[n] * fac[m] % mod * fac[n - m] % mod; }

int qkpow( int base, int indx )
{
	int ret = 1;
	while( indx )
	{
		if( indx & 1 ) ret = 1ll * ret * base % mod;
		base = 1ll * base * base % mod, indx >>= 1;
	}
	return ret;
}

void init( const int siz )
{
	fac[0] = ifac[0] = 1;
	for( int i = 1 ; i <= siz ; i ++ ) fac[i] = 1ll * fac[i - 1] * i % mod;
	ifac[siz] = inv( fac[siz] );
	for( int i = siz - 1 ; i ; i -- ) ifac[i] = 1ll * ifac[i + 1] * ( i + 1 ) % mod;
}

int main()
{
	read( N ), read( M );
	if( N < M ) swapp( N, M );
	init( N + M ); 
	
	int ans = 0, tmp = invC( N + M, N );
	for( int k = 1 ; k <= M ; k ++ )
		add( ans, 499122177ll * C( M - k + N - k, M - k ) % mod * C( 2 * k, k ) % mod * tmp % mod );
	add( ans, N ); write( ans ), putchar( '\n' );
	return 0;
}

Measured memory_bytes: 9308
N = int(input())
A = list(map(int, input().split()))

c = 0
e = len(A)
d = 1
for i in range(e):
  if A[i] == d:
    d = d + 1
  else:
    c = c + 1

if c == e:
    print(-1)
else:
    print(c)

Measured memory_bytes: 24744
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

    string s, t;
    cin >> s >> t;
    int N = s.size(), M = t.size();
    vector<vector<int>> dp(N + 1, vector<int>(M + 1, 0));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            if (s[i] == t[j]) {
                dp[i + 1][j + 1] =
                    max(max(dp[i][j + 1], dp[i + 1][j]), dp[i][j] + 1);
            }
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1]);
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j]);
        }
    }

    string ans = "";
    while (N > 0 && M > 0) {
        if (dp[N][M] == dp[N - 1][M])
            N--;
        else if (dp[N][M] == dp[N][M - 1])
            M--;
        else {
            N--;
            M--;
            ans.push_back(s[N]);
        }
    }

    reverse(all(ans));
    cout << ans << endl;
}

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

#ifndef ONLINE_JUDGE 
const bool DEBUG = true;
#else
const bool DEBUG = false;
#endif

typedef unsigned long long ull;
typedef long long ll;

#define F first
#define S second
#define all(x) begin(x), end(x)

using namespace std;

void exec()
{
	int n;
	cin >> n;

	vector<double> dp(n + 1);
	dp[0] = 1;

	double ans = 0;
	for (int i = 1; i <= n; ++i) {
		double head;
		cin >> head;

		for (int j = i; j > 0; --j) {
			dp[j] = dp[j] * (1 - head) + dp[j - 1] * head;
		}
	}

	/*for (double i : dp)
		cout << i << endl;*/

	cout << fixed << setprecision(12) << dp[n/2 + 1] << endl;
}

















int main()
{
	exec();

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int h,m,s;
    h=n/3600;
    m=(n-h*3600)/60;
    s=n%60;
    cout<<h<<':'<<m<<':'<<s<<endl;
    return 0;
}


Measured memory_bytes: 3088
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

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

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        string S;
        cin >> S;
        Int N = S.size() + 1;
        vector<Int> A(S.size() + 1, 0);
        for (int i = 0; i + 1 < N; ++i) {
            if (S[i] == '<') {
//                if (A[i] < A[i + 1]) {
                chmax(A[i + 1], A[i] + 1);
//                }
            }
        }
        for (int i = N - 1; i > 0; --i) {
            if (S[i - 1] == '>') {
                chmax(A[i - 1], A[i] + 1);
            }
        }

        Int ans = 0;
        for (int i = 0; i < N; ++i) {
            ans += A[i];
        }
        cout << ans << endl;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 4728
n = int(input())
n -= 1
for i in range(1, 15):
    if n >= 26**i :
        n -= 26**i
        continue 
    ans = ""
    for j in range(i):
        d = n % 26
        ans += chr(ord("a")+d)
        n //= 26
    ans = ans[::-1]
    break
print(ans)





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

int main(){
	string s;
  	cin >> s;
  
  	int ans = 0;
  	int tmp = 0;
  
  	for(int i = 0;i < 3;i++){
  		if(s[i] == 'R'){
          tmp++;
          ans = (ans<tmp?tmp:ans);
        }else{
          tmp = 0;
        }
    }

  	cout << ans  << endl;
}


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

int main(){
  long long X,i,j,ans;
  cin>>X;
  
  for(j=X;j<10000000;j++){
    for(i=2;i<j;i++){
      if(j%i==0)goto skip;
    }
    cout<<j;
    return 0;
    skip:;
  }

}
    


Measured memory_bytes: 256
import java.util.Scanner


object Main {


  def read() = {
    val sc = new Scanner(System.in)
    val n, d = sc.nextInt()
    val x = IndexedSeq.fill(n, d)(sc.nextInt())
    (n, d, x)
  }

  def solve(n: Int, d: Int, x: IndexedSeq[IndexedSeq[Int]]): Long = {
    def dist(y:IndexedSeq[Int], z:IndexedSeq[Int]):Double ={
      math.sqrt((y,z).zipped.map((yi,zi)=> (yi-zi)*(yi-zi)).sum)
    }
    val eps = 1e-6
    (for (i1 <- 0 until n; i2 <- i1 + 1 until n) yield {
      val y = x(i1)
      val z = x(i2)
      val d = dist(y,z)
        d.%(1) <= eps || d.%(1) >= 1 - eps
    }).count(identity)
  }

  def main(args: Array[String]): Unit = {
    val (n, d, x) = read()
    println(solve(n, d, x))
  }
}

Measured memory_bytes: 25796
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
#define toupper(S) transform(S.begin(),S.end(),S.begin(),toupper)
#define tolower(S) transform(S.begin(),S.end(),S.begin(),tolower)
//const lint MOD = pow(10, 9) + 7;

int main() {
	int N;
	cin >> N;
	cout << N / 2 + bool(N % 2) << endl;
}


Measured memory_bytes: 256
c = [0, 0, 0, 0]
for i in range(3):
  a, b = map(int, input().split())
  c[a-1] += 1
  c[b-1] += 1
cnt = 0
for i in range(4):
  if c[i] % 2 == 1:
    cnt += 1
print("YES" if cnt==0 or cnt==2 else "NO")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define int long long 
using namespace std;
signed main(){
  int a,b,k;
  cin>>a>>b>>k;
  for(int i=1;i<=k;i++){
    if(a%2!=0){
      a--;
    }
    b += a / 2;
    a = a / 2;
    i++;
    if(i>k){
      break;
    }else{
    if(b%2!=0){
      b--;
    }
    a += b / 2;
    b = b / 2;
    }
  }
  cout<<a<<" "<<b<<"\n";
  return(0);
}


Measured memory_bytes: 256
private fun readIntArray(): List<Int> {
    return readLine()!!.split(" ").map{ it.toInt() }
}

private fun readInt(): Int {
    return readLine()!!.toInt()
}

private fun bfs(x: Int, graph: MutableList<MutableList<Pair<Int, Int>>>, people: MutableList<Int>) {
    if(people[x] != Int.MAX_VALUE) {
        return
    }

    val unvisited = mutableListOf(x)
    people[x] = 0
    while (unvisited.size > 0) {
        val now = unvisited[0]
        unvisited.removeAt(0)
        for(next in graph[now]) {
            if (people[next.first] == Int.MAX_VALUE) {
                people[next.first] = people[now] + next.second
                unvisited.add(next.first)
            }
        }
    }
}

fun main(args: Array<String>) {
    val (N, M) = readIntArray()

    val graph: MutableList<MutableList<Pair<Int, Int>>> = mutableListOf()
    val people: MutableList<Int> = mutableListOf()
    for(i in 0 until N + 1) {
        people.add(Int.MAX_VALUE)
    }
    for(i in 0 until N + 1) {
        graph.add(mutableListOf())
    }

    for (i in 0 until M) {
        val (L, R, D) = readIntArray()
        graph[L].add(Pair(R, D))
        graph[R].add(Pair(L, -D))
    }

    for (i in 1 until N + 1) {
        bfs(i, graph, people)
    }

    for (i in 1 until N + 1) {
        for (p in graph[i]) {
            if (people[p.first] - people[i] != p.second) {
                println("No")
                return
            }
        }
    }

    println("Yes")
}


Measured memory_bytes: 134600
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from copy import deepcopy

h, w = map(int, readline().split())
s = [readline().rstrip().decode() for _ in range(h)]
move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
sg = []
memo = [[False] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            sg.append((i, j))
        else:
            memo[i][j] = True
ans = 0
for ss in sg:
    q = [ss]
    cnt = 0
    dist = deepcopy(memo)
    dist[ss[0]][ss[1]] = True
    while q:
        cnt += 1
        qq = []
        for y, x in q:
            for dy, dx in move:
                xx, yy = x + dx, y + dy
                if xx < 0 or yy > h - 1 or yy < 0 or xx > w - 1:
                    continue
                if dist[yy][xx]:
                    continue
                dist[yy][xx] = True
                qq.append((yy, xx))
        q = qq
    ans = max(ans, cnt - 1)
print(ans)


Measured memory_bytes: 3572
#include<iostream>
using namespace std;
int main(){
  int w,h;
  int x,y;
  int r;
  cin>>w>>h;
  cin>>x>>y;
  cin>>r;
  if(x-r>=0&&x+r<=w&&y-r>=0&&y+r<=h){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return (0);
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)

int main() {
    int k;
    cin >> k;
    int64_t ans = 0;
    for(int a = 1; a <= k; a++){
        for(int b = 1; b <= k; b++){
            for(int c = 1; c <= k; c++){
                int64_t gcdabc = __gcd(a,__gcd(b,c));
                ans += gcdabc;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
   
    int a,b,c;
    cin>>a>>b>>c;
    
    int s[3]={a,b,c};
    
    sort(s,s+3);
    
    if(s[0]+s[1]==s[2]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    
    
    return 0;
   
}






Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
int n,k;
int ans;
int arr[100005],maxi[100005];
vector<int>v[100005];;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
    }
    int a,b;
    for(int i=1;i<=k;i++){
        cin>>a>>b;
        v[a].pb(b);
        maxi[a]=max(maxi[a],arr[b]);
        v[b].pb(a);
        maxi[b]=max(maxi[b],arr[a]);
    }
    for(int i=1;i<=n;i++){
        if(v[i].size()==0) ans++;
        else if(arr[i]>maxi[i]) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 9500
#1150から
import numpy as np
N = int(input())
li = list(map(int, input().split()))
li.sort(reverse=True)
#numpyのndarrayに変換
arr = np.array(li)
if np.sum(arr) - arr[0] > arr[0]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 12488
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int M = 30000;

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

  if (N == 3) {
    puts("2 5 63");
    return 0;
  }

  for (int a = 1; a < N && 2*a <= M; ++a) {
    int b = N - a;

    if (3 + 6 * (b - 1) > M) continue;

    int mod2 = b % 2;
    int mod3 = a * (a + 1) % 3;

    if (mod2 != 0 || mod3 != 0) continue;

    REP(i, a) printf("%d ", 2*(i+1));
    REP(i, b) printf("%d ", 3 + i*6);
    printf("\n");
    return 0;
  }
  return 0;
}


Measured memory_bytes: 384
#include<math.h>
#include<map>
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include<array>
#include<tuple>
#include<queue>
#include<stack>
#include<iomanip>
#include<bitset>
#include <list>
#include<numeric>
//AtCoderC++.cpp

using namespace std;

inline int ceiling(int n, int d) {
	return n % d == 0 ? n / d : n / d + 1;
}

int main() {
	int N; string S; cin >> N >> S;
	auto left = vector<int>(26, 0), right = vector<int>(26, 0);
	for (size_t i = 0; i < N; i++) ++right[S[i] - 'a'];
	auto answer = 0, count = 0; int idx;
	for (size_t i = 0; i < N - 1; i++) {
		idx = S[i] - 'a';
		if (left[idx] == 0 && right[idx] > 1)++count;
		if (left[idx] > 0 && right[idx] == 1)--count;
		++left[idx]; --right[idx];
		answer = max(answer, count);
	}
	cout << answer << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

const int N = 2e9;
char out[N];

int main() {
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  // Emily <3
  ll n, b;
  cin >> n >> b;
  int ans = 1;
  ll num = b;
  while (num <= n) {
    ans++;
    num*=b;
  }
  cout << ans << nl;

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

int main(){
	IO_STREAM;
	int N;	cin>>N;
	int ans=0;
	rep(i,0,N){
		int a;
		cin>>a;
		if(i%2==0&&a%2==1) ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                    \
  ifstream in("abc168/abc168_d.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

void search_dijkstra(vector<int>& fixed, vector<vector<int>>& g,
                     map<P, int>& m) {
  // cost, to, from
  typedef tuple<int, int, ll> tpl;
  priority_queue<tpl, vector<tpl>, greater<tpl>> que;

  que.push(make_tuple(0, 0, 0));
  while (!que.empty()) {
    auto top = que.top();
    que.pop();
    int from = get<1>(top);
    if (fixed[from] != -1) continue;

    // 未確定のうち一番小さいものを確定
    ll now =  get<0>(top);
    ll _bef = get<2>(top);

    // fixed[from] = m.at(make_pair(_bef, from));
    fixed[from] = _bef;

    for (auto to : g[from]) {
      if (fixed[to] != -1) continue;
      que.push(make_tuple(now + 1, to, from));
    }
  }

  return;
}

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N, M;
  cin >> N >> M;

  vector<vector<int>> g(N);
  map<P, int> m;
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
    m.emplace(make_pair(a, b), i + 1);
    m.emplace(make_pair(b, a), i + 1);
  }

  vector<int> fixed(N, -1);
  search_dijkstra(fixed, g, m);
  rep(i, N) {
    if (fixed[i] == -1) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  repi(i, 1, N) { cout << fixed[i] + 1 << endl; }
}

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

using ll=long long;
#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.a<<","<<p.b<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

using uint=unsigned;
using ull=unsigned long long;

const uint mod=998244353;
//const uint mod=1000000007;
//uint mod=1;
struct mint{
	uint v;
	mint(ll vv=0){s(vv%mod+mod);}
	mint& s(uint vv){
		v=vv<mod?vv:vv-mod;
		return *this;
	}
	mint operator-()const{return mint()-*this;}
	mint& operator+=(const mint&rhs){return s(v+rhs.v);}
	mint&operator-=(const mint&rhs){return s(v+mod-rhs.v);}
	mint&operator*=(const mint&rhs){
		v=ull(v)*rhs.v%mod;
		return *this;
	}
	mint&operator/=(const mint&rhs){return *this*=rhs.inv();}
	mint operator+(const mint&rhs)const{return mint(*this)+=rhs;}
	mint operator-(const mint&rhs)const{return mint(*this)-=rhs;}
	mint operator*(const mint&rhs)const{return mint(*this)*=rhs;}
	mint operator/(const mint&rhs)const{return mint(*this)/=rhs;}
	mint pow(int n)const{
		mint res(1),x(*this);
		while(n){
			if(n&1)res*=x;
			x*=x;
			n>>=1;
		}
		return res;
	}
	mint inv()const{return pow(mod-2);}
	/*mint inv()const{
		int x,y;
		int g=extgcd(v,mod,x,y);
		assert(g==1);
		if(x<0)x+=mod;
		return mint(x);
	}*/
	friend ostream& operator<<(ostream&os,const mint&m){
		return os<<m.v;
	}
	bool operator<(const mint&r)const{return v<r.v;}
	bool operator==(const mint&r)const{return v==r.v;}
};

const int vmax=(1<<21)+10;
mint fact[vmax],finv[vmax],invs[vmax];
void initfact(){
	fact[0]=1;
	rng(i,1,vmax){
		fact[i]=fact[i-1]*i;
	}
	finv[vmax-1]=fact[vmax-1].inv();
	for(int i=vmax-2;i>=0;i--){
		finv[i]=finv[i+1]*(i+1);
	}
	for(int i=vmax-1;i>=1;i--){
		invs[i]=finv[i]*fact[i-1];
	}
}
mint choose(int n,int k){
	return fact[n]*finv[n-k]*finv[k];
}
mint binom(int a,int b){
	return fact[a+b]*finv[a]*finv[b];
}
mint catalan(int n){
	return binom(n,n)-(n-1>=0?binom(n-1,n+1):0);
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	
	initfact();
	
	const int v=1000010;
	vc<mint> w(v);
	rng(i,1,v){
		w[i]+=invs[i];
		for(int j=i*2;j<v;j+=i)
			w[j]-=w[i];
	}
	
	int n;cin>>n;
	mint ans=0;
	vc<mint> s(v);
	rep(i,n){
		int a;cin>>a;
		s[a]+=a;
		ans-=a;
	}
	rng(i,1,v){
		mint x=0;
		for(int j=i;j<v;j+=i)
			x+=s[j];
		ans+=x*x*w[i];
	}
	ans/=2;
	
	cout<<ans<<endl;
}


Measured memory_bytes: 32640
def main():
    N, Y = [int(_) for _ in input().split(" ")]

    flag = False
    for x in range(N+1):
        for y in range(N+1 - x):
            z = N - (x + y)
            if 10000*x + 5000*y + 1000*z == Y:
                flag = True
                break
        if flag == True:
            break

    if flag == False:
        x, y, z = -1, -1, -1

    print(x, y, z)

main()

Measured memory_bytes: 3060
def lower_bound(arr,tar):
    def _lower_bound(first,length):
        if(length==0):
            return first

        half = length//2
        middle = first+half
        if arr[middle]<tar:
            return _lower_bound(middle+1,length-half-1)
        else:
            return _lower_bound(first,half)
    return _lower_bound(0,len(arr))

def upper_bound(arr,tar):
    def _upper_bound(first,length):
        if(length==0):
            return first

        half = length//2
        middle = first+half
        if arr[middle]>tar:
            return _upper_bound(first,half)
        else:
            return _upper_bound(middle+1,length-half-1)
    return _upper_bound(0,len(arr))

N=int(input())
a=list(map(int,input().split()))
L = [(i+1)+a[i] for i in range(N)]
R = [(i+1)-a[i] for i in range(N)]
R.sort()

s=0
for it in L:
    s+=upper_bound(R,it)-lower_bound(R,it)
print(s)



Measured memory_bytes: 35168
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
const int m = 1010;
vector<int> g[m * m];
int dp[m * m];
int vis[m * m];
int idx[m][m];
int get_idx (int x, int y) {
  if (x > y) swap(x, y);
  return idx[x][y];
}
int dfs (int cur) {
  if (vis[cur]) {
    if (dp[cur] == -1) {
      cout << -1 << endl;
      exit(0);
    }
    return dp[cur];
  }
  int res = 0;
  vis[cur] = 1;
  for (int nxt : g[cur]) {
    int y = dfs (nxt);
    res = max(res, y);
  }
  return dp[cur] = res + 1;
}
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int>(n - 1));
  for (int i = 0; i < n; i++) for (int j = 0; j + 1 < n; j++) cin >> a[i][j], a[i][j]--;
  int it = 0;
  for (int i = 0; i < m; i++) for (int j = i + 1; j < m; j++) idx[i][j] = it++;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j + 1 < n; j++) a[i][j] = get_idx(i, a[i][j]);
    for (int j = 1; j + 1 < n; j++) g[a[i][j - 1]].push_back(a[i][j]);
  }
  int ans = -1;
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < m * m; i++) {
    if (g[i].empty()) continue;
    ans = max(ans, dfs (i));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 55808
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using ll = long long;
#define int long long
#define itn int
#define F first
#define S second
signed main(void){
    int n, m; cin>>n>>m;
    vector <pair<int,int>> data(n);
    rep(i,n) {int a,b; cin>>a>>b; data[i] = make_pair(a,-b);}
    sort(data.begin(),data.end());
    vector <int> nittei[m]; 
    int x = 0;
    int ans = 0;
    priority_queue <int> q;
    for(int i=0;i<m;i++){
        while(data[x].F <= i+1){
            q.push(-data[x].S);
            x++;
        }
        int tmp = 0;
        if(!q.empty()){
            tmp = q.top(); q.pop();
        } 
        ans += tmp;
    }
    cout<<ans<<endl;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> v1;

const ll mod = 1000000007;

ll h,w,k;
string s[500];
ll ans[305][305];
ll init = -1;

bool has_berry(ll i){
  for(ll j = 0;j < w;j++){
    if(s[i][j] == '#') return true;
  }
  return false;
}

int main(){
  cin >> h >> w >> k;
  for(ll i = 0;i < h;i++){
    cin >> s[i];
  }
  ll idx = 1;
  for(ll i = 0;i < h;i++){
    if(has_berry(i)){
      if(init < 0) init = i;
      for(ll j = 0;j < w;j++){
        ans[i][j] = idx;
        if(s[i][j] == '#') idx++;
      }
      for(ll j = w-1;j >= 0;j--){
        if(s[i][j] != '#') ans[i][j]--;
        else break;
      }
    }
  }
  for(ll i = init-1;i >= 0;i--){
    for(ll j = 0;j < w;j++){
      ans[i][j] = ans[init][j];
    }
  }
  for(ll i = init;i < h;i++){
    if(ans[i+1][0] == 0){
      for(ll j = 0;j < w;j++){
        ans[i+1][j] = ans[i][j];
      }
    }
  }
  for(ll i = 0;i < h;i++){
    for(ll j = 0;j < w-1;j++){
      cout << ans[i][j] << " ";
    }
    cout << ans[i][w-1] << endl;
  }
}


Measured memory_bytes: 1664