akhauriyash/Code-Regression huggingface dataset:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#define ll long long

int main(){
    ll ans = 0;
    int N;
    int A[100001], count[100001] = {0};
    scanf("%d", &N);
    for(int i=0;i<N;i++){
        scanf("%d", &A[i]);
        ans += A[i];
        count[A[i]]++;
    }
    int Q;
    scanf("%d", &Q);
    int B[Q], C[Q];
    for(int i=0;i<Q;i++){
        scanf("%d %d", &B[i], &C[i]);
    }

    for(int i=0;i<Q;i++){
        count[C[i]] += count[B[i]];
        ans += (C[i]-B[i]) * count[B[i]];
        count[B[i]] = 0;
        printf("%lld\n", ans);
    }
    return 0;
}



Measured memory_bytes: 3284
#include<stdio.h>
int main()
{
	int a,b,A,B,C,D; 
	scanf("%d%d%d%d",&A,&B,&C,&D);
	{
		if(A<D&&C<B)
		{
			if(A<C){a=C;}
			else{a=A;}
			if(B<D){b=B;}
			else{b=D;}
			printf("%d\n",b-a);
		}
		else
		printf("0\n");
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    String[] str = sc.next().split("-");
    if(str.length == 2){
      if(str[0].length() == a && str[1].length() == b){
        System.out.println("Yes");
      }else{
        System.out.println("No");
      }
    }else{
      System.out.println("No");
    }
  }
}

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

#define ll long long
#define pb push_back

int main(){

	int N, M;
	vector<int> X;
	cin >> N >> M;
	if(N >= M){
		cout << 0 << endl;
		return 0;
	}
	for(int i = 0; i < M; i ++){
		int x;
		cin >> x;
		X.pb(x);
	}
	sort(X.begin(), X.end());
	ll ans = X[X.size() - 1] - X[0];
	vector<int>	dif;
	for(int i = 1; i < M; i ++){
		dif.pb(X[i] - X[i - 1]);
	}
	sort(dif.begin(), dif.end());
	for(int i = 0; i < N - 1; i ++){
		ans -= dif[dif.size() - 1 - i];
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1400
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>

using namespace std;

typedef long long ll;
typedef long double ld;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mis map<int,string>
#define msi map<string,int>
#define mll map<ll,ll>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep1(i,n) for(int i=1; i<=(int)(n); i++)
#define all(c) c.begin(),c.end()
#define srta(a) sort(all(a))
#define srtd(a) sort(all(a),greater<型>())
#define rvs(s) reverse(all(s))
#define psb push_back
#define ppb pop_back
#define isu isupper
#define isl islower
#define lb(a,k) lower_bound(all(a),k)
#define ub(a,k) upper_bound(all(a),k)
#define bs(a,k) binary_search(all(a),k)

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const int I_INF = 1001001001;
const ll LL_INF = 1001001001001001001;
const ld EPS = 0.001;

int main() {
    ll N;
    cin >> N;
    vi a(N);
    rep (i, N) cin >> a[i];

    int cnt = 0;
    rep (i, N) {
        bool o = ((i+1)%2 == 1);
        if (!o) continue;
        if (a[i]%2 == 1) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3548
num = int(input())
p1 = num//100
p2 = num%100

if (p1<=12 and p1>=1) and (p2>12 or p2==0):
  print('MMYY')
if (p2<=12 and p2>=1) and (p1>12 or p1==0):
  print('YYMM')
if (p1<=12 and p1>=1) and (p2<=12 and p2>=1):
  print('AMBIGUOUS')
if (p2>12 or p2==0) and (p1>12 or p1==0):
  print('NA')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int N=100100;
int n,K,fa[N],ans,mx[N];
vector<int>g[N];
void dfs(int x){
	mx[x]=1;
	for(int i:g[x]){
		dfs(i);
		if(mx[i]>=K&&x!=1)++ans;
		else mx[x]=max(mx[x],mx[i]+1);
	}
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>K;
	for(int i=1;i<=n;++i)cin>>fa[i];
	if(fa[1]!=1)fa[1]=1,++ans;
	for(int i=2;i<=n;++i)g[fa[i]].push_back(i);
	dfs(1);
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 11264
#include<iostream>
#include<algorithm>

using namespace std;

int main() {

	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;

	
	
	int mn = 1001001001;

	int m;

	for (int i = 0; i <= max(2*x,2*y); i = i + 2) {

		m = i * c + max(x - i/2, 0) * a + max(y - i/2, 0) * b;
		if (mn > m) {
			mn = m;
		}

	}
	cout << mn << endl;

	return 0;
}

Measured memory_bytes: 256
/* Coached by Dukkha */
#include <stdio.h>

long long solve(long long a, long long b, long long c) {
	return b / c - (a - 1) / c;
}

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}

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

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

	scanf("%lld%lld%d%d", &a, &b, &c, &d);
	printf("%lld\n", b - a + 1 - solve(a, b, c) - solve(a, b, d) + solve(a, b, lcm(c, d)));
	return 0;
}


Measured memory_bytes: 128
import std.stdio;
import std.string;
import std.algorithm;
import std.array;
import std.conv;
import std.typecons;

long n, m;
long[string] assoc;
string[] cands;

long[long] dp;

long make_dp(long x) {
  if (x in dp) {
    return dp[x];
  }
  if (x < 0) {
    return long.min / 2;
  }

  auto max = long.min / 2;
  foreach (c; cands) {
    auto r = make_dp(x - assoc[c]) + 1;
    if (r > max) {
      max = r;
    }
  }
  dp[x] = max;

  return dp[x];
}

void main() {
  foreach (i, x; [2,5,5,4,5,6,3,7,6]) {
    assoc[(i+1).to!string] = x;
  }

  readf("%d %d\n", &n, &m);
  cands = readln.strip.split(" ").array;
  cands = sort!"a > b"(cands).array;
  dp[0] = 0;
  make_dp(n);

  string ans = "";
  while (n > 0) {
    foreach (c; cands) {
      auto next = n - assoc[c];
      if (next in dp && dp[next] == dp[n]-1) {
        n -= assoc[c];
        ans ~= c;
        break;
      }
    }
  }

  writeln(ans);
}


Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,q,i,x,y,same = 0;scanf("%d",&n);
    int a[n],s[n];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        s[i] = a[i];
    }
    sort(s,s+n);
    for(i=0;i<n;i++){
        if(a[i] == s[i]) same++;
    }
    scanf("%d",&q);
    for(i=0;i<q;i++){
        if(same == n){
            printf("%d\n",i);return 0;
        }
        scanf("%d%d",&x,&y);x--;y--;
        if(a[x] == s[x]) same--;
        if(a[y] == s[y]) same--;
        swap(a[x],a[y]);
        if(a[x] == s[x]) same++;
        if(a[y] == s[y]) same++;
    }
    printf("%d\n",(same==n ? q:-1));
}


Measured memory_bytes: 5608
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,*a = map(int,read().split())

MOD = 10**9+7


res = [0]*(n)
for i in a:
    res[i] += 1

if n&1:
    if res[0]==1 and all(ri==2 for ri in res[2::2]):
        print(pow(2,n//2,MOD))
    else:
        print(0)
else:
    if all(ri==2 for ri in res[1::2]):
        print(pow(2,n//2,MOD))
    else:
        print(0)
    







Measured memory_bytes: 20432
#define __GLIBCXX_DEBUG

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <random>
#include <queue>
#include <bitset>

#define pb push_back
#define int long long
#define dbl long double
#define str string
using namespace std;
const int M = 998244353;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    int ans = 0;
    for (int a = 1; a <= n; a++) {
        for (int b = 1; b <= n; b++) {
            for (int c = 1; c <= n; c++) {
                ans += __gcd(__gcd(a, b), c);
            }
        }
    }
    cout << ans;
}

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

using namespace std;

#define debug(x) '[' << #x << " is: " << x << "] "
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

template<int SZ> struct MAXM{
	vector<int> g[SZ];
	bool seen[SZ];
	int matchR[SZ],n,m;

	void init(int N,int M){
		n = N;
		m = M;
	}
		
	bool bpm(int u){ 
	    for(int v : g[u]){ 
	        if (!seen[v]){
	            seen[v] = true;
	            if (matchR[v] == -1 || bpm(matchR[v])){
	                matchR[v] = u; 
	                return true; 
	            }
	        }
	    }
	    return false; 
	} 
	void maxBPM(){
	    memset(matchR, -1, sizeof(matchR)); 
	    int result = 0;
	    for (int u=0;u<n; u++) { 
	        memset(seen, 0, sizeof(seen)); 
	        if (bpm(u)) result++;
	    } 
	    cout << result << endl;
	    // for(int i=0;i<SZ;i++){
	    // 	if(matchR[i] == -1)continue;
	    // 	cout << matchR[i] << ' ' << i << '\n';
	    // }
	}
};

MAXM<300> tree;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;
	#ifndef ONLINE_JUDGE
//		freopen("input.txt","r",stdin);
	#endif
	int n;
	cin>>n;
	tree.init(n,n);
	vector<pair<int,int>> p(n);
	for(int i=0;i<n;i++){
		cin>>p[i].first >> p[i].second;
	}
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		for(int j=0;j<n;j++){
			if(p[j].first < x && p[j].second < y){
				tree.g[j].push_back(i+n);
				tree.g[i+n].push_back(j);
			}
		}
	}
	tree.maxBPM();
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            char[] S = sc.next().toCharArray();

            int c = 0;
            for (int i = 0; i < N - 2; i++) {
                if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') {
                    c++;
                }
            }

            System.out.println(c);
        }
    }

}


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

using namespace std;
typedef vector<vector<int>> vvi;
#define REP(i,n) for (int i = 0; i < n; ++i)
#define MP make_pair

int N, M;
vvi s;
int p[11], K[11];

int main() {
    cin >> N >> M;
    s = vvi(M);
    REP (m, M) {
        cin >> K[m];
        s[m] = vector<int>(K[m]);
        REP (k, K[m]) {
            cin >> s[m][k];
            s[m][k]--;
        }
    }
    REP (i, M) cin >> p[i];

    int ans = 0;
    REP (i, 1<<N) {
        bool check = true;
        REP (m, M) {
            int count = 0;
            REP (k, K[m]) if (i&(1<<s[m][k])) count++;
            check &= (count%2 == p[m]);
        }
        if (check) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Procon
{
  public Procon() {}
  static void Main(string[] agrs)
  {
    new Procon().Do();
  }

  Scanner cin;

  public void Do()
  {
    cin = new Scanner();
    int N = cin.nextInt();
    int M = cin.nextInt();
    int[] ret = new int[M];
    for (int i=0; i < M; i++) {
      ret[i] = 0;
    }
    for (int i=0; i<N; i++) {
      int k = cin.nextInt();
      for (int j=0; j<k; j++) {
        int a = cin.nextInt();
        ret[a-1]++;
      }
    }
    int count = 0;
    for (int i=0; i<M; i++) {
      if(ret[i] == N) {
        count++;
      }
    }
    Console.WriteLine(count);
  }
}


class Scanner
{
  string[] s;
  int i;
  int max_i;

  public Scanner()
  {
    s = new string[0];
    max_i = 0;
    i = 0;
  }

  public string nextString()
  {
    if (i >= s.Length) 
    {
      s = Console.ReadLine().Split(' ');
      max_i = s.Length;
      i = 0;
      if (max_i == 0) 
      {
        return "";
      }
      return s[i++];
    } else 
    {
      return s[i++];
    }
  }

  public int nextInt()
  {
    return int.Parse(nextString());
  }


  public long nextLong()
  {
    return long.Parse(nextString());
  }

  public double nextDouble()
  {
    return double.Parse(nextString());
  }

  public string[] arrayString()
  {
    return Console.ReadLine().Split(' ');
  }

  public int[] arrayInt()
  {
    string[] str = Console.ReadLine().Split(' ');
    int[] array = new int[str.Length];
    for (int i=0; i<str.Length; i++) 
    {
      array[i] = int.Parse(str[i]);
    }
    return array;
  }

  public long[] arrayLong()
  {
    string[] str = Console.ReadLine().Split(' ');
    long[] array = new long[str.Length];
    for (int i=0; i<str.Length; i++) 
    {
      array[i] = long.Parse(str[i]);
    }
    return array;
  }

  public double[] arrayDouble()
  {
    string[] str = Console.ReadLine().Split(' ');
    double[] array = new double[str.Length];
    for (int i=0; i<str.Length; i++) 
    {
      array[i] = double.Parse(str[i]);
    }
    return array;
  }
}


Measured memory_bytes: 11092
n = int(input())
a = list(map(int,input().split()))
s = sum([abs(a[i]) for i in range(n)])
cnt = 0
for i in range(n):
        if a[i] < 0:
                cnt += 1
if cnt % 2 == 0:
        ans = s
else:
        ans = s - 2 * min ([abs(a[i]) for i in range(n)])
print(ans)

Measured memory_bytes: 14284
n=int(input())
a=[int(input()) for i in range(n)]
b=a.copy()
b.sort()
if b[-1]==b[-2]:
    for i in range(n):
        print(b[-1])
else:
    for i in range(n):
        if a[i]==b[-1]:
            print(b[-2])
        else:
            print(b[-1])

Measured memory_bytes: 14112
#include<bits/stdc++.h>
 
using namespace std;
using S = set<long long>;
using D = deque<long long>;
using L = vector<long long>;
using M = map<int,long long>;
using A = vector<vector<long long>>;
using Q = priority_queue<long long>;
using U = unordered_map<int,long long>; //mapとの違いはkeyの順番を保持していない

#define sorted(vector) sort(vector.begin(),vector.end()) //O(nlongn)
#define sortedreverce(vector) sort(vector.rbegin(),vector.rend()) //O(nlongn)
#define vmin(vector) *min_element(vector.begin(),vector.end()) //O(N)
#define vmax(vector) *max_element(vector.begin(),vector.end()) //O(N)
#define vsum(vector) accumulate(vector.begin(),vector.end(),0) //O(N)
#define vcount(vector,a) count(vector.begin(), vector.end(),a) //O(N)
#define bisect_left(vector,a) (lower_bound(vector.begin(),vector.end(),a)-vector.begin())
#define bisect_right(vector,a) (upper_bound(vector.begin(),vector.end(),a)-vector.begin())
#define vfind(vector,a) find(vector.begin(), vector.end(), a) != vector.end() //遅いからあんまり使うな
//存在確認はmap!!!!!!!!!!!!!か配列に埋め込んでcontinueで回避
//__gcd(a,b)はコンパイラがGCC時のみ

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    long long n,k;
    cin>>n>>k;
    L h(n,0);
    for(int i=0  ;i<n  ;i++){
        cin>>h[i];
    }
    sorted(h);
    long long ans=1e18;
    for(int i=0  ;i<n-k+1  ;i++){
//        cout<<h[i+k-1]-h[i]<<endl;
        ans=min(h[i+k-1]-h[i],ans);
    }
    cout<<ans<<endl;
}

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

int main(){
  while(1){
    int x,y,s;
    cin>>x>>y>>s;
    if(x==0&&y==0&&s==0)break;
    int ans=0;
    int ans2;
    for(int i=1;i<s;i++){
      for(int j=1;j<s;j++){
        ans2=i+((i*x)/100)+j+((j*x)/100);
        if(ans2==s){
          ans2=i+((i*y)/100)+j+((j*y)/100);
          ans=max(ans,ans2);
          //cout<<ans2<<" "<<i<<" "<<j<<endl;
        }
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3076
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int f(int x, int y) {
    if (y >= x) return y - x;
    else return INF;
}


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y;
    cin >> x >> y;
    int ans = INF;
    cout << min({f(x, y), f(-x, y) + 1, f(x, -y) + 1, f(-x, -y) + 2}) << endl;


    return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

int main()
{
    int m1, d1;
    int m2, d2;
    cin >> m1 >> d1;
    cin >> m2 >> d2;
    if (m1!=m2)
        cout << 1 << endl;
    else
        cout << 0 << endl;
    return 0;
}

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

#define UI unsigned int
#define SI signed int
#define ULL unsigned long long
#define SLL long long


using namespace std;

SLL DP[100002][2];

SLL MOD=1000000007;

SLL dp_call(string& l,int level,int overflag){
    if(DP[level][overflag]!=-1)
        return DP[level][overflag];
    if(level==l.size()-1){
        if(overflag){
            DP[level][overflag]=3;
            return DP[level][overflag];
        }else{
            if(l[l.size()-1]=='0'){
                DP[level][overflag]=1;
                return DP[level][overflag];
            }else{
                DP[level][overflag]=3;
                return DP[level][overflag];
            }
        }
    }
    if(overflag){
        DP[level][overflag]=(3*dp_call(l,level+1,overflag))%MOD;
        return DP[level][overflag];
    }else{
        if(l[level]=='0'){
            DP[level][overflag]=dp_call(l,level+1,overflag);
            return DP[level][overflag];
        }else{
            DP[level][overflag]=(dp_call(l,level+1,1)+(2*dp_call(l,level+1,overflag))%MOD)%MOD;
            return DP[level][overflag];
        }
    }
}

int main(void){
    string L;
    cin >> L;
    for(int i=0;i<100002;i++){
        for(int j=0;j<2;j++){
            DP[i][j]=-1;
        }
    }
    dp_call(L,0,0);
    SLL temp=-1;
    if(temp==-1){
        temp+=MOD;
    }
    cout << DP[0][0] << endl;
    return 0;
}

Measured memory_bytes: 8320
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb1=new StringBuilder();
		StringBuilder sb2=new StringBuilder();
		String b=" ",n="\n";
        String[] rc=br.readLine().split(b);
        int r=Integer.parseInt(rc[0]);
        int c=Integer.parseInt(rc[1]);
        int[][] h=new int[r+1][c+1];
        
        for(int i=0;i<r;i++){
        	String[] row=br.readLine().split(b);
        	for(int j=0;j<c;j++){
        		h[i][j]=Integer.parseInt(row[j]);
        		h[i][c]+=h[i][j];
        		h[r][j]+=h[i][j];
        		sb1.append(h[i][j]+b);
        		if(i==r-1){
        			h[r][c]+=h[r][j];
        			sb2.append(h[r][j]+b);
        		}
        	}
        	sb1.append(h[i][c]+n);
        }
        sb1.append(sb2).append(h[r][c]);
        System.out.println(sb1);
	}
}

Measured memory_bytes: 25416
#include<stdio.h>

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

	int times = (n + x - 1) / x;
	
	if (times * x >= n) {
		printf("%d", times*t);
	}
	
	
	return 0;
}

Measured memory_bytes: 2100
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int A = scanner.nextInt();
		scanner.close();
		Set<Integer> set = new HashSet<>();
		for (int i = 1; i <= 9; i++) {
			for (int j = i; j <= 9; j++) {
				set.add(i * j);
			}
		}
		if (set.contains(A)) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
        }
	}
}

Measured memory_bytes: 22996
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>
#define maxn 2003
#define mod 1000000007
#define ll long long
using namespace std;
struct edge{ int u, v; ll c; }edges[maxn];
bool cmp(const edge& x, const edge &y){
	return x.c < y.c;
}
vector <int> a[maxn];
bool in_spanning[maxn];
int fa[maxn];
int getfa(int x){
	if (fa[x] == x)
		return x;
	return fa[x] = getfa(fa[x]);
}
ll poww(ll x, int y){
	ll ans = 1;
	for (int i = 1; i <= y; i <<= 1, x = x * x % mod)
		if (y & i)
			ans = ans * x % mod;
	return ans;
}
ll read(){
	ll cnt = 0;
	char ch = getchar();
	while (ch < '0' || '9' < ch)
		ch = getchar();
	while ('0' <= ch && ch <= '9'){
		cnt = cnt * 10 + ch - '0';
		ch = getchar();
	}
	return cnt;
}
int main(){
	int n, m;
	ll x;
	cin >> n >> m >> x;
	for (int i = 1; i <= m; ++ i)
		edges[i].u = read(), edges[i].v = read(), edges[i].c = read();
	sort(edges + 1, edges + 1 + m, cmp);
	int cnt = 0;
	for (int i = 1; i <= m; ++ i)
		if (edges[i].c != edges[i - 1].c)
			a[++ cnt].push_back(i);
		else
			a[cnt].push_back(i);
	for (int i = 1; i <= n; ++ i)
		fa[i] = i;
	ll sum = 0;
	int edge_cnt = 0;
	for (int i = 1; i <= cnt; ++ i){
		for (int j = 0; j < a[i].size(); ++ j){
			edge e = edges[a[i][j]];
			if (getfa(e.u) != getfa(e.v)){
				++ edge_cnt;
				in_spanning[a[i][j]] = true;
			}
		}
		for (int j = 0; j < a[i].size(); ++ j){
			edge e = edges[a[i][j]];
			if (getfa(e.u) != getfa(e.v)){
				sum += e.c;
				fa[getfa(e.u)] = getfa(e.v);
			}
		}
	}
	if (sum > x){
		cout << 0 << endl;
		return 0;
	}
	if (sum == x){
		cout << poww(2, m - edge_cnt) * (poww(2, edge_cnt) - 2) % mod << endl;
		return 0;
	}
	int must = edge_cnt, can = 0;
	for (int i = 1; i <= m; ++ i)
		if (! in_spanning[i]){
			for (int j = 1; j <= n; ++ j)
				fa[j] = j;
			fa[edges[i].u] = edges[i].v;
			ll sum = edges[i].c;
			for (int j = 1; j <= m; ++ j)
				if (getfa(edges[j].u) != getfa(edges[j].v)){
					fa[getfa(edges[j].u)] = getfa(edges[j].v);
					sum += edges[j].c;
				}
			if (sum < x)
				++ must;
			if (sum == x)
				++ can;
		}
	cout << poww(2, m - must - can) * (poww(2, can) - 1) % mod * 2 % mod << endl;
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int maxn=100005;
int f[maxn],n,cnt,m;
int getf(int x) {
	if(f[x]==x)return x;
	return f[x]=getf(f[x]);
}
int main() {
	int x,y;
	scanf("%d%d",&n,&m);
	for(register int i=1; i<=n; i++) {
		f[i]=i;
	}
	for(register int i=1; i<=m; i++) {
		scanf("%d%d",&x,&y);
		int fx=getf(x),fy=getf(y);
		f[fx]=fy;
	}
	for(register int i=1; i<=n; i++) {
		if(f[i]==i) {
			cnt++;
		}
	}
	printf("%d",cnt-1);
	return 0;
}

Measured memory_bytes: 4216
n = int(input())
s = list(input())
s[0] = (s[0],1)
for i in range(1,n):
  if s[i] == s[i-1][0]:
    s[i] = (s[i],0)
  else:
    s[i] = (s[i],1)
print(len([i for i in s if i[1] != 0]))

Measured memory_bytes: 11052
//(・ω・)
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
using namespace std;
int main(){
    int x;
    cin >> x;
    
    cout << x*x*x << endl;
}



Measured memory_bytes: 3092
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define SYOU(x) setprecision(x)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
long long i[1111];
lol u[111111];
lol ii[121111];
bool o;
bool ans[5];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=0,f=0,g=0,h=0,j=0,can;
  string w;
  vector<string> s;
  for(int n=0;n<=100;n++) u[n]++;
  cin >>a;
  for(int n=0;n<a;n++){
    cin >>w;
    o=true;
    for(int m=0;m<s.size();m++){
      if(w==s[m]){
	u[m]++,o=false;
	break;
      }
    }
    if(o) s.push_back(w);
  }
  cin >>b;
  for(int n=0;n<b;n++){
    cin >>w;
    for(int m=0;m<s.size();m++){
      if(w==s[m]){
	u[m]--;
	break;
      }
    }
  }
  for(int n=0;n<s.size();n++){
    if(d<u[n]) d=u[n];
  }
  cout <<d<<'\n';
  return (0);
}


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

vector<int> getComp(vector<int> a, vector<int> b) {
    int n = a.size();
    vector<int> c(n, 0);
    for(int i = 0; i < n; ++i)
        c[i] = a[b[i]];
    return c;
}

vector<int> getExp(vector<int> p, int64_t k) {
    int n = p.size();
    vector<int> ans(n, 0);
    for(int i = 0; i < n; ++i)
        ans[i] = i;

    for(int64_t i = 0; (1LL << i) <= k; ++i) {
        if((1LL << i) & k)
            ans = getComp(ans, p);
        p = getComp(p, p);
    }

    return ans;
}

int main() {
    
    int n; cin >> n;
    vector<int> v(n, 0);

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

    int m; cin >> m;
    int64_t k; cin >> k;

    vector<int> rounds(m, 0);

    for(int i = 0; i < m; ++i) {
        cin >> rounds[i];
        rounds[i]--;
    }

    vector<int> p(n - 1, 0);

    for(int i = 0; i < n - 1; ++i)
        p[i] = i;

    for(auto temp : rounds) 
        swap(p[temp - 1], p[temp]);
    
    vector<int> expP = getExp(p, k);
    
    vector<int> dx(n - 1, 0);
    for(int i = 0; i < n - 1; ++i)
        dx[i] = v[i + 1] - v[i];
    
    vector<int64_t> newX(n, 0);
    newX[0] = v[0];
    
    cout << newX[0] << "\n";

    for(int i = 1; i < n; ++i) {
        newX[i] = newX[i - 1] + dx[expP[i - 1]];
        cout << newX[i] << "\n";
    }
}

Measured memory_bytes: 4568
#include <stdio.h>
int main(void)
{
  char p,q,r;
  int a=0,b=0,c=0;
  scanf("%s%s%s",&p,&q,&r);
  switch(p)
  {
    case 'a':
      a++;
      break;
    case 'b':
      b++;
      break;
    case 'c':
      c++;
      break;
  }
  switch(q)
  {
    case 'a':
      a++;
      break;
    case 'b':
      b++;
      break;
    case 'c':
      c++;
      break;
  }
  switch(r)
  {
    case 'a':
      a++;
      break;
    case 'b':
      b++;
      break;
    case 'c':
      c++;
      break;
  }
  if (a==1&&b==1&&c==1) printf("Yes\n");
  else printf("No\n");
}

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

int main(){
  int N;
  cin >> N;
  
  int maxi = 0;
  int maxj = 0;
  for(int i = 1; i <= N; i++){
    int num = i;
    int j = 0;
    for(; num%2 == 0; j++){
      num /= 2;
    }
    if(j >= maxj){
      maxi = i;
      maxj = j;
    }
  }
  cout << maxi << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int n, m;
    cin >> n >> m;
    priority_queue<int> pq;
    rep(i, n) {
        int a;
        cin >> a;
        pq.push(a);
    }
    rep(i, m) {
        int a = pq.top();
        pq.pop();
        a /= 2;
        pq.push(a);
    }
    ll ans = 0;
    int c = pq.size();
    rep(i, c) {
        ans += pq.top();
        pq.pop();
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main(){
    string t;
    cin >> t;
    int len = t.size();
    if((len%2)==1){
        cout << "No" << endl;
        return 0;
    }
    for(int i= 0;i<len;i++){
        if((i % 2 == 0 && t[i] != 'h')){
            cout << "No" << endl;
            return 0;
        }else if((i%2==1 && t[i] != 'i')){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	int i = 1;
	for (int j = 0; j < n; j++) {
		if (i < k) i *= 2;
		else i += k;
	}
	cout << i << endl;
	return 0;
}


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

vector<int> G[200000];
vector<long long> cnt(200000);
vector<bool> visited(200000);

void dfs(int u) {
    visited[u] = true;

    for (int i = 0; i < G[u].size(); i++) {
        int v = G[u][i];
        if (visited[v]) continue;
        cnt[v] += cnt[u];
        dfs(v);
    }
}

int main() {
    int N, Q;
    cin >> N >> Q;
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b); G[b].push_back(a);
    }

    for (int i = 0; i < Q; i++) {
        long long p, x;
        cin >> p >> x;
        p--;
        cnt[p] += x;
    }

    dfs(0);

    for (int i = 0; i < N; i++) {
        cout << cnt[i] << " ";
    }
    cout << endl;
    return 0;
}

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

int main(){
  int n,m;
  cin>>n>>m;
  vector<int> a;
  vector<int> b;
  for(int i=0;i<m;i++){
    int x;
    cin>>x;
    if(x%2==0){
      a.push_back(x);
    }else{
      b.push_back(x);
    }
  }
  if(b.size()>2){
    cout<<"Impossible"<<endl;
    return 0;
  }

  if(b.size()>0)a.insert(a.begin(),b[0]);
  if(b.size()>1)a.push_back(b[1]);

  for(int i=0;i<m;i++){
    cout<<a[i];
    if(i!=m-1)cout<<" ";
  }
  cout<<endl;

  if(m==1){
    if(a[0]!=1){
      cout<<2<<endl;
      cout<<a[0]-1<<" "<<1<<endl;
    }else{
      cout<<1<<endl;
      cout<<1<<endl;
    }
    return 0;
  }

  vector<int> ans;
  if(a[0]-1>0)ans.push_back(a[0]-1);
  for(int i=1;i<m-1;i++){
    ans.push_back(a[i]);
  }
  ans.push_back(a[m-1]+1);

  cout<<ans.size()<<endl;

  for(int i=0;i<ans.size();i++){
    cout<<ans[i];
    if(i!=ans.size()-1)cout<<" ";
  }
  cout<<endl;


}


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

int main() {
 int A,B,C,D;
  cin >> A >> B >> C >> D;
  while (true){
    C = C - B;
      if(C <= 0){
        cout << "Yes" << endl;
        return 0;
      }
    A = A - D;
    if(A <= 0){
      cout << "No" << endl;
      return 0;
    }
  }
}


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

using vec = vector<int64_t>;
using mat = vector<vec>;

mat mul(mat &a, mat &b) {
	mat c(a.size(), vec(b[0].size(), 0));
	for (int i = 0; i < a.size(); i++) {
		for (int k = 0; k < a[0].size(); k++) {
			for (int j = 0; j < b[0].size(); j++) {
				c[i][j] += a[i][k] * b[k][j];
			}
		}
	}
	return c;
}

mat pow(mat &a, int n) {
	mat r(a.size(), vec(a.size(), 0));
	for (int i = 0; i < a.size(); i++) {
		r[i][i] = 1;
	}
	for (; n; n >>= 1) {
		if (n & 1) {
			r = mul(r, a);
		}
		a = mul(a, a);
	}
	return r;
}

int main() {
	int n;
	cin >> n;
	mat m(2, vec(2, 0));
	m[0][0] = m[0][1] = m[1][0] = 1;
	m = pow(m, n - 1);
	mat a(2, vec(1));
	a[0][0] = 1;
	a[1][0] = 2;
	a = mul(m, a);
	cout << a[0][0] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
ll a[maxn];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
    }
    sort(a,a+n);
    ll ans=0;
    if(n%2==0)
    {
        for(int i=0;i<n/2;i++)
        {
           if(i!=n/2-1)
           {
               ans=ans+2*(a[n-1-i]-a[i]);
           }
           else
           {
              ans=ans+(a[n-1-i]-a[i]);
           }
        }
    }
    else
    {
        int k=0;
        ll anss=0;
        for(int i=n/2;i>=0;i--)
        {
            if(k<=1)
            {
                ans-=a[i];
                k++;
            }
            else
            {
                ans-=2*a[i];
            }
        }
        for(int i=n/2+1;i<n;i++)
        {
            ans+=2*a[i];
        }
        for(int i=0;i<=n/2-1;i++)
        {
            anss-=2*a[i];
        }
        k=0;
        for(int i=n/2;i<n;i++)
        {
            if(k<=1)
            {
                anss+=a[i];
                k++;
            }
            else
            {
                anss+=2*a[i];
            }
        }
        ans=max(ans,anss);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const ll MOD=1e9+7;
const int INF=2e9;
const double PI=acos(-1);

const int MAX=200010;

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

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


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


int main() {
    ios_base::sync_with_stdio(false); 

    int n;
    cin >> n;
    vector<int> cnt(n);
    rep(i,n) cin >> cnt[i];
    ll b=0,ans=0;
    rep(i,n) {
        ans+=(cnt[i]+b)/2;
        if (cnt[i]==0 || (cnt[i]+b)%2==0) b=0;
        else b=1;
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3772
#include<bits/stdc++.h>
 #define N 5015
 using namespace std;
 char s[N];
 string kk[10];
 int k;
 int main(){
 	scanf("%s",s+1);
 	scanf("%d",&k);
 	int len=strlen(s+1);
 	int now=0;
 	for (int i=1;i<=5;i++){
 		string tt;
 		for (int j=1;i+j-1<=len;j++){
 			char tmp=s[j+i];
 			s[j+i]='\0';
 			tt=s+j;
 			s[j+i]=tmp;
 			bool flag=1;
 			for (int l=1;l<=now;l++){
 				if (tt==kk[l]){
 					flag=0;
				 	continue;
				}
 			}
 			if (!flag) continue;
 			int kl=now+1;
 			for (int l=1;l<=now;l++) 
 			if (tt<kk[l]){ kl=l; break;}
 			for (int l=now+1;l>kl;l--) kk[l]=kk[l-1];
 			kk[kl]=tt;
 			now++;
 			if (now>5) now=5;
 		}
 	}
 	cout<<kk[k]<<endl;
 }

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cassert>
#include <complex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <ctime>
#include <cctype>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>
#include <memory.h>
using namespace std;
#define ll long long 
int n;
vector<int> g[200005];
int d1[100005],d2[100005];
void dfs(int r,int f,int d,int dist[])
{
    dist[r]=d;
    for(int x=0;x<g[r].size();x++){
        if(g[r][x]!=f){
        	dfs(g[r][x],r,d+1,dist);
		}
    }
}
int main()
{
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
    	int a,b;
        cin>>a>>b;
        a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(0,-1,0,d1);
    dfs(n-1,-1,0,d2);
    int ans=0;
    for(int i=0;i<n;i++){
        if(d1[i]<=d2[i]){
            ans++;
		}
        else{
        	ans--;
        }
    }
    if(ans>0){
    	cout <<"Fennec"<< endl;
	}
    else{
    	cout<<"Snuke"<<endl;
	}
    return 0;
}

Measured memory_bytes: 15104
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
int main(){
	int array[100];
	int n;
	cin>>n;
	for(int i=0; i<n; ++i){
		cin>>array[i];
	}
	for(int i=n-1; i>0; --i){
		cout<<array[i]<<" ";
	}
	cout<<array[0]<<endl;


	return 0;
}

Measured memory_bytes: 1164
import java.util.Scanner;
public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String f,s;
        int a=0,b=0;
        for(int i = 0; i<n; i++)
        {
            f = sc.next();
            s = sc.next();
            if(f.compareToIgnoreCase(s)<0)
            {
                b+=3;
            }
            else if(f.compareToIgnoreCase(s)>0)
            {
                a+=3;
            }
            else
            {
                a++;
                b++;
            }
        }
        System.out.printf("%d %d\n",a,b);
    }
}


Measured memory_bytes: 30408
n=int(input())
a=list(map(int,input().split()))
ans=[0]*(n+1)
for i in range(n,0,-1):
    temp=0
    for j in range(i,n+1,i): temp+=ans[j]
    if a[i-1]!=temp%2: ans[i]=1
print(sum(ans))           
for i in range(n+1):
    if ans[i]==1: print(i,end=" ")

Measured memory_bytes: 7148
#include<stdio.h>
int main(){
  int n,i,j,k,m=0,p;
  char s[100010]={};
  scanf("%d %s",&n,s+1);
  for(i=1;i<=n;i++){
    if(s[i]-'.')continue;
    for(j=i-1;s[j]=='W';j--);
    for(k=i+1;s[k]=='W';k++);
    if(s[j]=='B'&&s[k]=='B')continue;
    for(j=i-1;s[j]=='B';j--);
    for(k=i+1;s[k]=='B';k++);
    p=0;
    if(s[j]=='W')p+=(i-j-1);
    if(s[k]=='W')p+=(k-i-1);
    if(m<p)m=p;
  }
  printf("%d\n",m);
  return 0;
}



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

int main()
{
    set<int> s1, s2;
    int n, m;

    cin >> n;
   
    int a;

    for( int i = 0; i < n; i++ )
    {
        cin >> a;
        s1.insert(a);
    }

    cin >> m;

    for( int i = 0; i < m; i++ )
    {    
        cin >> a;
        s2.insert(a);
    }

    set<int>::iterator itr1 = s1.begin(), itr2 = s2.begin();
    for(; itr1 != s1.end() && itr2 != s2.end(); )
    {
        if( *itr1 < *itr2 )
            itr1++;
        else if( *itr1 > *itr2 )
            itr2++;
        else
        {    
            cout << *itr1 << endl;
            itr1++;
            itr2++;
        }
    }
    return 0;
}


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

int main() {
  int N,T; 
  cin>>N>>T;
  vector<vector<int>> v(N,vector<int>(2));
  rep(i,N) cin>>v[i][0]>>v[i][1];
  int mn=10000;
  rep(i,N){
    if(v[i][1]<=T){
      mn=min(mn,v[i][0]);
    }
  }
  if(mn==10000) puts("TLE");
  else cout<<mn<<endl;
}

Measured memory_bytes: 256
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [[input().split()] for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes) if b else print(no)
# from collections import Counter,deque,defaultdict
# import itertools
import math
# import networkx
# from bisect import bisect_left,bisect_right
a,b,h,m=n1()

m1=m*360/60
h1=(60*h+m)*360/(12*60)
d=min(abs(m1-h1),360-abs(m1-h1))
ans=math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(d)))
print(ans)

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

using namespace std;

int main()
{
  string O, E;
  cin >> O >> E;

  for (int i = 0; i < E.size(); i++) {
  	cout << O[i] << E[i];
  }
  if(O.size() > E.size()) cout << O.back();
  cout << endl;
  
  return 0;
}

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

int main(){
    priority_queue<ll> pq;
    int x,y,z,k; cin >> x >> y >> z >> k;
    vector<ll> a(x+1);
    vector<ll> b(y+1);
    vector<ll> c(z+1);
    for(int i=0;i<x;i++) cin >> a[i];
    for(int i=0;i<y;i++) cin >> b[i];
    for(int i=0;i<z;i++) cin >> c[i];
    sort(a.rbegin(),a.rend());
    sort(b.rbegin(),b.rend());
    sort(c.rbegin(),c.rend());
    for(int q=0;q<x;q++){
        for(int w=0;w<y;w++){
            for(int e=0;e<z;e++){
                if(q*w*e<=k) pq.push(a[q]+b[w]+c[e]);
            }
        }
    }
    for(int i=0;i<k;i++){
        cout << pq.top() << endl;
        pq.pop();
    }
    return 0;
}

Measured memory_bytes: 35048
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>

using namespace std;

const int MAX = 50;

const int dx[] = { 0,1,0,-1 };
const int dy[] = { 1,0,-1,0 };

int H, W;
char s[MAX][MAX];

bool solve() {
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i][j] == '.')continue;

			int cnt = 0;
			for (int k = 0; k < 4; k++) {
				int x = j + dx[k];
				int y = i + dy[k];
				if (x < 0 || y < 0 || x >= W || y >= H)continue;
				if (s[y][x] == '#')cnt++;
			}
			if (cnt == 0)return false;
		}
	}
	return true;
}

int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> s[i][j];
		}
	}

	if (solve())cout << "Yes" << endl;
	else cout << "No" << endl;
	

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

constexpr ll inf = INT64_MAX / 4;
constexpr ll mod = 1000000007;

constexpr int maxn = 200000;

int right_L[100000], left_R[100000], res[100000];

int main() {
    string s;
    vector<pair<char, int>> v;
    cin >> s;
    for (int i = 0; i < s.length(); i++) {
        v.emplace_back(s[i], i);
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < s.length(); i++) {
        right_L[i] = lower_bound(v.begin(), v.end(), make_pair('L', i))->second;
        left_R[i] = (upper_bound(v.begin(), v.end(), make_pair('R', i)) - 1)->second;
    }
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'R') {
            int s1 = right_L[i] - i;
            if (s1 % 2) res[right_L[i] - 1]++;
            else res[right_L[i]]++;
        } else {
            int s2 = i - left_R[i];
            if (s2 % 2) res[left_R[i] + 1]++;
            else res[left_R[i]]++;
        }
    }
    for(int i = 0;i < s.length();i++) {
        cout << res[i] << ' ';
    }
    cout << endl;
}

Measured memory_bytes: 2676
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int arr[N] = {};
int main() {
    int n, m, s = 0;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> arr[i], s += arr[i];
    int cnt = 0;
    for (int i = 1; i <= n; i++)
        cnt += (arr[i] * 4 * m >= s);
    cout << (cnt >= m ? "Yes\n" : "No\n");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int mod=1e9+7;
const int maxn=1000;
int n,m,a[maxn],b[maxn],f[2][maxn][maxn],x,y,t;
inline int read()
{   int x=0,f=1;  char ch;
    ch=getchar();
    while (ch>'9' || ch<'0') {  if (ch=='-') f=-1; ch=getchar(); }
	while (ch<='9'&& ch>='0') {  x=x*10+ch-'0'; ch=getchar(); }
	return f*x; 
}
void up(int &x,int y) {x=(x+y)%mod; } 
signed main()
{  n=read();
   for (int i=1;i<=n;i++)
   {  a[i*2-1]=read(); a[i*2]=read();
      if (a[i*2-1]>0 && a[i*2]>0){  b[a[i*2]]=-1,b[a[i*2-1]]=-1;continue;}
	  if (a[i*2-1]>0)  b[a[i*2-1]]=1;
	  if (a[i*2]>0) b[a[i*2]]=1;
	  if (a[i*2-1]==-1 && a[i*2]==-1)  m++; 
   }
   f[0][0][0]=1; t=0;
   for (int i=1;i<=2*n;i++)
   if (b[i]!=-1){  t=1-t;
      memset(f[t],0,sizeof(f[t]));
      for (int j=0;j<=n;j++)
      for (int k=0;k<=n;k++)
      if (b[i]==1)
      {  if (j) up(f[t][j-1][k],f[1-t][j][k]*j%mod);
         up(f[t][j][k+1],f[1-t][j][k]);
	  }
	  else
	  { if (m+(x-y+j-k)/2>0)  up(f[t][j][k+1],f[1-t][j][k]*(m+(x-y+j-k)/2));
	    up(f[t][j+1][k],f[1-t][j][k]);
	    if (k) up(f[t][j][k-1],f[1-t][j][k]);
	  }
	  if (b[i]==1)  x++; else y++;
   }
   cout<<f[t][0][0]<<endl;
}
		

Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
int main()
{
   string s,t;
   cin >> s >> t;
   for(int i=0;i<s.size();i++)
   {
      bool flag = true;
      for(int j=0;j<s.size();j++)
      {
          if(s[j] != t[(i+j)%s.size()])
         {
             flag = false;
             break;
         }
      }
      if(flag)
      {
          cout << "Yes" << endl;
          return 0;
      }
   }
     cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int a[] = new int[m];
        for(int i=0;i<m;i++){
            a[i] = sc.nextInt();
        }
        int sum = 0;
        for(int j=0;j<m;j++){
            sum = sum + a[j];
        }
        if(sum>n){
            System.out.println(-1);
            return;
        }
        n = n - sum;
        System.out.println(n);
    } 
}

Measured memory_bytes: 46220
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;

const int MAX = 500001;
const int NIL = -1;
struct Node {
	int key;
	Node* parent, * left, * right;
};
struct Node T[MAX];
Node* head = NULL;

void preParse(Node* u)
{
	if (u == NULL)
		return;
	cout << " " << u->key;
	preParse(u->left);
	preParse(u->right);
}

void inParse(Node* u)
{
	if (u == NULL)
		return;
	inParse(u->left);
	cout << " " << u->key;
	inParse(u->right);
}

int main(void)
{
	int n, key;
	char ss[10];
	cin >> n;
	memset(ss, 0, sizeof(ss));
	for (int i = 0; i < n; i++) {
		scanf("%s", ss);
		if (ss[0] == 'i') {
			cin >> key;
			Node* y = NULL, * x = head, * z = new(Node);
			z->key = key;
			z->left = z->parent = z->right = NULL;
			while (x != NULL) {
				y = x;
				if (z->key < x->key)
					x = x->left;
				else
					x = x->right;
			}
			z->parent = y;
			if (y == NULL)
				head = z;
			else if (z->key < y->key)
				y->left = z;
			else
				y->right = z;
		}
		else {
			inParse(head);
			cout << endl;
			preParse(head);
			cout << endl;
		}
	}
	return 0;
}


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

int main(int argc, char const *argv[]) {
    int A, B, C, ans;
    cin >> A >> B >> C;

    if (B + C <= A) {
        ans = 0;
    } else {
        ans = C- (A - B);
    }

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


Measured memory_bytes: 256
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,b,n) for(int i=b;i<n;i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n;
string str;
int main(){
	cin>>n;
	cin.ignore();
	string h  ="Hoshina";
	int pos = 0;
	for(int i = 0;i < n;i++){
		getline(cin,str);
		while(str.find("Hoshino")!=string::npos){
			pos = str.find("Hoshino");
			str.replace(pos,h.length(),h);
		}
		cout <<str<<endl;
	}
	return 0;
}

Measured memory_bytes: 1212
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>

int abs(int a){
    if(a>=0)return a;
    else return -a;
}

int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    int a[n][2];
    int c[m][2];
    int i,j;
    for(i=0;i<=n-1;i++)scanf("%d %d",&a[i][0],&a[i][1]);
    for(i=0;i<=m-1;i++)scanf("%d %d",&c[i][0],&c[i][1]);
    for(i=0;i<=n-1;i++){
        int dis=500000000,num=0;
        for(j=0;j<=m-1;j++){
            int d=abs(a[i][0]-c[j][0])+abs(a[i][1]-c[j][1]);
            if(d<dis){
                dis=d;
                num=j;
            }
        }
        printf("%d\n",num+1);
    }
    
    return 0;
}


Measured memory_bytes: 128