akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
ll A[MAX_N];

void solve() {
	cin >> N;
	rep(i, 0, N) cin >> A[i];
	sort(A, A + N);
	ll tmp = 0;
	while(A[N - 1] >= N) {
		ll S = 0;
		rep(i, 0, N) S += A[i] / N;
		rep(i, 0, N) A[i] = A[i] - (A[i] / N * N) + (S - A[i] / N);
		tmp += S;
		sort(A, A + N);
	}
	cout << tmp << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int start=100;
    double r=1.05;
    double result;
    int result1;
    int n,i;
    result1 = start;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        result=result1*r;
        result1=result;
        if(!(result-result1==0)){
            result1++;
        }
    }
    printf("%d\n",result1*1000);
    return 0;
}

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

ans = 0

for i in range(1,7):
    if n%(10**i)==n:
        #print(i)
        break

if i ==1:
    ans = n
elif i ==2:
    ans = 9
elif i ==3:
    ans = 9+(n-99)
elif i ==4:
    ans = 909
elif i ==5:
    ans = 909+(n-9999)
elif i ==6:
    ans = 90909

print(ans)

Measured memory_bytes: 3060
class Unionfind:

    def __init__(self,n):
        self.uf = [-1]*n

    def find(self,x):
        if self.uf[x] < 0:
            return x
        else:
            self.uf[x] = self.find(self.uf[x])
            return self.uf[x]

    def same(self,x,y):
        return self.find(x) == self.find(y)

    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.uf[x] > self.uf[y]:
            x,y = y,x
        self.uf[x] += self.uf[y]
        self.uf[y] = x
        return True

    def size(self,x):
        x = self.find(x)
        return -self.uf[x]

n,m,k = map(int,input().split())
un = Unionfind(n)
fre = [1]*n
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    un.union(a,b)
    fre[a] += 1
    fre[b] += 1

ans = [un.size(i)-fre[i] for i in range(n)]

for i in range(k):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    if un.same(a,b):
        ans[a] -= 1
        ans[b] -= 1
print(*ans)
    

Measured memory_bytes: 14128
n, m = map(int, input().split())
pairs = []
for i in range(m):
    a, b = map(int, input().split())
    pairs.append((a, b))
pairs.sort(key=lambda x: x[1], reverse=True)

res = 1

mina = pairs[0][0]
for i in range(m):
    a, b = pairs[i]
    if b <= mina:
        res += 1
        mina = a
    mina = max(mina, a)

print(res)


Measured memory_bytes: 18172
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace ABC121C_EnergyDrinkCollector
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var input1 = Console.ReadLine().Split(' ').Select(elem => int.Parse(elem)).ToArray();
            var N = input1[0];
            var M = input1[1];

            List<Item> itemList = new List<Item>();
            for (int i = 0; i < N; i++)
            {
                var input2 = Console.ReadLine().Split(' ').Select(elem => int.Parse(elem)).ToArray();
                itemList.Add(new Item { UnitPrice = input2[0], Stock = input2[1] });
            }

            decimal needPrice = 0;
            var haveCount = 0;
            foreach (var item in itemList.OrderBy(elem => elem.UnitPrice))
            {
                var need = M - haveCount;
                if (need < item.Stock)
                {
                    // 足りたので終了
                    haveCount += need;
                    needPrice += need * item.UnitPrice;
                    break;
                }
                else
                {
                    // 足りないので全部買って次の安い店へ
                    haveCount += item.Stock;
                    needPrice += item.Stock * item.UnitPrice;
                }
            }

            Console.WriteLine(needPrice);
        }
    }

    class Item
    {
        public int Stock { get; set; }
        public decimal UnitPrice { get; set; }
    }
}


Measured memory_bytes: 25908
import fractions
n = int(input())
l = list(map(int,input().split()))

left = []
right = []
left.append(1)
right.append(1)
left.append(l[0])
right.append(l[-1])
le = l[0]
ri = l[-1]
for i in range(1,n-1):
    le = fractions.gcd(le,l[i])
    left.append(le)
    ri = fractions.gcd(ri,l[-i-1])
    right.append(ri)
m = []
for i in range(1,n-1):
    m.append(fractions.gcd(left[i],right[-i-1]))
m.append(left[-1])
m.append(right[-1])
print(max(m))


Measured memory_bytes: 16572
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int N;
    cin >> N;
    int n = N%10;
    if(n == 3){
        cout << "bon" << endl;
    }else if(n == 0 || n == 1 || n == 6 || n == 8){
        cout << "pon" << endl;
    }else{
        cout << "hon" << endl;
    }
}

Measured memory_bytes: 3612
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


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

  ll ans;
  if (2 * n > m){
    ans = m / 2;
  }else{
    ll x = m - (2 * n);
    ans = n + (x / 4);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX = 1e5+5;
bool isPrime[MAX+5];
int ok[MAX+5];

void init() {
	for(int i=0;i<MAX;i++) {
		isPrime[i] = true;
		ok[i] = 0;
	}
}

void eratos() {
	isPrime[1] = false;
	for(int key=2;key<MAX;key++) {
		if(isPrime[key] == true) {
			for(int j=2*key;j<MAX;j+=key) {
				isPrime[j] = false;
			}
		}
	}
	for(int key=3;key<MAX;key+=2) {
		if(isPrime[key] == true && isPrime[(key+1)/2] == true) {
			ok[key] = 1;
		}
	}
	for(int key=3;key<MAX;key++) {
		ok[key] = ok[key] + ok[key-1];
	}
}


int main() {
	init();
	eratos();
	int q;
	cin >> q;
	for(int i=0;i<q;i++) {
		int l, r;
		cin >> l >> r;
		cout << ok[r] - ok[l-1] << endl;
	}
}

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

using namespace std;
typedef long long ll;

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

int main(int argc, char const *argv[]) {
  int n;
  std::string s;
  std::cin >> n;
  std::cin >> s;
  REP(i,s.size()) {
    REP(j,n) {
      s[i]++;
      if (s[i]=='[') s[i] = 'A';
    }
  }
  std::cout << s << '\n';
  return 0;
}


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

ll h,w;
char s[55][55];
ll dist[55][55];
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

int main(){
    cin >> h >> w;
    ll countw=0;
    for(ll i=0;i<h;i++){
        for(ll j=0;j<w;j++){
            cin >> s[i][j];
            if(s[i][j]=='.') countw++;
            dist[i][j]=-1;
        }
    }
    queue<pair<ll,ll>> que;
    dist[0][0]=1;
    que.push(make_pair(0,0));
    while(!que.empty()){
        auto v=que.front();
        que.pop();
        for(ll i=0;i<4;i++){
            pair<ll,ll> nv;
            nv.first=v.first+dx[i];
            nv.second=v.second+dy[i];
            if(nv.first<0||nv.first>=h||nv.second<0||nv.second>=w) continue;
            if(s[nv.first][nv.second]=='#'||dist[nv.first][nv.second]!=-1) continue;
            dist[nv.first][nv.second]=dist[v.first][v.second]+1;
            que.push(nv);
        }
    }
    ll res;
    if(dist[h-1][w-1]==-1) res=-1;
    else res=countw-dist[h-1][w-1];
    cout << res << endl;
}


Measured memory_bytes: 3596
# DP[i][j] = i番目まででjの体力を減らせる場合の最小の魔力消費

h, n = map(int, input().split())
a, b= [0]*n, [0]*n
for i in range(n):
    aa, bb = map(int, input().split())
    a[i], b[i] = aa, bb

dp = [[float('inf')] * (h+1) for _ in range(n+1)]
dp[0][0] = 0

for i in range(n):
    for j in range(h+1):
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        idx = min(j+a[i], h)
        dp[i+1][idx] = min(dp[i+1][idx], dp[i+1][j] + b[i])

print(dp[n][h])

Measured memory_bytes: 290312
#include<algorithm>
#include<cstdio>
#include<map>
#define mxn 1000010
using namespace std;
const int hs[]={13,29,53,71,103,1999,13577,50177,341569,992863},iv[]={11,87,57,2792,10759,284652,16312892,8982012,583800912,300380820},md[]={71,97,151,6007,23087,616489,19260817,19491001,998244353,1000000007};
long long ans;
int n,sl,fh;
char s[mxn];
struct hsh
{
	int s[10],X[10];
}a[mxn];
struct vl
{
	int s[10];
	bool operator <(const vl &x)const
	{
		for(int i=0;i<10;++i)
			if(s[i]!=x.s[i])
				return s[i]<x.s[i];
		return 0;
	}
}N,nw,tmp;
map<vl,int> mp;
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
void upd(int &x,int y,int mod) {x+=y; if(x>=mod) x-=mod;}
void add(hsh &x) {for(int i=0;i<10;++i) upd(x.s[i],x.X[i],md[i]);}
void plu(hsh &x) {for(int i=0;i<10;++i) upd(x.s[i],md[i]-x.X[i],md[i]);}
void mul(hsh &x) {for(int i=0;i<10;++i) x.X[i]=1ll*hs[i]*x.X[i]%md[i];}
void del(hsh &x) {for(int i=0;i<10;++i) x.X[i]=1ll*iv[i]*x.X[i]%md[i];}
int main()
{
	n=rd();scanf("%s",s+1);
	for(int i=0;i<10;++i) a[0].X[i]=1;
	for(int i=1;i<=n;++i)
	{
		a[i]=a[i-1];
		if(s[i]=='+') add(a[i]);
		else if(s[i]=='-') plu(a[i]);
		else if(s[i]=='>') mul(a[i]);
		else del(a[i]);
	}
	for(int j=0;j<10;++j) N.s[j]=a[n].s[j];
	for(int i=n;i;--i)
	{
		for(int j=0;j<10;++j)
		{
			nw.s[j]=a[i].s[j];
			tmp.s[j]=(a[i-1].s[j]+1ll*N.s[j]*a[i-1].X[j])%md[j];
		}
		mp[nw]++;ans+=mp[tmp];
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main(){
  int n, p[100]; cin >> n;
  for(int i = 0; i < n; i++) cin >> p[i];
  sort(p, p+n);
  
  int a = 0, b = 0;
  for(int j = 0; j < n; j++){
      if(j%2 == 0) a += p[n-1-j];
      else b += p[n-1-j];
  }
  
  cout << a - b << endl;
  return 0;
}

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



def main():
    x, k, d = map(int, input().split())
    
    x = abs(x)
    if abs(x) > k*d:
        ans = abs(x-k*d)
    else:
        if x == 0:
            if k%2:
                ans = d
            else:
                ans = 0
        else:
            key = x//d
            k -= key
            x -= key*d
            if k%2:
                ans = min(abs(x-d), abs(x+d))
            else:
                ans = abs(x)
    print(ans)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 8936
import java.util.*;
class Main{
  public static void main(String args[]){
    Scanner sc =new Scanner(System.in);
    int n= sc.nextInt();
    int a[]= new int[n];
    double sum=0;
    for(int i=0;i<n;i++){
      a[i]=sc.nextInt();
      sum+=1.0/a[i];
    }
    System.out.println(1.0/sum);
  }
}

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

using namespace std;
#define fordebug int hogeko;cin>>hogeko;
#define DEKAI 1000000007
#define INF 1000000000
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define floot10 cout<<fixed<<setprecision(10);
#define int long long
signed main(){
	int dp[100001];
	int n;
	cin>>n;
	int a[100000];
	lp(i,n){
		dp[i]=INF;
	}
	lp(i,n){
		cin>>a[i];
	}
	dp[0]=0;
	lp(i,n-1){
		dp[i+1]=min(dp[i]+abs(a[i]-a[i+1]),dp[i+1]);
		if(i!=n-2) dp[i+2]=min(dp[i]+abs(a[i]-a[i+2]),dp[i+2]);
	}
	cout<<dp[n-1]<<endl;
	return 0;
}



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

#define boost ios::sync_with_stdio(0); cin.tie(0);
#define int long long
const int N = 1e5 + 10;
const int MOD = 1e9 + 7;

int32_t main(){
	boost;
	int n , k;

	int a[10] = {0};

	cin >> n >> k;

	int temp;
	set<int> s;
	for(int i = 0 ; i < k ; ++i){
		cin >> temp;
		s.insert(temp);
		a[temp]++;
	}

	int num = n;
	while(1){
		string hell = to_string(num);
		bool flag = true;
		for(int i = 0 ; i < hell.size() ; ++i){
			if( s.find(hell[i] - '0') != s.end() ){
				flag = false;
				break;
			}
		}
		if(num >= n && flag){
			cout << num;
			return 0;
		}
		num++;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    int a,b,k;
    cin>>a>>b>>k;
    int atmp=a,btmp=b;
    vector<int> s;
    while(k>0){
        k--;
        if(atmp>b or btmp<0)continue;
        s.push_back(atmp);
        atmp++;
        s.push_back(btmp);
        btmp--;
    }
    set<int> tmp(s.begin(),s.end());
    vector<int> ans(tmp.begin(),tmp.end());
    REP(i,ans.size())cout<<ans.at(i)<<endl;
}

Measured memory_bytes: 256
a, b = map(int, input().split())
def calc(x):
    rtn = 0
    i = 1
    while i<=x:
        i *= 2
        if i==2:
            if x%4==1 or x%4==2:
                rtn += 1
            continue
        if x%i<i//2:
            continue
        rtn += ((x%i-i//2+1)%2)*(i//2)
    return rtn
if a==0:
    print(calc(b))
else:
    print(calc(a-1)^calc(b))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
 
#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed(x) fixed<<setprecision(x)
using namespace std;
using pii=pair<int,int>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
bool inLine(int x,int y,int mx,int my){return (x>=0&&y>=0&&x<mx&&y<my);}
const lol inf=(1LL<<62);
const int MOD=(1e9)+7;
const int mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
lol n,m,k;
int lcm(int l,int r);
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int w,h,c;
  cin >>w>>h>>c;
  lol ans=0;
  int sai=lcm(w,h);
  ans=w/sai;
  ans*=h/sai;
  cout <<ans*c<<'\n';

  return (0);
}
int lcm(int l,int r){
  if(l<r) swap(l,r);
  int p=l%r;
  while(p!=0){
    l=r;
    r=p;
    p=l%r;
  }
  return r;
}


Measured memory_bytes: 3216
from collections import deque


def main():
    N, M = map(int, input().split())
    e = [[] for _ in range(N)]
    input_edges = [0]*N
    for i in range(M):
        u, v = map(int, input().split())
        u -= 1
        v -= 1
        e[u].append(v)
        input_edges[v] += 1
    queue = deque()
    dp = [-1] * N
    for i, input_edge in enumerate(input_edges):
        if input_edge == 0:
            queue.appendleft(i)
            dp[i] = 0
    topological_sorted = []
    while queue:
        v = queue.pop()
        topological_sorted.append(v)
        for other_side in e[v]:
            input_edges[other_side] -= 1
            if input_edges[other_side] == 0:
                queue.appendleft(other_side)
    for v in topological_sorted:
        for other_side in e[v]:
            dp[other_side] = max(dp[v] + 1, dp[other_side])
    print(max(dp))


if __name__ == "__main__":
    main()


Measured memory_bytes: 23936
#include <iostream>
using namespace std;
int main(){
  long long n,k;cin>>n>>k;
  long long ans = k;
  //k/2から全探索
  long long sm = 0;
  long long mn = k/2;
  long long mx = k;
  long long ce = (mx+mn)/2;
  //cout << mn << " " << mx << endl;
  while(mx-mn > 1){
    //cout << mn <<  " " <<mx << endl;
    //1番目がce円もらえると仮定する
    sm = 0;
    sm += ce;
    long long nw = 1;
    long long wan = ce;
    while(nw < n && wan/2){
      sm += wan/2;
      wan/=2;
      nw++;
    }
    if(k<sm){
      mx = ce;
    }else{
      mn = ce;
    }
    ce = (mx+mn)/2;
  }
  sm = mx;
  long long nw = 1;
  long long wan = mx;
  while(nw < n && wan/2){
    sm += wan/2;wan/=2;
    nw++;
  }

  if(sm <= k){
    ce = mx;
  }
  cout << ce << endl;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
int n,a[100009],b[100009];
int main() {
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++)
		if(i%2==1) b[1]+=a[i];
		else b[1]-=a[i];
	cout<<b[1]<<' ';
	for(int i=2;i<=n;i++) {
		b[i]=2*a[i-1]-b[i-1];
		cout<<b[i]<<' ';
	}
	return 0;
}

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

int main(){
    int n,y;
    cin >> n >> y;
    int a = -1;
    int b = -1;
    int c = -1;
    bool flag = false;
    for(int i = 0;i<=5000;i++){
        for(int j = 0;j<= 2500;j++){
            if(y/1000 - n == 4*i+9*j && (y-5000*i-10000*j)/1000 >= 0){
                a = j;
                b = i;
                c = (y-5000*i-10000*j)/1000;
                flag = true;
                break;
            }
        }
        if(flag) break;
    }

    cout << a << " " << b << " " << c << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

int f_dir[2][4] = {{-1, 0, 1, 0}, {0, 1, 0, -1}}; //↑→↓←
int e_dir[2][8] = {{-1, -1, -1, 0, 0, 1, 1, 1}, {-1, 0, 1, -1, 1, -1, 0, 1}};
bool is_in_field(int y, int x, int h, int w){
  return (y >= 0 && y < h && x >= 0 && x < w);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  int k;
  cin >> k;
  string s = "";
  for(int i = 0; i < k; i++){
    s += "ACL";
  }
  cout << s << endl;

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 3676
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}


fn main(){
    let line = read_as_vec::<u64>();
    let (a, b, t) = (line[0], line[1], line[2]);

    println!("{}", t/a*b);
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//CODE

void solve(void)
{
  int A,B;
  cin>>A>>B;
  if(A > 12)
  {
    cout<<B<<endl;
  }
  else if(A >= 6)
  {
    cout<<B/2<<endl;
  }
  else
  {
    cout<<0<<endl;
  }
  
  
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T lcm(T x,T y){
    return x*y/GCD(x,y);
}
long long Pow(long long base,long long x){
    if (x == 0) return 1;
    if (x%2 == 1) return (base*Pow(base,x-1))%MOD;
    long long y = Pow(base, x/2);
    return y*y%MOD;
}
long long fac[100010],finv[100010],inv[100010];

const int MAX = 1010;
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int 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;
    }
}

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

int main(){
    long long n,k; cin >> n >> k;
    long long ans = 1;
    for(int i = 0; i < n; i++){
        ans *= k;
        ans %= MOD;
    }
    cout << ans << endl;
}
  




Measured memory_bytes: 3112
#include<stdio.h>
int a,b,c,x;
int answer(void){
  int ans=0;
  for(int loop=0;loop<=a;++loop){
    for(int loop2=0;loop2<=b;++loop2){
      for(int loop3=0;loop3<=c;++loop3){
        int tmp=loop*500+loop2*100+loop3*50;
        if(tmp==x){
          ans++;
        }
      }
    }
  }
  return ans;
}
int main(void){
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  scanf("%d",&x);
  int ans=answer();
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
int a[15];
int n, ans, res, cnt;
int main() {
	ans = 1;
	res = 1;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		if(a[i] % 2 == 0)cnt++;
	}
	for(int i = 1; i <= n; i++)ans = ans * 3;
	for(int i = 1; i <= cnt; i++)res = res * 2;
	printf("%d\n", ans - res);
	return 0;
}

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

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

vector<int> divisor(int N) {
    vector<int> RES;
    for (int I = 1; I*I <= N; I++) {
        if (N%I == 0) {
            RES.push_back(I);
            if (I != N/I) RES.push_back(N/I);
        }
    }
    return RES;
}

int main() {
    int n; cin >> n;
    ll k; cin >> k;
    int a[n]; rep(i,n) cin >> a[i];

    int s = 0;
    rep(i,n) s += a[i];
    vector<int> d = divisor(s);

    int ans = 1;

    for (auto g : d) {
        vector<int> r;
        rep(i,n) r.push_back(a[i]%g);
        sort(r.begin(),r.end());

        int sum_r = 0; rep(i,n) sum_r += r[i];
        int cmax = sum_r / g;
        int c = 0;
        rep(i,n-cmax) c += r[i];
        if ((ll)c <= k) ans = max(g,ans);
    }

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

Measured memory_bytes: 3612
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>

#define x first
#define y second

using namespace std;

typedef long long LL;
typedef pair<int,int>PII;

const int maxn = 2e5 + 10;

int t,n,m;

int main(void) {
	
	string str;
	cin >> str;
	if(str == "ABC") puts("ARC") ;
	else puts("ABC");

	return 0;	
} 

Measured memory_bytes: 3624
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>
#include <unordered_set>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

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

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

ll max(ll a, ll b) {return a > b ? a : b;}
//ll max(int a, ll b) {return a > b ? a : b;}
//ll max(ll a, int b) {return a > b ? a : b;}
//ll max(int a, int b) {return a > b ? a : b;}

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

int n, m;
long long q;
vector<long long> b;
int go[500000];
long long ans[500000];
long long sub[500000];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    b.push_back(n);
    for (int i = 0; i < m; i++)
    {
        cin >> q;
        while (b.size() && q <= b.back())
        {
            b.pop_back();
        }
        b.push_back(q);
    }
    reverse(all(b));
    sub[0] = 1;
    for (int i = 0; i < b.size(); i++)
    {
        int l = i, r = b.size();
        long long k = b[i];
        while (1)
        {
            int l = i, r = b.size();
            while (l + 1 < r)
            {
                int mid = (l + r) / 2;
                if (b[mid] <= k)
                    r = mid;
                else
                    l = mid;
            }
            if (r == b.size())
            {
                //cout << i << endl;
                ans[k] += sub[i];
                break;
            }
            long long rr = k / b[r];
            long long md = k % b[r];
            sub[r] += sub[i] * (k / b[r]);
            //cout << r << " " << b[r] << " " << sub[i] * (k / b[r]) << endl;
            k = md;
        }
    }
    for (int i = n - 1; i >= 0; i--)
    {
        ans[i] = ans[i + 1] + ans[i];
    }
    for (int i = 1; i <= n; i++)
    {
        cout << ans[i] << " ";
    }
}


Measured memory_bytes: 7540
/*
AUTHOR:

'|.   '|'     |     '||    ||'     |     '|.   '|'
 |'|   |     |||     |||  |||     |||     |'|   | 
 | '|. |    |  ||    |'|..'||    |  ||    | '|. | 
 |   |||   .''''|.   | '|' ||   .''''|.   |   ||| 
.|.   '|  .|.  .||. .|. | .||. .|.  .||. .|.   '| 

*/



#include <bits/stdc++.h>

using namespace std;
#define endl "\n"
#define ll int
#define ld long double
#define pll pair<long long,long long>
#define vll vector<long long>
#define all(x) x.begin(),x.end()
#define pb push_back
#define Fo(i,k,n) for(ll i=k;i<=n;i+=1)
#define deb(x) cout << #x << "=" << x << endl
#define in(a,n) Fo( i,0,n-1)cin>>a[i]
#define out(a,n) Fo( i,0,n-1)cout<<a[i]<<" ";cout<<endl
#define IOS     ios_base::sync_with_stdio(0); cin.tie(NULL);
const ll N=2*1e6+1;


int main() {
	IOS
    ll t=1;
	//cin>>t;	
	
	Fo(_,1,t)
	{
	   //cout<<"Case #"<<_<<": ";
	   
	   string s,tt;
	   cin>>s>>tt;
	   
	   bool yes=1;
	   
	   Fo(i,0,s.size()-1)
	   {
	       if(s[i]!=tt[i])yes=0;
	   }
	   
	   if(yes)cout<<"Yes";
	   else cout<<"No";
	 
	  
	   
	   
	   
	   
	   
	   cout<<endl;
	  
	}
	
    
}

Measured memory_bytes: 3612
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) {

		Scanner scanner=new Scanner(System.in);

		int n=scanner.nextInt();
		int k=scanner.nextInt();
		Map<Integer,Integer> data= new TreeMap<Integer,Integer>();

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

			int buf=scanner.nextInt();

			if(data.containsKey(buf)) {
				data.put(buf,data.get(buf)+1);
			}else {
				data.put(buf,1);
			}
		}

		int ret=data.size()>k?data.size()-k:0;

		List<Integer> sortedKeys = new ArrayList<Integer>(data.values());
		Collections.sort(sortedKeys);

		int result=0;
		for(Integer i:sortedKeys) {

			if(ret==0) {
				break;
			}


			result+=i;
			ret--;



		}

		System.out.println(result);


		scanner.close();

	}
}

Measured memory_bytes: 102040
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, L;
  cin >> N >> L;
  vector<string> S(N);
  for(int i=0;i<N;i++){
    cin >> S.at(i);
  }
  
  sort(S.begin() ,S.end());
  string mi;
  for(int i=0;i<N;i++){
    mi+=S.at(i);
  }
  cout << mi << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int N = 200003, mod = 1000000007;

int n, m;
int a[N];
char s[N];

int main()
{
    n = gi();
    double ans = acos(-1) * 2 * n;
    printf("%.13lf\n", ans);
    return 0;
}


Measured memory_bytes: 3812
s = input()

for i in range(len(s)):
  s = s[:-1]
  half_f = s[int(len(s)/2):]
  half_l = s[:int(len(s)/2)]
  
  if len(s)%2 == 0 and half_f == half_l :
    print(len(s))
    break

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    int h[n];
    rep(i, 0, n) {
        cin >> h[i];
    }
    int mxh = 0;
    rep(i, 0, n - 1) {
        mxh = max(mxh, h[i]);
        if (mxh - h[i + 1] >= 2) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll dp[505][10005];

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

	vector<int> v(m);
	rep(i, m) cin >> v[i];

	vector<P> p(n);
	rep(i, n) {
		cin >> p[i].first >> p[i].second;
	}

	sort(v.begin(), v.end(), greater<int>());

	int d[10005];
	memset(d, 0, sizeof(d));
	REP(i, 1, m + 1) {
		d[i] += d[i-1] + v[i-1];
	}

	// cout << d[m] << endl;
	// cout << " N : " << n << endl;
	// rep(i, n) cout << p[i].first << " " << p[i].second << endl;

	memset(dp, 0, sizeof(dp));
	rep(i, 505) {
		rep(j, 10005) dp[i][j]  = -1;
	}

	dp[0][0] = 0;

	rep(i, n) {
		rep(j, m + 1) {
			dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
		}

		rep(j, m) {
			if(dp[i][j] == -1) continue;

			int id = j + p[i].first;
			id = min(id, m);
			// cout << id << " <-" << j + p[i].first << " " << j << " " << p[i].first << " " << dp[i][j] + (d[id] - d[j]) - p[i].second << endl;
			dp[i+1][id] = max(dp[i+1][id], max(dp[i][id], dp[i][j] + (d[id] - d[j]) - p[i].second));
		}

		// cout << "--- i:" << i << endl;
		// rep(j, n + 1) {
		// 	rep(k, m + 1) {
		// 		if(dp[j][k] == -1) continue;
		// 		cout << dp[j][k] << " ";
		// 	}
		// 	cout << endl;
		// }
	}


	ll ans = 0;
	rep(i, n + 1) {
		rep(j, m + 1) {
			ans = max(ans, dp[i][j]);
			// cout << dp[i][j] << " ";
		}
		// cout << endl;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 40768
#include<cmath>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<cstring>
#define ll long long
#define clean(a,i) memset(a,i,sizeof(a))
using namespace std;

template <typename T>
inline void read(T &x){
    x=0;T k=1;char c=getchar();
    while(c>'9'||c<'0'){if(c=='-')k=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=k;
}

char s[105];
int main(){
	cin>>s;
	int po=0,ans=0;
	for(int i=0;i<=100;i++)
	{
		if(s[i]=='C')po=1;
		if(po==1&&s[i]=='F'){ans=1;break;}
	}
	if(ans==1)printf("Yes\n");
	else printf("No\n");
	
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * メインクラス
 *
 */
public class Main {

	/**
	 * メインメソッド
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {

		// 標準入力を取得
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();

		long N = Long.parseLong(line.split(" ")[0]);
		long M = Long.parseLong(line.split(" ")[1]);

		List<Long> xs = new ArrayList<Long>();
		line = br.readLine();
		for (String s : line.split(" ")) {
			xs.add(Long.valueOf(s));
		}
		Collections.sort(xs);

		List<Long> diffs = new ArrayList<Long>();
		for (int i=1; i< xs.size(); i++) {
			diffs.add(xs.get(i) - xs.get(i-1));
		}
		Collections.sort(diffs);

		long result = 0;
		for (int i=0; i < diffs.size()- (N-1); i++){
			result += diffs.get(i);
		}

		System.out.println(result);
	}
}

Measured memory_bytes: 49244
def main():
    H, W = [int(ele) for ele in input().split()]
    frame = ["#"] * (W+2)
    canvas = [[str(ele) for ele in input().split()] for _ in range(H)]

    print("".join(frame))
    for ele in canvas:
        print("#" + "".join(ele) + "#")

    print("".join(frame))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
//  main.cpp
//  20191220lesson
//
//  Created by Priscilla Leang on 12/20/19.
//  Copyright  2019 Priscilla Leang. All rights reserved.
//

#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int a, b;
    int n = 0;
    //Cormen-- the best friend of man
//    cin>> a>>b;
//    int walks [a];
//    int makeups[a];
//    for (int i = 0; i< a; i++){
//        cin>> walks[i];
//        makeups[i] = 0;
//    }
//    for (int i = 1; i< a; i+=2){
//        int m = 0;
//        int h = b -walks [i-1];
//        int g = b-walks[i+1];
//        if (h>=g){
//            m = h;
//        }
//        else {
//            m = g;
//        }
//        m-=walks[i];
//        if (m <=0){
//            continue;
//        }
//        else{
//            n+=m;
//            walks[i]+=m;
//        }
//    }
//    cout << endl;
//    cout << n<< endl;
//    for (int i = 0; i< a; i++){
//        cout << walks[i]<< " ";
//    }
    //fifty -fifty
    int samecharacter = 0;
    char input[4];
    for (int i = 0; i< 4; i++){
        cin>> input[i];
    }
    for (int i = 0; i< 4; i++){
        for (int j = i+1; j< 4; j++){
            if (input[i] == input[j]){
                samecharacter++;
            }
        }
    }
    if (samecharacter == 2){
        cout << "Yes";
    }
    else {
        cout << "No";
    }
    
    
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())
l = sorted(list(map(int,input().split())))
ans = 0
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      if l[i]+l[j]>l[k] and l[i]!=l[j] and l[j]!=l[k] and l[k]!=l[i]:
        ans += 1
print(ans)

Measured memory_bytes: 9216
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

#define MAX_N 10000
struct edge{ int to, cap, rev; };

vector<edge> G[MAX_N];
int level[MAX_N]; // sからの距離
int iter[MAX_N];  // どこまで調べ終わったか

void add_edge(int from, int to, int cap) {
  G[from].PB({to, cap, (int)G[to].size()});
  G[to].PB({from, 0, (int)G[from].size()-1});
}

void bfs(int s) {
  memset(level, -1, sizeof(level));
  queue<int> que;
  level[s] = 0;
  que.push(s);
  while(que.size()) {
    int v = que.front(); que.pop();
    for(auto i: G[v]) {
      if(i.cap > 0 && level[i.to] < 0) {
        level[i.to] = level[v] + 1;
        que.push(i.to);
      }
    }
  }
}

int dfs(int v, int t, int f) {
  if(v == t) return f;
  for(int &i = iter[v]; i<(int)G[v].size(); ++i) {
    edge &e = G[v][i];
    if(e.cap > 0 && level[v] < level[e.to]) {
      int 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;
}

int max_flow(int s, int t) {
  int flow = 0;
  while(1) {
    bfs(s);
    if(level[t] < 0) return flow;
    memset(iter, 0, sizeof(iter));
    int f;
    while((f = dfs(s, t, INF)) > 0) flow += f;
  }
}

int a[105];
signed main(void)
{
  int n;
  cin >> n;
  /* 0～N-1:宝石 N:スタートS N+1:ゴールT */
  int sum = 0;
  REP(i, n) {
    cin >> a[i];
    // 辺を張る
    if(a[i] > 0) add_edge(i, n+1, a[i]);
    else if(a[i] < 0) add_edge(n, i, -a[i]);
    sum += max(0LL, a[i]);
  }
  FOR(i, 1, n+1) {
    for(int j=2*i; j<=n; j+=i) {
      // 頂点iの倍数の頂点jに辺を張る
      add_edge(i-1, j-1, INF);
    }
  }

  cout << sum - max_flow(n, n+1) << endl;

  return 0;
}


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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT_ON(bit, i) (bit & (1LL << i))

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;
template<typename T> using VVVV = std::vector<std::vector<std::vector<std::vector<T>>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }
template<typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); }
template<class T> inline std::vector<T> unique(std::vector<T> v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v;
}
// 初項s, 交差dのn個の数列の和
long long sum_of_arithmetic_progression(long long s, long long d, long long n) {
    return n * (2 * s + (n - 1) * d) / 2;
}

const int INF = 1 << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = {0, -1, 0, 1}, dx4 = {1, 0, -1, 0};
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;

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

	int N;
	cin >> N;
	V<int> H(N);
	FOR(i, 0, N) {
	    cin >> H[i];
	}

	V<LL> dp(N, INF);
	dp[0] = 0;
	FOR(i, 0, N) {
	    if (i + 1 < N) {
	        chmin(dp[i + 1], dp[i] + abs(H[i] - H[i + 1]));
	    }
        if (i + 2 < N) {
            chmin(dp[i + 2], dp[i] + abs(H[i] - H[i + 2]));
        }
	}

	print(dp[N - 1]);

	return 0;
}

Measured memory_bytes: 1408
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

ll solve(ll N, ll X){
    if(N > X) return solve(X, N);
    ll cnt = X/N;
    ll ans = N*cnt + N*(cnt-1);
    if(X%N == 0){
        return ans;
    }
    return ans + N + solve(X-cnt*N, N);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N, X; cin >> N >> X;
    cout << solve(X, N-X) + N << endstr;
    return 0;
}


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


Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

vector<int> edge[100010];
// dp[i]:=iを根とする木の最大深度
int dfs(int from){
    // cout<<from<<endl;
    vector<int> v;
    for(auto to:edge[from]){
        v.push_back(dfs(to));
    }
    sort(all(v)); reverse(all(v));
    int ret=0,n=v.size();
    rep(i,n){
        ret=max(ret,v[i]+i+1);
    }
    return ret;
}
int main(){
    int n; cin>>n;
    for(int i=2;i<=n;i++){
        int a; cin>>a;
        edge[a].push_back(i);
    }
    cout<<dfs(1)<<endl;
    return 0;
}


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

using namespace std;

int main(){

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

    int m1, m2, d1, d2;
    cin >> m1 >> d1 >> m2 >> d2;

    if(m1 != m2) cout << 1 << '\n';
    else cout << 0 << '\n';

    return 0;
}

Measured memory_bytes: 256
def check_substring(s,i):
  if s[i]=='A' and s[i+1]=='B' and s[i+2]=='C':
    return True
  else:
    return False
no = 0
n = int(input())
s = input()
for i in range(n-2):
  if check_substring(s,i)==True:
    no+=1
print(no)

Measured memory_bytes: 3060