akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);

vector<vector<ll>> g(0);

signed main(){
    ll n,m,ans=-1;
    cin>>n>>m;
    g.assign(3*n +1,vector<ll>());
    
    for(int i=0;i < m;i++)
    {
        ll u,v;
        cin>>u>>v;
        g.at(u).pb(n+v);
        g.at(n+u).pb(2*n+v);    
        g.at(2*n+u).pb(v);
    }
    queue<ll> q;
    ll s,t;
    cin>>s>>t;
    q.push(s);
    q.push(0);

    while(siz(q)>0){
        ll x=q.front();
        q.pop();
        ll cnt=q.front();
        q.pop();

        if(x==t){
            ans=cnt;
            ans/=3;
            break;
        }

        for(int i=0;i < siz(g.at(x));i++)
        {
            q.push(g.at(x).at(i));
            q.push(cnt+1);
        }
        g.at(x).clear();
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 16640
#include <iostream>

using namespace std;

int main() {

    char N[3];

    cin >> N;

    for(int i = 0; i < 3; i++) {
        if(N[i] == '7') {
            cout << "Yes" << endl;
            return 0;
        }
    }

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

}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define EPS 1e-9
#define MOD	1000000007
#define int	long long
#define sz(x) (int)x.size()
#define all(a) (a).begin(),(a).end()
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;


#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << "[" << *it << " = " << a << "]" << " ";
	err(++it, args...);
}


int32_t main(){
	string s;
	cin >> s;
	for(int i = 0; i < (int)s.size()-1; i++)
		if(s[i] == s[i+1]){
			cout << "Bad";
			return 0;
		}
	cout << "Good";

	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
using namespace std;

int a[10];

int main()
{
	int i, x;
	for (i = 1; i <= 4; ++i)
	{
		scanf("%d", &x);
		a[x] = 1;
	}
	if (a[1] && a[9] && a[7] && a[4]) printf("YES");
	else printf("NO");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
int xxx,yyy,zzz,r;
using namespace std;
int gcd(int x,int y){return y==0?x:gcd(y,x%y);}
int pd(int x,int y,int z){
	int kk=x*y*z,kkk=x*y+y*z+x*z;
	int kkkk=gcd(kk,kkk);kk/=kkkk;kkk/=kkkk;
	if (kk==xxx&&kkk==yyy){
		cout<<x<<' '<<y<<' '<<z<<endl;
		exit(0);
	}
	if (kkk*xxx>yyy*kk)return false;
		else return true;
}
signed main(){
	cin>>xxx;yyy=4;zzz=gcd(xxx,yyy);xxx/=zzz;yyy/=zzz;
	for (int i=1;i<=3500;i++){
		r=3500;for (int j=i;j<=3500;j++){
			while (pd(i,j,r)&&j<=r)r--;
			if (j>r)break; 
		}
	}
} 

Measured memory_bytes: 256
#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

int main() {
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;

  vl A(X);
  vl B(Y);
  vl C(Z);

  FOR(i, 0, X) { cin >> A[i]; }
  FOR(i, 0, Y) { cin >> B[i]; }
  FOR(i, 0, Z) { cin >> C[i]; }

  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());  //降順ソート
  sort(B.begin(), B.end());
  reverse(B.begin(), B.end());  //降順ソート
  sort(C.begin(), C.end());
  reverse(C.begin(), C.end());  //降順ソート

  int a, b, c;
  ll rep = A[0] + B[0] + C[0];

  priority_queue<ll> PQ;

  FOR(i, 0, min(X, K)) {
    FOR(j, 0, min(Z, Y)) {
      FOR(k, 0, min(Z, K)) {
        if ((i + 1) * (j * 1) * (k * 1) <= K)
          PQ.push(A[i] + B[j] + C[k]);
        else
          break;
      }
    }
  }

  FOR(i, 0, K) {
    cout << PQ.top() << endl;
    PQ.pop();
  }
}

Measured memory_bytes: 35176
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
//#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  dsu d(n);
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    d.merge(a,b);
  }
  vector<vector<int> > v=d.groups();
  cout<<v.size()-1<<endl;

  return 0;
}


Measured memory_bytes: 8992
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <functional>
#include <cmath>
#include <cstdint>
#include <mutex>
#include <thread>
#include <bitset>
#include <utility>

using namespace std;

int main()
{
	long long int n, k;

	cin >> n >> k;

	n %= k;

	if (n >= abs(n - k))
		cout << abs(n - k);
	else
		cout << n;

	return 0;
}


Measured memory_bytes: 384
n,x = list(map(int,input().split()))
l = list(map(int,input().split()))
l.insert(0,0)
r = 0
n_l = []
for i in l:
    r += i
    n_l.append(r)

ans = 0
for i in n_l:
    if i <= x:
        ans += 1

print(ans)

Measured memory_bytes: 3064
import java.util.*;
public class Main{
	public static void main(String[] args){
		Main main = new Main();
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		Deque<Long> deque = new ArrayDeque<Long>();
		for (long i = 1; i < 10; i++) {
			deque.add(i);
		}
		for (int i = 1; i < K; i++) {
			long num = deque.poll();
			if (num%10 != 0) {
				deque.add(10 * num + num%10 - 1);
			}
			deque.add(10* num + num%10);
			if (num%10 != 9) {
				deque.add(10 * num + num%10 + 1);
			}
		}
		System.out.println(deque.poll());
	}
}

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

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

typedef int64_t ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

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

  int height = 0;
  int min_height = 0;
  REP(i, N) {
    if(S[i] == '(') {
      height += 1;
    }else{
      height -= 1;
      min_height = min(min_height, height);
    }
  }

  int left = -min(0, min_height);
  int right = height + left;
  string ret;
  REP(i, left) ret += '(';
  ret += S;
  REP(i, right) ret += ')';

  cout << ret << endl;
  return 0;
}



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

int main()
{

    string s1,s2,s3;
    getline(cin,s1);
    getline(cin,s2);
    getline(cin,s3);
    printf("%c%c%c\n",s1[0],s2[1],s3[2]);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<28)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    ll x, y;
    cin >> n;
    x = y = 1;
    rep(i, 0, n) {
        ll t, a;
        cin >> t >> a;
        ll mul = max(x%t ? x/t+1 : x/t, y%a ? y/a+1 : y/a);
        x = t * mul, y = a * mul;
    }
    cout << x + y << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String s1 = sc.next();
//		String s2 = new StringBuilder(sc.next()).reverse().toString();
		String s2 = new StringBuffer(sc.next()).reverse().toString();

		System.out.println((s1.equals(s2)) ?  "YES" : "NO");

		sc.close();


	}

}




Measured memory_bytes: 21716
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
 
#include<bits/stdc++.h>
 
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); 
#define nl "\n"
#define sz(a) (int)(a).size() 
#define all(a) (a).begin(),(a).end()
#define fl(a,x) memset(a,x,sizeof(a));
#define pt(a,x) cout << get<x>(a) << " " ;  
#define mt make_tuple 
#define vec vector
 
#define int long long 
 
const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18 ;
 
typedef vector<int> vii;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;
 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

void solve(int test) {
	
	int n; cin >> n ;
	map<int,int> m ;
	for(int i = 1; i <=100 ; ++i) {
		for(int j = 1; j <=100; ++j) {
			for(int k = 1; k <= 100 ; ++k) {
				m[i*i+j*j+k*k+i*j+i*k+j*k]++;
			}
		}
	}
	rep(i,1,n+1) {
		cout << m[i] << nl ;
	}
}
 
int32_t main() {
 
    fast;
	int t=1;
	// cin>>t;
	rep(i,0,t) {
		solve(i) ;
	}
 
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

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

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


Measured memory_bytes: 256
sa = list(input())
sb = list(input())
sc = list(input())

cards = [sa,sb,sc]
turn = 0
while True:
    if len(cards[turn]) == 0:
        print(chr(ord('A')+turn))
        break
    tmp = cards[turn].pop(0)

    turn = ord(tmp) - ord('a')


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const ll mod = 1e+9 + 7;

#define chadd(x, y) x = (x + y) % mod

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

    int n;
    cin >> n;
    vector<P> input(n);
    for(int i = 0; i < n; ++i){
        int x, l;
        cin >> x >> l;
        input[i] = (P(x - l, x + l));
    }
    sort(input.begin(), input.end());
    int left = input[0].first, right = input[0].second;
    int remove = 0;
    for(int i = 1; i < n; ++i){
        int n_left = input[i].first, n_right = input[i].second;
        if(n_left >= right){
            left = n_left, right = n_right;
        }
        else{   // n_left < right
            if(n_right < right){
                left = n_left, right = n_right;
            }
            ++remove;
        }
    }
    cout << n - remove << endl;
}

Measured memory_bytes: 1024
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
	    Scanner scan=new Scanner(System.in);
	    String str=scan.next();
	    long c=0;
	    for(int i=0;i<str.length();i++)
	    {
	        c+=(str.charAt(i)-'0');
	    }
	    if(c%9 == 0)
	        System.out.println("Yes");
	    else
	        System.out.println("No");
	}
}


Measured memory_bytes: 40476
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <stdio.h>

int main(void){
  int n,ans=0;
  std::cin >> n;
  std::vector<int> l(n);
  for(int i=0;i<n;i++)  std::cin >> l[i];
  std::sort(l.begin(), l.end());

  for(int i=0;i<n;i++){
    for(int j=0;j<i;j++){
      for(int k=0;k<j;k++){
        if(l[i]!=l[j] &&
           l[j]!=l[k] &&
           l[k]!=l[i] &&
           l[j] + l[k] >l[i] ){
          ans++;
        }
  }}}

  std::cout << ans;
  return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0);
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

template <class T>
void VecRowShow(vector<T> vec) {
	rep(i, vec.size()) {
		if (i != vec.size() - 1) cout << vec[i] << " ";
		else cout << vec[i] << endl;
	}
}


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



Measured memory_bytes: 256
def warshall_floyd(dist_matrix)
	dist = dist_matrix
	n = dist.size
	raise "dist_matrix is not square" if dist.any?{|row| row.size != n}

	(0..n-1).each{|k|
		next_dist = (1..n).map{ Array.new(n) }	
		(0..n-1).each{|i|
			(0..n-1).each{|j|
				x = dist[i][j]
				y = dist[i][k] + dist[k][j]
				next_dist[i][j] = (x < y ? x : y)
			}
		}
		dist = next_dist
	}
	dist
end


loop {
	m = gets.to_i
	break if m == 0
	dist_mat = (0..9).map{(0..9).map{Float::INFINITY}}
	(0..9).each{|i| dist_mat[i][i] = 0}
	m.times{
		i, j, d = gets.split.map &:to_i
		dist_mat[i][j] = d
		dist_mat[j][i] = d
	}
	while dist_mat.last.count(Float::INFINITY) == dist_mat.size - 1
		dist_mat.pop
		dist_mat.each(&:pop)
	end
	puts warshall_floyd(dist_mat).map.with_index{|r, i| [r.inject(:+), i]}.min.reverse * ' '
}

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

int main() {
	int N;
	cin >> N; 
	int num=0; 
	for(int i=0; i<N; i++){
		int l;
		int r;
		cin >> l >> r;
		num+=r-l+1;
	}
	cout << num << endl;
}


Measured memory_bytes: 256
from fractions import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)

a, b, c, d = map(int, input().split())
cd = lcm(c, d)
res = (b-a+1) - ((b//c - (a-1)//c) + (b//d - (a-1)//d) - (b//cd - (a-1)//cd))
print(res)

Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

vector<ll> v[100001];
struct Node{
    ll par;
    vector<ll> chi;
};
Node node[100001];
vector<ll> bro;
ll bro1;
void hoge(ll i){
    ll sum=0;
    rep(j,0,v[i].size()-1){
        if(v[i][j]!=node[i].par){
            node[i].chi.pb(v[i][j]);
            node[v[i][j]].par=i;
            sum++;
            hoge(v[i][j]);
        }
    }
    if(i==1){
        bro1=sum;
    }else if(sum>0){
        bro.pb(sum);
    }
}

ll kai(ll i,ll j){
    ll sum=1;
    rep(ii,0,j-1){
        sum=(sum*(i-ii))%i_7;
    }
    return sum;
}


int main(){
    ll n,k;cin>>n>>k;
    ll a[n-1],b[n-1];
    if(n==1){
        cout<<k<<endl;
        return 0;
    }
    rep(i,0,n-2){
        cin>>a[i]>>b[i];
        v[a[i]].pb(b[i]);
        v[b[i]].pb(a[i]);
    }
    node[1].par=1;
    hoge(1);
    ll ans=k%i_7;
    ans=(ans*kai(k-1,bro1))%i_7;
    if(bro.size()>0){
        rep(i,0,bro.size()-1){
            ans=(ans*kai(k-2,bro[i]))%i_7;
        }
    }
    cout<<ans<<endl;
    
    
    
    return 0;
}




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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>(b);i--)
#define P pair<int,int>
typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//s.find(w[i])==string::npos
//findの使い方

long long int n,cnt=0,ans=0,a,b,c,cmp,data,m,h,x,y;

string s,w;

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

	cin >> s;
	a=s.size();
	rep(i,s.size()){
	    if(s[i]=='S'){
	        cnt++;
	    }
	    else{
	        if(cnt>0){
	            cnt--;
	            a-=2;
	        }
	    }
	}
	cout << a << endl;
return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	cin >>n;
	ll sum=0;
	Vi a(n),ans(n,0);
	rep(i,n){
		cin>>a[i];
		sum ^=a[i];
		
	}
		//clog<<bitset<64>(sum)<<endl;
	rep(i,n){
		//clog << bitset<64>(a[i]) << endl;
		ans[i]=sum^a[i];
		cout<<ans[i];
		if(i!=n-1){
			cout<<" ";
		}
	}
	cout<<endl;
}
/*
20   01100 (16,4)
11   01011(8,2,1)
9    01001
24   11000(16,8)
sum  10110


an
    11010
	11101
	10001
	01110
 all0 => 0
 all1 => all 1
 one 1 other 0 =>  
*/

Measured memory_bytes: 4748
/*
[abc104] B - AcCepted
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

string S;

bool solve() {
    if (S[0] != 'A') {
        return false;
    }

    int pos = -1;
    for (int i = 2; i <= (int)S.length() - 2; i++) {
        if (S[i] == 'C') {
            if (pos != -1) {
                return false;
            }
            pos = i;
        }
    }
    if (pos == -1) {
        return false;
    }

    for (int i = 1; i < (int)S.length(); i++) {
        if (i == pos) {
            continue;
        }
        if (S[i] < 'a' || 'z' < S[i]) {
            return false;
        }
    }

    return true;
}

int main() {
    cin >> S;

    cout << (solve() ? "AC" : "WA") << endl;

    return 0;
}


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

int main(){
 int n,x,l;
 while(1){
  cin >> n >> x;
  if(n==0&&x==0) break;
  l=0;
  for(int i=1;i<=n-2;++i){
   for(int j=i+1;j<=n-1;++j){
    for(int k=j+1;k<=n;++k){
     if((i+j+k)==x) l+=1;
    }
   }
  }
 cout << l << endl;
 }
 return 0;
}

Measured memory_bytes: 3084
#include <stdio.h>
int main(void)
{
	int l,a[2],b[2],i,m=0;
	scanf("%d",&l);
	scanf("%d%d %d%d",&a[0],&a[1],&b[0],&b[1]);
	for(i=0;i!=2;++i){
		if(m<a[i]/b[i]){
			if(0==a[i]%b[i])
				m=a[i]/b[i];
			else
				m=a[i]/b[i]+1;
		}
	}
	printf("%d\n",l-m);
}

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

using namespace std;

typedef pair<int, int> ii;
typedef long long ll;
const int oo = 1e9 + 7;
const int modulo = 1e9 + 7;
template<typename T>
inline T sum(const T& a, const T& b) { return T((a % modulo + b % modulo) % modulo); }
template<typename T>
inline T mul(const T& a, const T& b) { return T((1LL * (a % (1LL * modulo)) * (b % (1LL * modulo))) % (1LL * modulo)); }
string to_string(string a) { return "\"" + a + "\""; }
#ifdef __LOCAL_DEBUG
#define debug(args...) { string __out = #args; replace(__out.begin(), __out.end(), ',', ' '); stringstream __out_ss(__out);\
istream_iterator<string> __it(__out_ss); _debug(__it, args); }
void _debug(istream_iterator<string> it) { }
template<typename T, typename... Args>
void _debug(istream_iterator<string> it, T a, Args... args){ cerr << *it << " = " << to_string(a) << '\n'; _debug(++it, args...); }
#else
#define debug(...)
#endif

bool check(string s) {
  if (int(s.size()) <= 2) return true;
  if (s.find("AGC") != string::npos)
    return false;
  for (int i = 0; i < int(s.size()) - 1; ++i) {
    swap(s[i], s[i + 1]);
    if (s.find("AGC") != string::npos)
      return false;
    swap(s[i], s[i + 1]);
  }
  return true;
}

typedef pair<int, string> is;
map<is, int> mem;
const char* p = "ACGT";
int n, ans = 0;

int dfs(int i, string s) {
  if (mem.find(is(i, s)) != mem.end())
    return mem[is(i, s)];
  if (i == n)
    return mem[is(i, s)] = 1;
  int res = 0;
  for (int j = 0; j < 4; ++j) {
    string tmp = s;
    tmp.push_back(p[j]);
    if (check(tmp)) {
      if (tmp.size() == 4) {
        tmp.erase(0, 1);
      }
      res = sum(res, dfs(i + 1, tmp));
    }
  }
  return mem[is(i, s)] = res;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < 4; ++i) {
    string s;
    s.push_back(p[i]);
    ans = sum(ans, dfs(1, s));
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 896
s = str(input())
K = int(input())
# sがabcac の場合、a,bca,ac などは部分列(substring
# abc とabの場合、abの方が辞書順で小さいと判断する。
# abc とabaの場合、abaの方が小さい

substrings = set([])
for i in range(5):
    for j in range(len(s) - i):
        # print(i, j)
        substrings.add(s[j:j + i + 1])
# print(substrings)
print(sorted(substrings)[K - 1])


Measured memory_bytes: 10572
#include <stdio.h>
#include <stdlib.h>

int code[256] = { 0 };

typedef struct _tree {
	int flag[4];
	struct _tree * (list[4]);
} TREE, *PTREE;

PTREE newTree(void) {
	PTREE tree = malloc(sizeof(TREE));
	tree->flag[0] = tree->flag[1] = tree->flag[2] = tree->flag[3] = 0;
	tree->list[0] = tree->list[1] = tree->list[2] = tree->list[3] = NULL;
	return tree;
}

void insert(PTREE root, char *str) {
	int i = code[(int)*str];
	if (*str == '\0') {
		root->flag[i] = 1;
		return;
	}
	if (root->list[i] == NULL) {
		root->list[i] = newTree();
	}
	insert(root->list[i], str + 1);
}

int find(PTREE root, char *str) {
	int i = code[(int)*str];
	if (*str == '\0') {
		return root->flag[i];
	}
	if (root->list[i] == NULL) {
		return 0;
	}
	return find(root->list[i], str + 1);
}

int main(void) {
	int i, n;
	char cmd[100], str[100];
	PTREE root = newTree();
	code['A'] = 0;
	code['C'] = 1;
	code['G'] = 2;
	code['T'] = 3;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; ++i) {
		scanf("%s %s", cmd, str);
		if (cmd[0] == 'i') {
			insert(root, str);
		} else if (find(root, str)) {
			printf("yes\n");
		} else {
			printf("no\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 22324
def main():
    a, b, c, k = (int(i) for i in input().split())
    ans = min(a, k)
    k -= a
    if k <= 0:
        print(ans)
        return
    k -= b
    if k <= 0:
        print(ans)
        return
    print(ans - k)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61856
#include<iostream>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

int main()
{
	int N, M;
	int ans[51] = {};
	cin >> N >> M;
	REP(i, 0, M) {
		int a, b;
		cin >> a >> b;
		ans[--a]++;
		ans[--b]++;
	}
	REP(i, 0, N) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(){

int n,i,j,l,k,t,p[101],m[101][101];
scanf("%d", &n);

for(i=0;i<n;++i){
scanf("%d %d",&p[i],&p[i+1]);
}
for(i=1;i<=n;++i){
m[i][i]=0;
}

for(l=2;l<=n;++l){
for(i=1;i<=n-l+1;++i){
j=i+l-1;
m[i][j]=m[i][i]+m[i+1][j]+p[i-1]*p[i]*p[j] ;
for(k=i+1;k<=j-1;++k){
t=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
if(m[i][j]>t)
m[i][j]=t;
}
}
}
printf("%d\n", m[1][n]);
return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    string s;
    cin>>s;
    if(s.substr(5,2)<="04" && s.substr(8,2) <= "30")
        cout << "Heisei" << endl;
    else
        cout << "TBD" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using   namespace      std;
typedef long long      LL;
typedef vector<int>    VI;
typedef pair<int,int>  PII;

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	int n;
	cin >> n;

	int ar[n+5] ;
	for(int i = 1 ; i <= n; i++)
		cin >> ar[i] ;
	
	int dp[n + 5] ;
	memset(dp, 0, sizeof dp);
	
	dp[2] = abs(ar[2] - ar[1]) ;
	
	for(int i = 3 ; i <= n ; i++){
		dp[i] = min(dp[i-1] + abs(ar[i] - ar[i-1]) , dp[i-2] + abs(ar[i] - ar[i-2])) ;
	}

	cout << dp[n] << endl ;

	return 0;
}

Measured memory_bytes: 1024
<?php

$inp = trim( fgets( STDIN ) );

$boin = ['a', 'e', 'i', 'o', 'u'];

for ( $i = 0; $i < 5; $i++ ) {
  if ( $boin[$i] === $inp ) {
    echo 'vowel';
    return;
  }
}

echo 'consonant';
?>

Measured memory_bytes: 4728
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
  
  int N; cin >> N;
  int *arr = new int[N];
  
  for(int i=0; i<N; i++) cin >> arr[i];
  
  int cnt = 0;
  for(int i=0; i<N; i++) {
    int min = i;
    for(int j=i; j<N; j++) {
      if(arr[j] < arr[min]) {
        min = j;
      }
    }
    if(i != min) {
      cnt ++;
      swap(arr[i], arr[min]);
    }
  }
  
  for(int i=0; i<N; i++) {
    if(i) cout << " ";
    cout << arr[i];
  }
  cout << endl << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 1188
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

string s[100], dp[100][100];
signed main(void)
{
	while(true) {
		int w, h;
		cin >> w >> h;
		if(!w && !h) break;
		REP(i, h) cin >> s[i];

		REP(i, h) REP(j, w) {
			if(i == 0 && j == 0) {
				if('1' <= s[i][j] && s[i][j] <= '9') dp[i][j] = s[i][j];
				else dp[i][j] = "0";
			} else if(i == 0) {
				if('0' <= s[i][j] && s[i][j] <= '9') {
					dp[i][j] = dp[i][j-1] + s[i][j];
				} else {
					dp[i][j] = "0";
				}
			} else if(j == 0) {
				if('0' <= s[i][j] && s[i][j] <= '9') {
					dp[i][j] = dp[i-1][j] + s[i][j];
				} else {
					dp[i][j] = "0";
				}
			} else {
				if('0' <= s[i][j] && s[i][j] <= '9') {
					bool flag = false;
					if(dp[i-1][j].size() > dp[i][j-1].size()) flag = true;
					if(dp[i-1][j].size() == dp[i][j-1].size()) {
						REP(k, dp[i-1][j].size()) {
							if(dp[i-1][j][k] > dp[i][j-1][k]) {flag = true; break;}
							else if(dp[i-1][j][k] < dp[i][j-1][k]) {flag = false; break;}
						}
					}
					if(flag) {
						dp[i][j] = dp[i-1][j] + s[i][j];
					} else {
						dp[i][j] = dp[i][j-1] + s[i][j];
					}
				} else {
					dp[i][j] = "0";
				}
			}
			//dp[i][j]???leading-zero????¶????
			int idx = 0;
			REP(k, dp[i][j].size()) {
				if(dp[i][j][k] != '0') {idx = k; break;}
			}
			if(idx == 0 && dp[i][j][0] == '0') dp[i][j] = "0";
			string tmp = "";
			FOR(k, idx, dp[i][j].size()) {
				tmp += dp[i][j][k];
			}
			dp[i][j] = tmp;
		}

		/*REP(i, h) {
			REP(j, w) {
				cout << dp[i][j] << " ";
			}
			cout << endl;
		}*/

		string ret = "0";
		REP(i, h) REP(j, w) {
			bool flag = false;
			if(dp[i][j].size() > ret.size()) flag = true;
			if(dp[i][j].size() == ret.size()) {
				REP(k, dp[i][j].size()) {
					if(dp[i][j][k] > ret[k]) {flag = true; break;}
					else if(dp[i][j][k] < ret[k]) {flag = false; break;}
				}
			}
			if(flag) ret = dp[i][j];
		}
		cout << ret << endl;
	}

	return 0;
}

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

int main()
{
  int n,k,m;
  while(cin >> n >> k >> m, (n || k || m))
    {
      vector<int> stone;
      for(int i=1;i<=n;i++)
	stone.push_back(i);
 
      m--;
      for(;stone.size() > 1;)
	stone.erase(stone.begin()+m),m = (m+k-1)%stone.size();
      cout << stone[0] << endl;
    }    
  return 0;
}

Measured memory_bytes: 3096
#include<stdio.h>
int main()
{
    int a[10],b,c,N;
    char s[101];
    int i,j,k,big,num,cost=0;
    
    // 整数の入力
    scanf("%d", &N);
    for(i=0;i<N;i++){
        scanf("%d", &a[i]);
    }

    big = a[0];
    num = 0;
    for(i=1;i<N;i++){
        if(a[i] > big){
            big = a[i];
            num = i;
        }
    }

    a[num] = big/2;

    for(i=0;i<N;i++){
        cost += a[i];
    }

    // 出力
    printf("%d\n",cost);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(ll i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<< endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

ll gcd(ll a, ll b) {
  while(a^=b^=a^=b%=a);
  return b;
}

void solve() {
  VAR(ll, N);
  VEC(ll, A, N);
  while (A.size() > 1) {
    ll a = A.back(); A.pop_back();
    ll b = A.back(); A.pop_back();
    A.push_back(gcd(a, b));
  }
  print(A.back());
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<numeric>
#include<climits>
#include<queue>
 
using namespace std;
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<long long> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i] -= i;
	}
	nth_element(a.begin(), a.begin() + n / 2, a.end());
	long long ans = 0;
	for (int i = 0; i < n / 2; i++) {
		ans += a[n - 1 - i];
                ans -= a[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<math.h>
int main()
{
	int r,c;
	long long d;
	while(~scanf("%d %d", &r, &c))
	{
		d = r==1||c==1? 1: (((long long)c*r)+1)/2;
		printf("%lld\n", d);
	}
	return 0;
}

Measured memory_bytes: 128
import sys
input=sys.stdin.readline
from math import ceil

s=input().rstrip()
s=s.replace("LR","L,R")
s=s.split(",")
ans=[]
for block in s:
    R=block.count("R")
    L=block.count("L")
    left=ceil(R/2)+(L//2)
    right=(R//2)+ceil(L/2)
    for i in range(R-1):
        ans.append(0)
    ans.append(left)
    ans.append(right)
    for i in range(L-1):
        ans.append(0)
print(*ans)

Measured memory_bytes: 85636
from collections import defaultdict

def scc(V, E):
    g = defaultdict(list)
    rg = defaultdict(list)
    for u, v in E:
        g[u].append(v)
        rg[v].append(u)


    o = []
    done = set()
    for u in V:
        if u in done:
            continue

        s = [(u, True)]
        while s:
            u, f = s.pop()
            if f:
                if u in done:
                    continue
                done.add(u)
                s.append((u, False))
                for v in g[u]:
                    if v in done:
                        continue
                    s.append((v, True))
            else:
                o.append(u)

    done = set()
    ans = []
    while o:
        u = o.pop()
        if u in done:
            continue

        s = [u]
        vv = [u]
        done.add(u)
        while s:
            u = s.pop()
            for v in rg[u]:
                if v in done:
                    continue
                vv.append(v)
                s.append(v)
                done.add(v)
        ans.append(vv)


    return ans


def atcoder_practice2_g():
    # https://atcoder.jp/contests/practice2/submissions/16819240
    import sys
    input = sys.stdin.buffer.readline
    N, M = map(int, input().split())

    E = []
    for _ in range(M):
        a, b = map(int, input().split())
        E.append((a, b))
    V = list(range(N))
    vv = scc(V, E)
    print(len(vv))
    for r in vv:
        print(len(r), *r)


if __name__ == "__main__":
    atcoder_practice2_g()


Measured memory_bytes: 332060
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define P 998244353
#define M 200010

using namespace std;

typedef long long ll;

int n, A[M];

ll gcd(ll x, ll y) {return !y ? x : gcd(y, x % y);}

int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%d", &A[i]);
    sort(A + 1, A + n + 1);
    ll ans = 1;
    for(int i = 1; i <= n; i++) ans = ans * gcd(A[i], i - 1) % P;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
//#define double long double
#define endre getchar();getchar();return 0
#define moder (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1)*x;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/

int n, a[214514];
int cnt[214514];
int ans[214514];
vector<int>vec[214514];
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		if (!i)vec[a[0]].push_back(i);
		if (i&&a[i] != a[i - 1])vec[a[i]].push_back(i);
	}
	ans[0] = 1;
	rep(i, n) {
		if (i)ans[i] += ans[i - 1];
		ans[i] %= moder;
		if (i&&a[i] == a[i - 1])continue;
		if (i != vec[a[i]].back()) {
			ans[vec[a[i]][cnt[a[i]] + 1]] += ans[i];
			ans[vec[a[i]][cnt[a[i]] + 1]] %= moder;
			cnt[a[i]]++;
		}
	}
	cout << ans[n - 1] % moder << endl;
	endre;
}

Measured memory_bytes: 16256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 500005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 1000000007;
int N;
int fac[MAXN],invfac[MAXN],p[MAXN],s[MAXN],k;
int tr[MAXN],ans[MAXN];
bool vis[MAXN];
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
int fpow(int x,int c) {
    int res = 1,t = x;
    while(c) {
	if(c & 1) res = mul(res,t);
	t = mul(t,t);
	c >>= 1;
    }
    return res;
}
int C(int n,int m) {
    if(n < m) return 0;
    return mul(fac[n],mul(invfac[m],invfac[n - m]));
}
int lowbit(int x) {return x & (-x);}
void insert(int x,int c) {
    while(x <= N) {
	tr[x] = inc(tr[x],c);
	x += lowbit(x);
    }
}
int query(int x) {
    int r = 0;
    while(x > 0) {
	r = inc(r,tr[x]);
	x -= lowbit(x);
    }
    return r;
}
void update(int &x,int y) {
    x = inc(x,y);
}
void Solve() {
    read(N);
    fac[0] = 1;
    for(int i = 1 ; i <= N ; ++i) {
	fac[i] = mul(fac[i - 1],i); 
    }
    invfac[N] = fpow(fac[N],MOD - 2);
    for(int i = N - 1 ; i >= 0 ; --i) {
	invfac[i] = mul(invfac[i + 1],i + 1);
    }
    for(int i = 1 ; i <= N ; ++i) {
	read(p[i]);
	if(p[i]) vis[p[i]] = 1;
	else ++k;
    }
    int sum = 0;
    for(int i = N ; i >= 1 ; --i) {
	s[i] += s[i + 1];
	if(!vis[i]) {
	    s[i]++;
	    update(sum,i - 1);
	}
    }

    int pre = 0;
    int rem = 0;
    for(int i = 1 ; i <= N ; ++i) {
	if(!p[i]) {
	    update(ans[i],MOD - pre);
	    if(k >= 2) update(ans[i],MOD - mul(rem,mul(C(k,2),fac[k - 2])));
	    update(ans[i],mul(sum,fac[k - 1]));
	    ++rem;
	}
	else {
	    update(ans[i],mul(p[i] - 1,fac[k]));
	    update(ans[i],MOD - mul(query(p[i] - 1),fac[k]));
	    if(k) update(ans[i],MOD - mul(rem,mul(s[1] - s[p[i]],fac[k - 1])));
	    if(k) update(pre,mul(s[p[i] + 1],fac[k - 1]));
	    insert(p[i],1);
	}
    }
    int res = fac[k];
    for(int i = 1 ; i <= N ; ++i) {
	update(res,mul(fac[N - i],ans[i]));
    }
    out(res);enter;
}

int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 12416
def makePrimeChecker(n):
    isPrime = [True] * (n + 1)
    isPrime[0] = False
    isPrime[1] = False
    for i in range(2, int(n ** 0.5) + 1):
        if isPrime[i]:
            for j in range(i * i, n + 1, i):
                isPrime[j] = False
    return isPrime

def main():
    n = int(input())
    prime_ls = makePrimeChecker(55555)
    ans = []
    i = 2
    while 1:
        if len(ans)==n:
            break
            
        if prime_ls[i] and i%5==1:
            ans.append(i)
        else:
            pass
        i += 1
    for ans_ in ans:
        print(ans_,end=" ")
    print("\n")

if __name__ == "__main__":
    main()

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

using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, k;
    cin >> n >> k;
    if (k == 1){
    cout << "0";
    return  0;
    }

    cout << n - k;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

void call(int n){
    int i = 0; 
    while(++i <= n){
        int x = i;
        if(x % 3 == 0){
            cout << " " << i;
            continue;
        }
        while(x){
            if(x % 10 == 3){
                cout << " " << i;
                break;
            }
            x /= 10;
        }
    }
}

int main(){
    int n;
    cin >> n;
    call(n);
    cout << endl;
    return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define ull unsigned long long
#define db double
#define pb push_back
#define ppb pop_back
#define all(x) (x).begin(), (x).end()

template <typename T>
using pr = array <T, 2>;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 123;
int n, a[N], cnt[16], b[N], dp[1 << 15], f[1 << 15];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int x, y, w;
		cin >> x >> y >> w;
		a[x] ^= w, a[y] ^= w;
	}
	int m = 0;
	for (int i = 0; i < n; i++) {
		cnt[a[i]]++;
	}
	int k = cnt[0];
	for (int i = 1; i < 16; i++) {
		k += cnt[i] / 2;
		if (cnt[i] & 1) {
			b[m++] = i;
		}
	}
	for (int i = 1; i < (1 << m); i++) {
		for (int j = 0; j < m; j++) {
			if (i >> j & 1) {
				f[i] ^= b[j];
			}
		}
		if (f[i] == 0) {
			dp[i] = 1;
		}
		for (int j = i; j > 0; j = (j - 1) & i) {
			dp[i] = max(dp[i], dp[j] + dp[i ^ j]);
		}
	}
	cout << n - dp[(1 << m) - 1] - k;
}


Measured memory_bytes: 896
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i32 = int32_t;
using i64 = int64_t;
constexpr char newl = '\n';

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
//#define F first
//#define S second
#define debug(x) cout << #x << ": " << x << '\n';
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1

template<class T>
class ConvexHullTrick {
  struct Line {
    T a, b;
  };
public:
  ConvexHullTrick(){}

  // 直線の傾きが単調減少だと分かっているときのみ、後端に追加すればよい
  void AddBack(T a, T b) {
    Line l{ a, b };

    while (lines.size() >= 2 && check(*(lines.end() - 2), lines.back(), l)) {
      lines.pop_back();
    }
    lines.emplace_back(l);
  }

  // 指定したxにおける最小のyを取得
  T Get(T x) {
    if (lines.size() == 0) return 0;

    int l = 0, r = lines.size();
    while (r - l > 1) {
      int m = (r + l) / 2;
      if (calc(lines[m-1], x) < calc(lines[m], x)) {
        r = m;
      }
      else {
        l = m;
      }
    }
    return calc(lines[l], x);
  }

protected:

  // 直線Ax+bにxを当てはめる
  constexpr T calc(const Line& line, T x) {
    return line.a * x + line.b;
  }

  // 直線3つを引数に、真ん中の直線が不要であるか調べる
  bool check(const Line& a, const Line& b, const Line& c) {
    return (c.b - b.b) * (a.a - b.a) <= (b.b - a.b) * (b.a - c.a);
  }

  vector<Line> lines;
};

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  i64 C;
  cin >> N >> C;

  vector<i64> hs(N);
  F0R(i, N) {
    cin >> hs[i];
  }

  // dp[i] = min((h[j]-h[i])^2 + C + dp[j] | j = 0~i-1)
  // (h[j]-h[i])^2+C+dp[j] = dp[j]+h[j]^2 + h[i]^2+C - 2*h[i]*h[j];
  // dp[i] = min{-2h[j] * (h[i]) + dp[j]+h[j]^2) | 0<=j<i} + h[i]^2 + C;

  ConvexHullTrick<i64> cht;

  vector<i64> dp(N, INT64_MAX);
  dp[0] = 0;

  F0R(i, N) {
    if (i > 0) {
      dp[i] = cht.Get(hs[i]) + hs[i] * hs[i] + C;
    }
    cht.AddBack(-2 * hs[i], dp[i] + hs[i] * hs[i]);
#if 0
    FOR(j, i + 1, N) {
      chmin(dp[j], dp[i] + ((i64)hs[j] - hs[i]) * (hs[j] - hs[i]) + C);
    }
#endif
  }
  cout << dp.back();
}
#endif


Measured memory_bytes: 9328
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

CB = []
for _ in range(M):
  b,c = map(int,input().split())
  CB.append([c,b])
CB.sort(reverse=True)

num = 0
ans = 0 
for c,b in CB:
  for bi in range(b):
    if num >= N: break
    if num > N or c<=A[num]:
      break
    else:
      num += 1
      ans += c
print(ans+sum(A[num:]) if num != N else ans)

Measured memory_bytes: 76696
def main():
    N = int(input())
    # r == N % m == N // m の時、
    # N = r * m + r = r * (m + 1) と書ける(0 < r < m)。
    # Nを2つの正の整数に分解し、上記を満たすmを求めて総和を求める。
    ans = 0
    r = 0
    while (r + 1) ** 2 <= N:
        r += 1
        if N % r > 0:
            continue
        m = N // r - 1
        if r < m:
            ans += m
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9100
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <array>
#include <stack>
#include <queue>
#include <chrono>
#include <numeric>
#include <memory.h>
#include <map>
#include <math.h>
#include <utility>
#include <set>

#pragma warning(disable:4996)
using namespace std;
#define REP(i,n) for(int i = 0 ; i < n ; ++i)
typedef long long Int;
const double PI = 3.141592653589793238;
const Int INF = 999999999999;
typedef pair<int, int> P;


int main()
{
	int n;
	double  xa, ya, ra, xb, yb, rb;

	cin >> n;
	REP(i, n){
		cin >> xa >> ya >> ra >> xb >> yb >> rb;

		double dx = (xa - xb)*(xa - xb) + (ya - yb)*(ya - yb);

		dx = sqrt(dx);

		if (dx > (ra + rb)){
			cout << 0 << endl;
			continue;
		}

		if (dx < (rb-ra)){
			cout << -2 << endl;
			continue;
		}

		if (dx < (ra - rb)){
			cout << 2 << endl;
			continue;
		}

		cout << 1 << endl;
	}
	return 0;

}

Measured memory_bytes: 1236