akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    n++;
    vector<ll> dp(n);
    dp[0] = 1; dp[1] = 1;
    rep(i, n - 2) {
        dp[i + 2] = dp[i] + dp[i + 1];
    }
    cout << dp[n - 1] << endl;
    return 0;
}



Measured memory_bytes: 3136
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int t = sc.nextInt();
    int ans = 2000;
    for(int i = 0; i < n; i++) {
      int c = sc.nextInt();
      int time = sc.nextInt();
      if(time <= t) ans = Math.min(ans, c);
    }
    if(ans < 2000) {
      System.out.println(ans);
    } else {
      System.out.println("TLE");
    }
  }
}

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

#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;

const int MOD = 998244353;
const ll INF = 1e16;

int main() {
    FASTIO

    int n, k;
    cin >> n >> k;
    int b[k][2];
    for(int i=0; i<k; i++) {
        cin >> b[i][0] >> b[i][1];
    }
    
    vector<int> dp(n+1,0);
    dp[1] = 1;
    for(int i=2; i<=n; i++) {
        for(int j=0; j<k; j++) {
            dp[i] += dp[max(i-b[j][0],0)] - dp[max(i-b[j][1]-1,0)];
            if(dp[i] < 0) dp[i] += MOD;
            else dp[i] %= MOD;
        }
        dp[i] += dp[i-1];
        if(dp[i] < 0) dp[i] += MOD;
        else dp[i] %= MOD;
    }
    int ways = dp[n]-dp[n-1];
    if(ways < 0) cout << ways+MOD << "\n";
    else cout << ways%MOD << "\n";
        
    return 0;
}


Measured memory_bytes: 3972
#include<cstdio>
#include<cstring>
#include<list>
#include<algorithm>
using namespace std;

int main() {
	list<int> L;
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		char s[15];
		int  x;
		scanf("%s", s);
		if (s[0] == 'i') {
			scanf("%d", &x);
			L.push_front(x);
		}
		else {
			if (s[6] == 'F') L.pop_front();
			else if (s[6] == 'L') L.pop_back();
			else if (s[0] == 'd') {
				scanf("%d", &x);
				for (list<int> ::iterator it = L.begin(); it != L.end(); it++) {
					if (*it == x) {
						L.erase(it);
						break;
					}
				}
			}
		}
	}
	int i = 0;
	for (list<int>::iterator it = L.begin(); it != L.end(); it++) {
		if (i++) printf(" ");
		printf("%d", *it);
	}
	puts("");
}


Measured memory_bytes: 33900
import sys
input = sys.stdin.readline
n = int(input())

ans = 0
num3 = n // 3
if num3 >= 1:
    ans += (num3 * 3 + 3) * num3 // 2
num5 = n // 5
if num5 >= 1:
    ans += (num5 * 5 + 5) * num5 // 2
num15 = n // 15
if num15 >= 1:
    ans -= (num15 * 15 + 15) * num15 // 2
print((1 + n) * n // 2 - ans)


Measured memory_bytes: 9188
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> P;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(x) cout << (x) << endl;
const int INF = 1e+8+7;
ll n,m;
string s,t;
int d[100],dp1[500][500],dp2[500][500];
vi vec;

ll func(ll n){
  ll m = 0;
  while(n != 0){
    m += n%10;
    n/=10;
  }
  return m;
}

int main(){
  cin >> n;
  if(n % func(n) == 0)puts("Yes");
  else puts("No");
  return 0;
}

Measured memory_bytes: 256
f=lambda line,x:line[0]*x+line[1]
def _add_line(line,k,l,r):
    m=(l+r)//2
    if not data[k]:
        data[k]=line
        return
    lx,mx,rx=X[l],X[m],X[r-1]
    left,mid,right=f(line,lx)<f(data[k],lx),f(line,mx)<f(data[k],mx),f(line,rx)<f(data[k],rx)
    if left and right:
        data[k]=line
        return
    if not left and not right:return
    if mid:data[k],line=line,data[k]
    if left!=mid:_add_line(line,2*k+1,l,m)
    else:_add_line(line,2*k+2,m,r)
def add_line(line,a,b):
    L,R=a+N0,b+N0
    a0,b0=a,b
    sz=1
    while L<R:
        if R&1:
            R-=1
            b0-=sz
            _add_line(line,R-1,b0,b0+sz)
        if L&1:
            _add_line(line,L-1,a0,a0+sz)
            L+=1
            a0+=sz
        L>>=1
        R>>=1
        sz<<=1
def query(k):
    x=X[k]
    k+=N0-1
    s=10**18
    while k>=0:
        if data[k]:
            t=f(data[k],x)
            if t<s:s=t
        k=(k-1)//2
    return s
n,*t=map(int,open(0).read().split())
t,v=t[:n],t[n:]
st=sum(t)*2
m=a=i=0
N0=2**(st).bit_length()
data=[None]*(2*N0+1)
X=list(range(st+1))+[10**18]*N0
i=b=0
add_line((.5,0),0,st+1)
for u,w in zip(t,v):
    u+=u+i
    add_line((0,w),i,u)
    add_line((-.5,w+i/2),0,i+1)
    add_line((.5,w-u/2),u,st+1)
    i,b=u,w
add_line((-.5,st/2),0,st+1)
a=x=0
for i in range(1,st+1):
    y=query(i)
    a+=(x+y)/4
    x=y
print(a)

Measured memory_bytes: 6900
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
// DONT USE MEMSET, USE VECTORS

vector<int> g[2][500001];
vector<int> vis[2];
map<pair<int,int>,int > mpp;

void dfs(int u, int vn, int gn){
	// cout<<u<<endl;
	vis[gn][u] = vn;
	for(int v:g[gn][u]){
		if(!vis[gn][v]){
			dfs(v,vn,gn);
		}
	}
}

void solve(){
	int n,k,l;
	cin>>n>>k>>l;
	for(int i=0;i<k;i++){
		int u,v;
		cin>>u>>v;
		g[0][u].pb(v);
		g[0][v].pb(u);
	}
	for(int i=0;i<l;i++){
		int u,v;
		cin>>u>>v;
		g[1][u].pb(v);
		g[1][v].pb(u);
	}
	vis[0].resize(n+1);
	vis[1].resize(n+1);
	// cout<<"ok"<<endl;
	int vn = 1;
	for(int i=1;i<=n;i++){
		if(!vis[0][i]){
			dfs(i,vn,0);
			vn += 1;
		}
	}
	vn = 1;
	for(int i=1;i<=n;i++){
		if(!vis[1][i]){
			dfs(i,vn,1);
			vn += 1;
		}
	}
	for(int i=1;i<=n;i++){
		mpp[mp(vis[0][i],vis[1][i])] += 1;
	}

	for(int i=1;i<=n;i++){
		cout<<mpp[mp(vis[0][i],vis[1][i])]<<" ";
	}
	cout<<endl;




}

int main(){
	fastread;
	int t = 1;
	// cin>>t;
	for(int i=1;i<=t;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}


Measured memory_bytes: 41984
def main():
    N, M, X = map(int, input().split())
    C = [0 for _ in range(N)]
    A = [[0 for _ in range(M)] for _ in range(N)]

    books = []

    for i in range(N):
        item = list(map(int, input().split()))
        books.append((item[0], item[1:]))
        C[i] = item[0]
        A[i] = item[1:]

    # understanding = [0 for _ in range(M)]
    # cost = 0
    #
    # for c, a in books:
    #     cost += c
    #     for i in range(len(a)):
    #         understanding[i] += a[i]
    #
    # if min(understanding) < X:
    #     print(-1)
    # else:
    #     for c, a in sorted(books, key=lambda x: x[0]):
    #         if all([understanding[i] - a[i] >= X for i in range(len(a))]):
    #             understanding = [understanding[i] - a[i] >= X for i in range(len(a))]
    #             cost -= c
    #
    #     print(cost)

    min_cost = float('inf')

    for i in range(2 ** N):
        cost = 0
        understanding = [0 for _ in range(M)]

        for j in range(N):
            if i & (2 ** j):
                cost += C[j]
                understanding = [understanding[k] + A[j][k] for k in range(M)]

        # print(i, cost, understanding)

        if all([understanding[k] >= X for k in range(M)]) and cost < min_cost:
            min_cost = cost

    if min_cost == float('inf'):
        print(-1)
    else:
        print(min_cost)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9268
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main(){

ll h,w;
cin>>h>>w;

vector<string> v(h);

bool arr1[500] = {false};
bool arr2[500] = {false};

for(ll i=0;i<h;i++)
{
    cin>>v[i];
}

for(ll i=0;i<h;i++)
{
    for(ll j=0;j<w;j++)
    {
        if(v[i][j]=='#')
        {
            arr1[i] = true;
            break;
        }
    }
}


for(ll i=0;i<w;i++)
{
    for(ll j=0;j<h;j++)
    {
        if(v[j][i]=='#')
        {
            arr2[i] = true;
            break;
        }
    }
}

vector<string> ans;


for(ll i=0;i<h;i++)
{
    string temp;
    if(!arr1[i])
        continue;
    for(ll j=0;j<w;j++)
    {
        if(!arr2[j])
            continue;
        temp += v[i][j];
    }
    ans.push_back(temp);
}

//cout<<ans[0].size();

for(ll i=0;i<ans.size();i++)
{
    for(ll j=0;j<ans[0].size();j++)
    {
        cout<<ans[i][j];
    }
    cout<<endl;
}

return 0;
}


Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	r = 0
	k = zeros(Int,9,9)
	for i in 1:n
		x = div(i,10^r)
		y = i%10
		if y!=0
			k[x,y] += 1
		end
		if i==9||i==99||i==999||i==9999||i==99999
			r += 1
		end
	end
	s = 0
	for i in 1:9
		for j in 1:9
			s += k[i,j]*k[j,i]
		end
	end
	println(s)
end

main()

Measured memory_bytes: 112264
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner in = new Scanner(System.in);
    int a = in.nextInt();
    int b = in.nextInt();
    int k = in.nextInt();
    if(k<b-a){
      for(int i = a;i<a+k&&i<=b-k;i++){
        System.out.println(i);
      }
      for(int i = b-k+1;i<=b&&i>=a;i++){
        System.out.println(i);
      }
    }
    else{
      for(int i=a;i<=b;i++){
        System.out.println(i);
      }
    }
  }
}


Measured memory_bytes: 24020
import java.util.Scanner;

class Main {
    public static void main (String args[]) {
	Scanner scan = new Scanner(System.in);
	double a, b, c, d, e, f, x, y;

	while (scan.hasNext()) {
	    a = scan.nextDouble();
	    b = scan.nextDouble();
	    c = scan.nextDouble();
	    d = scan.nextDouble();
	    e = scan.nextDouble();
	    f = scan.nextDouble();
	
	    x = (c*e - b*f)/(a*e - b*d);
	    y = (c*d - a*f)/(b*d - a*e);

	    if (x == -0.0) x = 0.0;
	    if (y == -0.0) y = 0.0;
	    System.out.printf("%.3f %.3f\n", x, y);
	}
    }
}

Measured memory_bytes: 28176
#include <iostream>
#include <vector>
using namespace std;
int l[55556]={0};

int main(){
    int N;
    for(int i=0;i<55556;i++){
        l[i]=i;
    }
    for(int i=2;i*i<55556;i++){
        if(!l[i]){continue;}
        for(int j=i+1;j<55556;j++){
            if(!l[j]){continue;}
            if(!(l[j]%l[i])){l[j]=0;}
        }
    }
    vector<int> v;
    for(int i=2;i<55556;i++){
        if(l[i]%5==1){v.push_back(l[i]);}
    }
    cin>>N;
    for(int i=0;i<N;i++){
        cout<<v[i];
        if(i<N-1){cout<<" ";}
        else{cout<<endl;}
    }
    return 0;
}


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


using namespace std;

vector<vector<long long>> dp;

int main(int argc, char const *argv[])
{
	string str;
	cin >> str;
	dp.assign(str.size(),vector<long long>(3,INT_MIN));
	dp[0][0]=1;
	string tmp="",tmp2="";
	for (int i = 1; i < str.size(); ++i)
	{
		if (i-1>=0)
		{
			tmp="";
			tmp2="";
			tmp+=str[i];
			tmp2+=str[i-1];
			dp[i][0]=max(dp[i][0],dp[i-1][1]+1);
			dp[i][0]=max(dp[i][0],dp[i-1][2]+1);
			if (tmp!=tmp2)
			{
				dp[i][0]=max(dp[i][0],dp[i-1][0]+1);
			}
		}
		if (i-2>=0)
		{
			tmp="";
			tmp2="";
			tmp+=str[i]+str[i-1];
			dp[i][1]=max(dp[i][1],dp[i-2][0]+1);
			dp[i][1]=max(dp[i][1],dp[i-2][2]+1);
			if (i-3>=0)
			{
				tmp2+=str[i-2]+str[i-3];
			}
			if (tmp!=tmp2)
			{
				dp[i][1]=max(dp[i][1],dp[i-2][1]+1);
			}
		}
		if (i-3>=0)
		{
			tmp="";
			tmp2="";
			tmp+=str[i]+str[i-1]+str[i-2];
			dp[i][2]=max(dp[i][2],dp[i-3][0]+1);
			dp[i][2]=max(dp[i][2],dp[i-3][1]+1);
			if (i-5>=0)
			{
				tmp2="";
				tmp2+=str[i-3]+str[i-4]+str[i-5];
			}
			if (tmp!=tmp2)
			{
				dp[i][2]=max(dp[i][2],dp[i-3][2]+1);
			}
		}
	}
	long long k=max(dp[str.size()-1][0],dp[str.size()-1][1]);
	k=max(dp[str.size()-1][2],k);
	cout << k << "\n";
	return 0;
}

Measured memory_bytes: 11396
import sys
#input = sys.stdin.buffer.readline


# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np

def main():
	s=input()
	ans="No"
	if s in ["hi","hihi","hihihi","hihihihi","hihihihihi"]:
		ans="Yes"
	print(ans)

if __name__ == "__main__":
	main()


Measured memory_bytes: 38384
#include <stdio.h>
#include <math.h>

int main(){
    int x, n, t;

    scanf("%d %d %d",&n,&x,&t);

    // printf("%d %d %f\n",n,x,(double)n/(double)x);
    printf("%d", (int)ceil((double)n/(double)x)*t);

    return(0);
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF= 1LL << 60;
#define REP(i,n) for(ll i=0; i<n; i++)
#define FOR(i,a,n) for(ll i=a; i<n; i++)
// #ifdef DEBUG 
int main(){
    int n;
    cin >> n;
    ll A[n],B[n];
    REP(i,n) cin >> A[i];
    ll m=-INF;
    B[0]= INF;
    FOR(i,1,n){
        B[i]= (A[i-1]<B[i-1])?A[i-1]:B[i-1];
    }
    REP(i,n) m=(A[i]-B[i]>m)?A[i]-B[i]:m;
    cout << m << endl;
}


Measured memory_bytes: 6204
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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; }

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

Measured memory_bytes: 256
from heapq import heappush, heappop
N,Q,*L = map(int, open(0).read().split())
D = L[3*N:]
ls = []
for i in range(N):
  s,t,x = L[3*i],L[3*i+1],L[3*i+2]
  ls.append((s-x,1,x))
  ls.append((t-x,0,x))
for i,d in enumerate(D):
  ls.append((d,2,i))
ls.sort()
ans = [0]*Q
S = set()
hq = []
for a,b,c in ls:
  if b==0:
    S.remove(c)
  elif b==1:
    S.add(c)
    heappush(hq,c)
  else:
    while hq and hq[0] not in S:
      heappop(hq)
    ans[c] = hq[0] if hq else -1
print('\n'.join(map(str,ans)))

Measured memory_bytes: 131628
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

int main(){
  int n; cin >> n;
  ll s = 0LL;
  vi ans;
  int k;
  for(ll i = 1; i <= n; i++) {
    s += i;
    if(s >= n){
      n -= i;
      k = i;
      ans.pb(k);
      break;
    }
  }
  k--;
  while(n > 0){
    if(n-k >= 0){
      n -= k;
      ans.pb(k);
    }
    k--;
  }

  for(auto num : ans) {
    cout << num << endl;
  }
}

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

int main(){
    int K;
    cin >> K;

    int num=7%K;

    if((K%2 == 0) or (K%5 == 0)){//打表打出来的 
        cout << -1 << endl;
        return 0;
    }

    int L = 9*K;

    for(double i = 0;i < L;i++){
        if(num%K == 0){
            cout << i+1;
            break;
        }
        num = (num*10+7)%K;
    }
    return 0;
}


Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5;

int n,m,k,x,y,z;
int a[N],b[N],c[N];
int main(){
    cin>>n>>m>>k;
    for(int i = 0;i < n;i++)
        cin>>a[i];
    for(int i = 0;i < m;i++)
        cin>>b[i];
    int r=-1;
    for(int i = 0;i < k;i++){
        cin>>x>>y>>z;
        if(a[x-1]&&b[y-1]){
            c[++r]=a[x-1]+b[y-1]-z;
        }
    }
    sort(a,a+n),sort(b,b+m),sort(c,c+r+1);
    if(r!=-1){
        if(a[0]+b[0]<=c[0]) cout<<a[0]+b[0];
        else cout<<c[0];
    }
    else cout<<a[0]+b[0];
    return 0;
}


Measured memory_bytes: 1408
#include<cstdio>
#include<cstring>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;
int panduan(char a[],char b[],int n,int m);

int main(){
	int m,n,x;
	int i,j;
	char a[1000];
	char b[1000];
	char temp;
	scanf("%s", a);
	scanf("%s", b);
	n=strlen(a);
	m=strlen(b);
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			if(a[i]>a[j]){
				temp=a[j];
				a[j]=a[i];
				a[i]=temp;
			}
		}
	}
	for(i=0;i<m-1;i++){
		for(j=i+1;j<m;j++){
			if(b[i]<b[j]){
				temp=b[j];
				b[j]=b[i];
				b[i]=temp;
			}
		}
	}
	x=panduan(a,b,n,m);
	if(x==1) printf("Yes\n");
	if(x==0) printf("No\n");
}
int panduan(char a[],char b[],int n,int m){
	int i;
     if(n==m){
     	 for(i=0;i<n;i++){
     	 	 if(a[i]<b[i]) return 1;
             if(a[i]>b[i]) return 0;
         	}
         	if(i==n) return 0;
	 }
       else	if(n < m){
       	   for(i=0;i<m;i++){
     	 	 if(a[i]<b[i]) return 1;
             if(a[i]>b[i]) return 0;
         	}
	   }
       else if(n > m) { 
       	   for(i=0;i<n;i++){
     	 	 if(a[i]<b[i]) return 1;
             if(a[i]>b[i]) return 0;
	 }
	   }
}


Measured memory_bytes: 128
use std::io::{self, BufRead};

fn main() {
    let mut buf = String::new();
    let mut r = io::BufReader::new(io::stdin());

    let (n, _m): (usize, usize) = {
        r.read_line(&mut buf);
        let mut i = buf.split(" ").map(|x| x.trim().parse().unwrap());
        (i.next().unwrap(), i.next().unwrap())
    };

    let mut digits: Vec<i32> = vec![-1; n];

    // false conditions
    //  * leading zero
    //  * same position different number

    let mut ok = true;

    for l in r.lines() {
        let l = l.unwrap();
        let mut iter = l.split(" ").map(|x| x.trim().parse::<i32>().unwrap());
        let s = iter.next().unwrap() as usize - 1;
        let c = iter.next().unwrap();
        if digits[s] >= 0 && digits[s] != c {
            ok = false;
        }
        digits[s] = c;
    }

    if digits.len() == 1 {
        if digits[0] < 0 {
            digits[0] = 0;
        }
    } else {
        if digits[0] < 0 {
            digits[0] = 1;
        }

        ok = ok && digits[0] > 0;
    }

    if ok {
        println!(
            "{}",
            digits
                .iter()
                .rev()
                .enumerate()
                .fold(0, |acm, (i, &n)| acm + (if n <= 0 { 0 } else { n }) * 10_i32.pow(i as u32))
        );
    } else {
        println!("-1");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ss second
#define ff first
#define pb push_back
unordered_map<ll,std::vector<ll>> graph;
unordered_map<ll,ll> vis,dp;
ll level = 0;

ll dfs(ll s,ll l)
{
    level = max(level,l);
    ll ans = 0;
    
    for(ll i=0;i<graph[s].size();i++){
        
        if(vis[graph[s][i]]==0){
            vis[graph[s][i]]=1;
            ans += 1 + dfs(graph[s][i],l+1);
        }
    }
    
    return dp[s] = ans;
        
}

void bfs(ll s,ll k)
{
    queue<pair<ll,ll>> pq;
    
    pq.push({s,0});
    // ll level = 0;
    vector<vector<pair<ll,ll>>> v(level+10);
    
    vis.clear();
    vis[1] = 1;
    
    
    while(!pq.empty())
    {
        auto s = pq.front();
        pq.pop();
        v[s.ss].push_back({dp[s.ff],s.ff});
        // vis[s.ff] = 0;
        for(ll i=0;i<graph[s.ff].size();i++){
            if(vis[graph[s.ff][i]]==0){
                vis[graph[s.ff][i]]=1;
                pq.push({graph[s.ff][i],s.ss+1});
            }
        }
    }
    
    ll ans = 0;
    vector<ll> a;
    
    
    for(ll i=level;i>=0;i--){
        for(ll j=0;j<v[i].size();j++)
        {
            // st.insert({v[i][j].ff,v[i][j].ss});
            a.push_back(i - v[i][j].ff);
        } 
    }
    
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    
    for(ll i:a){
        ans += i;
        k--;
        if(k==0){
            break;
        }
    }
    cout<<ans;
    
}

void solve()
{
    ll n;cin>>n;
    ll ans=0;
    while(n){
        if(n%3!=0 and n%5!=0)   ans += n;
        n--;
    }
    cout<<ans<<endl;
    
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    // ll t;cin>>t;while(t--)
    {
        solve();
    }
    
	return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
 
int main(){
  ll N,M,i,t=0;
  string S;
  cin >> N >> M >>S;
  vector<ll> ans(N);
  i=N;
  while(i>0){
    if(i-M<=0){
      ans.at(t)=i;
      t++;
      break;
    }
    ll x=M;
    while(S.at(i-x)=='1'){
      x--;
      if(x==0){
        cout << -1 << endl;
        return 0;
      }
    }
    ans.at(t)=x;
    i-=x;
    t++;
  }
  rep(j,t){
    cout << ans.at(t-j-1) << " ";
  }
  cout << endl;
}


Measured memory_bytes: 1408
#include "bits/stdc++.h"
using namespace std;

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define pb push_back


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;


/* constant */
const int inf = 1000100010010010;
const int mod = 1e9 + 7;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};


/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


/* general_method */
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; }
//template<typename T> auto cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}

/* main */

int n;
vi arr;

int dp[3010][3010];

int dfs(int left, int right){

    if(left > right) return 0;

    if(dp[left][right] > -inf) return dp[left][right];

    if(((right - left + 1) ^ n) % 2 == 0){
        return dp[left][right] = max(arr[left] + dfs(left + 1, right), arr[right] + dfs(left, right - 1));
    }else{
        return dp[left][right] = min(dfs(left + 1, right) - arr[left], dfs(left, right - 1) - arr[right]);
    }
    


}




signed main(){


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

    n = input();
    rep(i,0,n) arr.push_back(input());

    rep(i,0,3010) rep(j,0,3010) dp[i][j] = -inf;

    print(dfs(0, n - 1));


    




    






    



    


    

}



Measured memory_bytes: 71296
N,W=map(int,input().split())
w=[0]*N
v=[0]*N

for i in range(N):
    w[i],v[i]=map(int,input().split())

dp=[[0]*(W+1) for i in range(N+1)]

for i in range(W+1):
    for g in range(N):
        if i>=w[g]:
            dp[g+1][i]=max(dp[g][i],v[g]+dp[g][i-w[g]])
        else:
            dp[g+1][i]=dp[g][i]
print(dp[N][W])
    

Measured memory_bytes: 120812
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main
{

	public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	public static void main(String[] args)
	{
		// TODO 自動生成されたメソッド・スタブ
		try
		{
			String str1[] = input(1);
			ArrayList<String[]> str2 = new ArrayList<>();
			while(true)
			{
				String str[] = input(1);
				if(str[0].equals("END_OF_TEXT")) break;
				str[0] = str[0].toLowerCase();
				str2.add(str);
			}
			int sum = 0;
			for(int i = 0; i < str2.size(); i++)
			{
				int j = 0;
				while(true)
				{
					try
					{
						String str = str2.get(i)[0].substring(j, str2.get(i)[0].indexOf(" ", j));
						//System.out.println(str);
						if(str.equals(str1[0]))
						{
							sum++;
						}
						j = str2.get(i)[0].indexOf(" ", j) + 1;
					}
					catch(StringIndexOutOfBoundsException e)
					{
						String str = str2.get(i)[0].substring(j);
						//System.out.println(str);
						if(str.equals(str1[0]))
						{
							sum++;
						}
						break;
					}
				}
			}

			System.out.println(sum);
		}
		catch(IOException e)
		{
		}
	}

	public static int SelectionSort(int a[])
	{
		int Select = 0;
		for(int j = 0; j < a.length - 1; j++)
		{
			int[] min = {0, Integer.MAX_VALUE};
			for(int i = j; i < a.length; i++)
			{
				if(min[1] > a[i])
				{
					min[1] = a[i];
					min[0] = i;
				}
			}
			if(j != min[0])
			{
				Select++;
				swap(a, min[0], j);
			}
		}
		return Select;
	}

	public static int BubbleSort(int a[])
	{
		int swapp = 0;
		boolean flag = true;
		while(flag)
		{
			flag = false;
			for(int i = 0; i < a.length - 1; i++)
			{
				if(a[i] > a[i+1])
				{
					swapp++;
					swap(a, i, i+1);
					flag = true;
				}
			}
		}
		return swapp;
	}

	public static void swap(int a[], int x, int y)
	{
		a[x] = a[x] ^ a[y];
		a[y] = a[x] ^ a[y];
		a[x] = a[x] ^ a[y];
	}

	/*
	public static int Calc(int[] a, int f, int e)
	{
		ArrayList<Integer> list[] = new ArrayList[2];
		return e;
	}
	//*/

	public static String[] input(int Num) throws IOException
	{
		String str[] = new String[Num];
		String str2 = br.readLine();
		int j = 0;
		for(int i = 0; i < Num; i++)
		{
			if(i < Num - 1)
			{
				str[i] = str2.substring(j, str2.indexOf(" ", j));
				j = str2.indexOf(" ", j) + 1;
			}
			else
			{
				str[i] = str2.substring(j);
			}
		}
		return str;
	}

}



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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, s = 0, mx = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		mx = max(mx, a);
		s += a;
	}
	if (mx < s - mx) cout << "Yes" << '\n';
	else cout << "No" << '\n';
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int compare(const void *a, const void *b) {
	return *(long int*)b - *(long int*)a;
}

int main()
{
	long long int total_hp = 0, total = 0;
	long int enemy[200000] = { 0 }, buf;
	int num, hissatu, enemy_num, count_num = 0;
	scanf("%d %d", &num, &hissatu);

	for (int i = 0; i < num; i++) {
		scanf("%ld", &enemy[i]);
		total_hp += enemy[i];
	}
	qsort(enemy, 200000, sizeof(long int), compare);


	if (num <= hissatu) {
		printf("0\n");
	}else{
		for (int i = 0; i < hissatu; i++) {
			total_hp -= enemy[i];
		}
		printf("%lld\n", total_hp);
	}

	return 0;
}


Measured memory_bytes: 3324
x = gets.chomp
ary = []
x.size.times do |i|
  if(x[i]=="S")then
    ary.push("S")
  elsif(x[i]=="T")then
    if(ary.last=="S")then
      ary.pop
    else
      ary.push("T")
    end
  end
end
puts ary.size

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

int main(){
  int a,b;
  cin >> a >> b;
  char c[a+b+1];
  for(int i = 0;i < a+b+1;i++){
    cin >> c[i];
  }
  int count_s = 0;
  int count_i = 0;
  for(int i = 0;i < a+b+1;i++){
    if(i != a){
      int C = c[i]-'0';
      if(C >= 0 && C <= 9){
        count_i++;
      }
    }
    else if(c[a] == '-'){
      count_s++;
    }

  }
  if(count_s == 1 && count_i == a+b){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define pb push_back
#define mp make_pair
#define INF 999999999
#define MOD 1000000007
#define sp ' '


//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<long, long> pll;
typedef map<int, int> mint;
typedef set<int> sint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i] << endl;}}

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ddx[8] = {1,0,-1,0,1,-1,-1,1};
const int ddy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){

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

    int n;
    cin >> n;
    int odd = 0;


    rep(i, n) {
        int tmp;
        cin >> tmp;
        if(tmp%2) ++odd;
    }
    JUDGE(!(odd%2));
    return 0;
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;

namespace ABC118
{
    class A
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int A = input[0];
            int B = input[1];
            if (B % A == 0) Console.WriteLine(A + B);
            else Console.WriteLine(B - A);
        }
    }
}


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

int main() {
    int64_t N, M, X;
    cin >> N >> M >> X;
    vector<vector<int64_t>> A(N, vector<int64_t>(M));
    vector<int64_t> C(N);
    for (int64_t i = 0; i < N; i++) {
        cin >> C[i];
        for (int64_t j = 0; j < M; j++) {
            cin >> A[i][j];
        }
    }

    int64_t ans = LLONG_MAX;
    for (int64_t i = 0; i < (1ull << N); i++) {
        int64_t curr_cost = 0;
        vector<int64_t> score(N, 0);
        for (int64_t j = 0; j < N; j++) {
            if (i & (1ull << j)) {
                curr_cost += C[j];
                for (int64_t k = 0; k < M; k++) {
                    score[k] += A[j][k];
                }
            }
        }

        bool ok = true;
        for (int64_t j = 0; j < M; j++) {
            if (score[j] < X) {
                ok = false;
                break;
            }
        }

        if (ok) {
            ans = min(ans, curr_cost);
        }
    }

    cout << (ans != LLONG_MAX ? ans : -1) << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <math.h>
#include <algorithm>
using namespace std;

typedef long long ll;

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> H(N);
    for (int i = 0; i < N;i++){
        cin >> H[i];
    }
    sort(H.begin(), H.end());
    ll size = H.size();
    ll ans = 0;
    for (int i = 0; i < size-K;i++){
        ans += H[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int d = sc.nextInt();
        int ok = d * 2 + 1;
        int ans = n / ok;
        if (n % ok != 0) {
            ans++;
        }
        System.out.println(ans);

        sc.close();
    }
}


Measured memory_bytes: 22356
import java.util.*;
import java.math.*;

class Main{
	static final int INF = 114514810;
	
	public static void main(String[] args){
		int n, k;
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		k = sc.nextInt();
        
        int[] d = new int[k];
        boolean[] v = new boolean[10];
        for(int i = 0; i < 10; i++) v[i] = true; 
		
		for(int i = 0; i < k; i++){
            d[i] = sc.nextInt();
            v[d[i]] = false;
        }
        
        int m = n;
        while(true){
            String str = String.valueOf(m);
            
            boolean fg = true;
            for(int j = 0; j < str.length(); j++){
                if(!v[Character.getNumericValue(str.charAt(j))]) fg = false;
            }
            
            if(fg){
                System.out.println(str);
                return;
            }
            
            m++;
        }
	}
}

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

#define IO          ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int         long long
#define double      long double
#define vi          vector <int>
#define vvi         vector <vi>
#define pii         pair <int,int>
#define vii         vector <pii>
#define nl          '\n'
#define yy          "YES\n"
#define nn          "NO\n"
#define pb          emplace_back
#define all(v)      (v).begin(), (v).end()
#define rall(v)     (v).rbegin(), (v).rend()
#define mod         1000000007
#define PI          3.1415926535897932

vector <string> verdict = {"AC", "WA", "TLE", "RE"};

signed main()
{
        IO;
        int t;
        cin >> t;
        map <string, int> cnt;
        while (t--) {
            string s;
            cin >> s;
            cnt[s]++;
        }
        for (auto &it : verdict) {
            cout << it << " x " << cnt[it] << nl;
        }
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define ll                  long long
#define dl                 double
#define pb                push_back
#define F                  first
#define S                  second
#define endl              "\n"
#define rep(i,a,b)       for(i=a;i<b;i++)
#define all(v)             v.begin(),v.end()
#define allr(v)            v.rbegin(),v.rend()
#define mod              1000000007LL
#define CIN(V,s,n)      for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n)   {for(int i=s;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define CLEAR(V);      for(ll i=0;i<V.size();i++) V[i] = 0;
#define N                  150
#define tmod             998244353LL
using namespace std;

bool sBs(const pair<int,int> &a,const pair<int,int> &b)
{   return (a.second < b.second);   }

ll SUMD(ll n);
ll BS(vector<pair< ll ,ll > > &PS,ll s,ll e,ll ser);
ll MI(ll a, ll m);
//bool P[N+1];
void Sieve(int n=N);
ll Powb(ll b,ll n,ll m);

vector<vector<int> > G(200005);
vector<ll> A(200005),ans(200005,1);

void DFS(ll s,ll p,ll &l,vector<ll> &V)
{
    ll ol = l,ov;
    auto it = lower_bound(V.begin(),(V.begin()+l),A[s]);
    if(it==V.begin()+l) V[l++] = A[s];
    else {ov = (*it); *it = A[s];}
    ans[s] = l;
    for(auto it:G[s]) if(it!=p) DFS(it,s,l,V);
    if(ol==l) *it = ov;
    else l--;
}

int main()
{
fast;
ll q=1,t;
//cin >> q;
while(q--)
{
    ll i,j,n,m,k,l,r,a,b,c=0,d=0,e,g,p,q,u,v,w,x,y,flag=1;
    //n=m=k=i=j=l=r=a=b=c=d=u=v=w=p=x=y=0;
    cin >> k >> a >> b ;
    for(i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            cout << "OK"; return 0;
        }
    }
    cout << "NG";

}
    return 0;
}

//*****************************************************************************************************************************************

ll Powb(ll b,ll n,ll m)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2,m);
    if(n%2==0){return (temp*temp)%m;}
    else{return (b*((temp*temp)%m))%m;}
}

ll SUMD(ll n)
{   ll sum=0;
    while(n>0){sum += n%10;n = n/10;}
    return sum;

}
ll BS(vector<pair<ll,ll> > &PS,ll s,ll e,ll ser)
{
    if(s>e)
        return s;
    ll mid = (s+e)/2;
    if(PS[mid].F==ser)
    {
        return mid;
    }
    else if(PS[mid].F > ser)
    {
        return BS(PS,s,mid-1,ser);
    }
    else
        return BS(PS,mid+1,e,ser);
}
ll MI(ll a, ll m)
{
    ll m0 = m;
    ll 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;
}
/*
void Sieve(int n)
{
    memset(P,true,sizeof(P));
    P[0] = false;
    P[1]= false;
    for(ll i=2;i*i<=n;i++)
    {
        if(P[i])
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                P[j]=false;
            }
        }
    }

}

*/


Measured memory_bytes: 10952
#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
// #define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define eprintf(...) 42
#define dump(x) 42
#define debug(x) 42
#endif

typedef long long ll;

const ll MOD = 1e9 + 7;

void dfs(int k, int color, unordered_map<int, unordered_map<int, int> >& links, vector<int>& colors) {
    if (colors[k] != -1) return;
    colors[k] = color;

    for (const auto link : links[k]) {
//        if (link.second % 2 == 0) {
        dfs(link.first, color+1, links, colors);
//        } else {
//            dfs(link.first, color, links, colors);
//        }
    }
}

void solve(const int N, unordered_map<int, unordered_map<int, int> >& links) {
    vector<int> colors(N+1,-1);
    REP(i,1,N+1) {
        dfs(i, 0, links, colors);
    }

    cout << count(colors.begin()+1, colors.end(), 0) << '\n';

    return;
}

signed main() {
    int N, M;
    cin >> N >> M;
    unordered_map<int, unordered_map<int, int> > links;
    REP(i,0,M) {
        int u,v,w;
        cin >> u >> v >> w;
        links[u][v] = w;
        links[v][u] = w;
    }
    solve(N, links);
    
    return 0;
}



Measured memory_bytes: 26660
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
typedef long long ll;
using namespace std;
const int MAX_N = (1e+5)+1;
int par[MAX_N];//親
int pank[MAX_N];//木の深さ

//n要素で初期化
void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        pank[i]=0;
    }
}

//木の根を求める
int find(int x){
    if(par[x]==x){
        return x;
    }else{
        return par[x]=find(par[x]);
    }
}

//xとyの属する集合を併合
void unite(int x,int y){
    x = find(x);
    y = find(y);
    if(x==y)return;
    if(pank[x]<pank[y]){
        par[x]=y;
    }else{
        par[y]=x;
        if(pank[x]==pank[y])pank[x]++;
    }
}

//xとyが同じ集合に属するか否か
bool same(int x,int y){
    return find(x)==find(y);
}

int main(void){
    int n,m,k;cin>>n>>m>>k;
    init(n);
    vector<vector<int>> f(n);
    vector<int> F(n,0);
    rep(i,m){
        int a,b;cin>>a>>b;a--;b--;
        unite(a,b);
        F[a]++;
        F[b]++;
    }
    map<int,int> mp;
    rep(i,n){
        mp[find(i)]++;
    }
    rep(i,k){
        int c,d;cin>>c>>d;c--;d--;
        f[c].push_back(d);
        f[d].push_back(c);
    }
    rep(i,n){
        int x=mp[find(i)]-F[i]-1;
        rep(j,f[i].size())if(same(i,f[i][j]))x--;
        cout<<x<<" ";
    }
    cout<<endl;
}

Measured memory_bytes: 9984
use proconio::{input, fastout};
use std::collections::VecDeque;

#[fastout]
fn main() {
    input!(
        h: usize,
        w: usize,
        ch: usize,
        cw: usize,
        ds: usize,
        dw: usize,
        s: [String; h],
    );
    let s: Vec<Vec<char>> = s.iter().map(|ss| ss.chars().collect::<Vec<char>>()).collect();
    let dx = vec![1, 0, -1, 0];
    let dy = vec![0, 1, 0, -1];

    let mut dist = vec![vec![-1; w]; h];
    let mut queue: VecDeque<(usize, usize)> = VecDeque::new();

    queue.push_back((ch-1, cw-1));

    dist[ch-1][cw-1] = 0;
    loop {
        match queue.pop_front() {
            Some((x, y)) => {
                let d = dist[x][y];
                for i in 0..4 {
                    let nx = x as isize + dx[i];
                    let ny = y as isize + dy[i];
                    if nx < 0 || ny < 0 { continue; }
                    let nx = nx as usize;
                    let ny = ny as usize;
                    if nx >= h || ny >= w || s[nx][ny] == '#' { continue; }
                    if dist[nx][ny] != -1 && dist[nx][ny] <= d { continue; }
                    queue.push_front((nx, ny));
                    dist[nx][ny] = d;
                }
                for ei in -2..3 {
                    for ej in -2..3 {
                        let nnx = x as isize + ei;
                        let nny = y as isize + ej;
                        if nnx < 0 || nny < 0 { continue; }
                        let nnx = nnx as usize;
                        let nny = nny as usize;
                        if nnx >= h || nny >= w || s[nnx][nny] == '#' { continue; } 
                        if dist[nnx][nny] != -1 && dist[nnx][nny] <= d+1 { continue; }
                        queue.push_back((nnx, nny));
                        dist[nnx][nny] = d+1;
                    }
                }
            },
            None => break,
        }
    }

    println!("{:?}", dist[ds-1][dw-1]);

}


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


def main():
    S = input()
    Sr = S[::-1]

    count = 0

    for s1, s2 in zip(S, Sr):
        if s1 != s2:
            count += 1
    
    print(count // 2)


if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=400010;
int val[N],n,q,cnt,f[N];
ll ans;
struct node
{
	int u,v,w;
	bool operator<(const node&b)const
		{
			return w<b.w;
		}
}e[N<<1];
int find(int x)
{
	if(f[x]!=x)f[x]=find(f[x]);
	return f[x];
}
int main()
{
	n=gi();q=gi();
	memset(val,127,sizeof(val));
	for(int i=1;i<=q;i++)
	{
		int a=gi(),b=gi(),c=gi();
		e[++cnt]=(node){a,b,c};
		val[a]=min(val[a],c+1);
		val[b]=min(val[b],c+2);
	}
	int pos=0;
	for(int i=1;i<n;i++)if(val[pos]>val[i])pos=i;
	for(int i=(pos+1)%n,j=pos;i!=pos;j=i,i=(i+1)%n)
		val[i]=min(val[i],val[j]+2);
	for(int i=0;i<n-1;i++)
		e[++cnt]=(node){i,i+1,val[i]};
	e[++cnt]=(node){n-1,0,val[n-1]};
	sort(e+1,e+cnt+1);
	for(int i=0;i<n;i++)f[i]=i;
	int k=0;
	for(int i=1;i<=cnt;i++)
	{
		int u=e[i].u,v=e[i].v;
		if(find(u)!=find(v))
		{
			ans+=e[i].w,f[find(u)]=find(v);
			k++;
			if(k==n-1)break;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 11008
import java.util.*;
 
public class Main{
    public static void main(String args[] ) throws Exception {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        long num = 1;
        long ans = 0;
        
        if (n - m == 1) {
            for (long i = 1; i <= m; i++) {
                num = (num * i) % 1000000007;
            }
            ans = (num * num) % 1000000007;
            ans = (ans * n) % 1000000007;
        } else if (n - m == -1) {
            for (long i = 1; i <= n; i++) {
                num = (num * i) % 1000000007;
            }
            ans = (num * num) % 1000000007;
            ans = (ans * m) % 1000000007;
        } else if (n - m == 0) {
            for (long i = 1; i <= n; i++) {
                num = (num * i) % 1000000007;
            }
            ans = (num * num) % 1000000007;
            ans = (ans * 2) % 1000000007;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N=200005;
const int mod=1e9+7;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
struct node
{
    ll x,y;
} a[N],b[N];
ll d(node c,node d)
{
    return abs(c.x-d.x)+abs(c.y-d.y);
}
int main()
{
    std::ios::sync_with_stdio(false);
    int n,m;
    while(cin>>n>>m)
    {
        for(int i=1; i<=n; i++)
        {
            cin>>a[i].x>>a[i].y;
        }
        for(int i=1; i<=m; i++)
        {
            cin>>b[i].x>>b[i].y;
        }
        for(int i=1; i<=n; i++)
        {
            ll dis=1e18,p=0;
            for(int j=1; j<=m; j++)
            {
                if(d(a[i],b[j])<dis)
                {
                    dis=d(a[i],b[j]);
                    p=j;
                }
            }
            cout<<p<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 2304
from collections import deque
k = int(input())
q = deque([])
for i in range(1, 10):
    q.append(i)

for i in range(k):
    a = q.popleft()
    if i == k-1:
        print(a)
        exit()
    b = str(a)
    if b[-1] != '0':
        q.append(int(b + str(int(b[-1])-1)))
    q.append(int(b + b[-1]))
    if b[-1] != '9':
        q.append(int(b + str(int(b[-1])+1)))

Measured memory_bytes: 10892
s=[ [] for i in range(3) ]
s[0]=input()
s[1]=input()
s[2]=input()
p=0
while True:
  if len(s[p])==0:
    if p==0:
      print('A')
    elif p==1:
      print('B')
    else:
      print('C')
    exit()
  tmp=s[p][0]
  s[p]=s[p][1:]
  if tmp=='a':
    p=0
  elif tmp=='b':
    p=1
  else:
    p=2


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int n, k;
    cin >> n >> k;
    int ans = k;
    rep(i, n - 1) {
        ans *= ( k - 1 );
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256