akhauriyash/Code-Regression huggingface dataset:
import Control.Monad
import Data.Graph
import Data.List (unfoldr, partition)
import Data.Foldable (toList)
import qualified Data.ByteString.Char8 as B

main = do
  n <- readLn
  p <- replicateM n $ (\[a,b]->(a,b)) <$> readIntsLn
  print $ solve n p

solve n p = sum (map cnt cmp) - n where
  cmp = components grp
  grp = buildG (1, 2*10^5) $ map (\(x,y)->(x,y+10^5)) p
  cnt a = x * y where
    (x,y) = (length xs, length ys)
    (xs,ys) = partition (<=10^5) $ toList a

readIntsLn :: IO [Int]
readIntsLn
  = unfoldr (B.readInt.B.dropWhile(==' '))<$>B.getLine

Measured memory_bytes: 52604
#include <bits/stdc++.h>
using namespace std;
using  LL = long long;
LL yhaa(LL x, LL n, LL mod){
    if (n == 0){
        return 1;
    }
    if (n%2 == 0){
        LL t = (yhaa(x,n/2, mod)) % mod;//偶数の時は半分
        return (t*t) % mod;
    }
    return (x * yhaa(x, n-1, mod)) % mod;
}

LL nCk(LL n,LL k,LL m){
    int K;
    if (2*k > n){
        K  = n - k;
    }
    else{
        K = k;
    }
    LL X = 1;
    for(int i = 0; i < K;i++){
        X = (X*(n-i)) % m;
    }
    LL Y = 1;
    for(int i = 1; i < K+1; i++){
        Y = (Y*i) % m;
    }
    LL YY = yhaa(Y,1000000005,m);
    return (X*YY) % m;

}
int main(){
    int X, Y;
    cin >> X >> Y;
    int a, b;
    LL ans; 
    ans = 0;
    
    if ((X+Y) % 3 == 0){
        a = (2*X - Y) / 3;
        b = X - 2*a;
        if (a >= 0){
            if(b >= 0){
                ans = nCk(a+b,min(a,b),1000000007);
            }
        }
            
    }

    if (ans < 0){
        ans += 1000000009;
    }
    cout << ans << endl;

}


Measured memory_bytes: 3576
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)


constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;



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

	ll n, k; cin >> n >> k;
	vector<pair<int, int>> a;
	rep(i, 0, n) {
		int b, c; cin >> b >> c;
		a.emplace_back(b, c);
	}
	sort(a.begin(), a.end());

	ll num = 0;
	rep(i, 0, n) {
		num += a[i].second;
		if (num >= k) {
			cout << a[i].first << endl;
			return 0;
		}
	}
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define endl "\n"

const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

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

const int N = 1e5 + 5;

ll n, m, dp[N];
vector<ll> G[N];

ll solve(int i) {
    ll& ret = dp[i];
    if (~ret)
        return ret;

    ret = 0;
    for (auto to : G[i]) 
        ret = max(ret, solve(to) + 1);

    return ret;
}

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

    cin >> n >> m;

    for (int i = 0; i < m; ++i) {
        int x, y; cin >> x >> y;
        --x, --y;
        G[x].push_back(y);
    }

    memset(dp, -1, sizeof(dp));

    ll ans = 0;
    for (int i = 0; i < n; ++i)
        ans = max(ans, solve(i));

    cout << ans << endl;
}

Measured memory_bytes: 7936
#include<stdio.h>
int main()
{
    int i,X,Y,Z,t=0;
    scanf("%d%d%d",&X,&Y,&Z);
    t = X;
    X = Y;
    Y = t;
    t = X;
    X = Z;
    Z = t;
    printf("%d %d %d\n",X,Y,Z);
    return 0;
}


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

#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	int r;
	cin>>r;
	setprecision(5);
	r = 2*r;
	double ans = (double)3.1415*(double)r;
	cout<<ans;
}

Measured memory_bytes: 3796
//ÕÅ¼ÒÆæÔõÃ´ÓÖAKIOIÁËÑ½£¬ÔõÃ´CSPÒ²Âú·Ö°¡...ÔõÃ´Çå±±ÌìÌì¸øËû´òµç»°°¡...ÔõÃ´»áÓÐÕâÃ´Ç¿µÄÈË°¡
#include<bits/stdc++.h>
#define writeln(x)  write(x),puts("")
#define writep(x)   write(x),putchar(' ')
using namespace std;
inline int read(){
	int ans=0,f=1;char chr=getchar();
	while(!isdigit(chr)){if(chr=='-') f=-1;chr=getchar();}
	while(isdigit(chr)){ans=(ans<<3)+(ans<<1)+chr-48;chr=getchar();}
	return ans*f;
}void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
int main(){
	int x=read();
	for(int i=1;i<10;i++){
		for(int j=1;j<10;j++){
			if(i*j==x){
				puts("Yes");
				return 0;
			}
		}
	}puts("No");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pairs;

#define MOD 998244353


ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

bool primeNumber(ll n){
    if(n < 2) return false;
    else{
        for(ll i = 2; i * i <= n; i++){
            if(n % i == 0) return false;
        }
        return true;
    }
}



int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    ll count = 0;
    for(ll i = 1; i<=10000; i++){
        if(c%i == 0 && a<=i && i<=b){
            count++;
        }
        continue;
    }
    cout<<count<<endl;
    return 0;
}
 



Measured memory_bytes: 3116
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

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

typedef long long ll;

void Main()
{
    int N, M; cin >> N >> M;
    vector<int> v;
    REP(i, 2, N + 1) v.push_back(i);
    int con[15][15];
    memset(con, 0, sizeof con);
    rep(i, M)
    {
        int a, b; cin >> a >> b;
        con[a][b] = 1;
        con[b][a] = 1;
    }
    
    int res = 0;
    do {
        bool ok = true;
        rep(i, v.size())
        {
            if (i == 0) {
                if (!con[1][v[i]]) {
                    ok = false;
                }
            } else {
                if (!con[v[i - 1]][v[i]]) {
                    ok = false;
                }
            }
        }
        if (ok) ++res;
    } while(next_permutation(v.begin(), v.end()));
    cout << res << endl;
}

int main()
{
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	Main();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define debug(x) cerr << #x << " " << x << endl;
#define debug_p(x) cerr << #x << " [" << x.fi << " " << x.se << "]"<<endl;
#define debug_v(x) {cerr << #x << " "; for (auto ioi : x) cerr << ioi << " "; cerr << endl;}
#define debug_vp(x) {cerr << #x << " "; for (auto ioi : x) cerr << '[' << ioi.fi << " " << ioi.se << ']'; cerr << endl;}
#define debug_v_v(x) {cerr << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cerr << ioi2 << " "; cerr << '\n';} cerr << "*/" << #x << endl;}
#define gen_clock(x) ll x = clock(); cerr << "Clock " << #x << " created" << endl;
#define check_clock(x) cerr << "Time spent in " << #x << ": " << (double)(clock() - x)/CLOCKS_PER_SEC << endl; x = clock();
#define reset_clock(x) x = clock()
 
const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
 
void solve()
{
	ll x;
	cin>>x;
	if(x>=30)
	cout<<"Yes";
	else
	cout<<"No";
}
 
int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 3608
n,x,m=map(int,input().split())
order=[-1 for i in range(m)] #-1のところにはまだ対応する余りがない、余りは高々m通り
index=0 #何番目に出た余りなのかを示す
a=[] #数列
while order[x]==-1: #ループが完成するまでは
  order[x]=index #xはindex番目の余り
  a.append(x)
  x=(x**2)%m
  index+=1
tmp=sum(a[order[x]:index]) #1ループの和、xがループの始点の余り
t=index-order[x] #1ループの長さ
if n-1<order[x]: #ループが完成しない場合
  print(sum(a[:n]))
else:
  sum1=sum(a[:order[x]]) #ループの前の和
  x1=n-order[x] #ループ部分の長さ
  n1=x1//t #ループの回数
  n2=x1%t
  print(sum1+n1*tmp+sum(a[order[x]:order[x]+n2]))

Measured memory_bytes: 13644
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;

int main(){
    int a,b;
    cin >> a >> b;
    int n;
    if(b>99){
        n=a*1000+b;
    }
    else if(b>9){
        n=a*100+b;
    }
    else{
        n=a*10+b;
    }

    for(int i=1;i*i<=n;i++){
        if(i*i==n){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rrep(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
//using ll=long long;
const int MX = 2200000;
//const ll LINF = 1000000000000000000ll;
//const long long MOD = 1000000007;
//long long INF = 90000000001000;
int w,h;
bool seen[50][50];
int c[50][50];
int d[2]={1,-1};
void dfs(int i,int j){
    seen[i][j]=true;
    for (int k = 0; k < 2; ++k)
    {
       if (!seen[i+d[k]][j]&&i+d[k]<h&&i+d[k]>=0&&c[i+d[k]][j])dfs(i+d[k],j);
       if (!seen[i][j+d[k]]&&j+d[k]<w&&j+d[k]>=0&&c[i][j+d[k]])dfs(i,j+d[k]);
       if (!seen[i+d[k]][j-d[k]]&&i+d[k]<h&&i+d[k]>=0&&j-d[k]>=0&&j-d[k]<w&&c[i+d[k]][j-d[k]])dfs(i+d[k],j-d[k]);
       if (!seen[i+d[k]][j+d[k]]&&i+d[k]<h&&i+d[k]>=0&&j+d[k]<w&&j+d[k]>=0&&c[i+d[k]][j+d[k]])dfs(i+d[k],j+d[k]); 
    }

}


int main(){


while(1){
cin >> w >> h;
if(w==0&&h==0) break;
for (int i = 0; i < h; ++i)
{
   for (int j = 0; j < w; ++j)
   {
       cin >> c[i][j];
       seen[i][j]=false;
   }
}
int cnt=0;
for (int i = 0; i < h; ++i)
{
  for (int j = 0; j < w; ++j)
  {
    if(c[i][j]==1&&!seen[i][j]){cnt++;dfs(i,j);}
  }
}
cout << cnt << endl;
}

return 0;

}


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

using namespace std;

#define FaSt ios::sync_with_stdio(0),cin.tie(0);
#define random uniform_int_distribution<long long>(1, 2000000000000000LL)(rng)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count() * ((uint64_t) new char | 1));

const int N = 100005, M = 1e9 + 7;
int n, a[N];
long long ans;

int main() 
{
    FaSt
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        char c;
        cin >> c;
        a[(int)c]++;
        long long mul = 1;
        for (char j = 'a'; j <= 'z'; j++)
        {
            if (j == c) continue;
            mul = (mul * (a[(int)j] + 1)) % M;
        }
        ans = (ans + mul) % M;
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(long long i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n,maxi=0; cin>>n;
    bool can=true;
    for(int i=0;i<n;i++){
        ll a; cin>>a;
        if(a < maxi-1) can=false;
        maxi=max(maxi,a);
    }
    if(can) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3640
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		solve(S, T);
	}

	private static void solve(String s, String t) {
		// TODO Auto-generated method stub
		int n = t.length(), l = s.length();
		List<String> subs = new ArrayList<String>();
		for (int i = 0; i <= l - n; i++) {
			subs.add(s.substring(i, i + n));
		}
//		System.out.println(subs.toString());
		int gm = Integer.MAX_VALUE;
		for (String ss : subs) {
			int lm = 0;
			for (int i = 0; i < ss.length(); i++) {
				if (ss.equals(t)) {
					System.out.println(0);
					return;
				} else if (ss.charAt(i) != t.charAt(i)) {
					lm++;
				}
			}
			gm = Math.min(gm, lm);
		}
		System.out.println(gm);
	}

}


Measured memory_bytes: 27828
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<string>
#include<vector>
#include<functional>
using namespace std;
typedef long long lint;
typedef complex<double>Point;
typedef vector<Point>Polygon;
namespace std{
    bool operator<(const Point &P,const Point &Q){
        return real(P)!=real(Q)?real(P)<real(Q):imag(P)<imag(Q);
    }
}
const double EPS=1e-8;
const double INF=1e12;

struct Line:Polygon{
    Line(const Point &P,const Point &Q){
        push_back(P);push_back(Q);
    }
    Line(){}
};

struct Circle{
    Point P;
    double r;
    Circle(const Point &_P,double _r):P(_P),r(_r){}
    Circle(){}
};

double dot(const Point &P,const Point &Q){
    return real(P)*real(Q)+imag(P)*imag(Q);
}

double cross(const Point &P,const Point &Q){
    return real(P)*imag(Q)-real(Q)*imag(P);
}

int ccw(Point A,Point B,Point C){
    B-=A;C-=A;
    if(cross(B,C)>0)return 1; //???????¨???????
    if(cross(B,C)<0)return -1; //????¨???????
    if(dot(B,C)<0)return 2; //c-b-a
    if(norm(B)<norm(C))return -2; //a-b-c
    return 0; //a-c-b
}

bool inrersectSS(const Line &S,const Line &T){
    Point a=S[0],b=S[1],c=T[0],d=T[1];
    return ccw(a,b,c)*ccw(a,b,d)<=0&&
        ccw(c,d,a)*ccw(c,d,b)<=0;
}

double getPolygonS(Polygon &g){
    double sum=0;
    for(int i=0;i<g.size();i++){
        int a=i,b=(i+1)%g.size();
        sum+=cross(g[a],g[b]);
    }
    sum=abs(sum)*0.5;
    return sum;
}
int main(){
    double x,y;
    Polygon g;
    while(scanf("%lf,%lf",&x,&y)!=EOF)g.push_back(Point(x,y));
    printf("%f\n",getPolygonS(g));


    return 0;
}

Measured memory_bytes: 1236
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		int x, y;
		Scanner sc = new Scanner(System.in);
		x = sc.nextInt();
		y = sc.nextInt();
		sc.close();
		int px = 0, py = 0;
		int g[][] = { { 1, 3, 5, 7, 8, 10, 12}, { 4, 6, 9, 11, 0, 0, 0}, { 2, 0, 0, 0, 0, 0, 0}};
		for(int i = 0; i < 3; ++i) {
			for(int j = 0; j < 7; ++j) {
				if(x == g[i][j])px = i;
				if(y == g[i][j])py = i;
			}
		}
		
		if(px == py)System.out.println("Yes");
		else System.out.println("No");
	}
}


Measured memory_bytes: 22484
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=1e5+50;
const int mod=1e9+7;
using namespace std;
int n,m,i,l,r,j;
ll c,st[4*nmax];
vector<pair<int,ll> >a[nmax];
void build(int nod,int l,int r)
{
	if(l==r)
	{
		if(l!=1)st[nod]=llinf;
		else st[nod]=0;
		return;
	}
	int mid=(l+r)/2;
	build(2*nod,l,mid);
	build(2*nod+1,mid+1,r);
	st[nod]=min(st[2*nod],st[2*nod+1]);
}
void upd(int x,int l,int r,int p,ll v)
{
	if(l==r)
	{
		st[x]=min(st[x],v);
		return;
	}
	int mid=(l+r)/2;
	if(p<=mid)upd(2*x,l,mid,p,v);
	else upd(2*x+1,mid+1,r,p,v);
	st[x]=min(st[2*x],st[2*x+1]);
}
ll qry(int x,int l,int r,int tl,int tr)
{
	if(tl>r || l>tr)return llinf;
	if(tl<=l && r<=tr)return st[x];
	int mid=(l+r)/2;
	return min(qry(2*x,l,mid,tl,tr),qry(2*x+1,mid+1,r,tl,tr));
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n>>m;
	for(i=1;i<=m;i++)
	{
		cin>>l>>r>>c;
		a[l].pb(mkp(r,c));
	}
	build(1,1,n);
	for(i=1;i<=n;i++)
	{
		for(j=0;j<(int)a[i].size();j++)
		{
			r=a[i][j].fr,c=a[i][j].sc;
			upd(1,1,n,r,qry(1,1,n,i,r-1)+c);
		}
	}
	if(qry(1,1,n,n,n)==llinf)cout<<-1<<endl;
	else cout<<qry(1,1,n,n,n)<<endl;
	return 0;
}


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

int n,m,q;
int a[50],b[50],c[50],d[50];
int process();
int process_sub(int ps);
int ch();
int A[13];

int main()
{
    scanf("%d %d %d",&n,&m,&q);

    int i;

    for(i=0;i<q;i++)
        scanf("%d %d %d %d",&a[i],&b[i],&c[i],&d[i]);

    int max = process();
    printf("%d\n",max);

    return 0;
}

int process()
{
    int i;
    int ps = 0;
    int max=0,ans;

    for(i=1;i<=m;i++)
    {
        A[0] = i;
       ans =  process_sub(ps+1);
        if(max < ans)
            max = ans;
    }

    return max;
}

int process_sub(int ps)
{
    int max=0,ans;
    if(ps == n)
    {
        ans = ch();
        return ans;
    }

    int i;

    for(i = A[ps-1]; i<=m;i++)
    {
        A[ps] = i;
        ans = process_sub(ps+1);
        if(max < ans)
            max = ans;
    }

    return max;
}

int ch()
{
    int i;

    int sum_d = 0;

    for(i=0;i<q;i++)
    {
        if(A[b[i]-1] - A[a[i]-1] == c[i])
            sum_d += d[i];
    }

    

    return sum_d;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define pb(a) push_back(a)
#define rd(a) cin>>(a)
#define RD(a,b) cin>>(a)>>(b)
#define pr(a) cout<<(a)<<endl
#define PR(a,b) cout<<(a)<<" "<<(b)<<endl
#define F first
#define S second
#define ll long long
bool check(int n,int m,int x,int y){return (x<0||x>=n||y<0||y>=m)?false:true;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
typedef pair<int,int> P;

int main() {
  int M=3000010;
  bool b[M];
  fill(b,b+M,true);
  fill(b,b+6,false);
  vector<int> v;
  for(int i=7; i<M-5; i+=7) {
    if(b[i-1]) {
      int k=i-1;
      v.pb(k);
      for(int j=k*2; j<M; j+=k) b[j]=false;
    }
    if(b[i+1]) {
      int k=i+1;
      v.pb(k);
      for(int j=k*2; j<M; j+=k) b[j]=false;
    }
  }
  int x;
  while(cin >> x && x>1) {
    cout << x << ":";
    rep(i,v.size()) {
      if(x%v[i]==0) cout << " " << v[i];
      if(v[i]>=x) break;
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 5960
#include<iostream>
#include<algorithm>
#include<sstream>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
using namespace std;
#define rep(i, j) for(int i = 0; i < j; i++)
#define f(i, k, j) for(int i = k; i < j; i++)
const int INF = (1 << 26);

int main(){
    int n;
    while(cin >>n && n){
        map<string, string> con;
        stringstream ss;
        rep(i, n){
            string a, b; cin >>a >>b;
            con[a] = b;
        }
        int m; cin >>m;
        rep(i, m){
            string a; cin >>a;
            if(con.find(a) != con.end()) ss <<con[a];
            else ss <<a;
        }
        cout <<ss.str() <<endl;
    }
    return 0;
}

Measured memory_bytes: 1356
# coding: utf-8
#s = [[[0]*10]*3]*4
s =[[[0]*10 for i in range (0,3)] for k in range (0,4)]
n = int(input())
for i in range(n):
    b, f, r, v = map(int, input().split())
    s[b-1][f-1][r-1] += v
for i in range(4):
    for j in range(3):
        for k in range(10):
            print(" {}".format(s[i][j][k]) , end = "")
        print()     
        
    if i < 3:
        print("#"*20)



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

int n;

int main() {
    cin >> n;
    int n_ac = 0, n_wa = 0, n_tle = 0, n_re = 0;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        if (s == "AC") n_ac++;
        else if (s == "WA") n_wa++;
        else if (s == "TLE") n_tle++;
        else n_re++;
    }

    cout << "AC x " << n_ac << endl;
    cout << "WA x " << n_wa << endl;
    cout << "TLE x " << n_tle << endl;
    cout << "RE x " << n_re << endl;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;


void solve(long long N, std::vector<long long> H){
    int ans =0;
    int count=0;
    int preh = H[0];
    for(int i=1;i<N;i++){
        if(preh >= H[i]){
            count++;
            preh=H[i];
        }
        else{
            ans = max(ans, count);
            count = 0;
            preh = H[i];
        }
    }
    ans = max(ans,count);
    cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> H(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&H[i]);
    }
    solve(N, std::move(H));
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 1000010;
const int MAXK = 510;
const int MAXQ = 200010;

int n, k, d[MAXN];
vector<int> a[MAXN];
ll rev[MAXN], f[MAXN], res;

ll mu(ll a, ll b) {
    if (b == 0) return 1;
    if (b == 1) return a % MODBASE;
    ll g = mu(a, b/2);
    if (b % 2) return g * g % MODBASE * a % MODBASE;
    return g * g % MODBASE;
}

ll P(int n, int k) {
    if (k < 0 || k > n) return 0;
    return f[n] * rev[n-k] % MODBASE;
}

void dfs(int u, int p) {
    int cnt = 0;
    FOR(i,0,SZ(a[u])-1) {
        int v = a[u][i];
        if (v == p) continue;
        cnt++;
    }
    if (d[u] == 0) {
        res = res * P(k-1, cnt) % MODBASE;
    }
    else {
        res = res * P(k-2, cnt) % MODBASE;
    }
    FOR(i,0,SZ(a[u])-1) {
        int v = a[u][i];
        if (v == p) continue;
        d[v] = d[u] + 1;
        dfs(v, u);
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    f[0] = 1;
    rev[0] = mu(f[0], MODBASE - 2);
    FOR(i,1,100000) {
        f[i] = f[i-1] * i % MODBASE;
        rev[i] = mu(f[i], MODBASE - 2);
    }
    cin >> n >> k;
    FOR(i,1,n-1) {
        int u, v;
        cin >> u >> v;
        a[u].emplace_back(v);
        a[v].emplace_back(u);
    }
    res = k;
    dfs(1, 0);
    cout << res;
    return 0;
}


Measured memory_bytes: 13568
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <numeric>
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vi = vector <int>;

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

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

    int n, m; cin >> n >> m;
    int k[m];
    int s[m];
    REP(i, m) {
        cin >> k[i];
        s[i] = 0;
        REP(j, k[i]) {
            int tmp; cin >> tmp;
            s[i] |= (1 << (tmp-1));
        }
    }
    int p[m];
    REP(i, m) {
        cin >> p[i];
    }

    int cnt = 0;
    REP(bit, (1 << n)) {
        bool flag = true;
        REP(i, m) {
            if (__builtin_popcount(bit & s[i])%2 != p[i]) {
                flag = false;
                break;
            }
        }
        if (flag) cnt++;
    }
    cout << cnt << "\n";
}

Measured memory_bytes: 3592
N, K = map(int, input().split())
L=[]
R=[]
for i in range(K):
  l,r= map(int, input().split())
  L.append(l)
  R.append(r)

dp=[0]*N
dp[0]=1
dpc=[0]*(N+1)
dpc[1]=1

for i in range(N):
  for j in range(K):
    dp[i]+=dpc[max(i-L[j]+1,0)]-dpc[max(i-R[j],0)]
  dp[i]%=998244353
  dpc[i+1]=dpc[i]+dp[i]

print(dp[N-1])

Measured memory_bytes: 76244
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

immutable int INF = 1 << 29;

void main() {
    auto s = readln.split.map!(to!int);
    auto H = s[0];
    auto W = s[1];
    auto B = H.iota.map!(_ => readln.chomp).array;

    auto source = H + W;
    auto sink = H + W + 1;
    auto FF = new FordFulkerson(H + W + 2, source, sink);
    int r1, c1, r2, c2;

    foreach (i; 0..H) {
        foreach (j; 0..W) {
            if (B[i][j] == 'S') {
                FF.add_edge(source, i, INF);
                FF.add_edge(source, H + j, INF);
                r1 = i;
                c1 = j;
            } else if (B[i][j] == 'T') {
                FF.add_edge(i, sink, INF);
                FF.add_edge(H + j, sink, INF);
                r2 = i;
                c2 = j;
            } else if (B[i][j] == 'o') {
                FF.add_edge(i, H + j, 1);
                FF.add_edge(H + j, i, 1);
            }
        }
    }

    writeln( (r1 == r2 || c1 == c2) ? -1 : FF.run );
}

class FordFulkerson {
    int N, source, sink;
    int[][] adj;
    int[][] flow;
    bool[] used;

    this(int n, int s, int t) {
        N = n;
        source = s;
        sink = t;
        assert (s >= 0 && s < N && t >= 0 && t < N);
        adj = new int[][](N);
        flow = new int[][](N, N);
        used = new bool[](N);
    }

    void add_edge(int from, int to, int cap) {
        adj[from] ~= to;
        adj[to] ~= from;
        flow[from][to] = cap;
    }

    int dfs(int v, int min_cap) {
        if (v == sink)
            return min_cap;
        if (used[v])
            return 0;
        used[v] = true;
        foreach (to; adj[v]) {
            if (!used[to] && flow[v][to] > 0) {
                auto bottleneck = dfs(to, min(min_cap, flow[v][to]));
                if (bottleneck == 0) continue;
                flow[v][to] -= bottleneck;
                flow[to][v] += bottleneck;
                return bottleneck;
            }
        }
        return 0;
    }

    int run() {
        int ret = 0;
        while (true) {
            foreach (i; 0..N) used[i] = false;
            int f = dfs(source, int.max);
            if (f > 0)
                ret += f;
            else
                return ret;
        }
    }
}


Measured memory_bytes: 892
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	ll n, h;
	cin>>n>>h;
	ll mx = 0;
	vector<ll> b(n);
	rep(i, n){
		ll a;
		cin>>a>>b[i];
		chmax(mx, a);
	}
	sort(all(b));
	ll res = 0;
	while(h>0&&!b.empty()){
		ll t = b.back();
		if(t<=mx) break;
		res++;
		h -= t;
		b.pop_back();
	}
	if(h>0) res += (h+mx-1)/mx;
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int Asigma(int x){
  if(x < 10) return x;
  return x%10 + Asigma(x/10);
}


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

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

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 200'000;
const int LOGN = 18;

int n, m, k;

void solve(int test)
{
  cin >> n >> k;
  if (k > (n - 1) * (n - 2) / 2) {
    cout << "-1\n";
    return;
  }
  vector<pair<int, int>> ans;
  for (int i = 1; i < n; ++i) {
    ans.emplace_back(i, n);
  }
  int pairs = (n - 1) * (n - 2) / 2;
  int last = n - 1;
  int first = last - 1;
  while (pairs > k) {
    --pairs;
    ans.emplace_back(first, last);
    --first;
    if (first == 0) {
      --last;
      first = last - 1;
    }
  }
  cout << ans.size() << '\n';
  for (auto& pr : ans) {
    cout << pr.first << ' ' << pr.second << '\n';
  }
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
    solve(i);
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

template<typename T>
vector<vector<T>> Make2DVector(int d1, int d2, T default_value) {
  return vector<vector<T>>(d1, vector<T>(d2, default_value));
}

// Vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  s << "[";
	for (int i = 0; i < len; i++) {
    if (i > 0) s << ", ";
		s << v[i];
  }
  s << "]";
  return s;
}

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

  string s;
  cin >> s;
  vector<int> xs;
  for (char c : s) xs.push_back(c - 'a');

  int n = xs.size();
  auto dp = Make2DVector(n, 26, n);
  dp[n - 1][xs[n - 1]] = n - 1;
  for (int i = n - 2; i >= 0; i--) {
    for (int j = 0; j < 26; j++) {
      dp[i][j] = dp[i + 1][j];
    }
    dp[i][xs[i]] = i;
  }

  vector<int> prevs(n, -2);
  vector<int> path;

  auto dump_path_fn = [&](int k) {
    while (k >= 0) {
      // cout << "k: " << k << endl;
      path.push_back(xs[k]);
      k = prevs[k];
    }
    reverse(path.begin(), path.end());
  };

  deque<int> q;
  q.push_back(-1);
  vector<int> visited(n);
  while (!q.empty()) {
    int i = q.front();
    q.pop_front();
    if (i + 1 >= n) {
      dump_path_fn(i);
      path.push_back(0);
      break;
    }
    for (int j = 0; j < 26; j++) {
      int k = dp[i + 1][j];
      if (k >= n) {
        dump_path_fn(i);
        path.push_back(j);
        break;
      }

      if (visited[k]) continue;
      prevs[k] = i;
      q.push_back(k);
      visited[k] = 1;
    }
    if (!path.empty()) break;
  }

  // cout << path << endl;

  for (int x : path) {
    cout << static_cast<char>('a' + x);
  }
  cout << endl;
}


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

int main() {
  int N;
  cin >> N;
  int A, B;
  cin >> A >> B;
  vector<int> pi(N);
  int i;
  for (i=0;i<N;i++){
    cin >> pi.at(i);
  }

  int cat1=0, cat2=0, cat3=0;
  for (i=0;i<N;i++){
    if (pi.at(i) <= A){
      cat1++;
    } else if (pi.at(i)>B){
      cat3++;
    } else {
      cat2++;
    }
  }

  cout << min(cat1, min(cat2, cat3)) << endl;
}

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

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> c(n);
  for(Int i=0;i<n;i++) cin>>c[i];
  
  vector<vector<Int> > G(n);
  for(Int i=1;i<n;i++){
    Int x,y;
    cin>>x>>y;
    x--;y--;
    G[x].emplace_back(y);
    G[y].emplace_back(x);
  }
  
  const Int INF = 1e9;
  Int ans=-INF;
  vector<Int> dp1(n,-INF),dp2(n,-INF),dp3(n,-INF);
  
  function<void(Int, Int)> dfs=
    [&](Int v,Int p){
      for(Int u:G[v]) if(u!=p) dfs(u,v);
      
      Int res=0;
      vector<Int> w;
      for(Int u:G[v]){
	if(u==p) continue;
	res+=max(0LL,dp2[u]-2);
	w.emplace_back((dp1[u]-1)-max(0LL,dp2[u]-2));	
      }
	
      for(Int u:G[v]){
	if(u==p) continue;
	chmax(dp1[v],c[v]+res+(dp1[u]-1)-max(0LL,dp2[u]-2));
	chmax(dp3[v],c[v]+res+(dp3[u]-2)-max(0LL,dp2[u]-2));
      }
      sort(w.rbegin(),w.rend());
      
      chmax(dp1[v],c[v]+res);
      chmax(dp2[v],c[v]+res);      
      if(w.size()>1u) chmax(dp3[v],c[v]+res+w[0]+w[1]);

      chmax(ans,dp1[v]);
      chmax(ans,dp2[v]);
      chmax(ans,dp3[v]);      
    };
  
  dfs(0,-1);
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 27160
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define reverse(x) reverse(x.begin(), x.end())
#define sort(x) sort(x.begin(), x.end())
#define pb push_back
#define pii pair<int, int>
#define pll pair<long long,long long>
#define f first
#define s second
typedef long long ll;
const ll mod = 1e9+7;
using namespace std;

ll modpow(ll a, ll b, ll m) {
	ll p = 1, q = a;
	for (int i=0;i<32;i++) {
		if((b / (1LL << i)) % 2 == 1) { p *= q; p %= m; }
		q *= q; q %= m;
	}
	return p;
}

ll Div(ll a, ll b, ll m) {
	return (a * modpow(b, m - 2, m)) % m;
}

ll ncr(ll n, ll r) {
	if (n < r || r < 0) return 0;
	ll rem = 1;
	for (ll i = n - r + 1; i <= n; i++) { rem *= i; rem %= mod; }
	for (int i = 1; i <= r; i++) rem = Div(rem, i, mod);
	return rem;
}

int main(){
	ll N, A, B;
	cin >> N >> A >> B;

	ll V1 = modpow(2, N, mod); V1 = (V1 + mod - 1LL) % mod;
	ll V2 = ncr(N, A);
	ll V3 = ncr(N, B);
	cout << (V1 - V2 - V3 + mod * mod) % mod << endl;
	return 0;

}


Measured memory_bytes: 256
/*
	##############################
	## Author: Pratyush Gaurav ###
	## College: NIT ROURKELA #####
	##############################
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long/*--------------------*/lli;
typedef long double/*------------------*/ld;
typedef unsigned long long/*-----------*/ulli;
typedef pair<lli, lli >/*--------------*/plli;
typedef vector<plli >/*----------------*/vplli;

#define rep(i,a)/*---------------------*/for(i = 0 ; i < a ; i++)
#define repr(i,a)/*--------------------*/for(i = a ; i >= 0 ; i--)
#define REP(i,a,b)/*-------------------*/for(i = a ; i <= b ; i++)
#define REPR(i,a,b)/*------------------*/for(i = a ; i >= b ; i--)

#define scan(N)/*----------------------*/scanf("%lld",&N)
#define print(N)/*---------------------*/printf("%lld",N)
#define scan2(N1,N2)/*-----------------*/scanf("%lld %lld",&N1,&N2)
#define print2(N1,N2)/*----------------*/printf("%lld %lld",N1,N2)
#define scan3(N1,N2,N3)/*--------------*/scanf("%lld %lld %lld",&N1,&N2,&N3)
#define print3(N1,N2,N3)/*-------------*/printf("%lld %lld %lld",N1,N2,N3)

#define lb/*---------------------------*/lower_bound
#define ub/*---------------------------*/upper_bound
#define pb/*---------------------------*/push_back
#define popb/*-------------------------*/pop_back

#define mem(a,b)/*---------------------*/memset(a,b,sizeof(a))
#define opt/*--------------------------*/ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sz/*---------------------------*/size()

#define MP/*---------------------------*/make_pair
#define bs/*---------------------------*/binary_search
#define gcd(a, b)/*--------------------*/__gcd(a, b)
#define lcm(a, b)/*--------------------*/((a)*((b)/gcd(a,b)))
#define sqr(x)/*-----------------------*/(x)*(x)
#define all(a)/*-----------------------*/a.begin(),a.end()

#define ff/*---------------------------*/first
#define ss/*---------------------------*/second

#define endl/*-------------------------*/'\n'
#define inf/*--------------------------*/(lli)2000000000000
#define MOD/*--------------------------*/(lli)1000000007
#define MAXN/*-------------------------*/100005

template<class T> bool is_prime(T n)
{
	if((n%2 == 0 and n > 2) or n < 2 )
		return false;
	for(T i = 3; i*i <= n ; i += 2)
	{
		if( n % i == 0)
			return false;
	}
	return true;
}
lli power(lli a,lli b)
{
    lli value;
    if(!b)
    	return 1;
    else if(b%2==0)
    {
        value = power(a,b/2)%MOD;
        return (value * value)%MOD;
    }
    else
    {
        value = power(a,b/2)%MOD;
        return ((a*value)%MOD*(value))%MOD;
    }
}

int main()
{
	opt;
	lli n;
	cin >> n;
	lli dp[n+1];
	dp[0] = 2;
	dp[1] = 1;
	lli i;
	REP(i,2,n)
        dp[i] = dp[i-1] + dp[i-2];
    cout << dp[n] << endl;
	return 0;
}










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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<char, int>;

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

const int INF = 1e18;
const int MOD = 1e9 + 7;

signed main(){
    int N, M; cin >> N >> M;
    priority_queue<int> pq;
    REP( i, N ){
        int a; cin >> a;
        pq.push( a );
    }

    REP( i, M ){
        int t = pq.top() / 2; pq.pop();
        pq.push( t );
    }

    int ans = 0;
    REP( i, N ){
        ans += pq.top(); pq.pop();
    }

    cout << ans << endl;
}


Measured memory_bytes: 1400
#include <stdio.h>
#include <string.h>

int main (void) {
    char s[3];
    int i, ans = 0;
    scanf("%s", s);
    if (!strcmp(s, "RRR")) printf("3\n");
    else if (s[0] == 'R' && s[1] == 'R') printf("2\n");
    else if (s[1] == 'R' && s[2] == 'R') printf("2\n");
    else if (!strcmp(s, "SSS")) printf("0\n");
    else printf("1\n");
    return 0;
}

Measured memory_bytes: 1656
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    long long a[5],b[5];
    long long maxn=-1000000000000000000;
    long long ans;
    int i,j;
    while(~scanf("%lld%lld%lld%lld",&a[0],&a[1],&b[0],&b[1]))
    {
        for(i=0;i<2;i++)
        {
            for(j=0;j<2;j++)
            {
                ans=a[i]*b[j];
                maxn=max(maxn,ans);
            }
        }
        printf("%lld\n",maxn);
    }
}


Measured memory_bytes: 1732
//killer_R@$tog!
#include<bits/stdc++.h>
using namespace std;
#define hell 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)
#define mp make_pair
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define ll long long int
#define N 1000009
#define all(b) b.begin(),b.end()
#define sz sizeof
#define shuru(h) memset(h,0,sz(h))
vector<ll>adj[N];bool vis[N];ll ans;ll dp[N][2];
void dfs(int v,int p)
{
    vis[v]=true;
    ll a=1,b=1;
    for(auto x:adj[v])
    {
        if(!vis[x])
        {
            dfs(x,v);
            a=(a*(dp[x][0]+dp[x][1])%hell)%hell;
            b=(b*(dp[x][0])%hell);
        }
    }
    dp[v][0]=a;dp[v][1]=b;return;
}


void killer()
{
    ll n;cin>>n;ans=0;shuru(dp);
    if(n==1){cout<<"2";return;}
    rep(i,0,n-1)
    {
        ll x,y;cin>>x>>y;
        adj[x].pb(y);adj[y].pb(x);
    }
    rep(i,1,n+1)
    {
        if(!vis[i])dfs(i,0);
    }
    //rep(i,0,n+1)cout<<dp[i][0]<<" "<<dp[i][1]<<endl;
    ans=(ans+(dp[1][0]+dp[1][1])%hell)%hell;
    cout<<ans;
    return;
}
int main()
{
    ll t;
    t=1;
    while(t--)
        killer();

    return 0;
}

Measured memory_bytes: 50304
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vv;
typedef pair<int,ll> P;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
bool is(int x,int y){return 0<=x&&x<4&&0<=y&&y<4;}
inline ll toll(vv b){
	ll x=0;
	rep(i,4) rep(j,4) x=x*8+b[i][j];
	return x;
}
inline vv tovv(ll x){
	vv b(4,vi(4,0));
	rep(i,4) rep(j,4){
		b[3-i][3-j]=x%8;
		x/=8;
	}
	return b;
}
int main(){
	ll s=0;
	rep(i,4) rep(j,4){
		ll x;
		cin>>x;
		s=s*8+x;
	}
	if(s==0){
		puts("0");
		return 0;
	}
	queue<P> que;
	que.push(P(0,s));
	while(!que.empty()){
		P p=que.front();
		que.pop();
		if(p.fs>=5){
			puts("-1");
			return 0;
		}
		vv b=tovv(p.sc);
		rep(i,4) rep(j,4){
			vv nb=b;
			if(nb[i][j]==0) continue;
			nb[i][j]++;
			if(nb[i][j]==5){
				vv waters;
				rep(d,4) waters.pb(vi{i,j,d});
				while(!waters.empty()){
					vv nwaters;
					for(vi w:waters){
						int x=w[0],y=w[1],d=w[2];
						int nx=x+dx[d],ny=y+dy[d];
						if(!is(nx,ny)) continue;
						if(nb[nx][ny]==0){
							nwaters.pb(vi{nx,ny,d});
							continue;
						}else{
							nb[nx][ny]++;
							if(nb[nx][ny]==5){
								rep(di,4) nwaters.pb(vi{nx,ny,di});
							}
						}
					}
					waters=nwaters;
					rep(e,4) rep(f,4) if(nb[e][f]>=5) nb[e][f]=0;
				}
			}
			ll nx=toll(nb);
			if(nx==0){
				cout<<p.fs+1<<endl;
				return 0;
			}
			que.push(P(p.fs+1,nx));
		}
	}
	assert(0);
}

Measured memory_bytes: 18284
class UnionFind(n: Int) {
    private val parent = IntArray(n, {-1})
    private val rank = IntArray(n, {0})
    private val size = IntArray(n, {1})
    private var numTree = n

    fun find(x: Int): Int {
        if (parent[x] == -1) {
            return x
        } else {
            parent[x] = find(parent[x])
            return parent[x]
        }
    }

    fun isSame(x: Int, y: Int): Boolean {
        return find(x) == find(y)
    }

    fun getSize(): Int {
        return numTree
    }

    fun sizeOf(x: Int): Int {
        return size[find(x)]
    }

    fun rankOf(x: Int): Int {
        return rank[find(x)]
    }

    fun unite(x: Int, y: Int) {
        val parentX = find(x)
        val parentY = find(y)

        if (parentX == parentY) {
            return
        }

        numTree--

        if (rank[parentX] < rank[parentY]) {
            parent[parentX] = parentY
            size[parentY] += size[parentX]
        } else {
            parent[parentY] = parentX
            size[parentX] += size[parentY]
            if (rank[parentX] == rank[parentY]) {
                rank[parentX]++
            }
        }
    }
}

fun main(args: Array<String>) {
    val (N, M, K) = readInputLine().split(" ").map { it.toInt() }
    val unionFind = UnionFind(N)

    val friends = Array(N) { mutableSetOf<Int>() }
    val blocks = Array(N) { mutableSetOf<Int>() }

    for (i in 0 until M) {
        val (a, b) = readInputLine().split(" ").map { it.toInt() - 1 }
        friends[a].add(b)
        friends[b].add(a)
        unionFind.unite(a, b)
    }

    for (i in 0 until K) {
        val (c, d) = readInputLine().split(" ").map { it.toInt() - 1 }
        blocks[c].add(d)
        blocks[d].add(c)
    }

    val ans = IntArray(N)

    for (i in 0 until N) {
        var ansTmp = unionFind.sizeOf(i) - 1
        ansTmp -= friends[i].size
        for (b in blocks[i]) {
            if (unionFind.isSame(i, b)) {
                ansTmp--
            }
        }
        ans[i] = ansTmp
    }

    println(ans.joinToString(" "))
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 152900
d,m[];main(h,X,Y,S,x){for(;~scanf("%d,%d,%d",&X,&Y,&S);)for(x=100;x--;)hypot(x%10-X,x/10-Y)*2<=S+1?h-=!m[x],d=fmax(++m[x],d):0;d=!printf("%d\n%d\n",99+h,d);}

Measured memory_bytes: 0
n,m=map(int,input().split())
ab=[[0,0] for i in range(m)]
for i in range(m):
    ab[i][0],ab[i][1]=map(int,input().split())

import sys
sys.setrecursionlimit(10**9) #再帰の上限をあげる

root=[-1 for i in range(n+1)] #自分が親なら自身の番号を、そうでないなら（元）親の番号を示す
def r(x):   #親は誰？
    if root[x]<0:
        return x
    else:
        root[x]=r(root[x])
        return root[x]


ans=n*(n-1)//2
d=[n*(n-1)//2]
for i in range(1,m+1):
    a,b=ab[-i][0],ab[-i][1]
    a=r(a)
    b=r(b)
    a,b=min(a,b),max(a,b)
    if a!=b:
        ans-=root[a]*root[b]
        root[a]+=root[b]
        root[b]=a
    d.append(ans)

for i in range(m):
    print(d[-2-i])


Measured memory_bytes: 94520
// Copyright 2019 yaito3014
#include "bits/stdc++.h"
using namespace std;
using namespace literals;

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

int64_t lcm(int64_t a, int64_t b) {
  return a / gcd(a, b) * b;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int64_t> a(N);
  for (auto& v : a)cin >> v;
  int64_t l = a[0] / 2;
  for (int i = 1; i < N; ++i) l = lcm(l, a[i] / 2);
  bool all_odd = true;
  for (int i = 0; i < N; ++i) {
    if (l / (a[i] / 2) % 2 == 1)continue;
    all_odd = false;
    break;
  }
  if (all_odd)
    cout << (M + l) / (l * 2) << endl;
  else
    cout << 0 << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int inf = 1001001001;

int main(){
  rep(i,5) {
      int x;
      cin >> x;
      if(x == 0) {
          cout << i+1 << endl;
          break;
      }
  }
}

Measured memory_bytes: 3592