akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
"""
Created on Thu May  3 21:24:25 2018
ALDS1_6_C
@author: maezawa
"""
a = []
n = int(input())
for i in range(n):
    s = input().split()
    a.append([s[0], int(s[1])])
    
a_in = a.copy()

def is_stable(a, b):
    s = True
    for i in range(n-1):
        if b[i+1][1] == b[i][1]:
            j = a.index(b[i])
            k = a.index(b[i+1])
            if j > k:
                s = False
                return s
    return s
    

def partition(a, p, r):
    x = a[r][1]
    i = p - 1
    for j in range(p, r):
        if a[j][1] <= x:
            i += 1
            temp = a[i]
            a[i] = a[j]
            a[j] = temp
    temp = a[i+1]
    a[i+1] = a[r]
    a[r] = temp
    return i+1
    
def quick_sort(a, p, r):
    if p < r:
        q = partition(a, p, r)
        quick_sort(a, p, q-1)
        quick_sort(a, q+1, r)

quick_sort(a, 0, len(a)-1)
if is_stable(a_in, a):
    print('Stable')
else:
    print('Not stable')
for i in range(len(a)):
    print('{} {}'.format(a[i][0],a[i][1]))




Measured memory_bytes: 18588
import sys

def main():
    sinputl = sys.stdin.readline

    input = [int(sinputl()) for _ in range(5)]

    input.sort(key=lambda x: (x - 1) % 10)

    time = input.pop(0)

    for x in input:
        time += (x + 9) // 10 * 10

    print(time)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
"""
きょうぎぷろぐらみんぐ！！！！！！
競プロ競プロ競プロ競プロ競プロ競プローーーーー！！！！！！！
hshs！！ﾊｱﾊｱ！！興奮興奮！！！！うおおおおおおお！！！
競プロの重要性！！ｺﾞﾝｺﾞﾝｺﾞﾝｺﾞﾝ(頭を難易度の壁に打ち付ける音)
うおおおおおおお！！競プロの重要性！！
"""
from scipy.sparse.csgraph import shortest_path
from scipy.sparse import csr_matrix
h,w=map(int,input().split())
num=[list(map(int,input().split())) for _ in range(10)]
num=csr_matrix(num)
ans=shortest_path(num)
ans=ans.tolist()
ans2=[0]*10
for i in range(10):
    ans2[i]=int(ans[i][1])
ans3=0
for i in range(h):
    a=list(map(int,input().split()))
    for j in range(w):
        if a[j]!=-1:
            ans3+=ans2[a[j]]
print(ans3)


Measured memory_bytes: 37916
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

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

    int h, w;
    cin >> h >> w;

    vector<bool> eh(h, 0);
    vector<bool> ew(w, 0);
    string s[h];
    rep(i, h) {
        cin >> s[i];
    }

    rep(i, h) {
        rep(j, w) {
            if (s[i][j] == '#') {
                eh[i] = 1;
                ew[j] = 1;
            }
        }
    }


    rep(i, h) {
        if (eh[i] == 0) continue;
        rep(j, w) {
            if (ew[j] == 0) continue;
            cout << s[i][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
A=[[0 for i in range(2)] for j in range(n)]
ans=0

for i in range(n):
  A[i][0],A[i][1]=map(int,input().split())

A.sort()

for i in range(n):
  if A[i][1]<=m:
    ans+=A[i][0]*A[i][1]
    m-=A[i][1]
  
  else:
    ans+=A[i][0]*m
    break
    
print(ans)
      


Measured memory_bytes: 21548
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int a,b,c,i,y[]=new int[750];
		a=sc.nextInt();
		b=sc.nextInt();
		while(true){
			c=0;
			if(a==0 && b==0) break;
			for(i=a;i<=b;i++){
				if(i%4==0 && (i%100!=0 || i%400==0)){
					y[c++]=i;
				}
			}
			if(c>0){
				for(i=0;i<c;i++)
					System.out.println(y[i]);
			}
			else{
				System.out.println("NA");
			}
			a=sc.nextInt();
			b=sc.nextInt();
			if(a!=0 && b!=0)
			System.out.println("");
		}//
	}
}

Measured memory_bytes: 12000
#include <stdio.h>
#include <stdlib.h>//random,NULL
#include <string.h>
#include <time.h>
#include <unistd.h>//sleep()
#include <math.h>
#include <stdbool.h>

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000

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

int main(){
  char buf[1024];
  char S[200010];
  int N;

  fgets(buf,sizeof(buf),stdin);
  sscanf(buf, "%d", &N);

  fgets(S,sizeof(S),stdin);

  int countw=0;
  int countb=0;

  rep(i,N){
    if(S[i]=='.'){
      countw++;
    }
    else{
      countb++;
    }
  }

  //printf("%d, %d\n", countw, countb);

  int *cleftb=(int *)malloc(sizeof(int)*(N+1));
  int *crightw=(int *)malloc(sizeof(int)*(N+1));

  cleftb[0]=0;
  crightw[0]=countw;

  srep(i,1,N+1){
    if(S[i-1]=='#'){
      cleftb[i]=cleftb[i-1]+1;
      crightw[i]=crightw[i-1];
    }
    else{
      cleftb[i]=cleftb[i-1];
      crightw[i]=crightw[i-1]-1;
    }
  }

  // rep(i,N){
  //   printf("%d %d\n", cleftb[i], crightw[i]);
  // }

  int ans=cleftb[0]+crightw[0];
  rep(i,N+1){
    ans=min(ans, cleftb[i]+crightw[i]);
  }

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

  return 0;


}


Measured memory_bytes: 1920
using System;
using System.Linq;

namespace AtCoderMake.EX_NOMURA2020
{
    class N20A
    {
        static void Main(string[] args)
        {
            var abc = Console.ReadLine().Split().Select((x) => int.Parse(x)).ToArray();
            int minite = 0;
            minite = (abc[2] - abc[0]);
            minite *= 60;

            minite += abc[3];
            minite -= abc[1];
            minite -= abc[4];
            Console.WriteLine(minite);
        }
    }
}


Measured memory_bytes: 28304
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
using namespace std;

int
main(int argc, char *argv[])
{
  int a, b;
  cin >> a >> b;
  cout << max((b > 0 ? a + b : a - b), a * b) << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc145/tasks/abc145_f>
 問題文============================================================
 F - Laminate
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N,K; cin >> N >> K;
    vector<ll> H(N+1);
    for(int i = 1; i <= N;i++) cin >> H[i];
    
    // dp[i][j] := i番目まで見た時、j項を選択した場合の最小操作回数
    /*
     dp[i][j]
     
        dp[i][j] = min dp[k][j-1] + max(0,H[i]-H[k])
        k = 1 : i-1
     */
    auto dp = make_v<ll>(N+1,N+1);
    fill_v(dp,LINF);
    dp[0][0] = 0;
    
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N;j++){
            
            for(int k = 0; k < i;k++){
                dp[i][j] = min(dp[i][j],dp[k][j-1] + max(0LL,H[i]-H[k]));
            }
            
        }
    }
    
    res = LINF;
    for(int i = 0; i <= N;i++){
        res = min(res,dp[i][N-K]);
    }
    
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


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

int main(){

int m,f,r;
char ans;

while(1){

cin >> m >> f >> r ;

if (m == -1 && f == -1 && r == -1) break;

else if (m == -1 || f == -1) ans = 'F';

else if (m + f >= 80) ans = 'A';

else if (65 <= m + f && m + f < 80 ) ans = 'B';

else if (50 <= m + f && m + f < 65) ans = 'C';

else if (30 <= m + f && m + f < 50){
    if (50 <= r) ans = 'C';
    else ans = 'D';
} 
else ans = 'F';

cout << ans << endl;
}

}


Measured memory_bytes: 3080
#include<stdio.h>

#define MAX 100000

int p(int i){
  return i/2;
}

int l(int i){
  return 2*i;
}

int r(int i){
  return 2*i + 1;
}

int main(){
  int h,i,array[MAX+1];
  int a,b,c;
  
    scanf("%d",&h);
  
  for(i = 1;i <= h;i++){
  
    scanf("%d",&array[i]);
  }
  for(i = 1;i <= h;i++){
    printf("node %d: key = %d, ",i,array[i]);
    if(p(i) >= 1)printf("parent key = %d, ",array[a=p(i)]);
    if(l(i) <= h)printf("left key = %d, ",array[b=l(i)]);
    if(r(i) <= h)printf("right key = %d, ",array[c=r(i)]);
    printf("\n");
  }
  return 0;
}



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

int64_t MOD = 1000000007;
int64_t MAX = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int N, sum = 0;
    cin >> N;
    vector<int> list(N);
    for (int i = 0; i < N; i++)
    {
        cin >> list[i];
        sum += list[i];
    }
    sort(list.begin(), list.end());
    if (list[N - 1] < sum - list[N - 1])
        cout << "Yes";
    else
        cout << "No";
}

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

int N, L;

int taste(int i) {
	return L + i - 1;
}

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

	int taste_all = 0;
	for (int i = 1; i <= N; i++)
	{
		taste_all += taste(i);
	}

	int ans = 0;
	int min_abs = 10000;
	for (int i = 1; i <= N; i++)
	{
		int t = taste(i);
		if (min_abs > abs(t)) {
			min_abs = min(min_abs, abs(t));
			ans = taste_all - t;
		}
	}
	
	cout << ans << endl;
	cin >> ans;
	return 0;
}



Measured memory_bytes: 256
h[8],j;float v;main(i){for(;~scanf("%f",&v);j=1)i=v/5-30,h[i<2?2:i>7?7:i]+=j;for(;h[j]--||j<7&&printf("%d:",j++);)putchar(h[j]?42:10);exit(0);}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define ip pair<ll,ll>
#define ff first
#define ss second
#define MAX 100005
const ll MOD = 1000000007;

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

	int n;
	cin>>n;
	int a[n+1];
	int ans = 0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(i&1 && a[i]&1)
			++ans;
	}

	cout<<ans<<"\n";
}

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

#define long long long int

using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    int a, b;
    cin >> a >> b;
    if (a > 9 || b > 9) {
        cout << -1;
    } else {
        cout << a * b;
    }


    return 0;
}

Measured memory_bytes: 256
def main():
    N, P = (int(i) for i in input().split())
    A = [int(i) % 2 for i in input().split()]
    from collections import Counter
    c = Counter(A)
    ans = 0
    if P == 0:
        ans = 2**c[0]
        if c[1]:
            ans *= 2**(c[1]-1)
    else:
        if c[1]:
            ans = 2**(c[1]-1)
        ans *= 2**c[0]
    # print(c)
    print(ans)


if __name__ == '__main__':
    main()


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

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
	}

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

		int N = nextInt();
		int A = nextInt();
		int B = nextInt();
		long ans=N-A;


		System.out.println(ans%B);

	}
	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


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

using namespace std;

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

    sort(arr, arr+i);
    int value = sum-arr[n-1];

    if(value>arr[n-1]){
        printf("Yes\n");
    }
    else
        printf("No\n");

    return 0;
}


Measured memory_bytes: 256
#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

n=int(input())
a=input_array()
q=int(input())
BC=[input_array() for _ in range(q)]
SUM=sum(a)

A=[0]*(10**5+1)
for i in a:
	A[i]+=1

for bc in BC:
	diff= bc[1]-bc[0]
	SUM+=diff*A[bc[0]]
	A[bc[1]]+=A[bc[0]]
	A[bc[0]]-=A[bc[0]]
	print(SUM)

Measured memory_bytes: 32128
a = int(input())
b = int(input())
c = int(input())
x = int(input())

cnt = 0
ca = int(x/500)
if(ca>a):
    ca = a

for i in range(ca+1):
    ax = x - 500*i
    cb = int(ax/100)
    
    for j in range(cb+1):
        if(j>b):
            continue
        bx = x - 500*i - 100*j
        cc = int(bx/50)
        
        if(cc>c):
            continue
        
        cnt += 1


print(cnt)


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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;


ll mod = 1e9 + 7ll;
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; }
const ll INF = 1ll << 60;
const double PI=3.14159265358979323846;



int main(){
    int a, b;
    double x;
    scanf("%d%d%lf", &a, &b, &x);
    if(a * a * b / 2 > x) {
        double c = 2 * x / a / b;
        double res = atan(b / c) * 180 / PI;
        printf("%.10lf\n", res);
    } else {
        double c = 2 * (b - (x / a / a));
        double res = atan(c / a) * 180 / PI;
        printf("%.10lf\n", res);
    }
    return 0;
}

Measured memory_bytes: 4076
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll n;
  cin >> n;
  vector<ll> a(n),ans(n);
  rep(i,n){
    cin >> a.at(i);
    if(i!=0 &&a.at(i)==0){
      cout << 0;
      return 0;
    }
    if(i==0 && a.at(i)!=0){
      cout << 0;
      return 0;
    }
    if(a.at(i)==0){
      continue;
    }
    ans.at(a.at(i)-1)++;
  }
  ll ans1=1,mod=998244353;
  rep(i,n-1){
    if(ans.at(i)==0 && ans.at(i+1)!=0){
      cout << 0;
      return 0;
    }
    for(ll j=0;j<ans.at(i+1);j++){
      ans1*=ans.at(i);
      ans1%=mod;
    }
  }
  cout << ans1;
}
  

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

ll dp[55][2505][55];

int main(){
  int n,a;
  cin>>n>>a;
  dp[0][0][0]=1;
  rep(i,n){
    int x;
    cin>>x;
    rep(j,2501){
      rep(k,i+1){
	dp[i+1][j+x][k+1]+=dp[i][j][k];
	dp[i+1][j][k]+=dp[i][j][k];
      }
    }
  }
  ll ans=0;
  rep(j,2501){
    rep(k,n+1){
      if(k==0) continue;
      if(j%k) continue;
      if(j/k==a) ans+=dp[n][j][k];
    }
  }
  cout<<ans<<endl;
  return 0;
}

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



int main(){
   	int n, tam = 0, soma = 0;
    scanf("%d", &n);
	int v = n;
	while(n>0){
		soma = soma + n%10;
		n = n/10;	
	}  
  	 		
	if(v%soma == 0)
    	printf("Yes\n");
    else{
     	printf("No\n");   
    }
    return 0;
}


Measured memory_bytes: 128
from bisect import bisect, bisect_left


size = 10 ** 5 + 1

is_prime = [True] * size
is_prime[0] = is_prime[1] = False

# √size まで
for i in range(2, 317):
  j = 2 * i
  while j < size:
    is_prime[j] = False
    j += i

# 先に like_numbers のテーブルを作っておく    
like_numbers = [
  i 
  for i, x in enumerate(is_prime)
  if x and (i + 1) % 2 == 0 and is_prime[(i + 1) // 2]
]

Q = int(input())

for _ in range(Q):
  l, r = map(int, input().split())
  # l から r まで探索してると 10^5 かかって間に合わないので二分探索を行う
  print(bisect(like_numbers, r) - bisect_left(like_numbers, l))  
  

Measured memory_bytes: 56280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;
int main(){
    int s,w;
    cin>>s>>w;
    if (s<=w)
    {
        /* code */
        cout<<"unsafe"<<endl;
    }
    else
    {
        cout<<"safe"<<endl;
    }
    
    
        }


Measured memory_bytes: 3636
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    int A,B,C;
    cin>>A>>B>>C;
    int K;
    cin>>K;
    int cou=0;
    while(A>=B){
        B*=2;
        cou++;
    }
    while(B>=C){
        C*=2;
        cou++;
    }
    if(cou<=K)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <set>

#define PI 3.1415926535897

typedef long long ll;

using namespace std;

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

	if (s.size() + 1 == t.size() && equal(begin(s), end(s), begin(t))) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

Measured memory_bytes: 3628
//============================
// ABC133a T or T
//
// 2019/08/15
//============================

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

int main(int argc, char* argv[])
{
  int n, a, b;
  cin >> n >> a >> b;

  cout << min(a*n, b) << endl;

  return 0;
}

Measured memory_bytes: 256
//  0008.cpp
//  2012/09/03.

#if 1

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
    int n;
	while(cin >> n)
	{
		int res = 0;
		rep(a, 10) rep(b, 10) rep(c, 10) rep(d, 10) if(a + b + c + d == n) res++;
		cout << res << endl;
	}
}

#endif

Measured memory_bytes: 1160
import           Control.Monad

main :: IO ()
main = do
    n <- readLn :: IO Int
    ns <- replicateM (n - 1) $ do
        [c, s, f] <- getInts
        return (c, (s, f))
    mapM_ print $ solve ns

getInts :: IO [Int]
getInts = map read . words <$> getLine

solve cs = loop cs
    where
      loop []     = [0]
      loop (x:xs) = go (fst (snd x) + fst x) xs : loop xs
      go acc [] = acc
      go acc (x:xs)
          | acc <= s = go (s + c) xs
          | acc `mod` f == 0 = go (acc + c) xs
          | otherwise = let m = (f - (acc `mod` f)) in
                go (acc + m + c) xs
        where
          (c, (s, f)) = x



Measured memory_bytes: 1276
#include <cstdio>
int n, a[200005], b[200005];
long long ans;
long long calc(int x){ return 1ll * x * (x - 1) / 2; }
int main(){
  scanf("%d", &n);
  for (register int i = 1; i <= n; ++i)
    scanf("%d", &a[i]), ++b[a[i]];
  for (register int i = 1; i <= n; ++i)
    ans += calc(b[i]);
  for (register int i = 1; i <= n; ++i)
    printf("%lld\n", ans - calc(b[a[i]]) + calc(b[a[i]] - 1));
}

Measured memory_bytes: 3584
import heapq

a = []
heapq.heapify(a)

while True:
    x = input()
    if x == "end":
        break
    elif x == "extract":
        print(-heapq.heappop(a))
    else:
        p, q = x.split()
        heapq.heappush(a, -int(q))
    


Measured memory_bytes: 45308
import bisect

N=int(input())
A=[int(x) for x in input().split()]
B=[int(x) for x in input().split()]
C=[int(x) for x in input().split()]

A.sort()
B.sort()
C.sort()
ans=0
for i in range(N):
  a=bisect.bisect_right(C,B[i])
  b=bisect.bisect_left(A,B[i])
  ans+=(N-a)*b
print(ans)

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

int main(void)
{
    ll n, k;
    cin >> n >> k;
    
    vector<int> a(n);
    rep(i,n)cin >> a.at(i);

    vector<int> s,ord(n+1,-1);
    int c=1,l=0;
    int v=1;
    while(ord.at(v)==-1){
        ord.at(v)=s.size();
        s.push_back(v);
        v=a.at(v-1);
    }
    c=s.size()-ord.at(v);
    l=ord.at(v);
    
    if(k<l)cout<<s.at(k)<<endl;
    else{
        k-=l;
        k%=c;
        cout<<s.at(l+k)<<endl;
    }
    return 0;
}


Measured memory_bytes: 5804
#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>;

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

Measured memory_bytes: 3592
#include<iostream>
using namespace std;
        long long int x=0;
	long long int y=0;
	long long int ba=0;
	long long int r=0;   
int main(){
	int n=0;
	int a[200005];
	int i=0;
	int j=0;
	for(i=0;i<200005;i++){
		a[i]=0;
	}
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=0;i<n-1;i++){
		if(i==0){
			x=a[i];
			for(j=1;j<n;j++){
				y=y+a[j];
				r=x-y;
				
				if(r<0)r=r*-1;
				ba=r;
			}
		}else{
			x=x+a[i];
			y=y-a[i];
			r=x-y;
			if(r<0)r=r*-1;
			if(ba<r){
				r=ba;
			}
			ba=r;
		}
	}
	cout<<r<<endl; 
}

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

#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  string s;
  cin >> s;
  if (s[0] == '7' || s[1] == '7' || s[2] == '7') {
    yes();
  } else {
    no();
  }
}

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

int main() {

    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;

    if(x >= r && x <= w - r && y >= r && y <= h - r) cout << "Yes" << endl;
    else cout << "No" << endl;

}


Measured memory_bytes: 3116
N = int(input())
L = list( map( int, input().split() ) )

import bisect
L=sorted(L)
comb = 0
for a in range(N-2):
    for b in range(1+a,N-1):
        posIndex = bisect.bisect_left(L, L[a] + L[b])
        comb += posIndex - b - 1 if posIndex != 0 else 0
print(comb)

Measured memory_bytes: 3188
import math

A,B,M = map(int,input().split())

a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))

cur_best = min(a_list) + min(b_list)

for i in range(M):
    a_index,b_index,discount = map(int,input().split())
    
    price = a_list[a_index-1] + b_list[b_index-1] - discount
    
    cur_best = min(cur_best,price)
    
print(cur_best)


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

int N,x,y;
int a[100100];

int main() {
    cin>>N;
    for (int i=1; i<=N; i++) {
        cin>>a[i];
        if(a[i]%2==1) {
            x++;
        } else if(a[i]%4==0) {
            y++;
        }
    }
    if ((x+y==N) && (y==x-1)) {
        cout<<"Yes"<<endl;
    } else if (y>=x) {
        cout<<"Yes"<<endl;
    } else {
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3988
#include <iostream>

using namespace std;

int main()
{
	int D, L, S;
	S = 1;
	cin >> D >> L;

	if (D % L == 0)
	{
		cout <<  D / L << endl;
	}else
	{
		int remain = D % L / S;
		cout << D / L + remain << endl;

	}

    return 0;
}


Measured memory_bytes: 3108
def main():
    h, w = map(int, input().split())
    grid = [input() for _ in [0]*h]
    memo = [[0]*w for _ in [0]*h]
    for k in range(h+w):
        for i in range(max(0, k-w+1), min(h, k+1)):
            j = k-i
            if i == j == 0:
                continue
            if i == 0:
                memo[i][j] = memo[i][j-1]+(grid[i][j] != grid[i][j-1])
            elif j == 0:
                memo[i][j] = memo[i-1][j]+(grid[i][j] != grid[i-1][j])
            else:
                memo[i][j] = min(memo[i][j-1]+(grid[i][j] != grid[i][j-1]),
                                 memo[i-1][j]+(grid[i][j] != grid[i-1][j]))
    print((memo[h-1][w-1]+(grid[0][0] == "#")+(grid[h-1][w-1] == "#"))//2)


main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define base 1000000007LL
#define ll long long
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define CLR(a) memset(a,0,sizeof(a))
#define FOR(i,a,b) for(ll i=(a),_b=(b); i<=_b; i++)
#define FORE(i,a,b) for(ll i=(a),_b=(b); i>=_b; i--)

using namespace std;

typedef pair<int, int> II;
typedef vector<II> vi;

string a[4];
int n[4];

int main()
{
    ios::sync_with_stdio(0);
    //freopen("inp.txt", "r", stdin);
    cin >> a[1] >> a[2] >> a[3];
    int now = 1;
    n[1] = n[2] = n[3] = 0;
    while (1) {
        if (a[now].length() <= n[now]) {
            if (now == 1) cout << "A";
            else if (now == 2) cout << "B";
            else cout << "C";
            return 0;
        }
        char ch = a[now][n[now]++];
        if (ch == 'a') now = 1;
        if (ch == 'b') now = 2;
        if (ch == 'c') now = 3;
    }
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Program
{
    internal static void Main(string[] args) {
        var A = int.Parse(ReadLine());
        var B = int.Parse(ReadLine());
        var C = int.Parse(ReadLine());
        var X = int.Parse(ReadLine());
        int ans = 0;

        for (int a = 0; a <= A; a++) {
            for (int b = 0; b <= B; b++) {
                for (int c = 0; c <= C; c++) {
                    if ((500 * a) + (100 * b) + (50 * c) == X) { ans++; }
                }
            }
        }
        WriteLine(ans);
    }
}


Measured memory_bytes: 13140
class SegmentTree:
    def __init__(self, initial_values, f=max, zero=0):
        self.__size = len(initial_values)
        self.__n = 1 << ((self.__size - 1).bit_length())
        self.__f = f
        self.__z = zero
        self.__dat = [zero for _ in range(2 * self.__n)]
        self.__get_leaf = lambda i: self.__n + i - 1
        self.__get_parent = lambda i: (i-1)//2
        self.__get_children = lambda i: (self.__dat[2*i+1], self.__dat[2*i+2])
        self.__is_left = lambda i: i&1 == 1
        self.__is_right = lambda i: i&1 == 0
        zi = self.__get_leaf(0)
        for i, v in enumerate(initial_values):
            self.__dat[zi + i] = v
        for i in range(zi-1, -1, -1):
            self.__dat[i] = self.__f(*self.__get_children(i))
    
    def update(self, index, value):
        i = self.__get_leaf(index)
        if self.__dat[i] == value: return
        self.__dat[i] = value
        while i > 0:
            i = self.__get_parent(i)
            self.__dat[i] = self.__f(*self.__get_children(i))
    
    def query(self, from_inclusive, to_exclusive):
        if to_exclusive <= from_inclusive: return self.__z
        a, b = self.__get_leaf(from_inclusive), self.__get_leaf(to_exclusive) - 1
        ans = self.__z
        while b - a > 1:
            if self.__is_right(a): ans = self.__f(ans, self.__dat[a])
            if self.__is_left(b): ans, b = self.__f(ans, self.__dat[b]), b-1
            a, b = a//2, self.__get_parent(b)
        ans = self.__f(ans, self.__dat[a])
        if a != b: ans = self.__f(ans, self.__dat[b])
        return ans

N = int(input())
S = input()
g = lambda c: 1 << (ord(c)-ord('a'))
tree = SegmentTree([g(c) for c in S], lambda x,y:x|y)
Q = int(input())
for _ in range(Q):
    t, a, b = input().split()
    if t == '1': tree.update(int(a)-1, g(b))
    else: print(bin(tree.query(int(a)-1, int(b))).count('1'))

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

const int maxn = 5005;

int dp[maxn][maxn];

int fa[maxn], sz[maxn];
int p[maxn];
int n;
int power[maxn];
const int mod = 1e9 + 7;

int Find(int x){
    return x == fa[x] ? x : fa[x] = Find(fa[x]);
}

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


int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    power[0] = 1;
    for(int i = 1;i <= n;i++){
        fa[i] = i;
        sz[i] = 1;
        power[i] = 1LL * power[i - 1] * (n - 1) % mod;
    }
    for(int i = 1;i <= n;i++){
        cin >> p[i];
        if(p[i] != -1){
            int fx = Find(i);
            int fy = Find(p[i]);
            if(fx != fy){
                fa[fx] = fy;
                sz[fy] += sz[fx];
            }
        }
    } 
    int cycle = 0;
    int m = 0;
    vector<int> v;
    for(int i = 1;i <= n;i++){
        if(p[i] == -1){
            m++;
        }
        int fx = Find(i);
        if(fx == i){
            if(p[i] == -1){
                v.push_back(sz[i]);
            }else{
                cycle++;
            }
        }
    }
    //for(int i = 0;i < v.size();i++){
    //    cout << v[i] << " ";
    //}
    //cout << endl;
    dp[0][0] = 1;
    for(int i = 0;i < v.size();i++){
        for(int j = 0;j <= v.size();j++){
            dp[i + 1][j] = dp[i][j];
            if(j > 0){
                int tmp = 1LL * dp[i][j - 1] * v[i] % mod;
                if(j - 1 > 0){
                    tmp = 1LL * tmp * (j - 1) % mod;
                }
                add(dp[i + 1][j], tmp);
            }
        }
    } 
    int ans = 1LL * power[m] * (n - cycle) % mod;
    for(int i = 0;i < v.size();i++){
        if(v[i] > 1){
            int tmp = 1LL * power[m - 1] * (v[i] - 1) % mod;
            ans = (ans - tmp + mod) % mod;
        }
    }
    int K = v.size();
    for(int j = 2;j <= v.size();j++){
        int tmp;
        tmp = 1LL * dp[K][j] * power[m - j] % mod;
        //cout << dp[K][j] << " " << tmp << endl;
        ans = (ans - tmp + mod) % mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 101512
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <limits>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, a, n) for (int i = a; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eps 1e-15

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef tuple<int, int, int> ti3;

int main()
{
    int n;
    scanf("%d", &n);

    if (n <= 999) {
        printf("ABC\n");
    } else {
        printf("ABD\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int n; cin >> n;
	ll ans = 0;
	rep(i, 1, n + 1) {
		if(i % 3 && i % 5) ans += i;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <sstream>
#include <cmath>

using namespace std;


int main(int argc, const char * argv[]) {
    long long N; cin >> N;
    long long min_capacity = (long long)pow(10, 15);
    for (int i = 0; i < 5; i++) {
        long long tmp; cin >> tmp;
        min_capacity = min(tmp, min_capacity);
    }
    auto r = lldiv(N, min_capacity);
    cout << (4 + r.quot + min((long long)1, r.rem)) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int INF=1e9+7;
long long dp[60][2];
int main(){
	int n,p,x;
	scanf("%d%d",&n,&p);
	dp[0][0]=1LL;
	rep1(k,n){
		scanf("%d",&x);x&=1;
		dp[k][1]=dp[k-1][x^1]+dp[k-1][1];
		dp[k][0]=dp[k-1][x]+dp[k-1][0];
	}
	printf("%lld",dp[n][p]);
	return 0;
}

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

int main() {

    int X, A;
    cin >> X >> A;

    if (X < A) cout << 0 <<endl;
    else cout << 10 << endl;

    return 0;
}

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

using namespace std;

int main(){
    int N;
    cin >> N;
    for (int i = 0; i < 100/4; ++i) {
        for (int j = 0; j < 100/7+1; ++j) {
            if(4*i+7*j == N){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#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 ; 0 <= i ; i--)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define CEVCOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>
int main(void){


    int N;  cin >> N;
    vector<pair<int , int>> pa(N);
    for(int i = 0 ; i < N ; i++){
      int input;    cin >> input;
      pa[i] = make_pair(input, i + 1);
    }

    sort(ALL(pa));
    for(int i = 0 ; i < N ; i++)
      SCOUT(pa[i].second);

    cout << endl;

    return 0;
}


Measured memory_bytes: 1664
import java.util.Scanner ;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int cnt = 0;
        
        for (int i=a ; i<=b; i++){
            if (c%i == 0) cnt++;
        }
        System.out.println(cnt);
        sc.close();
    }
}


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

int main(){
    int n, m;
    cin >> n >> m;
    int a[n], b[n], c[m], d[m];
    
    for(int i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i];
    }
    for(int j = 0; j < m; j++)
    {
        cin >> c[j] >> d[j];
    }
    
    for(int i = 0; i < n; i++)
    {
        int ans=-1, distance=500000000;
        for(int j = 0; j < m; j++)
        {
            if(distance > abs(a[i]-c[j])+abs(b[i]-d[j])){
                ans = j;
                distance = abs(a[i]-c[j])+abs(b[i]-d[j]);
            }
        }
        cout << ans+1 << endl;
        
    }
    
    
    return 0;
}

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

using namespace std;

int main(){
  int N;cin>>N;
  pair<int,int> itv[N];
  for (int i=0;i<N; i++) {
    int x;cin>>x;
    int l;cin>>l;
    itv[i].first=x+l;
    itv[i].second=x-l;
  }
  sort(itv,itv+N);

  int ans=0, t=-2000000000;
  for (int i = 0; i < N; i++)
  {
    if(t<=itv[i].second){
      ans++;
      t=itv[i].first;
    }
  }
  cout<< ans  << "\n";

}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
//change null_type here for map/set
typedef tree<int,null_type,less<int>,rb_tree_tag,
            tree_order_statistics_node_update> indexed_set;
typedef long long int  ll;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define F first
#define S second

template<class T>inline bool read(T &x){
    int c=getchar();int sgn=1;
    while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}
    for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
    x*=sgn; return ~c;
}
///START HERE
///indexed_set pbd;
//pbd.insert()
//auto x = pbd.find_by_order(2);
//int od=pbd.order_of_key(7)
///rope<int> rp;
//rp.push_back()
//RandomAccess like vector
//mutable_begin, mutable_end()

int main(){
    ///read()+printf
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //fast;
    ll n,s=0;
    cin>>n;
    if(n==1){
        cout<<1;
        return 0;
    }
    for(int i=1;i<=n;i++){
        s+=i*(n/i)*(1+(n/i))/2;
    }
    cout<<s;


    return 0;
}


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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
const ll MOD = 1e9 + 7;
const int maxn = 1e6 + 10;

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    ll ans = min(a, c);
    c -= ans;
    if (b >= c) {
        ans += b + c;
    } else {
        ans += b + b + 1;
    }
    cout << ans << endl;
    return 0;
}

static int speedUp = []() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    return 0;
}();


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

using namespace std;

int main(){
  string S; cin >> S;
  int N = (int ) S.size();
  if( N == 1){ cout << 0 << endl; return 0;}
  int cnt = 0;
  for(int i = 0; i < N - 1; i++){
    if( S[i] != S[i+1]){ cnt++;}}
  
  cout << cnt << endl; return 0;}

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

int main(int argc, char const *argv[]) {
    ll N;
    std::cin >> N;
    ll a[N];
    ll mean = 0;
    for (size_t i = 0; i < N; i++) {
        std::cin >> a[i];
        mean += a[i];
    }
    mean = std::round((double)mean / N);
    ll ans = 0;
    for (size_t i = 0; i < N; i++) {
        ans += (a[i] - mean) * (a[i] - mean);
    }
    std::cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
N,K=[int(i) for i in input().split(" ")]
R,S,P=[int(i) for i in input().split(" ")]
T=input()


score=0
for i in range(K):
    hand=T[i::K]
    hand=hand.replace("pp","p")
    hand=hand.replace("rr","r")
    hand=hand.replace("ss","s")
    for h in hand:
        if h=="p":
            score+=S
        elif h=="r":
            score+=P
        else:
            score+=R
print(score)


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

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

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int N, M;
  cin >> N >> M;
  priority_queue< int > que;
  for(int i = 0; i < N; i++) {
    int x;
    cin >> x;
    que.emplace(x);
  }
  while(M--) {
    auto p = que.top();
    que.pop();
    que.emplace(p / 2);
  }
  int64 ret = 0;
  while(que.size()) {
    auto p = que.top();
    que.pop();
    ret += p;
  }
  cout << ret << endl;
}





Measured memory_bytes: 892
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<62)
typedef pair<ll, ll> P;
#define MOD (1000000007ll)
#define l_ength size
#define T ((ll)(2e12))

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

int main(void){
	int n,i,j,k;
	ll cnt[5],ans=0ll;
	string s[123456],march="MARCH";
	fill(cnt,cnt+5,0ll);
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> s[i];
		for(j=0; j<5; ++j){
			if(s[i][0] == march[j]){
				cnt[j]++;
				break;
			}
		}
	}
	for(i=0; i<5; ++i){
		for(j=(i+1); j<5; ++j){
			for(k=(j+1); k<5; ++k){
				ans += (cnt[i]*cnt[j]*cnt[k]);
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

const int H_MAX = 505;
const int W_MAX = 505;

int f[H_MAX][W_MAX];

int main() {
    int H, W;

    cin >> H >> W;

    vector< int > path_x, path_y;
    vector< int > y_src, x_src, y_dst, x_dst;

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> f[i][j];
        }
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            path_y.push_back(i);
            if (i % 2 == 0) {
                path_x.push_back(j);
            } else {
                path_x.push_back(W - 1 - j);
            }
        }
    }

    for (int i = 0; i < path_y.size() - 1; i++) {
        if (f[path_y[i]][path_x[i]] % 2 != 0) {
            f[path_y[i]][path_x[i]]--;
            f[path_y[i + 1]][path_x[i + 1]]++;

            y_src.push_back(path_y[i]);
            x_src.push_back(path_x[i]);
            y_dst.push_back(path_y[i + 1]);
            x_dst.push_back(path_x[i + 1]);
        }
    }

    cout << y_src.size() << endl;
    for (int i = 0; i < y_src.size(); i++) {
        cout << y_src[i] + 1 << " " << x_src[i] + 1 << " ";
        cout << y_dst[i] + 1 << " " << x_dst[i] + 1 << endl;
    }

    // for (int i = 0; i < H; i++) {
    //     for (int j = 0; j < W; j++) {
    //         cout << f[i][j] << " ";
    //     }
    //     cout << endl;
    // }
}

Measured memory_bytes: 8044