akhauriyash/Code-Regression huggingface dataset:
//hail to jwalaji
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
string s,t;
cin>>s>>t;
vector<vector<lli>> dp(3005,vector<lli>(3005,0));
for(lli i=1;i<=s.size();++i){
    for(lli j=1;j<=t.size();j++){
        if(s[i-1]==t[j-1]){
            dp[i][j]=dp[i-1][j-1]+1;
        }
        else{
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
}
/*for(lli i=0;i<=9;i++){
    for(lli j=0;j<=10;j++){
        cout<<dp[i][j]<<" ";
    }cout<<endl;
}*/
string sol="";
lli i,j;
i=s.size();j=t.size();
while(i>0&&j>0){
    if(s[i-1]==t[j-1]){
        sol+=s[i-1];
       // cout<<s[i-1]<<endl;
        i--;
        j--;
    }
    else if(dp[i-1][j]>dp[i][j-1]){
        i--;
    }
    else{
        j--;
    }
}
reverse(sol.begin(),sol.end());
cout<<sol<<endl;
return 0;
}


Measured memory_bytes: 73964
from collections import Counter
N, M = list(map(int,input().split()))
city_list = [list(map(int,input().split())) +[i+1]  for i in range(M)]
city_list_sorted = sorted(city_list,key=lambda x: (x[0],x[1]) )
pre = 0
counter = 0

for i in range(M):
  if pre == city_list_sorted[i][0]:
    counter+=1
    city_list_sorted[i][1] = counter
  else:
    counter = 1
    city_list_sorted[i][1] = counter
    pre = city_list_sorted[i][0]

anslist = [[x[2]]+[format(x[0],'0>6') + format(x[1],'0>6') ] for x in city_list_sorted]
[print(x[1]) for x in sorted(anslist)]


Measured memory_bytes: 105560
import java.util.*;
public class Main{

	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int ac= 0,wa = 0, tle = 0, re = 0;
		for(int i = 0;i < n; ++i){
			String s = scan.next();
			switch(s){
				case "AC":++ac;break;
				case "WA":++wa;break;
				case "TLE":++tle;break;
				case "RE": ++re;break;
			}
		}
		System.out.println("AC x "+ac);
		System.out.println("WA x "+wa);
		System.out.println("TLE x "+tle);
		System.out.println("RE x "+re);


	}
}


Measured memory_bytes: 58808
#include <bits/stdc++.h>
#define mod 1000000007ll
#define M 200010
using namespace std;
struct edge
{
	int to;
	int nxt;
}e[3000010];
int n,minnum,minnum2;
int color[M],dlfl[M],pos[M],vis[M];
long long val[M],minn[M];
long long fac[M],rfac[M];
long long X,Y;
long long min1 = 2147483647ll,min2 = 2147483647ll;
int head[M],cnt;
void addedge(int x,int y)
{
	e[++cnt].nxt = head[x];
	e[cnt].to = y;
	head[x] = cnt;
}
void add(int x,int y)
{
	addedge(x,y);
	addedge(y,x);
}
long long qpow(long long a,long long b)
{
	long long ans = 1,res = a;
	while(b)
	{
		if(b&1)ans = (ans * res) % mod;
		res *= res;
		res %= mod;
		b >>= 1;
	}
	return ans;
}
long long C(long long n,long long k)
{
	return  fac[n] * rfac[k] % mod * rfac[n - k] % mod;
}
void init()
{
	fac[0] = 1;
	for(int i = 1;i <= n;i++)fac[i] = (i * fac[i - 1]) % mod;
	rfac[n] = qpow(fac[n],mod - 2);
	for(int i = n; i > 0; i--)rfac[i - 1] = (i * rfac[i]) % mod;
}
void dfs(int x)
{
	vis[x] = 1;
	for(int i = head[x]; i; i = e[i].nxt)
	{
		if(!vis[e[i].to])dfs(e[i].to);
	}
}
void find()
{
	for(int i = 1; i <= n; i++)
	{
		if(val[i] < min1)
		{
			min1 = val[i];
			minnum = i;
		}
	}
	for(int i = 1; i <= n; i++)
	{
		if(val[i] <= min2 && color[i] != color[minnum])
		{
			min2 = val[i];
			minnum2 = i;
		}
	}
}
int main()
{
	scanf("%d%lld%lld",&n,&X,&Y);
	init();
	for(int i = 1;i <= n;i++)minn[i] = 2147483647ll;
	for(int i = 1;i <= n;i++)scanf("%d%lld",&color[i],&val[i]);
	for(int i = 1;i <= n;i++)
	{
		if(val[i] < minn[color[i]])
		{
			minn[color[i]] = val[i];
			pos[color[i]] = i;
		}
	}
	for(int i = 1; i <= n; i++)
	{
		if(i != pos[color[i]] && val[i] + minn[color[i]] <= X)
		{
			add(i,pos[color[i]]);
		}
	}
	find();
	for(int i = 1; i <= n; i++)
	{
		if(i != minnum)
		{
			if(color[i] != color[minnum] && val[i] + val[minnum] <= Y)
			{
				add(i,minnum);
			}
			if(minnum2 && color[i] != color[minnum2] && val[i] + val[minnum2] <= Y)
			{
				add(i,minnum2);
			}
		}
		
	}
	dfs(minnum);
	long long fldl = 0;
	for(int i = 1; i <= n; i++)
	{
		if(vis[i])
		{
			dlfl[color[i]]++;
		}
	}
	for(int i = 1;i <= n;i++)fldl += dlfl[i];
	long long ans = 1;
	for(int i = 1; i <= n; i++)
	{
		if(dlfl[i])
		{
			ans *= C(fldl,dlfl[i]);
			ans %= mod;
			fldl -= dlfl[i];
		}
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 18688
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))


ll solve(ll hp ){
    if(hp<=1)return 1;
    return 1+solve( hp/2 )*2;
}

int main(){
    ll ans=0,h;
    cin>>h;

    ll allenm=h;//全敵のhp

    ans=solve(h);

    cout <<ans<<endl;

    return 0;

}

Measured memory_bytes: 256
#pragma GCC optimize("O3", "unroll-loops")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

signed main() {
	int a, b, x;
	cin >> a >> b >> x;
	cout << setprecision(15);
	if (x >= (a * a * b) / 2.0) {
		cout << (180.0 / M_PI) * atan((2 * b * a * a - 2 * x) / ((double)a * a * a));
	}
	else {
		cout << (180.0 / M_PI) * atan((a * b * b) / (2.0 * x)) << endl;
	}
	return 0;
}

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

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        String ans = "yes";
        
        for (int i = 0; i < s.length(); i++) {
            for (int j = 0; j < s.length(); j++) {
                if (s.charAt(i) == s.charAt(j) && i != j) ans = "no";
            }
        }
        System.out.println(ans);
    }
}


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



int main()
{

 char S[4];

 scanf("%s",S);

  if (S[0]==S[1] && S[1]==S[2])
  {
   printf("%s",S);
  }
  
  else 
  { 

  char Copy[4];

  Copy[0] = S[0];
  Copy[1] = S[0];
  Copy[2] = S[0];

  int a = atoi(Copy);
  int RE= atoi(S);
  
  if (RE>a)
  {

  Copy[0] = S[0]+1;
  Copy[1] = S[0]+1;
  Copy[2] = S[0]+1;
  int res = atoi(Copy);
  printf("%d",res);
  }

  else 
  {
    printf("%d",a);

  }

  }
 
 return 0;
}

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

#define REP(i, n) for(int i = 0; i != n; ++i)
#define REPR(i, n) for(int i = n - 1; i != -1; --i)
#define FOR(i, a, b) for(int i = a; i != b; ++i)
#define RBF(i, n) for(auto &i : n)
#define ABS(n) (n < 0 ? -n : n)
#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define IN(n) (cin >> n)
#define OUT(n) (cout << n << "\n")
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define V vector<int>

using namespace std;
using ll = long long;

int main() {
    int N;
    IN(N);
    V a(N);
    float sum = 0;
    REP(i, N) {
        IN(a[i]);
        sum += a[i];
    }
    sum /= N;
    int min = 0, n = 0;
    REP(i, N) {
        if(abs(sum - n) > abs(sum - a[i])) {
            min = i;
            n = a[i];
        }
    }
    OUT(min);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define st first
#define nd second
using namespace std;
const int H = 21;
bool wall[H][H];
int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int h, w;
	cin>>h>>w;
	for(int i=0; i<h; ++i) {
		string s;
		cin>>s;
		for(int j=0; j<w; ++j) {
			if(s[j]=='#') {
				wall[i][j]=1;
			}
		}
	}
	int ans=0;
	for(int X=0; X<h; ++X) {
		for(int Y=0; Y<w; ++Y) {
			if(wall[X][Y]) continue;
			queue<pair<int, int>> Q;
			Q.push({X, Y});
			vector<vector<int>> dist(h, vector<int>(w, -1));
			dist[X][Y]=0;
			while(Q.size()) {
				int x = Q.front().st;
				int y = Q.front().nd;
				Q.pop();
				if(x<h-1) {
					if(dist[x+1][y]==-1 && !wall[x+1][y]) {
						dist[x+1][y]=dist[x][y]+1;
						Q.push({x+1, y});
					}
				}
				if(x>0) {
					if(dist[x-1][y]==-1 && !wall[x-1][y]) {
						dist[x-1][y]=dist[x][y]+1;
						Q.push({x-1, y});
					}
				}
				if(y<w-1) {
					if(dist[x][y+1]==-1 && !wall[x][y+1]) {
						dist[x][y+1]=dist[x][y]+1;
						Q.push({x, y+1});
					}
				}
				if(y>0) {
					if(dist[x][y-1]==-1 && !wall[x][y-1]) {
						dist[x][y-1]=dist[x][y]+1;
						Q.push({x, y-1});
					}
				}
			}
			for(int i=0; i<h; ++i) {
				for(int j=0; j<w; ++j) {
					ans=max(ans, dist[i][j]);
				}
			}
		}
	}
	cout<<ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    int n; cin >> n;
    vector<int> v(n);
    vector<int> v2(n);
    rep(i,n) {
        cin >> v[i];
        v2[i] = v[i];
    }
    sort(ALL(v));
    int ans1 = v[n/2-1];
    int ans2 = v[n/2];
    rep(i,n){
        if(v2[i]<=ans1) cout << ans2 << endl;
        else cout << ans1 << endl;
    }

    return 0;
}

Measured memory_bytes: 3712
def all_even?(a)
  a.map{|v| v & 1}.all?{|v| v == 0}
end

def all_div2(a)
  a.map{|v| v / 2}
end

def main(argv)
  n = STDIN.gets.chomp.to_i
  a = STDIN.gets.chomp.split(' ').map(&:to_i)

  i = 0
  while all_even?(a) do
    a = all_div2(a)
    i += 1
  end

  STDOUT.puts i.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

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

int N;

int main()
{
    cin>>N;

    long long ans = 1;
    for (int i = 1; i <= N; i++)
    {
        ans *= i; 
        ans %= 1000000007;
    }
    
    cout << ans << endl;
    return 0;

    
}


Measured memory_bytes: 256
N = int(input())

A = []
B = []

ans = 0
for i in range(N):
    s = input()
    for j in range(len(s)-1):
        if s[j:j+2] == "AB":
            ans += 1
    if s[0] == "B":
        B.append(i)
    if s[-1] == "A":
        A.append(i)

A = set(A)
B = set(B)
#print(A, B)
if len(A) == len(B):
    ans += len(A)
    if len(A&B) == len(A) and len(A)>0:
        ans -= 1
elif len(A)> len(B):
    ans += len(B)
else:
    ans += len(A)
print(ans)


        


Measured memory_bytes: 4980
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    long long solve(vector<long long>& A) {
        int n = A.size();
        int h = 0;
        {
            long long mx = *max_element(A.begin(), A.end());
            while ((1LL << (h + 1)) <= mx) {
                ++h;
            }
        }


        long long X = 0;
        for (auto x : A) {
            X ^= x;
        }

        vector<long long> LB;
        auto add = [&](long long x) {
            for (auto y : LB) {
                x = min(x, x ^ y);
            }
            if (x == 0) {
                return;
            }
            LB.push_back(x);
            for (int i = (int) LB.size() - 1; i > 0; --i) {
                if (LB[i] > LB[i - 1]) {
                    swap(LB[i], LB[i - 1]);
                }
            }
        };

        auto getMax = [&]() {
            long long res = 0;
            for (auto x : LB) {
                res = max(res, res ^ x);
            }
            return res;
        };

        for (auto x : A) {
            add(x & (~X));
        }

        long long res = (getMax() << 1) + X;
        return res;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<long long> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    Solution sol;
    cout << sol.solve(A) << "\n";

    return 0;
}

Measured memory_bytes: 1024
fun main(args: Array<String>) {

    fun gcd(a: Long, b: Long): Long {
        return if (b == 0L) a else gcd(b, a % b)
    }

    fun lcm(a: Long, b: Long): Long {
        return a / gcd(a, b) * b
    }

    val n = readLine()!!.toInt()
    val xs = (0 until n).map { readLine()!!.toLong() }

    println(xs.reduce { acc, l -> lcm(acc, l) })
}


Measured memory_bytes: 33636
#include <vector>
#include <list>
#include <map>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;
typedef long double ld;

int solve(void);
ll count_shakehands(ll X, ll& ans);

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

int solve(void)
{
	ll N;
	cin >> N;

	ll M = (N%2 == 0) ? N/2 : N/2 + 1;

	cout << (ld)(M)/(ld)N << endl;

	return 0;
}



Measured memory_bytes: 256
//線形探索
using System;

namespace tst
{
    class Program
    {
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            string text1 = Console.ReadLine();
            string[] S = text1.Split(' ');
            
            int q = int.Parse(Console.ReadLine());
            string text2 = Console.ReadLine();
            string[] T = text2.Split(' ');

            int cnt = 0;

            for(int i=0; i < q; i++)
            {
                for(int j=0; j<n; j++)
                {
                    if (T[i] == S[j])
                    {
                        //SとTが一致したらTを次に
                        cnt++;
                        break;
                    }
                }
            }
            Console.WriteLine(cnt);
        }

    }
}


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

int main() {
//	freopen("hayfeast.in", "r", stdin);
//	freopen("hayfeast.out", "w", stdout);
	int k;
	cin >> k;
	for(int i=0; i<k; i++) {
		cout << "ACL";
	}
	cout << endl;
}

Measured memory_bytes: 3636
from math import floor
N = int(input())
a = list(map(int, input().split()))
cnt_4 = 0
for i in a:
    if i%4==0:
        cnt_4 += 1

cnt_2 = 0
for i in a:
    if i%2==0 and i%4!=0:
        cnt_2 += 1

if floor(N//2)<=cnt_4+(cnt_2//2):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 62704
A=list(input())
B=list(input())
C=list(input())

a=1
b=0
c=0

t=A[0]
for i in range(len(A)+len(B)+len(C)-1):
    if t=="a":
        if a==len(A):
            print("A")
            break
        t=A[a]
        a+=1
    elif t=="b":
        if b==len(B):
            print("B")
            break
        t=B[b]
        b+=1
    elif t=="c":
        if c==len(C):
            print("C")
            break
        t=C[c]
        c+=1


Measured memory_bytes: 3188
using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
	class Program
	{
		static void Main(string[] args)
		{
			var inputs1 = Console.ReadLine().Split(' ');
			int n = int.Parse(inputs1[0]);
			int indexA = int.Parse(inputs1[1]) - 1;
			int indexB = int.Parse(inputs1[2]) - 1;
			int indexC = int.Parse(inputs1[3]) - 1;
			int indexD = int.Parse(inputs1[4]) - 1;
			var s = Console.ReadLine();

			var position = new List<bool>(n);
			foreach (var i in s)
			{
				position.Add(i.Equals('.'));
			}

			// D < Cの場合
			if (indexD < indexC)
			{
				// B - D の間に抜かすポイント(連続空白3つ)がなければアウト
				bool canSkip = false;
				for (int i = indexB - 1; i < indexD; i++)
				{
					if (position[i] && position[i + 1] && position[i + 2])
					{
						canSkip = true;
						break;
					}
				}
				if (!canSkip)
				{
					Console.WriteLine("No");
					return;
				}
			}

			// あとは移動途中に2連続岩がなければいい
			// B → D
			for (int i = indexB + 1; i < indexD; i++)
			{
				// 2連続でfalseだと駄目
				if (!position[i] && !position[i + 1])
				{
					Console.WriteLine("No");
					return;
				}
			}
			// A → C
			for (int i = indexA + 1; i < indexC; i++)
			{
				// 2連続でfalseだと駄目
				if (!position[i] && !position[i + 1])
				{
					Console.WriteLine("No");
					return;
				}
			}

			Console.WriteLine("Yes");
			return;
		}
	}
}


Measured memory_bytes: 11872
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    double l;
    double ans=0;
    
    cin >> l;
    
    ans = (l/3.0) * (l/3.0) * (l/3.0);
    
    printf("%.16f", ans);
    
    return 0;
    
}

Measured memory_bytes: 256
#include <stdio.h>

void bubblesort(int n,int *a){
    int flag = 1;
    int i,j,tmp,count;
    count = 0;
    i = 0;
    while(flag){
        flag = 0;
        for(j = n-1; j > i;j--){
            if(a[j] < a[j-1]){
                tmp = a[j];
                a[j] = a[j-1];
                a[j-1] = tmp;
                flag = 1;
                count++;
            }
        }
        i++;
    }

    for(j = 0; j < n; j++ ){
        if(j == 0){
            printf("%d",a[j]);
        }else{
            printf(" %d", a[j]);
        }
    }
    putchar('\n');
    printf("%d\n",count);
}

int main() {

    int n,i,count;
    count = 0;
    int a[101] = {};

    scanf("%d",&n);

    for(i = 0; i < n; i++){
        scanf("%d",&a[i]);
    }
    bubblesort(n,a);

    return 0;
}



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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vs = vector<string>;
using pll = pair<ll, ll>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i, a, b) for(ll i=(a); i<(b); i++)
#define FORD(i, a, b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    
    string s, t; cin >> s >> t;
    ll output = oo;
    FOR(i, 0, sz(s) - sz(t) + 1) {
        ll curr = 0;
        FOR(j, 0, sz(t)) {
            if(s[j + i] != t[j]) curr++;
        }
        output = min(output, curr);
    }
    cout << output << endl;
}

Measured memory_bytes: 3648
#include <cstdio>
#include <unordered_map>
using namespace std;
int main() {
	int n, x;
	unordered_map<int, int> hashTable;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &x);
		if (hashTable[x] == 0) {
			hashTable[x] = 1;
		} else {
			hashTable[x] = 0;
		}
	}
	int ans = 0;
	for (auto it = hashTable.begin(); it != hashTable.end(); ++it) {
		if (it->second == 1) {
			++ans;
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

typedef long long ll;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll a,b,v,w,t;
	cin >> a >> v >> b >> w >> t;
	ll gap = abs(a-b);
	if( gap == 0 )
	{
		cout << "YES" << '\n';
		return 0;
	}
	if( v < w )
	{
		cout << "NO" << '\n';
		return 0;
	}
	ll z = v - w;
	if( z * t >= gap ) cout << "YES" << '\n';
	else cout << "NO" << '\n';
	return 0;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll one = 1;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

struct UnionFind {
    // 親の番号を入れる配列。根のときはpar[i] = i
    vector<int> par;

    // 初めは空グラフとして初期化
    UnionFind(int N) : par(N){
        for(int i = 0; i < N; i++) par[i] = i;
    }

    // その点を含む成分の根を取り出す
    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    // xとyを同じ成分に入れる
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    // xとyが同じ成分に入っているか判定
    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
    ll N, M;
    cin >> N >> M;
    vector<ll> L(M), R(M), D(M);
    UnionFind UF(N);
    for (ll i = 0; i < M; i++) {
        cin >> L[i] >> R[i] >> D[i]; L[i]--; R[i]--;
        UF.unite(L[i], R[i]);
    }

    vector<vector<llll>> G(N);
    for (ll i = 0; i < M; i++) {
        G[L[i]].push_back(make_pair(R[i], D[i]));
        G[R[i]].push_back(make_pair(L[i], -D[i]));
    }

    stack<ll> s;
    for (ll iu = 0; iu < N; iu++) {
        s.push(iu);
    }

    vector<bool> used(N, false);
    vector<ll> x(N, -INF);
    while(!s.empty()){
        ll v = s.top(); s.pop();
        if(used[v]) continue;
        if(x[v] == -INF){
            x[v] = 0;
        }
        for (llll w : G[v]){
            ll u = w.first;
            ll d = w.second;
            if(x[u] != -INF){
                if(x[u] - x[v] != d){
                    No(); return 0;
                }
            }
            else{
                x[u] = x[v] + d;
                s.push(u);
            }
        }
        used[v] = true;
    }

    map<ll, vector<ll>> m;
    for (ll i = 0; i < N; i++) {
        if(m.count(UF.root(i))){
            m[UF.root(i)].push_back(i);
        }
        else{
            m[UF.root(i)] = {i};
        }
    }

    for (auto v : m){
        auto node = v.second;
        ll mi, ma; mi = 0; ma = 0;
        for (ll w : node) {
            mi = min(mi, x[w]);
            ma = max(ma, x[w]);
        }
        if(ma - mi > 1000000000){
            No();
            return 0;
        }
    }

    Yes(); return 0;
    



}

Measured memory_bytes: 24520
import java.util.*;

public class Main {
	static boolean f;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		/* 入力の受け取り
		 * String s = sc.next();
		 * int a = sc.nextInt();
		 * long a = sc.nextLong();
		 */
		
		// 文字列(String)を文字(char)に分解
		// char[] s_char = s.toCharArray();
		
		int n = sc.nextInt();
		long sum = 0;
		
		for(int i=1;i<=n;i++) {
			if(i%3!=0 && i%5!=0) {
				sum += i;
			}
		}
		
		System.out.println(sum);
		
		/*
		 * if(f)
		 *	System.out.println("Yes");
		 * else
		 * 	System.out.println("No");
		 */
	}
}


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

int d[1000001];
int main()
{
long long n;
cin>>n;
long long a[n];
for(int i=0;i<n;i++)cin>>a[i];
cout<<accumulate(a,a+n,0ll)-*max_element(a,a+n)/2<<endl;
	


}



Measured memory_bytes: 3576
#include <iostream>
#include <algorithm>
#include <vector>
#include<string>
#include <set>
#include <map>
#include <queue>
#include <limits.h>
#include <cmath>

using namespace std;

#define rip(i,n,s) for (int i=(s);i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<double, int> P;

struct  circle
{
	ll x;
	ll y;
	ll r;
};

double distans(circle &a, circle &b) {
	double dis = sqrt((double)((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y)));
	if (dis > a.r + b.r) {
		return (double)dis - (a.r + b.r);
	}
	else {
		return 0;
	}
}

int main() {
	ll sx, sy, gx, gy;
	cin >> sx >> sy >> gx >> gy;
	int n;
	cin >> n;
	vector<circle> da(n + 2);
	rip(i, n + 1, 1) {
		cin >> da[i].x >> da[i].y >> da[i].r;
	}
	da[0].x = sx;da[0].y = sy;da[0].r = 0;
	da[n + 1].x = gx;da[n + 1].y = gy;da[n + 1].r = 0;
	vector<vector<double>> HowDist(n + 2, vector<double>(n + 2));
	rip(i, n + 2, 0) {
		rip(j, n + 2, 0) {
			HowDist[i][j] = distans(da[i], da[j]);
		}
	}
	map<int, int> convert;
	priority_queue<P,vector<P>,greater<P>> q;
	vector<bool> reached(n + 2, false);
	rip(i, n + 2, 1) {
		q.push(make_pair(HowDist[0][i], i));
	}
	reached[0] = true;
	vector<double> ans(n + 2);
	ans[0] = 0;
	while (!q.empty()) {
		P now = q.top();
		q.pop();
		if(now.second==n+1){
            printf("%.10f\n",now.first);
			return 0;
		}
		if (reached[now.second]) {
			continue;
		}
		else {
			reached[now.second] = true;
			ans[now.second] = now.first;
			rip(i, n + 2, 0) {
				if (!reached[i]) {
					q.push(make_pair(now.first + HowDist[now.second][i], i));
				}
			}
		}
	}
}

Measured memory_bytes: 18428
#include <stdio.h>
#include <string.h>

#define N 25

typedef struct{
  int left, right;
}Node;

Node tree[N];
int n;
char root[N];

void visit_pre(int p){
  printf(" %d", p);
  if(tree[p].left != -1) visit_pre(tree[p].left);
  if(tree[p].right != -1) visit_pre(tree[p].right);
}

void visit_in(int p){
  if(tree[p].left != -1) visit_in(tree[p].left);
  printf(" %d", p);
  if(tree[p].right != -1) visit_in(tree[p].right);
}

void visit_post(int p){
  if(tree[p].left != -1) visit_post(tree[p].left);
  if(tree[p].right != -1) visit_post(tree[p].right);
  printf(" %d", p);
}

main(){
  int i, r;
  scanf("%d", &n);
  memset(root, 1, n);
  for(i=0;i<n;i++) tree[i].left = tree[i].right = -1;
  for(i=0;i<n;i++){
    int idx, l, r;
    scanf("%d %d %d", &idx, &l, &r);
    tree[idx].left = l;
    tree[idx].right = r;
    root[l] = root[r] = 0;
  }
  for(i=0;i<n;i++) if(root[i]) r = i;
  printf("Preorder\n");
  visit_pre(r);
  printf("\n");
  printf("Inorder\n");
  visit_in(r);
  printf("\n");
  printf("Postorder\n");
  visit_post(r);
  printf("\n");
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<list>
#include<queue>
#include<string.h>
#include<functional>
#include<stack>
#include<deque>
#include<string>
#include<limits.h>
#include<map>
#include<set>
#include<unordered_map>
#include<cmath>
#include<unordered_set>
using namespace std;

int ans[100][100];
signed main() {
	int a, b, n; cin >> a >> b >> n;
	int x = 0, y = 0;
	for (int i = 0; i < n; i++) {
		int c; cin >> c;
		while (c--) {
			ans[x][y] = i + 1;
			if (x & 1) {
				y--;
				if (y == -1) {
					y++;
					x++;
				}
			}
			else {
				y++;
				if (y == b) {
					y--;
					x++;
				}
			}
		}
	}
	for (int i = 0; i < a; i++) {
		for (int j = 0; j < b; j++) {
			if (j)cout << " ";
			cout << ans[i][j];
		}
		cout << endl;
	}
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

                if (input[0] == 0 && input[1] == 0 && input[2] == 0) break;

                Array.Sort(input);

                double l = Math.Sqrt(input[0] * input[0] + input[1] * input[1]);

                int n = int.Parse(Console.ReadLine());

                for (int i = 0; i < n; i++)
                {
                    int r = int.Parse(Console.ReadLine());

                    sb.AppendLine(r * 2 > l ? "OK" : "NA");
                }
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9072
#include <bits/stdc++.h>
#define VI vector<int> 
#define SI set<int>
#define QI queue<int> 
#define PII pair<int, int>
#define MP make_pair
#define PB push_back
#define REP(i,a,b) for(int i = a; i < b; ++i)
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define M 1000000007
using namespace std;

int main()
 {  
    FIO
    int a,b; cin>>a>>b;
    if (a == 1 or b == 1)
    {
        if (a == 1)
        {
            if(b == 1) cout<<"Draw";
            else cout<<"Alice";
        }
        else {
            cout<<"Bob";
        }
    }
    else {
        if(a == b) cout<<"Draw";
        else if(a > b) cout<<"Alice";
        else cout<<"Bob";
    }


    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int const N = 200000;
  vector<int> prime(N);
  REP(i,N)
    prime[i] = i;
  prime[0]=prime[1]=0;
  REP(i,N)
    if (prime[i])
      for (int j=i*2; j<N; j+=i) 
        prime[j] = 0;
  prime.erase(remove(ALL(prime), 0), prime.end());
  int n,p;
  while(cin>>n>>p,n>=0) {
    vector<int> v;
    int cnt = 0;
    vector<int>::iterator hoge = upper_bound(ALL(prime), n);
    for (vector<int>::iterator it = hoge; cnt<p; ++cnt, ++it) {
      int cnt2 = 0;
      for (vector<int>::iterator jt = it; cnt2<=p-cnt; ++cnt2, ++jt) {
//        cout << *it << " " << *jt << endl;
        v.push_back(*it + *jt);
      }
    }
    sort(ALL(v));
    // FOR(it, v)
    //   cout << *it << " ";
    // cout << endl;
    cout << v[p-1] << endl;
  }
}

Measured memory_bytes: 0
#include <algorithm>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

struct Enclosure {
  int l, r, len;
  Enclosure(int l_, int r_) : l(l_), r(r_), len(r_ - l_ + 1) {}
  bool operator<(const Enclosure& other) const { return len < other.len; }
};

template <class T>
struct fenwick_tree {
  vector<T> x;
  fenwick_tree(int n) : x(n, 0) {}
  T sum(int i, int j) {
    if (i == 0) {
      T S = 0;
      for (; j >= 0; j = (j & (j + 1)) - 1) S += x[j];
      return S;
    } else
      return sum(0, j) - sum(0, i - 1);
  }
  void add(int k, T a) {
    for (; k < x.size(); k |= k + 1) x[k] += a;
  }
};

int main() {
  int N, M;
  while (cin >> N >> M) {
    vector<Enclosure> enclosures;
    for (int i = 0; i < N; i++) {
      int l, r;
      cin >> l >> r;
      enclosures.emplace_back(Enclosure(l, r));
    }
    sort(enclosures.begin(), enclosures.end());
    fenwick_tree<int> ft(M + 10);
    int k = 0;
    for (int d = 1; d <= M; d++) {
      while (k < N && enclosures[k].len < d) {
        ft.add(enclosures[k].l, +1);
        ft.add(enclosures[k].r + 1, -1);
        ++k;
      }
      int ans = N - k;
      for (int p = 0; p <= M; p += d) {
        ans += ft.sum(0, p);
      }
      cout << ans << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 8560
n = int(input())
s = input()
l = [a for a in s]
if len(l)%2 == 1:
    print("No")
    exit()
n2 = int(n/2)
if "".join(l[:n2]) == "".join(l[n2:]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
	 int a[10]={0};
	 for(int i=0;i<4;i++){
	 	 int t;
	 	 cin>>t;
	 	 a[t]++;
	 }
	 if(a[1]&&a[7]&&a[9]&&a[4])
	 printf("YES\n");
	 else
	 printf("NO\n");
 } 

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

int main() {
  int K,A,B;
  cin >> K >> A >> B;
  
  for(int i=A;i<=B;i++){
    if(i%K) continue;
    else{
      cout << "OK" << endl;
      return 0;
    }
  }

  cout << "NG" << endl;
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

//++時計回り --反時計回り
// int dx[4] = {1, 0, -1, 0};
// int dy[4] = {0, 1, 0, -1};

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  cout << min(A * N, B) << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstring>

using namespace std;

int main(){
  string n;
  cin >> n;
  bool flag = 0;
  for(int i = 0; i < 3; i++){
    if(n[i] == '7') flag = 1;
  }

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

  return 0;
}

Measured memory_bytes: 3624
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        n: usize, a: usize, b: usize
    }
    let ans = if n * a > b { b } else { n * a };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <stdio.h>
int main()
{
    int a, b, c;
    int i = 0;
    scanf("%d %d %d", &a, &b, &c);
    for (int x = a; x <= b; x++)
        if(c%x==0) 
        {
            i += 1;
        }
    printf("%d\n", i);
}



Measured memory_bytes: 2112
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()

int main() {
	int a, b;
	cin >> a >> b;
	if (a <= 8 and b <= 8)cout << "Yay!" << endl;
	else cout << ":(" << endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;


#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;


void Main(){
   int N;
   string S;
   cin >> N >> S;
   
   int count = 0;
   
   rep(i,N-1){
       if(S[i]==S[i+1]){
           count++;
       }
   }
  cout << N-count << endl;
 return;
 }
  
int main(){
 cin.tie(nullptr);
 ios_base::sync_with_stdio(false);
 cout << fixed << setprecision(15);
 Main();
 return 0;
 }

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int n = in.nextInt() + 1;
        in.nextLine();
        final int[] leaves = new int[n];
        long branch = 0;
        for (int i = 0; i < n; i++) {
            leaves[i] = in.nextInt();
            branch += leaves[i];
        }
        branch--;
        long res = 0;
        long curr = 1;
        for (int i = 0; i < n; i++) {
            res += curr;
            curr -= leaves[i];
            if (curr < 0) {
                res = -1;
                break;
            }
            if (curr <= branch) {
                branch -= curr;
                curr *= 2;
            } else {
                curr += branch;
                branch = 0;
            }
        }
        System.out.println(res);
    }
}


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

using namespace std;

#define int long long

int cnt(int a) {
    int ans = 0;
    while (a % 2 == 0) {
        ++ans;
        a /= 2;
    }
    return ans;
}

void solve() {
    int n, m;
    cin >> n >> m;
    int a[n];
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i < n - 1; ++i) {
        if (cnt(a[i]) != cnt(a[i + 1])) {
            cout << 0;
            return;
        }
    }
    int g = a[0] / 2;
    int st = a[0] / 2;
    for (int i = 1; i < n; ++i) {
        a[i] /= 2;
        g = __gcd(st, a[i]);
        st *= a[i] / g;
        if (st > m - 1) {
            cout << 0;
            return;
        }
    }
    int l = 0, r = 1e9;
    while (l < r - 1) {
        int mid = (l + r) / 2;
        if (1 + st + 2 * st * mid <= m) l = mid;
        else r = mid;
    }
    cout << 1 + l;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> ipair;
typedef tuple<int, int, int> ituple;

// const int INF = INT_MAX;
// const ll INF = LLONG_MAX;
// const int MOD = ((int)1e9 + 7);
// const ld EPS = (1e-10);
#define PI acosl(-1)
#define MAX_N (100000 + 2)

void exec(){
  int n;
  ll a[MAX_N], b[MAX_N];
  ll happiness[2];
  vector<pair<ll, int>> points;

  happiness[0] = happiness[1] = 0;
  cin >> n;
  for (int i = 0; i < n; i++){
    scanf("%lld %lld", &a[i], &b[i]);

    points.push_back(make_pair(a[i] + b[i], i));
  }

  sort(points.rbegin(), points.rend());

  int head = 0;
  int player = 0;

  for (int i = 0; i < n; i++){
    if (player == 0){
      happiness[player] += a[points[head].second];
    }
    else{
      happiness[player] += b[points[head].second];
    }
      head++;

    player = 1 - player;
  }

  printf("%lld\n", happiness[0] - happiness[1]);

}

void solve(){
  int t = 1;
  // scanf("%d", &t);
  for (int i = 0; i < t; i++){
    exec();
  }
}

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


Measured memory_bytes: 3444
#include <iostream>
using namespace std;
long long int max_val(long long int wt[],long long int val[],long long int n,long long int w)
{
	long long int i,j;
	long long int dp[n+1][w+1];
	for(i=0;i<=n;i++)
	{
		for(j=0;j<=w;j++)
		{
		    if(i==0 || j==0)
		    dp[i][j]=0;
		    else if(wt[i-1]<=j)
		    dp[i][j]=max(dp[i-1][j-wt[i-1]]+val[i-1],dp[i-1][j]);
		    else
		    dp[i][j]=dp[i-1][j];
		}
	}
	return dp[n][w];
}
int main() {
    long long int n,w,i;
    cin>>n>>w;
    long long int val[n],wt[n];
    for(i=0;i<n;i++)
    cin>>wt[i]>>val[i];
    cout<<max_val(wt,val,n,w);
	return 0;
}

Measured memory_bytes: 79104
line = readlines.map(&:chomp)

N = line[0].to_i

ac = 0
wa = 0
tle = 0
re = 0
for i in 1..N do
  s = line[i]
  if s == "AC" then
    ac += 1
  elsif s == "WA" then
    wa += 1
  elsif s == "TLE" then
    tle += 1
  else
    re += 1
  end
end
    
puts "AC x " + ac.to_s
puts "WA x " + wa.to_s
puts "TLE x " + tle.to_s
puts "RE x " + re.to_s

Measured memory_bytes: 30724
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi >
#define vvvi vector<vvi >
#define pii pair<int,int>
#define INF 1e9
#define MOD 1e9+7
typedef long long llong;
using namespace std;

int main(){
	int a,b;
	cin>>a>>b;
	
	if(a>=13) cout<<b;
	else if(a>=6) cout<<b/2;
	else cout<<0;
}

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

int main(){
  int N,*selection;
  int i,j,tmp,min,k,count=0,flag=0;
  scanf("%d",&N);
  if(N>=1&&N<=100){//Nの条件は問題文に応じて変更する
    selection=(int *)malloc(N*sizeof(int));
    for(i=0;i<N;i++){
      scanf("%d",&selection[i]);
      if(selection[i]<0||selection[i]>100){
	exit(1);
      }
    }
    for(i=0;i<N-1;i++){
      min=i;//配列の先頭を最小値とする
      flag=0;
      for(j=i;j<N;j++){//比較ループ
	if(selection[j]<selection[min]){//昇順に並べるから
	  min=j;//最小値を持つ要素を更新
	  flag=1;
	}
      }
      if(flag){
	count++;
      tmp=selection[i];
      selection[i]=selection[min];
      selection[min]=tmp;
      }
    }
    for(k=0;k<N;k++){
      if(k!=N-1)printf("%d ",selection[k]);
      else printf("%d",selection[k]);
    }
    printf("\n%d\n",count);
    
  }
  return 0;
}



Measured memory_bytes: 2136
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <map>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926

typedef long long int ll;

ll num[ten52];
//int numAC[ten5];
//int numWA[ten5];

int main(void)
{
    long long int sum=0,range=0,ceiling;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=0,money;
    long long int a1,a2=0,a3=0,ar,as,at1;
    char c;
    //vector <int> v;
    //float f,g,h;
    //int c,d,big=0;
    string s,s1;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>num[i];
    }
    a1=num[0];
    for(i=0;i<n;i++)
    {
        a1=min(a1,num[i]);
        if(a1==num[i]) sum++;
    }
    cout<<sum;
    return 0;
}





Measured memory_bytes: 1792
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor, gcd
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10
    sa,sb = input().split()
    a = int(sa)
    b = int(float(sb)*100+0.5)
    print(a*b//100)

    
main()


Measured memory_bytes: 65376
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    ps = LI()
    ps_s = sorted(ps)
    c = 0
    for i in range(n):
        if ps[i] != ps_s[i]:
            c += 1
    if c < 3:
        print("YES")
    else:
        print("NO")

if __name__ == '__main__':
    main()

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

int main(){
  int N;
  cin >> N;
  vector<string> title(N);
  vector<int> time(N); 
  for(int i=0; i<N; ++i){
    cin >> title.at(i) >> time.at(i);
  }
  string X;
  cin >> X;
  
  int ans;
  bool a=false;
  for(int i=0; i<N; ++i){
    if(a==true){
      ans += time.at(i);
    }
    if(X == title.at(i)) a=true;
  }
  cout << ans << endl;
}

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

using namespace std;

int main() {
    vector<int> times(5);
    vector<int> dist(5);
    int t = 0;

    int tmp = 0;
    int i = 0;
    while(cin >> tmp) {
        times[i] = tmp;

        int count = 0;

        while(!(tmp % 10 == 0)) {
            tmp ++;
            count ++;
        }

        dist[i] = count;

        i ++;

        if(i >= 5) {
            break;
        }
    }

    /*
    for(int i = 0; i < 5; i ++) {
        cout << dist[i] << endl;
    }
    */

    int loop = 0;

    while(1) { 
        loop ++;
        int min = dist[0];
        int id = 0;

        for(int i = 1; i < 5; i++) {
            if(min > dist[i]) {
                min = dist[i];
                id = i;
            }
        }

         t += times[id];

        if(loop == 5) {
            break;
        }

        t += dist[id];

        dist[id] = 10;


    }

    cout << t << endl;



}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
int main()
{
	fast;
	ll n,x,cnt=0;
	cin>>n>>x;
	vector <ll> v;
	v.push_back(0);
	ll arr[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	for(int i=0;i<n;i++)
	{
		v.push_back(arr[i]+v[i]);
	}
	for(int i=0;i<v.size();i++)
		if(v[i]<=x)
			cnt++;
	cout<<cnt;
	return 0;
}


Measured memory_bytes: 3592
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void insert(int);
void inorder();
void preorder();

typedef struct node {
        int key;
        struct node *right, *left, *parent;
}node;

node *root, *NIL;

int main(){
        int n, i, x;
        char str[6];

        scanf("%d", &n);

        for(i=0; i<n; i++) {
                scanf("%s", str);
                if(strcmp(str,"insert")==0) {
                        scanf("%d", &x);
                        insert(x);
                }
                else if(strcmp(str,"print")==0) {
                        inorder(root);
                        printf("\n");
                        preorder(root);
                        printf("\n");
                }
        }
        return 0;
}

void insert(int k) {
        node *y = NIL;
        node *x = root;
        node *z;

        z = (node * )malloc(sizeof(node));
        z->key = k;
        z->left = NIL;
        z->right = NIL;

        while(x!=NIL) {
                y=x;
                if(z->key < x->key) {
                        x = x->left;
                }
                else {
                        x= x->right;
                }
        }
        z->parent = y;
        if(y==NIL) {
                root = z;
        }
        else{
                if(z->key < y->key) {
                        y->left = z;
                }

                else{
                        y->right = z;
                }
        }
}
void inorder(node *u){
        if(u==NIL) return;
        inorder(u->left);
        printf(" %d", u->key);
        inorder(u->right);
}

void preorder(node *u){
        if(u==NIL ) return;
        printf(" %d", u->key);
        preorder(u->left);
        preorder(u->right);
}

Measured memory_bytes: 24040
x = int(input())
lis = []
for i in range(-150,151):
    lis.append(i**5)
tab = [[0]*301 for _ in range(301)]
for j in range(301):
    for k in range(301):
        tab[j][k] = lis[j]-lis[k]
for l in range(301):
    for m in range(301):
        if tab[l][m] == x:
            print(l-150, m-150)
            exit()



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

int main(){
	int a[5];
	for(int i=0;i<5;i++)
		cin >> a[i];
	int k;
	cin >> k;
	if(a[4]-a[0]>k){
		cout << ":(" << endl;
		return 0;
	}
	cout << "Yay!" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include<fstream>
using namespace std;

int MAXint(int a, int b)
{
    if(a >= b)return a;
    else return b;
}

int MINint(int a, int b)
{
    if(a>=b)return b;
    else return a;
}


int main()
{
    int H, W;
    int i, j, bombnum;
    int i0, j0;
    cin>> H >> W;
    char tempc;
    string temp;
    vector <string> grid;
    for(i=0; i<H; ++i)
    {
        cin>> temp;
        grid.push_back(temp);
    }

    for(i=0; i<H; ++i)
    {
        for(j=0; j<W; ++j)
        {
            if(grid[i][j] == '#')continue;
            else
            {
                bombnum = 0;
                for(i0=MAXint(0, i-1); i0<MINint(i+2, H); ++i0)
                {
                    for(j0=MAXint(0, j-1); j0<MINint(j+2, W); ++j0)
                    {
                        if(grid[i0][j0] == '#') ++bombnum;
                    }
                }
                tempc = bombnum + 48;
                grid[i][j] = tempc;

            }
        }
    }

    for(i=0; i<H; ++i)
    {

        cout<< grid[i] << endl;

    }





    return 0;
}












Measured memory_bytes: 256
import numpy as np
n, m, x = map(int, input().split())
l = []
for i in range(n):
    l += [list(map(int, input().split()))]

a = 1 <<(n )
r = []
for i in range(a):
    li = np.array([0 for _ in range(m +1)])
    for j in range(n):
        if i & (1 << j):
            li += l[j]
#     print(li)
    for k in range(1,m +1):
        if li[k] < x:
            break
        if k == m:
            r +=[li[0]]
        
if len(r) == 0:
    print('-1')
else:
    print(min(r))

Measured memory_bytes: 27248