akhauriyash/Code-Regression huggingface dataset:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))


N,K = LI()
ab = [0 for i in range(N-1)]
for i in range(N-1):
    ab[i] = LI()

edges = {}
for i in range(N):
    edges[i] = []
count = [0 for i in range(N)]
for i in range(N-1):
    a,b = ab[i]
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)

def dfs(node,p):
    cnt = 0
    for i,new_node in enumerate(edges[node]):
        if new_node == p:
            continue
        else:
            p_cnt = 2
            if node == 0:
                p_cnt = 1
            count[new_node] = K - p_cnt - cnt
            cnt += 1
            dfs(new_node,node)


count[0] = K
dfs(0,-1)
# print(count)
ans = 1
for i in range(N):
    ans = ans *count[i] % mod

print(ans)


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

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

int n, a, b, c;
vector<int> l;
int nin = 1e6;


void dfs(int depth, int cost, int al, int bl, int cl) {
	if(depth == n) {
		if(al == 0 || bl == 0 || cl == 0)return ;
		if(cl > bl)swap(bl, cl);
		if(bl > al)swap(al, bl);
		if(cl > bl)swap(bl, cl);
		nin = min(abs(c - cl) + abs(b - bl) + abs(a - al) + cost, nin);
		return;
	}

	dfs(depth + 1, cost, al, bl, cl);
	dfs(depth + 1, cost + (al == 0 ? 0 : 10), al + l[depth], bl, cl);
	dfs(depth + 1, cost + (bl == 0 ? 0 : 10), al, bl + l[depth], cl);
	dfs(depth + 1, cost + (cl == 0 ? 0 : 10), al, bl, cl + l[depth]);
	return;
} 

int main()
{
	cin >> n >> a >> b >> c;
	l.resize(n);
	for(int i = 0; i < n; i++)cin >> l[i];
	dfs(0, 0, 0, 0, 0);
	cout << nin << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<int,int> P;

int h,w;
vector<vector<char> > c(110,vector<char>(110));
vector<int> dx={0,1},dy={1,0};
vector<int> ma[110],ma2[110];

//bfs
void bfs(int sx,vector<vector<int> > &d){
    queue<P> que;
    d[sx][1]=0;
    que.push(P(sx,1));
    while(!que.empty()){
        P p=que.front();
        que.pop();
        if(p.second==w){
            //cout<<p.first<<' '<<p.second<<'\n';
            ma[sx].push_back(p.first);
            ma[p.second].push_back(sx);
        }
        rep(i,2){
            int nx=p.first+dx[i];
            int ny=p.second+dy[i];
            if(1<=nx && nx<=h && 1<=ny && ny<=w && c[nx][ny]!='#' && d[nx][ny]==-1){
                que.push(P(nx,ny));
                //cout<<nx<<' '<<ny<<'\n';
                d[nx][ny]=d[p.first][p.second]+1;
            }
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    map<ll,ll> a;
    rep(i,n){
      ll x;
      cin>>x;
      a[x]++;
    }
    ll ans=0;
    for(auto itr:a){
      if(itr.second%2==1){
        ans++;
      }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6528
n, t = map(int, input().split())
c = []
for _ in range(n):
    c.append(list(map(int, input().split(" "))))
a = [c[i][0] for i in range(len(c)) if c[i][1] <= t]
if len(a) > 0:
    print(min(a))
else:
    print("TLE")

Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>
//#include <bits/stdc++.h>

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

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

using namespace std;
#define ALL(X) X.begin(),X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=1001001000;
const ll LLMAX=1010010010010010000;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N,K;
    cin>>N>>K;
    vll x(N),y(N);
    for(ll i=0;i<N;i++)cin>>x[i]>>y[i];
    
    ll ans=-1;
    for(ll i1=0;i1<N;i1++){
        for(ll i2=0;i2<N;i2++){
            for(ll j1=0;j1<N;j1++){
                for(ll j2=0;j2<N;j2++){
                    ll x1=min(x[i1],x[i2]);
                    ll x2=max(x[i1],x[i2]);
                    ll y1=min(y[j1],y[j2]);
                    ll y2=max(y[j1],y[j2]);
                    ll count=0;
                    for(ll i=0;i<N;i++){
                        if(x1<=x[i] && x[i]<=x2 && y1<=y[i] && y[i]<=y2){
                            count++;
                            if(count==K)break;
                        }
                    }
                    //printf("x:%d,%d,,y:%d,%d,,count:%d\n",x1,x2,y1,y2,count);
                    if(count==K){
                        if(ans==-1)ans=(x2-x1)*(y2-y1);
                        else chmin(ans,(x2-x1)*(y2-y1));
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            final String sl[] = s.split(" ");
            int X = Integer.parseInt(sl[0]);
            int A = Integer.parseInt(sl[1]);
            int B = Integer.parseInt(sl[2]);

            System.out.println(
                B - A <= 0 ? "delicious" : B - A <= X ? "safe" : "dangerous");
        }
    }
}


Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> a(M), b(M), countList(N);
  
  for(int i=0; i<M; i++){
    cin >> a.at(i);
    cin >> b.at(i);
   }
  
  for(int i = 0; i<M; i++){
    for(int j = 1; j<N+1; j++){    
      if(a.at(i)==j || b.at(i)==j){
      countList.at(j-1)++;
      }
    }
  } 
  for(int i=0; i<N; i++){
    cout << countList.at(i) <<endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int a,b;

int main(void)
{
	scanf("%d %d",&a,&b);

	if(a == b){
		printf("a == b\n");
	}else if(a>b){
		printf("a > b\n");
	}else{
		printf("a < b\n");
	}

	return 0;
}

Measured memory_bytes: 580
package main

import "fmt"

func max(ns []int) int {
	m := ns[0]
	for _, v := range ns {
		if v > m {
			m = v
		}
	}
	return m
}

func main() {
	var n int
	fmt.Scan(&n)
	ns := make([]int, n)
	for i := range ns {
		fmt.Scan(&ns[i])
	}

	sum := 0
	for _, v := range ns {
		sum += v
	}

	m := max(ns)

	if sum-m > m {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
using namespace std;

const long long MOD = 1000000007;

// Ref.[1] https://qiita.com/ofutonfuton/items/c17dfd33fc542c222396 //
// Ref.[2] https://atcoder.jp/contests/abc120/submissions/4444370 //
class UnionFind {
    vector<int> par,sz;
  public:

    // Initialize. All vertices are roots when initial state.
    UnionFind(int N) : par(N),sz(N) {
      REP(n,N){
        par[n] = n;
        sz[n] = 1;
      }
    }

    // Return the root of tree which consists of vertex(x)
    int root(int x) {
      if (par[x] == x) return x;     // If x is the root, return x
      return par[x] = root(par[x]);  // Recursively find the root of tree. 
    }

    // Unite two vertices into one tree. 
    void unite(int x, int y) {
      int rx = root(x);       // root of x
      int ry = root(y);       // root of y
      if (rx == ry) return;   // do nothing if root of x is the same as root of y
      if(sz[rx] > sz[ry]){
        par[ry] = rx;
        sz[rx] += sz[ry];
      }else{
        par[rx] = ry;
        sz[ry] += sz[rx];
      }
    }

    // Return true if two vertices has the same root, else return false.
    bool same(int x, int y) { return root(x) == root(y); }

    // Return the number of vertices which are component of a tree
    int size(int x){ return sz[root(x)]; }
};

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

  vector<int> A(M);
  vector<int> B(M);

  UnionFind orgtree(N);

  REP(m,M){
    cin >> A.at(m) >> B.at(m);
    A.at(m) -= 1, B.at(m) -= 1;
    orgtree.unite(A.at(m),B.at(m));
  }

  int ans = 0;
  REP(m,M){
    UnionFind brokentree(N);
    REP(mm,M){
      if (mm == m) continue;
      brokentree.unite(A.at(mm),B.at(mm));
    }
    if(orgtree.size(orgtree.root(0)) != brokentree.size(brokentree.root(0))) ans +=1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int main(){
	int N;
	cin>>N;
	vector<string> s(N);
	rep(i,N) cin>>s[i];
	int ans = 0;
	rep(d,N){
		rep(i,N) rotate(s[i].begin(),s[i].begin()+1,s[i].end());
		bool ok = 1;
		rep(i,N) rep(j,N) if(s[i][j]!=s[j][i]) ok = 0;
		if(ok) ans += N;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<cmath>
#include<set>
#include<stack>

using namespace std;
typedef unsigned long long ll;

int main(){
    int n,m,p;
    while(cin>>n>>m>>p,n){
        int x,y;
        int tot=0;
        for(int i=0;i<n;i++){
            cin>>x;
            tot+=x;
            if(i==m-1){
                y=x;
            }
        }
        cout<<(y==0?0:(tot*100*(100-p)/100)/y)<<endl;
    }
    return 0;
}

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

int main(){
	
	long long r ,d,x;
	cin >> r >> d>> x;
	long long arr[11];
	arr[0] = x;
	for(int i =1 ; i<=10 ;i++){
		arr[i] = r*arr[i-1] - d;
	}
	for(int i =1; i<=10;i++)
		cout<<arr[i] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;

using namespace std;

int main(int argc, char* argv[])
{
    long a,b,t;
    scanf("%ld%ld%ld", &a, &b, &t);

    printf("%ld\n", t/a*b);



    return 0;
}


Measured memory_bytes: 128
def main():
    I=lambda:input()
    s=I()
    if s!=s[::-1]:
        print('No')
        exit()
    s1=s[:(len(s)-1//2)+1]
    if s1!=s1[::-1]:
        print('No')
        exit()
    s2=s[(len(s)+3)//2-1:]
    if s2!=s2[::-1]:
        print('No')
        exit()
    print('Yes')
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

MIN=min(a)+min(b)

for i in range(M):
    x,y,c=map(int,input().split())
    if a[x-1]+b[y-1]-c<MIN:
        MIN=a[x-1]+b[y-1]-c
print(MIN)

Measured memory_bytes: 70124
#!/usr/bin/perl
my ($n) = map { $_ - 0 } split(/\s+/,<STDIN>);
my @a = map { $_ - 0 } split(/\s+/,<STDIN>);
my @b = map { $_ - 0 } split(/\s+/,<STDIN>);
my @c = map { $_ - 0 } split(/\s+/,<STDIN>);

my $sb = 0;
$sb += $_ for @b;
for(my $i=0;$i<$n-1;$i++){
  $sb += $c[$a[$i]-1] if( $a[$i] + 1 == $a[$i+1] );
}
print "$sb\n";



Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int a, b;
  cin >> a >> b;

  a--;
  b--;

  cout << (b + a - 1) / a << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using static System.Console;
using static System.Math;

namespace NotFounds
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve();
        }

        public void Solve()
        {
            MyInputStream cin = new MyInputStream();
            WriteLine(Max(cin.ReadInt() * cin.ReadInt(), cin.ReadInt() * cin.ReadInt()));
        }
    }

    public class MyInputStream
    {
        private char separator = ' ';
        private Queue<string> inputStream;
        public MyInputStream(char separator = ' ')
        {
            this.separator = separator;
            inputStream = new Queue<string>();
        }

        public string Read()
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = Console.ReadLine().Split(separator);
            for (int i = 0; i < tmp.Length; i++)
            {
                inputStream.Enqueue(tmp[i]);
            }
            return inputStream.Dequeue();
        }
        public string ReadLine() => Console.ReadLine();
        public int ReadInt() => int.Parse(Read());
        public long ReadLong() => long.Parse(Read());
        public double ReadDouble() => double.Parse(Read());
    }

    public class Pair<T1, T2>
    {
        public T1 First;
        public T2 Second;
        public Pair() { First = default(T1); Second = default(T2); }
        public Pair(T1 f, T2 s) { First = f; Second = s; }
        public override string ToString() { return "(" + First + ", " + Second + ")"; }
        public override int GetHashCode() { return First.GetHashCode() ^ Second.GetHashCode(); }
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(this, obj)) return true;
            else if (obj == null) return false;
            var tmp = obj as Pair<T1, T2>;
            return (object)tmp != null && First.Equals(tmp.First) && Second.Equals(tmp.Second);
        }
    }

    #region HashMap
    public class HashMap<K, V> : Dictionary<K, V>
    {
        public HashMap() : base() { }
        public HashMap(int cap) : base(cap) { }
        public HashMap(IDictionary<K, V> dictionary) : base(dictionary) { }
        new public V this[K i]
        {
            get
            {
                V v;
                return TryGetValue(i, out v) ? v : base[i] = default(V);
            }
            set { base[i] = value; }
        }
    }
    #endregion
}


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

using namespace std;

#define el				'\n'
#define sz(v)			((int)((v).size()))
#define all(v)          ((v).begin()),((v).end())
#define clr(v, d)		memset(v, d, sizeof(v))

double const EPS = 1e-8, PI = acos(-1);
const int N = 1e5 + 9, M = 50 + 9, OO = (int) 1e9 + 1;
const long long MOD = 1e9 + 7;

typedef long long ll;

void OUTPUT() {
	cout << fixed << setprecision(12);
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}

void INPUT() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	cout << fixed << setprecision(12);
//	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}

int n, arr[N], ans[N];
ll cnt;

int main() {
	OUTPUT();
//	INPUT();
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> arr[i];
	}
	for (int i = 1; i <= n; i++) {
		ans[arr[i]] = i;
	}
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << " ";
	}

	return 0;

}


Measured memory_bytes: 1664
#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cassert>
#include<random>
#include<fstream>
#include<chrono>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define int          long long
#define ld           long double
#define pii          pair<int,int>
#define vi           vector<int>
#define pb           push_back
#define mp           make_pair
#define ff           first
#define ss           second
#define rep(i,s,e)   for(int i=(s);i<=(e);i++)
#define brep(i,s,e)  for(int i=(s);i>=(e);i--)
#define all(x)       (x).begin(),(x).end()
#define ball(x)      (x).rbegin(),(x).rend()
#define sz(x)        (int)x.size()
#define mem(x,y)     memset(x,y,sizeof(x))
#define VR46         ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);ifstream fin("ip.txt");ofstream fout("op.txt");
#define milf(x)      x.reserve(1LL<<14LL); x.max_load_factor(0.25); // less_equal
#define pbds         tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
mt19937              rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9+7;
const int INF = 0x3F3F3F3F3F3F3F3F;
ld EPS = 1e-12;

signed main()
{
    VR46 // GANDU TEST CASE BNALE
    // int t;cin>>t;rep(test,1,t)
    {
        string s;
        cin>>s;
        int q;
        cin>>q;
        bool og = true;
        deque<char> S;
        for(auto i:s) S.pb(i);
        rep(qu,1,q)
        {
            int t;
            cin>>t;
            if( t==1 ) og = !og;
            else
            {
                int f;
                char c;
                cin>>f>>c;
                f--;
                if( !og ) f = !f;
                if( !f ) S.push_front(c);
                else S.pb(c);
            }
        }
        string ans = "";
        for(auto i:S) ans += i;
        if( !og ) reverse( all(ans) );
        cout<< ans <<endl;
    }
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

const int N = 100000;

int n;
int a[N];
vector<int> g[N];
LL d[N];

void dfs(int v, int par) {
    if (int(g[v].size()) == 1) {
        d[v] = a[v];
        return;
    }
    LL sum = 0;
    LL mx = 0;
    for (int to : g[v]) if (to != par) {
        dfs(to, v);
        sum += d[to];
        mx = max(mx, d[to]);
    }
    LL can = min(sum - mx, sum / 2);
    LL need = sum - a[v];
    if (need < 0 || need > can || need > a[v]) {
        cout << "NO" << endl;
        exit(0);
    }
    d[v] = a[v] - need;
}

int main() {
    //freopen("input.txt", "r", stdin);
    scanf("%d", &n);
    forn(i, n) scanf("%d", a + i);
    forn(i, n - 1) {
        int from, to;
        scanf("%d%d", &from, &to), --from, --to;
        g[from].pb(to);
        g[to].pb(from);
    }
    if (n == 2) {
        if (a[0] == a[1]) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
        return 0;
    }
    int st = 0;
    forn(i, n) {
        if ((int)g[i].size() > 1) {
            st = i;
            break;
        }
    }
    dfs(st, -1);
    if (d[st] == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 13568
#include <cstdio>

int main() {
    long A,B,C;
    scanf("%ld %ld %ld",&A,&B,&C);
    if (A+B < C) {
        printf("%ld\n",A+B+1+B);
    } else {
        printf("%ld\n",B+C);
    }
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] p = new int[n];
		int count=0;
		
		for(int i=0;i<n;i++) {
			p[i]=sc.nextInt();
		}
		
		for(int i=1;i<n-1;i++) {
			if((p[i]>p[i-1]&&p[i]<p[i+1])||(p[i]<p[i-1]&&p[i]>p[i+1])) {
				count++;
			}
		}
		
		System.out.println(count);
		sc.close();
	}
}


Measured memory_bytes: 25300
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long int S;
  cin >> S;
  
  long long int x=sqrt(S)+1;
 
  if(S>x*(x-1)){
  cout << 0 << " " << 0 << " " << x << " " << 1 
    << " " << x*x-S << " " << x << endl;
  }else if(S==1000000000000000000){
     cout << 0 << " " << 0 << " " << 1000000000 << " " << 0 
    << " " << 0 << " " << 1000000000 << endl;
  }else{
     cout << 0 << " " << 0 << " " << x << " " << 1 
    << " " << x*(x-1)-S << " " << x-1 << endl;
  }
    
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    REP(i, k + 1)REP(j, k - i + 1)REP(l, k - i - j + 1) {
        ans = max(ans, (int)(a * pow(2, i) + b * pow(2, j) + c * pow(2, l)));
    }
    cout << ans << endl;
    
    return 0;
}


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

class Program
{
    static void Main()
    {
		int a =int.Parse(Console.ReadLine());
		int b = 0;
		int c = 0;
		for(int i=1; i<=a; i+=2)
		{
			b = 0;
			for(int j=1; j<=i; j++)
			{
				if(i%j==0) b++;
			}
			if(b==8) c++;
		}
      	Console.WriteLine(c);
    }
}


Measured memory_bytes: 27536
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ld = long double;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMax = 1e12 + 1;
constexpr ll kMod = 1e9 + 7;
constexpr long double kPI = 3.14159265358979323846;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N, M, K;
  cin >> N >> M >> K;

  vll A(N + 1, 0);
  ll asum = 0;
  REP(i, 0, N) {
    ll a;
    cin >> a;
    A[i + 1] = a + asum;
    asum = A[i + 1];
  }
  vll B(M + 1, 0);
  ll bsum = 0;
  REP(i, 0, M) {
    ll b;
    cin >> b;
    B[i + 1] = b + bsum;
    bsum = B[i + 1];
  }

  ll ans = 0, j = M;
  REP(i, 0, N + 1) {
    if (A[i] > K) {
      break;
    }

    while (B[j] > K - A[i]) {
      j--;
    }
    ans = max(ans, i + j);
  }
  cout << ans << endl;
}


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

int lowElemCount(const vector<int> P, const int N);

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

    int N;
    vector<int> P;
    
    cin >> N;
    for (int i = 0; i < N; ++i){
        int x;
        cin >> x;
        P.push_back(x);
    }

    cout << lowElemCount(P, N) << "\n";

    return 0;
}

int lowElemCount(const vector<int> P, const int N)
{
    int co = 1;
    int min_v = P[0];
    for (int i = 1; i < N; ++i){
        if (min_v > P[i]){
            co++;
            min_v = P[i];
        }
    } 
    return co;
}

Measured memory_bytes: 1908
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	deque<char> d;
	int c=0;
	for(int i=0;i<n;++i){
		d.push_back(s[i]);
		if(s[i]=='('){
			++c;
		}
		if(s[i]==')'){
			--c;
			if(c<0){
				d.push_front('(');
				++c;
			}
		}
	}
	if(c>0){
		while(c--){
			d.push_back(')');
		}
	}
	string ss="";
	for(int i=0;i<d.size();++i){
		ss+=d[i];
	}
	cout<<ss<<endl;
	return 0;
}

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


int main() {

	int a, b;
	cin >> a >> b;

	if (a >= 2 * b) cout << a - 2 * b << endl;
	else cout << 0;

}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
struct Point {double x, y;};

double inner(double x1, double y1, double x2, double y2){
    return x1*x2 + y1*y2;
}

double cross(double x1, double y1, double x2, double y2){
    return x1*y2 - y1*x2;
}

double abs(Point x){
    return sqrt(x.x*x.x + x.y*x.y);
}

int main(int argc, char const *argv[])
{
    Point p0, p1, p2;
    Point a, b, x;
    
    int q;
    scanf("%lf %lf %lf %lf", &p1.x, &p1.y, &p2.x, &p2.y);
    a.x = p2.x - p1.x;
    a.y = p2.y - p1.y;

    scanf("%d", &q);
    for(int i=0; i<q; i++){
        scanf("%lf %lf", &p0.x, &p0.y);
        b.x = p0.x - p1.x;
        b.y = p0.y - p1.y;
        if(abs(b)==0){
            printf("%.10lf %.10lf\n", b.x, b.y);
        }
        else{
            double sine = cross(a.x, a.y, b.x, b.y)/(abs(a)*abs(b));
            double cosine = inner(a.x, a.y, b.x, b.y)/(abs(a)*abs(b)); 

            x.x = (2*cosine*cosine-1)*b.x + (2*cosine*sine)*b.y;
            x.y = -(2*cosine*sine)*b.x + (2*cosine*cosine-1)*b.y;
            
            printf("%.10lf %.10lf\n", x.x+p1.x, x.y+p1.y);
        }
    }
    return 0;
}



Measured memory_bytes: 2720
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	int x,y,sx,sy,cost;
};
int main() {

	ll h;
	int n;
	cin>>h>>n;
	ll t=0;
	rep(i,n){
		int a;
		cin>>a;
		t+=a;
	}
	if(t>=h)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	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);
		int n = sc.nextInt();
		int p[] = new int[n];
      	int a = 0;
		//pをn回出力
		for(int i=0; i<n; i++) {
			p[i] = sc.nextInt();
		}
		//真ん中のpが2番目に小さい数であれば、aを１ずつ増やす
		for(int i=1; i<n-1; i++) {
			if((p[i-1]<p[i])&&(p[i]<p[i+1])) {
				a++;
			}else if((p[i-1]>p[i]&&(p[i]>p[i+1]))){
				a++;
			}
		}
		System.out.println(a);
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
const int mo=1000000007;
const int N=100005;
int n,s,ans,a[N];
int power(int x,int y){
	int s=1;
	for (;y;y/=2,x=1ll*x*x%mo)
		if (y&1) s=1ll*s*x%mo;
	return s;
}
int main(){
	scanf("%d",&n);
	For(i,1,n) scanf("%d",&a[i]);
	int s=0;
	For(i,1,n-1){
		s=(s+power(i,mo-2))%mo;
		ans=(ans+1ll*s*(a[i+1]-a[i]))%mo;
	}
	For(i,1,n-1) ans=1ll*ans*i%mo;
	printf("%d\n",ans);
}
/*

*/

Measured memory_bytes: 640
#include <iostream>

using namespace std;
using ll = long long;

const ll MOD = 1e9 + 7;

ll powmod(ll a, ll p, ll mod) {
    ll ret = 1;
    ll mul = a;
    while (p > 0) {
        if (p & 1) ret *= mul;
        mul = mul * mul;
        mul %= mod;
        ret %= mod;
        p >>= 1;
    }
    return ret;
}

ll nCk(ll n, ll k) {
    ll ret = 1;
    for (int i = 0; i < k ;i++) {
        (ret *= n-i) %= MOD;
        (ret *= powmod(i+1, MOD-2, MOD)) %= MOD;
    }
    return ret;
}

signed main() {
    ll N, A, B;
    cin >> N >> A >> B;
    ll ret = powmod(2, N, MOD);
    (ret += MOD - 1) %= MOD;
    (ret += MOD - (nCk(N, A))) %= MOD;
    (ret += MOD - (nCk(N, B))) %= MOD;
    cout << ret << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
#define nl '\n'

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

const int N=2e5+11;
const int M=2e6+11;
const int W=1e3+11;
const int inf=1e9;
const ll INF=1e18;
const ll mod=1e9+7;
const ld EPS=1e-9;

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0),cout.tie(0);
  ll n;
  cin>>n;
  ll ans=(n/500)*1000;
  n%=500;
  ans+=(n/5)*5;
  cout<<ans;
}


Measured memory_bytes: 256
from collections import defaultdict, Counter
def inpl(): return list(map(int, input().split()))

N, M = inpl()
X = sorted(inpl())
C = Counter(X)
D = defaultdict(int)
E = defaultdict(int)
for k, v in C.items():
    D[k%M] += v
    E[k%M] += v//2

ans = D[0] // 2

for i in range(1, M):
    j = M - i
    if i < j:
        x = min(D[i], D[j])
        y = min((D[i] - x)//2, E[i]) + min((D[j] - x)//2, E[j])
        ans += x + y
    elif i == j:
        ans += D[i] //2
    else:
        break

print(ans)

Measured memory_bytes: 36044
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define all(x) x.begin(), x.end()
const ll inf = 1e18;
const ll mod = 1e9 + 7;

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

int main(){
    int n;
    cin >> n;
    vint fib(n+1, 1);
    for(int i=2; i<n+1; i++){
        fib[i] = fib[i-1] + fib[i-2];
    }
    cout << fib[n] << endl;
}



Measured memory_bytes: 3084
#a = int(input())
#b,c = map(int,input().split())
#s = input()
#list_s = list(input())
#list_int = list(map(int,input().split()))

#list = [0 for i in range(n)]
#dp = [[0 for i in range(A)] for j in range(B)]

#list_int 並べて出力 print (' '.join(map(str,ans_li)))
#list_str 並べて出力 print (' '.join(list))

# 2進数 format(10, 'b') # '1010'

# aa=[int(input()) for i in range(n)]

#for i,name in enumerate(list)

''' 二次元配列を一列ずつ
for i in ans:
	print(*i)
'''
''' heapq
queue = []
heapq.heapify(queue) #heapqの作成
heapq.heappush(queue,num) #numのpush(値の追加)
pop = heapq.heappop(queue) #numのpop(最小値の出力)
pop = heapq.heappushpop(queue,num) #push -> pop

'''

from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7

#最大公約数
def gcd(a,b):
	while b:
		a,b = b, a%b
	return a

#最小公倍数
def lcm(a,b):
	return a*b // gcd(a,b)

N = int(input())
aa = list_int = list(map(int,input().split()))

mod = 1

for i in range(N):
	mod = lcm(aa[i],mod)

mod -= 1
ans = 0
for i in range(N):
	ans += mod%aa[i]

print(ans)


Measured memory_bytes: 3960
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		
		int[] box = new int[n];
		int Max=0,Min=0;
		for(int i=0;i<n;i++) {
		int t = sc.nextInt();
			box[i] = t;
		}
		
		int q = sc.nextInt();
		for(int i=0;i<q;i++) {
			int com = sc.nextInt();
			int b=0,e=0;
			
			switch(com) {
			
			case 0:
				b = sc.nextInt();
				e = sc.nextInt();
				
				Min = box[b];
				for(int j=b;j<e;j++) {
					
					if(Min > box[j]) Min = box[j];
				}
				
				System.out.println(Min);
				break;
				
			
			case 1:
				b = sc.nextInt();
				e = sc.nextInt();
				
				Max = box[b];
				for(int j=b;j<e;j++) {
					
					if(Max < box[j]) Max = box[j];
				}
				
				System.out.println(Max);
				break;
			}
		}
		
		
	}
}


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());

signed main()
{   
    gearup;
    string s,t; cin >> s >> t;
    ll res = 0;
    rep(i,s.size()){
        if(s[i] != t[i])res++;
    }
    out(res);
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

const double eps=1e-10;

int main()
{
    int n,m,L;
    scanf(" %d %d %d", &n, &m, &L);
    vector<int> p(n),t(n),v(n);
    rep(i,n) scanf(" %d %d %d", &p[i], &t[i], &v[i]);

    // i???????????????j???????????????????¢???????????????¨?????????????????????
    double rest[100][51];
    double total[100][51];

    double dp[51][51];
    rep(i,n)
    {
        memset(dp,0,sizeof(dp));
        dp[0][0]=1;
        rep(j,m)rep(k,j+1)
        {
            dp[j+1][k]+=dp[j][k]*(100-p[i])/100;
            dp[j+1][k+1]+=dp[j][k]*p[i]/100;
        }

        rep(j,m+1)
        {
            rest[i][j]=dp[m][j];
            total[i][j]=(double)L/v[i]+j*t[i];
        }
    }

    double win[100]={0};

    // i???????????????j??????????????????????????????????¢????
    rep(i,n)rep(j,m+1)
    {
        double add=1;
        double mytime=total[i][j];

        rep(k,n)
        {
            if(k==i) continue;

            if(mytime>=total[k][m])
            {
                add=0;
                break;
            }

            int idx=0;
            while(idx<m && mytime>=total[k][idx]) ++idx;

            double q=0;
            for(int l=idx; l<=m; ++l) q+=rest[k][l];

            add*=q;
        }

        win[i]+=add*rest[i][j];
    }

    rep(i,n) printf("%.10f\n", win[i]);
    return 0;
}

Measured memory_bytes: 3340
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int main(){
  int N;
  cin >> N;
  double sum;
  for (int i=0;i<N;i++){
    double a;
    cin >> a;
    sum += 1.0/a;
  }
  cout << fixed << setprecision(6) << 1.0/sum << endl;

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int main(){
  long long int n, m;
  cin >> n >> m;
  vector<pair<long long int, long long int> > pairs(n);
  long long int ans=0;
  for(int i=0;i<n;i++){
    long long int tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    pairs[i]=make_pair(tmp1, tmp2);
  }
  sort(pairs.begin(), pairs.end());
  for(int i=0;i<n;i++){
    if(m>=pairs[i].second){
      ans+=pairs[i].second*pairs[i].first;
      m-=pairs[i].second;
    }
    else{
      ans+=m*pairs[i].first;
      m=0;
    }
    if(m==0)break;
  }
  cout << ans << endl;
  return 0;
}


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

const int MAX_N=1005;
int n;
int a[MAX_N];

int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	int Sum=0;
	for(int i=0;i<n;++i)
	{
		cin>>a[i];
		Sum+=a[i];
	}
	int ans=0,ss=Sum;
	for(int i=0;i<n;++i)
	{
		if(abs(a[i]*n-Sum)<ss){
			ss=abs(a[i]*n-Sum);	ans=i;
		}
	}
	cout<<ans<<endl;
	
	return 0;
}

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

const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	
	
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n; cin >> n;
	ll ans=0;
	
	ll h[n][3]; rep(i,n) rep(j,3) cin >> h[i][j];
	ll dp[n][3]={};
	
	rep(i,3) dp[0][i]=h[0][i];
	
	rep(i,n-1){
		rep(j,3){ //fix
			
			rep(k,3){
				if(j!=k) chmax(dp[i+1][j],dp[i][k]+h[i+1][j]);
			}
		}
	}
	
	
	rep(i,3) chmax(ans,dp[n-1][i]);
	
	cout << ans << "\n";
	
	return 0;
}


//vector<int> a(n);  sort(a.begin(),a.end());
//cout << "test" << "\n";


//g++ -o a a.cpp


Measured memory_bytes: 4992
#include<iostream>
using namespace std;
int main(){
int n,i,j;
  cin >> n;
  for(i=1;i<=9;i++){
    for(j=1;j<=9;j++){
      if(i*j==n){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
} 

Measured memory_bytes: 3544
import sys
import math
import copy
import queue
input = sys.stdin.readline
def LI(): return [int(x) for x in input().split()]

n = int(input())

def x(s,m,d):
    if d >= n:
        ans = ''
        for i in range(n):
            ans += chr(ord('a') + s[i])
        print (ans)
        return
    for i in range(m+1):
        ss = s + [i]
        m = max(m,i+1)
        x(ss,m,d+1)

x([0],1,1)


Measured memory_bytes: 57944
/* ITP1_8_B */
import java.io.*;

class Main
{
  public static void main(String[] args)
  {
    try{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringBuilder sb = new StringBuilder();

      while(true){
        String str = br.readLine();
        char[] input = str.toCharArray();
        if(input[0] == '0') break;

        int sum = 0;
        for(int i = 0; i < input.length; i++){
          sum += Character.getNumericValue(input[i]);
        }
        sb.append(sum).append("\n");
      }
      System.out.print(sb);

    }catch(Exception e){
      System.out.println(e);
    }
  }
}

Measured memory_bytes: 24224
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    int a, b, c; cin >> a >> b>> c;

    if(c<=a+b) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    string s; cin>>s;
    if(s[0]<'a') cout<<"A";
    else cout<<"a";
}



Measured memory_bytes: 3616
A=list([int(input()) for i in range(5)])
ans=0
cnt=0
B=[]
for i in range(5):
    if A[i]%10!=0:
        B.append(A[i]%10)
for i in range(5):
    if A[i]%10==0:
        ans+=A[i]
    else:
        ans+=(A[i]//10+1)*10
        if A[i]%10==min(B) and cnt==0:
            ans-=(10-A[i]%10)
            cnt+=1
print(ans)


Measured memory_bytes: 3064
//皆さん、第9回シンデレラガール総選挙は、トップでオンリーワンを目指す城ヶ崎美嘉に
//そしてボイスアイドルオーディションは、プログラミングが趣味の才女大石泉に、ぜひ投票をお願いします！
//#城ヶ崎美嘉を009のシンデレラに
//#大石泉の必勝プログラム
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int h[100100],num[100100];
int main()
{
	int n,m,a,b,out=0;
	cin>>n>>m;rep(i,n+10) num[i]=1;
	rep(i,n) cin>>h[i];
	rep(i,m){
		cin>>a>>b;a--;b--;
		if(h[a]<=h[b]) num[a]=0;
		if(h[b]<=h[a]) num[b]=0;
	}
	rep(i,n) out+=num[i];
	cout<<out<<endl;
}


Measured memory_bytes: 4412
#include <bits/stdc++.h>
using namespace std;
const int INF=2000000000;

int cnt;

void merge(int *A,int l,int mid,int r){
    int n1=mid-l;
    int n2=r-mid;
    int left[n1+1],right[n2+1];
    for(int i=0;i<n1;i++) left[i]=A[l+i];
    for(int i=0;i<n2;i++) right[i]=A[mid +i];
    left[n1]=INF;
    right[n2]=INF;
    int i=0,j=0;
    for(int k=l;k<r;k++){
        cnt++;
        if(left[i]<=right[j]) A[k]=left[i++];
        else A[k]=right[j++];
    }
}

void mergesort(int *A,int l,int r){
    if(l+1<r){
        int mid=(l+r)/2;
        mergesort(A,l,mid);
        mergesort(A,mid,r);
        merge(A,l,mid,r);
    }
}

int main()
{
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//	#endif
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    mergesort(a,0,n);
    for(int i=0;i<n;i++){
        cout<<a[i];
        if(i!=n-1)cout<<' ';
        else cout<<endl;
    }
    cout<<cnt<<endl;
}



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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;

int main(){
  int r; cin>>r;
  cout<<3*r*r<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<string> c(3);
  for(int i=0;i<3;i++){
    cin >>c.at(i);
  }
  
  cout<<c.at(0).at(0)<<c.at(1).at(1)<<c.at(2).at(2)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 nn;
	cin >> nn;
	if(nn % 2)
	{
		nn /= 2;
		nn++;
	}
	else
	{
		nn /= 2;
	}
	cout << nn << endl;
	return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll n;
  cin >> n;
  ll ans = n / 3;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * (n + 1)
for i in range(1, n + 1):
    b[i] = b[i - 1] + a[i - 1]
for i in range(n + 1):
    b[i] -= i
    b[i] %= k
d = dict()
for i in range(min(n + 1, k)):
    if b[i] in d:
        d[b[i]] += 1
    else:
        d[b[i]] = 1
ans = []
j = min(n + 1, k)
for i in range(n):
    ans.append(d[b[i]])
    d[b[i]] -= 1
    if j <= n:
        if b[j] in d:
            d[b[j]] += 1
        else:
            d[b[j]] = 1
    j += 1
ans = sum(ans) - n
print(ans)

Measured memory_bytes: 117316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
const int mod = 998244353;
int T, n, cnt[maxn];
void init() {
    int num = 0;
    for(int i = 1; i <= 200; i++) {
        int m = sqrt(i + 0.5);
        int div = 2;
        for(int j = 2; j <= m; ++j) {
            if(i % j == 0) {
                if(i/j == j) div++;
                else div += 2;
            }
        }
        if(div == 8 && (i & 1)) num++;
        cnt[i] = num;
    }
}
int main() {
    init();
    cin >> n;
    cout << cnt[n] << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

const int My_Inf=2147483647;
const long long int My_LInf=9223372036854775807;
//左辺に底　右辺に真数
long double mlog(const long double base, const long double anti) {
	return log(anti) / log(base);
}
int main() {
	int N; cin >> N;
	int a = mlog(3, N) - 1e-4;
	cout << a + 1 << endl;
	return 0;
}

Measured memory_bytes: 3232