akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)
#define mod 1000000007
#define bitcount __builtin_popcountll
#define ll long long
#define pb push_back
#define pi pair<int,int>
#define pii pair<pi,int>
#define mp make_pair
int arr[500005],n;
int main()
{
	int i,j,k;
	ll sum1=0,sum2=0;
	sd(n);
	for(i=1;i<=3*n;i++)
		sd(arr[i]);
	multiset<int>s1;
	multiset<int, greater<int> >s2;
	multiset<int>s3;
	for(i=1;i<=n;i++){
		s1.insert(arr[i]);
		sum1+=arr[i];
	}
	for(i=n+1;i<=3*n;i++)
	{
		if(s2.size()<n)
		{
			s2.insert(arr[i]);
			sum2+=arr[i];
		}
		else if(*(s2.begin())>arr[i])
		{
			s3.insert(*s2.begin());
			s2.erase(s2.begin());
			s2.insert(arr[i]);
			sum2-=*s3.begin();
			sum2+=arr[i];
		}
		else
			s3.insert(arr[i]);
	}
	ll ans=sum1-sum2;
	for(i=n+1;i<=2*n;i++)
	{
		multiset<int, greater<int> > :: iterator it1;
		multiset<int> :: iterator it2;
		it2=s3.find(arr[i]);
		if(it2!=s3.end())
		{
			s3.erase(it2);
			if(*s1.begin()<arr[i])
			{
				sum1-=*s1.begin();
				s1.erase(s1.begin());
				s1.insert(arr[i]);
				sum1+=arr[i];
			}
		}
		else
		{
			it1=s2.find(arr[i]);
			sum2-=arr[i];
			sum2+=*s3.begin();
			s2.erase(it1);
			s2.insert(*s3.begin());
			s3.erase(s3.begin());
			if(*s1.begin()<arr[i])
			{
				sum1-=*s1.begin();
				s1.erase(s1.begin());
				s1.insert(arr[i]);
				sum1+=arr[i];
			}
		}
		ans=max(ans,sum1-sum2);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 15488
#include<stdio.h>

int main(){
  int i,j,k;
  int N,Q;
  scanf("%d %d",&N,&Q);
  char S[N];
  scanf("%s",S);
  
  int A[N];
  k=0;
  for(i=0;i<N;i++){
    if(S[i] == 'C' && S[i-1] == 'A'){
      k++;
    }
    A[i]=k;
  }
  int a,b;
  for(i=0;i<Q;i++){
    scanf("%d %d",&a,&b);
    printf("%d\n",A[b-1]-A[a-1]);
  }
  return 0;
}



Measured memory_bytes: 1280
from collections import Counter
import math
def P(n, r):
  return math.factorial(n)//math.factorial(n-r)
def C(n, r):
  return P(n, r)//math.factorial(r)
n=int(input())
L=[]
for j in range(2,n+1):
    I=j
    s=0
    R=int(I)
    while s==0:
        for i in range(2,R+1):
            if I%i==0:
                I=I/i
                if I==1:
                    s=1
                L.append(i)
                break
C=Counter(L)
c=[0 for i in range(100)]
for i,j in C.most_common():
  c[j]+=1
 
s=0
s+=sum(c[4:])*(sum(c[4:])-1)*(sum(c[2:])-2)//2
s+=sum(c[14:])*(sum(c[4:])-1)
s+=sum(c[24:])*(sum(c[2:])-1)
s+=sum(c[74:])
print(s)

Measured memory_bytes: 3316
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>
#include<type_traits>

using namespace std;
using ll = long long;

constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;
constexpr ll LONGINF = 1050000000000000000;


int main() {
	int n; cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		int j = i;
		int keta = 0;
		while (j) {
			keta++;
			j /= 10;
		}
		if (keta & 1) {
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main() {
    int H, W;
    cin >> H >> W;

    vector<string> C(H);
    for (int i = 0; i < H; i++) {
        cin >> C[i];
    }

    for (int i = 0; i < H * 2; i++) {
        cout << C[i / 2] << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <vector>

using namespace std;

int main(){
  long long int n,i,j,a,b,k;
  cin >> a >> b >> k;
  for(i=a;i<a+k;i++){
    if(i>b)break;
    cout << i << endl;
  }
  for(j=0;j<k;j++){
    if(b-k+j+1<i)continue;
    cout << b-k+j+1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;

string ans = "";

void solve(){
	if(N==0){ans = "0";return;}
	while(N!=0){
		ans = (char)(abs(N)%2 + '0') + ans;
		if(N<0){
			N = -(N-abs(N)%2)/2;
		}
		else if(N>0){
			N = -N/2;
		}
	}
}
 
int main(){
    cin >> N;
 
    solve();
 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll a,b,c,k;cin>>a>>b>>c>>k;
  while(k--)
  {
    if(c<=b || c<=a)
    {c=c*2;
    }
    else if(b<=a)
      b*=2;
    else
      c*=2;
  }
  if(c>b && c>a && b>a)
    cout<<"Yes";
  else
    cout<<"No";
}


Measured memory_bytes: 3556
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    int N;
    cin >> N;
    int a;
    int ans = 0;
    rep (i, N)
    {
        cin >> a;
        ans += a;
    }
    ans -= N;
    cout << ans << "\n";
    return 0;
}



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

main(){
	int x[5];
	for(int i=0;i<5;++i){
		cin>>x[i];
	}
	
	sort(x, x+5);
	
	for(int i=4;i>=0;--i){
		cout << x[i];
		if( i!=0 ){
			cout <<" ";
		}
	}
	cout<<endl;
}


Measured memory_bytes: 3124
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector <int> > vvi;
const int EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 30);
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	if (N < 105)cout << 0 << endl;
	else if (N < 3 * 5 * 9)cout << 1 << endl;
	else if (N < 165)cout << 2 << endl;
	else if (N < 189)cout << 3 << endl;
	else if (N < 195)cout << 4 << endl;
	else cout << 5 << endl;
	PAU;
	return 0;
}


Measured memory_bytes: 504
import java.util.ArrayList;
import java.util.Scanner;
import java.util.List;
import java.lang.*;

public class Main{
 public static void main(String[] args){
   Scanner sc=new Scanner(System.in);
   int n;
   List<Integer> lst=new ArrayList<Integer>();
   while(true){
    n =sc.nextInt();
    if(n==0){
     break;
    }
    int[] a=new int[n];
    int sum = 0;
    for(int i=0;i<n;i++){
       a[i]=sc.nextInt();
       sum += a[i];
    }
    sum /= n;
    int count = 0;
    for(int i=0;i<n;i++){
      if(a[i]<=sum){
         count++;
      } 
    }
    lst.add(count);

   }
   for(int j=0;j<lst.size();j++){
    System.out.println((int)lst.get(j));
   }
 }

}



Measured memory_bytes: 59328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back

int main(){
    int n;
    cin >> n;
    char s[n];
    for(int i=0;i<n;i++) cin >> s[i];

    string ans="Three";

    for(int i=0;i<n;i++){
        if(s[i]=='Y'){
            ans = "Four";
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector<unsigned int> A(N);
    for (auto &a: A) {
        cin >> a;
    }
    unsigned int count = 0;
    bool loop = true;
    while (1) {
        for (auto &a: A) {
            if (a % 2 == 1) {
                loop = false;
            } else {
                a /= 2;
            }
        }
        if (!loop) break;
        count++;
    }
    cout << count;
}

Measured memory_bytes: 256
if __name__ == '__main__':
    N = int(input())
    P = list(map(int,input().split()))
    P.insert(0, 0)
    Dis = [[abs(P[i]-P[(i+j+1)%(N+1)]) for i in range(N+1)] for j in range(2)]
    temp = sum(Dis[0])
    temp2 = [sum(Dis[0][i:i+2]) for i in range(N)]
    for i in range(N): print(temp-temp2[i]+Dis[1][i])

Measured memory_bytes: 20372
#include <cstdio>
using namespace std;
int n, k, r, p;
int main() {
	scanf("%d%d", &n, &k);
	for ( int i = 1, a; i <= n; i ++) 
		scanf("%d", &a), p = a == 1 ? i : p;
	int ans = (p-1)/(k-1) + ((p-1)%(k-1) > 0);
	r = n - (k-1) * ans - 1;
	ans = ans + r/(k-1) + (r%(k-1) > 0);
	printf("%d\n", ans);
}

Measured memory_bytes: 128
H,W=map(int,input().split())
c=[]
for i in range(H):
  ci=input()
  if ci=="."*W:
    continue
  c.append(ci+"#")
l=len(c)
k=[True]*(W+1)
for i in range(l):
  for j in range(W,-1,-1):
    k[j]=k[j] and (c[i][j]==".")

for i in range(l):
  for j in range(W,-1,-1):
    if k[j]:
      c[i]=c[i][0:j]+c[i][j+1:]
for i in range(l):
  print(c[i][:-1])

Measured memory_bytes: 39408
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n string
	fmt.Scan(&n)

	num, _ := strconv.Atoi(n)

	var sum int
	for _, v := range n {
		sum += int(v - '0')
	}
	if num%sum == 0 {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}


Measured memory_bytes: 512
public class Main {

	public static void main(String[] args) {
		java.util.Scanner sc = new java.util.Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		if (a < b) {
			System.out.println("a < b");
		}else if (a > b) {
			System.out.println("a > b");
		}else {
			System.out.println("a == b");
		}
	}
}

Measured memory_bytes: 26028
000010 IDENTIFICATION  DIVISION.
000020 PROGRAM-ID.     MAIN.
000030 ENVIRONMENT     DIVISION.
000040 DATA            DIVISION.
000050 WORKING-STORAGE  SECTION.
000060 01 STR        PIC 999.
000070 01 ANS		  PIC 99.
000080 *     
000090 PROCEDURE DIVISION.
000100 *
000110 ACCEPT STR.
000120 DISPLAY "ABC"STR.
000130 STOP RUN.


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    int n, k;
    cin >> n >> k;
    map<int, int> m;
    for (int i = 1; i <= n; i++) {
        m[i] = 0;
    }
    for (int i = 0; i < k; i++) {
        int d;
        cin >> d;
        for (int j = 0; j < d; j++) {
            int a;
            cin >> a;
            m[a]++;
        }
    }

    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (m.at(i) == 0)
            cnt++;
    }

    cout << cnt << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
 
using namespace std;
 
#define ll long long 
#define ld long double
#define f first
#define s second
#define pii pair<int,int>
#define pb push_back
#define mk make_pair
#define vi vector<int>
int main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll x,k,d;
    cin>>x>>k>>d;
    x = abs(x);
    ll y = abs(x)/d;
    // if(x>=0)
    {
        if(abs(k-y)&1)
        {

            cout<<min(abs(x-min(y-1,k)*d),abs(x-min(y+1,k)*d))<<endl;

        }
        else
        cout<<x-min(y,k)*d<<endl;
    }
    // else
    // {
    //     if(abs(k-y)&1)
    //     {

    //         cout<<min(min(abs(x+min(y-1,k)*d),abs(x+min(y+1,k)*d)),abs(x))<<endl;

    //     }
    //     else
    //     cout<<x+min(y,k)*d<<endl;
    // }
    return 0;
}


Measured memory_bytes: 3648
w, h, n = map(int,input().split())
Op = []
for i in range(n):
    Op.append(list(map(int,input().split())))

Op1 = [0]
Op2 = [w]
Op3 = [0]
Op4 = [h]
for j in range(n):
    if Op[j][2] == 1:
        Op1.append(Op[j][0])
    elif Op[j][2] == 2:
        Op2.append(Op[j][0])
    elif Op[j][2] == 3:
        Op3.append(Op[j][1])
    elif Op[j][2] == 4:
        Op4.append(Op[j][1])
'''
print(Op1)
print(Op2)
print(Op3)
print(Op4)
'''
if min(Op2)-max(Op1) < 0:
    print(0)
elif min(Op4)-max(Op3) < 0:
    print(0)
else:
    print((min(Op2)-max(Op1))*(min(Op4)-max(Op3)))

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>

#define roop(i,p) for(int i=1;i<=p;i++)
#define ll long long

using namespace std;

int main(){

     ll int N;
	cin >> N;
     map<string,int> A;
     string B;
     roop(i,N){
	     cin >> B;
		     A[B]+=1;
	     

     }

	 int x;
	x = 0;
	for(auto itr = A.begin(); itr != A.end();itr++){
		if (itr->second > x){
			x = itr->second;
		}
	}

	for(auto itr = A.begin(); itr != A.end();itr++){
		if (itr->second == x){
		cout << itr-> first << endl;
		}
	}
	return 0;



}



Measured memory_bytes: 25216
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
AA = []
for i in range(N):
    AA.append(list(map(int, input().split())))

ans = 0
for A in AA:
    allall = 0
    for i in range(M):
        allall += A[i] * B[i]
    if allall + C > 0:
        ans += 1
print(ans)


Measured memory_bytes: 3060
import java.util.Scanner;
 
public class Main {
 
	public static final MyScanner in = new MyScanner();

	public static void main(String[] args) {


		long X = in.nextLong();


		long A = 100;
		long i=0;
		while(A<X){
			i++;
			A *= 1.01;
		}

		System.out.println(i);
	}



	public static class MyScanner {
		Scanner sc = new Scanner(System.in);
		String next() { return sc.next();}
		int nextInt() { return Integer.valueOf(sc.next());}
		long nextLong() { return Long.valueOf(sc.next()); }
	}
}

Measured memory_bytes: 35748
#include <iostream>
#include <stack>
#include <unordered_map>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <functional>
#include <iterator>
#include <tuple>

using namespace std;

int main() {
  int n, k, q;
  cin >> n >> k >> q;
  
  vector<int> ns(n);
  for (int i = 0; i < q; i++) {
    int a;
    cin >> a;
    ns[a-1]++;
  }  
  
  for (int i = 0; i < ns.size(); i++) {
    string result = (k - q + ns[i] > 0) ? "Yes" : "No";
    cout << result << endl;
  }
}

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

int main()
{
	int n; cin >> n;
	vector<int> P(n), Q(n), A(n);
	for (int i=0; i<n; i++) cin >> P[i];
	for (int i=0; i<n; i++) cin >> Q[i];
	for (int i=0; i<n; i++) A[i] = i+1;

	int sP=0, sQ=0;
	do
	{
		if (!lexicographical_compare(A.begin(), A.end(), P.begin(), P.end())) sP++;
		if (!lexicographical_compare(A.begin(), A.end(), Q.begin(), Q.end())) sQ++;
	} while(next_permutation(A.begin(), A.end()));

	cout<<abs(sP-sQ)<<"\n";

	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>

using namespace std;

int main(void){
    string s;
    cin >> s;
    string _s = s;
    string t[3] = {"A", "B", "C"};
    string v = "";
    bool f = true;
    while (f) {
        f = false;
        int type = -1;
        int size = s.size();
        for (int i = 0; i < size-2 && s != "ABC"; i++) {
            if (type == -1 && s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') {
                f = true;
                if (i == 0) type = 0;
                else if (s[i-1] == 'C') type = 0;
                else if (s[i-1] == 'A') type = 1;
                else if (s[i-1] == 'B') type = 2;
                v += t[type];
                if (i+3 < s.size()) s = s.substr(0,i) + t[type] +  s.substr(i+3);
                else s = s.substr(0,i) + t[type];
                size = s.size();
            }
            else if (s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') {
                if (i+3 < s.size()) s = s.substr(0,i) + t[type] +  s.substr(i+3);
                else s = s.substr(0,i) + t[type];
                size = s.size();
            }
        }
    }
    if (s != "ABC") {
        cout << "No" << endl;
        return 0;
    }
    
    string u = "ABC";
    for (int i = v.size()-1; i >= 0; i--) {
        int size = u.size();
        for (int j = 0; j < size; j++) {
            if (u[j] == v[i]) {
                if (j < size-1) u = u.substr(0,j) + "ABC" + u.substr(j+1);
                else u = u.substr(0,j) + "ABC";
                j += 2;
                size += 2;
            }
        }
    }
    cout << (_s == u? "Yes": "No") << endl;
}

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

using namespace std;
using ll = long long;

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

    if (S[S.length() - 1] == 's') {
        S += "es";
    } else {
        S += "s";
    }

    cout << S << endl;

    return 0;
}


Measured memory_bytes: 3628
program sum_of_product_of_pairs
  implicit none
  integer(16), parameter :: m = 1000000007
  integer(16), allocatable :: a(:)
  integer :: n
  read(*,*) n
  allocate(a(n))
  read(*,*) a
  write(*,'(i0)') mod((sum(a) ** 2 - sum(a ** 2)) / 2, m)
end program sum_of_product_of_pairs

Measured memory_bytes: 6100
#include<stdio.h>
#include<math.h>
int main(void)
{
    int n, k;
    scanf("%d%d", &n, &k);
    int i = 0, t = 0;
    while (i < n)
    {
        i += (k-1) * pow(k, t);
        t++;
    }
    printf("%d", t);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
using Graph = vector<vector<ll> >;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

//input
ll h,w;
vector<string>s;

ll l[2020][2020];
ll r[2020][2020];
ll u[2020][2020];
ll d[2020][2020];


int main(){
    cin >> h >> w;
    s.resize(h+1);
    rep(i,h){
        cin>>s[i];
    }
    for(int i=1;i<=h;i++){//left
        for(int j=1;j<=w;j++){
            if(s[i-1][j-1]=='#')l[i][j]=0;
            else {
                l[i][j]=l[i][j-1]+1;
            }
        }
    }
    for(int i=1;i<=h;i++){//right
        for(int j=w;j>=1;j--){
            if(s[i-1][j-1]=='#')r[i][j]=0;
            else r[i][j]=r[i][j+1]+1;
        }
    }
    for(int i=1;i<=h;i++){//up
        for(int j=1;j<=w;j++){
            if(s[i-1][j-1]=='#')u[i][j]=0;
            else {
                u[i][j]=u[i-1][j]+1;
            }
        }
    }
    for(int i=h;i>=1;i--){//down
        for(int j=w;j>=1;j--){
            if(s[i-1][j-1]=='#')d[i][j]=0;
            else d[i][j]=d[i+1][j]+1;
        }
    }
    ll ans = 0;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(s[i-1][j-1]=='#')continue;
            chmax(ans,l[i][j]+r[i][j]+u[i][j]+d[i][j]-3);
        }
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 137504
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
  int h, w; cin >> h >> w;
  vector<vector<int>> a(h, vector<int>(w));
  rep(i, h) rep(j, w) cin >> a[i][j];

  vector<pair<pair<int, int>, pair<int, int>>> p;
  int num = 0;
  rep(i, h) rep(j, w - 1) {
    if (a[i][j] % 2 == 1) {
      num ++;
      p.push_back(make_pair(make_pair(i + 1, j + 1), make_pair(i + 1, j + 2)));
      //cout << i + 1 << " " << j + 1 << " " << i + 1 << " " << j + 2 << endl;
      a[i][j] --, a[i][j + 1] ++;
    }
  }
  rep(i, h - 1) {
    if (a[i][w - 1] % 2 == 1) {
      num ++;
      p.push_back(make_pair(make_pair(i + 1, w), make_pair(i + 2, w)));
      //cout << i + 1 << " " << w - 1 << " " << i + 2 << " " << w - 1 << endl;
      a[i][w - 1] --, a[i + 1][w - 1] ++;
    }
  }

  cout << num << endl;
  rep(i, num) {
    cout << p[i].first.first << " " << p[i].first.second << " " << p[i].second.first << " " << p[i].second.second << endl;
  }
}

Measured memory_bytes: 5232
from sys import stdin
X, N = [int(x) for x in stdin.readline().rstrip().split()]
P = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
if N == 0 or X not in P:
    ans = X
else:
    i = True
    k = True
    a = X
    b = X
    while i:
        a += 1
        i = a in P
    while k:
        b -= 1
        k = b in P
    if abs(X - a) == abs(X - b):
        if a > b:
            ans = b
        else:
            ans = a
    else:
        if  abs(X - a) > abs(X - b):
            ans = b
        else:
            ans = a
print(ans)

Measured memory_bytes: 9228
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll read()
{
    char ch=getchar();
    ll x=0,f=1;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
char a[15];
int n;
void dfs(int deep,int x)
{
	if(deep==n)
	{
		puts(a);
		return ;
	}
	for(int i=0;i<=x;i++)
	{
		a[deep]='a'+i;
		dfs(deep+1,x);
	}
	a[deep]='a'+x+1;
	dfs(deep+1,x+1);
}
int main()
{
    cin>>n;
    a[0]='a';
    dfs(1,0);
    return 0;

}

Measured memory_bytes: 1536
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <cstdio>
#include <time.h>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <math.h>
//#include <bits/stdc++.h>
#define ll long long
#define int64 long long
#define mem(x,y) memset(x,y,sizeof(x))
#define ull unsigned long long
#define pb push_back
#define INF 0x3f3f3f3f
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1
#define pi 3.141592653589793238462

using namespace std;

const int maxn = 2e5 + 5;
const int maxm = 3e5 + 5;
const int mod = 1e9 + 7;
const int seed = 10007;
const double eps = 1e-5;
int n;
int c,cnt,ans;

int main() {
    scanf("%d",&n);
    c = 0;
    cnt = 0;
    ans = 1;
    for(int i=1;i<=n;i++){
        int temp=i;
        cnt = 0;
        while(temp%2==0){
            cnt++;
            temp/=2;
        }
        if(c<cnt) c=cnt,ans=i;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n, r] <- getIntList
    print $ solve n r

solve n r | n >= 10 = r
          | otherwise = r + 100 * (10 - n)

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

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)

        {
            long n = Input();
            long[] ai = new long[200000];
            long  max1= 0;
            long  max2= 0;
            for(long i = 0; i < n; i++)
            {
                ai[i] = Input();
                if (ai[i] > max1)
                {
                    max2 = max1;
                    max1 = ai[i];
                }else if (ai[i] > max2)
                {
                    max2 = ai[i];
                }
               /* Console.WriteLine("max1"+max1);
                Console.WriteLine("max2"+max2);*/

            }

            for(long i = 0; i < n; i++)
            {
                if (ai[i] != max1) Console.WriteLine(max1);
                else Console.WriteLine(max2);
            }
            

           
            
            //Console.WriteLine(ans);
                
                





        }

       
        static public long Input()
        {
            return long.Parse(Console.ReadLine());
        }

        static public string[] Input2()
        {
            return Console.ReadLine().Split();
        }

        static public long[] Input3()
        {
            string[] data = Console.ReadLine().Split();
            long[] res = new long[data.LongLength];
            for(long i = 0; i < data.LongLength; i++)
            {
                res[i] = long.Parse(data[i]);
            }
            return res;
        }
        public static long Choose(long n, long a)
        {
            long x = 1;
            long y = 1;
            for (long i = 0; i < a; i++)
            {
                x *= n - i;
                y *= i + 1;
            }
            return x / y;
        }

        public static long Gcd(long a, long b)
        {
            long x = Math.Max(a, b);
            long y = Math.Min(a, b);
            if (x % y == 0) return y;
            else return Gcd(y, x % y);
        }

        
       
    }
}


Measured memory_bytes: 17876
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#define r(i,n) for(int i=0; i<n; i++)
typedef long long ll;
using namespace std;

int main(void){
  int n;
  int a[110]={};
  cin >> n;
  r(i,n){
    cin >> a[i];
  }
  sort(a, a+n);
  reverse(a, a+n);

  int ansa=0;
  int ansb=0;

  for(int i=0; i<n; i+=2){
    ansa+=a[i];
    ansb+=a[i+1];
  }
  cout << ansa-ansb << endl;
  return 0;
}


Measured memory_bytes: 256
//#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cstring>
#include <cassert>

using namespace std;

#ifdef LOCAL_DEBUG
#include <local_debug.h>
#define DEBUG(...) DBG2::print(#__VA_ARGS__, __LINE__, __VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;



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

   int N;
   cin >> N;
   VI A(N);
   REP(i, N)
      cin >> A[i];

   llong res = 0;
   FOR(i, 1, N-1) {
      if (A[i-1] > A[i]) {
         res += A[i-1] - A[i];
         A[i] = A[i-1];
      }
   }

   cout << res << '\n';

   return 0;
}


Measured memory_bytes: 3972
//Author : Sukarna Paul

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pi acos(-1)
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;



ll cnt[2019];
int main(){
    IOS
    //freopen("output.txt","w",stdout);
    string s;
    cin>>s;
    int len = s.length();
    int dp[len+1];
    int p=1;
    memset(dp,0,sizeof dp);

    ll ans = 0;
    cnt[0]=1;
    for(int i=len-1;i>=0;i--){
        dp[i]=(dp[i+1]+p*(s[i]-'0'))%2019;
        p*=10;
        p%=2019;

        ans+=cnt[dp[i]]++;
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 4564
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let T: Vec<i64> = (0..N)
        .map(|_| {
                let mut line: String = String::new();
                std::io::stdin().read_line(&mut line).unwrap();
                line.trim().parse().unwrap()
        })
        .collect();

    fn gcd(a: i64, b: i64) -> i64 {
        if b == 0 {
            a
        } else {
            gcd(b, a % b)
        }
    }

    let ans = T.iter().fold(1, |res, &t| res / gcd(res, t) * t);

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
const int N=2e5+9,mod=998244353;
int tr[N];
int pw(int a,int t){
	int x=1;
	while(t){
		if(t&1)x=x*a%mod;
		a=a*a%mod,t>>=1;
	}
	return x;
}
void udt(int i,int d){
	i++;
	while(i<N)tr[i]+=d,i+=i&-i;
}
int get(int i){
	i++;
	int sum=0;
	while(i)sum+=tr[i],i-=i&-i;
	return sum;
}
int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int n;
    cin >> n;
    pair <int,int> a[n];
    int x[n],y[n],cx[n];
    for(int i=0;i<n;i++){
    	cin >> a[i].f >> a[i].s;
    	x[i]=a[i].f,y[i]=a[i].s;
    }
    sort(x,x+n),sort(y,y+n),sort(a,a+n);
    map <int,int> fx,fy;
    for(int i=0;i<n;i++)
    	fx[x[i]]=i,fy[y[i]]=i;
    for(int i=0;i<n;i++){
    	cx[i]=get(fy[a[i].s]);
    	udt(fy[a[i].s],1);
    }
    int ans=0;
    for(int i=0;i<n;i++){
    	int r=fx[a[i].f],c=fy[a[i].s];
    	int p1=cx[i],p2=r-cx[i],p3=n-1-c-p2,p4=n-1-p1-p2-p3;
    	ans=(ans+pw(2,n))%mod;
    	ans=(ans-pw(2,n-1-r)+mod)%mod;
    	ans=(ans-pw(2,r)+mod)%mod;
    	ans=(ans-pw(2,n-1-c)+mod)%mod;
    	ans=(ans-pw(2,c)+mod)%mod;
    	ans=(ans+pw(2,p1))%mod;
    	ans=(ans+pw(2,p2))%mod;
    	ans=(ans+pw(2,p3))%mod;
    	ans=(ans+pw(2,p4))%mod;
    }
    cout << (ans-n+mod)%mod;
}

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

int main(void){
    string s;
    int y, m, d;
    while (1) {
        cin >> s >> y >> m >> d;
        if (s == "#") break;
        if (y < 31) cout << s << " " << y << " " << m << " " << d << endl;
        else if (y == 31) {
            if (m < 5) cout << s << " " << y << " " << m << " " << d << endl;
            else cout << "? " << 1 << " " << m << " " << d << endl;
        }
        else cout << "? " << y - 30 << " " << m << " " << d << endl;
    }
}



Measured memory_bytes: 3180
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <bitset>
using namespace std;
 
int main() {
  string s; cin >> s;
  int x, y; cin >> x >> y;
  int n = s.size();
  int a[10010];
  int j = 0;
 
  for(int i = 0; i < 10010; ++i) {
    a[i] = 0;
  }
 
  for(int i = 0; i < n; ++i) {
    if(s[i] == 'T') j++;
    else a[j]++;
  }
 
  bitset<16001> dpx, dpy;
  dpx = dpy = 1;
  dpx = dpx << 8000;
  dpy = dpy << 8000;
  dpx = dpx << a[0];
  int i = 1;
  while(i < 8000) {
    dpy = (dpy << a[i]) | (dpy >> a[i]);
    i++;
    dpx = (dpx << a[i]) | (dpx >> a[i]);
    i++;
  }
 
  if(dpx[x+8000] && dpy[y+8000]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
 
  return 0;
}

Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    A=LIN(N)
    
    def solve(odd):
        s1 = sorted(A)
        s2 = sorted(A,reverse=True)


        if odd:
            s1,s2 = s2,s1
        
        q = deque([s1.pop()])

        sign = False
        for i in range(N):
            if sign:
                v = s1.pop()
            else:
                v = s2.pop()
            q.appendleft(v)

            if len(s1)+len(s2)<=N:
                break
            
            if sign:
                v = s1.pop()
            else:
                v = s2.pop()
            q.append(v)
            
            if len(s1)+len(s2)<=N:
                break
            sign ^= 1

        res = 0
        before = q[0]
        for a in q:
            res += abs(before-a)
            before = a

        return res 

    print(max(solve(1),solve(0)))
if __name__ == '__main__':
    main()

Measured memory_bytes: 9832
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main(){
	int N;
	cin>>N;
	int a[3][N];
	for(int n=0;n<N;n++){
		cin>>a[0][n]>>a[1][n]>>a[2][n];
	}
	int q,w,e;
	for(int m=0;m<N;m++){
		if(a[2][m]!=0){
			q=a[0][m];
			w=a[1][m];
			e=a[2][m];
			break;
		}
	}
	int i,j,H,f,r;
	for(i=0;i<=100;i++){
		for(j=0;j<=100;j++){
			H=e+abs(i-q)+abs(j-w);
			r=0;
			for(f=0;f<N;f++){
				int h=H-abs(i-a[0][f])-abs(j-a[1][f]);
				if (h<0){
					h=0;	
				}
				if(a[2][f]!= h){
					r=1;
					break;
				}
			}
			if(r == 0){
				cout<<i<<' '<<j<<' '<<H<<endl;
			}
		}
	}
	return 0;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

#define N 305
dd dp[N][N][N];
ll n;
ll a[3];

dd cal(ll i,ll j,ll k){
    if(i==0&&j==0&&k==0)return dp[i][j][k]=0;
    if(i<0||i>n||j<0||j>n||k<0||k>n)return 0;
    if(dp[i][j][k]!=0)return dp[i][j][k];
    return dp[i][j][k]=(dd)((i*cal(i-1,j,k)+j*cal(i+1,j-1,k)+k*cal(i,j+1,k-1)+n)/(dd)(i+j+k));
}

int main(){fastio
    cin>>n;
    rep(i,0,n-1){
        ll c;cin>>c;
        a[c-1]++;
    }
    cout<<setprecision(15)<<cal(a[0],a[1],a[2])<<endl;
    
    
    return 0;
}




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

using namespace std;

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

int main() {
  
  int N, R;
  while(cin >> N >> R) {
    queue<int> A, B, C;
    rep(i, N) { C.push(i); }
    rep(_, R) {
      int c; cin >> c;
      rep(i, N) {
	if(N/2<=i) { A.push(C.front()); }
	else { B.push(C.front()); }
	C.pop();
      }
      
      for(;(!A.empty()) || (!B.empty());) {
	rep(i, c) {
	  if(A.empty()) break;
	  C.push(A.front()); A.pop();
	}
	rep(i, c) {
	  if(B.empty()) break;
	  C.push(B.front()); B.pop();
	}
      }
    }
    cout << C.back() << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1216
#include <cstdio>
#include <cstring>
#include <cmath>

int main()
{
	int a, b;
	while(scanf("%d\n %d", &a, &b)!=EOF)
	{
		int x;
		x = 2 * b - a;
		printf("%d\n", x);
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    int check =0;
    for (int i=0; i<S.length(); i++) {
      for (int j=i+1; j<S.length(); j++) {
        if(S.charAt(i) == S.charAt(j)) {
          check++;
          break;
        }
      }
    }
    if (check == 0) {
      System.out.print("yes");
    } else {
      System.out.print("no");
    }
   }
}

Measured memory_bytes: 20948
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
int n,t1,t2;
int a[100009],b[100009];
main(){
	cin>>n;
	r(i,n)cin>>a[i];
	r(i,n)cin>>b[i];
	r(i,n){
		if(a[i]>b[i]){
			t1+=(a[i]-b[i]);
		}
		else if(a[i]<b[i]){
			if((b[i]-a[i])%2)t2++,t1++;
			t2+=(b[i]-a[i]);
		}
	}
	if(t1<=t2/2)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 384
def main():
    _ = input()
    lst_a = [int(a) for a in input().strip().split(' ')]

    # build hash table
    hash_tbl = {}
    for i, a_i in enumerate(lst_a):
        n_i = i + 1
        tmp = int(n_i - a_i)
        if tmp > 0:
            if tmp in hash_tbl.keys():
                hash_tbl[tmp].append(n_i)
            else:
                hash_tbl[tmp] = [n_i]

    ans = 0
    for j, a_j in enumerate(lst_a):
        n_j = j + 1
        tmp = int(n_j + a_j)
        if tmp in hash_tbl.keys():
            # ans += len([idx for idx in hash_tbl[tmp] if idx > j])
            ans += len(hash_tbl[tmp])
    print(int(ans))


if __name__ == '__main__':
    main()


Measured memory_bytes: 97892
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int len = s.length(), i=0, j=0;
		for (i=len-1; i>=0; i--) if (s.charAt(i)=='Z') break;
		for (j=0; j<len; j++) if (s.charAt(j)=='A') break;
		System.out.println(j>i ? 0 : (i-j)+1);
		sc.close();			
	}

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

}

Measured memory_bytes: 40564
// E - Red and Green Apples
#include <bits/stdc++.h>
using namespace std;
int in(){int x;cin>>x;return x;}

int main(){
	int X,Y,A,B,C; cin>>X>>Y>>A>>B>>C;
	int n = X + Y;
	priority_queue<int> P,Q,R;
	while(A--) P.push(in());
	while(B--) Q.push(in());
	while(C--) R.push(in());
	while(X--){ R.push(P.top()); P.pop(); }
	while(Y--){ R.push(Q.top()); Q.pop(); }
	long long ans = 0;
	while(n--){ ans += R.top(); R.pop(); }
	cout<< ans <<endl;
}

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

int main()
{
  string s;
  cin >> s;
  for(int i = 0; i < 26; i++)
  {
    char judge = 'a' + i;
    if(s.find(judge) == -1 )
    {
      cout << judge << endl;
      return 0;
    }
  }
  cout << "None" << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int a, b, c; cin >> a >> b >> c;
	int j = c * 3 - a - b;
	cout << a << ' ' << b << ' ' << j << endl;
	cout << 3 * c - a - (2 * c - j) << ' ' << c << ' ' << 2 * c - (3 * c - a - (2 * c - j)) << endl;
	cout << c * 2 - j << ' ' << c * 2 - b << ' ' << c * 2 - a << endl;
}

Measured memory_bytes: 256
from math import log2, ceil


class SegmentTree:
    def __init__(self, n):
        tn = 2 ** ceil(log2(n))
        self.a = [0] * (tn * 2)

    def find(self, c, l, r, i):
        if l == r:
            return self.a[c]
        mid = (l + r) // 2
        if i <= mid:
            return self.a[c] + self.find(c * 2, l, mid, i)
        else:
            return self.a[c] + self.find(c * 2 + 1, mid + 1, r, i)

    def add(self, c, l, r, s, t, x):
        if l == r or l == s and r == t:
            self.a[c] += x
            return
        mid = (l + r) // 2
        if t <= mid:
            self.add(c * 2, l, mid, s, t, x)
        elif s > mid:
            self.add(c * 2 + 1, mid + 1, r, s, t, x)
        else:
            self.add(c * 2, l, mid, s, mid, x)
            self.add(c * 2 + 1, mid + 1, r, mid + 1, t, x)


n, q = map(int, input().split())
st = SegmentTree(n)
for _ in range(q):
    query = input().split()
    if query[0] == '0':
        # CAUTION: DSL_2_D: i = 0,1,...,n-1.  DSL_2_E: i = 1,2,...,n.
        s, t, x = map(int, query[1:])
        st.add(1, 1, n, s, t, x)
    else:
        print(st.find(1, 1, n, int(query[1])))

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, max_ans = -1;
  cin >> n;
  vector<int> a(n);
  vector<int> list(100001, 0);
  vector<int> list2(100001, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    list[a[i]]++;
  }
  for (int i = 1; i < 100000; i++) {
    list2[i] = list[i - 1] + list[i] + list[i + 1];
    if(max_ans<list2[i]){
      max_ans = list2[i];
    }
  }
  cout << max_ans << endl;
  return 0;
}

Measured memory_bytes: 4552
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);

		int N = Integer.parseInt(scanner.nextLine());
		int largeN = N*100;
		int a[] = new int[25];
		Boolean isOK = false;
		for(int i = 0; i < 25; i++) {
			a[i] = largeN + i*8;
			if(i > 12) {
				a[i] -= 100;
			}
			if(a[i] % 108 == 0) {
				isOK = true;
				System.out.println(a[i] / 108);
				break;
			}
		}

		if(!isOK) {
			System.out.println(":(");
		}


	}

}


Measured memory_bytes: 21844
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(int a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
int N=0;
static inline void Add(int *fwt,int i,int v){while(i<N){fwt[i]+=v;i|=i+1;}}
static inline int Sum(int *fwt,int i){int v=0;while(i>=0){v+=fwt[i];i=(i&(i+1))-1;}return v;}
int main()
{
  N=IN();int Q=IN(),after[500001],dat[500000],fenwick[500000],id[500001],left[500001],pos[500000],result[500000];
  rep(i,N){dat[i]=IN()-1;}
  rep(i,Q){left[i+1]=IN()-1;int r=IN()-1;after[i+1]=id[r];id[r]=i+1;}
  for(int r=0;r<N;r++)
  {
    if(pos[dat[r]]){Add(fenwick,pos[dat[r]]-1,-1);}
    Add(fenwick,r,1);
    for(int i=id[r];i;i=after[i]){result[i-1]=Sum(fenwick,r)-Sum(fenwick,left[i]-1);}
    pos[dat[r]]=r+1;
  }
  rep(i,Q){OUT(result[i]);}
}

Measured memory_bytes: 17208
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define vi vector<int>
using namespace std;

//int gcd(int a, int b){
//	return b==0 ? a : gcd(b, a%b);
//}

int32_t main(void){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, m;
	cin>>n>>m;
	if(n == 1  || m == 1)
	{
		cout<<1<<endl;
		return 0;
	}
	int ans = ((n*m)+1)/2;
	cout<<ans<<endl;
}

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

#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prtd(n, var)  cout << setprecision(n) << var << endl

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

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

  int ct;

  double ans=0.;

  rep(i,n){
    int st = i+1;
    ct = 0;
    while(st<k){
      st = st * 2;
      ct++;
    }
    ans += 1./double(n)/double(pow(2,double(ct)));
  }

  prtd(12, ans);
}


Measured memory_bytes: 256
n = int(input())
ans = 0

for i in range(1,n+1):
  count = 0
  if i % 2 == 0:
    continue
  for j in range(1, i+1):
    if i % j == 0:
      count += 1
    if j == i and count == 8:
      ans += 1

print(ans)

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-

N_cnt = int(input().strip())
H_ary = list(map(int, input().strip().split()))

step_cnt = 0
most_step = 0
for i in range(1,N_cnt):
    if H_ary[i] <= H_ary[i-1]:
        step_cnt += 1
        if most_step < step_cnt:
            most_step = step_cnt
    else:
        step_cnt = 0

print(most_step)

Measured memory_bytes: 15020
#include<stdio.h>
int main(void)
{
	int D,L,S,O;
	scanf("%d %d",&D,&L);
	S=D/L;
	O=D%L;
	if (0==D%L) {
	printf("%d\n",S);
	}
	else  {
	printf("%d\n",O+S);
	}
	return 0;
}


Measured memory_bytes: 2104
N,C=gets.split(" ").map &:to_i
I=N.times.map{gets.split(" ").map &:to_i}
M,S,r,I[N]=[0],[0],0,[C,0]
(0...N).each{|i|S[i+1]=S[i]+I[i][1];M[i+1]=[S[i+1]-I[i][0],M[i][0]].max,[S[i+1]-2*I[i][0],M[i][1]].max}
(0..N).map{|i|o=S[N]-S[i];r=[r,o+M[i][0]-2*(C-I[i][0]),o+M[i][1]-C+I[i][0]].max}
puts r


Measured memory_bytes: 18476
#include<bits/stdc++.h>
using namespace std;
int main(){
	int w,a,b;
	cin>>w>>a>>b;
	if(fabs(a-b)<w){
		cout<<0;
		return 0;
	}else{
		cout<<fabs(a-b)-w; 
	} 
	return 0;
} 

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

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner (new BufferedInputStream(System.in));
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    System.out.println(c + " " + a + " " + b);
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  string s;
  cin >> s;

  ll n = s.size();
  

  ll res = 0, i = 0, an = 0;
  while(i < n){
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C'){
      res += an + 1;
      s[i] = 'B';
      s[i + 1] = 'C';
      s[i + 2] = 'A';
      i += 2;
    }
    else if (s[i] == 'A'){
      an++;
      i++;
    }
    else {
      an = 0;
      i++;
    }
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
    int l1=e*a,l2=e*b,l3=e*(a+b);//操作1,2に対して溶かせる最大の砂糖
    double ans=0.0;
    int ans1=100*a,ans2=0;
    int ans3=0,ans4=0;

    int c1=l1/c,c2=l1/d;//操作3,4の回数

    rep(i,c1+1){
      rep(j,c2+1){
        ans3=100*a+c*i+d*j;
        ans4=c*i+d*j;
        if(ans3<=f && ans4<=l1 && ans<(double)100*ans4/ans3){
          ans=(double)100*ans4/ans3;
          ans1=ans3;
          ans2=ans4;
        }
      }
    }

    c1=l2/c,c2=l2/d;//操作3,4の回数

    rep(i,c1+1){
      rep(j,c2+1){
        ans3=100*b+c*i+d*j;
        ans4=c*i+d*j;
        if(ans3<=f && ans4<=l2 && ans<(double)100*ans4/ans3){
          ans=(double)100*ans4/ans3;
          ans1=ans3;
          ans2=ans4;
        }
      }
    }

    c1=l3/c,c2=l3/d;//操作3,4の回数

    rep(i,c1+1){
      rep(j,c2+1){
        ans3=100*(a+b)+c*i+d*j;
        ans4=c*i+d*j;
        if(ans3<=f && ans4<=l3 && ans<(double)100*ans4/ans3){
          ans=(double)100*ans4/ans3;
          ans1=ans3;
          ans2=ans4;
        }
      }
    }

    cout<<ans1<<' '<<ans2<<endl;
}

Measured memory_bytes: 256