akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;
typedef pair<int, P> T;
int table[500][500];
int R;
int W;
int H;
int X;
int Y;
vector<int> num[2];
vector<int> level[2];
priority_queue<T,vector<T>,greater<T> > q;
int main() {
while(1){
	scanf("%d",&R);
	if(R==0)return 0;
	for(int i=0;i<2;i++){
		num[i].clear();
		level[i].clear();
		num[i].push_back(0);
		level[i].push_back(0);
		scanf("%d%d%d%d",&W,&H,&X,&Y);
		X--;
		Y--;
		for(int y=0;y<H;y++){
			for(int x=0;x<W;x++){
				scanf("%d",table[y]+x);
			}
		}
		q.push(T(1,P(Y,X)));
		table[Y][X]=-1;
		while(q.size()){
			int l=q.top().first;
			if(level[i].back()<l){
				level[i].push_back(l);
				num[i].push_back(num[i].back());
			}
			num[i].back()++;
			int dx=1;
			int dy=0;
			int x=q.top().second.second;
			int y=q.top().second.first;
			q.pop();
			//cout << x << ", " << y << ", " << l << endl;
			for(int k=0;k<4;k++,swap(dx,dy),dx=-dx){
				int s=x+dx;
				int t=y+dy;
				if(0<=s&&s<W&&0<=t&&t<H&&table[t][s]>=0){
					q.push(T(table[t][s],P(t,s)));
					table[t][s]=-1;
					//cout << s << ", " << t << endl;
				}
			}
		}
		/*
		for(int j=0;j<num[i].size();j++){
			cout << level[i][j] << ": " << num[i][j] << endl;
		}
		cout << endl;
		*/
	}
	int a=num[1].size()-1;
	int ret=INT_MAX;
	for(int i=0;i<num[0].size();i++){
		while(R<=num[1][a]+num[0][i]&&a>=0){
			ret=min(ret,level[1][a]+level[0][i]);
			a--;
		}
	}
	printf("%d\n",ret);
}
}

Measured memory_bytes: 4308
fn main() {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    println!("{}", solve(&input));
}

fn solve(input: &str) -> i64 {
    let mut iter = input.split_whitespace().map(|w| w.parse().unwrap());
    let n: i64 = iter.next().unwrap();
    let r: i64 = iter.next().unwrap();
    if n < 10 {
        r + 100 * (10 - n)
    } else {
        r
    }
}

Measured memory_bytes: 4352
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

#define INF (1<<31-1)
int dp[20001][256];

int tw(int n, int c)
{
	return (n-c)*(n-c);
}
int ck(int n)
{
	if(n<=0) return 0;
	if(n>=255) return 255;
	
	return n;	
}

int main()
{
	int N,M, c[16];
	while(cin >> N >> M, (N||M))
	{
		int Lv;
		for(int i=0; i<M; i++)
		cin >> c[i];
		
		for(int i=0; i<=N; i++)
		for(int j=0; j<256; j++)
		{
			dp[i][j] = INF;
		}
		
		dp[0][128] = 0;
		for(int i=0; i<N; i++)
		{
			cin >> Lv;
			
			for(int j=0; j<256; j++)
			{
				if(dp[i][j]!=INF)
				{
					for(int k=0; k<M; k++)
					{
						int nc = ck(j+c[k]);
						dp[i+1][nc] = min(dp[i+1][nc], dp[i][j]+tw(nc,Lv));
					}
				}
			}
		}
		
		int m = INF;
		for(int i=0; i<256; i++)
		{
			m=min(m,dp[N][i]);
		}
		cout << m << endl;
	}
}

Measured memory_bytes: 20000
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

#define ll long long

#define DEBUG (0)

int main()
{
  int a,b,c = 0;

  cin >> a >> b >> c;

  if((a == b) && (b != c) || ((b == c)&&(c != a)) || ((c == a)&&(a!=b))){
    cout << "Yes" << "\n";
  }else{
    cout << "No" << "\n";
  }
}


Measured memory_bytes: 256
n, m, l = map(int, input().split())
a = [[] for _ in range(n)]
b = [[] for _ in range(m)]

for i in range(n):
  a[i] = list(map(int, input().split()))

for i in range(m):
  b[i] = list(map(int, input().split()))

for i in range(n):
  line = []
  for j in range(l):
    c = 0
    for k in range(m):
      c += a[i][k]*b[k][j]
    line.append(str(c))
  print(' '.join(line))

Measured memory_bytes: 8460
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int ans=0, cnt=0;
    cin >> s;
    for(int i=0; i<s.size(); i++){
        if(s[i]=='R') ++cnt;
        else cnt=0;
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3580
until(n,m=gets.split.map(&:to_i))==[0,0]do
r,p,a=[],[],[]
n.times{r.unshift(gets.gsub("?",".").split)}
m.times{p<<gets.split}
p.each{|p|r.each{|r|if/#{r[1]}/=~p[0]&&p[1]=~/#{r[2]}/
a<<p*" "if/p/=~r[0]
break
end}}
puts a.size,a
end

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

const int MOD = 1e9+7;

void solve() {
  int n; cin >> n;
  vector<int> a(n);
  for(auto &x : a) cin >> x;
  auto sum = accumulate(begin(a), end(a), 0LL) % MOD;
  auto ans = sum * sum;
  for(auto &x : a) ans -= 1LL * x * x % MOD;
  ans %= MOD;
  if(ans < 0) ans += MOD;
  if(ans & 1) ans += MOD;
  cout << ans / 2 << endl;
}

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  solve();
  return 0;
}


Measured memory_bytes: 3952
#include<stdio.h>
int main(){
    int jlh,ptg ;
 
    int a[200002];
    scanf("%d %d", &jlh, &ptg);

    for (int i=0; i<jlh; i++){
        scanf ("%d", a + i);
    }

    for (int i=ptg; i<jlh; i++){
        if (a[i] > a[i - ptg]){
            printf ("Yes\n");
        }
        else {
            printf ("No\n");
        }
    }
    return 0;
}

Measured memory_bytes: 2428
def examA():
    N, A, B = LI()
    ans = inf
    if abs(A-B)%2==0:
        ans = abs(A-B)//2
    cur = min((A+B-1)//2,(2*N-A-B+1)//2)
    ans = min(ans,cur)
    print(ans)
    return

def examB():
    N, M, V, P = LI()
    A = LI(); A.sort()
    maxA = A[N-P]
    sumA = maxA*(N-P)-sum(A[:N-P])
#    print(maxA,sumA)
    l = -1; r = N-P
    while(r-l>1):
        flag = True
        now = (l+r)//2
        c = sumA - (maxA-A[now])
        need = maxA - A[now]
        if need>M:
            flag = False
        q = 0
        for i in range(N):
            if A[i]>=maxA-M+(M-need):
                break
            if i==now:
                break
            q +=maxA-M+(M-need)-A[i]
        if (V-P)*M-(N-P)*(M-need)+q>c:
            flag = False
        if flag:
            r = now
        else:
            l = now
#        print(A[now],c,(V-P)*M-(N-P)*(M-need)+q,q,need)
    ans = N-r
    print(ans)
    return

def examC():
    N = I()
    ans = [["."]*N for _ in range(N)]
    if N%3!=0 and N%2!=0:
        print("-1")
        return
    if N%3==0:
        for i in range(N//3):
            ans[i*3][i*3] = "a"
            ans[i*3][i*3+1] = "a"
        for i in range(N//3):
            ans[i*3+1][i*3+2] = "a"
            ans[i*3+2][i*3+2] = "a"
    else:
        for i in range(N//2):
            for j in range((N+2) // 4):
                ans[i * 2][j * 4] = "a"
                ans[i * 2][j * 4 + 1] = "a"
                ans[i * 2 + 1][j * 4] = "b"
                ans[i * 2 + 1][j * 4 + 1] = "b"
                if j*4+2==N:
                    break
                ans[i * 2][j * 4+2] = "c"
                ans[i * 2][j * 4+3] = "c"
                ans[i * 2 + 1][j * 4 + 2] = "d"
                ans[i * 2 + 1][j * 4 + 3] = "d"
            ans[i*2][i*2] = "e"
            ans[i*2+1][i*2] = "e"
            ans[i*2][i*2+1] = "f"
            ans[i*2+1][i*2+1] = "f"
    for v in ans:
        print("".join(map(str,v)))
    return

def examD():
    return

def examE():
    return

def examF():
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examB()


"""
                for j in range(N // 4):
                    ans[i * 2][j * 4+2] = "a"
                    ans[i * 2][j * 4 +3] = "a"
                    ans[i * 2 +1][j * 4+2] = "b"
                    ans[i * 2 +1][j * 4 +3] = "b"
                for j in range(N // 4):
                    ans[i*2-2][j*4+2] = "c"
                    ans[i*2-1][j*4+2] = "c"
                    ans[i*2-2][j*4 +3] = "d"
                    ans[i*2-1][j*4 +3] = "d"

"""

Measured memory_bytes: 15660
#include<stdio.h>
int selectionSort(int*,int);/*選択ソート*/
void swap(int* ,int*);/*入替*/

int main()
{
  int n,i,cnt;
  scanf("%d",&n);
  int b[n];
  for(i=0 ; i<n ; i++)
    scanf("%d",&b[i]);

  cnt=selectionSort(b,n);
   for(i=0;i<n;i++){
    if(i == n-1)
      printf("%d",b[i]);
    else
    printf("%d ",b[i]);}
  printf("\n");
  printf("%d\n",cnt);

  return 0;
}

void swap(int *x ,int *y)
{
  int z;
  z=*x;
  *x=*y;
  *y=z;
}

int selectionSort(int*b,int n)
{
  int i,j,mini,cnt=0;
  for(i=0 ; i < n-1; i++)
    {
      mini=i;
      for(j=i ; j < n ; j++)
	{
	  if(b[j] < b[mini])
	    { mini=j; }
	}
      swap(&b[i],&b[mini]);
      if(i!=mini)
      cnt++;
    }
  return cnt;
 
}



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


ll bit[MAX];

void numSet(int r,ll x){
  r=MAX-r-1;
  while(r){
    bit[r]=max(bit[r],x);
    r-=(r&-r);
  }
}

ll getMin(int i){
  i=MAX-i-1;
  ll res=0;
  while(i<MAX){
    res=max(res,bit[i]);
    i+=(i&-i);
  }
  return res;
}


ll n,k,sum,ans,num;
int main(){
  scanf("%lld",&n);
  while(n--){
    scanf("%lld",&num);
    sum+=num;
    k=getMin(num);
    ans=max(ans,k+num);
    numSet(num,k+num);
  }
  printf("%lld\n",sum-ans);
  return 0;
}

Measured memory_bytes: 1968
X=int(input())

if X >= 1800:
    print(1)
elif X >= 1600:
    print(2)
elif X >= 1400:
    print(3)
elif X >= 1200:
    print(4)
elif X >= 1000:
    print(5)
elif X >= 800:
    print(6)
elif X >= 600:
    print(7)
elif X >= 400:
    print(8)


Measured memory_bytes: 9172
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
bc = [tuple(map(int, input().split())) for _ in range(m)]
bc.sort(key=lambda t: t[1], reverse=True)

index = 0
count = [0] * m
for i in range(n):
    if index >= m or a[i] >= bc[index][1]:
        break
    a[i] = bc[index][1]
    count[index] += 1
    if count[index] >= bc[index][0]:
        index += 1

print(sum(a))


Measured memory_bytes: 22456
#include <iostream>

using namespace std;

int main() {
   string S;
   cin>> S;
   if(S=="Sunny"){
       cout<<"Cloudy";
   }
   else if(S=="Cloudy"){
       cout<<"Rainy";
   }
   else if(S=="Rainy"){
       cout<<"Sunny";
   }
    else{
        cout<<"Invalid string";
    }
    
}

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

int main()
{
    int a,b,c,n;
    
    string s;
    
    cin >> s;
    
    for(int i=0; i<s.size(); i++)
    {
        if(s[i]=='R'&&i%2!=0){
            cout << "No" << endl;
            return 0;
        }
        if(s[i]=='L'&&i%2==0)
        {
            cout << "No" << endl;
           return 0;
        }
    }
    cout << "Yes" << endl;
    
    return 0;
}


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

namespace B_ABC128
{
    class MainClass
    {

        static int[] s;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            var list = new List<Tuple<string,int,int>>();
            for(int i = 0;i<s[0];i++){
                string[] sp = ReadLine().Split().ToArray();
                var spi = new Tuple<string,int,int>(sp[0],int.Parse(sp[1]),i);
                list.Add(spi);
            }

            var ans = list.OrderBy(x=>x.Item1).ThenBy(y=>-y.Item2);
            foreach(var item in ans){
                Console.WriteLine(item.Item3+1);
            }



        }
    }
}


Measured memory_bytes: 13660
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include <vector>
#include <list>
#include <string>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <climits>
#include <map>

using namespace std;

int main(){

	int n;
	cin >> n;
	vector<int> l;
	for (int i = 0; i < 2*n; i++)
	{
		int t;
		cin >> t;
		l.push_back(t);
	}

	int sum = 0;
	sort(l.begin(), l.end());


	for (int i = 0; i < 2*n; i+=2)
	{
		
		sum += min(l[i], l[i + 1]);

	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <vector>
#include <cstdio>
#include <queue>
using namespace std;

#define pb push_back

const int N = 4e5 + 10;

int n, m, s, t;
long long d[N];
vector<int> G[N]; //g, g + n, g + 2*n

void bfs(int s, int t) {
	fill(d + 1, d + 3 * n + 1, -1);
	d[s] = 0; queue<int> q; q.push(s);
	while(q.size()) {
		int u = q.front(); q.pop();
		for(int &v : G[u]) if(d[v] == -1) {
			d[v] = d[u] + 1; q.push(v);
		}
	}
}

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; i ++) {
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].pb(v + n);
		G[u + n].pb(v + 2 * n);
		G[u + 2 * n].pb(v);
	}
	scanf("%d%d", &s, &t);
	bfs(s, t);
	if(d[t] == -1) puts("-1");
	else printf("%d\n", d[t] / 3);
	return 0;
}


Measured memory_bytes: 21888
import java.util.Scanner;

public class Main {

	static long mod = 1000000007;
	static long INF = Long.MAX_VALUE;

	static long chmin(long a, long b) {
		return Math.min(a, b);
	}

	static long chmax(long a, long b) {
		return Math.max(a, b);
	}

	public static void main(String[] args) {
		// AtCoder_A
		Scanner sc = new Scanner(System.in);
		// 入力
		String A = sc.nextLine();

	    // Scannerクラスのインスタンスをクローズ
		sc.close();
		if( Character.isUpperCase( A.charAt( 0 ) ) ) {
		    System.out.println( "A" );
		}
		else {
		    System.out.println( "a" );
		}
	}
}


Measured memory_bytes: 35656
def culEv (i, c = 0):
  if i % 2 == 0:
    c = c + 1
    c = culEv(i / 2, c)
  return c

s = [input() for i in range(2)]
n = int(s[0])
l = [int(i) for i in s[1].split()]
c = []
for i in l:
  if i % 2 != 0:
    c.append(0)
    break
  c.append(culEv(i))
print (min(c))

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

static const int INF = 1000000000;

int main() {
    int n;
    cin >> n;
    vector<int> p(n + 1);
    vector< vector<int> > dp(n + 1, vector<int>(n + 1));
    for (int i = 1; i <= n; i++)
        cin >> p[i - 1] >> p[i];

    for (int i = 1; i <= n; i++) dp[i][i] = 0;
    for (int l = 2; l <= n; l++) {
        for (int i = 1;  i <= n - l + 1; i++) {
            int j = i + l - 1;
            dp[i][j] = INF;
            for (int k = i; k <= j - 1; k++) {
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + p[i - 1] * p[k] * p[j]);
            }
        }
    }

    cout << dp[1][n] << endl;
    return 0;
}


Measured memory_bytes: 3168
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
inline void write(int x)
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n=read();
    pr2((n-2)*180);
   	return 0;
}

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

int main(){
    string S, T;
    long int cnt = 0;
    cin >> S;
    cin >> T;

    for(int i = 0; i < S.size(); i++){
        if(S[i] != T[i]) {
            cnt++;
        }
    }

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

Measured memory_bytes: 3880
#include <bits/stdc++.h>
using namespace std;
#define	rep(i,n)	for(long long i=0;i<n;i++)
int main(){
  long long n;	cin >> n;
  vector<long long>	a(3*n);
  rep(i,3*n)	cin >> a[i];
  sort(a.begin(),a.end());
  long long sum=0;
  for(long long i=n;i<3*n;i+=2){
    sum+=a[i];
  }
  cout << sum;
}

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

using namespace std;

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

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	ll a, b, c, ans=0;
	cin >> a >> b >> c;
	
	if(a >= b && a>= c){
		int m = a/2;
		ans= (b*c)*(a-2*m);
	}
	else if( b >= c){
		int m = b/2;
		ans= (a*c)*(b-2*m);
	}
	else{
		int m = c/2;
		ans= (b*a)*(c-2*m);
	}
	cout << ans;

}


Measured memory_bytes: 256
using System;

namespace DPL_1_B_2{
    public class Program{
        public static void Main(string[] args){
            var sr = new StreamReader();
            //---------------------------------
            var N = sr.Next<int>();
            var W = sr.Next<int>();
            var item = sr.Next<int>(N, 2);

            var dp = new int[W + 1];
            foreach(var i in item){
                for(var j = W; j >= i[1]; j--){
                    dp[j] = Math.Max(dp[j], dp[j - i[1]] + i[0]);
                }
            }

            Console.WriteLine(dp[W]);
            //---------------------------------
        }
    }

    public class StreamReader{
        private readonly char[] _c = {' '};
        private int _index = -1;
        private string[] _input = new string[0];

        public T Next<T>(){
            if(_index == _input.Length - 1){
                _index = -1;
                while(true){
                    string rl = Console.ReadLine();
                    if(rl == null){
                        if(typeof(T).IsClass) return default(T);
                        return (T)typeof(T).GetField("MinValue").GetValue(null);
                    }
                    if(rl != ""){
                        _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
                        break;
                    }
                }
            }
            return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
        }

        public T[] Next<T>(int x){
            var ret = new T[x];
            for(var i = 0; i < x; ++i) ret[i] = Next<T>();
            return ret;
        }

        public T[][] Next<T>(int y, int x){
            var ret = new T[y][];
            for(var i = 0; i < y; ++i) ret[i] = Next<T>(x);
            return ret;
        }
    }
}

Measured memory_bytes: 9988
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
    int N;
    cin >> N;
    int A[2][N];
    int S[2][N+1];
    memset(S,0,sizeof(S));
    for(int i = 0 ; i <2; i++){
        for(int j=0; j < N; j++){
            cin >> A[i][j];
            S[i][j+1] = S[i][j] + A[i][j];
        }
    }
    int ans =0;
    for(int i=0; i <N; i++){
        ans =max(ans, S[1][N]-S[1][i]+S[0][i+1]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
<?php
define('MOD', 10 ** 9 + 7);

fscanf(STDIN, '%d', $n);
fscanf(STDIN, '%s', $s);

if ($s[0] === 'W' || $s[2 * $n - 1] === 'W') {
    echo (0) . PHP_EOL;
    exit();
}

$lr[0] = 'L';
$l_cnt_sum[0] = 0;
$l_cnt_sum[1] = 1;
$l_cnt = 1;
$r_cnt = 0;
$x = 1;
for ($i = 1; $i < 2 * $n; $i++) {
    if ($s[$i] !== $s[$i - 1]) {
        if ($lr[$i - 1] === 'L') $lr[$i] = 'L';
        else $lr[$i] = 'R';
    } else {
        if ($lr[$i - 1] === 'L') $lr[$i] = 'R';
        else $lr[$i] = 'L';
    }
    if ($lr[$i] === 'L') {
        $l_cnt_sum[$i + 1] = $l_cnt_sum[$i] + 1;
        $l_cnt++;
    } else {
        $x = $x * ($l_cnt_sum[$i] - $r_cnt) % MOD;
        $l_cnt_sum[$i + 1] = $l_cnt_sum[$i];
        $r_cnt++;
    }
}

if ($l_cnt !== $r_cnt) {
    echo (0) . PHP_EOL;
    exit();
}

$ans = $x * kaijou($n) % MOD;
echo $ans . PHP_EOL;

function kaijou($n) {
    return $n > 1 ? $n * kaijou($n - 1) % MOD : 1;
}

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

using namespace std;

int main()
{
    long long n,k;
    cin>>n>>k;
    long long A[n];
    for(int i = 0; i < n; i++)cin>>A[i];
    long long all[n];
    long long af[n];
    for(int i = 0; i < n; i++){
        int s = 0;
        for(int j = 0; j < n; j++){
            if(A[j] < A[i]){
                s++;
            }
        }
        all[i] = s;
    }
    for(int i = 0; i < n; i++){
        int s = 0;
        for(int j = i+1; j < n; j++){
            if(A[j] < A[i]){
                s++;
            }
        }
        af[i] = s;
    }
    long long ans = 0;
    for(int i = 0; i < n; i++){
        ans = (ans +  (af[i] * k) % (1000000007)) % (1000000007);

        ans = (ans% (1000000007) +  (all[i] * ( (k*(k-1)/2)% (1000000007) ) )% (1000000007) ) % (1000000007);
    }
    cout<<ans;
    return 0;
}


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

int main(){
  ll a,b,r,tmp;
  cin >> a >> b;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  int ans=0;
  ll gcd = b;
  for(ll i=2;i*i<=gcd;i++){
    bool flag = 0;
    while(b%i==0){
      flag = 1;
      b /= i;
    }
    if(flag==1) ans++;
  }
  if(b!=1)ans++;
  cout << ans + 1 << endl;
}


Measured memory_bytes: 256
n, w = list(map(int,input().split()))
w_v = [list(map(int,input().split())) for i in range(n)]
dp = [[0] * 100001 for i in range(101)]

for i in range(n):
  for j in range(w+1):
    if j - w_v[i][0] >= 0:
      dp[i+1][j] = max(dp[i+1][j], dp[i][j-w_v[i][0]] + w_v[i][1])

    dp[i+1][j] = max(dp[i+1][j], dp[i][j])

print(dp[n][w])


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

#define ARC(i, a, b) for(int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)

template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; }
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; }
template<class T> T rng(const T &a, const T &b){ return a > b ? a - b : b - a; }
template<class T> T &anth(T &a, const T &b){ return a = ant(a, b); }
template<class T> T &onth(T &a, const T &b){ return a = ont(a, b); }

int r, b;
int main(){
	int n;
	char s[120];
	scanf("%d%s", &n, s);
	RC(i, n){
		if(s[i] == 'R') ++r;
		else ++b;
	}
	printf(r > b ? "Yes" : "No");
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>

using namespace std;
string str[10005];
//累乗(繰り返し2乗法)　aのb乗(mod)を求める。
long long int rui(long long int a, long long int b, long long mod) {
	int memo[65] = {};
	long long int A[65] = {};
	long long int tmp = 1;
	for (int i = 0; i < 65; i++) {
		memo[i] = b % 2;
		b /= 2;
	}

	A[0] = a;
	A[0] %= mod;

	for (int i = 1; i < 65; i++) {
		A[i] = A[i - 1] * A[i - 1];
		A[i] %= mod;
	}
	for (int i = 0; i < 65; i++) {
		if (memo[i] == 1) {
			tmp *= A[i];
			tmp %= mod;
		}
	}
	tmp %= mod;
	return tmp;
}

int main()
{

	long long int n, m,N, a[2000000] = {}, r, g, b, res = 0, a_fin = 0, b_start = 0, a_fin_b_start = 0;
	long long int yakusuu[2000000] = {}, kosuu = 1, sosu_fin;
	const long long int mod = 10000000000000000;
	cin >> n;
	N = n;
	yakusuu[0] = 1;
	for (long long int i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			a[i]++;
			n /= i;
		}
		if(a[i] != 0) {
			int tmp = a[i];
			for (int j = 1; j <= a[i]; j++) {
				for (int k = 0; k < kosuu; k++) {
					yakusuu[k + j * kosuu] = rui(i, j, mod) * yakusuu[k];
				}
			}
			kosuu *= (tmp+1);
		}
	}
	if (n != 1) {
		for (int k = 0; k < kosuu; k++) {
			yakusuu[k +kosuu] = n* yakusuu[k];
		}
		kosuu *= 2;
	}

	for (int i = 1; i < kosuu; i++) {
		if (yakusuu[i] * (N / (yakusuu[i] - 1)) == N) {
			res+=yakusuu[i]-1;
		}
	}
	cout << res;
}

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

int main() {
	
	int n, m;
	int count = 0;
	
	while (1)
	{
		int max = 0;
		int sum;
		
		std::cin >> n >> m;
		
		if ( n == 0 && m == 0) break;
		
		count++;
		int a[n];
		
		// 入力
		for (int i = 0; i < n; i++)	std::cin >> a[i];
		
		for (int i = 0; i < n; i++) {
			
			for (int j = i + 1; j < n; j++) {
				
				sum = a[i] + a[j];
				
				// 合計値が容量を下回るときのみ
				if ( sum <= m )
				{
					// 現在の最大値より大きいとき
					if ( sum > max ) 
					{
						max = sum;
					}
				}
				
			}
		}
		
		// 結果出力
		if ( max == 0) std::cout << "NONE" << std::endl;
		else		   std::cout <<   max  << std::endl;
		
	}
	
	/*
	for (int i = 0; i < count; i++) {
		cout <<  << endl;
	}
	
	*/
	
	return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int  a[N];
int main()
{
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
	int n,k;
	cin>>n>>k;
	int ans=0;
	while(n)
	{
		n/=k;
		ans++;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define re register
int a[2000100],b[2000100],c[2000100],b1[2000100],c1[2000100],q[2000100],ta;
bool bo[2000100];
int main()
{
	re int n,ans=1;re long long k;
	scanf("%d%lld",&n,&k);
	for(re int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(!b[a[i]])b[a[i]]=i;
	}
	c[n]=b[a[n]]+1;b1[a[n]]=n;c[n+1]=1;
	for(re int i=n-1;i;i--)
	{
		if(!b1[a[i]])
		{
			c[i]=b[a[i]]+1;
		}else
		{
			c[i]=c[b1[a[i]]+1];
		}b1[a[i]]=i;
	}k--;
	while(k)
	{
		if(k&1ll)ans=c[ans];
		for(re int i=1;i<=n+1;i++)c1[i]=c[c[i]];
		for(re int i=1;i<=n+1;i++)c[i]=c1[i];
		k>>=1;
	}
	for(re int i=ans;i<=n;i++)
	{
		if(!bo[a[i]])bo[a[i]]=1,q[++ta]=a[i];
		else
		{
			while(bo[a[i]])bo[q[ta]]=0,ta--;
		}
	}
	for(re int i=1;i<=ta;i++)printf("%d ",q[i]);
}

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

#define ll long long
#define mx  100005
#define mod 1000000009
#define lim 100

using namespace std;


int main(){
	ios_base::sync_with_stdio(false);
	int r;cin>>r;

	if(r<1200)cout<<"ABC\n";
	else if(r<2800)cout<<"ARC\n";
	else cout<<"AGC\n";
	return 0;
}

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

int a[100005];

int main()
{
    int n;

    cin >> n;

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

        cin >> x;

        a[x]++;
        if(x-1>=0)
        a[x-1]++;
        a[x+1]++;
    }
    int ans = -1;
    for(int i = 0 ; i<=100004 ; i++)
    {
        ans = max(ans , a[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
from collections import Counter

N = int(input())
a_s = input().split()
a_s = [int(a_s[i]) for i in range(N)]

c = Counter(a_s)
c = sorted(c.items(), key=lambda x:x[0])
a_unique, a_counts = zip(*c)

ans = 0
for i,a in enumerate(a_unique):
    val = a_counts[i]
    if (i>0):
        if (a_unique[i-1]+1==a):
            val += a_counts[i-1]
            
    if (i<len(a_unique)-1):
        if (a_unique[i+1]-1==a):
            val += a_counts[i+1]
    
    if val > ans:
        ans = val
        
print(ans)

Measured memory_bytes: 17372
/*
  Esteban Arango Medina
*/
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <tuple>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;

using ll=long long;
#define int ll

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<string,int> si;
typedef pair<int,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef vector <char> vc;
typedef vector <string> vs;
typedef map <string,vs> msvs;
typedef map <string,int> msi;
typedef map <char,int> mci;
typedef map <int,int> mii;
typedef map <string,string> mss;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define endl '\n' // Normal `cout << endl` flushes the output every time wich hit performance badly
#define INF 1000000000
#define deb(x) cout<<#x<<": "<<x<<endl;
#define printArray(arr) for(auto x: arr) { cout<<x<<", "; }
#define printMatrix(mat) for(auto x: mat) { cout<<" "; printArray(x); cout<<endl; }
#define printMap(mmap) for(auto p: mmap) { cout<< p.first<<": "<<p.second<<endl; }

int gcd(int x, int y){
  while(x > 0 && y > 0){
    if(x > y)x %= y; else y %= x;
  }
  return x + y;
}

signed main(){
  ios_base::sync_with_stdio(false); cin.tie(NULL); // Fast input
  #ifdef LOCAL_PROJECT
    freopen("in.in", "r", stdin);
    // freopen("out.out", "w", stdout);
  #endif

  int T = 1; //cin>>T;
  while(T--) {
    int ans = 0;
    int k; cin>>k;
    rep(i, 1, k+1){
      rep(j, 1, k+1){
        rep(l, 1, k+1){
          ans += gcd(i, gcd(j, l));
        }
      }
    }
    cout<<ans;
  }
  return 0;
}

Measured memory_bytes: 3652
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        s: String,
        t: String,
    };

    let mut dp = vec![vec![0; t.len()+1]; s.len()+1];
    let mut prev = vec![vec![[0, 0]; t.len()+1]; s.len()+1];

    for (i, ss) in s.chars().enumerate() {
        for (j, tt) in t.chars().enumerate() {
            if ss == tt {
                dp[i+1][j+1] = dp[i][j] + 1;
                prev[i+1][j+1] = [i, j];
            } else {
                if dp[i+1][j+1] < dp[i][j+1] {
                    dp[i+1][j+1] = dp[i][j+1];
                    prev[i+1][j+1] = [i, j+1];
                }

                if dp[i+1][j+1] < dp[i+1][j] {
                    dp[i+1][j+1] = dp[i+1][j];
                    prev[i+1][j+1] = [i+1, j];
                }
            }
        }
    }

    let mut ans = String::new();
    let s = s.chars().collect::<Vec<char>>();
    let t = t.chars().collect::<Vec<char>>();
    let mut i = s.len();
    let mut j = t.len();
    if s[s.len()-1] == t[t.len()-1] {
        ans.insert(0, s[s.len()-1]);
    }
    loop {
        let [si, ti] = prev[i][j];

        if si == 0 || ti == 0 {
            break;
        }

        if s[si-1] == t[ti-1] {
            ans.insert(0, s[si-1]);
        }
        i = si;
        j = ti;
    }

    println!("{}", ans);
}


Measured memory_bytes: 178132
#include<iostream>
#include<variant>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<climits>
#include<unordered_map>
#include<set>

using namespace std;

int main() {
	long long int n;
	int x, m, st = -1, en = -1, f = 0;
	cin >> n >> x >> m;
	long long int a = x, cnt = 0, total = 0;
	unordered_map<long long int,bool> note;
	vector<long long int> sub;
	for (int i = 0; i < n; i++) {
		if (note.find(a) != note.end()) {
			if (f == 0) {
				st = i;
				f = 1;
			}
			else if (sub[0] == a) {
				en = i;
				break;
			}
			sub.push_back(a);
			total += a;
		}
		note[a] = true;
		cnt+=a;
		a = (a * a) % m;
	}
	if (en != -1) {
		n -= en;
		cnt += total * (n / (en - st));
		n = n % (en - st);
		for (int i = 0; i < n; i++) {
			cnt += sub[i];
		}
	}
	cout << cnt;
	return 0;
}

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

typedef long long ll;
ll MOD = 1000000007;

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

    if (N % (2*D+1) == 0) cout << N/(2*D+1) << endl;
    else cout << N/(2*D+1)+1 << endl;
    
    return 0;
}


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

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

    n = int(input())
    print((n-2)*180)

if __name__ == '__main__':
    main()

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

int main(){
    int N, K;
    string S;
    cin >> N >> S >> K;
    for(int i = 0; i < N; i++){
        if(S[K-1] != S[i]) S[i] = '*';
    }
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b){if(a < b){ a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b){if(a > b){ a = b; return 1;} return 0;}

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

    if(a > b * 2){
        cout << a - b * 2 << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
CD = [list(map(int, input().split())) for _ in range(M)]

for a, b in AB:
  check, distance = 1, 400000001
  for i, [c, d] in enumerate(CD):
    if distance > abs(a-c) + abs(b-d):
      distance = abs(a-c) + abs(b-d)
      check = i+1
  print(check)

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

using namespace std;

int main(void)
{
  int a,b,c,d;

  cin>>a>>b>>c>>d;

  if(abs(a-c)<=d)
  {
    cout<<"Yes"<<endl;
    return 0;
  }
  else if(abs(a-b) <= d && abs(b-c) <= d)
  {
    cout<<"Yes"<<endl;
    return 0;
  }
  else
  {
    cout<<"No"<<endl;
    return 0;
  }
}

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

x=sum(b)-sum(a)

if x<0:
    print("No")
elif x==0:
    if a==b:
        print("Yes")
    else:
        print("No")
else:
    if x%2==0 and sum(a)%2!=sum(b)%2:
        print("No")
    elif x%2==1 and sum(a)%2==sum(b)%2:
        print("No")
    else:
        cnt=0
        for i in range(n):
            if a[i]<b[i]:
                cnt+=(b[i]-a[i]+1)//2
        if cnt<=x:
            print("Yes")
        else:
            print("No")

Measured memory_bytes: 4596
package main

import "fmt"

const mod int = 1e9 + 7

func main() {
	var s int
	fmt.Scan(&s)

	dp := [2010]int{}
	var dfs func(n int) int
	dfs = func(n int) int {
		if n < 3 {
			return 0
		}
		if dp[n] > 0 {
			return dp[n]
		}

		c := 1
		for i := 3; i <= n; i++ {
			c += dfs(n - i)
			c %= mod
		}

		dp[n] = c
		return c
	}

	ans := dfs(s)
	fmt.Println(ans)
}


Measured memory_bytes: 1952
#Tenka1 Programmer Beginner Contest b
def move(me,you):
    if me%2==0:
        return me//2,you+me//2
    else:
        return (me-1)//2,you+(me-1)//2

a,b,k=map(int,input().split())
turn=True#takahashi true aoki false
cnt=0
while cnt<k:
    if turn:
        a,b=move(a,b)
        cnt+=1
        turn=False
    else:
        b,a=move(b,a)
        cnt+=1
        turn=True
print(a,b)


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

class UF {

  vector<int> par; // 親
  vector<int> rank; // 深さ

public:

  void init(int n) { // n個で初期化
    for(int i=0;i<n;i++) {
      par.push_back(i);
      rank.push_back(0);
    }
  }

  UF(int n) {
    for(int i=0;i<n;i++) {
      par.push_back(i);
      rank.push_back(0);
    }
  }

  int find(int x) { // 木の中のxの親を返す
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
  }

  void unite(int x, int y) { // xとyを統合する
    x = find(x);
    y = find(y);
    if (x == y) return;

    if(rank[x] < rank[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }

  bool same(int x, int y) { // xとyが等しいかどうか判定する
    return find(x) == find(y);
  }
};

int main () {
  cin.tie(0);
  cout << setprecision(10);

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

  UF uf(n);
  vvi a(m);
  REP(i, n) {
    int k; cin >> k;
    REP(j, k) {
      int l; cin >> l;
      l--;
      a[l].pb(i);
    }
  }

  REP(i, m) {
    FOR(j, 1, SZ(a[i])) {
      uf.unite(a[i][j-1], a[i][j]);
    }
  }

  REP(i, n-1) {
    if(!uf.same(i, i+1)) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 4608
// Daniel Grzegorzewski
// while (clock()<=69*CLOCKS_PER_SEC)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second
#define int long long

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

//X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego)
//X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

const int N = 2*(int)1e5 + 3;

int n, a[N], cnt[N];
int res;

signed main() {
  init_ios();
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    ++cnt[a[i]];
  }
  for (int i = 1; i < N; ++i)
    res += cnt[i]*(cnt[i]-1)/2;
  for (int i = 1; i <= n; ++i) {
    int x = a[i];
    int tmp = res-cnt[x]*(cnt[x]-1)/2+(cnt[x]-1)*(cnt[x]-2)/2;
    cout<<tmp<<"\n";
  }
}

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

vector<string> G;
const int mod = (int)1e9 + 7;
int n, m;
int memo[1010][1010];
int dp(int i, int j) {
    if (i >= n || j >= m) return 0;
    if (G[i][j] == '#') return 0;
    if (i == n - 1 && j == m - 1) return 1;
    if (memo[i][j] != -1) return memo[i][j];
    int x = dp(i + 1, j) % mod;
    int y = dp(i, j + 1) % mod;
    int ans = x + y;
    ans %= mod;
    return memo[i][j] = ans;
}

int main() {
    cin >> n >> m;
    G = vector<string>(n);
    for(auto &t : G) cin >> t;
    memset(memo, -1, sizeof(memo));
    cout << ( dp(0,0) % mod )<< "\n";
    return 0;
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define For(i,j,k) for(int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for(int i=(int)(j);i>=(int)(k);i--)
inline ll read(){
	ll x=0;char ch=getchar();bool f=0;
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=1;
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return f?-x:x;
}
void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);putchar(x%10+'0');
}
void writeln(ll x){write(x);puts("");}
void writep(ll x){write(x);putchar(' ');}
const int N=1e5+5;
const ll mod=998244353;
int d[N],cnt[N];
int main(){
	int n=read();
	for(int i=1;i<=n;++i)
		d[i]=read();
	if(d[1]!=0) return puts("0"),0;
	for(int i=1;i<=n;++i)
		cnt[d[i]]++;
	int ans=1;
	for(int i=2;i<=n;++i)
		ans=1ll*ans*cnt[d[i]-1]%mod;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 4372
#include<iostream>
#include<vector>
using namespace std;
int needx[]={-1,0,1,0,1,1,-1,-1};
int needy[]={0,1,0,-1,1,-1,1,-1};
//??¶?????¨???false????????????true???????????¢??°//
bool land(int x,int y,vector<vector<bool> >& cango){
    if(cango[x][y]){
        cango[x][y]=false;
        for(int i=0;i<8;i++){
            int nextx=x+needx[i];
            int nexty=y+needy[i];
            if(cango[nextx][nexty])
                bool flag=land(nextx,nexty,cango);
            }
    return true;
     }else{
return false;
    }
}
int main(void){
    int input;
	int w,h;
	while(1){
cin>>w>>h;
if(h==0)break;
    vector<vector<bool> > cango(h+2,vector<bool>(w+2,false));
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin >>input;
            if(input==1){
cango[i][j]=true;
            }
        }
    }
  
    int t=0;
for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
        if(land(i,j,cango)){
            t++;
        }
    }
}
cout <<t<<endl;
	}
return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define FOR(i,a,b)  for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n)    FOR(i,0,n)
#define RER(i,n)    FOR(i,0,(n+1))
#define pb          push_back
#define mp(a,b)     make_pair((a),(b))
#define mset(m,v)   memset(m,v,sizeof(m))
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pair<ll, ll> > vpll;
typedef vector<string> vs;
typedef long double ld;
const double EPS    = 1e-10;
const int INF       = 1e+9;
const double PI     = acos(-1);


auto main() -> int
{
    string s;
    int k;
    cin >> s >> k;

    int sz = s.size();
    int a[sz];
    REP(i, sz) {
        a[i] = s[i] - 'a';
    }

    REP(i, sz) {
        if ( i == sz - 1 ) {
            a[i] = (a[i] + k) % 26;
            break;
        }
        if ( a[i] == 0 ) {
            continue;
        }
        int d = 26 - a[i];
        if ( k >= d ) {
            a[i] = 0;
            k -= d;
        }
    }

    REP(i, sz) {
        cout << static_cast<char>(a[i] + 'a');
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 896
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define K 10000

int n;

void CountingSort(unsigned short *A, unsigned short *B){
  int i, j, C[K+1];
  for( i = 0 ; i <= K ; i++ ){
    C[i] = 0;
  }
  for( j = 1 ; j <= n ; j++ ){
    
    C[A[j]]++;
  }
  for( i = 1 ; i <= K ; i++ ){
    C[i] = C[i] + C[i-1];
  }
  for( j = n ; j >= 1 ; j-- ){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
}

int main(){
  unsigned short *A, *B;
  int i, j;
  
  scanf("%d", &n);

  A = malloc(sizeof(short) * n + 1 );
  B = malloc(sizeof(short) * n + 1 );

  for( i = 0 ; i < n ; i++ ) scanf("%hu", &A[i+1]);

  CountingSort(A, B);

  for( i = 1 ; i <= n ; i++ ){
    if( i > 1 ) printf(" ");
    printf("%d", B[i]);
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 9636
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  ll n, c, k;
  cin >> n >> c >> k;
  vector<ll> t(n);
  rep(i,n) cin >> t[i];
  sort(ALL(t));
  ll ans = 0;
  for (ll i = 0; i < n;) {
    ans++;
    ll lim = t[i] + k;
    ll num = 0;
    while (i < n && t[i] <= lim && num < c) i++, num++;
  }
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 3968
#include<iostream>
#include<string>
#include<cstring>

using namespace std;

int main()
{
    string s,t,u;
    int a,b=0,c=0,d;
    cin >> a;
    for(int i = 0;i < a;i++){
        cin >> s >> t;
        if(s>t){
            b+=3;
        }else if(t>s){
            c+=3;
        }else{
            c++;
            b++;
        }
    }
    cout << b << " " << c << endl;

    return 0;
}


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

using namespace std;

#define int long long

int32_t main(){

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	int k,n,mx,i;
	cin>>k>>n;
	vector<int> a(n);

	for( i=0;i<n;i++)
		cin>>a[i];

	mx = a[0] + k - a[n-1];

	for(i=1; i<n; i++)
		mx=max(mx, a[i] - a[i-1]); 

	if(n==1)
		k+=a[0];
	
	cout<<k-mx;

	return 0;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  int n;
  cin >> n;
  int posx = 0, posy = 0, tprev = 0;
  bool check = true;
  for (int i = 0; i < n; i++) {
    int x, y, t;
    cin >> t >> x >> y;
    int temps = t - tprev;
    int desp = abs( x-posx) + abs(y-posy);
    if (desp > temps or (desp-temps)%2 != 0) check = false;
    posx = x;
    posy = y;
    tprev = t;
  }
  if (check) cout << "Yes\n";
  else cout << "No\n";
  
  return 0;
}



Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt(), n = sc.nextInt();
		int[] a = new int[n];
		List<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			list.add(sc.nextInt());
		}
		int r = Integer.MAX_VALUE;
		int res = -1;
		for (int i=-5;i<=100+5;i++) {
			if (!list.contains(i)) {
			int t = Math.abs(i - x);
				if (r > t) {
					r = t;
					res = i;
				}
			}
		}
		System.out.println(res);
	}
}


Measured memory_bytes: 35860
#include <bits/stdc++.h>
using namespace std;
int main(){

    long long int Q,H,S,D,N,A;
    cin >> Q >> H >> S >> D >>N;

    long long int a = min(2 * Q,H);
    long long int b = min(2 * a,S);
    long long int c = min(2 * b,D);
    
    A = c * (N / 2) + b * (N % 2);
    
    cout << A << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = [0]*(n+1)
for i in range(n+1):
    if b[a[i]] == 0:
        b[a[i]] += 1
    else:
        d = a[i]

l = 0
r = 0
c = 0
for i in range(n+1):
    if a[i] != d and c == 0:
        l += 1
    elif a[i] != d and c == 2:
        r += 1
    elif a[i] == d:
        c += 1


def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9 + 7
N = 100011
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

for i in range(1, n+2):
    print((cmb(n+1, i, mod)-cmb(r+l, i-1, mod))%mod)


Measured memory_bytes: 21928
N = int(input())
L = list(map(int, input().split()))

L.sort()
count = 0

for i in range(len(L)-2):
    for j in range(i+1, len(L)-1):
        for k in range(j+1, len(L)):
            if L[i] + L[j] > L[k] and L[i] != L[j] and L[i] != L[k] and L[j] != L[k]:
                count += 1

print(count)


Measured memory_bytes: 72812
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
const int mod = 1e9+7;

int main() {
    string sa, sb, sc; cin >> sa >> sb >> sc;
    queue<char> aq, bq, cq;
    rep(i,sa.size()) aq.push(sa[i]);
    rep(i,sb.size()) bq.push(sb[i]);
    rep(i,sc.size()) cq.push(sc[i]);
    char turn = 'a';
    while (true) {
        if (turn == 'a') {
            if (aq.empty()) {cout << 'A' << endl; return 0;}
            turn = aq.front(); aq.pop();
        }
        if (turn == 'b') {
            if (bq.empty()) {cout << 'B' << endl; return 0;}
            turn = bq.front(); bq.pop();
        }
        if (turn == 'c') {
            if (cq.empty()) {cout << 'C' << endl; return 0;}
            turn = cq.front(); cq.pop();
        }
    }
}

Measured memory_bytes: 256
a,b,c = map(int,input().split())
s = [a,b,c]
ans = 0

while a%2 + b%2 + c%2 == 0:
    na = (b + c) // 2
    nb = (a + c) // 2
    nc = (a + b) // 2
    
    if [na,nb,nc] == s:
        ans = -1
        break
        
    else:
        a = na
        b = nb
        c = nc
        ans += 1
        
print(ans)

Measured memory_bytes: 9172
import Foundation

func readInt() -> [Int]{
    return readLine()!.split(separator:" ").map{Int($0)!}
}

let xn = readInt()
let array = readInt()
for i in 0...xn[1]{
  guard let s = array.index(of: xn[0] - i) else{
    print(xn[0] - i)
    break
  }
  guard let t = array.index(of: xn[0] + i) else{
    print(xn[0] + i)
    break
  }
}

Measured memory_bytes: 13640