akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
int n, k;
ll dp[2010][2010];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    for (int i = 0; i <= n + 1; i++)
    {
        dp[i][0] = 1;
        dp[i][i] = 1;
    }
    for (int i = 0; i <= n + 1; i++)
    {
        for (int j = 1; j < i; j++)
        {
            dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1];
            dp[i][j] %= MOD;
        }
    }
    for (int i = 1; i <= k; i++)
    {
        cout << dp[k - 1][i - 1] * dp[n - k + 1][i] % MOD << "\n";
    }
}


Measured memory_bytes: 30208
# 2019-11-12 22:11:12(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    n, m, c = [int(x) for x in sys.stdin.readline().split()]
    b = [int(x) for x in sys.stdin.readline().split()]
    a = [[int(x) for x in sys.stdin.readline().split()] for _ in range(n)]

    count = 0
    for i in range(n):
        s = c
        for j in range(m):
            s += b[j] * a[i][j]
        if s > 0:
            count += 1
    print(count)

if __name__ == "__main__":
    main()


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

int main(void){
long long int x,k,d;
 
    scanf("%lld %lld %lld",&x,&k,&d);
    x=labs(x);
long long int ans;
if(x>k*d){
    //printf("0\n");
    if(10000000000000000/k<d){
    long long int idou  = x/d;
    long long int nokori = x%d;
    
    if((k-idou)%2==1){
        //printf("1 %lld %lld \n",nokori,d);
        ans=d-nokori;
    }else{
        //printf("2 %lld %lld \n",nokori,d);
        ans=nokori;
    }
    }else{
     ans=x-(k*d);
    }
}else{
    long long int idou  = x/d;
    long long int nokori = x%d;
    
    if((k-idou)%2==1){
        //printf("1 %lld %lld \n",nokori,d);
        ans=d-nokori;
    }else{
        //printf("2 %lld %lld \n",nokori,d);
        ans=nokori;
    }
}
ans=labs(ans);
 printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 1728
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }
};

int main() {
    int N, M;
    cin >> N >> M;

    UnionFind tree(N);

    for(int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        tree.unite(x, y); // xの木とyの木を併合する
    }
    map<int, int> mp;
    for(int i = 0; i < N; i++){
        int a = tree.root(i);
        mp[a]++;
    }
    int ans = 0;
    for(int i = 0; i < N; i++){
      if(mp[i]>=1)ans++;
    }
    cout << ans - 1 << endl;
    return 0;
}

Measured memory_bytes: 8284
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int64_t get_int(void) {
  int64_t num;
  scanf("%lld", &num);
  return num;
}

int get_str(char *str, int size)
{
    char format[100];
    if (size == 0)
        return 0;
    snprintf(format, sizeof(format), "%%%ds", size);
    scanf(format, str);
    return 0;
}

#define STR_MAX 100
#define BUF_MAX (STR_MAX+10)
int main(void) {
    static char str[BUF_MAX];
    get_str(str, BUF_MAX);
    int len = strlen(str);
    int64_t pos = get_int();
    // 0-indexed
    pos--;

    int i;
    for(i = 0; i < len; i++) {
        if(str[i]!='1') break;
    }

    if(i > pos) {
        putchar(str[pos]);
    } else {
        putchar(str[i]);
    }
    putchar('\n');
    return 0;
}

Measured memory_bytes: 128
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>



using namespace std;

vector<int> genGauss()
{
	vector<int> ans;
	ans.resize(999);
	ans[0] = 1;
	for (int i = 1; i < 999; i++)
	{
		ans[i] = ans[i - 1] + i + 1;
	}
	return ans;
}

int main()
{
	int A, B;
	cin >> A >> B;
	vector<int> gauss = genGauss();
	for (int i =0; i < 998;i++)
	{
		if (gauss[i] < A)
		{
			continue;
		}
		else
		{
			int depth = gauss[i] - A;
			if (gauss[i + 1] - B == depth)
			{
				cout << depth << "\n";
				return 0;
			}
		}
	}

}


Measured memory_bytes: 256
from collections import deque

def bfs(x):
  for v in graph[x]:
    if dist[v] != -1:
      continue
    dist[v] = dist[x] + 1
    queue.append(v)
  if len(queue) == 0:
    return
  bfs(queue.popleft())
  
N = int(input())
graph = []
for _ in range(N):
  graph.append(list(map(lambda x: int(x)-1, input().split()))[2:])
dist = [-1] * N
queue = deque()

dist[0] = 0
bfs(0)
for i in range(N):
  print("{} {}".format(i+1, dist[i]))


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

using namespace std;

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

    for (int i = 1; i <= 5000000; ++i) {
        double y = i * 1.08;
        if((int)y == n) return cout << i << "\n", 0;
    }
    cout << ":(\n";
    return 0;
}


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

int main(){
    std::string str;
    std::cin >> str;

    std::vector<int> s(4, 0);
    for(int i = 0; i < 4; ++i){
        s.at(i) = str.at(i) - 48;
    }

    std::string ops(3, '#');
    int i = 0;
    while(i < 8){
        int result = s.at(0);
        std::bitset<3> bs(i);
        for(int j = 0; j < 3; ++j){
            if(bs[2 - j]){
                result += s.at(j + 1);
                ops.at(j) = '+';
            }else{
                result -= s.at(j + 1);
                ops.at(j) = '-';
            }
        } 

        if(7 == result){
            break;
        }

        ++i;
    }

    std::cout << str.at(0);

    for(int i = 0; i < 3; ++i){
        std::cout << ops.at(i) << str.at(i + 1);
    }

    std::cout << "=7" << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <queue>
#include <stack>
using namespace std; 
typedef pair<long long int,long long int> pa;
#define resize(A) A.resize(unique(A.begin(), A.end()) - A.begin())
#define pb push_back
#define  MAX 1000005
long long int MOD=1e9+7;
long long int INF=1e18;
                                                 /*:-]*/
long long  int modulo(long long int a,long long  int b,long long  int n)
{
    long long int  x=1, y=a; 
    while (b > 0) 
    {
        if (b%2 == 1) 
        {
              x = (x*y) % n;
        }
        y = (y*y) % n; 
        
        b /= 2;
    }
    return x % n;
}


int main()
{
         ios_base::sync_with_stdio(false); 
         cin.tie(NULL);
         cout.tie(NULL);
         long long int i,j,k=0,l=0,r=0,m=0,n,c,p=0,cnt=0,cnt1=0,x,y,z=0,a,b,low,mid,high,ans=0,maxi=0,mini=INF,t,x1,y1;
         string s;
    cin>>n;
    maxi=n;
    for(i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            p=i-1+n/i-1;
            maxi=min(maxi,p);
        }
    }
    cout<<maxi<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <iomanip>
#include <assert.h>
using namespace std;
#define int long long

signed main() {
	
	int A, B;
	cin >> A >> B;
	if (A < 10 && B < 10) {
		cout << A * B << endl;
	}
	else {
		cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>

constexpr intmax_t  operator ""_jd(unsigned long long n) { return n; }
constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; }
constexpr size_t    operator ""_zu(unsigned long long n) { return n; }
// constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; }

int main() {
  size_t n, k;
  scanf("%zu %zu", &n, &k);

  std::vector<intmax_t> a(n);
  for (auto& ai: a) scanf("%jd", &ai);

  std::vector<intmax_t> cand;
  cand.reserve(n*(n+1)/2);

  for (size_t i = 0; i < n; ++i) {
    intmax_t acc = a[i];
    cand.push_back(acc);
    for (size_t j = i+1; j < n; ++j) {
      acc += a[j];
      cand.push_back(acc);
    }
  }

  intmax_t res = 0;
  for (int j = 62; j >= 0; --j) {

    std::vector<intmax_t> set, unset;
    for (auto ai: cand) {
      ((ai >> j & 1)? set: unset).push_back(ai & (~(1_ju << j)));
    }
    if (set.size() < k) continue;
    res |= 1_jd << j;
    std::sort(set.begin(), set.end());
    cand = std::move(set);
  }

  printf("%jd\n", res);
}


Measured memory_bytes: 13628
N = int(input())
S = sorted([int(input()) for n in range(N)])
S1 = []
S2 = []

for s in S:
  if s%10 ==0:
    S1.append(s)
  else:
    S2.append(s)
    
if sum(S)%10!=0:
  print(sum(S))
else:
  if len(S2)>0:
    print(sum(S)-S2[0])
  else:
    print(0)

Measured memory_bytes: 9196
N, X = map(int, input().split())
L = list(map(int, input().split()))
d = 0
if L[0] > X:
    print(0)
for i in range(1, N + 1):
    d += L[i - 1]
    if d > X:
        print(i)
        exit()
print(N + 1)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n), A(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    
    copy(a.begin(), a.end(), A.begin());
    sort(A.begin(), A.end());

    int cnt = 0;
    for(int i = 0; i < n; i += 2){
        int id = lower_bound(A.begin(), A.end(), a[i]) - A.begin();
        
        if(id % 2 != 0)     ++cnt;
    }
    
    cout << cnt << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

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

typedef long long lint;

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<lint>prime;
	int x;
	cin>>x;
	lint num=1;
	while(num++){
		if(num==2){
			prime.push_back(2);
			if(x<=2){
				cout<<2<<endl;
				break;
			}
		}else{
			bool isprime=true;
			each(it,prime)if(!(num%(*it))){isprime=false;break;}
			if(!isprime)continue;
			prime.push_back(num);
			if(x<=num){
				cout<<num<<endl;
				break;
			}
		}
	}
}

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

int main(int argc, char const *argv[]) {
    int N;
    std::cin >> N;

    std::vector<int> house_positions;
    for(int times = 0 ; times < N ; times++ )
    {
        int house_position;
        std::cin >> house_position;
        house_positions.push_back(house_position);
    }

    auto max_distance_house = std::max_element(house_positions.begin(),house_positions.end());
    auto min_distance_house = std::min_element(house_positions.begin(),house_positions.end());

    std::cout << *max_distance_house - *min_distance_house << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const ll MOD = 1e9 + 7;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

int main() {
    ll n,x, ans = 0; cin >> n >> x;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    for(int i = 0; i < n-1; i ++){
        if(a[i+1]+a[i] > x){
            if(a[i+1]+a[i]-x <= a[i+1]){
                ans += (a[i+1]+a[i]-x);
                a[i+1] -= (a[i+1]+a[i]-x);
            }else{
                ans += (a[i+1]+a[i]-x);
                a[i+1] = 0;
            }
        }
    }

    cout << ans;

}


Measured memory_bytes: 4048
#include<iostream>
#include<string>
#include<math.h>
using namespace std;
int main(){
  string s;
  int i, x, y;
  cin >> s;
  x=atoi(s.substr(0, 3).c_str());
  for(i=0; i<s.size()-2; i++){
    y=atoi(s.substr(i, 3).c_str());
    if(abs(753-x)>abs(753-y))
      x=y;
  }
  cout << abs(753-x);
return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>

using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
inline int x(int c,int d){return c^d;}

int a[200000],n,b;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n;
    REP(i,n)cin>>a[i];
    REP(i,n)b=x(a[i],b);
    REP(i,n)cout<<(a[i]^b)<<"\n";
    return 0;
}

Measured memory_bytes: 4396
public class
Main
{
  private static final int N = 999999; 

  public static void
  main (
    String[ ] args
    )
  {
    java.util.Scanner sc = new java.util.Scanner ( System.in );
    int[ ] p = new int[ N + 1 ];
    int i, j;
    
    for ( i = 2; i * i <= N; ++i )
    {
      if ( p[ i ] == 1 ) continue ;
      for ( j = i * 2; j <= N; j += i )
        p[ j ] = 1;
    }
    for ( i = 2; i <= N; ++i )
      p[ i ] = p[ i - 1 ] + ( p[ i ] == 0 ? 1 : 0);
    
    while ( sc.hasNextInt ( ) )
    {
      int n;
      
      n = sc.nextInt ( );
      System.out.println ( p[ n ] );
    }
    
    return ;
  }
}

Measured memory_bytes: 25288
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int K;
    cin >> K;
    int ans = 1;
    ll power = 1;
    ll cur = 0;
    while (1) {
        cur += power * 7 % K;
        cur %= K;
        if (cur % K == 0) {
            cout << ans << '\n';
            return 0;
        }
        if (ans >= 10000000) break;
        power *= 10; power %= K;
        ans++;
    }
    cout << -1 << '\n';
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define N 100010
#define M 1010

using namespace std;


int read() {
	int s = 0, f = 0; char ch = getchar();
	while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
	while (isdigit(ch)) s = s * 10 + (ch ^ 48), ch = getchar();
	return f ? -s : s;
}

int main() {
	int a = read();
	cout << a + a * a + a * a * a;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)

using namespace std;

static const int N = 100;
static const int white = 0;
static const int gray = 1;
static const int black = 2;

int n, M[N][N], color[N], d[N], f[N], tt;

void dfs_visit(int u) {
  color[u] = gray;
  d[u] = ++tt;
  REP(v, n) {
    if ( M[u][v] == 0) continue;
    if ( color[v] == white ) {
      dfs_visit(v);
    }
  }
  color[u] = black;
  f[u] = ++tt;
}

void dfs() {
  REP(u, n) color[u] = white;
  tt = 0;

  REP(u, n) {
    if ( color[u] == white ) dfs_visit(u);
  }
  REP(u, n) {
    cout << u + 1 << " " << d[u] << " " << f[u] << endl;
  }
}

int main() {
  int u, v, k;

  cin >> n;
  REP(i, n) {
    REP(j, n) {
      M[i][j] = 0;
    }
  }

  REP(i, n) {
    cin >> u >> k;
    u--;
    REP(j, k) {
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }

  dfs();

  return 0;
} 

Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
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; }

char maze[1010][1010];
int H,W;
int sx,sy;
int gx,gy;
int d[1010][1010];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int bfs(){
    queue<pair<int,int>> que;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            d[i][j]=INF;
        }
    }
    que.push(make_pair(sx,sy));
    d[sx][sy]=0;
    while(!que.empty()){
        pair<int,int> p=que.front();
        que.pop();
        if(p.first==gx && p.second==gy) break;
        for(int i=0;i<4;i++){
            int nx=p.first+dx[i];
            int ny=p.second+dy[i];
            if(0<=nx && nx<H && 0<=ny && ny<W && maze[nx][ny]!='#' && d[nx][ny]==INF){
                que.push(make_pair(nx,ny));
                d[nx][ny]=d[p.first][p.second]+1;
            }
        }
    }
    return d[gx][gy];
}

int main(){
    cin>>H>>W;
    queue<pair<int,int>> q;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            d[i][j]=INF;
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>maze[i][j];
            if(maze[i][j]=='#'){
                d[i][j]=0;
                q.push(make_pair(i,j));
            }
        }
    }
    while(!q.empty()){
        auto p=q.front();
        q.pop();
        for(int i=0;i<4;i++){
            int nx=p.first+dx[i];
            int ny=p.second+dy[i];
            if(0<=nx && nx<H && 0<=ny && ny<W && d[nx][ny]==INF){
                d[nx][ny]=d[p.first][p.second]+1;
                q.push(make_pair(nx,ny));
            }
        }
    }
    int ans=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            chmax(ans,d[i][j]);
        }
    }
    cout<<ans<<endl;
}

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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(ll i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(){
    ll n; cin >> n;
    ll tsum = 0;
    REP(i, 1, n+1){
        tsum += i * (n+1 - i);
    }
    REP(i, 0, n-1){
        ll a, b; cin >> a >> b;
        if(a > b){
            ll x = a; a = b; b = x;
        }
        tsum -= a * (n-b+1);
    }
    cout << tsum << endl;
}

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

using namespace std;

int main()
{
  int n, x[100], y[100];
  double d1 = 0, d2 = 0, d3 = 0, d8 = 0;

  cin >> n;

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

  for ( int i = 0; i < n; i++ )
    {
      double d = abs( x[i] - y[i] );
      d1 += d;
      d2 += d * d;
      d3 += d * d * d;
      d8 = max( d8, d );
    }

  d2 = sqrt( d2 );
  d3 = pow( d3, 1.0/3.0 );
  
  cout << fixed << setprecision(6) << d1 << endl;
  cout << fixed << setprecision(6) << d2 << endl;
  cout << fixed << setprecision(6) << d3 << endl;
  cout << fixed << setprecision(6) << d8 << endl;
  
  return 0;
}

Measured memory_bytes: 1276
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static long solve[][] = new long[101][100001];
    public static int weights[] = new int[100];
    public static int value[] = new int[100];
    public static long n,w;
    public static void main(String args[])throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String nw[]=br.readLine().split(" ");
        n=Long.parseLong(nw[0]);
        w=Long.parseLong(nw[1]);
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<=w;j++)
                solve[i][j]=-1;
        }
        for(int j=0;j<=w;j++)
            solve[(int)n][j]=0;
        for(int i=0;i<n;i++)
        {
            String S[]=br.readLine().split(" ");
            weights[i]=Integer.parseInt(S[0]);
            value[i]=Integer.parseInt(S[1]);
        }
        System.out.println(DP(0,(int)w));
        //System.out.println("\n\n\n");
        /*for(int i=0;i<n;i++)
        {
            for(int j=0;j<=w;j++)
                System.out.println(solve[i][j]);
        }*/
    }
    public static long DP(int x,int remainingCapacity)
    {
        if(solve[x][remainingCapacity]==-1)
        {
            if(remainingCapacity>=weights[x])
                solve[x][remainingCapacity]=Math.max(DP(x+1,remainingCapacity),(DP(x+1,remainingCapacity-weights[x])+value[x]));
            else
                solve[x][remainingCapacity]=DP(x+1,remainingCapacity);
        }
        return solve[x][remainingCapacity];
    }
}

Measured memory_bytes: 126032
x, y, z, k = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))
A_B_list = []
for i in range(x):
    for j in range(y):
        A_B = A_list[i] + B_list[j]
        A_B_list.append(A_B)
A_B_ranking = sorted(A_B_list, reverse=True)

A_B_C_list = []
for i in range(min(k, x*y)):
    for j in range(z):
        A_B_C = A_B_ranking[i] + C_list[j]
        A_B_C_list.append(A_B_C)

A_B_C_ranking = sorted(A_B_C_list, reverse=True)
for i in range(k):
    print(A_B_C_ranking[i])

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

bool check(int N,int K,vector<int> &A,int t){
  int count=0;
  for(int i;i<N;i++){
    count+=(A.at(i)-1)/t;
    if(count>K) return false;
  }
  return true;
}

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> A(N);
  for(int i=0;i<N;i++) cin >> A.at(i);
  int a,b,m;
  a=0;
  b=1<<30;
  while(b-a>1){
    m=(a+b)/2;
    if(check(N,K,A,m)){
      b=m;
    }else{
      a=m;
    }
  }
  cout << b << endl;
}


Measured memory_bytes: 4024
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
int main()
{
    ll n,w;
    cin>>n>>w;
    vector<pair<ll,ll> > a(n+1);
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i].first>>a[i].second;
    }
    ll k=1e5;
    vector<vector<ll> > dp(n+1,vector<ll> (k+2,1e16));
    for(ll i=0;i<=n;i++)
    {
        dp[i][0]=0;
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=k;j++)
        {
            if(j>=a[i].second)
            {
                dp[i][j]=min(dp[i-1][j],dp[i-1][j-a[i].second]+a[i].first);
            }
            else
            {
                dp[i][j]=dp[i-1][j];
            }
            
        }
    }
    ll maxi=0;

    for(ll i=1;i<=k;i++)
    {
        if(dp[n][i]<=w)
        {
            // cout<<dp[n][i]<<" ";
            maxi=i;
        }
    }
    cout<<maxi<<endl;

}

Measured memory_bytes: 83184
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
ll const mod =1e9+7;


int main(){
    string s;
    cin>>s;
    bool ok=true;
    if(s[1]=='R')ok=false;
    if(ok)cout<<"ARC"<<endl;
    else cout<<"ABC"<<endl;
    
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define eps 1e-3
#define pi acos(-1.0)
#define inf 0x3f
#define INF 0x3f3f3f3f
#define pb push_back
#define debug1 cout<<"&&";
#define debug2 cout<<"**";
#define ms(a, x) memset(a, x, sizeof(a))
#define for0(i, n) for(int i = 0; i < n; ++i)
#define for1(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;
typedef pair<long long, long long> pll;
const int mod = 1e9 + 7;
const int N = 1e5+10;
const int M = 1e6+10;
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline ll Pow(ll a, ll b) { ll ans = 1; for( ; b; b >>= 1) { if(b&1) ans = ans * a % mod; a = a * a % mod;} return ans;}
inline ll Mul ( ll a, ll b)  { ll lf = a * ( b >> 25ll ) % mod * ( 1LL << 25 ) % mod; ll rg = a * ( b & ( ( 1ll << 25 ) - 1 ) ) % mod; return ( lf + rg ) % mod;}
//==================================================================================================================================================================//

ll n, W, dp[N];
int ans;

int main() {
   scanf("%lld %lld", &n, &W);
   ms(dp, inf); dp[0] = 0;
   for1(i, n) {
      ll w, v;
      scanf("%lld %lld", &w, &v);
      for(int j = 100000; j >= v; --j) {
         dp[j] = min(dp[j], dp[j-v] + w);
      }
   }
   for1(i, 100000) if(dp[i] <= W) ans = i;
   printf("%d\n", ans);
   return 0;
}

Measured memory_bytes: 4604
# coding: utf-8

# In[28]:

import sys
#input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))


# In[21]:

#import numpy as np
#A.sort(key=lambda x:abs(x))
#print(N, A)


# In[25]:

#A = np.array(A)
#print(sum(A<0))
#if sum(A<0)%2 == 0:
#    print(sum(abs(A)))
#else:
#    print(sum(abs(A[1:])) - abs(A[0]))


# In[29]:

B = list(map(abs, A))
C = [a for a in A if a < 0]
#print(A)
#print(B)
#print(C)


# In[30]:

if len(C)%2 ==0:
    print(sum(B))
else:
    print(sum(B) - min(B)*2)


# In[ ]:





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

using namespace std;

void solve();

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

void solve() {
    int n;
    cin >> n;
    int d[n];
    for(int i = 0; i < n; i++) {
        cin >> d[i];
    }
    map<int,int> m;
    for(int i = 0; i < n; i++) {
        m[d[i]]++;
    }
    int M;
    cin >> M;
    int t[M];
    for(int i = 0; i < M; i++) {
        cin >> t[i];
    }
    for(int i = 0; i < M; i++) {
        if(m[t[i]] == 0) {
            cout << "NO" << endl;
            return;
        }
        m[t[i]]--;
    }
    cout << "YES" << endl;

}

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

int main() {
    long n, ans = 0;
    cin >> n;
    vector<int> a(n + 1), b(n + 1);
    rep(i, n + 1) cin >> a.at(i);
    rep(i, n) cin >> b.at(i);
    b.at(n) = 0;
    ans += min(a.at(0), b.at(0));
    b.at(0) -= ans;
    rep(i, n) {
        ans += min(a.at(i + 1), b.at(i) + b.at(i + 1));
        b.at(i + 1) -= min(max(0, a.at(i + 1) - b.at(i)), b.at(i + 1));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;;
#define int long long 
using namespace std;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPR(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size()) 
#define MAX(x) *max_element(ALL(x)) 
#define MIN(x) *min_element(ALL(x)) 
#define INF 1000000000000 
#define MOD 10000007 
#define MAXR 100000 
#define PI 3.14159265358979323846
using namespace std;

signed main(){

    double x ;
    cin >> x ;
    int ans =100;
    int c = 0;

    while(ans < x){
        ans *= 1.01 ;
        c++ ;
       // cout << "CCC" <<endl ;
    }
    
    cout << c <<endl ;  
      return 0;
}


Measured memory_bytes: 3724
#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
    vector<int> candy;
    REP(i, 3) {
        int tmp;
        cin >> tmp;
        candy.push_back(tmp);
    }
    sort(candy.begin(), candy.end());

    if (candy[0] + candy[1] == candy[2]) cout << "Yes" << '\n';
    else cout << "No" << '\n';
    return 0;
}

Measured memory_bytes: 256
S = input()
N = len(S)
countW = [0]*(N+1)
for i in range(1,N+1):
    countW[i] = countW[i-1]+(S[i-1]=='W')
ans = 0
for i in range(N):
    if S[i]=='W':
        ans += i-countW[i]
print(ans)


Measured memory_bytes: 11240
N,M,C=list(map(int,input().split()))
B = list(map(int,input().split()))
A=[]
for i in range(N):
    A.append(list(map(int,input().split())))
    
count=0
for i in range(N):
    s=C
    for j in range(M):
        s+=A[i][j]*B[j]
    if s>0:
        count+=1
        
print(count)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>

static const int MAXL = 53;
static const char *t = "AKIHABARA";
static const int TLEN = 9;

static char s[MAXL];
static int m = 0;

int main()
{
    scanf("%s", s);

    for (int i = 0; s[i] != '\0'; ++i) {
        while (s[i] != t[m] && m < TLEN && t[m] == 'A') ++m;
        if (s[i] != t[m]) {
            puts("NO");
            return 0;
        }
        ++m;
    }

    while (m < TLEN && t[m] == 'A') ++m;
    puts(m == TLEN ? "YES" : "NO");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
template<class T> inline istream& operator >> (istream & c, vector<T> & A) {rep(i, A.size()) c >> A[i];return c;}
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	map<int, int> mp;
	long long tmp = 0;
	for (int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		mp[a]++;
		tmp += a;
	}
	int q;
	cin >> q;
	while (q--) {
		int b, c;
		cin >> b >> c;
		long long res = mp[b];
		mp[b] = 0;
		tmp -= b * res;
		tmp += c * res;
		mp[c] += res;
		printf("%lld\n", tmp);
	}
	return 0;
}

Measured memory_bytes: 8088
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int[] cnt = new int[N];
    for (int i = 0; i < K; i++) {
      int d = sc.nextInt();
      int[] ary = new int[d];
      for (int j = 0; j < d; j++) {
        ary[j] = sc.nextInt();
      }
      for (int v : ary) {
        cnt[v-1]++;
      }
    }
    int ans = 0;
    for (int x = 0; x < N; x++) {
      if (cnt[x] == 0) {
        ans++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 46248
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fastinput                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

int main()
{
    fastinput;
    LL n, i, j, k, t, temp;
    cin >> n;
    LL a[3][n + 1], dp[3][n + 1];
    for (i = 1; i <= n; i++)
        cin >> a[0][i] >> a[1][i] >> a[2][i];
    for (i = 0; i <= 2; i++)
        for (j = 1; j <= n; j++)
            dp[i][j] = -1;

    dp[0][1] = a[0][1];
    dp[1][1] = a[1][1];
    dp[2][1] = a[2][1];
    for (i = 1; i <= n; i++)
    {
        for (j = 0; j < 3; j++)
        {
            dp[(j + 1) % 3][i + 1] = max(dp[(j + 1) % 3][i + 1], dp[j][i] + a[(j + 1) % 3][i + 1]);
            dp[(j + 2) % 3][i + 1] = max(dp[(j + 2) % 3][i + 1], dp[j][i] + a[(j + 2) % 3][i + 1]);
        }
    }
    LL ans = max({dp[0][n], dp[1][n], dp[2][n]});
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
n=input()
n=int(n)
i = int (1)
while True:
  if (i>n):
    break
  x=int(i)
  if (x%3 == 0):
    print ("",i,end="")
  elif(x%10 == 3):
    print ("",i,end="")
  else:
    while True:
      if(x==0):
        break
      x=x//10
      if(x%10 == 3):
        print ("",i,end="")
        break
  i=i+1
print ("")


Measured memory_bytes: 6160
// C++ code to find number of distinct numbers 
// in a subarray 
#include<bits/stdc++.h> 
using namespace std; 

const int MAX = 1000001; 

// structure to store queries 
struct Query 
{ 
	int l, r, idx; 
}; 

// cmp function to sort queries according to r 
bool cmp(Query x, Query y) 
{ 
	return x.r < y.r; 
} 

// updating the bit array 
void update(int idx, int val, int bit[], int n) 
{ 
	for (; idx <= n; idx += idx&-idx) 
		bit[idx] += val; 
} 

// querying the bit array 
int query(int idx, int bit[], int n) 
{ 
	int sum = 0; 
	for (; idx>0; idx-=idx&-idx) 
		sum += bit[idx]; 
	return sum; 
} 

void answeringQueries(int arr[], int n, Query queries[], int q) 
{ 
	// initialising bit array 
	int bit[n+1]; 
	memset(bit, 0, sizeof(bit)); 

	// holds the rightmost index of any number 
	// as numbers of a[i] are less than or equal to 10^6 
	int last_visit[MAX]; 
	memset(last_visit, -1, sizeof(last_visit)); 

	// answer for each query 
	int ans[q]; 
	int query_counter = 0; 
	for (int i=0; i<n; i++) 
	{ 
		// If last visit is not -1 update -1 at the 
		// idx equal to last_visit[arr[i]] 
		if (last_visit[arr[i]] !=-1) 
			update (last_visit[arr[i]] + 1, -1, bit, n); 

		// Setting last_visit[arr[i]] as i and updating 
		// the bit array accordingly 
		last_visit[arr[i]] = i; 
		update(i + 1, 1, bit, n); 

		// If i is equal to r of any query store answer 
		// for that query in ans[] 
		while (query_counter < q && queries[query_counter].r == i) 
		{ 
			ans[queries[query_counter].idx] = 
					query(queries[query_counter].r + 1, bit, n)- 
					query(queries[query_counter].l, bit, n); 
			query_counter++; 
		} 
	} 

	// print answer for each query 
	for (int i=0; i<q; i++) 
		cout << ans[i] << endl; 
} 

// driver code 
int main() 
{ 
    int n,q,a[500005];
    cin>>n>>q;
    for(int i=0;i<n;i++)
    cin>>a[i]; 
	Query queries[500005]; 
	for(int i=0;i<q;i++)
    {
        int le,ri;
        cin>>le>>ri;
        queries[i].l = le-1; 
        queries[i].r = ri-1; 
        queries[i].idx = i; 
    } 
	sort(queries, queries+q, cmp); 
	answeringQueries(a, n, queries, q); 
	return 0; 
} 


Measured memory_bytes: 19308
#include <iostream>
#include <cstring>

using namespace std;

int main(void)
{
    string s;
    cin>>s;
    if(s=="SUN")
        cout<<"7";
    else if(s=="MON")
        cout<<"6";
    else if(s=="TUE")
        cout<<"5";
    else if(s=="WED")
        cout<<"4";
    else if(s=="THU")
        cout<<"3";
    else if(s=="FRI")
        cout<<"2";
    else
        cout<<"1";
    return 0;
}


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

int main()
{
    int m, n;
    set<int> s;
    cin >> n;
    while(n--)
    {
        cin >> m;

        set<int>::iterator it=s.find(m);
        if(it==s.end()) s.insert(m);
        else s.erase(it);
    }

    cout << s.size();

    return 0;
}

Measured memory_bytes: 8252
#include <bits/stdc++.h>
#define ll long long
#define SZ(vvv) ((int)vvv.size())
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

const int N = 5e5 + 5, M = 5e4 + 9, INF = 1e9, MOD = 1e9 + 7;

void runtestcase() {

	string s;
	cin >> s;
	if(s.back() == 's')
		cout << s + "es";
	else
		cout << s + "s";

}


int main() {
    fastIO;
#ifdef LOCAL
    freopen("input.in", "rt", stdin);
//    freopen("cache.out", "wt", stdout);
#endif
  int t = 1, tt = 1;
//	cin >> t;
  while(t) {
//		cout << "Case #" << tt << ':' << ' ';
    runtestcase();
    if(t)
    	cout << '\n';
    --t, ++tt;
  }
}


Measured memory_bytes: 3660
use std::collections::HashMap;
use std::collections::VecDeque;
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let k = read::<usize>();
    let mut opens = HashMap::<usize, usize>::new();
    opens.insert(0, 1);
    let mut que = VecDeque::<usize>::new();
    que.push_back(0);
    let mut ans = 0;
    let mut sum = 0;
    for _i in 0..n {
        if que.len() >= k {
            let v = que.pop_front().unwrap();
            let entry = opens.entry(v).or_insert(0);
            *entry -= 1;
        }
        let v = read::<usize>();
        sum = (sum + v + k - 1) % k;
        let entry = opens.entry(sum).or_insert(0);
        ans += *entry;
        *entry += 1;
        que.push_back(sum);
    }
    println!("{}", ans);
}


Measured memory_bytes: 9560
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	k := intScanner()
	as := intSliceScanner(n)
	xs := make([]int, 0, n)
	ys := make([]int, 0, n)
	for i := 0; i < n; i++ {
		if as[i] < 0 {
			xs = append(xs, as[i])
		} else {
			ys = append(ys, as[i])
		}
	}
	sort.Sort(sort.Reverse(sort.IntSlice(ys)))
	sort.Ints(xs)
	ans := 1
	if n == k {
		for i := 0; i < n; i++ {
			if as[i] < 0 {
				ans *= as[i] + mod
			} else {
				ans *= as[i]
			}
			ans %= mod
		}
	} else if len(ys) == 0 {
		if k%2 == 0 {
			for i := 0; i < k; i++ {
				ans *= xs[i] + mod
				ans %= mod
			}
		} else {
			for i := n - 1; i > n-k-1; i-- {
				ans *= xs[i] + mod
				ans %= mod
			}
		}
	} else {
		if k%2 != 0 {
			ans = ys[0]
			ys = ys[1:]
			k--
		}
		i := 1
		j := 1
		for k > 0 {
			if i < len(xs) && j < len(ys) {
				p, q := xs[i-1]*xs[i], ys[j-1]*ys[j]
				if p > q {
					ans *= p % mod
					ans %= mod
					i += 2
					k -= 2
				} else {
					ans *= q % mod
					ans %= mod
					j += 2
					k -= 2
				}
			} else if i < len(xs) {
				ans *= xs[i-1] * xs[i] % mod
				ans %= mod
				i += 2
				k -= 2
			} else if j < len(ys) {
				ans *= ys[j-1] * ys[j] % mod
				ans %= mod
				j += 2
				k -= 2
			} else {
				break
			}
		}
	}
	fmt.Println(ans)
}


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

int main(){
  int n;
  cin>>n;
  
  vector<int>A(n);
  for(int i=0;i<n;i++)cin>>A[i];
  sort(A.begin(),A.end());

  vector<int>last;
  while(A.size()&&A[0]==0) last.push_back(0),A.erase(A.begin());
  if(A.size()&&last.size()%2)last.insert(last.end()-1,A[0]),A.erase(A.begin());
  while(A.size()&&A[0]==1) last.push_back(1),A.erase(A.begin());
  if(A.size()>=2&&A[A.size()-1]==3&&A[A.size()-2]==2)swap(A[A.size()-2],A[A.size()-1]);
  
  for(int i=0;i<A.size();i++)cout<<A[i]<<endl;
  for(int i=0;i<last.size();i++) cout<<last[i]<<endl;
  
  return 0;
}

Measured memory_bytes: 3160
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())
S = input().rstrip()

# l[i] : i番目からみて, 左側にいる W の人数
# r[i] : i番目からみて, 右側にいる E の人数
l = [0]*N
r = [0]*N

cnt = 0
for i in range(N-1):
    if S[i]=="W":
        cnt += 1
    l[i+1] = cnt
cnt = 0
for i in range(N-1):
    if S[N-1-i]=="E":
        cnt += 1
    r[N-1-i-1] = cnt

ans = N
for i in range(N):
    ans = min(ans, l[i]+r[i])

print(ans)

Measured memory_bytes: 17632
#include <stdio.h>
void swap(int *p, int *q){
  int tmp;
  tmp = *p;
  *p = *q;
  *q = tmp;
}


/*
A[0], A[1], ..., A[n-1] をソートして昇順に書き換える関数
*/
void quick_sort(int A[], int B[], int n){
    int i, j,pivot, ax;
    // 真ん中の要素をピボットとする
    if(n <= 1)  return ;
    pivot = A[n/2];
    A[n/2] = A[0];
    A[0] = pivot;
    ax = B[n/2];
    B[n/2] = B[0];
    B[0] = ax;  
    for(i = j = 1; i < n; i++){
        if(A[i] <= pivot){
            swap(A+i, A+j);
            swap(B+i, B+j);
            j++;
        }
    }
    A[0] = A[j-1];
    B[0] = B[j-1];
    A[j-1] = pivot;
    B[j-1] = ax;
    quick_sort(A, B, j-1);
    quick_sort(A+j, B+j, n-j);
    
}





int main(){
  int n, k, i, c;
  
  scanf("%d", &n);
  int A[n];
  int B[n];
  for (i=0; i<n; i++) scanf("%d", &A[i]);
  for (i=0; i<n; i++) {
    B[i] = i+1;
  }

  quick_sort(A, B, n);
  for (i=0; i<n; i++){
    printf("%d ", B[i]);
  }

  return 0;

  
  
  }

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

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

    set<string> st;
    
    for(int i=1; i<=k; i++){
        for(int j=0; j<s.size()-i+1; j++){
            st.insert(s.substr(j,i));
        }
    }
    int count = 0;
    for(auto itr = st.begin(); itr != st.end(); ++itr) {
        count++;
        if(count == k) std::cout << *itr << "\n";
    }
    return 0;
}

Measured memory_bytes: 1664
use std::io::Read;
use std::cmp::max;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();

    let mut results = Vec::new();
    dfs(n, &mut results, String::new(), -1);
    results.join("\n")
}

fn dfs(n: usize, results: &mut Vec<String>, s: String, mx: isize) {
    if s.len() == n {
        results.push(s);
        return;
    }

    let alphabets = vec!['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'];
    for i in 0..=(mx + 1) {
        dfs(n, results, format!("{}{}", s, alphabets[i as usize]), max(mx, i));
    }
}


Measured memory_bytes: 9496
#include <bits/stdc++.h>
using namespace std;
#define arep(i, x, n) for (int i = int(x); i < (int)(n); i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9 + 7
using ll = long long;

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

    int te_ceil = ceil(n / 1.08);
    int te_floor = floor(n / 1.08);

    int te_ceil_int = te_ceil * 1.08;
    int te_floor_int = te_floor * 1.08;

    if (te_ceil_int == n || te_floor_int == n) {
        if (te_ceil_int == n) {
            cout << te_ceil << endl;
        } else {
            cout << te_floor << endl;
        }
    } else {
        cout << ":(" << endl;
    }
}

Measured memory_bytes: 3632
#MLE注意！

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    k = int(input())
    def gcd(a, b):
        if b == 0:
            return a
        else:
            return gcd(b, a % b)
    
    def gcd_group(arr):
        g = gcd(arr[0], arr[1])
        for i in range(2, len(arr)):
            g = gcd(g, arr[i])
        return g
    
    def lcm(a, b):
        g = gcd(a, b)
        return (a*b)//g
    
    def lcm_group(arr):
        l = lcm(arr[0], arr[1])
        for i in range(2, len(arr)):
            l = lcm(l, arr[i])
        return l
    
    res = 0
    for a in range(1, k+1):
        for b in range(a, k+1):
            for c in range(b, k+1):
                if a==b==c:
                    res += gcd_group([a,b,c]) 
                elif a==b or b==c or a==c:
                    res += gcd_group([a,b,c]) * 3
                else:
                    res += gcd_group([a,b,c]) * 6
    print(res)

if __name__ == '__main__':
    main()

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

int main()
{
  int N;
  cin >> N;
  vector<int> d;
  rep(i, N)
  {
    int in;
    cin >> in;
    d.push_back(in);
  }
  sort(d.begin(), d.end());
  int ans = 1;
  rep(i, N - 1)
  {
    if (d[i] != d[i + 1])
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define fi first
#define se second
#define endl "\n" 
using namespace std;
using db = double;
using ll = long long;
using ull = unsigned long long; 
using pII = pair <int, int>;
using pLL = pair <ll, ll>;
constexpr int mod = 1e9 + 7;
template <class T1, class T2> inline void chadd(T1 &x, T2 y) { x += y; while (x >= mod) x -= mod; while (x < 0) x += mod; } 
template <class T1, class T2> inline void chmax(T1 &x, T2 y) { if (x < y) x = y; }
template <class T1, class T2> inline void chmin(T1 &x, T2 y) { if (x > y) x = y; }
inline int rd() { int x; cin >> x; return x; }
template <class T> inline void rd(T &x) { cin >> x; }
template <class T> inline void rd(vector <T> &vec) { for (auto &it : vec) cin >> it; }  
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0) 
void err() { cout << "\033[39;0m" << endl; } 
template <class T, class... Ts> void err(const T& arg, const Ts&... args) { cout << arg << ' '; err(args...); }
template <template<typename...> class T, typename t, typename... A> 
void err(const T <t> &arg, const A&... args) { for (auto &v : arg) cout << v << ' '; err(args...); }
inline void pt() { cout << endl; } 
template <class T, class... Ts> void pt(const T& arg, const Ts&... args) { cout << arg << ' '; pt(args...); }
template <template<typename...> class T, typename t, typename... A> 
void pt(const T <t> &arg, const A&... args) { for (auto &v : arg) cout << v << ' '; pt(args...); }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll qpow(ll base, ll n) { ll res = 1; while (n) { if (n & 1) res = res * base % mod; base = base * base % mod; n >>= 1; } return res; }
//head
constexpr int N = 2e3 + 10;
int n, a[N]; 
void run() {
	for (int i = 1; i <= n; ++i) a[i] = rd();
	sort(a + 1, a + 1 + n);
	ll res = 0;
	for (int i = 1; i <= n; ++i) {
		int pos = 1;
		for (int j = i - 1; j >= 1; --j) {
			if (pos > j) break;
			while (pos < j && a[pos] + a[j] <= a[i]) ++pos;
			res += j - pos;
		}
	}
	pt(res);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	cout << fixed << setprecision(20);
	while (cin >> n) run();
	return 0;
}


Measured memory_bytes: 256