akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <bitset>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repm(i, a, n) for (int i = a; i >= n; i--)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vs vector<string>
#define vii vector<vector<int>>
#define vll vector<ll>
#define vllll vector<vector<ll>>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define fi first
#define se second

void print(bool c)
{
    if (c)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

void Print(bool c)
{
    if (c)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

ll gcdll(ll a, ll b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

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

bool cmp(const pii &a, const pii &b)
{
    if (a.second != b.second)
        return a.second < b.second;
    return a.first < b.first;
}

int kaijo(int x)
{
    int ans = 1;
    rep(i, 1, x + 1) ans *= i;
    return ans;
}

string n_shin(int x, int n)
{
    string s;
    while (x > 0)
    {
        s += to_string(x % n + 1);
        x /= n;
    }
    while (s.size() < n)
    {
        s += '0';
    }
    s.reserve();
    //cout << s << endl;
    return s;
}

int main()
{
    int n, m;
    cin >> n >> m;
    vi s(m), c(m);
    rep(i, 0, m) cin >> s[i] >> c[i];
    int i = -1;
    while (1)
    {
        i++;
        string t = to_string(i);
        if (t.size() > n)
        {
            cout << -1 << endl;
            return 0;
        }
        if (t.size() != n)
            continue;
        if (m == 0)
        {
            cout << i << endl;
            return 0;
        }
        rep(j, 0, m)
        {
            if (t[s[j] - 1] - '0' != c[j])
                break;
            if (j == m - 1)
            {
                cout << i << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
      
        int train = (a < b ? a : b);
        int bus = (c < d ? c : d);
		// 出力
		System.out.println(train + bus);
	}
}

Measured memory_bytes: 20820
import sys
input = sys.stdin.buffer.readline

N,Q = map(int, input().split())
List = []
dic = {}
for _ in range(N):
    s, t, x = map(int, input().split())
    List.append((s-0.5-x, 1, x))
    List.append((t-0.5-x, -1, x))
    dic[x] = False

import heapq
    
List.sort()

h = []
j = 0
for _ in range(Q):
    D = int(input())
    while j < 2*N and List[j][0] < D:
        if List[j][1] == 1:
            heapq.heappush(h, List[j][2])
            dic[List[j][2]] = True
        else:
            dic[List[j][2]] = False
        j += 1
    while h:
        ans = h[0]
        if dic[ans]:
            print(ans)
            break
        else:
            heapq.heappop(h)
    if not h:
        print(-1)

Measured memory_bytes: 68228
package main

import (
  "fmt"
)

func main() {
  var s  string 
  fmt.Scanf("%s", &s)
  
  ans := 0
  if s == "SSS" {
    ans = 0
  }
  if s == "RSS" {
    ans = 1
  }
  if s == "SRS" {
    ans = 1
  }
  if s == "SSR" {
    ans = 1
  }
  if s == "RRS" {
    ans = 2
  }
  if s == "SRR" {
    ans = 2
  }
  if s == "RSR" {
    ans = 1
  }
  if s == "RRR" {
    ans = 3
  }
  
  fmt.Printf("%d\n", ans)
}

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


int main()
{
    int  m, n, cnt=0;
    cin >> n;
    int a[n], b[n];
    for(int i=0; i<n; i++)
    {
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b, b+n);
    for(int i=0; i<n; i++)
    {
        if(a[i]!=b[i]) cnt++;
    }
    if(cnt==2 || cnt==0) cout << "YES\n";
    else cout << "NO\n";
    return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

bool isprime(int x){
    for(int i = 2; i * i <= x; i++){
        if(x % i == 0) return false;
    }    
    return true;
}

void Main(){
    int n;
    cin >> n;
    
    vi ans;
    for(int i = 11; i <= 55555; i += 10){
        if(isprime(i)) ans.pb(i);
    }
    rep(i, n) cout << ans[i] << " ";
    cout << endl;
    return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 3628
N = int(input())
X = list(map(int,input().split()))

X_sort = sorted(X)
median_min = X_sort[N//2-1]
median_max = X_sort[N//2]

for i in range(N):
  if X[i] <= median_min:
    print(median_max)
  else:
    print(median_min)

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

typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

	int n;
	cin >> n;
	string s;
	cin >> s;

	int ans = 1;

	char c = s[0];

	for(int i = 0; i < n; i++) {
		if(s[i] == c) {
			continue;
		}
		else {
			ans++;
			c = s[i];
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 512
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class ARedOrNot {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int a;
	    string s;
	    in >> a >> s;
	    out << (a >= 3200 ? s : "red") << "\n";
	}
};


int main() {
	ARedOrNot solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

namespace IO
{
char gc()
{
#ifdef FREAD
	static char buf[1<<21], *P1 = buf, *P2 = buf;
	if(P1 == P2)
	{
		P1 = buf;
		P2 = buf + fread(buf, 1, 1<<21, stdin);
		if(P1 == P2) return EOF;
	}
	return *(P1++);
#else
	return getchar();
#endif
}
template<typename Tp> bool get1(Tp &x)
{
	bool neg = 0;
	char c = gc();
	while( c != EOF && (c < '0' || c > '9') && c != '-' ) c = gc();
	if(c == '-') c = gc(), neg = 1;
	if(c == EOF) return false;
	x = 0;
	for(; c>='0' && c<='9'; c = gc()) x = x*10 + c - '0';
	if(neg) x = -x;
	return true;
}
template<typename Tp> void printendl(Tp x)
{
	if(x<0)putchar('-'),x=-x;
	static short a[40], sz;
	sz = 0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
	puts("");
}
} // namespace IO
using IO::get1;
using IO::printendl;
#define get2(x,y) get1(x) && get1(y)
#define get3(x,y,z) get2(x,y) && get1(z)
#define get4(x,y,z,w) get3(x,y,z) && get1(w)
#define pb push_back
#define mp std::make_pair
#define ff first
#define ss second
typedef long long LL;
typedef unsigned long long uLL;
typedef std::pair<int,int> pii;
const int inf = 0x3f3f3f3f;
const LL Linf = 1ll<<61;

const int maxn = 100111;
const int mod = 998244353;
const int val = 1000000000000000000ll % mod;
int qpow(int x, int y)
{
	int ret = 1;
	while(y)
	{
		if(y&1) ret = 1ll * ret * x % mod;
		x = 1ll * x * x % mod;
		y >>= 1;
	}
	return ret;
}

//Fast Walsh transform : used in xor-convolution
void FWT(int *a, int n)
{
	int sz = (1<<n);
	for(int k=1; k<sz; k<<=1)
	{
		for(int i=0; i<sz; i+=(k<<1))for(int j=0; j<k; j++)
		{
			register int u=a[i+j], v=a[i+j+k];
			a[i+j]=u+v;if(a[i+j]>=mod)a[i+j]-=mod;
			a[i+j+k]=u-v;if(a[i+j+k]<0)a[i+j+k]+=mod;
		}
	}
}
void iFWT(int *a,int n)
{
	FWT(a,n);
	int inv = qpow((mod+1)/2,n);
	for(int i=0; i<(1<<n); i++) a[i] = 1ll*a[i]*inv % mod;
}

int n, power[maxn];
struct graph
{
	int sg[maxn], m;
	std::vector<int> g[maxn];
	void init(int *a)
	{
		get1(m);
		for(int i=1, u, v; i<=m; i++)
		{
			get2(u, v);
			if(u > v) std::swap(u, v);
			g[u].pb(v);
		}
		for(int i=n; i>=1; i--)
		{
			std::set<int> qq;
			for(auto v:g[i]) qq.insert(sg[v]);
			while(qq.count(sg[i])) sg[i]++;
			a[sg[i]] = (a[sg[i]] + power[i]) % mod;
		}
	}
};
graph G1, G2, G3;
int a[1<<17], b[1<<17], c[1<<17];
int main()
{
	power[0] = 1;
	for(int i=1; i<maxn; i++) power[i] = 1ll * val * power[i-1] % mod;
	get1(n);
	G1.init(a);
	G2.init(b);
	G3.init(c);
	FWT(a, 17);
	FWT(b, 17);
	for(int i=0; i<(1<<17); i++) a[i] = 1ll * a[i] * b[i] % mod;
	iFWT(a, 17);
	int ans = 0;
	for(int i=0; i<=n; i++) ans = (ans + 1ll * a[i] * c[i]) % mod;
	printendl(ans);
	return 0;
}

Measured memory_bytes: 15232
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

template <typename T>
struct WeightedUnionFind{
    vector<int> par,siz;
    vector<T> ws;

    WeightedUnionFind(int n) : par(n), siz(n, 1), ws(n, T(0)){
        iota(par.begin(), par.end(), 0);
    }

    int root(int x){
        if(par[x] == x) return x;
        int t = root(par[x]);
        ws[x] += ws[par[x]];
        return par[x] = t;
    }

    T weight(int x){
        root(x);
        return ws[x];
    }

    void unite(int x, int y, T w){
        w += weight(x);
        w -= weight(y);
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(siz[x] < siz[y]){
            swap(x, y);
            w = -w;
        }
        siz[x] += siz[y];
        par[y] = x;
        ws[y] = w;
    }

    bool same(int x, int y){
        return root(x) == root(y);
    }

    int size(int x){
        return siz[root(x)];
    }

    T diff(int x, int y){
        return weight(y) - weight(x);
    }
};

signed main(){
    int n,Q;
    cin >> n >> Q;
    WeightedUnionFind<int> wuf(n);
    while(Q--){
        int q;
        cin >> q;
        int x,y,z;
        if(q == 0){
            cin >> x >> y >> z;
            wuf.unite(x, y, z);
        }else{
            cin >> x >> y;
            if(!wuf.same(x, y)) cout << "?" << endl;
            else cout << wuf.diff(x, y) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3896
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define LIMIT(d_in, d_min, d_max) max(d_min, min(d_max, d_in))
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;
int N;
void create(stack<int> clist, int count, int max_num)
{

	if (count == N)
	{
		string output = "";
		for (int i = 0; i < N; i++)
		{
			output = (char)(clist.top() + 'a') + output;
			clist.pop();
		}
		cout << output << endl;

		return;
	}

	for (int i = 0; i < max_num + 1; i++)
	{
		clist.push(i);
		create(clist, count + 1, max(max_num, i + 1));
		clist.pop();
	}
}

void execute()
{

	cin >> N;

	stack<int> clist;
	create(clist, 0, 0);
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

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

using namespace std;

int mov[4][2] = {{-1, 0}, {+1, 0}, {0, -1}, {0, +1}};

int n, m, comp[1123][1123], done[1123456], dist[1123456], vis[1123][1123];
char mat[1123][1123];
vector<int> adjM[1123456];

void dfs(int x, int y, int f) {
    comp[x][y] = f;

    for (int i = 0; i < 4; ++i) {
        int viz_x = x + mov[i][0];
        int viz_y = y + mov[i][1];
 
        if (viz_x < 1 || viz_x > n || viz_y < 1 || viz_y > m)
            continue;
 
        if (mat[viz_x][viz_y] != '.' or comp[viz_x][viz_y] != -1)
            continue;
        
        dfs(viz_x, viz_y, f);
    }
}

void dfs2(int x, int y, int f) {
    vis[x][y] = 1;
    for (int i = 0; i < 4; ++i) {

        int viz_x = x + mov[i][0];
        int viz_y = y + mov[i][1];
 
        if (viz_x < 1 || viz_x > n || viz_y < 1 || viz_y > m)
            continue;
 
        if (mat[viz_x][viz_y] != '.' or comp[viz_x][viz_y] != f or vis[viz_x][viz_y])
            continue;
        
        dfs2(viz_x, viz_y, f);
    }

    for (int i=-2; i<=2; ++i) {
        for (int j=-2; j<=2; ++j) {
            int viz_x = x + i;
            int viz_y = y + j;

            if (viz_x < 1 || viz_x > n || viz_y < 1 || viz_y > m)
                continue;
            if (mat[viz_x][viz_y] != '.' or comp[viz_x][viz_y] == -1 or comp[viz_x][viz_y] == f)
                continue;

            adjM[f].push_back(comp[viz_x][viz_y]);
            adjM[comp[viz_x][viz_y]].push_back(f);
        }
    }
}

void calc_dist(int u) {
    deque<int> queue;

    queue.push_back(u);

    while (!queue.empty()) {
        int v = queue.front();
        queue.pop_front();

        for (auto w: adjM[v]) {
            if (dist[w] != -1)
                continue;

            dist[w] = dist[v]+1;
            queue.push_back(w);
        }
    }
}


int main() {
    int ini_x, ini_y, fim_x, fim_y, cont = -1;
    
    scanf("%d %d", &n, &m);
    scanf("%d %d", &ini_x, &ini_y);
    scanf("%d %d", &fim_x, &fim_y);

    for (int i=1; i<=n; ++i) {
        for (int j=1; j<=m; ++j) {
            scanf(" %c", &mat[i][j]);
            comp[i][j] = -1;
        }
    }

    for (int i=1; i<=n; ++i) {
        for (int j=1; j<=m; ++j) {
            if (mat[i][j] == '.' and comp[i][j] == -1) {
                ++cont;
                dfs(i, j, cont);
            }
        }
    }

    for (int i=1; i<=n; ++i) {
        for (int j=1; j<=m; ++j) {
            if (comp[i][j] != -1 and !done[comp[i][j]]) {
                dfs2(i, j, comp[i][j]);
                done[comp[i][j]] = 1;
            }
        }
    }

    memset(dist, -1, sizeof dist);

    dist[comp[ini_x][ini_y]] = 0;
    calc_dist(comp[ini_x][ini_y]);

    printf("%d\n", dist[comp[fim_x][fim_y]]);

    return 0;
}

Measured memory_bytes: 66644
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#include <algorithm>

int main(int argc, char* argv[])
{
    char str[11] = {0};
    scanf("%s", str);

    long len = strlen(str);

    long min = 1000;
    long i;
    for(i=2; i<len; i++) {
        char a[5] = {0};
        a[0] = str[i-2];
        a[1] = str[i-1];
        a[2] = str[i];
        long value = atoi( a );
        long value2 = abs( value - 753 );
        if(min > value2) {
            min = value2;
        }
    }    
    printf("%d\n", min);

    return 0;
}



Measured memory_bytes: 128
h,n=map(int,input().split())
M=[list(map(int,input().split())) for _ in range(n)]
res=[0]
f=0
for j in range(1,h+1):
    
    i=0
    if 0>=j-M[i][0]:
        ind=0
    else:
        ind=j-M[i][0]
    ff=res[ind]+M[i][1]
    
    for i in range(1,n):
        if 0>=j-M[i][0]:
            ind=0
        else:
            ind=j-M[i][0]
        kari=res[ind]+M[i][1]
        
        ff=min(ff,kari)
    res.append(ff)
print(res[-1])

Measured memory_bytes: 43688
#include <bits/stdc++.h>
using namespace std;
#define P pair<int,int>
#define ll long long
const int N = 2e5+10;
double p[N];
int main()
{
    int n,k;
    cin >> n >> k;
    for(int i=1;i<=n;i++)
    {
        cin >> p[i];
    }
    double maxn=0;
    for(int i=1;i<=k;i++)
    {
        maxn+=(p[i]+1);
    }
    double cnt=maxn;
    for(int i=k+1;i<=n;i++)
    {
        cnt=cnt+p[i]-p[i-k];
        maxn=max(maxn,cnt);
    }
    printf("%0.12lf",(maxn)/2);
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
//scanf("%d", &a) '\n'

int main() {
	int n;
	cin >> n;
	vector<vector<int>> p(n, vector<int>(2));
	rep(i, n) {
		int x,y;
		cin >> x>>y;
		p.at(i) = { x,y };
	}
	double ans = 0;
	int nk=1;
	int N = n;
	while (N != 1) {
		nk *= N;
		--N;
	}
	vector<int> v(n);
	rep(i, n)v[i] = i;
	vector<vector<int>> data(nk, vector<int>(n));
	int count = 0;
	do {
		data[count] = v;
		++count;
	} while (next_permutation(v.begin(), v.end()));
	
	rep(i, nk) {
		rep2(j,1, n) { 
			int a = data[i][j - 1];
			int b = data[i][j];
			ans += sqrt((p[a][0] - p[b][0])*(p[a][0] - p[b][0]) + (p[a][1] - p[b][1])*(p[a][1] - p[b][1]));
		}
		
	}
	cout << fixed << setprecision(10);
	cout << ans/nk<< endl;

}
	

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

int n, A, B, C;

int dfs(vector<int> &arr, int cur, int a, int b, int c) {
  if (cur == n) {
    if (min(a, min(b, c)) > 0) {
      int sum = abs(A - a) + abs(B - b) + abs(C - c);
      return sum - 30;
    } else {
      return (1 << 21);
    }
  }
  int ret1 = dfs(arr, cur + 1, a, b, c);
  int ret2 = dfs(arr, cur + 1, a + arr[cur], b, c) + 10;
  int ret3 = dfs(arr, cur + 1, a, b + arr[cur], c) + 10;
  int ret4 = dfs(arr, cur + 1, a, b, c + arr[cur]) + 10;

  return min(ret1, min(ret2, min(ret3, ret4)));
}

int main() {
  cin >> n >> A >> B >> C;
  vector<int> l(n);
  for (int i = 0; i < n; i++)
    cin >> l[i];

  cout << dfs(l, 0, 0, 0, 0) << endl;
}

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

string lowerize(string s) {
	for (int i = 0; i < s.size(); ++i) {
		if (isupper(s[i])) s[i] = tolower(s[i]);
	}
	return s;
}

signed main() {
	string s, w;
	cin >> w;
	w = lowerize(w);
	int cnt = 0;
	while (cin >> s and s != "END_OF_TEXT") {
		s = lowerize(s);
		if (s == w) cnt++;
	}
	cout << cnt << endl;
}



Measured memory_bytes: 3156
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
const int MOD = 1e9+7;
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i-1]*i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

ll COM(int n, int k){
    if(n<k) return 0;
    if(n<0 || k<0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

ll f(int S, int n){
  S -= 3*n;
  if(S<0) return 0;
  return COM(S+n-1,S);
}
  
int main(){
  COMinit();
  int S;
  cin >> S;
  ll ans = 0;
  int maxdigit = S / 3;
  for(int i=1; i<=maxdigit; i++){
    ans += f(S,i);
    ans %= MOD;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 15556
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
int w[110];
int s1=0,s2=0;
int out=10000;
cin>>n;
for(int i=1;i<=n;i++){
  cin>>w[i];
}
for(int i=1;i<=n;i++){
  for(int j=1;j<=i;j++){
    s1+=w[j];
  }
  for(int k=i+1;k<=n;k++){
    s2+=w[k];
  }
   int s=s1-s2;
  if(s<0) s*=-1;
  out=min(out,s);
  s1=s2=0;
}
cout<<out;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:1024000000")
#pragma warning( disable : 6031)
#pragma warning( disable : 4244)
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdint>
#include <climits>
#include <cassert>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <chrono>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef vector<ll> vll;
typedef vector<vector<long long>> vvll;
typedef tuple<int, int, int> tiii;
const long long mod = int(1e9) + 7;
const double eps9 = 1e-9;


int main() {
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
	int x, a;
	cin >> x >> a;
	if (x < a)
		cout << 0;
	else
		cout << 10;
	return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;
#define LL long long
#define MOD 100000
#define inf 2147483647



int main() {
	while (true) {
		int h, w;
		cin >> h >> w;
		if (h + w == 0)break;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if ((j == 0 || j == w - 1) || (i == 0 || i == h - 1))
					cout << '#';
				else cout << '.';
			}
			cout << endl;
		}
		cout << endl;
	}


	return 0;
}



Measured memory_bytes: 3060
import java.util.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int c=0;
    int flg=0;
    while(n-->0){
      int x = sc.nextInt();
      int y = sc.nextInt();
      
      if(x==y){
        c++;
        if(c>=3){
        flg=1;
      }
      }
      else{
        c=0;
      }
    }
    if(flg==0){
      System.out.println("No");
    }
    else{
      System.out.println("Yes");
    }
  }
}

Measured memory_bytes: 27332
// Author -> Preeyadarshee Dev
// Bc pata nhi kis baat ka attitude hai
// Joker ka dialogue suit karta hai yahan to
// " For my whole life, I thought I didn't exist. But now,I do. "
// I will meet you once. #Intequam
// This is fucking motivation.
// train hard win easy :D
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculation
// Don't copy code snippet
#include<bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                    long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   987654319
#define eps                   0.000000000000001
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define endl                 '\n'
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
vector<int> adj[300010];
vector<int> val(300010),dis(200010),vis(300010,0);
int myrandom (int i) { return std::rand()%i;}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    ll n,k;
    cin>>n>>k;
    vector<ll> v(n),t(n);
    f(i,n)
    {
        cin>>v[i];
    }
    f(i,n)
    {
        cin>>t[i];
    }
    sort(all(v));
    sort(all(t),greater<ll> ());
    ll lo=-1,hi=1ll<<60;
    while(hi-lo>1)
    {
        ll mid=(lo+hi)/2;
        ll cnt=0;
        for(int i=0;i<n;i++)
        {
            cnt=cnt+max((ll)ceil((v[i]*t[i]-mid)/(t[i]*1.0)),0ll);
        }
        if(cnt>k)
        {
            lo=mid;
        }
        else
        {
            hi=mid;
        }
    }
    cout<<hi<<endl;
}
// t4xxnve1
// 11906472
// YHUHA8ZBJH
// Preeyadarshee Dev Team 808db2e1




Measured memory_bytes: 13568
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int h,w;
vs a;
vvi b;

P dfs(int i,int j){
	b[i][j]++;
	P p={1,0};
	for(int k=0;k<4;k++){
		int x=i+dx[k],y=j+dy[k];
		if(x>=0&&x<h&&y>=0&&y<w&&a[i][j]!=a[x][y]&&!b[x][y]){
			P q=dfs(x,y);
			p.first+=q.second;
			p.second+=q.first;
		}
	}
	return p;
}

int main(){
	cin>>h>>w;
	a=vs(h);
	b=vvi(h,vi(w));
	for(auto &i:a) cin>>i;
	ll res=0;
	for(int i=0;i<h;i++) for(int j=0;j<w;j++) if(!b[i][j]){
		P p=dfs(i,j);
		res+=(ll)p.first*p.second;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 21120
#include<bits/stdc++.h>
#include<cstdlib>
using namespace std;
int main () {
    int n;
    int l;
    cin >> n >> l;

    int sum;
    sum = 0;
    int mini;
    mini = abs(l);
    for( int i=0; i<n; i++){
        sum = sum + (l+(i+1)-1);
        mini = min(mini,abs(l+(i+1)-1));
    }
    //cout << sum << endl;
    if(sum > 0){
        cout << sum-mini << endl;
    }else {
        cout << sum+mini << endl;
    }
}


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

typedef long long ll;
#define MOD = 1000000007;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
template<class T> inline bool is_overlap(const T& as, const T& ae, const T& bs, const T& be)
{ return bs <=ae && as <= be; }
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
#define ANS(a) cout<<a<<endl
void yes(bool f){cout<<(f?"yes":"no")<<endl;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int H,W; cin >>H>>W;
    vector<string> grid(H); cin >> grid;

    rep(i, H) {
        rep(j, W) {
            if (grid[i][j] == '.') {
                int c = 0;
                for (int m = max(i-1, 0); m < min(i+2,H); m++) {
                    //c += count(grid[m].begin() + max(j-1, 0), grid[m].begin() + min(j+2,W), '#');
                    for (int n = max(j-1, 0); n < min(j+2,W); n++)
                        if (grid[m][n] == '#') c++;
                    
                }
                grid[i][j] = '0' + c;
            }
        }
    }

    rep(i, H)
        cout << grid[i] << endl;
}


Measured memory_bytes: 256
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus >= 201703L
#        pragma GCC target("avx2")
#    else
#        pragma GCC target("avx")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int m = max({a, b, c});
    int ans = a + b + c - m;
    m = m << k;
    ans += m;

    cout << ans << endl;

    return 0;
}


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

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

using namespace std;
using namespace atcoder;
using ll = long long;

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

    int t;
    cin >> t;
    int n, m, a, b;
    rep(i, t) {
        cin >> n >> m >> a >> b;
        printf("%lld\n", floor_sum(n, m, a, b));
    }

    return 0;
}

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

int n, ans = 0, cnt = 0;
bool ch[1000005] = {0};

int main() {
  cin >> n;
  for(int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    if(ch[x]) ++cnt;
    ch[x] = 1;
  }
  ans = n - (cnt + cnt % 2);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
main()
{int n,m,c=0;
float a,s=0;
cin>>n>>m;
	vector<int> v(n);
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
		s=s+v[i];
	}
	a=s/(4*m);
	for(auto x:v)
	{
		if(x>=a)
	{
		c=c+1;
	}
}
	if(c>=m)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <bitset>
#include <fstream>
#include <cmath>
#include <ctime>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i = 0; i < n; i++)
#define MSG(a) cout << #a << " " << a << endl;
int main()
{
	int d;
	while( cin >> d && d)
	{
		int n, m;
		cin >> n >> m;
		vector<ll> s(n);

		rep(i, n - 1) cin >> s[i];

		s[n-1] = 0;
		s.push_back(d);

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

		ll res = 0;
		rep(i, m)
		{
			int k;
			cin >> k;

			vector<ll>::iterator it = upper_bound(s.begin(), s.end(), k);

			res += min(*it - k, k - *(it-1));
		}

		cout << res << endl;
	}
}

Measured memory_bytes: 1816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
//0-indexedで用いる (実装は1-indexedの配列だけど
//SegmentTree(n,f,m1):=サイズnの初期化。ここでfは2つの区間の要素をマージする二項演算m1はモノイドの単位元である。
//set(k,x) k番目の要素にxを代入する
//build() (代入で作った場合)セグメント木を構築するのに必要
//query(a,b) 区間[a,b)に対して二項演算した結果を返す
//update(k,x) k(0-indexed)番目の要素をxに変更する 
//operator[k] k(0-indexed)番目の要素を返す

template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;
 
  int sz;
  vector< Monoid > seg;
 
  const F f;
  const Monoid M1;
 
  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }
 
  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }
 
  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }
 
  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }
 
  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }
 
  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }
};

  // PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_A"
int main() {
  int n;
  string s;
  cin >> n;
  cin >> s;
  
  set<char> emp;
  SegmentTree< set<char> > seg(n, [](set<char> a, set<char> b) {
				    set<char> ts = a;
				    for(auto i:b) ts.insert(i);
				    return ts; }, emp);
  rep(i,n){
    set<char> t;
    t.insert(s[i]);
    seg.set(i,t);
  }
  seg.build();

  int q;
  cin >> q;
  rep(i,q){
    int ty,a;
    cin >> ty >> a;
    --a;
    if(ty==1){
      char b;
      cin >> b;
      set<char> t;
      t.insert(b);
      seg.update(a,t);
    }
    else{
      int b;
      cin >> b;
      auto ans = seg.query(a,b);
      cout << ans.size() << endl;
    }
  }
  
  
  return 0;
}


Measured memory_bytes: 190732
//from PKU1125
double dist[1001][1001],d;
next[1001][1001],x[1001],y[1001];
main(){
	int a,b,k,n,i,j;
	for(;scanf("%d",&n),n;){
		/*initialize*/
		for(i=1;i<=n;i++)scanf("%d",&a),scanf("%d%d",x+a,y+a);
		for(i=1;i<=n;i++)for(j=1;j<=n;next[i][j]=j,j++)
			dist[i][j]=(d=hypot(x[i]-x[j],y[i]-y[j]))<50.1?d:999;

		{/*warshall-floyd*/
			int k,i,j;
			for(k=1;k<=n;k++)
				for(i=1;i<=n;i++)
					for(j=1;j<=n;j++){
						if(dist[i][j]>dist[i][k]+dist[k][j])
							dist[i][j]=dist[i][k]+dist[k][j],next[i][j]=next[i][k];
					}
		}

		{/*query*/
			for(scanf("%d",&k);k;k--){
				scanf("%d%d",&a,&b);
				if(dist[a][b]>998)puts("NA");
				else{
					for(j=a;j!=b;j=next[j][b])printf("%d ",j);
					printf("%d\n",b);
				}
			}
		}
	}exit(0);
}

Measured memory_bytes: 5112
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
const ll inf = 1e18;
const ll mod = 1e9 + 7;

ll pow (ll x, ll n){
    ll ans = 1;
    while(n>0){
        if(n & 1 == 1){
            ans *= x;
        }
        x = x * x;
        n >>= 1;
    }
    return ans;
}

int main(){
    int n ;   cin >> n;
    vint d(n);
    set<int> t;
    rep(i,n){
        cin >> d[i];
        t.insert(d[i]);
    }
    int ans = t.size();

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


Measured memory_bytes: 256
N,K=map(int, input().split())
S=input()
if K==1:
  S=S[K-1].lower()+S[K:]
elif K==N:
  S=S[:K-1]+S[K-1].lower()
else:
  S=S[:K-1]+S[K-1].lower()+S[K:]
print(S)

Measured memory_bytes: 2940
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s, i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = s, i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = s; i < (n); ++i)
#define VFORS(i, s, n) for(int i = s; i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = s, i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = s, i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;
using VLL = vector<ll>;
using VS = vector<string>;
using VC = vector<char>;
using VB = vector<bool>;

const int MOD = 1000000007;
const int INF = 1000000000;

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


int main(){
    int h, w; cin >> h >> w;
    VS a(h);
    vector<VI> dp(h, VI(w, 0));
    REP(i, h) cin >> a[i];
    dp[0][0] = 1;
    REP(i, h) REP(j, w){
        if(a[i][j] == '#'){
            dp[i][j] = 0; continue;
        }
        if(i) dp[i][j] = (dp[i][j] + dp[i-1][j]) % MOD;
        if(j) dp[i][j] = (dp[i][j] + dp[i][j-1]) % MOD;
    }
    cout << dp[h-1][w-1] << "\n";
    return 0;
}


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

int h, w;
char grid[2100][2100];
int U[2100][2100] = {}, D[2100][2100] = {}, L[2100][2100] = {}, R[2100][2100] = {};

void input() {
	cin >> h >> w;
	for (int i = 0; i < h; i++)scanf("%s", grid[i]);
}

void prepare() {
	for (int i = 0; i < w; i++)if (grid[0][i] != '#')U[0][i] = 1;
	for (int i = 1; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (grid[i][j] == '#') {
				U[i][j] = 0;
			} else {
				U[i][j] = U[i - 1][j] + 1;
			}
		}
	}
	for (int i = 0; i < w; i++)if (grid[h - 1][i] != '#')D[h - 1][i] = 1;
	for (int i = 1; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (grid[h - i - 1][j] == '#') {
				D[h - i - 1][j] = 0;
			} else {
				D[h - i - 1][j] = D[h - i][j] + 1;
			}
		}
	}
	for (int i = 0; i < h; i++)if (grid[i][0] != '#')L[i][0] = 1;
	for (int i = 0; i < h; i++) {
		for (int j = 1; j < w; j++) {
			if (grid[i][j] == '#') {
				L[i][j] = 0;
			} else {
				L[i][j] = L[i][j - 1] + 1;
			}
		}
	}
	for (int i = 0; i < h; i++)if (grid[i][w - 1] != '#')R[i][w - 1] = 1;
	for (int i = 0; i < h; i++) {
		for (int j = 1; j < w; j++) {
			if (grid[i][w - j - 1] == '#') {
				R[i][w - j - 1] = 0;
			} else {
				R[i][w - j - 1] = R[i][w - j] + 1;
			}
		}
	}
}

void solve() {
	int ans = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			ans = max(ans, U[i][j] + D[i][j] + L[i][j] + R[i][j] - 3);
		}
	}
	cout << ans << endl;
}

int main() {
	input();
	prepare();
	solve();
}

Measured memory_bytes: 73216
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define pii pair<int, int> 
#define pll pair<long , long>
#define all(a) a.begin(), a.end()
#define int long long
#define ll long long
#define mod 998244353
#define endl "\n"
//#define int long long
#define loop(i,a,b) for(int i=a;i<b;i++)
#define bloop(i,a,b) for(int i=a;i>=b;i--)

using namespace std;


int32_t main() {
	//code
	int t=1;
	// cin>>t;
	while(t--)
	{
        int s,w;
        cin>>s>>w;
        if(w>=s)
            cout<<"unsafe"<<endl;
        else cout<<"safe"<<endl;
	    
	}
	return 0;
	
}

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

ll modulo(ll x){
    return (x>0) ? x : -x;
}

int main(){
    ll x, k, d, q, answ;

    cin >> x >> k >> d;

    q = modulo(x)/d;

    if(q>=k){
        answ = modulo(x) - k*d;
    }
    else if((k-q)%2){
        answ = d-modulo(x)%d;
    }
    else{
        answ = modulo(x)%d;   
    }

    cout << answ << '\n';

    return 0;
}

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

#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-funroll-loops")
#pragma GCC target("avx,sse4")

#define mms(a,n) memset(a,0,sizeof((a)[0])*(n))
#define mmp(a,b,n) memcpy(a,b,sizeof((b)[0])*(n))
#define lowbit(x) ((x)&-(x))
#define pb push_back
#define fi first
#define se second
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define fo(i,l,r) for(register int i=l,_lim_=r;i<=_lim_;i++)
#define fd(i,r,l) for(register int i=r,_lim_=l;i>=_lim_;i--)
#define fos(i,l,r,d) for(register int i=l,_lim_=r;i<=r;i+=d)
#define fol(i,l,r) for(register ll i=l,_lim_=r;i<=_lim_;i++)
#define fdl(i,r,l) for(register ll i=r,_lim_=l;i>=_lim_;i--)
#define fosl(i,l,r,d) for(register ll i=l,_lim_=r;i<=r;i+=d)
#define Clear(a) memset(a,0,sizeof(a))
#define Copy(a,b) memcpy(a,b,sizeof(b))
#define ALL(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define sqr(x) ((x)*(x))
#define GCD __gcd

using namespace std;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ldb;
typedef double db;
typedef pair<int,int> pi;
typedef vector<int> VI;
typedef vector<VI> VII;

namespace io{
	const int L=(1<<21)+1;
	char ibuf[L],*iS,*iT,obuf[L],*oS=obuf,*oT=obuf+L-1,c,st[55];int f,tp;
	#ifdef whzzt
		#define gc()getchar()
	#else
		#define gc()(iS==iT?(iT=(iS=ibuf)+fread(ibuf,1,L,stdin),(iS==iT?EOF:*iS++)):*iS++)
	#endif
	inline void flush(){fwrite(obuf,1,oS-obuf,stdout);oS=obuf;}
	inline void putc(char x){*oS++=x;if(oS==oT)flush();}
	template<class I>
	inline void gi(I&x){
		for(f=1,c=gc();c<'0'||c>'9';c=gc())if(c=='-')f=-1;
		for(x=0;c<='9'&&c>='0';c=gc())x=x*10+(c&15);x*=f;
	}
	template<class I>
	inline void print(I x){
		if(!x)putc('0');if(x<0)putc('-'),x=-x;
		while(x)st[++tp]=x%10+'0',x/=10;
		while(tp)putc(st[tp--]);
	}
	inline void gs(char*s,int&l){
		for(c=gc();c<'a'||c>'z';c=gc());
		for(l=0;c<='z'&&c>='a';c=gc())s[l++]=c;
	}
	inline void ps(const char*s){
		fo(i,0,strlen(s)-1)putc(s[i]);
	}
};
using io::putc;
using io::gi;
using io::gs;
using io::ps;
using io::print;

long long n;
int d;

int main(){
	cin>>n;n++;
	while(n>=10)d+=9,n/=10;
	cout<<d+n-1;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  
  int ans = 0;
  vector<int> vec(N);
  
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
    ans += min(vec.at(i), K - vec.at(i));
  }
  cout << 2 * ans << endl;
}
    
    

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

int main(){
  int n;
  cin >> n;
  double ans = 0;
  vector<double> x(n+10);
  vector<string> y(n+10);
  rep(i,n){
    cin >> x[i] >> y[i];
    if(y[i] == "JPY"){
      ans += x[i];
    }
    else{
      ans += x[i] * 380000;
    }
  }
  cout << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 
     String[] nyu=sc.nextLine().split(" ");

//     String nyu=sc.nextLine();
int A=Integer.parseInt(nyu[0]);
int B=Integer.parseInt(nyu[1]);
//int C=Integer.parseInt(nyu[2]);
//int D=Integer.parseInt(nyu);



//StringBuffer sb = new StringBuffer(nyu);
//		String dst = sb.reverse().toString();

//     String nyu2=sc.nextLine();
//int E=Integer.parseInt(nyu2);



//double A=Double.parseDouble(nyu[0]);
//double B=Double.parseDouble(nyu[1]);
/*
switch(C){
case 7:
case 5:
case 3:
System.out.println("YES") ;
break;
default:
System.out.println("NO") ;

break;
}
*/

//int res=Math.min((A*B),C);

//for(String tem:nyu){
//if(tem.equals("1"))res++;
//}
//int res=0;
//for(int i=0;i<300;i++){
//if(num[i]==1)res=i;
//}

//char[] c = nyu.toCharArray();


//System.out.println(nyu+"-"+line_r_2+"-"+nyu2+"-"+line_r_1);



//if(B-A==C-B){
//double res=Math.ceil((AB)/2);

//System.out.println("YES");
//}else if((C-B)<A){
//System.out.println("safe");

//}else{
System.out.println((A+B)%24);

//}




	}
}

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

int main(){
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int totalcount = 0;
    int total = 0;
    for (int i = 0; i <= A; i++){
        for(int j = 0; j <= B; j++){
            for(int k = 0; k <= C; k++){
                total = 500 * i + 100 * j + 50 * k;
                if (total == X)  totalcount += 1;
            }
        }
    }
    cout << totalcount << endl;
}

Measured memory_bytes: 256
N,M,V,P = map(int,input().split())
A = sorted([int(i) for i in input().split()],reverse = True)

pps = 0
con = P

for i in range(P,N):
  #P以降でi番目に大きい数を加算
  pps += A[i - 1]

  #xの上限が順位に入らない
  if A[i] + M < A[P - 1]:
    break
  #点数をいくら振り分けてもいいスコアの数
  fv = min(P - 1 + N - i, V)
  #左辺第二項は、P以降とi以前の、点数の振り分け可能数に上限がある数
  #左辺は振り分けた後にA[i]がP入りを果たせる区間の総和の上限を示す
  #右辺第一項は、振り分け可能数に上限がある数の総和
  #右辺第二項は、振り分けないといけない数の残り
  #右辺は、点数を振り分けた後の値の区間の総和を示すため、
  #右辺が左辺を上回った場合、ループは終了となる
  if (A[i] + M) * (i - P + 1) < pps + M * (V - fv):
    break
  con += 1
  
print(con)

Measured memory_bytes: 14484
//============================================================================
// Name        : f.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main() {
	int n,m;cin>>n>>m;
	string s;cin>>s;
	reverse(s.begin(),s.end());
	vector<string> v(n);
	int temp=0;
	vector<int> ans;
//	cout<<s<<endl;
	while(temp<n){
		int flag=1;
		for(int i=m;i>=1;i--){
			if(temp+i>n)continue;
//			cout<<s[temp+i]<<endl;
			if(s[temp+i]=='0'){
				flag=0;
				temp+=i;
				ans.push_back(i);
				break;
			}
		}
		if(flag){
			cout<<-1<<endl;
			return 0;
		}
	}
	reverse(ans.begin(),ans.end());
	for(int i=0;i<ans.size();i++){
		cout<<ans[i]<<' ';
	}cout<<endl;
	return 0;
}


Measured memory_bytes: 1912
n,m=map(int,input().split())
hls=list(map(int,input().split()))
abls=[list(map(int,input().split())) for i in range(m)]
d={i+1:0 for i in range(n)}

for i in abls:
    left_h,right_h = hls[i[0]-1],hls[i[1]-1]
    if left_h>=right_h:
        d[i[1]] = -1
    if left_h<=right_h:
        d[i[0]] = -1
 
ans=0
for i in d.values():
    if i==0:
        ans+=1
print(ans)

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

int main(){
  ll n;
  cin >> n;
  cout << (n + 1) / 2 << endl;
}

Measured memory_bytes: 256
e,s=gets
h=gets.split.map(&:to_i).sort.chunk{|e|e}.map{|k,v|s||=k;[e=k,v.size]}.to_h
$><<(h[s]==s*2+1-e&&(s+1..e).all?{|e|h[e]&&h[e]>=2}?"Possible":"Impossible")

Measured memory_bytes: 1916
N = int(input())
T,A  =[int(i) for i in input().split()]
H = [int(i) for i in input().split()]
diff = (abs(A-(T-H[0]*0.006)))
palace = 0
for i in range(len(H)):
    if(abs(A-(T-H[i]*0.006)) < diff):
        palace = i
        diff = abs(A-(T-H[i]*0.006))
print(palace+1)


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

#define ll long long

using namespace std;

const int MAXN = 1e5 + 10;
const int MAXM = 1e5 + 10;
const int INF = 0x3fffffff;
const int MOD = 1e9 + 7;

int n, m, k;
int tot, cnt, ans;

int a[MAXN];

string s;

int main() {
	int T;
	string s1, s2;
	cin >> s1;
	cin >> s2;
	for (int i = 0; i < s1.size(); i++) {
		if (s1[i] != s2[i]) {
			ans++;
		}
	}
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 3812