akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    long long int N,K;
    cin>>N>>K;
    long long int lisP[5003];
    long long int lisC[5003];
    long long int ans=-21000000000000;
    for(int i=1;i<=N;i++)cin>>lisP[i];
    for(int i=1;i<=N;i++)cin>>lisC[i];
    for(int i=1;i<=N;i++){
        long long int now=i;
        long long int te=0;
        long long int karians=0;
        long long int already[5003];
        for(int j=0;j<5003;j++)already[j]=-1;
        long long int anslis[5003];
        for(int j=0;j<5003;j++)anslis[j]=-1;
        already[now]=0;
        anslis[now]=0;
        long long int papapa=0;
        for(int j=0;te<K;j++){
            now=lisP[now];
            te++;
            karians+=lisC[now];
            ans=max(ans,karians);
            if(already[now]!=-1&&papapa==0){
                long long int syu=max(0ll,(K-te)/(te-already[now])-1);
                //printf("syu=[%lld]/[%lld]-1\n",(K-te),(te-already[now]));
                //printf("[%lld]*[%lld]\n",te-already[now],syu);
                te+=(te-already[now])*syu;
                //printf("[%lld]*[%lld]\n",karians-anslis[now],syu);
                karians+=(karians-anslis[now])*syu;
                //printf("[%lld]\n",karians);
                ans=max(ans,karians);
                papapa=1;
            }
            else{
                already[now]=te;
                anslis[now]=karians;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3276
using System;
using System.Linq;
using System.Collections.Generic;

class Cmondai
{
    static void Main()
    {
        var N = Int64.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).OrderBy(x=>x).ToArray();
        var array = new long[N + 1];
        var ans=0L;
        for (int i=0;i<N-1;++i)
        {
            if (N < a[i])
            {
                ans++;
                continue;
            }
            array[a[i]]++;
            if (a[i] < array[a[i]]) ans++;
            else if (array[a[i]] < a[i] && a[i + 1] != a[i]) ans += array[a[i]];
        }
        if (N < a[N - 1]) ans++;
        else
        {
            array[a[N-1]]++;
            if (a[N - 1] < array[a[N - 1]]) ans++;
            else if (array[a[N - 1]] < a[N - 1]) ans += array[a[N - 1]];
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 30172
while True:
    s = input()
    if s == "END OF INPUT":
        break
    list=[]
    d = 0
    count = 0
    while d < len(s):
        if s[d] == " ":
            list.append(count)
            count = 0
        else:
            count += 1
        d += 1
    list.append(count)
    print(*list,sep="")


Measured memory_bytes: 5560
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define pii pair<int, int>
#define ff first
#define ss second
using namespace std;
 
const int N = 100000;
 
signed main() {
 
    int n; cin >> n;
    int a[n + 1];
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    
    vector<int> dp(n + 1, (1LL << 40));
    dp[1] = 0LL;
    for(int i = 2; i <= n; i++) {
        if(i - 1 >= 1) dp[i] = min(dp[i], dp[i - 1] + abs(a[i] - a[i - 1]));
        if(i - 2 >= 1) dp[i] = min(dp[i], dp[i - 2] + abs(a[i] - a[i - 2]));
    }
    
    cout << dp[n] << endl;
 
    return 0;
}

Measured memory_bytes: 1792
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;
// powmod p^n%mod
LL powmod(LL p,LL n,LL mod){
	LL q=p%mod;
	LL pow=1;
	while(n){
		if(n&1){
			pow*=q;
			pow%=mod;
		}
		q=q*q;
		q%=mod;
		n/=2;
	}
	return pow;
}
LL dp[401][401];
LL N,C;
LL A[401];
LL B[401];
LL ps[401][401];
const LL M=1e9+7;
int main() {
	cin >> N >> C;
	for(int i=1;i<=N;i++){
		cin >> A[i];
	}
	for(int i=1;i<=N;i++){
		cin >> B[i];
	}
	dp[0][0]=1;
	for(int i=1;i<401;i++){
		ps[i][0]=1;
		for(int j=1;j<401;j++){
			ps[i][j]=ps[i][j-1]*i%M;
		}
	}
	for(int i=1;i<=N;i++){
		for(int a=0;a<=C;a++){
			LL v=0;
			for(int x=A[i];x<=B[i];x++){
				v+=ps[x][a];
				v%=M;
			}
			for(int c=a;c<=C;c++){
				dp[i][c]+=v*dp[i-1][c-a]%M;
				dp[i][c]%=M;
			}
		}
	}
	cout << dp[N][C] << endl;


	return 0;
}



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

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

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

ll dp[100005];

ll solve(vector<vector<ll>> &to, ll v){
    if(dp[v]!=-1){
        return dp[v];
    }

    ll res = 0;
    for(ll nv : to[v]){
        chmax(res, solve(to, nv) + 1);
    }
    return dp[v] = res;
}

int main() {

    rep(i,100005){
        dp[i] = -1;
    }

    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> to(n);

    int x, y;
    rep(i,m){
        cin >> x >> y;
        x --; y -- ;
        to[x].push_back(y);
    }


    ll ans = 0;
    rep(i,n){
        chmax(ans , solve(to, i));
    }

    cout << ans << endl;

    
    return 0;
}

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

int main(){
  char a;
  cin >> a;
  if(a=='A') cout << 'T' << endl;
  if(a=='T') cout << 'A' << endl;
  if(a=='G') cout << 'C' << endl;
  if(a=='C') cout << 'G' << endl;
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include<iostream>
#include <iomanip>
#include <cmath>
using namespace std;

struct vec2
{
	double height = 0;
  	double width = 0;
};

int main()
{
  static const double pi = 3.14159265358979323846;
  
	int alen,blen;
  	int min,hou;
  	vec2 aver,bver;
  
  cin>>alen>>blen>>hou>>min;
  if(hou==0 && min ==0)
  {
    aver.height = (double)alen;
  aver.width = (double)0;
  }
  else
  {
  aver.height = (double)alen*cos(M_PI*(((double)hou + ((double)min/60))/(double)6));
  aver.width = (double)alen*sin(M_PI*(((double)hou + ((double)min/60))/(double)6));
  }
  
  if(min==0)
  {
  bver.height = (double)blen;
  bver.width = (double)0;
  }
  else
  {
    bver.height = (double)blen*cos(M_PI*((double)min/(double)30));
  bver.width = (double)blen*sin(M_PI*((double)min/(double)30));
  }
  

  std::cout << setprecision(21);
  cout<<sqrt(pow(aver.height-bver.height,2) + pow(aver.width-bver.width,2));
  
}

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

int main() {
  char a;
  cin >>a;
  if(a == 'A')
    cout << 'T' << endl;
  if(a == 'C')
    cout << 'G' << endl;
  if(a == 'T')
    cout << 'A' << endl;
  if(a == 'G')
    cout << 'C' << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int N, D; scanf("%d%d", &N, &D);
  int ans = 0;
  while (N--) {
    int x, y; scanf("%d%d", &x, &y);
    ans += 1ll * D * D >= 1ll * x * x + 1ll * y * y;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define N 100010
#define pb push_back
#define fi first
#define se second
#define si size()
#define ll long long
#define mp make_pair
#define iter ::iterator
#define all(v) v.begin(), v.end()
#define pp pop_back
#define mapiter map<int, int>::iterator
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forn1(i, n) for(int i = 1; i <= n; ++i)
#define forr(i, n)	for(int i = n - 1; i >= 0; --i)
#define forr1(i, n)	for(int i = n; i >= 1; --i)
#define r0 return 0
#define barnarnar ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define lld long double
#define elif else if
 
const int inf = 1e9 + 7;
const lld EPS = 0.00000001;
const ll modw = 1e9 + 7;

using namespace std;

ll dp[N];
ll a[N];

int main()
{
	barnarnar
	int n;
	cin >> n;
	forn1(i, n)	cin >> a[i];
	dp[1] = 0;
	dp[2] = abs(a[2] - a[1]);
	for(int i = 3; i <= n; i++)
	{
		dp[i] = min(dp[i - 1] + abs(a[i - 1] - a[i]), dp[i - 2] + abs(a[i - 2] - a[i]));
	}
	cout << dp[n];
	return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define LL long long
#define uLL unsigned long long

using namespace std;
const int N=1e5+10;
int rd()
{
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
    return x*w;
}
int n,ff[N],sz[N],co[N],sq[N],ts,c[3];
bool v2[N];
int findf(int x){return ff[x]==x?x:ff[x]=findf(ff[x]);}
vector<int> e[N],fe[N];
void adde(int x,int y){e[x].push_back(y),fe[y].push_back(x);}
LL m;
queue<int> q,q2;

int main()
{
//////////////
    n=rd(),m=rd();
    for(int i=1;i<=n;++i) ff[i]=i;
    for(int i=1;i<=m;++i)
    {
	int x=rd(),y=rd();
	adde(x,y);
	if(findf(x)!=findf(y)) sz[findf(x)]+=sz[findf(y)],ff[findf(y)]=findf(x);
	++sz[findf(x)];
    }
    for(int h=1;h<=n;++h)
	if(findf(h)&&(int)e[h].size()&&(int)fe[h].size())
	{
	    m-=sz[findf(h)];
	    ff[h]=0,ts=0,q.push(h);
	    while(!q.empty())
	    {
		int x=q.front();
		q.pop();
		sq[++ts]=x;
		int nn=e[x].size(),mm=fe[x].size(),sx=e[x][0],tx=fe[x][0];
		for(int i=0;i<nn;++i)
		{
		    int y=e[x][i];
		    if(!(int)e[y].size()) adde(y,tx);
		    if(ff[y]) co[y]=(co[x]+1)%3,ff[y]=0,q.push(y);
		}
		for(int i=0;i<mm;++i)
		{
		    int y=fe[x][i];
		    if(!(int)fe[y].size()) adde(sx,y);
		    if(!v2[y]) v2[y]=1,q2.push(y);
		}
		if(q.empty())
		{
		    while(!q2.empty()&&!ff[q2.front()]) q2.pop();
		    if(!q2.empty())
		    {
			int y=q2.front();
			q2.pop();
			mm=fe[y].size();
			for(int j=0;j<mm;++j)
			{
			    int z=fe[y][j];
			    if(!ff[z]){co[y]=(co[z]+1)%3,ff[y]=0,q.push(y);break;}
			}
			nn=e[y].size();
			for(int j=0;j<nn;++j)
			{
			    int z=e[y][j];
			    if(!ff[z]&&(int)e[z].size()){sx=e[z][0];break;}
			}
			assert(!ff[sx]);
			if(ff[y]) adde(sx,y),co[y]=(co[sx]+1)%3,ff[y]=0,q.push(y);
		    }
		}
	    }
	    bool ok=0;
	    for(int i=1;i<=ts;++i)
	    {
		int x=sq[i],nn=e[x].size();
		for(int j=0;j<nn;++j)
		{
		    int y=e[x][j];
		    ok|=(co[y]-co[x]+3)%3!=1;
		}
	    }
	    if(ok) m+=1ll*ts*ts;
	    else
	    {
		c[0]=c[1]=c[2]=0;
		for(int i=1;i<=ts;++i) ++c[co[sq[i]]];
		m+=1ll*c[0]*c[1]+1ll*c[1]*c[2]+1ll*c[2]*c[0];
	    }
	}
    printf("%lld\n",m);
    return 0;
}


Measured memory_bytes: 14200
#include <stdio.h>
#include <stdlib.h>

int main()
{
  int N,i,v,j,k;
  int *A;

  scanf("%d",&N);
  if(N<1 || N>100) exit(2);
  A=(int *)malloc(sizeof(int)*N);
  for(i=0;i<N;i++)
    {
      scanf("%d",&A[i]);
      if(A[i]<0 || A[i]>1000) exit(1);
    }

  for(k=0;k<N-1;k++)
	{
	  printf("%d ",A[k]);
	  
	}
  printf("%d",A[N-1]);
  printf("\n");
  
  for(i=1;i<N;i++)
    {
      v=A[i];
      j=i-1;
      while(j>=0 && A[j]>v)
	{
	  A[j+1]=A[j];
	  j--;
	}
      A[j+1]=v;
      for(k=0;k<N-1;k++)
	{
	  printf("%d ",A[k]);
	}
      printf("%d",A[N-1]);
       printf("\n");
      
    }


  return 0;
}



Measured memory_bytes: 2104
#include<stdio.h>
#define SIZE 5
int main()
{
  int num[SIZE];
  int i,j,rep;
  for(i=0;i<SIZE;i++) scanf("%d",&num[i]);
  for(j=0;j<SIZE;j++)
    {
      for(i=0;i<SIZE-1;i++)
	{
	  if(num[i]<num[i+1])
	    {
	      rep=num[i];
	      num[i]=num[i+1];
	      num[i+1]=rep;
	    }
	}
    }
  for(i=0;i<SIZE-1;i++) printf("%d ",num[i]);
  printf("%d\n",num[SIZE-1]);
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define vmax 10000
constexpr ll inf = 100000000000000;
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/

int main(){
  int n;
  cin>>n;
  ll dp[87];
  for(int i=0;i<87;i++){
    dp[i]=inf;
  }
  dp[0]=2;
  dp[1]=1;
  for(int i=2;i<=n;i++){
    dp[i]=dp[i-1]+dp[i-2];
  }
  cout<<dp[n]<<endl;
  return 0;
}



Measured memory_bytes: 256
from collections import defaultdict

n, k = map(int, input().split())
top = [0] * n
sub = []

for i in range(n):
    t, d = map(int, input().split())
    t -= 1
    if top[t] == 0:
        top[t] = d
    else:
        if d > top[t]:
            sub.append(top[t])
            top[t] = d
        else:
            sub.append(d)

top.sort(reverse=True)
top_sum = [0]
sub.sort(reverse=True)
sub_sum = [0]

for p in top:
    if p == 0:
        top_sum.append(-1)
    else:
        top_sum.append(top_sum[-1] + p)

for p in sub:
    sub_sum.append(sub_sum[-1] + p)

ans = 0

for i in range(1, k + 1):
    if (len(sub_sum) - 1) >= (k - i) and top_sum[i] != -1:
        ans = max(ans, top_sum[i] + sub_sum[k - i] + i ** 2)

print(ans)


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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];
    sort(a.begin(),a.end());
    cout<<a[n-1]-a[0]<<endl;
}


Measured memory_bytes: 256
import java.util.*;

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

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

    private void run() {
        char[] t = sc.next().toCharArray();
        for (int i = 0; i < t.length; i++) {
            if (t[i] == '?') {
                if (i != 0 && t[i-1] == 'P') {
                    t[i] = 'D';
                } else if (i < t.length-1 && (t[i+1] == 'D' || t[i+1] == '?')) {
                    t[i] = 'P';
                } else {
                    t[i] = 'D';
                }
            }
        }
        System.out.println(String.valueOf(t));
    }
}



Measured memory_bytes: 41320
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    int N;
    cin >> N;
    vector<pair<int, int>> T(N);
    rep(i, N) {
        int A, B;
        cin >> A >> B;
        T.at(i) = make_pair(B, A);
    }
    sort(all(T));

    int sum = 0;
    bool flg = true;
    rep(i, N) {
        sum += T.at(i).second;
        if(sum > T.at(i).first) {
            flg = false;
            break;
        }
    }

    cout << (flg ? "Yes" : "No") << endl;
}

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

int main(){
int n;
string data[1000][2];
int score[2];
for(int i = 0; i < 2; i++){
  score[i] = 0;
}
cin >> n;
for(int i = 0; i < n; i++){
for(int j = 0; j < 2; j++){
  cin >> data[i][j];
}
}

for(int i = 0; i < n; i++){
  if(data[i][0] == data[i][1]){
  score[0]++;score[1]++;
  }else if(data[i][0] < data[i][1]){
  score[1]+=3;
  }else if(data[i][0] > data[i][1]){
  score[0]+=3;
  }
}
cout << score[0] << " " << score[1] << endl;
return 0;
}


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

int main() {
    long long int n,tmp,ans=0;cin>>n;
    
    for(long long int i=1;i<=n;++i){
        for(long long int  j=1;j<=n;++j){
            for(long long int  k=1;k<=n;++k){
                tmp=__gcd(i,j);
                tmp=__gcd(tmp,k);
                ans+=tmp;
            }
        }
    }
    cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3636
a,b,t=map(int,input().split())
print(int(b*((t+0.5)//a)))
    
        
    
    
    
        
        
    
    
    
    
        

        
   
    
    
    
        
        
    
    
    
    
        

      
    
    
        
        
    
    
    
    
        


Measured memory_bytes: 9140
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define ll long long
#define P pair<int, int>

using namespace std;
int mod = 1000000007;

int main() {
  ll a, b, x;
  cin >> a >> b >> x;
  long ans;
  if (a == 0) {
    ans = b/x + 1;
  } else {
    ans = b/x - (a-1)/x;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define lli long long int
bool check(int a, int b, int c){
    if(a+b > c && b+c>a && a+c>b && a!=c && a!=b && b!=c)
    return true;
    else
    return false;
}
int main() {
	int n;
	cin>>n;
    int a[n];
	for(int i=0;i<n;i++)
	{
	    cin>>a[i];
	}
	int cnt = 0;
	for(int i=0;i<n;i++){
	    for(int j=i+1;j<n;j++){
	        for(int k=j+1;k<n;k++){
	            if(check(a[i],a[j],a[k]))
	            cnt++;
	        }
	    }
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3188
import math


def resolve():
    import sys
    input = sys.stdin.readline
    # row = [int(x) for x in input().rstrip().split(" ")]
    # n = int(input().rstrip())
    n = int(input().rstrip())
    dx = [int(x) for x in input().rstrip().split(" ")]
    d = dx[0]
    x = dx[1]

    ans = 0

    for i in range(n):
        a = int(input().rstrip())

        day_count = 0
        while True:
            day = day_count * a + 1

            if day > d:
                break
            ans += 1
            day_count += 1

    print(ans + x)


if __name__ == "__main__":
    resolve()


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

int main()
{
 int h,w;
  cin >> h >> w;
  
  string s[100][100];
  for (int i = 0;i < h; i++)
    for (int j = 0; j< w; j++)
      cin >> s[i][j];
  
  int i,j;
  for ( i = 0;i < h; i++)
  {
   for ( j = 0; j< w; j++) 
   {
    	if (s[i][j] == "snuke") 
goto L;
   }
  }
  L:
  {}
  cout << (char)('A' + j) << i + 1 << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int n,k,a[200100],mn[200100],mx[200100];
deque<int> q;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	while(q.size()) q.pop_back();
	for(int i=n;i>=1;i--){
		while(q.size()&&q.front()>=i+k) q.pop_front();
		while(q.size()&&a[q.back()]>a[i]) q.pop_back();
		q.push_back(i);
		if(q.size()==1) mn[i]=1;
	}
	while(q.size()) q.pop_back();
	for(int i=1;i<=n;i++){
		while(q.size()&&q.front()<=i-k) q.pop_front();
		while(q.size()&&a[q.back()]<a[i]) q.pop_back();
		q.push_back(i);
		if(q.size()==1) mx[i]=1;
	}
	int num=0;
	for(int i=1,j=1;i<=n;i=j){
		j++;
		while(j<=n&&a[j]>a[j-1]) j++;
		if(j>=i+k) num++;
	}
	int tot=n-k+1-max(num-1,0);
	for(int i=k;i<=n;i++) tot-=(mx[i]&&mn[i-k]);
	cout<<tot<<endl;
	return 0;
}


Measured memory_bytes: 6008
#include <bits/stdc++.h>
using namespace std;
const int N=200010,INF=INT_MAX;

class RMQ{
public:
  int n,dat[2*N-1];
  void init(int _n){
    n=1;
    while(n<_n)n*=2;
    fill(dat,dat+2*n-1,INF);
  }
  void update(int k,int a){
    k+=n-1;
    dat[k]=a;
    while(k>0){
      k=(k-1)/2;
      dat[k]=min(dat[k*2+1],dat[k*2+2]);
    }
  }
  int query(int a,int b){return query(a,b,0,0,n);}
  int query(int a,int b,int k,int l,int r){
    if(r<=a||b<=l) return INF;
    if(a<=l&&r<=b) return dat[k];
    else {
      int vl=query(a,b,k*2+1,l,(l+r)/2);
      int vr=query(a,b,k*2+2,(l+r)/2,r);
      return min(vl,vr);
    }
  }
};

int main() {
  int n,q;
  cin >> n >> q;
  RMQ r;
  r.init(n);
  while(q--) {
    int x,y,z;
    cin >> x >> y >> z;
    if(!x) r.update(y,z);
    else cout << r.query(y,z+1) << endl;
  }
  return 0;
}


Measured memory_bytes: 2196
def rr(): return input().rstrip()
def rri(): return int(rr())
def rrl(): return list(map(int, rr().split()))
def rrt(): return tuple(map(int, rr().split()))
from collections import defaultdict
def mus(d=lambda: 0): return defaultdict(lambda: defaultdict(d))
def dd0(d=lambda: 0): return defaultdict(d)
def ms(x, y, d=0): return [[0]*y for i in range(x)]
def ar(x, d=0): return [d]*x
def ppm(m, n=0, x=0, y=0): print("\n".join(("\t".join((str(m[j][i]) for j in range(y or n))) for i in range(x or n))))
def ppa(a, n): print("\t".join(map(str, a[0:n])))
def ppl(a=0, x=[1]): x[0]=a or (x[0]+1); print("-"+"- -"*14+"-# "+str(x[0]-2)+" #-"+"- -"*14+"-")
def fltn(a): (i for sub in a for i in sub)
def yn(x): return "YES" if x else "NO"
from itertools import accumulate
from itertools import groupby
def grp(x): return ((i, sum(1 for _ in g)) for i, g in groupby(x))
import math
#def rnar(): return (*rrl(), rrl())
#def rn(): return (*rrl(),)
def dpp(a, b=""): print("[{}]o[{}]".format(a, b))

def read():
    return (rri(), rrl())
    return (0,)

def solve(n, arr):
    dp = ar(n)
    dp[0] = 0
    dp[1] = abs(arr[1]-arr[0])
    for i in range(2, n):
        dp[i] = min(dp[i-1] + abs(arr[i-1]-arr[i]), dp[i-2] + abs(arr[i-2]-arr[i]))

    ans = dp[-1]
    return ans

if __name__ == "__main__":
    #test_count = rri()
    test_count = 1
    for _ in range(test_count):
        input_data = read()
        result = solve(*input_data)
        print(result)


Measured memory_bytes: 53128
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;
using mapis = unordered_map<Int,string>;
using mapii = unordered_map<Int,Int>;
using pii = pair<Int,Int>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

Int modinv(Int a, Int m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main() {
    Int N,M;
    cin >> N >> M;

    vector<vector<pair<Int,Int>>> edges = vector<vector<pair<Int,Int>>>(N+1);
    vector<Int> cost = vi(N+1,inf);
    cost[1] = 0;

    rep(i,M){
        Int a,b,c;
        cin >>a >>b >>c;
        edges[a].push_back(make_pair(b,-c));
    }

    bool is_loop = false;
    vi pre = vi(N+1);

    REP(i,1,N+1){
        REP(j,1,N+1){
            rep(k,edges[j].size()){
                pii now = edges[j][k];
                if(cost[j] != inf && cost[now.first] > cost[j] + now.second ){
                    cost[now.first] = cost[j]+now.second;
                    pre[now.first] = j;
                    if (i == N) {
                        is_loop = true;
                        break;
                    }
                }
            }
        }
    }

    int check = N;
    for(int i = N; i>0; i--){
        check = pre[check];
        if(check == 0) break;
    }

    if(is_loop && check!=0){
        cout << "inf" << endl;
    }else{
        cout << -1*cost[N] << endl;
    }


    return 0;
}

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

int main() {
  int64_t n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i], a[i]--;

  set<int> used;
  vector<int> path;
  int cur = 0;
  while (used.count(cur) == 0) {
    path.push_back(cur);
    used.insert(cur);
    cur = a[cur];
  }

  int s = find(path.begin(), path.end(), cur) - path.begin();
  int r = (int)path.size() - s;

  if (k < s) cout << path[k] + 1 << endl;
  else cout << path[(k-s) % r + s] + 1 << endl;
  return 0;
}

Measured memory_bytes: 14016
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int t = N;
  int ans = 0;
  while ( t >= 1 ){
  int A = t % 10;
  t /= 10;
  ans += A;
  }
  if ( N % ans == 0){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
from math import factorial as fact
import math
import sys
import itertools
import numpy as np
from collections import Counter
import datetime


#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

def combinations(n,r):
	return list(itertools.combinations(range(n),r))



def all_sets(num_list):
	subsets=[]
	for i in range(2,len(num_list) + 1):
		for c in combinations(num_list, i):
			subsets.append(c) 
	return subsets

#公約数の列挙
def ch(x1):
	cf=[]
	for i in range(2,math.sqrt(x1)+1):
		if x1 % i==0:
			cf.append(i)
	return cf

def CountOneRoots(x,y):
	#x:縦，y:横
	return fact(x+y)/fact(x)/fact(y)

# 素因数分解
def factorization(n):
	tmp=n
	count=0
	for i in range(2,int(n**0.5)+2):
		if tmp%i==0:
			cnt=0
			while tmp%i==0:
				cnt+=1
				tmp//=i
			count+=1
	if tmp!=1:
		count+=1

	return count
			

def fl(a,b,x):
	b1=x//b
	x=math.floor(a*x/b)
	y=math.floor(b1)
	return x-y
	


# n,m,q = input2()
# abcd=[]
# A=[0]*n
# for i in range(q):
# 	abcd.append(input_array())

a,b,n=input2()
if b>n:
	b_ans=fl(a,b,n)
	# print(b_ans)
else:
	b_ans=fl(a,b,b-1)

for i in range(0,n,b):
	ans=fl(a,b,i)
	# print(ans)
	if ans> b_ans:
		b_ans=ans
	else:
		break
# if i<n:
# 	ans=fl(a,b,n)
# 	if ans> b_ans:
# 		b_ans=ans
print(b_ans)



Measured memory_bytes: 26924
import math
a, b, x = map(int, input().split())

if x / a > a * b / 2:
    print(math.degrees(math.atan(2 * (a ** 2 * b - x) / a ** 3)))
else:
    print(math.degrees(math.atan(b / (2 * x / a / b))))

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

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

using namespace std;

int main(){
	string s; cin>>s;
	rep(i,s.length()-1) if(s[i]=='A' && s[i+1]=='C') return puts("Yes"),0;
	puts("No");
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
//#define scanf scanf_s
typedef long long int lli;

// ITP1_5_A
// H * Wの四角形を'#'で出力
// H=0,W=0で終了
int main()
{
	int iInputH, iInputW;
	int iCnt1, iCnt2;

	scanf("%d %d", &iInputH, &iInputW);

	while (iInputH != 0 || iInputW != 0)
	{
		for (iCnt1 = 0; iCnt1 < iInputH; iCnt1++)
		{
			for (iCnt2 = 0; iCnt2 < iInputW; iCnt2++)
			{
				if (iCnt1 % 2 == 0)	// 偶数行
				{
					if (iCnt2 % 2 == 0)
					{
						printf("#");
					}
					else
					{
						printf(".");
					}
				}
				else
				{
					if (iCnt2 % 2 == 0)
					{
						printf(".");
					}
					else
					{
						printf("#");
					}
				}
			}
			printf("\n");
		}

		printf("\n");
		scanf("%d %d", &iInputH, &iInputW);
	}

	return 0;
}


Measured memory_bytes: 2040
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string s, t;
    cin >> s;
    int q;
    cin >> q;
    int m, n;

    for (int j = 0; j < q; ++j) {
    
        cin >> t;

        if (t == "print") {
            cin >> m >> n;
            cout << s.substr(m,n-m+1) << endl;
        }
        else if (t == "replace") {
            cin >> m >> n;
            string u;
            cin >> u;
            s.erase(m, n - m + 1);
            s.insert(m, u);
        }
        else if (t == "reverse") {
            cin >> m >> n;
            string u;
            u = s.substr(m, n - m + 1);
            reverse(u.begin(), u.end());
            s.erase(m, n - m + 1);
            s.insert(m, u);
        }

    }

    return 0;

}


Measured memory_bytes: 3212
#pragma GCC optimize(3,"Ofast","inline")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
#ifdef ONLINE_JUDGE
#define getchar gc
inline char gc(){
	static char buf[1<<16],*p1=buf,*p2=buf;
	if(p1==p2){
		p2=(p1=buf)+fread(buf,1,1<<16,stdin);
		if(p2==p1) return EOF;
	}
	return *p1++;
}
#endif
template<class t> inline t read(t &x){
    char c=getchar();bool f=0;x=0;
    while(!isdigit(c)) f|=c=='-',c=getchar();
    while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
    if(f) x=-x;return x;
}
template<class t> inline void write(t x){
    if(x<0) putchar('-'),write(-x);
    else{if(x>9) write(x/10);putchar('0'+x%10);}
}

const double eps=1e-9;
const double pi=acos(-1);


struct point{
	double x,y;
	inline void read(){
		scanf("%lf%lf",&x,&y);
	}
	inline point operator + (const point &nt) const {
		return (point){x+nt.x,y+nt.y};
	}
	inline point operator - (const point &nt) const {
		return (point){x-nt.x,y-nt.y};
	}
	inline point operator * (const double &nt) const {
		return (point){x*nt,y*nt};
	}
}x,y,p;

double DJ(point x,point y){ //点积 
	return x.x*y.x+x.y*y.y;
}

double CJ(point x,point y){ //叉积 
	return x.x*y.y+x.y*y.x;
}

double distance(point x,point y){ //距离 
	return sqrt((y.x-x.x)*(y.x-x.x)+(y.y-x.y)*(y.y-x.y));
}

struct segment{
	point x,y;
	inline void read(){
		x.read();y.read();
	}
	inline double length(){ //线段长度 
		return distance(x,y);
	}
}seg;

point trpoint(segment x){ //将有向线段转成向量点 
	return x.y-x.x;
}

double prolen(point x,segment a){ //点在有向线段上的投影长度 
	return DJ(trpoint((segment){a.x,x}),trpoint(a))/a.length();
}

point propoint(point x,segment a){ //点在直线上的投影点 
	return a.x+trpoint(a)*(prolen(x,a)/a.length());
}

point refpoint(point x,segment a){ //点在直线上的投影点 
	point y=propoint(x,a);
	return x+(y-x)*2;
}

void doit(){
	p.read();
	point res=refpoint(p,seg);
	printf("%.10lf %.10lf\n",res.x,res.y);
}

signed main(){
	x.read();y.read();
	seg=(segment){x,y};
	int t;
	read(t);
	while(t--) doit();
}


Measured memory_bytes: 3240
n, m = gets.split.map(&:to_i)
union_find = [*0..n]
rank = Array.new(n + 1) { 0 }

def union_find.root(idx)
  self[idx] == idx ? idx : (self[idx] = root(self[idx]))
end

m.times do
  a, b = gets.split.map(&:to_i)
  a = union_find.root(a)
  b = union_find.root(b)

  next if a == b

  if rank[a] > rank[b]
    union_find[b] = a
  else
    union_find[a] = b
    rank[b] += 1 if rank[a] == rank[b]
  end
end

h = Hash.new(0)
union_find.each { |e| h[union_find.root(e)] += 1 }

puts h.values.max

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

#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;

typedef long long ll;


int main(){

    string s;
    cin >> s;


    if(s == "AAA" || s == "BBB"){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
N,K = map(int,input().split())
X,Y = [],[]
p = []
for i in range(N):
    x,y = map(int,input().split())
    X.append(x)
    Y.append(y)
    p.append([x,y])
X.sort(),Y.sort()
ans = abs(X[N-1]-X[0])*abs(Y[N-1]-Y[0])
for xi in range(N):
    for xj in range(xi+1,N):
        for yi in range(N):
            for yj in range(yi+1,N):
                lx,rx = X[xi],X[xj]
                dy,uy = Y[yi],Y[yj]
                num = 0
                for x,y in p:
                    if lx<=x and x<=rx and dy<=y and y<=uy:
                        num += 1
                if K==num:
                    ans = min(abs(rx-lx)*abs(uy-dy),ans)
print(ans)


Measured memory_bytes: 48808
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var S = Str;
		var n = int.Parse(S.Replace(" ", ""));
		for (var i = 0; i <= 1000; i++) if (n == i * i) { WriteLine("Yes"); return; }
		WriteLine("No");
	}
}


Measured memory_bytes: 13140
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
  int N, M;
  cin >> N >> M;

  int ans = 1;
  if( N==1 )
    {
      cout << M << endl;
      return 0;
    }
  
  for(int i=1;i<=(int)M/N;i++)
    ans = (M%i == 0)?i:ans;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/math/constants/constants.hpp>
using namespace std;
typedef long long ll;
long double e = boost::math::constants::e<long double>();
long double pi = boost::math::constants::pi<long double>();
// 条件を見落としていませんか？
int main () {
    #define int long long
    int N;
    map<int, int> mp;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        mp[A[i]]++;
    }
    ll ans = 0;
    for (auto x: mp) {
        ans += x.second*(x.second-1)/2;
    }
    for (int i = 0; i < N; i++) {
        ll res = ans;
        res -= mp[A[i]]*(mp[A[i]]-1)/2;
        res += (mp[A[i]]-1)*(mp[A[i]]-2)/2;
        cout << res << endl;
    }
}

Measured memory_bytes: 11008
#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <numeric>

#define repAll(n) (n).begin(), (n).end()
#define repConAll(n) (n).cbegin(), (n).cend()

using namespace std;

namespace {

}

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

	vector<string> str;
	//set<string> setS;
	string lastS("");
	bool isNo = false;
	for (int i = 0; i < N; ++i){
		string s;
		cin >> s;
		if (count(str.begin(), str.end(), s) != 0){
			isNo = true;
		}
		if (lastS.size() > 0){
			if (lastS[lastS.size() - 1] != s[0]){
				isNo = true;
			}
		}

		str.push_back(s);
		lastS = s;
		//setS.insert(s);
	}

	if (isNo)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;

	return 0;
}

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

using ll = long long;

int main()
{
  int N, K;
  cin >> N >> K;
  vector<bool> A(N+1, false);
  int buf;

  for(int i = 0; i<K; i++){
    cin >> buf;
    for(int j = 0; j<buf; j++){
      int has;
      cin >> has;
      A.at(has) = true;
    }
  }

  int count = 0;
  for(bool s : A){
    if(s == false){
      count++;
    }
  }

  cout << count-1 << endl;


}

Measured memory_bytes: 3632
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll dp[55][3005];
// dp[i][j] means i length and sum j
int a[55];
int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,av;
    scanf("%d%d",&n,&av);
    int i;
    for(i=1;i<=n;i++)scanf("%d",&a[i]);
    dp[0][0] = 1;
    int j,k;
    for(i=1;i<=n;i++)
        {
        for(j=i-1;j>=0;j--)
            {
            for(k=0;k<=2500;k++)
                {
                int cur = k + a[i];
                dp[j+1][cur] += dp[j][k];
            }
        }
    }
    ll ans = 0;
   for(int len = 1; len<=n;len++)
       {
       ans += dp[len][av*len];
   }
    printf("%lld\n",ans);
    return 0;
}

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, T; cin >> N >> T;
    int ans = mod;
    rep(i, N){
        int c, t; cin >> c >> t;
        if(t <= T) ans = min(ans, c);
    }
    if(ans != mod) cout << ans << endl;
    else cout << "TLE" << endl;
    return 0;
}

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

using P = pair<long long, long long>;
struct dat {
  long long n, l;
};

long long n, q;
vector<long long> v, w, res;
vector<vector<dat>> query;

void solve();
void dfs(int now, int dep, vector<P> &lst);

int main() {
  cin >> n;
  v.resize(n);
  w.resize(n);
  for (int i = 0; i < n; ++i) cin >> v[i] >> w[i];
  cin >> q;
  query.resize(n + 1);
  for (int i = 0; i < q; ++i) {
    long long vn, li;
    cin >> vn >> li;
    query[vn].push_back({i, li});
  }
  solve();
  for (int i = 0; i < q; ++i) cout << res[i] << endl;
  return 0;
}

void solve() {
  res.assign(q, 0);
  vector<P> dummy(1, P(0, 0));
  dfs(1, 0, dummy);
}

void dfs(int now, int dep, vector<P> &lst) {
  if (now > n) return;
  if (dep == 9) reverse(lst.begin(), lst.end());
  if (dep < 9) {
    int len = lst.size();
    for (int i = 0; i < len; ++i)
      lst.emplace_back(lst[i].first + w[now - 1], lst[i].second + v[now - 1]);
    inplace_merge(lst.begin(), lst.begin() + len, lst.end());
    for (auto qu : query[now])
      for (auto p : lst)
        if (p.first <= qu.l) res[qu.n] = max(res[qu.n], p.second);
  } else {
    vector<P> suf;
    suf.emplace_back(0, 0);
    long long x = now;
    while (x >= (1 << 9)) {
      int len = suf.size();
      for (int i = 0; i < len; ++i)
        suf.emplace_back(suf[i].first + w[x - 1], suf[i].second + v[x - 1]);
      inplace_merge(suf.begin(), suf.begin() + len, suf.end());
      x >>= 1;
    }
    for (auto qu : query[now]) {
      long long nres = 0, lim = qu.l, plen = lst.size(), slen = suf.size();
      for (long long i = 0, id = 0, val = 0; i < plen; ++i) {
        if (lst[i].first > lim) continue;
        while (id < slen && lst[i].first + suf[id].first <= lim)
          val = max(val, suf[id++].second);
        nres = max(nres, val + lst[i].second);
      }
      res[qu.n] = nres;
    }
  }
  vector<P> dummy = lst;
  dfs(now * 2, dep + 1, lst);
  dfs(now * 2 + 1, dep + 1, dummy);
}


Measured memory_bytes: 17628
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++){
    cin >> a[i];
  }
  vector<int> b;
  b.push_back(0);
  for (int i = 0; i < N; i++){
    if (a[i] > b.back()){
      b.push_back(a[i]);
    }
  }
  int b_cnt = b.size();
  vector<int> c = a;
  c.push_back(0);
  sort(c.begin(), c.end());
  c.erase(unique(c.begin(), c.end()), c.end());
  int c_cnt = c.size();
  map<int, int> mp1;
  for (int i = 0; i < c_cnt - 1; i++){
    mp1[c[i + 1]] = c[i + 1] - c[i];
  }
  map<int, long long> mp2;
  for (int i = 0; i < N; i++){
    mp2[a[i]]++;
  }
  int sum = N;
  for (auto P : mp2){
    int tmp = sum - P.second;
    mp2[P.first] = sum;
    sum = tmp;
  }
  map<int, long long> mp3;
  for (int i = 1; i < c_cnt; i++){
    int num = *(lower_bound(b.begin(), b.end(), c[i]));
    mp3[num] += mp1[c[i]] * mp2[c[i]];
  }
  for (int i = 0; i < N; i++){
    cout << mp3[a[i]] << endl;
    mp3[a[i]] = 0;
  }
}

Measured memory_bytes: 21520
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> II;
typedef pair<LL, II> III;
typedef priority_queue<III, vector<III>, greater<>> Queue;
static const LL INF = 1LL << 60;

LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL lcm(LL a, LL b) { return (a / gcd(a, b)) * b; }

#if 0
	auto possible = [&](LL t) {

		return false;
	};
	LL left = 1, right = 1000000000;
	while (right - left > 1) {
		LL mid = (left + right) / 2;
		if (possible(mid)) {
			left = mid;
		} else {
			right = mid;
		}
	}
#endif

void solve(long long N, std::vector<std::vector<long long>> &D) {
	bool ans = false;
	int cnt = 0;
	for (LL i = 0; i < N; ++i) {
		if (D[i][0] == D[i][1]) {
			++cnt;
			if (cnt == 3) ans = true;
		} else {
			cnt = 0;
		}
	}
	cout << (ans ? "Yes" : "No") << endl;
}

int main() {
    long long N;
	std::cin >> N;
	std::vector<std::vector<long long>> D(N, std::vector<long long>(2));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 2; j++) {
			std::cin >> D[i][j]; // D[i][j]--;
		}
	}
	solve(N, D);
	return 0;
}


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

using namespace std;

int A, B, C;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> A >> B >> C;
    
    cout << max(C - (A - B), 0) << endl;
    
    return 0;
}



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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}


int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int  n; VI a(3);
	cin >>n >>a[0] >>a[1] >>a[2];
	vector<string> s(n);
	rep(i, n) cin >>s[i];
	bool ok = 1;
	string ans;
	auto mkp=[&](int c){return make_pair(s[c][0]=='A'? 0:1,s[c][1]=='C'? 2:1);};
	rep(i, n){
		int sm = a[0]+a[1]+a[2];
		if(sm <= 0){ ok=0; break;}
		int p1,p2; tie(p1, p2) = mkp(i);
		if(a[p1]==0 && a[p2]==0){ ok=0; break;}
		
		if(a[p2]==0){a[p1]--; a[p2]++; ans += 'A'+p2;}
		else if(a[p1]==0){a[p2]--; a[p1]++; ans += 'A'+p1;}
		else if(a[p1]==1 && a[p2]==1 && i<n-1){
			int pp1, pp2; tie(pp1, pp2)=mkp(i+1);
			auto q = a;
			q[p1]--; q[p2]++;
			if(q[pp1]==0 && q[pp2]==0){
				a[p1]++; a[p2]--; ans += 'A'+p1;
			}else{
				a[p1]--; a[p2]++; ans += 'A'+p2;
			}
			
		}else{
			if(a[p1]>=a[p2]){a[p1]--; a[p2]++; ans += 'A'+p2;}
			else{a[p1]++; a[p2]--; ans += 'A'+p1;}
		}
	}
		
	if(ok){
		cout <<"Yes\n";
		for(auto z: ans) cout << z <<"\n";
	}else cout <<"No\n";
	return 0;
}


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

int main() {
  int x, y;
  cin >> x >> y;
  
  if (y >= x * 2 && y % 2 == 0 && y <= x * 4) {
    cout << "Yes" << endl;
  }
  
  else
    cout << "No" << endl;
}

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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

int dp[100005];

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n,q;cin>>n>>q;
  string s;cin>>s;
  for(int i=1;i<n;i++){
    dp[i] = dp[i-1];
    if(s[i-1]=='A'&&s[i]=='C')dp[i]++;
  }
  for(int i=0;i<q;i++){
    int l,r;cin>>l>>r;
    l--,r--;
    cout<<dp[r]-dp[l]<<endl;
  }

  return 0;
}


Measured memory_bytes: 1488
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(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 repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n,k;
	ll ans=0LL;
	cin >>n>>k;
	int r,s,p;
	cin>>r>>s>>p;
	string t;
	cin>>t;
	int fin;
	vector<vector<ll>>dp(n/k+2,vector<ll>(3,0LL));
	for(int i=0;i<k;i++){
	//	clog <<  n / k + (n % k > i ? 1 : 0)<<endl;
		for(int I=0;I<n/k+2;I++){
			for(int J=0;J<3;J++){
				dp[I][J]=0LL;
			}
		}
		fin = n / k + (n % k > i ? 1 : 0) ;
		for (int j = 0; j < n / k + (n % k > i ? 1 : 0); j++)
		{
			if(j!=0){
				dp[j][0]=max(dp[j-1][1],dp[j-1][2]);
				dp[j][1] = max(dp[j - 1][0], dp[j - 1][2]);
				dp[j][2] = max(dp[j - 1][1], dp[j - 1][0]);
			}
			switch(t[j*k+i]){
			case 'r':
				dp[j][0] += p;
				break;
			case 's':
				dp[j][1] += r;
				break;
			case 'p':
				dp[j][2] += s;
				break;
			}
		//	clog<<dp[j][0]<<" "<<dp[j][1]<<" "<<dp[j][2]<<endl;
		}
	//	clog<<dp[fin-1][0]<<" "<<dp[fin-1][1]<<" "<<dp[fin-1][2]<<endl;
		ans += max(dp[fin-1][0], max(dp[fin-1][1], dp[fin-1][2]));
		clog<<ans<<endl;
	}

	cout<<ans<<endl;
}

Measured memory_bytes: 5760
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			String string = scanner.nextLine();
			if (string.equals("END OF INPUT")) {
				break;
			}
			String[] a = string.split(" ");
			StringBuilder stringBuilder = new StringBuilder();
			for (int i = 0; i < a.length; i++) {
				stringBuilder.append(a[i].length());
			}
			System.out.println(stringBuilder);
		}
		scanner.close();
	}

}



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

namespace abc144_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            if(a>=10 || b >= 10)
            {
                Console.WriteLine(-1);
            }
            else
            {
                Console.WriteLine(a*b);
            }
        }
    }
}


Measured memory_bytes: 13140
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

n = int(input())
count = 0
for i in make_divisors(n):
    if i == 1:
        continue
    quotient, remainder = divmod(n, i-1)
    if quotient == remainder:
        count += i-1

print(count)

Measured memory_bytes: 3268
#include<bits/stdc++.h>
#define lli long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define test lli t;cin>>t;while(t--)
#define arrin lli n;cin>>n;lli a[n];for(lli i=0;i<n;i++)cin>>a[i]
#define floop for(lli i=0;i<n;i++)
#define mod 1000000007
#define defvec vector<lli>v
#define ub upper_bound
#define pb push_back
#define bs binary_search
#define endl '\n'
using namespace std;

int main()
{   fastio;
    lli h, w;
    cin >> h >> w;
    if (h == 1 || w == 1)
        cout << "1" << endl;
    else
        cout << (h*w + 1) / 2 << endl;
}
    

Measured memory_bytes: 256