akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(void){
    int n = 0;
    cin >> n;
    int A[100];
    for(int i = 0; i < 100; i++){
        A[i] = 0;
    }
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }
    int count = 0;
    for(int i = 0; i < n; i++){
        int minj = i;
        for(int j = i; j < n; j++){
            if(A[j] < A[minj]){
                minj = j;
            }
        }
        if(minj != i){
            int temp = A[i];
            A[i] = A[minj];
            A[minj] = temp;
            count++;
        }
    }
    for(int i = 0; i < n-1; i++){
        cout << A[i] << " ";
    }
    cout << A[n-1] << endl;
    cout << count << endl;
    return 0;
}



Measured memory_bytes: 3104
n = int(input())
a = list(map(int, input().split()))
result = 1
if n > 2:
    h = -1
    for i in range(n-1):
        if a[i]!=a[i+1]:
            c = a[i]<a[i+1]
            if h<0:
                h = c
            else:
                if h==c:
                    continue
                else:
                    h = -1
                    result += 1
print(result)

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e15;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;

vector<ll> listMod(vector<ll> &list, ll m2) {
    vector<ll> res(list.size());
    rep(i, list.size()) {
        res[i] = list[i] % m2;
    }
    sort(res.begin(), res.end());
    return res;
}

int main() {
    ll n;
    cin >> n;
    vector<ll> as(n);
    vector<ll> bs(n);
    rep(i, n) {
        cin >> as[i];
    }
    rep(i, n) {
        cin >> bs[i];
    }

    ll ans = 0;

    for (int i = 0; i < 30; i++) {
        ll mod2 = 1LL << (i + 1);
        vector<ll> mod_as = listMod(as, mod2);
        vector<ll> mod_bs = listMod(bs, mod2);
        ll t = 1LL << i;

        ll now = 0;
        for (ll a  : mod_as) {
            ll t1 = t - a;
            ll t2 = 2 * t - a;
            ll t3 = 3 * t - a;
            ll t4 = 4 * t - a;

            auto l1 = lower_bound(mod_bs.begin(), mod_bs.end(), t1);
            auto r1 = lower_bound(mod_bs.begin(), mod_bs.end(), t2);
            auto l2 = lower_bound(mod_bs.begin(), mod_bs.end(), t3);
            auto r2 = lower_bound(mod_bs.begin(), mod_bs.end(), t4);
            now += (r1 - l1) + (r2 - l2);

        }

        ll bit = now % 2;
        ll i_ans = bit << i;
        ans += i_ans;
    }

    cout << ans << endl;

}

Measured memory_bytes: 6552
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll lcm(ll n,ll m)
{
	return ((n*m)/(__gcd(n,m)));
}

int main()
{
	const double pi = 3.1415926535;
	cin.tie(0);
	cout.tie(0);
	double a,b,n,m;
	cin>>a>>b>>n>>m;
	double a1=6*m,a2=(60*n+m)/2;
	a1=abs(a2-a1);
	a1=(a1*pi)/180;
	double ans=sqrt(a*a+b*b-2*a*b*cos(a1));
	cout<<setprecision(10)<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4228
#include <stdio.h>
 
int n,k,x,y ;
 
int main(void){
    
    scanf ("%d%d%d%d",&n,&k,&x,&y) ;
    
    if ( n>=k ){
        printf ("%d\n",k*x+(n-k)*y) ;
        
    } else {
        printf ("%d\n",n*x) ;
        
    }
    
    return 0 ;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;

    double r = 0;
    double weight = a * 100;
    double sugar = 0;
    for(int w = 1; w <= f/100; w++){
        bool valid = false;
        for(int B = 0; B * b <= w; B++){
            if((w - B * b) % a == 0)valid = true;
        }
        if(!valid)continue;

        for(int s = 0; s <= e * w; s++){
            if(w * 100 + s > f)break;
            if(s*(100+e) > e*(100*w+s))break;
            bool val = false;
            for(int D = 0; D * d <= s; D++){
                if((s - D * d) % c == 0)val = true;
            }
            if(!val)continue;

            if(r <= 100.0*s/(100*w+s)){
                r = 100.0*s/(100*w+s);
                weight = 100*w + s;
                sugar = s;
            }
        }
    }
    cout << weight << ' ' << sugar << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	string a;
	cin>>a;
	int size=a.size();
	for(int i=0;i<size;i++){
		if(a[i]=='C'){
			for(int j=i;j<size;j++){
				if(a[j]=='F'){
					cout<<"Yes";
					return 0;
				}
			}
		}
	}
	cout<<"No";
	return 0;
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll dp[1001000][2] = {0LL};

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

  string s;
  cin >> s;

  reverse(s.begin(), s.end());
  s += '0';

  int n = s.length();

  dp[0][0] = 0;
  dp[0][1] = INF;

  for(int i = 0; i < s.length(); i++){
    dp[i+1][0] = INF;
    dp[i+1][1] = INF;
  }

  rep(i, s.length()){

    int num = s[i] - '0';
    
    // 0-> 0に
    chmin(dp[i+1][0], dp[i][0] + num);
    // 0->1に
    chmin(dp[i+1][1], dp[i][0] + 10 - num);
    // 1->1に 
    chmin(dp[i+1][1], dp[i][1] + 10 - num - 1);
    // 1->0に
    chmin(dp[i+1][0], dp[i][1] + num + 1);

  }


  cout << dp[s.length()][0] << endl;


  

  return 0;
}


Measured memory_bytes: 17052
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    int n;
    cin >> n;
    ll ans = 0;
    for(ll i = 1; i * i < n; ++i) {
        for(ll j = i; i * j < n; ++j) {
            if(i == j) ans += 1;
            else ans += 2;
        }

    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3632
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#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++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  ll x,y; cin>>x>>y;
  ll count=1;
  while(x<=y){
    x*=2;
    count++;
  }
  cout <<count-1<<endl;
}

Measured memory_bytes: 256
import sys
def input():
	return sys.stdin.buffer.readline()[:-1]

class BIT():#1-indexed
	def __init__(self, size):
		self.table = [0 for _ in range(size+2)]
		self.size = size

	def Sum(self, i):#1からiまでの和
		s = 0
		while i > 0:
			s += self.table[i]
			i -= (i & -i)
		return s

	def Add(self, i, x):#
		while i <= self.size:
			self.table[i] += x
			i += (i & -i)
		return

n, q = map(int, input().split())
fw = BIT(n+2)
a = list(map(int, input().split()))
for i, x in enumerate(a):
	fw.Add(i+1, x)
for _ in range(q):
	x, y, z = map(int, input().split())
	if x == 0:
		fw.Add(y+1, z)
	else:
		print(fw.Sum(z) - fw.Sum(y))

Measured memory_bytes: 62344
#include <bits/stdc++.h>
 
using namespace std;
 
vector<int> graf[100010];
int veze[100010];
int qu[100010];
bool mark[100010];
int dp[100010];
int q = 0;
 
void topolosko(int x)
{
    //mark[x] = true;
    for(int i = 0; i < q; i++)
    {
       
        for(int p = 0; p < graf[qu[i]].size(); p++)
        {
            int t = graf[qu[i]][p];
            veze[t]--;
            if(veze[t] == 0) qu[q++] = t;
        }
    }
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   
    int n, m;
    cin >> n >> m;
    for(int i = 0; i< m; i++)
    {
        int a, b;
        cin >> a >> b;
        graf[a].push_back(b);
        veze[b]++;
    }
    for(int i = 1; i <= n; i++)
    {
        if(veze[i] == 0) qu[q++] = i;
    }
    topolosko(qu[0]);
    //for(int i=0; i < q; i++) cout << qu[i] << " ";
    dp[qu[0]] = 0;
    int res = 0;
    for(int i = 0; i < q; i++)
    {
        //cout << qu[i] << " ";
        for(int j = 0; j < graf[qu[i]].size();j++) 
        {
            //cout << graf[qu[i]][j] << " ";
            dp[graf[qu[i]][j]] = max(dp[qu[i]]+1, dp[graf[qu[i]][j]]);
            res = max(res, dp[graf[qu[i]][j]]);
        }
        //cout << "\n";
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 6912
package main

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

var sc = bufio.NewScanner(os.Stdin)

func ni() (val int) {
	sc.Scan()
	val, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return val
}

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

	sum := t
	prev := ni()
	for i := 1; i < n; i++ {
		tt := ni()
		sub := t - (tt - prev)
		if sub > 0 {
			sum -= sub
		}
		sum += t
		prev = tt
	}
	fmt.Println(sum)
}


Measured memory_bytes: 3840
h, w, d = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
q = int(input())
lr = [list(map(int, input().split())) for _ in range(q)]

x = [[-1] for _ in range(h*w+d+1)]
m = []
for i in range(h):
    for j in range(w):
        x[a[i][j]] = [i, j]
        m.append([a[i][j], i, j])
m.sort()
visit = [[-1 for _i in range(w)] for _j in range(h)]

for pos, xx, yy in m:
    if visit[xx][yy] < 0:
        visit[xx][yy] = 0
        while x[pos+d][0] >= 0:
            g, h = x[pos+d]
            visit[g][h] = visit[xx][yy] + abs(g-xx)+abs(h-yy)
            xx = g
            yy = h
            pos = a[xx][yy]
for l, r in lr:
    print(visit[x[r][0]][x[r][1]]-visit[x[l][0]][x[l][1]])

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

#define ll long long
#define pb push_back
std::vector<int> v;
int main()
{
	int N,d,m=0;
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>d;
		v.pb(d);
	}
	for(int i=0;i<N;i++)
	{
		if(v[i]>=1)
		{
			for(int j=i+1;j<N;j++)
			{ 
				m+=v[i]*v[j];
			}

		}
	}
	cout<<m;

}

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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

bool isM(int x) {
  return x >= 1 && 12 >= x;
}

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

  int a = stoi(s.substr(0, 2));
  int b = stoi(s.substr(2));

  if (isM(a) && isM(b)) {
    cout << "AMBIGUOUS" << endl;
  } else if (isM(a)) {
    cout << "MMYY" << endl;
  } else if (isM(b)) {
    cout << "YYMM" << endl;
  } else {
    cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import math

k = int(input())

ab = []
ans = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        if a % b == 0:
            ab.append(b)
        elif b % a == 0:
            ab.append(a)
        else:
            ab.append(math.gcd(a, b))
for i in ab:
    for c in range(1,k+1):
        if i % c == 0:
            ans += c
        elif c % i == 0:
            ans += i
        else:
            ans += math.gcd(i, c)

print(ans)

Measured memory_bytes: 75448
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <sstream>
#include <cmath>

using namespace std;


int main(int argc, const char * argv[]) {
    int N; cin >> N;
    
    int maxlen = -1;
    int total = 0;
    for (int i = 0; i < N; i++) {
        int l; cin >> l;
        total += l;
        maxlen = max(l, maxlen);
    }
    cout << (maxlen < (total - maxlen) ? "Yes" : "No") << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<iomanip>
#include<string>
using namespace std;
int main(){
string src[8];
for (int i=0;i<8;i++){
	cin>>src[i];
}

cout<<90<<endl;
for (int i=0;i<8;i++){
	for (int j=0;j<8;j++){
		cout<<src[7-j][i];
	}
	cout<<endl;
}
cout<<180<<endl;
for (int i=0;i<8;i++){
	for (int j=0;j<8;j++){
		cout<<src[7-i][7-j];
	}
	cout<<endl;
}
cout<<270<<endl;
for (int i=0;i<8;i++){
	for (int j=0;j<8;j++){
		cout<<src[j][7-i];
	}
	cout<<endl;
}


}

Measured memory_bytes: 1184
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

ll x[100010];
int main()
{
	int N, K;
	cin >> N >> K;
	for (int i = 0; i < N; i++)cin >> x[i];
	ll ans = INF;
	for (int i = 0; i < N - K + 1; i++) {
		ans = min(ans, abs(x[i]) + x[i + K - 1] - x[i]);
		ans = min(ans, abs(x[i + K - 1]) + x[i + K - 1] - x[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		char[] abcd = sc.next().toCharArray();

		int a = abcd[0] - '0';
		int b = abcd[1] - '0';
		int c = abcd[2] - '0';
		int d = abcd[3] - '0';

		char[] op = new char[3];
		for (int i = 0; i < 0x1 << 3; i++) {
			int tmp = a;
			if ((i & 0x1 << 2) == 0) {
				tmp += b;
				op[0] = '+';
			} else {
				tmp -= b;
				op[0] = '-';
			}
			if ((i & 0x1 << 1) == 0) {
				tmp += c;
				op[1] = '+';
			} else {
				tmp -= c;
				op[1] = '-';
			}
			if ((i & 0x1) == 0) {
				tmp += d;
				op[2] = '+';
			} else {
				tmp -= d;
				op[2] = '-';
			}

			if (tmp == 7) {
				pr.printf("%c%c%c%c%c%c%c=7\n", abcd[0], op[0], abcd[1], op[1], abcd[2], op[2], abcd[3]);
				return;
			}
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 23764
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const ll INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////

//カッコ列の整合性に関する問題は超定番の判定方法がある
//stackを用意する
//左カッコが来たらstackに追加
//右カッコがきたときstackが空だったらエラー検出で空じゃなかったらstackにある左カッコと
//今ある右カッコとをペアにしてstackからpopする

int main() {
	int n; cin >> n;
	string s; cin >> s;
	stack<int>st;
	string ans = s;
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == '(') {
			st.push(1);
		}
		else {
			if (!st.empty()) {
				st.pop();
			}
			else {
				ans = '(' + ans;
			}
		}
	}
	for (int i = 0; i < st.size(); ++i) {
		ans = ans + ')';
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

int N, K;

void solve()
{
    double ans = 0.;
    REP(i, N){
        int n = 0;
        int s = i+1;
        while(s < K){
            n++;
            s *= 2;
        }
        ans += pow(0.5, n) / N;
    }
    cout << fixed << setprecision(10) << ans << endl;
}

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

// vim:set foldmethod=marker:


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;
const int MOD = 1e9 + 7;

signed main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	cout << max(A * B, C * D);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const vi d8x = {1, 0, -1, 0, 1, -1, -1, 1};
const vi d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vi d4x = {1, 0, -1, 0};
const vi d4y = {0, 1, 0, -1};

//----------------ここからだよ-------------------

int main(){
    string S,T; cin>>S>>T;
    string ans;
    ans +=T;
    ans +=S;
    cout<<ans<<endl;   
}

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

int main() {
  int N;
  cin >> N;
  string s, t;
  cin >> s >> t;
  string u = "";
  for (int i = 0; i < N; i++) {
    u += s[i];
    u += t[i];
  }
  cout << u << endl;
}

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

#define REP(i, s,  n) for(int i = s;i < (n);i++)
#define VSORT(v) sort(v.begin(), v.end());
#define int64 long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> PP;

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

//---------------------------------------------------------------
//---------------------------------------------------------------

int N;

signed main(){
	cin >> N;
	int ans = 0;
	int a;
	REP(i, 0 , N) {
		cin >> a;
		REP(j, 0, 32) {
			if (a & (1<<j))	break;
			ans++;
		}
	}
	cout << ans << endl;
	
	return 0;
}


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

int main()
{
  vector<int> T(5);
  for (int i = 0; i < 5; ++i) {
    cin >> T[i];
  }
  
  vector<int> r(5);
  for (int i = 0; i < 5; ++i) {
    r[i] = T[i] % 10;
  }
  
  for (int i = 0; i < 5; ++i) {
    if (r[i] == 0)
      r[i] = 10;
  }
  
  auto minIter = min_element(r.begin(), r.end());
  int minIndex = (int)distance(r.begin(), minIter);
  
  int sum_time = 0;
  for (int i = 0; i < 5; ++i) {
    if (i == minIndex) {
      sum_time += T[i];
    }
    else if (T[i] % 10 == 0) {
      sum_time += T[i];
    }
    else {
      sum_time += T[i] / 10 * 10 + 10;
    }
  }
    
  cout << sum_time << endl;
}

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

int sumofDigits(int N)
{
    int sum = 0; 
    while (N)
    {
        sum += N%10;
	N /= 10;
    }	
    return sum;
}

int main()
{
    int N;
    cin >> N;
    int m = 99999999 ;
    for (int i=1; i<=N/2; ++i)
    {
	m = min(m, sumofDigits(i) + sumofDigits(N-i));
    }	
    cout << m << endl;
    return 0;
} 

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

long long Abs(long long x){
  if(x < 0){
    return -x;
  }
  else{
    return x;
  }
}

int n;
long long a[200005], s[200005];

int main(void){
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  for(int i = 0; i < n; i++){
    s[i + 1] = a[i] + s[i];
  }
  long long m = Abs(2 * s[1] - s[n]);
  for(int i = 1; i < n; i++){
    m = min(m, Abs(2 * s[i] - s[n]));
  }
  cout << m << endl;
}


Measured memory_bytes: 3328
#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++)
#define repi(i,a,b) for (int i = (a); i < (b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  
  cout << min({a+b, b+c, c+a}) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a, b, c;
	cin>>a>>b>>c;
	int cnt = 0;
	int sum = 0;
	while(sum < c)
	{
		sum+=a;
		cnt++;
		if(cnt % 7 == 0)
			sum += b;
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 3120
N,Q=map(int,input().split())
S=input()
list1=[list(map(int,input().split())) for _ in range(Q)]
list2=[0]*(N+1)
count=0
for i in range(N):
    if i>0:
        list2[i+1]=list2[i]
    if i==N-1:
        continue
    elif S[i:i+2]=="AC":
        list2[i+1]+=1
for tmp in list1:
    print(list2[tmp[1]-1]-list2[tmp[0]-1])

Measured memory_bytes: 30700
<?php
error_reporting(0);
$N = trim(fgets(STDIN));
//$A = explode(" ",trim(fgets(STDIN)));
//list($N,$M) = explode(" ",trim(fgets(STDIN)));
$cnt=0;
while(!empty($N)) {
  $len = strlen($N);
  if ($N[0]==$N[$len-1]) {
    $N = substr($N,1,$len-2);
    continue;
  }
  else {
    if ($N[0]=="x") {
      $N .= "x";
      $cnt++;
      continue;
    }
    if ($N[$len-1]=="x") {
      $N = "x" . $N;
      $cnt++;
      continue;
    }
    printf("-1\n");
    exit;
  }
}
printf("%d\n",$cnt);


Measured memory_bytes: 4212
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
	const char RN[] = { 'Z', 'I', 'V', 'X', 'L', 'C', 'D', 'M' }; //
	const int N[] = { 0, 1, 5, 10, 50, 100, 500, 1000 }; 
//	cut here before submit 
//	freopen("testcase.rf", "r", stdin);
	string str = "";
	map<char, int > Ruman;
	int i;
	int even = 5;
	int odd = 1;

	for (i = 0; i < sizeof(RN)/sizeof(RN[0]); ++i){
		Ruman[RN[i]] = N[i];
	} // end for
//	map<char, int>::iterator it = Ruman.begin();
//	for (; it != Ruman.end(); ++it){
//		cout << (*it).first << ':' << (*it).second << endl;
//	} // end for
		
	while (getline (cin, str ) ){
		if (str.empty() ){
			break;
		} // end if
		int len = str.length();
		str += 'Z';
		int curr = 0;
		int res = 0;

		
		for (i = 0; i < len; ++i){
			if (Ruman[str[i]] < Ruman[str[i+1]] ){
				curr = -Ruman[str[i]];
			}else{
				curr = Ruman[str[i]];
			} // end if
//			cout << "curr: " << curr << endl;
			res += curr;
			
		} // end for
		cout << res << endl;

	} // end while
			
	return 0;
}

Measured memory_bytes: 0
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let a: usize = iterator.next().unwrap().parse().unwrap();
    let b: usize = iterator.next().unwrap().parse().unwrap();

    if a >= 10 || b >= 10 {
        return "-1".to_string();
    }

    return format!("{}", a * b);
}


Measured memory_bytes: 4352
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
bool gem[21][21];
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
int main() {
	int N;
	while(scanf("%d",&N),N) {
		for(int i=0;i<=20;i++) {
			for(int j=0;j<=20;j++) gem[i][j]=0;
		}
		for(int i=0;i<N;i++) {
			int x,y;
			scanf("%d %d",&x,&y);
			gem[x][y]=1;
		}
		int M;
		scanf("%d",&M);
		int x=10,y=10;
		char d[2];
		int l;
		for(int i=0;i<M;i++) {
			scanf("%s %d",d,&l);
			int D=0;
			switch(d[0]) {
			case 'N':D=0;break;
			case 'E':D=1;break;
			case 'S':D=2;break;
			case 'W':D=3;break;
			}
			for(int j=0;j<l;j++) {
				x+=dx[D];
				y+=dy[D];
				if(gem[x][y]) {
					N--;
					gem[x][y]=0;
				}
			}
		}
		printf("%s\n",N>0?"No":"Yes");
	}
}

Measured memory_bytes: 1012
// Your code here!
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
fn main(){
 let char: Vec<char> = read::<String>().chars().collect();
 let count = char.len()-2;
 let beginning  = char[0];
 let end  = char[char.len()-1];
 
  println!("{}{}{}", beginning,count,end);
 }

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

const int MAX_N = 200000;

ll n;
ll a[MAX_N];

int main(){
  cin >> n;
  REP(i, n) cin >> a[i];
  ll mav = 0;
  int mai;
  REP(i, n) {
    if(mav < a[i]) {
      mav = a[i];
      mai = i;
    }
  }
  ll hd = INFll;
  int hi;
  REP(i, n) {
    if(i == mai) continue;
    if(hd > abs(a[i] - mav / 2)) {
      hd = abs(a[i] - mav / 2);
      hi = i;
    }
  }
  cout << mav << " " << a[hi] << endl;

  return 0;
}


Measured memory_bytes: 1024
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
B = [int(x) for x in stdin.readline().rstrip().split()]
diff = [A[i] - B[i] for i in range(N)]
d = [i for i in diff if i < 0]
ans = len(d)
s = sum(d)
for i in sorted(diff)[::-1]:
    if s >= 0:
        break
    s += i
    ans += 1
if sum(diff) < 0:
    ans = -1
print(ans)

Measured memory_bytes: 18356
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int N, K, Q;
    cin >> N >> K >> Q;

    std::vector<int> A(N);
    for (int &s : A) s = 0;

    for (int i = 0; i < Q; ++i)
    {
        int answer;
        cin >> answer;
        ++A[answer - 1];
    }

    for (int &s : A)
    {
        s = s + K - Q;
        cout << (s > 0 ? "Yes" : "No") << endl;
    }

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <omp.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

int main()
{
	int t;
	cin >> t;
	for (int i = 0; i < t; ++i) {
		long long n, m, a, b;
		cin >> n >> m >> a >> b;
		cout << floor_sum(n, m, a, b) << endl;
	}
}

Measured memory_bytes: 3672
import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInts() {
        return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
        return readInts()[0];
}
auto readLongs() {
        return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
        return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;


void main(){
    auto N = readLong();
    auto x = readLongs();
    auto L = readLong();
    auto list = new long[][](N, 50);
    foreach(i; iota(N)) {
        list[i][0] = x.length - x.assumeSorted.upperBound(x[i] + L).length - 1;
    }
    foreach(j; iota(1, 50)) {
        foreach(i; iota(N)) {
            list[i][j] = list[list[i][j-1]][j-1];
        }
    }

    long calc(long a, long m) {
        long j = 0;
        while(m > 0) {
            if((m & 1) > 0) {
                a = list[a][j];
            }
            ++j;
            m >>= 1;
        }
        return a;
    }
    long search(long a, long b) {
        long u = N;
        long l = 0;
        while(u-l > 1) {
            long m = (u+l) / 2;
            auto c = calc(a, m);
            if(c < b) {
                l = m;
            } else {
                u = m;
            }
        }
        return u;
    }

    auto Q = readLong();
    foreach(i; iota(Q)) {
        long a, b;
        readlnTo(a, b);
        if(a > b) {
            swap(a, b);
        }

        writeln(search(a-1, b-1));
    }
}


Measured memory_bytes: 68020
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
int n,m,f;
struct What {
	int id,cnt;
};
What h[300005];
What v[300005];
pair<int,int> coord[300005];

long long hs(int x,int y) {
	return 1LL*x*300000+y;
}

pair<int,int> dehs(long long h) {
	return make_pair(h/300000,h%300000);
}

bool cmp(What a,What b) {
	return a.cnt>b.cnt;
}

bool cmp2(pair<int,int> a,pair<int,int> b) {
	return hs(a.x,a.y)<hs(b.x,b.y);
}

bool sear(int x,int y) {
	long long l=1,r=f;
	while(l<=r) {
		long long mid=(l+r)>>1;
		if(coord[mid]==make_pair(x,y)) {
			return 1;
		}else if(hs(coord[mid].x,coord[mid].y)<hs(x,y)) {
			l=mid+1;
		}else {
			r=mid-1;
		}
	}
	return 0;
}

int main() {
  scanf("%d %d %d",&n,&m,&f);
  for(int i=1;i<=n;i++) {
  	h[i].id=i;
  }
  for(int i=1;i<=m;i++) {
  	v[i].id=i;
  }
  for(int i=1;i<=f;i++) {
    scanf("%d %d",&coord[i].x,&coord[i].y);
    h[coord[i].x].cnt++;
    v[coord[i].y].cnt++;
  }
  sort(h+1,h+n+1,cmp);
  sort(v+1,v+m+1,cmp);
  sort(coord+1,coord+f+1,cmp2);
  int i=1,j=1;
  int ans=0;
  while(h[i].cnt+v[j].cnt==h[1].cnt+v[1].cnt) {
  	bool f=0;
    if(sear(h[i].id,v[j].id)) {
    	f=1;
    	ans=max(ans,h[i].cnt+v[j].cnt-1);
	}
	if(!f) {
		ans=max(ans,h[i].cnt+v[j].cnt);
	}
	if(h[i+1].cnt+v[j].cnt>=h[i].cnt+v[j+1].cnt) {
		i++;
	}else {
		j++;
	}
  }
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 10808
#include <bits/stdc++.h>
using namespace std;
#define mp(a, b) make_pair(a, b)
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 1e3 + 10;
const int INF = 1e9;
int h, w, sx, sy, tx, ty;
char s[maxn][maxn];
int dis[maxn][maxn];
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
bool in(int x, int y) { return 1 <= x && x <= h && 1 <= y && y <= w && s[x][y] == '.';}
int main()
{
	scanf("%d%d%d%d%d%d", &h, &w, &sx, &sy, &tx, &ty);
	for(int i = 1; i <= h; ++i)
		scanf("%s", s[i] + 1);
	for(int i = 1; i <= h; ++i)
		for(int j = 1; j <= w; ++j)
			dis[i][j] = INF;
	deque<pii> Q;	
	dis[sx][sy] = 0;
	Q.push_back(mp(sx, sy));
	while(!Q.empty())
	{
		pii x = Q.front(); Q.pop_front();
		for(int i = 0; i < 4; ++i)
		{
			int nx = x.first + dx[i], ny = x.second + dy[i];
			if(in(nx, ny) && dis[nx][ny] > dis[x.first][x.second])
			{
				dis[nx][ny] = dis[x.first][x.second];
				Q.push_front(mp(nx, ny));
			}
		}
		for(int i = -2; i <= 2; ++i)
			for(int j = -2; j <= 2; ++j)
			{
				int nx = x.first + i, ny = x.second + j; 
				if(in(nx, ny) && dis[nx][ny] > dis[x.first][x.second] + 1)
				{
					dis[nx][ny] = dis[x.first][x.second] + 1;
					Q.push_back(mp(nx, ny));
				}
			}
	}
	if(dis[tx][ty] == INF) puts("-1");
	else printf("%d\n", dis[tx][ty]);
	return 0;
}
	

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

int A[20], n, q, k;

bool Comb(int sum, int i){
  if(sum == k) return true;
  if(i == n) return false;

  return Comb(sum + A[i], i + 1) + Comb(sum, i + 1);
}

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

  cin >> q;
  for(int i = 0; i < q; i++){
    cin >> k;
    if(Comb(0, 0)) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}

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

#define ll long long

struct P{
    double x,y;
};

int n;
double x[9], y[9];

void solve(){
    cin>>n;
    vector<pair<double, double> > p(n);
    for(int i=0; i<n; i++){
        cin>>p[i].first;
        cin>>p[i].second;
    }
    sort(p.begin(), p.end());

    double ans=0;
    int cnt=0;
    do{
        for(int i=1; i<n; i++){
            ans+=sqrt((p[i].first-p[i-1].first)*(p[i].first-p[i-1].first)+(p[i].second-p[i-1].second)*(p[i].second-p[i-1].second));
        }
        cnt++;
    }while(next_permutation(p.begin(), p.end()));
    printf("%.9f\n",ans/cnt);
}

signed main(){
    //while(1)
    solve();
}

Measured memory_bytes: 256
import sys
import numba

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@numba.njit('(i8,)', cache=True)
def main(N):
    x = 0
    for a in range(1, N+1):
        for b in range(1, N//a+1):
            x += a*b
    return x

N = int(read())
print(main(N))


Measured memory_bytes: 106264
import java.util.Scanner;
class Main{
public static void main(String[] args){
 Scanner scan = new Scanner(System.in);
 
 int X = scan.nextInt();
 int a = 0;
 int b = 0;
 int sum = 0;
   //500円換算
  	if( X >= 1000 ){
      a = X / 500;
      sum = 1000 * a;
      a = 500 * a;
      X = X - a;
    }
  	else if( X >= 500 ){
      X = X - 500;
      sum = 1000;
    }
    else{
    }
   //5円換算
	X = X / 5;
    X = X * 5;
    sum = sum + X;
  
  System.out.println(sum);
 }
}

Measured memory_bytes: 21972
import scala.io.StdIn

object Main extends App {
  val Array(n, m, q) = StdIn.readLine().split(" ").map(_.toInt)
  val a = (0 until q).map { _ =>
    val Array(a, b, c, d) = StdIn.readLine().split(" ").map(_.toInt)
    Item(a - 1, b - 1, c, d)
  }

  var best = 0
  def f(x: Int, n: Int, list: Vector[Int]): Unit = {
    if (x <= m) {
      if (n == 0) {
        val res = a.foldLeft(0) { case (acc, Item(a, b, c, d)) =>
          if (list(b) - list(a) == c) acc + d else acc
        }
        best = best max res
      } else {
        for (i <- x to m)
          f(i, n - 1, list :+ i)
      }
    }
  }
  f(1, n, Vector.empty)
  println(best)

  case class Item(a: Int, b: Int, c: Int, d: Int)

  def readIntPair: (Int, Int) = {
    val Array(x, y) = StdIn.readLine().split(" ").map(_.toInt)
    (x, y)
  }
}

Measured memory_bytes: 59600
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

struct st {
    int d1, d2;
    bool operator<(const st &r) const {
        return d1 != r.d1 ? d1 < r.d1 : d2 > r.d2;
    }
};

struct node {
    int v;
    int x, y;
    st d;
    bool operator<(const node &r) const { return !(d < r.d); }
};

st INF = st{1 << 30, 0};

int h, w, k;
int sx, sy, tx, ty;
vector<string> mp;
vector<vector<st>> d[4];

bool in(int x, int y) { return 0 <= x && x < h && 0 <= y && y < w; }

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

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

    cin >> h >> w >> k;
    cin >> sx >> sy >> tx >> ty;
    sx--;
    sy--;
    tx--;
    ty--;
    mp.resize(h);
    rep(i, 4) d[i].assign(h, vector<st>(w, INF));
    rep(i, h) cin >> mp[i];

    rep(i, 4) d[i][sx][sy] = st{0, 0};
    priority_queue<node> pq;
    rep(i, 4) pq.push(node{i, sx, sy, st{0, 0}});

    while(!pq.empty()) {
        node v = pq.top();
        pq.pop();
        if(d[v.v][v.x][v.y] < v.d) continue;
        if(v.d.d2 > 0) {
            int nx = v.x + dx[v.v];
            int ny = v.y + dy[v.v];
            if(in(nx, ny) && mp[nx][ny] == '.' &&
               st{v.d.d1, v.d.d2 - 1} < d[v.v][nx][ny]) {
                d[v.v][nx][ny] = st{v.d.d1, v.d.d2 - 1};
                pq.push(node{v.v, nx, ny, d[v.v][nx][ny]});
            }
        }
        rep(i, 4) {
            int nx = v.x + dx[i];
            int ny = v.y + dy[i];
            if(in(nx, ny) && mp[nx][ny] == '.' &&
               st{v.d.d1 + 1, k - 1} < d[i][nx][ny]) {
                d[i][nx][ny] = st{v.d.d1 + 1, k - 1};
                pq.push(node{i, nx, ny, d[i][nx][ny]});
            }
        }
    }

    st mn = INF;
    rep(i, 4) if(d[i][tx][ty] < mn) mn = d[i][tx][ty];

    if(mn.d1 == 1 << 30) {
        cout << -1 << endl;
    } else {
        cout << mn.d1 << endl;
    }

    return 0;
}

Measured memory_bytes: 42332
h, w, a, b = map(int, input().split())

# 列、0の数をカウント
col = [0 for i in range(w)]
correct = []


for r in range(h):
    tmp = ''
    for c in range(w):
        if c < a and r < b or (c in range(a, w) and r in range(b, h)):
            tmp += '0'
        else:
            tmp += '1'
    correct.append(tmp)

for s in correct:
    print(s)


Measured memory_bytes: 5108
#include<iostream>
using namespace std;
int main()
{
	int n, AC = 0, WA = 0, TLE = 0, RE = 0;
	string S;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> S;
		if (S == "AC")
			AC++;
		if (S == "WA")
			WA++;
		if (S == "TLE")
			TLE++;
		if (S == "RE")
			RE++;
	}
	cout << "AC x" << ' ' << AC << endl;
	cout << "WA x" << ' ' << WA << endl;
	cout << "TLE x" << ' ' << TLE << endl;
	cout << "RE x" << ' ' << RE << endl;
	return 0;
}

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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int N,M,X,Y;
    cin >> N >> M >> X >> Y;

    vector<int> x(N),y(M);
    rep(i,0,N) cin >> x[i];
    rep(i,0,M) cin >> y[i];
    x.push_back(X);
    y.push_back(Y);

    cout << (*max_element(begin(x),end(x))<*min_element(begin(y),end(y))?"No War":"War") << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

const int INF=1e18;

int Binary_search(int l,int r,int k)
{
	if(l+1==r || l==r)
		if(l*l*l*l*l==k)
			return l;
		else
			if(r*r*r*r*r==k)
				return r;
			else
				return INF;
	
	int mid=(l+r)>>1;
	if(mid*mid*mid*mid*mid==k) return mid;
	if(mid*mid*mid*mid*mid>k) return Binary_search(l,mid,k);
	if(mid*mid*mid*mid*mid<k) return Binary_search(mid,r,k);
}

signed main()
{
	int n;
	cin>>n;
	
	for(int i=-6178;i<=6178;i++)
	{
		int a=i,b=Binary_search(-10000ll,10000ll,a*a*a*a*a-n);
		if(b!=INF)
		{
			cout<<a<<" "<<b<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3612
import sys
sys.setrecursionlimit(10**6)
def dfs(G,v,p):
    for nv,nw in G[v]:
        if(nv==p):
            continue
        if(nw%2==0):
            color[nv]=color[v]
        else:
            color[nv]=int(not color[v])
        dfs(G,nv,v)
N=int(input())
G=[[] for i in range(N)]
color=[-1]*N
for i in range(N-1):
    u,v,w=map(int,input().split())
    u,v=u-1,v-1
    G[u].append((v,w))
    G[v].append((u,w))
color[0]=0
dfs(G,0,-1)
print(*color,sep='\n')

Measured memory_bytes: 162848
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main()
{
	int i,j,N,temp,ans=0;
	bool flag;
	vector<int> h,check;
	cin>>N;
	for(i=0;i<N;i++){
		cin>>temp;
		h.push_back(temp);
		check.push_back(0);
	}
	while(true){
		flag=0;
		for(i=0;i<N;i++){
			if(flag){
				if(h.at(i)==0){
					flag=0;
				}else{
					h.at(i)--;
				}
			}else{
				if(h.at(i)!=0){
					flag=1;
					h.at(i)--;
					ans++;
					//cout<<'#';
				}
			}
			//cout<<h.at(i);
		}
		//cout<<endl;
		if(h==check){
			break;
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#include <time.h> //for clock
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;
using ll = long long;

int main(){
    int H, W, h, w;
    cin >> H >> W >> h >> w;

    cout << (H-h)*(W-w) << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

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

int N, K;

int main() {

	scanf("%d%d", &N, &K);


	if (K > (N - 1) * (N - 2) / 2) {
		printf("-1\n");
		return 0;
	}

	int C = (N - 1) * (N - 2) / 2;
	vector<pair<int, int>> ans;

	rep(i, N - 1) ans.push_back({ 1, i + 2 });

	int i = 2, j = 3;
	while (C > K) {
		ans.push_back({ i, j });
		C--;
		j++;
		if (j > N) {
			i++;
			j = i + 1;
		}
	}

	printf("%d\n", ans.size());
	for (auto a : ans) printf("%d %d\n", a.first, a.second);

	return 0;
}


Measured memory_bytes: 384
from fractions import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)

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

lenS,lenT = len(S),len(T)
L = lcm(N,M)
isok = True
for i in range(L):
    if i*(L//M)>=len(S) or i*(L//N)>=len(T):
        break
    elif S[i*(L//M)]!=T[i*(L//N)]:
        isok = False
        break
        
if isok:
    print(L)
else:
    print("-1")

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

void Main()
{
  int N; string S;
  cin >> N; cin >> S;
  vector<int> wnum(N);
  vector<int> eanum(N);
  wnum[0] = 0; eanum[0] = 0;
  if (S[0] == 'W') wnum[0]++;
  else eanum[0]++;
  
  for (int i = 1; i < N; i++){
    if (S[i] == 'W') {
      wnum[i] = wnum[i-1] + 1;
      eanum[i] = eanum[i-1];
    } else {
      eanum[i] = eanum[i-1] + 1;
      wnum[i] = wnum[i-1];
    }
  }
  int minnum = N;
  rep(i,N) {
    if (i == 0) minnum = min(minnum, eanum[N-1]-eanum[0]);
    else {
      minnum = min(minnum, eanum[N-1]-eanum[i] + wnum[i-1]);
    } 
  }
  cout << minnum << endl;
}

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

Measured memory_bytes: 2964
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	long long int a,b,i,d,res=0;
	vector<int>c;
	cin>>a;
	for(i=0;i<a;i++){
		cin>>d;
		c.push_back(d);
		c[i]-=i+1;
	}
	sort(c.begin(),c.end());
	b=c[a/2];
	for(i=0;i<a;i++)res+=abs(c[i]-b);
	cout<<res;
}

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

ll factorial(ll n){
    ll answer = 1;
    while(n > 1){
        answer *= n;
        answer %= 1000000007;
        n--;
    }
    return answer;
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N, M;
    cin >> N >> M;
    if(abs(N-M) > 1) {
        cout << 0 << endl;
    }
    else {
        ll fn = factorial(N);
        ll fm = factorial(M);
        if((abs(N-M) == 0)) cout << fn * fm * 2 % 1000000007 << endl;
        else cout << fn * fm % 1000000007 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
/*
ID: jerrywcy
TASK: AtCoder Beginner Contest 107 Problem D
LINK: https://abc107.contest.atcoder.jp/tasks/arc101_b
LANG: C++
*/
#include<bits/stdc++.h>

using namespace std;

long long n,s[100500];

long long solve(long long p) {
    vector<long long> k(2*n+1);
    long long sum=n;
    k[sum]=1;
    long long add=1;
    long long res=0;
    for (int i=1;i<=n;i++) {
        if(s[i]<p) {
            add-=k[sum];
            sum--;
        }
        else {
            sum++;
            add+=k[sum];
        }
        res+=add;
        k[sum]++;
        add++;    
    }
    return res;
}

int main() {
    long long l=INT_MAX,r=INT_MIN,res=INT_MIN;
    cin>>n;
    int i;
    for(i=1;i<=n;i++) {
        cin>>s[i];
        l=min(l,s[i]);
        r=max(r,s[i]);
    }
    if(l==r)
    {
        cout<<l<<endl;
        return 0;
    }
    long long tot=n*(n+1)/2-(n*(n+1)/4+1);
    while(l<=r) {
        long long mid=(l+r)>>1;
        long long ans=solve(mid);
        if(ans<tot)r=mid-1;
        else {
            res=max(mid,res);
            l=mid+1;
        }
    } 
    cout<<res<<endl;  
}

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

using namespace std;
int t=0;
double solve(int i,int j,vector<double>&p,vector<vector<double> >&dp){
  //  cout << i << " " << j <<" "<< dp[i][j] <<endl;
   if(dp[i][j]!= -1.00)
      return dp[i][j];
   if(i==0 && j==0){
    return 1.00;
   }
   if(i<j){
    return 0.00;
   }
   double ans = p[i-1]*solve(i-1,j-1,p,dp);
   ans+=   (1-p[i-1])*solve(i-1,j,p,dp);
   dp[i][j]=ans;
 //  cout << i << " " << j <<" " <<dp[i][j]<<endl;
   return ans;



}
int main()
{
 int n;
 cin >> n;
 vector<double>p(n);
 for(int i=0;i<n;++i){
    cin >> p[i];
 }
 vector<vector<double> >dp(n+1,vector<double>(n+1,-1.00));
 double ans=0;
 for(int i=n;i>n/2;--i){
       //cout<<dp[n][i]<<endl;
    ans+=solve(n,i,p,dp);
 }
  cout <<fixed << setprecision(10)<<ans<<endl;
  return 0;
}

Measured memory_bytes: 74044