akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define MAX 10010
#define NIL -1
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;

struct Node {
    int parent, left, right;
};

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d) {
    if (u == NIL) return;
    D[u] = d;
    setDepth(T[u].left, d + 1);
    setDepth(T[u].right, d + 1);
}

int setHeight(int u) {
    int h1 = 0, h2 = 0;
    if (T[u].left != NIL) {
        h1 = setHeight(T[u].left) + 1;
    }
    if (T[u].right != NIL) {
        h2 = setHeight(T[u].right) + 1;
    }
    return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u) {
    if (T[u].parent == NIL) return NIL;
    if (T[T[u].parent].left != u && T[T[u].parent].left != NIL) {
        return T[T[u].parent].left;
    }
    if (T[T[u].parent].right != u && T[T[u].parent].right != NIL) {
        return T[T[u].parent].right;
    }
    return NIL;
}

void print(int u) {
    int deg = 0;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].parent << ", ";
    cout << "sibling = " << getSibling(u) << ", ";
    if (T[u].left != NIL) deg++;
    if (T[u].right != NIL) deg++;
    cout << "degree = " << deg << ", ";
    cout << "depth = " << D[u] << ", ";
    cout << "height = " << H[u] << ", ";

    if (T[u].parent == NIL) {
        cout << "root";
    } else if (T[u].left == NIL && T[u].right == NIL) {
        cout << "leaf";
    } else {
        cout << "internal node";
    }
    cout << endl;
}

int main() {
    int v, l, r, root = 0;
    cin >> n;
    REP(i, n) T[i].parent = NIL;

    REP(i, n) {
        cin >> v >> l >> r;
        T[v].left = l;
        T[v].right = r;
        if (l != NIL) T[l].parent = v;
        if (r != NIL) T[r].parent = v;
    }

    REP(i, n) if (T[i].parent == NIL) root = i;

    setDepth(root, 0);
    setHeight(root);

    REP(i, n) print(i);
}


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

const int LEN = 100005;
struct Task { char name[100]; int time; };
Task Tasks[LEN];
int head, tail;

void enqueue(Task task)
{
    Tasks[tail] = task;
    tail = (tail+1) % LEN;
}

Task dequeue()
{
    Task task = Tasks[head];
    head = (head+1) % LEN;
    return task;
}

int main()
{
    int n, q;
    int t = 0;

    scanf("%d %d", &n, &q);

    for (int i = 0; i != n; ++i)
    {
        scanf("%s", &Tasks[i].name);
        scanf("%d", &Tasks[i].time);
    }

    head = 0;
    tail = n;

    while (head != tail)
    {
        Task task = dequeue();

        if (task.time <= q)
        {
            t += task.time;
            printf("%s ", task.name);
            printf("%d\n", t);
        }
        else
        {
            task.time -= q;
            t += q;
            enqueue(task);
        }
    }

    return 0;
}


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

int main() {
  int H, W;
  for (;;) {
    cin >> H >> W;
    if (H == 0 && W == 0) {
      break;
    }
    for (int h = 0; h < H; ++h) {
      for (int w = 0; w < W; ++w) {
        cout << "#";
      }
      cout << endl;
    }

    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
s = input()

s = s[:-1]
if len(s) % 2 != 0:
    s = s[:-1]


while(True):
    s1, s2 = s[0:len(s)//2], s[len(s)//2:len(s)]
    if s1 == s2:
        print(len(s1)*2)
        break

    s = s[:-2]

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

int totalbit(int num, int b){
	// k * b <= num <= k * b + b / 2 -> k * b / 2
	// k * b + b / 2 <= num <= (k + 1) * b -> num - k * b - b / 2 + 1 + k * b / 2
	
	int k = num / b;
	return max<int>(num - k * b - b / 2 + 1, 0) + k * b / 2;
}

signed main(){
	//show(totalbit(2, 2));
	//show(totalbit(3, 2));
	//show(totalbit(4, 2));
	//show(totalbit(10, 2));
	//show(totalbit(10, 4));
	//show(totalbit(10, 8));
	//show(totalbit(10, 16));
	//rep(i,11){
	//	cout << bitset<4>(i) << endl;
	//}
	//exit(1);

	int a, b;
	cin >> a >> b;

	int ans = 0, k = 2;
	rep(_,50){
		bool bit = (totalbit(b, k) - totalbit(a - 1, k)) % 2;
		ans += bit * k / 2;
		k*=2;
	}
	cout << ans << endl;
}


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

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

    int n;
    cin >> n;

    int b;
    for (int i = 0; i < n; i++) {
        cin >> b;
        for (int x = 0; x < 3; x++) {
            for (int y = 0; y < 3; y++) {
                if (a[x][y] == b) a[x][y] = 0;
            }
        }
    }

    bool r = false;
    for (int i = 0; i < 3; i++) {
        if (a[i][0] == 0 && a[i][1] == 0 && a[i][2] == 0) r = true;
    }
    for (int i = 0; i < 3; i++) {
        if (a[0][i] == 0 && a[1][i] == 0 && a[2][i] == 0) r = true;
    }
    if (a[0][0] == 0 && a[1][1] == 0 && a[2][2] == 0) r = true;
    if (a[0][2] == 0 && a[1][1] == 0 && a[2][0] == 0) r = true;
    
    if (r) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>

using namespace std;

int main(){
	int a,b,c;
	int p=0,p1=0,p2=0,p3=0;
		
	while(1){
		scanf("%d %d %d",&a,&b,&c);
		vector<int> s;
		s.push_back(a);
		s.push_back(b);
		s.push_back(c);
		sort(s.begin(),s.end());
		if(s[0]+s[1]<=s[2]||s[1]+s[2]<=s[0]||s[2]+s[0]<=s[1])
		break;
		else{
			p++;
			for(int i=0;i<3;i++) s[i]=s[i]*s[i];
			if(s[0]+s[1]-s[2]==0)
			p1++;
			else if(s[0]+s[1]-s[2]>0)
			p2++;
			else
			p3++;
		}
	}
	printf("%d %d %d %d\n",p,p1,p2,p3);
}


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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MOD 1000000007
#define INF 100100100

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


int main(){
  ll q, h, s, d, n;
  cin >> q >> h >> s >> d >> n;
  if(n == 1){
    cout << min({q*4, h*2, s}) << endl;
    return 0;
  }

  q *= 8;
  h *= 4;
  s *= 2;



  ll res1 = (n / 2) * q;
  if(n % 2 == 1) res1 += q / 2;
  ll res2 = (n / 2) * h;
  if(n % 2 == 1) res2 += h / 2;
  ll res3 = (n / 2) * s;
  if(n % 2 == 1) res3 += s / 2;
  ll res4 = (n / 2) * d;
  if(n % 2 == 1) res4 += min({q, h, s}) / 2;

  cout << min({res1, res2, res3, res4}) << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n;
int main()
{
	cin>>n;
	for(int i=sqrt(n);i>=1;i--)
		if(n%i==0)
		{
			cout<<n/i+i-2<<endl;
			break;
		}
	return 0;
} 	

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <complex>

int main() {
    double p1x, p1y, p2x, p2y;
    std::cin >> p1x >> p1y >> p2x >> p2y;

    std::complex< double > p1(p1x, p1y), p2(p2x, p2y);

    std::cout << std::fixed << std::setprecision(20);
    std::cout << std::abs(p1 - p2) << std::endl;
}


Measured memory_bytes: 3340
n = int(input())
lst_p = [[0, 0, 0]] + [list(map(int, input().split())) for _ in range(n)]


ans = 'Yes'
for i in range(n):
    t = lst_p[i+1][0] - lst_p[i][0]
    x = abs(lst_p[i+1][1] - lst_p[i][1])
    y = abs(lst_p[i+1][2] - lst_p[i][2])
    if t >= x + y and (x+y)%2 == t%2:
        continue
    else:
        ans = 'No'
        break


print(ans)

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

int main()
{
  int n;
  cin >> n;
  
  int ans = 0;
  int p[n];
  for(int i = 1; i <= n; i++){
    cin >> p[i];
  }
  
  for(int i = 1; i <= n; i++){
    if(i != p[i]){
      ans++;
    }//if
  }
  if(ans > 2){
     cout << "NO" << endl;
  }else{
    cout << "YES" << endl;
  }
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int f[100],a[100],t[100],x[100],y[100];
int main(){
	int N;
	int A[2]={-1,-1},B[2]={-1,-1};
	cin>>N;
	rep(i,N) cin>>f[i]>>a[i]>>t[i]>>x[i]>>y[i];
	rep(i,N-1){
		if(t[i]!=t[i+1]||a[i]==a[i+1]) continue;
		int len=(x[i]-x[i+1])*(x[i]-x[i+1])+(y[i]-y[i+1])*(y[i]-y[i+1]);
		if(len>A[t[i]]||(len==A[t[i]]&&B[t[i]]>f[i+1]-f[i])){
			A[t[i]]=len,B[t[i]]=f[i+1]-f[i];
		}
	}
	rep(tt,2){
		if(A[tt]==-1) puts("-1 -1");
		else printf("%.12f %.12f\n",sqrt(A[tt]),(double)B[tt]/60);
	}
}

Measured memory_bytes: 1180
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        //MyDebugger.MakeTestCase("../TextFile2.txt"); return;
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var s = input.ReadLine();

        var ret = new int[s.Length];

        int count = 0;
        for(int i=0; i<s.Length-1; i++) {
            var c = s[i];
            var n = s[i + 1];
            if (c=='R'){
                if (n == 'L') {
                    ret[i] += (count) / 2 + 1;
                    ret[i + 1] += (count+1) / 2;
                    count = 0;
                } else {
                    count++;
                }
            }
        }
        
        count = 0;
        for(int i=s.Length-1; i>0; i--) {
            var c = s[i];
            var n = s[i - 1];
            if (c=='L'){
                if (n == 'R') {
                    ret[i] += (count) / 2 + 1;
                    ret[i - 1] += (count+1) / 2;
                    count = 0;
                } else {
                    count++;
                }
            }
        }

        var buil = new StringBuilder();
        foreach(var i in ret) {
            buil.Append(i);
            buil.Append(' ');
        }
        return buil.ToString();
    }
}


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

using namespace std;

string str;

int main() {
    cin >> str;
    int N = str.size();

    int ans = 0;
    for (int i = 1; i < N; i++) {
        if(str[i]!=str[i-1])
            ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3752
function Main(input) {
	var str = input;
	const a = str.split('\n')[0];
	if (a === "ABC"){
		console.log("ARC");
    }else{
		console.log("ABC");
    }
}
 
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main() {
    int n,a,tmp;
    long long ans=0;
    cin>>n;
    cin>>a;
    for (int i = 1; i < n; ++i) {
        cin>>tmp;
        if (a>tmp)
            ans+=a-tmp;
        else
            a=tmp;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

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

    int n;
    cin >> n;

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

        p[(a % 4 == 2) + (a % 4 == 0) * 2]++;
    }

    cout << ((p[1] == 0 ? p[2] + 1 >= p[0] : p[2] >= p[0]) ? "Yes" : "No") << endl;

    return 0;
}

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

int main(){
  int n;
  int num[1000000]={0};
  num[0]=1;
  num[1]=1;

  for(int i=2;i<1000000;i++){
    if(num[i]==0){
      for(int j=2;j*i<1000000;j++){
        num[j*i]=1;
      }
    }
  }

  while(scanf(" %d",&n)!=EOF){
    int cnt=0;
    for(int i=2;i<=n;i++){
      if(num[i]==0){
	cnt++;
      }
    }
    cout << cnt << endl;
  }

  return 0;
}

Measured memory_bytes: 7052
// https://atcoder.jp/contests/abc152/tasks/abc152_c

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int mi = n + 1;
    int ans = 0;
    for (long i = 0; i < n; i++)
    {
        int p;
        cin >> p;
        if (p <= mi)
        {
            ans++;
            mi = p;
        }
    }

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


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

using namespace std;

int main(){
  
  int n;
  cin >> n;
  vector<char> a(n), b(n);
  for(int i=0; i<n; i++){
    cin >> a.at(i);
  }
  for(int i=0; i<n; i++){
    cin >> b.at(i);
  }
  for(int i=0; i<n; i++){
    cout << a.at(i) << b.at(i);
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main(){
   int n;
   set<string> s;
   cin >> n;
   string sinput;
   REP(i,n){
      cin >> sinput;
      s.insert(sinput);
   }
   
   cout << s.size() << endl;
   
   
   
   
   
   
   return 0;
}

Measured memory_bytes: 19220
#include <iostream>
#include <cstdlib>
#include <unordered_map>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

int main(){
    int n, k; cin >> n >> k;
    unordered_map<int, int> m;

    for(int i = 0; i < n; ++i){
        int a; cin >> a;
        if(m.find(a) == m.end()){
            m.emplace(a, 1);
        }else{
            m[a]++;
        }
    }

    vector<int> v;
    for(const auto& kv : m){
        v.push_back(kv.second);
    }
    sort(v.begin(), v.end());

    int ans = 0;
    for(int i = 0; i < (int)v.size() - k; ++i){
        ans += v[i];
    }

    cout << ans << endl;

    return EXIT_SUCCESS;
}


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

int main(){
long long x;
  cin>>x;
  for(long long a=-200;a<200;a++){
    for(long long b=-200;b<200;b++){
if(a*a*a*a*a-b*b*b*b*b==x){
cout<<a<<" "<<b<<endl;
  return 0;
}
    }
  }
  return 0;
}


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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int A[1000000], n;

bool bin(int key) {
    int left = 0;
    int right = n;

    while ( left < right ) {
        int mid = (left + right) / 2;
        if (A[mid] == key) return true;
        if (A[mid] < key) left = mid + 1; // ???????????¢?´¢
        else if (A[mid] > key) right = mid; // ???????????¢?´¢
    }
    return false;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }

    int q, sum = 0;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int k;
        cin >> k;
        if ( bin(k) ) {
            sum++;
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3440
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int x = sc.nextInt();
      int y = sc.nextInt();
      int b = (y - 2 * x) / 2;
      int a = x - b;
      if(a >= 0 && b >= 0 && (2 * a + 4 * b) == y)
      	System.out.println("Yes");
  	  else
  	  	System.out.println("No");
      sc.close();
  }
}

Measured memory_bytes: 27036
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
using namespace std;

#define ll long long
#define ull unsigned long long
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

//sort(arr, arr+n, greater<int>())

//for(int i = 0; i < size; i++)
//    cout << a[i] << " ";

int main()
{
    fast_io;

    map <string, int> m;
    map <string, int>::iterator it;
    int n;

    cin >> n;

    for(int i = 0; i < n; i++)
    {
        string temp;
        cin >> temp;

        m[temp] += 1;
    }

    int max = 0;
    for(it = m.begin(); it != m.end(); it++)
    {
        max = it->second > max? it->second : max;
    }

    for(it = m.begin(); it != m.end(); it++)
    {
        if(it->second == max) cout << it->first << '\n';
    }
    return 0;
}


Measured memory_bytes: 19120
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 998244353;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    bool flg = 0;
    rep(i, n) {
        char c;
        cin >> c;
        a[i] = c - '1';
        flg |= a[i] == 1;
    }
    int x = 0;
    rep(i, n) {
        x ^= (a[i] % 2 * (n - 1 == (i | (n - 1 - i))));
    }
    if (x == 1) {
        cout << 1 << endl;
        return 0;
    }
    if (flg) {
        cout << 0 << endl;
        return 0;
    }
    rep(i, n) a[i] /= 2;
    rep(i, n) {
        x ^= (a[i] * (n - 1 == (i | (n - 1 - i))));
    }
    if (x == 0)
        cout << 0 << endl;
    else
        cout << 2 << endl;
}

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

typedef long long int ll;
typedef long int li;

const ll mod = 1000000007;
const ll inf = 1000000000000000000;

typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<vli> vvli;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef map<ll, ll> mll;
typedef map<ll, string> mls;
typedef map<string, ll> msl;

#pragma GCC optimize ("-O3")
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
#define PI 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define tol(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define tou(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define all(v) v.begin(), v.end()
#define FOR(i, j, k, in) for(li i=j; i<k; i+=in)
#define RFOR(i, j, k, de) for(li i=j; i>=k; i-=de)
#define rep(i,j,k) FOR(i, j, k, 1)
#define rrep(i,j,k) RFOR(i, j, k, 1)
#define repc(v) for(auto it=v.begin(); it!=v.end(); it++)
#define T ll t; cin>>t; while(t--)

int main(){
  FAST

	string s;
   cin>>s;
  if(s[0]=='7' || s[1]=='7' || s[2]=='7')
    cout<<"Yes";
  
  else
    cout<<"No";
  
  return 0;
}







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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/
int main(){
    int n;cin>>n;
    vector<V>f(n,V(10));
    vector<V>p(n,V(11));
    rep(i,n){
        rep(j,10){
            cin>>f[i][j];
        }
    }
    rep(i,n){
        rep(j,11){
            cin>>p[i][j];
        }
    }
    //bit全探索
    int ans=-INF;
    for(int bit=1;bit<(1<<10);bit++){
        int tmp=0;
        rep(i,n){
            int cnt=0;
            rep(j,10){
                if(bit&(1<<j)&&f[i][j]==1){
                    cnt++;
                }
            }
            //printf("cnt=%d\n",cnt);
            tmp+=p[i][cnt];
        }
        ans=max(ans,tmp);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
a = list(input())
b = list(input())
c = list(input())
trash = a.pop(0)
while True:
  if trash == "a":
    if len(a) == 0:
      print("A")
      break
    else:
      trash = a.pop(0)
  elif trash == "b":
    if len(b) == 0:
      print("B")
      break
    else:
      trash = b.pop(0)
  else:
    if len(c) == 0:
      print("C")
      break
    else:
      trash = c.pop(0)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
#define int ll
 
#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DMP(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
 
using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;
 
template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}
 
template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}
 
int read(){
	int i;
	scanf("%lld",&i);
	return i;
}
 
void printSpace(){
	printf(" ");
}
 
void printEoln(){
	printf("\n");
}
 
void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}
 
string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}
 
char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}
 
template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}
 
template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}
 
template<class T>
T Sq(const T& t){
	return t*t;
}
 
const int inf=LLONG_MAX/3;
 
 struct Node{
	 int minVal,minA,maxA;
 };
 
signed main(){
	int x=read(),k=read();
	vi r{0};REP(_,k)r.PB(read());
	vector<Node> pre{Node{0,0,x}};
	FOR(i,1,k+1){
		Node w=pre.back();
		if(i&1){//sub
			w.minVal-=(r[i]-r[i-1]);
			if(w.minVal<0){
				w.minA+=-w.minVal;
				w.minVal=0;
				chmax(w.maxA,w.minA);
			}
		}else{//add
			w.minVal+=(r[i]-r[i-1]);
			chmin(w.minVal,x);
			if(w.minVal+w.maxA-w.minA>x)
				w.maxA=x-w.minVal+w.minA;
		}
		pre.PB(w);
	}
	int q=read();
	REP(_,q){
		int t=read(),a=read();
		int i=upper_bound(ALL(r),t)-r.begin()-1;
		int res=pre[i].minVal+max(min(a,pre[i].maxA),pre[i].minA)-pre[i].minA;
		if(i&1){//add
			res=min(res+t-r[i],x);
		}else{//sub
			res=max(res-t+r[i],0LL);
		}
		print(res);
	}
}

Measured memory_bytes: 6384
#include<iostream>
#include<cmath>
#include<string>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[n];
    long long sum=0;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        a[i]=a[i]-i-1;
    }
    vector<int> vec_a (a, a+n);
    sort(vec_a.begin(), vec_a.end());
    for(int i=0; i<n/2; i++)
    {
        sum += vec_a[n-1-i]-vec_a[i];
    }
    cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 1792
# 解説を参考に作成
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(S, K):
    ans = ''
    for i in range(len(S)):
        if i + 1 == K:
            ans = S[i]
            break
        if S[i] != '1':
            ans = S[i]
            break
    print(ans)


if __name__ == '__main__':
    S = input()
    K = int(input())
    # N, M = map(int, input().split())
    # A = [int(i) for i in input().split()]
    # B = [int(i) for i in input().split()]
    # AB = [[int(i) for i in input().split()] for _ in range(N)]
    solve(S, K)

    # # test
    # from random import randint
    # from func import random_str
    # solve()


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

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

typedef long long ll;
using namespace std;

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

  int N;
  cin >> N;

  while (N > 0) {
    int n = N % 10;
    if (n == 9) {
      cout << "Yes" << endl;
      return 0;
    }
    N /= 10;
  }

  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		HashMap hs = new HashMap();
		PrintWriter ou = new PrintWriter(System.out);
		int[] a = new int[3];
		for(int i = 0 ; i < 3 ; i++){
			a[i] = Integer.parseInt(sc.next());
		}
		ou.print(a[2] / a[0] * a[1] + "\n");
		ou.flush();
	}
}

Measured memory_bytes: 38280
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;

int main() {
  ll A;
  double B;
  cin >> A >> B;
  int c;
  c = B*100+0.1;
  A = A*c/100;;

  cout<<A<<endl;


}



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

#define MAX 100000
#define NIL -1

struct Node
{
    int p,l,r;
};

void setDepth(int u, int d);
void print(int u);

Node T[MAX];
int D[MAX];

int main(){
    int n; cin >> n;
    for(int i = 0; i < n; i++){
        T[i].l = T[i].p = T[i].r = NIL;
    }

    for(int i = 0; i < n; i++){
        int id, k; cin >> id >> k;
        int c, left, ch = 0;
        for(int j = 0; j < k; j++){
            cin >> c;
            if(j == 0) T[id].l = c;
            else T[left].r = c;
            left = c;
            T[c].p = id;
        }
    }

    int root;
    for(int i = 0; i < n; i++){
        if(T[i].p == NIL) root = i;
    }

    setDepth(root,0);

    for(int i = 0; i < n; i++){
        print(i);
    }

}

void setDepth(int u, int d){
    D[u] = d;
    if(T[u].l != NIL) setDepth(T[u].l, d+1);
    if(T[u].r != NIL) setDepth(T[u].r, d);
}

void print(int u){
    cout << "node " << u << ": parent = " << T[u].p << ", depth = " << D[u] << ", ";
    if(T[u].p == NIL) cout << "root, ";
    else if(T[u].l == NIL) cout << "leaf, ";
    else cout << "internal node, ";
    cout << "[";
    int c = T[u].l;
    for(int i = 0; c != NIL; i++){
        if(i > 0) cout << ", ";
        cout << c;
        c = T[c].r;
    }
    cout << "]" << endl;
}


Measured memory_bytes: 4652
import java.util.Scanner;
public class Main{
	public static void main(String[]args){
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		String ans="AMBIGUOUS";
		int s1=Integer.parseInt(s.substring(0, 2));
		int s2=Integer.parseInt(s.substring(2,4));
		boolean Mflag1=true;
		boolean Mflag2=true;
		if(s1<1)Mflag1=false;
		if(s2<1)Mflag2=false;
		if(s1>12)Mflag1=false;
		if(s2>12)Mflag2=false;
		if(Mflag1==false&&Mflag2==false)ans="NA";
		if(Mflag1==true&&Mflag2==false)ans="MMYY";
		if(Mflag1==false&&Mflag2==true)ans="YYMM";
		System.out.println(ans);
	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

//HとWの最大値を入れておく
const int MAX_H = 432;
const int MAX_W = 432;

int H,W;
vs field;

//座標がフィールドに入っているかどうかの判定
bool in (int x, int y){
	return 0<=x&&x<H&&0<=y&&y<W;
}

//上下左右
const int dx4[4] = {0,0,1,-1};
const int dy4[4] = {1,-1,0,0};

//周囲8方向
const int dx8[8] = {0,1,1, 1, 0,-1,-1,-1,};
const int dy8[8] = {1,1,0,-1,-1,-1, 0, 1,};

//探索するときに、すでに訪れたか
bool seen[MAX_H][MAX_W];
ll black,white;
//深さ優先探索
//壁に注意
void dfs(int h, int w){
	seen[h][w] = true;
	if(field[h][w] == '.')white++;
	else black++;
	for (int i = 0; i < 4; ++i){
		int nh = h + dx4[i];
		int nw = w + dy4[i];
		if(!in(nh, nw)) continue;
		if(field[nh][nw] == field[h][w]) continue;
		if(seen[nh][nw])continue;
		dfs(nh, nw);
	}
}

int main() {
	cin>>H>>W;
	field.resize(H);
	rep(i,H)cin>>field[i];
	ll ans = 0;
	rep(i,H)rep(j,W){
		black = 0;
		white = 0;
		if(seen[i][j])continue;
		dfs(i,j);
		ans+=white*black;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 18176
import java.util.Scanner;

public class Main {
	  
	public static void main(String args[]) {
		    Scanner scanner = new Scanner(System.in);
		    
			String c1 = scanner.nextLine();
			String c2 = scanner.nextLine();
			String c3 = scanner.nextLine();
			
			System.out.println(c1.substring(0, 1) + c2.substring(1, 2)
									+ c3.substring(2, 3));
		    scanner.close(); }
		  }

Measured memory_bytes: 21844
"""
小数の状態だと処理しづらいので、与えられた数を全て10**9倍して小数を確実になくした上で
問題文を下記のように言い換える。
「積が10**18の倍数になるような数の組み合わせの数がいくつあるか」
数Aiがあり、Aiの2の素因数の数がn, 5の素因数の数がmのとき、
数Ai自体ですでにmin(n,m)個の0の数を持っている。この場合、のこり必要な0の数はx = 18-min(n,m)個である。
ここで、n == mの場合：
Aiの相方は少なくとも2,5の素因数をそれぞれx個以上持っていなくてはならない。
n > mの場合：
Aiの相方は少なくとも2の素因数をx-(n-m)個、5の素因数をx個持っていなくてはいけない。

m > nの場合：
Aiの相方は少なくとも2の素因数をx個以上、5の素因数をx-(m-n)個以上持っていなくてはならない。
"""
N = int(input())
dp = [[0]*(19) for _ in range(19)]
ans = 0
for _ in range(N):
    a = round(float(input())*pow(10,9))
    two = 0
    while a % 2 == 0 and two < 18:
        a //= 2
        two += 1
    five = 0
    while a % 5 == 0 and five < 18:
        a //= 5
        five += 1

    ans += dp[18-two][18-five]
    for i in range(two+1):
        for j in range(five+1):
            dp[i][j] += 1
print(ans)

Measured memory_bytes: 75464
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

LL modinv(LL a) {
    LL b = MOD, u = 1, v = 0;
    while (b) {
        LL t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

LL moddev(LL a, LL b){
	return a * modinv(b) % MOD;
}

void Main()
{
    int n,k;
    cin>>n>>k;

    int result = log(n) / log(k) + 1;

    cout << result << endl;

	return;
}

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

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

for i in range(h):
  for j in range(w):
    if s[i][j]=='#':
      continue
    cnt=0
    for dx in [-1,0,1]:
      for dy in [-1,0,1]:
        if not(0<=dx+i<=h-1 and 0<=dy+j<=w-1):
          continue
        if s[i+dx][j+dy]=='#':
          cnt+=1
    s[i][j]=str(cnt)
for m in s:
  print(''.join(m))



Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////


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

	vector<ll> A(N + 1);
	repn(i, N) cin >> A[i];

	sort(++A.begin(), A.end());

	ll ans = 0;

	repn(i, N-1) {
		ans += (A[i + 1] - A[i]) * 2 * min(i, N - i);
	}

	ll x;
	if (N % 2 == 1) { x = min(A[N / 2 + 2] - A[N / 2 + 1], A[N / 2 + 1] - A[N / 2]); }
	else { x = A[N / 2 + 1] - A[N / 2]; }

	cout << ans - x;


	system("PAUSE");
}


Measured memory_bytes: 1272
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin >> s;
    int n = s.length();
    int rc = 0;
    int ans = 0;
    for (int i = 0; i < n; ++i){
        if(s[i] == 'R'){
            ++rc;
            ans = max(ans, rc);
        }
        else {rc = 0;}
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<(n); i++)
#define int long long
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
using namespace std;
signed main(void){
    int n,k;cin>>n>>k;
    vector<int>V(n);rep(i,n)cin>>V[i];
    int Minus[n+1],Plus[n+1];Minus[0]=Plus[0]=0;
    rep(i,n){
        Plus[i+1]=Plus[i]+max((int)0,V[i]);
        Minus[i+1]=Minus[i]+min((int)0,V[i]);
    }
    int sum=Plus[n];int ans=-INF;
    int com0,com1;
    rep(i,n-k+1){
        com0=sum-(Plus[i+k]-Plus[i]);
        com1=sum+(Minus[i+k]-Minus[i]);
        ans=max(ans,max(com0,com1));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2560
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { -1,0,1,0 }, dy[4] = { 0,-1,0,1 };
const char dir[4] = { 'u','l','d','r' };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
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; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        (wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)

LL n, k;
const LL MOD = 1000000007;
LL combi(LL N_, LL C_) {
	const int NUM_ = 400001;
	static LL fact[NUM_ + 1], factr[NUM_ + 1], inv[NUM_ + 1];
	if (fact[0] == 0) {
		inv[1] = fact[0] = factr[0] = 1;
		for (int i = 2; i <= NUM_; ++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
		for (int i = 1; i <= NUM_; ++i) fact[i] = fact[i - 1] * i%MOD, factr[i] = factr[i - 1] * inv[i] % MOD;
	}
	if (C_<0 || C_>N_) return 0;
	return factr[C_] * fact[N_] % MOD*factr[N_ - C_] % MOD;
}
//K個のものから重複を許してN個選ぶ時の組み合わせ
LL hcomb(int P_, int Q_) { return (P_ == 0 && Q_ == 0) ? 1 : combi(P_ + Q_ - 1, Q_); }

LL modpow(LL a, LL n = MOD - 2) {
	LL r = 1;
	while (n) r = r*((n % 2) ? a : 1) % MOD, a = a*a%MOD, n >>= 1;
	return r;
}

int main() {
	cin >> n >> k;
	cout << combi(k, n) << endl;
}


Measured memory_bytes: 12440
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");

        long a = Long.valueOf(arr01[0]);
        long b = Long.valueOf(arr01[1]);
        long k = Long.valueOf(arr01[2]);

        if (a + b <= k) {

            a = 0;
            b = 0;

        } else if (a >= k) {

            long temp = a - k;
            a = temp;

            //} else if (b >= k) {
        } else {
            long temp = b - (k - a);
            a = 0;
            b = temp;

        }

        System.out.println(a + " " + b);

    }

}

Measured memory_bytes: 23124
N = int(input())

total = 0
noten = []
for i in range(N):
    s = int(input())
    total += s
    if s%10 != 0:
        noten.append(s)

noten.sort()

if total%10 != 0:
    print(total)
elif len(noten) == 0:
    print(0)
else:
    print(total-noten[0])

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

int main(){
  int N,K;
  cin>>N>>K;
  
  long long int max=0;
  long long int min=0;
  long long int ans=0;
  
  for(int i=0;i<=N;i++){
    max=max+N-i;
    min=min+i;
    //printf("%d %d\n",max,min);
    if(i>=K-1){
      ans+=(max-min+1)%MOD;
      ans=ans%MOD;
    }
  }
  ans=ans%MOD;
  cout<<ans<<endl;


}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define LOCAL
using std::to_string;
auto to_string(std::string s) -> std::string {
  return '"' + s + '"';
}
auto to_string(const char* s) -> std::string {
  return to_string((std::string) s);
}
auto to_string(bool b) -> std::string {
  return (b ? "true" : "false");
}
template <typename T, typename U>
auto to_string(std::pair<T, U> p) -> std::string {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <size_t N>
auto to_string(std::bitset<N> bs) -> std::string {
  std::string res{};
  for (size_t i = 0; i < N; i++)
    res.insert(res.begin(), bs.test(i) ? '1' : '0');
  return res;
}
template <typename T>
auto to_string(T v) -> std::string {
  bool flg = false;
  std::string res = "{";
  for (auto const&x : v) {
    if (flg) res += ", ";
    else flg = true;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  std::cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  size_t n, a, b, c, d;
  std::cin >> n >> a >> b >> c >> d;
  a--, b--, c--, d--;
  debug(a, b, c, d);
  std::vector<int> rock(n);
  std::for_each(rock.begin(), rock.end(), [](auto& x){
    char c; std::cin >> c;
    x = (c == '#');
  });
  debug(rock);
  auto can_go = [&] (size_t x, size_t y) {
    assert(x < y);
    assert(!rock.at(x));
    assert(!rock.at(y));
    for (size_t i = x + 1; i <= y - 2; i++) {
      if (rock.at(i) && rock.at(i + 1)) return false;
    }
    return true;
  };
  auto can_leap = [&] {
    assert(a < b && b < d && d < c);
    for (size_t i = b; i <= d; i++) {
      if (!rock.at(i - 1) && !rock.at(i) && !rock.at(i + 1)) return true;
    }
    return false;
  };
  auto err = [&] {
    std::cout << "No" << std::endl;
    exit(0);
  };
  if (!can_go(a, c)) err();
  if (!can_go(b, d)) err();
  if (d < c && !can_leap()) err();
  std::cout << "Yes" << std::endl;
  return 0;
}

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

using namespace std;

#define ll long long 
#define endl '\n'
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SIZE 100005

int main()
{
	
	int n,a[55],ans=0;
	cin >> n;
	for(int i = 1; i <= n;i++) cin >> a[i];
	for(int i = 1; i <= n; i++)
	{
		for(int j = i+1; j <= n; j++)
		{
			ans += (a[i]*a[j]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

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;
}
///////////////////////////////////////////////
int main(){
    int a,b;
    cin >> a >> b;
    int x = (a+b);
    cout << (x + (2 - 1)) / 2 << endl;
}






Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Data.List

main = do
    _  <- getLine
    xs <- map (read . BS.unpack) . BS.words <$> BS.getLine ::IO[Int]
    let as = scanl1 min xs
    print $ sum [1|(a,b)<- zip xs as, a==b]

Measured memory_bytes: 4348
N,M = (int(i) for i in input().split())
X =[]
for i in range(N):
    tmp = [int(i) for i in input().split()]
    X.append(tmp)
Y = []
for i in range(M):
    tmp = [int(i) for i in input().split()]
    Y.append(tmp)


for i in X:
    MAX = 10 ** 9
    ans = 0
    for j in range(M):
        LENGE = abs(i[0] - Y[j][0]) + abs(i[1] - Y[j][1])
        if LENGE < MAX:
            MAX = LENGE
            ans = j + 1
    print(ans)


Measured memory_bytes: 3064
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double EPS = 1e-9;
const double INT_MAX = 2147483647;
#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for(int i = x; i < (int)(n); i++)
#define rrep(i, n) RREP(i, 0, n)
#define RREP(i, x, n) for(int i = (int)(n) - 1 - (int)(x); i >= 0; i--)

void printv(vector<int> v) {
    for(auto it = v.begin(); it != v.end(); it++){
        cout << *it << ",";
    }
    cout << endl;
}

int N,M,X;
vector<int> c(13);
vector<vector<int>> a(13, vector<int>(13));
int res = INT_MAX;

void rec(vector<int> s, int d, int sum){
    //cout<<"d:"<<d<<" sum:"<<sum<<endl;
    //printv(s);
    if (d == N+1) return;
    bool r = true;
    rep(i, M){
        if (s[i] < X) r = false;
    }
    if (r && res > sum) res = sum;
    // dばんめを選ばない場合
    rec(s,d+1,sum);
    // 選ぶ場合
    if (r) return;
    rep(i, M){
        s[i] += a[d][i];
    }
    rec(s,d+1,sum+c[d]);
}

int main(void){
    // Your code here!
    cin>>N>>M>>X;
    rep(i, N){
        cin >> c[i];
        rep(j, M){
            cin >> a[i][j];
        }
    }
    vector<int> s(M);
    rec(s,0,0);
    if (res == INT_MAX) cout << "-1";
    else cout << res;
}


Measured memory_bytes: 3632
n = gets.chomp.to_i
slist = []
result = 0
hhash = Hash.new(0)
n.times do |ni|
  s = gets.chomp
  hash = Hash.new(0)
  s.each_char do |si|
    hash[si] += 1
  end
  hhash[hash] += 1
  slist.push(hash)
end
hhash.each do |k,v|
  result += (v*(v-1))/2
end

puts result


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


int main() {
    int N;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; ++i) cin >> A[i];
    sort(A, A + N);
    cout << abs(A[0] - A[N - 1]);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N;
int x,y,z;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>N;
    while(N--){
        int t,a,b;
        cin>>t>>a>>b;
        if( t-z < max(x-a,a-x)+max(y-b,b-y) ){
            puts("No");
            return 0;
        }
        if((t-z)%2 != (max(x-a,a-x)+max(y-b,b-y))%2 ){
            puts("No");
            return 0;
        }
        x=a;
        y=b;
        z=t;
    }
    puts("Yes");
}


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

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	string s;
	int k;
	cin >> s >> k;
	for(int i = 0;i < s.length(); ++i){
		int move = ('z' + 1 - s[i]) % 26;
		if(k >= move){
			k-=move;
			s[i] = 'a';
		}
	}
	int nd = s.length() - 1;
	k %= 26;
	s[nd] = 'a' + (s[nd] - 'a' + k) % 26;
	cout << s << '\n';
}


Measured memory_bytes: 592