akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N, M, X; cin >> N >> M >> X;
    vector<int> cs(N);
    vector<vector<int>> as(N, vector<int>(M));
    for (int i = 0; i < N; ++i)
    {
        cin >> cs[i];
        for (int j = 0; j < M; ++j) cin >> as[i][j];
    }
    int ans = 1e7;
    for (int bit = 0; bit < (1 << N); ++bit)
    {
        int cost = 0;
        vector<int> degrees(M, 0);
        for (int i = 0; i < N; ++i)
        {
            if (bit & (1 << i))
            {
                cost += cs[i];
                for (int j = 0; j < M; ++j)
                {
                    degrees[j] += as[i][j];
                }
            }
        }
        bool isOK = true;
        for (int j = 0; j < M; ++j)
        {
            if (degrees[j] < X)
            {
                isOK = false;
                break;
            }
        }
        if (isOK)
        {
            ans = min(ans, cost);
        }
    }
    if (ans == 1e7)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << ans << endl;
    }
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#define rep(i,m,n) for(int i=m; i<(n); i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
typedef long long ll;
using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k, n;
    cin >> k >> n;
    int A[n], B[n+1];
    rep(i,0,n) cin >> A[i];
    B[0] = A[0] + k - A[n-1];
    rep(i,1,n) B[i] = A[i] - A[i-1];
    sort(B, B+n);
    cout << k - B[n-1];
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
using namespace std;

int main() {
	int n, T;
	cin >> n >> T;
	vector<int>c(1000), t(1000);
	int tmp = 10000;
	for (int i = 0; i < n; i++) {
		cin >> c.at(i) >> t.at(i);
	}
	for (int i = 0; i < n; i++) {
		if (t.at(i) <= T && c.at(i) <= tmp)
			tmp = c.at(i);
	}
	if (tmp == 10000) {
		cout << "TLE";
	}else
	  cout << tmp;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<iomanip>

int main(){
    double a,b,s;

    std::cin>>a>>b>>s;
    
    double rad= s/180*M_PI;
    double cp= std::pow(a, 2)+ std::pow(b, 2)- 2*a*b*std::cos(rad);
    double c= std::sqrt(cp);
    
    std::cout<<std::fixed<<std::setprecision(4);
    std::cout<<a*b*std::sin(rad)/2 <<std::endl;
    std::cout<<a+ b+ c <<std::endl;
    std::cout<<b*std::sin(rad)<<std::endl;

    return 0;
}


Measured memory_bytes: 3660
///=======================///
/// coder: Andy - Tohrumi ///
///=======================///

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fastio ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for(__typeof(b) i = a; i < b; i++)
#define Rep(i, a, b) for(__typeof(a) i = a; i > b; i--)

using namespace std;

typedef pair<ll, ll> pll;	typedef pair<int, int> ii;
typedef vector<pll> vll;	typedef vector<string> vs;		typedef vector<ii> vii;
typedef vector<int> vi; 	typedef vector<ll> vl;

///====code start here====///

const int N = 305;
double dp[N][N][N];
int num[4];

signed main() {
	fastio;
	int n; cin >> n;
	int a[n];
	rep(i, 0, n) {
		cin >> a[i];
		num[a[i]]++;
	}
	rep(k, 0, n + 1) {
		rep(j, 0, n + 1) {
			rep(i, 0, n + 1) {
				if(i == 0 && j == 0 && k == 0) continue;
				dp[i][j][k] += n;
				if(i > 0) dp[i][j][k] += i * dp[i - 1][j][k];
				if(j > 0) dp[i][j][k] += j * dp[i + 1][j - 1][k];
				if(k > 0) dp[i][j][k] += k * dp[i][j + 1][k - 1];
				dp[i][j][k] /= (double)(i + j + k);
			}
		}
	}
	cout << setprecision(9) << fixed << dp[num[1]][num[2]][num[3]] << endl;
	return 0;
}


Measured memory_bytes: 220740
K, N = map(int, input().split(' '))
A_list = list(map(int, input().split(' ')))

distances = [0] * N
max_dist = 0

for i in range(N):
    if i != N-1:
        distances[i] = A_list[i+1] - A_list[i]
        max_dist = max(max_dist, distances[i])
    else:
        distances[i] = A_list[0] + K - A_list[i]
        max_dist = max(max_dist, distances[i])

print(K - max_dist)


Measured memory_bytes: 26436
import math

def main():
    a, b = map(str, input().split())
    arr = []
    num = int(a)

    arr.append(b[0])
    arr.append(b[2])
    arr.append(b[3])

    dec = int(''.join(arr))

    print((num*dec)//100)





if __name__ == "__main__":
    main()

Measured memory_bytes: 9112
// #include<bits/stdc++.h>
// #define REP(i,n) for(int i=0;i<n;i++)
// using namespace std;
// int main(){
//     double N,K;
//     double maxk=0,maxq=0;
//     cin>>N>>K;
//     vector<double> p;
//     vector<double> s(K,0.0);
//     REP(i,N){
//         double a;
//         cin>>a;
//         p.push_back(a);
//         if(i+1>=K){
//             double q=0;
//             REP(j,K){
//                 q+=p[i-j];
//             }
//             if(maxk<=q){
//                 REP(j,K){
//                     s[j] = p[i-j];

//                 }
//                 maxk=q;
//             }
//         }
//     }
//     double ans = 0;
//     REP(i,K){
//         double w = 0;
//         for(double v=1;v<=s[i];v++){
//             w += v * (1/s[i]);
//         }
//         ans += w;  
//     }

//     printf("%0.13lf",ans);
//     cout<<endl;
// }
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    double N,K;
    cin>>N>>K;
    vector<double> M(N+1);
    REP(i,N+1){
        if(i!=0){
            double p;
            cin>>p;
            double w=0.0;
            for(double q=1;q<=p;q++){
                w+=q*(1/p);
            }
            M[i] = M[i-1] + w;
        }
    }
    double ans = 0.0;
    for(int i=0;i<=N-K;i++){
        ans = max(ans,M[i+K]-M[i]);
    }
    printf("%0.13lf",ans);
    cout<<endl;
}

Measured memory_bytes: 1792
from math import copysign
K,N = map(int,input().split())
A = list(map(int,input().split()))

max_dist = K - A[N-1] + A[0]
s = 0
for i in range(0,N-1):
  if max_dist < A[i+1] - A[i]:
    max_dist = A[i+1] - A[i]
    s = i + 1

B = list(map(lambda x: int(copysign(x+K, x)), A[:s]))
A = A[s:] + B

ans = 0
for j in range(N):
  if j == 0:
    continue
  ans += A[j] - A[j-1]
  
print(ans)

Measured memory_bytes: 33668
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
int main() {
  int n,ans=0,s=0;
  cin>>n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  for(int i=0;i<n;i++){
    for(int j=0;j<=i;j++){
      if(a[j]<=a[i]){
        s++;
      }
    }
    if(s==i+1){
      ans++;
    }
    s=0;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.Scanner;

class Main {

	/*
	 * 着席位置：３列目の中央
	 * 最初はソートした家同士の間隔から
	 * 大きい方から発電機の数だけ除いていたのでおかしくなっていた。
	 * そして何故か最後のテストケースの計算が行われていない…
	 */

	public static void main(String args[]) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int dataset = Integer.parseInt(br.readLine());

		for(int i=0; i<dataset; i++) {
			//家の数と発電機の数の入力
			Scanner scanner = new Scanner(br.readLine());
			int house = scanner.nextInt()
			   ,generater = scanner.nextInt();
			scanner.close();
			//家の座標の入力
			scanner = new Scanner(br.readLine());
			int houseX[] = new int[house];
			for(int j=0; j<house; j++) {
				houseX[j] = scanner.nextInt();
			}
			scanner.close();
			//家の間隔を計算
			LinkedList<Integer> interval = new LinkedList<>();
			for(int j=0; j<house-1;j++) {
				interval.add(houseX[j+1] -houseX[j]);
			}
			//ソート
			interval.sort(new Comparator<Integer>() {
				@Override
				public int compare(Integer o1, Integer o2) {
					if (o1<o2) {
						return -1;
					}else if(o1>o2) {
						return 1;
					}else {
						return 0;
					}
				}
			});
			/*
			 * 家の間隔を全て足す
			 * ただし発電機が２つ以上ある場合は大きい方から
			 * 発電機の数−１個目までを除く
			 */
			int ret = 0;
			for(int j=0; j<interval.size()-(generater-1); j++) {
				ret+=interval.get(j);
			}
			System.out.println(ret);
		}

		br.close();
	}

}



Measured memory_bytes: 106560
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
string s;
cin >> s;
bool f=true;
if(s[0]==s[1] && s[1]==s[2]) cout << "No" << endl;
else cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <cmath>

using namespace std;

void a_meal_delivery(void) {
	int x, a, b;
	cin >> x >> a >> b;

	if (abs(x - a) < abs(x - b)) cout << "A" << endl;
	else                         cout << "B" << endl;
}

int main()
{
    a_meal_delivery();
    return 0;
}

Measured memory_bytes: 3600
import java.util.*;
class Main{
    public static void main(String[] args)
    {
	Scanner in = new Scanner(System.in);
	String s,s2;
	int n,de=0;
	s = in.next();
	n = in.nextInt();
	for(int i=0;i<n;i++)
	    {
		s2 = in.next();
		int ln = s2.length();
	
		while(ln-- > 0)
		    {
			if(s2.contains(s))
			    {
				de++;
				break;
			    }
			s2 = s2.substring(1) + s2.charAt(0);
		    }
	    }
	System.out.println(de);
    }
} //Res***2Dツつウツづアツづ個づーツ参ツ考

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

int main() {
    int N;
    cin >> N;
    vector<int>L(N);
    for (int i = 0; i < N; ++i) {
        cin >> L[i];
    }
    ll ans = 0;
    sort(L.begin(), L.end());
    for (int i = 0; i < N; ++i) {
        for (int j = i+1; j < N; ++j) {
            int k = L[i] + L[j];
            auto iter = lower_bound(L.begin(), L.end(), k);
            int id = iter - L.begin();
            if(id <= j) continue;
            ans += id - 1 - j;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007 
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main(){
	int n,m,c;
	cin >> n >> m;
	vector<pii> sto(n);
	cu(i,0,n){cin >> sto[i].F >> sto[i].S;}
	sort(all(sto));
	ll ans = 0;
	ll pos = 0;
	while(m){
		if(sto[pos].S > 0){
			--sto[pos].S;
			--m;
			ans += sto[pos].F;
		}
		else{
			++pos;
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long llong;
const int inf = 1 << 20;
const int mod = 1e9 + 7;
int main() {
   int x;
   cin >> x;
   cout << x * x * x << endl;
   return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
const int lm=100005,inf =1000000003; 
int a[lm];
pair<int, int> cnt[2][lm];

int main() {
	int n;
    cin>>n;
    for (int i=0;i<n;++i) {
        cin>>a[i];
        ++cnt[i%2][a[i]].first;
    }
    for (int i=0;i<lm;++i) {
        cnt[0][i].second=i;
        cnt[1][i].second=i;
    }
    sort(cnt[0],cnt[0]+lm);
    sort(cnt[1],cnt[1]+lm);
    reverse(cnt[0],cnt[0]+lm);
    reverse(cnt[1],cnt[1]+lm);
    int ans=n;
    for (int i=0;i<3;++i) {
        for (int j=0;j<3;++j) {
            if (cnt[0][i].second!=cnt[1][j].second) {
                ans=min(ans,n-cnt[0][i].first-cnt[1][j].first);
            }
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 2176
(defvar N (read))

(let ((tmp (loop repeat N collect (read))))
     (defvar lst (cons 0 (sort (loop for x1 in tmp
                                     for x2 in (cdr tmp) 
                                     if (= (1+ x1) x2) 
                                     collect x1)
                               #'<))))

(princ (+ (loop repeat N sum (read))
          (loop for x in lst
                for y in (cdr lst)
                do (loop repeat (- y x 1) do (read))
                sum (read)) ))

Measured memory_bytes: 6504
#include <bits/stdc++.h>
 
#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))
 
using namespace std;
 
typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;
 
template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
 
int main(int argc, char *argv[])
{
  lli x, y;
  while (cin >> x >> y) {
    assert(x != y);
    
    map<lli, lli> cost;
    cost[+y] = 1LL << 60;
    cost[-y] = 1LL << 60;

    cost[-x] = 1;
    cost[+x] = 0;
 
    each (src, vector<lli>({-x, +x})) {
      each (dst, vector<lli>({-y, +y})) {
        if (src <= dst) {
          cost[dst] = min(cost[dst], cost[src] + (dst - src));
        }
      }
    }
    cout << min(cost[y], cost[-y] + 1) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void showlist(list <int> g)
{
    list<int>::iterator i;
    for(i=g.begin();i!=g.end();++i)
        cout << ' ' << *i;
    cout << '\n';
}

int main()
{
    list<int> l;
    list<int>::iterator it = l.begin();
    int a,i,b,t;
    cin>>t;
    while(t--)
    {
        cin>>a;
        if(a==0)
        {
            cin>>b;
            it = l.insert(it,b);
        }
        else if(a==1)
        {
            cin>>b;
            for(i=0;i<abs(b);i++)
            {
                if(b<0)
                    it--;
                else
                    it++;
            }
        }
        else
        {
            it = l.erase(it);
        }

    }
    for(it = l.begin();it!=l.end();it++)
    {
        {
            cout<<*it<<endl;
        }
    }
}



Measured memory_bytes: 18628
#include<iostream>
#include<math.h>
#include<algorithm>

typedef long long ll;

#define FOR(i,a,b) for(ll i = (a);i < (b);++i)
#define REP(i,n) FOR(i,0,n)

#define debug(x) cout << #x << "=" << x << endl;

using namespace std;

int main(void){

    int A, B;
    cin >> A  >> B;

    if(A == 0){
        if(B==100){cout << 101 << endl; return 0;}
        cout << B << endl;
    }else if (A == 1){
       if(B == 100){
           cout << 10100 << endl; return 0;
       }
        int ans = 100*B;
        cout << ans << endl;
    }else{
       if(B == 100){cout << 1010000 << endl; return 0;}
        int ans = 100* 100 * B;
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <map>
#include <functional>
using namespace std;

int main() {
	bool flag = false;
	char s;
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> s;
		if (s == 'Y') {
			flag = true;
			break;
		}
	}
	if (flag) {
		cout << "Four" << endl;
	}
	else {
		cout << "Three" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n, i;
  scanf("%d", &n);
  int a[n];

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

  for(i = n-1; i > 0; i--)
    printf("%d ", a[i]);
    
  printf("%d\n", a[0]);
  return 0;
}



Measured memory_bytes: 2116
import sys

input = sys.stdin.readline


def main():
    A, B = map(int, input().split())

    if A % 3 == 0 or B % 3 == 0 or (A + B) % 3 == 0:
        ans = "Possible"
    else:
        ans = "Impossible"

    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;

#define int long long
int const maxn = 2e6 + 5;
int mod = 1e9 + 7;
int f[maxn], rev[maxn];

int st(int a, int b) {
    if (b == 0) return 1;
    if (b % 2 == 0) {
        int c = st(a, b / 2);
        return c * c % mod;
    }
    return a * st(a, b - 1) % mod;
}

inline int C(int n, int k) {
    return f[n] * rev[n - k] % mod * rev[k] % mod;
}

inline int CC(int x, int y) {
    return C(x + y - 1, x);
}

main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int k, ans = 0, t = 1;
    cin >> k;
    string s;
    cin >> s;
    f[0] = 1, rev[0] = 1;
    for (int i = 1; i < maxn; ++i) f[i] = f[i - 1] * i % mod;
    rev[maxn - 1] = st(f[maxn - 1], mod - 2);
    for (int i = maxn - 2; i >= 1; --i) rev[i] = rev[i + 1] * (i + 1) % mod;
    for (int i = 0; i <= k; ++i) {
        ans = (ans + t * CC(k - i, (int)s.size()) % mod * st(25, k - i)) % mod;
        t = t * 26 % mod;
    }
    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 35660
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    double n;

    while (cin >> n, n != -1.0) {
        int up = (int)n;
        string u, l;
        
        n -= up;
        while (up != 0) {
            u += (up % 2) + '0';
            up /= 2;
        }
        if (u.size() > 8) {
            cout << "NA" << endl;
            continue;
        }
        while (u.size() < 8)
            u += '0';
        reverse(u.begin(), u.end());

        if (n == 0.0)
            l = '0';
        else {
            for (int i = 0; i < 5; i++) {
                n *= 2;
                if ((int)n == 1) {
                    l += '1';

                    if (n - (int)n == 0)
                        break;
                    n -= (int)n;
                }
                else 
                    l += '0';
            }
        }
        if (l.size() > 4) {
            cout << "NA" << endl;
            continue;
        }
        while (l.size() < 4)
            l += '0';
        cout << u << '.' << l << endl;
    }

    return 0;
}

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

using namespace std;

#define int long long

signed main(){
  int n;
  cin >> n;
  
  int a[n+2];
  int cnt = 0;
  for(int i = 1;i<=n;i++){
    cin >> a[i];
    while(a[i]%2==0){
      a[i]/=2;
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
  

Measured memory_bytes: 384
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;
const ll inf=2e9,MOD=1e9+7,MAX=1e5+2;

int n,m,c[10][10];

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    IOS;
    cin>>n>>m;
    lp(i,0,10)
        lp(j,0,10)
            cin>>c[i][j];
    lp(k,0,10)
        lp(i,0,10)
            lp(j,0,10)
                if(c[i][j]>c[i][k]+c[k][j])
                    c[i][j]=c[i][k]+c[k][j];
    ll res=0;
    lp(i,0,n){
        lp(j,0,m){
            int x;
            cin>>x;
            if(x!=-1)
                res+=c[x][1];
        }
    }
    cout<<res;
}


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

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);
  int n,k,cnt=0; string s; cin >>n >>k >>s;
  for(int i=0; i<n-1; i++) if(s[i]!=s[i+1]) cnt++;  
  if(k<=cnt/2) cout <<n-1-cnt+2*k;
  else cout <<n-1;
return 0;}

Measured memory_bytes: 3748
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<ll>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecpll vector<pll>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}

vec par,height,ran;
vector<vec> chi,cir;
int k,ans=0;
int func(int v){
    int res = 0;
    REP(e,chi[v]){
        int x=func(e);
        if((v==0 && x==k+1) || (v>0 && x==k)){
            ans++;
        }else{
            res = max(res,x);
        }
    }
    return res+1;
}

int main(){
    int n=in();
    k=in();
    chi.resize(n);
    par.resize(n);
    height.resize(n);
    ran.resize(n);
    rep(i,n){
        int x=in()-1;
        if(i==0){
            if(x!=0)ans++;
            par[0]=-1;
        }else{
            chi[x].pb((int)i);
            par[i]=x;
        }
    }
    func(0);
    cout<<ans<<endl;
}


Measured memory_bytes: 11520
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	string s; cin >> s;
	if (s == "Sunny")cout << "Cloudy";
	else if (s == "Cloudy")cout << "Rainy";
	else cout << "Sunny";
	cout << endl;

	return 0;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amax(T& a,T b){if(a < b) a = b;}


ll fnc1(string sn, int q){
	//string sn = to_string(n);
	int cn=sz(sn); 
	ll ans =0;
	vector<VL> p(4, VL(2));
	p[0][0]=1;
	rep(i, cn){
		vector<VL> np(4, VL(2));
		rep(j, q)  rep(d, 10) {
			//int nk = k |(j>>d &1);
			int nj = j;
			if(d>0) nj = j+1;
			if(d < sn[i] -'0') np[nj][1] += p[j][0];
			else if(d== sn[i] -'0') np[nj][0] += p[j][0];
			np[nj][1] += p[j][1];
		}
		swap(p, np);
		ans += p[q][0] + p[q][1];
	}
	return ans;
}

int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int k;
	string sn;
	cin >>sn >>k;
	cout << fnc1(sn, k) <<"\n";;
	return 0;
}


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

int main() {
    long long Q, H, S, D, N;
    cin >> Q >> H >> S >> D >> N;
    long long one = min({Q*4, H*2, S});
    cout << min(one*N, D*(N/2)+one*(N%2)) << endl;
}


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

using namespace std;

const ll M = 1e9 + 7;

ll mod(ll a){

    return ((a % M) + M) % M;
}
ll mul(ll a,ll b){

    return mod(mod(a)*mod(b));
}
ll add(ll a,ll b){

    return mod(mod(a) + mod(b));
}
int main(){

    //freopen("in.txt","r",stdin);

    ll n;

    cin >> n;

    vector< ll > v(n + 5),pfs(n + 5,0);

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

    for(int i = n - 1; i >= 0; i--) pfs[ i ] = pfs[ i + 1 ] + v[ i ];

    ll sum = 0;

    for(int i = 0; i < n; i++) sum = add(sum,mul(v[ i ],pfs[ i + 1 ]));

    cout << sum << endl;

    return 0;
}



Measured memory_bytes: 6400
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std ;
template< class T > inl T read() {
	T x = 0 ; int f = 1 ; char k = getchar() ;
	for( ; k > '9' || k < '0'; k = getchar() ) if( k == '-' ) f = -1 ;
	for( ; k >= '0' && k <= '9'; k = getchar() ) x = x * 10 + k - '0' ;
	return x * f ;
}
template< class T > inl T read( T &x ) { return x = read<T>() ; }
int _num, _buf[20];
template< class T > il print( T x ) {
   	if( x == 0 ) return putchar( '0' ) ,void() ;
	if( x < 0 ) putchar( '-' ), x = -x ;
	while( x ) _buf[++_num] = x % 10, x /= 10 ;
	while( _num ) putchar( _buf[_num--] + '0' ) ;
}
ll mul( ll a, ll b, ll mod ) { long double c = 1. ; return ( a * b - (ll)( c * a * b / mod ) * mod ) % mod ; }
it qpow( int x, int m, int mod ) {
	int res = 1, bas = x ;
	while(m) {
		if( m & 1 ) res = ( 1ll * res * bas ) % mod ;
		bas = ( 1ll * bas * bas ) % mod, m >>= 1 ;
	}
	return res ;
}
int n, m, ans;
int main() {
//	freopen( ".in", "r", stdin ) ;
//	freopen( ".out", "w", stdout ) ;
	n = read<int>(), m = read<int>() ;
	for( ri i = 1; i <= n; ++i ) {
		int x = read<int>(), y = read<int>() ;
		ans += ( 1ll * x * x + 1ll * y * y <= 1ll * m * m ) ;
	}
	print( ans ), puts( "" ) ;
	cerr << 1. * clock() / CLOCKS_PER_SEC << "\n" ;
	return 0;
}

Measured memory_bytes: 3736
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<complex>
#include<algorithm>
#include<vector>
#include<math.h>
#include<set>
#include<map>

int main()
{
	int a, b;
	scanf("%d%d", &a, &b);
	if (a + b >= 10) printf("error\n");
	else printf("%d\n", a + b);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    int N; cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    sort(A.begin(), A.end(), greater<int>());
    queue<int> q;
    q.push(A[1]);
    q.push(A[1]);
    LL ans = A[0];
    for (int i = 2; i < N; ++i) {
        ans += q.front(); q.pop();
        q.push(A[i]);
        q.push(A[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4776
N,Y =map(int,input().split())
a = []
for i in range(N+1):
    for j in range(N+1):
        x = i
        y = j
        z = N-x-y
        if z <0:
            break
        if 10000*x+5000*y+1000*z == Y:
            a.append([x,y,z])
if len(a)>=1:
    print(a[0][0],a[0][1],a[0][2])
else:
    print(-1,-1,-1)
           
            

Measured memory_bytes: 3064
mod = 10**9+7

def comb(a,b):
      return fact[a]*inv[b]*inv[a-b]%mod
  
n,k = map(int, input().split())
a = list(map(int, input().split()))
fact = [1]
for i in range(n+k):
    fact.append(fact[-1]*(i+1)%mod)
inv = [1]*(n+k+1)
inv[n+k] = pow(fact[n+k],mod-2,mod)
for i in range(n+k)[::-1]:
    inv[i] = inv[i+1]*(i+1)%mod
f = [comb(i+n-1,n-1) for i in range(k+1)]
for i in a:
    for j in range(k-i)[::-1]:
        f[j+i+1] -= f[j]
        f[j+i+1] %= mod
print(f[k])

Measured memory_bytes: 141560
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a;
  cin >> a;
  if(a==1||a==2||a==3||a==4||a==5||a==6||a==7||a==8||a==9||a==10||a==12||a==14||a==15||a==16||a==18||a==20||a==21||a==24||a==25||a==27||a==28||a==30||a==32||a==35||a==36||a==40||a==42||a==45||a==48||a==49||a==54||a==56||a==63||a==64||a==81){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int H, A, jumlah, hasil, a, b;
	scanf("%d %d", &H, &A);
	
	a=H/A;
	b=H/A+1;
	
	hasil=H%A;
	
	hasil==0 ? printf("%d", a):printf("%d",b);
	
	return 0;
}

Measured memory_bytes: 1720
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <functional>
#include <set>
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<double,int>;
const ll M = 1e9+7;
void add(ll& x, ll y) {x+=y; x%=M;}
void chmax(ll& x, ll y) {if (x<y) x=y;}

int main() {
  ll k,a,b; cin>>k>>a>>b;
  ll an=1;
  if (k+1<a) {
    cout<<k+1<<endl;
    return 0;
  }
  k-=a-1; an+=a-1;
  if (2<b-a) {
    an+=(b-a)*(k/2);
    k-=(k/2)*2;
  }
  an+=k;
  cout<<an<<endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) = abc156d()

fun abc156d() {
    val (n, a, b) = readLine()!!.split(' ').map { it.toInt() }

    val nPow = Mint(2).modPow(n.toLong())

    var answer = Mint(nPow)
    answer -= 1
    answer -= comb(n, a)
    answer -= comb(n, b)

    println(answer)
}

private const val MOD = (1e9 + 7).toLong()

private fun modPow(n: Long, p: Long, m: Long): Long {
    var x = n
    var y = p
    var result = 1L

    x %= m
    while (y > 0) {
        if (y % 2 == 1L)
            result = (result * x) % m
        y = y shr 1
        x = (x * x) % m
    }

    return result
}

private fun comb(n: Int, k: Int): Long {
    if (n < k) return 0

    val min = Math.min(k, n - k)
    var value = 1L

    for (i in 1L..min) {
        value *= n - i + 1
        value %= MOD
        value *= modPow(i, MOD - 2, MOD)
        value %= MOD
    }
    return value
}

private class Mint(value: Long = 0L) {
    constructor(other: Mint) : this(other.value)

    private val value = if (value < 0) (value % MOD) + MOD else value % MOD
    operator fun unaryPlus() = this
    operator fun unaryMinus() = Mint(MOD - this.value)
    operator fun inc() = this.plus(1)
    operator fun dec() = this.minus(1)
    operator fun plus(other: Long) = Mint(this.value + other)
    operator fun plus(other: Mint) = this.plus(other.value)
    operator fun minus(other: Long) = Mint(this.value - other)
    operator fun minus(other: Mint) = this.plus(-other)
    operator fun times(other: Long) = Mint(this.value * other)
    operator fun times(other: Mint) = this.times(other.value)
    operator fun div(other: Long) = this.times(modPow(other, MOD - 2, MOD))
    operator fun div(other: Mint) = this.div(other.value)
    fun modPow(other: Long) = Mint(modPow(this.value, other, MOD))
    override fun toString() = this.value.toString()
    override fun hashCode() = value.hashCode()
    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false
        other as Mint
        return value == other.value
    }

    companion object Mod {
        private fun modPow(n: Long, p: Long, m: Long): Long {
            var x = n
            var y = p
            var result = 1L
            x %= m
            while (y > 0) {
                if (y % 2 == 1L) result = (result * x) % m
                y = y shr 1
                x = (x * x) % m
            }
            return result
        }
    }
}


Measured memory_bytes: 38364
#include <iostream>
using namespace std;
#define ll long long
#define inf 1<<29

int main () {
  ll n, m, r;
  cin >> n >> m >> r;
  ll rr[r];
  for (ll i = 0; i < r; i++) {
    cin >> rr[i];  
  }    
  sort(rr, rr + r);
  ll length[n + 1][n + 1];
  for (ll i = 0; i <= n; i++) {
    for (ll j = 0; j <= n; j++) {
      length[i][j] = inf;  
    }  
    length[i][i] = 0;
  }
  for (ll i = 0; i < m; i++) {
    ll s, ss, sss;
    cin >> s >> ss >> sss;
    if (length[s][ss] > sss) {
    	length[s][ss] = sss;
    	length[ss][s] = sss;
    }
  }
  for (ll k = 1; k <= n; k++) {
    for (ll i = 1; i <= n; i++) {
      for (ll j = 1; j <= n; j++) {
        if (length[i][j] > length[i][k] + length[k][j]) {
          length[i][j] = length[i][k] + length[k][j];  
        }  
      }  
    }  
  }
  ll min = -1;
  do {
    ll dis = 0;
    for (ll i = 1; i < r; i++) {
      dis += length[rr[i - 1]][rr[i]];
    }  
    if (min == -1 || min > dis) {
      min = dis;  
    }
  } while (next_permutation(rr, rr + r));
  cout << min << endl;

}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;
 
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
 
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
	int N,K; cin >> N >> K;
	vector<int> x(N);
	int d = -1;
	rep(i,N){
		cin >> x[i];
		if(x[i] < 0) d = i;
	}
	int ans = INF;
	repr(i,max(d-K+1,0),min(d+2,N)){
		if(i+K-1 < N){
			if(x[i+K-1] < 0){
				ans = min(ans,-x[i]);
			}
			else if(x[i] < 0){
				ans = min(ans,2*x[i+K-1]-x[i]);
				ans = min(ans,-2*x[i]+x[i+K-1]);
			}
			else{
				ans = min(ans,x[i+K-1]);
			}
		}
	}
	cout << ans << endl;
	
}


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

using namespace std;
using graph = vector<set<int>>;
vector<int> p, rk;
int n, m, k;

int find(int u){
    if (u == p[u]) return u;
    return p[u] = find(p[u]);
}

void join(int u, int v){
    u = find(u);
    v = find(v);
    if (u == v) return;
    if (rk[u] < rk[v]) swap(u, v);
    rk[u] += rk[v];
    p[v] = u;
}

int main(){
    cin.exceptions(cin.failbit);
    cin.tie(0);
    cout.tie(0);
    cin.sync_with_stdio(0);
    cin >> n >> m >> k;
    graph g(n);
    p = rk = vector<int>(n, 1);
    iota(p.begin(), p.end(), 0);
    for (int i = 0; i < m; ++i){
        int a, b;
        cin >> a >> b;
        a--, b--;
        join(a, b);
        g[a].insert(b);
        g[b].insert(a);
    }
    for (int i = 0; i < k; ++i){
        int a, b;
        cin >> a >> b;
        a--, b--;
        if (find(a) == find(b)) {
            g[a].insert(b);
            g[b].insert(a);
        }
    }
    for (int i = 0 ; i < n; ++i){
        cout << rk[find(i)] - g[i].size() - 1;
        if (i == n - 1) cout << '\n';
        else cout << ' ';
    }
    return 0;
}

Measured memory_bytes: 25088
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    string S; cin >> S;
    rep(i, S.size()) {
        if (i % 2 == 0 && S.at(i) == 'L') {
            cout << "No" << endl;
            return 0;
        }
        if (i % 2 == 1 && S.at(i) == 'R') {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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 <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> ans(n + 1);
    rep (x, 1, 101) {
        rep (y, 1, 101) {
            rep (z, 1, 101) {
                int a = x * x + y * y + z * z + x * y + y * z + z * x;
                if (a <= n) ans[a]++;
            }
        }
    }
    rep (i, 1, n + 1) cout << ans[i] << "\n";
    return 0;
}

Measured memory_bytes: 3684
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <fstream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_set>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-8;
int INF = INT_MAX / 2;

int main() {
	for (;;) {
		int N, M; cin >> N >> M;
		if (N == 0 && M == 0) break;
		vector<int> p(N);
		p[0] = -1;
		for (int u = 1; u < N; u++) {
			cin >> p[u];
			p[u]--;
		}
		vector<char> c(M);
		vector<int> v(M);
		vector<int> t(N);
		t[0] = 1;
		for (int i = 0; i < M; i++) {
			string s; cin >> s >> v[i];
			c[i] = s[0];
			v[i]--;
			if (c[i] == 'M') t[v[i]]++;
		}
		vector<int> a(N);
		for (int u = 0; u < N; u++)
			a[u] = (t[u] ? u : p[u]);
		ll ans = 0;
		for (int i = M - 1; i >= 0; i--) {
			if (c[i] == 'M') {
				t[v[i]]--;
				if (t[v[i]] == 0)
					a[v[i]] = p[v[i]];
			}
			if (c[i] == 'Q') {
				int& u = a[v[i]];
				for (; a[u] != u; u = a[u]);
				ans += u + 1;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 2844
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int main(void) {

	
	int N, L;

	cin >> N >> L;

	vector<int> ringo(N);

	iota(ringo.begin(), ringo.end(), L);

	int aji;

	if (L > 0) { //全て正
		aji= accumulate(ringo.begin() + 1, ringo.end(), 0);
	}
	else {
		if (N <= abs(L)) { // 全て負
			aji = accumulate(ringo.begin(), ringo.end() - 1, 0);
		}
		else { // 0が存在する
			aji = accumulate(ringo.begin(), ringo.end(), 0);
		}
	}

	cout << aji << endl; 

	return 0;
}

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

int main(){
	map<char, int> count;
	count['a'] = 0;
	count['b'] = 0;
	count['c'] = 0;
	count['d'] = 0;
	count['e'] = 0;
	count['f'] = 0;
	count['g'] = 0;
	count['h'] = 0;
	count['i'] = 0;
	count['j'] = 0;
	count['k'] = 0;
	count['l'] = 0;
	count['m'] = 0;
	count['n'] = 0;
	count['o'] = 0;
	count['p'] = 0;
	count['q'] = 0;
	count['r'] = 0;
	count['s'] = 0;
	count['t'] = 0;
	count['u'] = 0;
	count['v'] = 0;
	count['w'] = 0;
	count['x'] = 0;
	count['y'] = 0;
	count['z'] = 0;
	
	string in;
	cin >> in;
	
	for(auto i = in.begin();i != in.end();i++){
		count[*i]++;
	}
	
	bool oddf = false;
	for(auto i = count.begin();i != count.end();i++){
		if(i -> second % 2 == 1){
			oddf = true;
			break;
		}	
	}
	
	if(!oddf){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=51,inf=0x3f3f3f3f;
struct point{
	int w,t;ll v;
	bool operator <(const point &rhs) const{
		return v*rhs.w<rhs.v*w;
	}
}a[maxn];
int fa[maxn];
ll f[maxn*maxn*maxn];
int main(){
	int n=read(),X=read(),D=read();
	a[1].v=read(),a[1].w=1,a[1].t=inf;
	REP(i,2,n) a[i].v=read(),fa[i]=read(),a[i].t=D,a[i].w=1;
	DREP(i,n,2) a[fa[i]].w+=a[i].w,a[fa[i]].v+=a[i].v;
	sort(a+1,a+n+1);
	int Max=min(n*n*n,X);
	REP(i,1,Max) f[i]=1e18;
	REP(i,1,n) REP(l,1,min(n,a[i].t)) DREP(j,Max,a[i].w) chkmin(f[j],f[j-a[i].w]+a[i].v);
	ll ans=0;
	REP(i,0,Max){
		ll res=X-f[i],val=i;
		if(res<0) continue;
		REP(j,1,n){
			ll cur=min((ll)a[j].t-n,res/a[j].v);
			if(cur<0) continue;
			res-=cur*a[j].v;
			val+=cur*a[j].w;
		}
		chkmax(ans,val);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1280
<?php
while(true)
{
    $stdin = trim(fgets(STDIN));
    if ($stdin === '')
    {
        break;
    }  
    $stdins[] = $stdin;
}
list($summerDay, $homeworkNum) = explode(' ', $stdins[0]);
$homeworkDays = explode(' ', $stdins[1]);

if (array_sum($homeworkDays) > $summerDay) {
    echo '-1';
    exit;
}

echo ($summerDay - array_sum($homeworkDays));

Measured memory_bytes: 16748
use proconio::input;

fn main() {
    input!(n: usize, ab: [(u64, u64); n]);
    println!(
        "{}",
        if ab.iter().all(|&(x, y)| x == y) {
            0
        } else {
            ab.iter().map(|&(x, _)| x).sum::<u64>()
                - ab.iter()
                    .filter(|&&(x, y)| x > y)
                    .map(|&(_, y)| y)
                    .min()
                    .unwrap()
        }
    );
}


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

int main() {
  int s, count = 0;
  cin >> s;
  if(s / 100 > 0){
    count++;
    s -= 100;
  }
  if(s / 10 > 0) {
    count++;
    s-= 10;
  }
  if(s)
    count++;
  
  cout << count << endl;
  
}

Measured memory_bytes: 256
def F(a,b):
  return max(len(str(a)),len(str(b)))
n=int(input())
ans=10**15
for i in range(1,int(n**0.5)+1):
  if n%i==0:
    a=i
    b=n//i
    
    ans=min(ans,F(a,b))

print(ans)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int main(void) {

	// TODO: submit前にprintf-debugの削除確認！
	int N, M;
	cin >> N >> M;

	int A[M];
	for(int i=0; i<M; i++) A[i] = 0;
	for(int i=0; i<N; i++) {
		int K;
		cin >> K;
		for(int j=0; j<K; j++) {
			int a;
			cin >> a;
			A[a-1]++;
		}
	}

	int ans=0;
	for(int i=0; i<M; i++) {
		if(A[i] == N) ans++;
	}

	cout << ans;
	// cout << "[deb: val ]" << val <<endl;
	return 0;
}

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


int main() {
  string s;
  bool cond = true;
  cin >> s;
  rep(i ,s.size()) {
    if(i % 2 == 0) {
      if(s.at(i) == 'h') {
        continue;
      } else {
        cond = false;
        break;
      }
    }else {
      if(s.at(i) == 'i') {
        continue;
      }else {
        cond = false;
        break;
      }
    }
  }
  if (s.size() % 2 == 1){
    cond = false;
  }
  cout << (cond ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val eps = 0.0000001
    val scanner = Scanner(System.`in`)

    val a = scanner.nextInt()
    val b = scanner.nextInt()
    val x = scanner.nextInt()

    val m = a * a * b
    val space = m - x

    var l = 0.0
    var r = 90.0
    while (l + eps < r) {
        val mid = (l + r) / 2.0
        val rad = Math.toRadians(mid)
        val d = a * Math.tan(rad)
        if (d < b) {
            val s = a * a * d / 2.0
            if (s > space) {
                r = mid
            } else {
                l = mid
            }
        } else {
            val d2 = b / Math.tan(rad)
            val s = m - a * d2 * b / 2.0
            if (s > space) {
                r = mid
            } else {
                l = mid
            }
        }
    }

    println(l)
}

Measured memory_bytes: 31124
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace C___Distinct_or_Not
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

            Array.Sort(a);

            for (int i = 0; i < n - 1; i++)
            {
                if (a[i] == a[i + 1])
                {
                    Console.WriteLine("NO");
                    Environment.Exit(0);
                }
            }

            Console.WriteLine("YES");

        }
    }
}

Measured memory_bytes: 34140
#input
#スペース区切りの整数値の入力
N, A, B = map(int, input().split())
count = 0

def FindSumDigits(x):
    sum = 0
    while x>0:
        sum += x%10
        x = x//10
    return sum

for n in range(1,N+1):
    if A <= FindSumDigits(n) <= B:
        count += n

#Output
print(count)


Measured memory_bytes: 2940