akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		int c = sc.nextInt();
	
		int[] bList = new int[m];
		for (int i=0; i<m; i++) {
			bList[i] = sc.nextInt();
		}
		
		int ans = 0;
		for (int j=0; j<n; j++) {
			int count = 0;
			for (int k=0; k<m; k++) {
				count += sc.nextInt() * bList[k];
			}
			if (count+c > 0) {
				ans++;
			}
		}
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 23380
#include "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define FOR(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

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

using LL = long long int;
using LD = long double;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;


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

	int n;
	cin >> n;
	vi cnt(n);

	REP(i, n) {
		int a;
		cin >> a;
		cnt[a]++;
	}

	int h = 2;
	for (int i = n - 1; 1 <= i; i--) {
		if (cnt[i] != h) {
			cout << 0 << endl;
			return 0;
		}

		h = 2 - h;
	}

	LL ans = 1;
	REP(i, n / 2) ans = (ans + ans) % 1000000007;
	cout << ans << endl;
	return 0;
}

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

namespace ABC117_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var sss = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var n = sss[0];
            var m = sss[1];
            var num = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse).ToList();
            num.Sort();
            var dist = new List<int>();
            for (var i = 0; i < m - 1; i++)
            {
                dist.Add(Math.Abs(num[i + 1] - num[i]));
            }
            dist.Sort((a, b) => (b - a));
            long ans = dist.Sum();
            for (var i = 0; i < n - 1; i++)
            {
                if (i == dist.Count())
                    break;
                ans -= dist[i];
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 25436
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
 
int main(){
  int X,Y,A,B,C;
  cin>>X>>Y>>A>>B>>C;
  VI P(A),Q(B),R(C);
  rep(i,A) cin>>P[i];
  rep(i,B) cin>>Q[i];
  rep(i,C) cin>>R[i];
  vector<PII> Z;
  rep(i,A) Z.pb(mp(P[i],1));
  rep(i,B) Z.pb(mp(Q[i],2));
  rep(i,C) Z.pb(mp(R[i],0));
  sort(all(Z),greater<PII>());
  int RR=0,GG=0,MM=0;
  ll ans=0;
  rep(i,10000000){
    if(Z[i].second==0){
      ans+=Z[i].first;
      MM++;
    }else if(Z[i].second==1){
      if(RR>=X) continue;
      ans+=Z[i].first;
      RR++;
    }else{
      if(GG>=Y) continue;
      ans+=Z[i].first;
      GG++;
    }
    if(RR+GG+MM>=X+Y) break;
  }
  cout<<ans<<endl;
}

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

using namespace std;

const int N = 1e5 + 5, ITER = 100;
const double inf = 1e9;

int n;
struct line {
  long long a, b, c;
  line() {}
  double getx(double y) {
    return -(double)(b * y + c)/(double)a; 
  }
  double gety(double x) {
    return -(double)(a * x + c)/(double)b; 
  }
};
line l[N];
int pos[N], id[N];

bool cmp(int le, int ri) {
  return l[le].a * l[ri].b > l[le].b * l[ri].a;
}

pair<double, int> vs[N];

int bit[N];

int get(int x) {
  int ret = 0;
  for (; x; x -= x&-x)
    ret += bit[x];
  return ret;
}
void upd(int x, int v) {
  for (; x <= n; x += x&-x)
    bit[x] += v;
}

double solve() {
  sort(id, id + n, cmp);
  for (int i = 0; i < n; i++)
    pos[id[i]] = i;
  double le = -inf, ri = inf;
  long long all = 1LL * n * (n - 1) / 2;
  for (int iter = 0; iter < ITER; iter++) {
    double mid = (le + ri) / 2.0;
    for (int i = 0; i < n; i++) {
      vs[i] = make_pair(l[i].gety(mid), i);
    }
    sort(vs, vs+n);
    fill(bit, bit+n+1, 0);
    long long cnt = 0;
    // for (int i = 0; i < n; i++)
    //   cerr << id[i] << " ";
    // cerr << " ? " << endl;
    for (int i = 0; i < n; i++) {
      // cerr << vs[i].second << " ";
      cnt += get(pos[vs[i].second] + 1);
      upd(pos[vs[i].second] + 1, 1);
    }
    // cerr << " " << cnt << endl;
    if (cnt * 2 >= all)
      ri = mid;
    else
      le = mid;
  }
  return le;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld %lld %lld", &l[i].a, &l[i].b, &l[i].c);
    l[i].c *= -1;
    if (l[i].b < 0) {
      l[i].a *= -1;
      l[i].b *= -1;
      l[i].c *= -1;
    }
    id[i] = i;
  }
  double x = solve();
  for (int i = 0; i < n; i++) { 
    swap(l[i].a, l[i].b);
    if (l[i].b < 0) {
      l[i].a *= -1;
      l[i].b *= -1;
      l[i].c *= -1;
    }
    id[i] = i;
  }
  double y = solve();
  printf("%.20lf %.20lf\n", x, y);
  return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f|=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int N=200005;
int h,w;
LL tmp=1e9+7;
unordered_map <LL,int> Map;
int Min[N];
int main(){
	Map.clear();
	h=read(),w=read();
	int n=read();
	for (int i=1;i<=h;i++){
		Min[i]=w+1;
		Map[tmp*i+w+1]=1;
	}
	while (n--){
		int x=read(),y=read();
		Map[tmp*x+y]=1;
		Min[x]=min(Min[x],y);
	}
	int x=1,y=1;
	while (1){
		x++;
		if (!Map[tmp*x+y+1])
			y++;
		if (Min[x]<=y){
			printf("%d\n",x-1);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 29556
#include "bits/stdc++.h"
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n];
    int ans = 0;
    map<int,int>m;

    for(int i=0;i<n;i++){
        cin>>a[i];
        m[a[i]]++;
    }
    for(auto x:m){
        int cur = x.second * (x.second - 1);
        cur /= 2;
        ans += cur;
    }
    for(int i=0;i<n;i++){
        int cur = m[a[i]];
        int result = cur * (cur - 1);
        result /= 2;
        cur--;
        int get = cur * (cur - 1);
        get /= 2;
        int nice = ans + get;
        nice -= result;
        cout<<nice<<endl;
    }
    return 0;
    
}



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

string solve(string s) {
  set<char> st;
  for (char c = 'a'; c <= 'z'; ++c)
    st.insert(c);
  for (int i = 0; i < int(s.size()); ++i)
    st.erase(s[i]);
  return s + (*st.begin());
}

int main() {
  string a;
  cin >> a;
  if (int(a.size()) < 26) {
    cout << solve(a) << '\n';
  } else {
    string b = a;
    if (!next_permutation(b.begin(), b.end()))
      return cout << -1 << '\n', 0;
    int k = 25;
    set<char> s;
    while (k > 0 && a[k - 1] > a[k]) {
      s.insert(a[k]);
      --k;
    }
    s.insert(a[k]);
    a = a.substr(0, k);
    a[k - 1] = *s.upper_bound(a[k - 1]);
    cout << a << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
import sys


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


def main() -> None:
    s = next_str()
    ans = sys.maxsize

    for i in range(len(s) - 2):
        x = int(s[i:i + 3])
        ans = min(ans, abs(x - 753))

    print(ans)


if __name__ == '__main__':
    main()

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

int main()
{
    int K, A, B;
    cin >> K >> A >> B;

    for (int i = A; i <= B; i++)
    {
        if (i%K==0)
        {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}

Measured memory_bytes: 3592
// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);
//auto start=high_resolution_clock::now();
//auto end=high_resolution_clock::now();
// cout<<duration_cast<milliseconds>(end-start).count()<<endl;
// variable type var=numeric_limits<variable type>::max()/min();
//#define _GLIBCXX_DEBUG//only for debugging
/*BISMILLAH UR RAHMAN*/ 
/* AUTHOR -CARLOSRAMIREZ *///Perfection is achieved only on the point of collapse
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<fixed<<setprecision(10);
#define endl "\n"
#define pb push_back
#define all(v) v.begin(),v.end()
#define debug(x) std::cerr << #x << ": " << (x) << '\n';
#define sz(x) int(x.size())
#define INF INT_MAX;
using namespace std;
using namespace std::chrono;
typedef long long int ll;
ll arr[int(1e5+10)];
ll store[int(1e5+10)];
int main()
{
  int n;cin>>n;
  for(int i=1;i<=n;++i)
  cin>>arr[i];
  store[1]=0;
  store[2]=abs(arr[2]-arr[1]);
  for(int i=3;i<=n;++i)
  {
    store[i]=min(abs(arr[i]-arr[i-1])+store[i-1],abs(arr[i]-arr[i-2])+store[i-2]);
  }
  cout<<store[n]<<endl;


}
   

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <bitset>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using lint = long long;
using namespace std;

const int MOD = 1000000007;

int main() {
    string S, T;
    cin >> S >> T;

    int res = 0;
    rep(i, 3) {
        if (S[i] == T[i]) res++;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(n):
    if p[i] == i+1:
        if p[i] == n:
            p[i], p[i-1] = p[i-1], p[i]
        else:
            p[i], p[i+1] = p[i+1], p[i]
        count += 1
print(count)






Measured memory_bytes: 83648
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int[] sieve(int n) {
    assert(n > 1);
    auto t = new bool[n + 1];
    int[] primes = [2];
    for (int i = 3; i < t.length; i += 2) {
        if (!t[i]) {
            primes ~= i;
            for (int j = i + i; j < t.length; j += i)
                t[j] = true;
        }
    }
    return primes;
}

void main() {
    int n = 10 ^^ 5;
    auto primes = sieve(n);
    int[int] d;
    foreach (p; primes) d[p] = true;

    bool isLike(int n) {
        if (n % 2 == 0) return false;

        if (n in d && (n + 1) / 2 in d) {
             return true;
        }
        return false;
    }

    auto t = new int[n + 1];
    for (int i = 3; i <= n; i++) {
        t[i] = t[i - 1] + (isLike(i) ? 1 : 0);
    }

    int q = readint;
    for (int i = 0; i < q; i++) {
        auto lr = readints;
        int l = lr[0];
        int r = lr[1];

        writeln(t[r] - t[l - 1]);
    }
}


Measured memory_bytes: 4604
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define fi first 
#define se second
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
// ミント
const int mod = 1e9+7 ;
  //998244353;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//昆布
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n,int k){
    return fact[n]*ifact[n-k] ;
  }
}  ;
 
mint modpow(ll a,ll b){
 if(b==0) return 1 ;
 mint c= modpow(a,b/2) ;
 if(b%2==1) return c*c*a ;
 else return c*c ;
}

mint komb(ll n,ll m){
  mint x=1 ;mint y=1 ;
  rep(i,m){
    x*= n-i ;
    y*= i+1 ;
  }
  return x/y ;
}

 map<ll,ll> factor(ll n){  //素因数とオーダーをマップで管理
  map <ll,ll> ord ;  
  for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            int res=0;
            while(n%i==0){
                n/=i;
                res++;
            }
            ord[i]=res;
        }
    }
   if(n!=1) ord[n]++;
   return ord ;
 }
 

int main(){
  ll h, w , a, b ; cin>> h>>w>>a>>b ;
  ll p= h-a-1 ;
  mint ans=0 ;
  combination c(200005) ;
  rep2(i,b,w-1){
    ans+= c(p+i,p)*c(w-1-i+a-1,a-1) ;
  }
  cout<<ans<<endl ;
    return 0;
  }
   



Measured memory_bytes: 6440
#include <iostream>
#include <vector>
#include <map>

using namespace std;

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

    vector<map<int, int>> evidence(n + 1);
    for (int i = 1; i <= n; i++)
    {
        int a;
        cin >> a;
        for (int j = 1; j <= a; j++)
        {
            int x, y;
            cin >> x >> y;
            evidence[i][x] = y;
        }
    }

    int maxhonestman = 0;

    for (int bit = 0; bit < (1 << n); bit++)
    {
        int counter = 0;
        int isgoodpattern = true;
      
        for (int i = 0; i < n; i++)
        {
            if (bit & (1 << i))
            {
                for (auto &&mp : evidence[i + 1])
                {
                    bool ishonest = bit & (1 << (mp.first - 1));
                    if (!ishonest ^ mp.second)
                        continue;

                    isgoodpattern = false;
                }
                counter++;
            }
        }

        if (isgoodpattern)
            maxhonestman = max(maxhonestman, counter);
    }

    cout << maxhonestman << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int                 long long   
#define double              long double
#define endl                "\n"
#define pb                  push_back
#define PI                  3.1415926535897932384626433832795l
#define F                   first
#define S                   second
#define mp                  make_pair
#define f(i,n)              for(int i=0;i<n;++i)
#define loop(i,a,b)         for (int i=a ; i<b ;++i)
#define fastio              ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v)              (v).begin(),(v).end()
#define rall(v)             (v).rbegin(),(v).rend()
#define gcd(a,b)            __gcd((a),(b))
#define fill(a,value)       memset(a,value,sizeof(a));
#define minn(v)             *min_element(v.begin(), v.end());
#define maxx(v)             *max_element(v.begin(), v.end());
#define print(x)            cout<<(x)<<endl;
#define sum(v)+x            accumulate(v.begin(), v.end(),x);
typedef pair<int,int> pii;  
typedef vector<int> vi;

signed main() 
{
    fastio;
    cout << fixed << setprecision(12);
    int n;
    cin>>n;
    int A[202020];
    int B[202020];
    f(i,n)cin>>A[i+1];
    vi ans;
    for(int i=n;i>=1;i--)
    {
        int cur=0;
        for(int j=i;j<=n;j+=i)
        {
            cur+=B[j];
        }
        cur%=2;
        if(cur!=A[i])
        {
            ans.pb(i);
            B[i]=1;
        }
        
    }
    reverse(all(ans));
    print(ans.size())
    for(auto p:ans)
    {
        cout<<p<<" ";
    }
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 7324
#include<cstdio>
#include<vector>
using namespace std;
vector<int> v[200001];
char s[200002];
int num[200001][2];
int q[200001];
bool used[200001];
int main()
{
	int n,m,x,y;
	scanf("%d%d",&n,&m);
	scanf("%s",s+1);
	for(int i=0;i<m;i++){
		scanf("%d%d",&x,&y);
		v[x].push_back(y);
		v[y].push_back(x);
		num[x][s[y]-'A']++;
		num[y][s[x]-'A']++;
	}
	int k=0;
	for(int i=1;i<=n;i++){
		if(!num[i][0]||!num[i][1]){
			q[k++]=i;
			used[i]=true;
		}
	}
	for(int i=0;i<k;i++){
		for(int j:v[q[i]]){
			if(!used[j]&&!--num[j][s[q[i]]-'A']){
				q[k++]=j;
				used[j]=true;
			}
		}
	}
	puts(k==n?"No":"Yes");
}


Measured memory_bytes: 12928
N=int(input())
F=[]
P=[]
for i in range(N):
  F.append(list(map(int,input().split(' '))))
for i in range(N):
  P.append(list(map(int,input().split(' '))))
res=-1145141919810
for i in range(1023):
  i=bin(i+1 | 0b10000000000)
  i=str(i[3:])
  tmp=0
  for j in range(N):
    count=0
    for k in range(10):
      if int(i[k])==1 and F[j][k]==1:count+=1
    tmp+=P[j][count]
  if tmp>=res:res=tmp
print(res)

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

typedef struct array {
    // the type of elements
    typedef int TYPE;
    
    TYPE* m_data;
    int m_size;
    int m_capacity;

    array(int n) : m_size(n), m_capacity(n+1) {
        m_data = (TYPE*)malloc(m_capacity * sizeof(TYPE));
        if(m_data == NULL){
            printf("failed to initialize an array.\n");
            exit(0);
        }
    }
    ~array(){ free(m_data); }

    // push_back
    void push(TYPE x){
        if(m_size == m_capacity){
            m_capacity *= 2;
            TYPE* new_data = (TYPE*)malloc(m_capacity * sizeof(TYPE));
            if(new_data == NULL){
                printf("failed to resize an array.\n");
                exit(0);
            }
            memcpy(new_data, m_data, m_size * sizeof(TYPE));
            free(m_data);
            m_data = new_data;
        }
        m_data[m_size++] = x;
    }

    // pop_back
    void pop(){
        if(m_size * 2 < m_capacity){
            m_capacity /= 2;
            TYPE* new_data = (TYPE*)malloc(m_capacity * sizeof(TYPE));
            if(new_data == NULL){
                printf("failed to resize an array.\n");
                exit(0);
            }
            memcpy(new_data, m_data, (m_size-1) * sizeof(TYPE));
            free(m_data);
            m_data = new_data;
        }
        m_size--;
    }

    void set(int i, TYPE x){
        if(i < 0 || m_size <= i){
            printf("index out of range: %d\n", i);
            exit(0);
        }
        m_data[i] = x;
    }

    int size() const { return m_size; }

    TYPE get(int i) const {
        if(i < 0 || m_size <= i){
            printf("index out of range: %d\n", i);
            exit(0);
        }
        return m_data[i];
    }
} array;


int main(){
    int n;
    scanf("%d", &n);
    array a(n);
    for(int i = 0; i < a.size(); i++){
        int temp;
        scanf("%d", &temp);
        a.set(i, temp-1);
    }
    int j = 0;
    int cnt = 0;
    while(cnt < a.size()){
        j = a.get(j);
        cnt++;
        if(j == 1) break;
    }
    printf("%d\n", (j == 1 ? cnt : -1));
    return 0;
}

Measured memory_bytes: 3204
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if ("7".equals(s.substring(0, 1))
                || "7".equals(s.substring(1, 2))
                || "7".equals(s.substring(2, 3))) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 27004
#include <iostream>
using namespace std;
int main(void){
    int friends, given, cake, all_cake=0;
    cin >> friends >> given;
    for(int i=0; i<given; i++){
        cin >> cake;
        all_cake += cake;
    }
    if(all_cake%(friends+1)==0){
        cout << all_cake/(friends+1) << endl;
    }
    else cout << all_cake/(friends+1) + 1 << endl;
    return 0;
}



Measured memory_bytes: 3116
#include<bits/stdc++.h>
 using  namespace  std; 
#define int long long 
int32_t  main()
{
 int n, i;int x=0; cin>>n;  string s; cin>>s; int t=1;int s1=s[s.size()-4]-'0';
for(i=s.size()-1;i>=s. size()-2;i--)
{ x+=(s[i]-'0')*t; t=10;}
s1=s1*100+x; 
i=(n*s1)/100;cout<<i; 
}


Measured memory_bytes: 3604
#!/usr/bin/env python
# coding: utf-8

# In[37]:


d, g = map(int, input().split())
pcs = [list(map(int, input().split()))for _ in range(d)]
"""
2 700
3 500
5 800

2 2000
3 500
5 800
"""


# In[ ]:


"""
完全に解くか、全くとかないかを総当たり
完全に解く問題の総score

総scoreが目標scoreを上回っている
 -> 手数を保存
scoreを下回っている
 -> 全く解いていない問題の中から 一つ選び、中途半端に解く
    scoreを上回る場合
     -> 手数に数える
    scoreを下回る場合
     -> continue
"""


# In[35]:


import math


# In[68]:


temp_str = ''
min_nb = float('inf')
# 完全、完全じゃない、全探索
for i in range(2**d):
    #print(i)
    score = 0
    solved_nb = 0
    # j桁目が1の時、j番目のpをscoreに加算
    for j in range(d):
        if (i>>j) & 1:
            score += (j+1) * 100 * pcs[j][0] + pcs[j][1]
            #temp_str += '{}ten {}mon {}perf : total {}\n'.format((j+1)*100, pcs[j][0], pcs[j][1], score)
            solved_nb += pcs[j][0]
    
    # この時点で目標scoreを超えていれば、solved_nbを保存してcontinue
    if score >= g:
        min_nb = min(min_nb, solved_nb)
        #print(temp_str)
        continue
    
    # j桁目が0の中から一つ選び、
    
    #temp_score = score
    #temp_solved_nb = solved_nb
    #print(i)
    for j in range(d):
        
        if bin(i>>j)[-1] == '0':
            #print('a', j, score)
            j_nb = math.ceil((g-score)/((j+1)*100))
            #score_judge = score + pcs[j][1]*j_nb 
            #print('b', j_nb, pcs[j][0])
            if j_nb <= pcs[j][0]-1:
                min_nb = min(min_nb, solved_nb+j_nb)
                #temp_str += '{}ten {}mon: total {}\n'.format((j+1)*100, j_nb, (j+1)*100*j_nb)
                #print(temp_str)
    #print(temp_str)
print(min_nb)


# In[ ]:






Measured memory_bytes: 3064
//Date : 01 - 07 - 18  //Author:Rishabh Paul

#include<bits/stdc++.h>
using namespace std;

// int main() {
// 	int n;
// 	cin >> n;
// 	if(n % 2 == 0)	printf("%d" ,n);
// 	else printf("%d" ,n*2);
// 	return 0;
// }

// int main() {
// 	int n;
// 	cin >> n;
// 	std::vector<int> a(n);
// 	for(int i = 0 ; i < n ; i++)	cin >> a[i];
// 	sort(a.begin() ,a.end());
// 	printf("%d" ,a[n - 1] - a[0]);	
// 	return 0;
// }


int main() {
	int n ,x;
	scanf("%d" ,&n);
	int a[n + 1] ,b[n + 1];
	long long sum = 0LL ,c = 0;
	for(int i = 1 ; i <= n ; i++) {
		scanf("%d" ,&a[i]);
		b[i] = a[i] - i;
	}
	sort(b + 1 ,b + n + 1 ,[](int a,int b) {
		return a < b ;
	});
	long long ans = 0LL ,A = 0 ,B = 0;
	if(n & 1) {
		x = b[n / 2 + 1];
		for(int i = 1 ; i <= n ; i++) 	ans += abs(a[i] - (x + i));
	} else {
		x = b[n / 2];
		for(int i = 1 ; i <= n ; i++)	A += abs(a[i] - (x + i));
		x = b[n / 2 + 1];
		for(int i = 1 ; i <= n ; i++)	B += abs(a[i] - (x + i));	
		ans = min(A ,B)	;
	}
	printf("%lld" ,ans)	;
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
int main(void) {
	int n, count = 0;
	char s[50];
	scanf("%d", &n);
	scanf("%s", s);
	for (int i = 0; i < n - 2; i++) {
		if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
			count++;
	}
	printf("%d\n", count);
	return 0;
}

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

int main()
{
    int k,s;
    cin >> k >> s;
    int count = 0;

    for(int x = 0; x <= 2500; x++){
        for(int y = 0; y <= 2500; y++){
            if((x <= k) && (y <= k) && (s - x - y <= k) && s - x - y >= 0)
                count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
from math import ceil
N = int(input())
dia = [0]*(N-1)
for i in range(N-1):
    c,s,f = map(int,input().split())
    dia[i] = (c,s,f)
for i in range(N-1):
    time = 0
    for j in range(i,N-1):
        c,s,f = dia[j]
        if time > s:
            x = (time - s)/f
            s += ceil(x)*f
        time =  s + c
    print(time)
print(0)










Measured memory_bytes: 42076
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e9;

int main(){
  ll N;
  cin>>N;
  vector<ll>a(N);
  ll sum=0;
  
  for(ll i=0;i<N;i++){
    cin>>a[i];
    sum+=a[i];
  }
  
  cout<<sum-N<<endl;
}

  

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
	public static void main(String[] args)throws NumberFormatException{
		Scanner scan = new Scanner(System.in);
		String answer = "";
		String temp = "";
		
		while(true){
			temp = scan.next();
			if(temp.equals("-")){
				break;
			}
			char[] targetChar = temp.toCharArray();
			int targetLength = temp.length();
			int shuffleTimes = scan.nextInt();
			int shuffleBegin = 0;
 
			for(int i =0; i<shuffleTimes; i++){
				shuffleBegin = scan.nextInt();
				answer = "";
				for(int j=0; j<(targetLength - shuffleBegin) ; j++){
					answer = answer + targetChar[j + shuffleBegin];
				}
				for(int j=0; j<shuffleBegin; j++){
					answer = answer + targetChar[j];
				}
				targetChar = answer.toCharArray();
			}
			System.out.println(answer);
		}
	}
}


Measured memory_bytes: 46064
#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;

vector<int> sieve(int n) {
	vector<int> res(1, 2);
	vector<bool> prime(n, true);
	for(int i = 3; i < n; i += 2) {
		if(prime[i]) {
			res.push_back(i);
			for(int j = i * 3; j < n; j += i * 2)
				prime[j] = false;
		}
	}

	return res;
}

int main() {
	const int MAX = 1000000;
	vector<int> prime = sieve(MAX);

	for(int n; scanf("%d", &n), n;) {
		int ans = 0;
		for(int i = 0, j = prime.size() - 1; i < prime.size(); ++i) {
			while(j >= 0 && prime[i] + prime[j] > n) --j;

   			if(prime[i] + prime[j] == n) {
				ans += 1 + (i == j);
				--j;
			}
		}

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

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1560
/* You can't connect the dots looking forward 
   you can only connect them looking backwards. */

/* Nothing is impossible; impossible itself says "I'm possible" */

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);cout << fixed;
#define dbset(x) for(int i=0 ; i<x.size(); i++) cerr << x[i] << " "; cerr << endl;
#define inf 1000000007
#define INF 1000000000000000000LL
#define PI 3.14159265358979323846
#define mod 1000000007
#define mod1 1000696969
#define flusz fflush(stdout);
#define VI vector<int>
#define VPI vector < pair<int,int> >
#define PII pair<int, int>
#define BIT bitset<N>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define REP(x, y) for(int x = 0; x < (y); ++x)
#define FOR(x, y, z) for(int x = y; x <= (z); ++x)
#define FORR(x, y, z) for(int x = y; x >= (z); --x)
using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<","; _dbg(sdbg+1, a...);
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)

#define int long long
#define N 500007

int test;

int n;

string res;

void solve()
{
    FOR(i,1,11){
        int l = (i==1 ? 1 : 0);
        int r = 10;

        while(l!=r){
            int mid = (l+r)/2;

            string pom = res;

            char c = '0'+mid;

            pom+=c;

            while(pom.size()<=10){
                pom+='9';
            }

            cout << "?" << " " << pom << endl;
            flusz;

            string tmp;

            cin >> tmp;

            if (tmp == "Y"){
                r = mid;
            }else{
                l = mid + 1;
            }
        }

        char c = l + '0';

        res += c;

        if (l == 9 && res.size()==1){
            cout << "?" << " " << "10" << endl;
            flusz;

            string tmp;

            cin >> tmp;

            if (tmp == "N"){
                break;
            }
        }

        if (l == 9 && res.size()!=1){
            string pom = res;
            pom.pop_back();

            pom += "00";

            cout << "?" << " " << pom << endl;
            flusz;

            string tmp;

            cin >> tmp;

            if (tmp == "N"){
                break;
            }
        }else if(l!=9){
            string pom = res;
            pom.pop_back();

            c = l + 1 + '0';

            pom += c;

            cout << "?" << " " << pom << endl;
            flusz;

            string tmp;

            cin >> tmp;

            if (tmp == "Y"){
                break;
            }
        }   
    }

    cout << "! " << res;

    return;
}

int32_t main()
{
    test=1;

    while(test--)
    {
        solve();
    }

  return 0;
}


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

int main() {
    string A, B;
    cin >> A >> B;
    if (A.size()<B.size()) cout << "LESS\n";
    else if (A.size()>B.size()) cout << "GREATER\n";
    else if (A!=B) {
        for (int i=0; i<A.size(); i++) {
            if (A.at(i)==B.at(i)) continue;
            else if (A.at(i)<B.at(i)) {
                cout << "LESS\n";
                return 0;
            }
            else {
                cout << "GREATER\n";
                return 0;
            }
        }
        cout << "EQUAL\n";
    }
    else cout << "EQUAL\n";

}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
const int MOD = 1000000007;
int N, TF[262144], TG[262144], ZF[262144], ZG[262144];
long long a[100001], A, B;
inline int add(int u, int v)
{
	return u + v < MOD ? u + v : u + v - MOD;
}
inline void down(int *T, int *Z, int p)
{
	if (Z[p])
	{
		T[p << 1] = T[p << 1 | 1] = 0;
		Z[p << 1] = Z[p << 1 | 1] = 1;
		Z[p] = 0;
	}
}
int G(int *T, int *Z, int p, int l, int r, int L, int R)
{
	if (L <= l && r <= R)
		return T[p];
	int m = l + r >> 1;
	down(T, Z, p);
	if (R <= m)
		return G(T, Z, p << 1, l, m, L, R);
	if (L > m)
		return G(T, Z, p << 1 | 1, m + 1, r, L, R);
	return add(G(T, Z, p << 1, l, m, L, R), G(T, Z, p << 1 | 1, m + 1, r, L, R));
}
void P(int *T, int *Z, int x, int w)
{
	int p = 1, l = 0, r = N - 1;
	while (l < r)
	{
		int m = l + r >> 1;
		down(T, Z, p);
		if (x <= m)
			p <<= 1, r = m;
		else
			p = p << 1 | 1, l = m + 1;
	}
	T[p] = add(T[p], w);
	while (p > 1)
	{
		p >>= 1;
		T[p] = add(T[p << 1], T[p << 1 | 1]);
	}
}
int main()
{
	scanf("%d%lld%lld", &N, &A, &B);
	a[0] = -1LL << 61;
	for (int i = 1; i <= N; i++)
		scanf("%lld", a + i);
	P(TF, ZF, 0, 1);
	P(TG, ZG, 0, 1);
	for (int i = 2; i <= N; i++)
	{
		int cA = std::upper_bound(a, a + i - 1, a[i] - A) - a - 1;
		int cB = std::upper_bound(a, a + i - 1, a[i] - B) - a - 1;
		int sf = G(TG, ZG, 1, 0, N - 1, 0, cA);
		int sg = G(TF, ZF, 1, 0, N - 1, 0, cB);
		if (a[i] - a[i - 1] < A)
		{
			TF[1] = 0;
			ZF[1] = 1;
		}
		if (a[i] - a[i - 1] < B)
		{
			TG[1] = 0;
			ZG[1] = 1;
		}
		P(TF, ZF, i - 1, sf);
		P(TG, ZG, i - 1, sg);
	}
	printf("%d\n", add(TF[1], TG[1]));
	return 0;
}


Measured memory_bytes: 4992
import java.util.*;

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

        long[] x = new long[n];
        long[] y = new long[n];
        long[] z = new long[n];

        for(int i=0; i<n; i++){
            x[i] = sc.nextLong();
            y[i] = sc.nextLong();
            z[i] = sc.nextLong();
        }

        long[][] sum = new long[8][n];
        long[]   tmp = new long[8];

        for(int i=0; i<n; i++){
            sum[0][i] = x[i] + y[i] + z[i];
            sum[1][i] = x[i] + y[i] - z[i];
            sum[1][i] = x[i] - y[i] + z[i];
            sum[2][i] = x[i] - y[i] - z[i];
            sum[3][i] = x[i] + y[i] + z[i];
            sum[4][i] = -x[i] + y[i] - z[i];
            sum[5][i] = -x[i] + y[i] + z[i];
            sum[6][i] = -x[i] - y[i] - z[i];
            sum[7][i] = -x[i] - y[i] + z[i];
        }

        for(int i=0; i<sum.length; i++){
            Arrays.sort(sum[i]);
            tmp[i] = 0;
            for(int j=0; j<m; j++){
                tmp[i] += sum[i][j];
            }
            tmp[i] = Math.abs(tmp[i]);
        }
        Arrays.sort(tmp);

        System.out.println(tmp[7]);
    }
}

Measured memory_bytes: 27424
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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 solve(const ll n) {
    ll ans = 0;

    for (ll a = 1; a <= n; a++) {
        ll x = a * a;
        if (x > n) {
            break;
        }
        for (ll b = 1; b <= n; b++) {
            ll y = b * b + a * b;
            if (x + y > n) {
                break;
            }
            for (ll c = 1; c <= n; c++) {
                ll z = c * c + b * c + c * a;

                if (z > n) {
                    break;
                }

                if (x + y + z == n) {
                    ans++;
                }
            }
        }
    }

    return ans;
}

int main(void) {
    int N;
    cin >> N;

    for (int i = 1; i <= N; i++) {
        printf("%lld\n", solve(i));
        // solve(i);
    }

    return 0;
}


Measured memory_bytes: 3688
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;

int main(){
	ll a,b,c,x,y;
	cin >> a >> b >> c >> x >> y;
	if(x < y){
		swap(x,y);
		swap(a,b);
	}

	cout << min({x*2*c,(x-y)*a+2*y*c,a*x+b*y,x*2*c+y*b,x*a+2*y*c}) << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define rep2(i, a)for(auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll co(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
int LIS(const vector<int>& a) {
	int N = (int)a.size();
	vector<long long> dp(N, INF);
	for (int i = 0; i < N; ++i) {
		// dp[k] >= a[i] となる最小のイテレータを見つける
		auto it = upper_bound(dp.begin(), dp.end(), a[i]);

		// そこを a[i] で書き換える
		*it = a[i];
	}

	// dp[k] < INF となる最大の k に対して k+1 が答え
	// それは dp[k] >= INF となる最小の k に一致する
	return lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
}
int main()
{
	int n, ans = 0, temp;
	cin >> n;
	vector<int> a(n);
	rep(i, 0, n)cin >> a[i];
	reverse(all(a));
	printf("%d\n", LIS(a));
	return 0;
}

Measured memory_bytes: 4576
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
	int w, a, b;
	cin >> w >> a >> b;
	if (a + w < b) cout << abs(b - a - w) << endl;
	else if (b + w < a) cout << abs(a - b - w) << endl;
	else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ull = unsigned long long int;

#define MATHPI acos(-1)

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

using Mat = vector<vector<ll>>;
using Column = vector<ll>;

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ull N,A,B;
    cin>>N>>A>>B;

    ull r = N % (A+B);
    ull K = N / (A+B);

    if (r<=A) {
        cout << r + K * A << "\n";
    } else {
        cout << A + K * A << "\n";
    }

    return 0;
}


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

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

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

	vector< int> sum(n);

	LL res = 0;

	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;

		if (i - x >= 0) {
			res += sum[i - x];
		}

		if (i + x < n) {
			sum[i + x]++;
		}
	}

	cout << res  << endl;
}

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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define all(x) x.begin(), x.end()
#define PB push_back
#define F first
#define S second

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

#define MAX 100007

int pai[MAX];
int size[MAX];
int ans[MAX];

int find(int x){
	if(x == pai[x]) return x;
	return pai[x] = find(pai[x]);
}

void join(int a, int b){
	a = find(a);
	b = find(b);

	if(a != b){
		if(size[a] < size[b])
			swap(a, b);
		pai[b] = a;
		size[a] += size[b];
	}
}

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

	int n, m, k; cin >> n >> m >> k;
	FOR(i, n) pai[i] = i, size[i] = 1;

	FOR(i, m){
		int a, b; cin >> a >> b;
		a--; b--;
		join(a, b);
		ans[a]--; ans[b]--;
	}

	FOR(i, k){
		int a, b; cin >> a >> b;
		a--; b--;
		if(find(a) == find(b)){
			ans[a]--; ans[b]--;
		}
	}

	FOR(i, n)
		cout << ans[i] + size[find(i)]-1 << " \n"[i==n-1];	

	return 0;
}

Measured memory_bytes: 2048
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    ab = [0] * (N-1)
    num = [0] * N
    l = [[] for _ in range(N)]
    for n in range(N-1):
        a, b = [int(x)-1 for x in input().strip().split()]
        l[a].append(b)
        l[b].append(a)
    C = sorted([int(x) for x in input().strip().split()], reverse=True)
    ans = 0
    q = [0]
    i = 0
    while q:
        c = q.pop()
        num[c] = C[i]
        i += 1
        for n in l[c]:
            if num[n] == 0:
                q.append(n)

    print(sum(num)-C[0])
    print(*num)

if __name__ == '__main__':
    main()

Measured memory_bytes: 11876
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  int A[3][3],N,B[10],C[3][3]={0};
  for (int i(0);i<3;i++) for (int j(0);j<3;j++) cin>>A[i][j];
  cin>>N;
  for (int i(0);i<N;i++) cin>>B[i];
  for (int i(0);i<N;i++){
    for (int j(0);j<3;j++){
      for (int k(0);k<3;k++){
        if (B[i] == A[j][k]){
          C[j][k] = 1;
        }
      }
    }
  }

  for (int i(0);i<3;i++){
    if (C[0][i] == 1 && C[1][i] == 1 && C[2][i] == 1){
      cout << "Yes" << endl;
      return 0;
    }
  }
  for (int i(0);i<3;i++){
    if (C[i][0] == 1 && C[i][1] == 1 && C[i][2] == 1){
      cout << "Yes" << endl;
      return 0;
    }
  }
  if (C[0][0] == 1 && C[1][1] == 1 && C[2][2] == 1){
      cout << "Yes" << endl;
      return 0;
  }
  if (C[0][2] == 1 && C[1][1] == 1 && C[2][0] == 1){
      cout << "Yes" << endl;
      return 0;
  }
  cout << "No" << endl;
  return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef vector<int> vint;
#define rep(i,n) for(int i = 0; i < n; i++)
#define MSG(a) cout << #a << " " << a << endl;

int main()
{
	int n;
	while(cin >> n && n)
	{
		rep(i,9)
		{
			int x;
			cin >> x;
			n -= x;
		}
		cout << n << endl;
	}
}

Measured memory_bytes: 0
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	s := nextStr()
	if len(s) == 1 {
		fmt.Println("0")
		return
	}
	if IsKaibun(s) == true {
		fmt.Println("0")
		return
	}

	n := len(s)
	diff := 0

	for i := 0; i < n/2; i++ {
		c := s[i]
		if c != s[n-i-1] {
			diff++
		}
	}

	fmt.Println(diff)
}

// IsKaibun return IsKaibun
func IsKaibun(s string) bool {
	n := len(s)

	for i, c := range s {
		if c != rune(s[n-i-1]) {
			return false
		}
	}

	return true
}

// ---- readfunc
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int, int>;

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  swap(a, b);
  swap(a, c);
  cout << a << " " << b << " " << c << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=998244353;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
const int N=1e6+5,L=1e6;
bitset<N>vis;int p[N],mu[N],cnt[N],a[N],st[N],c[N],s[N],top,n,m,res;
void init(int n=L){
	mu[1]=1;
	fp(i,2,n){
		if(!vis[i])p[++m]=i,mu[i]=-1;
		for(R int j=1;j<=m&&i*p[j]<=n;++j){
			vis[i*p[j]]=1;
			if(i%p[j]==0)break;
			mu[i*p[j]]=-mu[i];
		}
	}
	fp(i,1,n)upd(mu[i],P);
	fp(i,1,n)for(R int j=i;j<=n;j+=i)upd(s[j],mul(i,mu[i]));
}
int main(){
	scanf("%d",&n);
	init();
	fp(i,1,n)scanf("%d",&a[i]),++cnt[a[i]];
	fp(T,1,L){
		R int sum=0;
		for(R int j=T;j<=L;j+=T)upd(sum,mul(j/T,cnt[j]));
		sum=mul(sum,sum),sum=mul(sum,mul(T,s[T]));
		upd(res,sum);
	}
	fp(i,1,n)res=dec(res,a[i]);
	res=mul(res,(P+1)>>1);
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 18816
#include<iostream>
using namespace std;
#include<iomanip>
#include<map>
#include<algorithm>
#include<cmath>
#define mod 1000000007
#define inf 100000000000000
#define int long long int
int32_t main()
{
    int n;
    cin>>n;
    int arr[3*n];
    int j;
    for(j=0;j<3*n;j++)
        cin>>arr[j];
    sort(arr,arr+3*n);
    int i=0;
    j=3*n-1;
    int answer=0;
    while(i<j)
    {
		answer+=arr[j-1];
		j-=2;
		i++;
	}
	cout<<answer<<endl;
     
}


Measured memory_bytes: 2560
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/g.inp"
exit $?
'''
import sys


def _i(): return int(sys.stdin.readline().strip())


h = _i()

n = 0
while h > 0:
    h //= 2
    n += 1

print(2**n - 1)


Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <map>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define INF 1e10
typedef long long ll;
typedef long double ld;
int main(){
    ll n;
    cin>>n;
    ld t,a;
    cin>>t>>a;
    vector<ld> h(n);
    REP(i,n)cin>>h[i];
    ld ans, m=INF;
    REP(i,n){
        ld temp=t-h[i]*0.006;
        ld dif=abs(temp-a);
        if(m>dif){
            m=dif;
            ans=i+1;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3788