akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10**7)

nodedict = {}

class Node:
    def __init__(self, id, left, right):
        self.id = id
        self.parent = -1
        self.depth = -1
        self.sibling = -1
        self.height = -1
        self.left = left
        self.right = right
        self.degree = 0
        if left != -1:
            self.degree += 1
        if right != -1:
            self.degree += 1

    def __repr__(self):
        return str(self.__dict__)

    def get_height(self):
        if self.height != -1:
            pass
        else:
            if self.degree == 0:
                self.height = 0
            else:
                lh, rh = 0, 0
                if self.left != -1:
                    lh = nodedict[self.left].get_height()
                if self.right != -1:
                    rh = nodedict[self.right].get_height()
                self.height = max(lh, rh) + 1

        return self.height

def assign_info(node, current_depth):
    node.depth = current_depth
    if node.left != -1:
        left = nodedict[node.left]
        left.parent = node.id
        left.sibling = node.right
        assign_info(left, current_depth + 1)

    if node.right != -1:
        right = nodedict[node.right]
        right.parent = node.id
        right.sibling = node.left
        assign_info(right, current_depth + 1)

def solve():
    n = int(input())

    # Node作成
    childlist = []
    for i in range(n):
        id, left, right = map(int, input().split())
        nodedict[id] = Node(id, left, right)
        childlist.append(left)
        childlist.append(right)


    # 根を探す
    rootid = -1
    for i in range(n):
        if i not in childlist:
            rootid = i

    # 根から順に情報割り当て
    assign_info(nodedict[rootid], 0)

    # 高さ割り当て
    for i in range(n):
        nodedict[i].get_height()

    # 出力
    for i in range(n):
        node = nodedict[i]
        if node.depth == 0:
            type = "root"
        elif node.height == 0:
            type = "leaf"
        else:
            type = "internal node"

        print("node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}".format(
            node.id, node.parent, node.sibling, node.degree, node.depth, node.height, type))

solve()


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int d;
	cin >> d;
	if(d == 22) {
		cout << "Christmas Eve Eve Eve" << endl;
	}
	if(d == 23) {
		cout << "Christmas Eve Eve" << endl;
	}
	if(d == 24) {
		cout << "Christmas Eve" << endl;
	}
	if(d == 25) {
		cout << "Christmas" << endl;
	}
	
	return 0;	
}


Measured memory_bytes: 256
n, m = map(int, input().split())
a_list = []
for i in range(n):
    a_list.append(set(map(int, input().split()[1:])))

all_like_list = a_list[0]
for i in range(1, len(a_list)):
    all_like_list = all_like_list.intersection(a_list[i])
print(len(all_like_list))


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
int a,b;
int init=0;
int main(){
while(cin>>a>>b){
	if(a==0&&b==0)break;
	if(init!=0)cout<<endl;
	init=1;
	int ans=0;
	for (int i = a; i <= b; ++i) {
		if((i%4==0)&&(i%100)!=0||(i%400==0)){cout<<i<<endl;ans++;}
	}
	if(ans==0){cout<<"NA"<<endl;}
}
return 0;
}

Measured memory_bytes: 2980
import java.lang.Math;
import java.util.*;
class Main{

     public static void main(String []args){
        Scanner sc = new Scanner(System.in);
        
        long N = sc.nextLong();
        long temp = N;
        for(long i = 1; i <= Math.sqrt(N); i++){
            if( N % i == 0 && N/i + i < temp){

                temp = N/i + i;
            }
        }
        if(temp == N){
            System.out.println(N-1);
        }else System.out.println(temp - 2);
     }
}

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

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

  vector<int> V;
  V.reserve(N);
  for (int i = 0; i < N; i++) {
    int v;
    cin >> v;
    V.push_back(v);
  }
  
  int max_ans = 0;
  for (int a = 0; a <= K; a++) {
    for (int b = 0; a + b <= K; b++) {
	  for (int k = 0; a + b + k <= K; k++) {
        int ans = 0;
        vector<int> tmp_v;
        for (int i = 0; i < a && i < N; i++) {tmp_v.push_back(V[i]);}
        for (int i = 0; i < b && i < N-a; i++) {tmp_v.push_back(V[N-1-i]);}
        sort(tmp_v.rbegin(), tmp_v.rend());
        for (int i = 0; i < k && !tmp_v.empty(); i++) {tmp_v.pop_back();}
        for (int i = 0; i < tmp_v.size(); i++) {ans += tmp_v[i];}
        max_ans = max(max_ans, ans);
      }
    }
  }  
  cout << max_ans << endl;
         
  return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 
int main() {
  	int a, b, c;
  	bool flag = false;
  	cin >> a >> b >> c;
  	for(int i = 1; i <= b; ++i){
      if(a * i % b == c)
        flag = true;
    }
  if(flag) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
n = int(input())
A = [None for i in range(n)]
B = list(map(int, input().split()))
A[0] = B[0]
A[-1] = B[-1]
 
for i in range(1, n-1):
  A[i] = min(B[i-1], B[i])
print(sum(A))

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

int main() {
    int N;
    cin>>N;
    vector<int> vec(N);
    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
    }
    int x=0;
    for (int i=0; i < N; i++) {
        if((vec.at(i)%2)==0){
            if(((vec.at(i)%3)!=0) && ((vec.at(i)%5)!=0)){
                x=1;
                break;
            }
        }
    }

    if(x==0){
        cout<<"APPROVED"<<endl;
    }
    else if (x==1){
        cout<<"DENIED"<<endl;
    }


}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().ToCharArray();
            var t = Console.ReadLine().ToCharArray();
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == t[i]) continue;
                Console.WriteLine("No");
                return;
            }
            Console.WriteLine("Yes");
        }
    }
}


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

#include <bits/stdc++.h>
using namespace std;
using Int = unsigned long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
int const mod = 1e9+7;
#define END {cout<<(ans)<<'\n'; return 0;}
#define ALL(vec) vec.begin(),vec.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,s,n) for(int i=s; i<n; 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]<<' '; cout<<a[(n)-1]<<'\n';
#define prip(p) cout<<(p).first<<' '<<(p).second<<'\n'
template<class T> inline bool cmin(T& a, T b) { if (a > b) { return a = b; } return false; }
template<class T> inline bool cmax(T& a, T b) { if (a < b) { return a = b; } return false; }

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(g.size(), INF);

  using Pi = pair< T, int >;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while(!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if(dist[idx] < cost) continue;
    for(auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}


int n,m,q,_,x,y;
string s,sb;
bool ok;
char ch;

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

  int c; V(int)d;
  while(1){
    cin>>n>>q; if(!n)return 0;
    WeightedGraph<int>g(n);
    rep(i,q){
      cin>>_;
      if(_){
        cin>>x>>y>>c;
        g[--x].eb(--y,c);
        g[y].eb(x,c);
      }else{
        cin>>x>>y;
        d=dijkstra(g,--x);
        cout<<(d[y-1]>1e9?-1:d[y-1])<<'\n';
      }
    }
  }
}


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

int main(void) {
    int n; cin >> n;
    double r = 1.05, q = 100000;
    for(int i = 0; i < n; i++) {
        q *= r;
        q = ceil(q / 1000) * 1000;
    }

    cout << (int)q << endl;
}

Measured memory_bytes: 2992
#include<vector>
#include<iostream>
#include<cstdlib>
#include<climits>
using namespace std;
int func(vector<int>& h,int k){
  int n=h.size();
  vector<int> dp(n,INT_MAX);
  dp[0]=0;
  for(int i=0;i<n;++i){
  	for(int j=i+1;j<=i+k && j<n;++j){
      dp[j] = min(dp[j],dp[i]+abs(h[j]-h[i]));
    }
  }
  return dp[n-1];
}
int main(){
  int n,k;cin>>n;cin>>k;
  vector<int> h(n);
  for(int i=0;i<n;++i)cin>>h[i];
  //vector<int> memo(n,-1);
  cout<<func(h,k);
  return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define see(x) cerr<<#x<<"="<<x<<endl;
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll fast(ll x,ll n) {ll ans=1;for(;n;n>>=1,x=x*x%mod) if(n&1) ans=ans*x%mod; return ans;}
const int N=1e6+100;

int main() {
    ll n;cin>>n;
    ll ans=0;
    for(int i=1;i<=n;i++)
        if(i%3&&i%5) ans+=i;
    cout<<ans;
}


Measured memory_bytes: 3644
def inp() a=gets.chomp.split(" ").map(&:to_i)end 
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def kaizyo(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b = na(a.max+1); a.each{|n|b[n]+=1};return b end
def na(n=0,d=0) Array.new(n,d)end
def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end
def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
n ,c,k= inp
d = []
ans = 0
max = 0
n.times do |i|
  d[i] = inp[0]
end
d.sort!
time = -999999999
cap = c
d.each do |i|
  cap -= 1
  if((i)>time or cap <= 0)
    time = i + k 
    cap = c
    ans +=1
  end
end
p ans

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int a[100050];
int main()
{
	int n;
	cin>>n;
	for(int i=0; i<n; i++)
		scanf("%d",&a[i]);
	sort(a,a+n);
	int ans;
	ans=a[n/2]-a[n/2-1];
	if(ans==0)
	cout<<0<<endl;
	else
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
dict = [*1..150].combination(2).map{|h,w| [h**2+w**2, h, w]}.sort
loop do
  h, w = gets.split.map(&:to_i)
  break if h==0

  r = dict[dict.index{|x| x[1] == h && x[2] ==w}+1]
  puts [r[1],r[2]].join(' ')
end

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

#define rep(i,a,b) for(int i=a;i<=b;i++)
typedef long long ll;
typedef unsigned long long ull;

const int maxn=1e5+5;
const int inf=0x3f3f3f3f;
const int bb=13331;
int a,b,c,d,n,m,k;
double q;
int main()
{
  cin>>n;
  a=n-n/2;
  q=1.0*a/n;
  printf("%.6f\n",q);
}

Measured memory_bytes: 256
from scipy.sparse.csgraph import floyd_warshall, csgraph_from_dense
H, W = map(int, input().split())
c = [tuple(map(int, input().split())) for i in range(10)]
A = [list(map(int, input().split())) for i in range(H)]
G = csgraph_from_dense(c)
C = floyd_warshall(G)

ans = 0
for i in range(H):
    for j in range(W):
        if A[i][j] >= 0:
            ans += int(C[A[i][j]][1])

print(ans)


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  cout << n * n * n << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
#define SIZE 100002
#define INF INT_MAX >> 1

using namespace std;

typedef long long ll;

ll dp[101][SIZE];//dp[n][w] := max_value

int main(void){
	ll n, w; cin >> n >> w;
	pair <ll, ll> p[101]; //(w, v)
	for(int i=0; i<n; i++){
		cin >> p[i].first >> p[i].second;
	}

	//配るDP
	for(int i=0; i<n; i++){
		for(int j=0; j<=w; j++){
			if(j-p[i].first >= 0){
				dp[i+1][j] = max(dp[i+1][j], dp[i][j-p[i].first] + p[i].second);
			}
			dp[i+1][j] = max(dp[i+1][j], dp[i][j]);

		}
	}

	ll ans = dp[n][w];
	//for(int i=0; i<=w; i++){// <=であることに注意
	//	ans = max(ans, dp[n][i]);
	//}
	cout << ans << endl;
}

Measured memory_bytes: 78336
//
//AtCoder Beginner Contest 144
//B - 81
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <functional>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

int main()
{
    int n;

    cin >> n;

    string ans = "No";

    FOR(i, 1, 9){
        FOR(j, i, 9){
            if (n == i * j) {
                ans = "Yes";
            }
        }
    }

    cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
long long int fact(long long int n)
{
    if(n==1 || n==0)
        return 1;
    else
        return ((n%M)*(fact(n-1)%M))%M;

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
 
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
 
   #endif
   int n,m;
   cin>>n>>m;
   int arr[n]={0};
   while(m--)
   {
    int a,b;
    cin>>a>>b;
    arr[a-1]++;
    arr[b-1]++;

   }
   for(int i=0;i<n;i++)
   {
       cout<<arr[i]<<endl;
   }


    return 0;
}








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

ll combination(int x, int y){
	if(x < y) return 0;
	ll a = 1;
	ll b = 1;
	rep(i,y){
		a *= i+1;
		b *= x-i;	
	}
	return b/a;
}

		

int main(){
	int n;
	cin >> n;
	vector<string> s(n+1);
	rep(i,n){
		cin >> s[i];
		sort(s[i].begin(), s[i].end());
	}
	sort(s.begin(), s.end()-1);
	ll ans=0, count=1;
	string tmp = "nyo";
	s[n] = "nyo";
	rep(i,n+1){
		if(tmp == s[i]){
			count++;
		}else{
			tmp = s[i];
			ans += combination(count, 2);
			count=1;
		}
	}		
	cout << ans << endl;
	return 0;
}

		


Measured memory_bytes: 7296
N, A, B = map(int, input().split())

if (B - A) % 2 == 0:
  print((B - A) // 2)
else:
  #A->1.1, B->B-A
  a = A + (B-A-1)//2
  #A->A+N-B+1, B->N.N
  b = N-B+1 + (- A + B - 1)//2
  
  print(min(a,b))


Measured memory_bytes: 2940
#include <stdio.h>

using namespace std;

int main(){
	int a,b;
	double a_d,b_d;
	scanf("%d %d",&a,&b);
	a_d = static_cast<double>(a);
	b_d = static_cast<double>(b);
	printf("%d %d %.5f\n",a/b,a%b,a_d/b_d);
}


Measured memory_bytes: 2736
from collections import deque
import sys
sys.setrecursionlimit(10 ** 9)


n = int(input())
query = [[] for i in range(n)]
for i in range(n-1):
    a, b, c = map(int, input().split())
    query[a-1].append((b-1, c))
    query[b-1].append((a-1, c))
q, k = map(int, input().split())
stack = deque([(k-1, 0, -1)])
dist = [0] * n
while stack:
    now, cnt, per = stack.pop()
    lis = query[now]
    dist[now] = cnt
    for nx, c in lis:
        if nx == per:
            continue
        if c != 0:
            stack.append((nx, cnt+c, now))
for i in range(q):
    x, y = map(int, input().split())
    print(dist[x-1] + dist[y-1])


Measured memory_bytes: 50528
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int N;

int main()
{
    cin >> N;
    cout << (N + 1) / 2 << endl;
}


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

#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;

typedef long long ll;



int main(){

    int n;
    cin >> n;

    map<string, int> m;

    int countmax = 0;

    rep(i,n){
        string s;
        cin >> s;

        int tmp;

        tmp = m[s];
        tmp++;
        m[s] = tmp;

        countmax = max(countmax, tmp);
    }

    for(auto it = m.begin(); it != m.end(); it++){
        string tmps = (*it).first;
        int tmpi = (*it).second;

        if(tmpi == countmax){
            cout << tmps << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 25216
#include <iostream>
#include <stdio.h>
#include <stack>
#include <vector>

using namespace std;
const int nil = -1;

int total, n, m, q;

vector<int>* vecs;
typedef int Comm;
Comm* comms;

void find_connection(int from){
	stack<int> stk;
	stk.push(from);

	while(stk.size()){
		int top = stk.top();
		comms[top] = from;
		for(int i=0, sz=vecs[top].size(); i<=sz; ++i){
			if(i==sz){
				stk.pop();
				break;
			}
			if(comms[vecs[top][i]] == nil){
				stk.push(vecs[top][i]);
				break;
			}
		}
	}
}

int main()
{
	scanf("%d %d",&n,&m);
	vecs = new vector<int> [n];
	comms = new Comm [n];

	for(int i=0; i<n; ++i){
		comms[i] = nil;
	}

	for(int i=0; i<m; ++i){
		int id, f;
		scanf("%d %d",&id,&f);
		vecs[id].push_back(f);
		vecs[f].push_back(id);
	}

	scanf("%d",&q);
	for(int i=0; i<q;++i){
		int from, to;
		scanf("%d %d",&from,&to);
		if(comms[from]==nil && comms[to]==nil){
			find_connection(from);
			if(comms[from] == comms[to]){
				cout << "yes" << endl;
			}
			else{
				cout << "no" << endl;
			}
		}
		else if(comms[from] == comms[to]){
			cout << "yes" << endl;
		}
		else{
			cout << "no" << endl;
		}
	}

	delete[] comms;
	delete[] vecs;

	return 0;
}


Measured memory_bytes: 8992
def p_c():
    n, m = map(int, input().split())
    ab = [tuple(map(int, input().split())) for _ in range(n)]
    ab.sort()
    ans = 0
    for i in range(n):
        a, b = ab[i]
        b = min(m, b)
        ans += a * b
        m -= b
        if m == 0:
            break
    print(ans)
    
p_c()

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    bool flag = false;

    while(k>0){
        if(b > a) break;
        b *= 2;
        k--;
    }
    if(b > a){
        while(k>0){
            if(c>b){
                flag = true;
                break;
            }
            c *= 2;
            k--;
        }
    }
    if(c > b) flag = true;
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;


}

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
ll MOD = ll(1e8) + 9;

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    int N, R;
    cin >> N >> R;

    if (N >= 10) {
        cout << R << endl;
    } else {
        cout << 100 * (10 - N) + R << endl;
    }


    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Kenji
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC096A solver = new ABC096A();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC096A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int ans = (a - 1) + (a <= b ? 1 : 0);
            out.println(ans);
        }

    }
}



Measured memory_bytes: 21972
# -*- coding: utf-8 -*-
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
ans = 0
for i in range(n // 3):
    ans += combinations_count(n-3*(i+1)+i, i)

print(ans % (10**9 + 7))

Measured memory_bytes: 9200
#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define M 1000000007
#define M2 998244353
#define ll long long
#define pll pair<long, long>
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define ff first
#define ss second
#define pb push_back
#define db pop_back
#define mp make_pair
#define mt make_tuple
#define g(a, b) get<a>(b)
#define INF (ll)1e18 + 100
#define vl vector<ll>
#define vi vector<int>
#define vll vector<pair<ll, ll>>
#define vii vector<pair<int, int>>
#define all(v) v.begin(),v.end()
#define bset(a, p) ((a) | (1ll << (p)))
#define bchk(a, p) ((a) & (1ll << (p)))
#define bxor(a, p) ((a) ^ (1ll << (p)));
#define brem(a, p) (bchk(a, p) ? (bxor(a, p)) : (a))
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

ll modI(ll a, ll m);
ll gcd(ll a, ll b);
ll powM(ll x, unsigned ll y, unsigned ll m);
void pairsort(int a[], int b[], int n);
void pairsortll(ll a[],ll b[],ll n);
ll logint(ll x,ll y);
 
 
ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}
 
ll powM(ll x,ll y,ll m)
{
    if(y==0) return 1;
    ll p=powM(x,y/2,m)%m;
    p=(p*p)%m;
    return (y%2==0)?p:(x*p)%m;
}
 
ll modI(ll a, ll m)
{
   return powM(a, m-2, m);
}
 
void pairsort(int a[],int b[],int n)
{
    pair<int,int> v[n];
    REP(i,0,n)
    {
        v[i].ff=a[i];
        v[i].ss=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].ff;
        b[i]=v[i].ss;
    }
}
 
void pairsortll(ll a[],ll b[],ll n)
{
    pair<ll,ll> v[n];
    REP(i,0,n)
    {
        v[i].ff=a[i];
        v[i].ss=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].ff;
        b[i]=v[i].ss;
    }
}
 
ll logint(ll x,ll y)
{
    ll ans=0;
    ll a=1;
    for(ll i=0;i<=x;i++)
    {
        if(x<a)
        {
            return ans;
        }
        ans++;
        a*=y;
    }
    return -1;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s;int n;
    cin>>n>>s;
    if(n%2){cout<<"No";}
    else{
        string t = "";
        REP(i,0, n/2){t.pb(s[i]);}
        t += t;
        if(t==s){cout<<"Yes";}
        else{cout<<"No";}
    }

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 1 << 21;
using pii = std::pair<int, int>;
#define SORT(v) std::sort(v.begin(), v.end())


int main(void) {
	int N;
	long long X;
	std::cin >> X;
	long long ans = 0;
	ans =(X / 11) * 2;
	long long t = X % 11;
	if (t >= 1 && t <= 6) ans++;
	else if (t >= 7) ans += 2;
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 2e5+10;
int N, K, nxt[MAXN], t[MAXN];
int dfs(int v, int k){
	if(t[v]){
		int ciclo = k + 1 - t[v];
		K = (K - t[v] + 1) % ciclo;
		k = 0;
		memset(t, 0, sizeof(t));
	}
	if(k == K) return v + 1;
	t[v] = k + 1;
	return dfs(nxt[v], k + 1);
}
main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
	cin >> N >> K;
	for(int i = 0; i < N; i++) cin >> nxt[i], nxt[i]--;
	cout << dfs(0, 0);
}

Measured memory_bytes: 6756
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cstring>
#include<string>
#include<iomanip>
#include<map>
#include<fstream>
#include<queue>
#include<set>
#include<deque>

using namespace std;

int main()
{
	long long  n, t, res = 0;
	vector<int> a, b, c;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> t;
		a.push_back(t);
	}
	for (int i = 0; i < n; i++) {
		cin >> t;
		b.push_back(t);
	}
	for (int i = 0; i < n; i++) {
		cin >> t;
		c.push_back(t);
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());

	for (int i = 0; i < n; i++) {
		auto x = lower_bound(a.begin(), a.end(), b[i]);
		auto y = upper_bound(c.begin(), c.end(), b[i]);

		long long z = (x-a.begin()) * (n-(y-c.begin()));
		res += z;
	}
	cout << res << endl;
}

Measured memory_bytes: 1784
N, K = map(int,input().split())
list = range(1,N+1)
ans=[0]*N
i = 1
j = 0

for n in reversed(list):
    while n*i < K:
        i = i*2
    ans[n-1] = i
for k in ans:
    j += 1/k*1/N

print(j)


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

#define mp make_pair
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int cys=998244353;
int n,m;
ll ans=0;
ll fac[500005],inv[500005];

ll C(ll x,ll y){return x<y?0:fac[x]*inv[y]%cys*inv[x-y]%cys;}

ll qpow(ll x,ll p){
	ll ret=1;
	for(;p;p>>=1,x=x*x%cys) if(p&1) ret=ret*x%cys;
	return ret;
}

int main(){
	n=readint(); m=readint();
	fac[0]=inv[0]=1;
	for(int i=1;i<=max(n,m);i++) fac[i]=fac[i-1]*i%cys;
	inv[max(n,m)]=qpow(fac[max(n,m)],cys-2);
	for(int i=max(n,m)-1;i>=1;i--) inv[i]=inv[i+1]*(i+1)%cys;
	for(int i=0;i<=min(n,m);i++) ans=(ans+(i&1?cys-1:1)*C(n,i)%cys*C(m,i)%cys*fac[i]%cys*qpow(m+1,n-i)%cys*qpow(n+1,m-i)%cys)%cys;
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;
using ll = long long;


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

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	/*
	iとjとkはループ変数、limit_valueとsum_valueは入力される上限値と合計値
	calc_valueは3つの数値を足した結果を、countは組み合わせの数を格納
	*/

	int i, j, k;
	int limit_value, sum_value;
	int calc_value, count;

	while(1){
		//初期値は0
		count = 0;
		scanf("%d %d", &limit_value, &sum_value);

		//データセットがともに0ならば終了
		if((limit_value == 0) && (sum_value == 0)){
			break;
		}
		else{
			//総当たりで組み合わせを探す
			for(i = 1; i <= (limit_value - 2); i++){
				for(j = (i + 1); j <= (limit_value - 1); j++){
					for(k = (j + 1); k <= limit_value; k++){
						calc_value = i + j + k;
						if(calc_value == sum_value){
							count++;
						}
					}
				}
			}
			//結果を出力
			printf("%d\n", count);
		}
	}

	return 0;
}


Measured memory_bytes: 2056
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> pint;
#define rep(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

int day[]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int main(){
	int m,d;
	for(;cin>>m>>d,m;){
		for(int i=1;i<m;i++){
			d+=day[i];
		}
		switch(d%7){
		case 0:
		cout<<"Wednesday"<<endl;
		break;
		case 1:
		cout<<"Thursday"<<endl;
		break;
		case 2:
		cout<<"Friday"<<endl;
		break;
		case 3:
		cout<<"Saturday"<<endl;
		break;
		case 4:
		cout<<"Sunday"<<endl;
		break;
		case 5:
		cout<<"Monday"<<endl;
		break;
		case 6:
		cout<<"Tuesday"<<endl;
		break;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
int W,H;
bool inrange(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
#define MP make_pair
signed main(){
    int a,b,k;cin>>a>>b>>k;
    map<int,int>mp;
    rep(i,k){if(i+a>b)break;else cout<<a+i<<endl;mp[a+i]++;}
    for(int i=b-k+1;i<=b;i++)
        if(i<a)continue;
        else if(mp[i]==0) cout<<i<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,t;
int m[1001],l[1001],k[1001];
bool used[1001];
int pl[2001];
int cnt[1001];
int nxt[1001];

bool C(int v){
	memset(used,0,sizeof(used));
	memset(pl,0,sizeof(pl));
	memset(cnt,0,sizeof(cnt));
	memset(nxt,0,sizeof(nxt));
	int call=0;
	for(int i=0;i<t;i++){
		call-=pl[i];
		for(int j=0;j<n;j++){
			if(call==v)break;
			if(!used[j] && nxt[j]<=i){
				used[j]=true;
				pl[i+m[j]]++;
				if(i+m[j]>t)return false;
				call++;
			}
		}
		for(int j=0;j<n;j++){
			if(!used[j]){
				if(nxt[j]<=i){
					cnt[j]++;
				}
				if(cnt[j]==(l[j]+1)){
					cnt[j]=0;
					nxt[j]=i+k[j];
				}
			}
		}
	}
	for(int i=0;i<n;i++){
		if(!used[i])return false;
	}
	return true;
}

int main(void){
	while(1){
		scanf("%d%d",&n,&t);
		if(n==0)break;
		for(int i=0;i<n;i++){
			scanf("%d%d%d",&m[i],&l[i],&k[i]);
		}
		for(int i=1;i<=n;i++){
			if(C(i)){
				printf("%d\n",i);
				break;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3184
/*
很巧妙的一道图论题，难度在于建图&猜结论。
考虑到有两种连接方式：，对于相邻的两块，左边的在上，记为正高度；右边的在上，记为负高度。
一般地，我们可以用(l,r)表示一块积木：
如果ci=0, l=ai, 否则, l=-ci。
如果di=0, r=-bi, 否则, r=di。
假设在(l',r')的右边放上(l,r)的积木，当且仅当:
	l和r'的符号不同		或		r=l'。
需要满足最左端的l是正数，最右端的r是负数。
	
考虑构造2H个点(-H,-H+1,...,-1,1,2,3,...,H)，
对于所有(li,ri)连边，
题目的要求等价于将图划分为若干不相交的路径。
且所有路径必须从正点出发，负点结束。

题目的条件等价于:
对于所有正点，出度>=入度。
对于所有负点，入度>=出度。
对于所有弱连通块，一定存在点，入度!=出度。

显然，这个是必要条件。而充分条件可以通过构造得出。
任意选择一正点出发，直到无法再走。
我们会得到两种集合：
满足条件的路径，或者一个环。

如何消去环？
根据条件3，我们可以将环与环（或路径合并），
最终一定可以找到一个路径与之合并。
*/
#include<bits/stdc++.h>
using namespace std;

const int maxn = 409;
int in[maxn], out[maxn], pa[maxn], flag[maxn];
int n, H, a, b, c, d;

int getpa(int x) {
	return pa[x] == x ? x : pa[x] = getpa(pa[x]);
}

int main() {
	scanf("%d%d", &n, &H);
	for (int i=1; i<=2*H; i++) pa[i] = i;
	for (int i=1; i<=n; i++) {
		scanf("%d%d%d%d", &a, &b, &c, &d);
		if (c) a = c + H; 
		if (!d) b = b + H; else b = d;
		out[a]++; in[b]++;
		pa[getpa(a)] = getpa(b);
	}
	//for (int i=1; i<=2*H; i++) printf("%d %d %d\n", i, in[i], out[i]);
	for (int i=1; i<=H; i++)
		if (out[i] < in[i]) { puts("NO"); return 0; }
	for (int i=H+1; i<=2*H; i++)
		if (in[i] < out[i]) { puts("NO"); return 0; }
	for (int i=1; i<=2*H; i++)
		if (in[i] != out[i]) flag[getpa(i)] = 1;
	for (int i=1; i<=2*H; i++)
		if (pa[i] == i && !flag[i] && in[i] && out[i]) { puts("NO"); return 0; }
	puts("YES");
	return 0;
}

Measured memory_bytes: 256
n = int(input())
data = [list(map(int, input().split())) for _ in range(n)]

def check(t, x, y):
    if t < (x + y):
        return False
    if t % 2 != (x+y) % 2:
        return False
    return True


ok = True
for t, x, y  in data:
    if not check(t, x, y):
        ok = False
        break
print('Yes') if ok else print('No')

Measured memory_bytes: 27380
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

vector< vector<int> > A = vector< vector<int> >(50, vector<int>(50, -1));
vector< vector<int> > B = vector< vector<int> >(50, vector<int>(50, -1));

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

    int N, M;
    cin >> N >> M;

    string s;
    rep (i, N)
    {
        cin >> s;
        rep (j, N)
        {
            A[i][j] = (s[j] == '.' ? 0 : 1);
        }
    }
    rep (i, M)
    {
        cin >> s;
        rep (j, M)
        {
            B[i][j] = (s[j] == '.' ? 0 : 1);
        }
    }

    bool ans = false;
    for (int i = 0; i < N - M + 1 && !ans; ++i)
    {
        for (int j = 0; j < N - M + 1 && !ans; ++j)
        {
            int temp = 0;
            rep (ii, M)
            {
                rep (jj, M)
                {
                    temp |= A[i + ii][j + jj] ^ B[ii][jj];
                }
            }
            if (temp == 0) ans = true;
        }
    }

    if (ans) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
        while(true){
            int a=sc.nextInt();
            int b=sc.nextInt();
            if(a==0&&b==0)
                break;
            
            if(a>b){
                System.out.println(b+" "+a);
            }else{
                System.out.println(a+" "+b);
            }
            
        }
    }
}


Measured memory_bytes: 35716
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (ql:quickload '(:cl-debug-print :fiveam))
  #-swank (set-dispatch-macro-character #\# #\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)
#-swank (disable-debugger) ; for CS Academy

;; BEGIN_INSERTED_CONTENTS
(defmacro with-buffered-stdout (&body body)
  "Buffers all outputs to *STANDARD-OUTPUT* in BODY and flushes them to
*STANDARD-OUTPUT* after BODY has been done (without error). Note that only
BASE-CHAR is allowed."
  (let ((out (gensym)))
    `(let ((,out (make-string-output-stream :element-type 'base-char)))
       (let ((*standard-output* ,out))
         ,@body)
       (write-string (get-output-stream-string ,out)))))

(declaim (ftype (function * (values fixnum &optional)) read-digit))
(defun read-digit (&optional (in *standard-input*))
  (declare #.OPT)
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (loop (let ((byte (%read-byte)))
            (cond ((<= 48 byte 57)
                   (return (- byte 48)))
                  ((zerop byte) ; #\Nul
                   (error "Read EOF or #\Nul.")))))))

(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (declare #.OPT)
  (let* ((n (read))
         (res (make-array (+ 1 n) :element-type 'bit :initial-element 0)))
    (declare (uint31 n))
    (loop for i from 1 to n do (setf (aref res i) (read-digit)))
    (loop for i from n downto 1
          do (loop with xor of-type bit = (aref res i)
                   for j from (* 2 i) to n by i
                   do (setf xor (logxor xor (aref res j)))
                   finally (setf (aref res i) xor)))
    (let ((count (count 1 res)))
      (with-buffered-stdout
        (println count)
        (loop for i from 1 to n
              when (= (aref res i) 1)
              do (println i))))))

#-swank (main)


Measured memory_bytes: 22880
#include <iostream>
#include <algorithm>
#include <vector>
  

using namespace std;
int main() {
  long long int a,b,c,tmp,ans=0,zero=0;
  cin >> a >> b >> c;
  vector <long long int> d(a+1);
  vector <long long int> e(b+1);
  d.at(0)=0,e.at(0)=0;
  for(int i = 1;i<a+1;i++){
    cin >> tmp;
    if((d.at(i-1)+tmp)<=c)d.at(i)=d.at(i-1)+tmp;
    else d.at(i) = c+1;
  }
  for(int i = 1;i<b+1;i++){
    cin >> tmp;
    if((e.at(i-1)+tmp)<=c)e.at(i)=e.at(i-1)+tmp;
    else e[i] = c+1;
  }
  if(d.at(1)>c&&e.at(1)>c)cout << 0;
  else if((d.at(a)+e.at(b))<=c) cout <<  a+b;
  else {
    for(int i = 0;i<a+1;i++){
    long long int sum = 0;
    tmp = d.at(i);
    if(tmp>c) break;
    for(int j=max(zero,ans-i);j<b+1;j++){
    if((tmp+e.at(j))<=c){
      sum = i+j;
     
    }
     else break;
    }
    ans = max(ans,sum);
    }
  cout << ans;
  }
}

Measured memory_bytes: 6284
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
using Graph = vector<vector<int>>;

int cnt[500000];

vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        //cout << v << " " << cnt[v] << "\n";
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        cnt[v] += 1;
        dfs(G, next_v); // 再帰的に探索
    }
}

int main() {
    int N; cin >> N;
    // グラフ入力受取 (ここでは無向グラフを想定)
    Graph G(N);
    for (int i = 1; i < N; ++i) {
        int a;
        cin >> a;
        G[i].push_back(a-1);
        G[a-1].push_back(i);
    }

    // 頂点 0 をスタートとした探索
    seen.assign(N, false); // 全頂点を「未訪問」に初期化
    dfs(G, 0);
    for(int i = 0; i < N; ++i) cout << cnt[i] << "\n";
    return 0;
}

Measured memory_bytes: 24312
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let s: String = read().unwrap();

    let a = s.chars()
        .nth(0)
        .unwrap()
        .to_string()
        .parse::<i32>()
        .unwrap();
    let b = s.chars()
        .nth(1)
        .unwrap()
        .to_string()
        .parse::<i32>()
        .unwrap();
    let c = s.chars()
        .nth(2)
        .unwrap()
        .to_string()
        .parse::<i32>()
        .unwrap();
    let d = s.chars()
        .nth(3)
        .unwrap()
        .to_string()
        .parse::<i32>()
        .unwrap();

    let mut op = vec!['+', '-'];

    for i in 0..op.len() {
        let mut ans1: i32 = 0;
        if op[i] == '+' {
            ans1 = a + b;
        } else {
            ans1 = a - b;
        }
        for j in 0..op.len() {
            let mut ans2: i32 = 0;
            if op[j] == '+' {
                ans2 = ans1 + c;
            } else {
                ans2 = ans1 - c;
            }
            for k in 0..op.len() {
                let mut ans3: i32 = 0;
                if op[k] == '+' {
                    ans3 = ans2 + d;
                } else {
                    ans3 = ans2 - d;
                }
                if ans3 == 7 {
                    println!("{}{}{}{}{}{}{}=7", a, op[i], b, op[j], c, op[k], d);
                    return;
                }
            }
        }
    }
    return;
}


Measured memory_bytes: 4352
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, happy = 0;
  cin >> n;
  happy += n / 500 * 1000;
  n %= 500;
  happy += n / 5 * 5;
  cout << happy << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define INFTY 10000000
using namespace std;
int n;
vector<pair<int,int> >G[10000];
int d[10000],flag[10000];
vector<int>path;
void dijkstra(){
    path.push_back(0);
    //int distance=0;
    int mini,min;
    while(path.size()<n){
        min=INFTY;
        int index=path.size()-1;
        //distance+=path[path.size()-1];
        for(int i=0;i<G[path[index]].size();i++)
        {
            int temp=d[path[index]]+G[path[index]][i].second;
            if(d[G[path[index]][i].first]>temp)
                d[G[path[index]][i].first]=temp;
        }
        for(int i=1;i<n;i++)
        {
            if(flag[i])continue;
            if(d[i]<min)
            {
                min=d[i];
                mini=i;
            }
        }
        path.push_back(mini);
        flag[mini]=1;
        //distance+=path[path.size()-1];
    }
}
int main()
{
    int u,k,v,c;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        d[i]=INFTY;
        flag[i]=0;
    }
    for(int i=0;i<n;i++)
    {
        cin>>u>>k;
        for(int j=0;j<k;j++)
        {
            cin>>v>>c;
            G[u].push_back(make_pair(v,c));
        }
    }
    d[0]=0;
    dijkstra();
    for(int i=0;i<n;i++)
        cout<<i<<' '<<d[i]<<endl;
    return 0;
}


Measured memory_bytes: 8000
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
 
        Scanner sc  = new Scanner(System.in);
 
        int K = Integer.parseInt(sc.next());
        int S = Integer.parseInt(sc.next());
        int count = 0;
        
        int z=0;
 
        for (int x=0;x<K+1;x++){
            for (int y=0;y<K+1;y++){
                 z = S-x-y;
                 if(z<=K&&z>=0){
                   //     System.out.println("x:"+x+"y:"+y+"z:"+z);
                        count++;
                    
                }
            }
        } 

        System.out.print(count);
        System.out.println();
    }
 
}

Measured memory_bytes: 9680
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(Console.ReadLine());

        var A = Console.ReadLine().Split(' ').ToArray();

        float denominator = 0.0f;

        for (var i = 0; i < N; i++)
        {
            denominator = denominator + 1.0f / float.Parse(A[i]);
        }

        Console.WriteLine(1 / denominator);
    }
}


Measured memory_bytes: 11220