akhauriyash/Code-Regression huggingface dataset:
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin>>n;
	vi a(n);
	rep(i,n)cin>>a[i];
	ll dp[n][n];
	const ll inf = 1e18;
	rep(i,n){
		rep(j,n){
			dp[i][j] = inf;
		}
	}
	ll pre[n];
	pre[0] = a[0];
	repa(i,1,n){
		pre[i] = pre[i-1] + a[i];
	}
	repr(l,n){
		repa(r,l,n){
			if(l == r){dp[l][r] = 0;continue;}
			else if(r == l+1){
				dp[l][r] = a[l] + a[r];
				continue;
			}	
			repa(x,1,r-l+1){
				ll temp1 = pre[r];
				if(l > 0){
					temp1 = pre[r] - pre[l-1];
				}
				// ll temp2 = pre[r] - pre[l+x-1];
				dp[l][r] = min(dp[l][r],dp[l+x][r] + dp[l][l+x-1] + temp1);
			}
		}
	}
	cout<<dp[0][n-1];
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for(int (i)=0;(i)<(n);(i)++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
bool custom1 (pair<int, int> a, pair<int, int> b) {
  return (a.first < b.first);
}
bool custom2(pair<int, int> a, pair<int, int> b) {
  return (a.second < b.second);
}

const int MAX = 200005;
const long long MOD = 1000000007;
const long long MODMOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

long long gcd(long long a, long long b) {
  if(a % b == 0) return b;
  else return gcd(b, a % b);
}

int main() {
  int n;
  cin >> n;
  int ans = 0;
  int endA = 0;
  int startB = 0;
  int both = 0;
  rep(i, n) {
    string s;
    cin >> s;
    rep(j, s.size()-1) {
      if(s[j] == 'A' && s[j+1] == 'B') ans++;
    }
    bool a = false, b = false;
    if(s[0] == 'B') b = true;
    if(s[s.size()-1] == 'A') a = true;
    if(a && b) both++;
    else if(a) endA++;
    else if(b) startB++;
  }
  if(both == 0) {
    cout << ans + min(endA, startB) << endl;
  }
  else {
    ans += both - 1;
    if(startB == 0 && endA == 0) cout << ans << endl;
    else cout << ans + 2 + min(endA-1, startB-1) << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[200010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	if(b>a)return 0;
	if(a==b)return 1;
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int g(int x){
	x=modpow(x,MOD-2);
	return x;
}
int n,q,sum[200010];
vector<int>v[200010];
bool used[200010];
void dfs(int i){
	used[i]=true;
	for(int x:v[i]){
		if(!used[x]){
			sum[x]+=sum[i];
			dfs(x);
		}
	}
}
signed main(){
	cin>>n>>q;
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		a--,b--;
		v[a].pb(b),v[b].pb(a);
	}
	rep(i,q){
		int p,x;
		cin>>p>>x;
		p--;
		sum[p]+=x;
	}
	dfs(0);
	rep(i,n){
		cout<<sum[i]<<(i==n-1?"\n":" ");
	}
	return 0;
}


Measured memory_bytes: 21376
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define M1 1000000007
#define M2 998244353

#define fl(i,a,b)  for(ll i=a;i<b;i++)
#define bfl(i,a,b) for(ll i=b-1;i>=a;i--)
#define f(i,n)     for(int i=0;i<n;i++)
#define bf(i,n)    for(int i=n-1;i>=0;i--)


#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define bn "\n"

//------------------------------------------------------------------------ 
// #define V(a) vector<a>
// #define vt() vector< tuple < int ,int ,int > > ;
// #define vector< int ,int > pv;
// vector< pair <int,int> > vect;


//------------------------------------------------------------------------

ll modI(ll a,ll m);
ll gcd(ll a,ll b);
ll powM(ll x,ll y,ll m);
ll swap(ll a,ll b);

void swap(ll& a,ll& b)
{
    ll tp=a;
    a=b;
    b=tp;
}

ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}

ll powM(ll x,ll y,ll m)
{
    ll ans=1,r=1;
    x%=m;
    while(r>0&&r<=y)
    {
        if(r&y)
        {
            ans*=x;
            ans%=m;
        }
        r<<=1;
        x*=x;
        x%=m;
    }
    return ans;
}
 
ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}

//---------------------------------------------------------------------------

// variable = Expression1 ? Expression2 : Expression3
// max = (n1 > n2) ? n1 : n2; 
// (n>m) ? cout<<"True"<<endl:cout<<"false"<<endl ;

// ---------------------------------------------------------------------------	

// int n;cin>>n;int a[n];for(int i=0;i<n;i++)cin>>a[i];    
// for(int i=0;i<n;i++)cout<<a[i];
// int a,b;cin>>a>>b;   

//----------------------------------------------------------------------------

// vector< tuple < int ,int ,int > > tv;
// vector< int ,int > pv;


//----------------------------------------------------------------------------


int main() {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
	int tt=1;
   // cin>>tt;
	while(tt--)
	{
	    
	  string s1,s2;
	  cin>>s1>>s2;
	  int n=s1.length();
	  ll cnt=0;
	  f(i,n)
	  {
	      if(s1[i]!=s2[i])
	      cnt++;
	  }
	  p1(cnt);
	    
	}
	
	return 0;
}


Measured memory_bytes: 3884
lw = []
lc = []
r, c = map(int, input().split())
for i in range(r):
    ls = list(map(int, input().split()))
    lw.append(ls)
for i in range(r):
    print(" ".join(map(str, (lw[i] + [sum(lw[i])]))))
for i in range(c):
    k = 0
    for j in range(r):
        k =  k + lw[j][i]
    lc.append(k)
print(" ".join(map(str, (lc + [sum(lc)]))))


Measured memory_bytes: 5692
de = false
require 'set'; require 'prime'
INF=Float::INFINITY
n = gets.chomp.to_i
xl = n.times.map{gets.split.map(&:to_i)}

xl.sort_by!{|x,l|x+l}
p xl if de
ans = 0
cur = -INF
xl.each do |x,l|
  p [cur, x,l,ans] if de
  if cur <= x - l
    cur = x + l
    ans += 1
  end
end
puts ans

Measured memory_bytes: 12920
import java.util.*;
import java.io.*;
import java.util.function.*;

class Main {
    static In in = new In();
    static Out out = new Out();
    static long mod = 1000000007;
    static long inf = 0xfffffffffffffffL;

    void solve() {
        int k = in.nextInt();
        int x = in.nextInt();
        out.println(k * 500 >= x ? "Yes" : "No");
    }

    static long gcd(long a, long b) {
        return 0 < b ? gcd(b, a % b) : a;
    }

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

    public static void main(String[]$) {
        new Main().solve();
        out.flush();
    }
}

class In {
    private BufferedInputStream reader = new BufferedInputStream(System.in);
    private byte[] buffer = new byte[0x10000];
    private int i = 0;
    private int length = 0;

    private int read() {
        if (i == length) {
            i = 0;
            try {
                length = reader.read(buffer);
            } catch (IOException ignored) {
            }
            if (length == -1) {
                return -1;
            }
        }
        return buffer[i++];
    }

    String next() {
        StringBuilder builder = new StringBuilder();
        int b = read();
        while (b < '!' || '~' < b) {
            b = read();
        }
        while ('!' <= b && b <= '~') {
            builder.appendCodePoint(b);
            b = read();
        }
        return builder.toString();
    }

    int nextInt() {
        return (int)nextLong();
    }

    long nextLong() {
        int b = read();
        while (b < '!' || '~' < b) {
            b = read();
        }
        int i = 0;
        if (b == '-') {
            i = 1;
            b = read();
        }
        long n = 0;
        while ('0' <= b && b <= '9') {
            n = n * 10 + b - '0';
            b = read();
        }
        return i == 0 ? n : -n;
    }

    char[][] nextCharArray(int n, int m) {
        char[][] a = new char[n][m];
        for (int i = 0; i < n; i++) {
            a[i] = next().toCharArray();
        }
        return a;
    }

    int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    int[] nextIntArray(int n, IntUnaryOperator op) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsInt(nextInt());
        }
        return a;
    }

    long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextLong();
        }
        return a;
    }

    long[] nextLongArray(int n, LongUnaryOperator op) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsLong(nextLong());
        }
        return a;
    }
}

class Out {
    private static PrintWriter out = new PrintWriter(System.out);

    void println(Object... a) {
        StringJoiner joiner = new StringJoiner(" ");
        for (Object obj : a) {
            joiner.add(String.valueOf(obj));
        }
        out.println(joiner);
    }

    void flush() {
        out.flush();
    }
}


Measured memory_bytes: 21460
#include <iostream>

using namespace std;

int main()
{
    int n,m;
    cin >>n>>m;
    int o[m];
    for(int i=0;i<m;i++){
        cin >>o[i];
    }
    int c[2*n+1];
    for(int i=1;i<=2*n;i++){
        c[i]=i;
    }
    int a[2*n],b[2*n];
    for(int i=0;i<m;i++){
        if(o[i]==0){
        for(int k=1;k<=n;k++){
            a[k]=c[k];
        }
        for(int k=n+1;k<=2*n;k++){
            b[k-n]=c[k];
        }
        for(int j=1;j<=2*n;j++){
            if(j%2==0)c[j]=b[j/2];
            else c[j]=a[(j+1)/2];
        }
        }
        else{
            for(int k=1;k<=o[i];k++){
                a[k]=c[k];
            }
            for(int k=o[i]+1;k<=2*n;k++){
                b[k-o[i]]=c[k];
            }
            for(int j=1;j<=2*n;j++){
                    int d=2*n-o[i];
                if(j<=d)c[j]=b[j];
                else c[j]=a[j-d];
            }
        }


    }
    for(int i=1;i<=2*n;i++){
        cout << c[i]<< endl;
    }
    return 0;

}



Measured memory_bytes: 3088
from sys import stdin
import math
import re
import queue

input = stdin.readline

MOD = 1000000007

def solve():
    S = (input().rstrip())
    K = int(input().rstrip())
    for x in range(len(S)):
        if(x%K == 0):
            print(S[x],end="")


    print("")
if __name__ == '__main__':
    solve()


Measured memory_bytes: 4080
#include <cstdio>
#include <cstring>
char s[12];int a[27];int n;
void sel(int u,int cur)
{
	if(u==n+1)
	{
		printf("%s\n",s+1);return;
	}
	for(int i=1;i<=cur;++i)
	{
		s[u]=i+'a'-1;
		sel(u+1,cur);
	}
	s[u]=++cur+'a'-1;sel(u+1,cur);
}
int main()
{
	scanf("%d",&n);sel(1,0);return 0;
}

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

int main() {
	ll N, z, w;
	cin >> N >> z >> w;
	vector<ll> a(N + 1);
	for (int i = 1; i <= N; i++) {
		cin >> a[i];
	}
	a[0] = w;

	if (N == 1) {
		ll res = abs(a[1] - w);
		cout << res << endl;
		return 0;
	}

	vector<vector<ll>> d(N, vector<ll>(2));
	for (int i = N - 1; i >= 0; i--) {
		for (int turn = 0; turn < 2; turn++) {
			ll tmp = (turn == 0) ? 0 : 1e18;
			for (int j = i + 1; j <= N; j++) {
				if (turn == 0) {
					if (j == N) tmp = max(tmp, abs(a[i] - a[j]));
					else tmp = max(tmp, d[j][1]);
				} else {
					if (j == N) tmp = min(tmp, abs(a[i] - a[j]));
					else tmp = min(tmp, d[j][0]);
				}
			}
			d[i][turn] = tmp;
		}
	}

	cout << d[0][0] << endl;
	return 0;
}


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

int main(){
  char b;
  cin >> b;
  
  if (b == 'A'){
    cout << 'T';
  }
  else if (b == 'T'){
    cout << 'A';
  }
  else if (b == 'C'){
    cout << 'G';
  }
  else {
    cout << 'C';
  }
  
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

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

if 0 in As:
    print(0)
else:
    ans = 1
    for a in As:
        ans *= a
        if ans > 10 ** 18:
            break
    if ans > 10 ** 18:
        print(-1)
    else:
        print(ans)




Measured memory_bytes: 23900
#include<bits/stdc++.h>
using namespace std;
using Weight=long long;

struct Edge{
    int to;
    Weight cap,rev;
};

using Edges=vector<Edge>;
using Graph=vector<Edges>;

class Flow{
    static const Weight INF=1e9+7;
    int N;
    Graph g;
    vector<int> level;
    vector<int> iter;
    void bfs(int s);
    Weight dfs(int v,int t,Weight f);
    public:
    Flow(int N):N(N),g(N){};
    void addEdge(int from,int to,Weight cap);
    Weight maxFlow(int s,int t);
};


void Flow::addEdge(int from,int to,Weight cap){
    g[from].push_back({to,cap,int(g[to].size())});
    g[to].push_back({from,Weight(0),int(g[from].size())-1});
}

Weight Flow::maxFlow(int s,int t){
    int flow=0;
    while(true){
        bfs(s);
        if(level[t]<0) return flow;
        iter.assign(N,0);
        int f;
        while((f=dfs(s,t,INF))>0){
            flow+=f;
        }
    }
}
void Flow::bfs(int s){
    level.assign(N,-1);
    queue<int> que;
    level[s]=0;
    que.push(s);
    while(!que.empty()){
        int v=que.front(); que.pop();
        for(int i=0;i<g[v].size();i++){
            Edge &e=g[v][i];
            if(e.cap>0 && level[e.to]<0){
                level[e.to]=level[v]+1;
                que.push(e.to);
            }
        }
    }
}

Weight Flow::dfs(int v,int t,Weight f){
    if(v==t) return f;
    for(int& i=iter[v];i<g[v].size();i++){
        Edge& e=g[v][i];
        if(e.cap>0 && level[v]<level[e.to]){
            Weight d=dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                g[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}


int main(){
    int v,e;
    cin>>v>>e;
    Flow g(v);
    for(int i=0;i<e;i++){
        int u,v,c;
        cin>>u>>v>>c;
        g.addEdge(u,v,c);
    }
    cout<<g.maxFlow(0,v-1)<<endl;
    return 0;
}

Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,ans=0,mx=0;
	char s[101];
    cin>>a>>s;
    for(int i=0;s[i]!=0;i++){
    	if(s[i]=='I'){
			ans++;if(ans>mx) mx=ans;
		}
    	if(s[i]=='D') ans--;
	}
	cout<<mx<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
 
int main()
{
    int n;
    while(cin>>n)
    {
        int a[2*n];
        int i;
        for(i=0;i<2*n;i++)
            cin>>a[i];
        sort(a,a+2*n);
        int sum=0;
        for(i=0;i<2*n;i+=2)
        {
            sum+=a[i];
        }
        cout<<sum<<endl;
    }
}

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

typedef int integer;
#define int long long
#define pb push_back
#define mp make_pair
#define sz(x) (int) x.size()
#define mod 1000000007
using namespace std;


int ar[1000000];
int n;

int brute() {
    int ans;
    bool f = false;
    for (int i = n; i < 2 * n; i++) {
        priority_queue<int> p1, p2;
        for (int j = 0; j < i; j++) {
            p1.push(ar[j]);
        }
        for (int j = i; j < 3 * n; j++) {
            p2.push(-1 * ar[j]);
        }
        int s1 = 0, s2 = 0;
        for (int j = 0; j < n; j++) {
            s1 += p1.top();
            p1.pop();
        }
        for (int j = 0; j < n; j++) {
            s2 += -1 * p2.top();
            p2.pop();
        }
        if (!f) {
            ans = s1 - s2;
            f = true;
        } else ans = max(ans, s1 - s2);
    }
    return ans;
}

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

    cin >> n;
    priority_queue<pair<int, int> > pq1, pq2, av;
    int sum1 = 0, sum2 = 0;
    for (int i = 0; i < 3 * n; i++) {
        cin >> ar[i];
        if (i < 2 * n) {
            pq1.push(mp(ar[i], i));
        } else {
            pq2.push(mp(ar[i], i));
            sum2 += ar[i];
        }
    }

    set<int> S;
    for (int i = 0; i < n; i++) {
        pair<int, int> t = pq1.top();
        pq1.pop();
        S.insert(t.second);
        sum1 += t.first;
    }
    for (int i = 0; i < n; i++) {
        pair<int, int> t = pq1.top();
        pq1.pop();
        av.push(t);
    }

    int ans = sum1 - sum2;
    for (int i = 2 * n - 1; i >= n; i--) {
        if (S.count(i)) {
            sum1 -= ar[i];
            while (!av.empty() && av.top().second >= i) {
                av.pop();
            }
            if (av.empty()) break;
            sum1 += av.top().first;
            S.insert(av.top().second);
            av.pop();
        }
        if (ar[i] < pq2.top().first) {
            sum2 -= pq2.top().first;
            sum2 += ar[i];
            pq2.pop();
            pq2.push(mp(ar[i], i));
        }

        ans = max(ans, sum1 - sum2);
    }

    cout << ans << endl;


}

Measured memory_bytes: 20460
//Breadth First Search
#if 0
?????¨?????????30??????
??????????????¨??????????????¢?´¢????????¬????????¨??¢?????´????????????????£?
#endif
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int n;
int D[100];
int matrix[100][100];
void bfs(int src)
{
    //cerr<<"bfs root = "<<src<<endl;
    queue<int> q;
    q.push(src);
    D[src]=0;
    while(!q.empty())
    {
        int cur=q.front();
        q.pop();
        //cerr<<"visiting "<<cur<<' '<<D[cur]<<endl;
        for(int dst=0;dst<n;dst++)
        {
            if(matrix[cur][dst]==1&&D[dst]==-1)
            {
                D[dst]=D[cur]+1;
                q.push(dst);
            }
        }
    }
};

int main()
{
    vector<int> l[101];
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int u,k;
        cin>>u>>k;
        for(int j=0;j<k;j++)
        {
            int tmp;
            cin>>tmp;
            l[u].push_back(tmp);
        }
    }
    
    for(int i=0;i<100;i++)
    {
        D[i]=-1;
    }
    
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            matrix[i][j]=0;
        }
    }
    
    for(int i=1;i<n+1;i++)
    {
        for(int j=0;j<l[i].size();j++)
        {
            matrix[i-1][l[i][j]-1]=1;
        }
    }
    
    bfs(0);
    
    for(int i=0;i<n;i++)
    {
        cout<<(i+1)<<' '<<D[i]<<endl;
    }
}

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

using namespace std;
const int mod = 1e9+7;
const int maxn = 2e3+23;
const int maxm = 1e5+15;
int n,m,a[maxn],b[maxn];
long long dp[maxn][maxn],sum[maxn];
int main(){
    cin >> n >> m;
    for(int i = 0;i <= n; ++i) dp[i][0] = 1;
    for(int i = 0;i <= m; ++i) dp[0][i] = 1;
    for(int i = 1;i <= n; ++i) cin >> a[i];
    for(int i = 1;i <= m; ++i) cin >> b[i];
    for(int i = 1;i <= n; ++i){
        for(int j = 1;j <= m; ++j){
            if(a[i] == b[j]) sum[j-1] = (sum[j-1]+dp[i-1][j-1])%mod;
            dp[i][j] = (dp[i][j-1] + sum[j-1])%mod;
        }
    }
    cout << dp[n][m];
    return 0;
}

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

int main() {
  int A,B,count=0;
  cin>>A>>B;
  int ans=0;
  for(int a=1;a<=9;a++){
    for(int b=0;b<=9;b++){
      for(int c=0;c<=9;c++){
        int x=10001*a+1010*b+100*c;
        if(A<=x&&x<=B) ans++; 
      }
    }
  }
  cout<<ans<<endl;
}
  

Measured memory_bytes: 256
/* ***********************************************
Author        :yang12138
Created Time  :2017年04月13日 星期四 01时00分34秒
File Name     :E.cpp
************************************************ */
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef pair<int,int>pii;
#define lson (root<<1)
#define rson (root<<1|1)

const int N=1e5+10;
char s[N];
int dat[N],n[2];

struct Tree{
	int val[N<<2];

	int cal(int x,int y){
		if(x==-1) return y;
		else if(y==-1) return x;
		else{
			if(x==y) return !x;
			else return -1;
		}
	}
	void build(int root,int l,int r){
		if(l<r){
			int m=(l+r)>>1;
			build(lson,l,m);
			build(rson,m+1,r);
			val[root]=cal(val[lson],val[rson]);
		}
		else val[root]=dat[l];
	}

	int query(int a,int b,int root,int l,int r){
		if(a==l && b==r) return val[root];
		int m=(l+r)>>1;
		if(b<=m) return query(a,b,lson,l,m);
		else if(a>m) return query(a,b,rson,m+1,r);
		else return cal(query(a,m,lson,l,m),query(m+1,b,rson,m+1,r));
	}
}t[2];


int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
	for(int i=0;i<2;i++){
		scanf("%s",s+1);
		n[i]=strlen(s+1);
		for(int j=1;j<=n[i];j++){
			if(s[j]=='A') dat[j]=0;
			else dat[j]=1;
		}
		t[i].build(1,1,n[i]);
	}

	int Q;
	scanf("%d",&Q);
	while(Q--){
		int a,b,c,d;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		if(t[0].query(a,b,1,1,n[0]) == t[1].query(c,d,1,1,n[1])) printf("YES\n");
		else printf("NO\n");
	}
    return 0;
}


Measured memory_bytes: 3072
/*  TAHMID RAHMAN
    DAMIAN FOREVER
     MATH LOVER
    NEVER GIVE UP
*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define GCD(a,b) __gcd(a,b);
#define endl "\n"
#define FRU freopen("out.txt","w",stdout)
#define FRO freopen("in.txt","r",stdin)
#define INFLL 9223372036854775807
#define debug 0
#define MAXN   100001
#define ar array
const int mxN=2e5;
const int MOD=1e9+7;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
#define debugx(v) {for(auto x:v){cout<<x<<" ";}cout<<endl;}
//Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;

int main()
{
    fastio;
    ll t;
    t=1;
    //cin>>t;
    while(t--)
    {
        ll n,i;
        cin>>n;
        vector<ll>v(n);
        ll sum=0;
        for(i=0;i<n;i++)
        {
            cin>>v[i];
            sum+=v[i];
        }
        sum-=v[n-1];
        ll ans=1e18;
        if(n==2)
        {
            cout<<abs(v[0]-v[1])<<endl;
            return 0;
        }
        ll sum1=0;
        ll j=n-2;
        for(i=n-1;i>0;i--,j--)
        {
            sum1+=v[i];
            //cout<<sum<<" "<<sum1<<endl;
            ans=min(abs(sum-sum1),ans);

            sum-=v[j];
        }
        cout<<ans<<endl;



    }

}



Measured memory_bytes: 4760
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;

const int N = 3;
const int maxn = 1E5 + 10;
typedef long long LL;
const LL mo = 1000000007;

inline int Mul(const LL &x,const LL &y) {return x * y % mo;}
inline int Add(const int &x,const int &y) {return x + y < mo ? x + y : x + y - mo;}

struct data{
	int a[N][N]; data(){memset(a,0,sizeof(a));}
	data operator * (const data &B)
	{
		data c;
		for (int k = 0; k < N; k++)
			for (int i = 0; i < N; i++)
				for (int j = 0; j < N; j++)
					c.a[i][j] = Add(c.a[i][j],Mul(a[i][k],B.a[k][j]));
		return c;
	}
}A,B,C,D;

int n,m,X[maxn];

void Pre_Work()
{
	for (int i = 0; i < N; i++) A.a[i][i] = 1;
	B.a[0][0] = 2; B.a[0][1] = 1; B.a[0][2] = 1;
	B.a[1][0] = 2; B.a[1][1] = 1; B.a[1][2] = 2;
	B.a[2][0] = 1; B.a[2][1] = 0; B.a[2][2] = 1;
	C.a[0][0] = 1; C.a[0][1] = 1; C.a[0][2] = 1;
	C.a[1][0] = 0; C.a[1][1] = 1; C.a[1][2] = 2;
	C.a[2][0] = 0; C.a[2][1] = 0; C.a[2][2] = 1;
	D.a[0][0] = 1; D.a[0][1] = 0; D.a[0][2] = 0;
	D.a[1][0] = 2; D.a[1][1] = 0; D.a[1][2] = 0;
	D.a[2][0] = 1; D.a[2][1] = 0; D.a[2][2] = 0;
}

inline data ksm(int y)
{
	data ret,x = B;
	for (int i = 0; i < N; i++) ret.a[i][i] = 1;
	for (; y; y >>= 1)
	{
		if (y & 1) ret = ret * x;
		x = x * x;
	}
	return ret;
}

int main()
{
	#ifdef DMC
		freopen("DMC.txt","r",stdin);
	#endif
	
	cin >> n >> m; Pre_Work();
	for (int i = 1; i <= m; i++) scanf("%d",&X[i]);
	for (int i = 1; i <= m; i++)
		A = A * ksm(X[i] - X[i - 1] - 1),A = A * C;
	A = A * ksm(n - X[m] - 1); A = A * D;
	cout << A.a[0][0] << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
	int a, b, n[5], k, count = 0;
	cin >> a >> b;
	for (int i = a; i <= b; i++) {
		k = i;
		for (int j = 0; j < 5; j++) {
			n[j] = k % 10;
			k /= 10;
		}
		if (n[0] == n[4] && n[1] == n[3] ) {
			count++;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<long long> a(N);

	for (auto &x : a) {
		cin >> x;
	}

	const auto T = accumulate(a.begin(), a.end(), 0LL);

	long long ans = 1LL << 60;

	long long s = 0;
	for (int i = 0; i + 1 < N; ++i) {
		s += a[i];
		ans = min(ans, abs(s - (T - s)));
	}
	cout << ans << endl;
}


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

int main(){
  int h,w;
  int n;
  int a[10000];
  cin >> h >> w;
  cin >> n;
  for(int i = 0;i < n;i++) cin >> a[i];

  int ans[100][100];
  int first[2] = {0,w-1};
  int move[2] = {1,-1};
  int now = 0;
  int st = 0;
  for(int i = 0;i < h;i++){
    for(int j = first[now];(0 <= j && j < w);j += move[now]){
      ans[i][j] = (st+1);
      a[st]--;
      if(a[st] == 0) st++;
    }
    now = (now+1)%2;
  }

  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      cout << ans[i][j];
      if(j < w-1) cout << " ";
      else cout << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;
int main(){
  ll mod = pow(10,9) + 7;
  ll n,m;
  cin >> n >> m;
  vector<ll> ng(m);
  vector<ll> dp(n + 1);
  for(int i = 0;i < m;i++){
    cin >> ng[i];
  }
  sort(ng.begin(),ng.end());
  ll now = 0;
  //cout << 0 << endl;
  if(n >= 1)dp[1] = 1;
  if(n >= 2)dp[2] = 2;
  //cout << 2 << endl;
  if(n >= 1 && m >= 1){
  if(ng[now] == 1){
    dp[1] = 0;
    if(n >= 2)dp[2] = 1;
    now++;
  }
  }
  //cout << 3 << endl;
  if(n >= 2 && m >= 2){
  if(ng[now] == 2){
    dp[2] = 0;
    now++;
  }
  }
  //cout << 1 << endl;
  for(int i = 3;i < n + 1;i++){
    dp[i] = dp[i - 1] + dp[i - 2];
    dp[i] %= mod;
    if(m > now){
    while(i >= ng[now]){
      if(ng[now] == i)dp[i] = 0;
      now++;
    }
    }
  }
  cout << dp[n] % mod << endl;
}

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

using namespace std;
int main()
{
    int n, x, cnt=0, i, cnt2=0;
    cin >> n;
    for(i=0;i<n;i++)
    {
        cin >> x;
        if(x%4==0) cnt++;
        else if(x%2==0) cnt2++;
    }
    cnt += cnt2/2;
    if(cnt*2+1 >= n) puts("Yes");
    else puts("No");
    return 0;
}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int main() {
  in(int, n);
  vector<ll> a(n + 1), b(n);
  rep(i, n + 1) cin >> a[i];
  rep(i, n) cin >> b[i];
  ll sum = accumulate(all(b), 0LL);
  rep(i, n) {
    ll s = min(a[i], b[i]);
    b[i] -= s;
    a[i] -= s;
    s = min(a[i + 1], b[i]);
    b[i] -= s;
    a[i + 1] -= s;
  }
  out(sum - accumulate(all(b), 0LL));
}


Measured memory_bytes: 4828
n, m, c = io.read("*n", "*n", "*n")
b = {}
for i = 1, m do
  b[i] = io.read("*n")
end
r = 0
for i = 1, n do
  z = c
  for i = 1, m do
    a = io.read("*n")
    z = z + a * b[i]
  end
  if 0 < z then r = r + 1 end
end
print(r)


Measured memory_bytes: 760
function Main(inp) {
    var input = inp.split("\n");
    var n = Number(input[0]);
    var t = Number(input[1].split(' ')[0]);
    var a = Number(input[1].split(' ')[1]);
    var heights = input[2].split(' ').map(function(n) { return Number(n);});
    var diff = Number.MAX_VALUE;
    var index = -1;
    heights.forEach(function (h, i) {
        var d = Math.abs((t - h * 0.006) - a);
        if (d < diff) {
            diff = d;
            index = i; 
        }
    });
    console.log(index + 1);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1e9 + 7

using namespace std;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(void)
{
    int a, b;
    cin >> a >> b;
    cout << ((b >= a) ? a : a - 1) << endl;
    return 0;
}

Measured memory_bytes: 256
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int W,H,x,y; R(W,H,x,y);
    printf("%.12f %d\n",(LL)W*H*0.5,(x*2==W&&y*2==H)?1:0);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int n,m;
vector<vector<int>> graph(10);
vector<int> reached(10);

int dfs(int p, bool visited[10])
{
    bool all_visited = true;

    REP(i, n) {
        if(!visited[i]) {
            all_visited = false;
        }
    }
    if(all_visited) {
        return 1;
    }

    int ret = 0;

    REP(i, graph[p].size()) {
        int n = graph[p][i];
        if(visited[n]) {
            continue;
        }

        visited[n] = true;
        ret += dfs(graph[p][i], visited);
        visited[n] = false;
    }

    return ret;
}

int main() {
    cin >> n >> m;

    REP(i, m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    bool visited[10] = {};
    visited[0] = true;
    cout << dfs(0, visited) << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

    constexpr ll N = 160 * 80 + 1;
    bitset<N> dp[85][85];

int main() {
    init();
    ll H, W;
    cin>>H>>W;
    vvc<ll> A(H, vl(W)), B(H, vl(W));
    rep(i,H)rep(j,W){
        cin >> A[i][j];
    }
    rep(i,H)rep(j,W){
        cin >> B[i][j];
    }

    vvc<ll> C(H, vl(W));
    rep(i,H)rep(j,W){
        C[i][j] = abs(A[i][j] - B[i][j]);
    }

    dp[0][1].set(0);
    rep(h,H)rep(w,W){
        ll c = C[h][w];
        rep(i,N){
            if (dp[h + 1][w][i]||dp[h][w+1][i])
                dp[h + 1][w + 1].set(abs(i-c)).set(i+c);
        }

        // rep(k, N) {
        //     if (dp[h + 1][w + 1][k]) cout << h << " " << w << " " << k << endl;
        // }
    }

    ll ans = 0;
    rep(i,N){
        if(dp[H][W][i]){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}

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


void solve(std::vector<long long> A) {
    cout << *max_element(A.begin(), A.end()) - *min_element(A.begin(), A.end()) << endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::vector<long long> A(3);
    for(int i = 0 ; i < 3 ; i++){
        scanf("%lld",&A[i]);
    }
    solve(std::move(A));
    return 0;
}


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

int main() {
  double a, b, h, m;
  cin >> a >> b >> h >> m;

  const double PI = acos(-1);
  double tm = 2 * PI / 60 * m;
  double th = 2 * PI / 720 * (60 * h + m);
  double t = abs(th - tm);
  t = min(2 * PI - t, t);

  cout << fixed << setprecision(15);
  cout << sqrt(a*a + b*b - 2*a*b*cos(t)) << endl;
  return 0;
}

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


def comb(n, k):
    if n < k or k < 0:
        return 0

    res = 1
    for i in range(1, k + 1):
        res = res * (n - i + 1) % MOD
        res = res * pow(i, MOD - 2, MOD) % MOD
    return res


N, A, B = map(int, input().split())
x1 = comb(N, A)
x2 = comb(N, B)
print((pow(2, N, MOD) - 1 - x1 - x2) % MOD)


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

int main ()
{
    int N;
    std::cin >> N;
    
    long long A[N];
    for (int i = 0; i < N; i++) 
    {
        std::cin >> A[i];
    }
    
    long long B[N];
    for (int i = 0; i < N; i++) 
    {
        B[i] = A[i] - (i+1);
    }
    
    sort(B, B+N);
    
    int center;
    if (N % 2 == 0)
    {
        //std::cout << "even" << std::endl;
        center = ( B[ (N/2) - 1  ] + B[ N/2 ] ) / 2;
    }
    else
    {
        //std::cout << "odd" << std::endl;
        center = B[ (N/2) ];
    }
    //std::cout << "center: " << center << std::endl;
    
    long long min = 0;
    for (int i = 0; i < N; i++) 
    {
        min += abs(A[i] - (i+1+center));
    }
    
    std::cout << min << std::endl;
    
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <utility>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <stack>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); ++i)

const int INF = 1 << 28;

int main()
{
  for(;;) {
    string str;
    getline(cin, str);

    if(str == ".") {
      break;
    }

    stack<int> list;
    int pl = 0;
    int kl = 0;
    bool flag = true;
    for(char c : str) {
      switch (c) {
        case '(':
          ++pl;
          list.push(0);
          break;
        case '[':
          ++kl;
          list.push(1);
          break;
        case ')':
          flag &= pl > 0;
          if(flag) {
            flag &= list.top() == 0;
            list.pop();
          }
          --pl;
          break;
        case ']':
          flag &= kl > 0;
          if(flag) {
            flag &= list.top() == 1;
            list.pop();
          }
          --kl;
          break;
      }
    }
    flag &= pl == 0;
    flag &= kl == 0;

    cout << (flag ? "yes" : "no") << endl;
  }

  return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
const int MAX_V = 1e5 + 1;

int N, mcolor;
map<P, int> mp;
vector<vector<int>> G(MAX_V);

void dfs(int v, int p, int color) {
    int nc = 1;
    // cout << v << " " << p << endl;
    rep(i, G[v].size()) {
        if (G[v][i] == p) continue;
        if (color == nc) nc++;
        dfs(G[v][i], v, nc);
        mp[{min(v, G[v][i]), max(v, G[v][i])}] = nc;
        chmax(mcolor, nc);
        nc++;
    }
}
int main()
{
    cin >> N;
    vector<P> AB(N);

    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        AB[i] = {a, b};
        G[a].push_back(b);
        G[b].push_back(a);
        mp[AB[i]] = -1;
    }

    dfs(0, -1, 0);

    cout << mcolor << endl;
    rep(i, N - 1) {
        cout << mp[AB[i]] << endl;
    }
    return 0;
}

Measured memory_bytes: 17660
/+ dub.sdl:
    name "A"
    dependency "dcomp" version=">=0.0.2"
+/

import std.algorithm, std.range, std.stdio, std.math, std.conv, core.bitop;

// import dcomp.scanner;
// import dcomp.algorithm;

int n;
struct Edge {
    int to;
    long dist;
}
Edge[][] g;
long md;

T[N] toS(T, int N)(T[N] data){ return data; }

long[2][] dfs(int p) {
    if (g[p].empty) {
        return [[0L, 0L]];
    }
    Edge le = g[p][0], re = g[p][1];
    auto lt = dfs(le.to);
    auto rt = dfs(re.to);
    if (lt.length > rt.length) {
        swap(le, re);
        swap(lt, rt);
    }
    long ld = le.dist, rd = re.dist;
    auto buf = Appender!(long[2][])();
    foreach (co; lt) {
        //co[1] + ld + rd + rco[0] <= md
        int idx = binSearch!((i){return co[1]+ld+rd+rt[i][0] > md;})(-1, rt.length.to!int)-1;
        if (idx == -1) continue;
        buf.put([co[0]+ld, rt[idx][1]+rd].toS);
        buf.put([rt[idx][1]+rd, co[0]+ld].toS);
    }
    auto ans = buf.data;
    sort(ans);
    if (ans.empty) return ans;
    long ma = 10L^^15;
    int co = 0;
    foreach (ref e; ans) {
        if (ma <= e[1]) {
            continue;
        }
        ma = min(ma, e[1]);
        ans[co] = e;
        co++;
    }

    return ans[0..co];
}

//md以下にできるか？
bool solve(long _md) {
    md = _md;
    return !dfs(0).empty;
}

int main() {
    auto sc = new Scanner();
    int n;
    sc.read(n);
    g = new Edge[][](n);
    foreach (i; 1..n) {
        int a; long b;
        sc.read(a, b); a--;
        g[a] ~= Edge(i, b);
    }

    writeln(binSearch!solve(-1L, 10L^^12));
    return 0;
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

class Scanner {
    import std.stdio : File, readln, stdin;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeString, isDynamicArray;
    import std.algorithm : map;
    File f;
    this(File f = stdin) {
        this.f = f;
    }
    string[] buf;
    bool succ() {
        while (!buf.length) {
            if (f.eof) return false;
            buf = readln.split;
        }
        return true;
    }
    int read(Args...)(auto ref Args args) {
        foreach (i, ref v; args) {
            if (!succ()) return i;
            alias VT = typeof(v);
            static if (!isSomeString!VT && isDynamicArray!VT) {
                v = buf.map!(to!(ElementType!VT)).array;
                buf.length = 0;
            } else {
                v = buf.front.to!VT;
                buf.popFront();
            }
        }
        return args.length;
    }
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/algorithm.d */
// module dcomp.algorithm;

//[0,0,0,...,1,1,1]で、初めて1となる場所を探す。pred(l) == 0, pred(r) == 1と仮定
T binSearch(alias pred, T)(T l, T r) {
    while (r-l > 1) {
        T md = (l+r)/2;
        if (!pred(md)) l = md;
        else r = md;
    }
    return r;
}


Measured memory_bytes: 45308
#include <stdio.h>

int
bubble_sort(int *A, int N)
{
    int i = 0, j, tmp;
    int flg = 1;
    int cnt = 0;

    while (flg) {
        flg = 0;
        for (j = N -1; j > i; j--) {
            if (A[j] < A[j - 1]) {
                tmp = A[j];
                A[j] = A[j - 1];
                A[j - 1] = tmp;
                flg = 1;
                cnt++;
            }
        }
        i++;
    }
    return cnt;
}

void
print_array(int *a, int n)
{
    int i;

    for (i = 0; i < n; i++) {
        printf("%d", a[i]);
        if (i != (n - 1))
            printf(" ");
    }
    printf("\n");
}

int
main()
{
    int N, i, cnt;
    int A[100];

    scanf("%d", &N);

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

    cnt = bubble_sort(A, N);
    print_array(A, N);
    printf("%d\n", cnt);
}


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

typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

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

const ll INF = 1e18;
const ll MOD = 998244353;
const ll MX = 100005;

int N, M, A, B;
int height[MX];
vector<int> graph[MX];

int valid(int v) {
    if (graph[v].size() == 0) {
        return 1;
    }
    
    for (auto& u : graph[v]) {
        if (height[u] >= height[v]) return 0;
    }

    return 1;
}

void solve() {
    cin >> N >> M;
    for (int i = 0; i < N; i++) cin >> height[i];
    for (int i = 0; i < M; i++) {
        cin >> A >> B;
        A--; B--;
        graph[A].push_back(B);
        graph[B].push_back(A);
    }
    
    int ans = 0;
    for (int i = 0; i < N; i++) {
        ans += valid(i);
    }
    cout << ans;
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    ll T = 1; // cin >> T;
    while (T--) solve();
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


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

int main(){
    int a, b, t; cin >> a >> b >> t;

    cout << b * (int)((t + 0.5) / a) << endl;
}

Measured memory_bytes: 256