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

using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  if (a == 1 && b == 2) cout << 3 << endl;
  if (a == 2 && b == 1) cout << 3 << endl;
  if (a == 2 && b == 3) cout << 1 << endl;
  if (a == 3 && b == 2) cout << 1 << endl;
  if (a == 1 && b == 3) cout << 2 << endl;
  if (a == 3 && b == 1) cout << 2 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mul(x,y) (((x)%P*(y))%P)
#define pls(x,y) ((x)%P+(y))%P
using namespace std;
const int N=10040;
const long long P=1e9+7;
long long qpow(long long x,long long k)
{
    long long rt=1,base=x;
    while(k)
    {
        if(k&1)rt=mul(rt,base);
        base=mul(base,base),k>>=1;
    }return rt;
}
long long f[N/2][N/2];
int main()
{
    int n;char str[N];
    scanf("%d",&n);
    scanf("%s",str);int len=strlen(str);
    f[0][0]=1;
    for(int i=0;i<=n;i++)
        for(int j=0;j<=i;j++)
        f[i+1][j+1]=pls(2*f[i][j],f[i+1][j+1]),f[i+1][j-1>-1?j-1:0]=pls(f[i][j],f[i+1][j-1>-1?j-1:0]);
    printf("%lld",mul(f[n][len],qpow(qpow(2,len),P-2)));
    return 0;
}


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

using namespace std;

const int M = 100005;

int n, w;
long long W[105], V[105], dp[105][M];

long long fun(int i, int k) {
  if (i >= n) return 0;
  if (dp[i][k] != -1) return dp[i][k];
  long long x = k - W[i] >= 0 ? fun(i + 1, k - W[i]) + V[i] : 0;
  long long y = fun(i + 1, k);
  return dp[i][k] = max(x, y);
}

int main() {
  scanf("%d %d", &n, &w);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &W[i], &V[i]);
  }
  memset(dp, -1, sizeof dp);
  printf("%lld\n", fun(0, w));
  return 0;
}


Measured memory_bytes: 82304
// Username: WillTheBill
// Time of creation: 2020-09-27 15:19
// Original filename: main.cp.cpp

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

// shortcuts
#define pb push_back
#define fi first
#define se second

// IO
#define multitest signed __T; cin >> __T; while(__T--)
void _masterread(){}
template<typename T,typename... V>
void _masterread(T& t, V&... v){cin >> t;_masterread(v...);}
#define read(...)_masterread(__VA_ARGS__)
void _masterprint(){cout << endl;}
template<typename T,typename... V>
void _masterprint(T t, V... v){cout << t;if(sizeof...(v)) cout << " ";_masterprint(v...);}
#define print(...)_masterprint(__VA_ARGS__)

// DEBUG
// colored output???
template <typename T> // start forward declaration
void _print(T t);
template<typename T1,typename T2>
void _print(pair<T1,T2> p);
template<typename T>
void _print(vector<T>v);
template <typename T> // end forward declaration
void _print(T t){cerr<<t;}
template<typename T1,typename T2>
void _print(pair<T1,T2> p){cerr<<"{";_print(p.first);cerr<<", ";_print(p.second);cerr<<"}";}
template<typename T>
void _print(vector<T>v){cerr<<"(";for(unsigned _i=0;_i<v.size();_i++)_print(v[_i]),cerr<<(_i==v.size()-1?"":", ");cerr << ")";}
void _masterdebug(){cerr<<"]\n";}
template<typename T,typename... V>
void _masterdebug(T t,V... v){_print(t);if(sizeof...(v))cerr<<", ";_masterdebug(v...);}
#ifdef __local__
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"] = [";_masterdebug(__VA_ARGS__)
#else
#define debug(...) 
#endif

// ordered_set and ordered_map
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2>
using ordered_map = tree<T1, T2, less<T1>, rb_tree_tag, tree_order_statistics_node_update>;

// TYPES
// #define int long long

vector<vector<int>> adj (100000);

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int N, M; read(N, M);
    for(int i = 0; i < M; i++){
        int a, b; read(a,b); a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    int c = 0;
    vector<bool> v (N);
    for(int i = 0; i < N; i++){
        if(!v[i]){
            queue<int> q;
            q.push(i);
            while(!q.empty()){
                auto curr = q.front(); q.pop();
                if(v[curr]) continue;
                v[curr] = 1;
                for(auto e : adj[curr]) q.push(e);
            }
            c++;
        }
    }
    print(c-1);
}


Measured memory_bytes: 8464
#include <iostream>
#include <cmath>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    int i, j, k;
    for(i=1;i<=1100;i++){
        j = std::floor(i * 0.08);
        k = std::floor(i * 0.1);
        if((a==j)&&(b==k)){
            cout << i << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

int a[400];
long long sum[401];
long long dp[401][401];

long long calc(int l, int r) {
    int i;
    long long ans = 1e18;
    
    if (dp[l][r] > 0) return dp[l][r];
    if (l + 1 == r) return 0;
    
    for (i = l + 1; i < r; i++) ans = min(ans, calc(l, i) + calc(i, r) + sum[r] - sum[l]);
    
    return dp[l][r] = ans;
}

int main() {
    int n, i;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    
    for (i = 0; i < n; i++) sum[i + 1] = sum[i] + a[i];
    
    printf("%lld\n", calc(0, n));
    
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    //freopen("output.txt","w",stdout);
//cout<<(1/8.0) ;
    ll n,m,sum=0;
    cin>>n>>m;
    ll arr[n+1];

    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        sum+=arr[i];
    }
    //double M=0;
    double chk=sum*(1/(4.0*m));
    //cout<<sum<<" "<<chk<<endl;
    int cnt=0;
   // string ans="No";
    for(int i=0;i<n;i++)
    {
        if(arr[i]>=chk)
            cnt++;
    }
    if(cnt>=m)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;




}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[N];
int main()
{
    int n;
    cin >> n;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    int x = 0;
    for(int i=1;i<=n;i++)
    {
        x = x ^ a[i];
    }
    for(int i=1;i<=n;i++)
    {
        cout << (x ^ a[i]) << ' ';
    }

    return 0;
}


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

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

    int a, b;
    cin >> a >> b;
    
    int sum = max(a, b);
    
    sum += max(max(a-1, b-1), min(a, b));
    
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int sum1 = 0;
		int sum2 = 0;
		long count1 = 0;
		long count2 = 0;
		for (int i = 0; i < n; i++) {
			int x = sc.nextInt();
			sum1 += x;
			sum2 += x;
			if (i % 2 == 0) {
				if (sum1 >= 0) {
					count1 += sum1 + 1;
					sum1 = -1;
				}
				if (sum2 <= 0) {
					count2 += -sum2 + 1;
					sum2 = 1;
				}
			} else {
				if (sum1 <= 0) {
					count1 += -sum1 + 1;
					sum1 = 1;
				}
				if (sum2 >= 0) {
					count2 += sum2 + 1;
					sum2 = -1;
				}
			}
		}
		System.out.println(Math.min(count1, count2));
	}
}


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

double PI = acos(-1);

void compute( double R ){
    for ( int d = 1;;d++){
	int l = 1, r = d*8;
	while(l < r){
	    int n = (l + r)/2;
	    double p = 1.0*n/d;
	    if ( fabs(PI-p) <= R ){
		cout << n << "/" << d << endl; return;
	    } else if ( p > PI ){
		r = n;
	    } else {
		l = n+1;
	    }
	}
    }
}

main(){
    double R;
    while(1){
	cin >> R;
	if ( R == 0 ) break;
	compute(R);
    }
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second

//int dxy[5] = {0, 1, 0, -1, 0};
// assign avl ncm dijkstra geo2 kruskal graph uf lca BIT
// matrix dinic next_combination topcoder

signed main()
{
    int2(h, w);
    Int(n);
    vi data(n);
    rep(i, n) cin >> data[i];
    vvi ans(h, vi(w));

    int ptr = 0;
    rep(i, h) {
        if (i % 2) {
            rep(j, w) {
                while (!data[ptr]) {
                    ptr++;
                }
                data[ptr]--;
                ans[i][j] = ptr+1;
                //std::cout << ptr+1 << " ";
            }
        } else {
            for (int j = w-1; j >= 0; j--) {
                while (!data[ptr]) {
                    ptr++;
                }
                data[ptr]--;
                ans[i][j] = ptr+1;
                //std::cout << ptr+1 << " ";
            }
        }
        //std::cout << std::endl;
    }
    rep(i, h) {
        rep(j, w) {
            std::cout << ans[i][j] << " ";
        }cout << endl;
    }




    return 0;
}


Measured memory_bytes: 512
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  st S;
  ci(S);
  map<char, int> A;
  rep(i, sz(S)){
    A[S.at(i)]++;
  }
  each(i, A){
    if(i.sc > 1){
      co("no");
      rt;
    }
  }
  co("yes");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include<map>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main() {
    int a, p;
    cin >> a >> p;
    cout << ((a * 3) + p) / 2 << endl;
}


Measured memory_bytes: 256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=500;
const int DX[]={-1,0,+1,0},DY[]={0,+1,0,-1};

int n;
ll ans[MAXN][MAXN];

set<ll> have;
int d1[2*MAXN-1],d2[2*MAXN-1];

void solve() {
	have.clear();
	memset(d1,-1,sizeof(d1)); memset(d2,-1,sizeof(d2));
	for(int i=0;i<2*n-1;i+=2) d1[i]=400+i/2;
	for(int i=(n-1)%2;i<2*n-1;i+=2) d2[i]=500+i/2;

	REP(i,n) REP(j,n) if((i+j)%2==0) {
		int a=i+j,b=j+n-i-1,t=1; ll cur=(ll)d1[a]*d2[b]; assert(d1[a]!=-1&&d2[b]!=-1);
		while(have.count(cur*t)) ++t;
		have.insert(cur*t);
		ans[i][j]=cur*t;
	}
	REP(i,n) REP(j,n) if((i+j)%2==1) {
		ll cur=1; int t=1;
		REP(k,4) {
			int ni=i+DX[k],nj=j+DY[k]; if(ni<0||ni>=n||nj<0||nj>=n) continue;
			ll g=gcd(cur,ans[ni][nj]); cur*=ans[ni][nj]/g;
		}
		while(have.count(cur*t+1)) ++t;
		have.insert(cur*t+1);
		ans[i][j]=cur*t+1;
	}
}

bool verify() {
	bool ok=true;
	have.clear();
	REP(x,n) REP(y,n) {
		assert(!have.count(ans[x][y])); have.insert(ans[x][y]); assert(ans[x][y]>=1&&ans[x][y]<=1000000000000000LL);
		REP(k,4) {
			int nx=x+DX[k],ny=y+DY[k];
			if(nx<0||nx>=n||ny<0||ny>=n||ans[nx][ny]>=ans[x][y]) continue;
			if(ans[x][y]%ans[nx][ny]!=1) {
				printf("(%d,%d)->(%d,%d) %lld vs %lld (%lld)\n",x,y,nx,ny,ans[x][y],ans[nx][ny],ans[x][y]%ans[nx][ny]);
				ok=false;
			}
		}
	}
	return ok;
}


void run() {
	scanf("%d",&n);
	solve();
	REP(i,n) { REP(j,n) { if(j!=0) printf(" "); printf("%lld",ans[i][j]); } puts(""); }
	//if(!verify()) printf("err\n");
}

void stress() {
	for(n=MAXN;n>=1;--n) {
		solve();
		bool ok=verify();
		printf("%d: %s\n",n,ok?"ok":"err");
	}
}

int main() {
	run();
	//stress();
	return 0;
}


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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 2147483647;
const ll INFL = 9223372036854775807;
const ll mod = 1000000007;





int main() {
	
	VI v = { 0,2,5,5,4,5,6,3,7,6 };
	VI x(10, 0);
	int n, m;
	cin >> n >> m;
	VI a(m);
	REP(i, m) {
		cin >> a[i];
		x[a[i]] = v[a[i]];
	}

	vector<string> dp(20010, "");

	FOR(i, 1, n + 1) {
		REP(j, 10) {
			if (x[j] == 0)continue;
			if (i - x[j] < 0)continue;
			if (i - x[j] > 0 && dp[i - x[j]] == "")continue;
			char c = j + '0';
			string s = dp[i - x[j]] + c;
			if (dp[i].size() < s.size())dp[i] = s;
			else if (dp[i].size() > s.size())continue;
			else {
				if (dp[i] < s)dp[i] = s;
			}
		}
	}


	cout << dp[n] << endl;

	return 0;

}

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

using ll = long long;

int main(){
    ll n, sz, w0;
    cin >> n >> sz >> w0;

    vector<ll> vals[4] = {};
    { ll tmp;
        cin >> tmp;
        vals[0].push_back(tmp); }

    for(ll i = 1, w, v; i < n; ++i){
        cin >> w >> v;
        vals[w-w0].push_back(v); }

    for(auto& v : vals){
        sort(begin(v), end(v), greater<ll>());
        v.insert(begin(v), 0);
        partial_sum(begin(v), end(v), begin(v)); }

    ll rez = 0;
    for(ll i = 0; i < vals[0].size() && w0 * i <= sz; ++i){
        for(ll j = 0; j < vals[1].size() && w0 * i + (w0 + 1) * j <= sz; ++j){
            for(ll k = 0; k < vals[2].size() && w0 * i + (w0 + 1) * j + (w0 + 2) * k <= sz; ++k){
                const ll left = sz - w0 * i - (w0 + 1) * j - (w0 + 2) * k;
                const ll l = min(left / (w0 + 3), (ll)vals[3].size() - 1);

                rez = max(rez, vals[0][i] + vals[1][j] + vals[2][k] + vals[3][l]); } } }
    cout << rez << endl;
    return 0; }


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define one 1.0
#define inf 100000000000000
#define ret return
#define all(vl) vl.begin(),vl.end()
#define sor sort 
#define cl clear
#define m_p make_pair 
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;
typedef map<string,ll> mapstl;
int main()
{
	ll n;
	cin>>n;
	ll ma = -inf;
	vector<ll> vl(n);
	mapll mp;
	for(int i=0;i<n;i++)
	{
		cin>>vl[i];ma = max(ma,vl[i]);
	 } 
	for(int i=0;i<vl.size();i++)
	{
		ll bei = 1;
		while(bei*vl[i]<=ma)
		{
			mp[bei*vl[i]]++;
			bei++;
		}
	}
	ll cnt = 0;
	for(int i=0;i<vl.size();i++)
	{
		if(mp[vl[i]] == 1)cnt++;
	}
	cout<<cnt<<endl; 
	return 0;
}

Measured memory_bytes: 67052
n = int(input())

tlist = []
hlist = []

for _ in range(n):
    clist = list(map(str, input().split()))
    tlist.append(clist[0])
    hlist.append(clist[1])

tscore = 0
hscore = 0

for t, h in zip(tlist, hlist):
    if t > h:
        tscore += 3
    elif t == h:
        tscore += 1
        hscore += 1
    else:
        hscore += 3

print(tscore, hscore)



Measured memory_bytes: 5624
/* Triangle */
#include <stdio.h>
#include <math.h>

#define PI 3.141592653589793

int main()
{
    int a, b, C;
    double S, L, h;

    scanf("%d %d %d", &a, &b, &C);
    S = sin(C * PI / 180) * a * b / 2;
    L = a + b + sqrt(pow(a,2)+pow(b,2) - 2 * a * b * cos(C * PI / 180));
    h = S * 2 / a;

    printf("%.8lf\n", S);
    printf("%.8lf\n", L);
    printf("%.8lf\n", h);
    return 0;
}


Measured memory_bytes: 2096
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>

int main(void) {
	int mae[26], ato[26], flag = 0;
	char S[200001], T[200001];

	for (int i = 0; i < 26; i++) {
		mae[i] = -1;
		ato[i] = -1;
	}

	scanf("%s%s", &S, &T);
	int length = strlen(S);

	for (int j = 0; j < length; j++) {
		int dis_a = S[j] - 'a';
		int dis_b = T[j] - 'a';

		if (mae[dis_a] != -1 || ato[dis_b] != -1) {
			if (mae[dis_a] != dis_b || ato[dis_b] != dis_a) {
				flag = 1;
				break;
			}
		}
		mae[dis_a] = dis_b;
		ato[dis_b] = dis_a;
	}

	puts(flag == 0? "Yes":"No");
	return 0;
}


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


def main():
    # 入力
    st = input()

    # 右からi文字目から最後の数字までを数値化したものについてmodを計算していく
    mod_res_dic = {0: 1}
    tmp_mod_val = 0
    r_st = ''.join(list(reversed(st)))
    cnt = 0
    for i in range(len(r_st)):
        target_st = r_st[i:i+1]
        tmp_mod_val += int(target_st)*pow(10, i, 2019)
        tmp_mod_val %= 2019
        ls = mod_res_dic.setdefault(tmp_mod_val, 0)
        mod_res_dic[tmp_mod_val] = ls+1
        if ls > 0:
            cnt += ls

    print(cnt)


main()


Measured memory_bytes: 10704
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE RankNTypes #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List
-- import qualified Data.Vector.Unboxed as VU
-- import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
-- import Control.Monad.ST
-- import Debug.Trace
-- trace _ = id

solve :: Int -> (Int, [(Int, Int)])
solve n = let ms = solve1 n in (length ms, ms)

solve1 n | even n = solveA n
         | n `mod` 4 == 1 = solveB n
         | n `mod` 4 == 3 = solveC n

solveA n = concat [f i | i <- [1..n]]
  where f i = [(i, j) | j <- [i+1..n], i /= j, i + j /= n+1]

solveB n = [(i,j) | i <- [1..n], j <- [i+1..n], not (except i j)]
  where
    except i j | i == j = True
               | i + j == n = True
               | otherwise = False

solveC n = [(i, j) | i <- grp1, j <- grp2]
  where
    m = (n - 1) `div` 4
    grp1 = sort ([4*k+1 | k <- [0..m]] ++ [4*k+2 | k <- [0..m]])
    grp2 = sort ([4*k+0 | k <- [1..m]] ++ [4*k+3 | k <- [0..m]])



readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> (Int, [(Int, Int)])
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n]:remLines1 = remLines0
      n = readBInt bs_n
  in solve n

outAnswer :: (Int, [(Int, Int)]) -> IO ()
outAnswer (m, lstAB) = do
  putStrLn $ show m
  forM_ lstAB $ \(a,b) -> putStrLn (show a ++ " " ++ show b)

main :: IO ()
main = outAnswer . tmain =<< B.getContents



Measured memory_bytes: 1660
import java.util.*;
import java.util.Map.Entry;

import javax.swing.text.Segment;
import javax.xml.ws.WebEndpoint;

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main //implements Runnable
{
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};
	
    public static void main(String[] args)   throws Exception, IOException{        
        long mod=1000000007;
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

//        int n=sc.nextInt();
        long a=sc.nextLong();
        long b=sc.nextLong();
        long k=sc.nextLong();
        a-=k;
        if(a<0) {b+=a; a=0;}
        if(b<0) b=0;        
        out.println(a+" "+b);
     	out.flush();
    }


    static void ret(String ans) {
    	System.out.println(ans);
    	System.exit(0);
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}

//
//class P {
//	int x, y, d;
//	P(int  x, int y, int d) {
//	  this.x=x;
//	  this.y=y;
//	  this.d=d;
//	}
//}
//

//class P implements Comparable<P>{
//    int a,b;
//    P(int a, int b) {
//    	this.b=b;
//    	this.a=a;
//    }
//
//    public int compareTo(P p){
//        return -p.a+a;//as
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) throws IOException{
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public char[] getCharSet() throws IOException{
        return this.nextString().toCharArray();
    }    
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
// #define ll int128_t
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define endl '\n'
#define all(x) x.begin(),x.end()
#define f(i,j,l) for(i=j;i<l;i++)
#define smax(a,b) a=max(a,b)
// #if !defined(ONLINE_JUDGE)
// #include "debugging.h"
// #endif
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
// erase,insert same as normal set

// int const mod = 7340033;
int const mod = 1e9+7;
int power(int a,int b,int m){
    int res = 1;
    while(b){
        if(b&1){
            res = res*a;
            res %= m;
        }
        a=a*a;
        a%=m;
        b=b/2;
    }
    return res;
}
 
int inverse(int x){
    return power(x,mod-2,mod);
}

int const N = 2e5+555;
int const inf = 2e16;

void solve(){  
    int n,i,j,l,m;
    cin>>n;
    ld x = (ld)n/3.0;
    ld v = x*x*x;

    cout<<fixed<<setprecision(10)<<v<<endl;
}       


int32_t main(){
    IOS;
    int t;
    t = 1;
    // precompute();
    // cin>>t;
    for(int tt=1;tt<=t;tt++){
        solve();
    }
    return 0;
}

/*

*/

Measured memory_bytes: 256
#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

def main():
    import sys
    input = sys.stdin.readline 
    n = int(input())
    p = list(map(int, input().split()))

    mi = 1000000000
    cnt = 0
    for i in range(n):
        if p[i] <= mi:
            cnt += 1
        if mi > p[i]:
            mi = p[i]
    print(cnt)

main()

Measured memory_bytes: 25992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    ll ans = 1;
    ll N; cin >> N;
    vector<ll> T(N), A(N);
    for(int i = 0; i < N; i++) cin >> T[i] >> A[i];

    for(int i = 1; i < N; i++){
        ll t1 = (A[i] + A[i-1] - 1)/ A[i], t2 = (T[i] + T[i-1] - 1) / T[i];
        //cout << t1 << ' ' << t2 << endl;
        A[i] *= max(t1, t2);
        T[i] *= max(t1, t2);
    }
    cout << T[N-1] + A[N-1] << endl;
}

Measured memory_bytes: 256
/**
 *    author:  Mohamad Milhem
**/

#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define MOD ll(1000000007)
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<endl;
#define decimalpoint cout << std::fixed << setprecision(5)


void solve(){
	int n;
	cin >> n;
	vector<long long> v(n);
	long long sum = 0;


	lp(i, 0 , n){
		cin >> v[i];
		sum+= v[i];
	}


	long long bigsum = 0;
	long long already = 0;


	lp(i , 0 , n){
		already+= v[i];
		bigsum+= (sum - already)%MOD * v[i]%MOD;
		bigsum%=MOD;
	}	

	cout << bigsum << endl;

}



int main()
{
    FAST;
    int t;
    t = 1;

    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 4792
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
using namespace std;
typedef long long ll;

void chmin(int &a, int b) { if (a > b) a = b; }

// コードはここから
int N, A, B, C;
int L[10];

int rec(int i, int a, int b, int c){
  if (i==N){
    if (a==0 || b==0 || c==0) return 1000000;
    else return abs(A-a) + abs(B-b) + abs(C-c);
  }

  // 注目している竹を使わない場合
  int res = rec(i+1, a, b, c);

  // 最初に使う竹を選ぶ場合は合成ではない
  // 竹が選ばれるのが2回目以降であれば10ポイントを消費する
  chmin(res, rec(i+1, a+L[i], b, c) + (a>0 ? 10:0));
  chmin(res, rec(i+1, a, b+L[i], c) + (b>0 ? 10:0));
  chmin(res, rec(i+1, a, b, c+L[i]) + (c>0 ? 10:0));

  return res;
}

int main(){
  cin >> N >> A >> B >> C;
  rep(i, N) cin >> L[i];

  cout << rec(0,0,0,0) << endl;
}


Measured memory_bytes: 3600
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left, bisect_right
from heapq import *
import sys
# sys.setrecursionlimit(1000000)
INF = 10 ** 17
MOD = 1000000007

from fractions import *
def inverse(f):
    # return Fraction(f.denominator,f.numerator)
    return 1/f


def combmod(n, k, mod=MOD):
    ret = 1
    for i in range(n - k + 1, n + 1):
        ret *= i
        ret %= mod

    for i in range(1, k + 1):
        ret *= pow(i, mod - 2, mod)
        ret %= mod

    return ret

def solve():
    n = getN()
    nums = getList()
    # 1段しかない
    if n == 0:
        if nums[0] == 1:
            print(1)
        else:
            print(-1)
        return
    # 1段目で終わり(かなしいね)
    if nums[0] > 0:
        print(-1)
        return

    acc = []
    tmp = 0
    for i , num in enumerate(nums[::-1]):
        tmp += num
        acc.append(tmp)
    acc.reverse()

    ans = 1
    ue = 1
    for i, num in enumerate(nums[1:-1]):
        if ue * 2 <= num:
            print(-1)
            return
        konodan = min(ue * 2, acc[i+1])
        # print(konodan)
        ans += konodan
        ue = konodan - num

    if ue * 2 < nums[-1]:
        print(-1)
        return

    print(ans + nums[-1])
    return


def main():
    # n = getN()
    # for _ in range(n):
    solve()
if __name__ == "__main__":
    solve()

"""
    12
    3 2
    3 2
    0 1
    2 -1
    -3 -9
    -8 12
    7 0
    8 1
    8 2
    8 4
    0 0
    0 0
"""

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(1e5) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)


int main() {
    string s;
    int t;
    cin >> s >> t;
    for(int i=0;i<s.size();i+=t){
        cout << s[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

int64_t N; cin >> N;

int64_t sum = 0;

for (int64_t i = 1; i * i < N; ++i)
    if (N / (N / i - 1) == N % (N / i - 1)) 
        sum += N / i - 1;

cout << sum << endl;
}

// 書いて考える
// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり



Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define f first
#define s second
#define pb push_back
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef vector<pair<int,int>> vii;
typedef vector<pair<ll,ll>> vll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

ll ppow(ll x,ll y,ll mod) {
    ll res=1;
    while(y) {
        if(y&1) res=res*x%mod;
        y>>=1;
        x=x*x%mod;
    }
    return res;
}



int main() {
    cout << fixed << setprecision(10);
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ld n; cin >> n;
    ld d=n/3,ans=d*d*d;
    cout << ans;
}


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

int main(){
  int n;cin >> n;
  vector<int> p(n),q(n);
  for (auto &&i : p)
  {
    cin >>i;
  }
  for (auto &&i : q)
  {
    cin >> i;
  }

  vector<int> tmp(n);
  for (int i = 0; i < n; i++)
  {
    tmp.at(i) = i+1;
  }

  ll count = 0;
  ll pnum = -1;
  ll qnum = -1;

  do
  {
    if(tmp == p) pnum = count;
    if(tmp == q) qnum = count;
    count++;
  } while (next_permutation(tmp.begin(),tmp.end()));
  

  cout << abs(pnum - qnum) << endl;
  
  

  
}


Measured memory_bytes: 256
import Data.Bool

main :: IO ()
main = do
  { [n,m,c] <- readLineInputs
  ; bs <- readLineInputs
  ; ass <- loop n
  ; print $ solve ass bs c
  }

loop :: Int -> IO [[Int]]
loop 0 = return []
loop n = do
  { xs  <- readLineInputs
  ; xss <- loop (pred n)
  ; return (xs:xss)
  }

{- |
>>> let [n,m,c] = map read (words "2 3 -10") :: [Int]
>>> let bs = map read (words "1 2 3") :: [Int]
>>> let ass = map (map read . words) (lines "3 2 1\n1 2 2")
>>> solve ass bs c
1
-}
solve :: [[Int]] -> [Int] -> Int -> Int
solve xss ys z = iter xss ys z 0
  where
    iter []       _  _ n = n
    iter (as:ass) bs c n = iter ass bs c $ bool n (succ n) (prod as bs + c > 0)

readLineInputs :: Read a => IO [a]
readLineInputs = map read . words <$> getLine

prod :: [Int] -> [Int] -> Int
prod = (sum .) . zipWith (*) 


Measured memory_bytes: 1020
h = [[[0]*10 for i in range(3)] for j in range(4)]
for i in range(int(input())):
    b,f,r,k = map(int,input().split())
    h[b-1][f-1][r-1]+=k
for i in range(4):
    for j in h[i]: print('',*j)
    if i<3: print('#'*20)



Measured memory_bytes: 5620
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
using namespace std;

struct Node{
    int key;
    Node *prev,*next;
};

Node *NIL;

void initList(){
    NIL = (Node *)malloc(sizeof(Node));
    NIL -> prev = NIL;
    NIL -> next = NIL;
}

void insert(int K){
    Node *x;
    x = (Node *)malloc(sizeof(Node));
    
    x -> key = K;
    x -> prev = NIL;
    x -> next = NIL -> next;
    
    x -> next -> prev = x;
    x -> prev -> next = x;
}

Node* find(int K){
    Node *Ser = NIL;
    Ser = Ser -> next;
    
    while (Ser != NIL) {
        if (Ser -> key == K) {
            return Ser;
        }
        Ser = Ser -> next;
    }
    return NIL;
}

void deleteNode(Node *t){
    if (t == NIL) return;
    t -> next -> prev = t -> prev;
    t -> prev -> next = t -> next;
    free(t);
}

void delete_x(int K){
    deleteNode(find(K));
}

void delete_first(){
    deleteNode(NIL -> next);
}

void delete_last(){
    deleteNode(NIL -> prev);
}

void printList(){
    Node *Ser = NIL;
    Ser = Ser -> next;
    if (Ser == NIL) return;
    
    while (Ser != NIL) {
        printf("%d",Ser -> key);
        if (Ser -> next != NIL) {
            printf(" ");
        }
        Ser = Ser -> next;
    }
    printf("\n");
}

int main(){
    char op[20];
    int N;
    cin >> N;
    initList();
    
    for (int i = 0; i < N; i++) {
        scanf("%s",op);
        int x;
        if (op[0] == 'i') {
            scanf("%d",&x);
            insert(x);
        }else{
            if (strlen(op) > 6) {
                if (op[6] == 'F') {
                    delete_first();
                }else{
                    delete_last();
                }
            }else{
                scanf("%d",&x);
                delete_x(x);
            }
        }
    }
    printList();
    return 0;
}

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

int main()
{
	string S, T;
	cin >> S >> T;
	reverse(T.begin(), T.end());
	if ( S == T ) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return ( 0 );
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }

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

    int i = 1;
    bool flag = true;
    for(char c : S){
        if(i % 2 == 0){
            if(c == 'R') flag = false;
        }else{
            if(c == 'L') flag = false;
        }
        i++;
    }

    cout << (flag ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const long long MAXN = 5e3+5;
bool visited[MAXN];
bool visited2[MAXN];
vector<pair<long long,long long>> v1[MAXN];
vector<long long> v2[MAXN];
long long dist[MAXN];

int main(){
    long long n,m,p;
    cin>>n>>m>>p;
    for(long long i=1;i<=m;i++){
        long long x,y,w;
        cin>>x>>y>>w;
        v1[x].push_back(make_pair(y,w-p));
        v2[y].push_back(x);
    }
    queue<long long> q1;
    q1.push(n);
    visited[n] = true;
    while(!q1.empty()){
        long long curr = q1.front();
        q1.pop();
        for(long long x:v2[curr]){
            if(!visited[x]){
                visited[x] = true;
                q1.push(x);
            }
        }
    }
    for(long long i=1;i<=n;i++){
        dist[i] = -1e18;
    }
    dist[1] = 0;
    visited2[1] = true;
    for(long long i=1;i<=n;i++){
        for(long long j=1;j<=n;j++){
            if(dist[j] == -1e18){
                continue;
            }
            for(auto k:v1[j]){
                long long nxt = k.first;
                visited2[nxt] = true;
                if(dist[nxt]<dist[j]+k.second){
                    dist[nxt] = dist[j] + k.second;
                }
            }
        }
    }
    for(long long i=1;i<=n;i++){
        for(auto j:v1[i]){
            long long k =j.first;
            if(dist[k] == -1e18||dist[i] == -1e18){
                continue;
            }
            if(dist[k]<dist[i]+j.second && visited[k]){
                cout<<-1<<endl;
                return 0;
            }
        }
    }
    cout<<max((long long)0,dist[n])<<endl;
}

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

int main() {
    int a,b,i,j;
    while (!((a==0)and(b==0))){
        cin >> a >> b;
        for (i=1;i<=a;i++){
            for (j=1;j<=b;j++)
                cout << '#';
            cout << endl;
        }
        if (!((a==0)and(b==0)))
            cout << endl;
    }
}


Measured memory_bytes: 3092
#include<stdio.h>
#include<math.h>
int N,x[10],y[10];
bool used[10];
double sum;

int fact(int n){
  int r=1;
  for(;n>0;n--){
    r = r*n;
  }
  return r;
}
double len(int i,int j){
  return sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
}
void next_town(int town ,int nd, double prev_len){
  int i;
  double to_len = 0.0;
  if(nd == N) {
    sum += prev_len;
    return;
  }
  for(i=0;i<N;i++){
    if(!used[i]){
      used[i] = true;
      if(town >= 0){
        to_len = len(town,i);
      }
      next_town(i,nd+1, prev_len+to_len);
      used[i] = false;
    }
  }
}


int main(){
  int i;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d%d",x+i,y+i);
  }
  sum = 0.0;
  next_town(-1,0,0.0);
  printf("%.8lf",sum/fact(N));
}

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

using namespace std;
typedef long long ll;

vector<vector<int>> generate_permutation(vector<int> &v){
    sort(v.begin(), v.end());
    int factorial = 1;
    for(int i=1;i!=v.size()+1;i++){
        factorial *= i;
    }
    int  cnt = 0;
    vector<vector<int>> permutation(factorial, vector<int>(v.size()));
    do{
        for(int i=0;i!=v.size();i++){
            permutation[cnt][i] = v[i];
        }
        cnt++;
    }while(next_permutation(v.begin(), v.end()));
    return permutation;
}

int main(){
    int v, e, R;
    cin >> v >> e >> R;

    vector<vector<int>> cost_graph(v, vector<int>(v,0));
    vector<vector<int>> path(v, vector<int>(v,0));
    vector<int> r(R,0);

    for(int i=0;i<R;i++){
        int tmp;
        cin >> tmp;
        r[i] = tmp;
    }

    for(int i=0;i<v;i++){
        for(int j=0;j<v;j++){
            cost_graph[i][j] = i==j ? 0 : 99999999;
            path[i][j] = j;
        }
    }

    for(int i=0;i<e;i++){
        int src, dst, cost;
        cin >> src >> dst >> cost;
        cost_graph[src-1][dst-1] = cost;
        cost_graph[dst-1][src-1] = cost;
    }


    for(int k=0;k<v;k++){
        for(int i=0;i<v;i++){
            for(int j=0;j<v;j++){
                if(cost_graph[i][k] + cost_graph[k][j] < cost_graph[i][j]){
                    cost_graph[i][j] = cost_graph[i][k] + cost_graph[k][j];
                    path[i][j] = path[i][k];
                }
            }
        }
    }

    vector<vector<int>> city = generate_permutation(r);

    int ans = 99999999;
    int factorial = 1;
    for(int i=1;i!=R+1;i++){
        factorial *= i;
    }
    for(int i=0;i<factorial;i++){
        int tmp = 0;
        for(int j=0;j<R-1;j++){
            tmp += cost_graph[city[i][j]-1][city[i][j+1]-1];
        }
        ans = min(ans,tmp);
    }
    cout << ans << "\n";

}


Measured memory_bytes: 3964
#include<stdio.h>

int main() {
	int n,calc,cnt,i,j,k,l;
	while (scanf("%d", &n) != EOF) {
		cnt = 0;
		for (i = 0; i < 10; i++) {
			for (j = 0; j < 10; j++) {
				for (k = 0; k < 10; k++) {
					for (l = 0; l < 10; l++) {
						if (i + j + k + l == n) {
							cnt++;
						}
					}
				}
			}
		}
		printf("%d\n", cnt);
	}
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n,m;cin>>n>>m;
  int ans=n*(n-1)+m*(m-1);
  cout<<ans/2<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd>> Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod

vec unable={-1};
vec Solve(){
    ll N,M; cin>>N>>M;
    string S; cin>>S;
    vec d;
    rep(i,N+1) if(S[i]=='0') d.pb(i);
    ll A=d.size();
    rep(i,A-1) if(d[i+1]>d[i]+M) return unable;
    vec L(A,0), R(A,0);
    REP(i,1,A){
        ll x=lower_bound(ALL(d),d[i]-M)-d.begin();
        L[i]=L[x]+1;
    }
    //cout<<"Steps is "<<L[A-1]<<endl;
    vec ret;
    for(int i=A-2; i>=0; i--){
        ll x=upper_bound(ALL(d),d[i]+M)-d.begin();
        x--;
        R[i]=R[x]+1;
        //if(R[i]<=ret.size() && L[i]+R[i]==L[A-1]) ret.pb(d[i]);
    }
    ll count=0, l=0;
    rep(i,A){
        if(L[i]+R[i]==R[0]) if(L[i]>l){
            ret.pb(d[i]-count);
            count=d[i];
            l++;
        }
    }
    return ret;

}

int main(){
    vec ans=Solve();
    rep(i,ans.size()) cout<<ans[i]<<endl;
}

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

int debug =0;

int main()
{
    int n;
    string st;
    map<string,int> mp;

    cin >> n;
    rep(i,n){
        cin >> st;
        auto itr = mp.find(st);
        if(itr != mp.end()){// found
            int val = itr->second;
            itr->second = val+1;
        }else{ // not found
            mp[st]=1;
        }
    }

    if(debug){
        for(auto itr = mp.begin();itr !=mp.end();++itr){
            cout << "<" << itr->first << "," << itr-> second << ">" <<endl;
        }

    }

    cout << mp.size() << endl;
    return 0;
}

Measured memory_bytes: 19072
n = int(input())
if n == 1:
  print(0)
  exit()

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

def is_prime(n):
  if n <= 1: return False
  for i in range(2, int(n**0.5)+1):
    if n%i == 0: return False
  return True

x = make_divisors(n)[1:]
if len(x)==1:
  print(1)
  exit()

cnt = 0
numbers = []
for a in x:
  if is_prime(a):
    n //= a
    b = 2
    cnt += 1
    while n%(a**b)==0:
      numbers.append(a**b)
      b += 1
  if a in numbers:
    if n%a==0: 
      n //= a
      cnt += 1
print(cnt)

Measured memory_bytes: 9528
#include <iostream>
#include <string>
int main() {
	int a, b, n, heihou = 2;
	std::string str;

		std::cin >> a >> b;
		str += (std::to_string(a) + std::to_string(b));
		n = std::stoi(str);


		for (int i = 0; i < 100000; i++) {
			if (n / heihou == heihou && n%heihou == 0) {
				std::cout << "Yes" << std::endl;
				return 0;
			}
			heihou++;
		}


		std::cout << "No" << std::endl;
		return 0;
}

Measured memory_bytes: 256
from collections import deque
n = int(input())
V = [[] for i in range(n+1)]
for i in range(n-1):
    u,v,w = map(int,input().split())
    V[u].append([v,w])
    V[v].append([u,w])
q = deque([])
dis = [-1]*(n+1)
q.append(1)
dis[1] = 0
while q:
    x = q.popleft()
    for y,z in V[x]:
        if dis[y] == -1:
            q.append(y)
            dis[y] = dis[x] + z
for i in range(1,n+1):
    if dis[i]%2 == 0:
        print(0)
    else:
        print(1)

Measured memory_bytes: 50800
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#define max(a,b) ((a>b)?(a):(b))
#define min(a,b) ((a<b)?(a):(b))
#define abs(x) (((x)<0)?(-(x)):(x))

using namespace std;


int main(){
    int N;
    long *a,*b,*c;
    cin >> N;
    a = new long[N];
    b = new long[N];
    c = new long[N];
    for(int i=0;i<N;i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    for(int i=1;i<N;i++){
        a[i]+=max(b[i-1],c[i-1]);
        b[i]+=max(c[i-1],a[i-1]);
        c[i]+=max(a[i-1],b[i-1]);
    }
    cout<<max(a[N-1],max(b[N-1],c[N-1]));
    
    delete[] a;
    delete[] b;
    delete[] c;
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <cmath>

using namespace std;

const long long INF = 1ll << 60;
long long dp[100000] = {};
long long h[100000] = {};

int rec(int index) {
    if(dp[index] < INF) return dp[index];
    else {
        int tmp = min(
            rec(index-1) + abs(h[index] - h[index-1]),
            rec(index-2) + abs(h[index] - h[index-2])
        );
        dp[index] = tmp;
        return tmp;
    }
}

int main() {
    // Input
    int N; cin >> N;
    for(int i = 0; i < N; ++i) cin >> h[i];

    // 初期条件
    dp[1] = abs(h[1] - h[0]);
    for(int i = 2; i < N; ++i) dp[i] = INF;

    cout << rec(N-1) << endl;
}


Measured memory_bytes: 3328