akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
class Main {
    public static void main(String[] args){
        Scanner scanner =new Scanner(System.in) ;
        int S = scanner.nextInt();
        int h = S / 3600;
        int m = (S-h*3600) / 60 ;
        int s = S % 60;
        System.out.println(h + ":" + m + ":" + s);
    }
}


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

int x = 0;
int i = 0;
int main()
{
scanf("%d",&x);
	while (1) {
	    if(x == 0){
	        break;
	    }
	    i++;
		printf("Case %d: %d\n", i, x);
		scanf("%d",&x);
	}
    return 0;
}



Measured memory_bytes: 2740
def check(i, num):

    global N, ans

    if i <= len(str(N)):
        if num <= N:
            list_n = list(map(int, list(str(num))))
            n3 = list_n.count(3)
            n5 = list_n.count(5)
            n7 = list_n.count(7)
            if n3 >= 1 and n5 >= 1 and n7 >= 1:
                ans += 1
                
        temp = 10 ** i   
        check(i + 1, num + 3 * temp)
        check(i + 1, num + 5 * temp)
        check(i + 1, num + 7 * temp)
    
N = int(input())
sn = str(N)

ans = 0

if len(sn) <= 2:
    print(0)
    exit()

check(0, 0)
    
print(ans)
            


Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>
 
double x[3],y[3];
 
double distance(int a,int b){
    return sqrt(pow(x[a]-x[b],2.0)+pow(y[a]-y[b],2.0));
}
 
int main(){
    int n,i,j;
    double xp,yp,R,S,s,s2,r,a,b,c,d,e,f;
    double len[3];
 
    scanf("%d",&n);
 
    for(i = 0;i < n;i++){
        for(j = 0;j < 3;j++){
            scanf("%lf %lf",&x[j],&y[j]);
        }
 
        s = 0.0;
        for(j = 0;j < 3;j++){
            len[j] = distance((j+2)%3,(j+1)%3);
            s += len[j];
        }
        s /= 2.0;
        s2 = s;
        r = 1.0;
        for(j = 0;j < 3;j++){
            s2 *= (s-len[j]);
            r *= len[j];
        }
        S = sqrt(s2);
        R = r/(4.0*S);
 
        a = 2*(x[1] - x[0]);
        b = 2*(y[1] - y[0]);
        c = x[0]*x[0]-x[1]*x[1]+y[0]*y[0]-y[1]*y[1];
        d = 2*(x[2] - x[0]);
        e = 2*(y[2] - y[0]);
        f = x[0]*x[0]-x[2]*x[2]+y[0]*y[0]-y[2]*y[2];
 
        xp = (b*f-e*c)/(a*e-d*b);
        yp = (c*d-f*a)/(a*e-d*b);
 
        printf("%.3f %.3f %.3f\n",xp,yp,R);
    }
 
    return 0;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
signed main(){
    string s;
    cin >> s;
    int cnt = 0;
    rep(i,6){
        if(s[i] == '1') ++cnt;
    }
    cout << cnt << '\n';
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();

      if (a + b >= c) {
         System.out.println("Yes");
      }
      else {
         System.out.println("No");
      }
   }
}

Measured memory_bytes: 23892
import java.util.Scanner;
public class Main {
	public static int search(int[] a,int key,int n){
		int left = 0;
		int right = n;
		int mid = 0;
		while(left<right){
			mid = (left + right)/2;
			if(a[mid]==key)
				return 1;
			else if(key<a[mid])
				right = mid;
			else
				left = mid +1;
		}
		return 0;
	}
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int result=0;
		int n = scan.nextInt();
		int[] S = new int[n+1];
		for(int i = 0 ; i < n ; i ++){
			S[i]=scan.nextInt();
		}
		int q = scan.nextInt();
		int[] T = new int[q];
		for(int i = 0 ; i < q ; i ++){
			T[i]=scan.nextInt();
		}
		for(int i = 0; i < q ; i ++){
			result += search(S,T[i],n);	
		}
		System.out.println(result);
		scan.close();
	}

}

Measured memory_bytes: 76052
a = list(map(int, input().split()))
queuekey = []
queuetime = []

for i in range(0, a[0]):
    tmp = list(input().split())
    queuekey.append(tmp[0])
    queuetime.append(int(tmp[1]))

spentTime = 0
while len(queuetime) > 0:
    if queuetime[0] <= a[1]:
        spentTime += queuetime[0]
        print(queuekey[0], end="")
        print(' ', end="")
        print(spentTime)
        queuekey.pop(0)
        queuetime.pop(0)
    else:
        spentTime += a[1]
        queuetime[0] -= a[1]
        queuetime.append(queuetime[0])
        queuekey.append(queuekey[0])
        queuetime.pop(0)
        queuekey.pop(0)

        
    

Measured memory_bytes: 11648
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
const int INF = 1e9;

int main(void){
    int h,n;
    cin >> h >> n;
    vector<int> a(n), b(n);
    rep(i,n){
        cin >> a[i] >> b[i];
    }
    vector<int> dp(h+1, INF);
    dp[h] = 0;
    rep(x,h) {
        int cur = h-x;
        rep(i,n){
            int to = max(cur-a[i], 0);
            dp[to] = min(dp[cur] + b[i], dp[to]);
        }
    }
    cout << dp[0] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int K,S;
    int X=0, Y=0, Z=0;
    int ans=0;

    scanf("%d %d", &K, &S);
        for (int j = 0; j <=K ; ++j) {
            for (int k = 0; k <=K ; ++k) {
                Z = S-k-j;
                if(0<= Z && Z <=K){
                    ans = ans + 1;
                }
            }
        }
    printf("%d", ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <unordered_map>

using namespace std;

void solve() {
    int n; cin >> n;
    vector<int> w(n);
    for(int i = 0; i < n; i++){
        cin >> w[i];
    }

    int minval;
    for(int i = 0; i < n; i++){
        int before = 0;
        int after = 0;
        for(int j = 0; j < n; j++){
            if(j <= i) before += w[j];
            else after += w[j];
        }
        if(i == 0) minval = abs(before - after);
        else {
            minval = min(minval, abs(before-after));
        }
    }
    cout << minval << endl;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  set<char>se;
  int n;
  char c;
  cin>>n;
  rep(i,n){
    cin>>c;
    se.insert(c);
  }
  if(se.size()==3)cout<<"Three"<<endl;
  else cout<<"Four"<<endl;
  return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	sc1 := bufio.NewScanner(os.Stdin)
	sc1.Split(bufio.ScanWords)
	heap := []int{}
	// dummy value for index ajustment(from 1)
	heap = append(heap, -1)

	for {
		// fmt.Println(heap)
		sc1.Scan()
		command := sc1.Text()
		if command == "insert" {
			sc1.Scan()
			num, _ := strconv.Atoi(sc1.Text())
			heap = insert(heap, num)
		} else if command == "extract" {
			max := 0
			heap, max = extract(heap)
			fmt.Println(max)
		} else {
			break
		}
	}
}

func insert(heap []int, val int) []int {
	result := append(heap, val)
	if len(heap) == 1 {
		return result
	}

	targetIndex := len(result) - 1

	for {
		parentIndex := (int)(targetIndex / 2)
		if parentIndex == 0 {
			// target is already root
			return result
		}
		if result[parentIndex] < result[targetIndex] {
			result[parentIndex], result[targetIndex] = result[targetIndex], result[parentIndex]
			targetIndex = parentIndex
		} else {
			return result
		}
	}

	return result
}

func extract(heap []int) ([]int, int) {
	max := heap[1]
	last := heap[len(heap)-1]
	// shorten length
	heap = heap[0 : len(heap)-1]
	if len(heap) == 1 {
		return heap, max
	}
	heap[1] = last
	maxIndex := len(heap) - 1

	index := 1
	for {
		rightIndex := index * 2
		leftIndex := index*2 + 1

		existRight := true
		if maxIndex < rightIndex {
			existRight = false
		}

		existLeft := true
		if maxIndex < leftIndex {
			existLeft = false
		}

		if !existLeft && !existRight {
			break
		}

		if (existRight && !existLeft) || (existRight && existLeft && heap[rightIndex] > heap[leftIndex]) {
			// right only or right > left
			if heap[rightIndex] > heap[index] {
				heap[index], heap[rightIndex] = heap[rightIndex], heap[index]
				index = rightIndex
				continue
			} else {
				break
			}
		} else if existLeft {
			// left only or left > right
			if heap[leftIndex] > heap[index] {
				heap[index], heap[leftIndex] = heap[leftIndex], heap[index]
				index = leftIndex
				continue
			} else {
				break
			}
		} else {
			break
		}
	}
	return heap, max
}



Measured memory_bytes: 26128
#include <bits/stdc++.h>
#include <math.h>
#define rep(i,n) for (int i=0;i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
 
bool pa(string s){
    string L(s.rbegin(),s.rend());
    return s == L;
}
int main() {
    string S;
    cin >> S;
    int n = S.size();
    if(pa(S)&&pa(S.substr(0,(n-1)/2))&&pa(S.substr((n+1)/2))){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
n,*t=map(int,open(0).read().split())
e=[[]for i in range(n+1)]
for a,b in zip(t[1::2],t[2::2]):
  e[a].append(b)
  e[b].append(a)
i=0
for v in e[1]:
  for w in e[v]:
    if w==n:
      i=2
print('IMPOSSIBLE'[i:])

Measured memory_bytes: 128708
n = int(input())
a = list(map(int,input().split()))
incre = None
ans = 1
for i in range(n-1):
    if incre == None:
        if a[i] == a[i+1]:
            continue
        elif a[i] < a[i+1]:
            incre = True
        elif a[i] > a[i+1]:
            incre = False
    elif incre == True and a[i] > a[i+1]:
        incre = None
        ans += 1
    elif incre == False and a[i] < a[i+1]:
        incre = None
        ans += 1
print(ans)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  
  vector<int> vec(N);
  for (int i=0;i<N;i++) {
    cin>>vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  
  int sum=0;
  for (int i=0;i<N-1;i++) {
    sum+=vec.at(i);
  }
  
  if (sum>vec.at(N-1)) {
    cout<<"Yes"<<endl;
  }
  else {
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#n=int(input())
n,a,b=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
mod=1000000007

#a!をmodで割ったあまりを求めるO(a)
def facmod(a,mod):
    res=1
    for i in range(1,a+1):
        res=(res*i)%mod
    return res

#a^nをmodでわったあまり 二分累乗法O(logn)
def modpow(a,n,mod):
    res=1
    while n>0:
        if n&1:
            res=(res*a)%mod
        a=(a*a)%mod
        n=n>>1
    return res

#フェルマーの小定理でaの逆元を求める
def modinv(a,mod):
    return modpow(a,mod-2,mod)

ans=(modpow(2,n,mod)-1)%mod

nca=1
ncb=1

#nCa
x=1;y=1
for i in range(n,n-a,-1):
    x=(i*x)%mod
y=facmod(a,mod)
yinv=modinv(y,mod)
nca=(x*yinv)%mod

#nCb
x=1;y=1
for i in range(n,n-b,-1):
    x=(i*x)%mod
y=facmod(b,mod)
yinv=modinv(y,mod)
ncb=(x*yinv)%mod

ans=(ans-nca-ncb)%mod

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
#define LINF 1e18
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n; cin >> n;
    vector<pair<pair<string, int>, int> > info(n);
    rep(i, n) {
        string s;
        int p;
        cin >> s >> p;
        info[i] = make_pair(make_pair(s, -p), i+1);
    }
    sort(all(info)); //第1要素同じなら第2要素見てソートしてくれる
    rep(i, n) cout << info[i].second << endl;
}


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

int main() {
	int n, m, x;
	cin >> n >> m >> x;
	int xto0 = 0, xton = 0;
	int a;
	for (int i = 0; i < m; i++) {
		cin >> a;
		if (a < x) {
			xto0++;
		}
		else {
			xton++;
		}
	}
	cout << min(xto0, xton) << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
lists = ['{0:03d}'.format(i) for i in range(1000)]
import re
def check(target, a):
    ans = re.search(a, target)
    if ans == None:
        return None
    else:
        return target[ans.start()+1:]

def print_ans(N, S):
    """Test Case
    >>> print_ans(4, "0224")
    3
    >>> print_ans(6, "123123")
    17
    >>> print_ans(19, "3141592653589793238")
    329
    """
    ans = 0
    for a in lists:
        tmp = S
        for i in range(3):
            tmp = check(tmp, a[i])
            if tmp == None:
                break
        if tmp != None:
            ans += 1
    print(ans)
    
if __name__ == '__main__':
    N = int(input().rstrip())
    S = input().rstrip()
    print_ans(N, S)


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

int main() {
  int n;

  cin >> n;

  vector<double> v(n);

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

  sort(v.begin(), v.end());

  for (int i = 0; i < n - 1; i++) {
    v[0] = (v[0] + v[1]) / 2;
    v[1] = 1e9;
    sort(v.begin(), v.end());
  }

  cout << v[0];

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int T[105000];
int N;
int M, sum;
int main() {
    //cout.precision(10);
  cin >> N;
  for(int i = 1; i <= N; i++) {
    cin >> T[i];
    sum += T[i];
  }
  cin >> M;
  while(M--) {
    int x, p;
    cin >> p >> x;
    cout << sum - T[p] + x << endl;
  }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int N;
	int i,j,hoge;
	int l[201]={0};
	int ans=0;
	scanf("%d",&N);
	for(i=0;i<2*N;i++){
		scanf("%d",&l[i]);
	}

	for(i=0;i<2*N;i++){
		for(j=0;j<2*N-1;j++){

			if(l[j]>l[j+1]){
				hoge=l[j];
				l[j]=l[j+1];
				l[j+1]=hoge;
			}
		}
	}

	for(i=0;i<N;i++){
		ans+=l[i*2];
	}

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


}

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

using namespace std;
#define ll long long int
int main()
{
    ll n,k,j;
    cin>>n>>k;
    ll a[n];
   ll b[n];

   for(ll i=0;i<n;i++)
   cin>>a[i];
 for(ll i=0;i<n;i++)
 {
     if(i==0)
        b[i]=0;
     if(i==1)
        b[i]=abs(a[i]-a[i-1]);
        if(i>1)
            {
                vector<ll>vec;
                if(i<k)
                {   for(ll j=1;j<=i;j++)
        {
                vec.push_back((b[i-j]+abs(a[i]-a[i-j])));
        } auto it=min_element(vec.begin(),vec.end());
               b[i]=*it;

                }

      if(i>=k)
           {   for(ll j=1;j<=k;j++)
        {
                vec.push_back((b[i-j]+abs(a[i]-a[i-j])));
        } auto it=min_element(vec.begin(),vec.end());
               b[i]=*it;

                }
        }
 }
cout<<b[n-1];
 return 0;

}


Measured memory_bytes: 1792
#include <iostream>
#include<stdio.h>
#include<bits/stdc++.h>

using namespace std;

int main()
{
    int x;
    cin>>x;
    if(x>=30)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define Q int q; cin >> q; while (q--)
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    map<string, int> m;
    Q {
        int c;
        string k;
        cin >> c >> k;
        if (c == 0) {
            int y;
            cin >> y;
            m[k] = y;
        } else if (c == 1) {
            if (m.count(k)) cout << m[k] << endl;
            else cout << 0 << endl;
        } else if (c == 2) {
            m.erase(k);
        }
    }
}



Measured memory_bytes: 25924
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N];
int32_t main(){_

   cin>>n;


   cout<<3*n*n;

   

   return 0;
}

Measured memory_bytes: 256
from math import log2
from itertools import accumulate

epsilon = 10 ** -5

MOD = 10 ** 9 + 7

N, K = map(int, input().split())
As = list(map(int, input().split()))

negs = []
poss = []
for A in As:
    if A > 0:
        poss.append(A)
    elif A < 0:
        negs.append(-A)

poss.sort(reverse = True)
negs.sort(reverse = True)

if len(poss) + len(negs) < K:
    print(0)
    exit()

if len(poss) == 0:
    if N > len(negs):
        if K % 2 == 1:
            print(0)
        else:
            ans = 1
            for n in negs[:K]:
                ans *= n
                ans %= MOD
            print(ans)
    else:
        if K % 2 == 1:
            ans = 1
            for n in negs[-K:]:
                ans *= n
                ans %= MOD
            print(-ans%MOD)
        else:
            ans = 1
            for n in negs[:K]:
                ans *= n
                ans %= MOD
            print(ans)
    exit()

if K == N:
    ans = 1
    for A in As:
        ans *= A
        ans %= MOD
    print(ans)
    exit()


def mulmod(a, b):
    return a * b % MOD

logs_poss = [0.0] + [log2(p) for p in poss] 
logs_poss_csum = list(accumulate(logs_poss))

poss_mod_csum = [1] + list(accumulate(poss, mulmod))

logs_negs = [0.0] + [log2(n) for n in negs] 
logs_negs_csum = list(accumulate(logs_negs))

negs_mod_csum = [1] + list(accumulate(negs, mulmod))

max_log = -1
for minus in range(0, K+1, 2):
    plus = K - minus
    if plus <= len(poss) and minus <= len(negs):
        if max_log + epsilon < logs_poss_csum[plus] + logs_negs_csum[minus]:
            max_log = logs_poss_csum[plus] + logs_negs_csum[minus]
            max_mod = poss_mod_csum[plus] * negs_mod_csum[minus] % MOD
        elif max_log <= logs_poss_csum[plus] + logs_negs_csum[minus]:
            mod = poss_mod_csum[plus] * negs_mod_csum[minus] % MOD
            if mod > max_mod:
                max_log = logs_poss_csum[plus] + logs_negs_csum[minus]
                max_mod = poss_mod_csum[plus] * negs_mod_csum[minus] % MOD

print(max_mod)



Measured memory_bytes: 127996
#include <iostream>
#include <algorithm>
#include <vector>

struct Card {
    char suit;
    int value;
};

void exchange(std::vector<Card>& A, int i, int j) {
    Card temp = A[i];
    A[i] = A[j];
    A[j] = temp;
}

int Partition(std::vector<Card>& A, int p, int r) {
    int x = A[r].value;
    int i = p-1;
    for (int j=p; j<r; ++j) {
        if (A[j].value <= x) {
            i++;
            exchange(A, i, j);
        }
    }
    exchange(A, i+1, r);
    return i+1;
}

void QuickSort(std::vector<Card>& A, int p, int r) {
    if (p < r) {
        int q = Partition(A, p, r);
        QuickSort(A, p, q-1);
        QuickSort(A, q+1, r);
    }
}

void Merge(std::vector<Card>& A, int left, int mid, int right) {
    std::vector<Card> L, R;
    for (int i=0; i<(mid-left); ++i) L.push_back(A[left+i]);
    for (int i=0; i<(right-mid); ++i) R.push_back(A[mid+i]);
    L.push_back(Card{'X', 1000000000});
    R.push_back(Card{'X', 1000000000});
    
    int i=0;
    int j=0;
    int k=left;
    
    while (k < right) {
        if (L[i].value <= R[j].value) {
            A[k] = L[i];
            i++;
        } else {
            A[k] = R[j];
            j++;
        }
        k++;
    }
}

void MergeSort(std::vector<Card>& A, int left, int right) {
    if (left+1 < right) {
        int mid = (left + right) / 2;
        MergeSort(A, left, mid);
        MergeSort(A, mid, right);
        Merge(A, left, mid, right);
    }
}

int main() {
    int N, tempi;
    char tempc;
    std::cin >> N;
    
    std::vector<Card> A, B;
    for (int i=0; i<N; ++i) {
        std::cin >> tempc >> tempi;
        A.push_back(Card{tempc, tempi});
        B.push_back(Card{tempc, tempi});
    }
    
    QuickSort(A, 0, N-1);
    MergeSort(B, 0, N);
    
    bool ans = true;
    for (int i=0; i<N; ++i) {
        if (A[i].suit != B[i].suit) {
            ans = false;
            break;
        }
    }
    
    std::cout << (ans ? "Stable" : "Not stable") << std::endl;
    for (auto &&e : A) {
        std::cout << e.suit << " " << e.value << std::endl;
    }
}


Measured memory_bytes: 5672
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <fstream>
#include <set>
#include <stack>
#include <queue>
#include <list>
using namespace std;
typedef long long int64;
typedef vector<int> vec;
typedef vector<int64> vec64;
#define db(x) cout << "> " << #x << ": " << x << "\n";
#define ss cout << " ";
#define ct(x) cout << x;
#define nn cout << "\n";
#define cts(x) cout << x << " ";
#define ctn(x) cout << x << "\n";
#define qr queries();
void solve();
void YN(bool b){if (b){ctn("YES");}else{ctn ("NO");}};
void yn(bool b){if (b){ctn("Yes");}else{ctn ("No");}};
void queries(){int n;cin >> n;while (n--)solve();}
// // // // // // // // // // // // // // // // // // // // // // 
/*                  TEMPLATE - VANILLA                         */
// // // // // // // // // // // // // // // // // // // // // //
int64 q, n;

void solve(){

    return;
}


int main(){
    int n;
    cin >> n;
    int k = 1000;
    while (k < n){
        k+=1000;
    }
    ctn(k - n);
    return 0;
}


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

using namespace std;


void solve() {
    int X; cin >> X;
    int a = X / 500;
    X %= 500;
    int b = X / 5;
    int ans = a * 1000 + b * 5;
    cout << ans << endl;
}


int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,T,c,t,ans=1e9;
	cin>>n>>T;
	while(cin>>c>>t)
		if(t<=T)
			ans=min(ans,c);
	if(ans==1e9)
		cout<<"TLE"<<endl;
	else
		cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int n;
map<int,int> s;

int main(){
  cin >> n;
  int a = INF;
  rep(i,0,n) {
    int x;
    cin >> x;
    a = min(a,x);
    s[x]++;
  }
  bool t = true;
  if(s.size() > 2)t = false;
  if(s.size() == 2){
    int k = s[a];
    int l = s[a+1];
    if(k>a || l < 2*(a+1-k))t=false;
  }else if(s.size() == 1){
    if(a == n-1)t = true;
    else{
      a--;
      int k = 0;
      int l = n;
      if(k>a || l < 2*(a+1-k))t=false;
    }
  }
  cout << (t?"Yes":"No") << endl;

  return 0;
}


Measured memory_bytes: 4992
#include<string>
#include<iostream>
#include<vector>

using namespace std;

bool check(int a)
{
  for(int i =2;i*i<=a;i++)
  {
    if(a%i==0) return false;
  }
  return true;
}
    
  

int main(void){
  int x;
  cin>>x;

  while(1)
  {
    if(check(x))
    {
      cout<<x<<endl;
      return 0;
    }
    x++;
  }
      
   	

}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#define For(i , j , k) for (int i = (j) , _##end_ = (k) ; i <= _##end_ ; ++ i)
#define Fordown(i , j , k) for (int i = (j) , _##end_ = (k) ; i >= _##end_ ; -- i)
#define Set(a , b) memset(a , b , sizeof(a))
#define pb push_back
#define INF (0x3f3f3f3f)
#define Mod (1000000007)
using namespace std;
typedef long long LL;

template <typename T> inline bool chkmax(T &a , T b) { return a < b ? (a = b , 1) : 0; }
template <typename T> inline bool chkmin(T &a , T b) { return b < a ? (a = b , 1) : 0; }

int _ , __;
char c_;
inline int read()
{
	for (_ = 0 , __ = 1 , c_ = getchar() ; !isdigit(c_) ; c_ = getchar()) if (c_ == '-') __ = -1;
	for ( ; isdigit(c_) ; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
	return _ * __;
}

inline void file()
{
#ifdef hany01
	freopen("permutation.in" , "r" , stdin);
	freopen("permutation.out" , "w" , stdout);
#endif
}

const int maxn = 500010 , maxm = 10000000;

int v[maxm] , in[maxn] , nex[maxm] , beg[maxn] , n , k , p[maxn] , e , ans[maxn];

inline void add(int uu , int vv)
{
//	printf("%d %d\n" , uu , vv);
	v[++ e] = vv;
	++ in[vv];
	nex[e] = beg[uu];
	beg[uu] = e;
}

struct Item
{
	int key , pos;
	bool operator < (const Item &item) const
	{
		return key < item.key;
	}
};

typedef set<Item>::iterator It;
It it;

inline void init()
{
	n = read();
	k = read();
	For(i , 1 , n)
		p[i] = read();
	set<Item> st;
	For(i , 1 , n)
	{
		if (i >= k + 1)
			st.erase((Item){p[i - k] , i - k});
		it = st.upper_bound((Item){p[i] , i});
		if (it != st.end())
			add(i , (*it).pos);
/*		printf("%d:" , p[i]);
		for (it = st.begin() ; it != st.end() ; ++ it)
			printf(" %d" , (*it).key);
		putchar('\n');*/
		st.insert((Item){p[i] , i});
	}
	st.clear();
	For(i , 1 , k - 1)
		st.insert((Item){p[i] , i});
//	putchar('\n');
	For(i , 1 , n)
	{
		st.erase((Item){p[i] , i});
		if (i + k - 1 <= n)
			st.insert((Item){p[i + k - 1] , i + k - 1});
		it = st.upper_bound((Item){p[i] , i});
		if (it != st.end())
			add(i , (*it).pos);
/*		printf("%d:" , p[i]);
		for (it = st.begin() ; it != st.end() ; ++ it)
			printf(" %d" , (*it).key);
		putchar('\n');*/
		st.erase((Item){p[i - k + 1] , i - k + 1});
	}
}

inline void toposort()
{
	priority_queue<int , vector<int> , greater<int> > q;
	For(i , 1 , n)
		if (!in[i])
			q.push(i);
	int now = 0;
	while (!q.empty())
	{
		int u = q.top();
		q.pop();
		ans[u] = ++ now;
		for (int i = beg[u] ; i ; i = nex[i])
		{
			-- in[v[i]];
			if (!in[v[i]])
				q.push(v[i]);
		}
	}
}

inline void print()
{
	For(i , 1 , n)
		printf("%d\n" , ans[i]);
}

int main()
{
	file();
	init();
	toposort();
	print();
	return 0;
}

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

public class Main{ 
	
	static class FastReader{ 
		BufferedReader br; 
		StringTokenizer st; 

		public FastReader() 
		{ 
			br = new BufferedReader(new
					InputStreamReader(System.in)); 
		} 

		String next() 
		{ 
			while (st == null || !st.hasMoreElements()) 
			{ 
				try
				{ 
					st = new StringTokenizer(br.readLine()); 
				} 
				catch (IOException e) 
				{ 
					e.printStackTrace(); 
				} 
			} 
			return st.nextToken(); 
		} 

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

		long nextLong() 
		{ 
			return Long.parseLong(next()); 
		} 

		double nextDouble() 
		{ 
			return Double.parseDouble(next()); 
		} 

		String nextLine() 
		{ 
			String str = ""; 
			try
			{ 
				str = br.readLine(); 
			} 
			catch (IOException e) 
			{ 
				e.printStackTrace(); 
			} 
			return str; 
		} 
	}

	public static void main(String[] args) 
	{ 
        FastReader sc = new FastReader(); 
        //PrintWriter out = new PrintWriter(System.out); 

        int n = sc.nextInt();
        long[] arr = new long[n];
        long[][] dp = new long[n][n];

        long sum = 0;
        for(int i=0;i<n;i++){
        	arr[i] = sc.nextLong();
        	sum += arr[i];
        }

        for(int l=0;l<n;l++){
        	for(int i=0;i<n-l;i++){
        		int j = i+l;
        		if(l==0)
        			dp[i][j] = arr[i];
        		else if(l==1)
        			dp[i][j] = Math.max(arr[i], arr[j]);
        		else
        			dp[i][j] = Math.max(arr[i] + Math.min(dp[i+2][j], dp[i+1][j-1]), arr[j] + Math.min(dp[i+1][j-1], dp[i][j-2]));
        	}
        }
        
        System.out.println( 2*dp[0][n-1]-sum );
	}
}


Measured memory_bytes: 128964
import java.util.Scanner;



public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] array = new int[6];
		for (int i = 0; i < array.length; i++) {
			array[i] = scan.nextInt();
		}
		String order = scan.next();
		scan.close();
		Dice dice = new Dice(array);
		array = dice.roll(order);
		System.out.println(array[0]);
	}
}
	

class Dice {
	int[] num = new int[6];
	Dice() {
	}

	Dice(int[] array) {
		for (int i = 0; i < array.length; i++) {
			this.num[i] = array[i];
		}
	}
	
	public int[] getNum() {
		return this.num;
	}
	
	public int getNumber(int i) {
		return this.num[i];
	}
	
	// ??????????????¢??????????????????
	public int[] roll(String order) {
		int now_1 = 0;	int now_2 = 1;	int now_3 = 2;	int tmp;
		int[] array = getNum();
		char[] check = {'N', 'E', 'S', 'W'};
		for (int i = 0; i < order.length(); i++) {
			for (int j = 0; j < check.length; j++) {
				if (order.charAt(i) == check[j]) {
					switch (j + 1) {
						case 1:
							tmp = now_1;
							now_1 = now_2;
							now_2 = 5 - tmp;
							break;
						case 2:
							tmp = now_1;
							now_1 = 5 - now_3;
							now_3 = tmp;
							break;
						case 3:
							tmp = now_1;
							now_1 = 5 - now_2;
							now_2 = tmp;
							break;
						case 4:
							tmp = now_1;
							now_1 = now_3;
							now_3 = 5 - tmp;
							break;
					}
				}
			}
		}
		int[] cp_array = new int[array.length];
		cp_array[0] = array[now_1]; cp_array[1] = array[now_2];
		cp_array[2] = array[now_3]; cp_array[3] = array[5 - now_3];
		cp_array[4] = array[5 - now_1]; cp_array[5] = array[5 -now_2];
		return cp_array;
	}
}

Measured memory_bytes: 26328
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  if(a%2==1&&b%2==1){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
   
  return 0;  
}

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

using namespace std;
typedef long long ll;
struct node
{
    int next;
    ll c;
};
node no[5005];
vector<int> vv[5005];
ll dp[5005][5005];
ll zz[5005];
int res=0;
ll max_=-1e10;
int flag[5005]={0};
//ll ans=0;
int main()
{
    for(int i=0;i<5005;i++)
        vv[i].clear();
    for(int i=0;i<5001;i++)
    {
        for(int j=0;j<5001;j++)
            dp[i][j]=-10000000000;
    }
    int n,K;
    cin>>n>>K;
    for(int i=1;i<=n;i++)
    {
        cin>>no[i].next;
    }
    for(int i=1;i<=n;i++)
    {
        cin>>no[i].c;
    }
    for(int i=1;i<=n;i++)
    {
        if(flag[i]==0)
        {
            res++;
            int index=i;
            while(flag[index]==0)
            {
                vv[res].push_back(index);
                //cout<<index<<" ";
                flag[index]=1;
                index=no[index].next;
            }
            //cout<<endl;
        }
    }
    for(int i=1;i<=res;i++)
    {
        for(int j=0;j<vv[i].size();j++)
        {
            ll ans=0;
            for(int k=1;k<=vv[i].size();k++)
            {
                dp[i][k]=max(dp[i][k-1],dp[i][k]);
                ans=ans+no[vv[i][(j+k)%vv[i].size()]].c;
                dp[i][k]=max(dp[i][k],ans);

            }
            zz[i]=ans;
            //cout<<zz[i]<<endl;
        }
    }
    /*for(int i=1;i<=res;i++)
    {
        for(int j=1;j<=vv[i].size();j++)
        {
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }*/
    for(int i=1;i<=res;i++)
    {
        if(K>vv[i].size())
        {
            if(zz[i]>0)
            {
                ll cc=K/vv[i].size();
                ll dd=K%vv[i].size();
                ll bns=cc*zz[i];
                if(dd!=0)
                    bns=bns+dp[i][dd];
                max_=max(max_,bns);
                bns=(cc-1)*zz[i];
                bns=bns+dp[i][vv[i].size()];
                max_=max(max_,bns);
            }
            else
            {
                max_=max(max_,dp[i][vv[i].size()]);
            }
        }
        else
        {
            max_=max(max_,dp[i][K]);
        }
    }
    cout<<max_;
    return 0;
}


Measured memory_bytes: 199396
/**
 *   author:  cryforthemoon46
 *   created: 26.05.2020 23:31:48
**/
#include <bits/stdc++.h>
using namespace std;

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

    // 各観光スポットiの座標を記録
    int A[N + 2]; A[0] = 0; A[N + 1] = 0;
    for (int i = 1; i <= N; i++) cin >> A[i];
    
    // 各観光スポットまで順番に訪れた場合のコストを記録
    int S[N + 2]; S[0] = 0;
    for (int i = 1; i <= N + 1; i++) {
        S[i] = S[i - 1] + abs(A[i] - A[i - 1]);
    }

    // 観光スポットiを訪れた場合のコストを出力
    for(int i = 1; i <= N; i++) {
        int ans = S[i - 1] + abs(A[i + 1]  - A[i - 1]) + (S[N + 1] - S[i + 1]);
        cout << ans << endl;
    }
}

Measured memory_bytes: 2048
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

char *s[100000];
int ccmp(const void *a, const void *b) {
	return *((char *)a) - *((char *)b);
}
int scmp(const void *a, const void *b) {
	return strcmp(*((char **)a), *((char **)b));
}

int isanag(char *, char *);

int main(int argc, char *argv[]) {
	int sr;
	int N;
	int i,j;
	char *inp;
	long count=0;
	long cont;

	sr=scanf("%d", &N);

	for (i=0; i<N; i++) {
		inp = (char *)malloc(sizeof(char)*11);
		sr=scanf("%s", inp);
		qsort(inp, 10, sizeof(char), ccmp);
		s[i] = inp;
	}
	qsort(s, N, sizeof(char *), scmp);
/*
	for (i=0; i<N; i++) {
		printf("%s\n", s[i]);
	}
*/
	cont = 0;
	for (i=0; i<N-1; i++) {
		if (strcmp(s[i], s[i+1]) == 0) {
			cont++;
//printf("%s %s %ld\n", s[i], s[i+1], cont);
		} else {
			if (cont>0) count += cont*(cont+1)/2;
			cont = 0;
		}
	}
	if (cont>0) count += cont*(cont+1)/2;

	printf("%ld\n", count); fflush(stdout);

	return 0;

}
int isanag(char *s1, char *s2) {
	int i;
	char sc[11];
	char *p;

	strcpy(sc, s2);
	for (i=0; i<10; i++) {
		p = strchr(sc, s1[i]);
		if (!p) return 0;
		*p='-';
	}
	return 1;
}


Measured memory_bytes: 6268
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define MOD 1000000007ULL;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {
	ll N,M;
  	cin>>N>>M;
  	ll mod=1;
  
  	rep(i,N) mod=mod*(i+1)%MOD;
  	rep(j,M) mod=mod*(j+1)%MOD;
  	if(M==N) mod=mod*2%MOD;
  	if(abs(M-N)>=2) mod=0;
  	cout<<mod<<endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<ctime>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<deque>
#include<map>
#include<cstring>
#include<stack>
#include<cctype>
#include<cstdio>
#include<bitset>
#ifdef LOCAL
	#define enu(i,n) for(int i=0;i<n;i++)
	#define tri(x) x*(x+1)/2;
	#define sqrsum(x) x*(x+1)*(2*x+1)/6;
	#define sqrsum_range(a,b) sqrsum(b)-sqrsum(a-1);
#endif
#define FOR(i,a,b) for(int i=a,_b=b;i<_b;i++)
#define REP(i,a,b) FOR(i,a,b+1)
#define ll_max 9223372036854775807LL
#define ll_min -9223372036854775808LL
#define int_max 2147483647
#define int_min -2147483648
#define PI 3.14159265358979323846265
#define eps 0.00000001
#define elif else if
using namespace std;
void fast()
{
	cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(false);
	return ;
}
bool isprime(int x)
{
	if(x<2)
		return false;
	for(int i=2;i<=sqrt(x);i++)
		if(x%i==0)
			return false;
	return true;
}
int GCD(int a,int b)
{
	return (b?GCD(b,a%b):a);
}
struct Tm
{
	int h,m,s;
	bool add()
	{
		s++;
		if(s==60)
			m++,
			s=0;
		if(m==60)
			h++,
			m=0;
		return (h<100);
	}
	void print()
	{
		printf("%02d:%02d:%02d",h,m,s);
		return ;
	}
	void println()
	{
		print();
		puts("");
	}
};
int A[200200],N,B[200200];
int main()
{
	cin>>N;
	for(int i=1;i<=N;i++)
		cin>>A[i];
	for(int i=N;i;i--)
	{
		int x=0;
		for(int j=i+i;j<=N;j+=i)
			x=x^B[j];
		B[i]=x^A[i];
	}
	int cnt=0;
	for(int i=1;i<=N;i++)
		if(B[i])
			cnt++;
	cout<<cnt<<endl;
	for(int i=1;i<=N;i++)
		if(B[i])
			cout<<i<<" ";
	return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
// Welcome to my source code!

const int INF = 1001001001;

int n, a, b, c;
int l[10];

ll f(int cur, int x, int y, int z) {
    if (cur == n) {
        if (x == 0 || y == 0 || z == 0) return INF;
        return abs(x - a) + abs(y - b) + abs(z - c);
    }
    ll res = INF;
    res = min(res, f(cur + 1, x, y, z));
    res = min(res, f(cur + 1, x + l[cur], y, z) + (x == 0 ? 0 : 10));
    res = min(res, f(cur + 1, x, y + l[cur], z) + (y == 0 ? 0 : 10));
    res = min(res, f(cur + 1, x, y, z + l[cur]) + (z == 0 ? 0 : 10));
    return res;
}

int main() {
    cin >> n >> a >> b >> c;
    for (int i = 0; i < n; i++) cin >> l[i];
    ll ans = f(0, 0, 0, 0);
    cout << ans << endl;
}

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

using std::cin;
using std::cout;
using std::endl;
using std::vector;

int main(void) {
	while (1) {
		int member_num;
		cin >> member_num;
		if (member_num == 0) {
			break;
		}

		vector<vector<int>> member_info;
		for (int i = 0; i < member_num; i++) {
			vector<int> info;
			int info_num;
			cin >> info_num;
			for (int j = 0; j < info_num; j++) {
				int tmp;
				cin >> tmp;
				info.push_back(tmp);
			}
			member_info.push_back(info);
		}

		int leak_num;
		cin >> leak_num;
		vector<int> leak;
		for (int i = 0; i < leak_num; i++) {
			int tmp;
			cin >> tmp;
			leak.push_back(tmp);
		}

		vector<bool> flag(member_num, true);
		int flag_num = member_num;
		for (auto leak_itr = leak.begin(); leak_itr != leak.end(); ++leak_itr) {
			for (int i = 0; i < member_num; i++) {
				if (!flag[i]) {
					continue;
				}

				bool hit = false;
				for (auto info_itr = member_info[i].begin(); info_itr != member_info[i].end(); ++info_itr) {
					if (*info_itr == *leak_itr) {
						hit = true;
						break;
					}
				}
				if (hit == false) {
					flag[i] = false;
					flag_num--;
				}
			}
		}

		if (flag_num != 1) {
			cout << -1 << endl;
		} else {
			for (int i = 0; i < member_num; i++) {
				if (flag[i]) {
					cout << i + 1 << endl;
					break;
				}
			}
		}
	}
	return 0;
}



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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int H, W, N; scanf("%d %d %d", &H, &W, &N);
  int a, b;
  vector<pair<int, int>> V;
  for (int i = 0; i < N; ++i) {
    scanf("%d %d", &a, &b);
    for (int dr = -2; dr <= 0; ++dr) {
      for (int dc = -2; dc <= 0; ++dc) {
        int nr = a + dr, nc = b + dc;
        if (1 <= nr and nr + 2 <= H and 1 <= nc and nc + 2 <= W) {
          V.push_back(make_pair(nr, nc));
        }
      }
    }
  }
  vector<ll> ans(10, 0);
  sort(V.begin(), V.end());
  int n = V.size();
  for (int i = 0, j; i < n; i = j) {
    j = i;
    while (j < n and V[j] == V[i]) { ++j; }
    int cnt = j - i;
    ++ans[cnt];
  }
  ans[0] = 1LL* (H - 2) * (W - 2) - accumulate(ans.begin(), ans.end(), 0);
  for (int i = 0; i < 10; ++i) {
    printf("%lld\n", ans[i]);
  }
  return 0;
}


Measured memory_bytes: 10604
#include<bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
using namespace std;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define MEM(x,a) memset((x),a,sizeof((x)))
#define F first
#define S second
#define imx INT_MAX
const long long MOD = (long long)(1e9+7);
const long long MMX = (long long)(1e18);
typedef long long LL;
typedef pair<int,int> pii;
int a,b,c;
int main()
{
    scanf("%d %d %d",&a,&b,&c);
    printf("%d",min(a+b+1,c)+b);
}


Measured memory_bytes: 3768
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int N, K;
	string S;
	cin >> N >> K >> S;
	S[K - 1] += 0x20;
	cout << S << endl;

	return 0;
}


Measured memory_bytes: 256
n, m = list(map(int, input().split()))
a = [0] * m
b = [0] * m
for i in range(m):
    a[i], b[i] = list(map(int, input().split()))
count = 0

for i in range(1, n + 1):
    count = a.count(i) + b.count(i)
    print(count)

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

int main() {
  int N;
  cin >> N;


  unsigned long x1 = 1, x2 = 2;
  unsigned long x = 1;
  for(int i = 0; i < N - 1; ++i) {
      x = x1 + x2;
      x2 = x1;
      x1 = x;
  }

  cout << x << endl;
}

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

int main(){

  int k, s, ans=0;

  cin>>k>>s;

  for(int x=0;x<=k;x++){
    for(int y=0;y<=k;y++){
      if(0<=s-x-y&&s-x-y<=k) ans++;
    }
  }

  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fo(x, n) for(int i = x; i <= n; i++)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector <int> vi;
const int MOD = 1e9 + 7;
void solve(){
    int a[5];
    cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
    sort(a, a + 5);
    int k;
    cin >> k;
    for(int i = 0; i < 5; i++){
        for(int j = 0; j < 5; j++){
            if(abs(a[i] - a[j]) > k){
                cout << ":(";
                return;
            }
        }
    }
    cout << "Yay!";
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
	int T = 1;
    //cin >> T;
    fo(1, T){
        solve();
    }
}




Measured memory_bytes: 256
n,m = map(int,input().split())
ac = 0
wa = 0
aclist = {}
walist = {}
for i in range(n):
    aclist[i + 1] = 0
    walist[i + 1] = 0

for i in range(m):
    a,b = input().split()
    a = int(a)
    if aclist[a] == 1:
        continue
    elif b == 'WA':
        walist[a] += 1
    elif b == 'AC':
        aclist[a] += 1
        ac += 1
        wa += walist[a]
        
print(ac, wa)


Measured memory_bytes: 24212
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
set<int> se[26];
int N,n,m,a,b,d,l,r;
char c;
string s;
int main(void){
    cin>>N>>s>>n;
    for(int i=0;i<s.size();i++){
        se[s[i]-'a'].insert(i);
    }
    for(int i=0;i<n;i++){
        int ans=0;
        cin>>a>>b;
        b--;
        if(a==1)cin>>c;
        else {cin>>d;d--;}
        if(a==1){
            se[s[b]-'a'].erase(b);
            se[c-'a'].insert(b);
            s[b]=c;
        }
        else{
            for(int i=0;i<26;i++){
                auto itr1=se[i].upper_bound(d);
                auto itr2=se[i].lower_bound(b);
                if(itr1!=itr2)ans++;
            }
            cout<<ans<<endl;
        }
        //cout<<s<<endl;
    }
}


Measured memory_bytes: 24196
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, cnt=0;
  string S;
  cin >> N >> S;
  REP(i,N) {
    if(S[i]!=S[i+1]) cnt++;
  }
  cout << cnt << endl;
}

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

int main()
{
    ll k,a,b;
    cin>>k>>a>>b;

    if(a>=b)
    cout<<(k+1);
    else
    {
        if(k<=a)
        cout<<(k+1);
        else
        {
            ll te=(k-a)/2,m;
           
            if((k-a)%2==0)
                m=((te-1)*(b-a)+1+b);
            else
            m=(te*(b-a)+b);
            cout<<max(m,k+1);
        }
    }
}

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

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

const int N = 2e5 + 11;
const int M = 1e6 + 11;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
 
int son[N];

int main(int argc, char **args){
   // freopen("in.txt", "r", stdin);
    int n; cin >> n;
    for(int i = 1; i < n; i++){
        int fa; scanf("%d", &fa);
        son[fa]++;
    }

    for(int i = 1; i <= n; i++){
        printf("%d\n", son[i]);
    }
return 0;
}


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;

  for (int i = A; i <= A * B; i += A) {
    if (i % B == C) {
      cout << "YES" << endl;
      return 0;
    }
  }

  cout << "NO" << endl;
}

Measured memory_bytes: 256
n = 0
s = ""

def format_input(filename = None):
	global n
	global s
	if filename == None:
		n = int(input())
		s = str(input())

	elif filename == '__random__':
		from random import randint as rng
		from random import choices
		n = rng(1, 4 * 10**3)
		s = ''.join(choices('RGB', k = n))
		print(n)
		print(s)

def get_answer():
	r = []
	g = []
	b = []
	for i in range(len(s)):
		if s[i] == 'R':
			r.append(i)
		elif s[i] == 'G':
			g.append(i)
		else:
			b.append(i)

	answer = len(r) * len(g) * len(b)

	for l in r:
		for m in g:
			if (l + m) % 2 == 0:
				if s[(l + m) // 2] == 'B':
					answer -= 1
			if max(l, m) + abs(l - m) < n:
				if s[max(l, m) + abs(l - m)] == 'B':
					answer -= 1
			if min(l, m) - abs(l - m) >= 0:
				if s[min(l, m) - abs(l - m)] == 'B':
					answer -= 1
	return answer

if __name__ == '__main__':
	format_input()

	ans = get_answer()
	print(ans)


Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
int n,a[200001],s[200001];
map<int,int> mp;
bool judge(int x)
{
    mp.clear();
    int cnt=0;
    for(int i=2;i<=n;i++)
        if(a[i]<=a[i-1])
        {
            if(x==1) return false;
            while(cnt&&s[cnt-1]>a[i])
                mp[s[cnt-1]]=0,cnt--;
            int t=a[i];
            while(mp[t]+1>=x&&t>0) mp[t]=0,t--;
            if(t<=0) return false;
            mp[t]++;
            s[cnt++]=t;
        }
    return true;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    int l=1,r=n,ans;
    while(l<=r)
    {
        int m=l+r>>1;
        if(judge(m)) ans=m,r=m-1;
        else l=m+1;
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 11904
import scala.io.StdIn.readLine

object Main {

  def main(args: Array[String]): Unit = {
    val Array(n, m, l) = readLine().split(" ").map(_.toInt)
    val a = Array.ofDim[Int](n, m)
    val b = Array.ofDim[Int](m, l)
    for (i <- 0 until n) {
      a(i) = readLine().split(" ").map(_.toInt)
    }
    for (i <- 0 until m) {
      b(i) = readLine().split(" ").map(_.toInt)
    }

    val c = Array.ofDim[Long](n, l)
    for (i <- 0 until n; j <- 0 until l; k <- 0 until m) {
      c(i)(j) += a(i)(k) * b(k)(j)
    }
    println(c.map(_.mkString(" ")).mkString("\n"))
  }
}



Measured memory_bytes: 54668