akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

final class Main {

    private Main() {
    }

    public static void main(final String[] argv) throws IOException {
        final BufferedReader inputReader =
                new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            final String input = inputReader.readLine();
            if (input == null) {
                break;
            }
            double cv = Double.parseDouble(input);
            double t = cv / 9.8;
            int N = 1;
            while (4.9 * Math.pow(t, 2) > 5 * N - 5) {
                N++;
            }
            System.out.println(N);
        }
    }
}

Measured memory_bytes: 9760
#include<stdio.h>


int main(void){
	
	int n,i,maxv,minv;
	
	int j;
	
	scanf("%d",&n);
	
	int a[n];
	
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	
	minv=a[0];
	maxv=a[1]-a[0];
	
	for(j=1;j<=n-1;j++)
	{
		if(maxv<a[j]-minv){maxv=a[j]-minv;}
		if(minv>a[j]){minv=a[j];}
	}
	
	printf("%d\n",maxv);
    return 0;	
}


Measured memory_bytes: 2496
#include <bits/stdc++.h>
using namespace std;
string S,T;
char tmp;
int main(){
  cin >> S >> T;
  for(int j=0;j<S.size();j++){
    tmp=S[S.size()-1];
    for(int i=S.size()-2;i>=0;i--){
      S[i+1]=S[i];
    }
    S[0]=tmp;
    if(S==T){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 51


int main(){
  int n,m;
  bool way[10][10] = {};
  int a,b;
  int dp[1<<8][10] = {};
  
  
  scanf("%d%d",&n,&m);

  for(int i=0;i<m;i++){
    scanf("%d%d",&a,&b);
    a--; b--;

    way[a][b] = way[b][a] = true;
  }

  dp[1][0] = 1;

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

    for(int j=0;j<n;j++){
      if(!(i & (1 << j))) continue;
      
      for(int k=0;k<n;k++){
        if(i & (1 << k)) continue;
        if(!way[j][k]) continue;
        
        dp[i | (1<<k)][k] += dp[i][j];
      } 
    }
  }

  ll ans_sum = 0;

  for(int i=0;i<n;i++){
    ans_sum += dp[(1<<n)-1][i];
  }
  
  printf("%lld\n",ans_sum);
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
// #define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

int color=0;
int root=0;
map<pair<int,int>,int> m;
void dfs(int pos,int bef,int c, vvi &g){
    int nowColor=1;
    for(auto i : g[pos]){
        if(bef==i)continue;
        if(c==nowColor)nowColor++;
        m[mp(min(pos,i),max(pos,i))]=nowColor;
        dfs(i,pos,nowColor,g);
        nowColor++;
    }
}

int main() {

    int n;cin>>n;
    vvi g(n);
    vi v(n,0);
    vpii w(n);
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        a--;b--;
        g[a].pb(b);
        g[b].pb(a);
        v[a]++;v[b]++;
        w[i]=mp(a,b);
    }
    rep(i,n){
        if(color<v[i]){
            color=v[i];
            root=i;
        }
    }
    dfs(root,-1,-1,g);
    fin(color);
    rep(i,n-1){
        cout<<m[mp(w[i].fi,w[i].se)]<<endl;
    }
}

Measured memory_bytes: 16128
import java.util.*
import kotlin.math.abs
import kotlin.math.min

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val x = sc.nextInt()
    val y = sc.nextInt()
    println(problem160d(n, x, y))
}

fun problem160d(n: Int, x: Int, y: Int): String {
    val distanceList = IntArray(n - 1) { 0 }

    for (i in 1 until n) {
        for (j in i + 1 until n + 1) {
            val distanceWithDontUseShortCut = j - i
            val distanceOfItoX = abs(i - x)
            val distanceOfYtoJ = abs(j - y)
            val shortCutCost = 1
            val distanceWithUseShortCut = distanceOfItoX + shortCutCost + distanceOfYtoJ
            val shortestDistance = min(distanceWithDontUseShortCut, distanceWithUseShortCut)
            distanceList[shortestDistance - 1]++
        }
    }
    return distanceList.joinToString("\n")
}

Measured memory_bytes: 40792
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);

int main() {
  ll A, B, Q;
  cin >> A >> B >> Q;
  ll s[A+2], t[B+2];
  ll X[Q];

  s[0] = - 20000000100;
  t[0] = - 20000000100;
  s[A+1] = 20000000100;
  t[B+1] = 20000000100;
  rep(i, A) cin >> s[i+1];
  rep(i, B) cin >> t[i+1];
  rep(i, Q) cin >> X[i];

  // 2分探索でもいけるらしいので、
  ll x[Q][4];

  rep(i, Q) {
    ll l = 0, r = A+1;
    while(l+1<r) {
      ll mid = (l+r)/2;
      if(X[i]<s[mid]) r = mid;
      else l = mid;
    }

    x[i][0] = s[l];
    x[i][1] = s[r];
  }

  rep(i, Q) {
    ll l = 0, r = B+1;
    while(l+1<r) {
      ll mid = (l+r)/2;
      if(X[i]<t[mid]) r = mid;
      else l = mid;
    }
    x[i][2] = t[l];
    x[i][3] = t[r];
  }


  rep(i, Q) {
    ll ret0 = abs(X[i]-x[i][0]) + abs(x[i][0]-x[i][2]);
    ret0 = min(ret0, abs(X[i]-x[i][1]) + abs(x[i][1]-x[i][2]) );
    ret0 = min(ret0, abs(X[i]-x[i][0]) + abs(x[i][0]-x[i][3]) );
    ret0 = min(ret0, abs(X[i]-x[i][1]) + abs(x[i][1]-x[i][3]) );

    ret0 = min(ret0, abs(X[i]-x[i][2]) + abs(x[i][2]-x[i][0]) );
    ret0 = min(ret0, abs(X[i]-x[i][3]) + abs(x[i][3]-x[i][0]) );
    ret0 = min(ret0, abs(X[i]-x[i][2]) + abs(x[i][2]-x[i][1]) );
    ret0 = min(ret0, abs(X[i]-x[i][3]) + abs(x[i][3]-x[i][1]) );

    cout << ret0 << endl;
  }

  return 0;
}

Measured memory_bytes: 6784
#include<stdio.h>
int Adj[100][100] = { 0 };
int Que[101] = { -1 }, d[100] = { -1 };
int main(){
	int n, u, k, v;
	int i, j;
	int id = 0, qin = 0, qout = 0, aid;
	
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &u);
		scanf("%d", &k);
		for (j = 0; j < k; j++) {
			scanf("%d", &v);
			Adj[u - 1][j] = v;
		}
	}
	for (i = 0; i < 101; i++) {
		Que[i] = -1;
		d[i] = -1;
	}
	
	Que[qin++] = id;
	d[id] = 0;
	while (id != -1) {
		qout++;
		for (i = 0; Adj[id][i] != 0; i++) {
			aid = Adj[id][i] - 1;
			if (d[aid] == -1) {
				Que[qin++] = aid;
				d[aid] = d[id] + 1;
			}
		}
		id = Que[qout];
	}
	
	for (i = 0; i < n; i++) {
		printf("%d %d\n", i + 1, d[i]);
	}
	return 0;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll k;
    cin >> k;
    int a,b,c;
    ll ans = 0;
    for(a = 1;a <= k;++a){
        for(b = 1;b <= k;++b){
            for(c = 1;c <= k;++c){
                ll tmp = gcd(a,b);
                tmp = gcd(tmp,c);
                ans += tmp;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
def smaller(a, b):
    n = min(len(a), len(b))
    for i in reversed(range(n)):
        if a[i] < b[i]:
            return True
        elif b[i] < a[i]:
            return False
    return len(a) < len(b)
    
  
    

a, b = [int(x) for x in raw_input().split()]

a_r = ''.join([str(a) for _ in range(b)])

b_r = ''.join([str(b) for _ in range(a)])

if smaller(a_r, b_r):
    print(a_r)
else:
    print(b_r)







Measured memory_bytes: 28012
import java.util.Arrays;

public class Main {

  private static void solve() {
    long n = nl();

    StringBuilder sb = new StringBuilder();
    while (n > 0) {
      n--;
      int v = (int) (n % 26);
      sb.append((char) ('a' + v));
      n /= 26;
    }

    sb.reverse();
    System.out.println(sb);

    // while (n > 0) {
    // sb.append((char) ('a' + n % 26 - 1));
    // n /= 26;
    // }
    // sb.reverse();
    // System.out.println(sb);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 36920
#include<stdio.h>

int main(void) {
    int line;
    int column;

    int area;
    int length;

    scanf("%d %d", &line, &column);
    area = line * column;
    length = 2 * line + 2 * column;
    printf("%d %d\n", area, length);

    return 0;
}

Measured memory_bytes: 596
N=int(input())
A=[list(map(int,input().split())) for i in range(N)]
DP=[-1]*(1<<N)
def f(x,k):
  if x==0:
    DP[x]=1
  if DP[x]!=-1:
    return DP[x]
  DP[x]=0
  for i in range(N):
    if x&(1<<i):
      if A[k][i]:
        DP[x]+=f(x^(1<<i),k+1)
  return DP[x]

print(f((1<<N)-1,0)%(10**9+7))

Measured memory_bytes: 143856
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;



int main() {
	cout << fixed << setprecision(18);
	long long int H,N,A[100005];
	cin>>H>>N;
	for(int i=0;i<N;i++){
		cin>>A[i];
		H-=A[i];
	}
	if(H<=0){cout<<"Yes";}
	else{cout<<"No";}
	
} 

Measured memory_bytes: 1024
import sys
n = input()
for i in range(1,n+1):
  x = i
  if x%3==0:
    sys.stdout.write(' %d' % i)
    continue
  while x<=n:
    if x%10==3:
      sys.stdout.write(' %d' % i)
      break
    else:
      x /= 10
      if x==0:
        break
sys.stdout.write('\n')

Measured memory_bytes: 6628
#include<bits/stdc++.h>
using namespace std;
#define inf 2123333333

int num[100010],sum1[100010],sum2[100010],n;

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

int main()
{
	n=rd();
	for (int i=1;i<=n;i++) num[i]=rd();
	bool flag=true;
	for (int i=2;i<=n;i++) if (num[i]!=num[1]) { flag=false;break; }
	if (flag) { printf("%d\n",n/2);return 0; }
	for (int i=1;i<=n;i++) if (i&1) sum1[num[i]]++;else sum2[num[i]]++;
	int h1=(n+1)/2,h2=n/2;
	int mn1=inf,mn2=inf,mn3=inf,mn4=inf;
	int id1,id2,id3,id4;
	for (int i=1;i<=100000;i++)
	{
		if (h1-sum1[i]<mn1) mn2=mn1,id2=id1,mn1=h1-sum1[i],id1=i;
		else if (h1-sum1[i]<mn2) mn2=h1-sum1[i],id2=i;
	}
	for (int i=1;i<=100000;i++)
	{
		if (h2-sum2[i]<mn3) mn4=mn3,id4=id3,mn3=h2-sum2[i],id3=i;
		else if (h2-sum2[i]<mn4) mn4=h2-sum2[i],id4=i;
	}
	int ans=inf;
	if (id1!=id3) { printf("%d\n",mn1+mn3);return 0; }
	printf("%d\n",min(mn1+mn4,mn2+mn3));
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef vector<int>::iterator vit;

vi adj[100001];
int ans[100001];
const int INF = 100000000;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i = 0; i < n; i++) ans[i] = INF;
	for(int i = 0; i < n - 1; i++)
	{
		int u, v; cin>>u>>v; u--; v--;
		adj[u].pb(v); adj[v].pb(u);
	}
	int k; cin>>k; priority_queue<ii,vector<ii>,greater<ii> > pq;
	for(int i = 0; i < k; i++)
	{
		int u, v; cin>>u>>v; u--;
		ans[u] = v; pq.push(mp(v,u));
	}
	while(!pq.empty())
	{
		int u = pq.top().se; pq.pop();
		for(int i = 0; i < adj[u].size(); i++)
		{
			int v = adj[u][i];
			if(ans[v]<INF)
			{
				if(abs(ans[v]-ans[u])!=1)
				{
					cout<<"No\n"; return 0;
				}
			}
			else
			{
				ans[v]=ans[u]+1;
				pq.push(mp(ans[v],v));
			}
		}
	}
	cout<<"Yes\n";
	for(int i = 0; i < n; i++)
	{
		cout<<ans[i]<< '\n';
	}
}


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

using namespace std;

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

    vector<long> L(100);

    int N;
    long count = 0;

    cin >> N;

    for(int i = 0; i < N; i++){
        cin >> L[i];
    }
/*
    for(int i = 0; i < N; i++){
        if(L[i] > max){
            max = L[i];
        }
    }
*/

    int max = *std::max_element(L.begin(), L.end());

    for(int i = 0; i < N; i++){
        count += L[i];
    }

    count -= max;

    if(N >= 3 && count > max){
        cout << "Yes";
    }else{
        cout << "No";
    }

    
}

Measured memory_bytes: 888
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Long[] A = new Long[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextLong();
        }
        Arrays.sort(A, Collections.reverseOrder());
        Long now = 0L;
        Long use1 = 0L;
        boolean first = true;
        Long use2 = 0L;
        for (Long l : A) {
            if (l.equals(now)) {
                if (first) {
                    first = false;
                    use1 = l;
                    now = 0L;
                    continue;
                } else {
                    use2 = l;
                    break;
                }
            }
            now = l;
        }
        System.out.println(use1*use2);
    }    
}


Measured memory_bytes: 62500
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    mod = 10**9 + 7

    n,a,b = map(int, input().split())
    def nCr(n, r, mod):#mod=10**9+7 
        r = min(r, n-r)
        numer = denom = 1
        for i in range(1, r+1):
            numer = numer * (n+1-i) % mod
            denom = denom * i % mod
        return numer * pow(denom, mod-2, mod) % mod

    res = (2**n - 1)%mod
    x = nCr(n, a, mod)
    y = nCr(n, b, mod)
    print((res-x-y)%mod)

if __name__ == '__main__':
    main()

Measured memory_bytes: 280732
#include <bits/stdc++.h>
using namespace std;
#define m 1000000007
int main() {
	int n , k;
	int ans = 0;
	cin >> n >> k;
	int a[n+1];
	for(int i = 0 ; i <= n ; i++)a[i] = i;
	long long int pre[n+1], suf[n+1];
	memset(pre,0,sizeof(pre));
	memset(suf,0,sizeof(suf));
	for(int i = 0 ; i <= n; i++){
		if(i == 0)pre[i] = a[i];
		else pre[i] = pre[i-1]+a[i];
	}
	for(int i = n ; i>= 0;i--){
		if( i == n )suf[i] = a[i];
		else suf[i] = suf[i+1]+a[i];
	}
	int l = k-1;
	int r = n-k+1;
	while(l <= n && r >= 0){
		ans = (ans + (suf[r]-pre[l]+1))%m;
		l++;
		r--;
	}
	cout<<ans<<"\n";
	return 0;
}

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

const long mod = 1000000007; 

long pmod(long b, long e) {
  if (e == 0) return 1;
  if (e % 2 == 1) return b * pmod(b, e - 1) % mod;
  long t = pmod(b, e / 2);
  return t * t % mod;
}

long inv(long n) {
  return pmod(n, mod - 2);
}


int n, k;
long f[800001];
void pre() {
  int max = n;
  f[0] = 1;
  for (int i = 1; i <= max; ++i) {
    f[i] = f[i - 1] * i % mod;
  }
}

long comb(long n, long r) {
  return f[n] * inv(f[n - r] * f[r] % mod) % mod; 
}

int main() {
  cin >> n >> k;
  k = min(k, n);
  pre();
  long sum = 0;
  for (int i = 0; i <= k; ++i) {
    sum = (sum + comb(n, i) * comb(n - 1, i)) % mod;
  }
  cout << sum << endl;
}

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

int main () {

    std::string s, t;
    std::cin >> s;
    std::cin >> t;

    bool ans = true;
    for (int i = 0; i < s.length(); i++) if(s[i] != t[i]) ans = false;

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

    return 0;
}

Measured memory_bytes: 3032
#include <math.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <climits>
using namespace std ;
#define ld long double
#define int long long
#define ii pair<int,int>
#define _ ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL);
#define dbg(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
const int N = 2e5+7 ;
const int INF = 1e9 ;
const int MOD = INF + 7 ;
//string s ;
void solve(){
	int n , k , r, s ,  p ;
	cin >> n >> k >> r >> s >> p ;
	string t ;
	cin >> t ;
	map<char , int> mp ;
	mp['r'] = r ;
	mp['s'] = s ;
	mp['p'] = p ;

	string tt ;
	tt.resize(n) ;
	for(int i = 0 ; i < n ; i++){
		if(t[i] == 'r'){
			tt[i] = 'p' ;
		}
		else if(t[i] == 'p'){
			tt[i] = 's' ;
		}
		else{
			tt[i] = 'r' ;
		}
	}
	// tt is winning string 
	for(int i = k ; i < n ; i++){
		if(tt[i] == tt[i-k]){
			tt[i] = '#' ;
		}
	}
	int ans = 0 ;
	for(int i = 0 ; i < n ; i++){
		ans += mp[tt[i]] ;
	}
	cout << ans << endl ;
}

int32_t main(){_
	int t = 1 ;
//	cin >> t ;
	while(t--){
		solve() ;
	}

}


Measured memory_bytes: 512
import math

N = int(input())
A = list(int(input()) for _ in range(N))

def insertionSort(A,n,g,cnt):
    for i in range(g,n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
    return cnt

def shellSort(A,n):
    cnt = 0
    G = []
    bet = 0
    while True:
        bet = 3*bet + 1
        if bet <= n:
            G.insert(0,bet)
        else:
            break
    m = len(G)

    for i in range(m):
        cnt = insertionSort(A,n,G[i],cnt)
    print(m)
    outputNumList(G)
    print(cnt)

def outputNumList(A):
    tmp = map(str,A)
    text = " ".join(tmp)
    print(text)

shellSort(A,N)
for k in range(N):
    print(A[k])


Measured memory_bytes: 45532
from collections import defaultdict as d
n=int(input())
a=list(map(int,input().split()))
p=d(int)
l=0
for i in a:
    p[i]+=1
    l+=i
for i in range(int(input())):
    b,c=map(int,input().split())
    l+=p[b]*(c-b)
    p[c]+=p[b]
    p[b]=0
    print(l)

Measured memory_bytes: 23984
import java.util.Scanner;


public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int[][] map = new int[h][w];
        for (int i = 0; i < h; i++) {
            String s = sc.next();
            for (int j = 0; j < w; j++) {
                map[i][j] = Character.digit(s.charAt(j),10);
            }
        }
        int[][] minMap = new int[h][w];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (i == 0 && j == 0) continue;
                int fromTop = i > 0 ? minMap[i-1][j] : 10000000;
                int fromLeft = j > 0 ? minMap[i][j-1] : 1000000;
                minMap[i][j] = Math.min(fromTop, fromLeft) + map[i][j];
            }
        }
        System.out.println(minMap[h-1][w-1]);
    }

}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const double PI = acos(-1);
const double EPS = 1e-8;

using pi = pair<int,int>;
using P = pair<double,pi>;

int main(){
    int n;
    scanf(" %d", &n);

    vector<P> v;
    rep(i,n){
        int x,y;
        scanf(" %d %d", &x, &y);
        double t = atan2(y,x);
        if(t<0) t = 2*PI+t;

        v.pb({t,{x,y}});
        v.pb({t+2*PI,{x,y}});
    }
    sort(all(v));

    int V = v.size();
    ll ans = 0;
    rep(i,V){
        ll x = 0, y = 0;
        for(int j=i; j<V; ++j){
            if(v[j].fi - v[i].fi > PI+EPS) break;
            x += v[j].se.fi;
            y += v[j].se.se;
            ans = max(ans, x*x+y*y);
        }
    }

    printf("%.15f", sqrt(ans));
    return 0;
}


Measured memory_bytes: 256
#!/usr/local/bin/ruby
num = Hash.new(0)
max = 0
while (n=gets.to_i)!=0
#while (n=gets.to_i) != true
 num[n] += 1
end
num.to_a.sort{|p,q| -(p[1]<=>q[1])}.each do |key,value|
 if value >= max
  max = value
  puts key
 else
  break
 end
end

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

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


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

    if(s[s.length()-1]=='s') cout << s << "es" <<  endl;
    else cout << s << "s" << endl;
}

Measured memory_bytes: 3628
N = int(input())
X = list(map(int, input().split()))

best = 10 ** 9
minx, maxx = min(X), max(X)
for p in range(minx, maxx + 1):
    tmp = 0
    for i in range(N):
        tmp += (X[i] - p) ** 2
    best = min(best, tmp)

print(best)

Measured memory_bytes: 9128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x, a, b;
  cin >> x >> a >> b;
 
  if (b<=a) {
    cout << "delicious" << endl;
  }
  else if (b<=a+x) {
    cout << "safe" << endl;
  }
  else {
    cout << "dangerous" << endl;
  }
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
import Control.Monad
import Data.Int (Int64)
import Data.List (foldl')
import Data.Array
import Data.Array.Unboxed
import Data.Array.ST
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS

main = do
  [n,k] :: [Int] <- map (read . BS.unpack) . BS.words <$> BS.getLine
  s <- BS.getLine -- '0' or '1'
  -- standing: 0, headstanding: 1
  let countStanding s | BS.null s = []
                      | (a,b) <- BS.span (== '0') s = BS.length a : countHandstanding b
      countHandstanding s | BS.null s = [0]
                          | (a,b) <- BS.span (== '1') s = BS.length a : countStanding b
      standing :: U.Vector Int
      standing = U.fromListN n $ countHandstanding s
      ss = U.scanl' (+) 0 standing
  if U.length ss > 2 * k + 1
    then print $ maximum [ss U.! (2*(i+k)+1) - ss U.! (2 * i) | i <- [0..(U.length ss `quot` 2) - k - 1]]
    else print n


Measured memory_bytes: 1916
#include <iostream>
#include <vector>

using namespace std;
using u64 = unsigned long long;
const u64 MOD = 1000000007;
const u64 INF = 0xffffffffffffffff;

u64 pow(u64 a, u64 n) {
  u64 res = 1;
  while (n > 0) {
    if (n % 2)
      res = res * a % MOD;
    a = a * a % MOD;
    n = n / 2;
  }
  return res;
}

u64 C(const u64 N, const u64 K, const u64 m, vector<u64> &memo) {
  if (memo[m] != INF) {
    return memo[m];
  }

  u64 r = pow(K / m, N);
  for (u64 i = 2; i * m <= K; i++) {
    r = (r + MOD - C(N, K, i * m, memo)) % MOD;
  }

  return memo[m] = r;
}

int main(void) {
  u64 N, K;
  cin >> N >> K;

  // K^N + \Sigma {m} ^{K} _{2} {m * C(m) - C(m)}
  //  = K^N + \Sigma {m} ^{K} _{2} {(m - 1) * C(m)}
  // C(m) = (K/m)^N - \Sigma {i} ^{K/m} _{2} C(i*m)

  u64 ans1 = pow(K, N);
  u64 ans2 = 0;
  vector<u64> memo(K + 1, INF);
  for (u64 m = 2; m <= K; m++) {
    u64 r = (m - 1) * C(N, K, m, memo) % MOD;
    ans2 = (ans2 + r) % MOD;
  }
  u64 ans = (ans1 + ans2) % MOD;
  cout << ans << endl;
  return 0;
}

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

double a, b, c, d, e, f;
double g;

int main() {
    cin >> a >> b >> c >> d;
    e=a-c;
    f=b-d;
    g=sqrt(e*e + f*f);
    cout << fixed << setprecision(9);
    cout << g << endl;
}


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


using namespace std;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int a,b,c;cin >> a >> b >> c;
    int d=(c-a+b);
    d=max(0,d);

    cout << d;



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0; i<(n); ++i)
#define REPR(i,n,m) for (int i=(n); i>=(m); --i)
using namespace std;
using LL = long long;
using LD = long double;
using PLL = pair<long long, long long>;
using PLD = pair<long double, long double>;
using VLL = vector<long long>;
using VLD = vector<long double>;
using VPLL = vector<PLL>;
using VPLD = vector<PLD>;

const int INF = numeric_limits<int>::max();
const unsigned long long int ULLINF = numeric_limits<unsigned long long int>::max();
const LL mod = 1000000007;

LL powmod(LL x, LL y) {
    LL res = 1;
    for (LL i=0; i<y; i++) {
        res = res * x % mod;
    }
    return res;
}


int main() {
    clock_t start = clock();

    LL n;
    cin >> n;

    LL ans = powmod(10, n) - powmod(9, n) * 2 + powmod(8, n);
    
    ans %= mod;
    ans = (ans+mod)%mod;

    cout << ans << endl;    
    

    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    // printf("time %lf[ms]\n", time);
    return 0;
}


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

ll N, K;
const int MAX = 1.0e5 + 100;

const int MOD = 1.0e9 + 7;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}

int main() {
    COMinit();

    cin >> N >> K;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];


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

    ll ans = 0;
    for (int i = N-1; i >= 0; i--) {
        int j = N - i;
        if (N-j >= K-1) {
            ans = mod(ans + mod(COM(N-j, K-1) * A[i], MOD), MOD);
        }
    }

    for (int i = 0; i < N; i++) {
        int j = i+1;
        if (N-j >= K-1) {
            ans = mod(ans - mod(COM(N-j, K-1) * A[i], MOD), MOD);
        }
    }

    cout << ans << endl;

    return 0;
}


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

INF = 10**18

def dijkstra(edges, size, src):
    from heapq import heappush, heappop

    dist = [INF] * size
    dist[src] = 0
    pq = [(0, src)]
    while pq:
        d, v = heappop(pq)
        if d > dist[v]:
            continue
        for u, weight in edges[v]:
            nd = d + weight
            if dist[u] > nd:
                dist[u] = nd
                heappush(pq, (nd, u))
    return dist

N, M = map(int, input().split())
G = [[] for _ in range(N+1)]
for i in range(2, N+1):
    G[i].append((i - 1, 0))
for _ in range(M):
    L, R, C = map(int, input().split())
    G[L].append((R, C))
dist = dijkstra(G, N+1, 1)
print(dist[N] if dist[N] < INF else -1)


Measured memory_bytes: 72992
N,M = map(int, input().split())
ans = 1
bro = list([])

for i in range(M):
    bro.append(int(input()))

bro.append(-1)

f = [0,0,1]

def Step (i):
    if i == bro[0]:
        bro.pop(0)
        f[0],f[1],f[2] = f[1],f[2],0
    else:
        f[0],f[1],f[2] = f[1],f[2],f[1]+f[2]

for i in range(N):
    Step(i+1)

ans = f[2]%(10**9+7)

print(ans)


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

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

    int main() {
    int m,n,o;
    cin >> m >> n >> o;
    cout << min(min(abs(m+n),abs(m+o)),n+o) << endl;
    }

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

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vs vector<string>
#define pull pair<ull, ull>
#define m_p make_pair
#define debug(x) cout << #x << " " << x << endl
#define printArr(a, start, end)for(int i=start ; i<end ; ++i)cout << a[i] << " ";
#define readArr(a, start, end)for(int i=start ; i<end ; ++i)cin >> a[i];
#define read2D(mat, n, m)for(int i=0 ; i<n ; ++i)for(int j=0 ; j<m ; ++j)cin >> mat[i][j];

const long double PI = 3.141592653589793238462643383279502884197169399;

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

void solve(){
	string s, t;
	cin >> s >> t;
	
	int diff=0;
	for(int i=0 ; i<s.size() ; ++i)if(s[i] != t[i])diff++;
	
	cout << diff;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int tt=1;
	//cin >> tt;
	
	while(tt--){
		solve();
	}
}


Measured memory_bytes: 3784
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.* ;
 
class Main{
  public static void main(String[] args)throws IOException{
      
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));// ??\?????????
    String str = br.readLine();
  
    String[] strAry = str.split(" ");
    int a = Integer.parseInt(strAry[0]);
  	int b = Integer.parseInt(strAry[1]);
  	int d= a / b;
  	int r= a%b ;
  	double f = (double)a/b ;
  	System.out.printf(d + " " + r + " " + "%.5f\n",f );
  	
  	}
}	

Measured memory_bytes: 24588
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int N,K;
string s;
string nxt(string s){
	if(s[0]=='A'){
		s[0]='B';
		return s;
	}
	int N=s.size();
	string t(N,'.');
	rep(i,N-1) t[i]='A'+'B'-s[i+1];
	t[N-1]='A';
	return t;
}
int main(){
	// string s;
	// cin>>s;
	// rep(i,50){
	// 	s = nxt(s);
	// 	cout<<s<<endl;
	// }
	cin>>N>>K>>s;
	// string brute;
	// string tmp = s;
	// rep(i,K){
	// 	tmp = nxt(tmp);
	// }
	int st=0;
	while(K>0&&st<N){
		K--;
		if(s[st]=='A' ^ st%2==1){
			s[st] = 'A'^'B'^s[st];
			continue;
		}else{
			st++;
		}
	}
	string t(N,'.');
	for(int i=st;i<N;i++){
		if(st%2==0) t[i-st] = s[i];
		else t[i-st] = s[i]^'A'^'B';
	}
	rep(i,st){
		if((st-i)%2==1) t[N-st+i] = 'A';
		else t[N-st+i] = 'B';
	}
	if(K>0){
		if(K%2==1) t = nxt(t);
	}

	cout<<t<<endl;
//	assert(tmp==t);
}


Measured memory_bytes: 1156
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstdlib>
#define INF 100000000
#define _INF -100000000
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;
 
char field[100][101];
int h, w;
queue<P> que;
int dx[4] = { 0,0,-1,1 }, dy[4] = { -1,1,0,0 };
int ret;
 
void solve() {
    Loop(i, h) {
        Loop(j, w) {
            if (field[i][j] != '.') {
                que.push(P(i, j));
                char c = field[i][j];
                field[i][j] = '.';
                while (que.size() > 0) {
                    P p = que.front(); que.pop();
                    Loop(k, 4) {
                        int a = p.first + dx[k], b = p.second + dy[k];
                        if (a >= 0 && a <= h - 1 && b >= 0 && b <= w - 1 && field[a][b] == c) {
                            field[a][b] = '.';
                            que.push(P(a, b));
                        }
                    }
                }
                ret++;
            }
        }
    }
}
 
int main() {
    while (cin >> h >> w, h || w) {
        Loop(i, h) {
            Loop(j, w) {
                cin >> field[i][j];
            }
        }
        ret = 0;
        solve();
        cout << ret << endl;
    }
    return 0;
}

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

int main(){

  string s;
  cin >> s;

  ll sum = 0;
  for(int i = 0; i < (1<<s.size()-1); i++){
    string tmp;
    for(int j = 0; j < s.size(); j++){
      tmp += s[j];
      if(i & (1 << j)){
        sum += stoll(tmp);
        tmp.clear();
      }
    }
    sum += stoll(tmp);
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {

    int N;
    cin >> N;
    cout << (N / 2 + (N % 2 == 0 ? 0 : 1)) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Abra_Ka_Dabra ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

    Abra_Ka_Dabra

    int a, b ,c, k;
    cin>>a>>b>>c>>k;
    int cnt=0;
    while(a>=b){
        b*=2;
        cnt++;
    }
    while(b>=c){
        c*=2;
        cnt++;
    }
    if(k>=cnt) cout<<"Yes\n";
    else cout<<"No\n";

    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define p (int)(1e9 + 7)

int MOD(int a){
	return (a %= p) >= 0 ? a : a + p;
}

int power(int a, int N){
	if(N == 0) return 1;
	else if(N % 2 == 0) return power(MOD(a * a), N / 2);
	else return MOD(a * power(a, N - 1));
}

int inverse(int a){
	return power(a, p - 2);
}

int fact(int N){
	static vector<int> _fact(1, 1);
	for(int i = _fact.size(); i <= N; i++){
		_fact.push_back(MOD(i * _fact[i - 1]));
	}
	return _fact[N];
}
 
int fact_inv(int N){
	static vector<int> inv(2, 1), _fact_inv(2, 1);
	for(int i = inv.size(); i <= N; i++){
		inv.push_back(MOD(-(p / i) * inv[p % i]));
		_fact_inv.push_back(MOD(inv[i] * _fact_inv[i - 1]));
	}
	return _fact_inv[N];
}
 
int combination(int N, int k){
	if(k < 0 || N < k || N < 0) return 0;
	else return MOD(fact(N) * MOD(fact_inv(N - k) * fact_inv(k)));
}

signed main(){
	int N, K, i;
	scanf("%lld%lld", &N, &K);
	vector<int> A(N);
	for(i = 0; i < N; i++){
		scanf("%lld", &A[i]);
	}
	sort(A.begin(), A.end());
	int ans = 0;
	for(i = N - 1; i >= K - 1; i--){
		ans = MOD(ans + A[i] * combination(i, K - 1));
	}
	for(i = 0; i < N; i++){
		if(i < N - 1 - i){
			swap(A[i], A[N - 1 - i]);
		}
	}
	for(i = N - 1; i >= K - 1; i--){
		ans = MOD(ans - A[i] * combination(i, K - 1));
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class Main {

	public static void main(String[] args) throws IOException {
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		
		Set<String> hashSet = new HashSet<String>();
		int n = Integer.parseInt(reader.readLine());
		for (int i = 0; i < n; i++) {
			String[] cmd = reader.readLine().split(" ");
			if ('i' == cmd[0].charAt(0)) {
				hashSet.add(cmd[1]);
			} else {
				if (hashSet.contains(cmd[1])) {
					System.out.println("yes");
				} else {
					System.out.println("no");
				}
			}
		}
	}
}


Measured memory_bytes: 191976
#include "bits/stdc++.h"
using namespace std;

int main() {
	vector<bool>Like_2017(100001, false);
	for (int i = 3; i < 100000; i++) {
		bool check1 = true, check2 = true;
		for (int j = 2; j <= sqrt(i); j++) {
			if (i % j == 0) check1 = false;
		}
		for (int j = 2; j <= sqrt((i + 1) / 2); j++) {
			if (((i + 1) / 2) % j == 0) check2 = false;
		}
		if (check1 && check2) Like_2017.at(i) = true;
	}
	vector<long long>Num_like(100001, 0);
	long long num = 0;
	Num_like.at(3) = 1;
	for (int i = 1; i < 100000; i++) {
		if (Like_2017.at(i)) Num_like.at(i) = Num_like.at(i - 1) + 1;
		else Num_like.at(i) = Num_like.at(i - 1);
	}
	long long Q;
	cin >> Q;
	long long Prime_left, Prime_right;
	long long ans = 0;
	for (long long i = 0; i < Q; i++) {
		ans = 0;
		cin >> Prime_left >> Prime_right;
		cout << Num_like.at(Prime_right) - Num_like.at(Prime_left - 1) << endl;
	}
}


Measured memory_bytes: 1408
using System;
namespace tst
{
    class Program
    {
        public static void Main()
        {
            string[] In = Console.ReadLine().Split(' ');
            int a = int.Parse(In[0]);
            int b = int.Parse(In[1]);
            int x = a - (b * 2);
            if (x >= 0)
            {
                Console.WriteLine(x);
            }
            else
            {
                Console.WriteLine(0);
            }
        }
    }
}

Measured memory_bytes: 11092
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	void doIt() {
		long a = sc.nextLong(), b = sc.nextLong(),c = sc.nextLong(),d = sc.nextLong();
		long cdivcnt = 0,ddivcnt = 0,cdboth = 0;
		cdivcnt = b/c;
		ddivcnt = b/d;
		cdboth = b/lcm(c,d,gcd(c,d));
		long bcnt = b - (cdivcnt + ddivcnt) + cdboth;
		
		cdivcnt = (a-1)/c;
		ddivcnt = (a-1)/d;
		cdboth = (a-1)/lcm(c,d,gcd(c,d));
		long acnt = (a-1) - (cdivcnt + ddivcnt) + cdboth;
		
		System.out.println(bcnt - acnt);
	}
	
	static long gcd(long a, long b) {
		if(a%b == 0) return b;
		return gcd(b,a%b);
	}
	
	static long lcm(long a,long b,long abgcd) {
		return a * b / abgcd;
	}

	public static void main(String[] args) {
		new Main().doIt();
	}

}





Measured memory_bytes: 21972
package main

import "fmt"

var s, t string

func main() {
	fmt.Scan(&s)
	fmt.Scan(&t)
	n := len(s)
	m := len(t)
	dp := make([][]int, n+1)
	for i := range dp {
		dp[i] = make([]int, m+1)
	}

	for i, c := range s {
		for j, d := range t {
			if c == d {
				chmax(&dp[i+1][j+1], dp[i][j]+1)
			}
			chmax(&dp[i+1][j+1], dp[i+1][j])
			chmax(&dp[i+1][j+1], dp[i][j+1])
		}
	}
	index := dp[n][m]
	lcs := make([]rune, index)
	rs := []rune(s)
	rt := []rune(t)

	for i, j := n, m; i > 0 && j > 0; {
		if rs[i-1] == rt[j-1] {
			lcs[index-1] = rs[i-1]
			index--
			i--
			j--
			continue
		}
		if dp[i-1][j] > dp[i][j-1] {
			i--
		} else {
			j--
		}

	}
	fmt.Println(string(lcs))
}

const INF = 1 << 60

func chmax(a *int, b int) {
	if *a < b {
		*a = b
	}
}

func chmin(a *int, b int) {
	if *a > b {
		*a = b
	}
}

func min(as ...int) int {
	m := as[0]
	for i := range as {
		chmin(&m, as[i])
	}
	return m
}

func max(as ...int) int {
	m := as[0]
	for i := range as {
		chmax(&m, as[i])
	}
	return m
}


Measured memory_bytes: 75392
/*
 *  Lang    : C++
 *  Author  : little_angel
 */

#include <bits/stdc++.h>

using namespace std;
#define int long long
#define dbg(x) cerr<<"["<<#x<<" = "<<x<<"]"

int D;
vector<vector<int>> s;
vector<int> c;

int get_score(vector<int> &sc) {
    unordered_map<int, int> last;
    int S = 0;
    for (int i = 0; i < D; ++i) {
        S += s[i][sc[i] - 1];
        last[sc[i] - 1] = i + 1;
        for (int j = 0; j < 26; j++)S -= c[j] * (i + 1 - last[j]);
        dbg(S) << endl;
    }
    return max(1000000 + S, 0ll);
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);

    cin >> D;
    c = vector<int>(26);
    s = vector<vector<int>>(D, vector<int>(26));
    for (auto &i:c)cin >> i;
    for (auto &i:s) {
        for (auto &j:i)cin >> j;
    }

    vector<int> ans(D);

    for (int i = 0; i < D; ++i) {
//        int cur = -1, pos = -1;
//        for (int j = 0; j < 26; ++j) {
//            if (cur < s[i][j]) {
//                pos = j;
//                cur = s[i][j];
//            }
//        }
//        ans[i] = pos + 1;
        ans[i] = 1 + i % 26;
    }
    for (auto i:ans)cout << i << endl;

//    int score = get_score(ans);
//    dbg(score) << endl;
}

Measured memory_bytes: 3748
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second   
#define rep(i,n) for(int i = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define setval(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define trav(x , a) for(auto &x : a)
#define sz(a) ((int)a.size())
typedef long long ll ; 
#define int ll
using namespace std;

const int N = 3e5 + 5 ;
const int mod = 1e9 + 7 ;
const ll inf = 1e18 ;
const int SZ = 101 ;
const long double eps = 1e-9 ;

using namespace __gnu_pbds;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

typedef pair<int, int> pii; 
typedef pair<int , pii> ipii ;
typedef pair<pii , int> piii ; 
typedef unsigned long long ull ;
typedef long double ld;

ll po(ll x,ll y,ll p = mod) {ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}

void solve()
{
    int n ;
    cin >> n ;
    int a[n + 1] = {} ;
    rep(i , n + 1) cin >> a[i] ;
    int nodes= 0 ;
    int nxtR = 0 , nxtL = 0 ;
    int ub[n + 1];
    for(int i = 0 ; i < n + 1 ; ++i){
        if(!i) ub[i] = 1;
        else ub[i] = min( (ub[i - 1] - a[i-1]) * 2LL  , inf);
    }

    repD(i , n , 0){
        // not too many st I exceed leaves on current level, but not too less to 
        int nL = a[i] + (nxtL+1)/2 , nR = a[i] + nxtR;
        nR = min(nR , ub[i]);
        if(nL > nR || nR < a[i]) {
            cout << -1;
            return;
        }        
        // cout << nR << '\n';
        nodes += nR;
        nxtR = nR ;
        nxtL = nL ;
    }
    cout << nodes; 
}
     
int32_t main(int32_t argc, char *argv[])
{
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        cout << "\n" ;
    }
    return 0;
}


Measured memory_bytes: 5172
/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*/
//vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a.at(i);
  int mi =10000000000;
  int ma =0;
  rep(i,n) mi = min(mi,a.at(i));
  rep(i,n) ma = max(ma,a.at(i));
  cout << ma - mi <<endl;
}

Measured memory_bytes: 256