akhauriyash/Code-Regression huggingface dataset:
import sys

N = list(input())
op = ["-", "+"]
shiki = ""
ev = []
ans = 0
for bit in range(1 << 3):
    ev.append(N[0])
    for i in range(3):
        if bit & (1 << i):
            ev.append(op[0])
        else:
            ev.append(op[1])
        ev.append(N[i + 1])
    shiki = "".join(ev)
    ans = eval(shiki)
    if ans == 7:
        print(shiki + "=7")
        sys.exit()
    ev.clear()


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

A,B=input().split()

x=int(B[0])
y=int(B[2])
z=int(B[3])

ans=[0]*18
L=len(A)

for i in range(L):
    a=int(A[L-i-1])
    c=a*z
    ans[17-i]=c

for i in range(L):
    a=int(A[L-i-1])
    c=a*y
    ans[16-i]+=c

for i in range(L):
    a=int(A[L-i-1])
    c=a*x
    ans[15-i]+=c

S=0

for i in range(16):
    S+=ans[i]*10**(15-i)

if ans[16]*10+ans[17] > 100:
    S+=(ans[16]*10+ans[17])//100
print(int(S))


Measured memory_bytes: 9272
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Scanner;

public class Main {
	
	
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.nextLine());
		for(int i = 0; i < n; i++){
			LinkedList<Character> list = new LinkedList<Character>();
			ListIterator<Character> iter = list.listIterator();
			char[] array = sc.nextLine().toCharArray();
			
			iter.add(array[0]);
			boolean is_migi = true;
			for(int j = 1; j < array.length;){
				if(is_migi == false){
					iter.next();
					is_migi = true;
				}
				
				if(array[j+1] == '>'){
					if(iter.hasNext()){
						iter.next();
					}else{
						iter.add(array[j+2]);
					}
				}else{
					if(is_migi == true){
						iter.previous();
						is_migi = false;
					}
					
					if(iter.hasPrevious()){
						iter.previous();
					}else{
						iter.add(array[j+2]);
						is_migi = true;
					}
				}
				
				j += 3;
			}
			
			for(char c : list){
				System.out.print(c);
			}
			System.out.println();
			
		}
		
	}
	
}

Measured memory_bytes: 12000
// ※※※ 解答不能 ※※※
// 以下のソースを勉強する.
// yutaka1999氏.
// https://atcoder.jp/contests/jsc2019-qual/submissions/7110919
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    for(int i = 0; i + 1 < n; i++){
        for(int j = i + 1; j < n; j++){
            int x = i ^ j;
            int cnt = 0;
            while(x > 0){
                x /= 2;
                cnt++;
            }
            printf("%d ", cnt);
        }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 512
import java.util.*;

public class Main{
  public static void main(String[] args){
  int[] nums = new int[3];
    Scanner scanner = new Scanner(System.in);
    for(int i = 0; i < 3;i++){
      nums[i] = scanner.nextInt();
    }
    if(nums[0] % nums[1] == 0){
    	System.out.println(nums[2] * nums[0] / nums[1]);
    }else{
      int v = nums[0] / nums[1] + 1;
    System.out.println(nums[2]*v );
    }
  }
}

Measured memory_bytes: 27064
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h=sc.nextInt(),w=sc.nextInt();
        boolean[][] input=new boolean[h][w];
        String tmp;
        for(int i=0;i<h;i++){
            tmp=sc.next();
            for(int j=0;j<w;j++){
                input[i][j]=tmp.charAt(j)=='#';
            }
        }
        boolean t;
        int[] mov1={1,0,-1,0};
        int[] mov2={0,1,0,-1};
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                t=false;
               if(input[i][j]){
                   for(int k=0;k<4;k++){
                       try{
                           t=t||input[i+mov1[k]][j+mov2[k]];
                       }catch(Exception e){}
                   }
                   if(!t){
                       System.out.println("No");
                       return;
                   }
               } 
            }
        }
        System.out.println("Yes");


    }
}

Measured memory_bytes: 21844
//参考：https://qiita.com/DaikiSuyama/items/9dba963ba74396b9b7fd
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define FIR first    //pairの一つ目の要素
#define SEC second   //pairの二つ目の要素

signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll N;
    cin >> N;

    string ans = "";

    ll Q, R;
    while (true)
    {
        Q = (N - 1) / 26;
        R = (N - 1) % 26;

        ans = char(R + 97) + ans;
        N = Q;
        if (N == 0)
            break;
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

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

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

    double ans = v[0];
    for (int i = 1; i < n; ++i) {
        ans = (ans + v[i])/2.0;
    }

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

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

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

/*************** using variables **************/
int a, b, k;
set<int> st;
/**********************************************/

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

    cin >> a >> b >> k;
    for(int i = a; i <= min(a+k-1, b); i++){
        st.insert(i);
    }
    for(int i = max(a, b-k+1); i <= b; i++){
        st.insert(i);
    }
    for(auto x: st) cout << x << endl;
}


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

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

  if(N[1]==N[2] && (N[0]==N[1] || N[2]==N[3])){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(A):
    return A + A**2 + A**3


def main():
    A = read_int()
    print(slv(A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 76916
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include<cstdio>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N;
  vector<int> v;
  vector<int> copyv;
  
  cin >> N;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    v.push_back(a);
  }
  
  copyv = v;
  
  sort( v.begin(), v.end() );
  
  int cnt = 0;

  for ( int i = 0; i < N; i++ ) {
    if (v[i] != copyv[i]) cnt++;
  }
  
  if (cnt <= 2) cout << "YES";
  else cout << "NO";
  
}

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

int main()
{
    int N,M,X; cin >> N >> M >>X;
    vector<int> cost(N);
    vector<vector<int>> book(N,vector<int> (M));
    for (int i=0;i<N;i++)
    {
        cin >> cost[i];
        for (int j=0;j<M;j++)
        {
            cin >> book[i][j];
        }
    }
    int ans=1000000000;
    for (int i=0;i<1<<N;i++)
    {
        int now=0;
        vector<int> choise;
        vector<int> abil(M,0);
        for (int r=0;i>>r>0;r++)
        {
            if ((i>>r)&1) choise.push_back(r);
        }
        for (int j:choise)
        {
            now+=cost[j];
            for (int k=0;k<M;k++)
            {
                abil[k]+=book[j][k];
            }
        }
        bool can=true;
        for (int k=0;k<M;k++)
        {
            if (abil[k]<X) can=false;
        }
        if (can) ans=min(ans,now);
    }
    if (ans==1000000000) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
   
}

Measured memory_bytes: 3636
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from collections import deque
from collections import defaultdict
def main():
    S_ = S()
    mod_list = defaultdict(int)
    ans = 0
    num = 0
    point = 1
    for i in S_[::-1]:
        num += int(i) * point
        mod = int(num) % 2019
        mod_list[mod] += 1
        point *= 10
        point %= 2019
    values_ = mod_list.values()
    ans += mod_list[0]
    for value in values_:
        ans += (value - 1) * value // 2

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 70444
#include <iostream>

using namespace std;

int main()
{
    string s,t;
    cin>>s>>t;
    
    int cnt=0;
    for(int i=0;i<3;i++)
    {
        if(s[i]==t[i])
        cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
function main(input) {
    var a = input[0].split(" ")[0]-0;
    var b = input[0].split(" ")[1]-0;
    var max = 1000*999/2;
    var ans = 0;
    var tmp = 0;
    for(var i=1;i<max;i++){
        tmp += i;
        if(tmp>a && tmp-a == (tmp+i+1)-b){
            ans = tmp-a;
            break;
        }
    }
    console.log(ans);
    
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


Measured memory_bytes: 21064
#include <stdio.h>
#include <queue>

using namespace std;

int main() {
    int a=0, b=0, c=0;
    for(int i = 0; i < 10; ++i) {
        int temp;
        scanf("%d",&temp);
        if(temp>a) {
            c = b;
            b = a;
            a = temp;
        } else if(temp > b) {
            c = b;
            b = temp;
        } else if(temp > c) {
            c = temp;
        } else {
        }
    }
    printf("%d\n",a);
    printf("%d\n",b);
    printf("%d\n",c);
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

int main(){
  ll n;
  string str;
  cin >> n >> str;
  if(n>=str.size()){
    cout << str << endl;
  }
  else{
    for(ll i=0;i<n;i++){
      cout << str[i];
    }
    cout << "...";
  }
}

Measured memory_bytes: 3128
toInt :: String -> Int
toInt = read :: String -> Int

main = do
  a <- toInt <$> getLine
  b <- toInt <$> getLine
  c <- toInt <$> getLine
  x <- toInt <$> getLine
  print $ length [(s, t, u) | s <- [0..a], t <- [0..b], u <- [0..c], 500*s+100*t+50*u == x]


Measured memory_bytes: 3888
#include<stdio.h>

int main(){
  int n,flag[4]={},i;
  char s[100];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%c",&s[i]);
    if(s[i]=='Y'){
      flag[0]=1;
       break;
    } 
  }
  if(flag[0]) printf("Four\n");
  else printf("Three\n");
}

Measured memory_bytes: 128
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n::Int=parseInt(readline())
    ans::Vector{Int}=[0 for i in 1:n]
    for x in 1:100
        for y in 1:100
            for z in 1:100
                tmp::Int=x^2+y^2+z^2+x*y+y*z+z*x
                if tmp<=n
                    ans[tmp]+=1
                end
            end
        end
    end
    for i in ans
        println(i)
    end
end
main()

Measured memory_bytes: 168464
#include<iostream>
#include<iomanip>
#include<memory>
#include<array>
#include<vector>
#include<queue>
#include<list>
#include<stack>
#include<algorithm>
#include<cmath>

using namespace std;

int chipher( string& s )
{
  for ( auto& c : s )
    {
      if ( c >= 'a' && c <= 'y' )
        ++c;
      else if ( c == 'z' )
        c = 'a';
    }
  return 0;
}

int main()
{
  
  string x;

  while( getline(cin, x) )
    {
      for ( int i = 0; i < 26; ++i )
        {
          if ( x.find( "the" ) != string::npos )
            cout << x << endl;
          else if ( x.find( "this" ) != string::npos )
            cout << x << endl;
          else if ( x.find( "that" ) != string::npos )
            cout << x << endl;
          chipher( x );
        }
    }
  
  return 0;
}

Measured memory_bytes: 1180
# include<iostream>
# include<algorithm>
# include<cctype>
# include<cstdio>
# include<cstring>
# include<cmath>
using namespace std;
int main()
{
      int n, a[100005];
      cin >> n;
      for (int i=0; i<n; i++)
      {
            cin >> a[i];
      }
      sort(a, a+n);
      cout << a[n/2] - a[n/2-1] << endl;
      return 0;
}


Measured memory_bytes: 640
import java.io.*;

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String s;
		int i,n;
		long c=1;
		try {
				s=r.readLine();
				n = Integer.parseInt(s);
				for(i=1;i<=n;i++)c*=i;
				System.out.println(c);
		} catch (Exception err) {
			System.exit(0);
		}
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n;
    cin>>n;
    cout<<(n+1)/2<<endl;
    return 0;
}

Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import Control.Monad
import Control.Monad.ST
import Data.Array.ST
import Data.Array.Unboxed
import Data.Bits

main = putStrLn . show . solve =<< parse

parse :: IO (Int, Int, Int, Int)
parse = (\[h, w, a, b] -> (h, w, a, b)) . map read . words <$> getLine

solve :: (Int, Int, Int, Int) -> Int
solve (h, w, a, b) = foldl add 0 $ map intrude [b .. w - 1] where
    fact = newFact $ h + w
    inv = newInv fact $ max h w
    ways x y = (fact ! (x + y)) `mul` (inv ! x) `mul` (inv ! y)
    intrude i = (ways (h - a - 1) i) `mul` (ways (a - 1) (w - i - 1))

newFact :: Int -> UArray Int Int
newFact n = runSTUArray $ do
    fact <- newArray_ (0, n) :: ST s (STUArray s Int Int)
    writeArray fact 0 1
    forM_ [1 .. n] $ \i -> do
        n <- readArray fact $ i - 1
        writeArray fact i $ mul n i
    return fact

newInv :: UArray Int Int -> Int -> UArray Int Int
newInv fact n = runSTUArray $ do
    inv <- newArray_ (0, n) :: ST s (STUArray s Int Int)
    writeArray inv 0 1 -- XXX
    writeArray inv 1 1 -- XXX
    writeArray inv n $ pow (fact ! n) (modulo - 2)
    forM_ [n - 1, n - 2 .. 2] $ \i -> do
        x <- readArray inv $ i + 1
        writeArray inv i $ mul x (i + 1)
    return inv

add :: Int -> Int -> Int
add n m = (n + m) `mod` modulo

mul :: Int -> Int -> Int
mul n m = mul' (n `mod` modulo) m 0
mul' n m res
    | m <= 0 = res
    | m .&. 1 == 1 = mul' (shiftL n 1 `mod` modulo) (shiftR m 1) (add res n)
    | otherwise = mul' (shiftL n 1 `mod` modulo) (shiftR m 1) res

pow :: Int -> Int -> Int
pow _ 0 = 1
pow n m
    | m .&. 1 == 0 = mul x x
    | otherwise = mul n . pow n $ m - 1 where
          x = pow n $ m `div` 2

modulo :: Int
modulo = 10 ^ 9 + 7


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

int main() {
  //freopen("input.txt","r",stdin);
  int n; cin >> n;
  long long k; cin >> k;
  int arr[n+5]; for(int i=0;i<n;++i){ cin >> arr[i]; --arr[i];}
  int visited[n+5]; for(int i=0;i<n;++i) visited[i] = -1;
  int cur = 0;
  for(int i=0;i<=n;++i){
    if(visited[cur] != -1){
    	k -= visited[cur];
      	long long cycle = i - visited[cur];
      	k %= cycle;
      	for(long long j=0;j<k;++j) cur = arr[cur];
      	cout << cur + 1;
      	return 0;
    }
  	visited[cur] = i;
    cur = arr[cur];
    if(k == (long long)(i+1)){
    	cout << cur + 1;
        return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 5200
from collections import deque 
import sys
input = sys.stdin.readline  #文字列入力では注意！

N,u,v = map(int,input().split())
u -= 1; v -= 1
tree = [[] for _ in range(N)]
for i in range(N-1):
    A,B = map(int,input().split())
    tree[A-1].append(B-1)
    tree[B-1].append(A-1)

def bfs(start):
    q = deque()
    q.append([start,0])
    visited = set()
    lis = [0]*N
    while q:
        now,dis = q.popleft()
        if now in visited:
            continue
        lis[now] = dis
        visited.add(now)
        for node in tree[now]:
            q.append([node,dis+1])    
    return lis
ut = bfs(u)
vt = bfs(v)

ans = 0
for i in range(N):
    if ut[i] <vt[i]:
        ans = max(ans,vt[i])
print(ans-1)


Measured memory_bytes: 36224
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Pranay2516
 *///
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            out.print(2*(3.1415)*in.nextInt());
        }
    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public String next() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            StringBuilder res = new StringBuilder();

            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }
        public int[] readIntArray(int size) {
            int[] array = new int[size];
            for (int i = 0; i < size; i++) {
                array[i] = nextInt();
            }
            return array;
        }

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



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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct edge {
  ll to, cost;
};

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

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
const int limit = 100010;
vector<long long> a; 
vector<long long> b;
vector<long long> c;
vector<long long> d;
ll inf =(1<<29);
vector< vector< pair<int,long long> > > t;
int n,q,k;
int dfs(int start,long long cost)
{
  d[start]=cost;
  for(int i=0;i<t[start].size();i++)
    {
      if(d[t[start][i].first]==-1) dfs(t[start][i].first,cost+t[start][i].second);
    }
  return 0;
}
int main()
{
  cin >> n;
  a.resize(n);
  b.resize(n);
  c.resize(n);
  d.resize(n,-1);
  t.resize(n);
  for(int i=0;i<n-1;i++)
    {
      cin >> a[i] >> b[i] >> c[i];
      a[i]--;b[i]--;
      t[a[i]].push_back({b[i],c[i]});
      t[b[i]].push_back({a[i],c[i]});
    }
  cin >> q >> k;
  dfs(k-1,0);
  int x,y;
  for(int i=0;i<q;i++)
    {
      cin >> x >> y;
      x--;y--;
      cout << d[x] + d[y] << endl;
    }
  return 0;
}


Measured memory_bytes: 16000
class station:
    def __init__(self, speed, first, interval):
        self.speed = speed
        self.first = first
        self.interval = interval


def onboard_duration(station, start_time, first=False):
    # return the arrival_time at the next_station
    if first or start_time < station.first: # starting station or the first train is not departed from the station
        return station.first + station.speed
    elif start_time % station.interval == 0:
        return start_time + station.speed
    else:
        return start_time + station.interval - (start_time % station.interval) + station.speed


stations = []
for _ in range(int(input())-1):
    stations.append(station(*list(map(int, input().split()))))

for i in range(len(stations)):
    elapsed_time = 0
    for j in range(i, len(stations)):
        if elapsed_time == 0:
            elapsed_time = onboard_duration(stations[j], elapsed_time, first=True)
        else:
            elapsed_time = onboard_duration(stations[j], elapsed_time)
    print(elapsed_time)

print('0')

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	array<int,100>ar;
	int i,j;
	int tmp;
	cin>>n;
	for(i=0;i<n;i++)	cin>>ar[i];
	for(i=0;i<n;i++){
		if(i==0)	cout<<ar[i];
		else		cout<<" "<<ar[i];
	}
	cout<<endl;
	for(i=1;i<n;i++){
		tmp=ar[i];
		j=i-1;
		while(j>=0&&ar[j]>tmp){
			ar[j+1]=ar[j];
			j--;
		}
		ar[j+1]=tmp;
		for(int k=0;k<n;k++){
			if(k==0)	cout<<ar[k];
			else		cout<<" "<<ar[k];
		}
		cout<<endl;
	}
	
	return 0;
}
	


Measured memory_bytes: 3100
n=int(input())
z=[[[0 for y in range(10)]for i in range(3)]for j in range(4)]
for x in range(n):
	a,b,c,d=map(int,input().split())
	z[a-1][b-1][c-1]+=d
	
for j in range(4):
	for i in range(3):
		for h in range(10):
			print(" "+str(z[j][i][h]),end="")
		print()
	if j!=3:
		print("#"*20)


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

using namespace std;

int n, k, ta, tb, tc, td;
int y[4005][4005], z[2005][2005], ans;
char x[5];

int main() {
	scanf("%d%d", &n, &k);
	while (n--) {
		scanf("%d%d%s", &ta, &tb, x);
		if (x[0] == 'B')
			ta += k;
		ta++, tb++;
		ta %= k * 2;
		if (ta >= k)
			ta -= k, tb += k;
		tb %= k * 2;
		//printf("%d %d\n", ta, tb);
		y[ta][tb]++;
		y[ta + k][tb]--;
		y[ta][tb + k]--;
		y[ta + k][tb + k]++;
	}
	//for (int i = 0; i < k * 2; i++)
	//	for (int j = 0; j < k * 4; j++)
		//	printf("%d%c", y[i][j], j == k * 4 - 1 ? '\n' : ' ');
	for (int i = 0; i < k * 2; i++)
		for (int j = 0; j < k * 4; j++) {
			if (i)
				y[i][j] += y[i - 1][j];
			if (j)
				y[i][j] += y[i][j - 1];
			if (i && j)
				y[i][j] -= y[i - 1][j - 1];
			ta = i, tb = j;
			if (ta >= k)
				ta -= k, tb += k;
			tb %= k * 2;
			z[ta][tb] += y[i][j];
			//printf("%d%c", y[i][j], j == k * 4 - 1 ? '\n' : ' ');
		}
	for (int i = 0; i < k; i++)
		for (int j = 0; j < k * 2; j++)
			ans = max(ans, z[i][j]);
	printf("%d\n", ans);
	return 0;
}

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

int main() {
  set<int> s;
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int d;
    cin >> d;
    s.insert(d);
  }
  cout << s.size() << endl;
}

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

using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	std::string str;
	K--;
	cin >> str;
	if (str[K] == 'A')str[K] = 'a';
	if (str[K] == 'B')str[K] = 'b';
	if (str[K] == 'C')str[K] = 'c';

	cout << str << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>
#include <set>
#include <map>
#include <type_traits>
#include <cstdint>

typedef long long ll;

using namespace std;

//素因数分解
void factoring(ll n, map<ll, ll>& mp) {
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			mp[i]++;
			n /= i;
		}
	}
	if (n != 1) mp[n]++;
}

//絶対値
template<class T, class U = std::make_unsigned_t<T>>
U SafeAbs( T x ) {
    return x < 0 ? -static_cast<uintmax_t>(x) : x;
}

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

//xのn乗
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
//xの逆元
ll mod_inv(ll x, ll mod) {//O(log(mod))
    return mod_pow(x, mod - 2, mod);
}

//nCr
ll ncr(ll n, ll r, ll mod){
	ll res=1;
	ll num=1,den=1;
	for(ll i=n;i>=n-r+1;i--){
		(den*=i)%=mod;
	}
	for(ll i=1;i<=r;i++){
		(num*=i)%=mod;
	}
	
	res=den*mod_inv(num,mod);

	return res%mod;
}


//二分探索
bool isOk(ll index, ll key,vector<ll> &a, bool g){
	if(g){
		if(a[index]<key){
			return true;
		}
	}
	else{
		if(a[index]>key){
			return true;
		}
	}
	return false;
}

ll bin_search(ll key, vector<ll> &a, bool g){
	
	ll l=-1;
	ll r=a.size();

	if(g){
		l=a.size();
		r=-1;
	}

	while(abs(r-l)>1){
		ll mid = (l+r)/2;
		if(isOk(mid, key, a, g)){
			r=mid;
		}
		else{
			l=mid;
		}
	}
	return r;
}

int main(){

	ll a,b,c;
	cin>>a>>b>>c;

	ll ans=b/a;

	if(b/a>c){
		ans=c;
	}

	cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
//aising2020_c.cpp
//Sat Jul 11 20:50:51 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i,n) for (int i=0;i<(n);++i)

using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	int a[70000];
	fill(a,a+70000,0);

	for (int i=1;i<100;i++){
		for (int j=1;j<100;j++){
			for (int k=1;k<100;k++){
				int tmp = i*i+j*j+k*k+i*j+j*k+k*i;
				a[tmp]++;
			}
		}
	}

	for (int i=1;i<=n;i++){
		cout << a[i] << endl;
	}
}

Measured memory_bytes: 3860
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;

int main(){
	int w[10],k[10];
	int temp;
	
	for(int i=0;i<10;i++) scanf("%d",&w[i]);
	for(int i=0;i<10;i++) scanf("%d",&k[i]);
	for(int i=0;i<10;i++){
		for(int j=i+1;j<10;j++){
			if(w[i]<w[j]){
				temp = w[i];
				w[i] = w[j];
				w[j] = temp;
			}
			if(k[i]<k[j]){
				temp = k[i];
				k[i] = k[j];
				k[j] = temp;
			}
		}
	}
	printf("%d %d\n",w[0]+w[1]+w[2],k[0]+k[1]+k[2]);
}

Measured memory_bytes: 3208
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
const ll INF = 100000000000000000;

int main(){
    int n;
    cin>>n;
    map<string,int> mp;
    ll ans = 0;
    rep(i,0,n-1){
        string s;
        cin>>s;
        sort(s.begin(),s.end());
        ans += mp[s];
        mp[s]++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 11136
#include <stdio.h>

int main(void) {
  int N, L, max = 0, sum = 0;
  
  scanf("%d", &N);
  
  for (int i = 0; i < N; i++) {
    scanf("%d", &L);
    max = max > L ? max : L;
    sum += L;
  }
  
  printf(sum - max > max ? "Yes" : "No");
  
  return 0;
}

Measured memory_bytes: 128
H,W,D=map(int,input().split())
import collections
import bisect
table=collections.defaultdict(list)
table2=collections.defaultdict(list)
dp=collections.defaultdict(list)
field=[list(map(int,input().split())) for i in range(H)]
for i in range(H):
  for j in range(W):
    table[field[i][j]%D].append((field[i][j],i,j))
    table2[field[i][j]%D].append(field[i][j])
for x in table:
  table[x].sort(key=lambda x:x[0])
  dp[x]=[0]*len(table[x])
  for i in range(1,len(table[x])):
    dp[x][i]=dp[x][i-1]+abs(table[x][i][1]-table[x][i-1][1])+abs(table[x][i][2]-table[x][i-1][2])
  table2[x].sort()
Q=int(input())
LR=[list(map(int,input().split())) for i in range(Q)]
for i in range(Q):
  ans=0
  x,y = LR[i]
  
  id = bisect.bisect_left(table2[x%D],x)
  id2=bisect.bisect_left(table2[x%D],y)
  print(dp[x%D][id2]-dp[x%D][id])

Measured memory_bytes: 85980
#include <iostream>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

int main(void) {
    int X, N;
    cin >> X >> N;
    map<int,int> mp;
    while(N--) {
        int p;
        cin >> p;
        mp[p]++;
    }

    int ans = 0;
    for(int i=0; i<=101; i++) {
        if(mp[i]) continue;
        if(abs(i - X) < abs(ans - X)) ans = i;
    }

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


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

int main()
{
    int a,b;

    cin >> a >> b;

    if( a > b )
        cout << "a > b" << endl;
    else if( a < b )
        cout << "a < b" << endl;
    else
        cout << "a == b" << endl;


    return 0; 
}



Measured memory_bytes: 3084
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;

struct Edge{int to,from,cost;};

#define debug cout

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) debug << *i << " "; debug << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repn(i,m,n) for(int i=(m);i<=(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;--i)
#define repnd(i,m,n) for(int i=(n);i>=(m);--i)
#define rep0(i,n) for(i=0;i<(n);++i)
#define repn0(i,m,n) for(i=(m);i<=(n);++i)
#define repd0(i,n) for(i=(n)-1;i>=0;--i)
#define repnd0(i,m,n) for(i=(n);i>=(m);--i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define SS stringstream
#define X second
#define Y first
#define PUTLINE debug<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

vint prime;
int p[100000];

int main() {
	for(int i=2;i*i<100000;++i){
		if(p[i]>0)continue;
		for(int j=2*i;j<100000;j+=i){
			p[j]=1;
		}
	}
	repn(i,2,99999)if(p[i]==0)prime.PB(i);
	Int m,a,b;
	IL{
		cin>>m>>a>>b;
		if(m==0&&a==0&&b==0)break;
		int p=0,q=0;
		rep(i,sz(prime))rep(j,i+1){
			Int pp=prime[j],qq=prime[i];
			if(pp*qq>m)break;
			if(a*qq<=pp*b){
				if(p*q<pp*qq){
					p=pp;
					q=qq;
				}
			}
		}
		cout<<p<<" "<<q<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C;
  cin>>A>>B>>C;
  int count=0;
  int X;
  cin>>X;
  for(int i=0;i<=A;i++){
    for(int j=0;j<=B;j++){
      for(int k=0;k<=C;k++){
        if(500*i+100*j+50*k==X){
          count++;
        }
      }
    }
  }
  cout<<count;
}


Measured memory_bytes: 3548
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15);  //"for float-base
  // problem"
  ll A;
  long double B;
  cin >> A >> B;

  B = B * 1000;
  int b = (int)B;
  b = b / 10;
  ll C = A * b;
  C = C / 100;

  cout << C << endl;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define st string
#define dl double
#define ve(i) vector<i>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define each(i, n) for(auto&& i: n)
#define co(n) cout << fixed << setprecision(n)

int main() {
  st S, a = "Yes";
  cin >> S;
  rep(i, S.size()) {
    if(i % 2 == 1 && S.at(i) == 'R') {
      a = "No";
    }
    if(i % 2 == 0 && S.at(i) == 'L') {
      a = "No";
    }
  }
  cout << a << endl;
}  

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine().Split(' ');
            var a = int.Parse(str[0]);
            var b = int.Parse(str[1]);
            var c = int.Parse(str[2]);
            var d = int.Parse(str[3]);

            var aaa = a * b;
            var bbb = c * d;

            if (aaa > bbb)
            {
                Console.WriteLine(aaa);
            }
            else
            {
                Console.WriteLine(bbb);
            }
        }
    }
}


Measured memory_bytes: 13140
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
typedef long long LL;
const int N=3005;
vector<int> vec[N];
int a[N];
int n;
bool dfs (int x,int fa)
{
	int siz=vec[x].size();
	for (int u=0;u<siz;u++)
	{
		int y=vec[x][u];
		if (y==fa) continue;
		if (a[x]>a[y]&&dfs(y,x)==false) return true;
	}
	return false;
}
int main()
{
	scanf("%d",&n);
	for (int u=1;u<=n;u++) scanf("%d",&a[u]);
	for (int u=1;u<n;u++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		vec[x].push_back(y);
		vec[y].push_back(x);
	}
	for (int u=1;u<=n;u++)
	{
		if (dfs(u,0)) printf("%d ",u);
	}
	return 0;
}

Measured memory_bytes: 384
# Making Triangle

def main(l):
    if len(l) < 3:
        return 0

    l.sort()
    p = 0
    for i in range(0, N - 2):
        for j in range(i + 1, N - 1):
            if l[j] == l[i]:
                continue
            for k in range(j + 1, N):
                if l[k] == l[j]:
                    continue
                if l[i] + l[j] <= l[k]:
                    break
                p += 1
    return p


N = int(input())
L = list(map(int, input().split()))
r = main(L)
print(r)


Measured memory_bytes: 9208
#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;
  cin >> N;

  ll L[86 + 10];
  L[0] = 2, L[1] = 1;
  for (int i = 2; i <= N; i++) {
    L[i] = L[i - 1] + L[i - 2];
  }

  cout << L[N] << endl;

  return 0;
}


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

#ifdef LOCAL
#include "bib/debug.h"
#else
#define debug
#define cerr if (false) cerr 
#endif

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int k;
  cin >> k;
  
  vector<vector<long long>> A = {{1, 2, 3, 4, 5, 6, 7, 8, 9}};
  int v = 9;
  while (v < k) {
    vector<long long> nv;
    for (auto &c : A.back()) {
      int d = c % 10;
      nv.emplace_back(c * 10 + d);
      if (d > 0) {
        nv.emplace_back(c * 10 + d - 1);
      }
      if (d < 9) {
        nv.emplace_back(c * 10 + d + 1);
      }      
    }
    sort(nv.begin(), nv.end());
    nv.resize(unique(nv.begin(), nv.end()) - nv.begin());
    A.emplace_back(nv);
    v += (int) nv.size();
  }
  k--;
  long long ans = -1;
  for (auto &G : A) {
    if (k < (int) G.size()) {
      ans = G[k];
      break;
    }
    k -= (int) G.size();
  }
  assert(ans != -1);
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 2980
#include<stdio.h>
#include<string.h>

void exchange(char *str){
	while (*str != '\0'){
		if (65 <= *str && *str <= 90){
			*str = *str + 32;
		}
		str++;
	}
}

int count(char str[1201], char s){
	exchange(str);
	int i=0,answer=0;
	while (i < strlen(str)){
		if (str[i] == s){
			answer++;
		}
		i++;
	}

	return answer;
}

int main(void){
	char str[1201];
	int i = 0;
	while (scanf("%c", &str[i]) != EOF){
		i++;
	}
	str[i + 1] = '\0';

	for (i = 0; i < 26;i++){
			char s = 'a' + i;
			printf("%c : %d\n", s, count(str, s));
		}


	return 0;
}


Measured memory_bytes: 2076
#coding:utf-8

import heapq

N, M = map(int, input().split())
invA = []
for a in map(int, input().split()):
    heapq.heappush(invA, -1*a)
for m in range(M):
    heapq.heappush(invA, heapq.heappop(invA)/2)
total = -1*sum(map(int, invA))

print(total)


Measured memory_bytes: 14180
n = gets.chomp.to_i
p = gets.chomp.split.map(&:to_i)

sorted_p = p.sort

count = 0
n.times do |i|
  count += 1 if p[i] != sorted_p[i]
end

if count == 0 || count == 2
  puts("YES")
else
  puts("NO")
end

Measured memory_bytes: 3836
using System;

class MainClass
{
	public static void Main (string[] args)
	{
		string str = Console.ReadLine ();
		string[]spStr = str.Split(' ');

		int a = int.Parse (spStr[0]);
		int b = int.Parse (spStr[1]);
		int c = int.Parse (spStr[2]);

		int[] array = new int[]{ a, b, c };

		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < 2; j++) {
				if (array [j] > array [j + 1]) 
				{
					int t = array[j];
					array [j] = array [j+1];
					array [j + 1] = t;
				}
			
			}

		}
		Console.WriteLine (array [0] + " " + array [1] + " " + array [2] );
	}
}

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

const ll MOD = 1000000007;
const int MAX_N = 100100;
ll X[MAX_N];
ll N;
ll fct[MAX_N]; // fct[i] := i! mod 1e9+7 (fct[0] = 1)
ll inv_fct[MAX_N]; // inv_fct[i] = i*(i+1)*...*(N-1) mod 1e9+7 (inv_fct[N] = 1)
ll Y[MAX_N]; // Y[i] := (N-1)!/i mod 1e9+7 を求める 
// Y[1] = fct[N-1] 
// Y[N-1] = fct[N-2]
// Y[i] = fct[i-1]*inv_fct[i+1] mod 1e9+7
ll Z[MAX_N]; // Z[i] := Y[1] ~ Y[i]までの累積和

void init(){
    fct[0] = 1LL;
    for(int i = 1; i <= N; ++i) fct[i] = fct[i-1]*(ll)i%MOD;
    inv_fct[N] = 1LL;
    for(int i = N-1; i >= 1; --i) inv_fct[i] = inv_fct[i+1]*(ll)i%MOD;
    for(int i = 1; i <= N-1; ++i) Y[i] = fct[i-1]*inv_fct[i+1]%MOD;

    Z[0] = 0LL;
    for(int i = 1; i <= N-1; ++i) Z[i] = (Z[i-1]+Y[i])%MOD;
}

int main()
{
    scanf("%lld", &N);
    for(int i = 1; i <= N; ++i) scanf("%lld", &X[i]);

    init();
    ll res = 0LL;
    for(int i = 1; i <= N-1; ++i) 
        res = (res + (X[i+1]-X[i])*Z[i]%MOD)%MOD;
    printf("%lld\n", res);
    return 0;
}

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

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  int n;
  ll c;
  cin >> n >> c;

  vector<pair<ll, ll>> v_xv(n);
  vector<ll> f1(n + 1, 0), f2(n + 1, 0);
  ll v_sum = 0;
  for (int i = 0; i < n; i++) {
    auto &p = v_xv[i];
    cin >> p.first >> p.second;
    v_sum += p.second;
    f1[i + 1] = max(f1[i], v_sum - p.first);
    f2[i + 1] = max(f2[i], v_sum - p.first * 2);
  }

  ll ans = f1.back();
  v_sum = 0;
  for (int i = 0; i < n; ++i) {
    auto &p = *(v_xv.rbegin() + i);
    v_sum += p.second;
    ll l_dist = c - p.first;
    ll l_ans = v_sum - l_dist;
    if (i != n - 1) {
      ll r_max1 = *(f1.rbegin() + i + 1), r_max2 = *(f2.rbegin() + i + 1);
      l_ans += max(r_max1 - l_dist, r_max2);
    }

    ans = max(ans, l_ans);
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 3328
use std::io::*;
use std::str::FromStr;
use std::collections::VecDeque;
use std::collections::HashMap;

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() {
    type Graph = Vec<Vec<usize>>;
    let n: usize = read();
    let x: usize = read();
    let y: usize = read();
    let mut G: Graph = vec![Vec::new(); n];
    for i in 0..n-1 {
        G[i].push(i+1);
        G[i+1].push(i);
    }
    G[x-1].push(y-1);
    G[y-1].push(x-1);

    //各頂点からその他への頂点への最短距離を格納するvec 全要素は-1で初期化
    let mut dist:Vec<Vec<i32>> = vec![vec![-1; n];n];
    //探索状態管理queue
    let mut queue: VecDeque<usize> = VecDeque::new();

    //各頂点からその他への頂点への最短距離をBFSで求める
    for i in 0..n {
        dist[i][i] = 0;
        queue.push_back(i);

        while !queue.is_empty() {
            let v = queue.pop_front().unwrap();
            for nv in G[v].iter() {
                if dist[i][*nv] == -1 {
                    dist[i][*nv] = dist[i][v] + 1;
                    queue.push_back(*nv);
                }
            }
        }
    }

    //各距離ごとの組の数を管理するHashMap
    let mut scores = HashMap::new();

    //nC2の組み合わせを列挙
    for i in 0..n {
        for j in i+1..n{
            //println!("dist{}",dist[i][j] );
            //各距離ごとの個数をカウント
            let count = scores.entry(dist[i][j]).or_insert(0);
            *count += 1;
        }
    }
    //println!("{:?}",G);
    //println!("{:?}",dist);
    //頂点1からn-1までの個数を表示。データがない場合は0を表示。
    for i in 1..n {
        println!("{}", scores.get(&(i as i32)).unwrap_or(&0));
    }
}


Measured memory_bytes: 20732
#include<stdio.h>//ラウンドロビンスケジューリング
#include<string.h>

typedef struct process{
	char name[10];
	int time;
}PROC;

PROC list[100000];

int main(void){
	int i,j,n,quan,total=0,max=0,temp,count=0;
	char tem[10];
	
	scanf("%d %d",&n,&quan);

	for(i = 0;i < n;i++){
		scanf("%s %d",list[i].name,&list[i].time);
	}
	for(i = 0;i < n;i++){
		if(list[i].time >= max){
			max = list[i].time;
		}
	}

	for(i = 0;;i++){
		if(i == n){
			i = 0;
			for(j = 0;j < n;j++){
				if(list[j].time > 0){
					list[count] = list[j];
					count++;
				}
			}
			n = count;
			count = 0;
		}
		if(n == 0){
			break;
		}
		if(list[i].time <= quan){
			total += list[i].time;
			list[i].time = 0;
			printf("%s %d\n",list[i].name,total);
			/*for(j = i;j < n - 1;j++){
				temp = list[j].time;
				strcmp(tem,list[j].name);
				list[j] = list[j + 1];
				list[n + 1].time = temp;
				strcmp(list[n + 1].name,tem);
			}
			n--;
			i--;*/
		}else if(list[i].time > quan){
			list[i].time -= quan;
			total += quan;
		}
	}
	

	return 0;
}

Measured memory_bytes: 1380
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const ll INF=1LL<<55;
int n;
ll a[410],s[410];
ll dp[410][410];
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	for (int i=1;i<=n;i++) read(a[i]),s[i]=s[i-1]+a[i];
	for (int len=2;len<=n;len++) {
		for (int l=1,r;l+len-1<=n;l++) {
			r=l+len-1;
			dp[l][r]=INF;
			for (int k=l;k<r;k++)
				dp[l][r]=min(dp[l][r],dp[l][k]+dp[k+1][r]+s[r]-s[l-1]);
		}
	}
	printf("%lld\n",dp[1][n]);
	return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using ull = unsigned long long;
using ll = long long;
using namespace std;

int main(void) {
    int a,b;
    cin >> a >> b;


    int cnt = 0;
    for (int i = 1; i <= a; ++i) {

        if (i == a) {
            for(int j = 1; j <= b; ++j) {
                if (i == j) {
                    cnt++;
                    break;
                }
            }
        } else {
            for(int j = 1; j <= 31; ++j) {
                if (i == j) {
                    cnt++;
                    break;
                }
            }
        }
    }

    // if ( a <= b) {
    //     cout << a << endl;
    // } else {
    //     cout << a-1 << endl;
    // }
        
    // return 0;

    cout << cnt << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

ll n, L;
ll a[100000];

int main() {
	cin >> n >> L;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	if(a[0] + a[1] >= L){
		cout << "Possible" << endl;
		for(int i = n - 1; i >= 1; i--)cout << i << endl;
		return 0;
	}
	if(a[n - 1] + a[n - 2] >= L){
		cout << "Possible" << endl;
		for(int i = 1; i < n; i++)cout << i << endl;
		return 0;
	}
	
	for(int i = 0; i < n - 1; i++){
		if(a[i] >= L){
			cout << "Possible" << endl;
			for(int j = 1; j <= i; j++)cout << j << endl;
			for(int j = n - 1; j > i; j--)cout << j << endl;
			return 0;
		}
		if(a[i] + a[i + 1] >= L){
			cout << "Possible" << endl;
			for(int j = 1; j <= i; j++)cout << j << endl;
			for(int j = n - 1; j > i + 1; j--)cout << j << endl;
			cout << i + 1 << endl;
			return 0;
		}
	}
	
	cout << "Impossible" << endl;
	return 0;
}


Measured memory_bytes: 1536
n,a,b=map(int,input().split())
x=list(map(int,input().split()))
y=[]
for i in range(n-1):
    y.append(a*(x[i+1]-x[i]))
ans=0
for i in y:
    if i<=b:
        ans+=i
    else:
        ans+=b

print(ans)

Measured memory_bytes: 63696