akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int 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


class UF{
private:
    vector<int> par,rank;
public:
    int groups;
    vector<set<int>> elmList;
    
    UF(int __size):par(__size) , rank(__size,0), elmList(__size) , groups(__size){
        rep(i,__size)elmList[i].insert(i);
        for(int i=0;i<__size;i++)par[i]=i;
    }
    
    int find(int x){
        if(par[x]==x) {
            return x;
        }else{
            return par[x]=find(par[x]);
        }
    }
    
    void unite(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y) return;
        
        groups--;
        if(rank[x]<rank[y]){
            par[x]=y;
            for(auto &e:elmList[x])elmList[y].insert(e);
            
        }else{
            par[y]=x;
            for(auto &e:elmList[y])elmList[x].insert(e);
            if(rank[x]==rank[y])rank[x]++;
        }
    }
    
    bool isSame(int x,int y){
        return find(x)==find(y);
    }
};

signed main(){
    int v,e;
    cin>>v>>e;
    vector<int> a(v);
    rep(i,v)cin>>a[i];
    
    UF uf(v);
    rep(i,e){
        int x,y;
        cin>>x>>y;
        uf.unite(x,y);
    }
    
    if(e==v-1){
        cout<<0<<endl;
        return 0;
    }
    
    int ans = 0;
    vector<int> remain;
    set<int> used;
    rep(i,v){
        int id = uf.find(i);
        if( used.count(id) )continue;
        used.insert(id);
        
        int mini = (1LL<<60);
        vector<int> tmp;
        for(auto elm:uf.elmList[id]){
            tmp.pb(a[elm]);
        }
        sort(all(tmp));
        ans+=tmp[0];
        for(int i=1;i<tmp.size();i++)remain.pb(tmp[i]);
    }
    
    sort(all(remain));
    if((int)used.size()>remain.size()+2){
        cout<<"Impossible"<<endl;
        return 0;
    }
    rep(i,used.size()-2)ans+=remain[i];
    cout<<ans<<endl;
}



Measured memory_bytes: 24692
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n = II()
    aa = LI()
    # できる数列にインデックスがかかれるときの最大値の底(bottom)
    bot = []
    mx = 0
    for i, a in enumerate(aa):
        if a > mx:
            bot.append((mx, i))
            mx = a
    #print(bot)
    aa.sort()
    ans = [0] * n
    j = n
    s = 0
    fin=0
    for mx, i in bot[::-1]:
        while j > 0 and aa[j - 1] > mx:
            j -= 1
            s += aa[j]
        ans[i]=s-(n-j)*mx-fin
        # print(mx,i,j,s,fin,ans)
        fin+=ans[i]
    print(*ans,sep="\n")

main()


Measured memory_bytes: 23936
#coding: utf-8

def print_list(X):
    first_frag = True
    for val in X:
        if first_frag:
            print_line = str(val)
            first_frag = False
        else:
            print_line = print_line + ' ' + str(val)
    print(print_line)

N = int(input())
A = list(map(int, input().split()))

print_list(A)

for i in range(1, N):
    tmp_val = A[i]
    j = i - 1
    while (j >= 0) and (tmp_val < A[j]):
        A[j+1] = A[j]
        j -= 1
    A[j+1] = tmp_val

    print_list(A)

Measured memory_bytes: 7648
import java.util.*;
import static java.lang.Integer.*;
//import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.System.*;
//import java.io.PrintWriter;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		String s = sc.next();
		sc.close();
		char[] ni = s.toCharArray();
		int n = parseInt(s);
		int sn = 0;
		for (i = 0; i < ni.length; i++) {
			sn += ni[i]-'0';
		}
		out.println(n%sn==0?"Yes":"No");
	}
}


Measured memory_bytes: 19796
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n[1000];
  int i;
  int N;
  cin >> N;
  for(i=0;i<N;i++) cin >> n[i];
  cout << n[N-1];
  for(i=1;i<N;i++) cout <<" "<<n[N-i-1];
  cout<<endl;
  return 0;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
#define sf scanf
#define pf printf
#define pb push_back
typedef long long ll;
const ll INF = 1e18;
const int MOD = 1e9+7;
const int N = 1e6+9;

#define fast()    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int ar[100005],br[100005];

int main()
{
    fast();
    ll t, num, x, y, z, c0=0, c1=0, sum=0, ans=0, res=0, m0;
    cin>>x>>y;
    for(ll i=1; i<=y; i++)
    {
        cin>>m0;
        sum+=m0;
    }
    if(sum>=x) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}


Measured memory_bytes: 256
/*
 * ITP1_6_B.cpp
 *
 *  Created on: Apr 20, 2018
 *      Author: 13743
 */

#include<iostream>
#include<cmath>

using namespace std;


bool isPrime(int n) {
	int r = sqrt(n);
	for(int i=2; i<=r; i++) {
		if(n % i == 0) {
			return false;
		}
	}
	return true;
}

int main() {
	int N;
	int cnt = 0;
	cin >> N;
	for(int i=0; i<N; i++) {
		int n;
		cin >> n;
		if(isPrime(n)) {
			cnt++;
		}
	}
	cout << cnt << endl;
}



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

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

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

#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(),x.end()

int main() {
    int N;
    cin >> N;
    vector<int> W(N);
    for(int i=0;i<N;i++)cin >> W[i];
    vector<int> sum(N+1);
    sum[0]=0;
    for(int i=1;i<N+1;i++){
        sum[i]+=sum[i-1]+W[i-1];
    }

    int ans = 100000000;

    for(int i=0;i<N+1;i++){
        int s1,s2;
        s1 = sum[i];
        s2 = sum[N]-sum[i];
        ans = min(ans,abs(s1-s2));
    }

    cout << ans << endl;


}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

typedef tuple<int, int, int> T;
// get<K>(tuple型の変数)



class UnionFind{
public:
    //親の番号を格納する。親だった場合はー（その集合のサイズ）
    vector<int> parents;
    int count;

    //作る時はparentsを-1で初期化する
    //こうすることで全部ばらばらになる
    UnionFind(int n){
        parents = vector<int>(n, -1);
        count = n;
    }

    //Aがどのグループにいるか調べる
    int root(int A){
        if(parents[A]<0) return A;
        return parents[A] = root(parents[A]);
    }

    //自分のいるグループの大きさを調べる
    int size(int A){
        return -parents[root(A)];
    }

    //AとBをくっつける
    bool connect(int A, int B){
        //AとBを直接ではなく親同士をくっつける
        A=root(A);
        B=root(B);
        if(A==B){
            return false;
        }

        //大きい方（A)に小さい方（B)をくっつけたい
        if(size(A)<size(B)) swap(A, B);

        parents[A] += parents[B];
        parents[B] = A;
        --count;

        return true;
    }
};

const ll MAX=110000;

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

    int n; cin >> n;
    UnionFind uni(MAX*2);
    vector<ll> x(n), y(n);
    rep(i,n){
        cin >> x[i] >> y[i];
        uni.connect(x[i], y[i]+MAX);
    }

    map<int, ll> mx, my;
    rep(i,MAX) mx[uni.root(i)]++;
    repr(i,MAX,2*MAX) my[uni.root(i)]++;
    ll res=0;
    rep(r,MAX*2) res+=mx[r]*my[r];
    cout << res-n << endl;
    
    return 0;
}


Measured memory_bytes: 30208
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))

for i in range(n):
    i_temperature = t - h[i]*0.006
    dif_a = abs(a - i_temperature)
    if i == 0:
        champ = dif_a
    if champ >= dif_a:
        champ = dif_a
        ans = i+1

print(ans)

Measured memory_bytes: 3060
#include <algorithm>
#include <complex>
#include <iostream>
#include <vector>
#include <iomanip>
#include <queue>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね

//ここから編集する

/*
 * ベルマンフォード方法による最短路問題
 * 0ビギナーであることに注意
 *                                 */
struct edge {
    int from, to;
    ll cost;
};
vector<edge> es; // 辺
vector<ll> d; //最短距離,0で初期化してね
int V, E;//頂点数と辺の数

bool find_negative_loop(int s) {
    //dは0で初期化しておくyu7y
    d[s] = 0;
    for (int i = 0; i < V; i++) {

        for (int j = 0; j < E; j++) {
            edge e = es[j];
            if (d[e.from] == INFl) continue;
            if (d[e.to] > d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
                if (i == V - 1) return true;
            }
        }
    }
    return false;
}

/* negative check */
vector<bool> negative;

void negative_check() {
    negative = vector<bool>(V,false);
    for (int i = 0; i < V; i++) {

        for (int j = 0; j < E; j++) {
            edge e = es[j];
            if (d[e.from] == INFl) continue;
            if (d[e.to] > d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
                negative[e.to] = true;
//                if (i == V - 1) return true;
            }
        }
    }
//    return false;
}

void print_d() {
    if (DEBUG) {
        REP(i, 0, d.size()) {
            cout << d[i] << " ";
        }
        cout << endl;
    }
}

int main() {
    queue<int> que;
    int N, M;
    cin >> N >> M;
    V = N;
    E = M;
    d = vector<ll>(V, INFl);
//    d[0] = 0;
    es = vector<edge>(E);

    REP(i, 0, M) {
        edge e;
        cin >> e.from >> e.to >> e.cost;
        e.from--;
        e.to--;
        e.cost *= -1;
        es[i] = e;
    }
//    d[0] = 0;
    find_negative_loop(0);
    ll ans = -d[N-1];
    negative_check();

    if (negative[N-1]) {
        cout << "inf" << endl;
    } else {
//        cout << -d[N-1] << endl;
        cout << -d[N - 1] << endl;
    }
    print_d();
    return 0;
}





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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        while (n-- > 0) {
            char[] m = sc.next().toCharArray();
            Arrays.sort(m);
            char[] l = new char[m.length];
            for (int i = m.length - 1; i >= 0; i--) {
                l[m.length - i - 1] = m[i];
            }
            System.out.println(Integer.parseInt(String.valueOf(l)) - Integer.parseInt(String.valueOf(m)));
        }
    }
}


Measured memory_bytes: 25912
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
#define fr first
#define sc second
ll n,W,ans=0;
map<ll,ll>res,tmp; 
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	cin>>n>>W;
	res[0]=0;
	for(int i=1;i<=n;++i){
		ll w,v;cin>>w>>v;
		tmp.clear();
		for(auto&x:res){tmp[x.fr+w]=x.sc+v;}
		for(auto&x:tmp){
			res[x.fr]=max(x.sc,res[x.fr]);
		}
	}
	for(auto&x:res){
		if(x.fr>W)break;
		ans=max(ans,x.sc);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>                                  
using namespace std;                                 
                                                     
int main(void) {                                     
  int a, b, c;                                       
  cin >> a >> b >> c;                                
  if ((a<b) && (b<c)) {                              
    cout << "Yes" << endl;                           
  } else {                                           
    cout << "No" << endl;                            
  }                                                  
  return 0;                                          
}                      

Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
#define int long long

signed main(){
	int n;
	int l,r;
	int a=1, b=1;
	cin >> n;
	LOOP(i,n){
		int mul = 0;
		cin >> l >> r;
		mul = max((l+a-1)/l, (r+b-1)/r);
		a=l*mul;
		b=r*mul;
		cerr << a << ":" << b << endl;
	}
	cout << a+b << endl;
}


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

int main() {
  int ans = 0;
  string s;
  cin >> s;
  if(s[0] == '1') ans++;
  if(s[1] == '1') ans++;
  if(s[2] == '1') ans++;
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>

#define dump(x) cerr << #x << "=" << (x) << endl;
using namespace std;
using ll = long long;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define IN(x) int (x); cin >> x
#define INS(x) string (s); cin >> s
#define INL(x) ll (x); cin >> x
#define VINT(a,n) vector<int> a(n)
#define VIN(a,n) VINT(a,n); REP(i,n){cin >> a[i];}
#define ALL(x) (x).begin(),(x).end()

int main () {
  int x;
  cin >> x;
  cout << 10-x/200 << endl;

}


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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr ll MOD = (ll)1e9 + 7;
constexpr ll MOD2 = 998244353;
constexpr ll HIGHINF = (ll)1e18;
constexpr ll LOWINF = (ll)1e15;
constexpr long double PI = 3.1415926535897932384626433;

template<typename T> vector<T> make_v(size_t N,T init){return vector<T>(N,init);}
template<typename... T> auto make_v(size_t N,T... t){return vector<decltype(make_v(t...))>(N,make_v(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
	int N,A,B; cin >> N >> A >> B;
	cout << min(B,N*A) << endl;

    return 0;
}


Measured memory_bytes: 384
package main

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

var scanner = bufio.NewScanner(os.Stdin)

// const (
// 	initialBufSize = bufio.MaxScanTokenSize //65536
// 	maxBufSize     = 100000
// )

func main() {
	scanner.Split(bufio.ScanWords)
	// buf := make([]byte, initialBufSize)
	// scanner.Buffer(buf, maxBufSize)

	n := nextInt()
	s := make([][]string, n)
	for i := range s {
		s[i] = make([]string, 10)
		s[i] = strings.Split(next(), "")
	}

	m := make(map[string]int)

	ans := 0
	for _, v := range s {
		sort.Strings(v)
		word := strings.Join(v, "")
		ans += m[word]
		m[word]++
	}
	fmt.Println(ans)
}

func next() string {
	scanner.Scan()
	return scanner.Text()
}
func nextInt() int {
	i, err := strconv.Atoi(next())
	if err != nil {
		fmt.Println(err)
	}
	return i
}


Measured memory_bytes: 37888
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;
typedef pair<ll,ll> P;

ll N;
ll a[100100];
ll ans;
ll ans2;
ll rui;
int main(){
  cin >> N;
  rep(i,N){
    cin >> a[i];
  }
  ll f = 0;
  rui = 0;
  rep(i,N){
    rui += a[i];
    if(f==0 && rui <= 0){
      ans += 1 - rui;
      rui += 1 - rui;
    }
    else if(f==1 && rui >= 0){
      ans += rui + 1;
      rui -= rui + 1;
    }
    f =(f+1)%2;
  }
  f = 1;
  rui = 0;
  rep(i,N){
    rui += a[i];
    if(f==0 && rui <= 0){
      ans2 += 1 - rui;
      rui += 1 - rui;
    }
    else if(f==1 && rui >= 0){
      ans2 += rui + 1;
      rui -= rui + 1;
    }
    f =(f+1)%2;
    cerr << rui << endl;
  }
  cout << min(ans,ans2) << endl;
}


Measured memory_bytes: 1024
n = gets.to_i
as = gets.split.map(&:to_i)

ans = []
reversed = false

n.times do |i|
  if reversed
    ans.push(as[i])
  else
    ans.unshift(as[i])
  end
  reversed = !reversed
end

puts reversed ? ans.join(" ") : ans.reverse!.join(" ")


Measured memory_bytes: 25444
class in {struct my_iterator{int it;const bool rev;explicit constexpr my_iterator(int it_, bool rev=false):it(it_),rev(rev){}int operator*(){return it;}bool operator!=(my_iterator& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const my_iterator i,n;public:explicit constexpr in(int n):i(0),n(n){}explicit constexpr in(int i,int n):i(i,n<i),n(n){}const my_iterator& begin(){return i;}const my_iterator& end(){return n;}};
 
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
 
using i64 = long long;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> a(N);
    for(int& x : a) cin >> x;

    int dia = *max_element(a.begin(), a.end());
    bool ok = true;
    ok &= dia >= (N == 2 ? 1 : 2);
    vector<int> cnt(N, 0);
    for(int x : a) cnt[x]++;

    for(int i : in(dia + 1))
        ok &= --cnt[dia - i / 2] >= 0;
    for(int i : in(N))
        if(cnt[i] > 0)
            ok &= i >= (dia + 1) / 2 + 1;

    cout << (ok ? "Possible" : "Impossible") << endl;
    
}

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

using namespace std;

int main() {
    char s[5];
    scanf("%s", s);
    if (s[0] == s[1] && s[1] == s[2]) {
        puts("Yes");
        return 0;
    }
    if (s[1] == s[2] && s[2] == s[3]) {
        puts("Yes");
        return 0;
    }
    puts("No");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>
#include <string>
#include <stack>
#include <tuple>

using namespace std;
typedef long long ll;

ll ans = 0;
string s;

int main()
{
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        if (i < k) ans += x;
        else ans += y;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };


signed main() {
	ll N;
	vector<ll>list;

	cin >> N;

	for (int i = 0; i < N; i++) {
		ll num;
		cin >> num;
		list.push_back(num);
	}

	sort(list.begin(), list.end());
	int index = -1;

	for (int i = 0; i < N - 1; i++) {
		if (list[i] * 2 < list[i + 1]) {
			index = i;
		}
		list[i + 1] += list[i];
	}

	cout << N - (index + 1) << endl;
	
	
	return 0;
}

Measured memory_bytes: 1400
a, b, c, d = map(int, input().split())
while d != 0 or a != 0:
  c -= b  # 高橋君の攻撃
  a -= d  # 青木君の攻撃
  if c <= 0:
    print("Yes")
    break
  elif a <= 0:
    print("No")
    break

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N; cin >> N;
  int S[15][15];
  int ans=0;
  for(int i=0;i<15;i++){
    for(int j=0;j<15;j++){
      S[i][j]=-1;
    }
  }
  for(int i=0;i<N;i++){
    int A; cin >> A;
    for(int j=0;j<A;j++){
      int x,y; cin >> x >> y;
      S[i][x-1]=y;
    }
  }
  for(int i=0;i<(1<<N);i++){
    int d[N];
    for(int j=0;j<N;j++){
      if(i>>j&1){
        d[j]=1;
      }
      else d[j]=0;
    }
    bool ok=true;
    for(int j=0;j<N;j++){
      if(d[j]){
        for(int k=0;k<N;k++){
          if(S[j][k]==-1) continue;
          if(S[j][k]!=d[k]) ok=false;
        }
      }
    }
    if(ok) ans=max(ans, __builtin_popcount(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[n],b[n],c[n];
   int dp[n][3];

  for(int i=0;i<n;i++)
  {cin>>a[i]>>b[i]>>c[i];
   }
  
  dp[0][0]=a[0];
  dp[0][1]=b[0];
  dp[0][2]=c[0];
  for(int i=1;i<n;i++)
  {
    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
    dp[i][2]=max(dp[i-1][1],dp[i-1][0])+c[i];

  }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;

}


Measured memory_bytes: 2560
import sys
import math


def solv(s):
    i = 0
    while True:
        i += 1
        c = frequency(s)
        if c == s:
            break
        else:
            s = c
    return (i - 1, c)


def frequency(lis):
    lis2 = map(lambda x: count(x, lis), lis)
    return lis2


def count(n, lis):
    return len(filter(lambda x: x ==n, lis))


while True:
    n = int(sys.stdin.readline())
    if n == 0:
        exit()
    s = map(int, sys.stdin.readline().split(' '))
    m, p = solv(s)
    print m
    print ' '.join(map(str, p))

Measured memory_bytes: 4480
s = input();

words = ["dream", "dreamer", "erase", "eraser"]

while(len(s) > 4):
    if s[-5:] == words[0]:
        s = s[:-5]
    elif s[-7:] == words[1]:
        s = s[:-7]
    elif s[-5:] == words[2]:
        s = s[:-5]
    elif s[-6:] == words[3]:
        s = s[:-6]
    else:
        break

print("YES") if len(s) == 0 else print("NO")

Measured memory_bytes: 3188
import math
import numpy as np

def katana(hp, katanas):
    katanas = np.array(katanas, 'i')
    max_slash = np.max(katanas[:, 0])
    throws = -np.sort(-katanas[:, 1])
    throws_index = np.where(throws > max_slash)[0]
    eff_throws = throws[throws_index]

    for i, v in enumerate(eff_throws):
        hp -= v
        if hp <= 0:
            print(i + 1)
            return

    print(len(eff_throws) + math.ceil(hp / max_slash))

n, hp = map(int, input().split())
takanas = [list(map(int, input().split())) for _ in range(n)]
katana(hp, takanas)

Measured memory_bytes: 38568
// ABC155_C
#include <algorithm>
#include <bitset>  // static_cast<std::bitset<8>>
#include <cctype>  // std::isdigit()
#include <climits>  // INT_MIN
#include <cmath>
#include <cstring>  // std::memset
#include <functional>  // std::greater<T>()
#include <iomanip>
#include <iostream>
#include <iterator>
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <sstream>  // std::stringstream
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>  // std::swap()
#include <vector>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> pll;
#define rep(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define rep1(i, n) for (ll i=1; i <= n; i++)  // 1 ~ n
#define repr(i, n) for (ll i=n-1; i >= 0; i++)  // n-1 ~ 0
#define all(vec) (vec).begin(), (vec).end()
#define sum(vec) accumulate(all(vec), 0LL)  // 0 は初期値
#define min_vec(vec) min_element(all(vec))  // iterator: * を先頭につける
#define max_vec(vec) max_element(all(vec))  // iterator: * を先頭につける
#define idx(vec, element_iter) distance((vec).begin(), element_iter)
const ll INF = 1LL<<60;  // 10^18（const int inf = 1<<29;）
const double PI = acos(-1);

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    // input(sunippets: inpv, inpn, inps)
    ll N;
    cin >> N;
    map<string, ll> mp;
    string str;
    rep(i, N) {
        cin >> str;
        mp[str]++;
    }
    
    // calculation
    // 文字列とそのカウントのペアを持った vector を作る
    auto begin = mp.begin(), end = mp.end();
    vector<pair<ll, string>> vec;
    pair<ll, string> p;
    for (auto itr = begin; itr != end; itr++) {
        // first: key, second: value 
        p = make_pair(itr->second, itr->first);
        vec.push_back(p);
    }
    // カウント数でソート
    sort(vec.begin(), vec.end(), greater<>());  // ll big -> small
    ll mx = vec[0].first;  // カウント数の最大値を取得
    
    // カウント数が mx（最大値）と等しい場合に文字列を取得
    vector<string> v_str;
    rep(i, vec.size()) {
        if (vec[i].first == mx) {
            v_str.push_back(vec[i].second);
        }
    }
    // 文字列を辞書順にする
    sort(v_str.begin(), v_str.end());
    
    // 出力
    rep(i, v_str.size()) {
        cout << v_str[i] << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 31084
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var s string
	fmt.Scan(&n, &s)

	l, r := 0, 0
	for _, c := range s {
		switch c {
		case '(':
			l++
		case ')':
			if l > 0 {
				l--
			} else {
				r++
			}
		}
	}

	ans := strings.Repeat("(", r) + s + strings.Repeat(")", l)
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;

int k, n, a[200010];

int main() {
    int maxt = 0;
    scanf("%d%d%d", &k, &n, &a[1]);
    for (int i = 2; i <= n; i++) {
        scanf("%d", &a[i]);
        maxt = max(maxt, a[i] - a[i - 1]);
    }
    maxt = max(maxt, a[1] - a[n] + k);
    printf("%d", k - maxt);
    return 0;
}

Measured memory_bytes: 2512
#E
x, y, al, bl, cl = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
am = x-1
bm = y-1
cm = 0
while True:
    #print(am)
    #print(bm)
    #print(cm)
    if cm >= cl:
        break
    elif am == -1:
        if bm == -1:
            break
        else:
            if c[cm] > b[bm]:
                cm += 1
                bm -= 1
            else:
                break
    elif bm == -1:
        if c[cm] > a[am]:
            cm += 1
            am -= 1
        else:
            break
    elif (c[cm] <= a[am]) & (c[cm] <= b[bm]):
        break
    elif (c[cm] > a[am]) & (c[cm] <= b[bm]):
        cm += 1
        am -= 1
    elif (c[cm] <= a[am]) & (c[cm] > b[bm]):
        cm += 1
        bm -= 1
    else:
        if (c[cm]-a[am]) < (c[cm]-b[bm]):
            cm += 1
            bm -= 1
        else:
            cm += 1
            am -= 1
ans = 0
if am != -1:
    for i in range(am+1):
        ans += a[i]
if bm != -1:
    for j in range(bm+1):
        ans += b[j]
if cm != 0:
    for k in range(cm):
        ans += c[k]

print(ans)

Measured memory_bytes: 23116
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const int MAXN = 2e5 + 5;
const int MOD = 998244353;

int n;
int f[MAXN],power[MAXN],s[MAXN];
vector<int> vec;
char str[MAXN];

int Calc(int len){
	int flag = 1,res = 0;
	for(int i = 1;i <= len;i++){
		if(s[i] == 1)
			res = (res + power[len - i]) % MOD;
	}
	for(int i = len + 1;i <= n;i++){
		if(s[i] != (s[i - len] ^ 1)){
			flag = (s[i] > (s[i - len] ^ 1) ? 1 : 0);
			break;
		}
	}
	return (flag + res) % MOD;
}

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d",&n);
	scanf("%s",str + 1);
	for(int i = 1;i <= n;i++)
		s[i] = str[i] - '0';
	power[0] = 1;
	for(int i = 1;i <= n;i++)
		power[i] = 2ll * power[i - 1] % MOD;
	for(int i = 1;i <= n;i++){
		if(n % i == 0 && (n / i) & 1)
			vec.push_back(i);
	} 
	for(int i = 0;i < (int)vec.size();i++)
		f[vec[i]] = Calc(vec[i]);
	for(int i = 0;i < (int)vec.size();i++){
		for(int j = 0;j < (int)vec.size();j++){
			if(vec[j] % vec[i] == 0 && vec[j] > vec[i])
				f[vec[j]] = (f[vec[j]] - f[vec[i]] + MOD) % MOD;
		}
	}
	int ans = 0;
	for(int i = 0;i < (int)vec.size();i++)
		ans = (ans + 2ll * vec[i] * f[vec[i]] % MOD) % MOD;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
int main() {
	int x, n; cin >> x >> n;
	set<int> st;
	for (int i = 0; i <= 101; i++)
		st.insert(i);
	for (int i = 0; i < n; i++) {
		int t; cin >> t;
		st.erase(t);
	}
	auto it = st.lower_bound(x);
	int abs1 = abs(*it - x);
	int abs2 = INT_MAX;
	if (it != st.begin())
		abs2 = abs(*(--it) - x);
	cout << (abs1 < abs2 ? x + abs1 : x - abs2);
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
using namespace std;
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / __gcd(a, b); }
bool isPrime(int n) {if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false;
    return true;}


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll a,b;
    cin>>a>>b;
    if(b%2==1)cout<<"No"<<endl;
    else if(b<a*2||b>a*4)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 3644
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
#define ll long long
const double EPS = 1e-10;

int main (){
  ll a,b;
  ll ans=0;
  cin>>a>>b;
  if(b%a==0)ans=a+b;
  else ans=b-a;
  cout<<ans<<endl;
}


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

int N;
int A[16];
int x[16][16];
int y[16][16];

int count(int bits) {
    if (bits == 0) return 0;
    return count(bits >> 1) + (bits & 1);
}
 
int main() {
    cin >> N;
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
        for (int j = 1; j <= A[i]; j++) {
            cin >> x[i][j] >> y[i][j];
        }
    }
 
    int result = 0;
    for (int bits = 1; bits < (1 << N); bits++) {
        bool ok = true;
        for (int i = 1; i <= N; i++) {
            if ( !( bits & ( 1 << (i-1) ) ) ) continue;
            for (int j = 1; j <= A[i]; j++) {
                if ( ( ((bits >> (x[i][j]-1)) & 1) ^ y[i][j] ) ) ok = false;
            }
        }
        if (ok) result = max(result, count(bits));
    }
 
    cout << result << endl;
    return 0;
}

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

using namespace __gnu_pbds;
using namespace std;

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

const int infI=1e9+5;
const long long infL=1e16;
const int MOD=1e9+7;
const int MAX=2e5+5;

#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define iii pair<ii,int>
#define ll long long
#define pll pair<ll,ll>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define forn(i,a,b) for(ll i=a;i<b;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define endl '\n'
#define popb pop_back()
#define se second
#define fi first
#define test(t) int t;cin>>t;while(t--)
#define debug(x) cerr<<"=>"<<#x<<" = "<<x<<endl

ll power(ll a,ll b){
    if(b==0){
        return 1;
    }
    if(b==1){
        return a;
    }
    ll temp=power(a,b/2);
    temp=(temp*temp)%MOD;
    if(b%2){
        temp=(temp*a)%MOD;
    }
    return temp;
}

//only use if mod is prime
ll mod_inv(ll a,ll mod){
    a%=mod;
    return power(a,mod-2);
}

void extended_gcd(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return;
    }
    ll x1,y1;
    extended_gcd(b,a%b,x1,y1);
    x=y1;
    y=x1-((a/b)*y1);
    return;
}

//TLE can also occur if vectors are not passed by reference, debug statements can also cause TLE.
//priority_queue implements max heap by default

int main(){
    fastio;
    // think about edge cases like n=1(especially graph questions).
    int n;
    cin>>n;
    string s;
    cin>>s;
    int i = 0,j = n-1;
    while(i<n and s[i] == 'R'){
        ++i;
    }
    while(j>=0 and s[j] == 'W'){
        --j;
    }
    int ans = 0;
    while(i<=j){
        swap(s[i],s[j]);
        ++ans;
        while(i<n and s[i] == 'R'){
            ++i;
        }
        while(j>=0 and s[j] == 'W'){
            --j;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;	cin>>n;
	vector<int> x(n);
	vector<pair<int,int> > use;
	for(int i=0;i<n;i++){
		cin>>x[i];
		use.push_back(make_pair(x[i]-1,i+1));
	}
	sort(use.begin(),use.end());
	
	vector<int> ret(n*n,0);
	vector<int> cnt(n,1);
	int check=0;
	int fin=0;
	for(int i=0;i<n;i++)	ret[use[i].first]=use[i].second;
	int i=0;
	for(;i<n*n;i++){
		if(ret[i]!=0)	continue;
		if(cnt[use[fin].second-1]<use[fin].second){
			cnt[use[fin].second-1]++;
			ret[i]=use[fin].second;
		}
		if(cnt[use[fin].second-1]==use[fin].second){
			fin++;
			if(ret[i]==0)	i--;
			if(fin==n)	break;
		}
	}
	fin=0;
	for(;i<n*n;i++){
		if(ret[i]!=0)	continue;
		if(cnt[use[fin].second-1]<n){
			ret[i]=use[fin].second;
			cnt[use[fin].second-1]++;
		}
		if(cnt[use[fin].second-1]==n){
			fin++;
			if(ret[i]==0)	i--;
			if(fin==n)	break;
		}
	}
	for(int i=0;i<n;i++)	cnt[i]=0;
	int s=0;
	for(int i=0;i<n*n;i++){
		cnt[ret[i]-1]++;
		if(i==use[s].first){
			if(cnt[use[s].second-1]!=use[s].second){
				cout<<"No"<<endl;
				return 0;
			}
			s++;
		}
	}
	cout<<"Yes"<<endl;
	for(int i=0;i<n*n;i++)	cout<<(i?" ":"")<<ret[i];
	cout<<endl;
	return 0;
}


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

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

    int sum = 0;
    int c_num = N;

    while (c_num > 0) {
        sum += c_num % 10;
        c_num /= 10;
    }

    if (N % sum == 0) {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <stdlib.h>
using namespace std;

int main(){
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	int ans = min(B, D) - max(A, C);
	if(ans < 0) ans = 0;
	cout << ans << endl;
	return 0;

}


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

int main(){
  int i,j,cnt=0;
  int n,a,b;
  cin>>n>>a>>b;
  string s;
  cin>>s;
  int p=0;
  for(i=0;i<n;i++){
    if(s[i]=='a' && cnt<a+b){
      cout<<"Yes"<<endl;
      cnt++;
    }
    else if(s[i]=='b' && p<b && cnt<a+b){
      cout<<"Yes"<<endl;
      cnt++;
      p++;
    }else cout<<"No"<<endl;
  }
}

Measured memory_bytes: 896
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
#include <assert.h>

int main(void){
		int a,b;
		scanf("%d",&a);
    scanf("%d",&b);

    if(a>b){
      puts("safe");
    }
    else{
      puts("unsafe");
    }

		return 0;
}


Measured memory_bytes: 1620
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>

using namespace std;

map<string, int> C;
int N;
string S[200005];
set<string> T;

int main(void) {

	cin >> N;

	for (int i = 1; i <= N; i++) {
		cin >> S[i]; C[S[i]]++; T.insert(S[i]);
	}

	int num = 0;
	for (auto y : T) {
		num = max(num, C[y]);
	}

	set<string> A;

	for (auto y : T) {
		if (C[y] == num) { A.insert(y); }
	}

	for (auto x : A) {
		cout << x << endl;
	}



	return 0;
}

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

int main() {
  long long N,A,B;
  cin >> N >> A >> B;
  
  if(N%(A + B) > A) cout << N/(A + B)*A + A << endl;
  
  else cout << N/(A + B)*A + N%(A + B) << endl;
  
}


Measured memory_bytes: 256
#include <atcoder/scc>
#include <iostream>
#include <vector>
using ll = long long;
#define rep(i, j, n) for (int i = 0; i < n; ++i)
using namespace std;

int main() {
  int n, m, a, b;
  cin >> n >> m;
  atcoder::scc_graph scc(n);
  rep(i, 0, m) {
    cin >> a >> b;
    scc.add_edge(a, b);
  }
  vector<vector<int>> res = scc.scc();

  cout << res.size() << '\n';
  rep(i, 0, res.size()) {
    cout << res[i].size() << ' ';
    rep(j, 0, res[i].size()) cout << res[i][j] << " \n"[j == res[i].size() - 1];
  }

  return 0;
}

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


def ceil(a, b):
    if a % b == 0:
        return a // b
    else:
        return a // b + 1


tx, ax = 1, 1
for i in range(n):
    t, a = [int(j) for j in input().split()]
    n = max(ceil(tx, t), ceil(ax, a))
    tx, ax = n * t, n * a
print(tx + ax)


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

ll n,m;

int main(void){
	scanf("%d%d",&n,&m);
	if(n==1LL && m==1LL){
		printf("%lld\n",1);
	}else if(n==1LL || m==1LL){
		printf("%lld\n",n*m-2LL);
	}else{
		printf("%lld\n",(n-2LL)*(m-2LL));
	}
	return 0;
}

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

struct Node { int p, l, r; };
struct Node T[MAX];
int n;

void preParse(int u)
{
    if (u == NIL) return;
    printf(" %d", u);
    preParse(T[u].l);
    preParse(T[u].r);
}

void inParse(int u)
{
    if (u == NIL) return;
    inParse(T[u].l);
    printf(" %d", u);
    inParse(T[u].r);
}

void postParse(int u)
{
    if (u == NIL) return;
    postParse(T[u].l);
    postParse(T[u].r);
    printf(" %d", u);
}


int main(int argc, char const *argv[])
{
    int i, v, l, r, root;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        T[i].p = NIL;
    }
    for (i = 0; i < n; i++) {
        scanf("%d %d %d", &v, &l, &r);
        T[v].l = l;
        T[v].r = r;
        if (l != NIL) T[l].p = v;
        if (v != NIL) T[r].p = v;
    }

    for (i = 0; i < n; i++) {
        if (T[i].p == NIL) {
            root = i;
            break;
        }
    }

    printf("Preorder\n");
    preParse(root);
    printf("\n");
    printf("Inorder\n");
    inParse(root);
    printf("\n");
    printf("Postorder\n");
    postParse(root);
    printf("\n");

    return 0;
}




Measured memory_bytes: 2044
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define   ull unsigned long long 
#define mp make_pair
#define pb push_back
const int MAX=2e5+9;
const long long mod=1e9+7;
using namespace std;
vector<int>adj[MAX];
int main(){
	int n;
	cin>>n;
	int arr[n+1];
	int b[n+1];
	for(int i=0;i<n;i++){
		cin>>arr[i];
		b[i]=arr[i];
	}
	sort(arr, arr+n);
	int mx=arr[n-1];
	int p=arr[n-2];
	for(int i=0;i<n;i++){
		if(b[i]==mx)
			cout<<p<<"\n";
		else
			cout<<mx<<"\n";
	}

}

Measured memory_bytes: 7808
#include<bits/stdc++.h>
#include<iostream>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
signed main(){
    ll n;cin>>n;
    vector<ll>p(n);
    rep(i,n)cin>>p[i];
    ll cnt=0;
    rep(i,n){
        if(i+1==p[i]){
            cnt++;
            i++;
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			int n = stdIn.nextInt();
			if(n == 0) break;
			boolean[][] map = new boolean[21][21];
			for(int i = 0; i < n; i++) {
				int x = stdIn.nextInt();
				int y = stdIn.nextInt();
				map[20-y][x] = true;
			}
			int nx = 10;
			int ny = 10;
			int m = stdIn.nextInt();
			for(int i = 0; i < m; i++) {
				String d = stdIn.next();
				int c = stdIn.nextInt();
				if(d.equals("N")) {
					for(int j = 0; j < c; j++) {
						if(map[ny][nx]) {
							map[ny][nx] = false;
						}
						ny--;
						if(map[ny][nx]) {
							map[ny][nx] = false;
						}
					}
				}
				if(d.equals("S")) {
					for(int j = 0; j < c; j++) {
						if(map[ny][nx]) {
							map[ny][nx] = false;
						}
						ny++;
						if(map[ny][nx]) {
							map[ny][nx] = false;
						}
					}
				}
				if(d.equals("W")) {
					for(int j = 0; j < c; j++) {
						if(map[ny][nx]) {
							map[ny][nx] = false;
						}
						nx--;
						if(map[ny][nx]) {
							map[ny][nx] = false;
						}
					}
				}
				if(d.equals("E")) {
					for(int j = 0; j < c; j++) {
						if(map[ny][nx]) {
							map[ny][nx] = false;
						}
						nx++;
						if(map[ny][nx]) {
							map[ny][nx] = false;
						}
					}
				}
			}
			boolean ans = true;
			for(int i = 0; i < 21; i++) {
				for(int j = 0; j < 21; j++) {
					if(map[i][j]) ans = false;
				}
			}
			System.out.println((ans)?"Yes":"No");
		}
	}

}

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

//諸機能
#pragma region MACRO 
#define putans(x)  cerr << "answer: " ; cout << (x) << endl
#define dputans(x) cerr << "answer: "; cout << setprecision(10) << (double)(x) << endl
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define RREP(i,a,n) for(int i=(int)(n-1); i>= a; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) begin((a)),end((a))
#define mp make_pair
#define exist(container, n) ((container).find((n)) != (container).end())
#define substr(s,i,l) string((s), (i), (l))
#define tos(x) (to_string((x)))
#ifdef _DEBUG //ファイルからテストデータを読み込む
std::ifstream ifs("data.txt");
#define input ifs >>
#else //いい感じにやる
#define input cin >>
#endif
#pragma endregion
//デバッグなどの支援
#pragma region CODING_SUPPORT
#define dbg(var0) { std::cerr << ( #var0 ) << "=" << ( var0 ) << endl; }
#define dbg2(var0, var1) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg(var1); }
#define dbg3(var0, var1, var2) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg2(var1, var2); }
#define dbgArray(a,n) {std::cerr << (#a) << "=";  rep(i,n){std::cerr <<(a[i])<<",";} cerr<<endl;} 
#ifndef _DEBUG
#define dbg1 {}
#define dbg2 {}
#define dbg3 {}
#define dbgArray {}
#endif 
#pragma endregion 
//typedef（書き換える、書き足す可能性ある）
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii; typedef pair<string, string> pss; typedef pair<int, string>pis;
typedef vector<string> vs; typedef vector<int> vi;
#pragma endregion
//諸々の定数(書き換える可能性ある)
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(1e9)
#pragma endregion

int main() {
	ll n, l; input n >> l;
	vector<ll> a;
	vi rireki;
	ll sumlength = 0;
	rep(i, n) {
		int ai; input ai;
		a.push_back(ai);
		sumlength += ai;
	}
	bool clear = false;
	int lastp = -1;
	rep(i, n) {
		if (a[i] + a[i + 1] >= l) {
			clear = true;
			lastp = i + 1;
			break;
		}
	}
	if (clear) {
		putans("Possible");
		rep(i, n - 1) {
			if (i + 1 == lastp)break;
			putans(i + 1);
		}
		RREP(i, 0, n) {
			if (i == lastp)break;
			putans(i);
		}
		putans(lastp);

	}
	else {
		putans("Impossible");
	}
	return 0;
}

Measured memory_bytes: 1780
#include <vector>
#include <bitset>
#include <cstdio>

using B = std::bitset<32>;

int main()
{
  int N;
  scanf("%d\n", &N);
  int S[500000];
  for(int i = 0; i < N; ++i) {
    char c;
    scanf("%c", &c);
    S[i] = 1 << (c - 'a');
  }
  int Q;
  scanf("\n%d\n", &Q);
  while (Q--) {
    int q;
    scanf("%d ", &q);
    if (q == 1) {
      int i;
      char c;
      scanf("%d %c\n", &i, &c);
      S[i - 1] = 1 << (c - 'a');
    } else {
      int r, l;
      scanf("%d %d\n", &r, &l);
      --r;
      int res{};
      for (int i = r; i < l; ++i) {
          res |= S[i];
      }
      B ans(res);
      printf("%d\n", ans.count());
    }
  }
  return 0;
}


Measured memory_bytes: 2304