akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);
const long double EPS = 1e-10; //要検証
long double add(const long double &x, const long double &y){
    if(abs(x + y) < EPS * (abs(x) + abs(y)) ) return 0;
    return x + y;
}
struct PL{
    long double x, y;
    PL() {}
    PL(long double x, long double y) : x(x), y(y) {
    }
    PL operator + (const PL &p){
        return PL(add(x, p.x), add(y, p.y));
    }
    PL operator - (const PL &p){
        return PL(add(x, -p.x), add(y, -p.y));
    }
    PL operator * (const long double d){
        return PL(x * d, y * d);
    }
    PL operator / (const long double d){
        return PL(x / d, y / d);
    }
    long double dot(const PL &p){
        return add(x * p.x, y * p.y);
    }
    long double det(const PL &p){
        return add(x * p.y, -y * p.x);
    }
    long double len(){
        return sqrt(add(x * x, y * y));
    }
};

/*bool cmp_x(const PL &p, const PL &q){
    if(p.x != q.x) return p.x < q.x;
    return p.y < q.y;
}*/

bool getCircleCross(const PL &a, const long double &ra, PL &b, const long double rb, PL &ans1, PL &ans2){
    //交わらなければfalse
    PL v = b - a;
    if(v.len() - ra - rb > EPS || v.len() - abs(ra - rb) < EPS) return false;
    long double len2 = v.dot(v), con = (len2 + ra * ra - rb * rb) * 0.5;
    PL t1 = v * con, t2 = PL(v.y, -v.x) * sqrt(len2 * ra * ra - con * con);
    ans1 = (t1 + t2) / len2 + a;
    ans2 = (t1 - t2) / len2 + a;
    return true;
}
vector<PL> d(60);
vec c(60);


bool check(const long double &time){
    rep(i,N){
        rep(j,i){
            PL a, b;
            if(getCircleCross(d[i], time / c[i], d[j], time / c[j], a, b)){
                int na = 0, nb = 0;
                rep(k, N) {
                    na += ((a - d[k]).len() * c[k] - time < EPS);
                    nb += ((b - d[k]).len() * c[k] - time < EPS);
                }
                if(na >= K || nb >= K) return true;
            }
        }
    }
    rep(i,N){
        int na = 0;
        rep(k, N) {
            na += ((d[i] - d[k]).len() * c[k] - time < EPS);
        }
        if(na >= K) return true;
    }
    return false;
}

int main() {
    cin>>N>>K;
    rep(i,N) cin>>d[i].x>>d[i].y>>c[i];

    if(K == 1){
        cout<<0<<endl;
    }else {
        long double lb = 0, ub = 5e+5;
        while(ub - lb > 5e-7 && ub * ub - lb * lb > 1e-7){
            long double cen = (ub + lb) * 0.5;
            (check(cen) ? ub : lb) = cen;
        }
        cout<<fixed<<setprecision(10)<<ub<<endl;
    }
}

Measured memory_bytes: 3864
#[derive(Default)]
//NOTE
//declare variables to reduce the number of parameters for dp and dfs etc.
struct Solver {}

impl Solver {
    fn solve(&mut self) {
        let stdin = std::io::stdin();
        let mut scn = Scanner {
            stdin: stdin.lock(),
        };
        let n: i64 = scn.read();
        let m: usize = scn.read();
        let d: i64 = scn.read();
        let mut result = 0.0;
        if d == 0 {
            println!("{:.10}", 1.0 / n as f64 * (m - 1) as f64);
            return;
        }
        println!(
            "{:.10}",
            2.0 * (n - d) as f64 * (m - 1) as f64 / n as f64 / n as f64
        );
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| {
            let mut solver = Solver::default();
            solver.solve()
        })
        .unwrap()
        .join()
        .unwrap();
}
pub mod utils {
    const DYX: [(isize, isize); 8] = [
        (0, 1),   //right
        (1, 0),   //down
        (0, -1),  //left
        (-1, 0),  //top
        (1, 1),   //down right
        (-1, 1),  //top right
        (1, -1),  //down left
        (-1, -1), //top left
    ];

    pub fn try_adj(y: usize, x: usize, dir: usize, h: usize, w: usize) -> Option<(usize, usize)> {
        let ny = y as isize + DYX[dir].0;
        let nx = x as isize + DYX[dir].1;
        if ny >= 0 && nx >= 0 {
            let ny = ny as usize;
            let nx = nx as usize;
            if ny < h && nx < w {
                Some((ny, nx))
            } else {
                None
            }
        } else {
            None
        }
    }
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 8572
n,k=map(int,input().split())
a=list(map(int,input().split()))

dp=[100000000000000000 for _ in range(n)]
dp[0]=0
#print(r)

for i in range(n):
  for j in range(min(k,n-i-1)):
    dp[i+j+1]=min(dp[i+j+1],dp[i]+abs(a[i+j+1]-a[i]))
      #print(i,i+j,">>",r)
  
print(dp[-1])


Measured memory_bytes: 56544
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using i64 = int64_t;

__attribute__((constructor)) static void init()
{
    ios::sync_with_stdio(false);
    std::cin.tie(0);
}

int main()
{
    int k, n;
    cin >> k >> n;
    int longest = 0;
    int st;
    cin >> st;
    int before = st;
    for (int i = 1; i < n; i++) {
        int tmp;
        cin >> tmp;
        longest = max(longest, tmp - before);
        before = tmp;
    }

    longest = max(longest, st + k - before);

    cout << k - longest << "\n";
}


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

int main(){
    int n;
    cin >> n;
    vector<int> p, q, a;
    int k;
    for(int i = 0; i < n; i++){
        cin >> k;
        p.push_back(k);
    }
    for(int i = 0; i < n; i++){
        cin >> k;
        q.push_back(k);
    }
    for(int i = 1; i <= n; i++){
        a.push_back(i);
    }

    int p_ans = 1;
    int q_ans = 1;
    int cou = 1;
    int flag = 0;

    do {
        if(p == a){
            p_ans = cou;
            flag++;
        }
        if(q == a){
            q_ans = cou;
            flag++;
        }
        if(flag == 2){
            break;
        }
        cou++;
    } while (next_permutation(a.begin(), a.end()));

    cout << abs(p_ans - q_ans) << endl;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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; }

const ll MRINF = 5000000000000000;

int main() {


    int N, M, X;
    cin >> N >> M >> X;
    vector<ll> A(M);
    REP(i, M)cin >> A[i];
    ll cost1 = 0, cost2 = 0;
    REP(i, M){
        if(A[i] < X)cost1++;
        else if(N >= A[i]&&A[i] > X) cost2++;
    }
    cout << min(cost1, cost2) << endl;



    

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		int c = in.nextInt();
		int cnt = 0;
		for(int i = a;i <= b;i++){
			if(c % i == 0){
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 17228
import math

abc = input()
abc_list = abc.split(' ')
abc_intlist = []
for c1 in abc_list:
  abc_intlist.append(int(c1))
a = abc_intlist[0]
b = abc_intlist[1]
x = abc_intlist[2]
if (a**2)*b<2*x:
    print(math.degrees(math.atan(  2*(b-x/(a**2))/a  )  ))
else:
    print(math.degrees(math.atan(  a*(b**2)/(2*x)  )  ))


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl '\n';
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll POSITIVE_INFINITY = 9223372036854775807;
const ll NEGATIVE_INFINITY = -9223372036854775807;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);

template <typename T> inline T bigMod(T A,T B,T M = MOD){A %= M;T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T invMod (T A,T M = MOD){return bigMod(A,M-2,M);}

const int N = 200005;

int main(){
  FASTER;
  int a, b;
  cin >> a >> b;
  string x(b, '0' + a);
  string y(a, '0' + b);
  if (x <= y){
    cout << x << "\n";
  } else {
    cout << y << "\n";
  }
  return 0;
}

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

int main(){
    int H, W;
    while(1) {
        cin >> H >> W;
        
        if (H == 0 && W == 0) break;
        
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (i == 0 || i == H - 1 || j == 0 || j == W - 1) {
                    cout << "#";
                } else {
                    cout << ".";
                }

            }
            cout << "\n";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3056
#include <bits/stdc++.h>
#define pb push_back
#define ll long long 
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    for(int T = 0; T < t ; T++){
       ll a, b, x;
       cin >> a >> b >> x;
       ll arem = a%x, brem = b%x;
       a /= x;
       b /= x;
       if(arem == 0 && brem == 0)
            std::cout << b - a + 1<< std::endl;
       else if(arem == 0)
           cout << b - a + 1 << endl;
        else
            cout << b - a  << endl;
    }
    return 0;
}

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

//GCD,LCM
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;}

int main()
{
    int N,A[100010]={},ans=0;

    cin>>N;
    for(int i=1;i<=N;i++){
        cin>>A[i];
    }

    for(int i=1;i<=N;i++){
        if(i==A[A[i]])ans++;
    }

    cout<<ans/2<<endl;

    return 0;
}

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

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define all(x) (x).begin(), (x).end()
template <typename T> istream& operator>>(istream& i, vector<T>& o) { rep(j, o.size()) i >> o[j]; return i;}
using ll = long long; using vll = vector<ll>; 
int main(void) {
    ll n; cin >> n; vll a(n); cin >> a;
    bitset<4000010> dp; dp[0] = 1; rep(i, n) dp |= (dp << a[i]);
    ll s = accumulate(all(a), 0ll);
    repi(i, s/2+(s&1), 4000010) if (dp[i]) 
        return cout << i << endl, 0;
}


Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		if(Math.abs(n-m) >= 2) {
			System.out.println("0");
			return;
		}
		long n$ = 1L;
		for(int i = 1; i <= n; i++) {
			n$ = n$ * i % 1000000007;
		}
		long m$ = 1L;
		for(int i = 1; i <= m; i++) {
			m$ = m$ * i % 1000000007;
		}
		long ans = n$ * m$ % 1000000007;
		System.out.println(n==m ? 2*ans%1000000007 : ans);
	}
}

Measured memory_bytes: 24916
import java.util.*;

class Main {
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                int N = sc.nextInt();
                int M = sc.nextInt();
                int[] num = new int[N];
                for (int i = 0; i < N; i++) {
                        num[i] = 1;
                }
                boolean[] b = new boolean[N];
                b[0] = true;
                for (int i = 0; i < M; i++) {
                        int x = sc.nextInt(), y = sc.nextInt();
                        x--; y--;
                        num[x]--;
                        num[y]++;
                        if (b[x]) {
                                b[y] = true;
                        }
                        if (num[x] == 0) {
                                b[x] = false;
                        }
                }
                int ans = 0;
                for (int i = 0; i < N; i++) {
                        if (b[i]) {
                                ans++;
                        }
                }
                System.out.println(ans);
        }
}

Measured memory_bytes: 24056
#include <bits/stdc++.h>
using namespace std;
int main(){
    int h,w;
    cin>>h>>w;
    char c[h][w];
    for(int i=0;i<h;i++){
    	for(int j=0;j<w;j++){
    		cin>>c[i][j];
    	}
    }
    for(int k=0;k<h*2;k++){
    	cout<<endl;
    	for(int l=0;l<w;l++){
    		cout<<c[k/2][l];
    	}
    }
    	return 0;
}


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

const int N = 1e5+7;
vector<int> adj[N];

int dfs(int u, int par)
{
    int gr = 0;
    for (auto v : adj[u])
        if (v!=par)
            gr ^= dfs(v, u);
    return 1 + gr;
}

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

    int t;
    t=1;

    while(t--) {
        fill(adj, adj+N, vector<int>());

        int n;
        cin>>n;

        for (int i=1; i<n; i++) {
            int u, v;
            cin>>u>>v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        int gr = dfs(1, -1) - 1;
        cout<<(gr ? "Alice\n" : "Bob\n");
    }
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int D;
int C[26];
int S[400][26];
int T[400];
int day[26];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>D;
	FOR(i,26) cin>>C[i];
	FOR(i,D) {
		FOR(j,26) cin>>S[i][j];
	}
	
	int sum=0;
	FOR(i,D) {
		cin>>T[i];
		T[i]--;
		sum+=S[i][T[i]];
		day[T[i]]=i+1;
		FOR(j,26) sum-=C[j]*(i+1-day[j]);
		cout<<sum<<endl;
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

int n, m;
vector<vector<int>> s(11, vector<int>(11));
vector<int> p(11);

int sim(string str, int nn)
{
    if (nn == 0)
    {
        int cnt = 0;
        for (int i = 0; i < m; i++)
        {
            int tmp = 0;
            for (int j = 0; j < s[i].size(); j++){
                tmp ^= (str[s[i][j]-1] == '1');
            }
            if(tmp == p[i]){
                cnt++;
            }
        }
        return cnt==m;
    }
    if (nn > 0)
    {
        return sim(str + "0", nn - 1) + sim(str + "1", nn - 1);
    }
}

int main()
{

//    int n, m;
    cin >> n >> m;
//    vector<vector<int>> s(11, vector<int>(11));

    for (int i = 0; i < m; i++)
    {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++)
        {
            int s1;
            cin >> s1;
            s[i].push_back(s1);
        }
    }
    for (int i = 0; i < m; i++)
    {
        cin >> p[i];
    }

    cout << sim("", n) << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main  {
   public static void main(String[] args)  {
      Scanner sc = new Scanner(System.in);
      
      int n = sc.nextInt();
      int m = sc.nextInt();
      
      int hw = 0;
      
      for (int i = 0; i < m; i++) {
         int a = sc.nextInt();
         hw += a;
      }
      if (n - hw >= 0) {
         System.out.println(n - hw);
      } else {
         System.out.println("-1");
      }
      
   }   
}


Measured memory_bytes: 46188
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - Digit Sums
            var line = Console.ReadLine();
            int n = int.Parse(line);
            
            //各桁の和
            int s = 0;
            
            foreach(var c in line)
            {
                s += int.Parse(c.ToString());
            }

            if (n % s == 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }            
        }
    }
}

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

int main() {
  string s;
  cin >> s;
  map<char, int> m;
  for (int i = 0; i < s.size(); i++) {
    m[s[i]]++;
  }

  if (abs(m['a'] - m['b']) <= 1 && abs(m['b'] - m['c']) <= 1 &&
      abs(m['c'] - m['a']) <= 1) {
    puts("YES");
  } else {
    puts("NO");
  }

  return 0;
}


Measured memory_bytes: 3684
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const int N = 5010;
const ll mod = 1e9 + 7;
ll dp[N][N][2], size[N];
VI e[N];
int n;

ll fact[N];

void dfs(int now, int past){
    dp[now][1][0] = 1;
    size[now] = 1;
    for (int next : e[now]){
        if (next == past) continue;
        dfs(next, now);
        int s1 = size[now], s2 = size[next];
        VVL dp2(s1+s2+1, VL(2));
        FOR(i,1,s1) REP(p,2) REP(j,s2+1) REP(q,2){
            ll tmp = (dp[now][i][p] * dp[next][j][q]) % mod;
            (dp2[i+j][(p+q)%2] += dp[now][i][p] * dp[next][j][q]) %= mod;
            (dp2[0][(p+q+1)%2] += tmp * fact[i+j]) %= mod;
        }
        REP(i,s1+s2+1) REP(k,2){
            dp[now][i][k] = dp2[i][k];
        }
        size[now] += size[next];
    }
}

int main() {
    fact[0] = 1;
    for (int i = 2; i < N; i += 2){
        fact[i] = (fact[i-2] * (i - 1)) % mod;
    }
    cin >> n;
    REP(i,n-1){
        int u = in() - 1, v = in() - 1;
        e[u].push_back(v);
        e[v].push_back(u);
    }

    dfs(0, -1);
    ll ans = (dp[0][0][1] - dp[0][0][0] + mod) % mod;
    cout << ans << endl;

    return 0;
}


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

using namespace std;


int main()
{
    long long int t, i, j, k;
    string s;
    cin >> s;
    if(s[2]==s[3] && s[4]==s[5]){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MOD 1000000007
#define MOD2 998244353
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) (ll)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(ll i=a;i<=b;++i)
#define ROF(i,a,b) for(ll i=a;i>=b;--i)
#define trace(x) cerr<<#x<<": "<<x<<'\n';
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;
#define T int
#define ordered_set tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
auto clk=clock();
 
ll mexp(ll a, ll b, ll m){
    ll ans=1;
    a%=m;
    while(b){
        if(b&1) ans=ans*a%m;
        b>>=1;
        a=a*a%m;
    }
    return ans;
}

const int N = 100005;
int a[N];

int main(){
    IOS
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    int n;
    cin >> n;
    FOR(i,1,n){
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    if(n % 2 == 1){
        if(a[1] != 0){
            cout << 0;
            return 0;
        }
        for(int i = 2; i <= n - 1; i += 2){
            if(a[i] != i || a[i+1] != i){
                cout << 0;
                return 0;
            }
        }
        cout << mexp(2, n / 2, MOD);
    }
    else{
        for(int i = 1; i <= n - 1; i += 2){
            if(a[i] != i || a[i+1] != i){
                cout << 0;
                return 0;
            }
        }
        cout << mexp(2, n / 2, MOD);
    }

    cerr<<endl<<endl<<"Time: "<<fixed<<setprecision(12)<<(long double)(clock()-clk)/CLOCKS_PER_SEC<<" ms"<<endl<<endl;
 
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
typedef long long ll;

bool check_prime(int x) {
    int s = (int) ceil(sqrt(x));
    for (int a = 2; a < s; a++) {
        if (x % a == 0) return false;
    }
    return true;
}

int main() {
    int X;
    cin >> X;
    while (true) {
        if (check_prime(X)) {
            break;
        }
        X += 1;
    }
    cout << X << endl;
}


Measured memory_bytes: 384
import itertools
N, M, Q = map(int, input().split())
q_list = []
final_score = 0
for i in range(Q):
    q_list.append(list(map(int, input().split())))
for A in itertools.combinations_with_replacement(range(1,M+1), N):
    score = 0
    for q in q_list:
        if A[q[1]-1] - A[q[0]-1] == q[2]:
            score += q[3]
        final_score = max([final_score, score])
print(final_score)

Measured memory_bytes: 9196
import qualified Data.Map as M
import Data.List (sortBy)

split2 :: [a] -> ([a], [a])
split2 ns = helper ([], []) ns
  where helper (as, bs) (x:y:zs) = helper (x:as, y:bs) zs
        helper all _ = all

toMap :: [Int] -> M.Map Int Int
toMap ns = foldr (\a b -> M.insertWith (+) a 1 b) M.empty ns

mosts :: (Ord k, Ord v) => M.Map k v -> [(v, k)]
mosts m = sortBy (flip compare) $ map (\(a,b) -> (b,a)) (M.assocs m)

count :: Eq a => [(Int, a)] -> [(Int, a)] -> Int
count [] (b:bs) = fst b
count (a:as) [] = fst a
count (a:as) (b:bs) = if (snd a /= snd b)
                      then fst a + fst b
                      else max (count (a:as) bs) (count as (b:bs))

doMain :: String -> Int
doMain line = 2 * (length as) - (count as' bs')
  where (as, bs) = split2 . map read $ words line ::([Int], [Int])
        as' = mosts $ toMap as
        bs' = mosts $ toMap bs

main = do
  getLine
  line <- getLine
  print $ doMain line


Measured memory_bytes: 47484
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// nameテ」ツ?ィtimeテ」ツ?ョテ」ツδ?」ツδシテ」ツつソテ」ツつ津」ツつづ」ツ?、テ」ツつッテ」ツδゥテ」ツつケテ」ツつ津」ツ?、テ」ツ?湘」ツつ?
		Scanner sc = new Scanner(System.in);
		int n=0,m=0;
		int[] timen = new int[31]; // テ」ツ?敕」ツ?ョテヲツ卍づ・ツ按サ(テヲツキツサテ・ツュツ?テ」ツ?ォテ」ツ??」ツつ凝、ツコツコテヲツ閉ー
		
		while(sc.hasNext()){
			n = sc.nextInt();
			if(n==0) break;
			
			charactor[] chara = new charactor[n];
			
			// テ」ツδ?」ツδシテ」ツつソテ・ツ?・テ・ツ環?
			for(int i = 0;i<n;i++){
				chara[i] = new charactor(sc.next());
				m = sc.nextInt();
				for(int j = 0;j<m;j++){
					int t = sc.nextInt();
					chara[i].addTime(t);
					timen[t]++;
				}
			}
			
			int minpoint = chara[0].getPoint(n,timen);
			String minname = chara[0].name;
			
			// テ」ツ?禿」ツ?禿」ツ?凝」ツつ英ointティツィツ暗ァツョツ?
			for(int i = 1;i<n;i++){
				//System.out.println(chara[i].name + ": " +chara[i].getPoint(n, timen));
				if(chara[i].getPoint(n, timen)<minpoint){
					minpoint = chara[i].getPoint(n, timen);
					minname = chara[i].name;
				}else if(chara[i].getPoint(n, timen)==minpoint){
					minname = chara[i].name.compareToIgnoreCase(minname)<0 ? chara[i].name : minname;
				}
			}
			
			System.out.println(minpoint + " " + minname);
		
			for(int i = 0;i<timen.length;i++) timen[i] = 0;
		}
	}

}

class charactor{
	ArrayList<Integer> time = new ArrayList<Integer>();
	String name;
	public charactor(String name){
		this.name = name;
	}
	void addTime(int t){
		time.add((Integer)t);
	}
	int getPoint(int n,int[] timen){
		int point=0;
		//System.out.print(name + ": ");
		for(int timei:time){
			point += n - (timen[timei]-1);
			//System.out.print(point + " ");
		}
		//System.out.println("]");
		return point;
	}
}

Measured memory_bytes: 30500
def chmin(a, b)
  a > b ? b : a
end
n = gets.to_i
k = gets.to_i
x = gets.split.map(&:to_i)

sum = 0
(0..n - 1).each do |i| 
    l = chmin(x[i] * 2, (x[i] - k).abs * 2)
    sum += l
end
puts sum

Measured memory_bytes: 1788
import sys

while True:
    m, f, r = [int(i) for i in input().split()]
    if m == -1 and f == -1 and r == -1:
        sys.exit()
    else:
        if m == -1 or f == -1:
            print('F')
        elif m + f >= 80:
            print('A')
        elif m + f >= 65:
            print('B')
        elif m + f >= 50:
            print('C')
        elif m + f >= 30:
            if r >= 50:
                print('C')
            else:
                print('D')
        else:
            print('F')


Measured memory_bytes: 5604
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

#define DEBUG
#ifndef DEBUG
#define endl "\n"
#endif

const double PI=3.1415926535897932384626433;
typedef long long ll;
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }

typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
    cini(n);
    for(int i=1; i<=9; i++) 
        for(int j=1; j<=9; j++)
            if(n==i*j) {
                cout<<"Yes"<<endl;
                return 0;
            }
    cout<<"No"<<endl;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define fi first
#define se second 
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define rep(i,a,b) for( ll i = a ; i < b ; i+=1 )
#define pp pair<ll,ll> 
#define sz(v) (ll)(v.size())
#define hell (ll)1000000007
#define slld(x) scanf("%lld",&x)
ll t = 1;
void solve() 
{
	ll n, cur=1;
	cin>>n;
	vector<ll> v(n);
	rep(i,0,n)cin>>v[i];
	rep(i,0,n){
		if(v[i]==cur)cur++;
	}
	if(n-cur+1>=n){
		cout<<"-1\n";return;
	}
	cout<<n-cur+1<<"\n";
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //cin >> t ;
    while(t--){
        solve();
    }
    return 0 ;
}


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

// abs(A-B)が偶数だった場合、答えはabs(A-B)/2
// abs(A-B)が奇数だった場合、どちらか片側まで二つが移動する必要がある。
//  ↑どちらかが片側まで移動し、(A-B)の偶奇を調整して、両方が近づく方が最適だった

int main() {
    long long N,A,B;
    cin >> N >> A >> B;
    if(abs(A-B)&1LL) {
        cout << min(A-1,N-B) + 1 + (B-A-1)/2 << endl;
    } else {
        cout << abs(A-B)/2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	static long ln = 1000000007;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		long fibdp[] = new long[n+1];
		fibdp[0] = 1;
		fibdp[1] = 1;
		for(int i=2;i<=n;i++) {
			fibdp[i] = (fibdp[i-1] + fibdp[i-2])%ln;
		}
		int[] a = null;
		if(m!=0) {
			a = new int[m];
			for(int i=0;i<m;i++) {
				a[i] = sc.nextInt();
			}
		}
		long ans;
		if(m!=0)
			ans = fib(a[0] -1, fibdp)% ln;
		else
			ans = fib(n, fibdp)%ln;
		
		for(int i=1;i<m;i++) {
			if(a[i]-a[i-1] == 0) {
				ans = 0;
				break;
			}
			ans = (ans * (fib(a[i]-a[i-1]-2, fibdp)% ln)) %ln;
		}
		if(m!=0)
			ans = (ans * (fib(n - a[m-1] -1, fibdp)% ln)) %ln;
		
		System.out.print(ans);
	}
	
	public static long fib(int i, long[] fibdp) {
		if(i<0)
			return 0;
		else 
			return fibdp[i];
	}
}

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

int main(){
	const int MAX_N = 100;
	int n, m, k;
	int card[MAX_N * 2], sub[MAX_N * 2];
	
	scanf("%d", &n);
	for(int i = 0; i < n * 2; i++){
		card[i] = i + 1;
	}
	
	scanf("%d", &m);
	
	for(int i = 0; i < m; i++){
		scanf("%d", &k);
		
		if(k == 0){
			for(int j = 0; j < n; j++){
				sub[j * 2] = card[j];
				sub[j * 2 + 1] = card[j + n];
			}
		}
		else{
			for(int j = k; j < 2 * n; j++){
				sub[j - k] = card[j];
			}
			for(int j = 0; j < k; j++){
				sub[2 * n - k + j] = card[j];
			}
		}
		
		for(int j = 0; j < n * 2; j++) card[j] = sub[j];
	}
	
	for(int i = 0; i < n * 2; i++){
		printf("%d\n", card[i]);
	}
	
	return 0;
}

Measured memory_bytes: 1028
gets
s = gets.strip

l = 0
o = ''
s.each_char {|c|
	l+=1 if c == '('
	l-=1 if c == ')'
	if l == -1
		o = '(' + o
		l = 0
	end
	o += c
}
l.times do
	o += ')'
end
puts o


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

using namespace std;

bool marcados[3][3];
int bingo[3][3];
int n,b;


void marcar(int numero) {
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			if (numero == bingo[i][j]) {
				marcados[i][j] = true;
				return;
			}
		}
	}
}

bool verificar_linha() {
	for (int i = 0; i < 3; i++) {
		if (marcados[i][0] && marcados[i][1] && marcados[i][2]) {
			return true;
		}	
	}

	return false;
}

bool verificar_coluna() {
	for (int i = 0; i < 3; i++) {
		if (marcados[0][i] && marcados[1][i] && marcados[2][i]) {
			return true;
		}
	} 

	return false;
}

bool verificar_diagonal1() {
	return marcados[0][0] && marcados[1][1] && marcados[2][2];
}

bool verificar_diagonal2() {
	return marcados[0][2] && marcados[1][1] && marcados[2][0];
}

int main() {

	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			marcados[i][j] = false;
		}
	}
	
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> bingo[i][j];
		}
	}

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> b;
		marcar(b);
	}

	if (verificar_linha() || verificar_coluna() || verificar_diagonal1() || verificar_diagonal2()) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

}


Measured memory_bytes: 3636
#include<iostream>

int main(){

    size_t s;
    std::cin >> s;

    size_t hour = s / 3600;
    size_t min = (s % 3600) / 60;
    size_t sec = s % 60;

    std::cout << hour << ':' << min << ':' << sec << std::endl;

    return 0;
}



Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define INF 2000000000	//int型は2 * 10^9ぐらいまで
#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int h, w, cnt = 0;
	char a[8][8];
	cin >> h >> w;
	REP(i, h){
		REP(j, w){
			cin >> a[i][j];
			if(a[i][j] == '#') cnt++;
		}
	}

	if(cnt == h + w - 1) cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	
	rtn 0;
}

Measured memory_bytes: 256
#include<cstdio>
int main() 
{
	int n;
	double dp[3000 + 5];
	//dp[heads] = probability of x heads so far
	scanf("%d", &n);
	dp[0] = 1;
	for (int i = 1; i <= n; i++) dp[i] = 0;
	for (int coin = 0; coin < n; coin++) {
		double p_heads;
		scanf("%lf", &p_heads);
		for (int i = coin + 1; i >= 0; i--) {
			dp[i] = (i == 0 ? 0 : dp[i - 1] * p_heads) + dp[i] * (1 - p_heads);
		}
	}

	double ans = 0;
	for (int heads = 0; heads <= n; heads++) {
		int tails = n - heads;
		if (heads > tails) {
			ans += dp[heads];
		}
	}
	printf("%.10lf\n", ans);
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) {
    int x;
    cin >> x;
    a[x-1]++;
  }
  sort(a.begin(),a.end());
  vector<int> s(n+1); // sum of [0,i)
  rep(i,n) s[i+1] = s[i]+a[i];
  for (int k = 1; k <= n; ++k) {
    int l = 0, r = n/k+1; // l:OK, r:NG
    while (l+1 < r) {
      int c = (l+r)/2;
      bool ok = [&](int c) {
        int i = lower_bound(a.begin(), a.end(), c) - a.begin();
        int sum = c*(n-i) + s[i];
        return (sum >= c*k);
      }(c);
      if (ok) l = c; else r = c;
    }
    printf("%d\n", l);
  }
  return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
string s,s1,s2,s3,s4,s5,s6;
int main() {
	// your code goes here
	cin>>s;
	s1=s;
	int l=s.size();
	  for(int i=((l-1)/2)-1;i>=0;i--)
	    {
	     s2+=s[i];  
	    }
	   // cout<<s2<<endl;
	    s4=s2;
	     for(int i=l-1;i>=((l+3)/2)-1;i--)
	    {
	     s3+=s[i];  
	    }
	   //  cout<<s3<<endl;
	    s5=s3;
	     reverse(s2.begin(),s2.end());
	    reverse(s3.begin(),s3.end());
	    reverse(s1.begin(),s1.end());
     if(s==s1&&s4==s2&&s5==s3)
     cout<<"Yes";
     else
     cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
	int MaxAi = 0;
	int Bi = 0;
	int N;
	cin >> N;
	int tempA;
	int tempB;
	for (int i = 0; i < N; i++)
	{
		cin >> tempA;
		cin >> tempB;
		if (MaxAi < tempA)
		{
			MaxAi = tempA;
			Bi = tempB;
		}
		
	}
	cout << MaxAi + Bi;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  for(int j=0; j<n; j++){
    cin >> b[j];
  }
  for(int k=0; k<n-1; k++){
    cin >> c[k];
  }
  
  int sum=0;
  for(int m=0; m<n; m++){
    sum += b[a[m]-1];
    if(a[m+1]-a[m]==1){
      sum += c[a[m]-1];
    }
  }
  
  cout << sum << endl;
  
}

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

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		int[] a = {1,0,0};
		while(sc.hasNext()) {
			String[] s = sc.next().split(",");
			swap( a, (int)(s[0].charAt(0) - 'A'), (int)(s[1].charAt(0) - 'A'));
//			debug(a);
		}
		int ans = 0;
		for(int i=0;i<3;i++) if(a[i] == 1) ans = i;
		System.out.println((char) ('A' + ans));
	}
	
	void swap(int[] s, int a, int b) {
		int tmp = s[a];
		s[a] = s[b];
		s[b] = tmp;
	}

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

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
{-# LANGUAGE ScopedTypeVariables #-}
import Control.Applicative
import Control.Monad
import Control.Monad.State
import Control.DeepSeq
import Data.Array
import Data.Bits
import Data.Char
import Data.Functor.Identity
import Data.List
import Data.Ord
import Data.Maybe
import Data.Tree
import Data.Tuple
import qualified System.IO
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.Sequence as Q
import qualified Data.ByteString.Char8 as B

main = do
  (n,x) <- getIntPair
  print $ n + solve x (n-x)

solve a b
  | r == 0
    = (2 * q - 1) * a
  | otherwise
    = 2 * q * a + solve r a
  where
   q = b `div` a
   r = b `mod` a
 
type Z = Int
type Q = Rational
type R = Double
type S = String

fint :: (Integral a, Num b) => a -> b
fint = fromIntegral

getInt = fst . fromJust . B.readInt <$> B.getLine
getIntPair = (\[a,b]->(a,b)) <$> getInts
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine
getStr = B.unpack <$> B.getLine

yesNo :: Bool -> String
yesNo True = "YES"
yesNo False = "NO"


-----  Union-find
type UnionFindT v m a = StateT (M.Map v (UnionFindVal v)) m a
newtype UnionFindVal v = UnionFindVal v

runUnionFindT :: (Monad m) => UnionFindT v m a -> m a
runUnionFindT = flip evalStateT $ M.empty

runUnionFind = runIdentity . runUnionFindT

ufFresh :: (Monad m, Ord v) => v -> UnionFindT v m ()
ufFresh v = modify $ M.insert v (UnionFindVal v)

ufClass :: (Monad m, Ord v) => v -> UnionFindT v m v
ufClass v = do
  (UnionFindVal pv) <- gets (M.! v)
  if v == pv
    then return v
    else do
      c <- ufClass pv
      modify $ M.insert v (UnionFindVal c)
      return c

ufUnify v w = do
  cv <- ufClass v
  cw <- ufClass w
  modify $ M.insert cw (UnionFindVal cv)
  return $ cv /= cw


Measured memory_bytes: 380
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int n,m,max,min;
		for(int i=0;i<7;i++){
			n = scan.nextInt();
			m = scan.nextInt();
			
			max = Math.max(n,m);
			min = Math.min(n,m);
			
			System.out.println(max-min);
		}
	}
}

Measured memory_bytes: 17312
#include<stdio.h>
#define N 1000001

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

  return i+1;
}

main(){
  int n, i, A[N], index;
  scanf("%d", &n);
  for( i = 0; i < n; i++ ){
    scanf("%d", &A[i]);
  }

  index = Partition( A, 0, n-1 );
  for( i = 0; i < n; i++ ){
    if( i > 0){
      printf(" ");
    }
    if( i == index){
      printf("[%d]", A[i]);
    }else{
      printf("%d", A[i]);
    }
  }
    printf("\n");
    return 0;
}

Measured memory_bytes: 1000
using System;

public class Test
{
	public static void Main( )
	{
		while( true ) {
			int n = int.Parse( Console.ReadLine() );
			if( 0 == n ) { break; }
			double[] nums = Array.ConvertAll( Console.ReadLine().Split( ' ' ), double.Parse );
			
			double sum = 0;
			for( var i=0; i<n; i++ ) {
				sum += nums[i];
			}
			var ave = sum/n;
			sum = 0;
			for( var i=0; i<n; i++ ) {
				sum += Math.Pow( nums[i]-ave, 2 );
			}
			Console.WriteLine( Math.Sqrt( sum/n ) );
		}
	}
}

Measured memory_bytes: 9472
#include<iostream> 
#include<bits/stdc++.h> 
using namespace std;
int main(){ 
	ios::sync_with_stdio(false); 
	cin.tie(0); 
	int N,W;
	cin>>N>>W;
	vector<int> w(N),v(N);
	for(int i=0;i<N;i++){ 
		cin>>w[i]>>v[i];
	}
	vector<vector<long long>> dp(N+1,vector<long long>(W+1,0LL)); 
	for(int i=1;i<=N;i++){ 
		for(int j=0;j<=W;j++){ 
			if(j-w[i-1]>=0){ 
				dp[i][j]=max(dp[i-1][j],v[i-1]+dp[i-1][j-w[i-1]]); 
			}else{ 
				dp[i][j]=dp[i-1][j];
			}
		}
	}
	cout<<dp[N][W];
	
	return 0;
} 



Measured memory_bytes: 80256
s = list(map(int, input().split()))
n = s[0]
a = s[1]
b = s[2]
if n % (a+b) < a:
    print(int(n / (a+b))*a+int(n % (a+b)))
else:
    print(int(n / (a+b))*a+a)

Measured memory_bytes: 3060
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        try(Scanner sc = new Scanner(System.in)){
            while (true){
                int a = sc.nextInt();
                String op = sc.next();
                int b = sc.nextInt();
                int answer;
                switch(op) {
                    case "+":
                        answer = a + b;
                        break;
                    case "-":
                        answer = a - b;
                        break;
                    case "*":
                        answer = a * b;
                        break;
                    case "/":
                        answer = a / b;
                        break;
                    default:
                        return;
                }
                System.out.println(answer);
                }
            }
    }
}



Measured memory_bytes: 26408
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Map<Integer, Set<Integer>> graph = new HashMap<>(n);
        for (int i = 1; i <= n; i++) {
            graph.put(i, new HashSet<>());
        }

        for (int r = 0; r < n - 1; r++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            graph.get(a).add(b);
            graph.get(b).add(a);
        }

        boolean[] claimedCache = new boolean[n + 1];
        LinkedList<List<Integer>> queue = new LinkedList<>();
        queue.addLast(Arrays.asList(1, 1));
        claimedCache[1] = true;
        queue.addLast(Arrays.asList(n, -1));
        claimedCache[n] = true;
        int fennecCount = 1;
        int snukeCount = 1;

        while (!queue.isEmpty()) {
            List<Integer> data = queue.removeFirst();
            int nodeId = data.get(0);
            int colorId = data.get(1);
            for (Integer neighbor : graph.get(nodeId)) {
                if (!claimedCache[neighbor]) {
                    claimedCache[neighbor] = true;
                    if (colorId == 1) {
                        fennecCount++;
                    }
                    else {
                        snukeCount++;
                    }
                    queue.addLast(Arrays.asList(neighbor, colorId));
                }
            }
        }

        System.out.println((fennecCount > snukeCount) ? "Fennec" : "Snuke");
    }
}


Measured memory_bytes: 119108
//Created by Aminul on 3/28/2020.

import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int x = in.nextInt(), y = in.nextInt();
        int a = in.nextInt(), b = in.nextInt(), c = in.nextInt();
       
      	PriorityQueue<Integer> red = new PriorityQueue<>();
        PriorityQueue<Integer> blue = new PriorityQueue<>();
        PriorityQueue<Integer> colorless = new PriorityQueue<>(Collections.reverseOrder());
       
      	for (int i = 0; i < a; i++) {
            red.add(in.nextInt());
        }
        for (int i = 0; i < b; i++) {
            blue.add(in.nextInt());
        }
        for (int i = 0; i < c; i++) {
            colorless.add(in.nextInt());
        }

        while (red.size() > x) red.poll();
        while (blue.size() > y) blue.poll();

        while (!colorless.isEmpty()) {
            int val = colorless.poll();
            if (red.size() == x && blue.size() == y) {
                if (red.peek() <= blue.peek() && red.peek() < val) {
                    red.poll();
                    red.add(val);
                } else if (blue.peek() <= red.peek() && blue.peek() < val) {
                    blue.poll();
                    blue.add(val);
                }
            } else if (red.size() < x) {
                red.add(val);
            } else if (blue.size() < y) {
                blue.add(val);
            }
        }

        long res = 0;
        for (int redVal : red) res += redVal;
        for (int blueVal : blue) res += blueVal;
        pw.println(res);
        pw.close();
    }

    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj));
    }
}

Measured memory_bytes: 101828