akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,res=0;
  cin>>n;
  vector<int> v(n),c(n);
  for(int i=0;i<n;++i)cin>>v[i];
  for(int i=0;i<n;++i)cin>>c[i];
  for(int i=0;i<n;++i){
    if(v[i]>c[i])res+=v[i]-c[i];
  }
  cout<<res;
  return 0;
}


Measured memory_bytes: 256
'''ika tako
見た目が難しそうな問題こそ、書いて考えよう
式の意味を、数字を当てはめながら、具体的に試してみよう
考察が出来れば、実装は簡単な問題もある

x  を B で割った商をd、剰余を m とすると、それぞれは以下のように表せる。
(Ax)/B=Ad+(Am)/B
A*x/B=Ad
なので、m を最大化すればよい。
m=B−1 とできるなら、それが最大となる。
N の制約のせいでできないなら、できるだけ大きい数なので、
x=N とすればよい。
'''
a, b, n = map(int, input().split())
 
if b <= n:
    print(a * (b - 1) // b)
else:
    print(a * n // b)

Measured memory_bytes: 9148
#include<iostream>
using namespace std;
int main(){
	int x,y;
	cin >> x >> y;
	while(true){
		if(x > y){
			x = x - y;
		}
		else if(x < y){
			y = y - x;
		}
		else if(x == y){
			break;
		}
	}
	cout << x << endl;
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<=n;++i)
int main(){
  int n;
  cin>>n;
  vector<ll> a(n);
  vector<ll> sum(n,0);
  rep(i,n)cin>>a[i];
  sum[0]=a[0];
  ll len=0;
  rep1(i,n-1)sum[i]=sum[i-1]+a[i];
  len=sum[n-1];
  int k=0;
  rep(i,n){
    if(sum[i]>=len/2){
      k=i;
      break;
    }
  }
  ll ans;
  if(k>=1)ans=min(2*sum[k]-len,-2*sum[k-1]+len);
  if(k==0)ans=2*sum[0]-len;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define ALL(c) (c).begin(), (c).end()
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n,k;
    cin >> n >> k;
    n %= k;
    cout << min(n, k-n) << endl;
    
    
}




Measured memory_bytes: 764
#include<iostream>
#include<string>
using namespace std;
int main(){
	string s;
	cin>>s;
	long long cnt=0;
	long long sum=0;
	for(int i=0;i<s.length();i++){
		if(s[i]=='W')
			sum+=(i-cnt),cnt++;
	}
	cout<<sum<<endl;
} 

Measured memory_bytes: 640
from collections import defaultdict

n = int(input())
nums = list(map(int, input().split()))
frequency = defaultdict(int)

for n in nums:
    for x in [-1, 0, 1]:
        if 0 <= n + x and n + x <= 10 **5:
            frequency[n + x] += 1

ans = 0
for k, v in frequency.items():
    ans = max(ans, v)

print(ans)


Measured memory_bytes: 20976
#include <iostream>
using namespace std;
int main(){
    int A,B,C,D,K;
    C = 100;
    D = 0;
    cin >> A >> B >> K;
    while(D < K){
        if(A % C == 0 && B % C == 0){
            D++;
        }
        C--;
    }
    cout << C + 1 << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	W, H := nextInt(), nextInt()
	x, y, r := nextInt(), nextInt(), nextInt()

	if 0 <= (x-r) && (x+r) <= W && 0 <= (y-r) && (y+r) <= H {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}



Measured memory_bytes: 1092
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    vector <int> p(n);
    for(int i = 0; i < n; i++){
        cin>>p[i];
    }
    sort(p.begin(),p.end());
    long ans = 0;
    for(int i = 0; i < k; i++){
        ans += p[i];
    }
    cout << ans << endl;
    return 0;
}

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

class UnionFind {
 public:
  vector<int> data;
  UnionFind(int size) : data(size, -1) {}
  void unionSet(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (data[y] < data[x]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
  }
  bool findSet(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
};

int n, m;

int main() {
  while (cin >> n >> m) {
    UnionFind uf(n + 5);
    for (int i = 0; i < m; ++i) {
      int a, b;
      cin >> a >> b;
      a--, b--;
      uf.unionSet(a, b);
    }
    int x = 0;
    for (int i = 0; i < n; ++i) x = max(x, uf.size(i));
    cout << x << endl;
  }
}

Measured memory_bytes: 4052
// AOJ 2642: Dinner
// 2017.10.12 bal4u@uu

#include <stdio.h>
#include <stdlib.h>

long long a[500003];

char buf[30], *bp;
int getint()
{
	int n = 0;
	if (*bp == '-') {
		bp++;
		while (*bp >= '0') n = (n<<3) + (n<<1) + (*bp++ & 0xf);
		return -n;
	}
	while (*bp >= '0') n = (n<<3) + (n<<1) + (*bp++ & 0xf);
	return n;
}

int cmp(long long *a, long long *b)
{
	if (*a == *b) return 0;
	if (*a < *b) return 1;
	return -1;
}

int main()
{
	int n, q, c, i, j;
	long long p, s, ans;

	fgets(bp=buf, 30, stdin);
	n = getint(), bp++, p = getint(), bp++, q = getint();
    for (s = 0, i = 0; i < n; i++) {
		fgets(bp=buf, 10, stdin);
		c = getint();
        s += c, a[i] = p * (q - i) - c;
    }
	qsort(a, n, sizeof(long long), cmp);
    for (ans = s, j = i = 0; i < n; i++, j+=2) {
		s += a[i] + p*j;
		if (s > ans) ans = s;
	}
    printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 9328
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
#define llMAX 9223372036854775807
#define llMIN -9223372036854775808
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,m;


//BFS
vector<vector<int>> g;
const int N = 3e5;
int used[N];
int mitis[N];

void bfs(int i,int c){
  REP(i,N){
    used[i]=-1;
    mitis[i]=-1;
  }
  used[i] = c;
  queue<int> que;
  que.push(i);
  int id;
  //col[i] = c;
  while (!que.empty()) {
      //cout << que.front() << " "; // 先頭要素を参照する
      id=que.front();
      int lootlen=used[id];
      for(auto to : g[id]) {
          if (used[to]==-1){
            que.push(to);
            used[to]=lootlen+1;
            mitis[to]=id;
          }
      }
      que.pop(); // 先頭要素を削除
  }
  return;
}


int main() {
  int m,n;
  cin>>n>>m;
  g.resize(m*2);
  for(int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }
  bfs(0,0);



  int flag=0;
  for(ll i=1;i<n;i++){
    if (mitis[i]==-1)flag=1;
  }
  if (flag==1){
    cout<<"No"<<endl;
    return 0;
  }


  cout<<"Yes"<<endl;

  for(ll i=1;i<n;i++){
    cout<<(mitis[i]+1)<<endl;
  }


  return 0;
}

Measured memory_bytes: 19308
#include<stdio.h>
#include<stdlib.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
int main(){
  int N,K,h[100000],min=1000000000,i;
  scanf("%d %d",&N,&K);
  for(i=0;i<N;i++){
    scanf("%d",&h[i]);
  }
  qsort(h, N, sizeof(int), compare_int);
  for(i=0;i<N-K+1;i++){
    if(h[i+K-1]-h[i]<min){
      min=h[i+K-1]-h[i];
    }
  }
  printf("%d",min);
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define ok cout<<"ok"<<endl
#define dbg(x) cout<<(#x)<<" is "<<x<<endl
using namespace std;
typedef long long ll;
const int N=100009;
int main()
{
   double n,ml,r;
   cin>>n;
   r=n/3.0;
   ml=r*r*r;
   printf("%0.10lf\n", ml);
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var x,a,b int
	fmt.Scan(&x,&a,&b)

	if a >= b {
		fmt.Println("delicious")
	} else if b - a > x {
		fmt.Println("dangerous")
	} else {
		fmt.Println("safe")
	}
}


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

int main(){
    int N,K,ans=0;
    cin >> N >> K;
    vector<int> vec(N);
    for(int i=0;i<N;i++){
        cin >> vec[i];
    }
    for(int i=0;i<N;i++){
        ans+=min(vec[i],K-vec[i])*2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct card{char c;int value;};

int main(void){
    int n,i,j,minj,ans=1,flag;
    cin>>n;
    vector<card> c1(n),c2(n);
    for(i=0;i<n;i++){
        cin>>c1[i].c>>c1[i].value;
        c2[i]=c1[i];
    }
    for(i=0;i<n-1;i++){
        for(j=n-1;j>=i+1;j--){
            if(c1[j-1].value>c1[j].value){
                swap(c1[j],c1[j-1]);
            }
        }
    }
    for(i=0;i<n-1;i++){
        minj=i;
        for(j=i+1;j<n;j++){
            if(c2[j].value<c2[minj].value){
                minj=j;
            }
        }
        swap(c2[i],c2[minj]);
    }
    for(i=0;i<n;i++){
        cout<<c1[i].c<<c1[i].value;
        if(i>=0&&i<n-1)cout<<" ";
    }
    cout<<endl;
    cout<<"Stable"<<endl;
    for(i=0;i<n;i++){
        if(c1[i].c!=c2[i].c)ans=0;
        cout<<c2[i].c<<c2[i].value;
        if(i>=0&&i<n-1)cout<<" ";
    }
    cout<<endl;
    if(ans)cout<<"Stable"<<endl;
    else cout<<"Not stable"<<endl;
}


Measured memory_bytes: 3096
using System;

 class Program
    {
        static void Main(string[] args)
        {
            string[] vs = Console.ReadLine().Split(' ');

            
            for (int i = 0; i < 5; i++)
            {
                if (vs[i]=="0")
                {
                    Console.WriteLine(i + 1);
                }
            }

        }
    }

Measured memory_bytes: 17628
N = int(input())
A= N//1000
B = (N - A*1000) //100
C = (N - A*1000 - B*100) // 10
D = N - A*1000 - B*100 - C*10
if A == B == C:
 print("Yes")
elif B==C==D:
 print("Yes")
else:
 print("No")

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

using namespace std;

int main() {
  int i, n, one, two;
  string p1, p2;

  cin >> n;
  one = 0; two = 0;

  for (i=0; i < n; i++) {
    cin >> p1 >> p2;

    if (p1 == p2) {
      one += 1;
      two += 1;
    }
    else if (p1 > p2) {
      one += 3;
    }
    else if (p1 < p2) {
      two += 3;
    }
  }

  cout << one << " " << two << endl;
  return 0;
}

Measured memory_bytes: 1208
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;

int main() {
  int A, B; std::cin >> A >> B;
  bool p[] = {true, true, true};
  p[A-1] = false; p[B-1] = false;
  for (int i = 1; i <= 3; ++i) {
    if (p[i-1]) {
      std::cout << i << std::endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n; cin>>n;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin>>a[i];

    int ng = 0, ok = n;
    while(ok - ng > 1){
        int mid = (ng + ok) / 2;

        bool valid = true;
        stack<P> st;
        for(int i=0; i+1<n; i++){
            if(a[i] >= a[i+1]){
                while(st.size() && !(st.top().first <= a[i+1])) st.pop();
                if(st.size() && st.top().first == a[i+1]) st.top().second++;
                else st.emplace(a[i+1], 1);

                while(st.top().second == mid){
                    int digit = st.top().first;
                    if(digit == 1){
                        valid = false;
                        goto END;
                    }
                    st.pop();
                    if(st.size() && st.top().first == digit - 1) st.top().second++;
                    else st.emplace(digit-1, 1);
                }
            }
        }

        END:;
        if(valid) ok = mid;
        else ng = mid;
    }

    cout << ok << endl;

    return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    ll n;cin >>n;
    vector<ll>a(n+1);
    vector<ll>b(n+1);
    for (int i = 0; i < n + 1; ++i) {
        cin >>a[i];
    }
    b[0]=1-a[0];
    vector<ll>sum(n+1,0);
    for (int i = 0; i < n; ++i) {
        if(sum[n-i]>INFll-a[n-i]){
            sum[n-i-1]=INFll;
        }
        sum[n-i-1]=sum[n-i]+a[n-i];
    }
//    for (int i = 0; i <=n; ++i) {
//        cout <<sum[i]<<endl;
//    }
    ll ans=0;
    for (int i = 0; i <n; ++i) {
        if(b[i]>INFll/2)b[i+1]=INFll;
        b[i+1]=min({2*b[i]-a[i+1],sum[i+1]});
    }
    for (int i = 0; i <=n; ++i) {
//        cout <<a[i]<<" "<<b[i]<<endl;
        if(b[i]<0){
            cout <<-1<<endl;
            return 0;
        }
        ans+=a[i]+b[i];
    }
    cout <<ans <<endl;
    return 0;
}


Measured memory_bytes: 5580
import java.util.Scanner;

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

		if (a < 10 && b < 10) {
			System.out.println(a * b);
		} else {
			System.out.println(-1);
		}
	}
}


Measured memory_bytes: 23892
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
typedef long long LL;

int main() {
    int n, T, c, t;
    int minc = 1001;

    cin >> n >> T;
    for (int i=0; i<n; i++) {
        cin >> c >> t;
        if (t <= T) minc = min(minc, c);
    }

    if (minc == 1001) puts("TLE");
    else cout << minc << endl;
}


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

int main() {
	char S[20];
	string T;
	string p;
	string Q;
	int a = 0;
	int A = 0;
	int b = 0;
	int B = 0;
	int c = 0;
	int C = 0;
	int q, w, z;
	int n = 0;
	int x = 0;
	int y = 0;
	int ans = 0;
	cin >> a >> b >> c;
	n = a * 100 + b * 10 + c;
	if (n % 4 == 0) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

long long int pow_mod(long long int p_a,long long int p_n,long long int p_p=1e9+7){
	//p_a^p_n mod p_p
	long long int p_b=1,p_t=1;
	for(;p_b<=p_n;p_b<<=1);
	for(p_b>>=1;p_b>0;p_b>>=1){
		p_t*=p_t;
		if(p_t>=p_p)p_t%=p_p;
		if(p_n&p_b)p_t*=p_a;
		if(p_t>=p_p)p_t%=p_p;
	}
	return p_t;
}

long long int gcd(long long int g_a,long long int g_b){
	if(g_a<g_b)gcd(g_b,g_a);
	if(g_b==0)return g_a;
	return gcd(g_b,g_a%g_b);
}

long long int divide(long long int d_a,long long int d_b,long long int d_p=1e9+7){
	// d_a/d_b mod d_p
	// prime:d_p is prime
	if(d_a>=d_p)d_a%=d_p;
	if(d_a<0)d_a+=d_p;
	if(d_b>=d_p)d_b%=d_p;
	if(d_b<0)d_b+=d_p;
	d_a*=pow_mod(d_b,d_p-2,d_p);
	return d_a%d_p;
}

LL kai[550000];

int main(){
	int n,m;
	int i,j,k;
	LL a,b,c;
	cin>>n>>m;
	kai[0]=1;
	for(i=1;i<=m;i++){
		kai[i]=kai[i-1]*i;
		if(kai[i]>=MAX)kai[i]%=MAX;
	}
	LL s=0;
	for(i=0;i<=n;i++){

		a=divide(kai[m],kai[i]*kai[m-i])*divide(kai[n],kai[n-i])%MAX;
		b=divide(kai[m-i],kai[m-n]);
		a=a*b%MAX*b%MAX;
		if(i%2)a=-a;
		s+=a;
		if(s<0)s+=MAX;
	}
	cout<<s%MAX<<endl;
}

Measured memory_bytes: 7500
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
using namespace std;
// }}} End Header

lli sigma1(lli n){
	return n*(n+1)/2;
}
lli sigma2(lli s, lli n){
	return sigma1(n) - sigma1(s -1);
}
int main()
{
	int p, q, r, max1, max2;
	cin >> p >> q >> r;
	if(p > q) max1 = p;
	else max1= q;

	if(max1 > r) max2 = max1;
	else max2 = r;
	cout << p+q+r-max2 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)
#define foreach(c,itr) for(__typeof(c)::iterator itr=c.begin();itr!=c.end();itr++)
typedef long long ll;
int i,j;

int main(){
	ios::sync_with_stdio(false);
    cin.tie();
    
    string s;
    cin>>s;
    int ans=-1;
    int sum=0;
    for(i=0;i<s.size();i++){
    	if(s[i]=='R') sum++;
    	else sum=0;
		if(sum>ans) ans=sum;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include<iostream>
#include<bits/stdc++.h> 
#define N 100005
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
ll r[100000+5],g[100000+5],col[100000+5];
ll rnum,gnum,cnum;
ll x,y,a,b,c,ans=0,num;
struct apple
{
	ll d,type;
}k[300000+5];
bool cmp(struct apple x,struct apple y)
{
	if(x.d==y.d)return x.type<y.type;
	return x.d>y.d;
}
int main()
{
	scanf("%lld%lld%lld%lld%lld",&x,&y,&a,&b,&c);
	for(int i=1;i<=a;i++)
	{
		scanf("%lld",&r[i]);
		num++;
		k[num].d=r[i];
		k[num].type=0;
	}
	for(int i=1;i<=b;i++)
	{
		scanf("%lld",&g[i]);
		num++;
		k[num].d=g[i];
		k[num].type=1;
	}
	for(int i=1;i<=c;i++)
	{
		scanf("%lld",&col[i]);
		num++;
		k[num].d=col[i];
		k[num].type=2;
	}
	sort(k+1,k+1+num,cmp);
	for(int i=1;i<=num;i++)
	{
		if(k[i].type==2)
		{
			cnum++;
			ans+=k[i].d;
		}
		else if(k[i].type==1)
		{
			if(gnum==y)continue;
			else 
			{
				gnum++;
				ans+=k[i].d;	
			}	
		}
		else
		{
			if(rnum==x)continue;
			else 
			{
				rnum++;
				ans+=k[i].d;
			}
		//	cout<<ans<<endl;
		}
		if(rnum+gnum+cnum==x+y)break;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 7296
import java.util.Arrays;
import java.util.Scanner;

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

        sc.close();

        char[] aa = a.toCharArray();
        Arrays.sort(aa);
        a = String.valueOf(aa);

        char[] bb = b.toCharArray();
        Arrays.sort(bb);
        b = String.valueOf(bb);
        b = new StringBuilder(b).reverse().toString();

        if (a.compareTo(b) < 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 23892
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();int result=0;
        String s = sc.next();
        char[] array = s.toCharArray();
        for (int i = 0; i <= n-3; i++) {
            if(array[i]=='A') {
                if (array[i + 1] == 'B') {
                    if (array[i + 2] == 'C')
                        result++;
                }
            }
        }
        System.out.println(result);
    }
}

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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

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

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      n: usize,
      s: chars,
    }
    let mut ans = vec![];
    let mut p = 0;
    for c in s {
        ans.push(c);
        if c == '(' {
            p += 1;
        } else {
            if p == 0 {
                ans.insert(0, '(');
            } else {
                p -= 1;
            }
        }
    }
    for _ in 0..p {
        ans.push(')');
    }
    println!("{}", ans.into_iter().collect::<String>());
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  ll N, K;
  cin >> N >> K;

  int ans = 0;
  while (N > 0) {
    N /= K;
    ++ans;
  }

  cout << ans << endl;

  return 0;
}


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

int main() {

    long long int k=0;

    cin >> k;

    int n = 50;

    long long int a[50];

    for(int i=0; i<n; i++){
        a[i] = n-1;
    }

    for(int i=0; i<k%50; i++){
        int min_itr = -1;
        long long int m = 10000000;
        for(int j=0; j<n; j++){
            if(m >= a[j]){
                m = a[j];
                min_itr = j;
            }
        }
        for(int j=0; j<n; j++){
            if(min_itr == j){
                a[j] += n;
            }
            else{
                a[j]--;
            }
        }
    }

    cout << n << endl;

    for(int i=0; i<n; i++){
        cout << a[i] + k/50 << " ";
    }

    cout << endl;

    return 0;
}


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

int main() {
  int N, Y, a, b, c;
  cin >> N >> Y;
  a = -1;
  b = -1;
  c = -1;
  bool flag = false;
    
  for (int i = 0; i < N+1; i++) {
    if(flag) {
      break;
    }
    
    for (int j = 0; j < N+1-i; j++) {
      if(10000 * i + 5000 * j + 1000 *(N-i-j) == Y) {
        a = i;
        b = j;
        c = N-i-j;
        flag = true;
        break;
      }
    }
  }
  cout << a << " " << b << " " << c << endl;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=1; i<=(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N;
    scanf("%d",&N);
    vi a(N);
    rep(i,N) cin>>a[i];
    map<string,int> m;
    rep(i,N) {
        if(a[i]<=400) m["grey"]++;
        else if(a[i]<800) m["brown"]++;
        else if(a[i]<1200) m["greren"]++;
        else if(a[i]<1600) m["aqua"]++;
        else if(a[i]<2000) m["blue"]++;
        else if(a[i]<2400) m["yellow"]++;
        else if(a[i]<2800) m["orange"]++;
        else if(a[i]<3200) m["red"]++;
        else m["freedom"]++;
    }
    int ans=0;
    for(auto c : m) {
       if(c.fi!="freedom"&&c.se>0) ans++;
    }
    if(ans==0&&N>=0) cout<<1<<" "<<m["freedom"]<<endl;
    else cout<<ans<<" "<<ans+m["freedom"]<<endl;
}

Measured memory_bytes: 256
array = Array.new
while true
	a = gets.split(" ").map{|e|e.to_i}
	break if a[0] == 0 && a[1] == 0
	array.push a
end

array.each{|a|
	a[0].times{
		a[1].times{
			print "#"
		}
		puts ""
	}
	puts ""
}

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

int main() {
  int X;
  cin >> X;
  vector<int> count = {0, 0};
  while (X >= 500) {
    count.at(0) += 1;
    X -= 500;
  }
  while (X >= 5) {
    count.at(1) += 1;
    X -= 5;
  }
  cout << 1000 * count.at(0) + 5 * count.at(1) << endl;
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <math.h>
#include <map>
#include <set>
#define sc scanf
#define pr printf
using namespace std;
typedef long long ll;
const ll N = 100000;
int main()
{
    ll n,x;
    while(~sc("%lld%lld",&n,&x))
    {
        ll a,b,ans = 0;
        sc("%lld",&a);
        if(a > x)
        {
            ans += a - x; a = x;
        }
        for(int i=1; i<n; i++)
        {
            sc("%lld",&b);
            if(b > x)
            {
                ans += b - x; b = x;
            }
            if(a + b > x)
            {
                ans += a+b - x; b =  b - (a + b - x);
            }
            a = b;
        }
        pr("%lld\n",ans);
    }
    return 0;
}


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

int main()
{
  int N;
  cin >> N;
  vector< int > p(N);
  for (int i = 0; i < N; ++i) {
    cin >> p[i];
  }

  int ans = 0;
  for (int i = 0; i < N; ++i) {
    if (p[i] == i + 1) {
      ans++;
      if (i == N - 1) {
	swap(p[i], p[i - 1]);
      } else if (p[i + 1] == i + 1) {
	swap(p[i], p[i - 1]);
      } else {
	swap(p[i], p[i + 1]);
      }
    }
  }
  cout << ans << endl;

  
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
int main()
{
	double a, b, c, d;
	scanf("%lf", &a);
	b = 3.1415926535897932384626433*a*a;
	c = 2 * 3.1415926535897932384626433*a;
	printf("%.6lf %.6lf\n", b, c);
	return 0;
}


Measured memory_bytes: 2760
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});
process.stdin.on('end', function() {
    main(g_input.split(/\r?\n/));
});

function main(inputs) {
  var N = parseInt(inputs[0]);
  var rs = inputs[1].split(" ").map(function(a){return parseInt(a);});
  var a = new Array(7).fill(false);
  var a8 = 0;
  var count = 0;
  for(var i = 0; i < N; i++){
    for(var j = 0; j < 9; j++){
      if(j != 8){
        if(rs[i] < (j+1)*400){
          if(!a[j]){
            a[j] = true;
            count += 1;
          }
          break;
        }
      }else{
        a8 += 1;
      }
    }
  }
  var min = count;
  if(min == 0 && N>0){
    min = 1;
    a8 -=1;
  }
  var max = min + a8;
  console.log(""+min+" "+max);
}


Measured memory_bytes: 7500
H,N = map(int,input().split())
A = [0] * N
B = [0] * N
for i in range(N):
    A[i],B[i] = map(int,input().split())

DP = [[0] * (H+1) for i in range(N)]

for i in range(1,H+1):
    DP[0][i] = B[0] * -(-i//A[0])

for i in range(1,N):
    for j in range(1,H+1):
        if DP[i-1][j] < DP[i][max(0,j-A[i])] + B[i]:
            DP[i][j] = DP[i-1][j]
        else:
            DP[i][j] = DP[i][max(0,j-A[i])] + B[i]

print (DP[N-1][H])


Measured memory_bytes: 120940
import math
import numpy as np

N,M=map(int,input().split())
gcd=math.gcd(N,M)
lcm=N*M//gcd

S=input()
T=input()
i=1

L=np.array([lcm*i for i in range(1,max(N,M)) if lcm*i<=N*M])
S_list=L//M
T_list=L//N

if S[0]!=T[0]:
  print(-1)
else:
  for i in range(len(S_list)-1):
    if S[S_list[i]]!=T[T_list[i]]:
      print(-1)
      break
  else:
    print(lcm)

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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

struct UF {
    static const int N = 100000;//書き換え!
    int par[N];
    int rank[N];
    int cnt;

    UF() {
        rep(i, N) {
            par[i] = i;
            rank[i] = 0;
        }
    }

    void init() {
        rep(i, N) {
            par[i] = i;
            rank[i] = 0;
        }
    }

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

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

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

int N, M;

signed main() {
    cin >> N >> M;
    UF uf;
    uf.cnt = N;
    rep(i, M) {
        int x, y, z;
        cin >> x >> y >> z;
        --x, --y;
        uf.unite(x, y);
    }
    cout << uf.cnt << endl;
    return 0;
}


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

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rbf(i, v) for (auto& (i) : (v))
#define All(x) (x).begin(),(x).end()
#define cAll(x) (x).cbegin(),(x).cend()
#define COL(x) cout << x << endl
#define CO(x) cout << x
//#define int long long

template<typename T> inline constexpr auto square(T x) { return (x) * (x); }

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const int INF = INT_MAX;

signed main()
{
	int a, b, x;
	cin >> a >> b >> x;

	double y = static_cast<double>(x) / a;
	double z = 2.0 * y / a - b;
	double theta;

	if (z > 0) {
		theta = atan2(b - z, a) * 360.0 / (2.0 * PI);
	}
	else {
		z = a - 2.0 * y / b;
		theta = atan2(b, a - z) * 360.0 / (2.0 * PI);
	}

	printf("%.10lf\n", theta);

	return 0;
}

Measured memory_bytes: 256
object Main extends App {
	import scala.math._

	val N = scala.io.StdIn.readInt
	val L = scala.io.StdIn.readLine.split(" ").map(_.toInt).sorted

	var sum = 0

	for(i<-0 until N){
		sum = sum + min(L(2*i),L(2*i + 1))
	}

	println(sum)

}


Measured memory_bytes: 25420
#include <stdio.h>

int cmpfunc (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}

int main()
{
    int a[4], ans=0, max, max2, max3;
    scanf("%d %d %d", &a[0], &a[1], &a[2]);

    qsort (a, 3, sizeof(int), cmpfunc);
    max = a[2];
    max2= a[1];
    max3= a[0];
    ans = (max * 10) + max2 + max3;
    printf("%d", ans);
    return 0;
}


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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }


/*
--------------------------------------------

	type

--------------------------------------------
*/
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

/*
--------------------------------------------

	container

--------------------------------------------
*/
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

/*
--------------------------------------------

	repetition

--------------------------------------------
*/
#define REP(n) for(int i=0; i<n; i++)
#define REPj(n) for(int j=0; j<n; j++)
#define REPinit(a,n) for(int i=a; i<n; i++)
#define REPinitj(a,n) for(int j=a; j<n; j++)

//algorithm
//#define SORT(c) sort((c).begin(),(c).end())

/*
--------------------------------------------

	constant

--------------------------------------------
*/
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

/*
--------------------------------------------

	Optimizer

--------------------------------------------
*/
//#pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/*
--------------------------------------------
 
	Utility Algorithm

-------------------------------------------- 
*/

template <typename T>
void swapAlgorithm(T& a, T& b) {
    T tmp = a;
    a = b;
    b = tmp;
}
 
template <typename T1>
T1 euclideanAlgorithm(T1 a, T1 b) {
    T1 a_tmp = a;
    T1 b_tmp = b;
 
    if (a_tmp > b_tmp) {
        swapAlgorithm<T1>(a_tmp, b_tmp);
    }
 
    T1 r = a_tmp % b_tmp;
    while (r != 0) {
        a_tmp = b_tmp;
        b_tmp = r;
        r = a_tmp % b_tmp;
    }
    return b_tmp;    
}

template <typename T2>
T2 getLCM(T2 a, T2 b) {
    return (a * b)/(euclideanAlgorithm(a, b));
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

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

    int H,A;
    cin >> H >> A;
    // cout << (int)ceil((double)H / A) << endl;
    cout << ((H + A - 1) / A) << endl;
    return 0;

}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;


namespace atcorder2
{
    class Program
    {
        public static long Read()
        {

            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {
            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

       
       
        public static long gcd(long x,long y)
        {
            if (x < y) gcd(y, x);
            
            while (y > 0)
            {
                var z = x % y;
                x = y;
                y = z;
            }
            return x;
        }

        public static long lcm(long x,long y)
        {
            return x * y / gcd(x, y);
        }



        static void Main(string[] args)
        {
            var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);


            var abhm = Reads();
            var a = abhm[0];
            var b = abhm[1];
            var h = abhm[2];
            var m = abhm[3];
            var arc = Math.Min(Math.Abs(m * 6 - (h * 30 + m * 0.5)), 360 - Math.Abs(m * 6 - (h * 30 + m * 0.5))) * Math.PI / 180.0;
            var ans=a * a + b * b - 2 * a * b * Math.Cos(arc);
            WriteLine(Math.Sqrt(ans));
            
           
          
            Out.Flush();
        }
    }
}




Measured memory_bytes: 19888
#include <iostream>
#include<list>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
using namespace std;

int main()
{
    set<int> a,b,d;
    int c;
    int n;
    cin>>n;
    while(n--){
        cin>>c;
        a.insert(c);
    }
    cin>>n;
    while(n--){
        cin>>c;
        b.insert(c);
    }
    //set_union(it1,it2,it3,it4,it);
    set_symmetric_difference(a.begin(),a.end(),b.begin(),b.end(),inserter(d,d.begin()));
    for(set<int>::iterator it=d.begin();it!=d.end();it++){
        cout<<*it<<"\n";
    }
}





Measured memory_bytes: 40584
n = int(input())
b = list(map(int, input().split()))
a = [b[0]]

for i in range(n-1):
  a_1 = a[i]
  a_2 = b[i]
  if b[i] >= max(a_1,a_2):
    a.append(b[i])
  else:
    a.append(b[i])
    a[i] = b[i]

print(sum(a))

Measured memory_bytes: 38384
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn zalgo(s: &[char]) -> Vec<usize> {
    let size = s.len();
    let mut ret = vec![0; size];
    ret[0] = size;
    let mut i = 1;
    let mut j = 0;
    while i < size {
        while i + j < size && s[j] == s[i + j] { j += 1; }
        ret[i] = j;
        if j == 0 {
            i += 1;
            continue;
        }
        let mut k = 1;
        while i + k < size && k + ret[k] < j {
            ret[i + k] = ret[k];
            k += 1;
        }
        i += k;
        j -= k;
    }
    ret
}

fn main() {
    input! {
        n: usize,
        s: chars
    }

    let mut ans = 0;
    for i in 0..n {
        let s2 = &s[i..];
        let lcp = zalgo(s2);
        for j in 1..(lcp.len()) {
            let mut c = lcp[j];
            if j < c { c = j; }
            if c > ans { ans = c; }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
using namespace std;

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

#define pb push_back
#define fr first
#define sc second
#define mp1(a,b,c) P1(a,P(b,c))

struct MAX_FLOW{
	vector<P1> G[105];
	bool used[105];
	void init(){
		for(int i = 0 ; i < 105 ; i ++)G[i].clear();
	}
	void add_edge(int from, int to, ll flow){
		G[from].pb( mp1( to, flow, G[to].size() ) );
		G[to].pb( mp1( from, 0, G[from].size()-1 ) );
	}
	ll dfs(int v, int t, ll f){
		if(v == t)return f;
		used[v] = true;
		for(int i = 0 ; i < G[v].size() ; i ++){
			if(!used[G[v][i].fr] && G[v][i].sc.fr > 0){
				ll d = dfs(G[v][i].fr,t,min(f,G[v][i].sc.fr));
				if(d > 0){
					G[v][i].sc.fr -= d;
					G[G[v][i].fr][G[v][i].sc.sc].sc.fr += d;
					return d;
				}
			}
		}
		return 0;
	}
	ll flow(ll s,ll t){
		ll ret = 0, d = 1;
		while(d > 0){
			for(int i = 0 ; i < 105 ; i ++)used[i] = false;
			d = dfs(s,t,1000000000);
			ret += d;
		}
		return ret;
	}
}flow;

int main(){
	int N;
	int a[102];
	scanf("%d",&N);
	for(int i = 1 ; i <= N ; i ++){
		scanf("%d",&a[i]);
	}
	
	ll ret = 0;
	flow.init();
	for(int i = 1 ; i <= N ; i ++){
		for(int j = 2*i ; j <= N ; j += i){
			flow.add_edge(i,j,1000000000000000000);
		}
		if(a[i] > 0){
			ret += a[i];
			flow.add_edge(i,N+1,a[i]);
		}
		if(a[i] < 0){
			flow.add_edge(0,i,-a[i]);
		}
	}
	ret -= flow.flow(0,N+1);
	cout << ret << endl;
}



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

using namespace std;

int main() {
int N;
cin>>N;
vector<int>a(N);
for(int i=0;i<N;i++){
   cin>>a[i];
}
int x=0;
for(int j=0;j<N;j++){
   x+=(a[j]-1);
}
cout<<x<<endl;
   return 0;
}






Measured memory_bytes: 3608
#include <cstdio>
#include <iostream>
#define MAX 100
using namespace std;
int N;
int a[MAX];
int cnt=0;
void bs(int *a,int n){
    bool flag=true;
    while(flag){
        flag=false;
        for(int j=N-1;j>0;j--){
            if(a[j]<a[j-1]){
                swap(a[j],a[j-1]);
                flag=true; 
                cnt++;
            }
        }
    }
}

int main(){
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        scanf("%d",&a[i]);
    }
    bs(a,N);
    printf("%d",a[0]);
    for(int i=1;i<N;i++){
        printf(" %d",a[i]);
    }
    printf("\n%d\n",cnt);
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	cout << n/500*1000+(n%500)/5*5;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0L;i--)
#define prep(i,n) for(int64_t i=1;i <= (int64_t)(n);i++)
using namespace std;

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  fspcnt = 0;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int a,b,gomi;
  cin >> a >> b;
  cout << (a*b)/2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100005],b[100005],dp[100005];
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	cin >> n;
	int mx = 0,mn = INT_MAX;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];  
		b[a[i]]++;
		mx = max(mx,a[i]);
		mn = min(mn,a[i]);
	}
	if (mn != (mx+1)/2)
	{
		cout << "Impossible";
		return 0;
	}
	int y = 0;
	for (int i = 1; i <= n; i++)
	{
		if (a[i] == mn){
			y++;
		}
	}
	if (((mx%2 == 1) && y != 2) || (mx %2 == 0 && y != 1)){
		cout << "Impossible";
		return 0;
	}
	for (int i = mn+1; i <= mx; i++){
		if(b[i] <= 1)
		{
			cout << "Impossible";
			return 0;
		} 	
	}
	cout << "Possible";
		
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int q = sc.nextInt();
			Set<Integer> s = new HashSet<>();
			for(int i = 0; i < q; i++) {
				int query = sc.nextInt();
				switch(query) {
				case 0:
					s.add(sc.nextInt());
					System.out.println(s.size());
					break;
				case 1:
					System.out.println(s.contains(sc.nextInt())?"1":"0");
				}
			}
		}
	}
}


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

int main(){
    ll n,n1,ans=0;
    cin >> n;
    n1 = n;
    set<ll> e;
    for(ll i = 1;i*i <= n1;i ++){
        if(n1%i==0){
            e.insert(i);
            if(i*i!=n1) e.insert(n1/i);
        }
    }
    for(auto ite = e.begin();ite != e.end();++ite){
        ll p = *ite;
        ll m = n/p-1;

        if(p<m&&n%m!=0) ans += m;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#define N 8
#define FREE -1
#define NOT_FREE 1

int tate[N],yoko[N],hnaname[2*N-1],mnaname[2*N-1];
int X[N][N];

void initialize(){
  int i;
  for(i=0;i<N;i++){tate[i]=FREE; yoko[i]=FREE;}
  for(i=0;i<2*N-1;i++){hnaname[i]=FREE; mnaname[i]=FREE;}
}

void print(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(X[i][j]){
        if(tate[i]!=j)return;
      }
   }
  }for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      printf((tate[i]==j)?"Q":".");
    }
    printf("\n");
  }
}
void haiti(int i){
    int j;
    if(i==N){
        print();
        return;
    }
    for(j=0;j<N;j++){
        if(NOT_FREE==yoko[j]||NOT_FREE==hnaname[i+j]||NOT_FREE==mnaname[i-j+N-1])
        continue;
        tate[i]=j;
        yoko[j]=hnaname[i+j]=mnaname[i-j+N-1]=NOT_FREE;
        haiti(i+1);
        tate[i]=yoko[j]=hnaname[i+j]=mnaname[i-j+N-1]=FREE;
    }
}

int main(){
    int i,j,k,r,c;
    initialize();
    for(i=0;i<N;i++){
        for(j=0;j<N;j++) X[i][j]=0;
    }
    scanf("%d",&k);
    for(i=0;i<k;i++){
        scanf("%d%d",&r,&c);
        X[r][c]=1;
    }
    haiti(0);
    return 0;
}




Measured memory_bytes: 2084
#include<stdio.h>
#include<stdlib.h>
int main()
{
    char ch[6];
    int i;
    for(i=0;i<6;i++)
        scanf("%c",&ch[i]);
    ch[i]='\0';
    if(ch[2]==ch[3]&&ch[4]==ch[5])
        printf("Yes");
    else
        printf("No");
    return 0;
}


Measured memory_bytes: 128