akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(n);
  rep(i, n) cin >> l[i];
  sort(rall(l));
  int ans = 0;
  rep(i, k) ans += l[i];
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
 typedef long long ll;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;
 const ll INF = 1LL << 60;

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

   vector<vector<ll>> a(3, vector<ll>(N + 1));
   vector<vector<ll>> happy(3, vector<ll>(N + 1, 0));

   rep(i, 1, N + 1) cin >> a.at(0).at(i) >> a.at(1).at(i) >> a.at(2).at(i);

   happy.at(0).at(1) = a.at(0).at(1);
   happy.at(1).at(1) = a.at(1).at(1);
   happy.at(2).at(1) = a.at(2).at(1);

   rep(i, 2, N + 1) {
     rep(j, 0, 3) {
       rep(k, 0, 3) {
         if (j == k) continue;
         else happy.at(j).at(i) = max(happy.at(j).at(i), happy.at(k).at(i - 1) + a.at(j).at(i));
       }
     }
   }
   cout << max(happy.at(0).at(N), max(happy.at(1).at(N), happy.at(2).at(N))) << endl;
 }


Measured memory_bytes: 5744
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
const int MAX=1e5+5;
struct city
{
	int P;
	int Y;
	int num;
	int x;
}c[MAX];
bool cmp1(city a,city b)
{
	if(a.P==b.P)
		return a.Y<b.Y;
	else
		return a.P<b.P;
}
bool cmp2(city a,city b)
{
	return a.num<b.num;
}
int main(int argc, char *argv[])
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
		{cin>>c[i].P>>c[i].Y;c[i].num=i+1;}
	sort(c,c+m,cmp1);
	int x=c[1].P;
	int y=1;
	for(int i=0;i<m;i++)
	{
		if(x!=c[i].P)
		{
			x=c[i].P;
			y=1;
		}
		c[i].x=y;
		y++;
	}
	sort(c,c+m,cmp2);
	for(int i=0;i<m;i++)
		printf("%06d%06d\n",c[i].P,c[i].x);
	return 0;
}

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

int main() {
    ll a,b,c,d,u,v,x,y,t,lcm1,lcm2,ans;
    cin>>a>>b>>c>>d;
   ll tot=(b-a)+1;
 //  cout<<tot<<" ";
    x=a-1;
    t=x;
    x=x/c;
    y=t/d;
  //  cout<<x<<" "<<y<<" ";
    lcm1=(c*d)/__gcd(c,d);
  //  cout<<lcm1<<" ";
    lcm2=lcm1;
    lcm1=t/lcm1;
    lcm1=(x+y)-lcm1;
  //  cout<<lcm1<<" ";
    u=b/c;
    v=b/d;
    lcm2=b/lcm2;
    ans=(u+v)-lcm2;
    ans=ans-lcm1;
   // cout<<ans;
    cout<<tot-ans;

}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
6 9
0 1 1
0 2 3
1 2 1
1 3 7
2 4 1
1 4 3
3 4 1
3 5 1
4 5 6

output:
5
"""

import sys
from operator import attrgetter


class Edge(object):
    __slots__ = ('source', 'target', 'weight')

    def __init__(self):
        self.weight = float('inf')
        self.source, self.target = None, None


class UnionFind(object):
    __slots__ = ('size', 'tree_height_rank_list', 'ancestor_list')

    def __init__(self, size):
        self.size = int(size)
        self.tree_height_rank_list = [0] * self.size
        self.ancestor_list = [i for i in range(self.size)]

    def _find(self, x):
        if x != self.ancestor_list[x]:
            self.ancestor_list[x] = self._find(self.ancestor_list[x])
        return self.ancestor_list[x]

    def same(self, x, y):
        return self._find(x) == self._find(y)

    def _link(self, x, y):
        if self.tree_height_rank_list[x] > self.tree_height_rank_list[y]:
            self.ancestor_list[y] = x
        else:
            self.ancestor_list[x] = y
            if self.tree_height_rank_list[x] == self.tree_height_rank_list[y]:
                self.tree_height_rank_list[y] += 1

    def union(self, x, y):
        self._link(self._find(x), self._find(y))


def generate_edge_table(v_table):
    for index, each in enumerate(v_table):
        source, target, weight = map(int, each)
        init_edge_table[index].source = source
        init_edge_table[index].target = target
        init_edge_table[index].weight = weight

    return init_edge_table


def graph_Kruskal():
    total_cost = 0
    edge_table.sort(key=attrgetter('weight'))
    # MST--> E = V + 1
    union_find_case = UnionFind(size=vertices + 1)
    for edge in edge_table:
        if not union_find_case.same(edge.source, edge.target):
            total_cost += edge.weight
            union_find_case.union(edge.source, edge.target)

    return total_cost


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices, edges = map(int, _input[0].split())
    v_info = map(lambda x: x.split(), _input[1:])

    init_edge_table = [Edge() for _ in range(edges)]
    edge_table = generate_edge_table(v_info)
    print(graph_Kruskal())

Measured memory_bytes: 32748
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
#define ceil(a,b) (a+b-1)/b
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

//START OF CODE ->->->->->->->

void solve()
{
    int a,b,t;
    cin>>a>>b>>t;
    cout<<t/a * b<<endl;
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



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

int main(){
  int n;
  cin >> n;
  string ans = "hon";
  string N = to_string(n);
  if(N[N.length()-1]=='3'){
    ans = "bon";
  }else if(N[N.length()-1]=='0'||N[N.length()-1]=='1'){
    ans = "pon";
  }else if(N[N.length()-1]=='6'||N[N.length()-1]=='8'){
    ans = "pon";
  }
  cout << ans;
}


Measured memory_bytes: 3692
#include<stdio.h>
#include<string.h>
int main ()
{
    char str1[100];
    char str2[100];
    char str3[100];
    int i,j;
    scanf("%s",str1);
    scanf("%s",str2);
    scanf("%s",str3);
    i=strlen(str1);
    j=strlen(str2);
    if(str1[i-1]==str2[0] && str2[j-1]==str3[0]){
        printf("YES\n");
    }
    else printf("NO\n");
    return 0;
}


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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int>answer(N);
  for(int i=0;i<M;i++) {
    vector<int>road(2);
    cin >> road.at(0) >> road.at(1);
    int x,y;
    x=road.at(0);
    y=road.at(1);
    answer.at(x-1)+=1;
    answer.at(y-1)+=1;
  }
  
  for(int i=0;i<N;i++) {
    cout << answer.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <utility>
#include <map>
#include <inttypes.h>


int main(){
	int N;
    
    std::cin >> N;
    int F[100];
    F[0]=F[1]=1;
    for(int i=2;i<=N;i++){
        F[i]=F[i-1]+F[i-2];
    }
    std::cout << F[N]<< std::endl;
    return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll x;
    cin, x;
    ll m = 100;
    int cnt = 0;
    while (m < x) {
        m *= 1.01;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long
#define inf 1000000001
using namespace std;
#define N 100005
int n,now,a[N],b[N];ll ans;
int main(){
    scanf("%d",&n);
    rep (i,1,n) scanf("%d%d",&a[i],&b[i]);
    n++;
    sort(&a[1],&a[n+1]);sort(&b[1],&b[n+1]);
    rep (i,1,n) ans+=max(0,a[n-i+1]-b[i]);ans*=2;
    cout<<ans<<'\n';
    return 0;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define PB push_back

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVi;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;

int main(){
	ios::sync_with_stdio(false);
    int n;
    cin>>n;
    VI a(n+1);
    VI v(n+1);
    int cnt=0;
    for(int i=1;i<=n;i++){
        v[i]=true;
    }
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        if(v[i] == true && v[a[i]] == true){
            if(a[a[i]] == i){
                cnt++;
                v[i]=false;
                v[a[i]]=false;
            }
        }

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


Measured memory_bytes: 1024
N = int(input())
h = list(map(int, input().split()))
x = [0, abs(h[1] - h[0])]

for i in range(2, N):
    x.append(min(x[i - 1] + abs(h[i] - h[i - 1]), x[i - 2] + abs(h[i] - h[i - 2])))

print(x[N - 1])




Measured memory_bytes: 13980
import sys
def f(x):
  if x%2==0:
    return x//2
  else:
    return (x*3)+1
s=int(input())
S=list()
i=2
S.append(s)
while True:
  s=f(s)
  if s not in S:
    S.append(s)
  else:
    print(i)
    sys.exit()
  i+=1

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



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

	if(x-'A'>y-'A'){
		cout<<">"<<endl;
	}
	else if(x-'A'<y-'A'){
		cout<<"<"<<endl;
	}
	else{
		cout<<"="<<endl;
	}


return 0;
}



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

#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)
const int inf = 1000000000; // 10^9

int main(){
   char s[3][4];
   for(int i = 0;i < 3;i++){
      scanf("%s",s[i]);
   }
   printf("%c%c%c",s[0][0],s[1][1],s[2][2]);
}

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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

template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
constexpr int INF = 1001001001;
//constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;


int main() {
    int N, M, X, Y; cin >> N >> M >> X >> Y;
    vi x(N + 1), y(M + 1);
    rep(i, N) cin >> x[i];
    rep(j, M) cin >> y[j];
    x[N] = X; y[M] = Y;
    cout << (*max_element(all(x)) < *min_element(all(y)) ? "No War" : "War" ) << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map(String::toInt)
    val mod = 1000000007L

    var ans = 1L
    val countArray = IntArray(n + 1) { 0 }
    for (a in aList) {
        if (a == 0) {
            ans *= (3 - countArray[a])
            ans %= mod
            countArray[a] = countArray[a] + 1
        } else {
            ans *= (countArray[a - 1] - countArray[a])
            ans %= mod
            countArray[a] = countArray[a] + 1
        }
    }
    println(ans)
}


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

bool solve(int c[3][3], int a[3]){
    int b[3];
    for(int j=0; j<3; j++)
        b[j] = c[0][j] - a[0];

    for(int i=1; i<3; i++)
        for(int j=0; j<3; j++)
            if(c[i][j] != a[i] + b[j]) return false;
    return true;
}

int main(){
    int c[3][3];
    for(int i=0; i<3; i++)
        for(int j=0; j<3; j++)
            cin >> c[i][j];

    for(int a1=0; a1<=100; a1++)
        for(int a2=0; a2<=100; a2++)
            for(int a3=0; a3<=100; a3++){
                int a[3] = {a1, a2, a3};
                if(solve(c, a)){
                    cout << "Yes" << endl;
                    return 0;
                }
            }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	unsigned long long blue;
	unsigned long long n;
	unsigned long long a;
	unsigned long long b;
	
	scanf("%lld",&n);
	scanf("%lld",&a);
	scanf("%lld",&b);
	
	blue=((n-n%(a+b))/(a+b))*a;
	if(n%(a+b)>a){
		blue+=a;
	}else{
		blue+=n%(a+b);
	}
	
	printf("%lld",blue);
}

Measured memory_bytes: 128
#include<stdio.h>

int main(void) {
	int i, n, minj, j, a[100], count = 0, temp;
	
	scanf("%d", &n);
	for (i = 0; i < n; ++i) scanf("%d", &a[i]);
	
	for (i = 0; i < n; ++i)
	{
		minj = i;
		for (j = i; j < n; ++j)
		{
			if (a[j] < a[minj]) minj = j;
		}
		if (i != minj)
		{
			temp = a[i];
			a[i] = a[minj];
			a[minj] = temp;
			++count;
		}
	}
	
	for (i = 0; i < n; ++i)
	{
		printf("%d", a[i]);
		if (i != n-1) printf(" ");
	}
	printf("\n");
	printf("%d\n", count);
	
	return 0;
}

Measured memory_bytes: 2672
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int count = 0 ;
		int arr[] = new int[n];
		for(int i = 0; i< n ; i++) {
			arr[i] = scan.nextInt();
		}
		int arr2[] = arr.clone();
		Arrays.sort(arr);
		
		for(int i = 0 ; i < n ; i++) {
			if(arr[i] != arr2[i]) {
				count++;
			}
		}
		//System.out.println(count);
		
		if(count == 0 || count ==2) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
		
	}
}


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

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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++)
        cin >> a[i];

    vector<int> l(N + 1), r(N + 1);
    l[0] = 0, r[N] = 0;
    for (int i = 1; i <= N; i++)
        l[i] = gcd(l[i - 1], a[i - 1]);
    for (int i = N - 1; i >= 0; i--) {
        r[i] = gcd(r[i + 1], a[i]);
    }

    int res = 0;
    for (int i = 0; i < N; i++) {
        int l_gcd = l[i];
        int r_gcd = r[i + 1];

        res = max(res, gcd(l_gcd, r_gcd));
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int M,W;
int bm[15];
int bw[15];
int dp[15][1<<15];
int en(int a,int b){
	int x=abs(a-b);
	return x*(x-30)*(x-30);
}
int main()
{
	while(true){
		scanf("%d%d",&M,&W);
		if(M==0&&W==0)break;
		for(int i=0;i<M;i++)scanf("%d",&bm[i]);
		for(int i=0;i<W;i++)scanf("%d",&bw[i]);
		for(int i=0;i<15;i++){
			for(int j=0;j<(1<<15);j++){
				dp[i][j]=0;
			}
		}
		for(int j=0;j<W;j++){
			dp[0][1<<j]=en(bm[0],bw[j]);
		}
		for(int i=1;i<M;i++){
			for(int j=0;j<(1<<W);j++){
				dp[i][j]=max(dp[i][j],dp[i-1][j]);
				for(int k=0;k<W;k++){
					if((j>>k)&1){
						dp[i][j]=max(dp[i][j],dp[i-1][j-(1<<k)]+en(bm[i],bw[k]));
					}
				}
				//printf("%d %d:%d\n",i,j,dp[i][j]);
			}
		}
		int ans=0;
		for(int i=0;i<(1<<W);i++){
			ans=max(ans,dp[M-1][i]);
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 5128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007;



int main() {
    int N;
    cin>>N;
    vector<string> S(N);
    rep(i,N)cin>>S.at(i);
    vector<P> ls,rs;
    rep(i,N){
        int count=0,mini=0;
        rep(j,sz(S.at(i))){
            if(S.at(i).at(j)=='('){
                count++;
            }
            else{
                count--;
                chmin(mini,count);
            }
        }
        if(count>=0){
            ls.eb(mini,count);
        }
        else{
            rs.eb(mini-count,-count);
        }
    }
    sort(ls.rbegin(),ls.rend());
    sort(rs.rbegin(),rs.rend());
    int L=0,R=0;
    rep(i,sz(ls)){
        if(L+ls.at(i).first<0){
            cout<<"No"<<endl;
            return 0;
        }
        L+=ls.at(i).second;
        if(L<0){
            cout<<"No"<<endl;
            return 0;
        }
    }
    rep(i,sz(rs)){
        if(R+rs.at(i).first<0){
            cout<<"No"<<endl;
            return 0;
        }
        R+=rs.at(i).second;
        if(R<0){
            cout<<"No"<<endl;
            return 0;
        }
    }
    if(R!=L){
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 42592
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
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
#define int long long
int dp[410][410];
int a[410];
int N; 
int sum[410];
int calc(int L = 0, int R = N - 1) {
    if(L > R) return 0;
    if(L == R) return a[L];
    if(dp[L][R] != -1) return dp[L][R];
    int ret = INF2;
    REP(i, L, R - 1) {
        int tmp = calc(L, i) + calc(i + 1, R) + sum[R + 1] - sum[L];
        ret = min(ret, tmp);
    }

    return dp[L][R] = ret;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    rep(i, N) cin >> a[i];
    rep(i, 410) rep(j, 410) dp[i][j] = -1;
    rep(i, N) sum[i + 1] = sum[i] + a[i];
    cout << calc()- sum[N] << endl;

    return 0;
}


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

typedef long long s64;
#define rep(i,l,r) for(int i=l;i<=r;++i)
const int N=50+5,M=100+5,D=1e9+7;
s64 mi(s64 x,int y=D-2)
{
	s64 ans=1;
	while(y)
	{
		if(y&1)ans=ans*x%D;
		x=x*x%D;y>>=1;
	}
	return ans;
}
namespace BING
{
int fa[N],sz[N];
int find(int x)
{
	return x==fa[x]?x:fa[x]=find(fa[x]);
}
void merge(int x,int y)
{
	if(x==y)return ;
	fa[x]=y;
	sz[y]+=sz[x];
}
};
using BING::find;
vector<int>lk[N];
int fa[N],dfn[N],tot;
s64 f[M],jie[M];
int k;

void dfs(int x)
{
	dfn[x]=++tot;
	for(auto y:lk[x])
	if(y!=fa[x])
	{
		if(dfn[y])
		{
			if(dfn[y]>dfn[x])continue;
			int now=find(x);
			++BING::sz[now];
			for(int z=x;z=fa[z],z!=y;)BING::merge(find(z),now);
			continue;
		}
		++BING::sz[y];fa[y]=x;
		dfs(y);
	}
}
void init_f(int n)
{
	jie[0]=1;
	rep(i,1,n)jie[i]=jie[i-1]*i%D; 
	f[0]=1;
	rep(i,1,n)
	{
		s64 ans=0;
		rep(j,1,i)(ans+=f[i-j]*mi(jie[i-j]))%=D;
		f[i]=ans*jie[i-1]%D*k%D;
	}
}

int cnt[N];

int main()
{
	//freopen("1.in","r",stdin);
	int n,m;
	cin>>n>>m>>k;
	rep(i,1,m)
	{
		int x,y;
		cin>>x>>y;
		lk[x].push_back(y);
		lk[y].push_back(x);
	}
	
	rep(i,1,n)BING::fa[i]=i;
	rep(x,1,n)
	if(!dfn[x])dfs(x);
	init_f(m);
	rep(x,1,n)++cnt[BING::fa[x]];
	s64 ans=1;
	rep(x,1,n)
	if(BING::fa[x]==x)
	{
		int s=BING::sz[x];
		if(!s)continue;
		if(s==1){ans=ans*k%D;continue;}
		if(s>cnt[x]+1){ans=ans*f[s]%D*mi(jie[s])%D;continue;}
		s64 sum=0;
		rep(i,0,s-1)(sum+=mi(k,__gcd(i,s)))%=D;
		ans=ans*sum%D*mi(s)%D;
	}
	cout<<ans;
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

const int N = 200005;

int TC;
int n;

int a[N];

int main() {

	FAST;

	cin >> n;
	int a = n / 1000;
	int b = (n / 100) % 10;
	int c = (n / 10) % 10;
	int d = n % 10;
	if (a == b && b == c) {
		cout << "Yes\n";
	}
	else if (b == c && c == d) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
	return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> L(n);
	rep(i, n) cin >> L[i];
	sort(L.begin(), L.end());
	int ans = 0;
	rep(b, n) rep(a, b) {
		int ab = L[a] + L[b];
		int r = lower_bound(L.begin(), L.end(), ab) - L.begin();
		int l = b + 1;
		//c = [l, r)
		ans += max(0, r-l);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F(i,s,e) for(int i=s;i<e;++i)

void print(vector<int>& a){
    int n=a.size();
    for(int i=a.size()-1;i>=0;--i){
        cout << a[i];
        if(i!=0) cout << ' ';
    }
    cout << endl;
}

void insertionSort(vector<int>& a,int& n,int g,long long int& cnt){
    F(i,g,n){
        int v=a[i];
        int j=i-g;
        while(j>=0 && a[j]>v){
            a[j+g]=a[j];
            j=j-g;
            ++cnt;
        }
        a[j+g]=v;
    }
}

void shellSort(vector<int>& a,int& n){
    long long int cnt=0;
    vector<int> g;
    for(int h=1; ; ){
        if(h>n) break;
        g.push_back(h);
        h=3*h+1;
    }
    cout << g.size() << endl;
    print(g);
    for(int i=g.size()-1;i>=0;--i) insertionSort(a,n,g[i],cnt);
    cout << cnt << endl;
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    F(i,0,n) cin >> a[i];

    shellSort(a,n);
    F(i,0,n){
        cout << a[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 6792
#include <iostream>

using namespace std;

short N, x, cnt;

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> N;
  for (int i = 1; i <= N; i ++) {
    cin >> x;
    if ((x & 1) && (i & 1))
      cnt ++;
  }
  cout << cnt;
  return 0;
}


Measured memory_bytes: 3580
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define LLIandI pair<long long int , int>
#define ll long long

//第8回課題
//Slim span
//問題:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1280&lang=jp
// 中央＊前


/////////////////
struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};
int main(){
    while(1){
        int N,M;
        scanf("%d %d",&N,&M);
         //2 ≤ n ≤ 100 and 0 ≤ m ≤ n(n - 1)/2=5000. ak and bk (k = 1, ... , m) are positive integers less than or equal to n
        if(N==0&&M==0)break;
        vector<pair<int,int> > edges[12100];//(to,cost)
        rep(i,12100)edges[i].clear();
        vector< pair<int,pair<int,int> > > edge_list;//(cost,(a,b))
        edge_list.clear();
        vector<int> cost_list;
        cost_list.clear();
        rep(i,M){
            int a,b,w;
            scanf("%d %d %d",&a,&b,&w);a--;b--;
            edges[a].push_back(mp(b,w));
            edges[b].push_back(mp(a,w));
            edge_list.push_back(mp( w,mp(a,b)) );
            cost_list.push_back(w);
        }
        sort(cost_list.begin(),cost_list.end());
        sort(edge_list.begin(),edge_list.end());
        cost_list.erase(unique(cost_list.begin(),cost_list.end() ),cost_list.end() );
        //使うコストのうち最小のものの大きさをMとおり変えて行きながらクラスカルほう
        //最後に全頂点を一周して(N)全域木になっているかをチェック
        
        long long int slimness=1145141919810;
        rep(i,cost_list.size()){
            int mincost=cost_list[i];
            int mincost_ite=lower_bound(edge_list.begin(),edge_list.end(),mp(mincost,mp(0,0) ))-edge_list.begin();
            int maxcost=0;
            UnionFind uni(N);
            for(int j=mincost_ite;j<edge_list.size();j++){//短い辺から順に見て行く
                int nw=edge_list[j].first;int na=edge_list[j].second.first;int nb=edge_list[j].second.second;
                if(uni.findSet(na,nb)){//使えない
                    
                }else{//辺を連結して追加
                    uni.unionSet(na,nb);
                    maxcost=max(maxcost,nw);
                }
            }
            bool ifperfecttree=true;
            rep(j,N){
                if(uni.findSet(0,j)==false)ifperfecttree=false;
            }
            //printf("%lld,",slimness);
            if(ifperfecttree)slimness=min(slimness,(long long int)(maxcost-mincost));
        }
        if(slimness==1145141919810)printf("-1\n");
        else printf("%lld\n",slimness);
    }
}



Measured memory_bytes: 3052
#include <iostream>
#include <vector>
#include <limits>

template <class Cap, class Cost, bool isDirect>
class MinCostFlow {
    struct Edge {
        int from, to;
        Cap cap;
        Cost cost;
        int rev;
        Edge(int from, int to, Cap cap, Cost cost, int rev)
            : from(from), to(to), cap(cap), cost(cost), rev(rev){};
    };

    class Graph {
    public:
        int size;
        std::vector<std::vector<Edge>> path;

        explicit Graph(int N = 0) : size(N), path(size) {}
        void span(int from, int to, Cap cap, Cost cost, int rev) {
            path[from].push_back(Edge(from, to, cap, cost, rev));
        }
        std::vector<Edge>& operator[](int v) { return path[v]; }
    };

public:
    const Cost INF = std::numeric_limits<Cost>::max();
    Graph graph;
    std::vector<Cost> dist;
    std::vector<Edge*> rev;

    explicit MinCostFlow(int N) : graph(N), dist(N), rev(N) {}

    void span(int from, int to, Cap cap, Cost cost) {
        graph.span(from, to, cap, cost, graph[to].size());
        graph.span(to, from, (isDirect ? 0 : cap), -cost, graph[from].size() - 1);
    }

    void BellmanFord(int s) {
        fill(dist.begin(), dist.end(), INF);
        dist[s] = 0;

        bool update = true;
        while (update) {
            update = false;
            for (int v = 0; v < graph.size; ++v) {
                if (dist[v] == INF) continue;
                for (auto& e : graph[v]) {
                    if (e.cap > 0 && dist[e.to] > dist[e.from] + e.cost) {
                        dist[e.to] = dist[e.from] + e.cost;
                        rev[e.to] = &e;
                        update = true;
                    }
                }
            }
        }
    }

    Cost exec(int s, int g, Cap flow) {
        Cost ret = 0;

        while (flow > 0) {
            BellmanFord(s);
            if (dist[g] == INF) break;

            Cap f = flow;
            int v = g;
            while (v != s) {
                f = std::min(f, rev[v]->cap);
                v = rev[v]->from;
            }
            flow -= f;
            ret += f * dist[g];

            v = g;
            while (v != s) {
                // rev[v]->to = v
                rev[v]->cap -= f;
                graph[v][rev[v]->rev].cap += f;
                v = rev[v]->from;
            }
        }
        return (flow > 0 ? -1 : ret);
    }
};

int main() {
    int N, M, F;
    std::cin >> N >> M >> F;

    MinCostFlow<int, int, true> mcf(N);
    for (int i = 0; i < M; ++i) {
        int u, v, c, d;
        std::cin >> u >> v >> c >> d;
        mcf.span(u, v, c, d);
    }

    std::cout << mcf.exec(0, N - 1, F) << std::endl;
    return 0;
}



Measured memory_bytes: 3164
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    set<string> strs;
    for (int i = 0; i < n; i++) {
        char cmd[10], str[15];
        scanf("%s %s", cmd, str);
        if (cmd[0] == 'i') {
            strs.insert(str);
        } else {
            if (strs.count(str)) {
                printf("yes\n");
            } else {
                printf("no\n");
            }
        }
    }
}

Measured memory_bytes: 26880
using System;
 
class Program{
	static void Main(){
		int n = int.Parse(Console.ReadLine());
		decimal d1, d2, d3, d4;

		while(n-- > 0){
			string[] s = Console.ReadLine().Split(' ');
			decimal[] p = Array.ConvertAll(s, decimal.Parse);
			d1 = p[2] - p[0];
			d2 = p[3] - p[1];
			d3 = p[6] - p[4];
			d4 = p[7] - p[5];
			Console.WriteLine(d1 * d4 == d2 * d3 ? "YES" : "NO");
		}
	}
}

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

int main()
{
  int x[6];
  for (int i = 1; i <= 5; i++) {
    cin >> x[i];
  }
  for (int i = 1; i <= 5; i++) {
    if (x[i] == 0) {
      cout << i << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3564
mod = int(10 ** 9) + 7

def main():
    n = int(input())
    c = list(map(int, input().split()))

    c.sort()
    pow2 = [None for _ in range(2*n+1)]
    pow2[0] = 1
    for i in range(1, 2*n+1):
        pow2[i] = (pow2[i-1] * 2) % mod

    total_cost = [None for _ in range(n)]
    for i in range(n):
        k = n - i - 1
        p2k2 = (pow2[k-1] * (k + 2)) % mod
        if k-1 < 0:
            p2k2 = 1
        total_cost[i] = (((p2k2 * c[i]) % mod) * pow2[2*i] * pow2[k+1]) % mod

    ans = sum(total_cost) % mod

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 114636
v[1001];main(n,d,i,j,r){for(;~scanf("%d%d",&n,&d);printf("%d\n",r)){
	v[0]=2,v[1]=3;for(i=2;i<n;i++)v[i]=(v[i-2]+v[i-1])%1001;
	for(i=0;i<n;i++)for(j=0;j<n-i-1;j++)if(v[j]>v[j+1])r=v[j],v[j]=v[j+1],v[j+1]=r;
	for(i=r=1;i<n;i++)if(v[i]-v[i-1]>=d)r++;
}exit(0);}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007LL;

ll N, K;
vector<vector<ll>> G;

ll dfs(int v, int p) {
    ll ret = 1;
    ll c = K-1;
    if ( p != -1 ) c--;
    ll ch = G[v].size() - (p != -1 ? 1 : 0);
    if ( c < ch ) return 0;

    for ( int i = 0; i < G[v].size(); i++ ) {
        if ( G[v][i] == p ) continue;
        ll m = c * dfs(G[v][i], v);
        ret *= (m % MOD);
        ret %= MOD;
        c--;
    }
    return ret;
}


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

    ll ans = K * dfs(0, -1);
    ans %= MOD;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 11520
from collections import deque
import sys
sys.setrecursionlimit(10 ** 6)
def input():
    return sys.stdin.readline()[:-1]
 
H,W=[int(i) for i in input().split()]
C=[input() for _ in range(H)]
C=[list(i) for i in C] 
 
ans = 10**9
 
visited_list = [[10**9]*W for _ in range(H)]
stack = deque([[0, 0, 0]])
visited_list[0][0] = 0
 
w_cnt=0
for c in C: w_cnt += c.count(".")
 
def dfs(town, visited_list, stack):
    global ans
    flag = 0
    while len(stack) > 0:
        h, w, cnt = stack.pop()
        if h == H-1 and w == W-1 and ans > cnt:
            ans = cnt
            flag = 1
            continue
        for j, k in ([1, 0], [0, 1], [-1, 0], [0, -1]):
            new_h, new_w = h+j, w+k
            if new_h < 0 or new_h >= H or new_w < 0 or new_w >= W:
                continue
            if  town[new_h][new_w] != "#" and visited_list[new_h][new_w] > cnt + 1:
                visited_list[new_h][new_w] = cnt + 1
                stack.append([new_h, new_w, cnt+1])
    if flag: 
        ans = w_cnt-(ans+1)
        return ans
    else: return -1
 
print(dfs(C, visited_list, stack))

Measured memory_bytes: 44252
import sys
from collections import deque

input = sys.stdin.readline


def dfs(N):
    alphabet = "abcdefghij"
    stack = deque(["a"])
    while stack:
        s = stack.pop()
        if len(s) == N:
            print(s)
            continue
        for suffix in reversed(alphabet[:len(set(s)) + 1]):
            stack.append("".join((s, suffix)))


def main():
    N = int(input())

    dfs(N)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9304
#include <iostream>

using namespace std;
void hoanvi(int &x, int &y )
{
	int temp = x; 
	x = y; 
	y = temp;
}

int main()
{
	int a, b, c;
	cin>>a>>b>>c;
	if (a > b)
		hoanvi(a,b);
	if (b > c)
		hoanvi(b,c);
	if (a > b)
		hoanvi(a,b);
	cout<<a<<" "<< b <<" "<< c <<endl;
	return 0;
}

Measured memory_bytes: 3092
N = int(input())
S = input()

W_sum = [0]
E_sum = [S.count('E')]
for i in range(0, N):
    W_sum.append(W_sum[i] + 1 if S[i] == 'W' else W_sum[i]) 
    E_sum.append(E_sum[i] - 1 if S[i] == 'E' else E_sum[i])

res = float('inf')
for i in range(0, N+1):
    res = min(res, W_sum[i] + E_sum[i])
    
print(res)

Measured memory_bytes: 80860
import copy
n,m,q=[int(_) for _ in input().split()]
lista=[[int(i) for i in input().split()] for j in range(q)]
v=list()  #0,0,0,0,0....,0
def make(a,b,c): #a=list b=maxlen c=max
    global v
    if len(a)==b:
        v.append(a)
    else:
        for i in range(a[-1],c+1):
            k=copy.copy(a)
            k.append(i)
            make(k,b,c)
for t in range(1,m+1):
    make([t],n,m)
max=0
for j in v:
    point=0
    for l in lista:
        if j[l[1]-1]-j[l[0]-1]==l[2]:
            point+=l[3]
    if max<point:
        max=point
print(max)



Measured memory_bytes: 29108
'use strict';
(function(stdin) {
  var lines = stdin.toString().split('\n');
  var Command = function(str) {
    this.text = str;
    this.buf = [];
  };
  Command.prototype.exec = function(command,index,option) {
    var self = this;
    var commands = {
      print : function(index) {
        self.buf.push(self.text.slice(index[0],index[1] + 1));
      },
      reverse : function(index) {
        var chars = self.text.split('');
        var reverse = chars.splice(index[0],index[1] - index[0] + 1).reverse().join('');
        chars.splice(index[0],0,reverse);
        self.text = chars.join('');
      },
      replace : function(index) {
        var chars = self.text.split('');
        chars.splice(index[0],index[1] - index[0] + 1,option);
        self.text = chars.join('');
      }
    };
    commands[command](index);
  }
  var result = (function(source ,commands) {
    var command = new Command(source);
    commands.forEach(function(v) {
      command.exec(v[0],v.slice(1,3).map(Number),v[3]);
    });
    return command.buf.join('\n');
  }(lines.shift(),lines.slice(0,lines.shift()).map(function(v){return v.split(' ')})
    ));
  console.log(result);
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 9500
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int[] x = new int[N];
        for (int i = 0; i < N; i++) {
            x[i] = sc.nextInt();
        }
        System.out.println(solve2(N, A, x));
    }

    private static long solve(int n, int a, int[] x) {
        int[] y = Arrays.stream(x).map(i -> i - a).toArray();
        return brute(n - 1, 0, y);
    }

    private static long brute(final int i, final int n, final int[] y) {
        if (i < 0) return 0;
        return (n + y[i] == 0 ? 1 : 0) + brute(i - 1, n, y) + brute(i - 1, n + y[i], y);
    }

    private static long solve2(int n, int a, int[] x) {
        // dp[i][j][k] := {x_1 ... x_i} から j 個選んで，和が k となる組み合わせの数 O(n^3X)
        // 平均 0 を求めるようにすると，O(n^2X)
        int X = Math.max(a, Arrays.stream(x).max().getAsInt());
        long[][][] dp = new long[n + 1][n + 1][n * X + 1];
        dp[0][0][0] = 1;
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= n; j++) {
                for (int k = 0; k <= n * X; k++) {
                    if (k - x[i - 1] >= 0 && j - 1 >= 0) {
                        dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i - 1]];
                    } else {
                        dp[i][j][k] = dp[i - 1][j][k];
                    }
                }
            }
        }
        long ans = 0;
        for (int i = 1; i <= n; i++) {
            ans += dp[n][i][i * a];
        }
        return ans;
    }

}

Measured memory_bytes: 77332
import sys

readline = sys.stdin.readline

def main():
    N = int(input())
    DPa = [0] * N; DPb = [0] * N; DPc = [0] * N
    for i in range(N):
        a, b, c = map(int, readline().split())
        if i == 0:
            DPa[i] = a; DPb[i] = b; DPc[i] = c
        else:
            DPa[i] = max(DPb[i-1], DPc[i-1]) + a
            DPb[i] = max(DPa[i-1], DPc[i-1]) + b
            DPc[i] = max(DPa[i-1], DPb[i-1]) + c

    ans = max(DPa[N-1], DPb[N-1], DPc[N-1])
    print(ans)


if __name__ == "__main__":
    main()


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

main()
{
  char st[10];
  char st1[10];
  char a[] = "ABC";
  char b[] = "ARC";
  
  scanf("%s",st);
  if(strcmp(st,a)>0)
    strcpy(st1,a);
  else
    strcpy(st1,b);
  
  printf("%s",st1);
}

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

int main()
{
    int n;
    scanf("%d", &n);
    char S[n];
    
    char T[n];
    int i;
    scanf("%s%s",S,T);
    
    for(i=0;i<n;i++){
        printf("%c%c",S[i],T[i]);
    }
    
    return 0;
}


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

int top,S[1000];

void push(int x){
    S[++top]=x;
}

int pop(){
   top--;
   return S[top+1];
}

int main(){
    int a,b;
    top=0;
    char s[100];
	
    while(scanf("%s",s)!=EOF){
    if(s[0]=='+'){
    a=pop();
    b=pop();
    push(a+b);
    }
    	
    else if(s[0]=='-'){
    	b=pop();
    	a=pop();
    	push(a-b);
    }
    	
    else if(s[0]=='*'){
    	a=pop();
    	b=pop();
    	push(a*b);
    }
    	
    else{
    	push(atoi(s));
    }
   }
	
	printf("%d\n",pop());
	return 0;
}


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

int main() {
  int n, k, m, t, count = 0;
  scanf("%d", &n);
  scanf("%d", &k);
  vector<bool> v(n, 0);
  while(k--) {
    scanf("%d", &m);
    while(m--) {
      scanf("%d", &t);
      v[t-1] = 1;
    }
  }
  for (int i = 0; i < v.size(); i++) {
    if(v[i] == 0) count++;
  }
  printf("%d\n", count);
}

Measured memory_bytes: 3220
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTS(s) printf("%s\n",(s))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

typedef long long ll;
int Min(int a, int b) {
	return a<b ? a : b;
}

void Swap(char x[], int i, int j)
{
	int temp;

	temp = x[i];
	x[i] = x[j];
	x[j] = temp;
}

void ShowData(int x[], int left, int right)
{
	int i;
	for (i = left; i <= right; i++)printf("%d  ", x[i]);
	printf("\n");
}
void QSort(char x[], int left, int right, int n) {
	int i, j;	//左端,右端
	int pivot;	//軸

	i = left;
	j = right;
	pivot = x[(left + right) / 2];

	while (1) {
		if (n > 0) {				//n>0なら昇順、n<=0なら降順
			while ((x[i] < pivot) && (i <= right))i++;	//軸値より大きい要素
			while ((pivot < x[j]) && (i <= right))j--;	//軸値より小さい要素
		}
		else {
			while ((x[i] > pivot) && (i <= right))i++;	//軸値より小さい要素
			while ((pivot > x[j]) && (i <= right))j--;	//軸値より大きい要素
		}
		if (i >= j)	break;
		Swap(x, i, j);
		i++; j--;
	}
	//ShowData(x, left, right);

	if (left < i - 1)QSort(x, left, i - 1, n);
	if (j + 1 <  right)QSort(x, j + 1, right, n);
}


int main() {
	char s[101], t[101];
	scanf("%s %s", s, t);
	QSort(s, 0, strlen(s) - 1, 1);
	QSort(t, 0, strlen(t) - 1, 0);
	//ShowData(s, 0, strlen(s) - 1);
	int flag = 0;
	REP(i, Min(strlen(s), strlen(t))) {
		if (s[i] < t[i]) {
			flag = 1;
			break;
		}
		else if (s[i]>t[i]) {
			break;
		}
		if (i == strlen(s) - 1 && i != strlen(t) - 1) {
			flag = 1;
			break;
		}
	}
	if (flag)PRINTS("Yes");
	else PRINTS("No");
}

Measured memory_bytes: 128
#include<stdio.h>

int main(){

	long int N;
	scanf("%ld",&N);

	long int in[5];
	for(int i=0;i<5;i++){
		scanf("%ld",&(in[i]));
	}


	long int min = in[0];
	for(int i=1;i<5;i++){
		if(in[i]<min){
			min=in[i];
		}
	}

	if(N<min){
		printf("%ld\n",5);
		return 0;
	}

	long int n = N / min;
	if(N%min){
		n++;
	}

	printf("%ld",n+4);
	return 0;
}



Measured memory_bytes: 128
import numpy as np

h,w=map(int,input().split())
s=[]
for i in range(h):
    s.append(list(input()))
grid=(np.array(s) ==".") *1

l=np.zeros((h,w),dtype=int)
r=np.zeros((h,w),dtype=int)
u=np.zeros((h,w),dtype=int)
d=np.zeros((h,w),dtype=int)

for j in range(w):
    if j == 0:
        l[:,j] = grid[:,j]
    else:
        l[:,j] = (l[:,j-1]+1) * grid[:,j]
for j in range(w-1,-1,-1):
    if j == (w-1):
        r[:,j] = grid[:,j]
    else:
        r[:,j] = (r[:,j+1] +1)*grid[:,j]

for i in range(h):
    if i == 0:
        u[i,:]=grid[i,:]
    else:
        u[i,:]=(u[i-1,:]+1)*grid[i,:]
for i in range(h-1,-1,-1):
    if i==(h-1):
        d[i,:]=grid[i,:]
    else:
        d[i,:]=(d[i+1,:]+1)*grid[i,:]


ans=np.max(l+r+u+d-3)
print(ans)

Measured memory_bytes: 266488
#include <stdio.h>

typedef struct
{
	int n, e, w, s, t, b;
} dice;

void dice_scan(dice *x)
{
	scanf("%d %d %d %d %d %d", &x->t, &x->s, &x->e, &x->w, &x->n, &x->b);
}

void dice_rorate_n(dice *x)
{
	int temp;
	temp = x->n;
	x->n = x->t;
	x->t = x->s;
	x->s = x->b;
	x->b = temp;
}

void dice_rorate_e(dice *x)
{
	int temp;
	temp = x->e;
	x->e = x->t;
	x->t = x->w;
	x->w = x->b;
	x->b = temp;
}

void dice_rorate_r(dice *x)
{
	int temp;
	temp = x->n;
	x->n = x->w;
	x->w = x->s;
	x->s = x->e;
	x->e = temp;
}

void dice_normalize(dice *x, int t, int s)
{
	for(int i = 0; i < 3; ++i)
	{
		if(t == x->t) { break; }
		dice_rorate_e(x);
	}
	for(int i = 0; i < 3; ++i)
	{
		if(t == x->t) { break; }
		dice_rorate_n(x);
	}
	for(int i = 0; i < 3; ++i)
	{
		if(s == x->s) { break; }
		dice_rorate_r(x);
	}
}

int main()
{
	dice d;
	int q, t, s;

	dice_scan(&d);
	scanf("%d", &q);

	for(int i = 0; i < q; ++i)
	{
		scanf("%d %d", &t, &s);
		dice_normalize(&d, t, s);
		printf("%d\n", d.e);
	}

	return 0;
}


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

#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size();
using ll = long long;
const int N = 1e5;

int n, m;
vector<int> conn[N];
bitset<N> valid;

int out[N], cnt[N], parent[N];

queue<int> q;

void search() {
	queue<int> nxt;
	vector<bool> used(N, false);
		
	int found = 0;
	while (found != n) {
		while (!q.empty()) {
			int v = q.front();
			q.pop();
			++found;
			used[v] = true;
			
			for (int u : conn[v]) {
				if (used[u]) continue;
				++cnt[u];
				if (cnt[u] == out[u]) {
					nxt.push(u);
				}
			}
		}
		
		while (!nxt.empty()) {
			int v = nxt.front();
			nxt.pop();
			q.push(v);
			for (int u : conn[v]) {
				if (used[u] && !parent[u]) {
					parent[u] = v;
				}
			}
		}
	}
}


int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	valid.set();
	cin >> n >> m;
	for (int i = 0; i < n - 1 + m; ++i) {
		int a, b;
		cin >> a >> b;
		conn[a].push_back(b);
		conn[b].push_back(a);
		++out[a];
		valid[a] = 0;
	}
	
	for (int i = 1; i <= n; ++i) {
		if (valid[i]) {
			q.push(i);
		}
	}
	
	search();
	for (int i = 1; i <= n; ++i) {
		cout << parent[i] << '\n';
	}
}


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

int main() {
  long long n;
  long long d;
  cin >> n >> d;
  long long D=d*d;
  int ans=0;
  
  vector<long long> x(n);
  vector<long long> y(n);
  vector<long long> z(n);
  for (int i = 0; i < n; i++) {
    cin >> x.at(i);
    cin >> y.at(i);
    z.at(i) = (x.at(i)*x.at(i)) + (y.at(i)*y.at(i));
    if(D >= z.at(i)){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 7988
#include<stdio.h>

int main(void){
    int n, R, min = 1000000000, max = -1000000000;
    
    scanf("%d",&n);
    scanf("%d",&R);
    min = R;
    for(int i = 0; i < n - 1;i++)
    {
        scanf("%d",&R);
        if(max < R - min)
        {
            max = R - min;
        }
        if(min > R)
        {
            min = R;
        }
        
    }
    
    printf("%d\n", max);
    return 0;
}



Measured memory_bytes: 1988