akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
from bisect import bisect_left
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ans += bisect_left(L, L[i]+L[j]) - 1 - j
print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int mex=5001;
#define ll long long 
#define test int t;cin>>t;while(t--)
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(i,a,n) for(int i=a;i<n;i++)
#define rfo(i,a,b) for(int i=a;i>=b;i--)
#define bg begin()
#define en end()
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define pb push_back
#define veci vector<int>
#define veclli vector<long long int> 
#define all(x) x.begin(),x.end()
#define sci(x) scanf("%d",&x);
#define scc(x) scanf("%c",&x);
#define scs(x) scanf("%s",x);
#define debug(arr,n) for(int i=0;i<n;i++) printf("%d ",arr[i]);
#define sz(x) x.size()
#define loop(x) for(auto it=x.begin();it!= x.end();it++) 
 
 
 
int main()
{
  int n;
  cin>>n;
  string s;
  cin>>s;
  map<char,int> mp;
  ll int ans=0;
  fo(i,0,n)
  {fo(j,i+1,n)
  {
	  if(s[i]==s[j]) continue;
	  if(s[i]!='R'&&s[j]!='R')
	  {
		  ans+=mp['R'];
		  int u=j-i;
		  if(i>=u&&s[i-u]=='R') ans--;
	  }
	  if(s[i]!='G'&&s[j]!='G')
	  {
		  ans+=mp['G'];
		  int u=j-i;
		  if(i>=u&&s[i-u]=='G') ans--;
	  }
	  if(s[i]!='B'&&s[j]!='B')
	  {
		  ans+=mp['B'];
		  int u=j-i;
		  if(i>=u&&s[i-u]=='B') ans--;
	  }
  }
  mp[s[i]]++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>
#include<queue>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int h, w;
vector<string> a;

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

bool inside(int y, int x){
    if(y < 0 || h <= y) return false;
    if(x < 0 || w <= x) return false;
    return true;
}

int main(){
    cin >> h >> w;
    a = vector<string>(h);
    for(int i = 0; i < h; i++){
        cin >> a[i];
    }
    vector<vector<int>> d(h, vector<int>(w, INF));
    queue<pair<int, int>> q;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(a[i][j] == '#'){
                d[i][j] = 0;
                q.push({i, j});
            }
        }
    }
    while(!q.empty()){
        auto p = q.front(); q.pop();
        for(int k = 0; k < 4; k++){
            int ny = p.first + dy[k], nx = p.second + dx[k];
            if(!inside(ny, nx)) continue;
            if(d[ny][nx] <= d[p.first][p.second] + 1) continue;
            d[ny][nx] = d[p.first][p.second] + 1;
            q.push({ny, nx});
        }
    }
    int ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            ans = max(ans, d[i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 13456
#include <bits/stdc++.h>
#define ll long long
#define P pair<int,int>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n;
    cin>>n;
    vector<ll> a(n);
    vector<ll> b(n);
    vector<ll> c(n);
    for(int i = 0; i<n; i++){
        cin>>a[i];
    }
    for(int i = 0; i<n; i++){
        cin>>b[i];
    }
    for(int i = 0; i<n; i++){
        cin>>c[i];
    }
    sort(a.begin(),a.end());
    sort(c.begin(),c.end());
    ll ans;
    
    for(int i = 0; i<n; i++){
        ll up = lower_bound(a.begin(),a.end(),b[i]) - a.begin();
        ll btm = c.end() - upper_bound(c.begin(),c.end(),b[i]);
        ans += up*btm;
    }
    cout<< ans <<endl;
}


Measured memory_bytes: 2560
public class Main
{
	public static void main(String[] args) throws java.io.IOException
	{
		java.io.BufferedReader br = new java.io.BufferedReader( new java.io.InputStreamReader( System.in ) );
		
		String[] st = br.readLine().split(" ");
		int[] nums = new int[st.length];
		for( int i = 0 ; i < nums.length ; i++ ) nums[i] = Integer.parseInt( st[i] );
		
		
		int x;
		boolean exchange = true;
		while( exchange )
		{
			exchange = false;
			for( int i = 0 ; i < (nums.length - 1) ; i++ )
			{
				if( nums[i] > nums[i+1] )
				{
					x = nums[i];
					nums[i] = nums[i+1];
					nums[i+1] = x;
					exchange = true;
				}
			}
		}
		
		String result = "";
		for( int i = 0 ; i < nums.length ; i++ )
		{
			 if( i < (nums.length -1) ){
				 result += ( nums[i] + " " );
			}else{
				result += nums[i];
			}
		}
		System.out.println( result );
	}
}

Measured memory_bytes: 24152
N = int(input())
H = [int(i) for i in input().split()]
count = 0
tmpcount = 0

for i in range(N-1):
    if H[i+1] <= H[i]:
        tmpcount += 1
        if tmpcount > count:
            count = tmpcount
    else:
        tmpcount = 0

print(count)


Measured memory_bytes: 14252
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(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 repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	ll ans=0;
	cin >>n;
	V a(n+1),b(n);
	rep(i,n+1){
		cin>>a[i];
	}rep(i,n){
		cin>>b[i];
	}
	rep(i,n){
		if(a[i]> b[i]){
			ans+=b[i];
			a[i]-=b[i];
			b[i]=0LL;
		}else{
			ans+=a[i];
			b[i]-=a[i];
			a[i]=0LL;
		}
		if(a[i]==0){
			ans+=min(a[i+1],b[i]);
			if(a[i+1] >b[i]){
				a[i+1]-=b[i];
				b[i]=0;
			}else{
				a[i+1]=0;
			}
		}
		//clog<<ans<<endl;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
from collections import defaultdict
n=int(input())
a_=list(map(int,input().split()))
import numpy as np
a=[]
for i,ai in enumerate(a_):
      a.append([1+i,ai])
a.sort(key=lambda x:x[1],reverse=True)
dp=np.zeros((n+1,n+1),np.int64) #dp[i,j]:i人目までを配置し終えていて、そのうちj人を右に置いた時の最大値。j<=i
dp[1,1]=a[0][1]*(n-a[0][0])
dp[1,0]=a[0][1]*(a[0][0]-1)
for i in range(2,n+1):#i人目の幼児。a[i-1]
      dp[i,0]=dp[i-1,0]+a[i-1][1]*abs((a[i-1][0]-1-(i-1))) #i人目を左にする。その時左に溜まっているのはi-1人
      dp[i,i]=dp[i-1,i-1]+a[i-1][1]*abs((n-a[i-1][0]-(i-1))) #i人目を右にする。その時右に溜まっているのはi-1人
      #i人目を左に
      l=dp[i-1,1:i]+[a[i-1][1]*abs((a[i-1][0]-1-j))for j in range(i-2,-1,-1)] #j:左に溜まっている人数
      #i人目を右に
      r=dp[i-1,:i-1]+[a[i-1][1]*abs((n-a[i-1][0]-j)) for j in range(i-1)] #j:右に溜まっている人数
      dp[i,1:i]=np.maximum(l,r)
print(max(dp[n]))


Measured memory_bytes: 50176
import Queue
while True:
    n = input()
    if n==0:
        break
    a = []
    nxt = [range(n) for i in xrange(2)]
    for i in xrange(2):
        a.append(map(int, raw_input().split()))
    for i in xrange(2):
        back = 0
        for j in xrange(n):
            if a[i][j]==2:
                nxt[i][j] = back
            else:
                back = j
        forw = n-1
        for j in xrange(n-1,-1,-1):
            if a[i][j]==1:
                nxt[i][j] = forw
            else:
                forw = j-1
    cost = [[10**9] * n for i in xrange(2)]
    que = Queue.PriorityQueue()
    cost[0][nxt[0][0]] = 0
    cost[1][nxt[1][0]] = 0
    que.put((0, 0, nxt[0][0]))
    que.put((0, 1, nxt[1][0]))
    ans = -1
    while not que.empty():
        co, sd, st = que.get()
        if st==n-1:
            ans = co
            break
        if cost[sd][st] < co:
            continue
        for i in xrange(3 if st+2<n else 2):
            step = nxt[sd^1][st+i]
            if co+1 < cost[sd^1][step]:
                cost[sd^1][step] = co+1
                que.put((co+1, sd^1, step))
    print "NA" if ans==-1 else ans

Measured memory_bytes: 4860
import scala.io.StdIn._
import scala.math._

object Main extends App with StdInHelper {
  val n = readInt
  val as = readLongs

  if (as.contains(0L)) {
    println(0)
  } else {
    var res = 1L
    val b = new scala.util.control.Breaks
    b.breakable {
      for (a <- as) {
        var temp = res * a
        if (pow(10, 18).toLong < temp || temp <= 0L) {
          res = -1L
          b.break
        } else {
          res = res * a
        }
      }
    }
    println(res)
  }
}

trait StdInHelper {
  def readInts = readLine.split(" ").map(_.toInt)
  def readLongs = readLine.split(" ").map(_.toLong)
}


Measured memory_bytes: 68600
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define MOD 1000000007
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 100005

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unordered_map<int,int> umii;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

ll gcd(ll a, ll b) {return b == 0 ? a : gcd(b, a % b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int len;
ll cap,dp[MAXN];

int main(){
    scanf("%d %lld",&len,&cap);
    for(int i=1; i<=1e5; i++) dp[i] = LONG_MAX;
    dp[0] = 0;
    for(int q=1; q<=len; q++){
        ll w; int val; scanf(" %lld %d",&w,&val);
        for(int i=1e5; i>=0; i--){
            if(dp[i] == LONG_MAX) continue;
            dp[i+val] = min(dp[i+val],dp[i]+w);
        }
    }
    for(int i=1e5; i>=0; i--){
        if(dp[i] <= cap){
            printf("%d\n",i);
            return 0;
        }
    }
}


Measured memory_bytes: 1024
n,m=map(int,input().split())
SC=[list(map(int,input().split())) for _ in range(m)]

for i in range(999):
  i=list(str(i))
  flag=True
  for s,c in SC:
    if s-1>=len(i): break
    if int(i[s-1])!=c: break
  else:
    if len(i)==n:
      print(*i,sep='')
      exit()
print(-1)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("sse4,avx,tune=native")
using namespace std;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }

constexpr int b = 80 * 80;
constexpr int M = b * 2 + 1;

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

    int H, W;
    cin >> H >> W;
    vector<int> A(H * W), B(H * W);
    cin >> A >> B;

    vector<bitset<M>> dp(W + 1);
    dp[1][b] = 1;
    int k = 0;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            int d = abs(A[k] - B[k]);
            dp[j + 1] |= dp[j];
            dp[j + 1] = (dp[j + 1] << d) | (dp[j + 1] >> d);
            k++;
        }
    }
    printf("%d", dp.back()._Find_next(b - 1) - b);
}


Measured memory_bytes: 512
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

def main():
    for line in sys.stdin:
        n = int(line)
        cnt = 0
        for a in range(0,10):
            for b in range(0,10):
                for c in range(0,10):
                    for d in range(0,10):
                        if a+b+c+d==n: cnt += 1
        print(cnt)


if __name__ == "__main__": main()

Measured memory_bytes: 7728
using System;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            string serch_word,sample_word="";
            int ans = 0;

            var read_text = Console.ReadLine();
            serch_word = read_text;
            while (true)
            {
                //??????????????????
                read_text = Console.ReadLine();
                if (read_text == "END_OF_TEXT")
                    break;
                sample_word += read_text+" ";

            }
            var sample_word_arry = sample_word.ToLower().Split(' ');

            //?????????????´¢
            foreach(string s in sample_word_arry)
            {
                if(s==serch_word)
                {
                    ans++;
                }
            }

            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define fi first
#define se second
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
//const ll mod=1000000007;
ll mod;
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

const int N=210;
int dp[N][N],comb[N][N];
int n,k;
void upd(int &a,int b) {
	a+=b; if (a>=mod) a-=mod;
}

int calc(int n,int m,int a,int b) {
	int ans=comb[n+m][n];
	PII p(0,0); int sg=0;
	while (1) {
		if (sg==0) p=mp(p.se-a,p.fi+a);
		else p=mp(p.se-b,p.fi+b);
		if (p.fi>n||p.se>m) break;
		if (sg==0) ans=(ans+mod-comb[n+m][n-p.fi])%mod;
		else ans=(ans+comb[n+m][n-p.fi])%mod;
		sg^=1;
	}
	p=mp(0,0); sg=0;
	while (1) {
		if (sg==0) p=mp(p.se-b,p.fi+b);
		else p=mp(p.se-a,p.fi+a);
		if (p.fi>n||p.se>m) break;
		if (sg==0) ans=(ans+mod-comb[n+m][n-p.fi])%mod;
		else ans=(ans+comb[n+m][n-p.fi])%mod;
		sg^=1;
	}
	return ans;
}
int solve(int x,int y) {
	if (y<0) return 0;
	if (y==0) return x<=1;
	int ans=0;
	for (int a=2;a<=y+1;a++) {
		int b=x-a;
		if (b<1||b>y+1) continue;
		int t=calc(a-1,b,b-(y+2),(y+2)-a);
		if (a+b<=y+1) upd(t,mod-1);
		upd(ans,t);
	}
	return ans;
}

int main() {
	scanf("%d%d%lld",&n,&k,&mod);
	for (int i=0;i<=2*n;i++) {
		comb[i][0]=comb[i][i]=1;
		rep(j,1,i) comb[i][j]=(comb[i-1][j-1]+comb[i-1][j])%mod;
	}
	int ans=0;
	for (int deg=0;deg<=n-2;deg++) {
		ans=(ans+(ll)solve(n-deg,k-deg)*powmod(n-deg,mod-2))%mod;
	}
	if (k>=n-1) {
		ans=(ans+1)%mod;
	}
	rep(i,1,n+1) ans=(ll)ans*i%mod;
	printf("%d\n",ans);
}

Measured memory_bytes: 4076
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    
    bitset<4000001> bs;
    bs.set(0);
    
    for(auto elm : a){
        bs |= bs<<elm;
    }
    
    int sum = accumulate(all(a),0);
    
    for(int i=(sum+1)/2;i;i++){
        if(bs[i]){
            cout<<i<<endl;
            break;
        }
    }
}


Measured memory_bytes: 1664
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")
    };
}

pub fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}
pub fn lcm(a: u64, b: u64) -> u64 {
    a / gcd(a, b) * b
}

fn main() {
    input! {
        n: u64
    }
    println!("{}", lcm(2,n));
}


Measured memory_bytes: 4352
#include <stdio.h>

int main(){
  int x,y,z;

  scanf("%d%d",&x,&y);

  if ((x>=1 && x<=1000000000) && (y>=1 && y<=1000000000)){
    if (x>=y){
      while(1){
	z = x%y;
	if (z == 0) break;
	x = y;
	y = z;
      }
      printf("%d\n",y);
    }
    else{
      while(1){
	z = y%x;
	if (z == 0) break;
	y = x;
	x = z;
      }
      printf("%d\n",x);
    }
  }

  return 0;
}



Measured memory_bytes: 2104
#include<iostream>
using namespace std;
#define int long long int
#define inf 1000000000000000000
bool check(int arr[],int n,int i,int j,int k)
{
	int status=0;
	int p;
	for(p=0;p<n;p++)
	{
		if(status==0)
		{
			if(arr[p]==i)
			   status++;
		}
		else if(status==1)
		{
			if(arr[p]==j)
			   status++;
		}
		else if(status==2)
		{
			if(arr[p]==k)
			   status++;
			if(status==3)
			    return true;
		}
	}
	return false;
}
int32_t main()
{
	 int n;
	 cin>>n;
     string str;
     cin>>str;
     int arr[n];
     int i,j,k;
     int answer=0;
     for(j=0;j<n;j++)
         arr[j]=str[j]-48;
     for(i=0;i<=9;i++)
     {
		 for(j=0;j<=9;j++)
		 {
			 for(k=0;k<=9;k++)
			 {
				 bool result=check(arr,n,i,j,k);
				 if(result)
				    answer++;
			 }
		 }
	 }
	 cout<<answer<<endl;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(){
    int m,f,r;
    
    while(1){
        scanf("%d%d%d",&m,&f,&r);
        if (m == -1 && f == -1 && r == -1)
            break;
        else if (m == -1 || f == -1)
            printf("F\n");
        else if ((m + f) >= 80)
            printf("A\n");
        else if ( (m + f) >= 65)
            printf("B\n");
        else if ((m + f) >= 50)
            printf("C\n");
        else if ((m + f) >= 30)
            if (r >= 50)
                printf("C\n");
            else
                printf("D\n");
        else
            printf("F\n");
    }
    
    return 0;
}


Measured memory_bytes: 2140
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,i,la,m,a[100010],sum,j,b[5];
int main(){
	scanf("%d",&n);
	if(n==3){
		puts("2 5 63");return 0;
	}
	if(n<=20){
		a[1]=2;a[2]=4;a[3]=3;a[4]=9;la=12;
		for(i=5;i<=n;i++){
			a[i]=la;la+=6;
		}
		for(i=1;i<=n;i++)printf("%d ",a[i]);
		return 0;
	}
	b[1]=2;b[2]=4;b[3]=3;b[4]=6;
	for(i=1;i<=5000;i++){
		a[++m]=b[1];a[++m]=b[2];a[++m]=b[3];a[++m]=b[4];
		for(j=1;j<=4;j++)b[j]+=6;
	}
	for(i=1;i<=n;i++){sum=(sum+a[i])%6;
	}
	if(sum!=0){
		if(n%4==0){
			a[n-1]+=9;
		}
		if(n%4==1){
			if(n%8==1)a[n]+=4;
			 else{
			 	a[n-1]+=4;a[n-2]+=9;
			 }
		}
		if(n%4==2){
			a[n-3]+=9;
		}
		if(n%4==3){
			a[n]+=3;
		}
	}
	for(i=1;i<=n;i++)printf("%d ",a[i]);
}

Measured memory_bytes: 3876
#include <bits/stdc++.h>
using namespace std;
const int mx = 100100100;

int main(){
  int n;
  cin >> n;
  queue<int> que;
  int ans = 0;
  que.push(3);
  que.push(5);
  que.push(7);
  while(que.front() <= n){
    int x = que.front();
    que.pop();
    bool f1 = false, f2 = false, f3 = false;
    int m = x;
    while(m > 0){
      if(m %10 == 3) f1 = true;
      if(m %10 == 5) f2 = true;
      if(m %10 == 7) f3 = true;
      m /= 10;
    }
    if(f1 && f2 && f3) ++ans;
    que.push(x*10 + 3);
    que.push(x*10 + 5);
    que.push(x*10 + 7);
  }
  cout << ans << endl;
}

Measured memory_bytes: 4036
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using Pair = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;

/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/
const ll MOD = 1e9+7;

int main(){
  ll n,m;
  cin >> n >> m;
  if(abs(n-m) > 1) {cout << 0 << endl;return 0;}
  
  if(n == m){
    ll tmp = 1;
    for(ll i=n;i>0;i--){
      tmp*=i;
      tmp%=MOD;
    }
    tmp = tmp*tmp * 2;
    tmp%=MOD;
    cout << tmp << endl;
    return 0;
  }
  if(abs(n-m) == 1){
    ll N = 1;
    ll M = 1;
    for(ll i=n;i>0;i--){
      N*=i;
      N%=MOD;
    }
    for(ll i=m;i>0;i--){
      M*=i;
      M%=MOD;
    }
    cout << (N*M)%MOD << endl;
    return 0;
  }
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin>>n;
    int dp[n+1] = {0}, a[n+1];
    for(int i = 1; i <= n; i++) 
        cin>>a[i];
    dp[0] = dp[1] = 0;
    dp[2] = abs(a[1]-a[2]);
    for(int i = 3; i <= n; i++) 
        dp[i] = min(dp[i-1] + abs(a[i] - a[i-1]), dp[i-2] + abs(a[i] - a[i-2]));
    cout<<dp[n]<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <iomanip>
#include <queue>
#include <deque>
#include <sstream>
#include <stdio.h>
#include <string>
#include <cmath>
#include <map>
#include <utility>
using namespace std;

#define s(n) scanf("%d",&n)
#define sc(n) scanf("%c",&n)
#define ss(n) scanf("%s",&n)
#define MOD 1000000007
#define ll long long int
#define vi vector<int>
#define vii vector< vector<int> >
#define PI 3.1415926535897932384626433832795

int main() {
	int n;
	string s;
	cin >> n >> s;
	string answ ("");
	int open = 0;
	for(int i = 0; i < n; i++) {
		if(s.at(i) == '(') {
			open++;
			answ+= "(";
		} else {
			if(open == 0) {
				answ = "(" + answ;
				answ+= ")";
			} else {
				answ+= ")";
				open--;
			}
		}
	}
	while(open > 0) {
		answ+= ")";
		open--;
	}
	cout << answ;
	return 0;
}



Measured memory_bytes: 256
N,K = gets.chomp.split(" ").map(&:to_i)
mat = readlines.map{|n| n.chomp.split(" ").map(&:to_i)}

@graph = Array.new(N+1){[]}
mat.each do |n|
    arr = @graph[n[0]]
    arr << n[1]
    @graph[n[0]] = arr
    arr = @graph[n[1]]
    arr << n[0]
    @graph[n[1]] = arr
end
def log(n)
    #p n
end

@q = []
@visited = []

def dfs(v, minus)
    @visited[v] = true
    @q << v
    num=1
    cands_number = K - 1
    while (tmp = @q.shift) do
        
        arr = @graph[tmp]
        arr.each do |n|
            next if @visited[n]
            num*= cands_number
            cands_number-=1
            num %= 1000000007
        end
        arr.each do |n|
            if not @visited[n]
                @visited[n] = true
                @q << n
            end
        end
        cands_number = K - 2
    end
    return num;
end
puts K * dfs(1,-1) % 1000000007

Measured memory_bytes: 22836
#include<bits/stdc++.h>
using namespace std;
int main()
{
      ios::sync_with_stdio(), cin.tie(0), cout.tie(0);
      long long  s, x, y;
      while(cin>>s)
      {
            x = s/500;
            long long temp = s%500;
            y = temp/5;
            cout << x*1000+y*5 << endl;
      }
      return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); --i)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)x.size())
using pii = pair<int, int>;
using vvi = vector<vector<int>>;
using vi  = vector<int>;

template <class Monoid>
class SegmentTree {
    using T = typename Monoid::T;
    int size;
    vector<T> data;
    void build() {
        rrep(i, 1, size) {
            data[i] = Monoid::op(data[i * 2], data[i * 2 + 1]);
        }
    }
public:
    SegmentTree(int n) {
        size = 1;
        while (size < n) size *= 2;
        data.assign(size * 2, Monoid::identity());
    }
    template <class It>
    SegmentTree(It first, It last) : SegmentTree(std::distance(first, last)){
        copy(first, last, std::begin(data) + size);
        build();
    }

    // 0-indexed
    void update(int p, const T &value) {
        for (data[p += size] = value; p /= 2; ) {
            data[p] = Monoid::op(data[p * 2], data[p * 2 + 1]);
        }
    }
    // [l, r)  0-indexed
    T query(int l, int r) {
        T resl = Monoid::identity(), resr = Monoid::identity();
        for (l += size, r += size; l < r; l /= 2, r /= 2) {
            if (l & 1) resl = Monoid::op(resl, data[l++]);
            if (r & 1) resr = Monoid::op(data[--r], resr);
        }
        return Monoid::op(resl, resr);
    }
    // 0-indexed
    T get(int p) {
        return data[p + size];
    }
};

struct RMQ {
    using T = int;
    static T op(T a, T b) { return min(a, b); }
    static constexpr T identity() { return (1LL << 31) - 1; }
};

struct RSQ {
    using T = int;
    static T op(T a, T b) { return a + b; }
    static constexpr T identity() { return 0; }
};

signed main() {
    int N, Q;
    cin >> N >> Q;
    SegmentTree<RMQ> seg(N);
    rep(i, 0, Q) {
        int C, X, Y;
        cin >> C >> X >> Y;
        if (C == 0) {
            // update
            seg.update(X, Y);
        } else {
            // find
            cout << seg.query(X, Y + 1) << endl;
        }
    }
}



Measured memory_bytes: 4948
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    static int K = sc.nextInt();
    static String S = sc.next();

    public static void main(String[] args) {
        char str[] = S.toCharArray();
        if (str.length <= K){
            System.out.println(S);
            return;
        }
        for (int i = 0; i < K; i++){
            System.out.print(str[i]);
        }
        System.out.print("...");
    }
}


Measured memory_bytes: 35792
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
if n<=3:
    print(max(a))
    exit()

lacc = [0]*n
racc = [0]*n
lacc[0] = a[0]
lacc[1] = a[1]
racc[n-1] = a[n-1]
racc[n-2] = a[n-2]
for i in range(2,n):
    if i%2==0:
        lacc[i] = lacc[i-2]+a[i]
    else:
        lacc[i] = max(lacc[i-3],lacc[i-2])+a[i]
if n%2==0:
    print(max(lacc[n-2],lacc[n-1]))
    exit()
for i in range(n-3,-1,-1):
    if (n-1-i)%2==0:
        racc[i] = racc[i+2]+a[i]
    else:
        racc[i] = max(racc[i+3],racc[i+2])+a[i]
mx = max(racc[2],lacc[n-3])
for i in range(1,n-2):
    if i%2==0:
        mx = max(mx, max(lacc[i-2],lacc[i-1])+racc[i+2])
    else:
        mx = max(mx, max(racc[i+2],racc[i+3])+lacc[i-1])
print(mx)


Measured memory_bytes: 93988
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
using pii = pair<i32, i32>;
using vi32 = vector<i32>;
using vu32 = vector<u32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf64 = vector<f64>;
using vf80 = vector<f80>;
using vstr = vector<string>;
using vpii = vector<pii>;
using vvi32 = vector<vi32>;
using vvu32 = vector<vu32>;
using vvi64 = vector<vi64>;
using vvu64 = vector<vu64>;
using vvf64 = vector<vf64>;
using vvf80 = vector<vf80>;

template<typename T, typename S> bool amax(T &x, S y) { if (x < y) { x = y; return 1; } return 0; }
template<typename T, typename S> bool amin(T &x, S y) { if (y < x) { x = y; return 1; } return 0; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  cerr << fixed << setprecision(16);
  int n;
  string s;
  cin >> s;
  n = s.size();
  if (s[n - 1] == '1' || s[0] == '0') {
    cout << -1 << endl;
    return 0;
  }
  rep(i, (n - 1) / 2) {
    if (s[i] != s[n - i - 2]) {
      cout << -1 << endl;
      return 0;
    }
  }
  s[n - 1] = '1';
  int cnt = 1;
  reps(i, n) {
    if (s[i] == '1') {
      reps(j, cnt) {
        cout << i - j + 1 << " " << i + 1 << endl;
      }
      cnt = 1;
    } else {
      cnt++;
    }
  }
  return 0;
}

Measured memory_bytes: 1616
/***** author :  C0d1ngPhenomena *****/

    #include <bits/stdc++.h>
    #define endl "\n"
    #define ll long long int
    #define TestCases int T; cin>>T; while(T--)
    #define rep(i,n) for(ll i = 0; i < n; i++)
    #define revrep(i,n) for(ll i = n-1; i >= 0; i--)
    #define vll vector<ll>
    #define vvll vector < vll >
    #define pll pair<ll, ll>
    #define mp(x,y) make_pair(x,y)
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define alld(c) c.begin(),c.end(),greater<int>()
    #define mem(a,val) memset(a,val,sizeof(a))
    #define f first
    #define s second
    #define pb push_back
    using namespace std;
    



    
    int main()
    {
        std::ios::sync_with_stdio(false);
        cin.tie(NULL);
        
       ll N;
       cin >> N;
       if(N%1000 == 0)
        cout << 0;
    else
        cout << 1000 - N%1000;

        return 0;
    }







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

int main(){
    int a,b,c;
    cin >>a>>b>>c;
    if(a+b+c>=22) cout<<"bust"<<endl;
    else cout<<"win"<<endl;
    }

Measured memory_bytes: 256
#include <queue>
#include <iostream>
#include <string>
using namespace std;
long n, q;
queue<pair<string, long> > Q, A;
long T = 0;
int main()
{
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    string name;
    long time;
    cin >> name >> time;
    Q.push(make_pair(name, time));
  }

  while (! Q.empty()) {
    pair<string, long> pair = Q.front();
    Q.pop();
    if (pair.second > q) {
      T += q;
      Q.push(make_pair(pair.first, pair.second - q));
    }
    else
    {
      T += pair.second;
      A.push(make_pair(pair.first, T));
    }
  }
  for (int i = 0; i < n; i++) {
    pair<string, long> pair = A.front();
    A.pop();
    cout << pair.first << " " << pair.second << endl;
  }
}


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

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]+n>=91) s[i]=(char)(s[i]+n-26);
        else s[i]=(char)(s[i]+n);
    }
    
    cout<<s<<endl;
    

}


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

using namespace std;

int main()
{
	int W, H;
	int h, w;
	cin >> H >> W;
	cin >> h >> w;

	cout << (H - h) * (W - w) << endl;


	return 0;
}


Measured memory_bytes: 256
//
//  atc1019.cpp
//  National Olympiad in Informatics in Provinces
//
//  Created by 黄子齐 on 2019/10/19.
//  Copyright © 2019 黄子齐. All rights reserved.
//

#include <stdio.h>
const int N = 2e5+10;
int n;
char c[N];
int sum;
int main() {
//    freopen("mytestdata.in", "r", stdin);
    scanf("%d", &n);
    scanf("%s", c);
    for (int i=0; i<n; i++) {
        ++sum;
        while (i<n && c[i]==c[i+1]) {
            ++i;
        }
    }
    printf("%d\n", sum);
    return 0;
}


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

using namespace std;

typedef vector<int> Vec;
typedef vector<Vec> Mat;

Mat a(5, Vec(5));
int score[5];

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

bool inField(int x, int y)
{
    return (0 <= x && x < 5 && 0 <= y && y < 5);
}

int erase(Mat &m)
{
    bool e[5][5] = {{}};
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 5; j++) {                        
            if (m[i][j] == 0) {
                continue;
            }
            int cnt[2] = {1, 1};
            for (int k = 0; k < 4; k++) {
                int ni = i + dy[k];
                int nj = j + dx[k];
                while (inField(ni, nj) &&
                       m[i][j] == m[ni][nj]) {
                    ni += dy[k];
                    nj += dx[k];
                    ++cnt[k&1];
                }
            }
            if (cnt[0] >= 3 || cnt[1] >= 3) {
                e[i][j] = 1;
            }
        }
    }
    int point = 0;
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 5; j++) {
            if (e[i][j]) {
                point += score[m[i][j]-1];
                m[i][j] = 0;
            }
        }
    }
    return point;
}

void fall(Mat &m)
{
    for (int j = 0; j < 5; j++) {
        for (int i = 4; i >= 1; i--) {
            if (m[i][j] == 0) {                
                for (int k = i-1; k >= 0; k--) {
                    if (m[k][j] != 0) {
                        swap(m[i][j], m[k][j]);
                        break;
                    }
                }
            }
        }
    }
}

int get_point()
{
    Mat b = a;
    int point = 0, bp = 1;
    bool update = 1;
    
    while (update) {
        update = 0;        
        Mat nb = b;
        point += erase(nb) * bp++;
        fall(nb);
        if (nb != b) {        
            update = 1;
            b = nb;
        }
    }
    return point;
}

int dfs(int y, int x, int n, int p)    
{
    int point = get_point();
    if (n > 0) {
        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (inField(nx, ny) && (p == -1 || (p + 2) % 4 != i)) {
                swap(a[ny][nx], a[y][x]);
                point = max(point, dfs(ny, nx, n-1, i));
                swap(a[ny][nx], a[y][x]);
            }        
        }
    }
    return point;
}

int main()
{
    int n;
    while (cin >> n, n != -1) {
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 5; j++) {
                cin >> a[i][j];
            }
        }
    
        for (int i = 0; i < 5; i++) {
            cin >> score[i];
        }

        int max_point = 0;
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 5; j++) {
                max_point = max(max_point, dfs(i, j, n, -1));
            }
        }   
        cout << max_point << endl;
    }
    return 0;
}

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

using namespace std;

int main(){

    int n, t;
    cin >> n >> t;
    vector<pair<int, int>> inp(n);
    for(int i = 0; i < n ; i++)
        cin >> inp[i].first >> inp[i].second;

    sort(inp.begin(), inp.end());
    vector<int> dp(6005, 0);
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        int f = inp[i].first, s = inp[i].second;
        for(int j = t-1; j >= 0; j--){
            if( dp[j] != -1 ){
                dp[j+f] = max(dp[j+f], dp[j]+s);
            }
        }
    }

    int ans = 0;
    for(int i = 0; i < 6005; i++)
        ans = max(ans, dp[i]);

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

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

int main() {
	string s[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
	string t;
	cin>>t;
	for(ll i=0;i<7;i++){
		if(s[i]==t){
			cout <<7-i;
		}
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
'use strict';
function main(input) {
  const a = input.trim().split('\n')[0].split(' ').map(x => Number(x));
  const b = input.trim().split('\n')[1].split(' ').map(x => Number(x)).sort(function (a, b) {
    return b - a;
  });
  let sum = 0;

  for (let i = 0; i < b.length; i ++) {
    sum += b[i];
  }

  if (b[(a[1] - 1)] < sum / 4 / a[1]) {
    console.log('No');
  } else {
    console.log('Yes');
  }
  
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include<stdio.h>
int main()
{
    int m,n,i,j;
    while(1){
        scanf("%d",&n);
        scanf("%d",&m);
        if(m == n){
            printf("Yes\n");
            break;
        }
        else{
            printf("No\n");
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 128
def ans(arr, n): 
	
	count = 0
	for i in range(n): 
		for j in range(i + 1, n):
			for k in range(j + 1, n):
			    if (arr[i] + arr[j] > arr[k] and arr[i] + arr[k] > arr[j] and arr[k] + arr[j] > arr[i]):
			        if len(set([arr[i],arr[j],arr[k]]))==3:
			            count += 1
	return count 


n = int(input())
arr = [int(x) for x in input().split()]
if(n<=2):
    print(0)
else:
    print(ans(arr,n))

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

int main() {
	int N, A[100002], D, ans;
	cin >> N ;
	A[0] = 0;
	D = 0; 
	for(int i=1; i<=N+1; i++){
		if(i == N+1){
			A[i] = 0;
			D += abs(A[i-1]);
		}
		else{
			cin >> A[i];
			D += abs(A[i]-A[i-1]);
		}
	}
	for(int i=1; i<=N; i++){
		ans = D -abs(A[i]-A[i-1]) -abs(A[i+1]-A[i]) +abs(A[i+1]-A[i-1]) ;			
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1664
package main

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

func main() {
	var top_1, bottom_1, front_1, back_1, left_1, right_1 int
	var top_2, bottom_2, front_2, back_2, left_2, right_2 int
	var command string = "WWWWSSSS"
	fmt.Scan(&top_1, &front_1, &right_1, &left_1, &back_1, &bottom_1)
	fmt.Scan(&top_2, &front_2, &right_2, &left_2, &back_2, &bottom_2)

	for i := 0; i < len(command); i++ {
		switch string(command[i]) {
		case "S":
			top_1, front_1, bottom_1, back_1 = back_1, top_1, front_1, bottom_1
		case "N":
			top_1, front_1, bottom_1, back_1 = front_1, bottom_1, back_1, top_1
		case "E":
			top_1, left_1, bottom_1, right_1 = left_1, bottom_1, right_1, top_1
		case "W":
			top_1, left_1, bottom_1, right_1 = right_1, top_1, left_1, bottom_1
		}
		if top_1 == top_2 && bottom_1 == bottom_2 {
			for j := 0; j < 4; j++ {
				front_1, left_1, back_1, right_1 = right_1, front_1, left_1, back_1
				if front_1 == front_2 && back_1 == back_2 && left_1 == left_2 && right_1 == right_2 {
					fmt.Println("Yes")
					return
				}
			}
		}
	}
	fmt.Println("No")
}

var reader = bufio.NewScanner(os.Stdin)

func read() string {
	reader.Scan()
	return reader.Text()
}



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

const long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair


void solve() {
  int n;
  cin >> n;
  vector<int> G[n];
  bool used[n] = {};
  ll ans[n];
  int cnt[n] = {};
  REP(i,n-1) {
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    G[a].pb(b);
    G[b].pb(a);
    cnt[a]++;
    cnt[b]++;
  }
  vector<ll> num(n);
  ll sum = 0;
  REP(i,n) {
    cin >> num[i];
    sum += num[i];
  }
  sort(num.begin(),num.end());
  sum -= num[n-1];
  queue<int> que;
  REP(i,n) {
    if (cnt[i] == 1)
      que.push(i);
    //cout << i << " " << cnt[i] << endl;
  }
  int pos = 0;
  while (!que.empty()) {
    int k = que.front();
    //cout << k << endl;
    que.pop();
    if (used[k]) continue;
    used[k] = 1;
    ans[k] = num[pos++];
    REP(i,G[k].size()) {
      if (used[G[k][i]]) continue;
      cnt[G[k][i]]--;
      if (cnt[G[k][i]] <= 1) {
        que.push(G[k][i]);
      }
    }
  }
  cout << sum << endl;
  REP(i,n) cout << ans[i] << " \n"[i == n-1];
}

int main(int argc, char *argv[]){

  /*Regular*/
  int case_num = 1;
  if (argc > 1 && stoi(argv[1])) cin >> case_num;
  REP(case_no, case_num) {
    cerr << endl << "case " << case_no + 1 << endl;
    solve();
  }

  // /*ICPC*/
  // while (cin >> t >> d >> l, t) {
  //   solve();
  // }

  //solve();
  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
int main() {
    int N;
    cin>>N;
    vector<int> items;
    int i = 1;
    while(i <=N){
        items.push_back(i);
        i*=6;
    }
    i=9;
    while(i<=N){
        items.push_back(i);
        i*=9;
    }
    sort(items.begin(), items.end());
    vector<int> data(N);
    for (auto it = items.begin();
         it != items.end(); ++it){
        for (int vol=0; vol<N; ++vol){
            int dif = vol - *it;
            if(dif+1>=0){
                if(dif==-1) data[vol] = 1;
                else if (data[vol]==0 || data[vol]>data[dif]+1)
                    data[vol] = data[dif] +1;
            }
        }
    }
    cout << data[N-1]<< endl;
    return 0;
}

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

int main(){
    int64_t N,A,B,rep,ans,rem;
    cin >> N >> A >> B;
    rep = N/(A+B);
    rem = N - (A+B)*rep;
    if(rem >= A){
        cout << rep*A + A << endl;
    }else{
        cout << rep*A + rem << endl;
    }
    

    return 0;
}

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

using namespace std;

#define pb push_back
#define pp pop_back
#define mp make_pair
#define F first
#define S second
#define xmax(x,y) ((x) = max((x),(y)))
#define xmin(x,y) ((x) = min((x),(y)))
#define all(x) (x).begin(),(x).end()
#define mem(x) memset(x , 0 , sizeof(x))
#define _ ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define FP(a , b , c)  for(ll (a) = (b) ; (a) < (c) ; (a++));
#define FM(a , b , c)  for(ll (a) = (b) ; (a) >= (c) ; (a--));
#define connect(a , b , c) a[b].pb(c) , a[c].pb(b)

typedef long long int ll;
typedef unsigned long long int ull;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector <ll> vl;
typedef vector <int> vi;
typedef vector <string> vs;

const ll Maxn3 = 1e3 + 10;
const ll Maxn4 = 1e4 + 10;
const ll Maxn5 = 1e5 + 10;
const ll Maxn6 = 1e6 + 10;
const ll Maxn7 = 1e7 + 10;
const ll Maxn8 = 1e8 + 10;
const ll Maxn9 = 1e9 + 10;
const ll Maxn18 = 1e18 + 10;
const ll Mod1 = 1e7 + 7;
const ll Mod2 = 1e9 + 7;
const ll LLMax = LLONG_MAX;
const ll LLMin  = LLONG_MIN;
const ll INTMax = INT_MAX;
const ll INTMin  = INT_MIN;

ll mn = LLMax , mx = LLMin;

int main()
{_
    str s , d , t;
    cin >> s >> d >> t;
    cout << s[0] << d[1] << t[2];
	return 0;
}
///SAliB


Measured memory_bytes: 256
import sys

def cal(a,b,c):
	if a==0:
		bc=b+c
	else:
		bc=b-c
	return bc

n=input()
list=[]
for i in range(4):
	list.append(int(n[i]))
for a in range(2):
	ab=cal(a,list[0],list[1])
	for b in range(2):
		abc=cal(b,ab,list[2])
		for c in range(2):
			abcd=cal(c,abc,list[3])
			if abcd==7:
				if a==0:
					op1='+'
				else:
					op1='-'
				if b==0:
					op2='+'
				else:
					op2='-'
				if c==0:
					op3='+'
				else:
					op3='-'
				print(str(n[0])+str(op1)+str(n[1])+str(op2)+str(n[2])+str(op3)+str(n[3])+str('=')+str(7))
				sys.exit()

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
int main(void) {
  string s;
  cin >> s;
  if(s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
    cout << "Bad" << endl;
  else
    cout << "Good" << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;
using TextReader = System.IO.TextReader;
using System.Text;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var n = consoleReader.Int;
            var a = consoleReader.Split.Double;
            return 1 / a.Sum(d => 1 / d);
        }

        #region いつもの
        private readonly ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader(Console.In)).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
        #endregion
    }

#pragma warning disable
    public class ConsoleReader
    {
        private string[] line = Array.Empty<string>();
        private int linePosition;
        private TextReader textReader;
        public ConsoleReader(TextReader tr) { textReader = tr; }
        public int Int => int.Parse(String);
        public long Long => long.Parse(String);
        public double Double => double.Parse(String);
        public string String
        {
            get
            {
                if (linePosition >= line.Length)
                {
                    linePosition = 0;
                    line = textReader.ReadLine().Split();
                }
                return line[linePosition++];
            }
        }
        public class SplitLine
        {
            private string[] splited;
            public SplitLine(ConsoleReader cr) { splited = cr.textReader.ReadLine().Split(); }
            public int[] Int => String.Select(x => int.Parse(x)).ToArray();
            public long[] Long => String.Select(x => long.Parse(x)).ToArray();
            public double[] Double => String.Select(x => double.Parse(x)).ToArray();
            public string[] String => splited;
        }
        public SplitLine Split => new SplitLine(this);
        public class RepeatReader
        {
            ConsoleReader cr; int count;
            public RepeatReader(ConsoleReader cr, int count) { this.cr = cr; this.count = count; }
            public IEnumerable<T> Select<T>(Func<ConsoleReader, T> func) { for (int i = 0; i < count; i++) yield return func(cr); }
            public IEnumerable<string> String { get { for (int i = 0; i < count; i++) yield return cr.String; } }
            public IEnumerable<int> Int { get { for (int i = 0; i < count; i++) yield return cr.Int; } }
            public IEnumerable<double> Double { get { for (int i = 0; i < count; i++) yield return cr.Double; } }
        }
        public RepeatReader Repeat(int count) => new RepeatReader(this, count);
    }
}

Measured memory_bytes: 13396
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i,n) for(int i=1;i<n;i++)
#define out(s) cout << s << endl

int main(){
    int cnt=0;
    int a,b,c;cin >> a >> b >> c;
    while(a!=b || b!=c){
        for(int i=0;i<2;i++){
            if(a==min(a,min(b,c)))a++;
            else if(b==min(a,min(b,c)))b++;
            else c++;
        }
        cnt++;
    }
    cout << cnt << endl;
}



Measured memory_bytes: 256