akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long LL;
const LL INF=1e15;
LL sum=0,f[200001],g[200001];
LL x,y,z;
priority_queue <LL , vector <LL> , greater <LL> > q;
struct data {
	LL va1,va2,va;
}a[200001];
bool cmp(data p,data q) {
	return p.va>q.va;
}
int main() {
	scanf("%lld%lld%lld",&x,&y,&z);
	for (int i=1;i<=x+y+z;i++) {
		LL ax,bx,cx;
		scanf("%lld%lld%lld",&ax,&bx,&cx);
		sum+=bx;
		a[i].va1=ax-bx;
		a[i].va2=cx-bx;
		a[i].va=a[i].va1-a[i].va2;
	}
	sort(a+1,a+x+y+z+1,cmp);
	LL now=0;
	for (int i=1;i<=x+y+z;i++) {
		if (q.size()<x) {
			q.push(a[i].va1);
			now+=a[i].va1;
			f[i]=-INF;
			if (q.size()==x) f[i]=now;
			continue;
		}
		int nowx=q.top();
		if (a[i].va1<=nowx) {
			f[i]=now;
			continue;
		}
		q.pop();
		q.push(a[i].va1);
		now=now-nowx+a[i].va1;
		f[i]=now;
	}
	while (!q.empty()) q.pop();
	now=0;
	for (int i=x+y+z;i>=1;i--) {
		if (q.size()<z) {
			q.push(a[i].va2);
			now+=a[i].va2;
			g[i]=-INF;
			if (q.size()==z) g[i]=now;
			continue;
		}
		int nowx=q.top();
		if (a[i].va2<=nowx) {
			g[i]=now;
			continue;
		}
		q.pop();
		q.push(a[i].va2);
		now=now-nowx+a[i].va2;
		g[i]=now;
	}
	LL max0=-INF;
	for (int i=1;i<x+y+z;i++)
		if (f[i]+g[i+1]>max0) max0=f[i]+g[i+1];
	printf("%lld\n",max0+sum);
	return 0;
}

Measured memory_bytes: 8056
//貪欲法
#include <bits/stdc++.h>
using namespace std;

int main(){
        long long n, m;
        while(cin >> n >> m && n > 0 || m > 0){
                long long ans = 0;
                vector<pair<long long, long long> > pairs(n);
                for (int i = 0; i < n; i++){
                        long long p, d;
                        cin >> d >> p;
                        pairs[i] = make_pair(p, d);
                }
                sort(pairs.begin(), pairs.end(), greater<pair<long long, long long> >());
                /*for (auto x : pairs){
                        cout << x.first << " " << x.second << endl;
                }
                long long tmp = 0;
                while(1){
                        if(pairs[tmp].second <= m){
                                ans -= pairs[tmp].first * pairs[tmp].second;
                                m -= pairs[tmp].second;
                                tmp++;
                        }
                        else {
                                ans -= m * pairs[tmp].first;
                                break;
                        }
                }*/
                for (int i = 0; i < n; i++){
                       if(pairs[i].second <= m) m -= pairs[i].second;
                       else {
                               ans += pairs[i].first * (pairs[i].second - m);
                               m = 0;
                       }
                }
                cout << ans << endl;
        }
        return 0;
}



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

  int main()
  {
	int n , t = 0 ;
	cin >> n ;
	int c[n] , v[n] ;
	for(int i = 1 ; i <= n ; i++)
	{
		cin >> c[i] ;
	 } 
	 for(int i = 1 ; i <= n ; i++)
	{
		cin >> v[i] ;
		if(v[i] < c[i])
		{
			t += c[i] - v[i] ; 
		}
	 } 
	 cout << t << endl ;
	 return 0 ;
}

Measured memory_bytes: 256
import math


def number2bit(n):
    return int(math.pow(2, n - 1))


def count_bit(n):
    count = 0
    while n > 0:
        if n & 1 == 1:
            count += 1
        n >>= 1
    return count


N, M = map(int, input().split(' '))
lights = [set(tuple(map(int, input().split(' ')))[1:]) for _ in range(M)]
light_bits = [sum(map(number2bit, light)) for light in lights]
mods = tuple(map(int, input().split(' ')))

count = 0
for i in range(int(math.pow(2, N))):
    for j, light_bit in enumerate(light_bits):
        if count_bit(i & light_bit) % 2 != mods[j]:
            break
    else:
        count += 1

print(count)


Measured memory_bytes: 3064
def divisor(x):
    div=[]
    for i in xrange(1,int(x**0.5)+1):
        if x%i==0:
            div.append(i)
            if i!=x/i:
                div.append(x/i)
    return div

n=int(raw_input())
ans=100
d=divisor(n)
for i in xrange(len(d)):
    a=str(d[i])
    b=str(n/d[i])
    ans=min(ans,max(len(a),len(b)))
print ans


Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const double pi = acos(-1.0);
const double EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

template<typename T>
struct Binary_Indexed_Tree{
    vector<T> bit;
    const int n;
    
    Binary_Indexed_Tree(int n) : n(n){
        bit.assign(n+1, 0);
    }
    
    void add(int i, const T &x){
        for(i++; i <= n; i += (i & -i)) bit[i] += x;
    }
    
    T sum(int i) const{
        T ret = 0;
        for(; i > 0; i -= (i & -i)) ret += bit[i];
        return ret;
    }
    
    T query(int l, int r) const{
        return sum(r) - sum(l);
    }

    int lower_bound(T x) const{
        int ret = 0;
        for(int k = 31-__builtin_clz(n); k >= 0; k--){
            if(ret+(1<<k) <= n && bit[ret+(1<<k)] < x) x -= bit[ret += (1<<k)]; 
        }
        return ret;
    }

    int upper_bound(T x) const {return lower_bound(x+1);}
    
    void clear(){
        fill(all(bit), 0);
    }
};

int main(){
    int N, Q;
    cin >> N >> Q;
    Binary_Indexed_Tree<ll> bit(N);
    rep(i, N){
        ll a; cin >> a;
        bit.add(i, a);
    }
    while(Q--){
        int q, x, y; cin >> q >> x >> y;
        if(q == 0) bit.add(x, y);
        else cout << bit.query(x, y) << endl;
    }
}

Measured memory_bytes: 8204
N = int(input())
D = [list(map(int, input().split())) for _ in range(N)]

cnt = 0
ans = False
for a, b in D:
  if a == b:
    cnt += 1
  else:
    cnt = 0
  if cnt == 3:
    ans = True

if ans:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 62440
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str):
    flag = True
    strings_odd = ['R', 'U', 'D']
    strings_even = ['L', 'U', 'D']
    for i, s in enumerate(S):
        i = i + 1
        if i % 2 == 0:
            if s in strings_even:
                pass
            else:
                flag = False
        if i % 2 == 1:
            if s in strings_odd:
                pass
            else:
                flag = False
    if flag == True:
        print('Yes')
    else:
        print('No')
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
fun main() {
    val n = readInt()
    val mod = 1000000007L

    val factorials = LongArray(n + 1)
    factorials[0] = 1
    for (i in 1..n) {
        factorials[i] = (factorials[i - 1] * i) % mod
    }

    fun modPow(x: Long, n: Int, m: Long): Long {
        if (n == 0) return 1 % m
        var u = modPow(x, n / 2, m)
        u = (u * u) % m
        if (n % 2 == 1) u = (u * x) % m
        return u
    }

    fun modInverse(x: Long, m: Long): Long {
        return modPow(x, m.toInt() - 2, m)
    }

    fun aChooseB(a: Int, b: Int): Long {
        if (b > a) return 0L
        val numerator = factorials[a]
        val denominator = (factorials[b] * factorials[a - b]) % mod
        return (numerator * modInverse(denominator, mod)) % mod
    }

    val nChoose = LongArray(n + 1)
    for (i in 0..n) nChoose[i] = aChooseB(n, i)

    var ans = 0L
    for (x in 2..n) {
        val choose = nChoose[x]
        val twoPow = (modPow(2L, x, mod) + mod - 2) % mod
        val eightPow = modPow(8L, n - x, mod)
//        println("$choose $twoPow $eightPow")
        ans = (ans + (((choose * twoPow) % mod) * eightPow) % mod) % mod
    }

    println(ans)
}

// Input Reader
private fun readLn() = readLine()!!

private fun readInt() = readLn().toInt()


Measured memory_bytes: 51856
//Tariquzzaman Faisal
//_Faisal101_
//IUT_CSE'19
//190041101

#include<iostream>
#include<stdio.h>
#include<vector>
#include<deque>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<cstring>
#include<climits>
#include<cmath>
#include<iterator>
#define mp make_pair
#define pb push_back
#define pb push_back
#define fileOut freopen(''out.txt'',''w'',stdout)
#define fileIn freopen(''in.txt'',''r'',stdout)
#define testcases ll tc,t; cin >> tc; for(t=1;t<tc;t++)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pi acos(-1.0)
#define ll long long

using namespace std;


int main(){
	
	double rad;
	cin >> rad;
	cout << 2*pi*rad<<endl;
	
return 0;
}

Measured memory_bytes: 3236
//
//AtCoder Beginner Contest XXX
//C - Green Bin
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

ll comb(ll n, ll r){
    ll ret = 1;
    FOR(i, 1, r) ret = ret * (n - i + 1) / i;
    return ret;
}

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

    vector<string> s(n);
    REP(i, n) {
        cin >> s[i];
        sort(ALL(s[i]));
    }
    sort(ALL(s));
    ll ans = 0;
    string tmp = s[0];
    int c = 1;
    FOR(i, 1, n-1){
        if (tmp == s[i]) c++;
        else {
            //MSG(c);
            ans += comb(c, 2);
            c=1;
        }
        tmp = s[i];
    }
    ans += comb(c, 2);
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7296
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<utility>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){
ll n;
cin>>n;
ll count=0;
for(ll i=0;i<4;i++){
if(n%10==2)
count++;
n=n/10;
}
cout<<count;
  return 0;

}



Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = sorted(list(map(int, input().split())), reverse=True)
    ans = 0
    j = 1
    for i in range(n):
        ans += a[i] * j
        j *= -1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import numpy as np

n, m = map(int, input().split())
mat = np.array([list(map(int, input().split())) for _ in range(n)])

ans = 0
minus_or_plus = [-1, 1]
for i in minus_or_plus:
    for j in minus_or_plus:
        for k in minus_or_plus:
            candidates = sorted([i * mat[_, 0] + j * mat[_, 1] + k * mat[_, 2] for _ in range(n)], reverse=True)
            ans = max(ans, sum(candidates[:m]))
print(ans)


Measured memory_bytes: 20260
#include<iostream>
#include<vector>
#include<map>
#include<queue>
#include<functional>
#include<stdio.h>
#define INF 1000000000//INF=∞
using namespace std;
typedef pair<int, int> P;//firstは最短距離,secondは頂点番号

const int MAX_M = 100;

struct edge {
  int to, cost;
  //edge() : to(0), cost(0) {}
  //edge(int to, int cost) : to(to), cost(cost) {}
};
int V;//頂点の数

vector<vector<edge> > time_graph(MAX_M); //頂点間の距離情報(隣接リスト)
vector<vector<edge> > cost_graph(MAX_M);

vector<vector<int> > time_ds(MAX_M); // メモ化配列
vector<vector<int> > cost_ds(MAX_M);

int dijkstra(vector<vector<edge> >& G, vector<vector<int> >& ds, int s, int g){
  // メモイズしてあったらそれを再利用（これ入れないとAOJで時間が足りない…なぜ）
  if (!ds[s].empty()) return ds[s][g]; 
  
  priority_queue<P, vector<P>, greater<P> > que;
  vector<int> d(V, INF);//最短距離を記録する配列(∞で初期化しておく)
  d[s] = 0;//頂点sから頂点sへの最短距離は0で確定
  que.push(P(0, s));//距離0,頂点sからスタート

  while(!que.empty()){
    /*処理1*/
    //キューの中で最も頂点sからの距離が近い頂点vとその距離cを取得
    P p = que.top();
    que.pop();
    int v = p.second, c = p.first;

    /*処理2*/
    //頂点vの最短距離がすでに確定していたらcontenue
    if(d[v] < c)
      continue;

    /*処理3*/
    //頂点vの最短距離が既に確定していなければ頂点vへの最短経路はcで確定
      d[v]=c;

    /*処理4*/
    //頂点vから移動しうる頂点とその距離をキューに入れる
    for(int i = 0; i < G[v].size(); i++){
      //頂点vはG[v].size()個の行き先を持つ
      edge e = G[v][i];
      if(d[e.to] > d[v] + e.cost){
        que.push(P(d[v] + e.cost, e.to));
      }
    }
  }
  
  ds[s] = d;
  return d[g];//頂点gへの最短距離を返す
}

int main() {
  int n, m;
  while (scanf("%d%d", &n, &m), n || m) {
    V = m;

    for (int i = 0; i < MAX_M; i++) {
      time_graph[i].clear();
      time_ds[i].clear();
      cost_graph[i].clear();
      cost_ds[i].clear();
    }

    for (int i = 0; i < n; i++) {
      int a, b, time, cost;
      scanf("%d%d%d%d", &a, &b, &time, &cost);
      a--; b--; // 0-indexedにする
      edge e1,e2,e3,e4;
      e1.to = e3.to = b; e1.cost = e2.cost = time;
      e2.to = e4.to = a; e3.cost = e4.cost = cost;
      time_graph[a].push_back(e1);
      time_graph[b].push_back(e2);
      cost_graph[a].push_back(e3);
      cost_graph[b].push_back(e4);
    }

    int k;
    cin >> k;
    for (int i = 0; i < k; i++) {
      int p, q, r;
      scanf("%d%d%d", &p, &q, &r);
      p--; q--;
      if (p > q) swap(p, q);
      if (r == 0)
        printf("%d\n", dijkstra(time_graph, time_ds, p, q));
      else
        printf("%d\n", dijkstra(cost_graph, cost_ds, p, q));
    }
  }
}

Measured memory_bytes: 1244
#include <iostream>
#include <vector> 
#include <cmath>
#include <algorithm>
#include <set>
#include <string>
#include <map>
#include <cerrno>
#include <stdio.h>
#include <stdlib.h>
#include <cfenv>
#include <stack>
#include <math.h>
#include <iomanip>
#include <limits>
#include <queue>
#define ll long long int
#define pb push_back
#define mp make_pair

using namespace std;

int main(){

    int N;
    cin >> N;
    vector<string> S(N);

    for(int i=0;i<N;i++){
        cin >> S[i];
    }

    vector<ll> vec(5,0);

    //cout << S[0][0] << endl;

    for(int i=0;i<N;i++){
        if(S[i][0] == 'M'){
            vec[0]++;
        }
        else if(S[i][0] == 'A'){
            vec[1]++;
        }
        else if(S[i][0] == 'R'){
            vec[2]++;
        }
        else if(S[i][0] == 'C'){
            vec[3]++;
        }
        else if(S[i][0] == 'H'){
            vec[4]++;
        }
    }

    ll ans = 0;
    
    for(int i=0;i<3;i++){
        for(int j=i+1;j<4;j++){
            for(int k=j+1;k<5;k++){
                ans += vec[i] * vec[j] * vec[k];
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6144
// C - 100 to 105
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int X; cin>>X;
	vi yen{0,100,101,102,103,104,105};
	vvi dp(yen.size()+1, vi(X+1));
	rp(i, 1, dp.size()){
		int y = yen[i];
		rp(j, y, X+1) dp[i][j] = max(dp[i][j-y]+y, dp[i-1][j-y]+y);
	}
	rp(i, 1, dp.size())
		if(dp[i][X] == X){ puts("1"); return 0; }
	puts("0");
}

Measured memory_bytes: 3712
#include<iostream>
int main() {
long long int N,V[100001];
V[0]=1;
V[1]=1;
std::cin >> N;
for(int i=1; i<=N; ++i)
V[i]=(i*V[i-1])%(1000000000+7);
std::cout << V[N] << std::endl;


return 0;
}
		



Measured memory_bytes: 1024
# -*- coding: utf-8 -*-

N = int(input())
s = [input() for i in range(N)]

cnt = 0
both_ab = 0
last_a = 0
initial_b = 0
for i in range(N):
    if s[i].count('AB') > 0:
        cnt += s[i].count('AB')

    if s[i][-1] == 'A' and s[i][0] == 'B':
        both_ab += 1
    elif s[i][-1] == 'A':
        last_a += 1
    elif s[i][0] == 'B':
        initial_b += 1


def calc(cnt, both_ab, last_a, initial_b):
    if both_ab == 0:
        min_a_b = min(initial_b, last_a)
        cnt += min_a_b
        return cnt

    if min(both_ab, last_a) > min(both_ab, initial_b):
        cnt += min(both_ab, initial_b)
        both_ab -= min(both_ab, initial_b)
    else:
        cnt += min(both_ab, last_a)
        both_ab -= min(both_ab, last_a)

    if last_a == 0 and initial_b == 0:
        return cnt + both_ab - 1

    min_a_b = min(initial_b, last_a)
    cnt += min_a_b

    return both_ab + cnt


ans = calc(cnt, both_ab, last_a, initial_b)
print(ans)


Measured memory_bytes: 3700
#include<iostream>
#include<string>
using namespace std;
typedef long long ll;
const int N = 1e5+600;
ll a[N];
ll gcd(ll n, ll m){
  ll t;
  while(m>0){
		t=n%m;
		n=m;
		m=t;
	}
  return n;
}
int main(){
    int n;
    cin>>n;
    for(int i = 0;i < n; i++){
      cin>>a[i];
    }
    int numb = a[0];
    for(int i = 1;i < n; i++){
      numb = gcd(numb, a[i]);
    }
    cout<<numb<<endl;
}


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


vector<bool> Eratosthenes(ll N){
    vector<bool> is_prime(N+1);
    rep(i,N+1){
        is_prime[i] = true;
    }

    for(int i=2;i<sqrt(N);i++){
        if(is_prime[i]){
            for(int j=i*2; j<N; j+=i){
                is_prime[j] = false;
            }
        }
    }
    is_prime[1] = false;
    return is_prime;
}

int main(){
    int Q; cin >> Q;
    vector<bool> is_prime = Eratosthenes(100010);

    vector<int> sum(100010);
    int cnt = 0;
    for(int i=1;i<=100001;i++){
        if(i%2==1 && is_prime[i] && is_prime[(i+1)/2]) cnt++;
        sum[i] = cnt;
    }

    rep(i,Q){
        int l,r; cin >> l >> r;
        cout << sum[r] - sum[l-1]  << endl;
    }
}

Measured memory_bytes: 3852
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>
#include <numeric>
#include <functional>
#include <utility>

using namespace std;

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

int main(void) {
  int n, k;
  cin >> n >> k;
  int r, s, p;
  cin >> r >> s >> p;
  string t;
  cin >> t;

  string tkh;
  int score = 0;

  vector<string> tbl(k);

  rep(i, n) {
    int idx = i % k;
    switch (t.at(i))
    {
    case 'r':
      score += p;
      tkh.push_back('p');
      tbl.at(idx).push_back('p');
      break;
    case 's':
      score += r;
      tkh.push_back('r');
      tbl.at(idx).push_back('r');
      break;
    case 'p':
      score += s;
      tkh.push_back('s');
      tbl.at(idx).push_back('s');
      break;
    }
  }

  rep(i, k) {
    int seqcnt = 1;
    for (int j = 0; j < tbl.at(i).size() - 1; ++j) {
      if (tbl.at(i).at(j) == tbl.at(i).at(j + 1)) {
        seqcnt++;
      }
      if (tbl.at(i).at(j) != tbl.at(i).at(j + 1) || j == tbl.at(i).size() - 2) {
        if (seqcnt >= 2) {
          int subscore = 0;
          switch (tbl.at(i).at(j))
          {
          case 'r':
            subscore = r;
            break;
          case 's':
            subscore = s;
            break;
          case 'p':
            subscore = p;
            break;
          }
          subscore *= (seqcnt / 2);
          score -= subscore;
        }
        seqcnt = 1;
      }
    }
  }
  cout << score << endl;
  return 0;
}


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

using namespace std;

#define sig(x) ((x) ? -1 : 1)

int main() {
  int n = 0;
  scanf("%d", &n);
  long long minDist[4], maxDist[4];
  for (int i = 0; i < 4; ++i) {
    minDist[i] = 1e9*4+5;
    maxDist[i] = -1e9*4+5;
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    long long x, y;
    scanf("%lld%lld", &x, &y);

    for (int j = 0; j < 4; ++j) {
      long long p = sig(j&1)*x + sig(j&2)*y;
      minDist[j] = min(minDist[j], p);
      maxDist[j] = max(maxDist[j], p);
      ans = max(ans, maxDist[j]-minDist[j]);
    }
  }

  printf("%lld\n", ans);

  return 0;
}

Measured memory_bytes: 3808
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  input! {
    n: i64,
    m: i64,
  }
  let mut d = m;
  {
    let mut i = 1;
    while i * i <= m {
      if m % i == 0 {
        if i >= n {
          d = cmp::min(d, i);
        }
        if m / i >= n {
          d = cmp::min(d, m / i);
        }
      }
      i += 1;
    }
  }

  println!("{}", m / d);
}


Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int H = scan.nextInt();
        int A = scan.nextInt();
        int answer = H / A;
        if (H % A != 0) {
            answer += 1;
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 23764
from math import floor
a, b, n = [int(x) for x in input().split()]
def e(x):
	return floor(a * x // b) - a * floor(x // b)
candidates = [a, a - 1, b-1, b, n-1, n]
print(max(*[e(x) for x in candidates if x >= 1 and x <= n]))

Measured memory_bytes: 9132
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

int dp[100005][2];

signed main() {
	string s;
	cin >> s;
	dp[0][0] = 1;
	rep(i, s.size()) {
		rep(j, 2) {
			for (int k = 0; k <= (j ? 1 : s[i] - '0'); k++) {
				if (k == 0) {
					dp[i + 1][j || (s[i] - '0') > k] += dp[i][j];
					dp[i + 1][j || (s[i] - '0') > k] %= MOD;
				}
				else {
					dp[i + 1][j || (s[i] - '0') > k] += (dp[i][j] * 2) % MOD;
					dp[i + 1][j || (s[i] - '0') > k] %= MOD;
				}
			}
		}
	}
	cout << (dp[s.size()][0] + dp[s.size()][1]) % MOD << endl;
	

	return 0;
}


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

struct edge {
	int from;
	int to;
	long long int cost;
};

struct aa {
	int now;
	int rema;
	long long int cost;
};
class Compare {
public:
	bool operator()(const aa&l, const aa&r) {
		return l.cost> r.cost;
	}
};	//aa?????????????????¶


int N, M, R, Q;
void dfs(const vector<vector<edge>>&edges,vector<vector<long long int>>&memo) {
	priority_queue<aa, vector<aa>, Compare>que;
	for (int i = 0; i <N; ++i) {
		que.push(aa{ i,(i + 1) % R,0 });
		memo[i][(i + 1)%R] = 0;
	}
	while (!que.empty()) {
		aa atop(que.top());
		que.pop();
		for (auto e : edges[atop.now]) {
			if (memo[e.to][atop.rema]>atop.cost + e.cost) {
				memo[e.to][atop.rema] = atop.cost + e.cost;
				que.push(aa{ e.to,atop.rema,atop.cost + e.cost });
			}
		}
	}
}

int main() { 
	cin >> N >> M >> R >> Q;
	vector<vector<long long int >>memo(N, vector<long long int>(R, 1e18));
	vector<vector<edge>>revedges(N);
	for (int i = 0; i < M; ++i) {
		int a, b;long long int c; cin >> a >> b >> c;
		a--; b--;
		revedges[b].push_back(edge{ b,a,c });
	}
	dfs(revedges, memo);
	long long int ans = 0;
	while (Q--) {
		int x, y; long long int  z; cin >> x >> y >> z; 
		x--; y--;
		long long int amin = 1e18;
		for (int rema = 0; rema < R; ++rema) {
			amin = min(amin, memo[x][rema] + memo[y][rema]);
		}
		ans += max(0ll, z - amin);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 26248
#include <iostream>
#include <vector>
#include <string>
#include <sstream> 
#include <algorithm>

using namespace std;

string solve(string str) {
    string ans;

    // split
    vector<string> results;    
    stringstream ss(str);
    string buffer;
    char sep = ' ';
    while( std::getline(ss, buffer, sep) ) {
        results.push_back(buffer);
    }

    const int size = results.size();
    for (int i = 0; i < size; ++i) {   
        string tmp = to_string(results[i].length());
        ans += tmp;
    }

    return ans;
}

int main(int argc, char const *argv[]) {
    string str;
    const string end("END OF INPUT");

    while (getline(cin, str), str != end) {
        cout<<solve(str)<<endl;
    }
    return 0;
}

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

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  for (int i = 100; i >= 0; i--) {
    if (A % i == 0 && B % i == 0) K--;
    if (!K) return cout << i << "\n", 0;
  }
}

Measured memory_bytes: 256
MALE = 0
FEMALE = 1

def query(i):
    print(i, flush=True)
    s = input()
    if s == 'Vacant':
        exit()

    if s == 'Male':
        return(MALE)
    else:
        return(FEMALE)

def search(start, end, start_gendar):
    i = (end - start)//2
    g = query(start + i)
    if (i%2 == 0 and g != start_gendar) or (i%2 != 0 and g == start_gendar):
        return (start, start+i, start_gendar)
    return (start+i, end, g)

def main():
    n = int(input())
    start = 0
    end = n
    gendar = query(0)
    for i in range(20):
        start_new, end_new, gendar_new = search(start, end, gendar)
        start = start_new
        end = end_new
        gendar = gendar_new

if __name__ == "__main__":
    main()

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

using ll = long long;

int main(){
  int N;
  cin >> N;
  vector<int> V(N), C(N);
  for (int i = 0; i < N; i++) {
    cin >> V[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> C[i];
  }
  int ans=0;
  for (int i = 0; i < N; i++) {
    if ((V[i]-C[i])>0) {
      ans += V[i]-C[i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define mp make_pair
#define LL long long
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
vector<int>gx,gy;
map<pii,bool>mm;
int n,m,q;
int mxx,mxy;
int sumx[300010],sumy[300010];
int main(){
	cin>>n>>m>>q;
	for(int i=1;i<=q;i++){
		int x,y;
		cin>>x>>y;
		sumx[x]++;
		sumy[y]++;
		mxx=max(mxx,sumx[x]);
		mxy=max(mxy,sumy[y]);
		mm[mp(x,y)]=1;
	}
	vector<int>vx,vy;
	for(int i=1;i<=n;i++)if(sumx[i]==mxx)gx.pb(i);
	for(int i=1;i<=m;i++)if(sumy[i]==mxy)gy.pb(i);
	for(auto x:gx)for(auto y:gy)
		if(!mm.count(mp(x,y))){
			cout<<mxx+mxy<<endl;
			return 0;
		}
	cout<<mxx+mxy-1<<endl;
	return 0;
}


Measured memory_bytes: 28460
# coding: utf-8
# Your code here!
s=list(input())
ss=set(s)
flg=0
if len(ss)!=2:
    flg=1
ss=list(ss)
for i in ss:
    cnt=s.count(i)
    if cnt!=2:
        flg=1

if flg==0:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main() {
    int N, X;
    cin >> N;
    cin >> X;
    int L[N];
    for (int i = 0; i < N; i++) cin >> L[i];
    int count = 1;
    int boal = 0;

    for(int i = 0; i < N; i++) {
        boal += L[i];
        if(boal > X) break;
        count++;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include<string>
#include<vector>
std::string minus2(long long n, int i = 40, bool padding = false) {
  static std::vector<long long> power = {1}, sum = {1, 2};
  while(int(power.size()) <= i) power.emplace_back(power.back() << 1);
  while(int(sum.size()) < i) sum.emplace_back(sum[sum.size() - 2] + power[sum.size()]);
  if(i < 0) return "";
  if(n == 0) return (padding ? std::string(i + 1, '0') : "0");
  if(i & 1) {
    if(i && sum[i - 1] < n + power[i]) return (padding ? "0" : "") + minus2(n, i - 1, padding);
    return "1" + minus2(n + power[i], i - 1, true);
  } else {
    if(n - power[i] < -sum[i - 1]) return (padding ? "0" : "") + minus2(n, i - 1, padding);
    return "1" + minus2(n - power[i], i - 1, true);
  }
}

#include<bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  cout << minus2(N) << endl;
}


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

#define MAX 7368792
int n, m;

int main() {
	cin >> m >> n;
	while (n != 0 || m != 0) {
		bool f[MAX] = {};
		
		int i = m;
		while(1){
			if (!f[i]) {
				if (n > 0) {
					n--;
					for (int j = i; j < MAX; j += i) {
						f[j] = true;
					}
				}
				else {
					cout << i << endl;
					break;
				}
			}
			i++;
		}

		cin >> m >> n;
	}
	
	return 0;
}

Measured memory_bytes: 10260
package main

import (
	"fmt"
)

func main() {
	var a, b, d, r int64

	fmt.Scanf("%d", &a)
	fmt.Scanf("%d", &b)
	d = a / b
	r = a % b
	A := float64(a)
	B := float64(b)
	f := A / B
	fmt.Printf("%d %d %.5f", d, r, f)

}



Measured memory_bytes: 1156
#include<iostream>
#include<cstdio>
using namespace std;
int n,a,b,cnt=0,id=0,ne[100005],in[100005],out[100005],cnt1,cnt2,fa[100005][20],len[100005];
struct node{
    int v,next;
}edge[400005];
inline int read(){
	char c=getchar();
	int x=0;
	for(;c>'9'||c<'0';) c=getchar();
	for(;c>='0'&&c<='9';){
		x=(x<<3)+(x<<1)+c-'0';
		c=getchar();
	}
	return x;
}
inline void add(int u,int v){
    edge[cnt]={v,ne[u]};
    ne[u]=cnt++;
    edge[cnt]={u,ne[v]};
    ne[v]=cnt++;
}
inline void dfs(int cur,int pre,int d){
    fa[cur][0]=pre;
    len[cur]=d;
    for(int i=1;i<20;i++)
        fa[cur][i]=fa[fa[cur][i-1]][i-1];
    in[cur]=++id;
    for(int i=ne[cur];i!=-1;i=edge[i].next){
        int v=edge[i].v;
        if(v==pre) continue;
        dfs(v,cur,d+1);
    }
    out[cur]=id;
}
int main(){
	n=read();
    for(int i=0;i<100005;i++) ne[i]=-1;
    for(int i=1;i<n;i++){
    	a=read(),b=read();
        add(a,b);
    }
    dfs(1,0,0);
    int tmp=(len[n]-1)>>1,now=n;
    for(int i=0;i<20;i++)
        if(tmp>>i&1) now=fa[now][i];
    cnt1=n-(out[now]-in[now]+1)-len[n]/2-1,cnt2=out[now]-in[now]+1-tmp-1;
    if(len[n]&1){
        if(cnt1<=cnt2) puts("Snuke");
        else puts("Fennec");
        return 0;
    }
    if(cnt2>cnt1) puts("Snuke");
    else puts("Fennec");
    return 0;
}

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

#define i64 long long int

i64 id;

int main() {
	cin>>id;
	
	int dig = 1;
	i64 cap = 26LL;
	while(cap < id) {
		id -= cap;
		
		dig++;
		cap *= 26;
	}
	
	for(int i=dig;i>0;i--) {
		cap /= 26;
		char ch = 'a';
		while(id > cap) {
			id -= cap;
			ch++;
		}
		cout<<ch;
	}
	cout<<endl;
	
	return 0;
}

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

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

  int l[N];
  int r[N];

  for(i=0;i<N;i++){
    cin >>l[i]>>r[i];
  }
 int total=0;
  for(i=0;i<N;i++){
    total+=(r[i]-l[i]+1);
  }
  cout<<total<<endl;
}


Measured memory_bytes: 256
package main

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

func main() {
	var n int
	fmt.Scan(&n)

	ns := make([][]int, 60)
	for i := range ns {
		ns[i] = []int{0, 0}
	}

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())
		for j := 0; j < 60; j++ {
			if a&(1<<uint(j)) > 0 {
				ns[j][1]++
			} else {
				ns[j][0]++
			}
		}
	}

	const mod int = 1e9 + 7
	var sum int
	mul := 1
	for i := range ns {
		cur := (ns[i][1] * ns[i][0]) % mod
		cur = (cur * mul) % mod
		sum = (sum + cur) % mod
		mul = (mul * 2) % mod
	}

	fmt.Println(sum)
}


Measured memory_bytes: 7572
import java.util.*;


public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ！！

        Scanner sc = new Scanner(System.in);
        int line = sc.nextInt();
      if(line==3||line==5||line==7)
        System.out.println("YES");
      else System.out.println("NO");
    }
}

Measured memory_bytes: 21588
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}

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

  int h, w; cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];

  int cnt1[h][w] = {}, cnt2[h][w] = {}, cnt3[h][w] = {}, cnt4[h][w] = {};

  for (int i = 0; i < h; ++i) {
    int cur = 0;
    for (int j = 0; j < w; ++j) {
      if (s[i][j] == '#') cur = 0;
      else ++cur;
      cnt1[i][j] = cur;
    }
  }

  for (int i = 0; i < h; ++i) {
    int cur = 0;
    for (int j = w - 1; j >= 0; --j) {
      if (s[i][j] == '#') cur = 0;
      else ++cur;
      cnt2[i][j] = cur;
    }
  }

  for (int i = 0; i < w; ++i) {
    int cur = 0;
    for (int j = 0; j < h; ++j) {
      if (s[j][i] == '#') cur = 0;
      else ++cur;
      cnt3[j][i] = cur;
    }
  }

  for (int i = 0; i < w; ++i) {
    int cur = 0;
    for (int j = h - 1; j >= 0; --j) {
      if (s[j][i] == '#') cur = 0;
      else ++cur;
      cnt4[j][i] = cur;
    }
  }

  int ans = 0;

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (s[i][j] == '#') continue;
      chmax(ans, cnt1[i][j] + cnt2[i][j] + cnt3[i][j] + cnt4[i][j] - 3);
    }
  }

  print(ans);

  return 0;
}

Measured memory_bytes: 67072
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    bool ora = 0;
    if(S[0] == S[1]||S[1] == S[2]||S[2] == S[3])ora = 1;
    if(ora){
        cout << "Bad" << "\n";
    }else{
        cout << "Good" << "\n";
    }
}

Measured memory_bytes: 256
from random import randrange

import sys
input = sys.stdin.readline
from collections import deque
h,w = map(int,input().split())
ch,cw = map(int,input().split())
dh,dw = map(int,input().split())
s = [list(input()) for _ in range(h)]
# h,w=1000,1000
# ch,cw=3,3
# dh,dw=8,8
# s=[]
# for _ in range(h):
#     row=[]
#     for j in range(w):
#         row.append("#."[randrange(2)])
#     s.append(row)
# s[ch-1][cw-1]="."
# s[dh-1][dw-1]="."
# for row in s:print(row)

INF=10**7

queue = deque()

cost = [[INF]*w for _ in range(h)]
cost[ch-1][cw-1]=0

dxdy = [[1,0],[-1,0],[0,1],[0,-1]]
warp = []
for m in range(-2,3):
    for n in range(-2,3):
        if [m,n] not in [[0,0],[1,0],[-1,0],[0,1],[0,-1]]:
            warp += [[m,n]]

queue.append([ch-1,cw-1,0])

while queue:
    x,y,d = queue.popleft()
    # if d>cost[x][y]:continue
    for dx,dy in dxdy:
        nx,ny = x+dx,y+dy
        if -1<nx<h and -1<ny<w and s[nx][ny]!="#" and d<cost[nx][ny]:
            cost[nx][ny]=d
            queue.appendleft([nx,ny,d])
            #[print(*cost[l]) for l in range(h)]
            #print("---------------")

    for dx,dy in warp:
        nx,ny = x+dx,y+dy
        if -1<nx<h and -1<ny<w and s[nx][ny]!="#" and d+1<cost[nx][ny]:
            cost[nx][ny]=d+1
            queue.append([nx,ny,d+1])
            #[print(*cost[l]) for l in range(h)]
            #print("---------------")


if cost[dh-1][dw-1]<INF:
    print(cost[dh-1][dw-1])
else:
    print(-1)



Measured memory_bytes: 170812
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int h, w, d;
	scanf("%d %d %d", &h, &w, &d);
	int e=0;
	while(d%2==0){
		d/=2;
		e++;
	}
	char c[500][500];
	if(e==0){
		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				if((i+j)%2==0) c[i][j]='R';
				else c[i][j]='Y';
			}
		}
	}else{
		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				int i0=i, j0=j;
				if((i0+j0)%2==1) i0--;
				if(((i0+j0)%(1<<(e+1)))<(1<<e) && ((i0-j0%(1<<(e+1))+(1<<(e+1)))%(1<<(e+1)))<(1<<e)){
					c[i][j]='R';
				}else if(((i0+j0)%(1<<(e+1)))<(1<<e) && ((i0-j0%(1<<(e+1))+(1<<(e+1)))%(1<<(e+1)))>=(1<<e)){
					c[i][j]='Y';
				}else if(((i0+j0)%(1<<(e+1)))>=(1<<e) && ((i0-j0%(1<<(e+1))+(1<<(e+1)))%(1<<(e+1)))<(1<<e)){
					c[i][j]='G';
				}else{
					c[i][j]='B';
				}
			}
		}
	}
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			cout<<c[i][j];
		}
		cout<<endl;
	}
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
   int a , b , c ;

   cin >> a;
   cin >> b;
   cin >> c;

   if (a<b&&b<c){
  cout << a << " " <<  b << " " << c;

} else if(a<c&&c<b){
  cout<< a << " " <<  c  << " " << b;
  
}else if(b<a&&a<c){
  cout<< b<< " " << a << "" <<c;
  
}else if(b<c&&c<a){
  cout<< b << " " << c << " " << a;
  
}else if(c<a&&a<b){
cout<< c << " " << a << " " << b;
  
}else if(c<b&&b<a){
 cout<< c << " " << b << " " << a;
 

}else if(a==b&&b<c){
  cout<< a << " " << b << " " << a;
  
}else if(a==b&&b>c){
cout<< c << " " << a << " " << b;
  
}else if(a==c&&c<b){
 cout<< a  << " " <<  c << " " << b;
 
}else if(a==c&&c>b){
 cout<< b  << " " <<  a << " " << c;

}else if(c==b&&b<a){
 cout<< c  << " " <<  b << " " << a;
 
}else if(c==b&&b>a){
 cout<< a  << " " <<  b << " " << c;
 
}else if(a==b&&b==c){
 cout<< a << " " <<  b << " " << c;

} 
   cout << endl;  
}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#undef int
#define INF 1000000009
#define INFL 1000000000000000018ll
#define mod 1000000007ll
#define pb push_back
#define fi first
#define se second
#define mk make_pair
typedef pair<int, int> PA;
typedef priority_queue<int> PQ;
typedef priority_queue<PA, vector<PA>, greater<PA> >PQG;

int N;
double a[1010];

signed main()
{
    cin >> N;
    double sum = 0;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        sum += a[i];
    }
    sum /= (double)N;
    double diff = (double)INF;
    int ind = 0;
    for(int i = 0; i < N; i++){
        if(abs(sum - a[i]) < diff){
            ind = i;
            diff = abs(sum - a[i]);
        }
    }
    cout << ind << endl;


    return 0;
}
/*


*/


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

using namespace std;

int main(){
	int n, x ,t;
	cin >> n >> x >> t;
	if (n % x == 0)
		cout <<  (n / x) * t << "\n";
	else
		cout << (floor(n/x) + 1) * t << "\n";
	return 0;
}


Measured memory_bytes: 3760
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
s=s0()
n=len(s)

L=[]
R=[]
for i in range(n):
    if s[i]=="L":
        L.append(i)
    else:
        R.append(i)

ans=[0]*n
for i in range(n):
    if s[i]=="R":
        j=L[bisect_right(L,i)]
        if (j-i)%2==1:
            ans[j-1]+=1
        else:
            ans[j]+=1
    else:
        j=R[bisect_right(R,i)-1]
        if (i-j)%2==1:
            ans[j+1]+=1
        else:
            ans[j]+=1
print(*ans)

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);

class Graph {
  protected:
    int vertex;

    Graph(int v) {
      vertex = v;
    }
};

struct Edge {
  int to;
  int cost;
};

class AdjacentListGraph : public Graph {
  protected:
    std::vector<std::vector<Edge> > list;
  public:
    AdjacentListGraph(int v): Graph(v) {
      list.resize(vertex);
    }

    virtual void push(int from, int to, int cost) = 0;
};

class MST : public AdjacentListGraph {
  private:
    std::vector<long long> key;
    std::vector<int> prev;

  public:
    long long inf = LLONG_MAX / 3;

    MST(int v);

    void push(int from, int to, int cost);

    void prim(int root);
    int total_weight();
};

MST::MST(int v): AdjacentListGraph(v) {
  key.resize(vertex);
  prev.resize(vertex);
  for (int i = 0; i < vertex; ++i) {
    key[i] = inf;
    prev[i] = -1;
  }
}

void MST::prim(int root = 0) {
  key[root] = 0;

  std::priority_queue<std::pair<long long, int>, std::vector<std::pair<long long, int> >, std::greater<std::pair<long long, int> > > pq;

  std::vector<bool> done(vertex, false);

  pq.push(std::make_pair(key[root], root));

  while (!pq.empty()) {
    int v = pq.top().second;
    pq.pop();

    done[v] = true;

    for (int i = 0; i < (int)list[v].size(); ++i) {
      Edge e = list[v][i];
      if (!done[e.to] && e.cost < key[e.to]) {
        key[e.to] = e.cost;
        prev[e.to] = v;
        pq.push(std::make_pair(key[e.to], e.to));
      }
    }
  }
}

void MST::push(int from, int to, int cost) {
  Edge e;
  e.to = to;
  e.cost = cost;
  list[from].push_back(e);
  e.to = from;
  list[to].push_back(e);
}

int MST::total_weight() {
  int total = 0;
  for (long v: key) {
    total += v;
  }
  return total;
}

int main() {
  
  int v;
  int e;

  scanf("%d %d", &v, &e);

  MST g = MST(v);

  int from, to, cost;

  for (int i = 0; i <  e; i++) {
    scanf("%d %d %d", &from, &to, &cost);
    g.push(from, to, cost);
  }

  g.prim();
  int weight = g.total_weight();
  printf("%d\n", weight);
}



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

int main(){
    int n,Tpoint = 0,Hpoint = 0;
    string Taro,Hanako;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> Taro >> Hanako;
        if (Taro > Hanako)
        {
            Tpoint += 3;
        }else if (Taro < Hanako){
            Hpoint += 3;
        }else if (Taro == Hanako)
        {
            Tpoint++;Hpoint++;
        }
    }
    cout << Tpoint << " " << Hpoint << endl;
return 0;
}


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

int main(){
  int a, b, value;
  char op;
  
  while(1){
    cin >> a >> op >> b;
    
    if(op == '?') break;
    
    switch (op) {
      case '+' : value = a + b; break;
      case '-' : value = a - b; break;
      case '*' : value = a * b; break;
      case '/' : value = a / b; break;
    }
    cout << value << endl;
  }
  return 0;
}

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

using namespace std;

int n, m, a, b, ans;
int vis[10];
vector <int> V[10];

void tap(int x)
{
	vis[x] = 1, a++;
	if(a == n) {
		ans++;
		return;
	}
	for(int i=0; i < V[x].size(); i++)
		if(vis[V[x][i]] == 0)
			tap(V[x][i]), a--, vis[V[x][i]] = 0;
}

int main()
{
	cin >> n >> m;
	
	for(int i=1; i <= m; i++)
		cin >> a >> b, V[a].push_back(b), V[b].push_back(a);
	
	a = 0, vis[1] = 1, tap(1);
	
	cout << ans;
}

Measured memory_bytes: 256