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

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

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int v[]=new int[n];
		for(int i=0; i<n; i++) {
				v[i]=sc.nextInt();
		}

		int e[] = new int[250000];
		int o[] = new int[250000];
		//0:key 1:value
		int emax1[] = {0,0};
		int emax2[] = {0,0};
		int omax1[] = {0,0};
		int omax2[] = {0,0};

		for(int i=0; i<n; i++) {
			if(i%2==0) {
				e[v[i]]++;
				if(emax1[1] < e[v[i]]) {
					emax1[0]=v[i];
					emax1[1]=e[v[i]];
				} else 	if(emax2[1] < e[v[i]]) {
					emax2[0]=v[i];
					emax2[1]=e[v[i]];
				}
			} else {
				o[v[i]]++;
				if(omax1[1] < o[v[i]]) {
					omax1[0]=v[i];
					omax1[1]=o[v[i]];
				} else if(omax2[1] < o[v[i]]) {
					omax2[0]=v[i];
					omax2[1]=o[v[i]];
				}
			}
		}
		int ans = 0;
		if(emax1[0]!=omax1[0]) {
			ans = n-emax1[1]-omax1[1];
		}else {
			ans = Math.min(n-emax1[1]-omax2[1], n-emax2[1]-omax1[1]);
		}
		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 50932
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val m = sc.nextInt()
    val a = Array(n) { sc.nextInt() }
    val sum = Array(n + 1) { 0L }
    for (i in 0 until n) {
        sum[i + 1] = sum[i] + a[i]
    }
    val map = mutableMapOf<Int, Long>()
    var ans = 0L
    for (i in 0 until n) {
        val r = (sum[i + 1] % m).toInt()
        ans += map[r] ?: 0
        if (r == 0) ans++
        map[r] = (map[r] ?: 0) + 1
    }
    println(ans)
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


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

typedef long long ll;

const ll INF = ll(1e18) + 1;

bool C(vector<ll> &A, ll K, ll x) {
    int n = (int)A.size();
    ll count = 0;
    for (int i = 0; i < n; i++) {
        if (A[i] < 0) {
            int l = -1, r = n;
            while (r - l > 1) {
                int mid = (l + r) / 2;
                if (A[mid] * A[i] < x) {
                    r = mid;
                } else {
                    l = mid;
                }
            }
            count += n - r;
        } else {
            int l = -1, r = n;
            while (r - l > 1) {
                int mid = (l + r) / 2;
                if (A[mid] * A[i] < x) {
                    l = mid;
                } else {
                    r = mid;
                }
            }
            count += l + 1;
        }
        if (A[i] * A[i] < x) {
            count--;
        }
    }
    count /= 2;
    return count < K;
}

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

    sort(A.begin(), A.end());
    ll lb = -INF, ub = INF;
    while (ub - lb > 1) {
        ll x = (lb + ub) / 2;
        if (C(A, K, x)) {
            lb = x;
        } else {
            ub = x;
        }
    }

    cout << lb << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<random>
#include<ctime>
#include<cstdlib>
#include<unordered_map>
#include<string.h>
#include<iostream>
#define P pair<int,int>
using namespace std;

int x[4] = { -1,0,0,1 }, y[4] = { 0,-1,1,0 };
string k[50];
int g[50][50];
signed main() {
	int a, b; cin >> a >> b;
	for (int i = 0; i < a; i++)cin >> k[i];
	int ans = 0;
	for (int i = 0; i < a; i++) {
		for (int j = 0; j < b; j++) {
			if (k[i][j] == '.')ans++;
		}
	}
	memset(g, -1, sizeof(g));
	queue<P>Q;
	g[0][0] = 0;
	Q.push({ 0,0 });
	while (Q.size()) {
		P i = Q.front(); Q.pop();
		for (int j = 0; j < 4; j++) {
			int dx = i.first + x[j], dy = i.second + y[j];
			if (dx >= 0 && dx < a&&dy >= 0 && dy < b&&k[dx][dy] == '.'&&g[dx][dy] == -1) {
				g[dx][dy] = g[i.first][i.second] + 1;
				Q.push({ dx,dy });
			}
		}
	}
	if (g[a - 1][b - 1] == -1) {
		puts("-1");
	}
	else {
		cout << ans - (g[a-1][b-1] + 1) << endl;
	}
}

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

int main(){
  double a,b,x;

  cin >> a >> b >> x;
  double s = x/a;
  double rad;

  if(s >= a*b/2){
    double h = (a*b - s)*2/a;
    rad = atan2(h,a);
  }

  else {
    double w = s*2/b;
    rad = atan2(b,w);
  }

  double pi = acos(-1);
  double deg = rad/(2*pi)*360;

  printf("%.10f\n", deg);
  return 0;
}


Measured memory_bytes: 4124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
//Yes,No
int main(){
    ll a,b,k;cin >> a >> b >> k;
    set<ll> st;
    for(int i=a;i<=b;++i){
        if(i<a+k || i>b-k)st.insert(i);
    }
    for(auto it: st){
        cout << it << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
  int a,b,c,sum;
  cin>>a>>b;
  c=b-a;
  
  for(int i=1;i<=c;i++){
    sum+=i;
  }
  cout<<sum-b<<endl;
}	


Measured memory_bytes: 256
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        
        loop:
        while((line = br.readLine()) != null){
            String[] input = line.split(" " , 3);
            int a = Integer.parseInt(input[0]);
            int b = Integer.parseInt(input[2]);

            switch(input[1]){
                case "?":
                    break loop;
                case "+":
                    System.out.println(a+b);
                    break;
                case "-":
                    System.out.println(a-b);
                    break;
                case "*":
                    System.out.println(a*b);
                    break;
                case "/":
                    System.out.println(a/b);
                    break;
            }

        }

    }
}

Measured memory_bytes: 24340
#include <iostream>
#include <math.h>
using namespace std;

int main(){
  long long int n, p, ans;
  cin >> n >> p;

  ans = pow( (long double)p, 1.0/(long double)n) + 1;
  while(ans > 1){
    if ( p % ( long long int)pow( (long long int)ans, (long long int)n ) == 0 ){
      break;
    }else{
      ans --;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

int dx[] = { -1, 0, 1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
/*
[1,pi]
E = 1*1/pi + 2*1/pi ... pi*1/pi = 1+2+3...+pi/pi=(pi+1)/2
*/

int main() {

	int n, k; cin >> n >> k;
	vector<int> p(n); for (int i = 0; i <= n - 1; i++) cin >> p[i];

	vector<long double> E(n);
	for (int i = 0; i <= n - 1; i++) {
		E[i] = ((p[i] + 1) / 2.0);
	}
	long double window = 0;
	long double max_window = 0;
	for (int i = 0; i <= n - 1; i++) {
		window += E[i];
		if (i >= k) window -= E[i - k];

		max_window = max(max_window, window);
	}
	cout << fixed << setprecision(15) ;
	cout << max_window;

	return 0;
}

Measured memory_bytes: 6824
n = int(input())
S = input()
a = []
while(S != ""):
  if len(S) != 1 and S[0] == S[1]:
    a.append(2)
    S = S[2:]
  else:
    a.append(1)
    S = S[1:]
if a[0] == 1:
  ans = 3
else:
  ans = 6
for i in range(0,len(a)-1):
  if a[i] == 1:
    ans *= 2
    ans %= 1000000007
  else:
    if a[i+1] == 2:
      ans *= 3
      ans %= 1000000007
print(ans)

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  ll N, ans = 0;
  cin >> N;
  vector<ll> H(N);
  vector<ll> t(N);
  rep(i,N)
    cin >> H[i];
  t[N-1] = 0;
  for (ll i=N-2; i>=0; i--) {
    if (H[i] >= H[i+1]) {
      t[i] = t[i+1] + 1;
    } else {
      t[i] = 0;
    }
    ans = max(ans, t[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
S = str(input())
SS = S[::-1]
N = len(S)
a = int((N-1)/2)
b = int((N+3)/2)
AS = S[:a]
ASS = AS[::-1]
BS = S[b-1:N]
BSS = BS[::-1]
if S == SS and AS == ASS and BS == BSS:
    print('Yes')
else:
    print('No')

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

#include <iomanip>

int main() {
    int a, b;
    cin >> a >> b;
    fixed; setprecision(5);
    cout << a/b << " " << a%b << " " << fixed << setprecision(5) << (double)a/b << endl;

    return 0;
}



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

int a[510][510],H,W,h,w;
int main()
{
	scanf("%d%d%d%d",&H,&W,&h,&w);
	if (!(H%h)&&!(W%w)) return puts("No"),0;
	puts("Yes");
	a[0][0]=(((H/h)*(W/w)) / ((H/h)+(W/w)-1))+1000000;
	a[h-1][w-1]=-a[0][0]-1;
	for (int i=0;i<H;i++,puts(""))
	for (int j=0;j<W;j++)
		printf("%d ",a[i%h][j%w]);
	return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=998244353,MAX=100005,INF=1<<28;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N;cin>>N;
        int sum=0,cnt=0;
        if(N==0) break;
        
        vector<int> A(N);
        
        for(int i=0;i<N;i++){
            cin>>A[i];
            sum+=A[i];
        }
        
        for(int i=0;i<N;i++){
            if(A[i]*N<=sum) cnt++;
        }
        
        cout<<cnt<<endl;
    }
}



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

int change[6] = {500, 100, 50, 10, 5, 1};

int main(void){
	int mon, cnt;
	while(true){
		cin >> mon;
		if(mon == 0)	break;
		mon = 1000 - mon;
		cnt = 0;
		for(int i = 0; i < 6; i++){
			if(mon == 0)	break;
			cnt += mon / change[i];
			mon -= change[i] * (mon / change[i]);
		}
		cout << cnt << endl;
	}
  return 0;
}

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

int main(int argc, char const *argv[]) {
  double x1, y1, x2, y2;

  cin >> x1 >> y1 >> x2 >> y2;

  printf("%.6f", sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));

  return 0;
}



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

int main(){
    int a,b,c,x;
    int ans=0;
    cin >> a>>b>>c>>x;

    for (int i = 0; i <= c; i++){
        for (int j = 0; j <= b; j++){
            for (int k = 0; k <= a; k++){
            
                if(x == 50*i+100*j+500*k)ans++;
            
            }
        }
    }

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


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

using namespace std;

int main() {
    int a, b;

    cin >> a >> b;

    int fee;

    if (a >= 13) {
        fee = b;
    } else if (6 <= a && a <= 12) {
        fee = b / 2;
    } else {
        fee = 0;
    }

    cout << fee << endl;

    return 0;
}

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

const int N=1e5+5;
const ll MD=1e9+7;
const ll INF=1e16;
int n,m,s,t;
ll d[N],d2[N],f[N],g[N];
bool vst[N];
vector<int> bw[N];
vector<pair<int,ll>> adj[N];
vector<pair<pair<int,int>,ll>> edges;

ll traverse(int u){
	if(f[u]!=-1) return f[u];
	f[u]=0;
	for(int v:bw[u])
		(f[u]+=traverse(v))%=MD;
	return f[u];
}

ll traverse2(int u){
	if(g[u]!=-1) return g[u];
	g[u]=0;
	for(int v:bw[u])
		(g[u]+=traverse2(v))%=MD;
	return g[u];
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n>>m>>s>>t;
	for(int i=0;i<m;++i){
		int u,v;
		ll c;
		cin>>u>>v>>c;
		edges.emplace_back(make_pair(u,v),c);
		adj[u].emplace_back(v,c);
		adj[v].emplace_back(u,c);
	}
	for(int i=1;i<=n;++i) d[i]=INF;
	d[s]=0;
	priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> Q;
	Q.push(make_pair(d[s],s));
	while(!Q.empty()){
		int u=Q.top().second;
		ll dist=Q.top().first;
		Q.pop();
		if(dist>d[u]) continue;
		vst[u]=true;
		for(auto nxt:adj[u]){
			if(!vst[nxt.first]&&dist+nxt.second<d[nxt.first]){
				d[nxt.first]=dist+nxt.second;
				Q.push(make_pair(d[nxt.first],nxt.first));
				bw[nxt.first].clear();
				bw[nxt.first].push_back(u);
			}
			else if(dist+nxt.second==d[nxt.first]){
				bw[nxt.first].push_back(u);
			}
		}
	}
	memset(f,-1,sizeof f);
	f[s]=1;
	traverse(t);
	memset(vst,false,sizeof vst);
	for(int i=1;i<=n;++i) d2[i]=INF;
	d2[t]=0;
	Q.push(make_pair(d2[t],t));
	while(!Q.empty()){
		int u=Q.top().second;
		ll dist=Q.top().first;
		Q.pop();
		if(dist>d2[u]) continue;
		vst[u]=true;
		for(auto nxt:adj[u]){
			if(!vst[nxt.first]&&dist+nxt.second<d2[nxt.first]){
				d2[nxt.first]=dist+nxt.second;
				Q.push(make_pair(d2[nxt.first],nxt.first));
				bw[nxt.first].clear();
				bw[nxt.first].push_back(u);
			}
			else if(dist+nxt.second==d2[nxt.first]){
				bw[nxt.first].push_back(u);
			}
		}
	}
	memset(g,-1,sizeof g);
	g[t]=1;
	traverse2(s);
	ll total=f[t]*f[t]%MD;
	ll path=d[t];
	for(int i=1;i<=n;++i)
		if(d[i]==d2[i]&&d[i]+d2[i]==path){ // Taka and Aoki meet at node i
			ll ways=f[i]*f[i]%MD;
			ways=ways*g[i]%MD*g[i]%MD;
			total=(total-ways+MD)%MD;
		}
	for(auto e:edges){
		int u=e.first.first;
		int v=e.first.second;
		ll len=e.second;
		if(d[u]>d[v]) swap(u,v);
		if(d[u]*2<path&&d2[v]*2<path&&d[u]+d2[v]+len==path){ // Taka and Aoki meet on edge that links u and v
			ll ways=f[u]*f[u]%MD;
			ways=ways*g[v]%MD*g[v]%MD;
			total=(total-ways+MD)%MD;
		}
	}
	cout<<total<<'\n';
}




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


int main(){
    string S;
    cin >> S;
    int A[26] = {0};
    for (int i = 0; i < S.size(); i++)
    {
        A[S[i]-'a']++;
    }
    for (int i = 0; i < 26; i++)
    {
        if(A[i] == 0){
            cout << (char)(i + 'a') << endl;
            return 0;
        }
    }
    
    cout << "None" << endl;
    return 0;
}

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



int main(){
    //input    
    int N;
    vector<int>V(N),C(N);
    cin >> N;
    for (int i = 0; i < N; i++){
        cin >> V[i];
    }
    for (int i = 0; i < N; i++){
        cin >> C[i];
    }

    //example

    int ans = 0;
    for(int i = 0; i < N; i++){
        if(V[i] - C[i] >= 0){
            ans = ans + V[i] - C[i];
        }
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
N = int(input())
L = sorted([int(input()) for i in range(N)])
i = 0
while sum(L) != 0 and sum(L) % 10 == 0 and i < len(L):
  if L[i] % 10 == 0:
    i += 1
  else:
    L.pop(i)
else:
  print(0 if sum(L) % 10 == 0 else sum(L))

Measured memory_bytes: 3060
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  ll ans = 0;
  for(int i = 1; i <= n; i++)
    ans += 1LL * i * (n + 1 - i);
  for(int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    if(a > b) swap(a, b);
    ans -= 1LL * a * (n + 1 - b);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3640
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val S = sc.nextLine().reverse.toList

    def loop(S: List[Char]): Boolean =
      S match {
        case Nil => true
        case 'r' :: 'e' :: 'm' :: 'a' :: 'e' :: 'r' :: 'd' :: t => loop(t)
        case 'm' :: 'a' :: 'e' :: 'r' :: 'd' :: t => loop(t)
        case 'r' :: 'e' :: 's' :: 'a' :: 'r' :: 'e' :: t => loop(t)
        case 'e' :: 's' :: 'a' :: 'r' :: 'e' :: t => loop(t)
        case _ => false
      }

    println(if (loop(S)) "YES" else "NO")
  }

}


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

const ll MOD = 1000000007;
const ll MAX = 1001;

int main(){
  ll N, A, B; cin >> N >> A >> B;
  ll ans = 0;
  ll prv; cin >> prv;
  for(ll i = 1; i < N; i++){
    ll now; cin >> now;
    ans += min(A * (now - prv), B);
    prv = now;
  }
  cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100005
#define INF 1000000005
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000005;
const int MOD = 998244353;
int main(){
    int n;
    cin>>n;
    vector<string>s(n);
    REP(i,n)cin>>s[i];
    struct u
    {
        /* data */
        int a;
        int x;
        int i;
    };
    vector<pair<pair<int,int>,int>>ab(n);
    REP(i,n){
        int a=0;
        int b=0;
        REP(j,SZ(s[i])){
            if(s[i][j]=='(')a++;
            else b++;
        }
        if(a>=b){
            ab[i].first.first=-1;
            ab[i].first.second=b;
        }
        else {
            ab[i].first.first=1;
            ab[i].first.second=-a;
        }
        ab[i].second=i;
    }
    sort(ALL(ab));
    int a=0;
    int b=0;
    bool f=true;
    REP(i,n){
        int p=ab[i].second;
        REP(j,SZ(s[p])){
            if(s[p][j]=='('){
                a++;
            }else{
                b++;
                if(a<b){
                    f=false;
                    break;
                }
            }
        }
        if(!f)break;
    }
    if(a!=b)f=false;
    if(f)OUT("Yes");
    else OUT("No");
    return 0;
}

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

public class Main {


    public Main(FastScanner in, PrintWriter out) {
        int N = in.nextInt();
        int K = in.nextInt();
        int lo = 1, hi = 0;
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = in.nextInt();
            hi = Math.max(hi, A[i]);
        }

        while (lo < hi) {
            int mid = lo + (hi - lo) / 2;
            int cut = 0;
            for (int h : A) {
                cut += (h - 1) / mid;
            }
            if (cut <= K) hi = mid;
            else lo = mid + 1;
        }
        out.println(hi);
    }

    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        // Scanner in = new Scanner(
                // new BufferedReader(new InputStreamReader(System.in)));
        FastScanner in = new FastScanner(System.in);

        Main sol = new Main(in, out);

        out.close();
    }
}


class FastScanner{
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

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

    int read()
    {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars){
            curChar = 0;
            try{
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    boolean isSpaceChar(int c)
    {
        return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
    }

    boolean isEndline(int c)
    {
        return c=='\n'||c=='\r'||c==-1;
    }

    int nextInt()
    {
        return Integer.parseInt(next());
    }

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

    double nextDouble()
    {
        return Double.parseDouble(next());
    }

    String next(){
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do{
            res.appendCodePoint(c);
            c = read();
        }while(!isSpaceChar(c));
        return res.toString();
    }

    String nextLine(){
        int c = read();
        while (isEndline(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do{
            res.appendCodePoint(c);
            c = read();
        }while(!isEndline(c));
        return res.toString();
    }
}


Measured memory_bytes: 53040
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int x;
	cin>>x;
	if(x==1)
	 cout<<"0";
	else
	 cout<<"1";
	return 0;
	
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
//*******************
// Mahmoud Magdy    *
//*******************
#define ll long long
#define endl "\n"

void fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
inline int D()
{
    int m ;
    cin>>m;
    return m ;
}
inline ll lD()
{
    ll m ;
    cin>>m;
    return m ;
}
inline double dD()
{
    double m ;
    cin>>m;
    return m ;
}

int main()
{
int n , a;
  n=D();a=D();
  if(n%500==0){
    cout<<"Yes"<<endl;
   return 0;
 }
 int x= n/500;
 int y= n-(x*500);
 if(a>=y)
    cout<<"Yes"<<endl;
 else
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

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

	map<string,int>mp;
	int n;
		cin>>n;
	vector<int> v(4);


	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		if(s=="AC"){
			v[0]++;
		}else if(s=="WA"){
			v[1]++;
		}else if(s=="TLE"){
			v[2]++;
		}else if(s=="RE"){
			v[3]++;
		}
	}
	cout<<"AC x "<<v[0]<<endl;
	cout<<"WA x "<<v[1]<<endl;
	cout<<"TLE x "<<v[2]<<endl;
	cout<<"RE x "<<v[3]<<endl;


	return 0;
}


Measured memory_bytes: 3644
n, m = map(int, input().split())
set_A = set()
dp = [0]*n
mod = pow(10, 9) + 7

for _ in range(m):
    set_A.add(int(input()))

if 1 not in set_A:
    dp[0] = 1
if 2 not in set_A and n != 1:
    dp[1] = 1 + dp[0]

for i in range(2, n):
    if i + 1 not in set_A:
        dp[i] += (dp[i-1] + dp[i-2])%mod

print(dp[n-1])

Measured memory_bytes: 18104
import java.util.*;
class Main {
    public static void main(String... args) {
        Scanner scan = new Scanner(System.in);
        int vertical = scan.nextInt();
        int horizon  = scan.nextInt();
        int[][] container = new int[vertical][horizon];
        for(int v = 0; v < vertical; v++) {
            for (int h = 0; h < horizon;  h++) {
                container[v][h] = scan.nextInt();
            }
        }
        for(int h = 0; h < horizon; h++) {
            int multi = scan.nextInt();
            for (int v = 0; v < vertical;  v++) {
                container[v][h] *= multi;
            }
        }
        for(int v = 0; v < vertical; v++) {
            int total = 0;
            for (int h = 0; h < horizon;  h++) {
               total += container[v][h];
            }
            System.out.println(total);
        }
    }
}


Measured memory_bytes: 40028
N,M,X = map(int, input().split())

def python_list_add(in1, in2):
    return [a + b for a, b in zip(in1, in2)]

A = []
for i in range(N):
	A.append(list(map(int, input().split())))

m = 1e9
for i in range(2 ** N):
	total = [0] * (M+1)
	for j in range(N):
		if((i >> j) & 1):
			total = python_list_add(total, A[j])
	if(all(elem >= X for elem in total[1:])):
		m = min(total[0],m)
if m == 1e9:
	m = -1
print(m)

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

using namespace std;

int main(void)
{
	int n;
	char c;
	string s;
	int num[4]={};
	while(cin>>n>>c>>s)
	{
		if(s=="A")num[0]++;
		else if(s=="B")num[1]++;
		else if(s=="AB")num[2]++;
		else num[3]++;
	}
	for(int i=0;i<4;i++)
	{
		cout<<num[i]<<endl;
	}
}

Measured memory_bytes: 1208
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
template <class T>
ostream& operator<<(ostream& output, const vector<T>& v) {
    for (auto itr = v.begin(); itr != v.end() - 1; ++itr) output << *itr << " ";
    output << v.back();
    return output;
}
int main() {
    ll N, S = 0;
    cin >> N;
    vector<ll> A(N), ans(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        S += A[i];
        if (!(i & 1) && i != N - 1) S -= 2 * A[i];
    }
    ans.back() = S;
    for (int i = N - 2; i >= 0; i--) ans[i] = 2 * A[i] - ans[i+1];
    cout << ans << endl;
}

Measured memory_bytes: 2944
#include<iostream>

using namespace std;

int main() {
    int a[5];
    int k;
    int diff;
    for(int i = 0; i < 5; i++) {
        cin >> a[i];
    }
    cin >> k;

    diff = a[4] - a[0];
    if (diff <= k) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<typename T>
inline void read(T &x)
{
	x=0;
	int 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^48),ch=getchar();
	x*=f;
	return;
}	
template<typename T>
void write(T x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);
	putchar(x%10+'0');
	return;
}
long long h,w;
long long ans=0;
int main()
{
    cin>>h>>w;
    if(h==1||w==1)
    {
        cout<<1<<endl;
        return 0;
    }
    if((h*w)&1) cout<<(h*w)/2+1<<endl;
    else cout<<(h*w)/2<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
typedef long long ll;
#define rep(i,a,b) for(ll i =a ;i <= b;i++)
#define per(i,a,b) for(ll i =a ;i >= b;i--)
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;




int main()
{
	//ifstream cin("input.txt");
	int n;
	cin>>n;
	vi nums(n);
	rep(i,0,n-1)
		cin>>nums[i];

	int mi = *(min_element(nums.begin(), nums.end()));
	int mx = *(max_element(nums.begin(), nums.end()));
	int mid = (mx+mi)/2;
	ll sum = 0, min_sum = INT_MAX;
	rep(x, mi,mx)
	{
		sum = 0;
		for(int i : nums)
			sum += (x - i)*(x - i);

		min_sum = min(sum, min_sum);
	}
	

	cout<<min_sum;
	
}

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

int main()
{
  int n;
  cin >> n;
  vector<int> p(n);
  for (auto i = 0; i < n; i++) {
    cin >> p[i];
  }
  sort(begin(p), end(p));
  p[n - 1] /= 2;
  int ans = accumulate(begin(p), end(p), 0);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring>
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));

signed main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    string s; cin >> s;
    int n=s.size();
    if(s[n-1]=='s') s+="es";
    else s+='s';
    cout << s << endl;
}




Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto x:v)cerr<<x<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define EPS 1e-9
typedef long long ll;

long long POW(long long x,long long n,long long mod){
  long long ans = 1;
  while(n){
    if(n%2)ans *= x;
    x *= x;
    x %= mod;
    ans %= mod;
    n >>= 1;
  }
  return ans;
}
vector<long long> factorial(2,1);
long long nckmodp(long long n,long long k,long long p){
  if(n < k || n <= 0 || k < 0)return 0;
  while(factorial.size() <= n){
    long long i = factorial.size();
    factorial.push_back(i*factorial[i-1]%p);
  }
  return ((factorial[n]*POW(factorial[k],p-2,p))%p)*POW(factorial[n-k],p-2,p)%p;
}
long long TwelvefoldWay9(long long n,long long k,long long MOD){
  long long ans = 0;
  for(long long i = 1;i <= k;i++){
    ans += ((k-i)%2 ? -1 : 1)*nckmodp(k,i,MOD)*POW(i,n,MOD);
    ans = (ans%MOD+MOD)%MOD;
  }
  return (ans*POW(factorial[k],MOD-2,MOD))%MOD;
}

signed main(){
  ll n,k;
  cin >> n >> k;
  cout << TwelvefoldWay9(n,k,INF) << endl;
}


Measured memory_bytes: 3160
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ld, ld> P;
typedef vector<ld> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ld a;
    string b;
    cin>>a>>b;
    ld c=(b[0]-'0')*100+(b[2]-'0')*10+(b[3]-'0');
    cout<<ll(a*c/100.00)<<endl;
}


Measured memory_bytes: 3764
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int sum = 0;
        
        for (int i = 0; i < 5; i++) {
            int score = sc.nextInt();
            if (score < 40) {
                score = 40;
            }
            sum += score;
        }
        
        int avg = sum / 5;
        System.out.println(avg);
    }
}


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

int main() {
  string S;
  cin >> S;
   bool d = true;
  for (int i = 0; i < S.size(); i+=2){
    if (S.at(i) == 'L')
      d = false;
    } 
  for (int i = 1; i < S.size(); i+=2){
    if (S.at(i) == 'R')
      d = false;
  }  
 cout << ((d == true) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int dest(int x1, int y1, int x2, int y2) {
	return abs(x1 - x2) + abs(y1 - y2);
}

int main() {
	int n, m;
	int *a, *b, *c, *d;

	scanf("%d %d", &n, &m);

	a = (int *)malloc(sizeof(int) * n);
	b = (int *)malloc(sizeof(int) * n);
	c = (int *)malloc(sizeof(int) * m);
	d = (int *)malloc(sizeof(int) * m);

	int i, j;
	for(i=0;i<n;i++) {
		scanf("%d %d", &a[i], &b[i]);
	}
	for(i=0;i<m;i++) {
		scanf("%d %d", &c[i], &d[i]);
	}

	int pos[50];

	for(i=0;i<n;i++) {
		int min = 400000000;
		int min_idx;
		for(j=0;j<m;j++) {
			int dest_t = dest(a[i], b[i], c[j], d[j]);
			if(dest_t < min) {
				min = dest_t;
				min_idx = j;
			}
		}
		pos[i] = min_idx;
	}
	for(i=0;i<n;i++) {
		printf("%d\n", pos[i] + 1);
	}
	
	free(a);
	free(b);
	free(c);
	free(d);
	return 0;
}


Measured memory_bytes: 128
N = int(input())
S = input()
T = list(1 if c == "(" else -1 for c in S)
l, l_min = 0, 0
r, r_min = 0, 0
for i in range(N):
    l += T[i]
    l_min = min(l_min, l)
    r -= T[N - i - 1]
    r_min = min(r_min, r)
print("".join(["(" * -l_min, S, ")" * -r_min]))

Measured memory_bytes: 9104
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
const int INF = 1e18, MOD = 1e9 + 7;
signed main() {
    INCANT;
    string s;
    int n;
    cin>>n>>s;
    each(c, s) {
        c += n;
        if(c > 90) {
            c -= 26;
        }
        cout<<c;
    }
    cout<<endl;
}


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

int main(){
    int N;
    cin >> N;
    ll a[N];
    for(int i=0; i<N; i++) cin >> a[i];
    ll ans[N];
    ll S = 0;
    for(int i=0; i<N; i++) S += a[i];
    ll sum = 0;
    for(int i=1; 2*i<N; i++) sum += 2*a[2*i-1];
    ans[0] = S - sum;
    for(int i=1; i<N; i++){
        ans[i] = 2*a[i-1] - ans[i-1];
    }
    for(int i=0; i<N; i++) printf("%lld ", ans[i]);
    printf("\n");
    return 0;
}

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

using namespace std;

int main(){
    int n;cin>>n;
    int m[8]={};
    int target=0;
    for(int i=0;i<n;++i){
        int a;cin>>a;
        if(a>=3200){
            target++;
            continue;
        }
        m[a/400]=1;
    }
    int ans1=0;
    for(int i=0;i<8;++i){
        if(m[i])ans1++;
    }
    int ans2=ans1+target;
    if(!ans1)ans1=1;
    cout<<ans1<<" "<<ans2<<endl;
}


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

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			long[] a = new long[n], b = new long[n];
			boolean isSame = true;
			long sum = 0;
			long min = Long.MAX_VALUE/2;
			for (int i = 0; i < n; i++) {
				a[i] = in.nextLong();
				b[i] = in.nextLong();
				if (a[i] != b[i]) isSame = false;
				sum += b[i];
				if (a[i] > b[i]) {
					min = Math.min(min, b[i]);
				}
			}

			if (isSame) {
				out.println(0);
				return;
			}

			out.println(sum-min);
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

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

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 33312
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        mut v: [usize; n]
    }
    let d = 1000000007;
    v.sort();
    let mut ans = 0;
    for i in 0..n {
        ans = (ans + (n - i + 1) * v[i] % d) % d;
    }
    ans = ans * pow_m(2, 2 * n - 2, d) % d;
    println!("{}", ans);
}

fn pow_m(n: usize, mut p: usize, d: usize) -> usize {
    let mut r = n;
    let mut ret = 1;
    while p > 0 {
        if p % 2 == 0 {
            r = r * r % d;
            p /= 2;
        } else {
            ret = ret * r % d;
            p -= 1;
        }
    }
    ret
}


Measured memory_bytes: 6396
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
import numpy as np

N, X, Y = map(int, input().split())
X -= 1
Y -= 1
a = list(range(N - 1)) + [X]
b = list(range(1, N)) + [Y]

matrix = csr_matrix(([1] * N, (a, b)), shape=(N, N))
distance = dijkstra(matrix, directed=False).astype(int)
answer = np.bincount(distance.flatten())[1:] // 2
answer = answer.tolist()
answer += [0] * (N - 1 - len(answer))
print('\n'.join(map(str, answer)))


Measured memory_bytes: 76604
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val d = readLine()!!.split(" ").map { it.toInt() }
    var hp = 0L
    for(i in d.indices) {
        for(j in d.indices) {
            if(i == j) continue
            if(i > j) continue
            hp += (d[i] * d[j]).toLong()
        }
    }
    println(hp)
}

Measured memory_bytes: 37576
def solve():
    N, K = map(int, input().split())
    *P, = map(int, input().split())
    *C, = map(int, input().split())
    ans = -float("inf")

    for pos in range(N):
        used = [-1] * N
        cost = [0] * (N+1)

        for k in range(N+1):
            if k:
                cost[k] = cost[k-1] + C[pos]
            if used[pos] >= 0:
                loop_size = k-used[pos]
                break
            used[pos] = k
            pos = P[pos] - 1
        if cost[loop_size] <= 0:
            ans = max(ans, max(cost[1:K+1]))
        else:
            a, b = divmod(K, loop_size)
            v1 = cost[loop_size] * (a-1) + max(cost[:K+1])
            v2 = cost[loop_size] * a + max(cost[:b+1])
            ans = max(ans, max(v1, v2) if a else v2)

    print(ans)

solve()


Measured memory_bytes: 81508
import numpy as np

n,x = list(map(int,input().split()))
a = list(map(int,input().split()))
a.sort()

cum = np.cumsum(a)

if x == cum[-1]:
    print(n)
elif x > cum[-1]:
    print(n-1)
else:
    temp = cum <= x
    print(sum(temp))

Measured memory_bytes: 22032
#include <iostream>
#include<algorithm>
using namespace std;
int main()
{   ios_base::sync_with_stdio(false);
     cin.tie(NULL);
      cout.tie(NULL);
  
  int a[3];
  for(int i=0;i<3;i++)
  {
    cin>>a[i];
  }
 sort(a,a+3);
 if(a[0]==5&&a[1]==5&&a[2]==7)
   cout<<"YES";
 else
   cout<<"NO";
   
  return 0;}


Measured memory_bytes: 3044
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <iterator>
#include <climits>
#include <unordered_map>
#include <functional>
#include <queue>

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

#define p2(a, b) cout << a << "\t" << b << endl
#define p3(a, b, c) cout << a << "\t" << b << "\t" << c << endl

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

inline int ctoi(char c) {
    return (int)(c -'0');
}

// ----------------------------------------------------------

int main() {
    ll n;
    cin >> n;
    ll number = 0;
    while (number*number <= n) {
        ++number;
    }
    cout << (number-1)*(number-1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
        long long int n; cin >> n;
        map<long long int, long long int> mp;
        for (long long int x = 0; x < n; ++x){
            long long int q; cin >> q;
            mp[q]++;
        }
        long long int c = 0;
        for (auto x : mp){
            if (x.second % 2 != 0) c++;
        }
        cout << c << endl;
    return 0;
}


Measured memory_bytes: 9720
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;


int main(){
	int n,k,a[2222]={},b[2020]={};
	cin>>n>>k;
	vector<vector<int>> g=vector<vector<int>>(n+1,vector<int>());
	FOR(i,0,n-1){
		cin>>a[i]>>b[i];
		g[a[i]].PB(b[i]);
		g[b[i]].PB(a[i]);
	}
	int ans=mod;
	FOR(i,0,n){
		queue<int> q;
		vector<int> v(n+1,-1);
		int scr=0;
		if(k&1){
			if(i==n-1)break;
			v[a[i]]=0;
			v[b[i]]=0;
			q.push(a[i]);
			q.push(b[i]);

		}else{
			v[i+1]=0;
			q.push(i+1);
		}
		while(q.size()){
			int t=q.front();
			q.pop();
			int l=g[t].size();
			FOR(j,0,l){
				if(v[g[t][j]]!=-1)continue;
				v[g[t][j]]=v[t]+1;
				if(v[g[t][j]]>k/2)scr++;
				q.push(g[t][j]);
			}
		}
		ans=min(ans,scr);
		cerr<<i<<" "<<scr<<endl;
	}
	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
def minkowski_dist(vx, vy, p):
    if p == float("inf"):
        return max([abs(x - y) for x, y in zip(vx, vy)])
    else:
        return sum([abs(x - y)**p for x, y in zip(vx, vy)])**(1 / p)


n = int(input())
vx = [int(c) for c in input().split()]
vy = [int(c) for c in input().split()]
for p in [1, 2, 3, float("inf")]:
    print("%.6f" % minkowski_dist(vx, vy, p))



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

int main() {
    int n, t, cnt = 0;
    cin >> n;
    rep(i, n) {
        cin >> t;
        if(t != i + 1) cnt++;
    }
    if(cnt <= 2) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
const long long INF = INT_MAX / 2;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define ll long long int
using namespace std;
ll ans = 0, sum = 0, n, k, cnt = 0, w, h;
string s;
vector<ll> v;
vector<ll> v1;
vector < pair<ll, ll > > vp;
vector<vector<ll> > vv(50, vector<ll>(50, INF));
vector<string> vs;
vector<char> vc;
set<ll> st;
map<char, ll> mp;

/*--------------------template--------------------*/

int main()
{
	cin >> n >> k >> h;
	FOR(i,n,k+1)
	{
		if (h % i == 0) cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3160