akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;

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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	long dp[100010];
	for(int i=0;i<100010;i++){
		dp[i]=INF;
	}
	dp[0]=0;

	for(int i=1;i<n;i++){
		chmin(dp[i],dp[i-1]+abs(a[i]-a[i-1]));
		if(i>1)chmin(dp[i],dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout << dp[n-1] << endl;
	
	return 0;
}


Measured memory_bytes: 1408
def wa(l):
    for k in range(10):
        for i in range(10):
            for j in range(10):
                l[i][j] = min(l[i][j], l[i][k] + l[k][j])
    return l
h, w = map(int, input().split())
c = [list(map(int, input().split())) for i in range(10)]
a = [list(map(int, input().split())) for i in range(h)]
l = wa(c)
ans = 0
for i in a:
    for j in i:
        if j != -1:
            ans += l[j][1]
print(ans)

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

int dp[3];
int new_dp[3];

int main(){
	int n;
	scanf("%d", &n);
	int c[3];
	for(int i=0; i < n; i++) {
		for(int j=0; j < 3; j++) scanf("%d", &c[j]);
		for(int j=0; j < 3; j++)
			for(int k=0; k < 3; k++)
				if(j != k) new_dp[k] = max(new_dp[k], dp[j] + c[k]);
		for(int j=0; j < 3; j++)
			dp[j] = new_dp[j];
	}
	printf("%d\n", max({dp[0], dp[1], dp[2]}));
}


Measured memory_bytes: 256
def resolve():
    a, b, c = map(int, input().split())
    count = 0
    while True:
        if a % 2 != 0 or b % 2 != 0 or c % 2 != 0:
            break
        _a = b / 2 + c / 2
        _b = a / 2 + c / 2
        _c = a / 2 + b / 2

        if [a, b, c] == [_a, _b, _c]:
            count = -1
            break
        else:
            a, b, c = _a, _b, _c
            count += 1

    print(count)


resolve()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	while(true){
		int n;
		int k=0;
		cin>>n;
		int p[n]={};
		int f=0;
		if(n==0){
			return 0;
		}
		for(int i=0; i<100; i++){
			if(k==n){
				k=0;
			}
			char c;
			cin>>c;
			if(c=='S'){
				f+=p[k]+1;
				p[k]=0;
				
			}else if(c=='L'){
				p[k]+=f+1;
				f=0;
			}else{
				p[k]++;
			}
			k++;
			
		}
		sort(p,p+n);
		for(int i=0; i<n; i++){
			cout<<p[i]<<" ";
		}
		cout<<f<<endl;
	}
}


Measured memory_bytes: 3104
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        try(Scanner sc = new Scanner(System.in)){
            while(true){
                int n = sc.nextInt();
                if(n == 0) break;
                int[] scores = new int[n];
                for(int i=0; i<scores.length;i++){
                    scores[i] = sc.nextInt();
                }
                double sum = 0,average = 0, variance = 0;
                for(int j=0; j<scores.length; j++){
                    sum += scores[j];
                }
                average = sum / scores.length;
                for(int k=0; k<scores.length; k++){
                    variance += ((average-scores[k])*(average-scores[k]))/scores.length;
                }
                System.out.println(Math.sqrt(variance));
            }
        }
    }
}


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

int main()
{
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int n,k;
    cin>>n>>k;
    vector<int> h(n);
    for(int i=0;i<n;i++)
    cin>>h[i];
    int dp[n+1];
    dp[0]=dp[1]=0;
    dp[2]=abs(h[1]-h[0]);
    for(int i=3;i<=n;i++){
        int mi=INT_MAX;
        for(int j=i-1;j>0&&i-j<=k;j--)
        mi=min(mi,dp[j]+abs(h[i-1]-h[j-1]));
        dp[i]=mi;
    }
    cout<<dp[n];
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;
 
public class Main {
 
	public static void main (String[] args)  {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		int d = sc.nextInt();
		int count = 0;
		for (int i = 22; i <= d; i++) {
			if (i % 10 < 2) {
				continue;
			}
			if ((i % 10) * (i / 10) <= m) {
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 21972
package main

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

func main() {
	A, B := ReadString(), ReadString()
	if len(A) == len(B) {
		if A == B {
			fmt.Println("EQUAL")
			return
		}
		if A < B {
			fmt.Println("LESS")
		} else {
			fmt.Println("GREATER")
		}
		return
	}
	if len(A) < len(B) {
		fmt.Println("LESS")
	} else {
		fmt.Println("GREATER")
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }


Measured memory_bytes: 1844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
const int mod = 1e9+7;
ll qpow(ll a,ll b){ll res=1;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int opt[maxn];
int main()
{
    int a,b,c,n;
    cin>>n>>a>>b>>c;
    for(int i = 1;i <= n;++i){
        string d;
        cin>>d;
        if(d=="AB")opt[i]=1;
        else if(d=="AC")opt[i]=2;
        else opt[i]=3;
    }
    string ans;
    bool ok = true;
    for(int i = 1;i <= n;++i){
        if(opt[i]==1){
            if(a==0&&b==0){
                ok=false;
                break;
            }
            else if(a==0){
                b--;
                a++;
                ans+='A';
            }
            else if(b==0){
                a--;
                b++;
                ans+='B';
            }
            else {
                if(opt[i+1]==1){
                    ans+='A';
                    ans+='B';
                    i++;
                }
                else if(opt[i+1]==2){
                    ans+='A';
                    a++;
                    b--;
                }
                else {
                    ans+='B';
                    a--;
                    b++;
                }
            }
        }
        else if(opt[i]==2){
            if(a==0&&c==0){
                ok=false;
                break;
            }
            else if(a==0){
                c--;
                a++;
                ans+='A';
            }
            else if(c==0){
                a--;
                c++;
                ans+='C';
            }
            else {
                if(opt[i+1]==2){
                    ans+='A';
                    ans+='C';
                    i++;
                }
                else if(opt[i+1]==1){
                    ans+='A';
                    a++;
                    c--;
                }
                else {
                    ans+='C';
                    a--;
                    c++;
                }
            }
        }
        else {
            if(c==0&&b==0){
                ok=false;
                break;
            }
            else if(c==0){
                b--;
                c++;
                ans+='C';
            }
            else if(b==0){
                c--;
                b++;
                ans+='B';
            }
            else {
                if(opt[i+1]==3){
                    ans+='C';
                    ans+='B';
                    i++;
                }
                else if(opt[i+1]==2){
                    ans+='C';
                    c++;
                    b--;
                }
                else {
                    ans+='B';
                    c--;
                    b++;
                }
            }
        }
    }
    if(ok){
        printf("Yes\n");
        for(int i = 1;i <= n;++i){
            printf("%c\n",ans[i-1]);
        }
    }
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 4248
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void){
  ll a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a + 3);
  if (a[0] % 2 == 0 || a[1] % 2 == 0 || a[2] % 2 == 0) {
    cout << 0 << endl;
    return 0;
  }
  cout << a[0] * a[1] << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n;
    cin >> n;
    vi a(n);
    rep(i,n)cin >> a[i];
    int ans = INF;
    rep(i,2001){
        int t = 0;
        rep(j,n)t = max(t, abs(a[j]-i));
        ans = min(ans, t);
    }
    cout << ans << endl;
}



Measured memory_bytes: 3108
#ifdef ONLINE_JUDGE

#include "bits/stdc++.h"
using namespace std;

#define ui unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double

#define all(v) v.begin(), v.end()

#define speed ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const ld PI = 3.1415926535897932384626;
ll MOD = 1000000007;
const ld EPS = 1e-9;
const int N = 3e5 + 7;

inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ui setBits(ui v) { ui c; for(c = 0 ; v; ++c) v &= (v - 1); return c; }
inline bool isPowerOfTwo(ui v) { return (v && !(v & (v - 1))); }
ll power(ll base, ull exp, ll mod = MOD) { 
	ll res = 1; base %= mod; 
	while(exp) { 
		if(exp & 1) res = (res * base)%mod; 
		exp >>= 1; base = (base * base)%mod; 
	} 
	return res; 
}
ll modInv(ll a, ll mod = MOD) { 
	if(mod == 1) return 0; 
	ll x = 1, y = 0, m = mod; 
	while(a > 1) { 
		ll q = a/m, t = m; m = a%m; a = t; t = y; y = x - q * y; x = t; 
	} 
	if(x < 0) x += mod; 
	return x; 
}
inline ui iabs(int x) { ui y = x; return (y > 0) ? y : -y; }
inline ll add(ll a, ll b, ll mod = MOD) { ll res = (a%mod + b%mod)%mod; return res; }
inline ll sub(ll a, ll b, ll mod = MOD) { ll res = (a%mod - b%mod + mod)%mod; return res; }
inline ll mult(ll a, ll b, ll mod = MOD) { ll res = (a%mod * b%mod)%mod; return res; }
inline ll div(ll a, ll b, ll mod = MOD) { ll res = (a%mod * modInv(b, mod))%mod; return res; }

#else

#include "custom.h"
using namespace std;

#endif

void openf() {
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif	
}

int main() {
	speed;
	openf();
	int N;
	cin >> N;
	vector<ll> arr(N);
	for(int i = 0 ; i < N ; ++i) {
		cin >> arr[i];
	}
	sort(all(arr), greater<int>());
	ll ans = arr[0], i = 1;
	N -= 2;
	while(N > 1) {
		N -= 2;
		ans += arr[i]*2;
		++i;
	}
	if(N) ans += arr[i];
	cout << ans << endl; 
	return 0;
}  
  

Measured memory_bytes: 4752
from collections import deque

N,M = map(int,input().split())
V=[[] for _ in range(N)]
for i in range(M):
    a,b = map(int, input().split())
    V[a-1].append(b-1)
    V[b-1].append(a-1)
state=[0]*N
q=deque()
ans=[0]*(N)

state[0]=1
q.append(0)
while len(q) > 0:
    v=q.popleft()
    for u in V[v]:
        if state[u]==0:
            state[u]=1
            ans[u]=v+1
            q.append(u)
print('Yes')
print(*ans[1:],sep='\n')

Measured memory_bytes: 39216
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
using vl=vector<ll>;
using vb=vector<bool>;
using vs=vector<string>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
const ll oo =0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })
int main(){ cin.sync_with_stdio(0);
	ll N, Q; cin >> N >> Q;
	string S; cin >> S;

	vl pref(sz(S)+1);

	FOR(i, 1, sz(S)) {
		pref[i] = pref[i-1];
		if (S[i] == 'C' && S[i-1] == 'A') {
			pref[i] ++;
		}
	}

	FOR(i, 0, Q) {
		ll l, r; cin >> l >> r;
		l --, r--;

		ll res = pref[r] - pref[max(l-1, 0ll)];
		if (S[l] == 'C' && l > 0 && S[l-1] == 'A') {
			res --;
		}
		cout << res << endl;
	}
} //cin.tie(0) bei schnellem Wechseln


Measured memory_bytes: 1872
#!/usr/bin/env python3
n = int(input())
p = list(map(lambda p_i: int(p_i) - 1, input().split()))
result = 0
for i in range(n):
    if p[i] == i:
        j = i + 1
        if j >= n:
            j = i - 1
        p[i], p[j] = p[j], p[i]
        result += 1
print(result)


Measured memory_bytes: 13880
#include <iostream>

using namespace std;

int main(void){
	int n;
	int list[11];
	int size;
	while(cin >>n,!cin.eof()){
		int i=1,size=0;
		if(i&n)
			list[size++]=i;
		i <<=1;
		while(i<=n){
			if(i&n)
				list[size++]=i;
 			i <<=1;
		}
		for(i=0;i<size;i++)
			cout << (i?" ":"")  << list[i];
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int A, B;
	
	cin>>A>>B;
	
	cout<<max(max(A+B, A-B),A*B)<<endl;
	
	
	return 0;
}

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

using namespace std;

int N, M;
int num[100005];
set<int> s;

int main(void)
{
	cin >> N >> M;
	for(int i = 1; i <= N; i++) num[i] = 1;
	s.insert(1);
	
	int x, y;
	for(int i = 0; i < M; i++){
		cin >> x >> y;
		if(s.count(x)) s.insert(y);
		num[x]--, num[y]++;
		if(num[x] == 0) s.erase(x);
	}
	
	cout << s.size() << endl;
	return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
	int N,i;
	string s;
	cin>>N;
	cin>>s;
	int bNum=0;
	int rNum=0;
	for (i=0;i<N;i++){
		if (s[i]=='B'){
			bNum++;
		}else{
			rNum++;
		}
	}
	if (rNum>bNum){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int64_t dceil(int64_t, int64_t);
int64_t dfloor(int64_t, int64_t);

int64_t dceil(int64_t x, int64_t y)
{
    if (y < 0) {
        return dceil(-x, -y);
    }
    if (x < 0) {
        return -dfloor(-x, y);
    }
    return (x + y - 1) / y;
}

int64_t dfloor(int64_t x, int64_t y)
{
    if (y < 0) {
        return dfloor(-x, -y);
    }
    if (x < 0) {
        return -dceil(-x, y);
    }
    return x / y;
}

const int64_t MOD = 998'244'353L;

int64_t dpow(int64_t x, int64_t y)
{
    if (y == 0) {
        return 1;
    }
    if (y % 2 == 0) {
        return dpow(x * x % MOD, y / 2);
    } else {
        return x * dpow(x, y - 1) % MOD;
    }
}

int64_t inv(int64_t x)
{
    return dpow(x, MOD - 2);
}

using S = tuple<int64_t, int64_t, int64_t, bool>;
S gcd(int64_t a, int64_t b, int64_t k)
{
    if (a == 0) {
        return S(b, 0, k / b, k % b == 0);
    } else {
        int64_t d, x, y;
        bool p;
        tie(d, x, y, p) = gcd(b % a, a, k);

        return S(d, y - b / a * x, x, p);
    }
}

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

    int64_t d, x, y;
    bool p;
    tie(d, x, y, p) = gcd(a, b, k);
    if (!p) {
        cout << 0 << endl;
        return 0;
    }

    a /= d;
    b /= d;

    vector<int64_t> fact(n + 1);
    irep(i, n)
    {
        if (i == 0) {
            fact[i] = 1;
        } else {
            fact[i] = fact[i - 1] * i % MOD;
        }
    }

    int64_t result = 0;
    for (int64_t t = dceil(-x, b); x + b * t <= n; t++) {
        int64_t w = x + b * t, z = y - a * t;
        if (z >= 0 && z <= n) {
            int64_t c1 = fact[n] * inv(fact[n - w]) % MOD * inv(fact[w]) % MOD;
            int64_t c2 = fact[n] * inv(fact[n - z]) % MOD * inv(fact[z]) % MOD;
            result += c1 * c2 % MOD;
            result %= MOD;
        }
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 2560
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

N, k = mi()
#A[0～N-1]
A = list(mi())

#1がある位置
posOf1 = A.index(1)

#1より左（右）にある数字の数
leftCnt = posOf1
rightCnt = N - 1 - posOf1

#1回の操作につきk-1ずつ減らせるわけだが、1の左からやるとミスると思われる
#↑1回目の操作で、1の左右に触手を伸ばすことができるから
#つまり、まず左側はroundup(leftCnt/(k-1))が答えで、
#左側の答え*(k-1) - leftCnt - 1が正の場合は、その分をrightCntから引く！
ans = 0
#左側の答え
import math
ans += math.ceil(leftCnt / (k-1)) #切り上げ

if ans*(k-1)-leftCnt > 0:
  rightCnt -= (ans*(k-1)-leftCnt)

#右側の答え
ans += math.ceil(rightCnt / (k-1)) #切り上げ

print(ans)



Measured memory_bytes: 52476
n, m = gets.split.map(&:to_i)
isl = {}
m.times do
  i, j = gets.split.map(&:to_i)
  [[i, j], [j, i]].each do |k, l|
    if [1, n].include? k
      if isl[l]
        puts 'POSSIBLE'
        exit
      end
      isl[l] = true
    end
  end
end
puts 'IMPOSSIBLE'


Measured memory_bytes: 14716
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
string ff(int n, int m, vector<int>&q,vector<int>&r, map<pair<int, int>, string>&memo) {
	if (memo.find(make_pair(n, m)) != memo.end()) {
		return memo[make_pair(n, m)];
	}
	if (n == 0) return "";
	string s = "";
	int f = 0;
	rep(i, m) {
		if (n - r[i] >= 0) {
			string tmp = ff(n - r[i], m, q, r, memo);
			if (tmp != "?") {
				tmp = to_string(q[i])+tmp;
				s = (s.size() != tmp.size()) ? ((s.size() > tmp.size()) ? s : tmp) : (s > tmp) ? s : tmp;
				
			}
			else {
				f++;
			}
		}
		else {
			f++;
		}
	}
	if (f == m) {
		return "?";
	}
	memo[make_pair(n, m)] = s;
	return s;
}
int main() {
	int n,m;
	cin >>n>>m;
	vector<int> a(m);
	rep(i, m)cin >> a[i];
	sort(a.begin(), a.end());

	vector<int> qq{ 1,2,3,4,5,6,7,8,9 };
	vector<int> rr{ 2,5,5,4,5,6,3,7,6 };
	vector<int> q;
	vector<int> r;
	for (int i = m - 1; i >= 0; i--) {
		q.push_back(qq[a[i] - 1]);
		r.push_back(rr[a[i] - 1]);
	}
	map<pair<int, int>, string> memo;
	cout << ff(n, m,q,r,memo) << endl;
	return 0;
}

Measured memory_bytes: 32896
#define DEBUG 0

/**
 * File    : D4.cpp
 * Author  : Kazune Takahashi
 * Created : 2019-5-28 12:34:39
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(10101010));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

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

// const int C = 1e6+10;
const ll MOD = 1000000007;

set<string> forbid;
vector<string> C = {"A", "G", "C", "T"};
map<string, ll> M[110];
int N;

void make_string(string S)
{
  if (S.size() == 4)
  {
    for (auto k = 0; k < 2; k++)
    {
      string s = S.substr(k, 3);
      if (s == "AGC")
      {
        forbid.insert(S);
        return;
      }
    }
    for (auto l = 0; l < 3; l++)
    {
      string T = S;
      swap(T[l], T[l + 1]);
      for (auto k = 0; k < 2; k++)
      {
        string s = T.substr(k, 3);
        if (s == "AGC")
        {
          forbid.insert(S);
          return;
        }
      }
    }
    return;
  }
  for (auto x : C)
  {
    make_string(S + x);
  }
}

int main()
{
  cin >> N;
  make_string("");
  M[0]["TTT"] = 1;
  for (auto i = 0; i < N; i++)
  {
    for (auto e : M[i])
    {
      string S = e.first;
      ll cnt = e.second;
      if (cnt == 0)
      {
        break;
      }
      for (auto x : C)
      {
        string T = S + x;
        string U = T.substr(1, 3);
        if (forbid.find(T) == forbid.end())
        {
          if (M[i + 1].find(U) == M[i + 1].end())
          {
            M[i + 1][U] = cnt;
          }
          else
          {
            M[i + 1][U] += cnt;
            M[i + 1][U] %= MOD;
          }
        }
      }
    }
  }
  ll ans = 0;
  for (auto x : M[N])
  {
    ans += x.second;
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 896
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define PI 3.14159265358979323846264338327950L

//マクロ
#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 INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

ll gcd(ll a, ll b){
    if(a % b == 0){
        return(b);
    }
    else{
        return(gcd(b, a % b));
    }
}

bool isPalindrome(string s){
    REP(i, s.length() / 2){
        if(s[i] != s[(s.length() - 1) - i]){
            return false;
        }
    }
    return true;
}

//scanf("%lld", &);
//cin >> ;
//cout << ans << endl;

ll N, M, i, j, k, l, tmp, ans;
ll D, x, y;
ll cnt;

ll sevenUp(ll i){
    return i * 10 + 7;
}

int main(){
    ans = 0;
    cin >> N;

    set<ll> t;

    if((N & 1) == 0){
        cout << -1 << endl;
        return 0;
    }
    // cntは値の桁数
    cnt = to_string(N).length() - 1;
    // sevenはNと同等以上で最小の7の数列
    ll seven = 7;
    REP(i, cnt){
        seven = sevenUp(seven);
    }
    // もし999などでsevenより大きいなら桁数を揚げておく
    if(N > seven){
        seven = sevenUp(seven);
        cnt++;
    }

    t.insert(N);

    while(true){
        int tmp = seven % N;
        if(t.find(tmp) == t.end()){
            t.insert(tmp);
        }else{
            cnt = -2;
            break;
        }

        if(tmp == 0){
            break;
        }
        seven = sevenUp(tmp);
        cnt++;
    }

    cout << (cnt + 1) << endl;

    return 0;
}

Measured memory_bytes: 50492
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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

signed main() {
  init();
  ll H, W;
  cin >> H >> W;
  ll N;
  cin >> N;
  vll A;
  rep(i, N) {
    ll n;
    cin >> n;
    rep(j, n) {
      A.pb(i + 1);
    }
  }

  ll ans[H][W];
  rep(i, A.size()) {
    ll r = i / W;
    ll c = i % W;

    if (r % 2 == 1) {
      c = W - 1 - i % W;
    }

    ans[r][c] = A[i];
  }

  rep(i, H) {
    rep(j, W) {
      if (j == 0) {
        cout << ans[i][j];
      } else {
        cout << " " << ans[i][j];
      }
    }
    ENDL;
  }

  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}


int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int h, w, n;

signed main() {
	cin >> h >> w >> n;
	if (n % (max(h, w)))cout << n / max(h, w) + 1 << endl;
	else cout << n / max(h, w) << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int part1 = n / 100;
        int part2 = n % 100;

        if (part1 <= 12 && part2 <=12 && part1 > 0 && part2 > 0) System.out.println("AMBIGUOUS");
        else if ((part1 > 12 || part1 == 0) && part2 <=12 && part2 > 0) System.out.println("YYMM");
        else if ((part2 > 12 || part2 == 0) && part1 <=12 && part1 > 0)   System.out.println("MMYY");
        else if (part1 > 12 && part2 > 12 || part1 == 0 || part2 == 0) System.out.println("NA");
    }
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define MOD 1000000007
typedef long long ll;

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b+c >= 22){
        cout << "bust" << endl;
    }else cout << "win" << endl;
}



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

int main(){
    int h,n;
    cin>>h>>n;
    int a[n],i,s=0;
    for(i=0;i<n;i++)cin>>a[i];
    for(i=0;i<n;i++){
    	s+=a[i];
	}
	if(s>=h)cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define     bit_1(a)       __builtin_popcount(a)
#define     ull            unsigned long long
#define     ll             long long
#define     pb             push_back
#define     pf             push_front
#define     mpr            make_pair
#define     ins            insert
#define     ff             first
#define     ss             second
#define     vi             vector<int>
#define     vl             vector<ll>
#define     vstr           vector<string>
#define     si             set<int>
#define     sl             set<ll>
#define     li             list<int>
#define     pii            pair<int,int>
#define     pll            pair<ll,ll>
#define     mii            map<int,int>
#define     mll            map<ll,ll>
#define     ma             INT_MAX
#define     mi             INT_MIN
#define     mod            1000000007
#define     pi             3.14159265359
#define     e              2.71828182846
#define     inf            1000000000000000LL
#define     all(x)         x.begin(), x.end()
#define     lb(a,b,c)      lower_bound(a,a+b,c)-a
#define     ub(a,b,c)      upper_bound(a,a+b,c)-a
#define     lbv(a,c)       lower_bound(all(a),c)-a.begin()
#define     ubv(a,c)       upper_bound(all(a),c)-a.begin()
#define     srt1(a,b)      sort(a,a+b)
#define     srt2(a,b)      sort(a,a+b,greater<int>())
#define     gcd(a,b)       __gcd(a,b)
#define     lcm(a,b)       (a*(b/gcd(a,b)))
#define     harmonic(n)    0.57721566490153286l+log(n)
#define     mem(a, b)      memset(a, b, sizeof(a))
#define     orderset1      tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define     orderset2      tree<int,null_type,greater<int>,rb_tree_tag,tree_order_statistics_node_update>

//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move

int main()
{
    string str;
    cin>>str;
    int sz=str.size();
    if(str[sz-1]!='s')cout<<str<<"s\n";
    else cout<<str<<"es\n";
    /*int n;
    cin>>n;
    int A[n+5],B[n+5],cnt=0;
    for(int i=0;i<n;i++)cin>>A[i]>>B[i];
    for(int i=0;i<n;){
        if(A[i]==B[i]){
            cnt=0;
            while(A[i]==B[i]){
                i++;
                cnt++;
                if(i>=n)break;
            }
            if(cnt>=3){
                cout<<"Yes\n";
                return 0;
            }
        }
        else i++;
    }
    cout<<"No\n";*/
    /*int n,cnt=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n/i;j++){
            int m=i*j;
            int dif=n-m;
            if(dif>0 && dif<n)cnt++;
        }
    }
    cout<<cnt<<endl;*/
}




Measured memory_bytes: 3624
#include<bits/stdc++.h> 
#define For(i,j,k) for(int i=j;i<=k;++i)
using namespace std;
int read(){
	int x=0,l=1; char ch=getchar();
	while(!isdigit(ch)) {if (ch=='-') l=-1; ch=getchar();}
	while(isdigit(ch)) x=x*10+(ch^48),ch=getchar();
	return x*l;
}
int main(){
	int e,f,n=read(),x,y,z,lx=0,ly=0,lz=0;
	For(i,1,n){
		x=read(),y=read(),z=read();
		e=x-lx; f=abs(ly-y)+abs(lz-z);
		if (e<f||(e-f)%2==1) printf("No"),exit(0);
		lx=x,ly=y,lz=z;
	}
	printf("Yes");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int sub=0;
    int sum = 0;
    sub = min(k,a);
    k -= sub;
    sum +=sub;
    sub = min(k,b);
    k -= sub;
    if(k==0){
        cout<<sum<<endl;
        return 0;
    }
    sub = min(k,c);
    sum -= sub;
    cout<<sum<<endl;
    
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;            //

int main(void)
{
    string A, B, C;
    cin >> A >> B >> C;

    if (A[A.size() - 1] == B[0] && B[B.size() - 1] == C[0])
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    return (0);
}

Measured memory_bytes: 256
#import string,itertools,fractions,heapq,re,array,bisect
#from math import *
#from collections import Counter
def rl(s): return xrange(len(s))

INF = 2147483647


import sys
stdin = sys.stdin

s = stdin.readline().strip()

rr = sum(a != b for a, b in zip(s, s[1:]))
print rr


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

using namespace std;

int fiv(int a[], int n){
    if(a[n])return a[n];
    if(n == 0)return a[n] = 1;
    if(n == 1)return a[n] = 1;
    return a[n] = fiv(a, n-1) + fiv(a, n-2);
}

int main(void){
    int n;
    cin >> n;
    int a[n+1];
    for(int i = 0; i <= n; i++)a[i] = 0;
    fiv(a, n);
    cout << a[n] << endl;
}


Measured memory_bytes: 3092
#ifdef Prateek
  #include "Prateek.h"
#else
  #include <bits/stdc++.h>
  using namespace std;
  #define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int l,r,d;
   cin >> l >> r >> d;
   int ans = 0;
   f(i,l,r+1){
      ans += (i%d == 0);
   }
   cout << ans << '\n';
   return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<58;
const double pi=acos(-1);
const double eps=1e-7;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;

int main(){
	cin>>n;
	vp a,b;
	int u=0,v=0;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		int t=0,m=0,S=s.size();
		for(int j=0;j<S;j++){
			if(s[j]=='('){
				t++;
				u++;
			}
			else{
				t--;
				v++;
			}
			m=min(m,t);
		}
		if(t>=0) a.push_back({m,t});
		else b.push_back({m-t,-t});
	}
	if(u!=v){
		cout<<"No"<<endl;
		return 0;
	}
	sort(a.rbegin(),a.rend());
	sort(b.rbegin(),b.rend());
	int A=a.size(),B=b.size(),t=0;
	for(int i=0;i<A;i++){
		if(t+a[i].first<0){
			cout<<"No"<<endl;
			return 0;
		}
		t+=a[i].second;
	}
	t=0;
	for(int i=0;i<B;i++){
		if(t+b[i].first<0){
			cout<<"No"<<endl;
			return 0;
		}
		t+=b[i].second;
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 3224
def main():
    import sys
    import heapq
    input = sys.stdin.readline
    N, C, K = [int(x) for x in input().strip().split()]
    T = []
    for _ in range(N):
        heapq.heappush(T, int(input()))
    
    k = 0
    c = 0
    ans = 0
    while T:
        t = heapq.heappop(T)
        if c % C == 0:
            k = t + K
            ans += (c > 0)
            c += 1
        elif t <= k:
            c += 1
        else:
            ans += 1
            c = 1
            k = t + K
    else:
        ans += (c > 0)

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 7112
//BISMILLAH
#include <bits/stdc++.h>
using namespace std;
#define sz 100006
long long int dp[sz];
long long int h[sz];
long long int n;
     long long int solve(long long int i){
         if(i == n-1) return 0;
         else if(i>=n) return INT_MAX;
         long long int left = INT_MAX,right = INT_MAX;
         if(dp[i] != -1) return dp[i];
         if(i+1 <= n-1) left = abs(h[i] - h[i+1]) + solve(i+1);
         if(i+2 <= n-1) right = abs(h[i] - h[i+2]) + solve(i+2);
         dp[i] = min(left,right);
         return dp[i];
     }
int main(){
    memset(dp,-1,sizeof(dp));
    long long int i,j;
    cin >> n;
    for(i = 0;i<n;i++){
        cin >> h[i];
    }
    long long int res = solve(0);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 9876
#include <bits/stdc++.h>
using namespace std;
int main(){
	int H, W, D;
	cin >> H >> W >> D;
	int N = H*W;
	vector<int> AX(N+1);
	vector<int> AY(N+1);
	vector<int> AS(N+1);
	AX[0] = 0;
	AY[0] = 0;
	AS[0] = 0;
	
	for( int i=0; i<H; i++ ){
		for( int j=0; j<W; j++ ){
			int temp;
			cin >> temp;
			AX[temp] = j;
			AY[temp] = i;
		}
	}
	
	for( int i = 1; i <= N; i++ ){
		if( i <= D ){
			AS[i] = 0;
			continue;
		}
		AS[i] = AS[i-D] + abs(AX[i]-AX[i-D]) + abs(AY[i]-AY[i-D]);
	}
	
	/*
	for(int i=0; i<=N; i++){
		cout << i << ": " << AS[i] << endl;
	}
	*/
	
	int Q;
	cin >> Q;
	for(int i=0; i<Q; i++){
		int L, R;
		cin >> L >> R;
		if( L-R ){
			cout << AS[R] - AS[L] << endl;
		} else{
			cout << 0 << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int maxb = (b/k)*k;
		if (maxb >=a) {
			System.out.println("OK");
		}else {
			System.out.println("NG");
		}
		sc.close();
	}
}


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

const int RLEN=1<<18|1;
inline char nc() {
	static char ibuf[RLEN],*ib,*ob;
	(ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
	return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
	char ch=nc(); int i=0,f=1;
	while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
	while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
	return i*f;
}
const int N=1e5+50;
int n,m,a[N],b[N],tot,c1,c[N];
int main() {
	n=rd(), m=rd();
	for(int i=1;i<=m;i++) a[i]=rd(), c1+=a[i]&1;
	if(c1>2) {puts("Impossible"); return 0;}
	for(int i=1;i<=m;i++) if(a[i]&1) b[++tot]=a[i];
	for(int i=1;i<=m;i++) if(!(a[i]&1)) b[++tot]=a[i];
	if(tot>=2) swap(b[2],b[tot]);
	for(int i=1;i<=m;i++) printf("%d ",b[i]);
	putchar('\n');
	c[1]=b[1]-1;
	for(int i=2;i<=m;i++) c[i]=b[i]+(i==m);
	int tot=0;
	for(int i=1;i<=m;i++) if(c[i]) b[++tot]=c[i];
	printf("%d\n",tot+(m==1));
	for(int i=1;i<=tot;i++) printf("%d ",b[i]);
	if(m==1) printf("%d ",1);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const int mod=1000000007;
#define ll long long
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
void printDivisors(int n) 
{
    for (int i=1; i<=sqrt(n); i++) 
    { 
        if (n%i == 0) 
        {
            if (n/i == i) 
                printf("%d ", i); 
  
            else 
                printf("%d %d ", i, n/i); 
        } 
    } 
} 

int _,a,b,n,k,m;
int main() {
	#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    bool flag;
  	int n,a,count=0;cin>>n;
  	int freq[1000001];
  	memset(freq,0,sizeof(freq));
  	std::vector<int> arr,arr1;
  	std::map<int, int> map1;
  	rep(i,0,n){
  		cin>>a;
  		arr.pb(a);
  		map1[a]++;
  	}
  	set<ll>set1;
  	rep(j,0,n){
  		flag=true;
  		int k=arr[j];
  		for (int i=1; i<=sqrt(arr[j]); i++) 
    	{ 
        if (k%i == 0) 
        {
        	set1.insert(i);
        	set1.insert(k/i);
        }
    	}
      	for(auto itr=set1.begin();itr!=set1.end();itr++){
      		if(*itr==arr[j]){
      			if(map1[*itr]>1){
      				flag=false;
      			}
      		}
      		else{
       		if(map1.find(*itr)!=map1.end()){
       			flag=false;
       			break;
       		}
       	  }
       }
       if(flag){
       	 count++;
       }
       set1.clear();
  	  }
  	cout<<count<<endl;
    return 0;
}

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

class BIT{
    public:
    int size;
    vector<int> tree;
    
    void set(int n){
        size = n;
        tree = vector<int>(n+1, 0);
        return;
    }
    
    void add(int n, int a) {
        int x = n;
        while (x <= size){
            tree[x] += a;
            x += (x & -x);
        }
        return;
    }
    
    int sum(int n) {
        int x = n;
        int sum = 0;
        while (x > 0) {
            sum += tree[x];
            x -= (x & -x);
        }
        return sum;
    }
    
};

int main(){
    int N;
    cin >> N;
    
    vector<int> bpos(N+1), wpos(N+1);
    for (int i = 0; i < 2*N; i++) {
        char c;
        int a;
        cin >> c >> a;
        if (c == 'B') bpos[a] = i+1;
        else wpos[a] = i+1;
    }
    int inf = 1e9;
    vector<vector<int>> dp(N+1, vector<int>(N+1, inf));
    dp[0][0] = 0;
    for (int i = 0; i <= N; i++) {
        BIT bit;
        bit.set(2*N+2);
        for (int j = 1; j <= i-1; j++) {
            bit.add(wpos[N+1-j], 1);
        }
        
        if (i >= 1) {
            dp[i][0] = min(dp[i][0], dp[i-1][0] + bit.sum(wpos[N+1-i]));
            bit.add(wpos[N+1-i], 1);
        }
        
        for (int j = 1; j <= N; j++) {
            dp[i][j] = min(dp[i][j], dp[i][j-1] + bit.sum(bpos[N+1-j]));
            bit.add(bpos[N+1-j], 1);
            if (i < N) {
                dp[i+1][j] = min(dp[i+1][j], dp[i][j] + bit.sum(wpos[N-i]));
            }
        }
        
    }
    /*
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= N; j++) {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    */
    cout << dp[N][N] << endl;
    return 0;
    
}

Measured memory_bytes: 16000
N, M = map(int, input().split())
L = 0
R = 1000000
for i in range(M):
    l, r = map(int, input().split())
    if l > L:
        L = l
    if r < R:
        R = r
if R >= L:
    print(R-L+1)
else:
    print(0)

Measured memory_bytes: 3060
/* Coached by rainboy */
#include <stdio.h>
#include <string.h>

#define N 100000
#define V 100000

int max(int a, int b) {
	return a > b ? a : b;
}

int main() {
	static int vv[N], kk[V + 1], mm1[2], mm2[2];
	int n, i, max1, max2, v_, v, r;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &vv[i]);
	for (r = 0; r < 2; r++) {
		memset(kk, 0, sizeof kk);
		for (i = r; i < n; i += 2)
			kk[vv[i]]++;
		max1 = max2 = 0;
		v_ = -1;
		for (v = 0; v <= V; v++)
			if (max1 < kk[v]) {
				max2 = max1;
				max1 = kk[v];
				v_ = v;
			} else if (max2 < kk[v])
				max2 = kk[v];
		mm1[r] = max1;
		mm2[r] = max2;
		vv[r] = v_;
	}
	printf("%d\n", n - (vv[0] != vv[1] ? mm1[0] + mm1[1] : max(mm1[0] + mm2[1], mm1[1] + mm2[0])));
	return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;

using cat = long long;

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout << fixed << setprecision(11);
	int N;
	cin >> N;
	vector<cat> A(N), B(N);
	for(int i = 0; i < N; i++) cin >> A[i];
	for(int i = 0; i < N; i++) cin >> B[i];
	int top = 0;
	for(int i = 0; i < N; i++) if(A[i] > A[top]) top = i;
	{
		vector<cat> A_tmp(N+1, A[top]);
		vector<cat> B_tmp(N+1, 0);
		for(int j = 1; j < N; j++) A_tmp[j] = A[(top+j)%N];
		for(int j = 1; j < N; j++) B_tmp[j] = B[(top+j)%N];
		A = A_tmp;
		B = B_tmp;
	}
	vector<cat> S(N+1, 0);
	for(int i = 1; i <= N; i++) S[i] = S[i-1] + (N-i) * B[i];
	vector<cat> SB(N+1, 0);
	for(int i = 1; i <= N; i++) SB[i] = SB[i-1] + B[i];
	vector<int> st = {0};
	vector< pair<cat, cat> > next_val(N+1);
	next_val[0] = {A[1]-A[0], 1};
	for(int i = 1; i <= N; i++) {
		while((int)st.size() > 1) {
			int id = st[st.size()-2];
			pair<cat, cat> p = {A[i]-A[id]-2*(S[i-1]-S[id])+2*(N-i)*(SB[i-1]-SB[id]), i-id};
			if(next_val[id].first*p.second > p.first*next_val[id].second) break;
			next_val[id] = p;
			st.pop_back();
		}
		st.push_back(i);
		if(i < N) next_val[i] = {A[i+1]-A[i], 1};
	}
	cat ans = 0;
	for(int i = 1; i < (int)st.size(); i++) {
		ans += 2 * A[st[i]];
		int l = st[i-1]+1, r = st[i]-1;
		cat sum = A[l-1] + A[r+1] - 2 * (SB[r]-SB[l-1]);
		while(l < r) {
			ans += 2 * sum;
			sum -= 2 * (SB[r-1]-SB[l]);
			l++, r--;
		}
		if(l == r) ans += sum;
	}
	cout << fixed << setprecision(12) << ans/(2.*N) << "\n";
}


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

int main(){
  vector<int> n(3);
  rep(i,3) cin >> n.at(i);
  if( count(n.begin(),n.end(),5) == 2 && count(n.begin(),n.end(),7) == 1 ){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    L=["dream","dreamer","erase","eraser"]
    S=input()
    N=len(S)
    f=1
    pos=N-1
    while f:
        for i in range(len(L)):
            t=L[i]
            temp=1
            for i in range(len(t)):
                if pos-i<0:
                    temp=0
                    break
                if t[-1-i]==S[pos-i]:
                    continue
                else:
                    temp=0
                    break
                
            if temp:
                pos-=len(t)
                break
        if pos==-1:
            break
        if temp==0:
            f=0
            
    if f==1:
        print("YES")
    else:
        print("NO")
                

main()


Measured memory_bytes: 40432