akhauriyash/Code-Regression huggingface dataset:
//q2.cpp
//Fri Aug  7 12:53:08 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i,n) for (int i=0;i<(n);++i)

using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int n;
	cin >> n;

	int ans = 0;

	for (int i=1;i<=n;i=i+2){
		int tmp = 0;
		for (int j=1;j<=i;j++){
			if (i%j==0) tmp++;
		}
		if(tmp==8) ans++;
	}

	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 3600
# グラフ問題での分析が全然できなかった（初体験）
# 次回は頑張って解く！
# 解説動画をみることがMUST、基本そのまま書いている。

from heapq import heappop, heappush
N, u, v = map(int, input().split())
edges = [[] for i in range(N+1)]

for i in range(N-1):
  a, b = map(int, input().split())
  edges[a].append(b)
  edges[b].append(a)

def dfs(u):
  colors = ["white"] * (N+1)
  d = [9999999999999999] * (N + 1)
  d[u] = 0
  stack = [u]

  while stack:
    u = stack.pop()
    colors[u] = "black"

    for e in edges[u]:
      if colors[e] != "black":
        d[e] = d[u] + 1
        stack.append(e)

  return d

u_dist = dfs(u)
v_dist = dfs(v)

ans = 0
for i in range(N+1):
  if u_dist[i] < v_dist[i]:
    ans = max(ans, v_dist[i] - 1)

print(ans)

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

vector<ll>  dijkstra(const WGraph &G, const int s) {
    int n = (int)G.size();
    std::vector<long long> dis(n, LINF);
    dis.at(s) = 0;
    using P = std::pair<long long, int>;
    std::priority_queue<P, std::vector<P>, std::greater<P>> que;
    que.push(std::make_pair(0, s));

    while (!que.empty()) {
        auto p = que.top();
        que.pop();
        int v = p.second;
        if (dis.at(v) < p.first) {
            continue;
        }
        for (auto e : G.at(v)) {
            if (dis.at(e.first) > dis.at(v) + e.second) {
                dis.at(e.first) = dis.at(v) + e.second;
                que.push(std::make_pair(dis.at(e.first), e.first));
            }
        }
    }
    return dis;
}

void solve() {
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    WGraph Ga(n), Gb(n);
    for (int i=0; i<m; ++i) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        Ga.at(u-1).push_back({v-1, a});
        Ga.at(v-1).push_back({u-1, a});
        Gb.at(u-1).push_back({v-1, b});
        Gb.at(v-1).push_back({u-1, b});
    }

    auto disa = dijkstra(Ga, s-1);
    auto disb = dijkstra(Gb, t-1);

    priority_queue<pair<ll, int>> que;
    constexpr ll money = 1e15;
    for (int i=0; i<n; ++i) que.push({money-disa.at(i)-disb.at(i), i+1});
    for (int i=0; i<n; ++i) {
        while (que.top().second <= i) que.pop();
        cout << que.top().first << '\n';
    }
}

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

    solve();

    return 0;
}


Measured memory_bytes: 19836
#include<bits/stdc++.h>
using namespace std;
#define debug 1

const long MAXH=12,MAXW=1100;
char board[MAXH][MAXW];
long h,w,k;
bool cut[MAXH];	//cut under it
long num_now[MAXH];

long ans=2147483647,num_h,num_w;

long calc() {
	register long i,j,kkk,now_group;
	
	num_w=0;
	memset(num_now,0,sizeof(num_now));
	for(i=1;i<=w;++i) {
		now_group=1;
		for(j=1;j<=h;++j) {
			num_now[now_group]+=(board[j][i]=='1'? 1:0);
			if(cut[j]==1)
				++now_group;
		}
		
		bool flag=0;
		for(j=1;j<=now_group;++j)
			if(num_now[j]>k) {
			flag=1;break;}
		
		if(flag) {
			++num_w;
			memset(num_now,0,sizeof(num_now));
			now_group=1;
			for(kkk=1;kkk<=h;++kkk) {
				num_now[now_group]+=(board[kkk][i]=='1'? 1:0);
				if(cut[kkk]==1)
					++now_group;
			}
			
			for(kkk=1;kkk<=now_group;++kkk)
				if(num_now[kkk]>k)
					return 1073741824;
		}
	}
/*
#ifdef debug
	if(num_w+num_h<4)*/
	return num_w;
}

void dfs(long now) {
	if(now==h) {
		
		ans=min(ans,calc()+num_h);
		return;
	}
	
	cut[now]=1;
	++num_h;
	dfs(now+1);
	cut[now]=0;
	--num_h;
	dfs(now+1);
}

int main() {
	cin>>h>>w>>k;
	char ch;
	for(long i=1;i<=h;++i)
		for(long j=1;j<=w;++j) {
			ch=getchar();
			board[i][j]=ch;
			if(ch!='0' && ch!='1')
				--j;
		}
	
	num_h=0;
	dfs(1);
	
	cout<<ans<<endl;
	return 0;
}

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

const int INF = (int)(1e9) + 7;
int dp[100010];

int main() {
  dp[0] = 0;
  for (int n = 1; n <= 100000; ++n) {
    dp[n] = INF;
    int power = 1;
    while (power <= n) {
      dp[n] = min(dp[n], dp[n-power] + 1);
      power *= 6;
    }
    power = 1;
    while (power <= n) {
      dp[n] = min(dp[n], dp[n-power] + 1);
      power *= 9;
    }
  }
  int N;
  cin >> N;
  cout << dp[N] << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pb push_back
#define fr first
#define sc second
#define MOD 1000000007
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define f(i, a, n) for (int i = a; i < n; i++)
using namespace std;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<string> vs;

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int s, w;
    cin >> s >> w;
    if (s <= w)
        cout << "unsafe";
    else
        cout << "safe";

    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

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

int main()
{
	int N, K;
	std::cin >> N >> K;
	std::vector<int> x(N);
	rep(i, N)	std::cin >> x[i];
	
	int ans = 0;
	rep(i, N)
	{
		ans += 2 * (std::min(abs(x[i] - 0), abs(x[i] - K)));
	//	printf("[%d]%d\n", i, ans);
	}

	std::cout << ans << std::endl;

    return 0;
}


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

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const double PI = atan(1.0) * 4.0;
// const int MOD = 998244353;
const ll LINF = 9e18;
const ll dx[] = {1, 0, -1, 0};
const ll dy[] = {0, 1, 0, -1};

ll S;

signed main() {
    cin >> S;
    ll x1, y1, x2, y2;
    ll rt = ceil(sqrt(S));
    x1 = rt, y2 = rt;
    x2 = rt * rt - S;
    y1 = 1;
    cout << 0 << " " << 0 << " " << x1 << " " << y1 << " " << x2 << " " << y2
         << "\n";
}

Measured memory_bytes: 256
import math
import functools

def gcd(*nums):
    return functools.reduce(math.gcd, nums)

k = int(input())

ans = 0
for a in range(1, k+1, 1):
    for b in range(a, k+1, 1):
        for c in range(b, k+1, 1):
            if a == b:
                if b == c:
                    tmp = a
                else:
                    tmp = gcd(a, b, c) * 3
            else:
                if b == c or a == c:
                    tmp = gcd(a, b, c) * 3
                else:
                    tmp = gcd(a, b, c) * 6
            ans += tmp

print(ans)


Measured memory_bytes: 9636
#include<iostream>
#include<cmath>
using namespace std;
main()
{
	int n,m;
	while(cin>>m,m)
	{
		double T=2*M_PI,v;
		double A=0;
		for(;--m;)
		{
			cin>>v;
			v=v*M_PI/180;
			T-=v;
			A+=sin(v);
		}
		A+=sin(T);
		T=2*M_PI;
		cin>>n;
		for(;--n;)
		{
			cin>>v;
			v=v*M_PI/180;
			T-=v;
			A-=sin(v);
		}
		A-=sin(T);
		cout<<(abs(A)<1e-10?0:A>0?1:2)<<endl;
	}
}



Measured memory_bytes: 3392
#include <iostream>

using namespace std;

int main()
{
	int h[2], m[2], s[2], t[2];
	int time;
	int M = 60;
	
	for (int j = 0; j < 3; j++){
		for (int i = 0; i < 2; i++){
			cin >> h[i] >> m[i] >> s[i];
			t[i] = M * M * h[i] + M * m[i] + s[i];
		}
		int time = t[1] - t[0];
		cout << time / (M * M) << ' ' << time % (M * M) / M << ' ' << time % M << endl;
	}
	return (0);
}

Measured memory_bytes: 1160
using System;

namespace ABC134
{
    class abc134b
    {
        static void Main(string[] args)
        {
            var buf = Console.ReadLine().Split();
            var n = int.Parse(buf[0]);
            var d = int.Parse(buf[1]);
            var i = 1;
            while (n > (d * 2 + 1) * i)
                ++i;
            Console.WriteLine(i);
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<vector>
#include<queue>

using namespace std;

int persimmon_cnt(vector< vector<int> > vv,int s, int t,int y,int x){
	int cnt = 0;
	for (int i = 0; i < t; i++){
		for (int j = 0; j < s; j++){
			//cout << "y = " << y+i << " x = " << x+j << endl;
			if (vv[y+i][x+j] == 1){
				//cout << "x = " << x+j << " y = " << y+i << endl;
				cnt++;
			}
		}
	}
	//cout << endl;
	return cnt;
}
int search_max(vector< vector<int> > vv,int s, int t){
	int max = 0;
	for (int i = 0; i <= vv.size() - t ; i++){ //83
		for (int j = 0; j <= vv.front().size() - s; j++){ //93
			//cout << "i = " << i << " j = " << j << endl;	
			int persimmon = persimmon_cnt(vv,s,t,i,j);
			//cout << vv[i][j] ;
			if (max < persimmon) max = persimmon;		
		}
		//cout << endl;
	}
	return max;
}
void print(vector<vector<int> > vv){
	for (int i = 0; i < vv.size(); i++){
		for (int j = 0; j < vv.front().size(); j++){	
			cout << vv[i][j];
		}
		//cout << endl;
	}
}
int main(){
	while(1){
		int n; cin >> n;
		if (n == 0) break;
		int w,h; cin >> w >> h;
		vector< vector<int> > field(h,vector<int>(w,0));
		//cout << field.size() <<" "<<  field.front().size() << endl;
		//            8                       10
		//cout << field[7][9] << endl;
		for (int i = 0 ; i < n; i ++){	
			int x,y;
			cin >> x >> y;
			//cout <<"i = " << i << " " <<  x << " " << y << endl;
			field[y-1][x-1] = 1;
		}
		//print(field);
		int s,t; cin >> s >> t;
		//cout << field.front().size() - s << endl;
		//cout << field.size() - t << endl;

		cout << search_max(field,s,t) << endl;;
		
	}
return 0;
}

Measured memory_bytes: 3116
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
bigger_a = bigger_b = 0
for a_, b_ in zip(a, b):
    if a_ > b_: bigger_a += a_ - b_
    if b_ > a_: bigger_b += (b_ - a_) // 2
if bigger_b >= bigger_a: print("Yes")
else: print("No")

Measured memory_bytes: 4596
#include <iostream>
using namespace std;
int main()
{
    int x,y;
    for(int i=0; ;i++){
        cin>>x>>y;
        if(x==0&&y==0)break;
        else if(x<=y){cout<<x<<" "<<y<<endl;}
        else{cout<<y<<" "<<x<<endl;}
        
    }
    return 0;
}


Measured memory_bytes: 2988
n = input()
if "SU" in n:
    print(7)
if "M" in n:
    print(6)
if "TU" in n:
    print(5)
if "W" in n:
    print(4)
if "TH" in n:
    print(3)
if "F" in n:
    print(2)
if "SA" in n:
    print(1)

Measured memory_bytes: 38256
a, b, c = gets.split
puts a.to_f * b.to_f * Math.sin( c.to_i * Math::PI/180) / 2
puts a.to_f + b.to_f + Math.sqrt(a.to_f  ** 2 +  b.to_f ** 2 - 2 * Math.cos( c.to_i * Math::PI/180) * a.to_f * b.to_f)
puts b.to_f *  Math.sin( c.to_i * Math::PI/180) 


Measured memory_bytes: 6932
#include<stdio.h>
int main(void){
    int c1,c2,c3;
    while(scanf("%d",&c1)!=EOF){
        scanf(" %d %d",&c2,&c3);
        int a,b,i,j,k;
        double x;
        a=20-c1-c2;
        b=0;
        if(a>10)a=10;
        for(i=1;i<=a;i++){
            if(i==c1 || i==c2 || i==c3)continue;
            else b++;
        }
 
 
        if(b>=4)puts("YES");
        else puts("NO");
    }
    return 0;
}


Measured memory_bytes: 1912
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  string s,t,u;
  int n;
  cin >> n >> s >> t;
  rep(i,n){
    u+=s[i];
    u+=t[i];
  }
  cout << u << endl;
} 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
    int h,w;
    cin >> h >> w;
    vector<vector<char>> a(h,vector<char>(w));
    int i,j;
    int sum=0;
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            cin >> a.at(i).at(j);
            if(a.at(i).at(j)=='#')sum++;
        }
    }

    if(sum!=h+w-1)cout << "Impossible" << endl;
    else       cout << "Possible" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define RRep(i, r, n) for (ll i = n - 1; i <= r; i--)
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
using Graph = vector<vector<pair<int, int>>>;
ll ni(int x){
    return x*(x+1)/2;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    
    string s;
    cin>>s;
    int n=s.size();
    vector<P> count(1000000);
    count[0].first=1;
    if(s[0]=='>'){
        count[0].sc=1;
    }
    int c=0;
    rep(i,n){
        if(i==0){
            continue;
        }
        if(s[i-1]==s[i]){
            count[c].first++;
        }
        else{
            c++;
            count[c].first++;
            if(s[i]=='>'){
                count[c].sc=1;
            }
        }
    }
    c++;
    ll ans=0;
    int x=c;
    c=0;
    if(count[0].sc==1){
        ans+=ni(count[0].fs);
        c=1;
    }
    Rep(i,c,x){
        if(count[i].sc==0){
            ans+=ni(count[i].fs);
        }
        else{
            ans+=ni(count[i].fs);
            ans-=min(count[i-1].fs,count[i].fs);
             }

    }
    cout<<ans<<endl;

}

Measured memory_bytes: 8732
#include <iostream>
#include <vector>
#include <algorithm>

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

int main(int argc, char* argv[]) {
  int a;
  string s;

  cin >> a;
  cin >> s;

  cout << ((a >= 3200) ? s : "red") << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
typedef long long ll;

int main()
{
  int r;
  cin >> r;
  cout << r * r << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>

using namespace std;

int n, a[110], b[110];

int main() {
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		a[i] += a[i - 1];
	}
	for(int i = 1; i <= n; i++)
	{
		cin >> b[i];
		b[i] = b[i] + max(b[i - 1], a[i]); 
	}
	cout << b[n] << endl;
    return 0;
}

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

typedef long long ll;

int n,m;
int po[55];
int u[25],v[25];
vector<int> g[55];
int d[55],fa[55];
int lca[55][55];
ll ans;

void mkdf(int x,int p,int c){
    d[x]=c;
    fa[x]=p;
    for(int i=0;i<g[x].size();i++){
        int &y=g[x][i];
        if(y!=p){
            mkdf(y,x,c+1);
        }
    }
}

inline void add(int *mk,int x,int y){
    while(d[x]>d[y]){
        if(mk[x]){
            x=mk[x];
        }else{
            mk[0]++;
            mk[x]=y;
            x=fa[x];
        }
    }
}

int main(){

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

    cin>>n;
    for(int i=1;i<n;i++){
        int a,b;
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    cin>>m;
    for(int i=0;i<m;i++){
        cin>>u[i]>>v[i];
    }
    mkdf(1,-1,0);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            int x=i,y=j;
            while(d[x]>d[y])x=fa[x];
            while(d[x]<d[y])y=fa[y];
            while(x!=y)x=fa[x],y=fa[y];
            lca[i][j]=x;
        }
    }
    for(int msk=0;msk<1<<m;msk++){
        int mk[55]={0};
        int bit=0;
        for(int i=0;i<m;i++){
            if(msk>>i&1){
                bit++;
                add(mk,u[i],lca[u[i]][v[i]]);
                add(mk,v[i],lca[u[i]][v[i]]);
            }
        }
        if(bit&1)ans-=1ll<<(n-1-mk[0]);
        else ans+=1ll<<(n-1-mk[0]);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
H,W,D=map(int,input().split())
A=[list(map(int, input().split())) for _ in range(H)]
Am=[None]*(H*W+1)
for h in range(H):
	for w in range(W):
		Am[A[h][w]] = (h, w)
C=[0]*(H*W+1)
for i in range(D+1, H*W+1):
	h,w=Am[i-D]
	ch,cw=Am[i]
	C[i] = C[i-D] + abs(ch-h) + abs(cw-w)
Q=int(input())
for _ in range(Q):
	L,R=map(int, input().split())
	print(C[R]-C[L])


Measured memory_bytes: 17888
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

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

		int deg2h = h*60 + m ;
		int deg2m = m*12 ;
		int deg2x = Math.max(deg2m,deg2h)-Math.min(deg2m,deg2h);
		if ( deg2x>360 ) deg2x = 720-deg2x;
		double radx = Math.toRadians((double)(deg2x/2d)) ;

		double cc = (double)(a*a) + (double)(b*b) - 2d*(double)a*(double)b*Math.cos(radx) ;
		double c = Math.sqrt(cc);

		System.out.println(c);
	}
}

Measured memory_bytes: 35988
pub mod io {
    use std::io;

    pub fn read_line() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }

    pub trait Read {
        fn read(s: &str) -> Self;
    }

    macro_rules! def_read {
        ($t: ty) => {
            impl Read for $t {
                fn read(s: &str) -> $t {
                    s.parse().unwrap()
                }
            }
        }
    }

    def_read!(i32);
    def_read!(i64);
    def_read!(isize);
    def_read!(usize);
    def_read!(f64);

    impl<T: Read> Read for Vec<T> {
        fn read(s: &str) -> Self { s.split_whitespace().map(|w| T::read(w)).collect() }
    }

    macro_rules! def_read_tuple {
        ($($t: ident),*) => {
            impl<$($t : Read + Default),*> Read for ($($t),*) {
                fn read(s: &str) -> Self {
                    let ws = s.split_whitespace().collect::<Vec<_>>();
                    let mut i = 0;
                    ( $({i += 1; $t::read(ws[i - 1])}),* )
                }
            }
        };
    }

    def_read_tuple!(T0, T1);
    def_read_tuple!(T0, T1, T2);
    def_read_tuple!(T0, T1, T2, T3);
    def_read_tuple!(T0, T1, T2, T3, T4);

    pub fn readln<T: Read>() -> T { T::read(&read_line()) }
}

fn main() {
    let (w, h): (usize, usize) = io::readln();
    let ps: Vec<i64> = (0..w).map(|_|io::readln()).collect();
    let qs: Vec<i64> = (0..h).map(|_|io::readln()).collect();

    let mut ord: Vec<(i64, usize, usize)> =
        ps.iter().enumerate().map(|(i, &v)| (v, i, 0))
        .chain(qs.iter().enumerate().map(|(j, &v)| (v, j, 1)))
        .collect();
    ord.sort();

    let mut ans = 0;
    let mut xs = 0;
    let mut ys = 0;

    for (v, _, d) in ord {
        if d == 0 {
            ans += v * (h + 1 - ys) as i64;
            xs += 1;
        } else {
            ans += v * (w + 1 - xs) as i64;
            ys += 1;
        }
    }

    println!("{}", ans);
}



Measured memory_bytes: 15996
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

template <typename T>
T gcd(T a, T b) {
  if (a % b == 0) {
    return b;
  } else {
    return gcd(b, a % b);
  }
}

template <typename T>
set<T> factorize(T num) {
  set<T> result;
  T d = 2;
  while (d * d <= num) {
    if (num % d == 0) {
      num /= d;
      result.insert(d);
    } else {
      d++;
    }
  }
  if (num != 1) result.insert(num);
  return result;
}

int main() {
  int n;
  cin >> n;
  V<int> a(n);
  rep(i, n) cin >> a[i];

  set<int> s;
  bool pairwise = true;
  rep(i, n) {
    auto ts = factorize(a[i]);
    for (auto e : ts) {
      if (s.count(e) > 0) {
        pairwise = false;
        break;
      }
      s.insert(e);
    }
  }
  if (pairwise) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  int num = a[0];
  rep(i, n) { num = gcd(num, a[i]); }
  if (num == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}


Measured memory_bytes: 10860
import java.util.Scanner;

public class Main {

	public static long CONST = (long) Math.pow(10,9) + 7L;

	static Main instance = new Main();

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値
		long N = scan.nextLong();
		long K = scan.nextLong();

		//WK変数
		long count = 0L;

		//演算
		for (long i = K; i < N + 2L; i++) {
			count += (N * i - i * (i - 1L) + 1L) % CONST;
			count %= CONST;
		}

		//結果出力
		System.out.println(count);
	}
}

Measured memory_bytes: 35572
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int d = sc.nextInt();
    int d_new = 2 * d + 1;

    for(int i = 1;; i++) {
      if(i * d_new >= n) {
        System.out.println(i);
        break;
      }
    }

  }

}


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

int main(){
  int N;
  cin >> N;
  vector<int> v(N+1);
  for(int i=1;i<=N;i++){
    cin >> v.at(i);
  }
  int ans=0;
  for(int i=1;i<=N;i++){
    if(v.at(v.at(i))==i){
      ans++;
    }
  }
  ans/=2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3796
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define sz(v) (int)v.size() 
#define all(v) v.begin(), v.end()
void dbg_out() { cerr << "\b\b]\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){ cerr << H << ", "; dbg_out(T...);}
#define watch(...) cerr << "[" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__)


/****************************** CODE IS HERE ***********************************/


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

    string s, t; cin >> s >> t;
    int n = sz(s);
    int m = sz(t);

    //dp[i][j] => represents max length subsequence I can get using elements
    //of s =>[1...i] and t=>[1...j]
    //initally dp[0][0] = 0, becuz, both string are empty
    vector <vector<int>> dp(n+1, vector <int>(m+1, 0));
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            if (s[i-1] == t[j-1]) dp[i][j] = max(dp[i][j], dp[i-1][j-1] + 1);
        }
    }
    // cout << dp[n][m]; //length

    string ans;
    for (int i = n, j = m; i > 0 and j > 0;) {
        if (dp[i][j] == dp[i-1][j]) i = i - 1;
        else if (dp[i][j] == dp[i][j-1]) j = j-1;
        else {
            ans += s[i-1];
            i = i - 1;
            j = j - 1;
        }
    }
    reverse(all(ans));
    cout << ans;

    return 0;
}

/*recurrence relation:
    
    f(i, j) = max { f(i+1, j), 1 <= i <= n
                    f(i, j+1), 1 <= j <= m
                    1 + f(i+1, j+1), i <= n and j <= m
                    }
    this is same as brute force soln, hence, brute force soln gives the recurrence 
    relation.
    If we use the above recurrence for bottom up then base case will be at
    f[n+1][m+1] = 0, and we get the final ans at f[1][1] by moving [n...1][m...1];


    So, we change the recurrence little bit, for moving [1...n] & [1...m], base at 
    f[0][0] and ans at [n][m], recurrece is similer only change is the movement
    from one to another state.
    f(i, j) = max { f(i-1, j), 1 <= i <= n
                    f(i, j-1), 1 <= j <= m
                    1 + f(i-1, j-1), i <= n and j <= m
                    }
*/

Measured memory_bytes: 35584
/*
 * abc061a_c.c
 *
 *  Created on: 2019/05/08
 *      Author: ktaka
 */

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

int main(void){

	char tango[100],*ch;
	int val[10];
	int i=0,j=0;

	fgets(tango,sizeof(tango),stdin);

	//printf("%s\n",tango);
	ch = strtok(tango," ");
	val[i] = atoi(ch);
	i++;

	while ((ch=strtok(NULL," ")) != NULL){
			/*ch = strtok(NULL," ");*/
			val[i] = atoi(ch);
			i++;
	}
/*
	for(j=0;j<=2;++j){
		printf("%d\n",val[j]);
	}
*/

	if (val[0] <= val[2] && val[2] <= val[1]){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}




}


Measured memory_bytes: 128
n=int(input())
import math
i=0
ans=0
if n!=0:
  while n!=1:
    ans+=(n-math.ceil(n/(-2))*(-2))*(10**i)
    n=math.ceil(n/(-2))
    i+=1
  ans+=10**i
else:
  ans=0
print(ans)
  
  

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false)
#define pdl cout << "*" << endl
#define MOD 1000000007
#define INF 1000000000
#define INFLL 1000000000000000000ll
#define ff first
#define ss second
#define long int64_t
using namespace std;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<> dis(0, INF<<1);
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args)
{ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma+1, args...); }

const int M = 18;

int mod;

struct Mat
{
	int m[3][3];

	Mat(int v)
	{
		memset(m, 0, sizeof m);
		for(int i=0; i<3; i++)
			m[i][i] = v;
	}

	Mat operator* (const Mat &a) const
	{
		Mat r(0);
		for(int i=0; i<3; i++)
			for(int j=0; j<3; j++)
				for(int k=0; k<3; k++)
					r.m[i][j] = (r.m[i][j] + m[i][k] * 1ll * a.m[k][j]) % mod;
		return r;
	}

};

int modexp(Mat a, long b, int s)
{
	Mat r(1);
	while(b)
	{
		if(b & 1)
			r = r * a;
		a = a * a;
		b >>= 1;
	}
	return (s * 1ll * r.m[0][1] + r.m[0][2]) % mod;
}

int modexp(int a, long b)
{
	int r = 1;
	while(b)
	{
		if(b & 1)
			r = (r * 1ll * a) % mod;
		a = (a * 1ll * a) % mod;
		b >>= 1;
	}
	return r;
}

long t[M+1];

long bs(long n, long a, long b, long lim)
{
	long l = -1, r = n;
	while(l != r)
	{
		long mid = l+r+1 >> 1;
		if(a + mid * b < lim)
			l = mid;
		else
			r = mid-1;
	}
	return l;
}

int main()
{
	fio;
	long l, a, b, t1 = 1;
	int ans = 0;
	cin >> l >> a >> b >> mod;
	t[0] = -1;
	for(int i=1; i<=M; i++)
	{
		t1 *= 10;
		t[i] = bs(l-1, a, b, t1);
		long A = a + (t[i-1] + 1) * b;
		long n = t[i] - t[i-1];
		if(n)
		{
			Mat a(1);
			a.m[0][0] = t1 % mod;
			a.m[0][1] = 1;
			a.m[1][2] = b % mod;
			int r = modexp(a, n, A % mod);
			int x = modexp(t1 % mod, n);
			ans = (ans * 1ll * x + r) % mod;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  string S;
  cin >> S;
  int x;
  x = S.size();
  if (S.at(x-1) == 's')
  {
    cout << S << "es" << endl;
  }
  else {cout << S << "s" << endl;}  
}

Measured memory_bytes: 3624
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
       String num = sc.next();
       String n2=num.substring(num.length()-1,num.length());
       int n = Integer.parseInt(n2);

      
       if(n==2||n==4||n==5||n==7||n==9){
           System.out.println("hon");
       }else if(n==0||n==1||n==6||n==8){
           System.out.println("pon");
       }else if(n==3){
        System.out.println("bon");
       }

    }
}

Measured memory_bytes: 35664
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Main {

  static int n;
  static List<Long> a;
  static long ans;

  public static void main(String[] args) throws Exception {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter out = new PrintWriter(System.out);

    String[] in = br.readLine().split(" ");
    n = Integer.parseInt(in[0]);

    in = br.readLine().split(" ");
    a = Arrays.stream(in).map(Long::parseLong).collect(Collectors.toList());

    br.close();

    ans = 1;

    for (long m : a) {
      if(m == 0) ans = 0;
    }

    for (long m : a) {
      if(ans == 0 || m == 0) {
        ans = 0;
        break;
      }

      if(keta(ans) + keta(m) > 20){
        ans = -1;
        break;
      }

      if(keta(ans) + keta(m) == 20){
        if(tc(ans) * tc(m) != 1){
          ans = -1;
          break;
        }
      }

      ans *= m;

      if(ans > 1_000_000_000_000_000_000L) break;

    }

    out.println(ans > 1_000_000_000_000_000_000L ? -1 : ans);

    out.flush();
  }

  static long keta(long x){
    long ret = 0;
    long tmp = x;
    while(tmp > 0){
      tmp /= 10;
      ret++;
    }
    return ret;
  }

  static long tc(long x){
    long tmp = x;
    while(tmp >= 10){
      tmp /= 10;
    }
    return tmp;
  }
}


Measured memory_bytes: 60728
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int l, r, d;
    cin >> l >> r >> d;
    int ans = 0;
    for (int i = l; i <= r; i++)
    {
        if (i % d == 0)
            ans++;
    }

    cout << ans << endl;

    return 0;
}

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

int N;
string S;

int main(void) {

	cin >> N;
	cin >> S;

	string ans = "";

	int M = S.size();
	for (int i = 0; i < M; i++) {
		char tmp= S[i] + N;
		//cout << tmp << endl;
		if (tmp > 'Z') { tmp -= 26; }
		ans += tmp;
	}

	cout<< ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
while(1){
	int n,A,B,a,b;
	cin>>n;
	if(n == 0)break;
	A=0;
	B=0;
		for(int i =0; i <n;i++){
			cin >>a>>b;
		if(a>b){
		A +=(a+b);
		}
		else if(a<b){
		B +=(a+b);
		}
		else {
      A +=a;
	  B +=b;
		}
		}
		cout<<A<<" "<<B<<endl;
   }
return 0;
}


Measured memory_bytes: 3040
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

struct trump {
  int value;
  char suit;
};

void print_trump(vector<trump> C,int N,bool is_stable) {
  for(int i=0;i<N;i++) {
    cout << C[i].suit << C[i].value << (i+1==N ? "" : " ");
  }
  cout << endl;
  if(is_stable) {
    cout << "Stable" << endl;
  }
  else {
    cout << "Not stable" << endl;
  }
}

vector<trump> bubble_sort(vector<trump> C,int N) {
  bool stable = true;
  int flag = 1;
  while(flag) {
    flag = 0;
    for(int j=N-1;j>0;j--) {
      if(C[j-1].value > C[j].value) {
        swap(C[j-1],C[j]);
        flag = 1;
      }
    }
  }
  return C;
}

vector<trump> selection_sort(vector<trump> C,int N) {
  bool stable = true;
  for(int i=0;i<N;i++) {
    int minj = i;
    for(int j=i;j<N;j++) {
      if(C[j].value < C[minj].value) {
        minj = j;
      }
    }
    if(minj != i) {
      swap(C[minj],C[i]);
    }
  }
  return C;
}

int main(void) {
  int N;
  vector<trump> C;

  /* input */
  cin >> N;
  for(int i=0;i<N;i++) {
    trump _t;
    cin >> _t.suit >> _t.value;
    C.push_back(_t);
  }

  vector<trump> B = bubble_sort(C,N);
  vector<trump> S = selection_sort(C,N);
  // bubble is stable sort
  print_trump(B,N,true);

  bool stable = true;
  for(int i=0;i<N;i++) {
    if(B[i].suit != S[i].suit) {
      stable = false;
      break;
    }
  }
  print_trump(S,N,stable);
}

Measured memory_bytes: 1220
def slove():
    import sys
    import itertools
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    d = list(map(int, input().rstrip('\n').split()))
    t = 0
    for v in itertools.combinations(d, 2):
        t += (v[0] * v[1])
    print(t)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 39024
from collections import defaultdict
from functools import lru_cache
import sys
input=sys.stdin.readline


class Reroot:
    def __init__(self, N, e, merge, f, g):
        self.G = defaultdict(list)
        self.parents = [-1]*(N+1)
        self.dp = defaultdict(lambda: defaultdict(int))
        self.ans = [0]*(N+1)
        self.merge = merge
        self.f = f
        self.g = g
        self.e = e

    def add_edge(self, s, t):
        self.G[s].append(t)

    def build(self):
        self.dfs1(1)
        self.dfs2(1)
        return self.ans

    def dfs1(self, s):
        l = []
        q = [1]
        while q:
            s = q.pop()
            l.append(s)
            for t in self.G[s]:
                if t == self.parents[s]:
                    continue
                self.parents[t] = s
                q.append(t)

        for s in l[::-1]:
            v = self.e
            for t in self.G[s]:
                if t == self.parents[s]:
                    continue
                v = self.merge(v, self.f(self.dp[s][t], s, t))
            self.dp[self.parents[s]][s] = self.g(v, self.parents[s], s)

    def dfs2(self, s):
        q = [(s, self.e)]
        while q:
            s, dp_p = q.pop()
            par = self.parents[s]
            for t in self.G[s]:
                if t == par:
                    self.dp[s][t] = dp_p

            size = len(self.G[s])
            ac_l = [self.e] * (size+1)
            ac_r = [self.e] * (size+1)
            for i, t in enumerate(self.G[s]):
                ac_l[i+1] = self.merge(ac_l[i], self.f(self.dp[s][t], s, t))
            for i, t in enumerate(self.G[s][::-1]):
                ac_r[size-i-1] = self.merge(ac_r[size-i], self.f(self.dp[s][t], s, t))
            self.ans[s] = self.g(ac_l[size], -1, 1)
            for i, t in enumerate(self.G[s]):
                if t == par:
                    continue
                q.append((t, self.g(self.merge(ac_l[i], ac_r[i+1]), t, s)))


def solve():
    N = int(input())

    MOD = 10**9+7
    n = N
    fac = [1]*(n+1)
    rev = [1]*(n+1)
    d = defaultdict(list)

    for i in range(1,n+1):
        fac[i] = i*fac[i-1]%MOD
        rev[i] = pow(fac[i], MOD-2, MOD)

    merge1 = lambda x,y:x+y
    f1 = lambda x, par, s:x
    g1 = lambda x, par, s:x+1
    e1 = 0
    tree1 = Reroot(N, e1, merge1, f1, g1)

    merge2 = lambda x,y:(x*y)%MOD
    f2 = lambda x, par, s:(x*rev[tree1.dp[par][s]])%MOD
    g2 = lambda x, par, s:(x*fac[tree1.dp[par][s]-1])%MOD
    e2 = 1
    tree2 = Reroot(N, e2, merge2, f2, g2)

    for _ in range(N-1):
        a, b = map(int, input().split())
        tree2.add_edge(a, b)
        tree2.add_edge(b, a)
        tree1.add_edge(a, b)
        tree1.add_edge(b, a)

    tree1.build()
    ans = tree2.build()

    for i in range(1, N+1):
        print(ans[i])


if __name__ == "__main__":
    solve()


Measured memory_bytes: 323436
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
double dp[305][305][305];

int main() {
  int n;
  cin >> n;
  vector<int> a(3, 0);
  int sum = 0;
  for (int i=0; i<n; ++i) {
    int x;
    cin >> x;
    a[x-1]++;
  }
  
  double p = 1.0/n;

  // i : num of dishes with 1 sushi
  // j : num of dishes with 2 sushi
  // k : num of dishes with 3 sushi
  rep(k, n+1)rep(j, n+1)rep(i, n+1) {
    int z = n-i-j-k;
    if (z<0) {
      break;
    }
    if (z==n) {
      continue;
    }
    double x = 1-z*p;
    if (i) {
      dp[i][j][k] += dp[i-1][j][k]*i*p;
    }
    if (j) {
      dp[i][j][k] += dp[i+1][j-1][k]*j*p;
    }
    if (k) {
      dp[i][j][k] += dp[i][j+1][k-1]*k*p;
    }
    dp[i][j][k] += 1;
    dp[i][j][k] /= x;
  }
  printf("%.10lf\n", dp[a[0]][a[1]][a[2]]);
  return 0;
}


Measured memory_bytes: 219392
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n, k;
  cin >> n >> k;
  int x[n];
  for (int i = 0; i < n; ++i) cin >> x[i];
  int ans = 0;
  for (int i = 0; i < n; ++i) ans += min(x[i], k-x[i]);
  cout << ans*2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define mt make_tuple

ll m, n;


int main(){
cin >> n >> m;
if(n>1&&m>1)cout << 1LL*(n-2)*(m-2);
else if(n==1&&m==1)cout << 1 << endl;
else if(n==1)cout << m-2 << endl;
else cout << n-2 << endl;




return 0;}


Measured memory_bytes: 384
n = int(input())
p = list(input().split())
q = list(input().split())

l = list(range(1, n+1))
ll = []

def Count_Order(n, s):
    if n == 0:
        ll.append("".join(list(map(str, s))))
    else:
        for x in l:
            if not x in s:
                Count_Order(n-1, s+[x])

s = []
Count_Order(n, s)
print(abs(ll.index("".join(p)) - ll.index("".join(q))))

Measured memory_bytes: 47708
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

int p[55556];

int main(){
    int N;
    cin >> N;
    for(int i=0;i<55556;i++) p[i] = 0;
    for(int i=2;i<=55555;i++){
        if(p[i] != 0) continue;
        p[i] = i;
        for(int j=i*2;j<55556;j+=i){
            p[j] = i;
        }
    }
    vector<int> v;
    for(int i=2;i<=55555;i++){
        if(i==p[i] && i % 5 ==1) v.push_back(i); 
    }
    for(int i=0;i<N;i++){
        cout << v[i];
        if(i!=N-1) cout << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 512
def read_input():
    w, h, n = map(int, input().split())

    points = []
    for i in range(n):
        x, y, a = map(int, input().split())
        points.append((x, y, a))

    return w, h, n, points


def submit():
    w, h, n, points = read_input()

    area_x = [0, w]
    area_y = [0, h]

    for point in points:
        if point[2] == 1:
            if area_x[0] < point[0]:
                area_x[0] = point[0]
            continue

        if point[2] == 2:
            if point[0] < area_x[1]:
                area_x[1] = point[0]
            continue

        if point[2] == 3:
            if area_y[0] < point[1]:
                area_y[0] = point[1]
            continue

        if point[2] == 4:
            if point[1] < area_y[1]:
                area_y[1] = point[1]
            continue

    if area_x[1] - area_x[0] < 0 or area_y[1] - area_y[0] < 0:
        print(0)
    else:
        print((area_x[1] - area_x[0]) * (area_y[1] - area_y[0]))

if __name__ == '__main__':
    submit()


Measured memory_bytes: 38256
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int main(void) {
    cout << std::fixed << std::setprecision(10);
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    int h, w, n;
    int barrier_mostsouth[200010];
    std::unordered_set<int> barrier[200010];
    cin >> h >> w >> n;
    for (int i = 1; i <= h; i++) {
        barrier_mostsouth[i] = w + 1;
    }
    barrier_mostsouth[h + 1] = 1;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        barrier[x].insert(y);
        if (barrier_mostsouth[x] > y) {
            barrier_mostsouth[x] = y;
        }
    }
    for (int i = 1; i <= h; i++) {
        barrier[i].insert(w + 1);
    }
    for (int i = 1; i <= w + 1; i++) {
        barrier[h + 1].insert(i);
    }

    int pos_x = 1, pos_y = 1;
    while (!(barrier_mostsouth[pos_x + 1] <= pos_y)) {

        pos_x++;
        // cout << "posx++: " << pos_x - 1 << " -> " << pos_x << endl;
        if (barrier[pos_x].find(pos_y + 1) == barrier[pos_x].end()) {
            pos_y++;
            // cout << "posy++: " << pos_y - 1 << " -> " << pos_y << endl;
        }
    }
    cout << pos_x << endl;

    return 0;
}


Measured memory_bytes: 42056
#include <iostream>
using namespace std;
void swap(int& a, int& b){
	int t;
	t = a;
	a = b;
	b = t;
}

void baburu(int y[], int n){
	int i, j;
	for(i = 0; i < n - 1; i++){
		for(j = n - 1; j > i; j--){
			if(y[j -1] > y[j]){
				swap(y[j - 1], y[j]);
			}
		}
	}
}

int main()
{
	int x[10];
	int j = 0;
	while(j <= 9){
		cin >> x[j];
		j++;
	}
	baburu(x, 10);
	cout << x[9] << "\n";
	cout << x[8] << "\n";
	cout << x[7] << "\n";
}

Measured memory_bytes: 1164
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int N;
  cin >> N;
  int s[N],i,ans=0;
  for(i=0;i<N;i++){
    cin >> s[i];
    ans+=s[i];
  }
  if(ans%10!=0){
    cout << ans << endl;
    return 0;
  }
  sort(s,s+N);
  for(i=0;i<N;i++)if(s[i]%10 != 0)break;
  if(i==N){
    cout << "0" << endl;
    return 0;
  }else{
    cout << ans-s[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null; }
        String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try { tokenizer = new StringTokenizer(reader.readLine()); } 
                catch (IOException e) { throw new RuntimeException(e);} }
            return tokenizer.nextToken(); }
        public int nextInt() { return Integer.parseInt(next()); }
        public long nextLong() { return Long.parseLong(next()); }
        public double nextDouble() { return Double.parseDouble(next()); }
    }

    static InputReader r = new InputReader(System.in);
    static PrintWriter pw = new PrintWriter(System.out);

    public static void main(String[] args) {
        
        String s = r.next();
        if(s.charAt(0) == 'S'){
            pw.println("Cloudy");
        } else if(s.charAt(0) == 'C'){
            pw.println("Rainy");
        } else{
            pw.println("Sunny");
        }

        pw.close();
    }
}

/**
                _        _                 _                                                
               | |      | |               | |                                               
   ___ ___   __| | ___  | |__  _   _    __| | __ _ _ __ _ __ ___ _ __     _   _  __ _  ___  
  / __/ _ \ / _` |/ _ \ | '_ \| | | |  / _` |/ _` | '__| '__/ _ \ '_ \   | | | |/ _` |/ _ \ 
 | (_| (_) | (_| |  __/ | |_) | |_| | | (_| | (_| | |  | | |  __/ | | |  | |_| | (_| | (_) |
  \___\___/ \__,_|\___| |_.__/ \__, |  \__,_|\__,_|_|  |_|  \___|_| |_|   \__, |\__,_|\___/ 
                                __/ |                               ______ __/ |            
                               |___/                               |______|___/             
 */

Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<bool, int>;
ll INF = 1e9;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>> d(n);
    for(int i = 0; i < m; i++)
    {
        int u, v;
        cin >> u >> v;
        u--;v--;
        d[u].push_back(v);
        d[v].push_back(u);
    }
    vector<int> color(n);
    ll one = 0;
    ll bip = 0;
    ll nbip = 0;
    ll bsize = 0;
    ll nbsize = 0;
    for(int i = 0; i < n; i++)
    {
        if(color[i] != 0) continue;
        if(!d[i].size())
        {
            one++;
            continue;
        }
        queue<int> que;
        que.push(i);
        color[i] = 1;
        bool flag = true;
        int size = 0;
        while(que.size())
        {
            size++;
            int v = que.front();
            que.pop();
            for(int nx : d[v])
            {
                if(color[nx] == color[v]) flag = false;
                if(color[nx] == 0)
                {
                    que.push(nx);
                    color[nx] = -color[v];
                }
            }
        }
        if(flag)
        {
            bsize += size;
            bip++;
        }
        else
        {
            nbsize += size;
            nbip++;
        }
    }
    ll ans = one * one;
    ans += nbip * nbip; // nbip * nbip
    ans += bip * bip * 2; // bip * bip
    ans += one * bsize * 2;
    ans += one * nbsize * 2;
    ans += nbip * bip * 2;
    cout << ans << endl;
}



Measured memory_bytes: 7296