akhauriyash/Code-Regression huggingface dataset:
while(True):
  n = int(input())
  if n == 0:
    quit()
  a = []
  for i in range(n):
    a.append(int(input()))
  a.sort()
  a = a[1:-1]
  ans = 0
  for j in a:
    ans += j
  print(ans//len(a))



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

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int main(){
	int a,b,c;
	cin >> a >> b >>c;
	int i=0;
	while(i < b && i*a % b !=c ) i++;
	if(i < b) cout <<"YES";
	else cout << "NO";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <algorithm>
using namespace std;

int N;
vector<vector<int>> G;
vector<int> C;

void dfs(vector<int> &nums, int u, int &cnt) {
    nums[u] = C[cnt++];

    for (int v : G[u]) {
        if (nums[v] != 0) continue;
        dfs(nums, v, cnt);
    }
}


int main() {
    cin >> N;
    G.resize(N); C.resize(N);
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for (int i = 0; i < N; i++) cin >> C[i];

    sort(C.begin(), C.end(), greater<int>());
    int res = 0;
    for (int i = 1; i < N; i++) res += C[i];

    vector<int> nums(N, 0);
    int cnt = 0;
    dfs(nums, 0, cnt);

    cout << res << endl;
    for (int i = 0; i < N; i++) {
        cout << nums[i] << " ";
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
#define INF 10000000000

int main() {
	int n, k, ans;
	cin >> n >> k;
	vector<int> p(n);
	for (int i = 0; i < n; i++) {
		cin >> p.at(i);
	}

	sort(p.begin(), p.end());
	ans = 0;
	for (int i = 0; i < k; i++) {
		ans += p[i];
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
	int H, W;
	int h, w;

	while (1) {
		scanf("%d%d", &H, &W);
		if (H == 0 && W == 0) break;
		for (h = 0; h < H; h++) {
			for (w = 0; w < W; w++) {
				putchar(((h & 1) ^ (w & 1)) == 0 ? '#' : '.');		}
			putchar('\n');
		}
		putchar('\n');
	}
	return 0;
}



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

using namespace std;

void solve() {
	int n; cin >> n;
	vector<int> A(n), B(n);
	rep(i, n) {
		scanf("%d", &A[i]);
		B[i] = A[i];
	}
	sort(B.begin(), B.end());
	int max_f = B[n - 1];
	int max_s = B[n - 2];
	rep(i, n) {
		if (A[i] == max_f) cout << max_s << endl;
		else cout << max_f << endl;
	}
}

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

Measured memory_bytes: 3200
//  Created by liszt on 2019/08/04.
#include<bits/stdc++.h>
using namespace std;

const int nmax = 8;
bool graph[nmax][nmax];

int dfs(int v, int N, bool visited[nmax]){
    
    bool all_visited=true;
    
    for(int i=0;i<N;i++){
        if(visited[i]==false)all_visited=false;
    }
    
    if(all_visited){
        return 1;
    }
    
    int ret=0;
    
    for(int i=0;i<N;i++){
        if(graph[v][i]==false) continue;
        if(visited[i]) continue;
        
        visited[i]=true;
        ret+=dfs(i,N,visited);
        visited[i]=false;
    }
    
    return ret;
}

int main(){
    int N, M;
    cin>>N >>M;
    
    for(int i=0;i<M;i++){
        int A, B;
        cin>>A >>B;
        graph[A-1][B-1]=graph[B-1][A-1]=true;
    }
    
    bool visited[nmax];
    for(int i=0;i<N;i++){
        visited[i]=false;
    }
    
    visited[0]=true;
    cout<<dfs(0,N,visited)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s;
    cin>>t;
    int ln=s.length();
    int ln1=t.length();
    int cnt=0;
    for(int i=0; i<ln; i++)
    {
        if(s[i]==t[i])
        {
            continue;
        }
        else
        {
            cnt++;
            break;
        }
    }
    if(cnt==0)
    {
        if(ln1-1==ln && (t[ln1-1]>='a' && t[ln1-1]<='z'))
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3596
from heapq import heappush, heappop
V, E, r = map(int, input().split())
edges = [[] for _ in [None]*V]
vertices = [10**10]*V
vertices[r] = 0

for _ in [None]*E:
    s, t, d = map(int, input().split())
    edges[s].append((t,d))

q = [(0, r)]
while q:
    cost, v = heappop(q)
    for dest, _cost in edges[v]:
        newcost = cost + _cost
        if vertices[dest] > newcost:
            vertices[dest] = newcost
            heappush(q, (newcost, dest))

print("\n".join([str(n) if n!=10**10 else "INF" for n in vertices]))

Measured memory_bytes: 97976
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		
		int[] dice_number = new int[6];

		for(int side_number = 0; side_number < 6; side_number++) {

			dice_number[side_number] = in.nextInt();

		}

		int question_num = in.nextInt();

		for(int i = 0; i < question_num; i++) {

			dice dice = new dice(dice_number);

			int top_num = in.nextInt();
			int front_num = in.nextInt();

			dice.dice_position(top_num, front_num);

			dice_number = dice.getDice_number();
			System.out.println(dice_number[2]);

		}
	}
}



class dice{

	int[] dice_number;

	// ?????????????????????
	dice(int[] dice_number){

		this.dice_number = dice_number;

	}

	// ????????????
	public int[] getDice_number() {
		return dice_number;
	}

	// ????????????
	public void setDice_number(int[] dice_number) {
		this.dice_number = dice_number;
	}

	// ?????????????????¢??????????????????
	void roll(char roll_direction){

		int tmp;

		switch(roll_direction){

		// ?????????????????¢??????
		case 'S':

			tmp = dice_number[0];
			dice_number[0] = dice_number[4];
			dice_number[4] = dice_number[5];
			dice_number[5] = dice_number[1];
			dice_number[1] = tmp;

			break;

		// ?\\???????????¢??????
		case 'N':

			tmp = dice_number[0];
			dice_number[0] = dice_number[1];
			dice_number[1] = dice_number[5];
			dice_number[5] = dice_number[4];
			dice_number[4] = tmp;

			break;

		// ??????????????¢??????
		case 'W':

			tmp = dice_number[0];
			dice_number[0] = dice_number[2];
			dice_number[2] = dice_number[5];
			dice_number[5] = dice_number[3];
			dice_number[3] = tmp;

			break;

		// ??????????????¢??????

		case 'E':

			tmp = dice_number[0];
			dice_number[0] = dice_number[3];
			dice_number[3] = dice_number[5];
			dice_number[5] = dice_number[2];
			dice_number[2] = tmp;

			break;

		}
	}

	// ?????????????????????????????¢?????????????????????
	void turn(char turn_direction) {

		int tmp;

		switch(turn_direction) {

		// ????????¢
		case 'R':

			tmp = dice_number[1];
			dice_number[1] = dice_number[3];
			dice_number[3] = dice_number[4];
			dice_number[4] = dice_number[2];
			dice_number[2]= tmp;

			break;

		// ????????¢
		case 'L':

			tmp = dice_number[1];
			dice_number[1] = dice_number[2];
			dice_number[2] = dice_number[4];
			dice_number[4] = dice_number[3];
			dice_number[3] = tmp;

			break;

		}
	}

	void dice_position(int top_num, int front_num) {

		if(top_num != dice_number[0]) {

			for(int i = 0; i < 3; i++) {

				roll('S');

				if(top_num == dice_number[0]) {

					break;

				}else{

					roll('E');

					if(top_num == dice_number[0]) {

						break;

					}
				}
			}
		}

		if(front_num != dice_number[1]) {

			for(int i = 0; i < 3; i++) {

				turn('R');

				if(front_num == dice_number[1]) {

					break;

				}
			}
		}
	}
}

Measured memory_bytes: 26156
#include<bits/stdc++.h>
using namespace std;
int n;
vector<int> dp;
bool solve(vector<int> &A, int k)
{
    if(k == 0)
        return 0;
    if(dp[k] != -1)
        return dp[k];
    for(int i = 0; i < n; i++)
    {
        if(k >= A[i])
        {
            bool res = solve(A, k - A[i]);
            if(res ==  0)
            {
                dp[k] = 1;
                return 1;
            }
        }
    }
    dp[k] = 0;
    return 0;
}

int main()
{
    int k;
    cin >> n >> k;
    vector<int> v(n);
    for(int i = 0; i < n; i++)
        cin >> v[i];
    dp = vector<int> (k + 1, -1);
    if(solve(v, k))
        cout << "First";
    else
        cout << "Second";
    return 0;
}

Measured memory_bytes: 6912
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.RoundingMode;

public class Main {

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = null;

		while ((line = br.readLine()) != null) {

			String[] input = line.split(" ");
			BigDecimal a = new BigDecimal(input[0]);
			BigDecimal b = new BigDecimal(input[1]);
			BigDecimal c = new BigDecimal(input[2]);
			BigDecimal d = new BigDecimal(input[3]);
			BigDecimal e = new BigDecimal(input[4]);
			BigDecimal f = new BigDecimal(input[5]);

			BigDecimal y = (a.multiply(f).subtract(d.multiply(c))).divide(a
					.multiply(e).subtract(d.multiply(b)));
			BigDecimal x = (c.subtract(b.multiply(y))).divide(a);

			String answer = x.setScale(3, RoundingMode.HALF_UP).toPlainString()
					+ " " + y.setScale(3, RoundingMode.HALF_UP).toPlainString();
			System.out.println(answer);
		}
	}
}

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

int main(){
	stack<int> garage;

	int car = 0;
	while(cin >> car){

		if(car != 0){
			garage.push(car);
		}else{
			cout << garage.top() << endl;
			garage.pop();
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <list>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

using ll = long long;
ll mod = 1e9 + 7;

int main() {
  string k;
  int d;
  cin >> k >> d;

  int n = k.size();

  ll dp[n + 1][d][2];
  for (int i = 0; i < d; i++) dp[n][i][0] = dp[n][i][1] = 0;
  dp[n][0][0] = dp[n][0][1] = 1;

  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < d; j++) {
      for (int limit : {0, 1}) {
        ll& ans = dp[i][j][limit];
        ans = 0;

        int ub = limit ? (k[i] - '0') : 9;
        for (int k = 0; k <= ub; k++) {
          ans += dp[i + 1][(j + k) % d][limit && (k == ub)];
          ans %= mod;
        }
      }
    }
  }
  cout << (dp[0][0][1] + mod - 1) % mod << endl;

  return 0;
}


Measured memory_bytes: 15872
from collections import Counter as C

n = int(input())
blue = C([input() for _ in range(n)])
m = int(input())
red = C([input() for _ in range(m)])

points = dict(blue)
for rk, rv in red.items():
    points[rk] = points.get(rk, 0) - rv
else:
    print(max(0, max(points.values())))

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

int main() {
	int n,k,s;
	while(cin>>n>>k>>s){
		if(!n&&!k&&!s)return 0;
		int dp[114][514]={};
		dp[0][0]=1;
		for(int i=1;i<=n;i++){
			for(int j=k-1;j>=0;j--){
				for(int l=s-i;l>=0;l--){
					if(dp[j][l]!=0)dp[j+1][l+i]+=dp[j][l];
				}
			}
		}
		cout<<dp[k][s]<<endl;
	}
	return 0;
}

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

//   String nyuA=sc.nextLine();
  // String nyuB=sc.nextLine();
 
     String[] O=sc.nextLine().split(" ");
   //  String[] E=sc.nextLine().split("");

//int n=Integer.parseInt(nyuA);

int A=Integer.parseInt(O[0]);
int B=Integer.parseInt(O[1]);
int C=Integer.parseInt(O[2]);

int flag=0;
for(int i=A;i<=A*B;i+=A){
if(i%B==C){
flag=1;
break;
}
}
if(flag==1)
System.out.println("YES");
else
System.out.println("NO");

//long H=Long.parseLong(t[0]);
//long W=Long.parseLong(t[1]);
//long C=Long.parseLong(t[2]);


	}
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  	char s[4];
  	char x[2];
  	char y[2];
  	int cnt = 0;
  	int j = 0;

  	cin >> s;
  	x[0] = s[0];
  
  	for(int i = 1; i < 4; i++){
    	if(s[i] == x[0]){
        	cnt++;
        }else{
        	y[j] = s[i];
          	j++;
        }
    }
 
  	if(cnt == 1 && y[0] == y[1]){
    	cout << "Yes" << endl;
    }else{
    	cout << "No" << endl;
    }
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    int count = 1; //1番目の旅館は必ず海が見える
    int h[n];
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    bool flag = false;
    for(int i=1;i<n;i++){
        for(int j=0;j<i;j++){
            if(h[j] <= h[i]){
                flag = true;
            }
            else{
                flag = false;
                break;
            }
        }
        if(flag){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
// AOJ1611
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int solve(int n){
    vector<int> w(n+10);
    vector<vector<int>> dp(n+10,vector<int>(n+10,0));
    rep(i,n) cin>>w[i+1];
    //cout<<w<<endl;
    for(int i=1;i<=n-1;i++) if(abs(w[i]-w[i+1])<=1) dp[i][i+1]=2;
    for(int L=3;L<=n;L++){
        for(int i=1;i<=n-2;i++){
            int j=i+L-1;
            if(n<j) break;
            for(int k=i;k<=j-1;k++){
                dp[i][j]=max(dp[i][j],dp[i][k]+dp[k+1][j]);
                if(abs(w[i]-w[j])<=1 && dp[i+1][j-1]==L-2) dp[i][j]=L;
            }
        }
    }
    return dp[1][n];
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    
    int x;
    while(cin>>x){
        if(x==0) break;
        cout<<solve(x)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3400
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fs first
#define se second

#define debug(x) cout<<#x<<" = "<<(x)<<endl;

int main(){
  int N;cin>>N;
  map<string, int> list;

  string buf;
  int m = 0;
  for(int i=0; i<N; i++){
    cin>>buf;
    auto itr = list.find(buf);
    if(itr == list.end()){
      //初めての文字列
      //list.insert(mp(buf, 1));
      list[buf]=1;//これも等価
      m = max(m, 1);
    }else{
      itr->se += 1;
      m = max(m, itr->se);
    }
  }

  //debug(m);

  for(auto x: list){
    if(x.se==m){
      cout<<x.fs<<endl;
    }
  }
}

Measured memory_bytes: 25216
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) std::memset(arg,n,sizeof(arg))
#define mp std::make_pair
#define pb push_back
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::set<int> si;
typedef std::string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
ll N,A,B;
ll h[100010];
bool C(ll x){
  //条件を入れる
  ll y=A-B,z=B*x;
  ll cnt=0;
  rep(i,N){
    if(h[i]-z>0) cnt+=(h[i]-z-1)/y+1;
  }
  return cnt<=x;
}
ll upper(ll l,ll r){//条件を満たす中で最小のものを返す
  ll lb=l-1,ub=r+1;
  while(ub-lb>1){
    ll mid=(lb+ub)/2;
    if(C(mid)) ub=mid;
    else lb=mid;
  }
  return ub;
}
int main(){
  cin>>N>>A>>B;
  rep(i,N) cin>>h[i];
  ll max=0;
  rep(i,N) max=std::max(max,h[i]);
  prin(upper(1,(max-1)/B+1));
  return 0;
}


Measured memory_bytes: 1024
PROGRAM ATCODER

implicit none
integer(16) :: n,m,i,max=1000000,l,count=0,h,j,on,check=0
integer(16),allocatable :: k(:),s(:,:),p(:),sw(:)

read*, n,m
allocate(k(m),s(m,n),p(m),sw(n))
s = 0
do i = 1, m, 1
  read*, k(i),s(i,1:k(i))
end do
read*, p(1:m)

do i = 0, max, 1
  check = 0
  l = i
  sw = 0
  do j = 1, n, 1
    if ( l == 0 ) exit
    sw(j) = mod(l,2)
    l = l/2
  end do
  if ( minval(sw) == 0 .and. maxval(sw) == 0 .and. i /= 0 ) exit
  do j = 1, m, 1
    on = 0
    do h = 1, k(j), 1
      if ( sw(s(j,h)) == 1 ) then
        on = on + 1
      end if
    end do
    if ( mod(on,2) /= p(j) ) then
      check = 1
      exit
    end if
  end do
  if ( check == 0 ) then
    count = count + 1
  end if
end do

print'(i0)', count

END PROGRAM ATCODER

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

using namespace std;

#define WMAX 10005
#define NMAX 105
#define DIAGONAL 1
#define TOP 0


struct Item
{
    int value, weight;
};

Item items[NMAX];
int C[NMAX][WMAX], G[NMAX][WMAX];
int N, W;

int compute(){
    for (int i = 0; i <= W; ++i)
    {
        C[0][i] = 0;
    }

    for (int i = 0; i <= N; ++i)
    {
        C[i][0] = 0;
    }

    for (int i = 1; i <= N; ++i)
    {
        for (int j = 1; j <= W; ++j)
        {
            C[i][j] = C[i-1][j];
            if (j < items[i].weight) continue;//?????????<=??????????????????????????§??????????????????????????? 
            if (C[i-1][j-items[i].weight] + items[i].value > C[i-1][j]) {
                C[i][j] = C[i-1][j-items[i].weight] + items[i].value;
            }
        }
    }
    return C[N][W];
}

void input(){
    cin >> N >> W;
    for (int i = 0; i < N; ++i)
    {
        cin >> items[i+1].value >> items[i+1].weight;
    }
}

int main(){
    input();
    cout << compute() << endl;
}

Measured memory_bytes: 5260
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int k;
  cin >> n;
  cin >> k;
  vector<int> saikoro(n); 
  for(int i=0;i<n;i++){
    cin >> saikoro.at(i);
  }
  auto expectation = [](int x){
    int sum;
    sum =0;
    for(int i=1;i<=x;i++){
      sum+=i;
    }
    return sum/((double) x);
  };
  double init_sum;
  vector<double> kitaichi(n);
  for(int i=0;i<n;i++){
    kitaichi.at(i) = expectation(saikoro.at(i));
  }
  queue<double> q;
  double sum1;
  double max_sum;
  for(int i=0;i<n;i++){
    sum1 += kitaichi.at(i);
    q.push(kitaichi.at(i));
    if(q.size()>k){
      sum1 -= q.front();
      q.pop();
    }
    if(q.size()==k){
      max_sum = max(max_sum,sum1);
    }
  }
  printf("%.10f\n", max_sum);
}

Measured memory_bytes: 4224
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
using namespace std;


int main()
{

    int a[5],b[5],c=0,s=0;
    for(int i=0; i<5; i++)
        cin>>a[i];
    for(int i=0; i<5; i++)
        b[i]=a[i]%10;
    sort(b,b+5);
    for(int i=0; i<5; i++)
        if(b[i]!=0)
        {
            c=b[i];
            break;
        }
    for(int i=0; i<5; i++)
        if(a[i]%10!=0)
            s=s+(a[i]/10+1)*10;
        else
            s=s+a[i];
    if(c!=0)
        s=s-10+c;
    cout<<s<<endl;
    return 0;
}



Measured memory_bytes: 256
k = gets.chomp.to_i
a = 1
b = 1
c = 1
ary = Array.new().map{Array.new(3,0)}
for a in 1..k
    for b in 1..k
        for c in 1..k
            ary.push(a.gcd(b.gcd(c)))
        end
    end
end
print ary.inject(:+)

Measured memory_bytes: 76936
#include <bits/stdc++.h>
#define LL long long
using namespace std;

const int maxn = 1e5 + 10;
int n, a[maxn], pre[maxn], suf[maxn];

int main()
{
    scanf("%d", &n);
    a[1] = 0;
    for(int i = 2; i <= n + 1; i ++)
        scanf("%d", &a[i]);
    a[n + 2] = 0;

    for(int i = 1; i <= n + 2; i ++)
        pre[i] = pre[i - 1] + abs(a[i] - a[i - 1]);
    for(int i = n + 2;  i >= 1; i --)
        suf[i] = suf[i + 1] + abs(a[i] - a[i + 1]);

    for(int i = 2; i <= n + 1;i ++)
        printf("%d\n", pre[i - 1] + abs(a[i + 1] - a[i - 1]) + suf[i + 1]);

    return 0;
}


Measured memory_bytes: 2432
import java.util.*;
import java.awt.geom.Line2D;

class Main{
    int n;
    int xa,ya,xb,yb;
    int xs,ys,xt,yt,o,l;
    Line2D a,b;
    Intersection[] inter;

    class Intersection{
	double dist;
	int owner,height;
	public Intersection(double dist,int owner,int height){
	    this.dist = dist;
	    this.owner = owner;
	    this.height = height;
	}
    }

    void solve(){
	Scanner sc = new Scanner(System.in);
	int T = sc.nextInt();
	while(T--!=0){
	    xa = sc.nextInt(); ya = sc.nextInt();
	    xb = sc.nextInt(); yb = sc.nextInt();
	    n = sc.nextInt();

	    inter = new Intersection[n];
	    for(int i=0; i<n; i++){
		xs = sc.nextInt(); ys = sc.nextInt();
		xt = sc.nextInt(); yt = sc.nextInt();
		o = sc.nextInt(); l = sc.nextInt();
		a = new Line2D.Double(xa,ya,xb,yb);
		b = new Line2D.Double(xs,ys,xt,yt);
		if(a.intersectsLine(b)){
		    double d = calcDist(xa,ya,xb,yb,xs,ys,xt,yt);
		    inter[i] = new Intersection(d,o,l);
		}else{
		    inter[i] = new Intersection(-1,-1,-1);
		}
	    }

	    for(int i=0; i<n; i++){
		double minD = inter[i].dist;
		int minIndex = i;
		for(int j=i; j<n; j++){
		    if(inter[j].dist<minD){
			minD = inter[j].dist;
			minIndex = j;
		    }
		}
		Intersection tmp = inter[minIndex];
		inter[minIndex] = inter[i];
		inter[i] = tmp;
	    }

	    int ans = Math.min(countGate(0),countGate(1));

	    System.out.println(ans);
	}
    }

    double calcDist(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4){
	double bx = x4-x3;
	double by = y4-y3;
	double d1 = Math.abs(bx*(y1-y3)-by*(x1-x3));
	double d2 = Math.abs(bx*(y2-y3)-by*(x2-x3));
	double t = d1/(d1+d2);	
	double x = x1+(x2-x1)*t;
	double y = y1+(y2-y1)*t;

	return (xa-x)*(xa-x)+(ya-y)*(ya-y);
    }

    int countGate(int nowHeight){
	int count = 0;
	for(int i=0; i<n; i++){
	    if(inter[i].dist==-1)continue;
	    if(inter[i].owner==0){
		if(inter[i].height==nowHeight){
		    nowHeight = 1 - nowHeight;
		    count++;
		}
	    }else{
		if(inter[i].height!=nowHeight){
		    nowHeight = 1 - nowHeight;
		    count++;
		}
	    }
	}
	return count;
    }

    public static void main(String[] args){
	new Main().solve();
    }
}

Measured memory_bytes: 12000
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}


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

    
    int s[2],t[2];
    cin>>s[0]>>s[1]>>t[0]>>t[1];
    string ans = "";
    for(int i=0;i<t[0]-s[0];i++)ans+='R';
    for(int i=0;i<t[1]-s[1];i++)ans+='U';
    for(int i=0;i<t[0]-s[0];i++)ans+='L';
    for(int i=0;i<t[1]-s[1];i++)ans+='D';
    ans += 'D';
    for(int i=0;i<t[0]-s[0]+1;i++)ans+='R';
    for(int i=0;i<t[1]-s[1]+1;i++)ans+='U';
    ans+='L';
    ans+='U';
    for(int i=0;i<t[0]-s[0]+1;i++)ans+='L';
    for(int i=0;i<t[1]-s[1]+1;i++)ans+='D';
    ans+='R';
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <iomanip>

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

    std::vector<int> x(n), y(n);

    for (int i = 0; i < n; i++) {
        std::cin >> x[i];
    }

    for (int i = 0; i < n; i++) {
        std::cin >> y[i];
    }

    double p1, p2, p3, pinf;

    p1 = p2 = p3 = pinf = 0;

    for (int i = 0; i < n; i++) {
        p1 += std::abs(x[i] - y[i]);
    }

    for (int i = 0; i < n; i++) {
        p2 += std::abs(x[i] - y[i]) * std::abs(x[i] - y[i]);
    }
    p2 = std::sqrt(p2);

    for (int i = 0; i < n; i++) {
        p3 += std::abs(x[i] - y[i]) * std::abs(x[i] - y[i]) * std::abs(x[i] - y[i]);
    }

    double low = 0, high = 100000000000;
    for (int i = 0; i < 1000; i++) {
        double mid = (low + high) / 2;
        if (mid * mid * mid <= p3) {
            low = mid;
        } else {
            high = mid;
        }
    }

    p3 = low;

    for (int i = 0; i < n; i++) {
        pinf = std::max(pinf, std::abs(1.0 * x[i] - y[i]));
    }

    std::cout << std::fixed << std::setprecision(10);
    std::cout << p1 << std::endl << p2 << std::endl << p3 << std::endl << pinf << std::endl;

    return 0;
}

Measured memory_bytes: 3272
#include <stdio.h>

int main(void) {
  long n;
  int data[30] = {0};
  int count = 0;
  scanf("%ld", &n);
  while(n > 0) {
    long x = n - 1;
    data[count++] = (x % 26) + 'a';
    n = x / 26;
  }
  for(int i = count - 1;i >= 0;i--) {
    printf("%c", data[i]);
  }
  puts("");
  return 0;
}


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

N,M,K=list(map(int,input().split()))
for iN in range(N+1):
    for iM in range(M+1):
        tmp = (N-iN)*(iM)+(iN)*(M-iM)
        if tmp == K:
            print('Yes')
            exit()
print('No')


Measured memory_bytes: 9172
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int>v(n);
  rep(i,n)cin >> v[i];
  bool can = false;
  int now = 1;
  rep(i,n){
    if(now == v[i]){
      now++;
      can = true;
    }
  }
  if(can){
    cout << n - now + 1<< endl;
  }
  else{
    cout << -1 << endl;
  }
  return 0;
}

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

//def
#define debug(x) cout << #x << ": " << x << '\n'
#define out(x) cout << x << '\n'
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

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

    int n;
    cin >> n;
    int lb = ceil(n / 1.08);
    int ub = floor((n + 1) / 1.08 - 0.0000001);

    vi ans;

    repeat(i, lb, ub + 1)
        ans.push_back(i);

    if (ans.empty()) {
        out(":(");
    } else {
        out(ans[0]);
    }
}


Measured memory_bytes: 256
macro_rules! read {
    () => {{
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf
    }};
    ( Vec<$t:ty> ) => {
        read!()
            .trim()
            .split_whitespace()
            .map(|x| x.parse::<$t>().unwrap())
            .collect::<Vec<_>>()
    };
    ( $( $t:ty ),* ) => {{
        let buf = read!();
        let mut iter = buf.split_whitespace().collect::<Vec<_>>().into_iter();
        ( $( iter.next().unwrap().parse::<$t>().unwrap() ),* )
    }};
}

fn main() {
    println!(
        "{}on",
        match read!(u16) % 10 {
            0 | 1 | 6 | 8 => "p",
            3 => "b",
            _ => "h",
        }
    )
}


Measured memory_bytes: 2124
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;
//vector<vector<int>> vec(縦,vector<int>(横));
/*deque<型> 配列の先頭にも用がある時はvectorの代わりに。
入力はstringでもらってからpush_back()*/

int main(){
  vector<int> vec;
    vec={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin>>K;
  
  cout<<vec.at(K-1)<<endl;
}

  
  

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

using namespace std;

int main() {
    int n;
    cin >> n;
    n = n % 10;
    if (n == 3) {
        cout << "bon\n";
    } else if (n == 0 || n == 1 || n == 6  || n == 8) {
        cout << "pon\n";
    } else {
        cout << "hon\n";
    }
    return 0;
}


Measured memory_bytes: 3584
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<cmath>
#include <bits/stdc++.h>
using namespace std;

int main(){
	int A,B,H,M;
	cin>>A>>B>>H>>M;
	double ang = abs(30*H*1.0+M/2.0 - 1.0*6*M)*1.0;
	//if(ang > 180)ang-=180;
	long double ans = sqrt(1.0*A*A+1.0*B*B-1.0*(2*A*B*cos(ang*M_PI/180.0)));
	cout << fixed << setprecision(100);
	cout<<ans<<endl;
	
	
	
}

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

int dp[300001];
int ar[300001];
int j,k,l,m,n;


int solve(int x)
{

    if(x == 0)return 0;

    if(dp[x] != -1)return dp[x];

    int ans = 0;
    for(int i=0;i<n;i++)
    {
        if(ar[i] > x)continue;

        if(solve(x-ar[i]) == 0)
        {
            ans = 1;
           // break;

        }
    }
    return dp[x] = ans;
}

int main()
{
    cin >> n >> k;
memset(dp,-1,sizeof dp);

    for(int i=0;i<n;i++)cin >> ar[i];

    if(solve(k))cout<<"First"<<endl;
    else cout << "Second" << endl;
}


Measured memory_bytes: 6144
A = int(input())
B = int(input())
C = int(input())
X = int(input())

cand = [(i, j, k) for i in range(A+1) for j in range(B+1) for k in range(C+1)]
count = 0

for c in cand:
    if 500*c[0] + 100*c[1] + 50*c[2] == X:
        count += 1
        
print(count)

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

using namespace std;

int main()
{
    double D,T,V,t;
    cin>>D>>T>>V;
    t=D/V;
    if(t<=T){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
   
    return 0;
}


Measured memory_bytes: 3708
program main
	implicit none
    character(5*10**5)::s
    integer(8)::i,n,ans
    integer(8),allocatable::a(:),b(:),c(:)
    read(*,*)s
    n=len_trim(s)
    allocate(a(n+1))
    allocate(b(n+1))
    allocate(c(n+1))
    a=0
    b=0
    c=0
    do i=1,n
    	if(s(i:i)=='<')then
        	a(i+1)=a(i)+1
        end if
    end do
    
    do i=n,1,-1
    	if(s(i:i)=='>')then
        	b(i)=b(i+1)+1
        end if
    end do
    ans=0
    !do i=1,n+1
    !	c(i)=max(a(i:i),b(i:i))
    !end do
    c=max(a,b)
    write(*,*) sum(c)
    deallocate(a)
    deallocate(b)
    deallocate(c)
    stop
end program main

    
    

Measured memory_bytes: 13024
# N, D = [int(i) for i in input().split()]
K = int(input())
if K % 7 == 0:
  K = K // 7
K = 9 * K
remain = 1
for i in range(10**6):
  remain = (remain*10) % K
  if remain == 1:
    print(i+1)
    break
else:
  print(-1)


Measured memory_bytes: 62908
#include <stdio.h>
#include <stdlib.h>

#define rep(i, n) for (int i = 0; i < n; i = i + 1)
#define array(N, t) (t*)calloc(N, sizeof(t))
#define ll long long
#define INF ((1LL << 62) - (1LL << 31))
#define max(p, q)((p) > (q) ? (p) : (q))
#define min(p, q)((p) < (q) ? (p) : (q))

const int MOD = 1000000007;
int N;
int * A;

int solve() {
  int ans = 0;
  int x = 0;

  rep(i, N) {
    ans = (ans + (ll)A[i] * x) % MOD;
    x = (x + A[i]) % MOD;
  }

  return ans;
}

int main() {
  scanf("%d", &N);
  A = array(N, int);
  rep(i, N) scanf("%d", A + i);

  printf("%d\n", solve());

  free(A);
  return 0;
}


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

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

# (nxt, cnt)
D = {
    0: (0, 1),
    1: (2, 1),
    2: (4, 1),
    3: (6, 1),
    4: (8, 1),
    5: (1, 2),
    6: (3, 2),
    7: (5, 2),
    8: (7, 2),
    9: (9, 2),
}

M = INT()
C = Counter()
for i in range(M):
    d, c = MAP()
    C[d] += c

def calc(a, cnt):
    sm = 0
    odd = []
    while cnt > 1:
        if cnt % 2 == 1:
            odd.append(a)
            cnt -= 1
        cnt //= 2
        sm += cnt * D[a][1]
        a = D[a][0]
    for b in odd:
        a += b
        sm += 1
        if a >= 10:
            a = int(str(a)[0]) + int(str(a)[1])
            sm += 1
    return (a, sm)

ans = 0
A = []
for k, v in C.items():
    a, sm = calc(k, v)
    ans += sm
    A.append(a)

for i in range(1, len(A)):
    A[i] += A[i-1]
    ans += 1
    if A[i] >= 10:
        A[i] = int(str(A[i])[0]) + int(str(A[i])[1])
        ans += 1
print(ans)


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

class Stack{
private:
	int sp;
	int S[100];
public:
	Stack()					{sp=0;}
	bool isFull()   const	{return(sp==100);}
	bool isEmpty()	const	{return(sp==0);}
	void push(int d);
	int top();
	void pop();
};
void Stack::push(int d){
	if(isFull()){return;}
	S[sp++]=d;
}
int Stack::top(){
	if(isEmpty()){return -1;}
	return S[sp-1];
}
void Stack::pop(){
	if(isEmpty()){return;}
	sp--;
}

int main(){
	Stack s;
	string expr;
	getline(cin,expr);
	istringstream is(expr);
	while(!is.eof()){
		string op;
		is>>op;
		int tmp1,tmp2;
		switch (op[0]){
		case '+':
			tmp1=s.top();s.pop();
			tmp2=s.top();s.pop();
			s.push(tmp2+tmp1);
			break;
		case '-':
			tmp1=s.top();s.pop();
			tmp2=s.top();s.pop();
			s.push(tmp2-tmp1);
			break;
		case '*':
			tmp1=s.top();s.pop();
			tmp2=s.top();s.pop();
			s.push(tmp2*tmp1);
			break;
		default:
			istringstream is2(op);
			is2>>tmp1;
			s.push(tmp1);
			break;
		}
	}
	cout<<s.top()<<endl;
	return 0;
}


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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;

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

	int n;cin>>n;
	string s;cin>>s;


	for(int i=0; i<s.length(); i++){
		int tmp = (int)s[i]+n;

		if(tmp>90)tmp-=26;

		cout<<(char)tmp;
	}
	cout<<endl;

}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll gcd(ll a,ll b)
{
	return b==0?a:gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
	return a*b/gcd(a,b);
}
ll a[100006];
int main(){
    ll n,m;
    scanf("%lld%lld",&n,&m);
    int lcm1=1;
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        if(lcm1>m){
            continue;
        }
        lcm1=lcm(lcm1,a[i]/2);
    }
    if(lcm1>m){cout<<0<<'\n';return 0;}
    int flag=0;
    for(int i=1;i<=n;i++){
        int temp=lcm1*2/a[i];
        if(temp%2==0){
            flag=1;
            break;
        }
    }
    if(flag){
        puts("0");
        return 0;
    }
    int cnt=m/lcm1;
    if(cnt&1){
        cnt=cnt/2+1;
    }
    else{
        cnt=cnt/2;
    }
    printf("%lld\n",cnt);
    return 0;
}

Measured memory_bytes: 4620
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 210000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
// long long C(int a,int b){
// 	if(a<b||b<0)return 0;
// 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
// }
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ
char in[20][20];
int ans;
int H,W;
int p[110][2];
int q[110][2];
int can[20][20];
void dfs2(int a,int b){
	if(a==W){
		ans=1;
		return;	
	}
	for(int i=0;i<b;i++){
		if(~q[i][1])continue;
		q[i][1]=a;
		if(can[q[i][0]][a])dfs2(a+1,b);
		if(ans)return;
		q[i][1]=-1;
	}
	if(b*2<W){
		q[b][0]=a;
		dfs2(a+1,b+1);
		q[b][0]=-1;
	}
}
void solve(){
	for(int i=0;i<W;i++)for(int j=i+1;j<W;j++){
		can[i][j]=1;
		for(int k=0;k<(H+1)/2;k++){
			if(p[k][1]==-1)continue;
			bool ok=true;
			if(in[p[k][0]][i]!=in[p[k][1]][j]||in[p[k][1]][i]!=in[p[k][0]][j])can[i][j]=0;
		}
		can[j][i]=can[i][j];
	}
	dfs2(0,0);
}
void dfs(int a,int b){
	if(a==H){
		solve();
		return;	
	}
	for(int i=0;i<b;i++){
		if(~p[i][1])continue;
		p[i][1]=a;
		dfs(a+1,b);
		if(ans)return;
		p[i][1]=-1;
	}
	if(b*2<H){
		p[b][0]=a;
		dfs(a+1,b+1);
		p[b][0]=-1;
	}
}
int main(){
	int a,b;scanf("%d%d",&a,&b);H=a;W=b;
	for(int i=0;i<a;i++)scanf("%s",in[i]);
	for(int i=0;i<12;i++)for(int j=0;j<2;j++)p[i][j]=q[i][j]=-1;
	dfs(0,0);
	if(ans)printf("YES\n");
	else printf("NO\n");
}

Measured memory_bytes: 128
s = input()
x, y = map(int, input().split())
n = len(s)
S = [[], []]
d = 0
f = 0
for i in range(n):
  if s[i] == 'T':
    if f != 0:
      S[d].append(f)
    d += 1
    d %= 2
    f = 0
  elif s[i] == 'F':
    f += 1
if s[n-1] == 'F':
  S[d].append(f)
if S[0] == []:
  S[0].append(0)
if S[1] == []:
  S[1].append(0)
px, py = 0, 0
if s[0] == 'F':
  px += S[0][0]
  S[0] = S[0][1:]
for i in range(len(S[0])):
  px -= S[0][i]
  S[0][i] *= 2
for i in range(len(S[1])):
  py -= S[1][i]
  S[1][i] *= 2
mpx, mpy = x - px, y - py
X = S[0][:]
Y = S[1][:]
Dx = {0: 1}
Dy = {0: 1}
for i in X:
  L = [i for i in Dx]
  for j in L:
    if i + j <= mpx and i + j not in Dx:
      Dx[i+j] = 1
for i in Y:
  L = [i for i in Dy]
  for j in L:
    if i + j <= mpy and i + j not in Dy:
      Dy[i+j] = 1

if mpx in Dx and mpy in Dy:
  print("Yes")
else:
  print("No")

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

N = int(input())
L = [int(v) for v in input().split()]
m = [set() for _ in range(N)]

t = N - 1
for i in range(N):
    v = L[i]
    e = (t + v) // 2
    s = t - e
    
    m[s].add(i)
    m[e].add(i)
    
l = set()
for v in m:
    if len(v) == 0:
        print("0")
        exit()
    elif len(v) == 1:
        v = list(v)
        if v[0] in l:
            print("0")
            exit()
        
        l.add(v[0])
        
c = (N - len(l)) // 2
print(2 ** c % (10 ** 9 + 7))

Measured memory_bytes: 34024
#include <iostream>
#include <cmath>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <map>
#include <list>
#include <stack>
#define lar(a, b) ((a>b) ? (a):(b))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;

int main(void) {
    vector<p> cnt;
    p pir;
    pir = make_pair(-1, 0);
    cnt.push_back(pir);
    
    ll n, i, tmp, atmp, ans=1, tmpc=0;
    cin >> n;
    ll a[n];
    for(i=0; i<n; i++)
        cin >> a[i];
    sort(a, a+n);
    
    for(i=0; i<n; i++) {
        tmp=1;
        atmp=a[i];
        while(a[i]==a[i+1]) {
            tmp++;
            i++;
        }
        pir = make_pair(atmp, tmp);
        cnt.push_back(pir);
    }
    
    pir = make_pair(-1, 0);
    cnt.push_back(pir);
    
    for(i=cnt.size()-2; i>=1; i--) {
        if(tmpc==0 && cnt[i].second>=4) {
            cout << cnt[i].first*cnt[i].first << endl;
            return 0;
        }else if(tmpc==0 && cnt[i].second>=2) {
            ans *= cnt[i].first;
            tmpc++;
            continue;
        }
        if(tmpc==1 && cnt[i].second>=2) {
            ans *= cnt[i].first;
            cout << ans << endl;
            return 0;
        }
    }
    cout << 0 << endl;
}


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

int main(void){
    int N,D,X;
    cin>>N>>D>>X;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    for(int i=0;i<N;i++){
        X+=((D-1)/A[i]);
    }
    X+=N;
    cout<<X<<endl;
    return 0;
}



Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int k = saori.saori_hayami();
		long ans = k;
		for(int i = 0;i < n-1;i++){
			ans = ans * (k-1);
		}
		System.out.println(ans);
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 19284
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <ctime>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <queue>
#include <utility>
#include <cmath>
#include <functional>
#include <map>
#include <set>
const long INF = 1000000009;

long k;
long a[100001];
const long MAX_K = 100000;

int main(){
	scanf("%ld", &k);
	for(long i = 0; i < k; i++){
		scanf("%ld", &a[i]);
	}
	/*
	if(2 % a[k-1] != 0){
		printf("-1\n");
		return 0;
	}
	//*/
	long b[2][100001];
	b[0][k] = 2;//max
	b[1][k] = 2;//min
	for(long i = k-1; i >= 0; i--){
		b[0][i] = (b[0][i+1] / a[i] + 1) * a[i] - 1;
		b[1][i] = ((b[1][i+1] - 1) / a[i] + 1) * a[i];
		//b[1][i] = (b[1][i+1] + a[i] - 1) / a[i] * a[i];
		if(b[0][i] < b[1][i]){
			//printf("break\n");
			printf("-1\n");
			return 0;
		}
	}
	printf("%ld %ld\n", b[1][0], b[0][0]);
	return 0;
}

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

int main(){
    int N;cin>>N;
    ll a[N];
    for(int i=0;i<N;i++)cin>>a[i];
    sort(a,a+N);
    ll b[N];
    b[0]=a[0];
    for(int i=1;i<N;i++)b[i]=a[i]+b[i-1];
    int ans=N;
    for(int i=N-1;i>=1;i--){
        if(b[i-1]*2<a[i]){
            ans=N-i;
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
using System;
using System.Linq;

namespace Candles
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = GetArrayIntInput();
            var inputs = GetArrayIntInput();

            int result = int.MaxValue;
            for (int i = 0; i <= nk[0] - nk[1]; i++)
            {
                var range = inputs[i + nk[1] - 1] - inputs[i];
                var tmpResult = Math.Min(range + Math.Abs(inputs[i]), range + Math.Abs(inputs[i + nk[1] - 1]));
                result = Math.Min(result, tmpResult);
            }
            CWrite(result);
        }

        static string[] GetArrayCharInput() => Console.ReadLine().Split();
        static int[] GetArrayIntInput() => Console.ReadLine().StringToIntArray();
        static int GetIntInput() => Console.ReadLine().ToInt();
        static void CWrite<T>(T str) => Console.WriteLine(str);
    }

    static class ExtentionsLibrary
    {
            public static int[] StringToIntArray(this string str) =>
            str.Split().Select(int.Parse).ToArray();
        public static int ToInt(this string str) => int.Parse(str);
    }
}


Measured memory_bytes: 21728
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const int mod=1000000007;
  i64 poww(i64 a, i64 b)
  {
    a%=mod;
    i64 res=1;
    while(b)
      {
if(b&1)res=res*a%mod;

      a=a*a%mod;
      b/=2;

      }
      return res;
  }
  i64 inv(i64 a)
  {
    return poww(a,mod-2);
  }


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

    // ifstream fin(".in");
    // ofstream fout(".in");


i64 sum=0,n;
cin>>n;
vi64 v(n);
forn(i,n)
{
  cin>>v[i];
  sum^=v[i];
}

forn(i,n)
cout<<(sum^v[i])<<" ";




    return 0;
  }


Measured memory_bytes: 4676