akhauriyash/Code-Regression huggingface dataset:
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>
#include <stack>
#include <limits>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repr(i, n) for(int i = n - 1; i >= 0; i--)

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

const int imax = numeric_limits<int>::max();
const ll llmax = numeric_limits<ll>::max();

using pp = pair<ll, pair<int, int>>; //cost, node_num, have_money;

struct Edge {
  int u;
  int v;
  int a;
  ll b;
};

struct City {
  ll c;
  ll d;
};

p graph[50][50]; //cost, need_money
Edge edges[100];
City cities[50];
ll dp[50][2501];

int n;
int m;
ll s;

void djk(int start, int have) {
  rep(i, n) {
    rep(j, 2501) {
      dp[i][j] = llmax;
    }
  }
  priority_queue<pp, vector<pp>, greater<pp>> pq; //cost, node_num, have_money;
  pq.push({0, {start, have}});
  dp[start][have] = 0;
  
  while(!pq.empty()) {
    pp cur = pq.top();
    pq.pop();
 
    ll curcost = cur.first;
    int curcity = cur.second.first;
    int nowhave = cur.second.second;

    //両替しない
    for(int i = 0; i < n; i++) {
      if(graph[curcity][i].first == 0) continue;

      ll newcost = curcost + graph[curcity][i].first;
      int newmoney = nowhave - graph[curcity][i].second;

      if(newmoney < 0) continue;

      if(newcost >= dp[i][newmoney]) continue;

      dp[i][newmoney] = newcost;
      pq.push({newcost, {i, newmoney}});
    }

    //両替する
    ll newcost = curcost + cities[curcity].d;
    int newmoney = nowhave + cities[curcity].c;
    newmoney = newmoney >= 2500 ? 2500 : newmoney;
    if(newcost < dp[curcity][newmoney]) {
      dp[curcity][newmoney] = newcost;
      pq.push({newcost, {curcity, newmoney}});
    }
  }
}

int main(){
  cin >> n >> m >> s;
  s = min(s, (ll)(2500));
  rep(i, m) {
    cin >> edges[i].u >> edges[i].v >> edges[i].a >> edges[i].b;
  }
  rep(i, n) {
    cin >> cities[i].c >> cities[i].d;
    cities[i].c = min(cities[i].c, (ll)2500);
  }

  //グラフの初期化
  rep(i, 50) rep(j, 50) graph[i][j] = {0, 0};

  //グラフの構成
  rep(i, m) {
    auto e = edges[i];
    graph[e.u - 1][e.v - 1] = {e.b, e.a};
    graph[e.v - 1][e.u - 1] = {e.b, e.a};
  } 
  djk(0, s);
  for(int i = 1; i < n; i++) {
    ll result = llmax;
    for(int j = 0; j <= 2500; j++)
    {
      result = min(result, dp[i][j]);
    }
    cout << result << endl;
  }
}


Measured memory_bytes: 6136
// get the input and separate it by line
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split("\n");

// first number is how many lines of text tor process (aside from the first line)
var numLines = parseInt(lines[0]);

// go through all the lines
for (var i = 1; i <= numLines; i++) {
	// get 2 lists, one of x-coords, one of y-coords
	var xs = [];
	var ys = [];
	var coords = lines[i].split(" ");
	for (var j = 0; j < coords.length; j++) {
		if (j % 2 === 0) {
			xs.push(parseFloat(coords[j]));
		}
		else {
			ys.push(parseFloat(coords[j]));
		}
	}

	// calculate the slopes
	var slope1 = ((ys[1] - ys[0]) / (xs[1] - xs[0])).toFixed(6);
	var slope2 = ((ys[3] - ys[2]) / (xs[3] - xs[2])).toFixed(6);

	// print if the slopes are parallel
	if (slope1 == slope2) {
		console.log("YES");
	}
	else {
		console.log("NO");
	}
}

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

int Balls[10];

bool fork(int balls[], int i, int b, int c) {
  if (i == 10) return true;
  if (b > balls[i] && c > balls[i]) return false;
  if (b < balls[i] && fork(balls, i + 1, balls[i], c)) return true;
  if (c < balls[i] && fork(balls, i + 1, b, balls[i])) return true;
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> Balls[j];
    }
    if(fork(Balls, 0, 0, 0)) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 2996
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;

int main() {
	int H1, M1, H2, M2, K;
	cin >> H1 >> M1 >> H2 >> M2 >> K;
	int nn = (H2 * 60 + M2) - (H1 * 60 + M1);
	cout << nn - K << endl;
}

Measured memory_bytes: 3632
#include <iostream>

int main() {
  long long n, a, b, c, d;
  std::cin >> n >> a >> b >> c >> d;

  for (long long m=0; m<n; m++) {
    if ( ( (n-1-m) * c + m * -d ) <= (b - a) &&
         (b - a) <= ( m * -c + (n-1-m) * d ) ) {
      std::cout << "YES" << std::endl;
      return 0;
    }
  }

  std::cout << "NO" << std::endl;

  return 0;
}


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

int main()
{
    int n, a, b;
    char S[100001] = {0};
    cin >> n >> a >> b;
    scanf("%s", S);

    int c_a = 0, c_b = 0, total = a+b;

    for (int i=0; i<n; i++)
    {
        if (S[i]=='a')
        {
            c_a++;
            if (c_a <= (a+b) && total > 0)
            {
                printf("Yes\n");
                total--;
                //printf("total_a: %d\n", total);
            }
            else
                printf("No\n");
        }
        if (S[i]=='b')
        {
            c_b++;
            if (c_b <= b && total > 0)
            {
                printf("Yes\n");
                total--;
                //printf("total_b: %d\n", total);
            }
            else
                printf("No\n");
        }
        if (S[i]=='c')
            printf("No\n");
    }
    return 0;
}


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

int main(){
    int N,M;
    cin >> N >> M;
    vector<vector<int>> beits(M);//2次元配列。{{B,B,B…}, {B,B,B…}…}というふうに入れる。
    for(int i = 0; i < N; i++){
        int A,B; //Aは日数,Bが報酬
        cin >> A >> B;
        if(A <= M) beits.at(A-1).push_back(B); //beitsは0~M-1の範囲。Aは１～M。調整する。
    }
    priority_queue<int> check;
    int sum = 0;
    for(int i = 0; i < M; i++){
        //M - i日目の選択。候補をcheckに入れる。
        for(int x: beits.at(i)) check.push(x); //beits.at(i)には i + 1 日後に報酬をもらえるバイトの報酬が入っている。
        if(check.size() != 0){
            sum += check.top();
            check.pop();
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 5632
#include <stdio.h>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <list>
#include <algorithm>
#include <map>
#include <iterator>
#include <limits>
#include <numeric>
#include <type_traits>
#include <cmath>
#include <cstdlib>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

#define ALL(v) (v).begin(), (v).end()
#define endl "\n"
typedef long long int ll;

template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
	for (int i = 0; i<vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

int SumDigitValues(int x)
{
	int sum = 0;
	while (x)
	{
		sum += x % 10;
		x = x / 10;
	}

	return sum;
}

int Factorial(int n)
{
	if (n < 0) return 0;
	if (n == 0) return 1;
	return n * Factorial(n - 1);
}

int factorial(int n)
{
	if (n > 1)
	{
		return n * factorial(n - 1);
	}
	else
	{
		return 1;
	}
}

int gcd(int x, int y)
{
	if (y == 0)
		return x;
	else 
		return gcd(y, x % y);
}

vector<int> Divisors(int x)
{
	vector<int> divisors;
	divisors.push_back(1);
	for (int a = 2; a <= x; a++)
	{
		if (x % a == 0) divisors.push_back(a);
	}
	return divisors;
}

vector<int> CommonDivisors(int a, int b)
{
	vector<int> divisorsA = Divisors(a);
	vector<int> divisorsB = Divisors(b);
	vector<int> commonDivisors;
	set_intersection(divisorsA.begin(), divisorsA.end(), divisorsB.begin(), divisorsB.end(), std::back_inserter(commonDivisors));
	return commonDivisors;
}

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

	int a, p;
	cin >> a >> p;
	p += a * 3;
	cout << p / 2 << endl;
}

Measured memory_bytes: 256
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

a_num = 0
b_num = 0
book_num = 0
passed_k = 0
for i in range(n):
    if a[i] + passed_k <= k:
        a_num += 1
        passed_k += a[i]
    else:
        break
for i in range(m):
    if b[i] + passed_k <= k:
        b_num += 1
        passed_k += b[i]
    else:
        break
book_num = a_num + b_num

while a_num > 0:
    passed_k -= a[a_num - 1]
    a_num -= 1
    while b_num < m:
        if passed_k + b[b_num] <= k:
            passed_k += b[b_num]
            b_num += 1
        else:
            break
    book_num = max(book_num, a_num + b_num)
    if b_num == m:
        break

print(book_num)

Measured memory_bytes: 39976
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    r,g = IR(2)
    print(2*g-r)

#B
def B():
    n = I()
    k = I()
    a = 1
    for i in range(n):
        if a > k:
            a += k
        else:
            a *= 2
    print(a)
#C
def C():
    def check(a,b):
        for i in range(len(a)):
            if a[i] != b[i] and a[i] != "?":
                return False
        return True
    def f(c):
        if c == "?":return "a"
        return c
    s = S()
    t = S()
    n = len(s)
    l = len(t)
    ans = []
    for i in range(n-l+1)[::-1]:
        if check(s[i:i+l],t):
            c = [f(s[j]) for j in range(i)]
            c += t
            for j in range(i+l,n):
                c += f(s[j])
            ans.append(c)
    if not len(ans):
        print("UNRESTORABLE")
    else:
        ans.sort()
        for i in ans[0]:
            print(i,end = "")
        print()
#D
def D():
    n = I()
    t = LI()
    v = LI()
    v.append(0)
    for i in range(n-1):
        t[i+1] += t[i]
    vt = defaultdict(int)
    k = 0
    for i in range(t[-1]*2+1):
        nt = i/2
        if nt >= t[k]:
            k += 1
        vt[nt] = v[k]
    for i in range(n)[::-1]:
        for j in range(t[i]*2+1)[::-1]:
            nt = j/2
            if -nt+v[i+1]+t[i] < vt[nt]:
                vt[nt] = -nt+v[i+1]+t[i]
    ans = 0
    nv = 0
    for i in range(1,t[-1]*2+1):
        nt = i/2
        if nv < vt[nt-0.5]:
            ans += 0.125+nv/2
            nv += 0.5
        elif nv == vt[nt]:
            ans += nv/2
        else:
            if nv > vt[nt]:
                nv -= 0.5
                ans += 0.125+nv/2
            else:
                ans += nv/2
    print(ans)
#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()


Measured memory_bytes: 46936
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i = 0;i<N;i++)cin>>a[i];
  auto b = a;
  sort(b.begin(),b.end());
  b.erase(unique(b.begin(),b.end()),b.end());
  for(int i=0;i<N;i++) a[i]=lower_bound(b.begin(),b.end(),a[i]) - b.begin();
  vector<int> cnt(b.size());
  for(int i=0;i<N;i++) cnt[a[i]] ^= 1;
  int res = 0;
  for(auto x : cnt) res += x;
  cout << res << endl;
}

Measured memory_bytes: 1408
#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 <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

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(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//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 MOD 1000000009

char board[301][601];

int main() {
	int n;
	scanf("%d", &n);
	char buf[301];
	REP(i, n) {
		scanf("%s", buf);
		strcat(board[i], buf);
		strcat(board[i], buf);
	}
	int ret = 0;
	REP(k, n) {
		bool flag = true;
		REP(i, n) {
			REP(j, i) {
				if (board[i][j + k] != board[j][i + k])flag = false;
			}
		}
		if (flag)ret += n;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 384
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var nd = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var n = nd[0];
        var d = nd[1];
        var ps = new int[n][];
        for (int i = 0; i < ps.Length; i++)
        {
            ps[i] = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        }

        var k = 0;
        for (int i = 0; i < ps.Length; i++)
        {
            for (int j = i + 1; j < ps.Length; j++)
            {
                var distance = Math.Sqrt(E.Zip(ps[i], ps[j], (y, z) => y * y - 2 * y * z + z * z).Sum());
                if (distance - Math.Floor(distance) > 0)
                {
                    continue;
                }

                k++;
            }
        }
        Console.WriteLine(k);
    }
}


Measured memory_bytes: 13524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	string s;ll k;cin>>s>>k;
	ll cnt1=0,cnt2=0,l=s.size();
	if(s==string(l,s[0])){
		cout<<l*k/2<<"\n";
		return 0;
	}

	string ss=s+s;
	rep(i,l-1){
		if(s[i]==s[i+1]){
		s[i+1]='/';
		cnt1++;
		}
	}
	rep(i,2*l-1){
		if(ss[i]==ss[i+1]){
			ss[i+1]='/';
			cnt2++;
		}
	}
	//cout<<cnt1<<" "<<cnt2<<"\n";
	cout<<cnt1+(cnt2-cnt1)*(k-1)<<"\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <unordered_set>
#include <numeric>
#include <iterator>
#include <unordered_map>
#include <array>
#include <map>
#include <cstring>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctgmath>
#include <set>
#include <queue>

using namespace std;
#define int long long
vector<int> div(int m)
{
	vector<int> res;
	for (int i=1; i <= sqrt(m); i++)
	{
		if (m%i == 0)
		{
			res.push_back(i);
			res.push_back(m / i);
		}
	}
	return res;
}

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

	int n, m;
	cin >> n >> m;

	vector<int> d = div(m);

	int ans = 0;

	for (auto i : d)
	{
		if (i*n <= m)
		{
			ans =max(ans, i);
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
int a,b,k;
cin >> a >> b >> k;
int cnt = 0;
    for(int i=min(a,b);i>0;i--){
        if(a%i == 0 && b%i == 0) cnt++;
        if (cnt == k){
        cout << i << endl;
        break;
        }
    }
}

Measured memory_bytes: 256
from fractions import gcd
def lcm(p, q):
  return (p * q // int(gcd(p, q)))
N, M = map(int, input().split())
A = list(map(int,input().split()))
B = []
for i in range(N):
  b = 0
  while A[i] % 2 == 0:
    A[i] >>= 1
    b += 1
  B.append(b)
S = set(B)
if len(S) != 1:
  print(0)
else:
  P = 1
  for i in range(N):
    P = lcm(P, A[i])
  print((M // (2 ** (list(S)[0] - 1)) + P) // (2 * P))

Measured memory_bytes: 96604
import sys
n = int(input())
ls = [int(input()) for _ in range(n)]
mx = max(ls)
c = ls.count(mx)
new = ls[:]
new.remove(mx)
nx = max(new)
if c > 1:
    for _ in range(n):
        print(mx)
    sys.exit()
for i in ls:
    if i == mx:
        print(nx)
    else:
        print(mx)


Measured memory_bytes: 14100
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,five=0,seven=0;
	cin>>a>>b>>c;
	if(a==5)
		five++;
	if(b==5)
		five++;
	if(c==5)
		five++;
	if(a==7)
		seven++;
	if(b==7)
		seven++;
	if(c==7)
		seven++;
	if(five==2 && seven==1)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (int)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    string N;
    cin >> N;

    if((N[0]==N[1] && N[1] == N[2]) || (N[1]==N[2] && N[2]==N[3]))
        print("Yes");
    else
        print("No");

    return 0;
}

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

int main(){
    string s;
    cin>>s;

    if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3]){
        cout<<"Bad"<<endl;
    }else{
        cout<<"Good"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <bitset>

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define INF 2000000000
#define rep(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> P;
const ll MOD=1000000007;
using Graph = vector<vector<int>>;

int cut(int a, int b) {//切り捨て
    return (a - a % b) / b;
}
int up(int a, int b) {
    return (a + a % b) / b;
}


int main() {
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <cmath>
#include <cstring>

using namespace std;

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)
#define SCANFD(x) scanf("%d",&x)

int H,W;
int cost[50][50];
char fld[50][51];
int xd[4] = {0,1,0,-1};
int yd[4] = {-1,0,1,0};

int check(int y,int x){
    REPI(4){
        if(x+xd[i]<0 || y+yd[i]<0 || y+yd[i]>=H || x+xd[i]>=W ){
            continue;
        }else if(fld[y+yd[i]][x+xd[i]] == '#'){
            continue;
        }else if(cost[y+yd[i]][x+xd[i]] > cost[y][x]+1 || cost[y+yd[i]][x+xd[i]] == -1){
            cost[y+yd[i]][x+xd[i]] = cost[y][x] + 1;
            check(y+yd[i],x+xd[i]);
        }
    }
    return 0;
}

int main(){
    int res,blk=0;
    char buf;

    REPI(50){
        REPJ(50){
            cost[i][j] = -1;
        }
    }

    scanf("%d %d",&H,&W);
    scanf("%c",&buf);

    REPI(H){
        fgets(fld[i],52,stdin);
    }
    
    cost[0][0] = 1;
    check(0,0);

    REPI(H){
        REPJ(W){
            if(fld[i][j] == '#')
                blk++;            
        }
    }

    if(cost[H-1][W-1]==-1){
        printf("%d\n",-1);
        return 0;
    }


    res = H*W - blk - cost[H-1][W-1];

    printf("%d\n",res);

    return 0;
}


Measured memory_bytes: 384
/************************************************************
	> File Name: e.cpp
	> Author: TSwiftie
	> Mail: 2224273204@qq.com 
	> Created Time: Sun 19 Jan 2020 04:54:43 PM CST
************************************************************/

#pragma GCC optimize(2)
#include <bits/stdc++.h>
#include <algorithm>
#define lowbit(x) (x&-x)
#define lc (o<<1)
#define rc (o<<1|1)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5+5;
const int MAXM = 2e5+5;
const int MOD = 1e9+7;
const int dir[4][2] = {1,0,-1,0,0,1,0,-1};
const double PI = acos(-1.0);
const double EXP = 1e-8;
void exgcd(ll a,ll b,ll &x,ll &y){
	if(!b){
		x = 1;
		y = 0;
		return ;
	}
	exgcd(b,a%b,y,x);
	y -= a/b*x;
	return ;
}
void cmb_init(int n,vector<ll> &fac,vector<ll> &inv){
	ll x, y;
	for(int i = 2;i <= n;i++){
		fac[i] = fac[i-1]*i%MOD;
		exgcd(i,MOD,x,y);
		inv[i] = inv[i-1]*(MOD+x%MOD)%MOD;
	}
}
ll cmb(ll n,ll k,vector<ll> &fac,vector<ll> &inv){
	if(n < k)
		return 0;
	if(n < 0 || k < 0)
		return 0;
	return fac[n]*(inv[k]*inv[n-k]%MOD)%MOD;
}
int main(void){
	IOS;
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n,0);
	for(int i = 0;i < n;i++)
		cin >> a[i];
	vector<ll> fac(n+1,1),inv(n+1,1);
	cmb_init(n,fac,inv);
	sort(a.begin(),a.end());
	ll sum = 0;
	for(int i = 0;i < n;i++){
		sum -= a[i]*cmb(n-i-1,k-1,fac,inv)%MOD;
		sum += a[i]*cmb(i,k-1,fac,inv)%MOD;
		sum %= MOD;
	}
	cout << sum << endl;
	return 0;
}


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

string s;

void input(){
  cin >> s;
}

void solve(){
  input();
  if(s == "Sunny"){
    cout << "Cloudy" << endl;
  }else if(s == "Cloudy"){
    cout << "Rainy" << endl;
  }else if(s == "Rainy"){
    cout << "Sunny" << endl;
  } 
}

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


Measured memory_bytes: 256
function Main(input) {
	var data = input.split("\n")
	input = data[0]
    if(input=="Sunny"){
    	console.log("Cloudy")
    }else if(input=="Cloudy"){
    	console.log("Rainy")
    }else if(input=="Rainy"){
    	console.log("Sunny")
    }
}
 
// Don't edit this line!
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
# import itertools
# import math
# from functools import reduce
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np
# import heapq
# from collections import deque

# N = int(input())
# S = input()
# n, *a = map(int, open(0))
A, B, C, X, Y = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr

# def gcd_list(numbers):
#     return reduce(math.gcd, numbers)

# if gcd_list(A) > 1:
#     print("not coprime")
#     exit()

# 高速素因数分解準備
#MAXN = 10**6+10
#sieve = [i for i in range(MAXN+1)]
#p = 2
#while p*p <= MAXN:
#    if sieve[p] == p:
#        for q in range(2*p, MAXN+1, p):
#            if sieve[q] == q:
#                sieve[q] = p
#    p += 1

if 2 * C > A + B:
    print(A * X + B * Y)
else:
    if X > Y:
        print(min(2 * C * X, 2 * C * Y + A * (X - Y)))
    else:
        print(min(2 * C * Y, 2 * C * X + B * (Y - X)))

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

int main(void){
    long long n, res = 0;
    cin >> n;
    for(int i = 1; i <= n; ++i){
        if((i%3 != 0) && (i%5 != 0)) res+= i;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3676
def main():
    n = int(input())
    hs = list(map(int, input().split()))

    ans = 0
    while True:
        if max(hs) == 0:
            break
        i = 0
        while (i < n):
            if hs[i] == 0:
                i += 1
            else:
                ans += 1
                while (i < n and hs[i] > 0):
                    hs[i] -= 1
                    i += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9056
let s = readLine()!.split(separator: " ")
let N = Int(s[0])
let M = Int(s[1])

let t = readLine()!.split(separator: " ").map({Int($0)!})

let work = t.reduce(0, {x,y in x+y})

if N! >= work {
    print(N! - work)
} else {
    print(-1)
}

Measured memory_bytes: 8332
#include <cstdio>

int main() {
	
	while(1){
		int num,n=0,i=0,a=0,b=0;
		scanf("%d",&num);
		if(num==0) break;
		n=1000-num;

	if (n>=500) {
		i++;
		n=(n-500);
	}
	if (n>=100){
		a=n/100;
		i=a+i;
		n=n%100;
	}
	if (n>=50){
		i++;
		n=(n-50);
	}
	if (n>=10){
		b=n/10;
		i=b+i;
		n=n%10;
	}
	if (n>=5){
		i++;
		n=(n-5);
	}
		i=(i+n);
	printf("%d\n",i);
	}
	
	return 0;
}

Measured memory_bytes: 1028
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
asum, s = [], 0

for i in a:
    s += i
    asum.append(s)

c = Counter(asum)
ans = 0
for i in c:
    ans += c[i]*(c[i]-1)//2
    if i == 0:
        ans += c[i]

print(ans)

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

int main() {
  string record;
  while (true) {
    cin >> record;
    if (record[0]=='0') {
      break;
    }
    int a = 0, b = 0;
    for (int j=0; j<record.size(); j++) {
      if (j>0 && record[j]=='A') {
	a++;
      } else if (j>0 && record[j]=='B') {
	b++;
      }
    }
    if (a>b) {
      a++;
    } else if (b>a) {
      b++;
    }
    cout << a << " " << b << endl;
  }
  return 0;
}

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) v.erase(remove(v.begin(), v.end(), a), v.end())
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
using namespace std;

int a[100000];
int t[3];
int res[100000];

signed main()
{
	int N;
	cin >> N;
	REP(i, N)
	{
		cin >> a[i];

		if (a[i] % 2 == 0)
		{
			if (a[i] % 4 == 0)
			{
				t[2]++;
			}
			else
			{
				t[1]++;
			}
		}
		else
		{
			t[0]++;
		}
	}

	for (int i = 2; i >= 0; i--)
	{
		if (t[i] > 0)
		{
			res[0] = i;
			break;
		}
	}

	if (t[1] > 0)
	{
		if (t[2] >= t[0])
		{
			cout << "Yes" << endl;
		}
		else
		{
			cout << "No" << endl;
		}
	}
	else
	{
		if (t[2] >= t[0] - 1)
		{
			cout << "Yes" << endl;
		}
		else
		{
			cout << "No" << endl;
		}
	}

	//for (int i = 1; i < N; i++)
	//{
	//	if (res[i - 1] == 0)
	//	{
	//		if (t[2] > 0)
	//		{
	//			t[2]--;
	//			res[i] = 2;
	//		}
	//		else
	//		{
	//			cout << "No" << endl;
	//			return 0;
	//		}
	//	}
	//	else if (res[i - 1] == 1)
	//	{
	//		if (t[1] > 0)
	//		{
	//			t[1]--;
	//			res[i] = 1;
	//		}
	//		else if (t[2] > 0)
	//		{
	//			t[2]--;
	//			res[i] = 2;
	//		}
	//		else
	//		{
	//			cout << "No" << endl;
	//			return 0;
	//		}
	//	}
	//	else if (res[i - 1] == 2)
	//	{
	//		if (t[0] > 0)
	//		{
	//			t[0]--;
	//			res[0] = 0;
	//		}
	//		else if (t[1] > 0)
	//		{
	//			t[1]--;
	//			res[i] = 1;
	//		}
	//		else if (t[2] > 0)
	//		{
	//			t[2]--;
	//			res[2] = 2;
	//		}
	//	}
	//}
	//cout << "Yes" << endl;
}

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

int main() {
	int a;
	cin >> a;
	double ans = 0;
	double x;
	string u;
	for
		(int i = 0; i < a; i++) {
		cin >> x >> u;
		if (u == "JPY") {
			ans += x;
		}
		else {
			ans += x * 380000;
		}
	}
	cout << ans << endl;

}


Measured memory_bytes: 256
#include<cstdio>
#include<deque>
#define FOR(i, a, b) for((i)=(a);(i)<(b);(i)++)
#define intq deque<int>
#define N (50)
#define M (50)

using namespace std;

int abs(int a) {
  if (a >= 0)
    return a;
  else
    return -a;
}

int main(void) {
  long a[N];
  long b[N];
  long c[M];
  long d[M];
  int n, m;
  scanf("%d %d", &n, &m);
  int i;
  FOR(i, 0, n) {
    scanf("%ld %ld", a + i, b + i);
  }
  FOR(i, 0, m) {
    scanf("%ld %ld", c + i, d + i);
  }

  intq r;

  FOR(i, 0, n) {
    int e;
    r.push_back(0);
    e = abs(a[i] - c[0]) + abs(b[i] - d[0]);
    int j;
    FOR(j, 1, m) {
      int f;
      f = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if (e > f) {
        r.pop_back();
        r.push_back(j);
        e = f;
      }
    }
  }

  FOR(i, 0, n) {
    printf("%d\n", r[i] + 1);
  }




  return 0;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
A=list(map(int,input().split()))
MOD=10**9+7

fac=[1]*(N+1)
inv=[1]*(N+1)
invfac=[1]*(N+1)
for i in range(2,N+1):
    fac[i]=fac[i-1]*i%MOD
    inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
    invfac[i]=invfac[i-1]*inv[i]%MOD

A.sort()
ans=0
for l in range(N):
    r=N-l-1
    #max
    if l>=K-1:
        ans+=A[l]*fac[l]*invfac[l-K+1]*invfac[K-1]%MOD
    #min
    if r>=K-1:
        ans-=A[l]*fac[r]*invfac[r-K+1]*invfac[K-1]%MOD
    ans%=MOD

print(ans)


Measured memory_bytes: 19536
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        if i == 0 or i == H - 1:
            print('#' * W)
        else:
            print('#' + '.' * (W - 2) + '#')
    print()


Measured memory_bytes: 5608
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    
    static final int NIL = -1;

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int[] parent = new int[n];
        int[] left = new int[n];
        int[] right = new int[n];
        Arrays.fill(parent, NIL);
        Arrays.fill(left, NIL);
        Arrays.fill(right, NIL);
        for(int i = 0; i < n; i++){
            int id = Integer.parseInt(sc.next());
            int k = Integer.parseInt(sc.next());
            int u = id;
            for(int j = 0; j < k; j++){
                int c = Integer.parseInt(sc.next());
                if(j == 0){
                    left[id] = c;
                }else{
                    right[u] = c;
                }
                u = c;
                parent[c] = id;
            }
        }
        
        int[] depth = new int[n];
        int u = 0;
        while(parent[u] != NIL){
            u = parent[u];
        }
        ArrayDeque<Integer> que = new ArrayDeque<>();
        depth[u] = 0;
        if(left[u] != NIL){
            que.add(left[u]);
        }
        while(!que.isEmpty()){
            u = que.remove();
            int d = depth[parent[u]]+1;
            while(u != NIL){
                depth[u] = d;
                if(left[u] != NIL){
                    que.add(left[u]);
                }
                u = right[u];
            }
        }
        
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < n; i++){
            sb.append("node ").append(i);
            sb.append(": parent = ").append(parent[i]);
            sb.append(", depth = ").append(depth[i]);
            if(parent[i] == NIL){
                sb.append(", root, [");
            }else if(left[i] == NIL){
                sb.append(", leaf, [");
            }else{
                sb.append(", internal node, [");
            }
            if(left[i] != NIL){
                sb.append(left[i]);
                int c = left[i];
                while(right[c] != NIL){
                    sb.append(", ").append(right[c]);
                    c = right[c];
                }
            }
            sb.append("]").append(System.lineSeparator());
        }
        System.out.print(sb);
    }
}


Measured memory_bytes: 100748
package main

import "fmt"

func main() {
	var M, D int
	fmt.Scan(&M, &D)
	ans := 0
	for m := 1; m <= M; m++ {
		for d := 1; d <= D; d++ {
			var d10, d1 int
			d10 = d / 10
			d1 = d % 10
			if d1 >= 2 && d10 >= 2 && m == (d10*d1) {
				ans++
			}
		}
	}
	fmt.Println(ans)
}


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

int cnt_2, cnt_4, length;

int main() {
	cin >> length;
	int input;
	while (cin >> input) {
		if (input % 4 == 0) {
			cnt_4++;
		} else if (input % 2 == 0) {
			cnt_2++;
		}
	}
	if (cnt_4 >= length/2) {
		cout << "Yes" << endl;
	} else if (cnt_4 < length/2 && cnt_2 >= 2*(length/2 - cnt_4)) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}


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

int main() {
  int n, t, a;
  int h[1010];
  cin >> n >> t >> a;
  for (int i = 0; i < n; i++) cin >> h[i];
  float min = 10000000.0;
  int ret;
  for (int i = 0; i < n; i++) {
    float diff = abs(a - (t - h[i] * 0.006));
    if (diff < min) {
      min = diff;
      ret = i + 1;
    }
  }
  cout << ret << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ちゃんと考えてわかって実装 */

int main(void){
    int n;
    string s;
    cin >> n >> s;
    map<char, ll> rgb;
    for(int i=0; i<n; i++){
        rgb[s[i]] += 1;
    }

    ll ans = rgb['R'] * rgb['G'] * rgb['B'];

    for(int st=1; st<=2000; st++){
        for(int i=0; i<n; i++){
            if(i + 2*st >= n) continue;
            if(s[i] != s[i + st] && s[i + st] != s[i + 2*st] && s[i + 2*st] != s[i]){
                ans -= 1;
            }
        }
    }

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

Measured memory_bytes: 3640
def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

n = inp[0]
f = na(10,false)
f[3] = true
f[5] = true
f[7] = true
puts (f[n])? "YES" : "NO"

Measured memory_bytes: 1788
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int x = sc.nextInt();

		int st = x - k + 1;
		int ed = x + k - 1;
		for (int i = st; i <= ed; i++) {
			System.out.print(i + " ");
		}
		System.out.println();
		sc.close();
	}

}


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

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

    while (t--) {
        int n;
        cin >> n;

        vector<ll> a(n);
        REP(i, n) cin >> a[i];

        string s;
        cin >> s;

        int ans = 0;
        vector<ll> dp;
        for (int i = n - 1; i >= 0; i--) {
            for (ll p : dp)
                a[i] = min(a[i], a[i]^p);
            if (a[i]) {
                if (s[i] == '0') dp.push_back(a[i]);
                else ans = 1;
            }
        }
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 3592
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int powi(int base, int index)
{
    int ret = 1;
    for (int i = 0; i < index; i++)
    {
        ret *= base;
    }
    return ret;
}

int main()
{
    vector<int> vs(3);
    for (auto& v : vs)
    {
        cin >> v;
    }
    sort(vs.begin(), vs.end());
    int k;
    cin >> k;
    cout << (vs[0] + vs[1] + vs[2] * powi(2, k)) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P a, const P b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int main() {
    ll dp[11][1010];
    dp[0][0] = 1;
    rep(k,0,101) repr(i,9,0) rep(j,0,1001-k) {
        dp[i+1][j+k] += dp[i][j];
    }

    int n, s;
    while(cin >> n >> s){
        if(n == 0 && s == 0) break;
        cout << dp[n][s] << endl;
    }
    return 0;
}

Measured memory_bytes: 1240
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//
// int combi(int n, int k) {
//   if (n == k || k == 0)
//     return 1;
//   else {
//     return combi(n - 1, k - 1) + combi(n - 1, k);
//   }
// }

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


signed main(){
	int n; cin>>n;
  // vector<vector<char> > S;
	vector<string> S;
	rep(i,n){
		string s; cin >> s;
		// vector<char> C;
		// rep(j,10){
		// 	C.PB(s[j]);
		// }
		// sort(ALL(C));
		// S.PB(C);
		sort(ALL(s));
		S.PB(s);
		// cout << s << endl;
	}
	sort(ALL(S));
	// rep(i,n){
	// 	cout << S[i] << endl;
	// }
	// cout << endl;
	ll ans = 0;
	VI cnt;
	ll r = 1;
	rep(i,n-1){
		if(S[i]==S[i+1]) r++;
		else{
			if(r!=1) ans+=(r*(r-1)/2);
			r = 1;
		}
		// cout << r << " ";
	}
	ans+=(r*(r-1)/2);
	// cout << endl;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5748
int main(int argc, char *argv[])
{
	int a;
	int b;
	int c;
	int t;
	int i;
	scanf("%d %d %d\n", &a, &b, &c);
	i = 0;
	for (t=a; t<=b; ++t)
	{
		if ((c % t) == 0)
		{
			++i;
		}
	}
	printf("%d\n", i);
	return 0;
}

Measured memory_bytes: 600
def search(num, items, Mark):
    printlist = []
    for i in range(num):
        if not(i+1 in items):
            print(Mark, i+1)

n = int(input())
Slist = []
Hlist = []
Clist = []
Dlist = []
for i in range(n):
    MN = input().split()
    mark = MN[0]
    number = int(MN[1])
    if mark == "S":
        Slist.append(number)
    elif mark == "H":
        Hlist.append(number)
    elif mark == "C":
        Clist.append(number)
    else:
        Dlist.append(number)
    i = i+1

search(13, Slist, "S")
search(13, Hlist, "H")
search(13, Clist, "C")
search(13, Dlist, "D")

Measured memory_bytes: 7760
#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>
#include<complex>
#include<cassert>
using namespace std;
#include<atcoder/all>
using namespace atcoder;


#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 = 998244353;
const ll MAX = 4000001;
const long double eps = 1E-14;

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;
};

using mint = modint998244353;

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

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

int main() {
	ll N, M;
	cin >> N >> M;
	vector<string> s(N);
	rep(i, N)cin >> s[i];

	vector<pair<ll, ll>> koma;

	rep(i, N)rep(j, M) {
		if (s[i][j] == 'o') { koma.push_back({ i,j }); }
	}

	ll K = koma.size();

	vvvll reach(K, vvll(N, vll(M, 0)));
	rep(i, K) {
		queue<pair<ll,ll>> q;
		q.push(koma[i]);
		
		reach[i][koma[i].first][koma[i].second] = 1;

		vll dx = { 1,0 };
		vll dy = { 0,1 };

		while (!q.empty()) {
			auto p = q.front();
			q.pop();
			
			ll x = p.first;
			ll y = p.second;
			rep(j, 2) {
				ll xx = x + dx[j];
				ll yy = y + dy[j];

				if (xx == N || yy == M || reach[i][xx][yy] == 1 || s[xx][yy] == '#') { continue; }
				reach[i][xx][yy] = 1;
				q.push({ xx,yy });
			}	
		}
	}

	ll BIG = 1e9;

	mcf_graph<ll, ll> g(N* M + K + 2);
	ll st = N * M + K;
	ll tar = N * M + K + 1;

	rep(k, K) {
		rep(i, N)rep(j, M) {
			if (reach[k][i][j] == 1) {
				//cout << i << j << k << endl;
				g.add_edge(i * M + j, N * M + k, 1, BIG - (i + j - koma[k].first - koma[k].second));
			}
		}
	}

	rep(i, N* M) {
		g.add_edge(st, i, 1, 0);
	}
	rep(i, K) {
		g.add_edge(N * M + i, tar, 1, 0);
	}

	ll ans = g.flow(st, tar, K).second;
	ans = BIG * K - ans;
	cout << ans << endl;

}


Measured memory_bytes: 10804
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define REP(i,x,n) for(int i = (x); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

int main(void)
{
    ll n, ans=0;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(rall(a));
    ll t = n-1;
    rep(i,n){
        ll lim = 2;
        if(i == 0) lim = 1;
        rep(j,lim){
            if(t > 0){
                ans += a[i];
                t--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define N 500000

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

struct Node *NIL,*root;

void inorder(struct Node *);
void preorder(struct Node *);
void insert(int);


int main() {
    int n,x,i;
    char com[N][10];
    
    scanf("%d",&n);
    
    for(i=0; i<n; i++) {
        scanf("%s",com[i]);
        
        if(strcmp(com[i],"insert")==0) {
            scanf("%d",&x);
            insert(x);
        }
        if(strcmp(com[i],"print")==0) {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    
    return 0;
}


void inorder(struct Node *x) {
    if(x==NIL) return;
    
    inorder(x->l);
    printf(" %d",x->key);
    inorder(x->r);
}


void preorder(struct Node *x) {
    if(x==NIL) return;
    
    printf(" %d",x->key);
    preorder(x->l);
    preorder(x->r);
}


void insert(int k) {
    struct Node *y=NIL;
    struct Node *x=root;
    struct Node *z;
    
    z = malloc(sizeof(struct Node));
    z->key = k;
    z->l = NIL;
    z->r = NIL;
    
    while(x!=NIL) {
        y = x;
        if(z->key < x->key) x=x->l;
        else x=x->r;
    }
    
    z->p = y;
    
    if(y==NIL) root = z;
    else if(z->key < y->key) y->l = z;
    else y->r = z;
}

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

using namespace std;

int func(int n) {
	if (n % 2 == 0) return n / 2;
	else return 3 * n + 1;
}

int main() {
	int i, j;
	vector<int> a(1000002);
	cin >> a[1];

	int m;
	for (i = 2; i < 1000001; i++) {
		a[i] = func(a[i - 1]);
		for (j = 1; j < i; j++) {
			if (a[i] == a[j]) {
				m = i;
				i = 1000001;
				break;
			}
		}
	}

	cout << m << endl;

	return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <math.h>
#include <algorithm>
#include <queue>
#include <map>
#include <list>
//#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = (a), i##formax = (b); i < i##formax; i++)
typedef long long ll;

int main()
{
    int n, k;
    int r, s, p;
    map<char, int> dic{{'r', 2}, {'s', 0}, {'p', 1}};
    vector<int> cnt(3);
    string t;
    bool flag = true;
    cin >> n >> k >> r >> s >> p >> t;
    FOR(i, 0, n)
    {
        if (i >= k)
        {
            if (t[i - k] == t[i])
            {
                t[i] = 'a';
            }
            else { cnt[dic[t[i]]]++; }
        }
        else { cnt[dic[t[i]]]++; }
    }
    ll score = cnt[0] * r + cnt[1] * s + cnt[2] * p;
    cout << score << endl;
    return 0;
}

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

int main(){
    string s;
    cin >> s;
    if(s == "SUN") cout << 7 << endl;
    else if(s == "MON") cout << 6 << endl;
    else if(s == "TUE") cout << 5 << endl;
    else if(s == "WED") cout << 4 << endl;
    else if(s == "THU") cout << 3 << endl;
    else if(s == "FRI") cout << 2 << endl;
    else cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    String N = sc.next();
    String first = N.substring(0,1);
    String second = N.substring(1,2);
    String third = N.substring(2,3);
    if(first.equals("7") || second.equals("7") || third.equals("7")){
        System.out.println("Yes");
    } else {
        System.out.println("No");
    }
  }
}

Measured memory_bytes: 35672