akhauriyash/Code-Regression huggingface dataset:
// -*- coding:utf-8-unix -*-

use std::cmp::*;
use std::collections::*;
use std::fs::File;
use std::io::prelude::*;
use std::io::*;
use std::vec;

const INF: i64 = 1223372036854775807;
const MEM_SIZE: usize = 202020;
const MOD: i64 = 1000000007;
use std::cmp::*;
use std::collections::*;
use std::io::stdin;
use std::io::stdout;
use std::io::Write;
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

#[allow(unused_macros)]
macro_rules! p {
    ([$($x:expr), *]) => {{
        let mut f = true;
        $(
            print!("{}{}", if f {""} else {" "}, $x);
            f = false;
        )*
78786    print!("\n");
    }};
    ($x:expr) => {{
        let mut f = true;
        for a in $x.iter() {
            print!("{}{}", if f {""} else {" "}, a);
            f = false;
        }
        print!("\n");
    }};
}
#[allow(dead_code)]
fn readii() -> (i64, i64) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<i64>().unwrap(),
        iter.next().unwrap().parse::<i64>().unwrap(),
    )
}
#[allow(dead_code)]
fn readuu() -> (usize, usize) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
    )
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn solve() {
    let (n, m) = readuu();
    let mut vec = vec![0; n];
    for i in 0..m {
        let (mut a, mut b) = readuu();
        a -= 1;
        b -= 1;
        vec[a] += 1;
        vec[b] += 1;
    }
    // p!(vec);
    let mut flg = true;
    for i in 0..n {
        if vec[i] % 2 == 1 {
            flg = false;
        }
    }
    if flg {
        println!("YES");
    } else {
        println!("NO");
    }

    return;
}
fn main() {
    solve()
}


Measured memory_bytes: 2236
#include<iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>

#define rep(j, n) for (int i = j; i < n; i++)
#define repd(j, n) for (int i = j; i > n; i--)

using namespace std;
typedef long long int ll;
typedef pair <int, int> P;
const long long INF = 0x3f3f3f3f3f3f3f3f;


int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n),dp(n);
	rep(0, n) {
		cin >> a[i];
		dp[i] = -1;
	}
	dp[0] = 0;
	rep(1, n) {
		ll minor=INF;
		if(k>=i){
			for(int j=1;j<=i;j++){
				minor = min(minor,dp[i - j] + abs(a[i] - a[i - j]));
			}
		}
		else {
			for (int j = 1; j <= k; j++) {
				minor = min(minor,dp[i - j] + abs(a[i] - a[i - j]));
			}
		}
		dp[i] = minor;
	}
	cout << dp[n - 1];
	return 0;
}

Measured memory_bytes: 1792
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x;
	scanf("%d",&x);
	long long n=2;
	for(int i=1;i<=x;i++)
	{
		n=2*n+2;
	}
	printf("%lld",n);
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,R;
  cin >> N >> R;
  int ans = 0;
  if (N < 10){
    ans = R + (10 - N) * 100;
  }
  else {
    ans = R;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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


int main(){
    ll N,R;
    cin>>N>>R;
    cout<<R + max(ll(0),(10-N)*100);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  char c;
  scanf("%c",&c);
  switch(c){
    case 'S':
      printf("Cloudy");
      break;
    case 'C':
      printf("Rainy");
      break;
    case 'R':
      printf("Sunny");
      break;
  }
  return(0);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999999
#define MOD 10007
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> LV;

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


// bool gousei(llong *x,llong *y){
//     if(*x<*y){
//         *y=x+y
//     }
// }

int main() {
	llong N;
	cin >> N;
    LV L(N);
    REP(i,N){
        cin >> L[i];
    }  
    sort(L.begin(),L.end(),greater<llong>());
    llong sigma=0;
    FOR(i,1,N){
        sigma+=L[i];
    }

    cout <<( L[0] < sigma ? "Yes" : "No") << endl;





}


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

using namespace std;

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

	string a, b, c;

	cin >> a >> b >> c;

	if (a.back() == b[0] && b.back() == c[0])
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N, Q;
    string S;
    
    cin >> N >> Q;
    cin >> S;
    
    vector<int> l(Q), r(Q);
    for (int i = 0; i < Q; i++) {
        cin >> l[i] >> r[i];
    }
    
    vector<int> sum(N + 1, 0);
    
    for ( int i = 0; i < N - 1; i++ ) {
        sum[i + 1] = sum[i];
        if ( S[i] == 'A' && S[i + 1] == 'C' ) {
            sum[i + 1]++;
        }
    }
    
    for ( int i = 0; i < Q; i++ ) {
        int ans = sum[r[i] - 1] - sum[l[i] - 1];
         cout << ans << endl;
    }
    
}


Measured memory_bytes: 2176
/*#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")  */
#include <bits/stdc++.h>
 
#define file ""
 
#define all(x) x.begin(), x.end()
 
#define sc second
#define fr first
 
#define pb push_back
#define mp make_pair

#define pss pair<line*, line*>
 
using namespace std;
using namespace __gnu_cxx;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
                                 
const ll inf = 1e18;
const int MOD = 1e9 + 7;

const int dx[] = {-1, +1, -2, +2, -2, +2, -1, +1};
const int dy[] = {-2, -2, -1, -1, +1, +1, +2, +2};

const int N = 5e5 + 5;

ll dp[1001][1001];

int main() {                
#ifdef Mask                                                         
  freopen(".in", 	"r", stdin);
  freopen(".out", "w", stdout);  
#endif
	ios_base :: sync_with_stdio(false);               
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  char a[n + 1][m + 1];
  for (int i = 1; i <= n; i++)
  	for (int j = 1; j <= m; j++)
  		cin >> a[i][j];	
  dp[1][1] = 1;
  for (int i = 1; i <= n; i++) {
   	for (int j = 1; j <= m; j++) {
   	 	if (i + 1 <= n && a[i + 1][j] == '.') 
   	 		dp[i + 1][j] += dp[i][j], dp[i + 1][j] %= MOD;
   	 	if (j + 1 <= m && a[i][j + 1] == '.')
   	 		dp[i][j + 1] += dp[i][j], dp[i][j + 1] %= MOD;
   	}
  }
  cout << dp[n][m];
	return 0;   
}



Measured memory_bytes: 9088
//Atcoder
import java.io.*;
import java.util.*;

public class Main {

	static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

        public int nextInt() {return Integer.parseInt(next());}

        public long nextLong() {return Long.parseLong(next());}

        public double nextDouble() {return Double.parseDouble(next());}

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

	public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        int[] a = new int[n];
        a[0] = sc.nextInt();
        for(int i=1;i<n;i++) a[i] = a[i-1] + sc.nextInt();
        int total = a[a.length-1];
        int min = Integer.MAX_VALUE;

        //pw.println(total);

        for(int i=0;i<n-1;i++) {
            min = Math.min(min, Math.abs(a[i] - (total - a[i])));
        }

        pw.println(min);
        pw.close();
    }
}


Measured memory_bytes: 22868
#include<stdio.h>
int main(void){
  int  s[5];
  int i;
  scanf("%d",s);
  s[1] = (int)s[0]/1000;
  s[2] = (int)s[0]/100-s[1]*10;
  s[3] = (int)s[0]/10-s[2]*10-s[1]*100;
  s[4] = (int)s[0]-s[3]*10-s[2]*100-s[1]*1000;
  for( i=0; i<4;i++){
    if(s[i] == s[i+1]){break;
    }
  }
  if(i==4)printf("Good");
  else printf("Bad");
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	

using namespace std;

int main() {
	char preP;
	cin >> preP;
	for (int i = 0; i < 3; ++i) {
		char p;
		cin >> p;
		if (p == preP) {
			cout << "Bad" << endl;
			return 0;
		}
		preP = p;
	}
	cout << "Good" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
#define MOD 1000000007
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> p;
typedef vector<int> vi;
set <int> st;
int n;
char s[100];
int tmps[43][43],ans=0;
bool firsts[4];

int main(int argc,char const* argv[])
{
  cin >> n;
  for(int i=0;i<n;i++)
    {
      cin >> s[i];
      if(s[i]=='G') firsts[0]=true;
      if(s[i]=='W') firsts[1]=true;
      if(s[i]=='Y') firsts[2]=true;
      if(s[i]=='G') firsts[3]=true; 
    }
  for(int i=0;i<4;i++)
    {
      if(firsts[i]) ans++;
    }
  if(ans==3) 
    {
      cout << "Three" << endl;
      return 0;
    }
  else if(ans==4)
    {
      cout << "Four" << endl;
      return 0;
    }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (long long i = l; i < r; i++)
using namespace std;
int mx[4]={0,1,0,-1},my[4]={1,0,-1,0};
signed main() {
	int h,w,ans=0;
	char c[1000][1000];
	queue<pair<pair<int,int>,int>> que;
	cin>>h>>w;
	rep(i,h){
		rep(j,w){
			cin>>c[i][j];
			if(c[i][j]=='#')que.push({{i,j},0ll});
		}
	}
	while(!que.empty()){
		pair<pair<int,int>,int> tu=que.front();que.pop();
		rep(i,4){
			if(tu.first.first+mx[i]<0||tu.first.first+mx[i]>=h||tu.first.second+my[i]<0||tu.first.second+my[i]>=w)continue;
			if(c[tu.first.first+mx[i]][tu.first.second+my[i]]=='.'){
				que.push({{tu.first.first+mx[i],tu.first.second+my[i]},tu.second+1});
				ans=tu.second+1;
				c[tu.first.first+mx[i]][tu.first.second+my[i]]='#';
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 13328
N = int(input())
nl = list(map(int, input().split()))

cnt = 0
flag = True
while flag:
    for i in range(N):
        if nl[i] % 2 == 0:
            nl[i] = nl[i] // 2
        else:
            flag = False
            break
    else:
        cnt += 1
print(cnt)


Measured memory_bytes: 3316
import Control.Applicative

main :: IO ()
main = print =<< solve <$> getLine <*> getLine

solve :: String -> String -> Int
solve n' k' = solve' 1 n k
  where n = read n' :: Int
        k = read k' :: Int

solve' :: Int -> Int -> Int -> Int
solve' c 0 k = c
solve' c n k = solve' (c + if c < k then c else k) (n-1) k

Measured memory_bytes: 508
// https://atcoder.jp/contests/abc018/tasks/abc018_4

#include <bits/stdc++.h>
using namespace std;
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e18;

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;
// 入力
// int H, W;
vector<vector<char>> field;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

ll nC2(ll n){
  return (ll)(n * (n-1) / 2);
}

int main() {

  int N;
  cin >> N;
  vector<string> _s(N);
  map<string, int> _m;
  REP(i, N){
    cin >> _s[i];
    sort(_s[i].begin(), _s[i].end());
    _m[_s[i]]++;
  }

  ll ans = 0;
  for( auto i = _m.begin(); i != _m.end() ; ++i ) {
      ans += nC2((ll)i->second);
      // cout << i->second << endl;
  }
  cout << ans << endl;

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

Measured memory_bytes: 18176
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;
typedef long long ll;

#define INF (long long)(10e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)

int main(void)
{
    int N, x, a[110];
    cin >> N >> x;
    REP(i, N) cin >> a[i];
    sort(a,a+N);
    int cnt = 0 ;
    REP(i, N) {
        if(x >= a[i]) {
	        x -= a[i];
	        cnt ++;
        }
//        cout << cnt << " " << x << endl;
    }
    if(x > 0 && cnt == N) cnt--;
    cout << cnt << endl; 
}


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


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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true){
		String[] arr = br.readLine().split(" ");
		int h = Integer.parseInt(arr[0]);
		int w = Integer.parseInt(arr[1]);
		
		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){
					System.out.print("#");
				}else if(j==0||j==w-1){
					System.out.print("#");
					
				}else{
					System.out.print(".");
				}
				
				
			}
			System.out.println("");
		}
		System.out.println("");
		
		}
		
	}
	


}

Measured memory_bytes: 30832
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int N;
    cin >> N;
 
    int mod = 0;
    int temp = N;
 
    while (temp > 0)
    {
        mod += temp % 10;
        temp /= 10;
    }
 
    if (N % mod == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
  
    return 0;
}

Measured memory_bytes: 256
use std::collections::VecDeque;

pub fn main() {
  fn read_line() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf);
    buf
  }
  fn read_tuple() -> (i32, i32) {
    let a: Vec<usize> = read_line()
      .split_whitespace()
      .map(|e| e.parse().unwrap())
      .collect();
    (a[0] as i32, a[1] as i32)
  }
  let (h, w) = read_tuple();
  let (ch, cw) = read_tuple();
  let (dh, dw) = read_tuple();

  let mut map: Vec<Vec<i32>> = Vec::new();
  for _ in 0..h {
    let mut row: Vec<i32> = Vec::new();
    let s: Vec<char> = read_line().trim().chars().collect();
    for j in 0..w {
      if s[j as usize] == '.' {
        row.push(-1);
      } else {
        row.push(-2);
      }
    }
    map.push(row);
  }

  let mv: Vec<(i32, i32)> = {
    let mut v = Vec::new();
    for i in -2..3 {
      for j in -2..3 {
        if !(i == 0 && j == 0) {
          v.push((i, j));
        }
      }
    }
    v
  };

  let mut deque: VecDeque<(i32, i32, i32)> = VecDeque::new();
  deque.push_front((ch, cw, 0));

  while !deque.is_empty() {
    let (cur_h, cur_w, point) = deque.pop_front().unwrap();
    if map[(cur_h as usize) - 1][(cur_w as usize) - 1] != -1 {
      continue;
    }
    map[(cur_h as usize) - 1][(cur_w as usize) - 1] = point;
    if cur_h == dh && cur_w == dw {
      println!("{}", point);
      return;
    }

    for next in &mv {
      let next_h = cur_h + next.0;
      let next_w = cur_w + next.1;
      if (next_h >= 1)
        && (next_w >= 1)
        && next_h <= h
        && next_w <= w
        && map[next_h as usize - 1][next_w as usize - 1] == -1
      {
        if next.0.abs() + next.1.abs() == 1 {
          deque.push_front((next_h, next_w, point));
        } else {
          deque.push_back((next_h, next_w, point + 1));
        }
      }
    }
  }
  println!("-1");
  return;
}

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

int main() {
    int n;
    cin >> n;
    int a[20];
    int x[20][20];
    int y[20][20];
    for(int i=0; i<n; ++i){
        cin >> a[i];
        for(int j=0; j<a[i]; ++j){
            cin >> x[i][j] >> y[i][j];
        }
    }
    int ans;
    ans=0;
    int ansans=0;
    for(int i=0; i<(1<<n); ++i){
        bool b;
        b=true;
        int count;
        count =0;
        for(int k=0; k<n; ++k){
            if(!((i >> k) & 1)) continue;
            for(int j=0; j<a[k]; ++j){
                if(((i>>(x[k][j]-1))&1)==y[k][j]){}
                else{
                    b=false;
                    break;
                }
            }
        }
        if(b){
        int countc; 
        countc=0;
        for(int j=0; j<n; ++j){
             if((i>>j)&1){
                 countc +=1;
             }
        }
        if(ansans<countc){
            ansans=countc;
        }  
        }  
    }
    cout << ansans << endl;
}


Measured memory_bytes: 256
n, m = map(int, input().split())

if n % 2 == 1:
    for i in range(m):
        print(1+i, n-1-i)
else:
    for i in range(m):
        if i % 2 == 0:
            print(n//2-i//2, n//2+1+i//2)
        else:
            print(1+i//2, n-1-i//2)

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

int main(){
  int a,b;
  cin>>a>>b;
  if(a*b==1){
    cout<<"Yes"<<endl;
  }

  else if(a*b==3){
    cout<<"Yes"<<endl;
  }

  else if(a*b==9){
    cout<<"Yes"<<endl;
  }

  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 384
package main

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

func solution(n, k int, h []int) int {
	if n <= k {
		return 0
	}
	sort.Ints(h)
	return sliceSum(h[:n-k])
}

func sliceSum(s []int) int {
	var sum int
	for _, v := range s {
		sum += v
	}
	return sum
}

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 10240*10240)

	var n, k int
	var err error
	fmt.Scan(&n, &k)
	h := make([]int, n)
	ss := strings.Split(readLine(reader), " ")
	for i := range ss {
		h[i], err = strconv.Atoi(ss[i])
		checkError(err)
	}
	fmt.Println(solution(n, k, h))
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}


Measured memory_bytes: 14720
#include <stdio.h>
#include <stdlib.h>
typedef long long ll;
int cmpint(const void *x, const void *y) {
	return *(int *)y - *(int *)x;
}
int main() {
	int n, a[200000];
	ll ans = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	qsort(a, n, sizeof(int), cmpint);
	int u[200000];
	for (int i = 0; i < n; i++) {
		u[i] = 2;
	}
	u[0] = 1;
	int pt = 0;
	for (int i = 1; i < n; i++) {
		if (u[pt] == 0) {
			pt++;
		}
		ans += a[pt];
		u[pt]--;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3304
import java.util.*;

public class Main {
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		int n, a;
		n = sc.nextInt();
		a = sc.nextInt();
		
		int i = n % 500;
		if(i == 0 || i <= a){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 23124
#include <iostream>

#define rep(i,n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar,val) memset(ar, val, sizeof(ar))
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

ll n2(int i){
  ll a = 1;
  while(i--) a *= 2;
  return a;
}
int main(void)
{
  ll a, b, ans;
  ll kurai[40][2] = {};
  cin >> a >> b;
  //LSB ... kurai[0][x]
  ll aa = a, bb = b;
  for(int i = 0; i != 40; i++){//rep(i, 40){
    kurai[i][0] = aa % 2;
    kurai[i][1] = bb % 2;
    aa /= 2;
    bb /= 2;
  }
//  for(int i = 39; i >= 0; i--) cout << kurai[i][0];cout << endl;
//  for(int i = 39; i >= 0; i--) cout << kurai[i][1];cout << endl;
  rep(i, 40){
    ll k = 0;
    if(i == 0){
      if(a % 2 == 0 && b % 2 == 0) k = (b - a) / 2;
      else k = (b - a) / 2 + 1;
    }else{
      if(kurai[i][0] == 0 && kurai[i][1] != 0){
        rep(j, i) k += n2(j) * kurai[j][1];
        k += 1;
      }
      if(kurai[i][0] != 0 && kurai[i][1] == 0){
        rep(j, i) k -= n2(j) * kurai[j][0];
        k += n2(i);
      }
      if(kurai[i][0] != 0 && kurai[i][1] != 0){
        if((b - a) < n2(i)) k = b - a + 1;
        else{
          rep(j, i) k += n2(j) * kurai[j][1];
          k += 1;
          rep(j, i) k -= n2(j) * kurai[j][0];
          k += n2(i);
        }
      }
    }
    if(k % 2 != 0) ans += n2(i);
//    cout << k << " ";
  }
//  cout << endl;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vec             vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define inf             1e18
#define no_of_test(x)        int x; cin>>x; while(x--)
const int mod = 1e9 + 7;
int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//	no_of_test(x)
	{
			string a,b;
			cin>>a>>b;
			int p=a.length();
			int q=b.length();
			int ans=1e8;
			for(int i=0;i<=p-q;i++)
			{
              int cnt=0;
			  for(int j=0;j<q;j++)
			  {
				  if(a[i+j]!=b[j])
				  cnt++;
			  }
			  ans=min(ans,cnt);
			}
			cout<<ans<<"\n";
	}
	return 0;
}

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

int main()
{      
    long long n;
    string S, T;
    cin >> S >> T;
    
    int len = S.length();
    n = 0;
    for(int i=0; i<len; i++){
        if(S.substr(i, 1) != T.substr(i, 1)){
            n++;
        }
    }
    
    cout << n << endl;
      
}


Measured memory_bytes: 3872
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun solve() {
    val (N, A, B, C) = rd.readIntArray()
    val L = IntArray(N)
    for (i in 0 until N) {
        L[i] = rd.readInt()
    }

    var ans = INF

    fun dfs(n: Int, a: Int, b: Int, c: Int, mp: Int) {
        if (n >= N) {
            if (a > 0 && b > 0 && c > 0) {
                ans = min(ans, mp + abs(a - A) + abs(b - B) + abs(c - C))
            }
            return
        }

        for (i in 0 until 4) {
            when (i) {
                0 -> {
                    dfs(n+1, a+L[n], b, c, if (a>0) mp+10 else mp)
                }
                1 -> {
                    dfs(n+1, a, b+L[n], c, if (b>0) mp+10 else mp)
                }
                2 -> {
                    dfs(n+1, a, b, c+L[n], if (c>0) mp+10 else mp)
                }
                3 -> {
                    dfs(n+1, a, b, c, mp)
                }
            }
        }
    }

    dfs(0, 0, 0, 0, 0)

    println(ans)
}


//val rd = debug.Reader("abc", "119", "c", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!!
    } catch (e: Exception) { throw e }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
const val EPS = 1e-9; fun DBLEQ(a: Double, b: Double): Boolean {return abs(a - b) < EPS}
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long)
typealias ALI = ArrayList<Int>
fun <T>edge(V: Int): Array<ArrayList<T>> { return Array(V){ArrayList<T>()} }
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}


Measured memory_bytes: 38356
import scala.collection.mutable

object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  val n = readLine.trim.toInt
  val time = Array.tabulate(n){_ ⇒
    val Array(a, b) = readLine.trim.split(' ').map(_.toInt)
    (a, b)
  }.sortBy(_._2).toList

  println(
    searchMax(time)
  )
  def searchMax(times: List[(Int, Int)], current: Int = 0, queue: mutable.PriorityQueue[Int] = mutable.PriorityQueue()): Int = {
    times match {
      case Nil ⇒ 0
      case (diff, limit)::t if current + diff <= limit ⇒
        queue.enqueue(diff)
        searchMax(t, current + diff, queue) + 1
      case (diff, limit)::t if queue.nonEmpty && queue.head > diff ⇒
        val remove = queue.dequeue()
        queue.enqueue(diff)
        searchMax(t, current - remove + diff, queue)
      case _::t ⇒ searchMax(t, current, queue)
    }
  }

  implicit class Extenion[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}


Measured memory_bytes: 44128
a, b, c, x, y = map(int, input().split())
if min(a + b, 2 * c) == 2 * c:
    if x >= y:
        print(min(2 * c * y + (x - y) * a, 2 * c * x))
    
    else:
        print(min(2 * c * x + (y - x) * b, 2 * c * y))

else:
    print(x * a + y * b)

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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    int a, b;
    string S, T, U;
    cin >> S >> T >> a >> b >> U;

    if(U == S)
        a--;
    else
        b--;

    cout << a << " " << b << "\n";
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	// "bufio"
	// "strings"
	// "os"
	// "strconv"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	// fmt.Printf("A %d, B %d\n", a, b)

	if a <= 8 && b <= 8 {
		fmt.Println("Yay!")
	} else {
		fmt.Println(":(")
	}
}

Measured memory_bytes: 512
MOD = 10 ** 9 + 7
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)

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

factorial = [1]
for i in range(1, N + 1):
    factorial.append(factorial[-1] * i % MOD)

inv_factorial = [-1] * (N + 1)
inv_factorial[-1] = pow(factorial[-1], MOD-2, MOD)
for i in reversed(range(N)):
    inv_factorial[i] = inv_factorial[i + 1] * (i + 1) % MOD

deg = [0] * N
parent = [0] * N
dp = [0] * N
ans = [0] * N
cnt_leaf = [0] * N

def dfs(v,p = -1):
    deg[v] = len(G[v])
    dp[v] = [0] * deg[v]
    res = 1
    cnt = 0
    for i,e in enumerate(G[v]):
        if e == p:
            parent[v] = i
            continue
        a,b = dfs(e,v)
        dp[v][i] = a*inv_factorial[b]%MOD
        cnt += b
        res *= dp[v][i]
        res %= MOD
    res *= factorial[cnt]%MOD
    cnt_leaf[v] = cnt
    return res,cnt + 1

def bfs(v,res_p = 0,p = - 1):
    if p != -1:
        dp[v][parent[v]] = res_p
    dpl = [1] * (deg[v] + 1)
    for i,x in enumerate(dp[v]):
        dpl[i + 1] = dpl[i]*x%MOD
    dpr = [1] * (deg[v] + 1)
    for i in range(deg[v] - 1,-1,-1):
        dpr[i] = dpr[i + 1]*dp[v][i]%MOD
    
    ans[v] = dpr[0]*factorial[N - 1]%MOD
    for i,e in enumerate(G[v]):
        if e == p:
            continue
        bfs(e,dpl[i]*dpr[i + 1]*pow(N - cnt_leaf[e] - 1,MOD - 2,MOD)%MOD,v)
    
dfs(0)
bfs(0)
print('\n'.join(map(str,ans)))


Measured memory_bytes: 219820
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(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; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

const int MOD = 1000000007;

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

signed main() {
    SS(ll,x);
    for(ll i=1;i<=50000;i++){
        if(floor(i*1.08)==x){
            p(i);
            return 0;
        }
    }
    p(":(");
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<list>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
#define MK make_pair
const ll E=1e18+7;
const ll MOD=1000000007;
const ll mod=998244353;

vector<ll> A={1,100,10000,1000000,100000000,10000000000,1000000000000,100000000000000};

vector<ll> string_hash(string s){
    vector<ll> ret;
    ll sum=0;
    for(ll i=0;i<s.size();i++){
        sum+=A[i%8]*(s[i]-'a'+1);
        if(i%8==7 || i==s.size()-1){ret.push_back(sum); sum=0;}
    }
    return ret;
}



int main(){
    typedef vector<ll> hash;
    typedef pair<hash,hash> Pstring;
    map<Pstring,ll> M;
    ll n;
    cin>>n;
    string s1,s2;
    for(int i=0;i<n;i++){
        char c;
        cin>>c;
        s1.push_back(c);
    }
    for(int i=0;i<n;i++){
        char c;
        cin>>c;
        s2.push_back(c);
    }
    reverse(s2.begin(),s2.end());
    ll k=1<<n;
    k--;
    while(1){
        string a,b;
        for(int i=0;i<n;i++){
            if(k>>i&1){a.push_back(s1[i]);}
            else{b.push_back(s1[i]);}
        }
        hash A=string_hash(a);
        hash B=string_hash(b);
        M[{A,B}]++;
        if(k==0){break;}
        k--;
    }
    ll ans=0;
    k=1<<n;
    k--;
    while(1){
        string a,b;
        for(int i=0;i<n;i++){
            if(k>>i&1){a.push_back(s2[i]);}
            else{b.push_back(s2[i]);}
        }
        hash A=string_hash(a);
        hash B=string_hash(b);
        ans+=M[{A,B}];
        if(k==0){break;}
        k--;
    }
    cout<<ans<<endl;
    
    
    return 0;
}

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

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

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

    vector<int> p2 = p;
    sort(p2.begin(),p2.end());

    int cnt = 0;
    for ( int i = 0 ; i < n ; i++ ){
        if ( p.at(i) != p2.at(i)) cnt++;
    }

    if ( cnt == 0 || cnt == 2 ) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
N = int(input())

AlList = {0:'Z', 1:'A', 2:'B', 3:'C', 4:'D', 5:'E', 6:'F', 7:'G', 8:'H', 9:'I', 10:'J', 11:'K', 12:'L', 13:'M', 14:'N', 15:'O', 16:'P', 17:'Q', 18:'R', 19:'S', 20:'T', 21:'U', 22:'V', 23:'W', 24:'X', 25:'Y', 26:'Z'}

result = ''

while 'true':
    if N > 26:
        tmp = N % 26
        result = AlList[tmp] + result
        N //= 26
        if tmp == 0:
            N -= 1
    else:
        result = AlList[N] + result
        break
print(result.swapcase())
    

Measured memory_bytes: 9220
#include<bits/stdc++.h>
using namespace std;
int dp[3002][3002];

int main()
{
        string x,y;cin>>x>>y;
        int n=x.length();
        int m=y.length();
        memset(dp,-1,sizeof(dp));
        
        for(int i=0;i<=m;i++) dp[0][i]=0;
        for(int i=0;i<=n;i++) dp[i][0]=0;
        
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                if(x[i-1]==y[j-1])
                dp[i][j]=1+dp[i-1][j-1];
                else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
        string ans;
      while(m>0 && n>0)
      {
          if(x[n-1]==y[m-1])
          {
              ans+=x[n-1];
              n--,m--;
          }
          else if(dp[n-1][m] > dp[n][m-1]) n--;
          else m--;
      }
      for(int i=ans.length()-1;i>=0;i--) cout<<ans[i];
}

Measured memory_bytes: 35456
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import math
from functools import lru_cache


@lru_cache(maxsize=None)
def get_gcd(a, b):
    return math.gcd(a, b)


def main():
    k = int(input().strip())
    sum = 0
    for a in range(1, k + 1):
        for b in range(1, k + 1):
            a_, b_ = (a, b) if a < b else (b, a)
            a_b_ = get_gcd(a_, b_)
            for c in range(1, k + 1):
                sum += get_gcd(a_b_, c) if a_b_ < c else get_gcd(c, a_b_)
    print(sum)


if __name__ == '__main__':
    main()


Measured memory_bytes: 11452
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;

int p[100001];

void ext(int i, int j) {
    int t = p[i];
    p[i] = p[j];
    p[j] = t;
}

int main() {
    int n;
    cin >> n;
    
    REP(i,n) cin >> p[i+1];
    int cnt = 0;
    for (int i = 1; i <= n-1; i++) {
        if (p[i] == i) {
            ext(i,i+1);
            cnt++;
        }
    }
    if (p[n] == n) cnt++;
    cout << cnt << endl;
}


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

static const int INF = 1001001001;
static const int MAX = 100000;

int n;
vector<int> a[MAX];
int p[MAX];

void bfs(int s){
    queue<int> q;
    int d[n];
    rep(i,n) d[i] = INF;
    d[s] = 0;
    q.push(s);
    
    while( !q.empty() ) {
        int u; u = q.front(); q.pop();
        rep(i,a[u].size()){
            int v = a[u][i];
            if(d[v] != INF) continue;
            d[v] = d[u] + 1;
            p[v] = u + 1;
            q.push(v);
        }
    }
    bool ok = true; rep(i,n) if (d[i] == INF)  ok = false;
    if(ok){
        cout << "Yes" << endl;
        for( int i = 1; i < n; i++) cout << p[i] << endl;
    }
    else cout << "No" << endl;
}

int main(){
    int m;
    cin >> n >> m;
    rep(i,m) {
        int s, t; cin >> s >> t;
        s--, t--;
        a[s].push_back(t); a[t].push_back(s);        
    }
    bfs(0);
    return 0;
}

Measured memory_bytes: 10848
//AtCoder Beginner Contest 066 C
#include <iostream>
#include <string>
#include <deque>

using namespace std;


int main() {
	
	int n;
	cin >> n;
	int a[200010];

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

	deque<int>que;
	int flag = 0;
	if ((n - 1)% 2 != 0) {//最後が奇数なら奇数はすべて前に挿入
		flag = 1;
	}
	for (int i = 0; i < n;i++) {
		if (flag == 1) {
			if (i % 2 != 0) que.push_front(a[i]);//奇数なら前に
			else que.push_back(a[i]);//偶数なら後ろに
		}
		else {
			if (i % 2 == 0) que.push_front(a[i]);//偶数なら前に
			else que.push_back(a[i]);//奇数なら後ろに

		}
	}

	for (int i = 0; i < que.size();i++) {
		if (i == n) cout << que[i] << endl;
		else cout << que[i] << " ";
	}

	return 0;
}

Measured memory_bytes: 3840
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
#include <string>
#include <math.h>
#include <stdint.h>
#include <bitset>
#include <iomanip>

using namespace std;

int main() {
  long int N;
  cin >> N;

  vector<long int> P(N);
  for (long int i=0; i<N; i++) {
    cin >> P[i];
  }

  long int tmp_min = 100000000;
  long int result = 0;
  for (long int i=0; i<N; i++) {
    if (tmp_min > P[i]) {
      result++;
      // cout << i << " " << P[i] << " " << tmp_min << endl;
      tmp_min = P[i];
    }
  }
  /*
  long int result = N;
  for (long int i=0; i<N; i++) {
    for (long int j=0; j<i; j++) {
      if (P[j] < P[i]) {
        result--;
        break;
      }
    }
  }
  */

  cout << result << endl; 
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 998244353
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, a[310];
int d[310][90010];
int d2[310][90010];
int ans = 1;
int cnt;

signed main() {
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i], ans = (ans * 3) % mod, cnt += a[i];
	d[0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= 90000; j++)d[i + 1][j] = d[i][j] * 2 % mod;
		for (int j = 0; j <= 90000 - a[i]; j++)d[i + 1][j + a[i]] = (d[i + 1][j + a[i]] + d[i][j]) % mod;
	}
	d2[0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= 90000; j++)d2[i + 1][j] = d2[i][j];
		for (int j = 0; j <= 90000 - a[i]; j++)d2[i + 1][j + a[i]] = (d2[i + 1][j + a[i]] + d2[i][j]) % mod;
	}
	for (int i = (cnt - 1) / 2 + 1; i <= cnt; i++)ans = (ans - 3 * d[n][i] + mod) % mod;
	if (cnt % 2 == 0)ans = (ans + 3 * d2[n][cnt / 2]) % mod;
	cout << ans << endl;
}

Measured memory_bytes: 425472
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
const double PI = acos(-1);
 
int lis(vector<int> &v) {
	vector<int> ans(v.size(), INF);
	for (int i = 0; i < v.size();i++) {
		(*lower_bound(ans.begin(), ans.end(), v[i])) = v[i];
	}
	return lower_bound(ans.begin(), ans.end(), INF) - ans.begin();
}
 
int main() {
	LL x1, x2, y1, y2;
	int n;
	cin >> x1 >> y1 >> x2 >> y2;
	cin >> n;
	if (x1 > x2) {
		swap(x1, x2);
		swap(y1, y2);
	}
	vector<pair<int, int>> xy;
	int x, y;
	for (int i = 0; i < n; i++) {
		cin >> x >> y;
		xy.emplace_back(x, y);
	}
	int sign = (y1 - y2) > 0 ? -1 : 1;
	vector<pair<int, int>> in;
	for(int i=0;i<n;i++){
		if (min(x1, x2) <= xy[i].first&&xy[i].first <= max(x1, x2) && min(y1, y2) <= xy[i].second&&xy[i].second <= max(y1, y2)) {
			in.emplace_back(xy[i]);
		}
	}
	sort(in.begin(), in.end());
	vector<int> temp;
	for (int i = 0; i < in.size();i++) {
		temp.push_back(sign*in[i].second);
	}
	int m = lis(temp);
	double ans = 100 * (abs(x1 - x2) + abs(y1 - y2));
	if (m - 1 >= abs(x1 - x2) || m - 1 >= abs(y1 - y2)) {
		ans += (10 * PI - 20) - (20 - 5 * PI) * (m - 1);
	}
	else {
		ans -= (20 - 5 * PI) * m;
	}
	cout << fixed << setprecision(20) << ans << endl;
}

Measured memory_bytes: 5232
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

using Weight = int;
using Flow = int;
struct Edge {
	int s, d; Weight w; Flow c;
	Edge() {};
	Edge(int s, int d, Weight w = 1) : s(s), d(d), w(w), c(w) {};
	bool operator<(const Edge &e)const { return w < e.w; }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

inline ostream &operator<<(ostream &os, const Edge &e) { return (os << '(' << e.s << ", " << e.d << ", " << e.w << ')'); }

void add_edge(Graph &g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int s, int d, Weight w = 1) { g[s].emplace_back(s, d, w); }


struct UnionFind {
	vector<int> parent;
	int size;
	UnionFind(int n) :parent(n, -1), size(n) {}
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x == y)return false;
		if (size_of(x) < size_of(y))swap(x, y);
		parent[x] += parent[y]; parent[y] = x; size--;
		return true;
	}
	bool same(int x, int y) { return root(x) == root(y); }
	int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }
	int size_of(int x) { return -parent[root(x)]; }
};

//????°???¨?????¨ (Minimum Spanning Tree)
//Kruskal O(|E|log|E|)
pair<Weight, Edges> kruskal(const Graph &g) {
	int n = g.size();
	UnionFind uf(n);
	Edges es;
	for (int i = 0; i < n; i++)
		for (auto &e : g[i])
			es.emplace_back(e);
	sort(es.begin(), es.end());
	Weight total = 0;
	Edges mst;
	for (auto &e : es)
		if (!uf.same(e.s, e.d)) {
			uf.unite(e.s, e.d);
			mst.push_back(e);
			total += e.w;
		}
	return make_pair(total, mst);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int V, E; cin >> V >> E;
	Graph g(V);
	rep(i, 0, E) {
		int s, t, w; cin >> s >> t >> w;
		add_edge(g, s, t, w);
	}
	auto res = kruskal(g);
	cout << res.first << endl;
	return 0;
}

Measured memory_bytes: 12340
# coding: utf-8
"""Fighting over Candies

@author: hijiri.n
@modified: 11-19-2016

"""

c_in = list(map(int, input().split()))

def solve(candies):

    ach = sum(candies) / 2
    return ["No", "Yes"][ach in candies]

print(solve(c_in))


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

int main(){
    int a;
    cin>>a;
    long long arr[a];
    for(int i=0;i<a;i++){
        cin>>arr[i];
    }
    long long sum=0;
    for(int i=0;i<a;i++){
        for(int j=i+1;j<a;j++){
            sum+=arr[i]*arr[j];
        }
    }
    cout<<sum<<"\n";
        return 0;
}

Measured memory_bytes: 256
from sys import stdin
input = stdin.buffer.readline

a, b, c = map(int, input().split())
k = int(input())
cnt = 0
while b <= a:
	cnt += 1
	b *= 2
while c <= b:
	cnt += 1
	c *= 2
if cnt <= k:
	print('Yes')
else:
	print('No')


Measured memory_bytes: 61868
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n, i;
    vector <int> v;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        int x;
        
        scanf("%d", &x);
        
        v.push_back(x);
    }
    
    sort(v.begin(), v.end());
    
    if (v[0] == v[n - 1]) {
        if (v[0] <= n / 2 || v[0] == n - 1) {
            puts("Yes");
        } else {
            puts("No");
        }
    } else if (v[0] + 1 == v[n - 1]) {
        int c;
        
        for (i = 0; i < n; i++) {
            if (v[i] != v[i + 1]) break;
        }
        
        c = i + 1;
        
        if (v[0] >= c && n - c >= (v[0] - c + 1) * 2) {
            puts("Yes");
        } else {
            puts("No");
        }
    } else {
        puts("No");
    }
    
    return 0;
}


Measured memory_bytes: 892
#include <iostream>

using namespace std;
#define min(a, b) ((a) < (b)? (a):(b))
#define max(a, b) ((a) > (b)? (a):(b))
#define abs(a) ((a) < (0)? -(a):(a))

int main() {
	int W, a, b; cin >> W >> a >> b;
	if(a + W < b)
	    cout << b-(a+W) << endl;
	else if(a > b + W)
	    cout << a-(b+W) << endl;
	else
	    cout << 0 << endl;
}


Measured memory_bytes: 256
import itertools
import numpy as np
import math

L = []
A = 0
t = 0
N = int(input())
for i in range(N):
    x, y = list(map(int, input().split()))
    L.append([x, y])
# print(L[1][0])
K = np.array(L)
for i in itertools.permutations(L):
    np.array(i)
    for k in range(N-1):
        u = math.sqrt((i[k][0]-i[k+1][0])**2+(i[k][1]-i[k+1][1])**2)
        A = A + u
    t += 1
B = A/t
print(B)

Measured memory_bytes: 21944