akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include<math.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18 

int main(){
    int n, m ;
    cin >> n >> m ;
    vector<int> h (n) ;
    rep(i, n) cin >> h[i] ; 
    vector<int> ans (n, 1) ;
    rep(i, m){
        int a, b ;
        cin >> a >> b ;
        a-- ; b-- ;
        if(h[a] > h[b]){
            ans[b] = 0 ;
        }
        else if (h[a] < h[b]){
            ans[a] = 0 ;
        }
        else {
            ans[a] = 0 ;
            ans[b] = 0 ;
        }
    }
    int num = 0;
    rep(i, n){
        num += ans[i] ;
    }
    cout << num << endl ;
}

Measured memory_bytes: 4004
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

void main_()
{
    ll n;
    vector<ll> as;
    cin >> n;

    deque<ll> bs;
    for (ll i = 0; i < n; ++i) {
        int a;
        cin >> a;
        if (i % 2 == 0) {
            bs.push_back(a);
        } else {
            bs.push_front(a);
        }
    }

    if (n % 2 == 1) {
        reverse(begin(bs), end(bs));
    }

    copy(begin(bs), end(bs), ostream_iterator<ll>(cout, " "));
    cout << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(x) x.begin(),x.end()
typedef long long ll;
ll mod = 1000000007;
ll inf = 1e18;
int main(){

    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ans;

        ans=max(max(max(a*c,b*d),a*d),b*c);


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

Measured memory_bytes: 3636
n=int(input())

C=[[] for i in range(n+1)]
P=[-1 for i in range(n+1)]
D=[0 for i in range(n+1)]
T=["" for i in range(n+1)]
#入力の取得
for i in range(n):
    data=list(map(int,input().split( )))
    C[data[0]]=data[2:]
#親
for i in range(n):
    if len(C[i])>0:
        for nodes in C[i]:
            P[nodes]=i
#深さと種類
for i in range(n):
    d=0
    v=i
    while P[v]!=-1:
        v=P[v]
        d+=1
    D[i]=d
    if d==0:
        T[i]="root"
    elif len(C[i])>0:
        T[i]= "internal node"
    else:
        T[i]="leaf"
for i in range(n):
    print(f"node {i}: parent = {P[i]}, depth = {D[i]}, {T[i]}, [",end="")
    if len(C[i])>0:
        str_i=", ".join((map(str,C[i])))
        print(str_i,end="")
    print("]")



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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

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

bool solve(string& s, int st, int ed) {
    bool result = false;
    // dream, dreamer, erase, eraser
    if (st == ed)
        return true;
    int l = ed - st;

    if (l >= 5 && s.substr(l - 5, 5) == "dream") {
        result = result | solve(s, st, ed - 5);
    }
    if (l >= 5 && s.substr(l - 5, 5) == "erase") {
        result = result | solve(s, st, ed - 5);
    }
    if (l >= 7 && s.substr(l - 7, 7) == "dreamer") {
        result = result | solve(s, st, ed - 7);
    }
    if (l >= 6 && s.substr(l - 6, 6) == "eraser") {
        result = result | solve(s, st, ed - 6);
    }

    return result;
}

int main(int argc, char** argv) {
    string s;
    cin >> s;

    if (solve(s, 0, s.length()))
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}


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

namespace B___Small_and_Large_Integers
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int A = int.Parse(str[0]);
            int B = int.Parse(str[1]);
            int K = int.Parse(str[2]);

            for (int i = A; i <= A + (K - 1); ++i)
            {
                if (i <= B)
                {
                    Console.WriteLine(i);
                }
            }

            for (int i = B - (K - 1); i <= B; ++i)
            {
                if (i > A + (K - 1))
                {
                    Console.WriteLine(i);
                }
            }

        }
    }
}


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

int main() {
  long n;
  cin >> n;
  vector<long> c(n-1);
  vector<long> s(n-1);
  vector<long> f(n-1);
  vector<long> ans(n);
  for(int i=0;i<n-1;i++) cin >> c[i] >> s[i] >> f[i];

  for(int i=0;i<n;i++) {
    for(int j=i;j<n-1;j++) {
      if(ans[i]<=s[j]) ans[i]=s[j]+c[j];
      else if(ans[i]%f[j]==0) ans[i]+=c[j];
      else ans[i]=c[j]+(ans[i]/f[j]+1)*f[j];
    }
    cout << ans[i] << endl;
  }
}

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

int main() {
  long long h, w;
  std::cin >> h >> w;
  if (h == 1 || w == 1) std::cout << 1 << std::endl;
  else std::cout << (h*w+2-1)/2 << std::endl;
  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define maxn 200001
using namespace std;
long long heng[maxn+5],shu[maxn+5]; 
int q,n;
int minx,miny;
int lowbit(int x) {return x&-x;}
long long getsum(long long *a,int pos)
{
	long long sum=0;
	pos++;
	for (pos;pos>=1;pos-=lowbit(pos))
		sum+=a[pos];
	return sum;
}
void add(long long *a,int pos,long long v)
{
	pos++;
	for (pos;pos<=maxn;pos+=lowbit(pos))
		a[pos]+=v;
	return;
}
int main()
{
	cin>>n>>q;
	minx=miny=n;
	long long ans=(long long)(n-2)*(n-2);
	for (int i=1;i<=q;i++)
	{
		int x,v;
		cin>>x>>v;
		if (x==1)
		{
			ans-=(n-2-getsum(shu,v));
//			cout<<(n-2-getsum(shu,v))<<endl;
			if (minx>v)
			{
//				cout<<"heng"<<"1~"<<miny-1<<" "<<minx-v<<endl;
				add(heng,0,minx-v);
				add(heng,miny,-(minx-v));
				minx=v;
			}
		}
		else
		{
			ans-=(n-2-getsum(heng,v));
//			cout<<(n-2-getsum(heng,v))<<endl;
			if (miny>v)
			{
//				cout<<"shu"<<"1~"<<minx-1<<" "<<miny-v<<endl;
				add(shu,0,miny-v);
				add(shu,minx,-(miny-v));
				miny=v;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 5164
#include<iostream>
#include<cmath>
#include <iomanip>
using namespace std;
int main(void){
  static const double pi = 3.141592653589793;
  int A,B,H,M;
  cin >> A >> B >> H >> M;
  double val1 = 0.0;
  double val2 = 0.0;
  val1 = pow( B*cos(M*6.0*(pi/180.0)) - A*cos( (M*0.5+H*30.0)*(pi/180.0) ), 2);
  val2 = pow( B*sin(M*6.0*(pi/180.0)) - A*sin( (M*0.5+H*30.0)*(pi/180.0) ), 2);
  double result =  sqrt(val1+val2);
  cout << fixed << setprecision(20) <<  result << endl;
  return 0;
}

Measured memory_bytes: 4236
sx,sy,tx,ty=map(int,input().split())
x=tx-sx
y=ty-sy
print('U'*y+'R'*x+'D'*y+'L'*(x+1)+'U'*(y+1)+'R'*(x+1)+'DR'+'D'*(y+1)+'L'*(x+1)+'U')


Measured memory_bytes: 61844
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=limii()
ans=0
chk={}
for p in range(n):
    i=p+1

    if i-arr[p] in chk:
        ans+=chk[i-arr[p]]
        #print(p,i,arr[p],i-arr[p],chk)
    
    if i+arr[p] in chk:
        chk[i+arr[p]]+=1
    else:
        chk[i+arr[p]]=1
    #print(i+arr[p])
#print(list(chk.values()),ans)
print(ans)

Measured memory_bytes: 122460
#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 A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    int ans;
    if (A + B <= 2 * C)
    {
        cout << A * X + B * Y << endl;
        return 0;
    } else
    {
        int temp1, temp2;
        temp1 = 2 * C * min(X, Y);
        if (X > Y)
        {
            temp1 += (A * (X - Y));
        } else
        {
            temp1 += (B * (Y - X));
        }
        temp2 = 2 * C * max(X, Y);
        ans = min(temp1, temp2);
    }
    cout << ans << endl;
    
    
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define ll long long
using namespace std;
const int mod = 1e9+7;
int main()
{
    int n;
    ll ans=1;
    cin>>n;
    for(int i=1;i<=n;i++){
        ans=(ans*i)%mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<int,int> pa;
#define w1 first
#define w2 second
#define ls (x<<1)
#define rs (x<<1|1)
#define pb push_back
#define mid ((l+r)>>1)
#define SZ(x) ((x).size())
#define All(x) (x).begin(),(x).end()
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)])
template<class T>void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
const int maxn=5e2+5;
int n;
pa x[maxn];
int ans[maxn*maxn];
int main(){
	read(n);
	rep(i,1,n)read(x[i].w1),x[i].w2=i;
	sort(x+1,x+n+1);
	int pnt=0,cnt;
	rep(i,1,n){
		cnt=0;
		while((pnt+1)<x[i].w1&&cnt+1<x[i].w2){
			pnt++;
			if(!ans[pnt])ans[pnt]=x[i].w2,cnt++;
		}
		if(cnt!=x[i].w2-1)return puts("No"),0;
		ans[x[i].w1]=x[i].w2;
	}
	rep(i,1,n){
		cnt=0;
		while(cnt+1<=n-x[i].w2){
			pnt++;
			if(!ans[pnt]){
				ans[pnt]=x[i].w2,cnt++;
				if(pnt<x[i].w1)return puts("No"),0;
			}
		}
	}
	puts("Yes");
	rep(i,1,n*n)printf("%d ",ans[i]);
	return 0;
}

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

void trace(int *a, int n) {
    for (int i = 0; i < n - 1; i++) {
        cout << a[i] << " ";
    }
    cout << a[n-1] << endl;
}

int selectionSort(int *a, int n) {
    int cnt = 0;
    for (int i = 0; i < n - 1; i++) {
        int min_offset = i;
        for (int j = i + 1; j < n; j++) {
            if (a[min_offset] > a[j]) {
                min_offset = j;
            }
        }
        if (i != min_offset) {
            int tmp = a[i];
            a[i] = a[min_offset];
            a[min_offset] = tmp;
            cnt++;
        }
    }
    return cnt;
}


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

    int cnt = selectionSort(a, n);

    trace(a, n);
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define all(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

// #define int ll
#ifdef _MSC_VER
const bool test = true;
#else 
const bool test = false;
#endif

int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
const int MAX = (int)2e5 + 5;

int main() {
	set<int> s;
	rep(i, 3) {
		int v;
		cin >> v;
		s.insert(v);
	}
	cout << s.size() << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <queue>
#include<string>
#include<cstring>
#include<complex>
#include<cmath>
using namespace std;
#define rep(i, n)   for(int i = 0; i < (int)(n); i++)
#define rrp(i, n)   for(int i = ((int)(n)); i >=0; i--)
#define mpp(i,j,k)  make_pair((int)(i),make_pair((int)(j),(int)(k)))
typedef pair<int,pair<int,int > > ppp;
typedef pair<int,int> pp;
typedef vector<int> vi;
typedef vector<vi>  vvi;

string s;

int main(){
 
 cin>>s;
int n=s.size();
int m=n;
rep(i,n){
if(s[i]=='1'){m=min(m,max(i,n-i-1));}
}
int mm=n;
rep(i,n){
if(s[i]=='0'){mm=min(mm,max(i,n-i-1));}
}
cout<<max(m,mm)<<endl;
  return 0;}




Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<functional>
#include<cctype>
#include<vector>

using namespace std;
vector<int> book[10];
vector<int> yen[10];
int dp[11][2001];

main(){
  int n,k;
  int c,g;
  int sum;
  int a=0;

  scanf("%d %d",&n,&k);
  for(int i=0;i<n;i++){
    scanf("%d %d",&c,&g);
    book[g-1].push_back(c);
  }


  for(int i=0;i<10;i++){
    sort(book[i].begin(),book[i].end(),greater<int>());
    sum=0;
    for(int j=0;j<book[i].size();j++){
      sum+=book[i][j];
      yen[i].push_back(sum+j*(j+1));
    }
  }

  for(int i=0;i<2000;i++)dp[0][i]=0;

  for(int i=0;i<10;i++){
    for(int j=0;j<yen[i].size();j++){
      a=i;
      for(int l=j;l<k;l++){
	/*
	if(i+1==2 && l+1==2){
	  printf("%d   ",dp[2][2]);
	  printf("[%d %d %d]",dp[i+1][l+1],dp[i][l+1],dp[i][l-j]+yen[i][j]);
	}
	*/
	dp[i+1][l+1]=max(max(dp[i+1][l+1],dp[i][l+1]),dp[i][l-j]+yen[i][j]);
	//	if(i+1==2 && l+1==2)printf("   %d\n",dp[2][2]);
      }
    }
  }

  /*
  for(int j=1;j<=k+1;j++) printf("%10d",j);
  puts("");
  for(int i=0;i<11;i++){
    for(int j=0;j<k+1;j++){
      printf("%10d",dp[i][j]);
    }
    printf("    ");
    for(int j=0;j<yen[i].size();j++){
      printf("%10d",yen[i][j]);
    }
    puts("");
  }
  */

  printf("%d\n",dp[a+1][k]);
}

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

int A[1000];
vector<double> den(1000);

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

  int max = 0;
  rep(i,n) {
    int h;
    scanf("%d", &h);
    if (max > h+1) {
      printf("No\n");
      return 0;
    }
    if (h > max) max = h;
  }
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 256
k = int(input())
from collections import deque
q = deque()
for i in range(1, 10):
    q.append(i)
ans = []
while len(ans) <= k:
    x = q.popleft()
    y = x%10
    if y == 0:
        q.append(x*10+0)
        q.append(x*10+1)
    elif 1 <= y <= 8:
        q.append(x*10+y-1)
        q.append(x*10+y)
        q.append(x*10+y+1)
    else:
        q.append(x*10+8)
        q.append(x*10+9)
    ans.append(x)
print(ans[k-1])


Measured memory_bytes: 82564
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
using ll = long long;
using P = pair<int, int>;
int main(){
    ll d,s,t;
    cin >> d >> t >> s;
    double minute = (double)d / (double)s;
    if (minute<=t){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3640
use std::io::*;
use std::str::FromStr;
use std::cmp::Ordering;

fn main() {
	let (n, m): (usize, usize) = (read(), read());
	let mut h = Vec::new();
	let (mut a, mut b): (usize, usize);
	for _ in 0..n {
		a = read();
		h.push(a);
	}
	let mut v = vec![0; n];
	for _ in 0..m {
		a = read();
		b = read();
		match h[a-1].cmp(&h[b-1]) {
			Ordering::Less => { v[a-1] += 1; },
			Ordering::Greater => { v[b-1] += 1; },
			Ordering::Equal => { v[a-1] += 1; v[b-1] += 1; },
		}
	}
	let mut cnt: usize = 0;
	for i in &v {
		if *i == 0 { cnt += 1; }
	}
	println!("{}", cnt);
}

fn read<T: FromStr>() -> T {
	let stdin = stdin();
	let stdin = stdin.lock();
	let token: String = stdin
		.bytes()
		.map(|c| c.expect("failed to read char") as char)
		.skip_while(|c| c.is_whitespace())
		.take_while(|c| !c.is_whitespace())
		.collect();
	token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 3168
#include<iostream>
using namespace std;
int main()
{
  int m,n,i;
  cin>>m>>n>>i;
  int count=0;
  for(int j=m;j<=n;j++)
  {
    if(j%i==0)
    {
      count++;
    }
  }
  cout<<count;
}

Measured memory_bytes: 3632
/* ex3_2
   KKOO  */

#include <stdio.h>

int main(void) {
    int pencil,one_space;
    //鉛筆の本数の入力
    scanf("%d",&pencil);

    //一の位の導出
    one_space = pencil % 10;

    //助数詞の読み分け
    if(one_space==2 || one_space==4 || one_space==5 || one_space==7 || one_space==9){
        printf("hon\n");
    }

    else if(one_space==0 || one_space==1 || one_space==6 || one_space==8){
        printf("pon\n");
    }

    else{
        printf("bon\n");
    }

    return 0;
}


Measured memory_bytes: 1656
#include <stdio.h>
#define N 100;

int main(){
  int A[1000],n,i,j,v;

  scanf("%d",&n);
  for( i=0 ; i<n ; i++){
    scanf("%d",&A[i]);
    printf("%d",A[i]);
    if(i < n-1)printf(" ");
  }
  printf("\n");

  for( i=1 ; i<n ; i++){
    v = A[i];
    j = i-1;
    while( j>=0 && A[j]>v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;

    for( v=0 ; v<n ; v++){
      printf("%d",A[v]);
      if(v < n-1)printf(" ");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 604
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]
ans = -1
for i in range(10**n):
    isAns = True
    isAns *= len(str(i)) == n
    for s, c in sc:
        isAns *= i//(10**(n-s)) % 10 == c
    if isAns:
        ans = i
        break
print(ans)

Measured memory_bytes: 9196
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
#define endl "\n"
using namespace std;
const ll N=500010;


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

    ll s,w;
    cin>>s>>w;
    if(w>=s){cout<<"unsafe";}
    else{cout<<"safe";}

    return (0);
}


Measured memory_bytes: 3652
#include <stdio.h>
int main(){
	int n,k,x,y,a,b,c;
	scanf("%d",&n);
	scanf("%d",&k);
	scanf("%d",&x);
	scanf("%d",&y);	
	if(k>=n){
		c=n*x;
	printf("%d",c);
	}else if(k<n){
		a=n-k;
		b=(x*k)+(a*y);
		printf("%d",b);
	}
	return 0;
}

Measured memory_bytes: 128
S = []
S.append(int(input()))
S.append(int(input()))
S.append(int(input()))
S.append(int(input()))
S.append(int(input()))
ch = int(input())
for i in range(len(S)):
	for j in range(i,len(S)):
		if(S[j]-S[i]>ch):
			print(":(")
			exit()
print("Yay!")

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  string s;
  cin >> s;

  vector<ll> rs;
  vector<ll> gs;
  vector<ll> bs;
  for (ll i = 0; i < s.size(); ++i) {
    if (s[i] == 'R') rs.push_back(i);
    if (s[i] == 'G') gs.push_back(i);
    if (s[i] == 'B') bs.push_back(i);
  }

  ll ans = 0;
  for (ll i = 0; i < s.size(); ++i) {
    ll r = 0;
    ll g = 0;
    ll b = 0;
    for (ll j = i+1; j < s.size(); ++j) {
      if (s[i] == 'R') {
        r = 1;
        if (s[j] == 'G') ++g;
        if (s[j] == 'B') ++b;
      }
      if (s[i] == 'G') {
        g = 1;
        if (s[j] == 'R') ++r;
        if (s[j] == 'B') ++b;
      }
      if (s[i] == 'B') {
        b = 1;
        if (s[j] == 'R') ++r;
        if (s[j] == 'G') ++g;
      }
    }
    ans += r*g*b;
  }

  each (r, rs) {
    each (g, gs) {
      if (g <= r) continue;
      ll b = g + (g - r);
      if (bs.size() == 0) continue;
      if (b > bs[bs.size()-1]) continue;
      if (s[b] == 'B') ans--;
    }
    each (b, bs) {
      if (b <= r) continue;
      ll g = b + (b - r);
      if (gs.size() == 0) continue;
      if (g > gs[gs.size()-1]) continue;
      if (s[g] == 'G') ans--;
    }
  }
  each (g, gs) {
    each (r, rs) {
      if (r <= g) continue;
      ll b = r + (r - g);
      if (bs.size() == 0) continue;
      if (b > bs[bs.size()-1]) continue;
      if (s[b] == 'B') ans--;
    }
    each (b, bs) {
      if (b <= g) continue;
      ll r = b + (b - g);
      if (rs.size() == 0) continue;
      if (r > rs[rs.size()-1]) continue;
      if (s[r] == 'R') ans--;
    }
  }
  each (b, bs) {
    each (r, rs) {
      if (r <= b) continue;
      ll g = r + (r - b);
      if (gs.size() == 0) continue;
      if (g > gs[gs.size()-1]) continue;
      if (s[g] == 'G') ans--;
    }
    each (g, gs) {
      if (g <= b) continue;
      ll r = g + (g - b);
      if (rs.size() == 0) continue;
      if (r > rs[rs.size()-1]) continue;
      if (s[r] == 'R') ans--;
    }
  }

  cout << ans << endl;

  return 0;
}

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

CSF = []

for i in range(N-1):
    C, S, F = map(int, input().split())
    CSF.append([C, S, F])

CSF.append([0, 0, 1])

ans = [0] * N

for i in range(N-1):
    t = 0
    for j in range(i, N):
        if t <= CSF[j][1]:
            t = CSF[j][1] + CSF[j][0]
        elif t % CSF[j][2] == 0:
            t += CSF[j][0]
        else:
            t = ((t // CSF[j][2]) + 1) * CSF[j][2] + CSF[j][0]
    ans[i] = t



for i in ans:
    print(i)

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void) {
	int n, i, a[300003];
	ll ans = 0;

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

	sort(a, a + n * 3, greater<int>());

	for (i = 0; i < n; i++) {
		ans += a[i * 2 + 1];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin>>n;
  vector<int> A(n);
  vector<int> B(n);
  vector<int> C(n-1);
  rep(i,n){
    cin>>A[i];
  }
  rep(i,n){
    cin>>B[i];
  }
  for(int i=0;i<n-1;i++){
    cin>>C[i];
  }
  int ans=0;
  for(int t:A){
    ans+=B[t-1];
  }
  for(int i=0;i<n;i++){
    if(A[i+1]-A[i]==1){
      ans+=C[A[i]-1];
    }
  }
  cout<<ans<<endl; 
}

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;
#define INF 1<<30
#define LINF 1LL<<60

/*
 http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_4_A&lang=jp
 
 ???????????????????????????
 ??????????¢????, ??¢, ??£, ?????????????????? N ???, ????¨? 4N ????????????????????\??£???????????????????????????????¢??????\??£??????????????????????????????ai, bi, ci, di ?????§??????D ??????, ????¢?????????????, ????¨?4 ?????????????????????????????¨?????£?????????, ?????????????¨????????????????V ?????????????????¨?????£???????????????????????????????????????????????????????????????????????§????????????? ?????????, ????????????????????????????????\??????????????¨????????????
 
 Constraints
 1 ??? N ??? 1000
 1 ??? ai, bi, ci, di ??? 10^16
 1 ??? V ??? 10^16
 ??\?????????????????´??°??§???????????????
 Output
 ?????????????????°??? 1 ???????????????????????????
 */
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll N,V;cin >> N >> V;
    vector<ll> a(N),b(N),c(N),d(N);
    for(int i = 0; i < N;i++) cin >> a[i];
    for(int i = 0; i < N;i++) cin >> b[i];
    for(int i = 0; i < N;i++) cin >> c[i];
    for(int i = 0; i < N;i++) cin >> d[i];

    /*
     a + b + c + d = V : O(N^4)
     => a + b = V - c - d : O(N^2) + O(N^2)
     */
    map<ll,ll> m;
    for(int i = 0; i < N;i++){
        for(int j = 0; j < N;j++){
            m[a[i]+b[j]]++;
        }
    }
    
    ll ans = 0;
    for(int i = 0; i < N;i++){
        for(int j = 0; j < N;j++){
            ans += m[V - c[i] - d[j]];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 128152
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int bpm(int x, unsigned int y) {
  if (x == 0) return 0;
  if (y == 0) return 1;
  int ans   = 1;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  x %= MOD;
  for (unsigned int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) ans = ans * x % MOD;
    x = x * x % MOD;
  }
  return ans;
}

class CCitySavers {
public:
  static void solve(std::istream &cin, std::ostream &cout) {
    int N;
    cin >> N;
    vector<int> A(N + 2);
    vector<int> B(N);
    rep(i, N + 1) cin >> A[i];
    rep(i, N) cin >> B[i];
    int ans = 0;
    rep(i, N) {
      if (B[i] >= A[i] + A[i + 1]) {
        ans += A[i] + A[i + 1];
        A[i + 1] = 0;
      } else if (B[i] >= A[i]) {
        ans += A[i] + (B[i] - A[i]);
        A[i + 1] -= (B[i] - A[i]);
      } else {
        ans += B[i];
      }
    }
    cout << ans << endl;
  }
};


signed main() {
  CCitySavers solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 1792
from functools import reduce
from operator import mul

N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))


def kaidan(n):
    return reduce(mul, range(1,n+1))

def migi(i,A):
    return len( list(filter(lambda x: x < A[i], A[i+1:])) )

def num(A):
    s = 0
    for i in range(N-1):
        s += kaidan(N-1-i) * migi(i,A)
    return s

print(abs(num(P) - num(Q)))

Measured memory_bytes: 3572
// at_abc143c.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
using namespace std;
int main()
{
    int strlen;string str;cin >> strlen >> str;
    char cur = str[0];
    int out = 1;
    for(int i=0;i<strlen;i++){
        if (str[i] != cur) {
            cur = str[i];
            out++;
        }
    }
    cout << out << "\n";
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file


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

#define MAX_SIZE 3

int compare_int(const void *c1, const void *c2) {
  if(*(int *)c1 <  *(int *)c2) return -1;
  if(*(int *)c1 == *(int *)c2) return 0;
  if(*(int *)c1 >  *(int *)c2) return 1;
  return -2;
}

int main () {
  int raw_data[MAX_SIZE];

  scanf("%d %d %d", &raw_data[0], &raw_data[1], &raw_data[2]);
  qsort(raw_data, MAX_SIZE, sizeof(raw_data[0]), compare_int);
  printf("%d %d %d\n", raw_data[0], raw_data[1], raw_data[2]);
  

  return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#define p 80*80
using namespace std;
const int N = 82;
int a[N][N];
int b[N][N];
bool can[N][N][N*N*2];
int main()
{
    int n,m,ans = 1e9;
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++)   for(int j=1;j<=m;j++)   scanf("%d",&a[i][j]);
    for(int i=1;i<=n;i++)   for(int j=1;j<=m;j++)   scanf("%d",&b[i][j]);
    can[1][1][p+(a[1][1]-b[1][1])] = can[1][1][p+(b[1][1]-a[1][1])] = true;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(i==1&&j==1)  continue;
            for(int k=0;k<=p*2;k++)
            {
                int now1 = k+(a[i][j]-b[i][j]);
                int now2 = k+(b[i][j]-a[i][j]);
                if(can[i-1][j][k]||can[i][j-1][k])
                {
                    if(now1>=0&&now1<=2*p)  can[i][j][now1] = true;
                    if(now2>=0&&now2<=2*p)  can[i][j][now2] = true;
                }
            }
        }
    }
    for(int i=0;i<=p*2;i++) if(can[n][m][i])    ans = min(ans,abs(i-p));
    printf("%d\n",ans);
}


Measured memory_bytes: 87040
import           Control.Monad
import           Data.List
import           Data.Ord
import           Data.List.Split
import qualified Data.Vector.Unboxed as V

main :: IO ()
main = do
  [a, b] <- map read . words <$> getLine
  s <- getLine
  let sa = take a s
      sb = s !! a
      sc = drop (a + 1) s
  if (length s == (a + b + 1))
      && all (`elem` ['0' .. '9']) sa
      && all (`elem` ['0' .. '9']) sc
      && sb == '-'
    then putStrLn "Yes"
    else putStrLn "No"

Measured memory_bytes: 508
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
#define INF 1000000007
#define MOD 1000000007

#define ARRAY_MAX 1005


int main(){

    ll n,h,w;
    cin >> n >> h >> w;
    vector<ll> a(n),b(n);
    REP(i,n){
        cin >> a[i] >> b[i];
    }
    ll ans = 0;
    REP(i,n){
        if(a[i] >= h && b[i] >= w){
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pie 3.1415926536
#define pb push_back
#define N 1000000007
#define M 998244353
#define ff first
#define ss second
#define INF 1ll<<63 - 1
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define nrep(i,a,b) for(int i=a;i>=b;i--)
#define pl pair<ll,ll>
#define pi pair<int,int>
#define pll pair<pair<ll,ll>, ll> 
#define pii pair< int, pair<int,int> >
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll t,x,b,y,q,z,k,n,m;
    cin>>n>>m;
    cout<<(n*m)/__gcd(n,m);
}

Measured memory_bytes: 3640
#include <iostream>
#include <iterator>
#include <vector>

#define MAX_N 100000
#define MAX_M 100

using namespace std;

int N, M;
int A[MAX_N];

vector<int> solve()
{
    vector<int> B;

    vector<int> O; // 奇数のインデックス
    for ( int i = 0; i < M; i++ )
        if ( A[i] % 2 ) O.push_back( i );

    switch ( O.size() )
    {
    case 2:
        swap( A[O[1]], A[M - 1] );
    case 1:
        swap( A[O[0]], A[0] );
        break;
    case 0:
        break;
    default:
        return B;
    }

    if ( A[0] > 1 ) B.push_back( A[0] - 1 );

    for ( int i = 1; i < M - 1; i++ ) B.push_back( A[i] );

    B.push_back( M == 1 ? 1 : A[M - 1] + 1 );

    return B;
}

int main( int argc, char **argv )
{
    cin >> N >> M;

    for ( int i = 0; i < M; i++ ) cin >> A[i];

    auto B = solve();

    if ( B.size() == 0 )
        cout << "Impossible" << endl;
    else
    {
        copy( A, A + M, ostream_iterator<int>( cout, " " ) );
        cout << endl;

        cout << B.size() << endl;

        copy( B.begin(), B.end(), ostream_iterator<int>( cout, " " ) );
        cout << endl;
    }

    return 0;
}


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

int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	//freopen("input.txt","r",stdin);
    int n;
    cin>>n;
    cout<<n+(n*n)+(n*n*n)<<endl;
	return 0;
}


Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
a, b = map(int, raw_input().split())
s = raw_input()
ok = False
if len(s) == (a+b+1):
  n = s.count('-')
  if n == 1:
    x,y = map(str, s.split('-'))
    if len(x) == a:
      if len(y) == b:
        ok = True

if ok:
  print 'Yes'
else:
  print 'No'

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

using namespace std;

typedef pair<int,string> P;
vector<string> IN;
vector<P> V;
char c;

void make(string s){
  s += " ";
  string in = "";
  for(int i = 0; i < s.length(); i++){
    if(s[i] == ' '){
      IN.push_back(in);
      // cout << in << endl;
      in = "";
      continue;
    }
    in += s[i];
  }
}

string gets(char key){
  
  for(int i = 0; i < IN.size(); i++)
    if(IN[i][0] == key) return IN[i];

  return "Cannot find";
}
void solve(){

  IN.push_back("{{{}}}");
  sort(IN.begin(),IN.end());

  // string a = "";
  //a += c;
  // string s = *lower_bound(IN.begin(),IN.end(),a);
  string s = gets(c);
  if(s == "Cannot find"){
    cout << "NA" << endl;
    return;
  }
  while(1){
    P p;
    p.first = -1*(upper_bound(IN.begin(),IN.end(),s)-lower_bound(IN.begin(),IN.end(),s));
    p.second = s;
    V.push_back(p);
    s = *upper_bound(IN.begin(),IN.end(),s);
    if(s[0] != c) break;
  }

  sort(V.begin(),V.end());
  
  for(int i = 0; i < min((int)V.size(),5); i++){
    if(i) cout << " ";
    cout << V[i].second;
  }
  cout << endl;
}


void init(){

  IN.clear();
  V.clear();
}

int main(){
  int n;
  while(cin >> n && n){
    init();
    string in;
    getline(cin,in);
    for(int i = 0; i < n; i++){
      getline(cin,in);
      make(in);
    }
    cin >> c;
    solve();
  }
  return 0;
}

Measured memory_bytes: 1268
#-------------
N = int(input())
A = list(map(int, input().split()))
#-------------
 
kabu = 0
money = 1000
for i in range(N-1):
  if A[i] < A[i+1]:
    mod,money = divmod(money , A[i])
    kabu += mod
  else:
      money = money + A[i] * kabu
      kabu = 0

money = money + A[N-1]*kabu
print(money)

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

using namespace std;

const int mod = 1e9 + 7, P = 1e9 + 7;
int n, a[323456];
int x[10], y[10], p[10];

 
int main() {

	cin >> n;
	string s;
	cin >> s;
	if(n & 1) return cout << "No", 0;

	string t = s.substr(0, n / 2);
	t = t + t;
	if(t == s) cout << "Yes";
	else cout << "No";
}


Measured memory_bytes: 256
/*AOJ 0018*/

#include<iostream>
using namespace std;

#define N 5

void Swap(int *a,int *b){
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

void BabbleSort(int *a){
	for(int i=0;i<N;i++){
		for(int j=N-1;j>i;j--){
			if(a[j] >= a[j-1]){
				Swap(&a[j],&a[j-1]);
			}
		}
	}
}


int main(){

	int a[N];

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

	BabbleSort(a);

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

Measured memory_bytes: 0
N = int(input())
A = list(map(int,input().split()))

ans = 0
count = 0
for i in range(N):
    if A[i] < 0:
        A[i] = -A[i]
        count += 1

if count%2==0:
    print(sum(A))
else :
    print(sum(A)-2*min(A))

Measured memory_bytes: 14412
#include <iostream>
#include<bits/stdc++.h>
#include<cmath>
#include <algorithm> 
#include <unordered_map>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long n;
	cin >> n;
	vector<long long>ans(10000001);
	for (int i = 0; i < n; i++) {
		if (i == 0) {
			ans[0] = 7;
		}
		else {
			ans[i] = (ans[i - 1] * 10 + 7) % n;
		}
	}
		for (int i = 0; i < n; i++) {
			if (ans[i] % n == 0) {
				cout << i + 1;
				return 0;
			}
		}
		cout << -1;
		return 0;
	
}

Measured memory_bytes: 81312
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"

using namespace std;

constexpr long long int MOD = 1000000007;
//const int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;

constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N;
	vector<pair<long long int, long long int>>a(N);
	for (auto &i : a)cin >> i.first >> i.second;
	a.push_back({ 0,0 });
	a.push_back({ MOD*MOD, -MOD * MOD });
	sort(a.begin(), a.end());
	for (int i = 1; i <= N; i++)a[i].second += a[i - 1].second;

	long long int ans = 0;
	long long int add = a[1].first;
	for (int i = 1; i <= N; i++) {
		//cout << i << " " << a[i].second - a[i].first + add << endl;
		ans = max(ans, a[i].second - a[i].first + add);
		add = max(add, a[i + 1].first - a[i].second);
	}
	cout << ans << endl;
}


Measured memory_bytes: 18396
//#define LOCAL

#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>

#define rep(i,n) for(int i=0; i<n; i++)

using namespace std;



int main()
{
#ifdef LOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    string red, green, down, myright;
    int red_pos, green_pos, down_pos;
    bool now_red;

    while (true) {
        cin >> red;
        if (red == "-") break;

        cin >> green;
        cin >> down;

        red_pos = 0;
        green_pos = 0;
        down_pos = 0;
        now_red = false;
        myright = "";

        while (!(red_pos == red.length() && green_pos == green.length())) {
            if (now_red) {
                if (down[down_pos] == red[red_pos]) {
                    red_pos++;
                    down_pos++;
                } else {
                    myright.push_back(red[red_pos]);
                    red_pos++;
                    now_red = false;
                }
            } else {
                if (down[down_pos] == green[green_pos]) {
                    now_red = true;
                    green_pos++;
                    down_pos++;
                } else {
                    myright.push_back(green[green_pos]);
                    green_pos++;
                }
            }
        }

        cout << myright << endl;
    }
}

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

int main() {

  string N;
  cin >> N;

  int sum = 0;
  for (int i = 0; i < N.size(); i++) {
  sum += N.at(i)-'0';
  }

  int X;
  X = stoi(N);

  string ans;
  if (X % sum == 0) ans = "Yes";
   else ans = "No";

  cout << ans << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
using namespace std;

int main()
{
  string a,b;
  cin >> a >> b;
  string ans;
  if (a == "H") {
    if (b == "H") ans = "H";
    else ans = "D";
  } else {
    if (b == "H") ans = "D";
    else ans = "H";
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, T t){return v2<T>(r, vector<T>(c, t));}

int n;

const int mx = 1e7+5;
int spf[mx];
void seive(){
    spf[1] = 1;
    for(int i = 2; i <= n; i++) spf[i] = i;
    for(int i = 4; i <= n; i+=2) spf[i] = 2;
    for(int i = 3; i*i <= n; i++){
        if(spf[i]==i){
            for(int j = i*i; j <= n; j+=i){
                if(spf[j]==j){
                    spf[j] = i;
                }
            }
        }
    }
}

ll factor(int a){
    // cout << a << '\n';
    unordered_map<int, int> pf;
    while(a != 1){
        pf[spf[a]]++;
        a /= spf[a];
    }
    ll ans = 1;
    for(auto& p : pf){
        ans *= p.second+1;
    }
    return ans;
}

void solve(){
    cin >> n;
    seive();
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        ans += i*factor(i);
    }
    // vector<int> dp(n+1);
    // dp[1] = 1;
    // ll ans = 1;
    // for(int i = 2; i <= n; i++){
    //     if(spf[i] == 1) dp[i] = 2;
    //     else dp[i] = 1+dp[i/spf[i]];
    //     ans += (ll)i*dp[i];
    // }
    cout << ans << '\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 42700
#include <iostream>
#define N (int) (1e5 + 10)
#define MOD (int) (1e9 + 7)

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

#if DEBUG_ON
    freopen("input", "r", stdin);
#endif

    int n, arr[N] = { 0 }, colors[3] = { 0 };
    std::cin >> n;
    for (int i = 0; i < n; ++i) {
        int a;
        std::cin >> a;
        bool added = false;
        for (int j = 0; j < 3; ++j) {
            if (a == colors[j]) {
                ++arr[i];
                if (!added) {
                    ++colors[j];
                    added = true;
                }
            }
        }
    }
    long long res = 1;
    for (int i = 0; i < n; ++i) {
        res *= arr[i];
        res %= MOD;
    }
    std::cout << res << '\n';
    return 0;
}

Measured memory_bytes: 640
n,m = map(int,input().split())
d = {}
for _ in range(m):
  s,c = map(int,input().split())
  if n != 1 and s ==1 and c == 0:
    print(-1)
    exit()
  if s in d:
    if d[s] == c:
      continue
    else:
      print(-1)
      exit()
  else:
    d[s] = c

ans = ''
flag = False
if n == 1:
  flag = True
for i in range(n):
  if i+1 in d:
    if d[i+1] != 0:
      flag = True
    ans += str(d[i+1])
  else:
    if flag:
      ans += '0'
    else:
      ans += '1'
      flag = True
print(ans)






Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#include <cmath>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
using ull =unsigned long long;
const ll INF =1001001001;

//10億7。　　　100000007

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}


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

 ll N;cin>>N;
  cout<<(1+N)*N/2<<endl;

  
  
  
}



Measured memory_bytes: 256
import numpy as np

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

A = np.zeros(N, dtype=int)

for _ in range(K):
    input()
    for i in input().split():
        A[int(i) - 1] += 1

ans = 0
for i in A:
    if i == 0:
        ans += 1
print(ans)


Measured memory_bytes: 27140
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e8;
int main(){
	int n;
	cin>>n;
	vi in(n);
	rep(i,n)cin>>in[i];
	int sum=0,q;
	rep(i,n)sum+=in[i];
	cin>>q;
	while(q--){
		int a,b;
		cin>>a>>b;
		cout<<sum+b-in[a-1]<<endl;
	}
}





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

int main(){
  
  int n, m, x;
  int al = 0, ar = 0;
  bool a[101] = {};
  
  cin >> n >> m >> x;
  for(int i = 0;i < m;i++){
    int x;
    cin >> x;
    a[x] = true;
  }
  
  for(int i = x;i <= n;i++) if(a[i]) ar++;
  for(int i = x;i >= 0;i--) if(a[i]) al++;
  
  cout << min(al, ar) << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<int> vec;

void solve(){
	string s; cin >> s;
	vector<int> a(4);
	rep(i, 4)a[i] = s[i] - '0';
	rep(i, 8) {
		int sum = a[0];
		rep(j, 3) {
			if (i&(1 << j)) {
				sum += a[j+1];
			}
			else {
				sum -= a[j+1];
			}
		}
		if (sum == 7) {
			cout << a[0];
			rep(j, 3) {
				if (i&(1 << j))cout << "+";
				else cout << "-";
				cout << a[j+1];
			}
			cout << "=7" << endl;
			return;
		}
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(6);
	//init();
	solve();
	stop
		return 0;
}


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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
typedef long long lint;

int N, A[100005];
vector< vector< int > > adj;

void yes() { puts("YES"); exit(0); }
void no() { puts("NO"); exit(0); }

lint rec(int v, int p) {
	if (adj[v].size() == 1) return A[v];
	
	vector< lint > deg;
	for (int u : adj[v]) if (u != p) deg.push_back(rec(u, v));
	lint sum = accumulate(deg.begin(), deg.end(), lint());
	
	if (p == -1 && 2 * A[v] != sum) no();
	if (2 * A[v] - sum < 0) no();
	deg.push_back(2 * A[v] - sum);
	for (lint x : deg) if (A[v] < x) no();
	return deg.back();
}

int main() {
	cin >> N;
	for_(i,0,N) cin >> A[i];
	
	adj.assign(N, vector< int >());
	for_(i,0,N-1) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	
	for_(v,0,N) {
		if (adj[v].size() > 1) {
			rec(v, -1);
			yes();
		}
	}
	
	if (A[0] == A[1]) yes();
	no();
}

Measured memory_bytes: 14080
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
def main():
  n,m,x = map(int,input().split())
  a = list(map(int,input().split()))
  cost = 0
  for i in range(x+1,n):
    if a.count(i):
      cost += 1
  mi_ = cost
  cost = 0
  for i in range(1,x):
    if a.count(i):
      cost += 1
  mi_ = min(mi_, cost)
  
  print(mi_)
if __name__ == '__main__':
  main()

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

using namespace std;
typedef pair<int, int> pii;

int n, q;

struct node {
    int time, corr, kind;
    bool operator<(const node &p) const {
        return time < p.time;
    }
};

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> q;
    vector<node> v;
    for (int i = 0; i < n; i++) {
        int s, t, x;
        cin >> s >> t >> x;
        v.push_back({ s - x, x, 1 });
        v.push_back({ t - x, x, 0 });
    }
    sort(v.rbegin(), v.rend());
    multiset<int> sp;
    for (int i = 0; i < q; i++) {
        int d;
        cin >> d;
        while (!v.empty() && v.back().time <= d) {
            if (v.back().kind) sp.insert(v.back().corr);
            else sp.erase(sp.find(v.back().corr));
            v.pop_back();
        }
        cout << (sp.empty() ? -1 : *sp.begin()) << '\n';
    }
}

Measured memory_bytes: 16108
import math

n, d = map(int, input().split())
l = [[int(x) for x in input().split()] for y in range(n)]

cnt = 0

for i in range(n):
    for j in range(n):
        if i ==j:
            continue
        dis_nijo = 0
        for k in range(d):
            dis_nijo += (l[i][k] - l[j][k]) **2
            dis = math.sqrt(dis_nijo)
        if dis ==int(dis):
            cnt += 1

print(cnt//2)

Measured memory_bytes: 3064