akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

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

    
    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 21732
# C - 一次元リバーシ
def main():
    s = input()
    t = s[0]
    cnt = 1

    for i in range(1, len(s)):
        if t != s[i]:
            t = s[i]
            cnt += 1
    else:
        print(cnt-1)
            

if __name__ ==  "__main__":
    main()

Measured memory_bytes: 9104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
bool f[114514];
int main(){
	ll n,k;
	cin>>n>>k;
	vector<vector<ll>>v(n+1);
	for(int i=0;i<n-1;i++){
		ll a,b;
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	queue<ll>que;
	que.push(1);
	f[1]=1;
	ll ans=k,mod=1e9+7;
	while(!que.empty()){
		ll x=que.front();
		que.pop();
		ll cnt=1;
		for(ll p:v[x]){
			if(f[p])cnt++;
			else{
				f[p]=1;
				que.push(p);
			}
		}
		ll num=v[x].size()+1-cnt;
		while(num){
			ans*=(k-cnt);
			ans%=mod;
			cnt++;
			num--;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 10300
package main

import (
	"fmt"
)

const mod = 1000000007

func mpow(x,n int) int {
	a := 1
	for ;n!=0; {
		if n&1 == 1 {
			a = a*x %mod
		}
		x = x*x %mod
		n = n >> 1
	}
	return a
}

func comb(a,b int, fac,facp []int) int {
	if a == 0 && b == 0 {
		return 1
	}
	return (fac[a]*facp[b]%mod)*facp[a-b]%mod
}

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

	a := make([]int,n+1) // n!
	b := make([]int,n+1) // n!^{mod-2}
	a[0] = 1
	b[0] = 1
	for i := 0; i < n; i++ {
		a[i+1] = a[i]*(i+1)%mod
		b[i+1] = b[i]*mpow(i+1,mod-2) %mod
	}

	for i := 1; i < k+1; i++ {
		if n-k+1<i {
			fmt.Println(0)
		} else {
			fmt.Println(comb(n-k+1,i,a,b)*comb(k-1,i-1,a,b)%mod)
		}
	}

}


Measured memory_bytes: 512
import math
def is_palindrome(string):
    if string == string[::-1]:
        return True
    else:
        return False

string = input()
num = 0



if is_palindrome(string):

    print(num)



else:
    for i in range(math.floor(len(string)/2)):
        if string[i]==string[-(i+1)]:

            continue
        else:
            str_list = list(string)
            str_list[i]=str_list[-(i+1)]
            num +=1
    print(num)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
const int NMAX = 3e5 + 5;
int x[NMAX], y[NMAX], n, m, k, freqx[NMAX], freqy[NMAX], maxx, maxy, sol, cntx[NMAX], cnty[NMAX], mx, my;
bool posx[NMAX], posy[NMAX];

int main() {
    cin >> n >> m >> k;
    for(int i = 1; i <= k; i++) {
        cin >> x[i] >> y[i];
        freqx[x[i]]++;
        freqy[y[i]]++;
        if(freqx[maxx] < freqx[x[i]]) {
            maxx = x[i];
        }
        if(freqy[maxy] < freqy[y[i]]) {
            maxy = y[i];
        }
    }
    for(int i = 1; i <= k; i++) {
        if(x[i] == maxx) {
            posy[i] = 1;
        }
        if(y[i] == maxy) {
            posx[i] = 1;
        }
    }
    for(int i = 1; i <= k; i++) {
        if(posx[i] == 0) {
            cntx[x[i]]++;
            if(cntx[x[i]] > cntx[mx]) {
                mx = x[i];
            }
        }
        if(posy[i] == 0) {
            cnty[y[i]]++;
            if(cnty[y[i]] > cnty[my]) {
                my = y[i];
            }
        }
    }
    cout << max(freqx[maxx] + cnty[my], freqy[maxy] + cntx[mx]);
    return 0;
}

Measured memory_bytes: 10888
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

def dist(i, j, lim, t):
	if abs(i - j) > t:
		dist = -INF
	else:
		x = (t + j - i) / 2
		y = (t + j + i) / 2
		if  y <= lim:
			dist = (i + y) * x / 2 + (j + y) * (t - x) / 2
		else:
			dist = (i + lim) * (lim - i) / 2 + lim * (t - (lim - i) - (lim - j)) + (j + lim) * (lim - j) / 2
			# print(dist)

	return dist

#処理内容
def main():
	N = int(input())
	T = getlist()
	V = getlist()
	DP = [[-INF] * 101 for i in range(N + 1)]
	DP[0][0] = 0
	for i in range(N - 1):
		lim = V[i]
		t = T[i]
		for p in range(lim + 1):
			for q in range(lim + 1):
				d = dist(p, q, lim, t)
				DP[i + 1][q] = max(DP[i + 1][q], DP[i][p] + d)

	lim = V[-1]
	t = T[-1]
	for p in range(lim + 1):
		d = dist(p, 0, lim, t)
		DP[N][0] = max(DP[N][0], DP[N - 1][p] + d)


	print(DP[N][0])

if __name__ == '__main__':
	main()

Measured memory_bytes: 46320
X, Y, Z, K = gets.chomp.split(" ").map(&:to_i)

cakes_a = gets.chomp.split(" ").map(&:to_i).sort.reverse
cakes_b = gets.chomp.split(" ").map(&:to_i).sort.reverse
cakes_c = gets.chomp.split(" ").map(&:to_i).sort.reverse

sums = []
cakes_a.each_with_index do |a, a_i|
  cakes_b.each_with_index do |b, b_i|
    break if (a_i + 1 ) * (b_i + 1) > K
    cakes_c.each_with_index do |c, c_i|
      break if (a_i + 1 ) * (b_i + 1) * (c_i + 1 ) > K
      sums.push a + b + c
    end
  end
end

puts sums.sort.reverse.slice(0...K)


Measured memory_bytes: 4532
import java.util.Scanner;

class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);

    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int D = sc.nextInt();

    if (A * B > C * D){
      System.out.println(A * B);
    }
    else {
      System.out.println(C * D);
    }

  }
}


Measured memory_bytes: 22868
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int N,M;
double x[100010];
ll K;
int a[100010];

vector<int> replace(vector<int> A,ll n){
    vector<int> B(N+1);
    for(int i=1;i<N;i++) B[i]=i;
    while(n>0){
        if(n&1){
            vector<int> C=B;
            for(int i=1;i<N;i++){
                B[i]=A[C[i]];
            }
        }

        vector<int> D=A;
        for(int i=1;i<N;i++){
            A[i]=D[D[i]];
        }
        n>>=1;
    }
    return B;
}

int main(){
  cin>>N;
  for(int i=0;i<N;i++) cin>>x[i];
  cin>>M>>K;
  for(int i=0;i<M;i++) cin>>a[i];

  double dif[N+1]={};
  for(int i=1;i<N;i++){
      dif[i]=x[i]-x[i-1];
  }

  vector<int> index(N+1);
  for(int i=1;i<N;i++) index[i]=i;
  for(int i=0;i<M;i++){
      swap(index[a[i]],index[a[i]-1]);
  }

  vector<int> A=replace(index,K);
  double ans[N+1]={};
  ans[0]=x[0];
  for(int i=1;i<N;i++){
      ans[i]=ans[i-1]+dif[A[i]];
  }
  for(int i=0;i<N;i++) cout<<fixed<<setprecision(10)<<ans[i]<<endl;

  return 0;
}


Measured memory_bytes: 6256
#include <cstdio>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

int N;
int h[110];

int f( int s, int t )
{
  if( t-s <= 0 )
    return 0;

  std::vector<int> zero;
  int ret = 0;

  zero.push_back( s-1 );

loop:;

  repi( i, s, t )
  {
    if( h[i] == 0 )
      zero.push_back( i );
  }

  zero.push_back( t );

  if( zero.size() == 2 )
  {
    repi( i, s, t+1 )
      --h[i];

    ++ret;

    zero.pop_back();
    
    goto loop;
  }
  else if( zero.size() < t-s+2 )
  {
    rep( i, zero.size()-1 )
      ret += f( zero[i]+1, zero[i+1] );

    return ret;
  }
  else
    return ret;
}

int main()
{
  scanf( "%d", &N );
  rep( i, N )
    scanf( "%d", h+i );

  printf( "%d\n", f( 0, N ) );

  return 0;
}

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict(list)
#import bisect
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    V = readInts()
    from collections import Counter
    a = Counter(V[0::2]).most_common(2) # 最大のもの1こ
    b = Counter(V[1::2]).most_common(2)
    a.append([0,0])
    b.append([0,0])
    #print(a,b)
    #print(a[1][1],b[1][1])
    if a[0][0] != b[0][0]:
        # mostが違う
        print(n - (a[0][1] + b[0][1]))
    else:
        print(min(n-(a[1][1] + b[0][1]), n-(a[0][1] + b[1][1])))
if __name__ == '__main__':
  main()


Measured memory_bytes: 15472
n=int(input())
d=[10*[0]for _ in range(10)]
ans=0
for i in range(1,n+1):
  s=str(i)
  if s[0]=="0" or s[-1]=="0":continue
  d[int(s[0])][int(s[-1])]+=1
for i in range(1,10):
  for j in range(1,10):
    ans+=d[i][j]*d[j][i]
print(ans)

Measured memory_bytes: 3064
use std::io::*;
use std::str::FromStr;
use std::cmp;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: String = read();
    let n = s.len();
    let cnt = s.chars().filter(|&c| c == '1').count();
    println!("{}", 2*cmp::min(cnt, n-cnt));
}


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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  cin >> n;
  cout << n*800 - n/15*200 << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

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


		int W = stdIn.nextInt();
		int H = stdIn.nextInt();
		int x = stdIn.nextInt();
		int y = stdIn.nextInt();
		int r = stdIn.nextInt();

		if((H - y) < r || (W - x) < r)
			System.out.println("No");
                else if(x < 0 || y < 0)
			System.out.println("No");

		else
			System.out.println("Yes");

	}

}

Measured memory_bytes: 26200
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
def main():
    N, K = map(int, input().split())
    answer = 0
    # m=(N以下の正整数であり、かつKの倍数であるものの個数)とする。
    m = N//K
    # aとbとcが全てKの倍数のとき
    # a,b,cがすべて同じ、うち2つが同じ、3つが相異なるときの場合の数。
    answer += m + m*(m-1)*3 + m*(m-1)*(m-2)

    # Kが偶数のときは、aとbとcが全てKを法として(K//2)に合同なときも条件を満たす。
    if K%2 == 0:
        # m=(N以下の正整数であり、かつKを法として(K//2)に合同なものの個数)とする。
        if m*K + K//2 <= N:
            m += 1
        answer += m + m*(m-1)*3 + m*(m-1)*(m-2)
    print(answer)

if __name__ == "__main__":
    main()



Measured memory_bytes: 9208
#include <iostream>
#include <cstdio>
#define N 1000005
using namespace std;

int s, d[2][N];
string a;
int main()
{
	int i;
	cin >> a;
	a = '0' + a;
	d[1][0] = 1;
	for (i = 1; i < a.size(); i++) {
		a[i] -= '0';
		d[0][i] = min(d[0][i - 1] + a[i], d[1][i - 1] + 10 - a[i]);
		d[1][i] = min(d[0][i - 1] + a[i] + 1, d[1][i - 1] + 9 - a[i]);
	}
    cout << d[0][a.size() - 1] << endl;
    return 0;
}

Measured memory_bytes: 9136
def run():
  N = int(input())
  n_li = [int(i) for i in input().split()]
  dp = [[0]*21 for _ in range(N-1)]
  dp[0][n_li[0]] = 1
  n_last = n_li[-1]
  for i in range(N-2):
    next_value = n_li[i+1]
    for num in range(21):
      if dp[i][num] > 0:
        sum1 = num + next_value
        sum2 = num - next_value
        if (sum1 >= 0) and (sum1 <= 20):
          dp[i+1][sum1] += dp[i][num]
        if (sum2 >= 0) and (sum2 <= 20):
          dp[i+1][sum2] += dp[i][num]
  print(dp[-1][n_last])
      
if __name__ == '__main__':
  run()


Measured memory_bytes: 5604
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
static const int MAX_SIZE = 1 << 17; //segment tree のサイズ。この実装では2べきにする必要がある。 2^17 ≒ 1.3 * 10^5

typedef long long Int;
Int segMin[2 * MAX_SIZE - 1], segAdd[2 * MAX_SIZE - 1];

//区間[a, b)に値xを加算する.
void add(int a, int b, int x, int k = 0, int l = 0, int r = MAX_SIZE)
{
	if (r <= a || b <= l) return; //もし交差しない区間であれば終える.
	
	if (a <= l && r <= b){ //もし今みている区間[l, r)が[a, b)に完全に内包されていれば
		segAdd[k] += x;  //区間[l, r)にkを加算する.
		return;
	}
	
	add(a, b, x, k * 2 + 1, l, (l + r) / 2); //子の区間に(必要があれば)xを加算する.
	add(a, b, x, k * 2 + 2, (l + r) / 2, r); //〃

	//親の区間の最小値は, 子の区間の最小値 + 自分に一様に加算されている値 である.一様に加算される値は更新しなくて良い.
	segMin[k] = min(segMin[k * 2 + 1] + segAdd[k * 2 + 1], segMin[k * 2 + 2] + segAdd[k * 2 + 2]);
}

Int getMin(int a, int b, int k = 0, int l = 0, int r = MAX_SIZE)
{
	if (r <= a || b <= l) return (BIG_NUM);
	
	if (a <= l && r <= b) return (segMin[k] + segAdd[k]); //完全に内包されていれば,その区間の最小値を返す.
	
	ll left = getMin(a, b, k * 2 + 1, l, (l + r) / 2); //子の区間の最小値を求める.
	ll right = getMin(a, b, k * 2 + 2, (l + r) / 2, r); //子の区間の最小値を求める
	
	return (min(left, right) + segAdd[k]); //親の区間の最小値は, 子の区間の最小値 + 自分に一様に加算されている値 である (大切なので2回書きました!!)
	
}
int main(){
	int n,q,s,t,x,a;
	cin>>n>>q;
	for(int i=0;i<q;i++){
		cin>>a;
		if(a==0){
			cin>>s>>t>>x;
			add(s,t+1,x,0,0,131072);
		}else{
			cin>>s>>t;
			cout<<getMin(s,t+1,0,0,131072)<<endl;
		}
	}
}




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

int main(){
  int n, m;
  cin >> n >> m;
  ll x[n+1], y[m+1];
  rep(i, n) cin >> x[i+1];
  rep(i, m) cin >> y[i+1];
  ll mx = 0, my = 0;
  for(int i = 1; i <= n; i++) mx =  (mx + (2*i-n-1)*x[i]) % mod;
  for(int i = 1; i <= m; i++) my =  (my + (2*i-m-1)*y[i]) % mod;
  ll ans = (mx * my) % mod;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define vll vector<ll>
#define vvll vector<vll>
#define mll map<ll,ll>
#define f(i,m,n) for(i=m;i<n;i++)
#define ee endl
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define take(v,n) for(i=0;i<n;i++) cin>>v[i];
#define print(v,n) for(i=0;i<n;i++) cout<<v[i]<<" ";
#define NO() cout<<"NO"<<endl
#define YES() cout<<"YES"<<endl
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sot(v) sort(v.begin(),v.end());
#define PI 3.14159265   ;
ll mod =1000000007;
bool isPrime(int n)
{
	// Corner cases 
	if (n <= 1)  return false;
	if (n <= 3)  return true;

	// This is checked so that we can skip  
	// middle five numbers in below loop 
	if (n % 2 == 0 || n % 3 == 0) return false;

	for (int i = 5; i*i <= n; i = i + 6)
		if (n%i == 0 || n % (i + 2) == 0)
			return false;

	return true;
}

ll powe(ll x, ll y) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) res =( res * x)%mod;
		y = y >> 1;
		x = (x * x)%mod;
	}
	return res;
}
struct hash_pair {
	template <class T1, class T2>
	size_t operator()(const pair<T1, T2>& p) const
	{
		auto hash1 = hash<T1>{}(p.first);
		auto hash2 = hash<T2>{}(p.second);
		return hash1 ^ hash2;
	}
};


void solve()
{
	ll i, x, y, j, k, h, n, w, k1, k2, q;
	string s;
	cin>>s;
	n=s.length();
	if(s[n-1]=='s') cout<<s<<"es";
	else cout<<s<<"s"<<ee;
}

int main() {
	fast;
	ll i, j, l, k, t, n;
	t=1;
	for (i = 1; i <= t; i++)
	{
		// cout<<"Case #"<<i<<": ";
		solve();
	}
}
// 

Measured memory_bytes: 3652
#include <iostream>
using namespace std;
int main(){
    int w,h,x,y;
    cin>>w>>h>>x>>y;
    int ans=0;
    if(x*2==w&&y*2==h) ans=1;
    cout<<(double)w*h/2.0<<" "<<ans;
    return 0;
}

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

using namespace std;

int main(){
      string S;cin >> S;
      int ans=0;
      if(S[0] == 'o')ans++;
      if(S[1] == 'o')ans++;
      if(S[2] == 'o')ans++;
      cout << 700 + (100*ans) << endl;
}


Measured memory_bytes: 256
x,y = gets.split.map(&:to_i)
break1 = "false"
 
if y.odd?
  puts "No"
elsif x > 50
  puts "No"
else
  for t in 0..50 do
   for k in 0..25 do
	if t+k == x && (t*2)+(k*4) == y
		puts "Yes"
		break1 = "true"
		break
	end
	if t==50 && k==25 && break1=="false" then
		puts "No"
	end
   end
   if break1 == "true"
     break
   end
  end
end  

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


int main() {

  	cin.tie(0);
    ios::sync_with_stdio(false);

    int N, i;
    int sum = 0;
    cin >> N;
	for (i = 1; i <= N; ++i){
    sum += i;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
from sys import stdin

class Vector:
    def __init__(self, x=None, y=None):
        self.x = x
        self.y = y

    def __add__(self, other):
        return Vector(self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        return Vector(self.x - other.x, self.y - other.y)

    def __mul__(self, k):
        return Vector(self.x * k, self.y * k)

    def __gt__(self, other):
        return self.x > other.x and self.y > other.y

    def __eq__(self, other):
        return self.x == other.x and self.y == other.y

    def dot(self, other):
        return self.x * other.x + self.y * other.y

    # usually cross operation return Vector but it returns scalor
    def cross(self, other):
        return self.x * other.y - self.y * other.x

    def norm(self):
        return self.x * self.x + self.y * self.y

    def abs(self):
        return math.sqrt(self.norm())

class Point(Vector):
    def __init__(self, *args, **kargs):
        return super().__init__(*args, **kargs)

class Segment:
    def __init__(self, p1=Point(0, 0), p2=Point(1, 1)):
        self.p1 = p1
        self.p2 = p2

def project(s, p):
    base = s.p2 - s.p1
    hypo = p - s.p1
    r = hypo.dot(base) / base.norm()
    return s.p1 + base * r

def reflect(s, p):
    return p + (project(s, p) - p) * 2

def read_and_print_results(s, n):
    for _ in range(n):
        line = stdin.readline().strip().split()
        p = Vector(int(line[0]), int(line[1]))
        x = reflect(s, p)
        print('{0:0.10f} {1:0.10f}'.format(x.x, x.y))

x1, y1, x2, y2 = input().split()
p1 = Point(int(x1), int(y1))
p2 = Point(int(x2), int(y2))
s = Segment(p1, p2)
n = int(input())
read_and_print_results(s, n)


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

n = int(input())
edges = [tuple([int(i) for i in input().split()]) for _ in range(n - 1)]
graph = [0] + [[] for _ in range(n)]

for e in edges:
    graph[e[0]].append(e[1])
    graph[e[1]].append(e[0])

max_color_index = 1
def bfs(graph, dist, queue, parent_colors, color_map):
    global max_color_index
    while queue:
        parent = queue.pop(0)
        children = graph[parent]

        color_index = 1
        for child in children:
            if dist[child] != -1:
                continue

            # 親との辺の色と重なった場合、一個進める
            # それ以外は1から順に埋めていく
            if parent_colors[parent] == color_index:
                color_index += 1

            e = (min(child, parent), max(child, parent))
            if e not in color_map:
                color_map[e] = color_index

            parent_colors[child] = color_index
            color_index += 1

            dist[child] = dist[parent] + 1
            queue.append(child)

        # 実際に使ったindexより1つ進んでいる
        max_color_index = max(max_color_index, color_index - 1)

dist = [0] + [-1] * n
dist[1] = 0
queue = [1]
parent_color = [0] * (n + 1)
color_map = {}
bfs(graph, dist, queue, parent_color, color_map)

print(max_color_index)
for e in edges:
    print(color_map[e])        


Measured memory_bytes: 87896
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val h = readLine()!!.split(" ").map { it.toInt() }.toMutableList()
    if (n == 1) {
        println("Yes")
        return
    }
    if (n < 4) {
        if (h[0] < h[2] && h[0] <= h[1]) println("Yes")
        else println("No")
        return
    }
    for (i in n - 1 downTo 2) {
        if (h[i] + 2 <= h[i - 1]) {
            println("No")
            return
        }
        if (h[i] < h[i - 1]) {
            h[i - 1]--
        }
    }
    if (h[0] > h[1]) {
        println("No")
    } else {
        println("Yes")
    }
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
#define all(c) (c).begin(),(c).end()
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
const ll MOD = 1e9+7;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"[";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"]";return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&p)
{o<<"{"<<p.first<<", "<<p.second<<"}";return o;}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj)
{o<<"{";for(auto itr=obj.begin();itr!=obj.end();++itr)o<<(itr!=obj.begin()?", ":"")<<*itr;o<<"}";return o;}
void dump() {}
template <class H, class... T>void dump(H&& head, T&&... tail)
{cout << head << (sizeof...(tail)==0 ? "\n" : " "); dump(forward<T>(tail)...);}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  vector<int> l(n);
  for(int i = 0; i < n; ++i){
    cin >> l[i];
  }
  sort(all(l));

  ll ans = 0;
  for(int i = 0; i < n; ++i){
    for(int j = i+1; j < n; ++j){
      auto right = lower_bound(all(l), l[i]+l[j]);
      int tmp = right - l.begin() - j - 1;
      //dump(i,j,tmp);
      if(tmp>0)ans += tmp;
    }
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

ll res[500001];

void solve(string S){
	ll c = 0, r = 0;	
	rep(i, S.length()) {
		if (S[i] == '<') {
			c++;
			res[i+1] = c;
		} else {
			c = 0;
		}
	}
	c = 0;
	rep(i, S.length()) {
		if (S[S.length()-i-1] == '>') {
			c++;
			res[S.length()-(i+1)] = max(res[S.length()-(i+1)], c);
		} else {
			c = 0;
		}
	}
	rep(i, S.length()+1) {
		r += res[i];
		// cout << res[i];
	}
	cout << r << endl;
}

int main(){	
	string S;
	cin >> S;
	solve(S);
	return 0;
}



Measured memory_bytes: 5252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MOD = 1e9+7;

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

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int K;cin>>K;

    vint lis;
    for(int i=1;i<1000;i++){
        int a=i;
        while(a<1000000000000000ll){
            lis.pb(a);
            a=a*10+9;
        }
    }
    sort(all(lis));lis.erase(unique(all(lis)),lis.end());
    vint S(lis.size());
    rep(i,lis.size()){
        int a=lis[i];
        while(a){
            S[i]+=a%10;
            a/=10;
        }
    }

    vint uku;
    rep(i,lis.size()){
        bool ok=true;
        for(int j=i+1;j<lis.size();j++){
            if(lis[i]*S[j]>lis[j]*S[i])ok=false;
        }
        if(ok)uku.pb(lis[i]);
    }
    rep(i,K)cout<<uku[i]<<endl;
    return 0;
}


Measured memory_bytes: 512
def inpl(): return [int(i) for i in input().split()]

N = int(input())
a = inpl()
mini = float('inf')
maxi = -mini
for i in a:
    mini = min(mini, i)
    maxi = max(maxi, i)
print(2*N-1)
if maxi > -mini:
    x = a.index(maxi)+1
    for i in range(1,N+1):
        print(x,i)
    for i in range(1,N):
        print(i,i+1)
else:
    x = a.index(mini)+1
    for i in range(1,N+1):
        print(x,i)
    for i in range(N,1,-1):
        print(i,i-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, x;
int a[maxn];
int main() {
	cin >> n >> x;
	if(x == 1 || x == 2 * n - 1)
		return cout << "No", 0;
	cout << "Yes\n";
	for(int i = 0; i < 2 * n - 1; i++)
		a[i] = i + 1;
	if(x > 2 && x < 2 * n - 2) {
		swap(a[n - 1], a[x - 1]);
		swap(a[n - 2], a[1]);
		swap(a[n - 3], a[0]);
		swap(a[n], a[2*n - 3]);
		swap(a[n + 1], a[2*n - 2]);			
	}
	else if (x == 2) {
		swap(a[1], a[n - 1]);
		swap(a[0], a[n - 2]);
	}
	else if (x == 2 * n - 2) {
		swap(a[n - 1], a[2 * n - 2]);
		swap(a[n - 2], a[2 * n - 3]);
	}
	
	for(int i = 0; i < 2 * n - 1; i++)
		cout << a[i] << '\n';
}

Measured memory_bytes: 2304
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cstdio>
#include<numeric>

using namespace std;
/*
int find(int x, vector<int> &p) {
if (p[x] == x)return x;
return p[x] = find(p[x], p);
}

void uni(int x, int y, vector<int> &p) {
x = find(x, p);
y = find(y, p);
p[x] = y;
}

int same(int x, int y, vector<int> p) {
if (find(x, p) == find(y, p))return 1;
return 0;
}
*/

int main() {
	long long N, K, cnt = 0, tmp, ans = 0;
	long long W, H, x, y;
  	cin >> W >> H >> x >> y;
    bool yn = (x == W/2.) && (y == H/2.);
  	cout << (W*H)/2. << " " << (int)yn;
    
  
	char qq;
	cin >> qq;
	return 0;
}

Measured memory_bytes: 256
import sys
# from math import sqrt, gcd, ceil, log
from bisect import bisect
from collections import defaultdict, Counter
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))

# sys.setrecursionlimit(10**6)



def solve():
	n = int(input()); ans = 0
	arr = [1]*(n+1)
	i = 1
	while i*2 < n+1:
		j = 2
		while i*j < n+1:
			arr[i*j] += 1
			j += 1
		i += 1
	ans = 0
	for i in range(1, n+1):
		ans += i * arr[i]
	print(ans)


	





		

if __name__ == "__main__":
	solve()

Measured memory_bytes: 151820
//Bismillahir Rahmanir Rahim

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

int main(){
  int t, ac=0, wa=0, tle=0, re=0;
  cin>>t;
  while(t--){
    string s;
    cin>>s;
    if(s[0]=='A') ac++;
    else if(s[0]=='W') wa++;
    else if(s[0]=='T') tle++;
    else if(s[0]=='R') re++;}
  cout<<"AC x "<<ac<<"\n";
  cout<<"WA x "<<wa<<"\n";
  cout<<"TLE x "<<tle<<"\n";
  cout<<"RE x "<<re<<"\n";
}



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

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

	int cnt = 0;
	int max_ab = max(A, B);

	for(int i = max_ab; i > 0; --i) {
		if(A % i == 0 && B % i == 0) {
			cnt++;

			if(cnt == K) {
				cout << i << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <ostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define INF 1000000000
#define rep(i,a,b) for (int i=(a);i<(b);i++)
#define rev(i,a,b) for (int i=(a)-1;i>=b;i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef queue<int> qi;
typedef queue< pair<int, int> > qpii;
typedef vector<int> vi;
typedef vector<int, int> vii;
typedef vector<string> vs;
typedef vector< pair<int, int> > vpii;
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };

map<string, int> d;

void bfs() {
	int dn[4] = {4, -4, -1, 1};
	queue<string> qs;

	qs.push("01234567");
	d["01234567"] = 0;

	while(qs.size()) {
		string s = qs.front(); qs.pop();
		int n = s.find("0");
		rep(i,0,4) {
			int ne = n + dn[i];
			if(0<=ne && ne<8) {
				if((n==4&&ne==3) || (n==3&&ne==4)) continue;
				string ss = s;

				char tmp = ss[n];
				ss[n] = ss[ne];
				ss[ne] = tmp;

				if(d.find(ss)==d.end()) {
					qs.push(ss);
					d[ss] = d[s] +1;
				}
			}
		}
	}
}

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

	bfs();

	while(1) {
		string in = "";
		char num;
		rep(i,0,8) {
			if(cin >> num) in += num;
			else return 0;
		}
		cout << d[in] << endl;
	}

	return 0;
}

Measured memory_bytes: 3452
#include <stdio.h>

int main(){

    int i,j,numl[1001],ans;
    char num[1001];
    i=0; 
   
     while(1){
		 scanf("%s",num);
         if (num[0]=='0') break;
         ans=0;
         j=0;
   
          while(1){
			if (num[j]=='\0') break;
			ans+=(int)(num[j]-'0');
	       ++j;
	     }
	     	     
           numl[i]=ans;
	       ++i;
	    }
   
       
     for (j=0;j<i;j++){
	  printf("%d\n",numl[j]);
     }  
    
	return 0;
}

Measured memory_bytes: 540
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;

int main(){
    int n,k,count=0;
    cin>>n>>k;
    REP(i, 100000000){
        if(n>0){
            n-=k;
            count++;
            if(n>0){
                n++;
            }
        }else{
            break;
        }
    }
    cout<<count;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
int a;
scanf("%d",&a);
if(a/100==7){
	printf("Yes");
}
else if(((a/100)-7)%10==0){
	printf("Yes");
}
else if (((a/10)-7)%10==0){
	printf("Yes");
}
else if((a-7)%10==0){
	printf("Yes");
}
else{
	printf("No");
}
return 0;
}


Measured memory_bytes: 1728
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;
    
    int a, b, c;
    io.read(a, b, c);
    priority_queue<int, vector<int>, greater<int>> q;
    q.push(a);
    q.push(b);
    q.push(c);
    int ans = 0;
    ans += q.top();
    q.pop();
    ans += q.top();
    q.pop();
    cout << ans;
    return 0;
}

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

#define int long long

#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##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(box) box.begin(), box.end()

using namespace std;

using P = pair<int, int>;
using ll = long long;

const long long INF = LLONG_MAX/3;

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

struct UnionFind{
	std::vector<int> par,siz;
	void init(int n){
		par.resize(n);
		for(int i=0;i<n;i++)par[i]=i;
		siz.resize(n,1);
	}
	UnionFind(int n){
		init(n);
	}
	int root(int n){
		if(par[n]==n)return n;
		else return par[n]=root(par[n]);
	}
	bool issame(int x,int y){
		return (root(x)==root(y));
	}
	bool marge(int a,int b){
		if(issame(a,b))return false;
		else{
			a=root(a),b=root(b);
			if(siz[a]<siz[b])swap(a,b);
			siz[a]+=siz[b];
			par[a]=par[b];
			return true;
		}
	}
	int size(int n){
		return siz[root(n)];
	}
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}
const int MOD=1e9+7;
long long fac[510000], finv[510000], inv[510000];
long long MAX=510000;
bool COMinited=false;
long long COM(int n, int k){
	if(COMinited==false){
		fac[0] = fac[1] = 1;
    	finv[0] = finv[1] = 1;
    	inv[1] = 1;
    	for (int i = 2; i < MAX; i++){
        	fac[i] = fac[i - 1] * i % MOD;
        	inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        	finv[i] = finv[i - 1] * inv[i] % MOD;
    	}
		COMinited=true;
	}
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
signed main(){
	int n;
	cin>>n;
	int memo=n+1;
	int ans=0;
	rep(i,n){
		int p;
		cin>>p;
		if(p<memo){
			ans++;
			memo=p;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
s = input()
t = input()
if s == t:
    print(n)
    exit()
for i in range(n):
    if s[i:] == t[:-i]:
        print(n+i)
        exit()
print(n+n)


Measured memory_bytes: 10216
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		label:while(cin.hasNext()){
			String str = cin.next();
			str = str.replace('o', '1');
			str = str.replace('x', '9');
			str = str.replace('s', '0');
			
			int[][] a = new int[3][3];
			String[] s = new String[3];
			s[0]=str.substring(0, 3);
			s[1]=str.substring(3, 6);
			s[2]=str.substring(6, 9);
			for(int i = 0; i < 3;i++){
				for(int j = 0; j < 3;j++){
					a[i][j] = Integer.parseInt(s[i].substring(j, j+1));
				}
			}
			for(int i = 0; i < 3;i++){
				if(a[i][0]+a[i][1]+a[i][2] == 3){
					System.out.println("o");
					continue label;
				}
				else if(a[i][0]+a[i][1]+a[i][2] == 27){
					System.out.println("x");
					continue label;
				}
			}
			for(int i = 0; i < 3;i++){
				if(a[0][i]+a[1][i]+a[2][i] == 3){
					System.out.println("o");
					continue label;
				}
				else if(a[0][i]+a[1][i]+a[2][i] == 27){
					System.out.println("x");
					continue label;
				}
			}
			if(a[0][0]+a[1][1]+a[2][2]==3){
				System.out.println("o");
				continue;
			}
			else if(a[0][0]+a[1][1]+a[2][2]==27){
				System.out.println("x");
				continue;
			}
			if(a[2][0]+a[1][1]+a[0][2]==3){
				System.out.println("o");
				continue;
			}
			else if(a[2][0]+a[1][1]+a[0][2]==27){
				System.out.println("x");
				continue;
			}
			System.out.println("d");
		}
	}

}

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


int main(){
  double L, ans;
  cin >> L;
  ans = L/3*L/3*L/3;
  
  printf("%.6f", ans);
  return 0;
}

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

int main()
{
  int n;
  cin >> n;
  
  vector<ll> L(100);
  L[0]=2;
  L[1]=1;
  
  for (int i = 2; i < 90; i++){
    L[i] = L[i-1] + L[i-2]; 
  }
  
  if(n==1){
    cout << 1 << endl;
  }else{
    cout << L[n] << endl;
  }

  return 0;
}

Measured memory_bytes: 3592
'''
3^9 = 19683
3^10 = 59049
これくらいの数なら全探索して十分間に合う
'''

import itertools
from functools import reduce

n = int(input())
ketasuu = len(str(n))
ans = 0

base = itertools.product('357', repeat=ketasuu)
# baseはタプルからなるリスト

for i in base:
	if len(set(i))== 3: # 3種類の数字が1回以上使われている
		i_int = int(reduce(lambda x, y: x + y, i))
		if i_int <= n:
			ans += 1

for k in range(3, ketasuu):
	temp = 3**k - 3*1**k - 3 * (2**k - 2* 1**k)
	ans += temp

print(ans)


Measured memory_bytes: 3572
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n,a;
  vector<int>v(1,0);
  cin >> n;
  while(n--){
    cin >> a;
    v.push_back(a);
  }
  for(int j=1;j<v.size();j++){
    int key = v[j],i = j - 1;
    while(i > 0 && v[i] > key){
      v[i+1] = v[i];
      i--;
    }
    v[i+1] = key;
    for(int j=1;j<v.size();j++){
      cout << (j==1?"":" ") << v[j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 1220
#include <iostream>
#include <cstdio>
#include <cstring>
#define maxlen 55
using namespace std;
int n,m;
int a,b,c;
int t;
long long x[35][maxlen][maxlen];
long long ans[2][maxlen][maxlen];
int aaa[maxlen];
int main ()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    while(cin>>n>>m>>a>>b>>c>>t)
    {
       // t++;
        memset(x,0,sizeof(x));
        memset(ans,0,sizeof(ans));
        memset(aaa,0,sizeof(aaa));
        if(n==0&&m==0&&a==0&&b==0&&c==0&&t==0)
            break;
        // t = t%(3*n);
        for(int i=0; i<n; i++)cin>>aaa[i],x[0][i][i]=1;
        //for(int i=0; i<n; i++)cout<<x[0][i][i]<<(i==n-1?"\n":" ");
        x[1][0][0]=b,x[1][0][1]=c;
        for(int i=1; i<n; i++)
            x[1][i][i-1]=(a)%m,
                         x[1][i][i]=(b)%m,
                                    x[1][i][i+1]=(c)%m;
                                   //,cout<<x[1][i][i-1]<<x[1][i][i]<<x[1][i][i+1]<<endl;

        int tt=t,cnt=0;
        while(tt!=0)cnt++,tt>>=1;
        for(int k=2; k<=cnt; k++)
        {
            //cout<<k<<endl;
            for(int i=0; i<n; i++)
            {
                for(int j=0; j<n; j++)
                {
                    for(int l=0; l<n; l++)
                    {
                        x[k][i][l]+=x[k-1][j][l]*x[k-1][i][j];
                        x[k][i][l]%=m;
                    }
                }
            }
        }
        tt=t,cnt=1;
        int mark=0;
        if(tt==0)
        {
            for(int i=0; i<n; i++)cout<<aaa[i]<<(i==n-1?"\n":" ");
           continue;
        }
        while(tt!=0)
        {
            if(tt&1)
            {
                if(mark==0)
                {
                    mark=1;
                    for(int i=0; i<n; i++)
                        for(int j=0; j<n; j++)
                            ans[0][i][j]=x[cnt][i][j];
                }
                else
                {
                    for(int i=0; i<n; i++)
                    {
                        for(int j=0; j<n; j++)
                        {
                            for(int l=0; l<n; l++)
                            {
                                ans[1][i][l]+=ans[0][i][j]*x[cnt][j][l];
                                ans[1][i][l]%=m;
                            }
                        }
                    }
                    for(int i=0; i<n; i++)
                        for(int j=0; j<n; j++)
                        {
                            ans[0][i][j]=ans[1][i][j];
                            ans[1][i][j]=0;
                        }
                }
            }
            cnt++;
            tt>>=1;
        }
        for(int i=0; i<n; i++)
        {
            int tmp=0;
            for(int j=0; j<n; j++)
            {
                tmp+=ans[0][i][j]*aaa[j];
                tmp%=m;
            }
            cout<<tmp<<(i==n-1?"\n":" ");
        }
    }

}

Measured memory_bytes: 2044
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int S = scan.nextInt();
		long[]a = new long[N];
		for(int i = 0; i < N; i++) {
			a[i] = scan.nextLong();
		}
		scan.close();
		int min = Integer.MAX_VALUE;
		long sum = 0;
		int right = 0;
		for(int left = 0; left < N; left++) {
			while(right < N && sum + a[right] < S){
				sum += a[right];
				right++;
			}
			if(right < N) {
				if(sum + a[right] >= S) {
					int l = right - left + 1;
					min = Math.min(min, l);
				}
			}

			if(right == left) {
				right ++;
			}else {
				sum -= a[left];
			}
		}
		if(min == Integer.MAX_VALUE) {
			System.out.println(0);
		}else {
			System.out.println(min);
		}
	}
}


Measured memory_bytes: 71428
// 2014/06/03 Tazoe

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
	while(true){
		int m;
		cin >> m;

		if(m==0)
			break;

		double S1 = 0.0;
		int V1 = 360;

		for(int i=0; i<m-1; i++){
			int v;
			cin >> v;

			S1 += sin((double)v*M_PI/180.0);
			V1 -= v;
		}

		S1 += sin((double)V1*M_PI/180.0);

		int n;
		cin >> n;

		double S2 = 0.0;
		int V2 = 360;

		for(int i=0; i<n-1; i++){
			int v;
			cin >> v;

			S2 += sin((double)v*M_PI/180.0);
			V2 -= v;
		}

		S2 += sin((double)V2*M_PI/180.0);

		if(fabs(S1-S2)<0.0000001){
			cout << 0 << endl;
		}
		else if(S1>S2){
			cout << 1 << endl;
		}
		else{
			cout << 2 << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int mod = 1e9 + 9;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1 ;
	//cin >> t;
	while(t--){
		int n;
		cin >> n;
		vector<int> h(n);
		for(int &a : h)
			cin >> a;
		vector<int> dp(n,0);
		dp[1] = abs(h[0] - h[1]);
		for(int i = 2; i <n; i++){
			dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
		}
		cout << dp[n-1] << endl;
	}
	return 0;
}


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

int main() {
  
  while (true) {
    
    int H, W; cin >> H >> W;
    
    if (H != 0 && W != 0) {
      
      for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
          if (i % 2 == 0) {
            if (j % 2 == 0) cout << "#";
            else cout << ".";
          }
          else {
            if (j % 2 == 0) cout << ".";
            else cout << "#";
          }
        }
        cout << endl;
      }
      
    }
    
    else {
      break;
    }
    
    cout << endl;
    
  }
  
}


Measured memory_bytes: 3008
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String args[]) {
        FastReader sc = new FastReader();
        int n = sc.nextInt();
        int[] as = new int[n];
        for (int i = 0; i < n; i++) {
            as[i] = sc.nextInt();
        }
        int sum = Math.abs(as[0]);
        for (int i = 1; i < n; i++) {
            sum += Math.abs(as[i] - as[i-1]);
        }
        sum += Math.abs(as[n-1]);
        System.out.println(sum + Math.abs(as[1]) - Math.abs(as[0]) -
                Math.abs(as[0] - as[1]));
        for (int i = 1; i < n-1; i++) {
            int ans = sum + Math.abs(as[i-1] - as[i+1]) -
                    Math.abs(as[i-1] - as[i]) - Math.abs(as[i] - as[i+1]);
            System.out.println(ans);
        }
        System.out.println(sum + Math.abs(as[n-2]) - Math.abs(as[n-1]) -
                Math.abs(as[n-2] - as[n-1]));
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}

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

struct t_card{
	char mark;
	long num;
	t_card operator=( const t_card &t ){
		mark = t.mark;
		num = t.num;
		return t;
	}
};
bool operator<( const t_card &l, const t_card &r ){
	return l.num < r.num;
}

int partition(t_card a[], int p, int r){
	t_card x = a[r];
	int i = p;
	for( int j=p; j<r; j++ ){
		if( a[j].num <= x.num ){
			t_card tmp = a[j];
			a[j] = a[i];
			a[i] = tmp;
			i++;
		}
	}
	a[r] = a[i];
	a[i] = x;
	return i;
}

void quicksort( t_card a[], int p, int r ){
	if( p < r ){
		int q = partition(a,p,r);
		quicksort(a,p,q-1);
		quicksort(a,q+1,r);
	}
}

int main(){
	int n;
	t_card a[100001],b[100001];
	cin >> n;
	for( int i=0; i<n; i++ ){
		char c;
		long k;
		cin >> c >> k;
		a[i].mark = c;
		a[i].num = k;
	}
	memcpy( b, a, sizeof(a) );
	quicksort( a, 0, n-1 );
	stable_sort( b, b+n );
	int i=0;
	for( ; i<n; i++ ){
		if( a[i].mark != b[i].mark ){
			cout << "Not stable" << endl;
			break;
		}
	}
	if( i==n )	cout << "Stable" << endl;
	for( i=0; i<n; i++ ){
		cout << a[i].mark << " " << a[i].num << endl;
	}
	return 0;
}

Measured memory_bytes: 4968