akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
template<typename T = int, T mod = 1'000'000'007, typename U = long long>
struct umod{
    T val;
    umod(): val(0){}
    umod(U x){ x %= mod; if(x < 0) x += mod; val = x;}
    umod& operator += (umod oth){ val += oth.val; if(val >= mod) val -= mod; return *this; }
    umod& operator -= (umod oth){ val -= oth.val; if(val < 0) val += mod; return *this; }
    umod& operator *= (umod oth){ val = ((U)val) * oth.val % mod; return *this; }
    umod& operator /= (umod oth){ return *this *= oth.inverse(); }
    umod& operator ^= (U oth){ return *this = pwr(*this, oth); }
    umod operator + (umod oth) const { return umod(*this) += oth; }
    umod operator - (umod oth) const { return umod(*this) -= oth; }
    umod operator * (umod oth) const { return umod(*this) *= oth; }
    umod operator / (umod oth) const { return umod(*this) /= oth; }
    umod operator ^ (long long oth) const { return umod(*this) ^= oth; }
    bool operator < (umod oth) const { return val < oth.val; }
    bool operator > (umod oth) const { return val > oth.val; }
    bool operator <= (umod oth) const { return val <= oth.val; }
    bool operator >= (umod oth) const { return val >= oth.val; }
    bool operator == (umod oth) const { return val == oth.val; }
    bool operator != (umod oth) const { return val != oth.val; }
    umod pwr(umod a, U b) const { umod r = 1; for(; b; a *= a, b >>= 1) if(b&1) r *= a; return r; }
    umod inverse() const {
        U a = val, b = mod, u = 1, v = 0;
        while(b){
            U t = a/b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        if(u < 0)
            u += mod;
        return u;
    }
};
using U = umod<int, 998244353>;
template<typename U>
struct NCR {
    vector<U> fact, ifact;
    NCR(int size){
        fact.resize(size + 1); ifact.resize(size + 1);
        fact[0] = 1;
        for(int i = 1; i <= size; i++) fact[i] = fact[i - 1] * i;
        ifact[size] = fact[size].inverse();
        for(int i = size - 1; i >= 0; i--) ifact[i] = ifact[i + 1] * (i + 1);
    }
    U ncr(int n, int r){
        if(n < r) return 0;
        return fact[n] * ifact[r] * ifact[n - r];
    }
};
using N = NCR<U>;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	N kt(20000);
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	auto f = create<U>(c + 2, d + 2);
	f[a][b] = 1;
	for(int i = a; i <= c; i++){
		for(int j = b; j <= d; j++){
			if(i == a && j == b);
			else {
				f[i][j] = f[i - 1][j] * j + f[i][j - 1] * i;
				f[i][j] -= f[i - 1][j - 1] * (i - 1) * (j - 1);
			}
		}
	}
	cout << f[c][d].val << '\n';
	return 0;
}


Measured memory_bytes: 38468
#include <iostream>
#include <vector>
using namespace std;
int N;

long long dfs(long long x, int bit, long long t){
  if(x > N) return 0;
  long long ret = (bit==7);
  ret += dfs(t*3+x, (bit|1), t*10);
  ret += dfs(t*5+x, (bit|2), t*10);
  ret += dfs(t*7+x, (bit|4), t*10);
  return ret;
}

int main(){
  cin >> N;
  cout << (dfs(3,1,10)+dfs(5,2,10)+dfs(7,4,10)) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <sstream>
#include <fstream>
//#include <tuple>
#include <set>
#include <string.h>

#define X first
#define Y second
#define MP make_pair
//#define MT make_tuple
#define FOR(i, n) for(int (i) = 0; (i) < (n); (i)++)
typedef long long ll;
using namespace std;
const int MAX = 101;

template<class T, class U>
void convert(T &t, U &u){
	stringstream ss;
	ss << t;
	ss >> u;
}

map<int, int> dp;
map<int, vector<pair<int, int> > > cost;

int main(){
	ll L, n;
	cin >> L >> n;

	cost[0].push_back(MP(0, 0));
	FOR(i, n){
		int p, d, t;
		cin >> p >> d >> t;
		cost[p].push_back(MP(p+d, t));
		cost[p+d].push_back(MP(p+d, 0));
	}

	auto prev = cost.begin();
	for(auto i = cost.begin(); i != cost.end(); i++){
		if(!(i==cost.begin())){
			cost[prev->first].push_back(MP(i->first, i->first-prev->first));
			prev = i;
		}
	}
	cost[prev->first].push_back(MP(L, L-prev->first));
	
	for(auto i = cost.begin(); i != cost.end(); i++){
		if(i == cost.begin()){
			dp[i->first] = 0;
		}
		FOR(j, i->second.size()){
			if(dp.count(i->second[j].first)){
				dp[i->second[j].first] = min(dp[i->second[j].first], dp[i->first]+i->second[j].second);
			}else{
				dp[i->second[j].first] = dp[i->first]+i->second[j].second;
			}
		}
	}

	cout << dp[L] << endl;
	return 0;
}


Measured memory_bytes: 1528
program ABC144B
    implicit none
    integer::N,i
    integer::result=0

    read*,N

    do i=1,9
        if(mod(N,i)==0 .and. N/i<=9) then
            result=1
        endif
    end do

    if(result==0) then
        print'(A)',"No"
    else
        print'(A)',"Yes"
    end if
end program ABC144B

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        double n = Double.parseDouble(br.readLine());
        n = n* ((double)(22)/(double)(7))*2;
        System.out.println(n);
    }
}


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

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

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

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

  ll C = A+B;

  cout << (N/C) * A + min(A, N - C * (N/C)) << endl;


  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n,a,b,c,hairetu[100][100];
  int i,j;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      hairetu[i][j]=0;
    }
  }

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

  
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j!=0) printf(" ");
      printf("%d",hairetu[i][j]);
    }
    
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 636
#include<stdio.h>

const int N=305;
const int M=305;

int main(void)
{
	int n ,m;
	while(scanf(" %d %d ", &n ,&m))
	{    
	     if(n == 0 && m == 0 )
	     {
	     	break;
		 }
	  
		for(int i = 0 ; i < n ; i++ )
		{
			for(int b = 0; b < m ;b++ )
			{		
			   printf("#");	
			}
			
			printf("\n");
		}
		printf("\n");	
	}
	return 0;
	
}


Measured memory_bytes: 2600
n, m, k = map(int, input().split())

mod = 10**9+7
N = 2*10**5+50
fac = [1]*(N+1)
finv = [1]*(N+1)
for i in range(N):
    fac[i+1] = fac[i] * (i+1) % mod
finv[-1] = pow(fac[-1], mod-2, mod)
for i in reversed(range(N)):
    finv[i] = finv[i+1] * (i+1) % mod

def cmb1(n, r, mod):
    if r <0 or r > n:
        return 0
    r = min(r, n-r)
    return fac[n] * finv[r] * finv[n-r] % mod

ans = 0
for i in range(n*m):
    x, y = divmod(i, m)
    # x
    ans += x*m*cmb1(n*m-2, k-2, mod)*x
    ans -= (n-1-x)*m*cmb1(n*m-2, k-2, mod)*x
    # y
    ans += y*n*cmb1(n*m-2, k-2, mod)*y
    ans -= (m-1-y)*n*cmb1(n*m-2, k-2, mod)*y

ans %= mod
print(ans)


Measured memory_bytes: 24468
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repm(i,m,n) for (int i = (m); i < (n); i++)
#define rrep(i,n) for (int i = (n); i >= 0; i--)
using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  
  for (int x = 111; x <= 999; x += 111) {
    if (x >= N) {
      cout << x<< endl;
      return 0;
    }
  }
   
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args){
		int[] abo = {0,0,0,0};
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String tmp = null;
		int cup = 0;
		int mun = 0;
		int ter = 0;
		String[] rrr;
		int st = 0,sr = 0;
		int mon = 0;
		int syo=0,hisi=0;
		
		
		
		while(true){
			
			try {
				tmp = br.readLine();
			} catch (IOException e) {
				// TODO 自動生成された catch ブロック
				e.printStackTrace();
			}
			
			if(tmp == null){
				break;
			}
			
			if(tmp.equals("")){
				break;
			}
			
			rrr = tmp.split(",");
			
			if(rrr[1].equals("A")){
				abo[0]++;
			}else if(rrr[1].equals("B")){
				abo[1]++;
			}else if(rrr[1].equals("AB")){
				abo[2]++;
			}else if(rrr[1].equals("O")){
				abo[3]++;
			}
		}
		System.out.println(abo[0]);
		System.out.println(abo[1]);
		System.out.println(abo[2]);
		System.out.println(abo[3]);
	}

}

Measured memory_bytes: 16912
n,m=map(int,input().split())
z={}
f=1
maxs=0
ii=1
ss=1
if m==0 and n==1:
    print(0)
    exit()
elif m==0 and n==2:
    print(10)
    exit()
elif m==0 and n==3:
    print(100)
    exit()
for i in range(m):
    s,c=map(int,input().split())
    if n!=1 and s==1 and c==0:
        print(-1)
        exit()
    if ii==1:
        ii=c
    elif ii!=1:
        ii=min(c,ii)
    if s not in z:
        z[s]=ii
    elif z[s]==c:
        continue
    else:
        f=0
        continue
sorted(z.items(),key=lambda x:x[1])
if not f:
    print(-1)
    exit()
for i in range(1,n+1):
    if i in z:
        print(z[i],end="")
    elif i!=1:
        print(0,end="")
    else:
        print(1,end="")


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

double P, E, T;

double dfs(int K, double L, double R){
    
    double H = (L + R) / 2.0;
    if(K == 0){
        if(abs(T - H) < E){
            return 1.0;
        }else{
            return 0.0;
        }
    }

    if(R < T - E || T + E < L){
        return 0.0;
    }
    
    if(T - E <= L && R <= T + E){
        return 1.0;
    }

    if(H <= T){
        return P * dfs(K - 1, L, H) + (1.0 - P) * dfs(K - 1, H, R);
    }else{
        return P * dfs(K - 1, H, R) + (1.0 - P) * dfs(K - 1, L, H);
    }
}

int main(){

    int K; 
    double R, L; 
    cin >> K >> R >> L;
    cin >> P;
    cin >> E;
    cin >> T;


    printf("%.10f\n", dfs(K, R, L));
    return 0;
}


Measured memory_bytes: 3292
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;
int n,a[1000000+100],sol;
string s;
int main()
{
    cin>>s;
    if (s[0]==s[2])cout<<"Yes"<<endl;else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 764
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
for i in range(K,N):
    if T[i]==T[i-K] and T[i-K]!="x":
      T=(T[:i]+"x"+T[i+1:])
    else:
      continue
     
R_win=T.count("s")
S_win=T.count("p")
P_win=T.count("r")
point=R_win*R+S_win*S+P_win*P
print(point)

Measured memory_bytes: 3452
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
int main() {
  int n, m, X, Y, z;

  cin >> n >> m >> X >> Y;
  rep(i,n)
  {
    cin >> z;
    X = max(X, z);
  }
  rep(i,m)
  {
    cin >> z;
    Y = min(Y, z);
  }
  if (X >= Y) {
    cout << "War";
  } else {
    cout << "No War";
  }
  return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	N := nextInt()
	K := nextInt() - 1

	A := make([]int, N)

	for i := 0; i < N; i++ {
		A[i] = nextInt()

		if i > K {
			if A[i-K-1] < A[i] {
				fmt.Println("Yes")
			} else {
				fmt.Println("No")
			}
		}
	}
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}

func debug(args ...interface{}) {
	fmt.Fprintln(os.Stderr, args)
}


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

int main() {
  ll k, a, b; cin >> a >> b >> k;
  bool aoki = k > a;
  if (aoki) {
    ll t = a + b - k;
    cout << 0 << " " << (0 < t ? t : 0) << endl;
  }
  else
    cout << a - k << " " << b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define mod 998244353LL
#define eps 1e-13
// #define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pair < pii, int > a, pair < pii, int > b)//true for a before b
{
	if(a.F.F/300 < b.F.F/300)
		return 1;
	if(a.F.F/300 > b.F.F/300)
		return 0;
	if(a.F.S < b.F.S)
		return 1;
	if(a.F.S > b.F.S)
		return 0;
	if(a.F <= b.F)
		return 1;
	return 0;
}

const int N = (2e5) + 9;
const int M = (N<<2) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 2*550;
const int SQRT = BUCK+9;

ll a[N];

void solve()
{
	int n, i;
	ll x, ans = 0;
	cin >> n >> x;
	fo(i,1,n+1)
		cin >> a[i];
	sort(a+1,a+n+1);
	fo(i,1,n+1)
	{
		if(x >= a[i])
		{
			x -= a[i];
			ans++;
		}
		else
			x = 0;
	}
	if(x > 0)
		ans--;
	cout << ans << '\n';
	return;
}

int main()
{
	sws;
	clock_t clk;
	clk = clock();
	// io_file;
	// srand (time(NULL));

	//Code here
	int t = 1, cs;
	cout << fixed << setprecision(9);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case #" << cs << ": ";
		solve();
	}
	// Code ends here

	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

int main(){
  string s; cin >> s;
  int n = s.size();
  reverse(all(s));

  vector<string> list = {"maerd", "remaerd", "esare", "resare"};
  string t;
  rep(i, n){
    t += s[i];
    for(auto x : list){
      if(t == x) t = "";
    }
  }

  std::cout << (t == "" ? "YES" : "NO") << '\n';
}


Measured memory_bytes: 640
using System;

namespace tes
{
    class Program
    {
        static void Main(string[] args)
        {
            var line1 = Console.ReadLine().Split();
            int W = int.Parse(line1[0]);
            int H = int.Parse(line1[1]);
            int x = int.Parse(line1[2]);
            int y = int.Parse(line1[3]);
            int r = int.Parse(line1[4]);

            if ((W <= x) || (H <= y))
            {
                Console.WriteLine("No");
            }
            else if ((W >= x + r) && (H >= y + r) && (0 < y + r) && (0 < x + r))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }


        }
    }
}

Measured memory_bytes: 8948
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1000000007;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%MOD;x=x*x%MOD;n>>=1;}return res;}
ll modinverse(ll a){return power(a, MOD-2);}
void solve()
{
    ll x, k, d;
    cin>>x>>k>>d;
    if(x%d==0)
    {
    	ll moves=abs(x/d);
    	if(moves>k)
    	{
    		cout<<abs(x)-k*d<<endl;
    		return;
    	}
    	if((k-moves)%2==0)
    	{
    		cout<<0<<endl;
    		return;
    	}
    	else
    	{
    		cout<<d<<endl;
    		return;
    	}
    }
    else
    {
    	x=abs(x);
    	ll moves=(x)/d;
    	if(moves>=k)
    	{
    		cout<<abs(x)-k*d<<endl;
    		return;
    	}
    	if((k-moves)%2==0)
    	{
    		cout<<x-moves*(d)<<endl;
    		return;
    	}
    	else
    	{
    		cout<<(d-(x-moves*(d)))<<endl;
    		return;
    	}
    }
}
int main()
{
	#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll test=1;
    //cin>>test;
    while(test--)
    {
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

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

using namespace std;

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

    int n, cnt = 0;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        int a;
        cin >> a;
        if (i % 2 == 1 && a % 2 == 1)
            cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3476
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template <class T, class U>ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >>p.second ;
	return is;
}
template <class T>istream& operator>>(istream& is,  vector<T>& v) {
	rep(i, v.size()) {
		is >> v[i];
	}
	return is;
}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n,q;
	string s;
//	int ans=0;
	int k;
	cin >>n>>s>>q;
	V data(2);//d,dm
	Vi sum(s.size()+1, 0);
	rep(i, s.size()) { 
		sum[i] += (s[i] == 'M'); 
	if(i!=0){
		sum[i] += sum[i - 1];
	}
	}
//	clog << sum << endl;
	ll ans = 0LL;
	rep(i, q) { 
		cin >> k;
		ans = 0LL;
		data[0] = 0LL;
		data[1] = 0LL;
		rep(i,s.size()){
			if (i >= k) {
				if (s[i - k] == 'D') {
					data[0]--;
					data[1] -= sum[i-1] - sum[i - k];
				
				}
			//	clog << "(" << s[i - k] << ") ";
			}
			switch (s[i])
			{
			case 'D':
				data[0]++;
				break;
			
			case 'M':
				data[1] += data[0];
				break;
			case 'C':
				ans += data[1];
				break;
			}
			
		//	clog << data << " "<<s[i]<<endl;
		}
		cout << ans << endl;
	}

}

Measured memory_bytes: 8096
const print2elm = (a,b) =>  fns => console.log(fns.map(f => f(a,b)).join(" "));
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const [a,b] = input.split(" ").map(Number);
const calc = print2elm(a,b);

calc([(a,b)=>a*b,(a,b)=>(a+b)*2]);



Measured memory_bytes: 15140
import sys
input = sys.stdin.readline


def load_num_check(max_load, k, n, w):
    item_num = 0
    for _ in range(k):
        current_load = 0
        while True:
            weight = w[item_num]
            next_load = current_load + weight
            if (next_load > max_load):
                break
            item_num += 1
            if(item_num == n):
                return n
            else:
                current_load = next_load
    return item_num


def main():
    n, k =  map(int, input().split())
    w = [int(input()) for _ in range(n)]
    min_load = 0
    max_load = 1e4 * 1e5
    while(max_load - min_load > 1):
        mid_load = (max_load + min_load) // 2
        loadable_item_num = load_num_check(mid_load, k, n, w)
        if (loadable_item_num >= n):
            max_load = mid_load
        else:
            min_load = mid_load
        # print(max_load, mid_load, min_load)
    print(int(max_load))
        

if __name__ == "__main__":
    main()


Measured memory_bytes: 9580
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);++i)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int gcd(int a,int b) { return b ? gcd(b,a%b) : a;}
int lcm(int a,int b) { return a/gcd(a,b)*b;}
void printb(unsigned int v) {
  unsigned int mask = (int)1 << (sizeof(v) * CHAR_BIT - 1);
  do putchar(mask & v ? '1' : '0');
  while (mask >>= 1);
}
void putb(unsigned int v) {putchar('0'), putchar('b'), printb(v), putchar('\n');}
#define ALL(W) (W).begin(),(W).end()

signed main(){
  int N;
  cin >> N;
  int B[N-1]={};
  rep(i,N-1) cin >> B[i];
  int ans=0;
  ans+=(B[0]+B[N-2]);
  for(int i=0;i<N-2;i++){
    ans+=min(B[i],B[i+1]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
//#define INF 1100000000000000000LL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=200050;
//int arr[SIZE]={};
//ここまでテンプレ
ll func(ll a,ll b){
	if(b)
		return 2*(a/b)*b+func(b,a%b);
	else
		return -a;
}
int main(){
	ll N,X;
	cin>>N>>X;
	cout<<N+func(min(X,N-X),max(X,N-X))<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;

using namespace std;

bool R[100005];
int B[100005];
int main()
{
	int N, M;
	cin >> N >> M;
	REP(i, N)
	{
		B[i] = 1;
	}
	R[0] = true;

	REP(i, M)
	{
		int x, y;
		cin >> x >> y;
		x--; y--;
		if (R[x])
		{
			R[y] = true;
		}
		B[x]--;
		B[y]++;
		if (B[x] == 0)
		{
			R[x] = false;
		}
	}

	int ans = 0;
	REP(i, N)
	{
		if (R[i])ans++;
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 768
// https://atcoder.jp/contests/abc076/tasks/abc076_a
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k, c = 1;
    cin >> n >> k;
    REP(i, n) {
        if (c < k) {
            c *= 2;
        } else {
            c += k;
        }
    }
    cout << c << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;

const ll MOD = (ll)(1e9 + 7);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(50) << setiosflags(ios::fixed);

  ll n, weight;
  cin >> n >> weight;
  ll w[110], v[110];
  rep(i, n) cin >> w[i] >> v[i];
  ll dp[110][100010]; //i個目まで見たときの，価値がjの場合の重さのmin
  rep(i, 110) rep(j, 100010) dp[i][j] = LINF;
  dp[0][0] = 0;
  rep(i, n)
  {
    rep(vi, 100010)
    {
      dp[i + 1][vi] = min(dp[i + 1][vi], dp[i][vi]);
      if (vi + v[i] < 100010)
        dp[i + 1][vi + v[i]] = min(dp[i + 1][vi + v[i]], dp[i][vi] + w[i]);
    }
  }
  ll ans = 0;
  rep(vi, 100010)
  {
    if (dp[n][vi] <= weight)
      ans = max(ans, vi);
  }
  cout << ans << endl;
  return 0;
}


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

const int MAX = 50;
int main() {
	int N, M, a, b;
	cin >> N >> M;
	int road[MAX]; // road[i]はi番目の都市に繋がっている道路の数
	for (int i = 0;i < N;i ++) road[i] = 0; // 初期化
	for (int i = 0;i < M;i ++) {
		cin >> a >> b;
		road[a - 1] ++;
		road[b - 1] ++;
	}
	for (int i = 0;i < N - 1;i ++) {
		cout << road[i] << endl;
	}
	cout << road[N - 1];
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

都市aと都市bの間に道路を作れば、都市aも都市bも他の都市に繋がる道路が1個増える
これを全道路に対して行っていけばおｋ
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define rep1(i, n) for (int i = 1; i < int(n); ++i)
#define repx(i, x, n) for (int i = int(x); i < int(n); ++i)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define ALL(n) begin(n), end(n)
#define IN(a, x, b) ((a) <= (x) && (x) < (b))
#define OUT(a, x, b) ((x) < (a) || (x) < (b))
typedef long long ll;
typedef long double ld;
const ll INF = 1e18;
const ll MOD = 1000000007;

int main()
{
    ll X;
    cin >> X;
    ll ans = 1;
    while (1)
    {
        if ((ans * (ans + 1)) / 2 >= X)
        {
            cout << ans << endl;
            break;
        }
        ans++;
    }

    return 0;
}


Measured memory_bytes: 3600
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

ll dp[1 << 20];

vector<int> V[51];
vector<pair<int, int>> E[51];
void dfs(int p, vector<int> v, int mae) {
	V[p] = v;
	for (auto pr : E[p]) {
		int to = pr.first;
		if (mae != to) {
			v.pb(pr.second);
			dfs(to, v, p);
			v.pop_back();
		}
	}
}

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


	int N;
	cin >> N;
	rep(i, N - 1) {
		int a, b;
		cin >> a >> b;
		E[a].pb(mp(b, i));
		E[b].pb(mp(a, i));
	}

	vector<int> kari;
	dfs(1, kari, 0);

	int M;
	cin >> M;
	int list[51] = {};
	rep(i, M) {
		int u, v;
		cin >> u >> v;

		for (int j : V[u]) list[j] ^= 1 << i;
		for (int j : V[v]) list[j] ^= 1 << i;
	}

	dp[0] = 1;
	rep(i, N - 1) {
		for (int j = (1 << M) - 1; j >= 0; j--) {
			dp[j | list[i]] += dp[j];
		}
	}

	co(dp[(1 << M) - 1]);


	Would you please return 0;
}

Measured memory_bytes: 8448
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){

	const double PI = 2*acos(0.0);
	double a,b,c,d;
	while(cin>>a>>b>>c>>d&&!(a==-1&&b==-1&&c==-1&&d==-1)){
		pair<double,double> angle[2];
		vector<pair<double,double> > v;
		v.push_back(make_pair(a,b));
		v.push_back(make_pair(c,d));
		for(int i = 0; i < 2; i++){
			angle[i].first=(v[i].first/180)*PI;
			angle[i].second=(v[i].second/180)*PI;
		}
		const double r=6378.1;
		vector<double> points[2];
		for(int i = 0; i < 2; i++){
			points[i].push_back(r*cos(angle[i].first)*cos(angle[i].second));
			points[i].push_back(r*cos(angle[i].first)*sin(angle[i].second));
			points[i].push_back(r*sin(angle[i].first));
		}
		double dist = sqrt((points[0][0]-points[1][0])*(points[0][0]-points[1][0])
			+(points[0][1]-points[1][1])*(points[0][1]-points[1][1])
			+(points[0][2]-points[1][2])*(points[0][2]-points[1][2]));
		double diffAngle=(r*r+r*r-dist*dist)/(2*r*r);


		double anp = acos(diffAngle);
		double comp=PI*r*(anp/PI);
		cout<<(int)(comp+0.5)<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

int main()
{
	int n,m,p[1000];
	while(cin>>n>>m,n){
		rep(i,n)cin>>p[i];
		sort(p,p+n,greater<int>());
		
		int ans=accumulate(p,p+n,0);
		for(int i=m-1;i<n;i+=m)ans-=p[i];
		cout<<ans<<endl;
	}
	
	return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int A, B, M;
  cin >> A >> B >> M;

  vector<int> a(A);
  vector<int> b(B);
  map<pair<int, int>,int> m;

  int mina = 1e5;
  int minb = 1e5;

  for(int &i : a){
    cin >> i;
    if(i < mina){
      mina = i;
    }
  }

  for(int &i : b){
    cin >> i;
    if(i < minb){
      minb = i;
    }
  }

  int x, y, c;
  for(int i=0; i < M; i++){
    cin >> x >> y >> c;
    if(m.find(make_pair(x - 1, y - 1)) == m.end() || m[make_pair(x - 1, y - 1)] < c)
    m[make_pair(x - 1, y - 1)] = c;
  }

  int min = mina + minb;

  for(auto itr = m.begin(); itr != m.end(); ++itr) {
    if(a[itr->first.first] + b[itr->first.second] - itr->second < min){
      min = a[itr->first.first] + b[itr->first.second] - itr->second;
    }
  }
  cout << min << endl;
}

Measured memory_bytes: 7296
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define int long long
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9+7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
unsigned day;
if(dow < dow1) dow += 7;
day = dow - dow1;
day += 7 * n - 6;
return day;
}
unsigned DayToWeekNumber(unsigned day)
{
  return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
  return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main(){
  int N; cin>>N;
  vector<string>A(N);
  vector<int>B(N);
  vector<int>ans(N);
  rep(i,N){
    cin>>A[i]>>B[i];
    if(i==0)ans[i]=B[i];
    else ans[i]=ans[i-1]+B[i];
  }
  string C; cin>>C;
  rep(i,N)if(A[i]==C)cout<<ans[N-1]-ans[i]<<endl;
}

Measured memory_bytes: 3616
N,M=map(int,input().split())
L=[0 for i in range(N+1)]
for i in range(M):
    a,b=map(int,input().split())
    L[a]+=1
    L[b]+=1

for i in range(1,len(L)):
    if L[i]%2==1:
        print("NO")
        exit()
print("YES")

Measured memory_bytes: 9992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;//10^12
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
//const long double EPS=1E-8;
////////////////////////////////////////


int main(){
    //ios::sync_with_stdio(false);cin.tie(0);
    
    int n;cin>>n;
    int s[n][3];rep(i,0,n-1)rep(j,0,2)cin>>s[i][j];
    rep(i,0,n-1){
        if(s[i][1]>=2*s[i][0])s[i][1]=2*s[i][0]-1;
    }
    int N=400;
    ll dp[N];fill(dp,dp+N,0);
    rep(i,0,n-1){
        rep(j,0,N-1){
            rep(k,s[i][0],s[i][1])
            if(j-k>=0)Max(&dp[j],dp[j-k]+s[i][2]);
        }
    }
    //rep(i,0,10)cout<<dp[i]<<" ";
    int m;cin>>m;
    vector<ll>ans;
    rep(i,0,m-1){
        int k;cin>>k;
        if(!dp[k]){cout<<-1<<endl;return 0;}
        ans.pb(dp[k]);
    }
    for(auto x:ans)cout<<x<<endl;
    
    return 0;
}


Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct UnionFind{
  Int num;
  vector<Int> r,p;
  UnionFind(){}
  UnionFind(Int n):num(n),r(n,1),p(n,0){iota(p.begin(),p.end(),0);}
  Int find(Int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(Int x,Int y){
    return find(x)==find(y);
  }
  void unite(Int x,Int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
    num--;
  }
  Int size(Int x){
    return r[find(x)];
  }
  Int count() const{
    return num;
  }
};

//INSERT ABOVE HERE
signed main(){
  Int n,m;
  while(cin>>n>>m,n){
    vector<Int> hs(n);
    for(Int i=0;i<n;i++) cin>>hs[i];
    struct edge{
      Int a,b,c,t;
      edge(Int a,Int b,Int c,Int t):
        a(a),b(b),c(c),t(t){}
      bool operator<(const edge &e)const{
        if(t!=e.t) return t>e.t;
        return c<e.c;
      }
    };

    vector<edge> es;
    for(Int i=0;i<m;i++){
      Int a,b,c;
      cin>>a>>b>>c;
      a--;b--;
      Int t=min(hs[a],hs[b]);
      es.emplace_back(a,b,c,t);
    }

    for(Int i=0;i<n;i++) es.emplace_back(i,i,0,hs[i]);
    es.emplace_back(0,0,0,0);

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

    using P = pair<Int, Int>;
    vector<P> vp;
    for(Int i=0;i<n;i++) vp.emplace_back(hs[i],i);
    sort(vp.rbegin(),vp.rend());

    Int time=1e9,cnt=0,num=0;
    UnionFind uf(n);

    Int pr=-1;
    for(edge &e:es){
      if(pr!=e.t&&num-cnt>1) time=e.t;
      pr=e.t;

      while(num<n&&e.t<=vp[num].first) num++;

      if(!uf.same(e.a,e.b)) cnt++;
      uf.unite(e.a,e.b);
    }
    //cout<<"time:"<<time<<endl;

    for(edge &e:es)
      chmin(e.t,time);

    sort(es.begin(),es.end());
    Int sum=0;
    UnionFind uf2(n);
    for(edge &e:es){
      //cout<<e.a<<" "<<e.b<<":"<<e.t<<endl;
      //if(e.t<time) continue;
      if(uf2.same(e.a,e.b)) continue;
      uf2.unite(e.a,e.b);
      sum+=e.c;
    }

    if(uf.count()!=1) sum=0;
    cout<<sum<<endl;
  }
  return 0;
}



Measured memory_bytes: 4332
s = input()
ans = 0
for i in range(len(s) - 1):
    if s[i] not in {'A', 'C', 'G', 'T'}:
        continue
    length = 1
    for j in range(i + 1, len(s)):
        if s[j] not in {'A', 'C', 'G', 'T'}:
            break
        length += 1
    ans = max(ans, length)
if len(s) == 1:
    ans = 0 if s not in {'A', 'C', 'G', 'T'} else 1
print(ans)

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

char s[200010];

int main() {
    scanf("%s", s + 1);
    int n = strlen(s + 1);
    int c0 = 0, c1 = 0;
    for (int i = 1; i <= n; ++i)
        c0 += s[i] == '0', c1 += s[i] == '1';
    ll ans = 0;
    for (int i = 1; i < c1; ++i)
        ans += (i + 1) / 2;
    int cur = 0;
    for (int i = 1; i <= n; ++i) {
        if (s[i] == '0') {
            ++cur;
            continue;
        }
        if (s[i] == s[i + 1]) {
            ++i;
            ans += c0 + 1;
            continue;
        }
        int ruc = c0 - cur;
        if (i & 1) ans += 1 + ruc + cur / 2;
        else ans += ruc + (cur - 1) / 2 + 1;
    }
    cout << ans << '\n';
    return 0;
}

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

int main(){
    int N;
    long long a_list[100010];
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> a_list[i];
    }
    long long ans1 = 0;
    long long sum1 = 0;
    //偶数を+にする
    for(int i=0; i<N; i++){
        sum1 += a_list[i];
        if(i%2 == 0 && sum1 <= 0){
            ans1 += 1-sum1;
            sum1 = 1;
        }else if(i%2 == 1 && sum1 >= 0){
            ans1 += sum1+1;
            sum1 = -1;
        }
    }
    long long ans2 = 0;
    long long sum2 = 0;
    //奇数を+にする
    for(int i=0; i<N; i++){
        sum2 += a_list[i];
        if(i%2 == 1 && sum2 <= 0){
            ans2 += 1-sum2;
            sum2 = 1;
        }else if(i%2 == 0 && sum2 >= 0){
            ans2 += sum2+1;
            sum2 = -1;
        }
    }
    cout << min(ans1, ans2);
    return EXIT_SUCCESS;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std;
const int N = 101;


int main(){
    int n, A[N], total = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        int t;
        cin >> t;
        A[i] = t;
        total += t;
    }
    sort(A, A + n);
    if(total % 10 != 0){
        cout << total << endl;
        return 0;
    }
    for(int i = 0; i < n; i++){
        if(A[i] % 10 != 0){
            printf("%d\n", total - A[i]);
            return 0;
        }
    }
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;

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

int a[3], b[3];

int pass[4][4];

int main()
{
    string ans = "YES";

    FOR(i, 0, 3)
    {
        cin >> a[i] >> b[i];
        pass[a[i] - 1][b[i] - 1]++;
        pass[b[i] - 1][a[i] - 1]++;
    }

    FOR(i, 0, 4)
    {
        int tmp = 0;
        FOR(j, 0, 4)
        {
            tmp += pass[i][j];
        }
        if (tmp >= 3)
        {
            ans = "NO";
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
const int N = 1300;
int main()
{
	char str[N];
	while(fgets(str, 1300, stdin))
	{
		int sum = 0;
		if(str[0] == '0')
		{
			break;
		}
		for(int i = 0;i < strlen(str) - 1;i++)
		{
			sum += str[i] - '0';
		}
		printf("%d\n", sum);
	}
	return 0;
}


Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
#define _(_1,_2,_3,N,...)N
#define pr(...) _(__VA_ARGS__,pr3,pr2,pr1)(__VA_ARGS__)
template<C T>void pr1(T a){cout<<a;ln;}
template<C T,C T2>void pr2(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr3(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;
typedef pair<int,P> PP;

void Main() {
  int n,m,l;
  while(cin >> n >> m >> l&&n) {
    vector<PP> v[n];
    rep(i,m) {
      int x,y,e,d;
      cin >> x >> y >> e >> d;
      x--,y--;
      v[x].pb(PP(y,P(e,d)));
      v[y].pb(PP(x,P(e,d)));
    }
    int d[n][l+1];
    rep(i,n)rep(j,l+1)d[i][j]=MAX;
    d[0][l]=0;
    priority_queue<PP,vector<PP>,greater<PP> > que;
    que.push(PP(0,P(0,l)));
    while(!que.empty()) {
      PP p=que.top();que.pop();
      int x=p.S.F,r=p.S.S,c=p.F;
      if(d[x][r]<c) continue;
      rep(i,v[x].size()) {
        PP q=v[x][i];
        int y=q.F,cc=q.S.S,e=q.S.F;
        if(d[y][r]>c+cc) {
          d[y][r]=c+cc;
          que.push(PP(c+cc,P(y,r)));
        }
        if(r-e>=0&&d[y][r-e]>c) {
          d[y][r-e]=c;
          que.push(PP(c,P(y,r-e)));
        }
      }
    }
    int ans=MAX;
    rep(i,l+1) ans=min(ans,d[n-1][i]);
    pr(ans);
  }
}

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


Measured memory_bytes: 1744
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	if !sc.Scan() {
		panic("failed scan string")
	}
	return sc.Text()
}

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

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	k := nextInt()

	list := make([]int, n)
	for i := 0; i < n; i++ {
		list[i] = nextInt()
	}
	sort.Ints(list)


	diff := 10000000000
	for i := 0; i < (n - k + 1); i++ {
		d := list[i+k-1] - list[i]
		if d < diff {
			diff = d
		}
	}
	fmt.Println(diff)
}


Measured memory_bytes: 3072
//Catchharsh
#include<bits/stdc++.h>
#define ll long long int 
#define ld long double
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define see(x) cout<<#x<<" = "<<x<<endl
const ll MOD = 1e9+7;
const ll INF = 1011111111;
const ll LLINF = 1000111000111000111LL;
const ld EPS = 1e-10;
const ld PI = 3.14159265358979323;
using namespace std;
ll power (ll base,ll exponent)
{
    ll ans=1;
    //base%=MOD;
    //exponent%=(MOD-1);
    while(exponent!=0)
    {
      if(exponent&1) ans=(1LL*ans*base);
      base=(1LL*base*base);
      exponent>>=1;
    }
    return ans;
}
int32_t main()
{   
     IOS;
     ll n,m,i,j,k;
     cin>>n;
     map<string,ll> mp;
     for(i=0;i<n;i++)
     {
      string s;
      cin>>s;
      mp[s]++;
     }
     ll maxi=-1;
     vector<string> ans;
     for(auto to=mp.begin();to!=mp.end();to++)
      maxi=max(maxi,to->S);
     for(auto to=mp.begin();to!=mp.end();to++)
     {
       if(to->S==maxi)
        ans.pb(to->F);
     }
     sort(all(ans));
     for(i=0;i<ans.size();i++) cout<<ans[i]<<endl;
     
     
     
     cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';             
}

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (int)(1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define PI 3.1415926535898

//------------------------------------------------------

int main() {
    int n, k;
    cin >> n >> k;
    int l[n];
    rep(i, n) cin >> l[i];

    sort(l, l + n);
    reverse(l, l + n);
    int sum = 0;
    rep(i, k) sum += l[i];
    cout << sum << endl;
    return 0;
}



Measured memory_bytes: 256
n, m = map(int, input().split())
H = list(map(int, input().split()))
H = [0] + H
Good = [1]*(n+1)
Good[0] = 0
for _ in range(m):
    a, b = map(int, input().split())
    if H[a] >= H[b]:
        Good[b] = 0
    if H[a] <= H[b]:
        Good[a] = 0
print(sum(Good))


Measured memory_bytes: 20108