akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
	string buf;
	vector< vector<int> > paper(14,vector<int>(14,0));
	while((cin>>buf)!=NULL){
		vector<int> a(3);
		for(int i=0;i<3;++i){
			a[i]=buf[2*i]-'0';
		}
		if(a[2]==1){
			const int dx[]={0,0,0,1,-1};
			const int dy[]={0,1,-1,0,0};
			for(int i=0;i<5;++i){
				++paper[a[0]+2+dx[i]][a[1]+2+dy[i]];
			}
		}else if(a[2]==2){
			const int dx[]={0,0,0,1,1,1,-1,-1,-1};
			const int dy[]={0,1,-1,0,1,-1,0,1,-1};
			for(int i=0;i<9;++i){
				++paper[a[0]+2+dx[i]][a[1]+2+dy[i]];
			}
		}else if(a[2]==3){
			const int dx[]={0,0,0,1,1,1,-1,-1,-1,0,2,0,-2};
			const int dy[]={0,1,-1,0,1,-1,0,1,-1,2,0,-2,0};
			for(int i=0;i<13;++i){
				++paper[a[0]+2+dx[i]][a[1]+2+dy[i]];
			}
		}
	}
	int cnt=0;
	int max=0;
	for(int i=2;i<12;++i){
		for(int j=2;j<12;++j){
			if(paper[i][j]==0){
				++cnt;
			}else{
				if(paper[i][j]>max) max=paper[i][j];
			}
		}
	}
	cout << cnt << endl;
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 0
# coding: utf-8

# https://atcoder.jp/contests/abc099/tasks
# 15:00-


def main():
    N = int(input())
    INF = 10**6

    moneys = [1]

    n = 1
    while 9**n <= N:
        moneys.append(9**n)
        n += 1

    n = 1
    while 6**n <= N:
        moneys.append(6**n)
        n += 1

    dp = [[INF] * (N+1) for _ in range(len(moneys))]
    for i in range(len(dp)):
        dp[i][0] = 0
    
    for i in range(len(dp)):
        for j in range(N+1):
            if j + moneys[i] <= N:
                dp[i][j+moneys[i]] = min(dp[i][j]+1, dp[i][j+moneys[i]])
                if i+1 < len(dp):
                    dp[i+1][j+moneys[i]] = min(dp[i][j]+1, dp[i+1][j+moneys[i]])
            if i+1 < len(dp):
                dp[i+1][j] = min(dp[i][j], dp[i+1][j])
    
    return dp[-1][-1]


print(main())


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

using namespace std;

#define mp(x,y) (make_pair(x,y))
typedef pair<int,int> pii;
typedef vector<int> Vec;
typedef vector<Vec> Mat;

int getMaxArea(Vec &h)
{
    int n=h.size();
    vector<int> l(n),r(n);
    stack<pii> st;
    for(int i=0;i<n;i++)
    {
        while(!st.empty()&&st.top().first>=h[i])
        {
            st.pop();
        }
        if(!st.empty())
        {
            l[i]=st.top().second+1;
        }else
        {
            l[i]=0;
        }
        st.push(mp(h[i],i));
    }
    while(!st.empty())
    {
        st.pop();
    }
    for(int i=n-1;i>=0;i--)
    {
        while(!st.empty()&&st.top().first>=h[i])
        {
            st.pop();
        }
        if(!st.empty())
        {
            r[i]=st.top().second;
        }else
        {
            r[i]=n;
        }
        st.push(mp(h[i],i));
    }
    int area=0;
    for(int i=0;i<n;i++)
    {
        area=max(area,h[i]*(r[i]-l[i]));
    }
    return area;
}

int main()
{
    int H,W;
    while(cin>>H>>W)
    {
        Mat mat(H,Vec(W));
        for(int i=0;i<H;i++)
        {
            for(int j=0;j<W;j++)
            {
                cin>>mat[i][j];
            }
        }
        Vec h(W);
        int area=0;
        for(int i=0;i<H;i++)
        {
            for(int j=0;j<W;j++)
            {
                if(mat[i][j])
                {
                    h[j]=0;
                }else
                {
                    h[j]++;
                }
            }
            area=max(area,getMaxArea(h));
        }
        cout<<area<<endl;
    }

    return 0;
}



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

#define PI (3.141592653589793)

int main()
{
    double ang_to_rad = PI / 180;	/*Change degree to radius*/
    double now_angle = 90;
    double x = 0, y = 0;
    double distance = 0, angle = 0;
    int final_x, final_y;

    while (1)
    {
        scanf("%lf,%lf", &distance, &angle);

        if (distance == 0 && angle == 0)
            break;
        if (distance < 0 || distance > 100 || angle < -180 || angle > 180)
            continue;

        x += distance * cos(now_angle * ang_to_rad);
        y += distance * sin(now_angle * ang_to_rad);
        now_angle -= angle;
    }

    final_x = x;
    final_y = y;
    printf("%d\n%d\n", final_x, final_y);


    return 0;
} 

Measured memory_bytes: 632
# import sys
# input = sys.stdin.readline

def mp(): return map(int, input().split())
def lmp(): return list(map(int, input().split()))
import math
from functools import reduce

def gcd(numbers):
    return reduce(math.gcd, numbers)
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

n = int(input())
a = lmp()
agcd = gcd(a)
used = set()
flag = True
for i in range(n):
    tar = a[i]
    if tar == 1:
        pass
    else:
        f = factorization(tar)
        for j in range(len(f)):
            if f[j][0] not in used:
                used.add(f[j][0])
            else:
                flag = False
                break
        if not flag:
            break
if flag:
    print("pairwise coprime")
elif agcd == 1:
    print("setwise coprime")
else:
    print("not coprime")





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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

#define INF 1e9

int main(){
  int N, K, R, S, P;
  string T;
  cin >> N >> K;
  cin >> R >> S >> P;
  cin >> T;
  int score = 0;
  string taka;
  REP(i, N){
    if(i < K){
      taka += T[i];
      if(taka[i] == 's'){
        score += R;
      }
      else if(taka[i] == 'p'){
        score += S;
      }
      else{
        score += P;
      }
      // if(T[i] == 'r'){
      //   taka+= 'p';
      // }
      // else if(T[i] == 's'){
      //   taka += 'r';
      // }
      // else{
      //   taka += 's';
      // }
    }
    else{
      if(T[i] == taka[i-K]){
        taka += 'l';
      }
      else{
        taka += T[i];
        if(taka[i] == 's'){
          score += R;
        }
        else if(taka[i] == 'p'){
          score += S;
        }
        else{
          score += P;
       }
      }
    }
  }
  cout << score << endl;
  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>

int main(){
	
	int ans=0,N,d[60],i,j;
	scanf("%d",&N);
	
	for(i=1;i<=N;i++){
		scanf("%d",&d[i]);
	}
	
	for(i=1;i<=N;i++){
		for(j=i+1;j<=N;j++){
				ans+=d[i]*d[j];
		}
	}
	
	
	printf("%d",ans);
	
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
	int n,m;char a[20];
	scanf("%d%d%s",&n,&m,a+1);
	int len=strlen(a+1);
	if(len!=n+m+1){
		printf("No\n");
		return 0;
	}
	for(int i=1;i<=len;++i){
		if(i!=n+1){
			if(!isdigit(a[i])){
				printf("No\n");
				return 0;
			}
		}else{
			if(a[i]!='-'){
				printf("No\n");
				return 0;
			}
		}
	}printf("Yes\n");
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static long Solve(int W, int H, int[] P, int[] Q)
        {
            var edges = new List<Tuple<int, int>>();
            for (int i = 0; i < W; ++i) { edges.Add(new Tuple<int, int>(P[i], 0)); }
            for (int i = 0; i < H; ++i) { edges.Add(new Tuple<int, int>(Q[i], 1)); }
            edges.Sort();
            long sum = 0;
            int x = W + 1;
            int y = H + 1;
            foreach (var edge in edges)
            {
                switch (edge.Item2)
                {
                case 0:
                    sum += Math.BigMul(edge.Item1, y);
                    --x;
                    break;
                case 1:
                    sum += Math.BigMul(edge.Item1, x);
                    --y;
                    break;
                }
            }
            return sum;
        }

        static void Main(string[] args)
        {
            int[] V = ReadInts();
            int W = V[0], H = V[1];
            var P = new int[W];
            for (int i = 0; i < W; ++i) { P[i] = ReadInt(); }
            var Q = new int[H];
            for (int i = 0; i < H; ++i) { Q[i] = ReadInt(); }
            Console.WriteLine(Solve(W, H, P, Q));
        }
    }
}


Measured memory_bytes: 28432
#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;

int MCXI2D(string str){
    int d = 1;
    int sum = 0;
    int p = 0;
    while (p < str.size()) {
        if (isdigit(str[p])) {
            d = str[p] - '0';
        }else{
            if (str[p] == 'm') {
                sum += d * 1000;
            }else if (str[p] == 'c'){
                sum += d * 100;
            }else if (str[p] == 'x'){
                sum += d * 10;
            }else if (str[p] == 'i'){
                sum += d * 1;
            }
            d = 1;
        }
        p++;
    }
    return sum;
}

string D2MCXI(int a, int b){
    int sum = a + b;
    string ans = "";
    int m = sum / 1000;
    sum %= 1000;
    int c = sum / 100;
    sum %= 100;
    int x = sum / 10;
    sum %= 10;
    int i = sum;

    if (m != 0) {
        if (m == 1) {
            ans += "m";
        }else{
            ans += (m + '0');
            ans += "m";
        }
    }
    if (c != 0){
        if (c == 1){
            ans += "c";
        }else{
            ans += (c + '0');
            ans += "c";
        }
    }
    if (x != 0){
        if (x == 1){
            ans += "x";
        }else{
            ans += (x + '0');
            ans += "x";
        }
    }
    if (i != 0){
        if (i == 1){
            ans += "i";
        }else{
            ans += (i + '0');
            ans += "i";
        }
    }
    return ans;
}



int main()
{
    string str1, str2;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> str1 >> str2;
        cout << D2MCXI(MCXI2D(str1), MCXI2D(str2)) << endl;
    }

    return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    lint N;
    cin >> N;
    VEC(lint) V(5);
    READVEC(V);
    lint mn = *min_element(ALL(V));

    // t >= 5, (t - 5) * mn >= N
    lint ret = 5 + (N - 1) / mn;
    cout << ret << endl;
    return 0;
};


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define ff first
#define ss second
#define all(v) (v).begin(), (v).end()
#define mod (int)(998244353)
#define PI 3.14159265358979323846264338327950L
#define debug(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i<<" "; cout<<endl
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << "[ " << *it << " = " << a << " ] ";
    err(++it, args...);
}

signed main(){

    fastIO

    int fre[(int)1e6+6];
    memset(fre, 0, sizeof(fre));
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++){
    	cin >> a[i];
    	fre[a[i]]++;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
    	bool found = false;
    	if (fre[a[i]] >= 2) continue;

    	for (int j = 1; j*j <= a[i]; j++) {
    		if (a[i]%j == 0) {
    			int f = j, s = a[i]/j;
    			int val = fre[f];
    			if (j == a[i]) {
    				val--;
    			}
    			if (val > 0) {
    				found = true;
    				break;
    			}
    			val = fre[s];
    			if (s == a[i]) {
    				val--;
    			}
    			if (val > 0) {
    				found = true;
    				break;
    			}
    		}
    	}
    	if (!found) {
    		ans++;
    	}
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N;
  cin>>N;
  int a,b,c,d,e,f,g,h;
  a=(N/10000000);
  b=((N-10000000*a)/1000000);
  c=((N-10000000*a-1000000*b)/100000);
  d=((N-10000000*a-1000000*b-100000*c)/10000);
  e=((N-10000000*a-1000000*b-100000*c-10000*d)/1000);
  h=(N%10) ;
  g=((N%100-h)/10);
  f=((N%1000-g*10-h)/100);
  int x;
  x=N%(a+b+c+d+e+f+g+h);
  if(x==0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

ll a[1005],b[1005],c[1005],ans,n,m;
bool ch[3];

void cal(){
	vector<pair<ll,ll>>d;
	for(ll i=0;i<n;i++){
		ll now=0;
		if(ch[0]){
			now+=a[i];
		}
		else{
			now-=a[i];
		}
		if(ch[1]){
			now+=b[i];
		}
		else{
			now-=b[i];
		}
		if(ch[2]){
			now+=c[i];
		}
		else{
			now-=c[i];
		}
		d.push_back(make_pair(now,i));
	}
	sort(d.begin(),d.end());
	ll sum1,sum2,sum3;
	sum1=sum2=sum3=0;
	for(ll i=0;i<m;i++){
		ll now=d[i].second;
		sum1+=a[now];
		sum2+=b[now];
		sum3+=c[now];
	}
	ans=max(ans,abs(sum1)+abs(sum2)+abs(sum3));
}

void dep(ll now){
	if(now==3){
		cal();
		return ;
	}
	ch[now]=0;dep(now+1);
	ch[now]=1;dep(now+1);
}

int main() {
	cin>>n>>m;
	for(ll i=0;i<n;i++){
		cin>>a[i]>>b[i]>>c[i];
	}
	dep(0);
	cout <<ans;
	// your code goes here
	return 0;
}

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

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

typedef long long LL;
typedef long double LD;

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

    count = 0;
    for (int i = min(a, b); i >= 1; i--) {
        if (a % i == 0 && b % i == 0) {
            // cout << i << endl;
            if (++count == k) {
                cout << i << endl;
                break;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
import sys
N,M = map(int,input().split())
s = [0] * M
c = [0] * M
a = ["-1"] * (N)
if N == 1 and M == 0:
    print(0)
    sys.exit()
for i in range(M):
    s[i],c[i] = map(int,input().split())

for j in range(M):
    if s[j] == 1 and c[j] == 0 and N != 1:
        print(-1)
        sys.exit()
    elif a[s[j]-1] == "-1":
        a[s[j]-1] = str(c[j])
    elif a[s[j]-1] == str(c[j]):
        pass
    else:
        print(-1)
        sys.exit()
if a[0] == "-1":
    a[0] = "1"
for h in range(1,N):
    if a[h] == "-1":
        a[h] = "0"
ans = "".join(a)
print(int(ans))

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

int main() {
  vector<int> d(3);
  cin >> d.at(0) >> d.at(1) >> d.at(2);
  sort(d.begin(), d.end());
  cout << d.at(0) + d.at(1) + d.at(2) * 10 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    #define ll long long int
    #define f(i,n) for(ll i=0;i<n;i++)
    #define fz for(ll j=i+1;j<n;j++)
    #define f2(i,n) for(ll i=1;i<=n;i++)
    #define endl "\n"
    #define vll vector <ll>
    #define sz(a) (ll)a.size()
    #define mod 1000000007
    #define pb push_back
    #define inf 1e13+5

    ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
    ll lcm(ll a, ll b){return a*b/gcd(a, b);}
    ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%mod; b/=2;a=a*a%mod;}return ans;}
    ll inverse(ll a, ll p){return fexp(a, p-2);} 

    
    
    void solve(){
      ll n,W;cin>>n>>W;
      ll wt[n+1]={0},val[n+1]={0};
      f2(i,n){
          cin>>wt[i]>>val[i];
      }
      ll dp[100003][103]={0};
      for(ll i=1;i<=n;i++){
          for(ll w=1;w<=W;w++){
              dp[w][i]=dp[w][i-1];  //ith item not taken 
              if(w-wt[i]>=0){
                    if(dp[w-wt[i]][i-1]+val[i]>dp[w][i-1]){
                      dp[w][i]=dp[w-wt[i]][i-1]+val[i];
                    }
              }
          }
      }
      cout<<dp[W][n]<<endl;

    }


    int main(){
        ios_base::sync_with_stdio(0) ;
        cin.tie(0) ; cout.tie(0) ;

        

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

       

        
        return 0;
    }

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

int main(){
  string a;
  cin>>a;
  if (a[0]==a[1]&&a[1]==a[2]) {
    cout<<"Yes"<<endl;
  }
  else if (a[3]==a[1]&&a[1]==a[2]){
    cout<<"Yes"<<endl;
  }
  else {
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
 int n;
 double a[100], a_inv[100];
 double ans, don = 0;
  
  scanf("%d", &n);
  for(int i = 0; i < n; i++ ){
    scanf("%lf", &a[i]);
    a_inv[i] = 1 / a[i];
  }
  
  for(int i = 0; i < n; i++)
    don += a_inv[i];
  ans = 1 / don;
  
  printf("%f\n", ans);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
using namespace std;

#define LL long long

const int MAXN = 200000 + 5;
const LL MOD = 1000000000 + 7;
LL a[MAXN];

int main()
{
    int N;
    LL sum, ans, mul;
    cin >> N;
    for (int i = 0; i < N; i ++){
        cin >> a[i];
    }
    sum = mul = ans = 0;
    for (int i = N - 1; i >= 0; i --){
        mul = (a[i] * sum) % MOD;
        sum = (sum + a[i]) % MOD;
        ans = (ans + mul) % MOD;
    }
    cout << ans;
    system("pause");
    return 0;
}

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

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) 
{
    os << "{ ";
    for(auto& y : x) 
    {
        os << y << " ";
    }
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) 
{
    return os << "[" << p.ff << ", " << p.ss << "]";
}

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

    return gcd(b, a%b);
}

ll modexp(ll a, ll b, ll c)
{   
    a%=c;

    ll ans = 1;

    while(b)
    {
        if(b&1)
        {
            ans = (ans*a)%c;
        }

        a = (a*a)%c;
        b >>= 1;
    }

    return ans;
}

const ll L = 1e6+5;

vector <bool> isPrime(L, true);

void sieve()
{
    isPrime[0] = false;
    isPrime[1] = false;

    for(ll i=2; i<L; i++)
    {
        if(isPrime[i])
        {
            for(ll j=2*i; j<L; j+=i)
            {
                isPrime[j] = false;
            }
        }
    }
}

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

    sieve();

    ll X;
    cin >> X;

    X--;

    while(X++)
    {
        if(isPrime[X])
        {
            cout << X << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 384
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define MSG(x) std::cout << #x << " : " << x << "\n";
using namespace std;
using lint = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const static lint FibMax = 100001;
int N;
vector<int> h;
int Fib[100001];

int main()
{
    cin >> N;
    h.resize(N);
    rep (i, N) { cin >> h[i]; }
    rep (i, FibMax)
    {
        Fib[i] = INT_MAX;
    }

    Fib[0] = 0;
    Fib[1] = abs(h[1] - h[0]);

    for (int i = 2; i < N; ++i)
    {
        int a = Fib[i - 2] + abs(h[i-2] - h [i-1]) + abs(h[i-1] - h[i]);
        int b = Fib[i - 2] + abs(h[i-2] - h[i]);
        int c = Fib[i - 1] + abs(h[i-1] - h[i]);
        Fib[i] = min(min(a, b), c);
    }

    cout << Fib[N - 1] << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
using namespace std;


//B - Kagami Mochi
//集計処理
//バケット法
int main() {
    int N;
    int d[110];
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> d[i];

    int num[110] = {0};  // バケット
    for (int i = 0; i < N; ++i) {
        num[d[i]]++;  // d[i] が 1 個増える
    }

    int res = 0;  // 答えを格納
    for (int i = 1; i <= 100; ++i) {  // 1 <= d[i] <= 100 なので 1 から 100 まで探索
        if (num[i]) {  // 0 より大きかったら
            ++res;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
//q4 abc064
#include <cstdio>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <tuple>
#define pb push_back
#define mkt make_tuple
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
const int INF =  2147483647;
const ll INFLL = 9223372036854775807;



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

  int n;
  cin >> n;
  string s;
  cin >> s;
  n = s.size();
  int mae = 0, ushiro = 0;
  for (size_t i = 0; i < n; i++) {
    if (s[i] == ')') {
      if (ushiro == 0) {
        mae++;
      } else {
        ushiro--;
      }

    } else if (s[i] == '(') {
      ushiro++;
    }
  }
  string mae_concat = "", ushiro_concat = "";
  for (size_t i = 0; i < mae; i++) {
    mae_concat += '(';
  }
  for (size_t i = 0; i < ushiro; i++) {
    ushiro_concat += ')';
  }

  cout << mae_concat + s + ushiro_concat << endl;
  return 0;
}


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





int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;
    string a,s;cin>>a>>s;
    string as;
    int l=0,j=0;
    for(int i=0;i<2*n;i++)
    {
        if(i%2==0)
        {
            as.push_back(a[l]);
            l++;
        }
        else
        {
            as.push_back(s[j]);
            j++;
        }
    }
    cout<<as;
    return 0;
}


Measured memory_bytes: 256
/**
 * @author: Jun
 * @date  : 03-14-2019
 **/
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
#define el '\n'
#define MOD 1000000007

int n,m;
int arr[50];
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    memset(arr, 0, sizeof arr);
    cin >> n >> m;
    for(int i=1;i<=n;i++){
        int t;
        cin >> t;
        while(t--){
            int a;
            cin >> a;
            arr[a]++;
        }
    }
    int cnt=0;
    for(int i=1;i<=m;i++){
        if(arr[i]==n){
            cnt++;
        }
    }
    cout << cnt << el;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>

using namespace std;

typedef long long ll;

ll Solve(vector<ll> L, vector<ll> R) {
  int n = L.size();
  sort(L.rbegin(), L.rend());
  sort(R.begin(), R.end());
  ll x = 0;
  ll result = 0;
  for (int i = 0; i < n; ++i) {
    if (L[i] >= x) {
      result += L[i] - x;
      x = L[i];
    } else {
      break;
    }

    if (R[i] <= x) {
      result += x - R[i];
      x = R[i];
    } else {
      break;
    }
  }
  result += abs(x);
  return result;
}

int main()
{
  int n;
  cin >> n;
  vector<ll> L(n), R(n);
  for (int i = 0; i < n; ++i) {
    cin >> L[i] >> R[i];
  }

  ll result = Solve(L, R);
  for (int i = 0; i < n; ++i) {
    L[i] *= -1;
    R[i] *= -1;
  }
  swap(L, R);
  result = max(result, Solve(L, R));
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3424
#include<stdio.h>
int main(){
  char s[]="abc",x[4];
  int i,a=0,b=0,c=0;
  scanf("%s",x);
  for(i=0;i<3;i++){
     if(s[0]==x[i])
       a++;
  	 if(s[1]==x[i])
       b++;
     if(s[2]==x[i])
       c++;
  }
  if(a==1&&b==1&&c==1)
   printf("Yes");
  else
   printf("No");
  return 0;
  }


Measured memory_bytes: 128
s = input()

def manyformulas(s):
    if len(s)==1:
        return 1,int(s[0])
    else:
        sum = int(s)
        count = 1
        for i in range(len(s)-1):
            c, recursive = manyformulas(s[(i+1):])
            sum += c*int(s[:(i+1)]) + recursive
            count += c

        return count, sum

print(manyformulas(s)[1])


Measured memory_bytes: 3060
#include<stdio.h>

int main()
{
    int n,i,max,min,a[10000];
    long int sum;

    scanf("%d",&n);
    for(i = 0; i < n; i++) {
      scanf("%d",&a[i]);
    }
    
    max = min = a[0];
    sum = 0;

    for(i = 0; i < n; i++) {
      if(a[i] > max) {
        max = a[i];
      }
      if(a[i] < min) {
        min = a[i];
      }
    sum = sum + a[i];
    }

    printf("%d %d %ld\n",min,max,sum);

    return 0;
}

Measured memory_bytes: 640
//https://atcoder.jp/contests/abc140/tasks/abc140_a
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;cin>>N;
    cout<<N*N*N<<endl;    
    return 0;
}

Measured memory_bytes: 256
k,t = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)
as.sort! {|a,b| b <=> a}

as = as.map.with_index do |a, i|
  [a, i]
end

last_cake = nil
ans = 0

as.sort! {|a,b| b <=> a}

while as[0][0] != 0
  if last_cake.nil?
    last_cake = 0
    as[0][0] -= 1
    next
  end

  if as[0][1] == last_cake
    if as[1].nil? || as[1][0] == 0
      ans += 1
      as[0][0] -= 1
      last_cake = as[0][1]
    else
      as[1][0] -= 1
      last_cake = as[1][1]
    end
  else
    as[0][0] -= 1
    last_cake = as[0][1]
  end

  as.sort! {|a,b| b <=> a}
end

puts ans


Measured memory_bytes: 16856
# cook your code here
from sys import stdin
a = stdin.readline().strip()
l = len(a)
s = 0
t = 0
i = l-1
while i>=0:
    if a[i]=='T':
        t+=1 
    else:
        if t>0:
            t-=1 
        else:
            s+=1
    i-=1 
print s+t            

Measured memory_bytes: 3072
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

#define mod 1e9+7
#define ll long long int
#define epsilon 1e-7

ll mi(ll x, ll y){
    if(x<y)return x;
    return y;
}
int rr[8];
int d[200][200];
int a[8];
int main(void){
    int n, m, r;
    scanf("%d %d %d", &n, &m, &r);
    for(int i = 0;i < r;i++){
        scanf("%d", &rr[i]);
        rr[i]--;
    }
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            d[i][j] = mod;
        }
    }
    for(int i = 0;i < m;i++){
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        d[a-1][b-1] = c;
        d[b-1][a-1] = c;
    }
    for(int k = 0;k < n;k++)for(int i = 0;i < n;i++)for(int j = 0;j < n;j++)d[i][j] = mi(d[i][j], d[i][k] + d[k][j]);
    for(int i = 0;i < 8;i++){
        a[i] = i;
    }
    int mii = mod;
    do {
        int mm = 0;
        for(int i = 0;i < r - 1;i++){
            mm += d[rr[a[i]]][rr[a[i+1]]];
        }
        mii = mi(mii, mm);
    }while(next_permutation(a, a + r));
    printf("%d\n", mii);
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int* x; int* y;
    x = new int[n]; y = new int[n];
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> y[i];
    }
    double d;
    for (int i = 0; i < n; i++) {
        double e = x[i]-y[i];
        if (e < 0) e = e*(-1);
        d += e;
    }
    cout << fixed << setprecision(6) << d << "\n";
    d = 0;
    for (int i = 0; i < n; i++) {
        d += (x[i]-y[i])*(x[i]-y[i]);
    }
    cout << sqrt(d) << "\n";
    d = 0;
    for (int i = 0; i < n; i++) {
        double e = x[i]-y[i];
        if (e < 0) e = e*(-1);
        d += e * e * e;
    }
    cout << cbrt(d) << "\n";
    d = 0;
    for (int i = 0; i < n; i++) {
        double e = x[i]-y[i];
        if (e < 0) e = e *(-1);
        if (d < e) d = e;
    }
    cout << d << "\n";
}

Measured memory_bytes: 3428
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var st = Console.ReadLine().Trim().Split(' ');
            var chars = new char[n * 2];
            for (var i = 0; i < n; i++)
            {
                var index = 2 * i;
                chars[index] = st[0][i];
                chars[index + 1] = st[1][i];
            }
            Console.WriteLine(new string(chars));
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
const long long MOD = 1e9+7, INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}



signed main(){
	int N;
	cin>>N;
	vector<int> a(N); for(auto& e:a)cin >> e;
	sort(ALL(a));
	double t = a[0];
	REP(i,N-1){
		t = (t + a[i+1]) / 2.0;
	}
	printf("%.10lf\n",t);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define Printv(v)                                                              \
  {                                                                            \
    FOREACH(x, v) { cout << x << " "; }                                        \
    cout << "\n";                                                              \
  }
#define int long long

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<vector<int>> xyz(N, vector<int>(3));
  int ans = -1;
  REP(i, N) { cin >> xyz[i][0] >> xyz[i][1] >> xyz[i][2]; }
  for(int bit = 0; bit < (1 << 3); bit++) {
    vector<int> sum(N, 0);
    for(int j = 0; j < N; j++) {
      for(int i = 0; i < 3; i++) {
        if(bit & (1 << i)) {
          sum[j] += xyz[j][i];
        } else {
          sum[j] -= xyz[j][i];
        }
      }
    }
    sort(rall(sum));
    int tmp = 0;
    REP(k, M) { tmp += sum[k]; }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <functional>
#define inf 1000000
using namespace std;
typedef long long ll;
const int MAXN=1e5+10;
const int MAX=1e5+10;
const double eps=1e-6;



int main(){
    #ifdef ONLINE_JUDGE
    #else
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    #endif

	int n;
	int last=0,score;
	int t,temp;
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%d %d",&t,&temp);
		if(t>last){
			last=t;
			score=temp;
		}
	}
	cout<<last+score<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

int main()
{
    ll S;
    cin >> S; 

    ll dp[S+10];
    dp[0] = 0;
    dp[1] = 0;
    dp[2] = 0;
    dp[3] = 1;
    dp[4] = 1;
    dp[5] = 1;

    for(ll i = 6; i <= S; i++){
        dp[i] = (dp[i - 1]%MOD + dp[i - 3]%MOD)%MOD;
    }

    cout << dp[S] << endl;

    return 0;
}

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

int main()
{
  string s;
  getline(cin,s);
  int n=s.length();
  if(s[n-1]=='s'){
    s.push_back('e');
    s.push_back('s');
  }
  else
    s.push_back('s');
  cout<<s;
  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef pair<char, char> c_c;
typedef pair<int, int> i_i;

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

    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    bool flag=true;
    for(int i=0; i<n; i++){
        if(a[i]%2==0){
            if(!((a[i]%3==0) || (a[i]%5==0))){
                flag = false;
                //cout << a[i] << endl;
                break;

            }
        }
    }
    if(flag) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Math;
using static System.Console;
using static exMath;
using static exReadLine;


class Program
{
    static void Main(string[] args)
    {
        long N, A, B;
        longReadLine(out N, out A, out B);
        long ab = A + B;
        long ans = N / ab * A;
        ans += Min(A, N % ab);
        WriteLine(ans);
        //ReadLine();
    }
}

static class exReadLine
{
    public static void intReadLine(out int a)
    {
        a = int.Parse(ReadLine());
    }
    public static void intReadLine(out int a, out int b)
    {
        int[] input = ReadLine().Split().Select(int.Parse).ToArray();
        a = input[0];
        b = input[1];
    }
    public static void intReadLine(out int a, out int b, out int c)
    {
        int[] input = ReadLine().Split().Select(int.Parse).ToArray();
        a = input[0];
        b = input[1];
        c = input[2];
    }
    public static void intReadLine(out int a, out int b, out int c, out int d)
    {
        int[] input = ReadLine().Split().Select(int.Parse).ToArray();
        a = input[0];
        b = input[1];
        c = input[2];
        d = input[3];
    }

    public static void longReadLine(out long a)
    {
        a = long.Parse(ReadLine());
    }
    public static void longReadLine(out long a, out long b)
    {
        long[] input = ReadLine().Split().Select(long.Parse).ToArray();
        a = input[0];
        b = input[1];
    }
    public static void longReadLine(out long a, out long b, out long c)
    {
        long[] input = ReadLine().Split().Select(long.Parse).ToArray();
        a = input[0];
        b = input[1];
        c = input[2];
    }
    public static void longReadLine(out long a, out long b, out long c, out long d)
    {
        long[] input = ReadLine().Split().Select(long.Parse).ToArray();
        a = input[0];
        b = input[1];
        c = input[2];
        d = input[3];
    }
    
    public static int[] intArrayReadLine()
    {
        return ReadLine().Split().Select(int.Parse).ToArray();
    }

    public static long[] longArrayReadLine()
    {
        return ReadLine().Split().Select(long.Parse).ToArray();
    }

    public static List<int> intListReadLine()
    {
        return ReadLine().Split().Select(int.Parse).ToList();
    }

    public static List<long> longListReadLine()
    {
        return ReadLine().Split().Select(long.Parse).ToList();
    }
}

static class exMath
{
    // 最大公約数
    public static int Gcd(int a, int b)
    {
        if (a < b) return Gcd(b, a);
        while (b != 0)
        {
            var r = a % b;
            a = b;
            b = r;
        }
        return a;
    }
    public static long Gcd(long a, long b)
    {
        if (a < b) return Gcd(b, a);
        while (b != 0)
        {
            var r = a % b;
            a = b;
            b = r;
        }
        return a;
    }

    // 最小公倍数
    public static long Lcm(int a, int b)
    {
        return BigMul(a, b) / Gcd(a, b);
    }
    public static long Lcm(long a, long b)
    {
        return a * b / Gcd(a, b);
    }
}

Measured memory_bytes: 13396
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    int a,b,c,d,n;
    ll ans=0;
    cin >> a >> b >> c >> d >> n;
    vector<pair<ll,char>>p;
    p.push_back(make_pair(a * 8, 'a'));
    p.push_back(make_pair(b * 4, 'b'));
    p.push_back(make_pair(c * 2, 'c'));
    p.push_back(make_pair(d, 'd'));
    sort(all(p));
    if (n >= 2)ans = p[0].first * ll(n / 2);
    if (n % 2 != 0) {
        if (p[0].second != 'd')ans += (p[0].first / 2);
        else ans += (p[1].first / 2);
    }
    cout << ans << endl;
    return 0;
}


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

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main() {
	int a, b;
	cin >> a >> b;
	if(a*b % 2 != 0)
		cout << "Yes" << endl;
	else
		cout << "No " << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	/*string str,str2;
	cin>>str>>str2;
	int a,b;
	cin>>a>>b;
	string s;
	cin>>s;
	(str==s)?cout<<a-1<<" "<<b:cout<<a<<" "<<b-1;*/
	
	/*string str;
	cin>>str;
	int n = str.size();
	for(int i = 0;i<n;i++)
		cout<<'x';*/
		
	int n;
	cin>>n;
	set<int> s;
	for(int i = 0;i<n;i++){
		int a;
		cin>>a;
		if(s.find(a)==s.end()){
			s.insert(a);
		}else{
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
	return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <cstring>

using namespace std;

			    
int main() {

  vector<int> hand;

  int sum;
  int one;
  char buf[100000];
  
  char* tp;


  while(fgets(buf,sizeof(buf),stdin)!=NULL) {

    buf[strlen(buf)-1]='\0';

    hand.clear();

    tp=strtok(buf," ");

    if(tp[0]=='1') {

      if(tp[1]!='\0') hand.push_back(10+(tp[1]-'0'));

      else hand.push_back(1);

    }

    else hand.push_back(tp[0]-'0');

    if(hand[0]==0) break;

    while(tp!=NULL) {

      tp=strtok(NULL," ");

      if(tp!=NULL) {

	if(tp[0]=='1') {

	  if(tp[1]!='\0') hand.push_back(10+(tp[1]-'0'));

	  else hand.push_back(1);

	}

	else hand.push_back(tp[0]-'0');

      }

    }

    //for(int i=0;i<hand.size();i++) cout << hand[i] << " ";
    //cout << endl;
    sum=one=0;

    for(int i=0;i<hand.size();i++) {

      if(hand[i]==1) one++;

      else if(hand[i]>=10 && hand[i]<=13) sum+=10;

      else sum+=hand[i];

    }

    for(int i=0;i<one;i++) sum+=11;

    for(int i=0;i<one;i++) {

      if(sum>21) sum-=10;

    }

    if(sum>21) sum=0;

    cout << sum << endl;
    
  }

  return 0;

}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
typedef long long i64;
int n, k, p[N], t[N], ans, cnt; i64 s;
void add(int x, int d) { for( ; x <= n; x += x&-x) t[x] += d; }
int ask(int x) { int y = 0; for( ; x; x ^= x&-x) y += t[x]; return y; }
int main()
{
    scanf("%d%d", &n, &k); for(int i = 1; i <= n; ++i) scanf("%d", p+i), ++p[i];
    for(int i = k; i; --i) s += ask(p[i]), add(p[i], 1); ans = s > 0, cnt = s == 0;
    for(int i = k+1, w = 0, v; i <= n; ++i) 
    {
        w = (v = ask(p[i-k]-1)) > 0, add(p[i-k], -1), s -= v,
        w |= (v = k-1-ask(p[i])) > 0, add(p[i], 1), s += v, 
        ans += w&&s > 0, cnt += s == 0;
    }
    printf("%d\n", ans+(cnt > 0));
    return 0;
}

Measured memory_bytes: 5328
import java.util.*;



class Main {
	Scanner sc = new Scanner(System.in);

	public void run() {
		while(sc.hasNext()){
			char[][] UD=new char[5][4];
			char[][] LR=new char[4][5];

			for(int i=0;i<4;i++){
				UD[i]=sc.next().toCharArray();
				LR[i]=sc.next().toCharArray();
			}
			UD[4]=sc.next().toCharArray();

			char[][][] root=new char[5][5][4];

			for(int i=0;i<5;i++){
				for(int j=0;j<4;j++)
					root[i][j][0]=UD[i][j];
				root[i][4][0]='0';

				if(i==0){
					for(int j=0;j<5;j++)
						root[i][j][1]='0';
				}else{
					for(int j=0;j<5;j++)
						root[i][j][1]=LR[i-1][j];
				}
				root[i][0][2]='0';
				for(int j=1;j<5;j++)
					root[i][j][2]=UD[i][j-1];

				if(i==4){
					for(int j=0;j<5;j++)
						root[i][j][3]='0';
				}else{
					for(int j=0;j<5;j++)
						root[i][j][3]=LR[i][j];
				}
			}

			int px=0,py=0;
			int rotate=0;//0 1 2 3
			do{
				for(int i=4-1;i>=0;i--){
					int r=(rotate+i+2)%4;
					if(root[py][px][r]=='1'){
						rotate=r;
						switch(r){
						case 0:pr("R");px++;break;
						case 1:pr("U");py--;break;
						case 2:pr("L");px--;break;
						case 3:pr("D");py++;break;
						}
						break;
					}
				}
			}while(!(px==0 && py==0));
			ln();
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 11000
#include <iostream>
#include "algorithm"
#include <map>
#include <vector>
#include<string>
#include <functional> // std::greater
using namespace std;
bool cmp(const pair<int, int>& a, const pair<int, int>& b) {
        return a.second > b.second;
}
int main(int argc, char *argv[])
{
	int n;
	while(cin>>n)
	{
		int i;
		int maxji = 0,maxou = 0;
		int jik = 0,ouk = 0;
		map<int,int> mj;
		map<int,int> mo;
		for(i =0;i<n;i++)
		{
			int shu;
			cin>>shu;
			
			if(i % 2 == 0)
			{
				mo[shu] += 1;
				if(mo[shu] > maxou)
				{
					maxou = mo[shu];
					ouk = shu;
				}
			}
			else if(i % 2 != 0)
			{
				mj[shu] += 1;
				if(mj[shu] > maxji)
				{
					maxji = mj[shu];
					jik = shu;
				} 
			}
		}
		typedef pair<int, int> PAIR;
		vector<PAIR> vecj(mj.begin(), mj.end());
    	//对线性的vector进行排序
    	sort(vecj.begin(), vecj.end(), cmp);
    	vector<PAIR> veco(mo.begin(), mo.end());
    	//对线性的vector进行排序
    	sort(veco.begin(), veco.end(), cmp);
    	//for (int i = 0; i < veco.size(); ++i)
//   		{
//  			cout<<"key"<<veco[i].first<<endl;
//  			cout<<"value"<<veco[i].second<<endl;
//   		}
		if (jik == ouk)
		{
			//cout<<"mj"<<mj[jik]<<endl;    
			//cout<<"mo"<<mo[ouk]<<endl;
			 if(mj[jik] > mo[ouk])
			{
				
				
				int twoo = 0;
				for (int i = 0; i < veco.size(); ++i)
        		{
		        	if(veco[i].first != jik)
		        	{
	        			twoo = veco[i].second;
	        			break;
	        		}
		        }
				cout<<n - mj[jik] - twoo<<endl;
			}
			else if(mj[jik] < mo[ouk])
			{
				int twoj = 0;
				for (int i = 0; i < vecj.size(); ++i)
        		{
        		/*
	cout<<vecj[i].first<<endl;
        			cout<<vecj[i].second<<endl;
        			cout<<"ouk"<<ouk<<endl;*/
		        	if(vecj[i].first != ouk)
		        	{
		        		
	        			twoj = vecj[i].second;
	 
	        			break;
	        		}
		        }
				cout<<n - mo[ouk] - twoj<<endl;
			}
			else if(mj[jik] == mo[ouk])
			{
				int twoo = 0;
				for (int i = 0; i < veco.size(); ++i)
        		{
		        	if(veco[i].first != jik)
		        	{
	        			twoo = veco[i].second;
	        			break;
	        		}
		        }
		        int twoj = 0;
				for (int i = 0; i < vecj.size(); ++i)
        		{
		        	if(vecj[i].first != ouk)
		        	{
	        			twoj = vecj[i].second;
	        			break;
	        		}
		        }
		        int tt = max(twoo,twoj);
		        cout<<n - mo[ouk] - tt<<endl;
			}
		}
		else
		{
			cout<<n-(mj[jik]+mo[ouk])<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 5760
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using i64 = int64_t;

__attribute__((constructor)) static void init()
{
    ios::sync_with_stdio(false);
    std::cin.tie(0);
}

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

    if (s.length() <= k) {
        cout << s << endl;
        return 0;
    }

    string res = s.substr(0, k);
    cout << res << "..." << endl;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using  namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long n,m,a[100000],i,sum=0,res;
    cin>>n>>m;
    for(i=0;i<m;i++){
        cin>>a[i];
    }
    for(i=0;i<m;i++){
        sum+=a[i];
    }

    res=n-sum;
    if(res>-1)cout<<res<<endl;
    else cout<<-1<<endl;


}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A,B,C;
    cin>>A>>B>>C;
    if(A<=B && B/A >= C){
    cout<< C <<endl;
    }else if (A<=B && B/A < C){
        cout<< B/A <<endl;
    }else if (A > B){
        cout<< 0 <<endl;
    }
}

Measured memory_bytes: 3644
Q = int(input())
AB = [sorted([int(_) for _ in input().split()]) for _ in range(Q)]

for a, b in AB:
    s = a * b
    r = int(s**0.5)

    def calc(x):
        if x == 0:
            return
        elif s % x:
            return s // x
        else:
            return s // x - 1

    ans = 2 * r - 1
    if a == b or calc(r) == r:
        ans -= 1
    elif calc(r) < r:
        ans -= 2
    print(ans)


Measured memory_bytes: 3188
#!/usr/bin/env python3
K  =int(input())
from collections import deque
cnt = 1
q = deque([])
for i in range(1,10):
    q.append(i)
# print(q)
cnt = 0
while True:
    cnt += 1
    a = q.popleft()
    if a%10 > 0:
        q.append(10*a+a%10-1)
    q.append(10*a+a%10)
    if a%10 < 9:
        q.append(10*a+a%10+1)
    # print(a)
    if cnt == K:
        print(a)
        exit()
    
    

Measured memory_bytes: 11908