akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

#include <climits>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

string N;
typedef long long ll;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;
#define rep(i, a, b) for (int i = a; i < b; i++)
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
//---------------------------------------------------------------------------------------------------
int g[11] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1};
int memo[10000001][2];
int f(int i, int j) {  // =[0,i]円+j円を支払う最小枚数
    if (i < 0) {
        if (j == 0)
            return 0;
        else
            return 1;
    }
    if (0 <= memo[i][j]) return memo[i][j];

    int res = inf;
    rep(d, 0, 10) {
        int n = N[i] - '0' + j;

        int sm = g[d];
        if (d < n)
            sm += f(i - 1, 1) + g[10 + d - n];
        else
            sm += f(i - 1, 0) + g[d - n];

        chmin(res, sm);
    }

    return memo[i][j] = res;
}
//---------------------------------------------------------------------------------------------------
int main() {
    cin >> N;
    rep(i, 0, 10000001) rep(j, 0, 2) memo[i][j] = -1;
    cout << f(N.length() - 1, 0) << endl;
    return 0;
}


Measured memory_bytes: 157700
#include <iostream>

using namespace std;

int main()
{
    int n,x1,y1,z1,w1,x2,y2,z2,w2;
    
    while(cin >> n,n!=0){
        for(int i=0;i<n;i++){
            
            cin >> x1 >> y1 >> z1 >> w1;
            cin >> x2 >> y2 >> z2 >> w2;
        
            cout << x1*x2 - y1*y2 - z1*z2 - w1*w2 << " ";
            cout << x1*y2 + y1*x2 + z1*w2 - w1*z2 << " ";
            cout << x1*z2 - y1*w2 + z1*x2 + w1*y2 << " ";
            cout << x1*w2 + y1*z2 - z1*y2 + w1*x2 << endl;
        }
        
    }
    
    return 0;
}



Measured memory_bytes: 3080
process.stdin.resume();
process.stdin.setEncoding('utf8');

process.stdin.on('data', function (chunk) {
    let h, m, rest = new Number();
    h = parseInt(chunk / 3600);
    rest = parseInt(chunk % 3600);
    m = parseInt(rest / 60);
    rest = parseInt(rest % 60);
    console.log(`${h}:${m}:${rest}`);
});


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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

int gcd(int x, int y)
{
	return y ? gcd(y, x % y) : x;
}

string str;

bool check(long long n) {
	return (n & (n - 1)) == 0;
}

void hawawa()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << min(a, b) + min(c, d) << "\n";
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

set<P> S;
vector<vector<Int> > X;
Int H, W, N;

Int calc(Int x,Int y){
  Int idx = lower_bound(X[y].begin(), X[y].end(), x) - X[y].begin();
  return X[y][idx] - x;
}

Int bfs(){
  using T = tuple<Int,Int,Int>;
  queue<T> Q;
  map<T,Int> D;
  vector<Int> used(H+1);
  map<T,Int> visited;
  Q.push(T(0, 0, 0));
  D[T(0, 0, 0)] = 0;

  Int ans = INF;
  while(!Q.empty()){
    Int x, y, turn;
    tie(x, y, turn) = Q.front(); Q.pop();
    Int cost = D[T(x, y, turn)];
    if(!used[y]) Min(ans, cost + calc(x, y));
    visited[T(x, y, turn)] = 1;
    used[y] = 1;
    
    if(turn == 0 && used[y+1] == 0){
      if(S.count(P(x+1, y)) || x+1 >= W) continue;
      Q.push(T(x+1, y, !turn));
      D[T(x+1, y, !turn)] = cost;
    }
    if(turn == 1){
      if(S.count(P(x, y+1))){
	if(!visited[T(x, y, !turn)]){
	  Q.push(T(x, y, !turn));
	  D[T(x, y, !turn)] = cost+1;
	}
      }
      else if(y+1 < H){
	Q.push(T(x, y+1, !turn));
	D[T(x, y+1, !turn)] = cost + 1;
      }
    }
  }
  return ans;
}
signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);


  cin>>W>>H>>N;
  X.resize(H);
  for(Int i=0;i<N;i++){
    Int x, y;
    cin>>x>>y; x--, y--;
    S.insert(P(x, y));
    X[y].push_back(x);
  }
  for(Int i=0;i<H;i++) {
    X[i].push_back(W);
    sort(X[i].begin(),X[i].end());
  }

  Int ans = bfs();
  cout<<ans<<endl;

  
  return 0;
}


Measured memory_bytes: 89472
/*
Anki:未済
作成日:
*/

#include <stdio.h>

int main()
{
    int a, b, c, color = 3;

    scanf( "%d %d %d", &a, &b, &c );

    if( a == b && b == c ) color = 1; //全部同じ
    else if( a == b || b == c || c == a ) 
        color = 2;
    else color = 3;
    
    printf( "%d\n", color );

    return 0;
}

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

const int N = 5005;
typedef long long LL;

int n, pre[N][N], a[N], pre_cnt[N][N], inv[N], occ[N];
LL dp[N][N];
LL A, B, inf = 1e18;

LL solve(int pos, int kth) {
    if(pos > n) return 0;
    if(kth > (n-pos+1)) return 0;
    if(dp[pos][kth] != -1) return dp[pos][kth];
    int kth_pos = pre[pos][kth];
    int kth_inv = pre_cnt[pos][kth];
    int back_small = (kth_pos-pos) - kth_inv;
//    cout << "back_small: " << back_small << endl;
    int kth_jump = (kth-back_small);
    LL ans1 = solve(kth_pos+1, kth_jump) + A*kth_inv;
    LL ans2 = solve(pos, kth+1) + B;
//    cout << "pos: " << pos << "   kth: " << kth << " ---> " << min(ans1, ans2) << endl;
    return dp[pos][kth] = min(ans1, ans2);
}

int main() {
    // freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> A >> B;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = n; i >= 1; i--) {
        occ[a[i]] = i;
        for(int j = 1; j <= n; j++) {
            if(occ[j] && j < a[i]) inv[j]++;
        }
        int kth = 0;
        for(int j = 1; j <= n; j++) {
            if(occ[j]) {
                ++kth;
                pre[i][kth] = occ[j];
                pre_cnt[i][kth] = inv[j];
            }
        }
    }
//    for(int i = 1; i <= n; i++) {
//        for(int j = 1; j <= n; j++) {
//            cout << pre_cnt[i][j] << " ";
//        }
//        cout << endl;
//    }
    memset(dp, -1, sizeof dp);
    cout << solve(1,1) << endl;

    return 0;
}



Measured memory_bytes: 391680
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cassert>
#include <utility>
#include <numeric>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#define rep(i,n) for (int i=0; i<(n); ++i)

using namespace std;
using ll = long long;
int main (){
    ll a,b,k;
    cin >> a >> b >> k;
    
    cout << max(0LL,a-k) << " "<<max(0LL,b-max(0LL,(k-a)));

}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int k = Integer.parseInt(sa[1]);
		sa = br.readLine().split(" ");
		int[] a = new int[n + 1];
		for (int i = 0; i < n; i++) {
			a[i + 1] = Integer.parseInt(sa[i]) - 1;
		}
		br.close();

		for (int i = 1; i <= n; i++) {
			a[i] += a[i - 1];
			a[i] %= k;
		}

		Map<Integer, Integer> map = new HashMap<>();
		long ans = 0;
		for (int i = 0; i <= n; i++) {
			if (i >= k) {
				delCntMap(map, a[i - k]);
			}
			if (map.containsKey(a[i])) {
				ans += map.get(a[i]);
			}
			addCntMap(map, a[i]);
		}
		System.out.println(ans);
	}

	static void addCntMap(Map<Integer, Integer> map, Integer key) {
		if (map.containsKey(key)) {
			map.put(key, map.get(key) + 1);
		} else {
			map.put(key, 1);
		}
	}

	static void delCntMap(Map<Integer, Integer> map, Integer key) {
		if (key != null && map.containsKey(key)) {
			int val = map.get(key);
			if (val == 1) {
				map.remove(key);
			} else {
				map.put(key, val - 1);
			}
		}
	}
}


Measured memory_bytes: 62476
#include <bits/stdc++.h>
using namespace std;
#define LOOP(val, times)   for(val = 0; val < (times); val++)
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  vector<int> b(n);
  int i;
  LOOP(i,n){
    cin>>a[i];
  }
  LOOP(i,n){
    cin>>b[i];
  }

  int ans=0;
  LOOP(i,n){
    if(a[i]-b[i]>0){
      ans+=a[i]-b[i];
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int m; int f; int r;
		while (true) {
			m = scan.nextInt();
			f = scan.nextInt();
			r = scan.nextInt();
			if (m == -1 && f == -1 && r == -1) break;
			if (m == -1 || f == -1) {
				System.out.println("F");
			}else if (m + f >= 80) {
				System.out.println("A");
			} else if (m + f >= 65) {
				System.out.println("B");
			} else if (m + f >= 50) {
				System.out.println("C");
			} else if (m + f >= 30) {
				if (r >= 50) {
					System.out.println("C");
				} else {
					System.out.println("D");
				}
			} else {
				System.out.println("F");
			}
		}
		
	}

}

Measured memory_bytes: 26328
using System;
using System.Collections.Generic;

namespace cswork {
    class Program {
        static void Main (string[] args) {
            List<long> line = ReadList ();
            int n = (int) line[0];
            long k = line[1];

            List<int> a = ReadListInt ();

            List<int> s = new List<int> ();
            int[] ord = new int[n + 1];
            for (int i = 0; i < ord.Length; i++) {
                ord[i] = -1;
            }

            int now = 1;
            while (ord[now] == -1) {
                ord[now] = s.Count;
                s.Add (now);
                now = a[now - 1];
            }
            int c = s.Count - ord[now];
            int l = ord[now];

            if (k < l) {
                Write (s[(int) k]);
            } else {
                k -= l;
                k %= c;
                Write (s[(int) k + l]);
            }
            Exit ();
        }

        public static void Write (string str) {
            Console.WriteLine (str);
        }

        public static void Write (int i) {
            Console.WriteLine (i);
        }

        public static void Write (double d) {
            Console.WriteLine (d);
        }

        public static string ReadStr () {
            return Console.ReadLine ();
        }

        public static int ReadInt () {
            return int.Parse (Console.ReadLine ());
        }

        public static long Read () {
            return long.Parse (Console.ReadLine ());
        }

        public static double ReadDouble () {
            return double.Parse (Console.ReadLine ());
        }

        public static void Exit () { }

        public static List<string> ReadListStr () {
            return new List<string> (ReadStr ().Split (" "));
        }

        public static List<long> ReadList () {
            return ReadListStr ().ConvertAll (x => long.Parse (x));
        }

        public static List<int> ReadListInt () {
            return ReadListStr ().ConvertAll (x => int.Parse (x));
        }
    }
}

Measured memory_bytes: 46776
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>

using namespace std;

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

int main(){
    int n, k;
    cin >> n >> k;
    int ans = k;
    rep(i, n - 1){
        ans *= k - 1;
    }
    cout << ans << endl;
}


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

int main (){
    int a, b, c ,d;
    cin >> a >> b >> c >>d;
    if((a+b)>(c+d)){
        cout << "Left";
    }else if((a+b)<(c+d)){
        cout << "Right";
    }else{
        cout << "Balanced";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main ()
{
	int n, k, sum = 0;
	cin >> n >> k;
	int h;
	for (int i=0; i<n; i++){
		cin >> h;
		if (h >= k){
			sum++;
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
using System;

namespace _4_B
{
    class Program
    {
        static void Main(string[] args)
        {
           
            double a = double.Parse(Console.ReadLine());
           // double b=12.566371 / 4;
            Console.WriteLine(3.141592653589 * a * a + " " + 3.141592653589 * a * 2);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 9164
function Main(input) {
 
    var N = new Number(input.split('\n')[0]);
    var A = input.split('\n')[1].split(' ');
 
    var sum = 0;

    for (var i = 0; i < N; i++){
        sum += (1.0 / A[i]);
    }

    console.log(1.0/sum);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21192
#include<iostream>
#include<stdio.h>
#include<string>
using namespace std;

int main() {
	string a, b, c;
	cin >> a >> b >> c;

	int sa = 'a' - 'A';
	printf("%c", a[0] - sa);
	printf("%c", b[0] - sa);
	printf("%c\n", c[0] - sa);

}

Measured memory_bytes: 256
num = []
num += gets.split.map &:to_i until num.size == 2
m, n = num
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
max = 0
(0..n-1).each{|j|
	c = 0	
	(0..m-1).each{|i|
		if a[i] == b[j]
			j += 1 
			c += 1
		end
	}
	max = c if c > max
}
p max

Measured memory_bytes: 6900
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vec>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll n;
  cin >> n;
  vec a(n);
  for(ll i=0;i<n;i++)cin >> a[i];

  ll ans=inf;
  for(ll i=-100;i<=100;i++){
    ll s=0;
    for(ll j=0;j<n;j++){
      s+=(a[j]-i)*(a[j]-i);
    }
    ans=min(ans,s);
  }

  cout << ans << endl;

}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef       long long int      ll;
#define       READ               freopen("in.txt", "r", stdin);
#define       WRITE              freopen("out.txt", "w", stdout);
#define       optimize           ios::sync_with_stdio(0);cin.tie(0);
#define       RESET(a, b)        memset(a, b, sizeof(a))
#define       gcd(a, b)          __gcd(a, b)
#define       MX                 300005
#define       MOD               1000000007
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p & 1LL) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
bool cmp(ll x,ll y)
{
   return x>y;
}
int main(void)
{
   optimize
   priority_queue<ll> pq;
   string s,t;
   //cin>>t;
   //while(t--)
   //{
      cin>>s;
      cin>>t;
      //ll cnt=0;
      for(ll i=0;i<=s.size()-t.size();i++)
      {
         ll cnt=0;
         for(ll j=0;j<t.size();j++)
         {
            if(s[i+j]==t[j])
               cnt++;
         }
         pq.push(cnt);
      }
      cout<<t.size()-pq.top();
   //}
   return 0;
}


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

const int64_t z=1e18;

int main()
{
  int n;
  cin>>n;
  vector<int64_t> a(n,0);
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    if(a[i]==0)
    {
      cout<<0<<endl;
      return 0;
    }
      
  }
  
  int64_t res=1;
  for(int i=0;i<n;i++)
  {
    if(a[i]>z/res)
    {
      cout<<-1<<endl;
      return 0;
    }
    res*=a[i];
  }
  cout<<res<<endl;
}
    

Measured memory_bytes: 4048
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll dp[3002][3002];
ll game(ll a[],int n,int l,int r)
{
      if(dp[l][r]!=-1)
            return dp[l][r];

      if( l==r )
            return a[l];

      ll x = a[l] - game(a,n,l+1,r);
      ll y = a[r] - game(a,n,l,r-1);
      dp[l][r] = max(x,y);
      return dp[l][r];
}
int main()
{
      // taro tries to maximizes X-Y -> means Taro wants to earn max Possible points
      // Jiro tries to minimize X-Y -> means Jiro wants to earn max Possible points
      // hence, in each their turns they will try to get the best Possible ans.
      int n;
      cin >> n ;
      ll a[n];
      memset( dp,-1,sizeof(dp) );
      ll total = 0;
      for(int i=0;i<n;i++)
      {
            cin >> a[i];
            total += a[i];
      }

      ll ans = game( a,n,0,n-1 );
      cout << ans << endl;
}


Measured memory_bytes: 71040
def bubble_sort(n,nums)
    0.upto(n-1) do |i|
        #N-1=4
        (n-1).downto(0) do |j|
            if nums[j][:value] < nums[j-1][:value] && j != 0
                nums[j], nums[j-1] = nums[j-1], nums[j]
            end
        end
    end
    return nums
end

def selection_sort(a,b)
    b.each_with_index do |num,i|
        min_index = 0 
        min_num = -1
        (i).upto(a-1) do |j|
            if min_num >= 0
                num_index = (min_num > b[j][:value]) ? [b[j][:value], j] : [min_num, min_index]
                min_num, min_index = num_index[0],num_index[1]
            else
                min_num = b[j][:value]
                min_index = j
            end
        end
        if b[i][:value] != b[min_index][:value]
            b[i],b[min_index] = b[min_index],b[i]
        end
    end
    return b
end

N = gets.chomp.to_i
cards_list = gets.chomp.split(" ")
hashed_cards_list = []
cards_list.each do |card|
    hashed_card = {}
    hashed_card[:suit], hashed_card[:value] =  card.split("")[0], card.split("")[1].to_i
    hashed_cards_list << hashed_card
end
bubble_sorted_cards_list = bubble_sort(N,hashed_cards_list.clone)
selection_sorted_cards_list = selection_sort(N,hashed_cards_list.clone)

stable = true
bubble_sorted_cards_list.length.times do |i|
    if bubble_sorted_cards_list[i][:suit] != selection_sorted_cards_list[i][:suit]
        stable = false
    end
end
output_string1 = ""
bubble_sorted_cards_list.each_with_index do |card,i|
    if i != 0
        output_string1 = output_string1 + " #{card[:suit]}#{card[:value]}"
    else
        output_string1 = "#{card[:suit]}#{card[:value]}"
    end
end
output_string2 = ""
selection_sorted_cards_list.each_with_index do |card,i|
    if i != 0
        output_string2 = output_string2 + " #{card[:suit]}#{card[:value]}"
    else
        output_string2 = "#{card[:suit]}#{card[:value]}"
    end
end
puts output_string1
puts "Stable"
puts output_string2
if stable
    puts "Stable"
else
    puts "Not stable"
end


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

using namespace std;
typedef long long ll;

#define out(ans) cout << ans << endl
#define in(n) cin >> n
#define floop(i, N) for (ll i = 0; i < N; i++)
#define floop1(i, N) for (ll i = 1; i <= N; i++)
#define floopi(i, j, N) for (ll j = i + 1; j < N; j++)

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

constexpr ll inf = 1e18;

void solve();

int main()
{
    solve();
}

void solve()
{
    ll n;
    in(n);
    ll a[n];
    floop(i, n) in(a[i]);
    ll ans = 0;
    ll mod = 1e9 + 7;
    ll count = 1;
    floop(i, 60)
    {
        ll flag_1 = 0, flag_0 = 0;
        floop(j, n)
        {
            if (a[j] & 1)
            {
                flag_1++;
            }
            else
            {
                flag_0++;
            }
            a[j] /= 2;
        }
        ll number = flag_1 * flag_0 % mod;
        count %= mod;
        ans += count * number;
        ans = ans % mod;
        count *= 2;
    }
    out(ans);
}

Measured memory_bytes: 2560
/*
23280701537353
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
//#define   Y            imag()
//#define   X            real()
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
//#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
//#define    dp(a,b)          (((conj(a))*(b)).real())
//#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
//#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     PT                    complex<double>
#define outfile freopen("out.out", "w", stdout);
#define infile  freopen("in.in", "r", stdin);
#define PI acos(-1)
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-9);
using namespace std;
using namespace __gnu_pbds;
int dcmp(double a,double b){   return fabs(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
ll setBit1(ll num, int idx) {return num | (1ll<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(int num, int idx) {return num ^ (1<<idx);}
void FS(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
const int N=100009;
int a[N],b[N],n;
int main()
{
    cin>>n;
    for(int i=1;i<=n+1;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++)
        cin>>b[i];
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
       int n1= min(a[i],b[i]);
       ans+=n1;
       a[i]-=n1;
       b[i]-=n1;

       int n2= min(b[i],a[i+1]);
       ans+=n2;
       b[i]-=n2;
       a[i+1]-=n2;
    }
    cout<<ans<<endl;
}























Measured memory_bytes: 1024
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var s,t string
	fmt.Scan(&n,&s,&t)
	ss := strings.Split(s,"")
	tt := strings.Split(t,"")

	ans := []string{}
	for i := 0; i < n; i++ {
		ans = append(ans,ss[i],tt[i])
	}

	fmt.Println(strings.Join(ans,""))
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int l,r,d,count = 0 ;cin>>l>>r>>d;
    while(l<=r){
        if(l%d == 0){
            count++;
        }
        l++;
    }
    cout<<count;
    return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <math.h>
#include <cmath>

using namespace std;

int main(){
	double sum = 0,am_sum = 0,count = 0,value,amount,average;

	while(scanf("%lf,%lf",&value,&amount)!=EOF){
		sum += value*amount;
		am_sum += amount;
		count++;
	}

	average = am_sum/count;

	printf("%.0lf\n%.0lf\n",sum,round(average));

	return 0;
}

Measured memory_bytes: 2840
import sys
k,a,b=map(int, input().split())
if a>=b or (a<b and b-a==1):
    bis=1+k
    print(bis)
    sys.exit()
if a<b and (k-a+1)%2==0:
    bis=(b-a)*((k-a+1)//2-1)+b
    print(bis)
    sys.exit()
if a<b and (k-a+1)%2!=0:
    bis=(b-a)*((k-a+1)//2-1)+b+1
    print(bis)

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

int main(){
    int N; cin >> N;
    vector<int> A(N), v(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        v[i] = i+1 - A[i];
    }
    ll cnt = 0;
    sort(v.begin(), v.end());
    for (int i = 0; i < N; i++)
    {
        auto th1 = lower_bound(v.begin(),v.end(), A[i]+(i+1));
        auto th2 = upper_bound(v.begin(),v.end(), A[i]+(i+1));
        cnt+=th2-th1;
        //cout << *th << endl;
        //for (auto iter = th;  iter!= v.end(); ++iter)
        //{
        //    if(*iter==A[i]+(i+1)) cnt++;
        //    else break;
        //}
    }
    cout << cnt << endl;
    
}

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

struct cell {
  int value;
  struct cell* pre;
};

int main(){
  int N;
  scanf("%d",&N);
  int i,tmp;
  struct cell* pre = NULL;
  for(i=0;i<N;i++){
    scanf("%d",&tmp);
    struct cell* cell = (struct cell*)malloc(sizeof(struct cell));
    cell->pre = pre;
    cell->value = tmp;
    pre = cell;    
  }

  struct cell lastEmptyCell;
  lastEmptyCell.pre = pre;
  int* memo = (int*)malloc(sizeof(int)*N);
  int n = N;
 next:while(n!=0){
    struct cell* tmpCell = &lastEmptyCell;
    //printf("%p\n",lastEmptyCell.pre);
    for(i=n;i>0;i--){
      //printf("%d %d %p\n",i,tmpCell->pre->value,tmpCell->pre);
      if(i==tmpCell->pre->value){
	//printf("in\n");
	//printf("%p\n",tmpCell.pre);
	tmpCell->pre = tmpCell->pre->pre;
	//printf("%p\n",tmpCell.pre);
	n--;
	memo[n] = i;
	goto next;
      }
      tmpCell = tmpCell->pre;
    }
    printf("%d\n",-1);
    exit(0);
  }
  
  for(i=0;i<N;i++){
    printf("%d\n",memo[i]);
  }
}


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

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)

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

    int R,G,B,N; cin >> R >> G >> B >> N;

    int ans = 0;
    int r, g, bB;
    for (r = 0; r <= 3000; r++) {
        if (r * R > N)
            break;
        for (g = 0; g <= 3000; g++) {
            bB = N - r * R - g * G;
            if (bB < 0)
                break;
            if (bB % B == 0) {
                ans++;
            }
        }
    }

    cout << ans << endl;
}


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

int main() {
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  int i=0;
  while(true){
    if(a>=b){
      b*=2;
      i++;
    }
    else if(b>=c){
      c*=2;
      i++;
    }
    else
      break;
  }
  if(i<=k)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}


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

#define int 				long long int
#define all(c)				c.begin(), c.end()
#define init(arr, num)		memset(arr, num, sizeof(arr))
#define fast				ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define inputFile			freopen("input.txt", "r", stdin); 
#define outputFile			freopen("output.txt", "w", stdout);
#define modM 				1000000007


#ifdef Voneone
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>  void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << std::endl;}
template <typename Arg1, typename... Args> 
	void __f(const char* names, Arg1&& arg1, Args&&... args) {
		const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; 
		__f(comma + 1, args...);
}
#else
#define trace(...)
#endif
 
unordered_map<int, int> primeFactors(int n){
	unordered_map<int, int> freq;

	while(n%2 == 0){
		freq[2]++;
		n = n/2;
	}

	int k = sqrt(n);
	for(int i = 3; i <= k; i += 2){
		while(n%i == 0){
			freq[i]++;
			n = n/i;
		}
	}
	if(n > 2)
		freq[n]++;
	return freq;
}

void solve() 
{ 

	int n;
	cin >> n;

	auto fc = primeFactors(n);



	int ans = 0;

	for(auto p : fc){

		int k = p.second;
		int contr = 1;
		int lo = 1, hi = k;
		while(lo <= hi){
			int mid = (lo+hi)/2;
			if(mid*(mid+1)/2 <= k){
				contr = mid;
				lo = mid+1;
			}else{
				hi = mid-1;
			}
		}

		ans += contr;

	}

	cout << ans;


} 
 
 
signed main()
{
 
	
	#ifdef _DEBUG
		inputFile;
	#endif
	fast;
	int T = 1;
	// cin >> T;
	while(T--)
	{
		solve();
		cout << endl;
	}
	
	
	return 0;
 
}


  

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
const int N=1<<18;
int read(){
	char c=getchar();int d=0,f=1;
	for(;c<'0'||c>'9';c=getchar())if(c=='-')f=-1;
	for(;c>='0'&&c<='9';d=d*10+c-48,c=getchar());
	return d*f;
}
const int mod=998244353;
const int N2=(mod+1)/2;
int n,a[N],e[N],b[N],c[N];
int mi(int a,int b){
	int s=1;
	for(;b;b>>=1,a=1LL*a*a%mod)
		if(b&1)s=1LL*s*a%mod;
	return s;
}
void fwt(int*a,int n){
	for(int i=1;i<(1<<n);i<<=1)
		for(int j=0;j<(1<<n);j+=(i<<1))
			for(int k=0;k<i;++k){
				int A=a[j+k],B=a[j+k+i];
				a[j+k]=(A+B)%mod;
				a[j+k+i]=(mod+A-B)%mod;
			}
}
void ifwt(int*a,int n){
	for(int i=1;i<(1<<n);i<<=1)
		for(int j=0;j<(1<<n);j+=(i<<1))
			for(int k=0;k<i;++k){
				int A=a[j+k],B=a[j+k+i];
				a[j+k]=1LL*(A+B)*N2%mod;
				a[j+k+i]=1LL*(mod+A-B)*N2%mod;
			}
}
int main(){
	n=read();
	int sum=0;
	ref(i,0,(1<<n)-1)a[i]=read(),sum+=a[i];
	sum=mi(sum,mod-2);
	ref(i,0,(1<<n)-1)e[i]=1LL*a[i]*sum%mod;
	fwt(e,n);
	ref(i,0,(1<<n)-1)b[i]=mi(mod+1-e[i],mod-2);
	ref(i,1,(1<<n)-1)c[i]=1;
	fwt(c,n);
	ref(i,1,(1<<n)-1)c[i]-=c[0];c[0]=0;
	ref(i,0,(1<<n)-1)c[i]=1LL*b[i]*c[i]%mod;
	ifwt(c,n);
	ref(i,1,(1<<n)-1)c[i]=(c[i]+mod-c[0])%mod;c[0]=0;
	ref(i,0,(1<<n)-1)cout<<c[i]<<endl;
}

Measured memory_bytes: 6912
#include <iostream>
#include <queue>
#include <utility>
using namespace std;

typedef pair<string, int> ps;

int main()
{
	queue<ps> Q;

	int n, q, st = 0;
	cin >> n >> q;

	ps p;
	while (n--) {
		cin >> p.first >> p.second;
		Q.push(p);
	}

	while (!Q.empty()) {
		ps t = Q.front();
		Q.pop();
		if (t.second <= q) {
			st += t.second;
			cout << t.first << " " << st << endl;
		} else {
			st += q;
			t.second -= q;
			Q.push(t);
		}
	}
}


Measured memory_bytes: 6328
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

 


int main(){
  int x,y;
  cin>>x>>y;
  if((x+y)%3!=0){
    cout<<0<<endl;
    return 0;
  }
  int a=x-(x+y)/3;
  int b=y-(x+y)/3;
  
  combination c(a+b+10);
  
  mint ans=c(a+b,a);
  
  cout<<ans.x<<endl;
}
  


Measured memory_bytes: 10624
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<card> cards = new ArrayList<>();
        for(int i = 0; i < m; i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            card c = new card(l,r);
            cards.add(c);
        }
        //cards.sort((a,b) -> a.l-b.l);
        int left = 0;
        int right = Integer.MAX_VALUE;
        for(card c : cards){
            left = Math.max(left,c.l);
            right = Math.min(right,c.r);
        }
        if(right-left < 0){
            System.out.println(0);
        }else{
            System.out.println(right-left+1);
        }
    }
}

class card{
    int l;
    int r;
    
    public card(int l, int r){
        this.l = l;
        this.r = r;
    }
}

Measured memory_bytes: 89344
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

fn main() {
    input! {
        s: Chars,
    }

    println!("{}{}{}", s[0], s[1], s[2]);
}


Measured memory_bytes: 2072
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  cout<<max(0,a-b)<<endl; 
  return 0;
}


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

int main()
{
    int a,b,cnt;
    cin>>a>>b;
    cnt = b*2;
    if(a>cnt){
        cout<<a-cnt<<endl;
    }
    else{
        cout<<"0"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
/* Generated by powerful Codeforces Tool
 * You can download the binary file in here https://github.com/xalanq/cf-tool (Windows, macOS, Linux)
 * Author: alireza_kaviani
 * Time: 2020-05-25 16:26:52
**/
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define sep                         ' '
#define endl                        '\n'
#define SZ(x)                       ll(x.size())

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 1e6 + 10;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll n , m , cost , ans = INF , A[MAXN] , ps[MAXN];
vector<pii> vec;

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

    cin >> n >> m;
    for(int i = 1 ; i <= n ; i++)   cin >> A[i];
    for(int i = 1 ; i + 1 <= n ; i++){
        cost += (A[i + 1] - A[i] + m) % m;
        int L = A[i] + 1 , R = A[i + 1];
        if(A[i] == A[i + 1])    continue;
        if(L > R)   R += m;
        ps[L + 1]++; ps[R + 1]--;
        vec.push_back({R + 1 , R - L});
    }
    partial_sum(ps , ps + MAXN , ps);
    for(pii i : vec)    ps[i.X] -= i.Y;
    partial_sum(ps , ps + MAXN , ps);
    //for(int i = 1 ; i <= m + m ; i++) cout << ps[i] << sep;
    for(int i = 1 ; i <= m ; i++)   ans = min(ans , cost - ps[i] - ps[i + m]);
    cout << ans << endl;

    return 0;
}
/*

*/


Measured memory_bytes: 11380
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#define mm(a,x) memset(a,x,sizeof(a))
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0)
#define ll long long
using namespace std;
const int MAXN=2e5+10;
ll a[MAXN];
ll labs(ll x)
{
	return x>0?x:-x;
}
int main(void)
{
    sync;
    int k,n;
    cin>>k>>n;
    for(int i=0;i<n;++i)
        cin>>a[i];
    ll res=a[n-1]-a[0];
    for(int i=1;i<n;++i)
        res=min(res,labs(k+a[(i+n-1)%n]-a[i]));
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;





int main(){

	int x;
	scanf("%d",&x);

	if(x < 1200){

		printf("ABC\n");

	}else{

		printf("ARC\n");
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
bool ok(int a){
    if(a==0 || a>12){
        return false;
    }
    return true;
}
int main(){
    int n;
    cin >> n;
    int a = n/100;
    int b = n%100;
    if(ok(a) && ok(b)){
        cout << "AMBIGUOUS" << endl;
    }
    else if(!ok(a) && ok(b)){
        cout << "YYMM" << endl;
    }
    else if(ok(a) && !ok(b)){
        cout << "MMYY" << endl;
    }
    else{
        cout << "NA" << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner kbd = new Scanner(System.in);
    void run(){
	int n = kbd.nextInt();
	int data = 0;
	while(n>0){
	    if(data>0)
		System.out.println();
	    solve();
	    n--;
	    data++;
	}
    }


    void solve(){
	int[][] field = new int[9][9];
	boolean[][] tf = new boolean[9][9]; // 正しい入力がされているか？
	int i, j;
	for(i=0; i<9; i++)	
	    Arrays.fill(tf[i], true);
	for(i=0; i<9; i++){
	    for(j=0; j<9; j++){
		field[i][j] = kbd.nextInt();
	    }
	}
	// 入力ここまで

	// チェックここから
	/*
	  1から9までが1つずつ使われていればtrue
	  足りない数字がある = 多い数字があるから、多いマスをfalseにする
	*/

	int[] c; // チェックする数字の固まり
	int[][] x; // チェック中の座標

	// i ラインチェック
	for(i=0; i<9; i++){
	    c = new int[9];
	    x = new int[9][2];
	    for(j=0; j<9; j++){
		int d = field[i][j]-1; // マスにある数字
		c[d]++;
		if(c[d]>1){
		    tf[i][j] = false;
		    tf[x[d][0]][x[d][1]] = false;
		}
		else{
		    x[d][0] = i;
		    x[d][1] = j;
		}
	    }
	}

	// j ラインチェック
	for(j=0; j<9; j++){
	    c = new int[9];
	    x = new int[9][2];
	    for(i=0; i<9; i++){
		int d = field[i][j]-1; // マスにある数字
		c[d]++;
		if(c[d]>1){
		    tf[i][j] = false;
		    tf[x[d][0]][x[d][1]] = false;
		}
		else{
		    x[d][0] = i;
		    x[d][1] = j;
		}
	    }
	}

	// 四角区切りチェック
	for(int si=0; si<9; si+=3){
	    for(int sj=0; sj<9; sj+=3){
		c = new int[9];
		x = new int[9][2];
		for(i=si; i<si+3; i++){	    
		    for(j=sj; j<sj+3; j++){
			int d = field[i][j]-1; // マスにある数字
			c[d]++;
			if(c[d]>1){
			    tf[i][j] = false;
			    tf[x[d][0]][x[d][1]] = false;
			}
			else{
			    x[d][0] = i;
			    x[d][1] = j;
			    //System.out.println("*"+x[d][0]+" "+x[d][1]+"*");
			}
		    }
		}
		//System.out.println();
	    }
	}
	    
	// 表示
	for(i=0; i<9; i++){
	    for(j=0; j<9; j++){
		if(tf[i][j]){
		    System.out.print(" "+field[i][j]);
		}
		else 
		    System.out.print("*"+field[i][j]);
	    }
	    System.out.println();
	}
    }
}
	

Measured memory_bytes: 23472
import java.util.*;
import java.io.*;

public class Main {	

	private static void solve(){
		//Implement solution here.
		int N = ni();
		int M = ni();		
		int[] A = na(M);

		Arrays.sort(A);
		int idx = 0;		
		while(idx < M) {
			if(N - A[idx] >= 0) {
				N -= A[idx];
				idx++;
			} else {
				break;
			}
		}			
		System.out.println(idx == M ? N : -1);
	}

	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		boolean hasNext = true;
		while(hasNext){
			solve();	
			try{
				br.mark(1);
				if(br.read() > 0){
					br.reset();			
					System.out.println("---");
				} else {
					hasNext = false;
				}
			}catch(Exception e){
				throw new RuntimeException(e);
			} 
		}
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 28344
#include <bits/stdc++.h>
         
typedef long long ll;
using namespace std;
        
#define F first
#define S second
#define sqr(x) x*x
#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define repit(i, n) for(auto it = n.begin(); it != n.end(); ++it)
       
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
int lcm(int a,int b){return abs(a*b)/gcd(a,b);}

int main(){ios_base::sync_with_stdio(0);cin.tie(0);
    ll a , b, x;
    ll ans = 0;
    cin >> a >> b >> x;
    if(a == 0){
        ans  = b / x + 1;
        cout << ans;
        exit(0);
    }
     ans = b / x - ((a - 1) / x);
    cout << ans ;
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int H,W,N;
int x[100000],y[100000],v[100000];

vpint lis[100000];

int par[100000],sz[100000],dif[100000],mi[100000];
vint mem[100000];

void init(){
    rep(i,W){
        par[i]=i;
        sz[i]=1;
        dif[i]=0;
        mi[i]=0;
        mem[i].clear();
        mem[i].pb(i);
    }
}

int find(int x){
    return x==par[x]?x:par[x]=find(par[x]);
}

bool unite(int x,int xx,int h,int hh){
    int y=find(x);
    int yy=find(xx);

    if(y==yy){
        int tmp=dif[xx]-dif[x];
        return tmp==hh-h;
    }

    if(sz[y]<sz[yy]){
        swap(y,yy);
        swap(x,xx);
        swap(h,hh);
    }

    int tmp=dif[xx]-dif[x]-(hh-h);
    for(auto u:mem[yy]){
        dif[u]-=tmp;
        chmin(mi[y],dif[u]);
        mem[y].pb(u);
    }
    sz[y]+=sz[yy];
    par[yy]=y;

    return true;
}

bool f(){
    rep(i,H)lis[i].clear();
    rep(i,N){
        lis[y[i]].pb(pint(x[i],i));
    }
    rep(i,H)sort(all(lis[i]));
    init();

    rep(i,H){
        for(int j=0;j+1<lis[i].size();j++){
            int x=lis[i][j].fi;
            int xx=lis[i][j+1].fi;
            int k=lis[i][j].se;
            int kk=lis[i][j+1].se;
            if(!unite(x,xx,v[k],v[kk]))return false;
        }
    }

    rep(i,N){
        int p=find(x[i]);
        int tmp=v[i]-dif[x[i]]+mi[p];
        if(tmp<0)return false;
    }
    return true;
}

signed main(){
    cin>>H>>W>>N;
    rep(i,N)cin>>y[i]>>x[i]>>v[i],x[i]--,y[i]--;

    bool ok=true;
    rep(t,2){
        ok&=f();
        swap(H,W);
        rep(i,N)swap(x[i],y[i]);
    }
    if(ok)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

int main(void){
  int n, k;
  long long data[100000];
  long long sum[100000];
  while(cin >> n >> k, n | k){
    for(int i=0; i < n; i++){
      cin >> data[i];
    }
    for(int i=1; i < n; i++){
      data[i] += data[i-1];
    }
    long long ans = 0;
    for(int i=k; i < n; i++){
      ans = max(ans, data[i] - data[i-k]);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1944
h,w=map(int,input().split())
A=[list(input()) for i in range(h)]
B=[['#' for i in range(w+2)] for i in range(h+2)]
for i in range(h):
    for j in range(w):
        B[i+1][j+1]=A[i][j]
for b in B:
    print(''.join(b))

Measured memory_bytes: 9280
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U> inline void cmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> inline void cmin(T &a, U b) { if (a > b) a = b; }
constexpr char el = '\n';
template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) os << v[i] << (i+1 != v.size() ? " " : ""); return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for(T &i : v) is >> i; return is; }
struct IoSetup {
  IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); }
} io_setup;
#line 2 "c.cpp"

int main() {
  uint64_t a;
  string s;
  cin >> a >> s;
  uint64_t c = 0;
  c += (s[0]-'0')*100;
  c += (s[2]-'0')*10;
  c += (s[3]-'0');

  cout << a*c/100 << el;
}


Measured memory_bytes: 3644
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
#define MAXN 100000
#define DB double
int n;
DB a,sum;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{scanf("%lf",&a);sum+=1.0/a;}
	printf("%.8f",1/sum);
}

Measured memory_bytes: 256