akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
int mod=1e9+7;

double dp[3001][3001];


double solve(std::vector<double> &v,int i,int x)
{
    if (x<=0)
        return 1;
    if (i==0)
        return 0;
    if (dp[i][x]> -0.9)
        return dp[i][x];
    dp[i][x]=v[i]*solve(v,i-1,x-1)+(1-v[i])*solve(v,i-1,x);
    return dp[i][x];
}


signed main()
{

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);


    memset(dp,-1.00,sizeof(dp));
    int n,m;
    cin>>n;
    m=(n+1)/2;
    std::vector<double> v(n+1);
    
    for (int i=1;i<=n;++i)
        cin>>v[i];

    cout<<fixed<<setprecision(9)<<solve(v,n,m)<<endl;
}


Measured memory_bytes: 74336
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

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

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

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

    int sum = 0;
    for ( int i = 0; i < n - 1; i++ ) {
        sum += l[i];
    }

    if ( sum > l[n-1] ) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

bool isPalindrome(int x){
  string s = to_string(x);
  int n=s.length();
  bool ret=true;
  repeat(i,(n+1)/2){
    ret &= s[i]==s[n-1-i];
  }
  return ret;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;cin>>N;
  map<string,int> mp;
  vint v;
  repeat(i,N){
    string s;cin>>s;
    if(mp.find(s)==mp.end()){
      mp[s]=v.size();
      v.push_back(0);
    }
    v[mp[s]]++;
  }
  int M;cin>>M;
  repeat(i,M){
    string t;cin>>t;
    if(mp.find(t)==mp.end()){
      mp[t]=v.size();
      v.push_back(0);
    }
    v[mp[t]]--;
  }
  int mx=0;
  for(int i:v){
    mx = max(mx,i);
  }
  //debugArray(v,v.size());
  cout << mx << endl;
  return 0;
}


Measured memory_bytes: 256
import math
import itertools

n = int(input())
l = []
for _ in range(n):
  a = list(map(int,input().split()))
  l.append(a)

dis = 0
for case in itertools.permutations(l):
  for i in range(n-1):
    dis += math.sqrt((case[i][0]-case[i+1][0])**2+(case[i][1]-case[i+1][1])**2)

result = dis/math.factorial(n)

print(result)

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

int c[26];
int64_t s[366][26];

int64_t eval(const vector<int> &state, int d){
    int last[26] = {0};
    int64_t csum = 0;
    for(int i=0;i<26;++i) csum += c[i];
    int64_t decl = -csum;
    int64_t score = 0;

    for(int i=1;i<=d;++i){
        score += s[i][state[i]];
        decl += (i - last[state[i]])*c[state[i]];
        last[state[i]] = i;
        score += decl;
        decl -= csum;
    }
    return score;
}

vector<int> beam(int D, int w){
    map<int64_t, vector<int>, greater<int64_t>> mp;
    for(int i=0;i<26;++i){
        mp[eval(vector<int>{2, i}, 1)] = vector<int>{2, i};
    }
    for(int d=2;d<=D;++d){
        int cnt = 0;
        vector<vector<int>> states;
        for(auto p: mp){
            states.push_back(p.second);
            ++cnt;
            if(cnt >= w) break;
        }
        mp.clear();
        for(auto v: states){
            for(int i=0;i<26;++i){
                vector<int> state{v};
                state.emplace_back(i);
                mp[eval(state, d)] = state;
            }
        }
    }
    return mp.begin()->second;
}

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

    int d;
    cin >> d;
    for(int i=0;i<26;++i) cin >>c[i];
    for(int i=1;i<=d;++i){
        for(int j=0;j<26;++j) cin >> s[i][j];
    }

    auto ans = beam(d, 250);
    for(int i=1;i<=d;++i) cout << ans[i] + 1 << endl;

    return 0;
}

Measured memory_bytes: 12816
#include <iostream>

using namespace std;

int main() {
    int p,q,r,a,b,c,s;
    cin>>p>>q>>r;
    a=p+q;
    b=q+r;
    c=r+p;
    if(a<=b && a<=c)
    {
        s=a;
    }
    if(b<=a && b<=c)
    {
        s=b;
    }
    if(c<=a && c<=b)
    {
        s=c;
    }
    cout<<s;
    
    
    
    return 0;
}

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

int64_t poww(int64_t a, int64_t b)
{
    int64_t ans = 1;
    for (int64_t i = 0; i < b; i++)
    {
        ans *= a;
    }

    return ans;
    
}

int main()
{
    int64_t H;
    cin >> H;
    int64_t ans = 0;
    int64_t count = 0;

    while (H != 1)
    {
        H /= 2;
        ans += poww(2, count);
        count++;
    }
    
    ans += poww(2, count);
    cout << ans;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
 public static void main(String args[]){
  Scanner sc = new Scanner(System.in);
  int n = sc.nextInt();
  int a[] = new int[n];
  for(int i=0;i<n;i++){
   a[i] = sc.nextInt();
  }
  for(int i=a.length-1;i>=0;i--){
   if(i!=a.length-1) System.out.print(" ");
   System.out.print(a[i]);
  }
  System.out.println();
 }
}


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

int main(){
    string s,s2,s3;
    cin >> s;
    ll n;
    n=s.size();
    ll k=0;
    ll ba=0;

    

    rep(i,n-2){
        //cout << s << endl;
        s2=s.substr(i,3);
        s3=s[i];
        
        if(s2=="ABC"){
            s[i]='B';
            s[i+1]='C';
            s[i+2]='A';
            if(ba>=1){
                s[i+1]='A';
            }
            
            ++k;
            k+=ba;
            if(ba>=1){
            --ba;
            }
            
        }
        else{
            if(s3=="A"){
            ++ba;
        }
        else{
            ba=0;
        }
        }
    }

    cout << k << endl;
    

    return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
#include<math.h>
int main()
{
    double x1,x2,y1,y2;
    double p=0,x,a=0,b=0;
    scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
 
    a=x2-x1;
 
    b=y2-y1;
 
    x=a*a+b*b;
 
    p=sqrt(x);
    printf("%.8lf\n",p);
    return 0;
}


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

float dist(vector<int>& a, vector<int>& b, int i, int j) {
	float d;
	d = sqrt(((a[i] - a[j]) * (a[i] - a[j])) + ((b[i] - b[j]) * (b[i] - b[j])));
	return d;
}

int main() {
	int n; cin >> n;
	vector<int> a(n), b(n);
	float ans = 0;

	for (int i = 0; i < n; i++) {
		int x, y; cin >> x >> y;
		a[i] = x;
		b[i] = y;
	}

	for (int i = 0; i < n - 1; i++) {
		for (int j = i + 1; j < n; j++) {
			ans = ans + dist(a, b, i, j);
		}
	}

	ans = ans * 2 / n;
	cout << setprecision(12) << ans;
}

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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

class Solution {
public:
	void solve() {
		int n;
		cin >> n;
		vector<string> s(n);
		vector<int> t(n, 0);
		for(int i=0; i < n; i++)cin >> s[i] >> t[i];
		string x;
		cin >> x;
		int ans = 0;
		bool flag = false;
		for(int i=0; i < n; i++){
			if(flag)ans += t[i];
			if(s[i] == x)flag = true;
		}
		cout << ans << "\n";
		
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 256
N = int(input())
L = list(map(int, input().split()))
L.sort()
from bisect import bisect_left
ans = 0

for a in range(0, N-2):
  for b in range(a+1, N-1):
    t = L[a] + L[b]
    idx = bisect_left(L,t)
    ans += max(0, idx-b-1)

print(ans)

Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int main()
{
	double N;
	double count=0;
	cin >> N;
	for(int i=1;i<=N;i++)
	{
		if(N==1)
		{
			count=1;
			break;
		}
		if(i%2!=0)
		count++;
	}
	printf("%.10lf",count/N);
	return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
diff_list = [n - a_list[-1] + a_list[0]]
for i in range(1, len(a_list)):
  diff_list.append(a_list[i] - a_list[i-1])
max_diff = max(diff_list)
sum_diff = sum(diff_list)
print(sum_diff-max_diff)

Measured memory_bytes: 26444
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
//
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


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




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


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n, b, r ;
  cin >> n >> b >> r ;
  
  if(b==0 && r==0){
    cout << 0 << endl ;
    return 0 ;
  }
  
  cout << n/(b+r)*b + min(n%(b+r),b) <<endl ;
  
  
  
  
  
  
  return 0 ;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
def solve(N,M):
    pref = [[] for _ in range(N)]
    P = [0]*M
    Y = [0]*M
    for i in range(M):
        P[i],Y[i] = map(int, input().split())
        pref[P[i]-1].append(Y[i])
    for i in range(N):
        pref[i].sort()
    ans = []
    for i in range(M):
        ind = bisect_left(pref[P[i]-1],Y[i])
        ans.append('0'*(6-len(str(P[i])))+str(P[i])+'0'*(6-len(str(ind+1)))+str(ind+1))
    return ans
print(*solve(N,M),sep='\n')


Measured memory_bytes: 29920
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
map<int,string>mp;
ll dp[105][5][5][5];
int n;ll ans;
bool check(int a,int b,int c,int d)
{
	string x=mp[a],y=mp[b],z=mp[c],w=mp[d];
	if(x+y+z=="AGC")return false;//abc
	if(y+z+w=="AGC")return false;//bcd
	if(y+x+z=="AGC")return false;//bac
	if(x+z+w=="AGC")return false;//acd
	if(x+z+y=="AGC")return false;//acb
	if(y+z+w=="AGC")return false;//bcd
	if(x+y+w=="AGC")return false;//abd
	if(y+w+z=="AGC")return false;//bdc
	if(z+y+w=="AGC")return false;//cbd
	return true;
}//Accepted
int main()
{
	mp[1]="A";
	mp[2]="G";
	mp[3]="C";
	mp[4]="T";
	cin>>n;
	if(n==1){cout<<"4\n";return 0;}
	if(n==2){cout<<"16\n";return 0;}
	if(n==3){cout<<"61\n";return 0;}
	for(int a=1;a<=4;a++)
		for(int b=1;b<=4;b++)
			for(int c=1;c<=4;c++)	
				dp[0][a][b][c]++;
	dp[0][1][2][3]=0;
	dp[0][1][3][2]=0;
	dp[0][2][1][3]=0;
	for(int i=1;i<=n-3;i++)
		for(int d=1;d<=4;d++)
			for(int a=1;a<=4;a++)
				for(int b=1;b<=4;b++)
					for(int c=1;c<=4;c++)
						if(check(d,a,b,c))
							dp[i][a][b][c]=(dp[i][a][b][c]+dp[i-1][d][a][b])%mod;
	for(int a=1;a<=4;a++)
		for(int b=1;b<=4;b++)
			for(int c=1;c<=4;c++)
				ans+=dp[n-3][a][b][c],ans%=mod;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define sz(v) (int)v.size()
#define pb push_back
using namespace std;

set<string> st;
string S;
int K;

void ins(string s){
    rep(j,s.size()) rep(i,s.size()-j) st.insert(s.substr(i,j+1));
}

int main(){
    cin >> S >> K;
    rep(i,S.size()) ins(S.substr(i,5));
    auto itr = st.begin();
    rep(i,K-1) ++itr;
    cout << *itr << endl;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
const int mod = 1000000007;
struct mint {
ll x;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res+=a;
}
mint operator-(const mint a) const {
mint res(*this);
return res-=a;
}
mint operator*(const mint a) const {
mint res(*this);
return res*=a;
}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
mint inv() const {
return pow(mod-2);
}
mint& operator/=(const mint a) {
return (*this) *= a.inv();
}
mint operator/(const mint a) const {
mint res(*this);
return res/=a;
}
};
int main(){
    ll n,k;cin >> n >> k;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    mint ans=0;
    mint sumR=0,sumL=0;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            if(a[i]>a[j]) sumR=sumR+1;
        }
    }
    ans+=sumR*k*(k+1)/2;
    for(int i=0;i<n;i++){
        for(int j=i-1;j>=0;j--){
            if(a[i]>a[j]) sumL=sumL+1;
        }
    }
    ans+=sumL*(k-1)*k/2;
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;
using namespace std;

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

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

ll modnCr(ll n, ll r, ll mod)
{
  ll ans = 1;
  FOR(i, 1, n + 1)
  {
    ans = (ans * i) % mod;
  }
  ll inv = 1;
  FOR(i, 1, r + 1)
  {
    inv = (inv * i) % mod;
  }
  FOR(i, 1, n - r + 1)
  {
    inv = (inv * i) % mod;
  }
  ans = (ans * modinv(inv, mod)) % mod;
  return ans;
}

int main()
{
  int n;
  ll k;
  cin >> n >> k;
  vector<int> a(n);
  vector<ll> back(n, 0), top(n, 0);
  REP(i, n)
  {
    cin >> a[i];
  }

  REP(i, n)
  {
    REP(j, n)
    {
      if (i == j)
        continue;
      if (i < j && a[i] > a[j])
      {
        top[i]++;
      }
      if (i > j && a[i] > a[j])
      {
        back[i]++;
      }
    }
  }

  ll ans = 0;
  REP(i, n)
  {
    ll tmp = k * (k - 1) % MOD;
    tmp = (tmp * (top[i] + back[i])) % MOD;
    ans = (ans + (tmp * modinv(2, MOD))) % MOD;
    tmp = k * top[i] % MOD;
    ans = ans + tmp % MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>

using namespace std;
const long long P = 1000000007;

int main() {
  int n,k;
  cin >> n >> k;
  int a[n];
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans;
  if((n-1) % (k-1) == 0) {
    ans = (n-1)/(k-1);
  }else {
    ans = (n-1)/(k-1)+1;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  int H, N;
  cin >> H >> N;
  vector<int> A(N);
  int sum = 0;
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
    sum += A.at(i);
  }
  cout << (sum >= H? "Yes": "No") << endl;

}

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

int main()
{
    int n, cnt=0;
    cin >> n;
    vector<int> a(n);
    rep(i, n)
    {
        cin >> a[i];
        if ((i + 1) % 2 == 1 && a[i] % 2 == 1)
        {
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
using namespace std;

#define ll long long

int main(){
    int N, M, X, Y, xmax, ymin;
    cin >> N >> M >> X >> Y;
    xmax = X;
    ymin = Y;
    int x[N], y[M];
    for(int i = 0; i < N; i++){
        cin >> x[i];
        if(x[i] > xmax)xmax = x[i];
    }
    for(int i = 0; i < M; i++){
        cin >> y[i];
        if(y[i] < ymin)ymin = y[i];
    }
    if(ymin > xmax)cout << "No War" << endl;
    else cout << "War" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class Main
{
	public static void main(String[] args) {
		BufferedReader in = null;
		try {
			in = new BufferedReader(
				new InputStreamReader(System.in)
				);
			double r = Double.parseDouble(in.readLine());
			System.out.printf("%f %f\n", 
				Math.PI * r * r,
				2.0 * Math.PI * r
			);
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (in != null) {
				try {
					in.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
				
			}
		}
		
	}
}

Measured memory_bytes: 16928
def solve():
  N = int(input())
  t = [0]
  x = [0]
  y = [0]
  for i in range(N):
    a, b, c = map(int, input().split())
    t.append(a)
    x.append(b)
    y.append(c)
  for i in range(N):
    l = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i])
    dt = t[i + 1] - t[i]
    if l > dt or l % 2 != dt % 2:
      return "No"
  return "Yes"

print(solve())

Measured memory_bytes: 11792
import java.util.Scanner;

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

        while (in.hasNext()) {
            int n = in.nextInt();
            int x = in.nextInt();

            if (n == 0) {
                break;
            }

            int ret = 0;
            for (int i = n; i >= 3; i--) {
                ret += cntPattern(i - 1, x - i);
            }
            sb.append(ret).append("\n");
        }

        System.out.print(sb.toString());
    }

    private static int cntPattern(int n, int x) {
        int ret = 0;
        int max = 2 * n;
        if (max <= x) {
            return 0;
        }
        if (max - 1 == n) {
            return 1;
        }

        for (int i = n; i > 1; i--) {
            for (int j = i - 1; j >= 1; j--) {
                if (j + i == x) {
                    ret++;
                    break;
                }
            }
        }
        return ret;
    }
}

Measured memory_bytes: 19976
import math 

def koch(n, p1, p2):
    if n==0:
        return
    
    s=((2*p1[0]+1*p2[0])/3 , (2*p1[1]+1*p2[1])/3)
   
    t=((1*p1[0]+2*p2[0])/3, (1*p1[1]+2*p2[1])/3)
    
    u= ( (t[0]-s[0])*math.cos(math.radians(60))-(t[1]-s[1])*math.sin(math.radians(60))+s[0],
        (t[0]-s[0])*math.sin(math.radians(60))+(t[1]-s[1])*math.cos(math.radians(60))+s[1])
    
    koch(n-1, p1, s)
    print(" {0:.8f} {1:.8f}".format(*s))
    koch(n-1, s , u)
    print("{0:.8f} {1:.8f}".format(*u))
    koch(n-1, u ,t)
    print("{0:.8f} {1:.8f}".format(*t))
    koch(n-1, t , p2)

p1=(0,0)
p2=(100,0)
n=int(input())

print("{0:.8f} {1:.8f}".format(*p1))
koch(n, p1, p2)
print("{0:.8f} {1:.8f}".format(*p2))

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

using namespace std;

typedef long long ll;

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

    string s; cin >> s;
    if(s[s.size() - 1] == 's'){
        s += "es";
    }else s += "s";
    cout << s << '\n';

}


Measured memory_bytes: 3632
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

const P: i64 = 1_000_000_007;

pub fn pow(x: i64, n: i64) -> i64 {
    let (mut x, mut y, mut n) = (x % P, 1_i64, n);
    while n > 0 {
        if n % 2 != 0 {
            y = (y * x) % P;
            n -= 1;
        }

        x = (x * x) % P;
        n /= 2;
    }
    y
}

fn main() {
    let N = read!(usize);
    let A = read![[i64]];

    let mut total = 0_i64;

    for i in 0..N {
        total += A[i] % P;
        total %= P;
    }

    total *= (N - 1) as i64;
    total %= P;

    debug!(total);

    let mut conj = 0_i64;

    for h in 0..62 {
        let r = (0..N).filter(|&i| (A[i] & (1 << h)) != 0).count();
        if r == 0 {
            continue;
        }

        let mut t = (r * (r - 1) / 2) as i64 % P;

        debug!((h, r, t));

        t *= (1 << h) % P;
        t %= P;

        conj += t;
        conj %= P;
    }

    debug!(conj);

    conj *= 2;
    conj %= P;

    total += P - conj;
    total %= P;

    println!("{}", total)
}


Measured memory_bytes: 15608
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//


int main() {
	int N;
	cin >> N;
	vector<int> P(N * N);
	REP(i, N * N) scanf("%d", &P[i]), --P[i];
	
	vector<vector<int>> d(N, vector<int>(N, INF));
	REP(i, N) REP(j, N) chmin(d[i][j], min({ i, N - 1 - i, j, N - 1 - j }));
	
	vector<vector<int>> done(N, vector<int>(N));
	int ans = 0;
	REP(i, N * N) {
		int y = P[i] / N, x = P[i] % N;
		
		ans += d[y][x];
		done[y][x] = true;
		queue<pii> que;
		que.emplace(y, x);
		
		while (!que.empty()) {
			int cy = que.front().fi, cx = que.front().se;
			que.pop();
			
			constexpr int dx[] = {0,1,0,-1}, dy[] = {-1,0,1,0};
			REP(dir, 4) {
				int ny = cy + dy[dir], nx = cx + dx[dir];
				if (nx < 0 || nx >= N || ny < 0 || ny >= N) continue;
				if (chmin(d[ny][nx], !done[cy][cx] + d[cy][cx])) {
					que.emplace(ny, nx);
				}
			}
		}
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 6228
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, e) for(int i = (int)(s); i < (int)(e); ++i)
#define rep(i, n) REP(i, 0, n)
int main() {
  int h, w;
  while(cin >> h >> w) {
    if(h == 0 && w == 0) break;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    map<string, int> mp;
    rep(i, h) rep(j, w) {
      REP(dx, -1, 2) REP(dy, -1, 2) {
	if(dx == 0 && dy == 0) continue;
	//cout << i << " " << j << " " << dy << " " << dx << endl;
	string tmp;
	tmp += s[i][j];
	int x = (j + dx + w) % w;
	int y = (i + dy + h) % h;
	while(1) {
	  // cout << y << " " << x << endl; 
	  if(x == j && y == i) break;
	  tmp += s[y][x];
	  x = (x + dx + w) % w;
	  y = (y + dy + h) % h;
	  mp[tmp]++;
	}
	// mp[tmp]++;
	// cout << i << " " << j << " " << dy << " " << dx << " " << tmp << endl;
      }
    }
    string ans;
    for(const auto& p : mp) {
      if(p.second == 1) continue;
      if(ans.size() < p.first.size()) ans = p.first;
      else if(ans.size() == p.first.size()) {
	ans = min(ans, p.first);
      }
    }
    if(ans == "") cout << 0 << endl;
    else cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 37976
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static final int BIG_NUM = 2000000000;
	public static final int MOD = 1000000007;

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String input[] = new String[2];

		try {
			input = br.readLine().split("\\s+");
			int N = Integer.parseInt(input[0]);
			int T = Integer.parseInt(input[1]);

			int table[] = new int[T+1];
			for(int i = 0; i < table.length; i++){
				table[i] = 0;
			}

			int left,right;

			for(int loop = 0; loop < N; loop++){

				input = br.readLine().split("\\s+");

				left =  Integer.parseInt(input[0]);
				right = Integer.parseInt(input[1]);

				table[left]++;
				table[right]--;
			}

			int ans = table[0];
			for(int i = 1; i < table.length; i++){
				table[i] += table[i-1];
				ans = Math.max(ans, table[i]);
			}

			System.out.println(ans);

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}



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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

int n, k;
string s;

int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> s >> k;
    n = s.length();

    vector<int> groups;
    char prev = s[0], len = 0;
    for(int i = 0; i < n; ++i) {
        if(s[i] == prev) len++;
        else {
            groups.push_back(len);
            prev = s[i];
            len = 1;
        }
    }
    groups.push_back(len);
    if(groups.size() == 1) {
        cout << n*k/2 << endl;
        return 0;
    }
    
    int ans = 0;
    for(int i = 1; i < (int)groups.size() - 1; ++i) {
        int cnt = groups[i];
        ans += cnt/2*k;
    }

    int fr = groups[0], ba = groups.back();
    if(s[0] == s[n-1]) {
        ans += fr/2 + ba/2 + (fr+ba)/2*(k-1);
    } else {
        ans += fr/2*k + ba/2*k;
    }

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


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

int main() {
  string A,B,C;
  cin >> A >> B >> C;
  if (A[A.size()-1] == B[0] && B[B.size()-1] == C[0]) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
import bisect

n = int(input())
ls = [sorted(map(int, input().split())) for _ in range(3)]
res = 0
for i in range(n):
    b = ls[1][i]
    x = bisect.bisect_right(ls[0], b - 1)
    y = bisect.bisect_left(ls[2], b + 1)
    res += x * (n - y)
print(res)

Measured memory_bytes: 22720
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		while (s.hasNextInt()) {
			int h = s.nextInt();
			int w = s.nextInt();
			if (h == 0 && w == 0) return;
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					System.out.print((0 < i && i < h - 1) && (0 < j && j < w - 1) ? '.' : '#');
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 26736
<?php
$N = trim(fgets(STDIN));
$A = str_split(trim(fgets(STDIN)));
$B = str_split(trim(fgets(STDIN)));
$C = str_split(trim(fgets(STDIN)));
$ANS = 0;
for($i = 0;$i<$N;$i++){
 $ans = 0;
 $a = 0;
  $b = 0;
  $c = 0;
  if($A[$i]!=$B[$i]){
  ++$a;
  }
  if($A[$i]!=$C[$i]){
  ++$a;
  }
  $ans = $a;
  if($B[$i]!=$A[$i]){
++$b;
}
if($C[$i]!=$B[$i]){
++$b;
}
if($ans<$b){
$ans = $b;
}
    if($C[$i]!=$A[$i]){
++$c;
}
if($B[$i]!=$C[$i]){
++$c;
}
if($ans>$c){
$ans = $c;
}
$ANS += $ans;
}
echo $ANS;


Measured memory_bytes: 4728
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cctype>
using namespace std;

int main(){
    string str1,str2,str3;
    cin>>str1>>str2>>str3;
transform(str1.begin(), str1.end(), str1.begin(), ::toupper);
transform(str2.begin(), str2.end(), str2.begin(), ::toupper);
transform(str3.begin(), str3.end(), str3.begin(), ::toupper);
    cout<<str1[0]<<str2[0]<<str3[0]<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(2) 
#include<bits/stdc++.h>
#define rg register
#define il inline
using namespace std;
typedef long long ll;
const int mod=1e9+7,O=1000010;
struct Data{
	bool v;int fa,id;
	il void init(int x){v=0;fa=x;id=-1;}
}a[O];
il int gi(){
	rg int o=0,fl=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')fl=-1,ch=getchar();
	while(isdigit(ch))o=o*10+ch-'0',ch=getchar();
	return fl*o;
}
int n,m,k,cnt,dis[O];
vector<pair<int,int> >g1[O];
vector<int>g2[O];
queue<int>Q;
il int find(int x){return x==a[x].fa?x:a[x].fa=find(a[x].fa);}
int main(){
	cnt=n=gi(),m=gi();
	for(int i=1;i<=m;++i){
		int a=gi(),b=gi(),c=gi();
		g1[c].push_back(make_pair(a,b));
		k=max(k,c);
	}
	for(int s=1;s<=k;++s){
		if(g1[s].empty())continue;
		for(unsigned int i=0;i<g1[s].size();++i){
			a[g1[s][i].first].init(g1[s][i].first);
			a[g1[s][i].second].init(g1[s][i].second);
		}
		for(unsigned int i=0;i<g1[s].size();++i){
			int X=find(g1[s][i].first),Y=find(g1[s][i].second);
			if(X!=Y)a[Y].fa=X;
		}
		for(unsigned int i=0;i<g1[s].size();++i){
			int p1=g1[s][i].first,p2=g1[s][i].second;
			if(!a[p1].v){
				a[p1].v=1;
				int x=find(p1);
				if(a[x].id==-1)a[x].id=++cnt;
				g2[a[x].id].push_back(p1);
				g2[p1].push_back(a[x].id);
			}
			if(!a[p2].v){
				a[p2].v=1;
				int x=find(p2);
				if(a[x].id==-1)a[x].id=++cnt;
				g2[a[x].id].push_back(p2);
				g2[p2].push_back(a[x].id);
			}
		}
	}
	memset(dis,-1,sizeof(dis));
	Q.push(1);dis[1]=0;
	while(!Q.empty()){
		int u=Q.front();Q.pop();
		for(unsigned int i=0;i<g2[u].size();++i){
			int v=g2[u][i];
			if(dis[v]==-1){
				dis[v]=dis[u]+1;
				Q.push(v);
			}
		}
	}
	if (dis[n]==-1)puts("-1");
	else printf("%d\n",dis[n]>>1);
	return 0;
}


Measured memory_bytes: 69504
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long
constexpr int nc2(int n) { return n * (n - 1) / 2; }

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

    int n;
    cin >> n;

    map<string, int> chars_count;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        chars_count[s]++;
    }

    int ans = 0;
    for (auto &&i : chars_count) {
        ans += nc2(i.second);
    }

    cout << ans << endl;
}


Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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やllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  ll N;
  cin >> N;
  ll A,B;
  cin >> A >> B;
  ll pos = B-A;
  ll C,D;
  cin >> C >> D;
  for(ll k=0; k<=N-1; k++){
    if(D*k-(((N-1)-k)*C) >= pos && pos >= C*k-(((N-1)-k)*D)){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

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

		String sa = scan.nextLine();
		String sb = scan.nextLine();
		String sc = scan.nextLine();

		int i = 0;
		int j = 0;
		int k = 0;

		List<String> a = new ArrayList<String>();
		List<String> b = new ArrayList<String>();
		List<String> c = new ArrayList<String>();

		for (i = 0; i < sa.length(); i++) {
			a.add(sa.charAt(i) + "");
		}

		for (j = 0; j < sb.length(); j++) {
			b.add(sb.charAt(j) + "");
		}

		for (k = 0; k < sc.length(); k++) {
			c.add(sc.charAt(k) + "");
		}

		String ha = "a";

		i = 1;

		for (;;) {

			if (ha.equals("a")) {

				if (a.size() == 0) {
					System.out.println("A");
					break;
				}

				ha = a.get(0);
				a.remove(0);

			} else if (ha.equals("b")) {

				if (b.size() == 0) {
					System.out.println("B");
					break;
				}

				ha = b.get(0);
				b.remove(0);

			} else if (ha.equals("c")) {

				if (c.size() == 0) {
					System.out.println("C");
					break;
				}

				ha = c.get(0);
				c.remove(0);

			}

		}

	}

}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long int N; cin>>N;
    long long int tmp=0,minimum=pow(10,12);
    for(long long int j=1;j<=sqrt(N);j++){
            if(N%j==0){
                long long int a=j;
                long long int b=N/j;
                tmp=a+b-2;
                minimum=min(minimum,tmp);
            }
    }
    cout<<minimum;
    return 0;
}




Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  char S[21] = {0};
  char NickName[4] = {0};
  int i = 0;
  
  scanf("%s", S);
  for( i = 0; i < sizeof(NickName) - 1; i++ ) {
    NickName[i] = S[i];
  }
  printf("%s", NickName);
}

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

template<typename T> struct BinaryIndexedTree {
    vector< T > data;
    BinaryIndexedTree(int sz) { data.assign(++sz, 0); }
    T sum(int k) {
        if (k < 0) return T(0);
        T ret = 0;
        for (++k; k > 0; k -= k & -k) ret += data[k];
        return (ret);
    }
    T sum(int l, int r) {
        assert(l <= r);
        return sum(r - 1) - sum(l - 1);
    }
    void add(int k, T x) {
        for (++k; k < data.size(); k += k & -k) data[k] += x;
    }
};

template<typename T> int_fast64_t InversionNumber(vector< T > &v) {
    int_fast64_t sz = v.size(), ret = 0;
    vector< T > rev, v_cp = v; sort(v_cp.begin(), v_cp.end());
    for (auto &e : v) rev.emplace_back(lower_bound(v_cp.begin(), v_cp.end(), e) - v_cp.begin());
    BinaryIndexedTree< T > bit(sz);
    for (int i = 0; i < sz; ++i) {
        ret += i - bit.sum(rev[i]);
        bit.add(rev[i], 1);
    }
    return ret;
}

signed main() {

    string S;
    while (cin >> S) {
        int N = S.size();

        int cnt[26], now[26];
        REP(i, 26) cnt[i] = now[i] = 0;
        REP(i, N) cnt[S[i] - 'a']++;

        bool valid = true;
        REP(i, 26) valid &= cnt[i] % 2 == 0;
        if (not valid) {
            cout << -1 << endl;
            continue;
        }

        // 塗り分ける
        bool color[N];
        REP(i, N) color[i] = false;
        REP(i, N) {
            int c = S[i] - 'a';
            if (now[c] < cnt[c] / 2) color[i] = true;
            now[c]++;
        }

        // 半分ずつに分けるコスト
        ll res = 0;
        REP(i, N / 2) res -= i;
        REP(i, N) if (color[i]) res += i;

        // 左半分と右半分の文字列
        string l = "", r = "";
        REP(i, N) {
            if (color[i]) l += S[i];
            else r += S[i];
        }
        reverse(l.begin(), l.end());

        map<int, queue<int>> ques;
        REP(i, N / 2) {
            int c = l[i] - 'a';
            ques[c].emplace(i);
        }

        // 転倒数を求める対象
        vector<int> r_vec;
        REP(i, N / 2) {
            int c = r[i] - 'a';
            r_vec.emplace_back(ques[c].front());
            ques[c].pop();
        }

        cout << res + InversionNumber(r_vec) << endl;
    }

}


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

int main()
{
    int n ;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int ans = 0;
    rep(i,n)
    {
        if(i %2 != 0) continue;
        if(a[i]%2 != 0) ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <limits.h>
using namespace std;

const long long INF = LLONG_MAX;

//足場nまでのコストの最小値
long long minC[100000+1];

//足場の高さ
int height[100000+1];

int cost(int x,int y)
{
    if(height[x]>height[y]) return height[x] - height[y];
    else return height[y] - height[x];
}

int main()
{
    int N,K;
    cin >> N >> K;
    for(int i = 0; i < N; i++) cin >> height[i];
    if(N == 2) cout << cost(1 - 1,2 - 1);
    else{
        minC[1 - 1] = 0;
        minC[2 - 1] = cost(1 - 1,2 - 1);
        for(int i = 3 - 1; i <= N - 1; i++){
            minC[i] = INF;
            for(int j = 1; (j <= K && i - j >= 0); j++){
                minC[i] = min(minC[i],minC[i - j] + cost(i - j,i));
            }
        }
        cout << minC[N - 1];
    }
    return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

using namespace std;

//階乗
vector<ll>fact;
//逆元
vector<ll>inv;
//逆元階乗
vector<ll>finv;

pii extgcd(ll a, ll b){
    //前提：aとbが互いに素であること．
    pii x(make_pair(1,0), a);
    pii y(make_pair(0,1), b);

    ll div = 0;

    //終了条件:(GCD(a,b), 0)または(0,GCD(a,b))
    while(true){
        if(y.second == 0) return x;
        
        div = x.second / y.second;
        x.second = x.second  - div * y.second;
        x.first.first = x.first.first - div * y.first.first;
        x.first.second = x.first.second - div * y.first.second;

        if(x.second == 0) return y;

        div = y.second / x.second;
        y.second = y.second - div * x.second;
        y.first.first = y.first.first - div * x.first.first;
        y.first.second = y.first.second - div * x.first.second;
    }
}

ll modinv(ll a, ll m = MOD){
    //前提：aとmが互いに素であること．
    pii ans;
    ans = extgcd(a, m);

    ll invNum = 0;
    invNum = ans.first.first;
    invNum %= m;
    //C++特有の剰余がマイナスになってしまう対策
    if(invNum < 0) invNum += m;

    return invNum;
}

ll warizan_mod(ll warareru, ll waru, ll m = MOD){
    //割られる数に逆元をかけるだけ
    warareru %= m;
    return warareru * modinv(waru, m) % m;
}

//階乗と逆元を列挙
void combination(ll num, ll m = MOD){
    fact.assign(num + 1919, 0);
    finv.assign(num + 1919, 0);
    inv.assign(num  + 1919, 0);

    //初期化
    fact[0] = 1; inv[0] = 1;
    //テーブルに列挙
    for(ll i = 1; i < fact.size(); i++){
        fact[i] = fact[i - 1] * i % m;
        inv[i]  = modinv(fact[i]);
    }
}

//階乗 n!
ll factrial(ll n){
    return fact[n];
}

//順列 nPk n!/(n-k)!
ll nPk(ll n, ll k, ll m = MOD){
    if(n < 0 || k < 0 || n < k) return 0;
    return fact[n] * inv[n - k] % m;
}

//二項係数 nCk n!/(k!*(n-k)!)
ll nCk(ll n, ll k, ll m = MOD){
    if(n < 0 || k < 0 || n < k) return 0;
    return fact[n] * (inv[k] * inv[n - k] % m) % m;
}

//重複組み合わせ n+k-1Ck
ll nHk(ll n, ll k, ll m = MOD){
    return nCk(n+k-1, k);
}

//最大値と最小値をまとめて合計取っ手から引いて良い
//結局3つの組み合わせ, 4つの組み合わせにしても最小値や最大値は変わらない
int main(){

    ll N, K; cin >> N >> K;

    for(ll i = 0; i < N; i++){
        ll t; cin >> t;
        vec.push_back(t);
    }

    //準備
    combination(100019);

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

    ll mx = 0;

    for(ll i = K-1; i < N; i++){
        //cout << i << " " << K-1 << endl;
        mx += nCk(i, K-1) * vec[i];
        mx %= MOD;
    }

    sort(vec.rbegin(), vec.rend());

    ll mn = 0;

    for(ll i = K-1; i < N; i++){
        mn += nCk(i, K-1) * vec[i];
        mn %= MOD;
    }

    cout << (mx % MOD - mn % MOD) % MOD << endl;

}

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

using namespace std;

int main()
{
    int N, K;
    while (cin >> N >> K, N) {
        vector<int> S(K);
        for (int i = 0; i < K; i++) {
            cin >> S[i];
        }
        
        int B[N][K];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < K; j++) {
                cin >> B[i][j];
            }
        }
        bool poss = 1;
        for (int i = 0; i < K; i++) {
            int sum = 0;
            for (int j = 0; j < N; j++) {
                sum += B[j][i];
            }
            if (sum > S[i]) {
                poss = 0;
            }
        }
        cout << (poss ? "Yes" : "No") << endl;
    }
        
    return 0;
}

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

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

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {
    
    // source code
  ll n;
  cin >> n;
  cout << (n - 1) / 2;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    string S;
    cin >> S;

    ll ans = 0;
    ll B = 0;
    rep(i, S.size()) {
        if (S[i] == 'B') B++;
        else {
            if (B == 0) continue;
            ans += B;
        }
    }

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

Measured memory_bytes: 640
//Author : Sukarna Paul

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pi acos(-1)
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;




int main(){
    IOS
    //freopen("output.txt","w",stdout);
    int a,b,c;
    cin>>a>>b>>c;
    map<int,int>mp;
    mp[a]++;
    mp[b]++;
    mp[c]++;
    if(mp[5]==2 && mp[7]==1)cout<<"YES\n";
    else cout<<"NO\n";
}


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

int main()
{
    ll n;
    cin>>n;
    vector<ll> arr(n);
    for(ll i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    ll ans=0;
    ll maxi=arr[0];
    for(ll i:arr)
    {
        maxi=max(maxi,i);
        ans+=(maxi-i);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 4836
n = gets.to_i
ary = gets.split(" ").map(&:to_i)
avg = ary.inject(0){ |r, i| r += i} / ary.size

avg_ary = [avg - 1, avg, avg + 1]

min_cost = -1
avg_ary.each do |arg|
  cost = 0
  ary.each do |a|
    cost += (a - arg) ** 2
  end
  min_cost = cost if min_cost == -1
  min_cost = cost if cost < min_cost
end
puts min_cost

Measured memory_bytes: 1788
#!/usr/bin/env python
N, A = map(int, raw_input().split())
x = map(int, raw_input().split())

DP =[[0 for i in range(N * 50 + 1)] for j in range(N + 1)]

DP[0][0] = 1

for i in range(N):
	for j in range(N, 0, -1):
		for k in range(x[i], N * 50 + 1):
			DP[j][k] += DP[j - 1][k - x[i]]

ans = 0
for i in range(1, N + 1):
	ans += DP[i][i * A]

print ans

Measured memory_bytes: 4228
N = int(input())
count = {'AC': 0, 'WA':0, 'TLE':0, 'RE':0}
for i in range(N):
    S = input()
    count[S] += 1

print('AC x {}'.format(count['AC']))
print('WA x {}'.format(count['WA']))
print('TLE x {}'.format(count['TLE']))
print('RE x {}'.format(count['RE']))



Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}

//ここから。
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<long long> siz; // size
    long long psiz; // 集合の数

    UnionFind(int N) : par(N),siz(N,1LL),psiz(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        if(siz[rx] < siz[ry]) swap(rx,ry);
        siz[rx] += siz[ry];
        psiz -= siz[ry];
        par[ry] = rx; //xとyの根が同じでない(=同じ木にない)時：yの根ryをxの根rxにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        return root(x) == root(y);
    }
    long long size(int x){
        return siz[root(x)];
    }
    long long psize() {
        return psiz;
    }
    
};

int main(){
    int n,m;
    cin >> n >> m;
    UnionFind tree(n);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        tree.unite(a-1,b-1);
    }
    ll ans = 0;
    ll onecnt = 0;
    rep(i,n){
        ll now = tree.size(i);
        chmax(ans,now);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5640