akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;


int main(void){
  int h,w,i,j,sr=0;
  string s[55];
  
  cin >> h >> w;
  for (i=0;i<h;i++) cin >> s[i];
  
  for (i=0;i<h;i++) for (j=0;j<w;j++){
    if (s[i][j]=='.') sr++;
  }
  
  int d[55][55];
  const int INF=1e9;
  for (i=0;i<h;i++) for (j=0;j<w;j++){
    d[i][j]=INF;
  }
  
  d[0][0]=0;
  int pi,pj,k;
  const int di[4]={1,0,-1,0},dj[4]={0,1,0,-1};
  P p;
  queue<P> q;
  q.push(P(0,0));
  while (q.size()>0){
    p=q.front();
    q.pop();
    pi=p.first;
    pj=p.second;
    for (k=0;k<4;k++){
      int ni,nj;
      ni=pi+di[k];
      nj=pj+dj[k];
      if (ni>=0 && ni<h && nj>=0 && nj<w && s[ni][nj]=='.' && d[ni][nj]>d[pi][pj]+1){
        d[ni][nj]=d[pi][pj]+1;
        q.push(P(ni,nj));
      }
    }
  }
  
  if (d[h-1][w-1]==INF) cout << -1 << endl;
  else cout << sr-d[h-1][w-1]-1 << endl;
  
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        
        Queue<Integer> queue = new PriorityQueue<>();
        
        for(int i = 0; i < N; i++){
            queue.add( sc.nextInt() );
        }
        
        int total = 0;
        for(int i = 0; i < N; i++){
            int x = queue.poll();
            if( i == N-1 ) x /= 2;
            total += x;
        }
        
        System.out.println(total);
        
    }
}


Measured memory_bytes: 21204
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define inf 100000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
#define ar array
const ll maxN=1e5+5 , N=1e3+5;
ar<ll,3> a[maxN],dp[maxN];
ll n ;
void solve(){
	cin>>n ;
	for(ll i=0;i<n ; i++)cin>>a[i][0]>>a[i][1]>>a[i][2];

	dp[0][0]=a[0][0], dp[0][1]=a[0][1], dp[0][2]=a[0][2];
	for(ll i=1;i<n ; i++){
		dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=a[i][1]+max(dp[i-1][2],dp[i-1][0]);
		dp[i][2]=a[i][2]+max(dp[i-1][0],dp[i-1][1]);
	}
	// for(ll i=0;i<n ;i++){
	// 	cerr<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl;
	// }
	cout<<max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
}
int main(){
	//mahakal(),fast;
	ll t=1;
	// cin>> t ;
	while(t--)solve();

	return 0;
}

Measured memory_bytes: 8284
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    long long a,b,x,ans;
    cin >> a >> b >> x;
    
    
    ans = b/x - max(0LL,a-1)/x;
     
     if ( !a ) { ans++; }
     
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define inf 1000000000
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define yoi cout<<"yo"<<endl;
#define debug(i) cout<<i<<endl;
const int mod=1e9 +7;
lli power(lli x, lli y, lli p)
{
    lli res = 1;

    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
int main(){
IOS;
lli n,k,i;
cin>>n>>k;
lli fact[n+1];
fact[0]=1;
for(i=1;i<=n;i++){
    fact[i]=(fact[i-1]*i)%mod;
}
lli inverse[n+1];
inverse[0]=1;
for(i=1;i<=n;i++){
    inverse[i]=power(fact[i],mod-2,mod);
}
for(i=1;i<=k;i++){
    lli ans=(fact[n-k+1]*inverse[i])%mod;
    ans=(ans*inverse[n-k-i+1])%mod;
    ans=(ans*fact[k-1])%mod;
    ans=(ans*inverse[k-i])%mod;
    ans=(ans*inverse[i-1])%mod;
    if(i>n-k+1)
        ans=0;
    cout<<ans<<endl;
}
}


Measured memory_bytes: 256
/*  
	Come feed the rain
	Cos I'm thirsty for your love
	Dancing underneath the skies of lust
	Yeah feed the rain...
	Cos without your love my life
	Ain't nothing but this carnival of rust
    _________________________
    _________________________
    840 Hours of Solitude
    Quarantine_Day : 35
*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int       ll;
typedef vector<int>         vi;
typedef vector<ll>          vl;
typedef pair<int, int>      pii;
typedef pair<ll, ll>		pll;

#define pb(n)           push_back(n)
#define GSORT(v)        sort(v.begin(), v.end(), greater<int>())
#define SORT(v)         sort(v.begin(), v.end());
#define REV(v)          reverse(v.begin(), v.end());
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define REP(i,n)        for(int i = (int)(0); i < (int)(n); i++)
#define FOR(i, a, b)    for(int i = (int)a; i <= (int)b; i++)    

#define MAX 50005
#define MOD 1000000007

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

	ll a, b, c;
	cin>>a>>b>>c;

	ll sum = a;
	bool flag = false;
	while(sum <= a * b){
		if(sum % b == c){
			flag = true;
			break;
		}
		sum += a;
	}
	cout<<(flag?"YES\n":"NO\n");

	return 0;
}


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

typedef long long ll;


int main(){

  ll T;
  cin >> T;
  for(ll i=0;i<T;i++){
    ll h,w;
    cin >> h >> w;
    ll k = __gcd(h,w);
    h = h/k; w = w/k;
    if( h == w ){
      cout << 1 << " " << 0 << endl;
    } else if( h == 1 || w == 1 ){
      ll a = max( h,w );
      if( a % 2 == 1 ){
        cout << a/2+1 << " " << a/2 << endl;
      } else {        
        cout << 1 << " " << 1 << endl;
      }
    } else {
      if( h % 2 == 1 && w % 2 == 1 ){       
        cout << w*h/2+1 << " " << w*h/2 << endl;
      } else 
        cout << 1 << " " << 1 << endl;
    }
  }
}

Measured memory_bytes: 1164
package main

import (
	"bufio"
	"os"
	"strings"
	"fmt"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	num := strings.Split(sc.Text(), "")
	if num[0] == num[2] {
		fmt.Printf("Yes")
	} else {
		fmt.Printf("No")
	}


}

Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define INF 1e10
#define MOD 1e9+7
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; }
signed main(){
int a;
  cin>>a;
  int b=a/100;
  if(b*105<a)
    cout<<0;
  else
    cout<<1;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
/*
         ########     ########   ########   #########   ##       #######   ##       #######
         #      #     #      #   #      #       #       # #      #     #   # #      #     #
         #      #     #      #   #      #       #       #  #     #     #   #  #     #     #
         ########     #      #   #      #       #       #   #    #     #   #   #    #     #
         ###          #      #   #      #       #       #    #   #######   #    #   #######
         #  #         #      #   #      #       #       #   #    #     #   #   #    #     #
         #   #        #      #   #      #       #       #  #     #     #   #  #     #     #
         #    #       #      #   #      #       #       # #      #     #   # #      #     #
         #     #      ########   ########       #       ##       #     #   ##       #     #
*/

#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define bitcount __builtin_popcountll //count no's of ones in a set bit
#define prq priority_queue
#define mp make_pair
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define debug(a)          \
    cerr << #a << ": ";   \
    for (auto i : a)      \
        cerr << i << " "; \
    cerr << '\n';
#define trace(a) cerr << #a << ": " << a << "\n"
#define print(ar, n)            \
    for (int u = 0; u < n; u++) \
    {                           \
        cout << ar[u] << " ";   \
    }                           \
    cout << endl;
#define int long long
#define M 1000000007
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
signed main()
{
    rootdada;
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
//     freopen("error.txt", "w", stderr);
// #endif
    int n; cin >> n; vi a(n);
    rep(i, 0, n)
    cin >> a[i];
    int maxi = INT_MIN;
    int ans = 0;
    rep(i, 0, n)
    {
        if (maxi < a[i])
            maxi = a[i];

        ans += (maxi - a[i]);
    }
    cout << ans << endl;
}

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



int main()
{

    //ios_base::sync_with_stdio(false);

    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5])
        cout<<"Yes\n";
    else
        cout<<"No\n";

    return 0;
}


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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    string B;
    long long a, b;
    cin >> a >> B;

    b = (B[0] - '0') * 100 + (B[2] - '0') * 10 + (B[3] - '0');

    cout << a * b / 100 << "\n";
    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
    long int n,ans,b,a[n];
    cin>>n;
    REP(i,n)cin>>a[i];
    REP(i,n){
        b=a[i];
        while(1){
            if(b%2==0){
                b=b/2;
                ans++;
            }
            if(b%2!=0)break;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <math.h>
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;

int main() {
  double r;
  cin >> r;
  double m = r*r*M_PI;
  double e = r*2*M_PI;
  cout << fixed;
  cout << setprecision(6) << m << " " << e << endl;
}



Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

string get(int x){
    string s = to_string(x);
    return string(4-s.size(), '0') + s;
}

int main() {
    map<string, int> dp;
    dp["6174"] = 0;
    auto dfs = [&](string s, auto &&f){
        if(dp.count(s)) return dp[s];
        string a = s, b = s;
        sort(a.begin(),a.end());
        sort(b.begin(),b.end(), greater<>());
        return dp[s] = f(get(stoi(b)-stoi(a)), f)+1;
    };
    for (int i = 0; i <= 9999; ++i) {
        if(i%1111 == 0) dp[get(i)] = -1;
        else dfs(get(i), dfs);
    }
    string s;
    while(cin >> s, s != "0000"){
        if(dp[s] < 0) puts("NA");
        else cout << dp[s] << "\n";
    }
    return 0;
}


Measured memory_bytes: 4372
import java.util.*;
import java.io.*;
import java.lang.*;



class Main
{
  public static void main(String[] args) {

  Scanner s=new Scanner(System.in);

  int n;
  n=s.nextInt();
  int [] a=new int[n];
  for(int i=0;i<n;i++)
  {
    a[i]=s.nextInt();
  }
    if(n<3)
    {
      System.out.println(0);
    }
    else
    {
    
    
    
  int count=0;
  for(int i=0;i<n-2;i++)
  {
    for(int j=i+1;j<n-1;j++)
    {
      for(int k=j+1;k<n;k++)
      {
        if(a[i]!=a[j] && a[j]!=a[k] && a[k]!=a[i])
        {
          if(a[i]+a[j]>a[k] && a[i]+a[k]>a[j] && a[k]+a[j]>a[i])
          {
            count++;
          }
        }
        
      }
    }
  }
  System.out.print(count);
    }













  }
}


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

typedef std::basic_string<int> string;

std::vector<string> a, b, c;

void dfs(std::vector<string> &ret, int rem, string now) {
	if (!rem) return ret.emplace_back(now);
	for (int i = 1; i <= rem; ++i) dfs(ret, rem - i, now + (i - 1));
}

const int N = 500005, mod = 1000000007;
int nxt[N][10], idx, fail[N];
bool end[N];
void insert(string s) {
	int p = 0;
	for (int ch : s) {
		if (!nxt[p][ch]) nxt[p][ch] = ++idx;
		p = nxt[p][ch];
	}
	end[p] = 1;
}
void build() {
	std::queue<int> q;
	for (int i = 0; i < 10; ++i) if (nxt[0][i]) q.push(nxt[0][i]);
	while (q.size()) {
		int x = q.front(); q.pop();
		for (int i = 0; i < 10; ++i)
			if (nxt[x][i]) {
				fail[nxt[x][i]] = nxt[fail[x]][i];
				end[nxt[x][i]] |= end[fail[nxt[x][i]]];
				q.push(nxt[x][i]);
			} else nxt[x][i] = nxt[fail[x]][i];
	}
	for (int i = 1; i <= idx; ++i) if (end[i]) for (int j = 0; j < 10; ++j) nxt[i][j] = i;
}

int dp[41][N];
void reduce(int &x) { x += x >> 31 & mod; }
int main() {
	int n, x, y, z;
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> x >> y >> z;
	dfs(a, x, string()), dfs(b, y, string()), dfs(c, z, string());
	for (string p : a) for (string q : b) for (string r : c) insert(p + q + r);
	build();
	dp[0][0] = 1;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j <= idx; ++j)
			for (int k = 0; k < 10; ++k)
				reduce(dp[i + 1][nxt[j][k]] += dp[i][j] - mod);
	int ans = 0;
	for (int i = 0; i <= idx; ++i) if (end[i]) reduce(ans += dp[n][i] - mod);
	std::cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 82304
#include <iostream>
#include <string>
    
int main(){
    const std::string wrong_word("Hoshino");
    const std::string right_word("Hoshina");
      
    int num;
    std::cin >> num;
    std::cin.ignore(); // ignore next newline character
        
    for(int i = 0; i < num; ++i){
        std::string str;
        std::getline(std::cin, str);
          
        std::size_t pos = str.find(wrong_word);
        while(pos != std::string::npos){
            str.replace(pos, wrong_word.length(), right_word);
            pos = str.find(wrong_word);
        }
          
        std::cout << str << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3124
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  for (int i = 0; i < 10; i++) {
    c=c*a-b;
    cout << c << endl;
  }
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
//配列の内容表示
dout << "====listの内容====\n";
for (int i = 0; i < N; i++) dout << list[i] << endl;
dout << "====ここまで====\n";
*/


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

int main(){
    while(1){
        vector<int>p(3);
        cin >> p[0] >> p[1] >> p[2];
        int t = p[0]+p[1];
        
        if(p[0]+p[1]+p[2] == -3){
            return 0;
        }else if((p[0] ==-1)||(p[1] ==-1)){
            cout << 'F' << endl;
        }else if(t >= 80){
            cout << 'A' << endl;
        }else if((80 > t)&&(t >= 65)){
            cout << 'B' << endl;
        }else if((65 > t)&&(t >= 50)){
            cout << 'C' << endl;
        }else if((50 > t)&&(t >= 30)){
            if(p[2] >= 50){
                cout << 'C' << endl;
            }else{
                cout << 'D' << endl;
            }
        }else{
            cout << 'F' << endl;
        }
    }
}


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

int main() {
    int n; cin >> n;
    vector<ll> a(2 * n, 0);
    ll total = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i], a[i + n] = a[i], total += a[i];
    }
    for (int i = 1; i < 2 * n; i++) {
        a[i] += a[i - 1];
    }
    // [i, j), [j, k), [k, i+n) の３ピースに分ける
    ll ans = 0;
    for (int i = 0, j = i + 1; i < n; i++) {
        while (true) {
            ll d = a[j] - a[i];
            auto tail = a.begin() + i + n + 1;
            int k = lower_bound(a.begin(), tail, a[j] + d) - a.begin();
            if (a[i + n] - a[k] > d) {
                ans = max(ans, d);
                j++;
            } else {
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4424
N, L = map(int, input().split())
diff_min = 100 + 200 - 1
apples = list()
remove_apple = 0

for i in range(N):
    taste = L + i
    apples.append(taste)
    if abs(taste) < diff_min:
        diff_min = abs(taste)
        remove_apple = taste

print(sum(apples) - remove_apple)


Measured memory_bytes: 38384
#include <iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    int ans = 0;
    for(int i=0; i<N; i++){
        int a;
        cin >> a;
        int temp = 0;
        while(a%2==0){
            a /=2;
            temp++;
        }
        ans += temp;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

n, q = map(int, input().split())
adj = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    adj[a].append(b)

res = [0] * n
for _ in range(q):
    i, x = map(int, input().split())
    res[i-1] += x

parent = [0] * n
stack = [0]
while len(stack) > 0:
    i = stack.pop()
    for j in adj[i]:
        res[j] += res[i]
        stack.append(j)

print(' '.join([str(x) for x in res]))



Measured memory_bytes: 112128
//Author : Ayush Jain
 
#include <bits/stdc++.h>
using namespace std;
 
#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define fi first
#define se second
const int N=1e5 + 5;
const int M=1e5 + 5;
 
ull pw[67];
void pre()
{
	pw[0]=1;
	for(int i=1;i<64;i++) pw[i]=2*pw[i-1];
}
bool vis[100005];
int mn[100005],t1[100005],t2[100005],tim=0,pt[100005],root;
vector <int> v[100005],art;
vector < pair < int , int > > bd;
int dfs(int s)
{
	vis[s]=true;
	t1[tim]=s;
	t2[s]=tim;
	tim++;
	int c=0;
	bool foo=false;
	int mnt=1e6;
	for(int i=0;i<v[s].size();i++){
		if(!vis[v[s][i]]){
			pt[v[s][i]]=s;
			mnt=min(mnt,dfs(v[s][i]));
			c++;
			if(!foo && s!=root && mn[v[s][i]] >= t2[s]){
				foo=true;
				art.push_back(s);
			}
			if(mn[v[s][i]] > t2[s]){
 
				int a=min(v[s][i],s);
				int b=max(v[s][i],s);
				bd.push_back(make_pair(a,b));
			}
		}
		else{
			if(v[s][i]!=pt[s])
			mnt=min(mnt,t2[v[s][i]]);	
		}
		
	}
	if(s==root && c>1) art.push_back(s); 
	mn[s]=mnt;
	return mnt;
 
}
int main()
{
	ios_base::sync_with_stdio(false);
	pre();
	int n,m,i,p,q;
	map < pair < int , int > , int > id;
	cin>>n>>m;
	for(i=0;i<m;i++){
		cin>>p>>q;
		id[make_pair(min(p,q),max(p,q))]=i+1;
		v[p].push_back(q);
		v[q].push_back(p);
	}
	for(i=0;i<100005;i++){
		vis[i]=false;
		pt[i]=-1;
	} 
    for(i=1;i<=n;i++){
        if(!vis[i]){
            root=i;
            dfs(i);
        }
    }	
    cout<<bd.size()<<endl;
	// bool is[100005];
	// for(i=0;i<100005;i++) is[i]=false;
	// for(i=0;i<bd.size();i++){
	// 	int a=min(bd[i].fi , bd[i].se);
	// 	int b=max(bd[i].fi , bd[i].se);
	// 	is[id[make_pair(a,b)]]=true;
	// } 
	// int Q;
	// cin>>Q;
	// while(Q--){
	// 	int x;
	// 	cin>>x;
	// 	if(is[x]){
	// 		cout<<"Unhappy\n";
	// 	}
	// 	else cout<<"Happy\n";
	// }	
	
	return 0;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
char a[10001];
inline int read()
{
    int k=1;int x=0;
    char c=getchar();
    while ((c<'0'||c>'9')&&c!='-')c=getchar();
    if(c=='-')
    k=-1,c=getchar();
    while(c>='0'&&c<='9')
    x=x*10+c-'0',c=getchar();
    return k*x;
}
int main()
{
    cin>>a;
    cout<<a[0]<<strlen(a)-2<<a[strlen(a)-1]<<endl;
    return 0;
}

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 100;
const long long LLINF = 2e18 + 129;
const long long MOD = 1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

struct edge{
    int to, cost;
};

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

int n;
vector<int> c;
vector< vector<edge> > g;
vector<edge> rev;
vector<bool> semi;

void dfs1(int v){
    if(semi[v]){
        return;
    }
    semi[v] = true;
    dfs1(rev[v].to);
    return;
}

int dfs2(int v, int mini){
    if(c[v] > 0){
        return mini;
    }

    int res = 0;
    for(auto x : g[v]){
        res += dfs2(x.to, min(mini, x.cost)) * (int)semi[x.to];
    }
    chmin(res, mini);

    return res;
}

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

    cin >> n;

    c.resize(n);
    REP(i, 1, n){
        cin >> c[i];
    }

    g.resize(n);
    rev.resize(n);
    rep(i, n - 1){
        int u, v, p;
        cin >> u >> v >> p;
        g[u].push_back({v, p});
        rev[v] = {u, p};
    }
    rev[0] = {0, IINF};

    semi.resize(n);
    rep(i, n){
        if(c[i] > 0){
            dfs1(i);
        }
    }

    int ans = dfs2(0, IINF) * (int)semi[0];
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3264
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<>();
		for (int i = 0; i < n; i++) {
		    int x = sc.nextInt();
		    if (x >= a) {
		        list.add(x);
		    } else {
		        break;
		    }
		}
		int count = 0;
		if (n - list.size() < m) {
		    for (int i = list.size() - 1; i >= 0; i--) {
		        if (list.get(i) <= b) {
		            count++;
		        } else {
		            break;
		        }
		    }
		}
		System.out.println(list.size() - count);
	}
}



Measured memory_bytes: 30328
#include <iostream>
#include <vector>
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<double> x(N);
  vector<string> u(N);
  for (int i = 0; i < N; i++)
    cin >> x[i] >> u[i];
  double ans = 0.0;
  for (int i = 0; i < N; i++)
  {
    if (u[i] == "BTC")
      ans += 380000.0 * x[i];
    else
      ans += x[i];
  }
  printf("%.6f\n", ans);
  return 0;
}

Measured memory_bytes: 256
while True:
    n = int(input())
    
    if n==0:
        break
    
    count = 0
    while True:
        if n==1:
            break
    
        if n%2==0:
            n = int(n/2)
            count += 1
            continue
        if n%2==1:
            n = int(3*n+1)
            count += 1
            continue
        
        if n==1:
            break
    
    print(count)
    
    continue


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

int main() {
  int n, ans = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    char a[10];
    sprintf(a, "%d", i);
    ans += (strlen(a) & 1);
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 256
using static System.Console;
using static System.Convert;

class Program
{
    static void Main(string[] args)
    {
        var input = ReadLine();
        var num = ToInt32(input);
        var sum = 0;
        for(var i = 0; i < input.Length; i++)
        {
            sum += ToInt32(input.Substring(i, 1));
        }
        WriteLine(num % sum == 0 ? "Yes" : "No");
    }
}



Measured memory_bytes: 11220
N = int(input())
W = list(map(int,input().split()))
d = [0]
r = 0
for w in W:
  r += w
  d.append(r)
m = 1000000000000000000
for i in range(1,N):
  d1 = d[i]
  d2 = d[-1] - d[i]
  m = min(m,abs(d1-d2))
print (m)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define sort(a) sort(a.begin(),a.end())
#define MOD (int)(1e9+7)
#define EPS 1e-8
#define INF (int)(1e9+1e7)
#define INFL (ll)(1e18)
typedef long long ll;
using namespace std;
int main()
{
    int N,Q;
    cin >> N >> Q;
    vector<tuple<ll,ll,ll>>p;
    rep(i,N){
        ll s,t,x;
        cin >> s >> t >> x;
        p.push_back(make_tuple(x,s-x,t-x));
    }
    sort(p);
    set<ll>D;
    map<ll,ll> ans;
    rep(i,Q){
        ll d;cin >> d;
        D.insert(d);
        ans[d]= -1;
    }


    rep(i,N){
        if(D.size()==0){break;}
        ll a=get<1>(p[i]);
        ll b=get<2>(p[i]);
        ll x=get<0>(p[i]); 
        auto itr1=D.upper_bound(a-1);
        auto itr2=D.lower_bound(b);
        for(auto itr = itr1;itr != itr2;itr++){
            ans[*itr]=x;
        }
        D.erase(itr1,itr2);
    }

    for(auto itr = ans.begin();itr!=ans.end();++itr){
        cout << itr->second << endl;
    }
    return 0;
}


Measured memory_bytes: 28396
// https://atcoder.jp/contests/m-solutions2019/tasks/m_solutions2019_a

#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF (1e9)
#define MOD (1e9 + 7)
#define LINF (1e18)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

// long gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// long lcm(long a, long b) { return a * b / gcd(a, b); }

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

    int n;
    cin >> n;
    cout << 180 * (n - 2) << endl;

    return 0;
}


Measured memory_bytes: 256
#ifdef HIRO
#include "../stdc++.h"
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#include <bits/stdc++.h>
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;

ll b(int x) {
  if(x == 1) return (ll)x;
  return (ll)x * b(x - 1);
}

int main() {
#ifdef HIRO
  ifstream cin("input.txt");
  std::cin.rdbuf(cin.rdbuf());
#endif

  int n, m;
  cin >> n >> m;
  int t[100001] = { 0 };
  long c = 0, p = 0;
  string s;
  int x;
  for(int i = 0; i < m; i++) {
    cin >> x >> s;
    if(t[x] == -1) continue;
    if(s.compare("WA") == 0) {
      t[x]++;
    }
    else if(s.compare("AC") == 0){
      p += t[x];
      t[x] = -1;
      c++;
    }
  }
  cout << c << " " << p;
  return 0;
}



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

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> broken(n+1);
    rep(i,m){
        int a;
        cin >> a;
        broken[a] = 1;
    }
    vector<int> dp(n+2);
    const int mod = 1000000007;
    dp[n] = 1;
    for(int i = n-1;i >= 0;i--){
        if(broken[i]){
            dp[i] = 0;
            continue;
        }
        dp[i] = (dp[i+1] + dp[i+2]) % mod;
    }
    cout << dp[0] << endl;
}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline

n, m = [int(x) for x in input().split()]

islands = [set() for _ in range(n + 1)]

for _ in range(m):
    ab = [int(x) for x in input().split()]
    islands[min(ab)].add(max(ab))

ans = 0

for i in range(1, n):
    if i + 1 in islands[i]:
        ans += 1
    elif len(islands[i]) > 0:
        islands[i + 1].add(min(islands[i]))

ans += len(islands[n])

print(ans)


Measured memory_bytes: 64944
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int k = in.nextInt();
		int x = in.nextInt();
		solve(k, x);
	}

	private static void solve(int k, int x) {
		int l = x - k + 1;
		int r = x + k - 1;
		if (l < -1000000)
			l = -1000000;
		if (r > 1000000)
			r = 1000000;
		for (int i = l; i <= r; i++)
			System.out.print(i + " ");
		System.out.println();
	}
}


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

using namespace std;

int main(){
  vector<int> check(26,0);
  string S; cin>>S;

  for(int i=0;i<S.size();i++){
    check[S[i]-'a']++;
  }

  for(int i=0;i<26;i++){
    if(check[i]>1){cout<<"no"<<endl; return 0;}
  }

  cout<<"yes"<<endl;

  return 0;
}


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

adj = [[] for _ in range(n)]
for a, b in ab:
    a -= 1
    b -= 1
    adj[a].append(b)
    adj[b].append(a)

dp = [[0] * n for _ in range(1 << n)]
dp[1][0] = 1

for i in range(1 << n):
    for u in range(n):
        for v in adj[u]:
            if i >> v & 1 == 0:
                nxt = i + (1 << v)
                dp[nxt][v] += dp[i][u]

print(sum(dp[-1]))


Measured memory_bytes: 9216
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
using namespace std;
const int mod=1e9+7;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define rep2(i,x,n) for (int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
#define nepe(v) next_permutation(all(v))
#define F first 
#define S second
#define PB push_back 
#define MP make_pair
using ll = long long;
using vi = vector<int>; 
using vvi = vector<vi>;
using vl=vector<long long>;
using vp =vector<pair<int,int>>;

typedef pair<int,int> P;
string s;
int k;
ll INF = 1000000000000;

int main(){
    int N,M;
    cin >>N>>M;
    vl dp(N+1,0);
    vi dang(N+1,0);
    rep(i,M){
        int a;
        cin >>a;
        dang[a]=1;
    }
    dp[0]=1;
    if(dang[1]==1) dp[1]=0;
    else dp[1]=1;
    rep2(i,2,N+1){
        if(dang[i]==1) continue;
        dp[i]=(dp[i-1]+dp[i-2])%mod;
    }
    cout <<dp[N]<<endl;
}

Measured memory_bytes: 1408
#include <iostream>
using namespace std;
int main(void){ 
int A, B, C, D, E;
cin >> A >> B >> C >> D >> E;
if (A == 0){
cout << 1 << endl;
}
else if (B == 0){
cout << 2 << endl;
}
else  if (C == 0){
cout << 3 << endl;
}
else if (D == 0){
cout << 4 << endl;
}
else if (E == 0){
cout << 5 << endl;
}
}


Measured memory_bytes: 3600
#include <stdio.h>
int main(void){

int h,w;

while(1){
    scanf("%d %d",&h,&w);
    if(h==0&&w==0) break;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if((i + j) % 2==0){
                printf("#");
            }else{
                printf(".");
            }
        }printf("\n");
        }printf("\n");
    }
    return 0;
}
    


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

int main() {
  string s,t;
  cin>>s>>t;
  int a,b;
  cin>>a>>b;
  string u;
  cin>>u;
  if(s==u){
    cout<<a-1<<" "<<b<<endl;
  }
  else{
    cout<<a<<" "<<b-1<<endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define M 1000000
#define L 14

char H[M][L];

int getChar(char ch){
  if(ch=='A') return 1;
  else if(ch=='C') return 2;
  else if(ch=='G') return 3;
  else if(ch=='T') return 4;
  else return 0;
}

long long getKey(char str[]){
  long long sum=0, p=1, i;
  for(i=0; i<strlen(str); i++){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){return key%M;}
int h2(int key){return 1+(key%(M-1));}
int find(char str[]){
  long long key, i, h;
  key = getKey(str);
  for(i=0; ; i++){
    h = (h1(key)+i*h2(key))%M;
    if(strcmp(H[h], str)==0) return 1;
    else if(strlen(H[h])==0) return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key, i, h;
  key = getKey(str);
  for(i=0; ; i++){
    h = (h1(key)+i*h2(key))%M;
    if(strcmp(H[h], str)==0) return 1;
    else if(strlen(H[h])==0){
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}

int main(){
  int i, n, h;
  char str[L], com[9];

  for(i=0; i<M; i++) H[i][0]='\0';

  scanf("%d", &n);

  for(i=0; i<n; i++){
    scanf("%s %s", com, str);
    if(com[0]=='i') insert(str);
    else{
      if(find(str)) printf("yes\n");
      else printf("no\n");
    }
  }
  return 0;
}


Measured memory_bytes: 15396
#include<iostream>
using namespace std;
int main() {
	int n, x, y, z; long long p; cin >> n >> p;
	z = (p % 5000) / 1000;
	n -= z; p -= z * 1000;
	y = (p % 10000) / 5000;
	n -= y;
	x = p / 10000; n -= x;
	if (n < 0) {
		printf("-1 -1 -1\n"); return 0;
	}
	while (x >= 0) {
		if (n == 0) {
			printf("%d %d %d\n", x, y, z);
			return 0;
		}
		x--; y += 2; n--;
		if (n % 4 == 0)if (n / 4 <= y) {
			z += (n / 4) * 5; y -= n / 4;
			n -= n;
		}
	}
	printf("-1 -1 -1\n");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<cctype>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
        for(;;){
                int h,w;
                scanf("%d %d",&h,&w);
                if(h){
                        for(int x=0;x<h;x++){
                                if(x==0 || x==h-1){
                                for(int i=0;i<w;i++){
                                        printf("#");
                                }
                                printf("\n");
                                }else{
                                        for(int i=0;i<w;i++){
                                                if(i==0 || i==w-1){
                                                        printf("#");
                                                }else{
                                                        printf(".");
                                                }
                                        }
                                        printf("\n");
                                }
                        }
                printf("\n");
                }else{
                        break;
                }
        }
        return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
const int p=1e9+7;
const int N=2e5+5;
struct each{
	int c,w;
}a[N];
map<int,int>ma[N];
typedef pair<int,int>P;
typedef set<P>::iterator it;
int n,X,Y,fa[N],fac[N],tot[N];
bool com(each x,each y){
	return x.w<y.w;
}
set<P>s[N];
#define fi first
#define se second
long long fsp(int x,int y){
	int ans=1;
	while(y){
		if(y&1)	ans=1LL*ans*x%p;
		x=1LL*x*x%p,y>>=1;
	}
	return ans;
}
int find(int x){
	return fa[x]!=x?fa[x]=find(fa[x]):x;
}
bool check(int x,int y){
	if(a[x].c==a[y].c)	return a[x].w+a[y].w<=X;
	return a[x].w+a[y].w<=Y;
}
void merge(int i,int x){
	int f=0;
	it j=s[i].begin();
	while(j!=s[i].end()&&check(j->se,x)){
		fa[j->se]=find(x);
		if(!f)	f=1,j++;
		else{
			it k=j++;
			s[i].erase(k);
		}
	}
}
int main(){
	scanf("%d%d%d",&n,&X,&Y),fac[0]=1;
	for(int i=1;i<=n;i++)
		scanf("%d%d",&a[i].c,&a[i].w);
	sort(a+1,a+n+1,com);
	for(int i=1;i<=n;i++)
		s[a[i].c].insert(P(a[i].w,i));
	for(int i=1;i<=n;i++)	fa[i]=i;
	for(int i=1;i<=n;i++)	merge(i,1);
	for(int i=2;i<=n;i++){
		if(check(i,1))	fa[find(1)]=find(i);
		merge(a[i].c,i),merge(a[i-1].c,i);
	}
	for(int i=1;i<=n;i++)
		++ma[find(i)][a[i].c],++tot[find(i)];
	for(int i=1;i<=n;i++)	fac[i]=1LL*fac[i-1]*i%p;

	int ans=1;
	for(int i=1;i<=n;i++)
		if(find(i)==i){
			ans=1LL*ans*fac[tot[i]]%p;
			map<int,int>::iterator it=ma[i].begin();
			for(;it!=ma[i].end();it++)	ans=ans*fsp(fac[it->se],p-2)%p;
		}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 41600
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        for (int i = 1; i < 6; i++){
            int tmp = input.nextInt();
            if (tmp == 0){
                System.out.println(i);
                break;
            }
        }
    }
}

Measured memory_bytes: 35652
#include <stdio.h>

int main(void) {
	int A, B, T;
	int sum = 0;
	int i;

	scanf("%d %d %d", &A, &B, &T);

	for(i = A; i <= T; i += A) {
		sum += B;
	}

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

	return 0;
}

Measured memory_bytes: 128
S = input()
mod = 10 ** 9 + 7

a, ab, abc, n = 0, 0, 0, 1
for s in S:
    if s == "A":
        a += n
        a %= mod
    elif s == "B":
        ab += a
        ab %= mod
    elif s == "C":
        abc += ab
        abc %= mod
    else:
        a, ab, abc, n = 3 * a + n, 3 * ab + a, 3 * abc + ab, 3 * n
        a %= mod
        ab %= mod
        abc %= mod
        n %= mod

print(abc)

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;


// 21 25


void oneCase() {
    int n, a;
    cin >> n >> a;
    vector<int> x(n);
    for (auto& e : x) {
        cin >> e;
    }
    map<int, map<int, ll>> stc;
    for (auto val : x) {
        map<int, map<int, ll>> nw;
        nw[val][1] += 1;
        for (auto p : stc) {
            auto sm = p.first;
            for (auto pp : p.second) {
                auto take = pp.first;
                auto cnt = pp.second;
                nw[sm][take] += cnt;
                nw[sm + val][take + 1] += cnt;
            }
        }
        swap(nw, stc);
    }
    ll res = 0;
    for (auto p : stc) {
        auto sm = p.first;
        for (auto pp : p.second) {
            auto take = pp.first;
            auto cnt = pp.second;
            if (sm % take == 0 && sm / take == a) {
                res += cnt;
            }
        }
    }

    cout << res << "\n";
}


int main() {
    int task = 1;
//    cin >> task;
    while (task--) {
       oneCase();
    }

    return 0;
}

ll fact(ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        res = (res * n) % mod;
        --n;
    }
    return res;
}


Measured memory_bytes: 3072
#include <iostream>

int main()
{
	std::string T, S;
	int A=0;
	std::cin >> S >> T;
	for (int i = 0; i < S.length(); i++)
	{
		if (S[i] != T[i]) {
			A++;
		}
	}
	std::cout << A;
}

Measured memory_bytes: 3852
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
using namespace std;


int main(){
	int n;
	int c[500],s[500],f[500];
	cin >> n;
	for( int i = 1 ; i < n ; i++ ){
		cin >> c[i] >> s[i] >> f[i];
	}
	
	
	for( int i = 1 ; i < n ; i++ ){
	int sum = 0;
	
		for ( int j = i ; j < n ; j++ ){
			
			if ( sum < s[j] ) sum = s[j] + c[j];
			else sum += f[j] - (sum - 1) % f[j] + c[j] - 1;
		
		}
	cout << sum << endl;	
	}
	cout << 0;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// スペース区切りの整数の入力
		int n = sc.nextInt();

		long c = 0;

		for ( int i=1; i<10; i++ ) {
			for ( int j=1; j<10; j++ ) {
				long c1 = 0;
				long c2 = 0;
				// i=jの場合、一桁を考慮する
				if (i==j && i<=n) {
					c1++;
					c2++;
				}
				for ( int k=0; k<5; k++ ) {
					// min1 = i0000j
					int min1 = defmin(String.valueOf(i), String.valueOf(j), k);
					if ( min1 > n ) {
						break;
					}
					// max1 = i9999j
					int max1 = defmax(String.valueOf(i), String.valueOf(j), k);
					if ( max1 <= n ) {
						c1 = c1 + (long)Math.pow(10,k);
						continue;
					} else {
						// i0000j <= n(=ixxxx#) < i9999j
						String a = String.valueOf(n);
						// n(=ixxxx#) からxxxx取り出し
						String b = a.substring(1,a.length()-1);
						int p = Integer.valueOf(b);
						// ixxxxj 計算
						String l = String.valueOf(i);
						l = l.concat(b);
						l = l.concat(String.valueOf(j));
						int il = Integer.valueOf(l);
						// n(=ixxxx#) と ixxxxj の比較
						if ( il <= n ) {
							c1 = c1 + (long)(p+1);
						} else {
							c1 = c1 + (long)(p);
						}
					}
				}
				for ( int k=0; k<5; k++ ) {
					// min2 = j0000i
					int min2 = defmin(String.valueOf(j), String.valueOf(i), k);
					if ( min2 > n ) {
						break;
					}
					// max2 = j9999i
					int max2 = defmax(String.valueOf(j), String.valueOf(i), k);
					if ( max2 <= n ) {
						c2 = c2 + (long)Math.pow(10,k);
						continue;
					} else {
						// j0000i <= n(=jxxxx#) < j9999i
						String a = String.valueOf(n);
						// n(=jxxxx#) からxxxx取り出し
						String b = a.substring(1,a.length()-1);
						int p = Integer.valueOf(b);
						// jxxxxi 計算
						String l = String.valueOf(j);
						l = l.concat(b);
						l = l.concat(String.valueOf(i));
						int il = Integer.valueOf(l);
						// n(=jxxxx#) と jxxxxi の比較
						if ( il <= n ) {
							c2 = c2 + (long)(p+1);
						} else {
							c2 = c2 + (long)(p);
						}
					}
				}
				c = c + (long)(c1*c2);
			}
		}
		System.out.println(c);
	}
	private static int defmin(String c1, String c2, int z) {
		String s = c1;
		for ( int i=0; i<z; i++ ) {
			s = s.concat("0");
		}
		s = s.concat(c2);
		return Integer.valueOf(s);
	}
	private static int defmax(String c1, String c2, int z) {
		String s = c1;
		for ( int i=0; i<z; i++ ) {
			s = s.concat("9");
		}
		s = s.concat(c2);
		return Integer.valueOf(s);
	}
}

Measured memory_bytes: 22356
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i<n; i++){cin >> a[i];}
    long long ans = 0;
    int Max = 0; // aditinal part
    for (int i = 0; i<n; i++){
            Max = max(Max, a[i]);
            int Bi = Max;
            ans += Bi - a[i];
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	bool is_possible = false;
	for (int i = 1; i <= B; i++) {
		int total = A*i;
		if (total % B == C) {
			is_possible = true;
			break;
		}
	}
	if (is_possible) cout << "YES" << endl;
	else cout << "NO" << endl;
    return 0;
}

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

int main() {
    int N, W;
    cin >> N >> W;
    int w[N], v[N];
    for (int i = 0; i < N; i++) {
        cin >> w[i] >> v[i];
    }
    long values[W + 1];
    for (int i = 0; i <= W; i++) {
        values[i] = 0;
    }
    for (int i = 0; i < N; i++) {
        for (int j = W - w[i]; j >= 0; j--) {
            values[w[i] + j] = max(values[w[i] + j], values[j] + v[i]);
        }
    }
    cout << values[max_element(values, values + W + 1) - values] << endl;
    return 0;
}


Measured memory_bytes: 1024
// #include <algorithm>
#include <stdio.h>
#include <vector> 
#include <math.h>
#include <map>
using namespace std;

struct uv_t{
  int u;
  int v;
};

vector<int> Parent;
vector<int> Rank;
multimap<int, uv_t> Edge; // Key: weight

int findSet(int x);

void makeSet(int x){
  Parent.push_back(x);
  Rank.push_back(0);
}
int findSet(int x){
  if( x != Parent[x] ){
    int r = findSet(Parent[x]);
    Parent[x] = r;
  }
  return Parent[x];
}
void link(int x, int y){
  if( Rank[x] > Rank[y] ){
    Parent[y] = x;
  }else{
    Parent[x] = y;
    if( Rank[x] == Rank[y] ){
      Rank[y] = Rank[y] + 1;
    }
  }
}

void unite(int x, int y){
  link(findSet(x), findSet(y));
}

int main(){ // P.231 Kruskal
  int V, E;
  scanf("%d %d" ,&V ,&E);
  for( int i = 0 ; i < V ; i++ ){
    makeSet(i);
  }
  for( int i = 0 ; i < E ; i++ ){
    int s, t, w;
    scanf("%d %d %d" ,&s ,&t ,&w);
    uv_t uv = {s ,t};
    Edge.insert(make_pair(w, uv));
  }

  int accw = 0; // accumulated Weight
  for(const auto& e : Edge){
    int weight = e.first;
    uv_t node = e.second;
    if(findSet(node.u) != findSet(node.v)){
      accw += weight;
      unite(node.u ,node.v);
    }
  }

  printf("%d\n" ,accw);
  return 0;
}



Measured memory_bytes: 9080
#include<bits/stdc++.h>
using namespace std;
int n,m,ans;
int a[17][17],p[17],vis[17];
bool check(){
	for(int i=1;i<=m;++i){
		int tmp=0;
		for(int j=1;j<=a[i][0];++j)
			if(vis[a[i][j]]){
				tmp++;
				tmp%=2;
			}
		if(tmp!=p[i])
            return 0;
	}
	return 1;
}
void dfs(int x){
	if(x==n+1){
		if(check())
            ans++;
		return ;
	}
	for(int i=x+1;i<=n+1;++i){
		vis[i]=1;
		dfs(i);
		vis[i]=0;
	}
}
int main() {
	cin>>n>>m;
	for(int i=1;i<=m;++i){
		cin>>a[i][0];
		for(int j=1;j<=a[i][0];++j)
			cin>>a[i][j];
	}
	for(int i=1;i<=m;++i)
		cin>>p[i];
	dfs(0);
	cout<<ans;
}


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

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

template<typename T>
T lcm(T a, T b) {
  return (a*b)/gcd(b%a, a);
}

ll PrimeFactorization(ll n) {
  ll ans = 0;
  if (n % 2 == 0) ans++;
  while (n % 2 == 0) n = n/2;

  for (int i = 3; i <= sqrt(n); i += 2) {
    if (n % i == 0) {
      ans++;
      while (n % i == 0) {
        n /= i;
      }
    }
  }
  if (n != 1) ans++;
  ans++; // 1の分を足す
  return ans;
}

void Print(ll n, unordered_map<ll, ll>& m) {
  cout << n << " = ";
  bool first = true;
  for (const auto& e : m) {
    rep(i, e.second) {
      if (!first) cout << " * ";
      cout << e.first;  
      first = false;
    }
  }
  cout << endl;
}

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

  ll a, b;
  cin >> a >> b;
  cout << PrimeFactorization(gcd(a, b)) << endl;
  return 0;
}



Measured memory_bytes: 256