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

int main() {
  int A;
  int B;
  int H;
  int M;
  cin>>A>>B>>H>>M;
  double kaku=3.141592653589793238462643*(11*M-60*H)/360;
  double kosain=cos(kaku);
  double nagasanonizyou=A*A+B*B-2*A*B*kosain;
  double nagasa=sqrt(nagasanonizyou);
    cout << fixed << setprecision(11);
  cout<<nagasa<<endl;
  
}



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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin() x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin() x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

struct Union_Find {
	vector<int> par;
	vector<int> rank;
	vector<ll> nnum;

	Union_Find(int n) : par(n), rank(n), nnum(n){
		for(int i=0; i<n; i++){
			par[i] = i;
			rank[i] = 0;
			nnum[i] = 1;
		}
	}

	int root(int x){
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	bool same(int x, int y){
		return root(x) == root(y);
	}

	void unite(int x, int y){
		int rx = root(x);
		int ry = root(y);
		if (rx == ry) return;
		if (rank[rx]<rank[ry]) swap(rx, ry);
		par[ry] = rx;
		rank[rx]++;
		nnum[rx] += nnum[ry];
	}

	ll nodes(int x){
		return nnum[root(x)];
	}
};

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m; cin >> n >> m;
	Union_Find uf(n+1);
	vector<pi> ab(m);
	rep(i, m) cin >> ab[m-i-1].fi >> ab[m-i-1].se;

	vll ans(m);
	ans[0] = (ll)n*(n-1)/2;

	rep(i, m-1){
		ans[i+1] = ans[i];
		int a = ab[i].fi, b = ab[i].se;
		if (!uf.same(a, b)){
			ans[i+1] -= uf.nodes(a)*uf.nodes(b);
			uf.unite(a, b);
		}
	}

	rep(i, m) cout << ans[m-i-1] << endl;
	return 0;
}

Measured memory_bytes: 4480
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder.Abc173
{
    class C
    {
        public static void Main()
        {
            var hwk = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
            var h = hwk[0];
            var w = hwk[1];
            var k = hwk[2];

            var matrix = new int[h][];

            for (int y = 0; y < h; y++)
                matrix[y] = Console.ReadLine().ToCharArray().Select(c => c == '#' ? 1 : 0).ToArray();
            
            int count = 0;
            for (int ybit = 0; ybit < 1 << h; ybit++)
            {
                for (int xbit = 0; xbit < 1 << w; xbit++)
                {
                    int n = 0;
                    for (int y = 0; y < h; y++)
                    {

                        for (int x = 0; x < w; x++)
                        {
                            if (((ybit >> y) & 1) == 0 && ((xbit >> x) & 1) == 0)
                                n += matrix[y][x];
                        }
                    }
                    if (n == k)
                        count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 28272
import java.util.*;

class Main {

    static boolean [] primes;

    static void makePrimeList() {

        for(int i = 0; i < 50001; i++) {
            primes[i] = true;
        }

        primes[0] = false;
        primes[1] = false;

        for(int n = 2; n < 50001; n++) {
            if (primes[n]) {
                for(int k = 2 * n; k < 50001; k += n) {
                    primes[k] = false;
                }
            }
        }

    }

    static void solve (int n) {

        int result = 0;

        for(int i = 2; i <= n / 2; i++) {
            if (primes[i] && primes[n-i]) result += 1;
        }

        System.out.println(result);
    }

    public static void main (String [] args) {

        Scanner sc = new Scanner(System.in);

        primes = new boolean[50001];
        makePrimeList();

        while (true) {
            int n = sc.nextInt();

            if ( n == 0 )   break;

            solve(n);
        }

    }
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
#define int long long
int w[105],v[105];
int dp[100005];

int32_t main() {
	int n,s;
	cin>>n>>s;
	for (int i = 0; i < n ; i++) {
	    cin>>w[i]>>v[i];
	}
    
	for(int i=0;i<n;i++)
	{
	    for(int j=s;j>=0;j--)
	    {
	        if(w[i]>j)
	            continue;
	        dp[j]=max(dp[j-w[i]]+v[i],dp[j]);
	    }
	}
	cout<<dp[s];
	
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n; vector<int>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	int ans = 0;
	while (true) {
		bool ok = true;
		for (int i = 0; i < n; i++) {
			if (a[i] % 2 != 0) {
				ok = false;
				break;
			}
		}
		if (!ok) {
			cout << ans << endl;
			return 0;
		}
		rep(i, n) {
			a[i] /= 2;
		}
		ans++;
	}
	return 0;
}

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




int main(){
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    string f="",b="";
    rep(i,ty-sy)f.push_back('U');
    rep(i,tx-sx)f.push_back('R');
    rep(i,ty-sy)b.push_back('D');
    rep(i,tx-sx)b.push_back('L');

    cout << f << b << "LU" << f <<"RDRD" << b << "LU"<<endl;

}


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

int     get_g(int i, vector<int> &grp) {
        if (i==grp.at(i)) return i;
        return get_g(grp.at(i), grp);
}

int     main() {
        int N, M;
        cin >>N >>M;
        vector<int> p(N+1, 0);
        vector<int> grp(N+1, 0);
        vector<int> grp_depth(N+1, 0);
        for (int i=1; i<=N; i++) {
                cin >>p.at(i);
                grp.at(i)=i;
        }
        vector<int> x(M, 0);
        vector<int> y(M, 0);
        for (int i=0; i<M; i++)
                cin >>x.at(i) >>y.at(i);
        // Grouping
        for (int i=0; i<M; i++) {
                int xx=x.at(i);
                int yy=y.at(i);
                xx=get_g(xx, grp);
                yy=get_g(yy, grp);
                // Already in same group, do nothing
                if (xx==yy) continue;
                // Put into one group
                if (grp_depth.at(xx)==grp_depth.at(yy)) {
                        grp.at(max(xx, yy)) = get_g(min(xx, yy), grp);
                        grp_depth.at(min(xx, yy))++;
                } else if (grp_depth.at(xx)>grp_depth.at(yy)) {
                        grp.at(yy) = xx;
                } else
                        grp.at(xx) = yy;
        }
        int S=0;
        for (int i=1; i<=N; i++) {
                if (i==p.at(i))
                        S++;
                else if (get_g(i, grp)==get_g(p.at(i), grp))
                        S++;
        }
        cout <<S <<endl;
        return 0;
};

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

long long a[100010];
long long b[100010];
int main(){
  int n;
  cin >> n;

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

  long long ans = 0;
  for(int i = n-1;i >= 0;i--){
    a[i] += ans;
    if(a[i] % b[i] != 0){
      long long tmp = a[i] / b[i] + 1;
      ans += b[i] * tmp - a[i];
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

vector<long long> fact(1000001,1);
void factorial(int N){
    for(int i=1; i<N; i++){
        fact[i+1]=(i+1)*fact[i]%MOD;
    }
}

map<long long, long long> inv_fact;
long long inv_factorial(long long x){
    if (inv_fact.count(x)){
        return inv_fact[x];
    }
    long long p=MOD-2;
    long long ret=1;
    long long tmp=x;
    while(p>0){
        if(p%2==1)ret=ret*tmp%MOD;
        tmp=tmp*tmp%MOD;
        p/=2;
    }
    inv_fact[x]=ret;
    return ret;
}

long long comb(int a, int b){
    long long ret=fact[a]*inv_factorial(fact[a-b])%MOD;
    return ret*inv_factorial(fact[b])%MOD;
}

int main(){
    int X, Y;
    cin >> X >> Y;
    factorial(1000000);

    if((2*X-Y)<0 || (2*X-Y)%3>0 || (2*Y-X)<0 || (2*Y-X)%3>0){
        cout << 0 << endl;
    }else{
        ll x=(2*X-Y)/3;
        ll y=(2*Y-X)/3;
        cout << comb(x+y,x) << endl;
    }
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

struct edge
{
	int to,cap,rev;
};
vector<edge>G[505];
bool used[505];

void add_edge(int from,int to,int cap)
{
	G[from].push_back((edge){to,cap,G[to].size()});
	G[to].push_back((edge){from,0,G[from].size()-1});
}
int dfs(int v,int t,int f)
{ 
	if(v==t) return f;
	used[v]=true;
	for(int i=0;i<G[v].size();i++)
	{
		edge &e=G[v][i];
		if(!used[e.to] && e.cap>0)
		{ 
			int d=dfs(e.to,t,min(f,e.cap));
			if(d>0) 
			{ 
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s,int t)
{ 
	int flow=0;
	while(1)
	{ 
		memset(used,0,sizeof(used));
		int f=dfs(s,t,INF);
		if(!f) return flow;
		flow+=f;
	}
}


int n,m;
int S,T;
int aa[300005],bb[300005];
bool bad[305][305];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int a,b; scanf("%d%d",&a,&b);
		add_edge(a,b,1);
		add_edge(b,a,1);
		aa[i] = a; bb[i] = b;
	}
	scanf("%d%d",&S,&T);
	int x = max_flow(S,T);
	cout << x << endl;
	for(int i=1;i<=n;i++){
		for(int j=0;j<G[i].size();j++){
			if(G[i][j].cap == 1){
				bad[i][G[i][j].to] = 1;
			}
		}
	}
	vector<int>ans;
	for(int i=1;i<=m;i++){
		if(bad[aa[i]][bb[i]]) ans.pb(i);
	}
	cout << ans.size() << endl;
	rep(i,ans.size()) cout<<ans[i]<<endl;
}


Measured memory_bytes: 3472
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll n, k;
    cin >> n >> k;

    vector<ll> P(n), C(n);
    REP(i, n) cin >> P[i];
    REP(i, n) P[i]--;
    REP(i, n) cin >> C[i];

    ll ans = C[0];
    REP(i, n) {
        vector<ll> c;
        vector<bool> used(n, false);

        int cur = i;
        while(!used[cur]) {
            used[cur] = true;
            cur = P[cur];
            c.pb(C[cur]);
        }

        ll sum = -INF;

        ll tmp = 0;
        REP(i, c.size()) {
            tmp += c[i];
            if (i + 1 <= k) sum = max(sum, tmp);
        }

        if (tmp > 0) {
            if (k > c.size()) {
                tmp = tmp * (k / (int)c.size() - 1);
                sum = max(tmp, sum);
                REP(j, c.size()) {
                    tmp += c[j];
                    sum = max(tmp, sum);
                }

                REP(j, k % c.size()) {
                    tmp += c[j];
                    sum = max(tmp, sum);
                }
            }
        }

        ans = max(ans, sum);
    }

    print(ans);
    
}


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

int main()
{
    vector<int> a, b;
    for (;;)
    {
        int c, d;
        cin >> c >> d;
        if (c == 0 && d == 0)
            break;
        a.push_back(c);
        b.push_back(d);
    }
    int n = a.size();
    vector<int> con;
    for (int i = 0; i < n; i++)
    {
        int cnt = 0;
        int o = a[i];
        for (int j = 1; j <= o - 2; j++)
        {
            for (int k = j + 1; k <= o - 1; k++)
            {
                for (int l = k + 1; l <= o; l++)
                {
                    if (j + k + l == b[i])
                        cnt++;
                }
            }
        }
        con.push_back(cnt);
    }
    for (int i = 0; i < n; i++)
        cout << con[i] << endl;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define lb lower_bound
#define ub upper_bound
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T>
T extgcd(T a,T b,T &x,T &y){
  if(!b){x=1;y=0;return a;}
  T d=extgcd(b,a%b,y,x); 
  y-=(a/b)*x;
  return d;
}
//ax+by=gcd(a,b)を満たすx,y 返り値はgcd

template<typename T>
pair<T,T> ChineseRem(const vector<T> &b,const vector<T> &m){
  T r=0,M=1;
  for(int i=0;i<(int)m.size();++i){
    T p,q;
    T g=extgcd(M,m[i],p,q);
    if((b[i]-r)%g)return {0,-1};
    r+=M*(((b[i]-r)/g*p)%(m[i]/g));
    M*=m[i]/g;
  }
  return {(r%M+M)%M,M};
}
//x=a[i](modm[i]) を満たすx(0<=x<Π(m[i])) を求める
//法が互いに素でない場合、解が存在しない場合がある

signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n,m,cnt=0,num;cin>>n>>m;
  V<ll> v(n);
  rep(i,0,n){
    cin>>v[i];
    cnt=0;
    while(v[i]%2==0){
      v[i]>>=1;
      ++cnt;
    }
    if(!i)num=cnt;
    else if(num!=cnt){
      cout<<0<<ENDL;
      return 0;
    }
  }

  ll l=v[0]*mpow(2,num-1);
  rep(i,1,n){
    v[i]*=mpow(2,num-1);
    l=l*v[i]/gcd(l,v[i]);
    cerr<<l<<ENDL;
  }

  ll ans=(m+l)/(2*l);
  cout<<ans<<ENDL;
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";

string vow = "aeiou";

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

const int dx[] = { -1 , 0 , 0 , 1 } ;
const int dy[] = { 0 , -1 , 1 , 0 } ;

const ld pie = 3.14159265358979 ;
const ll mod = 1e9 + 7 ;

void solve ( int test_case )
{
    int n , m ;
    cin >> n >> m ;

    vvb v ( m , vb ( n ) ) ;

    for ( int i=0 ; i < m ; i++ )
    {
        int t ; cin >> t ;
        while ( t-- )
        {
            int temp ; cin >> temp ;
            v[i][temp-1] = true ;
        }
    }

    vi req ( m ) ;
    for ( int i=0 ; i < m ; i++ ) cin >> req[i] ;

    int maxx = 1 << n ;
    int ans = 0 ;

    for ( int k = 0 ; k < maxx ; k ++ )
    {
        int bulb = 0 ;
        for ( bulb = 0 ; bulb < m ; bulb ++ )
        {
            int mask = k ;
            int cnt = 0 ;
            int indx = 0 ;

            for ( ; indx < n ; indx ++ , mask >>= 1 )
            {
                int bit = (mask&1) ;

                if ( bit == true && v[bulb][indx] == true )
                    cnt ++ ;
            }

            cnt %= 2 ;
            if ( cnt != req[bulb] )
                break ;
        }

        if ( bulb == m )
            ans ++ ;
    }

    cout << ans ; line
}

int main()
{
    int t = 1;
    //cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 256
n,m =map(int, input().split())
    #idxへの行き方の通りをリスト化
num_list = [0]*(n+1)
num_list[0] = 1
a_list =set([int(input()) for _ in range(m)])
if 1 not in a_list:
    num_list[1] = 1
for i in range(2,n+1):
    if i not in a_list:
        num_list[i] = num_list[i-1] + num_list[i-2]
print(num_list[n]%(10**9+7))

Measured memory_bytes: 465924
#include<stdio.h>
	int s[10],i=0;
	int main(){
		int n;
		while(scanf("%d",&n)!=EOF){
			if(n>0){
				s[i]=n;
				i++;
			}else{
				i--;
				printf("%d\n",s[i]);
			}
		}
		return 0;
	}

Measured memory_bytes: 1684
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define endl "\n"
#define all(c) (c).begin(),(c).end()

// target 4096

signed main() {
	// freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	std::ios::sync_with_stdio(false);
	cin.tie(0);

	ll n, x, m;
	cin >> n >> x >> m;
	vector<ll> pref(1);
	vector<ll> arr;
	ll p = x;
	ll i;
	while (true) {
		auto it = find(all(arr), p);
		if (it != arr.end()) {
			i = it - arr.begin();
			break;
		}
		arr.push_back(p);
		pref.push_back(pref.back()+p);
		p = p*p%m;
	}
	if (n < i) {
		cout << pref[n] << endl;
		return 0;
	}
	n -= i;
	ll k = arr.size()-i;
	cout << n/k * (pref.back() - pref[i]) + pref[n%k+i] << endl;
}
/* --- PSolving ---
 * Simplifying (getting rid of variables, conditions, code logic, etc.)
 * Reframing
 * Solving a subtask (subgoal, aux. problem, removing a condition or fixing a parameter, etc.)
 * Inducing
 * Divide and conquer
 * Working backwards
 * Visual intuition
 */


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

public class Main{
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int n = Integer.valueOf(line.split(" ")[0]);
		int q = Integer.valueOf(line.split(" ")[1]);
		
		int[] array = new int[n];
		Arrays.fill(array, Integer.MAX_VALUE);
		for(int i = 0; i < q; i++){
			String query = sc.nextLine();
			String com = query.split(" ")[0];
			int x = Integer.valueOf(query.split(" ")[1]);
			int y = Integer.valueOf(query.split(" ")[2]);
			switch(com){
				case "0":
					update(array, x, y);
					break;
				case "1":
					System.out.println(findMinimum(array, x, y));
					break;
			}
		}
		sc.close();
	}
	
	static void update(int[] array, int i, int x){
		array[i] = x;
	}
	
	static int findMinimum(int[] array, int from, int to){
		int result = Integer.MAX_VALUE;
		for(int i = from; i <= to; i++){
			if(array[i] < result) result = array[i];
		}
		return result;
	}
}

Measured memory_bytes: 164984
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60
#define MOD 1000000007
#define BOX 200000

typedef long long ll;

#define rep(i, s, e) for(unsigned int i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j
#define fix(i) fixed << setprecision(i)
#define so(a) sort(begin(a), end(a))
#define soR(a) sort(begin(a), end(a), greater<ll>())
#define sum(a) accumulate(begin(a), end(a), 0)


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; }



int main() {
    ll M1, D1, M2, D2;
    cin >> M1 >> D1 >> M2 >> D2;

    if (M1 != M2) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,k,i;
  cin >> a >> b >> k;
  if(b - a + 1 > 2 * k){
    for(i=0; i < k; i++){
      cout << a+i << endl;
    }
    for(i=0; i < k; i++){
      cout << b-k+1+i << endl;
    }
  }
  else{
    for(i = a; i < b + 1; i++){
      cout << i << endl;
    }
  }
}

Measured memory_bytes: 256
def saiki(x,s)
  if(@ind[s] != nil)
    if(@memo[s] == nil)
      @ind[s].each do |d|
        @ans[d] = 1
      end
      @memo[s] = 0
    end
  end
  return if(x >= @n)
  saiki(x+1,s+@a[x])
  saiki(x+1,s)
end
@memo = {}
@ind = {}
@n = gets.chomp.to_i
@a = gets.chomp.split(" ").map(&:to_i)
q = gets.chomp.to_i
m = gets.chomp.split(" ").map(&:to_i)
@ans = Array.new(q,0)
m.size.times do |d|
  if(@ind[m[d]] == nil)
  @ind[m[d]] = [d]
  else
  @ind[m[d]].push(d)
  end
end
saiki(0,0)
@ans.each do |d| 
  if(d == 0)
    puts "no"
  else
    puts "yes"
  end
end

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

int main() {
  string S;
  cin >> S;
  int N =0;
  N = S.size();
  int A,B,C;
  A = (N-3)/2;
  B = (N+1)/2;
  C = (3*N-1)/2;
  int count =0;
  bool finished = false;
  for (int i = 0;i <= A;i++) {
    if (S.at(i) != S.at(A-i)) {
      finished = true;
      break;
    }
    else if (S.at(i + B) != S.at(C-i-B)) {
      finished = true;
      break;
    }
  }
  for (int i = 0;i <= A;i++) {
    if (S.at(i) != S.at(C-i-B)) {
      finished = true;
      break;
    }
    else if (S.at(i + B) != S.at(A-i)) {
      finished = true;
      break;
    }
  }
  if (finished) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}
    
    


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

int main() {
    int n;
    long long int ans = 0, mod = 1000000007; 
    cin >> n;
    long long int a[n], b[n+1];
    for(int i = 0; i < n; ++i) cin >> a[i];
    b[n] = 0;
    for(int i = n-1; i >= 0; --i) {
        b[i] = (b[i+1] + a[i])%mod;
    }

    for(int i = 0; i < n-1; ++i) {
        ans = (ans + (a[i]*b[i+1])%mod)%mod;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 6752
a,b,c,d = map(int,input().split())

def gcd(x,y):
    if y == 0:
        return x
    return gcd(y, x % y)

lcm = c*d//gcd(c,d)
cc = b//c - (a-1)//c
dd = b//d - (a-1)//d
cd = b//lcm - (a-1)//lcm
print(b-a+1-cc-dd+cd)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
    
    #define fio ios_base::sync_with_stdio(false), cin.tie(NULL)
    #define ll long long int
    #define ull unsigned long long int
    #define ld long double
    #define sb __builtin_popcount
    #define vi vector<int>
    #define vl vector<ll>
    #define vc vector<char>
    #define ii pair<int, int>
    #define pq priority_queue<ii, vector<ii>, greater<ii>>
    #define vii vector<ii>
    #define viii vector<tuple<ll, ll, ll>>
    #define sz(a) int((a).size())
    #define f(a, b) for (int i = a; i < b; i++)
    #define fr(a, b) for (int i = a - 1; i >= b; i--)
    #define tr(x, m) for (auto x : m)
    #define in(a, b) (b.find(a) != string::npos)
    #define minin(a) *min_element(all(a))
    #define maxin(a) *max_element(all(a))
    #define bs(l, h, k) equal_range(l, h, k);
    #define X first
    #define Y second
    #define fill(a, x) memset(a, x, sizeof(a))
    #define pb push_back
    #define pf push_front
   // #define mp make_pair
    #define all(v) v.begin(), v.end()
    #define rall(v) reverse(v.begin(), v.end())
    #define unq(v) v.erase(unique(all(v)), v.end())
    #define el "\n"
    #define mx3(a, b, c) max(max(a, b), c)
    #define S(v) accumulate(all(v), (ll)0)
    #define IP(v1, v2) inner_product(all(v1), v2.begin(), (ll)0)
    const long double PI = atan(1.0) * 4.0;
    const ll MOD = 1e9 + 7;
    const ll INF = 1e18;
    const ld EPS = 0.0000001;
        bool xx(ll n){
            while(n>0){
                if(n%10==7)return true;
                n/=10;   
            }
            return false;
        }
        int main() {
            fio;
            ll n;
            cin>>n;
            if(xx(n))cout<<"Yes"<<el;
            else cout<<"No"<<el;
            return 0;
        }


Measured memory_bytes: 3636
#include<stdio.h>

int main(){
  int i,j,k;
  double ans;
  double W,H,x,y;
  scanf("%lf %lf %lf %lf",&W,&H,&x,&y);
  
  if(x == W/2.0 && y==H/2.0)
    printf("%lf %d\n",(W*H)/2.0,1);
  else
    printf("%lf %d\n",(W*H)/2.0,0);
  return 0;
}



Measured memory_bytes: 128
N=int(input())
ab=[]
for i in range(N-1):
  ab.append(list(map(int, input().split())))
A=[ [] for i in range(N) ]
for i in range(N-1):
  A[ab[i][0]-1]+=[ab[i][1]-1]
  A[ab[i][1]-1]+=[ab[i][0]-1]
 
def BFS(i,A):
  dist=[0]*N
  d=[-1]*N
  d[i]=0#未訪問ならd=-1,訪問済みならiからの距離
  que=[i]
  dist=1
  while que:
    for j in range(len(que)):
      label=que.pop(0)
      for i in range(len(A[label])):
        if d[A[label][i]]==-1:
          d[A[label][i]]=dist
          que+=[A[label][i]]
    dist+=1
  return(d)
 
dist1=BFS(0,A)
dist2=BFS(N-1,A)
Fe=0
Su=0
for i in range(N):
  if dist1[i]<=dist2[i]:
    Fe+=1
  else:
    Su+=1
if Fe>Su:
  print("Fennec")
else:
  print("Snuke")

Measured memory_bytes: 49564
#include <iostream>
using namespace std;
typedef long long ll;
string s, t;
ll slen, tlen, sa[100010], ta[100010], sb[100010], tb[100010], q;
int main(void){
    // Your code here!
    cin >> s >> t;
    slen = s.length(), tlen = t.length();
    for (ll i = 0; i < slen; i++){
        sa[i + 1] = sa[i] + (s[i] == 'A' ? 1 : 0);
        sb[i + 1] = sb[i] + (s[i] == 'B' ? 1 : 0);
    }
    for (ll i = 0; i < tlen; i++){
        ta[i + 1] = ta[i] + (t[i] == 'A' ? 1 : 0);
        tb[i + 1] = tb[i] + (t[i] == 'B' ? 1 : 0);
    }
    cin >> q;
    for (ll i = 0; i < q; i++){
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        ll srest = ((sa[b] - sa[a - 1]) + 2 * (sb[b] - sb[a - 1])) % 3;
        ll trest = ((ta[d] - ta[c - 1]) + 2 * (tb[d] - tb[c - 1])) % 3;
        if (srest == trest) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}


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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using piii = pair<int, pii>;
using plll = pair<ll, pll>;
using pib = pair<int, bool>;
using pdi = pair<double, int>;
using pid = pair<int, double>;
using ld = long double;
using piiii = pair<pii, pii>;

#define endl "\n"
#define inf 0x3f3f3f3f3f
#define f first
#define s second

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

string s;
vector<int> seg;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> s;
    int x = 0;
    for (int i=0; i<s.length(); i++){
        if (i>0&&s[i]!=s[i-1]){
            seg.push_back(x);
            x = 0;
        }
        x++;
    }
    seg.push_back(x);
    ll t = 0;
    ll p = 0;
    bool f = s[0]=='<';
    for (ll v : seg){
        if (f){
            ll a = p+1;
            ll b = p+v;
            t += ((a+b)*v)/2;
            p = b;
        }else{
            ll a = 0;
            ll b = v-1;
            t += ((a+b)*v)/2;
            if (p<=b) t += b-p+1;
            p = 0;
        }
        f = !f;
    }
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 2332
#include<stdio.h>

static int digits(int n)
{
  int d = 1;
  
  if (n < 0) {
    n = -n;
    d++;
  }
  
  while (n /= 10)
    d++;
  
  return d;
}

int main()
{
  int a, b;
  while (scanf("%d%d", &a, &b) != EOF)
	printf("%d\n", digits(a+b));
  
  return 0;
}



Measured memory_bytes: 2120
#include <iostream>
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <algorithm>

using namespace std;

string s;
int L;
int used[1000005];

string toStr(int x)
{
  char buf[55];
  sprintf(buf, "%d", x);
  return buf;
}

int main(void)
{
  while(1){
    cin >> s >> L;
    if(s == "0" && L == 0) break;

    for(int i = 0; i <= 1000000; i++) used[i] = -1;
    used[atoi(s.c_str())] = 0;

    int maxi, mini, val;
    for(int i = 1; ; i++){
      while(s.size() < L) s = "0" + s;
      sort(s.begin(), s.end());
      mini = atoi(s.c_str());
      reverse(s.begin(), s.end());
      maxi = atoi(s.c_str());

    //cout << mini << " " << maxi << endl;

      val = maxi - mini;
      if(used[val] >= 0){
        cout << used[val] << " " << val << " " << i - used[val] << endl;
        break;
      }
      used[val] = i;
      s = toStr(val);
    }
  }

  return 0;
}



Measured memory_bytes: 7184
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int a,b,c,d,e,k; cin >> a >> b >> c >> d >> e >> k;
    cout << ((e-a <= k) ? "Yay!" : ":(" ) << endl; return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>
#include <list>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
//#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))
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; }

using namespace std;

int main(void)
{
    int X, N; cin >> X >> N;
    vector<int> p(N); rep(i, 0, N)cin >> p[i];
    sort(p.begin(), p.end());
    int a = X, b = X;
    int ans = X;

    while (true) {
        bool flag1 = false, flag2 = false;
        rep(i, 0, N) {
            if (a == p[i])flag1 = true;
        }
        if (flag1)a--;
        else {
            ans = a;
            break;
        }

        rep(i, 0, N) {
            if (b == p[i])flag2 = true;
        }
        if (flag2)b++;
        else {
            ans = b;
            break;
        }
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;

//map<string>a
class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint & a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator-=(const mint & a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator*=(const  mint & a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint & a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint & a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint & a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint & a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint & a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
//組み合わせ
void recursive_comb(vector<int> indexes, int s, int rest, std::function<void(vector<int>)> f) {
	if (rest == 0) {
		f(indexes);
	}
	else {
		if (s < 0) return;
		recursive_comb(indexes, s - 1, rest, f);
		indexes[rest - 1] = s;
		recursive_comb(indexes, s - 1, rest - 1, f);
	}
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(vector<int>)> f) {
	vector<int>indexes(k);
	recursive_comb(indexes, n - 1, k, f);
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
int main() {
	ll N, M;
	cin >> N >> M;
	vector<string>s(M);
	map<ll,ll>m;
	vector<int>p(M);
	vector<bool>c(N+1, 0);
	ll ans[2] = {};
	rep(i, M) {
		cin >> p[i] >> s[i];
		if (s[i] == "WA") {
			m[p[i]]++;
		}
		else if(c[p[i]]==0){
			c[p[i]] = 1;
			ans[0]++;
			ans[1] += m[p[i]];
		}
	}
	cout << ans[0] <<" "<< ans[1];
}



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

int main() {
	int n;
	cin>>n;
	vector<int> a(n), dp(n);
	for(int i=0;i<n;i++) {
		cin>>a[i];
	}
	dp[0] = 0;
	dp[1] = abs(a[0]-a[1]);
	for(int i=2;i<n;i++) {
		dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout<<dp[n-1];
	return 0;
	
}

Measured memory_bytes: 1024
/*
    Author : manu_sy
*/
#include "bits/stdc++.h"
using namespace std;
 
/** Template Begins **/
#define int ll 
typedef long long        ll;
typedef pair<int,int>    PII;
 
#define IOS         ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl        '\n'
#define pb          push_back
#define F           first
#define S           second
#define mp          make_pair
#define all(a)      (a).begin(), (a).end()
#define FOR(i,a,b)  for(int i=a;i<=b;i++)
#define LP(i,n)     for(int i=0;i< n;i++)
 
/* Debug */
 
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.F << "," << P.S << ")";
} 
 
template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
 
template<class TH> void _dbg(const char *sdbg, TH h){ cerr << sdbg << '=' << h << endl; }
 
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',') cerr << *sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}
 
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif
 
/* Debug Ends */
 
const int N = 8e7+7;
 
/** Template Ends **/

 
signed main() {
 
    IOS;
    int k;	cin >> k;
    int cur = 7;

    FOR(i,1,N) {
    	if (cur % k == 0) {
    		cout << i << endl;
    		return 0;
    	}
    	cur = (cur * 10 + 7) % k;
    }
    cout << -1 << endl;


 
    return 0;
}























Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String t = sc.nextLine();
        String p = sc.nextLine();
        for (int i = 0; i <= t.length() - p.length(); i++){
            int a = i;
            int b = 0;
            while (b < p.length()) {
                if ((t.charAt(a) == p.charAt(b)) && (b != p.length() - 1)){
                    a++;
                    b++;
                }
                else if ((t.charAt(a) == p.charAt(b)) && (b == p.length() - 1)){
                    System.out.println(i);
                    b = p.length();
                }
                else {
                    b = p.length();
                }
            }
        }
    }
}


Measured memory_bytes: 26368
r=range
def a(i,j,k,l="+"):print(l,i,j,k)
print(6484)
a(0,1,3)
a(2,3,3,L:="<")
for x in 0,1:
	a(x,3,x)
	for t in r(30):a(v:=x+4,v,v);a(v,3,6),exec('a(6,6,6);'*(29-t));a(6,x,T:=x*60+35+t,L);a(v,T,v)
for t in r(60):a(2,2,2);[(a(34+t-s,95+s,5),a(3,5,6,L),a(2,6,2))for s in r(t)]

Measured memory_bytes: 9272
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int u32;
typedef pair<int, int> p;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int Inf = (1<<30);
ll inf = (1LL<<60);
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int MOD = 1000000007;
ll fac[110000];
ll finv[110000];
ll inv[110000];
void modinv(int max,int MOD) {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < max; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
ll comb(int n, int r,int mod) {
	if (n < r) return 0;
	if (n < 0 || r < 0) return 0;
	return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}
int main(){
	int n;
	cin >> n;
	int k;
	cin >> k;
	modinv(n, MOD);
	int i;
	vector<int> a(n);
	for (i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	ll ans = 0;
	for (i = 0; i < n; i++) {
		ans = ans + (a[i] * comb(n - i - 1, k - 1, MOD));
		ans = ans - (a[i] * comb((n - (n - i)), k - 1, MOD));
		ans %= MOD;
	}
	if (ans < 0) while (ans < 0) ans += MOD;
	if (ans > MOD) while (ans > MOD) ans -= MOD;
	cout << ans;
	return(0);
}

Measured memory_bytes: 2944
#include <iostream>

using namespace std;

int main()
{
    int n,a[200005],b[200005];
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>a[i];
    int x=0,y=n-1;
    if(n%2!=0)
        for(int i=n-1; i>=0; i--)
        {
            if(i%2==0)
            {
                b[x]=a[i];
                x++;
            }
            else
            {
                b[y]=a[i];
                y--;
            }
        }
    else
        for(int i=n-1; i>=0; i--)
        {
            if(i%2!=0)
            {
                b[x]=a[i];
                x++;
            }
            else
            {
                b[y]=a[i];
                y--;
            }
        }
    for(int i=0;i<n;i++)
        cout<<b[i]<<" ";
    return 0;
}


Measured memory_bytes: 3712
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, first, last) for (int i = (first); i < (last); ++i)
#define REP(i, n) FOR(i, 0, n)
#define CLR(a) memset((a), 0, sizeof(a))
#define DUMP(x) std::cerr << #x << " = " << (x) << std::endl;
#define DUMPR(v) REP(_i,v.size()){std::cerr<< #v << "[" << _i << "] = " << (v[_i]) << std::endl;}
#define CIN_VEC(v,N) {v.clear(); v.reserve(N); REP(i,N){typename decltype(v)::value_type x; cin>>x; v.emplace_back(x);}};

inline int to_int(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string to_string(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef unsigned long long ull;
typedef unsigned long ul;

int H,W;
int a[100][100];

bool solve() {

  for(int i=0;i<H;i++) {
    for(int j=0;j<W;j++) {
      if (!a[i][j]) continue;

      if ( !(i >= 1 && a[i-1][j])
        && !(i <H-1 && a[i+1][j])
        && !(j >= 1 && a[i][j-1])
        && !(j < W-1 && a[i][j+1]) )
        return false; 
    }
  }
  return true;
}

int main() {
  cin>>H>>W;
  REP(i,H) {
    REP(j,W) {
      char c;
      cin>>c;
      a[i][j] = c=='#';
    }
  }

  string ans = solve() ? "Yes" : "No";
  cout << ans << endl;

  return 0;
}


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

int width,height;
char lmap[50][51];
char rmap[50][51];

int isValid(int x1,int y1,int x2,int y2) {
	if(x1<0 || x1>=width || y1<0 || y1>=height)return 0;
	if(x2<0 || x2>=width || y2<0 || y2>=height)return 0;
	if(lmap[y1][x1]=='#' || rmap[y2][x2]=='#')return 0;
	if(lmap[y1][x1]=='%' && rmap[y2][x2]=='%')return 1;
	if(lmap[y1][x1]=='%' || rmap[y2][x2]=='%')return 0;
	return 1;
}

int stack_num;
char stack[50*50*50*50][4];
char visited[50][50][50][50];

void stack_push(int x1,int y1,int x2,int y2) {
	if(!visited[y1][x1][y2][x2]) {
		stack[stack_num][0]=x1;
		stack[stack_num][1]=y1;
		stack[stack_num][2]=x2;
		stack[stack_num][3]=y2;
		stack_num++;
		visited[y1][x1][y2][x2]=1;
	}
}

int tansaku(int sx1,int sy1,int sx2,int sy2,int dx1,int dy1,int dx2,int dy2) {
	memset(visited,0,sizeof(visited));
	visited[sy1][sx1][sy2][sx2]=1;
	stack[0][0]=sx1;
	stack[0][1]=sy1;
	stack[0][2]=sx2;
	stack[0][3]=sy2;
	stack_num=1;
	while(stack_num>0 && !visited[dy1][dx1][dy2][dx2]) {
		int x1,x2,y1,y2;
		int xx1,xx2,yy1,yy2;
		stack_num--;
		x1=stack[stack_num][0];y1=stack[stack_num][1];
		x2=stack[stack_num][2];y2=stack[stack_num][3];

		yy1=y1;yy2=y2;
		if(y1>0 && lmap[y1-1][x1]!='#')yy1--;
		if(y2>0 && rmap[y2-1][x2]!='#')yy2--;
		if(isValid(x1,yy1,x2,yy2) && (y1!=yy1 || y2!=yy2)) {
			stack_push(x1,yy1,x2,yy2);
		}
		yy1=y1;yy2=y2;
		if(y1+1<height && lmap[y1+1][x1]!='#')yy1++;
		if(y2+1<height && rmap[y2+1][x2]!='#')yy2++;
		if(isValid(x1,yy1,x2,yy2) && (y1!=yy1 || y2!=yy2)) {
			stack_push(x1,yy1,x2,yy2);
		}
		xx1=x1;xx2=x2;
		if(x1>0 && lmap[y1][x1-1]!='#')xx1--;
		if(x2+1<width && rmap[y2][x2+1]!='#')xx2++;
		if(isValid(xx1,y1,xx2,y2) && (x1!=xx1 || x2!=xx2)) {
			stack_push(xx1,y1,xx2,y2);
		}
		xx1=x1;xx2=x2;
		if(x1+1<width && lmap[y1][x1+1]!='#')xx1++;
		if(x2>0 && rmap[y2][x2-1]!='#')xx2--;
		if(isValid(xx1,y1,xx2,y2) && (x1!=xx1 || x2!=xx2)) {
			stack_push(xx1,y1,xx2,y2);
		}
	}
	return visited[dy1][dx1][dy2][dx2];
}

int tansaku_wrapper(int s[4],int g[4]) {
	return tansaku(s[0],s[1],s[2],s[3],g[0],g[1],g[2],g[3]);
}

int main(void) {
	int x,y;
	int start[4]={-1,-1,-1,-1};
	int goal[4]={-1,-1,-1,-1};
	while(scanf("%d%d",&width,&height)==2 && (width|height)!=0) {
		for(y=0;y<height;y++)scanf("%s%s",lmap[y],rmap[y]);
		for(y=0;y<height;y++) {
			for(x=0;x<width;x++) {
				if(lmap[y][x]=='L') {
					start[0]=x;start[1]=y;
				}
				if(rmap[y][x]=='R') {
					start[2]=x;start[3]=y;
				}
				if(lmap[y][x]=='%') {
					goal[0]=x;goal[1]=y;
				}
				if(rmap[y][x]=='%') {
					goal[2]=x;goal[3]=y;
				}
			}
		}
		if(start[0]<0 || goal[0]<0 || start[2]<0 || goal[2]<0)return 1;
		puts(tansaku_wrapper(start,goal)?"Yes":"No");
	}
	return 0;
}

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

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;
const double PI = acos(-1.0);
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to;
    int cost;
};

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int video[30][100010];

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

    rep(i, N)
    {
        int s, t, c;
        cin >> s >> t >> c;
        c--;
        video[c][s - 1]++;
        video[c][t]--;
    }

    rep(i, C) 
    {
        rep(j, 100010) if(j != 0) video[i][j] += video[i][j - 1];
    }

    int ans = 0;

    rep(i, 100010)
    {
        int tmp = 0;
        rep(j, C)
        {
            if(video[j][i]) tmp++;
        }

        ans = max(ans, tmp);
    }

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

Measured memory_bytes: 11904
//----------------------------------------------------------------------
// ITP1_1_D   Watch
//----------------------------------------------------------------------

//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include <iostream>

//----------------------------------------------------------------------
// Definitions
//----------------------------------------------------------------------
class Watch
{
public:
    Watch( size_t timeS )
        : m_timeS( timeS )
    {}

    size_t calcTimeH()
    {
        return m_timeS / 3600;
    }

    size_t calcTimeM()
    {
        return m_timeS % 3600 / 60;
    }

    size_t calcTimeS()
    {
        return m_timeS % 3600 % 60;
    }

private:
    size_t m_timeS;
};

//----------------------------------------------------------------------
// Entry point
//----------------------------------------------------------------------
int main()
{
    size_t s = 0;

    std::cin >> s;

    Watch watch( s );

    std::cout << watch.calcTimeH() << ':' << watch.calcTimeM() << ':' << watch.calcTimeS() << std::endl;

    return 0;
}

Measured memory_bytes: 3084