akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <vector>
#include <bitset>
#include <queue>
using namespace std;

int main(){
    int N;
    cin >> N;
    int a[N];
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    sort(&(a[0]), &(a[N]));


    // check
    int is_odd = N % 2;
    int start_num = 1 + is_odd;
    if(is_odd == 1){
        if(a[0] != 0){
            cout << 0 << endl;
            return 0;
        }
    }
    for(int i = is_odd; i < N; i++){
        if(is_odd != 1){

            if(a[i] != (1 + i/2*2)){
                cout << 0 << endl;
                return 0;
            }
        }else{
            if(a[i] != (i+1)/2*2){
                cout << 0 << endl;
                return 0;
            }
        }
    }
    long long ans = 1;
    for(int i = 0; i < N/2; i++){
        ans = ans*2 % 1000000007;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
x = ["" for _ in range(N)]
ans = 0
for i in range(N):
    if K <= i:
        if T[i] == "r":
            if x[i-K] == "p":
                if i + K < N:
                    if T[i+K] == "s":
                        x[i] = "s"
                    else:
                        x[i] = "r"
                else:
                    x[i] = "r"
            else:
                ans += P
                x[i] = "p"
        elif T[i] == "s":
            if x[i-K] == "r":
                if i + K < N:
                    if T[i + K] == "p":
                        x[i] = "p"
                    else:
                        x[i] = "s"
                else:
                    x[i] = "s"
            else:
                ans += R
                x[i] = "r"
        elif T[i] == "p":
            if x[i-K] == "s":
                if i + K < N:
                    if T[i + K] == "r":
                        x[i] = "r"
                    else:
                        x[i] = "p"
                else:
                    x[i] = "p"
            else:
                ans += S
                x[i] = "s"
    else:
        if T[i] == "r":
            ans += P
            x[i] = "p"
        elif T[i] == "s":
            ans += R
            x[i] = "r"
        elif T[i] == "p":
            ans += S
            x[i] = "s"
print(ans)

Measured memory_bytes: 4340
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }


int main() {
    int N, M;
    cin >> N >> M;
    vint A(N);
    rep(i, N) {
        cin >> A[i];
    }
    vector<pair<int, int>> CB(M);
    rep(i, M) {
        int B, C;
        cin >> B >> C;
        CB[i] = make_pair(C, B);
    }
    sort(A.begin(), A.end());
    sort(CB.begin(), CB.end(), greater<pair<int, int>>());
    int change = 0;
    ll ans = 0;
    rep(i, M) {
        auto lb = lower_bound(A.begin(), A.end(), CB[i].first) - A.begin();
        if (change + CB[i].second - 1 < lb) {
            ans += ll(CB[i].second) * ll(CB[i].first);
            change += CB[i].second;
            if (i == M - 1) {
                REP(i, change, N) {
                    ans += ll(A[i]);
                }
            }
        }
        else {
            ans += CB[i].first * (lb - change);
            REP(j, lb, N) {
                ans += ll(A[j]);
            }
            break;
        }
    }

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

Measured memory_bytes: 1408
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define eb emplace_back
#define el '\n'
typedef  long long  ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;

ll inf=(ll)2e18;
const int mod=1000000007;
//const int mod=998244353;
int n,m;






int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    int q,t,k,u,v;
    ll x,a,b,c,d,y,l,p;
    cin >> n >> m >> k;
    vvi vv(n,vi(m));
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            char c;
            cin >> c;
            if(c=='#')
                vv[i][j]=1;
            else
                vv[i][j]=0;
        }
    }
    a=0;
    for(int i=0; i<1<<n; i++){
        for(int j=0; j<1<<m; j++){
            u=0;
            for(int ii=0; ii<n; ii++){
                for(int jj=0; jj<m; jj++){
                    if((i&1<<ii)||(j&1<<jj))continue;
                    u+=vv[ii][jj];
                }
            }
            a+=(u==k);
        }
    }
    cout << a << el;
    return 0;
}


Measured memory_bytes: 3640
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int A[3];
	rep(i, 0, 3)
	{
		cin >> A[i];
	}

	sort(A, A + 3);

	cout << (A[0] * A[1]) / 2 << endl;

	return 0;
}

Measured memory_bytes: 256
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
ans = 0
for i in range(n):
	summ = 0
	a = list(map(int,input().split()))
	for j in range(len(a)):
		summ += a[j]*b[j]
	if summ + c > 0:
		ans += 1
print(ans)

Measured memory_bytes: 3060
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

using namespace std;

void func(int &a,int &b, long int &ans) {
	int big = max(a, b);
	int small = min(a, b);
	ans += small;
	a -= small;
	b -= small;
}

int main() {
	int N;
	long int ans = 0;

	cin >> N;

	vector <int> A(N + 1);
	vector <int> B(N);

	for (int i = 0; i < N + 1; i++) {
		cin >> A.at(i);
	}

	for (int i = 0; i < N; i++) {
		cin >> B.at(i);
	}

	for (int i = 0; i < N; i++) {
		func(A.at(i), B.at(i), ans);
		func(A.at(i+1), B.at(i), ans);
	}

	cout << ans << endl;

	return 0;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  if (a <= 0 && b >= 0) {
    cout << "Zero" << endl;
  }
  else if (a > 0 && b > 0) {
    cout << "Positive" << endl;
  }
  else if (a < 0 && b < 0 && (a + b) % 2 == -1) {
    cout << "Positive" << endl;
  }
  else if (a < 0 && b < 0 && (a + b) % 2 == 0) {
    cout << "Negative" << endl;
  }
}

Measured memory_bytes: 256
/*----------------by syr----------------*/
/*
  -----  -----  -----
  |   |  |---|    _/
  |   |  | \_    /
  -----  |   \  -----

  |---\  \   /  |\  /|
  |   |   \_/   | \/ |
  |   |   / \   |    |
  |---/  /   \  |    |
*/
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cstring>
#include<cstdlib>
#include<deque>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<limits>
#include<list>
#include<map>
#include<math.h>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<sstream>
#include<string>
#include<time.h>
#include<utility>
#include<vector>

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i,x,y) for(int i=(x);i<(y);++i)
#define REP(i,x,y) for(int i=(x);i<=(y);++i)
#define x0 x234567891
#define y0 y234567891
#define x2 x123456789
#define y2 y123456789

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ldb;
typedef pair<int,int> pii;

const int INF=1e9+7;
const int maxn=2005;

int n,cnt;
int a[maxn];
bool vis[maxn];
vector<int> b;
vector<int> g[maxn],ng[maxn];
priority_queue<pii> pq;

void dfs(int u){
	vis[u]=1;
	FOR(i,0,g[u].size()){
		int v=g[u][i];
		if(vis[v]) continue;
		ng[u].PB(v);
		dfs(v);
	}
	return;
}

int main(){
	scanf("%d",&n);
	FOR(i,0,n) scanf("%d",a+i);
	sort(a,a+n);
	FOR(i,0,n){
		FOR(j,0,n){
			if(__gcd(a[i],a[j])!=1) g[i].PB(j);
		}
	}
	FOR(i,0,n) if(!vis[i]) dfs(i),pq.PH(MP(a[i],i));
/*	FOR(i,0,n){
		FOR(j,0,ng[i].size()) printf("%d ",ng[i][j]);
		puts("");
	}
*/	while(!pq.empty()){
		int u=pq.top().snd;
		b.PB(pq.top().fst);
		pq.pop();
		FOR(i,0,ng[u].size()) pq.PH(MP(a[ng[u][i]],ng[u][i]));
	}
	FOR(i,0,n) printf("%d ",b[i]);
	puts("");
	return 0;
}

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

using namespace std;

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

	int n;
	cin >> n;
	vector<int> a(n+1);
	for (auto& i : a) {
		cin >> i;
	}
	vector<int> b(n);
	for (auto& i : b) {
		cin >> i;
	}

	long long num = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (b[i] >= a[i + 1]) {
			num += a[i + 1];
			b[i] -= a[i + 1];
			a[i + 1] = 0;
		}
		else {
			num += b[i];
			a[i + 1] -= b[i];
			b[i] = 0;
		}
		if (b[i] >= a[i]) {
			num += a[i];
			b[i] -= a[i];
			a[i] = 0;
		}
		else {
			num += b[i];
			a[i] -= b[i];
			b[i] = 0;
		}
	}
	cout << num << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>

#define X first
#define Y second
#define vsort(v) sort((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())


//INT_MAX
//INT_MIN
//LLONG_MAX
//LLONG_MIN
//DBL_MIN
//DBL_MAX
//LDBL_MIN
//LDBL_MAX

// A-Z: 65~90
// a-z: 97~122
// |a-z| = 26

using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    int n, t;
    cin >> n >> t;
    int ans = 10000;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        if (y <= t && ans > x) {
            ans = x;
        }
    }
    if (ans == 10000) {
        cout << "TLE" << endl;
    }else{
        cout << ans << endl;
    }
    
    
}


Measured memory_bytes: 256
// CPP program to find the minimum number of
// characters to be replaced in string S2, such
// that S1 is a substring of S2

#include <bits/stdc++.h>
using namespace std;

// Function to find the minimum number of
// characters to be replaced in string S2, such
// that S1 is a substring of S2
int minimumChar(string S1, string S2)
{
    // Get the sizes of both strings
    int n = S1.size(), m = S2.size();

    int ans = INT_MAX;

    // Traverse the string S2
    for (int i = 0; i < m - n + 1; i++) {
        int minRemovedChar = 0;

        // From every index in S2, check the number of
        // mis-matching characters in substring of
        // length of S1
        for (int j = 0; j < n; j++) {
            if (S1[j] != S2[i + j]) {
                minRemovedChar++;
            }
        }

        // Take minimum of prev and current mis-match
        ans = min(minRemovedChar, ans);
    }

    // return answer
    return ans;
}

// Driver Code
int main()
{
    string S1 ,S2;
    cin>>S1>>S2;

    cout << minimumChar(S2, S1);

    return 0;
}


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

using namespace std;

#define DIM 300009
#define INF ((long long)1e18+9ll)
#define pairll pair<long long,long long>
#define fi first
#define se second
#define ld long double
#define amen exit(0)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define endl '\n'
#define MODULO 1000000007

long long i,j,k,l,n,m;

long long vis[DIM];

string s;

void rec(long long pos,long long t){
    vis[t]++;
    s+='a'+t;
    if(pos==n){
        cout<<s<<endl;
        vis[t]--;
        s.pop_back();
        return;
    }

    for(int i=0;i<26;i++){
        if(vis[i]==0 && (i>0 && vis[i-1]==0))break;
        rec(pos+1,i);
    }

    s.pop_back();
    vis[t]--;
}

int main()
{   
    fast;

    cin>>n;
    rec(1,0);

    amen;
}


Measured memory_bytes: 1536
#include "bits/stdc++.h"

using namespace std;

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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


bool isLeap(int n){
    if( ( n%4==0 && n%100!=0 ) || n%400==0 ){
        return true;
    }
    return false;
}

int main(){
    int a,b;
    bool f = false;
    while( cin>>a>>b ){
        if(a==0&&b==0)break;
        if(f)cout<<endl;
        else f=true;
        
        int c=0;
        for(int i=a;i<=b;i++){
            if( isLeap(i) ){
                c++;
                cout<<i<<endl;
            }
        }
        if(c==0)cout<<"NA"<<endl;
    }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h> 
using namespace std; 
const int dx[]={1,0,-1,0,1,-1,-1,1}; 
const int dy[]={0,1,0,-1,1,1,-1,-1}; 
const int INF = 1e9; 
const long long LINF = 1e18; 
const double EPS = 1e-8; 
#define pb emplace_back 
#define mk make_pair 
#define fr first 
#define sc second 
#define ll long long 
#define reps(i,j,k) for(int i = (j); i < (k); ++i) 
#define rep(i,j) reps(i,0,j) 
#define all(a) (a).begin(),(a).end() 
#define MOD 1000000007 
typedef pair<int,int> Pii; 
typedef vector<int> vi; 
typedef pair<string, int> Psi; 
typedef pair<ll, ll> Pll;

int main(){
	string str;
	cin >> str;
	int cnt = 0;	string hoge = "CODEFESTIVAL2016";
	rep(i,str.size()){
		if(str[i] != hoge[i]){
			++cnt;
		}
	}
	cout << cnt << endl;
	return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
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; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int ketawa(int a){
  int k=0;
  rep(i,keta(a)){
  k+=kurai(a,i+1);
  }
  return k;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
 if(!b)return 1; if(b&1)return modpow(a,b-1,m)*a%m;
 int memo = modpow(a,b>>1,m);
 return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  int a;
  cin>>a;
  if(a!=120)
  out(360/gcd((180-a),180));
  else
    out(3);
}


Measured memory_bytes: 3708
n = gets.to_i
s = gets.chomp.chars
left = {}
right = {}
s.each { |c| right[c] = right[c].to_i + 1 }
ans = 0
s.each do |c|
  left[c] = left[c].to_i + 1
  right[c] -= 1
  cnt = ('a'..'z').count { |t| left[t].to_i > 0 && right[t] > 0 }
  ans = cnt if ans < cnt
end
puts ans

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

int main() {
	int k, a, b;
	cin >> k >> a >> b;
	
	if (a >= k || b - a <= 2) {
		cout << k + 1 << endl;
		return 0;
	}
	
	long long res = a;
	k -= (a - 1);
	
	//cerr << k << " " << b - a << endl;
	
	int delta = b - a;
	res += 1ll * delta * (k / 2) + k % 2;
	
	cout << res << endl;
}


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

int main()
{
    ll n;cin>>n;
    ll sum=100,i;
    for(i=1;i<=5000;i++)
    {
        sum+=(sum/100);
        if(sum>=n)break;
    }
    cout<<i<<endl;






}


Measured memory_bytes: 3596
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
if(s=="Sunny"){
cout<<"Cloudy"<<endl;
}
else if(s=="Cloudy"){
cout<<"Rainy"<<endl;
}
else if(s=="Rainy"){
cout<<"Sunny"<<endl;
}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<double> VL;
typedef vector<string> VS;
typedef vector<PLL> VP;
typedef vector<ll> VLL;
const static int INF = 1000000000;
const static int MOD = 1000000007;
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    int N;
    cin >> N;
    VI P(N),Q(N);
    VI PS(N), QS(N);
    rep(i,N){
        cin >> P[i];
        PS[i]=P[i];
    } 
    rep(i,N){
        cin >> Q[i];
        QS[i]=Q[i];
    }
    sort(all(P));
    sort(all(Q));
    ll a=1; 
    ll b=1;
    bool judge=true;
    do {
        rep(i,N){
            if(P[i]!=PS[i]){
                judge=false;
            }
        }
        if(judge){
            break;
        }
        else{
            a++;
            judge=true;
        }
    }while(next_permutation(all(P)));
    do{
        rep(i,N){
            if(Q[i]!=QS[i]){
                judge=false;
            }
        }
        if(judge){
            break;
        }
        else{
            b++;
            judge=true;
        }
    }while(next_permutation(all(Q)));
    cout << abs(a-b) << endl; 
}


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

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

        int[] pqr = new int[3];
        
        for (int i = 0 ; i < 3 ; i++) {
            pqr[i] = scanner.nextInt();
        }

        Arrays.sort(pqr);

        System.out.println(pqr[0] + pqr[1]);
    }
}


Measured memory_bytes: 35664
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9+7;

unordered_map<int,int> ans;

//素因数分解
unordered_map<int,int> factor(ll x){
    unordered_map<int,int> prime;
    for (ll i = 2; i<=sqrt(x); i++) {
        if(x%i != 0) continue;
        if(x%i==0){
            while(x%i == 0){
                prime[i]++;
                x/=i;
            }
        }
        if(x==1)break;
    }
    if(x != 1) prime[x]++;
    return prime;
}

//繰り返し二乗法
ll ex(ll x,ll n){
    if(n==0)return 1;
    else if(n%2==1)return ex(x,n-1)*x%mod;
    else return ex(x*x%mod,n/2)%mod;
};

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    unordered_map<int,int> flcm;
    ll lcm = 1;
    ll fans = 0;

    for(int i = 0 ; i < n; i++){
        cin >> a[i];
        unordered_map<int,int> pf = factor(a[i]);
        for(auto p:pf) flcm[p.first] = max(flcm[p.first],p.second);
    }

    for(auto p:flcm){
        lcm *= ex(p.first,p.second);
        lcm %= mod;
    }

    for(int i = 0; i < n; i++){
        fans += lcm*ex(a[i],mod-2);
        fans %= mod;
    }

    cout << fans << endl;
    return 0;
}


Measured memory_bytes: 4012
#include <bits/stdc++.h>
using namespace std;
int DP[15];
int main(){
  for(int i = 1;i < 15;i++)DP[i] = -1;
  int D,x,y,p,ans = 0;
  string a;
  cin >> D >> x;
  vector<int> v,w;
  for(int i = 0;i < x;i++){
    cin >> a >> p;
    if(a == "D"){
      v.push_back(p);
      w.push_back(1);
    }
  }
  cin >> y;
  for(int i = 0;i < y;i++){
    cin >> a >> p;
    if(a == "DD"){
      v.push_back(p);
      w.push_back(2);
    }
  }
  for(int i = 0;i < v.size();i++){
    for(int j = 15;j >= 0;j--)if(DP[j]!=-1)DP[j+w[i]] = max(DP[j+w[i]],DP[j]+v[i]);
  }
  for(int i = 0;i <= D;i++)ans = max(ans,DP[i]);
  cout << ans << endl;
}



Measured memory_bytes: 3220
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=2050;
//ここまでテンプレ
int main(){
	string S;
	cin>>S;
	if(S[0]!='A'){
		cout<<"WA"<<endl;
		return 0;
	}
	int C=0,cap=0;
	for(int i=2;i<S.length()-1;i++)
		if(S[i]=='C')
			C++;
		else if('A'<=S[i] && S[i]<='Z'){
			cout<<"WA"<<endl;
			return 0;
		}
	if('A'<=S[S.length()-1] && S[S.length()-1]<='Z'){
		cout<<"WA"<<endl;
		return 0;
	}
	if('A'<=S[1] && S[1]<='Z'){
		cout<<"WA"<<endl;
		return 0;
	}
	if(C!=1){
		cout<<"WA"<<endl;
	}
	else
		cout<<"AC"<<endl;
	return 0;
}

Measured memory_bytes: 256
/*
 * atcoder/abc125/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

int N;
ll A[100001];
ll acc_l[100001];
ll acc_r[100001];

void solve() {
  cin >> N;
  loop(n,0,N) cin >> A[n];

  // 累積和
  acc_l[0] = 0;
  loop(n,0,N) acc_l[n+1] = gcd(acc_l[n], A[n]);
  acc_r[N] = 0;
  for (int n=N; n>=1; n--) acc_r[n-1] = gcd(acc_r[n], A[n-1]);

  int max_ = 0;
  for (int k=0; k<N; k++) {
    chmax(max_, gcd(acc_l[k], acc_r[k+1]));
  }
  cout << max_ << endl;
}

int main() {
  // cout.precision(15);
  // cout << fixed << double

  solve();

  return 0;
}


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

#include "bits/stdc++.h"
using namespace std;
#define int long long


class APayment {
public:
	void solve(std::istream& in, std::ostream& out) {
    int n;
    in >> n;
    out << (n % 1000 == 0 ? 0 : 1000 - n % 1000) << endl;
	}
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
	APayment solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int main() {

    uint N;
    cin >> N;
    if ((N%2) != 0) {
        cout << "No" << endl;
        return 0;
    }

    string S;
    cin >> S;

    uint M = N / 2;
    bool judge = true;
    for (uint i=0; i<M; i++) {
        if (S[i] != S[i+M]) {
            judge = false;
            break;
        }
    }
    if (judge)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}



Measured memory_bytes: 3592
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cstdio>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;

#define fs first
#define sc second
#define pb push_back
#define mp make_pair 
typedef pair<int, int> pii;
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;

const int N = 1e6 + 10;
const int mo = 1e9 + 7;

int qpow(int a, int b) {
	int ans = 1;
	for(; b >= 1; b >>= 1, a = (ll) a * a % mo)
		if(b & 1) ans = (ll) ans * a % mo;
	return ans;
}
char s[N];
int dp[N][2];
bool ok(int x) {
	return x >= 0 && x < 10;
}
int main() {
	scanf("%s", s + 1);
	int n = strlen(s + 1);
	dp[0][1] = 1; dp[0][0] = 0;
	for(int i = 1; i <= n; i ++) {
		dp[i][0] = dp[i][1] = 1e9;
		int x = s[i] - '0';
		for(int j = 0; j < 10; j ++) {
			if(ok(10 + j - x)) dp[i][0] = min(dp[i][0], dp[i - 1][1] + j + (10 + j - x));
			if(ok(j - x)) dp[i][0] = min(dp[i][0], dp[i - 1][0] + j + (j - x));
			
			if(ok(10 + (j - 1) - x)) dp[i][1] = min(dp[i][1], dp[i - 1][1] + j + (10 + (j - 1) - x));
			if(ok(j - 1 - x)) dp[i][1] = min(dp[i][1], dp[i - 1][0] + j + ((j - 1) - x));
		}
	}
	printf("%d\n", dp[n][0]);
	return 0;
} 

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll n,a[114514];
	cin>>n;
	ll ans=0,cnt=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(i){
			if(a[i-1]>=a[i])cnt++;
			else{
				ans=max(ans,cnt);
				cnt=0;
			}
		}
	}

	ans=max(ans,cnt);
	cout<<ans<<endl;
	return 0;
}


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

int main() {
  long long a, b, n;
  cin >> a >> b >> n;
  if (b > n) {
    cout << a * n / b << endl;
  } else {
    cout << a * (b - 1) / b << endl;
  }
  return 0;
}

Measured memory_bytes: 3620
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
    
    
    
int n,cost;
int A[1001],B[1001];
int L[501],R[502];
    

void M(int left,int mid,int right);
void MS(int left,int right);
void swap(int a,int b,int *C);


int n,cost, A[1001],B[1001],L[501],R[502];
    
int main(){
  scanf("%d",&n);
  int i,j;
  int cnt,sum,min,start,x;
  int C[1001]={};
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    B[i]=A[i];
  }
  MS(0,n);
  for(i=0;i<n;i++){
    if(A[i]==B[i]) C[i]=1;
  }
  cost=0;
  for(i=0;i<n;i++){
    if(C[i]!=1){
      C[i]=1;
      cnt=0;
      sum=0;
      min=B[i];
      x=i;
      while(1){
        for(j=0;j<n;j++){
          if(B[x]==A[j]){
            C[j]=1;
            cnt++;
            sum+=B[j];
            if(min > B[j]) min=B[j];
            x=j;
            break;
          }
        }
        if(x==i) break;
      }
      sum-=min;
      if( (cnt -1)*min > (cnt -1)*A[0]+2*(min +A[0])) cost+=sum+(cnt-1)*A[0]+2*(min +A[0]);
      else cost+=sum+(cnt-1)*min;
    }
  }
  printf("%d\n",cost);
  return 0;
}


void M(int left,int mid,int right){
  int i,j,n1=mid-left,n2=right-mid;
  for(i=0;i<n1;i++) L[i]=A[left+i];
  L[n1]=INT_MAX;
  for(i=0;i<n2;i++) R[i]=A[mid+i];
  R[n2]=INT_MAX;
  int l=0,r=0;
  for(i=left;i<right;i++){
    if(L[l]<=R[r]){
      A[i]=L[l];
      l++;
    }
    else{
      A[i]=R[r];
      r++;
    }
  }
}


void MS(int left,int right){
  int mid;
  if( left+1 >= right) return;
  mid=(left+right)/2;
  MS(left,mid);
  MS(mid,right);
  M(left,mid,right);
}

void swap(int a,int b,int *C){
  int swap;
  swap=C[a];
  C[a]=C[b];
  C[b]=swap;
}



Measured memory_bytes: 2096
#include<bits/stdc++.h>
using namespace std;
#define p pair<string,int>
int main()
{
 int t;
  cin>>t;
  map<string,int> m;
  int ma=-1;
  while(t--)
  {
    string s;
    cin>>s;
    if(m.find(s)!=m.end())
     { m[s]++;}
    else
      m[s]=1;
      ma = max(ma,m[s]);
  }
  set<string> v;
 for(auto i:m) if(i.second==ma) v.insert(i.first);
 for(auto i:v) cout<<i<<"\n";
  
  return 0;
}


Measured memory_bytes: 34560
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<iomanip>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{"; for(auto nth : list){ cout << nth << " ";}cout << "}" << endl;

using namespace std;

int main(){

	while(true){

		int map[21][21];
		int x=10,y=10;
		int count=0;

		for(int i=0;i<21;i++){
			for(int j=0;j<21;j++){
				map[i][j]=0;
			}
		}

		int number,a,b;
		int stone;

		cin >> number;

		stone = number;

		if(number == 0) break;


		//cout << "あ" << endl;

		for(int i=0;i<number;i++){
			cin >> a >> b;
			map[a][b] = 1;
		}

		cin >> number;

		string aim;
		int num;


		for(int i=0;i<number;i++){
			cin >> aim >> num;
			
/*			for(int j=0;j<21;j++){
				for(int k=0;k<21;k++){
					cout << map[j][k] << " ";
				}
				cout << endl;
			}
*/			
			
			if(aim == "N"){
				for(int j=0;j<num;j++){
					y++;
					if(map[x][y]==1){
						count++;			
						map[x][y]=0;
					}
				}
			}
			else if(aim == "E"){
				for(int j=0;j<num;j++){
					x++;
					if(map[x][y]==1){
						count++;			
						map[x][y]=0;
					}
				}
			}
			if(aim == "S"){
				for(int j=0;j<num;j++){
					y--;
					if(map[x][y]==1){
						count++;			
						map[x][y]=0;
					}
				}
			}
			if(aim == "W"){
				for(int j=0;j<num;j++){
					x--;
					if(map[x][y]==1){
						count++;			
						map[x][y]=0;
					}
				}
			}

		}
		if(count==stone){
			cout << "Yes" << endl;	
		}
		else{
			cout << "No" << endl;
		}




	}

}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
#define rep(var,n) for(int var=0;var<(n);++var)
const ll MOD = 1e9+7;
 
#define MAX_V (long long)(1e5*2+200)
 
ll MAX_VAL;
ll fac[MAX_V], mmi[MAX_V], temp[MAX_V];
 
inline void factorial(){
	fac[0] = fac[1] = 1;
	for(long long i = 2; i < MAX_VAL; fac[i]%=MOD,i++)
		fac[i] = fac[i-1]*(i%MOD);
}
 
inline long long power_mod(long long x, long long n){
  long long ans = 1;
  for(;n;n>>=1,x*=x,ans%=MOD,x%=MOD)
    if(n&1)ans*=x;
  return ans;
}
 
inline void modular_multiplicatibe_inverse(){
  mmi[MAX_VAL-1] = power_mod(fac[MAX_VAL-1],MOD-2);
  for(long long i = MAX_VAL-2; i >= 0; mmi[i]%=MOD,i--)
    mmi[i] = mmi[i+1]*(i+1);
}
 
inline long long combination(long long n, long long r){
  return fac[n]*(mmi[r]*mmi[n-r]%MOD)%MOD;
}
 
int main(){
  ll n,k; cin >> n >> k;
 
  MAX_VAL = n+3;
 
  factorial();
  modular_multiplicatibe_inverse();
 
  rep(i,k)
    cout << (combination(k-1,i)*combination(n-k+1,i+1))%MOD << endl;
  return 0;
}

Measured memory_bytes: 2304
// AOJ 2586 Wish upon a shooting star
// 2018.3.31 bal4u
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
#define EPS 1e-9
int dcmp(double x) { if (fabs(x) < EPS) return 0; return x <= 0 ? -1 : 1; }
#define EQ(a,b)     (fabs((a)-(b))<EPS)
 
typedef struct { double x, y, z, vx, vy, vz, r, vr; } T;
T t[202];
typedef struct { int id1, id2; double t; } E;
E e[30000]; int sz;
double tm[202]; char f[202];
 
int quadratic(double *x, double a, double b, double c)
{
    int t;
    double d;
 
    if (EQ(a, 0)) return 0; 
    d = b*b - 4*a*c, t = dcmp(d), a *= 2;
    if (t < 0) return 0;
	if (t == 0) { x[0] = -b/a; return 1; }
	d = sqrt(d), x[0] = (-b+d)/a, x[1] = (-b-d)/a;
	return 2;
}
 
int cmp(E *a, E *b) { return dcmp(a->t - b->t); }
 
int main()
{
    int n, i, j, k;
    double x[2], a, b, c;       // ax^2 + bx + c = 0
	double dx, dy, dz, dr, vx, vy, vz, vr;

    while (scanf("%d", &n) && n) {
        sz = 0;
        for (i = 0; i < n; i++) {
			scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &t[i].x, &t[i].y, &t[i].z,
				  &t[i].vx, &t[i].vy, &t[i].vz, &t[i].r, &t[i].vr);
            e[sz].id1 = e[sz].id2 = i, e[sz++].t = t[i].r/t[i].vr;
        }
 
        for (i = 0; i < n; i++) for (j = i+1; j < n; j++) {
			vx = t[i].vx-t[j].vx, vy = t[i].vy-t[j].vy;
			vz = t[i].vz-t[j].vz, vr = t[i].vr+t[j].vr;
            a = vx*vx + vy*vy + vz*vz - vr*vr;
			
			dx = t[i].x-t[j].x, dy = t[i].y-t[j].y;
			dz = t[i].z-t[j].z, dr = t[i].r+t[j].r;
            c = dx*dx + dy*dy + dz*dz - dr*dr;

			b = dx*vx + dy*vy + dz*vz + dr*vr, b *= 2;

            k = quadratic(x, a, b, c);
            while (k--) if (dcmp(x[k]) > 0) {
                e[sz].id1 = i, e[sz].id2 = j, e[sz++].t = x[k];
            }
        }
        qsort(e, sz, sizeof(E), cmp);
        memset(f, 0, sizeof(f));
        for (i = 0; i < sz; i++) {
            j = e[i].id1, k = e[i].id2;
            if (!f[j] && !f[k]) {
                f[j] = f[k] = 1;
                tm[j] = tm[k] = e[i].t;
            }
        }
        for (i = 0; i < n; i++) printf("%.10lf\n", tm[i]);
    }
    return 0;
}


Measured memory_bytes: 2624
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro split-ints-bind (vars string &body body)
  (let ((position (gensym))
        (s (gensym)))
    (labels ((expand (vars &optional init-pos)
               (if (null vars)
                   body
                   `((multiple-value-bind (,(car vars) ,position)
                         (parse-integer ,s :start ,(or init-pos position)
                                           :junk-allowed t)
                       ,@(when (null (cdr vars)) `((declare (ignore ,position))))
                       ,@(expand (cdr vars)))))))
      `(let ((,s ,string))
         (declare (string ,s))
         ,@(expand vars 0)))))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Hauptteil

(defun main ()
  (let* ((n (read))
         (m (read))
         (as (make-array n :element-type 'int32 :initial-element 1)))
    (setf (aref as 0) -1)
    (dotimes (i m)
      (split-ints-bind (x y) (read-line)
        (decf x)
        (decf y)
        (symbol-macrolet ((ax (aref as x))
                          (ay (aref as y)))
          (cond ((and (> ax 0) (>= ay 0))
                 (setf ax (- ax 1)
                       ay (+ ay 1)))
                ((and (> ax 0) (< ay 0))
                 (setf ax (- ax 1)
                       ay (- ay 1)))
                ((and (< ax 0) (>= ay 0))
                 (setf ax (+ ax 1)
                       ay (+ (- ay) -1)))
                (t (setf ax (+ ax 1)
                         ay (- ay 1)))))))
    (println (count-if #'minusp as))))

#-swank(main)


Measured memory_bytes: 47588
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V  = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class H> void rsz(V<T> &v, H h) { v.resize(h); }
template<class T, class H, class... R> void rsz(V<T> &v, H h, R... r) { v.resize(h); for (auto&& i : v) rsz(i, r...); }
using P = pair<int, int>;
struct QU {
  V<> par;
  QU(int n) { par.resize(n); iota(par.begin(), par.end(), 0); }
  int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }
  bool same(int x, int y) { return find(x) == find(y); }
  void unite(int x, int y) { par[find(y)] = find(x); }
};
struct QF {
  V<> par; V< set<int> > chi;
  QF(int n) { par.resize(n); chi.resize(n); for (int i = 0; i < n; i++) par[i] = i, chi[i].insert(i); }
  bool same(int x, int y) { return par[x] == par[y]; }
  void _merge(int x, int y) { for (int i : chi[y]) par[i] = x; chi[x].insert(chi[y].begin(), chi[y].end()); chi[y].clear(); }
  void unite(int x, int y) { x = par[x], y = par[y]; if (chi[x].size() < chi[y].size()) swap(x, y); _merge(x, y); }
};

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  V<> k(n); VV<> l(n);
  for (int i = 0; i < n; i++) {
    cin >> k[i];
    l[i].resize(k[i]); for (int j = 0; j < k[i]; j++) cin >> l[i][j];
  }
  V<P> a;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l[i].size(); j++) a.emplace_back(l[i][j], i);
  }
  sort(a.begin(), a.end());
  // QF qf(n);
  QU qu(n);
  for (int i = 0; i < a.size() - 1; i++) {
    // if (a[i].first == a[i + 1].first) qf.unite(a[i].second, a[i + 1].second);
    if (a[i].first == a[i + 1].first) qu.unite(a[i].second, a[i + 1].second);
  }
  // cout << (qf.chi[qf.par[0]].size() == n ? "YES" : "NO") << '\n';
  for (int i = 0; i < n; i++) {
    if (!qu.same(0, i)) return cout << "NO" << '\n', 0;
  }
  cout << "YES" << '\n';
}

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST(N)

# 同色が直前に出現した位置を取っておく
prev = [INF] * N
D = {}
for i, a in enumerate(A):
    if a in D:
        prev[i] = D[a]
    D[a] = i

# dp[i] := 添字iが右端となる区間までの通り数
dp = [0] * N
dp[0] = 1
for i in range(1, N):
    # 1つ前と変化しない遷移は必ずある
    dp[i] += dp[i-1]
    # 左隣りが違う色でかつ、自分より左に同色があるなら、挟んで変色させる遷移をする
    if A[i-1] != A[i] and prev[i] != INF:
        # 挟む左端となる場所から遷移させる
        dp[i] += dp[prev[i]]
    dp[i] %= MOD
print(dp[N-1])


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

using namespace std;

#define ll long long 
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ff first
#define ss second
#define endl "\n"
#define MOD 1000000007
#define MOD1 998244353
#define inf LLONG_MAX

ll GCD(ll x,ll y){if(y==0)return x;return GCD(y,x%y);}
ll LCM(ll x,ll y){return (x*y)/(GCD(x,y));}
ll LOGK(ll x,ll k){if(x>=k)return 1+LOGK(x/k,k);return 0;}
ll MPOW( ll a, ll b, ll m) { if(b==0) return 1; ll x=MPOW(a,b/2,m); x=(x*x)%m; if(b%2==1) x=(x*a)%m; return x;}
ll MINV(ll a,ll m) {return MPOW(a,m-2,m);}

class pnc{
  ll FACT_MAX,MODU;
  vector<ll> fact;
public:
  pnc( ll n, ll m) { FACT_MAX = n; fact.resize(FACT_MAX); MODU = m; MFACT_INIT(MODU);}
  void MFACT_INIT( ll m) { fact[0]=1; for(ll i=1;i<FACT_MAX;++i) fact[i]=(i*fact[i-1])%MODU;}
  ll MFACT( ll n) { return fact[n];}
  ll PERM( ll n, ll r) { return (fact[n]*::MINV(fact[n-r],MODU))%MODU;}
  ll COMB( ll n , ll r) { return (PERM(n,r)*::MINV(fact[r],MODU))%MODU;}
};

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

    ll test=1;
    //cin>>test;
    while(test--)
    {
        string str;
        cin>>str;

        vector<ll> ans(str.length());

        for(ll i=0;i<str.length();i++)
        ans[i]=str[i]-'0';

        ll mod=2019;

        map<ll,ll> mp;
        mp[0]=1;
        ll total=0;
        ll p=0;
        ll rem=0;

        for(ll i=str.length()-1;i>=0;i--)
        {
            ll val=(ans[i]*MPOW(10,p,mod))%mod;
            val+=rem;
            val%=mod;
            p++;
            rem=val;

            if(mp[val]==0)
            mp[val]=1;
            else
            {
                total+=mp[val];
                mp[val]++;
            }
            
        }

        cout<<total;

    }
}

Measured memory_bytes: 5056
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[float('inf')]*n
dp[0]=0

for i in range(1,n):
    for j in range(1,k+1):
        if i-j<0:break
        pre=dp[i-j]+abs(h[i]-h[i-j])
        dp[i]=min(dp[i],pre)
print(dp[-1])

Measured memory_bytes: 55392
#include <stdio.h>
int main()
{
	char a[4], s = '\0', k = '\0';
	gets(a);
	s = a[0];
	for (int i = 1; i < 4; i++)
	{
		if (a[i] != s && k == '\0')
			k = a[i];
		else if (a[i] != s && a[i] != k)
		{
			printf("No");
			return 0;
		}

	}
	if (k == '\0')
	{
		printf("No");
	}

	else
	{
		printf("Yes");
	}

}


Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), m = sc.nextInt(), c = sc.nextInt();
		int[] b = new int[m];
		for(int i = 0;i < m;i ++) {
			b[i] = sc.nextInt();
		}
		int sum = 0,a = 0,cnt = 0;
		for(int i = 0;i < n;i ++) {
			sum = 0;
			for(int k = 0;k < m;k++) {
				a = sc.nextInt();
				sum += a * b[k];
			}
			sum += c;
			if(sum > 0) cnt++;
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 22224
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)

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

    ll n;
    cin>>n;
    ll left=0,right=1;
    ll size = 1;
    ll two = 1;
    while(left>n || right<n){
      two*=-2;
      if(size%2 == 1){
        right += two;
        left = right + two + 1;
      }
      else{
        left += two;
        right = left + two - 1;
      }
      size++;
    }

    while(size>1){
      if(left<=n && n<=right){
        n -= two;
        cout<<"1";
      }
      else{
        cout<<"0";
      }

      if(size%2 == 0){
        right -= two;
        left = right + (two/2 + 1);
      }
      else{
        left -= two;
        right = left + (two/2 - 1);
      }
      two/=-2;
      size--;
    }
    if(n <= 1)cout<<n;
    cout<<endl;

}


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

using namespace std;

const int MAX_N = 1e5+10;
const int MAX_C = 30+10;
const int MAX_T = 1e5+10;

int N, C;
int s[MAX_N], t[MAX_N], c[MAX_N];

int main(int argc, char const *argv[])
{
	cin >> N >> C;
	for (int i = 0; i < N; ++i) {
		scanf("%d %d %d", &s[i], &t[i], &c[i]);
		c[i]--;
	}
	vector<vector<pair<int, int> > > tb(MAX_C);
	for (int i = 0; i < N; ++i) {
		tb[c[i]].push_back(make_pair(s[i],t[i]));
	}
	for (int i = 0; i < C; ++i) {
		sort(tb[i].begin(), tb[i].end());
	}

	vector<pair<int, int>> vec;

	for (int i = 0; i < C; ++i) {
		if (tb[i].size()==0) continue;
		if (tb[i].size()==1) {
			vec.push_back(make_pair(tb[i][0].first, tb[i][0].second));
		}
		int idx = 0;
		for (int j = 0; j+idx < tb[i].size()-1; ) {
			if (tb[i][j+idx].second==tb[i][j+idx+1].first) idx++;
			else {
				vec.push_back(make_pair(tb[i][j].first, tb[i][j+idx].second));
				j+=idx+1;
				idx = 0;
			}
		}
		if (idx) {
			vec.push_back(make_pair(tb[i][tb[i].size()-idx-1].first, tb[i][tb[i].size()-1].second));
		}
	}

	long long table[MAX_T]={0};

	for (int i = 0; i < vec.size(); ++i) {
		table[--vec[i].first]++;
		table[vec[i].second]--;
	}

	for (int i = 1; i < MAX_T; ++i) {
		table[i] += table[i-1];
	}

	long long ans = 0;

	for (int i = 0; i < MAX_T; ++i) {
		ans = max(ans, table[i]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4212
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const int INF = 1001001001;
vector<int> to[100005];

int main()
{
	int n, m;
	cin >> n >> m;
	rep(i, m)
	{
		int a, b;
		cin >> a >> b;
		--a; --b;
		to[a].push_back(b);
		to[b].push_back(a); //to[0] 1; to[1] 0,2,3;�@to[2] 1,3; to[3] 1,2;
	}
	queue<int> q;
	vector<int> dist(n, INF);//dist{INF,INF,...,INF}
	vector<int>pre(n, -1);//pre{-1,-1,...,-1}
	dist[0] = 0;//dist{0,INF,...}
	q.push(0); //q {0}
	while (!q.empty())//when q is not empty 
	{
		int v = q.front();	q.pop();//v=0 //v=1 //v=2,3 as well as v=0,1
		for (int u : to[v])//u=1�@//u=0,2,3
		//every u which is contained in to[v]
		{
			if (dist[u] != INF) continue; //execute if dist[u] is not renewed
			dist[u] = dist[v] + 1;//dist{0,1,INF,...}�@//dist{0,1,2,2}
			pre[u] = v;// pre{-1,0,...}//pre{-1,0,1,1}
			q.push(u);//q{0,1}//q{0,1,2,3}
		}
	}
	auto result = find(dist.begin(), dist.end(), INF);
	if (result == dist.end()) {
		cout << "Yes" << endl;
		rep(i, n)
		{
			if (i == 0)continue;
			int ans = pre[i];
			++ans;
			cout << ans << endl;
		}
	}
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 10620