akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        List<Long> temp = new ArrayList<>();
        long tempNumber;
        for (long i = 0L; i < 150; i++) {
            tempNumber = i * i * i * i * i;
            temp.add(tempNumber);
            temp.add(-tempNumber);
        }
        temp.add(0L);
        long x = Long.parseLong(scanner.next());
        for (Long no : temp) {
            if (temp.contains(no - x)) {
                long b = no - x;
                long outA;
                long outB;
                if (no < 0) {
                    outA = (long)-Math.pow(-no,0.2);
                } else {
                    outA = (long)Math.pow(no,0.2);
                }
                if (b < 0) {
                    outB = (long)-Math.pow(-b,0.2);
                } else {
                    outB = (long)Math.pow(b,0.2);
                }
                System.out.println(outA + " " + outB);
                return;
            }
        }
    }

}

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

int main(){
    long long m, n;
    cin >> m >> n;
    vector<int> a(n);
    long long sum = 0;

    rep(i, n){
        cin >> a.at(i);
        sum += a.at(i);
    }

    long long ans = m - sum;
  	if (ans < 0){
      ans = -1;
    }

    cout << ans << endl;

}


Measured memory_bytes: 3640
n, m = map(int, input().split())
sc = []
for i in range(m):
    s, c = map(int, input().split())
    sc.append([s, c])

for i in range(1000):
    i = list(str(i))
    flag = True
    if len(i) == n:
        for j in sc:
            tmp = i[j[0] - 1]
            tmp2 = str(j[1])
            if tmp == tmp2:
                pass
            else:
                flag = False
    else:
        continue
    if flag:
        print(''.join(i))
        exit(0)
print(-1)


Measured memory_bytes: 3064
#include <stdio.h>
using namespace std;
int main()
{
	int n,x,y=0,c=0;
	scanf("%d",&n);
	x=n*800;
	while(n>=15)
	{
		n-=15;
		c++;
	}
	y=c*200;
	printf("%d",x-y);
}

Measured memory_bytes: 128
#include <iostream>
#include <queue>
using namespace std;
#define endl '\n'
void fastIO() {
	 ios_base::sync_with_stdio(false);
	 cin.tie(NULL);
}

int main() {
	fastIO();
	priority_queue<int> pq;
	int n;
	cin >> n;
	for(int i = 0 ; i < n ; ++i) {
		int x;
		cin >> x;
		pq.emplace(x);
	}
	
	int sum = 0;
	int maxValue = pq.top();
	pq.pop();
	while(!pq.empty()) {
		sum += pq.top();
		pq.pop();
	}
	
	if(sum > maxValue) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#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;

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

    if((B - A - 1) % 2 == 0) {
        cout << "Borys" << endl;
    } else {
        cout << "Alice" << endl;
    }

    /* 
    while(true) {
        if(A == 1 || A == N) {
            cout << "Borys" << endl;
            break;
        } else if(A == 1 || A == N) {
            cout << "Alice" << endl;
            break;
        } else {
            // TODO 引き分けってどういう状態?
            cout << "Draw" <<  endl;
            break;
        }
    } */
}

Measured memory_bytes: 256
import sys,math,collections,itertools
input = sys.stdin.readline

a,b,c,d =list(input().rstrip())
op_lis = itertools.product('+-',repeat=3)
for op in op_lis:
    if eval(a+op[0]+b+op[1]+c+op[2]+d) == 7:
        print(a+op[0]+b+op[1]+c+op[2]+d+'=7')
        exit()

Measured memory_bytes: 9364
import sys
import numpy as np
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

N, K = map(int, readline().split())
A = np.array(read().split(), np.int64)

bit_cnt = [((A >> i) & 1).sum() for i in range(40)]
bit_cnt = [0 if i > N - i else 1 for i in bit_cnt]

K_2 = format(K, 'b')
k = len(K_2)
X = []
if sum([2 ** i for i in range(k) if bit_cnt[i] == 1]) > K:
    for i in range(k - 1, -1, -1):
        if int(K_2[-i - 1]) < bit_cnt[i]:
            bit_cnt[i] = 0
            X.append(sum([2 ** i for i in range(k) if bit_cnt[i] == 1]))
else:
    X.append(sum([2 ** i for i in range(k) if bit_cnt[i] == 1]))

answer = [(i ^ A).sum() for i in X if i <= K]
print(max(answer))

Measured memory_bytes: 25508
#include <iostream>
#include <stdint.h>

using namespace std;
const int mod = 1000000007;

int main()
{
  int H, W, K;
  cin >> H >> W >> K;

  uint64_t A[H+1][W];
  for (int h=0; h<=H; ++h)
    for (int w=0; w<W; ++w)
      A[h][w] = 0;

  A[0][0] = 1;
  for (int w=1; w<W; ++w)
    A[0][w] = 0;

  for (int h=1; h<=H; ++h) {
    for (int w=0; w<W; ++w) {
      for (int p=0; p<1<<(W-1); ++p) {
	// check amidakuji path validity
	bool exist_consecutive_digit_1 = false;
	for (int bit=0; !exist_consecutive_digit_1 && bit<(W-1); ++bit) {
	  if (((p >> bit) & 1) == 1 && ((p >> (bit+1)) & 1) == 1) {
	    exist_consecutive_digit_1 = true;
	    break; // invalid amidakuji path found
	  }
	}
	
	if (exist_consecutive_digit_1) {
	  continue; // invalid amidakuji path
	}

	if (w<W-1 && ((p>>w)&1)==1) {// go left
	  A[h][w] += A[h-1][w+1];
	  A[h][w] %= mod;
	} else if (w>0 && ((p>>(w-1))&1)==1) {// go right
	  A[h][w] += A[h-1][w-1];
	  A[h][w] %= mod;
	} else {
	  A[h][w] += A[h-1][w];
	  A[h][w] %= mod;
	}	
      }
    }
  }

  cout << A[H][K-1] << endl;
  
  return 0;
}

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

int main() {
  int n;
  vector<int> vec;
  cin >> n;
  int temp;
  long long acm=0;
  for(int i=0; i<n; i++) {
    cin >> temp;
    //vec.push_back(temp);
    acm += temp-1;
  }
  cout << acm << endl;
  /* m=1 -> sum = m;
   * m = k -> f(k)
   * m = k+1 -> k+1を割り切る部分列b1 .. b_t -> 0
   *		    それ以外 1*(N-t)増加
   *		    (b1-1)+...+(b_t-1) - (N-t) < 0 減少 
   * m = prime number -> N 増加
   * m = a1*a2* .. a_n -> 0
   * T = a1*a2* .. *a_n とする。
   * 1,2,3,4, ... ,T までの数のうち、
   * 
   * 
  */
}



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

int main() {
  long long a, b, c, d;
  std::cin >> a >> b >> c >> d;
  long long max = a*c;
  max = std::max(max, a*d);
  max = std::max(max, b*c);
  max = std::max(max, b*d);
  
  std::cout << max << std::endl;
  
  return 0;
}

Measured memory_bytes: 3632
import sys
import re
import math
import collections
import decimal
import bisect
import itertools

import copy

# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, k = ns()
    a = na()

    total = 0
    for i in range(n):
        for j in range(n):
            if a[i] < a[j]:
                total += 1
                total %= MOD

    ans = total * (k * (k - 1) // 2) % MOD

    cnt = 0
    for i in range(n):
        for j in range(n-i-1):
            if a[j] > a[j+1]:
                a[j], a[j+1] = a[j+1], a[j]
                cnt += 1
                cnt %= MOD
    cnt = cnt * k % MOD

    res = (ans + cnt) % MOD

    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5204
#include<iostream>
using namespace std;
int main(){
	int n, cnt;
	
	while(cin >> n){
		bool prime[1000000] = {false};
		prime[1] = true; //1???????????\
		
		// ??¨??????????????????????????????
		for(int j = 2; j*j <= n; j++){
			if(prime[j] == false){
				for(int k = j; k*j <= n; k++){
					prime[j*k] =true;
				}
			}
		}
		cnt = 0;
		for(int i = 1; i <= n; i++){
			if(prime[i] == false) cnt++;
		}
		
		cout << cnt << endl;
	}
}

Measured memory_bytes: 4064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll a,b,q;
    cin>>a>>b>>q;
    ll s[a+2];
    for(ll i=1;i<=a;i++)
    {
        cin>>s[i];
    }
    ll t[b+2];
    for(ll i=1;i<=b;i++)
    {
        cin>>t[i];
    }
    s[0]=-1e18;
    s[a+1]=1e18;
    t[0]=-1e18;
    t[b+1]=1e18;
    ll dis1[a+2];
    dis1[0]=1e18;
    ll dis2[b+2];
    dis2[0]=1e18;
    dis1[a+1]=1e18;
    dis2[b+1]=1e18;
    for(ll i=1;i<=a;i++)
    {
        auto it=upper_bound(t,t+b+2,s[i]);
        dis1[i]=abs(*it-s[i]);
        it--;
        dis1[i]=min(dis1[i],abs(*it-s[i]));
    }
    for(ll i=1;i<=b;i++)
    {
        auto it=upper_bound(s,s+a+2,t[i]);
        dis2[i]=abs(*it-t[i]);
        it--;
        dis2[i]=min(dis2[i],abs(*it-t[i]));
    }
    ll x;
    while(q--)
    {
        cin>>x;
        auto it=upper_bound(s,s+a+2,x);
        ll ans=abs(*it-x)+dis1[it-s];
        it--;
        ans=min(ans,abs(*it-x)+dis1[it-s]);
        auto it1=upper_bound(t,t+b+2,x);
        ans=min(ans,abs(*it1-x)+dis2[it1-t]);
        it1--;
        ans=min(ans,abs(*it1-x)+dis2[it1-t]);
        cout<<ans<<endl;    
    }
}

Measured memory_bytes: 4480
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
  int N, M, R;
  cin >> N >> M >> R;
  vector<int> r(R);
  rep(i, R) {
    cin >> r[i];
    r[i]--;
  }
  vector<int> A(M), B(M), C(M);
  rep(i, M) {
    cin >> A[i] >> B[i] >> C[i];
    A[i]--;
    B[i]--;
  }
  vector<vector<int>> to(N, vector<int>(N, 1e9));
  rep(i, N) to[i][i] = 0;
  rep(i, M) {
    to[A[i]][B[i]] = C[i];
    to[B[i]][A[i]] = C[i];
  }
  rep(i, N) rep(j, N) rep(k, N)
    chmin(to[j][k], to[j][i]+to[i][k]);
  sort(r.begin(), r.end());
  int ans = 1e9;
  do {
    int tmp = 0;
    rep(i, R-1)
      tmp += to[r[i]][r[i+1]];
    chmin(ans, tmp);
  } while(next_permutation(r.begin(), r.end()));
  cout << ans << endl;
  return 0;
}

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

N=int(input())
S=input().strip()

SUB={""}
ANS=set()

for s in S:
    N=set()
    for t in SUB:
        x=t+s
        if len(x)<=2:
            N.add(x)
        else:
            ANS.add(x)

    SUB|=N

print(len(ANS))

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

using namespace std;

#define int long long

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    string ans = "Yes";
    for (int i = 0; i < n; ++i)
    {
        if (i % 2 == 0 && s[i] == 'L')
        {
            ans = "No";
        }
        if (i % 2 == 1 && s[i] == 'R')
        {
            ans = "No";
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	if (n==25)
	{
		cout<<"Christmas"<<endl;
		return 0;
	}
	if (n==24)
	{
		cout<<"Christmas Eve"<<endl;
		return 0;
	}
	if (n==23)
	{
		cout<<"Christmas Eve Eve"<<endl;
		return 0;
	}
	if (n==22)
	{
		cout<<"Christmas Eve Eve Eve"<<endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 768
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));

            return;
        }

        public void Solve(ConsoleInput cin)
        {
            var A = cin.ReadInt;
            var B = cin.ReadInt;
            var S = cin.Read.ToCharArray();

            var flag = true;

            for (int i = 0; i < A; i++)
            {
                if (S[i] < '0' || S[i] > '9') flag = false; 
            }

            if (S[A] != '-') flag = false;

            for (int i = A + 1; i < A + B + 1; i++)
            {
                if (S[i] < '0' || S[i] > '9') flag = false;
            }

            if (flag) WriteLine("Yes");
            else WriteLine("No");

        }
    }

    public static class Extensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 13268
from collections import deque,defaultdict
n = int(input())
edges = [[] for _ in range(n)]
for i in range(n-1):
    a,b=map(int, input().split())
    edges[a-1].append([b-1,i])
    edges[b-1].append([a-1,i])
c = 1
col = [0]*(n-1)
visited = [0]*(n-1)
que=deque()
for v in edges[0]:
    que.append(v)
    col[v[1]]=c
    visited[v[1]]=1
    c+=1
while que:
    v=que.popleft()
    c = 1
    used = set()
    for i in edges[v[0]]:
        if(visited[i[1]]):
            used.add(col[i[1]])
    for next_v in edges[v[0]]:
        if(not visited[next_v[1]]):
            if(c in used):
                c+=1
            col[next_v[1]] = c
            used.add(c)
            c+=1
            visited[next_v[1]] = 1
            que.append(next_v)
print(max(col))
for i in col:
    print(i)


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

int main(){

  int n;
  string s;
  
  int ans;
  
  int flag = 0;
  
  cin >> n;
  cin >> s;
  //cout << n  << s << endl;
  
  /*for(int i = 0; i < n; i++){
    
    cin >> s[i];
    cout << s[i] << endl;
  }
    */
  
  ans = n / 2;
  
  for(int i = 0; i < ans; i++){
    
    //cout << s.at(i)  << s.at(i + ans) << endl;

    if(s.at(i) != s.at(i + ans) ){
      
      flag = 1;
      
    }
    
  }
  
  if(flag == 0 && n % 2 == 0){
    cout << "Yes" << endl;
  }else{
	cout << "No" << endl;
  }
  
  return 0;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	int n=s.size();
	for (int i=0; i<n; i++) {
		if (i%2) {
			if (s[i]=='R') {
				cout<<"No\n"; return 0;
		}
	} else {
	if (s[i]=='L') {
	cout<<"No\n"; return 0;
		}
	 }
	}
	cout<<"Yes";
}


Measured memory_bytes: 256
import heapq
import math
import sys
from functools import reduce
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    A = [-float(c) for c in input().split()]
    heapq.heapify(A)

    for _ in range(M):
        tmp = heapq.heappop(A)
        heapq.heappush(A, tmp/2)

    print(reduce(lambda total, x: math.floor(-x) + total, A, 0))

main()

Measured memory_bytes: 13972
import java.util.Scanner;

public class Main {
	public static void main(String []args) {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		while( T-->0 ) {
			int a[] = new int[10];
			for(int i = 0; i < 10; i++) a[i] = sc.nextInt();
			boolean res = solve(a);
			if( res ) System.out.println("YES");
			else System.out.println("NO");
			
		}
	}
	
	static boolean solve(int a[]) {
		int left = -99999;
		int right = -99999;
		for(int i = 0; i < a.length; i++) {
			if( a[i] < left && a[i] < right ) return false;
			if( a[i] > left && a[i] > right ) {
				if( left > right ) left = a[i];
				else right = a[i];
			}
			else if( a[i] > left ) left = a[i];
			else right = a[i];
		}
		return true;
	}
}

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

using namespace std;

typedef long long int64;


int main()
{
  int64 N, x, A[100001] = {};

  cin >> N >> x;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }

  int64 ret = 0;
  for(int i = 1; i <= N; i++) {
    ret += min(A[i], max(0LL, A[i - 1] + A[i] - x));
    A[i] -= min(A[i], max(0LL, A[i - 1] + A[i] - x));
    ret += max(0LL, A[i - 1] + A[i] - x);
  }

  cout << ret << endl;
}

Measured memory_bytes: 1024
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
x = [0] * M
y = [0] * M
c = [0] * M
for i in range(M):
    x[i], y[i], c[i] = map(int, input().split())


ans= 0
tmp =0
#割引券を使わない場合
ans = min(a) + min(b)

#割引券を使う場合
for i in range(M):
    if a[x[i]-1] + b[y[i]-1] - c[i] < ans:
        ans = a[x[i]-1] + b[y[i]-1] - c[i]

print(ans)


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

int main() {
int N , M;
cin >> N >> M;
int a , b;
vector<int> vec(N);
  for (int i = 0; i < M; i++){
   cin >> a >> b;
   vec.at(a - 1)++;
   vec.at(b - 1)++;
  }
  for (int i = 0; i < N; i++){
   cout << vec.at(i)<< endl;
  }
}

Measured memory_bytes: 256
import java.util.GregorianCalendar;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);

		String[] list = { "", "Sunday", "Monday", "Tuesday", "Wednesday",
				"Thursday", "Friday", "Saturday" };

		while (true) {
			int month = sc.nextInt();
			int day = sc.nextInt();

			if (month == 0) {
				break;
			}

			GregorianCalendar calendar = new GregorianCalendar(2004, month - 1,
					day);
			System.out
					.println(list[calendar.get(GregorianCalendar.DAY_OF_WEEK)]);
		}

	}

}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;


void solve()
{
	ll a, b, c, k;
	cin >> a >> b >> c >> k;

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

	cout << endl;
}

int main()
{
	fastio;
	solve();

	return 0;
}

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

int main() 
{int n;
cin>>n;
if(n%10==2||n%10==4||n%10==5|| n%10==7||n%10==9)
cout<<"hon";
else if(n%10==0||n%10==1||n%10==6|| n%10==8)
cout<<"pon";
else 
cout<<"bon";
    return 0;
}

Measured memory_bytes: 3636
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CToInfinity solver = new CToInfinity();
        solver.solve(1, in, out);
        out.close();
    }

    static class CToInfinity {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String input = in.next();
            long k = in.nextLong();

            int n = input.length();
            int[] s = new int[n];
            for (int i = 0; i < n; i++) {
                s[i] = input.charAt(i) - '0';
            }

            for (int i = 0; i < k; i++) {
                if (s[i] > 1) {
                    out.println(s[i]);
                    return;
                }
            }

            out.println(1);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}



Measured memory_bytes: 21460
#include <stdio.h>

typedef struct{
    int id;
    int parent;
    int sibling;
    int degree;
    int depth;
    int height;
}node;

int main(){
    int i,j,n,depmax=0,depth;
    int id,b;
    scanf("%d",&n);
    node ha[n];
    for(i=0;i<n;i++){
        ha[i].id=-1;
        ha[i].parent=-1;
        ha[i].sibling=-1;
        ha[i].degree=0;
        ha[i].depth=0;
        ha[i].height=0;
    }
    
    
    for(i=0;i<n;i++){
        scanf("%d",&id);
        ha[id].id=id;
        scanf("%d",&b);
        if(b!=-1){
            ha[id].degree++;
            ha[b].parent=id;
        }
        scanf("%d",&b);
        if(b!=-1){
            ha[id].degree++;
            ha[b].parent=id;
        }
    }
    
    //get status
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            if(ha[i].parent==ha[j].parent&&i!=j){
                ha[i].sibling=j;
                ha[j].sibling=i;
            }
        }
        b=i;
        depth=0;
        while(ha[b].parent!=-1){
            depth++;
            b=ha[b].parent;
            if(ha[b].height<depth)ha[b].height=depth;
        }
        ha[i].depth=depth;
        
    }
    
    
    for(i=0;i<n;i++){
        printf("node %d: ",i);
	printf("parent = %d, ",ha[i].parent);
	printf("sibling = %d, ",ha[i].sibling);
	printf("degree = %d, ",ha[i].degree);
	printf("depth = %d, ",ha[i].depth);
	printf("height = %d,",ha[i].height);
        if(ha[i].parent==-1)printf(" root\n");
        else if(ha[i].degree==0)printf(" leaf\n");
        else printf(" internal node\n");
        
    }
    return 0;
}



Measured memory_bytes: 2084
#include <stdio.h>

int main(void)
{
    int a, b, r, s, t, gcd, lcm;

    while (scanf("%ld %ld", &a, &b) != EOF) {
        r = a > b ? a : b;
        s = a < b ? a : b;
        while (r % s != 0) {
            t = r;
            r = s;
            s = t % r;
        }
        gcd = s;
        lcm = a * (b / gcd);
        printf("%d %d\n", gcd, lcm);
    }

    return 0;
}

Measured memory_bytes: 596
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	map<int, int> mc;
	int n, m;
	cin >> n >> m;
	mc[0] = 1;
	int sum = 0;
	LL ans = 0;
	while (n--)
	{
		int x;
		cin >> x;
		sum = (sum + x) % m;
		ans += mc[sum];
		mc[sum]++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3200
#include <cstdio>
#include <iostream>
#include <cmath>
#include <set>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
using namespace std;
typedef long long ll;
int main()
{
    //freopen("a.in","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k;cin>>k;
    queue<ll> que;
    for(int i=1;i<10;i++)que.push(i);
    while(--k){
    	ll now=que.front();que.pop();
    	if(now%10!=0){
    		que.push(now*10+now%10-1);
    	}
    	que.push(now*10+now%10);
    	if(now%10!=9){
    		que.push(now*10+now%10+1);
    	}
    }
    cout<<que.front()<<"\n";
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;

ll gcd(ll a, ll b){
  if(a%b == 0) return b;
  else return gcd(b,a%b);
}

int main(){
  ll A,B;
  cin >>A>>B;
  ll AB = gcd(A,B);
  ll stop = sqrt(AB);
  vector<int> fact(1,1);
  ll i = 2;
  while(AB>1){
    if(i > stop){
      fact.push_back(i);
      break;
    }
    if(AB%i == 0){
      fact.push_back(i);
      while(AB%i == 0) AB /= i;
    }else i ++;
  }
  cout << fact.size() << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    S = list(map(int, list(input())))
    S = S[::-1]
    n = len(S)
    mod = 2019

    A = [0] * n
    times = 1
    for i in range(n):
        A[i] = S[i] * times % mod
        times = times * 10 % mod

    # 累積和
    R = [0] * (n + 1)
    for i in range(n):
        R[i+1] = (R[i] + A[i]) % mod
    # print(R)
    cnt = {}
    ans = 0
    for i in range(n+1):
        r = R[i] % mod
        # print(r)
        ans = ans + cnt.get(r, 0)
        # cnt.setdefault(r, 0)
        # ans = ans + cnt[r]
        cnt[r] = cnt.get(r, 0) + 1
    # print(cnt)
    print(ans)

if __name__ == '__main__':
    solve()


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

int maximumpoints(int n,int arr[][3])
{
	int dp[n][3];

	dp[0][0]=arr[0][0];
	dp[0][1]=arr[0][1];
	dp[0][2]=arr[0][2];

	for(int i=1;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			if(j==0)
			{
				dp[i][j]=arr[i][j]+max(dp[i-1][j+2],dp[i-1][j+1]);
			}
			else if(j==1)
			{
				dp[i][j]=arr[i][j]+max(dp[i-1][j+1],dp[i-1][j-1]);
			}
			else
			{
				dp[i][j]=arr[i][j]+max(dp[i-1][j-2],dp[i-1][j-1]);
			}
		}
	}
    return max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}

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

	int arr[n][3];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
	}

	cout<<maximumpoints(n,arr);
}

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

using namespace std;

int main() {
    string str;
    
    set<char> char_set;
    cin >> str;

    for(char &s: str) {
        if (char_set.count(s) == 0) {
            char_set.insert(s);
        } else {
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

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

	int n, m;
	cin >> n >> m;

	vector<vector<int>> edge(n);
	int a, b;
	while (m--) {
		cin >> a >> b;
		a--; b--;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}

	vector<int> d(n, -1);
	vector<bool> visited(n, 0);
	queue<int> q;
	q.push(0);
	d[0] = 0;
	while (!q.empty()) {
		int now = q.front(); q.pop();
		for (int u: edge[now]) {
			if (!visited[u]) {
				visited[u] = 1;
				d[u] = d[now] + 1;
				q.push(u);
			}
		}
	}

	if (d[n - 1] == -1 || d[n - 1] > 2) cout << "IMPOSSIBLE";
	else cout << "POSSIBLE";
}

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

int main() {
  int a,b,c,A,B,C,kari,nazo;
  cin >> A >>B;
  
  if ( A%(B*2+1) == 0) 
  cout << A / (B*2+1) << endl;
  else
  cout << A / (B*2+1) + 1 << endl;
}

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

int main(void){
    vector<int> H(10010),W(10010);
    for(int i=0;i<10010;i++){
        cin>>H.at(i)>>W.at(i);
        if(H.at(i)==0 && W.at(i)==0)break;
        for(int j=0;j<H.at(i);j++){
            if(j==0 || j==H.at(i)-1)
            for(int k=0;k<W.at(i);k++){
                cout<<'#';
            }
            else{
                cout<<'#';
                for(int l=0;l<W.at(i)-2;l++){
                    cout<<'.';
                }
                cout<<'#';
            }
            cout<<endl;
        }
        cout<<endl;
    }
}



Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mem(arr,v) memset(arr,v,sizeof(arr))
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
int main()
{
     ll m,n,kk;
     cin>>m>>n;
     kk=m*n;
     if(m==1|| n==1)
        cout<<"1"<<endl;
     else if(kk%2==0)
        cout<<kk/2<<endl;
     else
        cout<<kk/2+1<<endl;

}




Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
#include <iostream>
using namespace std;
void Attention() {
	int N;
	string S;
	cin >> N;
	cin >> S;
	int wcount = 0;
	for (size_t i = 0; i < N; i++)
	{
		wcount += S[i] == 'W';
	}
	int etw = N - wcount - (S[0] == 'E');
	int wte = 0;
	int r = etw;
	for (size_t i = 1; i < N; i++)
	{
		if (S[i - 1] == 'W') {
			wte++;
		}
		if (S[i] == 'E') {
			etw--;
		}
		r = min(wte + etw,r);
	}
	cout << r;
}
int main() {
	Attention();
	return 0;
}

Measured memory_bytes: 900
#include<stdio.h>

void trance(int A[], int N, int count){
	int i;
	for( i =0; i < N; i++ ){
		if( i > 0 ) printf(" ");
		printf("%d", A[i]);
	}
	printf("\n");
	printf("%d\n",count);
}

int bubbleSort(int A[], int N, int count){
	int i,v;
	int sum;
	sum = count;
	for(i=N-1;i>0;i--){
		if(A[i]<A[i-1]){
			v=A[i];
			A[i]=A[i-1];
			A[i-1]=v;
			sum++;
		}
	}
	return sum;
}

int main(void){
	int i,A[100],N,count=0;
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	for(i=0;i<N;i++){
		count = bubbleSort(A,N,count);
	}
	trance(A,N,count);
	return 0;
}

Measured memory_bytes: 604
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    if(s=="hi"||s=="hihi"||s=="hihihi"||s=="hihihihi"||s=="hihihihihi"){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(3e2) + 17;

int n, pp;
int a[MAXN];
double dp[(int) 5e7];
bool used[(int) 5e7];
unordered_map<long long, int> pos;

bool read() {
    if (!(cin >> n))
        return false;

    forn (i, n)
        cin >> a[i];

    return true;
}

int getp(int a, int b, int c) {
    if (!pos.count((ll) 1e6 * a + (ll) 1e3 * b + c))
        pos[(ll) 1e6 * a + (ll) 1e3 * b + c] = pp++;

    return pos[(ll) 1e6 * a + (ll) 1e3 * b + c];
}

void dfs(int a, int b, int c) {
    int p = getp(a, b, c);

    if (used[p])
        return ;

    if (a == 0 && b == 0 && c == 0)
        return ;

    used[p] = true;

    if (a > 0) dfs(a - 1, b, c);
    if (b > 0) dfs(a + 1, b - 1, c);
    if (c > 0) dfs(a, b + 1, c - 1);

    dp[p] = n;
    
    if (a > 0)
        dp[p] += a * dp[getp(a - 1, b, c)];

    if (b > 0)
        dp[p] += b * dp[getp(a + 1, b - 1, c)];

    if (c > 0)
        dp[p] += c * dp[getp(a, b + 1, c - 1)];

    dp[p] /= a + b + c;
}

void solve() {
    int A = count(a, a + n, 1);
    int B = count(a, a + n, 2);
    int C = count(a, a + n, 3);
    dfs(A, B, C);
    cout << setprecision(12) << fixed << dp[getp(A, B, C)] << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
#ifdef SEREZHKA
    freopen("file.in", "r", stdin);
#endif
    
    while (read())
        solve();
    
    return 0;
}



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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;

int main() {
  ll n, r;
  cin >> n >> r;
  ll ans;
  if (n < 10) {
    ans = r + 100 * (10 - n);
  } else {
    ans = r;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
ks = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2**n):
    l = [False] * n
    for j in range(n):
        if (i>>j) & 1:
            l[j] = True
    for j in range(m):
        if [l[k-1] for k in ks[j][1:]].count(True) % 2 != p[j]:
            break
    else:
        ans += 1
print(ans)

Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
#define ll long long  
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int main()
{   
    fast();
    int t=1;
    //cin>>t;
    while(t--)
    {
      int n,cnt=0,r=0,w=0;
      cin>>n;
      string s,t;
      cin>>s;
      for(int i=0;i<n;i++)
      {
         if(s[i]=='R')r++;
         else w++;
      }
      for(int i=0;i<r;i++) t.push_back('R');
      for(int i=0;i<w;i++) t.push_back('W');
      for(int i=0;i<n;i++)
      {
         if(s[i]!=t[i])
            cnt++;
      }
      cout<<cnt/2<<endl;
    }

  return 0;
}

Measured memory_bytes: 3852
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
using namespace std;

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

int selectSort(int a[], int n)
{
    int mini, cnt = 0;
    for (int i = 0; i < n; i++)
    {
        mini = i;
        for (int j = i + 1; j < n; j++)
        {
            if (a[mini] > a[j])
            {
                mini = j;
            }
        }
        if (mini != i)
        {
            swap(a[mini], a[i]);
            cnt++;
        }
    }
    return cnt;
}

int main()
{
    int n, p[55] = {}, cnt = 0;
    cin >> n;
    rep(i, n) cin >> p[i];
    cnt = selectSort(p, n);
    if (cnt >= 2)
    {
        printf("NO\n");
    }
    else
    {
        printf("YES\n");
    }

    // rep(i, n)
    // {
    //     if (i)
    //         cout << " ";
    //     cout << p[i];
    // }
    // cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,a[200005];
inline bool check(int x)
{
	if(x==1)
	{
		bool ch=true;
		for(int i=0;i<n-1;i++)
		{
			if(a[i+1]<=a[i])
			{
				ch=false;
			}
		}
		return ch;
	}
	map<int,int> mp;
	int cnt=-1;
	for(int i=0;i<n;i++)
	{
		if(a[i]<=cnt)
		{
			cnt=a[i];
			while(1)
			{
				if(mp[cnt]<x-1)
				{
					break;
				}
				mp[cnt]=0;
				cnt--;
			}
			mp[cnt]++;
			if(cnt<=0)
			{
				return false;
			}
		}
		else
		{
			cnt=a[i];
		}
		mp.erase(mp.upper_bound(cnt),mp.end());
	}
	return true;
}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int l=1,r=200005,ans;
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if(check(mid))
		{
			ans=mid,r=mid-1;
		}
		else
		{
			l=mid+1;
		}
	}
	cout<<ans;
	return 0;
}

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

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

        try {
            c = System.in.read();
        } catch (IOException e) {
            System.err.println(e.getMessage());
        }

        int i = 1;
        while (getToken() == TK_NUM && num != 0) {
            System.out.printf("Case %d: %d\n", i++, num);
        }
    }

    private static final int TK_END = 1;
    private static final int TK_NUM = 2;

    private static int c;
    private static int num;

    public static int getToken() {
        try {
            if (c == -1) {
                return TK_END;
            } else if (Character.isDigit(c)) {
                num = Character.getNumericValue(c);
                while (Character.isDigit(c = System.in.read()))
                    num = num * 10 + Character.getNumericValue(c);
                return TK_NUM;
            }
            while ((c = System.in.read()) != -1 && !Character.isDigit(c))
                    ;
        } catch (IOException e) {
            System.err.println(e.getMessage());
        }
        return getToken();
    }
}

Measured memory_bytes: 58236
#pragma region

#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;
typedef long long ll;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "vec[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

const int MAX = 510000;
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;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  COMinit();

  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  cin >> A;

  sort(rall(A));

  ll ans = 0;

  rep(i, N - K + 1) {
    ll c = COM(N - i - 1, K - 1);
    ans = (ans + c * A[i]) % MOD;
    ans = mod(ans - c * A[N - i - 1], MOD);
  }

  out(ans);
}


Measured memory_bytes: 13056
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

int main(){
    int N, x;
    cin >> N >> x;

    if(x == 1 || x == 2 * N - 1){
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    int n = 2*N - 1;
    vector<int> ans(n, 0);
    if (N == 2){
        ans = {1, 2, 3};
    }else{
        int nd = n / 2;
        int l, r;
        if(x+2 <= n){
            ans[nd-1] = x+1;
            ans[nd] = x-1;
            ans[nd+1] = x;
            ans[nd+2] = x+2;
            l = x-1;
            r = x+2;
        }else{
            ans[nd-1] = x-1;
            ans[nd] = x+1;
            ans[nd+1] = x;
            ans[nd+2] = x-2;
            l = x-2;
            r = x+1;
        }

        int k = 1;
        for(int i=0;i<n;i++){
            while(l <= k && k <= r) k++;
            if(ans[i] == 0) ans[i] = k++;
        }
    }

    for(int i=0;i<n;i++){
        cout << ans[i] << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long llint;
typedef complex <double> cd;
typedef pair <int, int> pi;

const int P = 200003;
const double PI = acos(-1);

int add (int x, int y) {x += y; if (x >= P) return x - P; return x;}
int sub (int x, int y) {x -= y; if (x < 0) return x + P; return x;}
int mul (int x, int y) {return (llint) x * y % P;}

llint n, sol;
int cnt[P], ex[P], pot[P];

void precompute () {
    int curr = 1;
    for (int i = 0; i < P-1; i++) {
        ex[curr] = i;
        pot[i] = curr;
        curr = mul(curr, 2);
    }
}

void fft (vector <cd> &v, bool flg) {
    int n = v.size();
    if (n == 1) return;

    vector <cd> a0(n / 2), a1(n / 2);
    for (int i = 0; i < n / 2; i++) {
        a0[i] = v[2 * i];
        a1[i] = v[2 * i + 1];
    }
    fft(a0, flg); fft(a1, flg);

    double ang = 2 * PI / n * (flg == 0 ? 1 : -1);
    cd w(cos(ang), sin(ang)), curr = 1;
    for (int i = 0; i < n/2; i++) {
        v[i] = a0[i] + curr * a1[i];
        v[i + n/2] = a0[i] - curr * a1[i];
        if (flg) v[i] /= 2, v[i + n/2] /= 2;
        curr *= w;
    }
}

void mult (vector <cd> a, vector <cd> b) {
    int n = a.size(), siz = 1;
    while (siz < n) siz *= 2; siz *= 2;
    vector <cd> fa(siz), fb(siz);
    for (int i = 0; i < n; i++) fa[i] = a[i], fb[i] = b[i];

    fft(fa, 0);
    fft(fb, 0);
    for (int i = 0; i < siz; i++) fa[i] *= fb[i];
    fft(fa, 1);

    for (int i = 0; i < siz; i++) {
        llint val = pot[i % (P-1)];
        sol += round(fa[i].real()) * val;
    }
}

void solve () {
    vector <cd> v(P-1);
    for (int i = 0; i < P-1; i++) {
        v[i] = cnt[pot[i]];
    }
    mult(v, v);
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        llint val; cin >> val;
        sol -= val * val % P;
        cnt[val]++;
    }
    precompute();
    solve();
    cout << sol / 2;
    return 0;
}


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

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

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>

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

using namespace std;

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

const int N = 100001;

ll n;
ll A[N];
ll B[N];

int main() {

    cin >> n;
    REP(i, n + 1) {
        cin >> A[i];
    }
    REP(i, n) {
        cin >> B[i];
    }
    ll ans = 0;
    REP(i, n) {
        ans += min(A[i], B[i]);
        B[i] -= min(A[i], B[i]);

        ans += min(A[i+1], B[i]);
        A[i+1] -= min(A[i+1], B[i]);
    }

    cout << ans;

    return 0;
}


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

using namespace std;
#define ll long long

ll mat(ll a, ll b) {
    ll res = ceil(sqrt((a*a)+(b*b)));
    return res;
}

int main() {
    int n;
    int d;
    cin >> n >> d;
    vector<pair<ll, ll>> v(n);
    for (int i = 0; i<n;i++) {
        cin >> v[i].first >> v[i].second;
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if(d >= mat(v[i].first, v[i].second)) {
            cnt++;
        }
    }
    cout << cnt;
    return 0;
}

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

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

  int b,f,v,r;
  int count[4][3][10] = {0};

  rep(i,n){
    cin >> b >> f >> r >> v;
    int bin = b-1;
    int fin = f-1;
    int rin = r-1;

    count[bin][fin][rin] += v;
  }

    rep(j,4){
      rep(k,3){
        rep(m,10){
            cout << " " << count[j][k][m] ; 
        }
        cout << endl;
      }
    if(j != 3){
    rep(num,20) cout <<"#";
    cout << endl;
    }  
    }
}


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

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

typedef long long ll;
typedef long long int64;

int main() {
  int p,q,r;
  cin >> p >> q >> r;

  int m = max({p,q,r});

  cout << p + q + r - m << endl;

  return 0;
}


Measured memory_bytes: 256