akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

int main(){
    int n,q;cin>>n>>q;
    vvin edge(n+1);
    int a,b;
    rep(i,n-1){
        cin>>a>>b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    vin root(n+1);
    int p,x;
    rep(i,q){
        cin>>p>>x;
        root[p]+=x;
    }
    vin ans(n+1);
    vbo arrived(n+1,false);
    queue<int> que;que.push(1);
    ans[1]=root[1];arrived[1]=true;
    while(que.size()){
        auto p=que.front();que.pop();
        if(edge[p].size()==0)continue;
        for(auto e:edge[p]){
            if(!arrived[e]){
                ans[e]=ans[p]+root[e];
                que.push(e);
                arrived[e]=true;
            }
        }
    }
    rep2(i,1,n)cout<<ans[i]<<" ";
    cout<<ans[n]<<endl;
}

Measured memory_bytes: 16372
while True:
    n,x=map(int,input().split())
    if n==0 and x==0:
        break
    a=0
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            for k in range(j+1,n+1):
                if i+j+k==x:
                    a=a+1
    print(a)



Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 3001;
int dp[maxn][maxn][2];
int solve(int l, int r, int type,vector<int>&a) {
	if (type == 1) {
		if (dp[l][r][0] != LLONG_MIN)return dp[l][r][0];
		if (r == l)return a[l];
		dp[l][r][0] = max(dp[l][r][0], solve(l + 1, r,2,a) + a[l]);
		dp[l][r][0] = max(dp[l][r][0], solve(l, r - 1, 2, a) + a[r]);
		return dp[l][r][0];
	}
	else {
		if (dp[l][r][1] != LLONG_MAX)return dp[l][r][1];
		if (r == l)return -a[l];
		dp[l][r][1] = min(dp[l][r][1], solve(l + 1, r, 1, a) - a[l]);
		dp[l][r][1] = min(dp[l][r][1], solve(l, r - 1, 1, a) - a[r]);
		return dp[l][r][1];
	}
}
signed main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	vector<int>a(n + 1);
	for (int i = 1; i <= n; i++)cin >> a[i];
	for (int i = 0; i < maxn; i++) {
		for (int j = 0; j < maxn; j++) {
			dp[i][j][0] = LLONG_MIN;
			dp[i][j][1] = LLONG_MAX;
		}
	}
	cout << solve(1, n, 1, a);
	return 0;
}

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

int main() {
	int N, M, X;
	cin >> N >> M >> X;
	
	int C[100100];
	vector<vector<int>> A(N, vector<int>(M));
	for (int i = 0; i < N; i++) {
		cin >> C[i];
		for (int j = 0; j < M; j++) {
			cin >> A.at(i).at(j);
		}
	}

	int minSum = 2000000;
	bool complete = true;



	for (unsigned i = 0; i < (1 << N); i++) {
		int understanding[20];
		for (int i = 0; i < 20; i++) {
			understanding[i] = 0;
		}
		int sum = 0;

		for (int j = 0; j < N; j++) {
			if (i & (1 << j)) {
				//参考書jを選んでいた場合
				sum += C[j];
				for (int k = 0; k < M; k++) {
					understanding[k] += A[j][k];
				}
			}
		}
		for (int k = 0; k < M; k++) {
			if (understanding[k] < X) complete = false;
		}
		if (complete) {
			if (sum < minSum) minSum = sum;
		}
		complete = true;
	}

	if (minSum == 2000000) {
		cout << -1;
	}
	else {
		cout << minSum;
	}
	
	return 0;
}

Measured memory_bytes: 3204
from sys import stdin
import numpy as np
n, k = map(int, stdin.readline().split())
a = np.array(stdin.readline().split(), dtype=np.int64)

ng = 0
ok = 10 ** 9 + 1
while ok - ng > 1:
    mid = (ok + ng) >> 1
    if np.sum(0 - - a // mid - 1) <= k:
        ok = mid
    else:
        ng = mid
print(ok)


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

const ll mod = 1e9+7;



int main()
{
    ll S;
    cin>>S;
    ll dp[2003];
    dp[0]=1;
    dp[1]=0,dp[2]=0;
    for(int i=3;i<=S;++i){
        ll sum=0;
        for(int j=0;j<=i-3;++j){
            sum = (sum + dp[j])%mod;
        }
        dp[i]=sum;
    }
    cout<<dp[S]%mod;
}

Measured memory_bytes: 3596
parseInt(x) = parse(Int, x)
parseArray(x::Array{SubString{String}, 1}) = map(parseInt, x)

function main()
  s = readline() |> strip

  n=length(s)
  ans=0
  ix=Int[]
  for i in 1:n-1
    s[i]=='>' && s[i+1]=='<' && push!(ix, i)
  end
  push!(ix, n)
  i1=1
  for i2 in ix
    # println((i1,i2))
    c1=count(c->c=='<', s[i1:i2])
    c2=i2-i1+1-c1
    # println((c1,c2))
    d=max(c1,c2)
    ans+=d*(d+1)÷2
    d=min(c1,c2)-1
    ans+=d*(d+1)÷2
    i1=i2+1
  end

  println(ans)
end

main()


Measured memory_bytes: 170640
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    A = sorted(A)
    different = True
    for i in range(N-1):
        if A[i] == A[i+1]:
            different = False
    if different:
        print("YES")
    else:
        print("NO")
if __name__ == "__main__":
    main()

Measured memory_bytes: 25172
#include<iostream>
#include<cmath>
#include<algorithm>
#include <string>
int main() {

	long long int n = 0, ans = 0,xyz[1000];
	std::cin >> n;

	xyz[0] = 2;
	xyz[1] = 1;
  if(n==0||n==1){
  std::cout<<xyz[n]<<std::endl;
    return 0;
  }
	for (int i = 2; i <= n; i++) {

		xyz[i] = xyz[i - 1] + xyz[i - 2];
        ans = xyz[i];
      
	}

	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

// mint
int64_t const MOD = 1e9+7;

template<int64_t Prime>
struct mod_int {
  int64_t v_;
  mod_int(int64_t x=0) : v_(x) { normalize(); }
  void normalize() { ((v_ %= Prime) += Prime) %= Prime; }
  mod_int operator+=(mod_int const& r){ (v_ += r.v_) %= Prime; return *this; }
  mod_int operator-=(mod_int const& r){ (v_ += Prime - r.v_) %= Prime; return *this; }
  mod_int operator*=(mod_int const& r){ (v_ *= r.v_) %= Prime; return *this; }
  mod_int operator+(mod_int const& r) { mod_int res(*this); return res += r; }
  mod_int operator-(mod_int const& r) { mod_int res(*this); return res -= r; }
  mod_int operator*(mod_int const& r) { mod_int res(*this); return res *= r; }
  mod_int pow(int x) const {
    int64_t res = 1, v = v_;
    while(x > 0) {
      if(x&1) (res *= v) %= Prime;
      x/=2; (v *= v) %= Prime;
    }
    return mod_int(res);
  }
  mod_int inv() const { return pow(Prime-2); }
};
typedef mod_int<MOD> mint;

int const MAXN=50;
int const MAXK=MAXN*MAXN/2;
mint dp[MAXN+1][MAXN+1][MAXK+1];

int main() {
  int N, K; std::cin >> N >> K;
  if(K%2==1) fin(0);
  K /= 2;
  dp[0][0][0] = 1;
  for(int i = 0; i < N; ++i) for(int j = 0; j <= i; ++j) {
    for(int k = 0; k+j+1 <= K; ++k) {
      dp[i+1][j+1][k+j+1] += dp[i][j][k];
    }
    for(int k = 0; k+j <= K; ++k) {
      dp[i+1][j][k+j] += mint(j+j+1)*dp[i][j][k];
    }
    if(j > 0) for(int k = 0; k+j-1 <= K; ++k) {
      dp[i+1][j-1][k+j-1] += mint(j*j)*dp[i][j][k];
    }
  }
  fin(dp[N][0][K].v_);
  return 0;
}


Measured memory_bytes: 25728
#include<bits/stdc++.h>
using namespace std;
const int N=4e5+5,mod=998244353;
typedef long long ll;
int n;
ll f[N];
char s[N];
bool vis[N];
vector<int>v;
int main()
{
    scanf("%d",&n);
    scanf("%s",s+1);
    for(int i=1;i<=n;i++) s[i+n]='1';
    for(int i=1;i*i<=2*n;i++)
        if(2*n%i==0)
    {
        if(i&1)
            v.push_back(i);
        if(2*n/i!=i&&(2*n/i&1)) v.push_back(2*n/i);
    }
    for(int l=0;l<v.size();l++)
    {
        int k=2*n/v[l],t=k/2;vis[k]=true;
        string a="",b="";
        for(int i=1;i<=t;i++) f[k]=((f[k]<<1)+s[i]-'0')%mod,a+=s[i],b+=s[i]=='1'?'0':'1';
        bool flag=true,ff=false;
        int p=0;
        for(int j=t;j+t<=2*n;j+=t)
        {
            p^=1;
            if(p)
            {
                for(int h=1;h<=t;h++)
                    if(s[j+h]!=b[h-1])
                    {
                        if(s[j+h]<b[h-1]) flag=false;
                        ff=true;
                        break;
                    }
            }
            else
            {
                for(int h=1;h<=t;h++)
                    if(s[j+h]!=a[h-1])
                    {
                        if(s[j+h]<a[h-1]) flag=false;
                        ff=true;
                        break;
                    }
            }
            if(ff) break;
        }
        f[k]+=flag;
    }
    ll ans=0;
    for(int i=2;i<=2*n;i+=2)
        if(vis[i])
    {
        for(int j=i+i;j<=2*n;j+=i)
            if(vis[j])
            f[j]=(f[j]-f[i])%mod;
        ans=(ans+f[i]*i)%mod;
    }
    ans=(ans+mod)%mod;
    printf("%lld\n",ans);
}


Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define pb push_back
#define mod 998244353

const ll N = 5005 ;

ll dp[N][N] ;

int main() {
    ll x = 1 , n , i , j=0 , ans = 0 ,s ,sum = 0,tot = 0;
    cin >> n >> s ;
    vector<ll> a(n+1) ;
    for(i  = 1 ; i<= n;  i++) {
      cin >> a[i]  ;
    }
    dp[0][0]=1 ;
    for (i = 1; i<= n ; i++) {
        for (j = 0 ; j<= s ; j++) {
            dp[i][j] += 2*dp[i-1][j] ;
            dp[i][j]%=mod ;
            if (j+a[i]<=s) {
                  //  cout << j+a[i] << ' ' <<dp[i][j] << endl ;
                dp[i][j+a[i]] += dp[i-1][j] ;
                dp[i][j+a[i]] %= mod ;
                //cout << dp[i][j+a[i]] << ' ' << i << ' ' << j+a[i] << endl  ;
            }
        }
    }

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


Measured memory_bytes: 85908
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) { }
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};

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

    int n, m; cin >> n >> m;
    vector<set<int>> s(m);
    rep(i, n){
        int K; cin >> K;
        rep(j, K){
            int a; cin >> a;
            a--;
            s[a].insert(i);
        }
    }

    UnionFind uf(n);
    rep(i, m){
        int pre = -1;
        for(auto& e : s[i]){
            if(pre == -1){
                pre = e;
                continue;
            }
            uf.unionSet(pre, e);
            pre = e;
        }
    }

    if(uf.size(0) == n){
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 9984
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n=32;
	int size;
	while(cin>>size){
		n=31;
		if(size==0)break;
		int dt[size];
		rep(i,size){
			cin>>dt[i];
		}
		int turn=1;
		int ite=0;
		while(n){
			if(n<=0)break;
			if(turn%2==1){
				n-=(n-1)%5;
				if(n<0) cout<<"0"<<endl;
				else cout<<n<<endl;
			}else{
				n-=dt[ite%size];
				if(n<0) cout<<"0"<<endl;
				else cout<<n<<endl;
				ite++;
			}
			turn++;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#include<iomanip>//浮動小数点数を出力する制度の指定
//使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
using ll =long long;
using db = double;
#define INF 2000000000
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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
/*覚えてないことメaモ
  数値型から文字列に変換　to_string(number);これは簡単
  文字列から数値型に変換　stoi(number)
  文字列からllに変換　stoll(number)
  __gcd(a,b)は最大公約数を取ってくれる、aとb
  の大きい方をNとしたとき、計算量は√N
 */
const int mod = 1e9 + 7;
//ここから書き始める
int main(){
	int n; cin>>n;
	vector<int> l(n); rep(i,n) cin>>l[i];
	SORT(l);
	int ans = 0 ;
	rep(i,n-2){
		for(int j = i + 1 ; j < n-1; j++){
			int dist = (lower_bound(l.begin(),l.end(), l[i]+l[j])-l.begin())-j-1;	
			if(dist > 0 ) ans+=dist;
		}
	}
	cout <<ans<<endl;
}



Measured memory_bytes: 256
fun main(args: Array<String>) {
    val S = readInputLine().toCharArray()
    val T = readInputLine().toCharArray()

    val R1 = mutableMapOf<Char, Char>()
    val R2 = mutableMapOf<Char, Char>()

    for ((i, c) in S.withIndex()) {
        val r1 = R1.get(c) ?: '-'
        val r2 = R2.get(T[i]) ?: '-'
        
        if (r1 == '-') {
            R1.put(c, T[i])
        } else {
            if (r1 != T[i]) {
                println("No")
                return
            }
        }
        
        if (r2 == '-') {
            R2.put(T[i], c)
        } else {
            if (r2 != c) {
                println("No")
                return
            }
        }
    }

    println("Yes")
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 41136
#include<bits/stdc++.h>
using namespace std;
 
int h[100001];
 
int main(){
    long long int n, a, b;
    scanf("%lld %lld %lld",&n,&a,&b);
    long long int sum=0;
    for(int i=0;i<n;++i){
        scanf("%d",&h[i]);
        sum += h[i];
    }
    long long int mt = ceil((double)sum / b);
    long long int left = 0, right = mt;
    while(right - left > 1){
        long long int t = left + (right - left) / 2;
        long long int cnt = 0;
        for(int i=0;i<n;++i){
            if(h[i] > b * t)cnt += ceil((double)(h[i]-b*t)/(a-b));
        }
        if(cnt > t)left = t;
        else right = t;
    }
 
    long long int cnt = 0;
    for(int i=0;i<n;++i){
        if(h[i] > b * left)cnt += ceil((double)(h[i]-b*left)/(a-b));
    }
 
    if(cnt > left) printf("%lld\n",right);
    else printf("%lld\n",left);
 
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
using namespace std;
int main(void){
    int a,b;
    while(1){
        cin>>a>>b;
        if(a==0){
            break;
        }
        for(int x=1;x<=a;x++){
            for(int y=1;y<=b;y++){
                cout<<"#";
            }
            cout<<endl;
        }
        cout<<endl;
    }
}


Measured memory_bytes: 3076
import java.util.Scanner;
public class Main {
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);

        long N = scan.nextLong();

        long A;
        long B;

        int ans=20;

        for(long i=1; i<=Math.sqrt(N); i++){
            int a=0; //Ａの桁数
            int b=0; //Ｂの桁数
            int tmp;
            if(N%i == 0){
                A = i;
                B = N/A;
            }else{
                continue;
            }
            while(A>0){
                A = A/10;
                a++;
            }
            while(B>0){
                B = B/10;
                b++;
            }
            tmp = Math.max(a,b);
            ans = Math.min(ans,tmp);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 1000000001;

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

int gcd_2(int a, int b, int c){
  return gcd(a, gcd(b, c));
}
    

int main(){
  int n;
  ll ans = 0;
  cin >> n;
  rep(i, n){
    rep(j, n){
      rep(k, n){
        ans = ans + gcd_2(i,j,k);
      }
    }
  }
  cout << ans <<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define maxn 100001
#define maxa 2000005
#define MOD 1000000007
#define INF 1000000000000000000

using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define piii pair<pii, ll>
#define ft first
#define sd second
#define rep(i, a, n) for(ll i = a; i < n; i++)
#define repr(i, a, n) for(ll i = n-1; i >= a; i--)
#define meme(a, b) memset(a, b, sizeof(a))

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}
ll ceil(ll a, ll b){if((a%b) != 0) return a/b+1; return a/b;}
void flaged(bool flag){
    if(flag) cout << "Yes\n";
    else cout << "No\n";
}
// power and modulo inverse
ll power(ll a, ll b = MOD-2){
    if(b == 0) return 1;
    ll r = power(a, b/2);
    r = (r*r)%MOD;
    if(b%2 == 1) r = (r*a)%MOD;
    return r;
}
// factorial
ll fact[maxa], finv[maxa];
void calf(){
    fact[0] = finv[0] = 1;
    for(ll i = 1; i < maxa; i++){fact[i] = (fact[i-1]*i) %MOD;finv[i] = (finv[i-1]*power(i))%MOD;}
}
// nCr
ll ncr(ll N, ll R){ if(R > N) return 0; return (fact[N]*((finv[R]*finv[N-R])%MOD))%MOD;}

void solve(){
    ll n, f = 0;
    cin >> n;
    for(ll i = 0; i < n; i++){
        ll x; cin >> x;
        if(x%2 == 0){
            if(!(x%3 == 0 || x%5 == 0)) f= 1;
        }
    }
    cout << (1-f? "APPROVED": "DENIED");

}

int main()
{
    fast();
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}


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

using namespace std;
typedef long long int ll;
int main()
{
 int n;
 cin>>n;
 vector<int> a(n+1,0);
 for(ll i=1;i<=n;i++)
 {
     for(int j=0;j<=n;j+=i)
     {
         a[j]++;
     }
 }
 ll sum=0;
 for(ll i=1;i<=n;i++)
 {
     sum+=a[i]*i;
 }
 cout<< sum<<endl;
   return 0;
}


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

int A[1000];
int ans = 0;

void trace(int A[], int N){
    for (int i = 0; i < N; i++){
        if(i>0){
            printf(" ");
        }
        printf("%d", A[i]);
    }
    printf("\n");
}

void bubbleSort(int A[], int N){
    bool flag = 1;
    // 5 3 2 4 1
    while(flag){
        flag = 0;
        for (int j = N-1; j >=1; j--){
            if(A[j] < A[j-1]){
                int x = A[j];
                A[j] = A[j - 1];
                A[j - 1] = x;
                ans++;
                flag = 1;
            }
        }
    }
    trace(A, N);
}

int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int N;
    cin >> N;
    rep(i, N) cin >> A[i];
    bubbleSort(A, N);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3256
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i, n) for (lint i = 0; i < (n); i++)
#define INF LLONG_MAX
#define all(x) (x).begin(), (x).end()
#define pb push_back
int main()
{
    int x, y;
    cin >> x >> y;
    bool flag = false;
    for (int i = 0; i <= x; i++)
    {
        if (2 * i + 4 * (x - i) == y)
            flag = true;
    }
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <atcoder/all>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

using mint = atcoder::modint998244353;

struct S {
  mint a;
  ll size;
};

struct F {
  mint a, b;
};

S op( S a, S b ) {
  return S{a.a+b.a, a.size+b.size};
}

S e() {
  return S{ 0, 0 };
}

S mapping( F f, S x ) {
  return S{ f.a*x.a+f.b*x.size, x.size };
}

F composition( F f, F g ) {
  return F{ f.a*g.a, f.b+f.a*g.b };
}

F id() {
  return F{ 1, 0 };
}

ll N, Q;

int main() {
  std::cin >> N >> Q;

  std::vector<S> a(N);

  rep( i, N ) {
    ll x;
    std::cin >> x;

    a[i] = S{ x, 1 };
  }

  atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg(a);

  rep( q, Q ) {
    ll t;
    std::cin >> t;

    if( !t ) {
      ll l, r, b, c;
      std::cin >> l >> r >> b >> c;

      seg.apply( l, r, F{ b, c } );
    } else {
      ll l, r;
      std::cin >> l >> r;

      std::cout << seg.prod( l, r ).a.val() << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 31404
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0; i<n; i++) {
            a[i] = sc.nextInt();
        }
        int max = 0;
        for(int i=0; i<n; i++) {
            int b;
            if(i == n-1) {
                b = a[0] + k - a[i];
            } else {
                b = a[i+1] - a[i];
            }
            if(b > max) max = b;
        }
        System.out.println(k - max);
    }
}


Measured memory_bytes: 79860
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
  ll X,now=100;
  cin>>X;
  if(now>=X) cout<<"0"<<endl;
  for(int i=1;;i++){
    ll a=now*0.01;
    now+=a;
    if(now>=X){
      cout<<i<<endl;
      break;
    }
  }
}

Measured memory_bytes: 3632
n=int(input())
l=[[int(i) for i in input().split()] for j in range(n)]

d=[]
for i in range(n):
  for j in range(i):
    d.append(((l[i][0]-l[j][0])**2+(l[i][1]-l[j][1])**2)**0.5)
print(sum(d)*(n-1)/len(d))

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

#define ll long long
#define ld long double
#define pb push_back
#define pob pop_back
#define mp make_pair
#define mod 1000000007
#define forn(i, n)     for(ll i = 0; i< (ll)n; i++)
#define forf(i, x, y)  for(ll i=(x); i< (ll)y; i++)
#define forb(i, x, y)  for(ll i=(x); i>=(ll)y; i--)

using namespace std;


int main()
{
ios_base::sync_with_stdio(0); 
cin.tie(NULL);
cout.tie(NULL);
	
	int n;
	cin>>n;
	int a[n],b[n],c[n];
	forn(i,n)
	{
		cin>>a[i]>>b[i]>>c[i];
	}
	ll ans[n][3];
	ans[0][0]=a[0]; ans[0][1]=b[0]; ans[0][2]=c[0];
	forf(i,1,n)
	{
		ans[i][0]=max(ans[i-1][1],ans[i-1][2]) + a[i];
		ans[i][1]=max(ans[i-1][0],ans[i-1][2]) + b[i];
		ans[i][2]=max(ans[i-1][0],ans[i-1][1]) + c[i];
	}

	cout<<max(ans[n-1][0],max(ans[n-1][1],ans[n-1][2]))<<endl;
return 0;
}

Measured memory_bytes: 3840
import java.util.Scanner;
 
class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();		
		if (n/100 == n%10) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    string s;
    cin >> s;
    string alp = "abcdefghijklmnopqrstuvwxyz";
    vector<bool> a(26,false); 
    rep(i,s.length()){
        a[s[i] - 'a'] = true;
    }

    rep(i,26){
        if(a[i] == false){ 
            cout << alp[i] << endl;
            return 0;
        }
    }
    
    cout << "None" << endl;

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define ll long long
#define pp pair<ll,ll>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
ll max(ll x, ll y)
{
    return x>y ? x : y;
}
ll min(ll x, ll y)
{
    return x<y ? x : y;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a[3][3];
    for (int i = 0; i < 3; ++i)
    {
    	for (int j = 0; j < 3; ++j)
    	{
    		cin >> a[i][j];
    	}
    }
    ll n;cin >> n;ll b[n];
    for (int i = 0; i < n; ++i)
    {
    	cin >> b[i];
    	for (int j = 0; j < 3; ++j)
    	{
    		for (int k = 0; k < 3; ++k)
    		{
    			if(a[j][k]==b[i]){a[j][k]=-1;break;}
    		}
    	}
    }
    for (int i = 0; i < 3; ++i)
    {
    	if(a[i][0]==-1 and a[i][1]==-1 and a[i][2]==-1){cout << "Yes";return 0;}
    }
    for (int i = 0; i < 3; ++i)
    {
    	if(a[0][i]==-1 and a[1][i]==-1 and a[2][i]==-1){cout << "Yes";return 0;}
    }
    if(a[0][0]==-1 and a[1][1]==-1 and a[2][2]==-1){cout << "Yes";return 0;}
    if(a[2][0]==-1 and a[1][1]==-1 and a[0][2]==-1){cout << "Yes";return 0;}
    cout << "No";
    }

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b, d, r;
	double f;
	
	scanf("%d %d", &a, &b);

	d = a / b;
	r = a % b;
	f = (double)a / (double)b;

	printf("%d %d %f\n", d, r, f);

	return 0;
}


Measured memory_bytes: 2120
#include <cstdio>
#include <vector>
#include <algorithm>
#define N 200005

int n;
int a[N], f[N], ans[N];
std::vector<int> v[N];

void dfs(int x, int fa) {
    int p = std::lower_bound(f, f + ans[fa], a[x]) - f;
    int t = f[p];
    f[p] = a[x];
    ans[x] = std::max(ans[fa], p + 1);
    for (int i : v[x])
        if (i != fa)
            dfs(i, x);
    f[p] = t;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", a + i);
    for (int i = 1, x, y; i < n; ++i) {
        scanf("%d%d", &x, &y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(1, 0);
    for (int i = 1; i <= n; ++i) printf("%d\n", ans[i]);
    return 0;
}


Measured memory_bytes: 30028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9 + 7;
const int MAX = 510000;

int main() {
    ll h,w; cin >> h >> w;
    ll n; cin >> n;
    vl a(n);
    rep(i,n) cin >> a[i];
    ll ans[h][w];
    ll yoko;
    ll index = 0;
    rep(i,h){
        rep(j,w){
            if(i%2==0) yoko = j;
            else yoko = w-j-1;
            if(a[index]){
                a[index]--;
            }
            else {
                index++;
                a[index]--;
            }
            ans[i][yoko] = index + 1;
        }
    }
    rep(i,h){
        rep(j,w) cout << ans[i][j] << " ";
        cout << endl;
    }
}

Measured memory_bytes: 384
import java.util.Scanner;
class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int a = 0,b = 0;
		while(scan.hasNext()){
			a = scan.nextInt();
			b = scan.nextInt();
			int sum = a + b;
			int i = 1,count=0;
			while(true){
				if(sum < i){
					System.out.println(count);
					break;
				}
				i *= 10;
				count++;
			}
			if(scan.hasNext() == false){
				break;
			}
		}
	}
}

Measured memory_bytes: 11000
count = {}

S = input()

for s in S:
  count[s] = count[s] + 1 if s in count else 1
  
key_counts = len(count)

if key_counts == 2:
  for v in count.values():
    if v != 2:
      print('No')
      exit()
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int myPower(int a, int n) { // aのn乗の計算
	int x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if ((b / a) > c) {
		cout << c << endl;
	} else {
		cout << (b / a) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include "algorithm"
#include "bits/stdc++.h"
#define ll long long
using namespace std ;
int ans=0;
int main(){
    int n,a;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a;
        if(i%2==1&&a%2==1)
            ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rrep(i,n) REP(i,1,n+1)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> PII;
typedef vector<ll> Vl;
typedef vector<int> VI;
typedef tuple<int, int, int> TT;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(), v.end()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
const int MAX = 500000;
const ll inf = 10000000000000000;
const ll mod = 1000000007;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

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


ll n, ans;
ll t[105];

int main() {

	cin >> n;
	rep(i, n)cin >> t[i];

	ans = t[0];

	rrep(i, n - 1)ans = lcm(ans, t[i]);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    set<char> s;
    for(int i=1;i<=3;i++) {
        char c;
        cin>>c;
        s.insert(c);
    }
    if(s.size()==1) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

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

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] s = new String[n];
        for (int i = 0; i < n; i++) {
            s[i] = sc.next();
        }

        Set<String> sSet = new HashSet<>(Arrays.asList(s));
        System.out.println(sSet.size());
    }
}

Measured memory_bytes: 76528
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 1000000 + 5;

int n;
int a[N], b[N];
int vis[N];
pair<int, int> c[N];

void solve()
{
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> c[i].first >> c[i].second;
    }
    sort(c, c + n);
    int ret = 0;
    for (int i = 0; i < n; i++) {
        int id = -1;
        for (int j = 0; j < n; j++) {
            if (vis[j]) continue;
            if (a[j] > c[i].first || b[j] > c[i].second) continue;
            if (id < 0 || b[id] < b[j]) {
                id = j;
            }
        }
        if (id != -1) {
            ret ++;
            vis[id] = true;
            //cout << c[i].first << ' ' << c[i].second << ' ' << a[id] << ' ' << b[id] << endl;
        }
    }
    cout << ret << endl;
}

int main()
{
    solve();
    return 0;
}



Measured memory_bytes: 6400
#include<stdio.h>

float abs(float a);

int main(void) {

  int N,T,A;
  
  scanf("%d",&N);
  scanf("%d %d",&T,&A);
  
  int H[1000]; 
  int i;
  
  for(i=0;i<N;i++){
    
    scanf("%d",&H[i]);
    
  }
  
  int ans=1;
  float ga=abs(A-(T-H[0]*0.006));
  float gb;
  
  for(i=1;i<N;i++){
    
    gb=abs(A-(T-H[i]*0.006));
    
    if(gb<ga){
      
      ga=gb;
      
      ans=i+1;
    
  	}
  
  }
  printf("%d\n",ans);
    
  return 0;
    
}

float abs(float a){
  
  if(a<0){
    
    return -a;
    
  }
  else{
    
    return a;
    
  }
  
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include <bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
 
int main(){
    int a,b;
    cin>>a>>b;
    if(a*b%2==0) cout << "Even" << endl;
    else cout << "Odd" << endl;
    return 0;

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){

    string s,t;

    cin >> s >> t;

    if(s.length() != t.length() - 1){
        printf("No");
        return 0;
    }

    FOR(i,0,s.length()){
        if(s[i] != t[i]){
            printf("No");
            return 0;
        }
    }

    printf("Yes");

    return 0;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef long long ll;
typedef long long integer;
//////////////////////////////////////////////////
int main(){
    int bal = 0;
    int ans = 0;
    string X;
    getline(cin,X);
    int l = X.length();

    REP(i,l){
        char s = X[i];
        if (s == 'S') bal++;
        else bal--;

        ans = min(bal,ans);
    }

    if (ans == 0) PRINTD(0);
    else PRINTD(-2*ans);

}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename V>
V compress(V v){
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  return v;
}
template<typename T>
map<T, Int> dict(const vector<T> &v){
  map<T, Int> res;
  for(Int i=0;i<(Int)v.size();i++)
    res[v[i]]=i;
  return res;
}
map<char, Int> dict(const string &v){
  return dict(vector<char>(v.begin(),v.end()));
}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;

  using P = pair<Int, Int>;
  vector<P> ans;

  Int d=n%3;
  for(Int i=0;i<n;i++){
    for(Int j=0;j<n;j++){
      if((i+j)%2==0) continue;
      if(i==0||j==0) ans.emplace_back(i,j);

      if(i<d) continue;
      if((i-d)%3==1) ans.emplace_back(i,j);
    }
  }


  ans=compress(ans);
  cout<<ans.size()<<endl;
  for(auto p:ans) cout<<p.first<<" "<<p.second<<endl;
  return 0;
}


Measured memory_bytes: 7020
n,k = map(int,input().split())

arr=list(map(int,input().split()))
inf =1e9+5
dp = [inf]*(n)

dp[0] = 0

for i in range(n):
    for j in range(i+1,i+k+1):
        if j < n:
            dp[j] = min(dp[j],dp[i]+abs(arr[i]-arr[j]))
            
            
print(dp[n-1])

Measured memory_bytes: 55136
#include<stdio.h>
int main(void){
    int H,W,i=0,j=0;
    while(1){
        scanf("%d %d",&H,&W);
        if(H==0&W==0)break;

    for(i=0;i<H;i++){
        for(j=0;j<W;j++){
            printf("#");
        }
        printf("\n");
    }
    printf("\n");
    }
return 0;

}

Measured memory_bytes: 572
import copy
N=int(input())
X=list(map(int,input().split()))
B=[]
P=copy.copy(X)
X.sort()
a=X[N//2-1]
b=X[N//2]
for i in range(N):
  if P[i]<=a:
    B.append(b)
  else:
    B.append(a)
for j in range(N):
  print(B[j])

Measured memory_bytes: 32684
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int S = sc.nextInt();
        int s = S % 60;
        int m = (S / 60) % 60;
        int h = S / 3600;

		System.out.printf("%d:%d:%d",h, m ,s);
		System.out.println();

		sc.close();

	}

}


Measured memory_bytes: 26340
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>


int main(void)
{
	//変数の宣言
	
	int n,k;
	int temp=0;
	long int ans=0;
	int i,j;
	
	//データの読み込み
	scanf("%d %d",&n,&k);
	
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	for(i=1;i<n+1;i++){
		if(i>=k){
			temp=(i-k)*(n/i);
			if(n%i-k+1>0){
				if(k==0){
					temp=temp+n%i-k;
				}else{
					temp=temp+n%i-k+1;
				}
			}
//			printf("i=%d temp=%d\n",i,temp);
		}else{
			temp=0;
		}
		ans=ans+temp;
	}
	
	
//	printf("計算部分終了\n");
	
	//出力
	
	
	printf("%ld",ans);
	
	
//	printf("結果の出力終了\n");
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b); 
#define chmax(a,b) if((a)<(b)) (a)=(b);
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a=a%b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e10+10;
struct Edge{int to,weight;};

/*----------------------------------------------*/
string s[50];


signed main(){
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  int check=0;
  int left=0,right=n-1;
  while(left<right){
    if(check<=0){
      check+=a[left];
      left++;
    }else{
      check-=a[right];
      right--;
    } 
  }
  int ans=INF;
  chmin(ans,abs(check+a[left]));
  chmin(ans,abs(check-a[left]));
  cout<<ans<<endl;;
  
  return 0;
}

Measured memory_bytes: 1792
n,k=map(int,input().split())
S=[0]*n

for _ in range(k):
	d=int(input())
	A=list(map(int,input().split()))
	for a in A:
		S[a-1]+=1

res=0
for i in range(n):
	if S[i]==0:
		res+=1

print(res)

Measured memory_bytes: 9216
#include <iostream>

int main(int argc, char const *argv[]) {
  int i=1;
  while(1){
    int x;
    std::cin >> x;
    if(x==0)break;
    std::cout << "Case " << i << ": "<< x << std::endl;
    i++;
  }
  return 0;
}

Measured memory_bytes: 2996
#include<bits/stdc++.h>
using namespace std;
const int md=1e9+7;
int n,k,ans,f[2005][2005],s[2005];
int main()
{
	scanf("%d%d",&n,&k);
	f[0][n+1]=1;s[n+1]=1;
	for(int i=n;i>=1;i--)s[i]=s[i+1]+f[0][i];
	for(int i=1;i<=k-1;i++)
	{
		for(int j=1;j<=n-i+1;j++)f[i][j]=s[j];
		s[n+1]=f[i][n+1];
		for(int j=n;j>=1;j--)s[j]=(s[j+1]+f[i][j])%md;
	}
	for(int i=2;i<=n+1;i++)ans=(ans+f[k-1][i])%md;
	for(int i=1;i<n-k;i++)ans=ans*2%md;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 15360
using System;
using System.IO;
using System.Linq;

namespace ABC121A
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                Console.SetIn(new StreamReader(args[0]));
            }

            new Program().Solve();
        }

        void Solve()
        {
            var temp = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var H = temp[0];
            var W = temp[1];
            temp = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var h = temp[0];
            var w = temp[1];

            Console.WriteLine(((H - h) * (W - w)));
        }
    }
}


Measured memory_bytes: 13396
//コンパイラ最適化用
#pragma GCC optimize("Ofast")
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#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,accumulate
#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;

//コンパイラ最適化用
#pragma GCC optimize("Ofast")
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#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,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;

signed main(){
  int L, R, d;
  int res = 0;

  cin >> L >> R >> d;
  for (int i = L; i <= R; i++)
    if (i % d == 0) res++;

  cout << res << endl;

  return 0;
}

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

long long MOD = 1000000007;

long long power(long long base, long long n)
{
    if (n == 0) return 1;
    if (n==1) return base;
    long long halfn = power(base, n/2);
    if (n % 2 == 0) return (halfn*halfn)%MOD;
    return (((halfn*halfn) % MOD) * base) % MOD;
}

long long inverse(long long n)
{
    return power(n, MOD-2);
}
long long binom(long long n, long long m)
{
    long long ans = 1;
    for (int i = 0; i < m; i++)
    {
        ans *= (n-i); ans %= MOD;
        ans *= inverse(m-i); ans %= MOD;
    }
    return ans;
}

struct segtree
{
    int sz; vector<int> maxi;
    void init(int n)
    {
        sz = n; maxi.assign(4*n, 0);
    }
    void update(int v, int tl, int tr, int pos, int val)
    {
        if (tl == tr) {
            maxi[v] = max(maxi[v], val);
            return;
        }
        int tm = (tl + tr) / 2;
        if (pos <= tm) update(2*v, tl, tm, pos, val);
        else update(2*v+1, tm+1, tr, pos, val);
        maxi[v] = max(maxi[2*v], maxi[2*v+1]);
    }
    void update(int pos, int val)
    {
        update(1, 0, sz-1, pos, val);
    }
    int getMax(int v, int tl, int tr, int l, int r)
    {
        if (tl == l && tr == r) return maxi[v];
        if (l > r) return 0;
        int tm = (tl + tr)/2;
        return max(getMax(2*v, tl, tm, l, min(r, tm)), getMax(2*v+1, tm+1, tr, max(l, tm+1), r));
    }
    int getMax(int pos, int k)
    {
        return getMax(1, 0, sz-1, max(0, pos-k), min(sz-1, pos+k));
    }
    int maximum(){
        return maxi[1];
    }
};
int main()
{
    ios::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    segtree st; st.init(300001);
    for (int i = 0; i < n; i++)
    {
        int a; cin >> a;
        st.update(a, st.getMax(a, k) + 1);
    }
    cout << st.maximum() << '\n';
    return 0;
}


Measured memory_bytes: 8012
#include<bits/stdc++.h>
using namespace std;
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define uii             unordered_map<int,int>
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
void S_K_S()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}


int32_t main()
{
	S_K_S();
	int n;
	cin >> n;
	int a[n], sum = 0,ans=0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		ans+=a[i]*sum;
		ans%=mod;
		sum+=a[i];
		sum%=mod;
	}
	cout<<ans;
}


Measured memory_bytes: 5148