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


public class Main {
		public static void main (String args[]) throws Exception{
		Scanner scan = new Scanner(System.in);
		int  n = scan.nextInt();
		long a[] = new long[n];
		Long max = Long.parseLong("1000000000000000000");
		// 0が含まれる場合
		for(int i = 0; i < n; i++) {
			a[i] = scan.nextLong();
			if(a[i] == 0) {
				System.out.println(0);
				return;
			}
		}
		long ans = a[0];
		for(int i = 1; i < n; i++) {
			if(ans > max / a[i]) {
				ans = -1;
				break;
			} else {
				ans = ans * a[i];
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 50836
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<Integer> score = new ArrayList<>();
        double total = 0;
        double a2n = 0.0;
        while(true){
        int n = sc.nextInt();
        if(n == 0){
            break;
        }
        for(int i = 0; i < n; i++){
            int s = sc.nextInt();
            score.add(s);
            total += s;
        }
        for(int i:score){
           a2n += Math.pow(i - (total/n), 2);
        }
        System.out.println(Math.sqrt(a2n/n));
        total = 0;
        a2n = 0;
        score.clear();
        }
                }
}

Measured memory_bytes: 31724
#include<iostream>
#include<vector>
using namespace std;
using ll = long long;

int main() {
  ll MOD = 1e9+7;
  int S;
  cin>>S;
  vector<ll> ans(S+1, 0);
  ans[0] = 1;
  for (int i=3;i<=S;i++) {
    ans[i] = (ans[i-1] + ans[i-3]) % MOD;
  }
  cout<<ans[S]<<endl;
  return 0;
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define endl '\n'
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define SZ(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
#define repe(it, x) for (auto it = (x).begin(); it != (x).end(); ++it)
const int MAXN = 1e5 + 20;
lint a[MAXN], rnk[MAXN], b[MAXN], cnt[MAXN];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	lint n, m, v, p;
	cin >> n >> m >> v >> p;
	rep (i, 1, n) {
		cin >> a[i];
	}
	sort(a + 1, a + n + 1);
	memcpy(b, a, sizeof(a));
	reverse(a + 1, a + n + 1);
	rnk[1] = 1;
	rep (i, 1, n) {
		cnt[i] = cnt[i - 1] + a[i];
	}
	rep (i, 2, n) {
		if (a[i - 1] == a[i]) {
			rnk[i] = rnk[i - 1];
		} else {
			rnk[i] = i;
		}
	}
	int ans = 0;
	rep (i, 1, n) {
		if (rnk[i] <= p) {
			++ans;
			continue;
		} else if (rnk[i] <= n - v + 1) {
			int pos = upper_bound(b + 1, b + n + 1, a[i] + m) - b - 1;
			if (n - pos + 1 <= p) ++ans;
			continue;
		}
		int res = -1;
		lint L = 1, R = rnk[i] - 1;
		lint las = v - (n - rnk[i] + 1);
		while (L <= R) {
			lint mid = (L + R) >> 1;
			if (a[mid] > a[i] + m) {
				L = mid + 1; continue;
			}
			lint tot = cnt[rnk[i] - 1] - cnt[mid - 1];
			lint lasf = las * m - ((a[i] + m) * (rnk[i] - mid) - tot);
			if (lasf <= (mid - 1) * m) {
				R = mid - 1, res = mid;
			} else {
				L = mid + 1;
			}
		}
		if (res != -1 && res <= p) ++ans;
	}
	cout << ans << endl; 
	return 0;
}

Measured memory_bytes: 3328
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pNO cout << "NO" << endl
#define pYES cout << "YES" << endl
#define endl "\n"
#define pi 3.14159265358979
using namespace std;
using ll = long long;

int main(){
    int a,b; cin >> a >> b;
    cout << a * b << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm> 
using namespace std;



int main() {
	int a, cun=0;
	cin >> a;
	if (a % 10 == 1)cun++;
	a /= 10;
	if (a % 10 == 1)cun++;
	a /= 10;
	if (a == 1)cun++;
	cout << cun << endl;

	return 0;
}

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

int n, m;
vector<int> check;
vector<vector<int>> g;
int solve(int k, int cnt){
  int res = cnt;
  if(check.at(k)) return 0;
  check.at(k) = 1;
  
  for(auto next : g.at(k)) res = max(res, solve(next, res+1));
  
  return res;
}

int main() {
  cin >> n >> m;
  check.resize(n, 0);
  g.resize(n);
  for(int i = 0; i < n; i++) g.at(i) = {};
  for(int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    a--, b--;
    g.at(a).push_back(b);
    g.at(b).push_back(a);
  }
  
  int ans = 0;
  for(int i = 0; i < n; i++){
    if(check.at(i)) continue;
    ans = max(ans, solve(i, 1));
  }
  
  cout << ans << endl;
}

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

int main() {
  int n,k;
  string s;
  
  cin >> n >> s >> k;
  
  for(int i = 0; i < n ; i++){
    if( s.at(i) != s.at(k-1)){
      s.at(i) = '*';
    }
  }
  
  cout << s << endl;
  
}


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

int main() {
  int n,k;cin>>n>>k;
  int ans=k;
  k--;
  rep(i,n-1)ans*=k;
  cout<<ans<<endl;
}

Measured memory_bytes: 3612
n,m=map(int,input().split())
mod=1000000007
f=[True for i in range(0,n)]
for i in range(m):
	f[int(input())]=False
dp=[1]+[0 for i in range(0,n+1)]
for i in range(0,n):
	if f[i]:
		dp[i+1] += dp[i]
		dp[i+1] %= mod
		dp[i+2] += dp[i]
		dp[i+2] %= mod
print(dp[n])

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

const int INF = 20000000;
const int MAX_M = 100;

struct data{
	int cost;
	int time;
};

int main(){
	data ds[MAX_M+1][MAX_M+1];
	int n, m, k;
	int a, b, time, cost;
	int p, q, r;
	while(cin >> n >> m){
		if(n == 0 && m == 0) break;
		for(int i = 1; i <= m; i++){
			for(int j = 1; j <= m; j++){
				ds[i][j].cost = ds[i][j].time = INF;
			}
		}
		for(int i = 0; i < n; i++){
			cin >> a >> b >> cost >> time;
			ds[a][b].cost = ds[b][a].cost = cost;
			ds[a][b].time = ds[b][a].time = time;
		}
		for(int i = 1; i <= m; i++){
			for(int j = 1; j <= m; j++){
				if(ds[j][i].cost != INF)
					for(int k = 1; k <= m; k++){
						if(ds[j][k].cost > ds[j][i].cost + ds[i][k].cost)
							ds[j][k].cost = ds[j][i].cost + ds[i][k].cost;
					}
				if(ds[j][i].time != INF)
					for(int k = 1; k <= m; k++){
						if(ds[j][k].time > ds[j][i].time + ds[i][k].time)
							ds[j][k].time = ds[j][i].time + ds[i][k].time;
					}
			}
		}
		cin >> k;
		for(int i = 0; i < k; i++){
			cin >> p >> q >> r;
			if(r) cout << ds[p][q].time << endl;
			else cout << ds[p][q].cost << endl;;
		}
	}
	return 0;
}

Measured memory_bytes: 944
#include <iostream>
#include <vector>

using namespace std;

typedef unsigned long long ll;

int main() {
	int N; cin >> N;
	vector<int> v(N);
	for (int i = 0; i < N; ++i) cin >> v[i];

	ll dp[101][21] = {0};
	dp[1][v[0]] = 1;
	for (int i = 1; i < N-1; ++i) {
		for (int j = 0; j <= 20; ++j) {
			if (dp[i][j]) {
				if (j + v[i] <= 20) dp[i+1][j+v[i]] += dp[i][j];
				if (j - v[i] >= 0) dp[i+1][j-v[i]] += dp[i][j];
			}
		}
	}
	cout << dp[N-1][v[N-1]] << endl;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    ll ans = 0;
    for (int l = 0; l <= min(n, k); l++)
    {
        for (int r = 0; (l + r) <= min(n, k); r++)
        {
            priority_queue<int, vector<int>, greater<int>> que;
            for (int i = 0; i < l; i++)
            {
                que.push(v[i]);
            }
            for (int i = 0; i < r; i++)
            {
                que.push(v[n - i - 1]);
            }

            for (int i = 0; i < k - (l + r); i++)
            {
                if (que.size() == 0)
                {
                    break;
                }
                if (que.top() < 0)
                {
                    que.pop();
                }
            }
            ll res = 0;
            while (que.size())
            {
                res += (ll)que.top();
                que.pop();
            }
            chmax(ans, res);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    double a, b;

    for(;sc.hasNext();){
      a = sc.nextDouble();
      b = sc.nextDouble();

      if(a < 35.5 && b < 71.0)System.out.println("AAA");
      else if(a < 37.5 && b < 77.0)System.out.println("AA");
      else if(a < 40.0 && b < 83.0)System.out.println("A");
      else if(a < 43.0 && b < 89.0)System.out.println("B");
      else if(a < 50.0 && b < 105.0)System.out.println("C");
      else if(a < 55.0 && b < 116.0)System.out.println("D");
      else if(a < 70.0 && b < 148.0)System.out.println("E");
      else System.out.println("NA");
    }


    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 20560
INF=9999999
N,M=map(int,input().split())
#隣接リスト
tolist=[[] for _ in range(N)]
for _ in range(M):
    a,b=map(int,input().split())
    tolist[a-1].append(b-1)
    tolist[b-1].append(a-1)
#始点から幅優先探索
pathlist=[0]
roomsign=[INF]*N
roomsign[0]=1
#空になるまで実行 先頭を削除して取得
while pathlist:
    nth=pathlist.pop(0)
    for i in tolist[nth]:
        if roomsign[i]==INF:
            roomsign[i]=nth+1
            pathlist.append(i)

print("Yes")
print(*roomsign[1:N],sep="\n")

Measured memory_bytes: 38016
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
typedef pair< int , int > P;
int main(){
  int N, M;
  while(cin >> N >> M , N){
    int d[11] = {};
    for(int i = 0 ; i < N ; i++ ){
      int a, b;
      cin >> a >> b;
      d[b] += a;
    }
    for(int i = 10 ; i && M ; i-- ){
      int t = min( d[i], M);
      d[i] -= t;
      M -= t;
    }
    int ret = 0;
    for(int i = 0 ; i < 11 ; i++ ) ret += d[i] * i;
    cout << ret << endl;
  }
}

Measured memory_bytes: 1160
#include <iostream>
typedef long long ll;
using namespace std;

int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}

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

  ll a, b, c, d; cin >> a >> b >> c >> d;
  // GCD = Greatest Common Diviser
  // LCM = Least Common Multiple
  ll lcm = c*d/gcd(c, d);
  ll toB = b - b/c - b/d + b/lcm;
  --a;
  ll toA = a - a/c - a/d + a/lcm;

  cout << toB - toA << '\n';
  return 0;
}


Measured memory_bytes: 256
# C - Next Prime

X = int(input())

def is_prime(x):
    if x == 2:
        return True
    if x < 2 or x % 2 == 0:
        return False
    i = 3
    while i <= x ** (1 / 2):
        if x % i == 0:
            return False
        i = i + 2
    return True

while True:
    if is_prime(X):
        break
    X += 1

print(X)


Measured memory_bytes: 2940
#include<iostream>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main()
{
    int n,k,s=0,p=0;
    cin>>n>>k;
    int a[n],i,temp[n]={0};
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        s=s+a[i];
    }
    int dp[n]={0};
    if(k>=n-1)
    {
        cout<<abs(a[0]-a[n-1]);
    }
    else
    {
        int j=k,cpy,mini=0;
        for(i=1;i<n;i++)
        {
           cpy=i;
           j=k;
           p=0;
           while(j>=1 && i>0)
           {
               temp[p]=dp[i-1]+abs(a[cpy]-a[i-1]);
               if(p==0)
               {
                   mini=temp[p];
               }
               else if(temp[p]<mini)
                 mini=temp[p];
               p++;
               i--;
               j--;
           }
           dp[cpy]=mini;
           i=cpy;
        }
        cout<<dp[n-1]<<"\n";
        return 0;
    }
}


Measured memory_bytes: 1408
#include <stdio.h>
#define MAX_CARD 101

int main() {
  int i, turn = 0, current_card_a = 0, current_card_b = 0, current_card_c = 0;
  char card_a[MAX_CARD], card_b[MAX_CARD], card_c[MAX_CARD];
  scanf("%s", card_a);
  scanf("%s", card_b);
  scanf("%s", card_c);
  while(1) {
    if(turn == 0) {
      if(card_a[current_card_a] == NULL) {
        printf("A\n");
        break;
      } else {
        turn = card_a[current_card_a] - 'a';
        current_card_a++;
      }
    } else if(turn == 1) {
      if(card_b[current_card_b] == NULL) {
        printf("B\n");
        break;
      } else {
        turn = card_b[current_card_b] - 'a';
        current_card_b++;
      }
    } else if(turn == 2) {
      if(card_c[current_card_c] == NULL) {
        printf("C\n");
        break;
      } else {
        turn = card_c[current_card_c] - 'a';
        current_card_c++;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> x(n),y(n);
  for(int i=0;i<n;i++){
    cin >> x[i];
    y[i]=x[i];
  }
  sort(y.begin(),y.end());
  for(int i=0;i<n;i++){
    int t=x[i]<y[n/2]?(n/2):(n/2-1);
    cout << y[t] << endl;
  }
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <string>

int main()
{
    int N, P;
    std::string S;
    std::cin >> N >> P >> S;

    if (P == 2 || P == 5) {
        long result = 0;
        for (auto i = 0; i < N; i++) {
            if ((S.at(i) - '0') % P == 0) {
                result += i + 1;
            }
        }

        std::cout << result;
        return 0;
    }

    std::vector<long> modulo_count(P, 0);

    int number = 0;
    int tens_mod_P = 1;
    for (auto iter = S.crbegin(); iter != S.crend(); iter++) {
        number = (number + tens_mod_P * (*iter - '0')) % P;

        modulo_count.at(number)++;

        tens_mod_P = (tens_mod_P * 10) % P;
    }

    long result = 0;

    {
        result += modulo_count.at(0) * (modulo_count.at(0) + 1) / 2;
    }
    for (auto i = 1; i < P; i++) {
        result += modulo_count.at(i) * (modulo_count.at(i) - 1) / 2;
    }

    std::cout << result;

    // std::cout << std::endl << std::endl;
    // for (auto i = 0; i < P; i++) {
    //     std::cout << i << ": " << modulo_count.at(i) << std::endl;
    // }

    return 0;
}

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

int main() {
  vector<ll> vec;
  ll N,a;
  cin >> N;
  for(int i=0; i<N; i++) {
    cin >> a;
    vec.push_back(a);
  }
  vector<ll>::iterator iter;
  int acc=0;
  ll d;
  for(iter=vec.begin(); iter!= vec.end(); iter++){
   d = *iter;
   while(d%2 == 0) {
     d = d/2;
     acc++;
   }
  }
   cout << acc << endl;
   return 0;

}


Measured memory_bytes: 512
n = int(input())
a, b = map(str, input().split())

a_v1 = list(a)
b_v1 = list(b)

ans = []

for i in range(n):
    ans.append(a_v1[i])
    ans.append(b_v1[i])

ans_v1 = "".join(ans)
print(ans_v1)

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

using namespace std;

const long long INF = 1e18;
const int N = 1e5;

const double PI = acos(-1);

int main() {
    int a, b, x;
    cin >> a >> b >> x;
    int v = a * a * b;
    int rem = v - x;
    double ang;
    if (rem > x) {
        double sq = x * 1.0 / a;
        double c = sq * 2 / b;
        ang = atan(c / b);
    } else {
        double sq = rem * 1.0 / a;
        double c = sq * 2 / a;
        ang = atan(a / c);
    }
    cout << setprecision(10) << 90 - ang * 180 / PI;
}


Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

struct Data {
    int t;
    int order;
};

int min_depth(int node, vector<vector<int>> &children) {
    int dep = 0;
    int n = children[node].size();
    if (n == 0)
        return 0;
    vector<int> deps(n);

    FOR(i, 0, n) {
        auto t = children[node][i];
        deps[i] = min_depth(t, children);
    }
    sort(deps.begin(), deps.end());
    // +1から+nまでを割り振って最大値が最小になるようにする段階
    // せいぜいO(n)くらい？
    int now = n;
    int maxx = -1;
    IFOR(i, 1, n) {
        maxx = max(maxx, deps[n - i] + i);
    }
    return maxx;
}


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

    vector<int> a(n);
    vector<int> depth(n);
    vector<vector<int>> children(n);

    FOR(i, 1, n) {
        cin >> a[i];
        a[i]--;
        children[a[i]].push_back(i);
    }

    int res = min_depth(0, children);

    cout << res << endl;




    return 0;
}

Measured memory_bytes: 18944
import java.util.*;

public class Main {

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


        for(int i=0;i<n;i++)a[i]=sc.nextLong();

        long ans =0;
        boolean allodd = true;

        for(int i=0;i<n;i++)ans+=two(a[i]);

        System.out.println(ans);

    }

    private static long two(long num){
        if(num%2==1)return 0;

        num=num/2;
        return two(num)+1;
    }

}




Measured memory_bytes: 34120
gets
ary = [[], [], [], []]
4.times{|i| 3.times{|a| ary[i] << [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}}
ARGF.each_line do |line|
  b, f, r, v = line.chomp.split.map(&:to_i)
  ary[b-1][f-1][r-1] += v
end
4.times do |n|
  puts "#"*20 if n != 0
  3.times{|i| puts "\s" + ary[n][i].join("\s")}
end

Measured memory_bytes: 6112
#include <bits/stdc++.h>
using namespace std;
long long usu[1000006];
char s[100003];
long long n,sol,act;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;++i)
    {
        cin>>(s+1);
        sort(s+1,s+10+1);
        for(int j=1;j<=10;++j) usu[i]=usu[i]*26+(s[j]-'a');
    }
    sort(usu+1,usu+n+1);
    act=1;
    for(int i=2;i<=n;++i)
    {
        if(usu[i]==usu[i-1])
        {
            ++act;
            continue;
        }
        else
        {
            sol+=(act-1)*act/2;
            act=1;
            continue;
        }
    }
    sol+=(act-1)*act/2;
    cout<<sol;
    return 0;
}


Measured memory_bytes: 1024
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	//adjacency list of edges
	public Graph() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}
	public void printAdjMatrix() {
		Integer[][] adjMatrix = new Integer[totalVertex][totalVertex];
		Iterator<LinkedList<Integer>> it = adjList.iterator();
		int num = 0;
		while(it.hasNext()) {
			LinkedList<Integer> c = it.next();
			Iterator<Integer> it2 = c.iterator();
			
			while(it2.hasNext()){
				adjMatrix[num][it2.next()] = 1; 
			}
			num++;
		}
		
		for(int i = 0; i<totalVertex;i++) 
			{
			String finalString = "";
			for (int j =0;j < totalVertex;j++)
				{
				if(adjMatrix[i][j] == null) {finalString += "0 ";}
				else {finalString += "1 ";}
				}
			System.out.println(finalString.substring(0, finalString.length() - 1));
			}
		
	}
}

//change class name GraphRepresentation to Main() for submission to AIZU
public class Main {
	public static void main(String argv[]) {
		Graph g = new Graph();
		g.loadAdjList();
		g.printAdjMatrix();
	}
}



Measured memory_bytes: 39544
while True:
    H,W = map(int,input().split())
    if H == 0 and W == 0:
        break
    else:
        print('#'*W)
        for i in range(1,H-1):
            print('#','.'*(W-2),'#',sep='')
        print('#'*W)
        
    print('')    


Measured memory_bytes: 5632
#include <iostream>
#include <cstdio>
#include <vector>
#define N 100005
using namespace std;

int n, cnt, a[2][N];
vector<int> v[N];

void f(int p, int q, int c) {
	int i;
	if (a[p][q]) return;
	a[p][q] = c;
	for (i = 0; i < v[q].size(); i++) f(p, v[q][i], c + 1);
}

int main()
{
	int i, t1, t2;
	cin >> n;
	for (i = 1; i < n; i++) {
		scanf("%d %d", &t1, &t2);
		v[t1].push_back(t2);
		v[t2].push_back(t1);
	}
	f(0, 1, 1);
	f(1, n, 1);
	for (i = 1; i <= n; i++) cnt += a[0][i] <= a[1][i];
    cout << (cnt > n - cnt ? "Fennec" : "Snuke") << endl;
    return 0;
}

Measured memory_bytes: 11136
x,y = map(int,input().split())

res = 0
if x == 1:
    res += 300000
elif x == 2:
    res += 200000
elif x == 3:
    res += 100000

if y == 1:
    res += 300000
elif y == 2:
    res += 200000
elif y == 3:
    res += 100000

if x == 1 and y == 1:
    res += 400000
print(res)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n;
	cin >> n;
	vector<ll> t(n), a(n);
	for (ll i = 0; i < n; i++) cin >> t[i] >> a[i];

	for (ll i = 1; i < n; i++) {
		ll x = max(ceil((long double)t[i - 1] / t[i]), ceil((long double)a[i - 1] / a[i]));
		t[i] *= x;
		a[i] *= x;
	}

	cout << t.back() + a.back() << endl;
}


Measured memory_bytes: 256
n = int(input())
w = list(map(int,input().split()))
l = []
r = []
#print(w)

min = abs(w[0] - sum(w[1:]))
#print(min)
s1 = 0
s2 = 0

for i in range(n-1):
    s1 = sum(w[:i+1])
    s2 = sum(w[i+1:])
    tmp = abs(s1 - s2)
#    print(s1,s2,tmp)
    if tmp < min:
        min = tmp

print(min)


Measured memory_bytes: 3064
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    int N; cin >> N;
    vi A(N - 1), B(N - 1);
    REP(i,N-1) {
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
    }

    vvi es(N);
    REP(i,N-1) {
        es[A[i]].push_back(B[i]);
        es[B[i]].push_back(A[i]);
    }

    queue<int> qf;
    qf.push(0);
    vb vf(N, false);
    vi df(N);
    df[0] = 0;
    while(!qf.empty()) {
        int x = qf.front(); qf.pop();
        vf[x] = true;
        for(int nx : es[x]) {
            if (vf[nx]) continue;

            df[nx] = df[x] + 1;
            qf.push(nx);
        }
    }

    queue<int> qs;
    qs.push(N-1);
    vb vs(N, false);
    vi ds(N);
    ds[N-1] = 0;
    while(!qs.empty()) {
        int x = qs.front(); qs.pop();
        vs[x] = true;
        for(int nx : es[x]) {
            if (vs[nx]) continue;

            ds[nx] = ds[x] + 1;
            qs.push(nx);
        }
    }

    int cf = 0, cs = 0;
    REP(i,N) {
        if (df[i] <= ds[i]) cf++;
        else cs++;
    }

    string ans;
    if (cf > cs) ans = "Fennec";
    else ans = "Snuke";

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <cmath>

using namespace std;

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

	long long A = 1, B = 1;
	for (int i = 0; i < N; i++){
		long long x, y;
		cin >> x >> y;
		long long n = max((A+x-1)/x, (B+y-1)/y);
		A = n * x;
		B = n * y;
	}

	cout << A + B << endl;
	return 0;
}


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

using lli = long long int;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

template <class T>ostream &operator<<(ostream &o,const pair<T, T>&p)
{o<<"("<<p.first<<", "<<p.second<<")";return o;}

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

const lli MOD = 1000000007LL;

lli modpow(lli a, lli n){
    lli res = 1;

    for(lli ai = a; n; n>>=1){
        if(1&n) res = (res*ai)%MOD;
        ai=(ai*ai)%MOD;
    }
    return res;
}

lli inv(lli n){
    return modpow(n, MOD-2);
}

lli modperm(lli n, lli k){
    lli res = 1;
    rep(i, k){
        res = (res*(n-i))%MOD;
    }
    return res;
}

lli modcomb(lli n, lli k){
    return (modperm(n, k)*inv(modperm(k, k)))%MOD;
}

lli posmod(lli n){
    lli res = n;
    res %= MOD;
    if(res < 0) res += MOD;
    return res;
}
#define N_MAX 100000

int n, m;
int h[N_MAX];
int a, b;
vector<vector<int>> link(N_MAX);
vector<int> seen(N_MAX);
int res;

int main(void){
    cin >> n >> m;
    rep(i, n) cin >> h[i];
    rep(i, m){
        cin >> a >> b;
        a--;
        b--;
        link[a].push_back(b);
        link[b].push_back(a);
    }

    res = 0;
    rep(i, n){
        if(seen[i] == true) continue;
        int most = 1;
        for(auto j : link[i]){
            if(h[i] > h[j]){
                seen[j] = true;
            }else if(h[i] == h[j]){
                most = 0;
                seen[j] = true;
            }else{
                most = 0;
            }
        }
        res += most;
        seen[i] = true;
    }
    cout << res << endl;
    return 0;
}


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

const int INF = 10000;

class MaxFlow {
	struct edge {
		int to, cap, rev;
		edge(int to_, int cap_, int rev_) : to(to_), cap(cap_), rev(rev_) {};
	};

	int V;
	vector<vector<edge>> G;
	vector<int> level;
	vector<int> iter;

	void BFS(int s) {
		fill(level.begin(), level.end(), -1);
		queue<int> que;
		level[s] = 0;
		que.push(s);
		while (!que.empty()) {
			int v = que.front(); que.pop();
			for (size_t i = 0; i < G[v].size(); i++) {
				edge &e = G[v][i];
				if (e.cap > 0 && level[e.to] < 0) {
					level[e.to] = level[v] + 1;
					que.push(e.to);
				}
			}
		}
	}

	int DFS(int v, int t, int f) {
		if (v == t) return f;
		for (int &i = iter[v]; i < (int)G[v].size(); i++) {
			edge &e = G[v][i];
			if (e.cap > 0 && level[v] < level[e.to]) {
				int d = DFS(e.to, t, min(f, e.cap));
				if (d > 0) {
					e.cap -= d;
					G[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}

public:
	MaxFlow(int _V) : V(_V), G(_V), level(_V), iter(_V) {}
	void add(int from, int to, int cap) {
		G[from].push_back(edge(to, cap, G[to].size()));
		G[to].push_back(edge(from, 0, G[from].size() - 1));
	}
	int Dinic(int s, int t) {
		int flow = 0;
		while (true) {
			BFS(s);
			if (level[t] < 0) return flow;
			fill(iter.begin(), iter.end(), 0);
			int f;
			while ((f = DFS(s, t, INF)) > 0) {
				flow += f;
			}
		}
	}
};

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

int main()
{
	int H, W;
	cin >> H >> W;
	vector<string> v(H);
	for (int i = 0; i < H; i++) {
		cin >> v[i];
	}
	MaxFlow mf(H * W * 2 + 2);
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (i == 0 || i == H - 1 || j == 0 || j == W - 1) {
				mf.add(H * W * 2, i * W + j, INF);
			}
			mf.add(i * W + j, H * W + i * W + j, 1);
			for (int k = 0; k < 4; k++) {
				int tx = i + dx[k], ty = j + dy[k];
				if (0 <= tx && tx < H && 0 <= ty && ty < W) {
					mf.add(H * W + i * W + j, tx * W + ty, 1);
				}
			}
			if (v[i][j] == 'X') mf.add(i * W + j, H * W * 2 + 1, INF);
		}
	}
	int res = mf.Dinic(H * W * 2, H * W * 2 + 1);
	cout << (res >= INF ? -1 : res) << endl;
	return 0;
}


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


int main(){
    string A,B,C;
    cin>>A>>B>>C;
    int aend,bend;
    aend=A.size();
    bend=B.size();
    if(A[aend-1]==B[0]&&B[bend-1]==C[0]){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    

    return 0;
}

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

int main(){
  string s;
  cin >> s;
  int64_t n = s.size();
  string rs = s;
  reverse(rs.begin(),rs.end());
  string hs = s.substr(0,(n-1)/2);
  string rhs = hs;
  reverse(rhs.begin(),rhs.end());
  string xs = s.substr(((n+3)/2)-1);
  string xrs = xs;
  reverse(xrs.begin(),xrs.end());
  //cout << rs << endl << rhs << endl << xrs << endl;
  if(s == rs && hs == rhs && xs == xrs){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
}


Measured memory_bytes: 256
package main

import "fmt"

var (
	S string
)

func contains(ss []rune, x rune) bool {
	for _, v := range ss {
		if v == x {
			return true
		}
	}
	return false
}
func main() {
	fmt.Scan(&S)

	odd := []rune{
		'R', 'U', 'D',
	}
	even := []rune{
		'L', 'U', 'D',
	}
	ok := true
	for i, v := range S {
		i++
		if i%2 == 0 && contains(even, v) {
		} else if i%2 == 1 && contains(odd, v) {
		} else {
			ok = false
		}
	}
	if ok {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include<iostream>
#include<queue>
#include<map>

struct P{
	int x, y;
};

struct Puzzle{
	int peace[2][4], t;
	P zero_p;
};

int toHash(int arr[][4]){
	int res = 0;
	for(int i=0;i<2;i++){
		for(int j=0;j<4;j++){
			res = (res << 3) + arr[i][j];
		}
	}
	return res;
}

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

int main(){
	std::map<int, int> ps;
	std::queue<Puzzle> pq;

	Puzzle f_puzzle;
	for(int i=0;i<8;i++){
		f_puzzle.peace[i/4][i%4] = i;
	}
	f_puzzle.t = 1;
	f_puzzle.zero_p = {0, 0};

	pq.push(f_puzzle);

	while(!pq.empty()){
		Puzzle p = pq.front();pq.pop();
		int h_value = toHash(p.peace);

		if(ps[h_value] != 0){
			continue;
		}

		P zero_p = p.zero_p;
		for(int i=0;i<4;i++){
			int mx = zero_p.x + dx[i],
				my = zero_p.y + dy[i];
			if(0 <= mx && mx < 4 &&
				 0 <= my && my < 2){
				Puzzle temp_p = p;
				temp_p.peace[zero_p.y][zero_p.x] = temp_p.peace[my][mx];
				temp_p.peace[my][mx] = 0;
				temp_p.zero_p = {mx, my};
				temp_p.t++;
				pq.push(temp_p);
			}
		}
		
		ps[h_value] = p.t;
	}

	int arr[2][4];
	while(true){
		std::cin >> arr[0][0];
		if(std::cin.eof()){
			return 0;
		}
		for(int i=1;i<8;i++){
				std::cin >> arr[i/4][i%4];
		}
		std::cout << ps[toHash(arr)]-1 << std::endl;
	}
}

Measured memory_bytes: 2264
if __name__ == '__main__':
	n = int(input())
	s = input()
	r, b = 0, 0

	for c in s:
		if c == 'R':
			r += 1
		else:
			b += 1
	
	if r > b:
		print('Yes')
	else:
		print('No')


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define INF 10000000000

ll a, b, c, n, m, x, y, z, w, h, ans = 0, cnt = 0, mx = 0, mn = INF;
string s;

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

    cin >> n >> a >> b;
    cout << ((abs(a - b - 1) % 2) ? "Alice" : "Borys") << endl;
}



Measured memory_bytes: 256
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True  and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,k = inm()
t1 = n-k+2
t2 = (n+1)*(n+k+1)*(n-k+2)//2
t3 = ((n+2)*(n+1)*(2*n+3)-(k-1)*k*(2*k-1))//6
ddprint(t1)
ddprint(t2)
ddprint(t3)
print((t1+t2-t3)%R)


Measured memory_bytes: 9228
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
int main()
{
   ll a ,b,y;
   	cin>>a>>b;
   	y=b;
	int dig=0;
	while(y)
	{
		dig++;
		y/=10;
	}
	ll x=1;
	for(int i=0;i<dig;i++)
		x*=10;
	ll  num=a*x+b;
	//cout<<sqrt(num)<<endl;
	if( num%(ll)sqrt(num) ==0 )
		puts("Yes");
	else
		puts("No");
	
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int n;
long long ans;
int a[101010];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;++i)
		scanf("%d",&a[i]);
	for (int i=1;i<=n;++i)
	{
		ans+=a[i]/2;
		a[i]%=2;
		int k=min(a[i],a[i+1]);
		a[i]-=k;
		a[i+1]-=k;
		ans+=k;
	//	printf("%d: %lld\n",i,ans);
	}
	printf("%lld\n",ans);
	return 0;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n;
  cin >> n;
  vl a(n);
  vl b(n);
  vl c(n);
  REP(i,n) cin >> a[i];
  REP(i,n) a[i]--;
  REP(i,n) cin >> b[i];
  REP(i,n) cin >> c[i];
  ll last = -3;
  ll ans = 0;
  REP(i,n){
    ans += b[a[i]];
    if(a[i]==last+1){
      ans += c[last];
    }
    last = a[i];
  }
  cout << ans<< endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937_64 mt64(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/


int n, m;
priority_queue<int>que;
signed main() {
	cin >> n >> m;
	rep(i, n) {
		int a; cin >> a;
		que.push(a);
	}
	rep(i, m) {
		int j = que.top(); que.pop();
		que.push(j / 2);
	}
	int ans = 0;
	while (que.size()) {
		int i = que.top(); que.pop();
		ans += i;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1400
#include<stdio.h>

int main(){
  int det=100000,week,i;

  scanf("%d",&week);

  for (i=0;i<week;i++){
    det=det*1.05;
    if((det%1000)!=0){
      det=det-(det%1000)+1000;
    }
  }

  printf("%d\n",det);

  return 0;
}

Measured memory_bytes: 592
S = input()

forward = int(S[:2])
backward = int(S[2:])

if (1<=forward<=12) and (1<=backward<=12):
    print('AMBIGUOUS')
elif ((forward == 0) or (12 <= forward <= 99)) and (1<=backward<=12):
    print('YYMM')
elif ((backward == 0) or (12<=backward<=99)) and (1<=forward<=12):
    print('MMYY')
else:
    print('NA')


Measured memory_bytes: 3060
#pragma GCC optimize ("-Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<cmath>
#include<cstdio>
#include<algorithm>
#include<bitset>
#include<complex>
#include<deque>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<utility>
#include<valarray>
#include<vector>
#include<array>
#include<forward_list>
#include<random>
#include<ratio>
#include<tuple>
#include<unordered_map>
#include<unordered_set>
#include<cstring>

using namespace std;
using Int = long long; using uint = unsigned int; using uInt = unsigned long long;
typedef pair<int,int> Pi; typedef pair<Int,Int> Pl;
constexpr int mod = 1e9+7;
constexpr int INF32 = numeric_limits<int>::max();
constexpr Int INF64 = numeric_limits<Int>::max();
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define mp make_pair
#define Pr(t) priority_queue<t>
#define gPr(t) priority_queue<t,vector<t>,greater<t>>
#define V(t) vector<t>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rer(i,l,r) for(int i=(l); i<=(r); ++i)
#define gnr(i,l,r) for(int i=(r); i>=(l); --i)
#define eb emplace_back
#define pri1(a) cout<<(a)<<'\n'
#define pri2(a,n) {rep(i,n-1)cout<<a[i]<<' '; if(n)cout<<a[n-1]<<'\n';}
#define prip(p) cout<<p.fi<<' '<<p.se<<'\n'
#define priend(a) {cout<<(a)<<'\n'; return 0;}
#define fil(a,v) memset((a),v,sizeof(a))
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

Int n,m,_,x,y,q;
string s,sb;
bool ok;
char cf,cb;


int main(){
  cin.tie(nullptr); ios::sync_with_stdio(0);
  //cout<<fixed<<setprecision(20);

  cin>>n; Int sn=0,an=0;
  rep(i,n){
    cin>>x>>y; sn+=x*y; an+=y;
  }
  cout<<an-1+(sn-1)/9;
}

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

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
typedef long long LL;
const int N = 100003;
const LL C = 2e17;
template<typename T>
inline void read(T &x){
    int ch = getchar(); x = 0; bool f = false;
    for(;ch < '0' || ch > '9';ch = getchar()) f |= ch == '-';
    for(;ch >= '0' && ch <= '9';ch = getchar()) x = x * 10 + ch - '0';
    if(f) x = -x;
}
int n;
LL x[N], y[N];
bool qry(LL a, LL b, LL c){return c >= a && (C - a - b & c - a) == c - a;}
bool qry(LL c){
    bool ans = false;
    for(Rint i = 0;i < n;++ i)
        ans ^= qry(x[i], y[i], c);
    return ans;
}
int main(){
    read(n);
    for(Rint i = 0;i < n;++ i){read(x[i]); read(y[i]);}
    LL now = C;
    for(Rint i = 58;~i;-- i) if(qry(now-(1ll<<i))) now -= 1ll<<i;
    printf("%lld\n", now);
}

Measured memory_bytes: 5320
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

int cm[128];
bool pm[128];

int dfs(vector<string> &v,int c,int p){
  if(v.back().empty()){
    return all_of(begin(v),end(v),[](string s){
	return s.empty();
	  })&&c==0;
  }else{
    for(auto &e:v){
      if(!e.empty()&&cm[e.back()]<0){
	int sum=0;
	for(int i=0;i<10;i++){
	  if(!(p>>i&1)&&(i||!pm[e.back()])){
	    cm[e.back()]=i;
	    sum+=dfs(v,c,p|1<<i);
	    cm[e.back()]=-1;
	  }
	}
	return sum;
      }
    }
    for(int i=0;i+1<v.size();i++){
      if(!v[i].empty()){
	c+=cm[v[i].back()];
      }
    }
    if(c%10==cm[v.back().back()]){
      vector<string> n;
      for(auto &e:v){
	n.push_back(e.empty()?e:e.substr(0,e.size()-1));
      }
      return dfs(n,c/10,p);
    }else{
      return 0;
    }
  }
}
 
int main(){
  for(int N;cin>>N,N;){
    fill(begin(cm),end(cm),-1);
    fill(begin(pm),end(pm),false);
    vector<string> s(N);
    for(auto &e:s){
      cin>>e;
      if(e.size()>1){
	pm[e[0]]=true;
      }
    }
    cout<<dfs(s,0,0)<<endl;
  }
}

  

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
int main()
{
	//while(1)
	{
		int n;
		cin>>n;
		int sum=0;
		int ma = -1000;
		for(int i=0;i<n;i++)
		{
			int a;
			cin>>a;
			sum+=a;
			ma = max(ma,a);
		}
		sum-=ma;
		if(ma<sum)
		{
			cout<<"Yes\n";
		}
		else
		{
			cout<<"No\n";
		}
	}
 } 

Measured memory_bytes: 256
import java.io.*;
import java.util.Arrays;
    
public class Main {
  public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String input;
    int count = 1;
    while (!(input = br.readLine()).equals("0")) {
      System.out.println("Case " + count + ": " + input);
      count++;
    }
  }
}

Measured memory_bytes: 31640
#include <iostream>
#include <math.h>
#include <stdlib.h>
using namespace std;

int main()
{
    int N, A, flag = 0;
    cin >> N >> A;

    while (N >= 500)
    {
        N -= 500;
    }

    if (N == 0 || N <= A)
    {
        flag = 1;
    }

    if (flag == 1)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=200009;

int Tn;

int n;
int K[maxn],L[maxn],R[maxn];
vector<int>G[maxn];

priority_queue<int>q;

int main(){
	scanf("%d",&Tn);
	while(Tn--){
		scanf("%d",&n);
		for(int i=1;i<=n;++i)scanf("%d%d%d",&K[i],&L[i],&R[i]);
		
		long long ans=0;
		
		for(int i=1;i<=n;++i)if(L[i]==R[i])ans+=L[i];
		
		int p=0;
		while(!q.empty())q.pop();
		for(int i=1;i<=n;++i)G[i].clear(); 
		for(int i=1;i<=n;++i){
			if(L[i]>R[i]){
				++p;G[K[i]].push_back(L[i]-R[i]);ans+=R[i];
			}
		}
		for(int i=p+1;i<=n;++i){
			for(int j=0;j<G[i].size();++j){
				int x=G[i][j];
				q.push(x);
			}
		}
		for(int i=p;i>=1;--i){
			for(int j=0;j<G[i].size();++j){
				int x=G[i][j];
				q.push(x);
			}
			if(!q.empty()){
				ans+=q.top();q.pop();
			}
		}
		
		p=0;
		while(!q.empty())q.pop();
		for(int i=1;i<=n;++i)G[i].clear();
		for(int i=1;i<=n;++i){
			if(L[i]<R[i]){
				++p;G[K[i]+1].push_back(R[i]-L[i]);ans+=L[i];
			}
		}
		for(int i=1;i<n-p+1;++i){
			for(int j=0;j<G[i].size();++j){
				int x=G[i][j];
				q.push(x);
			}
		}
		for(int i=n-p+1;i<=n;++i){
			for(int j=0;j<G[i].size();++j){
				int x=G[i][j];
				q.push(x);
			}
			if(!q.empty()){
				ans+=q.top();q.pop();
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}

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

int main()
{
	int N;
	int X[200005], sorted[200005];
	
	cin >> N;
	for ( int i = 0; i < N; i++ ) {
		cin >> X[i];
		sorted[i] = X[i];
	}
	sort(sorted, sorted + N);
	int a = sorted[N / 2 - 1], b = sorted[N / 2];

	for ( int i = 0; i < N; i++ ) {
		if ( X[i] <= a ) {
			cout << b << endl;
		} else {
			cout << a << endl;
		}
	}

	return (0);
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if (k%2) cout << b-a;
    else cout << a-b;
}


Measured memory_bytes: 256
import sys
import math
import bisect
import copy
sys.setrecursionlimit(1000000)
from collections import deque

def bubble(a,n):
    for i in range(n):
        for j in range(n-1,i,-1):
            if a[j][1]<a[j-1][1]:
                a[j],a[j-1] = a[j-1],a[j]

def selection(a,n):
    for i in range(n):
        minj = i
        for j in range(i+1,n):
            if a[j][1]<a[minj][1]:
                minj = j
        a[i],a[minj] = a[minj],a[i]

def main():
    n = int(input())
    a = list(input().split())
    b = copy.copy(a)
    bubble(a,n)
    selection(b,n)
    print (' '.join(a))
    print ('Stable')
    print (' '.join(b))
    if a==b:print ('Stable')
    else   :print ('Not stable')



if __name__ == '__main__':
    main()




Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 200005;
bool isPrime[MAXN];
vector<int> pr;
vector<int> ans;
void sieve()
{
    memset(isPrime, 1, sizeof isPrime);
    isPrime[0] = isPrime[1] = 0;

    for (int i = 2; i * i <= MAXN; i += 1 + (i & 1))
    {
        if (isPrime[i])
        {

            for (int j = i * i; j < MAXN; j += i)
                isPrime[j] = 0;
        }
    }
    for(int i=0; i<MAXN; i++)
    {
        if(isPrime[i])
        {

            ans.push_back(i);
        }
    }
}

ld power(ld x, ll y)
{
    ll temp;
    if (y == 0)
        return 1;
    temp = power(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
        return x * temp * temp;
}

void debug_out()
{
    cerr << endl;
}

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << H;
    debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)


int main()
{
    FAST
    int x,y;
    cin>>x>>y;
    for(int i=0;i<=100;i++){
        for(int j=0;j<=100;j++){
            if(2*i+4*j==y && i+j==x){
                return cout<<"Yes"<<endl,0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}


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

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    if(a%2==0 || b%2==0 || c%2==0){
        cout << 0 << endl;
        return 0;
    }
    int mx = max(a, max(b, c));
    ll ans = min(a*b, min(b*c, c*a));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3532