akhauriyash/Code-Regression huggingface dataset:
integer N,A,NA
integer,allocatable,dimension(:)::X
integer(16),allocatable,dimension(:,:,:)::DP
integer(16) ans
read*,N,A
allocate(X(N))
NA=N*A
read*,X
allocate(DP(0:N,0:N,0:50*N))
DP=0
DP(0,0,0)=1
do i=1,N
  do j=0,i
    do k=0,NA
      if(k<x(i).or.j==0)then
        DP(i,j,k)=DP(i-1,j,k)
      else
        DP(i,j,k)=DP(i-1,j,k)+DP(i-1,j-1,k-x(i))
      end if
    end do
  end do
end do

ans=0
do i=1,N
  ans=ans+DP(N,i,i*A)
end do

print"(i0)",ans

end


Measured memory_bytes: 101888
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>

long n, m;

long s[10];//ith bulb
long p[10];

void binlook(long i){
	std::stack<long> st;
	while(i){
		st.push(i%2);
		i /= 2;
	}
	while(!st.empty()){
		printf("%ld", st.top());
		st.pop();
	}
	printf("\n");
	return;
}

int main(){
	scanf("%ld%ld", &n, &m);
	for(int i = 0; i < m; i++){
		long k;
		scanf("%ld", &k);
		for(int j = 0; j < k; j++){
			long a;
			scanf("%ld", &a);
			s[i] |= (1l << (a-1));
		}
		//printf("%ld ", i);
		//binlook(s[i]);
	}
	//printf("\n");
	
	for(int i = 0; i < m; i++){
		scanf("%ld", &p[i]);
	}
	
	long ans = 0;
	for(long i = 0; i < (1 << n); i++){
		bool flag = true;
		for(long j = 0; j < m; j++){
			long cnt = 0;
			for(long k = 0; k < n; k++){
				if((i & s[j]) & (1 << k)){
					cnt++;
				}
			}
			if(cnt % 2 !=  p[j]){
				flag = false;
			}
		}
		//binlook(i);
		//printf("  %ld\n", flag);
		if(flag){
			ans++;
		}
	}
	printf("%ld\n", ans);
}


Measured memory_bytes: 256
#include<stdio.h>
long step;
long enclidean(long a, long b){
                step++;
                long c;
                c = a%b;
                if(c)return enclidean(b,c);
                else return b;
}
int main(){
        long a,b,c;

        while(scanf("%ld %ld",&a,&b), a+b != 0L){
                step = 0;
                if (a > b)
                        c = enclidean(a,b);
                else
                        c = enclidean(b,a);
                printf("%d %d\n",c,step);
        }
        return 0;
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int G[210][210],r[10],vis[210],n,m,R,a,b,c;
ll dis[210][210],s,ans=1000000000000;
void dfs(int k,int done)
{
	if(done==R)
	{
		ans=min(ans,s);
		return;
	}
	if(s>=ans) return;
	for(int i=1;i<=R;i++)
	{
		if(!vis[r[i]])
		{
			s+=dis[r[k]][r[i]];
			vis[r[i]]=1;
			dfs(i,done+1);
			s-=dis[r[k]][r[i]];
			vis[r[i]]=0;
		}
	}
}
int main()
{
	scanf("%d%d%d",&n,&m,&R);
	for(int i=1;i<=R;i++) scanf("%d",&r[i]);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d%d",&a,&b,&c);
		G[a][b]=G[b][a]=c;
	}
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++) 
	{
		dis[i][j]=100000000000;
		if(G[i][j]) dis[i][j]=G[i][j];
	}
	for(int k=1;k<=n;k++)
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)
	if(dis[i][j]>dis[i][k]+dis[k][j])
	dis[i][j]=dis[i][k]+dis[k][j];
	for(int i=1;i<=R;i++)
	{
		memset(vis,0,sizeof(vis));
		s=0;vis[r[i]]=1;
		dfs(i,1);
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main(){
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  int ans = (h2 - h1) * 60 + (m2 - m1);
  ans -= k;
  cout << max(0,ans) << endl;
}

Measured memory_bytes: 3632
// AtCoder165 C

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <string.h>
#include <memory.h>
#include <malloc.h>
#include <stdlib.h>
#include <ctype.h>

// qsortで用いる比較用関数．*a<*bならaが先になる．
int compare(const void* a, const void* b) {
    return *(int*)a - *(int*)b;
}

int revcompare(const void* a, const void* b) {
    return *(int*)b- *(int*)a;
}

double dmax(double x, double y){
    if(x < y) return y;
    return x;
}

int main() {
    int i,j;
    int n;

    int A,B,M;
    int* a;
    int* b;


    int mina = 100000;
    int minb = 100000;

    scanf("%d %d %d", &A, &B, &M);
    
    a = (int*)malloc(sizeof(int)*A);
    b = (int*)malloc(sizeof(int)*B);
    for(i = 0; i < A; i++){
        scanf("%d", a+i);
        if(mina > *(a+i)) mina = *(a+i);
    }

    for(i = 0; i < B; i++){
        scanf("%d", b+i);
        if(minb > *(b+i)) minb = *(b+i);
    }

    int sum = mina + minb;

    // printf("%d\n", sum);
    int x,y,c;
    for(i=0;i<M;i++){
        scanf("%d %d %d", &x,&y,&c);
        if(a[x-1]+b[y-1]-c < sum) sum = a[x-1]+b[y-1]-c;
    }
    printf("%d", sum);

    return 0;

}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main(){
        vector<int> vec(3); 
        cin >> vec.at(0) >> vec.at(1) >> vec.at(2);
    sort(vec.begin(), vec.end());
 
    for (int i = 0; i < vec.size(); i++) {
       if(i==2){
        cout << vec.at(i) << endl;
       break;
       }
       cout << vec.at(i) << " "; 
        }
} 



Measured memory_bytes: 3156
a,b,c,d,e = map(int,input().split())

L = []
L.append(a)
L.append(b)
L.append(c)
L.append(d)
L.append(e)

cnt = 1
for i in L:
  if i == 0:
    print(cnt)
  else:
    cnt += 1

Measured memory_bytes: 9184
n = gets.to_i
tmp = 0
h = Hash.new(0)
h[0] = 1

gets.split.map(&:to_i).each do |e|
  tmp += e
  h[tmp] += 1
end

sum = 0
h.values.each { |v| sum += v * (v - 1) }

puts sum / 2

Measured memory_bytes: 30596
unittest
{
	assert( [ "issii", "2" ].parse.expand.solve == 4 );
	assert( [ "qq", "81" ].parse.expand.solve == 81 );
	assert( [ "cooooooooonteeeeeeeeeest", "999993333" ].parse.expand.solve == 8999939997 );
	
	assert( [ "issiii", "2" ].parse.expand.solve == 5 );		// 追加ケース
	assert( [ "iissi", "2" ].parse.expand.solve == 4 );		// 追加ケース
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto s = input.front.to!( dchar[] );
	input.popFront;
	auto k = input.front.to!( long );
	return tuple( s, k );
}

auto solve( dchar[] s, long k )
{
	auto ans = 0L;
	auto gs = s.group.array;
	if( gs.length == 1 )
	{
		ans = gs.front[ 1 ] * k / 2;
	}
	else if( gs.front[ 0 ] != gs.back[ 0 ] )
	{
		ans = reduce!( ( a, b ) => a + b[ 1 ] / 2 )( 0L, gs ) * k;
	}
	else
	{
		ans += gs.front[ 1 ] / 2;														// 頭
		ans += reduce!( ( a, b ) => a + b[ 1 ] / 2 )( 0L, gs[ 1 .. $ - 1 ] ) * k;		// 身
		ans += ( gs.front[ 1 ] + gs.back[ 1 ] ) / 2 * ( k - 1 );						// 連結部分（頭＋尻尾）
		ans += gs.back[ 1 ] / 2;														// 尻尾
	}
	return ans;
}


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


int main()
{

   ll n;
   cin>>n;
   string a;
   set<string> s;
   for(ll i=0;i<n;i++)
   {
       cin>>a;
       s.insert(a);
   }
   cout<<s.size();
   return 0;
}


Measured memory_bytes: 19228
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int a,b;
    cin>>a>>b;
    if(5<a&&a<13){
        b/=2;
    }else if(a<=5){
        b=0;
    }

    cout<<b<<endl;

    return 0;
}


Measured memory_bytes: 888
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):
    c = Counter(S)
    if len(c) == 2 and len(S) == 4:
        return 'Yes'
    return 'No'


def main():
    S = read_str()
    print(slv(S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 8004
n = int(input())
plan = [list(map(int,input().split())) for i in range(n)]
t = x = y = 0
for i in plan:
    if (i[0] - t) >= (abs(x-i[1]) + abs(y-i[2])) and (i[0] - t) % 2 == (abs(x-i[1]) + abs(y-i[2])) % 2:
        t = i[0]
        x = i[1]
        y = i[2]
    else:
        print("No")
        break
else:
    print("Yes")


Measured memory_bytes: 27300
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int>vec(N);
    vector<int>vec2(N);
    for(int i=0;i<N;i++){
        cin >> vec.at(i);
    }
    for(int i=0;i<N;i++){
        vec2.at(vec.at(i)-1)=i+1;
    }
    for(int i=0;i<N;i++){
        cout<<vec2.at(i)<<endl;
    }  
    

}

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

int main() {
    int h, n, a;
    cin >> h >> n;
    bool flag = false;
    for(int i = 0; i < n; i++){
        cin >> a;
        h -= a;
        if(h <= 0){
            cout << "Yes";
            flag = true;
            break;
        }
    }
    if (!flag)
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<stdio.h>

#define MAX 100
#define INF (1<<21)

int main(){
  int i,j,k,l,n;
  int p[MAX+1],m[MAX+1][MAX+1];

  scanf("%d",&n);
  for(i=1;i<=n;i++)
    scanf("%d %d",&p[i-1],&p[i]);

  for(i=1;i<=n;i++)
    m[i][i] = 0;

  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j = i + l -1;
      m[i][j] = INF;
      for(k=i;k<j;k++)
	if(m[i][j] > m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j])
	  m[i][j] = m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j];
    }
  }

  printf("%d\n",m[1][n]);

  return 0;
}

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


using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> v(n);
	for(int& x : v) cin >> x;
	
	long long a=0;
	int cur=v[0];
	for(int i=1;i<n;i++) {
		if(v[i]<cur) {
			a+=cur-v[i];
		}
		cur=max(cur,v[i]);
	}
	cout << a;
	return 0;
}




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

#define PI 3.141592653589
#define ll long long int
#define ld long double
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vv vector
int MOD=1e9+7;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
ll min(ll a,ll b){return (a>b)?b:a;}
ll max(ll a,ll b){return (a>b)?a:b;}
bool prime[1000001];
vi primes;
void SieveOfEratosthenes(int n) 
{ 
    memset(prime, true, sizeof(prime)); 
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for(int p=2;p<1000001;p++)
        if(prime[p])
            primes.pb(p);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int t=1;
	//cin>>t;
	//SieveOfEratosthenes(1000000);
    while(t--){
        int a,b,c,k;
        cin>>a>>b>>c>>k;
        while(b<=a)
            b*=2,k--;
        while(c<=b)
            c*=2,k--;
        if(k>=0)
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }
}

Measured memory_bytes: 3648
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int c = sc.nextInt();
    int[] b = new int[m];
    int[][] a = new int[n][m];
    int count = 0;

    for (int i = 0; i < m; i++) {
      b[i] = sc.nextInt();
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        a[i][j] = sc.nextInt();
      }
    }

    for (int i = 0; i < n; i++) {
      int sum = 0;
      for (int j = 0; j < m; j++) {
        sum += a[i][j] * b[j];
      }
      sum += c;
      if (sum > 0) count++;
    }

    System.out.println(count);
  }

}


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

using namespace std;
using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const int inf = 1e9+7;
const int mod = 1e9+7;

int main(){
    int n,m,x;
    cin>>n>>m>>x;

    vector<int>c(n);
    vector<vector<int>>a(n,vector<int>(m));

    rep(i,n){
        cin>>c[i];
        rep(j,m)cin>>a[i][j];
    }

    int ans= inf;

    rep(bit,1<<n){
        int csum=0;
        vector<int>asum(m,0);
        bool jdg=true;

        rep(i,n){
            if(bit&(1<<i)){
                rep(j,m){
                    asum[j]+=a[i][j];
                }
                csum+=c[i];
            }
        }

        rep(i,m){
            if(asum[i]<x){
                jdg=false;
                break;
            }
        }

        if(jdg)ans=min(ans,csum);
    }

    if(ans==inf)cout<<-1<<endl;

    else cout<<ans<<endl;

}

Measured memory_bytes: 3604
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func min(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v < ret {
			ret = v
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	h, w, k := nextInt(), nextInt(), nextInt()
	s, sum := make([]string, h), make([][]int, h)
	for i := range s {
		s[i] = next()
		sum[i] = make([]int, w)
		for j := range sum[i] {
			sum[i][j] = int(s[i][j] - '0')
		}
	}
	// 累積和
	for i := 0; i < h; i++ {
		for j := 1; j < w; j++ {
			sum[i][j] += sum[i][j-1]
		}
	}
	for j := 0; j < w; j++ {
		for i := 1; i < h; i++ {
			sum[i][j] += sum[i-1][j]
		}
	}

	// ホワイトチョコ(1)の個数
	white := func(l, r, top, bottom int) int {
		res := sum[bottom][r]
		if l > 0 {
			res -= sum[bottom][l-1]
		}
		if top > 0 {
			res -= sum[top-1][r]
		}
		if l > 0 && top > 0 {
			res += sum[top-1][l-1]
		}
		return res
	}

	can := func(l, r int, btm []int) bool {
		top := 0
		for j := range btm {
			if white(l, r, top, btm[j]) > k {
				return false
			}
			top = btm[j] + 1
		}
		return true
	}

	ans := 10000
	// bitのibit目が1 => i:i+1で切る
	for bit := 0; bit < (1 << (h - 1)); bit++ {
		btm := make([]int, 0)
		for i, x := bit, 0; i > 0; i, x = i>>1, x+1 {
			if i&1 == 1 {
				btm = append(btm, x)
			}
		}
		btm = append(btm, h-1)
		ok, res := true, len(btm)-1
		for l := 0; l < w; l++ {
			r := l - 1
			for r+1 < w && can(l, r+1, btm) {
				r++
			}
			if r < l {
				ok = false
				break
			}
			if r < w-1 {
				res++
			}
			l = r
		}
		if ok {
			ans = min(ans, res)
		}
	}

	puts(ans)
}


Measured memory_bytes: 1976
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<iomanip>
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) loop(i,0,n)
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
int main(){
	string s="11111110000000001111011101";
	string in;
	while(cin>>in,in!="#"){
		int co=0;
		
		rep(i,in.size()-1)co+=(s[in[i]-'a']!=s[in[i+1]-'a']);
		cout<<co<<endl;
	}
}


Measured memory_bytes: 3172
import sys
sys.setrecursionlimit(1000000)


def dfs(i, res, under):
    if i == n:
        if min(under) < x:
            return -1
        else:
            return res
    l = dfs(i + 1, res + c[i], [s + t for (s, t) in zip(under, a[i])])
    r = dfs(i + 1, res, under)
    if l == r == -1:
        return -1
    else:
        if l == -1:
            return r
        elif r == -1:
            return l
        else:
            return min(l, r)


n, m, x = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
c = [a[s][0] for s in range(n)]
a = [a[t][1:] for t in range(n)]
und = [0]*m
ans = []
print(dfs(0, 0, und))


Measured memory_bytes: 9248
#include<stdio.h>
 
int main (void)
{ 
  int i, j, k, x, n, ans = 0;
  
  while(1){
  	scanf("%d %d",&n, &x);
  	if(n == 0 && x == 0) break;
  	for(i = 1; i <= n; i++){
  		for(j = 1; j <= n; j++){
  			for(k = 1; k <= n; k++){
  				if(i + j + k == x && i != j && j != k && k != i){
  					ans += 1;
  				}
  			}
  		}
  	}
  	  	printf("%d\n", ans / 6);
  	  	ans = 0;
  }

  			
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h> 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vv = vector<vector<int>>;
using P = pair<int,int>;

int main(){
  int a,b,m;
  cin >> a >> b >> m;
  vector<int> an(a),bn(b);
  int amin,bmin;
  rep(i,a){
    cin >> an.at(i);
    if( i==0 ) amin = an.at(i); else amin = min( amin,an.at(i));
  }
  rep(i,b){
    cin >> bn.at(i);
    if( i==0 ) bmin = bn.at(i); else bmin = min( bmin,bn.at(i));
  }
  
  vector<int> cst(m);
  for(int i=0;i<m;i++){
    int x,y,c;
    cin >> x >> y >> c;
    cst.at(i) = an.at(x-1) + bn.at(y-1) - c;
  }
  
  sort(cst.begin(),cst.end());
  
  cout << min( cst.at(0) , amin+bmin ) << endl;
  
  return 0;
}


Measured memory_bytes: 1408
q = int(input())

n = 10**6
is_prime = [True]*(n+1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(n**0.5) + 1):
	if not is_prime[i]:
		continue
	for j in range(i * 2, n + 1, i):
		is_prime[j] = False

P = [0]*(10**6)

for i in range(1,10**6 - 1):
	if is_prime[i+1] == True and is_prime[(i+2)//2] == True:
		P[i+1] = P[i] + 1
	else:
		P[i+1] = P[i]

for i in range(1,q+1):
	l,r = map(int,input().split())
	print(P[r] - P[l-1])

Measured memory_bytes: 24864
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

using Weight=long long;
static const Weight INF=1LL<<57;

struct Edge {
    size_t src, dst;
    Weight weight;
    Edge() {}
    Edge(size_t src, size_t dst, Weight weight=1):
        src(src), dst(dst), weight(weight)
    {}
};

bool operator<(const Edge &e, const Edge &f) {
    if (e.weight != f.weight) {
        return e.weight > f.weight;
    } else {
        return e.src!=f.src? e.src<f.src : e.dst<f.dst;
    }
}

using Edges=vector<Edge>;
using Vertex=vector<Edge>;
using Graph=vector<Vertex>;

void join(Graph &g, size_t s, size_t d, Weight w=1) {
    // non-directed
    g[s].push_back(Edge(s, d, w));
    g[d].push_back(Edge(d, s, w));
}

void connect(Graph &g, size_t s, size_t d, Weight w=1) {
    // directed
    g[s].push_back(Edge(s, d, w));
}

bool has_ncycle(const Graph &g) {
    /* Bellman-Ford */
    size_t V=g.size();
    vector<Weight> d(V);
    for (size_t k=0; k<V; ++k)
        for (size_t i=0; i<V; ++i)
            for (const Edge &e: g[i])
                if (d[e.dst] > d[e.src] + e.weight) {
                    d[e.dst] = d[e.src] + e.weight;
                    if (k == V-1)
                        return true;
                }

    return false;
}

int main() {
    size_t V, E;
    scanf("%zu %zu", &V, &E);

    int aaaaa[E][2];

    Graph g(V);
    for (size_t i=0; i<E; ++i) {
        size_t s, t; // 0-index
        scanf("%zu %zu", &s, &t);

        aaaaa[i][0] = s;
        aaaaa[i][1] = t;

        connect(g, s, t, -1);
    }

    cout << has_ncycle(g) << endl;
    
    return 0;
}



Measured memory_bytes: 3304
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000009
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int main() {
    fastio;
	long long int n,d,i;
	cin>>n;
	long long a[n],b[n];
	for(int i=0;i<n;i++){ cin>>d; a[i] = 2*d;} 
	long long int s = a[0]; 
	for(i=1;i<n-1;i++){
	    s = a[i]-s;
	    //cout<<s<<"\n";
	}
	s = s+a[i];
	s=s/2;
	b[n-1]=s;
	for(int i=n-2;i>0;i--){
	    b[i] = a[i]-s;
	    s = b[i];
	}
	b[0] = a[0]-s;
	for(int i=0;i<n;i++){
	    cout<<b[i]<<" ";
	}
	return 0;
}

Measured memory_bytes: 2944
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid<int> u1(5, 10); u1(rnd);

ll a;
str t;
vec<ll> hs, pw;
ll mod = 2e9+87, p = 101;

ll gh(ll l, ll r){
    ll h = (hs[r]-(l ? hs[l-1] : 0)+mod)%mod;
    return (h*pw[a-r])%mod;
}

ll check(ll d){
    multiset<ll> s;
    ll l=0, r=d-1;
    for(int q=d; q+d<=a; q++) s.insert(gh(q, q+d-1));
    for(; r<a; r++, l++){
        ll h = gh(l,r);
        if(s.count(h)) return 1;
        if(r+1==a) break;
        if(r+1+d<=a) s.erase(s.find(gh(r+1, r+d)));
        if(l-d+1>=0) s.insert(gh(l-d+1, l));
    }
    return 0;
}

int main(){
    fast;
    cin>>a>>t;
    hs = vec<ll>(a);
    pw = vec<ll>(a+5);
    pw[0] = 1;
    for(int q=1; q<a+5; q++) pw[q] = (pw[q-1]*p)%mod;
    hs[0] = t[0];
    for(int q=1; q<a; q++) hs[q] = (hs[q-1]+(t[q]*pw[q]))%mod;
    ll l=0, r=a;
    for(; l+1<r;){
        ll md = (l+r)/2;
        if(check(md)) l = md;
        else r = md;
    }
    cout<<l;
}

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

int main(){
  int H,N;
  cin >> H >> N;
  vector<int> A(N),B(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i) >> B.at(i);
  }
  const int64_t INF=1e9;
  vector<vector<int64_t> > dp(N+1,vector<int64_t>(H+1,INF));
  for(int i=0;i<=N;i++){
    dp.at(i).at(0)=0;
  }
  for(int i=1;i<=N;i++){
    for(int j=1;j<=H;j++){
      if(j>=A.at(i-1)){
        dp.at(i).at(j)=min(dp.at(i-1).at(j),dp.at(i).at(j-A.at(i-1))+B.at(i-1));
      }else{
        dp.at(i).at(j)=min(dp.at(i-1).at(j),(int64_t)B.at(i-1));
      }
    }
  }
  cout << dp.at(N).at(H) << endl;
  return 0;
}


Measured memory_bytes: 81596
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <stack>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#define int long long
#define ll long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
#define MIN -(9223372036854775807 / 2)
#define INF 9223372036854775807 / 2
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define mp make_pair


using namespace std;

std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

using Weight = int;
using Flow = int;
struct Edge {
	int src, dst;
	Weight weight;
	Flow cap;
	Edge() : src(0), dst(0), weight(0) {}
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph &g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }


signed main() {
	int H, W, h, w;
	cin >> H >> W >> h >> w;
	int white = H * W;
	white -= H * w;
	white -= h * W;
	white += h * w;
	cout << white << "\n";


	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    int l=s.length();
    int i,a,b;
    for(i=0;i<l;i++)
    {
        if(s[i]=='A')
        {
          a=i+1;
          break;
        }
    }
    for(i=0;i<l;i++)
    {
        if(s[i]=='Z')
        {
          b=i+1;
        }
    }
    cout<<b-a+1;
    return 0;
}


Measured memory_bytes: 832
import java.util.*;

class Main{

    int cnt;

    void solve(){
        Scanner sc = new Scanner(System.in);
        while(true){
            int x = sc.nextInt(), y =sc.nextInt();
            if(x==0 && y==0) break;
            if(x<y){
                int tmp = x;
                x = y; y = tmp;
            }
            cnt = 0;
            System.out.println(yu(x, y)+" "+cnt);
        }
    }

    int yu(int x, int y){
        if(y==0) return x;
        x = x % y;
        cnt++;
        return yu(y, x);
    }

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

Measured memory_bytes: 24392
#line 1 "/workspaces/compro/lib/template.hpp"


#line 1 "/workspaces/compro/lib/io/vector.hpp"
#include <iostream>
#include <vector>

#ifndef IO_VECTOR
#define IO_VECTOR

template <class T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
  int size = v.size();
  for (int i = 0; i < size; i++) {
    std::cout << v[i];
    if (i != size - 1)
      std::cout << " ";
  }
  return out;
}

template <class T> std::istream &operator>>(std::istream &in, std::vector<T> &v) {
  for (auto &el : v) {
    std::cin >> el;
  }
  return in;
}

#endif
#line 4 "/workspaces/compro/lib/template.hpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes, T no) { cout << (val ? yes : no) << "\n"; }

void say(bool val, string yes = "Yes", string no = "No") { say<string>(val, yes, no); }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}

// C++ 17に完全移行したら消す
// 最大公約数を求める
template <class T> T gcd(T n, T m) { return n ? gcd(m % n, n) : m; }

// 最小公倍数を求める
template <class T> T lcm(T n, T m) {
  int g = gcd(n, m);
  return n * m / g;
}

// 重複を消す。計算量はO(NlogN)
template <class T> void unique(std::vector<T> &v) {
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());
}


#line 2 "abc174_d.cpp"

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

  int n;
  cin >> n;
  string s;
  cin >> s;

  int ans = n + 1;
  int r = 0, w = 0;
  REP(i, n) {
    if (s[i] == 'R') {
      r++;
    } else {
      w++;
    }
  }

  chmin(ans, min(r, w));

  int cnt = 0;
  REP(i, r) {
    if (s[i] == 'W')
      cnt++;
  }
  chmin(ans, cnt);
  cout << ans << endl;
}


Measured memory_bytes: 3772
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

ll dp[18][100010];

int main() {
    ll N;
    cin >> N;
    ll x[N];
    REP(i, 0, N) {
        cin >> x[i];
    }
    ll L;
    cin >> L;
    REP(i, 0, N - 1) {
        ll id = upper_bound(x, x + N, x[i] + L) - x - 1;
        dp[0][i] = id;
    }
    dp[0][N - 1] = N - 1;
    REP(i, 1, 18) {
        REP(j, 0, N) {
            dp[i][j] = dp[i - 1][dp[i - 1][j]];
        }
    }
    // REP(i, 0, 18) {
    //     REP(j, 0, N) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    ll Q;
    cin >> Q;
    REP(i, 0, Q) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        if (a > b) {
            swap(a, b);
        }
        ll tmp = a;
        ll ans = 0;
        while (1) {
            if (dp[0][tmp] >= b) {
                ans++;
                break;
            }
            REP(i, 1, 18) {
                if (dp[i][tmp] >= b) {
                    ans += 1 << (i - 1);
                    tmp = dp[i - 1][tmp];
                    break;
                }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 15616
n = int(input())
def solve(n): 

    string = ""
    i = 0
    while n > 0: 
        rem = n % 26
        if rem == 0: 
            string += 'z'
            i += 1
            n = (n // 26) - 1
        else: 
            string += str(chr((rem - 1) + ord('a')))
            i += 1
            n = n // 26
    string = string[::-1] 
    print(string)

solve(n)

Measured memory_bytes: 9092
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, c;
    cin >> n >> m >> c;
    int b[m];
    int a[m][n];
    for(int i = 0;i < m;i++) {
        cin >> b[i];
    }

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

    int count = 0;
    for(int i = 0;i < n;i++) {
        int sum = 0;
        for(int j = 0;j < m;j++) {
            sum+=a[j][i]*b[j];
        }
        sum+=c;
        if(sum>0) {
            count++;
        }
    }
    cout << count << endl;
}

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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<double> v_double;
typedef std::vector<std::vector<double> > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

void IsPrimeNum(ll n, v_bool &is_prime)
{
    is_prime[0] = is_prime[1] = false;
    for(ll i = 2; i <= n; i++) {
        for(ll j = i*i; j <= n; j += i) {
            is_prime[j] = false;
        }
    }
}

int main(void)
{
    int n;
    cin >> n;
    int n_max = 55555;

    v_bool is_prime(n_max+1, true);    
    IsPrimeNum(n_max, is_prime);
    v_int prime;

    int cnt = 0;
    irep(i, n_max) {
        if(is_prime[i] && i % 5 == 1) { prime.push_back(i); }
    }

    irep(i, n) {
        printf("%d ", prime[i]);
    }
    return 0;
}
/** atcoder **/


Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;

int main() {
  int A, B; std::cin >> A >> B;
  if (A >= 13) {
    std::cout << B << std::endl;
  } else if (A > 5) {
    std::cout << B/2 << std::endl;
  } else {
    std::cout << 0 << std::endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

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

int main()
{	
	int N, A, B;
	cin >> N >> A >> B;
	if(N*A > B) cout << B << endl;
	else cout << A*N << endl;
}


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

typedef long long ll;
ll a,b;
int c,d;

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

int main()
{
    scanf("%lld %lld %d %d",&a,&b,&c,&d);
    ll t = gcd(c,d);
    t = c/t*d;
    ll ans = b-b/c-b/d+b/t-(a-1-(a-1)/c-(a-1)/d+(a-1)/t);
    printf("%lld\n",ans);
    return 0;
}


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

class Cube {
public:
  int f[6];
  Cube(){}
  void roll_z(void) {
    roll(1,2,4,3);
  }
  void roll_y(void) {
    roll(0,2,5,3);
  }
  void roll_x(void) {
    roll(0,1,5,4);
  }
  void roll(int i,int j,int k,int l) {
    int t = f[i];
    f[i] = f[j];
    f[j] = f[k];
    f[k] = f[l];
    f[l] = t;
  }
};

int getRight(Cube c1,int f1,int f2) {
  for (int i=0;i<6;i++) {
    for (int j=0;j<4;j++) {
      if (c1.f[0]==f1 && c1.f[1]==f2) {
        return c1.f[2];
      }
      c1.roll_z();
    }
    if (i%2==0) {
      c1.roll_y();
    }  else {
      c1.roll_x();
    }
  }
  return -1;
}

int main() {
  Cube c;
  int f1,f2;
  for (int i=0; i<6; i++) {
    cin >> c.f[i];
  }
  int q;
  cin >> q;
  for (int i=0; i<q; i++) {
    cin >> f1 >> f2;
    cout << getRight(c,f1,f2) << endl;
  }
  return 0;
}

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

using namespace std;

int main()
{
    string s;
    cin >> s;
    int length = s.length();
    int flag = 1;
    for (int i = 0; i < length / 2; i++)
    {
        if (s[i] != s[length - 1 - i])
        {
            flag = 0;
        }
    }
    int a = (length - 1) / 2;
    for (int i = 0; i < a - 1; ++i)
    {
        if (s[i] != s[a - 1 - i])
        {
            flag = 0;
        }
    }
    int b = (length + 3) / 2;
    for (int i = b - 1; i < length - 1; i++)
    {
        if (s[i] != s[length - 1 - i])
        {
            flag = 0;
        }
    }
    if (flag)
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
}

Measured memory_bytes: 256
#include <cstdio>
const int LEN = 1e5+4;
char buf[LEN], out[LEN];
bool check(int N, char x, char y)
{
	out[0] = x;
	out[1] = y;
	for(int i=1; i<=N; ++i)
		if(buf[i] == 'o')
			out[i+1] = out[i]=='S' ? out[i-1] : out[i-1]=='S' ? 'W' : 'S';
		else
			out[i+1] = out[i]=='W' ? out[i-1] : out[i-1]=='S' ? 'W' : 'S';
	x = out[N];
	y = out[N+1];
	out[N] = 0;
	return x==out[0] && y==out[1];
}
int main()
{
	int N;
	scanf("%d%s", &N, buf);
	buf[N] = buf[0];
	if(check(N, 'S', 'S'))
		puts(out);
	else if(check(N, 'S', 'W'))
		puts(out);
	else if(check(N, 'W', 'S'))
		puts(out);
	else if(check(N, 'W', 'W'))
		puts(out);
	else puts("-1");
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

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

int main() {
  int n;
  cin >> n;
  vector<int> v;
  rep(i, n) {
    int tmp;
    cin >> tmp;
    v.push_back(tmp);
  }
  int count = 0;
  while(1) {
    bool flag = true;
    rep(i, n) {
      if (v[i] != 0) {
        flag = false;
        break;
      }
    }
    if (flag) break;
    int index = 0;
    rep(i, n) {
      if (v[i] != 0) {
        index = i;
        break;
      }
    }

    for (int i = index; i < v.size(); ++i) {
      if (v[i] == 0) break;
      v[i]--;
    }
    count++;
  }
  cout << count << endl;


  return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    if(B % A == 0){
      System.out.println(B + A);
    }else{
      System.out.println(B - A);
    }
  }
}

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

int main(){
    ll a,b;
    cin>>a>>b;
    if(b+a-1>=0 && b<=0)cout<<(b+a-1+b)*a/2;
    else if(b>0)cout<<(b+a-1+b)*a/2-b;
    else cout<<(b+a-1+b)*a/2-(b+a-1);
    return 0;
}


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

int main() {
    int a, b;
    string s, t, u;
    cin >> s >> t >> a >> b >> u;
    if(u == s) {
        a-=1;
    }
    else {
        b-=1;
    }
    cout << a << ' ' << b << endl;
}

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

void max_self(ll& a, ll b) {
    a = max(a, b);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
    int n, w;
    cin >> n >> w;
    vector<ll> dp(w+1);
    // dp[i] - the maximum total value of items with total weight exactly i
    for(int item=0; item < n; ++item) {
        int weight, value;
        cin >> weight >> value;
        for(int wt_already = w - weight;  wt_already >= 0; --wt_already) {
        // for(int wt_already = 0;  wt_already <= w - weight; ++wt_already) {
            max_self(dp[wt_already+weight], dp[wt_already] + value);
        }
    }
    ll ans = 0;
    for(int i=0; i<=w; ++i) {
        max_self(ans, dp[i]);
    }
    cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long long mod = 1e9+7;
long long inv[3000001];
long long fac[3000001];
long long facinv[3000001];

int main(){
  int x,y;cin>>x>>y;
  if((2*y-x)%3!=0 ||(2*x-y)%3!=0){
    cout<<0<<endl;
  }else{
    int a = (2*y-x)/3;
    int b = (2*x-y)/3;
    
	if(a<0||b<0){
      cout<<0<<endl;
      return 0;
    }
    
    inv[0] = 1;
    inv[1] = 1;
    for(int i=2;i<3000001;++i){
        inv[i] = (mod-mod/i)*1LL*inv[mod % i]%mod;
    }

    fac[0] = 1;
    fac[1] = 1;
    for(int i=2;i<3000001;++i){
      fac[i] = fac[i-1] * 1LL* i % mod ;
    }

    facinv[0] = 1;
    facinv[1] = 1;
    for(int i=2;i<3000001;++i){
      facinv[i] = facinv[i-1] * 1LL* inv[i] % mod ;
    }
    
    int res = ((1LL * fac[a+b] * facinv[b]) % mod * facinv[a])%mod;
    cout<<res<<endl;
  }
  
  
  return 0;
}


Measured memory_bytes: 70528
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;
 
int gcd(int x,int y){
    if(y==0)return x;

    return gcd(y,x%y);
}
int lcm(int x,int y){
    return x*y/gcd(x,y);
}

int main(){

    int K,X;
    cin>>K>>X;

    for(int i=max(-100000,X-(K-1));i<=min(100000,X+(K-1));i++){
        cout << i << " ";
    }
    cout<<endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int n =scan.nextInt();
		int a = 0, b = 0, c = 0, d = 0;
		for(int i = 0; i < n; i++) {
			String s = scan.next();
			if(s.equals("AC")) {
				a++;
			}else if(s.equals("WA")) {
				b++;
			}else if(s.equals("TLE")) {
				c++;
			}else {
				d++;
			}
		}
		System.out.println("AC x "+ a);
		System.out.println("WA x "+ b);
		System.out.println("TLE x "+ c);
		System.out.println("RE x "+ d);
	}

}


Measured memory_bytes: 58180
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N = _I()
A = LI()

# 001, 101, 1000の場合など、最大桁数のものが1つしかない場合、絶対に1000と作る数は1XXXになるので、絶対無理
# 1000, 1001, 0101, 0001の場合、0001が作れる。しかし、1000はどう頑張っても作れない
# 全数字を2進数に直す結局全部1が並ぶやつ、つまり、1/1/0, 10/01/11, 111/100/011, 111/101/010などの組み合わせが必要
# そもそも3種類以上ある場合は絶対成り立たない
set_A = set(A)
if len(set_A) > 3:
    print('No')
    exit()

if len(set_A) == 1:
    if A[0] == 0:
        print('Yes')
    else:
        print('No')
elif len(set_A) == 2:
    # 2種類で成り立つのは、全部1111が2つと、全部000が1つの場合のみ
    A_list = list(set_A)
    if 0 in A_list:
        non_zero = [i for i in A_list if i != 0][0]
        if A_list[0] ^ A_list[1] == non_zero:
            # 0と1の比率が1:2でないとだめ。さらに、総数が3*2*n
            if A.count(0) * 2 == A.count(non_zero) and N % 3 == 0:
                # XORがA_listに入ってたら。
                print("Yes")
                exit()
            else:
                print('No')
                exit()
        else:
            print("No")
            exit()
    else:
        print('No')
        exit()
elif len(set_A) == 3:
    A_list = list(set_A)
    if A_list[0] ^ A_list[1] == A_list[2] and A_list[0] ^ A_list[2] == A_list[1] and A_list[1] ^ A_list[2] == A_list[0]:
        # それぞれの数が1:1:1でないとだめ
        if A.count(A_list[0]) == A.count(A_list[1]) == A.count(A_list[2]) and N % 3 == 0:
            print('Yes')
        else:
            print("No")
    else:
        print('No')




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

template<class T>
T extended_euclidian (T a, T b, T &x, T &y) {
	if (b == 0) {
		x = 1; y = 0;
		return a;
	}
	T d = extended_euclidian(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

int main() {
	long long a, b, x, y;
	cin >> a >> b;
	
	extended_euclidian<long long>(a, b, x, y);
	
	cout << x << ' ' << y << '\n';
	
	return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <sstream>
#include <fstream>
#include <tuple>
#include <set>
#include <functional> 
#include <string.h>

#define X first
#define Y second
#define MP make_pair
#define MT make_tuple
#define FOR(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define REP(i, a, n) for(int (i) = (a); (i) < (n); (i)++)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll > pll;
using namespace std;
const int MAX = 101;
const double PI = 3.1415926535897932384;

template<class T, class U>
void convert(T &t, U &u){
	stringstream ss;
	ss << t;
	ss >> u;
}

int TakeCustomNum(string s){
	int val = 0, digit = 10;
	FOR(i, s.size()){
		if (s[i] == ',') break;
		else{
			val *= digit;
			val += s[i] - '0';
		}
	}
	return val;
}

void InputLastData(map<int, int> &ans){
	string s;
	while (getline(cin, s) && s != "\0"){
		ans[TakeCustomNum(s)]++;
	}
}

void InputCurrentData(map<int, int> &prev, map<int, int> &now){
	string s;
	while (getline(cin, s) && s != "\0"){
		int key = TakeCustomNum(s);

		if (now.count(key)) now[key]++;
		else if (prev.count(key)) now[key] += prev[key] + 1;
	}
}

void OutputData(map<int, int> &ans){
	for(auto i: ans){
		if (i.second > 1){
			cout << i.first << " " << i.second << endl;
		}
	}
}

int main(){
	map<int, int> prev, now;
	
	InputLastData(prev); 
	InputCurrentData(prev, now);

	OutputData(now);

	return 0;
}

Measured memory_bytes: 1188
n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for j in range(m)]
S = list(set(s))
T = list(set(t))
b = []

for x in range(len(S)):
  a = s.count(S[x]) - t.count(S[x])
  b.append(a)
ans = max(0, max(b))
print(ans)

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

int main(){
  int n;
  cin >> n;
  int *arr = new int[n];
  int *sorted = new int[n];
  for (int i = 0;i < n;i++){
    cin >> arr[i];
    sorted[i] = arr[i];
  }
  sort(sorted, sorted + n);
  int med1, med2;
  med1 = sorted[n/2 -1];
  med2 = sorted[n/2];
  for (int i = 0; i < n; i++){
    if (arr[i] <= med1){
      cout << med2 << endl;
    }else{
      cout << med1 << endl;
    }
  }
  delete[] arr;
  delete[] sorted;
  return 0;
  
}

Measured memory_bytes: 3712
use proconio::input;

fn main() {
  input! {
    n: usize,
  }

  let mut count = 0;
  let mut i = 0;
  let mut v = 357;
  while v <= n {
    let mut temp = v;
    let mut f3 = false;
    let mut f5 = false;
    let mut f7 = false;
    while 0 < temp {
      let vv = temp % 10;
      if vv == 7 {
        f7 = true;
      } else if vv == 5 {
        f5 = true;
      } else if vv == 3 {
        f3 = true;
      } else {
        f3 = false;
        break
      }
      temp /= 10;
    }
    if f3 && f5 && f7 {
      count += 1;
    }
    
    if i % 3 == 0 {
      v += 6;
    } else {
      v += 2;
    }
    i += 1;
  }
  println!("{}", count);
}

Measured memory_bytes: 2108
n=int(input())
a=[0]+[int(i) for i in input().split()]
b=[0]+[int(i) for i in input().split()]
c=[0]+[int(i) for i in input().split()]
 
res = 0
prev = -1
for i in range(1, n+1):
    res += b[a[i]]
    if prev+1 == a[i]:
        res += c[prev]
    prev = a[i]

print(res)


Measured memory_bytes: 38256