akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

@SuppressWarnings("unchecked")
public class Main {
	// public static void printArray(int[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	// public static<T> void printArrayT(T[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	public static String joinInt(int[] a, String separator) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < a.length; i++) {
			if (i > 0) {
				sb.append(separator);
			}
			sb.append(a[i]);
		}
		return sb.toString();		
	}

	static int[] nextIntArray(Scanner sc, int N) {
		int[] arr = new int[N];
		for (int i = 0; i < N; i++) {
			arr[i] = sc.nextInt();
		}
		return arr;
	}

	public static void main(String[] args) {
		final int COMPRESS = 400;
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int W = sc.nextInt();

		int[] ws = new int[N];
		int[] vs = new int[N];
		for (int i = 0; i < N; i++) {
			ws[i] = sc.nextInt();
			vs[i] = sc.nextInt();
		}
		// System.out.println("XXX");

		int[] value = new int[(COMPRESS + 4) * N];
		
		int compress = 0;
		if (ws[0] > COMPRESS) {
			compress = ws[0] - COMPRESS;
		}
		for (int i = 0; i < N; i++) {
			int w = ws[i] - compress;
			int v = vs[i];
			// System.out.println("(" + w + ", " + v + ")");
			for (int j = value.length - 1; j >= w ; j--) {
				value[j] = Math.max(value[j], value[j-w] + v);
			}
		}
		if (compress == 0) {
			System.out.println(value[W]);
		} else {
			int a = W / ws[0];
			int b = W % ws[0];
			int c = ws[0] - compress;
			// System.out.println("(" + a + ", " + b + ")");
			int W2 = a * c + Math.min(b, c-1);
			System.out.println(value[W2]);
		}
	}
}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!

bool _find(vi &arr,int n){
    
    for(int i=1;i<n;i++){
        if(arr[i]>arr[i-1]){
            arr[i]--;
        }
        else if(arr[i]<arr[i-1]){
            return false;
        }
    }
    return true;
}
void solve(){
    int n;
    cin>>n;
    
    vi arr(n);
    for(int i=0;i<n;++i){cin>>arr[i];}
    
    if(_find(arr,n)){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    cout<<endl;
}





int main() {
    faster;
    int t=1;
    // cin>>t;
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3696
def solve(actions, n):
    # 1-origin
    dp = [[0] * 4 for _ in range(n + 1)]

    for day, action in enumerate(actions, 1):
        action1, action2, action3 = action[0], action[1], action[2]
        for key in range(1, 4):
            if key == 1:
                dp[day][key] = action1 + max(dp[day - 1][2], dp[day - 1][3])
            elif key == 2:
                dp[day][key] = action2 + max(dp[day - 1][1], dp[day - 1][3])
            else:
                dp[day][key] = action3 + max(dp[day - 1][1], dp[day - 1][2])

    return max(dp[n])


def main():
    n = int(input())
    actions = []

    for i in range(n):
        actions.append(list(map(int, input().split())))

    ans = solve(actions, n)
    print(ans)


main()

Measured memory_bytes: 47356
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel.Design;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Schema;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); }
        static public List<int> Slist() { return new List<int>(ReadLine().Split().Select(int.Parse)); }
        static void Main(string[] args)
        {
            var xy = Sarray();
            var x = xy[0];
            var y = xy[1];
            for(var i=0;i<=x;i++)
            {
                if(2*i+4*(x-i)==y)
                {
                    WriteLine("Yes");
                    return;
                }
            }
                    WriteLine("No");
        }
    }
}


Measured memory_bytes: 18868
a,b,x = map(int,input().split())

if (a*a*b/2)<=x:
    s = (2*a*a*b-2*x)/(a**3)
else:
    s = (a*b*b)/(2*x)

import math
theta = math.degrees(math.atan(s))

print(theta)

Measured memory_bytes: 3444
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>
#include <list>
#include <stdio.h>
#include <sstream>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const ll mod = 1e9 + 7;
const ll inf = 1LL << 60;
const long double pi = 3.14159265358979323846;

// ****************************************CODE***************************************//

ll n, w, weight[100100], value[100100];
ll dp[110][100100];

int main() {
    cin >> n >> w;
    for(int i = 0; i < n; i++) cin >> weight[i] >> value[i];
    for(int i = 0; i < 110; i++) for(int j = 0; j < 100100; j++) dp[i][j] = inf;

    dp[0][0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 100100; j++){
            if(j - value[i] >= 0) dp[i+1][j] = min(dp[i+1][j], dp[i][j - value[i]] + weight[i]);
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
        }
    }

    ll res = 0;
    for(int i = 0; i < 100100; i++){
        if(dp[n][i] <= w) res = i;
    }

    cout << res << endl;
}

Measured memory_bytes: 86272
n, a, b = map(int, input().split())
s = input()
u = v = 0
for x in s:
    if u == a+b or x == 'c':
        print('No')
    elif x == 'a':
        print('Yes')
        u += 1
    else:
        if v == b:
            print('No')
        else:
            print('Yes')
            u += 1
            v += 1

Measured memory_bytes: 4016
# coding: utf-8
# Your code here!

n=int(input())
x=list(map(int,input().split()))
cost_min=1000000000
for i in range(1,101):
    cost=0
    for j in x:
        cost+=(j-i)**2
    if cost>=cost_min:
        continue
    cost_min=cost
print(cost_min)

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

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

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

    int ans = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n-i-1; ++j) {
	if (a[j] > a[j+1]) {
	  ++ans;
	  swap(a[j], a[j+1]);
	}
      }
    }

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

Measured memory_bytes: 0
n, p = map(int, input().split())
even_count = sum(a % 2 == 0 for a in map(int, input().split()))
odd_count = n - even_count
if odd_count == 0:
  print(0 if p == 1 else 2 ** even_count)
else:
  print((2 ** even_count) * (2 ** (odd_count - 1)))

Measured memory_bytes: 9152
#include<iostream>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a<b)swap(a,b);
	if(a<c)swap(a,c);
	if(b<c) swap(b,c);
	cout<<a*10+b+c<<endl;
	return 0;
}

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

#define ll long long

using namespace std;

int main() {
	ll x;
	cin >> x;
	
	ll ans = x / 11 * 2;
	x %= 11;
	if (x > 6) ans +=2 ;
	else if (x > 0) ans += 1;
	cout << ans;
	return 0;
}




Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(void){
	int n, k;
	long *a;
	scanf("%d", &n);
	scanf("%d", &k);
	a = (long *)malloc(sizeof(long) * n);
	for(int i=0; i<n; i++){
		scanf("%ld", &a[i]);
	}
	for(int j=0; j<n-k; j++){
		if(a[j]>=a[j+k]){
			printf("No\n");
		} else{
			printf("Yes\n");
		}
	}
	return 0;
}

Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    double r;
    cin >> r;
    printf("%.10f\n", 2 * 3.1415926535 * r);

    return 0;
}

Measured memory_bytes: 3776
import sys
input=lambda: sys.stdin.readline().rstrip()
t=int(input())
import heapq
for _ in range(t):
  n=int(input())
  ans=0
  C=[]
  D=[]
  for i in range(n):
    k,l,r=map(int,input().split())
    if l>r:
      C.append((k,l-r))
      ans+=r
    else:
      D.append((n-k,r-l))
      ans+=l
  C.sort(key=lambda x:(x[0],x[1]), reverse=True)
  D.sort(key=lambda x:(x[0],x[1]), reverse=True)
  c,d=len(C),len(D)
  H=[]
  cur=0
  for i in range(1,c+1)[::-1]:
    while cur<c:
      k,l=C[cur]
      if k<i:
        break
      else:
        heapq.heappush(H,(-l,k))
        cur+=1
    if H:
      ll,kk=heapq.heappop(H)
      ll=-ll
      ans+=ll
  H=[]
  cur=0
  for i in range(1,d+1)[::-1]:
    while cur<d:
      k,l=D[cur]
      if k<i:
        break
      else:
        heapq.heappush(H,(-l,k))
        cur+=1
    if H:
      ll,kk=heapq.heappop(H)
      ll=-ll
      ans+=ll
  print(ans)

Measured memory_bytes: 109604
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		String s = sc.next();
		
		// 計算
		long result = 0;
		int[][] dp = new int[n+1][n+1];
		for(int i = n - 1; i >= 0; i--){
		    for(int j = n - 1; j >= i; j--){
		        if(s.charAt(i) == s.charAt(j)){
		            dp[i][j] = dp[i + 1][j + 1] + 1;
		            result = max(result, min(dp[i][j], abs(j - i)));
		        }
		    }
		}
		
		// 出力
		System.out.println(result);
		
	}
}


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

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    string s,t;cin>>t>>s;
    for(int i=0;i<s.length()-t.length();i++)
    {
        int flag=1;
        for(int j=0;j<t.length();j++)
        {
            if(s[i+j]!=t[j])
            {
                flag=0;break;
            }
        }
        if(flag) 
        {
            cout<<"Yes"<<endl;return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
 } 

Measured memory_bytes: 3640
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 15

int V,E;
int POW[NUM];
int num_edge[NUM][NUM];
double dp[16384];
double P,P_POW[101];

int main(){

	for(int i = 0; i < NUM; i++)POW[i] = pow(2,i);

	scanf("%d %d %lf",&V,&E,&P);

	P /= 100.0;

	P_POW[0] = 1.0;
	for(int i = 1; i <= 100; i++)P_POW[i] = P*P_POW[i-1];

	for(int i = 0; i < V; i++){
		for(int k = 0; k < V; k++)num_edge[i][k] = 0;
	}

	int from,to;
	for(int loop = 0; loop < E; loop++){
		scanf("%d %d",&from,&to);
		from--;
		to--;
		num_edge[from][to]++;
		num_edge[to][from]++;
	}

	int num_node,sub_state,num_del_edge,base_node;
	vector<int> G,sub_G;

	for(int state = 1; state < POW[V]; state++){
		num_node = 0;
		G.clear();

		dp[state] = 1.0;

		for(int loop = 0; loop < V; loop++){
			if(state & (1 << loop)){
				G.push_back(loop);
				base_node = loop;
				num_node++;
			}
		}
		if(num_node == 1){
			continue;
		}

		for(int i = 1; i < POW[num_node]-1; i++){

			sub_state = 0;
			sub_G.clear();

			for(int loop = 0; loop < num_node; loop++){
				if(i & (1 << loop)){
					sub_state += POW[G[loop]];
					sub_G.push_back(G[loop]);
				}
			}

			if((sub_state & (POW[base_node]))  == 0)continue;

			num_del_edge = 0;

			for(int k = 0; k < sub_G.size(); k++){
				for(int a = 0; a < G.size(); a++){
					if(POW[G[a]] & sub_state)continue;

					num_del_edge += num_edge[sub_G[k]][G[a]];
				}
			}
			dp[state] -= dp[sub_state]*P_POW[num_del_edge];
		}
	}

	printf("%.10lf\n",dp[POW[V]-1]);

	return 0;
}



Measured memory_bytes: 3560
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
using namespace std;

const long long MOD = 1000000007;

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

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

    if(s[0] == s[1] && s[1] != s[2] && s[2] == s[3]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <queue>
#include <string>
#include <vector>

#define N 12

using namespace std;

int main() {
  // 隣接行列
  // int adjacent[N][N];
  string s;
  while(cin >> s) {
    vector<string> numStr(N);
    // 到達したかどうかを判断
    bool reached[N][N];

    numStr[0] = s;
    for(int i = 1; i < N; i++) {
      cin >> numStr[i];
    }

    for(int i = 0; i < N; i++) {
      for(int j = 0; j < N; j++) {
        // cout << numStr[i].at(j);
        reached[i][j] = false;
      }
      // cout << endl;
    }
    // cout << numStr[N+1];

    // 始点の選択
    queue<pair<int, int> > que;
    // 島の数
    int cnt = 0;
    for(int i = 0; i < N; i++) {
      for(int j = 0; j < N; j++) {
        if(reached[i][j] == false && numStr[i].at(j) == '1') {
          que.push(pair<int, int>(i, j));
          // その島のカウントをつける。
          cnt++;
          while(!que.empty()) {
            // popする値を保存する。
            int f = que.front().first;
            int s = que.front().second;
            // cout << "front = (" << f << "," << s << ")" << endl;
            // popする値をtrueに変更する。
            reached[f][s] = true;
            que.pop();

            // 右
            if(!(s == N-1)) {
              // cout << "log右" << endl;
              if(reached[f][s+1] == false && numStr[f].at(s+1) == '1') que.push(pair<int, int>(f, s+1));
            }
            // 左
            if(!(s == 0)) {
              // cout << "log左" << endl;
              if(reached[f][s-1] == false && numStr[f].at(s-1) == '1') que.push(pair<int, int>(f, s-1));
            }
            // 上
            if(!(f == 0)) {
              // cout << "log上" << endl;
              if(reached[f-1][s] == false && numStr[f-1].at(s) == '1') que.push(pair<int, int>(f+1, s));
            }
            // 下
            if(!(f == N-1)) {
              // cout << "log下" << endl;
              if(reached[f+1][s] == false && numStr[f+1].at(s) == '1') que.push(pair<int, int>(f+1, s));
            }

          }
        }
      }
    }
    cout << cnt << endl;
    // 終了判定
    // if(cin.eof()) break;
  }
}



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

using namespace std;

int main() {
    int n;
    cin >> n;
    unsigned long long a[n];
    unsigned long long result = 1;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        if(a[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }

    for(int i = 0; i < n; i++) {
        if(log10(result) + log10(a[i]) > 18) {
            cout << (-1) << endl;
            return 0;
        }
        if(a[i] > 1000000000000000000) {
            cout << (-1) << endl;
            return 0;
        }
        result *= a[i];
        if(result > 1000000000000000000) {
            cout << (-1) << endl;
            return 0;
        }
    }

    cout << result << endl;
}

Measured memory_bytes: 4740
import collections
s=input().strip()
t=input().strip()
s_list=[]
t_list=[]
for char in s:
    s_list.append(char)
for char in t:
    t_list.append(char)
s_collection=collections.Counter(s_list)
t_collection=collections.Counter(t_list)
s_countlist=[]
t_countlist=[]
for entry in s_collection.values():
    s_countlist.append(entry)
for entry in t_collection.values():
    t_countlist.append(entry)
s_countlist.sort()
t_countlist.sort()
if s_countlist == t_countlist:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 7088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef priority_queue<double, vector<double>, less<double> > QUE_double;
typedef priority_queue<int, vector<int>, less<int> > QUE_int;//lessは大きい順にならべるよ
const int MAX = pow(10, 5)+1;//+1しないとREになる(out of rangeになるんかな?? )



int main(){
  int N;
  string S;
  cin >> N >> S;
  int ans = 0;
  for(int i=2; i<N ; i++){
    if(S.at(i-2) == 'A'){
      if(S.at(i-1) == 'B'){
        if(S.at(i) == 'C'){
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
/*{{{*/
#include <bits/stdc++.h>
#define st first
#define nd second
#ifdef LOCAL
int c_;
#define cout (c_?cerr:cout)
#define debug(...) {cerr<<(!c_?"\033[96;1m":"");\
++c_;__VA_ARGS__;--c_;cerr<<(!c_?"\033[0m":"");}
#else
#define debug(...) {}
#endif
#define st first
#define nd second
#define dump_range(...) debug(cerr<<#__VA_ARGS__<<": ";print_range(__VA_ARGS__))
#define all(...) (__VA_ARGS__).begin(), (__VA_ARGS__).end()
#define dump(...) debug(print(#__VA_ARGS__,'=',__VA_ARGS__))
using namespace std; using ll = long long;
template< typename... t > using V = vector< t... >;
void print(){cout << '\n';}
template< typename t, typename... v >
void print(const t& a, const v&... b)
{cout << a << (sizeof...(b)?" ":"");print(b...);}
int argc_; char** argv_;
template< typename t > 
void print_range(t a, const t& b)
{while (a != b) cout << (*a++) << ' '; cout << '\n';}
/*thread_local mt19937 gen;
inline ll arg(int v, ll def = 0)
{return v < argc_? atoll(argv_[v]) : def;}
template< typename t >
t rng(t min, t max) 
{return uniform_int_distribution< t >{min, max}(gen);}*/
/*}}}*/

ll n, p;
V< pair< ll, int > > prim;

inline ll fpow(ll v, ll w)
{
    ll r = 1;
    while (w--)
        r *= v;
    return r;
}

int main(int argc, char** argv)
{
    argc_ = argc; argv_ = argv;
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //gen = mt19937(arg(1));

    cin >> n >> p;

    for (ll i = 2; i * i <= p; ++i)
    {
        if ((p % i) == 0)
        {
            prim.push_back({i, 0});
            while ((p % i) == 0)
                ++prim.back().nd, p /= i;
        }
    }

    if (p > 1)
        prim.push_back({p, 1});

    ll res = 1;
    for (auto q : prim)
        res *= fpow(q.st, q.nd / n);

    print(res);
}

Measured memory_bytes: 256
/*bismillah ->                                                                                                         << Suirkhanov Meyirlan >>
  GL HF


                                                                                                                      42

    bless my code =)
                                                                                                            NEVER FOLLOW YOUR RULES :D HAHAHAHA
*/


///scanf ("%d%d", &x, &y);
///printf("%d", &a)

#include <bits/stdc++.h>

#define fast ios_base::sync_with_stdio();   cin.tie(0);   cout.tie(0);
#define randoperation srand(time(0));
#define pii pair < int , int >
#define pll pair < ll, ll >
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define fast ios_base::sync_with_stdio();   cin.tie(0);   cout.tie(0);
#define randoperation srand(time(0));

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll N = 1e6 + 7;
const ld pi = 3.14159265359;
const int INF = 1e9 + 7;
const double eps = 1e-9;

const int xi[4] = {-1, 0, +1, 0};
const int yj[4] = {0, +1, 0, -1};
const int xxi[4] = {+1, 0, -1, 0};
const int yyj[4] = {0, -1, 0, +1};

string s;

int k;

int main(){

  //freopen("bridge.in", "r", stdin);
  //freopen("bridge.out", "w", stdout);

  fast
  randoperation;

  ///           ||
  ///start here \/

  cin >> s >> k;

  for(int i = 0; i < k; i++){
    if(s[i] != '1'){
      cout << s[i] << '\n';
      return 0;
    }

    if(i + 1 == s.size()){
      break;
    }
  }

  cout << 1;
}


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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    int w, h, n; cin >> w >> h >> n;

    int x1 = 0;
    int x2 = w;
    int y1 = 0;
    int y2 = h;

    for (int i = 0; i < n; ++i) {
        int x, y, a; cin >> x >> y >> a;

        if (a == 1) {
            x1 = max(x1, x);
        }

        if (a == 2) {
            x2 = min(x2, x);
        }

        if (a == 3) {
            y1 = max(y1, y);
        }

        if (a == 4) {
            y2 = min(y2, y);
        }
    }

    if (x2 - x1 < 0 || y2 - y1 < 0) {
        cout << 0 << endl;
    } else {
        cout << (x2 - x1) * (y2 - y1) << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,c,x,y;scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&x,&y);c *= 2;
  printf("%lld\n",min({a*x+b*y,min(x,y)*c+(x-min(x,y))*a+(y-min(x,y))*b,max(x,y)*c}));
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define pb push_back
const int maxn = 1000005;
int u[maxn];
int cur[maxn];
int need[maxn];
vector<pair<int,int> >e;
vector<int>g[maxn];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;
	while(cin >> s){
		sort(s.begin(),s.end());
		if(s[0]==s[1]&&s[2]==s[3]&&s[1]!=s[2]){
			cout<<"Yes"<<endl;
		}
		else{
			cout<<"No"<<endl;
		}
	}
}

Measured memory_bytes: 24832
#include <bits/stdc++.h>
using namespace std;
int n,a,sam,sum;
int main () {
cin >> n;
sam = 1000000000;
for (int i=1 ; i<=n; i++) {
	cin >> a;
	sum = max(a , sum);
	sam = min(a , sam);
	
}
cout << sum - sam << endl;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=II()
  l=LI()

  l1=[]
  l2=[]

  for i in range(len(l)):
    if i%2==0:
      l1.append(l[i])
    else:
      l2.append(l[i])

  l1.sort()
  l2.sort()

  a1=[l1[0],1]
  a2=[0,0]
  b1=[l2[0],1]
  b2=[0,0]

  _a=l1[0]
  c1=1
  for x in l1[1:]:
    if _a==x:
      c1+=1
    else:
      if c1>a1[1]:
        if a1[0]!=l1[0]:
          a2[0]=a1[0]
          a2[1]=a1[1]
        a1[0]=_a
        a1[1]=c1
      elif c1>a2[1]:
        if a1[0]!=_a:
          a2[0]=_a
          a2[1]=c1
      _a=x
      c1=1
  if c1>a1[1]:
    if a1[0]!=l1[0]:
      a2[0]=a1[0]
      a2[1]=a1[1]
    a1[0]=_a
    a1[1]=c1
  elif c1>a2[1]:
    if a1[0]!=_a:
      a2[0]=_a
      a2[1]=c1

  _b=l2[0]
  c2=1
  for x in l2[1:]:
    if _b==x:
      c2+=1
    else:
      if c2>b1[1]:
        if b1[0]!=l2[0]:
          b2[0]=b1[0]
          b2[1]=b1[1]
        b1[0]=_b
        b1[1]=c2
      elif c2>b2[1]:
        if b1[0]!=_b:
          b2[0]=_b
          b2[1]=c2
      _b=x
      c2=1
  if c2>b1[1]:
    if b1[0]!=l2[0]:
      b2[0]=b1[0]
      b2[1]=b1[1]
    b1[0]=_b
    b1[1]=c2
  elif c2>b2[1]:
    if b1[0]!=_b:
      b2[0]=_b
      b2[1]=c2

  if a1[0]!=b1[0]:
    return len(l1)-a1[1]+len(l2)-b1[1]
  else:
    return min(len(l1)-a1[1]+len(l2)-b2[1],len(l1)-a2[1]+len(l2)-b1[1])

# main()
print(main())


Measured memory_bytes: 18212
#include <bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair <int,int> PAIR;
const int N = 2e6+5;
const ll M = 998244353;
struct node{
	int x,y;
}a[N];
bool cmp(node p1,node p2){
	return p1.x-p1.y>p2.x-p2.y;
}
int main() {
	int n;
	string s;
	cin>>n;
	getchar();
	int le=0,ri=0;
	for(int i=1;i<=n;i++){
		getline(cin,s);
		int l=0,r = 0;
		for(int j=0;j<s.length();j++){
			if(s[j]==')'){
				if(l>0) l--;
				else r++;
			}else {
				l++;
			}
		}
		if(l&&!r) le+=l;
		else if(r&&!l) ri+=r;
		else a[i].x = l,a[i].y=r;
	}
	sort(a+1,a+1+n,cmp);
	int l = le,r = ri;
	for(int i=1;i<=n;i++){
		if(l<a[i].y){
			cout<<"No\n";
			return 0;
		}else {
			l-=a[i].y;
			l+=a[i].x;
		}
	}
	if(l!=r) cout<<"No\n";
	else cout<<"Yes\n";
	return 0;
}


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

int main(){
    ll N;
    cin >> N;
    ll ans = 0,i = 1,ma = sqrt(N);
    while(i <= ma){
        if(N % i == 0 && N/i > i+1){
            ans += N/i - 1;
        }
        i++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
#define fr(i,a,b) for(int i = a;i <= b;++i)
using namespace std;
int main(){
	int n,m,a;
	cin>>n>>m;
	if((m-1) % (n-1))cout<<(m-1)/(n-1)+1;
	else cout<<(m-1)/(n-1);
	return 0;
}

Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! { in_n: i64};
    let mut count: i64 = 0;

    for i in 1..in_n + 1 {
        if i % 3 != 0 && i % 5 != 0 {
            count += i;
        }
    }

    println!("{}", count);
}


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

#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define rev(v) reverse(v.begin(), v.end());
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));
 
using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

signed main(){
    io();
    ll a, b; cin >> a >> b;
    cout << a*b/__gcd(a,b) << '\n';
    return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;

typedef long long ll;

struct Card { char suit, value; };

// 左のカードと比較し続ける
void bubbleSort(Card cards[], int n) {
    // 5枚のカードを1枚ずつループ
    REP(i, n) {
        // 5枚目のカードからi枚目まで一枚ずつ比較して入れ替える
        for (int j = n-1; j >= i; --j) {
            // もしj枚目のカードよりj-1枚目のカードの方が大きい場合swap
            if (cards[j].value < cards[j-1].value) {
                swap(cards[j], cards[j-1]);
            }
            // 左のカードとの比較を繰り替えす
        }
    }
}

// 最小値を取り続ける
void selectionSort(Card cards[], int n) {
    int minj;
    // 5枚のカードを1枚ずつループ
    REP(i, n) {
        minj = i;
        // i枚目のカードから5枚目までループ
        FOR(j, i, n) {
            if (cards[j].value < cards[minj].value) {
                minj = j;
            }
        }
        swap(cards[i], cards[minj]);
    }
}

void printCards(Card cards[], int n) {
    REP(i, n) {
        cout << cards[i].suit << cards[i].value;
        if (i < n-1) {
            cout << ' ';
        } else {
            cout << endl;
        };
    };
}

bool isSame(Card a[], Card b[], int n) {
    REP(i, n) if (a[i].suit != b[i].suit) return false;
    return true;
}

int main() {
    int n;
    cin >> n;

    Card cards1[n];
    Card cards2[n];

    // 入力の読み込み
    REP(i, n) cin >> cards1[i].suit >> cards1[i].value;
    // 配列をコピー
    REP(i, n) cards2[i] = cards1[i];

    bubbleSort(cards1, n);
    printCards(cards1, n);

    // バブルソートは安定ソート
    cout << "Stable" << endl;

    selectionSort(cards2, n);
    printCards(cards2, n);

    bool isStable = isSame(cards1, cards2, n);
    if (isStable){
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }
}



Measured memory_bytes: 3092
#include<stdio.h>
#define MAX 10
#define rep(i, n) for ( int i = 0; i < n; i++)
main(){
    int P[MAX+4][MAX+4];
    int dx[13] = {0, 1, 0, -1, 0, 1, -1, -1, 1, 2, 0, -2, 0};
    int dy[13] = {0, 0, -1, 0, 1, -1, -1, 1, 1, 0, -2, 0, 2};
    int x, y, size, empty = 0, maxv = 0;
    rep(y,MAX+4) rep(x,MAX+4) P[y][x] = 0;
    while ( scanf("%d,%d,%d", &x, &y, &size) != EOF ) {
	x += 2; y += 2;
	rep(r,size*4+1) P[y + dy[r]][x + dx[r]]++;
    }
    for ( int y = 2; y <= 11; y++ ){
        for ( int x = 2; x <= 11; x++ ){
            if ( P[y][x] == 0 ) empty++;
            if ( P[y][x] > maxv ) maxv = P[y][x];
        }
    }
    printf("%d\n%d\n", empty, maxv);
}

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

namespace AtCoder
{
    partial class Program
    {
        static void Main(string[] args)
        {
       
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var n = input[0];
            var d = input[1];

            var xs = new int[n][];
            for (int i = 0; i < n; i++)
            {
                var x = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                xs[i] = x;
            }

            var count = 0;


            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < i; j++)
                {
                    var sum = 0d;

                    for (int k = 0; k < d; k++)
                    {
                        sum += Math.Pow(xs[i][k] - xs[j][k], 2);
                    }

                    var rt = Math.Sqrt(sum).ToString();

                    if (rt.IndexOf('.') < 0)
                    {
                        count++;
                    }
                }
            }

            Console.WriteLine(count);
        }

    }
}

Measured memory_bytes: 13396
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

answer = 0
previous_index = n + 1

for number in a:
    answer += b[number - 1]

    if number == previous_index + 1:
        answer += c[previous_index - 1]

    previous_index = number

print(answer)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
ll dp[406][406];
ll a[406];
auto sum=[&](int l,int r){
	ll s=0;
	for(int i=l;i<=r;i++){
		s+=a[i];
	}
	return s;
};
int main(){
	ll n;
	cin>>n;

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

for(int i=n-1;i>=0;i--){
	for(int j=i;j<n;j++){
		if(j==i){
			dp[i][j]=0;
			}
			else{
				dp[i][j]=1e18+5;
				ll s=sum(i,j);
				for(int k=i;k<=j-1;k++){
					dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+s);
				}
			}
	}
}
	cout<<dp[0][n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1536
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE Unsafe #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE FlexibleContexts #-}

import Data.Bits
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BSL
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IMS
import Data.IntSet (IntSet)
import qualified Data.IntSet as IS
import qualified Data.Sequence as Seq
import Data.Sequence (Seq)
import qualified Data.Array.IArray as A
import qualified Data.Array.MArray.Safe as A
import qualified Data.Array.MArray as A
import Data.Array (Array)
import Data.Array.Unboxed (UArray)
import Data.Array.IArray (IArray)
import Data.Array.MArray.Safe (MArray)
import Data.Array.IO.Safe (IOArray, IOUArray)
import Data.Array.ST.Safe (STArray, STUArray, runSTArray, runSTUArray)
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Monad.ST
-- import Control.Monad.ST.Safe
import Control.Applicative
import Data.Maybe
import Data.Tuple
import Data.Ord
import Control.Monad.State.Strict
import Data.Int
import System.IO
import Data.Function
import Control.Monad.Primitive
import qualified Data.Vector.Primitive.Mutable as VPM
import qualified Data.Vector.Generic.Mutable as VGM
import Data.STRef


main :: IO ()
main = do
  n <- read <$> getLine
  vs <- VU.unfoldrN n (runStateT $ (,,) <$> rInt <*> rInt <*> rInt)
        <$> BSL.getContents
  print $ query vs

rInt :: StateT BSL.ByteString Maybe Int
rInt = StateT $ BSL.readInt <$> BSL.dropWhile (<'!')

query :: VU.Vector (Int,Int,Int) -> Int
query = (\(acc_a,acc_b,acc_c) -> max acc_a $ max acc_b acc_c)
  . VU.foldl' (\(!acc_a,!acc_b,!acc_c) (!ak,!bk,!ck)
                 -> (ak + max acc_b acc_c,
                     bk + max acc_c acc_a,
                     ck + max acc_a acc_b)) (0,0,0)


Measured memory_bytes: 2300
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    int N; cin >> N;
    VL A(N);
    REP(i,N) cin >> A[i];
    LL num = 1000 / A[0], val = A[0], rem = 1000 % A[0];
    
    FOR(i,1,N){
        if(A[i] == A[i-1]) continue;
        if(A[i] > A[i-1]) val = A[i];
        else{
            LL money = val * num + rem;
            num = money / A[i];
            val = A[i];
            rem = money % A[i];
        }

    }
    cout << val * num + rem << endl;

}

Measured memory_bytes: 3652
#if __has_include("noamoa_atcoder_lib.h")
#include "noamoa_atcoder_lib.h"
#else
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define endl '\n'
#define all(x) (x).begin(),(x).end()
namespace atcoder {
	using namespace std;
	using ll = long long;
	using llv = vector<ll>;
	using intv = vector<int>;
	using charv = vector<char>;
	using boolv = vector<bool>;
	using floatv = vector<float>;
	using doublev = vector<double>;
	using stringv = vector<string>;

	constexpr ll MOD7 = 1000000007;
	constexpr ll MOD9 = 1000000009;

	template<typename T>
	void init(vector<T>& v, T initVal = T()){
		for(auto& e : v){
			e = initVal;
		}
	}

	template<typename T>
	void sort(vector<T>& v){
		sort(all(v));
	}
	template<typename T>
	void sortInv(vector<T>& v){
		sort(all(v), greater<T>());
	}

	template<typename T>
	T sum(const vector<T>& v){
		T ret = 0;
		for(const auto& e : v) ret += e;
		return ret;
	}

	template<typename T>
	inline vector<T>& operator+=(vector<T>& v, const T& e){
		v.push_back(e);
		return v;
	}

	template<typename T1, typename T2>
	inline vector<T1>& operator+=(vector<T1>& v1, const vector<T2>& v2){
		for(const auto& e : v2) v1.push_back(e);
		return v1;
	}

	template<typename T>
	void in(vector<T>& v){
		for(auto& e : v) cin >> e;
	}

	template<typename T1, typename T2>
	void in(vector<T1>& v1, vector<T2>& v2){
		for(int i=0;i<v1.size();i++)
			cin >> v1[i] >> v2[i];
	}
	template<typename T1, typename T2, typename T3>
	void in(vector<T1>& v1, vector<T2>& v2, vector<T3>& v3){
		for(int i=0;i<v1.size();i++)
			cin >> v1[i] >> v2[i] >> v3[i];
	}
	template<typename T1, typename T2, typename T3, typename T4>
	void in(vector<T1>& v1, vector<T2>& v2, vector<T3>& v3, vector<T4>& v4){
		for(int i=0;i<v1.size();i++)
			cin >> v1[i] >> v2[i] >> v3[i] >> v4[i];
	}

	template<typename T>
	istream& operator>>(istream &stream, vector<T>& v){
		for(auto& e : v) stream >> e;
		return stream;
	}

	template<typename T>
	void out(const vector<T>& v){
		for(const auto& e : v) cout << e << ' ';
		cout << endl;
	}

	template<typename T>
	void outln(const vector<T>& v){
		for(const auto& e : v) cout << e << endl;
	}

	constexpr ll modPow(ll x, ll n, ll m){ // O(logn)
		if(n == 0) return 1;
		else if(n % 2 == 0) return modPow((x * x) % m, n / 2, m);
		else return x * modPow(x, n - 1, m) % m;
	}
}
using namespace atcoder;
#endif

int main(){
	cout << fixed << setprecision(15);

	int K;cin>>K;

	queue<ll> q;
	for(int i=1;i<=9;i++) q.push(i);

	ll n;
	for(int i=0;i<K;i++){
		n = q.front();
		q.pop();

		if(n%10!=0) q.push(n*10+n%10-1);
		q.push(n*10+n%10);
		if(n%10!=9) q.push(n*10+n%10+1);
	}
	cout << n;
}


Measured memory_bytes: 1792
# AtCoder Beginner Contest 135
# B - 0 or 1 Swap

N=int(input())
p=list(map(int,input().split()))

S={}
s=N+1

for i in range (N):
    if p[i]==i+1:
        pass
    else :
        S[i+1]=p[i]
        s=i+1


if len (S)==0:
    print('YES')
    exit()
elif len(S)>2:
    print('NO')

else:
    n=S[s]
    if S[n]==s:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 9212
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <functional>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <valarray>
#include <algorithm>
#include <time.h>
#include <cstdlib>
#include <iomanip>

using namespace std;

int main (void)
{
	long double s[1000],Hei,kari;

	long int n;

for (long int A = 0; A < 1000; A++)
{
		cin >> n;

		if (n == 0)
		{
			break;
		}


	for (long int i = 0; i < n; i++)
	{
		cin >> s[i];
		Hei += s[i];

	}

	for (long int i = 0; i < n; i++)
	{
		kari += (s[i] - Hei / n) * (s[i] - Hei / n);
	}


	cout << fixed << setprecision(8) << sqrt(kari / n) << endl;

	Hei = 0;
	kari = 0;

}
}

Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    string s;
    cin >> s;
    s[3] = '8';
    cout << s << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;
using P = pair<int, int>;
int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1}, dy[8] = {1,1,1,0,0,-1,-1,-1};


int main() {
    u32 h, w;
    cin >> h >> w;
    vector<vector<char>> v(h+2, vector<char>(w+2, '.'));
    for (int i = 1; i <= h; ++i) {
        string k;
        cin >> k;
        for (int j = 1; j <= w; ++j) {
            v[i][j] = k[j-1];
        }
    }
    for (int i = 1; i <= h; ++i) {
        for (int j = 1; j <= w; ++j) {
            if(v[i][j] == '#') continue;
            int cnt = 0;
            for (int k = 0; k < 8; ++k) {
                if(v[i+dx[k]][j+dy[k]] == '#') cnt++;
            }
            v[i][j] = char('0' + cnt);
        }
    }
    for (int i = 1; i <= h; ++i) {
        for (int j = 1; j <= w; ++j) {
            cout << v[i][j];
        }
        cout << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <string.h>
using namespace std;
int main()
{
    int a,b,k;
    cin>>a>>b>>k;
    for(int i=0;i<k;i++)
    {
        if(i%2==0)
        {
            if(a%2==1)
            {
                a--;
            }
            a=a/2;
            b=b+a;
        }
        else
        {
            if(b%2==1)
            {
                b--;
            }
            b=b/2;
            a=b+a;
        }
    }
    cout<<a<<" "<<b<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
// #define DEBUGGING

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }

namespace __init {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

V<ll> ans;

void calc(ll N, ll K, const V<ll> &P, ll dec) {
    DEBUG(N, dec);
    if(N == 0) return;
    
    ll val = K / 2 + 1;
    dec += (N % 2 == 0);
    
    if(N <= P.size()) {
        ll perm = P[N - 1] + (N > 1);
        ll div = dec / perm;
        ll min_dec = dec;
        ll min_val = val;
        for(ll plus = 0; plus <= 1; plus++) {
            for(ll i = -2; i <= 2; i++) {
                ll dtmp = dec + (plus ? 1 : -1) * (div + i) * perm;
                if(abs(dtmp) < abs(min_dec)) {
                    min_dec = dtmp;
                    min_val = val + (plus ? 1 : -1) * (div + i);
                }
            }
        }
        dec = min_dec;
        val = min_val;
    }
   
    DEBUG(dec, val);
    if(val == 0) return;
    // if(dec != 0) calc(N - 1, K, P, dec);
    calc(N - 1, K, P, dec);
    ans.push_back(val);
}

int main() {
    ll N, K;
    cin >> K >> N;
    
    if(K % 2 == 0) {
        cout << K / 2;
        for(ll i = 1; i < N; i++) cout << ' ' << K;
        cout << endl;
        return 0;
    }

    V<ll> P = { 1, K };
    DEBUG(P);
    while(P.back() <= N) {
        ll tmp = P.back();
        P.push_back((1 + tmp) * K);
    }
    calc(N - 1, K, P, (N % 2 == 0));
    ans.push_back(K / 2 + 1);
    reverse(ALL(ans));
    // while(ans.back() == 0) ans.pop_back();
    for(ll e : ans) cout << e << ' ';
    cout << endl;
    return 0;
}



Measured memory_bytes: 28272
#include <stdio.h>

int main(void) {
	int h, w;
	int i, j;
	
	while(1) {
		scanf("%d %d", &h, &w);
		if(h == 0 && w == 0) {
			break;
		}
		
		for(i = 0; i < h; i++) {
			for(j = 0; j < w; j++) {
				if(i == 0 || i == h - 1 || j == 0 || j == w - 1) {
					printf("#");
				} else {
					printf(".");
				}
			}
			
			printf("\n");
		}
		
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 572
import scala.io.StdIn

object Main extends App {
  val Array(h, w) = StdIn.readLine().split(" ").map(_.toInt)
  var strArr = new Array[String](h)
  for(r <- 0 to h - 1) strArr(r) = StdIn.readLine()

  println(Array.fill(w+2)("#").mkString)
  strArr.foreach(str => println(s"#$str#"))
  println(Array.fill(w+2)("#").mkString)

}

Measured memory_bytes: 26244
n, w = map(int, input().split())

dp = [[0] * (w + 1) for _ in range(n + 1)]
# (v, w)
weight = []
value = []
for _ in range(n):
    v, we = map(int, input().split())
    weight.append(we)
    value.append(v)

# dp[i+1][w] i番目までの品物の中から重さがWを超えないように選んだ時の価値の総和の最大値
#              weight[i]を引いた時の最大値
# dp[i+1][w] = dp[i][w-weight[i]]+value[i]
# 入れない時
# dp[i+1][w] = dp[i][w]

for i in range(n):
    for j in range(w+1):
        if j >= weight[i]:
            dp[i + 1][j] = max(dp[i][j - weight[i]] + value[i], dp[i][j])
        else:
            dp[i + 1][j] = dp[i][j]

# print(dp)
# print(weight)
# print(value)
print(dp[n][w])



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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

vector<ll> dv;
void divisor(ll n)
{
    for (int i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            dv.push_back(i);
            if (i * i != n)
                dv.push_back(n / i);
        }
    }
    sort(ALL(dv));
}

int main()
{
    int n, m;
    cin >> n >> m;

    divisor(m);

    int ans = 1;
    rep(i, dv.size())
    {
        if (m >= n * dv[i])
            ans = dv[i];
    }

    OP(ans);

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
using namespace std;

#define ll long long

int main()
{
    vector<ll> A(3);
    scanf("%lld %lld %lld", &(A[0]), &(A[1]), &(A[2]));

    sort(A.begin(), A.end());
    ll ans = A[2] - A[0];
    printf("%lld", ans);
}


Measured memory_bytes: 256