akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main(void) {
  int i,j,k;
  int h,w,n;
  cin>>h>>w>>n;
  vi x(n),y(n);
  rep(i,n)cin>>x[i]>>y[i];

  int ans=0;

  rep(i,n-1){

    int dx=x[i+1]-x[i];
    int dy=y[i+1]-y[i];

    if(dx*dy>0){

      dx=abs(dx);
      dy=abs(dy);

      int d=min(dx,dy);

      ans+=dx+dy-d;

    }else{

      ans+=abs(dx)+abs(dy);

    }

  }

  cout<<ans<<endl;

}



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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<string> w_v(n);
  map<string, int> w_m;
  for (auto& x : w_v) {
    cin >> x;
    w_m[x]++;
  }
  string s, t;
  for (int i = 0; i < n - 1; i++) {
    s = w_v[i].back();
    t = w_v[i + 1].front();
    if (s != t || w_m[w_v[i]] > 1) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 3524
n = int(input())
h = list(map(int, input().split()))

cnt = [float('inf')]*n
cnt[0], cnt[1] = 0, abs(h[0]-h[1])
for i in range(2,n):
    cnt[i]=min(abs(h[i-1]-h[i])+cnt[i-1],abs(h[i-2]-h[i])+cnt[i-2])

print(cnt[n-1])


Measured memory_bytes: 13928
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007
//S.size()
//配列名.Length()
using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<bool> VB;
typedef unsigned long long ll;


int main(void){
	int N; cin>>N;
	int a[N],b[N]; rep(t,N)cin>>a[t];
	for(int q = 0; q < N; q++)b[q] = a[q];
	sort(b , b  + N);
	int maxnum = 0;
	int maxa = 0;
	int sub;
	sub = b[N - 2];
	for(int i = 0; i < N; i++){
		if(a[i] > maxa){
			maxnum = i;
			maxa = a[i];
		}
	}

	for(int j = 0; j < N; j++){
		if(j != maxnum)cout<<maxa<<endl;
		else cout<<sub<<endl;
	}

}


Measured memory_bytes: 3200
import numpy as np
n = int(input())
aa = np.array(list(map(int, input().split())))
bb = list(map(int, input().split()))
cc = np.array(list(map(int, input().split())))

aa.sort()
cc.sort()

cnt = 0
for b in bb:
    na = np.searchsorted(aa,b, side='left')
    nc = n - np.searchsorted(cc,b, side='right')
    cnt += na*nc
print(cnt)

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

const int N = (int)1e5 + 500;

int n;
int num[N];
int cnt[2][N];
int mx[2][2];

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

    for(int i = 0; i < 2; i++){
        fill(cnt[i], cnt[i] + N, 0);
        for(int j = i; j < n; j+=2) cnt[i][num[j]] ++;
        mx[i][0] = mx[i][1] = 0;
        //cout << cnt[i][0] << endl;
        for(int j = 1; j < N; j++){
            if(cnt[i][j] > cnt[i][mx[i][0]]){
                mx[i][1] = mx[i][0];
                mx[i][0] = j;
            }
            else if(cnt[i][j] > cnt[i][mx[i][1]]) mx[i][1] = j;
        }
    }
    if(mx[0][0] != mx[1][0]){
        cout << n - cnt[0][mx[0][0]] - cnt[1][mx[1][0]] << endl;
    }
    else{
        //cout << mx[0][0] << " " << mx[0][1] << " " << mx[1][0] << " " << mx[1][1] << endl;
        int res = 10000000;
        res = min(res, n - cnt[0][mx[0][0]] - cnt[1][mx[1][1]]);
        res = min(res, n - cnt[1][mx[1][0]] - cnt[0][mx[0][1]]);
        cout << res << endl;
    }
}

Measured memory_bytes: 1408
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

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

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


















int main(){
    ll n, m, s;
    cin >> n >> m >> s;
    using T = pair<ll, pair<ll, ll>>;
    vector<vector<T>> g(n);
    s = min(s, 2600LL);
    REP(i, m){
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        u--; v--;
        g[u].push_back({v, {a, b}});
        g[v].push_back({u, {a, b}});
    }
    vector<ll> c(n), d(n);
    REP(i, n){
        cin >> c[i] >> d[i];
        g[i].push_back({i, {-c[i], d[i]}});
    }
    vector<vector<ll>> dists(n, vector<ll>(2700, INF));
    priority_queue<T, vector<T>, greater<T>> que;
    que.push({0, {0, s}});
    while(!que.empty()){
        auto [dist, tmp] = que.top(); que.pop();
        auto [now, tip] = tmp;
        tip = min(tip, 2600LL);
        if(dists[now][tip] <= dist) continue;
        dists[now][tip] = dist;
        for(auto [next, ab] : g[now]){
            auto [a, b] = ab;
            if(tip < a) continue;
            que.push({dist + b, {next, tip - a}});
        }
    }
    for(ll t = 1; t < n; t++){
        cout << *min_element(dists[t].begin(), dists[t].end()) << endl;
    }
}

Measured memory_bytes: 16452
using System;
using System.Collections.Generic;

namespace ConsoleApp_CS
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = CIn.ReadLong();
            var a = CIn.ReadLongArray(n);
            var ans = (long)1;
            var mod = (long)1000000007;

            Array.Sort(a);
            if (a.Length > 1)
            {
                var tmp = a[1] - 2;
                for (var i = a.Length % 2; i < n; i += 2)
                {
                    if (a[i] == a[i + 1] && a[i] - tmp == 2)
                    {
                        tmp = a[i];
                        ans *= 2;
                        if (ans >= mod)
                        {
                            ans %= mod;
                        }
                    }
                    else
                    {
                        ans = 0;
                    }
                }
            }

            Console.WriteLine(ans);

        }
    }

    class CIn
    {
        private static readonly Queue<string> fieldBuffer = new Queue<string>();

        public static string Read()
        {
            if (fieldBuffer.Count == 0)
            {
                foreach (var field in Console.ReadLine().Split())
                {
                    fieldBuffer.Enqueue(field);
                }
            }
            return fieldBuffer.Dequeue();
        }

        public static int ReadInt() => int.Parse(Read());
        public static long ReadLong() => long.Parse(Read());
        public static double ReadDouble() => double.Parse(Read());

        public static string[] ReadStringArray(long n)
        {
            var array = new string[n];
            for (var i = 0; i < n; i++)
            {
                array[i] = Read();
            }
            return array;
        }

        public static int[] ReadIntArray(long n)
        {
            var array = new int[n];
            for (var i = 0; i < n; i++)
            {
                array[i] = ReadInt();
            }
            return array;
        }

        public static long[] ReadLongArray(long n)
        {
            var array = new long[n];
            for (var i = 0; i < n; i++)
            {
                array[i] = ReadLong();
            }
            return array;
        }

        public static double[] ReadDoubleArray(long n)
        {
            var array = new double[n];
            for (var i = 0; i < n; i++)
            {
                array[i] = ReadDouble();
            }
            return array;
        }
    }
}


Measured memory_bytes: 19424
#include <stdio.h>
#include <stdlib.h>

int main(void) {
  long long a, ans;
  while( 1 ) {
    ans = 0;
    scanf("%lld", &a);
    if(!a) break;
    while(a) {
      ans += a / 5;
      a /= 5;
    }
    printf("%lld\n", ans);
  }
  return 0;
}


Measured memory_bytes: 2712
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
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(){
	ll n;cin>>n;
	string c;cin>>c;
	ll cntw = 0;
	ll cntr = 0;
	for(int i = 0; i < n; i++) {
		if (c[i] == 'W'){
			cntw ++;
		}
		else{
			cntr ++;
		}
	}
	if (cntw == n){
		cout << 0 << endl;
		return 0;
	}
	ll w2 = 0;
	ll r2 =0;
	ll ans = LINF;
	for(int i = 0; i < n; i++) {
		if (c[i] == 'W'){
			w2++;
		}
		else{
			cntr--;
		}
		ans = min(ans,max(w2,cntr));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3732
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc089c
{
    class Abc089c
    {
        static void Main(string[] args) {
            var n = int.Parse(Console.ReadLine());
            double m = 0, a = 0, r = 0, c = 0, h = 0;

            for (var i = 0; i != n; ++i) {
                var name = Console.ReadLine();
                switch (name[0]) {
                case 'M': ++m; break;
                case 'A': ++a; break;
                case 'R': ++r; break;
                case 'C': ++c; break;
                case 'H': ++h; break;
                }
            }

            double ans = 0;
            ans += m * a * r;
            ans += m * a * c;
            ans += m * a * h;
            ans += m * r * c;
            ans += m * r * h;
            ans += m * c * h;
            ans += a * r * c;
            ans += a * r * h;
            ans += a * c * h;
            ans += r * c * h;

            Console.WriteLine(ans);
        }
    }
}

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

typedef  long long ll;
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//
//
#define int long long

using namespace std;

int ctoi(char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
	}
}


ll a, b, c, s, t, x, y, z;
ll A, B, C, S, T, X, Y, Z;

ll cnt;

long double pi = 3.14159265358979323846;

string N, M;

unsigned long long D;

signed main() {

	cin >> a;

	vector<int> f(a);

	REP(i, a) cin >> f[i];

	//cout << f.size() << endl;


	for (x = 0; x < a- 2; x++) {
		for (y = x + 1; y < a - 1; y++) {
			for (z = y + 1; z < a; z++) {
				if (f[x] != f[y] && f[y] != f[z] && f[x] != f[z] && f[x] + f[y] > f[z] && f[z] + f[y] > f[x] && f[x] + f[z] > f[y] ) {
					cnt++;
				}
			}
		}
	}

	cout << cnt<<endl;;

	return 0;

}


Measured memory_bytes: 3608
n=int(input())
a=[int(k) for k in input().strip().split(" ")]
ai=a[::-1]
res=0

mod=10**9+7
fact=[1]
for i in range(1,100000):
    fact+=[(i*fact[-1]%mod)]

sa=[0]
for k in a:
    sa+=[(sa[-1]+k)%mod]

def ssum(l,r):
    return (sa[r+1]-sa[l])%mod

b=[[0 for i in range(2)] for j in range(n-1)]
b[0][0]=fact[n-1]
b[0][1]=(b[0][0]*pow(2,mod-2,mod))%mod
res+=(b[0][0]*(a[-1]-a[-2]))%mod
if n>2:
    res+=(b[0][1]*(ssum(1,n-2)-ssum(0,n-3)))%mod
for j in range(2,n):
    b[j-1][0]=(b[j-2][0]*(j-1) * pow(j,mod-2,mod))%mod
    res+=(b[j-1][0]*(a[-1]-a[-j-1]))%mod
    if j<n-1:
        b[j-1][1]=(b[j-2][1]*(j-1) * pow(j+1,mod-2,mod))%mod
        res+=(b[j-1][1]*(ssum(j,n-2)-ssum(0,n-j-2)))%mod

print(res%mod)

Measured memory_bytes: 93012
#include <bits/stdc++.h>
#define base 1000000007LL
#define ll long long
#define X first
#define Y second
#define pb push_back
#define Scan(a) scanf("%I64d", &a);
#define CLR(a) memset(a,0,sizeof(a))
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORE(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)

using namespace std;

typedef pair<int, int> II;
typedef vector<II> vi;

int n, x, a[100010];

int main()
{
    ios::sync_with_stdio(0);
    //freopen("inp.txt", "r", stdin);
    cin >> n >> x;
    FOR(i,1,n) cin >> a[i];
    ll res = 0;
    FOR(i,2,n) {
        int k = a[i] + a[i-1];
        if (k <= x) continue;
        int e = k-x;
        res = res + e;
        a[i] -= e;
        if (a[i] < 0) {
            e = -a[i];
            a[i] = 0;
            a[i-1] -= e;
        }
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 640
n, x, m = list(map(int, input().split()))

p = x
seen = {}
total = 0
done = False

for i in range(min(n, m)):
    total += p

    if p in seen:
        #print(p, "already seen!")
        cycleTotal = total - seen[p][1]
        cycleLength = i - seen[p][0]
        #print("total", cycleTotal, "length", cycleLength)

        iterationsLeft = (n-(i+1))
        total += (iterationsLeft//cycleLength) * cycleTotal

        iterationsLeft %= cycleLength

        for j in range(iterationsLeft):
            p = (p**2)%m
            total += p

        print(total)
        done = True
        break
    else:
        seen[p] = (i, total)

    p = (p**2)%m

if not done:
    print(total)

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

using namespace std;

vector< vector<int> >g;

int dp[100005];

void init(int n){
	g.clear();
    for(int i = 0; i<n+4; ++i){
     vector<int>ll;
      g.push_back(ll);
    }
    memset(dp,-1,sizeof(dp));
}

int dfs(int n){
  if(dp[n]!=-1)return dp[n];
  dp[n] = 0;
  for(int i = 0; i<(int)g[n].size(); ++i){
     int nxt = g[n][i];
     int ret = dfs(nxt);
     dp[n] = max(dp[n],1+ret);
  }
  return dp[n];
}

int main(){
	int n,m;
  	int x,y;
  	cin>>n>>m;
  	init(n);
  	for(int i = 0; i<m; ++i){
    		cin>>x>>y;
      g[x].push_back(y);
    }
  	int mxx = 0;
  	for(int i = 1; i<=n; ++i){
    	mxx = max(mxx,dfs(i));
    }
  cout<<mxx<<"\n";
  return 0;
}

Measured memory_bytes: 8432
#include<iostream>
#include<queue>
using namespace std;
int main(){
	int n,q;
	cin>>n>>q;
	priority_queue<int>que[n];
	while(q--){
		int command,t;
		cin>>command>>t;
		if(command==0){
			int x;
			cin>>x;
			que[t].push(x);
		}
		else if(command==1){
			if(!que[t].empty())	
				cout<<que[t].top()<<endl;
		}

		else if(command==2){
			if(!que[t].empty())	
				que[t].pop();
		}

	}
	return 0;
}


Measured memory_bytes: 4132
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    A=sorted(LI())
    maxA = A[-1]
    ans = min(A[:-1],key = lambda x:abs((maxA/2 - x)))
    print(maxA,ans)
if __name__ == '__main__':
    main()

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

int main() {
  ll M;
  cin >> M;
  vector<ll> d(M),c(M);
  for(int i=0;i<M;i++)cin >> d[i] >> c[i];
  ll cnt=-1; ll sum=0;
  for(int i=0;i<M;i++){
    cnt+=c[i];
    ll o=d[i]*c[i];
    ll k;
    if(o%9==0){k=o/9-1;}
    else{k=o/9;}
    cnt+=k;
    sum+=o-k*9;
    if(sum>9){sum-=9; cnt++;}
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3456
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline


def prime_factorization(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


N = int(input())
c = Counter(prime_factorization(N))
counter = 0

for v in c.values():
    t = 1
    while v - t >= 0:
        counter += 1
        v -= t
        t += 1

print(counter)


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


// 素集合データ構造
struct UnionFind
{
  // par[i]：データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである
  vector<int> par;
  // sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
	  // 最初は全てのデータiがグループiに存在するものとして初期化
	  for(int i = 0; i < n; i++){
		  par[i] = i;
	  }
  }

  // データxが属する木の根を得る
  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
  }

  // 2つのデータx, yが属する木をマージする
  void unite(int x, int y) {
    // データの根ノードを得る
    x = find(x);
    y = find(y);

    // 既に同じ木に属しているならマージしない
    if (x == y) return;

    // xの木がyの木より大きくなるようにする
    if (sizes[x] < sizes[y]) swap(x, y);

    // xがyの親になるように連結する
    par[y] = x;
    sizes[x] += sizes[y];
    // sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
  }

  // 2つのデータx, yが属する木が同じならtrueを返す
  bool same(int x, int y) {
    return find(x) == find(y);
  }

  // データxが含まれる木の大きさを返す
  int size(int x) {
    return sizes[find(x)];
  }
};

long long N, M;
long long A[100005];
long long B[100005];
long long Q[100005];

int main(){
	cin >> N >> M;
	for(long long i = 0; i < M; i++){
		cin >> A[i] >> B[i];
		A[i]--;B[i]--;
	}
	UnionFind uf(N);

	long long cur = (N * (N-1))/2;
	Q[M-1] = cur;
	for(long long i = M-1; i >= 1; i--){
		if(uf.find(A[i]) != uf.find(B[i])){
		long long asize = uf.size(A[i]);
		long long bsize = uf.size(B[i]);
		uf.unite(A[i], B[i]);
		cur -= asize * bsize;
		}
		Q[i-1] = cur;
	}

	for(long long i = 0; i < M; i++){
		cout << Q[i] << endl;
	}

}


Measured memory_bytes: 4480
#include<stdio.h>
#include<string.h>

int main(void){
   int k;
   char s[100];
   char S[100];

   scanf("%d", &k);
   scanf("%s", &s);
   int x = strlen(s);

   strncpy(S, s, k);
   S[k] = '\0';

   if(x <= k){
      printf("%s\n", s);
   }else{
      printf("%s...\n", S);
   }
   return 0;
}

Measured memory_bytes: 1648
#include <algorithm>
#include <cstdio>

const int N = 2001;

int a[N], mi[N], ma[N];

int main()
{
    int n;
    scanf("%d%*d%d", &n, a);
    for (int i = 1; i <= n; ++ i) {
        scanf("%d", a + i);
    }
    for (int i = n; i >= 1; -- i) {
        mi[i] = std::abs(a[i - 1] - a[n]);
        for (int j = i; j < n; ++ j) {
            mi[i] = std::min(mi[i], ma[j + 1]);
        }
        ma[i] = std::abs(a[i - 1] - a[n]);
        for (int j = i; j < n; ++ j) {
            ma[i] = std::max(ma[i], mi[j + 1]);
        }
    }
    printf("%d\n", ma[1]);
}


Measured memory_bytes: 128
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n;cin>>n;
  VV<int> e(n,V<int>(0));

  rep(i,0,n-1){
    int x,y;cin>>x>>y;
    x--;y--;
    e[x].pb(y);
    e[y].pb(x);
  }

  stack<int> r,b;
  queue<int> q;
  V<bool> used(n,false);
  q.push(0);
  q.push(0);
  used[0]=true;

  while(q.size()){
    int now=q.front();
    q.pop();
    int dis=q.front();
    q.pop();

    if(dis%2){
      r.push(now);
    }else{
      b.push(now);
    }

    rep(i,0,siz(e[now])){
      if(used[e[now][i]])continue;

      q.push(e[now][i]);
      q.push(dis^1);
      used[e[now][i]]=true;
    }
  }
  

  V<int> num(3,n/3);
  if(n%3==1)num[1]++;
  else if(n%3==2){
    num[1]++;
    num[2]++;
  }

  V<int> ans(n);
  assert(n==siz(b)+siz(r));

  if(siz(b)<siz(r))swap(b,r);


  if(siz(b)<=num[1]+num[0]){
    ll cnt=1;
    rep(i,0,num[1]){
      ans[b.top()]=cnt;
      cnt+=3;
      b.pop();
    }

    cnt=3;
    while(b.size()){
      ans[b.top()]=cnt;
      cnt+=3;
      b.pop();
    }

    while(cnt/3<=num[0]){
      ans[r.top()]=cnt;
      cnt+=3;
      r.pop();
    }

    cnt=2;
    rep(i,0,num[2]){
      ans[r.top()]=cnt;
      cnt+=3;
      r.pop();
    }
  }else if(num[0]>=siz(r)){
    ll cnt=1;
    rep(i,0,num[1]){
      ans[b.top()]=cnt;
      cnt+=3;
      b.pop();
    }
    cnt=2;
    rep(i,0,num[2]){
      ans[b.top()]=cnt;
      cnt+=3;
      b.pop();
    }
    cnt=3;
    while(b.size()){
      ans[b.top()]=cnt;
      cnt+=3;
      b.pop();
    }

    while(cnt/3<=num[0]){
      ans[r.top()]=cnt;
      cnt+=3;
      r.pop();
    }


  }else{
    cout<<-1<<ENDL;
    return 0;
  }


  rep(i,0,n){
    cout<<ans[i]<<" ";
  }
  cout<<ENDL;

  

}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 15344
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a: isize = read();
    let b: isize = read();

    let p = a + b;
    let mi = a - b;
    let mu = a * b;
    if p > mi && p > mu {
        println!("{}", p);
    } else if mi > mu {
        println!("{}", mi);
    } else {
        println!("{}", mu);
    }
}


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

using namespace std;
using ll = long long;

ll solve(ll x, ll k) {
    if (x == 1) return (1LL << (k - 1));
    return (1LL << (k - 1)) + solve(x / 2, k + 1);
}

int main() {
   ll h; cin >> h;
    cout << solve(h, 1) << endl;
}

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

int main() {
  int N, S;
  cin >> N;
  vector<int> W(N), M(N+1,0);
  for (int i=0; i<N; i++) {
    cin >> W[i];
    S+=W[i];
    M[i+1]+=M[i]+W[i];
  }
  int m=10000000;
  for (int i=0; i<=N; i++) {
    m=min(m, abs(S-2*M[i]));
  }
  cout << m << endl;
  
}


Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		Main main = new Main();
		
	}
	
	public Main() {
		
		//Variables to use
		Scanner input = new Scanner(System.in);
		int n;
		int[] R;
		
		//Get the number of inputs
		n = input.nextInt();
		
		//Create the array of values of size n
		R = new int[n];
		
		//Fill the values in the R array from the scanner
		for(int i = 0; i < n; i++) {
			
			R[i] = input.nextInt(); 
			
		}
		
		//Print out the returned value of the maxProfit function
		System.out.println(maxProfit(n, R));
		
	}
	
	public int maxProfit(int n, int[] R) {
		
		//Set the current max profit to a very negative number
		int maximumProfit = -1000000000;
		
		//At first the minimum is set to the very first index
		int minimumProfit = R[0];
		
		//Loop through the rest
		for(int i = 1; i < n; i++) {
			
			//Get the max of the max or the current index minus the minimum
			maximumProfit = Math.max(maximumProfit, R[i] - minimumProfit);
			
			//Set the minimum profit to the minimum of the minimum profit or the current index
			minimumProfit = Math.min(minimumProfit, R[i]);
			
		}
		
		//return the max profit
		return maximumProfit;
		
	}

}



Measured memory_bytes: 70984
n = int(input())
a = list(map(int,input().split()))

c1 = 0
c2 = 0
c4 = 0
for i in range(n):
    if a[i] % 4 == 0:
        c4 += 1
    elif a[i] % 2 == 0:
        c2 += 1
    elif a[i] == 1:
        c1 += 1

n -= c2
c2 %= 2
n += c2
f = n // 2

if c4 >= f:
    print('Yes')
    quit()
else:
    print('No')


Measured memory_bytes: 62704
N,M = map(int,input().split())
H = list(map(int,input().split()))
adj=[set() for _ in range(N)]
for _ in range(M):
    a,b = map(lambda x:int(x)-1,input().split())
    adj[a].add(b)
    adj[b].add(a)


ans=0
for i in range(N):
    if len(adj[i])==0:
        ans+=1
    elif all([H[i]>H[v] for v in adj[i]]):
        ans+=1
print(ans)


Measured memory_bytes: 45312
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int N; cin >> N;
    vector<int> L;
    rep (i, 0, N) {
        int in; cin >> in;
        L.push_back(in);
    }

    int max_val = *max_element(L.begin(), L.end());
    vector<int>::iterator iter = find(L.begin(), L.end(), max_val);
    size_t index = distance(L.begin(), iter);
    L.erase(L.begin() + index);
    int sum = std::accumulate(L.begin(), L.end(), 0);
    if (max_val < sum) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val d = sc.nextInt()

  val x = Array(n) { Array(d) { 0 } }
  for (i in 0 until n) {
    for (j in 0 until d) {
      x[i][j] = sc.nextInt()
    }
  }

  var count = 0
  for (i in 0 until n) {
    val xi = x[i]
    for (j in i until n) {
      if (i == j) continue
      val xj = x[j]
      var sum = 0
      for (di in 0 until d) {
        val tmp = xi[di] - xj[di]
        sum += tmp * tmp
      }
      val sqrt = Math.sqrt(sum.toDouble()).toInt()
      if (sqrt * sqrt == sum) count++
    }
  }

  println(count)

}


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

int main() {
	int a, b;
	string op;
	int goukei = 0;
	cin >> a >> op >> b;

	if (op == "+"){
    	goukei = a + b;
	}else if (op == "-"){
    	goukei = a - b;
    }cout << goukei << endl;
}    	

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

const int32 bsrep = 1e5;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n;
  cin >> n;
  vector<double> p[6];  //0->X軸方向不変, 1->R, 2->L
  REP(i,n){
    int32 x,y;
    char d;
    cin >> x >> y >> d;
    if(d == 'R'){
      p[1].pb(x);
      p[3].pb(y);
    }else if(d == 'L'){
      p[2].pb(x);
      p[3].pb(y);
    }else if(d == 'U'){
      p[0].pb(x);
      p[4].pb(y);
    }else{
      p[0].pb(x);
      p[5].pb(y);
    }
  }
  REP(i,6){
    sort(ALL(p[i]));
    double mn = INF, mx = -INF;
    if(p[i].size()){
      mn = p[i].front();
      mx = p[i].back();
    }
    p[i] = vector<double>(2);
    p[i][0] = mn;
    p[i][1] = mx;
  }

  auto mn = [&](double t){
    return min<double>({p[0][0], p[1][0]+t, p[2][0]-t});
  };
  auto mx = [&](double t){
    return max<double>({p[0][1], p[1][1]+t, p[2][1]-t});
  };

  auto mny = [&](double t){
    return min<double>({p[3][0], p[4][0]+t, p[5][0]-t});
  };
  auto mxy = [&](double t){
    return max<double>({p[3][1], p[4][1]+t, p[5][1]-t});
  };

  vector<double> tcand;
  REP(axis,2){
    {
      double l = 0, r = INF;
      REP(_,bsrep){
        double llr = (l + l + r) / 3;
        double lrr = (l + r + r) / 3;
        if(mx(llr) < mx(lrr)){
          r = lrr;
        }else{
          l = llr;
        }
      }
      tcand.pb(l);
    }
    {
      double l = 0, r = INF;
      REP(_,bsrep){
        double llr = (l + l + r) / 3;
        double lrr = (l + r + r) / 3;
        if(mx(llr) <= mx(lrr)){
          r = lrr;
        }else{
          l = llr;
        }
      }
      tcand.pb(l);
    }
    {
      double l = 0, r = INF;
      REP(_,bsrep){
        double llr = (l + l + r) / 3;
        double lrr = (l + r + r) / 3;
        if(mn(llr) < mn(lrr)){
          l = llr;
        }else{
          r = lrr;
        }
      }
      tcand.pb(l);
    }
    {
      double l = 0, r = INF;
      REP(_,bsrep){
        double llr = (l + l + r) / 3;
        double lrr = (l + r + r) / 3;
        if(mn(llr) <= mn(lrr)){
          l = llr;
        }else{
          r = lrr;
        }
      }
      tcand.pb(l);
    }

    REP(i,3)swap(p[i],p[i+3]);
  }
  double ans = (mx(0) - mn(0)) * (mxy(0) - mny(0));
  for(auto t : tcand){
    ans =min(ans, (mx(t) - mn(t)) * (mxy(t) - mny(t)));
  }
  cout << fixed << setprecision(15);
  ANS(ans);
  return 0;
}

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

int dx[9] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
int dy[9] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
ll ret[10];

int main() {
  ll H, W, N;
  cin >> H >> W >> N;
  map<pair<ll, ll>, int> m;
  vector<ll> A(N), B(N);
  for (int i = 0; i < N; i++) {
    ll y, x;
    cin >> y >> x;
    m[make_pair(y, x)]++;
    A[i] = y, B[i] = x;
  }

  for (int k = 0; k < N; k++) {
    ll y = A[k], x = B[k];
    for (int i = 0; i < 9; i++) {
      ll cx = x + dx[i], cy = y + dy[i];
      if (1 + 1 <= cx && cx <= W - 1 && 1 + 1 <= cy && cy <= H - 1) {
        int cnt = 0;
        for (int j = 0; j < 9; j++) {
          cnt += m[make_pair(cy + dy[j], cx + dx[j])];
        }
        ret[cnt]++;
      }
    }
  }
  ret[0] = (W - 2) * (H - 2);
  for (int i = 1; i < 10; i++) {
    ret[i] = ret[i] / i;
    ret[0] -= ret[i];
  }
  for (int i = 0; i < 10; i++) {
    cout << ret[i] << endl;
  }
}

Measured memory_bytes: 158080
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>

int main(){
  int N;
  scanf("%d",&N);
  std::vector<int > h(N);
  int hmax = 0;
  for (int i=0; i<N; i++){
    scanf("%d", &h[i]);
    hmax = std::max(hmax, h[i]);
  }
  
  int ans = 0;
  bool startsw = false;
  while(hmax>0){
    startsw = false;
    for (int i=0; i<N; i++){
      //printf("h[%d]=%d\n",i,h[i]);
      if (h[i]>0){
        startsw = true;
        h[i]--;
      } else if (startsw){
        //printf("ans+= at hmax=%d, i=%d\n",hmax,i);
        ans++;
        startsw=false;
      }
    }
    if(startsw){
      ans++;
      //printf("ans+= at hmax=%d end\n",hmax);
    }
    hmax--;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 504
#include<cstdio>
#include<iostream>

using namespace std;


int main(void){

	int n;
	int inp;
	long long dp[2][21]={0};

	cin>>n;

	cin>>inp;
	dp[0][inp]=1;

	for(int i=0;i<n-2;i++){
		cin>>inp;

		for(int j=0;j<=20;j++) dp[1][j]=0;

		for(int j=0;j<=20;j++){
			if(dp[0][j]>0){
				if(j+inp<=20){
					dp[1][j+inp]+=dp[0][j];
				}
				if(j-inp>=0){
					dp[1][j-inp]+=dp[0][j];
				}
			}
		}
		for(int j=0;j<=20;j++) dp[0][j]=dp[1][j];
	}
	cin>>inp;
	cout<<dp[0][inp]<<endl;


	return 0;
}

Measured memory_bytes: 1156
n = int(input())
list_score = list(map(int, input().split()))
ans = "Yes"
max_value = 0
for i in range(n):
    if list_score[i] > max_value:
        max_value = list_score[i]
    if max_value - list_score[i] > 1:
        ans = "No"
        break

print(ans)


Measured memory_bytes: 14252
#include <iostream>
#include <math.h>

using namespace std;

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

    int n, m;
    cin >> n >> m;

    int sum=0;

    for(int i=0; i<m; i++)
    {
        int days;
        cin >> days;
        sum += days;
    }

    int days_left = n - sum;
    if (days_left >= 0)
        cout << days_left << endl;
    else
        cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
using namespace std;
int main(){
	int n,i,j,k,x,counter=0;
	while(1){
		cin>>n>>x;
		if(n==0 && x==0){
			break;
		}
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			for(k=1;k<=n;k++){
			if(i+j+k==x && i!=j && i!=k && j!=k && j!=i && k!=j && k!=i && i<j && j<k  ){
				counter++;
			}
			
		}
	}
	}
	cout<<counter<<endl;
	counter=0;
	}
	return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define ll long long int
#define inf 3e18+1
#define all(v) (v).begin(),(v).end() 
#define N 200005
#define F first 
#define S second 
using namespace std;
ll mod=1e9+7;
// ll parent[N];  
// ll size[N]; 
// ll find(ll i){
//     if(parent[i]!=i) {
//         parent[i]=find(parent[i]);
//     }
//     return parent[i];
// }
// void Union(ll x,ll y){
//     ll a=find(x);
//     ll b=find(y);
//     if(a==b) return;
//     parent[a]=parent[b];
// }
int main()
{
    // added the two lines below 
    ios_base::sync_with_stdio (false); 
    cin.tie(NULL);
    cout.tie(0);    
    ll test=1;//cin>>test;
    while(test--){
        ll n,s;
        cin>>n>>s;
        ll w[n],v[n];
        for(int i=0;i<n;i++){
            cin>>w[i]>>v[i];
        }
        ll dp[n+1][s+1];
        memset(dp,0,sizeof(dp));
        for(int i=1;i<=n;i++){
            for(int j=0;j<=s;j++){
                if(j>=w[i-1]){
                    dp[i][j]=max(dp[i-1][j],v[i-1]+dp[i-1][j-w[i-1]]);
                }
                else dp[i][j]=dp[i-1][j];
            }
        }
        cout<<dp[n][s];

        
    }
    return 0;
    
}




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

int main()
{
  int n;
  cin >> n;
  int arr[n][3];
  for (int i = 0; i < n; i++)
  {
    cin >> arr[i][0];
    cin >> arr[i][1];
    cin >> arr[i][2];
  }
  int dp[n][3];
  dp[0][0] = arr[0][0];
  dp[0][1] = arr[0][1];
  dp[0][2] = arr[0][2];
  for (int i = 1; i < n; i++)
  {
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + arr[i][0];
    dp[i][1] = max(dp[i-1][2], dp[i-1][0]) + arr[i][1];
    dp[i][2] = max(dp[i-1][1], dp[i-1][0]) + arr[i][2];
  }
  cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]))<< endl;
}


Measured memory_bytes: 5460
#include <stdio.h>
  int main(){
	  int a;
    char x[10000];
   while(scanf("%s",&x) != EOF){
    int i=0;
    int sum1=0;
    int sum2=0;
    while(x[i+2] != EOF){
     if(x[i] == 'J' && x[i+1] == 'O' && x[i+2] == 'I'){
        sum1 ++;
          }
      if(x[i] == 'I' && x[i+1] == 'O' && x[i+2] == 'I'){
        sum2 ++;
          }
	  i++;
}
	for(a=0;a<10000;a++){
		   x[a]=0;
	   }
printf("%d\n",sum1);
printf("%d\n",sum2);
}
   return 0;
  }

Measured memory_bytes: 552
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

string s;

int main(void){
    
    cin >> s;
    
    vector<vector<ll>> dp(100001, vector<ll>(4, 0));
    dp[0][0] = 1;
    for(int i = 0; i < s.size(); ++i){
        for(int j = 0; j <= 3; ++j){
            if(s[i] == '?') dp[i + 1][j] = dp[i][j] * 3 % MOD;
            else dp[i + 1][j] = dp[i][j];
        }
        if(s[i] == 'A') dp[i + 1][1] += dp[i][0], dp[i + 1][1] %= MOD;
        else if(s[i] == 'B') dp[i + 1][2] += dp[i][1], dp[i + 1][2] %= MOD;
        else if(s[i] == 'C') dp[i + 1][3] += dp[i][2], dp[i + 1][3] %= MOD;
        else {
            dp[i + 1][1] += dp[i][0], dp[i + 1][1] %= MOD;
            dp[i + 1][2] += dp[i][1], dp[i + 1][2] %= MOD;
            dp[i + 1][3] += dp[i][2], dp[i + 1][3] %= MOD;
        }
    }
    printf("%lld\n", dp[s.size()][3]);
    
    return 0;
}

Measured memory_bytes: 7424
// E

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll MOD=1e9+7;

const int MAX = (int)1e5+1;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){  //nCkの計算をする
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
	COMinit();
  ll N,K,A[100000];
  cin>>N>>K;
  for (int i(0);i<N;i++) cin>>A[i];
  ll maxi[100000] = {0},mini[100000] = {0};
  sort(A,A+N);
  for (int i(0);i<N;i++){
    if (i >= K-1 ){
      maxi[i] = COM(i,(int)K-1);
    }
    if (N-i+1 > K){
      mini[i] = COM(N-i-1,(int)K-1);
    }
  }
  ll ans(0);
  for (int i(0);i<N;i++){
    //cout << maxi[i] << " " <<mini[i] << endl;
    ans += (maxi[i]*A[i] - mini[i]*A[i]);
    ans%=MOD;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 4992
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n;
    char ans[257], str[257];
    while(cin >> n){
        cin.ignore();
        rep(i,n){
            cin.getline(str, sizeof(str));
            bool c = false;
            rep(i,26){
                rep(j,26){
                    rep(k,strlen(str)){
                        if(str[k] != ' ')
                            ans[k] = (i * str[k] - 'a' + j) % 26 + 'a';
                        else ans[k] = str[k];
                    }
                    if(strstr(ans, "this") != NULL || strstr(ans, "that") != NULL){
                        c = true;
                    }
                    if(c) break;
                }
                if(c) break;
            }
            ans[strlen(str)] = '\0';
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
const int N=1e6+7,INF=0x3f3f3f3f,sgn[]={-1,1};
char a[N];
int n,s[N],nxt[N];
int solve(int x,int cnt=0){
	int w=0;
	FOR(i,1,n){
		if(a[i]=='?'&&cnt+2+nxt[i]<=x)cnt+=2;
		w=min(w,s[i]+cnt);
	}
	return x-w;
}
int main(){
	scanf("%s",a+1),n=strlen(a+1),nxt[n+1]=-INF;
	FOR(i,1,n)s[i]=s[i-1]+sgn[a[i]=='1'];
	ROF(i,n,0)nxt[i]=max(nxt[i+1],s[i]);
	cout<<min(solve(nxt[0]),solve(nxt[0]+1));
	return 0;
}

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

int main(){
  int n, k, d, x, ans=0;
  cin >> n >> k;
  vector<int> a(n,0);
  rep(i,k){
    cin >> d;
    rep(j,d){
      cin >> x;
      x--;
      a[x]++;
    }
  }
  rep(i,n)if(a[i]==0) ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, m;
    cin >> n >> m;
    if (n * 2 >= m) {
        cout << m / 2 << "\n";
    } else {
        lint ret = n;
        m -= 2 * n;
        ret += m / 4;
        cout << ret << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
h, w = gets.strip.split.map(&:to_i)

aa = Array.new(h) { [0]*w }
targets = []

h.times do |i|
  gets.chomp.each_char.with_index do |c,j|
    next if c == '.'
    aa[i][j] = 1
    targets << [i, j]
  end
end

def blacken(h, w, aa, targets)
  next_targets = []

  targets.each do |i, j|
    if aa[i][j]==1

      y, x = [i, j+1]
      if (x<w && aa[y][x]==0)
        next_targets.push( [y, x] )
        aa[y][x]=1
      end

      y, x = [i+1, j]
      if (y<h && aa[y][x]==0)
        next_targets.push( [y, x] )
        aa[y][x]=1
      end

      y, x = [i, j-1]
      if (x>=0 && aa[y][x]==0)
        next_targets.push( [y, x] )
        aa[y][x]=1
      end

      y, x = [i-1, j]
      if (y>=0 && aa[y][x]==0)
        next_targets.push( [y, x] )
        aa[y][x]=1
      end

    end
  end

  next_targets
end

b_c = targets.length

result = 0
until b_c == h*w
  targets = blacken(h, w, aa, targets)
  b_c += targets.length
  result += 1
end

p result





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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i,N){
        ll a;
        cin >> a;
        A[i] = a;
    }

    map<ll, ll> ma;
    ll ans = 0;
    for(auto&& a : A){
        auto iter = ma.upper_bound(-a);
        if(iter != ma.end()){
            auto p = *iter;
            ll key = p.first;
            ma[key]--;
            if(ma[key] == 0)
                ma.erase(key);
        }
        ma[-a]++;
    }

    for(auto&& p : ma)
        ans += p.second;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7168
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main(){

    input!{
        v: [usize; 5],
    }

    let mut min = 10;
    let mut sum = 0;
    for i in v{
        if i%10!=0{
            min = std::cmp::min(min, i%10);
            sum += i + (10 - i%10);
        } else {
            sum += i;
        }
    }

    println!("{}", sum - (10 - min));
}

Measured memory_bytes: 4476
#include<stdio.h>
#include<string.h>

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define INT_MAX 2147483647
#define INT_MIN -2147483648

typedef long long ll;			//%ld.
typedef long long int lli;		//%lld.
typedef unsigned long long ull;	//%llu.
// int %d, double %lf ,float %f ,string %s.

void swap(int *x,int *y);
int max(int x,int y);
int min(int x,int y);
void sortSeq(int dt[],int l,int r);
void sortIns(int dt[],int l,int r);
void mergeSort(int dt[],int l,int r);
int binser(int nilai,int dt[],int l,int r);
int abs(int x);
double maxD(double x,double y);
double minD(double x,double y);

//main code

int main(){
	int a,p;
	scanf("%d %d",&a,&p);
	p+=(a*3);
	printf("%d\n",p/2);
}

















///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double maxD(double x,double y){
	return x > y ? x : y;
}
double minD(double x,double y){
	return x < y ? x : y;
}
int abs(int x){
	if(x<0)	return -x;
	return x;
}
void merge(int arr[], int aLeft , int aRight , int bLeft , int bRight){ //merge
	int size = bRight - aLeft + 1;
	int temp[size];                
	int tIndex = 0;
	int aIndex = aLeft;
	int bIndex = bLeft;
	while( (aIndex <= aRight)&&(bIndex <= bRight))
	{
		if(arr[aIndex]<=arr[bIndex])
		{
			temp[tIndex] = arr[aIndex];
			aIndex = aIndex +1;
		}
		else
		{
			temp[tIndex] = arr[bIndex];
			bIndex = bIndex + 1;
		}
		tIndex = tIndex + 1;
	}
	while(aIndex <= aRight)
	{
		temp[tIndex] = arr[aIndex];
		aIndex = aIndex + 1;
		tIndex = tIndex + 1;
	}
	while(bIndex <= bRight)
	{
		temp[tIndex] = arr[bIndex];
		bIndex = bIndex + 1;
		tIndex = tIndex + 1;
	}
	for(int i = 0 ; i<= size-1 ; i++)
	{
		arr[aLeft + i] = temp[i];
	}
}

void swap(int *a,int *b){ //swap
	int temp = *a;
	*a = *b;
	*b = temp;
}
int max(int a,int b){ //maksimum
	return a>b ? a : b;
}
int min(int a,int b){ //minimum
	return a<b ? a : b;
}
void sortSeq(int arr[],int l,int r){ //sequencial sort
	for(int i=l;i<=r-1;i++)
		for(int j=i+1;j<=r;j++)
			if(arr[j]<arr[i])
				swap(&arr[i],&arr[j]);
}
void sortIns(int h[],int l,int r){ //insertion sort
	for(int i=l;i<=r;i++){
		int pos=i;
		while((pos>1)&&(h[pos]<h[pos-1])){
			swap(&h[pos],&h[pos-1]);
			pos=pos-1;
		}
	}
}
void mergeSort(int arr[],int left,int right){ //merge sort
	if( left == right )
		return; 
	else{
		int mid = (left+right)/2;    	 
		mergeSort(arr,left,mid);	
		mergeSort(arr,mid+1,right);
		merge(arr,left,mid,mid+1,right); 
	}
}
int binser(int x,int dt[],int kiri,int kanan){ //tidak ada = -1
	int hasil = -1;
	while((kiri<=kanan)&&(hasil==0)){
		int tengah=(kiri+kanan)/2;
		if(x<dt[tengah])
			kanan=tengah-1;
		else if(x>dt[tengah])
			kiri=tengah+1;
		else
			hasil=tengah;
	}
	return hasil;
}

Measured memory_bytes: 1680
#include <iostream>
using namespace std;
int a[201]={0};
int main() {
    int x, n, b;
    cin >> x >> n;
    while (n--) {
        cin >> b;
        a[b+100]=1;
    }
    for(int d=0;;d++) {
        if (a[x+100-d]==0) {
            cout << x-d;
            return 0;
        }
        if (a[x+100+d]==0) {
            cout << x+d;
            return 0;
        }
    }
}

Measured memory_bytes: 3592