akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

/*
 * adjrev -> reversed adjacency list
 * SCC -> saves number of Strongly Connected Components after the function calls.
 * components -> stores the nodes of all SCCs.
 */
vector<int> adj[N], in[N];
int dp[N];
bool vis[N];
stack<int> S;

/*
 * This method assumes 1-based indexing. For 0-based indexing, change call to dfs and adjacency list in main.
 * It doesn't handle self loops and back edges.
 */
void dfs(int src)
{
    vis[src] = true;
    for(int u : adj[src])
    {
        if(vis[u]) continue;
        dfs(u);
    }
    S.push(src);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int n, m;
    cin>>n>>m;
    f(i, m)
    {
        int u, v;
        cin>>u>>v;
        u--, v--;
        adj[u].pb(v);
        in[v].pb(u);
    }
    memset(vis, 0, sizeof(vis));
    f(i, n)
    {
        if(!vis[i])
        {
            dfs(i);
        }
    }
    memset(vis, 0, sizeof(vis));
    vector<int> topo;
    while(!S.empty()){
        topo.pb(S.top());
        S.pop();
    }
    for(int i : topo){
        for(int j : in[i]) {
            dp[i] = max(dp[j] + 1, dp[i]);
        }
    }
    int ans = 0;
    f(i, n) ans = max(ans, dp[i]);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 14516
#include <bits/stdc++.h>
#include <string>
using namespace std;
int N,M;
typedef long long ll;
typedef pair<int,int> p;
#define NMAX 1000
vector<p> data;
ll dp[NMAX][NMAX];

int main(){
    cin >> N >> M;
    priority_queue<int> pq;

    for(int i=0;i<N;i++){
        int tmp;
        cin >> tmp;
        pq.push(tmp);
    }
    int a=M;
    int b=M;
    while(a>0){
        ll tmp;
        tmp = pq.top();
        pq.pop();
        pq.push(tmp/2);
        a--;
    }
    ll ans =0;
    while(!pq.empty()){
        ll tmp;
        tmp = pq.top();
        pq.pop();
        ans += tmp;
    }

     cout << ans << endl;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t a,b,c,k,ans;
  cin >> a >> b >> c >> k;
  if(k <= a){
    ans = 1*k;
  }else if(k <= a+b){
    ans = 1*a;
  }else{
    ans = 1*a - (k-a-b)*1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3604
n=int(input())
a=list(map(lambda x: int(x), input().split()))
dic={}
for i in a:
    dic[i]=dic.get(i,0)+1
tmp=dic.get(0,0)+dic.get(1,0)
ans=0
for i in range(2,100000):
    tmp+=dic.get(i,0)
    if tmp>ans:
        ans=tmp
    tmp-=dic.get(i-2,0)
print(ans)

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

int main() {
  string S;
  cin >> S;
  int sum=700;
  
  if(S[0]=='o') sum+=100;
  if(S[1]=='o') sum+=100;
  if(S[2]=='o') sum+=100;
  
  cout << sum <<endl;
}


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

static const int MAX_NUM = 101;

static const int NO_VISIT  = 0;
static const int NOW_VISIT = 1;
static const int END_VISIT = 2;

void DSF(int* matrix, int num)
{
    int i, j;
    int ttime = 0;
    int stime[MAX_NUM+1] = {0};
    int etime[MAX_NUM+1] = {0};
    int state[MAX_NUM+1] = {0};
    stack<int> S;
    int target, next;
    int *tmp;

    for (j = 1; j <= num; j++) {
    if (state[j] != NO_VISIT) {
        continue;
    }
    S.push(j);
    ++ttime;
    stime[j] = ttime;
    state[j] = NOW_VISIT;

    while (S.empty() == false) {
        target = S.top();
        for (i = 1; i <= num; i++) {
            tmp = matrix + MAX_NUM * target + i;
            if ((*tmp == 1) && (state[i] == NO_VISIT)) {
                *tmp = 2;
                S.push(i);
                ++ttime;
                stime[i] = ttime;
                state[i] = NOW_VISIT;
                break;
            }
        }

        if (i == num + 1) {
            S.pop();
            ++ttime;
            etime[target] = ttime;
            state[target] = END_VISIT;
        }
    }
    }

    for (i = 1; i <= num; i++) {
        printf("%d %d %d\n", i, stime[i], etime[i]);
    }

    return;
}

int main(void)
{
    int i, j;
    int num;
    int elem;
    int nume;
    int tmp;
    int matrix[MAX_NUM][MAX_NUM] = {0};

    scanf("%d", &num);

    for (i = 0; i < num; i++) {
        scanf("%d %d", &elem, &nume);
        for (j = 0; j < nume; j++) {
            scanf("%d", &tmp);
            matrix[elem][tmp] = 1;
        }
    }

    DSF(&matrix[0][0], num);

    return 0;
}

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

#define INF 0x7fffffff

int main() {
	int		i,j,k,n,m,x,y,ans = 0;
	int		tmp = INF;

	cin >> n >> m;

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

	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());

	//for(i=0;i<n;i++)
	//	cout << a[i] << endl;

	if ( (double)a[m-1] >= (double)ans/(4*m) ) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

}


Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())


def factor(n, m=None):
    # mを与えると、高々その素因数まで見て、残りは分解せずにそのまま出力する
    arr = {}
    temp = n
    M = int(-(-n**0.5//1))+1
    if m is not None:
        M = min(m+1, M)
    for i in range(2, M):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr[i] = cnt

    if temp!=1:
        arr[temp] = 1

    if not arr:
        arr[n] = 1

    return arr
d = factor(n)
ks = list(d.keys())
l = len(ks)
ans = 0
for b in range(1<<l):
    v = 1
    s = 0
    for i in range(l):
        if b>>i&1:
            v *= ks[i]
            s += 1
    ans += (n//v) * pow(-1, s)
print(ans)            


Measured memory_bytes: 5660
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
int main(){
    string s;
    cin >> s;
    vector<int> G[26];
    for(int i = 0; i < s.size(); i++){
        G[s[i] - 'a'].push_back(i);
    }
    int ans = 1e9;
    for(int i = 0; i < 26; i++){
        vector<int> v = G[i];
        if(v.size() == 0) continue;
        int m = 0;
        int res = -1;
        for(int j: v){
            m = max(m, j - res - 1);
            res = j;
        }
        m = max(m, (int)s.size() - 1 - res);
        ans = min(ans, m);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int x,y,z;
	scanf("%d %d %d",&x,&y,&z);
	if((x==1&&y==1)||(z==1)){
		printf("Open\n");
	}
	else{
		printf("Close\n");
	}
	return 0;
}

Measured memory_bytes: 1012
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	const int mod=1e9+7;
	int h,w;
	cin>>h>>w;
	int dp[h+1][w+1];
	for(int i=0;i<=h;i++)
		dp[i][0]=0;
	for(int j=0;j<=w;j++)
		dp[0][j]=0;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			char ch;
			cin>>ch;
			if(ch!='#')
				dp[i][j]=1;
			else
				dp[i][j]=0;
		}
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(i==1&&j==1)
				continue;
			if(dp[i][j])
				dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
		}
	}
	cout<<dp[h][w];
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n, m; scanf("%d%d", &n, &m); std::vector<std::string> X(n), Y(n);
	std::set<std::string> st;
	for(int i = 0; i < n; i++) {
		cin >> X[i]; st.insert(X[i]);
		
		Y[i] = X[i];
		reverse(begin(Y[i]), end(Y[i]));
	}
	X.push_back("("); Y.push_back("{");
	sort(begin(X), end(X)); sort(begin(Y), end(Y));
	
	auto count = [](std::vector<std::string>& vec, std::string& s) {
		return upper_bound(begin(vec), end(vec), s + "{") - lower_bound(begin(vec), end(vec), s);
	};
	auto isExist = [&](std::string& s) {
		return st.count(s);
	};
	
	while(m--) {
		std::string s; cin >> s;
		
		auto getIndexQ = [](std::string& s) {
			for(int i = 0; i < s.size(); i++) if(s[i] == '?') return i;
			return -1;
		};
		auto doesExistAst = [](std::string& s) {
			if(s.front() == '*') return 1;
			if(s.back() == '*') return 2;
			return 0;
		};
		
		int ans = 0, ind = getIndexQ(s);
		if(ind != -1) {
			for(char ch = 'a'; ch <= 'z'; ch++) {
				s[ind] = ch;
				std::string t = s;
				
				int ast = doesExistAst(t);
				if(ast == 0) {
					ans += isExist(t);			
				} else if(ast == 1) {
					reverse(begin(t), end(t));
					t = t.substr(0, (int)t.size() - 1);
					ans += count(Y, t);
				} else {
					t = t.substr(0, (int)t.size() - 1);
					ans += count(X, t);
				}
			}		
		} else {
			int ast = doesExistAst(s);
			if(ast == 0) {
				ans = isExist(s);
			} else if(ast == 1) {
				reverse(begin(s), end(s));
				std::string t = s.substr(0, (int)s.size() - 1);
				ans = count(Y, t);
			} else {
				std::string t = s.substr(0, (int)s.size() - 1);
				ans = count(X, t);				
			}
		}
		
		printf("%d\n", ans);
	}
	return 0;
}



Measured memory_bytes: 14296
#include <cstdio>
#include <algorithm>
int N, a[100001];
bool check(int x)
{
	long long S = a[x];
	for (int i = 1; i <= N; i++)
		if (i != x)
		{
			if (S << 1 >= a[i])
				S += a[i];
			else
				return false;
		}
	return true;
}
int main()
{
	scanf("%d", &N);
	for (int i = 1; i <= N; i++)
		scanf("%d", a + i);
	std::sort(a + 1, a + N + 1);
	int l = 1, r = N;
	while (l < r)
	{
		int m = l + r >> 1;
		if (check(m))
			r = m;
		else
			l = m + 1;
	}
	printf("%d\n", N - l + 1);
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define BUF_SIZE 1500000

int update_incline(int prev, int cur, int incline) {
  if(prev == cur) {
    incline = incline & 3;
  } else {
    incline = incline & ((prev < cur)+1);
  }
  return incline;
}

int main(void) {
  char line[BUF_SIZE];
  FILE *fp = stdin;
  if(!fgets(line, BUF_SIZE, fp)) return 0;
  int num;
  sscanf(line, "%d", &num);

  if(!fgets(line, BUF_SIZE, fp)) return 0;
  int i;
  int cnt = 1;
  int incline = 3; // unknown
  char *tmp = strtok(line, " ");
  int prev = strtol(tmp, NULL, 10);
  for(i = 1; i < num; i++) {
    char *tmp = strtok(NULL, " ");
    int cur = strtol(tmp, NULL, 10);
    incline = update_incline(prev, cur, incline);
    if(incline == 0) {
      incline = 3;
      cnt++;
    }
    prev = cur;
  }

  printf("%d\n", cnt);
}

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

bool solve(string s){
  string t = "abc";
  do{
    if(s == t){
      return true;
    }
  }while(next_permutation(t.begin(), t.end()));
  return false;
}

int main(){
  string s;
  cin >> s;
  if(solve(s)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;

vector<P> v(100001),t(100001);

int main(){
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if(i%2){
            t[a].fs++;
            t[a].sc=a;
        }
        else{
            v[a].fs++;
            v[a].sc=a;
        }
    }
    sort(RALL(t));
    sort(RALL(v));
    if(t[0].sc!=v[0].sc) cout << n-(t[0].fs+v[0].fs) << endl;
    else{
        cout << n-max(t[1].fs+v[0].fs,t[0].fs+v[1].fs) << endl;
    }
    return 0;
}



Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str;
        StringBuilder sb = new StringBuilder();
        int m,f,r;
        while(true){
            str = br.readLine().split(" ");
            m = Integer.parseInt(str[0]);
            f = Integer.parseInt(str[1]);
            r = Integer.parseInt(str[2]);
            if(m == -1 && f == -1 && r == -1) break;
            if(m == -1 || f == -1){
                sb.append("F\n");
            }else if(m+f >= 80){
                sb.append("A\n");
            }else if(65 <= m+f && m+f < 80){
                sb.append("B\n");
            }else if(50 <= m+f && m+f < 65){
                sb.append("C\n");
            }else if(30 <= m+f && m+f < 50){
                if(r >= 50) sb.append("C\n");
                else sb.append("D\n");
            }else{
                sb.append("F\n");
            }
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 24228
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

############
############
############

N, K = l_inpl()
S = input()

ans = ""
for i in range(N):
    s = S[i]
    if i == K-1:
        s = s.lower()
    ans = ans + s

print(ans)

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

int main()
{
    int n,k;
    string a;
    char b;
    cin>>n;
    cin>>a;
    cin>>k;
    b=a[k-1];
    for(int i=0;i<n;i++)
        if(a[i]==b)
        cout<<a[i];
    else
        cout<<"*";
    return 0;
}


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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);
#define ll long long
#define ld long double

int main(){
  int x, y; // x 頭, y 足
  cin >> x >> y;
  bool can = false;
  for (int i = 0; i <= x; ++i) { // 弦の数
    if (i * 2 + (x - i) * 4 == y) {
      can = true;
      break;
    }
  }

  cout << (can ? "Yes" : "No") << endl;
  return 0;
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=998244353;
const int MAX=1e5+10;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    string t="PWGY";
    vector<int> cnt(4);
    rep(i,n) {
        char c;
        cin >> c;
        rep(i,4) {
            if (c==t[i]) cnt[i]=1;
        }
    } 
    int ans=0;
    rep(i,4) {
        if (cnt[i]==1) ++ans;
    }
    if (ans==3) cout << "Three" << endl;
    else cout << "Four" << endl;
     
    return 0;   
}

Measured memory_bytes: 3584
#!/usr/bin/env python


def run(a, vt, b, wt):
    if a < b:
        if b + wt <= a + vt:
            return 'YES'
        else:
            return 'NO'
    else:
        if a - vt <= b - wt:
            return 'YES'
        else:
            return 'NO'


def main():
    A, V = list(map(int, input().split()))
    B, W = list(map(int, input().split()))
    T = int(input())

    print(run(A, V*T, B, W*T))


if __name__ == '__main__':
    main()


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

int n;
vector<int> g[51];
vector<bool> vi(51);
map<P, bool> mp;

void dfs(int a, int d = 0) {
	vi[a] = true;
	for (auto& c : g[a]) {
		if (vi[c]) continue;
		if (mp[P(a, c)]) continue;
		dfs(c, d + 1);
	}
}

int main() {
	int n, m;
	cin >> n >> m;
	vector<P> p(m);
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		p[i].first = a;
		p[i].second = b;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}
	int ans = 0;
	rep(i, m) {
		mp[P(p[i].first, p[i].second)] = true;
		mp[P(p[i].second, p[i].first)] = true;
		rep(i, n) vi[i] = false;
		dfs(0);
		bool elf = true;
		rep(i, n) if (!vi[i]) elf = false;
		if (!elf) ans++;
		mp[P(p[i].first, p[i].second)] = false;
		mp[P(p[i].second, p[i].first)] = false;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
long long h,w,a,b;
int main(){
    ios::sync_with_stdio(0);
    cin>>h>>w>>a>>b;
    if (a==0&&b==0){
        for(int i=1; i<=h; i++){
            for(int j=1; j<=w; j++){
                cout<<0;
            }
            cout<<endl;
        }
        return 0;
    }
    if (a==0){
        for(int i=1; i<=b; i++){
            for (int j=1; j<=w; j++) cout<<0;
            cout<<endl;
        }
        for(int i=b+1; i<=h; i++){
            for(int j=1; j<=w; j++) cout<<1;
            cout<<endl;
        }
        return 0;
    }
    if (b==0){
        for(int i=1; i<=h; i++){
            for(int j=1; j<=a; j++) cout<<0;
            for(int j=a+1; j<=w; j++) cout<<1;
            cout<<endl;
        }
        return 0;
    }
    for(int i=1; i<=b; i++){
        for(int j=1; j<=a; j++) cout<<1;
        for(int j=a+1; j<=w; j++) cout<<0;
        cout<<endl;
    }
    for(int i=b+1; i<=h; i++){
        for(int j=1; j<=a; j++) cout<<0;
        for(int j=a+1; j<=w; j++) cout<<1;
        cout<<endl;
    }  
    return 0;
}

Measured memory_bytes: 3588
H, W = map(int, input().split())
grids = [input() for _ in range(H)]
dp = [[float('inf') for _ in range(W)] for _ in range(H)]
if grids[0][0] == '#':
    dp[0][0] = 1
else:
    dp[0][0] = 0

for i in range(W):
    for j in range(H):
        if i == 0 and j == 0:
            continue

        if i - 1 < 0:
            val1 = float('inf')
        elif grids[j][i - 1] == '.' and grids[j][i] == '#':
            val1 = dp[j][i - 1] + 1
        else:
            val1 = dp[j][i - 1]

        if j - 1 < 0:
            val2 = float('inf')
        elif grids[j - 1][i] == '.' and grids[j][i] == '#':
            val2 = dp[j - 1][i] + 1
        else:
            val2 = dp[j - 1][i]

        dp[j][i] = min(val1, val2)
        #print(i,j,dp)

#print(dp)
print(dp[-1][-1])


Measured memory_bytes: 43888
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
int dp[100001];

int solve(int a[], int n)
{
    if(n<2)
    {
        return 0;
    }
    
    if(dp[n] != -1)
    return dp[n];

    if(n==2)
        dp[n] = abs(a[n]-a[n-1]) + solve(a,n-1);

    if(n >2)
        dp[n] = min(abs(a[n]-a[n-1]) + solve(a,n-1),abs(a[n]- a[n-2]) +solve(a,n-2));

    return dp[n];
}

int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    memset(dp,-1,sizeof(dp));
   
   int l=solve(a,n);
    cout<<l<<"\n";

    return 0;
}


Measured memory_bytes: 8232
#include <iostream>
#include <algorithm>
#include <functional>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <queue>

using namespace std;
#define loop(i,n) for(int i = 0; i < (n); ++i)
#define loops(i,f,n) for(int i = (f); i < (n); ++i)
#define all(v) v.begin(),v.end()
#define show(v) for(int i = 0; i < v.size(); ++i){cout<<i<<": "<<v[i]<<" "<<endl;}
#define enld endl
#define INF 999999999
#define lint long long int

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, a; cin >> n >> a;
	vector<int> x(n); loop(i, n)cin >> x[i];
	vector<vector<vector<lint>>> dp(51, vector<vector<lint>>(51, vector<lint>(2501, 0)));//dp[j][k][s]=j枚目からk枚選んで合計をsにするような選び方の総数
	dp[0][0][0] = 1;
	loop(i, n)
	{
		loop(j, n)
		{
			loop(k, n * a)
			{
				if (k + x[i] <= n * a)
				{
					dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
				}
				dp[i + 1][j][k] += dp[i][j][k];
			}
		}
	}
	//loop(i, n)loop(j, n)loop(k, n * a)if ( != 0)cout << "dp" << "[" << i << "]" << "[" << j << "]" << "[" << k << "]" << "=" << dp[i][j][k];
	long long ans = 0;
	loops(i, 1, n + 1)ans += dp[n][i][i*a];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 52224
#include <iostream>
#include <map>
using namespace std;
typedef long long LL;
const int N = 200000+10;
int n;
LL a[N];
map<LL, int> mp;

int main() {
    scanf("%d",&n);

    LL s = 0;
    for(int i=1;i<=n;i++) {
        scanf("%lld",&a[i]);
        s += a[i]; mp[s] ++;
    }
    LL ret=0;
    s=0; mp[0]++;
    for(int i=1;i<=n;i++) {
        mp[s]--;
        ret+=mp[s];
        s+=a[i];
    }
    cout<<ret<<endl;

}

Measured memory_bytes: 14336
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

int main () {
	
	int n, m, c;
	cin >> n >> m >> c;
	vector<int> b;
	for (int i = 0; i < m; i++) {
		int temp;
		cin >> temp;
		b.push_back(temp);
	}
	int res = 0;
	for (int i = 0; i < n; i++) {
		int s = 0;
		for (int j = 0; j < m; j++) {
			int temp;
			cin >> temp;
			s += temp * b[j];
		}
		if (s + c > 0)
			res++;
	}
	cout << res;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	String S = sc.next();
	String T = sc.next();
	String newS = S;
	int lastSmoji =  S.length();
	boolean b = true;
	//System.out.println(newS.substring(lastSmoji-1,lastSmoji));
	//System.out.println(newS.substring(0, lastSmoji-1));

	for(int i = 0;i < S.length();i++){
	newS = newS.substring(lastSmoji-1,lastSmoji)+newS.substring(0, lastSmoji-1);
	if(T.equals(newS)){
		System.out.println("Yes");
		b = false;
		break;
	}
	}

	if(b){
		System.out.println("No");		
	}

	}
}
	



Measured memory_bytes: 21844
// 最大公約数 ( ユークリッドの互除法 )
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cassert>

#include<vector>
#include<queue>
#include<set>

using namespace std;

int EuclidMethodOfDivision(int x, int y);

int main(void)
{
	int x, y;

	cin >> x >> y;

	printf("%d\n", EuclidMethodOfDivision(x, y));

	return 0;
 }

// 最大公約数を求める関数 ( ユークリッドの互除法 )
int EuclidMethodOfDivision(int x, int y)
{
	if( x < y )
	{
		// x > y の関係になるようにする
		swap(x, y);
	}

	// 割り算の余り
	int r;

	// ユークリッドの互除法で最大公約数を探索する
	while( y > 0 )
	{
		r = x % y;
		x = y;
		y = r;
	}

	return x;
}



Measured memory_bytes: 3240
#include<iostream>
#include<vector>
#include<queue>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
  int a,b;
  cin >>a >> b;
  
  int p=0,q;

  cout << (a+b)%24;
    return 0;
}






Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define pragi(a,b) for(ll i = a;i<b;i++)
#define pragj(a,b) for(ll j = a;j<b;j++)
#define pragk(a,b) for(ll k = a;k>=b;k--)
#define all(v) (v.begin(),v.end())
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define KAKA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int mod = 998244353;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef long double ld;
typedef pair<int, int> pii;
//typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;
vector<ll> segtree(1e6);

void build(ll node,ll tl,ll tr,vector<ll> & ar)
{
    if(tl == tr)
    {
        segtree[node] = ar[tl];
    }
    else
    {
        ll mid = (tl + tr)/2;
        build(2 * node,tl,mid,ar);
        build(2*node + 1,mid + 1,tr,ar);
        segtree[node] = (segtree[2 * node] + segtree[(2 * node) + 1])%mod;
    }
    
}
ll query(ll node,ll tl,ll tr,ll ql,ll qr)
{
    if(ql > qr)
    {
        return 0;
    }
    else if((ql == tl) and (qr == tr))
    {
        return segtree[node];
    }
    else
    {
        ll mid = (tl + tr)/2;
        ll l = query(2 * node,tl,mid,ql,min(qr,mid));
        ll r = query(2*node + 1,mid + 1,tr,max(ql,mid + 1),qr);
        return (l + r)%mod;
    }
    
}
void update(ll node,ll tl,ll tr,ll pos,ll val)
{
    if(tl == tr)
    {
        segtree[node] = val;
    }
    else
    {
        ll mid = (tl + tr)/2;
        if(pos <= mid) update(2 * node,tl,mid,pos,val);
        else update(2 * node + 1,mid + 1,tr,pos,val);
        segtree[node] = (segtree[2*node] + segtree[2*node + 1])%mod;
    }
    
}
void Compute(ll n,ll k)
{
    KAKA
    vector<pll> vec(k);
    pragi(0,k)
    {
        cin>>vec[i].F>>vec[i].S;
    }
    /*pragi(0,k)
    {
        cout<<vec[i].F<<" "<<vec[i].S<<"\n";
    }*/
    vector<ll> dp(n + 1,0);
    dp[n] = 1;
    build(1,1,n,dp);
    /*pragi(1,n + 1)
    {
        cout<<dp[i]<<" ";
    }
    cout<<"\n";*/
    for(ll i = n-1;i >= 0;i--)
    {
        dp[i] = 0;
        for(auto p : vec)
        {
            ll ql = i + p.F,qr = i + p.S;
           // if(qr <= n)
            dp[i] = ((dp[i] % mod) + (query(1,1,n,ql,min(qr,n))))%mod;
        }
        update(1,1,n,i,dp[i]);
    }

    cout<<dp[1]%mod<<"\n";
}
int main()
{
    KAKA
    ll n,k;
    cin>>n>>k;
    Compute(n,k);
}

Measured memory_bytes: 12652
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(){
  int n,q,t;
  string name;
  queue<pair<string, int> > Q;
  cin >> n >> q;
  rep(i,n) {
    cin >> name >> t;
    Q.push(make_pair(name,t));
  }
  pair<string, int> u;
  int elaps = 0,a;
  while(!Q.empty()){ //Qが空になるまでまわす
    u = Q.front();
    Q.pop();
    a = min(u.second, q);
    u.second -= a;
    elaps += a;
    if(u.second > 0) Q.push(u);
    else cout << u.first << " " << elaps << endl;
  }
  return 0;
}



Measured memory_bytes: 6388
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <numeric>
#include <climits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <utility>
#include <cctype>
#include <iterator>
////////////////////////////////////////////////
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define REPe(e, mp) for (auto& e : mp)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
using ll = long long int;
using vecint = vector<int>;
using vecll = vector<ll>;
using vec2int = vector<vector<int>>;
using P = pair<int, int>;
////////////////////////////////////////////////
////////////////////////////////////////////////
int main() {
  ////////////////////////////////////////////////
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ////////////////////////////////////////////////
  vecint x(5, 0);
  REPe(e, x) cin >> e;
  REP(i, 5) {
    if (x[i] == 0) {
      cout << i + 1 << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3652
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin


def solve(L, num_rows, level, up):
    if level >= num_rows:
        return
    next_ = L[level]
    prev = L[level-1]
    if up:
        for i in range(len(next_)):
            next_[i] += max(prev[max(0, i-1):i+1])
    else:
        for i in range(len(next_)):
            next_[i] += max(prev[i:i+2])
    solve(L, num_rows, level+1, num_rows // 2 > level)

L = []
for line in stdin:
    L.append([int(s) for s in line.split(',')])

solve(L, len(L), 1, True)
print(L[-1][0])

Measured memory_bytes: 4396
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int Maxn=110;
int n,k;
char s[Maxn];
inline int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0' &&ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
int main()
{
	k=read();
	scanf("%s",s+1);
	n=strlen(s+1);
	if(n<=k)printf("%s\n",s+1);
	else
	{
		for(int i=1;i<=k;++i)
		printf("%c",s[i]);
		puts("...");
	}
	return 0;
}

Measured memory_bytes: 3664
import java.awt.event.TextEvent;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
            int r = sc.nextInt();
            int c = sc.nextInt();

            int excel[][] = new int[r+1][c+1];
            int num = 0;
            int num2 = 0;
            int num3 = 0;
            for(int i=0 ; i < r ; i++){
                for(int j=0 ; j < c ; j++){
                    excel[i][j] = sc.nextInt();
                    if(j == c-1){
                        num += excel[i][j];
                        excel[i][j+1] = num;
                        num = 0;
                    }else{
                        num += excel[i][j];
                    }
                }
            }

            for(int k=0 ; k < c ; k++) {
                for (int l = 0; l < r; l++) {
                    if(l == r-1){
                        num2 += excel[l][k];
                        excel[l+1][k] = num2;
                        num2 = 0;
                    }else{
                        num2 += excel[l][k];
                    }
                }
            }
            for(int i=0; i<r ;i++){
                num3 += excel[i][c];
            }
            excel[r][c] = num3;

            for( int i=0; i<r+1; i++ ) {
                for( int j=0; j<c+1; j++ ) {
                    if(j==c){
                        System.out.print(excel[i][j]);
                    }else {
                        System.out.print(excel[i][j] + " ");
                    }
                }
                System.out.println( "" );
            }
    }
}



Measured memory_bytes: 41316
from itertools import product
N=input()
ans=0
for i in range(3,len(N)+1):
    A=list(product(['7','5','3'],repeat=i))
    for a in A:
        if int(''.join(a))<=int(N) and set(a)>={'7','5','3'}:
            ans+=1
print(ans)


Measured memory_bytes: 6756
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
#define int lint
const int INF =1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define pb push_back
signed main(){
    int n, k;
    cin >> n >> k;
    vi h(n);
    rep(i,n){
        cin >> h[i];
    }
    sort(all(h));
    int res = 1 << 30;
    rep(i, n - k + 1)
    {
        int dis = h[i + k - 1] - h[i];
        res = min(res,dis);
    }
    cout << res << endl;
    return 0;
}

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

string s_al = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

//何個目なのかを算出する関数
char Numalpha(char s){
  
  int i;
  
  for (i = 0; i < 26; i++){
    if (s == s_al.at(i)){
      //cout << i << endl;
      return i;
    }
  }
  return -1 ;
}

//文字をN個進ませる関数
char Proc(int _n, char _s){
  
  int Pos;
  Pos = Numalpha(_s);
  _s = s_al.at((Pos + _n) % 26);
  //cout << _s << endl;
  
  return _s;
}


int main(){
  
  int N, i;
  cin >> N;
  string S;
  cin >> S;
  vector<char> _S(S.size());
  
  for (i = 0; i < S.size(); i++){
    
    cout << Proc(N, S.at(i));
    //_S.at(i) = Proc(N, S.at(i));
  }
  cout << endl;
  return 0;
}

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

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

    map<int, vector<pii>> pref_cyear;
    rep(city, 0, m)
    {
        int p, y;
        cin >> p >> y;
        pref_cyear[p].push_back(make_pair(y, city));
    }
    for (auto &p_cy: pref_cyear)
        sort(p_cy.second.begin(), p_cy.second.end());

    vector<pii> city_name(m);
    for (auto py: pref_cyear)
    {
        int pref = py.first;
        vector<pii> year_cities = py.second;
        rep(i, 0, year_cities.size())
        {
            int city = year_cities[i].second;
            city_name[city] = make_pair(pref, i + 1);
        }
    }
    rep(i, 0, m)
        printf("%06d%06d\n", city_name[i].first, city_name[i].second);
    return 0;
}

Measured memory_bytes: 13184
n=int(input(""))
lis=input("")
rt=0
for i in lis:
    if(i=="R"):
        rt+=1
ht=n-rt
r=0
h=0

s=max(h,rt)

for i in lis:
    if(i=="R"):
        r+=1
    else:
        h+=1
    on=rt-r
    m=max(on,h)
    if(s>m):
        s=m

print(s)
    
        
        


Measured memory_bytes: 9380
using System;
using System.IO;
 
class Program
{
    static void Solve()
    {
        var n = sc.Int();
        var a = new int[2][];
        a[0] = sc.Int(n);
        a[1] = sc.Int(n);

        var maxCnt = -1;

        for (int i = 0; i < n; i++)
        {
            var tmpCnt = 0;
            for (int j = 0; j <= i; j++)
                tmpCnt += a[0][j];
            
            for (int j = i; j < n; j++)
                tmpCnt += a[1][j];
            
            maxCnt = Math.Max(maxCnt, tmpCnt);
        }

        pr.WriteLine(maxCnt);
    }
 
 
    static void Main(string[] args)
    {
        // pr.AutoFlush = true;
        Solve();
        pr.Flush();
    }
 
    static Scanner sc = new Scanner();
    static Printer pr = new Printer();
}
 
#region IO
class Scanner
{
    private int _i = 0; 
    private string[] line = new string[0];
 
    private T[] Enumerate<T>(int n, Func<T> f)
    {
        T[] ret = new T[n];
        for (int i = 0; i < n; i++)
            ret[i] = f();
        return ret;
    }
 
    public string Str()
    {
        if (line.Length <= _i)
        {
            line = Console.ReadLine().Split(' ');
            _i = 0;
        }
 
        return line[_i++];
    }
 
    public int Int() => int.Parse(Str());
    public long Long() => long.Parse(Str());
    public double Double() => double.Parse(Str());
    public int[] Int(int n) => Enumerate(n, Int);
    public long[] Long(int n) => Enumerate(n, Long);
    public double[] Double(int n) => Enumerate(n, Double);
    public string[] Str(int n) => Enumerate(n, Str);
}
 
class Printer : StreamWriter
{
    public Printer() : base(Console.OpenStandardOutput())
    {
        AutoFlush = false;
    }
}
#endregion

Measured memory_bytes: 13268
x, y = map(int, input().split())
A = [1, 3, 5, 7, 8, 10, 12]
B = [4, 6, 9, 11]
count = 0
ax = x in A
ay = y in A
bx = x in B
by = y in B
if ax == True and ay == True:
    print("Yes")
elif bx == True and by == True:
    print("Yes")
else:
    print("No")


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

int main() {
  int a,b,c,sum;
  vector<int> vec(5);
  vector<int> vee(5);
  for(int i=0;i<5;i++){
  	cin>>vec.at(i);
  }
 
  for(int i=0;i<5;i++){
   vee.at(i) = ((vec.at(i)+9)/10)*10;
  }
  
  c=10000;
  for(int i=0;i<5;i++){
  	sum=0;
    for(int j=0;j<5;j++){
    	if(j!=i){
           sum += vee.at(j);
        }
    }
    	sum +=vec.at(i);
      c = min({c,sum});
  }
  
  cout<<c<<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include "stdio.h"

int main()
{
  int k, a, b;
  scanf ("%d",&k);
  scanf ("%d",&a);
  scanf ("%d",&b);
  int i,j;
  int c=0;
  for (i=1; i<=1000; i++)
    {
      for (j=a; j<=b; j++)
        {
          if ((k*i)==j)
            {
              c++;
              break;
            }
        }
      if (c == 0)
        continue;
      else
        break;
    }
  if (c==0)
    printf ("NG\n");
  else
    printf ("OK\n");
  return 0;
}

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


int main() {
	string O, E;
	cin >> O >> E;
	int o = (int)O.length();
	int e = (int)E.length();
	for (int i = 0;i<e;i++) {
		cout << O[i] << E[i];
	}
	if (o>e) { cout<<O[o - 1]; }
}

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

using ll = long long ;

int main() {
    ll a , b , c , d ;
    cin >> a >> b >> c >> d ;
    
    ll A = a*c ;
    ll B = a*d ;
    ll C = b*c ;
    ll D = b*d ;
    
    ll ans1 = 0 ;
    ll ans2 = 0 ;
    ll ans = 0 ;
    
    ans1 = max( A , B ) ;
    ans2 = max( C , D ) ;
    
    ans = max( ans1 , ans2 ) ;
    
    cout << ans << endl;
    
}


Measured memory_bytes: 3648
#pragma region include
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <cstdio>
#include <tuple>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (n); i < (m); i++)
#define MOD 1000000007
#define INF 1000000000
#define LLINF 4000000000000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#pragma endregion

int main() {
    int N, K; cin >> N >> K;
    // dp[i] := 残りi個のとき直後の手番の人が勝てるか
    vector<bool> dp(K + 1, false);
    VI a(N);
    REP(i, N) {
        cin >> a[i];
    }
    FOR(i, 1, K + 1) {
        REP(j, N) {
            if (i - a[j] >= 0 && !dp[i - a[j]]) {
                dp[i] = true;
                break;
            }
        }
    }
    if (dp[K]) {
        cout << "First" << endl;
    }
    else {
        cout << "Second" << endl;
    }
    getchar(); getchar();
}

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

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

int main()
{
    vector<int> a(3);
    rep(i, 3) cin >> a[i];

    OP(min(abs(a[0] - a[1]) + abs(a[1] - a[2]), min(abs(a[1] - a[0]) + abs(a[0] - a[2]), abs(a[0] - a[2]) + abs(a[2] - a[1]))));
    return 0;
}

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

using namespace std;

using ll = long long;

int main(){

    ll n, k; cin >> n >> k;
    ll arr[n];
    ll dp[max(n + 25, k + 2)] = {0};
    for(ll i = 0; i < n; ++i){
        cin >> arr[i];
    }
    for(ll i = k + 1; i < n; ++i){
        dp[i] = 2e9;
    }
    for(ll i = 1; i <= k; ++i){
        dp[i] = abs(arr[i] - arr[0]);
    }
    for(ll i = k; i < n; ++i){
        for(ll j = i - k; j < i; ++j){
            dp[i] = min(dp[j] + abs(arr[j] - arr[i]), dp[i]);
        }
    }
    cout << dp[n - 1];
    return 0;
}


Measured memory_bytes: 5124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;
// lint mod = 1000000007;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

lint app() {
  int n;
  cin>>n;

  vector<lint> a(n);
  rep(i,n){
    double d;
    cin>>d;
    d*=1e9;
    d+=0.5;
    a[i]=(lint)d;
  }

  vector<vector<lint>> ps(44,vector<lint>(19,0));
  rep(i,n){
    lint x=a[i];
    int i2=0;
    while(x%2==0 && i2+1<44){
      i2++; x/=2;
    }

    x=a[i];
    int i5=0;
    while(x%5==0 && i5+1<19){
      i5++; x/=5;
    }

    ps[i2][i5]++;
  }

  lint ans=0;
  rep(i2,44) rep(i5,19){
    rep_range(j2,max(0,18-i2),44) rep_range(j5,max(0,18-i5),19){
      if(i2==j2&&i5==j5) ans+=ps[i2][i5]*(ps[j2][j5]-1);
      else ans+=ps[i2][i5]*ps[j2][j5];
    }
  }

  return ans/2;
}

int main(){cout<<app()<<endl;return 0;}


Measured memory_bytes: 4788
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int a,b,c,k;
    cin >> a >> b >> c >> k;

    int ans = 0;
    if(k <= a){
        cout << k << endl;
        return 0;
    }else if(k <= a + b){
        cout << a << endl;
        return 0;
    }else {
        cout << a - (k-a-b) << endl;
        return 0;
    }

    return 0;
}

Measured memory_bytes: 3636
import math
import copy
import sys


inputa = input().split()
# inputb = input().split()
# inputc = input().split()

a = int(inputa[0])
# b = int(inputa[1])
# c = int(inputa[2])

# x = int(inputb[0])
# y = int(inputb[1])

# inputaList = [int(n) for n in inputa]

inputb = input().split()
inputbList = [float(n) for n in inputb]
#
# inputList = []
# inputNumList = []
# for i in range(a):
#     inputNum = input()
#     inputNumList = list(inputNum)
#     inputList.append(inputNumList)

# inputList = [int(n) for n in inputList]

# b = [int(n) for n in inputb]
# c = [int(n) for n in inputc]

inputbList.sort()

tmpsum = 0

for i in range(1, a):
    if i == 1:
        tmpsum = (inputbList[0] + inputbList[1])/2
    else:
        tmpsum = (tmpsum + inputbList[i])/2

print(tmpsum)



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

using namespace std;

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

	vector<int> a(q);
	vector<int> b(q);
	vector<int> c(q);
	vector<int> d(q);

	for(int i = 0; i < q; ++i) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}

	vector<int> A(n);

	int ans = 0;

	function<void(int, int)> dfs = [&] (int p, int low) {
		if(p == n) {
			int tot = 0;
			for(int i = 0; i < q; ++i) {
				tot += (A[b[i] - 1] - A[a[i] - 1] == c[i]) * d[i];
			}
			ans = max(ans, tot);
			return;
		}

		for(int i = low; i <= m; ++i) {
			A[p] = i;
			dfs(p + 1, i);
			A[p] = 0;
		}
	};

	dfs(0, 1);

	cout << ans << '\n';

	return 0;
}


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

int main() {
    int N; cin >> N;
    vector<int> A(N + 2);
    A[0] = 0;
    for (int i = 1; i <= N; i ++){
        cin >> A[i];
    }
    A[N + 1] = 0;
    int s = 0;
    vector<int> step1(N+1);
    vector<int> step2(N);
    for (int i = 0; i < N; i++){
        s += abs(A[i+1] - A[i]);
        step1[i] = abs(A[i+1] - A[i]);
        step2[i] = abs(A[i+2] - A[i]);
    }
    s += abs(A[N+1] - A[N]);
    step1[N] = abs(A[N+1] - A[N]);

    for (int i = 0; i < N; i++){
        cout << s - step1[i] - step1[i+1] + step2[i] << endl;
    }

}



Measured memory_bytes: 2432
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    public static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        string S = Console.ReadLine();
        var R = 0L; var G = 0L; var B = 0L;
        for (int i = 0; i < N; i++)
        {
            if (S[i] == 'R') R++;
            if (S[i] == 'G') G++;
            if (S[i] == 'B') B++;
        }
        var ans = R * G * B;
        for (int i = 0; i < N; i++)
        {
            for(int j = 1; i+2*j<N; j++)
            {
                if (S[i] != S[i + j] && S[i + j] != S[i + 2 * j] && S[i] != S[i+2*j]) {
                    ans--;
                }
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 27496
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void){
   int n,maxi=0,ans=0;
   cin>>n;
   for(int i=0;i<n;i++){
       int a,b;
       cin>>a>>b;
       if(maxi<a){
           ans=b+a;
           maxi=a;
       }
   }
   cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(in.next());
            }
            long ans = Long.MAX_VALUE;
            Arrays.sort(a);

            for (int i = a[0]; i < a[n - 1] + 1; i++) {
                long tmp = 0;
                for (int j = 0; j < n; j++) {
                    tmp += (a[j] - i) * (a[j] - i);
                }
                ans = Math.min(ans, tmp);
            }
            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 35884