akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

#define ll long long

#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define fill(ar,val) memset(ar, val, sizeof(ar))
#define fill0(ar) fill((ar), 0)
#define debug(x) cout<<#x<<": "<<x<<endl

#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ii> vii;
typedef vector<ll> vi;

#define INF 1000000000000000000
#define PI 3.14159265358979323846L

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n,l;
    cin >> n >> l;

    ll sum = 0;
    ll kon = INF;
    ll mini = INF;

    fr(i,1,n)
    {
    	sum = sum + l+i-1;
    	if(abs(l+i-1)<mini)
    	{
    		mini = abs(l+i-1);
    		kon = l+i-1;
    	}
    }

    cout << sum-kon << endl;
}


Measured memory_bytes: 256
fun main(args : Array<String>) {
    val read = readString()
    if (read.length % 2 != 0) {
        println("No")
        return
    }
    for ((i, c) in read.withIndex()){
        if (i % 2 == 0 && c == 'h') continue
        else if (i % 2 == 1 && c == 'i') continue
        else {
            println("No")
            return
        }
    }

    println("Yes")
}

fun readString() = readLine()!!

Measured memory_bytes: 33588
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s; cin >> s;
    
    int ans = 653;
    for (int i = 0; i < s.size() - 2; i++) {
        int sub = stoi(s.substr(i, 3));
        ans = min(ans, abs(753 - sub));
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
S=input()
N=len(S)
ans=0
A=list(S[0:N//2])
B=list(S[N//2+1:])
A_R=list(reversed(A))
B_R=list(reversed(B))
if A==B and A==A_R and B==B_R:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <string.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
int a[1010];
int main(){
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	int cnt=0;
	for(int i=0;i<k;i++){
		cnt+=a[i];
	}
	cout<<cnt<<endl;
	//fixed<<setprecision(3)
	return 0;
}


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

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

  while (K>0) {
    if(A<B) break;
    B *= 2;
    K--;
  }
  while (K>0){
    if(B<C) break;
    C *= 2;
    K--;
  }

  if(A<B&&B<C){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3628
<?php
  fscanf(STDIN, "%d", $n);
  $nums = explode(' ', trim(fgets(STDIN)));
  $ans = 1;

  for ($i = 0; $i < $n; $i++) {
    if ($nums[$i] == 0) {
      $ans = 0;
      break;
    }
    $ans *= $nums[$i];
  }

  if ($ans > pow(10, 18)) {
    $ans = -1;
  }

  echo $ans;

Measured memory_bytes: 25572
function main(arg) {
  const lines = arg.trim().split('\n');
  const K = Number(lines[0]);
  const ans =
    K % 2 === 0 ? parseInt(K / 2) ** 2 : parseInt(K / 2 + 1) * parseInt(K / 2);
  console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 29664
a = int(input())
al = []
for i in range(a):
  al.append(input())
b = int(input())
bl = []
for i in range(b):
  bl.append(input())
aa = list(set(al))
c =[]
for i in range(len(aa)):
  c.append(al.count(aa[i])-bl.count(aa[i]))
print(max(max(c),0))

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

int main()
{
  int n;
  cin >> n;
  int *a = new int[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  
  int s = 0;
  bool flag = true;
  do {
    for (int i = 0; i < n; i++) {
      if (a[i] % 2 != 0) {
        flag = false;
        break;
      }
    }
    if (flag) {
      for (int i = 0; i < n; i++)
        a[i] /= 2;
      s++;
    }
  } while (flag);
  cout << s << endl;

  delete a;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
	
typedef long long ll;
typedef unsigned long long ull;
typedef long double db;
	
#define MOD 1000000007
#define mi 18446744073709551615
#define ff first
#define ss second
#define pb push_back
#define vii vector<int>
#define pii pair<int,int>
#define vpii vector<pii>

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T=1;
	//cin>>T;
	while(T--)
	{
		int d,t,s;
		cin>>d>>t>>s;
		if(ceil(float(d)/s)<=t)
			cout<<"Yes";
		else
			cout<<"No";
	}  
	return 0;
}

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

int main() {
	int n, k, h[100001], count=0;
	cin>>n>>k;
	for(int i=0;i<n;i++) cin>>h[i];
	
	for(int i=0;i<n;i++){
		if(h[i]>=k) count++;
	}
	cout<<count;
	return 0;
}

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

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

#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define reps(i,s,e) for(int i=s; i<(int)e; i++)
#define coutd(i) cout << std::fixed << std::setprecision(i)
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;

template<class T>
using Set = std::set<T>;
template<class T, class U>
using Map = std::map<T, U>;

template<class T>
using Graph = vector<vector<T>>;

const int INT_BIG = 1<<28;

int main() {
    int N;
    cin >> N;
    N %= 10;
    switch(N) {
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            cout << "hon" << endl;
            break;
        case 0:
        case 1:
        case 6:
        case 8:
            cout << "pon" << endl;
            break;
        default:
            cout << "bon" << endl;
    }
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
	string s1;
	cin>>s1;
	if (s1=="SUN") {cout<<7<<endl;return 0;}
	if (s1=="MON") {cout<<6<<endl;return 0;}
	if (s1=="TUE") {cout<<5<<endl;return 0;}
	if (s1=="WED") {cout<<4<<endl;return 0;}
	if (s1=="THU") {cout<<3<<endl;return 0;}
	if (s1=="FRI") {cout<<2<<endl;return 0;}
	if (s1=="SAT") {cout<<1<<endl;return 0;}
	return 0;
}

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

int n, q;
string s;
int ss[101010];

int main()
{
    cin >> n >> q >> s;
    rep(i, n)
    {
        if(s[i] == 'A' && s[i + 1] == 'C')
        {
            ss[i + 1] = 1;
        }
    }
    rep(i, n + 1)
    {
        ss[i + 1] += ss[i];
    }

    //rep(i, n) cout << ss[i] << " "; cout << endl;

    rep(i, q)
    {
        int l, r;
        cin >> l >> r;
        cout << ss[r - 1] - ss[l - 1] << endl;
    }
    return 0;
}

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

using namespace std;

int max(int a,int b){
	if(a>=b)return a;
	else return b;
}

int main(){

	string str;

	cin >>str;

	int data[110];
	int nowDay=0;

	//for(;nowDay < str.size();nowDay++){
		for(int i=str.size()-1-nowDay;i>=0;i--){
			int flag=0;
			char now = str.at(i);
			for(int j = i-1;j>=0;j--){
				if(now == str.at(j)){
					data[i] = max(0,i-j -nowDay-1);
					flag = 1;
					break;
				}
			}

			if(flag==0){
				data[i]=i;
			}
		}
	//}

	for(int j=0;j<str.size();j++){
		//cout<<str.at(j)<<" "<<data[j]<<endl;
	}

	int ans=100000000;
	for(int i=str.size()-1;i>=0;i--){
		int pos=i;
		int tmpAns=str.size()-1-i;
		while(pos>0){
			//cout<<"pos="<<pos<<"tmpAns="<<tmpAns<<endl;
			tmpAns = max(tmpAns,data[pos]);
			pos -= (data[pos]+1);
			if(data[pos]==0){
				continue;
			}
		}
		//cout<<endl;
		ans = min(ans,tmpAns);
	}

	cout<<ans<<endl;

	return 0;

}

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

int main(){
  int a,b,x;
  //string a, b, c, d;
  cin >> a >> b >> x;
  //cin >> s;
  if(a<=x&&x<=(a+b))cout << "YES" << endl;
  else cout << "NO" << endl;
  //else cout << (a+b)/2 << endl;
  //int x, y;
  //x = min(a,b);
  //y = min(c,d);
  //cout << x+y << endl;
  return 0;
}

Measured memory_bytes: 256
x = int(input())
primes = [i for i in range(2 * x)]
for i, b in enumerate(primes):
    if i < 2 or b == 0:
        continue
    else:
        m = (2 * x - 1) // i
        if m > 1:
            for j in range(2, m + 1):
                primes[i * j] = 0
print(min([i for i in primes if i >= x]))

Measured memory_bytes: 11032
N,K = map(int,input().split())
A =list(map(int,input().split()))
pre_a = A[0]
ans =0
def sum(n):
    if n%2==0:
        return  (1+n)*(n//2)
    else:
        return  (1+n)*(n//2)+(n//2+1)

sumk = sum(K)
sumk1 = sum(K-1)
for i,a in enumerate(A):
    counter =0
    for b in A[i+1:]:
        if a > b:
            counter += 1

    ans += counter*sumk
    back = 0
    for c in A[:i]:
        if c < a:
            back += 1
    
    ans += back*sumk1
print(ans%(10**9+7))


Measured memory_bytes: 42604
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def main():
    H, W = map(int, input().split())
    d = defaultdict(int)
    for y in range(H):
        for c in input():
            d[c] += 1

    counter = [0] * 5
    counter[4] = (H // 2) * (W // 2)

    if H % 2 == 0 and W % 2 == 0:
        pass
    elif H % 2 != 0 and W % 2 == 0:
        counter[2] = W // 2
    elif H % 2 == 0 and W % 2 != 0:
        counter[2] = H // 2
    elif H % 2 != 0 and W % 2 != 0:
        counter[2] = H // 2 + W // 2
        counter[1] = 1

    for x in [4, 2, 1]:
        for k, v in d.items():
            if v >= x and counter[x] > 0:
                n = v // x
                counter[x] -= n
                d[k] -= x * n

    if sum(counter) == 0:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()


Measured memory_bytes: 4212
#include<iostream>
#include<string>
using namespace std;
int main(void){
    string str,n,z;
    int q,a,b;
    
    
    cin >> str >> q;
    for(int i = 0;i<q;i++){
        cin >> n >> a >> b;
        
        if(n =="print"){  //printのとき
            cout << str.substr(a, b-a+1) << endl;
            
        }else if(n == "reverse"){   //reverseのとき
            string word = str.substr(a, b-a+1);
            int m = word.size();
            
            
            for(int j = 0;j<m;j++){
                str[j+a] = word[m-j-1];
            }
            
        }else if(n == "replace"){  //replaceのとき
            cin >> z;
            str = str.replace(a, b-a+1, z);
        }
        
    }
    
}


Measured memory_bytes: 3216
S = input()
S = list(S)
S_1 = S[0:int((len(S)-1)/2)]
S_2 = S[int((len(S)-1)/2)+1:len(S)]
S_2.reverse()

if S_1 == S_2:
    if len(S_1) % 2 == 0:
        S_1_1 = S_1[0:int((len(S_1)-1)/2)+1]
        S_1_2 = S_1[int((len(S_1)-1)/2)+1:len(S_1)]
        S_2_1 = S_2[0:int((len(S_2)-1)/2)+1]
        S_2_2 = S_2[int((len(S_2)-1)/2)+1:len(S_2)]
    else:
        S_1_1 = S_1[0:int((len(S_1)-1)/2)]
        S_1_2 = S_1[int((len(S_1)-1)/2)+1:len(S_1)]
        S_2_1 = S_2[0:int((len(S_2)-1)/2)]
        S_2_2 = S_2[int((len(S_2)-1)/2)+1:len(S_2)]
    S_1_2.reverse()
    S_2_2.reverse()
    if S_1_1 == S_1_2:
        if S_2_1 == S_2_2:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
    int a[10],b[10]={0},n,c,d,j=0,i;
    for(i=0;i<9;i++)
    {
        scanf("%d",&a[i]);
    }
    scanf("%d",&n);

    for(i=1;i<=n;i++)
    {
        j=0;
       scanf("%d",&c);
       while(j<9)
       {
           if(a[j]==c)
           {
               b[j]=1;
               break;
           }
           j++;
       }
    }
    if(b[0]==1&&b[1]==1&&b[2]==1)
    {
        printf("Yes");
    }
    else if(b[3]==1&&b[4]==1&&b[5]==1)
    {
        printf("Yes");
    }
    else if(b[6]==1&&b[7]==1&&b[8]==1)
    {
        printf("Yes");
    }
    else if(b[0]==1&&b[3]==1&&b[6]==1)
    {
        printf("Yes");
    }
    else if(b[1]==1&&b[4]==1&&b[7]==1)
    {
        printf("Yes");
    }
    else if(b[2]==1&&b[5]==1&&b[8]==1)
    {
        printf("Yes");
    }
    else if(b[0]==1&&b[4]==1&&b[8]==1)
    {
        printf("Yes");
    }
    else if(b[6]==1&&b[4]==1&&b[2]==1)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    return 0;
}


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

namespace AtCoder.Abc
{
    class QuestionC
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            var num_N = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            //num_N[0]  時針の長さ
            //num_N[1]  分針の長さ
            //num_N[2]  時間
            //num_N[3]  分

            //時針の角度
            //[rad] = 度 * π/180
            //30°*　時間　＝分針が0のときの時針の位置

            var num_H = (30 * num_N[2] + 0.5 * num_N[3]) * Math.PI / 180;

            //分針の角度
            var num_M = (6 * num_N[3]) * Math.PI / 180;

            var num_HM = num_H - num_M;

            if (num_HM > Math.PI) num_HM = (2 * Math.PI) - num_HM;

            //余弦の定理
            var num_AA = Math.Sqrt(Math.Pow(num_N[0], 2) + Math.Pow(num_N[1], 2) - 2 * num_N[0] * num_N[1] * Math.Cos(num_HM));

            Console.WriteLine(num_AA);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 28636
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	Scanner in = new Scanner(System.in);
	int h, w;
	char[][] map;
	boolean[][] visited;
	int[] dirx = {-1, 0, 1, -1, 1, -1, 0, 1};
	int[] diry = {-1, -1, -1, 0, 0, 1, 1, 1};
	HashSet<String> hash;
	String ans;
	int x, y;
	
	public void run() {
		while (true) {
			h = in.nextInt();
			w = in.nextInt();
			if ((h|w) == 0) break;
			map = new char[h][w];
			hash = new HashSet<String>(0);
			ans = "";
			for (int i = 0; i < h; i++) {
				String s = in.next();
				for (int j = 0; j < w; j++) {
					map[i][j] = s.charAt(j);
				}
			}

			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					for (int k = 0; k < 8; k++) {
						x = j; y = i;
						StringBuilder sb = new StringBuilder(map[y][x]);
						for ( ; ; ) {
							x = (x + dirx[k] + w) % w;
							y = (y + diry[k] + h) % h;
							sb.append(map[y][x]);
							if (hash.contains(sb.toString())) {
								if (sb.length() > ans.length() || (sb.length() == ans.length() && ans.compareTo(sb.toString()) > 0)) {
									ans = sb.toString();
								}
							} else if (sb.toString().length() >= Math.max(2, ans.length())) {
								hash.add(sb.toString());
							}
							if (x == j && y == i) break;
						}
						
					}
				}
			}
			
			if (ans.length() < 2)
				System.out.println(0);
			else
				System.out.println(ans);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 262040
N,M = map(int,input().split())
d = [[float('inf') for j in range(N)] for i in range(N)]
es = {}
for i in range(M):
    a,b,c = map(int,input().split())
    a,b = a-1,b-1
    d[a][b] = d[b][a] = c
    es[(a,b)] = es[(b,a)] = c

for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j])

ans = 0
for (a,b),c in es.items():
    if c != d[a][b]:
        ans += 1
print(ans // 2)


Measured memory_bytes: 3956
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF         1e9
#define INFLL       1e18
#define EPS         1e-9
#define REP(i,n)    for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(ll i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP(n)     cout << fixed << setprecision(n)
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }
ll gcd(ll x, ll y) {
	return y == 0 ? x : gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y) * y;
}
signed main()
{
	ll n = in();
	vector<ll>t(n);
	REP(i, n) {
		t[i] = in();
	}
	ll ans = 1;
	REP(i, n) {
		ans = lcm(ans, t[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

void err() {
	puts(-1);
	exit(0);
}

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

	int N;
	cin >> N;
	vector<int>A(N);
	vector<int>B(N);

	priority_queue<pair<ll,int>>pq;
	for (int i = 0; i < N; i++)cin >> A[i];
	for (int i = 0; i < N; i++) {
		cin >> B[i];
		pq.push({ B[i],i });
	}
	

	ll ans = 0;
	while (pq.size()) {
		auto p = pq.top();
		pq.pop();
		ll num = p.first;
		ll idx = p.second;
		if (A[idx] > B[idx])err();
		else if (A[idx] == B[idx])continue;
		ll left = B[(idx != 0)?idx-1:N-1];
		ll right = B[(idx != N-1)?idx+1:0];
		ll sum = left + right;
		if ((num - A[idx]) % sum == 0) {
			ans += (num - A[idx]) / sum;
			B[idx] = A[idx];
			continue;
		}
		if (A[idx] > max(left, right))err();
		ll k = (num - max(left, right) + sum - 1LL) / sum;
		B[idx] -= k * sum;
		ans += k;
		if (B[idx] < A[idx])err();
		pq.push({B[idx],idx});
	}
	puts(ans);
	

	return 0;
}

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

using namespace std;

#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()

typedef long long int lld;
typedef pair<int, int> pii;
typedef pair<lld, lld> pll;

int main() {
#ifndef LOCAL
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#endif

    lld n = 0;
    cin >> n;

    for (int i = sqrt(n); i >= 1; i--) {
        if (n % i == 0) {
            cout << (i + n / i) - 2 << '\n';
            break;
        }
    }

    // system("pause");
    return 0;
}

Measured memory_bytes: 256
from collections import deque

h, w = map(int, input().split())
s = [input() for _ in range(h)]


INF = 100000000
dist = [[[[INF for j2 in range(w)] for i2 in range(h)] for j1 in range(w)] for i1 in range(h)]

def dfs(i1, j1, i2, j2):
    dist[i1][j1][i2][j2] = 0
    q = deque([(i2, j2, 0)])
    while q:
        i3, j3, d = q.popleft()
        for di, dj in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
            i4 = i3 + di
            j4 = j3 + dj
            if (0 <= i4 < h) and (0 <= j4 < w):
                if s[i4][j4] == "#":
                    continue
                if d + 1 < dist[i1][j1][i4][j4]:
                    dist[i1][j1][i4][j4] = d + 1
                    q.append((i4, j4, d+1))


for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            continue
        dfs(i, j, i, j)

ans = 0
for i1 in range(h):
    for j1 in range(w):
        if s[i1][j1] == "#":
            continue
        for i2 in range(h):
            for j2 in range(w):
                if s[i2][j2] == "#":
                    continue
                ans = max(ans, dist[i1][j1][i2][j2])

print(ans)


Measured memory_bytes: 49264
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define ld long double
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mod 1000000007
#define vll vector<ll>
#define inf 1e18
#define pll pair<ll,ll>
#define ff first 
#define ss second 
#define PI acos(-1)
#define prm 998244353
#define endl '\n'
using namespace std;
using namespace __gnu_pbds; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//cout << fixed << setprecision(0)
/*
ll power(ll x,ll y)
{
	ll res=1;
	while(y>0)
	{
		if(y%2==1)res=(res*x)%mod;
		y=y/2;
		x=(x*x)%mod;
	}
	return res;
}
ll inv(ll a) 
{
return power(a,mod-2);
}
 
ll fact[2000007];
ll inr[2000007];
void pre()
{
	fact[0]=1;
	for(ll i=1;i<=2000005;i++)fact[i]=(fact[i-1]*i)%mod;
	inr[0]=1;
	for(ll i=1;i<=2000005;i++)inr[i]=inv(fact[i]);
}
 
ll ncr(ll n,ll r)
{
	ll a=(fact[n]*inr[r])%mod;
	ll b=(a*inr[n-r])%mod;
	return b;
}
 
ll spf[10000050];
void sieve()
{
	for(ll i=2;i*i<=10000030;i++)
	{
		if(spf[i]==0)
		{
			for(ll j=i+i;j<=10000030;j+=i)
			{
				if(spf[j]==0)
				{
					spf[j]=i;
				}
			}
		}
	}
}
*/
ll n,m,k;
ll a[3005][3005];
ll dp[3005][3005][5];
ll solve(ll i, ll j,ll cnt)
{
	if(i>=n||j>=m||cnt>3)return -inf;
	if(i==n-1&&j==m-1)
	{
		ll dif=0;
		if(a[i][j]!=0)dif=1;
		if(cnt+dif<=3)return a[i][j];
		return 0;
	}
	ll res=dp[i][j][cnt];
	if(res!=-inf)return res;
	res=-inf;
	ll dif=0;
	if(a[i][j]!=0)dif=1;
	if(dif==1)
	{
		if(cnt+1<=3)res=max(solve(i+1,j,0)+a[i][j],res);
		if(cnt+1<=3)res=max(solve(i,j+1,cnt+1)+a[i][j],res);
		res=max(solve(i+1,j,0),res);
		res=max(solve(i,j+1,cnt),res);
	}
	else
	{
		res=max(solve(i,j+1,cnt),res);
		res=max(solve(i+1,j,0),res);
	}
	return dp[i][j][cnt]=res;
}
int main()
{
    fastio; 
    //sieve();
    //pre();
    ll T=1;
    //cin>>T;  
    while(T--)
    {
    	cin>>n>>m>>k;
    	ll r,c,v;
    	for(ll i=0;i<3005;i++)for(ll j=0;j<3005;j++)for(ll kk=0;kk<5;kk++)dp[i][j][kk]=-inf;
    	for(ll i=0;i<k;i++)
    	{
    		cin>>r>>c>>v;
    		r--,c--;
    		a[r][c]=v;
		}
		cout<<solve(0,0,0);
	}
}

Measured memory_bytes: 427092
#include <cstdint>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i,n) for(uint_fast32_t i=0;i<(n);++i)
inline char tc(){
  static char fl[100],*A=fl,*B=fl;
  return A==B&&(B=(A=fl)+fread(fl,1,100,stdin),A==B)?EOF:*A++;  
}
inline int read(){
  int a=0;static char c;
  while((c=tc())<48||c>57);
  while(c>=48&&c<=57)a=a*10+c-48,c=tc();
  return a;
}
uint_fast32_t h[100001];
int main(){
  uint_fast32_t n=read(),a=read(),b=read();a-=b;
  double a_=1.0/a;
  rep(i,n)h[i]=read();
  uint_fast32_t left=0,right=1000000000;
  int_fast64_t temp,cnt=0,mid;
  while (right>left+1) {
    mid=(right+left)>>1;
    cnt=0;
    rep(i,n){
      temp=h[i]-b*mid+a-1;
      if(temp>0)cnt+=temp*a_;
    }
    if(cnt<=mid)right=mid;
    else left=mid;
  }
  printf("%u\n",right);
}


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

int main() {
    int N;

    cin >> N;

    int a = N;
    int num = 1;

    while(a > 10) {
        num++;
        a /= 10;
    }

    a = N;
    int sum = 0;
    for(int i = 0; i < num; i++) {
        sum += a % 10;
        a /= 10;
    }

    if(N % sum == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

char s[51][51];

void func(int i,int j){
  if(s[i-1][j] == '#'){
    s[i-1][j] = '.';
    func(i-1,j);
  }
  if(s[i+1][j] == '#'){
    s[i+1][j] = '.';
    func(i+1,j);
  }
  if(s[i][j-1] == '#'){
    s[i][j-1] = '.';
    func(i,j-1);
  }
  if(s[i][j+1] == '#'){
    s[i][j+1] = '.';
    func(i,j+1);
  }
}

int main(){
  int h,w;cin >> h >> w;
  
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      cin >> s[i][j];
    }
  }
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      if(s[i][j] == '#'){
        if(s[i][j-1] == '#'||s[i][j+1] == '#'||s[i+1][j] == '#'||s[i-1][j] == '#'){
          func(i,j);
        }
      }
    }
  }
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      if(s[i][j] == '#'){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

using namespace std;

int main(){
	string s,a;
	cin >> s >> a;
	s += s;
	string::size_type index = s.find(a);
	if (index == string::npos) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}

	return 0;
}

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


def main():
    import sys
    input = sys.stdin.readline

    n = int(input())
    ans = [0 for _ in range(10 ** 6 + 2000)]
    candidate = 110

    for x in range(1, candidate + 1):
        for y in range(1, candidate + 1):
            for z in range(1, candidate + 1):
                total = 0
                total += (x ** 2) + (y ** 2) + (z ** 2)
                total += (x * y) + (y * z) + (z * x)

                if total < (10 ** 6 + 2000):
                    ans[total] += 1

    for i in range(1, n + 1):
        print(ans[i])


if __name__ == '__main__':
    main()


Measured memory_bytes: 16996
#!/usr/bin/env python3
import sys
import functools
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(N: int, M: int, Q: int,
          a: "List[int]", b: "List[int]", c: "List[int]", d: "List[int]"):

    # 全列挙行けるかを確認
    @functools.lru_cache(maxsize=None)
    def f(n, m):
        if n == 1:
            return m
        ret = 0
        for i in range(m, 0, -1):
            ret += f(n-1, i)
        return ret
    # print(f(N, M))

    samples = []
    # 全列挙

    def rec(curr, lower, d):
        # d: 今の深さ
        if d < N:
            for i in range(lower, M+1):
                rec(curr+[i], i, d+1)
        else:
            for i in range(lower, M+1):
                samples.append(curr+[i])

    max_tot = -INF
    rec([], 1, 1)

    # print(len(samples))
    for A in samples:  # 10^5程度のループ
        # print(A)
        tot = 0
        for aa, bb, cc, dd in zip(a, b, c, d):
            if A[bb-1] - A[aa-1] == cc:
                tot += dd
        max_tot = max(tot, max_tot)
    print(max_tot)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    a = [int()] * (Q)  # type: "List[int]"
    b = [int()] * (Q)  # type: "List[int]"
    c = [int()] * (Q)  # type: "List[int]"
    d = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = int(next(tokens))
        d[i] = int(next(tokens))
    solve(N, M, Q, a, b, c, d)


if __name__ == '__main__':
    main()


Measured memory_bytes: 23456
#include <stdio.h>
#include <stdlib.h>

int *check(int *h, int n) {
    int i, max = 0;
    int *max_pre = (int*)malloc((n+2)*sizeof(int));
    for(i = 0; i < n; ++i) {
        max = (max < h[i])? h[i] : max;
        max_pre[i] = max;
    }
    return max_pre;
}

void solve(int *h, int n){
    int i, cnt = 0;
    int *max_prev = check(h, n);
    for(i = 0; i < n; ++i) {
        if(max_prev[i] <= h[i]) { ++cnt; /*printf("(%d: %d)", i, h[i]);*/ }
    }
    //printf("\n");
    printf("%d\n", cnt);
    free(max_prev);
}

int main()
{
    int n, i;
    scanf("%d", &n);
    int *h = (int*)malloc((n+2)*sizeof(int));
    for(i = 0; i < n; ++i) { scanf("%d", &h[i]); }
    solve(h, n);
    free(h);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
const double PI  =3.141592653589793238463; 
using namespace std;
typedef long long ll;
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define MOD 1000000007
#define endl "\n"
#define sz(a) (int)((a).size())
#define all(x) (x).begin(), (x).end()
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define OTP(s) cout<<s<<endl;
#define FOR(i,j,k,l) for(ll i=j;i<k;i+=l)
#define REP(i,j) FOR(i,0,j,1)
inline ll add(ll a, ll b){a += b; if(a >= MOD)a -= MOD; return a;}
inline ll sub(ll a, ll b){a -= b; if(a < 0)a += MOD; return a;}
inline ll mul(ll a, ll b){return (ll)((ll) a * b %MOD);}
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
long long fast_power(long long base, long long power) {
    long long result = 1;
    while(power > 0) {
 
        if(power % 2 == 1) { // Can also use (power & 1) to make code even faster
            result = (result*base);
        }
        base = (base * base);
        power = power / 2; // Can also use power >>= 1; to make code even faster
    }
    return result;
}
ll min(ll a,ll b)
{
    return a>b?b:a;
}
ll max(ll a,ll b)
{
    return a>b?a:b;
}
void SieveOfEratosthenes(ll n, set<ll> &s) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (ll p=2; p<=n; p++) 
       if (prime[p]) s.insert(p*p); 
}
#define INF 1e9+5
int main()
{
    ll n;
    cin>>n;
    vl h(n);
    for(ll i=0;i<n;i++)
    {
        cin>>h[i];
    }
    vl dp(n,INF);
    dp[0]=0;
    for(ll i=0;i<n;i++)
    {
        for(ll j=i+1;j<=i+2;j++)
        {
            if(j<n)
            {
                dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
            }
        }
    }
    //prv(dp);
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
#pragma GCC optimize("Ofast","unroll-loops")
#pragma GCC target("avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); ++i)
#define iter(it,c) for (__typeof((c).begin()) \
  it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
const int INF = ~(1<<31);

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T> T smod(T a, T b) {
  return (a % b + b) % b; }

vii A;
int n, mW;
ll memo[105][100050];

ll dp(int at, int w) {
  if (at > n-1) return 0;
  if (memo[at][w] != -1) return memo[at][w];
  ll bst = dp(at+1,w);
  if (w + A[at].first <= mW) {
    bst = max(bst, dp(at+1,w+A[at].first)+A[at].second);
  }
  return memo[at][w] = bst;
}

int main() {
  cin >> n >> mW;
  A = vii(n);
  memset(memo, -1, sizeof(memo));
  rep(i,0,n) cin >> A[i].first >> A[i].second;
  cout << dp(0, 0) << endl;
  return 0;
}

Measured memory_bytes: 82304
#include <stdio.h>

#define N 100

int
main (
  )
{
  int i;

  for ( ; ; )
  {
    int s[ N ];
    int n, k;

    scanf ( "%d%d", &n, &k );
    if ( !( n | k ) ) break ;

    for ( i = 0; i < k; ++i )
    {
      scanf ( "%d", &s[ i ] );
    }

    while ( n-- )
    {
      for ( i = 0; i < k; ++i )
      {
        int b;

        scanf ( "%d", &b );
        s[ i ] -= b;
      }
    }

    for ( i = 0; i < k; ++i )
    {
      if ( s[ i ] < 0 ) break ;
    }

    puts ( i == k ? "Yes" : "No" );
  }

  return ( 0 );
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

const int MAX_N = 50000, MAX_M = 20;

int n, m, c[MAX_M];

int dp[MAX_N + 1];

int main() {
    cin >> n >> m;
    REP(i, m) cin >> c[i];
    REP(i, n + 1) dp[i] = MOD;
    dp[0] = 0;
    REP(i, n) {
        REP(j, m) {
            if (i + c[j] <= n) dp[i + c[j]] = min(dp[i + c[j]], dp[i] + 1);
        }
    }
    PRINT(dp[n]);
    return 0;
}


Measured memory_bytes: 3288
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	private static int n;

	public static void main(String[] args) {

		Main main = new Main();

		List<Integer> list = new ArrayList<>();
		int[][] arr = main.scan();
		int candies = 0;

		int f = 0;
		for (int i = 0; i < n; i++) {
			f += arr[0][i];
			for (int j = i; j < n; j++) {
				candies += arr[1][j];
			}
			list.add(f + candies);
			candies = 0;
		}

		System.out.println(list.stream().sorted((v1, v2) -> v2 - v1).findFirst().get());
	}

	private int[][] scan() {

		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		int[][] arr = new int[2][n];
		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < n; j++) {
				arr[i][j] = sc.nextInt();
			}
		}
		sc.close();
		return arr;
	}
}

Measured memory_bytes: 26828
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
#include<stdio.h>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

LL gcd(LL a, LL b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}

int main(){
    string S;
    cin >> S;
    bool exist=false;
    for(int i=0;i<3;++i){
        if(S[i]==S[i+1]) 
        {
            exist=true;
        }
    }
    if(exist) cout << "Bad";
    else cout << "Good";
    }

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()

#define PI 3.14159265359

using namespace std;
typedef long long unsigned int ll;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
vector<ll> fibs(100, -1);
ll fib(int n){
    if(fibs[n]!=-1) return fibs[n];
    if(n==0 || n==1) return 1;

    return fibs[n] = fib(n-2) + fib(n-1);
}

int main()
{
    int n; cin >> n;
    pr(fib(n));
    return 0;}


Measured memory_bytes: 3116
S = input()
flagA = False
flagB = False
if 1 <= int(S[2:4])<= 12:
  flagB = True
if 1 <= int(S[0:2])<= 12:
  flagA = True
if flagA and flagB:
  print("AMBIGUOUS")
elif flagA and not flagB:
  print("MMYY")
elif flagB and not flagA:
  print("YYMM")
else:
  print("NA")

Measured memory_bytes: 8976
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>

using namespace std;
char st[30];
int main()
{
    scanf("%s",st);
    for (int i=0;i<strlen(st);++i)
        if (st[i]==',') printf(" ");
    else printf("%c",st[i]);
    printf("\n");
    return 0;
}


Measured memory_bytes: 256
/*
h3110_fr13nd,
 
AUTHOR : @sam_jn
*/
 
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
using namespace std;
// using namespace __gnu_pbds;
// typedef tree<pair<int, int>, null_type, less_equal<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define MOD 1000000007
#define pb push_back
#define ff first
#define ss second
#define in(a, n) for(int i = 0; i < n; i++) cin >> a[i];
#define ot1(a, n) for(int i = 0; i < n; i++) cout << a[i] << " "; cout << endl;
#define ot2(a, n) for(int i = 0; i < n; i++) cout << a[i] << "\n";
ll pwr(ll a, ll b);
ll pwr(ll a, ll b, ll m);
int baap[200002];
int find(int i);  
bool Union(int x, int y);
ll inv(ll x) {return pwr(x, MOD - 2, MOD);}

//----------------------------------SOLUTION-BELOW-------------------------------------------// 
ll sumf[200002] = {0}, sumb[200002] = {0};
void solve(){   
    ll n, k;
    cin >> n >> k;
    
    for(ll i = 0; i <= n; i++){
        if(i == 0) sumf[i] = i;
        else sumf[i] = (sumf[i - 1] + i) % MOD;
    }
    for(ll i = 0; i <= n; i++){
        if(i == 0) sumb[n - i] = n;
        else sumb[n - i] = (sumb[n - i + 1] + n - i) % MOD;
    }
    // cout << sumb[1] << " " << sumf[2] << endl;
    // cout << sumf[]
    ll ans = 0;
    for(ll i = k; i <= n + 1; i++){
        // cout << sumb[n - i + 1] - sumf[i - 1] + 1     << endl;
        ans += (sumb[n - i + 1] - sumf[i - 1] + 1 + MOD) % MOD;
        ans %= MOD;
    }
    cout << ans;
}
int main(){


                                                            // #ifndef ONLINE_JUDGE    
                                                            // freopen("../../input", "r", stdin);
                                                            // freopen("../../output", "w", stdout);
                                                            // #else
                                                            // // online submission
                                                            // #endif


    boost
    int _ = 1;
    // cout << 0 << endl;
    // cin >> _;
    while(_--){
        solve();
        cout << endl;
    }
}
 
 
//--------------------------------------DEFININTIONS---------------------------------------
ll pwr(ll a, ll b){
    if(b == 0)
        return 1 ;
    ll c = pwr(a, b/2) ;
    c = c * c;
    if(b % 2)
        return c*a;
    return c ;
}
ll pwr(ll a, ll b, ll m){
    if(b == 0)
        return 1;
    ll c = pwr(a, b/2, m) % m ;
    c = (c * c) % m;    
    if(b % 2)
        return (c * a%m) % m;
    return c ;
}
int find(int i)  
{  
    if (baap[i] != i)  
        baap[i] = find(baap[i]);  
  
    return baap[i];  
}
 
bool Union(int x, int y)
{
    x = find(x);
    y = find(y);
    if(x == y) return false;
    baap[x] = y;
    return true;
}

Measured memory_bytes: 6796
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        string[] cin = Console.ReadLine().Split();
        int a = int.Parse(cin[0]);
        int b = int.Parse(cin[1]);
        int c = int.Parse(cin[2]);

        if (a == b || b == c || a == c)
        {
            if (a == b && b == c)
            {
                Console.WriteLine(1);
            }
            else
            {
                Console.WriteLine(2);
            }
        }
        else
        {
            Console.WriteLine(3);
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1e9 + 7

template < typename T >
void printVector (const vector < T > & vec) {
	for (const T x : vec) {
		cout << x << " ";
	}
	cout << endl;
}

template < typename T >
void printMatrix (const vector < vector < T > > & mat) {
	for (const vector < T > vec : mat) {
		printVector (vec);
	}
	cout << endl;
}

const ll INF = 1e18L + 5;

template < typename T >
void min_self (T& a, T b) {
	a = min (a, b);
}

template < typename T >
void max_self (T& a, T b) {
	a = max (a, b);
}

void add_self (int & a, int b) {
	a += b;
	if (a >= MOD) {
		a -= MOD;
	}
}

int main() {
	int n;
	scanf ("%d", &n);
	vector < int > a (n);
	for (int & x : a) scanf ("%d", &x);
	vector < vector < ll > > dp (3005, vector < ll > (3005));
	for (int l = n - 1; l >= 0; l--) {
		for (int r = l; r < n; r++){
			if (l == r) {
				dp[l][r] = a[l];
			} else {
				dp[l][r] = max (a[l] - dp[l + 1][r], a[r] - dp[l][r - 1]);
			}
		}
	}
	printf ("%lld\n", dp[0][n - 1]);
	return 0;
}



Measured memory_bytes: 70912
s = list(input())
n = len(s)
for i in range((n-3)//2):
    if s[i] != s[n-i-1]:
        print('No')
        exit()
for i in range((n+1)//4):
    if s[i] != s[(n-3)//2-i]:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 3060
N, K = (int(i) for i in input().split())

#最大化すると(N-2)*(N-1)//2組
ma = (N-2)*(N-1)//2
cou = 0
if N == 2:
    if K > 0:
        print("-1")
    else:
        print("1")
        print("1 2")
else:
    if K > ma:
        print("-1")
    else:
        print(N-1 + ma - K)
        for i in range(1, N):
            print("{} {}".format(i, N))
        for i in range(1, N):
            for j in range(1, N):
                if cou >= ma - K:
                    exit()
                if i < j:
                    print(i, j)
                    cou += 1

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#define N 55
using namespace std;

int n, m, ans, c[N];
bool v[N][N];
vector<int> a[N];
queue<int> qu;
int main()
{
	int i, t, t1, t2;
	cin >> n >> m;
	for (i = 0; i < m; i++) {
		scanf("%d %d", &t1, &t2);
		c[t1]++; c[t2]++;
		a[t1].push_back(t2), a[t2].push_back(t1);
	}
	for (i = 1; i <= n; i++) if (c[i] == 1) qu.push(i);
	while (!qu.empty()) {
		t = qu.front(), qu.pop();
		for (i = 0; i < a[t].size(); i++) {
			if (!v[t][a[t][i]]) {
				v[t][a[t][i]] = v[a[t][i]][t] = 1;
				c[a[t][i]]--, c[t]--;
				ans++;
				if (c[a[t][i]] == 1) qu.push(a[t][i]);
			}
		}
	}
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define sz(x)             (int)((x).size())
#define int               long long
#define M                 1000000007
#define MM                998244353
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount

template<typename T1,typename T2>
std::istream& operator>>(std::istream& in,pair<T1,T2> &a)
{
	in>>a.fr>>a.sc;
	return in;
}
template<typename T1,typename T2>
std::ostream& operator<<(std::ostream& out,pair<T1,T2> &a)
{
	out<<a.fr<<" "<<a.sc;
	return out;
}

int n;
int a[4];
double dp[305][305][305];
bool vis[305][305][305];

double calc(int a,int b,int c){
	if(a<0 || b<0 || c<0)return 0;
	if(a+b+c==0)return 0;
	double &ans=dp[a][b][c];
	if(vis[a][b][c])return ans;
	vis[a][b][c]=1;
	int z=n-a-b-c;
	ans = (1.0*z/n + (1+calc(a-1,b,c))*1.0*a/n + (1+calc(a+1,b-1,c))*1.0*b/n + (1+calc(a,b+1,c-1))*1.0*c/n)/(1 - 1.0*z/n);
	return ans;
}
void solve(){
	cin>>n;
	rep(i,0,n){
		int x;
		cin>>x;
		a[x]++;
	}
	cout<<calc(a[1],a[2],a[3]);
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cout<<setprecision(12);
	cout<<fixed;
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#ifdef SEIVE
		seive();
	#endif
	#ifdef NCR
		init();
	#endif
	#ifdef DSU
		cleardsu(MAXDSUSIZE);
	#endif
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef set<int> si;
typedef set<int,greater<int> > SI;


#define pi pair<int,int>
#define all(a) a.begin(),a.end()

const int mod = (1e9+7);
const int maxn = 1000010;

ull a[100005];

ull MX = (1e18);

int main()
{
    int n;
    cin>>n;
    int zro = 0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]==0ull)
            zro++;
    }

    if(zro)
    {
        cout << 0 << "\n";
        return 0;
    }

    ull result = 1ull;

    for(int i=0;i<n;i++)
    {
        if(a[i]>(MX/result))
        {
            cout << -1 << "\n";
            return 0;
        }
        result *= a[i];
    }
    cout << result << "\n";
    return 0;
}


Measured memory_bytes: 4332