akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<bool> vb;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const double pi=acos(-1);
const double eps=1e-8;

class Network{
	private:
	int GV,GE;
	struct edge{
		int to,cap,rev;
	};
	vector<vector<edge> > List;
	int DFS(int v,int t,int f,vb& used){
		if(v==t) return f;
		used[v]=1;
		for(int i=0;i<List[v].size();i++){
			edge &e=List[v][i];
			if(!used[e.to]&&e.cap>0){
				int d=DFS(e.to,t,min(f,e.cap),used);
				if(d>0){
					e.cap-=d;
					List[e.to][e.rev].cap+=d;
					return d;
				}
			}
		}
		return 0;
	}
	public:
	Network(int v,int e){
		GV=v;
		GE=e;
		List=vector<vector<edge> >(v);
	}
	void add_edge(int s,int t,int c){
		List[s].push_back(edge{t,c,(int)List[t].size()});
		List[t].push_back(edge{s,0,(int)List[s].size()-1});
	}
	int MF(int s,int t){
		int ans=0;
		while(1){
			vb used(GV);
			int f=DFS(s,t,inf,used);
			if(f==0) return ans;
			ans+=f;
		}
	}
};

int V,E;

int main(){
	cin>>V>>E;
	Network net(V,E);
	int s,t,c;
	for(int i=0;i<E;i++){
		cin>>s>>t>>c;
		net.add_edge(s,t,c);
	}
	cout<<net.MF(0,V-1)<<endl;
}

Measured memory_bytes: 1272
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int p, q, r, ans = 0;
        while (n-- > 0) {
            p = sc.nextInt();
            q = sc.nextInt();
            r = q - p + 1;
            ans += r;
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 27852
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) (x).begin(), (x).end()
template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	string s, t;
	cin >> s >> t;
	int res = 0;
	for (int i = 0; i < (int)s.size(); i++)
		res += (s[i] != t[i]);
	cout << res;
}


Measured memory_bytes: 3820
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */
void print(ll x, ll y){
  cout << x << " " << y << endl;
}

int main() {
  ll n; cin >> n;
  if(n%2 == 0){
    cout << n*(n-2)/2 << endl;
    FOR(i, 1, n/2) FOR(j, i+1, n/2+1){
      print(i, j);
      print(i, n+1-j);
      print(n+1-i, j);
      print(n+1-i, n+1-j);
    }
    return 0;
  }

  //n%2 == 1
  cout << (n-1) * (n-1) /2 << endl;
  FOR(i, 1, n) print(n, i);
  FOR(i, 1, (n-1)/2) FOR(j, i+1, (n-1)/2+1){
      print(i, j);
      print(i, n-j);
      print(n-i, j);
      print(n-i, n-j);
    }
}



Measured memory_bytes: 256
using System;
using System.Linq;
class P
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        int[] a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        long  c = 0;
        long m = 0;
        foreach(int i in a)
        {
            if (i > m) m = i;
            else if (i < m)
            {
                c += m - i;
            }
        }
        Console.WriteLine(c);
    }
}


Measured memory_bytes: 47184
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;

#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <climits>
using Graph = vector<vector<int>>;
const double PI = 3.14159265358979323846;



long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}


//約数をベクトル形式で返す
vector<int> vect_yakusuu(int n) {
	vector<int> ret;
	for (int i = 1; i*i <= n; i++) {
		if (n%i == 0) {
			ret.push_back(i);
			if (i*i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret));
	return ret;
}



int main() {

	long long ans;
	int a;
	string s, t;

	const int size = 2000;

	long long N, M, K;
	int A[size], B[size];
	long long sumA[size], sumB[size];


	cin >> N;

	ans = 0;
	long long num;

	for (long long i = 1; i < N + 1; i++) {
		num = N / i;
		ans += num*(num + 1) / 2 * i;
	}



	cout << ans << endl;

	cin >> ans;

	return 0;


}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;


void solve() {
}
int A, B;
string S, T, U;
signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> S >> T >> A >> B >> U;
    if (U == S)
        A--;
    if (U == T)
        B--;
    cout << A << " " << B << endl;
    solve();
    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
A = list(map(int, input().split()))

# 見る建物を決め打ち、コストを計算して最小値が答え。
# 左端は見えてしまうので、それを除いたn-1個からk-1個を選ぶ

from itertools import combinations

ptn = combinations(range(1, n), k - 1)

ans = 10 ** 19
for p in ptn:
  totalcost = 0
  repA = A[:]
  for itr, val in enumerate(p):
    cost = max(0, max(repA[:val]) + 1 - repA[val])
    repA[val] += cost
    totalcost += cost
  ans = min(ans, totalcost)
print(ans)

Measured memory_bytes: 3064
//
// Created by Takaaki Hirano on 2018/09/01.
//
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>

using namespace std;
int N, K;
long long ans = 0;

void solve() {
    unordered_map<long long, long long> mp;
    // あまりを保持しておく
    for (int i = 1; i <= N; ++i) mp[i % K]++;

    // 全てのaに対して
    for (auto a_mod: mp) {
        // aに対するb, cのあまり（等しくなる）
        int b = (K - a_mod.first) % K;
        int c = (K - a_mod.first) % K;

        // 場合の数を数えるためにあまりの場合の数を求める．
        if ((b + c) % K == 0) ans += a_mod.second * mp[b] * mp[c];
    }

    printf("%lli\n", ans);
}

int main() {
    cin >> N >> K;
    solve();
    return 0;
}

Measured memory_bytes: 4388
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,w;
    cin>>n>>w;
    vector<ll>W(n),V(n);
    ll Vmax=0;
    for(ll i=0;i<n;i++)
    {
        cin>>W[i]>>V[i];
        Vmax+=V[i];
    }
    vector<ll>dp(Vmax+1,INT_MAX);
    dp[0]=0;
    for(ll i=0;i<n;i++)
    {
        vector<ll>dp1=dp;
        for(ll v1=1;v1<=Vmax;v1++)
        {
            ll tmp=INT_MAX;
            if(v1>=V[i])
                tmp=W[i]+dp1[v1-V[i]];
            dp[v1]=min(dp[v1],tmp);
        }
    }
    for(ll v=Vmax;v>0;v--)
    {
        if(dp[v]<=w)
        {
            cout<<v;
            break;
        }
    }
}

Measured memory_bytes: 1792
n = int(input())
a = [0]*n

for i in range(n):
  a[i] = int(input())
  
a.sort()
a.append(-1)
ans = []
cn = 0
c = 1
#print(a)
for i in range(n):
  if a[i] != a[i+1]:
    ans.append(c)
    c = 1
  else:
    c += 1
#print(ans)

for i in range(len(ans)):
  if ans[i]%2 == 1:
    cn += 1
    
print(cn)

Measured memory_bytes: 82980
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)
#define debug(var) cout << "[" << #var << "] " << var << endl

const int INF = 1<<29;
const double EPS=1e-9;
const int MOD=998244353;

signed main() {
    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    rep(i, N) cin >> p[i];
    sort(all(p));
    int ans = 0;
    rep(i, K) ans += p[i];
    cout << ans;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> v(N);
  for(int i = 0; i < N; i++){
    cin >> v.at(i);
  }
  sort(v.begin(),v.end());
  cout << abs(v.at(0) - v.at(N-1)) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0; i<(n); i++)	//for文
#define REP2(i,x,n) for(int i=x; i<(n); i++)	//for文
int gcd(int a,int b){return b?gcd(b,a%b):a;}    //最大公約数
int lcm(int a, int b) {return a * b / gcd(a, b);}   //最小公倍数

int main()
{
    int N;
    cin>>N;
    int A[N];
    int c=0;
    
    REP(i,N){
        cin>>A[i];
    }
    bool flag=true;

    while(flag){
    REP(i,N){
        if(A[i]%2!=0)
            flag=false;
        else
            A[i]/= 2;    
    }
        if(flag)
            ++c;
    }
    cout<<c<<endl;
}

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

using namespace std;

#define int long long

signed main() {
  int m, rd, rr, cd, cr;
  cin >> m >> rd >> rr >> cd >> cr;
  int x = 100*cd/rd;
  int y = 100*cr/rr;
  if(100*cd%rd) x++;
  if(100*cr%rr) y++;
  int ans = m-x-y;
  cout << (ans < 0 ? -1 : ans) << endl;
  return 0;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define int long long
#define iris 998244353
using namespace std;

int dp[3010][3010];

int sana(int a,int b,int c,int d)
{
	if(c<a || d<b)
	{
		return 0;
	}
	else if(c==a && b==d)
	{
		return dp[c][d]=1;
	}
	else if(dp[c][d])
	{
		return dp[c][d];
	}
	
	dp[c][d]=(sana(a,b,c-1,d)*d+sana(a,b,c,d-1)*c-sana(a,b,c-1,d-1)*(c-1)*(d-1))%iris;
	dp[c][d]=(dp[c][d]+iris)%iris;
	return dp[c][d];
}

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<sana(a,b,c,d)<<'\n';
	
	return 0;
}

Measured memory_bytes: 74576
#include <stdio.h>

int main(){

int card[4][13]={}; 

int n; 

int i; 

scanf("%d",&n);

char mark[n];

int rank[n];

for(i=1;i<=n;i++){

  scanf("%*c%c",&mark[i-1]);

  scanf(" %d",&rank[i-1]);

	}

int k=0;

for(k=0;k<=n-1;k++){
	
	if(mark[k]=='S'){

		card[0][rank[k]-1]=1;

		}

	if(mark[k]=='H'){

		card[1][rank[k]-1]=1;

		}

	if(mark[k]=='C'){

		card[2][rank[k]-1]=1;

		}

	if(mark[k]=='D'){

		card[3][rank[k]-1]=1;

		}

	}
	
int x,y;

for(x=0;x<=3;x++){

	for(y=0;y<=12;y++){

		if(card[x][y]==0){

			if(x==0)

				printf("S %d",y+1);

			if(x==1)

				printf("H %d",y+1);

			if(x==2)

				printf("C %d",y+1);

			if(x==3)

				printf("D %d",y+1);

			printf("\n");

			}

		}

	}

return 0;

}

Measured memory_bytes: 600
// Author : Mohamed Sameh
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define Flush fflush(stdout);
typedef long long ll ;
using namespace std ;
int n, k ;
const int M = 2e5 ;
int a[M];
ll ans = 1e18 ;
int main()
{
     cin >> k >> n ;
     for (int i =0 ; i < n ;i++)
     {
         cin >> a[i];
     }
     ans = min ( a[n-1] - a[0] , a[0] + k - a[1]); 
     for (int i =0 ; i + 1 < n ;i++)
     {
         ans = min (ans , 1LL*k - a[i+1] + a[i]);
     }
     cout << ans <<"\n"; 
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define maxn 10000
using namespace std;
int main()
{
    int n;
    int w[105];
    scanf("%d",&n);
    int sum1=0;
    int sum2=0;
    for(int i=0; i<n; i++)
    {
        scanf("%d",&w[i]);
        sum2+=w[i];
    }
    int c=10000;
    for(int i=0; i<n; i++)
    {
        if(sum2-sum1==0)
        {
            printf("0\n");
            break;
        }
        else if(abs(sum2-sum1)<c)
        {
            c=abs(sum2-sum1);
            sum1+=w[i];
            sum2-=w[i];
        }
        else
        {
            printf("%d\n",c);
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
nedan = set()
nedan.add(min(a) + min(b))
for i in range(M):
    j, k, l = map(int, input().split())
    nedan.add(a[j - 1] + b[k - 1] - l)
print(min(nedan))

Measured memory_bytes: 18736
import java.io._
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.reflect.ClassTag

object Main {
  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val S = sc.next()
    val cnt = Array.ofDim[Int](3)
    rep(S.length)(i => cnt(S(i) - 'a') += 1)

    val ok = cnt.max - cnt.min <= 1
    val ans = if (ok) "YES" else "NO"

    out.println(ans)
  }

  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  def rep(n: Int)(f: Int => Unit): Unit = {
    var i = 0
    while(i < n) { f(i); i += 1 }
  }
  def rep_r(n: Int)(f: Int => Unit): Unit = {
    var i = n - 1
    while(i >= 0) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}


Measured memory_bytes: 28884
/* atcoder */
#include "bits/stdc++.h"
using namespace std;

/* typedef */
/* long系 */
typedef long long ll;   // long long
typedef long double ld; // long double
/* vector系 */
typedef vector<int> vi;                    // intのvector
typedef vector<double> vd;                 // doubleのvector
typedef vector<ll> vll;                    // llのvector
typedef vector<ld> vld;                    // ldのvector
typedef vector<vector<int>> vvi;           // intの2次元vector
typedef vector<vector<double>> vvd;        // doubleの2次元vector
typedef vector<vector<ll>> vvll;           // llの2次元vector
typedef vector<vector<ld>> vvld;           // ldの2次元vector
typedef vector<pair<int, int>> vi_i;       // i_iのvector
typedef vector<pair<double, double>> vd_d; // d_dのvector
typedef vector<pair<ll, ll>> vl_l;         // l_lのvector
typedef vector<pair<ld, ld>> vld_ld;       // ld_ldのvector
typedef vector<string> vs;                 // stringのvector
/* pair系 */
typedef pair<int, int> i_i;       // int同士のpair
typedef pair<double, double> d_d; // double同士のpair
typedef pair<ll, ll> l_l;         // ll同士のpair
typedef pair<ld, ld> ld_ld;       // ld同士のpair

/* define */
#define all(v) v.begin(), v.end() // コンテナ全体
#define PI (acos(-1))             // 円周率pi

/* stringstream */
stringstream ss;
stringstream init_ss; // save default formatting

/* upper, lower */
struct ToUpper
{
    char operator()(char c)
    {
        return toupper(c);
    }
};
struct ToLower
{
    char operator()(char c)
    {
        return tolower(c);
    }
};

/* main */
void Main(void)
{
    while (true)
    {
        int n;
        cin >> n;
        if (n == 0)
        {
            return;
        }
        vd a;
        a.resize(n);
        for (int rv = 0; rv < n; rv++)
        {
            cin >> a[rv];
        }
        double ave = accumulate(begin(a), end(a), 0.0) / (double)a.size();
        transform(begin(a), end(a), begin(a), [ave](double e) { return e - ave; });
        double var = inner_product(begin(a), end(a), begin(a), 0.0) / (double)a.size();
        cout << sqrt(var) << endl;
    }
}

int main(int argc, char const *argv[])
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();

    return 0;
}



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

const int INF = 1001001001;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  ll ans = 0;
  vector<vector<int>> visited(h, vector<int>(w, 0));
  rep(si,h)rep(sj,w) {
    if (s[si][sj] == '#') continue;
    queue<P> q;
    ll c_w = 0;
    ll c_b = 0;
    auto update = [&](int i, int j) {
      if (visited[i][j])return;
      visited[i][j] = 1;
      if(s[i][j]=='#')c_b++;
      else c_w++;
      q.push(P(i,j)); // .emplace(i,j)
    };
    update(si,sj);
    while (!q.empty()) {
      int i = q.front().first;
      int j = q.front().second; q.pop();
      rep(dir,4) {
        int ni = i+di[dir], nj = j+dj[dir];
        if (ni<0||ni>=h||nj<0||nj>=w) continue;
        if (s[ni][nj] == s[i][j]) continue;
        update(ni, nj);
      }
    }
    //cout << c_w << ' ' << c_b << endl;
    ans += c_w*c_b;
    // rep(i,h)rep(j,w) {
    //   if (dist[i][j] == INF) continue;
    //   ans = max(ans, dist[i][j]);
    // }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N)
  {
    cin >> A[i];
  }
  vector<int> B = A;
  // 降順ソート
  sort(B.rbegin(), B.rend());
  rep(i, N)
  {
    int ans = B[0];
    if (B[0] == A[i])
    {
      ans = B[1];
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3200
"""
    こんにちは。これはクシャルです
    
    Author : thekushalghosh (クシャル)
    Team   : CodeDiggers
 
    I prefer Python language over the C++ language :p :D
        
    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time,itertools
start_time = time.time()
##########################################################################
################# ---- THE ACTUAL CODE STARTS BELOW ---- #################
a = [0] * 10000
for i in range(1,100):
    for j in range(1,100):
        for k in range(1,100):
            if (i ** 2) + (j ** 2) + (k ** 2) + (i * j) + (j * k) + (k * i) <= 10000:
                a[(i ** 2) + (j ** 2) + (k ** 2) + (i * j) + (j * k) + (k * i) - 1] += 1
    
def solve():
    global a
    n = inp()
    for i in range(n):
        print(a[i])
    
################## ---- THE ACTUAL CODE ENDS ABOVE ---- ##################
##########################################################################
 
def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
        sys.stdout.close()
    
#---------------------- USER DEFINED INPUT FUNCTIONS ----------------------#
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))
 
#------------------ USER DEFINED PROGRAMMING FUNCTIONS ------------------#
def counter(a):
    q = [0] * max(a)
    for i in range(len(a)):
        q[a[i] - 1] = q[a[i] - 1] + 1
    return(q)

def counter_elements(a):
    q = dict()
    for i in range(len(a)):
        if a[i] not in q:
            q[a[i]] = 0
        q[a[i]] = q[a[i]] + 1
    return(q)

def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97],1
    return(q)
 
def factors(n):
    q = []
    for i in range(1,int(n ** 0.5) + 1):
        if n % i == 0: q.append(i); q.append(n // i)
    return(list(sorted(list(set(q)))))
 
def prime_factors(n):
    q = []
    while n % 2 == 0: q.append(2); n = n // 2
    for i in range(3,int(n ** 0.5) + 1,2):
        while n % i == 0: q.append(i); n = n // i
    if n > 2: q.append(n)
    return(list(sorted(q)))

def transpose(a):
    n,m = len(a),len(a[0])
    b = [[0] * n for i in range(m)]
    for i in range(m): 
        for j in range(n): 
            b[i][j] = a[j][i]
    return(b)

#-----------------------------------------------------------------------#
        
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline
    
main()

Measured memory_bytes: 69736
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << setw(5) << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int H, W, K;
	cin >> H >> W >> K;

	vector<vector<char>> grid(H, vector<char>(W));
	vector<vector<int>> ans(H, vector<int>(W));
	int cnt = 1;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> grid[i][j];
			if (grid[i][j] == '#') ans[i][j] = cnt++;
		}
	}

	auto dfs_r = [&](auto &&f, int row, int col) -> void {
		if (col - 1 >= 0 && ans[row][col - 1] == 0) {
			ans[row][col - 1] = ans[row][col];
			f(f, row, col - 1);
		}
		if (col + 1 < W && ans[row][col + 1] == 0) {
			ans[row][col + 1] = ans[row][col];
			f(f, row, col + 1);
		}
	};

	auto dfs_c = [&](auto &&f, int row, int col) -> void {
		if (row - 1 >= 0 && ans[row - 1][col] == 0) {
			ans[row - 1][col] = ans[row][col];
			f(f, row - 1, col);
		}
		if (row + 1 < H && ans[row + 1][col] == 0) {
			ans[row + 1][col] = ans[row][col];
			f(f, row + 1, col);
		}
	};

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (ans[i][j]) dfs_c(dfs_c, i, j);
		}
	}

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (ans[i][j]) dfs_r(dfs_r, i, j);
		}
	}

	cout  << ans << "\n";

	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <cstdio>
#include <cstdlib>

typedef long long int lld;
typedef unsigned long long int ulld;
const int mod = 1000000007;

using namespace std;

int uinps[3];

int main (void) {
	ios::sync_with_stdio (false);
	cin >> uinps[0] >> uinps[1] >> uinps[2];
	sort (uinps, uinps + 3);
	if (uinps[0] == 5 && uinps[1] == 5 && uinps[2] == 7) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
const int mod = 1e9+7;
const Int Inf = 1e17;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define mp make_pair
#define Pr(t) priority_queue<t>
#define gPr(t) priority_queue<t,vector<t>,greater<t>>
#define V(t) vector<t>
#define rep(i,n) for(int(i)=0; i<n; i++)
#define rer(i,l,r) for(int i=l; i<=r; i++)
#define gnr(i,l,r) for(int i=r; i>=l; i--)
#define eb emplace_back
#define pri1(a) cout<<(a)<<'\n'
#define pri2(a,n) {rep(pri2i,n-1)cout<<a[pri2i]<<' '; if(n>1)cout<<a[n-1]<<'\n';}
#define prip(p) cout<<p.fi<<' '<<p.se<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n,m,_,x,y,q;
string s,sb;
bool ok;
char cf,cb;

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

  int n,ans=1; cin>>n; int a[n];
  rep(i,n)cin>>a[i]; if(n==1||n==2)END
  int st=2;
  rep(i,n-1){
    if(st==0){
      if(a[i+1]>a[i]){ans++; st=2;}
      else continue;
    }else if(st==1){
      if(a[i+1]<a[i]){ans++; st=2;}
    }else{
      if(a[i+1]>a[i])st=1;
      else if(a[i+1]<a[i])st=0;
    }
  }
  END
}

Measured memory_bytes: 640
#include <iomanip>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
 
int N;
int x[10], y[10];
 
double dist(int i, int j) {
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx * dx + dy * dy, 0.5);
}
 
void solve() {
    cin >> N;
    for(int i = 1; i <= N; i++) cin >> x[i] >> y[i];
    double sum = 0.0;
    vector<int> v(N);
    for(int i = 0; i < N; i++) v[i] = i + 1;
    do {
        for(int i = 0; i < N - 1; i++) sum += dist(v[i], v[i+1]);
    } while(next_permutation(v.begin(), v.end()));
    int Factorial = 1;
    for(int i = 2; i <= N; i++) Factorial *= i;
    cout << fixed << setprecision(10) << sum / Factorial << endl;
    return;
}
 
int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;

const int md = (1.0e+9)+7;

bool is_ng(int a,int b,int c,int d){
  bool t = (b==0&&c==2&&d==1);
  t |= (b==2&&c==0&&d==1);
  t |= (b==0&&c==1&&d==2);
  t |= (a==0&&c==2&&d==1);
  t |= (a==0&&b==2&&d==1);
  return t;
}

void add(int&a,int&b){
  a=(a%md+b%md)%md;
}

int main(){
  int n;cin>>n;
  int dp[110][4][4][4]={};
  fill(dp[0][0][0],dp[0][0][0]+4,1);
  for(int i=0;i<4;++i)
	for(int j=0;j<4;++j)
	  dp[1][0][j][i]+=dp[0][0][0][j];
  for(int i=2;i<n;++i){
	for(int j=0;j<4;++j){
	  for(int k=0;k<4;++k){
		for(int l=0;l<4;++l){
		  if(i==2){
			if(!is_ng(-1,l,k,j)){
			  add(dp[2][l][k][j],dp[1][0][l][k]);
			}
			continue;
		  }
		  for(int m=0;m<4;++m){
			if(!is_ng(m,l,k,j))
			  add(dp[i][l][k][j],dp[i-1][m][l][k]);
		  }
		}
	  }
	}
  }
  int sum=0;
  for(int i=0;i<4;++i)
	for(int j=0;j<4;++j)
	  for(int k=0;k<4;++k)
		add(sum,dp[n-1][i][j][k]);

  cout<<sum<<endl;
	
}


Measured memory_bytes: 256
i = input().split()
h = int(i[0])
w = int(i[1])

if h == 1 or w == 1:
    print(1)
else:
    if (h * w % 2 == 0):
        print(h * w // 2)
    else:
        print(h * w // 2 + 1)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define MAX 1e6
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set


int main() 
{
	ll n,m;
	cin>>n>>m;
	ll sum = 0;
	REP(i,0,m){
		ll x;
		cin>>x;
		sum += x;
	}
	if(sum <= n) cout<<n - sum<<endl;
	else cout<<-1<<endl;

	return 0;
}  


Measured memory_bytes: 3624
N, M = gets.split.map(&:to_i)
S = gets.chomp
T = gets.chomp

g = N.gcd(M)
l = N.lcm(M)

g.times do |i|
    if S[N/g*i] != T[M/g*i]
        puts -1
        exit
    end
end
puts l

Measured memory_bytes: 2044
#include <iostream>
#include <vector>
#include <string>
using namespace std;
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; }

// MOD
const int MOD = 1000000007;

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int sum = 0;

int main() {
    int K; cin >> K;
    for(int i=1; i<=K; i++){
        for(int j=1; j<=K; j++){
            for(int k=1; k<=K; k++){
                sum += GCD(GCD(i, j), k);
            }
        }
    }
    cout << sum << endl;

}

Measured memory_bytes: 3192
import sys
n = int(input())
ls = [list(map(int,input().split())) for _ in range(n)]
for i in range(n-2):
    if ls[i][0] == ls[i][1]:
        if ls[i+1][0] == ls[i+1][1]:
            if ls[i+2][0] == ls[i+2][1]:
                print("Yes")
                sys.exit()
print("No")

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

#define db(x) cout<<x<<'\n'
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define repi(i,n) for(int i=0;i<(n);++i)
//#define repA(i,a,n) for(int i=a;i<=(n);++i)
//#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define ll long long int
#define endl '\n'
#define lld long long double
#define vi vector<int> 
#define vl vector<ll> 
#define vb vector<bool> 
#define vvi vector<vector<int>  >
#define err(t) cout<<"Error : "<<t<<endl;
#define all(v) v.begin(),v.end()
#define mp make_pair
#define M 100000
#define MD 1000000007 //998244353
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= (b); i++)
#define pii pair<int,int>
#define pll pair<ll,ll> 
#define vec(a) vector<a >
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
//template <typename T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll binpow(ll a,ll b){	if(a==0) return 0; if(b==0) return 1;ll ans=1;while(b>0){if(b&1) ans=ans*a; a=a*a; b=b>>1;}	return ans;}


int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	// int n;cin>>n;
	// string s;cin>>s;
	
	//ll n;cin>>n; vl a(n); repi(i,n) cin>>a[i];
	long double a,b;
	cin>>a>>b;
	//db(b);
	a*=b;
	ll ans=a;
	db(ans);
	
	/*
	int test1;cin>>test1;while(test1--){ 
		
	 }
	 //*/
return 0;
}



Measured memory_bytes: 3744
# 問題が少しわかりずらい。
n = int(input())
w = list(map(int, input().split()))
a = 10**19
for i in range(1, n-1):
  	# 重りを二つに分け、差異の最小値を判定する。
    a = min(abs(sum(w[:i+1]) - sum(w[i+1:])), a)
print(a)


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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

int main(){
  int n;
  cin >> n;
  vector<int>a(n+1);
  rep(i, 1, n+1)cin>>a[i];
  int ans = 0;
  rep(i, 1, n+1){
    if(a[i]%2==1&&i%2==1)ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#!/usr/bin/python

import sys

def solution(A, B, C, D, E, F):
    max_percentage = -1
    mass = 0
    mass_sugar = 0

    for c in xrange(0, int(F/C) + 1):
        if (c * C) > F:
            break

        for d in xrange(0, int(F/D) + 1):
            sugar = c * C + d * D
            if sugar > F:
                break

            for a in xrange(0, int(F/A) + 1):
                if (sugar + 100 * a * A) > F:
                    break

                for b in xrange(0, int(F/B) + 1):
                    water = 100 * a * A + 100 * b * B
                    if (sugar + water) > F:
                        break
                    elif (sugar + water) == 0:
                        continue

                    if sugar <= (int(water / 100) * E):
                        if water > 0:
                            percentage = float(sugar) / water * 100
                        else:
                            percentage = 0

                        if percentage > max_percentage:
                            mass = sugar + water
                            mass_sugar = sugar
                            max_percentage = percentage

                        if max_percentage == 100:
                            return mass, mass_sugar

    return mass, mass_sugar

def main(argv):
    line = sys.stdin.readline()

    while line:
        A, B, C, D, E, F = map(int, line.rstrip("\n").split(" ", 6))

        mass, mass_sugar = solution(A, B, C, D, E, F)
        print("{0} {1}".format(mass, mass_sugar))

        exit(0)
        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Measured memory_bytes: 2696
n = int(input())

def find(d):
    pp = False
    p = False
    for d1, d2 in d:
        now = (d1 == d2)
        if pp and p and now:
            return True
        pp = p
        p = now

    return False

d = list()
for i in range(n):
    d1, d2 = map(int, input().split())
    d.append((d1, d2))

if find(d):
    print('Yes')
else:
    print('No')


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

const int MAXN = 2e5+5;

ll n, a[MAXN];

int main() {
	cin >> n;
	bool z = 1;

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

	if (a[0] != 0)
		z = 0;
	for (int i = 0; i < n-1; ++i)
		if (a[i] < a[i+1])
			z = 0;
	if (z == 0) {
		cout << -1 << endl;
		return 0;
	}

	ll ans = 0;
	for (int i = 0; i < n; ++i) {
		if (i < n-1 && a[i+1] == a[i])
			continue;
		ans += i + a[i];
	}

	cout << ans << endl;
}

Measured memory_bytes: 1792
str = gets.chomp.to_s
count = 0
str.length.times do |num|
  if num %2 == 0
    if str[num] == "0"
      str[num] = "1"
      count += 1
    end
  elsif num %2 == 1
    if str[num] == "1"
      str[num] = "0"
      count += 1
    end
  end
end
puts [count, str.length - count].min

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

int main()
{
    int A, B;
    cin >> A >> B;
    if(abs(A - B) % 2 == 0)
    {
        cout << max(A - (abs(A - B) / 2), B - (abs(A - B) / 2)) << endl;
    }
    else
    {
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
using namespace std;
int main(){	
	double N,num=0.0000000000;
	double jl;
	cin>>N;
	for(int i=1;i<=N;i++){
		if(i%2==1)num++;			
	}
	jl=(num*1.0000000000)/(N*1.000000000);
	cout<<fixed<<setprecision(10)<<jl<<endl;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define pi 3.14159265358979323846
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

int main()
{

  int n; cin >> n;
  vector<string> s(n);
  rep(i,n){
    cin >> s[i];
    sort(s[i].begin(),s[i].end());
  }
  sort(s.begin(),s.end());

  ll ans=0;
  int x;

  rep(i,n){
    if(i==0){x=1;}
    else {
      if (s[i]!=s[i-1]){
        x=1;
      }
      else {ans+=x;x++;}
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 7296
# -*- coding: utf-8 -*-
import sys
import math

tmp = input().split()
n,k = list(map(lambda a: int(a), tmp))

#s = int(input())
#tmp = input().split()
#n,m,k = list(map(lambda a: int(a), tmp))

ans=[]
for i in range(n):
	ans.append(0)

for i in range(k):
	d = int(input())
	tmp = input().split()
	s = list(map(lambda a: int(a), tmp))
	for j in range(d):
		ans[s[j]-1]+=1

num=0
for i in range(n):
	if(ans[i]==0):
		num+=1
print(num)





Measured memory_bytes: 9204
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

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


int N;
ll K;
ll a[110000];
ll dp[60][2];

int main () {
  cin >> N >> K;
  Rep(i, N) cin >> a[i];

  Rep(i, 59) {
    dp[i][0] = dp[i][1] = -1;
  }

  dp[45][0] = 0;

  for (int k=44;k>=0;--k) {
    ll mask = 1LL << k;
    int num = 0; // a内のk bit目の1の個数
    Rep(i, N) {
      if (a[i] & mask) ++num; 
    }

    // 「Kよりも小さい」から「Kよりも小さい」への遷移。自由に最適なものを選べる
    if (dp[k+1][1] >= 0) chmax(dp[k][1], dp[k+1][1] + mask * max(num, N-num));
    if (dp[k+1][0] >= 0) { 
      if (K & mask) { // Kのkbit目が1
        chmax(dp[k][1], dp[k+1][0] + mask * num); // 「Kぴったり」から「Kよりも小さい」への遷移。0のみ選択できる
        chmax(dp[k][0], dp[k+1][0] + mask * (N - num)); // 「Kぴったり」から「Kぴったり」
      } else {
        chmax(dp[k][0], dp[k+1][0] + mask * num); //「Kぴったり」から「Kぴったり」
      }
    }
  }

  cout << max(dp[0][0], dp[0][1]) << "\n";

}

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

int main(void){
    ll n,m;
    cin >> n>> m;
    if(m<=n){
        cout << 0 << endl;
    }else{
        vector<ll>X(m);
        for(int i=0;i<m;i++){
            cin >> X[i];
        }
        sort(X.begin(),X.end());
        ll max = X[m-1]-X[0]+1-n;
        vector<ll>Y(m-1);
        for(int i=0;i<m-1;i++){
            Y[i] = X[i+1]-X[i]-1;
        }
        sort(Y.rbegin(),Y.rend());
        // for(int i=0;i<m-1;i++){
        //     cout << Y[i]<<' ';
        // }
        // cout << endl;
        ll space = accumulate(Y.begin(),Y.begin()+n-1,0);
        // cout << max <<' '<< space << ' '<< endl;
        cout << max - space << endl;
    }
}

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

#define rep(i,n) for(ll i=0;i<n;i++)
#define repm(i,m,n) for(ll i=m;i<n;i++)
#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))
#define YesNo(a) (a)?cout<<"Yes"<<endl:cout<<"No"<<endl
#define YESNO(a) (a)?cout<<"YES"<<endl:cout<<"NO"<<endl
#define INF (2e9)
#define PI (acos(-1))
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007

typedef long long ll;

int main(){
  int N; cin >> N;
  vector<int> x(N); rep(i,N) cin >> x[i];

  int ans = INF;
  rep(i,100){
    int stamina = 0;
    rep(j,N){
      stamina += pow(x[j]-(i+1), 2);
    }
    ans = min(ans, stamina);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
from collections import Counter
n, k = map(int, input().split())
ali = list(map(int, input().split()))

count = Counter(ali)
sortcount = sorted(count.items(), key=lambda x:x[1])

diverse = len(count)
erase = diverse - k
if erase <= 0:
    print(0)
    exit()

num = 0
for key, val in sortcount[:erase]:
    num += val
print(num)

Measured memory_bytes: 103368
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

struct drinkPriceAndStock{
	unsigned long long int price;
	unsigned long long limit;
};

bool asc(const struct drinkPriceAndStock &left,const struct drinkPriceAndStock &right){
	return left.price < right.price;
}

int main()
{
	unsigned long long int N,M;
	cin>>N>>M;
	struct drinkPriceAndStock *drinkList = new struct drinkPriceAndStock[N];
	for(int i = 0; i < N; i++){
		cin>>drinkList[i].price;
		cin>>drinkList[i].limit;
	}
	sort(drinkList,drinkList + N, asc);
	unsigned long long int totalPrice = 0;
	int index = 0;
	while( M != 0){
		if( M <= drinkList[index].limit){
			totalPrice += drinkList[index].price * M;
			break;
		}else{
			M -= drinkList[index].limit;
			totalPrice += drinkList[index].price * drinkList[index].limit;
		}
		index++;
	}
	cout<<totalPrice<<endl;
	return 0;
}



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

const int MAX_N = 87;
vector<ll> memo(MAX_N, 0);
ll Lucas(int N);

int main()
{
    int N;
    cin >> N;
    ll ans = Lucas(N);
    cout << ans << endl;
    ;
}

ll Lucas(int N)
{
    if (N == 0)
    {
        memo.at(0) = 2;
        return 2;
    }
    else if (N == 1)
    {
        memo.at(1) = 1;
        return 1;
    }
    if (memo.at(N) != 0)
    {
        return memo.at(N);
    }
    return memo.at(N) = Lucas(N - 1) + Lucas(N - 2);
}


Measured memory_bytes: 256
s = str(input())
t = str(input())

ls = list(s)
lt = list(t)

ans = 0
j = 0
while True:
  rep_cnt = 0
  for i in range(j, len(ls)):
    j += 1
    if ls[i] != lt[i]:
      ls[i] = lt[i]
      rep_cnt += 1
      break
  if rep_cnt > 0:
    ans += rep_cnt
  else:
    break

print(str(ans))



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

int main() {
	string N;
	cin >> N;
	string res = "No";
	if (N[0]=='7') res = "Yes";
	if (N[1]=='7') res = "Yes";
	if (N[2]=='7') res = "Yes";
	cout << res << "\n";
}


Measured memory_bytes: 3636
#include<cstdio>
#include<queue>
#include<map>
using namespace std;
typedef pair< int, int > Pi;
int info[100][100];
bool used[100];

int prim(const int& V){
  priority_queue< Pi > que;
  que.push(Pi());
  int ret = 0;
  while(!que.empty()){
    Pi p = que.top(); que.pop();
    if(!~-p.first || used[p.second]++) continue;
    ret -= p.first;
    for(int i = 0; i < V; i++) que.push( Pi( -info[p.second][i], i));
  }
  return ret;
}

int main(){
  int N;
  scanf("%d", &N);
  for(int i = 0; i < N; i++){
    for(int j = 0 ; j < N ; j++){
      scanf("%d", &info[i][j]);
    }
  }
  printf("%d\n", prim(N));
}



Measured memory_bytes: 2868
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


vector<int>  dx = {1,-1,0,0};
vector<int>  dy = {0,0,1,-1};


int main() {

	int h,w; cin >> h >> w;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			string str; cin >> str;
			if (str == "snuke") {
				cout << (char)(j+65) << i+1 << endl;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll,ll>
#define pint pair<int,int>
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define mod 1000000007
#define MAX 100000000
#define endl '\n'
#define mp make_pair
#define INF INT_MAX
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ff first
#define ss second
#define ps(x,y) fixed<<setprecision(y)<<x
#define setbits(x) __builtin_popcountll(x)			//counts no of ones in binary representation
#define w(t) 	int t; cin>>t; while(t--)
#define pi 3.141592653589793238
#define sortt(v)  sort(v.begin(),v.end())
#define lb(v,x) std::lower_bound(v.begin(),v.end(),x)
#define ub(v,x) std::upper_bound(v.begin(),v.end(),x)

using namespace std;

ll power(int a,int n){
	ll ans=1;
	while(n){
		if(n%2==0){
			a*=a;
			n/=2;
		}
		else{
			ans*=a;
			n--;
		}
	}
	return ans;
}

int main(){
	fast;
	ll n;
	cin>>n;
	ll b[n];
	forn(i,n)	cin>>b[i];
	ll a[n];
	string s[n];
	forn(i,n)	s[i]=std::bitset<32>(b[i]).to_string();
	int cnt[32]={0};
	forn(i,n){
		forn(j,32){
			if(s[i][j]=='1')	cnt[j]++;
		}
	}
	forn(i,n){
		string ans="";
		forn(j,32){
			if(s[i][j]=='1'){
				if((cnt[j]-1)%2)	ans+='1';
				else	ans+='0';
			}
			else{
				if((cnt[j])%2)	ans+='1';
				else	ans+='0';
			}
		}
		a[i]=std::bitset<32>(ans).to_ulong();
	}
	forn(i,n)	cout<<a[i]<<' ';
}

Measured memory_bytes: 22356