akhauriyash/Code-Regression huggingface dataset:
N = int(input())

S = input()

ans = 0


sumR = [0]
sumG = [0]
sumB = [0]

for s in S:
    if s == "R":
        sumR.append(sumR[-1] + 1)
        sumG.append(sumG[-1])
        sumB.append(sumB[-1])
    elif s == "G":
        sumR.append(sumR[-1])
        sumG.append(sumG[-1] + 1)
        sumB.append(sumB[-1])
    elif s == "B":
        sumR.append(sumR[-1])
        sumG.append(sumG[-1])
        sumB.append(sumB[-1] + 1)


for i, s in enumerate(S):
    not_cnt = 0
    for k in range(1, min(i + 1, N - i)):
        L, R = S[i - k], S[i + k]
        if s != L and s != R and L != R:
            not_cnt += 1

    cnt = 0
    if s == "R":
        cnt += sumG[i] * (sumB[-1] - sumB[i + 1])
        cnt += sumB[i] * (sumG[-1] - sumG[i + 1])
    elif s == "G":
        cnt += sumR[i] * (sumB[-1] - sumB[i + 1])
        cnt += sumB[i] * (sumR[-1] - sumR[i + 1])
    elif s == "B":
        cnt += sumG[i] * (sumR[-1] - sumR[i + 1])
        cnt += sumR[i] * (sumG[-1] - sumG[i + 1])

    cnt -= not_cnt
    ans += cnt


print(ans)

Measured memory_bytes: 68648
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 20, M = 1000000007;

int ans;

int n;
int a[(1 << N)];

int u[(1 << N)];

void dfs1(int x, int d, bool z, int p)
{
    if (!z)
    {
        if (d < n)
        {
            dfs1(x * 2, d + 1, z, (p * 1LL * x) % M);
            dfs1(x * 2 + 1, d + 1, z, (p * 1LL * x) % M);
        }
        else
        {
            dfs1((1 << (n - 1)) - 1 + a[x - (1 << (n - 1))], n, true, (p * 1LL * x) % M);
        }
    }
    else
    {
        u[x] = (u[x] + (p * 1LL * x) % M) % M;
        if (d > 1)
            dfs1(x / 2, d - 1, z, (p * 1LL * x) % M);
    }
}

void dfs2(int x, int d, bool z, int p, int s)
{
    if (!z)
    {
        if (d < n)
        {
            dfs2(x * 2, d + 1, z, (p * 1LL * x) % M, s);
            dfs2(x * 2 + 1, d + 1, z, (p * 1LL * x) % M, s);
        }
        else
        {
            dfs2((1 << (n - 1)) - 1 + a[x - (1 << (n - 1))], n, true, (p * 1LL * x) % M, s);
        }
    }
    else
    {
        ans = (ans + p * 1LL * u[x]) % M;
        ans = (ans - p * 1LL * s) % M;
        ans = (ans + M) % M;
        if (d > 1)
            dfs2(x / 2, d - 1, z, (p * 1LL * x) % M, ((u[x]) * 1LL * (x / 2)) % M);
    }
}

void dfs3(int x, int d, bool z, int p)
{
    if (!z)
    {
        if (d < n)
        {
            dfs3(x * 2, d + 1, z, (p * 1LL * x) % M);
            dfs3(x * 2 + 1, d + 1, z, (p * 1LL * x) % M);
        }
        else
        {
            dfs3((1 << (n - 1)) - 1 + a[x - (1 << (n - 1))], n, true, (p * 1LL * x) % M);
        }
    }
    else
    {
        u[x] = 0;
        if (d > 1)
            dfs3(x / 2, d - 1, z, (p * 1LL * x) % M);
    }
}

void dfs(int x, int d)
{
    if (d == n)
        return;
    dfs1(x * 2, d + 1, false, x);
    dfs2(x * 2 + 1, d + 1, false, 1, 0);
    dfs3(x * 2, d + 1, false, x);
    dfs(x * 2, d + 1);
    dfs(x * 2 + 1, d + 1);
}

void solv()
{
    scanf("%d", &n);
    for (int i = 0; i < (1 << (n - 1)); ++i)
        scanf("%d", &a[i]);
    dfs(1, 1);
    printf("%d\n", ans);
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    //ios_base::sync_with_stdio(false), cin.tie(0);
    solv();
    return 0;
}

//while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}


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

const int MAX=510000;
const int MOD=1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for (int i=2;i<MAX;i++) {
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
long long COM(int n,int k) {
    if (n<k) return 0;
    if (n<0 || k<0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
int main(){
    COMinit();
    int h,w,a,b,ans=0,ex=0,t;
    scanf("%d %d %d %d",&h,&w,&a,&b);
    t=h-a;
    for (int i=0;i<(w-b);i++) {
        ans+=(COM(t+b-1+i,t-1)*COM(a+(w-b)-2-i,a-1))%MOD;
        ans%=MOD;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 12160
import java.util.Scanner

object Main {
  def solve(sc: => Scanner): Unit = {
    val D = Array.fill[(Int, Int)](sc.nextInt)((sc.nextInt, sc.nextInt)).max
    println(D._1 + D._2)
  }


  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)

    solve(sc)
  }
}


Measured memory_bytes: 73900
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int k(long long a,long long b){
	long long c=1;
	for(long long i=1;i<=a;i++)c=(c*i)%1000000007;
	for(long long i=1;i<=b;i++)c=(c*i)%1000000007;
	return c;
}
int main(){
	long long n,m;
	cin>>n>>m;
	if(abs(n-m)==1){
		cout<<(k(n,m))%1000000007<<endl;
		return 0;
	}
	if(n==m){
		cout<<(2*k(n,m))%1000000007<<endl;
		return 0;
	}
	cout<<0<<endl;
	return 0;
}


Measured memory_bytes: 256
import heapq

def main2(l, n):
    ans = 0
    lis = []
    heapq.heapify(lis)

    for i in range(1, n):
        for j in l[i]:
            heapq.heappush(lis, j)
        while len(lis) > i:
            ans += heapq.heappop(lis)

    return ans

def main():
    from sys import stdin

    t = int(stdin.readline().strip())

    answer = []
    for _ in range(t):

        n = int(stdin.readline().strip())
        ans = 0
        l = [[] for _ in range(n+1)]
        r = [[] for _ in range(n+1)]

        for _ in range(n):
            i, j, k = map(int, stdin.readline().strip().split())
            if j > k:
                ans += j
                l[i].append(j-k)
            elif j < k:
                if i == n:
                    ans += j
                else:
                    ans += k
                    r[n-i].append(k-j)
            else:
                ans += j

        ans -= main2(l, n) + main2(r, n)
        answer.append(ans)

    for i in answer:
        print(i)

main()

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N, K; cin >> N >> K;
	set<int> st;
	for (int i = 0; i < K; i++) {
		int d; cin >> d;
		for (int i = 0; i < d; i++) {
			int a; cin >> a;
			st.insert(a);
		}
	}
	cout << N - st.size() << '\n';
	return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int A, B; cin >> A >> B;
    if (A > B) swap(A,B);
    if ((abs(B-A) % 2) == 0) {
        cout << (A + (B-A)/2) << '\n';
    }
    else {
        cout << "IMPOSSIBLE\n";
    }
}



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

using namespace std;

int n, cnt, mx;
int a[100005];

int main()
{
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
        if(a[i] <= a[i - 1]) cnt++;
        else mx = max(mx, cnt), cnt = 1;
    }
    mx = max(mx, cnt);
    printf("%d", mx - 1);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << -1 << endl;return 0
#define Endl endl


signed main(void){
    string L;
    cin >> L;
    int N=L.size();
    int Ans=1;
    int T=1;
    REP(i,N){
        if(L[N-i-1]=='1'){
            Ans=(2*Ans)%MOD;
            Ans=(Ans+T)%MOD;
        }
        T=(3*T)%MOD;
    }
    cout << Ans << endl;
    return 0;
}



Measured memory_bytes: 512
package main

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

func main() {
	var n, m int
	fmt.Scan(&n)
	fmt.Scan(&m)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	a := make([]int, n, n)
	l := make([]int, n, n)

	for i := 0; i < n; i++ {
		sc.Scan()
		b, _ := strconv.Atoi(sc.Text())

		j := 1
		for b&j == 0 {
			j <<= 1
		}
		l[i] = j
		a[i] = b
	}

	answer := -1
	for i := 0; i < n; i++ {
		if l[i] == 1 || l[i] != l[0] {
			answer = 0
		}
	}

	if answer != 0 {
		semilcm := int64(a[0]) / 2
		for i := 1; i < n; i++ {
			semilcm = lcm(semilcm, int64(a[i])) / 2
			if semilcm > int64(m) {
				answer = 0
				break
			}
		}
		answer = (m/int(semilcm) + 1) / 2
	}

	fmt.Println(answer)
}

func gcd(n1 int64, n2 int64) int64 {
	if n1%n2 == 0 {
		return n2
	}
	return gcd(n2, n1%n2)
}

func lcm(n1 int64, n2 int64) int64 {
	return n1 / gcd(n1, n2) * n2
}


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


void solve(long long x, long long a, long long b){
    if(abs(x-a) < abs(x-b)) cout << "A" << endl;
    else cout << "B" << endl;
}

int main(){
    long long x;
    scanf("%lld",&x);
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    solve(x, a, b);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int W,H,x,y,r;
    scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
    if(0<!W||0<!H||r>100||x<0||y<0){
        printf("No\n");
    }else if(x+r<=W&&y+r<=H){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
    int N, A; cin >> N >> A;
    cout << (N%500 > A ? "No" : "Yes") << endl;
}



Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.InputStream;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author MaxHeap
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    ACurtain solver = new ACurtain();
    solver.solve(1, in, out);
    out.close();
  }

  static class ACurtain {

    public void solve(int testNumber, InputReader in, PrintWriter out) {
      int n = in.nextInt();
      int b = in.nextInt() << 1;
      out.println(Math.max(0, n - b));
    }

  }

  static interface FastInput {

  }

  static class InputReader implements FastInput {

    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer;
    private int bytesRead;

    public InputReader(InputStream is) {
      din = new DataInputStream(is);
      buffer = new byte[BUFFER_SIZE];
      bufferPointer = bytesRead = 0;
    }

    public InputReader(String file_name) throws IOException {
      din = new DataInputStream(new FileInputStream(file_name));
      buffer = new byte[BUFFER_SIZE];
      bufferPointer = bytesRead = 0;
    }

    public int nextInt() {
      int ret = 0;
      byte c = read();
      while (c <= ' ') {
        c = read();
      }
      boolean neg = (c == '-');
      if (neg) {
        c = read();
      }
      do {
        ret = ret * 10 + c - '0';
      } while ((c = read()) >= '0' && c <= '9');

      if (neg) {
        return -ret;
      }
      return ret;
    }

    private void fillBuffer() {
      try {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
      } catch (IOException e) {
        throw new RuntimeException("trying to read from null input, verify constraints ");
      }
      if (bytesRead == -1) {
        buffer[0] = -1;
      }
    }

    private byte read() {
      if (bufferPointer == bytesRead) {
        fillBuffer();
      }
      return buffer[bufferPointer++];
    }

  }
}



Measured memory_bytes: 23124
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
	long long  n, a, b;
	scanf("%lld %lld %lld", &n, &a, &b);
	printf("%lld\n", max(1LL * 0, ((n - 1)*b + a) - ((n - 1)*a + b - 1)));
	return 0;
}

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

int main() {
  int N, K, sum=0;
  cin >> N >> K;
  
  for (int i=0; i<N; i++) {
    int x;
    cin >> x;
    
    if (x <= (K-x)) {
      sum += 2*x;
    }
    else {
      sum += 2*(K-x);
    }
  }

  cout << sum << endl;
}

Measured memory_bytes: 3628
K = int(input())
a = []
dp = [[[] for i in range(10)] for j in range(100)]
for i in range(10):
  dp[0][i] = [i]
  if i != 0:
    a.append(i)
for i in range(1, 10):
  for j in range(10):
    if j != 0:
      for k in dp[i-1][j-1]:
        dp[i][j].append(k + 10 ** i * j)
        a.append(k + 10 ** i * j)
    for k in dp[i-1][j]:
      dp[i][j].append(k + 10 ** i * j)
      if j != 0:
        a.append(k + 10 ** i * j)
    if j != 9:
      for k in dp[i-1][j+1]:
        dp[i][j].append(k + 10 ** i * j)
        if j != 0:
          a.append(k + 10 ** i * j)
print(a[K-1])


Measured memory_bytes: 21120
/* Author: Dhruv Rastogi */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
const long double PI = acos(-1.0);

const int N=1e5+4;
int valid[N];
int dp[N];
void solve(){
	int n;
	cin>>n;
	dp[0]=1;
	memset(valid,1,sizeof valid);
	int m;
	cin>>m;
	rep(i,0,m){
		int x;
		cin>>x;
		valid[x]=0;
	}
	rep(i,0,n){
		if(valid[i]){
			dp[i]%=hell;
			dp[i+1]+=dp[i];
			dp[i+2]+=dp[i];
		}
	}
	cout<<dp[n]%hell<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 1792
from functools import reduce
mod = 10**9+7

def P(n, k):
  return reduce(lambda x, y:x*y%mod, range(n-k+1, n+1))

def factorial(n):
  return P(n, n)

def C(n, k):
  k = min(k, n-k)
  if k == 0:
    return 1
  else:
    return (P(n, k)*pow(factorial(k), mod-2, mod))%mod

X, Y = map(int, input().split())
if (X+Y)%3 == 0:
  n = Y-(X+Y)//3
  m = X-(X+Y)//3
  if n < 0 or m < 0:
    print(0)
  else:
    print(C(n+m, n))
else:
  print(0)

Measured memory_bytes: 38980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef std::pair<int, int> ii;
typedef tuple<int,int,int> i3;
typedef std::pair<int, ii> iii;
typedef std::vector<int> vi;
typedef std::vector<vi> vvi;
typedef std::vector<ii> vii;
typedef std::vector<iii> viii;
const int INF=10000000;
#define pb(a) push_back(a)
#define m0(x) memset(x,-1,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);  // greater than or equal
#define ub(v,n) upper_bound(v.begin(), v.end(), n);  // greater than
#define all(x) (x).begin(), (x).end()
vector<string> temp(15);
vector<string> g(15);
string finalans="NO";
int h,w;
int hi=0;


void printy(vector<string> &temp){
  for (auto i: temp) cerr<<i<<endl;
    cerr<<"-----------------"<<endl;
}

void check(vector<string> &temp){
  set<int> avail;
  for (int i=0; i<w; i++) avail.insert(i);
  for (int i=0; i<w-1; i++){
    for (int j=i+1; j<w; j++){
      if (avail.find(i)!=avail.end() and avail.find(j)!=avail.end()){
        bool ans=true;
        for (int k=0; k<h; k++){
          if (temp[k][i]!=temp[h-k-1][j]) ans=false;
        }
        if (ans) {
          avail.erase(i);
          avail.erase(j);
        }
      }

    }
  }
  vector<int> test;
  for (auto i: avail) test.pb(i);
  if (test.size()==1 and w%2==1){
    bool ans=true;
    for (int i=0; i<h; i++){
      if (temp[i][test[0]]!=temp[h-1-i][test[0]]) ans=false;
    }
    if (ans) finalans="YES";
  }
  else if (test.size()==0) finalans="YES";




}




void play(vector<string> &temp){
  // hi++;
  //printy(temp);
  check(temp);
}


void perm(int n, set<int> &avail){

  if (n==-1){
    vector<int> tempy;
    for (auto i: avail) tempy.push_back(i);
    for (int i: tempy){
      temp[(h+1)/2-1]=g[i];  //0 1 2 3 4    n=5
      avail.erase(i);
      perm(n+1,avail);
      avail.insert(i);
    }
  }

  else if (n==h/2-1) {
    vector<int> tempy;
    for (auto i: avail) tempy.push_back(i);
    temp[n]=g[tempy[0]];
    temp[h-1-n]=g[tempy[1]];
    play(temp);
  }

  else {
    vector<int> tempy;
    int siz=0;
    for (auto i: avail) {tempy.push_back(i); siz++;}
        int a=0;
        int i=tempy[a];
        avail.erase(i);
        for (int b=a+1; b<siz; b++){
          int j=tempy[b];
          temp[n]=g[i];
          temp[h-1-n]=g[j];
          avail.erase(j);
          perm(n+1,avail);
          avail.insert(j);
        }
        avail.insert(i);
  }
}


bool is_palindrome(string s, int n){
  for (int i=0; i<n; i++){
    if (s[i]!=s[n-1-i]) return false;
  }
  return true;
}




int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> h >> w;
  set<int> avail;
  for (int i=0; i<h; i++) {cin >> g[i]; avail.insert(i);}
  if (h!=1){
    int t=0;
    if (h%2==1) t=-1;
    perm(t,avail);
   
  }
  else {
    check(g);
  }
  
cout<<finalans<<endl;
    cerr<<hi;




}


Measured memory_bytes: 3668
#coding:utf-8
from collections import deque
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = True

def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]


    s = input()

    a = {"SUN": 7,"MON": 6,"TUE":5 ,"WED":4,"THU":3,"FRI":2,"SAT":1}
    print(a[s])




if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include<iostream>
#include<string>
#include<complex>
char map[3][3]={'A','B','C','D','E','F','G','H','I'};
using namespace std;
int main(){
 string a;
 for(int u=0;u<1000;u++){
     cin>>a;
     bool ok=true;
     int ax,ay,bx,by;
     for(int i=0;i<3;i++)for(int j=0;j<3;j++)if(map[i][j]==a[0])bx=j,by=i;
     for(int k=1;k<a.size();k++){
         for(int i=0;i<3;i++)for(int j=0;j<3;j++)if(map[i][j]==a[k])ax=j,ay=i;
         int x=abs(ax-bx),y=abs(ay-by);
         if(!(x*y==0&&x+y==1))ok=false;
         bx=ax,by=ay;
     }
     if(ok)cout<<a<<endl;
 }
 return 0;
}

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

int main()
{
    int n, k;
    cin>>n>>k;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    int cnt = 0;
    rep(i,n)if(h[i]>=k)cnt++;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 640
n,m,q=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
L=[[0 for i in range(n)] for j in range(n)]
L2=[[0 for i in range(n+1)] for j in range(n+1)]
for i in range(m):
  L[l[i][0]-1][l[i][1]-1]+=1
for i in range(1,n+1):
  for j in range(1,n+1):
    L2[i][j]=L2[i][j-1]+L[i-1][j-1]
for j in range(1,n+1):
  for i in range(1,n+1):
    L2[i][j]=L2[i-1][j]+L2[i][j]

p=[list(map(int,input().split())) for i in range(q)]
for i in range(q):
  print(L2[p[i][1]][p[i][1]]-L2[p[i][1]][p[i][0]-1]-L2[p[i][0]-1][p[i][1]]+L2[p[i][0]-1][p[i][0]-1])

Measured memory_bytes: 111192
// 2020.4.17

#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <stdlib.h>
#include <cstdio>

using namespace std;

int D, G;
int p[10], c[10];
// char use[10];

int dfs(int i, string use) {
    if (i == D) {
        // ...
        // cout << use << endl;

        int g = G;
        int ans = 0;

        for (int a = D - 1; a >= 0; a--) {
            if (use[a] == 't') {
                for (int b = 0; b < p[a]; b++) {
                    // printf("a: %d, b: %d\n", a, b);
                    g -= 100 * (a + 1);
                    ans += 1;

                    if (g <= 0) {
                        return ans;
                    }
                }

                g -= c[a];
                if (g <= 0) {
                    return ans;
                }
            }
        }

        return 1001;
    }

    // p[i]を使う場合。
    use[i] = 't';
    int min1 = dfs(i + 1, use);

    // p[i]を使わない場合。
    use[i] = 'f';
    int min2 = dfs(i + 1, use);

    return min(min1, min2);
}

int main() {
    cin >> D >> G;
    for (int i = 0; i < D; i++) {
        cin >> p[i] >> c[i];
    }

    // int ans = 10000;

    // for (int i = D - 1; i >= 0; i--) {
    //     int g = G;
    //     int an = 0;
    //     int clear = false;

    //     // 上から引いていく。
    //     for (int j = i; j >= 0; j--) {
    //         for (int k = 0; k < p[j]; k++) {
    //             // printf("i: %d, j: %d, k: %d, g: %d\n", i, j, k, g);

    //             g -= 100 * (j + 1);
    //             an += 1;

    //             if (g <= 0) {
    //                 ans = min(ans, an);
    //                 clear = true;
    //                 break;
    //             }
    //         }

    //         // ループの途中でクリアした場合はぬける
    //         if (clear == true) {
    //             break;
    //         }

    //         // そうでないときはクリア報酬
    //         g -= c[j];
    //         // クリア報酬を引いてクリアした場合は抜ける
    //         if (g <= 0) {
    //             ans = min(ans, an);
    //             clear = true;
    //             break;
    //         }
    //     }
    // }

    int ans = dfs(0, "ffffffffff");

    cout << ans << endl;
}


Measured memory_bytes: 256
//
//  main.c
//  practice
//
//  Created by 松田拓人 on 2018/10/23.
//  Copyright © 2018年 松田拓人. All rights reserved.
//

#include <stdio.h>

int main(void){
    int n, m, l;
    int j, q, k;
    long int a[101][101] = {}, b[101][101] = {}, c[101][101] = {};
    //縦＊横　n * m、　m * l  Cnl = Ank * Bkl; k= 1 ~ m;
    
    scanf("%d %d %d", &n, &m, &l);
    for(j = 0; j < n; j++){
        for(q = 0; q < m; q++){
            scanf(" %ld", &a[j][q]);
        }
    }
    for(j = 0; j < m; j++){
        for(q = 0; q < l; q++){
            scanf(" %ld", &b[j][q]);
        }
    }
    
    for(j = 0; j < n; j++){
        for(q = 0; q < l; q++){
            for(k = 0; k < m; k++){
                c[j][q] += a[j][k] * b[k][q];
            }
        }
    }
    
    for(j = 0; j < n; j++){
        for(q = 0; q < l; q++){
            printf("%ld", c[j][q]);
            if(q < l - 1)
                printf(" ");
        }
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2140
s = input()
t = input()
lt = len(t)
ls = len(s)
li = []
if ls < lt:
    ans = "UNRESTORABLE"
else:
    for i in range(ls-lt+1):
        subs = s[i:i+lt]
        for c,d in zip(subs,t):
            if c == d or c == "?":
                continue
            else:
                break
        else:
            li.append((s[0:i]+t+s[i+lt:]).replace("?","a"))
    li.sort()
    ans = li[0] if li else "UNRESTORABLE"
print(ans)

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

int main() {
  ll N;
  cin>>N;
  cout<<2*N*3.1415<<endl;
}


Measured memory_bytes: 3784
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define all(a) (a).begin(), (a).end()


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

    string S;
    cin >> S;
    int count = 0;
    for(char x : S){
        if(x == '+')count++;
        else count--;
    }
    cout << count << endl;
}


Measured memory_bytes: 3584
#include <iostream>

using namespace std;

int main(void){
 
  int H, W, N;
  
  cin >> H >> W >> N;
  
  int a[N];
  
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }
    
  int field[H * W];
  
  int col = 1;
  
  for (int i = 0; i < H; i++){
    for (int j = i % 2 == 0 ? 0 : W - 1; i % 2 == 0 ? j < W : j >= 0;
         i % 2 == 0 ? j++ : j--){
      field[i * W + j] = col;
      if (--a[col - 1] == 0){
        col++;
      }
    }
  }
  
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      if (j > 0) {
        cout << " ";
      }
      cout << field[i * W + j]; 
    }
    cout << endl;
  }
  
  return 0;
  
}

Measured memory_bytes: 384
use proconio::*;
#[allow(unused_imports)]
use proconio::marker::*;

#[fastout]
#[allow(non_snake_case)]
fn main() {
    input! {
        X: i32, N: usize,
        p: [i32; N],
    }
    let mut ans = 1000;
    if X < 1 || X > 100 {
        ans = X;
    } else {
        for i in 0..=101 {
            if p.contains(&i) {
                continue;
            }
            if (X - i).abs() < (X - ans).abs() {
                ans = i;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2200
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BBalance solver = new BBalance();
        solver.solve(1, in, out);
        out.close();
    }

    static class BBalance {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int a[] = new int[n];
            int tot = 0;
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
                tot += a[i];
            }
            int curr = 0;
            int ans = Integer.MAX_VALUE;
            for (int i = 0; i < n; i++) {
                curr += a[i];
                ans = Math.min(ans, Math.abs(curr - (tot - curr)));
            }
            out.println(ans);

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21460
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		long ans=0;
		for(int i = 1;i<=n;i++) {ans+=Ap(i,i,n/i);}
		Console.WriteLine("{0}",ans);
	}
	static long Ap(long a,long d,long n){return (n*((a<<1)+(n-1)*d))>>1;}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 27192
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a,b,c,d;
    double e,f,g;
    cin>>a>>b;
    g=a;
    f=b;
    c=a/b;
    d=a%b;
    e=(double)a/(double)b;
    cout<<c<<" "<<d<<" "<<fixed<<setprecision(10)<<e<<endl;
}


Measured memory_bytes: 3288
import sys
import numpy as np
from scipy.sparse.csgraph import floyd_warshall

def main():
    input = sys.stdin.readline
    N, M = map(int, input().split())

    INF = 10**6
    A = np.array([[INF for _ in range(N)] for _ in range(N)])
    for i in range(N):
        A[i][i] = 0

    edges = []
    for _ in range(M):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        A[a][b] = c
        A[b][a] = c
        edges.append((a, b, c))

    G = floyd_warshall(A)

    ans = 0
    for a, b, c in edges:
        if G[a][b] < c:
            ans += 1

    return ans


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 19188
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fr(i,a,n) for(i=a;i<n;i++)
#define frn(i,a,n) for(i=a;i<=n;i++)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vp vector<pll>
#define ub upper_bound
#define lb lower_bound
//#define map map<ll,ll>
#define mem(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(),v.end()
#define bs binary_search
#define qll queue<ll>
#define sll set<ll>
#define ma 500000
/*ll power(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return power(x*x,n/2);
    else                             //n is odd
        return x*power(x*x,(n-1)/2);
}*/

/*void decToBinary(ll n)
{
    string s;
int binaryNum[32];
int i = 0;
while (n > 0) {
binaryNum[i] = n % 2;
n = n / 2;
i++;
}
for (int j = i - 1; j >= 0; j--) {
 char c = binaryNum[j] +'0';
 s=s+c;
}
 
 //cout<<s<<endl;
 
 
 
 // for (int j = i - 1; j >= 0; j--)
 // cout<<s[j];
 
sort(s.begin(), s.end());
do {
cout << s << endl;
} while (next_permutation(s.begin(), s.end())); */
int highestPowerof2(int n)
{
   int p = (int)log2(n);
   return (int)pow(2, p);  
}
ll mindig(ll n){
ll x;
ll ans=mod;
 while(n>0)
        {
            x=n%10;
            ans=min(ans,x);
            n=n/10;
        }
        return ans;
}
ll maxdig(ll n)
{
    ll x;
    ll ans1=-1;
         while(n>0)
        {
            x=n%10;
            ans1=max(ans1,x);
            n=n/10;
        }
        return ans1;
}
 ll power(ll x, ll y, ll p)  
{  
    ll res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}  
 
int main()
{
    fastio;

        string s;
        cin>>s;
        ll n=s.length();
        
        if(s[n-1]=='2'||s[n-1]=='4'||s[n-1]=='5'||s[n-1]=='7'||s[n-1]=='9')
        cout<<"hon"<<endl;
        else if(s[n-1]=='3')
        cout<<"bon"<<endl;
        else if(s[n-1]=='0'||s[n-1]=='1'||s[n-1]=='6'||s[n-1]=='8')
        cout<<"pon"<<endl;
}



Measured memory_bytes: 3676
require "set"

n = gets.to_i
m = 10**6
a = gets.split.map(&:to_i).sort
num = a.tally
seen = Set.new # 倍数消込

ans = 0
a.each do |i|
  next unless num[i]
  next if seen === i
  ans += 1 if num[i] == 1

  i.step(m, i) do |j|
    seen << j
  end
end
puts ans



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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
st = [input().split() for _ in range(n)]
x = input()
flg = False
ans = 0
for s,t in st:
    if flg:
        ans += int(t)
    if s == x:
        flg = True
print(ans)

Measured memory_bytes: 38256
n = int(input())
a = list(map(int, input().split()))
count = 0
odd = 0
while odd == 0:
    for i in range(len(a)):
        if a[i] % 2 == 0:
            a[i] = a[i] // 2
        else:
            odd += 1
    count+=1

print(count-1)   

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

int main() {
  int A,B;
  cin >> A >> B;
  if ((A + B) % 2 == 1) {
    cout << (A + B) / 2 + 1 << endl;
  }
  else {
    cout << (A + B) / 2 << endl;
  }
}



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

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	ll a,b,c;
	cin >> N;
	for(a=1;a<=3500;a++){
		for(b=1;b<=3500;b++){
			ll x = (4*a*b - N*a - N*b);
			if(x>0 && N*a*b%x==0){
				c = (N*a*b)/x;
				cout << a <<" "<< b <<" "<< c << endl;
				return 0;
			}
			
		}
	}
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const ll MOD = 1000000007;
// const int INF = 2000000000;

ll N, A, B, DIFF;
vector<ll> h;

bool killed(ll cnt) {
  ll tmp_cnt = cnt;
  for (auto e : h) {
    e -= (B * cnt);
    if (e <= 0) {
      continue;
    }

    if (e % DIFF == 0) {
      tmp_cnt -= (e / DIFF);
    } else {
      tmp_cnt -= (e / DIFF + 1);
    }
  }
  if (tmp_cnt < 0) {
    return false;
  }
  return true;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> A >> B;
  DIFF = A - B;
  h.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }
  sort(h.begin(), h.end());

  ll l = 0, r = h[N - 1] + 1;
  while (r - l > 1) {
    ll mid = l + (r - l) / 2;
    if (killed(mid)) {
      r = mid;
    } else {
      l = mid;
    }
  }

  cout << r << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <map>
#include <queue>
#include <deque>
#include <set>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define FOR(i,a,b) for (ll i = (a) ; i <= (b); ++i)
#define RFOR(i,a,b) for (ll i = (a) ; i >= (b); --i)
#define all(x) (x).begin(), (x).end()
//#define repitr(itr, st) for(auto itr = st.begin(); itr != st.end(); ++itr)
#define P_B push_back
#define PO_B pop_back
#define E_B emplace_back
#define M_P make_pair
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << endl
//#define print(x) printf("%d\n", x)

using namespace std;
using ll = long long;
using Pii = pair<int,int>;
using Pll = pair<ll,ll>;
using VI = vector<int>;
using VL = vector<ll>;
using VVI = vector<vector<int> >;
using VVL = vector<vector<ll> >;
//int dx[4] = {1, 0, -1, 0};
//int dy[4] = {0, 1, 0, -1};
//const ll LINF = (ll)1e18 - 1;
//const int INF = 1e9 - 1;
//int:±2*10^9くらい　ll:±9*10^18くらい


void Main(){
	string S;
	ll l, r, p, n;
	cin >> S;
	n = S.size();
	VI ans(n, 0);

	r=0;
	rep(i, n){
		if(S[i] == 'L' && r != -1){
			ans[i] = (i-r)/2;
			ans[i-1] = (i-r)/2 + (i-r)%2;
			r = -1;
		}else if(S[i] == 'R' && r == -1){
			r = i;
		}
	}

	l = n-1;
	RFOR(i, n-1, 0){
		if(S[i] == 'R' && l != -1){
			ans[i] += (l-i)/2;
			ans[i+1] += (l-i)/2 + (l-i)%2;
			l = -1;
		}else if(S[i] == 'L' && l == -1){
			l = i;
		}
	}

	rep(i, n){
		cout << ans[i] << " ";
	}
	cout << endl;




}

int main()
{
	cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();

  return 0;
}


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

int main()
{
	int N;
	cin >> N;
	vector<int> B( N - 1 );
	for( int i = 0; i < N - 1; i++ ) {
		cin >> B[i];
	}

	vector<int> A( N );
	for( int i = 0; i < N; i++ ) {
		if( i == 0 ) A[i] = B[i];
		else if( i == N - 1 ) A[i] = B[N - 2];
		else A[i] = min( B[i], B[i - 1] );
	}
	long long ans = 0;
	for( int i = 0; i < N; i++ ) {
		ans += A[i];
	}

	cout << ans << endl;
}


Measured memory_bytes: 3612
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    if op == '?':
        break
    elif op == '+':
        print(a + b)
    elif op == '-':
        print(a - b)
    elif op == '*':
        print(a * b)
    elif op == '/' and b != 0:
        print(a // b)
    else:
        None


Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
#define MAX 3000
int dp[MAX + 1][MAX + 1];
string getLCS(string& s, string& t, int len){
	string lcs;
	int i = 0, j = 0;
	while(len > 0){
		if(s[i] == t[j]){
			lcs.push_back(s[i]);
			len--;
			i++;
			j++;
		}
		else{
			if(dp[i][j+1] > dp[i+1][j])j++;
			else i++;
		}
	}
	return lcs;
}

int lenLCS(string& s, string& t, int i, int j)
{
	if(i >= s.size() or j >= t.size())return 0;
	if(dp[i][j] != -1)return dp[i][j];
	if(s[i] == t[j]){
		return dp[i][j] = 1 + lenLCS(s, t, i + 1, j + 1);
	}
	else{
		return dp[i][j] = max(lenLCS(s, t, i, j + 1),lenLCS(s, t, i + 1, j));
	}
}
string solve(string& s, string& t)
{
	memset(dp, -1, sizeof dp);
	int len = lenLCS(s, t, 0, 0);
	return getLCS(s, t, len);
}
int main()
{
	string s, t;
	cin >> s >> t;
	cout << solve(s, t);
	return 0;
}

Measured memory_bytes: 39212
N,A,B,C,D = map(int, input().split())
A -= 1
B -= 1
C -= 1
D -= 1
s = str(input())
if C < D:
    if "##" in s[A:C] or "##" in s[B:D]:
        print("No")
    else:
        print("Yes")
else:
    if "##" in s[A:C] or "##" in s[B:D]:
        print("No")
    else:
        if D-B >= 2:
            if "..." in s[B-1:D+1]:
                print("Yes")
            elif s[D-1] == ".":
                print("Yes")
            else:
                print("No")
        else:
            if s[B+2] == "." or s[B-1] == ".":
                print("Yes")
            else:
                print("No")

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
using namespace std;
int n;
long c,x[1<<17],v[1<<17];
main()
{
	cin>>n>>c;
	long ans=0,L=0,R=0,Rmax=0;
	for(int i=0;i<n;i++)
	{
		cin>>x[i]>>v[i];
		L+=v[i];
	}
	ans=L-x[n-1];
	for(int i=n;i--;)
	{
		L-=v[i];
		R+=v[i];
		Rmax=max(Rmax,R-(c-x[i]));
		ans=max(ans,L-(i?x[i-1]*(Rmax?2:1):0)+Rmax);
	}
	long Lmax=0;
	for(int i=0;i<n;i++)
	{
		L+=v[i];
		R-=v[i];
		Lmax=max(Lmax,L-x[i]);
		ans=max(ans,R-(i!=n-1?(c-x[i+1])*(Lmax?2:1):0)+Lmax);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
	public Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		while(sc.hasNext()){
			new AOj0017().doIt();
		}
	}
	class AOj0017{
		void doIt(){
			String text = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";
			String input = sc.nextLine();
			for(int i=0;i<=26;i++){//?????????
				StringBuffer sb = new StringBuffer("");
				for(int s=0;s<input.length();s++){
					if(input.charAt(s) != ' ' && input.charAt(s) != '.'){
						int index = textIndex(input.charAt(s));
						sb.append(text.charAt(index + i));
					}else sb.append(input.charAt(s));
//					System.out.println(sb.toString());
				}
				if(isOk(sb.toString()) == true){
					System.out.println(sb.toString());
					if(i == 0)break;
				}
			}
		}
		
		boolean isOk(String t){
			String[] str = t.split(" ");
			for(int i = 0;i < str.length;i++){
				if(str[i].equals("this") || str[i].equals("that") || str[i].equals("the")){
					return true;
				}
			}
			return false;
		}
		
		int textIndex(char c){
			String text = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";
			for(int i=0;i<text.length();i++)if(c == text.charAt(i))return i;
			return -1;
		}
		
	}
}

Measured memory_bytes: 19588
#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define SREP(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTF(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define NMAX 1e9

typedef long long ll;
int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int a, int b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}
ll Sqrt(ll n) {
	ll s = n;
	ll x = s / 2;
	while (x > NMAX) {
		x /= 2;
	}
	while(1) {
		x = (x + s / x) / 2;
		if (x*x <= s)break;
	}
	return x;
}

int main() {
	int n,m,x;
	scanf("%d %d %d", &n, &m, &x);
	int a[101] = { 0 };
	REP(i, m) {
		scanf("%d", &a[i]);
	}
	int l = 0, r = 0;
	REP(i, m) {
		if (a[i]<x) {
			l++;
		}
		else {
			r++;
		}
	}
	PRINTD(Min(l, r));
}

Measured memory_bytes: 128
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int main() {
    fastio();

    ll a, b, v, w, t;

    cin >> a >> v >> b >> w >> t;

    ll d = abs(a - b);

    ll x = v - w;

    if (d <= x * t) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }

    return 0;
}

Measured memory_bytes: 3652
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    private static void solver(InputReader sc, PrintWriter out) {
            int n  =sc.nextInt();
            int m = sc.nextInt();
        long ans = (m * (m-1)) /2  ;
        ans += (n*(n-1))/2;
        out.println(ans);
    }

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        solver(in, out);
        out.close();
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}


Measured memory_bytes: 22740