akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) (((n) * ((n) + 1)) / 2)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
constexpr int MOD = 1e9 + 7;
//} END

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

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

  if (b % a == 0)
    cout << a + b << '\n';
  else
    cout << b - a << '\n';
  return 0;
}

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


class Program
{


    static void Main(string[] args)
    {
        Solve();
    }

    static void Solve()
    {
        Scan sc = new Scan();
        write wr = new write();

        var s=sc.intarr;
        int a = s[0];
        int b = s[1];
        wr.wri(Math.Max(Math.Max(a + b, a - b), a * b));
    }


}
    class Scan
    {
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
        public char[] chararr => str.ToArray();


}



class write
{
    public void wri<Type>(Type x)
    {
        Console.WriteLine(x);
    }
}


Measured memory_bytes: 13268
using System;
namespace aizu2
{
    class Program2
    {
        static void Main(string[] args)
        {
            double time = double.Parse(Console.ReadLine());
            double hour = Math.Floor(time / 3600);
            double minute = Math.Floor((time % 3600) / 60);
            double second = Math.Floor((time % 3600) % 60);
            
            Console.WriteLine(hour + ":" + minute + ":" + second);
          
        }
    }
}


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

int main(){
  int n;
  cin >> n;
  vector<int> mou(n);
  for(int i=0; i<n; ++i){
    cin >> mou.at(i);
  }
  //以上入力
  //以下はans[0]÷2について二分探索をし、適切かどうかを調べる。適切な場合同時に答えを求める。
  int l=-1, r=min(mou[0], mou[n-1])+1;
  vector<int> ans(n);
  while(l<r-1){
    int mid = (l+r)/2;
    ans[0] = mid;
    bool bad=false;
    //cout << l << " " << r << endl;
    for(int j=1; j<=n; ++j){
      int x = mou[j-1] - ans[j-1];
      if(j==n) x -= ans[0];
      if(x<0){
        //cout << "false" << endl;
        if(j%2) r=mid;
        else l=mid;
        bad = true;
        break;
      }
      if(j==n && ans[0]+ans[n-1] != mou[n-1]){
        l=mid;
        bad = true;
        break;
      }
      ans[j] = x;
    }
    if(!bad) break;
  }
  //以下答え出力
  for(int i=0; i<n; ++i){
    cout << ans.at(i)*2 << " ";
  }
  cout << endl;
}

Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits.h>

using namespace std;

void out(int* a, int n)
{
    for(int i=0; i<n; i++){
        cout << a[i];
        if(i != n-1) cout << " ";
    }
    cout << endl;
}
int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    //out(a, n);

    int cnt = 0;
    for(int i=0; i<n; i++){
        //cout << "---" << endl;
        int min = a[i];
        int min_index = i;
        for(int j=i+1; j<n; j++){
            if(a[min_index] > a[j]){
                min_index = j;
            }
        }
        if(min_index != i){
            int tmp = a[i];
            a[i] = a[min_index];
            a[min_index] = tmp;
            cnt++;
            //out(a, n);
        }
    }
    
    out(a, n);
    cout << cnt << endl;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define ll long long
#define loop(i,a,b) for(int i=a;i<b;i++)
#define pb(x) push_back(x)
#define F first
#define S second
#define mp(x,y) make_pair(x,y)
using namespace std;


void solve(){ 
            int h1,h2,m1,m2,k;
            cin>>h1>>m1>>h2>>m2>>k;
            int ans=(h2-h1)*60 +(m2-m1);
            if(ans-k<0) cout<<0<<endl;
            else cout<<ans-k<<endl;
  	
	
	
	
	
	
	
	
	
	
	
}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//	freopen("input.txt","r",stdin);
	int t=1;
//	t=1;
//	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}






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

using namespace std;

int main() {
    cin.tie(0), ios::sync_with_stdio(0);
    
    long long int num=10e8+7;
    int t;
    while(cin>>t){
        vector<long long> v;
        while(t--){
            long long tmp;
            cin>>tmp;
            v.push_back(tmp);
        }
        long long sum=0;
        vector<long long> pre;
        long long rec=0;
        for(int i=1;i<v.size();i++){
            rec+=v[i];
        }
        for(int i=1;i<v.size();i++){
            pre.push_back(rec);
            rec-=v[i];
        }
        for(int i=0;i<v.size()-1;i++){
            long long tmp=(v[i]%num)*(pre[i]%num);
            tmp%=num;
            sum+=tmp;
        }
        sum=sum%num;
        cout<<sum<<endl;
    }   
    
    return 0;
}

Measured memory_bytes: 7964
#include<bits/stdc++.h>
using namespace std;
long double X[200100];
int N;
long long Count(long double len)
{
  long long Ans=0;
  for(int i=0;i<N;i++)
  {
    Ans+=(long long)(X[i]/len);//解答引っ張ってきた人の条件。なぜか通る
    //Ans+= ceil(X[i]/len)-1;//多少遅くなるがこっちが正解
  }
  return Ans;
}

int main()
	{
	  long long K;
	  cin>>N>>K;
	  for(int i=0;i<N;i++)
	{
		cin>>X[i];
		//X[i]-=0.1;
	}

  long double l=1,r=1e9;
  //while(l<r-0.1)//解答を引っ張ってきた人の条件。なぜかOKだったが、lとｒの整数部が異なる状態でループを出ると問題になるはず
	for(int i=0;i<35;i++)//OK log2(10^9)=30.二分探索だとこのやり方安定する。ただし、浮動小数のせいか34以上でないと通らず。
  //while(!((ceil(r)-ceil(l)) == 0))//NG:左端が初期値0のままだと、右端のceilは0にならず、無限ループ
	//while(!((floor(r)-floor(l)) == 0))//OK:右端がぴったり整数にならなければ成立.(あまりよくない)
  {
    long double mid=(l+r)/2;
    if(Count(mid)<=K) r=mid;
    else	l=mid;
  }
  cout<<(long long)(l+0.999)<<endl;
  return 0;
}


Measured memory_bytes: 6824
n = gets.chomp.to_i
tt = gets.chomp.split(" ").map(&:to_i)
aa = gets.chomp.split(" ").map(&:to_i)
htt = Array.new(n, nil)
tt.each_with_index do |e, i|
  if i == 0 || tt[i-1] < e then  
    htt[i] = e
  end
end
haa = Array.new(n, nil)
aa.each_with_index do |e, i|
  if i == (n - 1) || aa[i + 1] < e then
    haa[i] = e
  end
end
ret = 1
tt.zip(aa).each_with_index do |e, i|
  if haa[i] && e[0] < haa[i] then
    puts 0; exit
  elsif htt[i] && e[1] < htt[i] then
    puts 0; exit
  elsif htt[i] || haa[i] then
    next
  end
  ret *= e.min
  ret %= (10**9 + 7)
end
puts ret

Measured memory_bytes: 24108
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <functional>

using namespace std;

struct St{
  int x, y, cst;

  St() {}
  St(int _x, int _y, int _cst): x(_x), y(_y), cst(_cst) {}

  bool operator>(const St& st) const{
    return cst > st.cst;
  }

  bool operator<(const St& st) const{
    return cst < st.cst;
  }
};

int h, w;
bool a[31][31][31][31];
int xdir[4] = {0, 1, 0, -1}, ydir[4] = {-1, 0, 1, 0};

int bfs()
{
  bool vis[31][31];
  priority_queue<St, vector<St>, greater<St> > que;
  que.push(St(0, 0, 1));
  fill(&vis[0][0], &vis[31][0], true);
  vis[0][0] = false;

  while(!que.empty()){
    St st = que.top();
    que.pop();

    if(st.x == w-1 && st.y == h-1) return st.cst;

    for(int i = 0; i < 4; ++i){
      int dx = st.x+xdir[i], dy = st.y+ydir[i];
      if(0 <= dx && dx < w && 0 <= dy && dy < h && vis[dy][dx] && a[dy][dx][st.y][st.x]){
	vis[dy][dx] = false;
	que.push(St(dx, dy, st.cst+1));
      }
    }
  }

  return 0;
}

int main()
{
  int s, t;

  while(cin>>w>>h && w+h){
    fill(&a[0][0][0][0], &a[31][0][0][0], false);
    t = 0;
    for(int i = 0; i < 2*h-1; ++i){
      if(i%2 == 0){
	for(int j = 0; j < w-1; ++j){
	  cin >> s;
	  a[t][j][t][j+1] = a[t][j+1][t][j] = (s == 0);
	}
      } else {
	for(int j = 0; j < w; ++j){
	  cin >> s;
	  a[t][j][t+1][j] = a[t+1][j][t][j] = (s == 0);
	}
	++t;
      }
    }

    cout << bfs() << endl;
  }

  return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int main()
{
	string s;
	cin >> s;
	int cnt1 = 0, cnt0 = 0;
	for (int i = 0; i < s.length(); i++)
	{
		if (s[i] == '0') cnt0++;
		else cnt1++;
	}
	cout << min(cnt0, cnt1) * 2 << endl;
	return 0;
}

Measured memory_bytes: 512
import sys,collections,math,random;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

a,b = Is()
ans = 0
if 6 <= a <= 12:
    ans = b//2
elif 12 < a:
    ans = b
print(ans)

Measured memory_bytes: 5732
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>



#define int long long
#define pb(n) push_back(n)
#define Rap(n,i) for(int (i)=0;(i)<(n);(i)++)
#define Pr(n) cout<<n<<endl;
#define F first
#define S second
#define Vector1  vector<int>
#define vector2 vector<vector<int> >
#define index(v,x) find((v).begin(), (v).end(), (x))-(v).begin()
#define ctoi(c) (int)(c-'0')
#define incin(n) int (n); cin>>(n);
#define stcin(s) string (s); cin>>(s);
#define all(v) (v).begin() , (v).end()
#define PI 3.14
#define Rad2Deg  57.29578

using namespace std;

signed  main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    incin(n);
    incin(k);
    Vector1 h(n);
    Rap(n,i){
        cin >> h.at(i);
    }
    int count = 0;
    Rap(n,i){
        if(h[i]>=k){
            count++;
        }
    }
    Pr(count);
    return 0;
}


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

int main() {
    int A,B,C,K;
    cin >> A >> B >> C >> K;
    for (int i=K; i>0; i--) {
        if (A>=B) {
            B = B*2;
        }
        else if (B>=C) C = C*2;
        else {
            cout << "Yes";
            return 0;
        }
    }
    if (A<B && B<C) cout << "Yes";
    else cout << "No";
}

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

using namespace std;


int main()
{
    string str;
    int count_0 = 0, count_1 = 0, count = 0;
    bool take;
    take = false;
    cin >> str;

    if (str[0] == '0') {
        count_0++;
    } else {
        count_1++;
    }
    for (int i = 1; i < (int)str.length(); i++) {
        if (str[i] == '0') {
           count_0 += 1;
           if (take) {
               if (count_1 > 0) {
                    count += 2;
                    count_1 -= 1;
                    count_0 -= 1;
               } else {
                   take = false;
               }
           } else if (str[i-1] == '1') {
                count += 2;
                count_0--;
                count_1--;
                take = true;
            } else {
                take = false;
            }
        } else {
            count_1 += 1;
            if (take) {
                if (count_0 > 0) {
                    count += 2;
                    count_1 -= 1;
                    count_0 -= 1;
                } else {
                    take = false;
                }
           } else if (str[i-1] == '0') {
                   count += 2;
                   count_0--;
                   count_1--;
                   take = true;
            }  else {
                take = false;
            }
        }
    }

    cout << count << endl;
 
 return 0;   
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <climits>
#include <cassert>

using namespace std;
typedef unsigned int index;

class Exec
{
private:
	size_t n;
	vector<int> a;

public:
	Exec(){}

	void main()
	{
		vector<vector<vector<int>>> d(n, vector<vector<int>>(2, vector<int>(n)));
		vector<int> mx(n);
		vector<int> mn(n);
		for (index i = (index)n - 1; i != (index)-1; i--)
		{
			for (index j = (index)n - 1; j != i; j--)
			{
				if (j == n - 1)
				{
					d[i][0][j] = abs(a[i] - a[j]);
					d[i][1][j] = abs(a[i] - a[j]);
				}
				else
				{
					d[i][0][j] = mx[j];
					d[i][1][j] = mn[j];
				}
			}
			mx[i] = INT_MIN / 2;
			mn[i] = INT_MAX / 2;
			for (index j = i + 1; j < n; j++)
			{
				mx[i] = max(mx[i], d[i][1][j]);
				mn[i] = min(mn[i], d[i][0][j]);
			}
		}
		cout << d[0][0][1] << endl;
	}

	void read()
	{
		cin >> n;
		n += 2;
		a.resize(n);
		for (auto &i: a)
		{
			cin >> i;
		}
	}
};

int main()
{
#ifdef ONPC
	assert(freopen("a.in", "r", stdin));
	assert(freopen("a.out", "w", stdout));
#else
#endif
	Exec a;
	a.read();
	a.main();
}


Measured memory_bytes: 31744
#include<bits/stdc++.h>
#include<vector>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define rep(i,N) for(int i=0;i<N;i++)
#define MOD 1000000007

using namespace std;

int main(void){
    int N;
    double ans=0;
    cin>>N;
    V<double> v(N);
    rep(i,N)cin>>v[i];
    sort(v.begin(),v.end());
    ans=(double)(v[0]+v[1])/2;
    for(int i=2;i<N;i++){
        double xx=ans+v[i];
        ans=xx/2.0;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<vector>

using namespace std;

#define REP(i, n) for(int i=0; i<n; i++)

typedef pair<pair<int, int>, pair<int, int> > pii; // cost, from, x, y

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

int INF = 10e8;
int w, h;
int map[30][30][4];
int cmap[30][30][4];
int c[4];

int main(){
    while(1){
        cin >> w >> h;
        if(w==0) break;

        REP(i, h) REP(j, w) REP(k, 4) map[i][j][k] = INF;
        REP(i, h){
            REP(j, w){
                int s;
                cin >> s;
                if(s<=3){
                    map[i][j][s] = 0;
                }
            }
        }

        REP(i, 4) cin >> c[i];
        REP(i, h) REP(j, w) REP(k, 4) map[i][j][k] = min(map[i][j][k], c[k]);

        REP(i, h) REP(j, w) REP(k, 4) cmap[i][j][k] = INF;
        cmap[0][0][1] = 0;
        priority_queue<pii, vector<pii>, greater<pii> > que;
        que.push(pii(make_pair(0, 1), make_pair(0, 0)));
        while(!que.empty()){
            pii p = que.top();
            que.pop();
            int cost = p.first.first;
            int from = p.first.second;
            int x = p.second.first;
            int y = p.second.second;
            REP(i, 4){
                int nx = x+dx[(i+from)%4];
                int ny = y+dy[(i+from)%4];
                if(nx>=0 && ny>=0 && nx<w && ny<h){
                    if(cmap[ny][nx][(i+from)%4] > map[y][x][i] + cost){
                        cmap[ny][nx][(i+from)%4] = map[y][x][i] + cost;
                        que.push(pii(make_pair(cmap[ny][nx][(i+from)%4], (i+from)%4), make_pair(nx, ny)));
                    }
                }
            }
        }

        /*
        REP(i, h){
            REP(j, w){
                int out = INF;
                REP(k, 4) out = min(cmap[i][j][k], out);
                cout << out;
            }
            cout << endl;
        }
        */

        int output = INF;
        REP(i, 4) output  = min(output, cmap[h-1][w-1][i]);
        cout << output << endl;
    }
}

Measured memory_bytes: 3224
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct edge{
	int u, v;
	double dis;
};
bool operator<(const edge& left, const edge& right){
	return left.dis > right.dis;
}

struct uf{
	int par, rank;
};

vector<pair<double, double>> pails;
vector<edge> ve;
int main() {
	int n, m;
	cin >> n >> m;
	pails.resize(n);
	ve.resize(m);
	REP(i, n){
		cin >> pails[i].first >> pails[i].second;
	}
	REP(i, m){
		int u, v;
		cin >> u >> v;
		ve[i].u = u - 1;
		ve[i].v = v - 1;
		ve[i].dis = hypot(pails[ve[i].u].first - pails[ve[i].v].first, pails[ve[i].u].second - pails[ve[i].v].second);
	}
	SORT(ve);
	double ans = 0.0;
	vector<uf> U(n);
	REP(i, n){
		U[i].par = i;
		U[i].rank = 0;
	}
	REP(i, m){
		int u = ve[i].u, v = ve[i].v;
		while (u != U[u].par){
			u = U[u].par;
		}
		while (v != U[v].par){
			v = U[v].par;
		}
		if (u == v){
			ans += ve[i].dis;
		}
		else{
			if (U[u].rank > U[v].rank){
				U[v].par = u;
			}
			else if (U[u].rank < U[v].rank){
				U[u].par = v;
			}
			else{
				U[u].par = v;
				U[v].rank++;
			}
		}
	}
	printf("%.3lf\n", ans);
}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define rep(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007


using namespace std;

int main(void){
    int N,K;
    cin>>N>>K;
    int t=1,n=1,a=1;
    while(1){
        n=(K+a-1)/K;
        a+=n;
        if(N<a){
            cout<<t<<endl;
            return 0;
        }
        t++;
    }
}





Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

void chmax(ll &a, ll b){ if( a < b){ swap(a,b);} return ;}

int main(){
  ll N; cin >> N; string S; cin >> S;
  ll dp[5010][5010];
  for(ll i = 0; i < 5010; i++){
    for(ll j = 0; j < 5010; j++){
      dp[i][j] = 0LL;}}
  
  ll ans = 0LL;
  
  for(ll i = N-1; i >= 0; i--){
    for(ll j = N-1; j >= 0; j--){
      if(S[i] == S[j]){
        chmax(dp[i][j], dp[i+1][j+1]+1);}
    }
  }
  
  for(ll i = 0; i < N; i++){
    for(ll j = 0; j < N; j++){
      chmax(ans, min(dp[i][j],abs(j-i)));}}
  
  cout << ans << endl; return 0;}
  
        

Measured memory_bytes: 196480
//#define _USE_MATH_DEFINES
#include <iostream>
//#include <stdio.h>
//#include <iomanip>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <functional>
//#include <cmath>
//#include <time.h>

using namespace std;


int main(){

	int a;
	vector <int> s;

	while (cin >> a){
		if (a == 0){
			cout << s.back() << endl;
			s.pop_back();
		}
		else{
			s.push_back(a);
		}
	}


	return 0;
}

Measured memory_bytes: 1212
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let h: usize = scan(tokens);
    let n: usize = scan(tokens);
    let mut dp: Vec<usize> = vec![std::usize::MAX; h + 1];
    dp[0] = 0;
    for _ in 0..n {
        let a: usize = scan(tokens);
        let b: usize = scan(tokens);
        for x in 0..h + 1 {
            if x < a {
                dp[x] = std::cmp::min(dp[x], b);
            } else {
                dp[x] = std::cmp::min(dp[x], dp[x - a] + b);
            }
        }
    }
    println!("{}", dp[h]);
}


Measured memory_bytes: 4352
x = int(input())
i = 0
if x//100 == 1:
    i = i + 1
    x = x - 100
    if x//10 ==1:
        i = i + 1
        x = x - 10
        if x == 1:
            i = i + 1
    else:
        if x == 1:
            i = i + 1
else:
    if x//10 == 1:
        i = i + 1
        x = x - 10
        if x == 1:
            i = i + 1
    else:
        if x == 1:
            i = i + 1     

print(i)

Measured memory_bytes: 38256
--{-# LANGUAGE StandaloneDeriving #-}
--{-# LANGUAGE BangPatterns #-}

module Main where

import Debug.Trace
--import Data.List
--import Data.Char
--import qualified Data.Set.Strict as Set
--import qualified Data.Map.Strict as Map

main :: IO ()
main = do
  a <- read <$> getLine
  --a `traceShow`
  print $ solve a


solve :: Int -> Int
solve a = sum . map (\x -> let y = a `div` x in x * y * (y + 1) `div` 2) $ [1 .. a]


Measured memory_bytes: 3876
n, x, y = map(int, input().split())

counter = [0] * n

for i in range(1, n):
    for j in range(i+1, n+1):
        min_d = min(abs(j-i), (abs(x-i) + 1 + abs(j-y)), (abs(y-i) + 1 + abs(j-x)))
        counter[min_d] += 1

for k in counter[1:]:
    print(k)

Measured memory_bytes: 3444
#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    char s[n],t[n];
    scanf("%s",s);
    scanf("%s",t);
for(int i=0;i<n;i++){
    printf("%c%c",s[i],t[i]);
}
   return 0; 

}

Measured memory_bytes: 128
#include "stdio.h"
#include "string.h"

int main()
{
    int i, j;
    char a, s[3];
    scanf("%s", s);
    for (i = 0; s[i] != 0; i++) {
         for (j = i + 1; s[j] != 0; j++) {
              if (s[i] > s[j]) {
                                    a = s[i];
                                    s[i] = s[j];
                                    s[j] = a;
              }
         }
    }

    if (strcmp(s, "abc") == 0)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;

}

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

char a[110][110];
char b[110][110];


int main(void) {

	int i, j;
	int h, w;

	scanf("%d%d", &h, &w);

	//行列aに入力　11からhw成分まで入っている h0成分は改行文字//
	for (i = 1; i <= h ; i++) {
		for (j = 0; j <= w; j++) {
			scanf("%c", &a[i][j]);
		}
	}

	//行列bの成分を全て#にして h(w+2)成分を改行文字にする//
	for (i = 0; i <= h + 1; i++) {
		for (j = 0; j <= w + 2; j++) {
			if (j <= w + 1) {
				b[i][j] = '#';
			}
			else{
				b[i][j] = '\n';
			}
		}
	}

	//行列bの 11成分からhw成分　に行列aを代入する//
	for (i = 1; i <= h; i++) {
		for (j = 1; j <= w; j++) {
			b[i][j] = a[i][j];
		}
	}

	for (i = 0; i <= h + 1; i++) {
		for (j = 0; j <= w + 2; j++) {
			printf("%c", b[i][j]);
		}
	}

	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define debug(var) std::cout << #var << " : " << var;



int main() {
	
	std::cin.tie(nullptr); std::ios::sync_with_stdio(false);
	
	int N; std::cin >> N;

	std::cout << N / 3;

	return 0;
}

Measured memory_bytes: 256
'use strict';

function Main(input) {
  const N = Number(input.split('\n')[0]);

  let W = [];
  for(let i=0; i<N; i++) {
    W.push(input.split('\n')[i+1]);
  }

  let Wremovepoly = W.filter((x, i, self) => self.indexOf(x) === i);

  const siritori = () => {
    for(let j=0; j<N-1; j++) {
      if(W[j].slice(-1) !== W[j+1].slice(0, 1)) {
        console.log('No');
        break;
      }
      if(j === N-2) {
        console.log('Yes');
      }
    }
  }

  if(W.length !== Wremovepoly.length) {
    console.log('No');
  } else {
    siritori();
  }

};

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 21064
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize(2)
#pragma G++ optimize(2)

#include <bits/stdc++.h>

#define LL long long
#define int long long
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<LL, LL>
#define pdd pair<double, double>
#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define length(p1, p2) ((p1.fi-p2.fi)*(p1.fi-p2.fi)+(p1.se-p2.se)*(p1.se-p2.se))
#define ith(state, i) (state & (1 << i))
#define PI acos(-1.0)
#define SZ(x) ((int)(x.size()))

using namespace std;

constexpr int N = 3e5+9;
constexpr int M = 1e6+7;
constexpr int INF = 0x3f3f3f3f3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcfcfcfcfcf;

int n;
int a[N];
int cnt[M];
int d[M];

signed main() {
    fastio
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        cnt[a[i]]++;
    }
    for (int i = 1; i < M; i++) {
        for (int j = i; j < M; j += i)
            d[j] += cnt[i];
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (d[a[i]] == 1) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 20768
s = input()

result1, result2 = 0, 0

for ss in range(len(s)):
  
  # １桁目が0
  if ss % 2 - int(s[ss]) != 0:
      result1 += 1
  
  # 1桁目が1
  if abs(ss % 2 - int(s[ss])) != 1:
      result2 += 1
      
print(min(result1, result2))
      
      

Measured memory_bytes: 3188
#include <stdio.h>

int dp[1024][10010];

int main(void)
{
	int i, j;
	int n;
	int wei;
	int w[1024];
	int k[1024];
	int b;
	int max;
	int mw;
	
	b = 0;
	while (scanf("%d", &wei), wei != 0){
		scanf("%d", &n);
		for (i = 0; i <= n; i++){
			if (i < n){
				scanf("%d,%d", &k[i], &w[i]);
			}
			for (j = 0; j < 10000; j++){
				dp[i][j] = 0;
			}
		}
		for (i = 0; i < n; i++){
			for (j = 0; j <= wei; j++){
				if (dp[i + 1][j + w[i]] < dp[i][j] + k[i] && j + w[i] <= wei){
					dp[i + 1][j + w[i]] = dp[i][j] + k[i];
				}
				if (dp[i + 1][j] < dp[i][j]){
					dp[i + 1][j] = dp[i][j];
				}
			}
		}
		max = 0;
		for (i = 0; i <= wei; i++){
			if (max < dp[n][i]){
				max = dp[n][i];
				mw = i;
			}
		}
		b++;
		printf("Case %d:\n", b);
		printf("%d\n%d\n", max, mw);
	}
	return (0);
}

Measured memory_bytes: 40176
import sys
import math


def main():
    inp = [int(line)  for line in sys.stdin.readlines()]
    num = inp.pop(0)
    inp_min = min(inp)
    if inp_min >= num:
        print(5)
    else:
        a = math.ceil(num / inp_min) + 4
        print(a)


if __name__ == '__main__':
    sys.exit(main())


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n,i,j,sum=0,cnt;
    scanf("%d",&n);
    int num[n];
    for(i=0;i<n;i++)
        scanf("%d",&num[i]);
    sort(num,num+n);
    for(i=1;i<n;i++)
    {
        cnt=1;
        if(num[i-1]==num[i])
        {
            for(j=i;j<n;j++)
            {
                if(num[j]==num[i-1])
                    cnt++;
            }
            sum=sum+cnt%2;
            i=i-1+cnt;
        }
        else
            sum++;
        if(i==n-1)sum++;
    }
    printf("%d",sum);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using ll = long long;
using namespace std;

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int n, z, w; cin >> n >> z >> w;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    int dp[n + 1][2];
    for (int i = n - 1; i >= 0; i--) {
        int nw = (i > 0 ? a[i - 1] : w);
        dp[i][0] = abs(nw - a[n - 1]);
        for (int j = i + 1; j < n; j++) dp[i][0] = max(dp[i][0], dp[j][1]);

        int nz = (i > 0 ? a[i - 1] : z);
        dp[i][1] = abs(nz - a[n - 1]);
        for (int j = i + 1; j < n; j++) dp[i][1] = min(dp[i][1], dp[j][0]);
    }

    cout << dp[0][0] << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int[]A = new int [N];
			for(int i = 0;i<N;i++)A[i] = scan.nextInt();
			
			long []s = new long[N+2];
			
			s[1] = s[0]+(long)Math.abs(A[0]-0);//1
			for(int i = 1;i<N;i++) {//Nー1
				s[i+1] = s[i]+(long)Math.abs(A[i]-A[i-1]);
			}
			s[N+1] = s[N]+(long)Math.abs(0-A[N-1]);
			
			for(int i = 0;i<N;i++) {
				long goukei = 0;
				goukei+=s[N+1]-s[i+2];
				//System.out.print(goukei);
				//System.out.print(" ");
				goukei+=s[i];
				//System.out.println(s[i]);
				
				if(i==0) goukei+=(long)Math.abs(A[i+1]);
				else if(i==N-1)goukei+=(long)Math.abs(A[i-1]);
				else goukei+=(long)Math.abs(A[i+1]-A[i-1]);
				
				System.out.println(goukei);
			}
			
			
			
			
			
		}
		
		
	}
		

}


Measured memory_bytes: 66496
def m():
    MOD = 10 ** 9 + 7
    N, M = map(int, input().split())
    A = [int(input()) for _ in range(M)]
    dp = [0] * (N + 1)
    for a in A: dp[a] = -1
    if N == 1:
        if dp[1] != -1:
            return 1
        else:
            return 0
    if dp[1] != -1 and dp[2] != -1:
        dp[1] = 1
        dp[2] = 2
    elif dp[1] != -1 and dp[2] == -1:
        dp[1] = 1
    elif dp[1] == -1 and dp[2] != -1:
        dp[2] = 1
    else:
        return 0

    for i in range(3, N + 1):
        if dp[i] == -1:
            continue
        l = dp[i - 2] if dp[i - 2] != -1 else 0
        r = dp[i - 1] if dp[i - 1] != -1 else 0
        dp[i] = (l + r) % MOD
    return dp[N] % MOD


print(m())


Measured memory_bytes: 80764
package main

import (
    "fmt"
    "sort"
)

func main() {
    s := make([]int, 3)
    for i := range s { 
        fmt.Scan(&s[i])
    }   
    sort.Sort(sort.Reverse(sort.IntSlice(s)))
    fmt.Println(s[0]*10 + s[1] + s[2])
}


Measured memory_bytes: 512
import sys
sys.setrecursionlimit(10**6)

def m():
    n, m = map(int, input().split())
    p = list(map(int, input().split()))
    g = [[] for _ in range(n+1)]
    for _ in range(m):
        x, y = map(int, input().split())
        g[x].append(y)
        g[y].append(x)
    color = [-1] * (n+1)

    def dfs(v, c):
        s = []
        s.append(v)
        color[v] = c
        while len(s) != 0:
            a = s.pop()
            for elem in g[a]:
                if color[elem] == -1:
                    dfs(elem, c)

    k = 0
    for i in range(1, n):
        if color[i] == -1:
            dfs(i,k)
            k +=1
    ans = 0
    for i in range(n):
        if color[p[i]] == color[i+1]:
            ans +=1
    return ans

print(m())

Measured memory_bytes: 102372
# Template 1.0
import sys, re
from decimal import *
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, floor, trunc, log
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

s = input()

if('RRR' in s):
    print(3)
elif('RR' in s):
    print(2)
elif('R' in s):
    print(1)
else:
    print(0)

Measured memory_bytes: 71020
#include <stdio.h>
int main(){
  int a[300];
  char s[100010];
  scanf("%s",s);
  for(int i=0;s[i]!='\0';i++){
    a[(int)s[i]]=1;
  }
  for(int i=(int)'a';i<=(int)'z';i++){
    if(a[i]==0){
      printf("%c\n",(char)i);
      return 0;   
    }
  }
  printf("None\n");
  return 0;
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

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

    rep(i,s.size()-1){
        if(s.substr(i,2)=="AC"){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
<?php

$string = trim(fgets(STDIN));

$array = array();

for ($i = 0; $i < strlen($string); $i ++)
{
	$dir = $string[$i];


	$array[$dir] = true;
}

if (($array['N']) && ! $array['S'])
{
	echo "No\n";
	die();
}

if (($array['S']) && ! $array['N'])
{
	echo "No\n";
	die();
}

if (($array['E']) && ! $array['W'])
{
	echo "No\n";
	die();
}

if (($array['W']) && ! $array['E'])
{
	echo "No\n";
	die();
}


echo "Yes\n";


Measured memory_bytes: 3576
ts = []

while True:
    vs = tuple(map(int, input().split(' ')))
    if vs[0] == 0 and vs[1] == 0:
        break

    ts.append(vs)

for vs in ts:
    for i in range(0, vs[0]):
        for j in range(0, vs[1]):
            if i % 2 == 0:
                if j % 2 == 0:
                    print("#", end='')
                else:
                    print(".", end='')
            else:
                if j % 2 == 0:
                    print(".", end='')
                else:
                    print("#", end='')
        print()
    print()




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

using namespace std;

#define MAXN 100010
#define INF 0x3f3f3f3f
typedef long long LL;

int n, x, y, z;
int a[MAXN], b[MAXN], c[MAXN];
int vis[MAXN];
LL sum;
priority_queue<pair<int, int> > q1, q2, q3;

void Init()
{
    scanf("%d %d %d", &x, &y, &z);
    n = x + y + z;
    for(int i = 1; i <= n; ++i){
        scanf("%d %d %d", a + i, b + i, c + i);
        sum += a[i];
    }
}

void Work()
{
    int i;
    for(i = 1; i <= n; ++i){
        q1.push({b[i] - a[i], i});
    }
    for(i = 1; i <= y; ++i){
        vis[q1.top().second] = 1;
        sum += q1.top().first;
        q1.pop();
    }
    while(!q1.empty()) q1.pop();

    for(i = 1; i <= n; ++i){
        if(vis[i]) q2.push({c[i] - b[i], i});
        else{
            q1.push({c[i] - a[i], i});
            q3.push({b[i] - a[i], i});
        }
    }

    for(i = 1; i <= z; ++i){
        while(vis[q1.top().second] != 0) q1.pop();
        while(vis[q3.top().second] != 0) q3.pop();
        if(q1.top().first >= 0LL + q2.top().first + q3.top().first){
            vis[q1.top().second] = 2;
            sum += q1.top().first;
            q1.pop();
        }
        else{
            vis[q2.top().second] = 2;
            vis[q3.top().second] = 1;
            sum += 0LL + q2.top().first + q3.top().first;
            q2.pop();
            q2.push({c[q3.top().second] - b[q3.top().second], q3.top().second});
            q3.pop();
        }
    }
    cout << sum << endl;
}

int main()
{
    Init();
    Work();
    return 0;
}


Measured memory_bytes: 4468
<?php
// バーチャル Dまで自力AC 1000 57:01 => 推定パフォ 1441
// D
fscanf(STDIN, '%d %d', $n, $x);
$cnt = [1];
$cnt_p = [1];
for ($i = 1; $i <= $n; $i++) {
    $cnt[] = $cnt[$i - 1] * 2 + 3;
    $cnt_p[] = $cnt_p[$i - 1] * 2 + 1;
}
echo f($n, $x);

function f($n, $x)
{
    global $cnt, $cnt_p;

    if ($n === 0) return min(1, $x);
    if ($x - 1 >= $cnt[$n]) return $cnt_p[$n];

    if ($x <= 1) return 0;
    if ($x <= ($cnt[$n] - 3) / 2 + 1) {
        return f($n - 1, $x - 1);
    }
    if ($x === ($cnt[$n] - 3) / 2 + 2) {
        return f($n - 1, $x - 2) + 1;
    }
    return $cnt_p[$n - 1] + 1 + f($n - 1, $x - (($cnt[$n] - 3) / 2 + 2));
}

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

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

    int A[n], sum_a=0;
    rep(i, n) {
        cin >> A[i];
        sum_a += A[i];
    }

    int q;
    cin >> q;

    int M[q];
    rep(i, q) cin >> M[i];

    rep(i, q) {
        string ans_i = "no";
        if (M[i] <= sum_a) {
            for (int bit=0; bit<(1<<n); bit++) {
                int comb=0;
                for (int j=0; j<n; j++) {
                    if (bit & (1<<j)) comb += A[j];
                }
                if (comb==M[i]) {
                    ans_i = "yes";
                    break;
                }
            }
        }
        cout << ans_i << endl;
    }

    return 0;
}




Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define simplify ios_base::sync_with_stdio(0);cin.tie(0);
#define int long long
#define endl "\n"
using namespace std;



int32_t main() {

    simplify

    int n;
    cin>>n;
    //n--;
    string s;
    while(n>0){
        int add=(n)%26;
        //cout<<add<<endl;
        char c;
        if(add==0){
            c='z';
            n=n/26;
            n--;
        }
        else{
            c='a'+(add-1);
            n/=26;
        }
        s.push_back(c);
        
    }
    //cout<<s;
    reverse(s.begin(),s.end());
    cout<<s;



    return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>
int main()
{
    int N;
    float sum=0.00;
    scanf("%d",&N);
    int A[N],i;
    for(i=0;i<N;i=i+1)
    {
        scanf("%d",&A[i]);
        sum=sum+(1.0/A[i]);
    }
    printf("%f",1/sum);

}


Measured memory_bytes: 128
/** @Date    : 2017-08-26 19:22:06
  * @FileName: A.cpp
  * @Platform: Windows
  * @Author  : Lweleth (SoungEarlf@gmail.com)
  * @Link    : https://github.com/
  * @Version : $Id$
  */
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std;

const LL INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8;


int main()
{
	LL a, b, c, d;
	LL n;
	while(cin >> a >> b >> c >> d)
	{
		cin >> n;
		LL a1 = n * 4LL * a;
		LL b1 = n * 2LL * b;
		LL c1 = n * c;
		LL d1;
		if(n % 2 == 0)
			d1 = (n / 2LL) * d;
		else
			d1 = (n / 2LL) * d + min(4LL * a, min(2LL * b, c));
		cout << min(min(a1, b1), min(c1, d1)) << endl;
	}
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll=long long ;
ll f(ll n){
	if(n>0)	
		return n*f(n-1);
	else
		return 1;
}
int main(){
	ll N,x,cnt=0,sum=0;
	cin >> N;
	vector<ll> a(N+1);
	a[0]=0;
	for(ll i=1;i<=N;i++){
		cin >> x;
		a[i] = a[i-1]+x;
	}
	sort(a.begin(),a.end());
	for(ll i=0;i<N;i++){
		//cout << a[i] << ' ' << a[i+1] << endl;
		if(a[i]==a[i+1])	sum++;
		else{
			if(sum>0){
				//cout << sum << endl;
				cnt+=(sum+1)*sum/2;
			}
			sum=0;
		}
	}
	if(sum>0){
		//cout << sum << endl;
		cnt+=(sum+1)*sum/2;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 1792
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100005;

int N,M;
vpi v;

void init() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> M;
    vi x(N), y(M);
    F0R(i,N) cin >> x[i];
    F0R(i,M) cin >> y[i];
    int nex = 0;
    F0R(i,N) {
        while (nex < M && y[nex] < x[i]) nex ++;
        if (nex != 0 && nex != M) v.pb({x[i]-y[nex-1], y[nex]-x[i]});
    }
}

template<class T, int SZ> struct BIT {
    T bit[SZ+1];
    
    BIT() { memset(bit,0,sizeof bit); }
    
    void upd(int k, T val) { // add val to index k
        for( ;k <= SZ; k += (k&-k)) bit[k] = (bit[k]+val)%MOD;
    }
    
    T query(int k) {
        T temp = 0;
        for (;k > 0;k -= (k&-k)) temp = (temp+bit[k])%MOD;
        return temp;
    }
};

BIT<int,MX> B;

int main() {
    init();
    sort(all(v),[](pi a, pi b) {
        if (a.f != b.f) return a < b;
        return a > b;
    }); 
    v.erase(unique(all(v)),v.end());
    map<int,int> m;
    m[1] = 0;
    for (auto a: v) m[a.s+1] = 0;
    int co = 0;
    for (auto& a: m) a.s = ++co;
    B.upd(1,1);
    for (auto a: v) {
        int ind = m[a.s+1];
        B.upd(ind,B.query(ind-1));
    }
    cout << B.query(MX-1);
}

/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( ) 
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
* if you have no idea just guess the appropriate well-known algo instead of doing nothing :/
*/

Measured memory_bytes: 5996
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001

int main() {
    int N; cin >> N;
    vector<int> A(N);
    vector<ll> C(N+1);
    for(int i=0; i<N; i++){
        cin >> A[i];
        C[i+1] = C[i] + A[i];
    }
    
    sort(C.begin(), C.end());
    ll ans = 0;
    ll cur = 1;
    for(int i=0; i<N; i++){
        if(C[i+1]==C[i]) cur++;
        else{
            ans += cur*(cur-1)/2;
            cur = 1;
        }
    }
    ans += cur*(cur-1)/2;
    cout << ans << endl;
    return 0;
}


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

int main(void){
  using namespace std;
  long long i;
  long long sum=0;
  string s;
  //const char* cs = s.c_str();

  cin >> s;
  //cout << s.length();
 // cout << s << endl;
  /*
  for(int i = 0; i < (int)s.size(); ++i){
    cout << s[i];
    sum = sum + (int)s[i]-48;
  }
  */

  for(int i=0;i<s.length();i++){
    //cout << s[i] << endl;
    sum = sum + ((int)s[i]-48);
  }
  //cout << sum <<endl;
  if(sum%9==0) cout << "Yes" << endl;
  else cout << "No" <<endl;
}
  

Measured memory_bytes: 3648
#include<algorithm>
#include<iomanip>
#include<iostream>
#include<map>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<vector>
using namespace std;
#define FOR(i,a,b) for(int i=(a); i<int(b); ++i)
#define RFOR(i,a,b) for(int i=(b)-1; i>=int(a); --i)
#define rep(i,n) FOR(i,0,n)
#define rep1(i,n) FOR(i,1,int(n)+1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
#define al(d) d.begin(),d.end()
using namespace std;
template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
template <class T>
vector<T> getv(int n){
	vector<T> vec;
	rep(i,n){
		T input;
		cin >> input;
		vec.emplace_back(input);
	}
	return vec;
}
using AdjList = vector<vector<int>>;
using Weight = int;
using Flow = int;
struct Edge {
	int src, dst;
	Weight weight;
	Flow cap;
	Edge() : src(0), dst(0), weight(0) {}
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph &g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }

// Recieve edge(=(int,int)) as an adj list.
AdjList getadj(int N, int M){
	// Initialize all lists of the graph as a empty vector.
	vector<int> init;
	vector<vector<int>> graph(N,init);

	rep(i,M){
		int a, b;
		cin >> a >> b;
		graph[a-1].emplace_back(b-1);
		graph[b-1].emplace_back(a-1);
	}
// rep(i,N)
// 	putv(graph[i]);
	return graph;
}

long long Manhattan_dist(long long x1, long long y1, long long x2, long long y2){return abs(x1-x2) + abs(y1-y2);}

void out(bool ans){
	if(ans == true) cout << "yes" << endl;
	else cout << "no" << endl;
}
void Out(bool ans){
	if(ans == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}
void OUT(bool ans){
	if(ans == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}
unsigned long long gcd(const unsigned long long a, const unsigned long long b){
	return (b==0) ? a : gcd(b,a%b);
}
int push(int n, int N);
vector<int> a;
int cntr = 0;
int main(){
	int N;
	cin >> N;
	a = getv<int>(N);

	cout << push(0,N) << endl;
}
int push(int n,int N){
	cntr++;
	if(n+1==2) return cntr-1;
	else if(cntr>N) return -1;
	return push(a[n]-1,N);
}

Measured memory_bytes: 892
#include <stdio.h>
int main(void){
  int a,b,c,d;
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  scanf("%d",&d);
  if(a<=b){printf("%d",(c*a));}
                 if(a>b){printf("%d",b*c+(a-b)*d);}
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

vector<ll> yakusu(ll x){
	vector<ll> ans;
	if(x==1){return {1};}
	ll p=x;
	ans.push_back(1);
	for(ll i=2;i*i<=x;i++){
		ll j=0,l=1;
		while(p%i==0){
			p /= i;
			j++;
		}
		vector<ll> s=ans;
		for(ll k=0;k<j;k++){
			l*=i;
			for(auto y:ans){
				s.push_back(y*l);
			}
		}
		ans = s;
	}
	if(p!=1){
		vector<ll> s=ans;
		for(auto x:ans){
			s.push_back(x*p);
		}
		ans = s;
	}
	sort(ans.begin(),ans.end());
	return ans;
}

int main(){
	ll N,ans=0;
	cin >> N;
	vector<ll> a(N);
	FOR(i,0,N)cin>>a[i];
	SORT(a);
	FOR(i,0,2){
		for(auto x:yakusu(a[i])){
			ll k = 0;
			FOR(j,0,N){
				if(a[j]%x==0)k++;
			}
			if(k>=N-1){
				ans = max(ans,x);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
N, K = map(int, input().split())
S_temp = input()
S = [c for c in S_temp]

happy = 0
change = 0
for i in range(N-1):
  if S[i] == S[i+1]:
    happy += 1
  else:
    change += 1

#change += 1
happy2 = min(K, (change // 2)) * 2
if change % 2 == 1 and K > change // 2:
  happy2 += 1
print(happy + happy2)    



Measured memory_bytes: 4084
#include <iostream>
using namespace std;
int main(void){
    
    int a,b,c;
    cin >>a>>b;
    
    if(a >= b){
        cout<<"1"<<endl;
        
    }else if(b % a){
        c = b / a + 1;
        cout <<c<<endl;
    }else{
        cout<<b / a<<endl;
    }
    
}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=900005,M=1e9+7;
int a,b,c,fac[N],fac2[N],inv[N],f[N];
int ksm(int x,int y){
	if (!y)return 1;
	int z=ksm(x,y/2);
	z*=z;z%=M;
	if (y&1)z*=x;
	return z%M;
}
int C(int x,int y){
	if (x<y)return 0;
	return fac[x]*inv[y]%M*inv[x-y]%M;
}
signed main(){
	scanf("%lld%lld%lld",&a,&b,&c);
	fac[0]=inv[0]=fac2[0]=1;
	for (int i=1;i<N;i++)fac[i]=fac[i-1]*i%M,fac2[i]=fac2[i-1]*3%M,inv[i]=ksm(fac[i],M-2);
	a--;
	int now1=0,now2=1,ans=fac2[b+c];
	for (int i=1;i<=b+c;i++){
		now2=(now2*2-C(i-1,b)+M)%M;
		now1=(now1*2+C(i-1,i-c-1))%M;
		(ans+=fac2[b+c-i]*(now2-now1+M)%M*C(a+i,a))%=M;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 22272