akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(long long i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

int binary(long long bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}

int main(){
  int a,b;
  cin >> a >> b;
  if (b%a == 0) {
    cout << a+b;
  } else {
    cout << b-a;
  }
} 

Measured memory_bytes: 256
N, Q = map(int , input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

Measured memory_bytes: 9028
<?php
  list($x, $n) = explode(" ", trim(fgets(STDIN)));

  $p = explode(" ", trim(fgets(STDIN)));

  $max = $x;
  for($i=0; $i<101; $i++){
    if(!in_array($max, $p)){
      break;
    }
    $max++;
  }

  $min = $x;
  for($i=0; $i<101; $i++){
    if(!in_array($min, $p)){
      break;
    }
    $min--;
  }

  if($x-$min > $max-$x){
    echo $max;
  }else{
    echo $min;
  }

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

int main(){
  int A,B,C,K;
  cin >> A >> B >> C >> K;

  int count = 0;
  if (A >= K) {
    count = K;
  }
  else if (A+B >= K) {
    count = A;
  }  
  else {
    count = A - (K -(A + B));
  }
  cout << count << endl;

  return 0;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>
#include <omp.h>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;
typedef pair<long long int, pll> lpll;

const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 
//const long long int pl=1000000;
long long int D,T,S;




int main(){
    cout << fixed << setprecision(18);
    cin>>D>>T>>S;
    IFYes(D<=T*S);
    
    
}



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

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


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

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

int main() {
    int j = 1;
    while (true) {
        int i;
        cin >> i;
        if (i == 0) {
            return 0;
        }

        printf("Case %d: %d\n", j, i);
        j++;
    }

}



Measured memory_bytes: 3116
var i,n,t:Longint;s:String;
begin
readln(n);
n:=n-65;
readln(s);
for i:=1 to length(s)do begin
	t:=ord(s[i])+n;
	if t>=26 then t:=t-26;
	s[i]:=chr(t+65);
end;
writeln(s);
end.

Measured memory_bytes: 128
#include<iostream>

#define MAX_K 500000
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef long long ll;

ll combination_n[MAX_K + 1];//combination_n[i] := nCi

ll extend_gcd(ll a,ll b,ll &x,ll &y) {
    if(b == 0) {
        x = 1;y = 0;
        return a;
    }
    ll r = a % b;
    ll d = extend_gcd(b,r,y,x);
    y -= (a / b) * x ;

    return d;
}

void precompute_for_combination(ll n,ll k,ll p) {
    combination_n[0] = 1;

    for(int i = 1;i <= k;i++) {
        ll x,y;
        extend_gcd(i,p,x,y);

        x %= p;

        if(x < 0) x = p + x;

        combination_n[i] = 
            combination_n[i - 1] * (n - i + 1) % p * x % p;
    }
}


ll N,A,B,K;
int main() {
    cin >> N >> A >> B >> K;
    ll p = 998244353;

    precompute_for_combination(N,N,p);

    ll ret = 0;
    rep(i,N+1) {
        ll a = i;
        ll b = K - a * A;
        if(b < 0 || b % B)continue;
        b  /= B;
        if(b > N)continue;
        (ret += combination_n[a] * combination_n[b] % p) %= p;
    }

    cout << ret << endl;
    
    return 0;
}

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

#define println(msg) cout << msg << endl
#define sort_vec(vec) sort(vec.begin(), vec.end())
#define rsort_vec(vec) sort(vec.rbegin(), vec.rend()) // greater<int>()

int main() {
  // 入力
  int N;
  cin >> N;

  vector<int> d(N);
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }
  
  // 計算
  
  // 重複をけす
  set<int> tmp;
  for (int i = 0; i < N; i++) {
    tmp.insert(d.at(i));
  }
  
  // 出力
  println(tmp.size());
}


Measured memory_bytes: 3616
#include<iostream>
#include<string>
using namespace std;
int main() {
	string S, T, U;
	int A, B;
	cin >> S >> T;
	cin >> A >> B;
	cin >> U;
	if (S == U) cout << A - 1 <<" "<< B << endl;
	if (T == U) cout <<A  <<" "<< B - 1 << endl;

}

Measured memory_bytes: 256
n = int(input())
p = [1.0] + list(map(float,input().split()))
dp = [[0]*(n+1) for _ in range(n+1)]
dp[0][0] = 1.0
for i in range(1,n+1):
  dp[i][0] = dp[i-1][0]*(1.0-p[i])
  for j in range(1,i+1):
    dp[i][j] = dp[i-1][j-1]*p[i] + dp[i-1][j]*(1-p[i])
print(sum(dp[n][j] for j in range(n//2+1,n+1)))


Measured memory_bytes: 263048
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define ll long long
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);

int main() {
  int n;
  cin >>n;
 
  int ans = 0;
  
  vector<int> jun(n);
  vector<int> man(n);
  vector<int> bon(n-1);
  
  rep(i,n) {
  cin >> jun[i];
  }
  rep(i,n) {
  cin >> man[i];
  ans+=man[i];
  }
  rep(i,n-1) {
  cin >> bon[i];
  }
  
  rep(i,n-1) {
    if(jun[i]+1==jun[i+1]) ans+=bon[jun[i]-1];
  }
  
  cout << ans << endl;
  
}

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

#define debug(x) cerr<<#x<<'='<<x<<'\n'
#define Int const int &
int a[123456];

int main(void) {
	int n;
	cin>>n;
	for (int i=1; i<=n; i++) {
		int l, r;
		cin>>l>>r;
		for (int j=l; j<=r; j++) {
			a[j]=233;
		}
	}
	int ans=0;
	for (int i=1; i<=100000; i++) {
		if (a[i]) {
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define nl '\n'

#define boost ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;

const ll INF=1e18;
const int inf=1e9;
const ld eps=1e-7;
const ld pi=acos(-1);
const int dx[8]={0,0 ,1,-1,1,1,-1,-1};
const int dy[8]={1,-1,0,0,1,-1,1,-1};
const int mod1=998244353;
const int mod2=1e9+7;
const int N=2111;

int a[N],ans[N],cnt[N];

int main(){
  boost;

  int n,k;
  cin>>n>>k;
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
  for(int i=1;i<=n;i++){
    for(int j=a[i]+1;j<=2000;j++){
      ans[i]+=cnt[j];
    }
    cnt[a[i]]++;
  }
  ll res=0;
  for(int i=1;i<=n;i++){
    ll val=0;
    for(int j=a[i]+1;j<=2000;j++){
      val+=cnt[j];
    }
    ll p=1ll*k*(k-1)/2;
    p%=mod2;
    res+=(val*p)%mod2+(1ll*ans[i]*k)%mod2;
    res%=mod2;
  }
  cout<<res;

  return 0;
}


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

x, y = map(int, input().split())
k = y - 2 * x
l = 4 * x - y

ans = 'No'

if k % 2 == 0:
    b = k / 2

    if l % 2 == 0:
        a = l / 2

        if a + b == x and a >= 0 and b >= 0:
            ans = 'Yes'


print(ans)

Measured memory_bytes: 61744
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
  
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
  
using namespace std;
  
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

int main(){
    map<char, ll> m;
    int n;
    cin >> n;
    rep(i, n){
        int a, b;
        char c;
        cin >> a >> c >> b;
        m[c] += b;
        cout << (m['(']==m[')']?"Yes":"No") << endl;
    }

    return 0;
}

Measured memory_bytes: 1188
class TreeNode:
    def __init__(self):
        self.val=-1
        self.left=-1
        self.right=-1
        self.parent=-1

n=int(input())
nodes=[TreeNode() for _ in range(n)]

for _ in range(n):
    idx,left,right=map(int,input().split())
    nodes[idx].val=idx
    nodes[idx].left=left
    nodes[idx].right=right
    if(left!=-1):
        nodes[left].parent=idx
    if(right!=-1):
        nodes[right].parent=idx

root_idx=-1
for i in range(n):
    if(nodes[i].parent==-1):
        root_idx=i
        break

preorder_idx=[]
def preOrder(idx):
    preorder_idx.append(idx)
    if(nodes[idx].left!=-1):
        preOrder(nodes[idx].left)
    if(nodes[idx].right!=-1):
        preOrder(nodes[idx].right)

inorder_idx=[]
def inOrder(idx):
    if(nodes[idx].left!=-1):
        inOrder(nodes[idx].left)
    inorder_idx.append(idx)
    if(nodes[idx].right!=-1):
        inOrder(nodes[idx].right)

postorder_idx=[]
def postOrder(idx):
    if(nodes[idx].left!=-1):
        postOrder(nodes[idx].left)
    if(nodes[idx].right!=-1):
        postOrder(nodes[idx].right)
    postorder_idx.append(idx)


preOrder(root_idx)
inOrder(root_idx)
postOrder(root_idx)

print("Preorder")
print(" ",end="")
print(*preorder_idx)

print("Inorder")
print(" ",end="")
print(*inorder_idx)

print("Postorder")
print(" ",end="")
print(*postorder_idx)



Measured memory_bytes: 5616
#include <bits/stdc++.h>
//F6編譯，右上三角形執行，ctrl+c強制停止執行  F5開啟exe
#define ll long long
#define maxn 200005
#define mod 998244353
using namespace std;

typedef pair<int, int> P;

int k, a, b;

int main()
{
    cin >> k >> a >> b;
    int cnt = b / k - (a - 1) / k;
    if (cnt == 0)
        printf("NG\n");
    else
        printf("OK\n");
    return 0;
}


Measured memory_bytes: 3592
import sys
input = sys.stdin.readline

s=input()
A = int(s[0])
B = int(s[1])
C = int(s[2])
D = int(s[3])

ans = ''
for i in range(2):
    if ans != '':
        break
    for j in range(2):
        if ans != '':
            break
        for k in range(2):
            t = A + (2*i-1)*B + (2*j-1)*C + (2*k-1)*D
            if t == 7:
                op1 = '-' if i == 0 else '+'
                op2 = '-' if j == 0 else '+'
                op3 = '-' if k == 0 else '+'
                ans = "{}{}{}{}{}{}{}=7".format(A,op1,B,op2,C,op3,D)
                break

print(ans)

Measured memory_bytes: 61992
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
ll dx[4]={-1,1,0,0};
ll dy[4]={0,0,-1,1};


void solve()
{
	ll h,w,m;
	cin>>h>>w>>m;
	vector<pair<ll,ll>> a(m);
	map<pair<ll,ll>,ll> mp;
	map<ll,ll> row,col;
	for(int i=0;i<m;i++)
	{
		cin>>a[i].first>>a[i].second;
		mp[{a[i].first,a[i].second}]++;
		row[a[i].first]++;
		col[a[i].second]++;
	}
	
		
	ll rmax=0,cmax=0;
	for(auto i:row)
		rmax=max(rmax,i.second);
	for(auto i:col)
		cmax=max(cmax,i.second);
	// cout<<cmax<<endl;
	vector<ll> r,c;
	for(auto i:row)
		if(i.second==rmax)
			r.push_back(i.first);
	for(auto i:col)
		if(i.second==cmax)
			c.push_back(i.first);
	// cout<<c.size()<<endl;
	for(auto i:r)
		for(auto j:c)
		{
			// cout<<i<<j<<endl;
			if(mp.find({i,j})==mp.end())
			{
				cout<<rmax+cmax<<endl;
				return;
			}
		}
			
	
	cout<<rmax+cmax-1;

	return;
}

int main()
{
	fast;
	ll q;
	q=1;
	// cin>>q;
	while(q--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 72564
#include<stdio.h>

int h, r;

int main(void)
{
	
	scanf( "%d %d", &h, &r );
	
	if ( h + r > 0) printf( "1\n" );
	else if ( h + r < 0 ) printf( "-1\n" );
	else printf( "0\n" );
	
	return 0;
}

Measured memory_bytes: 1812
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll mod = 1000000007;

int main() {
  int n, k;

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

  ll i1 = 0;
  ll i2 = 0;
  for (int i=0; i<n-1; i++) {
    for (int j=i+1; j<n; j++) {
      if (a[i] > a[j]) {
        i1++;
      } else if (a[i] < a[j]) {
        i2++;
      }
    }
  }

  ll ans;
  if (k == 1) {
    ans = i1 % mod;
  } else {
    ll kc2 = ((ll)k * ((ll)k - 1) / 2) % mod ;
    ans = (i1 * (ll)k) % mod;
    ans += (i1 + i2) * kc2;
    ans %= mod;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
def main():
    s = input()
    ans = 'No'
    for i in range(len(s)):
        if i % 2 == 0 and s[i] == 'L':
            break
        if i % 2 == 1 and s[i] == 'R':
            break
    else:
        ans = 'Yes'

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
import java.util.Scanner;

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

        int min = 10000;


        if(r - l < 2019){
            if(l%2019 > r%2019) {
                min = 0;
            } else{
                for(int i = l; i < r; i++){
                    for(int j = i+1; j <= r; j++){
                        min = Math.min(min, (i%2019)*(j%2019) % 2019);
                        if(min == 0) break;
                    }
                }
            }
        } else {
            min = 0;
        }

        System.out.println(min);
    }
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  ld a, b;
  cin >> a >> b;
  ld res = a*b;
  cout << ll(res) << '\n';
}

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

    println(
            readLine()!!.split(Regex("\\s+")).map { it.toInt() }
                    .groupBy { it }
                    .mapValues { it.value.size }
                    .filterValues { it >= 2 }
                    .toList().sortedByDescending { it.first }
                    .let { l ->
                        val p1 = l.getOrElse(0, { i -> 0 to 0 })
                        val p2 = l.getOrElse(1, { i -> 0 to 0 })

                        val e1 = p1.first.toLong()
                        val e2 = p2.first.toLong()
                        
                        e1 * (if (p1.second >= 4) e1 else e2)
                    }
    )
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

bool b[114][114];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, w;
	string a[114];
	cin>>h>>w;
	REP(i, h){
		cin>>a[i];
		bool ok=true;
		REP(j, w){
			if(a[i][j]!='.'){
				ok=false;
				break;
			}
		}
		if(ok){
			REP(j, w){
				b[i][j]=true;
			}
		}
	}
	REP(i, w){
		bool ok=true;
		REP(j, h){
			if(a[j][i]!='.'){
				ok=false;
				break;
			}
		}
		if(ok){
			REP(j, h){
				b[j][i]=true;
			}
		}
	}
	REP(i, h){
		bool ok=false;
		REP(j, w){
			if(!b[i][j]){
				cout<<a[i][j];
				ok=true;
			}
		}
		if(ok){
			cout<<'\n';
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
const int N=105;
char s[N][N];
int dp[N][N];
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
    dp[1][1]=0;
    if(s[1][1]=='#') dp[1][1]=1;
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(i+j>2) {
        dp[i][j]=N;
        if(i>1) dp[i][j]=std::min(dp[i][j],dp[i-1][j]+(s[i][j]=='.'||s[i-1][j]=='#'?0:1));
        if(j>1) dp[i][j]=std::min(dp[i][j],dp[i][j-1]+(s[i][j]=='.'||s[i][j-1]=='#'?0:1));
    }
    printf("%d\n",dp[n][m]);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.rbegin(),a.rend())
#define lb(a,b) lower_bound(a.begin(),a.end(),b)
#define ub(a,b) upper_bound(a.begin(),a.end(),b)
#define MOD ((int)( 1e9 + 7  ))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double
#define sqrt sqrtl
#define cbrt cbrtl
#define endl '\n'
typedef vector<int> vi;
typedef vector<float> vf;
typedef pair<float,int> fi;
typedef pair<int,int> ii;
typedef pair<float,float> ff;
typedef vector<ff> vff;
typedef vector<ii> vii;
typedef vector<fi> vfi;
typedef vector<vi> vvi;
typedef vector<vf> vvf;
typedef vector<vii> vvii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef priority_queue<fi> pqfi;
typedef priority_queue <int, vector<int>, greater<int> > rpqi; 
typedef priority_queue <ii, vector<ii>, greater<ii> > rpqii; 
typedef priority_queue <fi, vector<fi>, greater<fi> > rpqfi;

const int N=2e5+5;
int par[N];
int root(int v){return par[v] < 0 ? v : (par[v] = root(par[v]));}
void merge(int x,int y){	
        if((x = root(x)) == (y = root(y)) )    return ;
	if(par[y] < par[x])	
		swap(x, y);
	par[x] += par[y];
	par[y] = x;
}

int32_t main()
{
	IOS
	int n;cin>>n;
	cout<<(n*(n-1))/2<<endl;
			
	
		
	
}
 
 


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

#[allow(unused_macros)]
macro_rules! chmax {
    ( $ x : expr , $ y : expr ) => { if $ x < $ y { $ x = $ y ; true } else { false } };
}

fn main() {
    input! {
        n: usize,
        a: [[i64; n];n]
    }

    let mut p = vec![0i64;1<<n];
    for mask in 0..1<<n {
        let mut cnt = 0;
        for i in 0..n {
            for j in i+1..n {
                if mask >> i & 1 == 1 && mask >> j & 1 == 1 {
                    cnt += a[i][j];
                }
            }
        }
        p[mask] = cnt;
    }
    let mut dp = vec![None;1<<n];
    for mask in 0..1<<n {
        let mut sub = mask;
        loop {
            match dp[mask] {
                Some(_) => {
                    chmax!(dp[mask], Some(dp[mask-sub].unwrap_or(0) + p[sub]));
                },
                None => dp[mask] = Some(dp[mask-sub].unwrap_or(0) + p[sub]),
            };
            if sub == 0 {
                break;
            }
            sub = (sub - 1) & mask;
        }
    }
    println!("{}", dp[(1<<n)-1].unwrap());
}


Measured memory_bytes: 4352
#include <algorithm> //STLͨ���㷨
#include <cmath> //������ѧ����
#include <cstdio> //��������/�������
#include <iostream> //����������/���
#include <cstring> //�ַ�������
#include <string> //�ַ�����
#include <ctime> //�������ʱ��ĺ���
#define itn int
#define fro for
#define ll long long
#define reg register
#define inf 1234567890
#define rep(i,a,b,c) for (int i=a;i<=b;i+=c)
/*#include <bitset> //STLλ������
#include <cstype> //�ַ�����
#include <cerrno> //���������
#include <complex> //������
#include <clocale> //���屾�ػ�����
#include <cstdlib> //������������ڴ���亯��
#include <deque> //STL˫�˶�������
#include <exception> //�쳣������
#include <fstream> //�ļ�����/���
#include <functional> //STL�������㺯��(���������)
#include <limits> //�����������������ֵ����
#include <list> //STL�����б�����
#include <map> //STLӳ������
#include <iomanip> //����������/���
#include <ios> //��������/���֧��
#include <iosfwd> //����/���ϵͳʹ�õ�ǰ������
#include <istream> //����������
#include <ostream> //���������
#include <queue> //STL��������
#include <set> //STL��������
#include <sstream> //�����ַ�������
#include <stack> //STL��ջ����
#include <stdexcept> //��׼�쳣��
#include <streambuf> //�ײ�����/���֧��
#include <utility> //STLͨ��ģ����
#include <vector> //STL��̬��������
#include <cwchar.h>//���ַ�����������/���
#include <cwctype.h> //���ַ�����*/

using namespace std;

ll ans;

int max(int x,int y){return x>y?x:y;}

int min(int x,int y){return x<y?x:y;}

int abs(int x){return x>0?x:-x;}

int gcd(int x,int y){return (!y)?x:gcd(y,x%y);}

void exgcd(int a,int b,int &d,int &x,int &y){if (!b){d=a,x=1,y=0;}else{exgcd(b,a%b,d,y,x);y-=x*(a/b);}}

int quick_power(ll a,int b){ll r=1;for (;b;b>>=1,a=a*a)if (b&1) r=r*a;return r;}

inline char read() {
	static const int IN_LEN = 1000000;
	static char buf[IN_LEN], *s, *t;
	return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin), (s == t ? -1 : *s++) : *s++);
}
template<class T>
inline void read(T &x) {
	static bool iosig;
	static char c;
	for (iosig = false, c = read(); !isdigit(c); c = read()) {
		if (c == '-') iosig = true;
		if (c == -1) return;
	}
	for (x = 0; isdigit(c); c = read()) x = x * 10 + (c ^ '0');
	if (iosig) x = -x;
}

char sr[10000000],z[20];int C=-1,Z=0;
void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(int x){
	if (x<0) sr[++C]='-',x=-x;
    while(z[++Z]=x%10+48,x/=10);
    while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
//int find(int x){return fa[x]=fa[x]==x?x:find(fa[x]);}

//void add(int x,int y,int z){to[++cnt]=y;v[cnt]=z;Next[cnt]=head[x];head[x]=cnt;}

ll n;

void judge(ll x,ll y)
{
	if (!x) return;
	if (n/x==y&&n%x==y) ans+=x;
}

int main()
{
	read(n);
	for (ll i=1;i*i<=n;i++)
	{
		if (n%i) continue;
		judge(i-1,n/i);
		if (i*i<n) judge(n/i-1,i);
	}
	cout<<ans;
	return 0;
}









Measured memory_bytes: 2304
// 2020-08-11 22:41:57
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

using ull = unsigned long long;
int n;
vector<vector<int> > A;
vector<int> ST[2];
vector<int> UV[64][2];
void transpose() {
  rep(i, n) REP(j, i+1, n) swap(A[i][j], A[j][i]);
}
bool solve(int b) {
  A.assign(n, vector<int>(n, -1));
  rep(k, 2) {
    rep(i, n) {
      if(ST[k][i] == 0 && UV[b][k][i] == 1) {
        rep(j, n) {
          if(A[i][j] == 0) return false;
          A[i][j] = 1;
        }
      } else if(ST[k][i] == 1 && UV[b][k][i] == 0) {
        rep(j, n) {
          if(A[i][j] == 1) return false;
          A[i][j] = 0;
        }
      }
    }
    transpose();
  }
  rep(_, 2) {
    rep(k, 2) {
      rep(i, n) {
        if(ST[k][i] != UV[b][k][i]) continue;
        bool ok = false;
        vector<int> idx;
        int x = ST[k][i];
        rep(j, n) {
          if(A[i][j] == x) {
            ok = true;
          } else if(A[i][j] == -1) {
            idx.push_back(j);
          }
        }
        if(ok) continue;
        if(idx.size() == 0) return false;
        if(idx.size() == 1) A[i][idx[0]] = x;
      }
      transpose();
    }
  }
  set<int> is, js;
  rep(i, n) rep(j, n) if(A[i][j] == -1) {
    is.insert(i);
    js.insert(j);
  }
  int base = 1;
  for(int i : is) {
    base = 1 - base;
    int c = base;
    for(int j : js) {
      A[i][j] = c;
      c = 1 - c;
    }
  }
  return true;
}
void answer() {
  cin >> n;
  rep(k, 2) rep(i, n) {
    int x;
    cin >> x;
    ST[k].push_back(x);
  }
  rep(k, 2) rep(i, n) {
    ull x;
    cin >> x;
    rep(j, 64) UV[j][k].push_back((x>>j)&1);
  }
  vector<vector<ull> > ans(n, vector<ull>(n, 0));
  rep(b, 64) {
    if(solve(b)) {
      rep(i, n) {
        rep(j, n) {
          ans[i][j] |= (ull(A[i][j])<<b);
        }
      }
    } else {
      cout << -1 << '\n';
      return;
    }
  }
  rep(i, n) {
    rep(j, n) {
      if(j) cout << ' ';
      cout << ans[i][j];
    }
    cout << '\n';
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 8900
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
local function array(dimension, default_val) local n=dimension local m={}if default_val~=nil then m[1]={__index=function()return default_val end}end for i=2,n do m[i]={__index=function(p, k)local c=setmetatable({},m[i-1])rawset(p,k,c)return c end}end return setmetatable({},m[n])end
----
local N, M = read.nn()
local KCost = {}
local KAbl = {}
for i=1,M do
    local a, b = read.nn()
    KCost[i] = a
    KAbl[i] = 0
    for j=1,b do
        local c = read.n()
        local bit = 1 << (c-1)
        KAbl[i] = KAbl[i] | bit
    end
end


local curset = 0
local STATMAX = math.floor(2^N) - 1

local INF = 10^9
local cost = array(1, INF)
cost[0] = 0
local min = math.min
local function chmin(s, val)
    cost[s] = min(cost[s], val)
end

for stat=0,STATMAX do
    if cost[stat] ~= INF then
        for curkey=1,M do
            local newstat = stat | KAbl[curkey]
            chmin(newstat, cost[stat] + KCost[curkey])
        end
    end
end

if cost[STATMAX] == INF then
    print("-1")
    return
end

print(cost[STATMAX])


Measured memory_bytes: 760
n, m = map(int, input().split())
li = [0]*200001
s = "IMPOSSIBLE"
for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
        if li[b] == 0:
            li[b] = 1
        else:
            s = "POSSIBLE"
    
    if b == n:
        if li[a] == 0:
            li[a] = 1
        else:
            s = "POSSIBLE"

print(s)

Measured memory_bytes: 10380
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [s,t] <- words <$> getLine
    [a, b] <- getIntList
    u <- getLine
    putStrLn . unwords . map show $ solve s t a b u

solve s t a b u | s == u = [a - 1, b]
                | t == u = [a, b - 1]

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

void EAST(int* dice) {
    int copy = dice[0];
    dice[0] = dice[3];
    dice[3] = dice[5];
    dice[5] = dice[2];
    dice[2] = copy;
}

void NORTH(int* dice) {
    int copy = dice[0];
    dice[0] = dice[1];
    dice[1] = dice[5];
    dice[5] = dice[4];
    dice[4] = copy;
}

void SOUTH(int* dice) {
    int copy = dice[0];
    dice[0] = dice[4];
    dice[4] = dice[5];
    dice[5] = dice[1];
    dice[1] = copy;
}

void WEST(int* dice) {
    int copy = dice[0];
    dice[0] = dice[2];
    dice[2] = dice[5];
    dice[5] = dice[3];
    dice[3] = copy;
}

int main(void) {
    int dice[6];
    string order;
    
    for(int i = 0; i < 6; ++i) {
        cin >> dice[i];
    }
    cin >> order;
    
    for(int i = 0; i < order.length(); ++i) {
        switch(order[i]) {
            case 'E' : EAST(dice);   break;
            case 'N' : NORTH(dice);  break;
            case 'S' : SOUTH(dice);  break;
            case 'W' : WEST(dice);   break;
        }
    }
    cout << dice[0] << endl;
    
    return 0;
}




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

int main(void)
{
	string s;
	cin >> s;
	int n = s.size();
	for (int i = 0; i < n; i++)
	{
		if (i % 2 == 0 && s[i] == 'L')
		{
			cout << "No" << endl;
			return 0;
		}
		if (i % 2 != 0 && s[i] == 'R')
		{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 504
package main

import "fmt"

func main() {
	// Code for A - Libra
	var A, B, C, D int
	fmt.Scanf("%d %d %d %d", &A, &B, &C, &D)

	if A+B > C+D {
		fmt.Println("Left")
	} else if A+B == C+D {
		fmt.Println("Balanced")
	} else {
		fmt.Println("Right")
	}
}


Measured memory_bytes: 1836
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

template<class T>bool umax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool umin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}
template<typename T>
T lcm( T m, T n )
{
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;

    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    long long N;
    cin >> N;
    vector<long long>a(N);

    rep(i,N){
        cin >> a[i];
    }
    long long araigumakun=accumulate(a.begin(),a.end(),0LL)-a[0];
    long long sunukekun=a[0];
    long long minimum=abs(araigumakun-sunukekun);

    for(long long i=1; i<N-1; i++){
        sunukekun+=a[i];
        araigumakun-=a[i];
        minimum=min(minimum,abs(araigumakun-sunukekun));
    }
    cout << minimum << endl;
    return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define reg register
using namespace std;
int a,b;
string s;
inline bool judge()
{
	if(s[a]!='-')return 0;
	for(reg int i=0;i<a;i++)if(s[i]<'0'||s[i]>'9')return 0;
	for(reg int i=a+1;i<=a+b;i++)if(s[i]<'0'||s[i]>'9')return 0;
	return 1;
}
int main()
{
	scanf("%d%d",&a,&b);
	cin>>s;
	puts(judge()?"Yes":"No");
	return 0;
}

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

int main(){
    int n, m;
    while(cin >> n >> m, n+m){
        vector<int> vec[m];
        int d, v;
        for(int i = 0; i < n; i++){
            cin >> d >> v;
            vec[d-1].push_back(v);
        }
        int ans = 0;
        for(int i = 0; i < m; i++)  ans += *max_element(vec[i].begin(), vec[i].end());
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3144
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code ---*/
	N := nextInt()
	v := make([]int, N)
	for i := 0; i < N; i++ {
		v[i] = nextInt()
	}
	sort.Ints(v)
	x := float64(v[0])
	for i := 1; i < N; i++ {
		x = (x + float64(v[i])) / 2.0
	}
	fmt.Fprintln(out, x)
}

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// Genericsがないので筋肉で...
// interfaceでの取扱がようわからんし
func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// mapからkeysとvaluesを返す感じのやつ
// なんかしらんけどmap[interface{}]interface{}しか受け付けない。なんのためのinterface{}やねん
// なので呼ぶときのmapはmap[int]stringとかじゃダメ
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
	return
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N, T;
	cin >> N >> T;
	vector<int>c(N), t(N);
	vector<pair<int, int>>p(N);
	int ans = 1e9;
	for (int i = 0; i < N; i++){
		cin >> c[i] >> t[i];
		p[i] = make_pair(c[i], t[i]);
		if (t[i] <= T) {
			ans = min(ans, p[i].first);
		}
	}
	if (ans == 1e9) {
		cout << "TLE" << endl;
	}
	else {
		cout << ans << 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 a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      
      if(a+b+c>=22){
      System.out.println("bust");
      }
      else if(a+b+c<=21){
        System.out.println("win");
      }
    }
}

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

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

    int size = s.size();
    for (int i = 0; i < size; i++) {
        s.pop_back();
        if (s.substr(0, s.size()/2) == s.substr(s.size()/2, s.size()/2)) {
            cout << s.size() -1 << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, m, x, amount[13][13], skills[13], cost[13], sol = 2e18;

bool good() {
    for (int i = 1; i <= m; i++)
        if (skills[i] < x)
            return false;
    return true;
}

int main() {
    cin.tie(0); ios::sync_with_stdio(0);
    cin >> n >> m >> x;
    for (int i = 1; i <= n; i++) {
        cin >> cost[i];
        for (int j = 1; j <= m; j++)
            cin >> amount[i][j];
    }

    ll last = (1 << n);
    for (ll i = 1; i < last; i++) {
        for (int j = 1; j <= m; j++)
            skills[j] = 0;

        ll cnt = 1, suma = 0;
        for (ll x = 1; x <= i; x <<= 1, cnt++)
            if (x & i) {
                suma += cost[cnt];
                for (int j = 1; j <= m; j++)
                    skills[j] += amount[cnt][j];
            }

        if (good())
            sol = min(sol, suma);
    }

    if (sol == 2e18)
        cout << -1;
    else
        cout << sol;
    return 0;
}


Measured memory_bytes: 3696
import sys
input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    p = list(map(lambda x: (1 + int(x)) / 2, input().split()))

    for i in range(1, N):
        p[i] += p[i-1]
    
    ans = p[K-1]
    for i in range(K, N):
        ans = max(ans, p[i] - p[i-K])

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 22868
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


class UnionFind:

    def __init__(self, N: int):
        # d[i] = <parent id> if i is a child,
        #       - <size of the group> if i is a root
        self.d = [-1 for _ in range(N)]

    def root(self, x: int) -> int:
        if self.d[x] < 0:
            return x
        self.d[x] = self.root(self.d[x])
        return self.d[x]

    def unite(self, x: int, y: int) -> bool:
        x, y = self.root(x), self.root(y)
        if x == y:
            return False
        if self.d[x] > self.d[y]:
            x, y = y, x
        self.d[x] += self.d[y]
        self.d[y] = x
        return True

    def same(self, x: int, y: int) -> bool:
        return self.root(x) == self.root(y)

    def size(self, x: int):
        return -self.d[self.root(x)]

    def show(self):
        m = {}
        for n in range(len(self.d)):
            r = self.root(n)

            if r not in m:
                m[r] = [n]
            else:
                m[r].append(n)

        print("root -> childs")
        print("---------------------")
        for key in m:
            print("{} -> {}".format(key, m[key]))


def main():
    n, m = geta(int)

    uf = UnionFind(2*n)

    ans = n

    for _ in range(m):
        x, y, z = geta(int)

        united = False
        if z & 1 == 0:
            united = uf.unite(2*x-2, 2*y-2) and uf.unite(2*x-1, 2*y-1)
        else:
            united = uf.unite(2*x-2, 2*y-1) and uf.unite(2*x-1, 2*y-2)

        if united:
            ans -= 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 8216
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


int n, a=0, w=0, t=0,r=0; string s;

void print(string s, int k) {
    cout << s << " x " << k << endl;
}

void solve()
{
    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> s;
        if (s=="AC") a++;
        else if (s=="WA") w++;
        else if (s=="TLE") t++;
        else r++;
    }

    print("AC",a); print("WA",w); print("TLE",t); print("RE",r);


}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3640
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int n,a[2011],g[2011][2011];
vector<int> facp[2011];
vector<int> vp,v[20011];
bool used[2011],hs[20011];
bool vis[2011],visp[20011];
void dfs(int x);
void dfsp(int p)
{
	visp[p]=1;
	for(int i=0;i<v[p].size();i++)
	{
		if(!vis[v[p][i]])dfs(v[p][i]);
	}
}
void dfs(int x)
{
	vis[x]=1;
	if(used[x])return;
	for(int i=0;i<facp[x].size();i++)
	{
		if(!visp[facp[x][i]])dfsp(facp[x][i]);
	}
}
void dfsgraph(int v)
{
	dfs(v);
}
int tag[2011],mn[2011];
int main()
{
	geti(n);
	for(int i=1;i<=n;i++)geti(a[i]);
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
	{
		for(int j=i;j<=n;j++)
		{
			g[i][j]=g[j][i]=__gcd(a[i],a[j]);
		}
	}
	for(int i=1;i<=n;i++)
	{
		int x=a[i];
		for(int j=2;j*j<=x;j++)
		{
			if(x%j==0)
			{
				facp[i].PB(j);
				while(x%j==0)x/=j;
				vp.PB(j);
			}
		}
		if(x>1)facp[i].PB(x),vp.PB(x);
	}
	sort(vp.begin(),vp.end());
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<facp[i].size();j++)
		{
			facp[i][j]=lower_bound(vp.begin(),vp.end(),facp[i][j])-vp.begin();
			v[facp[i][j]].PB(i);
		}
	}
	for(int i=0;i<=n+1;i++)mn[i]=Imx;
	for(int i=1;i<=n;i++)
	{
		memset(vis,0,sizeof(vis));
		memset(visp,0,sizeof(visp));
		int cur=-1;
		for(int j=1;j<=n;j++)
		{
			if(used[j])continue;
			if(mn[tag[j]+1]>=a[j])
			{
				if(!vis[j])
				{
					dfsgraph(j);
					cur=j;
				}
			}
		}
		assert(cur!=-1);
		for(int j=1;j<=n;j++)if(g[cur][j]>1)tag[j]=i;
		used[cur]=1;
		puti(a[cur]);
		for(int j=1;j<=i;j++)mn[j]=min(mn[j],a[cur]);
	}
	return 0;
}

Measured memory_bytes: 16768
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repeq(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rep1eq(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i,n) cin >> v[i];

    sort(v.begin(),v.end());
    double ans = v[0];
    double max_ = 0;
    rep1(i,1,n){
        ans = (ans + v[i])/2.0;
    }

    cout << std::fixed << std::setprecision(14) << ans << endl;
    return 0;

}

Measured memory_bytes: 256