akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <stack>
#include <vector>
#include <utility>
using namespace std;
int main()
{
    stack<int> S;
    vector<pair<int, int> > L;
    char c;
    int x = 0;
    int A = 0;

    while (scanf("%c", &c) != EOF)
    {

        if (c == '\\')
        {
            S.push(x);
        }
        else if (c == '/')
        {
            if (!S.empty())
            {
                A = 0;
                for (int i = L.size() - 1; i >= 0; i--)
                {
                    if (L[i].first >= S.top())
                    {
                        A += L[i].second;
                        L.pop_back();
                    }
                    else
                        break;
                }
                A += x - S.top();
                L.push_back(make_pair(S.top(), A));
                S.pop();
            }
        }
        x++;
    }
    A = 0;
    for (int i = 0; i < L.size(); i++)
    {
        A += L[i].second;
    }

    printf("%d\n%d", A, L.size());

    for (int i = 0; i < L.size(); i++)
    {
        printf(" %d", L[i].second);
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n, a, x = 0, y = 0;
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    scanf("%d", &a);
    x += a*a;
    y += a;
  }
  printf("%d\n", x + (n*(y/n + (y%n > n/2)) - 2*y)*(y/n + (y%n > n/2)));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define pii pair<int, int>
#define forr(i,a,n) for (int i = (a); i < (n); ++i)
#define rforr(i,a,n) for (int i = (a); i > (n); --i)
#define ALL(x) x.begin(),x.end()
#define LEN(X) ((int)(X).size())
#define CASET int _T; cin >> _T; forr(caset,0,_T)
//#define int ll
 
int h,w; 
int grid[100][100];
int moves[100][100];
bool vis[100][100] = {};
 
int minMoves(int r, int c) {
    if (r<0 || c<0) return INT_MAX - 10;
    if (vis[r][c]) return moves[r][c];
    int a = minMoves(r-1, c);
    int b = minMoves(r, c-1);
    if (grid[r][c]==1) {
        if (r>0 && grid[r-1][c]==0) a++; 
        if (c>0 && grid[r][c-1]==0) b++;
    } 
    moves[r][c] = min(a,b);
    vis[r][c] = true;
    return moves[r][c];
}
 
int main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    //freopen("input.txt","r",stdin);
    cin >> h >> w;
    forr(i,0,h) forr(j,0,w) {
        char c; cin >> c;
        grid[i][j] = (c=='#') ? 1 : 0;
    }
    moves[0][0] = (grid[0][0] == 1) ? 1 : 0;
    vis[0][0] = true;
 
    cout << minMoves(h-1,w-1) << '\n';
 
    return 0;
}

Measured memory_bytes: 384
import itertools
import math

N = int(input())
P = []

for _ in range(N):
    P.append(list(map(int, input().split())))

lists = itertools.permutations(range(N))

ans = 0
for l in lists:
    for i, x in enumerate(l):
        
        if i == 0:
            pre = P[x]
            continue

        temp = (P[x][0] - pre[0])**2 + (P[x][1] - pre[1])**2
        ans += math.sqrt(temp)
        pre = P[x]

print(ans / math.factorial(N))

Measured memory_bytes: 41196
#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
typedef long long ll;
typedef long l;
typedef long long unsigned ull;



int main(){
    string s,revs;
    cin>>s;
    int pos_start = (s.length()-1)/2;
    int pos_end = (s.length()+3)/2;
    int n = s.length();
    string a,b,c,d;
    for(int i=0,j=pos_start-1;i<pos_start,j>=0;i++,j--){
        a += s[i];
        b += s[j];
    }


    for(int i=pos_end-1,j=n-1;i<n,j>=pos_end-1;i++,j--){
        c += s[i];
        d += s[j];
    }
    for(int i=n-1;i>=0;i--){
        revs += s[i];
    }
    if(a == b && c == d && s == revs){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }

    return 0;

}


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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	ll int w,h;
	vector<pair<ll int,bool> > pq;
	cin >> w >> h;
	REP(i,w){
		ll int t;
		cin >> t;
		pq.pb(mp(t,true));
	}
	REP(i,h){
		ll int t;
		cin >> t;
		pq.pb(mp(t,false));
	}
	sort(All(pq));
	ll int sum = 0;
	
	ll int tsum,fsum;
	tsum = 0; fsum = 0;
	for(ll int i = pq.size()-1; i >= 0; i--){
		// cout << pq[i].first << " " << pq[i].second << " " << fsum << " " << tsum << endl;
		if(pq[i].second == true) tsum++;
		else fsum++;
		if(pq[i].second == true){
			sum += pq[i].first * (fsum + 1);
		}else{
			sum += pq[i].first * (tsum + 1);
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 4464
#include<cstdio>
#define N 21
#define mod 1000000007
int n;
int id;
int a[N][N];
int dp[N][1<<N];
int vis[N][1<<N];
int DP(int i,int j){
	if(!~i)return !j;
	if(vis[i][j])return dp[i][j];
	vis[i][j]=1;
	dp[i][j]=0;
	for(int k=0;k<n;++k)if(j>>k&1){
		if(a[i][k])dp[i][j]+=DP(i-1,j^(1<<k));
		if(dp[i][j]>=mod)dp[i][j]-=mod;
	}
	return dp[i][j];
}
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;++i)for(int j=0;j<n;++j)scanf("%d",&a[i][j]);
	id=(1<<n);
	printf("%d\n",DP(n-1,id-1));
	return 0;
}

Measured memory_bytes: 321792
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
int main()
{
    std::string S;
    std::cin >> S;
    int ans = 0;
    int count0 = 0, count1 = 0;
    for (int i = 0; i < S.size(); ++i)
    {
        if (i % 2 == 0)
        {
            if (S[i] == '0')
            {
                ++count1;
            }
            else
            {
                ++count0;
            }
        }
        else
        {
            if (S[i] == '0')
            {
                ++count0;
            }
            else
            {
                ++count1;
            }
            
        }
        
    }
    ans = std::min(count0, count1);
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 512
def main():
    import sys
    input = sys.stdin.readline
    from bisect import bisect_left, insort_left
    N = int(input())
    S = list(input())
    Q = int(input())
    dic = {chr(i): [] for i in range(ord('a'), ord('z')+1)}
    for i in range(N):
        dic[S[i]].append(i)
    for _ in range(Q):
        query, a, c = input().split()
        if query == "1":
            i = int(a)-1
            if S[i] == c:
                continue
            ind = bisect_left(dic[S[i]], i)
            dic[S[i]].pop(ind)
            insort_left(dic[c], i)
            S[i] = c
        else:
            l, r = int(a)-1, int(c)-1
            ans = 0
            for inds in dic.values():
                if inds and l <= inds[-1] and inds[bisect_left(inds, l)] <= r:
                    ans += 1
            print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 29320
package main

import "fmt"

func ceil(i int) int {
	rem := i % 10
	if rem == 0 {
		return i
	}
	return i + 10 - rem
}

func main() {
	a := make([]int, 5)
	for i := 0; i < 5; i++ {
		fmt.Scan(&a[i])
	}

	var sum int
	ceils := make([]int, 5)
	for i, v := range a {
		ceiled := ceil(v)
		ceils[i] = ceiled
		sum += ceiled
	}
	var maxSave int
	for i := 0; i < 5; i++ {
		save := ceils[i] - a[i]
		if save > maxSave {
			maxSave = save
		}
	}

	fmt.Println(sum - maxSave)
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


/*

*/

ll n,h[100010],c=0,ans=0;

int main(void){
	cin>>n;
	rep(i,n)cin>>h[i];
	rep(i,n){
		ans+=max(h[i]-c,(ll)0);
		c=h[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
using namespace std;
#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define INF 100000000
#define _INF -100000000
#define INFLL (long long)1e14
#define _INFLL (long long)-1e14
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
struct dat { double x, y, arg; };

class SCC {
public:
	int n;
	vvi G;
	vvi rG;
	vi visited;
	stack<int> order;
public:
	vvi ret;
	SCC(vvi A) {
		G = A;
		n = G.size();
		rG.resize(n);
		Loop(i, n) {
			Loop(j, G[i].size()) {
				rG[G[i][j]].push_back(i);
			}
		}
		visited.resize(n);
		fill(visited.begin(), visited.end(), 0);
		mainf();
	}
	void dfs(int a) {
		visited[a] = 1;
		Loop(j, G[a].size()) {
			if (visited[G[a][j]]) continue;
			dfs(G[a][j]);
		}
		order.push(a);
	}
	void rdfs(int a) {
		visited[a] = 1;
		Loop(j, rG[a].size()) {
			if (visited[rG[a][j]]) continue;
			rdfs(rG[a][j]);
		}
		ret.back().push_back(a);
	}
	void mainf() {
		Loop(i, n) {
			if (visited[i]) continue;
			dfs(i);
		}
		fill(visited.begin(), visited.end(), 0);
		while (order.size()) {
			int focus = order.top(); order.pop();
			if (visited[focus]) continue;
			ret.push_back({});
			rdfs(focus);
		}
	}
};

class Union_Find_Tree {
private:
	vi p, r;
public:
	Union_Find_Tree(int N) {
		p.resize(N);
		r.resize(N);
		Loop(i, N) {
			p[i] = i;
			r[i] = 0;
		}
	}
	int find(int x) {
		if (p[x] == x) return x;
		else return p[x] = find(p[x]);
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (r[x] < r[y]) p[x] = y;
		else {
			p[y] = x;
			if (r[x] == r[y]) r[x]++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};


int main() {
	int n, m; cin >> n >> m;
	vvi G(n);
	Loop(i, m) {
		int s, t;
		cin >> s >> t;
		G[s].push_back(t);
	}
	SCC scc(G);
	Union_Find_Tree uf(n);
	Loop(i, scc.ret.size()) {
		Loop(j, scc.ret[i].size()) {
			uf.unite(scc.ret[i][j], scc.ret[i][0]);
		}
	}
	int q; cin >> q;
	Loop(i, q) {
		int s, t;
		cin >> s >> t;
		cout << uf.same(s, t) << endl;
	}
	return 0;
}

Measured memory_bytes: 5548
#include <stdio.h>

#define PRIME_MAX 1000000
char tmp[PRIME_MAX];
int getprimes(int list[], int top){
	int i, j;
	int index = 0;

	for(i=0;i<top;i++) {
		tmp[i] = 1;
	}
	
	tmp[0] = tmp[1] = 0;
	for(i=2;i<top;i++) {
		if(tmp[i] == 1) {
			/* 素数 */
			list[index] = i;
			index ++;
			for(j=2;j*i<top;j++) {
				tmp[j*i] = 0;
			}
		}
	}

	list[index] = -1;
	return index;
}

int primes[100000];

int main(void) {
	int i, c;
	int n;
	int size;
	size = getprimes(primes, PRIME_MAX);
	
	while(scanf("%d\n", &n) == 1) {
		c = 0;
		for(i=0;i<size;i++) {
			if(primes[i] > n) break;

			c++;
		}
		printf("%d\n", c);
	}
	
	return 0;
}

Measured memory_bytes: 1880
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll N, K;
	cin >> N >> K;
	ll res = 0;
	for (ll k = K; k <= N+1; ++ k) {
		ll x = (k-1)*k/2;
		ll y = x + k*(N-k+1);
		(res += y-x+1) %= 1000000007;
	}
	cout << res << endl;
}


Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		// 整数の入力
		int a = sc.nextInt();

		if (a == 0) {
			System.out.println(1);
		} else if (a == 1) {
			System.out.println(0);
		}
	}
}

Measured memory_bytes: 35600
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String S = sc.next();
		long K = sc.nextLong();

		long cnt = 1;
		for (int i = 0; i < S.length(); i++) {
			char c = S.charAt(i);
			if (c != '1') {
				if (K < cnt) {
					System.out.println(1);
				}else {
					System.out.println(c);
				}
				return;
			}
			cnt++;
		}
		System.out.println(1);
	}
}


Measured memory_bytes: 22728
/*
    Ujjawal Pabreja
*/
#include <bits/stdc++.h> 
#include <functional> 
using namespace std;
using ll = long long;
using ld = long double;
#define speed_cubing    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i,a)        for(ll i = 0 ; i < a ; i++)
#define repe(i,a,b)     for(ll i = a ; i < b ; i++)
#define bac(i,a)        for(ll i = a ; i >= 0 ; i--)
#define bace(i,a,b)     for(ll i = a ; i >= b ; i--)
#define pb              push_back
#define mp              make_pair
#define in              insert
#define ff              first
#define ss              second
#define vv              vector
#define vll             vector <ll>
#define pll             pair <ll,ll>
#define vpll            vector <pll>
#define umap            unordered_map
#define uset            unordered_set
#define mset            multiset
#define pqueue          priority_queue
#define setbit(x)       __builtin_popcountll(x)
#define init(c,a)       memset(c,a,sizeof(c))
#define all(c)          c.begin(),c.end()
#define sz(c)           (ll)c.size()
#define lb              lower_bound
#define ub              upper_bound
#define maxe            *max_element
#define mine            *min_element
#define gcd(a,b)        __gcd(a,b)
#define rev             reverse
#define Y				"YES"
#define N 				"NO"
#define nl              "\n"
#define debug(x)        cout << #x << " : " << x << nl;
const ll inf = 1e18;  
const ll mod = 1e9 + 7;
const ll MOD = 998244353;
const ll MAX = 2e5 + 1;

// ====== int_1024t begins ======
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// ====== int_1024t ends ======

// ====== pbds begins ======
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, 
//         tree_order_statistics_node_update> 
//         pbds; 
// ====== pbds ends ======

// ====== Useful functions begin ======
inline ll add(ll a,ll b) {return ((a%mod)+(b%mod))%mod;}
inline ll sub(ll a,ll b) {return ((a%mod)-(b%mod)+mod)%mod;}
inline ll mul(ll a,ll b) {return ((a%mod)*(b%mod))%mod;}
ll pwr(ll x,ll n){
    if(!n) return 1;
    if(n&1) return mul(x, pwr(mul(x,x),(n-1)/2));
    else return pwr(mul(x,x),n/2);
}
ll modinv(ll n){ 
    return pwr(n,mod - 2); 
}
// ====== Useful functions end ======
 
// ====== Variables begin ======

// ====== Variables end ======
void speed_solve(){
    ll a, b, c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b;
}
int main()
{
    speed_cubing;
    ll test_cases = 1;
    // cin >> test_cases;
    rep(i,test_cases){
        // cout << "Case #" << i + 1 << ": ";
        speed_solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define sz 3005
using namespace std;
double a[sz];
double dp[sz][sz];
int main(){
    //freopen("test.txt","r",stdin);
    int i  , j , n , m;
    double sum = 0.0 , x;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    dp[1][1] = 1.0-a[0];dp[1][2] = a[0];
    for(i=2;i<=n;i++){
        for(j=1;j<=i+1;j++){
            dp[i][j] = (1.0-a[i-1]) * dp[i-1][j] + a[i-1]*dp[i-1][j-1];
        }
    }
    for(i=n/2+2;i<=n+1;i++)
        sum += dp[n][i];
    printf("%0.9lf\n",sum);
    return 0;
}


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

using namespace std;

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



int main() {
    int N, M;
    cin >> N >> M;
    vector<int> k(M);
    vector<vector<int>> s(M);
    vector<int> p(M);

    rep(i, M) {
        cin >> k[i];
        s[i].resize(k[i]);
        rep(j, k[i]) cin >> s[i][j];
        rep(j, k[i]) s[i][j]--;
    }

    rep(i, M) cin >> p[i];

    int ans = 0;
    rep(S, 1 << N) {
        vector<int> cnt(M);
        rep(i, M) {
            rep(j, k[i]) {
                if (S >> s[i][j] & 1) cnt[i]++;
            }
        }
        
        bool ok = true;
        rep(i, M) ok &= cnt[i] % 2 == p[i];
        if (ok) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<functional>
#include<stack>
#include<queue>
#include<cmath>
# define MOD 1000000000+7
# define INF 1e9
# define LINF 1e18
typedef long long ll;

using namespace std;
int gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
 

bool broken[100000] = {false};
int dp[100010] = {};

int unko[200000] = {}, geri[200000] = {};

int main() {
/*
	int n = 0, m = 0;
	cin >> n >> m;

	for (int i = 0; i < m; i++) {
		int temp;
		cin >> temp;
		broken[temp] = true;
	}

	dp[0] = 1;

	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j <= min(i + 2, n); j++) {

			if (broken[j] == false) {
				dp[j] += dp[i];
				dp[j] %= MOD;
			}

		}
	}

	cout << dp[n] << endl;

	return 0;
	*/


	int n = 0,nibante = 0,top_of_the_world;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> unko[i];
		geri[i] = unko[i];
	}
	sort(unko, unko + n);

	nibante = unko[n - 2];
	top_of_the_world = unko[n - 1];

	for (int i = 0; i < n; i++) {

		if (geri[i] != top_of_the_world) {
			if (i == n - 1) {
				cout << top_of_the_world;
			}
			else {
				cout << top_of_the_world << endl;
			}
		}
		else {
			if (i == n - 1) {
				cout << nibante;
			}
			else {
				cout << nibante << endl;
			}
		}

	}

}

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

int main(){
    int N,T;cin>>N>>T;
//    vector<int> c(N);
 //   vector<int> t(N);
    int ans=INT_MAX,c,t;
    for(int i=0;i<N;i++){
        cin>>c>>t;
        if(t<=T)ans=min(ans,c);
    }
    if(ans<INT_MAX)
    cout<<ans<<endl;
    else cout<<"TLE"<<endl;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n = INT()
    p = LIST()
    q = LIST()
    li = list(permutations(range(1, n+1)))
    print(abs(li.index(tuple(p))-li.index(tuple(q))))

if __name__=='__main__':
    main()

Measured memory_bytes: 9816
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()

int main() {
  //
  int n, m;
  cin >> n >> m;
  set<int> from1, ton;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    if (a == 1) {
      if (ton.find(b) != ton.end()) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
      from1.insert(b);
    } else if (b == n) {
      if (from1.find(a) != from1.end()) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
      ton.insert(a);
      ;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}


Measured memory_bytes: 9600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC115A
{
    class Program
    {
        static void Main(string[] args)
        {
            int D;
            D = int.Parse(Console.ReadLine());
            Console.Write("Christmas ");

            for (int i = 0; i < 25 - D; i++) 
            {
                Console.Write("Eve ");
            }
            
            Console.ReadKey();

        }
    }
}


Measured memory_bytes: 13140
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        a: chars,
    }
    puts!("{}\n", (a[0] as u8 + 1) as char);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

struct Edge{
    int to, cost;
    bool used = false;
};
vector<Edge> vec[100010];
constexpr int INF = 1 << 29;

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

    vector<int64_t> cntL(N);
    vector<int64_t> cntR(N);
    for(int i = 0; i < M; ++i){
        int L, R, D;
        cin >> L >> R >> D;
        --L, --R;
        vec[L].push_back(Edge{R, D});
        //vec[R].push_back(Edge{L, -D});
        cntL[L]++;
        cntR[R]++;
    }
    queue<int> que;
    for(int i = 0; i < N; ++i){
        if(cntL[i] > 0 && cntR[i] == 0){
            que.push(i);
        }
    }
    if(M == 0){
        cout << "Yes" << endl;
        return 0;
    }
    if(que.empty()){
        cout << "No" << endl;
        return 0;
    }
    
    vector<int64_t> d(N);
    for(int i = 0; i < N; ++i){
        d[i] = INF;
    }
    d[que.front()] = 0;

    bool check = true;
    while(!que.empty()){
        int q = que.front();
        que.pop();
        bool flag = false;
        for(auto c : vec[q]){
            if(!c.used){
                if(d[c.to] == INF){
                    d[c.to] = d[q] + c.cost;
                    que.push(c.to);
                }
                else if(d[c.to] != d[q] + c.cost){
                    check = false;
                    break;
                }
                c.used = true;
                if(d[q] == INF){
                    if(d[c.to] != INF){
                        d[q] = d[c.to] - c.cost;
                    }
                    else {
                        c.used = false;
                        flag = true;
                    }
                }
            }
        }
        if(flag){
            for(auto c : vec[q]){
                if(!c.used){
                    if(d[c.to] == INF){
                        d[c.to] = d[q] + c.cost;
                        que.push(c.to);
                    }
                    else if(d[c.to] != d[q] + c.cost){
                        check = false;
                        break;
                    }
                    c.used = true;
                }
            }
        }
    }
    cout << (check ? "Yes" : "No") << endl;
}

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

int main(){
    bool flag = false;
    string code;
    cin >> code;
    for(int i = 0;i < 3;i++){
        if(code[i] == code[i+1]){
            flag = true;
            break;
        } 
    } 
    if(flag) cout << "Bad" << endl;
    else cout << "Good" << endl;

    return 0;
}

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

a = [0] * n
c = b[0]
a[0] = b[0]
for i,data in enumerate(b):
  if b[i] >= c:
    a[i+1] = b[i]
  else :
    a[i],a[i+1] = b[i],b[i]
  c = b[i]

print(sum(a))


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>

#define rep(i,n) for(ll i=0;i<(n);i++)
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
	if (b == 0)return a;

	return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

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

	double ans = r * 2 * 3.14;
	printf("%.10f\n", ans);

	return 0;
}


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

int main() {
  int lake, N;
  cin >> lake >> N;
  
  vector<int> house(N);
  for (int i = 0; i < N; i++) {
    cin >> house.at(i);
  }
  
  int diff = 0;
  int cache = 0;
  
  for(int i = 0; i < N-1; i++){
    cache=house.at(i+1)-house.at(i);
    if(cache>diff){
      diff = cache;
    }
  }
  
  cache = house.at(0)+lake-house.at(N-1);
  if(cache>diff){
      diff = cache;
  }
  
  cout << lake-diff << endl;
    
}


Measured memory_bytes: 1024
/*************************************************************************
	> File Name: 49a.cpp
	> Author: SIU
	> Created Time: 2016年12月10日 星期六 20时04分16秒
 ************************************************************************/

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    char a;
    scanf("%c",&a);
    if(a=='a'||a=='i'||a=='e'||a=='o'||a=='u'||a=='A'||a=='E'||a=='I'||a=='O'||a=='U')
    printf("vowel\n");
else 
    printf("consonant\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int n,ans=INT_MAX;
int num(int x){
	int s=0;
	while (x){
		s+=x%10;
		x/=10;
	}
	return s;
}
int main(){
	cin>>n;
	for (int i=1;i<n;i++){
		int j=n-i;
		ans=min(num(i)+num(j),ans);
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    int a[m],b[m];
    pair<int,int> p[m];
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i];
        p[i]={b[i],a[i]};
    }
    sort(p,p+m);
    int ans=1,x=p[0].first;
    for(int i=1;i<m;i++){
        if(p[i].second>=x){
            ans++;
            x=p[i].first;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define memset(v, h) memset((v), h, sizeof(v))
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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

int main(){
    ll n1, n2;
    cin >> n1;
    cin >> n2;

    if(n1 == 1)
    {
        n2 = n2 == 2 ? 3 : 2;
    }

    if(n1 == 2)
    {
        n2 = n2 == 1 ? 3 : 1;
    }

    if(n1 == 3)
    {
        n2 = n2 == 2 ? 1 : 2;
    }


    cout << n2 << endl;
    return 0;
}

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

int H, W;
int white_num = 0;
vector<vector<char>> maze(H, vector<char>(W));
vector<vector<int>> dist(H, vector<int>(W, -1));

void input()
{
    cin >> H >> W;
    maze = vector<vector<char>> (H, vector<char>(W));
    dist = vector<vector<int>> (H, vector<int>(W, -1));
    for (int i=0; i<H; i++)
    {
        string row;
        cin >> row;
        for (int j=0; j<W; j++)
        {
            maze[i][j] = row[j];
            if (row[j]=='.') white_num++;
        }
    }
}

void solve()
{
    auto check = [](int h, int w)
    {
        if (h>=0 && h<H && w>=0 && w<W && maze[h][w]=='.' && dist[h][w]==-1) return true;
        else return false;
    };

    int dh[4] = {1, -1, 0, 0};
    int dw[4] = {0, 0, 1, -1};

    queue<pair<int, int>> que;
    pair<int, int> start={0, 0};
    dist[0][0] = 1;
    que.push(start);

    while(!que.empty())
    {
        pair<int, int> v = que.front();
        que.pop();
        for (int i=0; i<4; i++)
        {
            pair<int, int> next;
            next.first = v.first + dh[i];
            next.second = v.second + dw[i];
            if (check(next.first, next.second))
            {
                que.push(next);
                dist[next.first][next.second] = dist[v.first][v.second]+1;
            }
        }
    }
    int ans;
    if (dist[H-1][W-1]!=-1) ans = white_num - dist[H-1][W-1];
    else ans = -1;
    cout << ans << endl;

    //デバッグ用
    /*
    for (int i=0; i<H; i++)
    {
        for (int j=0; j<W; j++)
        {
            cout << dist[i][j] << " ";
        }
        cout << endl;
    }
    */
}

int main()
{
    input();
    solve();
}

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

using namespace std;

int main() {
    int h, n;
    scanf("%d %d", &h, &n);

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

    if (a >= h) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define int long
using namespace std;
int n,a[1<<17];
main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	int l=2,r=2;
	for(int i=n-1;i>=0;i--)
	{
		if((l+a[i]-1)/a[i]*a[i]>r)
		{
			cout<<-1<<endl;
			return 0;
		}
		l=(l+a[i]-1)/a[i]*a[i];
		r=r/a[i]*a[i]+a[i]-1;
	}
	cout<<l<<" "<<r<<endl;
}


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

int main(){

  int a,b,c=0;

  while(true){
    
    cin>>a>>b;
    if(a==0&&b==0) break;
    if(c!=0)cout<<endl;


    vector<int> leaps;

    if(a%4!=0)
      a = 4 - a%4 + a;

    for(int i=a;i<=b;i+=4){
      if(i%400==0){
        cout<<i<<endl;
        leaps.emplace_back(i);
      }else if(i%100==0){
        continue;
      }else{
        cout<<i<<endl;
        leaps.emplace_back(i);
      }
    }

next : 

    if(leaps.size()==0) cout<<"NA"<<endl;
    ++c;

  }

  return EXIT_SUCCESS;
}

Measured memory_bytes: 1228
#include <iostream>
#include <vector>
#include <set>
using namespace std;
static const int MOD = 1000000007;

int main() {
    int N, M; cin >> N >> M;
    vector<int> dp = {0, 1};
    set<int> S;
    for (int i = 0; i < M; i++) {
        int a; cin >> a;
        S.insert(a);
    }

    for (int i = 1; i <= N; i++) {
        if (S.find(i) != S.end()) {
            dp.push_back(0);
            continue;
        }
        dp.push_back((dp[i-1] + dp[i]) % MOD);
    }

    cout << dp[N + 1] << endl;

    return 0;
}


Measured memory_bytes: 5628
import os,re
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate,combinations
from sys import stdin,setrecursionlimit
from copy import deepcopy
setrecursionlimit(10**6)

a,b,c=map(int,input().split())
now1=max(0,a-b)
print(max(0,c-now1))

Measured memory_bytes: 3956
#include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
#define N 8
using namespace std;
int row[N];
bool col[N],dpos[2*N-1],dneg[2*N-1];

void printBoard(){
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(j==row[i])printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}
void putqueen(int i){
  if(i == N){
    printBoard();
    return;
  }
  if (row[i]!=-1){
      putqueen(i+1);
  }
  else {
    for(int j=0;j<N;j++){
      if(col[j]||dpos[i+j]||dneg[i-j+N-1])continue;
      row[i]=j;
      col[j]=dpos[i+j]=dneg[i-j+N-1]= true;
      putqueen(i+1);
      row[i]=-1;
      col[j]=dpos[i+j]=dneg[i-j+N-1]= false;
    }
  }
}

int main(){
  int n,x,y;
  cin>>n;
  for(int i=0;i<N;i++)row[i]=-1;
  for(int i=0;i<n;i++){
    cin>>x>>y;
    row[x]=y;
    col[y]=dpos[x+y]=dneg[x-y+N-1]=true;
  }
  putqueen(0);

  return 0;
}



Measured memory_bytes: 3100
def main():
    
    N = int(input())

    POW6 = []
    POW9 = []
    for i in range(7):
        POW6.append(6**i)
        
    for i in range(6):
        POW9.append(9**i)
        
    
    dp = [N]*(N+1)
    dp[0] = 0
    for i in range(1, N+1):
        cnt = 0
        while i-POW6[cnt] >= 0:
            dp[i] = min(dp[i], dp[i-POW6[cnt]]+1)
            cnt += 1
            if cnt == len(POW6):
                break
        cnt = 0
        while i-POW9[cnt] >= 0:
            dp[i] = min(dp[i], dp[i-POW9[cnt]]+1)
            cnt += 1
            if cnt == len(POW9):
                break

    
    print(dp[N])
    
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 3828
import sys
sys.setrecursionlimit(100010)

def main():
    def input():
        return sys.stdin.readline()[:-1]

    N, M = map(int,input().split())

    p = list(map(lambda x: int(x)-1, input().split()))
    parent = [k for k in range(N)]

    def find(x):
        if parent[x] == x:
            return x
        else:
            parent[x] = find(parent[x])
            return find(parent[x])

    def unite(x,y):
        parent[find(x)] = find(y)

    for k in range(M):
        x, y = map(int,input().split())
        unite(x-1,y-1)

    ans = 0
    for k in range(N):
        if find(k) == find(p[k]):
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14008
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    string s;
    cin >> s;

    int n = s.size();
    int rnum = 1, lnum = 0;
    int pos;
    int i = 0;
    int l, r;

    vs32 ans(n, 0);
    while (i < n)
    {
        l = i;
        while (i < n && s[i] == 'R') { ++rnum; ++i; }
        int pos = i;
        while (i < n && s[i] == 'L') { ++lnum; ++i; }
        r = i;
        ans[pos - 1] = (r - pos) / 2 + (pos - l - 1) / 2 + 1;
        if (pos < n) ans[pos] = (r - pos - 1) / 2 + (pos - l) / 2 + 1;
    }

    rep (i, n)
    {
        if (i > 0) cout << " ";
        cout << ans[i];
    }
    cout << "\n";
    return 0;
}



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

int main(void){
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    if(s[0]==s[1] && s[1] != s[2] && s[2] == s[3]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
using System;

namespace A___Takahashi_Calendar
{
    class Program
    {
        static void Main(string[] args)
        {
            var MD = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var count = 0;
            for (int m = 1; m <= MD[0]; m++)
            {
                for (int d = 22; d <= MD[1]; d++)
                {
                    var d1 = d % 10;
                    var d10 = d / 10;
                    if (d1 >= 2 && d10 >= 2 && d1 * d10 == m) count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<ll> a(n);
    ll cnt_neg = 0;
    ll sm = 0;
    ll mn = 1001001001;
    rep(i, n){
        cin >> a[i];
        if(a[i] < 0) ++cnt_neg;

        sm += abs(a[i]);
        mn = min(mn, abs(a[i]));
    }

    if(cnt_neg % 2 == 0) cout << sm << endl;
    else cout << sm - mn*2 << endl;
    
    return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for(ll i = n-1; i >= 0LL; i--)
#define FOR(i, n, m) for(ll i = n; i < (ll)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()
#define INF (ll)1e18
#define INFD 1e18
#define PI 3.14159265358979
#define MOD 1000000007
#define vl vector<ll>

vector<ll> dx = {-1, 1, 0, 0};
vector<ll> dy = {0, 0, 1, -1};

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


// union by size + path having
class UnionFind {
public:
		vector <ll> par; // 各元の親を表す配列
		vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

		// Constructor
		UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
				for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
		}
		void init(ll sz_) {
				par.resize(sz_);
				siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
				for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
		}

		// Member Function
		// Find
		ll root(ll x) { // 根の検索
				while (par[x] != x) {
						x = par[x] = par[par[x]]; // x の親の親を x の親とする
				}
				return x;
		}

		// Union(Unite, Merge)
		bool merge(ll x, ll y) {
				x = root(x);
				y = root(y);
				if (x == y) return false;
				// merge technique（データ構造をマージするテク．小を大にくっつける）
				if (siz[x] < siz[y]) swap(x, y);
				siz[x] += siz[y];
				par[y] = x;
				return true;
		}

		bool issame(ll x, ll y) { // 連結判定
				return root(x) == root(y);
		}

		ll size(ll x) { // 素集合のサイズ
				return siz[root(x)];
		}
};

int main()
{
	ll N, M;
	cin >> N >> M;
	UnionFind uf(N);
	REP(i, M) {
		ll X, Y, Z;
		cin >> X >> Y >> Z;
		X--; Y--;
		uf.merge(X, Y);
	}
	set<ll> se;
	REP(i, N) {
		se.insert(uf.root(i));
	}
	PRINT(se.size());
	return 0;
}




Measured memory_bytes: 6528
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
count = 0
for i in range(n):
  if a[i] >= b[i]:
    count += b[i]
  else:
    count += min(b[i], a[i]+a[i+1])
    a[i+1] = max(0, a[i+1]-(b[i]-a[i]))
print(count)


Measured memory_bytes: 18624
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N, P;
  cin >> N >> P;
  if(N == 1){
    cout << P << endl;
    return 0;
  } else if (N >= 64) {
    cout << 1 << endl;
    return 0;
  }
  long ans = 1;
  vector<long> data((long)(sqrt(P) + 1));
  for(long i = 2; i <= sqrt(P); i++){
    while(P % i == 0){
      data.at(i)++;
      P /= i;
    }
    if(data.at(i) >= N)ans *= pow(i, data.at(i) / N);
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
	string s, t;
	cin >> s >> t;
	int lens = s.size(), lent = t.size();
	int ans = 0;
	for(int i = 0; i + lent <= lens; i++){
		int mt = 0;
		for(int j = 0; j < lent; j++){
			if(s[i + j] == t[j])
				mt++;
		}
		if(mt > ans)
			ans = mt;
	}
	cout << lent - ans << endl;
	return 0;
}

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

using namespace std;

int oo = 0x3f3f3f3f;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)

int dist[400][400];

void floyd(int n) {
    FOR(k,0,n) FOR(i,0,n) FOR(j,0,n)
        if (dist[i][k] < oo && dist[k][j] < oo && dist[i][k]+dist[k][j] < dist[i][j])
            dist[i][j] = max(dist[i][k]+dist[k][j], -oo);
}

int main() {
    vector<vector<int>> dirs = {{1,0}, {-1,0}, {0,1}, {0,-1}};

    int h, w;
    cin >> h >> w;

    for (int i = 0; i < 400; i++) {
        for (int j = 0; j < 400; j++) {
            if (i == j) dist[i][j] = 0;
            else dist[i][j] = oo;
        }
    }

    vector<vector<bool>> s = vector<vector<bool>>(h, vector<bool>(w, false));
    string si;
    vector<vector<int>> node_num = vector<vector<int>>(h, vector<int>(w, -1));
    int node_count = 0;
    for (int i = 0; i < h; i++) {
        cin >> si;
        for (int j = 0; j < w; j++) {
            if (si[j] == '.') {
                node_num[i][j] = node_count;
                node_count++;
                s[i][j] = true;
            }
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (!s[i][j]) continue;
            for (int k = 0; k < 4; k++) {
                vector<int> dir = dirs[k];
                if (i+dir[0] >= 0 && i+dir[0] < h && j+dir[1] >= 0 && j+dir[1] < w) {
                    if (s[i+dir[0]][j+dir[1]]) {
                        dist[node_num[i][j]][node_num[i+dir[0]][j+dir[1]]] = 1;
                    }
                }
            }
        }
    }

    floyd(node_count);

    int max_dist = -1;
    FOR(i,0,400) FOR(j,0,400) {
        if (dist[i][j] != oo) max_dist = max(max_dist, dist[i][j]);
    }

    cout << max_dist << endl;

    return 0;
}


Measured memory_bytes: 896
il = lambda: list(map(int, input().split()))
ils = lambda n, s="int(input())": [eval(s) for _ in range(n)]

n, m, x, y = il()
xs = il()
ys = il()
a = max(xs)
b = min(ys)
if x < a and b <= y and a < b:
    print("No War")
else:
    print("War")

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

typedef unsigned long long ull;

struct Shop {
  ull price, num;
  bool operator <(const Shop &another) const {
    return price < another.price;
  }
};

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

  Shop A[100100];
  for (int i = 0; i < N; ++i) {
    cin >> A[i].price >> A[i].num;
  }

  sort(A, A+N);

  ull ans = 0;
  int i = 0;
  int num = M;
  while (num != 0 && i < N) {
    if (num > A[i].num) {
      ans += A[i].price * A[i].num;
      num -= A[i].num;
    } else {
      ans += A[i].price * num;
      num = 0;
    }
    ++i;
  }

  cout << ans << endl;

  return 0;
}


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

const int N = 60;

int n, rt;

namespace WEN {

vector<int> G[N]; int ind[N];

inline void adde(int from, int to) {
//    cout << "adde: " << from << ' ' << to << endl;
    ind[to]++, G[from].push_back(to);
}

inline bool check() {
    queue<int> q; int tot = 0;
    for (int i = 1; i <= n; i++) if (!ind[i]) q.push(i);
    while (!q.empty()) {
        int u = q.front(); q.pop(); tot++;
        for (auto v : G[u])
            if (!--ind[v]) q.push(v);
    }
    for (int i = 1; i <= n; i++) G[i].clear(), ind[i] = 0;
    return tot == n;
}

}

vector<int> G1[N], G2[N]; int G[N][N], mark[N], tot, fuck[N][N];

void dfs(int u, int f, int ok) {
    if (ok) mark[u] = 1, tot++;
    else if (!mark[f]) WEN::adde(u, f);
    for (auto v : G1[u]) if (v != f) 
        dfs(v, u, ok & G[u][v]);
}

void dfs1(int u, int f) {
    if (!mark[u] && !mark[f]) WEN::adde(f, u);
    mark[u] = 0;
    for (auto v : G2[u]) if (v != f) dfs1(v, u);
}

inline void erase(vector<int> &t, int a) {
    for (auto &v : t) if (v == a) {
        swap(v, t.back()), t.pop_back(); return;
    }
    assert(0);
}

int main() {
    int T; scanf("%d", &T);
    while (T--) {
        int res = 1e9; scanf("%d", &n);
        memset(G, 0, sizeof(G)), memset(fuck, 0, sizeof(fuck));
        for (int i = 1; i <= n; i++) G1[i].clear(), G2[i].clear();
        for (int i = 1, a, b; i < n; i++)
            scanf("%d%d", &a, &b), G1[a].push_back(b), G1[b].push_back(a), fuck[a][b] = fuck[b][a] = 1;
        for (int i = 1, a, b; i < n; i++)
            scanf("%d%d", &a, &b), G2[a].push_back(b), G2[b].push_back(a), G[a][b] = G[b][a] = 1;
        for (int i = 1; i <= n; i++) if (G1[i].size() == 1)
            for (int j = 1; j <= n; j++) if (j != i) {
                int v = G1[i].back(); G1[i].pop_back(), erase(G1[v], i);
                G1[i].push_back(j), G1[j].push_back(i), tot = 0;
                rt = i, dfs(i, 0, 1), dfs1(i, 0);
                G1[i].pop_back(), G1[i].push_back(v), G1[j].pop_back(), G1[v].push_back(i);
                if (WEN::check()) res = min(res, n - tot + !fuck[i][j]);
//                cout << "check: " << i << ' ' << j << ' ' << res << endl;
            }
        if (res <= n) printf("%d\n", res);
        else puts("-1");
    }
}

Measured memory_bytes: 384