akhauriyash/Code-Regression huggingface dataset:
import std.algorithm;
import std.bigint;
import std.bitmanip;
import std.concurrency : generator = Generator, yield;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long N) {
    generator!string f(size_t d) {
        return new generator!(string)({
            if (d <= 0)
                yield("");
            else foreach (s; f(d - 1)) {
                yield("3" ~ s);
                yield("5" ~ s);
                yield("7" ~ s);
            }
        });
    }

    return iota(N.to!string.length)
        .map!(i => f(i + 1))
        .joiner
        .filter!(s => s.canFind('3'))
        .filter!(s => s.canFind('5'))
        .filter!(s => s.canFind('7'))
        .filter!(s => s.to!long <= N)
        .count;
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    static if (is(ReturnType!solve == void))
        solve(N);
    else {
        auto ans = solve(N);

        static if (isFloatingPoint!(ReturnType!solve))
            writeln(format("%.9f", ans));
        else static if (is(ReturnType!solve == bool))
            writeln(ans ? YES : NO);
        else
            writeln(ans);
    }
}


Measured memory_bytes: 1404
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
typedef long long int ll;
using namespace std;
int main()
{
	int r,d,x;
	cin >> r >> d >> x;

	for(int i=1; i<=10; i++){
		x *= r;
		x -= d;
		cout << x << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
//保留所有权利。
#include<iostream>
#include<stdio.h>//printするよ
#include<vector>
#include<algorithm>//辞書順はnext_permutationだよ
#include<set>
#include<string>
#include<string.h>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<utility>//swapで数値交換するよ
//END OF LIBRARIES.
#define rt "\n"//改行を最速化させるよ
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define vcin(v) for (int i = 0; i < (v).size(); i++) { cin >> (v)[i]; }
#define sort(s) sort(s.begin(),s.end())
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define cncn int cnt=0
#define smsm int sum=0
#define str srting
#define nn int n=0
#define please return
#define AC 0//おまじないだよ
#define Rapid cin.tie(0);ios::sync_with_stdio(false)
//END OF DEFINE.
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vcha;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool; 
//END OF TYPEDEF.

//最大公約数（GCD）を求めるよ
//最小公倍数（LCM）は＜＜　A × B ÷ GCD　 ＞＞で求まるよ

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}
int x = 0, y = 0;
//BEGIN OF CODE.
int main(void){
	int h, a;
	cin >> h >> a;
	if (h % a == 0)cout << h / a << rt;
	else cout << h / a + 1 << rt;
	please AC;
}
//THE END.

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

using namespace std;

int main(){
    int H,W,h,w;
    cin >> H >> W >> h >> w;
    
    int math = H*W;
    int total = W*h + H*w - h*w;
   
    math -= total;
    cout << math <<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 998244353;

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

  string s;
  cin >> s;

  cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;
}


Measured memory_bytes: 256
from collections import defaultdict
while True:
  n = int(input())
  if n == 0:
    break
  score = {}
  dic = defaultdict(list)
  for _ in range(n):
    line = input().split()
    name = line[0]
    score[name] = 0
    for d in line[2:]:
      dic[d].append(name)
  
  for v in dic.values():
    p = n - len(v) + 1
    for name in v:
      score[name] += p
  
  print(*min([(v, k) for k, v in score.items()]))
  


Measured memory_bytes: 6004
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    long long a,b,k,x;
    cin>>a>>b>>k;
    x=min(k,a);
    a=a-x;
    k=k-x;
    b=b-min(b,k);
	cout<<a<<" "<<b<<endl;
}

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

group = [0]
now = 0
seen = [0]*n
seen[0] = 1
while True:
    now = an[now] - 1
    
    group.append(now)
    if seen[now] == 1:
        break
    seen[now] = 1

l = len(group)
a = group.index(group[-1])
roop = l - a - 1
if k < a:
    print(group[k] + 1)
else:
    x = (k - a) % roop
    print(group[a + x] + 1)



Measured memory_bytes: 32368
import numpy as np


def solve(k, q, d_list, query_list):

    res = []
    d_arr = np.array(d_list)
    for query in query_list:
        n, x, m = query
        d_arr_mod = (d_arr - 1) % m + 1
        x = x % m
        a_n1 = x + ((n - 1) // k) * d_arr_mod.sum() + d_arr_mod[:((n - 1) % k)].sum()
        res.append(n - 1 - a_n1 // m)

    return res


def main():
    k, q = map(int, input().split())
    d_list = list(map(int, input().split()))
    query_list = [map(int, input().split()) for _ in range(q)]
    res = solve(k, q, d_list, query_list)
    for r in res:
        print(r)


def test():
    assert solve(3, 1, [3, 1, 4], [(5, 3, 2)]) == [1]
    assert solve(7, 3, [27, 18, 28, 18, 28, 46, 1000000000], [
        (1000000000, 1, 7), (1000000000, 2, 10), (1000000000, 3, 12)]) == [224489796, 214285714, 559523809]


if __name__ == "__main__":
    # test()
    main()


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

typedef long long int ll; 
#define MOD 1000000007
#define ON 200000
#define rep(i,n) fp(i,0,n)  
#define fp(i,a,b) for(ll i=(a);i<(b);++i)
#define fn(i,a,b) for(ll i=(a);i>(b);i--)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define FF first
#define SS second
typedef pair<ll, ll> pll; 
typedef vector<pll> vpll;
typedef vector<ll> vll;
#define rs(t) string t;cin>>t
#define ri(t) int t;cin>>t
#define rll(t) long long int t;cin>>t
#define MK make_pair
#define PB push_back
#define PO pop_back
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
///// This part below is only for debug, not used /////
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
///// END /////

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  rll(n);
  ll num;
  if(n%2==0){
  	cout << (double)1/(double)2 << endl;
  }
  else{
  	cout << (double)(n/2+1)/(double)n << endl;
  }
  
  return 0;
  
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

typedef struct{
    long long x;
    long long y;
} pair;

int pairsort(const void *A, const void *B){
    long long P=((pair*)A)->x-((pair*)B)->x;
    long long Q=((pair*)A)->y-((pair*)B)->y;
    if (P!=0){
        return P;
    } else if (Q!=0){
        return Q;
    } else {
        return 0;
    }
}

int asort(const void *A,const void *B){
    return *(long long*)A>*(long long*)B?1:0;
}

int min(int A,int B){
    return A<B?A:B;
}

int max(int A,int B){
    return A>B?A:B;
}

int main(void){
    int n;
    scanf("%d",&n);
    pair ball[n];
    for (int i=0; i<n; i++){
        scanf("%lld%lld",&ball[i].x,&ball[i].y);
    }
    int ans=n;
    bool visited[n];
    qsort (ball,n,sizeof(pair),pairsort);
    for (int i=0; i<n; i++){
        for (int j=0; j<n; j++){
            int tmpans=n;
            long long tmpp=ball[j].x-ball[i].x;
            long long tmpq=ball[j].y-ball[i].y;
            for (int k=0; k<n; k++){
                visited[k]=false;
            }
            for (int k=0; k<n; k++){
                for (int l=k+1; l<n; l++){
                    if (k!=l && ball[k].x-ball[l].x==tmpp && ball[k].y-ball[l].y==tmpq && visited[l]==false){
                        tmpans--;
                        visited[l]=true;
                        //visited[l]=true;
                    }
                }
            }
            //printf("%lld %lld %d\n",tmpp,tmpq,tmpans);
            ans=min(ans,tmpans);
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#define PI atan(1.0)*4
#define E 2.718281828
#define rp(i,s,t) for (register int i = (s); i <= (t); i++)
#define RP(i,t,s) for (register int i = (t); i >= (s); i--)
#define ll long long
#define ull unsigned long long
#define mst(a,b) memset(a,b,sizeof(a))
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define debug printf("ac\n");
using namespace std;
inline int read()
{
    int a=0,b=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-')
            b=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9')
    {
        a=(a<<3)+(a<<1)+c-'0';
        c=getchar();
    }
    return a*b;
}
const int INF = 0x3f3f3f3f;
const int N = 2e5+7;
int a[N];
int main(){
    int n=read();
    rp(i,1,n) a[i]=read();
    ll ans=0;
    ll sum1=0,sum2=0;
    for(int l=1,r=0;l<=n;){
        while(r<=n&&(sum1^a[r])==sum2+a[r]){
            sum1^=a[r];
            sum2+=a[r];
            r++;
        }
        // cout<<l<<" "<<r<<endl;
        ans+=r-l;
        sum1^=a[l];
        sum2-=a[l];
        l++;
    }
    cout<<ans<<endl;
    return 0;
}
/*
1 1
1 2
2 2
2 3
2 4
3 3
3 4
4 4
4 5
4 6
4 7
5 5
5 6
5 7
6 6
6 7
6 8
7 7
7 8
8 8
9 9
10 10
10 11
10 12
11 11
11 12
12 12
13 13
14 14
14 15
14 16
15 15
15 16
16 16
17 17
18 18
19 19
37
*/

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

#define ln '\n'
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

VI ans;
void dfs(int i, bool is_black, vector<vector<P>>& edge) {
    if(ans[i] != -1) return;
    ans[i] = is_black ? 0 : 1;
    for(auto& adj : edge[i]) {
        int cost = adj.first;
        int to = adj.second;
        bool next_is_black = cost % 2 == 0 ? is_black : !is_black;
        dfs(to, next_is_black, edge);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ans.resize(n, -1);  // init
    vector<vector<P>> edge(n);  // first: cost, second: to
    REP(i, n - 1) {
        int u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        edge[u].push_back(P(w, v));
        edge[v].push_back(P(w, u));
    }

    dfs(0, true, edge);

    REP(i, n) cout << ans[i] << ln;
    return 0;
}


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

long long n, s, e, w;
string st;

void fail(){
	cout << "No";
	exit(0);
}

int main(){
	cin >> st;
	for(int i = 0; i < st.size(); i++){
		if(st[i] == 'N') n++;
		if(st[i] == 'S') s++;
		if(st[i] == 'E') e++;
		if(st[i] == 'W') w++;
	}
	if(n > 0 && s == 0) fail();
	if(s > 0 && n == 0) fail();
	if(e > 0 && w == 0) fail();
	if(w > 0 && e == 0) fail();
	cout << "Yes";
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(200002)


def dfs(start, edges, nodes):
    for adj_node, distance in edges[start].items():
        # まだ訪れていない隣接ノード
        if nodes[adj_node] is None:
            nodes[adj_node] = nodes[start] + distance
            # adj_nodeを開始位置にしてまだ訪れていないノードを探索する
            # 探索中にノード値とエッジの関係性が一致しなくなればFalse
            if not dfs(adj_node, edges, nodes):
                return False
        # 既に訪れた隣接ノード
        else:
            if nodes[adj_node] - nodes[start] != distance:
                return False

    return True


if __name__ == '__main__':
    N, M = map(int, input().split())
    if M == 0:
        print("Yes")
        exit(0)

    Ls, Rs, Ds = zip(*[list(map(int, input().split())) for _ in range(M)])

    # N, M = 10, 3
    # Ls, Rs, Ds = zip(*[[8, 7, 100],
    #                    [7, 9, 100],
    #                    [9, 8, 100]])

    edges = {i: dict() for i in range(N)}

    for L, R, D in zip(Ls, Rs, Ds):
        edges[L - 1][R - 1] = D
        edges[R - 1][L - 1] = -D

    nodes = [None] * N

    valid_list = []
    for start in range(N):
        if nodes[start] is None:
            nodes[start] = 0
            # ノード値とエッジの関係性が一致しなくなればfalse
            valid_list.append(dfs(start, edges, nodes))

    if all(valid_list):
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 160560
def resolve():
    N = int(input())
    S = input()

    ans = set()
    for i in range(1000):
        str_i = str(i).zfill(3)
        idx1 = S.find(str_i[0], 0)
        idx2 = S.find(str_i[1], idx1 + 1)
        idx3 = S.find(str_i[2], idx2 + 1)
        if idx1 != -1 and idx2 != -1 and idx3 != -1:
            ans.add(str_i)


    return print(len(ans))

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 3188
#include <iostream>
using namespace std;
int main() {
    string a;
    int n,i,b;
    cin>>n>>a>>b;
    for (i=0;i<n;i++){
        if (a[i]!=a[b-1]){
            a[i]='*';
        }
    }
    cout<<a;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

ll f(ll n) {
  if (n < 0) return 0ll;
  ll res = (n / 2) & 1;
  for (ll m = n / 2 * 2; m <= n; m++) res ^= m;
  return res;
}

int main() {
#ifdef DEBUG
  ifstream cin("in.txt");
#endif
  ll A, B;
  while (cin >> A >> B) {
    ll res = f(B) ^ f(A - 1);
    cout << res << endl;
  }
  return 0;
}


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

#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

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

void solve()
{
  string s; cin>>s;
  int l = s.length();
  ll ans = 0;
  ll tmp = 1;
  for (int i=0; i<l; i++) {
    if (s[i]=='1') {
      ans = (ans + modpow(3, l-1-i, mod)*tmp % mod) % mod;
      tmp = tmp*2%mod;
    }
  }
  ans = (ans+tmp)%mod;
  cout << ans << endl;
}

int main()
{
  solve();
  return 0;
}


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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N,M;
vector< vector<int> > A;

bool f(int m,vector< vector<int> > v)
{
	vector<int> cnt(M);
	deque<bool> erased(M);
	FOR(i,0,N) cnt [v [i].back()]++;
	while(true){
		int mx = -1,mxIdx = -1;
		FOR(i,0,M) if(chmax(mx,cnt [i])){
			mxIdx = i;
		}
		if(mx <= m) return true;
		erased [mxIdx] = true;
		FOR(i,0,N) if(erased [v [i].back()]){
			cnt [v [i].back()]--;
			while(v [i].empty() == false && erased [v [i].back()]){
				v [i].pop_back();
			}
			if(v [i].empty()) return false;
			cnt [v [i].back()]++;
		}
	}
}

int main()
{
	scanf("%d%d",&N,&M);
	A.assign(N,vector<int>(M));
	FOR(i,0,N) FOR(j,0,M){
		scanf("%d",&A [i] [j]);
		A [i] [j]--;
	}
	FOR(i,0,N) reverse(A [i].begin(),A [i].end());

	int ok = N,ng = 0,mid;
	while(ok - ng > 1){
		mid = (ok + ng) / 2;
		if(f(mid,A)){
			ok = mid;
		}
		else{
			ng = mid;
		}
	}
	printf("%d\n",ok);

	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<math.h>
#include<cstring>
#include<set>
#include<algorithm>
#include<vector>
#include<map>
#include <vector>
#include<iomanip>
#include<queue>
#include<string>
#include<bitset>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
typedef long long ll;
using namespace std;

const int N = 200;
const ll INF = (1LL << 62) - 1;
ll dist[N][N];
vector <int> rr;

int main()
{
    int n;
    cin >> n;
    set <int> s;
    for (int i = 0; i < n; ++i) {
        int k;
        cin >> k;
        if (!s.count(k))
            s.insert(k);
        else
            s.erase(k);
    }
    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 4864
//============================================================================
// Name        : Problem.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;

int solve(int m, int c, int n)
{
	queue<int>* queries = new queue<int>[n];
	int cost = 0;
	int k;
	for(int i = 0; i < n; i++)
	{
		cin >> k;
		for(int j = 0;j < k; j++)
		{
			int book_id;
			cin >> book_id;
			queries[i].push(book_id);
		}
	}

	deque<int>* desks = new deque<int>[m];
	bool flag = true;
	while(flag)
	{
		flag = false;
		for(int i = 0; i < n; i++)
		{
			if(queries[i].empty())
				continue;
			flag = true;
			int book = queries[i].front(); queries[i].pop();
			// find book
			int pos = m;
			for(int j = 0; j < m; j++)
			{
				if(count(desks[j].begin(), desks[j].end(), book) > 0){
					pos = j;
					break;
				}
			}
			if(pos < m)
				desks[pos].erase(find(desks[pos].begin(), desks[pos].end(), book));

			cost += pos + 1;

			if((int)desks[0].size() < c)
			{
				desks[0].push_back(book);
				cost += 1;
			}else{
				// step 1 : move from shelf(current position) to non-full nearest to entrance desk
				int pos_2 = m;
				for(int j = 0; j < m; j++)
				{
					if((int)desks[j].size() < c)
					{
						pos_2 = j;
						break;
					}
				}
				if(pos_2 < m)
					desks[pos_2].push_front(book);
				cost += pos_2 + 1;

				// step 2 : move least recently used from desk 1
				int pos_3 = m;
				for(int j = 0; j < m; j++)
				{
					if((int)desks[j].size() < c)
					{
						pos_3 = j;
						break;
					}
				}
				int lru = desks[0].front(); desks[0].pop_front();
				if(pos_3 < m)
					desks[pos_3].push_back(lru);

				cost += 1 + pos_3;
				cost += 1;

				// step 3 : move book from pos_2 to desk 1
				if(pos_2 < m)
					desks[pos_2].pop_front();
				desks[0].push_back(book);
				cost += pos_2 + 1;
				cost += 1;
			}
		}
	}

	deque<int> dq;
	for(int i = 0; i < m; i++)
	{
		swap(desks[i], dq);
	}

	queue<int> q;
	for(int i = 0; i < n; i++)
	{
		swap(queries[i], q);
	}

	delete[] desks;
	delete[] queries;
	return cost;
}

int main() {
	int m, c, n;
	cin >> m >> c >> n;
	while(m != 0 && c != 0 && n != 0)
	{
		cout << solve(m,c,n) << endl;
		cin >> m >> c >> n;
	}
	return 0;
}

Measured memory_bytes: 3176
#include<iostream>
#include<iomanip>
#include<algorithm> // inplace_merge
#include<cmath>
#include<vector>
using namespace std;

typedef pair<double,double> p;
p v[100000];

const double INF = 1e10;

bool comp_y(p a, p b){
    return a.second < b.second;
}

// 分割統治 O(nlogn)
double closest_pair(p *a, int n){
    if(n <= 1)  return INF;
    
    int m = n/2;
    double x = a[m].first;
    double d = min(closest_pair(a, m), closest_pair(a+m, n-m)); // x軸で区切られた範囲内での頂点対のみ考慮
    inplace_merge(a, a+m, a+n, comp_y); // ソート済みの[a, a+m)と[a+m, a+n)をy座標基準でマージ

    vector<p> b; // 直線 x = a[m].firstから距離d未満の点を入れる
    for(int i = 0; i < n; i++){
        if(fabs(a[i].first-x) >= d) continue; // そもそもx座標の差がd以上の点は論外

        // bに入っている頂点を末尾から、y座標の差がd以上になるまで見ていく
        // y座標降順で見ていき、d以上離れた時点で打ち切り
        for(int j = 0; j < b.size(); j++){
            double dx = a[i].first - b[b.size()-1-j].first;
            double dy = a[i].second - b[b.size()-1-j].second;
            if(dy >= d) break;
            d = min(d, sqrt(dx*dx + dy*dy));
        }

        b.push_back(a[i]);
    }
    return d;
}

int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        double x, y;
        cin >> x >> y;
        v[i] = {x,y};
    }
    sort(v, v+n);
    cout << fixed << setprecision(12) << closest_pair(v, n) << endl;
    return 0;
}


Measured memory_bytes: 7744
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
 
typedef long long ll;
typedef long double ld;
//typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<pair<ll,ll> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef pair<ll,pair<ll,ll> > iii;
#define PI 3.141592653589793
#define mod (ll)(1000*1000*1000+7)
//# define N 300005
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=((ans%m)*(a%m))%m; b/=2; a=((a%m)*(a%m))%m; } return ans%m; }
# define INF (ll)1e18
# define LN 20  
# define EPS 1e-9
typedef pair<ll,pair<ll,ll> > pii;
# define INF1 (ll)1e10
# define maxn 200005
# define offset 2000005
#define N 100005
const ld eps = 1e-10L;

/*void LPS()
{
	len = s.length();
    lps[0] = 0;
    for(ll i=1;i<len;i++){

        ll j = lps[i-1];
        while(j > 0 && s[j] != s[i])    j = lps[j-1];
        if(s[i] == s[j])    j++;
        lps[i] = j;
    }
}*/

/*************************************************
struct Coupon {
	ll l;
	ll r;
	ll id;

	Coupon(ll l, ll r, ll id): l(l), r(r), id(id) {} // Initialization

	bool operator<(const Coupon& c) { // Sorting
		return l < c.l;    
	}
};

**************************************************/

int a[maxn];
int n;
int k;
int dp[101][100002];

ll solve(int id,int left)
{
	//trace2(id,left);
	if(left<0)
		return 0;
	if(left>k)
		return 0;
	if(id==n+1)
	{
		return (left==k);
	}
	if(dp[id][left]!=-1)
		return dp[id][left];
	ll ans=(solve(id+1,min(k,left+a[id]))%mod)-(solve(id+1,left-1)%mod);
	if(ans<0)
		ans+=mod;
	ans%=mod;
	ans+=solve(id,left-1);
	ans%=mod;
	return dp[id][left]=ans;
}

int main()
{
	IOS;
	cin >> n >> k;
	for(int i=1;i<=n;i++)
		cin >> a[i];
	memset(dp,-1,sizeof dp);
	cout << solve(0,0);
}

Measured memory_bytes: 44416
// inputに入力データ全体が入る
function Main(input) {
  input = input.split("\n")[0]

  tmp = input.split(' ').map(v=> parseInt(v))
  H = tmp[0]
  W = tmp[1]
  if(H ==1 || W ==1){
    t =1
  }else{
  t = H * Math.floor((W / 2))
  if(W % 2 == 1){
    t += Math.round(H / 2)
  }
  }


  console.log(t);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    int n,Q;
    cin>>n>>Q;
    vector<vector<ll> > g(n);
    for(int i=0;i<n-1;i++){
	ll a,b;
	cin>>a>>b;
	a--,b--;
	g[a].push_back(b);
	g[b].push_back(a);
    }
    vector<ll> cost(n,0);
    vector<bool> used(n,true);
    for(int i=0;i<Q;i++){
	ll p,x;
	cin>>p>>x;
	p--;
	cost[p]+=x;
    }
    priority_queue<mp> q;
    q.push(mp(0,0));
    while(!q.empty()){
	mp now = q.top();
	q.pop();
	ll nc = now.first;
	ll nn = now.second;
	if(!used[nn])continue;
	used[nn] = false;
	cost[nn] += nc;
	for(int i=0;i<g[nn].size();i++){
	    q.push( mp( cost[nn],g[nn][i] ) );
	}
    }
    cout<<cost[0];
    for(int i=1;i<n;i++)cout<<' '<<cost[i];
    cout<<endl;

    return 0;
}


Measured memory_bytes: 20592
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld double 
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define BOOST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define sl(a) a.size()
#define mod 1000000007 
#define lcm(a,b) (a*b)/__gcd(a,b)
#define MAX1 100006
#define f first
#define s second
#define pi 2*acos(0.0)
void solve()
{
    int n,ans=0;  cin>>n;
    int arr[n]; 
    rep(i,0,n) cin>>arr[i];
    rep(i,1,n-1)
    {
        int ar[]={arr[i-1],arr[i],arr[i+1]};
        sort(ar,ar+3);
        ans+=(ar[1]==arr[i]);
    }cout<<ans;
}
int main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt","r",stdin);
    //for getting error from error.txt
    freopen("error.txt", "w", stderr);
    // for writing output to output.txt
    freopen("output.txt","w",stdout);
    #endif
    BOOST
    int T=1;  //cin>>T;
    while(T--) solve();
    cerr<<"Time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<"\n";
    cerr<<"My CLOCKS_PER_SEC= "<<CLOCKS_PER_SEC<<"\n";
    return 0;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int n, m;
    cin >> n >> m;
    vector<string> a, b;
    rep(i, n){
        string s;
        cin >> s;
        a.push_back(s);
    }
    rep(i, m) {
      string s;
      cin >> s;
      b.push_back(s);
    }
    rep(i, n-m+1){
        rep(j, n-m+1){
            bool flag = true;
            rep2(k, i, i+m){
                rep2(l, j, j+m){
                    if(a[k][l]!=b[k-i][l-j]){
                        flag = false;
                        break;
                    }
                }
                if(!flag){
                    break;
                }
            }
            if(flag){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3608
V,E=map(int,input().split())
dis=[[10**10 for _ in range(V)]for _ in range(V)]
for i in range(E):
	u,v,d=map(int,input().split())
	dis[u-1][v-1]=d
	dis[v-1][u-1]=d
def warshall_floyd(d):
	for k in range(V):
		for i in range(V):
			for j in range(v):
				d[i][j]=min(d[i][j],d[i][k]+d[k][j])
	return d
dis=warshall_floyd(dis)
#ここから上は不変
t=int(input())
bag=[]
for i in range(t):
	N_new=int(input())
	p=[]
	for j in range(N_new):
		id,dst=map(int,input().split())
		p.append([id,dst])
	bag.append(p)
now=1
for i in range(t):
	print(-1)


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

using namespace std;

typedef long long int ll;
#define pb push_back
#define ALL(a) (a).begin() , a.end()

int mod = 1e9 + 7;
int add(int a, int b){
	if(a + b >= mod)return a+ b - mod;
	return a + b;
}
int mul(int a, int b){
	return 1LL * a * b  % mod;
}
int power(int a, int b){
	int re = 1;
	while(b){
		if(b&1)re= mul(re, a);
		a = mul(a, a);
		b>>=1;
	}
	return re;
}
int const N = 200 * 1010;

/********************i**********************************/
vector<vector<int>> match(25, vector<int>(25, 0));
int n1;
int dp[25][(1<<22)];

int go(int n, int mask){

	if(dp[n][mask] != -1)return dp[n][mask];

	if(n == n1){
		return 0;
	}
	auto &ans = dp[n][mask];
	ans = 0;
	for(int x = 0; x<n1; x++){
		if(!(mask & (1<<x)) && match[n][x] == 1){
			// cout << n << "  x  " << x << " ans " << ans << endl;
			ans = add(ans,  go(n+1, (mask ^ (1<<x))));
		}
	}
	// cout << n << " " << mask << " --  " << ans << endl;; 
	return ans;
}

void solve(){
	int n; cin >> n;
	n1 = n;
	for(int x =0; x<n; x++){
		for(int y = 0; y<n; y++){
			cin >> match[x][y];
		}
	}
	for(int x =0; x<n; x++)
		for(int y =0; y<(1<<n); y++)
			dp[x][y] = -1;
	dp[n][(1<<n)-1] = 1;
	int a =  go(0, 0);
	cout << dp[0][0];
	// for(int x =0; x<n; x++){
	// 	for(int y =0; y<(1<<n); y++)
	// 		cout << dp[x][y] << " ";
	// 	cout << endl;
	// }
}

/******************************************************/
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	int t;
	t = 1;
	// cin >> t;
	while(t--){
		solve();
	}
}

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

struct cc{
    int y;
    int x;
    int depth;
};
std::vector<std::pair<int,int>> dir{{0,1},{1,0},{-1,0},{0,-1}};

int main()
{
    int h,w;
    std::cin >> h >> w;
    std::vector<std::vector<bool>> map(h + 2,std::vector<bool>(w + 2));
    int ans = 0;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            char t; std::cin >> t;
            map[i][j] = (t == '.');
            if(map[i][j])ans++;
        }
    }
    int path = 100000000;
    std::vector<std::vector<bool>> seen(h + 2, std::vector<bool>(w + 2));
    std::queue<cc> que;
    que.push({1,1,0});
    seen[1][1] = true;
    while(que.size()){
        auto cur = que.front();
        que.pop();
        if(cur.y == h && cur.x == w){
            path = cur.depth;
            break;
        }
        for(auto i : dir){
            if(seen[cur.y + i.first][cur.x + i.second] || !map[cur.y + i.first][cur.x + i.second])continue;
            que.push({cur.y + i.first,cur.x + i.second, cur.depth + 1});
            seen[cur.y + i.first][cur.x + i.second] = true;
        }
        
    }
    std::cout << (path == 100000000 ? -1 : ans - path - 1) << std::endl;

}

Measured memory_bytes: 256
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import scipy as scp

# 入力の受け取り
a,b = map(int,input().split())

if (a+b)%2 == 0:
    ans = (a+b)//2
else:
    ans = "IMPOSSIBLE"

print(ans)
# print("{:.10f}".format(ans))
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する



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

int32_t main() {
    ios_base::sync_with_stdio(0);
    int h, w, a, b;
    cin >> h >> w >> a >> b;

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; j++) {
            int x = (i < b) ^ (j < a);
            cout << x;
        }
        cout << "\n";
    }

    return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end() 
#define SZ(x) (int)x.size()
#define f first
#define s second
const int MAXN=410000;
const int MAXK=18;
const int INF = 1e9;
const ll MOD = 998244353;

ll N,R,Q,a,b,c,d,e,f;
vi A,B,C;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	map<string,int> M;
	string A;
	cin>>N;while(N--){cin>>A;M[A]++;}
	string verdicts[] = {"AC","WA","TLE","RE"};
	for(int i=0;i<4;++i){
		cout<<verdicts[i]<<" x "<<M[verdicts[i]]<<'\n';
	}
}

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

int main() {
  string S;
  cin >> S;
  vector<char>bun(6);
  for (int i = 0; i < 6; i++) {
    bun.at(i) = S.at(i);
}
  if (bun.at(2)==bun.at(3) && bun.at(4)==bun.at(5))
  {cout << "Yes" << endl;}
  else {cout << "No" << endl;}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define emp emplace
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
const ll MAXN = 200100;
const ll INF = 1e9;
const ll MOD = 1e9+7;

ll N,Q,a,b,c,d,e,M,X;
ll A[MAXN];
ll B[MAXN];
map<ll,ll> p;
ll ans;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>X;
	for (ll a=-3800;a<=3800;++a){
		for(ll b=-3800;b<=3800;++b){
			if(a*a*a*a*a-b*b*b*b*b==X){
				cout<<a<<' '<<b;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

signed main() {
	int x;
	cin >> x;
	
	for (int a = -3000; a <= 3000; a++) {
		for (int b = -3000; b <= 3000; b++) {
			if (a * a * a * a * a - b * b * b * b * b == x) {
				cout << a << " " << b << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3636
//
// Created by Mahmoud Rashad on 11/27/19.
//

#include <bits/stdc++.h>


using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<ii, ii>> vii;


const int A = 911382323, B = 972663749;

const int P = 31 , MOD = 1e9 + 9; // Single Hashing parameters

void compute_hash(string const& s , vector<int> &preH) {
    int n = (int)s.size();
    preH.resize(n);
    long long hash_value = 0;
    long long p_pow = 1;
    for(int i = 0 ; i < n ; ++i){
        hash_value = (hash_value + (s[i] - 'a' + 1) * p_pow) % MOD;
        p_pow = (p_pow * P) % MOD;
        preH[i] = hash_value;
    }
}

int power(int b, int p) {
    if (p == 0) return 1;
    int res = power(b, p / 2);
    res = 1LL * res * res % MOD;
    if (p & 1) {
        res = 1LL * b * res % MOD;
    }
    return res;
}

int modInv(int x) {
    return power(x, MOD - 2);
}

int mul(int a , int b , int m){
    return (1LL * (a % m) * (b % m)) % m;
}

int add(int a , int b , int m){
    return (1LL * (a % m) + (b % m)) % m;
}

long long get_hash(int l , int r , vector<int> &preH){                     // returns hash value of substring using preH of string in O(log n) s.t. n is size of the string
    long long ret = (preH[r] - (l ? preH[l - 1] : 0) + MOD) % MOD;          // can be negative so we add MOD
    return mul(ret , modInv(power(P , l)) , MOD);                           // divide it by p^l
}

int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.out", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;

    int n;
    cin >> n;
    string str;
    cin >> str;
    vector<int> h(n);
    compute_hash(str, h);
//    h[0] = str[0];
//    for (int i = 1; i < n; ++i) {
//        h[i] = (h[i - 1] * A + (str[i] - 'a')) % B;
//    }
//    vector<long long> p(n);
//    p[0] = 1;
//    for (int i = 0; i < n; ++i) {
//        p[i] = 1LL * p[i - 1] * A % B;
//    }

//    int x = get_hash(0, 1, h);
//    int y = get_hash(2, 3, h);

//    cout << x << ' ' << y << endl;

    int l = 0, r = n;
    while (true) {
        int m = (l + r) / 2;
        if (m == l)
            break;
        bool f = false;
        set<pair<int, int>> st;
        for (int i = 0; i + m - 1 < n; ++i) {
            int hash = get_hash(i, i + m - 1, h);
            auto it = st.lower_bound({hash, -1});
            if ((*it).first == hash) {
                if ((*it).second + m - 1 < i) {
                    f = true;
                    break;
                }
            } else {
                st.insert({hash, i});
            }
        }
        if (f)
            l = m;
        else
            r = m;
    }

    cout << l << '\n';

    return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<int> a(n); REP(i, n) cin >> a[i];
  sort(ALL(a), greater<int>());
  int ans = 0;
  REP(i, n) {
    if (i%2==0) ans += a[i];
    else ans -= a[i];
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
package main

import "fmt"
import "math"

func main() {
  var n,k int
  const MAX_N = 110
  var x[MAX_N] int
  fmt.Scan(&n)
  fmt.Scan(&k)
  for i:=0 ; i < n ; i++ {
    fmt.Scan(&x[i])
  }
  var min_sum = 0
  for i:= 0 ; i < n ; i++ {
    var tmp_x = x[i]
    min_sum += int(math.Min(float64(2*tmp_x), 2*math.Abs(float64(k-tmp_x))))
  }
  fmt.Println(min_sum)
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<algorithm>
#include<cstdio>
#include<stack>
#include<queue>
#include<cstring>
#define up 1
#define right 2
#define down 3
#define left 4
#define mod 1000000007
#define ll long long

using namespace std;

vector< ll > v;

int main(){
    cin.sync_with_stdio(false);
    int n;
    cin >> n;
    v.push_back(0);
    for(int i = 1 ; i <= n ; ++i){
        int x;
        cin >> x;
        v.push_back(x);
    }
    v.push_back(0);
    ll res = 0;
    for(int i = 1 ; i <= n + 1 ; ++i){
        res += abs(v[i] - v[i - 1]);
    }
    for(int i = 1 ; i <= n ; ++i){
        ll curr = res;
        curr -= abs(v[i] - v[i - 1]);
        curr -= abs(v[i + 1] - v[i]);
        curr += abs(v[i + 1] - v[i - 1]);
        cout << curr << endl;
    }
}



Measured memory_bytes: 2164
#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($( { splits.next().unwrap().parse::<$t>().unwrap() },)*)
    }}
}


#[allow(unused_macros)]
macro_rules! invec {
    ( $ t : ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(n) => s
                .trim()
                .split_whitespace()
                .map(|s| s.parse::<$t>().unwrap())
                .collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }};
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (n, m) = input!(usize, usize);
    let costs = invec!(u64);
    let mut queue = std::collections::BinaryHeap::new();

    for cost in costs {
        queue.push(cost);
    }

    for _ in 0..m {
        let max = queue.pop().unwrap();
        queue.push(max / 2);
    }

    let total: u64 = queue.iter().sum();

    println!("{}", total);
}

fn main() {
    solve();
}


Measured memory_bytes: 8444
mod = 10**9+7
from math import factorial

N,K = map(int,input().split())

def comb(n,k):
    if (k<0 or k>n):
        return 0
    k = min(k,n-k)
    return g1[n]*g2[k]*g2[n-k] % mod

g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

if N==K:
    print(1)
    for i in range(K-1):
        print(0)

else:
    for i in range(1,K+1):
        blue=0
        red=0

        if K>=i:
            blue=comb(K-1,i-1)
        for j in [i-1,i,i+1]:
            if N-K>=j and j>0:
                if i!=j:
                    red += comb(N-K-1,j-1)
                else:
                    red += 2*comb(N-K-1,j-1) % mod
        print(blue*red % mod)


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;

using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vvvd = vector<vector<vector<double>>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pint = pair<int, int>;
using Graph = vvi;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

bool cmp(pint a, pint b) {return a.second < b.second;}
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}

const double PI=acos(-1.0);

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

    int cnt = 1;
    char p = s[0];
    for(int i = 1; i < s.size(); i++) {
        if(s[i] == p) continue;
        else {
            p = s[i];
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 512
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;
const long mod = 1000000007;


int main() {

	string S; cin >> S;
	long slen = S.length();

	long dp[100009][5] = {};//どこまで走査して何文字照合させたか。
	dp[0][0] = 1;


	for (int i = 1; i <= slen; i++) {
		
		for (int j = 0; j <= 3; j++) dp[i][j] = dp[i - 1][j];
		
        for(int j = 0; j <= 3; j++) if (S[i - 1] == '?') dp[i][j] *= 3;
        //?にAを代入しようが、?にBCを代入しようが「状態そのまま」の組み合わせに影響しない
        
		if (S[i - 1] == 'A' || S[i - 1] == '?') dp[i][1] += dp[i - 1][0];
		if (S[i - 1] == 'B' || S[i - 1] == '?') dp[i][2] += dp[i - 1][1];
		if (S[i - 1] == 'C' || S[i - 1] == '?') dp[i][3] += dp[i - 1][2];
        
        for(int j = 0; j <= 3; j++) dp[i][j] %= mod;
	}

	cout << dp[slen][3] << endl;

}

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

int main() {
    
    
    int n,m;
    cin>>n>>m;
    vector< vector<int> > A(n,vector<int>(m));
    vector<int> B(m);
    vector<int> C(n,0);
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>A.at(i).at(j);
        }
    }
    for(int i=0;i<m;i++){
        cin>>B.at(i);
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            C.at(i)+=A.at(i).at(j)*B.at(j);
        }
        cout<<C.at(i)<<endl;
    }
}



Measured memory_bytes: 3184
#include <stdio.h> 

int main(void)
{
    // int x;
    // scanf("%d", &x);
    // printf("%d\n", x);

    // long x;
    // scanf("%ld", &x);
    // printf("%ld\n", x);

    // char array[x];

    long x, sum=100,cnt=0;
    scanf("%ld", &x);
    // printf("%ld\n", x);


    while (1) {
        sum *= 1.01;
        cnt++;
        if (sum >= x)
            break;
    }
    printf("%ld\n", cnt);

    return 0;
}

Measured memory_bytes: 1732
#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, ll> pil;

const ll INF = 1e17;

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

	int n, m;
	ll L;
	cin >> n >> m >> L;

	ll dist[n][n];
	rep(i, n) rep(j, n) dist[i][j] = INF;
	rep(i, n) dist[i][i] = 0;

	rep(i, m){
		int a, b;
		ll c;
		cin >> a >> b >> c;
		a--; b--;

		dist[a][b] = c;
		dist[b][a] = c;
	}

	rep(k, n) rep(i, n) rep(j, n) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);

	ll dist2[n][n];
	rep(i, n) rep(j, n) {
		if(i == j) dist[i][j] = 0;
		dist2[i][j] = dist[i][j] <= L ? 1 : INF;
	}

	rep(k, n) rep(i, n) rep(j, n) dist2[i][j] = min(dist2[i][j], dist2[i][k] + dist2[k][j]);

	int q;
	cin >> q;
	rep(_, q){
		int s, t;
		cin >> s >> t;
		s--; t--;
		cout << (dist2[s][t] == INF ? -1 : dist2[s][t] - 1) << endl;
	}

}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
 
 
int main(){
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int sum=0;
  for(int r=0; r<=N/R; r++){
    for(int g=0; g<=(N-R*r)/G; g++){
      if((N-R*r-g*G)%B==0){
        sum++;
      }
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256