akhauriyash/Code-Regression huggingface dataset:
/*
   Creator - Glitched
   Yeet!!
*/
#include "bits/stdc++.h"
using namespace std;

#define testcases ll T;cin>>T;while(T--)
#define ll long long
#define loop(i,x,n) for(ll i=x;i<n;i++)
#define loopr(i,x,n) for(ll i=n-1;i>=x;i--)
#define ff first
#define ss second
#define pb push_back
#define elif else if
#define flush cout<<"\n"
#define mod 1E9+7
#define L LONG_MAX
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
const string yes = "Yes", no = "No";
ll dp[101][101];
char a[101][101];

ll f(ll i, ll j, ll count, ll n, ll m){
	if(a[i][j] == '#')
		count++;
	// if(dp[i][j] != -1){
	// 	return dp[i][j];
	// }

	if(i == n-1 && j == m-1){		
		return count;		
	}

	if(i == n-1){
		dp[i][j]  =  f(i, j+1, count, n,m);
		return dp[i][j];
	}
	if(j == m-1){
		dp[i][j]=f(i+1,j, count, n , m);
		return dp[i][j];
	}
	dp[i][j] = min(f(i,j+1,count,n,m), f(i+1,j,count,n,m));
	return dp[i][j];

}


int main()
{	
	string s,a,b,c,e,d;cin>>s;
	ll n = s.size();
	a = s;reverse(a.begin(), a.end());
	loop(i,0,(n-1)/2){
		string y = "0";
		y[0] = s[i];
		b.append(y);
		c.append(y);
	}
	loop(i,(n+3)/2 - 1,n){
		string y = "0";
		y[0] = s[i];
		d.append(y);
		e.append(y);
	}
	reverse(b.begin(), b.end());
	reverse(e.begin(), e.end());

	if(a == s && b == c && d==e)
		cout<<"Yes";
	else
		cout<<"No";
}

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

bool is_prime(int n) {
	int x = 1;
	if (n < 2) return false;
	else if (n % 2 == 0) x = 2;
	else {
		double m = sqrt(n);
		bool f = false;
		for (int i = 3; i <= m; i += 2) {
			if (n % i == 0) {
				x = i;
				f = true;
				break;
			}
		}
		if (!f) return true;
	}

	int t = n;
	for (size_t i = 0; i < 100; i++) {
		if (t % x != 0) {
			return false;
		}
		t /= x;
		if (t == 1) {
			return true;
		}
	}
}

int main() {
	int64_t N;
	cin >> N;
	int64_t a=0, b=0, c=0, x, y, z;
	int64_t m = N;
	double r = sqrt(N);
	for (int i = 2; i <= m; i++) {
		if (!is_prime(i)) {
			continue;
		}
		if (N % i == 0) {
			a++;
			N /= i;
			m /= i;
		}
		// std::cout << "test " << i << " N " << N << '\n';
		if (N <= i) {
			break;
		} else if (i > 5000000) {
			a++;
			break;
		}
	}
	// if (m<N && is_prime(N)) a++;
	std::cout << a << '\n';
}


Measured memory_bytes: 3680
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int const maxn=200000+10;
int n,H[maxn],N[maxn*2],V[maxn*2],d[maxn],W[maxn],tot;
void add(int u,int v){
	V[++tot]=v;N[tot]=H[u];H[u]=tot;
}
void dfs(int u,int fa){
	int i,v;
	W[u]+=d[u];
	for(i=H[u];i;i=N[i]){
		v=V[i];
		if(v==fa) continue;
		d[v]+=d[u];
		dfs(v,u);
	}
}
int main(){
	int i,j,u,v,q;
	scanf("%d%d",&n,&q);
	
	for(i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		add(u,v);add(v,u);
	}
	while(q--){
		scanf("%d%d",&u,&v);
		d[u]+=v;
	}
	dfs(1,0);
	for(i=1;i<=n;i++) printf("%d ",W[i]);
	return 0;
}


Measured memory_bytes: 17280
#include <iostream>
#include <utility>
#include <vector>
#include <tuple>
#include <unordered_map>
#include <algorithm>
#include <boost/functional/hash.hpp>

int main(){
  int N;
  std::cin >> N;
  std::unordered_map<std::tuple<int,int>, std::vector<std::tuple<int,int>>,boost::hash<std::tuple<int,int>>> t_arr;
  std::unordered_map<std::tuple<int,int>, int,boost::hash<std::tuple<int,int>>> in_nodes;

  for(int i = 0; i < N; i++){
    int a;
    std::cin >> a;
    std::pair<int,int> p = std::minmax(i, a-1);
    in_nodes[p];
    for(int j = 1; j < N-1; j++){
      std::cin >> a;
      std::pair<int,int> q = std::minmax(i, a-1);
      t_arr[p].push_back(q);
      in_nodes[q] += 1;
      p = q;
    }
  }

  std::vector<std::tuple<int,int>> p1, p2;
  for(auto&& it: in_nodes){
    if(it.second == 0) p1.push_back(it.first);
  }

  int ncount = 0, nd = 0;
  while(ncount < in_nodes.size()){
    if(p1.size() == 0){
      nd = -1;
      break;
    }
    ncount += p1.size();
    nd++;
    for(auto&& it: p1){
      for(auto&& it2: t_arr[it]){
        in_nodes[it2] -= 1;
        if(in_nodes[it2] == 0) p2.push_back(it2);
      }
    }
    p1.clear();
    std::swap(p1, p2);
  }

  std::cout << nd << std::endl;

  return 0;
}



Measured memory_bytes: 78568
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> p(51), b(51);

ll f(ll n, ll x) {
	if (n == 0) {
		if (n >= x)
			return 0;
		return 1;
	}
	if (x <= 1 + b[n-1])
		return f(n-1, x-1);
	if (x == (2 + b[n-1]))
		return p[n-1] + 1;
	if (x <= 2 + 2 * b[n-1])
		return p[n-1] + 1 + f(n-1, x-2-b[n-1]);
	return 2 * p[n-1] + 1;
}

int main() {
	ll n; cin >> n;
	ll x; cin >> x;
	p[0] = b[0] = 1;
	for (int i = 0; i < 50; i++) {
		b[i+1] = b[i] * 2 + 3;
		p[i+1] = p[i] * 2 + 1;
	}
	cout << f(n, x) << '\n';
	return 0;
}


Measured memory_bytes: 3608
import java.util.Scanner;
import java.util.LinkedList;
import java.util.Queue;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int nodeCount = sc.nextInt();
		
		int[][] edges = new int[nodeCount][nodeCount];
		//each row is that node's edges
		
		//fill the edges array
		for(int i = 0; i < nodeCount; i++) {
			int node = sc.nextInt();
			int edgeCount = sc.nextInt();
			for(int j = 0; j < edgeCount; j++) {
				edges[i][sc.nextInt()-1] = 1;
			}
		}
		
		int[] visited = new int[nodeCount];
		int[] answers = new int[nodeCount];
		for(int i = 0; i < nodeCount; i++) {
			answers[i] = -1;
		}
		
		Queue<Integer> curQ = new LinkedList<>();
		Queue<Integer> nextQ = new LinkedList<>();
		
		
		//do the thing
		int row = 0;
		curQ.add(0);
		visited[0] = 1;
		answers[0] = 0;
		int round = 1;
		while(curQ.peek() != null) {
			//use curQ to make nextQ, update visited, update answers
			while(curQ.peek() != null) {
				row = curQ.remove();
				for(int i = 0; i < nodeCount; i++) {
					if(edges[row][i] == 1 && visited[i] == 0){
						nextQ.add(i);
						visited[i] = 1;
						answers[i] = round;
					}
				}
			}
			//transfer nextQ to curQ
			while(nextQ.peek() != null) {
				curQ.add(nextQ.remove());
			}
			round++;
		}
		
		
		for(int i = 0; i < answers.length; i++) {
			System.out.println((i + 1) + " " + answers[i]);
		}
		sc.close();
	}
	
}



Measured memory_bytes: 28732
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
Ps = list(mapint())
ans = 0

for i in range(1, N-1):
    if Ps[i-1]<=Ps[i]<Ps[i+1] or Ps[i+1]<=Ps[i]<Ps[i-1]:
        ans += 1
print(ans)

Measured memory_bytes: 61388
import collections
N,C=map(int,raw_input().split())
a=collections.defaultdict(list)

max_t=0
for i in range(N):
	s,t,c=map(int,raw_input().split())
	a[c].append((s,t))
	max_t=max(max_t,t)

[a[i].sort() for i in a.keys()]
#print a
#print max_t

b=collections.defaultdict(list)


for i,j in a.items():
	start=0
	end=0
	for k in j:
		if start==0 and end==0:
			start=k[0]-1
			end=k[1]
			continue
		elif k[0]<=end:
			end=k[1]
		else:
			b[i].append((start,end))
			start=k[0]-1
			end=k[1]
	else:
		b[i].append((start,end))		

#print "# b"
#print b

c=[0 for i in range(max_t+2)]

for i in b.values():
	for j,k in i:
		#print j,1,k+1,-1
		c[j]+=1
		c[k]-=1
#print c

ans=0
sum=0
for i in c:
	sum+=i
	ans=max(ans,sum)

print ans




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

int main() {
  int N;
  string S;
  cin >> N >> S;
  long long r = 0, g = 0, b = 0;
  for (auto c : S) {
    if (c == 'R')
      ++r;
    else if (c == 'G')
      ++g;
    else
      ++b;
  }
  long long all = r * g * b;
  long long sub = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      if (S[i] == S[j])
        continue;
      int k = j * 2 - i;
      if (k >= N || S[k] == S[i] || S[k] == S[j])
        continue;
      ++sub;
    }
  }
  cout << all - sub << endl;
}

Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

class City{
public:
  ll normal_fare;
  ll ic_fare;
  ll ic_price;
  City(ll normal_fare,ll ic_fare,ll ic_price){
    this->normal_fare = normal_fare;
    this->ic_fare = ic_fare;
    this->ic_price = ic_price;
  }
};

int main(){
  int total_cities;
  int travel_period;
  while(~scanf("%d %d",&total_cities,&travel_period)){
    vector<int> route;
    for(int day = 0; day < travel_period; day++){
      int city;
      scanf("%d",&city);
      city--;
      route.push_back(city);
    }
    
    vector<City> cities;
    for(int city_i = 0; city_i < total_cities - 1; city_i++){
      ll normal_fare;
      ll ic_fare;
      ll ic_price;
      scanf("%lld %lld %lld",&normal_fare,&ic_fare,&ic_price);
      cities.push_back(City(normal_fare,ic_fare,ic_price));
    }
    ll count[100001] = {};
    for(int route_i = 0; route_i + 1 < route.size(); route_i++){
      int from = route[route_i];
      int to = route[route_i + 1];
      if(from < to){
        count[from]++;
        count[to]--;
      }
      else{
        count[to]++;
        count[from]--;
      }
    }

    ll res = 0;
    int sum = 0;
    for(int city_i = 0; city_i < total_cities - 1; city_i++){
      sum += count[city_i];
      res += min(sum * cities[city_i].normal_fare,
                 sum * cities[city_i].ic_fare + cities[city_i].ic_price);
    }
    printf("%lld\n",res);
  }
}

Measured memory_bytes: 6068
# include <iostream>

using namespace std;

int main(){
  int K, S, count;

  cin >> K >> S;

  count = 0;
  for (int x = 0; x <= S && x <= K; x++) {
    for (int y = 0; y <= S-x && y <= K; y++) {
      if (S-x-y<=K) {
	count++;
      }
    }
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range((n+1)//2):
  here = n-1-2*i
  b.append(str(a[here]))
for i in range(n//2):
  here = 2*i+(n%2)
  b.append(str(a[here]))
print(' '.join(b))

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

#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()

signed main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << (b-a == c-b ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
MOD = 10 ** 9 + 7

N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A.sort(reverse = True)
B.sort(reverse = True)

A.append(0)
B.append(0)

if len(set(A)) != len(A) or len(set(B)) != len(B):
    print (0)
    exit()

# print ()
ans = 1
a = 0
b = 0
for i in range(N * M, 0, -1):
    while A[a] > i:
        a += 1

    while B[b] > i:
        b += 1
    
    if A[a] == i and B[b] == i:
        pass
    elif A[a] < i and B[b] < i:
        ans *= a * b - (N * M - i)
    elif A[a] < i:
        ans *= a
    elif B[b] < i:
        ans *= b
    ans %= MOD
    # print (i, a, b, 'ans =', ans)

print (ans)

    

Measured memory_bytes: 3316
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
typedef long long ll;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int dp[100010];

int main() {
    int X;
    cin >> X;
    dp[0] = 1;
    for(int i = 0; i < X; i++) {
        if(dp[i]) {
            dp[i + 100] = 1;
            dp[i + 101] = 1;
            dp[i + 102] = 1;
            dp[i + 103] = 1;
            dp[i + 104] = 1;
            dp[i + 105] = 1;
        }
    }
    cout << dp[X] << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<cstring>
#include<queue>
#include<algorithm>

using namespace std;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define reep(i, s, t) for(int i=s;i<(int)t;i++)
#define irep(i, n) for(int i=(int)n-1;i>=0;i--)
#define ireep(i, n, s) for(int i=(int)n-1;i>=s;i--)
#define all(v) v.begin(), v.end()
#define vc vector
#define pb push_back

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

struct Card
{
	int num;
	char color;

	friend bool operator < ( const Card& c1, const Card& c2 )
	{
		return (c1.num == c2.num ? c1.color < c2.color : c1.num < c2.num);
	}
};

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

	rep(i, n){
		vector<Card> card(9);
		rep(j, 9){
			cin >> card[j].num;
		}
		rep(j, 9){
			cin >> card[j].color;
		}

		sort( all(card) );

		bool flag = false;
		do{
			int cnt = 0;
			rep(i, 3){
				bool issamec = true;
				
				rep(j, 3){
					int idx = i*3 + j;
					if( card[idx].color != card[i*3].color ){
						issamec = false;
						break;
					}
				}

				if( !issamec ){
					break;
				}

				bool issame = true;
				rep(j, 3){
					int idx = i*3 + j;
					if( card[idx].num != card[i*3].num ){
						issame = false;
						break;
					}
				}

				if( issame ){
					++cnt;
					continue;
				}

				bool iscont = true;
				rep(j, 2){
					int idx = i*3 + j;
					if( card[idx].num != card[idx+1].num+1 ){
						iscont = false;
						break;
					}
				}

				if( iscont ){
					++cnt;
				}
			}

			if( cnt == 3 ){
				flag = true;
			}
		}while( !flag && next_permutation(all(card)) );

		cout << flag << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
using namespace std;


int main(){
    FIO
    double a,h,x;
    cin>>a>>h>>x;
    x=x/(a*a);
    
    double angle;
    if(x<=(h/2)){
        
        angle = atan(2*a*x/(h*h));

    }else{
        angle = atan(a/(2*(h-x)));
    }
    
    angle = angle*180/3.1415926535;
    cout<<fixed<<setprecision(10)<<90-angle;
    
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline #inputに置き換え可能

n = int(input())
txy = [[0,0,0]] + [list(map(int,input().split())) for i in range(n)]

flg = True
for i in range(1, n+1):
    dt = txy[i][0] - txy[i-1][0] 
    dx = abs(txy[i][1] - txy[i-1][1])
    dy = abs(txy[i][2] - txy[i-1][2])
    dxdy = dx + dy
    if dt % 2 != dxdy % 2 or dt < dxdy:
        flg = False
        break
print('Yes') if flg else print('No')

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

int main(){
  int r;
  cin>>r;
  cout<<2*r*3.141592;
}

Measured memory_bytes: 3748
def anss(N,K):
    c=0
    for i in range(1,N+1):
        if len(str(i))-str(i).count('0') == K:
            c+=1
    return c
def solve(p,n,k):
    if p == 0:
        return 0
    if k==1:
        return 10 + 9*(n-1)+(p-1)
    elif k==2:
        return 81 * n*(n-1)//2 + (p-1)*9*n
    else:
        return 729 * n*(n-1)*(n-2)//6 + (p-1)*81*n*(n-1)//2

N=input()
K=int(input())

N=str(N)
NN = [i for i in list(N) if i != '0']
dig = len(N) - 1

if K == 2:
    if len(NN) == 1:
        n0 = int(N[0])
        ans= (solve(n0,dig,2))
    else:
        n0 = int(N[0])
        for inn,nn in enumerate(N[1:]):
            if nn != '0':
                n1 = int(nn)
                break
        ans= (solve(n0,dig,2) + solve(n1,dig-inn-1,1))
elif K == 3:
    if len(NN) == 1:
        n0 = int(NN[0])
        ans=solve((n0),dig,3)
    elif len(NN) == 2:
        n0 = int(N[0])
        for inn,nn in enumerate(N[1:]):
            if nn != '0':
                n1 = int(nn)
                break
        ans= (solve(n0,dig,3) + solve(n1,dig-inn-1,2))
    else:
        n0 = int(N[0])
        
        n1 = int(N[1])
        n2 = int(N[2])
        ans=solve((n0),dig,3) + solve(n1,dig-1,2) + solve(n2,dig-2,1)
elif K == 1:
    ans=(solve(int(N[0]),dig,1))
    
print(ans)

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

map<ll,ll> prime(ll n){
	map<ll,ll> mp;
	for(ll i = 2; i*i <= n; i++){
		while(n % i == 0){
			n /= i;
			mp[i]++;
		}
	}
	if(n > 1) mp[n] = 1;
	return mp;
}

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	ll n; cin >> n;

	int ans = 0;
	for(auto t : prime(n))
		ans += (int)(sqrt(8*t.second+1)-1)/2;

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

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

int main() {
  int K;
  cin>>K;
  string S;
  cin>>S;
  int len=S.length();
  if(len<=K){
    cout<<S<<endl;
  }
  else{
    vector<int> vec(K);
    for (int i=0; i<K; i++){
      vec.at(i)=S[i];
    }
    string ans="";
    for (int i=0; i<K; i++){
      ans+=vec.at(i);
    }
    cout<<ans<<"...";
  }
}

Measured memory_bytes: 3592
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		int x = scanner.nextInt();
		int i = 0;
		
		while (x != 0) {
			i++;
			System.out.println("Case " + i + ": " + x);
			x = scanner.nextInt();
		}

	}

}



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

int main()
{
  int N;
  cin >> N;
  int r = 0, r2 = 0;
  while (N--) {
    int a;
    cin >> a;
    r += a, r2 += a * a;
  }
  cout << (r * r - r2) / 2 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int d[1000][1000];
int M=2100000000;
int wafl(int v,int e,int *a,int *b,int *c){
  int i,j,k;
  for(i=0;i<v;i++){
    for(j=0;j<v;j++)d[i][j]=M;
    d[i][i]=0;
  }
  for(i=0;i<e;i++)d[a[i]][b[i]]=c[i];
  for(k=0;k<v;k++){
    for(i=0;i<v;i++){
      for(j=0;j<v;j++){
	if(d[i][k]==M||d[k][j]==M)continue;
	if(d[i][j]>d[i][k]+d[k][j])d[i][j]=d[i][k]+d[k][j];
      }
    }
  }
  for(i=0;i<v;i++){
    if(d[i][i])return 1;
  }
  return 0;
}
int main(){
  int n,m,i,j,a[100010],b[100010],c[100010];
  scanf("%d %d",&n,&m);
  for(i=0;i<m;i++)scanf("%d %d %d",&a[i],&b[i],&c[i]);
  if(wafl(n,m,a,b,c))printf("NEGATIVE CYCLE\n");
  else{
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	if(j)printf(" ");
	d[i][j]-M?printf("%d",d[i][j]):printf("INF");
      }
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 1116
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}

void solve(){
	int n,k;
	cin>>n>>k;
	int a[n+2];
	rep(i,n)cin>>a[i+1];
	while(k--){
		int b[n+2];
		memset(b,0,sizeof(b));
		for(int i=1;i<=n;i++){
			int l=max(1,i-a[i]);
			int r=min(n,i+a[i]);
			b[l]++;
			b[r+1]--;
		}
		int c=0;
		for(int i=1;i<=n;i++){
			a[i]=b[i]=b[i-1]+b[i];
			if(a[i]==n)c++;
		}
		if(c==n)break;
	}
	rep(i,n)cout<<a[i+1]<<" ";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 5124
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)
n,m=map(int,input().split())

edges=[[] for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    edges[a].append(b)
    edges[b].append(a)
def dfs(cnt,v,before=-1):
    if cnt>=2:
        return False
    ans=False
    for to in edges[v]:
        if to!=before:
            if to==n-1:
                return True
            else:
                ans|=dfs(cnt+1,to,v)
    return ans

if dfs(0,0):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


Measured memory_bytes: 38320
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def modpow(a, n, mod):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n >>= 1
    return res


def modinv(a, mod):
    return modpow(a, mod - 2, mod)


def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = float("inf")
    s = a[0]
    su = sum(a) - a[0]
    ans = min(ans , abs(s - su))
    for i in range(1, n-1):
        s += a[i]
        su -=a[i]
        ans = min(ans, abs(s - su))
    print(ans)
    



if __name__ == '__main__':
    main()


Measured memory_bytes: 27600
import itertools

n=int(input())
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))


l=[i+1 for i in range(n)]
t = list(itertools.permutations(l, n))

a=t.index(p)
b=t.index(q)
 
print(abs(a-b))

Measured memory_bytes: 8052
#include<bits/stdc++.h>
using namespace std;
int n,x,ans;
priority_queue<int>pq;
map<int,int>pos;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		pos[x]=i%2;
		pq.push(-x);	
	}
	for(int i=1;i<=n;i+=2)
	{
		if(!pos[-pq.top()])ans++;
		pq.pop();
		if(!pq.empty())pq.pop();
	}
	printf("%d",ans);
}

Measured memory_bytes: 5368
#line 1 "test/aoj/ITP1_7_D.test.cpp"
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_D"
#line 1 "test/aoj/../../math/matrix.cpp"
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

template< class T >
struct Matrix {
  const size_t H, W;
  vector< vector< T > > A;
  Matrix() {}
  Matrix(size_t n, size_t m) : H(n), W(m), A(H, vector< T >(W, 0)) {}
  Matrix(size_t n) : H(n), W(n), A(H, vector< T >(W, 0)) {};
  size_t height() const { return H; }
  size_t width() const { return W; }
  inline const vector< T > &operator[](int k) const { return (A.at(k)); }
  inline vector< T > &operator[](int k) { return (A.at(k)); }
  static Matrix I(size_t n) {
    Matrix mat(n);
    for(int i = 0; i < n; i++) mat[i][i] = 1;
    return (mat);
  }

  Matrix &operator+=(const Matrix &B) {
    assert(H == B.H && W == B.W);
    for(int i = 0; i < H; i++)
      for(int j = 0; j < W; j++)
        (*this)[i][j] += B[i][j];
    return (*this);
  }

  Matrix &operator-=(const Matrix &B) {
    assert(H == B.H && W == B.W);
    for(int i = 0; i < H; i++)
      for(int j = 0; j < W; j++)
        (*this)[i][j] -= B[i][j];
    return (*this);
  }

  Matrix &operator*=(const Matrix &B) {
    assert(W == B.H);
    vector< vector< T > > C(H, vector< T >(B.W, 0));
    for(int i = 0; i < H; i++)
      for(int j = 0; j < B.W; j++)
        for(int k = 0; k < W; k++)
          C[i][j] += ((*this)[i][k] * B[k][j]);
    A.swap(C);
    return (*this);
  }

  Matrix &operator^=(long long k) {
    Matrix B = Matrix::I(H);
    while(k > 0) {
      if(k & 1) B *= *this;
      *this *= *this;
      k >>= 1LL;
    }
    A.swap(B.A);
    return (*this);
  }

  Matrix operator+(const Matrix &B) const { return (Matrix(*this) += B); }
  Matrix operator-(const Matrix &B) const { return (Matrix(*this) -= B); }
  Matrix operator*(const Matrix &B) const { return (Matrix(*this) *= B); }
  Matrix operator^(const long long k) const { return (Matrix(*this) ^= k); }

  friend ostream &operator<<(ostream &os, Matrix &p) {
    for(int i = 0; i < p.H; i++) {
      for(int j = 0; j < p.W; j++) {
        os << p[i][j] << (j + 1 == p.W ? "\n" : " ");
      }
    }
    return (os);
  }
};
#line 3 "test/aoj/ITP1_7_D.test.cpp"
#include <iostream>
using namespace std;

using matrix = Matrix<long long>;
int main() {
  int n, m, l; cin >> n >> m >> l;
  matrix A(n, m), B(m, l);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> A[i][j];
    }
  }
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < l; ++j) {
      cin >> B[i][j];
    }
  }
  matrix C = A*B;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < l; ++j) {
      cout << C[i][j] << (j+1 == l ? "\n":" ");
    }
  }
}


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n), b(n-1, 0), d(n, 0);
  rep(i, n){
    cin >> a.at(i);
  }
  rep(i, n-1){
    if(a.at(i)>=a.at(i+1)){
      b.at(i) = 1;
    }
  }
  
  int count=0;
  
  rep(i, n-1){
    
    if(b.at(i)==1){
      count++;
    }
    else if(b.at(i)==0){
      d.at(i) = count;
     
      count = 0;
    }
    
    
  }
  d.at(n-1) = count;
  
  
  int max = 0;
  rep(i, n){
    if(max<d.at(i)){
      max = d.at(i);
    }
  }
  cout << max << endl;

}

Measured memory_bytes: 1408
# -*- coding: utf-8 -*-
"""
Created on Sat Jul  7 20:14:40 2018
SHPC_B
@author: maezawa
"""

s = input()
w = int(input())

n = len(s)
ans = []

for i in range(0,n,w):
    ans.append(s[i])
    
print(''.join(ans))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define fast ios::base_sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define M 1000000007
#define pie 3.141592653589793238
using namespace std;
 
signed main(){
    string t,s;cin>>t>>s;
    cout<<s<<t;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
using P = pair<long long, long long>;

int main() {
  long long a[200000];
  long long N;
  cin >> N;
  vector<long long> v;
  rep(i, N) {
    long long temp;
    cin >> temp;
    temp--;
    v.push_back(temp);
    a[temp]++;
  }
  long long sum = 0;
  rep(i, N) {
    sum += a[i] * (a[i]-1) / 2;
  }
  long long b[200000];
  rep(i, N) {
    b[i] = sum - a[i] + 1;
  }
  rep(i, v.size()) {
    cout << b[v[i]] << endl;
  }
  return 0;
}

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

int main()
{
    int r,i,j;
    char a[105];
    scanf("%d",&r);
    scanf("%s",a);
    if(r%2!=0)
        {
            printf("No\n");
            return 0;
        }
    for(i=r/2,j=0;j<r/2;j++,i++)
    {
        if(a[i]!=a[j])
        {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        while(true){
            int m=sc.nextInt();
            if(m==0)
                break;
            int nmin=sc.nextInt();
            int nmax=sc.nextInt();
            Integer p[]=new Integer[m];
            int i;
            for(i=0;i<m;i++){
                p[i]=sc.nextInt();
            }
            Arrays.sort(p,Collections.reverseOrder());
            int gap=0;
            int j=0;
            
            for(i=nmin-1;i<nmax;i++){
                if(gap<=p[i]-p[i+1]){
                    gap=p[i]-p[i+1];
                    j=i+1;
                }
            }
            System.out.println(j);        
        }
    }
}




Measured memory_bytes: 57744
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	int a,b,c,x,y,z;
	cin>>a>>b>>c>>x>>y;
	ll ans = 0ll;
	if(c*2<=a+b)
	{
		z = min(x,y);
		ans = ans + 2ll*z*c;
		x -= z;
		y -= z;
	}
	if(c*2<=b)
	{
		ans = ans + 2*c*y;
	}
	else		ans = ans + y*b;
	y=0;
	if(c*2<=a)
	{
		ans = ans + 2*c*x;
	}
	else		ans = ans + x*a;
	x=0;
	cout<<ans;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Painting_problem
{
    class Program
    {
        static int height = 0;
        static int width = 0;
        static int[,] datas;
        static void Main(string[] args)
        {
            String input = Console.ReadLine();
            try
            {
                height = Int32.Parse(input.Split(' ')[0]);
                width = Int32.Parse(input.Split(' ')[1]);
                datas = new int[height + 1, width + 1];
                for (int i = 0; i < height; i++)
                {
                    input = Console.ReadLine();
                    for (int j = 0; j < width; j++)
                    {
                        if (input[j].Equals('#'))
                        {
                            datas[i, j] = 1;
                        }
                    }
                }
            }
            catch (Exception)
            {
                Console.WriteLine("形式エラー");
                Console.ReadLine();
                return;
            }
            //Paint
            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    if (!PaintOut(i, j))
                    {
                        Console.WriteLine("No");
                        return;
                    }
                }
            }
            Console.WriteLine("Yes");
        }

        static Boolean PaintOut(int x, int y)
        {
            if (datas[x,y] == 1)
            {
                bool isSuccess = false;
                if (x > 0)
                {
                    isSuccess = isSuccess || datas[x - 1, y] != 0;
                }
                if (y > 0)
                {
                    isSuccess = isSuccess || datas[x, y - 1] != 0;
                }
                isSuccess = isSuccess || datas[x + 1, y] != 0;
                isSuccess = isSuccess || datas[x, y + 1] != 0;
                return isSuccess;
            }
            return true;
        }
    }
}


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

using namespace std;

int main()
{
    int n ;
    cin>>n ;
    int arr[n] , sum = 0;
    for(int i = 0 ; i < n ; ++i)
    {
        cin>>arr[i] ;
        sum += arr[i] ;
    }
    double x = sum * 1.00 / n*1.00 ;
    int ans = 0 ;
    double MIN = 1e9 ;
    for(int i = 0 ; i < n ; ++i)
    {
        if(abs(x - (arr[i]*1.00)) < MIN)
            MIN = abs(x - (arr[i]*1.00)) , ans = i ;
    }
    return cout<<ans , 0 ;
}


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

#define LL long long
#define Dl double
#define Pb push_back
#define Po pop_back
#define Mp make_pair
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)

using namespace std;

typedef vector<LL> Vl;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef vector<Pll> Vpl;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
#define X first
#define Y second
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

LL a[210];

int main()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

    LL n;
    cin >> n;

    n <<= 1;
    for(LL i = 0; i < n; i++)
        cin >> a[i];

    sort(a, a + n);

    LL ans = 0;
    for(LL i = 0; i < n; i += 2)
        ans += a[i];

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    return buf
}

fn main() {
  let line = gets();
  let n = line.trim().parse::<usize>().unwrap();
  let line = gets();
  let mut a: Vec<i64> = line.split_whitespace().map(|x| x.parse::<i64>().unwrap()).collect();
  let mut l = &0;
  let mut s = &0;
  a.sort_by(|x, y| y.cmp(x));
  let mut it = a.iter();
  let mut curr = it.next().unwrap();
  let mut cnt = 1;
  loop {
    let x = it.next();
    match x {
      Some(i) if i == curr => cnt = cnt + 1, 
      Some(i) => {
        if cnt >= 4 {
          if l == &0 {
            l = curr;
          }
          if s == &0 {
            s = curr;
          }
        } else if cnt >= 2 {
          if l == &0 {
            l = curr;
          } else if s == &0 {
            s = curr;
          }
        }
        curr = i;
        cnt = 1;
      }, 
      None => {
        if cnt >= 4 {
          if l == &0 {
            l = curr;
          }
          if s == &0 {
            s = curr;
          }
        } else if cnt >= 2 {
          if l == &0 {
            l = curr;
          } else if s == &0 {
            s = curr;
          }
        }
        println!("{}", l * s);
        break;
      }, 
    }
  }
}


Measured memory_bytes: 6396
#include <iostream>
using namespace std;
typedef long long ll;

int main() {    
    int n;
    string s, t;
    cin >> n;
    cin >> s >> t;

    for(int i = 0; i < n; i++) {
        cout << s[i] << t[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;

int main() {
  ll H, W;
  cin >> H >> W;
  if (H == 1 || W == 1) {
    cout << 1 << endl;
    return 0;
  }
  
  ll ans = ((H+1)/2) * ((W+1)/2) + (H/2) * (W/2);
  cout << ans << endl;
  
  return 0;
}



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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define CEIL(n, m) ceil(n/pow(10.0, m))*pow(10.0, m)
#define FLOOR(n, m) floor(n/pow(10.0, m))*pow(10.0, m)
#define ROUND(n, m) round(n/pow(10.0, m))*pow(10.0, m)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define llong long long
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

const int INF = 1000000000;

void solve()
{
  int ans=INF;

  int n; cin >> n;
  vector<int> a(n); REP(i, n) cin >> a[i];
  SORT(a);

  for(int i=a[0]; i<=a[n-1]; i++) {
    int t=0;
    for(int j=0; j<n; j++) {
      t+=pow(a[j]-i, 2);
    }
    ans = min(ans, t);
  }

  cout << ans << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--) 
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();


int main(){
  int n,res=0;
  cin >> n;

  REP(i,n){
    int a;
    cin >> a;
    if(a%2==1)
      res++;
  }
  if(res%2==0)
  cout <<"YES" << endl;
  else
    cout << "NO" << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
#define rep(i, s, n) for(i64 i=(s); i < (n); ++i)
using namespace std;
using i64 = long long;
using pii = pair<int, int>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD  = int(1e9) + 7;

signed main()
{
  char s[5];
  cin >> s;

  cout << (
      s[0] - '0' +
      s[1] - '0' +
      s[2] - '0'
  ) << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

ll power(ll x, ll pw, ll mod) {
    ll res = 1;
    x = x % mod;  // if it x >= p
    while (pw > 0) {
        if (pw & 1)
            res = (res*x) % mod;
        pw /= 2;
        x = (x*x) % mod;
    }
    return res;
}
ll modInverse(ll n, ll p) {
    return power(n, p-2, p) % p; // Fermat's little theorem
}

int main() {
    ll n, x, m;
    cin >> n >> x >> m;
    vector<ll> bucket(m, 0);
    ll pre = x;
    bucket[x] += 1;
    ll period = -1;
    vector<ll> pos(m, -1);
    pos[x] = 0;
    ll ans = x;
    vector<ll> rec(m, -1);
    rec[0] = x;
    for(int i = 1; i < n; i++) {
        ll cur = (pre*pre) % m;
        if (pos[cur] == -1) {
            bucket[cur] += 1;
            pos[cur] = i;
            rec[i] = cur;
            ans += cur;
        } else {
            period = i-pos[cur];
            //cout << "period " << period << endl;
            int beg = pos[cur];
            ll remain = n-i;
            ll repeat_sum = 0;
            for(int j = beg; j < i; j++)
                repeat_sum += rec[j];
            ll repeat_times = remain / period;
            ans += repeat_times * repeat_sum;
            ll rem = remain % period;
            for(int j = beg; j < beg+rem; j++) {
                ans += rec[j];
            }
            //cout << "remain " << remain << endl;
            break;
        }
        pre = cur;
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 5516
#include <bits/stdc++.h>
using namespace std;
const int MM = 10005;
int N, a[MM], b[MM], sum; vector<int> adj[MM]; bool vis[MM];
int main(){
    scanf("%d", &N);
    for(int i=1, u, v; i<N; i++){
        scanf("%d %d", &u, &v); adj[u].push_back(v); adj[v].push_back(u);
    }
    for(int i=0; i<N; i++){
        scanf("%d", &a[i]); sum += a[i];
    }
    sort(a, a+N); sum -= a[N-1];  printf("%d\n", sum);
    queue<int> Q; int t=N-1;
    Q.push(1); vis[1]=1;
    while(!Q.empty()){
        int u = Q.front(); Q.pop(); b[u] = a[t--];
        for(int v: adj[u]){
            if(!vis[v]){ Q.push(v); vis[v]=1; }
        }
    }
    for(int i=1; i<=N; i++) printf("%d ", b[i]);
    printf("\n");
}


Measured memory_bytes: 1024
import Foundation

func readInt() -> Int {
    return Int(readLine()!)!
}

func readString() -> String {
    return readLine()!
}

func readLines(times: Int) -> [String] {
    var array = [String]()
    for _ in 0..<times {
        array.append(readLine()!)
    }
    return array
}

func readSeparatedStrings() -> [String] {
    return readLine()!.split(separator: " ").map {String($0)}
}

func readStringToStrings() -> [String] {
    return readLine()!.map{String($0)}
}

func readSeparatedInts() -> [Int] {
    return readLine()!.split(separator: " ").map {Int($0)!}
}
func readSeparatedDouble() -> [Double] {
    return readLine()!.split(separator: " ").map {Double($0)!}
}

// 二進数に変換
func convertIntToRadix2(n: Int, radix: Int = 2) -> String {
    return String(n, radix: radix)
}

//配列を逆順にする reverced ソートする　sorted
//最初数文字取得 prefix

let abcd = readSeparatedInts()

var products = [Int]()
products.append(abcd[0] * abcd[2])
products.append(abcd[0] * abcd[3])
products.append(abcd[1] * abcd[2])
products.append(abcd[1] * abcd[3])
products.sort { a, b in a > b }
print(products.first!)


Measured memory_bytes: 13740
import java.util.Scanner

object Main {
  def solve(sc: => Scanner): Unit = {
    val A, B = sc.nextDouble
    val N: Double = (math.max(A, B) - math.min(A, B)) / 2 + math.min(A, B)
    println( if (math.abs(A - N) < 90) (N) else {
      if (N + 180 >= 360) (N - 180) else (N + 180)
    })
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)

    solve(sc)
  }
}

Measured memory_bytes: 45920
import sys
input = sys.stdin.readline

Sdict = {}
Tdict = {}
N = int(input().rstrip())
for i in range(N):
  item = input().rstrip()
  if item not in Sdict.keys():
    Sdict[item] = 1
  else:
    Sdict[item] += 1
M = int(input().rstrip())
for i in range(M):
  item = input().rstrip()
  if item not in Tdict.keys():
    Tdict[item] = 1
  else:
    Tdict[item] += 1

ans_dict = {'0': 0}
for i in Sdict.keys():
  S = Sdict[i]
  if i not in Tdict:
    T = 0
  else:
    T = Tdict[i]
  ans_dict[i] = S-T

print(max(ans_dict.values()))


Measured memory_bytes: 38384
import java.util.Scanner;

public class Main{
  static int[][][] dp;
  static int[] a;
  static int[] b;
  static int[] c;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int Ma = Integer.parseInt(sc.next());
    int Mb = Integer.parseInt(sc.next());
    a = new int[N];
    b = new int[N];
    c = new int[N];
    for(int i=0; i<N; i++){
      a[i] = Integer.parseInt(sc.next());
      b[i] = Integer.parseInt(sc.next());
      c[i] = Integer.parseInt(sc.next());
    }
    dp = new int[N+1][500][500];
    for(int i=0; i<N+1; i++){
      for(int j=0; j<499; j++){
        for(int k=0; k<499; k++){
          dp[i][j][k] = Integer.MAX_VALUE/2;
        }
      }
    }
    dp[0][0][0] = 0;
    for(int i=0; i<N; i++){
      for(int j=0; j<400; j++){
        for(int k=0; k<400; k++){
          //i番目の物質を追加するとき
          dp[i+1][j+a[i]][k+b[i]] = Math.min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);
          //i番目の物質を追加しないとき
          dp[i+1][j][k] = Math.min(dp[i+1][j][k],dp[i][j][k]);
        }
      }
    }
    int min = Integer.MAX_VALUE/2;
    for(int i = 1; i <= 400; i++){
        for(int j= 1; j <= 400; j++){
            if(Ma*j == Mb*i && dp[N][i][j]!=Integer.MAX_VALUE){
                min = Math.min(min,dp[N][i][j]);
            }
        }
    }
    if(min == Integer.MAX_VALUE/2)System.out.println(-1);
    else System.out.println(min);
  }
}

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

int partition(int A[], int p, int r){
    int x = A[r];
    int i = p-1;
    for(int j=p; j<r; j++){
        if(A[j] <= x){
            i++;
            swap(A[i], A[j]);
        }
    }
    swap(A[i+1], A[r]);
    return i+1;
}

int main(void){
    int n;
    int A[100001];
    cin >> n;
    for(int i=0; i<n; i++) cin >> A[i];
    
    int q = partition(A, 0, n-1);
    for(int i=0; i<n; i++){
        cout << (i ? " " : "") << (i==q ? "[" : "") << A[i] << (i==q ? "]" : "");
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3476
import java.util.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int V, d, N;
	static int[] fib = new int[1001];
	
	public static void main(String[] args) {
		N = 1001;
		fib[0] = 1; fib[1] = 2;
		for (int i = 2; i < 1001; i++)
			fib[i] = (fib[i - 1] + fib[i - 2]) % N;
		
		while (read()) {
			solve();
		}
	}
	
	static boolean read() {
		if (!sc.hasNextInt()) return false;
		V = sc.nextInt();
		d = sc.nextInt();
		return true;
	}
	
	static void solve() {
		UF uf = new UF(V + 1);
		for (int i = 1; i <= V; i++) {
			for (int j = i + 1; j <= V; j++) {
				if (abs(fib[i] - fib[j]) < d) {
					uf.merge(i, j);
				}
			}
		}
		
		int res = 0;
		for (int i = 1; i <= V; i++) {
			if (i == uf.find(i))
				res++;
		}
		System.out.println(res);
	}	
}

class UF {
	int[] p, r;
	
	UF(int n) {
		p = new int[n];
		r = new int[n];
		for (int i = 0; i < n; i++) {
			p[i] = i;
			r[i] = 0;
		}
	}
	
	int find(int x) {
		if (x == p[x]) return p[x];
		else return p[x] = find(p[x]);
	}
	
	void merge(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		
		if (r[x] < r[y]) p[x] = y;
		else {
			p[y] = x;
			if (r[x] == r[y]) r[x]++; 
		}
	}
}

Measured memory_bytes: 12000
// She is Pretty pretty!
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

const int N = 1e6 + 100;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n, m, sum = 0;
    cin >> n >> m;
    vector<ll> a(m+10);
    for (int i = 0; i < m; i++) {
        cin >> a[i];
        sum += a[i];
    }
    if (sum > n) {
        puts("-1");
    } else {
        cout << n - sum << endl;
    }
    return 0;
}

Measured memory_bytes: 3732
n,w = map(int,input().split())
weight = [0]*n
value = [0]*n
for i in range(n):
    weight[i],value[i] = map(int,input().split())
dp = [[1000000001 for i in range(max(value)*n+1)]for j in range(n+1)]
dp[0][0] = 0

for i in range(n):
    for j in range(len(dp[0])):
        if j >= value[i]:
            dp[i+1][j] = min(dp[i][j-value[i]]+weight[i],dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]

ans = 0
for i,j in enumerate(dp[n]):
    if j <= w:
        ans = max(ans,i)

print(ans)

Measured memory_bytes: 171528
from itertools import permutations

n = int(input())
x, y = zip(*[list(map(int, input().split()))for i in range(n)])
ans = cnt = 0
for i in permutations(range(n)):
        cnt += 1
        for j in range(n-1):
                f, t = i[j], i[j+1]
                ans += ((x[f]-x[t])**2 + (y[f]-y[t])**2)**0.5
print(ans/cnt)

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

using namespace std;

int a, b;

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

    cin >> a >> b;

    a--;

    b--;

    if (a == 0) {
        a = 13;
    }

    if (b == 0) {
        b = 13;
    }

    if (a > b) {
        cout << "Alice" << endl;
    }

    if (a < b) {
        cout << "Bob" << endl;
    }

    if (a == b) {
        cout << "Draw" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
/*
 © 2020-08-15 22:18:58 Franco1010 All Rights Reserved
*/

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<lli> vi;
#define deb(x) cout << #x": " << (x) << endl;
const int N = 3005;
lli mat[N][N];
lli dp[N][N][4];
bool vis[N][N][4];
lli r, c, k;
lli solve(lli x, lli y, lli z){
  if(x == r and y == c) return mat[x][y] > 0 and z < 3? mat[x][y] : 0;
  lli &ans = dp[x][y][z];
  if(!vis[x][y][z]){
    vis[x][y][z] = true;
    ans = 0;
    if(y + 1 <= c){
      if(z < 3) ans = max(ans, solve(x, y + 1, z + 1) + mat[x][y]);
      ans = max(ans, solve(x, y + 1, z));
    }
    if(x + 1 <= r){
      if(z < 3) ans = max(ans, solve(x + 1, y, 0) + mat[x][y]);
      ans = max(ans, solve(x + 1, y, 0));
    }
  }
  return ans;
}
int main(){ _
  cin >> r >> c >> k;
  fore(i, 0, N) fore(j, 0, N) mat[i][j] = -1;
  fore(i, 0, k){
    lli x, y, v; cin >> x >> y  >> v;
    // if(v > 0)
    mat[x][y] = v;
    // else mat[x][y] = 0;
  }
  cout << solve(1, 1, 0) << ENDL;
  return 0;
}


Measured memory_bytes: 391380