akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
# Here your code !
 
def func():
    inputdata=[]
    while(True):
        try:
            line=input().rstrip()
            if(int(line)==0):
                break
            else:
                inputdata.append(line)
        except EOFError:
            return 0
        except:
            return inputError()
    
    data=[sum( [int(char) for char in item] ) for item in inputdata]
    [print(item) for item in data]
        
def inputError():
    print("input Error")
    return -1
 
func()

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

signed main(void)
{
	int N, W;
	cin >> N >> W;
	long long w[N + 1], v[N + 1], dp[N + 1][W + 1];
	
	for(int i = 1; i <= N; i++) cin >> w[i] >> v[i];
	rep(i, N + 1) rep(j, W + 1) dp[i][j] = 0; 
	for(int i = 1; i <= N; i++)
	{
		for(int j = 1; j <= W; j++)
		{
			if (j - w[i] >= 0)
				dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
			dp[i][j] = max(dp[i][j], dp[i - 1][j]);	
		}
	}
	cout << dp[N][W] << endl;
	return 0;
}


Measured memory_bytes: 79104
n,T=map(int,input().split())
ct = []
for _ in range(n):
    c,t=map(int,input().split())
    ct.append([c,-(t<=T)])
ct = sorted(ct,key=lambda x:(x[1],x[0]))
print(ct[0][0] if ct[0][1] < 0 else 'TLE')

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

int main() {
  int n;
  string s;
  cin>>n>>s;
  int ans = 0;
  for (int i=1; i<n-1; i++) {
    string x = s.substr(0, i);
    string y = s.substr(i);
    set<char> sx(x.begin(), x.end());
    set<char> sy(y.begin(), y.end());

    int cnt = 0;
    for (char c: sx) {
      if (sy.find(c) != sy.end()) {
        ++cnt;
      }
    }
    ans = max(cnt, ans);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;using pld=pair<ld,ld>;
const ll INF=1LL<<60;void solve();int main(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();}
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d!=0&&d>0?i<n:i>n;i+=d)
#define foreach(i,A) for(auto &i:A)
#define all(A) A.begin(),A.end()
#define len(A) (ll)A.size()
template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b; return 1;} return 0;}

void solve(){
  ll n; cin>>n;
  vector<pll> PI(n);
  rep(i,n){
    ll p; cin>>p;
    PI[i]={p,i};
  }
  sort(all(PI),greater<pll>());
  
  ll ans=0;
  multiset<ll> S{-1,-1,n,n};
  foreach(tup,PI){
    ll p,i; tie(p,i)=tup;
    auto it1=S.insert(i);
    auto it2=it1;
    ll l0=*(--it1), l1=*(--it1);
    ll r0=*(++it2), r1=*(++it2);
    ans+=p*((l0-l1)*(r0-i)+(i-l0)*(r1-r0));
  }

  cout<<ans<<"\n";
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+7;
int main()
{
	string s;
	int n;cin>>n;
	cin>>s;
	int len=s.length();
	for(int i=0;i<len;i++)
	{
		s[i]=(s[i]-'A'+n)%26+'A';
	}
	cout<<s<<endl;
	return 0;
}

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

namespace test
{

    class Program
    {
        static void Main(string[] args)
        {
            List<string> resultList = new List<string>();

            string input;
            while ((input = Console.ReadLine()) != null)
            {
                string[] array = input.Split(' ');
                int c1 = int.Parse(array[0]);
                int c2 = int.Parse(array[1]);
                int c3 = int.Parse(array[2]);
                List<int> mountain = new List<int>();
                for (int i = 1; i <= 10; i++)
                {
                    if (i != c1 || i != c2 || i != c3)
                    {
                        mountain.Add(i);
                    }
                }

                if (c1 + c2 + mountain[3] <= 20)
                {
                    resultList.Add("YES");
                }
                else
                {
                    resultList.Add("NO");
                }

            }

            foreach (string a in resultList)
            {
                Console.WriteLine(a);
            }

        }

        
    }
}

Measured memory_bytes: 5420
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define FOR(i,n,a) for(int i = a;i<n;i++)
#define rep(i,n) FOR(i,n,0)
#define UNFOR(i,n,a) for(int i = a;i>n;i--)
#define unrep(i,n) UNFOR(i,0.n)
typedef long long ll;
using namespace std;
int main(){
	map<string, int> s, t;
	int n ,m;
	cin >> n;
	vector<string> v;
	rep(i, n) {
		string tmp;
		cin >> tmp;
		v.push_back(tmp);
		if(s[tmp]==0)s[tmp]= 1;
		else s[tmp]++;
	}
	cin >> m;
	rep(i, m) {
		string tmp;
		cin >> tmp;
		v.push_back(tmp);
		if (t[tmp] == 0)t[tmp] = 1;
		else t[tmp]++;
	}
	int ans = 0;
	rep(i, v.size()) {
		ans = max(ans, s[v[i]] - t[v[i]]);
	}
	cout << ans << endl;
	cin >> ans;
	return 0;
}

Measured memory_bytes: 384
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

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

    int N = scanner.nextInt();
    long[] cumsum = new long[N + 1];
    for (int i = 1; i <= N; i++) cumsum[i] = cumsum[i - 1] + scanner.nextInt();

    Map<Long, Integer> freq = new HashMap<>();
    freq.put(0L, 1);
    long res = 0;
    for (int i = 1; i <= N; i++) {
      int f = freq.getOrDefault(cumsum[i], 0);
      res += f;
      freq.put(cumsum[i], f + 1);
    }
    System.out.println(res);
  }
}


Measured memory_bytes: 91464
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;


int main(){
    char s[100005];
    scanf("%s",s);
    int n;
    n=strlen(s);
    int sta=0,end=n-1;
    int ans=0;
    int flag=0;
    while(sta<=end){
        if(s[sta]==s[end]){
            sta++;
            end--;
        }else if(s[sta]=='x'){
            sta++;
            ans++;
        }else if(s[end]=='x'){
            end--;
            ans++;
        }else{
            flag++;
            break;
        }
    }
    if(flag!=0)printf("-1");
    else printf("%d",ans);
    
    
    return 0;
}


Measured memory_bytes: 256
#include <atcoder/mincostflow>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
typedef long long ll;
const ll M = 1000000000;
int main() {
	int N, K;
	cin >> N >> K;
	vector<vector<int>> A(N, vector<int>(N));
	for (auto& x : A) for (auto& y : x) cin >> y;

	mcf_graph<int, ll> G(2*N+2);
	G.add_edge(2*N, 2*N+1, N*K, M);
	for (int i = 0; i < N; ++ i) {
		G.add_edge(2*N, i, K, 0);
		G.add_edge(N+i, 2*N+1, K, 0);
	}
	for (int i = 0; i < N; ++ i) {
		for (int j = 0; j < N; ++ j) {
			G.add_edge(i, N+j, 1, M - A[i][j]);
		}
	}
	auto r = G.flow(2*N, 2*N+1, N*K);
	cout << M * N * K - r.second << endl;

	vector<string> a(N, string(N, '.'));
	for (auto e : G.edges()) if (e.from < 2*N && e.to < 2*N && e.flow > 0) {
		a[e.from][e.to-N] = 'X';
	}
	for (auto& x : a) cout << x << endl;
}


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

int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if (a+b>c+d){
    cout<<"Left"<<endl;
  }else if(a+b<c+d){
    cout<<"Right"<<endl;
  }else{
    cout<<"Balanced"<<endl;
  }
}

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


int main()
{
   int a[3],s=0,i;
   cin>>a[0]>>a[1]>>a[2];
   sort(a,a+3);
    for(i=0; i<2; i++){
        s+=a[i+1]-a[i];
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()
#define pb push_back

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1 << 60LL;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

// 型による変数のオーバーフローに気をつけろ！！
// 悩んだら図やグラフを書け！！悩む前から書け！！

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

	ll n;
	cin >> n;
	vector<long double> x(n);
	vector<string> u(n);
	rep(i, n) {
		cin >> x[i] >> u[i];
	}

	long double sum = 0;
	rep(i, n) {
		if (u[i] == "BTC") {
			sum += x[i] * 380000;
		}
		else {
			sum += x[i];
		}
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

using T = tuple<int, int, int>;
const int INF = 1001001001;

bool r[33][33];
bool c[33][33];
int d[33][33];
int dx[4] = { 0, 0, -1, 1 }, dy[4] = { -1, 1, 0, 0 };

int main() {
    int w, h;
    while (cin >> w >> h && w) {
        for (int i = 0; i < 33; i++) {
            for (int j = 0; j < 33; j++) {
                r[i][j] = c[i][j] = true;
                d[i][j] = INF;
            }
        }
        for (int i = 0, k; i < 2 * h - 1; i++) {
            if (i % 2 == 0) {
                for (int j = 0; j < w - 1; j++) {
                    cin >> k;
                    if (k) c[i / 2][j] = false;
                }
            } else {
                for (int j = 0; j < w; j++) {
                    cin >> k;
                    if (k) r[i / 2][j] = false;
                }
            }
        }
        queue<T> que;
        que.push(T(0, 0, 1));
        d[0][0] = 1;
        while (que.size()) {
            T t = que.front(); que.pop();
            int cy = get<0>(t), cx = get<1>(t);
            for (int i = 0; i < 4; i++) {
                int ny = cy + dy[i], nx = cx + dx[i];
                if (!(0 <= ny && ny < h && 0 <= nx && nx < w)) continue;
                if (dy[i] == -1 && !r[cy - 1][cx]) continue;
                if (dy[i] == 1 && !r[cy][cx]) continue;
                if (dx[i] == -1 && !c[cy][cx - 1]) continue;
                if (dx[i] == 1 && !c[cy][cx]) continue;
                if (d[ny][nx] == INF) {
                    d[ny][nx] = get<2>(t) + 1;
                    que.push(T(ny, nx, d[ny][nx]));
                }
            }
        }
        if (d[h - 1][w - 1] == INF) cout << 0 << endl;
        else cout << d[h - 1][w - 1] << endl;
    }
}


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

using namespace std;

#define all(x) begin(x), end(x)

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;

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

    int n;
    cin >> n;
    vi a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    int v = a[0] - a[n - 1];
    for (int i = 1; i < n - 1; ++i) {
        v = a[i] - v;
    }

    vi b(n);
    b[n - 1] = v / 2;
    for (int i = n - 2; i >= 0; --i) {
        b[i] = a[i] - b[i + 1];
    }

    for (int i = 0; i < n; ++i) {
        cout << (2 * b[i]) << ' ';
    }

    // a0 = x0 + x1
    // a1 = x1 + x2
    // a2 = x2 + x0
    //
    // a0 - an-1 = x0 + x1 - xn-1 - x0
    // a0 - an-1 = x1 - xn-1
    //
    // a1 - (a0 - xn-1) = x2 + xn-1
    //
    // a2 - (a1 - (a0 - xn-1)) = x3 - xn-1
    // a3 - (...) = -x4 - xn-1
    
    return 0;
}


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

class Program
{    

    static void Main(string[] args)
    {
        string str = Console.ReadLine();    
        char[] origin = str.ToArray();      
        string input;
        int n = int.Parse(Console.ReadLine());    
        string[] strer;
        int a;
        int b;
        string p;
        var resultlist = new List<string>();  

        for(int i = 0; i < n; i++)
        {
            input = Console.ReadLine();
            strer = input.Split(' ');
                     
            if(strer[0] == "replace")
            {
                
                a = int.Parse(strer[1]);
                b = int.Parse(strer[2]);
                p = strer[3];

                char[] ch = p.ToArray();  

                for(int j = 0; j < b - a + 1; j++)
                {
                    origin[a + j] = ch[j];
                }               
            }
            else if(strer[0] == "print")
            {
                a = int.Parse(strer[1]);
                b = int.Parse(strer[2]);
                char[] c = new char[b - a + 1];
                for(int j = 0; j < b - a + 1; j++)
                {
                    c[j] = origin[a + j];
                }

                string s = new string(c);
                resultlist.Add(s);
               
            }
            else if(strer[0] == "reverse")
            {
                a = int.Parse(strer[1]);
                b = int.Parse(strer[2]);
                
                Array.Reverse(origin, a, b - a + 1);
                
            }

        }

        foreach(var s in resultlist)
        {
            Console.WriteLine(s);
        }





    }
}


Measured memory_bytes: 18348
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,a[100007],dp[1000007];
int32_t main()
{
 cin>>n;
 for(int i=0;i<n;i++)
   cin>>a[i],dp[i]=0;
 dp[0]=0;
 dp[1]=abs(a[1]-a[0]);
 for(int i=2;i<n;i++)
   dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
 cout<<dp[n-1]<<endl;
 return 0;
}

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

int main() {

    int a,b,c;
    scanf("%d %d %d", &a, &b, &c);

    if(c>=a && c<=b){
        puts("Yes");
    }else{
        puts("No");
    }


    return 0;

}


Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
int main(void){
    int A,B;
    scanf("%d %d",&A,&B);
    if(A-B>=1){
        printf("%d",2*A-1);
    }
    else if(A==B){
        printf("%d",2*A);
    }
    else{
        printf("%d",2*B-1);
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

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

    priority_queue<ll, vector<ll>, greater<ll>> plus;
    vector<ll> p(N + 1);
    ll psum = 0;
    for (int i = 0; i < N; i++) {
        plus.push(a[i]);
        psum += a[i];
    }
    p[0] = psum;
    for (int i = N; i < 2 * N; i++) {
        if (plus.top() < a[i]) {
            psum += a[i] - plus.top();
            plus.pop();
            plus.push(a[i]);
        }
        p[i - N + 1] = psum;
    }

    priority_queue<ll> minus;
    vector<ll> m(N + 1);
    ll msum = 0;
    for (int i = 3 * N - 1; i >= 2 * N; i--) {
        minus.push(a[i]);
        msum += a[i];
    }
    m[N] = msum;
    for (int i = 2 * N - 2; i >= N - 1; i--) {
        if (minus.top() > a[i + 1]) {
            msum += a[i + 1] - minus.top();
            minus.pop();
            minus.push(a[i + 1]);
        }
        m[i - N + 1] = msum;
    }

    ll ans = -1e18;
    for (int i = 0; i <= N; i++) {
        // cout << i + N - 1 << " " << p[i] << " " << m[i] << endl;
        ans = max(ans, p[i] - m[i]);
    }
    cout << ans << endl;
}


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

int main() {
    string s;
    cin >> s;
    int a = 0, b = 0, c = 0;
    for (int i = 0; i < 3; i++)
    {
        if(s[i] == 'a')a++;
        else if(s[i] == 'b')b++;
        else c++;
    }

    if(a == 1 && b == 1 && c == 1) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N, K = LI()
A = LI()


# def binary_search(low, high):

#     while low <= high:
#         mid = (low + high) // 2
#         guess = list[mid]
#         if guess == item:
#             return guess
#         if guess > item:
#             high = mid - 1
#         else:
#             low = mid + 1
low = 0
high = max(A)

while high != low+1:
    mid = (low + high) // 2
    cut_cnt = 0
    # print(low, high)
    # print(mid)
    for i in range(N):
        tmp = math.ceil(A[i] / mid)
        if tmp > 0:
            cut_cnt += tmp - 1
    if cut_cnt <= K:
        high = mid
    else:
        low = mid 
print(high)









"""
L > t, L - t



7,9

3.5, 3.5, 9

3.5, 3.5, 3, 3, 3

K = 1
7, 4.5, 4.5
K = 2
3.5, 3.5, 4.5, 4.5
K = 3
3.5, 3.5, 3, 3, 3

K = 4
2.3, 2.3, 2.3, 3,3,3

"""

Measured memory_bytes: 33920
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int K = fs.nextInt();
        int S = fs.nextInt();

        int ans = 0;
        for (int i = 0; i <= K; ++i) {
            for (int j = 0; j <= K; ++j) {
                int z = S - i - j;
                if (z >= 0 && z <= K) ++ans;
            }
        }

        System.out.println(ans);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}

    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() { return Double.parseDouble(next());}
}




Measured memory_bytes: 32604
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    for(int q=0;q<n;q++){
        string x,y;
        cin >>x >> y;
        int dp[1002][1002];
        memset(dp,-1, sizeof(dp));
        dp[0][0] = 0;
        for(int i=0;i<x.size()+1;i++){
            for(int j=0;j<y.size()+1;j++){
                if (i < x.size() && j < y.size() && x[i] == y[j]){
                dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1);
                }
                dp[i][j+1] = max(dp[i][j+1],dp[i][j]);
                dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
            }
        }
        cout << dp[x.size()][y.size()] << endl;
    }
}


Measured memory_bytes: 7068
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#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 repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main(){
  ll n;
  cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i];
  sort(all(a));
  ll k=a[n-1];
  ll j=INF;
  ll cu;
  rep(i,n){
    if(j>abs(a[i]-(k-a[i]))){
      j=abs(a[i]-(k-a[i]));
      cu=a[i];
    }
  }
  cout<<k<<" "<<cu<<endl;
}

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

const int N = 300000 + 233, P = 1e9 + 7;

inline void check(int &x) {
  x -= P, x += x < 0 ? P : 0;
}

int n, f[N][7]; char str[N];

int main() {
  scanf("%s", str + 1);
  n = strlen(str + 1);
  if (n == 1) {
    puts(str[1] == '0' ? "0" : "1");
    return 0;
  }
  if (str[1] != '1') f[1][0] = 1;
  if (str[1] != '0') f[1][1] = 1;
  for (int i = 1; i < n; ++i) {
    if (str[i + 1] != '1') {
      check(f[i + 1][0] += f[i][2]);
      check(f[i + 1][0] += f[i][3]);
      check(f[i + 1][2] += f[i][0]);
      check(f[i + 1][4] += f[i][1]);
      check(f[i + 1][5] += f[i][4]);
      check(f[i + 1][6] += f[i][6]);
      check(f[i + 1][4] += f[i][5]);
    }
    if (str[i + 1] != '0') {
      check(f[i + 1][0] += f[i][2]);
      check(f[i + 1][3] += f[i][0]);
      check(f[i + 1][1] += f[i][3]);
      check(f[i + 1][1] += f[i][4]);
      check(f[i + 1][4] += f[i][5]);
      check(f[i + 1][6] += f[i][1]);
      check(f[i + 1][6] += f[i][6]);
    }
  }
  std::cout << (f[n][1] + f[n][6]) % P << std::endl;
  return 0;
}



Measured memory_bytes: 8704
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int main() {
  string n;
  cin>>n;
  int a;
  a=n[n.size()-1]-'0';
  if(a==3) cout<<"bon"<<endl;
  else if(a==0 or a==1 or a==6 or a==8) cout<<"pon"<<endl;
  else cout<<"hon"<<endl;
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>

void output(std::vector<int>& v)
{
	std::string answer;

	size_t size = v.size();
	for (size_t i = 0; i < size; i++)
	{
		std::ostringstream item;
		item << v[i];
		answer = answer + item.str();
		if (i < size-1)
		{
			answer += " ";
		}
	}

	std::cout << answer << std::endl;
}

int main()
{
	std::vector<int> input(3);
	for (int i = 0; i < 3; i++)
	{
		std::cin >> input[i];
	}
	
	std::sort(input.begin(), input.end());
	output(input);

	return 0;
}


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


void cc_env() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	//
#endif
}



int main() {
	// cc_env();
	// input part
	int N;
	cin >> N;
	vector<double> inputArr(N);
	for (int i = 0; i < N; i++)
		cin >> inputArr[i];

	// processing part
	vector<vector<double> > dp(N + 1, vector<double>(N + 1, 0.0));

	// base case
	dp[0][0] = 1.0;
	for (int j = 1; j <= N; j++)
		dp[j][0] = dp[j - 1][0] * (1.0 - inputArr[j - 1]);

	for (int i = 0; i < N + 1; i++) { // turn
		for (int j = 1; j < N + 1; j++) { // number of head
			if (j <= i) {
				dp[i][j] = (dp[i - 1][j - 1] * inputArr[i - 1]) + dp[i - 1][j] * (1.0 - inputArr[i - 1]);
			}
		}
	}

	double ans = 0;
	for (int i = N / 2 + 1; i <= N; i++)
		ans += dp[N][i];
	cout << setprecision(10) << ans << endl;

}


Measured memory_bytes: 73812
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>
using namespace std;
typedef long long ll;

int main(){
	ios::sync_with_stdio(false);
	ll N,out=0;
	cin>>N;
	vector<ll> A(N),B(N);
	for(int i=0;i<N;i++) cin>>A[i];
	for(int i=0;i<N;i++) cin>>B[i];
	for(ll i=29;i>=0;i--){
		ll high=1<<(i+1),low=1<<i;
		for(int j=0;j<N;j++){
			B[j]%= high;
			A[j]%= high;
		}
		sort(B.begin(),B.end());
		ll ans=0;
		for(int j=0;j<N;j++){
			ll reg=0;
			if(low -A[j] >= 0){
				reg += lower_bound(B.begin(), B.end(), high - A[j] ) - lower_bound(B.begin(), B.end(), low - A[j] );
			}else{
				reg += lower_bound(B.begin(), B.end(), high - A[j] ) - B.begin();
				reg += lower_bound(B.begin(), B.end(), high ) - lower_bound(B.begin(), B.end(), high + low - A[j] );
			}
			ans+=reg;
		}
		//cout<<reg<<" ";
		if(ans&1) out += low;
	}
	cout<<out<<endl;
	return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#include <stdio.h>
#include <cassert>
using namespace std;
typedef long long lo;
typedef pair<lo,lo> ll;//pair
typedef vector<lo> vl;  //vector of long
typedef vector<ll > vll;   //vector of pair
typedef priority_queue<lo>p_q;
typedef vector< vl > vvl;  //vector of vectors
#define X first
#define Y second
#define mp(a,b) make_pair((a),(b))
#define REP(a,b) for(lo i=(a);i<(lo)b;i++)//no need to declare variable i
#define REPE(a,b,c,d) REP(a,b)for(lo j=(c);j<(lo)d;j++)//no need to declare vaiables i,j
#define REPV(a,b,c) for((a)=b;(a)<(c);(a)++)//a is the variable
#define IREP(a,b) for(lo i=(a);i>=(b);i--)
#define IREPV(a,b,c) for((a)=b;(a)>=(c);(a)--)
#define all(v) (v).begin(),(v).end()
#define TRV(a) for(auto i : a)
#define INF 50000
#define MOD 1000000007
#define pb(a) push_back((a))
#define meme(a,b) memset((a),(b),sizeof((a)))

vector<lo> pset(1000001); // 1000 is just an initial number, it is user-adjustable.
void initSet(lo _size) { pset.resize(_size); REP (0, _size) pset[i] = i; }
lo findSet(lo i) { return (pset[i] == i) ? i : (pset[i] = findSet(pset[i])); }
void unionSet(lo i, lo j) { pset[findSet(i)] = findSet(j); }
bool isSameSet(lo i, lo j) { return findSet(i) == findSet(j); }

int main(){
    lo a,b,c,d,j,k,l,te,ans1,n,ans,arr[4];
    cin>>a>>b>>c>>d>>n;
    lo x = 100000000000000000;
    x = min(x,d);
    x = min(x,2*c);
    x = min(x,c+b*2);
    x = min(x,c+b+a*2);
    x = min(x,c+a*4);
    x = min(x,b+a*6);
    x = min(x,2*b+a*4);
    x = min(x,3*b+a*2);
    x = min(x,4*b);
    //x = min(x,b+a*6);
    x = min(x,a*8);
   // cout<<x<<endl;
    ans = 0;
    ans = (n/2)*x;
    n%=2;
    if(n==0)cout<<ans;
    else if(n==1){
        x = 100000000000000000;
        x = min(x,a*4);
        x = min(x,a*2+b);
        x = min(x,2*b);
        //x = min(x,3*b+a*2);
        x = min(x,c);
        ans +=x;
        cout<<ans;
    }
    return 0;
}


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

using namespace std;

using int64 = long long;

int main() {
  int N;
  cin >> N;
  int sum = 0;
  int add[86401 * 2] = {};
  for(int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    sum += a;
    sum %= 86400;
    add[sum]++;
    add[sum + 86400]++;
    sum += b;
  }
  for(int i = 1; i < 86400 * 2; i++) {
    add[i] += add[i - 1];
  }
  int ret = 0;
  for(int i = 10801; i < 86400 * 2; i++) {
    ret = max(ret, add[i] - add[i - 10801]);
  }
  cout << ret << endl;
}

Measured memory_bytes: 896
import sys, os, math

def get_cd(n):
    cd = []
    for i in range(1, int(n/2)+1):
        if n % i == 0:
            cd.append(i)
        else:
            continue
    cd.append(n)
    return cd

def get_gcd(a, b, c, cd_d):
    if 1 in [a, b, c]:
        return 1
    else:
        cd = sorted(list(set(cd_d[a]) & set(cd_d[b]) & set(cd_d[c])))
        return cd[-1]

if __name__ == '__main__':
    k = int(input())
    cc_d = {}
    for i in range(1, k+1):
        cc_d[i] = get_cd(i)

    computed_d = {}
    s = 0
    for a in range(1, k+1):
        for b in range(a, k+1):
            for c in range(b, k+1):
                if a == b == c:
                    s += a
                else:
                    gcd = get_gcd(a, b, c, cc_d)
                    if a != b != c:
                        s += gcd*6
                    else:
                        s += gcd*3
    print(s)

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

class Dmondai
{
    static void Main()
    {
        var nm = Console.ReadLine().Split(' ').Select(x=>Int64.Parse(x)).ToArray();
        var N = nm[0];
        var M = nm[1];
        var ans = 0L;
        if (N == 1 && M == 1) ans=1;
        else if( N==1 || M == 1)
        {
            if (N == 1) ans = M - 2;
            else ans = N - 2;
        }
        else ans = (N - 2) * (M - 2);
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13268
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	int n; cin >> n;
	VI c(n), a(n);
	rep(i, n)cin >> c[i];

	int q; cin >> q;
	int ans = 0;
	rep(i, q) {
		int t, x, d; cin >> t >> x >> d;
		if (t == 1)a[x - 1] += d;
		else a[x - 1] -= d;

		if (a[x - 1] > c[x - 1] || a[x - 1] < 0) {
			ans = ans == 0 ? x : ans;
		}
	}
	Cout(ans);
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main()
{
	ll n,x;
	cin >> n >> x;
	vector<ll> a(n);
	rep(i,n)cin >> a[i];
	ll s = 0, t = 0;
	vector<ll> b , c;
	b = a;
	rep(i,n-1)
	{
		if(b[i]+b[i+1]>x)
		{
			if((b[i]+b[i+1]-x)>b[i+1])
			{
				s+=b[i+1];
				b[i+1]=0;
				s += b[i]-x;
				b[i]-=b[i]-x;
				
			}
			else
			{
				
			s += b[i]+b[i+1]-x;
			b[i+1] -= b[i]+b[i+1]-x;
			}
			
			
		}
	}
	//rep(i,n)cout<<b[i]<<' ';cout<<endl;
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;

namespace ABC122A
{
    class Program
    {
        static void Main(string[] args)
        {
            var b = Console.ReadLine()[0];
            if (b == 'A') Console.WriteLine("T");
            if (b == 'T') Console.WriteLine("A");
            if (b == 'G') Console.WriteLine("C");
            if (b == 'C') Console.WriteLine("G");
        }


    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String ReadNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int ReadInt => int.Parse(ReadNext());
        public static long ReadLong => long.Parse(ReadNext());
        public static int[] ReadInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] NextLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

    static class Debug
    {
        static public void Draw2D(int[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            int[,] map2 = new int[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0;
                    else if (i == 0) map2[i, j] = j - 1;
                    else if (j == 0) map2[i, j] = i - 1;
                    else map2[i, j] = map[i - 1, j - 1];
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j] % 10);
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        static void Draw1D(int[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


Measured memory_bytes: 13140
def main():
    n = int(input())
    A = list(map(int, input().split()))
    ans = []

    x1 = 0
    for i, ai in enumerate(A):
        x1 += ai if i % 2 == 0 else -ai
    x1 //= 2
    ans.append(x1)

    for a in A[:-1]:
        ans.append(a - ans[-1])

    print(" ".join(str(a * 2) for a in ans))


if __name__ == '__main__':
    main()


Measured memory_bytes: 24936
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    k,n=INTM()
    A=LIST()
    As=[]
    for i in range(n-1):
        As.append(A[i+1]-A[i])
    As.append(k+A[0]-A[n-1])
    print(k-max(As))
    
if __name__ == '__main__':
    do()

Measured memory_bytes: 26444
/*------------------------------------
.....Bismillahir Rahmanir Rahim.......
created by muslim.time: 2:24:23 pm....
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld long double
#define   pb push_back
#define  sz(x)  (int)x.size()
#define  ff first
#define  ss second
#define  pii  pair<int,int>
using namespace std;

inline void solve(){ 
    string a,b,c; 
    cin>>a>>b>>c; 
    // int l=a.size(),ll=b.size(),lll=c.size(),i=0,j=0,k=0; 
    char cc ; 
    while (1){
        cc =a[0];
        a.erase(a.begin());
        break;
    }
    while (1){
        if (cc=='a') { 
            if (a.size()==0){ 
                cc='a'; break; 
            }  
            else {
                cc=a[0]; 
                a.erase(a.begin()); 
            }
        }
        else if (cc=='b'){
            if (b.size()==0){
                cc='b'; break;
            }
            else {
                cc=b[0];
                b.erase(b.begin());
            }
        }
        else {
            if (c.size()==0){
                cc='c'; break;
            }
            else {
                cc=c[0];
                c.erase(c.begin());
            }
        }
    }
    cout << (char) (cc-32) << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 504
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

int main(){
    ll n;
    cin >> n;
    ll a,b;
    cin >> a >> b;
    ll p[n];
    ll p1=0,p2=0,p3=0;
    rep(i,n){
        cin >> p[i];
        if(p[i] <= a) p1++;
        else if(p[i] > b) p3++;
        else p2++;
    }
    cout << min(p1, min(p2, p3)) << endl;  
}

Measured memory_bytes: 256
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <string>
#include <map>
#include <iostream>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <climits>
#include <limits>
#include <queue>
#include <utility>

using namespace std;

//codeforces 651 



#define ll long long


	ll mypow(int base, int p) {
		ll res = 1;
		for (int i = 0; i < p; i++)
			res *= base;
		return res;
	}

	int main() {

		ll num;
		cin >> num;
		int len = 1;
		ll lim = 26;
		ll prevLim = 0;
		while (lim < num) {
			len++;
			prevLim = lim;
			lim = mypow(26, len) + lim;
			//cout << " lim = " << lim << " len = " << len << endl;
		}

		if (num < 27) {
			cout << (char)(num + ((int)'a' - 1)) << endl;
			return 0;
		}
		
		//cout << " num = " << num << " prevLim = " << prevLim << endl;

		lim = num - prevLim - 1;
		vector<int> digs(len, 0);
		int currPow = len-1;
		while (lim) {
			//cout << " lim = " << lim << endl;
			ll reduce = mypow(26, currPow);
			//cout << "    can we reduce " << reduce << "?";
			if (lim >= reduce) {
				//cout << " yes! " << endl;
				//lim -= reduce;
				//digs[currPow]++;
				digs[currPow] += (lim / reduce);
				lim -= (reduce * (lim / reduce));
			}
			else {
				//cout << " no... reducing pow to " << (currPow - 1) << endl;
				currPow--;
			}
		}
		string s("");
		for (int i = digs.size() - 1; i >= 0; i--)
			s = s + (char)(digs[i] + ((int)'a'));

		cout << s << endl;
		//cout << "lim = " << lim << " len = " << len << endl;

		return 0;

	}




Measured memory_bytes: 3608
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;

ll MOD = 1000000007;

mat Edge;
vec p;

void dfs(int v,int par)
{
	for (auto u : Edge[v])
	{
		if (u == par)continue;
		p[u] += p[v];
		dfs(u, v);
	}
}

int main()
{
	int N, Q; cin >> N >> Q;
	Edge = mat(N);

	for (int i = 0; i < N - 1; ++i)
	{
		int a, b; cin >> a >> b; --a; --b;

		Edge[a].emplace_back(b);
		Edge[b].emplace_back(a);
	}

	p = vec(N, 0);

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

	dfs(0, 0);

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

	return 0;
}

Measured memory_bytes: 24320
import numpy as np
import math
import sys
import heapq
sys.setrecursionlimit(10000000)

def main():
    N, M = map(int, input().split())
    AB = []
    for i in range(N):
        a, b = map(int, input().split())
        AB.append((a, b))
    
    AB = sorted(AB)
    ans = 0
    idx = 0
    priority_queue = []
    for i in range(1, M + 1):
        # print(i)
        while True:
            if idx < N and AB[idx][0] <= i:
                heapq.heappush(priority_queue, - AB[idx][1])
                idx += 1
            else:
                break
        if len(priority_queue) == 0:
            continue
        else:
            max_element = - heapq.heappop(priority_queue)
            ans += max_element
    print(ans)



if __name__ == '__main__':
    main()

Measured memory_bytes: 29332
#include <iostream>
#include <array>
#include <algorithm>

using namespace std;

int main()
{
  array<int,3> v;
  cin >> v[0] >> v[1] >> v[2];
  sort(v.begin(),v.end());
  cout << v[2]*10 + v[1] + v[0] << endl;
  return 0;
}

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

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

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

    vector<P> V(N);
    rep(i, N) {
        int l, r;
        cin >> l >> r;
        V[i] = P(l, r + 1);
    }

    int maxL = 0, minR = INF;
    rep (i, N) {
        maxL = max(maxL, V[i].first);
        minR = min(minR, V[i].second);
    }

    // maxLの区間とminRの区間を同じ集合の要素とする場合
    ll ans = 0;
    rep(i, N) {
        ans = max(ans, (ll)max(0, minR - maxL) + (V[i].second - V[i].first));
    }

    vector<P> ab(N);
    rep(i, N) {
        int a = max(0, V[i].second - maxL);
        int b = max(0, minR - V[i].first);
        ab[i] = P(a, b);
    }

    sort(ab.begin(), ab.end(), [](P a, P b){
        return a.first < b.first || (a.first == b.first && a.second > b.second);
    });

    int res = INF;
    rep(i, N - 1) {
        res = min(res, ab[i].second);
        ans = max(ans, (ll)res + ab[i + 1].first);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
import sys
input = sys.stdin.readline
N = int(input())
t,x,y = 0,0,0
for i in range(N):
    T,X,Y = map(int,input().split())
    d = abs(x-X)+abs(y-Y)
    if (T-t)-d >= 0 and ((T-t)-d)%2 == 0:
        t,x,y = T,X,Y
        continue
    else:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

typedef pair<int, int> P;

P mov[100000];
bool possibility[100000] = {};
int num[100000];

int main() {
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> mov[i].first >> mov[i].second;
		mov[i].first--, mov[i].second--;
	}

	possibility[0] = true;
	for (int i = 0; i < N; i++)num[i] = 1;

	for (int i = 0; i < M; i++) {
		int from = mov[i].first, to = mov[i].second;
		if (num[from] == 0)continue;
		else {
			num[from]--;
			num[to]++;
			if (possibility[from]) {
				possibility[to] = true;
				if (num[from] == 0)possibility[from] = false;
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < N; i++)ans += possibility[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1536
import sys
from itertools import product


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    s = input().strip().decode()
    ans = 0
    for p in product(range(10), repeat=3):
        matched = 0
        for i in range(n):
            if s[i] == str(p[matched]):
                matched += 1
            if matched == 3:
                ans += 1
                break
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 73244
l = [int(input()) for i in range(5)]
k = int(input())
p = True

for i in range(len(l)):
    for j in range(i+1, len(l)):
        if l[j] - l[i] > k:
            p = False
            break          
if p :
    print("Yay!")
else:
    print(":(")

Measured memory_bytes: 8904
//package BeginnerContest147;

import java.lang.reflect.Array;
import java.util.*;
import java.io.*;

public class Main {
    static class Person{
        ArrayList<Integer> honest;
        ArrayList<Integer> dishonest;
        int i;
        public Person(int i){
            honest = new ArrayList<>();
            dishonest = new ArrayList<>();
            this.i = i;
        }
    }
    public static void main(String[] args) throws IOException {
        FastReader sc = new FastReader();
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        Person[] list = new Person[n];
        for(int i = 0; i<n; i++){
            list[i] = new Person(i);
            int a = sc.nextInt();
            for(int j = 0; j<a; j++){
                int x = sc.nextInt();
                int y = sc.nextInt();
                x--;
                if(y == 0){
                    list[i].dishonest.add(x);
                }
                else{
                    list[i].honest.add(x);
                }
            }
        }
        int max = -1;
        loop : for(int i = 0; i <= (1 << n); i++){
            int count = 0;
            boolean possible = true;
            //System.out.println("hey");
            for(int j = 0; j<n; j++){
                if((i & (1 << j)) > 0){
                    count++;
                    Person p = list[j];
                    for(int k : p.honest){
                        if((i & (1 << k)) == 0){
                            continue loop;
                        }
                    }
                    for(int k : p.dishonest){
                        if((i & (1 << k)) > 0){
                            continue loop;
                        }
                    }
                }
            }
            max = Math.max(count, max);
        }
        if(max == -1)
            max = 0;
        pw.println(max);
        pw.close();
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 36308
// Problem : A - Blackjack
// Contest : AtCoder - AtCoder Beginner Contest 147
// URL : https://atcoder.jp/contests/abc147/tasks/abc147_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c >= 22) cout<<"bust";
    else cout<<"win";
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
  long long N,ans=0;
  while(cin>>N,N){
    ans=0;
  vector<long long> v(N);
  rep(i,N){
    cin>>v[i];
  }
  sort(v.begin(),v.end());
  for(int i=1;i<N-1;i++)ans+=v[i];
  cout<<ans/(N-2)<<endl;
  }
 return 0;
}

Measured memory_bytes: 3072