akhauriyash/Code-Regression huggingface dataset:
import fractions
n=int(input())
a=[int(i) for i in input().split()]

class SegmentTree:
    # 初期化処理
    # f : SegmentTreeにのせるモノイド
    # default : fに対する単位元
    def __init__(self, size, f=lambda x,y : fractions.gcd(x,y), default=0):
        self.size = 2**(size-1).bit_length() # 簡単のため要素数Nを2冪にする
        self.default = default
        self.dat = [default]*(self.size*2) # 要素を単位元で初期化
        self.f = f

    def update(self, i, x):
        i += self.size
        self.dat[i] = x
        while i > 0:
            i >>= 1
            self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])

    def query(self, l, r):
        l += self.size
        r += self.size
        lres, rres = self.default, self.default
        while l < r:
            if l & 1:
                lres = self.f(lres, self.dat[l])
                l += 1

            if r & 1:
                r -= 1
                rres = self.f(self.dat[r], rres) # モノイドでは可換律は保証されていないので演算の方向に注意
            l >>= 1
            r >>= 1
        res = self.f(lres, rres)
        return res
    
tree = SegmentTree(n)
for i in range(n):
    tree.update(i,a[i])

max_=tree.query(1,n)
for i in range(1,n-1):
    max_=max(max_,fractions.gcd(tree.query(0,i),tree.query(i+1,n)))
max_=max(max_,tree.query(0,n-1))
print(max_)

Measured memory_bytes: 100072
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main()
{
	double a, b, c;
	double s, l, h;
	cin >> a >> b >> c;
	s = a * b * sin(c * M_PI / 180.0) / 2.0;
	l = a + b + sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * cos(c * M_PI / 180.0));
	h = s / a * 2;
	cout << fixed << setprecision(5) << s << endl;
	cout << fixed << setprecision(5) << l << endl;
	cout << fixed << setprecision(5) << h << endl;
}


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

int main() {
    int S, h, m, s;
    cin >> S;
    h = S/3600;
    m = (S-h*3600)/60;
    s = (S-h*3600-m*60);

    cout << h << ":" << m <<":" << s << endl;

    return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
using namespace std;

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

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n,m;
	cin >> n >> m;
	vector<int> p(n);
	rep(i,0,n)p[i] = i;
	int g[n][n] = {};
	rep(i,0,m){
		int x,y;
		cin >> x >> y;
		--x,--y;
		g[x][y] = g[y][x] = 1;
	}
	int cnt = 0;
	do {
		bool valid = p[0] == 0;	
		rep(i,0,n-1){
			valid &= g[p[i]][p[i+1]];
		}
		cnt += valid;
	} while(next_permutation(all(p)));
	cout << cnt << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
string s;
ll p[200005],ss[200005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n>>s;
    while(sz(s) and s.back()=='#')
        s.pop_back();
    reverse(all(s));
    while(sz(s) and s.back()=='.')
        s.pop_back();
    reverse(all(s));
    vector<pll>v;
    for(ll i=0;i<sz(s);)
    {
        ll j=i;
        while(j<sz(s) and s[j]==s[i])
            j++;
        if(sz(v) and v.back().S==0)
            v.back().S=(j-i);
        else
            v.pb({j-i,0});
        i=j;
    }
    if(sz(v)==0)
    {
        cout<<0;
        return 0;
    }
    rep(i,0,sz(v))
        p[i]=(i?p[i-1]:0)+v[i].F;
    sep(i,sz(v)-1,0)
        ss[i]=ss[i+1]+v[i].S;
    ll ans=min(p[sz(v)-1],ss[0]);
    rep(i,0,sz(v)-1)
        ans=min(ans,p[i]+ss[i+1]);
    cout<<ans;
}


Measured memory_bytes: 4232
#include <stdio.h>

int main(void) {
	int H, W, i, j;
	
	while(1){
		scanf("%d %d", &H, &W);
		
		if(H==0 && W==0)
		break;
		
		for(j=1;j<=H;j++){
			
		if(j%2==1){
		 for(i=1;i<=W;i++){
		 if(i%2==1)
		 printf("#");
		 
		 else
		 printf(".");
		 }
		 putchar('\n');
		}
		
		else{
			for(i=1;i<=W;i++){
		 if(i%2==1)
		 printf(".");
		 
		 else
		 printf("#");
		 }
		 putchar('\n');
		}
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 576
H,W=map(int,input().split())
a=[list(map(int,input().split()))for i in range(H)]
l=[]
for i in range(H):
  for j in range(W):
    if a[i][j]%2:
      if i+1<H:
        a[i][j]-=1
        a[i+1][j]+=1
        l.append((i+1,j+1,i+2,j+1))
      elif j+1<W:
        a[i][j]-=1
        a[i][j+1]+=1
        l.append((i+1,j+1,i+1,j+2))
print(len(l))
for i in l:
  print(*i)

Measured memory_bytes: 30504
#include <iostream>
#include <algorithm>
using namespace std;
 
int main()
{
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if ((e - a) > k) 
        cout << ":(" << endl;
    else
    {
        cout << "Yay!" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <cassert>
#include <time.h>

#define mst(a,b)memset(a, b, sizeof(a))
#define repi(a,b)for(int i = a; i < b; i++)
#define repj(a,b)for(int j = a; j < b; j++)
#define pii pair<int,int>
#define print_time()cout<<clock()/CLOCKS_PER_SEC<<" s"<<endl;

#ifdef LOCAL
#define fre()freopen("in.txt","r",stdin)
#endif
#ifndef LOCAL
#define fre()
#endif

//static int x = []() {
//  std::ios::sync_with_stdio(false);
//  std::cin.tie(NULL);
//  return 0;
//}();

#define FASTIO
#ifdef FASTIO
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
//#define scanf abcabc
//#define printf abcabc
#endif
//#ifndef FASTIO
//#define cin abcabc
//#define cout abcabc
//#endif

typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;

using namespace std;


int a[100010];
int main() {
	IOS;
	int n; cin >> n;
	repi(0, n)cin >> a[i];
	for (int i = n - 1; i > 0; i--) {
		if (a[i] >= a[i - 1])continue;
		if (a[i - 1] - a[i] == 1)a[i - 1]--;
		else {
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;

int main(){
  int N, M;cin>>N>>M;
  vi G[N];
  int used[N];
  memset(used, 0, sizeof(used));
  
  for (int i=0;i<M;++i){
    int a, b;cin >>a>>b;
    G[a-1].push_back(b-1);G[b-1].push_back(a-1);
  }

  int cnt=0;
  vi path;
  path.push_back(0);
  used[0]=1;
  int pos=0;

  while(cnt<M){
    int j=0;
    while(used[G[pos][j]]==1&&j<G[pos].size()){j++;}
    int ps=G[pos].size();
    if(j==ps) break;
    int v=G[pos][j];
    path.push_back(v);
    used[v]=1;
    pos=v;
    cnt++;
  }
cnt=0;
  vi path2;
  pos=0;
  while(cnt<M){
    int j=0;
    while(used[G[pos][j]]==1&&j<G[pos].size()){j++;}
    int ps=G[pos].size();
    if(j==ps) break;
    int v=G[pos][j];
    path2.push_back(v);
    used[v]=1;
    pos=v;
    cnt++;
  }

  reverse(path2.begin(), path2.end());

  int L=path2.size();

  path.insert(path.begin(), path2.begin(), path2.end());
  

  int K=path.size();
  cout << K << endl;
  for (int i=0;i<K;++i){
    int v=path[i];
    cout << v+1 << ' ';
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 7160
#include <bits/stdc++.h>
 
using namespace std;
 
#define f0r(a, b) for (long long a = 0; a < (b); a++)
#define f1r(a, b, c) for (long long a = (b); a < (c); a++)
#define f0rd(a, b) for (long long a = (b); a >= 0; a--)
#define f1rd(a, b, c) for (long long a = (b); a >= (c); a--)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define pb push_back
#define mp make_pair
#define f first
#define s second
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vpl = vector<pll>;
 
void fio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); 
  cout.tie(0);
}
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const long double pi = 3.14159265358979323846;

using ld = long double;

void solve() {
  ll a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;

  bool dp[f + 1][f + 1];
  ms(dp, 0);
  dp[0][0] = 1;

  pll ans = mp(0, 0);
  f0r(i, f + 1) {
    f0r(j, f + 1) {
      if (dp[i][j]) {
        ll ni, nj;

        ni = i + 100 * a, nj = j;
        if (ni <= f && nj <= f) dp[ni][nj] = 1;

        ni = i + 100 * b, nj = j;
        if (ni <= f && nj <= f) dp[ni][nj] = 1;

        ni = i, nj = j + c;
        if (ni <= f && nj <= f) dp[ni][nj] = 1;

        ni = i, nj = j + d;
        if (ni <= f && nj <= f) dp[ni][nj] = 1;

        if (i + j <= f && i * e >= 100 * j) {
          if (j * (ans.f + ans.s) >= (i + j) * ans.s) ans = mp(i, j);
        }
      }
    }
  }

  cout << ans.f + ans.s << " " << ans.s << '\n';
}
 
int main() {
  fio();
  
  int T = 1;
  // cin >> T;
  while (T--) solve();
} 

Measured memory_bytes: 11580
while True:
    n,k = map(int,input().split(" "))
    if n == 0 and k == 0:
        break
    else:
        nums = [int(input()) for _ in range(n)]
        ruiseki = [0] * (n + 1)
        for i,num in enumerate(nums):
            ruiseki[i + 1] = ruiseki[i]  + num
        # print(ruiseki)
        ans = - (10 ** 15)
        for left in range(n - k):
            ans = max(ans, ruiseki[left + k] - ruiseki[left])
        print(ans)




Measured memory_bytes: 13420
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#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
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
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<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}

int n,k;
vpi v;

signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);


   cin >> n >> k;
   if( k> ( ((n-1)*(n-2))/2 ) ){
      cout << -1 << endl;
      return 0;
   }

   for(int i=1;i<=n-1;i++){
      for( int j=i+1;j<=n-1;j++ ){
         v.pb( {i,j} );
      }
   }

   int req = (int)v.size() - k;

   cout << n-1 + req << endl;

   for(int i=1;i<=n-1;i++){
      cout << n << " " << i << endl;
   }



   for(auto t:v){
      if(req>0){
         cout << t.fs << " " << t.sc << endl;
         req--;
      }
   }


return 0;
}

///....



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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



int n, m, a[1010][1010];
void solve(){
	cin >> n >> m;
	int cnt = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			cin >> a[i][j];
			cnt += a[i][j];
			cnt %= 2;
		}
	}
	
	vector<int> b,c,d,e;
	int j = 0;
	for(int i = 0; i < n; i++){
		if(i & 1){
			for(; j > 0; j--){
				if(a[i][j] & 1){
					b.push_back(i+1);
					c.push_back(j+1);
					d.push_back(i+1);
					e.push_back(j);
					a[i][j-1]++;
				}
			}
			if(i != n-1 && a[i][j] & 1){
				b.push_back(i+1);
				c.push_back(j+1);
				d.push_back(i+2);
				e.push_back(j+1);
				a[i+1][j]++;
			}
		}
		else{
			for(; j < m-1; j++){
				if(a[i][j] & 1){
					b.push_back(i+1);
					c.push_back(j+1);
					d.push_back(i+1);
					e.push_back(j+2);
					a[i][j+1]++;
				}
			}
			if(i != n-1 && a[i][j] & 1){
				b.push_back(i+1);
				c.push_back(j+1);
				d.push_back(i+2);
				e.push_back(j+1);
				a[i+1][j]++;
			}
		}
	}
	
	cout << b.size() << endl;
	for(int i = 0; i < b.size(); i++){
		cout << b[i] << " " << c[i] << " " << d[i] << " " << e[i] << endl;
	}
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 6244
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
 */
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);
        HSI solver = new HSI();
        solver.solve(1, in, out);
        out.close();
    }

    static class HSI {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();

            long ans = (1900 * m + 100 * (n - m)) * (long) Math.pow(2, m);
            out.println(ans);

        }

    }
}



Measured memory_bytes: 35832
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    long long N,K;
    long long R,ans;
    cin >> N >> K;
    
    R = N/K;
    
    
   // cout << N - R * K << endl;
//    cout << abs((N - R*K) - K) << endl;
    ans = min ( N-R*K , abs((N - R*K) - K));
    cout << ans << endl;
    
    
}


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

using namespace std;

int main(){
  long n;
  cin >> n;
  
  long res=0;
  
  for(long r=1;r<=sqrt((double)n);r++){
   if(n%r==0){
     long m;
     m=n/r-1;
     
     if(m>r){
       res+=m;
     }
   
   }
  
  }
  
  
 cout << res <<endl;

}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

MOD = 10**9+7

n = int(input())
a = list(map(int, input().split()))

rgb = [0, 0, 0]

ans = 1
for i in range(n):
    ans *= rgb.count(a[i])
    ans %= MOD
    # print(rgb, a[i], ans)
    for j in range(3):
        if rgb[j] == a[i]:
            rgb[j] += 1
            break
print(ans)


Measured memory_bytes: 19172
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

int f(int a){
	if(a==1)return 1;
	return 2*f(a/2)+1;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,m;
	cin>>n>>m;
	vi dp(n+1,inf);
	dp[n]=0;
	rep(i,m){
		int a,b;
		cin>>a>>b;
		for(int j=n;j>=0;j--)
			cmin(dp[max(0ll,j-a)],dp[j]+b);
	}
	cout<<dp[0]<<endl;
	
	
/*	int a;cin>>a;
	cout<<f(a)<<endl;
	*/
}









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

int main() {
    int h;
    cin >> h;
    int w;
    cin >> w;
    vector<string> a(h);
    for (int i = 0; i < h; i++) {
        cin >> a[i];
    }

    vector<bool> row(h, false);
    vector<bool> col(w, false);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (a[i][j] == '#') {
                row[i] = true;
                col[j] = true;
            }
        }
    }
    for (int i = 0; i < h; i++){
        if (row[i]){
            for(int j = 0; j < w; j++){
                if (col[j])
                    cout << a[i][j];
            }
            cout << endl;
        }
    }
}


Measured memory_bytes: 256
// 　　＿＿
// 　／　<＠ﾌ
//  ｜(ﾉﾉハ))
//  ﾉ从ﾟヮﾟ从
// 　ﾉ｜ｿﾉГ|つ author:hotarunx
// 〈_ﾉ^^^ヽ|
// 　~~tｧtｧ~
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

    int n;
    cin >> n;
    vector<int> a(3*n);
    for (int i = 0; i < 3 * n; i++) cin >> a[i];
    sort(a.rbegin(), a.rend());

    int ans = 0;

    for (int i = 0; i < n; i++) {
        ans += a[2 * i + 1];
    }

    cout << ans << endl;
}


Measured memory_bytes: 5584
N=int(input())

d=[]
out=[]
for i in range(N):
    num=int(input())
    d.append(num)

d.sort()

for i in range(N):
    if i!=0:
        if d[i-1]!=d[i]:
            num=d[i]
            out.append(num)
    else:
        out.append(d[0])

print(len(out))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
using namespace std;
typedef long long ll;


int main() {
    int N; cin >> N;
    int ans = 0;
    for(int i=0; i<N; i++){
        int a; cin >> a;
        ans += a-1;
    }
    cout << ans << endl;
    return 0;
}





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

namespace AtCoder.Abc
{
    class QuestionE
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            string n = Console.ReadLine();
            int k = int.Parse(Console.ReadLine());
            int first = int.Parse(n.Substring(0,1));

            long result = 0;

            if (n.Length < k)
            {
                result = 0;
            }
            else
            {
                result = Test(n, k);
            }

            Console.WriteLine(result);

            Console.Out.Flush();
        }

        public static long Test(string n, int k)
        {
            if(n.Length == 0)
            {
                return 0;
            }
            int first = int.Parse(n.Substring(0, 1));
            if (n.StartsWith("0"))
            {
                //0始まりは、無視する
                return Test(n.Substring(1), k);
            }
            if (n.Length < k)
            {
                return 0;
            }

            long result = 0;

            if (k == 1)
            {
                //最上位以外は1～9の9個が該当する
                //最上位だけ、1～{first-1}個が該当
                result = 9 * (n.Length - 1);
                result += first;
            }
            else
            {
                //sの最大桁数を使わない場合
                //残りのs.Length - 1からk箇所とって、k^10 -1をかければいい

                result = nCr(n.Length - 1, k) * (long)(Math.Pow(9, k));

                //sの最大桁数を使う場合

                //最大桁数が最大値でないなら、残りのs.Length -1 からk-1箇所取って、(k-1)^10-1をかければいい
                result += (first - 1) * nCr(n.Length - 1, k-1) * (long)(Math.Pow(9, k-1));

                //最大桁数が最大値の場合、再起で求める
                result += Test(n.Substring(1), k - 1);
            }

            //Program.Debug.Log($"Test({n},{k}) -> {result}");
            return result;
        }


        public static long nCr(int n, int r)
        {
            // naive: return Factorial(n) / (Factorial(r) * Factorial(n - r));
            return nPr(n, r) / Factorial(r);
        }

        public static long nPr(int n, int r)
        {
            // naive: return Factorial(n) / Factorial(n - r);
            return FactorialDivision(n, n - r);
        }

        private static long FactorialDivision(int topFactorial, int divisorFactorial)
        {
            long result = 1;
            for (int i = topFactorial; i > divisorFactorial; i--)
                result *= i;
            return result;
        }

        private static long Factorial(int i)
        {
            if (i <= 1)
                return 1;
            return i * Factorial(i - 1);
        }
    }
}


Measured memory_bytes: 13404
#include <string.h>

#include <algorithm>
#include <cstdlib>  // abs() for integer
#include <iostream>

using namespace std;

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

  if (X >= 30) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3632
N = int(input())
P = list(map(int, input().split()))

counter = 0

for i in range(1,N-1):
#    print(i)
    p1 = P[i-1]
    p2 = P[i]
    p3 = P[i+1]

    if p1 < p2 and p2 < p3:
        counter += 1
    elif p3 < p2 and p2 < p1:
        counter += 1
    
print(counter)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	vector<int> v(n);
	for(int&x:v) scanf("%d",&x);
	vector<int> dp(n+1);
	dp[1] = abs(v[0]-v[1]);
	for(int i = 2; i < n; i++)
		dp[i] = min(dp[i-1]+abs(v[i]-v[i-1]), dp[i-2]+abs(v[i]-v[i-2]));
	printf("%d\n", dp[n-1]);
	return 0;
}

Measured memory_bytes: 4084
#include <iostream>
using namespace std;
int main(){
    char mark[] = "#.";
    int t, H, W;
    while(1){
        cin >> H >> W;
        if(H == 0 && W == 0){
            break;
        }
        for(int i = 0; i < H; i++){
            t = i % 2;
            for(int j = 0; j < W; j++){
                cout << mark[t];
                 t = (t+1) % 2;
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
#include<bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std;
#define ll long long
#define ld long double
#define mp(x,y) make_pair(x,y)
const int nax=1e6+5;
ld pie=3.141592653589793238;

void solve(){
    int n,m;
    cin>>n>>m;
    vector<int> v[n];
    for(int i=0;i<m;i++){
        int x,y; cin>>x>>y;x--; y--;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    int vis[n]={0};
    queue<int> q;
    vis[0]=1;
    q.push(0);
    int p[n];
    while(q.size() > 0){
        int ci=q.front();
        q.pop();
        vis[ci]=1;
        for(auto  x: v[ci]){
            if(vis[x]==1) continue;
            p[x]=ci;
            q.push(x);
            vis[x]=1;
        }
    }
    cout<<"Yes\n";
    for(int i=1;i<n;i++){
        cout<<p[i]+1<<'\n';
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int tc;
    tc=1;
    cout<<fixed<<setprecision(20);
    while(tc--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 10928
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define PB push_back
#define PI 3.14159265358979323846
using namespace std;
typedef pair<int, int> P1;
typedef pair<int, pair<int, int> > P2;
static const int INF = 1ll<<60;
static const int dx[] = { 1, -1, 0, 0, };
static const int dy[] = { 0, 0, 1, -1 };

int X,Y,Z;
int A[100005],B[100005],C[100005];
vector<P1> AB;
int N;
int sum_x,sum_y,sum_z;

priority_queue< P1,vector<P1>,greater<P1> > Left;
priority_queue< P1,vector<P1>,greater<P1> > Right;
int dp_x[100005],dp_y[100005],dp_z[100005];


void solve(){
    for(int i=0;i<N;++i)dp_x[i]=dp_y[i]=-INF;
    //左側
    for(int i=0;i<N;++i){
        int it = AB[i].second;
        sum_y+=(B[it]-C[it]);
        Left.push(P1(B[it]-C[it],it));
        if(Left.size()>Y){
            sum_y-=Left.top().first;
            Left.pop();
        }
        if(Left.size()==Y){
            dp_y[i]=sum_y;
        }
    }

    //右側 ※逆からやる
    for(int i=N-1;i>=0;--i){
        int it = AB[i].second;
        sum_x+=(A[it]-C[it]);
        Right.push(P1(A[it]-C[it],it));
        if(Right.size()>X){
            sum_x-=Right.top().first;
            Right.pop();
        }
        if(Right.size()==X){
            dp_x[i]=sum_x;
        }
    }
}

signed main(){
    cin>>X>>Y>>Z;
    N = X+Y+Z;
    for(int i=0;i<N;++i){
        cin>>A[i]>>B[i]>>C[i];
        AB.PB(P1(A[i]-B[i],i));
        sum_z+=C[i];
    }
    sort(AB.begin(),AB.end());
    solve();
    int ans=-INF;
    int p;
    for(int i=1;i<N;++i){
        ans=max(ans,dp_x[i]+dp_y[i-1]+sum_z);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 9200
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;
int main(){ 
   int n;
   cin>>n;
   cout<<n/2+n%2;
   return 0;
}

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

int main() {
    int N, K;  cin >> N >> K;
    vector<int> v(N);
    for (int i = 0; i < K; ++i) {
        int d;  cin >> d;
        for (int j = 0; j < d; ++j) {
            int a;  cin >> a;
            v[a - 1] = 1;
        }
    }
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        if (!v[i]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		int h, m, s;
		h = S / 3600;
		S%=3600;
		m=S/60;
		S%=60;
		s=S;
		System.out.println(h + ":" + m + ":" + s);
		
	}

}

Measured memory_bytes: 26260
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,W,b,c=0;
scanf("%d%d%d",&W,&a,&b);
if(b>(a+W)){
c=b-(a+W);	
printf("%d",c);
}
else if(a>(W+b)){
c=a-(W+b);
printf("%d",c);
}	
else 
printf("%d",c);
}

Measured memory_bytes: 256
#入力
A, B = map(int, input().split())
#rに+,-,*を代入
r = [0,0,0]
r[0] = A + B
r[1] = A - B
r[2] = A * B

#rをソートして最大の要素(r_0)を返す
r.sort()
print(r[2])

Measured memory_bytes: 3060
const val P = 998244353L

fun mod(x: Long) = if (x >= 0) x % P else (P - ((-x) % P)) % P
fun modPlus(x1: Long, x2: Long) = (x1 + x2) % P
fun modMinus(x1: Long, x2: Long) = (x1 + P - x2) % P

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val xs = IntArray(n, { readLine()!!.toInt() })
  val s = xs.sum()

  val count3 = LongArray(s + 1)
  count3[0] = 1
  for (i in 0 until n) {
    for (k in s downTo 0) {
      if (count3[k] == 0L) continue
      count3[k + xs[i]] = modPlus(count3[k + xs[i]], count3[k])
      count3[k] = modPlus(count3[k], count3[k])
    }
  }

  val count2 = LongArray(s + 1)
  count2[0] = 1
  for (i in 0 until n) {
    for (k in s downTo 0) {
      if (count2[k] == 0L) continue
      count2[k + xs[i]] = modPlus(count2[k + xs[i]], count2[k])
      count2[k] = count2[k]
    }
  }

  var remove = 0L
  remove = modPlus(remove, 3L * pow2(n) % P)
  for (k in 0..s) {
    if (k >= (s + 1) / 2) {
      remove = modPlus(remove, 3L * count3[k] % P)
    }
  }
  for (k in 0..s) {
    if (k >= (s + 1) / 2) {
      remove = modMinus(remove, 6L * count2[k] % P)
    }
  }

  val total = pow3(n)
  val ans = modMinus(total, remove)
  println(ans)
}

fun pow2(n : Int): Long {
  if (n == 0) return 1L
  val x = pow2(n - 1)
  return 2 * x % P
}

fun pow3(n: Int): Long {
  if (n == 0) return 1L
  val x = pow3(n - 1)
  return 3 * x % P
}

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

#define llint long long int

using namespace std;

#define INF ((llint) 1.0e+12)

int main(){
    int N, M, P;

    cin >> N >> M >> P;

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

    for(int i = 0; i < M; i ++){
        cin >> A[i] >> B[i] >> C[i];

        C[i] -= P;
    }
    vector<llint> coin(N, -INF), score(N);
    vector<bool> inf_flag(N, false);

    coin[0] = 0;

    for(int i = 0; i < N; i ++){
        for(int j = 0; j < M; j ++){
            if(coin[A[j] - 1] != -INF){
                llint new_coin = coin[A[j] - 1] + C[j];

                if(new_coin > coin[B[j] - 1]){
                    coin[B[j] - 1] = new_coin;
                }
            }
        }
        score[i] = coin[N - 1];
    }
    for(int j = 0; j < M; j ++){
        if(coin[A[j] - 1] != -INF){
            llint new_coin = coin[A[j] - 1] + C[j];

            if(new_coin > coin[B[j] - 1]){
                inf_flag[B[j] - 1] = true;
            }
        }
    }
    for(int i = 0; i < N; i ++){
        for(int j = 0; j < M; j ++){
            if(inf_flag[A[j] - 1] == true){
                inf_flag[B[j] - 1] = true;
            }
        }
    }
    if(inf_flag[N - 1] == true){
        cout << - 1 << endl;
    }else if(score[N - 1] < 0){
        cout << 0 << endl;
    }else{
        cout << score[N - 1] << endl;
    }
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

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

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    string s;
    cin >> s;
    int cnt = 0;
    rep(i, 3) if(s[i] == 'R') ++cnt;
    if(s == "RSR") cnt = 1;
    cout << cnt << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 3636
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdio>
#include <stack>

using namespace std;

int getret(int a) {

	int ret = 0;
	while (1) {
		if (a == 0) break;
		ret = ret + a % 10;
		a = a / 10;
	}
	return ret;
}


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

	int ret = getret(n);

	if (n % ret == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
void Main()
{
    ll x;
    cin >> x;

    ll sum = (x / 11) * 2;
    ll rem = x % 11;
    if (rem != 0) {
        if (rem <= 6) {
            sum += 1;
        }
        else {
            sum += 2;
        }
    }

    put(sum);

}
signed main(){ Main();return 0;}

Measured memory_bytes: 3592
#include <stdio.h>
int min(int a,int b){
	if(a < b)
		return a;
	else
		return b;
}

int main(void)
{
	int N = 0,A[100000] = {0};
	int i = 0,j = 0,k = 0,l = 0;
	long long int ans = 0;
	
	scanf("%d",&N);
	for(i = 0;i < N;i++)
		scanf("%d",&A[i]);
	
	for(i = 0;i < N;i++){
		while(1){
			if(A[i] > 1){
				ans += A[i] / 2;
				A[i] %= 2;
			}else if(A[i] > 0 && A[i + 1] > 0){
				ans += min(A[i],A[i + 1]);
				l = min(A[i],A[i + 1]);
				A[i] -= l;
				A[i + 1] -= l;
			}else{
				break;
			}
		}
	}
	
	printf("%lld\n",ans);
	
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];

int main(){
  int H,W ,h,w ;
  cin >> H >> W >> h >> w ;
  cout << (H-h)*(W-w) << endl;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	String s = sc.next();
    	Set<Character> set = new HashSet<>();
    	for (char c : s.toCharArray()) {
    		set.add(c);
    	}
    	System.out.println(s.length() == set.size() ? "yes" : "no");
    }
}

Measured memory_bytes: 23252
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <math.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define vsort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end())


// a,bの最小公倍数
ll LCM(ll a, ll b){ll lcm = a * b; ll r = a % b;while(r != 0){a = b; b = r; r = a % b;}return lcm /= b;}
// a,bの最大公約数
ll GCD(ll a, ll b){ll r = a % b;while(r != 0){a = b; b = r; r = a % b;}return b;}


const int MOD = 1000000007;
const int INF = INT_MAX;



int main(){

    int c[3][3];
    rep(i,3){
        rep(j,3) cin >> c[i][j];
    }


    int flag = 0;
    for (int i=0; i <= 100; i++){
        for (int j=0; j <= 100; j++){
            for (int k=0; k <= 100; k++){
                if(c[0][0] - i == c[0][1] - j && c[0][1] - j == c[0][2] - k &&
                   c[1][0] - i == c[1][1] - j && c[1][1] - j == c[1][2] - k &&
                   c[2][0] - i == c[2][1] - j && c[2][1] - j == c[2][2] - k){
                       flag = 1;
                   }
            }
        }
    }

    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;

}





//              g++ -std=c++1z


Measured memory_bytes: 256
house = [[ 0 for i in range(10)],
        [ 0 for i in range(10)],
        [ 0 for i in range(10)],
        [ "#" for i in range(20)],
        [ 0 for i in range(10)],
        [ 0 for i in range(10)],
        [ 0 for i in range(10)],
        [ "#" for i in range(20)],
        [ 0 for i in range(10)],
        [ 0 for i in range(10)],
        [ 0 for i in range(10)],
        [ "#" for i in range(20)],
        [ 0 for i in range(10)],
        [ 0 for i in range(10)],
        [ 0 for i in range(10)]]
n = int(input())
for i in range(n):
    b,f,r,v = map(int,input().split())
    if b==1:
        house[f-1+(b-1)*4][r-1] += v
    elif b==2:
        house[f-1+(b-1)*4][r-1] += v
    elif b==3:
        house[f-1+(b-1)*4][r-1] += v
    else:
        house[f-1+(b-1)*4][r-1] += v
for i in range(len(house)):
    if (i+1)%4 ==0:
        print(''.join(str(i) for i in house[i]))
    else:
        print('',' '.join(str(i) for i in house[i]))


Measured memory_bytes: 5628
#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define pb              push_back
#define int             long long
#define mp              make_pair
#define pr              pair<long long,long long>
#define vr              vector<long long>
#define mod1            1000000007
#define mod2            998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define ll              long long
#define ld	            long double
#define w(x)            int x; cin>>x; while(x--)

int32_t sum_of_digit(int n)  
{  
    if (n == 0)  
    return 0;  
    return (n % 10 + sum_of_digit(n / 10));  
}  



int32_t main()
{ 
    int l,r,d;
    cin>>l>>r>>d;
    int ans=0;
    for(int i=l;i<=r;i++)
    {
        if(i%d==0)
        ans++;
    }
    cout<<ans<<"\n";
	return 0;
	}

Measured memory_bytes: 3592
#include<iostream>
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;

int main() {
	
    string s ;    
    cin >> s  ;

    char a[s.size()] ;    
    char b[s.size()] ;    

    for(int i=0;i<s.size();i++){
    if(i%2==0){
       a[i] = '0' ;
       b[i] = '1';
    }else{
       a[i] = '1' ;
       b[i] = '0';
           }
    }
    // cout << a << b  << endl ;
    int ans1= 0 ; int ans2 = 0  ;
    for(int i=0;i<s.size();i++){
        if(a[i]!=s[i]) ans1+=1 ;
        if(b[i]!=s[i]) ans2+=1 ;
    }

    if(ans1<ans2)
     cout << ans1 ;
    else
     cout << ans2 ;

    cout  << endl ;
  //cout << (ans1<ans2) ? ans1 : ans2 ;
  	return 0;
}


Measured memory_bytes: 640
import java.io.*;
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;

public class Main{

    public static void main(String[] args){
        //START

        Scanner sc=new Scanner(System.in);
        int M=sc.nextInt();

        int N=M%10;

        if(N==2||N==4||N==5||N==7||N==9){
            System.out.println("hon");
        }else if(N==0||N==1||N==6||N==8){
            System.out.println("pon");
        }else{
            System.out.println("bon");
        }

        //END
    }
}



Measured memory_bytes: 35780
l = int(input(""))
a = 0.001
b = l - 2 * a
V = 0
V_vec = [0,0]
for i in range(l*999):
    if V < a * a * b :
        V = a * a * b
        V_vec = [a,b]
    a += 0.001
    b = l - 2 * a
print(V)

Measured memory_bytes: 2940
s = input()

if len(s) % 2 == 0:
    s1 = s[:len(s) // 2]
    s2 = s[:len(s) // 2 - 1:-1]
else:
    s1 = s[:len(s) // 2]
    s2 = s[:len(s) // 2:-1]

ans = 0
for i in range(len(s1)):
    if s1[i] != s2[i]:
        ans += 1

print(ans)


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

struct UnionFind {
  UnionFind(size_t size) : v(size, -1) {}
  vector<int> v;

  int root(int x) {
    return (v[x] < 0 ? x : v[x] = root(v[x]));
  }

  bool same(int x, int y) {
    return root(x) == root(y);
  }

  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (v[x] > v[y]) swap(x, y);
      v[x] += v[y];
      v[y] = x;
    }
  }

  int size(int x) {
    return -v[x];
  }
};

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

  UnionFind uf(N + M);
  for (int i = 0; i < N; ++i) {
    int k;
    cin >> k;

    while (k--) {
      int l;
      cin >> l;

      uf.unite(i, N + l - 1);
    }
  }

  bool f = true;
  int v = uf.root(0);
  for (int i = 0; i < N; ++i) {
    if (v != uf.root(i)) f = false;
  }

  cout << (f ? "YES" : "NO") << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(int argc, char const *argv[]) {
  int N=0,T=0,z=0,i,x=0;
  scanf("%d %d",&N,&T);
  int t[N];
  for (i = 0; i < N; i++) {
    scanf("%d",&t[i]);
  }
  for (i = 0; i < N; i++) {
    if (z > t[i]) {
      x += (T - (z - t[i])) ; z = t[i] + T;
    }else{
      x += T ; z = t[i] + T;
    }
  }
  printf("%d",x);
  return 0;
}

Measured memory_bytes: 896
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		short size, sum;
		while (true) {
			sum = 0;
			String input = in.readLine();
			if (input.equals("0")) {
				break;
			}
			size = (short) input.length();
			char[] charNum = input.toCharArray();
			for (int i = 0; i < size; i += 1) {
				charNum[i] = input.charAt(i);
				sum += Short.parseShort(Character.toString(charNum[i]));
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 17032
#include <bits/stdc++.h>    
using namespace std;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define fone for(i=0;i<n;i++)
#define endl "\n"
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N          = 5000*100+1;
const ll N2      = 1000*1000;
const ld PI  = 3.14159265;
const ll R   = 250;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;} 
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
    }

    int main()
    {
        int a,b;
        cin>>a>>b;
        if(b>a)
        {
            for(int i=0;i<b;i++)
                {cout<<a;}
        }
        else
        {
            for(int i=0;i<a;i++)
            {
                cout<<b;
            }
        }

return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  string w;
  cin >> w;

  vector <int> app(26);  //現れた回数
  int N = w.length();
  rep(i,N){
    app[w[i] - 'a'] ++;
  }
  rep(i,26){
    if (app[i] % 2 != 0){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
const string tr="abcdefghijklmnopqrstuvwxyz";
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll llpow(ll n,ll i){ll cnt=n;  for(ll j=0;j<i-1;j++){n*=cnt;}return n;}
bool ip/*is_prime*/(long long N) {if (N == 1) return false;for (long long i = 2; i * i <= N; ++i) {if (N % i == 0) return false;}return true;}
int digit(ll N) {int ans = 0;while (N) {++ans;N /= 10;}return ans;}
vector<pair<ll,ll>> pf/*prime_factorize*/(ll n){vector<pair<ll,ll>> res;for(ll a=2;a*a<=n;a++){if(n%a!=0) continue;ll ex=0;while(n%a==0){ex++;n/=a;}res.pb({a,ex});}if(n!=1) res.pb({n,1});return res;}
vector<ll> div/*divisor*/(ll n){  vector<ll> res={1};for(ll a=2;a*a<=n;a++){if(n%a!=0) continue;ll b=n/a;res.pb(b);if(b!=a) res.pb(a);}sort(all(res));return res;}

int main() {
  ll n,m;
  cin>>n>>m;
  ll G=gcd(n,m);
  auto pg=pf(G);
  cout<<pg.size()+1<<endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int P = 1e9 + 7;
inline int add(int a, int b) {if((a += b) >= P) a -= P; return a;}
inline int sub(int a, int b) {if((a -= b) < 0) a += P; return a;}
inline int mul(int a, int b) {return 1ll * a * b % P;}
inline int kpow(int a, int b) {int r=1;for(;b;b>>=1,a=mul(a,a)) {if(b&1)r=mul(r,a);}return r;}
//----
const int N = 2020;
int f[N], g[N];
int n, z, w;
int a[N];
int main(){
	scanf("%d%d%d", &n, &z, &w);
	rep(i, 0, n) scanf("%d", a + i);
	int ans = 0;
	if(n == 1) {
		ans = abs(a[0] - w);
	} else {
		f[n - 1] = abs(a[n - 1] - w);
		f[n - 2] = abs(a[n - 1] - a[n - 2]);
		g[n - 2] = abs(a[n - 1] - a[n - 2]);
		for(int i = n - 3; i > -1; i--) {
			int & t = f[i];
			t = abs(a[n - 1] - a[i]);
			rep(j, i + 1, n - 1) t = min(t, g[j]);
			int & q = g[i];
			q = abs(a[n - 1] - a[i]);
			rep(j, i + 1, n - 1) q = max(q, f[j]);
		}
		rep(i, 0, n) ans = max(ans, f[i]);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3888
//
// Created by corol

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio();
    cin.tie(0);
    int n,d;
    cin >> n >> d;
    vector <double> a(n);
    for (int i=0;i<n;i++) {
        double l,b;
        cin >>l >> b;
        a[i]=sqrt(l*l+b*b);
    }
    int cnt=0;
    for (int i=0;i<n;i++) {
        if (a[i]<=d) cnt++;
    }
    cout << cnt;
    //cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s. \n";
    return 0;
}

Measured memory_bytes: 4848
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N, K = map(int, input().split())
A = list(map(int, input().split()))

print(max(N - sum(A), -1))






Measured memory_bytes: 10144
#include<iostream>

using namespace std;

int main(void)
{
  int a,b; cin>>a>>b;
  int max;
  if(a>b){max=a;}else{max=b;}
  for(int i=0;i<10000;i++){
    int A=0.08*i;
    int B=0.1*i;
    if((A==a)&&(B==b)){ cout<<i<<endl; return 0;}
  }
  cout<<-1<<endl;
  
  return 0;
}

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

void Main()
{
    string s, t;
    cin >> s >> t;
    int sum = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if(s[i] != t[i]) sum++;
    }
    
    cout << sum << endl;
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


Measured memory_bytes: 3916