akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 300200;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
int n;
namespace tj {
	struct T {
		int to, nxt;
	} way[maxn << 5];
	int h[maxn], num, tot;
	int dfn[maxn], low[maxn], st[maxn], block[maxn], idx, top;
	int in[maxn];
	inline void link(int x,int y) {
		way[++num] = {y, h[x]}, h[x] = num;
	}
	inline void clear() {
		memset(h, 0, sizeof h);
		memset(dfn, 0, sizeof dfn);
		memset(low, 0, sizeof low);
		memset(block, 0, sizeof block);
		num = 0;
	}
	inline void dfs(int x) {
		dfn[x] = low[x] = ++ tot, st[++top] = x, in[x] = 1;
		for(int i = h[x];i;i = way[i].nxt) {
			if(!dfn[way[i].to]) {
				dfs(way[i].to);
				low[x] = std::min(low[x], low[way[i].to]);
			} else {
				if(in[way[i].to])
					low[x] = std::min(low[x], dfn[way[i].to]);
			}
		}
		if(low[x] == dfn[x]) {
			++idx;
			do block[st[top]] = idx, in[st[top]] = 0; while(st[top--] != x);
		}
	}
}
int x[maxn << 1], rk[maxn], irk[maxn];
int st[20][maxn << 1];
inline int cmp(int a,int b) {
	return x[a] < x[b];
}
inline int get(int a) {
	return *x = a, std::lower_bound(rk + 1, rk + n + n + 1, 0, cmp) - rk;
}
inline void base_link(int x,int l,int r) {
	const int lg = std::__lg(r - l);
	tj::link(st[lg][l], x);
	tj::link(st[lg][r - (1 << lg)], x);
}
inline void link(int x,int l,int r,int mid) {
	l = get(l), r = get(r + 1);
	if(l < mid) base_link(x, l, mid);
	if(mid + 1 < r) base_link(x, mid + 1, r);
}
inline bool can(int len) {
	tj::clear(); int tot = n + n;
	rep(i, 1, n + n) st[0][i] = rk[i];
	rep(i, 1, 19) for(int j = 1;j + (1 << i) - 1 <= n + n;++j) {
		st[i][j] = ++tot;
		tj::link(st[i - 1][j], st[i][j]);
		tj::link(st[i - 1][j + (1 << i - 1)], st[i][j]);
	}
	rep(i, 1, n) {
		link(i, x[i + n] - len + 1, x[i + n] + len - 1, irk[i + n]);
		link(i + n, x[i] - len + 1, x[i] + len - 1, irk[i]);
	}
	rep(i, 1, tot) if(!tj::dfn[i])
		tj::dfs(i);
	rep(i, 1, n) if(tj::block[i] == tj::block[i + n]) return 0;
	return 1;
}
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	rep(i, 1, n) {
		cin >> x[i] >> x[i + n];
	}
	rep(i, 1, n + n) rk[i] = i;
	std::sort(rk + 1, rk + n + n + 1, cmp);
	rep(i, 1, n + n) irk[rk[i]] = i;
	int l = 0, r = 1e9;
	for(;l + 1 != r;){
		int mid = l + r >> 1;
		if(can(mid)) {
			l = mid;
		} else {
			r = mid;
		}
	}
	cout << l << '\n';
}


Measured memory_bytes: 52608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Nmax=200010;
//#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//#definr REP(i,n) FOR(i,0,n)
//#define dump(x) cout << #x << "=" << (x) << endl;
//#define debug(x) cout << #x << "=" << (x) << "(L" << _LINE_ << ")" << "" << _FILE_ << endl;
//ll a[Nmax];
//int* P = new int[N];

int main() {
	ll H,a[Nmax],b[Nmax],d=0;
	int N;
	cin >> N >> H;
	for(int i=0;i < N;i++) cin >> a[i] >> b[i];
	int cnt=0;
	ll max=0;
	for(int i=0;i < N;i++) if(max < a[i]) max = a[i];
  	sort(b,b+N);
	for(int i=N-1;i >= 0;i--){
      	if(max < b[i]){
			d+=b[i];
			cnt++;
     	}
		if(d >= H){
			cout << cnt << endl;
			return 0;
		}
	}
 
	for(;;){
		d+=max;
		cnt++;
		if(d >= H){
			cout << cnt << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
int t[]={9,180,2700,36000,450000,5400000,63000000,720000000,8100000000};
int n,m;
char get2(int a,int b,int c){
  int x=pow(10,a);
  x+=b;
  string s;
  while(x)s+=(x%10)+'0',x/=10;
  reverse(s.begin(),s.end());
  return s[c];
}
char get(int x){
  int res=-1;
  while(t[res+1]<x)x-=t[res+1],res++;
  res+=2;
  x--;
  int p=x/res,c=x%res;
  return get2(res-1,p,c);
}
main(){
  while(cin>>n>>m,m){
    r(i,m)cout<<get(n+i);
    cout<<endl;
  }
}

Measured memory_bytes: 3352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d;
  cin >> a >> b;
  c = a+b;
  d = c/2;
  if(c%2>=1){
    d = d +1;
  }
  cout << d << endl;  // ここにプログラムを追記
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int (i)=(a);(i)<(int)(b);(i)++)
#define RREP(i,a,b) for(int (i)=(a);(i)>=(int)(b);(i)--)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;

int main(){
    ll n, m;
    cin >> n >> m;
    cout << min(m / 2, (m + 2 * n) / 4) << endl;
    
    return 0;
}

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

int main() {
    int t, y;
    cin >> t >> y;

    char a[t][y];
    rep(i, t) {
        rep(j, y) cin >> a[i][j];
    }

    rep(i, t) {
        rep(j, y) if(a[i][j] == '.') {
            int cnt = 0;
            rep(k, 3) {
                rep(l, 3) {
                    bool flag1 = false;
                    bool flag2 = false;
                    bool flag3 = false;
                    bool flag4 = false;
                    if(i-1+k >= 0) flag1 = true;
                    if(i-1+k <= t-1) flag2 = true;
                    if(j-1+l >= 0) flag3 = true;
                    if(j-1+l <= y-1) flag4 = true;
                    if(flag1==true && flag2==true && flag3==true && flag4==true && a[i-1+k][j-1+l] == '#') cnt++;
                }
            }
            int ans = cnt;
            a[i][j] = '0' + ans;
        }
    }

    rep(i, t) {
        rep(j, y) {
            cout << a[i][j];
            if(j == y-1) cout << endl;
        }
    }
}


Measured memory_bytes: 256
/*　　　　　　　{:i:i:|i:i:/l/l--　 　 　--l/li:i:i|i:i:i:i}
　　　　　　 　 {:rx|:i:i ィi芥ミ 　 　 .ィi芥ミｉ:ｉ|ﾍ:i:i:}
.　　　 　 　 　 ｛ﾏ|ｉ:  {::’:} 　 　 　{:‘::} :ｉ:i:|〉｝:/
　　 　 　 　 　 乂|:i:| ｀¨¨¨¨´ 　 　　｀¨¨¨´  :i:ｉ:|ｼ/
　 　 　 　 　 　 ﾉ:|:i|　　　　　　′　　　 　   |:i:i:|ﾂ
　　　　　　　　/:/|:i:| ､　　　 　_ _ 　　　　  |:i:i:|
　 　 　　 　 /:/ .|:i:|/ ＼　　　 　 　     ｨ〔|:i:/
　　 　 　  　 〈;/ く刈＿ 个 　   -   　＜}　./|/_〉
　　     　　 r-っ'~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ|___
　　 　     /／ニつ　　　　　　 ､　　　　　　　ノﾆﾆ　＼
.　　　     |　　ニ⊃ 　./　/　 ──   /　/　　..⊆ﾆﾆ　　:|
.　　　     |　　丁´　 /|￣|￣  ─‐ /|￣|￣ 　 .￣|丁 　|
.　　　     |　　ﾉ.  　 |￣|￣  ─‐  |￣|￣ 　 　.|八 　|
.　　　     |　　||. 　 |￣|￣ |￣| |￣|￣ 　   .|　|
.　 　 　   |  　||   　￣￣￣　￣ 　￣￣￣　　  .|　|  |
.　 　 　  　    ||＿＿＿＿＿＿＿＿＿＿＿＿______|__　　 ',
　 　      ,′　 | ７ﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆ}  ,′
.　　     {　　　|/　}ﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆ{/ 　 　
*/
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

using namespace std;

#define rep(a) _rep(0,int(a))
#define _rep(a,b) for(int i=int(a);i<int(b);i++)
#define ll long long
#define fst first
#define snd second


//factorial
int fact(int n) {
	int a = 1;
	for (int i = 1;i <= n;i++) a *= i;
	return a;
}

ll n, a, b,ans;
int main() {
	cin >> n >> a >> b;
	ans = n / (a + b) * a;
	if (n % (a + b)>a) {
		ans += a;
	}
	else ans += n % (a + b);
	cout << ans << endl;
}



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

int main() {
  int A, B;
  cin >> A >> B;
  int ans = 1;
  while (true){
    if (floor(ans * 0.1) - B == 0){
      if (floor(ans * 0.08) - A == 0){
        cout << ans << endl;
        break;
      }
    }
    else if (ans >= 1010){
      cout << -1 << endl;
      break;
    }
    ans++;
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007

int a,b,c,n,k,x,y;

int main(){
  int ans=0;
  string s;cin>>s;
  n=s.length();
  vector<int> a(n),vl(n),vr(n);
  REP(i,n-1){
    if ((s[i]=='R')&(s[i+1]=='L'))a[i]=1;
  }
  REP(i,n-1){
    if (a[i]==1){
      //左に検
      for(int j=i-1;j>=0;j--){
        if (s[j]=='R'){
          vl[i]++;
        }else{break;}
      }
      //右に検
      for(int j=i+2;j<n;j++){
        if (s[j]=='L'){
          vr[i]++;
        }else{break;}
      }
    }
  }


  int outR=0;
  int outL=0;
  REP(i,n){
    if (a[i]==1){
      outR=1;//出力右がわ
      outL=1;
      outR+=vl[i]/2+vl[i]%2;
      outL+=vl[i]/2;

      outR+=vr[i]/2;
      outL+=vr[i]/2+vr[i]%2;
      

      cout<<outL<<" ";
      cout<<outR<<" ";
      i++;
    }else{
      cout<<0<<" ";
    }
  }



  return 0;
}

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

char map[111][111];

int hoge(int i,int j,int h,int w,char key);
void DFS(int x,int y,int h,int w,char key);

int main(){
  int i,j;
  int h,w;
  int ans=0,cnt=0;
  char key;

  while(1){
    scanf("%d %d",&h,&w);
    
    if(h==0 && w==0) break;
    
    for(i=0;i<h;i++){
      scanf("%s",map[i]);
    }
    
    
    key='#';
    ans+=hoge(0,0,h,w,key);
    
    key='*';
    ans+=hoge(0,0,h,w,key);
    
    key='@';
    ans+=hoge(0,0,h,w,key);
    
    printf("%d\n",ans);
    ans=0;

  } 

  return 0;
}


int hoge(int i,int j,int h,int w,char key){
  int cnt=0;

  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(map[i][j]==key){
	cnt++;
	DFS(j,i,h,w,key);
      }
    }
  }

  return cnt;
}


void DFS(int x,int y,int h,int w,char key){

  if(x<0 || y<0 || x>=w || y>=h) return;
  if(map[y][x] != key) return;

  map[y][x]='0';

  DFS(x+1,y,h,w,key); DFS(x,y+1,h,w,key);
  DFS(x-1,y,h,w,key); DFS(x,y-1,h,w,key);

  return;
}

Measured memory_bytes: 1664
N = input()
H = map(int, input().split())
last_h = float('inf')
cnt = -1
ans = 0
for h in H:
    if h <= last_h:
        cnt += 1
    else:
        ans = max(ans, cnt)
        cnt = 0
    last_h = h
ans = max(ans, cnt)
print(ans)

Measured memory_bytes: 11132
using System;
class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());

        int ans = 0;
        int count = 0;

        int a = 0;

        for(int i=1; i<=N; i++)
        {
            a = i;
            count = 0;
            while (true)
            {
                if (a / 10 == 0)
                {
                    count++;
                    break;
                }
                count++;
                a /= 10; 
            }

            if (count % 2 == 1) ans++;
        }

        Console.WriteLine(ans);
    }

}

Measured memory_bytes: 13140
from collections import Counter
n = input()
V = list(map(int, input().split(" ")))

"""
9
1 1 1 1 2 2 2 4 
1 1 1 1 3 3 4 4
"""

#V = [1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 2, 3, 2, 4, 4, 4]

v1 = V[0::2]
v2 = V[1::2]

f1 = Counter(v1).most_common(2)
f2 = Counter(v2).most_common(2)

ans = 0

if len(set(v1)) == len(set(v2)) == 1:
    if v1 == v2:
        ans = min(len(v1), len(v2))
else:
    if f1[0][0] != f2[0][0]:
        ans = (len(v1) - f1[0][1]) + (len(v2) - f2[0][1])
    else:
        if f1[1][1] < f2[1][1]:
            ans = (len(v1) - f1[0][1]) + (len(v2) - f2[1][1])
        else:
            ans = (len(v1) - f1[1][1]) + (len(v2) - f2[0][1])
        
print(ans)


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

int h, w;
P d;
int ans = -1;
queue<pair<int, vector<int> > > q;

vector<string> m(1e3);
vector<vector<int> > area(1e3, vector<int>(1e3, 0));

void rec(int x, int y, int c){
  if ((x < 0) || (x >= h)) return;
  if ((y < 0) || (y >= w)) return;
  if ((d.first == x) && (d.second == y)) ans = c - 1;
  if (area[x][y] != 0) return;
  if (m[x][y] == '.') area[x][y] = c;
  else return;

  q.push(pair<int, vector<int> >(c, {x, y}));
  rec(x - 1, y, c);
  rec(x + 1, y, c);
  rec(x, y - 1, c);
  rec(x, y + 1, c);
}

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

  int s1, s2;
  cin >> s1 >> s2;
  P s(s1 - 1, s2 - 1);

  int d1, d2;
  cin >> d1 >> d2;
  d = P(d1 - 1, d2 - 1);


  rep(i, h) cin >> m[i];

  rec(s.first, s.second, 1);
  if (ans != -1){
    cout << ans << endl;
    return 0;
  }
 
  while(!q.empty()){
    pair<int, vector<int> > cur = q.front();
    q.pop();

    for(int i = -2; i <= 2; ++i){
      for(int j = -2; j <= 2; ++j){
        int x = cur.second[0] + i;
        int y = cur.second[1] + j;
        if ((x < 0) || (x >= h)) continue;
        if ((y < 0) || (y >= w)) continue;
        if ((area[x][y] == 0) &&  (m[x][y] == '.')){
          rec(x, y, cur.first + 1);
          if (ans != -1){
            cout << ans << endl;
            return 0;
          }
        }
      }
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 10096
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    a,b=MI()
    if a%3==0 or b%3==0 or (a+b)%3==0:
        print("Possible")
    else:
        print("Impossible")
main()

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

struct Point
{
	int x;
	int y;
	int index;
};

struct Node
{
	Point p;
	Node *right;
	Node *left;
};

Node* makeKdTree(vector<Point> &ps, int first, int last, int depth) {
	int d = last - first;
	if (d < 0) {
		return nullptr;
	}

	int axis = depth % 2;

	if (axis == 0) {
		sort(ps.begin() + first, ps.begin() + last + 1, [](const Point &a, const Point &b) {
			return a.x < b.x;
		});

	}
	else {
		sort(ps.begin() + first, ps.begin() + last + 1, [](const Point &a, const Point &b) {
			return a.y < b.y;
		});
	}

	Point median = ps[first + d / 2];
	Node *node = new Node;
	node->p = median;
	node->right = makeKdTree(ps, first + d / 2 + 1, last, depth + 1);
	node->left = makeKdTree(ps, first, first + d / 2 - 1, depth + 1);
	return node;
}

void search(Node *p, int sx, int tx, int sy, int ty, int depth, vector<int> &result) {
	if (p == nullptr) {
		return;
	}
	if (p->p.x >= sx && p->p.x <= tx && p->p.y >= sy && p->p.y <= ty) {
		result.push_back(p->p.index);
	}

	int axis = depth % 2;

	if (axis == 0) {
		if (p->p.x < sx) {
			search(p->right, sx, tx, sy, ty, depth + 1, result);
		}
		else if (p->p.x > tx) {
			search(p->left, sx, tx, sy, ty, depth + 1, result);
		}
		else {
			search(p->left, sx, tx, sy, ty, depth + 1, result);
			search(p->right, sx, tx, sy, ty, depth + 1, result);
		}
	}
	else {
		if (p->p.y < sy) {
			search(p->right, sx, tx, sy, ty, depth + 1, result);
		}
		else if (p->p.y > ty) {
			search(p->left, sx, tx, sy, ty, depth + 1, result);
		}
		else {
			search(p->left, sx, tx, sy, ty, depth + 1, result);
			search(p->right, sx, tx, sy, ty, depth + 1, result);
		}
	}

	return;
}

void freeKdTree(Node *p) {
	if (p == nullptr) {
		return;
	}

	freeKdTree(p->left);
	freeKdTree(p->right);
	free(p);
	return;
}

int main() {
	int n;
	cin >> n;
	vector<Point> ps;
	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		ps.push_back(Point{ x, y, i });
	}

	Node *kdtree = makeKdTree(ps, 0, n - 1, 0);

	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int sx, tx, sy, ty;
		cin >> sx >> tx >> sy >> ty;
		vector<int> result;
		search(kdtree, sx, tx, sy, ty, 0, result);
		sort(result.begin(), result.end());
		for (auto item : result) {
			cout << item << '\n';
		}
		cout << '\n';
	}

	freeKdTree(kdtree);
	return 0;
}

Measured memory_bytes: 31400
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int main(){
  int A;
  int B;
  int C;
  rd(A);
  rd(B);
  rd(C);
  if(A > B){
    swap(A, B);
  }
  if(B > C){
    swap(B, C);
  }
  if(A > B){
    swap(A, B);
  }
  ;
  if(A!=C && (A==B || B==C)){
    wt_L("Yes");
    wt_L('\n');
  }
  else{
    wt_L("No");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20200214-1

// --- original code ---
// {
//   int A, B, C;
//   rd(A,B,C);
//   sortE(A,B,C);
//   wt(if[A!=C && (A==B || B==C), "Yes", "No"]);
// }


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int c[256];
	int a;
	while(1){
		scanf("%d",&a);
		if(a==0)return 0;
		for(int i=0;i<256;i++)c[i]=i;
		getchar();
		getchar();
		for(int i=0;i<a;i++){
			char b,d;
			b=getchar();
			getchar();
			d=getchar();
			getchar();
			getchar();
			c[b]=d;
		}
		int e;
		scanf("%d",&e);
		getchar();
		getchar();
		char f;
		for(int i=0;i<e;i++){
			f=getchar();
			getchar();
			getchar();
			putchar(c[(int)f]);
		}
		printf("\n");
	}
}

Measured memory_bytes: 0
"""
10**15なので，ループで割ることを考える
1 + (6, 5)
"""

x = int(input())
count = (x // 11) * 2
x = x % 11
if x > 6:
    print(count+2)
elif x > 0:
    print(count+1)
else:
    print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main () {
    int a, b;
    cin >> a >> b;
    if (a < b) {
        swap(a, b);
    }
    for (long long i = a; ; i += a) {
        if (i % b == 0) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3") 
#pragma GCC optimization ("unroll-loops")
 
// #include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
// const ll RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
// gp_hash_table<int, int> table;
 
#define ll  long long
#define vii vector< ll >
#define pb push_back
#define pii pair<ll,ll>
#define ppi pair<pii,ll>
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define ins insert
#define ld long double
#define lp(l,r) for(i=l;i<=r;++i)
 
#define lpj(l,r) for(j=l;j<=r;++j)
#define lpr(l,r) for(i=r;i>=l;--i)
#define lprj(l,r) for(j=r;j>=l;--j)
 
#define swap(a,b){ auto _t=a;a=b,b=_t;}
#define flush() cout.flush()
#define popcount __builtin_popcount
#define die() return 0;
#define sz() size() 


 
 
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define MD          1000000007
#define M 			200011
#define LN             14
#define fftmod      998244353
#define EPS         (double)1e-10
 
long long  md=MD;
ll inf=1e18;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 
 
 
inline ll exp(ll a,ll b){if(a==0&&b==0)return 1ll;if(a==0)return 0ll;ll r=1LL;while(b>0){if(b&1){r=(r%md)*(a%md);r=(r+md)%md;}b/=2;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;if(a==0)return b;return gcd(b,a%b);}
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (ll)r;}
 
using cd=complex<double>;
const double PI=acos(-1);
 
inline ll rand(ll l,ll r){
    return l+rng()%(r-l+1);
}


int main(){
 
     
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
 
   // ifstream fin("input.txt");ofstream fout("outut.txt");
    ll t,i,j,m,n,s,z,k,p;string s1,s2;ll q;ll x,y;
    cin>>n>>k;
    vii v;
    ll g=-1;
    lp(1,n){
    	cin>>x;v.pb(x);
    }
    for(auto x:v){
    	ll dif=abs(k-x);
    	if(g==-1)g=dif;
    	g=gcd(g,dif);
    }
    cout<<g<<"\n";





    

}



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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long X, long long Y, long long A, long long B, long long C, std::vector<long long> p, std::vector<long long> q, std::vector<long long> r){
    sort(ALL(p), greater<LL>());
    sort(ALL(q), greater<LL>());
    sort(ALL(r), greater<LL>());

    VLL ans;
    REP(i, X) ans.PB(p[i]);
    REP(i, Y) ans.PB(q[i]);
    sort(ALL(ans));

    int idx = 0;
    LL ans2 = 0;
    REP(i, ans.size()) {
        if(ans[i] < r[idx]) {
            ans2 += r[idx];
            idx++;
        } else {
            ans2 += ans[i];
        }
    }

    cout << ans2 << endl;
}

int main(){
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    std::vector<long long> p(A);
    for(int i = 0 ; i < A ; i++){
        scanf("%lld",&p[i]);
    }
    std::vector<long long> q(B);
    for(int i = 0 ; i < B ; i++){
        scanf("%lld",&q[i]);
    }
    std::vector<long long> r(C);
    for(int i = 0 ; i < C ; i++){
        scanf("%lld",&r[i]);
    }
    solve(X, Y, A, B, C, std::move(p), std::move(q), std::move(r));
    return 0;
}


Measured memory_bytes: 4724
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n;
    cin >> n;
    vint v(n), c(n);
    rep(i, n) cin >> v[i];
    rep(i, n) cin >> c[i];

    int ans = 0;
    rep(i, n) {
        ans += max(v[i] - c[i], 0);
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sin60 1.732050807568877/2
#define cos60 1.0/2
using namespace std;
int n;
void kohho(int d,double x1,double y1,double x2,double y2){
  if(d==n){
    printf("%f %f\n",x2,y2);
    return;
  }
  double nx1=(2*x1+x2)/3,ny1=(2*y1+y2)/3,nx2=(x1+2*x2)/3,ny2=(y1+2*y2)/3;
  double dx=nx2-nx1,dy=ny2-ny1;
  double cx=dx*cos60-dy*sin60+nx1,cy=dx*sin60+dy*cos60+ny1;
  kohho(d+1,x1,y1,nx1,ny1);
  kohho(d+1,nx1,ny1,cx,cy);
  kohho(d+1,cx,cy,nx2,ny2);
  kohho(d+1,nx2,ny2,x2,y2);
}
int main(){
  cin>>n;
  cout<<"0 0"<<endl;
  kohho(0,0,0,100,0);
  return 0;
}

Measured memory_bytes: 1228
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
x,y = I()
if (x in a and y in a) or (x in b and y in b) or x == y == 2:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 77264
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

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

func nextInt3() (int, int, int) {
	return nextInt(), nextInt(), nextInt()
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func pyramid(cx, cy, x, y, h int) int {
	return h + abs(x-cx) + abs(y-cy)
}

func height(cx, cy, h, x, y int) int {
	return max(0, h-abs(x-cx)-abs(y-cy))
}

func max(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := nextInt()
	x, y, h := make([]int, n), make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		x[i], y[i], h[i] = nextInt3()
	}

	for cx := 0; cx <= 100; cx++ {
		for cy := 0; cy <= 100; cy++ {
			ok := true
			k := 0
			for k < n && h[k] == 0 {
				k++
			}
			H := max(1, pyramid(cx, cy, x[k%n], y[k%n], h[k%n]))
			for l := 0; ok && l < n; l++ {
				ok = ok && (max(height(cx, cy, H, x[l], y[l]), 0) == h[l])
			}

			if ok {
				puts(cx, cy, H)
				return
			}
		}
	}
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define LL long long
using namespace std;
int main()
{
    int n,a[100005];
    bool vis[100005];
    scanf("%d",&n);
    LL ans=0;
    memset(vis,false,sizeof(vis));
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
        if(a[i])vis[i]=true;
        ans+=a[i]/2;
        a[i]%=2;
    }
    for(int i=1; i<n; i++)
    {
        if(a[i]&&a[i-1])
        {
            a[i]=0;
            a[i-1]=0;
            ans++;
        }
        else if(a[i]==0&&a[i-1])
            if(vis[i]) a[i]++,a[i-1]--;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 768
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


n = inp()
a = inpl()
money = 1000
for i in range(1, n):
    if a[i] > a[i - 1]:
        money += (a[i] - a[i - 1]) * (money // a[i - 1])
print(money)


Measured memory_bytes: 69080
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    string S; cin >> S;
    string dream = "dream";
    string dreamer = "dreamer";
    string erase = "erase";
    string eraser = "eraser";
    reverse(dream.begin(), dream.end());
    reverse(dreamer.begin(), dreamer.end());
    reverse(erase.begin(), erase.end());
    reverse(eraser.begin(), eraser.end());
    reverse(S.begin(), S.end());
    
    ll idx = 0; bool ok = true;
    while(idx < S.size()){
        if(dream == S.substr(idx, dream.size())){
            idx += 5;
        }
        else if(dreamer == S.substr(idx, dreamer.size())){
            idx += 7;
        }
        else if(erase == S.substr(idx, erase.size())){
            idx += 5;
        }
        else if(eraser == S.substr(idx, eraser.size())){
            idx += 6;
        }
        else{
            ok = false; break;
        }
    }
    cout << (ok ? "YES" : "NO") << endl;
    return 0;
}


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

#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define rev(a) (a).rbegin(),(a).rend()
#define pll pair<ll,ll>
#define rep(i,a,b) for(long long i = (a); i <= (b); i++)

const int mod = 1e9+7;
const int N = 1e5+5; 

int main(){
	fast;
	ll t = 1;
// 	cin >> t;
	while(t--){
	    ll x,y,z; cin>>x>>y>>z;
	    swap(x,y);
	    swap(x,z);
	    cout << x << " " <<  y << " " << z << endl;
	}
}

Measured memory_bytes: 256
s = input()
s = [s[_] for _ in range(len(s))]
l = ['-']*len(s)
answers = []
for i in range(8):
    l = ['-']*len(s)
    for j in range(3):
        if ((i>>j) & 1):
            l[j] = '+'
    ans = []
    for j, k in zip(s, l):
        ans.append(j)
        ans.append(k)
    ans = ans[:-1]
    ans1 = ''.join(ans)
    ans2 = 0
    for _, j in enumerate(s):
        if _ == 0:
            ans2 += int(j)
        else:
            if l[_-1] == '-':
                ans2 -= int(j)
            else:
                ans2 += int(j)
    answers.append([ans1, ans2])
for i in answers:
    if i[1] == 7:
        print(''.join(i[0]) + '=7')
        break

Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++){for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;}
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  string s;cin>>s;
  if(s.back()=='s')s+='e';
  s+='s';
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 3664
N, M = [int(i) for i in input().split()]
if 2 * N >= M:
    # SccをMの値が許す限り作る
    ans = M // 2
else:
    # SccをN個作り、残りのccccからSccを作る
    ans = N + (M - 2 * N) // 4
print(ans)

Measured memory_bytes: 3316
#include <iostream>

using namespace std;

int main()
{
    int a, b;
    char op;
    while (true)
    {
        cin >> a >> op >> b;
        if (op == '?')
            break;

        if (op == '+')
        {
            cout << a + b << endl;
        }
        else if (op == '-')
        {
            cout << a - b << endl;
        }
        else if (op == '*')
        {
            cout << a * b << endl;
        }
        else if (op == '/')
        {
            cout << a / b << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;
#define lint long long
#define ll long long
static const int INF = 1 << 22;
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
/*******source code below********/
//?012,?021,0?12,01?2,?102:NG
ll dp[101][4][4][4];
ll ans;
void solve(int N) {
	ans = 0;
	dp[0][3][3][3] = 1;
	for (ll len = 0; len < N; len++) {
		for (ll l1 = 0; l1 < 4; l1++) {
			for (ll l2 = 0; l2 < 4; l2++) {
				for (ll l3 = 0; l3 < 4; l3++) {

					if (dp[len][l1][l2][l3] == 0) continue;
					for (ll a = 0; a < 4; a++) {

						if (a == 2 && l1 == 1 && l2 == 0) continue;
						if (a == 1 && l1 == 2 && l2 == 0) continue;
						if (a == 2 && l1 == 1 && l3 == 0) continue;
						if (a == 2 && l2 == 1 && l3 == 0) continue;
						if (a == 2 && l1 == 0 && l2 == 1) continue;

						dp[len + 1][a][l1][l2] += dp[len][l1][l2][l3];
						dp[len + 1][a][l1][l2] %= mod;

					}

				}
			}
		}
	}


	
		for (ll l1 = 0; l1 < 4; l1++) {
			for (ll l2 = 0; l2 < 4; l2++) {
				for (ll l3 = 0; l3 < 4; l3++) {
					ans += dp[N][l1][l2][l3];
					ans %= mod;
				}
			}
		}
	
}
int main(void) {

	long long N; cin >> N;
	solve(N);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	long int a=0;
	long int ans=0;
	scanf("%ld",&a);
	
	ans += (a/500) * 1000;
	ans += (a-ans/2)/5 * 5;
	
	printf("%ld\n",ans);
	return 0;
}

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

using namespace std;

int main() {
  int H, W;
  string s = ".";
  cin >> H >> W;
  vector<string> map(H + 2);
  
  for (int i=0; i < W + 1; i++) {
    s += ".";
  }
  
  map.at(0) = s;
  map.at(H + 1) = s;
  
  for (int i=1; i < H + 1; i++) {
    string S;
    cin >> S;
    S = "." + S + ".";
    map.at(i) = S;
  }
  
  for (int i = 0; i < H * W; i++) {
    int row = i / W + 1;
    int col = i % W + 1;
    
    int num = 0;
    
    if (map.at(row).at(col) == '#') {
      cout << '#';
    } else {
      for (int j = -1; j < 2; j++) {
        for (int k = -1; k < 2; k++) {
          if (map.at(row + j).at(col + k) == '#') {
            num++;
          }
        }
      }
      cout << num;
    }
    
    if (col == W) cout << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
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 pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int main(){
	string s;
	cin>>s;
	string s2 = "2016";
	rep(i, 4) cout<<s[i];
	cout<<" ";
	REP(i, 4, s.size()) cout<<s[i];
	cout<<endl;
}

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

graph = [[False for j in range(N)] for i in range(N)]

am = [0] * M
bm = [0] * M


def dfs(visited, n):
    visited[n] = True

    for k, v in enumerate(visited):
        if v:
            continue

        if not graph[n][k]:
            continue

        visited = dfs(visited, k)

    return visited


def main():
    for i in range(M):
        # 0-indexed
        ai, bi = map(int, input().split())
        ai -= 1
        bi -= 1

        am[i] = ai
        bm[i] = bi

        graph[ai][bi] = True
        graph[bi][ai] = True

    ans = 0

    for ai, bi in zip(am, bm):
        graph[ai][bi] = False
        graph[bi][ai] = False

        # 訪問済 All False
        visited = dfs([False] * N, 0)

        # All True ならば 橋 ではない
        if not all(visited):
            ans += 1

        # 元に戻す
        graph[ai][bi] = True
        graph[bi][ai] = True

    print(ans)
    return


main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;

int dp[2001];

signed main() 
{
	int n;
	cin >> n;
	for(int i = 3; i <= n; i++)
	{
		dp[i] = 1;
		for(int j = 3; j <= i; j++)
		{
			dp[i] = (dp[i - j] + dp[i] + mod)%mod;
		}
	}
	cout << dp[n] << '\n';
}

Measured memory_bytes: 3616
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def read_a_int(): return int(read())


def read_ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

A, B = read_ints()
print(A * B)


Measured memory_bytes: 65324
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

const int nax = 2e5 + 5;
vector<pair<int,int>> intervals[nax];
const ll INF = 1e18L + 5;

// add to the prefix
// give the min of everything

struct S {
    ll small, lazy;
    void merge(const S& a, const S& b) {
        small = min(a.small, b.small);
        assert(lazy == 0);
    }
    void add(ll x) {
        small += x;
        lazy += x;
    }
};
vector<S> tree;

const int TYPE_ADD = 1, TYPE_MIN = 2;
void rec(int id, int low, int high, int q_low, int q_high, int type, ll& x) {
    if(high < q_low || q_high < low) {
        return;
    }
    if(q_low <= low && high <= q_high) {
        if(type == TYPE_ADD) {
            tree[id].add(x);
        }
        else if(type == TYPE_MIN) {
            x = min(x, tree[id].small);
        }
        else {
            assert(false);
        }
        return;
    }
    for(int b : {2 * id, 2 * id + 1}) {
        tree[b].add(tree[id].lazy);
    }
    tree[id].lazy = 0;
    
    int last_left = (low + high) / 2;
    rec(2 * id, low, last_left, q_low, q_high, type, x);
    rec(2 * id + 1, last_left + 1, high, q_low, q_high, type, x);
    
    tree[id].merge(tree[2*id], tree[2*id+1]);
}
        

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    ll sum_of_scores = 0;
    for(int i = 0; i < m; ++i) {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        intervals[b].emplace_back(a, c);
        sum_of_scores += c;
    }
    ll answer = 0;
    
    int base = 1;
    while(base <= n + 1) {
        base *= 2;
    }
    tree.resize(2 * base, {INF, 0});
    
    ll whatever = 0 - INF;
    rec(1, 0, base - 1, 0, 0, TYPE_ADD, whatever);
    for(int i = 1; i <= n + 1; ++i) {
        // I want to put '1' here
        for(pair<int,int> p : intervals[i-1]) {
            whatever = p.second;
            rec(1, 0, base - 1, 0, p.first - 1, TYPE_ADD, whatever);
        }
        ll best = INF;
        rec(1, 0, base - 1, 0, base - 1, TYPE_MIN, best);
        if(i == n + 1) {
            answer = best;
        }
        whatever = best - INF;
        rec(1, 0, base - 1, i, i, TYPE_ADD, whatever);
    }
    
    
    printf("%lld\n", sum_of_scores - answer);
}


Measured memory_bytes: 19328
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = Long.parseLong(sc.next());
		int min = Integer.MAX_VALUE;
		for (long a = 1; a <= Math.sqrt(n); a++) {
			if (n % a != 0)
				continue;
			int l = String.valueOf(n / a).length();
			if (l < min)
				min = l;
		}
		System.out.println(min);
	}
}

Measured memory_bytes: 23636
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long ll;
const int maxn = 100000 + 10;

int n, m;
char s[maxn], t[maxn];

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

int main() {
	scanf("%d%d%s%s", &n, &m, s + 1, t + 1);
	ll k = 1LL * n / gcd(n,m) * m;
	ll now = k / n;
	if(s[1] != t[1]) {
	  puts("-1");
	  return 0;
	}
	for(int i = 1;i < m;i ++) {
	  if(i % now == 0) {
	    ll k1 = 1LL * n * i / m;
	    ll k2 = i;
	    k1 ++; k2 ++;
	    if(s[k1] != t[k2]) {
	      puts("-1");
	      return 0;
			}
		}
	}
	printf("%lld\n", k);
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long int ll;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int k; cin >> k;
    string s; cin >> s;
    if(s.size()<=k){
        cout << s << endl;
    }
    else{
        cout << s.substr(0,k) << "..." << endl;
    }
}


Measured memory_bytes: 3656
#include<stdio.h>
int main()
{
      long long int n,i,p;
      scanf("%lld",&n);
      long long int a[100001]={};
      long long int sum=0;
      for(i=0;i<n;i++)
      {
            scanf("%lld",&p);
            sum+=p;
            a[p]++;
      }
      long long int m,b,c;
      scanf("%lld",&m);
      for(i=0;i<m;i++)
      {
            scanf("%lld%lld",&b,&c);
            a[c]+=a[b];
            sum=sum+c*a[b]-b*a[b];
            a[b]=0;
            printf("%lld\n",sum);
      }

      return 0;
}


Measured memory_bytes: 2488
#include<bits/stdc++.h>
const int N=1007,inf=0x3f3f3f3f;
int n,xs[N],ys[N],fa[N],f[5007],g[5007];
void mins(int&a,int b){if(a>b)a=b;}
void f1(int w){
	for(int u=w+1;u<=n;++u)if(fa[u]==w)f1(u);
	memset(f,0,sizeof(f));
	for(int u=w+1;u<=n;++u)if(fa[u]==w){
		memset(g,0x3f,sizeof(g));
		int x=xs[u],y=ys[u];
		for(int i=x;i<=xs[w];++i)mins(g[i],f[i-x]+y);
		for(int i=y;i<=xs[w];++i)mins(g[i],f[i-y]+x);
		memcpy(f,g,sizeof(g));
	}
	ys[w]=f[xs[w]];
}
int main(){
	scanf("%d",&n);
	for(int i=2;i<=n;++i)scanf("%d",fa+i);
	for(int i=1;i<=n;++i)scanf("%d",xs+i);
	f1(1);
	puts(ys[1]<inf?"POSSIBLE":"IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 384
import numpy as np

N, X = [int(i) for i in input().split()]
l_l = [int(i) for i in input().split()]

d1=0
l_d = [d1]
for i in range(N):
    l_d.append(l_d[i]+l_l[i])
    
arr_d = np.array(l_d)
print(len(arr_d[arr_d<=X]))

Measured memory_bytes: 12440