akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const double pi = acos(-1.0);


int n, x, m;
VI l, r, s;

VI vec, ans;
int asum = -1;

void check() {
	bool ret = true;
	rep(i, m) {
		int sum = 0;
		for (int j = l[i]; j <= r[i]; j++) { sum += vec[j]; }
		if (sum != s[i])ret = false;
	}

	if (ret) {
		int sum = accumulate(all(vec), 0);
		if (asum < sum) {
			ans = vec;
			asum = sum;
		}
	}
}

void dfs(int d) {
	if (d == n) {
		check();
	}
	else {
		rep(i, x + 1) {
			vec[d] = i;
			dfs(d + 1);
		}
	}
}

int main() {
	cin >> n >> x >> m;
	l = VI(m);
	r = VI(m);
	s = VI(m);
	rep(i, m) { cin >> l[i] >> r[i] >> s[i]; l[i]--; r[i]--; }

	vec = VI(n);
	rep(i, x + 1)dfs({});

	if (asum == -1) {
		Cout(-1);
	}
	else {
		rep(i, n)cout << ans[i] << (i == n - 1 ? "\n" : " ");
	}
}


Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N; int K;
  cin>>N>>K;
  vector<long long> S(N);
  for(int i=0; i<N; i++){
    cin>>S.at(i);
  }
for(int i=K; i<N; i++){
  if(S.at(i)>S.at(i-K))
    cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
}

Measured memory_bytes: 4828
(let* ((n (read))
       (m (read))
       (h (make-array n :element-type 'fixnum :initial-contents (loop :repeat n :collect (read))))
       (ans (make-array n :element-type 'fixnum :initial-element 0)))
  (loop :repeat m :do (funcall (lambda (x y)
                                 (cond ((< (aref h x) (aref h y))
                                        (incf (aref ans x)))
                                       ((> (aref h x) (aref h y))
                                        (incf (aref ans y)))
                                       ((= (aref h x) (aref h y))
                                        (incf (aref ans x))
                                        (incf (aref ans y)))))
                               (1- (read)) (1- (read))))
  (princ (count 0 ans)))

Measured memory_bytes: 80444
import sys
N = int(input())
input_list = input().split()
result = 1
max = 10 ** 18
if '0' in input_list:
    print(0)
else:
    for i in input_list:
        result *= int(i)
        if result > max:
            print(-1)
            sys.exit(0)
    print(result)

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

ll MOD = 1000000007;

int main() {
    ll n, m;
    cin >> n >> m;
    if (abs(n-m)>1) {
        cout << 0;
        return 0;
    }
    vector<ll> facts(100001);
    facts[0] = 1;
    for (ll i=1; i<=100000; i++) facts[i] = facts[i-1]*i%MOD;
    ll res = facts[n]*facts[m];
    if (n==m) res*=2;
    res%=MOD;
    cout << res;
    return 0;
}

Measured memory_bytes: 3988
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int a,b,c,d,t,k,n,o,x,y,z;
    cin>>n>>a>>b>>c>>d;
    if(n%a==0){
        x=n/a;
    }
    else if(n%a>0){
        x=n/a+1;
    }
    if(n%c==0){
        y=n/c;
    }
    else if(n%c>0){
        y=n/c+1;
    }
    z=min(x*b,y*d);
    cout<<z<<endl;
}



Measured memory_bytes: 3116
fn main() {
	use std::io::Read;
	let mut s = String::new();
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let h: Vec<u8> = s.map(|a| a.parse().unwrap()).collect();
	let mut max = 0;
	let mut ans = 0;
	for i in 0..h.len() {
		if h[i] >= max {
			ans += 1;
			max = h[i];
		}
	}
	println!("{}", ans);
}


Measured memory_bytes: 4352
#include<stdio.h>
int main(void)
{
	int a,b,c,k,sa1,sa2,sum;
	scanf("%d %d %d %d",&a,&b,&c,&k);
	sa1=k-a;
	if(sa1<0){
		sa1=0;
	}
	sum=0;
	sum+=k-sa1;
	if(sa1>=1){
		sa2=sa1-b;
		if(sa2>=1){
			sum-=sa2;
		}
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 1680
import java.io.*;
 
class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        int h = Integer.parseInt(br.readLine());
        StringBuilder sb = new StringBuilder();
        int a,b;
        for(int i=0 ;i<h ;i++){
            String[] str1 = br.readLine().split(" ");
            a = Integer.parseInt(str1[1]);
            b = Integer.parseInt(str1[2]);
            if(str1[0].equals("reverse")){
                sb.append(str.substring(a,b+1));
                String x = sb.reverse().toString();
                sb.setLength(0);
                sb.append(str);
                sb.replace(a,b+1,x);
                str = sb.toString();
                sb.setLength(0);
            }
            if(str1[0].equals("replace")){
                sb.append(str);
                sb.replace(a,b+1,str1[3]);
                str = sb.toString();
                sb.setLength(0);
            }
            if(str1[0].equals("print")){
                System.out.println(str.substring(a,b+1));
            }
        }
    }
}

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

int findSumOfDigits( int n ) {
  int sum = 0;
  while(n > 0){
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main(){
  int n, a, b;
  cin >> n >> a >> b;
  int total = 0;
  for( int i = 0; i <= n; ++i ){
    int sum = findSumOfDigits(i);
    if(sum >= a && sum <= b) {
      total += i;
    }
  }
  cout << total << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int A = sc.nextInt();
 
      if(X < A){
    System.out.println("0");
      }else{
	System.out.println("10");
      }
      }
}


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


import sys
def query(i,j):
    print("? {0} {1}".format(i, j))
    sys.stdout.flush()
    return int(input())

n,c = list(map(int, input().split()))
ds = [None]*c
cs = [None]*n
for i in range(c):
    ds[i] = list(map(int, input().split()))
for i in range(n):
    cs[i] = list(map(lambda x : int(x)-1, input().split()))
from itertools import product
ans = float("inf")
v0 = [0]*c
v1 = [0]*c
v2 = [0]*c
for i,j in product(range(n), range(n)):
    if (i+j)%3==0:
        v = v0
    elif (i+j)%3==1:
        v = v1
    else:
        v = v2
    for cc in range(c):
        v[cc] += ds[cs[i][j]][cc]
for c0,c1,c2 in product(range(c), range(c), range(c)):
    if c0==c1 or c0==c2 or c1==c2:
        continue
    val = v0[c0] + v1[c1] + v2[c2]
    ans = min(ans, val)
print(ans)

Measured memory_bytes: 76696
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        for (int i = 9; i >= 1; i--) {
            if(n%i == 0&&n/i<=9){
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}


Measured memory_bytes: 23764
#include <iostream>
using namespace std;
int main(void){
  int N;
  cin >> N;
  bool waru = false;
  if(N == 7){
    waru = true;
  }
  while(true){
    if(N % 4 == 0){
      waru = true;
      break;
    }
    N -= 7;
    if(N < 4){
      break;
    }
    
  }
  if(waru){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

int main()
{
    ll x, y;
    cin >> x >> y;
    int ans = 0;
    while((__int128_t)x <= (__int128_t)y){
        x *= 2;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int findNextSectionIndex(vector<int> &a, int sectionIndex) {
  int diff = 0;
  for (int i = sectionIndex; i < (a.size() - 1); i++) {
    int newDiff = a.at(i + 1) - a.at(i);

    if (diff > 0 && newDiff < 0 || diff < 0 && newDiff > 0) {
      int newSectionIndex = i + 1;
      return newSectionIndex;
    }
    if (newDiff != 0) {
      diff = newDiff;
    }
  }
  return a.size();
}

int main() {
  int N;
  cin >> N;
  vector<int> a = vector<int>(N);
  for (int i = 0; i < a.size(); i++) {
    cin >> a.at(i);
  }

  int index = 0;
  int count = 0;
  while (index < a.size()) {
    index = findNextSectionIndex(a, index);
    count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(x)     (x).begin() , (x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl       '\n'
#define MAX        1000000
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
typedef long long int ll;
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}


const ll mod = 1e9+7;
const double eps = 1e-9;
const double pi = acos(-1);


const int maxN=102;
int arr[maxN];
int n;

ll cost(int e) {
    ll c=0;
    for(int i=0;i<n;++i) {
        c+=(arr[i]-e)*(arr[i]-e);
    }
    return c;
}

void solve(){
    string s;
    cin>>s;
    int arr[26];
    memset(arr,0,sizeof(arr));
    for(char i:s) {
        arr[i-'a']++;
    }
    for(int i:arr)if(i&1) {
        cout<<"No";
        return;
    }
    cout<<"Yes";
}





int main(){
    fastio
    int test=1;
    while(test--)
        solve();
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  ll a[n];

  rep(i, n) { cin >> a[i]; }

  ll ans = 0;
  rep(i, 60) {
    ll x = 0;
    rep(j, n) if (a[j] >> i & 1) x++;
    ll now = x * (n - x) % MOD;
    rep(k, i) { now = now * 2 % MOD; }
    ans += now;
    ans %= MOD;
  }

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


Measured memory_bytes: 2560
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int times(int x, int k) {
    int ret = 0;
    while (x < k) {
        x *= 2;
        ret++;
    }
    return ret;
}

int main(void) {
    int n, k;
    cin >> n >> k;

    double ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += pow(0.5, times(i, k)) / n;
    }
    cout << setprecision(30) << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int res[200000];

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

Measured memory_bytes: 3960
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;

using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
	public Program() { }

	static void Main(string[] args)
	{
		new Program().prog();
	}
	Scanner cin;
	const int MOD = 1000000007;
	const int INF = int.MaxValue;
	const long INFL = long.MaxValue;
	const double EPS = 1e-7;
	const double PI = 3.1415926536;

	int[] p = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101 };

	int MAX = 1000000000;

	void prog()
	{
		cin = new Scanner();
		int[,] dir8 = new int[8, 2] { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } };
		int[,] dir4 = new int[4, 2] { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };

		string str = cin.next();
		int num = 0;
		for (int i = 1; i < str.Length; i++)
		{
			if (str[i - 1] != str[i]) num++;
		}
		Console.WriteLine(num);
	}
}

class Scanner
{
	string[] s;
	int i;

	char[] cs = new char[] { ' ' };

	public Scanner()
	{
		s = new string[0];
		i = 0;
	}

	public string next()
	{
		if (i < s.Length) return s[i++];
		string st = Console.ReadLine();
		while (st == "") st = Console.ReadLine();
		s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
		i = 0;
		return next();
	}

	public int nextInt()
	{
		return int.Parse(next());
	}

	public long nextLong()
	{
		return long.Parse(next());
	}

	public double nextDouble()
	{
		return double.Parse(next());
	}
}

Measured memory_bytes: 3672
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	if (a > 12)
	{
		cout << b;
	}
	else if (a > 5)
	{
		cout << b / 2;
	}
	else
	{
		cout << 0;
	}

}

Measured memory_bytes: 256
#include<stdio.h>
#define max(a,b)            (((a) > (b)) ? (a) : (b))
#define INF 100005
int L[INF];
int main(){
	int n,P=-INF,k,ave=0;//n货个数；P要求；ave均；wei一车量；numb装车量
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;++i){
		scanf("%d",L+i);
		ave+=L[i];
		if(L[i]>P) P=L[i];}
	ave/=k;
	P=max(ave,P);
	while(1){
		int numb=0,i=0,wei=0;
		for(;i<n;){
			if(wei+L[i]<P) wei+=L[i],++i;
			else if(wei+L[i]==P) wei=0,numb++,i++;
			else wei=0,numb++;}
		if(i==n&&wei<P&&wei!=0) numb++;
		if(numb<=k) break;
		else P++;}
	printf("%d\n",P);

	return 0;
}


Measured memory_bytes: 2184
n = int(input())
s = [None] * n
for i in range(n):
    x, l = map(int, input().split())
    s[i] = x-l, x+l

s.sort(key=lambda x: x[1])
ans, c = 0, -float("inf")

for l, r in s:
    if c > l: continue
    ans += 1
    c = r

print(ans)


Measured memory_bytes: 19084
#!/usr/bin/python3
# -*- coding: utf-8 -*-
k = int(input())
if k % 2 == 0:
    print(-1)
elif k % 5 == 0:
    print(-1)
else:
    c = 7
    count = 1
    while True:
        if c % k == 0:
            print(count)
            break
        else:
            c = (10 * c + 7) % k
            count += 1

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

int main(){
  ll a; double b;
  cin >> a >> b;
  ll aa = a;
  int bb = b*100+0.1;
  printf("%lld\n",(aa*bb)/100);
  return 0;
}


Measured memory_bytes: 3796
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
inline int read()
{
	int x;char c;
	while((c=getchar())<'0'||c>'9');
	for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0';
	return x; 
}
#define MN 300
#define MOD 1000000007
int f[MN+5][MN+5][MN+5];
vector< pair<int,int> > v[MN+5];
inline void rw(int&a,int b){if((a+=b)>=MOD)a-=MOD;}
int main()
{
	int n,m,l,r,i,j,k,ans=0;
	n=read();m=read();
	while(m--)l=read(),r=read(),v[r].push_back(make_pair(l,read()));
	f[0][0][0]=1;
	for(i=0;i<n;++i)
	{
		for(j=0;j<=i;++j)for(k=0;k<=j;++k)if(f[i][j][k])
			rw(f[i+1][j][k],f[i][j][k]),
			rw(f[i+1][i][k],f[i][j][k]),
			rw(f[i+1][i][j],f[i][j][k]);
		for(l=0;l<v[i+1].size();++l)for(j=0;j<=i;++j)for(k=0;k<=j;++k)
			if(1+(j>=v[i+1][l].first)+(k>=v[i+1][l].first)!=v[i+1][l].second)f[i+1][j][k]=0;
		if(i+1==n)for(j=0;j<=i;++j)for(k=0;k<=j;++k)rw(ans,f[i+1][j][k]);
	}
	printf("%d",ans);
}

Measured memory_bytes: 108800
#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;

int main()
{
	int A, B;
	cin >> A >> B;
	int ans = 0;
	if (A >= B) {
		ans += A;
		A--;
	}
	else {
		ans += B;
		B--;
	}
	if (A >= B) {
		ans += A;
		A--;
	}
	else {
		ans += B;
		B--;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 998244353LL;
typedef pair <int, int> P;

template <typename T>
class SegmentTree {
    using F = function<T(T, T)>;
    int n;
    F f;
    T t;
    vector <T> dat;
public:
    SegmentTree(F f, T t) : f(f), t(t) {}
    void init(int n_) {
        n = 1;
        while (n < n_) n <<= 1;
        dat.assign(n << 1, t);
    }
    void build(const vector <T> &v) {
        auto n_ = (int)v.size();
        init(n_);
        for (int i = 0; i < n_; i++) dat[n + i] = v[i];
        for (int i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
    }
    void set_val(int k, T x) {
        dat[k += n] = x;
        while (k >>= 1) dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]);
    }
    T query(int a, int b) {
        T vl = t, vr = t;
        for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
            if (l & 1) vl = f(vl, dat[l++]);
            if (r & 1) vr = f(dat[--r], vr);
        }
        return f(vl, vr);
    }
};

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

    int n;
    cin >> n;

    vector <P> xd(n);
    for (int i = 0; i < n; i++) cin >> xd[i].first >> xd[i].second;

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

    vector <int> x(n);
    for (int i = 0; i < n; i++) x[i] = xd[i].first;

    vector <int> nxt(n);
    for (int i = 0; i < n; i++) nxt[i] = i;

    auto f = [](int a, int b) { return max(a, b); };
    SegmentTree<int> seg(f, 0);
    seg.build(nxt);

    for (int i = n - 2; i >= 0; i--) {
        int idx = lower_bound(x.begin(), x.end(), x[i] + xd[i].second) - x.begin();
        int mx = seg.query(i, idx);
        seg.set_val(i, mx);
    }

    vector <ll> dp(n + 1, 1);
    for (int i = n - 1; i >= 0; i--) {
        dp[i] = dp[i + 1] + dp[seg.query(i, i + 1) + 1];
        dp[i] %= MOD;
    }

    cout << dp[0] << "\n";
    return 0;
}

Measured memory_bytes: 7040
#include<stdio.h>

int main(){
  int a,b,c;
  scanf("%d%d",&a,&b);
  if(a>b+1){
    c=2*a-1;
  }
  else if(b>a+1){
    c=b*2-1;
  }
  else
    c=a+b;
  printf("%d\n",c);
  return 0;
}
    


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
char m[302][302];
int ans[302][302];
int main() {
	int h, w, k;
	cin >> h >> w >> k;
	rep(i,h) rep(j,w) cin >> m[i][j];

	int num = 1;
	
	bool row1 = false;
	rep(i,h) {
		if (i == 0) {
			rep(j,w) {
				if (m[i][j] == '#') row1 = true;
			}
			if (!row1) continue;

			int cl = 0, num_stb = 0;
			while (cl < w)
			{
				if (m[i][cl] == '#') {
					if (num_stb > 0) num++;
					num_stb++;
				}
				ans[i][cl] = num;
				cl++;
			}
			num++;

		} else {
			bool berry = false;
			rep(j,w) {
				if (m[i][j] == '#') berry = true;
			}
			if (berry) {
				int cl = 0, num_stb = 0;;
				while (cl < w) 
				{
					if (m[i][cl] == '#') {
						if (num_stb > 0) num++;
						num_stb++;
					} 
					ans[i][cl] = num;
					cl++;
				}
				num++;
			} else {
				rep(j,w) ans[i][j] = ans[i-1][j];
			}
		}
	}
	int x;
	rep(j,w) {
		rep(i,h) {
			if (ans[i][j] > 0) {
				x = i;
				break;
			}
		}
		for (int i = x; i >= 1; i--) ans[i-1][j] = ans[i][j];
	}

	rep(i,h) {
		rep(j,w) {
			cout << ans[i][j];
			if (j < w-1) cout << " ";
		}
		cout << endl;
	}
	return 0;
}

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

#define FOR(i, a) for(int i=0;i<(int)a;++i)
typedef long long ll;
typedef long double ld;
using namespace std;

void solver() {
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        ld x1, x2, x3, x4, y1, y2, y3, y4;
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
        auto isOK = (y2 - y1) * (x4 - x3) == (y4 - y3) * (x2 - x1);
        if (isOK) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}

int main() {
    solver();
    return 0;
}

Measured memory_bytes: 3136
import java.io.*;

/**
 * Created by Ayushi on 01/09/2019.
 */

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String[] temp = r.readLine().split(" ");
        long n = Long.parseLong(temp[0]);
        r.close();
        int x;
        if (n%2 == 0) x = 1;
        else x = 0;
        long ans = (n/2)*(n-x);
        System.out.println(ans);
    }
}


Measured memory_bytes: 21332
import java.util.Scanner;


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

		int n = scan.nextInt();

		for(int i=0; i<n; i++){
		//1をa
		double x1 = scan.nextDouble();
		double y1 = scan.nextDouble();
		//2をb
		double x2 = scan.nextDouble();
		double y2 = scan.nextDouble();
		//3をc
		double x3 = scan.nextDouble();
		double y3 = scan.nextDouble();

		double a1 = 2*(x2 - x1);
		double b1 = 2*(y2 - y1);
		double c1 = Math.pow(x1, 2) - Math.pow(x2, 2) + Math.pow(y1, 2) - Math.pow(y2, 2);

		double a2 = 2*(x3 - x1);
		double b2 = 2*(y3 - y1);
		double c2 = Math.pow(x1, 2) - Math.pow(x3, 2) + Math.pow(y1, 2) - Math.pow(y3, 2);

		double xp = (b1*c2 - b2*c1)/(a1*b2 - a2*b1);
		double yp = (c1*a2 - c2*a1)/(a1*b2 - a2*b1);

		System.out.printf("%.3f %.3f %.3f\n",xp,yp,distance(x1, y1, xp, yp));


		//三角形の面積
		}
	}

	static double distance(double ax, double ay, double bx, double by){
		return Math.sqrt(Math.pow(bx-ax, 2) + Math.pow(by-ay, 2));
	}

}

Measured memory_bytes: 20544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define int ll
//const ll mod = 1000000007;

int n, k;
int t, d;
i_i dt[100001];
bool mem[100001];
vector<int> sushi;
signed main() {
    cin >> n >> k;
    for (int i=0;i<n;i++) {
        cin >> t >> d;
        dt[i] = make_pair(d, t);
    }

    sort(dt,dt+n,greater<i_i>());

    int sum = 0;
    int kind = 0;
    for (int i=0;i<k;i++) {
        sum += dt[i].first;
        if (mem[dt[i].second]) sushi.push_back(dt[i].first);
        else {
            mem[dt[i].second] = true;
            kind++;
        }
    }
    if (sushi.empty()) {
        cout << sum + kind*kind << endl;
        return 0;
    }
    int ans = sum + (kind*kind);
    for (int i=0;i<n;i++) {
        if (!mem[dt[i].second]) {
            mem[dt[i].second] = true;
            sum -= sushi.back(); sushi.pop_back();
            sum += dt[i].first;
            kind++;
            ans = max(ans, sum+(kind*kind));
            if (sushi.empty()) break;
        }
    }

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

// まず上からkこ食べる 種類を記録しておく
// 新しい種類の寿司は1個reserveしておく
// 一番価値のない寿司を一個減らしてまだ出ていない種類の寿司を食べる


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=500005,p=998244353;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int qpow(int x,int k){
	int t=1;
	for (;k;k>>=1){
		if (k&1) t=(ll)t*x%p;
		x=(ll)x*x%p;
	}
	return t;
}
int n,K,fac[N],inv[N],ans;
void check(int &x,int y){x=(x+y<p) ? (x+y) : (x+y-p);}
int C(int n,int m){return (ll)fac[n]*inv[m]%p*inv[n-m]%p;}
int calc(int n,int m,int x){
	if ((x<=0)||(x<=m-n)) return 0;
	if (x>m) return C(n+m,n);
	return (C(n+m,n)-C(n+m,n+x)+p)%p;
}
int calc(int R,int B){
	if ((R<B)||(R<n)) return 0;
	if (R==B) return calc(R,B-1,B-n+1);
	return calc(R,B,R-n+1);
}
int main(){
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	n=read();K=read();
	fac[0]=1;
	for (int i=1;i<=K;i++) fac[i]=(ll)fac[i-1]*i%p;
	inv[K]=qpow(fac[K],p-2);
	for (int i=K;i;i--) inv[i-1]=(ll)inv[i]*i%p;
	for (int i=0;i<=K;i++) check(ans,calc(i,K-i));
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4096
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner s = new Scanner(System.in)) {
			final int N = s.nextInt();
			final int AllA = s.nextInt() * N;
			final int B = s.nextInt();

			if(AllA < B) {
				System.out.println(AllA);
			} else {
				System.out.println(B);
			}
		}
	}
}


Measured memory_bytes: 22732
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

template<typename T> T In() { T v; cin >> v; return v; }

#define P(s) cout<<s<<endl
#define P2(b,y,f) P(((b)?y:f))
#define REP(i,b,e) for(auto i=b;i<e;++i)
#define ALL(con) con.begin(), con.end()

int main() {
    auto w = In<int>();
    auto h = In<int>();
    auto n = In<int>();
    int w0 = 0, h0 = 0;
    
    REP(i,0,n) {
        auto x = In<int>();
        auto y = In<int>();
        auto a = In<int>();
        
        switch (a) {
        case 1:
            w0 = max(w0, x);
            break;
        case 2:
            w = min(w, x);
            break;
        case 3:
            h0 = max(h0, y);
            break;
        case 4:
            h = min(h, y);
            break;
        }
    }
    
    P(max(0, h - h0) * max(0, w - w0));
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        System.out.println(str);
    }

    public static void main(String[] args) {

        long A;
        long B;


        try (Scanner sc = new Scanner(System.in)) {
            A = sc.nextLong();
            B = sc.nextLong();
        }
        long result = 1;

        long l = gcd(A,B);
        long t = (long) Math.sqrt(l) +1;
        for(long i =2; i <= t;i++){
            if(l % i != 0){
                continue;
            }

            result++;
            while(true){
                if(l%i == 0){
                    l = l/i;
                }else{
                    break;
                }
            }
        }
        if(l != 1){
            result++;
        }


        System.out.println(result);

    }
    //最大公約数
    static long gcd(long a, long b) {
        long temp;
        while ((temp = a % b) != 0) {
            a = b;
            b = temp;
        }
        return (long) b;
    }

}


Measured memory_bytes: 22608
/************************************/
/* NoobM							*/
/* File Name : atjp.cpp				*/
/* Date : 05.07.2020 18:00:02 +06	*/
/************************************/

#include <bits/stdc++.h>

#define rr(i, b)    for (int i = 0; i < int(b); i++)
#define vi(n, a) vector <long long> a(n); rr(i, n) cin >> a[i]
#define pvec(a) rr(i, a.size()) cout << a[i] << " "; cout << endl
#define bug(x) cout << #x << " " << x << endl
#define ll long long
#define vii vector <int>

using namespace std;

void solve() {
	/*int n, m;
	cin >> n >> m;
	
	string g[m];
	
	rr(i, n) {
		cin >> g[i];
	}*/
	
	int n;
	cin >> n;
	
	vi(n, a);
	
	sort(a.rbegin(), a.rend());
	
	ll c = 0;
	
	int counter = 0;
	int k = 0;
	for(int i = 0; i < n - 1; i++) {
		c += a[i - k];
		counter++;
		if(counter == 2) {
			counter = 0;
			k++;
		}
	}
	
	cout << c << endl;
}
 
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
	
	int t = 1;
	//cin >> t;
	
	while (t--) {
		solve();
	}
    return 0;
}


Measured memory_bytes: 4776
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

int n;

void gen(string s, char mx) {
	if ((int)s.size() == n) {
		cout << s << endl;
	} else {
		for (char c = 'a'; c <= mx + 1; c++) {
			s.push_back(c);
			gen(s, max(mx, c));
			s.pop_back();
		}
	}
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	cin >> n;
	gen("", 'a' - 1);
}

Measured memory_bytes: 1536
#include<stdio.h>
int search(char a[]){
	int i,score,box=0;
	for(i=0;;i++){
		if(a[i]=='\0')break;
		switch(a[i]){
			case 'm' :if(a[i-1]>='2'&&a[i-1]<='9'&&i!=0)box+=(a[i-1]-'0')*1000;else box+=1000;break;
			case 'c' :if(a[i-1]>='2'&&a[i-1]<='9'&&i!=0)box+=(a[i-1]-'0')*100;else box+=100;break;
			case 'x' :if(a[i-1]>='2'&&a[i-1]<='9'&&i!=0)box+=(a[i-1]-'0')*10;else box+=10;;break;
			case 'i' :if(a[i-1]>='2'&&a[i-1]<='9'&&i!=0)box+=(a[i-1]-'0')*1;else box+=1;;break;
		}
	}
	return box;
}
int main(void){
	int n,i,j,flag,box;
	char mcxi1[10],mcxi2[10],ans[10];
	scanf("%d",&n);
	while(n--){
		for(i=0;i<10;i++){mcxi1[j]='\0';mcxi2[j]='\0';ans[i]='\0';}
		flag=0;
		scanf("%s%s",mcxi1,mcxi2);
		box=search(mcxi1);
		box+=search(mcxi2);
		for(i=0;i<10;i++){
			if(ans[i]=='\0'){
				if(box/1000>1&&flag<1){ans[i]='0'+box/1000;ans[i+1]='m';box-=1000*(box/1000);flag=1;}
				else if(box/1000>0&&flag<1){ans[i]='m';box-=1000;flag=1;}
				else if(box/100>1&&flag<2){ans[i]='0'+box/100;ans[i+1]='c';box-=100*(box/100);flag=2;}
				else if(box/100>0&&flag<2){ans[i]='c';box-=100;flag=2;}
				else if(box/10>1&&flag<3){ans[i]='0'+box/10;ans[i+1]='x';box-=10*(box/10);flag=3;}
				else if(box/10>0&&flag<3){ans[i]='x';box-=10;flag=3;}
				else if(box>1&&flag<4){ans[i]='0'+box;ans[i+1]='i';flag=4;}
				else if(box>0&&flag<4){ans[i]='i';flag=4;}
			}
			if(flag==4)break;
		}
		printf("%s\n",ans);
	}
	return 0;
}

Measured memory_bytes: 584
using System;

class Program
{
    static void Main()
    {
        string[] a = Console.ReadLine().Split(' ');
        int[] ans = new int[int.Parse(a[2])];
        int[] person = new int[int.Parse(a[0])];
        string[] ret = new string[int.Parse(a[0])];
        for (int i = 0; i < ans.Length; i++)
        {
            ans[i] = 0;
        }
        for (int i = 0; i < int.Parse(a[2]); i++)
        {
            person[int.Parse(Console.ReadLine()) - 1] ++;
        }

        for (int i = 0; i < int.Parse(a[0]); i++)
        {
            if ((int.Parse(a[1]) + person[i] - int.Parse(a[2])) > 0)
            {
                ret[i] = "Yes";
            }
            else
            {
                ret[i] = "No";
            }

        }
        foreach (var item in ret)
        {
            Console.WriteLine(item);
        }
    }
}


Measured memory_bytes: 20956
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll k, s;std::cin >> k >> s;
  ll c = 0;
  for(int i=0;i<=k;i++){
    for(int j=0;j<=k;j++){
      ll t = s - i - j;
      if(t>=0&&t<=k) c++;
    }
  }
  std::cout << c << '\n';
  return 0;
}


Measured memory_bytes: 888
n = int(input())
a = [(int(x), int(y)) for x, y in zip(input().split(), range(n))]
a.sort(reverse=True)

dp = [[0]*(n+1) for i in range(n+1)]
for i in range(n+1):
  for j in range(n+1-i):
    if i == 0 and j == 0:
      continue
    if i == 0:
      dp[i][j] = dp[i][j-1]+a[i+j-1][0]*abs(a[i+j-1][1]-j+1)
      continue
    if j == 0:
      dp[i][j] = dp[i-1][j]+a[i+j-1][0]*(n-i-a[i+j-1][1])
      continue
    dp[i][j] = max([dp[i][j-1]+a[i+j-1][0]*abs(a[i+j-1][1]-j+1), dp[i-1][j]+a[i+j-1][0]*(n-i-a[i+j-1][1])])

ans = 0
for i in range(n+1):
  key = dp[n-i][i]
  if ans < key:
    ans = key

print(ans)

Measured memory_bytes: 100428
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
using namespace std;

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

  vector<int> a(N);
  rep(i, 0, N) {
    cin >> a.at(i);
  }

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

  cout << a.back() - a.front() << endl;
}


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

using namespace std;

const int INF = 1e7;
int Cost[101][101], DpMoney[11][101];
bool Used[11][101];


void solve(int ticket, int n, int start) {
	int u, v;

	for (int i = 0; i < 11; ++i) {
		fill(DpMoney[i], DpMoney[i] + 101, INF);
		fill(Used[i], Used[i] + 101, false);
	}

	DpMoney[0][start] = 0;
	while (true) {
		u = -1;
		for (int i = 0; i <= ticket; ++i) {
			for (int j = 1; j <= n; ++j) {
				if (!Used[i][j] && (u == -1 || DpMoney[i][j] < DpMoney[u][v])) {
					u = i;
					v = j;
				}
			}
		}
		if (u == -1) {
			break;
		}
		Used[u][v] = true;

		for (int k = 1; k <= n; ++k) {
			DpMoney[u][k] = min(DpMoney[u][k], DpMoney[u][v] + Cost[v][k]);
			if (u + 1 <= ticket) {
				DpMoney[u + 1][k] = min(DpMoney[u + 1][k], DpMoney[u][v] + Cost[v][k] / 2);
			}
		}
	}
	
}

int main() {
	int c, n, m, s, d, a, b, f;

	while (cin >> c >> n >> m >> s >> d, c) {
		for (int i = 0; i < 101; ++i) {
			fill(Cost[i], Cost[i] + 101, INF);
		}
		for (int i = 0; i < m; ++i) {
			cin >> a >> b >> f;
			Cost[a][b] = f;
			Cost[b][a] = f;
		}
		solve(c, n, s);
		f = INF;
		for (int i = 0; i <= c; ++i) {
			f = min(f, DpMoney[i][d]);
		}
		cout << f << endl;
	}

	return 0;
}


Measured memory_bytes: 3168
# -*- coding: utf-8 -*-
import sys
from collections import Counter
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    A=list(map(int,input().split()))
    c=Counter(A)
    if N%2:
        if not (0 in c and c[0]==1):
            print(0)
            exit()
        for k in range(2,N,2):
            if not (k in c and c[k]==2):
                print(0)
                exit()
    else:
        for k in range(1,N,2):
            if not (k in c and c[k]==2):
                print(0)
                exit()
    print(pow(2,N//2,MOD))

if __name__ == '__main__':
    main()


Measured memory_bytes: 55916
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;cin>>N;string S;cin>>S;
    S='E'+S+'W';
    vector<int>E(N+2);
    int count=0;
    for(int i=0;i<N+2;i++){
        if(S[i]=='E')count++;
        E[i]=count;
    }
    int ans=600000;
    for(int i=1;i<N+1;i++){
        ans=min(ans,i-E[i-1]+count-E[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1888
#include <bits/stdc++.h>
using namespace std;
int main(){
    int D;
    cin >> D;
    if(D == 25) cout << "Christmas" << endl;
    else if(D == 24) cout << "Christmas Eve" << endl;
    else if(D == 23) cout << "Christmas Eve Eve" << endl;
    else cout << "Christmas Eve Eve Eve" << endl;
    return 0;
}

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

#define long long long int
using namespace std;


#ifdef JUDGE
std::ifstream cin("input.txt");
std::ofstream cout("output.txt");
#else
using std::cin;
using std::cout;
#endif

using namespace std;


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


    int n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;
    int cnt = 0;
    int f = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'a') {
            if (cnt < a + b) {
                cnt++;
                cout << "Yes" << '\n';
            } else {
                cout << "No" << '\n';
            }
        } else if (s[i] == 'b') {
            if (cnt < a + b and f < b) {
                cnt++, f++;
                cout << "Yes" << '\n';
            } else {
                cout << "No" << '\n';
            }
        } else {
            cout << "No" << '\n';
        }
    }
    return 0;


}


Measured memory_bytes: 848
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;

const long long MOD = 1000000007;

vector<int> places[210000];
long long dp[210000];
void add(long long &a, long long b)
{
    a += b;
    if (a >= MOD)
        a -= MOD;
}
int main()
{
    string s;
    cin >> s;
    string t;
    cin >> t;

    vector<bool> used(26, false), contain(26, false);
    vector<vector<int>> ch(26);
    rep(i, t.size())
    {
        int m = t[i] - 'a';
        used[m] = true;
    }
    string ss = s + s;

    rep(i, ss.size())
    {
        int m = ss[i] - 'a';
        ch[m].push_back(i);
        contain[m] = true;
    }
    bool ok = true;
    rep(i, 26)
    {
        if (used[i] && !contain[i])
        {
            ok = false;
        }
    }
    if (ok)
    {
        int n = s.size();
        vector<vector<int>> next(n, vector<int>(26));
        vector<int> start(26, 1e9);
        rep(i, 26)
        {
            if (used[i])
                start[i] = ch[i][0];
        }
        rep(i, n)
        {
            rep(j, 26)
            {
                if (used[j])
                {
                    int ite = upper_bound(ch[j].begin(), ch[j].end(), i) - ch[j].begin();
                    next[i][j] = ch[j][ite];
                }
            }
        }
        int now = start[t[0]-'a'];
        //cout<<now<<endl;
        ll cnt = 0;
        if(t.size()==1){
            cnt=now;
        }
        FOR(i, 1, t.size())
        {
            int m = t[i] - 'a';
            now=next[now][m];
            if (i == t.size() - 1)
            {
                cnt += now;
            }
            else if (now >= n)
            {
                cnt += n;
                now -= n;
            }
        }
        cout << cnt + 1 << endl;
    }
    else
    {
        cout << -1 << endl;
    }
}

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

int main() 
{
    int n, q;
    string s;
    cin >> n >> q;
    cin >> s;
    vector<pair<int,int>> V;
    rep(i,q) {
        int l, r;
        cin >> l >> r;
        V.push_back(make_pair(l, r));
    }

    int S[s.size()+1];
    S[0] = 0;
    S[1] = 0;
    for (int i=2; i<=s.size(); i++) {
        if(s[i-1] == 'C' && s[i-2] == 'A') S[i] = S[i-1] +1;
        else S[i] = S[i-1];
    }    

    for(auto p : V) {
        int l = p.first;
        int r = p.second;
        cout << S[r] - S[l] << endl;
    }

    return 0;
}


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

const int LIMIT = 1000000000;

int main()
{
	int n;

	while( cin >> n && n ){
		int wf[ 10 ][ 10 ] = {0};
		for( int i = 0; i < 10; ++i ){
			for( int j = 0; j < 10; ++j ){
				if( i != j ) wf[ i ][ j ] = LIMIT;
			}
		}
		int m = 0;
		for( int i = 0; i < n; ++i ){
			int s, e, d;
			cin >> s >> e >> d;
			if( m < s ) m = s;
			if( m < e ) m = e;
			wf[ s ][ e ] = wf[ e ][ s ] = d;
		}
		m += 1;
		for( int k = 0; k < m; ++k ){
			for( int i = 0; i < m; ++i ){
				for( int j = 0; j < m; ++j ){
					wf[ i ][ j ] = min( wf[ i ][ j ], wf[ i ][ k ] + wf[ k ][ j ] );
				}
			}
		}
		int ansP = 0;
		int ansD = LIMIT;
		for( int i = 0; i < m; ++i ){
			int sum = 0;
			for( int j = 0; j < m; ++j ){
				sum += wf[ j ][ i ];
			}
			if( ansD > sum ){
				ansP = i;
				ansD = sum;
			}
		}
		cout << ansP << " " << ansD << endl;
	}


	return 0;
}

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

int main(){
	int n,l;
	cin >> n >> l;
	vector<string> s(n);
	for(int i=0;i<n;++i){
		cin >> s[i];
	}
	sort(s.begin(),s.end());
	for(int i=0;i<n;++i){
		cout << s[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
use std::io;
use std::io::BufRead;

fn main() {
    let stdin = io::stdin();
    let mut stdin = stdin.lock();

    let (n, k) = {
        let mut input = String::new();
        stdin.read_line(&mut input).unwrap();
        let mut input = input.trim().split_whitespace();
        (
            input.next().unwrap().parse::<i32>().unwrap(),
            input.next().unwrap().parse::<f64>().unwrap(),
        )
    };

    let prob: f64 = (0..n).map(|i| 1. + i as f64)
        .map(|n| if k <= n { 0i32 } else { ((k/n) as f64).log2().ceil() as i32 } )
        .map(|n| 1./2f64.powi(n))
        .sum();

    println!("{}", prob/n as f64);
}


Measured memory_bytes: 4604
n = int(input())
s1 = input()
s2 = s1[::-1]
i1 = 0
i2 = 0
ans = 0
while i1 < n:
  if s1[i1]=='W':
    while i2 < n:
      if s2[i2]=='R':
        ans += 1
        i2 += 1
        break
      elif i1+i2 >= n-2:
        break
      else:
        i2 += 1
  if i1+i2 >= n-2:
    break
  i1 += 1
print(ans)

Measured memory_bytes: 9396
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

std::vector<std::string> split(const std::string &s, const std::string &delim) {
  using string = std::string;
  std::vector<string> v;
  string::size_type pos = 0;
  while (pos != string::npos) {
    string::size_type p = s.find(delim, pos);
    if (p == string::npos) {
      v.push_back(s.substr(pos));
      break;
    }
    v.push_back(s.substr(pos, p - pos));
    pos = p + delim.size();
  }
  return v;
}

template<typename InputIterator> std::string join(InputIterator first, InputIterator last, const std::string &sep) {
  if (first == last) return "";
  std::stringstream ss;
  ss << *(first++);
  for_each(first, last, [&](auto &x) { ss << sep << x; });
  return ss.str();
}

main {
  vi dx = {1, -1, 4, -4};
  map<string, int> m;
  queue<string> q;
  q.emplace("01234567");
  while (q.size()) {
    string s = q.front();
    q.pop();
    int pos = distance(s.begin(), find(all(s), '0'));
    rep(i, 4) {
      if (pos + dx[i] < 0 || pos + dx[i] >= 8 || (i / 2 == 0 && pos / 4 != (pos + dx[i]) / 4)) continue;
      string t = s;
      swap(t[pos], t[pos + dx[i]]);
      if (m.count(t)) continue;
      q.emplace(t);
      m[t] = m[s] + 1;
    }
  }
  string s;
  while (getline(cin, s)) {
    auto x = split(s, " ");
    cout << m[join(all(x), "")] << endl;
  }
}

Measured memory_bytes: 5400
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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; }
const int INF = 1e9;
const LL LLINF = 1e16;

template<int mod>
struct ModInt {
    int x;

    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt &operator+=(const ModInt &p) {
        if((x += p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }

    ModInt pow(int e){
        long long a = 1, p = x;
        while(e > 0) {
            if(e%2 == 0) {p = (p*p) % mod; e /= 2;}
            else {a = (a*p) % mod; e--;}
        }
        return ModInt(a);
    }

    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

const int mod = 1e9 + 7;
using modint = ModInt<mod>;

modint dp[2020][2020];

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> s(n), t(m);
    rep(i, n) cin >> s[i];
    rep(i, m) cin >> t[i];
    dp[0][0] = 0;
    rep(i, n){
        rep(j, m){
            if(s[i] == t[j]){
                dp[i+1][j+1] = dp[i][j+1] + dp[i+1][j] + 1;
            }else{
                dp[i+1][j+1] = dp[i][j+1] + dp[i+1][j] - dp[i][j];
            }
        }
    }
    cout << dp[n][m]+1 << endl;

}

Measured memory_bytes: 16256