akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) {}
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if(par[x] < 0)
            return x;
        else
            return par[x] = root(par[x]);
    }

    bool issame(int x, int y) { return root(x) == root(y); }

    bool merge(int x, int y) {
        x = root(x);
        y = root(y);
        if(x == y)
            return false;
        if(par[x] > par[y])
            swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) { return -par[root(x)]; }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    for(int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
        --a[i];
        --b[i];
    }

    auto calc = [](ll sz) { return sz * (sz - 1) / 2; };

    ll ans = calc(n);
    UnionFind uf(n);
    vector<ll> res(m);
    for(int i = m - 1; i >= 0; i--) {
        res[i] = ans;
        if(uf.issame(a[i], b[i])) {
            ans += calc(uf.size(a[i]));
        } else {
            ans += calc(uf.size(a[i]));
            ans += calc(uf.size(b[i]));
        }
        uf.merge(a[i], b[i]);
        ans -= calc(uf.size(a[i]));
    }
    for(int i = 0; i < m; i++) {
        cout << res[i] << endl;
    }
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    int a, b, x;
    cin >> a >> b >> x;
    if(a + b >= x && a <= x) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

int main()
{
	// Variable declaration
	int n, m;
	int A[100][100], b[100];
	int disp[100];

	// Input n, m
	cin >> n >> m;

	// Input
	// n times loop
	for (int cnt = 0; cnt < n; cnt++)
	{
		// m times loop
		for (int cnt2 = 0; cnt2 < m; cnt2++)
		{
			// Input A, b
			cin >> A[cnt][cnt2];
		}
	}
	// m times loop
	for (int cnt = 0; cnt < m; cnt++)
	{
		// Input b
		cin >> b[cnt];
	}
	// n times loop
	for (int cnt = 0; cnt < n; cnt++)
	{
		disp[cnt] = 0;
		// m times loop
		for (int cnt2 = 0; cnt2 < m; cnt2++)
		{
			disp[cnt] += A[cnt][cnt2] * b[cnt2];
		}
		// Output
		cout << disp[cnt] << endl;
	}

	return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(),(a).end()

using namespace std;

int main(int argc, char const *argv[]) {
  int A,B,C;
  scanf("%d%d%d",&A,&B,&C);
  for (size_t i = 1; i <= 100; i++) {
    if((A*i)%B==C){
      printf("YES\n");
      return 0;
    }
  }
  printf("NO\n");
  return 0;
}

/*
Aの倍数をN個選ぶ、総和をBで割ってCになる
可能かどうか
つまりAN%B=Cになるのか。
*/


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

int main() {
	long long a,b,c,d;
	cin >> a >> b >> c >> d;
	long long all = b-a+1,
	cd = lcm(c,d),
	bc = b/c,
	bd = b/d,
	ac = (a-1)/c,
	ad = (a-1)/d,
	bcd = b/cd,
	acd = (a-1)/cd;
	cout << all-bc-bd+bcd+ac+ad-acd << endl;
	return 0;
}


Measured memory_bytes: 3604
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }


/*
<url:https://onlinejudge.u-aizu.ac.jp/services/room.html#RitsCamp18Day2/problems/C>
問題文============================================================
 N 個のボールがあり、各ボールには色と価値が決められている。
 ボールの色は1からCまでC種類存在し、各色ごとに選べるボールの数の上限が決められている。
 ボールを全体で高々M個選ぶとき、得られる価値の合計を最大化せよ。

=================================================================

解説=============================================================

================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll N,M,C; cin >> N >> M >> C;
    vector<ll> l(C);
    for(auto& in:l) cin >> in;
    vector<pll> cw(N);
    for(auto& in:cw) cin >> in.second >> in.first;
    sort(cw.begin(),cw.end(),greater<pll>());
    
    ll cnt = 0;
    ll ans = 0;
    for(int i = 0; i < N;i++){
        if(l[cw[i].second-1]-- > 0){
            cnt++;
            ans += cw[i].first;
        }
        if(cnt == M) break;
    }
    cout << ans << endl;
	return 0;
}



Measured memory_bytes: 4948
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(ll i = (ll)(n)-1;i >= 0;--i)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
//#define int ll
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
vb used;
int solve(vvi &gr,int n,int a=0,int c=1){
  if(c==n) return 1;
  int res = 0;
  for(auto i:gr[a]){
    if(used[i]) continue;
    used[i] = true;
    res += solve(gr,n,i,c+1);
    used[i] = false;
  }
  return res;
}
signed main(){
  int n,m;
  cin >> n >> m;
  used.assign(n,false);
  vvi gr(n);
  REP(i,m){
    int a,b;
    cin >> a >> b;
    --a; --b;
    gr.at(a).emplace_back(b);
    gr.at(b).emplace_back(a);    
  }
  used[0] = true;
  cout << solve(gr,n) << endl;
}



Measured memory_bytes: 256
#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( void )
{
	ll n, k;
	cin >> n >> k;

	n = n % k;

	cout << min(n, k - n) << '\n';
}


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

int main(){
    ll n,a,b,xl,ans=0;
    cin >> n >> a >> b >> xl;
    vector<ll> sub(n);
    for(int i = 0;i < n-1;i ++){
        ll xr;
        cin >> xr;
        sub[i] = xr-xl;
        xl = xr;
    }
    for(int i = 0;i < n-1;i ++){
        ans += min(sub[i]*a,b);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//
        int A, B;
        cin >> A >> B;

        if (A * B % 2 == 0)
        {
                cout << "Even" << endl;
        } else{
                cout << "Odd" << endl;
        }

        

        return 0;
}


Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

from collections import deque

H, W = input_nums()
H += 2
W += 2
grid = '#' * W
for i in range(H - 2):
    grid += '#' + input() + '#'
grid += '#' * W

def bfs(start):
    INF = 10**9
    dist = [INF] * (H * W)
    dist[start] = 0
    q = deque([start])
    while q:
        v = q.popleft()
        dv = dist[v]
        for move in (1, -1, W, -W):
            next_v = v + move
            if grid[next_v] == '#':
                continue
            d_next_v = dv + 1
            if d_next_v >= dist[next_v]:
                continue
            dist[next_v] = d_next_v
            q.append(next_v)
    return max([x for x in dist if x < INF])

ans = max([bfs(x) for x in range(H * W) if grid[x] != '#'])
print(ans)

Measured memory_bytes: 43116
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const long long M = 10e9+7;
int status[1000006];
void sieve()
{
	for(int i=3;i<=sqrt(100006);i+=2)
	{
		if(status[i]==0)
		{
			for(int k= i*i;k<=100006; k+=2*i)
			{
				status[k] = 1;
			}
		}
	}
}
int main()
{
	sieve();
	int x;cin>>x;
	if(x==2)
	{
		cout<<"2\n";
		return 0;
	}
	if(x%2==0) x++;
	int ind = x;
	for(int i=ind;i<=1000000;i+=2)
	{
		if(status[i]==0)
		{
			cout<<i<<"\n";
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author SimplyDivine
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            if (n < 2) {
                out.println(1);
            } else if (n < 4) {
                out.println(2);
            } else if (n < 8) {
                out.println(4);
            } else if (n < 16) {
                out.println(8);
            } else if (n < 32) {
                out.println(16);
            } else if (n < 64) {
                out.println(32);
            } else {
                out.println(64);
            }
        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream i) {
            br = new BufferedReader(new
                    InputStreamReader(i));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    string N ;
    cin >> N;
    rep(i,3){
        if(N.at(i)=='7'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3596
n = int(input())
a = list(map(int, input().split()))
q = int(input())
l = [0]*100010
ans = sum(a)

for i in a:
    l[i] += 1

for i in range(q):
    b, c = map(int, input().split())
    ans += (c - b)*l[b]
    l[c] += l[b]
    l[b] = 0
    print(ans)

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

int main(){
  int a,b,m;
  cin >> a >> b >> m;
  vector<int>an(a);
  vector<int>bn(b);
  vector<tuple<int,int,int>>mn(m,tuple<int,int,int>(0,0,0));
  for(int i=0;i<a;i++)
    cin >> an.at(i);
  for(int i=0;i<b;i++)
    cin >> bn.at(i);
  for(int i=0;i<m;i++)
    cin >> get<0>(mn.at(i)) >> get<1>(mn.at(i)) >> get<2>(mn.at(i));
  int ans=2e5;
  for(int i=0;i<m;i++){
    ans=min(ans,an.at(get<0>(mn.at(i))-1)+bn.at(get<1>(mn.at(i))-1)-get<2>(mn.at(i)));
  }
  sort(an.begin(),an.end());
  sort(bn.begin(),bn.end());
  ans=min(ans,an.at(0)+bn.at(0));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5084
import bisect
from collections import deque
de1 = deque()
N = int(input())
A = [0] * N
for i in range(N):
    A[i] = int(input())
de1.appendleft(A[0])
for j in range(1, N):
    if de1[0] >= A[j]:
        de1.appendleft(A[j])
    else:
        de1[bisect.bisect_left(de1, A[j]) - 1] = A[j]
print(len(de1))


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


int main()
{
  ll n,m,i,j,temp=0,flag=0;
string s;
cin>>n;
while(n>0)
{
    temp=n%10;
    if(temp==7)flag=1;
    n/=10;
}
if(flag)cout<<"Yes"<<endl;
else cout<<"No"<<endl;

return 0;

}






Measured memory_bytes: 3592
// -*- coding:utf-8-unix -*-

use proconio::input;

// v[i] > k を満たす最小の i を返す (or k より小さい v の要素数)
// 見つからなければ `v.len()` を返す
// `v` はソートされていること
fn upper_bound(v: &[usize], k: usize) -> usize {
    let mut low: isize = -1;
    let mut high = v.len() as isize;

    while high - low > 1 {
        let mid = (low + high) / 2;
        if v[mid as usize] > k {
            high = mid;
        } else {
            low = mid;
        }
    }
    high as usize
}

// v[i] >= k を満たす最小の i を返す (or k より小さい v の要素数)
// 見つからなければ `v.len()` を返す
// `v` はソートされていること
fn lower_bound(v: &[usize], k: usize) -> usize {
    let mut low: isize = -1;
    let mut high = v.len() as isize;

    while high - low > 1 {
        let mid = (low + high) / 2;
        if v[mid as usize] >= k {
            high = mid;
        } else {
            low = mid;
        }
    }
    high as usize
}

fn main() {
    input! {
        n: usize,
        mut a: [usize; n],
        b: [usize; n],
        mut c: [usize; n],
    }

    a.sort();
    c.sort();
    let mut ans = 0;
    for i in 0..n {
        let a_idx = lower_bound(&a[..], b[i]);
        // if a_idx == n && a[n - 1] >= b[i] {
        //     continue;
        // }

        let c_idx = upper_bound(&c[..], b[i]);
        // if c_idx == n {
        //     continue;
        // }

        // println!("a_idx: {}, b: {}, c_idx: {}", a_idx, b[i], c_idx);
        // println!("{}", a_idx * (n - c_idx));
        ans += a_idx * (n - c_idx);
    }
    println!("{}", ans);
}


Measured memory_bytes: 7752
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;const int N=2*1e5+10;
int w[N];int d[N];int cnt[20];int res;int n;int st;bool book[N];
struct data{int v;int cf;};int sxr[N];int srt[N];
inline bool cmp(int a,int b){return d[a]<d[b];}
int main()
{
	scanf("%d",&n);
	for(int i=1,u,v,va;i<n;i++){scanf("%d%d%d",&u,&v,&va);w[u]^=va;w[v]^=va;}
	for(int i=0;i<n;i++){cnt[w[i]]++;}
	for(int i=1;i<=15;i++)res+=cnt[i]/2,st|=(cnt[i]&1)<<(i-1);	
	for(int i=1;i<(1<<15);i++)d[i]=d[i>>1]+(i&1);
	for(int i=1;i<(1<<15);i++)d[i]-=1;
	for(int i=1;i<(1<<15);i++)
		for(int j=0;j<15;j++)if((i>>j)&1)sxr[i]^=(j+1);
	for(int i=1;i<(1<<15);i++)srt[i]=i;sort(srt+1,srt+(1<<15));
	for(int i=1;i<(1<<15);i++)
	{
		if(sxr[srt[i]]!=0)continue;
		for(int k=(srt[i]-1)&srt[i];k;k=(k-1)&srt[i])
			if(sxr[k]==0)d[srt[i]]=min(d[srt[i]],d[k]+d[srt[i]^k]);
	}printf("%d",res+d[st]);return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){ 
	long long n,sum = 0;
	cin>>n;
	for(int i = 1; i <= n; i++){
		if(i % 3 == 0 || i % 5 == 0)
			continue;
		else
			sum += i;
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 3628
import java.util.*;
import java.util.stream.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int mod = (int)1e9 + 7;
        String s = sc.next();
        for (int i = 0; i < s.length(); i++) {
            if ((i % 2 == 0 && s.charAt(i) == 'L') || (i % 2 != 0 && s.charAt(i) == 'R')) {
                System.out.println("No");
                System.exit(0);
            }
        }
        System.out.println("Yes");
    }

}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M; cin >> N >> M;
  vector<int> A(M), B(M);
  vector<int> guide(N,-1);
  vector<vector<int>> pswg(N,vector<int>());
  for (int i=0;i<M;i++) {
    cin >> A.at(i) >> B.at(i);
    A.at(i)--;
    B.at(i)--;
  }
  for (int i=0; i<M;i++) {
    pswg.at(A.at(i)).push_back(B.at(i));
    pswg.at(B.at(i)).push_back(A.at(i));
  }
  vector<int> spots, newspots;
  spots={0};newspots={};
  int count=1;
  guide.at(0)=0;
  while (count<N) {
    for (int i=0;i<spots.size();i++) {
      for (int j=0;j<pswg.at(spots.at(i)).size();j++) {
        if ( guide.at( pswg.at(spots.at(i)).at(j) )==-1 ) {
          guide.at( pswg.at(spots.at(i)).at(j) ) = spots.at(i);
          count++;
          newspots.push_back(pswg.at(spots.at(i)).at(j));
        }
      }
    }
    spots=newspots;
    newspots={};
  }
  cout << "Yes" << endl;
  for (int i=1;i<N;i++) {
    cout << guide.at(i)+1 << endl;
  }
}

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

long long n,a[100005],b[100005],c[100005],r;

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

    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
        cin>>b[i];
    for(int i=0;i<n;i++)
        cin>>c[i];
    sort(a,a+n);
    sort(b,b+n);
    sort(c,c+n);

    for(int i=0;i<n;i++)
    {
        int M=upper_bound(c,c+n,b[i])-c;
        if(M==n)
            continue;
        else
        {
            int m=lower_bound(a,a+n,b[i])-a-1;
            if(m==-1)
                continue;
            else
                r+=(m+1)*(n-M);
        }
    }

    cout<<r<<endl;

    return 0;
}


Measured memory_bytes: 5968
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

using veci = vector<int>;
using pii = pair<int, int>;
using vecii = vector<pii>;
using ll = long long;
using vecl = vector<ll>;
#define fi first
#define se second
#define endl '\n'

void solve() {
    string day[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

    string s;
    cin >> s;
    for (int i=0; i<7; ++i) {
        if (day[i]==s) {
            cout << 7-i << endl;
            return;
        }
    }
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#if defined(LOCAL_TEST)
    (void)argc;
    freopen(string(argv[0]).append("-test.in").c_str(), "r", stdin);
    int tcs;
    cin >> tcs;
    while (tcs-- > 0)
#endif
    solve();
}


Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
dp = [[0] * (k + 1) for _ in range(n + 1)]

for i in range(n + 1):
    dp[i][0] = 1
for i in range(a[0] + 1):
    dp[1][i] = 1

for i in range(2, n + 1):
    for j in range(1, k + 1):
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod
        if j > a[i - 1]:
            dp[i][j] -= (dp[i - 1][j - a[i - 1] - 1]) % mod
        dp[i][j] %= mod
print(dp[n][k])

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

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

int main(){
  int h,w,k;
  cin >> h >> w >> k;

  vector<vector<int>> g(h, vector<int>(w,0));
  rep(i,h){
    rep(j,w){
      char c;
      cin >> c;
      if(c=='.')g.at(i).at(j)=0;
      if(c=='#')g.at(i).at(j)=1;
    }
  }

  //rep(i,h)rep(j,w)cout << g.at(i).at(j) << endl;

  int p_w = pow(2,w);
  int p_h = pow(2,h);
  int ans=0;

  rep(x, p_h){
    rep(y, p_w){
      int count=0;
      int nowx = x;
      int nowy = y;
      rep(i,h){
        rep(j,w){
          int tes = (nowx>>i)&1;
          int to = (nowy>>j)&1;
          if(tes==0&&to==0&&g.at(i).at(j)==1) count++;
        }
      }
      //cout << nowx << " " << nowy << " ";
      if(count==k) ans++;
      //cout << count << endl;
    }
  }

  cout << ans;
}

Measured memory_bytes: 4060
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<utility>

using namespace std;
typedef pair<int, int> P;
const int INF = (1 << 30);
int V, E, r;
int dp[100000];
struct edge{
	int to, cost;
	edge(int to,int cost=1):to(to),cost(cost){}
};
vector<edge> G[100000];

int main()
{
	cin.tie(0);
	ios::ios_base::sync_with_stdio(false);
	cin >> V >> E >> r;
	int s, t, d, update = 1, limit = V*E + 1;
	for (int i = 0; i < E; ++i) {
		cin >> s >> t >> d;
		edge e(t,d);
		G[s].emplace_back(e);
	}
	fill(dp, dp + V, INF);
	dp[r] = 0;
	priority_queue<P, vector<P>, greater<P>> que;
	que.push(P(0, r));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		if (dp[p.second] < p.first)continue;
		int v = p.second;
		for (int i = 0; i < G[v].size(); ++i) {
			edge e = G[v][i];
			if (dp[e.to]>dp[v] + e.cost) {
				dp[e.to] = dp[v] + e.cost;
				++update;
				que.push(P(dp[e.to], e.to));
			}
		}
		if (update > limit) {
			cout << "NEGATIVE CYCLE\n";
			return 0;
		}
	}
	for (int i = 0; i < V; ++i) {
		if (dp[i] == INF)cout << "INF\n";
		else cout << dp[i] << "\n";
	}
	cout << flush;
	return 0;
}

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

int main(){
 int n;cin >> n;
 vector<int> num(n);
  vector<int> numcnt(100010,0);
  for(int i=0;i<n;i++){
  cin >> num[i];
    numcnt[num[i]]++;
  }
  int cntmax=0;
  for(int i=1;i<100005;i++){
   int cnt=numcnt[i-1]+numcnt[i]+numcnt[i+1];
    cntmax=max(cntmax,cnt);
  }

  cout << cntmax << endl;

}


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

int main() {
	int N, D, X;
	cin >> N >> D >> X;
	int A[110];
	int c = 0;
	for (int i = 1;i < N + 1;i++) {
		cin >> A[i];
	}
	for (int i = 1;i < N + 1;i++) {
		for (int j = 0; j*A[i]+1 < D + 1;j++) {
			c++;
		}
	}
	cout << X + c << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define DL double
#define MLL map<LL,LL>::iterator
#define MSL map<string,L>::iterator
#define MLS map<LL,string>::iterator
#define MSS map<string,string>::iterator
#define MCL map<char,LL>::iterator
#define SL set<LL>::iterator
#define SS set<string>::iterator sl
#define G getline
#define SZ size()
#define IN insert
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
V<LL>u,v,w;
int main()
{
    FAST;
    LL n,m,i,j,k,p,q,o,l,s,t,z;
    string a;
    cin>>n;
    k=0;
    l=0;
    for(i=0; i<n; i++)
    {
        cin>>o;
        v.PSB(o);
    }
    for(i=0; i<n; i++)
    {
        o=v[i];
        k+=o;
        if(k==0)
        {
            l++;
            if(i%2==0){k=1;}
            else{k=-1;}
        }
        else
        {
            if(i%2==0 && k<0)
            {
                l+=(1-k);
                k=1;
            }
            else if(i%2==1 && k>0)
            {
                l+=(k+1);
                k=-1;
            }
        }
    }
    s=l;
    k=0;
    l=0;
    for(i=0; i<n; i++)
    {
        o=v[i];
        k+=o;
        if(k==0)
        {
           l++;
            if(i%2==0){k=-1;}
            else{k=1;}
        }
        else
        {
            if(i%2==0 && k>0)
            {
                l+=(k+1);
                k=-1;
            }
            else if(i%2==1 && k<0)
            {
                l+=(1-k);
                k=1;
            }
        }
    }
    t=l;
    cout<<min(s,t)<<endl;

    return 0;

}


Measured memory_bytes: 1400
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
typedef long long ll;
bool isEven(string s){
    int len = s.length();
    return s.substr(0,len/2) == s.substr(len/2);
}
int main(){
    string S;
    cin >> S;
    int len = S.length();
    for(int i=S.length()-2;i>=0;i-=2){
        if(isEven(S.substr(0,i))){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
// #include "prettyprint.hpp"

int findLargerThan(map<int, int> divs, int num) {
  int count = 0;
  for (int i = 1; i <= 100; i++) {
    if (divs[i] >= num) count++;
  }
  return count;
}

int main() {
  int N;
  cin >> N;
  map<int, int> divs;
  for (int i = 1; i <= 100; i++) {
    divs[i] = 0;
  }

  for (int i = 2; i <= N; i++) {
    int currentValue = i;
    for (int j = 2; j <= currentValue; j++) {
      while (currentValue % j == 0) {
        divs[j]++;
        currentValue = currentValue / j;
      }
    }
  }

  int l2 = findLargerThan(divs, 2);
  int l4 = findLargerThan(divs, 4);
  int l14 = findLargerThan(divs, 14);
  int l24 = findLargerThan(divs, 24);
  int l74 = findLargerThan(divs, 74);

  int ans = 0;
  if (l2 > 2) ans += (l4 * (l4 - 1) / 2) * (l2 - 2);
  if (l4 > 1) ans += l14 * (l4 - 1);
  if (l2 > 1) ans += l24 * (l2 - 1);
  ans += l74;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define OUT(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    while(true) {
        int h, w;
        cin >> h >> w;
        if (h == 0) break;
        string s(w,'#');
        REP(i,h) cout << s << endl;
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3188
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  string s;
  cin >> s;

  if(s[2] == s[3] && s[4] == s[5]){
    cout << "Yes\n";
  }else{
    cout << "No\n";
  }
  return 0;

}





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

//const double PI = acos(-1);
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 4e18;
const ll MOD = 1e9+7;
typedef pair<int,int> P;

int n,m;
int a[200010],b[200010];

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

  int y,m,d;
  scanf("%d/%d/%d", &y,&m,&d);
  if (y < 2019) {
    cout << "Heisei\n";
  } else {
    if (m <= 4) {
      cout << "Heisei\n";
    } else {
      cout << "TBD\n";
    }
  }
  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++)
#define ll long long
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<int>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
  int n;
  cin >> n;
  ll ans=0;
  rep(i,1000000){
    int j=i+1;
    ans+=((n-1)/j);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
W,H,x,y = map(int,input().split())

if x == W and y == H:
	print(W*H/2,end=" ")
	print(0)
	
elif x == W and y == 0:
	print(W*H/2,end=" ")
	print(0)

elif x == 0 and y == H:
	print(W*H/2,end=" ")
	print(0)
	
elif x == 0 and y == 0:
	print(W*H/2,end=" ")
	print(0)

elif x == W/2 and y == H/2:
	print(W*H/2,end=" ")
	print(1)
	
elif x == W/2:
	print(W*H/2,end=" ")
	print(0)
	
elif y == H/2:
	print(W*H/2,end=" ")
	print(0)

else:
	print(W*H/2,end=" ")
	print(0)

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

using namespace std;

#define int long long

const int DIM = 2e5 + 7;
const int mod = 1e9 + 7;

int power[DIM];
int v[DIM];

int logpow(int x, int n)
{
	int res = 1;
	
	while(n)
	{
		if(n & 1)
			res = (res * x) % mod;
		
		n >>= 1;
		x = (x * x) % mod;
	}
	
	return res;
}

void solve()
{
	int n;
	cin >> n;
	
	for(int i = 1; i <= n; i++)
	{
		cin >> v[i];
	}
	
	sort(v + 1, v + 1 + n);
	
	power[0] = 1;
	int invs = logpow(2, mod - 2);
	
	for(int i = 1; i <= n; i++)
	{
		power[i] = (2 * power[i - 1]) % mod;
	}
	
	int res = 0;
	
	for(int i = 1; i <= n; i++)
	{
		int p = power[n];
		
		p = (p * power[i - 1]) % mod;
		
		int t = power[n - i];
		
		t *= ((1 + n - i + 1) / 2);
		t %= mod;
		
		if((n - i) % 2 == 1)
			t += (power[n - i] * invs) % mod;
		
		t %= mod;
		
		p = (p * t) % mod;
		
		res += (p * v[i]) % mod;
		res %= mod;
	}
	
	cout << res << '\n';
}

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

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

using namespace std;
const int IINF = INT_MAX;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000000000
int main(){
    int n,k; cin >> n >> k;
    
    int ans = 0;
    int ten = 1;
    while(true){
    	if(n < k){
    		break;
    	} else{
    		n/=k;
    		ten++;
    	}
    }
    
    cout << ten << endl;
    return 0;	
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a; i<=b; ++i)
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
using vl=vector<ll>;
using vp=vector<pll>;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n,x,m;
    cin>>n>>x>>m;
    ll idx[m+5]={};
    vl sum;
    sum.pb(0);
    FOR(i,1,n){
        ll j=idx[x];
        if(j){
            n-=j;
            ll ans=sum[j-1]+n/(i-j)*(sum[i-1]-sum[j-1]);
            n%=i-j;
            ans+=sum[n+j]-sum[j-1];
            cout<<ans;
            return 0;
        }
        else{
            idx[x]=i;
            sum.pb(sum.back()+x);
        }
        x=x*x%m;
    }
    cout<<sum[n];
    return 0;
}

Measured memory_bytes: 4636
#include<stdio.h>
#include<string.h>
int n,a[100010],b[100010];
int main()
{
	
	while(~scanf("%d",&n))
	{
		int i;
		for(i=0;i<n+1;i++)
		scanf("%d",&a[i]);
		for(i=0;i<n;i++)
		scanf("%d",&b[i]);
		long long sum=0;
		for(i=0;i<n;i++)
		{
			if(b[i]>=a[i])
			{
				sum+=a[i];
				if(b[i]-a[i]>=a[i+1])
				{
					sum+=a[i+1];
					a[i+1]=0;
				}
				
				else
				{
					sum+=b[i]-a[i];
					a[i+1]-=b[i]-a[i];
				}
			}
			
			else
			sum+=b[i];
		}
		printf("%lld\n",sum);
	}
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;


#define ll       long long int
#define fast     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define MOD      1000000007
#define pb       push_back
#define S        second
#define F        first
#define P 		 pair<ll,ll>
#define PI 3.1415926535897932384626433832795028
//#define ordered_set tree<ll, null_type,less_equal<>, rb_tree_tag,tree_order_statistics_node_update>

int mul(int a, int b) {
	return (long long)a * b % MOD;
}

int power(int a, int b) {
	int ans = 1;
	while (b > 0) {
		if (b & 1) ans = mul(ans, a);
		a = mul(a, a);
		b >>= 1;
	}
	return ans;
}
//bitset<400000010> b;

// ll n=100000;
ll p[1000100] = {0};
vector<ll> v[1000000];
void sieve(ll n) {
	for (ll i = 2; i * i <= n; i++) {
		if (!p[i])
			//primes.push_back(i);
			for (ll j = i; j <= n; j += i) {
				if (i != j)
					;
				p[j] = 1;
			}
	}
}


// ll nextPowerOf2(ll n)
// {
//     ll p = 1;
//     if (n && !(n & (n - 1)))
//         return n;

//     while (p < n)
//         p <<= 1;

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

}
ll factorial(ll n)
{
	if (n == 0)
		return 1;
	return n * factorial(n - 1);
}
struct segmenttree {
	vector<int> st;
	int n;
	void init(int _n) {
		n = _n;
		st.clear();
		st.resize(4 * _n, 0);
	}

	void update(int l, int r, int indup, int val, int node) {
		if (l == r) {
			st[node] += val;
			return;
		}
		else {
			int mid = (l + r) / 2;
			if (indup >= l && indup <= mid) {
				update(l, mid, indup, val, node * 2 + 1);
			}
			else {
				update(mid + 1, r, indup, val, node * 2 + 2);
			}
			st[node] = st[2 * node + 1] + st[2 * node + 2];
		}
	}

	int query(int si, int se, int l, int r, int node) {
		if (se < l || si > r || l > r) {
			return 0;
		}
		if (si >= l && se <= r) {
			return st[node];
		}
		int mid = (si + se) / 2;
		int q1 = query(si, mid, l, r, node * 2 + 1);
		int q2 = query(mid + 1, se, l, r, node * 2 + 2);
		return q1 + q2;
	}
	int query(int l, int r) {
		return query(0, n - 1, l, r, 0);
	}
	void update(int index, int val) {
		update(0, n - 1, index, val, 0);
	}
} tree;

bool chkcow(ll n, vector<ll> &a, ll k, ll mis) {
	ll sum = 0;
	for (ll i = 0; i < n; i++) {
		if (a[i] > mis)
			sum += a[i] - mis;
		if (sum >= k)
			return true;
	}


	return false;
}
struct cmp {
	bool operator() (const pair<ll, ll> &a, const pair<ll, ll> &b )const
	{
		ll lena = a.S - a.F;
		ll lenb = b.S - b.F;
		if (lena == lenb)
			return a.F < b.F;
		return lena > lenb;
	}
};

int32_t main()
{	fast

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll n;
	cin >> n;
	ll x = 0;
	x = n % 10;
	if (x == 2 || x == 4 || x == 5 || x == 7 || x == 9)
		cout << "hon" << endl;
	else if (x == 0 || x == 1 || x == 6 || x == 8)
		cout << "pon" << endl;
	else
		cout << "bon" << endl;
}

Measured memory_bytes: 27088
a, b, c, d = map(int, input().split())

x, y = c, d
r = x % y
while r != 0:
    x, y = y, r
    r = x % y
gcd = y
lcm = c * d // gcd

nc = b // c - (a - 1) // c
nd = b // d - (a - 1) // d
nlcm = b // lcm - (a - 1) // lcm

print((b - a + 1) - (nc + nd - nlcm))


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

using namespace std;

int main(){
    int n, m, x, y;
    cin>>n>>m;
    bool red[n+1];
    int arr[n+1];
    red[1] = true;
    arr[1] = 1;
    for (int i=2; i<=n; i++){
        red[i] = false;
        arr[i] = 1;
    }
    for (int i=0; i<m; i++){
        cin>>x>>y;
        if (red[x] == true){
            if (arr[x]==1){
                red[x] = false;
            }
            red[y] = true;
            arr[x]--;
            arr[y]++;
        }
        else if (red[x] == false){
            arr[x]--;
            arr[y]++;
        }
    }
    int cnt = 0;
    for (int i=1; i<=n; i++){
        if (red[i] == true){
            cnt++;
        }
    }
    cout<<cnt;
}

Measured memory_bytes: 768
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define RFOR(i,a,b) for(long long i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

int main() {
	int N;
	cin >> N;
	int a[201]={};
	FOR(j,1,N+1){
      	if(j%2!=0){
			FOR(i,1,j+1){
				if(j%i==0) a[j]++;
			}
        }
	}
	int cnt=0;
	REP(i,200){
		if(a[i]==8) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string w = Console.ReadLine().ToUpper();
            int num = 0;
            string line = null;

            while ((line = Console.ReadLine()) != null)
            {
                if (line.CompareTo("END_OF_TEXT") == 0)
                    break;

                num += line.Split(' ')
                    .Select( x => x.ToUpper())
                    .Where(  x => x.CompareTo(w)  == 0)
                    .Count();

            }

            Console.WriteLine(num);
        }
    }
}

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


void solve(std::vector<long long> A){
    if(accumulate(A.begin(), A.end(), 0LL) >= 22) cout << "bust" << endl;
    else cout << "win" << endl;
}

int main(){
    std::vector<long long> A(3);
    for(int i = 0 ; i < 3 ; i++){
        scanf("%lld",&A[i]);
    }
    solve(std::move(A));
    return 0;
}


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

int main(){
    int n; cin >> n;
    vector<int> a(200000);
    vector<ll> memo(200000+1, 0);
    for(int i=0; i<n; i++){
        cin >> a[i];
        memo[a[i]]++;
    }
    ll sum=0;
    for(int i=1; i<=n; i++){
        if(memo[i]<2) continue;
        else{
            sum += memo[i]*(memo[i]-1)/2;
        }
    }
    for(int i=0; i<n; i++){
        ll ans = sum - (memo[a[i]]-1);
        cout <<ans << endl;
    }
    return 0;

}

Measured memory_bytes: 5632
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
string s;
int i;
int func(int a){
    vector<int>in;
    for(i=a;i<1e10;i++){
        if(s[i]==']')break;
        if(s[i]=='['){
            int q=i+1;
            in.pb(func(q));
        }
        if(isdigit(s[i])){
            int out=0;//s[i]-'0';
            while(isdigit(s[i])){
                out*=10;
                out+=s[i]-'0';
                i++;
            }
            return out/2+1;
        }
    }
    //rep(j,in.size())cout<<" "<<in[j];
    //cout<<endl;
 
    sort(all(in));
    int sum=0;
    rep(j,in.size()/2+1)sum+=in[j];
    return sum;
}
int main(){
    int n;
    cin>>n;
    while(n--){
        i=0;
        cin>>s;
        int q=1;
        cout<<func(q)<<endl;
    }
}

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

int64_t DP[19][2][2][10][10][10];

signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    cout << fixed << setprecision(20);

    string n;
    cin >> n;
    if (n.length() < 4){
        cout << 0 << endl;
        return 0;
    }
    DP[0][0][0][0][0][0] = 1;

    for (int i = 0; i < n.length(); i++){
        for (int j = 0; j <= 1; j++){
            for (int k = 0; k <= 1; k++){
                for (int a = 0; a < 10; a++){
                    for (int b = 0; b < 10; b++){
                        for (int c = 0; c < 10; c++){
                            for (int d = 0; d < 10; d++){
                                int pyonpyon = k == 1 or (a == 5 and b == 1 and d == 3);
                                if (j == 1){
                                    DP[i + 1][1][pyonpyon][b][c][d] += DP[i][j][k][a][b][c];
                                    continue;
                                }
                                if (d > n[i] - '0')
                                    continue;
                                if (d == n[i] - '0')
                                    DP[i + 1][0][pyonpyon][b][c][d] += DP[i][j][k][a][b][c];
                                else
                                    DP[i + 1][1][pyonpyon][b][c][d] += DP[i][j][k][a][b][c];
                            }
                        }
                    }
                }
            }
        }
    }
    

    int64_t ans = 0;
    for (int a = 0; a < 10; a++){
        for (int b = 0; b < 10; b++){
            for (int c = 0; c < 10; c++){
                ans += DP[n.length()][0][1][a][b][c];
                ans += DP[n.length()][1][1][a][b][c];
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

int main(void){
  int A,B,C; cin >> A >> B >> C;
  int K;cin >> K;
  if(A<B) swap(A,B);
  if(A<C) swap(A,C);
  A<<=K;
  cout << A+B+C << endl;
  return 0;
}


Measured memory_bytes: 256
#![allow(
  non_snake_case,
  unused_variables,
  unused_assignments,
  unused_mut,
  unused_imports,
  dead_code
)]
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
//use std::num;
//use petgraph::unionfind::UnionFind;
//use permutohedron::LexicalPermutation as _;

//#[fastout()]
fn main() {
  input! {
      N:usize,
      A:[u64;N]
  }
  let A: Vec<u64> = A;
  let mut ans = 0u64;
  let mut tmp = A[0];
  for i in 1..A.len() {
    if A[i] < tmp {
      let diff = tmp - A[i];
      ans += diff;
    } else {
      tmp = A[i];
    }
  }
  println!("{}", ans);
}


Measured memory_bytes: 5536
def givenewluns(string):
    if string[-1] == '0':
        return [string + '0', string + '1']
    elif string[-1] == '9':
        return [string + '8', string + '9']
    else:
        return [string + str(int(string[-1])-1), string + string[-1], string + str(int(string[-1])+1)]

luns = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
counter = 0

K = int(input())

while(counter + len(luns) < K):
    counter += len(luns)
    newluns = []
    for l in luns:
        newluns += givenewluns(l)
    luns = newluns

print(luns[K - counter - 1])

Measured memory_bytes: 15628
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

ll dp[22][22][22][22];

int main(){
  int h,w; cin >> h >> w;
  rep(i,h)rep(j,w)rep(k,h)rep(l,w) dp[i][j][k][l]=inf;
  rep(i,h)rep(j,w) dp[i][j][i][j]=0;
  vector<string> g(h);
  rep(i,h) cin >> g[i];
  rep(i,h)rep(j,w){
    if(j-1>=0&&g[i][j]=='.'&&g[i][j-1]=='.') dp[i][j][i][j-1]=1;
    if(i-1>=0&&g[i][j]=='.'&&g[i-1][j]=='.') dp[i][j][i-1][j]=1;
    if(j+1<w&&g[i][j]=='.'&&g[i][j+1]=='.') dp[i][j][i][j+1]=1;
    if(i+1<h&&g[i][j]=='.'&&g[i+1][j]=='.') dp[i][j][i+1][j]=1;
  }
  rep(a,h)rep(b,w)rep(i,h)rep(j,w)rep(k,h)rep(l,w){
    chmin(dp[i][j][k][l],dp[i][j][a][b]+dp[a][b][k][l]);
  }
  ll ans=0;
  rep(i,h)rep(j,w){
    rep(k,h)rep(l,w){
      if(dp[i][j][k][l]!=inf) chmax(ans,dp[i][j][k][l]);
    }
  }
  cout << ans << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3
#define mod 1000000007

struct state{
  int v,elim,rest;
};

bool operator<(const state& a,const state& b){
  return a.rest < b.rest;
}

int N,M,C;
vector<P> g[100];
int dp[100][1001];

int main(){
  while(1){
    cin>>N>>M>>C;
    if(N==0&&M==0)break;
    rep(i,N)g[i].clear();
    rep(i,M){
      int a,b,c;
      cin>>a>>b>>c;
      a--;b--;
      g[a].push_back(P(b,c));
    }
    rep(i,N)rep(j,M+1)dp[i][j]=-INF;
    priority_queue<state> que;
    que.push((state){0,0,C});
    while(que.size()){
      state s=que.top(); que.pop();
      if(dp[s.v][s.elim]!=-INF)continue;
      dp[s.v][s.elim]=s.rest;
      for(P e : g[s.v]){
        if(s.rest>=e.se){
          que.push((state){e.fi,s.elim,s.rest-e.se});
        }
        que.push((state){e.fi,s.elim+1,s.rest});
      }
    }
    int res=INF;
    repl(j,1,M+1)if(dp[N-1][j]>=0)minch(res,j);
    cout<<res<<endl;
  }
  return 0;
}



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

#define int long long

signed main() {
#ifdef _DEBUG
	//freopen("in", "r", stdin);
#endif
	int n; cin >> n;
  if (n == 2) {
    cout << 1 << '\n';
    return 0;
  }
	int cnt = 2;
	for (int i = 2; i * i <= n - 1; i++) {
		if ((n - 1) % i == 0) {
			cnt++;
			if ((n - 1) / i != i) cnt++;
		}
	}
  for (int i = 2; i * i <= n; i++) {
    if (n % i) continue;
    vector<int> v = {i};
    if (n / i != i) v.push_back(n / i);
    for (auto j : v) {
      int t = n;
      while (t % j == 0) t /= j;
      if (t % j == 1) cnt++;
    }
  }
	cout << cnt << '\n';
}


Measured memory_bytes: 3636
#include<iostream>
using namespace std;
#define inf 1e9
int n;
int solve(int* arr, int n)
{
	int dp[n + 1];
	dp[1] = 0;
	if(n==2)return dp[2] = abs(arr[2] - arr[1]);
	for(int i = 2; i <= n; i++){
		int option1 = abs(arr[i] - arr[i-1]) + dp[i - 1];
		int option2 = (i==2)?inf:abs(arr[i] - arr[i-2]) + dp[i - 2];
		dp[i] = min(option1, option2);
	}
	return dp[n];
}
int main()
{
	cin >> n;
	int arr[n + 1];
	for(int i = 1; i <= n; i++)cin >> arr[i];
	cout << solve(arr, n);
	return 0;
}

Measured memory_bytes: 3912
#include <stdio.h>

int main(void){
	double a[50]={0};
	double max=0,min;
	int i=1;

	scanf("%lf",&a[0]);
	min=a[0];
	max=a[0];

	while(scanf("%lf",&a[i]) != EOF){
		if(max < a[i])
			max=a[i];
		if(min >a[i])
			min=a[i];
		i++;
	}

	printf("%f\n",max-min);
	return 0;
}

Measured memory_bytes: 648