akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = list(map(int,input().split()))
d = {}
s = sum(a)
for i in a:
    if i not in d:
        d[i] = 1
    else:
        d[i] += 1
q = int(input())
for i in range(q):
    b,c = map(int,input().split())
    if b not in d:
        print(s)
        continue
    s += (c-b)*d[b]
    if c not in d:
        d[c] = d[b]
    else:
        d[c] += d[b]
    d[b] = 0
    print(s)



Measured memory_bytes: 85488
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

ll knapsack(const vector<pair<ll, ll>>& items, ll max_w) {
	vector<ll> res(max_w+1, 0);
	for (auto pr : items) {
		ll val = pr.first;
		ll wei = pr.second;
		for (int j = 0; j + wei <= max_w; ++j) {
			res[j+wei] = max(res[j+wei], res[j]+val);
		}
	}
	ll ans = 0;
	for (int i = 1; i <= max_w; ++i) ans = max(ans, res[i]);
	return ans;
}

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

	ll n;
	cin >> n;
	vector<ll> vals1(3);
	vector<ll> vals2(3);
	for (int i = 0; i < 3; ++i) cin >> vals1[i];
	for (int i = 0; i < 3; ++i) cin >> vals2[i];

	// Really it's two instances of knapsack
	// Item value is its buy price - its sell price
	// Item weight is its buy price

	vector<pair<ll, ll>> items1(3);
	vector<pair<ll, ll>> items2(3);
	for (int i = 0; i < 3; ++i) {
		items1[i] = {vals2[i] - vals1[i], vals1[i]};
		items2[i] = {vals1[i] - vals2[i], vals2[i]};
	}

	ll cur = n;
	cur += knapsack(items1, cur);
	cur += knapsack(items2, cur);
	cout << cur << '\n';
}


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

const int N=2050;
char s[N][N];
int dp[N][N][5],ans;

int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<=n-1;++i)	cin>>s[i];
	
	for(int i=0;i<=n-1;++i)
		for(int j=0;j<=m-1;++j) {
            if (s[i][j] == '.') {
            	dp[i][j][1] = dp[i][j][2] = 1;
            	if (j > 0 && dp[i][j - 1][1] > 0) dp[i][j][1] = dp[i][j - 1][1] + 1;
            	if (i > 0 && dp[i - 1][j][2] > 0) dp[i][j][2] = dp[i - 1][j][2] + 1;
            }
        }
        
    for (int i = n-1; i >=0; i--) 
        for (int j = m-1; j >=0; j--) {
            if (s[i][j] == '.') {
                dp[i][j][3] = dp[i][j][4] = 1;
                if (j < m-1  && dp[i][j + 1][3] > 0) dp[i][j][3] = dp[i][j + 1][3] + 1;
                if (i < n-1  && dp[i + 1][j][4] > 0) dp[i][j][4] = dp[i + 1][j][4] + 1;
            }
    	}
        
    for (int i = 0; i <= n-1; i++) 
    	for (int j = 0; j <= m-1; j++) {
           if (s[i][j] == '#') continue;
           int temp = 1;
           for (int cnt = 1; cnt <= 4; cnt++) temp += dp[i][j][cnt];
           ans = max(ans, temp - 4);
    }
    
    cout<<ans;	
}

Measured memory_bytes: 86272
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using System;

public class Hello
{
    public static void Main()
    {
        var d = new Dictionary<int, int>();
        var n = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var a = int.Parse(line[0]);
            var b = int.Parse(line[1]);
            if (d.ContainsKey(a)) d[a]++;
            else d[a] = 1;
            if (d.ContainsKey(b+1)) d[b+1]--;
            else d[b+1] = -1;
        }
        Console.WriteLine(getAns(d));
    }
    static int getAns (Dictionary<int,int> d)
    {
        var ans = 0;
        var s = 0;
        foreach (var x in d.OrderBy(y =>y.Key))
        {
            s += x.Value;
            ans = Max(ans, s);
        }
        return ans;
    }
}



Measured memory_bytes: 37116
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=1e5+10;
ll dp[maxn],sum[maxn];
int n,K;
int a[110];
inline void add(ll &a,ll b)
{
	if(b>=MOD)b-=MOD;
	a+=b;
	if(a>=MOD)a-=MOD;
}
int main()
{
	scanf("%d%d",&n,&K);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	dp[0]=1;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<=K;j++)
		{
			sum[j]=dp[j];
			if(j)add(sum[j],sum[j-1]);
		}
		for(int j=0;j<=K;j++)
		{
			dp[j]=sum[j];
			if(j-a[i]-1>=0)add(dp[j],MOD-sum[j-a[i]-1]);
		}
	}
	printf("%lld\n",dp[K]);
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<stack>
#include<sstream>
#include<string>
#include<ctype.h>
using namespace std;

stack<int> s;

int main(){

    while(!s.empty()){
      s.pop();
    }
    string tmp="";
    while(getline(cin,tmp,' ')){
      stringstream ss;
      int a=0;
      if(isdigit(tmp[0])){
        ss << tmp;
        ss >> a;
        s.push(a);
      }else{
        string sign;
        sign = tmp;
        int left,right;
        right = s.top(); s.pop();
        left = s.top(); s.pop();
        switch (sign[0]) {
          case '+':
            s.push(left+right);
            break;
          case '-':
            s.push(left-right);
            break;
          case '*':
            s.push(left*right);
            break;
          default:
            break;
        }
      }
    }

    cout << s.top() << endl;

    return 0;
}

Measured memory_bytes: 3192
#include <stdio.h>

long long int gcd(long long int x, long long int y) {
   return y ? gcd(y, x % y) : x;
}

int main()
{
   long long int x, y;

   scanf("%ld %ld", &x, &y);

   printf("%lld\n", gcd(x, y));


   return 0;
}

Measured memory_bytes: 1792
import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner sc  = new Scanner (System.in);
        String s = sc.nextLine();
        boolean res = true;
        int i = 0;
        if(s.charAt(0)==s.charAt(1) && s.charAt(2)==s.charAt(0) && s.charAt(2)==s.charAt(3)){
            res = false;
        }
        else{
        if(s.charAt(i)==s.charAt(i+1)||s.charAt(i)==s.charAt(i+2)||s.charAt(i)==s.charAt(i+3)){
            if(s.charAt(i+1)==s.charAt(i+2)||s.charAt(i+1)==s.charAt(i+3)){
                
            }
            else{
                if(s.charAt(i+2)==s.charAt(i+3)){

                }
                else    
                    res = false;
            }

                
                
        }
        else{
            res = false;
        }
    }
           
        if(res == true)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}

Measured memory_bytes: 35656
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define all(x) (x.begin()),(x.end())
#define sz(x)  ((ll)x.size())
#define FAST_IO ios_base :: sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
using namespace std;

#ifdef LOCAL
#include "uj.h"
#endif
void tokenize(string str,const char delim,vector<string> & res){
	stringstream p(str);
	string token;
	while(getline(p,token,delim)){
		res.push_back(token);
	}
	return;
}
int N,W;
vector<pair<int,int>> v;

int pp,qq;
void test_case(){
	cin>>N>>W;
	v.push_back({0,0});
	for(int i = 0;i<N;++i){
		cin>>pp>>qq;
		v.push_back({pp,qq});
	}
	
	vector<vector<ll>> dp(W+1,vector<ll>(N+1,0));
	dp[0][0] = 0;
	// dp[i][k] = max value of ith weight by using first k elements...
	ll ans = 0;
	for(int k = 1;k<=N;++k){
		for(int x = 0;x<=W;++x){
			if(x-v[k].first>=0) dp[x][k] = max(dp[x][k],dp[x-v[k].first][k-1] + v[k].second);
			dp[x][k] = max(dp[x][k],dp[x][k-1]);
			ans = max(ans,dp[x][k]);
		}
	}
	cout<<ans;
	
}
			 
		
		



int main(){
	FAST_IO;
	int tt;
	//cin>>tt;
	tt = 1;
	while(tt--){
		test_case();
	}
#ifndef ONLINE_JUDGE
 	cerr << "Running Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


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

int main(){
    int s;  cin >> s;
    vector<int> f(1000000,0);
    f[s] = 1;
    bool flag = false;
    int ans = 1;
    while(!flag){
        if(s%2==0) s = s/2;
        else s = 3*s + 1;
        ans++;
        if(f[s] == 1){
            flag = true;
        }else{
            f[s] = 1;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4096
import copy
class Dice2:
    def __init__(self, nums):
        self.nums = nums
        self.dic = \
                {(1,2):3, (1,3):5, (1,4):2, (1,5):4, (2,3):1, (2,4):6, (2,6):3, (3,5):1, (3,6):5, (4,5):6, (4,6):2, (5,6):4}
    def output_right(self, x):
        x[0] = self.nums.index(x[0]) + 1
        x[1] = self.nums.index(x[1]) + 1
        nums = self.nums
        y = copy.deepcopy(x)
        x.sort()
        key = tuple(x)
        if tuple(y)==key:
            return nums[self.dic[key]-1]
        else:
            return nums[6-self.dic[key]]

dice = Dice2(list(map(int, input().split())))
q = int(input())
for i in range(q):
    print(dice.output_right(list(map(int, input().split()))))

Measured memory_bytes: 8168
#include <bits/stdc++.h>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define all(v)   v.begin(), v.end()
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define START cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define isOdd(n)    (n&1)
#define LLMAX LLONG_MAX
#define LLMIN LLONG_MIN
#define IMN INT_MIN
#define IMX INT_MAX
#define pow(n, m) power((ll)n, (ll)m)
#define numOfDigits(n)  ((n)? (ll)(log10(n))+1 : 1)
#define mem(x, val)    memset(x, val, sizeof(x)) //be careful
#define sz(x)          (int) x.size()
#define MOD 1000000007
#define EPS 1e-7
#define lol    {cout<<i<<" "<<-j<<endl; goto here;}
#define lol2    {cout<<i<<" "<<j<<endl; goto here;}

typedef long long ll;
typedef long double ld;
typedef double dd;
typedef pair<int, int> pii;
typedef vector<int> vi;

bool compare(const pii &a, const pii &b){
    return a.first > b.first;
}
int main()
{
    START
    //freopen("test cases\\in.txt", "r", stdin) ;
    int n, m; cin>>n>>m;
    int arr[n+1];
    bool good[n+1];
    mem(good, 1);
    for(int i  = 1; i <= n; i++) cin>>arr[i];
    while(m--){
        int u, v; cin>>u>>v;
        if(arr[u]<=arr[v]) good[u] = 0;
        if(arr[v]<=arr[u]) good[v] = 0;
    }
    int cnt = 0;
    for(int i = 1; i<=n; i++)
        if(good[i])cnt++;

    cout<<cnt;
	return 0;
}


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

int main(void){
    int n;
    cin>>n;
    int ans=n%1000;
    if(ans!=0)ans=1000-ans;
    cout<<ans<<endl;
}

Measured memory_bytes: 3488
#include <bits/stdc++.h>
using namespace std;
string s;
int main(){
    cin>>s;
    if(s[0]!='A'){
        printf("WA\n"); return 0;
    }
    int n=s.size();
    int cnt=0;int idx=-1;
    for(int i=2;i<n-1;i++){
        if(s[i]=='C'){
            cnt++;idx=i;
        }
    }
    if(cnt!=1){
        printf("WA\n"); return 0;
    }
    for(int i=1;i<n;i++){
        if(i!=idx){
            if(!(s[i]>='a' && s[i]<='z')){
                printf("WA\n"); return 0;
            }
        }
    }
    printf("AC\n");
    return 0;
}


Measured memory_bytes: 256
# import numpy as np
# import math
import sys
# input = sys.stdin.readline().rstrip


def main():
    N = int(input())

    s = []
    t = []

    for i in range(N):
        temp = list(map(str,input().split()))
        s.append(temp[0])
        t.append(int(temp[1]))

    X = input()

    isSlept = False
    res = 0

    for i in range(N):
        if isSlept:
            res += t[i]
        if s[i] == X:
            isSlept = True

    print(res)



main()


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

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

using namespace std;

int main() {
    string s;
    cin >> s;
    int win;
    rep(i,s.length()){
        if(s[i] == 'o'){
            win++;
        }
    }
    if(win + (15 - s.length()) >= 8){
        cout << "YES" << endl;
    }else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
# coding: utf-8
H, W = map(int, input().split())
pic = [['#' for _ in range(W + 2)] for _ in range(H + 2)]
for i in range(H):
    for j, k in enumerate(list(input())):
        pic[i + 1][j + 1] = k
for i in pic:
    print(''.join(i))

Measured memory_bytes: 3060
N = int(input())
h = list(map(int, input().split()))

#N = 4
#h = [10, 30, 40, 20]


score = [0 for i in range(N)]

for i in range(N):
    if i == 0:
        score[i] = 0
    elif i == 1:
        score[i] = abs(h[i] - h[i-1])
    else:
        s1 = score[i-2] + abs(h[i] - h[i-2])
        s2 = score[i-1] + abs(h[i] - h[i-1])
        score[i] = min([s1, s2])
print(score[-1])

Measured memory_bytes: 13928
//Vol0 0023
#include<stdio.h>
#include<math.h>
int main()
{
	int n,r=0;
	double xa,ya,ra,xb,yb,rb,ht;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lf%lf%lf%lf%lf%lf",&xa,&ya,&ra,&xb,&yb,&rb);
		ht=sqrt(((xa-xb)*(xa-xb))+((ya-yb)*(ya-yb)));
		if(ra+rb<ht){
			r=0;
		}else if(ht+rb<ra){
			r=2;
		}else if(ht+ra<rb){
			r=-2;
		}else{
			r=1;
		}
		printf("%d\n",r);
	}
	return 0;
}

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

int main(){
  char a;
  cin >> a;

  if (a == 'a' || a == 'i' || a == 'u' || a=='e' || a== 'o'){
    cout << "vowel" <<endl;
  }
  else{
    cout << "consonant" <<endl;
  }
}
  


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

int main() {
  int n, answer=0;
  int c[500],s[500],f[500];
  cin >> n;
  for (int i = 0; i <= n-2; i++) {
    cin >> c[i] >> s[i] >> f[i];
  }
  for (int i = 0; i <= n-2; i++) {
    answer = 0;
    for (int j = i; j <= n-2; j++) {
      if (answer > s[j])
	answer = ceil((answer - s[j])*1.0/f[j]) * f[j] + c[j] + s[j];
      else answer = s[j] + c[j];
    }
    cout << answer << endl;
  }
  cout << "0" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a[100];
  int i,j,t,c,n;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  for(i=n-1;i>0;i--)
    printf("%d ",a[i]);
  printf("%d\n",a[0]);
  return 0;
}

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

using namespace std;

int main()
{
  int N;
  vector<int> vec_a;
  
  cin >> N;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    vec_a.push_back(a);
  }

  sort(vec_a.begin(), vec_a.end());

  bool isPigeon = false;
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      int diff = vec_a.at(j) - vec_a.at(i);
      if (!((vec_a.at(j) - vec_a.at(i)) % (N - 1))) {
        cout << vec_a.at(i) << " " << vec_a.at(j) << endl;
        isPigeon = true;
        break;
      }
    }
    if (isPigeon) {
      break;
    }
  }
}
 



Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////

#define N 305
ll n;
ll a[3];
double dp[N][N][N];


int main(){
    cin>>n;
    rep(i,0,n-1){ll b;cin>>b;b--;if(b>=0)a[b]++;}
    rep(x,0,n){
        rep(y,0,x){
            rep(z,0,y){
                if(x==0&&y==0&&z==0)continue;
                ll i=x-y,j=y-z,k=z;
                double sum=n;
                if(i-1>=0)sum+=i*dp[i-1][j][k];
                if(j-1>=0)sum+=j*dp[i+1][j-1][k];
                if(k-1>=0)sum+=k*dp[i][j+1][k-1];
                dp[i][j][k]=sum/(i+j+k);
            }
        }
    }
    /*rep(i,0,n){
        rep(j,0,n){
            rep(k,0,n){
                cout<<dp[i][j][k]<<" ";
            }cout<<endl;
        }cout<<endl;
    }*/
    printf("%10.10lf\n",dp[a[0]][a[1]][a[2]]);
    
    return 0;
}






Measured memory_bytes: 219392
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_B&lang=jp
sentinel = pow(10,9) + 1
def merge(target_list, left_index, mid_index,right_index):
    global count
    l = target_list[left_index:mid_index] + [sentinel]
    r = target_list[mid_index:right_index] + [sentinel]
    l_target = 0
    r_target = 0
    #print(left_index, right_index, mid_index, l,r)
    for k in range(left_index, right_index):
        count += 1
        if l[l_target] < r[r_target]:
            target_list[k] = l[l_target]
            l_target += 1
        else:
            target_list[k] = r[r_target]
            r_target += 1

    #print(target_list)
            
def merge_sort(target_list, left_index, right_index):
    count = 0
    if left_index + 1 < right_index:
        mid_index = (left_index + right_index) // 2

        merge_sort(target_list, left_index, mid_index)
        merge_sort(target_list, mid_index, right_index)
        merge(target_list, left_index, mid_index,right_index)
        
if __name__ == "__main__":
    l = input()
    target_list = [int(a) for a in input().split()]
    global cnt
    count = 0
    merge_sort(target_list, 0, len(target_list))
    print(" ".join([str(n) for n in target_list]))
    print(count)

Measured memory_bytes: 69040
#include<stdio.h>
int m[]={5,1,2,4,1,3,1,0,0,2,3,2,2,4,5,1,4,0,4,3,3,5,0,5};
char s[99];
int a,b,c,d,r;
int main(){for(s[87]=1,s[78]=4,s[69]=3,s[83]=2;~scanf("%s",s);*s<60?(printf(r?"%d\n":"",r),a=c=0,b=r=1):(d=s[*s],d?d=d+c&3,a=m[4*a+d],b=m[4*b+d]:c+=*s-76?1:3,r+=a%3?b%3?(b+6-a)%6<3?2:5:b?3:4:a?6:1));}

Measured memory_bytes: 0
use std::io::*;
use std::str::FromStr;

pub 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")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}

use std::cmp::{max, min};
use std::collections::HashSet;

fn divisors(N: i64) -> HashSet<i64> {
    let mut ds = vec![];
    let mut d = 1;
    while d * d <= N {
        if N % d == 0 {
            ds.push(d);
            ds.push(N / d);
        }
        d += 1;
    }
    let uniq: HashSet<i64> = ds.into_iter().collect();
    uniq
}

fn main() {
    let n: i64 = read();
    for i in n..1000000 {
        if divisors(i).len() == 2 {
            println!("{}", i);
            break;
        }
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	string s;
	cin >> s;
	stack<int> st;
	int p = n;
	while(p != 0){
		bool flag = false;
		for(int i = m; i > 0; i--){
			if(p-i < 0) continue;
			if(s[p-i] == '0'){
				flag ^= true;
				st.push(i);
				p -= i;
				break;
			}
		}
		if(flag == false){
			cout << -1 << endl;
			return 0;
		}
	}
	while(!st.empty()){
		cout << st.top() << " ";
		st.pop();
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 868
n, m = map(int, input().split())
ac = []
for _ in range(m):
    a, _ = map(int, input().split())
    c = sum([2**(int(i)-1) for i in input().split()])
    ac.append([a, c])
dp = [float('inf')] * 2**n
dp[0] = 0
for s in range(2**n):
    for a, c in ac:
        t = s|c
        if dp[t] > dp[s] + a:
            dp[t] = dp[s] + a
ans = dp[-1]
if ans == float('inf'):
    ans = -1
print(ans)

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

using namespace std;

#define ll long long

void solve() {
	int n, a, b;
	cin >> n >> a >> b;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		int temp = 0;
		string s = to_string(i);
		for (char& c : s) {
			temp += c-'0';
		}
		if (temp >= a && temp <= b) {
			ans += i;
		}
	}
	cout << ans << "\n";
}

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

	int t = 1, i = 1;
	//cin >> t;
	while(t--) {
		//cout << "Case #" << i << ": ";
		solve();
		//i++;
	}
	return 0;
}



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

int main() {
  int s = 0,i,N,K;cin >> N >> K;
  for(i = 0; i < N; i++){
    int x;cin >> x;
    if (2 * x < K) s += 2 * x;
    else s += 2 * (K - x);
  }
  cout << s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

signed main(){
	int a,b,c;int k;cin>>a>>b>>c>>k;
	int d=1<<k;
	cout<<max({a*d+b+c,a+b*d+c,a+b+d*c})<<endl;
}

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

/* constant */

typedef long long ll;

const int MAX_N = 100000;
const int MAX_M = 100000;
const int MAX_Q = 100000;
const int MAX_BITS = 1 << 17;
const ll INF = 1LL << 62;

/* typedef */

typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
typedef vector<pil> vpil;

struct Stat {
  ll d;
  int i;
  Stat() {}
  Stat(ll _d, int _i) { d = _d, i = _i; }
  bool operator<(const Stat& s) const { return d > s.d; }
};

struct Query {
  ll fs, fg;
  int i;
  bool operator<(const Query& q) const { return fs < q.fs; }
};

struct BIT {
  int n;
  int bits[MAX_BITS];

  BIT() {}
  BIT(int _n) { init(_n); }
  
  void init(int _n) { n = _n; }

  int sum(int x) {
    int s = 0;
    while (x > 0) {
      s += bits[x];
      x -= (x & -x);
    }
    return s;
  }

  void add(int x, int v) {
    while (x <= n) {
      bits[x] += v;
      x += (x & -x);
    }
  }

  void print(int m) {
    for (int i = 1; i <= m; i++) cout << sum(i) << ' ';
    cout << endl;
  }
};

/* global variables */

int n, m, q;
vpil nbrs[MAX_N];
ll sdists[MAX_N], gdists[MAX_N];
pll sgdists[MAX_N];
Query qrs[MAX_Q];
BIT bit;
int ans[MAX_Q];

/* subroutines */

void calc_dists(int st, ll *dists) {
  for (int i = 0; i < n; i++) dists[i] = INF;
  dists[st] = 0;

  priority_queue<Stat> q;
  q.push(Stat(0, st));

  while (! q.empty()) {
    Stat u = q.top();
    q.pop();
    if (dists[u.i] != u.d) continue;

    vpil& nbru = nbrs[u.i];
    
    for (vpil::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
      int vi = vit->first;
      ll vd = u.d + vit->second;

      if (dists[vi] > vd) {
	dists[vi] = vd;
	q.push(Stat(vd, vi));
      }
    }
  }
}

/* main */

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

  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    nbrs[a].push_back(pil(b, c));
    nbrs[b].push_back(pil(a, c));
  }

  calc_dists(0, sdists);
  calc_dists(n - 1, gdists);

  for (int i = 0; i < n; i++)
    sgdists[i].first = sdists[i], sgdists[i].second = gdists[i];

  sort(sgdists, sgdists + n);

  sort(gdists, gdists + n);
  int gn = unique(gdists, gdists + n) - gdists;
  
  cin >> q;

  for (int i = 0; i < q; i++) {
    cin >> qrs[i].fs >> qrs[i].fg;
    qrs[i].i = i;
  }
  sort(qrs, qrs + q);

  bit.init(gn);
  int sgi = 0;
  
  for (int qi = 0; qi < q; qi++) {
    //printf("qrs[%d]=(%lld,%lld)\n", qrs[qi].i, qrs[qi].fs, qrs[qi].fg);
    while (sgi < n && sgdists[sgi].first <= qrs[qi].fs) {
      int gi = lower_bound(gdists, gdists + gn, sgdists[sgi].second) - gdists;
      //printf("  gi=%d\n", gi);
      bit.add(gn - gi, 1);
      sgi++;
      //bit.print(gn);
    }

    int fgi = lower_bound(gdists, gdists + gn, qrs[qi].fg) - gdists;
    //printf("  fgi=%d\n", fgi);
    ans[qrs[qi].i] = bit.sum(gn - fgi);
  }

  for (int i = 0; i < q; i++)
    cout << ans[i] << endl;
  
  return 0;
}

Measured memory_bytes: 16948
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define MOD 1e+7
#define inf 1e9
#define fi first
#define se second
using namespace std;

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

  int n, m = 0;
  cin >> n;
  reps(i,1,n+1) {
    int h;
    cin >> h;
    if(h < m){
      cout << "No" << endl;
      return 0;
    }
    m = max(m, h-1);
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh

int main(){
	dhoom;
	string s;
	cin >> s;
	int n = s.size();
	for(int i = 0 ; i < n ; i++)
		cout << "x" ;
	return 0;
}


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

vector<int> moto;

int main() {
	int n, x, dump, used = 0, answer = 0;
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		cin >> dump;
		used += dump;
		answer++;
		moto.push_back(dump);
	}
	sort(moto.begin(), moto.end());
	answer += (x - used) / moto[0];
	cout << answer << endl;
	return 0;
}

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

using namespace std;

int main(int argc, char* argv[])
{
	int A, B, C;
	cin >> A;
	cin >> B;
	cin >> C;
	bool ret = false;
	ret |= (A == 7 && B == 5 && C == 5);
	ret |= (A == 5 && B == 7 && C == 5);
	ret |= (A == 5 && B == 5 && C == 7);
	string s = ret ? "YES" : "NO";
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  static int[] A = new int[2000];
  static int n;

  public static void main(final String[] args) {
    Scanner sc = new Scanner(System.in);
    n = sc.nextInt();
    for (int i = 0; i < n; i++)
      A[i] = sc.nextInt();
    int q = sc.nextInt();
    for (int i = 0; i < q; i++) {
      int m = sc.nextInt();
      if (solve(0, m))
        System.out.println("yes");
      else
        System.out.println("no");
    }
  }

  private static boolean solve(int i, int m) {
    if (m == 0)
      return true;
    if (i >= n)
      return false;
    boolean res = solve(i + 1, m) || solve(i + 1, m - A[i]);
    return res;
  }
}


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

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

class ADividingAString {
public:
void solve(std::istream& cin, std::ostream& cout) {
    string S;
    cin >> S;

    int ans = 0;
    char t = 'A';

    for (int i = 0; i < S.length(); i++){
        ans++;
        if (t == S[i]){
            i++;
            t = 'A';
            if (i == S.length())
                ans--;
        }
        else
            t = S[i];
    }

    cout << ans << endl;

}
};

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


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int H,W;cin >> H >> W;
    map<char,int> mp;
    rep(i,H)rep(j,W){
        char c;cin >> c;
        mp[c]++;
    }
    map<int,int> cnt;
    for(auto x:mp){
        cnt[x.second%4]++;
    }
    
    int flag = 1;
    if((H%2)&&(W%2)){
        if(cnt[1]+cnt[3]!=1)flag=0; 
        if(cnt[3]==1)cnt[2]++;  
        if(cnt[2]>H/2+W/2)flag=0;
    }
    else if(!(H%2)&&!(W%2)){
        //if(cnt[0]!=H*W/4)flag=0;
        if(cnt[1]||cnt[2]||cnt[3])flag=0;
    }
    else{
        if(H%2)swap(H,W);
        if(cnt[1]||cnt[3])flag=0;
        if(cnt[3])cnt[2]++;
        if(cnt[2]>H/2)flag=0;
    }
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
const int N = 2e5 + 10;
int mod = 1e9 + 7;
typedef long long ll;
int main()  
{
 //  freopen("in.txt", "r", stdin);
   int a, b, c, d, n;
   while (cin >> a >> b >> c >> d >> n)
   {
   		int x = d;
   		x = min(a<<3, x);
   		x = min(b<<2, x);
   		x = min(c<<1, x);
   		int leftval = n&1;
   		ll ans = (ll)n/2*x;
   		if (leftval == 1)
   			ans += min(min(a<<2, b<<1), c);
   		cout<<ans<<endl;
   }
   return 0;
}

Measured memory_bytes: 256
def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))
def inNL(n):
    return [list(map(int,input().split())) for i in range(n)]
mod = pow(10,9)+7
import numpy
n = inN()

if n < 3:
    print(0)
    exit()
elif n < 6:
    print(1)
    exit()


m = n//3
n -= 5
l = [1]*n
ans = 1
for i in range(m-1):
    l = numpy.cumsum(l)
    l %= mod
    ans += l[n-1]%mod
    n -= 3

print(ans%mod)
    

Measured memory_bytes: 27260
n = gets.to_i
commands = Array.new(n){gets.split}
dict = {}

commands.each do |com|
  case com[0]
  when "insert"
    dict[com[1]] = com[1]
  when "find"
    puts (dict.has_key?(com[1]) ? "yes" : "no")
  end
end


Measured memory_bytes: 214256
#include <stdio.h>

int main (void)
{
    int N,key=0;
    scanf("%d",&N);
    for(int i=0;i<N;i++)
    {
        char c;
        scanf("%c",&c);
        if(c=='Y')
        {
            key++;
            break;
        }
    }
    if(key==1)
    {
        puts("Four");
    }else{
        puts("Three");
    }
    return 0;
}


Measured memory_bytes: 1660
from bisect import bisect_left
from collections import defaultdict
N, K, *A = map(int, open(0).read().split())
dic = defaultdict(list)
for i, a in enumerate(A):
  dic[a] += [i]
ls = []
ps = 0
m = A[0]
cycle = 0
while True:
  ls.append(ps+N*cycle+1)
  i = bisect_left(dic[m],ps+1)
  ps = dic[m][i%len(dic[m])]
  if i>=len(dic[m]):
    cycle += 1
  ps += 1
  ps %= N
  m = A[ps]
  if ps==0:
    cycle += 1
    break
k = K%cycle
j = bisect_left(ls,k*N)
if ls[j]==k*N:
  c = (ls[j]-1)%N
  print(A[c])
elif ls[j]==k*N+1:
  pass
else:
  c = (ls[j-1]-1)%N
  M = k*N-ls[j-1]
  ans = [A[c]]
  log = set(ans)
  ind = {}
  ind[A[c]] = 0
  cnt = 0
  while M:
    c += 1
    c %= N
    cnt += 1
    cnt %= N
    M -= 1
    if not A[c] in log:
      log.add(A[c])
      ind[A[c]] = cnt
      ans += [A[c]]
    else:
      log.remove(A[c])
      ans = ans[:ind[A[c]]]
      log = set(ans)
      cnt = ind[A[c]]-1
  print(*ans)


Measured memory_bytes: 106744
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    long long solve(vector<long long>& A) {
        int n = A.size();
        const long long MOD = 1e9 + 7;

        vector<long long> pow2(100, 1);
        for (int i = 1; i < pow2.size(); ++i) {
            pow2[i] = (pow2[i - 1] << 1) % MOD;
        } 

        long long mx = *max_element(A.begin(), A.end());
        int h = 0;
        while (1LL << (h + 1) <= mx) {
            ++h;
        }

        long long res = 0;
        for (int i = 0; i <= h; ++i) {
            long long cnt = 0;
            long long ones = 0;
            long long zeros = 0;
            for (auto x : A) {
                if (x & (1LL << i)) {
                    cnt += zeros;
                    cnt %= MOD;
                    ++ones;
                } else {
                    cnt += ones;
                    cnt %= MOD;
                    ++zeros;
                }
            }
            res += cnt * pow2[i] % MOD;
            res %= MOD;
        }
        return res;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<long long> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    Solution sol;
    cout << sol.solve(A) << "\n";

    return 0;
}

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

using namespace std;

#define ll long long

int main (){

    ll n,k,i,a,b=0;

    vector<int>v;

    cin>>n;

    for(i=0; i<n; i++){

        cin>>k;

        if(k%2 == 0){

            v.push_back(k);

        }

    }

    for(i=0; i<v.size(); i++){

        if(v[i]%3==0 || v[i]%5==0){

            b++;

        }

    }

    if(v.size() == b) cout<<"APPROVED"<<endl;

    else cout<<"DENIED"<<endl;

    return 0;

}


Measured memory_bytes: 256
l = input().split()
a = int(l[0])
b = int(l[1])
c = int(l[2])

for i in range(1,10):
    if a>b:
        a,b = b,a
    elif b>c:
        b,c = c,b
    elif a>b:
        a,b = b,a
    else :
        pass
print(a,b,c)


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


int main()
{
	double p1_x,p1_y;
	double p2_x,p2_y;
	double x,y;
	double wk;
	double calc_f;

	scanf("%lf %lf %lf %lf",&p1_x,&p1_y,&p2_x,&p2_y);
	x = fabs(p1_x-p2_x);
	y = fabs(p1_y-p2_y);
	
	calc_f = (pow(x,2) + pow(y,2));
	calc_f = sqrt(calc_f);
	printf("%lf\n",calc_f);

	return 0;
}

Measured memory_bytes: 652
import math
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")


a = I()
ans = a * (1+a+a**2)

print(ans)

Measured memory_bytes: 9248
#include<iostream>
using namespace std;
int main(){
  int n,a[100],c=0;
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n-1;i++) 
    for(int j=n-1;i<j;j--){
      int tmp=a[j];
      if(a[j-1]>a[j])a[j]=a[j-1],a[j-1]=tmp,c++;
    }
  for(int i=0;i<n-1;i++)cout<<a[i]<<" ";
  cout<<a[n-1]<<endl;
  cout<<c<<endl;
  return 0;
}

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

using namespace std ;

int main ()
{
    int a [ 4 ] ;
    for ( int i = 1 ; i <= 3 ; ++ i ){
        cin >> a [ i ] ;
    }
    sort ( a + 1 , a + 1 + 3 ) ;
    if ( a [ 1 ] == 5 && a [ 2 ] == 5 && a [ 3 ] == 7 ){
        cout << "YES" ;
        return 0 ;
    }
    cout << "NO" ;
    return 0 ;
}

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

using namespace std;

int main(){
  int n,x1,x2;
  long x4;
  char x3;
  string x5;
  vector<tuple<int, int, char, long, string>> a;

  cin >> n;
  for (int i = 0; i < n; i++){
    cin >> x1;
    cin >> x2;
    cin >> x3;
    cin >> x4;
    cin >> x5;
    a.push_back(make_tuple(x1, x2, x3, x4, x5));
  }
  sort(begin(a), end(a));
  for (int i = 0; i < a.size(); i++)
          cout << get<0>(a[i]) << " "
               << get<1>(a[i]) << " "
               << get<2>(a[i]) << " "
               << get<3>(a[i]) << " "
               << get<4>(a[i]) << "\n";

  return 0;
}



Measured memory_bytes: 12228
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    vector<int> p(n);
    rep(i,n) cin>>p[i];
    sort(p.rbegin(),p.rend());
    int res=0;
    rep(i,n){
        if(i==0)res+=p[i]/2;
        else res+=p[i];
    }
    cout<<res<<endl;
}


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

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()
    return

#B
def B():
    n = I()

    return

#C
def C():
    def factor(n):
        if n < 4:
            return {1:1,n:1}
        else:
            d = defaultdict(lambda : 0)
            i = 2
            m = n
            while i**2 <= n:
                if m%i == 0:
                    while m%i == 0:
                        d[i] += 1
                        m //= i
                i += 1
            d[m] += 1
            return d
    n = I()
    if n == 1:
        print(1)
        quit()
    f = defaultdict(lambda : 0)
    for i in range(2,n+1):
        fact = factor(i)
        for j,k in fact.items():
            if j > 1:
                f[j] += k
                f[j] %= mod
    ans = 1
    for i in f.values():
        ans *= (i+1)
        ans %= mod
    print(ans)
    return

#D
def D():
    def root(x):
        if x == par[x]:
            return x
        par[x] = root(par[x])
        return par[x]

    def unite(x,y):
        x = root(x)
        y = root(y)
        if rank[x] < rank[y]:
            par[x] = y
        else:
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1

    n,a,b = LI()
    par = [i for i in range(n)]
    rank = [0]*n
    x = LI()
    for i in range(n-1):
        if a*(x[i+1]-x[i]) < b:
            unite(i,i+1)
    ans = 0
    f = [1]*n
    f[0] = 0
    for i in range(1,n):
        if f[root(i)]:
            ans += b
            f[root(i)] = 0
        else:
            ans += a*(x[i]-x[i-1])
    print(ans)
    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

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


Measured memory_bytes: 43628
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

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

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    int M = min(a,b);
    int m = max(0,a+b-n);

    cout << M << " " << m << endl;


    return 0;
}


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

int main(){
  int N;
  cin >> N;
  
  vector<int> d(N);
  for(int i = 0; i < N; ++i) {
    cin >> d.at(i);
  }
  
  int count = 0;
  
  for(int i = 0; i < N; ++i) {
    for(int j = i+1; j < N; ++j) {
      count += d.at(i) * d.at(j);
    }
  }
  
  cout << count << endl;
}

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


int main(){
  int h,w,n,i,j,k;
  cin >> h >> w;
  cin >> n;
  vector<int> a(n);
  for(i=0;i<n;++i){
    cin >> a[i];
  }
  vector<vector<int>> c(h,vector<int>(w));
  k=1;
  for(i=0;i<h;++i){
    if(i%2==0){
      for(j=0;j<w;++j){
        c[i][j]=k;
        a[k-1]--;
        if(a[k-1]==0){
          k++;
        }
      }
    }else{
      for(j=w-1;j>=0;--j){
        c[i][j]=k;
        a[k-1]--;
        if(a[k-1]==0){
          k++;
        }
      }
    }
  }
  for(i=0;i<h;++i){
    for(j=0;j<w;++j){
      cout << c[i][j] << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
#define int long long int
#define vi vector<int>
#define vvi vector<vi>
#define read(a)  for(int i = 0; i < n; i++) cin >> a[i];
#define print(a)  for(int i = 0; i < n; i++) cout << a[i] << " ";
#define pb push_back
#define pql priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define pqlv priority_queue<vi>
#define pqsv priority_queue<vi, vvi, greater<vi>>
// #define endl '\n'
#define N 10000002
#define MOD 1000000007
signed main() {
    int t = 1;
    // cin >> t;
    while(t--) {
        int n = 5;
        vi a(n);
        read(a);
        for(int i = 0; i < n; i++) {
            if(a[i] == 0) {
                cout << i + 1 << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 3600
#include <stdio.h>
int main(void){
	int n,i=0,counter=0;
	scanf("%d",&n);
	char S[n+1];
	scanf("%s",S);
	S[n]='\0';
	i=0;
	while(i<n-1){
		if((S[i]=='A')&&(S[i+1]=='B')&&(S[i+2]=='C')&&(i+2<=n)){
			counter++;
		}
		i++;
	}
	printf("%d",counter);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[100001];
		int answer =0;
		for(int i=0; i< n;i++) {
			array[sc.nextInt()]++;
		}
		for(int i =0; i <= 100000-2;i++) {
			int tmpAnswer = 0;
			tmpAnswer += array[i];
			tmpAnswer += array[i+1];
			tmpAnswer += array[i+2];
			if(answer < tmpAnswer) {
				answer = tmpAnswer;
			}
		}
		System.out.print(answer);
	}
}

Measured memory_bytes: 48884
/*
　　　　 ∧＿∧　にっぽんちゃちゃちゃ
　／＼（　・∀・）／ヽ
（ ●　と　　　つ　● ）　にっぽんちゃちゃちゃ
　＼/⊂、 ノ　　＼ノ
　　　　　し'
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define MOD 1000000007
#define INF 9223372036854775807


signed main()
{
  string xyz ="";
int x=0,y=0,z=0,w=0,i=0,j=0,n=0;
repone(i,10){
  Repone(j,10){
    std::cout << i<<"x"<<j<<"="<<i*j<< '\n';
  }
}

}


Measured memory_bytes: 3084
import sys
input = sys.stdin.readline

#import fractions #fractions.gcd() python~3.4
sys.setrecursionlimit(1000000)

N, M = map(int,input().split())
A = list(map(int, input().split()))
INF = 1e+10
def f(x):
    if x == 1:
        return 2
    if x == 2:
        return 5
    if x == 3:
        return 5
    if x == 4:
        return 4
    if x == 5:
        return 5
    if x == 6:
        return 6
    if x == 7:
        return 3
    if x == 8:
        return 7 
    if x == 9:
        return 6

A.sort(reverse=True)

dp=[-INF]*(N+1)
dp[0] = 0
for i in range(1,N+1):
    for j in range(M):
        if i-f(A[j]) >= 0:
            dp[i] = max(dp[i],dp[i-f(A[j])]+1)
 
ans = ""
remain = dp[N]
match = N

while match > 0:
    for i in range(M):
        if match - f(A[i]) >=0 and dp[match - f(A[i])] == remain - 1:
            ans += str(A[i])
            match -= f(A[i])
            remain -= 1
            
            break
            
print(ans)



Measured memory_bytes: 3424
#include <iostream>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <vector>

#define all(vec) vec.begin(), vec.end()

using namespace std;

struct point{long x, y;};

struct uftree {
    int n, *par, *rank, *size;
    uftree(int N) : n(N) {
        par = new int[(size_t)N];
        rank = new int[(size_t)N];
        size = new int[(size_t)N];
        for (int i = 0; i < N; i++) {
            par[i]  = i;
            rank[i] = 0;
            size[i] = 1;
        }
    }
    int root(int x) {
        if (par[x] == x)
            return x;
        else {
            int r         = root(par[x]);
            size[x]       = size[par[x]];
            return par[x] = r;
        }
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (rank[x] > rank[y])
            par[y] = x;
        else {
            par[x] = y;
            if (rank[x] == rank[y]) rank[y]++;
        }
        size[x] += size[y];
        size[y] = size[x];
    }
    int getsize(int x) {
        root(x);
        return size[x];
    }
    bool same(int x, int y) { return root(x) == root(y); }

    // 集合の数をカウントする関数
    // 1..nのつもりでやってる場合も0をカウントしちゃうので注意
    int count_sets() {
        int cnt = 0;
        bool used[n];
        fill(used, used+n, false);
        for (int i=0; i<n; i++) {
            if (used[par[i]]) continue;
            cnt++;
            used[par[i]] = true;
        }
        return cnt;
    }
};

#define MAX_N 100010
struct edge{int from, to; long cost;};
int n;
vector<edge> E;
long prim() {
    uftree uft(n);
    sort(all(E), [](edge l, edge r) {
        return l.cost < r.cost;
    });
    long sum = 0;
    for (auto e:E) {
        if (uft.same(e.from, e.to)) continue;
        sum += e.cost;
        uft.unite(e.from, e.to);
    }
    return sum;
}

int main() {
    cin >> n;
    point p[n];
    for (auto &pi:p) 
        cin >> pi.x >> pi.y;
    int xs[n], ys[n];
    iota(xs, xs+n, 0);
    iota(ys, ys+n, 0);
    sort(xs, xs+n, [&](int l, int r) {
        return p[l].x < p[r].x;
    });
    sort(ys, ys+n, [&](int l, int r) {
        return p[l].y < p[r].y;
    });
    for (int i=0; i<n-1; i++) {
        E.push_back({xs[i], xs[i+1], p[xs[i+1]].x - p[xs[i]].x});
        E.push_back({ys[i], ys[i+1], p[ys[i+1]].y - p[ys[i]].y});
    }
    cout << prim() << '\n';
    return 0;
}

Measured memory_bytes: 8816
#include <bits/stdc++.h>
using namespace std;
char a[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
int main(){
	long long n, x=26, i=0, now, next;
	cin >> n;
	--n;
	for (; n-x>=0; n-=x, x*=26, i++);
	next=n;
	if (i==0){
		cout << a[n] << endl;
		return 0;
	}
	if (n==0)
		for (int j=1; j<=i+1; j++) cout << 'a';
	else
		for (int j=1; j<=i+1; j++){
			x/=26;
			now=next/x, next%=x;
			cout << a[now];
		}
	cout << endl;
	return 0;
}

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

int main(){
  string a,b,c;
  int n,m;
  cin >> a >> b;
  c=a+b;
  n=stoi(c);
  m=sqrt(n);
  if (n==m*m){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
 }


Measured memory_bytes: 256