akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define reps2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int n, m;
struct edge {
    int to, cost;
    edge(int to, int cost) : to(to), cost(cost) {}
};
bool seen[100'002];
vector<edge> G[100'002];

void dfs(int s) {
    vector<int> st;
    st.push_back(s);
    seen[s] = true;

    while (!st.empty()) {
        int u = st.back();
        st.pop_back();
        for (const auto e : G[u]) {
            if (!seen[e.to]) {
                seen[e.to] = true;
                st.push_back(e.to);
            }
        }
    }
}

int solve() {
    int ans = 0;
    rep(i, n) {
        if (!seen[i]) {
            dfs(i);
            ans++;
        }
    }
    return ans;
}

int main() {
    cin >> n >> m;
    rep(i, m) {
        int u, v, w;
        cin >> u >> v >> w;
        G[u - 1].push_back(edge(v - 1, w));
        G[v - 1].push_back(edge(u - 1, w));
    }
    cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 7540
#
# File    : A.rb
# Author  : Kazune Takahashi
# Created : 2019-5-25 20:54:47
# Powered by Visual Studio Code
#

a, b = gets.chomp.split(" ").map{|i| i.to_i}
if a <= 5
  puts 0
elsif a <= 12
  puts b/2
else
  puts b
end

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

int main()
{
    int a, b;

    cin >> a >> b;

    if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
while 1:
    n=int(input())
    if n==0:
        break
    data=[]
    for i in range(n):
        data.append(set(list(map(int,input().split()))[1:]))
    check=set(list(map(int,input().split()))[1:])
    ans=[]
    for i in range(n):
        if check-data[i]==set():
            ans.append(i+1)
    if len(ans)==0 or len(ans)>1:
        print(-1)
    else:
        print(ans[0])



Measured memory_bytes: 6340
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////



int main(){

    itn n,k;
    cin >> n >> k;

    ll v[n] = {};
    
    rep(i,0,n){
	cin >> v[i];
    }

  
    ll ans = 0;

    rep(i,0,n+1){
	rep(j,0,n+1){
	    if(k - (i+j) >= 0 && n - (i+j) >= 0){
		vector<ll> vv;
		rep(l,0,i)vv.pb(v[l]);
		rep(l,0,j)vv.pb(v[n-1-l]);

		vsort(vv);
		ll t = 0,cnt = k-(i+j);
		rep(l,0,sz(vv)){
		    if(cnt > 0 && vv[l] < 0)cnt--;
		    else t += vv[l];
		}
		ans = max(ans,t);
	    }
	}
    }
    P(ans);
    return  0;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long ll;


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

  int canBuy = n/100;
  int mustBuy = (n%5 == 0) ? n%100/5 : n%100/5 + 1;

  cout << (canBuy >= mustBuy) << endl;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;
typedef vector<pair<ll, ll>> vpll;

mt19937 tw(566);
uniform_int_distribution<ll> ll_distr;

ll rnd(ll a, ll b) {
    return ll_distr(tw) % (b - a + 1) + a;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int x;
    cin >> x;
    if (400 <= x && x <= 599) cout << 8 << "\n";
    if (600 <= x && x <= 799) cout << 7 << "\n";
    if (800 <= x && x <= 999) cout << 6 << "\n";
    if (1000 <= x && x <= 1199) cout << 5 << "\n";
    if (1200 <= x && x <= 1399) cout << 4 << "\n";
    if (1400 <= x && x <= 1599) cout << 3 << "\n";
    if (1600 <= x && x <= 1799) cout << 2 << "\n";
    if (1800 <= x && x <= 1999) cout << 1 << "\n";
    return 0;
}

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

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  if (b <= a) {
    cout << "delicious" << endl;
  }else if(b > a+x){
    cout << "dangerous" << endl;
  }else{
    cout << "safe" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
N,M,C  = map(int,input().split())
#B
B = list(map(int,input().split()))

counter = 0

#A
A_list = []
for i in range(N):
    sum_seki = 0
    A = list(map(int,input().split()))
    for j in range(M):
        seki = A[j]*B[j]
        sum_seki = sum_seki + seki
    ans = sum_seki + C
    if ans > 0:
        counter += 1


print(counter)


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int const nm = 107;
int v[nm];
int main()
{
    int n , a , suma = 0 , sumb = 0 ;
    cin >> n;
    for(int i = 1 ;i <= n; ++ i)
    {
        cin >> a;
        ++ v[a];
    }
    bool pp = 1;
    while( pp )
    {
        int i;int cnt = 1;
        for(i = 100; i >= 1 && cnt <= n; i){
            if(v[i] != 0 && cnt % 2 == 1)
                -- v[i] , suma += i , ++ cnt;
            if(v[i] != 0 && cnt % 2 == 0)
                -- v[i] , sumb += i , ++ cnt;
            if( ! v[i])
                -- i;
        }
        pp = 0;
    }
    cout << suma - sumb;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define NIL -1

int main(){
    int n;
    scanf("%d",&n);
    int x[n+1],i;
    for(i=1;i<=n;i++)scanf("%d",&x[i]);
    int ans[n*n+1],first[n*n+1];
    for(i=1;i<=n*n;i++)ans[i]=NIL,first[i]=NIL;
    for(i=1;i<=n;i++)ans[x[i]]=i,first[x[i]]=i;
    
    int j=1,flag=1;  /*flag 1は真 0は偽*/
    
    while(j<=n*n){
        if(ans[j]!=NIL){
            int count=1,k=1;
            while(count<=ans[j]-1 && k<=j-1){
                if(ans[k]==NIL){
                    ans[k]=ans[j];
                    count++;
                }
                k++;
            }
            if(count!=ans[j])flag=0;
        }
        j++;
    }
    
    j=n*n;
    while(j>=1){
        if(first[j]!=NIL){
            int count=1,k=n*n;
            while(count<=n-ans[j] && k>=1){
                if(ans[k]==NIL){
                    ans[k]=ans[j];
                    count++;
                }
                k--;
            }
            if(count!=n-ans[j]+1)flag=2;
        }
        j--;
    }
    int Count[n+1];
    for(i=1;i<=n;i++)Count[i]=0;
    for(i=1;i<=n*n;i++){
        if(ans[i]==NIL)flag=3;
        else Count[ans[i]]++;
        
        if(first[i]!=NIL && Count[first[i]]!=first[i])flag=4;
        
    }
    
    
    if(flag!=1)printf("No\n");
    else{
        printf("Yes\n");
        for(i=1;i<=n*n;i++){
            printf("%d ",ans[i]);
        }
    }
    
    return 0;
}


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

const int LIM = 3000000;

char isprime[LIM];
int primes[LIM];
int PRIME_LIM = 0;

void eratosthenes() {
    fill(isprime, isprime + LIM, 1);
    isprime[0] = isprime[1] = 0;

    for(int x = 2; x * x < LIM; ++x) {
        if(!isprime[x]) continue;

        for(int y = x * x; y < LIM; y += x) {
            isprime[y] = 0;
        }
    }

    for(int x = 0; x < LIM; ++x) {
        if(isprime[x]) {
            primes[PRIME_LIM++] = x;
        }
    }
}

int solve(int N, int P) {
    vector<int> mtseq;
    int* ub = upper_bound(primes, primes + PRIME_LIM, N);

    for(int s = 0; s <= P; ++s) {
        for(int j = 0; j <= s; ++j) {
            int m = ub[s] + ub[j];
            mtseq.push_back(m);
        }
    }

    sort(begin(mtseq), end(mtseq));

    return mtseq[P - 1];
}

int main() {
    eratosthenes();
    int N, P;
    while(true) {
        cin >> N >> P;
        if(N == -1 && P == -1) break;
        cout << solve(N, P) << endl;
    }
    return 0;
}

Measured memory_bytes: 6540
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import defaultdict
    n, m, l = map(int, readline().split())
    dist = [[INF] * n for _ in range(n)]

    for _ in range(m):
        a, b, c = map(int, readline().split())
        a, b = a - 1, b - 1
        dist[a][b] = c
        dist[b][a] = c

    for k in range(n):
        for i in range(n):
            for j in range(n):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

    dist2 = [[INF] * n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            if dist[i][j] <= l:
                dist2[i][j] = 1

    for k in range(n):
        for i in range(n):
            for j in range(n):
                dist2[i][j] = min(dist2[i][j], dist2[i][k] + dist2[k][j])

    q = int(readline())

    for _ in range(q):
        s, t = map(int, readline().split())
        s, t = s - 1, t - 1
        if dist2[s][t] == INF:
            print(-1)
        else:
            print(dist2[s][t] - 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 82596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
int n;
vector<pair<double,double>> p;
double f(double x,double y){
    double res=0.0;
    rep(i,n){
        double dx=x-p[i].fi;
        double dy=y-p[i].se;
        double dd=sqrt(dx*dx+dy*dy);
        chmax(res,dd);
    }
    return res;
}
double g(double x){
    double l=0,r=1000;
    int cnt=100;
    while(cnt--){
        double c1=(l*2+r)/3;
        double c2=(l+r*2)/3;
        if(f(x,c1)>f(x,c2)) l=c1;
        else r=c2;
    }
    return f(x,l);
}
int main(){
    cin>>n;
    p=vector<pair<double,double>>(n);
    rep(i,n) cin>>p[i].fi>>p[i].se;
    int cnt=100;
    double l=0,r=1000;
    while(cnt--){
        double c1=(l*2+r)/3;
        double c2=(l+r*2)/3;
        if(g(c1)>g(c2)) l=c1;
        else r=c2;
    }
    double ans=g(l);
    cout<<fixed<<setprecision(10);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
// ref: https://img.atcoder.jp/arc093/editorial.pdf

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N; cin >> N;
    vector<int> vA(N+2, 0); for(int i=1; i<=N; ++i){ cin >> vA[i]; }
    int sum = 0ll; for(int i=1; i<=N+1; ++i){ sum += abs(vA[i]-vA[i-1]); }
    
    for(int i=1; i<=N; ++i){
        int bypass = abs(vA[i+1] - vA[i-1]); // for bipass
        int r = abs(vA[i+1] - vA[i]); // for rm pass
        int l = abs(vA[i] - vA[i-1]); // for rm pass
        cout << sum + bypass - l - r << endl;
    }
    
    return 0;
}

// 6
// -679 -2409 -3258 3095 -3291 -4462

// -4462 -3291 -3258 -2409 -679 3095
// 0 => -679 => -2409 => -3258 => 3095 => -3291 => -4462 => 0
//                        3258*2 +3095*2          + 4462*2 = 21630

// 0 => -679  =>  -2409   => -3258  =>  3095  => -3291  => -4462 => 0
// | 679 |  2409-679  |3258-2409|3095+3258|3291+3095|4462-3291| 4462|

/*
3
3 5 -1
vA     = [ 0 3 5 -1 0 ]
vA_sum = [ 0 3 5 11 12 ]
*/

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

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

    int n;
    cin >> n;

    int z = n * 3;
    vector< LL >v(z);
    for (int i = 0; i < z; i++) cin >> v[i];

    sort(v.rbegin(), v.rend());

    LL ans = 0;
    for (int i = 0, j = 1; i < n; i++, j += 2) {
        ans += v[j];
    }

    cout << ans << "\n";


    return 0;
}


Measured memory_bytes: 2560
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
A += [-1e10]
B += [-1e10]
C += [-1e10]

memo = [A[i] + B[0] + C[0] for i in range(X + 1)]
L = [[0 for i in range(Y + 1)] for j in range(X + 1)]

for i in range(K):
  ma = 0
  for j in range(X):
    if memo[ma] < memo[j]:
      ma = j
  print(memo[ma])
  mb = 0
  mn = 0
  for j in range(Y):
    x = B[j] + C[L[ma][j]]
    if mb < x:
      mb = x
      mn = j
  L[ma][mn] += 1
  n = 0
  for j in range(Y):
    n = max(n, B[j] + C[L[ma][j]])
  memo[ma] = A[ma] + n

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

int main () 
{
    int x, y;
    cin >> x >> y;
    
    while (!(x == 0 && y == 0)) {
        if (x > y) {
            swap(x, y);
        }
        
        cout << x << " " << y << endl;
        
        cin >> x >> y;
    }


    return 0;
} 


Measured memory_bytes: 3060
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author himkha_100
 */

#include <bits/stdc++.h>

#define MOD 1000000007
#define INFI 1e15
#define INFIM 1e18
#define ll long long int
#define s(t) scanf("%d",&t)
#define p(t) printf("%d\n",t)
#define pb push_back
#define f(t) for(int i=0;i<t;i++)
#define fi first
#define se second
#define all(t) t.begin(),t.end()
#define ci(t) cin>>t
#define co(t) cout<<t
#define mii map<int,int>
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
struct node{
    int val;
    int pos;
};
bool ac(int x,int y)
{
    return x>y;
}
class BFizzBuzzSum {
public:
	void solve(std::istream& cin, std::ostream& cout) {
        ll n;
        cin>>n;
        ll ans=0;
        for(int i=1;i<=n;i++) {
            if(i%3!=0&&i%5!=0) {
                ans+=i;
            }
        }cout<<ans<<endl;
	}
};

int main() {
	BFizzBuzzSum solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  int count = 0;
  for(int i = 0; i < N; i++){
    int a;
    int tmp_count = 0;
    cin >> a;
    while(true){
    	if(a % 2 == 0){
          tmp_count++;
          a /= 2;
        }else{
          break;
        }
    }
    if(i == 0 || tmp_count <= count){
      count = tmp_count; 
    }
  }
  cout << count << endl;
}

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

int bubbleSort(int A[], int N) {
    int sw = 0, temp;
    bool flag = true;

    while (flag) {
        flag = false;

        for (int i = 0; i < N-1; i++) {
            if (A[i] > A[i+1]) {
                flag = true;
                sw++;

                temp = A[i];
                A[i] = A[i+1];
                A[i+1] = temp;
            }
        }
    }

    return sw;
}

int main(int argc, char const *argv[]) {
    int N;
    cin >> N;
    int A[N];

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

    int sw = bubbleSort(A, N);
    for (int i = 0; i < N-1; i++) {
        cout << A[i] << ' ';
    }
    cout << A[N-1] << endl;
    cout << sw << endl;
    return 0;
}



Measured memory_bytes: 3088
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

n,m = map(int, input().split())
G = [[] for i in range(n)]
rG = [[] for i in range(n)]
used = [0]*n
for i in range(n+m-1):
    a,b = map(int, input().split())
    a,b = a-1, b-1
    G[a].append(b)
    rG[b].append(a)
    used[b] = 1
root = used.index(0)

par = [-1]*n
depth = [-1]*n

def rec(cur):
    if depth[cur] != -1:
        return depth[cur]
    m = 0
    i = -1
    for p in rG[cur]:
        if rec(p)+1 > m:
            i = p
            m = rec(p)+1
    par[cur] = i
    depth[cur] = m
    return m

for i in range(n):
    rec(i)
par = [i+1 for i in par]
print(*par, sep="\n")


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

#ifndef ONLINE_JUDGE
	#define W(x, y) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << y;
#else
	#define W(x, y)
#endif

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vii vector<pii>
#define vl vector<ll>
#define vll vector<pll>
// #define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pi acosl(-1)
#define ld long double
#define prime (1000000000 + 7)
#define INF 1000000000

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
    ll n, res = 0;
    cin >> n;
    vl vet(n);
    for(int i = 0; i < n; ++i){
        cin >> vet[i];
    }
    sort(vet.begin(), vet.end(), greater<ll>());
    for(int i = 1; i < n; ++i){
        res += vet[i/2];
    }
    cout << res << endl;
    

	return 0;
} 
// 1 2 3 4 6 12
// 0	1	2	3	4	5	6	7	8	9	10
// -	(	(	(	)	)	)	)	)	)	-
// 0	1	1	1	1	1	1	0	0	0	0
// 0	1	2	3	3	3	3	3	3	3	3
// 0	0	0	0	1	2	3	3	3	3	3
// 0	0	1	2	3	3	3	3	3	3	3



// 6 - 
// 5 - a
// 0 - ababba
// 2 - abba
// 4 - ba
// 1 - babba
// 3 - bba


// -$a
// -aa
// -aa
// -aa
// -a$

Measured memory_bytes: 4792
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;

int main(){
    int a,b,h;
    cin>>a>>b>>h;
    int ans =(a+b)*h;
    cout<<ans/2<<endl;
}


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

int main() {
    int n;
    int m;
  
   cin >> n >> m;
  
   int ans = n + m;
  
   if (ans > 9){
     
     cout << "error" << endl;
     
   }else{
     
     cout << ans << endl;
   }
  
  
   
   
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	map<char,int>m;
	map<char,int>::iterator it;
	for(int i=0;i<s.size();i++)
	{
		m[s[i]]++;
	}
	for(it=m.begin();it!=m.end();it++)
	{
		if(it->second%2!=0)
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	
	
}

Measured memory_bytes: 3620
import java.util.*;

public class Main {
    static int max = -1;
    static Set<Integer>[] from;
    static Set<Integer>[] to;
    
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        
        from = new Set[n];
        for (int i = 0; i < n; i++) {
            from[i] = new HashSet<Integer>();
        }
        to = new Set[n];
        for (int i = 0; i < n; i++) {
            to[i] = new HashSet<Integer>();
        }
        
        // リストの作成
        for (int i = 0; i < m; i++) {
            int s = sc.nextInt() - 1;
            int t = sc.nextInt() - 1;
            from[t].add(s);
            to[s].add(t);
        }
        
        // que: 親がいない点のキュー
        Queue<Integer> que = new ArrayDeque<Integer>();
        for (int i = 0; i < n; i++) {
            if (from[i].size() == 0) {
                que.add(i);
            }
        }
        
        // counter[i]: 点iまでの最長距離
        int[] counter = new int[n];
        
        while (!que.isEmpty()) {
            int p = que.poll();
            for (Integer q : to[p]) {
                counter[q] = Math.max(counter[q], counter[p] + 1);
                max = Math.max(max, counter[q]);
                from[q].remove(p);
                
                if (from[q].size() == 0) {
                    que.add(q);
                }
            }
        }
        
        System.out.println(max);
    }
    // 頂点pと隣接する点に自分の値+1を配ることで距離を与える
    public static void dfs(int p, int d, int par) {
        max = Math.max(max, d);
        
        for (Integer q : to[p]) {
            if (q == par) continue;
            
            dfs(q, d+1, p);
        }
    }
}

Measured memory_bytes: 138176
from collections import deque


def main():
    n, *a = map(int, open(0).read().split())
    dq = deque()
    n -= 1
    for i, ai in enumerate(a):
        if i % 2 == n % 2:
            dq.appendleft(ai)
        else:
            dq.append(ai)
    print(" ".join(map(str, dq)))
    return


main()


Measured memory_bytes: 29660
#include <stdio.h>
    #include <string.h>
     
    int main(){
        int n, cep = 0, wrong = 0, limit = 0, runt = 0;
        scanf("%d", &n);
        char ved[4];
        
        for (int i = 0; i < n; ++i){
            scanf("%s", ved);
            
            if (strcmp(ved, "AC") == 0)
                cep += 1;
            else if (strcmp(ved, "WA") == 0)
                wrong += 1;
            else if (strcmp(ved, "TLE") == 0)
                limit += 1;
            else
                runt += 1;
        }
        printf("AC x %d\n", cep);
        printf("WA x %d\n", wrong);
        printf("TLE x %d\n", limit);
        printf("RE x %d\n", runt);
     
     
        return 0;
    }

Measured memory_bytes: 1708
#include <iostream>
#include <unordered_set>
#include <cstdint>
#include <vector>
#include <sstream>
#include <string>
#include <climits>
#include <set>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <numeric>
#include <map>
using namespace std;

int main()
{
	string str;
	cin >> str;
	int n = str.length();
	int cnt = 0;

	for (int i = 0; i < n / 2; i++)
	{
		if (str[i] != str[n - i - 1])
		{
			cnt++;
			str[i] = str[n - 1];
		}
	}

	cout << cnt;
}

Measured memory_bytes: 3624
n,x = list(map(int, input().split()))
l = list(map(int, input().split()))
#print(l)
a = [0]
#a[0] = 0
#a[1] = l[0]
ans = 0
d = 0
for i in range(0,len(l)):
  a.append(d+  l[i])
  d = d+ l[i]
  if x >= d:
    ans+=1
    
print(ans+1)    
#print(a)

Measured memory_bytes: 3064
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  a=LI()
  b=[]
  for x in a:
    b.append(x-1)
    b.append(x)
    b.append(x+1)

  b.sort()
  c=1
  mx=1
  d=b[0]
  for x in b[1:]:
    if d==x:
      c+=1
    else:
      mx=max(mx,c)
      c=1
      d=x

  return mx

print(main())


Measured memory_bytes: 22552
import itertools

n,m=map(int,input().split())
uselist=[]
for _ in range(m):
    ad=list(map(int,input().split()))
    uselist.append(ad)
cnt=0
for i in itertools.permutations(range(1,n+1)):
    if i[0]==1:
        flag=True
        for j in range(n-1):
            if [i[j],i[j+1]]  not in uselist and [i[j+1], i[j]] not in uselist:
                flag =False
                break
            else:
                continue
        if flag==True:
            cnt+=1
        else:
            continue
        
print(cnt)            


Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string.h>
#include <stdlib.h>
#include <limits>
#include <iomanip>
using namespace std;

int main(){

    int N, R;
    cin >> N >> R;

    int ans = 0;

    if( N < 10 ){
        ans = R + 100 * (10 - N);
    }else{
        ans = R;
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
L = (10, 50, 100, 500)

def calc(N):
    ret = [0] * 4
    r = sum(L[i] * N[i] for i in xrange(4)) - M
    for i in xrange(3, -1, -1):
        ret[i] += r / L[i]
        r -= ret[i] * L[i]
    return ret

M = int(raw_input())
while M != 0:
    N = map(int, raw_input().split())
    for i, n in zip(L, map(lambda a, b: max(0, a - b), N, calc(N))):
        if n == 0:
            continue
        print i, n
    M = int(raw_input())
    if M == 0:
        break
    print

Measured memory_bytes: 4244
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int N, A, B;
    cin >> N >> A >> B;
    int h[N], max=0;
    REP(i,N){
        cin >> h[i];
        chmax(max, h[i]);
    }
    int l = 0, r = ceil((double)max/B);
    int T = (l+r)/2, add = A-B;
    while(r-l > 1){
        ll num = 0;
        REP(i,N){
            if(h[i] > B*T){
                num += ceil((double)(h[i]-B*T) / add);
            }
        }

        if(T < num) l = T;
        else r = T;
        T = (l+r)/2;
    }

    cout << r << endl;
    return 0;
}

Measured memory_bytes: 640
# coding:utf-8
n = int(input())
a = list(map(int, input().split()))
money = 1000

for i in range(n - 1):
    stock = 0
    if a[i] < a[i + 1]:
        stock = money // a[i]
    money += (a[i + 1] - a[i]) * stock

print(money)


Measured memory_bytes: 9168
#include <string>
#include <iostream>
using namespace std;
int main(){
	int N, L, sum = 0;
	cin >> N;
	cin >> L;
	if(L >= 0){
		sum = (L + L+N-1) * N / 2 - L;
	}else if(L+N-1 <= 0){
		sum = (L + L+N-1) * N / 2 - (L+N-1);
	}else if(L < 0 && (L + L+N-1) > 0){
		sum = (L + L+N-1) * N / 2;
	}
	cout << sum;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[10005][2];
set<long long> s;
int main(){
	long long n;
	cin>>n;
	long long cnt = 0;
	for(long long i=1;(i-1)*(i-1)<=n;i++){
	//	cout<<1111<<endl;
		long long t = n-i;
		if(t&&t%i==0&&i==n/(t/i)){
			cnt+=(t/i);
		}
	}
	cout<<cnt<<endl;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define REP(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) (flag)?1:0
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ================================================

// Template End ======================================================

int main(void){
  int N,M; cin>>N>>M;
  vec<int> A(N); cin>>A;
  map<ll,ll> mp; ++mp[0];
  ll asum=0;
  rep(i,N){
  	asum+=A[i];
  	++mp[asum%M];
  }
  
  ll ans=0;
  ran(i,mp){
  	if(i.second==1) continue;
  	ans+=i.second*(i.second-1)/2;
  }
  cout<<ans;
}














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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int maxn = 1e6 + 5;

int n,a;

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

  cin>>n>>a;
  for (int x=0; x<1e9; x++) {
    if (x*500 > n) break;
    int y = n - 500*x;
    if (y<=a) out("Yes");
  }
  out("No");
  

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

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

    if (n % 2) {
        cout << n / 2 << endl;
    } else {
        cout << n / 2 - 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define first F
#define second S

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  int ans=0;
  int m=INF;
  rep(i,3){
    cin>>n;
    m=min(m,n);
  }
  ans+=m;
  m=INF;
  rep(i,2){
    cin>>n;
    m=min(m,n);
  }
  ans+=m;
  cout<<ans-50<<endl;
}

Measured memory_bytes: 3080
package main

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

var sc = bufio.NewScanner(os.Stdin)

func read() string {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Scan()
	return sc.Text()
}

func geti() int {
	n, _ := strconv.Atoi(read())
	return n
}

// 10 11 12 => [10, 11, 12]
func getli(size int) []int {
	a := make([]int, size)
	list := strings.Split(read(), " ")
	for i, s := range list {
		n, _ := strconv.Atoi(s)
		a[i] = n
	}
	return a
}

func get2byte(size int) [][]byte {
	a := make([][]byte, size)
	for i := 0; i < size; i++ {
		var low string
		fmt.Scan(&low)
		a[i] = []byte(low)
	}
	return a
}

func transpose(a [][]int) {
	n := len(a)
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			a[i][j], a[j][i] = a[j][i], a[i][j]
		}
	}
}

func fact(n, m int) int {
	res := 1
	for i := m + 1; i <= n; i++ {
		res *= i
	}
	return res
}

func perm(n, r int) int {
	if r > n {
		return 0
	}
	return fact(n, n-r)
}

func comb(n, m int) int {
	if m > n {
		return 0
	}
	return fact(n, n-m) / fact(m, 0)
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func main() {
	N := 2019
	s := read()
	m := make([]int, N)
	total := 0
	ten := 1
	for i := 0; i < len(s); i++ {
		n, _ := strconv.Atoi(s[len(s)-1-i : len(s)-i])
		total += (n * ten) % N
		ten = (ten * 10) % N
		m[total%N]++
	}
	sum := m[0]
	for _, v := range m {
		sum += v * (v - 1) / 2
	}
	fmt.Println(sum)
}


Measured memory_bytes: 2432
import java.util.*;
public class Main {
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	String S = sc.next();
        int cnts[] = new int[2019];
        int d = 1;
		int sum_of_digits=0;
      cnts[0]=1;
        for (int i=S.length()-1;i>=0;i--){
            sum_of_digits += Integer.parseInt(S.substring(i,i+1))*d;
            sum_of_digits%=2019;
            d*=10;
          	d%=2019;
            cnts[sum_of_digits]++;
     //     System.out.println(sum_of_digits);
        }
        int ans =0;
        for (int i=0;i < 2019;i++){
            ans += cnts[i]*(cnts[i]-1)/2;
        }
      System.out.println(ans);
            
    }

}



Measured memory_bytes: 40568
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int main(){
	int n, k;
	cin >> n >> k;
	ll answer = 0;
	for(int b = k+1; b<= n; b++){
		if(k == 0) answer-- ;
		answer += (n/b)*(b-k);
		int sub = n%b - k + 1;
		if(sub > 0) answer += sub;
	}

	cout << answer << endl;
}


Measured memory_bytes: 3576
#include <iostream>
#include <cmath>
#include <string>

using namespace std;

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

	if ((s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) || 
		(s[0] == s[2] && s[1] == s[3] && s[0] != s[1]) || 
		(s[0] == s[3] && s[1] == s[2] && s[0] != s[1])) {
		cout << "Yes" << endl;
		return 0;
	}

	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

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

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

ll mod(ll val, ll M) {
    ll res = val % M;
    if(res < 0) {
        res += M;
    }
    return res;
}

// N^P mod M（ただしM == -1の時はmodを取らない）
template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    int N;
    ll K;
    cin >> N >> K;
    vector<int> P(N);
    for(int i = 0;i < N;i++) {
        cin >> P.at(i);
        P.at(i)--;
    }
    vector<ll> C(N);
    for(int i = 0;i < N;i++) {
        cin >> C.at(i);
    }
    ll ret = -INF;
    for(int i = 0;i < N;i++) {
        vector<bool> used(N);
        vector<int> roop;
        int itr = i;
        while(true) {
            itr = P.at(itr);
            if(used.at(itr) == true) {
                break;
            }
            used.at(itr) = true;
            roop.push_back(C.at(itr));
        }
        ll siz = roop.size();
        ll Sum = 0;
        for(int j = 0;j < roop.size();j++) {
            Sum += roop.at(j);
        }
        ll Sum2 = 0;
        ll res = -INF;
        for(int j = 0;j < roop.size();j++) {
            if(K <= j) {
                continue;
            }
            Sum2 += roop.at(j);
            ll res2 = 0;
            ll cnt = K - (j + 1);
            if(Sum > 0) {
                res2 += Sum * (cnt / siz);
            }
            res2 += Sum2;
            chmax(res,res2);
        }
        chmax(ret,res);
    }
    cout << ret << endl;
}

Measured memory_bytes: 3748
n = int(input())
s = input()
c_list = [(0, 0, 0) for i in range(n)]
r = 0
g = 0
b = 0
n_list = [0]*n
p = -1
for i in range(n):
  if s[i] == "R":
    r += 1
    p = 0
  elif s[i] == "G":
    g += 1
    p = 1
  else:
    b += 1
    p = 2
  c_list[i] = (r, g, b)
  n_list[i] = p
count = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    c1 = n_list[i]
    c2 = n_list[j]
    if c1 != c2:
      if j+j-i < n and 3 - n_list[j+j-i] - c1 - c2 == 0:
        count += c_list[n-1][3-c1-c2] - c_list[j][3-c1-c2] -1
      else:
        count += c_list[n-1][3-c1-c2] - c_list[j][3-c1-c2]
print(count)
        
  

Measured memory_bytes: 69032
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
using namespace std;
int main() {
	int count = 0, n, ans = 0;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		count = 0;
		for (int j = 1; j <= n; ++j) {
			if (i%j == 0 && i % 2 == 1) count++;
		}
		if (count == 8) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    int K, S;
    cin >> K >> S;
    int count = 0;
    for (int X = 0; X <= K; ++X)
    {
        for (int Y = 0; Y <= min(S - X, K); ++Y)
        {
            int Z = S - X - Y;
            if (0 <= Z && Z <= K) ++count;
        }
    }
    cout << count << endl;

    return 0;
}

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

using namespace std;

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    vector<vector<int>> candles(2);
    for (int i = 0; i < 2; i++)
    {
        int p;
        vector<int> c;
        for (int j = 0; j < n; j++)
        {
            cin >> p;
            // cout << "p is :" << p << endl;
            c.push_back(p);
        }
        candles[i] = c;
    }
    //cout << "input done" << endl;
    //cout << candles[0][0] << " " << candles[1][0] << endl;
    vector<vector<int>> dp(2);
    vector<int> row(n);
    dp[0] = row;
    dp[1] = row;
    dp[0][0] = candles[1][n - 1];
    dp[1][0] = candles[1][n - 1];
    // cout << "dp array" << endl;
    // cout << dp[0][0] << " " << dp[1][0] << endl;
    for (int i = 1; i < n; i++)
    {
        dp[0][i] = max(dp[0][i - 1], dp[1][i - 1]) + candles[0][n - i];
        dp[1][i] = candles[1][n - i - 1] + dp[1][i - 1];
        //cout << dp[0][i] << " " << dp[1][i] << endl;
    }
    cout << max(dp[0][n - 1], dp[1][n - 1]) + candles[0][0];
    // int right = max(dp[0][n - 1], dp[1][n - 1]) + candles[0][0];
    // int down = candles[0][0] + candles[1][0] + dp[1][n - 1];
    // cout << max(right, down);
    return 0;
}


Measured memory_bytes: 256
s=input()
l=len(s)

from itertools import product
bits=list(product([0,1], repeat=l-1))

ans=0
for bit in bits:
    tmp_s=s
    cnt=0
    for i in range(l-1):
        if bit[i]==1:
            tmp_s=tmp_s[:i+1+cnt]+'+'+tmp_s[i+1+cnt:]
            cnt+=1
    ans+=eval(tmp_s)

print(ans)


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

int main(void){
    int n, h, w;
    cin >> n >> h >> w;
    vector<int> a(n);
    vector<int> b(n);
    int i, ans;

    for(i = 0, ans = 0;i < n; i++){
        cin >> a.at(i) >> b.at(i);
        if(a.at(i) >= h && b.at(i) >= w){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int N=200005;


void solve()
{
    
    int n,x;
    cin>>x>>n;
    int is[103]={0},a;
    for(int i=1;i<=n;i++)
    {
        cin>>a;
        is[a]=1;
    }
    if(x>100)
    {
        cout<<x<<endl;
        return;
    }
    int mn=INF,ans=0;
    for(int i=0;i<=102;i++)
    {
        if(!is[i]&&(abs(x-i))<mn)
        {
            mn=abs(x-i);
            ans=i;
        }
    }
    cout<<ans<<endl;
    
    
}



int32_t main()
{
    IOS;
    
    int t;
    t=1;
    // cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3696
import java.util.*

fun main(args : Array<String>) {
    val sc = Scanner(System.`in`)
    val N = sc.nextLong()
    var total = 0L
    for (i in 1 .. N) {
        if (i % 3 == 0L || i % 5 == 0L) {
            continue
        }
        total += i
    }
    println(total)
}


Measured memory_bytes: 36352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
   long long N;
   cin >> N;
   vector<long long> A(N);
   for (int i=0;i<N;i++) {
       cin >> A[i];
   }
   sort(A.begin(),A.end());
   reverse(A.begin(),A.end());
   
   long long ans=A[0];
   if(N!=2) {
   for (int i=1;i<N/2;i++) {
       ans+=2*A[i];
   } 
   if (N%2==1) {
       ans+=A[N/2];
   }
   }
   cout << ans << endl;
}

Measured memory_bytes: 4788
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
template<typename T>void read(T &x){
	x=0;int f(1);char c(getchar());
	for(;!isdigit(c);c=getchar())if(c=='-')f=-f;
	for(; isdigit(c);c=getchar())x=(x<<3)+(x<<1)+(c-'0');
	x*=f;
}
template<typename T>void write(T x){
	if(x<0)putchar('-'),x=-x;
	if(x/10)write(x/10),x%=10;
	putchar(x+'0');
}
int main(){
	int a,b,k;
	read(k),read(a),read(b);
	puts((a-1)/k==b/k?"NG":"OK");
	return 0;
}


Measured memory_bytes: 3636