akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

struct UnionFind {
    roots: Vec<usize>,
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        let mut roots = vec![];
        for i in 0..n {
            roots.push(i);
        }
        UnionFind { roots: roots }
    }
    fn find(&mut self, i: usize) -> usize {
        if self.roots[i] == i {
            i
        } else {
            let tmp_i = self.roots[i];
            self.roots[i] = self.find(tmp_i);
            self.roots[i]
        }
    }
    fn unite(&mut self, i: usize, j: usize) {
        let root_i = self.find(i);
        let root_j = self.find(j);
        self.roots[root_i] = root_j;
    }
}

fn main() {
    input! {
        n: usize,
        m: usize,
        ab:[(usize1, usize1); m],
    }
    let mut inconvenience = n * (n - 1) / 2;
    let mut union_find = UnionFind::new(n);
    let mut ans = vec![];
    let mut sizes = vec![1; n];
    for &(a, b) in ab.iter().rev() {
        ans.push(inconvenience);
        let root_a = union_find.find(a);
        let root_b = union_find.find(b);
        if root_a != root_b {
            let size_a = sizes[root_a];
            let size_b = sizes[root_b];
            union_find.unite(a, b);
            let root_a = union_find.find(a);
            sizes[root_a] = size_a + size_b;
            inconvenience -= size_a * size_b;
        }
    }
    for i in ans.iter().rev() {
        println!("{}", i);
    }
}


Measured memory_bytes: 11516
#include <bits/stdc++.h>
using namespace std;
 
constexpr int INF = 1e9;
 
int main() {
    int H, W;
    cin >> H >> W;
    vector<string> v(H);
    for(int i = 0; i < H; ++i) {
        cin >> v[i];
    }
    vector<string> a(H, string(W, '#')), b(H, string(W, '.'));
    for(int i = 1; i < H - 1; ++i) {
        for(int j = 1; j < W - 1; ++j) {
            a[i][j] = (i & 1 ? '.' : '#');
            b[i][j] = (i & 1 ? '#' : '.');
        }
    }
    for(int i = 1; i < H - 1; ++i) {
        bool drawed = false;
        for(int j = 1; j < W - 1; ++j) {
            if(v[i][j] == '#') {
                (i & 1 ? a : b)[i][j] = '#';
                drawed = true;
            }
        }
        if(i % 2 == 0 && !drawed) {
            bool f = false;
            for(int j = 1; j < W - 1; ++j) {
                if(a[i - 1][j] == '.' || a[i + 1][j] == '.') {
                    a[i][j] = '.';
                    b[i][j] = '#';
                    f = true;
                    break;
                }
            }
            if(!f) {
                a[i][1] = '.';
                b[i][1] = '#';
            }
        }
    }
    for(int i = 0; i < H; ++i) {
        cout << a[i] << endl;
    }
    cout << endl;
    for(int i = 0; i < H; ++i) {
        cout << b[i] << endl;
    }
    
    //cout << "debug: " << endl;
    //for(int i = 0; i < H; ++i) {
    //    for(int j = 0; j < W; ++j) {
    //        if(a[i][j] == '#' && a[i][j] == b[i][j]) {
    //            cout << '#';
    //        } else {
    //            cout << '.';
    //        }
    //    }
    //    cout << endl;
    //}
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s(3,'0'),ans;
  cin >> s.at(0) >> s.at(1) >> s.at(2);
  int num = stoi(s);
  if(num % 4 == 0){
    ans = "YES";
  }else{
    ans = "NO";
  }
  cout << ans << endl;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
int a[maxn],b[maxn];
int tot;

int main(){
    int n;cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        tot^=a[i];
    }
    for(int i=0;i<n;i++){
        b[i]=a[i]^tot;
        cout<<b[i]<<' ';
    }
    return 0;
}

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

typedef long long ll;

int main(void){
    ll N, D;
    cin >> N >> D;
    
    int cnt = 0;
    for(int i = 0; i < N; i++){
        ll X, Y;
        cin >> X >> Y;
        
        if(sqrt(X*X + Y*Y) <= D){
            cnt++;
        }
    }
    
    cout << cnt << endl;
}

Measured memory_bytes: 3672
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Arrays;

public class Main {
	static int N;
	static long[] A;
	static long MAX = (long) 1e18;
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		read();
	}

	private static void read() throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		N = Integer.parseInt(br.readLine());
		String[] word = br.readLine().split("\\s+");
		A = new long[N];
		for (int i = 0; i < N; i++) {
			A[i] = Long.valueOf(word[i]);
		}
		Arrays.sort(A);
		BigInteger res = BigInteger.ONE;
		for (int i = 0; i < N; i++) {
			res = res.multiply(BigInteger.valueOf(A[i]));
			if ( res.compareTo(BigInteger.valueOf(MAX) ) > 0 ){
				System.out.println(-1);
				br.close();
				return;
			}

		}
		System.out.println(res);
		br.close();
	}

}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    double R; cin >> R;
    cout << fixed << setprecision(10) <<  2*3.1415*R << endl;
    return 0;
}

Measured memory_bytes: 3764
h, w = map(int, input().split())
s = [input() for _ in range(h)]

for i in range(h):
    ans = ''
    for j in range(w):
        if s[i][j] == '.':
            n = 0
            for x in [-1, 0, 1]:
                for y in [-1, 0, 1]:
                    xx = x + i
                    yy = y + j
                    if (x != 0 or y != 0) and xx >= 0 and xx <= h - 1 and yy >= 0 and yy <= w - 1:
                        if s[xx][yy] == '#':
                            n += 1
            ans += str(n)
        else:
            ans += '#'
    print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll a,b;
    cin>>a>>b;
    if(a>8||b>8)
      cout<<":("<<endl;

    else
        cout<<"Yay!"<<endl;

    
    
}
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = pow(10, 9) + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

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

  priority_queue<ll> Q;
  for (ll i = 0; i < N; i++)
  {
    ll A;
    cin >> A;
    Q.push(A);
  }

  for (ll i = 0; i < M; i++)
  {
    ll q = Q.top();
    Q.pop();
    Q.push(q / 2);
  }

  ll ans = 0;
  for (ll i = 0; i < N; i++)
  {
    ans += Q.top();
    Q.pop();
  }

  cout << ans << endl;
}

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

int N,A,B,C,X;
int Y[111];
bool F[111];
int main(){
  while(  cin >> N >> A >> B >> C >> X && (N||A||B||C||X) ){
    for(int i=0;i<N;i++){
      cin >> Y[i];
    }
    memset(F,0,sizeof(F));
    int jd = 0;
    for(int i=0;i<=10000;i++){
      if( Y[jd] == X ) F[jd++] = true;

      X = (A * X + B ) % C;

      if( jd == N ){
	cout << i << endl; break;
      }
      if( i == 10000 ) cout << -1 << endl;
    }
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;



int main()
{
    double l;
    cin >> l;
    printf("%.8lf",(l/3)*(l/3)*(l/3));
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ld eps = 1e-9;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n, m, l; cin >> n >> m >> l;
  vi k(n), s(m);
  for(int i=0;i<n;++i) {
    cin >> k[i];
    k[i]--;
  }
  sort(k.begin(), k.end());
  for(int i=0;i<m;++i) {
    cin >> s[i];
  }
  vll su(m+1);
  for(int i=0;i<m;++i) {
    su[i+1] = su[i] + s[i];
  }
  vvll dp(n, vll(n, LINF));
  dp[0][0] = 0;
  for(int i=0;i<n-1;++i) {
    for(int j=0;j<n;++j) {
      if(dp[i][j] == INF) continue;
      dp[i+1][i] = min(dp[i+1][i], dp[i][j] + (su[k[i+1]+1] - su[k[j]]) / l);
      dp[i+1][j] = min(dp[i+1][j], dp[i][j] + (su[k[i+1]+1] - su[k[i]]) / l);
    }
  }
  ll ans = LINF;
  for(int i=0;i<n;++i) {
    ans = min(ans, dp[n-1][i] + (su[k[n-1]+1] - su[k[i]]) / l);
  }
  cout << ans << endl;
}



Measured memory_bytes: 35332
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  vector<int> m(N);
  rep(i, N) {
    cin >> m[i];
    X -= m[i];
  }

  std::sort(m.begin(), m.end());

  int sum = N + X / m[0];
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 384
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	static Main instance = new Main();

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値取得
		long N = scan.nextLong();

		//WK変数
		Map<Long, Integer> map = new HashMap<>();

		//演算
		long x = N;
		long result = 0L;

		for (long i = 2L; i * i<= x;) {
			if (x % i == 0L) {

				if (map.containsKey(i)) {
					map.put(i, map.get(i) + 1);
				} else {
					map.put(i, 1);
				}
				x /= i;
			} else {
				i++;
			}
		}

		if (x != 1) {
			if (map.containsKey(x)) {
				map.put(x, map.get(x) + 1);
			} else {
				map.put(x, 1);;
			}
		}

		for (Map.Entry<Long, Integer> entry: map.entrySet()) {

			int wk = entry.getValue();

			int i = 1;

			while (i * (i + 1) / 2 <= wk) {
				i++;
			}

			result += (i - 1);
		}


		//結果出力
		System.out.println(result);
	}
}

Measured memory_bytes: 36228
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) ll((a).size())
#define out(a) cout<<(a)<<endl;
const ll inf=1e9;
const int MAX = 510000;
const ll MOD = 998244353;

inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}

int main(){
  ll n,m,k;cin>>n>>m>>k;
  rep(i,0,m+1){
    rep(j,0,n+1){
      if(n*i+m*j-i*j*2==k){
        cout<<"Yes"<<endl;return 0;
      }
    }
  }
  cout<<"No"<<endl;
}






Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) x.begin(),x.end()
#define db(x) cout<<#x<<"="<<x<<endl
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, n, m) for(int i = n; i >= m; i--)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;

int main(){

  string S;
  cin >> S;

  S+="R";

  int slen=S.length();

  int ans[slen]={};

  int ctodd=0;
  int cteven=0;
  int ri=-1;
  int li=-1;
  char nowc;

  rep(i,slen){
    char c;
    c=S[i];
    if(i==0){
      nowc = 'R';
      cteven++;
      continue;
    }
    if(nowc=='R'){
      if(c=='R'){
        if(i%2==0){
          cteven++;
        }
        else ctodd++;
        continue;
      }

      if(c=='L'){
        ri=i-1;
        li=i;

        if(i%2==0){
          cteven++;
        }
        else ctodd++;
        nowc='L';
        continue;

      }

    }
    if(nowc=='L'){
      if(c=='R'){
        if(ri%2==0) swap(ctodd,cteven);
        ans[ri]=ctodd;
        ans[li]=cteven;

        ctodd=0;
        cteven=0;

        if(i%2==0){
          cteven++;
        }
        else ctodd++;

        nowc='R';
        continue;

      }
      if(c=='L'){
        if(i%2==0){
          cteven++;
        }
        else ctodd++;
        continue;
      }

    }

  }

  rep(i,slen-1){
    std::cout << ans[i];
    if(i!=slen-2) std::cout << " ";
  }
  return 0;
}


Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(A: int, B: int, C: int):
    print(YES if (A+B) >= C else NO)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <utility>
#include <tuple>

using namespace std;

int main()
{
    int a, b;
    vector<vector<int>> v(5);
    for (int i=0; i<3; ++i){
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    int check1 = 0;
    int check2 = 0;
    for (int i=1; i<=4; ++i){
        if(v[i].size() == 1){
            check1++;
        }
        else if(v[i].size() == 2){
            check2++;
        }
    }
    if(check1 == 2 && check2 == 2){
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 888
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = []

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            ans.append(500*i + 100*j + 50*k)

print(ans.count(x))

Measured memory_bytes: 8276
N = input()
if N == "SAT":
  print("1")
elif N == "SUN":
  print("7")
elif N == "MON":
  print("6")
elif N == "TUE":
  print("5")
elif N == "WED":
  print("4")
elif N == "THU":
  print("3")
else:
  print("2")

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef tuple<ll, ll, ll> T;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin>>s;
    cout<<"ABC"<<s<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int num;
vector<int> tree;
int lowbit(int s)
{
    return s & (-s);
}
int query(int s)
{
    int ans = 0;
    for(int i = s; i > 0; i -= lowbit(i))
    {
        ans += tree[i];
    }
    return ans;
}
void update(int s, int x)
{
    for(int i = s; i <= num; i += lowbit(i))
    {
        tree[i] += x;
    }
}
int main()
{
    while(scanf("%d", &num) == 1)
    {
        tree.resize(num + 1);
        vector<int> v[100005];
        for(int i = 1; i <= num; i++)
        {
            int n;
            scanf("%d", &n);
            v[n].push_back(i);
            update(i, 1);
        }
        long long ans = 0;
        for(int i = 1; i <= 100005; i++)
        {
            for(int j = 0; j < v[i].size(); j++)
            {
                int r = query(num) - query(v[i][j]) - (v[i].size() - j - 1);
                int l = query(v[i][j] - 1);
                ans += min(l, r);
                update(v[i][j], -1);
            }
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 8608
import java.util.*;
public class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    String str = sc.next();
    char[] c = str.toCharArray();
    int n = c.length;
    int count = 0 ;

    for (int i = 0 ; i < n/2 ; i++ ) {
      if (c[i] != c[n-1-i]) {
        count++;

      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 23764
n,y = (int(i) for i in input().split())
y/=1000
payed = False
for i in range(n+1):
    if payed:
        break
    for j in range(n+1-i):
        k = n-i-j
        if k>=0:
            if i*10+j*5+k==y:
                print(i,j,k)
                payed = True
                break
if not payed:
    print(-1,-1,-1)

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

int main() {
  int N;
  string S;
  cin >> N >> S;

  int x=0;
  int ma=0;

  for(int i=0;i<S.size();i++) {
    if(S.at(i)=='I'){
      x++;
      ma=max(ma,x);
    }
    else x--;
  }

  cout << ma << endl;
}


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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    vector<ll> ans(n);
    ll sum = 0;
    REP(i, n)  { 
        cin >> a[i];
        sum += a[i];
    }

    ans[0] = sum;
    for(int i = 1; i < n; i += 2) {
        ans[0] -= 2 * a[i];
    }

    FOR(i, 1, n) {
        ans[i] = 2 * a[i - 1] - ans[i - 1];
    }
    
    for(auto e: ans) {
        printf("%lld ", e);
    }
}


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

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int N;
long long A[210000];
long long dif[210000];

int main() {
    while (cin >> N) {
        for (int i = 0; i < N; ++i) cin >> A[i];
        long long all = 0;
        long long prev = 0;
        A[N] = 0;
        for (int i = 0; i < N; ++i) {
            all += abs(prev - A[i]);

            dif[i] = 0;
            if (prev <= A[i] && A[i] >= A[i+1]) dif[i] = abs(A[i] - max(prev, A[i+1])) * 2;
            else if (A[i] <= prev && A[i+1] >= A[i]) dif[i] = abs(A[i] - min(prev, A[i+1])) * 2;
            
            prev = A[i];
        }
        all += abs(A[N-1]);

        for (int i = 0; i < N; ++i) {
            //cout << i << ": " << dif[i] << endl;
            cout << all - dif[i] << endl;
        }
    }
}
























Measured memory_bytes: 2816
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using namespace std::literals;

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

  int counter = 0;
  int n = (int)s.size();
  for (int i = 0; i < n / 2; ++i) {
    if (s[i] != s[n - 1 - i])
      counter++;
  }
  cout << counter;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
    ll N;
    cin >> N;
    ll dp[100000 + 1] = {0, 1, 2, 3, 4, 5, 1};
    for(ll i = 7; i <= N; i++){
        ll po = 1, yo = 1;
        while(po * 9 <= i) po *= 9;
        while(yo * 6 <= i) yo *= 6;
        dp[i] = min(min(dp[i - 1], dp[i - po]), dp[i - yo]) + 1;
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N, x;
  std::cin >> N >> x;
  std::vector<int> a(N);
  range(i, N) std::cin >> a[i];
  sort(a.begin(), a.end());
  range(i, N){
    if(a[i] <= x) x -= a[i];
    else{
      std::cout << i << '\n';
      break;
    }
    if(i == N-1){
      if(x == 0) std::cout << N << '\n';
      else std::cout << N - 1 << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 #define int long long

#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
#define fi first
#define se second


using namespace __gnu_pbds;
using namespace std;
const int mod=1e9+7;
 // const int mod=998244353;
 // const int mod=1e9+9;
const int INF=4e18+10;
// const int INF=4e18+10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define read(n) int n; cin>>n;
#define readv(x, n) vector<int> x(n); for(auto &i:x) cin>>i;


typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

template<typename T1,typename T2>
void set_min(T1& a, T2 b)
{
    a=min(a, (T1)b);
}


int multiply(int a, int b, int in_mod){return (a*b)%in_mod;}
int mult_identity(int a){return 1;}


auto power(auto a, int b, int in_mod)
{
    auto prod=mult_identity(a);
    auto mult=a%in_mod;
    while(b!=0)
    {
        if(b%2)
        {
            prod=multiply(prod,mult, in_mod);

        }
        mult=multiply(mult, mult,in_mod);
        b/=2;
    }
    return prod;
}
int mod_inv(int q, int in_mod)
{

    return power(q, in_mod-2,in_mod);
}

void precomp()
{
}



void solve()
{
    int n;
    cin>>n;
    readv(a,n);
    sort(all(a));
    reverse(all(a));
    int ans =0;
    ans  = a[0];
    int cnt = 1;
    for(int i= 1;i<n;i++)
    {
        ans += min(n -1 - cnt , (int)2) * a[i];
        cnt +=min(n - 1- cnt, (int)2);
    }
    cout<<ans<<endl;
}


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen("INPUT.txt", "r", stdin);
        freopen("OUTPUT.txt", "w", stdout);
    }
#endif
    auto clk = clock();
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    // -------------------------------------Code starts here---------------------------------------------------------------------
    precomp();
    int t = 1;
    // cin>>t;

    for (int test = 1; test <= t; test++)
    {
        // cout<<"Case #"<<test<<": ";
        // cout<<endl;
        solve();

        // cout<<endl;
    }

    // -------------------------------------Code ends here------------------------------------------------------------------

    clk = clock() - clk;
    // cerr << fixed << setprecision(6) << "Time: " << ((long double)clk) / CLOCKS_PER_SEC << "\n";
    return 0;
}


Measured memory_bytes: 4832
#include <bits/stdc++.h>
using namespace std;
// 型エイリアス
using pii = pair<int, int>;
using tisb = tuple<int, string, bool>;
using vi = vector<int>;
using vii = vector<vi>;

struct Node{
  int key;
  Node *prev, *next;
};

Node *nil;

void init(){
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void insert(int key){
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;

  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

Node* listSearch(int key){
  Node *cur = nil->next;
  while(cur != nil && cur->key != key){
    cur = cur->next;
  }
  return cur;
}

void deleteNode(Node *t){
  if(t == nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void deleteKey(int key){
  deleteNode(listSearch(key));
}

void printList(){
  Node *cur = nil->next;
  int isf = 0;
  while(1){
    if(cur == nil) break;
    if(isf++ > 0) printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
  }
  printf("\n");
}

int main(){
  int n;
  int size = 0;
  char com[20];

  scanf("%d", &n);
  init();

  for(int i=0; i<n; ++i){
    int key;
    scanf("%s%d", com, &key);
    if(com[0] == 'i'){
      insert(key);
      ++size;
    }else if(com[0] == 'd'){
      if(strlen(com) > 6){
        if(com[6] == 'F') deleteFirst();
        else if(com[6] == 'L') deleteLast();
      }else{
        deleteKey(key);
      }
      --size;
    }
  }

  printList();
}


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

int main()
{
  long long int i,j,k,l=0;
  long long int space;
  long long int N,M,X;
  scanf("%lld %lld %lld",&N,&M,&X);
  long long int A[N+1][M+1];
  long long int C[N+1];
  long long int Min=0;
  long long int Num[M+1];
  for(j=0;j<M;j++){
    Num[j] = 0;
  }
  for(i=0;i<N;i++){
    for(j=0;j<M;j++){
      A[i][j] = 0;
    }
    C[i] = 0;
  }
  long long int MIN = 100000000;
  
  for(i=0;i<N;i++){
    scanf("%lld",&C[i]);
    for(j=0;j<M;j++){
      scanf("%lld",&A[i][j]);
    }
  }

    for(int temp=0;temp<(1<<N);temp++){
      for(i=0;i<N;i++){
        if( temp & (1<<i) ){
          for(j=0;j<M;j++){
            Num[j] += A[i][j];            
          }
          Min += C[i];
        }
      }
      for(j=0;j<M;j++){
        if( Num[j] < X ){
          l = -1;
          break;
        }
      }
      if( l == 0 ){
        if( Min < MIN ){
          MIN = Min;
        }
      }   
      for(j=0;j<M;j++){ Num[j] = 0; } 
      Min = 0;
      l = 0;
    }
  
    if( MIN == 100000000 ){
      printf("-1\n");
    }
    else{
      printf("%lld\n",MIN);
    }
  
  return 0; 
  
}

Measured memory_bytes: 3836
using System;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ');
        var a = Convert.ToInt32(input[0]);
        var b = Convert.ToInt32(input[1]);
        var c = Convert.ToInt32(input[2]);
        var d = Convert.ToInt32(input[3]);

        if (Math.Abs(a - c) <= d || (Math.Abs(a - b) <= d && Math.Abs(b - c) <= d)) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}

Measured memory_bytes: 13140
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define EPS 1e-8
#define DEB 0


const int dx[] = {0,1,0,-1};
const int dy[] = {-1,0,1,0};
int w,h,sx,sy,gx,gy;
int field[32][32];
int karikari;

int solve(int x, int y, int cnt){
	if( cnt>=karikari )return INT_MAX;
	if( field[y][x]==3 ) return cnt;
	
	int ret = INT_MAX;
	int tx,ty;
	rep(k,4){
		tx = x + dx[k];
		ty = y + dy[k];
		if( tx<0 || ty<0 || tx>=w || ty>=h || field[ty][tx]==1 )continue;

		int t;
		for(t=1;;t++){
			tx = x + dx[k]*t;
			ty = y + dy[k]*t;
			if( tx<0 || ty<0 || tx>=w || ty>=h ){
				break;
			}
			if( field[ty][tx]==1 ){
				field[ty][tx] = 0;
				ret = min(ret, solve(tx-dx[k],ty-dy[k],cnt+1));
				field[ty][tx] = 1;
				break;
			}else if( field[ty][tx]==3 ){
				karikari = min(karikari,cnt+1);
				ret = min(ret, cnt+1);
				break;
			}
		}
	}
	return ret;
}
int main(){
	while(scanf("%d%d",&w,&h),w|h){
		karikari = 10;
		rep(i,h){
			rep(j,w){
				scanf("%d",&field[i][j]);
				if( field[i][j]==2 ){
					sx = j;
					sy = i;
				}else if( field[i][j]==3 ){
					gx = j;
					gy = i;
				}
			}
		}
		int ans = solve(sx,sy,0);
		printf("%d\n",ans==INT_MAX?-1:ans);
	}
	return 0;
}

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

int main(){
	ll n,k;
	cin >> n >> k;
	vector<double> a(n);
	rep(i,n) cin >> a[i];
	rep(i,n){
		a[i] = (a[i]+1)/2;
	}
	double ans = 0;
	double temp = 0;
	rep(i,k){
		temp += a[i];
	}
	ans = max(ans, temp);
	rep(i,n-k){
		temp += a[i+k] - a[i];
		ans = max(ans, temp);
	}
	printf("%.10f", ans);
	
    return 0;
}



Measured memory_bytes: 1792
class UnionFind:
    def __init__(self, n):
        #親ノードの番号を格納
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.size = [1] * (n+1)
    def find(self, x):
        #根ならその番号を返す
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def same_check(self, x, y):
        #同じかどうかの確認
        return self.find(x) == self.find(y)
    def union(self, x, y):
        #統合する
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
            self.size[x] = 0
        elif self.rank[x] > self.rank[y]:
            self.par[y] = x
            self.size[x] += self.size[y]
            self.size[y] = 0
        else:
            self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]
            self.size[y] = 0
    def getsize(self, x):
        p = self.find(x)
        return self.size[p]
n, m = map(int, input().split())
p = list(map(int, input().split()))
G = UnionFind(n)
for i in range(m):
    x,y = map(int, input().split())
    G.union(x,y)
ans = 0
for i in range(1,n+1):
    if G.same_check(p[i-1], i):
        ans += 1
print(ans) 

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

int main(){
    int n; cin>>n;
    ll s[200010];
    s[0]=0;
    for(int i=1;i<=n;i++){
        ll a; cin>>a;
        s[i]=s[i-1]+a;
    }
    ll ans=2e9+10;
    for(int i=1;i<=n-1;i++){
        ans=min(ans,abs(2*s[i]-s[n]));
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s = sc.nextLine().split(" ");
        int N = getInt(s[0]);
        int M = getInt(s[1]);
        int X = getInt(s[2]);
        String[] A = sc.nextLine().split(" ");

        int countBefore = 0;
        int countAfter = 0;
        for(int i = 0;i < M;i++){
            int a = getInt(A[i]);
            if(a < X && a > 0){
                countBefore++;
            }else if(a < N && a > X){
                countAfter++;
            }
        }

        if(countAfter > countBefore){
            println(countBefore);
        }else{
            println(countAfter);
        }

        return;
    }
    static long getLong(String val) {return Long.parseLong(val);}
    static int getInt(String val) {return Integer.parseInt(val);}
    static String[] split(String val) {return val.split(" ");}
    static List<String> toSortedList(String[] s){ return sortList(Arrays.asList(s));}
    static List<String> sortList(List<String> list){
        Collections.sort(list, Comparator.comparingInt(val -> Integer.parseInt(String.valueOf(val))));
        return list;
    }

    static void println(String val){System.out.println(val);}
    static void println(int val){System.out.println(val);}
    static void println(long val){System.out.println(val);}
    static void println(boolean val){System.out.println(val);}
}


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

using namespace std;

int main(){
  string s1,s2;
  cin >> s1 >> s2;
  
  int c1,c2;
  cin >> c1 >> c2;
  
  string u;
  cin >> u;
  
  if(u==s1) --c1;
  else --c2;
  cout << c1 << " " << c2 <<endl;
  return 0;
}

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

int main()
{
  const int MAX_PRIME = 1000000+1;

  bool p[MAX_PRIME];
  memset(p, true, sizeof(p));
  p[0] = p[1] = false;
  for (int i = 2; i*i <= MAX_PRIME; ++i) {
    if (p[i]) {
      for (int j = i+i; j < MAX_PRIME; j += i)
	p[j] = false;
    }
  }

  vector<int> prime;
  for (int i = MAX_PRIME-1; i >= 0; --i) {
    if (p[i])
      prime.push_back(i);
  }

  int n, x;
  while (cin >> n >> x) {
    if ((n|x) == 0)
      break;

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

    vector<int> dp(x+1, 0);
    dp[0] = 1;
    for (int i = 0; i <= x; ++i) {
      if (!dp[i])
	continue;
      for (int j = 0; j < n; ++j) {
	if (i+foods[j] <= x)
	  dp[i+foods[j]] = 1;
      }
    }

    bool found = false;
    for (unsigned int i = 0; i < prime.size() && !found; ++i) {
      if (prime[i] <= x && dp[prime[i]]) {
	cout << prime[i] << endl;
	found = true;
      }
    }

    if (!found)
      cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 6492
S=input()
def f(S):
    L=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
    for l in L:
        if l not in S:
            return print(l)
    return print("None")
f(S)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<long double, long double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int MOD = 1000000007;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main() {
    string s, t; cin >> s >> t;
    t += s; cout << t << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	int n, m, x;
	cin >> n >> m >> x;
	vector<int> c(n);
	vector<vector<int>> a(n, vector<int>(m));
	int mn = 1e9;
	forn(i, n){
		cin >> c[i];
		forn(j, m){
			cin >> a[i][j];
		}
	}
	for(int mask = 0; mask < (1<<n); mask++) {
		vector<int> t(m);
		int sum = 0;
		for(int i = 0; i < n; i++) {
		if((mask>>i)&1) {
			sum += c[i];
			for(int j = 0; j < m; j++)
				t[j] += a[i][j];
			}
			
		}
		bool ok = true;
		for(int i = 0; i < m; i++) {
			if(t[i] < x) {
				ok = false;
				break;
			}
		}

		if(ok) mn = min(mn, sum);
	}	
	if(mn == 1e9) cout << -1 << endl;
	else cout << mn << endl;
	return 0;
}



Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
#define ll long long
int main(){
	int n,w;
	cin>>n>>w;
	vector<ll> dp(w+1);   // 1 2 ........w
	//dp[i] -maximum total value of items with total weight exactly equal to i

	for(int item=0;item<n;item++){
		int weight,value;
		cin>>weight>>value;
		for(int already_weight=w-weight;already_weight>=0;already_weight--){
			dp[already_weight+weight] = max(dp[already_weight+weight],dp[already_weight]+value);
		}
	}
	ll m=0;
	for(int i=0;i<=w;i++) m=max(m,dp[i]);
	cout<<m<<endl;
}

Measured memory_bytes: 3964
h,w,m= map(int,input().split(" "))
ys, xs=[0 for i in range(h)],[0 for j in range(w)]
ms=set()
for i in range(m):
    y,x= map(lambda x: int(x)-1,input().split(" "))
    ys[y]+=1
    xs[x]+=1
    ms.add((y,x))
y_max,x_max= max(ys),max(xs)
largest_ys, largest_xs=[],[]
for i in range(h):
    if ys[i]==y_max:
        largest_ys.append(i)
for i in range(w):
    if xs[i]==x_max:
        largest_xs.append(i)
ans=y_max+x_max-1
for i in largest_ys:
    for j in largest_xs:
        if (i,j) not in ms:
            print(ans+1)
            exit()
print(ans)

Measured memory_bytes: 166936
#include<iostream>
#include<vector>
#include<string>

int main(){
    std::string S;
    std::cin >> S;
    int cnt = 0;
    char c = S[0];
    for(int i = 1; i < S.size(); i++){
        if(c != S[i]){
            cnt++;
            c = S[i];
        }
    }
    std::cout << cnt << std::endl;
    return 0;
}


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

public class Main {
	
	static String merge(String s1, String s2) {
		for(int i=0; i<s1.length(); i++) {
			boolean f=true;
			for(int j=0; i+j<s1.length(); j++) {
				if(j>s2.length()-1) break;
				if(s1.charAt(i+j)!=s2.charAt(j)) {
					f=false;
					break;
				}
			}
			if(f) {
				if(i+s2.length()<=s1.length()) return "";
				return s2.substring(s1.length()-i);
			}
		}
		return s2;
	}
	
	static boolean match(String s1, String s2) {
		if(s1.length()<s2.length()) {
			return false;
		}
		for(int i=0; i+s2.length()<s1.length(); i++) {
			if(s1.substring(i, i+s2.length()).equals(s2)){
				return true;
			}
		}
		return false;
	}
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			while(sc.hasNext()) {
				int n=sc.nextInt();
				if(n==0) break;
				String[] moji=new String[n];
				for(int i=0; i<n; i++) {
					moji[i]=sc.next();
				}
				boolean[] moji1=new boolean[n];
				String[] s=new String[n];
				int count=0;
				for(int i=0; i<n; i++) {
					if(moji1[i]) continue;
					for(int j=0; j<n; j++) {
						if(i==j) continue;
						if(match(moji[i], moji[j])) {
							moji1[j]=true;
						}
					}
				}
				ArrayList<String> list=new ArrayList<>();
				for(int i=0; i<n; i++) {
					if(! moji1[i]) {
						list.add(moji[i]);
					}
				}
				n=list.size();
				String[][] mer=new String[n+1][n+1];
				for(int i=0; i<n; i++) {
					for(int j=0; j<n; j++) {
						mer[i][j]=merge(list.get(i), list.get(j));
					}
				}
				
				for(int i=0; i<n; i++) {
					mer[n][i]=list.get(i);
				}
				String INF="SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS";
				String res=INF;
				String[][] dp=new String[(1<<n)][n+1];
				for(int i=0; i<(1<<n); i++) {
					for(int j=0; j<=n; j++) {
						dp[i][j]=INF;
					}
				}
				dp[0][n]="";
				for(int i=0; i<(1<<n); i++) {
					for(int j=0; j<=n; j++) {
						if(dp[i][j]==INF) continue;
						if(i==(1<<n)-1) {
							if(res.length()>dp[i][j].length()) {
								res=dp[i][j];
							}
							else if(res.length()==dp[i][j].length()) {
								res=res.compareTo(dp[i][j])>0 ? dp[i][j]:res;
							}
						}
						for(int k=0; k<n; k++) {
							if((i&(1<<k))==1) continue;
							int next = i|(1<<k);
							String nexts=dp[i][j]+mer[j][k];
							if(dp[next][k].length()>nexts.length()) {
								dp[next][k]=nexts;
							}
							else if(dp[next][k].length()==nexts.length()) {
								dp[next][k]=dp[next][k].compareTo(nexts)>0 ? nexts:dp[next][k];
							}
						}
					}
				}
				System.out.println(res);
				
			}
			
		}
	}
}


Measured memory_bytes: 101976
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int MAXN = 10 + 1e6;
const ll oo = 1 + 1e18;
const ll mod = 7 + 1e9;

int a[6];

int main()
{
    #define TASK "ABC"
    #ifndef ONLINE_JUDGE
    freopen(TASK".inp","r",stdin);
    freopen(TASK".out","w",stdout);
    #endif ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    for (int i = 1; i <= 5; i++)
    {
        cin >> a[i];
        if (a[i] != i)
        {
            cout << i << '\n';
            return 0;
        }
    }


    return 0;
}




















































































Measured memory_bytes: 3608
#include <iostream>
#include <string>

using namespace std;

int main(void) {
	int n, m;
	int AC_num = 0, WA_num = 0;
	int i;
	int p[100000] = {};
	int WA_count[100000] = {};

	cin >> n >> m;
	if (m == 0)
		printf("0 0\n");
	else {
		for ( i = 1; i <= m; i++) {
			int a;
			string s;
			cin >> a >> s;
			if (p[a - 1] == 1)
				continue;
			else {
				if (s == "AC") {
					AC_num++;
					p[a - 1] = 1;
					WA_num += WA_count[a - 1];
					//WA_count = 0;
				}
				else if (s == "WA")
					WA_count[a - 1]++;
			}
		}

		printf("%d %d\n", AC_num, WA_num);
	}

	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int F[45];

int fibonacci(int n) {
  int i;
  F[0] = 1;
  F[1] = 1;
  for (i = 2; i <= n; i++) {
    F[i] = F[i - 2] + F[i - 1];
  }
  return F[n];
}

int main() {
  int n, fib;

  scanf("%d", &n);
  fib = fibonacci(n);
  printf("%d\n", fib);
  return 0;
}

Measured memory_bytes: 596