akhauriyash/Code-Regression huggingface dataset:
def main():
    N, Q = map( int, input().split())
    C = list( map( int, input().split()))
    LRI = []
    for i in range(Q):
        l, r = map( int, input().split())
        LRI.append((r,l,i))
    LRI.sort(key=lambda x:x[0])
    lastAppend = [-1]*(N+1)
    BIT = [0]*(N+1)
    #A1 ~ Aiまでの和 O(logN)
    def BIT_query(idx):
        res_sum = 0
        if idx == 0:
            return 0
        while idx > 0:
            res_sum += BIT[idx]
            idx -= idx&(-idx)
        return res_sum

    #Ai += x O(logN)
    def BIT_update(idx,x):
        while idx <= N:
            BIT[idx] += x
            idx += idx&(-idx)
        return

    ANS = [0]*Q
    now = 1
    for r, l, i in LRI:
        while now <= r:
            c = C[now-1]
            if lastAppend[c] == -1:
                BIT_update(now, 1)
            else:
                BIT_update( now, 1)
                BIT_update(lastAppend[c],-1)
            lastAppend[c] = now                
            now += 1
        ANS[i] = BIT_query(r) - BIT_query(l-1)
    print( "\n".join( map( str, ANS)))
    
    

if __name__ == '__main__':
    main()


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

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 10000000000;
const ll MOD = 1000000007;

using namespace std;

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	long long g = gcd(a, b);
	return a / g * b;
}

int main() {
	string o, e; cin >> o >> e;

	for (int i = 0; i < o.size(); i++) {
		cout << o[i];
		if (i < e.size()) {
			cout << e[i];
		}
	}
}


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

int main(){
    int deg[110];

    int a, b;
    while(cin >> a >> b){
        fill(deg, deg+110, 0);

        if(a+b != 0){deg[a]++; deg[b]++;}
        else return 0;

        while(cin >> a >> b, a+b != 0){
            deg[a]++; deg[b]++;
        }
        bool odd = false;
        for(int i=3; i < 110; i++){
            if(deg[i] % 2 ==1){
                odd = true;
            }
        }
        if(deg[1] % 2 == 0 || deg[2] % 2 == 0 || odd) cout << "NG" << endl;
        else cout << "OK" << endl;
    }
}

Measured memory_bytes: 1156
a = list(map(int,input().split()))
 

b = list(map(int,input().split()))
c = list(map(int,input().split()))

b.append(a[2])
c.append(a[3])

b.sort()
c.sort()
if b[-1] < c[0]:
	print("No War")
else:
	print("War")

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

string s, t;
int dp[1000][1000];

void solve() {
    cin >> s >> t;
    for (int i = 0; i < s.size(); i++) {
        for (int j = 0; j < t.size(); j++) {
            dp[i][j] = (i < 1 || j < 1 ? 0 : dp[i-1][j-1]) + (s[i] == t[j] ? 1 : 0);
            int a = (i < 1 ? 0 : dp[i-1][j]);
            int b = (j < 1 ? 0 : dp[i][j-1]);
            dp[i][j] = max(dp[i][j], max(a, b));
        }
    }

    cout << dp[s.size()-1][t.size()-1] << endl;
}

int main() {
    int n;
    cin >> n;
    while (n--) solve();

    return 0;
}

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

vector<int> diff(2);
void diffgene(int a, int b, int c) {
  diff.at(0) = a - b;
  diff.at(1) = b - c;
}

vector<int> input() {
  vector<int> vec(3);
  for (int i = 0; i < 3; i++) {
    cin >> vec.at(i);
  }
  return vec;
}

int main() {
  vector<int> A1,A2,A3;
  A1 = input();
  A2 = input();
  A3 = input();
  
  int n = 0;
  
  vector<int> A1diff(2);
  vector<int> A2diff(2);
  vector<int> A3diff(2);
  vector<int> B1diff(2);
  vector<int> B2diff(2);
  vector<int> B3diff(2);
  
  diffgene(A1.at(0), A1.at(1), A1.at(2));
  A1diff = diff;
  
  diffgene(A2.at(0), A2.at(1), A2.at(2));
  A2diff = diff;
  
  diffgene(A3.at(0), A3.at(1), A3.at(2));
  A3diff = diff;
  
  diffgene(A1.at(0), A2.at(0), A3.at(0));
  B1diff = diff;
  
  diffgene(A1.at(1), A2.at(1), A3.at(1));
  B2diff = diff;
  
  diffgene(A1.at(2), A2.at(2), A3.at(2));
  B3diff = diff;
  
  if (A1diff != A2diff || A2diff != A3diff || B1diff != B2diff || B2diff != B3diff) n++;
  
  if (n) cout << "No" << endl;
  else cout << "Yes" << endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

x = 0
y = 0
for i in range(n):
  t = min(a[i], x)
  y += t
  a[i] -= t
  if b[i] > a[i]:
    y += a[i]
    x = b[i]-a[i]
  else:
    y += b[i]
    x = 0
  
t = min(a[n], x)
y += t
print(y)
  

Measured memory_bytes: 19116
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <bitset>
using ll = long long;
using namespace std;
constexpr ll INF = 1LL << 60;


string s;

int main() {
	cin >> s;
	int n = (int)s.size();
	string t = s.substr(0, (n - 1) / 2);
	string u = s.substr(n / 2 + 1, (n - 1) / 2);
	string rs = s;
	string rt = t;
	string ru = u;
	reverse(rs.begin(), rs.end());
	reverse(rt.begin(), rt.end());
	reverse(ru.begin(), ru.end());
	if (s == rs && t == rt && u == ru) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	return 0;
}

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

float calcConcentration(int water, int sugar)
{
    if (water + sugar == 0)
    {
        return 0;
    }
    return 100 * sugar / (water + sugar);
}

int main()
{
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    pair<int, int> ans = make_pair(0, 0);

    for (int i = 0; i <= F / (100 * A); i++)
    {
        int f_a = F - (100 * A * i);
        for (int j = 0; j <= f_a / (100 * B); j++)
        {
            int water_coef = A * i + B * j;
            int e_available = min(E * water_coef, F - 100 * water_coef);
            int e_val = 0;
            for (int k = 0; k <= e_available / C; k++)
            {
                e_val = max(e_val, C * k + ((e_available - C * k) / D) * D);
            }
            // if (calcConcentration(water_coef * 100, e_val) > calcConcentration(ans.first - ans.second, ans.second))
            if (e_val * ans.first >= (water_coef * 100 + e_val) * ans.second)
            {
                ans = make_pair(water_coef * 100 + e_val, e_val);
            }
        }
    }

    cout << ans.first << " " << ans.second << endl;

    return 0;
}

Measured memory_bytes: 256
d, g = list(map(int, input().split()))
spc = []
for s in range(100, d * 100 + 1, 100):
    p, c = list(map(int, input().split()))
    spc.append([s, p, c + s * p])

from itertools import product
ans = float('inf')
for comps in product(range(2), repeat=d):
    cnt = sum(p * x for (s, p, c), x in zip(spc, comps))
    scr = sum(c * x for (s, p, c), x in zip(spc, comps))
    if scr >= g:
        if cnt < ans:
            ans = cnt
        continue
    for (s, p, c), x in zip(spc, comps):
        if x or s * (p - 1) + scr < g:
            continue
        cnt += -((scr - g) // s)
        if cnt < ans:
            ans = cnt

print(ans)

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

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

const int limit=50;

int n,m;

int a[limit],b[limit];
bool visited[limit];
bool graph[limit][limit];

void dfs(int v){
    visited[v]=true;
    for(int v2=0;v2<n;v2++){
        if(graph[v][v2]==false) continue;
        if(visited[v2]==true) continue;
        dfs(v2);
    }
}

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

    for(int i=0;i<m;i++){
        cin >> a[i] >> b[i];
        a[i]--;b[i]--;
        graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
    }

    int ans=0;
    for(int i=0;i<m;i++){
        graph[a[i]][b[i]]=graph[b[i]][a[i]]=false;

        for(int j=0;j<n;j++) visited[j]=false;

        dfs(0);

        bool isBrige=false;
        for(int j=0;j<n;j++) if(visited[j]==false) isBrige=true;
        if(isBrige) ans++;

        graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
    }
    p(ans)
    return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)

int main(){
    
    // 1. 入力情報.
    int N, A, B;
    scanf("%d %d %d", &N, &A, &B);
    
    // 2. 最大で何回のコンテストを開催できるか？
    int ans = 0, a = 0, b = 0, c = 0, p;
    rep(i, N){
        scanf("%d", &p);
        if(p <= A)               a++;
        if(p >= A + 1 && p <= B) b++;
        if(p >= B + 1)           c++;
    }
    
    // 3. 出力.
    printf("%d\n", min({a, b, c}));
    return 0;
    
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll a,b;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>a>>b;
    if((a+b)%2==0){
        print((a+b)/2);
    }else{
        print("IMPOSSIBLE");
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ar array
#define pb push_back
#define input(arr,n) for(int i = 0; i<n; i++) cin>>arr[i]
const int mod = 1e9+7;
ll power(ll a,ll b){ll r=1;for(;b;b>>=1){if(b&1)r=r*a%mod;a=a*a%mod;}return r;}
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n; string s;
	cin>>n>>s;
	int i = s.length()-1;
	for(; i>=0; i--)
		if(s[i]=='R') break;
	int h = 0,r1 = count(s.begin(),s.end(),'R'),w1 = count(s.begin(), s.end(),'W');
	for(int j = 0; j<n; j++)
	{
		if(r1==0 || w1==0) break;
		if(s[j]=='W') h++,r1--,w1--;
		else r1--;
	}

	int r = count(s.begin(),s.begin()+i+1,'R');
	int w = count(s.begin(),s.begin()+i+1,'W');
	cout<<min({r,w,h})<<endl;
	return 0;
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(vec) vec.begin(),vec.end()
#define rep(i,n) for(int i = 0;i<n;++i)
#define repc(bit,k,n) for (ll bit = (1<<k)-1;bit < (1<<n); bit = next_combination(bit))
#define repi(itr,vec) for(auto itr = vec.begin();itr!=vec.end();++itr)
using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;cin>>n;
  vector<pair<int,int> >p(n);
  rep(i,n){
    int a,b;cin>>a>>b;
    p[i] = make_pair(a,b);
  }
  sort(ALL(p), [](const pair<int,int> &a, const pair<int,int> &b){return a.first+a.second>b.first+b.second;});
  ll ans = abs(p[0].first- p.back().first)+abs(p[0].second-p.back().second);
  sort(ALL(p), [](const pair<int,int> &a, const pair<int,int> &b){return a.first-a.second>b.first-b.second;});
  ans = max(ans, (ll)abs(p[0].first- p.back().first)+(ll)abs(p[0].second-p.back().second));
  cout<< ans<<endl;


  return 0;
}

Measured memory_bytes: 4756
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
const int MAX = 1e6+10;
const int MOD = 1e9+7;
ll fac[MAX], finv[MAX], inv[MAX];

void comInit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    reps(i,2,MAX){
        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;
}

int main(){
    int x,y;
    cin >> x >> y;
    
    comInit();

    if(((x + y) % 3) != 0){
        cout << 0 << endl;
        return 0;
    }else{
        cout << COM((x+y)/3,x-(x+y)/3) << endl;;
    }

    return 0;
}

Measured memory_bytes: 23680
import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {
	private static int X = 600;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		ArrayList<Long> results = new ArrayList<Long>();
		
		try{
			while(true){
				int d = sc.nextInt();
				int  n = getNumRectangle(d);
				long area = 0;
				for(int i = 0; i < n; i++){
					area += getArea(d, i);
				}
				results.add(area);
			}
		}catch(NoSuchElementException e){
			//½àµÈ¢
		}
		
		//ÊXgÌoÍ
		for(int i = 0; i < results.size(); i++){
			System.out.println(results.get(i));
		}
	}
	private static long getArea(int d, int n){
		int tmp = n * d;
		int height = tmp * tmp;
		return height * d;
	}
	
	private static int getNumRectangle(int d){
		return X / d;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
using namespace std;

int N, K, M;

int main(void) {
  while(cin >> N >> K >> M, N || K || M) {
    vector<int> v;
    REP(i, 1, N + 1) v.push_back(i);
    int m = M - 1;
    while(v.size() > 1) {
      v.erase(v.begin() + m);
      m = (m + K - 1 + v.size()) % v.size();
    }
    cout << v[0] << endl;
  }

  return 0;
}

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

int main(){

	int K;
  	cin >> K;
  	int c,d;
  	c = 0;
  	d = 0;
  
	for(int i = 0; i < K; i++){
      
		if(i%2==0)c++;
      	if(i%2==1)d++;
      
    }
  
  
  	cout << c*d << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
int a[SIZE],b[SIZE];
int main(){
    DRI(N);
    REP(i,N)RII(a[i],b[i]);
    LL an=0;
    for(int i=N-1;i>=0;i--){
        LL x=a[i]+an;
        an+=(((x+b[i]-1)/b[i])*b[i])-x;
    }
    cout<<an<<endl;
    return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Queue;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] strArray = br.readLine().split(" ");
		
		int n = Integer.parseInt(strArray[0]);
		int q = Integer.parseInt(strArray[1]);
		
		Queue<Process> queue = new ArrayDeque<Process>();
		for(int i = 0; i < n ;i++){
			strArray = br.readLine().split(" ");
			queue.add(new Process(strArray[0], Integer.parseInt(strArray[1])));
		}
		
		int currentTime = 0;
		while(queue.size() > 0){
			if(queue.element().remainTime > q){
				queue.element().remainTime -= q;
				queue.add(queue.poll());
				currentTime += q;
			}
			else{
				currentTime += queue.element().remainTime;
				System.out.println(queue.element().name + " " + currentTime);
				queue.poll();
			}
			
		}
	}

}

class Process {
	String name;
	int remainTime;
	int finishedTime;
	
	public Process (String name, int time){
		this.name = name;
		this.remainTime = time;
	}
}

Measured memory_bytes: 61336
#include <iostream>
#include <queue>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

#define rep(i,n) for(int i=0;i<(n);++i)
const int MOD = 1e9+7,
      MAX_N = 1e5+1,
      MAX = 1e5+1;
ll fac[MAX], finv[MAX], inv[MAX];

void comb_init() {
  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 comb(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;
}


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

  comb_init();
  vvi edge(N, vi());
  bool visited[N];
  rep(i, N-1) {
    int a, b; cin >> a >> b;
    --a, --b;
    edge[a].push_back(b);
    edge[b].push_back(a);
    visited[i] = false;
  }
  visited[N-1] = false;

  queue<int> q;
  q.push(0);
  ll ans = K;
  while (!q.empty()) {
    int from = q.front(); q.pop();
    visited[from] = true;

    int child = edge[from].size()-1;
    if (from == 0) ++child;

    for (const auto& to : edge[from]) {
      if (!visited[to])
        q.push(to);
    }
    if (from == 0) ans *= comb(K-1, child) * fac[child] % MOD;
    else ans *= comb(K-2, child) * fac[child] % MOD;

    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 8952
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 2*acos(0.0)
#define f first
#define s second
#define pb push_back
#define gap ' '
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mod 1000000007
#define N 1005

int main()
{
    int n;
    cin>>n;
    for(int i=1000;i<=10000;i+=1000)
    {
        if(i>=n)
        {
            cout<<i-n<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3632
import bisect

N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

total = 0

for b in B:
    i = N - bisect.bisect_right(C, b)
    j = bisect.bisect_left(A, b)
    total += i * j

print(total)

Measured memory_bytes: 23200
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#include <algorithm>
#define mp make_pair
#define fi first
#define se second
#define fzhead EDGE(int _to, int _val, int _next)
#define fzbody to(_to), val(_val), next(_next)
#define mst(x,a) memset(x,a,sizeof(x))
#define For(i,x,y) for( int i=(x); i<=(y); i++)
using namespace std;
const int maxm=2e5+10;
const int maxn=1e5+10;
const int INF=0x3f3f3f3f;
typedef pair<int,int>pa;
struct EDGE
{
    int to,val,next;
    EDGE(){}
    fzhead:fzbody{}
}e[maxm<<1];
int cnt,head[maxn],vis[maxn];
int n,m;
int sign[maxn];
void add(int bg, int to, int val)
{
    e[++cnt]=EDGE(to,val,head[bg]);
    head[bg]=cnt;
}
int main()
{
    mst(head,-1);
    scanf("%d%d", &n,&m);
    For(i,1,m)
    {
        int a,b;
        scanf("%d%d", &a,&b);
        add(a,b,1);add(b,a,1);
    }
    queue<int>q;
    q.push(1);
    while(!q.empty())
    {
        int u=q.front();q.pop();
        for(int i=head[u]; i!=-1; i=e[i].next)
        {
            int v=e[i].to;
            if(!sign[v])
            {
                sign[v]=u;
                q.push(v);
            }
        }
    }
    cout<<"Yes"<<endl;
    For(i,2,n)cout<<sign[i]<<endl;
    return 0;
}
/*
    queue<int>q;
    dis[s]=0;
    q.push(1);
    while(!q.empty())
    {
        int u=q.front();q.pop();
        for(int i=head[u]; i!=-1; i=e[i],next)
        {
            int v=e[i].to,w=e[i].val;
            if(dis[v]>dis[u]+w)
            {
                dis[v]=dis[u]+w;
                q.push(v);
                vis[v]++;
                if(vis[v])
            }
        }
    }
*/


Measured memory_bytes: 9308
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}


signed main(void) {
    string s,t;
    cin >> s >> t;
    int n = s.size();
    rep(i,n){
        bool c = true;
        rep(j,n)if(s[(i+j)%n] != t[j])c = false;
        if(c){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


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

#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcd(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

vvt<int> edge;
vt<int> dp;

int rec(int v) {
  if(dp[v] != -1) return dp[v];

  int res = 0;
  for(auto nxt : edge[v]) {
    res = max(res, rec(nxt) + 1);
  }
  return dp[v] = res;
}

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

  int n, m;
  cin >> n >> m;
  dp = vt<int>(n, -1);
  edge = vvt<int>(n);
  rep(i, 0, m) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    edge[x].push_back(y);
  }

  int ans = 0;
  rep(v, 0, n) ans = max(ans, rec(v));
  cout << ans << endl;
}

Measured memory_bytes: 8192
#include <iostream>
using namespace std;
int main(){
	int i,j,k,p,n,m;
	cin>>n>>m;
	for(i=0;i<=n;i++){
		for(j=0;i+j<=n;j++){
			 k=n-i-j;
			 if(i*10000+j*5000+k*1000==m){
				cout<<i<<" "<<j<<" "<<k<<endl;
				return 0;
			} 
		}
	}
	cout<<-1<<" "<<-1<<" "<<-1<<endl;
}

Measured memory_bytes: 256
# frozen_string_literal: true

n = gets.to_i

MOD = 10**9 + 7

if n == 1
  puts 0
  exit
end

# nP2 * 10**(n - 2)

s = 1
n.times do
  s *= 10
  s %= MOD
end

z = 2
n.times do
  z *= 9
  z %= MOD
end

e = 1
n.times do
  e *= 8
  e %= MOD
end

puts (s - z + e) % MOD


Measured memory_bytes: 14364
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;

int dfs(int cur, int d, int g, int sum, int cnt, vector<int>& p, vector<int>& c, vector<int>& a)
{
    if(cur == d)
    {
        if(sum >= g)
            return cnt;
        for(int i=d-1;i>=0;--i)
        {
            if(a[i]*(i+1)*100 + sum < g)
            {
                sum += a[i]*(i+1)*100;
                cnt += a[i];
            }
            else
            {
                int c = (g-sum) / ((i+1)*100);
                if((g-sum)%((i+1)*100) != 0)
                    c++;
                sum += c*(i+1)*100;
                cnt += c;
                break;
            }            
        }
        if(sum < g)
            cnt = INF;
        return cnt;
    }

    a[cur] = p[cur] - 1;
    int cnt0 = dfs(cur+1,d,g,sum,cnt,p,c,a);
    a[cur] = 0;
    sum += p[cur]*(cur+1)*100 + c[cur];
    cnt += p[cur];
    int cnt1 = dfs(cur+1,d,g,sum,cnt,p,c,a);

    return min(cnt0,cnt1);
}

int main()
{
    int d,g;
    cin >> d >> g;
    vector<int> p(d);
    vector<int> c(d);
    rep(i,d) cin >> p[i] >> c[i];
    vector<int> a(d);
    rep(i,d) a[i] = 0;
    cout << dfs(0,d,g,0,0,p,c,a) << endl;
    return 0;
}

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

int main(){
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	int has=a-b;
	if(n==1)printf("Borys\n");
	else{
		if(has<0)has*=-1;
		if(has%2==0)printf("Alice\n");
		else printf("Borys\n");	
	}
	
}

Measured memory_bytes: 256
/**********************
 * Author: Cloud_     *
 * Date:   27.06.2020 * 
 * Time:   18.33.28   *
 *                    *
***********************/
#include <bits/stdc++.h>
using namespace std;

#define gap " "
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ok cout<<"ok"<<endl
#define dbg(x) cout<<(#x)<<" is "<<x<<endl
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int N=10000009;
int d[N];

ll fn(ll n)
{
	int i,j;

	ll sum=0;
	for(i=1; i<=n; i++)
	{
		for(j=i; j<=n; j+=i)
		{
			d[j]++;
		}
		sum+=(d[i]*1ll*i);
	}

	return sum;
}
int main()
{
  //fastio; 
  ll n,ans;
  scanf("%lld",&n);
  ans=fn(n);
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 42748
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
  }
}init;


int main(){
  int N;
  while(cin >> N){
    cout << N*N*N << endl;
  }


  return 0;
}


Measured memory_bytes: 256
/* ****revpro**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl	   '\n'
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)    
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mii	    map<ll,ll>
using namespace std;

#define N  1005
ll n,m,cnt=0;
vector <pii> a[N][N];
ll in[N][N];
ll ans[N][N],tmp;
vector <pii> order;
vector <pii> nextnode;

void topsort()
{
	rep(i,1,n+1)
		rep(j,i+1,n+1)
			if(in[i][j]==0) nextnode.pb({i,j}),ans[i][j]=1;
	while(!nextnode.empty())
	{
		pii cur=nextnode.back();
		nextnode.pop_back();
		order.pb(cur);
		cnt++;
		for(auto i:a[cur.F][cur.S])
		{
			ans[i.F][i.S]=max(ans[cur.F][cur.S]+1,ans[i.F][i.S]);
			tmp=max(tmp,ans[i.F][i.S]);
			in[i.F][i.S]--;
			if(!in[i.F][i.S])
				nextnode.pb(i);
		}
	}
	if(cnt!=n*(n-1)/2) //Failed cycle
	{
		tmp=-1;
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		cin>>n;
		ll a1[n+1][n-1];
		rep(i,1,n+1)
		{
			rep(j,0,n-1){
				cin>>a1[i][j];
			}
		}
		rep(i,1,n+1){
			rep(j,1,n-1){
				a[min(i,a1[i][j])][max(i,a1[i][j])].pb({min(i,a1[i][j-1]),max(i,a1[i][j-1])});
				in[min(i,a1[i][j-1])][max(i,a1[i][j-1])]++;
			}
		}
		topsort();
		cout<<tmp;
	}
	return 0;
}

Measured memory_bytes: 82924
mod=1e9+7
n=input()
s1=raw_input()
s2=raw_input()
if s1[0]==s2[0]:
	r=3
	i=1
	prev=True
else:
	assert s1[0]==s1[1]!=s2[0]==s2[1]
	r=6
	i=2
	prev=False
while i<n:
	if s1[i]==s2[i]:
		if prev:
			r=r*2%mod
		i+=1
		prev=True
	else:
		assert s1[i]==s1[i+1]!=s2[i]==s2[i+1]
		if prev:
			r=r*2%mod
		else:
			r=r*3%mod
		i+=2
		prev=False
print int(r)

Measured memory_bytes: 2692
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;

int main(){
	int n,d,x,ans=0;
	cin>>n>>d>>x;
	vector<int> a(10000000);
	for(int i=0;i<n;i++){
		cin>>a[i];
		ans+=(d-1)/a[i]+1;
	}
	ans+=x;
	cout<<ans<<endl;
	return 0;
}

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

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



int main(){
    int n,m;
    cin >> n >> m;
    vector<int> h(n);
    vector<int> good(n,1);
    rep(i,n) cin >> h[i];
    
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--;b--;
        if (h[a] > h[b]){
            good[b] = 0;
        }
        else if(h[a] < h[b]){
            good[a] = 0;
        }
        else{
            good[a] = 0; good [b] = 0;
        }

        
    }
        int ans = 0;
        rep(i,n){
            ans += good[i];
        }
    cout << ans;

}





Measured memory_bytes: 4052
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<double>;
using VecS = vector<string>;
using VecVec = vector<Vec>;
using Tree = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<vector<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
template <typename T>
void co(const T n){cout << n << endl;}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void coVec(const Vec &v){for(ll i : v) cosp(i); cout << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

ll h, w;
VecS s;
VecVec dist;

void init(){
	rep(i, h+2) fill(all(dist[i]), LINF);
}

void bfs(ll x, ll y){
	queue<P> que;
	dist[x][y] = 0;
	que.push({x, y});
	Vec2<ll> sign = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
	while(!que.empty()){
		P p = que.front(); que.pop();
		rep(i, 4){
			ll dx = p.fs+sign[i][0], dy = p.sc+sign[i][1];
			if(s[dx][dy] == '.' && dist[dx][dy] == LINF){
				dist[dx][dy] = dist[p.fs][p.sc]+1;
				que.push({dx, dy});
			}
		}
	}
}

ll maxDist(){
	ll res = 0;
	repn(i, h) repn(j, w) if(dist[i][j] != LINF) chmax(res, dist[i][j]);
	return res;
}

int main(void){
	cin >> h >> w;
	s.resize(h+2);
	repn(i, h){
		string t;
		cin >> t;
		s[i] += "#";
		s[i] += t;
		s[i] += "#";
	}
	rep(i, w+2){
		s[0] += "#";
		s[h+1] += "#";
	}
	dist.resize(h+2);
	rep(i, h+2) dist[i].resize(w+2);

	ll ans = 0;
	repn(i, h){
		repn(j, w) if(s[i][j] == '.'){
			init();
			bfs(i, j);
			chmax(ans, maxDist());
		}
	}
	co(ans);

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		long a = sc.nextLong();
		// スペース区切りの整数の入力
		long b = (long)Math.pow(a, 0.5);
		// 文字列の入力
		for(long i = b; i > 0; i--){
			if(a % i == 0){
				System.out.println(i + a / i - 2);
              break;
			}
		} 
		
		
	}
}

Measured memory_bytes: 35744
#include <iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#include <unordered_set>
#include <unordered_map>

#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
typedef set<LL> SLL;
typedef unordered_set<LL> USLL;
typedef string STR;

template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
template<class T> void _R(std::vector<T>& v) { for (auto& e : v) { _R(e); } }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;


int main() {
  LL n;
  R(n);
  std::vector<std::string> s(n);
  R(s);
  std::unordered_map<std::string, LL> count;
  count["RE"] = 0;
  count["TLE"] = 0;
  count["WA"] = 0;
  count["AC"] = 0;
  for (const auto& elem : s) {
    ++count[elem];
  }
  W("AC", "x", count["AC"]);
  W("WA", "x", count["WA"]);
  W("TLE", "x", count["TLE"]);
  W("RE", "x", count["RE"]);
  return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;
const int INF = 2e16;
const int MOD = 1e9 + 7;
const int MB = 20;
const int K = 500;
const int maxN = 2e4 + 1;


void solve() {
	int n;
	cin >> n;
	cout << n * n;
}
	

signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
class FactMod():
    '''
    modの値が素数の時のfactと組み合わせを求める
    フェルマーの小定理を用いているため、modが素数以外の時は使えない
    '''

    def __init__(self, n, mod):
        '''
        コンストラクタ
        f:nまでの i!の値を　配列に入れる
        inv: (i!)^-1　の値を配列に入れる
        '''
        self.mod = mod
        self.f = [1]*(n+1)
        for i in range(1, n+1):
            self.f[i] = self.f[i-1]*i % mod

        self.inv = [pow(self.f[-1], mod-2, mod)]
        for i in range(1, n+1)[::-1]:
            self.inv.append(self.inv[-1]*i % mod)
        self.inv.reverse()

    def fact(self, n):
        '''
        n!の値を返す
        '''
        return self.f[n]

    def comb(self, n, r):
        '''
        nCrの値を返す
        '''
        ret = self.f[n] * self.inv[n-r]*self.inv[r]
        ret %= self.mod
        return ret

    def perm(self, n, r):
        """
        nPrの値を返す
        """
        ret = self.f[n] * self.inv[n-r]
        ret %= self.mod
        return ret


N, K = map(int, input().split())
L = list(map(int, input().split()))
L = sorted(L)
MOD = 10**9+7

F = FactMod(N+1, MOD)

sub = 0
add = 0
for i in range(N-K+1):
    sub += L[i]*F.comb(N-i-1, K-1)
for i in reversed(range(K-1, N)):
    add += L[i]*F.comb(i, K-1)

print((-sub+add+MOD) % MOD)


Measured memory_bytes: 15060
#include "bits/stdc++.h"
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const long long mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

ll powMod(ll n, ll k, ll m) {
	if (k == 0) {
		return 1;
	} else if (k % 2 == 1) {
		return powMod(n, k - 1, m) * n % m;
	} else {
		ll t = powMod(n, k / 2, m);
		return t * t % m;
	}
}

int main() {
	string s;
	cin >> s;
	
	ll c=0;

	rep(i, 3) {
		if (s[i] == 'A') {
			c++;
		}
	}

	if (c == 3 || c == 0) {
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}
}

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

int main() {
   string S;
   cin >> S;
   int count = 0;
   if( S.at(0) == '+' ) count++;
   else count--;
   if( S.at(1) == '+' ) count++;
   else count--;
   if( S.at(2) == '+' ) count++;
   else count--;
   if( S.at(3) == '+' ) count++;
   else count--;
  cout << count << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int l,r;
        cin >> l >> r;
        ans += r-l+1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
k=int(input())
l=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(l[k-1])

Measured memory_bytes: 65388
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define repC3(vari,varj,vark,n)  for(int vari=0;vari<(n)-2;++vari)for(int varj=vari+1;varj<(n)-1;++varj)for(int vark=varj+1;vark<(n);++vark)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
using namespace std;
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }


int main() {
    int N=3,A,B,C;
    int ans=0;
    //cin>>N;
    char S[N],D[N];
    rep(i,N){
        cin>>S[i];
    }
    rep(i,N){
        cin>>D[i];
        if(S[i]==D[i]){
            ans++;
        }
    }
    

    Out(ans);
    return 0;
}

Measured memory_bytes: 256
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Scanner;

public class Main{
	static Scanner sc;

	static int N, M ,K;

	public static void main(String[] args) throws Exception {
		//InputStream in = new FileInputStream("src/input.txt");
		InputStream in = System.in;
		//PrintStream out = new PrintStream("src/output.txt");

		//System.setOut(out);

		sc = new Scanner(in);

		N = sc.nextInt();
		M = sc.nextInt();
		K = sc.nextInt();

		boolean answer = false;
		for(int i = 0; i <= M; i++){
			for(int j = 0; j <= N; j++){
				if(K == (M-i)*j + (N-j)*i){
					answer = true;
					break;
				}
			}
			if(answer == true){
				break;
			}
		}
		if(answer == true){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 25044
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner (System.in);
    int B[][]=new int[3][3];
    for(int i=0;i<3;i++){
      for(int j=0;j<3;j++){
        B[i][j]=sc.nextInt();}}
    int N =sc.nextInt();
    int M[]=new int[N];
    Integer[] P=new Integer[10];
    int x=0;
    for(int k=0;k<N;k++){
      M[k]=sc.nextInt();
      loop:for(int l=0;l<3;l++){
        for(int m=0;m<3;m++){
          if(M[k]==B[l][m]){P[k]=3*l+m+1;x=x+1;break loop;}}}
      if(x>2){
    if(Arrays.asList(P).contains(1)){
        if(Arrays.asList(P).contains(2)&&Arrays.asList(P).contains(3)){System.out.println("Yes");System.exit(0);}
        else if(Arrays.asList(P).contains(4)&&Arrays.asList(P).contains(7)){System.out.println("Yes");System.exit(0);}
        else if(Arrays.asList(P).contains(5)&&Arrays.asList(P).contains(9)){System.out.println("Yes");System.exit(0);}}
      if(Arrays.asList(P).contains(5)){
        if(Arrays.asList(P).contains(2)&&Arrays.asList(P).contains(8)){System.out.println("Yes");System.exit(0);}
        if(Arrays.asList(P).contains(3)&&Arrays.asList(P).contains(7)){System.out.println("Yes");System.exit(0);}
        if(Arrays.asList(P).contains(4)&&Arrays.asList(P).contains(6)){System.out.println("Yes");System.exit(0);}}
      if(Arrays.asList(P).contains(9)){
        if(Arrays.asList(P).contains(3)&&Arrays.asList(P).contains(6)){System.out.println("Yes");System.exit(0);}
        if(Arrays.asList(P).contains(7)&&Arrays.asList(P).contains(8)){System.out.println("Yes");System.exit(0);}}}}
    System.out.println("No");}
}

Measured memory_bytes: 21716
#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;


#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          N (int)2e5+5
#define          pb push_back
#define          mod 1000000007
#define          ld long double
#define          vi vector<int>
#define          eb emplace_back
#define          vpii vector<pii>
#define          mii map<int,int>
#define          int long long 
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) rbegin(x),rend(x)
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define          PI acos(-1.0)
#define 		 bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > 
OS ;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

inline void INP()
{
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);   
	    freopen("output.txt","w",stdout);
	#endif 
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
vi adj[N];
int vis[N],par[N],a[N];

void go()
{
	cin >> n >> m;
	int sum = 0;
	fo(i,0,n) cin >> a[i] , sum += a[i];

	sort( a , a + n );
	int ans = 0;

	fo(i,0,n)
	{
		if( a[i]*4*m >= sum ) ans++; 
	}
	if( ans >= m ) cout << "Yes\n";
	else cout << "No\n";
}

int32_t main()
{
	//INP(); 
	FAST;     
	int t=1; 
	// cin>>t;
	test(t) go();
}

 

Measured memory_bytes: 5504
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int b[n-1],a[n]={0};
    for(int i=0;i<n-1;i++)
        cin>>b[i];
    for(int i=0;i<n-1;i++)
    {
        if(i==0)
        {
            a[i]=b[i];
            a[i+1] = b[i];
        }
        else
        {
            a[i+1] = b[i];
            a[i] = min(a[i],b[i]);
        }
    }
    int ans = 0;
    for(int i=0;i<n;i++)
        ans += a[i];
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256