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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

//実行部
void Main()
{
  ll a, b; cin >> a >> b;
  fin((a+b)%3==0||a%3==0||b%3==0?"Possible":"Impossible")
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}


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

using namespace std;
 
#define MD 1000000007
typedef long long int ll;

int v[3][101]={0};

int dfs(int n,int i,int j,int sum){
    sum+=v[i][j];
    if(i==1&&j==n-1){
        return sum;
    }
    int ans=0;
    if(i==0&&j<n-1){
        ans=max(dfs(n,i,j+1,sum),dfs(n,i+1,j,sum));
    }else if(i==0&&j==n-1){
        ans=dfs(n,i+1,j,sum);
    }else if(i==1){
        ans=dfs(n,i,j+1,sum);
    }
    return ans;
}

int main(){
    int n;
    cin>>n;
    for(int i=0;i<2;i++){
        for(int j=0;j<n;j++){
            cin>>v[i][j];
        }
    }
    cout<<dfs(n,0,0,0)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fr first
#define sc second
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rrep(i, n) for(int i = 1; i <= (n); ++i)
#define drep(i, n) for(int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for(int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define snuke srand((unsigned)clock() + (unsigned)time(NULL));
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
// typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
// typedef vector<T> vt;
inline int getInt() {
    int x;
    scanf("%d", &x);
    return x;
}
template <typename T> inline istream &operator>>(istream &i, v(T) & v) {
    rep(j, sz(v)) i >> v[j];
    return i;
}
template <typename T> string join(const v(T) & v) {
    stringstream s;
    rep(i, sz(v)) s << ' ' << v[i];
    return s.str().substr(1);
}
template <typename T> inline ostream &operator<<(ostream &o, const v(T) & v) {
    if(sz(v))
        o << join(v);
    return o;
}
template <typename T1, typename T2>
inline istream &operator>>(istream &i, pair<T1, T2> &v) {
    return i >> v.fi >> v.se;
}
template <typename T1, typename T2>
inline ostream &operator<<(ostream &o, const pair<T1, T2> &v) {
    return o << v.fi << "," << v.se;
}
template <typename T> inline ll suma(const v(T) & a) {
    ll res(0);
    for(auto &&x : a)
        res += x;
    return res;
}
template <class T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if(b < a) {
        a = b;
        return 1;
    }
    return 0;
}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame                                                                   \
    {                                                                          \
        puts("-1");                                                            \
        return 0;                                                              \
    }
#define yn                                                                     \
    { puts("Yes"); }                                                           \
    else {                                                                     \
        puts("No");                                                            \
    }

int main() {
    int X, Y;
    cin >> X >> Y;
    if(Y % 2 == 0 && 2 * X - Y / 2 >= 0 && Y / 2 - X >= 0)
        yn
}

Measured memory_bytes: 3600
import heapq

N = int(input())
q = list(map(int, input().split()))

heapq.heapify(q)

while (len(q) > 1):
    v1 = heapq.heappop(q)
    v2 = heapq.heappop(q)
    heapq.heappush(q, (v1+v2)/2.0)

print(heapq.heappop(q))



Measured memory_bytes: 3060
import math

A, B, H, M = map(int, input().split())


M_A = M / 60 * 360 * math.pi / 180
Minx = B * math.cos(M_A)
Miny = B * math.sin(M_A)

H = H
if H >= 12: 
    H -= 12
H = H + M / 60

H_A = H / 12 * 360 * math.pi / 180

Hourx = A * math.cos(H_A)
Houry = A * math.sin(H_A)

result = math.sqrt(pow((Minx - Hourx),2) + pow((Miny - Houry), 2))
print(result)

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll n, k;
    cin >> n >> k;
    ll a[n];
    rep(i, n) { cin >> a[i]; }
    map<ll, ll> m;
    rep(i, n) {
        if (m[a[i]] == 0) {
            m[a[i]] = 1;
        } else {
            m[a[i]]++;
        }
    }
    vector<pair<ll, ll>> v;
    for (auto iter = m.begin(); iter != m.end(); iter++) {
        v.push_back(make_pair(iter->first, iter->second));
    }

    sort(v.begin(), v.end(), [](auto const &a, auto const &b) {
        if (a.second == b.second) {
            return a.first < b.first;
        } else {
            return a.second < b.second;
        }
    });

    ll ans = 0;
    ll num = v.size() - k;
    rep(i, num) { ans += v[i].second; }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 19056
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int dp[300000][2];
int main(){
	int n;string s;cin>>n>>s;
	memset(dp,0x3f,sizeof(dp));
	if(s[0]=='#'){
		dp[1][1]=0;
		dp[1][0]=1;
	}
	else{
		dp[1][1]=1;
		dp[1][0]=0;
	}
	for(int i=1;i<n;i++){
		int a=(s[i]=='#'?1:0);
		rep(j,2){
			rep(k,2){
				if(j==1&&k==0)continue;
				dp[i+1][k]=min(dp[i+1][k],dp[i][j]+(a!=k));
			}
		}
	}
	cout<<min(dp[n][0],dp[n][1])<<endl;
}

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

using ll = long long;
using pii = pair<int, int>;

int main() {
    int N;
    cin >> N;
    vector<int> x(N), y(N);
    for(int i = 0; i < N; ++i) {
        cin >> x[i] >> y[i];
        if(x[i] > y[i]) swap(x[i], y[i]);
    }

    if(N == 1) {
        cout << 1 << endl;
        return 0;
    }

    int min_pos = 0, max_pos = 0;
    for(int i = 0; i < N; ++i) {
        if(x[i] < x[min_pos]) min_pos = i;
        if(y[i] > y[max_pos]) max_pos = i;
    }

    // min is in red, max is in blue
    const int r_min = x[min_pos];
    ll ans = 1LL * (*max_element(begin(x), end(x)) - r_min) * (y[max_pos] - *min_element(begin(y), end(y)));

    if(min_pos == max_pos) {
        cout << ans << endl;
        return 0;
    }

    // min ans max is in red
    const int r_max = y[max_pos];
    set<pii> blue;
    for(int i = 0; i < N; ++i) {
        if(i == min_pos)      blue.insert(make_pair(y[i], i));
        else if(i == max_pos) blue.insert(make_pair(x[i], i));
        else                  blue.insert(make_pair(min(x[i], y[i]), i));
    }
    for(int i = 0; i < N; ++i) {
        ans = min(ans, 1LL * (blue.rbegin()->first - blue.begin()->first) * (r_max - r_min));
        const auto p = *blue.begin();
        if(p.first >= y[p.second]) {
            break;
        }
        blue.erase(p);
        blue.insert(make_pair(y[p.second], p.second));
    }

    cout << ans << endl;
}

Measured memory_bytes: 11136
#include<iostream>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	int cnt=0,s;
	for(int i=0;i<m;++i){
		cin>>s;
		cnt+=s;
	}
	if(cnt>=n)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int N;
int A[110];
int main(){
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
 int diff;
 int max = A[0];
 int min = A[0];
  for(int i = 0; i < N; i++){
    if(A[i] > max) max = A[i];
  }
  for(int i = 0; i < N; i++){
    if(A[i] < min) min = A[i];
  }
  diff = max - min;
  cout << diff << endl;
  
}

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

using namespace std;

#define boost ios::sync_with_stdio(0);cin.tie(0);
#define debug(s) cout << #s << " = " << s << endl
#define forn(i,n) for ( int i=0 ; i < n ; i++ )
#define all(a) (a).begin(), (a).end()
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ll long long
#define endl '\n'
#define mod 1000000007

int main()
{
	//freopen ("f.in","r",stdin);
 	//freopen ("f.out","w",stdout);
	boost
	//code
	int n,m;
	cin >> n >> m;
	vector<string> v(m);
	map<int,set<pair<int,int> > > mp;
	forn(i,m){
		int a,b;
		cin >> a >> b;
		mp[a].insert(MP(b,i));
	}
	for(auto it:mp){
		string pre = to_string(it.F);
		while(pre.length() < 6){
			pre = "0" + pre;
		}
		int count = 1;
		for(auto itt:it.S){
			string final = pre;
			string here = to_string(count);
			while(here.length() < 6) here = "0" + here;
			final += here;
			v[itt.S] = final;
			count++;
		}
	}
	for(auto it:v) cout << it << endl;
	return 0;
}

Measured memory_bytes: 20992
def main():
    import collections
    S = input()
    T = input()

    table = collections.defaultdict(set)
    table2 = collections.defaultdict(set)
    a = []
    b = []

    for i, xy in enumerate(zip(S, T)):
        x, y = xy
        if x not in table:
            a.append(i)
        if y not in table2:
            b.append(i)

        table[x].add(i)
        table2[y].add(i)

    flag = True

    if a != b:
        flag = False

    for i in a:
        if flag:
            if table[S[i]] == table2[T[i]]:
                continue
            else:
                flag = False
                break
    if flag:
        print("Yes")
    else:
        print("No")


main()


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

int main(){
    int n, ans = 0;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    bool dp[1000001];
    for(int i = 0; i < 1000001; i++) dp[i] = true;
    for(int i = 0; i < n; i++){
        if(dp[a[i]] == false) continue;
        ans++;
        if(i + 1 < n){
            if(a[i] == a[i + 1]) ans--;
        }
        int tmp = a[i];
        while(tmp <= 1000001){
            dp[tmp] = false;
            tmp += a[i];
        }
    }
    cout << ans;
    return 0;
}

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

int main(void){
	int W,H,N;
	cin >> W >> H >> N;
	int x[N],y[N],a[N];
	for(int i=0;i<N;i++)cin>>x[i]>>y[i]>>a[i];
	int leftx=0,rightx=W;
	int bottomy=0,topy=H;
	for(int i=0;i<N;i++){
		switch(a[i]){
		case 1:
			if(leftx<x[i])leftx=x[i];
			break;
		case 2:
			if(rightx>x[i])rightx=x[i];
			break;
		case 3:
			if(bottomy<y[i])bottomy=y[i];
			break;
		case 4:
			if(topy>y[i])topy=y[i];
			break;
		}
	}
	int ans = (topy-bottomy)*(rightx-leftx);
	if(topy<bottomy || rightx<leftx)ans=0;
	//if(ans<0)ans=0;
	cout << ans;
}

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

Measured memory_bytes: 596
# -*- coding: utf-8 -*-

a, b, m = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
res = min(A) + min(B)
for j in range(m):
    x, y, c = map(int, input().split())
    summ = A[x-1] + B[y-1] - c
    if summ < res:
        res = summ

print(res)

Measured memory_bytes: 70380
#include "bits/stdc++.h"
using namespace std;
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	long long int x;
	cin >> x;
	long long int amari;
	amari = x % 11;
	long long int ans;
	if (amari == 0) {
		ans = x / 11;
		cout << ans *2;
		return 0;
	}
	if (amari <= 6) {
		ans = x / 11 * 2+ 1;
	}
	else {
		ans = x / 11 * 2 + 2;
	}
	cout << ans;
}

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

using namespace std;

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

map<int, vector<char>> mp = {
  {2, {'a', 'b', 'c'}}, {6, {'m', 'n', 'o'}},
  {3, {'d', 'e', 'f'}}, {7, {'p', 'q', 'r', 's'}},
  {4, {'g', 'h', 'i'}}, {8, {'t', 'u', 'v'}},
  {5, {'j', 'k', 'l'}}, {9, {'w', 'x', 'y', 'z'}}
};

map<char, vector<string>> MS;
vector<int> S;
int N;
deque<string> out;

bool check(string const& word, int idx) {
  int n = word.size();
  rep(i, n) {
    if(idx + i >= N) return false;
    auto& v = mp[S[idx + i]];
    if(find(v.begin(), v.end(), word[i]) == v.end()) return false;
  }
  return true;
}

void output() {
  rep(i, out.size()) {
    if(i) cout << ' ';
    cout << out[i];
  }
  cout << "." << endl;
}

void dfs(int idx) {
  int num = S[idx];
  auto& chrs = mp[num];
  for(auto c: chrs) {
    for(auto word: MS[c]) {
      if(check(word, idx)) {
        int temp = idx;
        idx += word.size();
        out.push_back(word);
        if(idx == N) output();
        else dfs(idx);
        out.pop_back();
        idx = temp;}}}
}

int main() {

  for(int n; cin >> n && n;) {
    MS.clear();
    S.clear();
    rep(i, n) {
      string s; cin >> s;
      MS[s[0]].push_back(s);
    }
    string s; cin >> s;
    N = s.size();
    rep(i, N) S.push_back(s[i]-'0');
    dfs(0);
    cout << "--" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3092
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

c = sorted(c, reverse=True)
ab = []
for i in range(x):
    for j in range(y):
        temp = a[i] + b[j]
        ab.append(temp)

ab = sorted(ab, reverse=True)
ans = []
for i in range(z):
    for j in range(min(x * y, k)):
        temp = c[i] + ab[j]
        ans += [temp]
ans = sorted(ans, reverse=True)

for i in range(k):
    print(ans[i])

Measured memory_bytes: 136672
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
			　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <memory>
#include <iomanip>
#include <type_traits>

#define rep(i, n) for(Int (i) = 0; (i) < (n); ++(i))
#define all(n) std::begin(n), std::end(n)
#define debug(var) std::cout << #var << ": " << var << "\n"
using Int = int64_t;
constexpr Int INF = INT_MAX;
constexpr Int mod = 1e9 + 7;

//a, a + 1, a + 2, ... , b - 1, bの総和を求める関数(a <= b)。計算量はO(1)
Int Sum(Int a, Int b) {
	if (b < a)return 0;
	if ((b - a + 1) % 2 == 0)return (a + b) * (b - a + 1) / 2;
	else return (a + b) * ((b - a + 1) / 2) + (a + b) / 2;
}

void calc() {

	Int N, K; std::cin >> N >> K;
	Int ans = 0;
	for (Int i = K; i <= N + 1; ++i) {
		Int min = Sum(0, i - 1), max = Sum(N - i + 1, N);
		ans += (max - min + 1);
		ans %= mod;
	}

	std::cout << ans;

}


int main() {

	calc();

	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
#define fi first
#define se second
const ll inf = 9e18;
const ll mod = 1e9 + 7;
const ll N = 2001;

ll modfac[N];
ll modfacinv[N];
ll invsi[N];

ll power(ll x, ll y, ll M = inf){
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {
    return power(n, mod-2, mod);
}
ll spower(ll x, string s, ll M) {
    x %= M;
    ll ans = 1 % M;
    ll now = x;
    for (ll i = (ll)s.size() - 1; i >= 0; i--) {
        ans = (ans * power(now, s[i] - '0', M)) % M;
        now = power(now, 10, M);
    }
    return ans;
}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

void simake(){
	invsi[0]=1;
	invsi[1]=1;
	for(ll i=2;i<N;i++)
	{
		invsi[i]=mul(invsi[mod%i], (mod-(mod/i)));
	}
}
void factmod(){
    modfac[0]=1;
	modfac[1]=1;
	for(ll i=2;i<N;i++)
	{
		modfac[i]=mul(i, modfac[i-1]);
	}
}
void factmodinv(){
	modfacinv[0]=1;
	modfacinv[1]=1;
	for(ll i=2;i<N;i++)
	{
		modfacinv[i]=mul(invsi[i], modfacinv[i-1]);
	}
}
ll nCrm(ll n,ll r){
	return mul(mul(modfac[n], modfacinv[r]), modfacinv[n-r]);
}

int main() {
	simake();
    factmod();
    factmodinv();
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

	ll n, r;
	cin>>n>>r;
	for(int i=1;i<=r;i++){
		if (n-r+1 >= i)
			cout<<mul(nCrm(n-r+1, i), nCrm(r-1, i-1))<<"\n";
  		else
		  	cout<<"0\n";
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  long a,b,c,k,ans;
  scanf("%ld %ld %ld %ld",&a,&b,&c,&k);

  
  if(k%2==1)
   ans=b-a;
  
  
  else
   ans=a-b;
  

    printf("%d",ans);
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

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

    LL n,m;
    cin >> n >> m;

    vector<vector<LL>> edge(n+1);

    for(int i = 0; i < m; i++){
        LL a,b;
        cin >> a >> b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    vector<bool> close(n+1,false);
    deque<LL> result;
    LL j = 1;
    stack<LL> st;
    st.push(j);
    bool endfrag;
    while(!st.empty()){
        endfrag = true;
        LL k = st.top();
        st.pop();
        if(close[k]){
            continue;
        }
        result.push_front(k);
        close[k] = true;
        for(int l = 0; l < edge[k].size(); l++){
            if(!close[edge[k][l]]){
                st.push(edge[k][l]);
                endfrag = false;
            }
        }
        if(endfrag){
            break;
        }
    }

    LL s = -1;

    for(int i = 0; i < edge[j].size(); i++){
        if(!close[edge[j][i]]){
            s = edge[j][i];
            break;
        }
    }

    if(s < 0){

    }else{
        stack<LL> st2;
        st2.push(s);
        while(!st2.empty()){
            endfrag = true;
            LL k = st2.top();
            st2.pop();
            if(close[k]){
                continue;
            }
            result.push_back(k);
            close[k] = true;
            for(int l = 0; l < edge[k].size(); l++){
                if(!close[edge[k][l]]){
                    st2.push(edge[k][l]);
                    endfrag = false;
                }
            }
            if(endfrag){
                break;
            }
        }   
    }

    cout << result.size() << endl;

    for(int i = 0; i < result.size(); i++){
        if(i > 0)cout << " ";
        cout << result[i];
    }
    cout << endl;
    
    return 0;
}

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

int main(void){
    int N, X, Y;
    cin >> N >> X >> Y;
    
    vector<int> nums(N, 0);
    for (int i = 1; i <= N; i++) {
        for (int j = i+1; j <= N; j++) {
            if (j <= X || i >= Y)
                nums[j-i]++;
            else if (i <= X && j >= Y)
                nums[X-i + j-Y + 1]++;
            else if (X <= i && j <= Y)
                nums[min(j-i, i-X + Y-j + 1)]++;
            else if (i <= X && j < Y)
                nums[min(j-i, X-i + Y-j + 1)]++;
            else
                nums[min(j-i, j-Y + i-X + 1)]++;
                
        }
    }
    
    for (int i = 1; i < N; i++)
        cout << nums[i] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N; cin >> N;
	string s; cin >> s;
	int r_cnt = 0, w_cnt = 0;
	rep(i,N){
		if(s[i] == 'R')++r_cnt;
		else ++w_cnt;
	}
	int r_no_move = 0, w_no_move = 0;
	rep(i,r_cnt){
		if(s[i] == 'R')++r_no_move;
	}
	rep(i,w_cnt){
		if(s[N-1-i] == 'W')++w_no_move;
	}
	cout << min(r_cnt - r_no_move, w_cnt - w_no_move) << endl;
	return 0;
}


Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int arr[4],sum=0;
    int a1,a2,a3;
    cin>>a1>>a2>>a3;
    arr[0]=a1;
    arr[1]=a2;
    arr[2]=a3;
    sort(arr,arr+3);
    for(int i=1;i<3;i++){
       // cout<<arr[i]<<endl;
        sum=sum+(arr[i]-arr[i-1]);
    }
cout<<sum<<endl;
}


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

int main() {
  ll n;
  cin >> n;
  string ans;
  while (n > 0) {
    n--;
    ans += 'a' + n % 26;
    n /= 26;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
signed main() {
	cin >> N >> K;
	vector< int > A(N);
	rep(i, N) cin >> A[i];
	vector< int > B(N);
	int S = 0;
	rep(i, N) S += A[i];
	vector< int > D;
	for (int i = 2; i * i <= S; i++) {
		if (S % i == 0) {
			D.push_back(i);
			if (i != S / i)
				D.push_back(S / i);
		}
	}
	D.push_back(S);
	int ans = 1;
	rep(k, D.size()) {
		int d = D[k];
		rep(i, N) B[i] = A[i] % d;
		sort(B.begin(), B.end());
		int c = 0, l = 0, r = N - 1;
		while (B[l] == 0)
			++l;
		while (r - l > 0) {
			int a = min(d - B[r], B[l]);
			c += a;
			if (c > K)
				break;
			B[l] -= a;
			B[r] += a;
			if (B[l] == 0)
				++l;
			if (B[r] == d)
				--r;
		}
		if (r + 1 == l)
			chmax(ans, d);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public int c[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int a[] = new int[m + 1];
            int f[][] = new int[n + 10][10];
            for (int i = 1; i <= m; i++) {
                a[i] = in.nextInt();
                f[c[a[i]]][a[i]] = 1;
            }
            Arrays.sort(a);
            for (int i = 2; i < n; i++) {
                for (int j = 1; j <= m; j++) {
                    if (f[i][a[j]] > 0) {
                        for (int k = 1; k <= m; k++) {
                            f[i + c[a[k]]][a[k]] = Math.max(f[i + c[a[k]]][a[k]], f[i][a[j]] + 1);
                        }
                    }
                }
            }

            int k = 0;
            for (int i = n; i > 0; i -= c[a[k]]) {
                k = 0;
                for (int j = 1; j <= m; j++) {
                    if (f[i][a[j]] > 0 && f[i][a[k]] <= f[i][a[j]]) k = j;
                }
                out.print((char) ('0' + a[k]));
            }
            out.println();

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

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

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[]) {
    string s,t; cin >> s >> t;
    bool flag = true;
    REP(i,SIZE(s)) {
        if (s[i] != t[i]) flag = false;
    }
    if (flag) cout << "Yes" << "\n";
    else cout << "No" << "\n";
    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std ;
int main()
{

   int a[1000], b , c , d ,n ,e;
   int sm ;
   int sum=0;
   cin>>n>>b;
   for(int i=0;i<n;i++)
   {


       cin>>a[i];

   }
for(int i=0;i<n;i++)
{

       sum+=a[i];
}
   sm=a[0];
  for(int i=0;i<n;i++)
  {

      if(a[i]<sm)
        sm=a[i];
  }
  /*cout<<sm;
  cout<<" "<<sum;*/
  d=b-sum;
  if(d==0)
  {
      cout<<n<<endl;
  }
  else
  {
      e=d/sm;
      cout<<e+n;
  }

    return 0 ;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		int count = 0;
		for(int i = a; i <= b; i++){
			char str[] = Integer.toString(i).toCharArray();

			if(str[0] == str[4] && str[1] == str[3]){
				count++;
			}
		}

		System.out.println(count);
	}
}


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

int main()
{
	int N, X;
	cin >> N >> X;
	vector<int> L(N + 1);
	int res = 1;
	for (int i = 0; i < N; i++) {
		cin >> L[i + 1];
		L[i + 1] += L[i];
		res += L[i + 1] <= X;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

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

	int mx = max(a, b);
	mx = max(mx, c);
	
	int res = mx * ((1 << k) - 1);
	cout << a + b + c + res << endl;
	return 0;
}

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

ll M,N,P[1001];

int main(){
	while(scanf("%lld%lld",&N,&M),N){
		for(int i=0;i<N;i++) scanf("%lld",&P[i]);
		vector<ll> d;
		for(int i=0;i<=N;i++) for(int j=0;j<=N;j++)
			d.push_back(P[i]+P[j]);
		sort(d.begin(),d.end());
		d.erase(unique(d.begin(),d.end()),d.end());
		vector<ll>::iterator it;
		ll res=0;
		for(int i=0;i<d.size();i++){
			it=upper_bound(d.begin(),d.end(),M-d[i]);
			if(it!=d.begin()){
				it--;
				res=max(res,*it+d[i]);
			}
		}
		printf("%lld\n",res);
	}
}

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

int main() {
    int n, x; scanf("%d%d", &n, &x);
    vector<int> l(n);
    for (int i = 0; i < n; ++i) scanf("%d", &l[i]);
    sort(l.begin(), l.end(), greater<int>());
    constexpr int kMod = 1'000'000'000 + 7;
    vector<vector<int>> dp(x + 1, vector<int>(n + 1));
    dp[0][0] = 1;
    for (int i = 0; i < n; ++i) {
        vector<vector<int>> nxt(x + 1, vector<int>(n + 1));
        for (int j = 0; j <= x; ++j) {
            for (int k = 0; k <= i; ++k) {
                if (dp[j][k] == 0) continue;
                if (j + l[i] <= x) (nxt[j + l[i]][k + 1] += 1LL * (k + 1) * dp[j][k] % kMod) %= kMod;
                if (k == 0) continue;
                (nxt[j][k] += 1LL * (j - (l[i] - 1) * k) * dp[j][k] % kMod) %= kMod;
                for (int p = 1; p < l[i] && j + p <= x; ++p) (nxt[j + p][k] += 2LL * k * dp[j][k] % kMod) %= kMod;
                for (int p = 0; p < l[i] - 1 && j + p <= x; ++p) {
                    (nxt[j + p][k - 1] += 1LL * dp[j][k] * ((k - 1) * (l[i] - 1 - p)) % kMod) %= kMod;
                }
            }
        }
        dp = nxt;
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) (ans += dp[x][i]) %= kMod;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 728
#include <stdio.h>
#include <math.h>

int main(void)
{
	double x1, y1, x2, y2;
	
	scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
	printf("%f\n", sqrt(pow(x2-x1,2)+pow(y2-y1,2)));
	
	return(0);
}



Measured memory_bytes: 1788
import java.util.Scanner;
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		Scanner sc=new Scanner(System.in);
		int num_1=sc.nextInt();
		int num_2=sc.nextInt();
		String number=num_1+""+num_2;
		int num=Integer.parseInt(number);
		if(Math.pow((int)Math.sqrt(num),2)==num){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 21716
N = int(input())
As = input().split(" ")
As = [int(i) for i in As]
div = [i for i in As if i % 2==0]
No3 = [i for i in div if i % 3 !=0]
deny = [i for i in No3 if i % 5 != 0]
if len(deny)>0:
    print("DENIED")
else:
    print("APPROVED")

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
int cmpint(const void *x, const void *y) { return *(int *)x - *(int *)y; }
int main() {
	int n, s[100], sum = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &s[i]);
		sum += s[i];
	}
	if (sum % 10 != 0) {
		printf("%d\n", sum);
		return 0;
	}
	int dec = sum;
	qsort(s, n, sizeof(int), cmpint);
	for (int i = 0; i < n; i++) {
		if (s[i] % 10 != 0) {
			dec = s[i];
			break;
		}
	}
	printf("%d\n", sum - dec);
	return 0;
}

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

int main(){
  int H1,M1,H2,M2,K;
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  int start=H1*60+M1;
  int end=H2*60+M2;
  cout << end-start-K << endl;
}

Measured memory_bytes: 3636
from fractions import Fraction
N=int(input())
A=[Fraction(input()) for i in range(N)]
def vp(n,p):
    res=0
    m=n
    while(m>0):
        if m%p==0:
            res+=1
            m//=p
        else:
            return res
def div25(f):
    return (vp(f.numerator,2)-vp(f.denominator,2),vp(f.numerator,5)-vp(f.denominator,5))
B=[div25(f) for f in A]
B.sort()
MAX_N=100
C=[[0 for j in range(MAX_N)] for i in range(MAX_N)]
for seq in B:
    x,y=seq
    C[x+MAX_N//2][y+MAX_N//2]+=1
D=[[0 for j in range(MAX_N)] for i in range(MAX_N+1)]
E=[[0 for j in range(MAX_N+1)] for i in range(MAX_N+1)]
for i in range(MAX_N):
    for j in range(MAX_N):
        D[i+1][j]=D[i][j]+C[i][j]
for i in range(MAX_N+1):
    for j in range(MAX_N):
        E[i][j+1]=E[i][j]+D[i][j]
ans=0
for seq in B:
    x,y=seq
    tmp=E[MAX_N][MAX_N]+E[-x+MAX_N//2][-y+MAX_N//2]-E[MAX_N][-y+MAX_N//2]-E[-x+MAX_N//2][MAX_N]
    if x>=0 and y>=0:
        ans+=tmp-1
    else:
        ans+=tmp
print(ans//2)

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

int main(){
      string s, t;
      cin>>s>>t;
      vector<vector<int>>dp(s.size()+1, vector<int>(t.size()+1, 0));
      for(int i=1; i<=s.size(); i++)
      {
            for(int j=1; j<=t.size(); j++)
            {
                  if(s[i-1]==t[j-1])
                        dp[i][j]=dp[i-1][j-1]+1;
                  else dp[i][j]=max(dp[i][j-1], max(dp[i-1][j], dp[i-1][j-1]));
            }
      }
      string ans;
      int i=s.size(), j=t.size();

      while(i>0 && j>0)
      {
            if(s[i-1]==t[j-1]){
                  ans+=s[i-1];
                  i--, j--;
            }

            else {
                  if(dp[i][j]==dp[i][j-1])
                        j--;
                  else i--;
            }
      }

      reverse(ans.begin(), ans.end());
      cout<<ans;
}

Measured memory_bytes: 38544
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]


macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut 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<_>>()
    };

    ($next:expr, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $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")
    };
}


#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    ($arg:expr) => (println!("{:?}",$arg));
}


#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}


use std::cmp;
use std::collections::HashMap;


#[allow(dead_code)]
static INF_I64 :i64 = 9223372036854775807;
#[allow(dead_code)]
static INF_I32 : i32 = 2147483647;
#[allow(dead_code)]
static INF_USIZE : usize = 18446744073709551615;



fn main() {

    input! { 
       n: usize,
       k: i64,
       h : [i64;n],
    }

    let mut ans = 0;

    for item in &h{
        if *item >= k{
            ans +=1;
        }
    }
    
    
    println!("{}",ans);


}


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

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,m,n) for (int i = m; i < n; i++)
#define FORE(x, xs) for (auto &x: xs)
#define PB push_back
#define MP make_pair

const int MAX_M = 4e4;
const int MAX_K = 111;
const int MOD = 1e9+7;

ll dp1[MAX_K][MAX_M];
ll dp2[MAX_M];
int N, K;

vi getNums() {
    vi nums;
    nums.PB(1);
    int lo = 2, hi = N+1;
    while (N/lo != N/hi) {
        while (hi - lo > 1) {
            int mid = (lo+hi) / 2;
            if (N/lo == N/mid) lo = mid;
            else hi = mid;
        }
        nums.PB(lo);
        lo = lo+1;
        hi = N+1;
    }
    return nums;
}

int main() {
    cin >> N >> K;
    vi nums = getNums();
    int M = nums.size();
    dp1[0][0] = 1;
    FOR (i, 1, M) dp1[0][i] = nums[i] - nums[i-1];
    FOR (k, 1, K) {
        dp2[0] = dp1[k-1][0];
        FOR (i, 1, M) dp2[i] = (dp2[i-1] + dp1[k-1][i]) % MOD;
        dp1[k][0] = dp2[M-1];
        FOR (i, 1, M) {
            dp1[k][i] = (dp2[M-1-i] * (nums[i]-nums[i-1])) % MOD;
        }
    }

    ll ans = 0;
    REP (i, M) {
        ans = (ans + dp1[K-1][i]) % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 33656
n,m = map(int,input().split())
a = [0]*m
b = [0]*m
for i in range(m):
    a[i] , b[i] = map(int, input().split())

itv = [[0 for i in range(2)] for j in range(m)]
for i in range(m):
    itv[i][0] = b[i]
    itv[i][1] = a[i]
itv.sort()

ans = 0
curx = 0

for i in range(m):
    if curx <= itv[i][1]:
        curx = itv[i][0]
        ans += 1
        
print(ans)

Measured memory_bytes: 59872
#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();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

struct state{
	int b,e,t;
	state(int _b,int _e,int _t){
		b=_b,e=_e,t=_t;
	}
};

int main(void){
	int n;
	while(cin >> n,n){
		vector<state> files;
		state init(0,1000000000,-1);
		files.pb(init);
		rep(i,n){
			char mode;
			cin >> mode;
			if(mode=='W'){
				int l,s;
				cin >> l >> s;
				rep(i,files.size()){
					if(files[i].t==-1&&s>0){
						int fs=(files[i].e-files[i].b)+1;
						if(s>=fs)
							files[i].t=l,s-=fs;
						else{
							state newfile(files[i].b+s,files[i].e,files[i].t);
							files[i].e=files[i].b+s-1,files[i].t=l,s=0;
							files.insert(files.begin()+i+1,newfile);
						}
					}
				}
			}else if(mode=='R'){
				int p;
				cin >> p;
				int ans=-1;
				rep(i,files.size()) if(files[i].b<=p&&p<=files[i].e) ans=files[i].t;
				cout << ans << endl;
			}else{
				int l;
				cin >> l;
				rep(i,files.size()) if(files[i].t==l) files[i].t=-1;
			}
			//for(auto &i:files){
			//	cout << i.b << " " << i.e << " " << i.t << endl;
			//}
		}
		cout << endl;
	}
	return 0;
}

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

int main(){
 int n;
 double m,sig;

 while(1){
  cin >> n ;
  if(n==0)break;

  double s[1000]={0},sum=0;
  for(int i=0;i<n;i++){
   cin >> s[i] ;
   sum+=s[i];
  }

  m=sum/n;
  sum=0; 

  for(int i=0;i<n;i++){
   sum+=(s[i]-m)*(s[i]-m);
  }

  sig=sqrt(sum/n);

  cout << fixed << sig << endl;
 }

 return 0;
}

Measured memory_bytes: 3284
a, b, c = map(int, input().split())  # a < b < c
k = int(input())

for i in range(k):
    if a >= b:
        b *= 2
    elif b >= c:
        c *= 2
    elif a < b and b < c:
        break


if a < b and b < c:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9168
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  
  vector<int> prices(N+1);
  for (int m = 1; m <= M; ++m) {
    int A;
    cin >> A;
    prices[A] = 1;
  }
  
  int zero = 0;
  for (int i = 1; i < X; ++i) {
    zero += prices[i];
  }
  int n = 0;
  for (int i = X+1; i <= N; ++i) {
    n += prices[i];
  }
  cout << min(zero, n) << endl;
  
  return 0;
}


Measured memory_bytes: 3568
#include <stdio.h>
#define WHITE 0
#define BLACK 1
#define GRAY 2
#define INF 10000000

int n;

void prim();

int main(){
  int i,j,mincost=0,k,u,color[100],M[100][100],d[100],p[100],ans=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf(" %d",&M[i][j]);
    }
  }
  for(i=0;i<n;i++){
    color[i]=WHITE;
    d[i]=INF;
  }
  d[0]=0;
  p[0]=-1;
  while(1){
    mincost=INF;
    for(i=0;i<n;i++){
      if(color[i] != BLACK && d[i] < mincost){
	mincost = d[i];
	u = i;
      }
    }
    if(mincost == INF){
      break;
    }
    
    color[u]=BLACK;
      
      for(k=0;k<n;k++){
       	if(color[k] != BLACK && M[u][k] != -1){
	  if(M[u][k] < d[k]){
	    d[k] = M[u][k];
	    p[k]=u;
	  }
	}
      }
  }
  for(i=0;i<n;i++){
    ans=ans+d[i];
  }
  printf("%d\n",ans);
  return 0;
}

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

int n, k;
int a[100010];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	int g = 0, mx = 0;
	for (int i = 1; i <= n; ++i) g = __gcd(g, a[i]), mx = max(mx, a[i]);
	
	if (mx < k) return printf("IMPOSSIBLE\n"), 0;
	if (g && k % g) return printf("IMPOSSIBLE\n"), 0;
	printf("POSSIBLE\n");
}

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

int main() {
	ll n;
	cin >> n;
	vector<ll> a(n+1), b(n);
	rep(i,n+1) cin >> a[i];
	rep(i,n) cin >> b[i];
	ll ans = 0;
	rep(i,n) {
		ll mons = min(a[i],b[i]);
		ans += mons;
		a[i] -= mons;
		b[i] -= mons;
		mons = min(a[i+1],b[i]);
		ans += mons;
		a[i+1] -= mons;
		b[i] -= mons;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define INF 2e9
#define ll long long
//文字列を右半分、真ん中、左半分の三種類に分けたとき
//右半分の文字列が左半分の反転になるように操作すればよい。

int bit[200006];
int n = 200005;

//BIT
int sum(int i){
    int s = 0;
    while(i>0){
        s += bit[i];
        i -= i & -i; 
    }
    return s;
}

void add(int i, int x){
    while(i<=n){
        bit[i] += x;
        i += i & -i;
    }
}

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

    vector<vector<int>> v(26);
    
    for(int i=0; i<s.size(); i++){
        v[s[i]-'a'].emplace_back(i);
    }

    int tmp=0;
    for(int i=0; i<26; i++){
        if(v[i].size()%2==1){
            tmp++;
        }
    }
    if(tmp>1){
        cout<<"-1"<<endl;
        return 0;
    }

    pair<int, int> p[26];
    for(int i=0; i<26; i++){
        p[i] = make_pair(0, v[i].size()-1);
    }

    int len = s.size() - 1;
    long long ans = 0;

    for(int i=0; i<s.size()/2; i++){
        int t;
        int minCost = INF;

        for(int j=0; j<26; j++){
            if(v[j].size() <= 1){
                continue;
            }

            int front, back;
            tie(front, back) = p[j];
            if(front>=back){
                continue;
            }

            int front_p = v[j][front];
            int back_p = v[j][back];

            int left = front_p -sum(front_p + 1);
            int right = back_p - sum(back_p + 1);

            int cost = left + (len - right);
            if(minCost > cost){
                minCost = cost;
                t = j;
            }
        }

        ans += minCost;
        add(v[t][p[t].first] + 1, 1);
        add(v[t][p[t].second] + 1, 1);
        p[t].first++;
        p[t].second--;
        len -= 2;
    }

    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 2300
M, D = map(int, input().split())


s = 0
for i in range(1, M+1):
    for j in range(22, D+1):
        if int(str(j)[0]) < 2 or int(str(j)[1]) < 2:
            continue
        d10 = str(j)[0]
        d1 = str(j)[1]
        if int(d10) * int(d1) == i:
            s += 1
print(s)

Measured memory_bytes: 3316
import java.util.*;
public class Main{
  public static void main(String args[]){
  Scanner sc = new Scanner(System.in);
  int H = sc.nextInt();
  int W = sc.nextInt();
  int h = sc.nextInt();
  int w = sc.nextInt();
  System.out.println((W*H)-(((w*H)+(h*W))-(w*h)));
  }
}

Measured memory_bytes: 21844