akhauriyash/Code-Regression huggingface dataset:
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstdlib>
#define rp(i,a,b) for(int (i)=(int)(a);i<(int)(b);++i)

typedef long long ll;

using namespace std;

int main(){
    string s;
    cin>>s;
    bool f1=false,f2=false;
    rp(i,0,s.size()){
        if(f1==false and f2==false and s[i]=='C')
            f1=true;
        if(f1==true and f2==false and s[i]=='F')
            f2=true;
    }
    if(f2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args){
        
    	Scanner sc= new Scanner(System.in);
    	int N=sc.nextInt();
    	sc.nextLine();
        int[] x =new int[2*N];
        for(int i=0;i<2*N;i++) {
        	x[i]=sc.nextInt();
        	
        }
       
        double d=0;

        for(int i=0;i<2*N;i+=2) {
        	for(int j=i+2;j<2*N;j+=2) {
        		
        		int dx=Math.abs(x[j]-x[i]);
        		int dy=Math.abs(x[i+1]-x[j+1]);
        		d+=Math.sqrt(Math.pow(dx,2)+Math.pow(dy,2));
        		
        	}
    	}

        int z=N*(N-1)/2;
        double answer=d/z*(N-1);
        System.out.println(answer);
    }
}

Measured memory_bytes: 22352
# Algorithms and Data Structures 1
# Bubble Sort
# Name: Ryuya Asada
# ID: s1260064


def BubbleSort(A: list):
    number_of_swaps = 0
    flag = 1
    while flag:
        flag = 0
        for j in range(len(A)-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                number_of_swaps += 1
    print(*A, sep=" ")
    print(number_of_swaps)


def main():
    length = int(input())
    A = [int(e) for e in input().split(" ")]
    BubbleSort(A)

if __name__ == "__main__":
    main()



Measured memory_bytes: 5612
#include <bits/stdc++.h>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main(){
    int n;
    cin >> n;
    ll x[n];
    pair<ll,int> sort_x[n];
    for(int i=0; i<n; i++){
        cin >> x[i];
        sort_x[i].first=x[i];
        sort_x[i].second=i;
    }
    sort(sort_x,sort_x+n);
    int mid1 = sort_x[n/2-1].first;
    int mid2 = sort_x[n/2].first;
    for(int i=0; i<n; i++){
        if(x[i]<=mid1){
            cout << mid2 << endl;
        }else{
            cout << mid1 << endl;
        }
    }
    return 0;
}


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

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

	string ans = "No";
	int a = 0;
	int b = 0;
	for( int i = 0; i < S.size(); i++ ) {
		if( S[i] == 'A' ) a++;
		if( S[i] == 'B' ) b++;
	}
	if( a && b ) ans = "Yes";

	cout << ans << endl;
}


Measured memory_bytes: 256
function myout(text){console.log(text);}//standard output
function Main(input) {
	//input = parseInt(input);
	//input = input.trim().split(" ");
	//input = input.trim().split("\n");
	//input = input.trim().split(" ").map((a)=>Number(a));
	input = input.trim().split("\n").map((a)=>Number(a));
  var len = input[0];
  var output = 0;
  input.shift();
  for(var i = 0; i < len; i++){
    if(i == 0){
       output += Math.floor(input[i] / 2);
      input[i] = input[i] % 2;
    }else{
      if(input[i] != 0){
         if(input[i-1] != 0){
         	var tmp = Math.min(input[i],input[i-1]); 
           output += tmp;
           input[i] -= tmp;
           input[i-1] -= tmp;
           if(input[i] >= 2){
              output += Math.floor(input[i] / 2);
             input[i] = input[i] % 2;
           }
         }else{
            output += Math.floor(input[i] / 2);
           input[i] = input[i] % 2;
         }
      }
    }
    //myout(output);
    //myout(input);
  }
  myout(output);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


Measured memory_bytes: 28120
#!/usr/bin/env python3
import sys
import math

def solve(N: int, P: "List[int]", Q: "List[int]"):
    cnta = 0
    cntb = 0

    for i, x in enumerate(P):
        p_ = x-1
        for y in range(i):
            if P[y] < x : p_-=1
        cnta += p_ * math.factorial(N - 1 - i)
    for i, x in enumerate(Q):
        p_ = x-1
        for y in range(i):
            if Q[y] < x : p_-=1
        cntb += p_ * math.factorial(N - 1 - i)
    # print(cnta, cntb)
    print(abs(cnta-cntb))

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    Q = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, P, Q)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
x,y = map(int,input().split())
if (x+y)%3:
    print(0)
    exit()
c = (x+y)//3
x -= c; y -= c
if x<0 or y<0:
    print(0)
    exit()

n = x+y
mod = 10**9+7
fun = [1]*(n+1)
for i in range(1,n+1):
    fun[i] = fun[i-1]*i%mod
rev = [1]*(n+1)
rev[n] = pow(fun[n],mod-2,mod)
for i in range(n-1,0,-1):
    rev[i] = rev[i+1]*(i+1)%mod

def nCr(n,r):
    if r > n:
        return 0
    return fun[n]*rev[r]%mod*rev[n-r]%mod
    
print(nCr(x+y,x))

Measured memory_bytes: 55796
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>

typedef long long LL;

const int N=505;
const LL inf=(LL)1e17;

int n;
LL s1[N][N],s2[N][N],a[N][N],f[N][N];

void pre()
{
	for (int l=1;l<n;l++)
		for (int i=1;i+l<=n;i++)
		{
			int j=i+l;
			s1[i][j]=s1[i][j-1]+s1[i+1][j]-s1[i+1][j-1]+a[i][j];
		}
	for (int i=1;i<=n;i++)
		for (int j=n;j>i;j--)
			s2[i][j]=s2[i][j+1]+a[j][i];
	for (int j=1;j<=n;j++)
		for (int i=1;i<j;i++)
			s2[i][j]+=s2[i-1][j];
}

LL dp()
{
	for (int i=0;i<=n;i++)
		for (int j=0;j<=n;j++)
			f[i][j]=inf;
	LL ans=s1[1][n];
	for (int i=1;i<=n;i++) ans=std::min(ans,s1[1][i]+s1[i+1][n]);
	for (int i=1;i<n;i++)
		for (int j=i+1;j<=n;j++)
			f[i][j]=s1[1][i]+s1[i+1][j]+s2[i][j+1];
	for (int j=1;j<=n;j++)
		for (int i=1;i<j;i++)
		{
			ans=std::min(ans,f[i][j]+s1[j+1][n]);
			for (int k=j+1;k<=n;k++)
				f[j][k]=std::min(f[j][k],f[i][j]+s1[j+1][k]+s2[j][k+1]-s2[i][k+1]);
		}
	return ans;
}

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
			if (i!=j) scanf("%lld",&a[i][j]);
	pre();
	printf("%lld\n",dp());
	return 0;
}

Measured memory_bytes: 8192
#include <stdio.h>

int		main(void)
{
	int n;
	scanf("%d", &n);
	int a[n];
	int i;
	int count;
	i = 0;
	while (i < n)
		scanf("%d", &a[i++]);

	i = 0;
	count = 0;
	while (a[i] % 2 == 0)
	{
		a[i] /= 2;
		i++;
		if (i == n)
		{
			i = 0;
			count++;
		}
	}
	printf("%d", count);
	return (0);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int n, na;
  cin >>n;
  na = n % 1000;
    if(na % 111 == 0){
      cout << "Yes" <<endl;
    }
  else if ((n - n%10)%1110 == 0){
    cout << "Yes" << endl;
  }
  else { cout<<"No"<<endl;}
}

Measured memory_bytes: 256
#include <stdio.h>

long long sumf(long long, long long);

int main()
{
    long long n, a;
    long long ans, sum;
    
    scanf("%d", &n);
    
    ans = sumf(1, 0) + sumf(n - 1, 0);
    
    for (a = 2; a  <= n / 2; ++a)
    {
        sum = sumf(a, 0) + sumf(n - a, 0);
        
        if (ans > sum)
        {
            ans = sum;
        }
    }
    printf("%d", ans);
    
    return 0;
}


long long sumf(long long a, long long sum)
{
    if (a < 10)
    {
        return sum + a;
    }
    else
    {
        sumf(a / 10, sum + a % 10);
    }
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#include <time.h>
typedef std::pair<int,int> pii;
using namespace std;
using ll = long long;
#define PI 3.14159265358979323846264338327950L
const int mod =  998244353;



#define SIZE 200005
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

struct BIT{
	int bit[SIZE];
	
	void init(){memset(bit,0,sizeof(bit));}
    
	void add(int k,int x) {
		k++;
		while(k<SIZE){
			bit[k]+=x;
			k+=k&-k;
		}
	}
	int get(int k){
		k++;
		int ret=0;
		while(k>0){
			ret+=bit[k];
			k-=k&-k;
		}
		return ret;
	}
    
	int get(int s,int t){
		return get(t)-get(s-1);
	}
    
	int pos(int k){ //k番目
		int l=0,r=SIZE;
		while(r-l>1)
		{
			int m=(l+r)/2;
			if(get(m)<k) l=m;
			else r=m;
		}
		return r;
	}
};


BIT bit;




void solve(){
    string s;
    cin >> s;
    cout << s.substr(0,3);

}


int main(){
    int T;
    T = 1;
    while(T--){
        solve();
        cout << endl;
    }
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>

using namespace std;

typedef long long ll;

int main() {
    int n,a;cin >> n >> a;
    if (n%500 <= a)
        cout << "Yes" << endl;
    else 
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+5;
const int mod = 998244353;
const int INF = 0x3f3f3f3f;
typedef long long ll;
ll inv(ll b)
{
	if(b == 1)	return 1;
	return (mod-mod/b)*inv(mod%b)%mod;
}
ll fac[N];
ll C(ll n,ll m)
{
	ll t = (fac[m]*fac[n-m])%mod;
	return (fac[n]*inv(t))%mod;
}
ll ans[N][2];
int main()
{
	ll n,i,a,b,k;
	fac[0] = 1;
	fac[1] = 1;
	for(i = 2;i <= 3e5+5;i++)
	{
		fac[i] = (fac[i-1]*i)%mod;
	}
	scanf("%lld %lld %lld %lld",&n,&a,&b,&k);
	ll cnt = 0;
	for(i = 0;i <= n;i++)
	{
		if(k-(i*a) >= 0 && (k-a*i)%b == 0 && (k-a*i)/b <= n)
		{
			ans[cnt][0] = i;
			ans[cnt][1] = (k-a*i)/b;
			++cnt;
		}
	}
	ll res=0;
	for(i = 0;i < cnt;i++)
	{
		res = (res+C(n,ans[i][0])*C(n,ans[i][1])%mod)%mod;
	}
	printf("%lld",res);
}

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

using namespace std;

int main() {


    int n, v, c, x, y, soma=0;
    cin >> n;
    int listaV[n];
    int listaC[n];
    int listaL[1000];
    

    for(int i=0;i<n;i++){
        cin >> v;
        listaV[i] = v;
    }
    
    for(int p=0;p<n;p++){
        cin >> c;
        listaC[p] = c;
    }
        
    for(int k=0; k<n; k++){

        listaL[k] = listaV[k] - listaC[k];

        if(listaL[k]>0) {
            
            soma = soma + listaL[k];

        }

    }

    cout << soma << endl;

    
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

void trace(int a[], int n) {
	int i;
	for (i = 0; i < n; i++) {
		if (i) printf(" ");
		printf("%d", a[i]);
	}
	printf("\n");
}
void insertionsort(int a[], int n) {
	int j, i, v;
	for (i = 1; i < n; i++) {
		v = a[i];
		j = i - 1;
		while (j >= 0 && a[j] > v) {
			a[j + 1] = a[j];
			j--;
		}
		a[j+1]=v;
		trace(a,n);
	}
}


int main(){
	int n, i, j;
	int a[100];
    cin>>n;
	for (i = 0; i < n; i++) {
	cin>>a[i];
	}
	trace(a, n);
	insertionsort(a, n);
	return 0;
}


Measured memory_bytes: 3104
void main() {
	auto S = rs;
	auto N = S.length;
	alias Pair = Tuple!(dchar, "c", ulong, "l", ulong, "r", ulong, "n");
	ulong k;
	Pair[] pairs;
	foreach(v; S.group) {
		pairs ~= Pair(v[0], k, k+v[1]-1, v[1]);
		k += v[1];
	}
	auto arr = new ulong[](N);
	foreach(p; pairs) {
		debug writefln("%s, [%d, %d], %d", p.c, p.l, p.r, p.n);
		if(p.l == 0 && p.c == 'L') {
			arr[0] = p.n;
			continue;
		}
		if(p.r == N-1 && p.c == 'R') {
			arr[N-1] = p.n;
			continue;
		}
		if(p.c == 'R') {
			arr[p.r] += (p.n + 1) / 2;
			arr[p.r + 1] += p.n / 2;
		} else {
			arr[p.l] += (p.n + 1) / 2;
			arr[p.l - 1] += p.n / 2;
		}
		debug writefln("%(%d %)", arr);
	}
	writefln("%(%d %)", arr);
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 4504
n=int(input())
d=[0]+[-10**18]*n
for j,(a,i)in enumerate(sorted((-a,i)for i,a in enumerate(map(int,input().split())))):
    d=[max(t-a*abs(~i-j+k+n),d[k-1]-a*abs(~i+k))for k,t in enumerate(d)]
print(max(d))

Measured memory_bytes: 75060
#include<bits/stdc++.h>
#define ll long long
#define f(i,l,r) for(int i=l;i<r;i++)
#define debug(x) cout<<#x<<'='<<(x)<<endl
using namespace std;
double dp[3001][3001];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    double p;
    dp[0][0]=1;

    for(int i=1;i<=n;i++)
    {
        cin>>p;
        for(int h=0;h<=i;h++)
        {
            if(h==0)    dp[i][h]=(1-p)*dp[i-1][h];
            else
            {
                dp[i][h]=dp[i-1][h-1]*p+(1-p)*dp[i-1][h];
            }
            
        }
    }
    double ans=0;
    for(int i=n/2+1;i<=n;i++)
        ans+=dp[n][i];
    printf("%.10lf",ans);
    return 0;
}

Measured memory_bytes: 68992
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

int main(){
	int n, m, i, j, t, k;
	while(~scanf("%d %d", &n, &m)){
		int a[55] = {0};
		for(i = 0; i < m; i++){
			scanf("%d %d", &t, &k);
			for(j = 1; j <= n; j++){
				if(j == t) a[t]++;
				if(j == k) a[k]++;
			}
		}
		for(i = 1; i <= n; i++)
			cout << a[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#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) (v).begin(),(v).end()
#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; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

string S, T;

bool solve() {
	map<char, char> mm;
	REP(i, S.size()) {
		if (mm.find(S[i]) != mm.end()) {
			if (mm[S[i]] != T[i]) return false;
		}
		else {
			mm[S[i]] = T[i];
		}
	}
	
	return true;
}

int main() {
	cin >> S >> T;
	
	bool ans = solve();
	
	REP(i, S.size()) swap(S[i], T[i]);
	ans &= solve();
	
	puts(ans ? "Yes" : "No");
	
	return 0;
}

Measured memory_bytes: 776
#include <iostream>

using namespace std;

int main(){
    while(true){
        int a, b;
        cin >> a >> b;
        if(a == 0 and b == 0){
            break;
        }
        else{
            if(a > b){
                cout << b << " " << a << endl;
            }
            else{
                cout << a << " " << b << endl;
            }
        }
    }
    return 0;
}


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

string S;

int catcheck(int pointer){
	
	if (S[pointer] != 'm') return -1;
	pointer++;

	if (S[pointer] != 'e'){
		pointer = catcheck(pointer);
		if (pointer == -1) return -1;
	}
	pointer++;

	if (S[pointer] != 'w'){
		pointer = catcheck(pointer);
		if (pointer == -1) return -1;
	}
	pointer++;

	return pointer;
}

int main(){

	cin >> S;
	if (S.length() == catcheck(0)){
		cout << "Cat" << endl;
	}
	else{
		cout << "Rabbit" << endl;
	}

	return 0;
}

Measured memory_bytes: 1184
#include<stdio.h>
int main(void)
{
	int n,a[200],i,s,cnt,flg;
	cnt=0;
	flg=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	while(1){
		for(i=0;i<n;i++){
			if(a[i]%2!=0){
				flg=1;
				break;
			}
		}
		if(flg==1){
			break;
		}
		for(i=0;i<n;i++){
			a[i]/=2;
		}
		cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}


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

int main(){
    int n,a,b;
    a = 0;
    b = 0;
    string t,h;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> t >> h;
        if(t==h){
            a += 1;
            b += 1;
        }else if(t>h){
            a += 3;
        }else{
            b += 3;
        };
    };
    cout << a << " " << b << endl;
    return 0;
}


Measured memory_bytes: 3216
<?php
  fscanf(STDIN, "%d %d %d", $N, $A, $B);
  $reslut=$N*$A;
  if($reslut === $B ){
  echo $reslut;
  }
elseif($reslut <= $B ){
  echo $reslut;
}else{
  echo $B;
}
?>

Measured memory_bytes: 3828
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;
typedef pair<ll, ll> pl;

pl div(pl a)
{
  while(a.second % 2 == 0 && a.first % 2 == 0){
    a.second /= 2;
    a.first /= 2;
  }
  return a;
}

pl sub(pl a, pl b)
{
  a.first = a.first * b.second - a.second * b.first;
  a.second *= b.second;
  return div(a);
}

pl plu(pl a, pl b)
{
  a.first = a.first * b.second + a.second * b.first;
  a.second *= b.second;
  //  cout << a.first << endl;
  return div(a);
}

int main()
{
  while(1){
    string s;
    cin >> s;
    if(s == "#") break;
    vector<char>v;
    for(int i=s.size()-1;i>=0;i--)
      if(s[i] == 'n' || s[i] == 'w') v.push_back(s[i]);
    pl digree = make_pair(0, 1);
    ll pow = 1;    
    if(v[0] == 'w') digree = MP(90, pow);

    for(int i=1;i<v.size();i++){
      pow *= 2;
      if(v[i] == 'w') digree = plu(digree, MP(90, pow));
      else digree = sub(digree, MP(90, pow));
      //      cout << digree.first << endl;
    }

    if(digree.second == 1) cout << digree.first << endl;
    else cout << digree.first <<  "/"  << digree.second << endl;
  }
  return 0;
}

Measured memory_bytes: 1216
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
#include <list>
#include <cassert>
 
using namespace std; 

const long long INF=1LL<<50LL;
const double PI=3.14159265358979323846264;
const long long mod=1000000000LL+7LL;

long long gcd(long long x,long long y){
	return y==0 ? x : gcd(y,x%y);
}

int main(){

	string s="CODEFESTIVAL2016";

	string t;
	cin>>t;

	int res=0;
	for(int i=0;i<s.size();i++) res+=s[i]!=t[i];
	cout<<res<<endl;

}


Measured memory_bytes: 384
import java.util.*;
import java.io.*;

public class Main {	

	private static void solve(){
		//Implement solution here.
		int K = ni();
		int A = ni();
		int B = ni();
		for(int i = A; i <= B; i++) {
			if(i%K == 0) {
				System.out.println("OK");
				return;
			}
		}
		System.out.println("NG");
	}

	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		boolean hasNext = true;
		while(hasNext){
			solve();	
			try{
				br.mark(1);
				if(br.read() > 0){
					br.reset();			
					System.out.println("---");
				} else {
					hasNext = false;
				}
			}catch(Exception e){
				throw new RuntimeException(e);
			} 
		}
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 25424
#include <bits/stdc++.h>
#define x real()
#define y imag()
using namespace std;
typedef complex<double> point;
typedef long long ll;
int n;
vector <point> xy;
bool used[5001][5001];
ll ans;

void check(point a,point b){
  point d=b-a;
  point e=point(0,abs(d));
  point f=point(abs(d),abs(d));
  e=(e*d/abs(d))+a;
  f=(f*d/abs(d))+a;
  a=e,b=f;
  int ax=a.x,ay=a.y,bx=b.x,by=b.y;

  if(ax<0||ay<0||bx<0||by<0||5000<ax||5000<bx||5000<ay||5000<by)return;
  if(a.x==ax&&b.x==bx&&a.y==ay&&b.y==by&&used[ax][ay]&&used[bx][by])ans=max(ans,ll(d.x*d.x+d.y*d.y));
  
}

int main(){
  while(cin>>n,n){
    xy.clear();
    memset(used,0,sizeof(used));
    for(int i=0,a,b;i<n;i++){
      cin>>a>>b;
      used[a][b]=1;
      xy.push_back(point(a,b));
    }
    ans=0;
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)if(i!=j)check(xy[i],xy[j]);
    cout <<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 25760
package main

import (
	"fmt"
)

func abs(x int) int {
	var res = x

	if x < 0 {
		res = -x
	}

	return res
}

func main() {
	var N, left, right int
	var ans = 10001
	fmt.Scan(&N)
	W := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&W[i])
		right += W[i]
	}

	for i := 0; i < N; i++ {
		left += W[i]
		right -= W[i]
		calc := abs(left - right)

		if ans > calc {
			ans = calc
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <stdio.h>
#include <algorithm>

int N, K, a[1123], b[1123];
int ans[1123];

int main(void) {
	scanf("%d%d", &N, &K);
	for (int i = 0; i < K; ++i) { scanf("%d%d", &a[i], &b[i]); }

	for (int i = 0; i < K; ++i) {
		ans[i] = std::min(a[i] - 1, std::min(N - a[i], std::min(b[i] - 1, N - b[i])));
		ans[i] %= 3;
	}

	for (int i = 0; i < K; ++i) { printf("%d\n", ans[i] + 1); }
	return 0;
}

Measured memory_bytes: 2704
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] x = new int[n];
		for(int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
		}
		int cout = 0;
		for(int i = 0; i < n; i++) {
			if(x[i] > k / 2) {
				cout += k - x[i];
			} else {
				cout += x[i];
			}
		}
		System.out.println(cout * 2);
	}
}

Measured memory_bytes: 21460
import java.util.*;
import java.util.Map.Entry;
import java.math.*;
import java.awt.geom.*;
import java.io.*;
      
      
public class Main {	
	static boolean[] use;
	static boolean[] used;
	static boolean[] notEmpty;
	static int[]     beaker;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if(n == 0) break;
			beaker = new int[n];
			for(int i = 0; i < n; i++) {
				beaker[i] = sc.nextInt();
			}
			Arrays.sort(beaker);
			int max = beaker[n-1];
			use = new boolean[n];
			used = new boolean[n];
			notEmpty = new boolean[n];
			use[0] = true;
			
			boolean ans = dfs(1,max - beaker[0]);
			System.out.println(ans?"YES":"NO");
		}
	}
	static boolean dfs(int index, int water) {
		if(water == 0) {
			used = new boolean[beaker.length];
			notEmpty = new boolean[beaker.length];
			for(int i = 0; i < use.length; i++) {
				if(use[i]) {
					notEmpty[i] = true;
				}
			}
			return greedy();
		}
		if(water < 0) return false;
		if(index >= beaker.length) return false;
		use[index] = true;
		if(dfs(index+1,water - beaker[index])) return true;
		use[index] = false;
		return dfs(index+1,water);
	}
	
	static boolean greedy() {
		for(int i = 0; i < used.length; i++) {
			if(!used[i] && !notEmpty[i]) {
				if(!c(i-1,beaker[i])) return false;
				notEmpty[i] = true;
			}
		}
		return true;
	}
	
	static boolean c(int index, int water) {
		if(water == 0) return true;
		if(water < 0) return false;
		for(int i = index; i >= 0; i--) {
			if(!used[i] && notEmpty[i]) {
				used[i] = true;
				notEmpty[i] = false;
				if(c(index-1,water - beaker[i])) return true;
				used[i] = false;
				notEmpty[i] = true;
			}
		}
		return false;
	}
	
	
}

Measured memory_bytes: 37944
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<pair<int, int> > v(n);
    for(int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        v[i] = make_pair(tmp, i);
    }

    
    vector<pair<int, int> > p(n);
    p = v;
    sort(v.begin(), v.end());
    for(int i = 0; i < n; i++) {
        if(p[i].first != v[n-1].first) {
            cout << v[n-1].first << endl;
        }
        else {
            cout << v[n-2].first << endl;
        }
    }

    return 0;
}

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

int main(){
    ll n,tmp;
    cin>>n;
    vector<ll> num;
    rep(i,n){
        cin>>tmp;
        num.push_back(tmp);
    }

    ll ans=0;
    for(int i=1;i<n-1;i++){
        // cout<<num[i-1]<<","<<num[i]<<","<<num[i+1]<<endl;

        if(num[i-1]<num[i] && num[i]<num[i+1]){
            ans++;
        }else if(num[i-1]>num[i] && num[i]>num[i+1]){
            ans++;
        }
    }

    cout<<ans<<endl;

}


Measured memory_bytes: 3624
package main

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

var sc = bufio.NewScanner(os.Stdin)
const MAX_N = 20 + 10

func nextInt() int {
    sc.Scan()
    i, e := strconv.Atoi(sc.Text())
    if e != nil {
        panic(e)
    }
    return i
}

func main() {
    sc.Split(bufio.ScanWords)

    n := nextInt()
    var a, b, c [MAX_N]int
    for i := 0; i < n; i++ {
        a[i] = nextInt()
        a[i]--
    }
    for i := 0; i < n; i++ {
        b[i] = nextInt()
    }
    for i := 0; i < n-1; i++ {
        c[i] = nextInt()
    }

    sum := 0

    for i := 0; i < n-1; i++ {
        sum += b[a[i]]
        if a[i]+1 == a[i+1]{
            sum += c[a[i]]
        }
    }
    sum += b[a[n-1]]

    fmt.Println(sum)
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main()
{
    int n,ok=0;
    cin>>n;
    while(n>0)
    {
        if(n%10==7)
        {
            ok=1;
            break;
        }
        n/=10;
    }
    if(ok)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <list>
#include <stack>
#include <unordered_set>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1LL << 50;
static const int NIL = -1;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue
 
int gcd(int a, int b) { int c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
int lcm(int a, int b) { int c = gcd(a, b); a /= c; return a*b; }
int nCr(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
int pow(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llpow(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llgcd(long long a, long long b) { long long c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
long long lllcm(long long a, long long b) { long long c = llgcd(a, b); a /= c; return a*b; }
long long llnCr(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
 
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
 
struct edge{
    int from, to; ll cost;
};

int main(){
    int n;
    cin >> n;
    ll a[200010];
    REP(i, n){
        cin >> a[i];
    }
    list<ll> ans;
    REP(i, n){
        ans.pb(a[i]); i++;
        if(i >= n){
            ans.reverse();
            break;
        }
        ans.push_front(a[i]);
    }
    for_each(ans.cbegin(), ans.cend(), [](ll x){
        cout << x << " ";
    });
    cout << endl;
}

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

int main(){
    int n,x=0;
    cin >> n;
    vector<int> a(n-1),b(n);
    rep(i,n-1)cin >> a[i];
    
    rep(i,n)b[i] = 0;
    sort(a.begin(),a.end());
    rep(i,n){
        
            while(a[x]==i+1){
                x++;
                b[i]++;
            }
        
    }
    rep(i,n)cout << b[i] << endl;
	return 0;
}



Measured memory_bytes: 4848
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

template <class T, class F>
T LowerBound(T i0, T i1, F f) {
    while (i0 < i1) {
        T i = i0 + (i1 - i0) / 2;
        if (f(i)) i1 = i; else i0 = i + 1;
    }
    return i0;
}

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

    int n, k;
    cin >> n >> k;

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

    auto d = LowerBound<int>(1, (int)1e+9, [&](auto d) {
        //長さd以下を達成できるか
        int s = 0;
        for (int i = 0; i < n; i++) {
            int t = (a[i] + d - 1) / d - 1;
            s += t;
        }
        return s <= k;
    });

    cout << d << endl;

    return 0;
}

Measured memory_bytes: 3956
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        int count = 0;
        char c;
        String word, temp;
        Scanner sc = new Scanner(System.in);
        word = sc.next();
        temp = sc.next();
        
        while (!temp.equals("END_OF_TEXT")) {
            if (temp.equalsIgnoreCase(word)) 
                count++;
            temp = sc.next();
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 26140
#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;
  cin >> s;
  string t;
  rep(i, 3) t += s[i];
  cout << t << endl;
  return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int k;
char s[104];
int main() {
	scanf("%d",&k);
	scanf("%s",s+1);
	int n=strlen(s+1);
	if (n>k) {
		for (int i=1;i<=k;++i)
			printf("%c",s[i]);
		puts("...");
	} else {
		for (int i=1;i<=n;++i)
			printf("%c",s[i]);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <set>
using namespace std;
int main() {
  int N, X;
  cin >> N >> X;
  multiset<int> m;
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    X -= tmp;
    m.insert(tmp);
  }
  cout << N + (X / *m.begin()) << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())

Nm = int(str(N)[0])
N0 = int(str(N)[-1])
ORD_N = len(str(N))
N_LEFT = int(str(N)[1:-1]) if 2 < ORD_N else -1

# print(N, ORD_N)
# print(Nm, N0, N_LEFT)
# print('!' * 10)
# print()
# 

def get_number_less_than_N(bm, b0):
    """ 先頭bm, 後ろb0 を持ち、N より小さい値の数 """
    count = 0
    
    # b が1桁
    if bm == b0:
        count += 1
        # print('1k', count)
    # b が2桁 (N以下ならば該当)
    if bm*10 + b0 <= N:
        count += 1
        # print('2k', count)
    # order(N) 未満の桁
    # たとえばN=10000 なら、3桁(bm x b0), 4桁(bm xx b0) のパターンは全てOK
    for i in range(3, ORD_N):
        count += 10 ** (i-2)
        # print('M', i, count)
    
    # order(N) のけた
    # bm xx.. b0 <= Nm N1 N2.. N0
    if ORD_N >= 3 and bm <= Nm:
        if bm < Nm:
            count += 10 ** (ORD_N-2)
            # print('L++', count)
        elif b0 <= N0:
            count += N_LEFT + 1
            # print('L+', count)
        else:
            count += N_LEFT
            # print('L', count)
    # print('='*10)

    return count
        

count = 0
for i in range(1, N+1):
    # couniprint("<<", i)
    bm, b0 = int(str(i)[-1]), int(str(i)[0])
    if bm == 0:
        continue
    cold = count
    count += get_number_less_than_N(bm, b0)
print(count)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i, a, b) for(int i=a; i<b; i++)
#define repi(i, a, b) for(int i=a; i>b; i--)
#define db(x) (cerr << #x << ": " << x << '\n')
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define ll long long
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll, ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define fi first
#define se second
#define umap unordered_map
#define umapi umap<int, int>
#define mapi map<int, int>
#define uset unordered_set
#define useti uset<int>
#define seti set<int>
#define pqueue priority_queue
#define si(a) scanf("%d", &a)
#define sll(a) scanf("%lld", &a)
#define bitcount(x) __builtin_popcount(x)
#define cps CLOCKS_PER_SEC
#define PI acos(-1.0)
#define EPS 1e-9
#define mod 1000000007
#define MOD 1000000007
#define N 
using namespace std;

template<typename T>
using maxpq = priority_queue<T, vector<T>, greater<T>>;

template<typename T>
using minpq = priority_queue<T>;
#define int ll

main()
{	

	clock_t clk = clock();
	cerr << "I will return...\n";
	
	int n, m; cin >> n >> m;
	
	int a[n][3];
	
	rep(i, 0, n) {
		rep(j, 0, 3) {
			cin >> a[i][j];
		}
	} 
	
	int mx = 0;
	rep(i, 0, 8) {
		
		vi v;
		
		rep(j, 0, n) {
			int s = 0;
			rep(k, 0, 3) if(i & (1 << k)) s -= a[j][k]; else s += a[j][k];
			v.pb(s);
		}
		
		sort(all(v), greater<ll>());
		
		int ans = 0;
		rep(i, 0, m) ans += v[i];
	
		mx = max(mx, ans);
	}
	
	cout << mx << '\n';
	
	cerr << "...don't you ever hang your head.\n";
	cerr << "Time (in ms): " << double(clock() - clk) * 1000.0 / cps << '\n';
}








Measured memory_bytes: 256
function main(i) {
  i = i.split('\n');
  const a = [];
  f = i.map(n => {
    if (Number(n) % 10 === 0) {
      return [Number(n), 10];
    }
    return [Number(n), Number(n) % 10];
  });
  f.sort((a, b) => a[1] - b[1]);
  var answer = 0;
  f.forEach((item, index) => {
    if (index === 0) {
      answer += item[0];
    } else {
      answer += Math.ceil(item[0] / 10) * 10;
    }
  });
  console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>
using namespace std;
#define All(v) (v).begin(),(v).end()
const long long mod = 1000000007;
const long long inf = mod*mod;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
signed main(){
    int dx[4]={1,0,-1,0};
    int dy[4]={0,1,0,-1};
    int h,w;
    cin>>h>>w;
    string s[50];
    for(int i=0;i<h;i++)cin>>s[i];
    bool flag = true;
    for(int y=0;y<h;y++){
        for(int x=0;x<w;x++){
            if(s[y][x]=='.')continue;
            else{
                bool round = false;
                for(int i=0;i<4;i++){
                    int ny=y+dy[i];
                    int nx=x+dx[i];
                    if(0<=ny&&ny<h&&0<=nx&&nx<w){
                        if(s[ny][nx]=='#')round=true;
                    }
                }
                if(!round)flag=false;
            }
        }
    }
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
const int maxn=100005;
struct Matrix
{
    long long a[2][2];
};
Matrix mull(Matrix x,Matrix y)
{
    Matrix ans;
    for(int i=0;i<2;i++)
    {
        for(int j=0;j<2;j++)
        {
            ans.a[i][j]=0;
            for(int k=0;k<2;k++)
            {
                ans.a[i][j]=(ans.a[i][j]+x.a[i][k]*y.a[k][j])%mod;
            }
        }
    }
    return ans;
}
long long fib(long long m)
{
    if(m<1) return 0;
    if(m<3) return 1;
    Matrix ans;
    m--;
    for(int i=0;i<2;i++)
    {
        for(int j=0;j<2;j++)
            ans.a[i][j]=(i==j);
    }
    Matrix shit;
    shit.a[0][1]=shit.a[0][0]=shit.a[1][0]=1;
    shit.a[1][1]=0;
    while(m)
    {
        if(m&1) ans=mull(ans,shit);
        shit=mull(shit,shit);m=m>>1;
    }
    return (ans.a[1][0]+ans.a[1][1])%mod;
}
long long fast(long long a,long long num)
{
    long long ans=1;
    while(num){
        if(num&1) ans=ans*a%mod;
        a=a*a%mod;
        num=num>>1;
    }
    return ans;
}
int main()
{
    int n;
    long long m;
    scanf("%d%lld",&n,&m);
    int k=n-2;
    long long tmp=1;
    long long sum=fib(2*k+2);
    for(int i=1;i<=k;i++)
    {
        tmp=(m+i-1)%mod*tmp%mod*fast(i,mod-2)%mod;
        sum=sum+tmp*fib(2*k+2-2*i)%mod;
        sum=sum%mod;
    }
    sum=fib(m+2*k+2)-sum;
    sum=(sum%mod+mod)%mod;
    printf("%lld\n",sum);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            String headnext="#";
            String next = "#";
            int h = sc.nextInt(), w = sc.nextInt();
            if (h == 0 && w == 0) break;
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    System.out.print(next);
                    if ("#".equals(next)) next = ".";
                    else next = "#";
                }
                System.out.println();
                if ("#".equals(headnext)) {
                    headnext = ".";
                    next = headnext;
                }
                else {
                    headnext = "#";
                    next = headnext;
                }
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 35140
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
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; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


void solve() {
	ll n, m, k; scanf("%lld %lld %lld", &n, &m, &k); if (n == 0 and m == 0 and k == 0) exit(0);
	vector<vector<double>> dp(n + 1, vector<double>(n * m + 1));
	dp[0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= n * m; j++) {
			if (dp[i][j] < 1e-14) continue;
			for (int k = 1; k <= m; k++) {
				if (j + k <= n * m) {
					dp[i + 1][j + k] += dp[i][j] / (double)m;
				}
			}
		}
	}
	double res = 0;
	for (int i = 1; i <= n * m; i++) {
		res += dp[n][i] * max(1LL, i - k);
	}
	printf("%.12f\n", res);
}

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	int kkt = 89;
	while (kkt) {
		solve();
	}
	return 0;
}


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

int main() {
	// your code goes here
	int n, m, l, max2, min2;
	
	cin >> n >> m >> l;
	
	max2 = max(n, max(l, m));
	min2 = min(n, min(l, m));
	
	if(max2 - min2 == n || max2 - min2 == l || max2 - min2 == m) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<string.h>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;
typedef unsigned long long ull;
typedef  long long ll;
#define INF  0x7f7f7f7f7f7f7f7f
#define M 2000002
#define N 1000100
const ll mod = 1e9+7;
ll n,m,ans;
int main(void){
	cin>>n;
	for(ll i = 1;i < n;i++)
	ans +=i;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::collections::HashMap;
use std::collections::VecDeque;
use std::cmp::max;
use std::cmp::min;


fn main() {
    input! {
        N: usize,
        As: [i64; N],
    }

    // 誤差を減らすために整数で計算したかったが、無理そう
    let mut ans : f64 = 0.0;

    for &a in As.iter() {
        let a_inv : f64 = 1.0 / a as f64;
        ans += a_inv;
    }

    ans = 1.0 / ans;
    println!("{}", ans);
}


Measured memory_bytes: 2140
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0
#define distance(x1,y1,x2,y2) sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

template<typename T>
void maxi(T &a, T b) {
	a = max(a, b);
}

template<typename T>
void mini(T &a, T b) {
	a = min(a, b);
}

int main() {
	makei(N);
	int ans = 0;
	for (int i = 1; i <= N; i += 2) {
		int cnt = 0;
		FOR(j, 1, i + 1) {
			if (i%j == 0)++cnt;
		}
		if (cnt == 8)++ans;
	}
	say(ans);
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    String[] s = new String[N]; 
    String[][] s_ = new String[N][10];

    for (int i = 0; i < N; i++) {
      s[i] = "";
      String str_ = sc.next();
      s_[i] = str_.split("");
      Arrays.sort(s_[i]);
      for (int j = 0; j < 10; j++) {
        s[i] += s_[i][j];
      }
    }

    Arrays.sort(s);

    sc.close(); 

    long count_ = 0;
    long count = 0;
    boolean countStart = false;

    for (int i = 0; i < N-1; i++){
      if (s[i].equals(s[i+1])) {
        if (countStart == false) {
          countStart = true;
          count_ = 1;
        }
        count_++;
      } else {
        if (countStart == true) {
          count += count_ * (count_ - 1) / 2;
          countStart = false;
        }
      }
    }

    if (countStart == true) {
      count += count_ * (count_ - 1) / 2;
    }

    System.out.println(count);
  
  }

}

Measured memory_bytes: 194012
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
ll h[N], a[N], dp[N];
ll tree[3 * N];
int n;


int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> h[i];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++) {
        ll hi = h[i];
        ll ai = a[i];
        int l = 1 + n, r = hi + n;
        ll mx = 0;
        while (l < r) {
            if (l & 1) {
                mx = max(mx, tree[l]);
                l++;
            }
            if (r & 1) {
                r--;
                mx = max(mx, tree[r]);
            }
            l /= 2;
            r /= 2;
        }
        dp[hi] = ai + mx;
        int pos = hi + n;
        tree[pos] = ai + mx;
        while (pos > 1) {
            pos >>= 1;
            tree[pos] = max(tree[2 * pos], tree[2 * pos + 1]);
        }
    }
    ll mx = 0;
    for (int i = 1; i < N; i++)
        mx = max(mx, dp[i]);
    cout << mx;
    return 0;
}


Measured memory_bytes: 9600