akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, r, ans = 2e9;
int b[205];
int a[205][205];

int main()
{
    scanf("%d%d%d", &n, &m, &r);
    for(int i = 0; i < r; i++)
    {
        scanf("%d", &b[i]);
    }
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            a[i][j] = 1e9;
        }
    }
    for(int i = 0; i < m; i++)
    {
        int t1, t2, t3;
        scanf("%d%d%d", &t1, &t2, &t3);
        a[t1][t2] = t3;
        a[t2][t1] = t3;
    }
    for(int k = 1; k <= n; k++)
    {
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= n; j++)
            {
                if(a[i][j] > a[i][k] + a[k][j]) a[i][j] = a[i][k] + a[k][j];
            }
        }
    }
    sort(b, b + r);
    do
    {
        int sum = 0;
        for(int i = 0; i < r - 1; i++)
        {
            sum += a[b[i]][b[i + 1]];
        }
        ans = min(ans, sum);
    }while(next_permutation(b, b + r));
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int k;
  cin>>k;
 int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout<<a[k-1];
}  
  


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=200009;

int n;
int cnt;
char s[maxn];

int ans;

int main(){
	scanf("%d",&n);
	scanf("%s",s+1);
	for(int i=1;i<=n;++i)if(s[i]=='R')++cnt;
	for(int i=1;i<=cnt;++i)if(s[i]=='W')++ans;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4016
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<algorithm>
#include<cmath>
#include<complex>
using namespace std;

int main(){
    int mod=1000000007;
    char str[11];
    int a[10][10];
    while (scanf("%s ",str)!=EOF) {
        for (int i=0;i<10;++i) {
            a[0][i]=str[i]-'0';
        }
        for (int i=1;i<10;++i) {
            for (int j=0;j<10-i;++j) {
                a[i][j]=(a[i-1][j]+a[i-1][j+1])%10;
            }
        }
        printf("%d\n",a[9][0]);
    }
    return 0;
}

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

int main(void) {
    int N;
    cin>>N;
    int T,A;
    cin>>T>>A;
    double mi;
    int result = -1;
    for (int i = 0; i < N; i++) {
        int H;
        cin>>H;
        double current = T - 0.006 * H;
        double sabun = max(current - A, A - current);
        if (i == 0) {
            mi = sabun;
            result = i;
            continue;
        }
        if (sabun < mi) {
            mi = sabun;
            result = i;
        }
    }
    cout << result + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>u
using namespace std;
int main(){
	long double a;
	long double b;
	cin>>a;
	cin>>b;
	"a">=0;
	"b">=0;
	if(a>b)
	cout<<"GREATER";
	else if(a<b)
	cout<<"LESS";
	else
	cout<<" EQUAL";
	
}

Measured memory_bytes: 632
// -*- coding:utf-8-unix -*-

use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        a: isize,
        b: isize,
        c: isize,
        d: isize
    }
    let z = (a * c).max(a * d).max(b * c).max(b * d);
    println!("{}", z);
}


Measured memory_bytes: 2200
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
    
    ll n;
    cin >> n;
    vector <ll> w;
    ll sum = 0;
    for (ll i=0;i<n;i++){
        ll tmp;
        cin >> tmp;
        sum += tmp;
        w.push_back(sum);
    }
    ll ans = sum;
    for (ll i=0;i<n;i++){
        if(ans > abs(sum-2*w[i])) ans = abs(sum-2*w[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

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

        for (int i = 0; i < 3; ++i) {
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);

        System.out.println(a[0] + a[1]);
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#include<math.h>
#include<string>
#include<vector>
using namespace std;
int main(void){
	int i,j,k,M,N,H,W,X,A,K;
	cin >> X >> A;
	if(X<A){
		cout << 0;
	}else{
		cout << 10;
	}
	return 0;
}

Measured memory_bytes: 256
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


S = sys.stdin.buffer.readline().decode().rstrip()
K = int(sys.stdin.buffer.readline())

ss = set()
for k in range(1, K + 1):
    for i in range(len(S)):
        ss.add(S[i:i + k])
ss = list(sorted(ss))
print(ss[K - 1])


Measured memory_bytes: 39536
import heapq
from collections import defaultdict

N, M = map(int, input().split())

a_b_dict = defaultdict(list)
for _ in range(N):
    a, b = tuple(map(int, input().split()))
    a_b_dict[a].append(b)

result = []
h = []
num_days = 0
for i in range(1, 1+M):
    for b in a_b_dict.get(i, []):
        heapq.heappush(h, -b)
    if len(h) > 0:
        result.append(-1*heapq.heappop(h))
print(sum(result))



Measured memory_bytes: 30652
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()

    var aSum = 0
    var bSum = 0
    var cSum = 0
    var aPrev = 0
    var bPrev = 0
    var cPrev = 0

    for ( i in 0 until n) {
        val (a, b, c) = readLine()!!.split(" ").map { it.toInt() }
        aSum = Math.max(bPrev, cPrev) + a
        bSum = Math.max(aPrev,cPrev) + b
        cSum = Math.max(aPrev,bPrev) + c

        aPrev = aSum
        bPrev = bSum
        cPrev = cSum
    }

    println(Math.max(Math.max(aSum, bSum), cSum))
}

Measured memory_bytes: 61956
use proconio::input;

fn main() {
    input! {
        n: usize,
        k: usize,
        dd: [usize; k],
    }

    for i in n.. {
        let mut x = i;
        while x > 0 {
            let d = x % 10;
            if dd.contains(&d) {
                break;
            }
            x /= 10;
        }
        if x == 0 {
            println!("{}", i);
            return;
        }
    }
}


Measured memory_bytes: 2072
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <sstream>
#include <list>
//#include <array>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <iterator>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
inline int lc(int x)  {return x << 1;}
inline int rc(int x)  {return x << 1 | 1;}
int k;
set<ll> st = {1, 2, 3, 4, 5, 6, 7, 8, 9};
map<int, int> mp;

void solve() {
    priority_queue<ll, vector<ll>, greater<ll>> q;
    for (auto &x : st) {
        q.emplace(x);
    }
    while (!q.empty()) {
        if (st.size() >= maxn) return;
        auto x = q.top();
        q.pop();
        ll y = x * 10 + x % 10 - 1;
        if (abs(y % 10 - x % 10) <= 1) {
            if (!st.count(y)) {
                st.insert(y);
                q.push(y);
            }
        }
        y = x * 10 + x % 10;
        if (abs(y % 10 - x % 10) <= 1) {
            if (!st.count(y)) {
                st.insert(y);
                q.push(y);
            }
        }
        y = x * 10 + x % 10 + 1;
        if (abs(y % 10 - x % 10) <= 1) {
            if (!st.count(y)) {
                st.insert(y);
                q.push(y);
            }
        }
    }
}

int main(void) {
    FAST_IO;
    solve();
    cin >> k;
    vector<ll> v;
    for (auto &x : st) {
        v.emplace_back(x);
    }
    cout << v[k - 1] << endl;
    
    return 0;
}

Measured memory_bytes: 7664
//#include <tourist>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//g++ yarudake.cpp -std=c++17 -I .
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll t;
    cin>>t;
    rep(i,t){
        ll n,m,a,b;
        cin>>n>>m>>a>>b;
        cout<<floor_sum(n,m,a,b)<<"\n";
    }
}

Measured memory_bytes: 3672
#include <stdio.h>

typedef struct {
	int m[50][50];
} MATRIX;

void mulMatVec(int out[50],const MATRIX* m,const int v[50],int n,int modBy) {
	int i,j;
	for(i=0;i<n;i++) {
		out[i]=0;
		for(j=0;j<n;j++) {
			out[i]+=m->m[i][j]*v[j];
		}
		out[i]%=modBy;
	}
}

void mulMatMat(MATRIX* out,const MATRIX* x,const MATRIX* y,int n,int modBy) {
	int i,j,k;
	for(i=0;i<n;i++) {
		for(j=0;j<n;j++) {
			out->m[i][j]=0;
			for(k=0;k<n;k++)out->m[i][j]+=x->m[i][k]*y->m[k][j];
			out->m[i][j]%=modBy;
		}
	}
}

void powMat(MATRIX* out,const MATRIX* in,int powNum,int n,int modBy) {
	MATRIX resultBuf[2];
	MATRIX mulBuf[2];
	int i,j;
	int resultNo=0;
	int mulNo=0;
	for(i=0;i<n;i++) {
		for(j=0;j<n;j++) {
			mulBuf[0].m[i][j]=in->m[i][j];
			resultBuf[0].m[i][j]=(i==j?1:0);
		}
	}
	while(powNum>0) {
		if(powNum&1) {
			mulMatMat(&resultBuf[1-resultNo],
				&resultBuf[resultNo],&mulBuf[mulNo],n,modBy);
			resultNo=1-resultNo;
		}
		mulMatMat(&mulBuf[1-mulNo],&mulBuf[mulNo],&mulBuf[mulNo],n,modBy);
		mulNo=1-mulNo;
		powNum>>=1;
	}
	for(i=0;i<n;i++) {
		for(j=0;j<n;j++)out->m[i][j]=resultBuf[resultNo].m[i][j];
	}
}

int main(void) {
	int N,M,A,B,C,T;
	while(scanf("%d%d%d%d%d%d",&N,&M,&A,&B,&C,&T)==6 && (N|M|A|B|C|T)!=0) {
		MATRIX automaton;
		MATRIX automatonStatus;
		int initialStatus[50];
		int resultStatus[50];
		int i,j;
		for(i=0;i<N;i++)scanf("%d",&initialStatus[i]);
		for(i=0;i<N;i++) {
			for(j=0;j<N;j++) {
				switch(i-j) {
					case  1: automaton.m[i][j]=A;break;
					case  0: automaton.m[i][j]=B;break;
					case -1: automaton.m[i][j]=C;break;
					default: automaton.m[i][j]=0;break;
				}
			}
		}
		powMat(&automatonStatus,&automaton,T,N,M);
		mulMatVec(resultStatus,&automatonStatus,initialStatus,N,M);
		for(i=0;i<N;i++) {
			printf("%d%c",resultStatus[i],i+1<N?' ':'\n');
		}
	}
	return 0;
}

Measured memory_bytes: 656
# frozen_string_literal: true

n, m = gets.split.map(&:to_i)

switches = []
m.times do
  tmp = gets.split.map(&:to_i)
  tmp.shift(1)
  switches << tmp.map { |item| item - 1 }
end

ps = gets.split.map(&:to_i)

cnt = 0
[true, false].repeated_permutation(n) do |ary|
  flg = true
  ps.each_with_index do |mod, index|
    switch = switches[index]

    dummy_count = 0
    switch.each do |s|
      value = ary[s] ? 1 : 0
      dummy_count += value
    end

    flg = dummy_count % 2 == mod

    break unless flg
  end
  cnt += 1 if flg
end

puts cnt


Measured memory_bytes: 1916
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var a = Input().ToInt();
		var n = a[0];
		var m = a[1];
		long wa = 0;
		
		var was = new long[200001];
		for(int i = 1; i <= 200000; i++)
		{
			was[i] = was[i-1] + i;
		}
		
		for(int i = m; i <= n+1; i++)
		{
			if(i == n+1)
			{
				wa += 1;
			}
			else
			{
				long q = was[i-1];
				//Console.WriteLine("{0} {1} {2} {3}", i, n, q, i * n-q);
				long d = ((i % Giri) * (n % Giri)) % Giri;
				//d -= (q & (Giri-1)) * 2+1;
				d = ((d + Giri) - ((q % Giri) * 2))%Giri + 1;
				wa += d % Giri;
				//wa += i * n-q*2+1;
				//Console.WriteLine("{0} {1}", i, d);
			}
			wa %= Giri;
		}
		Console.WriteLine(wa % Giri);
	}
	
	static long Kaijo(long i)
	{
		long wa = 0;
		for(long j = i-1; j >=1; j--)
			wa += j; 
		return wa;
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 29052
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
set<string> T;
string func(string S,ll N){
    if(N>0){
        ll maxc=0;
        rep(i,S.size())maxc=max(maxc,(ll)S[i]-'a');
        rep(i,maxc+2)func(S+(char)('a'+i),N-1);
    }
    else T.insert(S);
    return S;
}
int main(){
    ll N;cin>>N;
    func("a",N-1);
    for(auto p:T)cout<<p<<endl;
    return 0;
}

Measured memory_bytes: 14208
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A1 = sc.nextInt();
        int A2 = sc.nextInt();
        int A3 = sc.nextInt();
        int sum = A1 + A2 + A3;

        if (sum >= 22) {
            System.out.println("bust");
        } else {
            System.out.println("win");
        }
        
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <string.h>
using namespace std;
#define MAX_N 10000
#define INF 1000000
struct road{int to,dist,cost;};
typedef pair<int,int> P;

int main(){
  while(1){
    int n,m;
    vector<road> roads[MAX_N];
    int dist[MAX_N],cost[MAX_N];
    road pre[MAX_N];

    scanf("%d%d",&n,&m);
    if(!n&&!m)break;

    for(int i=0;i<m;i++){
      int u,v,d,c;
      scanf("%d%d%d%d",&u,&v,&d,&c);
      roads[u-1].push_back((road){v-1,d,c});
      roads[v-1].push_back((road){u-1,d,c});
    }

    fill(dist,dist+n,INF);
    priority_queue<P, vector<P>, greater<P> > que;
    dist[0] = 0;
    que.push(P(0,0));
    while(que.size()){
      P p = que.top(); que.pop();
      int d = p.first;
      int pos = p.second;
      //cout << pos+1 << endl;
      if(d>dist[pos]) continue;
      for(int i=0;i<roads[pos].size();i++){
        int to = roads[pos][i].to;
        int co = roads[pos][i].dist + dist[pos];
        //cout << pos+1 <<"->" << to+1<< endl;
        if(dist[to]>co){
          pre[to] = roads[pos][i];
          dist[to] = co;
          que.push(P(dist[to],to));
        }else if(dist[to]==co){
          if(pre[to].cost>roads[pos][i].cost){
            pre[to] = roads[pos][i];
          }
        }
      }
    }

    int sum=0;
    for(int i=1;i<n;i++){
      sum += pre[n-i].cost;
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	int main()
	{
		std::ios::sync_with_stdio(false);

		// cin.ignore(); must be there when using getline(cin, s)
		int sum=0,temp,m=11;
		for (int i = 0; i < 5; ++i)
		{
			cin>>temp;
			if(temp%10!=0)
				m=min(m,temp%10);
			sum+=(int)ceil(temp/10.0);
		}
		cout<<(sum-1)*10+(m==11?10:m);
	}

Measured memory_bytes: 384
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k;
	LL sum1 = 0;
	LL sum2 = 0;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
	{
		if (i%k == 0) sum1++;
		if (i%k * 2 == k) sum2++;
	}
	cout << sum1 * sum1*sum1 + sum2 * sum2*sum2 << endl;
	return 0;
}


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

int main()
{
long long int n,i,x,y;
cin>>n;
vector<pair<long long int,long long int>> a;
for(i=0;i<n;i++)
{
cin>>x>>y;
a.push_back(make_pair(x,y));
}
long long int mx1=a[0].first+a[0].second , mn1=a[0].first+a[0].second;
long long int mx2=a[0].first-a[0].second , mn2=a[0].first-a[0].second;
for(i=1;i<n;i++)
{
mx1=max(mx1,a[i].first+a[i].second);
mn1=min(mn1,a[i].first+a[i].second);
mx2=max(mx2,a[i].first-a[i].second);
mn2=min(mn2,a[i].first-a[i].second);
}
cout<<max(mx1-mn1,mx2-mn2);
return 0;
}

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

using namespace std;

int main(){
  string s,t,u;
  int a,b;
  cin >> s >> t >> a >> b >> u;
  if(u == s){
    a -= 1;
  }else{
    b -= 1;
  }
  cout << a << " " << b;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll T,n,i,k,tmp,ans=0;cin>>T>>n;
  ll s[n],t[n],sum[n+2];
  vector<ll> v;
  sum[0]=0;
  for(i=0;i<n;i++){
    cin >> s[i] >> t[i];
    v.push_back(s[i]);
    sum[i+1]=sum[i]+t[i]-s[i];
  }
  sum[n+1]=sum[n];
  v.push_back(1e18);
  for(i=0;i<n;i++){
    tmp=0;
    k=distance(v.begin(),lower_bound(v.begin(),v.end(),s[i]+T))-1;
    //cout << i << ":" << s[k] << endl;
    //cout << sum[k] << "-" << sum [i] << endl; 
    tmp+=sum[k]-sum[i];
    tmp+=min(s[i]+T,t[k])-s[k];
    //cout << i << ":" << tmp << endl; 
    ans=max(ans,tmp);  
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4400
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long int A,B;
    cin >> A >> B;
  
  if(A==B){
    cout << 1 << endl;
  }
  else if((A+B)%2==0){
    cout << (A+B)/2 << endl;
  }
  else
    cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
long long mod=1e9+7;
//
int main(){
	long long n,m,x;
	long long c[12];
	long long a[12][12];
	cin>>n>>m>>x;
	for(long long i=0;i<n;i++){
		cin>>c[i];
		for(long long j=0;j<m;j++){
			cin>>a[i][j];
		}
	}
	long long ans=1e9+7;
	for(long long i=0;i<(1<<n);i++){
		long long sum=0;
		long long cnt[12]={};
		for(long long j=0;j<12;j++){
			if(i&(1<<j)){
				sum+=c[j];
				for(int k=0;k<m;k++){
					cnt[k]+=a[j][k];
				}
			}
		}
		bool f=true;
		for(int j=0;j<m;j++){
			if(cnt[j]<x){
				f=false;
			}
		}
		if(f){
			ans=min(ans,sum);
		}
	}
	if(ans==1e9+7){
		cout<<-1<<endl;
	}else{
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 1000000000
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    string s; cin >> s;
    int ret = 700;
    for(auto ch : s)
        if(ch == 'o')
            ret += 100;
    cout << ret;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s;
int main()
{
	cin>>s;
	bool begin=false;
	bool end=false;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='C')begin=true;
		if(begin&&s[i]=='F')end=true;
		if(begin&&end)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	} 
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int heap[500010];

void maxHeapify( int,int);
void buildMaxHeap(int);

int main(){

  int i,j,sumnode;

  scanf("%d",&sumnode);

  for(i =1; i<= sumnode; i++){

    scanf("%d",&heap[i]);

  }

  buildMaxHeap(sumnode);


  for(i = 1; i <= sumnode; i++){

    printf(" %d",heap[i]);

  }

  printf("\n");

  return 0;

}

void buildMaxHeap(int sumnode){

  int i;

  for(i = sumnode/2; i >=1 ; i--){

    maxHeapify(i,sumnode);

  }

}

void maxHeapify(int i ,int sumnode){

  int left,right,largest,swap;

  left = i *2;
  right = i *2 +1;

  if(left <= sumnode && heap[left] > heap[i]){

    largest = left;

  }

  else{

    largest = i;

  }


  if(right <= sumnode && heap[right] > heap[largest]){

    largest = right;

  }


  if(largest != i){

    swap = heap[i];

    heap[i] = heap[largest];

    heap[largest] = swap;

    maxHeapify(largest,sumnode);

  }

}

Measured memory_bytes: 2552
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>
#include <bitset>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
bool dp[2][16001];
const int base = 8000;

int main(int argc, char const* argv[])
{
  string s;
  cin >> s;
  int x, y;
  cin >> x >> y;
  vector<int> a, b;
  bool leri = true;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == 'T')leri = !leri;
    else if(s[i] == 'F'){
      if(i == 0 || s[i - 1] == 'T'){
        if(leri)a.pb(1);
        else b.pb(1);
      }else{
        if(leri)a[a.size() - 1]++;
        else b[b.size() - 1]++;
      }
    }
  }

  fill(dp[0], dp[0] + 16001, false);
  if(a.size() > 0 && s[0] == 'F'){
    dp[0][base + a[0]] = true;
  }else if(a.size() > 0){
    dp[0][base + a[0]] = true;
    dp[0][base - a[0]] = true;
  }
  for(int i = 1; i < a.size(); i++){
    fill(dp[1], dp[1] + 16001, false);
    for(int j = 0; j < 16001; j++){
      if(dp[0][j]){
        if(j + a[i] >= 0 && j + a[i] < 16001)dp[1][j + a[i]] = true;
        if(j - a[i] >= 0 && j - a[i] < 16001)dp[1][j - a[i]] = true;
      }
    }
    swap(dp[0], dp[1]);
  }
  if(!dp[0][x + base] && !(a.size() == 0 && x == 0)){
    cout << "No" << endl;
    return 0;
  }
  fill(dp[0], dp[0] + 16001, false);
  if(b.size() > 0){
    dp[0][base + b[0]] = true;
    dp[0][base - b[0]] = true;
  }
  for(int i = 1; i < b.size(); i++){
    fill(dp[1], dp[1] + 16001, false);
    for(int j = 0; j < 16001; j++){
      if(dp[0][j]){
        if(j + b[i] >= 0 && j + b[i])dp[1][j + b[i]] = true;
        if(j - b[i] >= 0 && j - b[i])dp[1][j - b[i]] = true;
      }
    }
    swap(dp[0], dp[1]);
  }
  if(!dp[0][y + base] && !(b.size() == 0 && y == 0)){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
	return 0;
}


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

namespace HABIT{
    #define f(a,b,c,d) for(register int a=b,c=d;a<=c;a++)
    #define g(a,b,c,d) for(register int a=b,c=d;a>=c;a--)
    #define LOCAL
    typedef int i32;
    typedef unsigned int u32;
    typedef long long int i64;
    typedef unsigned long long int u64;
    typedef pair<i32,i32> pii;
    const i32 MAXN=1e5+10;
    typedef i64 ar[MAXN];
    
    template<typename T> inline T Max(T a) { return a; }
    template<typename T,typename... Args> inline T Max(T a,Args... args){
        T b=Max(args...);
        return (a>b)?a:b;
    }
    template<typename T> inline T Min(T a) { return a; }
    template<typename T,typename... Args> inline T Min(T a,Args... args){
        T b=Min(args...);
        return (a<b)?a:b;
    }

    #ifdef LOCAL
        inline char gc() { return getchar(); }
    #else
        inline char gc() {
            static char s[1<<20|1]={0},*p1=s,*p2=s;
            return (p1==p2)&&(p2=(p1=s)+fread(s,1,1<<20,stdin),p1==p2)?EOF:*(p1++);
        }
    #endif
    inline i64 read(){
        register i64 ans=0;register char c=gc();register bool neg=0;
        while(c<48||c>57) neg^=!(c^'-'),c=gc();
        while(c>=48&&c<=57) ans=(ans<<3)+(ans<<1)+(c^48),c=gc();
        return neg?-ans:ans;
    }

    char Output_Ans[1<<20|1],*Output_Cur=Output_Ans;
    inline void output() { Output_Cur-=fwrite(Output_Ans,1,Output_Cur-Output_Ans,stdout); }
    inline void print(char c){
        if(Output_Cur-Output_Ans+1>>20) output();
        *(Output_Cur++)=c;
    }
    inline void print(char *s) { while(*s) print( *(s++) ); }
    inline void print(u64 x){
        if(!x) { print('0'); return ; }
        char buf[30]={0},*p=buf+28;
        while(x) *(p--)=x%10+48,x/=10;
        print(p+1);
    }
    inline void print(u32 x) { print( (u64)x ); }
    inline void print(i64 x){
        if(x<0) print('-'),x=-x;
        print( (u64)x );
    }
    inline void print(i32 x){
        if(x<0) print('-'),x=-x;
        print( (u64)x );
    }
}
using namespace HABIT;

i64 N;
ar A;

inline i64 ans(){
    i64 Ans=1,Lim=1e18;
    f(i,1,I,N){
        if(Ans<=Lim/A[i])
            Ans*=A[i];
        else
            return -1;
        if(Ans>Lim)
            return -1;
    }
    return Ans;
}

int main(){
    N=read();
    f(i,1,I,N) A[i]=read();
    sort(A+1,A+1+N);
    if(A[1]==0) print(0);
    else print( ans() );
    output();
    return 0;
}

Measured memory_bytes: 4416
//A - comes only from A's and AB's - 
//AB gives me better then I will buy there
//B - comes only from
//if half the charge is less than half tthe mine then non need of buying that
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;
  
  int na=0,nb=0,cost=0;
  
  if(c*2<=a){na=x;nb=x;cost=x*2*c;}
  if(c*2<=b){int rem = y-nb;nb+=(rem);na+=(rem);cost+=(rem)*2*c;}
 // cout<<na<<' '<<nb<<'\n';
  if(2*c<=(a+b)){int rem=min(x-na,y-nb);
  if(rem>=0){nb+=rem;na+=rem;cost+=2*c*rem;}}
 // cout<<na<<' '<<nb<<'\n';
  if(x-na>0)cost+=a*(x-na);
  if(y-nb>0)cost+=b*(y-nb);
  
  cout<<cost;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;

int p(int X){
    return (X-1)%10;
}

int main() {
    vector<int> A(5);
    rep(i,5){cin>>A.at(i);}
    vector<int> a(5);
    rep(i,5){
        a.at(i)=p(A.at(i));
    }
    sort(a.begin(),a.end());
    int s=a.at(0)+1;
    s=10-s;
    int t=0;
    rep(i,5){
        t+=A.at(i);
        t+=9;
        t/=10;
        t*=10;
    }
    cout<<t-s<<endl;
}

Measured memory_bytes: 3600
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    string s;
    cin>>s;
    vec a(s.size(),1);
    rep(i,s.size()-1){
        if(s[i]=='R'&&s[i+1]=='R') a[i+1]+=a[i],a[i]=0;
    }
    for(int i=a.size()-1;i>0;i--){
        if(s[i]=='L'&&s[i-1]=='L') a[i-1]+=a[i],a[i]=0;
    }
    rep(i,s.size()){
        // cout<<a[i]<<endl;
    }
    rep(i,s.size()-1){
        if(a[i]!=0&&a[i+1]!=0){
            int memo=a[i]+a[i+1];
            if(memo%2==1){
                swap(a[i],a[i+1]);
                if(a[i]%2==1){
                    a[i]=memo/2;
                    a[i+1]=memo/2+1;
                }
                else{
                    a[i]=memo/2+1;
                    a[i+1]=memo/2;
                }
            }
            else{
                a[i]=memo/2;
                a[i+1]=memo/2;
            }
            i++;
        }
        
    }
    rep(i,s.size()){
        cout<<a[i]<<endl;
    }
}

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


int main() {
  int a,b,c;
  cin>>a>>b>>c;
  if((a==5&&b==5&&c==7)||(a==5&&b==7&&c==5)||(a==7&&b==5&&c==5)){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MAXN=100010;
int a[MAXN],n,cnt,b[MAXN],c[MAXN];
inline int read(){
    int f=1,x=0;
    char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
    return f*x;
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) cin>>b[i];
    for(int i=1;i<=n;i++) c[i]=a[i]-b[i];
    for(int i=1;i<=n;i++) if(c[i]>0) cnt+=c[i];
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    long int a=0,b=0,temp;
    
    long int r,f;
    
    long int A,B;
    
    while(scanf("%ld %ld",&a,&b)!=EOF){
        A=a;
        B=b;
        
        if(b>a){
           temp=a;
           a=b;
           b=temp;
        }
        do{
            r= a % b;
            a = b;
            b = r;
        } while (r != 0);
        
        f=A*B/a;
        printf("%ld %ld\n",a,f);
    }
    
}



Measured memory_bytes: 1976
//https://onlinejudge.u-aizu.ac.jp/challenges/sources/JOI/Prelim/0544?year=2010

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, m;

    while (cin >> n >> m, n | m) {
        int cmd[1010];
        for (int i = 1; i <= n; ++i) {
            cin >> cmd[i];
        }

        int dice[1010];
        for (int i = 1; i <= m; ++i) {
            cin >> dice[i];
        }

        int cur = 1, ans = 0;
        for (int i = 1; i <= m; ++i) {
            ans++;
            cur += dice[i];
            cur += cmd[cur];
            if (cur >= n) {
                cout << ans << endl;
                break;
            }
        }
    }
    return 0;
}

/*
 *
 */


Measured memory_bytes: 3076
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

const int MAX = 500000,MS=2;
const ll mod[] = {999999937LL, 1000000007LL}, base = 9973;
struct rolling_hash{
    int n;
    vector<ll> hs[MS],pw[MS];
    rolling_hash(){};
    rolling_hash(const string &s){
        n=s.size();
        for(int i=0;i<MS;i++){
            hs[i].assign(n+1,0);
            pw[i].assign(n+1,0);
            hs[i][0]=0;
            pw[i][0]=1;
            for(int j=0;j<n;j++){
                pw[i][j+1] = pw[i][j]*base%mod[i];
                hs[i][j+1] = (hs[i][j]*base+s[j])%mod[i];
            }
        }
    }
    ll get_hash(int l,int r,int i){
        return ((hs[i][r]-hs[i][l]*pw[i][r-l])%mod[i]+mod[i])%mod[i];
    }
};

int main(){
    int N;string S;
    cin >> N;
    cin >> S;
    using pii = pair<int,int>;
    rolling_hash rh = rolling_hash(S);
    int l = 0,r = N;
    while(r-l>1){
        int found = 0;
        int mid = (l+r)/2;
        for(int i=0;i<N;i++){
            if(i+mid-1>=N)break;
            pii first = make_pair(rh.get_hash(i,i+mid,0),rh.get_hash(i,i+mid,1));
            for(int j=i+mid;j<N;j++){
                if(j+mid-1>=N)break;
                pii second = make_pair(rh.get_hash(j,j+mid,0),rh.get_hash(j,j+mid,1));    
                if(first==second)found=1;
            }
        }
        if(found)l=mid;
        else r=mid;
    }

    cout << l << endl; 

    return 0;
}

Measured memory_bytes: 384
using System;
using System.Linq;

class prog{
  static void Main(){
    
    int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int N = n[0];
    int K = n[1];
    
    Console.WriteLine((int)Math.Ceiling((double)(N - K) / (K - 1)) + 1);
    
  }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h> 
using namespace std; 
  
typedef long long int ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef pair<string, string> pss; 
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef vector<pii> vii; 
typedef vector<ll> vl; 
typedef vector<vl> vvl; 
  
double EPS = 1e-9; 
long long INF = 1000000000000000005ll; 
double PI = acos(-1); 
#define M 1000000007ll
#define D 998244353ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound  
#define SQR(x) ((LL)(x) * (x)) 
#define RESET(a, b) memset(a, b, sizeof(a))
#define GCD(a,b) __gcd(a,b)
#define setbits(x)   __builtin_popcountll(x)
#define zerobits(x)  __builtin_ctzll(x) 
#define ps(x,y)  fixed<<setprecision(y)<<x
#define endl '\n'
#define ff first 
#define ss second 
#define mp make_pair  
#define ALL(v) v.begin(), v.end() 
#define ALLA(arr, sz) arr, arr + sz 
#define SIZE(v) (int)v.size() 
#define SORT(v) sort(ALL(v)) 
#define REVERSE(v) reverse(ALL(v)) 
#define SORTA(arr, sz) sort(ALLA(arr, sz)) 
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) 
#define PERMUTE next_permutation 
  
inline string IntToString(ll a) 
{ 
    char x[100]; 
    sprintf(x, "%lld", a); 
    string s = x; 
    return s; 
} 
  
inline ll StringToInt(string a) 
{ 
    char x[100]; 
    ll res; 
    strcpy(x, a.c_str()); 
    sscanf(x, "%lld", &res); 
    return res; 
} 
  

inline string uppercase(string s) 
{ 
    int n = SIZE(s); 
    for(ll i=0;i<n;i++) 
    if (s[i] >= 'a' && s[i] <= 'z') 
        s[i] = s[i] - 'a' + 'A'; 
    return s; 
} 
  
inline string lowercase(string s) 
{ 
    int n = SIZE(s); 
    for(ll i=0;i<n;i++) 
    if (s[i] >= 'A' && s[i] <= 'Z') 
        s[i] = s[i] - 'A' + 'a'; 
    return s; 
}

bool sortcol( const vector<ll>& v1, 
               const vector<ll>& v2 ) { 
 return v1[0] > v2[0]; 
} 

bool isPrime(ll n) 
{ 
    // Corner cases 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
  
    // This is checked so that we can skip  
    // middle five numbers in below loop 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}

int main() {
    FAST
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ll n;
    cin>>n;
    ll a[n];
    map <ll,ll> m;
    for(ll i=0;i<n;i++){
    	cin>>a[i];
    	//m[a[i]]++;
    }
    sort(a,a+n);
    ll cnt=0;
    for(ll i=0;i<n;i++){
    	//cout<<a[i]<<endl;
    	for(ll j=a[i];j<=a[n-1];j+=a[i]){
    		m[j]++;
    	}
    }
  	for(ll i=0;i<n;i++){
  		if(m[a[i]]>1){
  			cnt++;
  		}
  	}
  	cout<<n-cnt<<endl;
    return 0;
}

Measured memory_bytes: 67344
n = int(input())
a = [0]*n
for i in range(n):
    a[i] = list(map(int,input().split()))
dp = [[0 for j in range(3)] for i in range(n)]
dp[0] = a[0][:]
for i in range(1,n):
    dp[i][0] = max(dp[i-1][1]+a[i][0],dp[i-1][2]+a[i][0])
    dp[i][1] = max(dp[i-1][2]+a[i][1],dp[i-1][0]+a[i][1])
    dp[i][2] = max(dp[i-1][0]+a[i][2],dp[i-1][1]+a[i][2])
print(max(dp[-1][:]))

Measured memory_bytes: 72652
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()

	x := make([]int, n)
	sum := 0.0
	for i := 0; i < n; i++ {
		x[i] = nextInt()
		sum += float64(x[i])
	}

	p := int(sum/float64(n) + 0.5)
	ans := 0

	for _, y := range x {
		ans += (p - y) * (p - y)
	}

	fmt.Println(ans)
}


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

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

    int h, w, n; 
    cin >> h >> w >> n;
    cout << n / max(h, w) + (n%max(h, w) != 0) << endl;

    return 0;
}

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

using namespace std;

#define int long long

int comb(int n,int k){
    int res=1;
    if(n<k)return 0;
    k=min(n-k,k);
    for(int i=n-k+1;i<=n;++i)res=res*i;
    for(int i=1;i<=k;i++)res/=i;
    return res;
}

signed main(){
    int n,p;
    cin>>n>>p;
    int gu=0,ki=0;
    for(int i=0;i<n;++i){
        int a;
        cin>>a;
        if(a%2)ki++;
        else gu++;
    }
    int res=1;
    for(int i=0;i<gu;++i){
        res*=2;
    }
    int res1=0;
    if(p){
        for(int i=1;i<=ki;i+=2){
            res1+=comb(ki,i);
        }
    }else{
        for(int i=0;i<=ki;i+=2){
            res1+=comb(ki,i);
        }
    }
    cout<<res*res1<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int c[50][50];
int w,h;

int visit(int i,int j){
  c[i][j]=0;
  if((i+1)<h){
    if(c[i+1][j]==1) visit(i+1,j);
    if((j+1)<w) if(c[i+1][j+1]==1) visit(i+1,j+1);
    if((j-1)>=0) if(c[i+1][j-1]==1) visit(i+1,j-1);
  }
  if((j+1)<w)if(c[i][j+1]==1) visit(i,j+1);
  if((i-1)>=0){
    if(c[i-1][j]==1) visit(i-1,j);
    if((j-1)>=0) if(c[i-1][j-1]==1) visit(i-1,j-1);
    if((j+1)<w) if(c[i-1][j+1]==1) visit(i-1,j+1);
  }
  if((j-1)>=0) if(c[i][j-1]==1) visit(i,j-1);

  return 0;
}

int main(){
  int co;
  int i,j,k,l;

  while(1){
    scanf("%d %d",&w,&h);
    if(w==0 && h==0) break;
    co=0;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	scanf("%d",&c[i][j]);
      }
    }
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	if(c[i][j]==1){
	  visit(i,j);
	  co++;
	  
	}
      }
    }
    printf("%d\n",co);
  }
  return 0;
}

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

using namespace std;

#define ll long long int

int main()
{
    int n,k,i,j,ara[1005];

    cin>>n>>k;

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

    int ans=0;

    for(i=0; i<n; i++)
    {
        int temp1=min((k-ara[i])*2,ara[i]*2);

        ans+=temp1;
    }

    cout<<ans<<endl;
}


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

using namespace std;

#define ll 			long long
#define db			double
#define up(i,j,n)		for (int i = j; i <= n; i++)
#define down(i,j,n)	for (int i = j; i >= n; i--)
#define cadd(a,b)		a = add (a, b)
#define cpop(a,b)		a = pop (a, b)
#define cmul(a,b)		a = mul (a, b)
#define pr			pair<int, int>
#define fi			first
#define se			second
#define SZ(x)		(int)x.size()
#define bin(i)		(1 << (i))
#define Auto(i,node)	for (int i = LINK[node]; i; i = e[i].next)

template<typename T> inline bool cmax(T & x, T y){return y > x ? x = y, true : false;}
template<typename T> inline bool cmin(T & x, T y){return y < x ? x = y, true : false;}

const int MAXN = 5005;;
const int oo = 0x3f3f3f3f;
const int mod = 1e9 + 7;

inline int add(int a, int b){a += b; return a >= mod ? a - mod : a;}
inline int pop(int a, int b){a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b){return 1LL * a * b % mod;}

int N, fac[MAXN], f[MAXN], g[MAXN], a[MAXN], C[MAXN][MAXN], M = 0, ans = 0;

struct edge {
	int y, next;
}e[MAXN << 1];
int LINK[MAXN], len = 0, siz[MAXN], mxsiz[MAXN], rt[MAXN], rts;
inline void ins(int x, int y){
	e[++len].next = LINK[x]; LINK[x] = len;
	e[len].y = y; 
}
inline void Ins(int x, int y){
	ins(x, y);
	ins(y, x);
}

void DFS(int node, int fa){
	siz[node] = 1; mxsiz[node] = 0;
	Auto (i, node) if (e[i].y != fa) {
		DFS(e[i].y, node);
		siz[node] += siz[e[i].y];
		cmax(mxsiz[node], siz[e[i].y]);
	}
	cmax(mxsiz[node], N - siz[node]);
	if (mxsiz[node] < mxsiz[rt[rts]]) rt[rts = 1] = node;
	else if (mxsiz[node] == mxsiz[rt[rts]]) rt[++rts] = node;
}

void Fix(int node, int fa){
	siz[node] = 1;
	Auto (i, node) if (e[i].y != fa) {
		Fix(e[i].y, node);
		siz[node] += siz[e[i].y];
	}
}

int main(){
	scanf("%d", &N);
	C[0][0] = 1;
	up (i, 1, N) {
		C[i][0] = 1;
		up (j, 1, i) C[i][j] = add(C[i - 1][j - 1], C[i - 1][j]);
	} 
	fac[0] = 1;
	up (i, 1, N) fac[i] = mul(i, fac[i - 1]);
	up (i, 2, N) {
		int x, y;
		scanf("%d%d", &x, &y);
		Ins(x, y);
	}
	mxsiz[0] = oo;
	DFS(1, 0);
	if (rts == 2) {
		Fix(rt[1], rt[2]);
		Fix(rt[2], rt[1]);
		printf("%d\n", mul(fac[siz[rt[1]]], fac[siz[rt[2]]]));
		return 0;
	}
	Fix(rt[1], 0); 
	Auto (i, rt[1]) a[++M] = siz[e[i].y];
	f[0] = 1;
	int cur = 0;
	up (i, 1, M) {
		memset(g, 0, sizeof(int) * (cur + 1));
		up (j, 0, cur) up (k, 0, a[i]) cadd(g[j + k], mul(f[j], mul(C[a[i]][k], mul(C[a[i]][k], fac[k]))));
		cur += a[i];
		memcpy(f, g, sizeof(int) * (cur + 1));
	} 
	up (i, 0, N) {
		if (i & 1) 	cpop(ans, mul(f[i], fac[N - i]));
		else		cadd(ans, mul(f[i], fac[N - i]));
	} 
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 96896
import math
# from collections import Counter

# N = int(input()) # 1行, 単数
# arg = list(map(int, input().split())) # 1行, 配列
# D = Counter(arg) # 出現数カウント

# print('Yes')
# print('No')
# print()
N = int(input()) # 1行, 単数

i = 100
z = 1.01
count = 0
while i < N:
  i = math.floor(i * z)
  count = count + 1

print(count)

Measured memory_bytes: 63380
n,m = gets.split(" ").map(&:to_i)
candidates = []
h = Hash.new(false)
m.times do
  a,b = gets.split(" ").map(&:to_i)
  if b == n
    h[a] = true
  end
  if a == 1
    candidates << b
  end
end

ans = "IMPOSSIBLE"
candidates.each do |c|
  if h[c]
    ans = "POSSIBLE"
    break
  end
end

puts ans

Measured memory_bytes: 9084
use std::io;
use std::str::FromStr;
use std::collections::HashMap;

fn input_int_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn main() {
    let (n, m) = input_int_tuple();
    let mut a_vec: Vec<u64> = Vec::new();

    for i in 0..m {
        let a: u64 = input();
        a_vec.push(a);
    }

    if m == 0 {
        let fibonacci_vec = fibonacci(n);        
        println!("{}", fibonacci_vec[n as usize]);
        return;
    }

    let mut max_dist = a_vec[0];
    for i in 1..a_vec.len() {
        if a_vec[i as usize] - a_vec[i as usize - 1] > max_dist {
            max_dist = a_vec[i as usize] - a_vec[i as usize - 1];
        }
    }
    let fibonacci_vec = fibonacci(max_dist);

    let mut now = 0;
    let mut sum = 1;
    for a in &a_vec {
        let distance = *a - now;
        if distance == 0 {
            println!("0");
            return;
        }
        sum *= fibonacci_vec[(distance - 1) as usize];
        if sum > 1000000007 {
            sum %= 1000000007;
        }
        // println!("sum = {}", sum);
        now = *a + 1;
    }
    sum *= fibonacci_vec[(n - now) as usize];
    // println!("{:?}", a_vec);
    if sum > 1000000007 {
        sum %= 1000000007;
    }
    println!("{}", sum);
}

fn fibonacci(max: u64) -> Vec<u64> {
    let mut fibonacci_vec: Vec<u64> = Vec::new();
    for i in 0..max + 1 {
        if i == 0 || i == 1 {
            fibonacci_vec.push(1);
            continue;
        }        
        let mut n = fibonacci_vec[i as usize -1] + fibonacci_vec[i as usize -2];
        if n > 1000000007 {
            n %= 1000000007;
        }
        fibonacci_vec.push(n);
    }
    fibonacci_vec
}


Measured memory_bytes: 4352