akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

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

		int a = in.nextInt();
		int b = in.nextInt();
		int h = in.nextInt();
		int m = in.nextInt();

		double x1 = (double)a * Math.sin(2.0*Math.PI*((double)h/12.0 + (double)m/60.0/12.0));
		double y1 = (double)a * Math.cos(2.0*Math.PI*((double)h/12.0 + (double)m/60.0/12.0));

		double x2 = (double)b * Math.sin(2.0*Math.PI*(double)m/60.0);
		double y2 = (double)b * Math.cos(2.0*Math.PI*(double)m/60.0);

		System.out.println(Math.sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)));
	}
}



Measured memory_bytes: 35808
module Main where
import Data.Char
int = read :: String -> Int
getWord :: IO String
getWord = do
  c <- getChar
  if isSpace c
  then
    return []
  else do
    ws <- getWord
    return (c:ws)
getInt = fmap int getWord
replace pred a = map (\x -> if pred x then a else x)

main = interact $ printer . solver . parser
parser = map int . words
printer = unlines . (:[])

solver [n,a] = if n`mod`500 <= a then "Yes" else "No"

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

int main() {
  int n, m;
  cin >> n >> m;
  int p, y;

  map<pair<int, int>, int> d;

  for (int i = 0; i < m; i++) {
    cin >> p >> y;
    d[make_pair(p, y)] = i;
  }

  map<int, pair<int, int>> ans;
  int pnum = 0, count = 1;
  for (auto iter = begin(d); iter != end(d); ++iter) {
    if (iter->first.first == pnum)
      count++;
    else
      count = 1;
    pnum = iter->first.first;
    ans[iter->second] = make_pair(pnum, count);
  }

  for (auto iter = begin(ans); iter != end(ans); ++iter) {
    cout << setfill('0') << right << setw(6) << iter->second.first;
    cout << setfill('0') << right << setw(6) << iter->second.second << endl;
  }
}


Measured memory_bytes: 13952
main = do
    [a1, a2, a3] <- map read . words <$> getLine
    let ans = foldl1 min $ [abs (a1 - a2) + abs (a2 - a3), abs (a1 - a2) + abs (a1 - a3), abs (a1 - a3) + abs (a2 - a3)]
    putStrLn $ show ans


Measured memory_bytes: 508
#include <iostream>
#include <iomanip>
#include <cassert>

#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <limits>
#include <unordered_map>
using namespace std;

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

void Main()
{
	int N;
	cin >> N;
	unordered_map<string, int> K;
	rep(i, N)
	{
		string s;
		cin >> s;
		++K[s];
	}

	int M;
	cin >> M;
	rep(i, M)
	{
		string s;
		cin >> s;
		--K[s];
	}

	int max_e = numeric_limits<int>::min();
	for (auto e : K)
	{
		max_e = max(max_e, e.second);
	}

	cout << max(0, max_e) << endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);

	Main();
	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
d=dict()
s=sum(a)
for i in a:
    if i in d:
        d[i]+=1
    else:
        d[i]=1
for i in range(int(input())):
    b,c=map(int,input().split())
    if b in d:
        print(s:=s+(c-b)*d[b])
        if c in d:
            d[c]+=d[b]
        else:
            d[c]=d[b]
        d[b]=0
    else:
        print(s)

Measured memory_bytes: 20932
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define MOD 1000000007
 
typedef long long ll;
typedef pair<int, int> ii;

int main() {

	ll n;
	cin >> n;
	vector<ll> v(n);
	rep(i, n) cin >> v[i];
	
	SORT(v);
	
	bool flag = true;
	
	if(n % 2 == 0){
		for(int i = 0; i * 2 < n; i++){
			if(v[i*2] != i*2+1 || v[i*2+1] != i*2+1){
				flag = false;
				break;
			}
		}
	}else{
		if(v[0] != 0){
			flag = false;
		}
		else{
			for(int i = 1; i * 2 < n; i++){
				if(v[i*2-1] != i*2 || v[i*2] != i*2){
					flag = false;
					break;
				}
			}
		}
	}
	
	if(flag){
		ll ans = 1;
		for(int i = 0; i*2<n-1; i++) ans = (ans * 2) % MOD;
		cout << ans << endl;
	}
	else cout << 0 << endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long int ll;

int main()
{
	int A,B,C,D,E,F;
	cin>>A>>B>>C>>D>>E>>F;
	int a = 100*A;
	int b = 100*B;
	vector<int> alpha;
	vector<int> beta;
	for(int i = 0; a*i <= F; i++){
		for(int j = 0; a*i + b*j <= F; j++){
			alpha.push_back(a*i + b*j);
		}
	}
	sort(alpha.begin(),alpha.end());
	alpha.erase(unique(alpha.begin(),alpha.end()),alpha.end());
	/*for(auto iter = alpha.begin(); iter != alpha.end(); iter++){
		cout<<*iter<<endl;
	}*/
	for(int i = 0; C*i <= F; i++){
		for(int j = 0; C*i + D*j <= F; j++){
			beta.push_back(C*i + D*j);
		}
	}
	sort(beta.begin(),beta.end());
	beta.erase(unique(beta.begin(),beta.end()),beta.end());
	

	int maxAlpha = 0;
	int maxBeta = 0;
	double maxConcentration = 0;
	for(auto iterA = alpha.begin(); iterA != alpha.end(); iterA++){
		for(auto iterB = beta.begin(); iterB!= beta.end(); iterB++){
			if( (*iterA + *iterB <= F) && (*iterA * E) >= (100*(*iterB))){
				double concentration = 0;
				if( *iterA + *iterB != 0){
					concentration = (double)(*iterB) / (double)(*iterA + *iterB);
					//cout<<"alpha + beta: "<<*iterA + *iterB<<", concentration:"<<concentration<<endl;
				}
				if( concentration > maxConcentration){
					maxAlpha = *iterA;
					maxBeta = *iterB;
					maxConcentration = concentration;
				}
			}
		}
	}
	if( maxAlpha == 0 && maxBeta == 0){
		cout<<min(a,b)<<" "<<0<<endl;
	}else{
		cout<<maxAlpha+maxBeta<<" "<<maxBeta<<endl;
	}

	return 0;
}


Measured memory_bytes: 3820
#include <iostream>
#include <vector>
#include <numeric>
#include <string>
using namespace std;


int main(void){
    long long N, X, M;
    cin >> N >> X >> M;
    
    vector<long long> A(2*M+1);
    A[1]=X;
    for(int i=1; i<2*M; i++){
        A[i+1]=A[i]*A[i]%M;
    }
    
    long long ans=0;
    if(N<=2*M){
        for(int i=1; i<=N; i++){
            ans += A[i];
        }
        cout << ans << endl;
        return 0;
    }
    
    long long cycle=0, sum=0, start=0;
    for(int i=2*M-1; i>=M; i--){
        if(A[i]==A[2*M]){
            cycle = 2*M-i;
            start=i+1;
            for(int j=i; j<2*M; j++){
                sum += A[j];
            }
            break;
        }
    }
    
    for(int i=1; i<=2*M; i++){
            ans += A[i];
    }
    ans += sum * ((N-2*M)/cycle);
    long long d=(N-2*M)%cycle;
    for(int i=start; i<start+d; i++){
        ans += A[i];
    }
    
    cout << ans << endl;
    
    
    return 0;
}


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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define ub upper_bound
#define lb lower_bound
#define bit __builtin_popcount
#define memset(x) memset(x,0,sizeof(x))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vector<int>> matrix;

inline void boost(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const ll maxn=2e5+123;
const ll inf=1e9+123;
const ll linf=1e18+123;
const ll mod=1e9+7;
const double eps=1e-9;
const double pi=acos(-1);
int dx[8]={0,1,-1,0,1,-1,1,-1};
int dy[8]={1,0,0,-1,1,1,-1,-1};

int main(){
    boost();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n,m;
    cin>>n>>m;
    if((n-1)*(n-2)/2<m){
        cout<<"-1";
        return 0;
    }
    int q=(n-1)*(n-2)/2-m;
    cout<<n-1+q<<"\n";
    for(int i=1;i<n;i++){
        cout<<i<<" "<<n<<"\n";
    }
    int l=1,r=2;
    while(q--){
        cout<<l<<" "<<r<<"\n";
        r++;
        if(r==n){
            l++;
            r=l+1;
        }
    }
    exit(0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int N;
  cin >> N;
  
  if(N % 1000 % 111 == 0){
    cout << "Yes" << endl;
  }
  else if(N / 10 % 111 == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

//-----------------------------------------------------------------------------

int n;
string s,t;

int check(int i,int j) {
	int res=n-i;
	while(i<n) {
		if(s[i]!=t[j]) return 0;
		i++,j++;
	}
	return res;
}

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

	cin>>n>>s>>t;
	int ma=0;
	REP(i,n) {
		REP(j,n) {
			if(s[i]==t[j]) {
				if(s[n-1]==t[j+(n-i-1)]) ma=max(check(i,j),ma);
			}
		}
	}
	cout<<2*n-ma<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

#define REP(i, n) for (int i = 0; i < n; i++) 
#define REP2(i, n) for (int i = n - 1; i >= 0; i--)

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int n;
    cin >> n;
    int x = n * 800;
    int y = (n / 15) * 200;
    cout << x - y << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
int n,k,i,j,t,m,a[201],b[201];
scanf("%d",&n);
for(i=1;i<=2*n;i++){
a[i]=i;
}
scanf("%d",&m);
for(i=0;i<m;i++){
scanf("%d",&k);
if(k==0){
t=1;
j=1;
while(1){
b[j]=a[t];
b[j+1]=a[n+t];
t++;
j+=2;
if(j>=2*n+1)break;
}
for(j=1;j<=2*n;j++){
a[j]=b[j];
}
}
else if(1<=k && k<=2*n-1){
t=1;
for(j=k+1;j<=2*n;j++){
b[t]=a[j];
t++;
}
for(j=1;j<=k;j++){
b[t]=a[j];
t++;
}
for(j=1;j<=2*n;j++){
a[j]=b[j];
}
}
}
for(i=1;i<=2*n;i++){
printf("%d\n",a[i]);
}
return 0;
}

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

int main(){
  
  int N,M;
  cin>>N>>M;
  vector<int>k(M);
  vector<vector<int>>s(M,vector<int>(N));
  vector<int>p(M);
  
  for(int i=0;i<M;i++){
    cin>>k[i];
    for(int j=0;j<k[i];j++){
      cin>>s[i][j];
    }
  }
  
  for(int i=0;i<M;i++){
    cin>>p[i];
  }
  
  int ans=0;
  for(long long int i=0;i<pow(2,N);i++){
    bitset<10>b(i);
    string B=b.to_string();
    int chk=0;
    
    for(int j=0;j<M;j++){
      int sum=0;
      for(int l=0;l<k[j];l++){
if(B[s[j][l]+9-N]=='1'){
  sum++;
}
      }
      if(sum%2!=p[j]){
        break;
      }
      chk++;
    }
    
    if(chk==M){
ans++;
    }
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll dp[101][101010];


int main(){
    int k,n;
    cin>>k>>n;
    vector<int> a;
    REP(i,1,100000){
        if(i*i>k)break;
        a.push_back(i);
        a.push_back(k/i);
    }
    a.push_back(0);
    sort(a.begin(),a.end());
    int m = a.size();
    dp[0][0]=1;
    rep(i,n){
        rep(j,m)(dp[i][j+1]+=dp[i][j])%=mod;
        rep(j,m-1){
            int idx = m-j-2;
            dp[i+1][j]=dp[i][idx]*(a[j+1]-a[j])%mod;
        }
    }
    ll ans = 0;

    rep(i,m)ans += dp[n][i];
    cout<<ans%mod<<endl;
    return 0;
}

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

using namespace std;

int main()
{
    string str;
    cin >> str;
    for (int i = 0; i < str.size(); ++i){
        if(i==4){
            cout << " ";
        }
        cout << str[i];
    }
    cout <<"\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
#include <deque>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;
Graph G;
const int AMAX = 100000;
/*int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}



int n;
vll a;

ll solve(bool isp)
{
	ll sum = 0ll;
	ll ret = 0ll;

	for (int i = 0; i < n; i++)
	{
		sum += a[i];
		if (isp and sum <= 0)
		{
			ret += -sum + 1;
			sum = 1ll;
		}
		if (not isp and sum >= 0)
		{
			ret += sum + 1;
			sum = -1ll;
		}
		isp ^= 1;
	}
	return ret;
}

*/


/*
 * 最大公約数計算
 */
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N;
	cin >> N;
	vector<ll> data(N);
	for (int i = 0; i < N; i++)
	{
		cin >> data[i];
	}
	
	ll ans = 1ll;
	for (int i = 0; i < N; i++)
	{
		ans = lcm(ans, data[i]);
	}

	cout << ans << endl;
	
	return 0;

	


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if ((A + B) > (C + D)) {
  	cout << "Left" << endl;
  }
  else if ((A + B) < (C + D)) {
  	cout << "Right" << endl;
  }
  else if ((A + B) == (C + D)) {
  	cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
H, W = map(int, input().split())
s = [input() for i in range(H)]

def count(x, y):
    c = 0
    if x-1 >= 0 and s[x-1][y] =="#":
        c += 1
    if x+1 <= H-1 and s[x+1][y] =="#":
        c += 1
    if y-1 >= 0 and s[x][y-1] =="#":
        c += 1
    if y+1 <= W-1 and s[x][y+1] =="#":
        c += 1
    if x-1 >= 0 and y-1>=0 and s[x-1][y-1] =="#":
        c += 1
    if x-1 >= 0 and y+1 <= W-1 and s[x-1][y+1] =="#":
        c += 1
    if x+1 <= H-1 and y-1 >=0 and s[x+1][y-1] =="#":
        c += 1
    if x+1 <= H-1 and y+1 <= W-1 and s[x+1][y+1] =="#":
        c += 1
    return c

ans = [[None] * W for i in range(H)]
for i in range(H):
    for j in range(W):
        ans[i][j] = count(i, j)

for i,line in enumerate(ans):
    for j,num in enumerate(line):
        if s[i][j] == "#":
            print("#", end="")
        else:
            print(num, end="")
    print()

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

const int INF = 1 << 30;

int N, K;
int h[100010];

int dp[100010];

int main() {
    cin >> N >> K;
    for(int i = 1; i <= N; i++)
        cin >> h[i];

    for(int i = 0; i < 100010; i++)
        dp[i] = INF;

    dp[1] = 0;
    for(int i = 1; i <= N; i++)
        for(int j = 1; j <= K; j++)
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));

    cout << dp[N] << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

class Main {
    private static void solve() {
        Scanner scanner = new Scanner(System.in);
        int[] days = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
        String[] map = { "Wednesday", "Thursday", "Friday",
            "Saturday", "Sunday", "Monday", "Tuesday" };

        while (true) {
            int month = scanner.nextInt();
            int day = scanner.nextInt();
            if (month == 0 && day == 0) {
                break;
            }
            int total = 0;
            for (int i = 0; i < month - 1; i++) {
                total += days[i];
            }
            total += day;
            System.out.println(map[total % 7]);
        }
    }

    public static void main(String... args) {
        solve();
    }
}

Measured memory_bytes: 0
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <queue>
#include <cmath>
using namespace std;

int main() {
        int n, m;
        scanf("%d %d", &n, &m);
        vector<vector<int>> g(n);
        vector<int> a(n);
        for (int i = 0; i < n; i ++) {
                scanf("%d", &a[i]);
        }
        for (int i = 0; i < m; i ++) {
                int a, b;
                scanf("%d %d", &a, &b);
                g[a].push_back(b);
                g[b].push_back(a);
        }
        vector<bool> used(n, false);
        vector<int> tmp;
        function<void (int)> dfs = [&](int u) {
                tmp.push_back(a[u]);
                for (auto v : g[u]) if (!used[v]) {
                        used[v] = true;
                        dfs(v);
                }
        };
        vector<vector<int>> s;
        for (int i = 0; i < n; i ++) {
                tmp.clear();
                if (!used[i]) {
                        used[i] = true;
                        dfs(i);
                }
                if (!tmp.empty()) s.push_back(tmp);
        }
        int k = (int) s.size();
        if (n < 2 * (k - 1)) {
                puts("Impossible");
                return 0;
        }
        if (k == 1) {
                printf("%d\n", 0);
                return 0;
        }
        int need = 2 * (k - 1);
        long long ans = 0;
        priority_queue<long long> que;
        for (auto st : s) {
                sort(st.begin(), st.end());
                ans += (long long) st[0];
                for (int i = 1; i < st.size(); i ++) {
                        que.push(-st[i]);
                }
                need --;
        }
        while (need --) {
                ans -= que.top();
                que.pop();
        }
        printf("%lld\n", ans);
        return 0;
}



Measured memory_bytes: 9652
#include <iostream>

using namespace std;

int main()
{
  int n;
  cin >> n;
  bool can=false;
  for(int i=1; i <=9; ++i)
  {
    if (n%i==0) 
    {
      if (n/i >=1 && n/i <=9) can=true;
    }
  }
  if (can) cout << "Yes"; else cout << "No";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define rt return
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
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;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n;
int a[maxn];
void solve(int l,int r,int k)
{
	repd(i,l,r)
	{
		a[i]-=k;
	}
}
int main()
{
    gg(n);
    repd(i,1,n)
    {
    	gg(a[i]);
    }
    int ans=0;
    repd(i,1,n)
    {
    	int mi=inf;
    	int l=1;int r=n;
    	repd(j,1,n)
    	{
    		if(a[j]==0)
    		{
    			if(mi==inf)
    			{	l=j+1;continue;}
    			else
    			{	r=j-1;break;}
    		}else
    		{
    			mi=min(mi,a[j]);
    		}
    		if(j==n)
    		{
    			r=n;
    		}
    	}
    	if(l<=r)
    	{
    		ans+=mi;
    		solve(l,r,mi);
    	}else
            break;
    }
    printf("%d\n",ans );
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



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

int main(){
	int a[3];
	scanf("%d%d%d",&a[0],&a[1],&a[2]);
	if(a[0]==a[1]&&a[0]==a[2]){
		printf("1");
	}
	else if(a[0]!=a[1]&&a[1]!=a[2]&&a[2]!=a[0]){
		printf("3");
	}
	else{
		printf("2");
	}
} 

Measured memory_bytes: 128
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    CIN(a);CIN(b);CIN(h);
    COUT((a+b)*h/2);
    return 0;
}




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

int main() {
  int64_t N, sum = 1, tate_prev;
  string S1, S2;
  cin >> N >> S1 >> S2;
  for (int i = 0; i < N; ++i) {
    int x, tate = S1[i] == S2[i];
    if (i == 0) {
      x = tate ? 3 : 6;
    } else {
      if (tate)
        x = tate_prev ? 2 : 1;
      else
        x = tate_prev ? 2 : 3;
    }
    if (!tate) ++i;
    sum = sum * x % 1000000007;
    tate_prev = tate;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n,x,cnt,i,j,k;

  while(1){
    cnt = 0;
    scanf("%d%d", &n, &x);
    if(n == 0 && x == 0)
      break;
    for(i=1; i<=n; i++)
      for(j=1; j<=n; j++)
	for(k=1; k<=n; k++)
	  if(i+j+k == x && i != j && j != k && k != i)
	    cnt++;
        
    printf("%d\n",cnt/6);
  }
  
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define rep(i,n) for(int i=0;i<(n);i++)
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); \
                                                  it != container.end(); ++it)
#define mp(a,b) make_pair((a),(b))

typedef long long ll;
typedef complex<double> point;

// up right down left
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};

const double EPS = 1e-9;
const int days[]     = {31,28,31,30,31,30,31,31,30,31,30,31};
const int daysleap[] = {31,29,31,30,31,30,31,31,30,31,30,31};

int main(){
    int Q;
    cin >> Q;
    rep(i,Q){
        ll N;
        cin >> N;
        int R=0;
        set<ll> S;
        S.insert(N);
        bool ok = true;
        while(N >= 10){
            stringstream ss;
            ss << N;
            string s;
            ss >> s;
            ll maxi = -1;
            for(int i=1;i<s.length();i++){
                string front = s.substr(0,i);
                string back = s.substr(i);
                ll ifront,iback;
                stringstream ss;
                ss << front;
                ss >> ifront;
                ss.clear();
                ss << back;
                ss >> iback;
                maxi = max(maxi,ifront*iback);
            }
            N = maxi;
            R++;
            if(!S.insert(N).second){
                ok = false;
                break;
            }
        }
        if(ok){
            cout << R << endl;
        }else{
            cout << -1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1244
#include<bits/stdc++.h>
#define endl '\n'
#define PI 3.14159265358979323844
#define DECIMAL(n)  std::cout << std::fixed;std::cout << std::setprecision(n);
#define mp make_pair
#define pb push_back
#define int long long int 
#define forr(i,a,b) for (int i= a; i <b; ++i)
    using namespace std; 
    int dp[4000][4000];

int mixtures(int * a, int s ,int e){
        if(s>e)return 0;
        if (dp[s][e]!=-1)return dp[s][e]; 
      dp[s][e]=max( (a[s]+min(mixtures(a,s+2,e), mixtures(a,s+1,e-1))), (  a[e]+min(mixtures(a,s+1,e-1),mixtures(a,s,e-2))));
      return dp[s][e]; 
    }
    
    signed main(){
        int n;cin>>n; int sum=0;
        int a[n];forr(i,0,n) {cin>>a[i];sum+=a[i];}
        memset(dp,-1, sizeof dp);
        cout<< (2*mixtures(a,0,n-1) -(sum));
    }

Measured memory_bytes: 125440
Q = int(input())

queries = [list(map(int, input().split())) for _ in range(Q)]

max_num = 0
for _, r in queries:
    max_num = max(max_num, r)


is_prime = [True] * (max_num + 1)
is_prime[0] = False
is_prime[1] = False

for i in range(2, max_num + 1):
    if not is_prime[i]:
        continue

    cnt = 2
    while i * cnt <= max_num:
        is_prime[i * cnt] = False
        cnt += 1

nums_like = [0] * (max_num + 1)
cnt = 0
for i in range(1, max_num + 1):
    if i % 2 == 0:
        nums_like[i] = nums_like[i - 1]
    else:
        if is_prime[i] and is_prime[(i + 1) // 2]:
            cnt += 1

        nums_like[i] = cnt


for l, r in queries:
    print(nums_like[r] - nums_like[l - 1])


Measured memory_bytes: 29032
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define MAX 1000000000000000000
int main() {
    int N;
    cin >> N;
    ll A[N];
    rep(i, N) cin >> A[i];
    sort(A,A+N);

    ll answer = 1;
    rep(i, N) {
        if(A[i] == 0) {
            answer = 0;
            break;
        } else if(MAX / answer < A[i]) {
            answer = -1;
            break;
        } else {
            answer *= A[i];
        }
    }

    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 4420
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int[] count = new int[200001];
        for (int i = 0; i < n; i++) {
            count[a[i]]++;
        }
        Arrays.sort(count);
        int ans = 0;
        for (int i = 200000 - k; i >= 0; i--) {
            if (count[i] != 0)
                ans += count[i];
            else
                break;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 74620
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 62;

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

inline bool is_prime(long long x) {
  if (x <= 1) return false;
  for (long long i = 2; i*i <= x; ++i) if (x % i == 0) return false;
  return true;
}

bool table[100010] = {};
int acc[100010] = {};

void calc() {
  for (int i = 1; i < 100010; i += 2) {
    if (is_prime(i) and is_prime((i+1)/2)) table[i] = true;
  }
  rep(i, 100000) acc[i+1] = acc[i] + table[i+1];
}

int main() {
  int q; cin>>q;
  calc();
  rep(i, q) {
    int l, r; cin>>l>>r;
    print(acc[r] - acc[l-1]);
  }
  return 0;
}


Measured memory_bytes: 1152
#include<stdio.h>

main(){
int arr[100],N;
int i,sw;

scanf("%d",&N);
for(i=0;i<N;i++)scanf("%d",&arr[i]);

sw=Sort(arr,N);

for(i=0;i<N;i++){
if(i>0)printf(" ");
printf("%d",arr[i]);
}
printf("\n");
printf("%d\n",sw);

return 0;
}

int Sort(int arr[],int N){
int i,j;
int k,sw=0;
int minj;

for(i=0;i<N-1;i++){
minj=i;
for(j=i;j<N;j++){
if(arr[j]<arr[minj])minj=j;
}
k=arr[i];
arr[i]=arr[minj];
arr[minj]=k;
if(i!=minj)sw++;
}
return sw;
}

Measured memory_bytes: 604
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
//
//class UnionFind {
//private:
//    int sz;
//    vector<int> par, size_;
//public:
//    UnionFind(){}
//    UnionFind(int node_size) : sz(node_size), par(sz), size_(sz, 1){
//        iota(par.begin(), par.end(), 0);
//    }
//    int find(int x){
//        if(par[x] == x) return x;
//        else return par[x] = find(par[x]);
//    }
//    void unite(int x, int y){
//        x = find(x); y = find(y);
//        if(x == y) return;
//        if(size_[x] < size_[y]) swap(x,y);
//        par[y] = x;
//        size_[x] += size_[y];
//    }
//    int size(int x){
//        x = find(x);
//        return size_[x];
//    }
//    bool same(int x, int y){
//        return find(x) == find(y);
//    }
//};
//void no(){
//    cout << "Impossible" << endl;
//    exit(0);
//}
//int main(){
//    cin.tie(nullptr);
//    ios::sync_with_stdio(false);
//    int n, m;
//    cin >> n >> m;
//    vector<vector<int>> g(n);
//    vector<int>a(n);
//    rep(i,n)cin >> a[i];
//    rep(i,m){
//        int x, y;
//        cin >> x >> y;
//        x--;y--;
//        g[x].push_back(y);
//        g[y].push_back(x);
//    }
//    if(m == n - 1){
//        cout << 0 << endl;
//        return 0;
//    }
//    if(n / 2 < n - m - 1){
//        no();
//    }
//}
int main(){
    double r;
    cin >> r;
    printf("%.10lf\n", 2 * r * M_PI);
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ll long long
#define P pair<int,int>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
const int INF = 2002002002;
const ll LLINF = 9009009009009009009;
using namespace std;

int main() {
    fast_io
    ll n;
    cin >> n;
    vector<ll> a(n+1), node(n+1), total(n+1);
    rep(i,n+1) cin >> a[i];
    if (a[0] > 1) {cout << "-1" << endl; return 0;}
    total[n] = a[n];
    for (int i = n-1; i >= 0; i--) {
        node[i] = total[i+1];
        total[i] = node[i] + a[i];
    }
    ll reduce;
    total[0] = 1;
    node[0] = total[0] - a[0];
    for (int i = 0; i < n; i++) {
        reduce = max(total[i+1] - node[i]*2, 0LL);
        node[i+1] -= reduce;
        if (node[i+1] < 0) {cout << "-1" << endl; return 0;}
        total[i+1] = node[i+1] + a[i+1];
    }
    ll ans = 0;
    rep(i,n+1) ans += total[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5576
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    cin >> N;
    VEC(int) Answer(N + 1);
    FOR(i, 0, N) {
        int count;
        cin >> count;
        Answer[count] = i + 1;
    }

    FOR(i, 1, N + 1)
        cout << Answer[i] << " ";
    cout << endl;
    return 0;
};


Measured memory_bytes: 1280
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000
#define df 0
int dc=10000;
int main(){
  int h,w;
  scanf("%d%d",&h,&w);
  int i,j;

  int mat[h+1][w+1],a[h+1][w+1],b[h+1][w+1];
  /*
  for(i=0;i<h;i++){
    mat[i]=(int *)malloc(sizeof(int)*(w+h));
    a[i]=(int *)malloc(sizeof(int)*(w+h));
    b[i]=(int *)malloc(sizeof(int)*(w+h));
  }
  */
  char ss[MAX+1];
  for(i=0;i<h;i++){
    dc-=df;if(dc<0){printf("A");break;}
    scanf("%s",ss);
    for(j=0;j<w;j++){
    dc-=df;if(dc<0){printf("B");break;}
      if(ss[j]=='.')mat[i][j]=0;
      else mat[i][j]=1;
    }
  }
  if(df){
    for(i=0;i<h;i++){
    dc-=df;if(dc<0){printf("C");break;}
      for(j=0;j<w;j++){
    dc-=df;if(dc<0){printf("D");break;}
	printf("%d",mat[i][j]);
      }
      printf("\n");
    }
  }
  int s;
  if(df)printf("\na:\n");

  for(i=0;i<h;i++){
    dc-=df;if(dc<0){printf("E");break;}
    j=0;
    int jj=0;
    s=0;
    while(j<w){
      dc-=df;if(dc<0){printf("F");break;}
      if(mat[i][j]==1){
	for(;jj<j;jj++){
	  dc-=df;if(dc<0){printf("G");break;}
	  a[i][jj]=s;
	  if(df)printf("%d",s);
	}
	a[i][j]=0;
	if(df)printf("#");
	jj=j+1;
	s=0;
      }
      else{
	s++;
      }
      j++;
    }
    for(;jj<j;jj++){
      dc-=df;if(dc<0){printf("H");break;}
      a[i][jj]=s;
      if(df)printf("%d",s);
    }
    if(df)printf("\n");
  }


  for(j=0;j<w;j++){
    i=0;
    int ii=0;
    s=0;
    while(i<h){
      if(mat[i][j]==1){
	for(;ii<i;ii++){
	  b[ii][j]=s;
	}
	b[i][j]=0;
	ii=i+1;
	s=0;
      }
      else{
	s++;
      }
      i++;
    }
    for(;ii<i;ii++){
      b[ii][j]=s;
    }
  }

  if(df){
    printf("\nb:\n");
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	printf("%d",b[i][j]);
      }
      printf("\n");
    }
  }

  
  int m=0;
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(a[i][j]+b[i][j])
      if(m<a[i][j]+b[i][j])m=a[i][j]+b[i][j];
    }
  }
  printf("%d",m-1);
  /*  
  free(mat);
  free(a);
  free(b);
  */
}


Measured memory_bytes: 47104
n,m = map(int,input().split())
p_lists = [list(map(str,input().split())) for _ in range(m)]

# print(p_list)

AC_count = 0
WA_count = 0

AC_question = set()
WA_question = dict()

for p_list in p_lists:
    if p_list[0] in AC_question:
        continue

    if p_list[1] == 'AC':
        AC_count += 1

        if p_list[0] in WA_question:
            WA_count += WA_question[p_list[0]]

        AC_question.add(p_list[0])

    if p_list[1] == 'WA':
        if p_list[0] in WA_question:
            WA_question[p_list[0]] = WA_question[p_list[0]] + 1
        else:
            WA_question[p_list[0]] = 1

print(AC_count, WA_count)
    


Measured memory_bytes: 38292
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  int p, q, r;
  readf("%d %d %d\n", &p, &q, &r);
  writeln(min(min(p + q, p + r), q + r));
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
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/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, Q;
	cin >> N >> Q;
	dsu d(N);

	REP(i, Q) {
		bool t;
		ll a, b;
		cin >> t >> a >> b;
		if (t) {
			bool s;
			s = d.same(a, b);
			if(s) cout << 1 << endl;
            else cout << 0 << endl;
		}
		else {
			d.merge(a, b);
		}
	}
    
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll 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++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  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;
  }
};


int main()
{
  int n, x, y;
  cin >> n >> x >> y;

  vector<vector<int>> g(n+1);
  for(int i = 1; i < n; ++i) {
    g[i].push_back(i+1);
    g[i+1].push_back(i);
  }
  g[x].push_back(y);
  g[y].push_back(x);

  vector<int> dist(n+1);
  queue<int> q;

  auto update = [&](int now) {
    for(auto next : g[now]) {
      if(dist[next] == INF) {
        dist[next] = dist[now]+1;
        q.push(next);
      }
    }
  };

  vector<int> ans(n);

  for(int start = 1; start < n; ++start) {
    dist.assign(n+1, INF);
    dist[start] = 0;
    q.push(start);

    while(!q.empty()) {
      int now = q.front(); q.pop();
      update(now);
    }

    for(int j = start+1; j <= n; ++j) {
      ++ans[dist[j]];
    }
  }

  for(int i = 1; i < n; ++i) cout << ans[i] << endl;
}

Measured memory_bytes: 384
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k; cin >> k;
    vector<int> as(k);
    for(int i = 0; i < k; i++){
        cin >> as[i];
    }
    reverse(as.begin(), as.end());
    if(as[0] != 2){
        cout << -1 << '\n';
        return 0;
    }
    ll l = 2, r = 3;
    for(int i = 1; i < k; i++){
        if(as[i] > r){
            cout << -1 << '\n';
            return 0;
        }
        l = ((l + as[i] - 1)/ as[i]) * as[i];
        r = (r / as[i] + 1) * as[i] - 1;
        printd(l, r);
        if(l > r){
            cout << -1 << '\n';
            return 0;
        }
    }
    cout << l << ' ' << r << '\n';
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;

int main(){
    ll n, ans = 0;
    string s;
    cin >> n;
    unordered_map<string, int> mp; 

    for(int i = 0; i < n; ++i){
        cin >> s;
        sort(ALL(s));

        ans += mp[s]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 10660
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <math.h>
using namespace std;

typedef pair<int, int> P;
#define ll long long
#define int ll
#define INF (1LL<<60)
#define mod 1000000007
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };

ll H, W;
ll sy, sx, gy, gx;
char a[52][52];
int d[52][52];

void bfs(){
	queue<P> que;

	for (int h = 1; h <= H; h++)
		for (int w = 1; w <= W; w++) d[h][w] = INF;

	que.push(P(sy, sx));
	d[sy][sx] = 0;

	while (que.size()>0){
		P p = que.front();
		que.pop();

		if (p.first == gy && p.second == gx) break;

		for (int i = 0; i < 4; i++){
			int ny = p.first + dy[i], nx = p.second + dx[i];
			if (1 <= ny && ny <= H && 1 <= nx && nx <= W &&
				a[ny][nx] == '#' && d[ny][nx] == INF){
				que.push(P(ny, nx));
				d[ny][nx] = d[p.first][p.second] + 1;
			}
		}
	}
}

signed main(){

	cin >> H >> W;

	sx = sy = 1;
	gx = W; gy = H;

	int count = 0;
	for (int h = 1; h <= H; h++)
		for (int w = 1; w <= W; w++){
			cin >> a[h][w];
			if (a[h][w] == '#') count++;
		}

	bfs();

	if (d[gy][gx] == H + W - 2 && count == H+W-1)
		cout << "Possible" << endl;
	else
		cout << "Impossible" << endl;

	return 0;
}


Measured memory_bytes: 256
//omajinai c++
#include <iostream>
#include<cmath>
#include<vector>
#include <algorithm>
#include <limits>
#include <numeric>
#include <type_traits>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
constexpr auto mod = 1000000007;
using namespace std;
 


int main() {

int n,m;
  cin>>n>>m;
 vector<int> ac(n+1);
  vector<int > wa(n+1);
  vector<int > v(n+1);
 rep(i,n+1){
   ac.at(i)=0;
   wa.at(i)=0;
   v.at(i)=0;
 }
  int p;
  string s;
  for(int i=0;i<m;i++){
    cin>>p>>s;
   if(ac.at(p)==0)
    { if(s=="WA"){
      wa.at(p)++;
    }
    else{
      ac.at(p)++;
      v.at(p)++;
    }
    }
    }
  
  int a=0,w=0;
  
  for(int i=0;i<n+1;i++){
    if(ac.at(i)>0){
      a++;
      w+=wa.at(i);
    }
  }
  
  cout<<a<<' '<<w;
}
      

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
#define int long long
typedef long long ll;
using namespace std;

const int N = 222222;
int f[N];
string s;
int n, p;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> p >> s;
    if(p == 2 || p == 5) {
        int ans = 0;
        rep(i, 1, n) {
            if((s[i - 1] - '0') % p == 0) {
                ans += i;
            }
        }
        cout << ans << endl;
        return 0;
    }
    unordered_map<int, int> mp;
    int ans = 0, po = 1;
    mp[0]++;
    rrep(i, 1, n) {
        int d = s[i - 1] - '0';
        int nf = (f[i + 1] + d * po % p) % p;
        ans += mp[nf];
        mp[nf]++;
        f[i] = nf;
        po = po * 10 % p;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2452
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    ll x, y, a, b, c;
    cin >> x>> y >> a >> b >> c;

    vector<ll> p(a);
    vector<ll> q(b);
    vector<ll> r(c);
    for(int i = 0; i < a; i++){
        cin >> p[i];
    }
    for(int i = 0; i < b; i++){
        cin >> q[i];
    }
    for(int i = 0; i < c; i++){
        cin >> r[i];
    }

    sort(all(p)); reverse(all(p));
    sort(all(q)); reverse(all(q));
    sort(all(r)); reverse(all(r));

    vector<ll> pq;
    for(int i = 0; i < x; i++){
        pq.push_back(p[i]);
    }
    for(int i = 0; i < y; i++){
        pq.push_back(q[i]);
    }
    sort(all(pq));
    for(int i = 0; i < c; i++){
        if(i>=x+y){break;}
        if(pq[i]<r[i]){pq[i] = r[i];}
        else{break;}
    }
    ll ans = 0;
    for(int i = 0; i < pq.size(); i++){
        ans += pq[i];
    }
    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 4724
#include<iostream>
#include<cmath>
#include<iomanip>

#define PI 3.14159265358979323846264338327950L

int main(){
  int a, b, h, m;
  std::cin>>a>>b>>h>>m;

  long double rad = PI* 2 * ((long double)h/ 12.0 + ((long double)m/ 60.0) / 12.0 - (long double)m/ 60.0);

  printf("%20.20Lf", sqrtl((long double)(a*a+b*b)-(long double)(2*a*b)*cosl(rad)));
}


Measured memory_bytes: 4108