akhauriyash/Code-Regression huggingface dataset:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
v = LIST()
v.sort()

for i in range(1, N):
	v[i] = (v[i-1] + v[i])/2

print(v[N-1])


Measured memory_bytes: 5196
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

const int MOD = 1000000007;

int main(){
	int n;
	ll k;
	cin >> n >> k;
	vector<int> a(n);
	rep(snip_i, n) cin >> a.at(snip_i);
	vector<int> a1(n, 0);
	vector<int> a2(n, 0);
	rep(i, n){
		rep(j, n){
			if(i < j){
				if(a.at(i) > a.at(j)) a1.at(i)++;
			}
			if(a.at(i) > a.at(j)) a2.at(i)++;
		}
	}
	ll ans = 0;
	rep(i, n){
		ans = (ans + (ll)a1.at(i) * k) % MOD;
		ll temp = (k * (k-1) / 2) % MOD;
		ans = (ans + (ll)a2.at(i) * temp) % MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <math.h>
#include <tuple>
#include <queue>
#include <set>

using namespace std;

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

    string S;
    cin >> S;

    int ans_first_black;
    int ans_first_white;

    ans_first_black = 0;
    ans_first_white = 0;

    for(int i = 0; i < S.length(); i++){
        if(i%2 ==0){
            if(S[i] == '1'){
                ans_first_black++;
            }else{
                ans_first_white++;
            }
        }else{
            if(S[i] == '0'){
                ans_first_black++;
            }else{
                ans_first_white++;
            }
        }
    }

    if(ans_first_black < ans_first_white){
        cout << ans_first_black << endl;
    }else
    {
        cout << ans_first_white << endl;
    }

    return 0;
}


Measured memory_bytes: 512
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

S = sys.stdin.readline().rstrip()


def solve(S: str):
    if S[-1] == '1':
        return None
    S = S[:-1]
    if S[::-1] != S:
        return None
    if S[0] == '0':
        return None
    ret = [(1, 2)]
    v = 2
    for i in range(1, (len(S) + 1) // 2):
        ret.append((v, i + 2))
        if S[i] == '1':
            v = i + 2
    for i in range((len(S) + 1) // 2, len(S)):
        ret.append((v, i + 2))

    return ret


ans = solve(S)
if ans:
    for r in ans:
        print(*r)
else:
    print(-1)


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

const int mod = (int)1e9 + 7;

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<bool>> grid(h + 1,
                            vector<bool>(w + 1, false));  //'.':true, '#':false
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      char tmp;
      cin >> tmp;
      grid[i][j] = (tmp == '.');
    }
  }
  vector<vector<int>> r(h + 1, vector<int>(w + 1, 0));
  r[0][1] = 1;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (grid[i][j]) r[i][j] = (r[i - 1][j] + r[i][j - 1]) % mod;
    }
  }
  cout << r[h][w];
  return 0;
}

Measured memory_bytes: 4352
h, w = gets.chomp.split.map(&:to_i)

ary = h.times.map do
  line = gets.chomp
  if line.squeeze == "."
    next
  else
    line.chars
  end
end.compact

ary = ary.transpose.map do |line|
  if line.uniq == ["."]
    next
  else
    line
  end  
end.compact.transpose

ary.each do |line|
  puts line.join
end

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

int main()
{
    string str1,str2;
    cin>>str1>>str2;

    sort(str1.begin(),str1.end());
    sort(str2.begin(),str2.end());

    reverse(str2.begin(),str2.end());

    if(str1<str2)
		printf("Yes\n");
	else printf("No\n");

}


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

long long gcd(long long a, long long b)
{
  if (a < b)
  {
    a ^= b;
    b ^= a;
    a ^= b;
  }
  return b ? gcd(b, a % b) : a;
}
long long lcm(long long a, long long b)
{
  return a * b / gcd(a, b);
}

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

int solve()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, ans = 0, count = 0;
  string s;
  cin >> n;
  vector<long long> v(n, 0);
  vector<long long> x(n + 1, 0);
  vector<long long> y(n + 1, 0);
  for (long long i = 0; i < n; i++)
  {
    cin >> v[i];
  }

  for (long long i = 0; i < n; ++i)
  {
    x[i + 1] = gcd(x[i], v[i]);
  }
  for (long long i = n - 1; i >= 0; --i)
  {
    y[i] = gcd(y[i + 1], v[i]);
  }

  for (long long i = 0; i < n; ++i)
  {
    long long l = x[i];
    long long r = y[i + 1];
    chmax(ans, gcd(l, r));
  }
  cout << ans << endl;
  return 0;
}

signed main()
{
  solve();
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define int       long long int
#define vi        vector<int>
#define vii       vector<pii>
#define pii       pair<int, int>
#define mii       map<int, int>
#define pb        push_back
#define rev(v)    reverse(v.begin(), v.end())
#define all(v)    v.begin(), v.end()
#define rall(v)   v.rbegin(), v.rend()
#define endl      '\n'
#define F         first
#define S         second
#define PI        3.14159265359
#define MAXN      100007

const int mod = 1e9 + 7;

vi graph[MAXN], dp(MAXN);
vector<bool> vis(MAXN);

void dfs(int s)
{
   vis[s] = true;
   for (auto u : graph[s])
   {
      if (vis[u])
      {
         dp[s] = max(dp[s], 1 + dp[u]);
         continue;
      }
      dfs(u);
      dp[s] = max(dp[s], 1 + dp[u]);
   }
}

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

   int n, m;
   cin >> n >> m;
   for (int i = 0; i < m; ++i)
   {
      int x, y;
      cin >> x >> y;
      graph[x].push_back(y);
   }

   int ans = 0;
   for (int i = 1; i <= n; ++i)
   {
      if (!vis[i])
         dfs(i);
      ans = max(ans, dp[i]);
   }
   cout << ans << endl;
   return 0;
}

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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr ll mod = static_cast<ll>(1e9 + 7);

int n;
ll a[200005], b[200005];
std::pair<ll, ll> p[200005];
int main() {
	std::cin >> n;

	for (int i = 0; i < n; ++i) {
		std::cin >> a[i] >> b[i];

		p[i].first = b[i];
		p[i].second = a[i];
	}

	std::sort(p, p + n);

	bool check = true;
	ll time = 0;
	for (int i = 0; i < n; ++i) {
		time += p[i].second;

		if (time > p[i].first) {
			check = false;
			break;
		}
	}


	if (check)
		std::cout << "Yes" << std::endl;
	else
		std::cout << "No" << std::endl;

	return 0;
}


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

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

  if (S.at(0) != S.at(1) && S.at(1) != S.at(2) && S.at(2) != S.at(0))
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3552
// Target Expert 

/*
 * Author    : raj1307 - Raj Singh
 * Institute : Jalpaiguri Government Engineering College
 * Date      : 3.08.19
 */

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <iomanip>
#include <memory.h>
#include <assert.h>
using namespace std;


//#define DEBUG
#ifdef DEBUG
#define deb(...) cerr<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
#define debarr(a,n) cerr<<#a<<" : ";for(int i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
#define debmat(mat,row,col) cerr<<#mat<<" :\n";for(int i=0;i<row;i++) {for(int j=0;j<col;j++) cerr<<mat[i][j]<<" ";cerr<<endl;}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cerr<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	const char *comma=strchr(names+1,',');
	cerr.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}

#else
#define deb(...) {}
#define debarr(a,n) {}
#define debmat(mat,row,col) {}
#define endl "\n"
#endif

#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fr(i, a, b) for(int i = (a); i < (b); ++i)
#define fb(i, b, a) for(int i = (b); i > (a); --i)
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define rr return 
#define int long long
#define pb push_back
#define sz(x) ((int)x.size())
int max(int a,int b){if(a>b) return a; else return b;}
int min(int a,int b){if(a>b) return b; else return a;}

const int mod = 1000*1000*1000+7;
const int INF = 1e18 +5;

int powm(int a, int b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}


const int N = 1e5 + 5;
int n,m;
int x[N],y[N];
 
int mm[N]; 

vector<int>graph[N];
bool vis[N];


int dfs(int v){
	

	if(mm[v]!=-1)
		return mm[v];

	//deb(v,c,graph[v].size());
	mm[v]=0;
	for(auto i:graph[v]){
		//deb(*i,c+1);
		mm[v]=max(mm[v],1+dfs(i));
	}
	return mm[v];
}

 






 
 
 
 
void solve(){
 
 
	cin>>n>>m;
	int u,v;
	for(int i=1;i<=m;++i){
        
        cin>>u>>v;
        //deb(u,v);
        graph[u].pb(v);
    }
    int c=0;
	memset(mm,-1,sizeof(mm));
 	int ans=0;
	//deb(mm);
	fr(i,1,n+1){
		ans=max(ans,dfs(i));	
		
	}
	
	cout<<ans;


	
 
}
 



signed main() {
	fio;
	
	cout<<fixed<<setprecision(10);
	int t=1;
//	cin>>t;
	while(t--) {
		solve();
	}

	
	return 0;
}


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

int main() {
    int n; cin >> n;
    vector<int> add(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        int p; cin >> p;
        add[p] = i - 1;
    }
    for (int i = 1; i <= n; i++) {
        cout << n * i + add[i] << " ";
    }
    cout << endl;
    for (int i = 1; i <= n; i++) {
        cout << n * (n + 1 - i) << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <string.h>
#include <stdio.h>
#include <queue>
#include <limits.h>
#include <stack>
#include <set>
#include <map>

#define P pair
#define MP make_pair

typedef long long int llint ;

using namespace std;

int main()
{
	string s;
	cin>>s;
	s[3]='8';
	cout<<s;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

//int GCD(const int a, const int b){
////   const int& _a = max(a,b);
////   const int& _b = min(a,b);
//   if(a % b == 0){
//      return b;
//   }
//   else{
//      return GCD(b, a % b);
//   }
//}

int GCD(int a, int b){
   return b ? GCD(b, a%b) : a;
}

int LCM(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   return (_a*_b)/(GCD(_a, _b));
}

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

   // init accumulate GCD
   vector<int> left(N+1, 0), right(N+1, 0);
   for(int i = 0; i < N; i++){
      left[i+1] = GCD(left[i], a[i]);
   }
   for(int i = N-1; i >= 0; i--){
      right[i] = GCD(right[i+1], a[i]);
   }

   int ans = 0;
   for(int i = 0; i < N; i++){
      ans = max(ans, GCD(left[i], right[i+1]));
   }

   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 1408
package main

import "fmt"

func solve() {
	var A, B, C, D int
	fmt.Scan(&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")
	}
}

func main() {
	solve()
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = 1000000007;
const long long INF = 1LL << 60;

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

int main()
{   
    int a,b,c; cin >> a >> b >> c;
    cout << a*b/2 << endl;
}
    

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int64_t const INF = 1e18;

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  std::vector<int64_t> A(N), S(N+1, 0);
  for(int i = 0; i < N; ++i) std::cin >> A[i];
  for(int i = 0; i < N; ++i) S[i+1] = S[i] + A[i];
  int64_t P[4];
  P[0] = A[0];
  P[1] = A[1];
  P[2] = A[2];
  P[3] = S[N] - S[3];
  int j = 1, l = 3;
  int64_t ans = INF;
  for(int k = 2; k < N-1; ++k) {
    while(j < k-1 && std::abs(P[0]-P[1]) > std::abs(P[0]+A[j]-(P[1]-A[j]))) {
      P[0] += A[j];
      P[1] -= A[j];
      ++j;
    }
    while(l < N-1 && std::abs(P[2]-P[3]) > std::abs(P[2]+A[l]-(P[3]-A[l]))) {
      P[2] += A[l];
      P[3] -= A[l];
      ++l;
    }
    ans = std::min(ans, *std::max_element(P, P+4) - *std::min_element(P, P+4));
    P[1] += A[k];
    P[2] -= A[k];
  }
  fin(ans);
  return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define INF 10000000000000009
#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl



signed main(){
    int D;
    cin >> D;
    cout << "Christmas";
    REP(i,25-D){
        cout << " Eve";
    }
    cout << endl;
    return 0;
}   


Measured memory_bytes: 256
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat[i])


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
# sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = True
show_flg = False

def f(x):
    return x


# 二分探索 ok ng
def main():
    N = I()
    L = LI()
    # L = L.sort()
    R = sorted(L, reverse=True)
    L = R[::-1]
    # print(R)
    ans = 0

    for i in range(N):
        for j in range(i+1, N):
            a = R[i]
            b = R[j]
            remain = a - b + 1
            idx = bisect.bisect_left(L, remain)
            c_idx = N - (idx + 1)
            if j < c_idx:
                c = (c_idx - j)
                ans += c
                # print('Need', remain, 'c', c)
                # print('a', a)
                # print('b', b)
                # print(i, j, c_idx - j)
                # print('a', a, 'b', b, c_idx, L[:idx])

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 43224
import std.stdio, std.algorithm, std.range, std.conv, std.meta;
/*
  a1+b1, a1+b2, a1+b3
  a2+b1, a2+b2, a2+b3
  a3+b1, a3+b2, a3+b3
 */
void main() {
    int[3*3] _c;
    ref c(size_t i, size_t j) {
        return _c[i * 3 + j];
    }
    ref ct(size_t i, size_t j) {
        return _c[j * 3 + i];
    }
    foreach (i; 0..3) {
        foreach (j, n; readln.split.map!(to!int).enumerate) {
            c(i, j) = n;
        }
    }
    foreach (f; AliasSeq!(c, ct)) {
        foreach (i; 0..2) {
            foreach (j; i..3) {
                auto d0 = f(i, 0) - f(j, 0); // a[i] - a[j] or b[i] - b[j]
                auto d1 = f(i, 1) - f(j, 1);
                if (d0 != d1) {
                    writeln("No");
                    return;
                }
                auto d2 = f(i, 2) - f(j, 2);
                if (d0 != d2) {
                    writeln("No");
                    return;
                }
            }
        }
    }
    writeln("Yes");
}

Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

const long mod = 1e9 + 7;

#define REP(i, n)  for(int i = 0; i < (int)n; ++i)

int main() {
    int N;
    int a;
    cin >> N;
    int A[100010] = {};
    REP(i, N) {
        cin >> a;
        A[a]++;
    }
    int init = 0;
    if (N % 2 == 0) {
        init = 1;
    }
    for (int i = init; i <= N; i += 2) {
        if (i == 0) {
            if (A[i] != 1) {
                cout << 0 << endl;
                return 0;
            }
        } else if (i != 0) {
            if (A[i] != 2) {
                cout << 0 << endl;
                return 0;
            }
        }
    }
    long out = 1;
    REP(i, N / 2) out =out* 2 %mod;
    cout << out << endl;
    return 0;
}

Measured memory_bytes: 640
n, m, l = input().split()
n = int(n)
m = int(m)
l = int(l)
A = [[0] * m for i in range(n)]
B = [[0] * l for i in range(m)]
for i in range(n):  #inputA
    line = input().split()
    for j in range(m):
        A[i][j] = int(line[j])

for i in range(m):  #inputB
    line = input().split()
    for j in range(l):
        B[i][j] = int(line[j])

# 行列の積計算
C = [[0] * l for i in range(n)]
for i in range(n):
    for j in range(l):
        for k in range(m):
            C[i][j] += A[i][k] * B[k][j]

for i in range(n):  #outputC
    for j in range(l):
        if j != l - 1:
            print("%d " %C[i][j], end="")
        else:
            print(C[i][j])


Measured memory_bytes: 7040
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

long long getint(string str) {
	long long ret = 0;

	for (int i = 0; i < str.size(); i++) {
		ret = ret * 10 +(str[i] - '0');
	}

	return ret;
}

int main() {

	string s; cin >> s;

	if (s.size() == 1) {
		cout << s << endl;
		return 0;
	}
	
	int l = s.size()-1;

	long long ans = 0;

	reverse(s.begin(), s.end());

	for (int bit = 0; bit < (1 << l); bit++) {
		
		string tmp ="";
		tmp += s[0];
		
		for (int i = 0; i < l; i++) {
			if ((bit >> i) & 1) {
				ans += getint(tmp);
				tmp = s[i+1];
			}
			else {
				tmp= s[i+1]+tmp;
			}

			if (i == l - 1) {
				ans += getint(tmp);
			}
		}
	}

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

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe


# my functions here!
#標準エラー出力
def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)






def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
#入力（後でいじる）
        
#input
def resolve():
    A=[0,1,2,3]
    A[int(input())]=0
    A[int(input())]=0
    print(sorted(A)[-1])
    #print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])
#if __name__=="__main__":resolve()
"""
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""

import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3
1"""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """1
2"""
        output = """3"""
        self.assertIO(input, output)

if __name__=="__main__":resolve()

Measured memory_bytes: 84844
import sys

def main():
  n, k = list(map(int, input().split()))
  h = [int(input()) for i in range(n)]
  h.sort(reverse=True)

  cnt = sys.maxsize
  for i in range(n - k + 1):
    if cnt > h[i] - h[i+k-1]:
      cnt = h[i] - h[i+k-1]
  print(cnt)

if __name__ == '__main__':
  main()

Measured memory_bytes: 7384
N = int(input())
A = tuple(map(int,input().split()))
mod = 10**9+7
ans = 0
s = (sum(A) - A[0])%mod
for i in range(N-1):
    if s < 0:
        s += mod
    ans += A[i]*s%mod
    ans %= mod
    s -= A[i+1]
print(ans)

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

using namespace std;

int main()
{
	long long n;
	cin >> n;
	int ans = 10;
	for (long long i = 1; i <= sqrt(n); i++)
		if (n % i == 0)
		{
			int ca = 0, cb = 0;
			long long a = i, b = n / i;
			while (a)
			{
				a /= 10;
				ca++;
			}
			while (b)
			{
				b /= 10;
				cb++;
			}
			ans = min(ans, max(ca, cb));
		}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<queue>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<double,double> Pdouble;

const int INF = 2000000000;
const int MOD = 1000000007;

int main() {
  ll h,w;
  cin >> h >> w;
  if(h==1 || w == 1){
    cout << 1 << endl;
    return 0;
  }
  ll answer;
  if(h%2 == 1&& w%2 == 1){
    answer = ((h*w)+1)/2;
  }else{
    answer = h*w/2;
  }
  cout << answer << endl;
}

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

using namespace std;

#define topper top //XDDDDDDD

#define mp make_pair
#define pb push_back
#define db(x) cerr << #x << " == " <<  x << endl;
#define _ << " " <<

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

const long double EPS = 1e-9;
const int N=1e5+5;
const int MOD=1e9+7;
const int INF=0x3f3f3f3f;

vi adj[N];
int n, vis[N], leaves[N], f[N], paths[N];
int ans;

int dfs(int u) {
  vis[u] = 1;
  for(int v : adj[u]) if(!vis[v]) {
    leaves[u] += dfs(v);
  }

  leaves[u] += (adj[u].size() == 1);
  return leaves[u];
}

void get_ans(int u) {
  vis[u] = 1;
  if(adj[u].size() <= 2) paths[u] = 1;

  for(int v : adj[u]) if(!vis[v]) {
    get_ans(v);
    paths[u] = paths[u] and paths[v];
    f[u] += paths[v];
  }
}

int main(){
  scanf("%d", &n);
  for(int i=1; i<n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    adj[u].pb(v); adj[v].pb(u);
  }

  bool path = true; int l = 0;
  for(int i=0; i<n; i++) path = path and (adj[i].size() == 2 or adj[i].size() == 1);
  for(int i=0; i<n; i++) l += (adj[i].size() == 1);
  if(path and l == 2) return printf("1\n"), 0; 

  int root;
  for(int i=0; i<n; i++) if(adj[i].size() > 2){
    root = i;
  }

  get_ans(root);
  ans = 0;
  for(int i=0; i<n; i++) ans = ans + max(0, f[i] - 1);

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

  return 0;
}



Measured memory_bytes: 9472
#include <stdio.h>
#include <math.h>

#define DEBT_BASE 100000

int main ( void )
{
    int i, weeks, debt = DEBT_BASE;

    if ( scanf( "%d", &weeks ) != EOF )
    {
        for ( i = 0; i < weeks; i++ )
        {
            debt = ceil( debt * 1.05 / 1000 ) * 1000;
        }
        printf( "%d\n", debt);
    }
    else
    {
        fputs("Syntax Error.", stderr);
    }

    return 0;
}

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


void solve()
{
	ll n;
	cin>>n;
	ll a[n];
	ll m=0,m2=0,m4=0;
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]%4==0)
			m4++;
		else if(a[i]%2==0)
			m2++;
		else
			m++;
			
	}
	if(m2==0)
	{
		if(m-m4<=1)
			cout<<"Yes";
		else
			cout<<"No";
		return;
	}
	else
	{
		if(m<=m4)
			cout<<"Yes";
		else
			cout<<"No";
		return;
	}
	return;
}
int main()
{
	fast;
	int q;
	q=1;
	// cin>>q;
	while(q--)
	{
		solve();
	}
	return 0;
}

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

int W,H;
int count=0;

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


vector<vector<char> > M;

void go(int x,int y){
	if(x<0 || y<0 || x>=W || y>=H) return;
	if(M[y][x]=='.' || M[y][x]=='@'){
		count++;
		M[y][x]='#';
		for(int r=0;r<4;r++){
			go(x+dx[r],y+dy[r]);
		}
	}
}

void solve(){
	count=0;

	M.clear();
	M.resize(H,vector<char>(W));

	int sx,sy;
	for(int y=0;y<H;y++){
		for(int x=0;x<W;x++){
			char t;
			cin>>t;
			M[y][x]=t;
			if(t=='@'){
				sx=x;sy=y;
			}
		}
	}

	go(sx,sy);
	cout<<count<<endl;

}


int main(){
	while(cin>>W>>H){
		if(W==0) return 0;
		solve();
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
	vector<int> data(10);
	for(int i = 0; i < 10; i++)cin >> data[i];
	
	sort(data.begin(), data.end());
	reverse(data.begin(), data.end());
	
	cout << data[0] << endl;
	cout << data[1] << endl;
	cout << data[2] << endl;
	
	return 0;
}

Measured memory_bytes: 1208
n,k,q = map(int,input().split())
a = {i: 0 for i in range(1,n+1)}
points = []

for i in range(1,q+1):
    x = int(input())
    if x in a:
        a[x] += 1
    else: 
        a[x] = 1

tot = sum(a.values())
tot = -tot

for i in range(1,n+1):
    if tot + a[i] + k > 0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 15084
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }

int a[11][11];

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

	int n, d;
	cin >> n >> d;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < d; j++) cin >> a[i][j];
	}
	int res = 0;
	for(int i = 0; i < n; i++){
		for(int j = i + 1; j < n; j++){
			int temp = 0;
			for(int k = 0; k < d; k++){
				temp += abs(a[i][k] - a[j][k]) * abs(a[i][k] - a[j][k]);
			}
			ld root = sqrt(temp);
			if(root * root == floor(root) * floor(root)) res++;
		}
	}
	cout << res;
}

Measured memory_bytes: 384
import sys
readline = sys.stdin.readline
write = sys.stdout.write

N, Q = map(int, input().split())
INF = 2**31-1

LV = (N-1).bit_length()
N0 = 2**LV
data = [INF]*(2*N0)
lazy = [None]*(2*N0)

def gindex(l, r):
    L = (l + N0) >> 1; R = (r + N0) >> 1
    lc = 0 if l & 1 else (L & -L).bit_length()
    rc = 0 if r & 1 else (R & -R).bit_length()
    for i in range(LV):
        if rc <= i:
            yield R
        if L < R and lc <= i:
            yield L
        L >>= 1; R >>= 1

def propagates(*ids):
    for i in reversed(ids):
        v = lazy[i-1]
        if v is None:
            continue
        lazy[2*i-1] = data[2*i-1] = lazy[2*i] = data[2*i] = v
        lazy[i-1] = None

def update(l, r, x):
    *ids, = gindex(l, r)
    propagates(*ids)

    L = N0 + l; R = N0 + r
    while L < R:
        if R & 1:
            R -= 1
            lazy[R-1] = data[R-1] = x
        if L & 1:
            lazy[L-1] = data[L-1] = x
            L += 1
        L >>= 1; R >>= 1
    for i in ids:
        data[i-1] = min(data[2*i-1], data[2*i])

def query(l, r):
    propagates(*gindex(l, r))
    L = N0 + l; R = N0 + r

    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = min(s, data[R-1])
        if L & 1:
            s = min(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s


ans = []
for q in range(Q):
    t, *cmd = map(int, readline().split())
    if t:
        s, t = cmd
        ans.append(str(query(s, t+1)))
    else:
        s, t, x = cmd
        update(s, t+1, x)

write("\n".join(ans))
write("\n")



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

int main() {
  int N;
  cin >> N;
  
  vector<int> p(N, 0);
  for (int i = 0; N>i; i++) {
    cin >> p.at(i);
  }
  
  vector<int> k(N,0);
  for (int i = 0; N>i; i++) {
    k.at(i) = p.at(i);
  }
  sort(k.begin(),k.end());
  
  int kazu = 0;
  for (int j =0; N > j; j++) {
    if (k.at(j) != p.at(j)){
      kazu++;
    }
  }
  if (kazu == 0 or kazu ==2) {
    cout << "YES" <<endl;
  } else {
    cout << "NO" << endl;
  }
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d;
    cin >> a >> b>>c>>d;
  if((a+b)>(c+d)){
    cout << "Left" << endl;
  }else if((a+b)==(c+d)){
    cout << "Balanced" << endl;
  }else{
    cout<< "Right" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int n, l;
vector<string> s;

bool comp(string a, string b)
{
	return (a + b) < (b + a);
}

int main()
{
	cin >> n >> l;
	s.resize(n);

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

	sort(s.begin(), s.end(), comp);

	for (int i = 0; i < n; i++) {
		cout << s[i];
	}

	cout << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>

#define _GLIBCXX_DEBAC
using namespace std;
	


int main() {
	int n, m;
	cin >> n;
	vector<string> s(n);
	for (int i = 0; i < n; i++) {
		cin >> s.at(i);
	}
	cin >> m;
	vector<string> t(m);
	for (int i = 0; i < m; i++) {
		cin >> t.at(i);
	}

	int  b=0;
	for (int i = 0; i < n; i++) {
		int a = 0;
		for(int j=0;j<n;j++){
			if (s[j] == s[i]) a+=1;
		}
		for (int j = 0; j < m; j++) {
			if (t[j] == s[i]) a -= 1;
		}
		if (b < a) b = a;
	}
	cout << b << endl;

	
	return 0;
}










Measured memory_bytes: 256
//Never stop trying
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef string str;
typedef long long ll;
#define int ll
typedef double db;
typedef long double ld;

typedef pair<int,int> pi;
#define fi first
#define se second

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;

#define pb push_back
#define eb emplace_back
#define pf push_front

#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"

const int MOD = 1e9+7; //998244353
const ll INF = 1e18;
const int nx[4]={0,0,1,-1}, ny[4]={1,-1,0,0}; //right left down up

void IO(){
#ifndef ONLINE_JUDGE 
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout); 
#endif 
}

int32_t main(){
   boost;
   IO();
	
	str s; cin>>s;
	int x=0;
	for(auto it: s) x+=it-'0',x%=9;

	if(x==0) cout << "Yes"<< endl;
	else cout << "No" << endl;

   return 0;
}



Measured memory_bytes: 3800
#include<iostream>
#include<stdlib.h>
#include<cstdio>
using namespace std;

struct node{
  int key;
  node *prev,*next;
};

node *nil;

void init(){
  nil= (node *)malloc(sizeof(node));
  nil->next =nil;
  nil->prev=nil;
}

void insert(int key){
  node *x= (node *)malloc(sizeof(node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

node* search(int key){
  node * cur;
  for(cur=nil->next;cur!=nil;cur=cur->next)if(cur->key==key) return cur;
  return cur;
}

void delnode(node *t){
  if(t==nil) return;
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}


void delFL(int n){
  if(n)  delnode(nil->next);
  else delnode(nil->prev);
}
	   
int main(){
  int n,key;
  cin>>n;
  char str[1000];
  init();
  for(int i=0;i<n;i++){
    scanf("%s",str);
    if(str[6]=='F') delFL(1);
    else if(str[6]=='L') delFL(0);
    else{
      scanf("%d",&key);
      if(str[0]=='i')insert(key);
      else if(str[0]=='d') delnode(search(key));
    }
  }
  
  node * cur;
  for(cur=nil->next;cur->next!=nil;cur=cur->next) cout<<cur->key<<" ";
  cout<<cur->key<<endl;
   return 0;
}

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

// 未AC
int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  int count = 1, ans = 0;
  if (N==1) cout << 1 << endl;
  else {
    for (int i = 0; i < N-1; i++) {
      if (A.at(i) == A.at(i+1) && i+1 != N-1) {
        count++;
      }
      else if (A.at(i) == A.at(i+1) && i+1 == N-1) {
        count++;
        if (count%2==1) ans++;
      }
      else {
        if (count%2==1 && i != N-2) ans++;
        else if (count%2==1 && i == N-2) ans += 2;
        count = 1;
      }
    }
    cout << ans << endl;
  }

}

Measured memory_bytes: 1024
loop do
  n, m = gets.chomp.split.map &:to_i
  break if n == 0 && m == 0

  t = (0...n).inject(Array.new){|s| s << gets.to_i}
  h = (0...m).inject(Array.new){|s| s << gets.to_i}
  tm = t.inject(0){|sum, i| sum += i}
  hm = h.inject(0){|sum, i| sum += i}
  target = ( tm > hm ? tm : hm ) - ( tm - hm ).abs / 2

  result = nil
  catch :fin do
    t.each do |ti|
      h.each do |hi|
        if ( tm - ti + hi == target && hm - hi + ti == target )
          result = [ti, hi]
          throw :fin
        end
      end
    end
  end

  puts result.nil? ? -1 : "#{result[0]} #{result[1]}"
end

Measured memory_bytes: 6120
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

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

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll d;
    cin >> d;
    vector<ll> z(d);
    for (int i = 0; i < d; i++) {
        cin >> z[i];
    }
    vector<vector<ll>> x(d, vector<ll>(26));
    for (int i = 0; i < d; i++) {
        for (int j = 0; j < 26; j++) {
            cin >> x[i][j];
        }
    }
    vector<ll> ans(d);
    for (int i = 0; i < d / 26; i++) {
        vector<bool> flag(26, false);
        for (int j = 0; j < 26; j++) {
            ll mx = 0;
            ll atai = 0;
            for (int k = 0; k < 26; k++) {
                if (flag[k] == false) {
                    mx = max(x[i * 26 + j][k], mx);
                    if (mx == x[i * 26 + j][k])atai = k;
                }
            }
            flag[atai] = true;
            ans[i * 26 + j] = atai + 1;
        }
    }
    ll mix = 0;
    ll ataii = 0;
    for (int k = 0; k < 26; k++) {
        mix = max(x[364][k], mix);
        if (mix == x[364][k])ataii = k;
    }
    ans[364] = ataii;
    for (int i = 0; i < d; i++) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
const int mod=1e9+7;

int main(){
  int n,q;cin>>n>>q;
  string s;cin>>s;
  char t[q],d[q];
  rep(i,q)cin>>t[i]>>d[i];
  int ok=-1;
  int ng=n;
  while(ng-ok>1){
    int mid=(ng+ok)/2;
    rep(i,q){
      if(s[mid]==t[i]){
        if(d[i]=='L')--mid;
        else ++mid;
      }
    }
    if(mid<0){
      ok=(ng+ok)/2;
    }
    else ng=(ng+ok)/2;
  }
  int lok=ok+1;
  ok=n;
  ng=-1;
  while(ok-ng>1){
    int mid=(ng+ok)/2;
    rep(i,q){
      if(s[mid]==t[i]){
        if(d[i]=='L')--mid;
        else ++mid;
      }
    }
    if(mid==n){
      ok=(ng+ok)/2;
    }
    else ng=(ng+ok)/2;
  }
  int rok=n-ok;
  cout<<max(n-(lok+rok),0)<<endl;
}


Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
const int N = 1001;
const int mod = 1e9 + 7;
char arr[N][N];
int dp[N][N];
int r;
int c;

int calc(int i, int j)
{
	if(i >= r || j >= c)
		return 0;
	if(i == r-1 && j == c-1)
		return 1;
	if(dp[i][j] != -1)
		return dp[i][j];
	if(arr[i][j] == '.')
	{
		int val1 = calc(i+1, j);
		int val2 = calc(i, j+1);
		return dp[i][j] = (val1 % mod + val2 % mod) % mod;
	}
	else
		return 0;
}
int main() {
	cin >> r >> c;
	for(int i = 0; i < r; i++)
	{
		for(int j = 0; j < c; j++)
		{
			cin >> arr[i][j];
		}
	}
	memset(dp, -1, sizeof dp);
	cout << calc(0, 0) << endl;
	return 0;
}

Measured memory_bytes: 8552
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

#include<unistd.h>
template <int size>
struct Buffer{
    char buff[size];
    int idx = 0;
    Buffer(){ read(0, buff, size); }
    template <class T>
    void next(T& ret){
        // int ret = 0;
        ret = 0;
        while(!(buff[idx] & 0x10)){ idx++; }
        while(buff[idx] & 0x10){ ret = ret * 10 + buff[idx++] - '0'; }
        // idx++;
        // while(!isdigit(buff[idx])){ idx++; }
        // while(isdigit(buff[idx])){ ret = ret * 10 + buff[idx++] - '0'; }
        // return ret;
    }
};
struct FastInput {
    Buffer<1 << 22> buf;
    template <class T>
    FastInput& operator >> (T& num) { buf.next(num); return *this; }
    // FastInput& operator >> (T& num) { num = buf.next(); return *this; }
    void tie(int){ }
    template <class S, class T>
    friend FastInput& operator >> (FastInput& in, pair<S, T>& p){ return in >> p.first >> p.second; }
    template <class T>
    friend FastInput& operator >> (FastInput& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
};
FastInput fin;
#define cin fin

enum { SIZE = 1 << 20 };
char buf[SIZE];
int accs[512][512];
pair<int, int> pqs[100000];
int main(){
    int n, m, q;
    cin >> n >> m >> q;
    for(int i = 0; i < m; i++){
        int l, r;
        cin >> l >> r;
        accs[1][r]++;
        accs[l + 1][r]--;
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            accs[i + 1][j] += accs[i][j];
            accs[i][j] += accs[i][j - 1];
        }
    }
    char* ptr = buf + SIZE;
    for(int i = 0; i < q; i++){
        cin >> pqs[i].first >> pqs[i].second;
    }
    for(int i = q - 1; i >= 0; i--){
        int p = pqs[i].first, q = pqs[i].second;
        *--ptr = '\n';
        div_t num2;
        num2.quot = accs[p][q];
        do{
            num2 = div(num2.quot, 10);
            *--ptr = num2.rem | '0';
        }while(num2.quot);
    }
    write(1, ptr, buf + SIZE - ptr);
}


Measured memory_bytes: 6784
s=input()
ans=False
if s[0]==s[1]:
    if s[0]!=s[2] and s[2]==s[3]:
        ans=True
elif s[0]==s[2]:
    if s[0]!=s[1] and s[1]==s[3]:
        ans=True
elif s[0]==s[3]:
    if s[0]!=s[1] and s[1]==s[2]:
        ans=True
if ans:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
import math
N=int(input())
cord=[]
mylist=[]
answer=0
for i in range(N):
    cord=list(map(int,input().split()))
    mylist.append(cord)
    
    
#print(mylist)


def distance(a,b):
    l=math.sqrt((mylist[a][0]-mylist[b][0])**2+(mylist[a][1]-mylist[b][1])**2)
    return l

for i in range(N-1):
    for j in range(i+1,N):
        #print(i,j)
        answer+=distance(i,j)
        
        
print(answer*2/N)

Measured memory_bytes: 3064
N, K = map(int, input().split())

def cmb(n, r, mod):
    if (r<0 or r>n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N1 = 2000
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル


for i in range(2, N1 + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod//i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

for i in range(1, K+1):
    a = cmb(K-1, K-i, mod)
    b = cmb(N-K+1, i, mod)
    print(a * b % mod)


Measured memory_bytes: 43888