akhauriyash/Code-Regression huggingface dataset:
import os
import sys
from io import BytesIO, IOBase
# from collections import defaultdict as dd
# from collections import deque as dq
# import itertools as it
# from math import sqrt, log, log2
# from fractions import Fraction
# def primeFactors(n): 
#     ans = []
#     # Print the number of two's that divide n 
#     while n % 2 == 0: 
#         ans.append(2) 
#         n = n / 2
          
#     # n must be odd at this point 
#     # so a skip of 2 ( i = i + 2) can be used 
#     for i in range(3,int(sqrt(n))+1,2): 
          
#         # while i divides n , print i ad divide n 
#         while n % i== 0: 
#             ans.append(i)
#             n = n / i 
              
#     # Condition if n is a prime 
#     # number greater than 2 
#     if n > 2: 
#         ans.append(int(n))

#     return ans 

def main():
    k = int(input())
    if k%2 == 0:
        print(-1)
    else:
        pass
    
        rem = 7%k

        ans = -1
        for i in range(1, 10**7):
            if rem == 0:
                ans = i
                break

            rem = 10*rem + 7
            rem %= k

        print(ans)

        


        




































# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 63740
#include<bits/stdc++.h>
#include<stdio.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define pb                  push_back
#define arr                 vector<ll>
#define mem(x,val)          memset(x,val,sizeof(x))
#define vp                  vector<pair<ll,ll>>
#define matrix              vector<vector<ll> >
#define digit(x)            floor(log10(x))+1
#define debug(x)            cerr << #x << " is " << x << endl;
#define all(a)              a.begin(),a.end()
#define fixed               setprecision(15)
// ll dx[]={-1,1,0,0},dy[]={0,0,-1,1}; 4 Sides
//ll dx[]={-1,1,-1,1,0,0,-1,1} , dy[]={-1,1,0,0,-1,1,1,-1};    8 Sides
using namespace std;
ll maxx = INT_MIN;
ll minx = INT_MAX;
arr read(ll n){
    arr a;
    for (ll i=0;i<n;i++){
        ll x;
        cin>>x;
        a.pb(x);
    }
    return a;
}
int main(){
   string s;
   cin>>s;
   ll ans=0;
   for (ll i=0;i<3;i++){
       if (s[i]=='R'){
           ans++;
       }else{
           ans=0;
       }
       maxx=max(ans,maxx);
   }
   cout<<maxx<<endl;
    return 0;
}


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

int main(void){
    // Your code here!
   int x, y;
   cin >> x >> y;
   int a [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
   cout << ( a [ x ] == a [ y ] ? " Yes " : " No ") << endl ;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int num1=fabs(a-b);
	int num2=fabs(a-c);
	int num3=fabs(b-c);
	int max=num1;
	if(max<num2)
		max=num2;
	if(max<num3)
		max=num3;
	int sum=num1+num2+num3-max;
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 128
n = gets.to_i
p = gets.split(' ').map(&:to_i)
count = 0

(n - 2).times do |i|
  count += 1 if (p[i] < p[i + 1] and p[i + 1] < p[i + 2]) or (p[i + 2] < p[i + 1] and p[i + 1] < p[i])
end

p count

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

namespace Tasks
{
    public class B
    {
        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 = Scanner.Scan<int>();
            var answer = false;
            var count = 0;
            for (var i = 0; i < N; i++)
            {
                var (d1, d2) = Scanner.Scan<int, int>();
                if (d1 == d2)
                {
                    count++;
                    if (count >= 3) answer = true;
                }
                else
                {
                    count = 0;
                }
            }
            Console.WriteLine(answer ? "Yes" : "No");
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


Measured memory_bytes: 28248
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int a, b, c, d;
  scanf("%d%d%d%d", &a, &b, &c, &d);

  if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) printf("Yes\n");
  else  printf("No\n");
  return 0;
}


Measured memory_bytes: 128
import math

n = int(input())
ans = n
for i in range(n+1):
    cc = 0
    t = i
    while (t > 0):
        cc += t % 6
        t = math.floor(t/6)
    t = n - i
    while (t > 0):
        cc += t % 9
        t = math.floor(t/9)
    ans = min(ans, cc)
print(ans)


Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{
    int N, M, n, m, A;

    scanf("%d", &N);
    scanf("%d", &M);

    n = N * (N - 1);
    m = M * (M - 1);
    A = n / 2 + m / 2;

    printf("%d\n", A);

    return 0;
}

Measured memory_bytes: 128
S=list(input())
N=len(S)

def circle_judge(S,N):
	circle=True
	if N%2==1:
		ite=(N-1)//2
	elif N%2==0:
		ite=(N+1)//2
	for n in range(ite):
		if S[n]!=S[N-1-n]:
			circle=False
			break
	return circle

def main():
	circle=circle_judge(S,N)
	if circle==True:
		S_h=S[:(N-1)//2]
		circle=circle_judge(S_h,(N-1)//2)
	else:
		pass
	return circle

result=main()
if result==True:
	print('Yes')
elif result==False:
	print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;cin>>n>>m;
  ll sum = 0;
  while(m--){
    ll a;cin>>a;
    sum += a;
  }
  if(sum > n)cout<<-1<<endl;
  else cout<<n-sum<<endl;
  return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define fasterthanlight ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define test int T; cin>>T; while(T--)
#define endl "\n"
#define int long long
#define vi vector<int>
#define pb push_back
#define mod 1000000007
#define MAX 1e9
#define MIN -1e9
#define hi "visited\n" //sasta debugging
using namespace std;

//author::@whohet-->Het Patel

signed main()
{
	fasterthanlight;
	int a;
	long double b;
	cin >> a >> b;
	int b1 = trunc(a * b);
	//int c1 = b1; //cout << b1 << endl;
	cout << b1;
	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
}


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

using namespace std;
const int N = 1e6+100;
typedef long long ll;
vector<pair<int,int> > G[N];
int ans[N];
bool vis[N];
void dfs(int now){
	vis[now]=1;
	for(auto v:G[now]){
		if(!vis[v.first]){
			if(v.second&1){
				ans[v.first]=!ans[now];
			}
			else ans[v.first]=ans[now];
			dfs(v.first);	
		}
	}
}
int main(){
	int n;
	cin>>n;
	int u,v,w;
	for(int i=1;i<=n-1;i++){
		cin>>u>>v>>w;
		G[u].push_back({v,w});
		G[v].push_back({u,w});
	}
	ans[1]=0;
	dfs(1);
	for(int i=1;i<=n;i++){
		cout<<ans[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 29568
#include <bits/stdc++.h>
//#include "Local_Debug.h"
using namespace std;
#define Endl endl
#define debug(x) cout << #x << " = " << (x) << endl
typedef long long ll;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)2e5 + 5;
ll n;
string s;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	while (cin >> n >> s)
	{
		for (auto i : s)
			cout << char((i + n - 'A') % 26 + 'A');
		cout << endl;
	}
}
/*
2
ABCXYZ

0
ABCXYZ

13
ABCDEFGHIJKLMNOPQRSTUVWXYZ
*/

Measured memory_bytes: 256
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]
W = read_int()
INF = float('inf')

def solve():
    ans = INF
    for i in range(N):
        res = abs(sum(W[: (i + 1)]) - sum(W[(i + 1) :]))
        if ans > res: ans = res
    return ans

if __name__ == "__main__":
    print(solve())

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int left = max(a,c);
  int right = min(b, d);
  int ans = max(right-left,0);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <bitset>
#include <iomanip>
#include <sstream>
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define read freopen("input.txt","r",stdin);
#define write freopen("out.txt","w",stdout);
#define showtime cout << 1000.0 * clock() / CLOCKS_PER_SEC << " ms" << endl; 
#define pfi(a) printf("%d\n", a)
#define pfl(a) printf("%lld\n", a)
#define pfc(a) printf("%c\n", a)
#define pf printf
#define sb c scanf
using namespace std;
typedef pair<int, int> poii;
typedef pair<string , int> posi;
typedef map<int, int> moii;
typedef map<string, int> mosi;
typedef long long ll;
typedef unsigned long long ull;
typedef set<int>soi;
typedef set<string>sos;
typedef set<char> soc;
typedef vector<string> vos;
typedef vector <int> voi;


int main() 
{
	fast;
	int x, a;
	cin >> x >> a;
	cout << (x < a ? "0" : "10") << endl;
	// showtime;					
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    
    //入力
    int A,B,C;
    cin >> A>>B>>C;
    
    //処理
    int x=0;
    x=B/A;
    
    if(x>C){
        x=C;
    }
    
    //出力
    cout<<x<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

// Search all cases. 4 ** N
// N is 8. So digit is 16.

int main(int argc, char** argv) {
  ll N, A, B, C;
  cin >> N >> A >> B >> C;
  vector<ll> l(N);
  rep(i, N) {
    cin >> l[i];
  }

  ll ans = INF;
  rep(i, 1LL << (2 * N)) { // Max is 1 << 16 ~ 6*10^4
    ll cost = 0;
    vector<ll> a, b, c;
    rep(j, N) {
      int s = 0;
      s += (i >> (j * 2)) & 1;
      s += (i >> (j * 2)) & 2;
      // 0: not used, 1: used in A, 2: used in B, 3: used in C
      if (s == 0) {
        continue;
      } else if (s == 1) {
        a.push_back(l[j]);
      } else if (s == 2) {
        b.push_back(l[j]);
      } else { // s == 3
        c.push_back(l[j]);
      }
    }
    if ((a.size() == 0) || (b.size() == 0) || (c.size() == 0)) { continue; }
    // Now, a, b, c has at least one.

    ll asum = 0;
    if (a.size() > 1) { cost += (a.size() - 1) * 10; }
    for (auto x : a) { asum += x; }
    cost += abs(asum - A);

    ll bsum = 0;
    if (b.size() > 1) { cost += (b.size() - 1) * 10; }
    for (auto x : b) { bsum += x; }
    cost += abs(bsum - B);

    ll csum = 0;
    if (c.size() > 1) { cost += (c.size() - 1) * 10; }
    for (auto x : c) { csum += x; }
    cost += abs(csum - C);

    if (cost < ans) {
      ans = cost;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll INF = 1e9+7;
int main()
{
    int a, b;
    cin >> a >> b;
    int c = a - 2*b;
    if(c < 0) cout << 0 << endl;
    else cout << c << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
static string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
static long n = long.Parse(input[0]);
static long m = long.Parse(input[1]);
static long[] parents = new long[n];

	static void Main()
	{
    for(long i = 1; i < n; i++)
    {
      parents[i] = i;
    }
    bool answer = true;
    long peopleMemo = 0;
    long languageSum = 0;
    long[][] languageMemoSub = new long[100000][];//言語番号と、話し手番号
    for(long i = 0; i < 100000; i++)
    {
      languageMemoSub[i] = new long[2];
    }
    for(long i = 0; i < n; i++)
    {
		  long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
      for(long j = 0; j < nums[0]; j++)
      {
        languageMemoSub[languageSum][0] = nums[j+1];
        languageMemoSub[languageSum][1] = i;
        languageSum++;
      }
    }

    long[][] languageMemo = new long[languageSum][];//言語番号と、話し手番号
    for(long i = 0; i < languageSum; i++)
    {
      languageMemo[i] = new long[2];
      languageMemo[i][0] = languageMemoSub[i][0];
      languageMemo[i][1] = languageMemoSub[i][1];
    }

    Array.Sort(languageMemo, (a, b) => a[0].CompareTo(b[0]));//言語でソート
    peopleMemo = languageMemo[0][0];

    for(long i = 1; i < languageSum; i++)
    {
      if(languageMemo[i][0] == peopleMemo &&
        whatParent(languageMemo[i-1][1]) != whatParent(languageMemo[i][1]))
      {
        parents[whatParent(languageMemo[i-1][1])] = whatParent(languageMemo[i][1]);//親を結合して統一。
      }else
      {
        peopleMemo = languageMemo[i][0];
      }
    }

    for(long i = 1; i < n; i++)
    {
      if(whatParent(0) != whatParent(i))
      {
        answer = false;
        break;
      }
    }
    
    Console.WriteLine((answer) ? "YES" : "NO");
	}

  static long whatParent(long child)
  {
    if(parents[child] == child) return child;
    else return parents[child] = whatParent(parents[child]);
  }
  
}

Measured memory_bytes: 33992
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef pair<int,int> P;
typedef long long ll;

ll caliculate(ll h,ll w){
    ll ans=1000000000000;
    for(ll i=1;i<h;i++){
        //cout<<i<<"番目"<<endl;
        ll mi=1000000000000;
        ll ma=0;
        ll tri1=i*w;
        ll tri2=(ll)w/2*(h-i);
        ll tri3=(ll)(w-w/2)*(h-i);
        ma=max(ma,max(tri1,max(tri2,tri3)));
        mi=min(mi,min(tri1,min(tri2,tri3)));
        //cout<<ma-mi<<endl;
        ans=min(ans,ma-mi);
        mi=1000000000000;
        ma=0;
        tri1=(h-i)*w;
        tri2=(ll)w/2*i;
        tri3=(ll)(w-w/2)*i;
        ma=max(ma,max(tri1,max(tri2,tri3)));
        mi=min(mi,min(tri1,min(tri2,tri3)));
        //cout<<ma-mi<<endl;
        ans=min(ans,ma-mi);
        if(i>=2){
            mi=1000000000000;
            ma=0;
            tri1=(h-i)*w;
            tri2=(ll)w*(i/2);
            tri3=(ll)(i-i/2)*w;
            ma=max(ma,max(tri1,max(tri2,tri3)));
            mi=min(mi,min(tri1,min(tri2,tri3)));
            //cout<<ma-mi<<endl;
            ans=min(ans,ma-mi);
        }
        if(h-i>=2){
            mi=1000000000000;
            ma=0;
            ll l=h-i;
            tri1=i*w;
            tri2=(ll)w*(l/2);
            tri3=(ll)(l-l/2)*w;
            //cout<<l<<endl;
            ma=max(ma,max(tri1,max(tri2,tri3)));
            mi=min(mi,min(tri1,min(tri2,tri3)));
            //cout<<ma-mi<<endl;
            ans=min(ans,ma-mi);
        }
    }
    return ans;
}

int main(void){
    ll h,w;
    cin>>h>>w;
    cout<<min(caliculate(h,w),caliculate(w,h))<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

int main() {
	int n;cin>>n;
	vector<ll> x(n),y(n),a(n),b(n);
	vector<pair<ll,ll>> p(n);
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i];
		a[i]=x[i];
		b[i]=y[i];
		if(x[i]<y[i]){
			a[i]=y[i];
			b[i]=x[i];
		}
		p[i].first=a[i];
		p[i].second=b[i];
	}
	sort(p.begin(),p.end(),greater<pair<ll,ll>>());
	sort(a.begin(),a.end(),greater<ll>());
	sort(b.begin(),b.end(),greater<ll>());
	ll max=a[0];
	ll min=b[n-1];
	ll ans=(a[0]-a[n-1])*(b[0]-b[n-1]);
	ll max2=p[0].second;
	ll min2=a[n-1];
	ll sub=a[0]-a[n-1];
	for(int i=0;i<n-1;i++){
		if(min2>p[i].second){
			min2=p[i].second;
		}
		if(max2<p[i].second){
			max2=p[i].second;
		}
		if(max2<p[i+1].first){
			if(sub>p[i+1].first-min2){
				sub=p[i+1].first-min2;
			}
		}else{
			if(sub>max2-min2){
				sub=max2-min2;
			}
			break;
		}
	}
	if(ans>(max-min)*sub){
		ans=(max-min)*sub;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 11648
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define N 2001
#define M 1000000007
using namespace std;
ll a[N];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k,s=0,s1=0,r=0,i,j;
    cin>>n>>k;
    ll cct=(k*(k-1)/2)%M;
    for(i=1; i<=n; ++i)
        cin>>a[i];
    for(i=1; i<=n; ++i){
        s=s1=0;
        for(j=1; j<=n; ++j){
            if(a[i]>a[j]){
                ++s;
                if(i<j) ++s1;
            }
        }
        r=(r+(k*s1)%M+(s*cct)%M)%M;
    }
    cout<<r;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n,a,b;

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

    cin>>a>>b>>n;
    long long x=min((b-1),n)*a;
    //cout<<x;
    cout<<x/b;

}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - Addition and Multiplication
            var line = ReadLines(2);
            int N = line[0];
            int K = line[1];
            int num = 1;

            for(int i = 0; i < N; i++)
            {
                if (num < K)
                {
                    num *= 2;
                }
                else
                {
                    num += K;
                }
            }

            Console.WriteLine(num);
        }

        static List<int> ReadLines(int count = 0)
        {
            //[summary]コンソールの値を読み込む
            var lines = new List<int>();
            string s;

            //読み込む行数が未指定のときは、1行目の値を"count"とみなす
            if (count == 0)
            {
                s = Console.ReadLine().TrimEnd();
                count = int.Parse(s);
            }

            for (int i = 0; i < count; i++)
            {
                s = Console.ReadLine().TrimEnd();
                lines.Add(int.Parse(s));
            }

            return lines;
        }
    }
}

Measured memory_bytes: 13140
// #include "testlib.h"
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define endl '\n'
#define Endl '\n'
#define fi first
#define ii pair<ll,ll>
#define se second
#define double long double
#define mod 1000000007
#define popcount __builtin_popcountll
const double PI = acos(-1.0);
using namespace std;
#define MXN 3005
int n, m;
int a[88][88];
int b[88][88];
int dp[80][80][88*88];
int cal(int i, int j, int s){
    if(i==n || j==m || s>=15626)return 1e8;
    if(i==n-1 && j==m-1){
        int d = a[i][j]-b[i][j];
        return min(abs(s+d), abs(s-d));
    }
    int &ret = dp[i][j][s];
    if(ret!=-1)return ret;
    ret = 1e8;
    int d = a[i][j]-b[i][j];
    ret = cal(i+1, j, abs(s+d));
    ret = min(ret, cal(i+1, j, abs(s-d)));
    ret = min(ret, cal(i, j+1, abs(s+d)));
    ret = min(ret, cal(i, j+1, abs(s-d)));
    return ret;
}
int main(){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            scanf("%d", &a[i][j]);
        }
    }
 
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            scanf("%d", &b[i][j]);
        }
    }
    memset(dp,-1,sizeof dp);
    cout<<cal(0,0, 0)<<endl;
}

Measured memory_bytes: 193920
#include <bits/stdc++.h>
typedef long long ll;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define x first
#define y second
#define loop(i, start, end) for(int i=start; i<=end; ++i)
#define loopr(i, end, start) for(int i=end; i>=start; --i)
#define pb push_back
#define MOD 1000000007
using namespace std;
    
template <typename T>
void cloneArray(T *a, T *b, int start, int end) {
    loop(i, start, end) {
        *(b+i)=*(a+i);
    }
}
    
template <typename T>
void inputArray(T *a, int start, int end) {
    loop(i, start, end) cin >> a[i];
}
    
template <typename T>
void printArray(T *a, int start, int end) {
    loop(i, start, end) cout << *(a+i) << ' ';
}
    
void ruffleSort(int *a, int n) {
    unsigned seed=0;
    shuffle(a, a+n, default_random_engine(seed));
    sort(a, a+n);
}

ll mod_add(ll a, ll b) {
    return ((a%MOD)+(b%MOD))%MOD;
}

ll mod_mult(ll a, ll b) {
    return ((a%MOD)*(b%MOD))%MOD;
}
   
int main(int argc, char const *argv[])
{   
    IOS;
    int n;
    cin >> n;
    int a[n+5];
    ll pre[n+5]={}, sum=0;
    inputArray(a, 1, n);
    loop(i, 1, n) pre[i]=pre[i-1]+a[i];
    loop(i, 1, n) {
        sum=mod_add(sum, mod_mult(a[i], pre[n]-pre[i]));
    }
    cout << sum;
    //cerr<<" Execution : "<<(1.0*clock())/CLOCKS_PER_SEC<<"s \n";
    return 0;
}

Measured memory_bytes: 5988
#include<stdio.h>
main(){
  int a,b;
  int d,r;
  double f;
  scanf("%d%d",&a,&b);
  d=a/b;
  r=a%b;
  f=(double)a/(double)b;
  printf("%d %d %f\n",d,r,f);
  return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
//#define INF 1e18
#define MOD 1000000007

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

int n,m,q;
int a[505][505];

int main(){
  cin >> n >> m >> q;
  rep(i,0,m){
    int l,r;
    cin >> l >> r;
    a[1][r]++;//cout << 1 << r;
    a[l+1][r]--; //cout << l+1 << r << endl;
  }
  rep(i,1,n+1){
    rep(j,1,n+1){
      a[i][j] += a[i][j-1];
    }
  }
  rep(i,1,n+1){
    rep(j,1,n+1){
      a[i][j] += a[i-1][j];
    }
  }

  rep(i,0,q){
    int s,t;
    cin >> s >> t;
    cout << a[s][t] << endl;
  }

  return 0;
}


Measured memory_bytes: 1920
import sys
sys.setrecursionlimit(10 ** 7)
S = ['0'] + list(input())

def g(i):
    if i == 0:
        return 0
    if i == 1:
            return 1
    if i == 2:
        if S[2] == S[1]:
            return 1
        else:
            return 2     

    if S[i] == S[i - 1]:
        return g(i - 3) + 2
    if S[i] != S[i - 1]:
        return g(i - 1) + 1
# print (len(S) - 1)
print (g(len(S) - 1))

Measured memory_bytes: 153808
#!/usr/bin python3
# -*- coding: utf-8 -*-

N, M, K = map(int, input().split())
md = 998244353

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % md )
    inverse.append( ( -inverse[md % i] * (md//i) ) % md )
    g2.append( (g2[-1] * inverse[-1]) % md )

def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % md

def cnt(k):
    ret = pow(M-1, N-1-k, md)
    ret *= cmb(N-1,k)
    ret %= md
    ret *= M
    ret %= md
    return ret

def main():
    rt = 0
    for k in range(K+1):
        rt += cnt(k)
        rt %= md
    print(rt)

if __name__ == '__main__':
    main()


Measured memory_bytes: 32728
import sys

input = sys.stdin.readline

n, k = map(int, input().split())
a = tuple(map(int, input().split()))

dp = [None] * (k + k + 1)
# dp[手番の石の数] := 手番の勝敗
# True(勝ち) / None(負け)

for opponent_remains in range(k):  # 自分が石を取った残りなので、k未満
    if dp[opponent_remains] is None:  # 相手が負ける場合
        for my_take in a:  # 自分が取る石の数
            my_remains = opponent_remains + my_take  # 相手が負けるようにできる、自分の手番の石の数
            dp[my_remains] = True

ans = dp[k]
print('First' if ans else 'Second')

# 内側のループに入る前に枝刈りしているので、速い


Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
#define sz(x) int(x.size())
#define pb push_back
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ff first
#define ss second
typedef long long ll;
typedef pair<int, int> ii;

int p[52];

int main(){
	fastio;
	int n; cin >> n;
	int bad = 0;
	for(int i = 0; i < n; ++ i) {
		cin >> p[i];
		p[i] --;
		if(p[i] != i) bad ++;
	}
	if(bad > 2) cout << "NO" << endl;
	else cout << "YES" << endl;
	return 0;
}



Measured memory_bytes: 3648
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
const int INF = 100000000;

int main() {
  int n, x0, y0;
  cin >> n >> x0 >> y0;
  vector<int> a(n);
  int ans = 0;

  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
int s1,s2;
  s1 = abs(a[n - 1] - y0);
  if (n != 1) {
    s2 = abs(a[n - 2] - a[n - 1]);
  } else {
    s2 = s1;
  }
  cout << max(s1, s2) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
using namespace std;
int main(){
    int k, s;
    cin >> k >> s;
    int z,cnt=0;
    rep(i,k+1){
        rep(j,k+1){
            z = s - i - j;
            if(0 <=z && z <= k)
                cnt ++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
# include <cstdio>
# include <vector>
# include <algorithm>

using namespace std;

const int MAX_N = 2048;
const int MAX_M = 2048;

int n, m;

char c[MAX_N][MAX_M];
int a[MAX_N][MAX_M];
int l[MAX_N][MAX_M];

int right[MAX_M];
int ans;

int main ()
{
    int i, j;
    scanf ("%d%d", &n, &m);
    for (i = 1; i <= n; i ++)
        scanf ("%s", c[i] + 1);

    for (i = 1; i < n; i ++)
        for (j = 1; j < m; j ++)
        {
            a[i][j] = ((c[i][j] == '#') + (c[i + 1][j] == '#') + (c[i][j + 1] == '#') + (c[i + 1][j + 1] == '#')) & 1;
            if (a[i][j])
                l[i][j] = 0;
            else
                l[i][j] = l[i - 1][j] + 1;
        }

    if (n < m)
        ans = m;
    else
        ans = n;

    n --;
    m --;

    vector <pair <int, int>> t;

    for (i = 1; i <= n; i ++)
    {
        t.clear ();

        for (j = m; j >= 1; j --)
        {
            int cnt = 1;
            while (t.size () && t[t.size () - 1].first >= l[i][j])
            {
                cnt += t[t.size () - 1].second;
                t.pop_back ();
            }
            t.push_back ({l[i][j], cnt});
            right[j] = cnt;
        }

        t.clear ();

        for (j = 1; j <= m; j ++)
        {
            int cnt = 1;
            while (t.size () && t[t.size () - 1].first >= l[i][j])
            {
                cnt += t[t.size () - 1].second;
                t.pop_back ();
            }
            t.push_back ({l[i][j], cnt});

            if ((right[j] + cnt) * (l[i][j] + 1) > ans)
                ans = (right[j] + cnt) * (l[i][j] + 1);
        }
    }

    printf ("%d\n", ans);

    return 0;
}


Measured memory_bytes: 37120
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var scanner *bufio.Scanner

func printIt() {
	n := nextInt()
	nums1 := make([]float64, n)
	nums2 := make([]float64, n)
	for i := 0; i < n; i++ {
		nums1[i] = nextFloat()
	}
	for i := 0; i < n; i++ {
		nums2[i] = nextFloat()
	}
	r1 := 0.0
	r2 := 0.0
	r3 := 0.0
	r := 0.0
	for i := 0; i < n; i++ {
		r1 += math.Abs(nums1[i] - nums2[i])
		r2 += math.Pow(math.Abs(nums1[i]-nums2[i]), 2)
		r3 += math.Pow(math.Abs(nums1[i]-nums2[i]), 3)
		if math.Abs(nums1[i]-nums2[i]) > r {
			r = math.Abs(nums1[i] - nums2[i])
		}
	}
	fmt.Println(r1)
	fmt.Println(math.Sqrt(r2))
	fmt.Println(math.Pow(r3, 1.0/3.0))
	fmt.Println(r)
}

func nextInt() int {
	scanner.Scan()
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(1)
	}
	return num
}

func nextFloat() float64 {
	scanner.Scan()
	num, err := strconv.ParseFloat(scanner.Text(), 10)
	if err != nil {
		panic(1)
	}
	return num
}

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	printIt()
}



Measured memory_bytes: 1156
N = int(input())

A = list(map(int,input().split()))


f = 0
s = 0
for i in range(N):
    if f == 0:
        s += A[i]
    else:
        s -= A[i]
    f = 1 - f

ans = [0] * N
ans[0] = str(s)

for i in range(N - 1):
    ans[i + 1] = str((A[i] - int(ans[i]) // 2 )* 2)
print(" ".join(ans))





Measured memory_bytes: 17228
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>


using namespace std;

int main(){
  string S;
  string A = "keyence";
  cin >> S;
  bool ok = false;
  for(int i = 0 ; i < (int)A.size(); i++){
     string S1 = S.substr(0,i);
     int b = A.size()-i;
     string S2 = S.substr(S.size()-b, b);
     string S3 = S1+S2;
     //cout <<S1<<" " << S2 <<endl;
     if(S3 == A){
        ok = true;
     }
  }
  if(ok) cout <<"YES"<<endl;
  else cout <<"NO"<<endl;
  

  return 0;
}


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

#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        998244353
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll n,s;
    cin>>n>>s;
    vi v(n+1);
    rep(i,1,n) cin>>v[i];
    ll dp[n+1][s+1];
    memset(dp,0,sizeof(dp));
    // dp[0][0]=1;
    rep(i,1,n){
        rep(j,0,s) dp[i][j]=dp[i-1][j];
        if(v[i]<=s) dp[i][v[i]]=(dp[i][v[i]]+i)%hell;
        rep(j,0,s){
            if((v[i]+j)<=s) dp[i][v[i]+j]=(dp[i][v[i]+j]+dp[i-1][j])%hell;
        }
    }
    ll tot=0;
    rep(i,1,n){
        tot=(tot+dp[i][s])%hell;
    }
    // rep(i,1,n) rep(j,0,s) cout<<dp[i][j]<<" \n"[j==s];
    cout<<tot<<endl;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 70656
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<vector>
using namespace std;
#define read freopen("in.in","r",stdin)
#define write freopen("out.out","w",stdout)
#define FastIO ios::sync_with_stdio(0)
#define Mod 1000000007
typedef long long ll;
int n;
double coins[3000];
double memo[3000][3000];
double solve(int idx, int head) {
	if(idx==n)
	return head > n - head ? 1 : 0;

	double &ret = memo[idx][head];
	if (ret != -1)return ret;
	ret = (solve(idx + 1, head + 1)*coins[idx]) + (solve(idx + 1, head)*(1 - coins[idx]));
	return ret;
}
int main() {
	FastIO;
#ifndef ONLINE_JUDGE
	//write; read;
#endif 
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> coins[i];
	for (int i = 0; i < 3000; i++)
		for (int j = 0; j < 3000; j++)
			memo[i][j] = -1;
	double res = solve(0, 0);
	cout << setprecision(10)<<res << endl;

	return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

int n, a, b, c, d;
string s;

bool check_reach(int start, int end) {
  for (int i = start; i <= end - 1; ++i) {
    if (s[i] == '#' && s[i + 1] == '#') {
      return false;
    }
  }

  return true;
}

bool check_triple() {
  bool ret = false;
  for (int i = b; i <= d; ++i) {
    if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') ret = true;
  }

  return ret;
}

int main(void) {
  // Here your code !
  scanf("%d %d %d %d %d", &n, &a, &b, &c, &d);
  --a; --b; --c; --d;

  cin >> s;

  // s = '#' + s + '#';

  if (!check_reach(a, c) || !check_reach(b, d)) {
    printf("No\n");
    return 0;
  }

  if (c < d) {
    printf("Yes\n");
    return 0;
  }

  if (check_triple()) {
    printf("Yes\n");
  }
  else {
    printf("No\n");
  }

  return 0;
}


Measured memory_bytes: 640
x = input()
y = input()
co = [[0] * (len(x)+1) for i in range(len(y)+1)]

for i in range(len(x)+1):
    co[0][i] = i
for i in range(len(y)+1):
    co[i][0] = i

for i in range(len(y)):
    for j in range(len(x)):
        count = 0
        if x[j] != y[i]:
            count += 1
        co[i+1][j+1] = min(co[i][j]+count, co[i+1][j]+1, co[i][j+1]+1)

print(co[len(y)][len(x)])
#print(co)


Measured memory_bytes: 43068
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
		Date baseDate = sdf.parse("2019/04/30");
		try(Scanner sc = new Scanner(System.in)){
				String ret = baseDate.compareTo(sdf.parse(sc.nextLine())) == -1 ? "TBD" : "Heisei";
				System.out.println(ret);
			}
		}	
}


Measured memory_bytes: 24016
import Foundation
let input_line: String = readLine()!
let split: [String] = input_line.components(separatedBy: " ") //ブランクで区切られている場合
let x = split[0]
let length = x.count
var ans = ""
for i in 0..<length{
    ans += "x"
}
print(ans)

Measured memory_bytes: 13576
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	void solve() throws IOException {
		int n = ni();
		int m = ni();
		int a[] = nia(n);

		Map<Long, Integer> mp = new HashMap<Long, Integer> ();
		mp.put(0L, 1);
		long sum = 0;
		long ans = 0;
		for (int i:a) {
			sum += i;
			sum %= m;
			ans += mp.getOrDefault(sum, 0);
			mp.put(sum, mp.getOrDefault(sum, 0)+1);
		}
		out.println(ans);
	}


	String ns() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine(), " ");
		}
		return tok.nextToken();
	}

	int ni() throws IOException {
		return Integer.parseInt(ns());
	}

	long nl() throws IOException {
		return Long.parseLong(ns());
	}

	double nd() throws IOException {
		return Double.parseDouble(ns());
	}

	String[] nsa(int n) throws IOException {
		String[] res = new String[n];
		for (int i = 0; i < n; i++) {
			res[i] = ns();
		}
		return res;
	}

	int[] nia(int n) throws IOException {
		int[] res = new int[n];
		for (int i = 0; i < n; i++) {
			res[i] = ni();
		}
		return res;
	}

	int[][] nia(int n, int m) throws IOException {
		int[][] res = new int[n][];
		for (int i = 0; i < n; i++) {
			res[i] = nia(m);
		}
		return res;
	}

	long[] nla(int n) throws IOException {
		long[] res = new long[n];
		for (int i = 0; i < n; i++) {
			res[i] = nl();
		}
		return res;
	}

	public static void main(String[] args) throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		tok = new StringTokenizer("");
		Main main = new Main();
		main.solve();
		out.close();
	}
}

Measured memory_bytes: 46284
#include <iostream>
#include <cstring>
#define MAXS 500000
using namespace std;
int main(){
	char str[MAXS+1];
	int S;
	long long len[2] = {0, 0};
	char mark[2] = {'<', '>'};
	int now = 0;
	long long ans = 0;
	const long long& (*funcs[2])(const long long&, const long long&) = {min, max};
	cin >> str;
	S = strlen(str);
	for(int i=0; i<=S; i++){
		if(str[i] == mark[now])
			len[now]++;
		else{
			//cout << "len[" << now << "] = " << len[now] << endl;
			if(now || i == S){
				for(int j=0; j<2; j++){
					long long m = funcs[j](len[0], len[1]) + j;
					ans += (m * (m - 1)) / 2;
				}
				for(int j=0; j<2; j++)
					len[j] = 0;
			}
			now ^= 1;
			len[now]++;
		}
	}
	cout << ans << endl;
}






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

using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	double ans=0;
	for(int i=1;i<=n;i++){
		double t=1.0/n;
		int l=i;
		while(l<k){
			l*=2;
			t/=2;
		}
		ans+=t;
	}
	printf("%.15f",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

int main(){
  int N,D,A;
  cin>>N>>D>>A;
  VI X(N),H(N);
  rep(i,N) cin>>X[i]>>H[i];
  vector<PII> P(N);
  rep(i,N) P[i]=mp(X[i],H[i]);
  sort(all(P));
  rep(i,N){
    X[i]=P[i].first;
    H[i]=P[i].second;
  }
  VL cnt(N+1);
  VI R(N);
  rep(i,N) R[i]=ub(all(X),X[i]+D*2)-X.begin()-1;
  ll ans=0;
  rep(i,N){
    if(i) cnt[i]+=cnt[i-1];
    ll tmp=(max(0ll,H[i]-cnt[i]*A)+A-1)/A;
    ans+=tmp;
    cnt[i]+=tmp;
    cnt[R[i]+1]-=tmp;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5760
N,W = map(int,input().split())
wv = list(list(map(int,input().split()))for i in range(N))
DP = [[0]*(W+1) for i in range(N+1)]
for i in range(N):
    w,v = wv[i]
    for j in range(1,W+1):
        if j >= w:
            DP[i+1][j] = max(DP[i][j-w]+v,DP[i][j],DP[i+1][j-1])
        else:
            DP[i+1][j] = max(DP[i][j],DP[i+1][j-1])
print(DP[-1][-1])

Measured memory_bytes: 120300
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll K = 0;
ll t;
ll ret = 0;
string s;

ll l[200005];
ll r[200005];

// ll modPow(ll x, ll y) {
//   if (y == 1) return x;
//   else if (y % 2 == 0) return modPow((x * x) % MOD, y / 2);
//   else return (x * modPow((x * x) % MOD, y / 2)) % MOD;
// }

void input() {
  IN(N);
  IN(K);
}

void solve() {
  l[1] = 0;
  r[1] = N;
  FOR(i, 2, N+2) {
    l[i] = l[i-1] + (i-1);
    l[i] %= MOD;
    r[i] = r[i-1] + (N-i+1);
    r[i] %= MOD;
    // DEBUG(l[i]);
    // DEBUG(r[i]);
    // LN();
  }
  FOR(i, K, N+2) {
    ret += r[i] - l[i] + 1;
    ret %= MOD;
  }
  while(ret < 0) ret += MOD;
  PRINT(ret);
}

int main(void){
  input();
  solve();
}


Measured memory_bytes: 6692
import sys
import math


def input():
    return sys.stdin.readline()[:-1]

A, B, H, M = map(int, input().split())
rad_H = math.pi*2 * H / 12 + math.pi/6 * M / 60
rad_M = math.pi*2 * M / 60

diff_rad = abs(rad_H-rad_M)
if diff_rad > math.pi:
	diff_rad = 2*math.pi - diff_rad


ans = A**2 + B**2 - 2 * A * B * math.cos(diff_rad)
print(math.sqrt(ans))


Measured memory_bytes: 62404
#include <stdio.h>
int F[44];
void Fibo(int N){
        int i;
        F[0]=1;
        F[1]=1;
        for(i=2; i<=N; i++) {
                F[i]=F[i-2]+F[i-1];
        }
        printf("%d\n",F[N]);
}
int main(){
        int n;
        scanf("%d",&n);
        Fibo(n);
        return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000




int main(){
	int N,C;
	cin>>N>>C;
	
	vector<int> A(N),B(N);
	
	for(int i=0;i<N;i++)cin>>A[i];
	for(int i=0;i<N;i++)cin>>B[i];
	
	vector<vector<int>> beki(N,vector<int> (500,0));
	
	for(int i=0;i<N;i++){
		vector<int> X(B[i]-A[i]+1);
		
		for(int j=0;j<=C;j++){
			int a = 0;
			for(int k=0;k<X.size();k++){
				if(j==0)X[k]=1;
				else{
					X[k] = mod(X[k] * (A[i]+k));
				}
				a = mod(a+X[k]);
			}
			beki[i][j] = a;
		}
	}
	
	vector<vector<int>> dp(N+1,vector<int>(C+1,0));
	
	dp[0][0] = 1;
	
	for(int i=1;i<=N;i++){
		for(int j=0;j<=C;j++){
			for(int k=0;k<=C;k++){
				int a = j-k;
				if(a<0)break;
				
				dp[i][j] = mod(dp[i][j] + mod(dp[i-1][a] * beki[i-1][k]));
			}
			
			
		}
	}
				
	cout<<dp[N][C]<<endl;
		
	
	return 0;
}


Measured memory_bytes: 1664
#include<stdio.h>
int main(void)
{
	int n,k,h,i,cnt;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++){
		scanf("%d",&h);
		if(h>=k)	cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}


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

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    ll t = A[0];
    vector<pair<ll,ll>> ans;
    for(int i=1;i<N;i++){
        if(i==N-1){
            cout << A[i] -t << endl;
            ans.emplace_back(A[i],t);
            break;
        }
        if(A[i] >=0){
            ans.emplace_back(t,A[i]);
            t = (t-A[i]);
        }else{
            ans.emplace_back(A[N-1],A[i]);
            A[N-1] -= A[i];
        }
        
    }
    for(auto P:ans){
        cout << P.first << " "<<P.second<<endl;
    }

    return 0;
}


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

int main() {
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    double X = abs(x2 - x1);
    double Y = abs(y2 - y1);

    double Z = pow(X, 2.0) + pow(Y, 2.0);
    double ans = sqrt(Z);

    printf("%f\n", ans);

    return 0;

}


Measured memory_bytes: 3284
#include <iostream>
#include<iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))

int GCD(int a, int b){
   return b ? GCD(b, a%b) : a;
}

int LCM(int a, int b){
   return (a * b)/(GCD(a, b));
}

int main(){
   int n, k;
   cin >> n >> k;

   double p = 0;
   for(int i = 1; i <= n; i++){
      int score = i;
      double p_dice = 1./n;
      while(score <= k-1){
         score *= 2;
         p_dice /= 2.;
      }
   p += p_dice;
   }

   cout <<std::setprecision(13) << p << endl;
   return 0;
}

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

int main()
{
	int n,m,l;

	cin >> n >> m >> l;

	int a[101][101] = {};
	int b[101][101] = {};
	long c[101][101] = {};

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < l; j++)
		{
			cin >> b[i][j];
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < l; j++)
		{
			for (int k = 0; k < m; k++)
			{
				c[i][j] += a[i][k] * b[k][j];
			}
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < l; j++)
		{
			cout << c[i][j];
			if (j != l-1)
			{
				cout << " ";
			}
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1328
n=int(input())
a=list(map(int,input().split()))
dic={}
for i in range(n):
  if a[i] in dic:
    dic[a[i]]+=1
  else:
    dic[a[i]]=1
ans=0
for i in dic.values():
  ans+=i*(i-1)/2
for i in range(n):
  bk=dic[a[i]]
  print(int(ans-bk+1 if bk>1 else ans))

Measured memory_bytes: 25644
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <string>
#include <map>
#include <list>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define LargeNum 1000000007

int main(){
    int N, k, t, ans;
    ull K;
    cin >> N >> K;
    int A[N + 1], memo[N + 1];
    rep(i, N) cin >> A[i + 1];
    rep(i, N) memo[i + 1] = -1;
    k = 1;
    t = 0;
    while(memo[k] == -1 && K > t){
        memo[k] = t;
        t++;
        k = A[k];
    }
    if (t == K) ans = k;
    else{
        int cycle = t - memo[k];
        K = (K - memo[k]) % cycle;
        rep(i, K){
            k = A[k];
        }
        ans = k;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5168