akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

using Weight=long long;
static const Weight INF=1LL<<57;

struct Arc {
    // accessible to the reverse edge
    size_t src, dst;
    Weight capacity, flow;
    size_t rev;
    Arc() {}
    Arc(size_t src, size_t dst, Weight capacity):
        src(src), dst(dst), capacity(capacity), flow(0), rev(-1)
    {}
    Weight residue() const {
        return capacity - flow;
    }
};

using Arcs=vector<Arc>;
using Node=vector<Arc>;
using FlowNetwork=vector<Node>;

void connect(FlowNetwork &g, size_t s, size_t d, Weight c=1) {
    g[s].push_back(Arc(s, d, c));
    g[d].push_back(Arc(d, s, 0));

    g[s].back().rev = g[d].size()-1;
    g[d].back().rev = g[s].size()-1;
}

void join(FlowNetwork &g, size_t s, size_t d, Weight c=1) {
    g[s].push_back(Arc(s, d, c));
    g[d].push_back(Arc(d, s, c));

    g[s].back().rev = g[d].size()-1;
    g[d].back().rev = g[s].size()-1;
}

Weight augment(
        FlowNetwork &g, const vector<Weight> level, vector<bool> &finished,
        size_t u, size_t v, Weight cur
) {
    if (u == v) return cur;
    if (finished[u] || !cur) return 0;

    finished[u] = true;
    for (Arc &e: g[u])
        if (level[e.dst] > level[e.src]) {
            Weight f=augment(
                g, level, finished, e.dst, v, min(cur, e.residue())
            );
            if (f > 0) {
                e.flow += f;
                g[e.dst][e.rev].flow -= f;
                finished[u] = false;
                return f;
            }
        }

    return 0;
}

Weight max_flow(FlowNetwork &g, size_t s, size_t t) {
    /* Dinic */
    size_t V=g.size();

    Weight mflow=0;
    for (bool increased=true; increased;) {
        increased = false;
        vector<Weight> level(V, -1); level[s]=0;
        queue<size_t> q; q.push(s);
        for (Weight d=V; (!q.empty() && level[q.front()]<d);) {
            size_t u=q.front(); q.pop();
            if (u == t) d = level[u];

            for (Arc &e: g[u])
                if (e.residue()>0 && !~level[e.dst]) {
                    q.push(e.dst);
                    level[e.dst] = level[u] + 1;
                }
        }

        vector<bool> finished(V);
        for (Weight f=1; f>0;) {
            f = augment(g, level, finished, s, t, INF);
            if (!f) break;

            mflow += f;
            increased = true;
        }
    }
    return mflow;
}

int main() {
    size_t V, E;
    scanf("%zu %zu", &V, &E);

    FlowNetwork g(V);
    for (size_t i=0; i<E; ++i) {
        size_t u, v;
        Weight c;
        scanf("%zu %zu %lld", &u, &v, &c);

        connect(g, u, v, c);
    }

    printf("%lld\n", max_flow(g, 0, V-1));
    return 0;
}

Measured memory_bytes: 2864
#include <iostream>

using namespace std;

int main(){
  int N, ans=1;
  cin >> N;
  char S[N];
  for(int i=0; i<N; i++) cin >> S[i];
  for(int i=0; i<N-1; i++){
    if(S[i] != S[i+1]) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
n = int(input())
A = list(map(int,input().split()))
B = [0]*30
ans = []
for i in A:
    for j in range(30):
        if (i>>j) & 1:
            B[j] += 1
for i in A:
    C = [c for c in B]
    for j in range(30):
        if (i>>j) & 1:
            C[j] -= 1
    a = 0
    for j in range(30):
        if C[j]%2 == 1:
            a += 2**(j)
    ans.append(str(a))
print(" ".join(ans))

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

using namespace std;

struct DATA{
  int Number;
  int Count;
};

void Device(string, int&, int&);
int Atoi(const string);
void PushData(vector<DATA>&, int);
bool Compare(const DATA&, const DATA&);

int main(){
  int i, j, number, day;
  string str;
  DATA _Answer;
  vector<DATA> ThisMonth, LastMonth, Answer;

  while(1){
    getline(cin, str);
    if(str == "") break;
    Device(str, number, day);
    PushData(ThisMonth, number);
  }

  sort(ThisMonth.begin(), ThisMonth.end(), Compare);

  while(cin >> str){
    Device(str, number, day);
    PushData(LastMonth, number);
  }

  sort(LastMonth.begin(), LastMonth.end(), Compare);

  for(i=0; i<ThisMonth.size(); ++i){
    for(j=0; j<LastMonth.size(); ++j){
      if(ThisMonth[i].Number == LastMonth[j].Number){
	_Answer.Number = ThisMonth[i].Number;
	_Answer.Count = ThisMonth[i].Count + LastMonth[j].Count;
	Answer.push_back(_Answer);
	break;
      }else if(ThisMonth[i].Number < LastMonth[j].Number){
	break;
      }
    }
  }

  for(i=0; i<Answer.size(); ++i)
    cout << Answer[i].Number << " " << Answer[i].Count << endl;

  return 0;
}

void Device(string s, int& x, int& y){
  string s1, s2;
  string::iterator iter;

  iter = find(s.begin(), s.end(), ',');
  copy(s.begin(), iter, back_inserter(s1));
  copy(iter+1, s.end(), back_inserter(s2));

  x = Atoi(s1);
  y = Atoi(s2);
}

int Atoi(const string s){
  int i, x=0, digit=1;

  for(i = s.size()-1; i >= 0; --i){
    x = x + (s[i] - 48) * digit;
    digit *= 10;
  }
  return x;
}

void PushData(vector<DATA>& month, int x){
  int i, isFound=0;
  DATA data;

  for(i=0; i<month.size(); ++i){
    if(x == month[i].Number){
      isFound = 1;
      ++month[i].Count;
      break;
    }
  }

  if(isFound == 0){
    data.Number = x;
    data.Count = 1;
    month.push_back(data);
  }
}

bool Compare(const DATA& x, const DATA& y){
  return x.Number < y.Number;
}

Measured memory_bytes: 0
#include "iostream"

typedef long long ll;
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c, k;
    cin >> a >> b >> c >> k;

    if (k < a)
    {
        cout << k << endl;
    }
    else if (a <= k && k < a + b)
    {
        cout << a << endl;
    }
    else if (a + b <= k)
    {
        cout << a + (-1) * (k - (a + b)) << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <cmath>

int main(){
  	std::string s, t;
  	std::cin >> s >> t;
  	int x = stoi(s+t);
  	if(int(sqrt(x))*int(sqrt(x)) == x) std::cout << "Yes" << std::endl;
  	else std::cout << "No" << std::endl;
}


Measured memory_bytes: 3720
#include "bits/stdc++.h"
using namespace std;
bool eq(int a,int b,int c,int d,int e){
    set<int>k;
    k.insert(a);
    k.insert(b);
    k.insert(c);
    k.insert(d);
    k.insert(e);
    return k.size() < 5;
}
int main() {
    int ans = INT_MAX;
    vector<int>a(5);
    for(int i = 0;i<5;i++)cin >> a[i];
    for(int i = 0;i<5;i++){
        for(int j = 0;j<5;j++){
            for(int k = 0;k<5;k++){
                for(int z = 0;z<5;z++){
                    for(int m = 0;m< 5;m++){
                        if(eq(i,j,k,z,m))continue;
                        else{
                            int tmp = 0;
                            int add = a[i];
                            if(add % 10 != 0)add += 10 - add % 10;
                            tmp += add;
                            add = a[j];
                            if(add % 10 != 0)add += 10 - add % 10;
                            tmp += add;
                            add = a[k];
                            if(add % 10 != 0)add += 10 - add % 10;
                            tmp += add;
                            add = a[z];
                            if(add % 10 != 0)add += 10 - add % 10;
                            tmp += add;
                            add = a[m];
                            tmp += add;
                            if(tmp < ans)ans = tmp;
                        }
                    }
                }
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

unordered_map<ll,ll> dp[85];

int main(){
  int N;
  cin >> N;
  vector<int> v;
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(a);
  }

  dp[0][0] = 1000;

  rep(i,N){
    FOR(it,dp[i]){
      ll kabu = it->first;
      ll money = it->second;

      {
        dp[i+1][kabu] = max(dp[i+1][kabu], money);
      }
      {//kau
        ll cnt = money / v[i];
        ll remain = money % v[i];
        dp[i+1][kabu+cnt] = max(dp[i+1][kabu+cnt], remain);
      }
      {//uru
        dp[i+1][0] = max(dp[i+1][0], money + kabu * v[i]);
      }
    }
  }
  
  ll ret = 0;
  FOR(it,dp[N]){
    ret = max(ret, it->second);
  }

  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 3800
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
ll f[N] = {1};
ll in(ll a, ll b = M - 2)
{
    ll r = 1;
    while (b)
    {
        if (b % 2)
            r = (r * a) % M;
        a = (a * a) % M;
        b /= 2;
    }
    return r;
}
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    for (ll i = 1; i < N; i++)
        f[i] = (f[i - 1] * i) % M;
    ll x, y;
    cin >> x >> y;
    ll a = 2 * x - y;
    ll b = 2 * y - x;
    if (a < 0 || b < 0 || a % 3 || b % 3)
        return cout << 0, 0;
    a /= 3;
    b /= 3;
    cout << f[a + b] * in(f[a]) % M * in(f[b]) % M;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

void Main(){
    int N; cin >> N;
    VI x(N); REP(i,N) cin >> x[i];
    VI p(N); REP(i,N) p[i] = i;

    auto comp = [&](int i, int j){return x[i]<x[j];};
    sort(ALL(p), comp);

    VI a(N*N,-1);
    REP(i,N) a[x[i]-1] = i+1;

    int ptr = 0;
    for(int i : p){
        REP(_,i){
            while(ptr<N*N && a[ptr]!=i+1 && a[ptr]!=-1) ptr++;
            if(a[ptr]==i+1){
                cout << "No" << en;
                return;
            }
            else{
                a[ptr++] = i+1;
            }
        }
    }

    ptr = N*N-1;
    REVERSE(p);
    for(int i : p){
        REP(_,N-1-i){
            while(0<=ptr && a[ptr]!=i+1 && a[ptr]!=-1) ptr--;
            if(a[ptr]==i+1){
                cout << "No" << en;
                return;
            }
            else{
                a[ptr--] = i+1;
            }
        }
    }

    cout << "Yes" << en;
    REP(i,N*N) cout << a[i] << " ";
    return;
}

int main(void){
    cin.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t){
        Main();
    }
    return 0;
}

Measured memory_bytes: 2176
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
use std::f64::consts::PI;
fn main() {
    input!{
        a: f64,
        b: f64,
        x: f64,
    }
    println!("{:.10}", {
        if x <= a * a * b / 2.0 { 180.0 / PI * (a * b * b / 2.0 / x).atan() }
        else { 180.0 / PI * (2.0 * (a * a * b - x) / (a * a * a)).atan() }
    });
}


Measured memory_bytes: 4352
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class Atk
{
	public int Type { get; private set; }  // 0:A, 1:B
	public long Damage { get; private set; }

	public Atk(int type, long damage)
	{
		Type = type;
		Damage = damage;
	}
}


public class D
{
	public static void Main()
	{
		int Q = Int32.Parse(Console.ReadLine());
		int[] l = new int[Q];
		int[] r = new int[Q];
		for(int i = 0; i < Q; i++)
		{
			string[] args = Console.ReadLine().Split(' ');
			l[i] = Int32.Parse(args[0]);
			r[i] = Int32.Parse(args[1]);
		}	

		int maxN = 100000;
		bool[] isPrime = new bool[maxN + 1];
		for(int i = 2; i <= maxN; i++)
			isPrime[i] = true;
		for(int i = 2; i <= maxN; i++)
			if(isPrime[i])
				for(int j = 2 * i; j <= maxN; j += i)
					isPrime[j] = false;

		int[] csum = new int[maxN + 1];
		for(int i = 2; i <= maxN; i++)
		{
			csum[i] = csum[i-1];
			if(isPrime[i] && isPrime[(i + 1)/2])
				csum[i]++;
		}

		for(int i = 0; i < Q; i++)
			Console.WriteLine(csum[r[i]] - csum[l[i]-1]);
	}
}





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

int main() {
  int n, k, tmp = 1;
  cin >> n >> k;

  for (int i = 0; i < n; i++) {
    if (tmp + k <= tmp * 2) tmp += k;
    else tmp *= 2;
  }

  cout << tmp << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    int n, d, ans;
    cin >> n >> d;
    vector<vector<int>> data(n, vector<int>(d));
    rep(i, n){
        rep(j,d){
            cin >> data[i][j];
        }
    }

    ans = 0;
    for(int i = 0; i < n - 1; i++){
        for(int j = i + 1; j < n; j++){
            int p = 0;
            rep(k, d){
                p += pow(data[i][k] - data[j][k], 2.0);
            }
            double r = floor(sqrt(p));
            if(pow(r, 2.0) == p){
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, ll num=0){
  if(num == 0) num = (ll)v.size();
  cout << endl; cout << "i=  ";for(ll i=0; i<num; i++) cout << i << "   ";cout << endl;  
  cout << "    ";
  if(is_reverse) for(ll i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<"   ";}
  else for(ll i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<"   ";}
  cout << endl;
}

// template <typename T>
// void print_pairvec(const vector<T> &v, ll num=0){
//   if(num == 0) num = (ll)v.size();
//   cout << endl; for(ll i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
// }
template <typename T>
void print_pairvec(const T &_pair, ll num=0){
  cout << endl; for(pair<ll, int> x: _pair){ cout << x.first << " " << x.second << endl;}
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(ll i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(ll i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(ll j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

int f(int n){
  if(n%2 ==0) return n/2;
  else return 3*n + 1;
}
int main(){
  int s;
  cin >> s;
  map<int, int> mp;
  mp[s]++;
  int ans = 1;
  while(true){
    ans++;
    s = f(s);
    if(mp[s] != 0) break;
    mp[s]++;
  }
  cout << ans << endl;
  return 0;
  // cout << fixed;//小数点を確実に10桁で表示するためのもの
  // cout << setprecision(10); 
}


Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
int main() {
    string s;
    while (getline(cin, s) && s != ".") {
        string t;
        rep(i, s.size()) {
            if (s[i] == '[' || s[i] == ']' || s[i] == '(' || s[i] == ')') t += s[i];
        }
        if (t == "") {
            cout << "yes" << endl;
            continue;
        }
        //cout << t << endl;
        int table[t.size()];
        rep(i, t.size()) table[i] = 0;
        rep(i, t.size()) {
            //cout << t[i] << endl;
            if (t[i] == '[') table[i] = 1;
            else if (t[i] == ']') table[i] = 2;
            else if (t[i] == '(') table[i] = 3;
            else table[i] = 4;
        }
        /*
        rep(i, t.size()) cout << table[i] << " ";
        cout << endl;
        */
        int flg = 0;
        rep(i, t.size()) {
            if (t[i] == ')') {
                for (int j = i - 1; j >= 0; --j) {
                    if (table[j] == 3) {
                        table[j] = 0;
                        table[i] = 0;
                        break;
                    } else if (table[j] == 1){
                        cout << "no" << endl;
                        flg = 1;
                        break;
                    }
                    if (j == 0) {
                        cout << "no" << endl;
                        flg = 1;
                        break;
                    }
                }
            } else if (t[i] == ']') {
                for (int j = i - 1; j >= 0; --j) {
                    if (table[j] == 1) {
                        table[j] = 0;
                        table[i] = 0;
                        break;
                    } else if (table[j] == 3) {
                        cout << "no" << endl;
                        flg = 1;
                        break;
                    }
                    if (j == 0) {
                        cout << "no" << endl;
                        flg = 1;
                        break;
                    }
                }
                
            }
            if (flg) break;
            /*
            rep(i, t.size()) cout << table[i] << " ";
            cout << endl;
             */
        }
        if (flg == 0) {
            rep(i, t.size()) {
                if (table[i] > 0) {
                    cout << "no" << endl;
                    break;
                }
                if (i == t.size() - 1) cout << "yes" << endl;
            }
        }
    }
    
    
}



Measured memory_bytes: 3176
N=int(input())
ES = []
for i in range(N):
    x,l = list(map(int,input().split()))
    ES.append((x+l,x-l))
 
ES = sorted(ES)

sel = []
cur = None
ans = 0
for E,S in ES:
    if cur is None or cur <= S:
        sel.append((S,E))
        cur = E
        ans += 1
print(ans)



Measured memory_bytes: 60888
#include<stdio.h>
int main(){
int n,a[55],i,j,ans=0;
scanf("%d\n",&n);
  for(i=0;i<n;i++){
    scanf("%d\n",&a[i]);
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(i!=j){
        ans=ans+a[i]*a[j];
      }
    }
  }
  printf("%d\n",ans/2);
return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>

#define INF (1 << 29)

using namespace std;

int fix(int num)
{
    return min(255, max( num, 0) );
}

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

        vector<int> in_C(M);
        for(auto& _c : in_C)
        {
            cin >> _c;
        }

        vector<int> in_X(N);
        for(auto& _x : in_X)
        {
            cin >> _x;
        }

        int dp[2][256];
        for(int i = 0; i < 256; i++)
        {
            dp[0][i] = dp[1][i] = INF;
        }

        for(int i = 0; i < M; i++)
        {
            int sub = fix(128 + in_C[i]);
            dp[0][sub] = (in_X[0] - sub) * (in_X[0] - sub);
        }

        for(int n = 1; n < N; n++)
        {
            for(int i = 0; i < 256; i++)
            {
                if(dp[0][i] == INF)continue;
                for(int j = 0; j < M; j++)
                {
                    int sub = fix(i + in_C[j]);
                    int nextScore = dp[0][i] + (in_X[n] - sub) * (in_X[n] - sub);
                    dp[1][sub] = min(dp[1][sub], nextScore);
                    /*
                    cout << sub << endl;
                    cout << dp[0][sub] << endl;
                    cout << pow( in_X[n] - sub, 2.0 ) << endl;
                    cout << endl;
                    //*/
                }
            }
            for(int i = 0; i < 256; i++)
            {
                dp[0][i] = dp[1][i];
                dp[1][i] = INF;
            }
        }

        int ans = INF;
        for(int i = 0; i < 256; i++)
        {
            ans = min(ans, dp[0][i]);
        }
        cout << ans << endl;

    }



    return 0;
}

Measured memory_bytes: 3088
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define ll long long
using namespace std;

int main(){
	int n;
	cin >> n;
	int ans = 0;
	for(int i = 105; i <= n; i ++) {
		if(i&1) {
			int cnt = 0;
			for(int j = 1; j <= n; j ++) if(i%j==0) cnt++;
			if(cnt == 8) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
//#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

int main(){
    LL n;
    bool is_four=false;
    cin >> n;

    char s;
    for(LL i=0; i<n; i++){
        cin >> s;
        if(s=='Y'){
            is_four=true;
        }
    }

    if(is_four==true){
        cout << "Four" << endl;
    }else{
        cout << "Three" << endl;
    }

    return 0;
}


Measured memory_bytes: 3536
N = int(input())
A = input().split()
A = [int(x) for x in A]

c = 0 #交換回数
flag = 1
while flag:
    flag = 0
    j = N-1
    while j >= 1:
        if A[j] < A[j-1]:
            c +=1 
            v = A[j]
            A[j] = A[j-1]
            A[j-1] = v
            flag = 1
        j -=1

A = [str(x) for x in A]
print(" ".join(A))
print(c)


Measured memory_bytes: 5604
# -*- coding: utf-8 -*-
# 整数の入力
n = int(input())
# スペース区切りの整数の入力
ln_i = list(map(int, input().split()))
ln_j = list(map(int, input().split()))
sum_max = 0
for i in range(n):
    sum_max = max(sum_max, sum(ln_i[0:i+1]) + sum(ln_j[i:n]))

print(sum_max)


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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;
using ll = int64_t;

int main() {
    int N;
    cin >> N;
    int A;
    bool flg = true;
    REP (i, N) {
        cin >> A;
        if (!(A % 2) && A % 3 && A % 5) {
            flg = false;
            break;
        }
    }
    cout << (flg ? "APPROVED" : "DENIED") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF (1<<30);

int main() {
  int N, X, L[105];
  cin >> N >> X;
  rep(i, N) cin >> L[i];

  int ans = 0, xx = 0;
  rep(i, N) {
    ans++;
    xx += L[i];
    if (xx > X) break;
  }
  if (xx <= X) ans++;
  /*while (true) {
    ans++;
    xx += L[i];
    if (xx > X) break;
    i++;
    if (i >= N) break;
  }*/

  cout << ans << endl;

  return 0;
}

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b,c; cin>>a>>b>>c;
	cout << min({a+b,a+c,b+c}) << endl;
	return 0;
}


Measured memory_bytes: 256
n = gets.to_i
as = gets.chomp.split.map(&:to_i)
as.map!.with_index(1) do |a, i|
  a - i
end
as.sort!
b = as.size % 2 == 0 ? as[as.size / 2 - 1, 2].inject(:+) / 2.0 : as[as.size / 2]
as.map! do |a|
  (a - b).abs
end
puts as.inject(:+).to_i


Measured memory_bytes: 19456
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

map<ll,ll> pfact(ll n) {
  map<ll,ll> ret;
  while(n%2==0) {ret[2]++;n/=2;}
  for(ll i=3;i*i<=n;i+=2) while(n%i==0) {ret[i]++;n/=i;}
  if(n!=1) ret[n]=1;
  return ret;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,ans=0;cin>>n;
  map<ll,ll> mp=pfact(n);
  for(auto p:mp) {
    ll a=p.first,b=p.second,num=1;
    while(b-num>-1) {
      ll div=1;
      rep(i,num) div*=a;
      n/=a;
      ans++,b-=num,num++;
    }
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

    int N,M; cin >> N >> M;
    vi G[100010];
    rep(i,N){
        int a,b; cin >> a >> b;
        a--;
        G[a].eb(b);
    }
    priority_queue<int> p;
    int ans=0;
    rep(i,M){
        for(int a:G[i]){
            p.push(a);
        }
        if(p.size()){
            ans+=p.top();
            p.pop();
        }
    }
    cout << ans << endl;
}

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

int D, G;
//vector<int> p(D), c(D);
vector<int> p(20), c(20);

int ans = 1e9;

void rec(int sum, int counter, int i, vector<bool> D_bool) {
  if (i == D) {
    if (sum >= G) {
      ans = min(ans, counter);
    }
    else {
      int j = D - 1;
      rrep(k,D-1) {
        if (!D_bool.at(k)) {
          j = k;
          break;
        }
      }
      
      for (int l = 0; l < p.at(j)-1 && sum < G; l++) {
        sum += 100*(j+1);
        counter++;
      }
      
      if (sum >= G) ans = min(ans,counter);
    }
  }
  else {
    D_bool.at(i) = false;
    rec(sum, counter, i+1, D_bool);
    
    D_bool.at(i) = true;
    rep(j,p[i]) {
      sum += 100*(i+1);
      counter++;
    }
    sum += c.at(i);
    rec(sum, counter, i+1, D_bool);
  }
}

int main() {
  cin >> D >> G;
  rep(i,D) cin >> p.at(i) >> c.at(i);
  
  vector<bool> vec_bool(D, false);
  
  rec(0,0,0,vec_bool);
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
def solve():
    N, Q = map(int, input().split())
    S = input()
    
    t = [0] * (N+1)
    for i in range(N):
        t[i+1] = t[i] + (1 if S[i:i+2] == 'AC' else 0)
      
    for _ in range(Q):
        l, r = map(int, input().split())
        print(t[r-1]-t[l-1])
        
solve()

Measured memory_bytes: 7748
f = []
def precompute():
    f.append(1)
    for i in range(1,10**6+1):
        f.append((f[i-1]*i)%m)
def ncr(n,r):
    return f[n]*pow(f[n-r],m-2,m)*pow(f[r],m-2,m)
    
n,m = int(input()),int(1e9+7)
precompute()
x = pow(10,n,m)%m
y = pow(8,n,m)%m
z = 1
for i in range(1,n):
    z += ncr(n,i)*pow(8,n-i,m)
print((x-(y+z+z))%m)

Measured memory_bytes: 163292
#include <iostream>
#include <string>

using namespace std;

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

    int d1 = N / 100;
    int d2 = (N - d1 * 100) / 10;
    int d3 = (N - d1 * 100 - d2 * 10);

    if (d1 != 7 && d2 != 7 && d3 != 7) {
        cout << "No";
    } else {
        cout << "Yes";
    }

    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long int;
using ull = unsigned long long int;
using P = pair<int, int>;
using P3 = pair<double,P>;
using PP = pair<P ,P>;
constexpr ll MOD = 998244353;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e6) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    vector<int> t(n);
    for(int i=0;i<n;i++){
        cin >> s[i] >> t[i];
    }
    string x;
    cin >> x;
    int id = 0, ans = 0;
    for(int i=0;i<n;i++){
        if(s[i] == x) id = i+1;
    }
    for(int i=id; i<n;i++){
        ans += t[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
  int d,x,y,xmax,ymax,xx,yy;
  scanf("%d",&d);
  scanf("%d",&x);
  scanf("%d",&y);
  scanf("%d",&xmax);
  scanf("%d",&ymax);
  xx=x/xmax;
  yy=y/ymax;
  if(x%xmax!=0)
    xx=xx+1;
  if(y%ymax!=0)
    yy=yy+1;
  if(xx>yy)
    printf("%d\n",d-xx);
  else if(xx<yy)
    printf("%d\n",d-yy);
  else
    printf("%d\n",d-yy);
  return 0;
}

Measured memory_bytes: 596
#include <iostream>

auto CalculateState(const std::string& s, std::uint64_t i) {
    auto result = std::uint64_t(0);
    auto target = static_cast<std::uint64_t>(s[0] - '0');

    for (auto j = std::size_t(1); j < s.length(); ++j) {
        if (i % 2 == 0) {
            target = target * 10 + static_cast<std::uint64_t>(s[j] - '0');
        } else {
            result += target;
            target = static_cast<std::uint64_t>(s[j] - '0');
        }

        i /= 2;
    }

    result += target;

    return result;
}

int main() {
    auto s = std::string();
    std::cin >> s;

    auto sum = std::uint64_t(0);

    for (auto i = std::size_t(0); i < (1 << (s.length() - 1)); ++i) {
        sum += CalculateState(s, i);
    }

    std::cout << sum << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main(){
        int i,n,j,ans=0,u,v,mn,mx,k1,k2;
        cin>>n;
        for(i=1;i<=n;i++){
            ans+=(i*(i+1))/2;
        }
        for(i=1;i<n;i++){
            cin>>u>>v;
            mn=min(u,v);
            mx=max(u,v);
            k1=n-mx;
            k2=mn-1;
            k1++;
            k2++;
            ans-=(k1*k2);
        }
        cout<<ans;
    return 0;
}

Measured memory_bytes: 3632
l,r = map(int, input().split())
ans = 10**10

for i in range(l,r):
    for j in range(i+1,r+1):
        a = (i*j) % 2019
        if a == 0:
            print(0)
            exit()
        elif a < ans:
            ans = a
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <climits>
#include <map>
#include <queue>

#define ll long long int
#define mod 1000000007

using namespace std;

map<int, int> m;

void bfs(int start, vector<vector<int>>& vec){
    queue<int> q;
    int n = vec.size();
    vector<bool> b(n,false);
    int cnt = 1;
    q.push(start);
    b[start] = true;
    vector<int>level(n+1);
    while(q.size() != 0){
        int top = q.front();
        bool x = false;
    for(int i = 0; i < vec[top].size(); i++){
        if(b[vec[top][i]] == false){
        q.push(vec[top][i]);
        b[vec[top][i]] = true;
        level[vec[top][i]] = level[top] + 1;
    }
    }
    q.pop();
    }
    for(int i:level)
    m[i]++;
}

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int n, x, y;
    cin >> n >> x >> y;
    
    vector<vector<int>> vec(n+1);
    vec[0].push_back(0);
    vec[1].push_back(2);
    for(int i = 2; i <= n-1; i++){
        
        vec[i].push_back(i+1);
        vec[i].push_back(i-1);
    }
    vec[n].push_back(n-1);
    vec[x].push_back(y);
    vec[y].push_back(x);
    
    
    for(int i = 1; i <=n; i++){
        bfs(i,vec);
    }
    for(int i = 1; i < m.size(); i++){
        cout << m[i]/2 << '\n';
    }
    for(int i = m.size(); i < n;i++)
    cout << 0 << '\n';
}









Measured memory_bytes: 512
//OPTIMIZATIONS
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
//#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN NEEDED)
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//OPTIMIZATIONS
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long uu;
typedef long long int lll;
typedef unsigned long long int uuu;
using namespace std;

#define watch(x) cerr << "\n" \
					  << (#x) << " is " << (x) << endl
#define cel(x, y) 1 + ((x - 1) / y)
const double PI = 3.141592653589793238463;
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f;

/*
$alil03

URL: url

Solution Begins here
*/

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int a, b;
	cin >> a >> b;
	if (a == 1 && b == 2)
	{
		cout << 3;
	}
	else if (a == 2 && b == 1)
	{
		cout << 3;
	}
	else if (a == 2 && b == 3)
	{
		cout << 1;
	}
	else if (a == 3 && b == 2)
	{
		cout << 1;
	}
	else if (a == 1 && b == 3)
	{
		cout << 2;
	}
	else if (a == 3 && b == 1)
	{
		cout << 2;
	}
}

Measured memory_bytes: 256
char a[],R[99];h,b;main(i){for(;scanf("%s%s",R,a)*R[1];h=!printf("%d %d\n",h,b/2-h)){for(b=4;b--;h+=R[b]==a[b])R[R[b]]++,R[a[b]]--;for(i=47;++i<58;R[i]=0)b+=!R[i];}}

Measured memory_bytes: 0
package main

import (
	"fmt"
)

func findHintMatchIndex(idx int, sp, t string) int {
	for i := idx; i <= (len(sp) - len(t)); i++ {
		match := true
		for j := 0; j < len(t); j++ {
			if sp[i+j] != '?' && sp[i+j] != t[j] {
				match = false
				break
			}
		}

		if match {
			return i
		}
	}
	return -1
}

func main() {
	var sp, t string
	fmt.Scan(&sp)
	fmt.Scan(&t)

	secrets := make([]string, 0)
	i := 0
	for i+len(t) <= len(sp) {
		mi := findHintMatchIndex(i, sp, t)
		if mi == -1 {
			i++
			continue
		}
		i = mi + 1

		tmp := []byte(sp)
		// replace "?" to hint string
		for i := 0; i < len(t); i++ {
			tmp[mi+i] = t[i]
		}
		for i := 0; i < len(tmp); i++ {
			if tmp[i] == '?' {
				tmp[i] = 'a'
			}
		}
		secrets = append(secrets, string(tmp))
	}
	if len(secrets) == 0 {
		fmt.Println("UNRESTORABLE")
		return
	}

	ans := secrets[0]
	for i := 1; i < len(secrets); i++ {
		if ans > secrets[i] {
			ans = secrets[i]
		}
	}
	fmt.Println(ans)
}


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

int main()
{
	int a, b, c;
	int yakusuu = 0;
	cin >> a >> b >> c;
	for (int i = a; i <= b; i++)
	{
		if (c % i == 0) yakusuu++;
	}
	cout << yakusuu << endl;
	return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <iomanip>
#include <math.h>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<long double> x(n);
	vector<long double> y(n);

	cout << setprecision(10);
	for (int i = 0; i < n; i++)
	{
		cin >> x[i] >> y[i];
	}
	long double min_of_max = 10e15;
	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			{
				//二点の中点を求める
				long double ux, uy;
				ux = (x[i] + x[j]) / 2;
				uy = (y[i] + y[j]) / 2;

				//各点への距離の最大を求める
				long double max = 0;
				for (int v = 0; v < n; v++)
				{
					long double d = sqrt((x[v] - ux) * (x[v] - ux) + (y[v] - uy) * (y[v] - uy));
					if (max < d)
						max = d;
				}
				if (max < min_of_max)
					min_of_max = max;
			}

			for (int k = j + 1; k < n; k++)
			{
				long double a = (x[j] - x[i]) * (x[j] - x[i]) + (y[j] - y[i]) * (y[j] - y[i]); //kの対辺の長さの二乗
				long double b = (x[k] - x[i]) * (x[k] - x[i]) + (y[k] - y[i]) * (y[k] - y[i]); //jの対辺の長さの二乗
				long double c = (x[j] - x[k]) * (x[j] - x[k]) + (y[j] - y[k]) * (y[j] - y[k]); //iの対辺の長さの二乗

				long double ux, uy;

				if (a * (b + c - a) + b * (c + a - b) + c * (a + b - c) == 0) //3点が同一直線上
					continue;

				//正規直交基底として外心の座標を成分ごとに計算
				ux = (a * (b + c - a) * x[k] + b * (c + a - b) * x[j] + c * (a + b - c) * x[i]) / (a * (b + c - a) + b * (c + a - b) + c * (a + b - c));
				uy = (a * (b + c - a) * y[k] + b * (c + a - b) * y[j] + c * (a + b - c) * y[i]) / (a * (b + c - a) + b * (c + a - b) + c * (a + b - c));
				
				//各点への距離の最大を求める
				long double max = 0;
				for (int v = 0; v < n; v++)
				{
					long double d = sqrt((x[v] - ux) * (x[v] - ux) + (y[v] - uy) * (y[v] - uy));
					if (max < d)
						max = d;
				}
				if (max < min_of_max)
					min_of_max = max;
			}
		}
	}
	cout << min_of_max << endl;
}

Measured memory_bytes: 256
#pragma region
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define vi vector<int>
#define vd vector<double>
#define vs vector<string>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m-1);i>=(int)(n);i--)
#define rev(i, n) revi(i, n, 0)
#define each(i, n) for(auto&& i: n)
#define sz(v) ((int)(v).size()) 
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define dump(x) cerr << #x << " = " << x << endl
#define gcd __gcd
int lcm(int a, int b){return a / gcd(a, b) * b;}
const int INF = 1e18;
const int MOD = 1e9 + 7;
const double EPS = 1e-15;
const double PI = acos(-1);
int dig(int n){return (int)(log10(n) + 1);}
int abc(char x){return (int)(x)-(int)('a');} // 0~25
char abc(int x){return (char)(x+(int)('a'));} 
int ABC(char x){return (int)(x)-(int)('A');}
char ABC(int x){return (char)(x+(int)('A'));}
void solve();
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	solve();
}
#pragma endregion

void solve() {
	int K, X; cin >> K >> X;
	repi(i, X - K + 1, X + K) {
		cout << i << ' ';
	}
	cout << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		try (Scanner sc = new Scanner(System.in)) {
			int h = sc.nextInt();
			int n = sc.nextInt();
			int i = 0;
			while (h > 0 && i++ < n) {
				h -= sc.nextInt();
			}
			if (h > 0) {
				System.out.println("No");
			} else {
				System.out.println("Yes");
			}
		}
	}
}


Measured memory_bytes: 48136
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    for(int i = 1; i <= 3; i++){
      if(i != a && i != b){
        System.out.println(i);
      }
    }
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
  int i ,j ,n ,m ,hit=0 ,blow=0;
  char a[5] ,r[5];
  while( 1 ){
    cin >> a;
    cin >> r;

    if( a[0] == '0' && r[0] == '0' ){
      break;
    }

    for( i=0 ; i<4 ; i++ ){
      for( j=0 ; j<4 ; j++ ){
	if( a[i] == r[j] ){
	  
	  if( i == j ){
	    hit++;
	  }
	  else{
	    blow++;
	  }
	}
      }
     
    }
      
    printf( "%d %d\n" ,hit ,blow );
    hit = 0;
    blow = 0;
  }
  
  return 0;
}

Measured memory_bytes: 1124
#include<stdio.h>
#include<stdlib.h>
typedef long long int lli;

typedef char bool;
typedef int item;
typedef struct _cell
{
  item car;
  struct _cell *cdr;
} cell;
#define NULL_ITEM 0;

cell* make_cell(item val);
void delete_cell(cell* cp);
cell* cons(item val,cell* cp,bool *err);
item pop(cell** cpp, bool *err);


int main (void){
  int n,m;
  scanf("%d %d",&n,&m);
  int comp[n+1],i,num[n];
  for(i=0;i<=n;i++)comp[i]=i;
  for(i=0;i<=n;i++)num[i]=1;
  lli inconv[m+1];
  inconv[m]=(lli)(n-1)*n/2;
  int u,v,ru,rv,w,j;
  cell* temp=NULL;
  bool err;
  item old;
  int edge1[m],edge2[m];
  for(i=0;i<m;i++)
    scanf("%d %d",&edge1[i],&edge2[i]);
  
  //  printf("\n");
  //  for(i=0;i<m;i++) printf("%d: %d %d\n",i,edge1[i],edge2[i]);
  for(i=m-1;i>=0;i--){
    inconv[i]=inconv[i+1];
    //        printf("%d inconv %d\n",i,inconv[i],edge2[i]);
    u=edge1[i];v=edge2[i];
    //        printf("u:%d v:%d\n",u,v);
    while(comp[u]!=u){
      temp=cons(u,temp,&err);
      u=comp[u];
    }
    //        printf("done: u.\n");
    //        printf("done: re u.\n");
    while(comp[v]!=v){
      temp=cons(v,temp,&err);
      v=comp[v];
      //            printf("v:%d\n",v);
    }
    //        printf("done: v.\n");
    //        printf("done: re v.\n");
    w=(num[u]>num[v])?u:v;
    if(comp[u]!=comp[v]){
      inconv[i]-=num[u]*num[v];
      num[w]=num[u]+num[v];
    }
    temp=cons(u+v-w,temp,&err);
    while(temp!=NULL){
      old=pop(&temp,&err);
      comp[old]=w;
    }

    /*
    for(j=1;j<=n;j++)
      printf("%2d",comp[j]);
    printf(":comp. edge(%d,%d):\n",edge1[i],edge2[i]);
    for(j=1;j<=n;j++)
      printf("%2d",num[j]);
      printf(":num. inconv=%d \n\n",inconv[i]);
    */
  }

  for(i=1;i<=m;i++)
    printf("%ld\n",inconv[i]);
  
  return 0;
}


cell* make_cell(item val)
{
  cell* ncellp=malloc(sizeof(cell));
  if(ncellp!=NULL)
    {
      ncellp->car=val;
      ncellp->cdr=NULL;
    }
  else
    printf("not enough memory.\n");
  return ncellp;
}


void delete_cell(cell* cp)
{
  cell* temp=cp,*next;
  while(temp!=NULL)
    {
      next=temp->cdr;
      free(temp);
      temp=next;
    }
}

cell* cons(item val,cell* cp,bool *err)
{
  cell* top=make_cell(val);
  if(top!=NULL)
    {
      *err=1;
      top->cdr=cp;
      return top;
    }
  *err=0;
  return cp;
}

item pop(cell** cpp, bool *err)
{
  if(*cpp==NULL)
    {
      *err=0;
      printf("nil.\n");
      return NULL_ITEM;
    }

  item it=(*cpp)->car;
  cell* temp=(*cpp)->cdr;
  *err=1;
  free(*cpp);
  *cpp=temp;
  return it;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string S;
    cin >> N >> S;
    vector<int> a(N), b(N-1);
    bool one = false;
    REP(i,N){
        a[i] = S[i] - '0';
        if(i > 0){
            b[i-1] = abs(a[i] - a[i-1]);
            if(b[i-1] & 1) one = true;
        }
    }
    if(!one) REP(i, N-1) b[i] /= 2;
    
    int ans = 0;
    REP(i,N-1){
        // _(n-2)C_i
        if(b[i] == 1 && ((N-2) & i) == i) ans ^= 1;
    }
    if(!one) ans *= 2;
    cout << ans << endl;
}


Measured memory_bytes: 9244
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String[] tenki = {"Sunny", "Cloudy", "Rainy" };
    String s = sc.next();
    int t = 0;
    for(int i = 0; i < tenki.length;i++){
      if(tenki[i].equals(s)){
        t = (i + 1) % 3;
      }
    }

    System.out.println(tenki[t]);
  }
}


Measured memory_bytes: 21972
/*input
30 4 
*/
#include<bits/stdc++.h>
using namespace std;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int fast_ex(int a,int n,int m){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= fast_ex(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int n,d;
string s;
int memo[10001][2][201];

int rec(int ind,bool pref,int sum){
     if(ind == n)return (sum%d == 0);
     if(memo[ind][pref][sum] != -1)return memo[ind][pref][sum];
     int res = 0;
     int till = 9;
     if(pref)till = s[ind]-'0';
     for(int i= 0;i <= till;i++){
        int sums = sum+i;
        sums %= d;
        res += rec(ind+1,pref&(i == till),sums);
        res %= MOD;
     }
     return memo[ind][pref][sum]=res;
}


void solve(){
    REP(i,10001){
      REP(j,2){
        REP(k,201){
          memo[i][j][k] = -1; 
        }
      }
    }
    cin >> s >> d;
    n = s.size();
    int ans = rec(0,1,0);
    ans--;
    ans %= MOD;
    if(ans < 0)ans += MOD;
    cout << ans;
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;//cin >> t;
  WL(t)solve();
  return 0;
}

Measured memory_bytes: 32512