akhauriyash/Code-Regression huggingface dataset:
from sys import stdin


def get_result(data):
    N = data[0][0]
    A = data[1]
    dp = [[0]*(N+1) for _ in range(N+1)]
    B = [[A[i], i] for i in range(N)]
    B = sorted(B, reverse=True)
    for i in range(N):
        for j in range(N-i):
            dp[i+1][j] = max(dp[i+1][j], dp[i][j] + B[i+j][0] * (B[i+j][1] - i))
            dp[i][j+1] = max(dp[i][j+1], dp[i][j] + B[i+j][0] * ((N-1-j) - B[i+j][1]))

    res = 0
    for i in range(N):
        res = max(res, dp[i][N-i])
    return res


if __name__ == '__main__':
    raw_data = [val.rstrip() for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)


Measured memory_bytes: 94824
#include<iostream>
#include<iomanip>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
#include<string.h>
#include<set>
#include<vector>
using namespace std;

#define INF 1<<21
#define MAX 100005
#define MOD 10e9+7

int main(){
    int N;
    int A[MAX];
    int w=0,h=0;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    sort(A,A+N);
    for(int i=0;i<N-1;i++){
        if(A[i]==A[i+1]){
            h=w;
            w=A[i];
            i++;
        }
    }
    cout<<(1LL)*h*w<<endl;
    return 0;
}


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

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

    int count=0;
    vector<int> data(n);
    rep(i, n)
    {
        cin >> data[i];
        int flag=0;
        rep(j, i)
        {
            if (data[j] > data[i])
            {
                flag = 1;
                break;
            }
        }
        if (flag != 1)
        {
            count += 1;
        }
    }
    cout <<count<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define ms_valtype int

//比較関数
int compare_ms(ms_valtype a, ms_valtype b){
	return a - b;
}

//昇順
void sort_sub(ms_valtype *origin, int left, int right, ms_valtype *tmp){
	if(right - left > 1){
		int i, j, k, half = (left + right) / 2;
		sort_sub(origin, left, half, tmp);
		sort_sub(origin, half, right, tmp);
		for(i = left; i < right; i++){
			tmp[i] = origin[i];
		}
		for(i = left, j = left, k = half; i < right; i++){
			if(k == right){
				origin[i] = tmp[j];
				j++;
			}
			else if(compare_ms(tmp[j], tmp[k]) <= 0 && j < half){
				origin[i] = tmp[j];
				j++;
			}
			else{
				origin[i] = tmp[k];
				k++;
			}
		}
	}
}

void sort(ms_valtype *origin, int N){
	ms_valtype *tmp = (ms_valtype *)malloc(sizeof(ms_valtype) * N);
	sort_sub(origin, 0, N, tmp);
	free(tmp);
}

int main(){
	int N, i, ans = 0;
	scanf("%d", &N);
	int *L = (int *)malloc(sizeof(int) * 2 * N);
	for(i = 0; i < 2 * N; i++){
		scanf("%d", &L[i]);
	}
	sort(L, 2 * N);
	for(i = 0; i < 2 * N; i += 2){
		ans += L[i];
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

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

    int N; cin >> N;
    vector<int> rates(8, 0);
    int numCrowns = 0;

    rep(i, 0, N) {
        int rate;
        cin >> rate;
        if (rate < 3200) ++rates[rate/400];
        else ++numCrowns;
    }

    int resMin, resMax;
    resMin = 8 - count(rates.begin(), rates.end(), 0);
    resMax = resMin + numCrowns;
    if (resMin == 0) ++resMin;

    cout << resMin << " " << resMax << "\n";
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np

MOD = 10**9 + 7

N = int(input())
T = np.array(input().split(),dtype=np.int64)
A = np.array(input().split(),dtype=np.int64)

Tlower = T.copy()
Tlower[1:][T[1:]<=T[:-1]] = 1

A = A[::-1]
Alower = A.copy()
Alower[1:][A[1:]<=A[:-1]] = 1
A = A[::-1]; Alower = Alower[::-1]

lower = np.maximum(Alower,Tlower)
upper = np.minimum(A,T)
x = np.maximum(0,upper - lower + 1)

L = len(x); Lsq = int(L**.5+1)
x = np.resize(x,Lsq**2); x[L:] = 1; x = x.reshape((Lsq,Lsq))
for n in range(1,Lsq):
    x[:,n] *= x[:,n-1]; x[:,n] %= MOD
for n in range(1,Lsq):
    x[n] *= x[n-1,-1]; x[n] %= MOD
answer = x[-1,-1]
print(answer)

Measured memory_bytes: 25968
//
// Created on 2019-02-09.
//
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=b; }

#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

#define PB push_back
#define INF 1e9
#define MOD 1e9+7
#define EPS 1e-9

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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


    int a, b, c, d, e, k;

    cin >> a >> b >> c >> d >> e >> k;

    if (b-a>k or c-a>k or d-a>k or e-a>k or c-b>k or d-b>k or e-b>k or d-c>k or e-c>k or e-d>k) {
        cout << ":(" << endl;
        return 0;
    } else {
        cout << "Yay!" << endl;
        return 0;
    }

    return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>

using namespace std;

using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

int sum[2][4005][4005];

int rect(int c, int x1, int y1, int x2, int y2)
{
    return sum[c][x2][y2]
        - sum[c][x1 - 1][y2]
        - sum[c][x2][y1 - 1]
        + sum[c][x1 - 1][y1 - 1];
}

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

    for (int i = 0; i < n; i++)
    {
        int x, y, c;
        char buf[2];

        scanf("%d %d %s", &x, &y, buf);

        x %= 2 * k;
        y %= 2 * k;
        x++;
        y++;
        
        if (buf[0] == 'W')
            c = 0;
        else
            c = 1;

        sum[c][x][y]++;
        sum[c][x + 2 * k][y]++;
        sum[c][x][y + 2 * k]++;
        sum[c][x + 2 * k][y + 2 * k]++;
    }

    for (int x = 1; x <= 4 * k; x++)
        for (int y = 1; y <= 4 * k; y++)
            for (int c = 0; c < 2; c++)
                sum[c][x][y] += sum[c][x][y - 1];

    for (int y = 1; y <= 4 * k; y++)
        for (int x = 1; x <= 4 * k; x++)
            for (int c = 0; c < 2; c++)
                sum[c][x][y] += sum[c][x - 1][y];

    int ans = 0;
    for (int xshift = 1; xshift <= 2 * k; xshift++)
    {
        for (int yshift = 1; yshift <= 2 * k; yshift++)
        {
            //0 / 1이 있어야하는 각각 영역의 실제 개수 구해서 더해준다
            int zero = rect(0, xshift, yshift, xshift + k - 1, yshift + k - 1) +
                rect(0, xshift + k, yshift + k, xshift + 2 * k - 1, yshift + 2 * k - 1);
            int one = rect(1, xshift + k, yshift, xshift + 2 * k - 1, yshift + k - 1) +
                rect(1, xshift, yshift + k, xshift + k - 1, yshift + 2 * k - 1);

            ans = max(ans, zero + one);
        }
    }

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

    return 0;
}

Measured memory_bytes: 125440
n = gets.to_i
a = gets.split.map(&:to_i)
x = [0, 0, 0]
ans = 1
n.times do |i|
  mul = 0
  3.times do |j|
    mul += 1 if x[j] == a[i]
  end
  3.times do |j|
    if x[j] == a[i] then
      x[j] += 1
      break
    end
  end
  ans *= mul
  ans %= 1000000007 if ans > 1000000007
end
puts ans

Measured memory_bytes: 10628
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
using namespace std;
int main(){
    ll n;
    cin>>n;
    unordered_map<string,ll> u;
    u["AC"]=0;
    u["WA"]=0;
    u["RE"]=0;
    u["TLE"]=0;
    while(n--){
        string a;
        cin>>a;
        u[a]++;
    }
    cout<<"AC x "<<u["AC"]<<endl;
    cout<<"WA x "<<u["WA"]<<endl;
    cout<<"TLE x "<<u["TLE"]<<endl;
    cout<<"RE x "<<u["RE"]<<endl;
}

Measured memory_bytes: 3632
#include <iomanip>
#include <iostream>

using namespace std;

int main()
{
  int n; cin >> n;
  int x = 0, y = 0, z = 0;
  for (int i = 0; i < n; ++i) {
    int a; cin >> a;
    if (a == 3) ++x;
    else if (a == 2) ++y;
    else ++z;
  }

  double dp[310][310][310];
  dp[0][0][0] = 0;
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= n; ++j)
      for (int k = 0; k <= n; ++k) {
        int sm = i+j+k;
        if (!sm) continue;
        dp[i][j][k] = 1.0*n/sm;
        if (i) dp[i][j][k] += dp[i-1][j+1][k]*i/sm;
        if (j) dp[i][j][k] += dp[i][j-1][k+1]*j/sm;
        if (k) dp[i][j][k] += dp[i][j][k-1]*k/sm;
      }
  
  cout << fixed << setprecision(12) << dp[x][y][z] << endl;
  return 0;
}

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

int main(){
    string s;
    cin >> s;
    char c1,c2,c3,c4;
    c1 = s[0];
    c2 = s[1];
    c3 = s[2];
    c4 = s[3];
    if(c1==c2 && c2==c3){
        cout << "Yes" << endl ;
    }
    else if(c2==c3 && c3==c4){
        cout << "Yes" << endl ;
    }
    else {
        cout << "No" << endl ;
    }
}

Measured memory_bytes: 256
a=list(input())

n = 0

s = 0

e = 0

w = 0

for i in a:
  if i == 'N':
    n += 1
  elif i == 'S':
    s += 1
  elif i == 'E':
    e += 1
  elif i == 'W':
    w += 1

if n > 0 and s == 0 or n == 0 and s > 0 or e > 0 and w == 0 or e == 0 and w > 0:
  print('No')
else:
  print('Yes')

Measured memory_bytes: 38256
#include <iostream>
#include <string>
#include <cctype>
using namespace std;

int main(void){
    while(1){
        string input_num;
        input_num.reserve(1000);
        getline(cin,input_num);
        if(input_num == "0")
            break;
        int result = 0;
        for(int i=0;i<input_num.size();i++){
            result += (input_num[i] - '0');

        }
        cout << result << endl;
    }
}


Measured memory_bytes: 3136
use std::io;
use std::str::FromStr;

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn input_vec() -> Vec<u64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
      a
    } else {
      gcd(b, a % b)
    }
  }
  

fn main() {
    let (n, k) = input_tuple();
    let a_vec = input_vec();
    let mut max = 0;
    let mut buf = a_vec[0];
    for a in a_vec {
        buf = gcd(buf, a);
        if a > max { 
            max = a;
        }
    }
    if k > max {
        println!("IMPOSSIBLE");
        return;
    }
    if k % buf == 0 {
        println!("POSSIBLE");
    } else {
        println!("IMPOSSIBLE");
    }
}


Measured memory_bytes: 6396
import java.util.*;

class Main {
	Scanner sc;
	int N, M;
	int[] stat;
	int[] penalty;
	
	private void calc() {
		sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		stat = new int[N];
		penalty = new int[N];
		for (int i = 0; i < M; i++) {
			int p = sc.nextInt() - 1;
			String S = sc.next();
			switch (S) {
			case "WA":
				if (stat[p] == 0) penalty[p]++;
				break;
			case "AC":
				stat[p] = 1;
				break;
			default:
			}
		}
		int ac = 0;
		int pe = 0;
		for (int i = 0; i < N; i++) {
			if (stat[i] == 1) {
				ac++;
				pe += penalty[i];
			}
		}
		
		System.out.println(ac+" "+pe);
	}

	public static void main(String[] args) {
		new Main().calc();
	}
}

Measured memory_bytes: 65716
n=int(input())
import sys
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
from fractions import Fraction as frac  #frac(a,b)で正確なa/b
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

class UnionFind():
    def __init__(self,num):
        self.n = num         #class内変数nに、外部から入力した値numを代入
        self.parents = [-1 for i in range(self.n)]
          #parentsは要素の親(1こ上のやつ)番号0~n-1を格納、自分が最親なら-(要素数)を格納(初期値は-1)

    #xの最親は誰？
    def find(self,x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x]) #再帰して1番上までいってる
                #調べながらparentsの値を更新してる！（経路圧縮）
            return self.parents[x]

    #結合せよ
    #xの親とyの親をくっつける
    def union(self,x,y):
        xx=self.find(x)  #xxはxの最親
        yy=self.find(y)  #yyはyの最親
        if xx==yy:
            return     #同じ屋根の下にあった場合は何もしない
        else:
            size_xx=abs(self.parents[xx]) #xが含まれる木のサイズ
            size_yy=abs(self.parents[yy]) #yが含まれる木のサイズ
            if size_xx>size_yy:
                xx,yy=yy,xx  #yyの方が大きい木、ってことにする

            self.parents[yy]+=self.parents[xx] #大きい木のサイズ更新
            self.parents[xx]=yy   #サイズが小さい木を大きい木に接ぐ

    #xの属する木の大きさ（まあunionでも使ったけど）
    def size(self,x):
        xx=self.find(x)
        return abs(self.parents[xx])

    #xとyはこの空の続く場所にいますか　いつものように笑顔でいてくれますか　今はただそれを願い続ける
    def same(self,x,y):
        return 1 if self.find(x)==self.find(y) else 0

    #xと　同じ木にいる　メンバーは？
    def members(self,x):
        xx=self.find(x)
        return [i for i in range(self.n) if self.find(i)==xx]
             #ifの条件式に漏れたら無視

    #最親だけを並べあげる
    def roots(self):
        return [i for i,x in enumerate(self.parents) if x < 0]
        #いやこれは天才すぎる、basisのenumerate.py参照

    #すべての最親について、メンバーを辞書で
    def all_group_members(self):
        return {r:self.members(r) for r in self.roots()}

    #グループ分けどうなりましたか、２重リストで
    def state_grouping(self):
        return list(self.all_group_members().values())

uf=UnionFind(n)
A=[0]*n 
for i in range(n):
    a,b=map(int,input().split())
    a-=1;b-=1
    A[b]=(a,i)
M= deque([])
for i in range(n):
    if not M: M.append(A[i]);continue
    h,num = A[i]
    cnt=0
    while M:
        xx,nownum = M.pop()
        if not cnt: xori,nowori= xx,nownum
        if xx> h: 
            M.append((xx,nownum));break
        uf.union(nownum,num)
        cnt+=1
    if cnt==0:
        M.append((xori,nowori))
        M.append((h,num))
    else:
        M.append((h,num))
        M.append((xori,nowori))
for i  in range(n):
    print(uf.size(i))
        
    



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

#define YES(condition) if(condition){ cout << "YES" << endl; }else{ cout << "NO" << endl; }
#define Yes(condition) if(condition){ cout << "Yes" << endl; }else{ cout << "No" << endl; }
#define POSS(condition) if(condition){ cout << "POSSIBLE" << endl; }else{ cout << "IMPOSSIBLE" << endl; }
#define Poss(condition) if(condition){ cout << "Possible" << endl; }else{ cout << "Impossible" << endl; }
long power(long base, long exponent, long mod){ if(exponent % 2){ return power(base, exponent - 1, mod) * base % mod; }else if(exponent){ long root_ans = power(base, exponent / 2, mod); return root_ans * root_ans % mod; }else{ return 1; }}

int main(){
    int N;
    cin >> N;
    long back;
    cin >> back;
    long ans = back / 2;
    back %= 2;
    for(int i = 1; i < N; i++){
        long num;
        cin >> num;
        ans += min(back, num);
        num -= min(back, num);
        ans += num / 2;
        back = num % 2;
    }
    cout << ans << endl;
}



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

int main() {
  int N, M;
  cin >> N >> M;
  int ac[1000000] = {};
  int wa[1000000] = {};
  bool Acount[1000000] = {};
  for (int i = 0; i < M; i++) {
    string s;
    int p;
    cin >> p >> s;
    if (s == "AC") {
      ac[p]++;
      Acount[p] = 1;
    }
    else if (s == "WA" && Acount[p] == 0) {
      wa[p]++;
    }
  }
  int A = 0;
  int W = 0;
  for (int i = 1; i < N + 1; i++) {
    if (ac[i] > 0) {
      A++;
      if (wa[i] > 0) {
        W += wa[i];
      }
    }
  }
  cout << A << ' ' << W <<endl;
}

Measured memory_bytes: 9088
"""
author : halo2halo
date : 3, Feb, 2020
"""

import sys
import itertools

import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A, op, B = readline().decode('utf8').split()
print(int(A) + int(B) if op == '+' else int(A) - int(B))


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

class floodfill{
  struct pt{
    int x,y,n;
  };
  vector<pt> dirs = { {0,1,1}, {0,-1,1}, {1,0,1}, {-1,0,1} };
  int h,w;
  vector<string> vs;
public:
  floodfill(int _h,int _w,vector<string>& _vs) : h(_h),w(_w),vs(_vs) {}
  int dist(){
    int ans = 0;
    queue<pt> q;
    for(int i = 0; i < h; ++i){
      for(int j = 0; j < w; ++j){
        if(vs[i][j] == '#'){
          vs[i][j] = true;
          q.emplace(pt{i,j,0});
        }
      }
    }
    while(!q.empty()){
      auto p = q.front();
      q.pop();
      for(auto& d : dirs){
        int x=p.x+d.x,y=p.y+d.y,n=p.n+d.n;
        if(0 <= x and x < h and 0 <= y and y < w){
          if(vs[x][y] == '.'){
            vs[x][y] = '#';
            ans = max(ans,n);
            q.emplace(pt{x,y,n});
          }
        }
      }
    }
    return ans;
  }
};

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  int h,w,nb = 0;
  cin >> h >> w;
  vector<string> vs(h);
  for(int i = 0; i < h; ++i) cin >> vs[i];
  floodfill ff(h,w,vs);
  cout << ff.dist();
  return 0;
}

Measured memory_bytes: 14480
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)n; i++)
#define REPR(i, n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=(int)m; i<(int)n; i++)
#define FORR(i, m, n) for(int i=(int)m-1; i>=(int)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
typedef long long ll;
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }



void solve(long long N, std::vector<long long> d){
	ll res = 0;
	REP(x, N) {
		REP(y, x) {
			res += d[x]*d[y];
		}
	}
	cout << res << "\n";
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> d(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&d[i]);
    }
    solve(N, std::move(d));
    return 0;
}


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

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

  vector<int> A(N, 0);
  for (int i = 0; i < N; i++) {
    scanf("%d", &A.at(i));
  }

  vector<int> ans(N, 0);
  for (int i = 0; i < N; i++) ans.at(A.at(i) - 1) = i + 1;
  for (int i = 0; i < N; i++) printf("%d ", ans.at(i));
  return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;


const int SIZE = 1e5+100;

ll n, a, b;
ll ans;
int main(){
    cin >> n >> a >> b;
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        int nn = i, mem = 0;
        while(nn > 0){
            mem += nn%10;
            nn /= 10;
        }
        if(mem >= a && mem <= b){
            ans += i;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A, B = [], []

for i in range(N):
	a = list(map(str, input()))
	A.append(a)
	
for i in range(M):
	b = list(map(str, input()))
	B.append(b)
	
def foo():
	for si in range(N - M + 1):
		for sj in range(N - M + 1):
			flg = 1
			for i in range(M):
				if not A[si + i][sj : sj + M] == B[i]:
					flg = 0
					break
			if flg:
				print("Yes")
				return 0
	print("No")
	return 0
	
foo()

Measured memory_bytes: 38640
from collections import deque

N,K = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)
    
mod = 10**9+7
L = [0]*N
L[0] = K
ans = 1
q = deque()
q.append(0)
while q:
    t = q.popleft()
    c = max(K-1, L[t])
    for e in E[t]:
        if L[e] == 0:
            c -= 1
            if c <= 0:
                ans = 0
                q = []
                break
            L[e] = c
            q.append(e)
            
for i in range(N):
    ans *= L[i]
    ans %= mod
    
print(ans)

Measured memory_bytes: 27032
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        //static long Mod = (long)1e9 + 7;
        static List<long>[] tree;
        static long[] query;
        static bool[] cmp;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NK = Sarray();
            var N = NK[0];
            var K = NK[1];
            var xi = Sarray();
            var ans = long.MaxValue / 2;
            for (var l = 0; l < N - K + 1; ++l)
            {
                var r = l + K - 1;
                if (xi[l] < 0 && xi[r] <= 0)
                {
                    ans = Min(ans, Abs(xi[l]));
                }
                else if (xi[l] < 0 && 0 < xi[r]) 
                {
                    var t = Min(Abs(xi[l]) * 2 + xi[r], xi[r] * 2 + Abs(xi[l]));
                    ans = Min(ans, t);
                }
                else
                {
                    ans = Min(ans, xi[r]);
                }
            }
            WriteLine(ans);
            //Out.Flush();
        }
    }
}


Measured memory_bytes: 22880
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <string.h>
#include <string>

using namespace std;

int main()
{
    int n, x;
    cin >> n >> x;
    int a[n];
    for (int i=0; i<n; i++) {
        cin >> a[i];
    }
    sort(a, a+n);
    int cnt = 0;
    for (int i=0; i<n; i++) {
        if (i == n-1) {
            if (x != a[i]) break;
        }
        if (x < a[i]) break;
        x = x - a[i];
        cnt++;
    }
    cout << cnt << '\n';
   return 0;
}

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

typedef long long int ll;
const int maxn = 2e5 + 10;
int a[maxn];
void solved(){
	long long n,k;cin>>n>>k;
	for(int i = 1; i <= n; i++)cin>>a[i];
	map<int,bool>mp;
	vector<int>cyc,sta;
	for(int i = 1; ;i = a[i]){
		if(!mp[i]){
			mp[i] = true;
			sta.push_back(i);
		}else{
			bool flag = false;
			for(int k = 0; k < sta.size(); k++){
				if(i == sta[k])flag = true;
				if(flag){
					cyc.push_back(sta[k]);
				}
			}
			break;
		}
	}
	if(k < sta.size())cout<<sta[k]<<endl;
	else {
		k -= sta.size();
		k %= cyc.size();
		cout<<cyc[(k + (int)cyc.size()) % (int)cyc.size()]<<endl;
	}
}
int main(){
	solved();
	return 0;
} 


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

int main(){
  int d, n;
  cin >> d >> n;
  if(d==0) {if(n==100) cout << 101 << endl; 
            else cout << n << endl;}
  else if(d==1){
    if(n==100) cout << 10100 << endl;
    else cout << 100*n << endl;
  }
  else {if(n==100) cout << 1010000 << endl;
        else cout << 10000*n << endl;}
  
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>

using namespace std;

#define rep(i,n) for(int i=0;i<int(n);i++)
#define reps(i,n) for(int i=1;i<=int(n);i++)
#define sint(i) scanf("%d",&i);
#define sintt(i,j) scanf("%d%d",&i,&j);
#define sinttt(i,j,k) scanf("%d%d%d",&i,&j,&k);
#define sintttt(i,j,k,m) scanf("%d%d%d%d",&i,&j,&k,&m);

#define INF 1010000000
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

class S{
	public:
	int a,b,c,d;
	int n;
	S(int p,int n,int t,int k,int i):a(p),b(n),c(t),d(k),n(i){}
	
};

char visit[51][51][51][51];

int main(){
	while(1){
		int n,m;
		sintt(n,m);
		if(n==0)break;
		int a,b,c,d;
		sintttt(a,b,c,d);
		
		int masu[51][51];
		
		rep(i,51)rep(j,51)masu[j][i]=0;
		reps(i,m){
			reps(j,n){
				sint(masu[j][i]);
			}
		}
		
		queue<S> que;
		que.push(S(a,b,c,d,0));
		rep(i,51)rep(j,51)rep(k,51)rep(p,51)visit[i][j][k][p]=0;
		int ans=0;
		while(1){
			if(que.empty()==1){
				break;
			}
			
			
			S u=que.front();
			que.pop();
			
			//printf("%d %d  %d %d  %d\n",u.a,u.b,u.c,u.d,u.n);
			
			if(visit[u.a][u.b][u.c][u.d]==1){
				continue;
			}
			visit[u.a][u.b][u.c][u.d]=1;
			
			if(u.a==u.c && u.b==u.d){
				ans=u.n;
				break;
			}
			
			rep(i,4){
				int dx1=u.a+dx[i];
				int dy1=u.b+dy[i];
				
				int dx2=u.c+dx[i]*-1;
				int dy2=u.d+dy[i]*-1;
				
				//printf("push %d %d %d %d\n",dx1,dy1,dx2,dy2);
				
				if(dx1<=0 || dy1<=0 || dx1>n ||dy1>m|| masu[dx1][dy1]==1){
					dx1-=dx[i];
					dy1-=dy[i];
				}
				if(dx2<=0 || dy2<=0 || dx2>n ||dy2>m|| masu[dx2][dy2]==1){
					dx2-=dx[i]*-1;
					dy2-=dy[i]*-1;
				}
				
				//printf("push %d %d %d %d\n",dx1,dy1,dx2,dy2);
				que.push(S(dx1,dy1,dx2,dy2,u.n+1));
			}
		}
		if(ans==0){
			puts("NA");
		}else{
			printf("%d\n",ans);
		}
	}
}

Measured memory_bytes: 8348
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <map>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten6 1000005
#define PI 3.1415926

typedef long long int ll;

ll getGcd(ll,ll);
//int num[ten6];

int main()
{
    //int m,n,o=0,i,j,k;
    long long int sum=0,sum2=0,n1=0,n2=0,n3;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=1,now=1;
    long long int a,a1,a2,a3,a4,aa[4];
    //float f,g,h;
    char c;
    string s,s1;
    //priority_queue<long l ong int> pq;
    //vector<long long int> vint;
    //map<int,int> mp;
    //map<string,int>::iterator iter;
    //set<int> sint;
    cin>>n>>m;
    a=getGcd(m,n);
    cout<<m*n/a;
    return 0;
}

ll getGcd(ll m,ll n)
{
    if(n==0) return m;
    else return getGcd(n,m%n);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int a, b;
  cin >> a >> b;
  int ans;
  rep(i, 20){
    if(1+(a-1)*i >= b){
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
# A**5 = X + B**5
X = int(input())

l = []
for i in range(-300, 300):
    l.append(i**5)

for b, b_5 in enumerate(l, start=-300):
    # print(b, b_5, X)
    if X+b_5 in l:
        a_5 = X+b_5
        a = l.index(a_5)-300
        print(a, b)
        break

Measured memory_bytes: 9124
#include <stdio.h>
int main(void){
    // Your code here!
   int h;
   
   int w;
   while(1) {
       scanf("%d%d", &h, &w);
       if(h == 0 && w == 0)
       return(0);
       int i;
       for(i = 0; i < h; i++) {
           int j;
           for(j = 0; j < w; j++) {
               if((i == 0 || i == h-1) || (j == 0 || j == w-1)) putchar('#');
               else putchar('.');
               }
               if(i < h-1) putchar('\n');
               else{
                   putchar('\n');
                   putchar('\n');
                   }
                   }
                   }
                   return 0;
                   }



Measured memory_bytes: 1924
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,A,B) for(int I=int(A);I<int(B);I++)

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

	clock_t start = clock();


	int N,ans=0;
	cin >> N;
	vector<int> A[N+1];
	FOR(i,1,N+1){
		A[i].resize(N);
		FOR(j,1,N){
			cin >> A[i][j];
		}
	}
	
	bool game = true;
	vector<int> ind(N+1,1);//A[i][ind[i]]
	vector<int> nextOPP(N+1,-1);
	vector<int> rest;
	FOR(i,1,N+1) rest.push_back(i);
	while(game){
		game = false;
		ans++;
		vector<int> restt;
		for(int i:rest)nextOPP[i] = -1;
		for(int i:rest){
			if(ind[i]>=N)continue;
			nextOPP[i] = A[i][ind[i]];
			if(nextOPP[nextOPP[i]]==i){
				game = true;
				ind[i]++;
				ind[nextOPP[i]]++;
			}
		}
		for(int i:rest) if(ind[i]<N) restt.push_back(i);
		rest = restt;

		clock_t end = clock();
		double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
		if(time >= 1800.0){
			cout << N*(N-1)/2 << endl;
			return 0;
		}
	}
	bool allok = true;
	FOR(i,1,N+1)if(ind[i]<N)allok=false;
	if(allok){
		cout << ans-1 << endl;
	}else{
		cout << -1 << endl;
	}
}



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

int main () {
  int N, K;
  cin >> N >> K;
  vector<int> x(N);
  rep(i,N) cin >> x[i];

  int ans = 1e9;

  for(int i = 0; i + K - 1 < N; i++) {
    int l = x[i];
    int r = x[i+K-1];
    if(r <= 0) {
      ans = min(ans, -l);
    } else if(l >= 0) {
      ans = min(ans, r);
    } else {
      ans = min(ans, min(abs(l), abs(r)) * 2 + max(abs(l), abs(r)));
    }
  }

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


Measured memory_bytes: 640
import sys


def main():
    n = int(sys.stdin.readline().strip())
    H = [int(s) for s in sys.stdin.readline().strip().split()]
    if is_possible(n, H):
        print('Yes')
    else:
        print('No')


def is_possible(n, H):
    prev = float('-inf')
    for i in range(n):
        if H[i] - 1 >= prev:
            prev = H[i] - 1
        elif H[i] >= prev:
            prev = H[i]
        else:
            return False
    return True


main()


Measured memory_bytes: 63984
mod=1e9+7
n=input()
s1=raw_input()
s2=raw_input()
if s1[0]==s2[0]:
	r=3
	i=1
	prev=True
else:
	assert s1[0]==s1[1]!=s2[0]==s2[1]
	r=6
	i=2
	prev=False
while i<n:
	if s1[i]==s2[i]:
		if prev:
			r=r*2%mod
		i+=1
		prev=True
	else:
		assert s1[i]==s1[i+1]!=s2[i]==s2[i+1]
		if prev:
			r=r*2%mod
		else:
			r=r*3%mod
		i+=2
		prev=False
print int(r)

Measured memory_bytes: 28396
#include <math.h>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>

#define YES "YES"
#define NO "NO"

using namespace std;

void func();
int n;

int main(void)
{
	
	func();

	return 0;
}

void func()
{
	cin >> n;

	while (n-- > 0)
	{
		int edge[3];
		for (int i = 0; i < 3; i++)
		{
			cin >> edge[i];
			edge[i] *= edge[i];	// 2?????????
		}
		sort(edge, edge + 3);

		if ((edge[0] + edge[1]) == edge[2])
		{
			cout << YES << endl;
		}
		else
		{
			cout << NO << endl;
		}
	}
}

Measured memory_bytes: 1164
def inputs(get_t=False):
    D = int(input())
    c = list(map(int, input().split()))
    s = []
    for d in range(D):
        sd = list(map(int, input().split()))
        s.append(sd)
    if get_t:
        t = []
        for d in range(D):
            t.append(int(input()))
    return D, c, s


def greety(D, c, s):
    best_t = []
    for day in range(1, D+1):
        day_idx = day - 1
        max_idx = s[day_idx].index(max(s[day_idx]))
        best_t.append(max_idx+1)
    return best_t


def output(types):
    for t in types:
        print(t)


if __name__ == "__main__":
    D, c, s = inputs()
    t = greety(D, c, s)
    output(t)


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

int main()
{
    int H, W;

    while (true)
    {
        cin >> H >> W;
        if (H == 0 && W == 0)
        {
            break;
        }

        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                if (i == 0 || i == H - 1 ||
                    j == 0 || j == W - 1)
                {
                    cout << "#";
                }
                else
                {
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3080
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

import static java.util.Comparator.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        Solver solver = new Solver(System.in, out);
        solver.solve();
        out.close();
    }
}
class Solver {
	Scanner sc;
	PrintWriter out;
    public Solver(InputStream in, PrintWriter out) {
    	sc = new Scanner(in);
    	this.out = out;
    }
    // ==================================================================
    int INF = 1000000000;
    public void solve() {
    	int N = Integer.parseInt(sc.next());
    	char[] C = sc.next().toCharArray();
    	int[] P1 = new int[30010];
    	HashSet<Integer> set = new HashSet<>();
    	HashSet<Integer> set2 = new HashSet<>();
    	for (int i = N - 1; i >= 0; i--) {
    		if(!set.contains((int)(C[i]-'0'))) {
    			set.add((int)(C[i]-'0'));
    			P1[i] = P1[i+1] + 1;
    		} else {
    			P1[i] = P1[i+1];
    		}
		}
    	set.clear();
    	int ans = 0;
    	for (int i = 0; i < N; i++) {
    		if(!set.contains((int)(C[i]-'0'))) {
    			set.add((int)(C[i]-'0'));
    			set2.clear();
    			for (int j = i+1; j < N; j++) {
    	    		if(!set2.contains((int)(C[j]-'0'))) {
    	    			set2.add((int)(C[j]-'0'));
    	    			ans += P1[j+1];
    	    		}
				}
    		}
		}
    	out.println(ans);
    }
    // ==================================================================
}
class PP{
	public int key, val;
	public PP(int key, int val) {
		this.key = key;
		this.val = val;
	}
	public int getKey() {
		return key;
	}
	public int getVal() {
		return val;
	}
}


Measured memory_bytes: 25172
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var Mi = Sarray();
            var Yi = Sarray();
            var ans = 0L;
            for (var i = 0; i < N; ++i)
            {
                ans += Min(Yi[i], Mi[i] + Mi[i + 1]);
                var zan = Max(Yi[i] - Mi[i], 0);
                Mi[i + 1] = Max(Mi[i + 1] - zan, 0);
            }
            WriteLine(ans);

            //Out.Flush();
        }
    }
}

Measured memory_bytes: 35700
#include<bits/stdc++.h>
using namespace std;
 
#define IOS 		ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sd(n)       scanf("%d", &n)
#define sdd(a,b)    scanf("%d %d", &a, &b)
#define sddd(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sld(n)      scanf("%lld", &n)
#define slld(a,b)   scanf("%lld %lld", &a, &b)
#define sllld(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define slu(n)      scanf("%llu", &n)
#define sllu(a,b)   scanf("%llu %llu", &a, &b)
#define slllu(a,b,c) scanf("%llu %llu %llu", &a, &b, &c)
#define ss(a)		scanf("%s", a)
#define all(a) 		a.begin(),a.end()
#define unq(x)      x.erase(unique(all(x)), x.end()
#define mp 			make_pair
#define sz(av) 		int((av).size())					//return size of vec
#define CLR(arr)    memset(arr, 0, sizeof(arr))			//assign 0 to whole arr
#define SET(vec)    memset(arr, -1, sizeof(arr))		//assign -1 to whole arr
#define CLRV(vec)	fill(vec.begin(), vec.end(), 0)		//assign 0 to whole vec
#define SETV(vec,n,a) vec.assign(n, a)	
#define vtd(rowsize,colsize,type,name) 		vector < vector <type> > name(rowsize,vector <type> (colsize)); 	//assign to first n elements value a in vec
#define SETB(a)		memset(a, true, sizeof(a))			//boolean array initialize by true value
#define CLRB(a)		memset(a, false, sizeof(a))			//boolean array initialize by false value
#define vintitr 	vector<int>::iterator
#define vlnlnitr 	vector<long long>::iterator
#define sintitr 	set<int>::iterator
#define slnlnitr 	set<long long>::iterator
#define aa			first
#define bb 			second
#define mod 		n007
#define PI 			acos(-1.00)
#define psb 		push_back
#define ppb			pop_back
#define ppb			pop_back
#define psf			push_front
#define ppf			pop_front
#define in 			inset
#define for0(i, n) 	for(int i=0; i<n; i++)
#define fori(i,j,n) for(int i=j; i<=n; i++)
#define rof(i, n)   for(int i=n-1; i>=0; i--)
#define min3(a,b,c) (min((c),min((a),(b))))
#define max3(a,b,c) (max((a),max((b),(c))))
#define __lcm(a, b)	a*b / __gcd(a, b)
#define D(t)        cerr << #t " = " <<t  << '\n'
#define DBG         cerr << "Hi!" << '\n'
 
 
typedef long long	 		ll;
typedef unsigned long long	llu;
typedef long double			ld;
typedef pair<int, int> 		pii;


int main()
{
	int a, b;
	cin >> a >> b;
	cout << max3(a+b, a-b, a*b) << endl;
	return 0;
}


Measured memory_bytes: 256
myCeil :: Int -> Int -> Int
myCeil a b = (div a b) + c
 where c = if((mod a b) == 0) then 0 else 1

main :: IO ()
main = do
 [a,b,c,d] <- map read . words <$> getLine :: IO[Int]
 putStr $ (\a b c d -> if (myCeil c b) <= (myCeil a d) then "Yes" else "No") a b c d

Measured memory_bytes: 3796
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const ll mod=1000000007;
const ll INF=1e15;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end())
#define pb push_back
#define mp make_pair
#define MODP(A,B) A=(A+B)%mod
typedef pair<ll,ll> P;
typedef pair<double,double> Pd;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

vec Sosu;

//Combinationを求める

const ll MaxN=201001;

ll f[MaxN], rf[MaxN];
ll inv(ll x) {
    ll res = 1;
    ll k = mod - 2;
    ll y = x;
    while (k) {
        if (k & 1) res = (res * y) % mod;
        y = (y * y) % mod;
        k /= 2;
    }
    return res;
}
void init() {
    f[0] = 1;
    REP(i, 1, MaxN) f[i] = (f[i - 1] * i) % mod;
    REP(i, 0, MaxN) rf[i] = inv(f[i]);
}
//---------------------------------------------------------------------------------------------------
ll C(ll n, ll k) {
    ll a = f[n]; // = n!
    ll b = rf[n-k]; // = (n-k)!
    ll c = rf[k]; // = k!

    ll bc = (b * c) % mod;

    return (a * bc) % mod;
}

vec Eratosthenes(ll N){
    vec ret;
    vector<bool> a(N+1,true);
    a.at(0)=false;
    a.at(1)=false;
    REP(i,2,N+1){
        if(a.at(i)) for(ll k=2*i;k<=N;k+=i) a.at(k)=false;
    }
    rep(i,N+1) if(a.at(i)) ret.pb(i);
    return ret;
}

vector<P> Soin(ll N){
    vec Sosu=Eratosthenes(N);
    vector<P> ret;
    for(int i=0;Sosu.at(i)*Sosu.at(i)<=N;i++){
        ll k=Sosu.at(i);
        ll count=0;
        while(true){
            if(N%k!=0) break;
            count++;
            N/=k;
        }
        if(count!=0) ret.pb(mp(k,count));
    }
    if(N!=1) ret.pb(mp(N,1));
    return ret;
}


int main(){
    ll N,M; cin>>N>>M;
    vec R;
    init();
    ll ans=1;

    for(ll i=2;i*i<=M;i++){
        ll count=0;
        while(true){
            if(M%i!=0) break;
            M/=i;
            count++;
        }
        R.pb(count);
    }
    if(M!=1) R.pb(1);
    
    rep(i,R.size()){
        ll a=R.at(i);
        ans=(ans*C(N+a-1,a))%mod;
    }
    cout<<ans<<endl;


}

Measured memory_bytes: 3456
#include <iostream>

using namespace std;

long long int min(long long int a, long long int b) {
    return a < b ? a : b;
}

int main()
{
    int N;
    cin >> N;
    int arr[N];
    int max_a = -100;
    int min_a = +100;
    for(int i = 0; i < N; ++i) {
        cin >> arr[i];
        if(arr[i] > max_a) max_a = arr[i];
        if(arr[i] < min_a) min_a = arr[i];
    }
    long long int ans = 10000000;
    for(int target = min_a; target <= max_a; ++target) {
        long long int cost = 0;
        for(int i = 0; i < N; ++i) {
            cost += (arr[i] - target) * (arr[i] - target);
        }
        ans = min(ans, cost);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")

//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
  // 高速化
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);


    int n;
    cin >> n;
    std::set<string>   s; 
    REP(i, n){
        string x;
        cin >> x; 
        s.insert(x);
    }

        cout <<  s.size()<< "\n"; 

    return 0;



}


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

typedef long long ll;

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

    int n;
    cin>>n;
    int A[n];

    for (int i=0;i<n;++i) cin>>A[i];
    sort(A, A+n);

    double ans = (double)(A[0] + A[1]);
    ans /= 2;

    for (int i=2;i<n;++i){
        ans = (ans + (double)A[i])/2;
    }

    printf ("%.5lf\n", ans);
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N_MAX 131072
#define A(I)  (edge[(I)]/N_MAX)
#define B(I)  (edge[(I)]%N_MAX)
void QSort(int left,int right);
long edge[200001];
int main(void) {
  long N,M,wait_v[100001]={},v4[2],index[100001],j,temp,temp2,a,b,num_v4=0;
  scanf("%ld %ld",&N,&M);
  for(int i=1;i<=M;i++){
    scanf("%ld %ld",&a,&b);
    edge[i]=a*N_MAX+b;
    edge[i+M]=b*N_MAX+a;
    wait_v[a]++;
    wait_v[b]++;    
  }
//  printf("\n");
//  for(int i=1;i<=2*M;i++){printf("%ld %ld\n",A(i),B(i));}
//  printf("\n");  
//  for(int i=1;i<=N;i++){printf("%d\n",wait_v[i]);}
  for(int i=1;i<=N;i++){
    if(wait_v[i]%2==1){
      printf("No");
      return 0;
    }
  }
  for(int i=1;i<=N;i++){
    if(wait_v[i]>=6){
      printf("Yes");
      return 0;
    }else if(wait_v[i]==4){
      if(num_v4==2){
        printf("Yes");
        return 0;
      }
      v4[num_v4++]=i;
    }
  }
  if(num_v4==2){
//    printf("\n%d %d\n",v4[0],v4[1]);
    QSort(1,2*M);
//    printf("\n");
//    for(int i=1;i<=2*M;i++){printf("%ld %ld\n",A(i),B(i));}
    j=1;
    for(int i=1;i<=N;i++){
      while(A(j)!=i){j++;}
      index[i]=j;
    }
//    for(int i=1;i<=N;i++){printf("%d\n",index[i]);}
    for(int i=0;i<3;i++){
      temp=B(index[v4[0]]+i);
      temp2=v4[0];
//      printf("%d %d\n",temp,temp2);
      while((temp!=v4[0])&&(temp!=v4[1])){
        if(B(index[temp])==temp2){
          temp2=temp;
          temp=B(index[temp]+1);
        }
        else{
          temp2=temp;
          temp=B(index[temp]);
        }
//        printf("%d %d\n",temp,temp2);
      }
      if(temp==v4[0]){
        printf("Yes");
        return 0;
      }
    }
  }
  printf("No");
  return 0;
}

void QSort(int left,int right)
{
  int i,j;
  long a_center,temp;
  i=left;
  j=right;
  a_center=edge[(left+right)/2];
  while(1){
      while(edge[i]<a_center){i++;}
      while(a_center<edge[j]){j--;}
      if(i>=j){break;}
      temp=edge[i];
      edge[i]=edge[j];
      edge[j]=temp;
      i++;
      j--;
  }
  if (left<i-1){QSort(left,i-1);} 
  if (j+1<right){QSort(j+1,right);}
}


Measured memory_bytes: 3328
/*suri_kumkaran*/

#include <bits/stdc++.h>

using namespace std;

#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define MP make_pair
#define EB emplace_back
#define endl "\n"
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long

typedef long long int64;
typedef vector<int> VI64;
typedef vector<pair<int,int>> VII64;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;

void fileIO()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
}

int32_t main()
{
	IOS;
	fileIO();
	int T=1;
	//cin>>T;
	while(T--)
	{
		int a,b,v1,v2,t;
		cin>>a>>v1>>b>>v2>>t;
		int dis = abs(a-b) + t*v2;
		int hs = t*v1;
		if(hs>=dis)
			cout<<"YES";
		else
		{
			cout<<"NO";
		}
		
	}
	
	return 0;
}

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

const int x = 101, y = 100001;
long long dp[x][y];
long long c[x], w[x], n, mx_w;

long long solve(int idx, int acc_w) {
    if (idx == n)
        return 0;
    if (dp[idx][acc_w] != -1)
        return dp[idx][acc_w];

    if (w[idx] + acc_w <= mx_w)
        return dp[idx][acc_w] = max(solve(idx + 1, acc_w), c[idx] + solve(idx + 1, acc_w + w[idx]));
    else
        return dp[idx][acc_w] = solve(idx + 1, acc_w);
}
int main() {
    memset(dp, -1, sizeof dp);
    cin >> n >> mx_w;
    for (int i = 0; i < n; i++)
        cin >> w[i] >> c[i];
    cout << solve(0, 0) << '\n';
    return 0;
}


Measured memory_bytes: 79104