akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#define ll long long
#define INF 10000000000000000
#define MOD 998244353
using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    
    int d=b-a;

    int t=0;
    for(int i=0; i<d; i++){
        t+=i;
    }
    
    cout<<t-a<<endl;
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <math.h>

#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
#define ll long long
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

using namespace std;

int main(){
    string s,t;

    cin >> s >> t;

    int size = s.size();
    rep(i,size){
        rotate(s.begin(),s.end()-1,s.end());
        if(s==t){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

int main()
{
    // input
    int a, b, c;
    cin >> a >> b >> c;

    vector<int> inputs = {a, b, c}; 

    // sort input
    sort(inputs.begin(), inputs.end());

    // output
    for (int i = 0; i < inputs.size(); i++)
    {
        cout << inputs[i];
        if (i != inputs.size() - 1) {
            cout << " ";
        } else {
            cout << endl;
        }
    }
    
    return 0;
}



Measured memory_bytes: 3172
# -*- coding: utf-8 -*-

"""
参考：https://img.atcoder.jp/soundhound2018-summer-qual/editorial.pdf
　　　https://ikatakos.com/pot/programming_algorithm/contest_history/atcoder/2018/0707_soundhound2018_summer_qual
"""

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul, xor
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

# ダイクストラ(頂点数, 隣接リスト(0-indexed), 始点)
def dijkstra(N: int, nodes: list, src: int) -> list:
    # 頂点[ある始点からの最短距離]
    # (経路自体を知りたい時はここに前の頂点も持たせる)
    res = [float('inf')] * N
    # スタート位置
    que = [(0, src)]
    res[src] = 0
    # キューが空になるまで
    while len(que) != 0:
        # srcからの距離, 現在のノード
        dist, cur = heappop(que)
        # 出発ノードcurの到着ノードでループ
        for nxt, cost in nodes[cur]:
            # 今回の経路のが短い時
            if res[cur] + cost < res[nxt]:
                res[nxt] = res[cur] + cost
                # 現在の移動距離をキューの優先度として、早い方から先に処理するようにする
                heappush(que, (res[nxt], nxt))
    # ノードsrcからの最短距離リストを返却
    return res

N,M,S,T=MAP()
nodes1=[[] for i in range(N)]
nodes2=[[] for i in range(N)]
for i in range(M):
    u,v,a,b=MAP()
    # 円での始点からダイクストラ用
    nodes1[u-1].append((v-1,a))
    nodes1[v-1].append((u-1,a))
    # スヌークでの終点からダイクストラ用
    nodes2[u-1].append((v-1,b))
    nodes2[v-1].append((u-1,b))

yen=dijkstra(N,nodes1,S-1)
snuk=dijkstra(N,nodes2,T-1)

ans=[0]*N
mn=INF
# 逆順で最小値を取っていけば効率よくやれる
for i in range(N-1, -1, -1):
    ans[i]=mn=min(mn, yen[i]+snuk[i])
# 10^15から引けば答え
for i in range(N):
    print(1000000000000000-ans[i])


Measured memory_bytes: 89024
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define INF 999999999
typedef long long ll;
using namespace std;
int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if(A > B) swap(A, B);
    if(A < C && B > C) {
        puts("Yes");
    }else puts("No");
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int a;
	int b;
	int c;
	
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	
	int i1=a;
	int i2=b;
	int i3=c;
	int i4;
	
	if(a>b){
		i1=b;
		i2=a;
	}
	
	if(i2>c){
		i3=i2;
		i2=c;
	}
	
	i4=i2;
	
	if(i1>i2){
		i2=i1;
		i1=i4;
	}
		
	printf("%d %d %d\n", i1, i2, i3);

	return 0;
}

Measured memory_bytes: 2744
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    int n;
    string s;
    cin>>n>>s;
    int cnt[2]={};
    int cur=0;
    // while(cur<n&&s[cur]==')'){
    //     cnt[0]++;
    //     cur++;
    // }
    while(cur<n){
        if(cnt[1]==0&&s[cur]==')')cnt[0]++;
        else if(s[cur]=='(')cnt[1]--;
        else cnt[1]++;
        cur++;
    }
    rep(i,cnt[0])s='('+s;
    if(cnt[1]>0)rep(i,cnt[1])s='('+s;
    else rep(i,-cnt[1])s+=')';
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A, B;
  cin >> A >> B;
  cout << 6 - A - B << '\n';
  return 0;
}


Measured memory_bytes: 3580
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
	Scanner in = new Scanner(System.in);
	int a = in.nextInt();
	int b = in.nextInt();
        int c = in.nextInt();

	int cnt=0;
	for(int num = a; num<=b; num++){
	    if(c%num==0)cnt++;
	}
	System.out.println(cnt);
    }
}



Measured memory_bytes: 26392
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static int[][][] directedGraph(int n, int[] from, int[] to, int[] cost) {
		int[] cnt = new int[n];
		for (int i : from) cnt[i]++;

		int[][][] g = new int[n][][];
		for (int i=0; i<n; i++) g[i] = new int[cnt[i]][2];
		for (int i=0; i<from.length; i++) {
			int s = from[i];
			int t = to[i];

			g[s][--cnt[s]][0] = t;
			g[s][cnt[s]][1] = cost[i];
		}

		return g;
	}

	static int[] dijkstra(int[][][] g, int source) {
		int n = g.length;

		final int[] d = new int[n];
		Arrays.fill(d, 1<<30);
		d[source] = 0;

		TreeSet<Integer> pQ = new TreeSet<Integer>(new Comparator<Integer>(){
			public int compare(Integer a, Integer b) {
				if (d[a] != d[b]) return d[a] - d[b];
				return a - b;
			}
		});
		pQ.add(source);

		while (!pQ.isEmpty()) {
			int cur = pQ.pollFirst();

			for (int i=0; i<g[cur].length; i++) {
				int next = g[cur][i][0];
				int dist = d[cur] + g[cur][i][1];
				if (dist < d[next]) {
					pQ.remove(next);
					d[next] = dist;
					pQ.add(next);
				}
			}
		}

		return d;
	}

	static void solve() {
		int v = in.nextInt();
		int e = in.nextInt();
		int r = in.nextInt();
		int[] s = new int[e];
		int[] t = new int[e];
		int[] d = new int[e];
		for (int i=0; i<e; i++) {
			s[i] = in.nextInt();
			t[i] = in.nextInt();
			d[i] = in.nextInt();
		}
		int[][][] g = directedGraph(v, s, t, d);
		int[] ans = dijkstra(g, r);
		for (int i=0; i<v; i++) {
			out.println(ans[i] == 1<<30 ? "INF" : ans[i]);
		}
		// dump(ans);
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		solve();
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 300596
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
    int64_t N;
	std::cin >> N;

	double_t rate = 1.08;

	for (int64_t i = 1; i <= 50000; i++) {
		if (floor((double_t)i * rate) == N) {
			std::cout << i << std::endl;
			return;
		}
	}
	std::cout << ":(" << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	solve();
}


Measured memory_bytes: 256
'''input
1700
'''

s = input()

a, b = int(s[:2]), int(s[2:])

pir = False
ant = False

if a and a <= 12:
	pir = True

if b and b <= 12:
	ant = True

if pir and ant:
	print("AMBIGUOUS")
elif pir:
	print("MMYY")
elif ant:
	print("YYMM")
else:
	print("NA")

Measured memory_bytes: 38384
#include <iostream>

using namespace std;

int Asize, Bsize;
int coin;
int coinmax;

inline void PushButtonA()
{
	coin += Asize;
	Asize--;
}

inline void PushButtonB()
{
	coin += Bsize;
	Bsize--;
}

int main()
{
	cin >> Asize >> Bsize;

	for (int i = 0; i < 2; i++)
	{
		if (Asize > Bsize)
			PushButtonA();
		else
			PushButtonB();
	}

	coinmax = coin;

	cout << coinmax;

	return 0;
}

Measured memory_bytes: 256
class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        if n < r:
            return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    MOD = 10 ** 9 + 7
    ans = 0
    comb = Combination(N + 5)
    A.sort(reverse=True)
    for i in range(N-1):
        ans += A[i] * comb(N-1-i, K-1)

    # min求める
    A.sort()
    for i in range(N-1):
        ans -= A[i] * comb(N-1-i, K-1)

    print(ans % MOD)



if __name__ == "__main__":
    main()

Measured memory_bytes: 72104
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;
//UnionFind
struct UnionFind {
    vector<int> par; // iの親の番号

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    UnionFind Uni(n);
    for(int i = 0; i < m; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        a--;
        b--;
        Uni.unite(b, a);
    }
    int nCount = 0;
    for(int i = 0; i < n; i++){
        if(Uni.root(i) == i){
            nCount++;
        }
    }
    printf("%d", nCount - 1);
    return 0;
}


Measured memory_bytes: 3352
process.stdin.resume();
process.stdin.setEncoding('utf8');
// Here your code !
process.stdin.on('data', function (chunk) {
    var lines = chunk.toString().split(' ');
    var A = parseInt(lines[0]);
    var B = parseInt(lines[1]);
    var C = parseInt(lines[2]);
    
    if(A<=C && C<=B)
    {
    console.log("Yes");    
    }else{
    console.log("No");    
    }
});


Measured memory_bytes: 11468
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}






using namespace std;


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

    deque<char> de;

    REP(i,s.size()){
        de.push_back(s[i]);
    }

    int n;
    int rev = 0;
    cin >> n;

    REP(i,n){
        int t;
        cin >> t;

        if(t == 1){
            rev++;
        }else{
            int f;
            char x;
            cin >> f >> x;

            if(f == 1){
                if(rev %2 == 0){
                    de.push_front(x);
                }else{
                    de.push_back(x);
                }
            }else{
                if(rev %2 == 1){
                    de.push_front(x);
                }else{
                    de.push_back(x);
                }
            }
        }
    }


    string ans ="";
    if(rev%2 == 0){
        while(!de.empty()){
            ans += de.front();
            de.pop_front();
        }
    }else{
        while(!de.empty()){
            ans += de.back();
            de.pop_back();
        }
    }

    cout << ans <<endl;
}





Measured memory_bytes: 1412
#include<stdio.h>
int main(void)
{
  char s1[5];
  char s2[5];
  scanf("%s %s",s1,s2);
  for(int i=0;i<3;i++){
    if(s1[i]!=s2[2-i]){
      puts("NO");
      return 0;
    }
  }

  puts("YES");
  return 0;
}


Measured memory_bytes: 1664
#import sys
MOD = 10 ** 9 + 7
#input = sys.stdin.readline
import math

#import bisect

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def main():
#    h,w,a,b = map(int, input().split())
    h,w,k=map(int,input().split())
    s=[]

    a = [[0] * w for i in range(h)]
    for i in range(h):
        s.append(list(input()))
    temp=1
    new=0
    p=[]
#    print(a)
    for i in range(h):
        for j in range(w):
            if s[i][j]==".":
                a[i][j]=temp
            elif s[i][j]=="#" and new!=0:
                temp+=1
                a[i][j]=temp
            else:
                a[i][j]=temp
                new=1
        if new==1:
            temp+=1
        else:
            p.append(i)
        new=0

#    print(p)
    for i in p:
        for j in range(w):
            a[i][j]=0
    for i in range(1,h):
        for j in range(w):
            if a[i][j]==0:
                a[i][j]=a[i-1][j]


    for i in range(h - 2,-1,-1):
        for j in range(w):
            if a[i][j] == 0:
                a[i][j] = a[i + 1][j]

#    print(s)
    for i in range(h):
        print(*a[i])


if __name__ == "__main__":
    main()

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

int main() {
    int n;
    cin >> n;
    int x=0, y=0, q[200005];
    for(int i=0; i<n; i++) {
        cin >> q[i];
        if(q[i]>x) y=x, x=q[i];
        else if(q[i]>y) y=q[i];
    }
    for(int i=0; i<n; i++) {
        if(q[i]==x) cout << y << endl;
        else cout << x << endl;
    }
    return 0; 
}

Measured memory_bytes: 2432
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<max(min(b,d)-max(a,c),(ll)0)<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main( ) {
    //freopen("A.01.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    scanf("%d",&n);
    (n<=999)?printf("%s","ABC"):printf("%s","ABD");
    return 0;
}

Measured memory_bytes: 3696
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <string>
#include <map>
#include <set>

using Dice = std::array<int, 6>;

// d[i] <- d[i + 1]
std::vector<std::vector<int>>
    ways = {{0, 5, 1, 4},
            {0, 4, 1, 5},
            {3, 5, 2, 4},
            {3, 4, 2, 5}};

std::vector<int> dx{-1, 1, 0, 0}, dy{0, 0, 1, -1};

using Route = std::map<std::pair<int, int>, int>;

Route input() {
    int x, y;
    std::cin >> x >> y;

    Dice ds;
    for (auto& d : ds) std::cin >> d;

    std::string s;
    std::cin >> s;

    Route route;
    route[std::make_pair(x, y)] = ds[4];

    for (char c : s) {
        int d;
        for (d = 0; c != "LRBF"[d]; ++d) {}

        const auto& way = ways[d];
        auto tmp = ds[way[0]];
        for (int i = 0; i + 1 < 4; ++i) {
            ds[way[i]] = ds[way[i + 1]];
        }
        ds[way[3]] = tmp;

        x += dx[d], y += dy[d];

        route[std::make_pair(x, y)] = ds[4];
    }
    return route;
}

constexpr int INF = 1 << 30;

bool solve() {
    int n;
    std::cin >> n;
    if (n == 0) return false;

    std::vector<Route> rs(n);
    std::generate(rs.begin(), rs.end(), input);

    std::vector<int> dp(1 << n, -INF);
    dp[0] = 0;

    for (int b = 0; b < (1 << n); ++b) {
        std::set<std::pair<int, int>> filled;
        for (int i = 0; i < n; ++i) {
            if (!((b >> i) & 1)) continue;

            for (const auto& p : rs[i]) {
                filled.insert(p.first);
            }
        }

        for (int i = 0; i < n; ++i) {
            if ((b >> i) & 1) continue;

            int score = 0;
            for (const auto& p : rs[i]) {
                if (filled.count(p.first)) continue;
                score += p.second;
            }

            int nb = b | (1 << i);
            dp[nb] = std::max(dp[nb], dp[b] + score);
        }
    }

    std::cout << dp.back() << std::endl;
    return true;
}

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

    while (solve()) {}

    return 0;
}



Measured memory_bytes: 3360
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>

using namespace std;

int main(){
    long long w, h, x, y;
    cin >> w >> h >> x >> y;
    double ans_area = (double)(w) / 2.0 * h;
    bool multi = (w == x * 2) && (h == y * 2);
    cout << ans_area << ' ' << (int)(multi) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define COUT(x) cout<<(x)<<endl
typedef long long ll;
template<class T> inline void chmax(T& a, T b) {
  if (a < b) a = b;
}

template<class T> inline void chmin(T& a, T b) {
  if (a > b) a = b;
}

const long long INF = 1LL << 60;
int main() {
  int r;
  cin >> r;
  const double pi = 3.1415926535;
  double leng = 2 * pi * r;
  cout << leng << endl;
  return 0;

}

Measured memory_bytes: 3784
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

int n, m;
struct UnionFind {
	int par[201000];
	int rank[201000];

	void init() {
		for (int i = 0; i < 201000; i++) {
			par[i] = i;
			rank[i] = 1;
		}
	}

	int find(int x) {
		if (par[x] == x) return x;
		return par[x] = find(par[x]);
	}

	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;
		if (rank[x] < rank[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (rank[y] == rank[x])rank[x]++;
		}
	}

	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

UnionFind uf;
struct edge {
	ll u;
	ll v;
	ll cost;
};
bool comp(const edge& e1, const edge& e2) {
	return e1.cost < e2.cost;
}

vector<edge> es;

ll kruskal() {
	sort(ALL(es), comp);//edeg.costがちいさい順にソートする（比較式を指定してソート）

	ll res = INF;
	for (int i = 0; i < es.size(); i++) {
		uf.init();//unionfindの初期化
		ll num = 0;
		for (int j = i; j < es.size(); j++) {
			edge e = es[j];
			if (!uf.same(e.u, e.v)) {
				uf.unite(e.u, e.v);
				num = e.cost - es[i].cost;
			}
		}
		bool f = 1;
		for (int j = 0; j < n; j++) {
			if (!uf.same(0, j))f = 0;
		}
		if(f)res = min(res, num);
	}
	return res;
}

int main() {
	while (cin >> n >> m&&n + m) {
		es.clear();
		rep(i, m) {
			ll a, b, w;
			cin >> a >> b >> w;
			a--; b--;
			es.push_back({ a,b,w });
		}
		ll ans = kruskal();
		if (ans == INF)cout << -1 << endl;
		else cout << ans << endl;
	}
}


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


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    ll n, ans = 0; cin>>n;
    ans = n/500 * 1000;
    n %= 500;
    ans += n/5 * 5;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
bool RightAngle(int a,int b,int c)
{
	if((a*a+b*b==c*c||a*a+c*c==b*b)||b*b+c*c==a*a)return true;
	else return false;
}
int main ()
{
	int a,b,c,n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a>>b>>c;
		if(RightAngle(a,b,c))cout<<"YES\n";
		else cout<<"NO\n";
	}
}

Measured memory_bytes: 2976
n, m = map(int,input().split())
s = []
c = []
for _ in range(m):
  x, y = map(int,input().split())
  s.append(x)
  c.append(y)

for i in range(10 ** (n + 1)):
    Str = str(i)

    if len(Str) == n and all([Str[s[j] - 1] == str(c[j]) for j in range(m)]):
        print(Str)
        exit()

print(-1)

Measured memory_bytes: 9080
#include<bits/stdc++.h>
using namespace std;
 
 
int pre[500010],suf[500010];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin>>s;
	int n=s.size()+1;
	for(int i=1;i<n;i++)
		pre[i]=(s[i-1]=='<'?pre[i-1]+1:0);
	for(int i=n-2;i>=0;i--)
		suf[i]=(s[i]=='>'?suf[i+1]+1:0);
	long long int ans=0;
	for(int i=0;i<n;i++)
		ans+=max(pre[i],suf[i]);
	cout<<ans<<endl;
}
//

Measured memory_bytes: 4764
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <fstream>
#include <set>
#include <stack>
#include <queue>
#include <list>
using namespace std;
typedef long long int64;
typedef vector<int> vec;
typedef vector<int64> vec64;
#define db(x) cout << "> " << #x << ": " << x << "\n";
#define ss cout << " ";
#define ct(x) cout << x;
#define nn cout << "\n";
#define cts(x) cout << x << " ";
#define ctn(x) cout << x << "\n";
// // // // // // // // // // // // // // // // // // //
int64 n, k;
vec arr(2e5 + 10);

int64 op(){
    map <int64, int> mp;
    vec nw;
    int64 last = 1;
    mp[1] = 1;
    while (true){
        int64 now = arr[last];
        if (mp[now] <2){
            mp[now]++;
        }
        else{
            last = now;
            break;
        }
        last = now;
    }
    map <int64, bool> mp2;
    while (true){
        if (!mp2[last]){
            mp2[last] = 1;
            nw.push_back(last);
        }
        else{
            break;
        }
        last = arr[last];
    }
    last = 1;
    while (true){
        if (k == 0){
            return (last);
        }
        if (!mp2[last]){
            mp2[last] = 1;
            k--;
        }
        else{
            break;
        }
        last = arr[last];
    }
    // for (auto i: nw){
    //     cts(i);
    // }
    // nn;
    // db(k);
    return (nw[k % nw.size()]);
}
int brute(){
    int cnt = 0;
    int last = 1;
    while (cnt != k){
        cnt++;
        last= arr[last];
    }
    return(last);
}


int main(){
    cin >> n >> k;
    for (int i = 1; i <=n; i++){
        cin >> arr[i];
    }
    ctn(op());
    // int a = op();
    // int b = brute();
    // cts(a);
    // cts(b);
    // ctn(abs(a - b));
    // return 0;
}


Measured memory_bytes: 27744
#import numpy as np
import math
#from fractions import gcd

def main():

    ##get int
    first_input = list(map(lambda x:int(x), input().split(" ")))
    #second_input = list(map(lambda x:int(x), input().split(" ")))

    ##get float
    #first_input = list(map(lambda x:float(x), input().split(" ")))
    #second_input = list(map(lambda x:float(x), input().split(" ")))

    ##get string
    #first_input = input().split(" ")

    K = first_input[0]

    gcd_sum = 0
    for a in range(1,K+1):
        for b in range(1,K+1):
            for c in range(1,K+1):
                gcd_sum = gcd_sum + math.gcd(math.gcd(a,b),c)

    print(gcd_sum)

if __name__ == '__main__':
    main()


Measured memory_bytes: 67736
N = int(input())
S = [input().strip() for _ in range(N)]
C = {"A":0,"B":0,"BA":0}
cnt = 0
for i in range(N):
    s = S[i]
    for j in range(len(s)-2+1):
        if s[j:j+2]=="AB":
            cnt += 1
    if s[0]=="B" and s[-1]=="A":
        C["BA"] += 1
    elif s[0]=="B":
        C["B"] += 1
    elif s[-1]=="A":
        C["A"] += 1
if C["BA"]>0:
    cnt += C["BA"]-1
    if C["B"]>0:
        cnt += 1
        C["B"] -= 1
    if C["A"]>0:
        cnt += 1
        C["A"] -= 1
cnt += min(C["B"],C["A"])
print(cnt)

Measured memory_bytes: 70500
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine().Select(x => x.ToString()).ToArray();
            List<int> list = new List<int>();
            int count = 0;

            foreach(string s in S)
            {
                if (s == "A" || s == "T" || s == "C" || s == "G")
                {
                    count = count + 1;
                }
                else if(count > 0)
                {
                    list.Add(count);
                    count = 0;
                }
            }

            list.Add(count);

            if (list.Count != 0)
            {
                Console.WriteLine(list.Max());
            }
            else
            {
                Console.WriteLine(0);
            }

        }
    }
}


Measured memory_bytes: 13396
s = input()
n = len(s)
chd = [0] * n

cnt = 0
for i in range(n - 1):
    if s[i] == "R":
        cnt += 1
        if s[i + 1] == "L":
            chd[i] += (cnt+1)//2
            chd[i + 1] += cnt//2
            cnt = 0

for i in range(n - 1, 0, -1):
    if s[i] == "L":
        cnt += 1
        if s[i - 1] == "R":
            chd[i] += (cnt+1)//2
            chd[i - 1] += cnt//2
            cnt = 0

print(*chd)


Measured memory_bytes: 6400
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;

struct Info{
	int color,succeed;
};

int main(){

	int n,white,black,tmp;
	Info info;
	stack<int> S;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		info.succeed = 0;
		white = 0;
		black = 0;

		scanf("%d",&tmp);

		if(tmp == 0){
			white++;
			info.color = 0;
			info.succeed = 1;
		}else{
			black++;
			info.color = 1;
			info.succeed = 1;
		}

		for(int i = 2; i <= n; i++){
			scanf("%d",&tmp);

			if(tmp == 0){
				white++;
			}else{
				black++;
			}

			if(i % 2 == 1){
				if(info.color == tmp){
					info.succeed++;
				}else{
					S.push(info.succeed);
					info.succeed = 1;
					info.color = tmp;
				}
			}else{
				if(info.color == tmp){
					info.succeed++;
				}else{
					if(tmp == 0){
						black -= info.succeed;
						white += info.succeed;
						if(!S.empty()){
							info.succeed += S.top();
							S.pop();
						}
						info.color = 0;
						info.succeed++;
					}else{
						black += info.succeed;
						white -= info.succeed;
						if(!S.empty()){
							info.succeed += S.top();
							S.pop();
						}
						info.color = 1;
						info.succeed++;
					}
				}
			}
		}
		while(!S.empty())S.pop();
		printf("%d\n",white);
	}
    return 0;
}

Measured memory_bytes: 2592
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100000

ll V,E;
int color[NUM];
ll num[2];
bool dp[2][NUM];
vector<int> G[NUM];

//2部グラフか判定する(2色で全連結成分を塗れるか)
bool dfs(int node_id,int which){

	color[node_id] = which;
	num[which]++;

	for(int i = 0; i < G[node_id].size(); i++){
		//隣接している頂点が同じ色ならfalse
		if(color[G[node_id][i]] == which)return false;
		//隣接している頂点がまだ塗られていないなら反対色で塗る
		if(color[G[node_id][i]] == -1 && dfs(G[node_id][i],1-which) == false)return false;
	}

	return true; //全ての頂点を塗れたらtrue
}


int main(){

	scanf("%lld %lld",&V,&E);

	for(ll i = 0; i < V; i++){
		color[i] = -1;
	}

	int from,to;
	for(ll loop = 0; loop < E; loop++){
		scanf("%d %d",&from,&to);
		from--;
		to--;
		G[from].push_back(to);
		G[to].push_back(from);
	}

	map<int,int> MAP; //MAP[差] = 差の個数
	ll base_num = 0;

	for(int i = 0; i < V; i++){
		if(color[i] != -1)continue;

		num[0] = 0;
		num[1] = 0;

		if(!dfs(i,0)){ //2部グラフでない
			printf("-1\n");
			return 0;
		}

		MAP[max(num[0],num[1])-min(num[0],num[1])]++;
		base_num += min(num[0],num[1]);
	}

	//任意の個数を作れるかを計算する
	int CURRENT = 0,NEXT = 0;
	for(int i = 0; i < NUM; i++){
		dp[CURRENT][i] = false;
		dp[NEXT][i] = false;
	}



	int add,count,num,mult;

	dp[CURRENT][0] = true;
	dp[NEXT][0] = true;

	for(auto at: MAP){

		add = at.first; //差分
		count = at.second; //add分の差分を反映できる数

		//ダブリングナップザック
		num = count;
		for(int k = 1; num > 0; k *= 2){
			mult = min(k,num);
			for(int diff = NUM-1; diff-add*mult >= 0; diff--){
				if(dp[CURRENT][diff-add*mult] == false)continue;
				dp[NEXT][diff] = true;
			}
			num -= mult;
		}

		swap(CURRENT,NEXT);
	}

	ll ans = 0;
	for(int i = 1; i < NUM; i++){
		if(dp[CURRENT][i]){
			ans = max(ans,(base_num+i)*(V-(base_num+i)));
		}
	}

	printf("%lld\n",ans-E);

	return 0;
}



Measured memory_bytes: 9772
/*
 ID: swagchicken1
 PROG:
 LANG: C++11
 */

#include <iostream>
#include <tuple>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <vector>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <cctype>
#include <climits>
#include <chrono>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vector <int> > vvi;
typedef pair<int, int> pii;
typedef pair < pair < int, int >, int > piii;
typedef pair < pair <int, int > , pair <int, int> > piiii;

#define FOR(i,a,b) for(int i = a; i < b; i ++)
#define RFOR(i,a,b) for(int i = a-1; i >= b; i --)

//#define endl '\n';

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 998244353;

long double PI = 4*atan(1);
long double eps = 1e-12;



int main() {
    //auto start = chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);cin.tie(0);
    //ofstream cout("output.txt");
    //ifstream cin("input.txt");
    int n; cin >> n;
    int a[200050] = {};
    FOR(i,2,n+1)  {
        int sub; cin >> sub;
        a[sub] ++;
    }
    
    FOR(i,1, n+1) {
        cout << a[i] << endl;
    }
    
    
    
    
    //auto stop = chrono::high_resolution_clock::now();
    //auto duration = chrono::duration_cast<chrono::microseconds>(stop - start);
    //cout << duration.count() << endl;
    //cin.close();
    //cout.close();
}


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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

const ll MOD = 1000000007;
const double EPS = 1e-9;

map<ll, ll> d;
priority_queue< Pll, vector<Pll>, greater<Pll> > que;
map<ll, vector<Pll> > edges;

void dijkstra(ll start){
    d[start] = 0;
    que.push(Pll(0, start));

    while(!que.empty()){
        Pll v = que.top(); que.pop();
        if(d.find(v.second) != d.end() && d[v.second] < v.first) continue;
        rep(edges[v.second].size()){
            Pll e = edges[v.second][i];
            if(d.find(e.first) == d.end() || d[e.first] > d[v.second] + e.second){
                d[e.first] = d[v.second] + e.second;
                que.push(Pll(d[e.first], e.first));
            }
        }
    }
}

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

    rep(n){
        ll u, k, c, v;
        cin >> u >> k;
        repp(j, k){
            cin >> v >> c;
            edges[u].emplace_back(v, c);
        }
    }

    dijkstra(0);
    repp(u, n){
        cout << u << " " << d[u] << endl;
    }

}



Measured memory_bytes: 3284
import sys

s1 = list(map(str, input()))

s1_ = list(reversed(s1))
if s1 != s1_:
    print('No')
    sys.exit()

n = len(s1)
# s2 = s1[(n+3)//2-1:]
# s2_ = list(reversed(s2))
# if s2 != s1_:
#     print('No')
#     sys.exit()

s3 = s1[:(n-1)//2]
s3_ = list(reversed(s3))
if s3 != s3_:
    print('No')
    sys.exit()

print('Yes')

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

struct max_flow{
    public:
    struct edge {int to;ll cap;int rev;};
    int V;
    vector<vector<edge>> G;
    vector<int> level,iter;
 
    void init(int v){
        V = v; G.resize(v);
    }
 
    void add_edge(int from, int to, ll cap){
        int a=G[to].size(),b=G[from].size()-1;
        G[from].push_back((edge){to,cap,a});
        G[to].push_back((edge){from,0,b});
    }
 
    void bfs(int s){
        level.assign(V,-1);
        queue<int> que;
        level[s] = 0;
        que.push(s);
        while(!que.empty()){
            int v = que.front();
            que.pop();
            rep(i,G[v].size()){
                edge &e = G[v][i];
                if(e.cap > 0 && level[e.to] < 0){
                    level[e.to] = level[v] + 1;
                    que.push(e.to);
                }
            }
        }
    }
 
    ll dfs(int v, int t, ll f){
        if(v == t) return f;
        for(int &i = iter[v]; i < G[v].size(); i++){
            edge &e = G[v][i];
            if(e.cap > 0 && level[v] < level[e.to]){
                ll d = dfs(e.to,t,min(f,e.cap));
                if(d > 0){
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
 
    ll run(int s, int t){
        ll flow = 0;
        while(1){
            bfs(s);
            if(level[t] < 0) return flow;
            iter.assign(V,0);
            ll tmp;
            while((tmp = dfs(s,t,INF)) > 0){
                flow += tmp;
            }
        }
    }
};

int n;
ll ans=0;
void solve(){
    cin >> n;
    max_flow f;f.init(n+2);
    rep(i,n){
        ll c;
        cin >> c;
        if (c>=0) {
            f.add_edge(i+1,n+1,c);
            ans+=c;
        }
        else f.add_edge(0,i+1,-c);
    }
    rep(i,n){
        int k=2;
        while ((i+1)*k<=n){
            f.add_edge(i+1,k*(i+1),INF);
            k+=1;
        }
    }

    rep(i,n){
        rep(j,f.G[i].size()){
            //cout << i << " " << f.G[i][j].to << " " << f.G[i][j].cap << endl;
        }
    }

    cout << ans-f.run(0,n+1) << endl;
}

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mx = 3005;
const long double ONE = 1;

int n, vis[mx][mx/2];
long double h[mx], t[mx];
long double dp[mx][mx/2];

long double fun(int i, int ta){
    if(i == n) return ONE;

    long double &ans = dp[i][ta];
    if(vis[i][ta]) return ans; vis[i][ta]=1;

    ans = h[i] * ONE * fun(i+1, ta);
    if(ta+1 <= (n/2))
        ans += t[i] * ONE * fun(i+1, ta+1);
    return ans;
}

int main(){

    cin.tie( nullptr );
    ios_base::sync_with_stdio(0);

    cin >> n;
    for(int i=0; i<n; i++)
        cin >> h[i], t[i] = ONE-h[i];

    long double ans = fun(0, 0);
    cout << setprecision(10) << fixed;
    cout << ans << "\n";

    return 0;
}


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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

const int N_MAX = 2048;

struct BIT {
  vi bit;
  BIT(){
    bit.assign(N_MAX+10, 0);
  }
  void add(int a,int w){
    for(int x=a;x<=N_MAX;x+=x&-x)bit[x]+=w;
  }
  int sum(int a){
    int ret = 0;
    for(int x=a;x>0;x-=x&-x)ret += bit[x];
    return ret;
  }
};

struct segBIT {
  vector<BIT> seg;
  segBIT(){
    seg.resize(2*N_MAX);
  }
  void add(int y,int x,int w){
    y += N_MAX-1;
    seg[y].add(x,w);
    while(y>0){
      y = (y-1)/2;
      seg[y].add(x,w);
    }
  }
  bool check(int y,int x){
    y += N_MAX-1;
    int cnt = seg[y].sum(x) - seg[y].sum(x-1);
    return cnt>0;
  }
  int sum(int y,int y2,int x,int x2,int a,int b,int k){
    if(y2<=a || b<=y)return 0;
    if(y<=a && b<=y2){
      return seg[k].sum(x2-1) - seg[k].sum(x-1);
    }else{
      int m = (a+b)/2;
      return sum(y,y2,x,x2,a,m,2*k+1) + sum(y,y2,x,x2,m,b,2*k+2);
    }
  }
  int sum(int y,int y2,int x,int x2){
    return sum(y,y2,x,x2,0,N_MAX,0);
  }
};

segBIT yaiteru, yaketakana;

int h,w,t,q;

int main(){
  scanf("%d%d%d%d",&h,&w,&t,&q);
  queue<pair<int,pii> > yaketaQ;
  while(q--){
    int tt,c,y,x;
    scanf("%d%d%d%d",&tt,&c,&y,&x);
    while(yaketaQ.size()){
      int ttt = yaketaQ.front().first;
      if(ttt>tt)break;
      int y = yaketaQ.front().second.first;
      int x = yaketaQ.front().second.second;
      yaketaQ.pop();
      yaiteru.add(y,x,-1);
      yaketakana.add(y,x,1);
    }
    if(c==0){
      // set
      yaiteru.add(y,x,1);
      yaketaQ.push(make_pair(tt+t,pii(y,x)));
    }else if(c==1){
      // taberu
      if(yaketakana.check(y,x)){
        yaketakana.add(y,x,-1);
      }
    }else{
      // count
      int y2,x2;
      scanf("%d%d",&y2,&x2);
      int ans1 = yaiteru.sum(y,y2+1,x,x2+1);
      int ans2 = yaketakana.sum(y,y2+1,x,x2+1);
      printf("%d %d\n",ans2,ans1);
    }
  }
  return 0;
}

Measured memory_bytes: 70088