akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define sc(a) scahf("%c",&a);
#define ss(a) scanf("%s",a)
#define pi(a) printf("%d\n",a)
#define pl(a) printf("%lld\n",a)
#define pc(a) putchar(a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i, a, b) for(register int i=a;i<=b;++i)
#define repd(i, a, b) for(register int i=a;i>=b;--i)
#define reps(s) for(register int i=head[s];i;i=Next[i])
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pii pair<int,int>
#define mii unordered_map<int,int>
#define msi unordered_map<string,int>
#define lowbit(x) ((x)&(-(x)))
#define ce(i, r) i==r?'\n':' '
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;

inline int qr() {
    int f = 0, fu = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-')fu = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        f = (f << 3) + (f << 1) + c - 48;
        c = getchar();
    }
    return f * fu;
}

const int N = 5e3 + 10;
int n, k;
int a[N], b[N], tot;
bool v[N];
vector<int> seq[N];
ll sum[N *3];

void dfs(int x) {
    if (v[x])return;
    v[x] = true, seq[tot].pb(x), dfs(a[x]);
}

ll calc(int u) {
    int len = seq[u].size();
    repi(i, 1, len)sum[i] = sum[i - 1] + b[seq[u][i - 1]];
    ll ans = -4e18, res = 0;
    //pr(len);
    //repi(i,1,len)printf("%lld%c",sum[i],ce(i,len));
    int c = k;
    if (sum[len] > 0&&k>len) {
        res = sum[len] * ((k-len) / len);
        c = k%len+len;
    }
    repi(i, 1, len)sum[i + len] = sum[i + len - 1] + b[seq[u][i - 1]];
    repi(i, 1, len)sum[i + 2*len] = sum[i + 2*len - 1] + b[seq[u][i - 1]];
    len *=3;
    repi(i, 1, len) { repi(j, 1, c) { if (i + j - 1 <= len)ans = max(ans, sum[i + j - 1] - sum[i - 1]); else break; }}
    return ans + res;
}

int main() {
    n = qr(), k = qr();
    repi(i, 1, n)a[i] = qr();
    repi(i, 1, n)b[i] = qr();
    repi(i, 1, n)if (!v[i])tot++, dfs(i);
    ll ans = -4e18;
    repi(i, 1, tot)ans = max(ans, calc(i));
    pl(ans);
    return 0;
}

Measured memory_bytes: 4248
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	int num;
	scanf("%d", &num);
	vector<ll>v;
	for (int i = 0; i < num; i++)
	{
		ll z;
		scanf("%lld", &z);
		v.push_back(z);
	}
	ll ans = 0;
	for (;;)
	{
		sort(v.begin(), v.end());
		reverse(v.begin(), v.end());
		if (v[0] <= num - 1)break;
		if (v[0] <= num * 10)
		{
			for (;;)
			{
				ans++;
				v[0] -= num;
				for (int i = 1; i < num; i++)v[i]++;
				sort(v.begin(), v.end());
				reverse(v.begin(), v.end());
				if (v[0] <= num - 1)break;
			}
			break;
		}
		int t = 0;
		for (int i = 0; i < v.size(); i++)if (v[0] - v[i] <= num + 1)t = i + 1;
		ll x;
		if (t == num)x = v[t - 1] - num * 2;
		else x = (v[t - 1] - max((ll)num, v[t])) / (num + 1);
		x = max(x, 0LL);
		ans += x*t;
		for (int i = 0; i < t; i++)v[i] -= x*(num - (t - 1));
		for (int i = t; i < num; i++)v[i] += x*t;
		if (x == 0)
		{
			ans++;
			v[0] -= num;
			for (int i = 1; i < num; i++)v[i]++;
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      int k = sc.nextInt();
      int x = sc.nextInt();

      int start = x - k +1;
      int end = x + k -1;

      for(int i=start;i<=end;i++){
        System.out.print(i+" ");
      }




    }
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define reps(i,a,b) for(int i=a;i>=b;i-=1)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pi pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define in1(x) int x; cin>>x;
#define in2(x, y) int x, y; cin>>x>>y;
#define in3(x, y, z) int x, y, z; cin>>x>>y>>z;
#define in4(x, y, z, w) int x, y, z, w; cin>>x>>y>>z>>w;
#define mi unordered_map<int,int>
#define mem(x) memset(x, 0, sizeof(x))
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int32_t main(void){
	IOS;
	string s1, s2;
	cin>>s1>>s2;
	int n = s1.length();
	if(s2.length() != n+1) cout<<"No"<<endl;
	else
	{
		string s = "";
		rep(i, 0,n) s += s2[i];
		if(s == s1) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
}

Measured memory_bytes: 3644
#!/usr/bin/env python3


def main():
    N = int(input())
    Hs = list(map(int, input().split()))

    for i in reversed(range(1, N)):
        if Hs[i] - Hs[i-1] == -1:
            Hs[i-1] -= 1
        elif Hs[i] - Hs[i-1] <= -2:
            print('No')
            return
    print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 14396
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = int64_t;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll n;
    cin >> n;
    vi a(n);
    rep(i,n) cin >> a.at(i);
    ll res = 0;
    rep(i,n){
        if(a.at(i)%2==1 && i%2==0) res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int n,m,i,j,xx,yy,x,y,ans;
int f[200001],siz[200001];

inline int get(int x){
if (f[x]==x) return x;
else return f[x]=get(f[x]);
}

int main(){
scanf("%d%d",&n,&m);
for (i=1; i<=n; i++) f[i]=i,siz[i]=1;
for (i=1; i<=m; i++)
{
scanf("%d%d",&x,&y);
xx=get(x); yy=get(y);
if (xx!=yy)
{
f[xx]=yy;
siz[yy]+=siz[xx];
}
//for (j=1; j<=n; j++) printf("%d ",get(f[j])); puts(""); 
}
for (i=1; i<=n; ++i) ans=max(ans,siz[i]);
printf("%d\n",ans);
return 0;
}

Measured memory_bytes: 5384
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;

set<int> s;

int n, a[505];
int r[250005];
vector<int> v[505];
pi b[505];

int main(){
	cin >> n;
	for(int i=1; i<=n; i++){
		cin >> a[i];
		b[i] = pi(a[i], i);
	}
	sort(b+1, b+n+1);
	for(int i=1; i<=n*n; i++){
		s.insert(i);
	}
	for(int i=1; i<=n; i++){
		for(int j=1; j<b[i].second; j++){
			if(*s.begin() >= b[i].first){
				puts("No");
				return 0;
			}
			r[*s.begin()] = b[i].second;
			s.erase(s.begin());
		}
		s.erase(b[i].first);
		r[b[i].first] = b[i].second;
	}
	for(int i=1; i<=n; i++){
		for(int j=b[i].second+1; j<=n; j++){
			r[*s.begin()] = b[i].second;
			s.erase(s.begin());
		}
	}
	for(int i=1; i<=n*n; i++){
		v[r[i]].push_back(i);
	}
	for(int i=1; i<=n; i++){
		if(v[i][i-1] != a[i]){
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	for(int i=1; i<=n*n; i++) printf("%d ",r[i]);
}



Measured memory_bytes: 12928
import java.util.Scanner;

public class Main {
	
	public static void main(String... ac) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt(), d = sc.nextInt(), x = sc.nextInt();
		
		for (int i = 0; i < n; i++) {
			
			int a = sc.nextInt();
			
			x += (d + a - 1) / a;
			
		}
		
		System.out.println(x);
		
	}
	
}

Measured memory_bytes: 21332
from dataclasses import dataclass 
from collections import  defaultdict
from pprint import  pprint

@dataclass
class mount:
    id: int
    height: int

if __name__ == "__main__":
    n,m = list( map( int, input().split(' ')) ) 
    ar = [0] + list(map(int, input().split(" ")))
    d =  defaultdict(lambda : [])
    for i in range(1,n+1):
        d[i] = []
    for i in range(m):
        f,to = list(map(int, input().split(' ')))
        d[f].append(ar[to])
        d[to].append(ar[f])
    count = 0
    for i in d:
        if all([ ar[i] > x for x in d[i]]):
            count +=1 
    print(count )



  

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

typedef long long ll;
typedef pair<int, int> pii;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repp(i, s, e) for (int i = (s); i < (e); i++)
#define all(x) x.begin(), x.end()

#define endl "\n"

void use_cio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto x : V) os << x << ", ";
  return os << "]";
}

//--------------------------------------------------//

int main() {
  use_cio();
  int n, l;
  cin >> n >> l;
  int mn = 1e9;
  int mnh = -1;
  ll sum = 0;
  rep(i, n) {
    if (mn > abs(l + i)) {
      mn = min(mn, abs(l + i));
      mnh = l + i;
    }
    sum += l + i;
  }
  cout << sum - mnh << endl;
}


Measured memory_bytes: 256
program ccc

implicit none
integer :: n, k
integer,allocatable,dimension(:) :: d


read*, n
allocate(d(n))
read*, d

call heapsort(n,d)

write(*,'(i0)') (d(n/2+1)-d(n/2))

end program

subroutine heapsort(n,array)
  implicit none
  integer,intent(in) :: n
  integer,intent(inout) :: array(1:n)
 
  integer ::i,k,j,l
  integer :: t
 
  if(n.le.0)then
     write(6,*)"Error, at heapsort"; stop
  endif
  if(n.eq.1)return

  l=n/2+1
  k=n
  do while(k.ne.1)
     if(l.gt.1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k.eq.1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j.le.k)
        if(j.lt.k)then
           if(array(j).lt.array(j+1))j=j+1
        endif
        if (t.lt.array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo

  return
end subroutine heapsort

Measured memory_bytes: 1152
N = int(input())
lists = []
AC = 0
TLE = 0
WA = 0
RE = 0
for i in range(N):
    S = str(input())
    lists.append(S)
for o in lists:
    if o == "AC":
        AC +=1
    elif o == "TLE":
        TLE +=1
    elif o == "WA":
        WA +=1
    elif o == "RE":
        RE +=1
print("AC x "+str(AC))
print("WA x "+str(WA))
print("TLE x "+str(TLE))
print("RE x "+str(RE))

Measured memory_bytes: 16324
#include<bits/stdc++.h>
using namespace std;
#define MP make_pair
#define F first
#define S second
typedef pair<double, double> P;
vector<P> ans;
double Pythagorean(double x, double y){
    return sqrt(x * x + y * y);
}
void KochCurve(P s, P e, int n){
    if(n){
        double l = Pythagorean((e.F - s.F) / 3, (e.S - s.S) / 3);
        l *= sqrt(3) / 2;
        P direct = MP(e.F - s.F, e.S - s.S);
        double temp = Pythagorean(direct.F, direct.S);
        direct.F /= temp; direct.S /= temp;
        
        P c1 = MP((e.F - s.F) / 3 + s.F, (e.S - s.S) / 3 + s.S);
        P c2 = MP((e.F - s.F) / 2 - direct.S * l + s.F, (e.S - s.S) / 2 + s.S + direct.F * l);
        P c3 = MP((e.F - s.F) / 3 * 2 + s.F, (e.S - s.S) / 3 * 2 + s.S);
        n--;
        KochCurve(s, c1, n);
        KochCurve(c1, c2, n);
        KochCurve(c2, c3, n);
        KochCurve(c3, e, n);
        n++;
    }
    else{
        ans.push_back(e);
        return;
    }
}
int main(){
    int n;
    P s = MP(0, 0), e = MP(100, 0);
    cin >> n;
    KochCurve(s, e, n);
    cout << s.F << " " << s.S << endl;
    for(int i = 0; i < ans.size(); i++){
        cout << ans[i].F << " " << ans[i].S << endl;
    }
}


Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define ll long long int 
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a;i<n;i++)
#define ve vector
#define ss second 
#define ff first
#define pf pop_front
#define pob pop_back
#define psf push_front
#define it vector<ll>:: iterator
#define res(x) cout<<x<<'\n'
#define read(t) ll t;cin>>t
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    read(n);
    read(k);
    ll a[n];
    f(i,0,n)
    cin>>a[i];
    ll dp[n];
    dp[0]=0;
    for(int i=1;i<n;i++){
        ll t = k;
        int j=i-1;
        dp[i]=1e9;
    while(t && j>=0){
        dp[i]=min(dp[j]+abs(a[i]-a[j]),dp[i]);
        j--;
        t--;    
    }
    }
    res(dp[n-1]);
    return 0;
    }

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

int main(){

    int A[100000];
    int p=0,r,x,i,j,n;
    
    scanf("%d", &r);
    for(i=0;i<r;i++){
        scanf("%d",&A[i]);
    }
    x=A[r-1];
    i=p-1;
    for(j=p;j<r-1;j++){
        if(A[j]<=x){
            i++;
            n=A[i];
            A[i]=A[j];
            A[j]=n;
        }
    }
    n=A[i+1];
    A[i+1]=A[r-1];
    A[r-1]=n;
    
    for(j=0;j<r;j++){
        if(j) printf(" ");
        if(j==i+1) printf("[%d]",A[j]);
        else printf("%d",A[j]);
    }
    printf("\n");

    return 0;
}



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

using namespace std;
#define MAX 100000

int parent(int i) { return i / 2; }
int left(int i) { return 2 * i; }
int right(int i) { return 2 * i + 1; }

int main() {
    int H, i, A[MAX + 1];
    scanf("%d", &H);
    for(int i = 1; i <= H; i++) {
        scanf("%d", &A[i]);
    }

    for(i = 1; i <= H; i++) {
        cout << "node " << i << ": key = " << A[i] << ", ";
        if(parent(i) >= 1)
            cout << "parent key = " << A[parent(i)] << ", ";
        if(left(i) <= H)
            cout << "left key = " << A[left(i)] << ", ";
        if(right(i) <= H)
            cout << "right key = " << A[right(i)] << ", ";
		cout << endl;
    }
	return 0;
}


Measured memory_bytes: 3244
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

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

uint64_t dec_dig(uint64_t num) {
  uint64_t res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

uint64_t gcd(uint64_t a, uint64_t b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

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

int main() {
  uint64_t a, b;
  cin >> a >> b;
  char c;
  uint32_t cnt;
  if (a > b) {
    c = b + '0';
    cnt = a;
  } else {
    c = a + '0';
    cnt = b;
  }
  for (uint32_t i = 0; i < cnt; ++i) {
    cout << c;
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力(スペース改行関係なし)
		int x = sc.nextInt();


		if(x==0){
			// 出力
			System.out.println(1);
		}else{
			System.out.println(0);
		}
		
	}
}

Measured memory_bytes: 35656
#include <stdio.h>

int main()
{
 int a, b, c, d, e;
 scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
 if(a >= (c + e) && b >= (d + e) && (c - e) >= 0 && (d - e) >= 0 && (d + e) >= 0 && (c + e) >= 0)
   printf("Yes\n");
 else
  printf("No\n");
 return 0;
}

Measured memory_bytes: 584
#include <stdio.h>
#include <string.h>

int rev(char *s){
    int i,j;
    int sum = 0;

        if(s[0] == 'm')
            sum+=1000;
        if(s[0] == 'c')
            sum+=100;
        if(s[0] == 'x')
            sum+=10;
        if(s[0] == 'i')
            sum+=1;


    for(i = 1; i < strlen(s); i++){
        if(s[i] == 'm'){
            if(s[i-1] >= '2' && s[i-1] <= '9'){
                sum += 1000*(s[i-1] - '0');
            }else{
                sum+=1000;
            }
        }
        if(s[i] == 'c'){
            if(s[i-1] >= '2' && s[i-1] <= '9'){
                sum += 100*(s[i-1] - '0');
            }else{
                sum+=100;
            }
        }
        if(s[i] == 'x'){
            if(s[i-1] >= '2' && s[i-1] <= '9'){
                sum += 10*(s[i-1] - '0');
            }else{
                sum+=10;
            }
        }
        if(s[i] == 'i'){
            if(s[i-1] >= '2' && s[i-1] <= '9'){
                sum += 1*(s[i-1] - '0');
            }else{
                sum+=1;
            }
        }
    }

    return sum;
}



int main(){
    
    char mcxi1[10], mcxi2[10],mcxi3[10];
    int n,i,j;

    int x1,x2,x3;

    scanf("%d",&n);

    while(n > 0){
        x1 = 0;x2 = 0;

        scanf("%s %s",mcxi1,mcxi2);
        
        x1 = rev(mcxi1);
        x2 = rev(mcxi2);
        /*
        printf("%d\n",x1);

        printf("%d\n",x2);
        */
        x3 = x1+x2;

        int k=1000;
        while(k>0){
            int d=x3/k;
            if(d>=1){
                if(d>=2)printf("%d",d);
                if(k==1000)printf("m");
                if(k==100)printf("c");
                if(k==10)printf("x");
                if(k==1)printf("i");
            }
            x3%=k;
            k/=10;
        }
        printf("\n");
    

        n--;    
    }


    return 0;

}


Measured memory_bytes: 2048
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0; i<n; i++)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define reprs(i, s, e) for(int i=e-1; i>=s; i--)

int main(){

    string s; cin >> s;

    bool good = true;
    rep(i, s.size()){
        if(i % 2 == 0){
            if(s[i] == 'L'){
                good = false;
                break;
            }
        }
        else{
            if(s[i] == 'R'){
                good = false;
                break;
            }
        }
    }

    cout << (good ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); (i)--)
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
using namespace std;
typedef long long lint;

int n;
vector<int> a;
vector<int> v;

lint solve(int l, int r){
    if(r - l == 1) return 0;
    int m = (l + r) / 2;
    lint cl = solve(l, m);
    lint cr = solve(m, r);
    lint c = 0;
    int s = l;
    int t = m;
    int cur = l;
    while(t < r){
        while(s < m && a[s] < a[t]){
            v[cur] = a[s];
            cur++;
            s++;
        }
        c += m - s;
        v[cur] = a[t];
        cur++;
        t++;
    }
    if(cur < r){
        For(i, s, m) v[cur] = a[i], cur++;
    }
    For(i, l, r) a[i] = v[i];
    return cl + cr + c;
}

int main(){
    cin >> n;
    a.resize(n);
    rep(i, n) cin >> a[i];
    v.resize(n);
    cout << solve(0, n) << endl;
    //rep(i, n) cout << a[i] << " ";
}


Measured memory_bytes: 4340
n = int(input())


def count_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)
  length = len(divisors)
  return length


l = []
for i in range(1, n + 1):
  if i % 2 == 0:
    continue
  else:
    if count_divisors(i) == 8:
      l.append(i)

      
print(len(l))


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

int main()
{
    int N, X;
    cin >> N >> X;
    int res = 1;
    int Li;
    int D = 0;
    for(int i=0;i<N;i++){
        cin >> Li;
        D += Li;
        if(D<=X) res++;
    }
    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

map<int, int> mx, my;
vector<int> vx, vy;
int N, M, x[5010], y[5010];
int board[5010][5010];

signed main() {
    cin >> N >> M;
    rep(i,0,N) {
        cin >> x[i] >> y[i];
        if(!mx.count(x[i])) vx.push_back(x[i]);
        if(!my.count(y[i])) vy.push_back(y[i]);
        mx[ x[i] ];
        my[ y[i] ];
    }
    sort(vx.begin(), vx.end());
    sort(vy.begin(), vy.end());
    vx.push_back(INF); vy.push_back(INF);

    // compression
    int k = 1;
    for(auto &e : mx) {
        e.second = k++;
        // printf("mx: %lld -> %lld\n", e.first, e.second);
    }
    k = 1;
    for(auto &e : my) {
        e.second = k++;
        // printf("my: %lld -> %lld\n", e.first, e.second);
    }

    // accumulate
    rep(i,0,N) {
        // printf("treasure exist: (%lld, %lld)\n", mx[x[i]], my[y[i]]);
        board[ mx[x[i]] ][ my[y[i]] ]++;
    }
    rep(i,0,N+1) rep(j,0,N+1) board[i+1][j+1] += board[i+1][j];
    rep(j,0,N+1) rep(i,0,N+1) board[i+1][j+1] += board[i][j+1];

    // solve
    rep(i,0,M) {
        int xl, yl, xr, yr;
        cin >> xl >> yl >> xr >> yr;

        // 1-indexed
        xl = lower_bound(vx.begin(), vx.end(), xl) - vx.begin();
        yl = lower_bound(vy.begin(), vy.end(), yl) - vy.begin();
        xr = upper_bound(vx.begin(), vx.end(), xr) - vx.begin();
        yr = upper_bound(vy.begin(), vy.end(), yr) - vy.begin();

        // printf("xl = %lld, yl = %lld, xr = %lld, yr = %lld\n", xl, yl, xr, yr);

        int ans = board[xr][yr] - board[xr][yl] - board[xl][yr] + board[xl][yl];
        cout << ans << endl;
    }
    return 0;
}

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

int pow(int a,int b){
	if(b==0)return 1;
	if(b%2)return a*pow(a,b-1);
	else return pow(a*a,b/2);
}

int main(){
	int x;
	cin>>x;
	bool beki[1001];
	rep(i,1001)beki[i]=false;
	loop(i,1,40){
		loop(j,2,11){
			if(pow(i,j)>1000)break;
			beki[pow(i,j)]=true;
		}
	}
	int i;
	for(i=x;!beki[i];i--);
	cout<<i<<endl;
	return 0;
}

Measured memory_bytes: 256
#a,b=map(int,input().split())
import numpy as np
 
s=input()
n=len(s)
wayA=np.array([0,0,0,0],dtype=np.int64)
wayB=np.array([0,0,0,0],dtype=np.int64)
wayC=np.array([0,0,0,0],dtype=np.int64)
hatena=0
MOD=1000000007
for c in s:
	if c=="A":
		wayA[0]=wayA[0]+1
	if c=="B":
		wayB+=wayA;
	if c=='C':
		wayC=wayC+wayB
	if c=='?':
		wayC[1]=wayC[1]+wayB[0]
		wayC[2]=wayC[2]+wayB[1]
		wayC[3]=wayC[3]+wayB[2]
		wayB[1]=wayB[1]+wayA[0]
		wayB[2]=wayB[2]+wayA[1]
		wayA[1]=wayA[1]+1
		hatena=hatena+1
	for z in range(0,4):
		wayA[z]=wayA[z]%MOD
		wayB[z]=wayB[z]%MOD
		wayC[z]=wayC[z]%MOD
ans=0
for i in range(0,4):
	p3=1
	if wayC[i]<=0:
		continue
	for k in range(0,hatena-i):
		p3=p3*3
		p3=p3%MOD
	ans=ans+p3*wayC[i]
	ans=ans%MOD
print(ans)

Measured memory_bytes: 14664
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

map<ll,int> prime_factorization(ll n){
	map<ll,int> ret;
	
	for(ll div=2;div<=1+sqrt(n);div++){
		while(n%div==0){
			ret[div]++;
			n/=div;
		}
	}
	if(n!=1)ret[n]++;
	return ret;
}


ll solve(int n){
	map<ll,int> mp = prime_factorization(n);
	vector<int> v;
	for(auto &elm:mp){
		v.pb(elm.first);
	}
	int ans = v[v.size()-1];
	rep(i,v.size()-1)ans-=v[i];
	return ans;
}

int main(){
	assert(solve(20)==3);
	int a,b;
	while(cin>>a>>b&&(a||b)){
		ll ra = solve(a);
		ll rb = solve(b);
		if(ra>rb)cout<<'a'<<endl;
		else cout<<'b'<<endl;
	}
}

Measured memory_bytes: 2972
def BMI(height, weight):
    return weight / (height / 100) ** 2


STANDARD_VALUE = 22

while True:

    input_count = int(input())

    if input_count == 0:
        break

    input_data = [map(int, input().split(" ")) for _ in range(input_count)]
    data = [(number, BMI(height, weight)) for number, height, weight in input_data]
    data = [(number, abs(bmi - STANDARD_VALUE)) for number, bmi in data]
    data.sort(key=lambda item: (item[1], item[0]))
    print(data[0][0])



Measured memory_bytes: 6252
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
 int  i,j,n;
char c[50];

 cin >> n;
 for (auto i = 0; i < n; i++) {
	 cin >> c[i];
 }
 i = 0;
 j = 0;
 for (i = 0; i < n; i++){
	 if (c[i] == 'A') {
		 if(c[i+1] =='B'){
			 if (c[i+2] == 'C') {
				 j++;
			}
		 }
	 }
	 

 }
 cout << j;
}

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

typedef long long ll;
typedef long double ld;


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

	int n;
	cin>>n;
	int cnt0=0;
	for(int i=1;i<n+1;i+=2)
	{
	   	 int cnt=0;
		 for(int j=1;j<=i;j++)
		 {
	         if(i%j==0) cnt++;
		 }
		 if(cnt==8) cnt0++;
		 
	}
	cout<<cnt0;
				
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
int n,s;
int main(){
	cin>>n;
	int c=n;
	while(c){
		s+=c%10;
		c/=10;
	}
	if(n%s==0) puts("Yes");
	else puts("No");
	return 0; 
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        String t = scanner.next();
        String res = lcs(s, t);
        System.out.println(res);
    }

    private static final int UPPER_LEFT = 1;
    private static final int UPPER = 2;
    private static final int LEFT = 3;

    private static String lcs(String s, String t) {
        // subproblem:
        // f(k, l) = LCS of s[0..k) and t[0..l)
        // f(s.length, t.length)

        // f(0, *) = ""
        // f(*, 0) = ""
        // f(k, l) = max:
        //         f(k-1, l)
        //         f(k, l-1)
        //         f(k-1, l-1) + s[k-1], if s[k-1] == t[l-1]

        int N1 = s.length();
        int N2 = t.length();
        int[][] dp = new int[N1+1][N2+1];
        int[][] last = new int[N1+1][N2+1];
        for (int i = 0; i <= N1; i++) {
            for (int j = 0; j <= N2; j++) {
                if (i == 0 || j == 0) {
                    dp[i][j] = 0;
                    last[i][j] = 0;
                } else {
                    if (s.charAt(i-1) == t.charAt(j-1)) {
                        dp[i][j] = dp[i-1][j-1] + 1;
                        last[i][j] = UPPER_LEFT;
                    } else if (dp[i-1][j] > dp[i][j-1]) {
                        dp[i][j] = dp[i-1][j];
                        last[i][j] = UPPER;
                    } else {
                        dp[i][j] = dp[i][j-1];
                        last[i][j] = LEFT;
                    }
                }
            }
        }

        int i = N1;
        int j = N2;
        StringBuilder sb = new StringBuilder();
        while (i > 0 && j > 0) {
            if (last[i][j] == UPPER_LEFT) {
                sb.append(s.charAt(i-1));
                i--;
                j--;
            } else if (last[i][j] == UPPER) {
                i--;
            } else if (last[i][j] == LEFT) {
                j--;
            } else {
                break;
            }
        }
        return sb.reverse().toString();
    }
}


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

int main() {
	int n,m,q; cin>>n>>m>>q;
	vector<vector<int>> trains(n+2,vector<int>(n+2));
	while (m--) {
		int l,r; cin>>l>>r;
		trains[l][r]++;
	}

	for (int i=1; i<=n; i++) {
		for (int j=1; j<=n; j++) {
			trains[i][j] = trains[i][j]
						 + trains[i-1][j]
						 + trains[i][j-1]
						 - trains[i-1][j-1];
		}
	}

	while (q--) {
		int pi, qi; cin>>pi>>qi;
		//between [pi][pi] and [qi][qi]
		int ans = trains[qi][qi]
				- trains[pi-1][qi]
				- trains[qi][pi-1]
				+ trains[pi-1][pi-1];
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 1920
X,N = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]

if N != 0:
    if X in p:
        sorted_p = sorted(p)

        x = sorted_p.index(X)
            
        def checknum(d,loweridx,upperidx):
            upper = sorted_p[upperidx]
            lower = sorted_p[loweridx]
            if X-d == lower:
                if X+d == upper:
                    if loweridx == 0:
                        print(X-d-1)
                    elif upperidx == N-1 and sorted_p[loweridx-1] == X-d-1:
                        print(X+d+1)
                    else:
                        checknum(d+1,loweridx-1,upperidx+1)
                else:
                    print(X+d)        
            else:
                return print(X-d)

        if x == 0:
            print(X-1)
        elif x == N-1:
            if sorted_p[x-1] != X-1:
                print(X-1)
            else:
                print(X+1)
        else:
            checknum(1,x-1,x+1)
    else:
        print(X)
else:
    print(X)

Measured memory_bytes: 9192
#include <stdio.h>

int gcd(int a, int b)
{
	int r = a % b;
	while(r > 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

int main()
{
	int n, k;
	scanf("%d %d", &n, &k);

	int i;
	int a[100005];
	for(i=0; i<n; i++)
		scanf("%d", &a[i]);

	int max = 0;
	for(i=0; i<n; i++)
		if(max < a[i])
			max = a[i];

	if(k > max) {
		printf("IMPOSSIBLE\n");
		return 0;
	}

	int g = a[0];
	for(i=0; i<n; i++) {
		g = gcd(g, a[i]);
	}

	if(k%g == 0)
		printf("POSSIBLE\n");
	else
		printf("IMPOSSIBLE\n");

	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
//typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){int i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,M;
  cin>>N>>M;
  const int sz=1<<N;
  vector<vector<int>> edge(N,vector<int>(N,0));
  vector<vector<bool>> edge2(N,vector<bool>(N,false));
  ll uku=0;
  for(int i=0;i<M;i++){
    int a,b,c;
    cin>>a>>b>>c;
    uku+=c;
    a--; b--;
    edge[a][b]=c;
    edge[b][a]=c;
    edge2[a][b]=true;
    edge2[b][a]=true;
  }
  vector<ll> sum(sz,0);
  for(int i=0;i<sz;i++){
    for(int j=0;j<N;j++){
      for(int k=j+1;k<N;k++){
        if((i>>j&1) && (i>>k&1)){sum[i]+=edge[j][k];}
      }
    }
  }
  const ll INF=1e15;
  const int msk=sz-1;
  vector<vector<ll>> dp(N,vector<ll>(sz,-INF));
  for(int i=1;i<sz;i+=2){
    dp[0][i]=sum[i];
  }
  for(int i=0;i<sz;i++){
    int all=msk^i;
    for(int u=0;u<N;u++){
      if((i>>u&1)==0){continue;}
      for(int k=all;k>0;k=(k-1)&all){
        for(int v=0;v<N;v++){
          if((k>>v&1) && edge2[u][v]){
            dp[v][i|k]=max(dp[v][i|k],dp[u][i]+sum[k]+edge[u][v]);
          }
        }
      }
    }
  }
  //for(auto &I:dp){for(auto &J:I){cout<<" "<<(J<0?-1:J);}cout<<endl;}
  cout<<uku-dp.back().back()<<endl;

  return 0;
}


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

struct P
{
    int x,y;
    bool operator<(const P &a)const{
        if(y!=a.y) return y>a.y;
        return x>a.x;
    }
};

vector<P> v;
//bitset<4001000> b;
int i,n,d,m,k,a,b,c;
int e;
int o[1];
int l[1];
int j[1];

int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
int px[10]={-1,1,1,-1,1,1,-1,-1},py[10]={1,1,-1,-1,1,-1,1,-1};
long long mod=1000000007,mod2=1000000009,mod3=2017;
long long x,z,y;
double pi=3.14159265;
P u[1];
stack<int> s;
//set<int> se[33],s1;

//priority_queue<P> q;
queue<int> q;
string r;

char r1[1],r2[1];
//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p;
//v.resize(unique(v.begin(),v.end())-v.begin());

bool as(P a,P b)
{
    if(a.x!=b.x)
    //return a.y>b.y;
    return a.x<b.x;
    return a.y<b.y;
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//rng();



int main()
{
    scanf("%d",&a);
    for(int t=1;t<=a;t++)
    {
        cin>>r;
        for(int h=0;h+1<r.size();h++)
            if(r[h]=='A'&&r[h+1]=='B') k++;
        if(r[0]=='B'&&r[r.size()-1]=='A') b++;
        else if(r[0]=='B') c++;
        else if(r[r.size()-1]=='A') d++;
    }
    if(c==0||d==0)
    {
        if(b==0)
        {
            printf("%d",k);
            return 0;
        }
    }
    if(c==0) b--,c++;
        if(d==0) b--,d++;
    //if(c&&d)
    {
        k+=min(c,d)+b;
    }
    printf("%d",k);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int A;
int B;
int C;
int D;
int main(){
  int res;
  rd(A);
  rd(B);
  rd(C);
  rd(D);
  res =max_L(0, min_L(B, D)-max_L(A, C));
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// int A, B, C, D;
// {
//   int res;
//   rd(A, B, C, D);
//   res = max(0, min(B,D) - max(A,C));
//   wt(res);
// }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

#define FOR(i,a) for(auto i:a)
#define pub push_back
#define pob pop_buck
#define all(in) in.begin(),in.end()

using ll = long long; // typedef long long ll; と同意
using ull = unsigned long long;
using namespace std;

int main(){
    int n, k; cin >> n >> k;
    int data[n]; rep(i, n) cin >> data[i];
    rep(i, k){
        vector<int> data2(n+1, 0);
        rep(j, n){
            int left = max(0, j-data[j]);
            int right = min(n-1, j+data[j]);
            data2[left]++; data2[right+1]--;
        }
        data[0] = data2[0];
        rep(j, n-1) data[j+1] = data[j] + data2[j+1];

        bool count = true;
        rep(j, n) if(data[j] != n) count = false;
        if(count) break; 
    }
    rep(i, n) cout << data[i] << " ";
}



Measured memory_bytes: 5160
#include <bits/stdc++.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll INF=1e15+4;
const int Nmax=2e5+1;
const int Nd=61;
ll dfs[3003][3003][4];
ll  v[3003][3003];


int main(){
  int n; cin>>n;
  vector<ll> a(n),b(n);
  ll sumA=0,sumB=0;
  ll now1=0,now2=0;

  rep(i,n) {
    cin>>a[i];
    sumA+=a[i];
  }
  rep(i,n) {
    cin>>b[i];
    
    sumB+=b[i];
    if(a[i]<b[i]){
      now1+=((b[i]-a[i]+1)/2);
    }else{
      now2+=a[i]-b[i];
    }

  }

  ll num=sumB-sumA;
  if(now1>num || now2>num){
    cout<<"No"<<endl;
  }else{
    cout<<"Yes"<<endl;
  }
  return 0;


}


Measured memory_bytes: 3708
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "x", long, "y", bool, "haspair");
alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less);

void main()
{
    long h, w;
    scan(h, w);
    auto s = new string[](h);
    foreach (ref e; s)
        e = sread();

    auto cntrow = new long[][](h, w);
    auto cntclm = new long[][](h, w);
    foreach (i; iota(h))
    {
        long p, q;
        while (p < w)
        {
            while (q < w && s[i][q] == '.')
            {
                q++;
            }
            foreach (j; iota(p, q))
            {
                cntrow[i][j] = (q - p);
            }
            q++;
            p = q;
        }
    }
    // cntrow.each!(x => x.writeln());
    foreach (j; iota(w))
    {
        long p, q;
        while (p < h)
        {
            while (q < h && s[q][j] == '.')
            {
                q++;
            }
            foreach (i; iota(p, q))
            {
                cntclm[i][j] = (q - p);
            }
            q++;
            p = q;
        }
    }
    // cntclm.each!(x => x.writeln());
    long ans;
    foreach (i; iota(h))
    {
        foreach (j; iota(w))
        {
            if (s[i][j] == '.')
            {
                ans = max(ans, cntrow[i][j] + cntclm[i][j]);
            }
        }
    }
    writeln(ans - 1);
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


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

using namespace std;

int n;
int a[300001];
long long ans = 0;

int main( ) {
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++) {
		scanf("%d", &a[i]);
		a[i] -= i;
	}
	sort(a + 1, a + 1 + n);
	for (int i = 1; i <= n; i ++)
		ans += abs(a[i] - a[(n + 1) / 2]);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;

string sor(string Q, string W){
    if(Q.size() < W.size()) return W;
    if(W.size() < Q.size()) return Q;

    if(Q < W) return W;
    else return Q;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    int N, M;
    cin >> N >> M;
    int A[M];
    rep(i,M) cin >> A[i];
    int num[10] =  {10, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    string dp[N+1]{};
    rep(i,N+1){
        rep(j,M){
            int x = A[j];
            char c = x + '0';
            int d = i-num[x];
            if(i - num[x] >= 0){
                if(dp[d] == "" && d != 0) continue;
                string S, T;
                S = dp[d] + c;
                T = c + dp[d];
                dp[i] = sor(dp[i], S);
                dp[i] = sor(dp[i], T);
            }
        }
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 44416
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const int INF = INT_MAX / 2;

int main(){
    int N, M; cin >> N >> M;
    int l = -INF, r = INF;

    for (int i = 0; i < M; i++)
    {
        int L, R; cin >> L >> R;
        l = max(l, L);
        r = min(r, R);
    }
    
    if(r-l>=0) cout << r - l + 1 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

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

    public static void solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] s = new int[n];
        for(int i=0;i<n;i++){
        	s[i] = sc.nextInt();
        }
        int[] dp = new int[10001];
        for(int i=0;i<n;i++){
        	for(int j=10000-s[i];j>=0;j--){
        		if(dp[j]!=0){
        			dp[j+s[i]] = 1; 
        		}
        	}
        	dp[s[i]] = 1;
        }

        for(int i=10000;i>=0;i--){
        	if(dp[i]!=0 && i%10!=0){
        		System.out.println(i);
        		break;
        	}
        	if(i==0){
        		System.out.println(i);
        	}
        }
    }
}

Measured memory_bytes: 23508
#!/usr/bin/env python3
from bisect import bisect_right

s = input()
N = len(s)
si = [[] for _ in range(26)]
for i in range(N):
    si[ord(s[i])-ord('a')].append(i+1)

ans = 0
t = input()
M = len(t)
for j in range(M):
    ti = si[ord(t[j])-ord('a')]
    if len(ti)==0:
        print(-1)
        exit()
    d = bisect_right(ti,ans%N)
    if d == len(ti):
        ans += ti[0]+N-ans%N
    else:
        ans += ti[d]-ans%N
print(ans)

Measured memory_bytes: 13600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll x,ans;
    cin >> x;
    ans = (x/11)*2;
    if(x%11<=6 && x%11>=1){
        cout << ans+1 <<endl;
    }else if(x%11== 0){
        cout << ans << endl;
    }else{
        cout << ans+2 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define PI 3.14159265359
const int INF = 1001001001;
const int MOD = 1000000007;

int counter(ll x)
{
    int count=0;
    while(x>=1)
    {
        x=x/10;
        count++;
    }
    return count;
}

double round(double src, int n)
{
    double dst;
    
    dst = src * pow(10, -n - 1);          /*処理を行う桁を10-1 の位にする*/
    dst = (double)(int)(dst + 0.5);
    
    return    dst * pow(10, n + 1);       /*処理を行った桁を元に戻す*/
}
int main()
{
    /*A
    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
    */
    /*B
    int n;
    cin>>n;
    vector <ll> a(n);
    ll sum=1;
    bool flag = 1;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]==0)
        {
            flag = 0;
        }
    }
    if(!flag)
    {
        cout<<0<<endl;
        return 0;
    }
    for(int i=0;i<n;i++)
    {
        ll temp = 1;;
        temp *= sum*a[i];
        if(temp<sum || temp>1000000000000000000)
        {
            cout<<-1<<endl;
            return 0;
        }
        else
        {
            sum=temp;
        }
    }
    cout<<sum<<endl;
    */

    ll a;
    double b;
    cin>>a>>b;
    ll b_int = b*100+0.5;
    a*=b_int;
    cout<<a/100<<endl;

    
    
    
    /*if(b_int>1)
    {
        b_decimal = double(b-b_int);
    }
    else
    {
        b_decimal = b;
    }
    
    ll sum=0;
    sum+=a*b_int;
    cout<<b_decimal;
    ll ab_int = ll(a*(b_decimal));
    sum+=ab_int;
    cout<<sum<<endl;
    */

    return 0;
}

Measured memory_bytes: 3788
#include<stdio.h>
int main(void)
{
int A,B,C,K;

  scanf("%d%d%d",&A,&B,&C);

  if(A*C<B)
    printf("%d\n",C);

  else if((A<B)||(A*B>C)){
    K=B/A;
    printf("%d\n",K);
  }
  else
    printf("0\n");


  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define out(a) cout<<fixed<<setprecision((a))


int main(){
	ll a;
	cin >> a;
	cout << a*a*3 << endl;
}

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

const int N = 500009;
const int mod = 1000000007;

#define IOS                               \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);
#define int long long int
#define endl "\n"
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()

int x;
vector<int> pri;
vector<bool> isP;

void pre()
{
	isP.assign(N, 1);
	isP[1] = 0;
	for (int i = 2; i < N; i++)
	{
		if (isP[i])
		{
			for (int j = (2 * i); j < N; j += i)
			{
				isP[j] = 0;
			}
			pri.push_back(i);
		}
	}
}

int32_t main()
{
	IOS;
	pre();
	cin >> x;
	auto it = lower_bound(all(pri), x);
	int i = it - pri.begin();
	cout<<pri[i]<<endl;
	return 0;
}

Measured memory_bytes: 1020
# coding: utf-8
while True:
    line = input().split()
    n = int(line[0])
    x = int(line[1])
    if (n == 0 and x == 0):
        break
    ans = 0
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            for k in range(j+1, n+1):
                if i + j + k == x:
                    ans += 1
    
    print(ans)


Measured memory_bytes: 5596
arr = gets.chomp.split(" ")
memory = []
cnt = 0
for i in 0..arr.size()-1
  if arr[i]=="+"
    memory[cnt-2]+=memory[cnt-1]
    cnt-=1
  elsif arr[i]=="-"
    memory[cnt-2]-=memory[cnt-1]
    cnt-=1
  elsif arr[i]=="*"
    memory[cnt-2]*=memory[cnt-1]
    cnt-=1
  else
    memory[cnt]=arr[i].to_i
    cnt+=1
  end
end
puts(memory[0])

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>


template <class T> void chmin(T&a, const T&b) { a = min(a,b); }
template <class T> void chmax(T&a, const T&b) { a = max(a,b); }

const double EPS =1e-9;
const long INF =999999999;
const long MOD =1000000007; //10^9+7
#define PI 3.14159265258979

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


int main(){
	int N,K,l[51],result=0;
	cin>>N>>K;

	REP(i,N) cin>>l[i];
	DSORT(l,N);

	REP(i,K) result+=l[i];

	printf("%d\n",result);
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main (){
  int a, b, c;
  cin >> a >> b >> c ;
  
   
   if (a==b && a==c && b==c){
     
     cout<< " 1 " << endl;
   }
  else if ((a==b || a==c || b==c ) && !(a==b && a==c && b==c)){
    
    cout << " 2 " << endl;
    
  }
  
  else if (!(a==b || a==c || b==c )){
    cout << "3" << endl;
    
  }
}

     
     

Measured memory_bytes: 256