akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
typedef struct proces {
  char name[10];
  int t;
  int flag;
} P;

P S[100005];
int head, tail, n;

void enqueue(P x) {
  S[tail] = x;
  tail = (tail + 1) % 100005;
}

P dequeue() {
  P x = S[head];
  head = (head + 1) % 100005;
  return x;
}

int min(int x, int y) {
  if (x > y)
    return y;
  else
    return x;
}
int main() {
  int spend = 0, c, i, qp;
  P in;

  scanf("%d %d", &n, &qp);
  for (i = 1; i <= n; i++) {
    scanf("%s", S[i].name);
    scanf("%d", &S[i].t);
    S[i].flag = 1;
  }
  head = 1;
  tail = n + 1;
  while (head != tail) {
    in = dequeue();
    c = min(qp, in.t);
    in.t -= c;
    spend += c;
    if (in.t > 0) {
      enqueue(in);
    } else if (in.flag == 1) {
      printf("%s %d\n", in.name, spend);
      in.flag = 0;
    }
  }
  return 0;
}



Measured memory_bytes: 3716
using System;
using System.Linq;

class B
{
	static void Main()
	{
		var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
		Console.WriteLine(string.Join(" ", Enumerable.Range(a[1] - a[0] + 1, 2 * a[0] - 1)));
	}
}


Measured memory_bytes: 13396
#include<iostream>
using namespace std;
int main(){
 int x,y;
  cin>>x>>y;
  int ans=0;
  if(x==1)
    ans += 300000;
  else if(x==2)
    ans += 200000;
  else if(x==3)
    ans += 100000;
  
    if(y==1)
    ans += 300000;
  else if(y==2)
    ans += 200000;
  else if(y==3)
    ans += 100000;
  
  if(x==1&&y==1){
  ans += 400000;
  }
  cout<<ans;
return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int n,m,l,i,j,k;
    long int sum=0;
    int a[100][100],b[100][100];

    scanf("%d %d %d",&n,&m,&l);
    
    // 格納
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[i][j]);
        }
    }
    for(i=0;i<m;i++){
        for(j=0;j<l;j++){
            scanf("%d",&b[i][j]);
        }
    }

// 計算と出力
    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            for(k=0;k<m;k++){
                sum+=a[i][k]*b[k][j];
            }
            printf("%ld",sum);

            if(j==l-1){ printf("\n"); }
            else{ printf(" "); }
            sum=0;
        }
    }
    return 0;
}




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

int main()
{
       int a, b, i;

       scanf("%d %d", &a, &b);
       if( a < b ) 
              for( i = 1; i <= b; i++ )
              {
                     printf( "%d", a);
              }
       else
              for (i = 1; i <= a; i++)
              {
                     printf("%d", b);
              }
       printf("\n");
       return 0;
}

Measured memory_bytes: 128
import sys
from collections import deque

sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline

N, Q = [int(_) for _ in input().split()]

edges = [[] for _ in range(N + 1)]
for i in range(N - 1):
    a, b = [int(_) for _ in input().split()]
    edges[a].append(b)
    edges[b].append(a)

P = [0] * (N + 1)

for q in range(Q):
    p, x = [int(_) for _ in input().split()]
    P[p] += x

que = deque()
que.append((1, 0))

while que:
    v, parent = que.popleft()
    P[v] += P[parent]
    for next_v in edges[v]:
        if next_v == parent: continue
        que.append((next_v, v))

# def f(v, parent=0):
#     P[v] += P[parent]
#
#     for next_v in edges[v]:
#         if next_v == parent: continue
#         f(next_v, v)
#
#
# f(1)
print(*[P[i] for i in range(1, N + 1)])


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

const int MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define _sort(a) sort(a.begin(), a.end())
#define _sortd(a) sort(a.rbegin(), a.rend())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

int main() {
  int a, b;
  cin >> a >> b;
  p(max(0, a - b * 2));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  while(true){
    int x = N;
    vector<int> v;
    while(x>0){
      v.push_back(x%10);
      x/=10;
    }
    bool ok = true;
    rep(i,v.size()){
      if(v[0] != v[i]) ok = false;
    }
    if(ok){
      cout << N << endl;
      return 0;
    }
    N++;
  }
  
  return 0;
}



Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    int H,W;
    int A,B;
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Read();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        Fact f = new Fact(H+W);
        long count = 0;
        for(int i=0;i<H-A;i++){
            count = (count + (f.GetConv(i+B-1,i) * f.GetConv(H-i+W-B-2,H-i-1) % Define.mod)) % Define.mod;
        }
        sb.Append(count+"\n");
    }
    void Read(){
        string[] str = Console.ReadLine().Split(' ');
        H = int.Parse(str[0]);
        W = int.Parse(str[1]);
        A = int.Parse(str[2]);
        B = int.Parse(str[3]);
    }    
}
class Fact{
    public long[] f;
    public long[] rf;
    public Fact(int N){
        f = new long[N+1];
        rf = new long[N+1];
        for(int i=0;i<N+1;i++){
            if(i == 0){
                f[i] = 1;
            }
            else{
                f[i] = (f[i-1]*i)%Define.mod;
            }
        }
        for(int i=N;i>=0;i--){
            if(i == N){
                rf[i] = pow(f[N],Define.mod-2);
            }
            else{
                rf[i] = rf[i+1]*(i+1)%Define.mod;
            }
        }
    }
    public long pow(long N,long K){
        if(K == 0){
            return 1;
        }
        else if(K % 2 == 0){
            long t = pow(N,K/2);
            return t*t%Define.mod;
        }
        else{
            return N*pow(N,K-1)%Define.mod;
        }
    }
    public long GetFact(int N){
        return f[N];
    }
    public long GetConv(int N,int R){
        return ((f[N]*rf[R])%Define.mod*rf[N-R])%Define.mod;
    }
}
public static class Define{
    public const long mod = 1000000007;
}

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

const int p = 1000000007;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    s%=p;
    if (s<0) s+=p;
    return s;
}

int sub(int a, int b) {
    int s = (a-b);
    s = s%p;
    if (s<0) s+=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

int dp[300000][3];


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

    string s;
    cin>>s;
    int n = s.size();
    if (n==1) {cout<<1; return 0;}
    dp[0][1] = 1;
    dp[0][2] = -1;
    for (int i = 1; i<n; i++)
    {
        dp[i][1] = -1;
        if (s[i-1]!=s[i]) dp[i][1] = max(dp[i][1], 1 + dp[i-1][1]);
        if (dp[i-1][2]!=-1) dp[i][1] = max(dp[i][1], 1 + dp[i-1][2]);
        dp[i][2] = -1;
        if (i==1) {dp[i][2] = 1;
            continue;
        }
        if (dp[i-2][1]!=-1) dp[i][2] = max(dp[i][2], 1 + dp[i-2][1]);
        if (dp[i-2][2]!=-1 && s.substr(i-1, 2)!=s.substr(i-3, 2)) dp[i][2] = max(dp[i][2], 1 + dp[i-2][2]);
    }
    int maxx = 0;
    if (dp[n-1][1]!=-1) maxx = max(maxx, dp[n-1][1]);
    if (dp[n-1][2]!=-1) maxx = max(maxx, dp[n-1][2]);
    cout<<maxx;


}

Measured memory_bytes: 2964
import java.util.Scanner;

class Main{
public static void main(String[] args){
  Scanner sc = new Scanner(System.in);
  String S = sc.next();
  String[] Ssplit = S.split("");
  int ans = 0;
  int ans1 = 0;
  int ans2 = 0;
  int ans3 = 0;
  if(Ssplit[0].equals(Ssplit[1]))
  ans = ans + 1;
  if(Ssplit[0].equals(Ssplit[2]))
  ans = ans + 1;
  if(Ssplit[0].equals(Ssplit[3]))
  ans = ans + 1;
  if(ans != 1)
  System.out.println("No");
  
  if(ans == 1){
  if(Ssplit[1].equals(Ssplit[0]))
  ans1 = ans1 + 1;
  if(Ssplit[1].equals(Ssplit[2]))
  ans1 = ans1 + 1;
  if(Ssplit[1].equals(Ssplit[3]))
  ans1 = ans1 + 1;
  if(ans1 != 1)
  System.out.println("No");
  }
  
  if(ans1 == 1){
  if(Ssplit[2].equals(Ssplit[0]))
  ans2 = ans2 + 1;
  if(Ssplit[2].equals(Ssplit[1]))
  ans2 = ans2 + 1;
  if(Ssplit[2].equals(Ssplit[3]))
  ans2 = ans2 + 1;
  if(ans2 != 1)
  System.out.println("No");
  }

  
  if(ans == 1 & ans1 == 1 & ans2 == 1 )
  System.out.println("Yes");
}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <unordered_set>
#include <random>
using namespace std;
#define ll long long
#define fr first
#define sc second
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N; cin >> N;
	int mp[110000] = { 0 };
	ll sum = 0;
	for (int i = 0; i < N; i++) {
		int a; cin >> a;
		mp[a]++;
		sum += a;
	}

	int Q; cin >> Q;
	for (int i = 0; i < Q; i++) {
		ll a, b; cin >> a >> b;
		if (a == b) continue;
		sum -= a * mp[a];
		sum += b * mp[a];
		mp[b] += mp[a];
		mp[a] = 0;
		cout << sum << '\n';
	}
		
	return 0;
}

Measured memory_bytes: 4024
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
void First(){
    cout << "First" << endl;
    exit(0);
}
void Second(){
    cout << "Second" << endl;
    exit(0);
}
vector<vector<int>>g;
vector<int> DiameterPath() {
    int n = g.size();
    if (n == 1) return vector<int> { 0 };
    //startから最も離れた頂点を求める
    auto farthest = [&](int start) {
        vector<int> depth(n);
        function<void (int, int, int)> get_depth = [&](int u, int prev, int d) {
            depth[u] = d;
            for (auto v : g[u]) if (v != prev) {
                get_depth(v, u, d + 1);
            }
        };
        get_depth(start, -1, 0);
        int maxd = 0;
        int res = 0;
        for (int i = 0; i < n; i ++) {
            if (depth[i] > maxd) {
                maxd = depth[i];
                res = i;
            }
        }
        return res;
    };
    //両端を決める
    int s = farthest(0);
    int t = farthest(s);
    //パスを構築する
    vector<int> diameter_path;
    function<void (int, int, vector<int> &)> construct = [&](int u, int prev, vector<int> &path) {
        if (u == t) {
            diameter_path = path;
            return;
        }
        for (auto v : g[u]) if (v != prev) {
            path.push_back(v);
            construct(v, u, path);
            path.pop_back();
        }
    };
    vector<int> tmp;
    tmp.push_back(s);
    construct(s, -1, tmp);
    return diameter_path;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    g.resize(n);
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    auto d = DiameterPath();
    int k = (int)d.size();
    if(k%3==2){
        Second();
    }else{
        First();
    }
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

template <typename T> bool chmax(T &a, const T b){if(a < b){a = b;return true;}return false;}

vector<ll> bfs(ll top, vector<vector<ll>>& graph)
{
    ll i,j;
    queue<ll> que;
    ll n = graph.size();
    vector<ll> vdis(n,-1);
    vdis.at(top) = 0;
    que.emplace(top);
    while(!que.empty()){
        ll now = que.front();
        que.pop();
        ll dist = vdis.at(now);
        for(i = 0;i < graph.at(now).size();++i){
            ll next = graph.at(now).at(i);
            if(vdis.at(next) == -1){
                vdis.at(next) = dist+1;
                que.emplace(next);
            }
        }
    }
    return vdis;
}

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    vector<vector<ll>> graph(n);
    rep(i,n-1){
        ll a,b;
        cin >> a >> b;
        --a;    --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    vector<ll> v = bfs(0, graph);
    ll p = -1;
    ll num = -1;
    rep(i,n){
        if(chmax(num, v[i])) p = i;
    }
    vector<ll> u = bfs(p, graph);
    ll ans = -1;
    rep(i,n) chmax(ans, u[i]);
    if(ans%3 == 1) cout << "Second" << endl;
    else cout << "First" << endl;

    return 0;
}

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

#define INF (2e9)
#define FOR(i, a, b) for (ll (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)

using namespace std;

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

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

using ll = long long;
using ld = long double;

#define ALL(x) (x).begin(), (x).end()
template<class T>
using vc = vector<T>;
using vi = vc<ll>;
using vvi = vc<vi>;

template<class T>
using va = valarray<T>;
using vad = va<ld>;
using vai = va<ll>;

vi Read(ll n) {
    auto      v = vi(n);
    for (auto i = std::size_t(0); i < n; ++i) {
        cin >> v[i];
    }
    return v;
}

template<class T>
void Dump(const T& A) {
    for (const auto& value : A)
        cout << value << "\n";
}

int main() {
    ll n, p;
    cin >> n >> p;

    auto v = vvi(n, vi());

    REP(i, p) {
        int query, t;
        cin >> query >> t;

        if (query == 0) {
            int x;
            cin >> x;
            v[t].push_back(x);
        } else if (query == 1) {
            if (v[t].empty()) cout << endl;
            else {
                REP(j, int(v[t].size() - 1)) cout << v[t][j] << " ";
                cout << v[t][v[t].size() - 1] << endl;
            }
        } else if (query == 2) {
            if (!v[t].empty()) v[t].clear();
        } else cout << "Error: query is not correct\n";
    }

    return 0;
}



Measured memory_bytes: 8756
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <set>
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    int N;
    cin >> N;
    vector<LL> a(N, 0);
    REP(i,N){cin >> a[i];}

    LL a_all = a[0];
    FOR(i,1,N){
        a_all ^= a[i];
    }

    REP(i,N){
        LL ans = a_all ^ a[i];
        cout << ans << " ";  
    }

    return 0;
}

Measured memory_bytes: 4688
#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
const long long LINF=1e18;
using namespace std;
#define int long long
#define fin {cout<<-1<<endl;return 0;}
//template
int pw(int n,int k){
  int res=1;
  while(k){
    if(k&1)res*=n;res%=MOD;
    n*=n;n%=MOD;
    k>>=1;
  }
  return res;
}
//main
signed main(){
  int M,K;cin>>M>>K;
  if(K>=pw(2,M))fin
  if(M==1){
    if(K==0)cout<<"0 0 1 1"<<endl;
    else fin
    return 0;
  }
  for(int i=pw(2,M)-1;i>=0;i--)if(i!=K)cout<<i<<" ";
  cout<<K<<" ";
  for(int i=0;i<=pw(2,M)-1;i++)if(i!=K)cout<<i<<" ";
  cout<<K<<endl;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();
    char[][] C = new char[H][W];
    for (int i = 0; i < H; i++) {
      C[i] = sc.next().toCharArray();
    }
    for (int i = 0; i < H; i++) {
      System.out.println(C[i]);
      System.out.println(C[i]);
    }
  }
}

Measured memory_bytes: 23940
#include <bits/stdc++.h>
#include<unordered_map>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 50
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
ll ans = 0;
int main() {
	string s, res;
	cin >> s >> K;
	vector<vector<int>>ch(26);
	for (int i = 0; i < s.size(); i++) {
		ch[s[i] - 'a'].push_back(i);
	}
	string ANS;
	for (int i = 0; i < 26; i++) {
		if (ch[i].size() == 0)continue;
		set<string>set;
		vector<string>res;
		string x = { char(i + 'a') };
		res.push_back(x);
		for (int k : ch[i]) {
			for (int j = 2; j < 6; j++) {
				if (k + j > s.size())continue;
				string tmp = s.substr(k, j);
				if (set.count(tmp) == 0) {
					set.insert(tmp);
					res.push_back(tmp);
				}
			}
		}
		if (res.size() < K)K -= res.size();
		else {
			sort(res.begin(), res.end());
			ANS = res[K - 1];
			break;
		}
	}
	cout << ANS << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
int main (){
int n;
int g;
  scanf("%d",&n);

if(n>=64)g=64;
else if(n>=32)g=32;
else if(n>=16)g=16;
else if(n>=8)g=8;
else if(n>=4)g=4;
else if(n>=2)g=2;
else g=1;
printf("%d\n",g);
return 0;
}

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

int main() {
    int N;
    cin >> N;
    
    vector<int> t(N+1), x(N+1), y(N+1);
    t[0] = 0;
    x[0] = 0;
    y[0] = 0;
    
    for (int i=1; i<N+1; i++) {
        cin >> t[i] >> x[i] >> y[i];
    }
    
    int d_min;
    
    for (int i=0; i<N; i++) {
        d_min = abs(x[i] - x[i+1]) + abs(y[i] - y[i+1]);
        if (d_min > t[i+1] - t[i]) {
            cout << "No" << endl;
            return 0;
        } else if ((t[i+1] - t[i] - d_min) % 2 != 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
        
}

Measured memory_bytes: 1408
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    # too slow
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def get_all_members(self):
        pare_d = {}
        for i in range(self.n):
            parent = self.find(i)
            pare_d.setdefault(parent,[])
            pare_d[parent].append(i)
        return list(pare_d.values())

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n,m = map(int, input().split())
uf = UnionFind(n)

for _ in range(m):
    a,b = map(int, input().split())
    a-=1
    b-=1
    uf.union(a,b)

cnt = uf.group_count()
ans = max(cnt-1,0)
print(ans)

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

int main()
{
    ll n, m, k;
    cin >> n >> m;
    rep(i, n)
    {
        rep(j, n - i)
        {
            k = n - i - j;
            if (m == i * 10000 + j * 5000 + k * 1000)
            {
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
}


Measured memory_bytes: 3580
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>

#pragma region 定義
#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin4(X,Y,Z,W) scanf("%d %d %d %d",&X,&Y,&Z,&W)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define f_cin(X) scanf("%f",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)

#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)

typedef long long  ll;
#define rept(x, s, n) for (int x = s; x < n; x++)

#define S_RTN(S)  s_cout(S);return 0


#define _itoa(A,N) sprintf(A, "%d", N);

int i_cins(int n, int* A);
int l_cins2(int n, long* A, long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);


int s_asorts(const void* a, const void* b);

//昇順
int s_asorts(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int s_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}
int l_cins2(int n, long* a, long* b) {
	int i;
	rept(i, 0, n) {
		l_cin2(*(a + i), *(b + i));
	}
	return 0;
}
int i_cins(int n, int* a) {
	int i;
	for (i = 0; i < n; i++) {
		i_cin(*(a + i));
	}

	return 0;
}
int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}

long _max(long a, long b) {
	return a > b ? a : b;
}
long _min(long a, long b) {
	return a < b ? a : b;
}
int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}
#pragma endregion

int main(void)
{
	int  i, cnt = 0;
	int  x,a[101],n;

	scanf("%d%d",&n,&x);

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

	qsort(a,n,sizeof(int),s_asort);
	
	for (i = 0; i < n; i++) {
		cnt++;
		x -= a[i];
		if (x <= 0)break;
	}

	(x) ? printf("%d\n",cnt-1) : printf("%d\n",cnt);
	
	return 0;
}



Measured memory_bytes: 1724
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ave = (int) Math.ceil((double) (a + b) / (double) 2);
		System.out.println(ave);
		sc.close();
	}
}

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

typedef long long ll;
const int maxn = 1e5 + 10;
int n;
ll sum, a[maxn], b[maxn], c[maxn], _count[maxn];

int main() {
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++) {
        cin >> b[i];
    }
    for (int i = 1; i <= n; i++) {
        cin >> c[i];
    }
    sort(a + 1, a + n + 1);
    sort(b + 1, b + n + 1);
    sort(c + 1, c + n + 1);
    for (int i = n; i >= 1; i--) {
        _count[i] = _count[i + 1];
        _count[i] += n - (upper_bound(c + 1, c + n + 1, b[i]) - c) + 1;
    }
    for (int i = 1; i <= n; i++) {
        sum += _count[upper_bound(b + 1, b + n + 1, a[i]) - b];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int x[100010];
vector<int> co;
int ans = 0;
int main(){
	int m, n;
	cin >> m >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	sort(x, x + n);
	for (int j = 0; j < n - 1; j++) {
		co.emplace_back(x[j + 1] - x[j]);
	}
	sort(co.begin(), co.end());
	for(int k = 0; k < n - m; k++) {
		ans += co[k];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1276
N, M = [int(_) for _ in input().split()]
A = [list(input()) for i in range(N)]
B = [list(input()) for i in range(M)]

for i in range(N-M+1):
    for j in range(N-M+1):
        flag = True
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            print('Yes')
            exit()

print('No')

Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
#define rep(i,a,n) for(int i=a;i<n;i++)
int main(){
	int table[182],ret,n;
	for(int i=0;i<182;i++)table[i]=i*i;
	while(scanf("%d",&n),n){
		ret=0;
		rep(i,0,182)rep(j,i,182)rep(k,j,182)
			if(std::binary_search(table+k,table+182,n-table[i]-table[j]-table[k]))ret++;
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 756
#include <bits/stdc++.h>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define all(v)   v.begin(), v.end()
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define START cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define isOdd(n)    (n&1)
#define LLMAX LLONG_MAX
#define LLMIN LLONG_MIN
#define IMN INT_MIN
#define IMX INT_MAX
#define pow(n, m) power((ll)n, (ll)m)
#define numOfDigits(n)  ((n)? (ll)(log10(n))+1 : 1)
#define mem(x, val)    memset(x, val, sizeof(x)) //be careful
#define sz(x)          (int) x.size()
#define MOD 1000000007
#define EPS 1e-7

typedef long long ll;
typedef long double ld;
typedef double dd;
typedef pair<int, int> pii;

int main()
{
    START
    //freopen("test cases\\in.txt", "r", stdin) ;
    int k, a, b; cin>>k>>a>>b;
    for(int i= a; i<=b; i++)
        if(i%k==0)return cout<<"OK", 0;
    cout<<"NG";
	return 0;
}


Measured memory_bytes: 3608
#include<stdio.h>
int main(){
	int a[100],n,i,p=0,q=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&a[i]);
	for(i=0;i<n;i++){
		if(a[i]==1){
			++p;
			if(q<p)q=p;
		}
		else{
			if(q<p)q=p;
			p=0;
		}
	}
	printf("%d\n",q+1);
	return 0;
}


Measured memory_bytes: 2060
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ll    long long
#define PR    pair<ll, ll>

const int N = 3e5 + 5;
const int MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int maxn = 15;

int cost[maxn], skill[maxn][maxn];

int main() {
//    ios::sync_with_stdio(false);
//    cin.tie(0);
    int n, m, x;
    cin >> n >> m >> x;
    for (int i = 0; i < n; i++) {
        cin >> cost[i];
        for (int j = 0; j < m; j++) {
            cin >> skill[i][j];
        }
    }
    int ans = 1e9;
    for (int mask = 0; mask < (1 << n); mask++) {
        int tmp = 0;
        map<int, int> mob;
        for (int i = 0; i < n; i++) {
            if (mask & (1 << i)) {
                tmp += cost[i];
                for (int j = 0; j < m; j++) {
                    mob[j] += skill[i][j];
                }
            }
        }
        int ok = 1;
        for (int i = 0; i < m; i++) {
            if (mob[i] < x) {
                ok = 0;
                break;
            }
        }
        if (ok) {
            ans = min(ans, tmp);
        }
    }
    if (ans == 1e9) {
        ans = -1;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3604
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define repf(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define repfr(i, x, n) for (int i = (int)(x)-1; i >= (int)(n); i--)
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> inline void in(T &a) { cin >> a; }
template <class T, class U> inline void in(T &a, U &b) { cin >> a >> b; }
template <class T, class U, class V> inline void in(T &a, U &b, V &c) {
  cin >> a >> b >> c;
}
template <class T> inline void out(T a) { std::cout << a << endl; }
template <class T, class U> inline void out(T a, U b) {
  cout << a << ' ' << b << endl;
}
template <class T, class U, class V> inline void out(T a, U b, V c) {
  cout << a << ' ' << b << ' ' << c << endl;
}
#define inf 1e9
using ll = int64_t;

void Main() {
  char c[2][3];
  rep(i, 2) {
    rep(j, 3) { in(c[i][j]); }
  }

  out((c[0][0] == c[1][2] && c[1][0] == c[0][2] && c[1][1] == c[0][1] ? "YES"
                                                                      : "NO"));

  return;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
using ll = long long;
template <class T> using vec = vector<T>;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vvvi = vector<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval>newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!
int count(vi &h, int i){
  int c = 0;
  bool p = false;
  int res = 0;
  for(auto hj : h){
    if(hj>=i && !p) res++;
    p = (hj>=i);
  }
  dump(h,i,res);
  return res;
}
// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  int n = in();
  vi h(n); rep(i,n) cin>>h[i];
  int m = 0;
  rep(i,n) m = max(m,h[i]);
  int ans = 0;
  rep(i,m){
    ans += count(h,i+1);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
class test
{
  public static void Main(string[] args)
  {
    long n = long.Parse(Console.ReadLine());
    if(n%10==3)
      Console.WriteLine("bon");
    else if(n%10==0||n%10==1||n%10==6||n%10==8)
      Console.WriteLine("pon");
    else
      Console.WriteLine("hon");
  }
}

Measured memory_bytes: 27548
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;



int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 1; i <= n; i++){
		cin >> a[i-1];
		a[i-1] -= i;
	}
	sort(a.begin(), a.end());
	ll mid = a[(n-1)/2], ans = 0; 
	for (int i = 0; i < n; i++){
		ans += abs(a[i] - mid);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

#define MOD 998244353

long long myPow(long long n,long long k)
{
	long long ans=1;
	while(k)
	{
		if(k&1)ans*=n;
		n*=n;
		k/=2;
		ans%=MOD;
		n%=MOD;
	}
	return ans;
}

int main()
{

	long long n;
	cin >> n;
	vector<long long> d(n);
	for(long long i=0;i<n;i++)
		cin >> d[i];
	
	if(d[0]!=0)
	{
		cout << 0 << endl;
		return 0;
	}
	
	sort(d.begin(),d.end());

	vector<long long> x(d[n-1]+1,0);

	for(long long i=0;i<n;i++)
	{
		x[d[i]]++;
	}

	if(x[0]!=1)
	{
		cout << 0 << endl;
		return 0;
	}
	

	long long ans=1;

	for(long long i=1;i<x.size();i++)
	{
		if(x[i]==0)
		{
			ans=0;
			break;
		}
		ans*=myPow(x[i-1],x[i]);
		ans%=MOD;
	}
	
	cout << ans%MOD << endl;



}


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

long long guusuuDP(long long N,long long num[])
{
	long long ma[N][2];
	ma[1][0] = num[0];
	ma[1][1] = num[1];
	int i;
	for(i=1;i<=(N/2-1);i++)
	{
		ma[2*i+1][0] = ma[2*i-1][0] + num[2*i];
		ma[2*i+1][1] = max((ma[2*i-1][0]),(ma[2*i-1][1]))
		+ num[2*i+1];
	}
	return max(ma[N-1][0],ma[N-1][1]);
}
long long kisuuDP(long long N,long long num[])
{
	long long ma[N][2];
	ma[2][0] = max(num[0],num[1]);
	ma[2][1] = num[2];
	long long i;
	long long sum[(N+1)/2];
	sum[0] = num[0];
	for(i=1;i<=(N-1)/2;i++)
	{
		sum[i] = sum[i-1] + num[2*i];
	}
	for(i=2;i<=(N-1)/2;i++)
	{
		ma[2*i][1] = max(ma[2*i-2][0],ma[2*i-2][1])
		+ num[2*i];
		ma[2*i][0] = max(sum[i-1],ma[2*i-2][0]+num[2*i-1]);
	}
	return max(ma[N-1][0],ma[N-1][1]);
}
int main()
{
	long long N;
	cin >> N;
	long long num[N];
	long long i;
	for(i=0;i<N;i++)
	{
		cin >> num[i];
	}
	if(N % 2 == 0) cout << guusuuDP(N,num) << endl;
	else if(N % 2 == 1) cout << kisuuDP(N,num) << endl;
	return 0;
}


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

signed main() {

    int n, h[32], ans = 1;
    scanf("%d", &n);
    for ( int i = 0; i < n; i++ ) scanf("%d", &h[i]);
    for ( int i = 1; i < n; i++ ) {
        bool flg = true;
        for ( int j = 0; j < i; j++ ) {
            flg &= h[j] <= h[i];
        }
        ans += flg;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
#define S 1000000
typedef struct{char n[10];int t;}QUE;QUE que[S];main(){int i=0,T=0,h=0,t,n,q;scanf("%d %d",&n,&q);for(t=n;i<n;)scanf("%s %d",que[i++].n,&que[i].t);while(h!=t){i=que[h].t<=q||t-h==1;T+=i?que[h].t:q;if(i)printf("%s %d\n",que[h].n,T);else{que[h].t-=q;que[t]=que[h];t=S==t+1?0:t+1;}h=S==h+1?0:h+1;}}


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

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    vector<int> V, C;
    V.resize(N);
    C.resize(N);
    for (int i = 0; i < N; i++)
    {
        cin >> V[i];
    }
    for (int i = 0; i < N; i++)
    {
        cin >> C[i];
    }

    vector<int> d;
    d.resize(N);
    int sum = 0;
    for (int i = 0; i < N; i++)
    {
        d[i] = V[i] - C[i];
        if (d[i] > 0)
        {
            sum += d[i];
        }
        
    }
    
    cout << sum << 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)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

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

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 45;
const int mod = 1000000007;
//const int mod = 10007;

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n+1, 0);
  rep(i, n) cin >> a[i+1];
  rep(i, n) a[i+1] += a[i];
  rep(i, n+1) a[i] = (a[i]-i)%k;

  map<ll, ll> m;
  for(int i = 1; i < min(n+1, k); ++i) {
    if(m.find(a[i]) == m.end()) m[a[i]] = 0;
    ++m[a[i]];
  }
  ll ans = 0;
  for(int i = 0; i < n; ++i) {
    if(m.find(a[i]) != m.end()) {
      ans += m[a[i]];
    }
    --m[a[i+1]];
    if(i+k <= n) {
      if(m.find(a[i+k]) == m.end()) m[a[i+k]] = 0;
      ++m[a[i+k]];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 14336
/*
THINGS TO DO
1) Check integer overflows
2) Check corner cases
3) Compile and run once on terminal
4) Code smart, not quick
*/

#ifndef ONLINE_JUDGE
	#define _GLIBCXX_DEBUG
	#include "debug.cpp"
#endif

#include <bits/stdc++.h>
using namespace std;

int ans[1005][1005];
int visited[1005][1005];
int h, w;

int ok(int curx, int cury){
	if(curx >= 0 && curx < h && cury >= 0 && cury < w)
		return 1;
	return 0;
}

void bfs(int x, int y, string mat[]){
	int i, j;
	deque<vector<int>> dq;
	dq.push_back({x, y, 0});
	ans[x][y] = 0;
	while(dq.size() != 0){
		vector<int> front = dq.front();
		int curx = front[0], cury = front[1];
		dq.pop_front();
		visited[curx][cury] = 1;
		// debug(curx, cury, front[2]);

		for(i=curx-2; i<=curx+2; i++){
			for(j=cury-2; j<=cury+2; j++){
				if(ok(i, j) == 1 && mat[i][j] == '.'){
					if(abs(curx - i) + abs(cury - j) == 1){
						ans[i][j] = min(ans[i][j], front[2]);
						if(visited[i][j] == 0)
							dq.push_front({i, j, front[2]});
					}
					else{
						ans[i][j] = min(front[2] + 1, ans[i][j]);
						if(visited[i][j] == 0)
							dq.push_back({i, j, front[2]+1});
					}
				}
			}
		}

	}
}


int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int i, j, ch, cw, dh, dw;
	cin >> h >> w;
	cin >> ch >> cw;
	cin >> dh >> dw;
	ch--; cw--; dh--; dw--;

	for(i=0; i<h; i++){
		for(j=0; j<w; j++){
			ans[i][j] = 9999999;
		}
	}

	string mat[h];
	for(i=0; i<h; i++)
		cin >> mat[i];

	bfs(ch, cw, mat);

	// for(i=0; i<h; i++){
	// 	for(j=0; j<w; j++)
	// 		cout << ans[i][j] << " ";
	// 	cout << "\n";
	// }

	if(ans[dh][dw] == 9999999)
		cout << "-1\n";
	else
		cout << ans[dh][dw] << "\n";

}

//Read the stuff at the top

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

typedef long long ll;
const int mod = 1e9 + 7;

ll N, K;
vector<ll> H;

int main() {
    cin >> N >> K;
    H.resize(N);

    rep(i, N) cin >> H[i];

    if (N <= K) {
        cout << 0 << endl;
        return 0;
    } 

    sort(H.begin(), H.end());

    cout << accumulate(H.begin(), H.begin() + N - K, 0LL) << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;cin>>s;
    int f=10*(s[0]-48)+(s[1]-48);
    int l=10*(s[2]-48)+(s[3]-48);
    if(f>0 and f<13 and l>0 and l<13)cout<<"AMBIGUOUS";
    else if(f>0 and f<13 and l>=0 and l<100)cout<<"MMYY";
    else if(l>0 and l<13 and f>=0 and f<100)cout<<"YYMM";
    else cout<<"NA";
}


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

using namespace std;

typedef long long ll;
const ll INF = 1e18;

ll dp[65][35][3];
int main() {
	int w, h;
	int dx[9] = { 1,1,2,1,2,3,1,2,1 }, dy[9] = { -2,-1,-1,0,0,0,1,1,2 };
	char s[65][35];
	while (1) {
		cin >> w >> h;
		if (w == 0 && h == 0) break;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> s[i][j];
			}
		}
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				for (int k = 0; k < 2; k++) {
					dp[i][j][k] = INF;
				}
			}
		}
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (s[i][j] == 'S') {
					dp[i][j][0] = dp[i][j][1] = 0LL;
				}
			}
		}
		auto isOutOfRange = [] (int x, int y, int h, int w){
			return x < 0 || x >= w || y < 0 || y >= h;
		};
		auto cost = [&](int x, int y) {
			if (s[y][x] == 'X') return INF;
			if (s[y][x] == 'S') return INF;
			if (s[y][x] == 'T') return 0LL;
			return (ll)s[y][x] - '0';
		};
		while(1){
			bool f = false;
			for (int y = 0; y < h; y++) {
				for (int x = 0; x < w; x++) {
					for (int now = 0; now < 2; now++) {
						if (dp[y][x][now] == INF) continue;
						for (int i = 0; i < 9; i++) {
							int nx = x + (now==0?dx[i]:-dx[i]), ny = y + dy[i], nxt = (now + 1) % 2;
							if (isOutOfRange(nx, ny, h, w) || s[ny][nx] == 'X') continue;
							//dp[ny][nx][nxt] = min(dp[ny][nx][nxt], dp[y][x][now] + cost(nx, ny));
							if (dp[ny][nx][nxt] > dp[y][x][now] + cost(nx, ny)) {
								dp[ny][nx][nxt] = dp[y][x][now] + cost(nx, ny);
									f = true;
							}
						}
					}
				}
			}
			if (f == false) break;
		}
		/*for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cout << "(" << (dp[i][j][0]==INF?-1:dp[i][j][0]) << ", " << (dp[i][j][1]==INF?-1:dp[i][j][1])<< ")";
			}
			cout << endl;
		}*/

		ll ans = INF;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (s[i][j] != 'T') continue;
				ans = min({ ans, dp[i][j][0], dp[i][j][1] });
			}
		}
		if (ans == INF) cout << -1 << endl;
		else cout << ans << endl;
	}
}

Measured memory_bytes: 3108
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;

int main(){
    int n;
    cin >> n;
    int s[n], p[n];
    int a[n];
    vector<pair<pair<string, int> , int> > info;
    vector<string> str;

    for(int i = 0; i < n; i++){
        a[i] = 0;
        string s;
        int p;
        cin >> s >> p;
        str.push_back(s);
        info.push_back(make_pair(make_pair(s, p), i+1));
    }

    sort(info.begin(), info.end());
    //sort(info.begin(), info.end());


    for(int i = 0; i < n; i++){
        size_t size;
        size = count(str.begin(), str.end(), info[i].first.first);
    }
    //str.erase(unique(str.begin(), str.end()), str.end());
    size_t size;
    for(int i = 0; i < n; i+=size){
        size = count(str.begin(), str.end(), info[i].first.first);
        for(int j = i+size-1; j > i-1; j--){
            //cout << "j" << j << endl;
            cout << info[j].second << endl;
        }
        //cout << info[i].second << endl;
    }
    

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int  long long int
#define fi first
#define se second
#define pb push_back
#define soo(v) sort(v.rbegin(),v.rend())
#define so(v) sort(v.begin(),v.end())
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define endl '\n'
#define dbv(v) cout<<endl;cout<<#v<<"-->> ";for(auto it:v){cout<<it<<" ";}cout<<endl;
#define dbm(m)cout<<endl;cout<<#m<<"-->> ";for(auto it:m){cout<<it.fi<<" "<<it.se.fi<<" "<<it.se.se<<endl;}
#define dbs(s)cout<<endl;cout<<#s<<"-->> ";for(auto it:s){cout<<it<<" ";}cout<<endl;
#define mod 1000000007
#define db1(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl;
#define mx 1e18
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v)  *min_element(v.begin(),v.end())
#define double long double
int powe(int x,int n)
{
  if(n==0)return 1;
  if(n%2==0)
    return powe((x%mod*x%mod)%mod,n/2)%mod;
  return (x%mod*powe((x%mod*x%mod)%mod,(n-1)/2))%mod;
}
int gcd(int A,int B)
{
  if(B==0)return A;
  return gcd(B,A%B);
}
#define io std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define re(s) reverse(s.begin(),s.end())
int32_t main()
{
    io
int a;
cin>>a;
cout<<a*(1+a+a*a)<<endl;
}

Measured memory_bytes: 3556
program reconciled;
uses math;
const
  md: int64 = 1000000007;
  xx: int64 = 765302181;
var
  n, m, x, i: int64;
begin
  read(n, m);
  if abs(n-m) > 1 then
  begin
    writeln(0);
    halt(0);
  end;
  if min(n, m) < 50000 then
  begin
    x := ifthen(n = m, 2, 1);
    for i := 1 to min(n, m) do
      x := ((i*i mod md)*x mod md);
    for i := min(n, m)+1 to max(n, m) do
      x := (i*x mod md);
    writeln(x);
    halt(0);
  end;
  x := xx*ifthen(n = m, 2, 1) mod md;
  for i := 50001 to min(n, m) do
    x := ((i*i mod md)*x mod md);
  for i := min(n, m)+1 to max(n, m) do
    x := (i*x mod md);
  writeln(x);
end.

Measured memory_bytes: 128
import sys
input = sys.stdin.readline

import itertools

# 初日以外は何も気にせず動けるとしてよい。初日に到達可能な場所のうち、最もゴールに近いものはどこか

H,W,K = map(int,input().split())
A = '#' * (W+2)
for _ in range(H):
    A += '#' + input().rstrip() + '#'
A += '#' * (W+2)

start = A.find('S')
dxs = (1,-1,(W+2),-(W+2))

visited = set()
q = [start]
visited.add(start)
for _ in range(K):
    qq = []
    for dx,x in itertools.product(dxs,q):
        y = x+dx
        if A[y] == '#':
            continue
        if y in visited:
            continue
        visited.add(y)
        qq.append(y)
    q = qq

nearest = 10**9
for x in visited:
    row,col = divmod(x,W+2)
    d = min(row-1,H-row,col-1,W-col)
    if nearest > d:
        nearest = d

answer = 1 + (nearest+K-1)//K
print(answer)

Measured memory_bytes: 40112