akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	long long n, i, j, k, m, a, b, c, x;
	string s, t, ss;
	cin >> s >> t;
	ss = s + s;
	n = s.length();
	vector<vector<int>> next(n + n + 1, vector<int>(26, -1));
	for (i = n + n - 1; i >= 0; i--) {
		next[i] = next[i + 1];
		next[i][ss[i] - 'a'] = i;
	}

	set<char> sc;
	for (auto ch : s) sc.insert(ch);

	bool valid = true;
	for (auto ch : t) {
		if (sc.find(ch) == sc.end()) valid = false;
	}

	if (!valid) cout << "-1\n";
	else {
		x = 0; a = 0;
		for (auto ch : t) {
			b = next[a][ch - 'a'];
			x += b - a + 1;
			a = x % n;
		}
		cout << x << "\n";
	}


	return 0;
}


Measured memory_bytes: 27264
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD1 1000000007
#define MOD2 998244353
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ll t;cin>>t;while(t--)
#define pb push_back
#define ff first    
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define ovp(a,n) for(ll i=0;i<n;i++)cout<<a[i].ff<<" "<<a[i].ss<<endl;
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<ll,ll> pii;
ll powe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m,ll MOD){if(m==0)return 1;ll t=mpowe(n,m/2,MOD);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}
int main()
{
    fastio();
   
    int n;
    cin>>n;
    ll sum=0;
    for(ll i=1;i<=n;i++)
    {
        if(i%3==0 || i%5==0)
        {

        }
        else
        {
            sum+=i;
        }
    }
    cout<<sum<<endl;

}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
static const long long MOD = 1000000000+7;

bool check(vector<long long> & v, int x) {
  for (int i=1; i<v.size(); i++) {
    if (v.at(i) < x) return false;
  }
  return true;
}




int main() {
  int n,m,x;
  cin >> n >> m >> x;
  vector<vector<int>> v(n, vector<int>(m+1));
  for (auto & r:v) {
    for (auto & c:r) {
      cin >> c;
    }
  }

  long long ans=-1;
  for (int i = pow(2,n)-1; i>=0; i--) {
    vector<long long> skil(m+1,0);
    int bit =i;
    // cout << bit << endl;
    for (int j=n-1; j>=0; j--) {
      if (bit & 1) {
        // cout << " " << bit << endl;
        for (int k=0; k<m+1; k++) {
          skil.at(k) += v.at(j).at(k);
        }
      }
      bit = bit>>1;
    }
    // cout << skil.at(0) << endl;
    if (check(skil,x)) {
      if (ans == -1) ans = skil.at(0);
      else ans = min(ans,skil.at(0));
    }
  }

  cout << ans << endl;


}

Measured memory_bytes: 4112
#include<iostream>
#include<string>

using namespace std;

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

int main(){
    long int mod = 1000000007;
    string s;
    cin >> s;
    int k = s.size();
    long int dp[k][13];
    rep(i, k)rep(j, 13) dp[i][j] = 0;
    if (s[0] == '?') {
        rep(i, 10)dp[0][i] = 1;
    }else{
        int num = s[0] - '0';
        dp[0][num] = 1;
    }
    int num = 1;
    for(int i = 1; i < k; i++){
        if (s[i] == '?') {
            rep(j, 10){
                rep(l, 13){
                    long int m = (l * 10 + j) % 13;
                    dp[i][m] += dp[i-1][l];
                    dp[i][m] %= mod;
                }
            }
        }else{
            long int j = s[i] - '0';
            rep(l, 13){
                long int m = (l * 10 + j) % 13;
                dp[i][m] += dp[i-1][l];
                dp[i][m] %= mod;
            }
        }
    }
    cout << dp[k-1][5] << endl;
    
    
}

Measured memory_bytes: 10624
import collections

N = int(input())

S = [0] * N

for i in range(N):
    S[i] = input()

c= collections.Counter(S)

mc = c.most_common()
mxf = mc[0][1]

ans = []
for i in range(len(c)):
    if(mc[i][1] == mxf):
        ans.append(mc[i][0])

ans.sort()
for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 47656
import java.util.Scanner;
public class Main { 
    public static void main(String[] args) { 
	Scanner scn = new Scanner(System.in);
        int n = scn.nextInt();
        double[]a = new double[n];
        double reci = 0;
        for(int i = 0; i < n; i++){
            a[i] = scn.nextDouble();
            reci += (1/a[i]);
        }
        System.out.println(1/reci);
    }
} 


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

ll g(ll x) {
    if(x == 0) return 1;
    int ret = 0;
    while(x > 0) {
        ret++;
        x /= 10;
    }
    return ret;
}
ll f(ll a, ll b) {
    return max(g(a), g(b));
}

int main(){
    ll n;
    cin >> n;
    ll ans = INF;
    REP(i, 1, sqrt(n)+10) {
        if(n % i != 0) continue;
        chmin(ans, f(i, n / i));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

#define int long long

int n,s,m,ans,cnt,tot,nxt[1000000],pos;
bool v[1000000];
vector<int> sum;

signed main(){
	read(n,s,m);
	sum.push_back(0);
	for(int i=s;!v[i];i=i*i%m) nxt[i]=i*i%m,v[i]=1,cnt++,sum.push_back(sum.back()+i),pos=i*i%m;
	tot=cnt;
	for(int i=s;i!=pos;i=nxt[i]) cnt--;
	ans=sum[min(tot-cnt,n)];
	if(n>tot-cnt){
		n-=tot-cnt;
		ans+=(sum[tot]-sum[tot-cnt])*(n/cnt)+sum[n%cnt+tot-cnt]-sum[tot-cnt];
	}
	write(ans);
}

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

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

int main(void){
	int n, i;
	int a[200000];
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d", a+i);
	}
	qsort(a, n, sizeof(int), comp);
	for(i=1; i<n; i++){
		if(a[i]==a[i-1]) break;
	}
	puts(i==n?"YES":"NO");
}


Measured memory_bytes: 1788
N = int(input())
W = [input() for _ in range(N)]

if len(set(W)) != N:
    print('No')
    exit()

tail = W[0][-1]
for w in W[1:]:
    if w[0] != tail:
        print('No')
        exit()

    tail = w[-1]

print('Yes')


Measured memory_bytes: 2940
/*input
13 21 106
.....................
.####.####.####.####.
..#.#..#.#.#....#....
..#.#..#.#.#....#....
..#.#..#.#.#....#....
.####.####.####.####.
.....................
.####.####.####.####.
....#.#..#....#.#..#.
.####.#..#.####.#..#.
.#....#..#.#....#..#.
.####.####.####.####.
.....................
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back

#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)

#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int raise(int a,int n,int m = MOD){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= raise(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int floor1(int n,int k){
    if(n%k == 0 || n >= 0)return n/k;
    return (n/k)-1;
}

int ceil1(int n,int k){
    return floor1(n+k-1,k);
}

const int N = 301;
bool a[N][N];
int what[N][N];
int n,m,k;

void solve(){
  	cin >> n >> m >> k;
  	RE(i,n){
  		RE(j,m){
  			char o;cin >> o;
  			a[i][j] = (o == '#');
  		}
  	}
  	int cur = 0;
  	int first = 0;
  	RE(i,n){
  		RE(j,m){
  			if(a[i][j]){
  				first = i;
  				break;
  			}
  		}
  		if(first)break;
  	}
  	first--;
  	for(int i = first;i <= n;i++){
  		int cnt = 0;
  		int lst =0 ;
  		RE(j,m){
  			cnt += a[i][j];
  			if(a[i][j])lst = j;
  		}
  		if(!cnt){
  			RE(j,m){
  				what[i][j] = what[i-1][j];
  			}
  			continue;
  		}
  		cur++;
  		RE(j,m){
  			if(a[i][j]){
  				what[i][j] = cur;
  				if(lst > j)cur++;
  			}
  			else{
  				what[i][j] = cur;
  			}
  		}
  	}
  	RE(i,first){
  		RE(j,m){
  			what[i][j] = what[first+1][j];
  		}
  	}
  	RE(i,n){
  		RE(j,m)cout << what[i][j] << " ";
  		cout << endl;
  	}
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
  return 0;
}

Measured memory_bytes: 1536
package main

import (
        "fmt"
)

func solution(n int) int {

        memo := make(map[int]int, 86)
        var rec func(n int) int

        rec = func(n int) int {
                if n == 0 {
                        return 2
                }

                if n == 1 {
                        return 1
                }
                out, ok := memo[n]
                if !ok {
                        out = rec(n-1) + rec(n-2)
                        memo[n] = out
                }
                return out
        }
        return rec(n)
}

func main() {
        var n int
        fmt.Scan(&n)
        fmt.Println(solution(n))
}

Measured memory_bytes: 512
#
import sys
from collections import deque

def input(): return sys.stdin.readline().strip()

def main():
    n = int(input())
    agrid = []
    agrid_pointer = [0] * n

    for i in range(n):
        al = list(map(int, input().split()))
        for j in range(len(al)):
            al[j] -= 1
        agrid.append(al)

    ans = 0

    def find_next(idx, q, m):
        if agrid_pointer[idx] == n - 1 or i in m:  # もう全部対戦済み or この日対戦済み
            return

        target = agrid[idx][agrid_pointer[idx]]
        if agrid_pointer[target] == n - 1 or target in m:  # もう全部対戦済み or この日対戦済み
            return

        if agrid[target][agrid_pointer[target]] != idx:
            return

        q.append((idx, target))
        m.add(idx)
        m.add(target)

    que = deque()
    first_matching = set()
    for i in range(n):
        find_next(i, que, first_matching)

    while que:
        ans += 1

        changed = []
        while que:
            i, j = que.popleft()
            agrid_pointer[i] += 1
            agrid_pointer[j] += 1
            changed.append(i)
            changed.append(j)

        next_que = deque()
        match = set()
        for i in changed:
            find_next(i, next_que, match)

        # print(match)
        que = next_que

    # print(aconditions)
    # 対戦が残ってたら
    for p in agrid_pointer:
        if p != n - 1:
            print(-1)
            return
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 57692
def main():
    in1 = input().split(" ")
    n, m = [int(c) for c in in1]

    arr = []
    for i in range(m):
        _in = input().split(" ")
        a, b = [int(c) for c in _in]
        arr.append((a, b))

    sorted_arr = sorted(arr, key=lambda x: x[0])

    n = 1

    mi, ma = sorted_arr[0]
    mi, ma = (mi, ma) if mi < ma else (ma, mi)
    for a, b in sorted_arr[1:]:
        a, b = (a, b) if a < b else (b, a)
        if ma <= a:
            n += 1
            mi, ma = a, b
        if mi < a:
            mi = a
        if ma > b:
            ma = b
    print(n)

if __name__ == "__main__":
    main()


Measured memory_bytes: 19020
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
typedef long long LL;
const int N=1e5+100;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int fa[N];bool odd[N],two[N],d[N];
inline int find(int x) {
	if (fa[x]==x) return x;
	find(fa[x]);
	d[x]^=d[fa[x]];
	return fa[x]=fa[fa[x]];
}
int main()
{
	int n=gi(),m=gi(),i,a,b;
	for (i=1;i<=n;i++) fa[i]=i;
	while (m--) {
		a=gi(),b=gi();
		if (find(a)!=find(b)) {
			two[a]=true;
			odd[fa[a]]|=odd[fa[b]];
			d[fa[b]]=d[b]^1;
			fa[fa[b]]=a;
		} else odd[fa[a]]|=d[a]^d[b]^1;
	}
	int A=0,B=0,C=0;
	for (i=1;i<=n;i++)
		if (fa[i]==i)
			(two[i]?(odd[i]?A:B):C)++;
	cout<<1LL*C*C+2LL*C*(n-C)+2LL*A*B+1LL*A*A+2LL*B*B;
	return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

const int SIZE = 1e5+100;
ll r;

int main(){
    cin >> r;
    ll ans = 3LL*r*r;
    cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
S = ["".join(sorted(input())) for i in range(N)]

hashtable = {}

for x in S:
    hashtable.setdefault(x, 0)
    hashtable[x] += 1

sumS = 0
for y in hashtable.values():
    sumS += y * (y - 1) // 2
print(sumS)


Measured memory_bytes: 19460
#include<bits/stdc++.h>
using namespace std;
int main(){
   int a,b,c,d;
   cin >> a >> b >> c >> d;
   vector<int> flgA(101,false);
   vector<int> flgB(101,false);
   for(int i=a; i<=b; i++){
       flgA[i]=true;
   }
   for(int i=c; i<=d; i++){
       flgB[i] = true;
   }
   int cnt=0;
   for(int i=0; i<101; i++){
       if(flgA[i] && flgB[i]) cnt++;
   }
   if(cnt!=0) cnt--;
   cout << cnt << endl;
}




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

int main(){
    string p, s;
    cin >> s;
    cin >> p;
    string res = "No";
    for(int i = 0; i < s.size(); i++){
        int j;
        for(j = 0; j < p.size(); j++){
            if(p[j] != s[(i+j) % s.size()]) break;
        }
        if(j == p.size()){
            res = "Yes";
            break;
        }
    }
    
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3204
fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val a = readLine()!!.split(" ").map { it.toLong() }
  val b = readLine()!!.split(" ").map { it.toLong() }
  var p = 0L
  var m = 0L
  for (i in 0 until n) {
    val d = a[i] - b[i]
    if (d >= 0) {
      p += d
    } else {
      m += (-d + 1) / 2
      p += -d % 2
    }
  }
  p -= m
  println(if (p <= 0) "Yes" else "No")
}


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

#define ll long long
using namespace std;

const int N = 16;
int n;
ll a[N][N], sum[1 << N], dp[1 << N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }
    for(int mask = 1; mask < (1 << n); mask++) {
        for(int i = 0; i < n; i++) {
            if((mask >> i) & 1) {
                for(int j = i + 1; j < n; j++) {
                    if((mask >> j) & 1) {
                        sum[mask] += a[i][j];
                    }
                }
            }
        }
    }
    for(int mask = 1; mask < (1 << n); mask++) {
        dp[mask] = LLONG_MIN;
        for(int b = mask; b > 0; b = (b - 1) & mask) {
            dp[mask] = max(dp[mask], sum[b] + dp[mask - b]);
        }
    }
    cout << dp[(1 << n) - 1] << endl;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define pb push_back
#define inf 0x3f3f3f3f
#define all(v) (v).begin() , (v).end()
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef long long   ll;

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

bool vis[10];

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


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>s;
	int n=s.size(), ans=n;
	REP(i, n-1){
		if(s[i]!=s[i+1]){
			ans=min(ans, max(i+1, n-(i+1)));
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(){
    int x, cont=0;
    scanf("%d", &x);
    if (x>=400 && x<=599)
        cont=8;
    else if(x >= 600 && x <= 799)
        cont=7;
    else if(x >= 800 && x <= 999)
        cont=6;
    else if(x >= 1000 && x <= 1199)
        cont=5;
    else if(x >= 1200 && x <= 1399)
        cont=4;
    else if(x >= 1400 && x <= 1599)
        cont=3;
    else if(x >= 1600 && x <= 1799)
        cont=2;
    else if(x >= 1800 && x <= 1999)
        cont=1;
    printf("%d\n", cont);

    return 0;
}

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

using namespace std;

int main(int argc, char const *argv[])
{
  int N, tmp;
  cin >> N;
  vector<int> W(N);
  vector<int> diff(N);
  vector<int> sum(N);
  for (int i = 0; i < N; ++i)
  {
    cin >> W[i];
    if (i == 0)
    {
      sum[i] = W[i];
    }else{
      sum[i] = W[i] + sum[i-1];
    }
  }
  for (int i = 0; i < N; ++i)
  {
    diff[i] = abs((sum[N-1] - sum[i]) - sum[i]);
  }
  sort(diff.begin(), diff.end());
  cout << diff[0] << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){

  double x1,y1,x2,y2,xq,yq;
  double xa,ya,xb,yb,x,y,t1,t2;
  while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf",&x1,&y1,&x2,&y2,&xq,&yq)){
    
    xa=xq-x1,ya=yq-y1;
    xb=x2-x1,yb=y2-y1;

    t1=xa*xb+ya*yb,t2=xb*xb+yb*yb;

    x=2*(x1+xb*t1/t2)-xq;
    y=2*(y1+yb*t1/t2)-yq;
    
    printf("%lf %lf\n",x,y);
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<cstring>
using namespace std;

int main()
{
	string in;
	getline(cin,in);

	for(int i=0;i<in.size();i++)
	{
		if(islower(in[i])) in[i]=toupper(in[i]);
	}
	cout<<in<<endl;
	return 0;
}

Measured memory_bytes: 1176
#include<stdio.h>
int main (void){
int num,i,count,sum;
char number[1001];
char*str;
while(1){
	scanf("%s",number);
	i = 0;
	sum= 0;
	str = &number;
	count = (int)strlen(str);
	if(number[0]=='0'){
		if(count == 1){
			break;
		}
	}
	while(i<count){
		num = number[i]-'0';
		sum = sum +num;
		i++;
	}
	printf("%d\n",sum);
}
return 0;
}

Measured memory_bytes: 536
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		String s = sc.next();
		sc.close();

		for(int i=0; i<n; i++) {
			if(i+1==k) {
				System.out.print(Character.toLowerCase(s.charAt(i)));
			}else {
				System.out.print(s.charAt(i));
			}
		}

	}

}


Measured memory_bytes: 21588
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;cin>>s;
  cout << ((s[0]=='1')+(s[1]=='1')+(s[2]=='1'))<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <string>
using namespace std;
vector<long long> p(51);
vector<long long> b(51);
vector<long long> l(51);
long long Count(int N, long long X) {
	if (N == 0) return 1;
	if (X <= N) {
		return 0;
	}
	else if (X <= l[N] / 2) {
		return Count(N - 1, X - 1);
	}
	else if (X <= l[N] / 2 + 2)
		return p[N - 1] + 1;
	else if (X < l[N] - N) {
		return p[N - 1] + 1 + Count(N - 1, X - l[N]/2 - 1);
	}		
	else
		return p[N];
}

int main() {
	long long N, X;
	cin >> N >> X;
	long long cnt = 0;
	int i = 0;
	
	p[0] = 1;
	b[0] = 0;
	l[0] = 1;
	for (int i = 1; i < N + 1; i++) {
		p[i] = p[i - 1] * 2 + 1;
		b[i] = b[i - 1] * 2 + 2;
		l[i] = l[i - 1] * 2 + 3;
	}
	cout << Count(N, X);
	return 0;
}

Measured memory_bytes: 256
/*
 * ALDS1_6_C.cpp
 *
 *  Created on: Apr 30, 2018
 *      Author: 13743
 */

#include<iostream>
#include<algorithm>

struct Card {
	char c;
	int x;
};

void merge(Card* A, int l, int mid, int r) {
	int n1 = mid - l;
	int n2 = r - mid;
	Card L[n1+1];
	Card R[n2+1];
	for(int i=0; i<n1; i++) {
		L[i] = A[l + i];
	}
	for(int i=0; i<n2; i++) {
		R[i] = A[mid + i];
	}
	L[n1].x = 1000000001;
	R[n2].x = 1000000001;
	int lj = 0;
	int rj = 0;
	for(int i=0; l+i<r; i++) {
		if(L[lj].x <= R[rj].x) {
			A[l+i] = L[lj];
			lj++;
		}
		else {
			A[l+i] = R[rj];
			rj++;
		}
	}
}

void mergeSort(Card* A, int l, int r) {
	if(l+1 < r) {
		int mid = (l + r) / 2;
		mergeSort(A, l, mid);
		mergeSort(A, mid, r);
		merge(A, l, mid, r);
	}
}

int partition(Card* A, int l, int r) {
	int x = A[r].x;
	int i = l - 1;
	for(int j=l; j<r; j++) {
		if(A[j].x <= x) {
			i++;
			std::swap(A[i], A[j]);
		}
	}
	std::swap(A[i+1], A[r]);
	return i+1;
}

void quickSort(Card* A, int p, int r) {
	if(p < r) {
		int q = partition(A, p, r);
		quickSort(A, p, q-1);
		quickSort(A, q+1, r);
	}
}

int main() {
	int n;
	Card A[100000];
	Card B[100000];

	std::cin >> n;
	for(int i=0; i<n; i++) {
		std::cin >> A[i].c >> A[i].x;
		B[i] = A[i];
	}

	mergeSort(A, 0, n);
	quickSort(B, 0, n-1);

	for(int i=0; i<n; i++) {
		if(A[i].c != B[i].c) {
			std::cout << "Not stable" << std::endl;
			break;
		}
		if(i == n-1) {
			std::cout << "Stable" << std::endl;
		}
	}
	for(int i=0; i<n; i++) {
		std::cout << B[i].c << " " << B[i].x << std::endl;
	}
}





Measured memory_bytes: 5340
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#define N 100005
using namespace std;
 
int n, m, q, b1[N], b2[N], b3[N], c[N], d[N];
vector<int> a[N];
 
void f(int p, int q, int r) {
	int i;
	if (q <= d[p]) return;
	d[p] = q;
	if (!c[p]) c[p] = r;
	for (i = 0; i < a[p].size(); i++) f(a[p][i], q - 1, r);
}
 
int main()
{
	int i, t1, t2;
	cin >> n >> m;
	memset(d, -1, sizeof(d));
	for (i = 0; i < m; i++) {
		scanf("%d %d", &t1, &t2);
		a[t1].push_back(t2);
		a[t2].push_back(t1);
	}
	cin >> q;
	for (i = 0; i < q; i++) scanf("%d %d %d", &b1[i], &b2[i], &b3[i]);
	for (i = q - 1; i >= 0; i--) {
		f(b1[i], b2[i], b3[i]);
	}
	for (i = 1; i <= n; i++) printf("%d\n", c[i]);
    return 0;
}

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

void fnInput(vector<vector<int>>& rvvnAdjcy)
{
  int nxSiz;
  cin >> nxSiz;

  rvvnAdjcy.resize(nxSiz + 1, vector<int>(nxSiz + 1, 0));
  for (int i = 0; i < nxSiz; i++)
  {
    int nx, nySiz;
    cin >> nx >> nySiz;
    for (int j = 0; j < nySiz; j++)
    {
      int ny;
      cin >> ny;
      rvvnAdjcy[nx][ny] = 1;
    }
  }
}

void fnResult(const vector<vector<int>>& cnrvvnAdjcy)
{
  for (int i = 1; i < cnrvvnAdjcy.size(); i++)
  {
    for (int j = 1; j < cnrvvnAdjcy[i].size(); j++)
    {
      if (j != 1) cout << " ";
      cout << cnrvvnAdjcy[i][j];
    }
    cout << endl;
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<vector<int>> vvnAdjcy;

  fnInput(vvnAdjcy);
  fnResult(vvnAdjcy);

  return 0;
}

Measured memory_bytes: 3192
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <random>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
typedef pair<int, int> P;
#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 EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)
#define ALL(a) ((a).begin(), (a).end())

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}

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

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

    //cout << fixed << setprecision(15);

    int L;
    cin >> L;

    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if (A % C == 0 && B % D == 0)
    {
        cout << L - max(A / C, B / D) << endl;
    }
    else if (A % C == 0)
    {
        cout << L - max(A / C, (B + D) / D) << endl;
    }
    else if (B % D == 0)
    {
        cout << L - max((A + C) / C, B % D) << endl;
    }
    else
    {
        cout << L - max((A + C) / C, (B + D) / D) << endl;
    }

    return 0;
}



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

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

    int n, m;
    cin >> n >> m;
    vector<int> A(m, 0);
    
    for(int i = 0; i < n; i++){
        int k;
        cin >> k;
        for(int j = 0; j < k; j++){
            int a;
            cin >> a;
            A[a - 1]++;
        }
    }

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

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from pprint import pprint as pp
from pprint import pformat as pf

import math


if __name__ == '__main__':
    x = int(input())
    money = 100
    count = 0
    while not (money >= x):
        money = math.floor(money * 101 / 100)
        count += 1
    print(count)


Measured memory_bytes: 75052
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
  int a,b;
  cin >> a >> b;
  
  if(a >= b+1) 
    cout << a+a-1 << endl;
  else if(a == b)
    cout << a+b << endl;
  else if(b >= a+1)
    cout << b+b-1 << endl;
}

Measured memory_bytes: 3556
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define debug int debug = 0;
#define RREP(i,a) for(int i=a-1;i>=0;i--)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 1000000007; //10^9+7

int n, m;
ll x[1002], y[1002], z[1002];

ll cal(bool i, bool j, bool k){
    ll cnt = 0;
    vector<ll> v;
    REP(o, n){
        cnt = 0;
        if(!i){
            cnt += x[o];
        }else{
            cnt -= x[o];
        }
        if(!j){
            cnt += y[o];
        }else{
            cnt -= y[o];
        }
        if(!k){
            cnt += z[o];
        }else{
            cnt -= z[o];
        }
        v.push_back(cnt);
    }
    sort(v.rbegin(), v.rend());
    ll sum = 0;
    REP(o, m){
        sum += v[o];
    }
    return sum;
}

int main() {
    cin >> n >> m;
    REP(i, n){
        cin >> x[i] >> y[i] >> z[i];
    }
    ll ans = 0;
    ans = max(ans, cal(0, 0, 0));
    ans = max(ans, cal(0, 0, 1));
    ans = max(ans, cal(0, 1, 0));
    ans = max(ans, cal(0, 1, 1));
    ans = max(ans, cal(1, 0, 0));
    ans = max(ans, cal(1, 0, 1));
    ans = max(ans, cal(1, 1, 0));
    ans = max(ans, cal(1, 1, 1));
    print(ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
 
#define ll long long
 
#define pq(name,type) priority_queue<type> name
#define vec(name,type,length,value) vector<type> name(length,value)
#define vec2(name,type,length,width,value) vector<vector<type>> name(length,vector<type>(width,value));
 
int main(){
	int N;
  cin >> N;
  vector<int> a(26,0);
  string s;
  cin >> s;
  int l = s.length();
  froop1(0,l){
   int b = s[i] - 'a';
    a.at(b)++;
  }
  
  froop1(1,N){
    cin >> s;
    int l = s.length();
    vector<int> a2(26,0);
   for(int j = 0;j < l;j++){
     int b = s[j] - 'a';
     a2.at(b)++;
   }
    for(int j = 0;j < 26;j++){
      a.at(j) = min(a.at(j),a2.at(j));
    }
  }
  string ans = "";
  froop1(0,26){
   for(int j = 0;j < a.at(i);j++){
     ans += 'a' + i;
   }
  }
  cout << ans << endl;
 
  return 0;
}

Measured memory_bytes: 3616
/*
ID: 5ak0
PROG:
LANG: C++11
*/

#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define mpr make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9 + 7;

int n;
vector <int> p, v;

pii f(vector<int> v){
	pii ret = {1, 0};
	for (int i = 1; i < v.size(); ++i)
        if (v[i] == v[i - 1])
            ret.fr = false;
	if (!ret.fr)
        return ret;
	ret.second = (v[n / 2] ^ ((n / 2) & 1));
	return ret;
}

int check(int val){
	v.clear();
	for (int i = 0; i <= n; ++i){
		int value;
		if (p[i] >= val)
            value = 1;
		else
            value = 0;
		v.pb(value);
	}
	pii ret = f(v);
	if (ret.first)
        return ret.second;

	int lp = -1;
	int rp = -1;
	for (int i = n / 2 + 1; i >= 1; --i)
        if (v[i] == v[i - 1]){
            lp = i;
            break;
        }
	for (int i = n / 2; i <= n - 1; ++i)
        if(v[i] == v[i + 1]){
            rp = i;
            break;
        }
	int addLp = 0, addRp = 0;
	if (lp == -1 || rp == -1){
		if(lp == -1)
            return v[rp];
		else
            return v[lp];
	}
	else{
		if (v[lp] == v[rp])
            return v[lp];
		for (int i = lp + 1; i <= rp; ++i)
            if(v[i] == v[lp])
                ++addLp;
            else
                --addRp;
	}
	if (lp + addLp >= n / 2)
        return v[lp];
	else
        return v[rp];
}

int main(){
    #ifndef SAKO
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
    #endif // SAKO
    ios_base::sync_with_stdio(0);


	cin >> n;
	n = n + n - 1;
	for (int i = 1; i <= n; ++i){
		int x;
		cin >> x;
		p.pb(x);
	}
	int l = 0, r = n + 1;
	while (r - l > 1){
		int m = (l + r) / 2;
		if (check(m))
            l = m;
		else
            r = m;
	}
	cout << l;
    return 0;
}


Measured memory_bytes: 2804
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int main() {
  long long int number_of_students, number_of_checkpoint, i, j, min_distance, min_distance_index, temp_distance;
  scanf("%d %d", &number_of_students, &number_of_checkpoint);
  long long int student_point_x[number_of_students];
  long long int student_point_y[number_of_students];
  long long int checkpoint_point_x[number_of_checkpoint];
  long long int checkpoint_point_y[number_of_checkpoint];
  for(i = 0; i < number_of_students; i++) {
    scanf("%lld %lld", &student_point_x[i], &student_point_y[i]);
  }
  for(i = 0; i < number_of_checkpoint; i++) {
    scanf("%lld %lld", &checkpoint_point_x[i], &checkpoint_point_y[i]);
  }
  for(i = 0; i < number_of_students; i++) {
    min_distance = INT_MAX;
    for(j = 0; j < number_of_checkpoint; j++) {
      temp_distance = abs(student_point_x[i] - checkpoint_point_x[j]) + abs(student_point_y[i] - checkpoint_point_y[j]);
      if(min_distance > temp_distance) {
        min_distance = temp_distance;
        min_distance_index = j;
      }
    }
    printf("%lld\n", min_distance_index + 1);
  }
  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;


public class Main{

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int cnt = Integer.parseInt(s.nextLine());
		int[] binaryTree = new int[cnt];
		String[] tmp = s.nextLine().split(" ");
		int[] parentKey = new int[cnt];
		int[] leftKey = new int[cnt];
		int[] rightKey = new int[cnt];
		for(int i=0 ; i<cnt ; i++) {
			binaryTree[i] = Integer.parseInt(tmp[i]);
			parentKey[i] = -2000000001;
			leftKey[i] = -2000000001;
			rightKey[i] = -2000000001;
		}
		for(int i=0 ; i<cnt ; i++) {
			//????????????
			int parentNode = (i+1)/2;
			if(parentNode!=0) {
				parentKey[i] = binaryTree[parentNode-1];
			}
			//????????????
			int leftNode = (i+1)*2;
			if(cnt>=leftNode) {
				leftKey[i] = binaryTree[leftNode-1];
			}
			//????????????
			int rightNode = (i+1)*2+1;
			if(cnt>=rightNode) {
				rightKey[i] = binaryTree[rightNode-1];
			}
		}
		for(int i=0 ; i<cnt ; i++) {
			StringBuilder sb = new StringBuilder();
			sb.append("node " + (i+1) + ": key = " + binaryTree[i] + ",");
			if(i!=0) {
				sb.append(" parent key = " + parentKey[i] + ",");
			}
			if(leftKey[i]!=-2000000001) {
				sb.append(" left key = " + leftKey[i] + ",");
			}
			if(rightKey[i]!=-2000000001) {
				sb.append(" right key = " + rightKey[i] + ",");
			}
			sb.append(" ");
			System.out.println(sb.toString());
		}
	}

}

Measured memory_bytes: 21124
#include<stdio.h>
int main(){
int n,k=0;
char s[60];
scanf("%d %d",&n,&k);
scanf("%s",s);
k=k-1;
if(s[k]=='A'){
s[k]='a';
}
else if(s[k]=='B'){
s[k]='b';
}
else s[k]='c';

printf("%s",s);
return 0;
}

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


int main(){

	string s;
	long long k;
	cin >> s >> k;
	long long length = s.size();
	char ans = '0';
	
	for(int i = 0; i < length; i++)
	{
		if(s[i] != '1'){
			ans = s[i];
			break;
		}
	}
		
	if(length >= k){
		string judge = "";
		for(int i = 0; i < k; i++)
		{
			judge += '1';
		}
		
		if(s.substr(0, k) == judge) ans = '1';
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;
typedef long long ll;
const int maxn = 1e6+10;

char s[1000000];int l = 300000,r;
int T,cnt;
int main(){
    scanf("%s",s+l);
    r = l+strlen(s+l)-1;
    cin>>T;
    while(T--){
        int op,t;char c;
        scanf("%d",&op);
        if(op == 1) ++cnt;
        else{
            scanf("%d %c",&t,&c);
            if(cnt%2 == 1){
                if(t == 1) t = 2;
                else t = 1;
            }
            if(t == 1) s[--l] = c;
            else s[++r] = c;
        }
    }
    if(cnt %2 ==  0){
        for(int i = l;i<=r;i++) putchar(s[i]);
    }else{
        for(int i = r;i>=l;i--) putchar(s[i]);
    }


    return 0;
}

Measured memory_bytes: 896
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int X = sc.nextInt();
		int Y = sc.nextInt();
		int Z = sc.nextInt();

		System.out.println(Z);
		System.out.println(X);
		System.out.println(Y);
	}

}

Measured memory_bytes: 20948
#include<cstdio>
int n;
int main(){
    scanf("%d",&n);
    if(n==1)puts("1");
    if(n==2||n==3)puts("2");
    if(n>=4&&n<8)puts("4");
    if(n>=8&&n<16)puts("8");
    if(n>=16&&n<32)puts("16");
    if(n>=32&&n<64)puts("32");
    if(n>=64)puts("64");
}

Measured memory_bytes: 128
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include<queue>

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
int gcd(int a, int b){return b ? gcd(b, a%b) : a;}


int main(){
    int x;
    cin >> x;
    for(int a = -1000; a < 1000; a++){
        for(int b = -1000; b < 1000; b++){
            if(pow(a,5)-pow(b,5) == x){
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }
}


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

int main(){
  int h,w,count;
  cin >> h >> w;
  vector<string> v(h);
  for (int i=0; i<h; i++){
    cin >> v.at(i);
  }
  
  for (int i=0; i<h; i++){
    for (int j=0; j<w; j++){
      if (v.at(i).at(j) == '.'){
        count = 0;
        for (int k=-1; k<2; k++){
          for (int l=-1; l<2; l++){
            if(i+k >= 0 && i+k < h && j+l >= 0 && j+l < w)
              if (v.at(i+k).at(j+l) == '#') count++;
          }
        }
        v.at(i).at(j) = '0' + count;
      }
    }
  }

  for (int i=0; i<h; i++){
    cout << v.at(i) << endl;
  }
}
  

Measured memory_bytes: 256
H,W=map(int,input().split())
s=[]

for i in range(H):
    a=[i for i in input()]
    s.append(a)


for i in range(H):
    for j in range(W):
        if s[i][j]=='#':
            f=0
            for x,y in [(j,i+1),(j+1,i),(j,i-1),(j-1,i)]:
                if x<0 or x>W-1 or y<0 or y>H-1:
                    continue
                if s[y][x]=='#':
                    f=1
                    break
            if f==0:
                print('No')
                exit()

print('Yes')


Measured memory_bytes: 67936
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll M = 1e18;
int si[] = {-1, 0, 1, 0};
int sj[] = {0, -1, 0, 1};

int main(){
  int a,b;
  cin >> a >> b;

  if (a+b == 15) cout << "+" << endl;
  else if (a*b == 15) cout << "*" << endl;
  else cout << "x" << endl;

  return 0;
}


Measured memory_bytes: 3600
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

using ll = long long;
using namespace std;

void solve() {
    int n, k;
    cin>>n>>k;
    vector<ll> a;
    for(int i=0;i<n;i++){
        int num;
        cin>>num;
        a.pb(abs(k-num));
    }
    ll ans  = __gcd(a[0], a[1]);
    for(int i=2;i<n;i++){
        ans = __gcd(ans, a[i]);
    }
   cout<<ans<<'\n';

}

int main() 
{
    std::ios::sync_with_stdio(false); \
        std::cin.tie(NULL);
    int test;
   test =1;;
    while (test--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 4232
//--------------------------------------------------
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2,popcnt,fma")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Ofast")
//--------------------------------------------------
#include <bits/stdc++.h>
#include <chrono>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <cassert>
#include <random>
#include <bitset>
#include <iomanip>
#include <numeric>
#include <time.h>
#include <ctime>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <stack>
#include <cstring>
//--------------------------------------------------
#define forn(i, n) for(int i = 0; i < n; i++)
#define forw(i, n) for(int i = n-1; i >= 0; --i)
#define forns(i, n, s) for(int i = s; i < n; i++)
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
//----------------------------------------------------
using namespace std;
//----------------------------------------------------
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;
typedef vector<ll> lnum;
typedef complex<ld> comp;
//----------------------------------------------------
const ll mod = 1e9 + 7, mod2 = 998244353;
const ld eps = 1e-6;
const ll inf = 1e18;
const int base = 1e9;
const ld PI = 3.1415926;
//----------------------------------------------------
//#define endl '\n';
#ifdef MY_DEBUG
void deb(ld x) { cerr << x << endl; };
#else
void deb(ld x){};
#endif
//----------------------------------------------------
//----------------------------------------------------
ll a[2*100*1000], k, n;
//----------------------------------------------------
unsigned int bitcount(ull val) { return __builtin_popcount(val) + __builtin_popcount(val >> 32); }

void local() {
    freopen("test.in", "r", stdin);
}

void remote() {
}

void read() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> k >> n;
    forn(i, n) cin >> a[i];
}


int main() {
#ifdef MY_DEBUG
    local();
#else
    remote();
#endif
    read();

    ll ans = INT32_MAX;
    forn(i, n){
        ans = min(ans, min(
                i > 0 ? k-a[i]+a[i-1] : a[n-1]-a[0],
                i < n-1 ? k-a[i+1]+a[i] :  a[n-1]-a[0]));
    }
    cout << ans << endl;

}

Measured memory_bytes: 1792
a,b,c,d=gets.split.map &:to_i
a_c = a/c
a_d = a/d
a_cd = a/(c.lcm(d))
b_c = b/c
b_d = b/d
b_cd = b/(c.lcm(d))

sum = (b_c + b_d - b_cd) - (a_c + a_d - a_cd)
sum += 1 if a % c == 0 || a % d == 0
sums = b-a+1
puts sums-sum

Measured memory_bytes: 1788
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;



#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

ll debugFlag = false;
template<typename T> void debug(T&);
template<typename T> void debug(T&, bool);
template<typename T> void debug(vector<T>&);
template<typename T> void debug(vector<T>&, bool);
template<typename T, typename U> void debug(pair<T, U>&);
template<typename T, typename U> void debug(pair<T, U>&, bool);

template<typename T>
void debug(T& obj) {
	debug(obj, true);
}

template<typename T>
void debug(T& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << obj;
	if (lnFlag) cout << endl;
}

template<typename T>
void debug(vector<T>& obj) {
	debug(obj, true);
}

template<typename T>
void debug(vector<T>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "[";
	rep(i, obj.size()) {
		if (i != 0) cout << ",";
		debug(obj[i], false);
	}
	cout << "]";
	if (lnFlag) cout << endl;
}

template<typename T, typename U>
void debug(pair<T, U>& obj) {
	debug(obj, true);
}

template<typename T, typename U>
void debug(pair<T, U>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "(";
	debug(obj.first, false);
	cout << ",";
	debug(obj.second, false);
	cout << ")";
	if (lnFlag) cout << endl;
}

void solve() {

	int N;
	cin >> N;

	rep(i, 9) {
		if (N % (i + 1) == 0 && N / (i + 1) < 10) {
			cout << "Yes";
			return;
		}
	}

	cout << "No";

}


int main(int argc, char* argv[]) {
	if (argc == 2 && string(argv[1]) == "debug") debugFlag = true;
	solve();
	return 0;
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))

ans = 0
que = [H]

while que:
    h = que.pop()
    h_min = min(h)
    ans += h_min
    h = [hi - h_min for hi in h]

    tmp = []
    for hi in h:
        if hi == 0:
            if tmp:
                que.append(tmp)
                tmp = []
        else:
            tmp.append(hi)
    else:
        if tmp:
            que.append(tmp)

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
const long long LINF=1e18;
template<typename T>
void chmin(T &a,T b){
  if(a>b)a=b;
}
template<typename T>
void chmax(T &a,T b){
  if(a<b)a=b;
}

signed main(){
  int n;cin>>n;
  vector<P> b(n);
  int mx=0;
  for(int i=0;i<n;i++){
    int x,y;cin>>x>>y;
    if(x>y)swap(x,y);
    chmax(mx,y);
    b[i]=P(x,y);
  }
  sort(b.begin(),b.end());
  int ans=LINF;
  int A=b[n-1].first-b[0].first;
  int B=LINF;
  for(int i=0;i<n;i++)chmin(B,b[i].second);
  chmin(ans,A*(mx-B));
  map<int,int> m;
  for(int i=0;i<n;i++)m[b[i].first]++;
  for(int i=0;i<n;i++){
    chmin(ans,(mx-b[0].first)*(m.rbegin()->first-m.begin()->first));
    m[b[i].second]++;
    if(--m[b[i].first]==0)m.erase(b[i].first);
  }
  chmin(ans,(mx-b[0].first)*(m.rbegin()->first-m.begin()->first));
  cout<<ans<<endl;
}


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

int main() {
    int w, a, b;
    std::cin >> w >> a >> b;

    if(b -(w+a) >= 0 || a - (w+b) >= 0) {
        if(b - (w+a) >= 0) {
            std::cout << b - (w + a) << "\n";
        } else if(a - (w+b) >= 0) {
            std::cout << a - (w + b) << "\n";
        }
    } else {
        std::cout << 0 << "\n";
    }
}

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

using namespace std;

typedef long long ll;

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

	string s;
	cin >> s;

	int cnt = 0;
	int n = s.size();
	rep(i, n){
		if(s[i] == 'o') cnt++;
	}

	if(cnt + (15 - n) >= 8){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
}


Measured memory_bytes: 256