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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
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; }
//template end

int mod=1e9+7;
struct Mint {
    int val;
    Mint inv() const{
        int tmp,a=val,b=mod,x=1,y=0;
        while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
        return Mint(x);
    }
public:
    Mint():val(0){}
    Mint(ll x){if((val=x%mod)<0)val+=mod;}
    Mint pow(ll t){Mint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
    Mint& operator+=(const Mint& x){if((val+=x.val)>=mod)val-=mod;return *this;}
    Mint& operator-=(const Mint& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
    Mint& operator*=(const Mint& x){val=(ll)val*x.val%mod; return *this;}
    Mint& operator/=(const Mint& x){return *this*=x.inv();}
    bool operator==(const Mint& x) const{return val==x.val;}
    bool operator!=(const Mint& x) const{return val!=x.val;}
    bool operator<(const Mint& x) const{return val<x.val;}
    bool operator<=(const Mint& x) const{return val<=x.val;}
    bool operator>(const Mint& x) const{return val>x.val;}
    bool operator>=(const Mint& x) const{return val>=x.val;}
    Mint operator+(const Mint& x) const{return Mint(*this)+=x;}
    Mint operator-(const Mint& x) const{return Mint(*this)-=x;}
    Mint operator*(const Mint& x) const{return Mint(*this)*=x;}
    Mint operator/(const Mint& x) const{return Mint(*this)/=x;}
};
struct factorial {
    vector<Mint> Fact, Finv;
public:
    factorial(int maxx){
        Fact.resize(maxx+1),Finv.resize(maxx+1); Fact[0]=Mint(1); rep(i,0,maxx)Fact[i+1]=Fact[i]*(i+1);
        Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*i;
    }
    Mint fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];}
    Mint nPr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[n-r];}
    Mint nCr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[r]*Finv[n-r];}
};

int n,k; vector<int> g[100010];
Mint ans=1;
void dfs(int v,int pre,int col){
    ans*=col; col=k-1;
    if(pre!=-1)col--;
    for(int to:g[v])if(to!=pre){
        dfs(to,v,col); col--;
    }
}

int main(){
    scanf("%d%d",&n,&k);
    rep(i,0,n-1){
        int u,v; scanf("%d%d",&u,&v);
        u--; v--;
        g[u].push_back(v); g[v].push_back(u);
    }
    dfs(0,-1,k);
    printf("%d\n",ans.val);
    return 0;
}

Measured memory_bytes: 9216
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef vector<int> vint;

int main() {
	int n, m;	cin >> n >> m;
	vector<vint> edge(n);
	for (int i = 0; i < m; i++) {
		int a, b;	cin >> a >> b;	a--;	b--;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	vector<bool> visited(n, false);
	vector<int> ret;
	int cur = 0;
	visited[cur] = true;
	ret.push_back(cur);
	bool next = true;
	while (next) {
		next = false;
		for (int i = 0; i < edge[cur].size(); i++) {
			if (visited[edge[cur][i]])	continue;
			cur = edge[cur][i];
			visited[cur] = true;
			ret.push_back(cur);
			next = true;
			break;
		}
	}
	cur = 0;
	next = true;
	while (next){
		next = false;
		for (int i = 0; i < edge[cur].size(); i++) {
			if (visited[edge[cur][i]])	continue;
			cur = edge[cur][i];
			visited[cur] = true;
			ret.insert(ret.begin(), cur);
			next = true;
			break;
		}
	}
	cout << ret.size() << endl;
	for (int i = 0; i < ret.size(); i++) {
		cout << (i > 0 ? " " : "") << ret[i] + 1;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 6776
#include<stdio.h>

int main( void ){
    int m1,m2,d1,d2;
    scanf("%d%d", &m1, &d1);
    scanf("%d%d", &m2, &d2);
    if(m1 != m2){
        printf("1\n");
    } else {
        printf("0\n");
    }
    return 0;
}

Measured memory_bytes: 128
N, M = map(int, input().split())
H = list(map(int, input().split()))

a = [None] * M
b = [None] * M

ans = {i: True for i in range(N)}

for i in range(M):
    s, t = map(int, input().split())
    a, b = s - 1, t - 1
    if H[a] > H[b]:
        ans[b] = False
    elif H[a] < H[b]:
        ans[a] = False
    elif H[a] == H[b]:
        ans[a] = False
        ans[b] = False

nums = 0
for i in ans.values():
    if i:
        nums += 1

print(nums)


Measured memory_bytes: 92696
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 100000 + 47;
const int MOD = 1000 * 1000 * 1000 + 7;

int A[MAX];
int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	int n, c, k;
	cin >> n >> c >> k;
	FOR(i, 0, n)
	{
		cin >> A[i];
	}

	sort(A, A + n);
	int cnt = 1;
	int last = 0;
	int ans = 0;

	FOR(i, 1, n)
	{
		if (cnt == c || A[i] - A[last] > k)
		{
			ans++;
			cnt = 1;
			last = i;
			continue;
		}

		cnt++;
	}

	ans++;
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),char_cmp_r);
#define chsort(s) qsort(s,strlen(s),sizeof(char),cmp)
#define chsort_r(s) qsort(s,strlen(s),sizeof(char),char_cmp_r);
#define TYPE char
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
	return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
	return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}

int main(void){
	char s[101],t[101];
	chin(s);
	chin(t);
	sort(s,strlen(s));
	sort_r(t,strlen(t));
	puts(strcmp(s,t)<0?"Yes":"No");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define traverse(container,it)  for(auto it = container.begin();it != container.end(); it++)
ll MOD = 1e9 + 7;

int main()
{
    //freopen("in.txt","r",stdin);
    int n,k,cnt=0;
    string s;
    vector< int > one_segment;
    vector< int > zero_segment;
    cin >> n >> k >> s;
    s += '2';
    char first_segment = s[0];


    for(int i=0;i<n;i++){
        cnt++;
        if(s[i] != s[i+1]){
            if(s[i] == '0'){
                zero_segment.push_back(cnt);
            }
            else{
                one_segment.push_back(cnt);
            }
            cnt = 0;
        }
    }
    s.erase(s.begin()+n);

    int current_one_length = 0,current_zero_length = 0,left_segment = 0,max_length = 1;

    for(int i=0;i<(zero_segment.size())||i < one_segment.size();i++){
        if(i<one_segment.size())    current_one_length += one_segment[i];
        if(i<zero_segment.size()) current_zero_length += zero_segment[i];

        if(i>=k){
            current_one_length -= one_segment[left_segment];
            current_zero_length -= zero_segment[left_segment];
            left_segment++;
        }
        int extra  = 0;
        if(first_segment == '0' && left_segment != 0){
                extra = one_segment[left_segment-1];
        }
        else if(first_segment == '1' && (i+1)<one_segment.size()){
                extra = one_segment[i+1];
        }

        int length  = current_one_length + current_zero_length + extra;
        max_length = max(max_length,length);
    }
    cout << max_length << endl;

    return 0;

}


Measured memory_bytes: 1020
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int n;cin>>n;
    vin judge(n+1);
    int cannot=0;
    rep(i,n){
        int a;cin>>a;
        if(a>n)cannot++;
        else judge[a]++;
    }
    int ans=cannot;
    rep2(i,1,n+1){
        if(judge[i]>=i)ans+=judge[i]-i;
        else ans+=judge[i];
    }   
    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <stdio.h>
int main(){
  int a;
  int b,c;
  int d;
  scanf("%d",&a);
  scanf("%d %d",&b,&c);
  for(d=b;d<=c;d++)
  	if (d%a==0) { printf("OK"); exit(0); }    
  printf("NG");     
}

Measured memory_bytes: 1732
n,a,b,c,d=map(int,input().split())
x=y=a
for i in range(1,n):
  if (x+y)//2<b:
    x+=c
    y+=d
  else:
    x-=d
    y-=c
if x<=b<=y:print('YES')
else:print('NO')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
// make pair, tuple
// make pair, tuple
// 
// __gcd(int, int);
// lcm = a * b / __gcd(a, b);
// 
// bool isPrime(int n){
//       if(n <= 1)return false;
//       if(n <= 3)return true;
//       if(n % 2 == 0 || n % 3 == 0)return false;
//       for(int i = 5;i * i <= n;i += 6){
//             if(n % i == 0 || n % (i + 2) == 0)return false;
//       }
//       return true;
// }
// int countSubString(string s, string temp){
//       int ans = 0;
//       size_t f = s.find(temp);
//       while(f != string::npos){
//             ans++;
//             f = s.find(temp, f + 1);
//       }
//       return ans;
// }
// 
// #Count leading & trailing zero of an integer bits
// __builtin_clz(n);
// __builtin_clzll(n);
//
// #Count 1s bits of an integer
// __builtin_popcount(n);
// __builtin_popcountll(n);
//
// #Error checking
// assert(n == 3);
// 
// #Error Printing
// cerr << "Some thing";

int main(){
    long long int MOD = 1e9 + 7;
    int n,m;cin >> n >> m;
    vector<long long int> dp(n + 5, 0);
    set<int> s;
    dp[0] = 1;
    for(int i = 0;i < m;i++){
        int t;cin >> t;
        s.insert(t);
    }
    for(int i = 1;i <= n;i++){
        if(s.count(i) > 0)continue;
        if(i - 1 >= 0)dp[i] += dp[i - 1];
        if(i - 2 >= 0)dp[i] += dp[i - 2];
        dp[i] %= MOD;
    }
    cout << dp[n];
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 1000000000;
const ll INF64 = 9223372036854775807ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;
//mapは、if関数などで覗いただけで構成されるので注意しよう！
ll n,a,b,c,d;
ll ans=INF64;
std::map<ll, ll> m;
int cou=0;
void dfs(ll num,ll val){
    if(m.find(num)!=m.end()){
        if(m[num]<=val)return;
        else chmin(m[num],val);
    }
    else{
        m[num]=val;
    }
    /*
    cou++;
    if(cou%20000==0){
        ppri(m.size(),ans);
    }
    */
    if(double(val)+double(num)*double(d)<double(INF64))chmin(ans,val+num*d);
    if(num==1ll)return;
    dfs(num/2,val+d*(num%2)+a);
    if(num%2)dfs((num+1)/2,val+d*(2-(num%2))+a);
    //if(num<=2)return;
    dfs(num/3,val+d*(num%3)+b);
    if(num%3)dfs((num+2)/3,val+d*(3-(num%3))+b);
    //if(num<=4)return;
    dfs(num/5,val+d*(num%5)+c);
    if(num%5)dfs((num+4)/5,val+d*(5-(num%5))+c);
    return;
}

int main(){
    query{
        std::cin >> n>>a>>b>>c>>d;
        ans=INF64;
        m.clear();
        dfs(n,0ll);
        std::cout << ans << std::endl;
    }
}

Measured memory_bytes: 4384
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n;
  cin>>n;
  int ans=1;
  rep(i,n){
    int a;
    cin>>a;
    ans=ans*a/__gcd(ans,a);
  }
  cout<<ans<<endl;


}


Measured memory_bytes: 3200
#coding : utf8

def maximumSum(slist):

    ABCli = list(map(int,slist[0]))
    K = int(slist[1][0])
    ABCli.sort()

    for i in range(0,K):
        ABCli[2] = ABCli[2] * 2

    return sum(ABCli)


if __name__ == '__main__':
    # A=[0][0], B=[0][1], C=[0][2], D=[1][0]
    string_list = [input().split() for i in range(2)]

    print(maximumSum(string_list))


Measured memory_bytes: 2940
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p){ os << "(" << p.first << ", " <<  p.second << ")"; return os; }

int n;
using ll = long long;
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    n++;
    vector<int> a(n);
    vector<int> b(n);
    REP(i, n) cin >> a[i];
    REP(i, n - 1) cin >> b[i];
    int left = 0;
    ll ans = 0;
    REP (i, n - 1) {
        int es = max(a[i] - left, 0);
        int kill = min(es, b[i]);
        left = b[i] - kill;
        ans += kill;
        // DDD(i, kill, left);
        ans += min(left, a[i + 1]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)
double r3 = sqrt(3);
typedef tuple<double, double, double, int> p;
int main() {
	//ifstream in("Ain.txt");
	//cin.rdbuf(in.rdbuf());
	//ofstream ofs("Aout.txt");
	//cout.rdbuf(ofs.rdbuf());
	cout << setprecision(20);
	int n, k;
	while (cin >> n, n) {
		
		cin >> k;
		p point;//(h, l, r, id)
		vector<p> ps,psh,psl,psr;
		double x,y;
		rep(i, n) {
			cin >> x >> y;
			point = make_tuple(y, x - y / r3, x + y / r3, i);
			ps.push_back(point);
		}
		psh = ps;
		sort(psh.begin(),psh.end());
		psl = ps;
		sort(psl.begin(),psl.end(), [](p a, p b){return get<1>(a) < get<1>(b);} );
		psr = ps;
		sort(psr.begin(),psr.end(), [](p a, p b){return get<2>(a) < get<2>(b);} );
		int F[n] = {};
		int ph = 0;
		int a = 0;
		double ans = 1e15;
		while (ph < n and a <= k) {
			double h = get<0>(psh[ph]);
			rep(i, n) F[i] = F[i] & 4;
			int pl = 0;
			int pr = n - 1;
			int c = 0;
			int b = 0;
			while(pl < n and F[get<3>(psl[pl])] != 0) {
				F[get<3>(psl[pl])] = F[get<3>(psl[pl])] | 1;
				pl ++;
			}
			if (pl == n) break;
			while (pr >= 0){
				int id = get<3>(psr[pr]);
				if (F[id] == 0) {
					c ++;
					pr --;
					F[id] += 2;
				} else {
					pr --;
					F[id] = F[id] | 2;
				}
			}
			//ans = min(ans, get<2>(psr[pr]) - h / r3 -  (get<1>(psl[pl]) + h / r3) );
			while (1) {
				if (a + b + c <= k) {
					if (F[get<3>(psl[pl])] == 0) {
						F[get<3>(psl[pl])] += 1;
						pl ++;
						b ++;
					} else {
						F[get<3>(psl[pl])] = (F[get<3>(psl[pl])] | 1);
						pl ++;
					}
				} else {
					pr ++;
					if(pr >= n) break;
					if (F[get<3>(psr[pr])] == 2) c--;
					F[get<3>(psr[pr])] = (F[get<3>(psr[pr])] & 5);
				}
				if (a + b + c <= k) {
					ans = min(ans, get<2>(psr[pr]) - h / r3 -  (get<1>(psl[pl]) + h / r3) );
				}
			}
			F[get<3>(psh[ph])] += 4;
			ph ++;
			a ++;
		}
		cout << ans * 3 << endl;
	}
}



Measured memory_bytes: 4600
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long int
#define MOD 1000000007

void Fast_IO(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input.in","r",stdin);
	freopen("output.out","w",stdout);
	freopen("debug.out","w",stderr);
	#endif
}

int main(){
	Fast_IO();
	int n,k,i;
	cin>>n>>k;
	int a[n],freq[n+1]={0},flag,c;
	for(i=0;i<n;i++){
		cin>>a[i];
		freq[max(0,i-a[i])]++;
		freq[min(n,i+a[i]+1)]--;
	}

	while(k>0){
		c=0;
		flag=1;
		for(i=0;i<n;i++){
			c+=freq[i];
			a[i]=c;
			if(a[i]!=n)
				flag=0;
		}
		for(i=0;i<n;i++)
			freq[i]=0;

		for(i=0;i<n;i++){
			freq[max(0,i-a[i])]++;
			freq[min(n,i+a[i]+1)]--;
		}
		if(flag)
			break;
		k--;
	}
	// cout<<k<<'\n';
	for(i=0;i<n;i++)
		cout<<a[i]<<' ';
	cout<<'\n';

	return 0;
}

Measured memory_bytes: 5204
#include <iostream>
#include <cmath>
#include <algorithm>


int main(){

	int tmp;
	std::cin >> tmp;

	int num[4];
	for(int i = 0; i < 4; i++){
		num[3-i] = (tmp / (int)(std::pow(10, i)) % 10);
	}

	// 全探索
	bool flag = false;
	for(int a1 = -1; a1 <= 1 && !flag; a1+=2){
		for(int a2 = -1; a2 <= 1 && !flag; a2+=2){
			for(int a3 = -1; a3 <= 1 && !flag; a3+=2){

				if( (num[0]+ num[1] * a1 + num[2] * a2 + num[3] * a3) == 7){

					num[1] *= a1;
					num[2] *= a2;
					num[3] *= a3;

					flag = true;
				}
			}
		}
	}

	std::cout << num[0];
	for(int i =1; i < 4; i++){
		std::cout << std::showpos << num[i];
	}
	std::cout << "=7" << std::endl;

	return 0;
}

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

int main(){
    int deg;
    double rad;
    double PI = acos(-1);  // PI = 3.141593...
    double a, b, c;
    double S, L, h;
    cin >> a >>b;
    scanf("%d", &deg);
    rad = deg * PI / 180;
    S = (0.5)*a*b*sin(rad);
    c = sqrt(a*a+b*b-2*a*b*cos(rad));
    printf("%lf\n",S);
	printf("%lf\n",a+b+c);
	printf("%lf\n",2*S/a);
    
  return 0;
}


Measured memory_bytes: 3448
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
long double pi=3.14159265358979323846L;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll gya[1000010];
ll kai[1000010];
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int k,x;cin>>k>>x;
    k*=500;
    if(k>=x)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

using namespace std;

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

typedef long long ll;
typedef long double ld;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n, m, r;
    cin >> n >> m >> r;
    vector<int> city(r);
    rep (i, r) {
        cin >> city[i];
        city[i]--;
    }
    sort(city.begin(), city.end());
    vector<vector<int> > g(n, vector<int>(n, Inf));
    rep (i, n) g[i][i] = 0;
    rep (i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        g[a][b] = g[b][a] = c;
    }
    rep (k, n) {
        rep (i, n) {
            rep (j, n) {
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }
    int res = Inf;
    do {
        int dist = 0;
        rep (i, r - 1) dist += g[city[i]][city[i + 1]];
        res = min(res, dist);
    } while (next_permutation(city.begin(), city.end()));
    cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;

bool check(char s){
    if(s=='A'||s=='C'||s=='G'||s=='T') return true;
    return false;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s;
    int ans=0;

    for(int i=0; i<s.length(); i++){
        if (check(s[i])){
            int cnt=1;
            while(cnt+i<=s.length()){
                if(check(s[i+cnt])){
                    cnt++;
                    ans=max(ans,cnt);
                }
                else{
                    ans=max(ans,cnt);
                    break;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
using namespace std;
int n,i,j,k,a[200005],gap[2],nxt[3],cur[2],ans;
int main(){
	cin>>n;rep(i,n) cin>>a[i];
	rep(i,n+1){
		cur[0]=max(0,a[i]-a[i-1]);
		cur[1]=min(0,a[i]-a[i-1]);
		nxt[0]=nxt[1]=0x3f3f3f3f;nxt[2]=0;
		for(j=0;j<=1;j++)for(k=0;k<=1;k++){
			nxt[j+k]=min(nxt[j+k],max(0,gap[j]+cur[k]));
		}
		int d=(nxt[0]>a[i]);
		ans+=d;
		for(j=0;j<=1;j++) gap[j]=nxt[j+d];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4412
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
	  result=(result*base)%modulus;
	  exponent=exponent>>1;
	  base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}
 
 
/*
ll ncr(ll N,ll K){
	if(N<K)return 0;
	if(K==0)return 1;
	if(N==0)return 0;
 
	ll den=1;
	for(ll i=1;i<=K;i++)den*=i;
	ll num=1;
	while(K--){
		num*=N;
		if(num%den==0){
			num/=den;
			den=1;
		}
		N--;
	}
 
	return num;
}
*/
ll n;
ll a[55];
int main(){FAST;
cin>>n;
for(ll i=1;i<=n;i++){
	cin>>a[i];
}
ll l=0;
for(ll i=1;i<=n;i++){
	if(a[i]!=i){
		l++;
	}
}
if(l == 2 || l == 0){
	cout<<"YES";
}
else cout<<"NO";
return 0;
}

Measured memory_bytes: 256
module Main where

import Control.Applicative
import Numeric
import Data.List

main :: IO ()
main = do
  { [n] <- getInts
  ; cards <- loop n
  ; putCards (allcards \\ cards)
  }
  
putCards :: [(Suit, Int)] -> IO()
putCards = putStr . unlines . map showCard

loop :: Int -> IO [(Suit, Int)]
loop 0 = return []
loop n = do
  { c  <- getCard   
  ; cs <- loop (n-1)
  ; return (c:cs)
  }

showCard :: (Suit, Int) -> String
showCard (s,n) = show s ++ " " ++ show n

--

data Suit = S | H | C | D deriving (Eq, Ord, Show, Read)

allcards :: [(Suit, Int)]
allcards = [ (s,r) | s <- [S, H, C, D], r <- [1..13] ]

getCard :: IO (Suit, Int)
getCard = do
  { [s, r] <- words <$> getLine
  ; return (read s, read r)
  }

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn .  unwords . map show

getDoubles :: IO [Double]
getDoubles = map read . words <$> getLine

putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDouble

showDouble :: Double -> String
showDouble d = showFFloat Nothing d ""



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

using namespace std;

#define forn(i, s, f) for(int i = (s); i <= (f); ++i)
#define for1(i, f, s) for(int i = (f); i >= (s); --i)
#define show(x) cout << #x << " = " << x << " ";
#define skip continue;
#define pb push_back

#define _1 first
#define _2 second

typedef unsigned long long ll;

const int INF = 1e9 + 5;
const int N5 = 1e5 + 5;

ll n, a[4 * N5], ans, y, x;

main()
{
    cin >> n;
    forn (i, 1, n * 3)
        cin >> a[i];
    sort(a + 1, a + (n * 3) + 1);
    for (int i = n + 1;  i <= n * 3; i += 2)
        x += a[i];

    cout << x;
}


Measured memory_bytes: 2560
N = int(input())
P = list(map(int, input().split()))

m = P[0]
ans = 0
for i in range(N):
    # print(P[:i+1])
    if P[i] <= m:
        m = P[i]
        # print(i)
        ans += 1
    # m = max(P[:i+1])
    # print(m)


print(ans)


Measured memory_bytes: 24744
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb(x) (x&-(x))
const int N = 101010;
int n;
int num[105];
long long earn[1500];
long long p[105][15];
long long maxx=-9999999999;
int getcount(int a,int b)
{
	int c=(a&b);
	int ans=__builtin_popcount(c);
	return ans;
} 
void read(int i)
{
	int tmp;
	for(int j=0;j<10;j++)
	{
	scanf("%d",&tmp);
	num[i]=num[i]*2+tmp;
	}
}
int main(){
	memset(num,0,sizeof(num));
	memset(earn,0,sizeof(earn));
	rep(i,0,105)rep(j,0,15) p[i][j]=-99999999999;	
	cin>>n;

	for(int i=0;i<n;i++)
	{
		read(i);//读10个0 1进去 把num[i]装满
	}
		for(int i=0;i<n;i++)
	{
		for(int j=0;j<=10;j++)
		scanf("%lld",&p[i][j]);	
	}
	int maxxi;

	for(int i=1;i<1024;i++)//我的开店状态 
	{	
		for(int j=0;j<n;j++)//对于每家店 把赚的钱加起来 
		{	
			earn[i]=earn[i]+p[j][getcount(i,num[j])];
		}//赚的总钱数 
		if(earn[i]>maxx)
		{
			maxx=earn[i];
		}
	}
	cout<<maxx<<endl;
    return 0;
}
/*
1
1 1 0 1 0 0 0 1 0 1
3 4 5 6 7 8 9 -2 -3 4 -2


*/


Measured memory_bytes: 256
def gcd(a,b):
	if a % b == 0:
		return b
	else:
		return gcd(b,a%b)
while True:
	try:
		a,b = map(int,input().split())
		d = gcd(max(a,b),min(a,b))
		print(d,a*b//d)
	except:
		break

Measured memory_bytes: 5596
#include<cstdio>
const int N=4007,M=200007,P=1000000007;
int f[N][N],g[N][N],a[M],b[M];
int read(){int x;scanf("%d",&x);return x;}
void inc(int&a,int b){a+=b-P,a+=a>>31&P;}
int main()
{
    int n=read(),ans=0;g[0][0]=1;
    for(int i=1;i<=n;++i) a[i]=read(),b[i]=read(),++f[2000-a[i]][2000-b[i]];
    for(int i=0;i<=4000;++i) for(int j=0;j<=4000;++j) inc(g[i][j],i? g[i-1][j]:0),inc(g[i][j],j? g[i][j-1]:0),inc(f[i][j],i? f[i-1][j]:0),inc(f[i][j],j? f[i][j-1]:0);
    for(int i=1;i<=n;++i) inc(ans,f[2000+a[i]][2000+b[i]]),inc(ans,P-g[a[i]*2][b[i]*2]);
    printf("%d",(int)(ans*500000004ll%P));
}

Measured memory_bytes: 127104
#include <iostream>
using namespace std;
#define MAX 10001

struct set{
    int parent;
    int key;
};

set A[MAX];

void unite(int x,int y){
    int n1=x;
    int n2=y;
   while(true){
       if(A[n1].parent==n1 && A[n2].parent==n2)break;
       else{
           n1=A[n1].parent;
           n2=A[n2].parent;
       }
   }
   A[n1].parent=n1;
   A[n2].parent=n1;
}

int findset(int x,int y){
    while(true){
        if(A[x].parent==x&&A[y].parent==y)break;
        else {
           x=A[x].parent;
           y=A[y].parent;
        }
    }
   if(A[x].parent==A[y].parent) return 1;
   else return 0;
    
}

int main(){
    int q,n,com,x,y;

    cin>>n>>q;
    
    for(int i=0;i<n;i++){
        A[i].parent=i;
        A[i].key=i;
    }
   
    for(int i=0;i<q;i++){
       cin >> com >> x >> y;
        if(com==0) unite(x,y);
        else if(com==1) cout<<findset(x,y)<<endl;
    }
    
    //for(int i=0;i<n;i++){
        //cout<<"parent "<<A[i].parent<<" key "<<A[i].key<<endl;
    //}

}



Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  vector<vector<int>> v(n, vector<int>(3));
  int not_zero = -1;
  rep(i, 0, n) {
    rep(j, 0, 3) cin >> v[i][j];
    if (v[i][2])
      not_zero = i;
  }

  rep(cx, 0, 101) {
    rep(cy, 0, 101) {
      bool flg = true;
      ll H =
          abs(v[not_zero][0] - cx) + abs(v[not_zero][1] - cy) + v[not_zero][2];
      rep(i, 0, n) {
        ll h = abs(v[i][0] - cx) + abs(v[i][1] - cy);
        if ((v[i][2] == 0 && H > h) || (v[i][2] > 0 && H - v[i][2] != h))
          flg = false;
      }
      if (flg) {
        cout << cx << " " << cy << " " << H << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 3584
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; ++i)

int main(){
double n,m,d;
cin>>n>>m>>d;

if(d==0) printf("%.10lf\n",(m-1)/n);
else printf("%.10lf\n",2*(m-1)*(n-d)/n/n);
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
inline int rd() {
	char ch=getchar(); int i=0,f=1;
	while(!isdigit(ch)) {if(ch=='-')f=-1; ch=getchar();}
	while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=getchar();}
	return i*f;
}
const int N=2e5+50,INF=0x3f3f3f3f;
int n,col[N],fa[N],sze[N];
int d1[N]; //子树最远点
int d2[N]; //父亲最远点
int d3[N]; //经过存在黑点的子树最近点
int d4[N]; //经过存在黑点的父亲最近点
int d5[N]; //不经过某子树最远点
int d6[N]; //下界 
vector <int> edge[N]; 
inline void dfs1(int x,int f) {
	fa[x]=f; sze[x]=col[x];
	if((x!=1 && edge[x].size()==1) || (x==1 && !edge[x].size())) {
		d1[x]=0; 
		d3[x]=(col[x]?0:INF);
		return;
	}
	int mx=0,mx2=INF;
	for(auto v:edge[x]) {
		if(v==f) continue;
		dfs1(v,x); sze[x]+=sze[v];
		mx=max(mx,d1[v]); 
		if(d3[v]<INF) mx2=min(mx2,d1[v]);
	}
	d1[x]=mx+1; d3[x]=mx2+1; 
	if(col[x]) d3[x]=min(d3[x],d1[x]); 
}
inline void dfs2(int x,int f) {
	d2[x]=max(d2[x],(f!=0)+d2[f]);
	if(f) d5[x]=max(d5[x],d2[x]-1);
	int mx,mx2;
	mx=-1;
	for(int e=0;e<edge[x].size();++e) {
		int v=edge[x][e]; if(v==f) continue;
		d2[v]=max(d2[v],mx+2);
		mx=max(mx,d1[v]);
	}
	mx=-1;
	for(int e=edge[x].size()-1;e>=0;e--) {
		int v=edge[x][e]; if(v==f) continue;
		d2[v]=max(d2[v],mx+2);
		mx=max(mx,d1[v]);
	}
	for(auto v:edge[x]) if(v!=f) dfs2(v,x);
}
int main() { 
	n=rd();
	memset(d3,0x3f,sizeof(d3));
	memset(d4,0x3f,sizeof(d4));
	for(int i=1;i<n;i++) {
		int x=rd(), y=rd();
		edge[x].push_back(y);
		edge[y].push_back(x); 
	}
	string s; cin>>s; int bz=0;
	for(int i=0;i<n;i++) col[i+1]=s[i]-'0', bz|=col[i+1];
	if(!bz) {puts("0"); return 0;}
	dfs1(1,0); 
	dfs2(1,0);
	long long ans=0;
	for(int i=1;i<=n;i++) {
		if(col[i]) d6[i]=0;
		else d6[i]=min(d3[i],(sze[i]==sze[1])?INF:d2[i]);
		int u=max(d1[i],d2[i])-1;
		for(auto v:edge[i]) {
			if(v==fa[i]) u=min(u,d1[i]+1);
			else u=min(u,d5[v]+1);
		} 
		if(u>=d6[i]) ans=ans+u-d6[i]+1;
		//cerr<<i<<" "<<ans<<endl;
	}
	cout<<ans+1;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
   int h,w;cin >>h>>w;
   vector<string>s(h);
    for (int i = 0; i < h; ++i) {
        cin >>s[i];
    }
    for (int i = 0; i < h; ++i) {
        cout <<s[i]<<endl;
        cout <<s[i]<<endl;
    }
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)
//#define MULTI_TEST
//#define GOOGLE
#ifdef LOCAL
#include "debugger.h"
#else
#define db(...)
#endif
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
const ll MOD = 1e9 + 7;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }

void solve()
{
	ll k, a, b;
	cin >> k >> a >> b;
	for (int i = a; i <= b; i++)
	{
		if (i % k == 0)
		{
			cout << "OK" << ln;
			return;
		}
	}
	cout << "NG" << ln;
	return;
}

int main()
{
#ifndef LOCAL
	FASTIO;
#endif
	int t = 1;
#ifdef LOCAL
	clock_t start, stop;
	start = clock();
#endif
#ifdef MULTI_TEST
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
	{
#ifdef GOOGLE
		cout << "Case #" << tc << ": ";
#endif
		solve();
	}
#ifdef LOCAL
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 3608
class DiGraph:
    def __init__(self, n):
        self.n = n
        self.graph = [[] for _ in range(n)]
        self.rev = [[] for _ in range(n)]
        self.deg = [0 for _ in range(n)]

    def add_edge(self, fr, to):
        self.graph[fr].append(to)
        self.rev[to].append(fr)
        self.deg[to] += 1

    def scc_ids(self):
        group = [None for _ in range(self.n)]
        used = [0 for _ in range(self.n)]
        order = []
        for s in range(self.n):
            if not used[s]:
                stack = [s]
                used[s] = 1
                while stack:
                    node = stack.pop()
                    movable = False
                    for adj in self.graph[node]:
                        if not used[adj]:
                            movable = True
                            used[adj] = 1
                            stack.append(node)
                            stack.append(adj)
                            break
                    if not movable:
                        order.append(node)
        used = [0 for _ in range(self.n)]
        count = 0
        for s in order[::-1]:
            if not used[s]:
                stack = [s]
                group[s] = count
                while stack:
                    node = stack.pop()
                    used[node] = 1
                    for adj in self.rev[node]:
                        if not used[adj]:
                            group[adj] = count
                            stack.append(adj)
                count += 1
        return group, count

    def scc(self):
        group, count = self.scc_ids()

        scc = [[] for _ in range(count)]
        for i, k in enumerate(group):
            scc[k].append(i)

        return scc


N, M = map(int, input().split())

dg = DiGraph(N)

for i in range(M):
    dg.add_edge(*list(map(int, input().split())))

scc = dg.scc()

print(len(scc))
for c in scc:
    print(len(c), ' '.join(map(str, c)))


Measured memory_bytes: 249532
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
string a,b;
long int ans=0;
int r,c;
void lo()
{
    long int ll[a.length()+1][b.length()+1];
    for(long int i=0;i<=a.length();i++)
    {
        for(long int j=0;j<=b.length();j++)
        {
            if(i==0||j==0)
            ll[i][j]=0;
            else if(a[i-1]==b[j-1])
            {
            ll[i][j]=1+ll[i-1][j-1];
            if(ans<ll[i][j])
            {
                ans=ll[i][j];
                r=i;
                c=j;
            }
            }
            else
            ll[i][j]=max(ll[i][j-1],ll[i-1][j]);
        }
    }
    //cout<<ans<<" "<<r<<" "<<c<<endl;
    vector<char> x;
    r=a.length(),c=b.length();
    while(r>0&&c>0)
    {
        if(a[r-1]==b[c-1])
        {
            x.push_back(a[r-1]);
            r--;
            c--;
        }
        else if(ll[r-1][c]>ll[r][c-1])
        {
            r--;
        }
        else
        c--;
    }
    std::reverse(x.begin(),x.end());
    for(long int i=0;i<x.size();i++)
    cout<<x[i];
}
int main() {
    cin>>a>>b;
    lo();
}

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

signed main() {
  // freopen("in", "r", stdin);
  int x;
  while(~scanf("%d", &x)) {
    if(x==3||x==5||x==7)printf("YES\n");
    else printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <queue>
using namespace std;

#define PI 3.14159265358979323846264338327950L

int res;

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

    int A, B, C;
    int data[5];
    cin >> data[0] >> data[1] >> data[2];
    sort(data, data + 3);
    int shortage = data[2] - data[0] + data[2] - data[1];
    if (shortage % 2 == 0)
    {
        res = shortage / 2;
    }
    else
    {
        res = (shortage + 3) / 2;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#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>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int SIZE=100050;
//int arr[SIZE]={};
//ここまでテンプレ
int main(){
	int A,B,C;
	cin>>A>>B>>C;
	set<int> tes;
	for(int i=0;;i++){
		int D=i*A%B;
		if(D==C){
			cout<<"YES"<<endl;
			return 0;
		}
		else if(tes.count(D)){
			cout<<"NO"<<endl;
			return 0;
		}
		else
			tes.insert(D);
	}
	return 0;
}

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

int main(){
	// sengen
	long long n,k,sum,wari;
	// nyuryoku
	cin >> n >> k;
	// keisan
	wari = 1000000007;
	sum = 0;
	for(long long i=k;i<=n+1;i++){
		sum += i*(2*n-i+1)/2 - i*(i-1)/2 +1;
		sum = sum%wari;
	}
	// syutsuryoku
	cout << sum;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <set>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b+1;i++)
#define Per(i,b,a) for(int i=b;i>=a;i--)

ll binary_method(ll a,ll b){
    if(b==0) return (ll)1;
    ll temp = binary_method(a,b>>1);
    if(b%2==1) return (((temp*temp)%mod)*a)%mod;
    else return (temp*temp)%mod;
}

ll inv(ll a){
    return binary_method(a,mod-2);
}

ll solve(ll n){
    if(n==-1) return 0;
    if(n==0) return (ll)1;
    ll ans = 1;
    ll temp = 1;
    Rep(i,1,n/2){
        ll bunshi = ((n-2*i +1) * (n-2*i+2))%mod;
        ll bunbo = ((n-i+1)*(ll)i)%mod;

        temp = (((temp * bunshi)%mod ) * inv(bunbo) )%mod;
        ans = (ans+temp)%mod;
    }
    return ans;
}

int main(){
    int N,M;
    cin>>N>>M;
    if(M==0){
        cout<<solve(N)<<endl;
        return 0;
    }
    int *a = new int[M];
    rep(i,M) cin>>a[i];

    int *start = new int[M+1];
    int *end = new int[M+1];
    start[0] = 0;
    rep(i,M) start[i+1] = a[i]+1;
    rep(i,M) end[i] = a[i]-1;
    end[M] = N;
    ll ans = 1;
    rep(i,M+1){
        ans = (ans*solve(end[i]-start[i]))%mod;
    }
    cout<<ans<<endl;
    delete[] a;
    delete[] start;
    delete[] end;
    return 0;
}

Measured memory_bytes: 1408
def area(x1,y1,x2,y2):
    if x1 >= x2 or y1 >= y2:
        ans = 0
    else:
        ans = (x2-x1)*(y2-y1)
    return(ans)
w,h,n = map(int,input().split())
xy = [0]*n
for i in range(n):
    xy[i] = list(map(int,input().split()))

x1,y1 = 0,0
x2,y2 = w,h
for x,y,a in xy:
    if a == 1:
        x1 = max(x1,x)
    elif a == 2:
        x2 = min(x2,x)
    elif a == 3:
        y1 = max(y1,y)
    else:
        y2 = min(y2,y)
print(area(x1,y1,x2,y2))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

vector<vector<pair<ll, P> > > g(55);
const ll KEY = 55;
const ll SEICA = 55*55;
ll dist[KEY][SEICA];
P mp[KEY];

void pushQ(priority_queue<T, vector<T>, greater<> > &pq, P nxt, ll DC){
	if(DC < dist[nxt.FI][nxt.SE]){
		dist[nxt.FI][nxt.SE] = DC;
		pq.push(MP(DC, MP(nxt.FI, nxt.SE)));
	}
}

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

	ll n, m, s;cin >> n >> m >> s;
	s = min(SEICA - 1, s);
	REP(i, m){
		ll u, v, a, b;cin >> u >> v >> a >> b;
		u--;v--;
		g[u].EB(v, MP(a, b));
		g[v].EB(u, MP(a, b));
	}
	REP(i, n){
		ll c, d;cin >> c >> d;
		mp[i] = MP(c, d);
	}

	REP(i, KEY)REP(j, SEICA)dist[i][j] = LLINF;
	dist[0][s] = 0;

	priority_queue<T, vector<T>, greater<> > pq;
	pq.push(MP(0, MP(0, s)));

	while(!pq.empty()){
		ll d = pq.top().FI;
		ll node = pq.top().SE.FI;
		ll money = pq.top().SE.SE;
		pq.pop();

		if(dist[node][money] < d)continue;
		pushQ(pq, MP(node, min(SEICA - 1, money + mp[node].FI)), d + mp[node].SE);
		REP(i, g[node].size()){
			ll aite = g[node][i].FI;
			ll nokori = money - g[node][i].SE.FI;
			ll DC = d + g[node][i].SE.SE;
			if(nokori < 0)continue;
			pushQ(pq, MP(aite, nokori), DC);
		}

	}

	for(ll t = 1;t < n;t++){
		ll ans = LLINF;
		REP(i, SEICA)ans = min(ans, dist[t][i]);
		cout << ans << endl;
	}

	return 0;
}


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

using namespace std;
#define ll long long
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(vr) vr.begin(),vr.end()
const int N=1e5+10,inf=2e9;
ll a[N],val[N],n,ps[N],ans[N];

ll get(ll x)
{
    int tmp=upper_bound(val+1,val+n+1,x)-val;
    return ps[tmp]-x*(n-tmp+1);
}

int main()
{
    //freopen("ss.inp","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for (int i=1;i<=n;i++) cin>>a[i],val[i]=a[i];
    sort(val+1,val+n+1);
    for (int i=n;i;i--) ps[i]=ps[i+1]+val[i];
    vector<int> st;
    a[n+1]=inf;
    st.pb(n+1);
    for (int i=n;i;i--)
    {
        while (a[i]>=a[st.back()]) st.pop_back();
        st.pb(i);
    }
    st.pb(0);
    for (int i=1;i<(int)st.size()-1;i++)
    {
        int x=st[i],y=st[i+1];
        ans[x]=get(a[y])-get(a[x]);
    }
    for (int i=1;i<=n;i++) cout<<ans[i]<<"\n";
    return 0;
}


Measured memory_bytes: 4728