akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <functional>
using namespace std;

template <typename T>
struct ReRooting
{
  using F = function<T(T, int)>;
  using F2 = function<T(T, T)>;
  int V;
  vector<vector<int>> E;
  vector<vector<T>> dp;
  //f(v) = g(merge(f(dp_c1,c1), f(dp_c2,c2), ..., f(dp_ck,ck)) , v)
  F f, g;
  F2 merge;
  T mi; //identity of merge

  ReRooting(int V_, F f_, F2 merge_, T mi_, F g_ = [](T a, int b) { return a; })
      : V(V_), f(f_), merge(merge_), mi(mi_), g(g_)
  {
    E.resize(V);
    dp.resize(V);
  }

  void add_E(int a, int b)
  {
    E[a].push_back(b);
    E[b].push_back(a);
  }

  T dfs1(int p, int v)
  {
    T res = mi;
    for (int i = 0; i < E[v].size(); ++i)
    {
      if (E[v][i] == p)
        continue;
      dp[v][i] = dfs1(v, E[v][i]);
      res = merge(res, f(dp[v][i], E[v][i]));
    }
    return g(res, v);
  }

  void dfs2(int p, int v, T add)
  {
    for (int i = 0; i < E[v].size(); ++i)
    {
      if (E[v][i] == p)
      {
        dp[v][i] = add;
        break;
      }
    }

    vector<T> pL(E[v].size() + 1), pR(E[v].size() + 1);
    pL[0] = mi;
    for (int i = 0; i < E[v].size(); ++i)
      pL[i + 1] = merge(pL[i], f(dp[v][i], E[v][i]));
    pR[E[v].size()] = mi;
    for (int i = E[v].size(); i > 0; --i)
      pR[i - 1] = merge(pR[i], f(dp[v][i - 1], E[v][i - 1]));

    for (int i = 0; i < E[v].size(); ++i)
    {
      if (E[v][i] == p)
        continue;
      T val = merge(pL[i], pR[i + 1]);
      dfs2(v, E[v][i], g(val, v));
    }
  }

  void calc(int root = 0)
  {
    for (int i = 0; i < V; ++i)
      dp[i].resize(E[i].size());
    dfs1(-1, root);
    dfs2(-1, root, mi);
  }

  T solve(int v)
  {
    T ans = mi;
    for (int i = 0; i < E[v].size(); ++i)
    {
      ans = merge(ans, f(dp[v][i], E[v][i]));
    }
    return g(ans, v);
  }
};

int main()
{
  int n, m;
  cin >> n >> m;
  auto f = [&](long long a, int v) {
    (void)v;
    return (a + 1) % m;
  };
  auto merge = [&](long long a, long long b) {
    return a * b % m;
  };
  ReRooting<long long> re(n, f, merge, 1);
  for (int i = 0; i < n - 1; ++i)
  {
    int x, y;
    cin >> x >> y;
    x--, y--;
    re.add_E(x, y);
  }
  re.calc();
  for (int i = 0; i < n; ++i)
    cout << re.solve(i) << endl;
  return 0;
}


Measured memory_bytes: 31488
S = str(input())
target = ["A","C","G","T"]
ans = ""

for i in range(len(S)):
    if S[i] in target:
        ans+="1"
    else:
        ans+="0"

ans = ans.split("0")
cnt = 0

for i in range(len(ans)):
    cnt = max(len(ans[i]),cnt)

print(cnt)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

int main()
{
	int x, h;
	double x2;
	double X, H;
	double S;
	
	while (1){
		x = 0;
		h = 0;
		x2 = 2.0;
		
		cin >> x >> h;
		
		if (x == 0 && h == 0){
			break;
		}
		
		X = x * x;
		x2 = x / x2;
		H = sqrt(x2 * x2 + h * h);
		
//		cout << X << " " << x2 << " " << H << endl;
		
		S = X + (H * x2) * 4;
		
		printf("%f\n", S);
	}
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

const int N = 21, M = (1<<N);
int mat[N][N], n, mod = 1e9 + 7;
ll dp[N][M];

ll f(int i, int mask){
  if(i == n){
    return !mask? 1: 0;
  }
  ll &ans  = dp[i][mask];
  if(ans != -1)return ans;
  ans = 0;
  forn(j, 0, n){
    if((mask >> j & 1) && mat[i][j]){
      ans = (ans + f(i+1, mask^(1 << j)))%mod;
    }
  }
  return ans;
}



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

  cin >> n;
  forn(i, 0, n){
    forn(j, 0, n){
      cin >> mat[i][j];
    }
  }
  memset(dp, -1, sizeof dp);
  int mask = (1 << n)-1;
  cout << f(0, mask) << endl;



}





Measured memory_bytes: 347724
//
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

int main(){

    ll A, B;
    cin >> A >> B;
    ll ans = -1;
    rep1(i, 100000){
        ll a = i * 0.08;
        ll b = i * 0.1;
        if(a == A && b == B){
            ans = i;
            break;
        }
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,X,Y,Z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;

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

int main() {
    cin >> X >> Y;
    int sum = 0;
    if(X == 1 && Y == 1) sum += 400000;
    if(X == 1) sum += 300000;
    if(X == 2) sum += 200000;
    if(X == 3) sum += 100000;
    if(Y == 1) sum += 300000;
    if(Y == 2) sum += 200000;
    if(Y == 3) sum += 100000;
    cout << sum;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;
int main(){ 
   int a,b;
   cin>>a>>b;
   string s;
   cin>>s;
   bool x=true;
   rep(i,a+b){
      if(i==a) continue;
      if('0'<=s[i] && s[i]<='9') continue;
      else x=false;
   }
   if(s[a]!='-') x=false;

   x? cout<<"Yes":cout<<"No";


   
   return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n = int(input())
    A = list(map(int,input().split())) #深さiの葉の数
    B = [0] * (n + 1)   #深さiの、葉でない頂点の数
    sum_A = sum(A[1:]) # その深さ以上の葉の数の和

    B[0] = 1 - A[0]
    if sum_A == 0:
        if B[0] == 0:
            print(1)
        else:
            print(-1)
        sys.exit()
    ans = 1
    for i in range(1, n + 1):
        sum_A -= A[i]
        max_b = min(2*B[i-1] - A[i], sum_A)
        if max_b + A[i] < B[i-1] or max_b < 0:
            print(-1)
            sys.exit()
        else:
            B[i] = max_b
        ans += A[i] + max_b

    print(ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 86360
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N, M = read_int()
num_array = [read_int()[0] for _ in range(M)]

BIG = 1000000007

dp = [0 for _ in range(N + 2)]
for i in range(M):
    dp[num_array[i]] = -1

def solve():
    ans = 0
    dp[0] = 1
    for i in range(N):
        if dp[i] == -1:
            if dp[i + 1] == -1:
                return 0
            continue
        if dp[i + 1] != -1:
            dp[i + 1] += dp[i] % BIG if dp[i + 1] == 0 else dp[i]
        if dp[i + 2] != -1:
            dp[i + 2] += dp[i] % BIG if dp[i + 2] == 0 else dp[i]
    return dp[N] % BIG

if __name__ == "__main__":
    print(solve())

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

typedef long long int ll;

int main () {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    string s,t;
    cin >> s >> t;
    
    ll ans = INT_MAX;
    
    ll n = s.size();
    ll m = t.size();
    
    for (ll i=0 ; i<n-m+1 ; i++) {
		ll cur = 0;
		for (ll j=0 ; j<m ; j++) {
			if (s[i+j]!=t[j]) cur++;
		}
		ans = min(ans,cur);
	}
	
	cout << ans << "\n";
    
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;using pld=pair<ld,ld>;
const ll INF=1LL<<60;void solve();int main(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();}
#define foreach(i,a) for(auto &i:a)
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d!=0&&d>0?i<n:i>n;i+=d)
template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b; return 1;} return 0;}

void solve(){
  ll n; cin>>n;
  vector<ll> A(n),B(n);
  rep(i,n) cin>>A[i];
  rep(i,n) cin>>B[i];

  ll ans=0;
  rep(d,30){
    ll T=1<<d;
    vector<ll> C(n),D(n);
    rep(i,n) C[i]=A[i]%(2*T);
    rep(i,n) D[i]=B[i]%(2*T);
    sort(D.begin(),D.end());
    ll cnt=0;
    foreach(c,C){
      cnt+=D.end()-lower_bound(D.begin(),D.end(),T-c);
      cnt-=D.end()-lower_bound(D.begin(),D.end(),2*T-c);
      cnt+=D.end()-lower_bound(D.begin(),D.end(),3*T-c);
      cnt-=D.end()-lower_bound(D.begin(),D.end(),4*T-c);
    }
    if(cnt&1) ans+=T;
  }

  cout<<ans<<"\n"; 
}

Measured memory_bytes: 8512
#include "bits/stdc++.h"
#include <unordered_set>
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

struct UnionFind
{
	UnionFind(int n) : p(n, -1) {}
	int root(int u)
	{
		return p[u] < 0 ? u : p[u] = root(p[u]);
	}
	int size(int u)
	{
		return -p[root(u)];
	}
	bool same(int u, int v)
	{
		return root(u) == root(v);
	}
	void unite(int u, int v)
	{
		u = root(u);
		v = root(v);
		if (u == v) return;
		if (p[u] > p[v]) swap(u, v);
		p[u] += p[v];
		p[v] = u;
	}
	vector<int> p;
};

int main()
{
	cout << fixed << setprecision(10);

	int n, m;
	cin >> n >> m;
	UnionFind tree(n);
	REP(i, m)
	{
		int a, b;
		cin >> a >> b;
		tree.unite(a - 1, b - 1);
	}
	int ans = 1;
	REP(i, n)
	{
		chmax(ans, tree.size(i));
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 4060
import heapq

from typing import List


def main():
    n, k = map(int, input().split())
    v = []
    for _ in range(n):
        a, b = map(int, input().split())
        v.append((a, b))

    print(sv(v, k))


def sv(v: List[List[int]], k: int) -> int:
    vv = {}
    for a, b in v:
        if str(a) in vv:
            vv[str(a)].append(b)
        else:
            vv[str(a)] = []
            vv[str(a)].append(b)

    hp = []
    result = 0
    bk = 1
    while k >= bk:
        if str(bk) in vv:
            for b in vv[str(bk)]:
                heapq.heappush(hp, -b)
        if len(hp) > 0:
            result += -heapq.heappop(hp)
        bk += 1

    return result


if __name__ == '__main__':
    main()


Measured memory_bytes: 44984
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long ans = 0;
        if(N % 2 == 0){
            long k = 10;
            while(k <= N){
                ans += N / k;
                k *= 5;
            }
            
        }
        else{
            System.out.println("0");
            return;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Main{
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        try {
            String line;

            line = br.readLine();
            while (line != null) {
                StringBuilder sb = new StringBuilder();
                int hit =0;
                int blow = 0;
                LinkedList<Integer> listA = new LinkedList<>();
                LinkedList<Integer> listB = new LinkedList<>();

                st = new StringTokenizer(line);
                listA.add(Integer.parseInt(st.nextToken()));
                listA.add(Integer.parseInt(st.nextToken()));
                listA.add(Integer.parseInt(st.nextToken()));
                listA.add(Integer.parseInt(st.nextToken()));

                line = br.readLine();
                st = new StringTokenizer(line);
                listB.add(Integer.parseInt(st.nextToken()));
                listB.add(Integer.parseInt(st.nextToken()));
                listB.add(Integer.parseInt(st.nextToken()));
                listB.add(Integer.parseInt(st.nextToken()));
                for (int i = 0; i < 4; i++) {
                    if(listB.indexOf(listA.get(i))==i){
                        hit++;
                    }else if(listB.contains(listA.get(i))){
                        blow++;
                    }
                }
                sb.append(hit).append(" ").append(blow);
                System.out.println(sb.toString());
                line = br.readLine();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

Measured memory_bytes: 23924
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

        int N=gi();
        String S=gs();
        
        
        System.out.print(S.length()-S.replace("ABC", "!!").length());

//        if (s>L[n-2]) {
//        	System.out.println("Yes");
//        }else {
//        	System.out.println("No");
//        }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35584
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; ++i) {
    cin >> A[i];
  }
  map<ll, ll> counts;
  counts[A[0] + 0]++;
  ll ans = 0;
  for (ll j = 1; j < N; ++j) {
    ll x = j - A[j];
    ans += counts[x];
    counts[A[j] + j]++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 27036
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    int a,b[100],c=0,Alice=0,Bob=0;
    cin>>a;
    for(int i=0;i<a;i++){
        cin>>b[i];
    }
    sort(b,b+a);
    if(a%2==0){
        for(int i=0;i<a;i++){
            if(c%2==0){
                Alice=Alice+b[i];
            }else{
                Bob=Bob+b[i];
            }
            c++;
        }
    }
        if(a%2==1){
        for(int i=0;i<a;i++){
            if(c%2==1){
                Alice=Alice+b[i];
            }else{
                Bob=Bob+b[i];
            }
            c++;
        }
    }
    
    cout<<Bob-Alice<<endl;
}

Measured memory_bytes: 256
//
#include <bits/stdc++.h>
using namespace std;
#define ote(x) cout<<(x)<<endl

int main(){
	string s; cin>>s;
	int m = (s[5]-'0')*10+(s[6]-'0');
	int d = (s[8]-'0')*10+(s[9]-'0');
	if(m*100+d<=430) ote("Heisei");
	else ote("TBD");
}


Measured memory_bytes: 256
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
  if a[i] > K:
    break
  while b[j] > K - a[i]:
    j -= 1
  ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 47444
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

long long power(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a ;
        a = a * a ;
        b >>= 1;
    }
    return res;
}


signed main()
{

ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n;
    cin>>n;
    int ini=1;
    int z=1;
    while (1)
    {
        z*=26;
        if(z<n)
            n-=z;            
        else
            break;
        ini++;
    }
    
    vector<int>ans;
    for(int i=1;i<=ini&&n>0;i++)
    {
        for(int j=0;j<26;j++)
        {
            int z=power(26,ini-i)*(j+1);
            if(z>n)
            {
                n-=power(26,ini-i)*j;
                ans.push_back(j);
                break;
            }
            else if(z==n)
            {
                ans.push_back(j);
                for(int j=i+1;j<=ini;j++)
                    ans.push_back(25);
                n=-1;
                break;
            }
        }
    }

    for(auto i:ans)
        cout<<char(97+i);
    cout<<'\n';

} 
    
 


Measured memory_bytes: 3632
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	// a := make([]int, n)
	m := map[int]int{}
	for i := 0; i < n; i++ {
		m[nextInt()]++
	}

	cnt := 0
	for k, v := range m {
		if k != v {
			if k > v {
				cnt += v
			} else {
				cnt += v - k
			}
		}
	}

	fmt.Println(cnt)
}


Measured memory_bytes: 7040
def cost(place,zone):
    if zone == 0 or zone == 4:
        return A[place]
    elif zone == 1 or zone == 3:
        if A[place] == 0:
            return 2
        elif A[place] % 2 == 0:
            return 0
        else:
            return 1
    else:
        if A[place] % 2 == 0:
            return 1
        else:
            return 0

if __name__=='__main__':
    L = int(input())
    A = [int(input()) for i in range(L)]

    # dp配列の初期化
    dp = [[0 for _ in range(5)] for _ in range(L+10)]
    # 初項の設定
    for j in range(5):
        dp[0][j] = cost(0,j)
    # dp配列の更新
    for i in range(1,L):
        dp[i][0] = dp[i-1][0]+cost(i,0)
        for j in range(1,5):
            # 0〜jまでの最小に，i番目をjにするためのコストを足したものが最小
            dp[i][j] = min(min(dp[i-1][0:j+1])+cost(i,j),dp[i][j-1])
    # print(dp)
    print(min(dp[L-1]))

Measured memory_bytes: 67668
N=int(input())
l,r=0,N
print(0)
s=input()
ls=s
if s!='Vacant':
    for i in range(19):
        x=l+(r-l)//2
        print(x)
        s=input()
        if s=='Vacant':
            break
        elif (x-l)%2==0 and s==ls or (x-l)%2==1 and s!=ls:
            l=x
            ls=s
        else:
            r=x

Measured memory_bytes: 3660
n = int(input())
a = list(map(int, input().split()))
s = [0]
for i in a:
    s.append(i+s[-1])
b = sorted(s)
c = [[b[0], 1]]
for i in range(1, n+1):
    if b[i] == c[-1][0]:
        c[-1][1] += 1
    else:
        c.append([b[i], 1])
ans = 0
for i in c:
    ans += (i[1]*(i[1]-1))//2
print(ans)

Measured memory_bytes: 44992
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
vector<ll> MEMO(20000, -1);

ll loop(ll curHP, ll skill, ll N, vector<ll> &D, vector<ll> &MP) {
    curHP -= D[skill];
    ll min_mp = 1e9;
    if (curHP <= 0) {
        return MP[skill];
    } else if (MEMO[curHP] != -1) {
        return MP[skill] + MEMO[curHP];
    } else {
        for (int i = 0; i < N; i++) {
            ll mp = loop(curHP, i, N, D, MP);
            if (mp < min_mp) {
                min_mp = mp;
            }
        }
        MEMO[curHP] = min_mp;
        return MP[skill] + min_mp;
    }
}

int main() {
    ll H, N;
    cin >> H >> N;
    vector<ll> D(N), MP(N);
    for (int i = 0; i < N; i++) {
        cin >> D[i] >> MP[i];
    }
    // sort(D.begin(), D.end());
    // sort(MP.begin(), MP.end());
    ll ans = 1e9, mp;
    for (int i = 0; i < N; i++) {
        mp = loop(H, i, N, D, MP);
        if (mp < ans) {
            ans = mp;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1152
N = int(input())
A = list(map(int,input().split()))
minnumber = -1
answer = 0
number = 0

for x in range(len(A)):
    if A[x] < 0:
        A[x] = abs(A[x])
        number += 1
    answer += A[x]
    if minnumber == -1 or minnumber > A[x]:
        minnumber = A[x]

if number % 2 == 0:
    print(answer)
else:
    answer -= minnumber * 2
    print(answer)

Measured memory_bytes: 14412
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define pb(a) push_back(a)
using namespace std;
typedef long long ll;

int func(int x)
{
    int y = pow(x, 0.5);

    if (x == y * y)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

int main()
{
    int N, D;
    cin >> N >> D;
    vector<vector<int>> data(N, vector<int>(D));
    REP(i, N)
    {
        REP(j, D)
        {
            cin >> data.at(i).at(j);
        }
    }

    int ans = 0;
    REP(i, N)
    {
        for (int j = i + 1; j < N; j++)
        {
            int d = 0;
            REP(k, D)
            {
                d += pow(data.at(i).at(k) - data.at(j).at(k), 2);
            }
            ans += func(d);
        }
    }

    cout << ans;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(){
  char a[82], b[82];
  int ans[81];
  int a_len, b_len;
  int a_num, b_num, ans_num, agari;
  int setsize, keta;
  int i, j;

  scanf("%d", &setsize);
  for(i=0; i<setsize; i++){
    scanf("%81s%*", a);
    scanf("%81s%*", b);
    if((a_len=strlen(a))>80 || (b_len=strlen(b))>80){
      printf("overflow\n");
      continue;
    }
    agari=0;
    for(j=0; j<81; j++){
      a_num=0; b_num=0;
      if(a_len>0){
        a_num=atoi(&a[a_len-1]);
        a[a_len-1]='\0';
        a_len--;
      }
      if(b_len>0){
        b_num=atoi(&b[b_len-1]);
        b[b_len-1]='\0';
        b_len--;
      }
      ans_num=a_num+b_num+agari;
      if(ans_num>9){
        agari=1;
        ans_num%=10;
      }
      else agari=0;
      ans[j]=ans_num;
    }
    if(ans[80]>0){
      printf("overflow\n");
      continue;
    }
    for(keta=80; keta>0; keta--){
      if(ans[keta]>0) break;
    }
    for(j=keta; j>0; j--){
      printf("%d", ans[j]);
    }
    printf("%d\n", ans[0]); 
  }

  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);	
		String W = scanner.next().toLowerCase();	//computer
		String temp;
		int count = 0;
		while(!(temp=scanner.next()).equals("END_OF_TEXT")) {	//读取下一字段直到字段为END_OF_TEXT
			if (temp.toLowerCase().equals(W)) {
				count++;
			}
		}
		System.out.println(count);
		scanner.close();
	}
}


Measured memory_bytes: 26088
#include <iostream>
#include <vector>
#include <unordered_set>
#include <set>
#include <cstring>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>

using namespace std;

using ll = long long;
const ll INF = 1e18 + 1;


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

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

    vector<ll> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }

    sort(p.begin(), p.end());

    ll ans = 0;
    for (int i = 0; i < k; ++i) {
        ans += p[i];
    }

    cout << ans << endl;


}

Measured memory_bytes: 3196
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
    int n;
    cin >> n;
    int ferias[n][3], aux[n][3];
    for (int i=0;i<n;i++){
        for (int j=0;j<3;j++){
            int points;
            cin >> points;
            ferias[i][j] = points;
            if(i == 0){
                aux[i][j] = points;
            }
        }
    }
    for(int i=1; i<n; i++){
        for(int j=0;j<3;j++){
            if(j==0){
                aux[i][j] = ferias[i][j] + max(aux[i-1][j+1],aux[i-1][j+2]);
            }
            else if(j == 1){
                aux[i][j] = ferias[i][j] + max(aux[i-1][j-1],aux[i-1][j+1]);
            }
            else if(j == 2){
                aux[i][j] = ferias[i][j] + max(aux[i-1][j-1],aux[i-1][j-2]);
            }
        }
    }
    int soma = 0;
    for(int i=0; i<3;i++){
        if(aux[n-1][i] > soma){
            soma = aux[n-1][i];
        }
    }
    cout << soma << endl;
    return 0;
}

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

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

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    int n; cin>>n;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin>>a[i];
    sort(a.begin(), a.end());

    vector<ll> sum(n+10, 0);
    for(int i=0; i<n; i++){
        sum[i+1]=sum[i]+a[i];
    }

    int id;
    for(int i=n; i>1; i--){
        if(a[i-1]<=2LL*sum[i-1]) id=i;
        else break;
    }
    cout << n-id+2 << endl;
}

Measured memory_bytes: 1408
s = input()
 
ans_flag = False
for i in range(len(s)-1):
    if s[i] == "C":
        if "F" in s[i+1:]:
            ans_flag = True
            break
        else:
            break
 
if ans_flag == True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3188
#include <stdio.h>

int main(void)
{
	int n, a[1001][1001];
	scanf("%d", &n);

	int i, j;
	for (i = 1; i <= n; i++)
	{
		for (j = 0; j < n - 1; j++)
		{
			scanf("%d", &a[i][j]);
		}
	}

	int next[1001] = {0};        // next_idx[i]:選手iが次に戦う選手が書いてあるa[i][k]のインデックスk
	int judge, matches, days, sum_matches;
	judge = matches = days = 0;
	sum_matches = n * (n - 1) / 2;
	while (1)
	{
		int played[1001] = {0};			 // played[i]:選手iがを試合を行なっていたら1
		judge = 0;
		for (i = 1; i <= n - 1; i++)
		{
			j = a[i][next[i]];
			if (played[i] == 0 && played[j] == 0 && a[j][next[j]] == i)
			{
				judge = 1;
				played[i] = played[j] = 1;
				next[i]++; next[j]++;
				matches++;
			}
		}
		if (judge == 0) 
		{
			days = -1;
			break;
		} else {
			days++;
			if (matches == sum_matches) break;
		}
	}
	printf("%d\n", days);
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
 
using namespace std;
 
#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()
 
template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
 
typedef long long LL;

int main()
{
	LL result = 0;
	LL cur = 1;
	LL temp;
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> temp;
		if (temp == cur)
		{
        cur ++;
        continue;
		}
		result += (temp-1)/cur;
		if (cur == 1)
		{
			cur++;
		}

	}
	cout << result;
	return 0;
}


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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
constexpr ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }

int a, b;
void solve() {
    cin >> a >> b;

    if (a > 0 && a < 10 && b>0 && b < 10)
        cout << a * b << endn;
    else
        cout << -1 << endn;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


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

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

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

    int flag = 0;
    for(int i = 0; i < n; i++){
        if(a[i] % 2 == 0){
            if(a[i] % 3 != 0 && a[i] % 5 != 0){
                flag = 1;
                break;
            }
        }
    }

    if(flag == 1){
        cout << "DENIED" << endl;
    }else{
        cout << "APPROVED" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#define INF 1<<20
using namespace std;

int w, h;
int data[22][22];
int memo[22][22];

int solve(int x, int y){

  if(x < 0 || x == w || data[y][x]&1) return 0;
  if(y > h-2) return 1;
  if(memo[y][x]) return memo[y][x];

  int ret = 0;
  if(data[y][x] == 2) ret += solve(x, y+2);
  else{
    if(x && !data[y+1][x-1]) ret += solve(x-1, y+1);
    if(!data[y+1][x+1]) ret += solve(x+1, y+1);
    ret += solve(x, y+1);
  }
  
  return memo[y][x] = ret;
}

int main(){

  while(cin >> w >> h, w+h){

    for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin >> data[i][j];

    int ans = 0;
    for(int i=0;i<w;i++){
      memset(memo, 0, sizeof(memo));
      ans += solve(i, 0);
    }

    cout << ans << endl;
  }

}

Measured memory_bytes: 1168
(* O(n) (n = |s|) *)
let string_to_char_array s = Array.init (String.length s) (fun i -> s.[i])

(* O(n) (n = |cs|) *)
let char_array_to_string cs = String.init (Array.length cs) (fun i -> cs.(i))

(* O(n * log(n)) (n = |s|) *)
let string_sort cmp s =
  let cs = string_to_char_array s in
  Array.sort cmp cs;
  char_array_to_string cs

(* O(n * log(n)) (n = max {|s|, |t|}) *)
let solve s t =
  if string_sort compare s < string_sort (fun x y -> compare x y * -1) t then
    "Yes"
  else
    "No"

let _ =
  let s = read_line () in
  let t = read_line () in
  solve s t |> print_endline

Measured memory_bytes: 384
s = input()
t = input()
minl = len(t)
for i in range(len(s)-len(t)+1):
    tmp = len(t)
    for j in range(0, len(t)):
        if s[i+j] == t[j]:
            tmp -= 1
    minl = min(minl, tmp)
print(minl)

Measured memory_bytes: 8980
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

#define MAX_N 1000010
ll inv[MAX_N+10],fac[MAX_N+10],ifac[MAX_N+10];

void setComb(){
  inv[0]=1;inv[1]=1;fac[1]=1;ifac[1]=1;fac[0]=1;ifac[0]=1;
  for(int i=2;i<MAX_N;i++){
    inv[i]=(-MOD/i)*inv[MOD%i]%MOD;
    fac[i]=fac[i-1]*i%MOD;
    ifac[i]=ifac[i-1]*inv[i]%MOD;

    inv[i]=(inv[i]+MOD)%MOD;
    fac[i]=(fac[i]+MOD)%MOD;
    ifac[i]=(ifac[i]+MOD)%MOD;
  }
  return;
}


ll mod_pow(ll x,ll n){
  x%=MOD;
  ll res=1;
  while(n>0){
    if(n&1) res=res*x%MOD;
    x=x*x%MOD;
    n>>=1;
  }
  return res;
}

void add(ll &a,ll b){
  a=(a+b)%MOD;
}

void mul(ll &a,ll b){
  a%=MOD;b%=MOD;
  a=a*b%MOD;
}

ll comb(ll n,ll k){
  ll res=ifac[k];
  for(ll i=0;i<k;i++){
    mul(res,n-i);
  }
  return res;
}

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

  ll N;
  cin>>N;
  ll A,B;
  cin>>A>>B;

  setComb();

  ll ans=mod_pow(2ll,N);
  add(ans,MOD-1);
  ll nans=comb(N,A);
  add(ans,MOD-nans);
  nans=comb(N,B);
  add(ans,MOD-nans);

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 23680
from string import ascii_lowercase
s = input()
if len(s) != 26:
    nokori = set(ascii_lowercase) - set(s)
    print(s + min(nokori))
else:
    for i in range(2, 27):
        if s[-i] <= s[-i + 1]:
            break
        if i == 26:
            print(-1)
            exit()
    s_ = sorted(s[-i + 1:])
    for j in s_:
        if j > s[-i]:
            break
    print(s[:-i]+j)


Measured memory_bytes: 4084
n, k = [int(x) for x in input().split()]

np = [0] * n

for i in range(k):
    d = int(input())
    for x in input().split():
        np[int(x) - 1] += 1

ans = 0
for i in np:
    if i == 0:
        ans += 1
print(ans)


Measured memory_bytes: 9068
// Contest with Drinks Easy
#include <iostream>
using namespace std;

int n,t[100],m,p,x[100],sum;

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>t[i];
        sum+=t[i];
    }
    cin>>m;
    for(int i=0;i<m;i++){
        cin>>p>>x[i];
        x[i]-=t[p-1];
    }
    for(int i=0;i<m;i++){
        cout<<sum+x[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define lcm( a, b ) ((a)/__gcd(a,b)*(b))
#define MP make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> iP;
typedef pair< LL, LL > LP;

const int INF = INT_MAX;
const int MIN = INT_MIN;
const LL LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const int SIZE = 300005;

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );
            if( i * i != n ) ret.pb( n / i );

        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int n;
    string s;
    cin >> n >> s;
    int cnt = 1;
    for( int i = 1; i < s.size(); ++i ) {
        if( s[i] != s[i - 1] ) ++cnt;

    }
    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 512
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int N=sc.nextInt();
		int[] As=sc.nextIntsN(N);
		double[] Bs=new double[N];
		double total=0.0;
		for(int i=0;i<As.length;i++) {
			Bs[i]=1.0/As[i];
			total+=Bs[i];
		}
		out.println(1.0/total);
		out.flush();
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntsN(int N) {
		int[] ints = new int[N];
		for (int i = 0; i < N; i++) {
			ints[i] = nextInt();
		}
		return ints;
	}
	
	public long[] nextLongsN(int N) {
		long[] longs = new long[N];
		for (int i = 0; i < N; i++) {
			longs[i] = nextLong();
		}
		return longs;
	}
	
	public char[] nextCharsN(int N) {
		char[] chars = new char[N];
		String msg=next();
		for (int i = 0; i < N; i++) {
			chars[i] = msg.charAt(i);
		}
		return chars;
	}

	public char[][] nextCharsHW(int H, int W) {
		char[][] chars = new char[H][W];
		for (int i = 0; i < H; i++) {
			String str = next();
			for (int j = 0; j < W; j++) {
				chars[i][j] = str.charAt(j);
			}
		}
		return chars;
	}

	public int[][] nextIntsNM(int N, int M) {
		int[][] ints = new int[N][M];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < M; j++) {
				ints[i][j] = nextInt();
			}
		}
		return ints;
	}
}


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

const int MOD = 1000000007;

const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    int W, H, N;
    cin >> W >> H >> N;
    set<int> left;
    set<int> right;
    set<int> lower;
    set<int> upper;

    for (int i = 0; i < N; i++) {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1) {
            left.insert(x);
        } else if (a == 2) {
            right.insert(x);
        } else if (a == 3) {
            lower.insert(y);
        } else {
            upper.insert(y);
        }
    }

    int x_min = 0;
    int x_max = W;
    int y_min = 0;
    int y_max = H;
    if (!left.empty()) {
        x_min = *rbegin(left);
    }
    if (!right.empty()) {
        x_max = *begin(right);
    }
    if (!lower.empty()) {
        y_min = *rbegin(lower);
    }
    if (!upper.empty()) {
        y_max = *begin(upper);
    }

    int ans = 0;
  if(x_max-x_min>=0 && y_max-y_min>0){
       ans = (x_max - x_min) * (y_max - y_min);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int N;
string S;
int main() {
	cin >> N >> S;
	vector<int> a(26, 1);
	for (char c : S) {
		++ a[c-'a'];
	}
	long long r = 1;
	for (int i = 0; i < 26; ++ i) {
		(r *= a[i]) %= mod;
	}
	cout << r-1 << endl;
}


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

const int MAX = 510000;
// const int MOD = 1000000007;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

    int a, ne = 0, no = 0;
    rep(i, N) {
        cin >> a;
        if (a%2==0) ne++;
        else no++;
    }

    COMinit();

    ll ans = 0;
    if (P==0) {
        for (int k=0; k<=no; k+=2) ans += COM(no, k);
    } else {
        for (int k=1; k<=no; k+=2) ans += COM(no, k);
    }

    rep(k, ne) ans *= 2;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 12160
import java.util.*;

public class Main{

    public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      int N = scan.nextInt();
      int K = scan.nextInt();
      int X = scan.nextInt();
      int Y = scan.nextInt();
      
      int Xvalue;
      int Yvalue;
      
      
      if (N > K){
        Xvalue = K * X;
        Yvalue = (N-K)*Y;
        System.out.print(Xvalue+Yvalue);
      }else{
        System.out.print(N*X);
      
      }
     
     
    
    }

}

Measured memory_bytes: 35756
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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


int main() {

    ll a, b, c;
    cin >> a >> b >> c;

    ll d, e;
    if (a > c){
        d = a - c;
        e = b;
    }else if(a + b > c){
        d = 0;
        e = a + b - c;
    }else{
        d = 0;
        e = 0;
    }
    cout << d << " " << e << endl;

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
  int card[5];

  while(scanf("%d,%d,%d,%d,%d", &card[0], &card[1], &card[2], &card[3], &card[4]) != EOF){
    sort(card, card+5);
    int f = 0;
    bool st = 0;

    for(int i = 0 ; i < 4 ; i++){
      for(int j = i+1 ; j < 5 ; j++){
	if(card[i] == card[j]) f++;
      }
    }
    
    if(card[0]+1 == card[1] && card[0]+2 == card[2] &&
       card[0]+3 == card[3] && card[0]+4 == card[4] ||
       card[0] == 1 && card[1] == 10 && card[2] == 11 &&
       card[3] == 12 && card[4] == 13){
      st = 1;
    }
    
    if(f == 6) cout << "four card" << endl;
    else if(f == 4) cout << "full house" << endl;
    else if(f == 3 && st == 0) cout << "three card" << endl;
    else if(f == 2 && st == 0) cout << "two pair" << endl;
    else if(f == 1 && st == 0) cout << "one pair" << endl;
    else if(f <= 3 && st == 1) cout << "straight" << endl;
    else cout << "null" << endl;

  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define pi 3.14159265358979323846264338327950L
using namespace std;

int main() {
  string S;
  int64_t K, ans;
  cin >> S >> K;
  for (int64_t i=0; i<K; i++) {
    if (S[i]=='1') {
      ans=1;
    }
    else if (S[i]=='2') {
      ans=2;
      break;
    }
    else if (S[i]=='3') {
      ans=3;
      break;
    }
    else if (S[i]=='4') {
      ans=4;
      break;
    }
    else if (S[i]=='5') {
      ans=5;
      break;
    }
    else if (S[i]=='6') {
      ans=6;
      break;
    }
    else if (S[i]=='7') {
      ans=7;
      break;
    }
    else if (S[i]=='8') {
      ans=8;
      break;
    }
    else if (S[i]=='9') {
      ans=9;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch ColoringColorfully | diff ColoringColorfully.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address ColoringColorfully.cpp && ./a.out

/*
 
 4/17/2019
 
 15:40-
 
 */

//const int MAX_N=1e6+1;
string S;
int N;

int f(int s) {
  int res=0;
  REP(i,N) {
    int x=S[i]-'0';
    res+=x!=s;
    s^=1;
  }
  return res;
}
void solve() {
  N=SZ(S);
  int res=min(f(0),f(1));
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>S;
  solve();
  
  return 0;
}


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

int main() {
  int N,i,k=0,l=0;
  cin >> N;
  vector<int> a(N,0);
  for(i=0;i<N;++i){
    cin >> a.at(i);
    if(k!=1&&a.at(k)){
      k=a.at(k)-1;
      ++l;
    }
  }
  i=k;
  while(k!=1&&l<N){
    ++l;
    k=a.at(k)-1;
    if(k==1)
      break;
  }
    
  if(l!=N)
    cout << l << endl;
  else
    cout << -1 << endl;
    
}


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

using ll = long long;

const int mod = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++)
        cin >> a[i];
    int k = 0;
    for (int i = 0; i < N; i++) {
        if (a[i] == k + 1)
            k++;
    }
    if (k == 0)
        cout << -1 << endl;
    else
        cout << N - k << endl;
}

Measured memory_bytes: 1024