akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define forn(i, n) for (llong i = 0ll; i < (llong) n; ++i)
#define fornn(i, l, r) for (llong i = (llong) l; i < (llong) r; ++i)
#define size(x) ((int) (x.size()))
 
using namespace std;
 
typedef long long llong;
const llong inf = (llong) 1e+9 + 7ll;
const llong linf = (llong) 1e+18 + 7ll;
const long double eps = (long double) 1e-9;
const long double pi = acosl((long double) -1.0);
const int alph = 26;

mt19937 mrand(random_device{} ()); 

template<typename T, typename U> inline llong umin(const T& a, const U& b) { return a < b ? a : b; }
template<typename T, typename U> inline llong umax(const T& a, const U& b) { return a > b ? a : b; }
 
static char buff[(int) 2e6 + 17]; // reads std::string
const int maxn = (int) 2e3 + 17;

llong L, R;

bool read()
{
	if (scanf("%lld %lld", &L, &R) != 2)
		return false;

	return true;
}

void solve()
{
	if (L == R)
		return void(printf("1\n"));
	
	int m = 61;
	for (; ((L >> m) & 1ll) == ((R >> m) & 1ll); --m);

	L &= (1ll << (m + 1)) - 1;
	R &= (1ll << (m + 1)) - 1;
	
	llong M = 1ll << m;
	map<llong, int> mp;
	++mp[L], --mp[M];

	int mm = 0;
	for (; M + (1ll << mm) <= R; ++mm);
	++mp[M], --mp[M + (1ll << mm)];
	++mp[M + L], --mp[2ll * M];

	llong l = -1, ans = 0;
	int cur = 0;

	for (auto i : mp)
	{
		if (l == -1)
			l = i.first;

		cur += i.second;

		if (cur == 0)
		{
			ans += i.first - l;
			l = -1;
		}
	}

	assert(l == -1);
	printf("%lld\n", ans);
}

int main()
{
#if SEREZHKA
	freopen("file.in", "r", stdin);
#endif

	while (read())
		solve();

	return 0;
}


Measured memory_bytes: 384
import java.io.*;
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class Main {

    static int N;
    static Pile[] P;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        N = sc.nextInt();

        P = new Pile[N];
        for (int i = 0; i < N; i++) {
            int size = sc.nextInt();
            P[i] = new Pile(i+1, size);
        }

        PrintWriter pw = new PrintWriter(System.out);
        for (long l : solve()) {
            pw.println(l);
        }
        pw.flush();
    }

    static long[] solve() {
        Arrays.sort(P, (p1, p2) -> {
            if( p1.size != p2.size ) {
                return Integer.compare(p2.size, p1.size); // sizeで降順
            } else {
                return Integer.compare(p1.no, p2.no);
            }
        });

        long[] cnt = new long[N];

        Pile first = P[0];
        int no = first.no;
        int size = first.size;
        for (int i = 1; i < N; i++) {
            Pile p = P[i];
            if( p.size != size ) {
                int diff = size - p.size;
                cnt[no-1] += (long)diff * (i);
                if( p.no < no ) {
                    no = p.no;
                }
                size -= diff;
            }
        }
        cnt[no-1] += (long)size * N;
        return cnt;
    }

    static class Pile {
        int no, size;

        public Pile(int no, int size) {
            this.no = no;
            this.size = size;
        }
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 47084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
//void chmin(int &a, int b) { if (a > b) a = b; }
//void chmax(int &a, int b) { if (a < b) a = b; }

const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}



int main() {
    int n;
    string s,ans = {};
    cin >> n >> s;
    for (int i = 0; i < s.size(); ++i) {
        int x = s[i]-'A';
        x += n;
        x %= 26;
        s[i] = 'A' + x;
        cout << s[i];
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>

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

typedef std::vector<int> v;
typedef std::vector<std::vector<int>> vv;
typedef unsigned long long ull;

int main(void)
{
    int n;
    scanf("%d", &n);
    n = n % 100 % 10;
    if (n == 3)
    {
        puts("bon");
    }
    else if (n == 0 || n == 1 || n == 6 || n == 8)
    {
        puts("pon");
    }
    else
    {
        puts("hon");
    }
}

Measured memory_bytes: 3192
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        new Program().Calc();
    }

    Scanner cin;

    public Program() { }

    bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }

    void Calc()
    {
        cin = new Scanner();

        string s = cin.next();
        string t = cin.next();

        char[] s_ = s.ToCharArray();
        char[] t_ = t.ToCharArray();

        bool ans = true;

        for (int i = 0; i < s_.Length; ++i)
        {
            if (s_[i] != t_[i])
            {
                ans = false;
                break;
            }
        }

        WriteLine(ans? "Yes" : "No");

    }
}

public static class StringExtension
{
    public static char GetChar1(this string str, int indexOneBase)
    {
        return str[indexOneBase - 1];
    }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 25808
#pragma GCC optimize("Ofast", "unroll-loops")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

int bitcount(int f) {
	int res = 0;
	for (int i = 0; i < 32; ++i)
		if (f & (1 << i))
			++res;
	return res;
}

signed main() {
	int n; cin >> n;
	vector<int> a(n);
	vector<vector<pair<int, int>>> xy(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		for (int j = 0; j < a[i]; ++j) {
			int x, y;
			cin >> x >> y;
			xy[i].emplace_back(--x, y);
		}
	}

	int ans = 0;
	for (int flg = 0; flg < (1 << n); ++flg) {
		bool ok = true;
		for (int i = 0; i < n; ++i) {
			if (flg & (1 << i)) { // i人目が正直者
				for (auto xyi : xy[i]) {
					if (xyi.second && !(flg & (1 << xyi.first)))
						ok = false;
					if (!(xyi.second) && (flg & (1 << xyi.first)))
						ok = false;
				}
			}
		}
		if (ok)
			ans = max(ans,bitcount(flg));
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc=new Scanner(System.in);
        int ans=0;

        int m=sc.nextInt();
        int f=sc.nextInt();
        int b=sc.nextInt();

        if (b-m<=0) { ans=0; }
        else if (m+f<b) {System.out.println("NA"); System.exit(0);}
        else { ans=b-m; }

        System.out.println(ans);
    }
}


Measured memory_bytes: 26320
#include<bits/stdc++.h>
using namespace std;
int a,s,d,f,g,h,j,k,l,i,n,m;
set<int> q;
main(){
    cin>>n;

    for(i=0;i<n;i++){
        cin>>a;
        k=max(k,a);
        q.insert(a);

    }
    q.insert(0);
    q.insert(k+1);
    q.erase(k);
    j=*q.lower_bound(k/2);
    h=*--q.lower_bound(k/2);
    cout<<k<<" ";
    if(k/2-h<j-(k+1)/2) cout<<h; else cout<<j;
}


Measured memory_bytes: 4992
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	ll N, Y;
	cin >> N >> Y;


	for (int i = 0; i <= N; i++) {
		for (int j = 0; i + j <= N; j++) {


			if (10000 * i + 5000 * j + 1000 * (N - i - j) == Y) {
				cout << i <<" "<< j << " " << N - i - j << endl;
				return 0;
			}



		}
	}

	cout << "-1 -1 -1" << endl;





}


Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
        int a, b;
        scanf("%d%d", &a, &b);
        if(a < b) {
                printf("a < b\n");
        } else if(a > b) {
                printf("a > b\n");
        } else {
                printf("a == b\n");
        }
        return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include<vector>
using namespace std;
typedef long long ll;
//#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i =0;i<n;++i)
//#define mod (ll)(1e9+7)
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll K;
    cin >> K;
    ll ans;
    int A[K];
    ll sum = 0;
    REP(i,K) {
        cin >> A[i];
        A[i]=A[i]-(i+1);
    }
    sort(A,A+K);
    REP(i,K) sum += (A[i]-A[0]);
    ans = sum;
    int f = 0;
    for(int i=A[0];i<=A[K-1];i++){
        while(f<K){
            if(A[f]>i) break;
            f++;
        }
        sum+=(f);
        sum-=(K-f);
        ans = min(ans,sum);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

typedef struct {
    int flip;
    long long rotate;
} Query;

long long n, k, q;

Query tree[(1 << 20) * 2];

void  build(long long _n);
Query merge(Query a, Query b);
void  update(Query data, long long i);
Query sum(void);

int main()
{
    long long _n;
    long long a;

    scanf("%lld %lld %lld", &k, &_n, &q);

    build(_n);

    for (long long i = 0; i < _n; i++) {
        scanf("%lld", &a);

        Query data = {0, 0};

        if (a == 0) data.flip = 1;
        else data.rotate = -a;

        update(data, i);
    }

    for (long long i = 0; i < q; i++) {
        long long left, right;
        Query l, r;
        scanf("%lld %lld", &left, &right);
        left--;
        right--;

        l = tree[left + n - 1];
        r = tree[right + n - 1];

        update(l, right);
        update(r, left);


        Query total = sum();

        long long num;
        if (total.rotate < 0) total.rotate = k + total.rotate;
        num = 1 + total.rotate;

        if (total.flip) {
            if (num == 1) num *= -1;
            else num = ((k + 2) - num) * -1;
        }

        printf("%lld\n", num);
        //        printf("%d %lld\n", total.flip, total.rotate);
    }
    
    return 0;
}

void  build(long long _n)
{
    n = 1;

    while (n < _n) {
        n *= 2;
    }

    for (long long i = 0; i < 2 * n; i++) {
        tree[i] = (Query){0, 0};
    }

    return;
}

Query merge(Query a, Query b)
{
    Query x;

    x.flip = (a.flip + b.flip) % 2;

    if (b.flip) {
        x.rotate = (b.rotate - a.rotate) % k;
    } else {
        x.rotate = (a.rotate + b.rotate) % k;
    }

    return x;
}

void update(Query data, long long i)
{
    i += n - 1;

    tree[i] = data;

    while (i != 0) {
        i = (i - 1) / 2;
        tree[i] = merge(tree[i * 2 + 1], tree[i * 2 + 2]);
    }

    return;
}

Query sum(void)
{
    return tree[0];
}



Measured memory_bytes: 6868
import itertools
nt,mt,qt = input().split()
n, m, q = int(nt), int(mt), int(qt)
a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q
nums = [0]*m
for i in range(q):
	a[i], b[i], c[i], d[i] = map(int, input().split())
for i in range(m):
	nums[i] = i
ans = 0
for i in itertools.combinations_with_replacement(nums, n):
	anstmp = 0
	for j in range(q):
		if i[b[j]-1] - i[a[j]-1] == c[j]:
			anstmp += d[j]
	if anstmp > ans:
		ans = anstmp
print(ans)

Measured memory_bytes: 9240
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================

	ll N;
	cin >> N;

	vpll XL(N);
	for (int i = 0; i < N; i++) {
		cin >> XL[i].first >> XL[i].second;
	}

	vpll LR(N);
	for (int i = 0; i < N; i++) {
		LR[i].first = XL[i].first - XL[i].second;
		LR[i].second = XL[i].first + XL[i].second;

	}


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

	ll ans = 0;
	ll before = 0;
	ll next = 1;
	for (int i = 0; i < N - 1; i++) {

		// 共通部分を持つとき
		if (LR[before].second > LR[next].first
			&& LR[before].second < LR[next].second) {

			before = before;
			next++;
			ans++;
		}
		// 真部分集合の時
		else if (LR[before].second >= LR[next].first
			&& LR[before].second >= LR[next].second) {

			before = next;
			next++;
			ans++;
		}
		// 重なってないとき
		else {
			before = next;
			next++;
		}

	}


	cout << N - ans;






}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll int64_t
#define all(v) v.begin(), v.end()

int permutation(int n){
  int P=1;
  while(n>1){
    P*=n;
    n--;
  }

  return P;
}


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

  vector<int> P(N);
  vector<int> Q(N);

  rep(i,N) cin >> P.at(i) ;
  rep(i,N) cin >> Q.at(i) ;

  vector<int> order(N);//初期順列の作成
  rep(i,N) order.at(i)=i+1;//i+1とすることで、1~Nで初期化

  int a=0,b=0,ai=0,bi=0;

  do{
    ai++; bi++;
    bool eqP=true,eqQ=true;
    rep(i,N){
      if(order.at(i)!=P.at(i)) eqP=false;
      if(order.at(i)!=Q.at(i)) eqQ=false;
    }
    if(eqP) a=ai;
    if(eqQ) b=bi;

  }while(next_permutation(all(order)));


  if(a>b){
    cout << a-b << endl;
  }
  else{
    cout << b-a << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn.{readInt, readLine}
object Main {
    def main(args: Array[String]): Unit = {
        val len = readInt
        val arr = readLine.split(" ").map(_.toInt)
        val (ret, cnt) = bubbleSort(len, arr)
        println(ret.mkString(" ") + "\n" + cnt)
    }
    
    def bubbleSort(len: Int, arr: Array[Int]): (Array[Int], Int) = {
        val ret = new Array[Int](len)
        arr.copyToArray(ret)
        var cnt = 0
        (1 until len).foreach { i =>
            (i until len).reverse.foreach { j =>
                if (ret(j - 1) > ret(j)) {
                    cnt += 1
                    swap(ret, j, j - 1)
                }
            }
        }
        (ret, cnt)
    }
    
    def swap(arr: Array[Int], a: Int, b: Int): Unit = {
        val tmp = arr(a)
        arr(a) = arr(b)
        arr(b) = tmp
    }
}


Measured memory_bytes: 43980
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define INF (ll) (1e18)
#define mod (ll) (1e9 + 7)
#define endl "\n"
#define tt ll testcase; cin>>testcase; while(testcase--)
 
const int mxn = 1*(1e5) + 5;
ll n, m;
 
void solve(){
	cin >> n;
	ll a[n];
	for(int i=0; i<n; i++) {
		cin >> a[i];
	}
	ll pref[n+1] = {};
	//// sum [l][r] = pref[r] - pref[l-1]
	for(int i=0; i<n; i++) {
		pref[i+1] = pref[i] + a[i];
	}
	// ll dp[n][n] = {};
	vector<vector<ll>>dp(n, vector<ll>(n, INF));
	for(int l=n-1; l>=0; l--) {
		dp[l][l] = 0;
		for(int r = l; r<n; r++) {
			// if(r-l == 1) {
			// 	dp[l][r] = a[r] + a[l];
			// } else {
				// dp[l][r] = min(a[l] + dp[l+1][r] + pref[r+1]-pref[l+1], a[r] + dp[l][r-1] + pref[r]-pref[l]);
				for(int i = l; i<r; i++) {
					dp[l][r] = min(dp[l][i] + dp[i+1][r] - pref[l] + pref[r+1], dp[l][r]);	
				}
				// if((r-l) == 1) dp[l][r] = a[r] + a[l];
			// }
		}
	}
	// for(int i=0; i<n; i++) {
	// 	for(int j=0; j<n; j++) {
	// 		cout << dp[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }
	cout << dp[0][n-1];
}
 
int main(){
    fast;
    #ifndef ONLINE_JUDGE 
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout); 
    #endif 
     // tt
        solve();
    return 0;
}

Measured memory_bytes: 4500
#include <iostream>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
  int n, m, x, left=0, right=0, i;
  cin >> n >> m >> x;
  int a[m];
  for(i=0; i<m; i++){
    cin >> a[i];
    if(a[i]>x) right++;
    else left++;
  }
  cout << min(left, right);
  return 0;
}

Measured memory_bytes: 256
import sys
n = int(input())
h = [int(i) for i in input().split(' ')]
for i in range(n-1):
    if h[i] <= h[i+1]:
        if h[i] <= h[i+1] -1:
            h[i+1] -= 1
    elif h[i] > h[i+1]-1:
        print('No')
        sys.exit()


print('Yes')

Measured memory_bytes: 14396
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
    ll x,y;cin>>x>>y;
    if(x%y==0)cout<<-1;
    else cout<<x;
    
}

Measured memory_bytes: 256
from sys import stdin
h, w = [int(x) for x in stdin.readline().rstrip().split()]
matrix = [stdin.readline().rstrip() for _ in range(h)]
for i in range(h):
    matrix[i] = [matrix[i][x:x+1] for x in range(len(matrix[i]))]
    matrix[i] = [0 if x == '.' else x for x in matrix[i]]
for i in range(h):
    for j in range(w):
        if matrix[i][j] == '#':
            for n in range(-1, 2):
                for m in range(-1, 2):
                    i_n = i + n
                    j_m = j + m
                    if h > i_n >= 0 and w > j_m >= 0 :
                    	if matrix[i_n][j_m] != '#':
                        	matrix[i_n][j_m] += 1
for i in range(h):
  for j in range(w):
  	print('{}'.format(matrix[i][j]), end = '')
  print('')

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define MOD 1000000007
#define EPS (1 >> 30)
#define INF (1 << 30)
//#define INFll (1LL << 60)

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    string s,t;
    cin>>s>>t;
    int ans=0;
    rep(i,3){
        if(s[i]==t[i]){
            ans++;
        }
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int a[10],b[10];
  int hit=0,blow=0;
  while(scanf("%d",&a[0])!=EOF){
    for(int i=1;i<4;i++){
      cin >> a[i];
    }
    for(int i=0;i<4;i++){
      cin >> b[i];
    }
    hit=0;
    blow=0;
    for(int i=0;i<4;i++){
      if(a[i]==b[i]){
	hit++;
      }
    }
    for(int i=0;i<4;i++){
      for(int j=0;j<4;j++){
	if(a[i]==b[j]){
	  blow++;
	}
      }
    }
    blow-=hit;
    cout << hit << " " << blow << endl;
  }
  return 0;
}

Measured memory_bytes: 1244
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,i,sum=0;
    cin>>a;
    b=a;
    while (b>0)
    {
        sum+=b%10;
        b/=10;
    }
    if (a%sum==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)

S = input()
T = input()
N = len(S)
M = len(T)

dp = [[0]*(M+1) for i in range(N+1)]

for i in range(N):
    for j in range(M):
        if S[i] == T[j]:
            dp[i+1][j+1] = dp[i][j] + 1
        else:
            dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j])

ans = ''
def rec(i,j):
    if i==0 or j==0: return
    if S[i-1] == T[j-1]:
        global ans
        ans += S[i-1]
        rec(i-1,j-1)
    elif dp[i-1][j] >= dp[i][j-1]:
        rec(i-1,j)
    else:
        rec(i,j-1)

rec(N,M)
print(ans[::-1])

Measured memory_bytes: 117980
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");

		//コード
		//    	Scanner sc = new Scanner(file);
		Scanner sc = new Scanner(System.in);

		String S = sc.next();
		String T = sc.next();
		int A = sc.nextInt();
		int B = sc.nextInt();
		String U = sc.next();

		if (U.equals(S)) {
			A--;
		} else {
			B--;
		}
		System.out.println(A + " " + B);

	}

}


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

int n, a;
set<int> st;
int main() {
	cin >> n;
	while(n--) {
		scanf("%d", &a);
		if(st.count(a)==1) return puts("NO")*0;
		st.insert(a);
	}
	return puts("YES")*0;
}

Measured memory_bytes: 9600
from collections import defaultdict

class Tree:
    def __init__(self, N):
        self.N = N
        self.D = (self.N-1).bit_length()
        self.E = defaultdict(dict)
    
    def add_edge(self, init, end, weight, undirected=False):
        self.E[init][end] = weight
        if undirected: self.E[end][init] = weight
    
    def dfs(self, root):
        # parents[v]: the parent of the vertex v
        # depth[v]: the depth of the vertex v from the root
        # dist[v]: the distance of the vertex v from the root.
        self.parent = [None] * self.N
        self.depth = [-1] * self.N
        self.dist = [float('inf')] * self.N
        self.parent[root] = -1; self.depth[root] = 0; self.dist[root] = 0;
        stack = [root]
        while stack:
            v = stack.pop()
            for u in self.E[v].keys():
                if self.depth[u] != -1: continue
                self.parent[u] = v
                self.depth[u] = self.depth[v] + 1
                self.dist[u] = self.dist[v] + self.E[v][u]
                stack.append(u)
    
    def doubling(self):
        # O(N log N) time
        self.next = [self.parent]
        for d in range(1, self.D):
            self.next.append([self.next[d-1][self.next[d-1][v]] if self.next[d-1][v] != -1 else -1 for v in range(self.N)])
    
    def lca(self, u, v):
        # O(log N) time
        # the depth of v is set to be no less than that of u
        if self.depth[u] > self.depth[v]: u, v = v, u
        # find the ancestor of v with the same depth as that of u
        diff = self.depth[v] - self.depth[u]
        for i in range(diff.bit_length()):
            if diff & 1: v = self.next[i][v]
            diff >>= 1
        if u == v: return u
        for i in range(self.D-1, -1, -1):
            pu, pv = self.next[i][u], self.next[i][v]
            if pu != pv: u, v = pu, pv
        return self.next[0][u]

n = int(input())
tr = Tree(n)
for i in range(n):
    k, *C, = map(int, input().split())
    for c in C:
        tr.add_edge(i, c, 1, undirected=True)
tr.dfs(0)
tr.doubling()
q = int(input())
for _ in range(q):
    u, v = map(int, input().split())
    print(tr.lca(u, v))


Measured memory_bytes: 62396
#include<bits/stdc++.h>
using namespace std;
int a[1025][1025],i,j,k,b[1025][1025],n,m;
bool flag;
int main()
{
	scanf("%d %d",&n,&m);
	if(n<m)
	{
		swap(n,m);
		flag=true;
	}
	a[1][1]=1;
	for(i=1;i<m;++i)
		for(j=0;j<(1<<i);++j)
			for(k=0;k<(1<<i);++k)
			{
				a[j+(1<<i)][k]=a[j][k+(1<<i)]=a[j][k];
				a[j+(1<<i)][k+(1<<i)]=a[j][k]^1;
			}
	for(i=(1<<m);i<(1<<n);++i)
		for(j=0;j<(1<<m);++j)
			a[i][j]=a[i-(1<<m)][j];
	for(i=(1<<n)-1;i>0;--i)
		for(j=(1<<m)-1;j>0;--j)
			a[i][j]^=a[i-1][j]^a[i][j-1]^a[i-1][j-1];
	if(flag)
	{
		for(i=1;i<(1<<n);++i)
			for(j=1;j<(1<<m);++j)
				b[j][i]=a[i][j];
		swap(n,m);
		for(i=1;i<(1<<n);++i)
			for(j=1;j<(1<<m);++j)
				a[i][j]=b[i][j];
	}
	for(i=1;i<(1<<n);++i)
	{
		for(j=1;j<(1<<m);++j)
			printf("%d",a[i][j]);
		printf("\n");
	}
}

Measured memory_bytes: 8960
#include<iostream>
#include<algorithm>
#include<array>
#include<set>

using namespace std;

struct S{
  int y,x;
  vector<int> v;
  S(int py,int px,vector<int> pv):y(py),x(px),v(pv){
  }
};

int x,y;
char g[12][13];
int id[12][12];

bool inside(int py,int px){
  return 0<=py&&py<y&&0<=px&&px<x;
}

void ff(int y,int x,int n){
  if(!inside(y,x)||g[y][x]!='X'||id[y][x]>=0)return;
  id[y][x]=n;
  for(int i=0;i<4;i++){
    static int d[]={0,1,0,-1,0};
    ff(y+d[i],x+d[i+1],n);
  }
}

int main(){
  while(cin>>x>>y,x){
    int sy,sx,gy,gx;
    for(int i=0;i<y;i++){
      cin>>g[i];
      for(int j=0;j<x;j++){
	if(g[i][j]=='S'){
	  sy=i;
	  sx=j;
	}else if(g[i][j]=='G'){
	  gy=i;
	  gx=j;
	}
      }
    }
    fill(id[0],id[12],-1);
    int nid=0;
    for(int i=0;i<y;i++){
      for(int j=0;j<x;j++){
	if(g[i][j]=='X'&&id[i][j]<0){
	  ff(i,j,nid++);
	}
      }
    }
    vector<int> ni(nid);
    for(int i=0;i<nid;i++){
      ni[i]=count(id[0],id[12],i);
    }
    vector<S> v[146];
    v[0].emplace_back(sy,sx,vector<int>(nid));
    set<vector<int> > s[12][12];
    for(int i=0;;i++){
      for(auto e:v[i]){
	if(e.y==gy&&e.x==gx){
	  cout<<i<<endl;
	  goto next;
	}
	if(any_of(begin(s[e.y][e.x]),end(s[e.y][e.x]),[&](vector<int> v){
	      for(int i=0;i<nid;i++){
		if(v[i]>e.v[i])return false;
	      }
	      return true;
	    }))continue;
	s[e.y][e.x].insert(e.v);
	//	if(!s[e.y][e.x].insert(e.v).second)continue;
	for(int j=0;j<4;j++){
	  static int d[]={0,1,0,-1,0};
	  int ny=e.y+d[j];
	  int nx=e.x+d[j+1];
	  if(inside(ny,nx)&&g[ny][nx]!='#'){
	    auto nv=e.v;
	    if(g[ny][nx]=='X'){
	      int cid=id[ny][nx];
	      nv[cid]++;
	      if(nv[cid]>ni[cid]/2)continue;
	    }
	    v[i+1].emplace_back(ny,nx,nv);
	  }
	}
      }
    }
  next:
    ;
  }
}


	      

Measured memory_bytes: 19792
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

const ll mod = 1000000007;
const ll INF = 100000010000;

ll kai[100010];
ll bit[700010];

void pres(double A, ll x = 20) { printf("%.20f\n", x); }

/*ll sum(ll i)
{
	ll s = 0;
	while (i > 0)
	{
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(ll i, ll x)
{
	while (i <= 700005)
	{
		bit[i] += x;
		i += i & -i;
	}
}*/

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}

ll pow_mod(ll x, ll y) {
	if (y == 0) return 1;
	if (y % 2 == 1) {
		return x * pow_mod(x, y - 1) % mod;
	}
	else {
		ll half = pow_mod(x, y / 2);
		return half * half % mod;
	}
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

ll com(ll x, ll y) {
	return kai[x] * div_mod(kai[y] * kai[x - y] % mod) % mod;
}

ll N, D, A;
ll x[200010], h[200010];
vector<P> vec;
ll num[200010];
ll ans;

void solve() {
	cin >> N >> D >> A;
	rep(i, N) {
		cin >> x[i] >> h[i];
		h[i] = (h[i] - 1) / A + 1;
		vec.push_back(P(x[i], h[i]));
	}
	sort(vec.begin(), vec.end());
	for (int i = 0; i < N; i++) {
		if (i != 0) num[i] += num[i - 1];

		if (num[i] < vec[i].second) {
			ll lb = i, ub = N;
			while (lb + 1 < ub) {
				ll mid = (lb + ub) / 2;
				if (vec[i].first + 2 * D >= vec[mid].first) {
					lb = mid;
				}
				else {
					ub = mid;
				}
			}
			num[ub] += num[i] - vec[i].second;
			ans += vec[i].second - num[i];
			num[i] = vec[i].second;
		}
	}
	cout << ans << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	ll N;
	cin >> N;
}

Measured memory_bytes: 10480
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<vector<int>> d(1001, vector<int>(1001, 0));
  for (int i = 0; i < N; i++){
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    d[x1][y1]++;
    d[x1][y2]--;
    d[x2][y1]--;
    d[x2][y2]++;
  }
  for (int i = 0; i <= 1000; i++){
    for (int j = 1; j <= 1000; j++){
      d[i][j] += d[i][j - 1];
    }
  }
  for (int i = 1; i <= 1000; i++){
    for (int j = 0; j <= 1000; j++){
      d[i][j] += d[i - 1][j];
    }
  }
  int M = 0;
  for (int i = 0; i < 1000; i++){
    for (int j = 0; j < 1000; j++){
      M = max(M, d[i][j]);
    }
  }
  cout << M << endl;
}


Measured memory_bytes: 6844
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repb(i, n) for (int i = (int)n; i >= 0; i--)
#define reps(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define repsb(i, m, n) for (int i = (int)m; i >= (int)n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999
#define ll long long int
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; }
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
using namespace std;

int main(int argc, char const *argv[])
{
    ll dp[100010][3],t[100010][3];
    int n;
    cin >> n;
    rep(i,n)
    {
        rep(j,3){
            cin >> t[i][j];
        }
    }
    
    rep(i, n)
    {
        rep(j,3){
            rep(k,3){
                if(j==k){
                    continue;
                }
                chmax(dp[i + 1][k], dp[i][j] +t[i][k]);
            }
            
            }
        
        
    }
    ll ans = 0;
    rep(i,n)
        chmax(ans, dp[n][i]);
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main(){
	int N, M;
	scanf("%d%d", &N, &M);
	
	int l = 0;
	int r = 2147483647;
	for(int i = 0; i < M; i ++){
		int x, y;
		scanf("%d%d", &x, &y);
		l = max(x, l);
		r = min(y, r);
	}
	
	printf("%d", max(0, r-l+1));
	return 0;
}


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

using namespace std;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    bool flag = false;
    if(a==b||b==c||c==a){
        flag = true;
        if(a==b && b==c){
            flag = false;
        }
    }
    cout << (flag ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WRANINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;

int n,m;

int calc(vector<int>& v,int l){
	int ret = 0;
	FOR(i,n){
		if(v[i] == 1){
			ret += (int)pow(3.0,n-1-i);
			l ^= 2;
		} else if(v[i] != l){
			ret += 2 * (int)pow(3.0,n-1-i);
		}
	}
	return ret;
}

int main(){
	while(cin>>n>>m,n||m){
		vector<int> v(n);
			FOR(i,3){
				int x; cin>>x;
				FOR(j,x){ int a; cin>>a; v[a-1] = i; }
			}
		int ans = min(calc(v,0),calc(v,2));
		cout << ((ans > m) ? -1 : ans) << endl; 
	}
    return 0;
}

Measured memory_bytes: 1192
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	static FastScanner sc;
	static PrintWriter out;
	public static void main(String[] args){
		sc = new FastScanner();
		out = new PrintWriter(System.out);
		//out.println(solve());
		solve();
		out.flush();
	}

	static void solve(){
		int N = sc.nextInt();
		int[] xList = new int[N];
		int[] yList = new int[N];
		int[] hList = new int[N];
		int idx = -1;
		for(int i=0;i<N;i++){
			xList[i] = sc.nextInt();
			yList[i] = sc.nextInt();
			hList[i] = sc.nextInt();
			if(hList[i] != 0 && idx == -1){
				idx = i;
			}
		}
		int H ;
		int tmp;
		boolean res = true;
		for(int x=0;x<=100;x++){
			for(int y=0;y<=100;y++){
				H=hList[idx] + Math.abs(x-xList[idx]) + Math.abs(y-yList[idx]);
				res = true;
				for(int i=0;i<N;i++){
					tmp = Math.max(H-Math.abs(x-xList[i]) -Math.abs(y-yList[i]), 0);
					if(tmp!=hList[i]){
						res = false;
						break;
					}
				}
				if(res){
					out.println(x + " " + y + " " + H);
					return;
				}
			}
		}

	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		}else{
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			}else if(b == -1 || !isPrintableChar(b)){
				return minus ? -n : n;
			}else{
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}
	public double nextDouble() { return Double.parseDouble(next());}
}

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

int main() {
int n,b=100,c=-100,m=4000000;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
    cin>>a[i];
    if(b>a[i])b=a[i];
    if(c<a[i])c=a[i];
}
for(int i=b;i<=c;i++){
    int d=0;
    for(int j=0;j<n;j++){
        d+=(a[j]-i)*(a[j]-i);
    }
    if(m>d){
        m=d;
    }
}
cout<<m<<endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int nums[109];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,X;
    cin>>N>>X;
    
    rep(i,N) cin>>nums[i];
    
    int mn=INF;
    rep(i,N){
        X-=nums[i];
        chmin(mn,nums[i]);
    }
    
    cout1(N+X/mn)
}

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

int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i,n) cin >> a[i];
    bool ans = false;
    int hako=1,cnt=1;
    for(int i = 0;i<n;i++){
        if(a[hako-1]==2){
            ans=true;
            break;
        }
        hako = a[hako-1];
        cnt++;
    }
    if(ans) cout << cnt << endl;
    else cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <map>
using namespace std;


int main (int argc, char const *argv[])
{
    int A,B;
    cin>>A>>B;
    int ans=A*B;

    if (ans%2==0) {
        cout<<"No"<<endl;
    }else
    {
        cout<<"Yes"<<endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 256
import math

a, b, x = map(int,input().split())

halfvol = a**2*b/2

if x <= halfvol:
    theta = math.atan(a*b**2/2/x)
else:
    theta = math.atan(2*(a**2*b-x)/a**3)

print(math.degrees(theta))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ull unsigned ll
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (ll)1e9
#define OO (ll)1e18
#define EPS 1e-7
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=105;
int n,m;
char a[maxn][maxn];
int main()
{
    IO;
    int n,k;
    cin >> n >> k;
    vector<ll> a(n);
    int idx=0;
    for(int i=0;i<n;++i){
        cin >> a[i];
        if(a[i]<0)idx=i;
    }
    idx=idx-k+1;
    idx=max(idx,0);
    ll Min=oo;
    while(idx+k-1<n){
        if(a[idx]*a[idx+k-1]>=0){
            a[idx]=max(a[idx],a[idx]*-1);
            a[idx+k-1]=max(a[idx+k-1],a[idx+k-1]*-1);
            Min=min(Min,max(a[idx],a[idx+k-1]));
        }
        else {
            a[idx]=max(a[idx],a[idx]*-1);
            a[idx+k-1]=max(a[idx+k-1],a[idx+k-1]*-1);
            Min=min(Min,2*min(a[idx],a[idx+k-1])+max(a[idx],a[idx+k-1]));
        }
        ++idx;
    }
    cout<<Min<<endl;
    re 0;
}

Measured memory_bytes: 1024
import java.util.*;


public class Main {

	static Scanner sc = new Scanner(System.in);
	static boolean[] prime_number;
	static int max;


	public static void main(String[] args) {

		eratosu(999999);

		while(read()){
			solve();
		}
	}

	public static void eratosu(int max_int){
		prime_number = new boolean[max_int+1];

		prime_number[0] = false;
		prime_number[1] = false;

		for(int i=2; i<=max_int; i++){
			prime_number[i] = true;
		}

		for(int i=2; i<=max_int; i++){
			int n = i;
			int x = 2;
			while(n*x <= max_int){
				prime_number[n*x] = false;
				x++;
			}
		}

	}

	public static Boolean read(){
		if(!sc.hasNextInt())  return false;
		max = sc.nextInt();
		return true;
	}


	public static void solve(){
		int cnt = 0;

		for(int i=2; i<=max; i++){

			if(prime_number[i]){
				cnt++;
			}
		}

		System.out.println(cnt);

	}

}

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


#define     Boost               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define     all(cont)           cont.begin(),cont.end()
#define     rall(cont)          cont.rbegin(),cont.rend()
#define     foreach(cont)       for(auto &val: cont)
#define     dbg(args...)        do {   cerr << #args << "-> " ;  show(args); } while(0); cerr<< endl ;
#define     TS                  template < typename T >
#define     TP                  template < typename F, typename S >
#define     TM                  template<typename T1, typename... T2>
#define     flush               cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define     Case                cout<< "Case "<< ++cs <<": "
#define     PI                  3.1415926535897932384
#define     pf                  printf
#define     sf                  scanf
#define     mp                  make_pair
#define     pb                  push_back
#define     ff                  first
#define     ss                  second

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

/** Debugging Tool **/
TS void show(const T& v) {    cerr << v << ' ' ;}
TM void show(const T1& first,const T2&... rest){show(first);show(rest...);}
TP ostream& operator<<(ostream& os,const pair<F,S>& p){return os<<"("<<p.ff<<", "<<p.ss<<")";}
TS ostream& operator<<(ostream& os,const vector<T>& v){os << "{"; typename vector< T >::const_iterator it;
    for(it=v.begin();it!=v.end();it++){if( it != v.begin() )os<<", ";os<<*it;}return os<<"}";}
TS ostream& operator<<(ostream& os,const set<T>& v){os<<"[";typename set<T>::const_iterator it;
    for(it=v.begin();it!=v.end();it++){if(it!=v.begin())os<<", ";os<<*it;}return os<<"]";}
TP ostream& operator<<(ostream& os,const map<F,S>& v){os<<"[";typename map<F,S>::const_iterator it;
    for(it=v.begin();it!=v.end();it++){if(it!=v.begin())os<<", ";os<<it->ff<<" = "<<it->ss;}return os<<"]";}
/** Ends **/

const double eps = 1e-9 ;
/*
int const dr[] = { 0, 0, 1, -1, -1, -1, 1, 1 } ;
int const dc[] = { 1, -1, 0, 0, -1, 1, -1, 1 } ;
int const drH[] = { 2, 1, -1, -2, -2, -1, 1, 2 } ;
int const dcH[] = { 1, 2, 2, 1, -1, -2, -2, -1 } ;
*/


void solve(){
    int n ;
    cin>> n ;
    vector<int> arr(4) ;
    while(n--){
        string str ;
        cin>> str ;
        if(str == "AC") arr[0]++ ;
        else if(str == "WA") arr[1]++ ;
        else if(str == "TLE") arr[2]++ ;
        else if(str == "RE") arr[3]++ ;
    }

    cout<< "AC x " << arr[0] << endl ;
    cout<< "WA x " << arr[1] << endl ;
    cout<< "TLE x " << arr[2] << endl ;
    cout<< "RE x " << arr[3] << endl ;

}

int main()
{
    Boost;

    #ifndef ONLINE_JUDGE
    clock_t tStart = clock();
    freopen("input.txt","r",stdin);    // Read
    freopen("output.txt","w",stdout);  // Write
    #endif

    int t = 1,cs = 0 ;
    //cin>> t ;

    while(t--){
        //Case ;
        solve() ;
    }

    #ifndef ONLINE_JUDGE
    fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif

    return 0;
}



Measured memory_bytes: 3656
// AtCoder template
// 見た奴全員saba!
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

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

    int n, m, k; cin >> n >> m >> k; 
    for(int i = 0; i <= m; ++i){
        for(int j = 0; j <= n; ++j){
            if((i*n+j*m-2*i*j) == k){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define EPS (1e-8)
#define x p.real()
#define y p.imag()
using namespace std;
typedef complex <double> point;
struct po{
  point p;
  double l;
  po(){x=y=l=0;};
  po(double a,double b,double c){x=a,y=b,l=c;}
  po(point a,double b){p=a,l=b;}
};
int n;
po bal[10];
double Abs(po a){return (a.x*a.x+a.y*a.y+a.l*a.l);}

po get_po(po a,po b){
  if(a.l>b.l) swap(a,b);
  double D=Abs(po(a.p-b.p,0));
  if(a.l*a.l+D<=b.l*b.l)return a;
  
  double t=(a.l*a.l+D-b.l*b.l)/(2*sqrt(D));
  point vec=b.p-a.p;
  vec=(vec/abs(vec))*t+a.p;
  return po(vec,sqrt(a.l*a.l-t*t));
}

po BinarySearch(double l,po b){
  double L=0,Y,R=l,h;
  int cnt=50;
  while(cnt--){
    Y=(L+R)/2;
    h=sqrt(l*l-Y*Y);
    if(Abs(po(b.x,Y-b.y,h))-b.l*b.l<=EPS) R=Y;
    else L=Y;
  }
  return po(0,Y,h-EPS);
}

bool check(po a){
  for(int i=0;i<n;i++)
    if(Abs(po(a.p-bal[i].p,a.l))-bal[i].l*bal[i].l>EPS)return 0;
  return 1;
}

double solve(){
  if(n==1)return bal[0].l;
  double res=0;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++){
      po a=get_po(bal[i],bal[j]);
      for(int k=0;k<n;k++){
	point p=bal[i].p-a.p,q=bal[k].p-a.p;
	q=q*conj(p)/abs(p);
	po b=BinarySearch(a.l,po(q,bal[k].l));
	b.p=b.p*p/abs(p)+a.p;
	if(check(b)) res=max(res,b.l);
      }
    }
  return res;
}


int main(){
  while(cin>>n,n){
    for(int i=0;i<n;i++) cin>>bal[i].x>>bal[i].y>>bal[i].l;
    printf("%.8f\n",solve());
  }
  return 0;
}

Measured memory_bytes: 1272