akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, M: int, X: int, Y: int, x: "List[int]", y: "List[int]"):
    return 'No War' if X < max(x) < min(y) <= Y else 'War'


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    x = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    y = [ int(next(tokens)) for _ in range(M) ]  # type: "List[int]"
    result = solve(N, M, X, Y, x, y)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5124
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<functional>
#include<stack>

using namespace std;

int main() {
	int a, b;
	while (cin >> a >> b) {
		if (a == 0)break;
		for (int i = 0; i < a; i++) {
			for (int j = 0; j < b; j++) {
				if ((i+j)%2==0)cout << "#";
				else cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3040
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int MOD  = 1e9+7;

int n, a;
int dp[100005];
int h[100005];

int32_t main() {
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a;	
		h[i] = a;
	}
	dp[0] = 0;
	dp[1] = abs(h[1]-h[0]);
	for (int i = 2; i < n; i++)	{
		dp[i] = min(dp[i-1]+abs(h[i-1]-h[i]), dp[i-2]+abs(h[i-2]-h[i]));
		// cout << i << " " << min(dp[i-1]+abs(h[i-1]-h[i]), dp[i-2]+abs(h[i-2]-h[i])) << " " << abs(h[i-1]-h[i]) << " " << abs(h[i-2]-h[i]) << endl;
	}
	cout << dp[n-1] << endl;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"

using namespace std;
using ll = long long;

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

#define INF 99999999
#define MOD (int)1e9 + 7
#define rep(i,n) for(int i = 0;i<n;i++)

int main() {

	int n;
	int a[100000];
	int cnt = 0;

	cin >> n;

	rep(i, n) {
		cin >> a[i];
		a[i]--;
	}

	rep(i, n) {
		if (a[a[i]]  == i ) {
			cnt++;
			a[a[i]] = -1;
			a[i] = -1;
		}
	}

	cout << cnt << endl;

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  int a;
  int cnt = 1, check;
  cin >> check;
  for (int i = 0; i < n-1; i++) {
    cin >> a;
    if (check <= a) {
      cnt++;
      check = max(check, a);
    }
    
  }
  cout << cnt << endl;
}




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

int INF = 1'000'000'007;

int main(){
    int n, m;
    cin >> n >> m;
    vector<bool> ok(n, true);
    int a;
    for (int i = 0; i < m; i++){
        cin >> a;
        ok[a] = false;
    }
    vector<long long> dp(n + 2, 0);
    dp[0] = 1;
    for (int i = 0; i < n; i++){
        if (!ok[i]) continue;
        dp[i + 1] += dp[i];
        dp[i + 1] %= INF;
        dp[i + 2] += dp[i];
        dp[i + 2] %= INF;
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = double;
template<class T>
using Table = vector<vector<T>>;


int main() {
	int N; cin >> N;
	vector<int>as;
	for (int i = 0; i < N; ++i) {
		int a; cin >> a;
		as.push_back(a);
	}
	vector<vector<ld>>dp(N, vector<ld>(200000,10000));
	for (int b = 1; b < 3 * as[0]; ++b) {
		dp[0][b] = ld(abs(b - as[0])) / as[0];
	}
	for (int i = 0; i < N-1; ++i) {
		for (int j = 1; j < as[i] * 2; ++j) {
			if (dp[i][j]>1000)continue;
			for (int k = j; k <= as[i + 1] * 2; k+=j) {
				dp[i + 1][k] = min(dp[i + 1][k], max(dp[i][j], ld(abs(k - as[i + 1])) / as[i+1]));
			}
		}
	}
	ld ans = 3;
	for (int j = 1; j < 2e5; ++j) {
		ans = min(ans, dp[N-1][j]);

	}
	cout << setprecision(22)<<fixed<<ans << endl;
	return 0;
}

Measured memory_bytes: 35604
using System;
using System.Collections.Generic;
using System.Linq;

namespace _016_TreasureHunt
{
	class Program
	{
		static void Main ( string[] args )
		{
			double xSum = 0;
			double ySum = 0;
			double angle = 0;

			//input
			while (true)
			{
				int[] inputNum = Console.ReadLine ().Split (',').Select (str => int.Parse (str)).ToArray ();

				bool isEnd = inputNum.All (item => item == 0);

				if (isEnd)
				{
					break;
				}

				double xDistance = inputNum[0] * Math.Sin (angle);
				double yDistance = inputNum[0] * Math.Cos (angle);

				xSum += xDistance;
				ySum += yDistance;

				angle += inputNum[1] * Math.PI / 180;
			}

			Console.WriteLine (Math.Truncate (xSum));
			Console.WriteLine (Math.Truncate (ySum));
		}
	}

}

Measured memory_bytes: 9448
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
    public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		boolean[] a = new boolean[n];
		Arrays.fill(a , false);
		for(int i = 0 ; i < n ; i++){
			int aa = Integer.parseInt(sc.next());
			int bb = Integer.parseInt(sc.next());
			if(aa == bb) a[i] = true;
		}
		boolean q = false;
		for(int i = 0 ; i < n - 2 ; i++){
			if(a[i] && a[i + 1] && a[i + 2]) q = true;
		}
		if(q) ou.println("Yes");
		else ou.println("No");
		ou.flush();
	}
}

Measured memory_bytes: 35792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @author Pavel Mavrin
 */
public class Main {

    private void solve() throws IOException {
        int n = nextInt();
        int m = nextInt();
        int[][] a = new int[n][m];
        for (int i = 0; i< n; i++){
            for (int j = 0; j < m;j++) {
                a[i][j] = nextInt() - 1;
            }
        }
        boolean[] z = new boolean[m];
        int res = n;
        int[] d = new int[m];
        for (int xx = 0; xx < m; xx++) {
            Arrays.fill(d, 0);
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (!z[a[i][j]]) {
                        d[a[i][j]]++;
                        break;
                    }
                }
            }
            int max = 0;
            for (int i = 0; i < m; i++) {
                max = Math.max(max, d[i]);
            }
            res = Math.min(res, max);
            for (int i = 0; i < m; i++) {
                if (d[i] == max) {
                    z[i] = true;
                    break;
                }
            }
        }
        out.println(res);
    }

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

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    PrintWriter out = new PrintWriter(System.out);

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

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

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

    private void run() throws IOException {
        solve();
        out.close();
    }

}


Measured memory_bytes: 29780
#include<bits/stdc++.h>
using namespace std;
vector<int>zh;
bool ch[1050];
int cnt[1050];
void fj(int x)
{
	for(int i=0;i<zh.size();i++)
	{
		if(x%zh[i]==0)
		{
			cnt[zh[i]]++;
			x/=zh[i];
			while(x%zh[i]==0)
			{
				x/=zh[i];
				cnt[zh[i]]++;
			}
		}
	}
}
int main()
{
	memset(ch,true,sizeof(ch));
	ch[0]=false;
	ch[1]=false;
	for(int i=2;i<1040;i++)
	{
		if(ch[i])
		{
			zh.push_back(i);
			for(int j=i*i;j<1040;j+=i)
			{
				ch[j]=false;
			}
		}
	}
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		fj(i);
	}
	long long ans=1,md=1e9+7;
	for(int i=0;i<1040;i++)
	{
		if(cnt[i])
		{
			ans*=(cnt[i]+1);
			ans%=md;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    string S;
    cin >> S;

    if(S[S.size() - 1] !=  's'){
        cout << S << "s" << endl;
    }else{
        cout << S << "es" << endl;;
    }

    return 0;
}


Measured memory_bytes: 3632
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

int main(void)
{
	int n, k;
	while(scanf("%d%d", &n, &k)==2)
	{
		vi h(n);
		for(auto&m:h) scanf("%d", &m);

		sort(h.begin(), h.end());
		ll ans=0;
		for(int i=0;i<n-k;i++) ans+=h[i];

		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define VOUT(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vout(v) VOUT(v,z);
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL);
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<" "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) { a = b; return true; }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) { a = b; return true; }
    return false;
}


vector<vector<ll>> num(1010, vector<ll>(1010, -1));
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
bool isRange(ll y, ll x, ll H, ll W){return(0<=y&&y<H&&0<=x&&x<W);}

void solve(long long H, long long W, std::vector<std::string> A){
    ll val=0;
    queue<P> q;
    for (ll i = 0; i < H; i++) {
        for (ll j = 0; j < W; j++) {
            if(A[i][j]=='#') {
                q.push(P(i,j));
                num[i][j] = 0;
            }
        }
    }
    while(q.size()){
        P p = q.front();
        q.pop();
        for (ll i = 0; i < 4; i++) {
            ll ny = p.first + dy[i], nx = p.second + dx[i];
            if(isRange(ny, nx, H, W) && A[ny][nx] == '.' && num[ny][nx] == -1){
                num[ny][nx] = num[p.first][p.second] + 1;
                q.push(P(ny,nx));
                chmax(val, num[ny][nx]);
            }
        }
    }
    // MOUT(num, H, W);
    cout << val << "\n";
}

int main(){
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    std::vector<std::string> A(H);
    for(int i = 0 ; i < H ; i++){
        std::cin >> A[i];
    }
    solve(H, W, std::move(A));
    return 0;
}


Measured memory_bytes: 25652
#include<stdio.h>
#include<stdlib.h>
int u[200005], v[200005];
long long int a[200005], b[200005];
int asc(const void* x, const void* y)
{
	if (u[*(int*)x] > u[*(int*)y])return 1;
	if (u[*(int*)x] < u[*(int*)y])return -1;
	return 0;
}
int h[1000006], l;
long long int dist[100005];
void swap_h(int x, int y)
{
	int f = h[x];
	h[x] = h[y];
	h[y] = f;
	return;
}
int comp_h(int x, int y)
{
	x = h[x];
	y = h[y];
	if (dist[x] > dist[y])return 1;
	if (dist[x] < dist[y])return -1;
	return 0;
}
void f1(int n)
{
	h[l] = n;
	int now = l;
	l++;
	while (now > 0)
	{
		if (comp_h((now - 1) / 2, now) > 0)
			swap_h((now - 1) / 2, now);
		now = (now - 1) / 2;
	}
	return;
}
int f2()
{
	l--;
	int now = 0;
	swap_h(0, l);
	for (;;)
	{
		if (2 * now + 2 < l)
		{
			if (comp_h(2 * now + 1, 2 * now + 2) > 0)
			{
				if (comp_h(now, 2 * now + 2) > 0)
					swap_h(now, 2 * now + 2);
				now = 2 * now + 2;
			}
			else
			{
				if (comp_h(now, 2 * now + 1) > 0)
					swap_h(now, 2 * now + 1);
				now = 2 * now + 1;
			}
		}
		else if (2 * now + 1 < l)
		{
			if (comp_h(now, 2 * now + 1) > 0)
				swap_h(now, 2 * now + 1);
			now = 2 * now + 1;
		}
		else
			break;
	}
	return h[l];
}
int main()
{
	int n, m, s, t;
	scanf("%d %d %d %d", &n, &m, &s, &t);
	s--;
	t--;
	int i;
	for (i = 0; i < m; i++)
	{
		scanf("%d %d %lld %lld", &u[2 * i], &v[2 * i], &a[2 * i], &b[2 * i]);
		u[2 * i]--;
		v[2 * i]--;
		u[2 * i + 1] = v[2 * i];
		v[2 * i + 1] = u[2 * i];
		a[2 * i + 1] = a[2 * i];
		b[2 * i + 1] = b[2 * i];
	}
	int c[200005];
	for (i = 0; i < 2 * m; i++)
		c[i] = i;
	qsort(c, 2 * m, sizeof(int), asc);
	long long int ans[100005];
	for (i = 0; i < n; i++)
		ans[i] = 1000000000000000;
	int min, mid, max;
	for (i = 0; i < n; i++)
		dist[i] = 1000000000000000000;
	l = 0;
	dist[s] = 0;
	f1(s);
	while (l > 0)
	{
		i = f2();
		min = 0;
		max = 2 * m;
		while (max - min > 1)
		{
			mid = (max + min) / 2;
			if (u[c[mid]] < i)
				min = mid;
			else
				max = mid;
		}
		if (u[c[min]] < i)
			min++;
		if (min < 2 * m)
		{
			while (u[c[min]] == i)
			{
				if (dist[v[c[min]]] > dist[i] + a[c[min]])
				{
					dist[v[c[min]]] = dist[i] + a[c[min]];
					f1(v[c[min]]);
				}
				min++;
				if (min == 2 * m)
					break;
			}
		}
	}
	for (i = 0; i < n; i++)
		ans[i] -= dist[i];
	for (i = 0; i < n; i++)
		dist[i] = 1000000000000000000;
	l = 0;
	dist[t] = 0;
	f1(t);
	while (l > 0)
	{
		i = f2();
		min = 0;
		max = 2 * m;
		while (max - min > 1)
		{
			mid = (max + min) / 2;
			if (u[c[mid]] < i)
				min = mid;
			else
				max = mid;
		}
		if (u[c[min]] < i)
			min++;
		if (min < 2 * m)
		{
			while (u[c[min]] == i)
			{
				if (dist[v[c[min]]] > dist[i] + b[c[min]])
				{
					dist[v[c[min]]] = dist[i] + b[c[min]];
					f1(v[c[min]]);
				}
				min++;
				if (min == 2 * m)
					break;
			}
		}
	}
	for (i = 0; i < n; i++)
		ans[i] -= dist[i];
	for (i = n - 2; i >= 0; i--)
		if (ans[i] < ans[i + 1])
			ans[i] = ans[i + 1];
	for (i = 0; i < n; i++)
		printf("%lld\n", ans[i]);
	return 0;
}

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

void solve(){
  int N, L; cin >> N >> L;
  vector<string> wd;
  for(int i = 0; i < N; ++i) {
    string tmp;
    cin >> tmp;
    wd.push_back(tmp);
  }
  sort(wd.begin(), wd.end());
  for( auto word: wd){
    cout << word ;
  }
  cout << endl;
}

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


Measured memory_bytes: 3556
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int n,k,x,y;
	cin>>n>>k>>x>>y;
	if(n<=k){
		cout<<n*x<<endl;
	}
	
	else if(n>k){
		cout<<k*x+(n-k)*y<<endl;
	}
	
}

Measured memory_bytes: 256
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")
MOD = 1000000007


INF = float("inf")
import heapq


ans = []
def dijkstra_heap(G, s, n):
    d = [INF] * n           # 始点sから各頂点への最短距離
    used = [False] * n
    d[s] = 0
    used[s] = False

    edgelist = []
    for edge in G[s]:
        heapq.heappush(edgelist, [edge[0], edge[1], s])

    while len(edgelist) > 0:
        minedge = heapq.heappop(edgelist)       # 距離最小の辺を取り出す
        dist, v, pv = minedge[0], minedge[1], minedge[2]
        
        if used[v]:
            continue
        ans[v] = pv
        d[v] = dist
        used[v] = True

        # v から伸びてる辺を edgelist に入れる
        for edge in G[v]:
            cost, nv = edge[0], edge[1]
            if used[nv]:
                continue
            heapq.heappush(edgelist, [d[v] + cost, nv, v])
    
    return d


def main():
    N, M = map(int, input().split())
    G = [[] for _ in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        a -= 1; b -= 1
        G[a].append([1, b])
        G[b].append([1, a])

    for _ in range(N):
        ans.append(-1)
    dijkstra_heap(G, 0, N)

    print("Yes")
    for i in range(1, N):
        print(ans[i] + 1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 85740
#include<bits/stdc++.h>
using namespace std;
long long read(){
	char c=getchar();long long x=0,f=1;
	while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-'0',c=getchar();
	return x*f;	
}
long long a[200005],sum;
int main(){
	long long n;
	n=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
		a[i]-=i;
	}
	sort(a+1,a+n+1);
	long long b=a[(n+1)/2];
	for(int i=1;i<=n;i++){
		sum+=abs(a[i]-b);
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using ll=long long;
ll a[510];
ll mod[510];
int n,k;
bool isGCD(int z){
  ll sum=0;
  REP(i,n){
    mod[i]=a[i]%z;
    sum+=mod[i];
  }
  if(sum%z!=0)return false;
  sort(mod,mod+n,greater<int>());
  ll rests=sum/z;
  ll result=0;
  for(int i=0;i<rests;i++){
    result+=(z-mod[i]);
  }
  if(result>k){
    return false;
  }
  return true;
}

int main(){_;
  cin>>n>>k;
  ll sum=0;
  REP(i,n){
    cin>>a[i];
    sum+=a[i];
  }

  ll result=1;
  for(ll i=2;i<30000LL;i++){//30000>sqrt(500*1000000)
    if(i*i>sum)break;
    if(sum%i!=0)continue;
    if(isGCD(i)){
      result=max(result,i);
    }
    ll j=sum/i;
    if(isGCD(j)){
      result=max(result,j);
    }
  }
  if(isGCD(sum)){
    result=sum;
  }
  cout<<result<<endl;
}


Measured memory_bytes: 256
n,y = gets.split.map(&:to_i)

(0..n).each do |man|
  (0..n).each do |gosen|
    next if man + gosen > n
    sen = n - man - gosen
    sum_val = 10000*man + 5000*gosen + 1000*sen
    if sum_val == y
      puts "#{man} #{gosen} #{sen}"
      exit
    end
  end
end

puts "-1 -1 -1"

Measured memory_bytes: 1788
def p_e():
    """
    ナップサック問題（制約厳しい版） 
    """
    N, W = map(int, input().split())
    dp = [0] * (W + 1)
    for i in range(1, N + 1):
        w, v = map(int, input().split())
        NEXT = [0] * (W + 1)
        for j in range(1, W + 1):
            if j - w >= 0:
                NEXT[j] = max(v + dp[j - w], dp[j])
            else:
                NEXT[j] = dp[j]
        dp = NEXT

    print(max(NEXT))


if __name__ == '__main__':
    p_e()


Measured memory_bytes: 117232
#include "bits/stdc++.h"
#include <stdio.h>
#pragma warning(disable : 4996)

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#define min3(x, y, z) min(x, min(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif

using namespace std;
//#define int long long;

double dist(double x1, double y1, double x2, double y2) {
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
ll idist(ll x1, ll y1, ll x2, ll y2) {
	return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}

signed main() {
	int n, k, p;
	int a = 0;
	cin >> n >> k;
	vector<int> list(n);
	rep(i, n) {
		cin >> p;
		list.at(i) = p;
	}
	sort(list.begin(), list.end());
	rep(i, k) {
		a = a + list.at(i);
	}
	cout << a << endl;
}

Measured memory_bytes: 3720
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
using namespace std;
#define int long long
#define inf 1000000007
#define rep(i,j,n) for(int i=j;i<n;i++)
typedef pair<int,int>  P;
double pi = 3.141592653589793;
//使うやつはここから下に置こうな
signed main(){
    string s;int a;cin>>s>>a;
    rep(i,0,s.size()){
        int n=s[i]-'a';
        if(n==0)continue;
        if(n+a>=26){
            a-=26-n;
            s[i]='a';
        }
    }
    int h=s[s.size()-1]-'a';
    s[s.size()-1]=(a+h)%26+'a';
    cout<<s<<endl;
    return 0;
}

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

using namespace std;

using ll = long long;

const int N = 1e5 + 10;

int a[N], mem[N], n;

int dp(int i)
{
    if (i > n - 1)
        return 2e9;

    if (i == n - 1)
        return 0;

    if (mem[i] != -1)
        return mem[i];

    int ans = 2e9;

    for (int j = 1; j <= 2; j++)
    {
        if (i + j < n)
            ans = min(ans, abs(a[i] - a[i + j]) + dp(i + j));
    }

    return mem[i] = ans;
}

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

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

    memset(mem, -1, sizeof(mem));

    printf("%d", dp(0));
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
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;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

void solve();

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

void solve(){
    char x,y;cin>>x>>y;
    if(x<y){
        cout<<'<'<<endl;
    }else if(x>y){
        cout<<'>'<<endl;
    }else{
        cout<<'='<<endl;
    }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define fastio                        \
    std::ios::sync_with_stdio(false); \
    std::cin.tie(NULL);
#define pb push_back
#define mp make_pair

using ll  = long long;

using namespace std;
ll x, y, z, l, m, n, r, q, k;

int main()
{
    fastio;
    string s;
    cin>>s;
    if(s.back()=='s') cout<<s+"es"<<endl;
    else cout<<s+"s"<<endl;
    
    
    return 0;
}

Measured memory_bytes: 3660
#include<stdio.h>

int main(void)

{
        int i=0, N, D;

        scanf("%d%d", &N, &D);

        D=D*2+1;

        for(;;){
         N=N-D;
         i++;
         if(N<=0)
           break;

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


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

int main()
{
  int ip[5];
  for(int i=0;i<5;i++)
    cin>>ip[i];
  vector<pair<int,int> >p;
  for(int j=0;j<5;j++)
  {
  	int rem = ip[j]%10;
  	int waitTime=rem!=0?10-rem:0;
  	p.push_back(make_pair(waitTime,ip[j]));
  }
  sort(p.begin(),p.end());
  int totalTime=0;
  for(int k=0;k<4;k++)
  {
   totalTime+= p[k].first+p[k].second;
  	
  }
   totalTime+=p[4].second;
   cout<<totalTime<<"\n";
}

Measured memory_bytes: 256
from collections import Counter

if __name__ == '__main__':
    MOD = 998244353
    n = int(input())
    d = list(map(int, input().split()))
    if d[0] != 0:
        print(0)
        exit(0)
    c = Counter(d)
    if c[0] != 1:
        print(0)
        exit(0)
    ans = 1
    for i in range(n - 1):
        ans *= pow(c[i], c[i + 1], MOD)
        ans %= MOD
    print(ans)


Measured memory_bytes: 19936
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

#define MAX_V 100000

struct edge{int to, cost;};
vector <edge> G[MAX_V];

ll d[MAX_V];
int V;

void dijkstra2(ll s){
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, LLINF);
    d[s] = 0;
    que.push(P(0,s));

    while(!que.empty()){
        P p=que.top(); que.pop();
        ll v=p.second;
        if(d[v] < p.first) continue; // これはなんのために
        for(int i=0; i<G[v].size(); ++i){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}


int main(){
    cin >> V;

    rep(i, V-1){
        ll from_, to_, cost_;
        cin >> from_ >> to_ >> cost_;
        --from_;
        --to_;
        edge e;
        e.to = to_; e.cost = cost_;
        G[from_].emplace_back(e);
        e.to = from_;
        G[to_].emplace_back(e); // 戻る方向のも追加が必要！！
    }
    int q, k;
    cin >> q >> k;

    dijkstra2(--k);
    rep(i, q){
        int x, y;
        cin >> x >> y;
        cout << d[--x] + d[--y] << endl;
    }
    return 0;
}

Measured memory_bytes: 9460
#include <bits/stdc++.h>
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

int main(){
  multiset<int> s;
  int q;
  cin >> q;
  int tmp, tmp2, tmp3;
  rep_i(i, q){
    cin >> tmp >> tmp2;
    if(tmp == 0){
      s.insert(tmp2);
      say(s.size());
    }else if(tmp == 1){
      // set<int>::iterator itr = s.find(tmp2);
      // if(itr == s.end()){
      //   say(0);
      // }else{
      //   say(1);
      // }
      cout << s.count(tmp2) << endl;
    }else if(tmp == 2){
      s.erase(tmp2);
    }else{
      cin >> tmp3;
      // set<int>::iterator lit = s.lower_bound(tmp2);
      // set<int>::iterator rit = s.lower_bound(tmp3);
      // size_t start = distance(s.begin(), lit);
      // size_t end = distance(s.begin(), rit);
      set<int>::iterator itr = s.lower_bound(tmp2);
      set<int>::iterator itr2 = s.find(tmp3);
      for (auto i = itr; i != s.end() && *i <= tmp3; i++){
        say(*i);
      }
      
      // r_rep_i(i, tmp2, tmp3 + 1){
      //   if(itr == s.end()){
      //     continue;
      //   }else{
      //     say(*itr);
      //   }
      // }
    }
  }
}


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

int main(){
  string S;
  cin >> S;
  int L=S.size();
  int firsta=0;
  int lastz=200001;
  for(int i=0; i<L; i++){
    if(S.at(i)=='A'){
      firsta=i;
      break;
    }
  }
  for(int i=L-1; i>0; i--){
    if(S.at(i)=='Z'){
      lastz=i;
      break;
    }
  }
  cout << lastz-firsta+1 << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  int H,W;
  cin>>H>>W;
  string S[H+1][W+1];
  
  REP(i,H){
    REP(j,W){
      cin>>S[i][j];
      if(S[i][j]=="snuke") cout<<char(j+'A')<<i+1<<endl;
    }
  }
  
}


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

#define ALL(c) c.begin(),c.end()
#define LOOP(v_name, loop_start, loop_bound) for (int(v_name) = (loop_start); (v_name) < (loop_bound); ++(v_name))
#define RLOOP(v_name, rloop_start, rloop_bound) for (int(v_name) = (rloop_start-1); v_name >= (rloop_bound); --(v_name))
#define EN_FAST_IO ios::sync_with_stdio(0);cin.tie(0);

using namespace std;
using ll = long long;
typedef vector<ll> vll;



int main(){
    EN_FAST_IO;
    int a;
    string s;
    cin>>a>>s;

    if(a>=3200){
        cout<<s;
    }
    else
    cout<<"red";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int A[n+1];
    int B[n];
    for(int i=1;i<n;i++)
    {
       cin>>B[i];
    }
    A[1]=B[1];
    for(int i=2;i<n;i++)
    {
        A[i]=min(B[i-1],B[i]);
    }
    A[n]=B[n-1];
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        sum+=A[i];
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }
  
  private static class Problem implements Comparable<Problem> {

    public int getScore() {
      return score;
    }

    public int getIndex() {
      return index;
    }

    private final int index;
    private final int score;

    private Problem(int index, int score) {
      this.score = score;
      this.index = index;
    }

    @Override
    public int compareTo(Problem o) {
      return Integer.compare(this.score, o.score);
    }
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();
    int m = sc.nextInt();
    int v = sc.nextInt();
    int p = sc.nextInt();
    
    List<Problem> list = new ArrayList<>(n);
    
    for (int i = 0; i < n; i++) {
      Problem problem = new Problem(i, sc.nextInt());
      list.add(problem);
    }
    
    list.sort(Comparator.comparingInt(Problem::getScore));
    
    List<Long> accum = new ArrayList<>();
    
    long sum = 0;
    for (int i = 0; i < n; i++) {
      accum.add(sum);
      sum += list.get(i).score;
    }
    accum.add(sum);
    
    Set<Problem> ans = new HashSet<>();
    Problem threshold = list.get(n - p);
    
    for (int i = n - 1; 0 <= i; i--) {
      Problem problem = list.get(i);
      if (!isAcceptable(n, m, v, p, i, problem, threshold, accum)) break;
      ans.add(problem);
    }
    os.println(ans.size());
  }
  
  private static boolean isAcceptable(int n, long m, long v, int p, int i, Problem problem, Problem threshold, List<Long> accum) {
    if (problem.score + m < threshold.score) return false;
    
    long vote = 0;
    int l = i;
    int r = Math.max(i, (n - 1) - ((p - 1) - 1));
    vote += m * (long) ((n - 1) - r);
    vote += m * (long) (l + 1);
    long targetScore = problem.score + m; // all man will vote to the target
    vote += targetScore * (long) (r - l) - (accum.get(r) - accum.get(l));
    return m * v <= vote;
  }
}

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

using namespace std;

#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    FOREACH(x, v) { cout << x << " "; }                                        \
    cout << "\n";

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, V, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

ll n;
deque<ll> dq;

int main() {
    cin >> n;
    REP(i, n) {
        if(i % 2)
            dq.emplace_back(IN());
        else
            dq.emplace_front(IN());
    }
    REP(i, n) {
        if(n % 2) {
            cout << dq.front() << " ";
            dq.pop_front();
        } else {
            cout << dq.back() << " ";
            dq.pop_back();
        }
    }
    cout << "\n";
}

Measured memory_bytes: 3840
using System;
using System.Collections.Generic;
using System.Linq;

namespace Eee
{
    class P
    {
        private string Read()
        {
            return Console.ReadLine();
        }

        private int[] ReadArray()
        {
            return Read().Split().Select(int.Parse).ToArray();
        }
        private const string STAR = "*";

        private void S()
        {
            var N = int.Parse(Read());
            var S = Read().ToLower();
            var arrayS = S.Split().ToArray();
            var K = int.Parse(Read());
            var list = new List<string>();
            if(N == S.Length)
            {
                var p = S.Substring(K-1,1);
                for (int i = 0; i < N; i++)
                {
                    var consol = S[i];
                    if (p.Contains(S[i]))
                    {
                        list.Add(S[i].ToString());
                    }
                    else
                    {
                        // *なやつ
                        list.Add(STAR);
                    }
                }

            }

            Console.WriteLine(string.Join("", list));
        }

        static void Main(string[] args)
        {
            new P().S();
        }
    }
}


Measured memory_bytes: 13276
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func read() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanLines)
	n, _ := strconv.Atoi(read())
	sum := 1
	for i := n; i > 0; i-- {
		sum *= i

	}
	fmt.Println(sum)
}


Measured memory_bytes: 1068
#ifdef __GNUC__
#include <bits/stdc++.h>
#endif // __GNUC__

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

    int A, B, C;
    std::cin >> A >> B >> C;
    if (A > B)std::swap(A, B);
    std::cout << (A<C&&C<B?"Yes":"No") << std::endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
const int N=1e5+5, INF=1e9;
using namespace std;
int n, k, val[N], par[N], l[N], r[N];
vector<int> adj[N];
bool can=true;
void dfs2(int u, int x)
{
    if(l[u]<=x-1 && x-1<=r[u])
    {
        val[u]=x-1;
    }
    else if(l[u]<=x+1 && x+1<=r[u])
    {
        val[u]=x+1;
    }
    else
    {
        cout << u << ": Ye to bakchodi hogai" << endl;
        exit(7);
    }
    for(auto v: adj[u])
    {
        if(v!=par[u] && val[v]==-1)
        {
            dfs2(v, val[u]);
        }
    }
}
void dfs1(int u)
{
    l[u]=-1; r[u]=INF;
    for(auto v: adj[u])
    {
        if(v==par[u]) continue;
        par[v]=u;
        dfs1(v);
        if(!can) return;
        if(l[v]==-1) continue;
        if(l[u]!=-1)        //have been initialized
        {
            if( (l[u]%2 == l[v]%2) || (r[u]%2 == r[v]%2) ) // if equal then -1 +1 wont give same parity
            {
                can=false;
                return;
            }
        }
        l[u]=max(l[v]-1, l[u]);
        r[u]=min(r[v]+1, r[u]);
    }
    if(val[u]!=-1)
    {
        if(l[u]>val[u] || r[u]<val[u] || ( (l[u] != -1) && (r[u]%2 != val[u]%2) ) ) //in range, if initialized same parity
        {
            can=false;
            return;
        }  
        for(auto v: adj[u])
        {
            if(v!=par[u] && val[v]==-1)
            {
                dfs2(v, val[u]);
            }
        }
        l[u]=val[u];
        r[u]=val[u];
    }
   // cout << u << " - " << l[u] << " " << r[u] << endl;
}
signed main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        val[i]=-1;
    }
    for(int i = 0; i < n-1; i++)
    {
        int a, b;
        cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    cin >> k;
    int root;
    for(int i = 0; i < k; i++)
    {
        int v, p;
        cin >> v >> p;
        root = v;
        val[v]=p;
    }
    dfs1(root);
    if(!can)
    {
        cout << "No";
    }
    else
    {
        cout << "Yes" << endl;
        for(int i = 1; i <= n; i++)
        {
            cout << val[i] << endl;
        }
    }
    
}

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

int main(){
    int x, y;
    while(1) {
        cin >> x >> y;
        if (x == 0 && y == 0) break;
        if (x > y){
            cout << y << " " << x << endl;
        } else {
            cout << x << " " << y << endl;
        }
    }
    return 0;
}


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

int n;
vector<int> out[200010];
int in[200010];
int cycle[200010];
int grundy[200010];
int st = -1;
const int CYCLE = 42;

int dfs(int x, int p) {
	cycle[x] = 1;
	for(int i : out[x]) {
		if(i != p) {
			if(cycle[i] == 1) {
				st = i;
				cycle[x] = CYCLE;
				return CYCLE;
			}
			else if(cycle[i] == 0) {
				if(dfs(i, x) == CYCLE) {
					cycle[x] = CYCLE;
					if(x == st) return 0;
					else return CYCLE;
				}
			}
		}
	}
	cycle[x] = 2;
	return 0;
}

int getgrundy(int x) {
	set<int> s;
	for(int i : out[x])
		if(cycle[i] != CYCLE)
			s.insert(getgrundy(i));
	int ans = 0;
	auto it = s.begin();
	while(it != s.end()) {
		if(*it == ans) {
			++ans;
			++it;
		}
		else return grundy[x] = ans;
	}
	return grundy[x] = ans;
}

bool chk(int x, int val, int res) {
	if(x == st) return res == val;
	int nxt = -1;
	for(int i : out[x]) {
		if(cycle[i] == CYCLE) {
			nxt = i;
		}
	}
	if(nxt == -1) return false;
	return chk(nxt, grundy[nxt] + (grundy[nxt] == val), res);
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	memset(cycle, 0, sizeof cycle);
	for(int i = 0; i < n; ++i){
		int x;
		cin >> x;
		--x;
		if(i == x) return cout << "POSSIBLE" << endl, 0;
		out[x].push_back(i);
		in[i] = x;
		if(x < i and in[x] == i) {
			st = i;
			cycle[x] = cycle[i] = CYCLE;
		}
	}
	for(int i = 0; st == -1 and i < n; ++i) if(cycle[i] == 0) dfs(i, -1);
	for(int i = 0; i < n; ++i) {
		if(cycle[i] == CYCLE) getgrundy(i);
	}
	int nxt;
	for(int i : out[st]) {
		if(cycle[i] == CYCLE) {
			nxt = i;
		}
	}
	if(chk(nxt, grundy[nxt] + (grundy[st] == grundy[nxt]), grundy[st])) cout << "POSSIBLE" << endl;
	else if (chk(nxt, grundy[nxt] + ((grundy[st] + 1) == grundy[nxt]), grundy[st] + 1)) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;

}


Measured memory_bytes: 22912
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
if 0 <= a <= 123 and 0 <= b <= 123 and 0 <= c <= 123 and 0 <= d <= 123 and 0 <= e <= 123 and 0 <= k <= 123 and a < b < c < d < e:
    if k >= e - a:
        print('Yay!')
    else:
        print(':(')
else:
    print('invalid value')

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

namespace IO {
    #define gc getchar()
    template <typename T>
    inline void read(T& x) {
        x = 0; bool f = 1; char ch;
        for (ch = gc; ch < '0' || '9' < ch; ch = gc) if (ch == '-') f ^= 1;
        for (; '0' <= ch && ch <= '9'; ch = gc) x = (x << 3) + (x << 1) + (ch ^ 48);
        x = f ? x : -x;
    }
    #undef gc
}

const int MAXN = 100000 + 10;

int n, m, fa[MAXN];

int gf(int x) { return fa[x] == x ? x : fa[x] = gf(fa[x]); }

int main() {
    IO::read(n), IO::read(m);
    rep(i, 1, n) fa[i] = i;
    rep(i, 1, m) {
        int a, b;
        IO::read(a), IO::read(b);
        if (fa[gf(a)] != fa[gf(b)]) fa[gf(a)] = gf(b);
    }
    int ans = 0;
    rep(i, 1, n) {
        if (fa[i] == i) ans++;
    }
    printf("%d", ans - 1);
    return 0;
}

Measured memory_bytes: 4060
fn main() {
    proconio::input! {
        n: usize,
        m: usize,
        abs: [(usize, usize); m],
    }
    let mut roadss = vec![vec![]; n + 1];
    for (a, b) in abs {
        roadss[a].push(b);
        roadss[b].push(a);
    }
    let mut deque = std::collections::VecDeque::new();
    deque.push_back(1);
    let mut rooms = vec![None; n + 1];
    while let Some(child) = deque.pop_front() {
        if let Some(grand_children) = roadss.get(child) {
            for grand_child in grand_children {
                if rooms[*grand_child].is_none() {
                    rooms[*grand_child] = Some(child);
                    deque.push_back(*grand_child);
                }
            }
        }
    }
    let ans = if rooms[2..].iter().all(|room| room.is_some()) {
        let mut v = vec!["Yes".to_string()];
        v.append(
            &mut (2..=n)
                .map(|i| rooms[i].unwrap().to_string())
                .collect::<Vec<_>>(),
        );
        v.join("\n")
    } else {
        "No".to_string()
    };
    println!("{}", ans);
}


Measured memory_bytes: 22412
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;


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

    int N;
    cin >> N;
    int H[N];
    rep(i,N) cin >> H[i];
    H[0]--;
    string ans="Yes";
    for(int i=1;i<N;i++){
        if(H[i]==H[i-1]){}
        else if(H[i]>H[i-1]){
            H[i]--;
        }
        else {
            ans="No";
            break;
        }
    }
    cout << ans << endl;

    


}


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

using namespace std;

const int NMAX = 8 + 5;

int n, m;
string mat[NMAX];

bool works(int lin, int col) {
    if (mat[lin][col] != '#')
        return false;
    if (lin == n && col == m)
        return true;

    if (mat[lin + 1][col] == '#')
        return works(lin + 1, col);
    if (mat[lin][col + 1] == '#')
        return works(lin, col + 1);
}

int main()
{
    cin >> n >> m;

    for (int i = 1; i <= n; ++ i) {
        cin >> mat[i];
        mat[i] = " " + mat[i];
    }

    int cnt = 0;
    for (int i = 1; i <= n; ++ i)
        for (auto it: mat[i])
            cnt += (it == '#');

    if (cnt != n + m - 1) {
        cout << "Impossible\n";
        return 0;
    }

    if (works(1, 1))
        cout << "Possible\n";
    else
        cout << "Impossible\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
	int A, P;
	cin >> A >> P;
	P += A * 3;
	P /= 2;
	cout << P << endl;
	return 0;
}

Measured memory_bytes: 3604
from sys import stdin
import math
import fractions
from collections import deque

INF = 10 ** 10

N, M = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]
BC = [list(map(int, stdin.readline().rstrip().split())) for _ in range(M)]
A.sort()
BC.sort(key=lambda x: (x[1]), reverse=True)

i = 0

for B, C in BC:
    for _ in range(B):
        if A[i] < C:
            A[i] = C
            i += 1
            if i > N - 1:
                print(sum(A))
                exit()
        else:
            print(sum(A))
            exit()

print(sum(A))

Measured memory_bytes: 99708
K, A, B = map(int, input().split())
answer = 1
if B - A <= 2:
    #ずっと＋１する場合
    answer += K
else:
    time = A - 1 #A枚最初に手に入る
    if time + 2 > K or B - A < 2:
        answer += K
    else:
        answer += time
        answer += ((K-time)//2) * (B-A)
        answer += (K-time)%2
print(answer)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ALL(v) std::begin(v), std::end(v)
#define ALLR(v) std::rbegin(v), std::rend(v)
using ll = std::int64_t;
using ull = std::uint64_t;
using pll = std::pair<ll, ll>;
using tll = std::tuple<ll, ll, ll>;
template <typename T> using vec = std::vector<T>;
template <typename T> using vvec = vec<vec<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return vec<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec

ll solve() {
    ll a, b;
    std::cin >> a >> b;
    for (ll i = 0; i <= 1e7; i++) {
        ll an = i * 108 / 100;
        ll bn = i * 110 / 100;
        ll adda = an - i;
        ll addb = bn - i;
        if (a == adda && b == addb) return i;
    }
    return -1;
}

int main() {
    std::cout << solve() << '\n';
    return 0;
}


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

const int MOD = 2019;

int main() {
	ios_base::sync_with_stdio(0); // making cin faster
	cin.tie(0); // making cin faster
	
	string s;
	cin >> s; // "231895129591239510901223"
	int n = s.length();
	int suf = 0;
	int power_of_ten = 1;
	vector<int> cnt_suf(MOD);
	cnt_suf[0]++;
	long long answer = 0;
	// O(N)
	for(int i = n - 1; i >= 0; i--) {
		suf = (suf + (s[i] - '0') * power_of_ten) % MOD;
		power_of_ten = 10 * power_of_ten % MOD;
		// cout << i << " " << suf << " " << power_of_ten << endl;
		answer += cnt_suf[suf];
		cnt_suf[suf]++;
	}
	cout << answer << endl;
}


Measured memory_bytes: 3788