akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
    // cout << fixed << setprecision(10) << flush;

    vector<int> ans;
    int n;
    cin >> n;
    while(n != 0){
        vector<int> w(n);
        for(int i=0; i<n; i++){
            cin >> w[i];
        }
    

        // 閉区間 [i, j] じゃなくて半開区間 [i, j) の方が便利そう？
        // dp[i][i] = 0, dp[i][i+1] = 1
        // 場合分け
        // どこかで二分割できて、それぞれの和になっている
        // dp[i][j] = min_{i+1 <= k <= j-1} (dp[i][k] + dp[k][j])
        // 真ん中がすっぽ抜けて、一番上と一番下が打ち消しあう
        // if(dp[i+1][j-1] == 0 && abs(w[i] - w[j-1])){
        //     dp[i][j] = 0;
        // }

        int INF = 1<<30;
        // dp[i][j] は [i, j) で残る個数の最小
        vector<vector<int>> dp(n+1, vector<int>(n+1, INF));
        for(int i=0; i<n; i++){
            dp[i][i] = 0;
            dp[i][i+1] = 1;
        }
        dp[n][n] = 0;

        for(int width=2; width<=n; width++){
            for(int i=0; i+width<=n; i++){
                int j = i + width;
                if(dp[i+1][j-1] == 0 && abs(w[i] - w[j-1]) <= 1){
                    dp[i][j] = 0;
                }
                else{
                    for(int k=i+1; k<=j-1; k++){
                        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
                    }
                }
            }
        }

        ans.push_back(n - dp[0][n]);
    
        cin >> n;
    }

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


Measured memory_bytes: 3560
#include <stdio.h>

int main(void)
{
	int n,a,b,c,d,e,i ;
	char s[100000] ;
	
	scanf("%d %d %d",&n, &a, &b);
	scanf("%s", &s);
	
	c=0;
	e=0;
	d = a + b ;
	
	for(i=0 ; i<n  ; i++){
		
		if(s[i]=='a'){
			if(c < d){
				printf("Yes\n") ;
				c++ ;
			}else{
				printf("No\n") ;
			}
			
		}else if(s[i]=='b'){
			e++ ;
			if(c < d && e <= b){
				printf("Yes\n") ;
				c++ ;
			}else{
				printf("No\n") ;
			}	
		}else{
			printf("No\n") ;
		}
	}

	return 0 ;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll i, temp,t, n,j, ans;
vector<pair<int,int> >V;
bool cond;
char c;
string s;
int main()
{
    //I am Monim, a tiny creature of Allah
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    cin >> t >> j;
    ans = 1;
    V.push_back(make_pair(t,j));
    for(i=1;i<n;i++)
    {
        cin >> t >> j;
        V.push_back(make_pair(t,j));
        if(V[i].first==V[i].second)
        {
            if(V[i-1].first==V[i-1].second)
                ans++;
            else
                ans = 1;
        }
        if(ans>=3)
            cond = true;
    }
    if(cond)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

const ll MOD = 1000000007;

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

  ll ans = 1;
  for (ll i = 1; i <= n; ++i) {
    ans = ans * i % MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;



void main() {
    long n;
    scan(n);

    long[] div;

    for (long d = 1; d*d <= n; d++) {
        if (n % d == 0) {
            div ~= d;

            if (d != n / d) {
                div ~= n / d;
            }
        }
        
    }

    div.sort();

    debug {
        writeln(div);
    }

    long ans;

    int k = div.length.to!int;

    foreach (i ; 0 .. k) {
        long x = n / div[i] - 1;
        if (x > n / (div[i] + 1) && x < (n + div[i] - 1) / div[i]) {
            ans += x;
        }
    }

    writeln(ans);
}























int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {
    writeln(b ? "Yes" : "No");
}

void YES(bool b) {
    writeln(b ? "YES" : "NO");
}

T[] readArr(T)() {
    return readln.split.to!(T[]);
}

T[] readArrByLines(T)(int n) {
    return iota(n).map!(i => readln.chomp.to!T).array;
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 380
use std::io::Read;
use std::cmp::min;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let m: usize = iterator.next().unwrap().parse().unwrap();
    let x: usize = iterator.next().unwrap().parse().unwrap();

    let mut c: Vec<usize> = Vec::new();
    let mut a: Vec<Vec<usize>> = vec![vec![0; m]; n];
    for i in 0..n {
        c.push(iterator.next().unwrap().parse().unwrap());
        for j in 0..m {
            a[i][j] = iterator.next().unwrap().parse().unwrap();
        }
    }

    let mut ans: usize = std::usize::MAX;
    for i in 0..(2_i64.pow(n as u32)) {
        let bin: Vec<char> = format!("{:0>1$b}", i, n).chars().collect();

        let mut cost: usize = 0;
        let mut sum: Vec<usize> = vec![0; m];
        for j in 0..n {
            if bin[j] == '0' {
                continue;
            }
            cost += c[j];
            for k in 0..m {
                sum[k] += a[j][k];
            }
        }
        if sum.iter().all(|it| *it >= x) {
            ans = min(ans, cost);
        }
    }

    if ans == std::usize::MAX {
        return "-1".to_string();
    }
    return ans.to_string()
}


Measured memory_bytes: 2272
from collections import deque

H, W = map(int, input().split())
grid = [input() for i in range(H)]

# 初期の黒('#')の位置からの距離
dist = [[-1]*W for _ in range(H)]

# '#'の位置をキューに追加（＝今回はこれが複数あるので、複数スタートとなる）
black_cells = deque()
for h in range(H):
    for w in range(W):
        if grid[h][w] == '#':
            black_cells.append((h, w))
            dist[h][w] = 0

d = 0
while black_cells:
    # キューとして使うのでpop()ではなくpopleft()
    h, w = black_cells.popleft()
    d = dist[h][w]
    for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        new_h = h + dy
        new_w = w + dx
        if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
            continue
        if dist[new_h][new_w] == -1:  # セルが白('.')であるのと同義
            dist[new_h][new_w] = d+1
            black_cells.append((new_h, new_w))
print(d)

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

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


Measured memory_bytes: 3636
while True:
    x = str(input())
    if x == '0':
        break
    x = str(x)
    a = x[1:].count('A')
    b = x[1:].count('B')
    if a < 10:
        b = b + 1
    elif b < 10:
        a = a + 1
    elif a >= 10 and b >= 10 and a > b:
        a = a + 1
    elif a >= 10 and b>= 10 and b > a:
        b = b + 1
    print(a, b)


Measured memory_bytes: 5556
using System;
public class A
{
    public static void Main()
    {
        string Hs = Console.ReadLine();
        string Ws = Console.ReadLine();
        String Ns = Console.ReadLine();
        int H = int.Parse(Hs);
        int W = int.Parse(Ws);
        int N = int.Parse(Ns);
        float P = 0;
        int Big = 0;
        if (H >= W)
        {
            Big = H;
        }
        else
        {
            Big = W;
        }
        
        P = (float)N / Big;
        P = (float)Math.Ceiling(P);
        Console.WriteLine(P);
        
    }
}


Measured memory_bytes: 13140
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) x.begin(), x.end()
typedef tuple<int, int, int> t3;

void solve(){
	int n, a[110];
	scanf("%d", &n);
	for(int i=1;i<=n;i++) scanf("%d", a+i);
	int ans = 0, now = 0;
	for(int i=1;i<=n;i++) {
		++now;
		if(i == n || a[i] != a[i+1]) {
			ans += now / 2;
			now = 0;
		}
	}
	printf("%d\n", ans);
}

int main(){
	int Tc = 1; //scanf("%d", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
using namespace std;
#define LL long long 
#define LD long double
bool f[100005];
int n,v[10];
int main()
{
	v[1]=100;v[2]=101;v[3]=102;
	v[4]=103;v[5]=104;v[6]=105;
	cin>>n;
	f[0]=1;
	for(int i=1;i<=6;i++)
		for(int j=v[i];j<=n;j++)
			f[j]|=f[j-v[i]];
	printf("%d\n",f[n]);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

typedef string::const_iterator State;
class ParseError {
    public:
        static void inputError(void){
            cerr << "error!" << endl;
            exit(1);
        }
};

int number(State &begin){
    int ret = 0;
    while(isdigit(*begin)){
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }
    return ret;
}

int calc(State &begin){
    if(*begin != '['){
        ParseError::inputError();
    }
    if(*(++begin) != '[') return (number(begin)/2 + 1);
    vector<int> a;
    while(*begin == '['){
        a.pb(calc(begin));
        begin++;
    }
    sort(all(a));
    int ans = 0;
    REP(i, a.size()/2+1) ans += a[i];
    return ans;
}

signed main(){
    int n;
    cin >> n;
    REP(i, n){
        string s;
        cin >> s;

        State begin = s.begin();
        int ans = calc(begin);
        cout << ans << endl;
    }
}



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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  ll x,y,z;
  cin>>x>>y>>z;
  cout<<min(x+y, min(y+z, z+x))<<endl;
  return 0;
}


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

int main(){
   int w, h, x, y;
   cin >> w >> h >> x >> y;
   double ans = (double)w * h / 2;
   int num = (w == x * 2 && h == y * 2)? 1 : 0;
   printf("%.10f %d\n", ans, num);
   return 0;
}


Measured memory_bytes: 3704
import java.util.*;
 
public class Main{
	public static void main(String[] args) {
	    Scanner sc=new Scanner(System.in);
      	for (int i=0; i<5; i++){
			int n=sc.nextInt();
          	if (n==0){
              System.out.print(i+1);
              return;
            }
        }		
	}
}

Measured memory_bytes: 35688
#include<stdio.h>
#include<string.h>
#define N 101

struct node{ char suit;
             char value;
            };

void selectsort(struct node *,int);
void bubblesort(struct node *,int);
void print(struct node *,int);
int stable(struct node *,struct node *,int);

int main(){
  struct node n1[N],n2[N];
  int n,i;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c%c",&n1[i].suit,&n1[i].value);
  }
  for(i=0;i<n;i++) n2[i]=n1[i];

  bubblesort(n1,n);
  selectsort(n2,n);

  print(n1,n);
  printf("Stable\n");
  print(n2,n);
  if(stable(n1,n2,n)==1) printf("Stable");
  else printf("Not stable");
  printf("\n");


  return 0;
}
void bubblesort(struct node *n1,int n ){
  int i,j;
  struct node temp;  
  for(i=0;i<n;i++){
    for(j=n-1;j>=i+1;j--){
      if(n1[j].value<n1[j-1].value){
        temp=n1[j];
	n1[j]=n1[j-1];
	n1[j-1]=temp;
      }
    }
  }
}

void selectsort(struct node *n2,int n){
  int i,j,min;
  struct node temp;
  for(i=0;i<n;i++){
    min=i;
    for(j=i;j<n;j++){
      if(n2[j].value<n2[min].value) min =j;     
    }
    temp=n2[i];
    n2[i]=n2[min];
    n2[min] =temp;
  }
}

void print(struct node *m,int n){
  int i;
  for(i=0;i<n;i++){
      printf("%c%c",m[i].suit,m[i].value);
      if(i!=n-1) printf(" ");
  }
   printf("\n");
}
int stable(struct node *n1,struct node *n2,int n){
  int i;
  for(i=0;i<n;i++){
    if(n1[i].suit!=n2[i].suit){
      // printf("%c %c\n",n1[i].suit,n2[i].suit);
      return 0;
    }
  }
  return 1;
  
}



Measured memory_bytes: 2100
n, m, c = map(int, input().split())
b = [int(num) for num in input().split()]
a = []
for i in range(n):
    a_r = [int(num) for num in input().split()]
    a.append(a_r)

count = 0
for an in a :
    sum = 0
    for j in range(m) :
        sum += an[j]*b[j]
    if (sum + c) > 0 :
        count += 1
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string> //文字列
#include <iomanip> //doubleの桁数指定 setprecision()
#include <list> //前後に数値を入れれる配列
#include <map> //map
#include <vector> //vecror

#define REP(i,m,n) for(ll i = (ll) (m);i < (ll) (n);i++) //forの短縮
#define rep(i,n) REP(i,0,n) //REPが0の時
#define ll long long int

using namespace std;

double PI = acos(-1); //円周率
ll mod = 1e9 + 7;


//提出コード↓

ll x,cnt;
ll mny = 100;


int main() {
	cin >> x;
	while (x > mny) {
		mny *= 1.01;
		cnt++;
	}
	cout << cnt << endl;
	
	return 0;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

// 
const int INF = 987654321;
int n, A, B, C;
vi v;

int dfs(int pos, int a, int b, int c) {
	if (pos == n) {
		int ret = abs(a-A) + abs(b-B) + abs(c-C) - 30;
		return (min(a,min(b,c)) == 0 ? INF : ret);
	}

	int ret = INF;
	ret = min(ret, dfs(pos+1,a,b,c));
	ret = min(ret, dfs(pos+1,a+v[pos], b, c) + 10);
	ret = min(ret, dfs(pos+1,a,b+v[pos], c) + 10);
	ret = min(ret, dfs(pos+1,a,b,c+v[pos]) + 10);
	return ret;
}

int main(void) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//freopen("in.txt", "r", stdin);
	cin >> n >> A >> B >> C;
	v.resize(n);
	rep(i,0,n) {
		cin >> v[i];
	}
	cout << dfs(0,0,0,0) << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //ArrayList<Integer> A = new ArrayList<Integer>();

        int n = sc.nextInt();
        int[] B = new int[n];
        long sum = 0;
        for (int i=0; i<n; i++) {
            B[i] = sc.nextInt();
        }
        Arrays.sort(B);
        for (int i=0; i<n; i++) {
            sum += B[i];
        }
        System.out.print(B[0]);
        System.out.print(" ");
        System.out.print(B[n-1]);
        System.out.print(" ");
        System.out.println(sum);

    }
}


Measured memory_bytes: 40964
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*************** using variables ***************/
int n;
int a[100005];
map<int, int> mp;
LL ans = 0;
/**********************************************/

int main(){
    cin >> n;
    REP(i, n){
        cin >> a[i];
    }
    
    REP(i, n){
        mp[a[i]] += 1;
    }

    for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
        if(itr->first != itr->second){
            if(itr->first > itr->second){
                ans += itr->second;
            }else{
                ans += min(itr->second - itr->first, itr->second);    // 値を表示
            }
        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 5120
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;

int main() {
    ll n,a,b;
    std::cin >> n>>a>>b;
    
    string s;
    std::cin >> s;
    ll c = 0;
    ll bc = 0;
    for (int i = 0; i < n; i++) {
        if(s[i]=='c'){
            std::cout << "No" << std::endl;
            continue;
        }
        if(s[i]=='a'){
            if(c<a+b){
                std::cout << "Yes" << std::endl;
                c++;
            }else{
                std::cout << "No" << std::endl;
            }
        }
        if(s[i]=='b'){
            if(c<a+b&&bc<b){
                std::cout << "Yes" << std::endl;
                c++;bc++;
            }else{
                std::cout << "No" << std::endl;
            }
        }
    }
}



Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef long long ll;
#define endl '\n'

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

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

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

	int N; cin >> N;
	vector<int> ans(N, 0);
	for (int i = 1; i < N; i++) {
		int a; cin >> a;
		ans[a - 1]++;
	}

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

	return 0;
}

Measured memory_bytes: 3996
#include <iostream>
int main() {
	int a, b;
	std::cin >> a >> b;
	if (a <= 0 && 0 <= b)
		std::cout << "Zero" << std::endl;
	else if (a > 0 && b > 0)
		std::cout << "Positive" << std::endl;
	else if (b < 0) {
		int n = -1 * (a - b - 1);
		if (n % 2 == 0)
			std::cout << "Positive" << std::endl;
		else
			std::cout << "Negative" << std::endl;
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
typedef long long ll;

const int Inf=0x3f3f3f3f;
int n,a,b,Mb=Inf;
ll Sum;

int main()
{
	for(scanf("%d",&n);n--;)
	{
		scanf("%d%d",&a,&b),Sum+=b;
		if(a>b)Mb=std::min(Mb,b);
	}
	Sum-=Mb;
	if(Mb==Inf)Sum=0;
	printf("%lld\n",Sum);
	return 0;
}

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

int main(){
    int k;
    string result={};
    string s;
    bool f=0;
cin >>k >>s;
if(s.size()>k){
    s.erase(k);
    cout <<s;
    f=1;
}
else cout <<s <<endl;

if(f==1){
 string p="...";   
    cout << p <<endl;
}
return 0;
}


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

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

  int ans = 0;
  vector<int> count(n, 1);
  vector<int> red(n);
  red[0] = 1;

  for(int i=0;i<m;i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    if(red[x]) red[y] = 1;
    count[x]--;
    count[y]++;
    if(!count[x]) red[x] = 0;
  }

  for(int i=0;i<n;i++) {
    if(red[i]) ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 1024
// Starting with the name of Allah

#include <bits/stdc++.h>
#define ll long long
#define nl endl
#define Nayon ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define gcd(a,b)         __gcd(a,b)
#define lcm(a,b)         (a/gcd(a,b))*b
#define v_sum(a)         accumulate(a.begin(),a.end(),0)
#define v_max(a)         *max_element(a.begin(),a.end())
#define v_min(a)         *min_element(a.begin(),a.end())
#define v_uni(a)         a.erase(unique(a.begin(),a.end()),a.end())

using namespace std;





int main()
{
	Nayon;
	ll a,b,c,d,x,y,z,mx1,mx2,mx3,mx4;
	cin>>a>>b>>c>>d;
	mx1=a*c;
	mx2=a*d;
	mx3=b*c;
	mx4=b*d;
	if(mx1>mx2 && mx1>mx3 && mx1>mx4){
		cout<<mx1;
	}
	else if(mx2>mx1 && mx2>mx3 && mx2>mx4){
		cout<<mx2;
	}
	else if(mx3>mx1 && mx3>mx2 && mx3>mx4){
		cout<<mx3;
	}
	else{
		cout<<mx4;
	}
	return 0;
}


//Happy Coding..........

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>

using namespace std;

template<typename T>inline T get(){T x;cin>>x;return x;}

int main()
{
    int x = get<int>(), a = get<int>();
    if (x < a)
        cout << 0 << endl;
    else
        cout << 10 << endl;

    return 0;
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  int sum =0;
  for (auto &x: p){
    cin >> x;
    sum += x;
  }
  int max = *std::max_element(p.begin(), p.end());
  cout << (sum - max /2);
}


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

int main(void){
    ll n, ans = 1;
    cin >> n;
    for (int i=1; i<=n; i++){
        ans *= i;
        ans %= (int)(pow(10, 9) + 7);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]

for y in range(h):
  for x in range(w):
    if s[y][x]=='.':
      cnt=0
      for dy,dx in [[0,1],[0,-1],[1,0],[-1,0],[1,1],[-1,1],[1,-1],[-1,-1]]:
        ny=y+dy
        nx=x+dx
        if 0<=ny<h and 0<=nx<w and s[ny][nx]=='#':
          cnt+=1
      s[y][x]=str(cnt)

for i in s:
  print(''.join(i))

Measured memory_bytes: 3188
using System;
using System.Collections.Generic;


namespace ConsoleApplication30
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string[] str = Console.ReadLine().Split(' ');
                int n = int.Parse(str[0]);
                int x = int.Parse(str[1]);               

                if (n == 0 && x == 0)
                {
                    break;
                }
                int count = 0;
                for (int i = 1; i <= n - 2; i++)
                {
                    for (int j = i + 1; j <= n - 1; j++)
                    {
                        for (int k = j + 1; k <= n; k++)
                        {
                            if (x == i + j + k)
                            {
                                count++;
                            }
                        }
                    }
                }
                Console.WriteLine("{0}", count);
            }
        }
    }
}

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

#define ll long long
#define pll pair<ll,ll> 

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

	ll n, m, k;
	cin>>n>>m>>k;
	ll A[n+1]={};
	ll B[m+1]={};
	for(ll i=1;i<=n;i++){
		cin>>A[i];
		A[i]+=A[i-1];
	}
		
	for(ll j=1;j<=m;j++){
		cin>>B[j];
		B[j]+=B[j-1];
	}
	
	ll ans=0;
	ll x=n, y=0;
	
	while(x>=0 && y<=m){
		if(A[x]+B[y]<=k){
			ans=max(ans, x+y);
			y++;
		} else{
			x--;
		}
	}


	
	


	cout<<ans<<endl;
}


Measured memory_bytes: 6736
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define cl clear
#define in insert
#define er erase
#define S second
#define F first
#define endl "\n" 
#define all(v) (v).begin(), (v).end()
#define getbit(x, i) ((x >> i)&1)
#define sz(v) (v).size()
#define fr(i, a, b, d) for(ll i = a; i < b; i+= d)
#define frr(i, a, b, d) for(ll i = a; i >= b; i -= d)
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define pll pair < ll, ll >
#define pii pair < int, int >
#define trace1(x)                cerr << #x << ": " << x << "\n";
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << "\n";
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << "\n";
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << "\n";
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << "\n";
using namespace std;
const ll N = 305;
const ll M = 1e9 + 7;
ll graph[N][N];
ll dis[N][N];
ll dp[N][N];
int main(){
	ll n, m, D;
	cin >> n >> m >> D;
	for(ll i = 0; i <= n; i++) for(ll j = 0; j <= n; j++) dis[i][j] = 1e15;
	for(ll i = 0; i <= n; i++) dis[i][i] = 0;	
	for(ll i = 0; i < m; i++){
		ll x, y, c;
		cin >> x >> y >> c;
		if(c <= D){
			graph[x][y] = c;
			graph[y][x] = c;
			dis[x][y] = c;
			dis[y][x] = c;
		}
	}
	for(ll k = 1; k <= n; k++) 
		for(ll i = 1; i <= n; i++)
			for(ll j = 1; j <= n; j++)
				dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
	
	for(ll i = 1; i <= n; i++)
			for(ll j = 1; j <= n; j++) dp[i][j] = (dis[i][j] <= D ? 0 : 400);

	for(ll k = 1; k <= n; k++) 
		for(ll i = 1; i <= n; i++)
			for(ll j = 1; j <= n; j++)
				dp[i][j] = min(dp[i][j] , dp[i][k] + 1 + dp[k][j]);
	ll q;
	cin >> q;
	while(q--){
		ll x, y;
		cin >> x >> y;
		if(dp[x][y] == 400) cout << -1 << "\n";
		else cout << dp[x][y] << "\n";
	}

	return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <set>
#include <map>
 
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
 
int h, w, n, md;
bool g[51][51] = {};
 
void answer() {
    ll res = 0;
    ll base = 1;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (g[i][j]) res = (res+base) % md;
            base = 2*base % md;
        }
    }
    cout << "! " << res << endl;
}
 
using T = tuple<int, int, int, int>;
map<T, int> buf;
int que(int ax, int ay, int bx, int by) {
    bx--; by--;
    if (buf.count(T(ax, ay, bx, by))) return buf[T(ax, ay, bx, by)];
    cout << "? " << ay << " " << ax << " " << by << " " << bx << endl;
    int p;
    cin >> p;
    return buf[T(ax, ay, bx, by)] = p;
}


ll rand_int(ll l, ll r) { //[l, r]
    using D = uniform_int_distribution<ll>;
    static random_device rd;
    static mt19937 gen(rd());
    return D(l, r)(gen);
}

int dfs(int y, int l, int r, int nm = -1) {
    if (nm == -1) {
        nm = que(l, y, r, y+1);
    }
    if (nm == 0) return 0;
    if (nm == r-l) {
        for (int i = l; i < r; i++) {
            g[y][i] = true;
        }
        return nm;
    }
    int md = (l+r+rand_int(0, 1))/2;
    
        int buf = dfs(y, l, md);
        dfs(y, md, r, nm-buf);




    return nm;
}
 
int main() {
    ios::sync_with_stdio(0);
    cin >> h >> w >> n >> md;
    for (int i = 0; i < h; i++) {
/*        for (int j = 0; j < w; j++) {
            g[i][j] = (que(j, i, j+1, i+1) != 0);
        }*/
        dfs(i, 0, w);
    }
    answer();
    return 0;
}
 

Measured memory_bytes: 848
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define mp make_pair
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
const int N = 5e5 + 1;
int n , m , fact[N] , inv[N];
int mult(ll a , ll b){
	return (a*b)%M;
}
int fp(ll a , ll b){
	int res = 1;
	while(b > 0){
		if(b&1)res = mult(res , a);
		b/=2;
		a = mult(a , a);
	}
	return res;
}
int nck(ll n , ll k){
	//if(k > n)return 1;
	return mult(fact[n] , mult(inv[n-k] , inv[k]));
}
int npk(ll n , ll k){
	return mult(fact[n] , inv[n-k]);
}
int main(){
	cin >> n >> m;
	fact[0] = inv[0] = 1;
	for (int i = 1; i <= N-1; ++i){
		fact[i] = mult(fact[i-1] , i);
		inv[i] = fp(fact[i] , M-2);
	}
	int res = 0;
	//cout << nck(5 , 2) <<endl;
	for (int i = 0; i <= n; ++i){
		int x = mult(nck(n , i) , npk(m-i , n-i));
		if(i&1) res = (res - x + M)%M;
		else res = (res + x)%M;
		//cout << res <<endl;
	}
	cout << mult(npk(m,n) , res);
	

}	

Measured memory_bytes: 7544
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(v) v.bigin(),v.end()
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
#define R(a) a=sqrt(a)
#define POW(a,b) a=pow(a,b)
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main(){
    FAST;
    ll k,x;
    cin>>k>>x;
    if(500*k>=x){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    
}



Measured memory_bytes: 3612
n = int(input())
h = [int(i) for i in input().split()]
inf = 10**9
dp = [inf] * n
dp[0] = 0
for i in range(n-1):
    dp[i+1] = min(dp[i] + abs(h[i+1] - h[i]), dp[i+1])
    if i < n-2:
        dp[i+2] = min(dp[i] + abs(h[i+2] - h[i]), dp[i+2])

print(dp[n-1])


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

#define ll long long
#define ldb long double
#define rep(i, x, n, j) for(int i=x;i<(int)n;i+=j)
#define F first
#define S second
#define per(i, x, n, j) for(int i=(int)n-1;i>=0;i-=j)
#define all(v) v.begin(),v.end()
#define sz(a) (int)a.size()

const int N = 2000100;
const ll MOD = 1e9+7;
const ll inf = 1e18+5;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;

int _;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, k; cin >> n >> k;
	string s; cin >> s;
	/*if(k==2 || k==5){
		ll counter=1ll;
		rep(i,0,sz(s),1) if((s[i]-'0')%k == 0) ++counter;
		cout << (((counter-1)*counter)/2ll);
		exit(0);
	}*/
	if (10%k == 0) { // 2,5
    ll ans = 0;
    rep(r,0,n,1) {
      if ((s[r]-'0') % k == 0) {
        ans += r+1;
      }
    }
    cout << ans << endl;
    return 0;
  }
	else{
		vector<ll> d(n+1, 0ll);
		ll mul = 1ll;
		map<ll, ll> mp;
		mp[0]++;
		for(int i=n-1; i>=0; --i){
			ll h = (s[i]-'0');
			d[i] = ((h*mul)+d[i+1])%k;
			mp[d[i]]++;
			mul*=10ll; mul%=k;
		}
		/*
		vector<int> cnt(k);
		ll ans = 0;
		for (int i = n; i >= 0; --i) {
			ans += cnt[d[i]];
			cnt[d[i]]++;
		}
		cout << ans << endl;*/
		ll ans = 0ll;
		for(auto &x: mp)
			ans += ((x.S-1)*x.S)/2ll;

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


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

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


Measured memory_bytes: 3632
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    ll A, B, K;
    cin >> A >> B >> K;
    cout << max(0LL, A - K) << ' ' << max(0LL, B - max(0LL, K - A)) << endl;
}

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

using namespace std;

int main()
{
	long N;
	cin >> N;
	
	vector<long> a(N + 1);
	for (int i = 0; i < N; i++)
	{
		cin >> a[i + 1];
	}
	
	vector<long> b(N + 1);
	
	// 大きい値から処理する
	for (long i = N; i >= 1; i--)
	{
		int sum = 0;
		
		// i以外の倍数をの総和
		for (int j = i + i; j <= N; j += i)
		{
			sum += b[j];
		}
		
		sum %= 2;
		// ボールの総数を2で割った余りの数がa[i]でない場合に
		if (sum != a[i])
		{
			// 現在のiの箱にボールをいれます。
			b[i] = 1;
		}
	}
	
	vector<long> answer;
	
	// 1の倍数からNの倍数の箱
	for (long i = 1; i <= N; i++)
	{
		// ボールがある場合
		if (b[i])
		{
			// ボールを入れる箱に書かれた整数を格納する
			answer.push_back(i);
		}
	}
	
	// 出力
	cout << answer.size() << endl;
	for (int i = 0; i < answer.size(); i++)
	{
		cout << answer[i] << endl;
	}
	
	return 0;
}


Measured memory_bytes: 4980
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int in;
    for(int i=s.length()-1; i>=0; --i){
        string str = {s[i-2], s[i-1], s[i]};
        if(753 > atoi(str.c_str()))
            in = min(in, (753 - atoi(str.c_str())));
        else
            in = min(in, (atoi(str.c_str())-753));
    }
    cout << in << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

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

    cout << (n-1)*(m-1) << endl;
}

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] card = new long[N];
        long sum = 0;
        for(int i=0;i<N;i++){
        	card[i]=sc.nextInt();
        	sum+=card[i];
        }
        long ans = 1_000_000_000_000_000L;//large enough
        long snuke = 0;
        long raccoon = sum;
        for(int i=0;i<N-1;i++){
        	snuke += card[i];
        	raccoon -= card[i];
        	if(Math.abs(snuke-raccoon)<ans) ans = Math.abs(snuke-raccoon);
        }
        
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 65652
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
template <typename Int, Int MOD, int N>
struct comb_util {
	std::array<Int, N + 1> fc, ifc;

	comb_util() {
		fc[0] = 1;
		for (int i = 1; i <= N; i++) fc[i] = fc[i - 1] * i % MOD;
		ifc[N] = inv(fc[N]);
		for (int i = N - 1; i >= 0; i--) ifc[i] = ifc[i + 1] * (i + 1) % MOD;
	}

	Int fact(Int n) { return fc[n]; }

	Int inv_fact(Int n) { return ifc[n]; }

	Int inv(Int n) { return pow(n, MOD - 2); }

	Int pow(Int n, Int a) {
		Int res = 1, exp = n;
		for (; a; a /= 2) {
			if (a & 1) res = res * exp % MOD;
			exp = exp * exp % MOD;
		}
		return res;
	}

	Int perm(Int n, Int r) {
		if (r < 0 || n < r)
			return 0;
		else
			return fc[n] * ifc[n - r] % MOD;
	}

	Int binom(Int n, Int r) {
		if (n < 0 || r < 0 || n < r) return 0;
		return fc[n] * ifc[r] % MOD * ifc[n - r] % MOD;
	}

	Int homo(Int n, Int r) {
		if (n < 0 || r < 0) return 0;
		return r == 0 ? 1 : binom(n + r - 1, r);
	}
};

using comb = comb_util<long long, 1000000007, 300000>;
comb cb;
int add(int &a, const int &b) {
	a += b;
	if (a >= MOD)a -= MOD;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M, K;
	cin >> N >> M >> K;
	int coef = cb.binom(N*M - 2, K - 2);
	int sum = 0;

	int tmp = 0;
	for (int i = 1; i < N; i++) {
		add(tmp, (i * (N - i)) % MOD);
	}
	tmp = (((tmp * M) % MOD)*M) % MOD;
	add(sum, tmp);

	tmp = 0;
	for (int i = 1; i < M; i++) {
		add(tmp, (i * (M - i)) % MOD);
	}
	tmp = (((tmp * N) % MOD)*N) % MOD;
	add(sum, tmp);

	int res = (sum * coef) % MOD;



	cout << res << endl;
}

Measured memory_bytes: 5120
#include<iostream>
#include<cstdio>
#include<string>
#include<math.h>

using namespace std;

int main()
{
	long N,K,V;
	cin >> N >>K;
	V=0;
	while(N>=pow(K,V)){
		V++;
	}		
	cout<<V<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define eb(t) emplace_back(t)
typedef long long ll;
typedef long long unsigned int llu;
ll INF = 1000000009;
ll MOD = 1000000007;

bool b[110];

void solve(){

    ll n,k;
    cin >> n >> k;
    rep(i,110){
        b[i]=false;
    }
    rep(i,k){
        ll d;
        cin >> d;
        rep(j,d){
            ll t;
            cin >> t;
            b[t-1]=true;
        }
    }

    ll ans =0;
    rep(i,n){
        if(!b[i]) ans++;
    }

    cout << ans << endl;


}

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


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


int main(){
  int n;
  cin >> n;
  if ( n %111 == 0) cout << n << endl;
  else cout <<n + (111-n%111) << endl;
  }

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int main()
{     int n,m,i,j,k,sum=0;
      cin>>n;
      for(i=1;i<=n;i++){
      	int x,y;
      	scanf("%d%d",&x,&y);
      	sum+=(y-x+1);
      }
      cout<<sum<<endl;
	  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> Pint;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    map<ll, ll> mp;
    rep(0, i, N)
    {
        cin >> A.at(i);
        mp[A.at(i)]++;
    }

    sort(all(A));
    vector<ll> memo(1000100, 0);

    for (auto m : mp)
    {
        if (m.second > 1)
        {
            ll c = m.first;
            while (c <= 1000000)
            {
                memo.at(c) = 1;
                c += m.first;
            }
        }
    }

    ll ans = 0;
    rep(0, i, N)
    {
        if (memo.at(A.at(i)) == 0)
        {
            ans++;
            ll c = A.at(i);
            while (c <= 1000000)
            {
                memo.at(c) = 1;
                c += A.at(i);
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 25076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M; cin >> N >> M;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    priority_queue<ll> pq;
    rep(i,N) pq.push(A[i]);
    rep(i,M){
        ll a=pq.top(); pq.pop();
        pq.push(a/2);
    }
    ll ans=0;
    while(!pq.empty()){
        ans+=pq.top(); pq.pop();
    }
    cout << ans << endl;
}

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

using namespace std;

const int N = 1e3 + 5;
vector<int> adj[N];
int vis[N] , n;

bool cycle(int node , int lim) {
    if (vis[node])
        return vis[node] == 1;

    if (!lim)
        return 0;

    vis[node] = 1;
    for (int c : adj[node])
        if (cycle(c , lim - 1))
            return 1;
    vis[node] = 2;

    return 0;
}

vector<int> sec;
void find_ans(int node , int lim) {
    if (vis[node] == 2)
        return;

    if (vis[node] == 1) {
        for (int c : sec)
            cout << c << '\n';
        exit(0);
    }

    if (!lim)
        return;

    sec.push_back(node);
    vis[node] = 1;

    for (int c : adj[node])
        find_ans(c , lim - 1);

    vis[node] = 2;
    sec.pop_back();
}

bool good(int lim) {
    for (int st = 1 ; st <= n ; st++) {
        memset(vis , 0 , sizeof vis);
        if (cycle(st , lim))
            return 1;
    }
    return 0;
}

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

    int m;
    cin >> n >> m;

    while (m--) {
        int u , v;
        cin >> u >> v;
        adj[u].push_back(v);
    }

    int l = 2 , r = n , ans = -1;
    while (l <= r) {
        int mid = (l + r) / 2;
        if (good(mid)) {
            ans = mid;
            r = mid - 1;
        } else {
            l = mid + 1;
        }
    }

    cout << ans;
    if (~ans) {
        cout << '\n';
        for (int st = 1 ; st <= n ; st++) {
            memset(vis , 0 , sizeof vis);
            if (cycle(st , ans)) {
                memset(vis , 0 , sizeof vis);
                find_ans(st , ans);
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3708
#include <stdio.h>

int main(void)
{
    int n, i, a, b, c, d;

    while (scanf("%d", &n) != EOF) {
        i = 0;
        for (a = 0; a <= 9; ++a)
            for (b = 0; b <= 9; ++b)
                for (c = 0; c <= 9; ++c)
                    for (d = 0; d <= 9; ++d)
                        if (a + b + c + d == n)
                            ++i;
        printf("%d\n", i);
    }

    return 0;
}

Measured memory_bytes: 596
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {
  int H, W;
  cin >> H >> W;

  char a[H][W];

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

  int x = 0;
  int y = 0;
  a[0][0] = '.';
  while (true) {
    if (x < W - 1 && a[y][x + 1] == '#')
      ++x;
    else if (y < H - 1 && a[y + 1][x] == '#')
      ++y;
    else
      break;
    a[y][x] = '.';
    if (x == W - 1 && y == H - 1)
      break;
  }

  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (a[i][j] == '#') {
        cout << "Impossible" << endl;
        return 0;
      }
    }
  }

  cout << "Possible" << endl;

  return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        q: usize,
        h: usize,
        s: usize,
        d: usize,
        mut n: usize
    }
    n *= 4;
    let mut ord = vec![(1, q * 8), (2, h * 4), (4, s * 2), (8, d)];
    ord.sort_by_key(|x| x.1);
    let mut ans = 0;
    for &(i, x) in &ord {
        ans += n / i * (x * i / 8);
        n %= i;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
def hantei(a):
    a = str(a)
    a_keta_sum = 0
    for i in range(len(a)):
        a_keta_sum += int(a[i])
    return a_keta_sum


N, A, B = list(map(int,input().split()))
ans = 0

for i in range (N+1):
    if A <= hantei(i) and hantei(i) <= B:
        ans += i

print(ans)

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

using namespace std;

typedef long long int lli;

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

    int n, d, ans = 0;
    lli x[10][10];

    cin >> n >> d;
    for (int i=0; i<n; i++) {
        for (int j=0; j<d; j++) cin >> x[i][j];
    }

    for (int i=0; i<n; i++) {
        for (int j=i+1; j<n; j++) {
            lli dist = 0;
            for (int k=0; k<d; k++) {
                dist += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }

            lli tmp = 0;
            while (dist >= tmp*tmp) {
                if (dist == tmp*tmp) ans++;
                tmp++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256