akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define uniqueV(x)          \
  sort(x.begin(), x.end()); \
  x.erase(unique(x.begin(), x.end()), x.end());
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << "(" << #x << ", " << #y << ") = " \
                          << "(" << x << ", " << y << ")" << '\n'

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

// ----------------------------------------------

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

  int n;
  cin >> n;
  vector<int> v(n);
  REP(i, n) { cin >> v[i]; }

  int i = 1;
  int num = 0;
  while (num <= n) {
    num++;
    if (v[i] == 2) {
      cout << num << endl;
      return 0;
    }

    i = v[i];
  }

  cout << -1 << endl;

  return 0;
}

Measured memory_bytes: 640
def main():
    a, b, c, k = map(int, input().split())
    #  a      ,     b   ,        c
    #     b+ c,  a   + c,  a+ b   
    # 2a+ b+ c,  a+2b+ c,  a+ b+2c
    # 2a+3b+3c, 3a+2b+3c, 3a+3b+2c
    # 6a+5b+5c, 5a+6b+5c, 5a+5b+6c
    if k%2 == 0:
        print(a-b)
    else:
        print(b-a)

if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>PP;
const ll MOD = 1000000007;
ll T[200005]={0};//iの深さ
ll oya[200005]={0};//iの上位の頂点
ll mai[200005]={0};//iをTOPとする部分木の頂点数iは除く
ll used[200005]={0};
vector<ll> V[200005];//隣接リスト
priority_queue<PP>Q;
priority_queue<PP>Q2;
/*void ki(int x){
  for(int j=0;j<V[x].size();j++){
    int now=V[x][j];
    if(used[now]==0){
      oya[now]=x;
      T[now]=T[x]+1;
      used[now]++;
      ki(now);
    }
  }
}*/
int main(){
  int n;
  cin>>n;
  for(int i=2;i<=n;i++){
    int a;
    cin>>a;
    V[a].push_back(i);
    //V[i].push_back(a);
  }
  //used[1]=1;
  //ki(1);
  /*for(int i=2;i<=n;i++){
    Q.push(make_pair(T[i],i));
  }
  for(int i=2;i<=n;i++){
    mai[oya[Q.top().second]]+=(mai[Q.top().second]+1);
    Q.pop();
  }*/
  for(int i=1;i<=n;i++){
    cout<<V[i].size()<<endl;
  }
}

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

int main(){
  int x, y;
  cin >> x >> y;
  vector<int> A = {1, 3, 5, 7, 8, 10, 12}, B = {4, 6, 9, 11};
  int cnt = 0;
  for(int i = 0; i < 7; i++){
    if(A[i] == x) cnt++;
    else if(A[i] == y) cnt++;
  }
  if(cnt == 2){
    cout << "Yes";
    return 0;
  }
  
  cnt = 0;
  for(int i = 0; i < 4; i++){
    if(B[i] == x) cnt++;
    else if(B[i] == y) cnt++;
  }
  if(cnt == 2){
    cout << "Yes";
    return 0;
  }
  cout << "No";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3") 
#pragma GCC optimization ("unroll-loops")
 
// #include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
// const ll RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
// gp_hash_table<int, int> table;
 
#define ll  long long
#define vii vector< ll >
#define pb push_back
#define pii pair<ll,ll>
#define ppi pair<pii,ll>
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define ins insert
#define ld long double
#define lp(l,r) for(i=l;i<=r;++i)
 
#define lpj(l,r) for(j=l;j<=r;++j)
#define lpr(l,r) for(i=r;i>=l;--i)
#define lprj(l,r) for(j=r;j>=l;--j)
 
#define swap(a,b){ auto _t=a;a=b,b=_t;}
#define flush() cout.flush()
#define popcount __builtin_popcount
#define die() return 0;
#define sz() size() 


 
 
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define MD          1000000007
#define M 			200011
#define LN             14
#define fftmod      998244353
#define EPS         (double)1e-10
 
long long  md=MD;
ll inf=1e18;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 
 
 
inline ll exp(ll a,ll b){if(a==0&&b==0)return 1ll;if(a==0)return 0ll;ll r=1LL;while(b>0){if(b&1){r=(r%md)*(a%md);r=(r+md)%md;}b/=2;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;if(a==0)return b;return gcd(b,a%b);}
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (ll)r;}
 
using cd=complex<double>;
const double PI=acos(-1);
 
inline ll rand(ll l,ll r){
    return l+rng()%(r-l+1);
}

ll pr[M],fa[M],iv[M];

ll chose(ll n,ll k){
	if(n<k)return 0;
	ll r=fa[n]%md;r=r*iv[k]%md;r%=md;r=r*iv[n-k]%md;return r%md;
}
int main(){
 
     
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
 
   // ifstream fin("input.txt");ofstream fout("outut.txt");
    ll t,i,j,m,n,s,z,k,p;string s1,s2;ll q;ll x,y;
    fa[0]=iv[0]=1;
    lp(1,M-1){
    	fa[i]=fa[i-1]*i%md;;fa[i]%=md;
    	iv[i]=iv[i-1]*exp(i,md-2)%md;iv[i]%=md;
    }vii v;
    for(i=2;i<M;++i){
    	if(pr[i]==1)continue;
    	v.pb(i);
    	for(j=2*i;j<M;j+=i)pr[j]=1;
    }
	cin>>n>>m;
	map<ll,ll> mp;
	for(auto x:v){
		if(x>m)break;
		if(m%x==0){
			p=0;
			while(m%x==0)m/=x,p++;
			mp[x]=p;
		}
	}
	if(m>1)mp[m]=1;
	p=1ll;
	for(auto x:mp){
		k=x.S;
		y=chose(n+k-1,n-1);y%=md;
		p=p*y%md;p%=md;


	}
	cout<<p<<"\n";






    

}



Measured memory_bytes: 5376
// inputに入力データ全体が入る
function Main(input) {
  input = input.split("\n");
  // 1行目がinput[0], 2行目がinput[1], …に入る
  var inputs = input[0].split(" ");
  var n = Number(inputs[0]);
  var k = Number(inputs[1]);
  console.log(String(n.toString(k)).length);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main('11 2');
// Main('1010101 10');
// Main('314159265 3');


Measured memory_bytes: 7372
#include<iostream>

int main() {
	int n;
	int l;
	std::cin >> n;
	int max = 0;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		std::cin >> l;
		if (l > max) {
			max = l;
		}
		sum += l;
	}
	if (sum - max > max) {
		std::cout << "Yes" << std::endl;
	}
	else {
		std::cout << "No" << std::endl;
	}
	return 0;
}


Measured memory_bytes: 256
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int A, B, X;
	std::cin >> A >> B >> X;
	if (A <= X && (A+B) >= X) {
		std::cout << "YES\n";
	} else {
		std::cout << "NO\n";
	}
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000)
N, Q = map(int, input().split())
rl = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    rl[a].append(b)
    rl[b].append(a)
cnt = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    p -= 1
    cnt[p] += x

def dfs(v, pv):
    for next_v in rl[v]:
        if next_v == pv:
            continue
        cnt[next_v] += cnt[v]
        dfs(next_v, v)
dfs(0, -1)
print(*cnt)

Measured memory_bytes: 233268
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(s,i, n) for (int i = (int)s; i < (int)(n); i++)
#define pb push_back
typedef long long ll;
  
int main(){
    int a,b;
    cin>>a>>b;
    int ans=0;
    if(a>=13)ans=b;
    else if(a>=6)ans=b/2;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // cin, cout の高速化
#define MOD 1000000007
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP1(i, n) for (int i = 1; i <= (n); i++)

#define MAX_N 10000000

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> M;
    REP(i, h)
    {
        string s;
        cin >> s;
        bool flg = false;
        REP(j, s.length())
        {
            if (s[j] == '#')
            {
                flg = true;
                break;
            }
        }
        if (flg)
        {
            M.push_back(s);
        }
    }
    REP(ii, w)
    {
        int i = w-1-ii;
        bool flg = false;
        REP(j, M.size())
        {
            if(M[j][i] == '#'){
                flg = true;
                break;
            }
        }
        if (!flg){
            REP(j, M.size())
            {
                M[j] = M[j].erase(i,1);
            }
        }
    }
    REP(i,M.size()){
        cout<<M[i]<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;
int Inf = (1 << 30);
ll inf = (1LL << 60);
const int MOD = 1e9 + 7;
int main() {
	int n;
	cin >> n;
	vector<double> a(n);
	int i;
	for (i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0));
	dp[0][0] = 1;
	dp[0][1] = 0;
	for (i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			dp[i + 1][j + 1] += (dp[i][j] * a[i]);
			dp[i + 1][j] += (dp[i][j] * (1 - a[i]));
		}
	}
	double ans = 0;
	for (i = (n + 1) / 2; i <= n; i++) {
		ans += dp[n][i];
	}
	cout << fixed << setprecision(10) << ans;
	return 0;
}

Measured memory_bytes: 70656
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P pair<int,int>
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

signed main(){
  int k;
  cin >> k;
  string s;
  cin >> s;
  if(k < s.size()){
    rep(i,0,k){
      cout << s[i];
    }
    cout << "..." << endl;
  }
  else{
    cout << s << endl;
  }
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int s[16] = {0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0};
int s2[20] = {5,6,7,8,9,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9};
int main(void){
  int n;
  cin>>n;
  while(n--){
    int a,b;
    vector<int> ans;
    cin>>a>>b;
    bool f=false;
    REP(i,16){
      if(s[i]==a){
        if(!f)f=true;
        else ans.clear();
      }
      if(f) ans.push_back(s[i]);
      if(f&&s[i]==b) break;
    }
    if(b>=5&&a>b){
      ans.clear();
      f = false;
      REP(i,20){
        if(s2[i]==a){
          if(!f)f=true;
          else ans.clear();
        }
        if(f) ans.push_back(s2[i]);
        if(f&&s2[i]==b) break;
      }
    }
    REP(i,ans.size()){
      if(i) cout<<" ";
      cout<<ans[i];
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
def solve():
    S = raw_input()
    even0 = 0
    even1 = 0
    odd0 = 0
    odd1 = 0
    for i in range(len(S)):
        if i % 2 == 0:
            if S[i] == '0':
                even0 += 1
            else:
                even1 += 1
        else:
            if S[i] == '0':
                odd0 += 1
            else:
                odd1 += 1
    ret = min(even0 + odd1, even1 + odd0)
    print str(ret)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 5892
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <set>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

int main(void) {
  int n, m, k;
  scanf("%d %d %d", &n, &m, &k);
  REP(a, n+1) REP(b, m+1)
    if (a*(m-b) + b*(n-a) == k) { puts("Yes"); return 0; }
  puts("No");
  return 0;
}


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

#define REP(i, n) for(int i= 0; i < (n); ++i)
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)

typedef long long ll;

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;
}
 
 //入力
int N;          //足場の総数
ll h[100010];   //足場
ll dp[100010];  //DPテーブル

const ll INF = 1LL << 60;   //2^60で初期化

int main() {
    cin >> N;
    FOR(i, 0, N) cin >> h[i];

    FOR(i, 0, 100010) dp[i] = INF;

    dp[0] = 0;  //初期条件

    FOR(i, 1, N) {
        chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1])); //1つ前のコストの総和を比較
        if (i > 1)
            chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2])); //2つ前のコスト総和を比較
    }

    cout << dp[N - 1] << '\n';

    return 0;
}


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

using namespace std;
long double pi = 3.1415926536;

/*bool secgreat(pair<int, int> a, pair<int, int> b){
    return a.second>b.second;
}
 */

long long MAXN = 1e6+3;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, x, t;
    cin>>n>>x>>t;
    int sum = 0;
    int ti = 0;
    while(sum<n){
        sum+=x;
        ti+=t;
    }
    cout<<ti;

}

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

int main() {
  int A,B,C,D;
  cin >>A>>B>>C>>D;
  if (A+B==C+D) {
    cout << "Balanced" << endl;
  }
  else if (A+B>C+D){
    cout << "Left"<< endl;
  }
  else {
    cout <<"Right" << endl;
  }
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

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

//-----------------------------------------------------------------------------

int a, b, x;

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

	cin >> a >> b >> x;
	x -= a;
	if (x < 0) cout << "NO" << endl;
	else if (x > b) cout << "NO" << endl;
	else cout << "YES" << endl;

    return 0;
}


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
    int N; cin>>N;
    vector<ll> A(N);
    ll res = 0;
    rep(i,N){
        cin>>A.at(i);
        res+=A.at(i);
    }
    map<ll,ll> M;
    rep(i,N)M[A.at(i)]++;
    int Q; cin>>Q;
    rep(i,Q){
        ll b,c; cin>>b>>c;
        res += (c-b)*M[b];
        cout<<res<<endl;
        M[c]+=M[b];
        M[b]=0;
    }
}


Measured memory_bytes: 10116
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a;
	cin>>a;
	for(int i=0;i<a.size();i++)
	{
        if(a[i]=='e')      
        {
            if(a[i+1]=='r'&&a[i+2]=='a'&&a[i+3]=='s'&&a[i+4]=='e')  
			{    
                if(a[i+5]=='r')      
                {
                    i+=5;
                }
                else          
                {
                    i+=4;
                }
            }
        }
        else if(a[i]=='d')         
        {
            if(a[i+1]=='r'&&a[i+2]=='e'&&a[i+3]=='a'&&a[i+4]=='m')    
            {
                if(a[i+5]=='e'&&a[i+6]=='r'&&a[i+7]=='a'&&a[i+8]=='s'&&a[i+9]=='e')        
                {
                    i+=4;
                }
                else
                {
                    if(a[i+5]=='e'&&a[i+6]=='r')      
                    {
                        i+=6;
                    }
                    else
                    {
                        i+=4;
                    }
                }
            }
        }
        else    
        {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
	return 0;
}
//ak

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vector<int> a;
  a.resize(n);
  for(int i=0;i<n;i++) cin>>a.at(i);
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());

  ll ans=0L;
  queue<int> que;
  que.push(a[0]);

  for(int i=1; i<n; i++){
    ans += que.front();
    que.pop();
    que.push(a[i]);
    que.push(a[i]);
  }

  cout << ans<< endl;

  return 0;
}


Measured memory_bytes: 4424
(let* ((n (read))
       (m (read))
       (stack)
       (c (make-array (list (1+ n)) :initial-element nil))
       (r (make-array (list (1+ n)) :initial-element nil))
       (num (make-array (list (1+ n)) :initial-element 0)))
  (loop :for _ :from 1 :to m
        :for a := (read)
        :for b := (read)
        :do (push a (aref r b))
        :do (push b (aref r a)))
  (defun cnt (x gn)
    (unless (aref c x)
      (setf (aref c x) t)
      (incf (aref num gn))
      (loop :for y :in (aref r x)
            :do (push y stack))))
  (loop :for x :from 1 :to n
        :if (null (aref c x))
        :do (push x stack)
        :do (loop :while stack
                  :for z := (pop stack)
                  :do (cnt z x)))
  (format t "~A~%" (loop :for i :from 1 :to n
                         :maximize (aref num i))))


Measured memory_bytes: 87212
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

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

	int N, L;
	cin >> N >> L;

	vector<int> a(N + 1);
	for (int i = 1; i <= N; ++i)
		cin >> a[i];

	int which = -1;
	for (int i = 1; i < N; ++i)
		if (a[i] + a[i + 1] >= L)
			which = i;

	if (which == -1)
		cout << "Impossible" << endl;
	else
	{
		cout << "Possible" << endl;
		for (int i = 1; i < which; ++i)
			cout << i << endl;
		for (int i = N - 1; i > which; --i)
			cout << i << endl;
		cout << which << endl;
	}

	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr << #x << ":" << (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;
	VAR(int, n);
	VEC(string, w, n);
	bool ok = true;
	REP(i, n) {
		REP(j, n) {
			if (i == j) continue;
			ok &= (w[i] != w[j]);
		}
		if (i > 0) {
			ok &= (w[i - 1].back() == w[i][0]);
		}
	}
	OUT(ok ? "Yes" : "No")BR;

  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) ll aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) string aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
		
	int N;
	cin>>N;
	string S;
	cin>>S;
	map<char,int> F;
	fx(N){
		F[S.at(x)]++;
	}
	
	ll ans=1;
	fx(26){
		char c='a'+x;
		if(F[c]>0){
			ans=(ans*(F[c]+1))%MOD;
		}

	}
	if(ans==0){
		ce(MOD-1)
	}else{
		ce(ans-1)
	}
	
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

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

    vector<ll> a(N);
    REP(i,N) cin >> a[i];

    if(N==1 || N==2){
        pl(1)
        return 0;
    }

    int ans = 1;
    int now = 0;
    REP(i,N-1){
        if(now == 0) now = a[i+1] - a[i];
        else {
            if(now * (a[i+1] - a[i]) < 0) {
                ans++;
                now = 0;
            }
        }
    } 

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

Measured memory_bytes: 1024
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

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

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  int n, k;cin>>n>>k;
  string s;cin>>s;
  int cnt=0, ans=0;
  rep(i, n-1){
    if(s[i]!=s[i+1])cnt++;
  }
  rep(i, n){
    if(s[i]=='R'){
      if(i+1<n && s[i+1]=='R')ans++;
    }else{
      if(i-1>=0 && s[i-1]=='L')ans++;
    }
  }
  ans += min(cnt, k)*2;
  ans = min(n-1, ans);
  cout<<ans<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 512
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
#define INF_LL 1000000000000000000LL
#define INF 200000000
#define MOD 998244353
#define ll long long
#define all(x) x.begin(), x.end()
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// typedef float double;
// typedef priority_queue prique;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
typedef vector<vi> matrix;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int sign[2] = {1, -1};
template <class T> bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll modpow(ll a, ll b, ll m) {
    if(b == 0)
        return 1;
    ll t = modpow(a, b / 2, m);
    if(b & 1) {
        return (t * t % m) * a % m;
    } else {
        return t * t % m;
    }
}

struct edge {
    int to;
    ll cost;
    edge(int t, ll c) { to = t, cost = c; }
};

ll GetDigit(ll num) {
    if(num == 0) {
        return 0;
    }
    ll digit = 0;
    while(num != 0) {
        num /= 10;
        digit++;
    }
    return digit;
}

int op(int a, int b) { return max(a, b); }
int e() { return 0; }

int main() {
    int n, k;
    cin >> n >> k;
    vi a(n);
    rep(i, n) cin >> a[i];
    segtree<int, op, e> seg(300003);
    seg.set(a[0], 1);
    rep(i, n - 1) {
        seg.set(a[i + 1],
                seg.prod(max(0, a[i + 1] - k), min(300001, a[i + 1] + k + 1)) +
                    1);
        // rep(i, 10) cout << seg.get(i) << " ";
        // cout << endl;
    }
    cout << seg.all_prod() << endl;
}


Measured memory_bytes: 9628
def main2():
    n = int(input())
    res=0
    div = [0]*(n+1)
    for i in range(1,(n+1)):
        for j in range(0,n,i):
            if(i+j<=n):
                div[i+j]+=1
        res+=i*div[i]
    print(res)



if __name__ == '__main__':
    main2()


Measured memory_bytes: 151560
#!/usr/bin/env python3
#ABC120 C

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = list(input())
stack = deque()
ans = 0
for i in range(len(s)):
    if len(stack) == 0:
        stack.append(s[i])
        continue
    if stack[-1] != s[i]:
        stack.pop()
        ans += 2
    else:
        stack.append(s[i])
print(ans)


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

int main(int argc, const char * argv[]) {
  
    int N;
	double T, A;
  	cin >> N >> T >> A;
  
  	vector<double> H(N);
  	for (int i = 0; i < N; i++) cin >> H.at(i);
  
  	double b = 100000000;
  	int res = 0;
  
  	for (int i = 0; i < N; i++) {
      double c = abs(A - (T - H.at(i) * 0.006));
      if (b > c) {
        b = c;
        res = i + 1;
      }
    }
  
  	cout << res << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <functional>

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    Edge rev() { return Edge(dst, src, cost); }

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;

using namespace std;

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

    vector<int> deg(N, 0);
    Graph<> graph(N);
    for (int i = 0; i < N - 1; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        graph[u].emplace_back(u, v);
        graph[v].emplace_back(v, u);
        ++deg[u], ++deg[v];
    }

    vector<bool> isw(N);
    int white = 0;
    for (auto&& e : isw) {
        char c;
        cin >> c;
        e = (c == 'W');
        white += e;
    }

    if (white <= 1) {  // 例外
        cout << white << endl;
        return 0;
    }

    // 黒い葉を取り除く
    queue<int> que;
    for (int v = 0; v < N; ++v) {
        if (deg[v] == 1 && !isw[v]) que.push(v);
    }
    while (!que.empty()) {
        int v = que.front();
        que.pop();
        deg[v] = 0;

        for (auto e : graph[v]) {
            if (deg[e.dst] == 0) continue;
            if (--deg[e.dst] == 1 && !isw[e.dst]) {
                que.push(e.dst);
            }
        }
    }

    int ans = accumulate(deg.begin(), deg.end(), 0);
    for (int v = 0; v < N; ++v) {
        if (deg[v] & 1) isw[v] = !isw[v];
        if (isw[v]) ++ans;
    }

    vector<int> dist(N);  // rからvのパスに含まれる白の個数
    function<void(int, int, int)> dfs = [&](int v, int r, int d) {
        if (isw[v]) ++d;
        dist[v] = d;
        for (auto e : graph[v]) {
            if (e.dst != r && deg[e.dst] > 0) dfs(e.dst, v, d);
        }
    };

    int r;
    for (r = 0; deg[r] == 0; ++r) {}

    fill(dist.begin(), dist.end(), -1);
    dfs(r, -1, 0);

    r = max_element(dist.begin(), dist.end()) - dist.begin();
    fill(dist.begin(), dist.end(), -1);
    dfs(r, -1, 0);

    cout << ans - *max_element(dist.begin(), dist.end()) * 2 << endl;
    return 0;
}


Measured memory_bytes: 14336
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

int main() {
    long long n, ans = 1;
    cin >> n;
    vector<long long> a(n);
    for(long long i = 0; i < n; i++) {
        cin >> a[i];
    }

    for(auto v : a) {
        if(v == 0) {
            cout << 0 << endl;
            return 0;
        }
    }

    for(long long i = 0; i < n; i++) {
        if(ans > 1000000000000000000 / a[i]) {
            cout << -1 << endl;
            return 0;
        }
        ans = a[i] * ans;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
        using namespace std;
        int main(){
			int n,x,l,t=0,ans=1;
			cin>>n>>x;
			for(int i=0;i<n;i++){
				cin>>l;
				t+=l;
				if(t<=x){
					ans++;
				}
			}
			cout<<ans<<endl;
    		return(0);
        }

Measured memory_bytes: 256
/// sultanov      

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
     
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()

using namespace std;
using namespace __gnu_pbds;
                                                          
template<typename T> 
using ordered_set = tree<T, null_type,   
less<T>, rb_tree_tag,
tree_order_statistics_node_update>;

using ll = long long;
using pii = pair<int, int>;                                   

const int N = 2e2;
const int MOD = 1e9 + 7;
const int INF32 = 1e9 + 1e2;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int a, b;
    cin >> a >> b;
    cout << (a * 3 + b) / 2;
    return false;
}


Measured memory_bytes: 256
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string& S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}
// mod 1000000007 の世界で a += b する関数
void add(long long& a, long long b) {
	a += b;
	if (a >= MOD) a -= MOD;
}
ll slide(vector<ll>& v, ll a, ll b) {
	ll azv = abs(v[0] - a);
	ll bzv = abs(v[0] - b);
	ll aov = abs(v[1] - a);
	ll bov = abs(v[1] - b);
	v[0] = a;
	v[1] = b;
	return max((azv + bov), (bzv + aov));
}
bool use[105];

void solv() {


	int n;
	cin >> n;
	int b[105];
	bool no = false;
	for (size_t i = 0; i < n; i++)
	{
		cin >> b[i];
		if (i + 1 < b[i])
			no = true;
	}

	if (no) {
		cout << -1 << endl;
		return;
	}

	int bef = 0;
	int mini = INF;
	int mai = -1;
	int cn[105];
	for (int i = 1; i <= n; i++)
	{
		int v = -1;
		bool th = false;
		int uc = 0;
		for (int j = n - 1; j >= 0; j--)
		{
			if (b[j] > i) continue;
			if (use[j]) {
				uc++;
				continue;
			}
			if (((i - 1) - uc) != b[j] - 1) {
				continue;
			}

			v = b[j];
			use[j] = true;
			break;
		}
		if (v == -1) {
			cout << -1 << endl;
			return;
		}
		cn[i] = v;
	}
	for (size_t i = 1; i <= n; i++)
	{
		cout << cn[i] << endl;
	}
}
int main() {
	//COMinit();
	solv();

	return 0;
}


Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------

int main(void){
    int x;
    cin >> x;

    bool dp[1100][1100] = {false};

    dp[0][0] = true;

    int h = x / 100;
    int r = x % 100;

    for(int i = 0; i <= r; i++){
        for(int j = 0; j <= h; j++){
            for(int k = 0; k <= 5; k++){
                if(dp[i][j]){
                    dp[i + k][j + 1] = true;
                }
            }
        }
    }

    if(dp[r][h]){
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }


    


}

Measured memory_bytes: 1408
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf 1000000000000000000

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vector<vi> a(n,vi(n));
    rep(i,n){
        int u,k;
        cin>>u>>k;
        u--;
        rep(j,k){
            int v;
            cin>>v;
            v--;
            a[u][v]=1;
        }
    }
    rep(i,n){
        rep(j,n){
            cout<<a[i][j]<<(j==n-1?"\n":" ");
        }
    }
}


Measured memory_bytes: 3304
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

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

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}";
  return o;
}



int main() {
  int N;
  cin >> N;
  vector<ll> A(N+1),s(N+1,0);
  rep(i,N+1) cin >> A[i];
  for (int i=N;i>=0;i--) {
    s[i]=A[i];
    if (i<N)
    s[i]+=s[i+1];
  }
  if ((N>0&&A[0]>0)||(N==0&&A[0]>=2)) {
    cout << -1 << endl;
    return 0;
  }
  ll cnt=1,now=1;
  rep2(i,1,N+1) {
    auto t = A[i];
    if (t>now*2) {
      cout << -1 << endl;
      return 0;
    }
    ll tmp=min(now*2,s[i]);
    cnt+=tmp;
    now=tmp-A[i];
  }
  cout << cnt << endl;
}

Measured memory_bytes: 4844
n = int(input())
a = []

for i in range(n):
  a.append(int(input()))

a2 = []
a2 = a.copy()
a2.sort()

mx = max(a)
mx2 = list(reversed(a2))[1]
mc = a.count(mx)


if mc > 1:
  for i in range(n):
    print(mx)

else:
  for i in range(n):
    if a[i] == mx:
      print(mx2)
    else:
      print(mx)


Measured memory_bytes: 14160
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

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

            int n = int.Parse (str[0]);

            int max = -1000000;
            int min = 1000000;
            long sum = 0;

            str = Console.ReadLine ().Split (' ');
            for (int i = 0; i < n; i++)
            {
                int a = int.Parse (str[i]);
                if (a > max) max = a;
                if (a < min) min = a;
                sum += a;
            }
            Console.WriteLine ("{0} {1} {2}", min, max, sum);
        }
    }

    class MyLibrary
    {

        // 自作の関数
        public static int MyFunction (int n)
        {
            return 0;
        }
    }
}


Measured memory_bytes: 17960
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007



int main() {
    string S; cin >> S;
    int N = S.size();
    vector<int> A(N+1);
    A[0] = 0;
    for(int i=0; i<N; i++){
        if(S[i]=='B') A[i+1] = A[i] + 1;
        else A[i+1] = A[i];
    }
    
    int cw = 0;
    ll ans = 0;
    for(int i=N-1; i>=0; i--){
        if(S[i]=='W'){
            cw++;
        } else {
            ans += (ll)cw * A[i+1];
            cw = 0;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1412
using System;
class Program
{
    static void Main(string[] args)
    {
        // スペース区切りの整数の入力
        string[] input = Console.ReadLine().Split(' ');
        double a = double.Parse(input[0]);
        double b = double.Parse(input[1]);
        //出力
        Console.Write(((int)(a/b))+" "+ ((int)(a % b))+" "+ ((a / b).ToString("F5")));

    }
}



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

int main()
{
    long n;
    cin >> n;
    long t = n;
    int ans = 0;
    while (n)
    {
        // cout << n % 10 << endl;
        ans += (n % 10);
        n /= 10;
    }
    // cout << ans << endl;
    if (t % ans == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define V (500)
//n<=50000

struct edge{
	int to, cap, rev;
};
vector<edge> g[V];
bool used[V];
int n, m;

//辺追加(1回)
void add_edge(void){
	int x, y, z;
	scanf("%d %d", &x, &y);
	y += n;
	g[x].push_back({ y, 1, g[y].size() });
	g[y].push_back({ x, 0, g[x].size() - 1 });
}

//増加路探索
int dfs(int vec, int ep, int val){
	if (vec == ep)return val;
	used[vec] = true;
	f(i, g[vec].size()){
		edge &e = g[vec][i];
		if (!used[e.to] && e.cap > 0){
			int d = dfs((e.to), ep, 1);
			if (d > 0){
				e.cap = 0;
				g[e.to][e.rev].cap = 1;
				return 1;
			}
		}
	}
	return 0;
}

//最大流探索
int max_flow(int s, int t){
	int ret = 0;
	int res;
	bool z = true;
	while (z){
		memset(used, false, sizeof(used));
		res = dfs(s, t, 1);
		if (res == 0)z = false;
		else ret++;
	}
	return ret;
}

//2部グラフ
int main(void){
	int k, s, t;
	int x, y;
	int z, ans;
	scanf("%d %d %d", &n, &m, &k);
	f(i, k){
		scanf("%d %d", &x, &y);
		x++;
		y++;
		y += n;
		g[x].push_back({ y, 1, g[y].size() });
		g[y].push_back({ x, 0, g[x].size() - 1 });
	}
	f(i, n){
		g[0].push_back({ i + 1, 1, g[i + 1].size() });
		g[i + 1].push_back({ 0, 0, g[0].size() - 1 });
	}
	f(i, m){
		g[n + i + 1].push_back({ n + m + 1, 1, g[n + m + 1].size() });
		g[n + m + 1].push_back({ n + i + 1, 0, g[n + i + 1].size() - 1 });
	}
	ans = max_flow(0, n + m + 1);
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 2900
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,p;
  cin>>N;
  p=0;
  char g;
  for(int i=0;i<N;i++){
    cin>>g;
      if(g=='Y') {
        p++;
          break;
      }
  }
  if(p==1){
    cout<<"Four"<<endl;
  }
   else {
    cout<<"Three"<<endl;
  }
}       

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

import copy

def main():
    n = int(input())
    x = list(map(int, input().split()))

    t = copy.deepcopy(x)
    t.remove(min(x))
    t.sort()
    m1 = t[int(n / 2 - 1)]
    t = copy.deepcopy(x)
    t.remove(max(x))
    t.sort()
    m2 = t[int(n / 2 - 1)]
    for i in range(n):
        print(m1 if x[i] < m1 else m2)

if __name__ == '__main__':
    main()


Measured memory_bytes: 26724
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

int main(){
  int N, K; cin >> N >> K;

  long long ans = 0;
  for (int i = K + 1; i <= N; i++){
    int num = i - K;

    int res = N % i;

    if(res < K) res = 0;
    else res = res - K + 1;

    ans += num * (N / i) + res;
  }
  if (K == 0) ans -= N;  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256