akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

	public static void main (String[] args)  {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		PriorityQueue<Long> queue = new PriorityQueue<Long>(new Comparator<Long>() {
		public int compare(Long lon1, Long lon2) {
			if (lon1.longValue() < lon2.longValue()) {
				return 1;
			} else if (lon1.longValue() > lon2.longValue()) {
				return -1;
			} else {
				return 0;
			}
		}
		});
		PriorityQueue<Long> next = new PriorityQueue<Long>(new Comparator<Long>() {
		public int compare(Long lon1, Long lon2) {
			if (lon1.longValue() < lon2.longValue()) {
				return 1;
			} else if (lon1.longValue() > lon2.longValue()) {
				return -1;
			} else {
				return 0;
			}
		}
		});
		for (int i = 0; i < n; i++) {
			queue.add(sc.nextLong());
		}
		long count = 0;
		while (true) {
			long x = queue.poll();
			if (x < n) {
				break;
			}
			long ans = x / n;
			next.add(x % n);
			while (queue.size() >  0) {
				next.add(queue.poll() + ans);
			}
			count += ans;
			PriorityQueue<Long> tmp = next;
			next = queue;
			queue = tmp;
		}
		System.out.println(count);
	}
	
}


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

int main() {
    int L, R; cin >> L >> R;
    int ans = 2019, flag = 0;
    for (long long i = L; i <= R; i++) {
        for (long long j = i + 1; j <= R; j++) {
            int t = (i % 2019) * (j % 2019) % 2019;
            ans = min(ans, t);
            if (ans == 0) { flag = 1;  break; }
        }
        if (flag) break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int n;
  scanf("%d",&n);
  int i,p[n];
  for(i=0;i<n;i++)
    scanf("%d",&p[i]);

  int cnt=0;
  for(i=1;i<n-1;i++){
    if((p[i-1]<p[i])&&(p[i]<p[i+1]))
      cnt++;
    else if((p[i-1]>p[i])&&(p[i]>p[i+1]))
      cnt++;
  }

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

Measured memory_bytes: 128
#include<cstdio>

using namespace std;

char mp[2000][2000];
int dp[2000][2000],MOD=1e9+7;

int main()
{
  int h=0,w=0;scanf("%d%d",&h,&w);
  for(int i=1;i<=h;i++)scanf("%s",mp[i]+1);
  for(int i=1;i<=h;i++)
  {
    for(int j=1;j<=w;j++)
    {
      if(i==1&&j==1)dp[i][j]=1;
      else if(mp[i][j]=='#')dp[i][j]=0;
      else dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
    }
  }
  printf("%d",dp[h][w]);
  return 0;
}
  

Measured memory_bytes: 12416
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val list :List<Int> = listOf()
    val r = odd(N,list)
    val answer :Float = r.size.toFloat()/N.toFloat()
    println(answer)
}

fun odd(n :Int,list :List<Int>) :List<Int> {
    return when (n) {
        1 -> list + listOf(1)
        else -> {
            if (n % 2 == 0) {
                odd(n-1, list)
            } else {
                odd(n-1 , list + listOf(n))
            }
        }
    }
}

Measured memory_bytes: 33604
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	vector<long double> p(N);
	for (int i = 0; i < N; ++i) { cin >> p[i]; }

	vector<long double> d(N + 1, 0);
	for (int i = 0; i < N; ++i) {
		d[i + 1] = (p[i] * (p[i] + 1) / 2.0) / p[i];
		d[i + 1] += d[i];
	}

	long double ans = 0;
	for (int i = K; i <= N; ++i) {
		ans = max(ans, d[i] - d[i - K]);
	}
	cout.precision(15);
	cout << fixed << ans << endl;

	return 0;
}


Measured memory_bytes: 6528
N = int(input())
A = list(map(int,input().split()))
C = {}
for i in range(N):
    if A[i] not in C:
        C[A[i]] = 0
    C[A[i]] += 1
n = len(C)
if n%2==1:
    print(n)
else:
    print(n-1)

Measured memory_bytes: 97976
#include <iostream>
#include <map>
using namespace std;
typedef pair<int,int> P;

int n,m,f[101][101],s[51][51];

bool search(int sx, int sy){
	for(int y=sy ; y-sy < m ; y++ ){
		for(int x=sx ; x-sx < m ; x++ ){
			int mx = x-sx;
			int my = y-sy;
			if( s[my][mx] == -1 ){
				continue;
			}else if( f[y][x] != s[my][mx] ){
				return false;
			}
		}
	}
	return true;
}

P check(){
	for(int y=0 ; y < m ; y++ ){
		for(int x=0 ; x < m ; x++ ){
			if( s[y][x] != -1 ){
				P p(y,x);
				return p;
			}
		}
	}
}

void rot(){
	int r[51][51];
	for(int y=0 ; y < m ; y++ ){
		for(int x=0 ; x < m ; x++ ){
			r[x][m-y-1] = s[y][x];
		}
	}
	for(int y=0 ; y < m ; y++ ){
		for(int x=0 ; x < m ; x++ ){
			s[y][x] = r[y][x];
		}
	}
}

int main(){
	while( cin >> n >> m , n||m ){
		bool ans = false;
		int ax,ay;
		P p(100,100);

		for(int y=0 ; y < n ; y++ ){
			for(int x=0 ; x < n ; x++ ){
				cin >> f[y][x];
			}
		}
		for(int y=0 ; y < m ; y++ ){
			for(int x=0 ; x < m ; x++ ){
				cin >> s[y][x];
			}
		}
		for(int i=0 ; i < 4 ; i++ ){
			rot();
			for(int y=0 ; y+m <= n ; y++ ){
				for(int x=0 ; x+m <= n ; x++ ){
					if( search( x , y ) == true ){
						ans = true;
						P p_ = check();
						p_.first += y;
						p_.second += x;
						p = min( p , p_ );
					}
				}
			}
		}
		
		if( ans ){
			cout << (p.second+1) << " " << (p.first+1) << endl;
		}else{
			cout << "NA" <<endl;
		}
	}
}

Measured memory_bytes: 932
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

typedef long long ll ;
typedef double db;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define for0(i,n)          for(int i=0;i<n;i++)
#define for1(i,n)          for(int i=1;i<=n;i++)
#define forab(a,b)       for(int i=a;i<=b;i++)
//#define gcd(a, b)     __gcd(a, b)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)     cout<<"Case "<<z<<": "<<x<<"\n"
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)

using namespace std;

int main()
{
	int i,n,m,x,s=0;
	cin>>n>>m;
	for1(i,m){
		cin>>x;
		s += x;
		}
	if(s>n) cout<<-1<<nw;
	else cout<<n-s<<nw;
	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
char change1[5]={' ','.',',','!','?'};
char change2[3]={'c','a','b'};
char change3[3]={'f','d','e'};
char change4[3]={'i','g','h'};
char change5[3]={'l','j','k'};
char change6[3]={'o','m','n'};
char change7[4]={'s','p','q','r'};
char change8[3]={'v','t','u'};
char change9[4]={'z','w','x','y'};
int cnt;
char change(char c){
    if(c=='1'){
        return change1[cnt%5];
    }
    else if(c=='2'){
        return change2[cnt%3];
    }
    else if(c=='3'){
        return change3[cnt%3];
    }
    else if(c=='4'){
        return change4[cnt%3];
    }
    else if(c=='5'){
        return change5[cnt%3];
    }
    else if(c=='6'){
        return change6[cnt%3];
    }
    else if(c=='7'){
        return change7[cnt%4];
    }
    else if(c=='8'){
        return change8[cnt%3];
    }
    else if(c=='9'){
        return change9[cnt%4];
    }
}
using namespace std;
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        vector<char> ans;
        cnt=0;
        char tmp;
        string s;
        cin>>s;
        for(int j=0;j<s.size();j++){
            if(s[j]=='0'){
                if(cnt!=0){
                    ans.push_back(change(tmp));
                    cnt=0;
                }
                else {continue;}
            }
            else{
                tmp=s[j];
                cnt++;
            }
        }
        for(int j=0;j<ans.size();j++){
            cout<<ans.at(j);
        }
        cout<<endl;
        
    }
    return 0;
}




Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    long long N;
    cin >> N;
    if (N%2 == 1) {
        puts("0");
    } else {
        long long ans = 0, i = 5, tmp = N/2;
        while (i <= tmp) {
            ans += tmp / i;
            i *= 5;
        }
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int c = scanner.nextInt();
		int r = scanner.nextInt();
		
		
		int[][] A; 
		A = new int[r+1][c+1];//合計を表す領域を作るために+1
		
		for(int i=0;i<c;i++){
			for(int f=0;f<r;f++){
			int n= scanner.nextInt();
				A[f][i]=n;//A[行][列]
			}
		}
        int sum1=0;
        
		for(int i=0;i<c+1;i++){
			
			for(int f=0;f<r+1;f++){

					if((f == r)&&(!(i == c) )){
					System.out.println(A[f][i]);//行の合計、列の合計、総合計、その他に場合分けして出力
					
					}
					else if((!(f ==r))&&(i == c)){
						System.out.print(A[f][i]+" ");
					}
					else if((f ==r) && (i==c)){
						for(int g=0;g<c;g++){
							A[r][c]=A[r][c]+A[r][g];

						}
						 System.out.println(A[r][c]);
					}
					else {
						sum1=A[r][i]+A[f][i];
					    A[r][i]=sum1;
					    sum1=0;
					    
					    sum1=A[f][c]+A[f][i];
					    A[f][c]=sum1;
					    sum1=0;
					    
						System.out.print(A[f][i]+" ");
					}}
				
				
			}
		
		scanner.close();

	}
}



Measured memory_bytes: 41272
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

ll x[MAX_N],y[MAX_N];
ll sx[MAX_N];
ll sy[MAX_N];
int n,m;

int main()
{
	scanf("%d%d",&n,&m);
	rep(i,n){
		scanf("%lld",&x[i]);
	}
	rep(i,m){
		scanf("%lld",&y[i]);
	}
	rep(i,n-1){
		sx[i] = (x[i+1] - x[i])%MOD;
	}
	rep(i,m-1){
		sy[i] = (y[i+1] - y[i])%MOD;
	}
	ll sumx = 0LL;
	rep(i,n-1){
		sumx = (sumx + ((ll)(n-1-i)*(i+1)%MOD)*sx[i]%MOD)%MOD;
	}
	ll sumy = 0LL;
	rep(i,m-1){
		sumy = (sumy + ((ll)(m-1-i)*(i+1)%MOD)*sy[i]%MOD)%MOD;
	}
	ll ans = sumx*sumy%MOD;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3328
import java.util.*;

class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int wmax = sc.nextInt();
        int w[] = new int[n];
        int v[] = new int[n];
        for (int i=0;i<n;i++){
            w[i] = sc.nextInt();
            v[i] = sc.nextInt();
        }
        if (w[0]<=300) {
            int dp[][] = new int[n+1][303*n+1];
            for (int i=1;i<=n;i++){
                for (int weight=0;weight<=303*n;weight++){
                    int diffw = weight - w[i-1];
                    if (diffw>=0){
                        dp[i][weight] = Math.max(dp[i-1][weight],dp[i-1][diffw] + v[i-1]);
                    } else {
                        dp[i][weight] = dp[i-1][weight];
                    }
                }
            }
            System.out.println(dp[n][Math.min(wmax,303*n)]);

        } else {
            int maxn = wmax/w[0];
//            System.out.println(maxn);
            int maxr = wmax - maxn*w[0];
//            System.out.println(maxr);
            maxn = Math.min(maxn,n);
            maxr = Math.min(maxr,3*n);
            int dp[][][] = new int[n+1][n+1][3*n+1];
            //maybe initialized to 0?
            for (int i=1; i<=n; i++) {
                int diff = w[i-1]-w[0];
                for (int m=0; m<=n; m++) {
                    for (int r=0; r<=3*n; r++){
                        if (m>0 && r-diff>=0){
                            dp[i][m][r] = Math.max(dp[i-1][m][r],dp[i-1][m-1][r-diff]+v[i-1]);
                        } else {
                            dp[i][m][r] = dp[i-1][m][r];
                        }
                    }
                }
            }
            /*
            for (int i=0;i<=n;i++){
                
                System.out.println("-----");
                System.out.println(i);
                System.out.println("-----");
                for(int m=0;m<=n;m++){
                    for(int r=0;r<=3*n;r++){
                        System.out.print(dp[i][m][r]);
                        System.out.print(" ");
                    }
                    System.out.println();
                }
            }
            */
            System.out.println(dp[n][maxn][maxr]);
        }

    }
}

Measured memory_bytes: 35304
N = int(input())
xyh = []
for _ in range(N):
    xyh.append(list(map(int,input().split())))

for x in range(101):
    for y in range(101):
        h_must = 0
        h_max = 1000000000
        for k in range(N):
            h_tmp = xyh[k][2]+abs(x-xyh[k][0])+abs(y-xyh[k][1])
            if h_must == 0:
                if xyh[k][2] != 0:
                    h_must = h_tmp
                else:
                    h_max = min(h_max,h_tmp)
            else:
                if xyh[k][2] != 0:
                    if h_must != h_tmp:
                        break
                else:
                    h_max = min(h_max,h_tmp)
                    if h_must > h_max:
                        break
        else:
            if h_must == 0:
                h_must = h_max
            print("{} {} {}".format(x,y,h_must))
            break
    else:
        continue
    break


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{    priority_queue<unsigned long long int> q; 
	int  n,m;
    cin>>n>>m;
    unsigned long long int i, a[n];
    for(i=0;i<n;i++)
    { cin>>a[i]; q.push(a[i]);}
    unsigned long long int ans=0;
    while(m--)
    {
        long long int x=q.top();
    //cout<<x<<endl;
        q.pop();
        x=x/2;
        q.push(x);
        
    }
 
   while(!q.empty())
    {
        long long int x=q.top();
        //cout<<x<<endl;
        q.pop();
        ans+=x;}
    cout<<ans<<endl;
 
    
}

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

typedef long long LL;
const double eps = 1e-8;
#define MAXN 100010

LL a[MAXN], b[MAXN], f[MAXN], s[MAXN];
LL c[MAXN], d[MAXN];


int main()
{
	int n; 
	LL C;
	scanf("%d %lld", &n, &C);
	for (int i = 1; i <= n; ++i)
		scanf("%lld %lld", &a[i], &b[i]);
		
	LL sum, ans = 0;
	sum = 0;	
	for (int i = n; i >= 1; --i)
		s[i] = s[i + 1] + b[i];
	
	for (int i = n; i >= 1; --i)
	{
		f[i] = max(f[i + 1], s[i] - (C - a[i]));
	}
	for (int i = 1; i <= n; ++i)
	{
		sum += b[i];
		ans = max(ans, sum - a[i] + max(0LL, f[i + 1] - a[i]));
	}
	
	
	for (int i = 1; i <= n; ++i)
	{
		c[i] = C - a[n + 1 - i];
		d[i] = b[n + 1 - i];
	}
	for (int i = 1; i <= n; ++i)
		a[i] = c[i], b[i] = d[i];
	
	sum = 0;	
	for (int i = n; i >= 1; --i)
		s[i] = s[i + 1] + b[i];
	
	for (int i = n; i >= 1; --i)
	{
		f[i] = max(f[i + 1], s[i] - (C - a[i]));
	}
	for (int i = 1; i <= n; ++i)
	{
		sum += b[i];
		ans = max(ans, sum - a[i] + max(0LL, f[i + 1] - a[i]));
	}
		 
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4992
/**
*   Bismillahir Rahmanir Rahim.
*   Imtiaz_rafi
*   PCIU, CHITTAGONG
**/
#include<bits/stdc++.h>
using namespace std;
#define speed ios::sync_with_stdio(0);cin.tie(0);
#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)
#define rep(i,a) for(ll i=0;i<a;i++)
#define rep1(i,begin,end) for(ll i=begin;i<=end;i++)
#define all(v)   v.begin(),v.end()
#define pb push_back
#define pf push_front
#define mp make_pair
#define pi acos(-1)
// bitshift (1LL<<(3)) *2^3
typedef long long int ll;
typedef vector<ll>vi;
typedef map<ll,ll>m;
typedef map<char,ll>mc;
typedef set<ll>st;
typedef set<char>sc;
ll dx[] ={-1,+1,0,0,+1,-1,+1,-1};
ll dy[] ={0,0,-1,+1,+1,+1,-1,-1};
const ll mx = 1e5+123;
bool vis[mx];
vi adj[mx];
int main()
{
    speed;
    ll t,i,j,a,b,x,y,e=0,ans=0,sum=0;
    string s,c;
    cin>>s>>c;
    //sort(all(s));
    //sort(all(c));
    for(i=0,j=s.size();i<=j;i++,j--)
    {
        if(i==j)
        {
            if(s[i]!=c[i])
            ans++;
        }
        else
        {
            if(s[i]!=c[i])
            ans++;
            if(s[j]!=c[j])
                ans++;
        }

            //cout<<i<<" "<<j<<endl;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 6152
#include <cstdio>
#include <cstring>

int main() {
    char s[102], t[102];
    scanf("%s\n%s", s, t);
    if (strlen(s) > strlen(t)) {
        puts("GREATER");
    }
    else if (strlen(s) < strlen(t)) {
        puts("LESS");
    }
    else {
        for (int i = 0; i < strlen(s); i++) {
            if (s[i] > t[i]) {
                puts("GREATER");
                return 0;
            }
            else if (s[i] < t[i]) {
                puts("LESS");
                return 0;
            }
        }
        puts("EQUAL");
    }
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;



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

  ll K, X;
  cin >> K >> X;

  cout << ((500*K>=X) ? "Yes" : "No") << "\n";
  return 0;
}


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

int len ;

char s[300010] ;

int main(){
	#define NAME "arc098a"
	//freopen( NAME".inp" , "r" , stdin ) ; freopen( NAME".out" , "w" , stdout ) ;

	scanf("%d", &len) ;

	scanf("%s", s + 1) ;

	int numfoo = 0, numbar = 0 ;

	for (int i = 1; i <= len; ++ i){
		if(s[i] == 'W') numfoo ++ ;
		else numbar ++ ;
	}

	int foo = 0, bar = 0 ;

	int ans = (int)1e9 ;

	for (int i = 1; i <= len; ++ i){
		ans = min(ans, foo + numbar - (s[i] == 'E') - bar) ;
		if(s[i] == 'W') foo ++ ;
		else bar ++ ;
	}

	printf("%d", ans) ;

	return 0 ;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string p;
	cin>>p;
	int n=p.size();
	if(p[n-1]=='s')
	{
		p+='e';
		p+='s';
	}
	else
	{
		p+='s';
	}
	cout<<p;
}


Measured memory_bytes: 3628
// class

#include <iostream>
#include <string>
using namespace std;

static const int MAX_N = 9;
static const int AM_V = 200;
static const int PM_V = 300;

struct DATA {
	int cnt;
	int value;
	string name;
};

class CLS {
private:
	DATA data;

public:
	CLS();
	void set(int in_cnt, int in_value, string set_str);
	DATA get();
};

CLS::CLS()
{

	this->data.cnt   = 0;
	this->data.value = 0;
	this->data.name  = "no name";

};

void CLS::set(const int in_cnt, const int in_value, const string set_str)
{

	this->data.cnt   = in_cnt;
	this->data.value = in_value;
	this->data.name  = set_str;

}

DATA CLS::get()
{

	return this->data;

}

int main()
{

	int am_c, pm_c;
	string n_str;
	CLS cls[MAX_N];
	
	for(int i = 0; i < MAX_N; i++) {
		cin >> n_str >> am_c >> pm_c;
		cls[i].set(am_c + pm_c, am_c * AM_V + pm_c * PM_V, n_str);
	}

	for(int i = 0; i < MAX_N; i++) {
		cout << cls[i].get().name << " " << cls[i].get().cnt << " " << cls[i].get().value << endl;
	}

	return 0;

}

Measured memory_bytes: 2980
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")

#include <cstdio>
#include <stdint.h>
#include <algorithm>
#include <functional>

#ifdef _MSC_VER
//#include <__msvc_all_public_headers.hpp>
#define getchar_unlocked getchar
#define putchar_unlocked putchar
#endif // VS

#define long long long
using namespace std;

void read(uint32_t& x)
{
	x = 0;
	int k;
	while (true)
	{
		k = getchar_unlocked();
		if (k < '0' || k > '9')	break;
		x = x * 10 + k - '0';
	}
}

void sread(int32_t& x)
{
	bool flag;
	x = 0;
	int k = getchar_unlocked();
	if (flag = (k == '-')) k = getchar_unlocked();

	while (true)
	{
		if (k < '0' || k > '9')	break;
		x = x * 10 + k - '0';
		k = getchar_unlocked();
	}
	if (flag) x *= -1;
}

void sprint(int64_t x) {
	if (x == 0) {
		putchar_unlocked('0');
		return;
	}
	if (x < 0) {
		putchar_unlocked('-');
		x *= -1;
	}
	int s = 0;
	char f[15];
	while (x) {
		f[s++] = x % 10;
		x /= 10;
	}
	while (s--)
		putchar_unlocked(f[s] + '0');
	putchar_unlocked('\n');
}

int32_t a[200000];
int main() {
	uint32_t n;
	read(n);
	for (size_t i = 0; i < n; i++) sread(a[i]);
	int64_t res;
	if (n & 1) {
		//Odd
		int64_t sum = 0;
		for (int i = 0; i < n - 1; i += 2) sum += a[i];
		res = sum;
		int64_t tailDiff = 0, tailDiffMax = 0;
		for (int i = n - 3; i >= 0; i -= 2)
		{
			sum -= a[i]; sum += a[i + 1];
			tailDiff += a[i + 2]; tailDiff -= a[i + 1];
			tailDiffMax = max(tailDiffMax, tailDiff);
			res = max(res, sum + tailDiffMax);
		}
	}
	else {
		//Even
		int64_t sum = 0;
		for (size_t i = 0; i < n; i += 2) sum += a[i];
		res = sum;
		for (int i = n - 1; i >= 0; i -= 2)
		{
			sum += a[i]; sum -= a[i - 1];
			res = max(res, sum);
		}
	}
	sprint(res);
}


Measured memory_bytes: 3772
#include<bits/stdc++.h>
using namespace std ;
#define ll long long int 
#define pb push_back 
#define mp make_pair 
#define pii pair <int , int > 
#define pll pair < ll , ll >
int main(){
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;
	ll n , sum = 0 ;
	cin >> n ;
	ll arr[n] ;
	map < ll , ll > m ;
	for(int i = 0 ; i < n ; i++) {
		cin >> arr[i] ;
		sum += arr[i] ;
		m[arr[i]]++ ;
	}
	int q ;
	cin >> q ;
	while(q--){
		ll b , c ;
		cin >> b >> c ;
		cout << sum + m[b]*(c - b) << '\n' ;
		m[c] += m[b] ;
		sum += m[b]*(c - b) ;
		m[b] = 0 ;
	}
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll k; cin >> k;
	while (k--) cout << "ACL";
	cout << endl;
}



Measured memory_bytes: 3580
n = input()
s = input()
L = 0
r = len(s)

cnt = 0
while True:
    L = s.find('W')
    if L == -1:
        break
    r = s.rfind('R')
    if r == -1:
        break

    if (L > r):
        break

    s = s[L + 1:r].lstrip('R').rstrip('W')

    cnt += 1

if L != -1 and L < r:
    cnt += L + 1

print(cnt)

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int n, a; cin >> n >> a;
	n %= 500;
	string ret;
	if (n <= a) ret = "Yes";
	else ret = "No";
	cout << ret << endl;
	return 0;
}

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

int main() {
  vector<vector<vector<int>>> vec(4,vector<vector<int>>(3,vector<int>(10,0)));
  int n;
  cin >> n;
  rep(i,n) {
    int b,f,r,v;
    cin >> b >> f >> r >> v;
    b--;f--;r--;
    vec[b][f][r] += v;
  }
  rep(i,4) {
    rep(j,3) {
      rep(k,10) {
        cout << ' ' << vec[i][j][k];
      }
      cout << endl;
    }
    if(i!=3) {
      cout << "####################" << endl;
    }
  }
  return 0;
}


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

using namespace std;

const int INF = 1e9;
const int MAX = 16;

int dp[1 << MAX][MAX];
int costs[1 << MAX];
int G[MAX][MAX];

int main() {
    int N, M, a, b, c, all_costs = 0;

    cin >> N >> M;

    for(int i = 0; i < M; i++) {
        cin >> a >> b >> c;
        a--, b--;
        G[a][b] = G[b][a] = c;
        all_costs += c;
    }

    for(int i = 0; i < (1 << N); i++) {
        for(int j = 0; j < N; j++) {
            for(int k = j+1; k < N; k++) {
                if(!((i >> j) & 1)) continue;
                if(!((i >> k) & 1)) continue;
                costs[i] += G[j][k];
            }
        }
    }

    for(int i = 0; i < (1 << N); i++) {
        for(int j = 0; j < N; j++) {
            dp[i][j] = -INF;
        }
    }

    for(int i = 0; i < (1 << N); i++) {
        // set to terminal 0
        if(i & 1) {
            dp[i][0] = costs[i];
        }
    }

    int mask = ((1 << N) - 1);

    for(int S = 0; S < (1 << N); S++) {
        for(int i = 0; i < N; i++) {
            // select terminal i in S
            if(dp[S][i] == -INF) continue;
            // create a sets "sup" that is sub S
            int sup = (~S) & mask;
            int sub = sup;

            do {
                // select terminal j in "sub"
                for(int j = 0; j < N; j++) {
                    if(!((sub >> j) & 1)) continue;
                    if(G[i][j] == 0) continue;

                    dp[S|sub][j] = max(dp[S|sub][j], dp[S][i] + G[i][j] + costs[sub]);
                }

                sub = (sub-1) & sup;
            } while(sub != sup);
        }
    }

    cout << all_costs - dp[(1<<N)-1][N-1] << endl;
}

Measured memory_bytes: 4224
N = int(input())    
S = [0]*N
for i in range(N):
    t = list(input())
    t.sort()
    t_sort = "".join(t)
    S[i] = t_sort

count = 0
result={}
for i in range (0,len(S)):
    item = S[i]
    if item in result:
        count += result[item]
        result[item] = result[item]+1
    else:
        result[item] = 1
    
print(count)

Measured memory_bytes: 66124
#include<bits/stdc++.h>
#define ll long long
#define rep(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
int main()
{
  ll a,b;
  cin >> a >> b;
  if(a+b==15)printf("+");
  else if(a*b==15)printf("*");
  else printf("x");
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int top,S[1000];
void push(int x)
{
    S[++top]=x;
}
int pop()
{
    top--;
    return S[top+1];
}
int main()
{
    int a,b;
    top=0;
    char s[100];
    while(scanf("%s",s)!=EOF)
    {
        if(s[0]=='+')
        {
            a=pop();
            b=pop();
            push(a+b);
        }
        else if(s[0]=='-')
        {
            b=pop();
            a=pop();
            push(a-b);
        }
        else if(s[0]=='*')
        {
            a=pop();
            b=pop();
            push(a*b);
        }
        else
            push(atoi(s));
    }
    printf("%d\n",pop());
    return 0;
}

Measured memory_bytes: 3224
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define what_is(x) cerr << #x << " is " << x << endl;

signed main()
{
	cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);

	string s;
	cin >> s;
	int n = s.size();
	int cnt = 1, cond = 1;
	for (int i = 1; i < n; ++i)
	{
		if (cond == 1)
		{
			if (s[i] == s[i - 1])
			{
				cond = 2;
				++i;
				if (i == n) break;
			}
			else
				cond = 1;
		}
		else
			cond = 1;
		++cnt;
	}

	cout << cnt << endl;

	return 0;
}


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

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using qi = queue<int>;

int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n, u, v;
  cin >> n;
  vi a(n * n), d(n * n);
  vvi g(n * n);
  for(int i = 0; i < n; i++) {
    int p;
    for (int j = 0; j < n - 1; j++) {
      cin >> u, u--;
      int e;
      if (i > u) e = u * n + i;
      else e = i * n + u;
      if (j) g[p].push_back(e), a[e]++;
      p = e;
    }
  }
  bool ok = 1;
  qi q;
  for (int i = 0; i < n * n; i++)
    if (!a[i])
      q.push(i), d[i] = 1;
  while (ok && !q.empty()) {
    u = q.front();
    q.pop();
    for(int v : g[u]) {
      a[v]--;
      if (!a[v])
        q.push(v), d[v] = d[u] + 1;
    }
  }
  for (int x : a)
    if (x) {
      cout << "-1\n";
      return 0;
    }
  cout << d[u] << "\n";
}


Measured memory_bytes: 49152
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		
		long a=s.nextLong();
		long a_c=a;
		long b=s.nextLong();
		long b_c=b;
		long ans=1;
		long x=1;
		
		for(int i=2;a>i && b>i;i++)
		{
			while((a_c%i)==0 && (b_c%i)==0)
			{
				a_c/=i;
				b_c/=i;
				x*=i;
			}
		}
		ans=a_c*b_c*x;
		System.out.println(ans);
		
		s.close();
	}
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define SFOR(i,a,b) for(int i=a;i<b;i++)
#define elif(a) else if(a)
#define INF INT_MAX
#define F first
#define S second
#define endl '\n'
using namespace std;
typedef long long ll;
//typedef pair<int,int>P;

int s[1001][1001],P,Q,R,C;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;

  while(1){
    cin>>n;
    if(n==0) break;
    FOR(i,n){
      FOR(j,4){
        cin>>s[i][j];
      }
    }
    cin>>P>>Q>>R>>C;
    int fl=0;
    FOR(i,n){
      if(s[i][1]<=P && s[i][2]<=Q && s[i][3]<=R && (s[i][1]*4+s[i][2]*9+s[i][3]*4)<=C){
        cout<<s[i][0]<<endl;
        fl=1;
      }
    }
    if(!fl) cout<<"NA"<<endl;
  }

  return 0;
}




Measured memory_bytes: 6984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> P;

template <typename T> T gcd(T x, T y) { return( y ? gcd(y, x % y) : x); }
template <typename T> T lcm(T x, T y) { return( x / gcd(x, y) * y); }
template <typename T> void printVec(vector<T> &vec) {
  cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    cout << *it << " ";
  }
  cout << endl;
}

int main() {
  long double a;
  long double b;
  long double ans;
  ll ans2;
  cin >> a >> b;
  
  ans = a * b;
  ans2 = ans;
  cout << ans2 << endl;
	return 0;
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	int ans=0;
	cin>>s;
	int l=s.length();
	for(int i=0;i<l;i++)
	if(i%2==0)
		if(s[i]!='0') ans++;
		else continue;
	else
		if(s[i]!='1') ans++;
		else continue;
	ans=min(ans,l-ans);
	cout<<ans;
}

Measured memory_bytes: 512
# -*- coding: utf-8 -*-
N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

ans = 0
before_A = -1
for A in A_list:
    ans += B_list[A - 1]
    if A - before_A == 1:
        ans += C_list[before_A - 1]
    before_A = A
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	string s, t;
	cin >> s >> t;

	int s_len = (int)s.size(), t_len = (int)t.size();
	vector<vector<int>> dp(s_len + 1, vector<int>(t_len + 1));

	for (int i = 1; i <= s_len; i++) {
		for (int j = 1; j <= t_len; j++) {

			if (s[i - 1] == t[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 1;
			else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);

		}
	}
	
	string ans;
	int x = s_len, y = t_len;
	while (x > 0 && y > 0) {

		if (dp[x][y] == dp[x - 1][y]) x--;
		else if (dp[x][y] == dp[x][y - 1]) y--;
		else {
			ans.push_back(s[x - 1]);
			x--, y--;
		}
	}

	reverse(ans.begin(), ans.end());
	cout << ans << "\n";

	return 0;

}

Measured memory_bytes: 35584
readline = open(0).readline

N = int(readline())
P = [readline().split() for i in range(N)]

P = [(int(v), int(w), t, int(d), s) for v, w, t, d, s in P]
P.sort()

open(1, 'w').writelines(["%d %d %s %d %s\n" % e for e in P])


Measured memory_bytes: 67040
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			var d = new Dictionary<int, int>();
			var s = "";
			while ((s = Console.ReadLine()) != null)
			{
				var n = int.Parse(s);
				if (!d.ContainsKey(n))
					d.Add(n, 0);
				d[n]++;
			}
			var max = d.Select(p => p.Value).Max();
			foreach (var p in d.Where(i => i.Value == max).OrderBy(i => i.Key))
			{
				Console.WriteLine(p.Key);
			}
		}
	}
}

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

int n;
int k;
int h[100010];
int memo[100010];

int dp(int i){
  if(i == n-1){
    return 0;
  }

  if(memo[i] != -1) return memo[i];

  int ans = INT_MAX;
  for(int j = 1;j <= k;j++){
    if(i+j < n){
      ans = min(ans, dp(i+j) + abs(h[i+j] - h[i]));
    }
  }

  return memo[i] = ans;
}

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

  for(int i = 0;i < n;i++) cin >> h[i];

  memset(memo, -1, sizeof(memo));

  cout << dp(0) << endl;

  return 0;
}

Measured memory_bytes: 5760
open Printf
open Scanf

let ( ++ ) = Int64.add
let ( -- ) = Int64.sub
let ( ** ) = Int64.mul
let ( // ) = Int64.div
let ( %% ) = Int64.rem
let landl = Int64.logand
let long = Int64.of_int

let read_int _ = bscanf Scanning.stdin " %d " (fun x -> x)

let max_n = 200
let max_x = 100000
let m = 1000_000_007L

let rec foldi i n f a =
  if i > n
  then a
  else foldi (i+1) n f (f a i)

(*
let rec mod_pow' res a = function
  | 0L -> res
  | b ->
    let res' = if landl b 1L = 1L then res ** a %% m else res in
    mod_pow' res' (a**a%%m) (b//2L)
*)

let rec mod_pow a = function
  | 0L -> 1L
  | b -> (if landl b 1L = 1L then a else 1L) ** mod_pow (a**a%%m) (b//2L) %% m

let dp = Array.make_matrix max_n (max_x+1) (-1L)
let rec f n x s i =
  if i = n
  then long x
  else if dp.(i).(x) < 0L
  then
    let res = (long (n-i-1) ** f n x s (i+1) %% m ++ f n (x mod s.(i)) s (i+1)) %% m in
    let res = res ** mod_pow (long (n-i)) (m--2L) %% m in
    let () = dp.(i).(x) <- res in
    res
  else dp.(i).(x)

let () =
  let n = read_int () in
  let x = read_int () in
  let s = Array.(init n read_int) in
  let () = Array.fast_sort (fun x y -> y - x) s in
  let ans = foldi 1 n (fun a i -> a ** long i %% m) (f n x s 0) in
  printf "%Ld\n" ans



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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;


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

    vector<int> q(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        q[p[i]] = q[p[i] - 1] + 1;
    }

    sort(ALL(q), greater<int>());
    cout << n - q[0] << endl;
}


Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	static char winHand(char c){
		if(c == 'r'){
			return 'p';
		}else if(c == 's'){
			return 'r';
		}else{
			return 's';
		}
	}
	static char exclude(char c1 , char c2){
		char arr[] = {'p' , 'r' , 's'};
		for(char c : arr){
			if(c == c1 || c == c2){
				continue;
			}
			return c;
		}
		return 'N';
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int R = sc.nextInt();
		int S = sc.nextInt();
		int P = sc.nextInt();
		String T = sc.next();
		char prev[] = new char[N];
		long result = 0;
		for(int i = 0 ; i < N ; ++i){
			char c = T.charAt(i);
			char w = winHand(c);
			char cur = w;
			if(i >= K){
				if(prev[i - K] == w){
					if(i + K < N){
						char w2 = winHand(T.charAt(i + K));
						cur = exclude(w, w2);
					}else{
						cur = exclude(w, w);
					}
				}
			}else{
				
			}
			prev[i] = cur;
			if(cur == w){
				if(w == 'r') result += R;
				if(w == 's') result += S;
				if(w == 'p') result += P;
			}
		}
//		System.out.println(Arrays.toString(prev));
		System.out.println(result);
	}
}


Measured memory_bytes: 27364
h, w = map(int, input().split())
A = [list(str(input())) for _ in range(h)]

from collections import deque
q = deque([])
visit = [[-1]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if A[i][j] == '#':
            q.append((i, j))
            visit[i][j] = 0

while q:
    y, x = q.popleft()
    for dy, dx in (-1, 0), (1, 0), (0, -1), (0, 1):
        ny, nx = y+dy, x+dx
        if 0 <= ny < h and 0 <= nx < w:
            if visit[ny][nx] == -1:
                visit[ny][nx] = visit[y][x]+1
                q.append((ny, nx))
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, visit[i][j])
print(ans)


Measured memory_bytes: 148816
#include<cstdio>
int n,m;
long long dp[51][51][51],c[51][51],mo,f1[51][51],f2[51][51];
int main()
{
	scanf("%d",&n);
	dp[1][0][0]=1;
	mo=1000000007;
	c[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		c[i][0]=c[i][i]=1;
		for(int j=1;j<=i-1;j++) c[i][j]=(c[i-1][j-1]+c[i-1][j])%mo;
	}
	for(int k=0;k<=n-1;k++)
	for(int i=0;i<=n-k;i++)
	for(int j=0;j<=n-i-k;j++) if(i+j>0)
	{
		if(i>j) dp[i][j][k]=(dp[i][j][k]+f1[i-j][k])%mo;
		else dp[i][j][k]=(dp[i][j][k]+f2[j-i][k])%mo;
		for(int i1=1;i1<=i;i1++)f1[i1][k+i+j]=(f1[i1][k+i+j]+((dp[i][j][k]*c[n-k][j+i1])%mo)*c[n-k-j-i1][i-i1])%mo;
		for(int i1=0;i1<=j;i1++)f2[i1][k+i+j]=(f2[i1][k+i+j]+((dp[i][j][k]*c[n-k][i+i1])%mo)*c[n-k-i-i1][j-i1])%mo;
	} 
	printf("%d\n",f2[0][n]);
} 

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  string a, b, c;
  cin >> a >> b >> c;
  
  map<char, string> s = {{'a', a}, {'b', b}, {'c', c}};
  char nex = 'a';
  char cur;
  while (true) {
    if (s[nex].empty()) {
      printf("%c\n", toupper(nex));
      return 0;
    }
    cur = nex;
    nex = s[cur][0];
    s[cur] = s[cur].substr(1);
  }
}

Measured memory_bytes: 256
n=int(input())
ct=0
best=0
arr=[]
for i in range(n):
	a,b=map(int,input().split())
	if a==b:
		ct+=1
		best=max(ct,best)
	else:
		ct=0
if best>=3:
	print("Yes")
else:
	print("No")


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;})
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;})
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

typedef long long ll;
typedef pair<ll, ll> P;

struct edge { int to,cost; };

int main() {
  ll a,b,x;cin>>a>>b>>x;
  // ...o.|..o...o..|
  ll mod_a = a%x;
  ll res = 0;
  if (mod_a==0) res++;
  res += (mod_a+(b-a))/x;
  OUT(res);

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=i;j<=n;j++){
			if(i%2==0&&j%2==1){
				ans++;
			}
			else if(i%2==1&&j%2==0){
				ans++;
			}
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        //long start = System.currentTimeMillis();
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n+1];
        a[0] = -1;
        for (int i = 1;i<=n;++i) a[i] = sc.nextLong();
        sc.close();

//        System.err.println(n);
//        for (int i = 1;i<=n;++i) System.err.print(a[i] + ",");
//        System.err.println();

        long sum = 0;
        for (int i = 1;i<=n;++i)
        {
            if (a[i-1] > a[i])
            {
                long tmp = a[i-1] - a[i];
                sum += tmp;
                a[i] += tmp;
            }
        }
        System.out.println(sum);

//        long end = System.currentTimeMillis();
//        System.err.println((end-start)+"ms");
    }
}

Measured memory_bytes: 61096
# include <bits/stdc++.h>
using namespace std;
namespace Base{
	# define mr make_pair
	typedef long long ll;
	typedef double db;
	const int inf = 0x3f3f3f3f, INF = 0x7fffffff;
	const ll  infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;
	template<typename T> void read(T &x){
    	x = 0; int fh = 1; double num = 1.0; char ch = getchar();
		while (!isdigit(ch)){ if (ch == '-') fh = -1; ch = getchar(); }
		while (isdigit(ch)){ x = x * 10 + ch - '0'; ch = getchar(); }
	    if (ch == '.'){
	    	ch = getchar();
	    	while (isdigit(ch)){num /= 10; x = x + num * (ch - '0'); ch = getchar();}
		}
		x = x * fh;
	}
	template<typename T> void chmax(T &x, T y){x = x < y ? y : x;}
	template<typename T> void chmin(T &x, T y){x = x > y ? y : x;}
}
using namespace Base;

ll count(int x, int y){
	if (x == 0 || y == 0) return (y - x + 1);
	ll s2 = 1ll * x * y,
	b = x + y + __gcd(x, y),
	a2 = s2 - b + 2;
	return a2 / 2 + b;
}
ll ans, cnt;
ll solve(int W, int H, int L){
	int Lim = 2 * L + W + 1;
	ll sum = 0;
	for (int t = 1; t < H - 1; t++)
		for (int x = 1; x <= W - 1; x++){
			if (t * x >= Lim) break;
			int r = 2 * L + __gcd(W, t) - 2 - x * t;
			if (r < 0) continue;
			int y = r / W; 
			y = min(y, H - 1 - t);
			sum = sum + 4 * y;
			while (W * y <= r + W && y + 1 + t < H){
				y++;
				if (W * y - __gcd(y, x) - __gcd(W - x, y + t) <= r) sum += 4;
			}
		}
	
	int t = 0;
	for (int x = 1; x <= W - 1; x++){
			if (t * x >= Lim) break;
			int r = 2 * L + __gcd(W, t) - 2 - x * t;
			if (r < 0) continue;
			int y = r / W;	y = min(y, H - 1 - t);
			sum = sum + 2 * y;
			while (W * y <= r + W && y + 1 + t < H){
				y++;
				if (W * y - __gcd(y, x) - __gcd(W - x, y + t) <= r) sum += 2;
			}
		}
	return sum;
}
int main(){
	int W, H, L;
	read(W); read(H); read(L);
	ans = ans + solve(W, H, L);
	ans = ans + solve(H, W, L);
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}




int main() {
  int n,k;
  cin >> n >> k;
  int p[n+1];
  rep (i,n) {
    cin >> p[i];
  }
  sort(p,p+n);
  ll sum=0;
  rep (i,k){
    sum+=p[i];
  }
  cout << sum << endl;
}

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(ll i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	int n,k;
	cin>>n>>k;
	ll ans=0;
	ll low=0, high=0;
	repi(i,1,n+2){
		low+=i-1;
		high+=n-i+1;

		if(i>=k){
			ans += (high-low+1);
			ans %= mod;
		}
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>

using namespace std;

int main(){
    string w, t;
    int count = 0;

    cin >> w;
    for(int i = 0; i < w.size(); i++){
        if(w[i] >= 'A' && w[i] <= 'Z')
            w[i] += 'a' - 'A';
    }

    cin >> t;
    while(t != "END_OF_TEXT"){
        for(int i = 0; i < t.size(); i++){
            if(t[i] >= 'A' && t[i] <= 'Z')
                t[i] += 'a' - 'A';
        }
        if(w == t)
            count++;
        cin >> t;
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define lli long long int
#define DBG false
using namespace std;

int main(){
	int n;
	string s;
	cin >> n >> s;
	long long r = 0, g = 0, b = 0;
	for(int i=0; i<n; i++){
		if (s[i] == 'R') r++;
		if (s[i] == 'G') g++;
		if (s[i] == 'B') b++;
	}
 
	long long sum = r * g * b;

    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            int k = j + (j - i);
            if(k >= n) break;
            if(s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) sum--;
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 3636
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    v = list(map(int, input().split()))
    ev, od = [], []
    for i in range(n):
        if i % 2 == 0:
            ev.append(v[i])
        else:
            od.append(v[i])

    cnt_ev = sorted(Counter(ev).items(), key=lambda x: x[1], reverse=True)
    cnt_od = sorted(Counter(od).items(), key=lambda x: x[1], reverse=True)

    if len(cnt_ev) == 1 and len(cnt_od) == 1:
        if cnt_ev[0][0] == cnt_od[0][0]:
            res = n // 2
            print(res)
        else:
            res = 0
            print(res)
    elif len(cnt_ev) == 1:
        if cnt_ev[0][0] == cnt_od[0][0]:
            res = n // 2 - cnt_od[1][1]
            print(res)
        else:
            res = n // 2 - cnt_od[0][1]
            print(res)
    elif len(cnt_od) == 1:
        if cnt_ev[0][0] == cnt_od[0][0]:
            res = n // 2 - cnt_ev[1][1]
            print(res)
        else:
            res = n // 2 - cnt_ev[0][1]
            print(res)
    else:
        if cnt_ev[0][0] == cnt_od[0][0]:
            res1 = n - cnt_ev[0][1] - cnt_od[1][1]
            res2 = n - cnt_ev[1][1] - cnt_od[0][1]
            res = min(res1, res2)
            print(res)
        else:
            res = n - cnt_ev[0][1] - cnt_od[0][1]
            print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 21204
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(){
    vector<int> vec(100001,1);
    vec[0]=0;vec[1]=0;
    for(int i=2;i<=316;i++){
        if(vec[i]==0)continue;
        for(int j=i*2;j<100001;j+=i){
            vec[j]=0;
        }
    }
    for(int i=100000;i>=2;i--){
        if(vec[i]==0)continue;
        if(vec[(i+1)/2]==0)vec[i]=0;
    }
    for(int i=1;i<100001;i++){
        vec[i]+=vec[i-1];
    }
    int q,left,right;cin>>q;
    for(int i=0;i<q;i++){
        cin>>left>>right;
        cout<<vec[right]-vec[left-1]<<endl;
    }
}


Measured memory_bytes: 3700
#include <iostream>
#include <sstream>
#include <string>

/// check if (x1, y1) <-> (x2, y2) and (x3, y3) <-> (x4, y4) is crossed.
bool is_cross(double x1, double y1, double x2, double y2,
              double x3, double y3, double x4, double y4)
{
  if (((x1 - x2) * (y3 - y1) + (y1 - y2) * (x1 - x3)) *
      ((x1 - x2) * (y4 - y1) + (y1 - y2) * (x1 - x4)) > 0) {
    return false;
  } else {
    return true;
  }
}

int main()
{
  double x1, y1, x2, y2, x3, y3, xp, yp, center_x, center_y;
  while (std::cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp) {
    center_x = (x1 + x2 + x3) / 3.0;
    center_y = (y1 + y2 + y3) / 3.0;
    if (is_cross(x1, y1, x2, y2, xp, yp, center_x, center_y) ||
        is_cross(x1, y1, x3, y3, xp, yp, center_x, center_y) ||
        is_cross(x2, y2, x3, y3, xp, yp, center_x, center_y)) {
      std::cout << "NO" << std::endl;
    } else {
      std::cout << "YES" << std::endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1220