akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
using ll = long long;

int main(){
  int h, w, k; cin >> h >> w >> k;
  vector<vector<int>> wh(h, vector<int>(w));
  vector<string> s(h);
  rep(i, h) cin >> s[i];
  
  	wh[0][0] = s[0][0]-'0';
    int ans = 10005;
  for (int bit = 0; bit < (1 << h-1); bit++) {
    int cut = 0;
	rep(i, h-1){
      if (bit & (1 << i)){
        wh[i+1][0] = (s[i+1][0]-'0'); cut++;
      }
      else wh[i+1][0] = wh[i][0] + (s[i+1][0]-'0');
      if(wh[i+1][0] > k) cut = 10005;
    }
    
    rep(j, w-1){
      bool over = false;
      wh[0][j+1] = wh[0][j] + (s[0][j+1]-'0');
      if(wh[0][j+1]>k) over = true;
      rep(i, h-1){  
      if (bit & (1 << i)) wh[i+1][j+1] = wh[i+1][j] + (s[i+1][j+1]-'0');
      else wh[i+1][j+1] = wh[i+1][j] + wh[i][j+1] - wh[i][j] + (s[i+1][j+1]-'0');
      
      if(wh[i+1][j+1]>k) over = true;
      }
      
      if(over){
        cut++;
        wh[0][j+1] = s[0][j+1]-'0';
        rep(i, h-1){
           if (bit & (1 << i)) wh[i+1][j+1] = (s[i+1][j+1]-'0');
           else wh[i+1][j+1] = wh[i][j+1] + (s[i+1][j+1]-'0');
        }
      }
    }
      ans = min(ans, cut);  
  }
    
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N, *A = map(int, open(0).read().split())
l = 0
r = 0
s = A[l]
x = A[l]
ans = 0
flag = True
for l in range(N):
  while s==x and flag:
    r += 1
    if r==N:
      flag = False
      break
    s += A[r]
    x ^= A[r]
  ans += r-l
  s -= A[l]
  x ^= A[l]
print(ans)

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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;

  cout << (N+1)/2-1 << endl;
  
  return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    vector<int> A(N);
    vector<vector<pair<int,int>>> xy(N);
    rep(i,N){
        cin >> A[i];
        rep(j,A[i]){
            int x,y;cin >> x >> y;
            x--;
            xy[i].push_back({x,y});
        }
    }

    //bit_flag集をvectorに格納
    vector<int> bit_flag(15);
    rep(i,15){
        bit_flag[i] = (1 << i);
    }

    int ans = 0;
    for(int bit = 0;bit < (1 << N);++bit){
        bool ok = true;

        rep(i,N)rep(j,A[i]){
            if(bit & bit_flag[i]){      // 正直者
                rep(j,A[i]){
                    int x = xy[i][j].F;
                    int y = xy[i][j].S;
                    if((bit >> x) % 2 != y)ok = false;         
                }
            }
        }
        if(ok)ans = max(ans,__builtin_popcount(bit));
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
//----->|try=0; while(!success) try++;|<------
//----->|Belief Yourself,Respect Yourself|<----
//----->|Be Proud Of Yourself,You're Doing Your best|<-----
#include<bits/stdc++.h>
using namespace std;
#define uniq(x)  x.erase(unique(x.begin(),x.end()), x.end()) //Unique value find from vector
#define upper(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Upper value search;
#define lower(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Lower value search;
#define max3(a,b,c) max(max(a,b),c)//maximum value find three value;
#define min3(a,b,c) min(min(a,b),c)//minimum value find three value;
#define rep(i,intial,n) for(int i=intial; i<(n) ; i++)
#define REP(i,intial,n) for(int i=intial; i<=(n) ; i++)
#define PI acos(-1.0)//PI Calculation
#define LL long long
#define AND(a,b) ((a) & (b))
#define OR(a,b) ((a)|(b))
#define XOR(a,b) ((a) ^ (b))
#define MP make_pair
#define sqr(x) ((x)*(x))
#define sqrt(x) sqrt(1.0*(x))
#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define MX 1000005
#define MOD 1000000007
template<typename T> T POW(T b,T p)          //Pow calculation
{
    T r=1;
    while(p)
    {
        if(p&1)r=(r*b);
        b=(b*b);
        p>>=1;
    }
    return r;
}

template<typename T> T BigMod(T b,T p,T m) //BigMod Calculation
{
    T r=1;
    while(p)
    {
        if(p&1)r=(r*b)%m;
        b=(b*b)%m;
        p>>=1;
    }
    return r;
}

//||--------------------------->||Main_Code_Start_From_Here||<---------------------------------||
int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    int x1,y1,x2,y2;
    while(cin>>x1>>y1>>x2>>y2)
    {
        int height=y2-y1;
        int weight=x2-x1;
        string s="";
        rep(i,0,height) s+='U';
        rep(i,0,weight) s+='R';
        rep(i,0,height) s+='D';
        rep(i,0,weight) s+='L';

        s+='D';

        rep(i,0,weight+1) s+='R';
        rep(i,0,height+1) s+='U';

        s+="LU";

        rep(i,0,weight+1) s+='L';
        rep(i,0,height+1) s+='D';

        s+='R';

        cout<<s<<endl;
    }


}


Measured memory_bytes: 256
#include<stdio.h>
main(){
  int ia,ma,sa,ea,ib,mb,sb,eb,S,T;
  scanf("%d%d%d%d",&ia,&ma,&sa,&ea);
  scanf("%d%d%d%d",&ib,&mb,&sb,&eb);
  S=ia+ma+sa+ea;
  T=ib+mb+sb+eb;
  if(S>T || S==T){
    printf("%d\n",S);
  }
  else{
    printf("%d\n",T);
  }
  return 0;
}

Measured memory_bytes: 588
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int ma=-1;
  int mi=10000;
  vector<int> ie(n);
  for(int i=0;i<n;i++){
    cin>>ie[i];
    ma=max(ma,ie[i]);
    mi=min(mi,ie[i]);
  }
  cout<<ma-mi<<endl;
}


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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    map<int ,int > mp;
    rep(i,n)
    {
        cin >> a[i];
        mp[a[i]]++;
    }
    int ans = 0;
    sort(a.begin(),a.end());
    a.erase(std::unique(a.begin(), a.end()), a.end());
    for (auto &s : a)
    {
        if(mp[s]%2 != 0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
int a[3010], n;
long long dp[3010][3010], sum;
long long solve(int l, int r){
    //printf("%d %d\n", l, r);
    if (dp[l][r] != 0)
        return dp[l][r];
    if (l > r)
        return 0;
    /*if (l == r)
        return dp[l][r] = a[l];
    if (l + 1 == r)
        return dp[l][r] = max(a[l], a[r]);
    */
    dp[l][r] = a[l] + min(solve(l + 1, r - 1), solve(l + 2, r));
    dp[l][r] = max(dp[l][r], a[r] + min(solve(l + 1, r - 1), solve(l, r - 2)));
    //!!not maxxxxxx opponent want to minimize what player 1 gets
    //printf("%d %d %lld!\n", l, r, dp[l][r]);
    return dp[l][r];
}
int main(){
    scanf("%d", &n);
    for (int i = 1; i <= n; i++){
        scanf("%d", &a[i]);
        sum += a[i];
    }
    //memset(dp, 0, sizeof(dp));
    solve(1, n);
    //printf("%lld\n", dp[1][n]);
    printf("%lld\n", 2 * dp[1][n] - sum);
    return 0;
}

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

const int MAXN = 101;
const int MAXM = 10080;
int N, M;
vector<int> T[MAXN];

int main() {
  while(cin >> N >> M && (N|M)) {
    for(int i = 0; i < MAXN; ++i) T[i].clear();
    for(int i = 0; i < N; ++i) {
      int a;
      while(cin >> a && a) {
	T[i].push_back(a);
      }
    }
    queue<int> que;
    int ju_den = -1;
    int p[MAXN];
    int t[MAXN];
    fill(p,p+MAXN, 0);
    for(int j = 0; j < N; ++j) t[j] = T[j][0];
    int ans = 0;
    for(int i = 0; i < M; ++i) {
      for(int j = 0; j < N; ++j) {
	if(p[j]%2 == 0) {
	  --t[j];
	  if(t[j] == 0) {
	    p[j] = (p[j]+1)%T[j].size();
	    t[j] = T[j][p[j]];
	    que.push(j);
	  }
	} else {
	  if(ju_den == j) {
	    --t[j];
	    if(t[j] == 0) {
	      p[j] = (p[j]+1)%T[j].size();
	      t[j] = T[j][p[j]];
	      ju_den = -1;
	    }
	  } else {
	    ++ans;
	  }
	}
      }
      if(que.size() && ju_den == -1) {
	ju_den = que.front();
	que.pop();
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1248
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	a := nextInt(sc)
	b := nextInt(sc)
	fmt.Println(resolve(a, b))
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) int64 {
	i, err := strconv.ParseInt(nextString(sc), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func resolve(a, b int64) string {
	if a == b {
		return "a == b"
	} else if a < b {
		return "a < b"
	} else {
		return "a > b"
	}
}



Measured memory_bytes: 1084
#!/usr/bin/env python3
import sys, math, itertools
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0



a, b, c = map(int, input().split())
for i in itertools.permutations([a, b, c], 3):
    if i[0] == sum(i[1:]) or sum(i[:2]) == i[2]:
        print("Yes")
        exit()

print("No")


Measured memory_bytes: 38384
package main

import (
	"bytes"
	"fmt"
)

func main() {
	var n, k int
	var s string
	fmt.Scan(&n)
	fmt.Scan(&s)
	fmt.Scan(&k)

	left := s[k-1]
	ret := bytes.NewBuffer([]byte{})
	for i := 0; i < len(s); i++ {
		if s[i] == left {
			ret.WriteByte(s[i])
		} else {
			ret.WriteByte('*')
		}
	}

	fmt.Println(ret.String())
}


Measured memory_bytes: 640
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

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; }
const long long INF = 10010010010010;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}
//dp[i][j][k]:i桁目まで見て、0以外をj個使ってそれまで一致している時k=0
long long dp[105][4][2];

int main() {
    string S;cin >> S;
    int K;cin >> K;
    int N = S.size();
    for(int i = 0;i<105;i++) for(int j = 0;j<4;j++) for(int k = 0;k<2;k++) dp[i][j][k] = 0;
    dp[0][0][0] = 1;
    //状態を全列挙
    for(int i = 0;i<N;i++){
        for(int j = 0;j<4;j++){
            for(int k = 0;k<2;k++){
                //Sのi桁目を見る
                int nowdigit = S.at(i)-'0';
                //i桁目として0~9の10通り
                for(int l = 0;l<10;l++){
                    int nextj = j,nextk = k;
                    //i桁目が0でないなら次桁のjを加算する
                    if(l != 0) nextj++;
                    //i桁目として0以外を使えるのはK回まで
                    if(nextj > K) continue;

                    //i-1桁目まで今まで一致している時
                    if(k == 0){
                        //i桁目の候補がnowdigitより大きかったらダメ
                        if(l > nowdigit) continue;
                        //i桁目の候補がnowdigitより小さいとkは0になる
                        if(l < nowdigit) nextk = 1;
                    }
                    dp[i+1][nextj][nextk] += dp[i][j][k];
                }
            }
        }
    }
    cout << dp[N][K][0]+dp[N][K][1] << endl;
}


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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

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


int main()
{
    int n;
    cin >> n;
    vector<ll> sosu(n+1);
    rep(i,n+1)sosu[i] = (ll)0;
    int temp_n;
    for(int nn = 2; nn<= n; nn++)
    {
        int temp_n = nn;
        for (int num = 2; num * num <= temp_n; num++)
        {
            while (temp_n % num == 0)
            {
                sosu[num]++;
                temp_n /= num;
            }
        }
        sosu[temp_n]++;
    }
    
    
    ll ans = 1;
    for (int i = 2; i <=n; i++)
    {
        if(sosu[i]!=0)
        {
            ll temp = sosu[i] + 1;
            ans *= temp;
            ans %= MOD;
        }
    }
    cout << ans << endl;


    

    
    

}

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


int abs(int i, int j) {
  if (i > j) {
    return i - j;
  } else{
    return j - i;
  }
}
  
int main ()
{
  int tmp_N;
  cin >> tmp_N;
  const int N = tmp_N;
  vector <int> cost(N);
  vector <int> dp(N);
  for (int i = 0; i < N; i++) cin >> cost.at(i);
  
  dp.at(0) = 0;
  dp.at(1) = abs(cost.at(0), cost.at(1));
  
  for (int i = 2; i < N; i++) {
    int tmp1 = 0, tmp2 = 0;
    tmp1 = abs(cost[i], cost[i-1]);
    tmp2 = abs(cost[i], cost[i-2]);
    
    if (dp.at(i-1)+tmp1 < dp.at(i-2)+tmp2 ){
      dp.at(i) = dp.at(i-1)+tmp1;
     } else{
      dp.at(i) = dp.at(i-2)+tmp2;
    }
  }
  
  cout << dp.at(N-1) << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
deque<char> deq;
int main() 
{
    string s;
    cin >> s;
    for(int i=0;i<s.size();i++)
        deq.push_back(s[i]);
    bool on = false;
    int Q;
    cin >> Q;
    while(Q--) 
    {
        int T;
        cin >> T;
        if(T == 1) 
            on ^= true;
        else 
        {
            int F;
            cin >> F;
            char c;
            cin >> c;
            if(on^(F == 1)) 
                deq.push_front(c);
            else 
                deq.push_back(c);
        }
    }
    string ans;
    while(!deq.empty()) 
    {
        ans.push_back(deq.front());
        deq.pop_front();
    }
    if(on) 
        reverse(ans.begin(), ans.end());
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1412
N=int(input())
A=list(map(int,input().split()))
A.sort()
dic={}
for i in range(N):
    if A[i] not in dic:
        dic[A[i]]=0
    dic[A[i]]+=1
ban=set([])
res=0
for i in range(N):
    a=A[i]
    if a not in ban:
        if dic[A[i]]==1:
            res+=1
        for j in range(1,10**6//a+1):
            ban.add(a*j)

print(res)

Measured memory_bytes: 174616
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

int main(){
	int n;

	cin >> n;

	vector<int> a(n);

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

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

	int sum = 0;

	for (int i = 0; i < n; i++){
		if(i!=n-1)sum += a[i];
	}

	if (a[n - 1] < sum)puts("Yes");
	else puts("No");

	return 0;
}

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

int H, W, N;
constexpr char D[4] = {'U', 'R', 'D', 'L'};
constexpr int dx[4] = {0, 1, 0, -1},
              dy[4] = {-1, 0, 1, 0};

string dfs(int y, int x, int d, string res, vector<string>& v) {
    if(res.size() == N) {
        return res;
    }

    v[y][x] = '.';
    for(int i=0; i<4; ++i) {
        if(i == (d + 2) % 4) {
            continue;
        }

        int ny = y, nx = x;
        while(0 <= ny && ny < H && 0 <= nx && nx < W) {
            if(v[ny][nx] == 'o') {
                break;
            }
            ny += dy[i];
            nx += dx[i];
        }
        if(0 <= ny && ny < H && 0 <= nx && nx < W) {
            string r = dfs(ny, nx, i, res + D[i], v);
            if(r != "") {
                return r;
            }
        }
    }
    v[y][x] = 'o';

    return "";
}

int main() {
    cin >> H >> W;
    vector<string> v(H);
    int sx, sy, sd;
    for(int i=0; i<H; ++i) {
        cin >> v[i];
        for(int j=0; j<W; ++j) {
            N += v[i][j] == 'o';
            if(v[i][j] == 'U' || v[i][j] == 'D' || v[i][j] == 'L' || v[i][j] == 'R') {
                sy = i;
                sx = j;
                sd = find(D, D+4, v[i][j]) - D;
            }
        }
    }
    cout << dfs(sy, sx, sd, "", v) << endl;
}


Measured memory_bytes: 3224
import java.util.Arrays;
import java.util.Scanner;
 
class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int ans = 0;

    String s = sc.next();
    String a,b;
    int x = s.length();
    a = String.valueOf(s.charAt(0));
    b = String.valueOf(s.charAt(x-1));
    System.out.println(a + (x-2) + b);

    sc.close();
  }
}


Measured memory_bytes: 23252
MOD = 10 ** 9 + 7
INF = 10 ** 20
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)
from collections import defaultdict
dy = (-1,0,1,0)
dx = (0,1,0,-1)

def main():
    n = int(input())
    a = list(map(int,input().split()))

    dp = [{(i - 1)//2: -INF, (i + 1)//2: -INF} for i in range(n + 1)]
    dp[0][0] = 0
    dp[1][0] = 0
    dp[1][1] = a[0]
    for i in range(1,n):
        if i%2 == 1:
            m1,m2 = (i + 2)//2,i//2
            dp[i + 1][m1] = max(dp[i - 1][m1 - 1] + a[i],dp[i][m1])
            dp[i + 1][m2] = max(dp[i - 1][m2 - 1] + a[i],dp[i][m2])
        else:
            m1,m2 = (i + 2)//2,i//2
            dp[i + 1][m1] = dp[i - 1][m1 - 1] + a[i]
            dp[i + 1][m2] = max(dp[i - 1][m2 - 1] + a[i],dp[i][m2])

    print(dp[n][(n//2)])

if __name__ =='__main__':
    main()  


Measured memory_bytes: 105452
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <cmath>

using namespace std;

const long mod = 2019;

int main() {
	long l,r;
	cin >> l >> r;

	long ldiv = (l-1) / mod;
	long rdiv = r / mod;
 
	if ( rdiv - ldiv > 0 ) {
		puts("0");
		return 0;
	}

	l%=mod; r%=mod;

	long ans = 3000;
	for (long i=l; i<=r; i++) {
		for(long j=i+1; j<=r; j++) {
			ans = min(ans, (i*j)%mod);
		}
	}
	cout << ans << endl;

}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define int long long
using namespace std;

inline int read(){
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')w=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}

inline bool read(int& a){
    int s=0,w=1;
    char ch=getchar();
    if(ch==EOF){
		return false;
	}
    while(ch<'0'||ch>'9'){
        if(ch=='-')w=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    a=s*w;
    return true;
}

inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}

inline void writeln(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
    puts("");
}

struct node{
    int x,y;
};

int n,m;
char a[1010][1010];
int inq[1010][1010];
deque<node> q;

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
int nx,ny,ex,ey;

bool check(int x,int y,int w){
    return !(x<1||x>n||y<1||y>m||inq[x][y]<=w);
}

signed main(){
    memset(inq,0x3f,sizeof(inq));
    
    read(n),read(m);
    read(nx),read(ny),read(ex),read(ey);
    
    q.push_back((node){nx,ny});
    inq[nx][ny]=0;
    
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cin>>a[i][j];
            
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            if(a[i][j]=='#')
                inq[i][j]=-1;
            
    node t;
    int i,j;
            
    while(q.size()){
        t=q.front();
        q.pop_front();
        
        if(t.x==ex&&t.y==ey){
            cout<<inq[ex][ey]<<"\n";
            
            while(q.size())
                q.pop_front();
                
            return 0;
        }
        
        for(i=0;i<4;i++)
            if(check(t.x+dx[i],t.y+dy[i],inq[t.x][t.y])){
                inq[t.x+dx[i]][t.y+dy[i]]=inq[t.x][t.y];
                q.push_front((node){t.x+dx[i],t.y+dy[i]});
            }
            
        for(i=-2;i<3;i++)
            for(j=-2;j<3;j++)
                if(check(t.x+i,t.y+j,inq[t.x][t.y]+1)){
                    inq[t.x+i][t.y+j]=inq[t.x][t.y]+1;
                    q.push_back((node){t.x+i,t.y+j});
                }
    }
    
    cout<<"-1\n";
    return 0;
}

Measured memory_bytes: 12596
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <tuple>
using namespace std;

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

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
string s;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> s;
  int sl = s.length();
  bool ans = false;
  char c = s[0];
  REP(i, sl) {
    if(c == s[i + 1]) ans = true;
    c = s[i + 1];
  }

  cout << (ans ? "Bad" : "Good") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();


int main() {
    int n;
    cin >> n;
    vector<ll> T(n, 0);
    vector<ll> A(n, 0);
    for(ll& val: T)
        cin >> val;
    for(ll& val: A)
        cin >> val;
    ll M = T.back();
    if (A[0] != M) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    ll mod = 1e9 + 7;
    int T_idx = -1, A_idx = n;
    for(int i = 0; i < n; i++) {
        if (T[i] == M && T_idx == -1)
            T_idx = i;
    }
    for(int i = n-1; i >= 0; i--) {
        if (A[i] == M && A_idx == n)
            A_idx = i;
    }
    if (T_idx > A_idx) {
        cout << 0 << endl;
        return 0;
    }
    for(int i = 1; i < n-1; i++) {
        if (i < T_idx && T[i] == T[i-1])
            ans *= T[i];
        else if (i > A_idx && A[i] == A[i+1])
            ans *= A[i];

        else if (i > T_idx && i < A_idx)
            ans *= T.back();
        ans %= mod;

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




Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

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

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

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

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

  int a, p;
  cin >> a >> p;

  cout << (a * 3 + p) / 2 << endl;

  return 0;
}

Measured memory_bytes: 256
# coding: utf-8

a = int(input())
sum = []
result = 0

ub = int(pow(a, 0.5)) + 1

for i in range(2, ub):  
  (d, mod) = divmod(a, i)
  if mod == 0:
    sum.append(i + d)

if len(sum) == 0:
  print(a - 1)
else:
  sum.sort()
  print(sum[0] - 2)


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

int main(){

	ios::sync_with_stdio(0);
	cin.tie(0);

	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	
	int n,k;
	cin>>n>>k;

	int d[k+1],i;
	map<int,int> m;

	for(i=1;i<=k;i++){
		cin>>d[i];
		while(d[i]--){
			int temp;
			cin>>temp;
			m[temp] = 1;
		}
	}

	int ans = 0;
	for(i=1;i<=n;i++){
		if(m[i] == 0)
		ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define Inf 1LL << 60
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 N;
long long dp[100010][3];
int h[100010][3];

int main(){
    cin >> N;
    for(int i = 0;i < N;i++)
        cin >> h[i][0] >> h[i][1] >> h[i][2];
    for(int i = 0;i < N;i++){
        for(int j = 0;j < 3;j++){
            for(int k = 0;k < 3;k++){
                if(k == j) continue;
                chmax(dp[i + 1][k],dp[i][j] + h[i][k]);
            }
        }
    }
    long long ans = 0;
    for (int j = 0; j < 3; ++j) chmax(ans, dp[N][j]);
    cout << ans << '\n';
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define qsort(A) sort(A.begin(),A.end())
#define rev(A) reverse(A.begin(),A.end())
typedef long long ll;

int main(){
  int N,M;
  cin >>N>>M;
  priority_queue<pair<int,int>> q;
  rep(i,N){
    int A; cin >>A;
    q.push(make_pair(A,1));
  }
  rep(i,M){
    int B,C; cin >>B>>C;
    q.push(make_pair(C,B));
  }
  ll ans = 0;
  rep(i,N){
    pair<int,int> P = q.top();
    q.pop();
    ans += P.first;
    P.second --;
    if(P.second > 0) q.push(P);
  }
  cout << ans << endl;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int maxn=2009;
const int maxk=10009;
int n,K,len[maxn];
char s[maxn][maxk];
bitset<maxk> bit[maxn];
pii v[2][maxk];
int main()
{
    scanf("%d%d",&n,&K);
    for (int i=1;i<=n;++i) {
        scanf("%s",s[i]);
        len[i]=strlen(s[i]);
    }
    bit[n+1][0]=1;
    for (int i=n;i>=1;--i)
        bit[i]=bit[i+1]|(bit[i+1]<<len[i]);
    int c1=0;
    for (int i=1;i<=n;++i)
        if (bit[i+1][K-len[i]])
            v[0][++c1]=pii(i,0);
    for (int o=1;o<=K;++o) {
        char mmin='z';int c2=0;
        for (int i=1;i<=c1;++i)
            mmin=min(mmin,s[v[o-1&1][i].first][v[o-1&1][i].second]);
        putchar(mmin);
        int ID=n+1;
        for (int i=1;i<=c1;++i) {
            int id=v[o-1&1][i].first,pos=v[o-1&1][i].second;
            if (s[id][pos]!=mmin) continue;
            if (pos+1==len[id]) ID=min(ID,id);
            else v[o&1][++c2]=pii(id,pos+1);
        }
        for (int i=ID+1;i<=n;++i)
            if (K-o-len[i]>=0&&bit[i+1][K-o-len[i]])
                v[o&1][++c2]=pii(i,0);
        c1=c2;
    }
    return 0;
}


Measured memory_bytes: 15124
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <complex>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>

using namespace std;
typedef long long ll;

int main() {
	int n = 4;
	//cin >> n;
	vector<int> h((int)n);
	for (int i = 0; i < n; ++i) cin >> h[i];

	int v[4];

	for (int i = 0; i < 4; ++i)
	{
		v[i] = 1;
	}

	string ans = "YES";

	for (int i = 0; i < 4; ++i)
	{
		if (h[i] == 1) v[0] = 0;
		if (h[i] == 9) v[1] = 0;
		if (h[i] == 7) v[2] = 0;
		if (h[i] == 4) v[3] = 0;
	}

	for (int i = 0; i < 4; ++i)
	{
		if (v[i] != 0)
		{
			ans = "NO";
			break;
		}
	}

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

Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;

int main() {
	int N;
	cin>>N;
	vector<long long> x(N), y(N), h(N);
	for(int i=0; i<N;++i){
		cin>>x[i]>>y[i]>>h[i];
	}

	int MAX = 100;
	for(int posY = 0; posY <= MAX; posY++){
		for(int posX = 0; posX <= MAX; posX++){
			int needH = -1;

			for(int i = 0; i < N; i++){
				if(h[i] > 0){
					int tmp = h[i] + abs(posY - y[i]) + abs(posX - x[i]);
					if(needH == -1){
						needH = tmp;
					}
					else{
						if(needH != tmp){
							needH = -2;
							break;
						}
					}
				}
			}
			if(needH == -2) continue;

			for(int i = 0; i < N; i++){
				if(h[i] == 0){
					int dist = abs(posY - y[i]) + abs(posX - x[i]);
					if(needH > dist){
						needH = -2;
						break;
					}
				}
			}
			if(needH == -2) continue;

			cout<<posX<<" "<<posY<<" "<<needH<<endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n; cin >> n;
  vector<int> v(n);
  for(int i=0; i<n; i++){
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  int sum = 0;
  for(int i=0; i<n;i++){
    for(int j=i+1;j<n;j++){
      for(int k=j+1;k<n;k++){
        if(v[i]+v[j]>v[k] && (v[k]+v[j]>v[i] && v[i]+v[k]>v[j])){
          sum += 1;
        }
        else break;
      }
    }
  }
  cout << sum << endl;
}
   


Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<int> P(N), idx(N);
	for (int i = 0; i < N; i++) cin >> P[i];
	for (int i = 0; i < N; i++) idx[P[i] - 1] = i;

	multiset<lint> st;
	st.emplace(-1), st.emplace(-1);
	st.emplace(N), st.emplace(N); // 番兵
	lint ans = 0;
	for (int i = N - 1; i >= 0; i--) {

		auto ub1 = st.lower_bound(idx[i]);
		auto ub2 = ++st.lower_bound(idx[i]);
		auto lb1 = --st.upper_bound(idx[i]);
		auto lb2 = ----st.upper_bound(idx[i]);

		ans += (idx[i] - *lb1) * (*ub2 - *ub1) * P[idx[i]];
		ans += (*ub1 - idx[i]) * (*lb1 - *lb2) * P[idx[i]];
		st.emplace(idx[i]);

	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <sstream>
using namespace std;
#define p 1000000 

int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);


	while(1){
		long long int n,tmp[3],cnt = 0;
		vector<long long int> number;
		vector<long long int> sales;
		vector<long long int> flg;
		cin >> n;
		if(n == 0) break;
		for(int i=0; i<4000; i++) {
			sales.push_back(0); 
			flg.push_back(0);
		}
		for(int i=0; i<n; i++) {
			cin >> tmp[0] >> tmp[1] >> tmp[2];
			sales.at(tmp[0]) += tmp[1]*tmp[2];
			if(flg.at(tmp[0]) == 1) continue;
			number.push_back(tmp[0]);
			flg.at(tmp[0]) = 1;
		}
		for(int i=0; i<number.size(); i++) {
			if(sales.at(number.at(i)) >= p) {
				cout << number.at(i) << endl;
				cnt++;
			}
		}
		if(cnt == 0) {
			cout << "NA" << endl;
		} 
	}

	//while(1){}
	return 0;
}

Measured memory_bytes: 1300
#include <stdio.h>

int main(void) {
	// bubble sort 
	int i, j, temp;
	int arr[3]={0,};
	
	scanf("%d %d %d", &arr[0], &arr[1], &arr[2]);
	
	    for (i = 0; i < 2; i++) {
        for (j = 2; j > i; j--) {
            if (arr[j - 1] > arr[j]){
                temp = arr[j];        
                arr[j] = arr[j - 1];
                arr[j - 1]= temp;}
            }
        }
        
    printf("%d %d %d\n", arr[0], arr[1], arr[2]);    
        
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
int main() {
	int n,ans = 1 ;string s;cin >> n >> s;
	char c = s[0];
	for(int i = 1; i < n;i++) {
		if (s[i] != c) {
			ans++;c = s[i];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <set>
using namespace std;
struct hash {
    vector<string> vec;
    int add(string s) {
        for (int i=0; i<vec.size(); i++) if (vec[i]==s) return i;
        vec.push_back(s);
        return vec.size()-1;
    }
    string find(int num) {
        return vec[num];
    }
};
struct tree {
    vector<int> G[10000];
    set<int> child;
    int used[10000];
    tree() { memset(used,0,sizeof(used)); }
    void solve(int x) {
        if (used[x]==1) return;
        if (G[x].size()==0) {
            child.insert(x);
            return;
        }
        used[x]=1;
        for (int i=0; i<G[x].size(); i++) {
            solve(G[x][i]);
        }
    }
};    
int main() {
    int n;
    while (scanf("%d",&n)) {
        if (n==0) break;
        hash h; tree t;
        for (int i=0; i<n; i++) {
            string s; cin>>s;
            string temp="";
            int root, leaf;
            for (int j=0; j<s.length(); j++) {
                if (s[j]==':') {
                    root=h.add(temp);
                    temp="";
                } else if (s[j]==','||s[j]=='.') {
                    leaf=h.add(temp);
                    t.G[root].push_back(leaf);
                    temp="";
                } else {
                    temp+=s[j];
                }
            }
        }
        t.solve(0);
        // for (int i=0; i<h.vec.size(); i++) {
            // cout<<h.find(i)<<"---"<<<endl;
            // for (int j=0; j<t.G[i].size(); j++) {
                // cout<<h.find(t.G[i][j])<<" ";
            // }
            // cout<<endl;
        // }
        printf("%d\n",t.child.size());
    }
}

Measured memory_bytes: 1188
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> H >> W;
	vector< vector< int > > A(H, vector< int >(W));
	vector< pair< pii, pii > > ans;
	rep(i, H) rep(j, W) cin >> A[i][j];
	rep(i, H) rep(j, W) {
		if (A[i][j] % 2 == 0)
			continue;
		if (j < W - 1 && A[i][j + 1] % 2 == 1) {
			ans.emplace_back(pii(i + 1, j + 1), pii(i + 1, j + 2));
			A[i][j + 1]++;
		} else if (i < H - 1 && A[i + 1][j] % 2 == 1) {
			ans.emplace_back(pii(i + 1, j + 1), pii(i + 2, j + 1));
			A[i + 1][j]++;
		} else {
			if (j < W - 1) {
				ans.emplace_back(pii(i + 1, j + 1), pii(i + 1, j + 2));
				A[i][j + 1]++;
			} else if (i < H - 1) {
				ans.emplace_back(pii(i + 1, j + 1), pii(i + 2, j + 1));
				A[i + 1][j]++;
			}
		}
	}
	cout << ans.size() << endl;
	rep(i, ans.size()) {
		cout << ans[i].first.first << " " << ans[i].first.second << " " << ans[i].second.first << " " << ans[i].second.second << endl;
	}
	return 0;
}

Measured memory_bytes: 8432
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n,maxi=0;
   long long sum=0;
   scanf("%d",&n);
   for(int i=1;i<=n;i++)
   {
       int val;
       scanf("%d",&val);
       sum+=val;
       if(val>maxi)maxi=val;
   }
   cout<<sum-(maxi/2)<<"\n";
}


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

using namespace std;

// char transStr(){

// }
int ctoi(char c){
  int num;
  num = c - 48;
  return num;
}

int main(){
  string s;
  vector<string> data;
  while(1){
    cin >> s;
    if(s == "0") break;
    data.push_back(s);
  }
  int sum = 0;
  for(vector<string>::size_type i = 0; i < data.size(); i++){
    sum = 0;
    for(string::size_type j = 0; j < data[i].length(); j++){
      sum += ctoi(data[i][j]);
    }
    cout << sum << endl;
  }


  return 0;
}



Measured memory_bytes: 3176
/*...................bismillahir rahmanir rahim.....................*/
/*
  author :
    Muhammad Najmul hasan Nayeem
    Sust Math 17
*/
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// using namespace __gnu_pbds;
 
using namespace std;

#define m_p make_pair
#define PB push_back
#define eb emplace_back
#define FF first
#define SS second
#define MX5 100005
#define MX6 1000006
#define MOD 1000000007
#define in()({int a;scanf("%d",&a);a;})
#define SI(a) scanf("%d",&a)
#define SII(a,b) scanf("%d%d",&a,&b)
#define SIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define SC()({char a;scanf("%c",&a);a;})
#define SL()({long long a;scanf("%lld",&a);a;})
#define SD()({double a;scanf("%f",&a);a;})
#define nl '\n'
#define For(_,n) for(int i=_;i<=n;i++)
#define once "once upon a time\n"
#define FI freopen("input.txt","r+",stdin);
#define FO freopen("output.txt","w+",stdout);
 
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<string,string> PSS;
// typedef tree<PII,null_type,less<PII>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
    return out << "(" << a.FF << ", " << a.SS << ")";
}
 
template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
    out << "[";
    for(int i=0;i<v.size();i++) {
        if(i) out << ", ";
        out << v[i];
    }
    return out << "]";
}
 
#define chk(a) cout<<(#a)<<" = "<<a<<endl;
#define chka(a,_) cout<<(#a)<<"["<<_<<"] = "<<a[_]<<"\n";

// int Set(int n,int pos){ return n | (1<<pos); }
// int Reset(int n,int pos){ return n=n & ~(1<<pos); }
// bool Check(int n,int pos){ return (bool)(n & (1<<pos)); }
 
/*............start.............*/

void solve()
{
    string s;
    cin>>s;
    int res=0;
    for(auto i: s)
    {
        res+=(int )(i-'0');
        if(res>=9) res-=9; 
    }
    if(res) cout<<"No\n";
    else cout<<"Yes\n";
}
int main()
{
    // clock_t time_start=clock();
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int q=1;
    // cin>>q;
    // SI(q);
    for(int kase=1;kase<=q;kase++)
    {
        // cout<<"Case "<<kase<<": ";
        // printf("Case %d: ",kase );
        solve();
    }
    // clock_t time_end=clock();
    // cerr<<float((time_end-time_start)/CLOCKS_PER_SEC);
    return 0;
}


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

int main(){
  int n;
  cin >>n;
  int ans = 0;
  for(int i = 1;;i++){
    if(i*i>n) break;
    ans = i*i;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001



int main() {
    ll H, W, N; cin >> H >> W >> N;
    map<PII, ll> M;
    
    for(int i=0; i<N; i++){
        int a, b; cin >> a >> b;
        a--;
        b--;
        for(int y=-2; y<=0; y++){
            for(int x=-2; x<=0; x++){
                int ny = a + y;
                int nx = b + x;
                
                bool f = false;
                for(int j=0; j<3; j+=2){
                    for(int k=0; k<3; k+=2){
                        if(ny+j<0 || ny+j>=H || nx<0 || nx+k>=W) f = true;
                    }
                }
                if(f) continue;

                M[{ny, nx}]++;
            }
        }
    }
    
    
    
    vector<ll> ret(10);
    ret[0] = (H-2)*(W-2) - M.size();
    
    for(auto V:M){
        ret[V.sc]++;
    }
    
    
    for(int i=0; i<10; i++){
        cout << ret[i] << endl;
    }
    
    return 0;
    
}





Measured memory_bytes: 56448
#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt=0,ans=0,a[ohara],b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
      
    cin>>n;
    rep(i,3*n)cin>>a[i];
    sort(a,a+3*n);
    reverse(a,a+3*n);
    rrep(i,1,3*n){
        ans+=a[i];
        cnt++;
        i++;
        if(cnt==n)break;
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#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##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

ll mpow(ll x, ll n, ll mod) { ll y = 1; for (; n; n /= 2) { y = n % 2 ? y * x % mod : y; x = x * x % mod; } return y; }

int main() {
    string S;
    cin >> S;

    int N = S.size();
    reverse(all(S));
    vector<int> r(N + 1);
    rep(i, N) {
        r[i + 1] = (r[i] + (S[i] - '0') * mpow(10, i, 2019)) % 2019;
    }
    ll ans = 0;
    map<int, int> mp;
    mp[0] = 1;
    rep(i, 1, N + 1) {
        ans += mp[r[i]];
        mp[r[i]]++;
    }
    //vector<int> r(N + 1);
    //rep()
    write(ans);
}

Measured memory_bytes: 4276