akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
 
public class Main {
    private static final Scanner scn = new Scanner(System.in);
     
    public static void main(String[] args) {
        String ptn = scn.next().toLowerCase();
        ArrayList<String> als = new ArrayList<>();
        while(scn.hasNext()) {
            als.add(scn.next().toLowerCase());
        }
        System.out.println(Collections.frequency(als, ptn));
    }
}

Measured memory_bytes: 26156
#include <iostream>
#include <vector>
using i64 = long long;

template <class T = long long int>
class Bit {
    private:
    unsigned len;
    T init;
    std::vector<T> arr;

    public:
    Bit(unsigned length, T initialValue = 0): len(length), init(initialValue), arr(len + 1, init) {}
    void update(unsigned a, T newval) {
        for (unsigned x = a; x <= len; x += x & -x) arr[x] += newval;
    }
    T query(unsigned a) const {
        T ret = init;
        for (unsigned x = a; x > 0; x -= x & -x) ret += arr[x];
        return ret;
    }
};

int main() {
    int n, q;
    std::cin >> n >> q;

    Bit<> b(n + 1);
    for (int i = 0; i < n; i++) {
        i64 a;
        std::cin >> a;
        b.update(i + 1, a);
    }

    while (q--) {
        int t, x, y;
        std::cin >> t >> x >> y;
        if (t) std::cout << b.query(y) - b.query(x) << '\n';
        else b.update(x + 1, y);
    }

    return 0;
}


Measured memory_bytes: 8224
#include<stdio.h>
int main(void){

    int m[50], f[50], r[50];
    for (int i = 0; i < 50; i++)
    {
        scanf("%d %d %d",&m[i],&f[i],&r[i]);
        // ↓入力終了フラグ
        if (m[i]==-1 && f[i]==-1 && r[i]==-1){break;}
    }

    for (int i = 0; i < 50; i++)
    {
        // ↓出力終了フラグ
        if (m[i]==-1 && f[i]==-1 && r[i]==-1){break;}
        int sum;
        sum=m[i]+f[i];

        if (sum>=80){printf("A\n");}
        else if(sum>=65){printf("B\n");}
        else if(m[i]==-1||f[i]==-1){printf("F\n");}
        else if(sum>=50){printf("C\n");}
        else if(sum>=30 && r[i]>=50){printf("C\n");}
        else if(sum>=30){printf("D\n");}
        else {printf("F\n");}    
    }
    
    
    
       

       return 0;

}


Measured memory_bytes: 2104
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;

int main() {
    int n, m, inf = 1e9;
    cin >> n >> m;

    int d[5000];
    for (int i = 0; i < (1 << n); i++) d[i] = inf;
    d[0] = 0;

    for (int i = 0; i < m; i++) {
        int a, b, m = 0;
        cin >> a >> b;
        for (int j = 0; j < b; j++) {
            int c;
            cin >> c;
            c--;
            m |= (1 << c); 
        }
        d[m] = min(d[m], a);
    }

    for (int i = 0; i < (1 << n); i++) {
        for (int j = i + 1; j < (1 << n); j++) {
            int l = (i | j);
            d[l] = min(d[l], d[i] + d[j]);
        }
    }
    cout << (d[(1 << n) - 1] == inf ? -1 : d[(1 << n) - 1]) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,mod=1000000007;
const long long llinf=9223372036854775807ll;
map<int,int> mp;
string s;
int query(int x)
{
	if(mp.find(x)!=mp.end())
		return mp[x];
	cout<<x<<'\n';
	fflush(stdout);
	cin>>s;
	if(s=="Vacant")
		exit(0);
	if(s=="Male")
		mp[x]=1;
	else
		mp[x]=0;
	return mp[x];
}
int n,l,r;
int main(){
	cin>>n;
	l=0,r=n-1;
	while(r-l>1)
	{
		int m=(l+r)/2;
		if(query(m)^(m%2)!=(query(l)^(l%2)))
			r=m;
		else
			l=m;
	}
	for(int i=l;i<=r;i++)
		query(i);
	return 0;
}

Measured memory_bytes: 852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

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

    vector<string> ans;
    for(int i=0; i<s.size()+1-t.size(); ++i){
        string tmp = s;
        bool flg = true;
        for(int j=0; j<t.size(); ++j){
            if(s[i+j] == '?') tmp[i+j] = t[j];
            else if(s[i+j] == t[j]) tmp[i+j] = t[j];
            else flg = false;
        }
        if(flg){
            for(int j=0; j<tmp.size(); j++){
                if(tmp[j] == '?') tmp[j] = 'a';
            }
            ans.push_back(tmp);
        }
    }

    if(ans.size() == 0) cout << "UNRESTORABLE" << endl;
    else{
        sort(ans.begin(), ans.end());
        cout << ans[0] << endl;
    }
}

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

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

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

    int n, k, s;
    cin >> n >> k >> s;
    for (int i = 0; i < k; i++) cout << s << ' ';
    int d = 1;
    while (s % d == 0) d++;
    for (int i = k; i < n; i++) cout << d << ' ';
}

Measured memory_bytes: 1280
typedef long long int ll;
typedef unsigned long long int ull;
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MOD 1000000007
#define M_PI           3.14159265358979323846  /* pi */
#define sec second
#define fir first
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repe(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define entire(a) (a).begin(),(a).end()
#define pb push_back
#define pii pair<int,int>
#include<bits/stdc++.h>
using namespace std;

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t = 1;
	// cin >> t;
	while (t--) {
		int n,cnt=0;
		cin>>n;
		bool flag= false;

		while(n--){
			int a,b;
			cin>>a>>b;
			if(a==b){
				cnt++;
			}else{
				cnt=0;
			}
			if(cnt==3){
				flag=true;
			}
		}
		cout<<(flag?"Yes\n":"No\n");

	}

	return 0;

}


Measured memory_bytes: 3620
{-# LANGUAGE OverloadedStrings #-}
import Data.Char
import Data.Function
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as UV


readInt :: BS.ByteString -> Maybe (Int, BS.ByteString)
readInt = BS.readInt . BS.dropWhile isSpace

getIntVec :: Int -> IO (UV.Vector Int)
getIntVec n = UV.unfoldrN n readInt <$> BS.getLine

main :: IO()
main = do
  n <- readLn
  ns <- getIntVec n
  print . sum $ [((*) `on` (ns UV.!)) i j | i <- [0..n-2], j <- [i+1..n-1]]


Measured memory_bytes: 508
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define N 100
int m[N][N];
int MCOrder(int *p, int num);
int main(){
  int num, i, p[N+1];
  scanf("%d", &num);
  for(i = 0; i < num; i++){
    scanf("%d%d", &p[i], &p[i+1]);
  }
  printf("%d\n", MCOrder(p, num));
  return 0;
}
int MCOrder(int *p, int num){
  int i, j, k, l, r;
  for(i = 1; i <= num; i++){
    m[i][i] = 0;
  }
  for(l = 2; l <= num; l++){
    for(i = 1; i <= num-l+1; i++){
      j = i+l-1;
      m[i][j] = INT_MAX;
      for(k = i;k <= j - 1;k++){
        r = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
        m[i][j] = ((m[i][j] <= r) ? m[i][j] : r);
      } }
  }
  return m[1][num];
}



Measured memory_bytes: 2112
#include <iostream>
using namespace std;
int main(void)
{
int a,b,c;
cin >>a;
cin >>b;
cin >>c;
if(b<a){
   int temp=a;
   a=b;
   b=temp;
}
if(c<b){
   int temp=b;
   b=c;
   c=temp;
}
if(b<a){
   int temp=b;
   b=a;
   a=temp;
}
cout<<a<<" "<<b<<" "<<c<<endl;
}


Measured memory_bytes: 3104
n = int(input())
arrx = list(map(int,input().split()))
sumx = sum(arrx)
small = int(sumx // len(arrx))
big = int(-(-sumx // len(arrx)))
smallans = 0
bigans = 0
for x in arrx:
  smallans += (x-small)**2
  bigans += (x-big)**2
print(min(smallans,bigans))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	int R,G,B,N;cin>>R>>G>>B>>N;
	int sum=0;int temp;
	for(int i=0;i<=N;i=i+R){
		for(int j=0;j<=N;j=j+G){
            temp=N-i-j;
			if(temp%B==0&&temp>=0){
				sum++;
                //cout<<i/R<<" "<<j/G<<endl;
			}
		}
	}cout<<sum<<endl;
}

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

using namespace std;

// input
int h,w;
int n;
vector<int> vec;
vector<vector<int> > field;

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

    cin >> h >> w;
    cin >> n;

    int num,index = 1;
    vector<int> row;
    while(cin >> num){
        for(int i = 0;i < num;i++){


            row.push_back(index);
            int size = row.size();
            if(size == w){
                field.push_back(row);
                row.clear();
            }
        }
        index++;
    }
    
    int row_num = 0;
    for(auto row:field){

        if(row_num % 2 == 1) reverse(row.begin(),row.end());

        for(auto cell:row){
            cout << cell << " ";
        }
        cout << "\n";
        row_num++;
    }

    
}

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

long long int a,b,c,ab;
long long int sum;
int main()
{
	cin>>a>>b>>c;
	
	if(a+b>=c)
	{
		sum=b+c;
	}
	ab=a+b;
	if(a+b<c)
	{
		sum=b+a+b+1;
	}
	cout<<sum;
}

Measured memory_bytes: 256
s='>'+input()+'<'
l=len(s)-1
arr=[-1]*l
for i in range(l):
  if s[i]=='>' and s[i+1]=='<':
    arr[i]=0
for i in range(1,l):
  if s[i]=='<' and arr[i-1]!=-1:
    arr[i]=arr[i-1]+1
for i in range(l-1,0,-1):
  if s[i]=='>' and arr[i]!=-1:
    arr[i-1]=max(arr[i-1],arr[i]+1)
print(sum(arr))

Measured memory_bytes: 23228
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
#define pb push_back
typedef long double ld;
#define fi first
#define se second
#define mp make_pair

vector<vector<pair<ll,ll>>> out(1e5);
vector<vector<ll>> in(1e5);
ll inf=1e18;
ll p=1e9+7;
ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
   while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll n,i,j,t,a,b,temp,m,k,x,y,ctr;
	ld r;
	cin>>n;
	map<ll,ll>mp;
	for(i=0;i<n-1;i++)
	{
	    cin>>t;
	    mp[t]++;
	    
	    
	}
	for(i=1;i<=n;i++)
	cout<<mp[i]<<"\n";
	return 0;
	
	
}

Measured memory_bytes: 20420
import java.util.*;

class Main {
  public static void main(String[] args) {
	Scanner scanner = new Scanner(System.in);
    
    int N = scanner.nextInt(); //next(文字列), nextDouble, nextLine(1行)とか
	int S = scanner.nextInt();
    
    int x = -1;int y= -1;int z = -1;
    for (int i = 0; i <= N; i++){
      x = i;
      for (int j = 0; j <= N-i; j++){
        y = j;
        z = N - i - j;
        if ((z >= 0) && (10000*x + 5000*y + 1000*z == S)){
          System.out.println(x + " " + y + " " + z);
          return;
        }
      }
    }
    System.out.println(-1 + " " + -1 + " " + -1);
  }
}


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

using namespace std;

using int64 = long long;

void operator*=(vector< int > &latte, const vector< int > malta)
{
  for(int i = 0; i < malta.size(); i++) {
    latte[i] = malta[latte[i]];
  }
}

vector< int > mod_pow(vector< int > x, int64 n)
{
  vector< int > ret(x.size());
  iota(begin(ret), end(ret), 0);
  while(n > 0) {
    if(n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return (ret);
}

int main()
{
  int N, M, A[100000];
  int64 K, X[100000];

  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> X[i];
  }
  cin >> M >> K;
  for(int i = 0; i < M; i++) {
    cin >> A[i];
    --A[i];
  }

  int64 B[100000];
  vector< int > order(N - 1);
  for(int i = 0; i < N - 1; i++) {
    B[i] = X[i + 1] - X[i];
    order[i] = i;
  }
  for(int i = 0; i < M; i++) {
    swap(order[A[i] - 1], order[A[i]]);
  }
  order = mod_pow(order, K);

  cout << X[0] << endl;
  auto base = X[0];
  for(int i = 0; i < N - 1; i++) {
    base += B[order[i]];
    cout << base << endl;
  }
}

Measured memory_bytes: 3944
def main():
  N,P = map(int,input().split())
  S = input()

  ans = 0
  if P == 2 or P == 5:
    for i in range(N):
      if int(S[i])%P == 0:
        ans += i+1
  else:
    # r = [0] * (N+1)
    # for i in range(N):
    #   r[N-1-i] = int(S[N-1-i:])%P
    # for i in range(N):
    #   for j in range(i,N):
    #     if (r[i]-r[j+1])%P == 0:
    #       ans += 1
    d = {}
    r = 0
    for i in range(N):
      r = (r+int(S[N-1-i])*pow(10,i,P))%P
      if r in d:
        d[r] += 1
      else:
        d[r] = 1
    if 0 in d:
      d[0] += 1
    for k,v in d.items():
      ans += v*(v-1)//2
  
  print(ans)

if __name__ == '__main__':
  main()

Measured memory_bytes: 42700
/*
*          Name : chaitanya
*
*     Institute : ANITS,Visakhapatnam
*
*/
#include<cstdio>
#include<iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include<cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
#define all(x) begin(x),end(x)
#define ll long long int
#define ff first
#define ss second
#define pb push_back
const ll mod = 1000000007;
#pragma GCC optimization ("O3")
const int N = 100005;
using namespace std;

int main()
{
 
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  ll a,b;
  cin >> a >> b;
  ll x = __gcd(a,b);
  map<ll,int>p;
  for (ll i = 2; i*i <= x; ++i)
  {
    while(x % i == 0)
    {
      p[i]++;
      x /= i;
    }

  }
  if( x != 1)
    p[x] = 1;
  cout << p.size()+1 <<endl;
  return 0;
}


Measured memory_bytes: 256
# coding: utf8

import math

def read_int():
    return int(input())

 
def read_int_n():
    return list(map(int, input().split()))
 
 
def read_str():
    return input()
 
 
def read_str_n():
    return list(map(int, input().split()))

def main():
    n = read_int()
    keta = math.floor(math.log10(n)) + 1
    ans = 0
    for i in range(1, keta):
        if i % 2 == 0:
            continue
        else:
            plus = ( 10 ** i ) - (10 ** (i-1))
            ans += plus
    if keta % 2 == 1:
        ans += n - (10 ** (keta - 1)) + 1
    print(ans)

main()

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long x;
  cin >> x;
  long long ans;
  if (x < 11) {
    ans = (x > 6) + 1;
  } else {
    ans = (x + 10) / 11 * 2;
    if (x % 11 >= 1 && x % 11 <= 6) ans--;
  }
  cout << ans << '\n';
  return 0;
}

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

#define pb push_back
#define mk make_pair
#define sc second
#define fr first

using namespace std;

typedef long long ll;

const int N = (int) 1e6 + 5;
const int mod = (int) 1e9 + 7;

long long a,b;

int main () {
        cin >> a >> b;

        if(abs(a - b) <= 1)
                cout << "Brown" << endl;
        else
                cout << "Alice" << endl;
        return 0;
}


Measured memory_bytes: 256
N = gets.to_i
T = gets.split.map(&:to_i)
M = gets.to_i
P, X = M.times.map{gets.split.map(&:to_i)}.transpose

all=T.sum
M.times do |i|
    c_no=P[i]-1
    puts all-T[c_no]+X[i]
end

Measured memory_bytes: 14336
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		while (N != 0) {
			List<L> list = new ArrayList<L>();
			for (int i = 0; i < N; i++) {
				L l = new L();
				l.name = sc.next();
				int P = sc.nextInt();
				int ABC = sc.nextInt() + sc.nextInt() + sc.nextInt();
				int DE = sc.nextInt() + sc.nextInt();
				int F = sc.nextInt();
				int S = sc.nextInt();
				int M = sc.nextInt();
				int time = ABC + DE * M;
				int money =  F * M * S - P;
				l.money = (double)money / time;
				list.add(l);
			}
			Collections.sort(list);
			Collections.reverse(list);
			for (L l : list) {
				System.out.println(l.name);
			}
			System.out.println("#");
			N = sc.nextInt();
		}
	}
}

class L implements Comparable<L> {
	String name;
	double money;

	@Override
	public int compareTo(L o) {
		if (money > o.money)
			return 1;
		else if (money < o.money)
			return -1;
		else
			return o.name.compareTo(name); 

	}
}

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

int main()
{
	int H, W, h, w;
	cin >> H;
	cin >> W;
	cin >> h;
	cin >> w;
	int ans = (H - h)*(W - w);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    ll n, k;
    cin >> n >> k;

    if (n == k) {
        cout << 0 << endl;
    } else if (n > k) {
        n = n % k;
        cout << min(n, k - n) << endl;
    } else {
        cout << min(n, k - n) << endl;
    }

    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
using namespace std;
 
int main() {
  int n;
  cin >> n;
  if(n<105) cout << 0 << endl;
  else if(n<135) cout << 1 << endl;
  else if(n<165) cout << 2 << endl;
  else if(n<189) cout << 3 << endl;
  else if(n<195) cout << 4 << endl;
  else  cout << 5 << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
H,W,D = map(int,input().split())
A = [list(map(int,input().split())) for i in range(H)]
Q = int(input())
LR = [tuple(map(int,input().split())) for i in range(Q)]

INF = float('inf')
h = 0--(H*W+1)//D

pos = [[INF]*h for _ in range(D)]
for i,row in enumerate(A):
    for j,a in enumerate(row):
        d,m = divmod(a,D)
        pos[m][d] = (i,j)

dists = [[0] for _ in range(D)]
for i,p in enumerate(pos):
    for p1,p2 in zip(p,p[1:]):
        if p1==INF or p2==INF: continue
        a1,b1 = p1
        a2,b2 = p2
        dist = abs(a1-a2) + abs(b1-b2)
        dists[i].append(dists[i][-1] + dist)

ans = []
for l,r in LR:
    a,i = divmod(l,D)
    b,j = divmod(r,D)
    if i==0:
        a-=1; b-=1
    ans.append(dists[i][b] - dists[i][a])
print(*ans, sep='\n')

Measured memory_bytes: 48004
#include <cstdio>
#include <vector>
using namespace std;
using ll = long long int;
#define REP(i, n) for (int i = 0; i < n; ++i)

int main() {
  int N, Q; scanf("%d %d", &N, &Q);
  vector<ll> a(N);
  REP(i,N) scanf("%lld", &a[i]);

  while (Q--) {
    ll x; scanf("%lld", &x);
    auto left = a.begin(), right = a.begin();
    ll sum = 0, res = 0;
    while ( right != a.end() ) {
      sum += *right;
      ++right;
      while ( sum > x ) {
        sum -= *left;
        ++left;
      }
      res += right - left;
    }
    printf("%lld\n", res);
  }
}


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

const int WIDTH = 300;
const int DEBUG = 0;

struct State {
	int score;
	int prevs;
	int sousa;
	int Last[29];
};

bool operator<(const State& a1, const State& a2) {
	if (a1.score < a2.score) return true;
	return false;
}

int N;
int C[29], S[409][29];
int cnts[409];
State G[409][WIDTH + 9];
State H[(WIDTH * 26) + 9];

void solve(int pos, int num) {
	for (int i = 1; i <= 26; i++) {
		int NewScore = G[pos][num].score;
		NewScore += S[pos + 1][i];
		for (int j = 1; j <= 26; j++) {
			if (i != j) NewScore -= C[j] * ((pos + 1) - G[pos][num].Last[j]);
		}
		H[cnts[pos + 1]].score = NewScore;
		H[cnts[pos + 1]].prevs = num;
		H[cnts[pos + 1]].sousa = i;
		for (int j = 1; j <= 26; j++) H[cnts[pos + 1]].Last[j] = G[pos][num].Last[j];
		H[cnts[pos + 1]].Last[i] = pos + 1;
		cnts[pos + 1]++;
	}
}

int main() {
	// 入力
	if (DEBUG == 0) {
		cin >> N;
		for (int i = 1; i <= 26; i++) cin >> C[i];
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= 26; j++) cin >> S[i][j];
		}
	}
	else {
		N = 365;
		for (int i = 1; i <= 26; i++) C[i] = rand() % 101;
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= 26; j++) S[i][j] = ((rand() % 32768) * 32768 + (rand() % 32768)) % 20001;
		}
	}
	
	// ビームサーチ
	G[0][0].prevs = -1; cnts[0] = 1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < cnts[i]; j++) solve(i, j);
		sort(H, H + cnts[i + 1]);
		reverse(H, H + cnts[i + 1]);
		cnts[i + 1] = min(cnts[i + 1], WIDTH);
		for (int j = 0; j < cnts[i + 1]; j++) G[i + 1][j] = H[j];
	}

	// 復元
	vector<int> Answer; int cx = 0;
	for (int i = N; i >= 1; i--) {
		Answer.push_back(G[i][cx].sousa);
		cx = G[i][cx].prevs;
	}
	reverse(Answer.begin(), Answer.end());
	for (int i = 0; i < Answer.size(); i++) cout << Answer[i] << endl;
	return 0;
}

Measured memory_bytes: 18740
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ms(a,x) memset(a,x,sizeof(a))
const int Max=1000000+10;
int main()
{
    int n;
    cin>>n;
    int m,k;
    cin>>m>>k;
    double t=1000000,num;
    for(int i=1;i<=n;i++)
    {
        double s,ans;
        cin>>s;
        ans=(m-(s*0.006));
        //cout<<s<<' '<<m<<' '<<ans<<endl;
        if(t>fabs(k-ans))
        {
            num=i;
            //cout<<t<<' '<<fabs(k-ans)<<endl;
            t=fabs(k-ans);
        }

    }
    cout<<num<<endl;
    return 0;
}


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

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

const ll MOD = 1e9+7;

// Combinationの使い方
// vector<vector<ll>> v(N+1, vector<ll>(N+1, 0));
// comb(v);
void comb(vector<vector<ll>> &v){
    for(int i = 0; i < v.size(); i++){
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for(int k = 1; k < v.size(); k++){
        for(int j = 1; j < k; j++){
            v[k][j] = (v[k-1][j-1] + v[k-1][j]);
            //余りを求める問題は毎回計算ごとにやる
            // v[k][j] = (v[k-1][j-1] + v[k-1][j]) % MOD;
        }
    }
}

// Union Find
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

// 1 << 3 : int "3" change to bit "100"
// rep(pattern, 1 << N) if (pattern & (1 << x)) cnt++

int main(){
    int r, g, b;
    cin >> r >> g >> b;
    if((r*100+g*10+b) % 4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

A,B = MI()

print(A*B)

Measured memory_bytes: 27124
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
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; }


int main() {
    int N,K;
    cin >> N >> K;
    vector<int> h(N);
    REP(i,N) cin >> h[i];
    int minv = INF;

    sort(h.begin(),h.end());
    REP(i,N-K+1){
        minv = min(minv,abs(h[i+K-1]-h[i]));
    }
    cout << minv << endl;
}

Measured memory_bytes: 640
#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 ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;

typedef tree <pii, null_type, less <pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 103;
int n, used[N], a[N], f[N], good[N];
ll ans = 0;
vi vec = {21, 27, 29, 31, 33, 34, 35, 36, 37, 38, 39, 40, 41, 43, 44, 45, 46, 47, 49, 50};

void solve() {
	ll res = 0;
	for (int i = 1; i <= n; i++) {
		f[i] = used[i];
		if (!f[i]) {
			res += a[i];
		}
	}
	for (int i : vec) {
		ll cur = 0;
		for (int j = i; j <= n; j += i) {
			if (!f[j]) {
				cur += a[j];
			}
		}
		if (cur < 0) {
			for (int j = i; j <= n; j += i) {
				f[j] = 1;
			}
			res -= cur;
		}
	}
	ans = max(ans, res);
}

void rec(int last) {
	for (int i = last + 1; i <= min(n, 50); i++) {
		if (!good[i] && !used[i]) {
			vi tmp(n / i);
			int cur = 0;
			for (int j = i; j <= n; j += i) {
				tmp[cur++] = used[j];
				used[j] = 1;
			}
			rec(i);
			cur = 0;
			for (int j = i; j <= n; j += i) {
				used[j] = tmp[cur++];
			}
		}
	}
	solve();
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (a[i] < 0 && i > 50) {
			a[i] = 0;
		}
	}
	for (int i : vec) {
		good[i] = 1;
	}
	rec(0);
	cout << ans;
}


Measured memory_bytes: 256
#from numpy import*
#from scipy import*
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby
from operator import mul
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
#input=sys.stdin.readline  #危険！基本オフにしろ！
sys.setrecursionlimit(10**6)


def main():
    while 1:
        a,b=map(int,input().split())
        if a==b==0:
            break
        print(sum(sum(i)==b for i in combinations(range(1,a+1),3)))
    
    
    
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 6912
#include<bits/stdc++.h>
#define ll long long int
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define rep(n) for(ll i2=0;i2<n;i2++)
#define vmp(v,a,b) v.push_back(make_pair(a,b))
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define aset(a,n,k) for(ll i3=0;i3<n;i3++)a[i3]=k; 	
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define f first
#define s second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_orde(ind)
using namespace std;
int main()
{
	sync;
	ll n;
	cin>>n;
	ll arr[n],pref[n],suf[n];
	input(arr,n);
	pref[0]=arr[0];
	suf[n-1]=arr[n-1];
	for(ll i=1;i<n;i++)
	pref[i]=__gcd(pref[i-1],arr[i]),suf[n-1-i]=__gcd(suf[n-i],arr[n-1-i]);
	ll ans=0;
	for(ll i=1;i<n-1;i++)
	ans=max(ans,__gcd(pref[i-1],suf[i+1]));
	ans=max(ans,max(suf[1],pref[n-2]));
	cout<<ans;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int a, b;
  std::cin >> a >> b;
  int tmp = b;
  while (tmp > 0) {
    tmp /= 10;
    a *= 10;
  }
  tmp = a + b;
  int s = sqrt(tmp * 1.0) + 0.5;
  if (s * s == tmp)
    std::cout << "Yes" << std::endl;
  else
    std::cout << "No" << std::endl;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>

#define rep(i, n) for (int i = 0; i < static_cast<int>(n); i++)
using std::cin;
using std::cout;
using std::endl;
using std::vector;

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

  vector<int64_t> weight(N + 1);
  vector<int64_t> value(N + 1);
  for (int i = 0; i < N; i++) cin >> weight[i] >> value[i];
  int64_t v_max = std::accumulate(value.begin(), value.end(), 0LL);

  int64_t init_value = 10e9 * N;
  vector<vector<int64_t>> dp(N + 1, vector<int64_t>(v_max + 1, init_value));

  dp[0][0] = 0;

  for (int i = 0; i < N; i++) {
    for (int v = 0; v <= v_max; v++) {
      if (v >= value[i]) {
        dp[i + 1][v] = std::min(dp[i][v - value[i]] + weight[i], dp[i][v]);
      } else {
        dp[i + 1][v] = std::min(weight[i], dp[i][v]);
      }
      // cout << "dp[" << i + 1 << "][" << v << "] = " << dp[i + 1][v] << endl;
    }
  }
  int64_t ans = 0;
  for (int64_t v = 0; v <= v_max; v++) {
    if (dp[N][v] <= W) {
      ans = v;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 80256
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           node(a,b,c)                 mp(mp(a,b),c)
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;
map<int,pi>yo;
 main()

{
    fast
    int n;
    cin>>n;
    f(i,1,n)
    {
        int x,y;
        cin>>x>>y;
        yo[x]=(mp(y,0));
    }
    f(i,1,n)
    {
        int x,y;
        cin>>x>>y;
        yo[x]=(mp(y,1));
    }
    int ses=0;
    set<int>s;
    set<int>::iterator it;
    for(auto z:yo)
    {
        int x=z.fi;
        int typ=z.si.si;
        int y=z.si.fi;
        if(typ==0)
        {
            s.insert(y);
        }
        else
        {
           if(s.empty())continue;
           it=s.upper_bound(y);
           if(it==s.begin())continue;
           it--;
           s.erase(it);
           ses++;

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

}





































Measured memory_bytes: 3632
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int n;
    scan(n);
    auto ans = readln.split.to!(int[]).sum() - n;
    writeln(ans);
}





void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 380
#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;
int N, K;

void solve() {
  int cnt = (N-1)*(N-2) / 2;
  if (K > cnt) {
    cout << -1 << endl;
    return;
  }
  int mat[N][N];
  rep(i, N)rep(j, N) mat[i][j] = 0;
  rep(i, N-1) mat[0][i+1] = 1;
  int i = 1, j = 2;
  int M = N-1;
  while (cnt > K) {
    if (j == N) {
      ++i;
      j = i+1;
    }
    mat[i][j] = mat[j][i] = 1;
    ++j; --cnt; ++M;
  }
  cout << M << endl;
  for (int i = 0; i < N; ++i) {
    for (int j = i+1; j < N; ++j) {
      if (mat[i][j]) printf("%d %d\n", i+1, j+1);
    }
  }
}

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

Measured memory_bytes: 256
n,m=map(int,input().split())
p=list(map(int,input().split()))
k=[i for i in range(n+1)]
r=[0]*(n+1)
def root(x):
    if x==k[x]:
        return x
    x=k[x]
    return root(k[x])
def unite(x,y):
    x=root(x)
    y=root(y)
    if x!=y:
        if r[x]>r[y]:
            k[y]=x
            r[x]+=1
        else:
            k[x]=y
            r[y]+=1
c=0
for i in range(m):
    x,y=map(int,input().split())
    unite(x,y)
for i in range(n):
    if root(i+1)==root(p[i]):
        c+=1
print(c)

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

int cnt4;
int cnt2;
int cnt1;
int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		if (a % 4 == 0){
			cnt4++;
		}
		else{
			if (a % 2 == 0){
				cnt2++;
			}
			else{
				cnt1++;
			}
		}
	}
	while (cnt4>0){
		cnt1--;
		cnt4--;
	}
	cnt1--;
	if (cnt1 > 0){
		puts("No");
	}
	else{
		if (cnt1 == 0 && cnt2){
			puts("No");
		}
		else{
			puts("Yes");
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define IOS 		ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sd(n)       scanf("%d", &n)
#define sdd(a,b)    scanf("%d %d", &a, &b)
#define sddd(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sld(n)      scanf("%lld", &n)
#define slld(a,b)   scanf("%lld %lld", &a, &b)
#define sllld(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define slu(n)      scanf("%llu", &n)
#define sllu(a,b)   scanf("%llu %llu", &a, &b)
#define slllu(a,b,c) scanf("%llu %llu %llu", &a, &b, &c)
#define ss(a)		scanf("%s", a)
#define inStrAftInSome cin.ignore(numeric_limits<streamsize>::max(),'\n')		//input string(with whitespace) after input something(char, int, bool, str)
#define all(a) 		a.begin(),a.end()
#define unq(x)      x.erase(unique(all(x)), x.end()
#define mp 			make_pair
#define sz(av) 		int((av).size())					//return size of vec
#define CLR(arr)    memset(arr, 0, sizeof(arr))			//assign 0 to whole arr
#define SET(vec)    memset(arr, -1, sizeof(arr))		//assign -1 to whole arr
#define CLRV(vec)	fill(vec.begin(), vec.end(), 0)		//assign 0 to whole vec
#define SETV(vec,n,a) vec.assign(n, a)	
#define vtd(rowsize,colsize,type,name) 		vector < vector <type> > name(rowsize,vector <type> (colsize)); 	//assign to first n elements value a in vec
#define SETB(a)		memset(a, true, sizeof(a))			//boolean array initialize by true value
#define CLRB(a)		memset(a, false, sizeof(a))			//boolean array initialize by false value
#define vintitr 	vector<int>::iterator
#define vlnlnitr 	vector<long long>::iterator
#define sintitr 	set<int>::iterator
#define slnlnitr 	set<long long>::iterator
#define aa			first
#define bb			second
#define mod 		1000000007
#define PI 			acos(-1.00)
#define psb 		push_back
#define ppb			pop_back
#define ppb			pop_back
#define psf			push_front
#define ppf			pop_front
#define in 			inset
#define rep(i, n) 	for(int i=0; i<n; i++)
#define repi(i,j,n) for(int i=j; i<n; i++)
#define rof(i, n)   for(int i=n-1; i>=0; i--)
#define min3(a,b,c) (min((c),min((a),(b))))
#define max3(a,b,c) (max((a),max((b),(c))))
#define __lcm(a, b)	a*b / __gcd(a, b)
#define __builtin_zerocount(a)	8*sizeof(a)-__builtin_popcount(a)-__builtin_clz(a)-__builtin_ctz(a)
#define D(t)        cerr << #t " = " <<t  << '\n'
#define DBG         cerr << "Hi!" << '\n'
 
 
typedef long long	 		ll;
typedef unsigned long long	llu;
typedef long double			ld;
typedef pair<int, int> 		pii;

int main()
{
//	freopen("t.in","r",stdin);
//	freopen("t.out","w",stdout);
	IOS;
	int n;
	cin >> n;
	int b[n];

	rep(i, n-1){
		cin >> b[i];
	}

	llu ans = b[0];
	rep(i, n-2){
		ans += min(b[i], b[i+1]);
	}
	ans += b[n-2];
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
#define maxn 1000000
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pp;
struct edge{
	int u,v,c;
};
int n,m,x,orix; vector <edge> t;
void PrintAns(int so){
	int i,j;
	cout<<"20 "<<t.size()<<'\n';
	for (i=0;i<t.size();i++){
		edge e=t[i]; if (e.v==so) e.v=20;
		cout<<e.u<<' '<<e.v<<' '<<e.c<<'\n';
	}
	exit(0);
}
void thu3(){
	int i,j,dem=1,ed=0; edge e; bool ok=false;
	if (x>=2) ok=true;
	while (ok&&x>=2){
		if (x>2&&x%3!=2){
			while (x%3!=2){
				ed++; 
				e.u=dem; e.v=20; e.c=x;
				t.pb(e); x--;
			}
		}
		int newx=x/3;
		ed+=3; 
		e.u=dem; e.v=dem+1; e.c=0; t.pb(e);
		e.u=dem; e.v=dem+1; e.c=newx+1; t.pb(e);
		e.u=dem; e.v=dem+1; e.c=2*newx+2; t.pb(e);
		x=newx; dem++;
	}
	if (x==0&&ed<=60&&dem<=20){
		PrintAns(dem); exit(0);
	}
	while (x>=0){
		ed++; e.u=dem; e.v=dem+1; e.c=x; 
		t.pb(e); x--;
	}
	dem++;	
	if(ed<=60&&dem<=20){
		PrintAns(dem); exit(0);
	}
}
void thu4(){
	int i,j,dem=1,ed=0; edge e; bool ok=false;
	if (x>=3) ok=true;
	while (ok&&x>=3){
		if (x>3&&x%4!=3){
			while (x%4!=3){
				ed++; 
				e.u=dem; e.v=20; e.c=x;
				t.pb(e); x--;
			}
			
		}
		int newx=x/4;
		ed+=4; 
		e.u=dem; e.v=dem+1; e.c=0; t.pb(e);
		e.u=dem; e.v=dem+1; e.c=newx+1; t.pb(e);
		e.u=dem; e.v=dem+1; e.c=2*newx+2; t.pb(e);
		e.u=dem; e.v=dem+1; e.c=3*newx+3; t.pb(e);
		x=newx; dem++;
	}
	if (x==0&&ed<=60&&dem<=20){
		PrintAns(dem); exit(0);
	}
	while (x>=0){
		ed++; e.u=dem; e.v=dem+1; e.c=x; 
		t.pb(e); x--;
	}
	dem++;	
	
	if(ed<=60&&dem<=20){
		PrintAns(dem); exit(0);
	}
}
main(){
	ios::sync_with_stdio(false); cin.tie(0);
	//freopen(".inp","r",stdin); freopen(".out","w",stdout);
	//freopen("inp.txt","r",stdin);
	cin>>x; x--; orix=x;
	thu3(); 
	x=orix; t.clear(); 
	thu4();
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,m;
	cin>>n>>m;
	int out=0;
	rep(i,n){
		int a;
		cin>>a;
		out+=2*min(a,m-a);
	}
	cout<<out<<endl;
}








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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

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

  vector<vector<int>> vec(M);
  for(int i = 0; i < M; ++i) {
    int k; cin >> k;
    vec[i].resize(k);
    for(int j = 0; j < k; ++j) {
      cin >> vec[i][j];
      --vec[i][j];
    }
  }

  vector<int> p(M);
  for(int i = 0; i < M; ++i) cin >> p[i];
  int ans = 0;
  for (int i = 0; i < (1 << N); ++i) {
    bool ok = true;
    for (int j = 0; j < M; ++j) {
      int c = 0;
      for (int id : vec[j]) {
        if ((i >> id) & 1) {
          ++c;
        }
      }
      c %= 2;
      if (c != p[j]) {
        ok = false;
      }
    }
    if (ok) {
      ++ans;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N=int(input())
W_list=list(map(int,input().split()))
sum_list=[]
for T in range(0,N):
  S1 =sum(W_list[0:T+1])
  S2 =sum(W_list[T+1:N])
  diff = abs(S1 - S2)
  sum_list.append(diff)
print(min(sum_list))

Measured memory_bytes: 3060
#include<stdio.h>
#define N 1000
#define Z 500000
int a, b, c, d;
int push(void);
int top(void);
int pop(void);
int A[N][Z];
int size[N];
////////////////////////////////////////////////////////////
int main(void){
    scanf("%d%d", &b, &a);
    while (a-- != 0){
        scanf("%d", &b);
        if (b == 0) push();
        if (b == 1) top();
        if (b == 2) pop();
    }
    return 0;
}
int push(void){
    scanf("%d%d", &c, &d);
    A[c][size[c]] = d;
    size[c]++;
    return 0;
}
int top(void){
    scanf("%d", &c);
    if (size[c] == 0) return 0;
    printf("%d\n", A[c][size[c]-1]);
    return 0;
}
int pop(void){
    scanf("%d", &c);
    A[c][size[c]] = 0;
    if (size[c] == 0) return 0;
    size[c]--;
    return 0;
}


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

bool check(ll n, ll a)
{
    if (n%a == 1) return true;
    else if (n%a == 0) return check(n / a, a);
    return false;
}


int main()
{
    ll n;
    cin >> n;
    ll x = n - 1;
    int cnt = 0;
    if (n == 2) {
        cout << "1\n";
        return 0;
    }
    for (ll i = 2; i * i <= n; i++) {
        if (n%i == 0) {
            if (check(n, i)) cnt++;
            if (i * i != n && check(n, n / i)) cnt++;
        }
    }
    cnt += 2;
    for (ll i = 2; i * i <= x; i++) {
        if (x%i == 0) {
            cnt++;
            if (i * i != x) cnt++;
        }
    }
    cout <<  cnt << "\n";
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var k int
	fmt.Scan(&k)
	qs := make([]int, 0)
	qs = append(qs, []int{1, 2, 3, 4, 5, 6, 7, 8, 9}...)
	var cnt int
	for len(qs) > 0 {
		cnt++
		q := qs[0]
		qs = qs[1:]
		if cnt == k {
			fmt.Println(q)
			break
		}
		bs := []byte(strconv.Itoa(q))
		last := bs[len(bs)-1]
		if last == '0' {
			qs = append(qs, q*10+0)
			qs = append(qs, q*10+1)
		} else if last == '9' {
			qs = append(qs, q*10+8)
			qs = append(qs, q*10+9)
		} else {
			ln, _ := strconv.Atoi(string([]byte{last}))
			qs = append(qs, q*10+ln-1)
			qs = append(qs, q*10+ln)
			qs = append(qs, q*10+ln+1)
		}
	}
}


Measured memory_bytes: 9856
#include<iostream>
#include<cstdio>
#include<algorithm>
#define f first
#define s second
using namespace std;

typedef pair<pair<long,long>,pair<long,long> > pp;

bool ppc(pp& f,pp& s){return f.s.s<s.s.s;}

int main()
{
	int n,m,p,y;
	cin>>n>>m;
	pp a[100010];
	for(int i=1;i<=m;i++)
	{
		cin>>p>>y;
		a[i].f.f=p;
		a[i].f.s=y;
		a[i].s.f=0;
		a[i].s.s=i;
	}
	sort(a+1,a+m+1);
	p=a[1].f.f;
	y=1;
	for(int i=1;i<=m;i++)
	{
		if(p!=a[i].f.f)p=a[i].f.f,y=1;
		a[i].s.f=y;
		y++;
	}
	sort(a+1,a+m+1,ppc);
	for(int i=1;i<=m;i++)
	{
		printf("%012ld\n",a[i].f.f*1000000l+a[i].s.f);
	}
	return 0;
}

Measured memory_bytes: 4608
#include<bits/stdc++.h>
    int main(){
      std::string s[3];
      long long k,a[3]={};
      std::cin>>s[0]>>k;
      for(size_t i=0;i<2;++i) s[i+1]=s[i]+s[0];
      for(size_t i=0;i<3;++i) for(size_t j=0;j<s[i].length()-1;++j) if(s[i][j]==s[i][j+1]) ++a[i],++j;
      std::cout<<(k&1?a[0]:a[1])+(k-1)/2*(a[2]-a[0])<<std::endl;
    }

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

using namespace std;

int main()
{
        string s;
        cin>>s;
        int i,j,d[10000],c[1000],k=0,p[1000];
         for(i=0;i<s.size();i++)
        {
                c[i]=s[i]-'0';
        }
        for(i=0;i<s.size()-2;i++)
        {
                d[k]=(c[i]*100)+((c[i+1])*10)+(c[i+2]);
                p[k]=abs(753-d[k]);
                k++;
        }
        sort(p,p+k);
        cout<<p[0]<<endl;
        return 0;
}


Measured memory_bytes: 256
n,q=map(int,input().split())
s=input()
ac=[0]*(n+1)
for i in range(n):
  ac[i]=ac[i-1]+(s[i:i+2]=="AC")
for i in range(q):
  l,r=map(int,input().split())
  print(ac[r-2]-ac[l-2])

Measured memory_bytes: 7668