akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int a,b,c; cin >> a >> b >> c;
  if(a == b && a != c)
    cout << "Yes" << endl;
  else if(a == c && a != b)
    cout << "Yes" << endl;
  else if(b == c && b != a)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3604
#include<stdio.h>

#define N_MAX 20000000
#define k 10005


int A[N_MAX];
int B[N_MAX];
int C[k];
int n;

int main()
{
  int i, j;
  
  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d", &A[i]);
  }

  for(i=0; i<k; i++){
    C[i] = 0;
  }
  
  for(j=0; j<=n; j++){
    C[A[j]]++;
  }
  
  for(i=0; i<k; i++){
    if(i==0)
      continue;
    C[i] =C[i] +  C[i-1];
    // printf("C[%d] = %d\n", i, C[i]);
  }
  
  for(j=n-1; j>=0; j--){
    B[C[A[j]]-1] = A[j];
    //    printf("B[%d] = %d\n",C[A[j]], B[C[A[j]]]);
    C[A[j]]--;
  }



  for(i=1; i<=n; i++){
    printf("%d", B[i]);
    
    if(i!=n)
      printf(" ");
    else
      printf("\n");
  }

  return 0;
}

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

int main(){
  int n,l,log,sum=0,minnum=1000;
  cin>>n>>l;
  vector<int> num(n);
  for(int i=0;i<n;i++){
    num[i]=l+i;
    sum+=num[i];
  }
  for(int i=0;i<n;i++){
    int sum2=0;
    for(int j=0;j<n;j++){
      if(j==i) continue;
      sum2+=num[j];
    }
    if(minnum>abs(sum2-sum)){
      minnum=abs(sum2-sum);
      log=sum2;
    }
  }
  cout<<log<<endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N),B(N),C(N-1);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  for(int i=0;i<N;i++){
    cin >> B.at(i);
  }
  for(int i=0;i<N-1;i++){
    cin >> C.at(i);
  }
  int ans=0;
  for(int i=0;i<N;i++){
    ans+=B.at(A.at(i)-1);
    if(i!=0 && A.at(i)==A.at(i-1)+1){
      ans+=C.at(A.at(i-1)-1);
    }
  }
  cout << ans << endl;
}
      
      
    


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

#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr);
#define pb push_back
#define ll long long
#define fi first
#define se second
#define maxn 3001

const int mod = 1e9+7 ;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;

double dp[maxn][maxn][2], a[maxn];

signed main()
{
//	freopen(".inp","r",stdin);
//	freopen(".out","w",stdout);
	int n;	cin >> n;
	for (int i = 1; i <= n; i++)	cin >> a[i];
	dp[1][1][1] = a[1];
	dp[1][0][0] = 1 - a[1];
	for (int i = 2; i <= n; i++)
	{
		dp[i][0][0] = dp[i-1][0][0] * (1 - a[i]);
		for (int j = 1; j <= i; j++)
		{
			dp[i][j][0] += (dp[i-1][j][0] + dp[i-1][j][1]) * (1 - a[i]);
			dp[i][j][1] += (dp[i-1][j-1][0] + dp[i-1][j-1][1]) * a[i];
		}
	}
	double ans = 0;
	for (int i = n/2+1; i <= n; i++)
	{
		ans += (dp[n][i][0] + dp[n][i][1]);
	}
	cout << setprecision(10) << fixed << ans;
}




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


int main (){
    int N, M, X, Y;
    cin>>N>>M>>X>>Y;
    vector<int> CityX(N), CityY(M);
    int MaxX=-200;
    int MinY=200;
    for(int i=0; i<N; i++){
        cin>>CityX.at(i);
        MaxX=max(MaxX, CityX.at(i));
    }
    for(int i=0; i<M; i++){
        cin>>CityY.at(i);
        MinY=min(MinY, CityY.at(i));
    }
    if(MinY>MaxX&&X<MinY&&Y>MaxX){
        cout<<"No War"<<endl;
    }
    else{
        cout<<"War"<<endl;
    }
    
}

Measured memory_bytes: 256
import heapq
def dijkstra(G, s):
    dist = [float("inf")]*len(G)
    q = []
    dist[s] = 0
    heapq.heapify(q)
    heapq.heappush(q, [0, s])
    while 0 < len(q):
        pre_cost, p = heapq.heappop(q)
        if dist[p] < pre_cost:
            continue
        for v, d in G[p]:
            if dist[v] > dist[p] + d:
                dist[v] = dist[p] + d
                heapq.heappush(q, [dist[v], v])
    return dist
import sys
input = sys.stdin.readline
def main():
    n, m, s, t = map(int, input().split())
    s, t = s-1, t-1
    G_y = [[] for _ in range(n)]
    G_s = [[] for _ in range(n)]
    f = [True]*n
    for _ in range(m):
        u, v, a, b = map(int, input().split())
        u, v = u-1, v-1
        G_y[u].append([v, a])
        G_y[v].append([u, a])
        G_s[u].append([v, b])
        G_s[v].append([u, b])
    cost_y = dijkstra(G_y, s)
    cost_s = dijkstra(G_s, t)
    cost = [[cost_y[i] + cost_s[i], i] for i in range(n)]
    cost.sort()
    x = 0
    for i in range(n):
        while not f[cost[x][1]]:
            x += 1
        print(10**15 - cost[x][0])
        f[i] = False

if __name__ == "__main__":
    main()


Measured memory_bytes: 106624
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun nextPermutation(array: MutableList<Int>): Boolean {
    var tmp = 0
    for (i in array.size-2 downTo 0) {
        if (array[i] < array[i+1]) {
            for (j in array.size-1 downTo i+1) {
                if (array[j] > array[i]) {
                    tmp = array[i]
                    array[i] = array[j]
                    array[j] = tmp

                    val tmpArray = array.takeLast(array.size-(i+1)).sorted()
                    tmpArray.forEachIndexed { index, e ->
                        array[i+1+index] = e
                    }

                    return true
                }
            }
        }
    }

    return false
}

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val m = sc.nextInt()
    val R = sc.nextInt()
    val r = Array(R) { sc.nextInt() - 1 }
    val a = Array(m) { 0 }
    val b = Array(m) { 0 }
    val c = Array(m) { 0 }
    for (i in 0 until m) {
        a[i] = sc.nextInt() - 1
        b[i] = sc.nextInt() - 1
        c[i] = sc.nextInt()
    }
    val p = r.sorted().toMutableList()
    val inf = 10000000000000000L
    val dist = Array(n) { Array(n) { inf } }
    for (i in 0 until m) {
        dist[a[i]][b[i]] = c[i].toLong()
        dist[b[i]][a[i]] = c[i].toLong()
    }
    for (k in 0 until n) {
        for (i in 0 until n) {
            for (j in 0 until n) {
                dist[i][j] = Math.min(dist[i][j], dist[i][k] + dist[k][j])
            }
        }
    }
    var min = inf
    do {
        var sum = 0L
        for (i in 1 until R) {
            sum += dist[p[i]][p[i - 1]]
        }
        min = Math.min(min, sum)
    } while (nextPermutation(p))
    println(min)
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 111388
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>

using namespace std;
typedef long long ll;

int main() {
  ll n, k;
  cin >> n >> k;
  
  vector<pair<ll,ll>> vec(n);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    vec[i] = {b, a};
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  set<ll> s;
  ll sum = 0;
  vector<ll> r;
  for (int i = 0; i < k; i++) {
    sum += vec[i].first;
    if (s.count(vec[i].second) == 0) {
      s.insert(vec[i].second);
    } else {
      r.push_back(vec[i].first);
    }
  }
  sum += s.size() * s.size();
  
  ll ans = sum;
  for (ll i = k; i < n; i++) {
    if (s.count(vec[i].second) == 0 && r.size() > 0) {
      sum -= r.back();
      sum -= s.size() * s.size();
      r.pop_back();
      
      sum += vec[i].first;
      s.insert(vec[i].second);
      sum += s.size() * s.size();
      ans = max(ans, sum);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5116
import java.util.Scanner;

/**
 * Knapsack 1
 */
public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int W = sc.nextInt();

            long[][] dp = new long[N + 1][W + 1];

            for (int i = 1; i <= N; i++) {
                int w = sc.nextInt();
                int v = sc.nextInt();

                for (int j = 1; j <= W; j++) {
                    if (j < w) {
                        dp[i][j] = dp[i - 1][j];
                    } else {
                        dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - w] + v);
                    }
                }
            }

            System.out.println(dp[N][W]);
        }
    }

}


Measured memory_bytes: 125524
#include <stdio.h>

int main(void)
{
  int n;
  double result;
  int i=0;
 
  scanf("%d",&n);
  result = 1.0;
  for(i = n ; i > 0 ; i--)
    {
      result *= i;
    }
  printf("%.0f\n",result);
  return 0;
}

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

ll gcd(ll x, ll y) {
    if (y == 0) return x;
    return gcd(y, x % y);
}

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> towns(n);
    for (int i = 0; i < n; ++i) cin >> towns[i];
    towns.emplace_back(x);
    sort(towns.begin(), towns.end());
    int ans = towns[1] - towns[0];
    for (int j = 1; j < n; ++j) ans = gcd(ans, towns[j + 1] - towns[j]);
    cout << ans << endl;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;

namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            int N = int.Parse(ReadLine());

            long[] An = ReadLine().Split(' ').Select(long.Parse).ToArray();
            var ls = new List<long>();
            ls.AddRange(An);
            int tmp = 0;
            for (int i = 0; i < N; i++)
            {
                if (ls[i] < 0)
                {
                    tmp++;
                }
            }

            long ans = 0;long AbsMin = long.MaxValue;
            for (int i = 0; i < N; i++)
            {
                long s = Abs(ls[i]);
                ans += s;
                if (s<AbsMin)
                {
                    AbsMin = s;
                }
            }

            if (tmp % 2 == 0)
            {
                WriteLine(ans);
            }
            else
            {
                WriteLine(ans - (AbsMin*2));
            }

        }

    }
}


Measured memory_bytes: 32092
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a;
    int b,c,d;
    cin >> a;
    b = a%10;
    c = a%100 - b;
    d = a-b-c;
    //cout << b << endl << c << endl << d << endl; 
    if(b == d/100){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    return 0;
    
}

Measured memory_bytes: 256
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

result = min(a) + min(b)
for _ in range(M):
    x, y, c = map(int, input().split())
    t = a[x - 1] + b[y - 1] - c
    if t < result:
        result = t
print(result)


Measured memory_bytes: 18736
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(vec) vec.begin(),vec.end()
#define rep(i,n) for(ll i = 0;i<n;++i)
#define repc(bit,k,n) for (ll bit = (1<<k)-1;bit < (1<<n); bit = next_combination(bit))
#define repi(itr,vec) for(auto itr = vec.begin();itr!=vec.end();++itr)
using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll a,b,c,d;cin>>a>>b>>c>>d;
  ll ans = a*c;
  ans = max(ans,a*d);
  ans = max(ans,b*c);
  ans = max(ans,b*d);
  cout<< ans<<endl;

  return 0;
}

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

int main() {
  string S;
  int W;
  
  cin >> S >> W;
  
  float size = S.size();
 
  for(int i = 0; i < size/W; i++){
    cout << S.at(i*W);
  }
  cout << endl;
}


Measured memory_bytes: 256
n, T = map(int, input().split())
t = [int(x) for x in input().split()]

sum = 0

for i in range(n-1):
    if t[i+1]- t[i] < T:
        sum = sum + t[i+1] - t[i]
    else:
        sum = sum + T

sum = sum + T

print(sum)

Measured memory_bytes: 25172
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MOD 1000000007

int main() {
	int n;
	char str[5];
	cin >> n;
	REP(i, n) {
		scanf("%s", str);
		if (str[0] == 'Y') {
			cout << "Four" << endl;
			return 0;
		}
	}
	cout << "Three" << endl;
	return 0;
}

Measured memory_bytes: 256
////......VACATION......////
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main {
    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()));
        }

        String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }
    }
    public static void main(String[] args) {
        FastReader in = new FastReader();
        int n=in.nextInt();
        int a[][]=new int[n][3];
        for(int i=0;i<n;i++){
            a[i][0]=in.nextInt();
            a[i][1]=in.nextInt();
            a[i][2]=in.nextInt();
        }
        int max=Math.max(Math.max(a[0][0],a[0][1]),a[0][2]);
        for(int i=1;i<n;i++){
            for(int j=0;j<3;j++){
                if(j==0){
                    a[i][0]+=Math.max(a[i-1][1],a[i-1][2]);
                }else if(j==1){
                    a[i][j]+=Math.max(a[i-1][0],a[i-1][2]);
                }else{
                    a[i][j]+=Math.max(a[i-1][0],a[i-1][1]);
                }

                if(max<a[i][j]){
                    max=a[i][j];
                }
            }
        }
        System.out.println(max);
        /*for(int i=0;i<n;i++){
            for(int j=0;j<3;j++){
                System.out.print(a[i][j]+" ");
            }
            System.out.println();
        }*/
    }
}


Measured memory_bytes: 57416
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  
  // 変数aで入力を受け取る
  cin >> s;
 
  int counter = 0;
  
  if(s[0] == '1') ++counter;
  if(s[1] == '1') ++counter;
  if(s[2] == '1') ++counter;
  
  cout << counter << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n,a;
	ll d;
	ll ans=0;
	cin >>n>>d>>a;
	VP q(n+1);//x,h
	VP dis(n, mp(0LL, 0LL));
	rep(i,n){
		cin>>q[i].F>>q[i].S;
		dis[i].F=q[i].F;
	}
	q[n]=mp(INFLL,0LL);
	sort(all(q));
	sort(all(dis));
	auto ter=dis.begin();
	ll cnt=0LL;
	for(int i=0;i<n;i++){
		if(i!=0){
			dis[i].S+=dis[i-1].S;
		}
		cnt=max(0LL,(q[i].S-dis[i].S+a-1)/(a));
		//clog<<dis[i].F<<" "<<cnt<<endl;
		dis[i].S+=cnt*a;
		ans+=cnt;
		ter=upper_bound(all(dis),mp(dis[i].F+d*2,INFLL));
		if(ter!=dis.end()){
		ter->S-=a*cnt;
		}
		
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
const ll MOD = 1000000007;

int N, M;
int cnt = 0;
vector<vector<int>> G;

vector<int> seen;
void dfs(int v) {
    seen[v] = cnt;

    for (auto nv : G[v]) {
        if (seen[nv] != -1) continue;

        dfs(nv);
    }
}

int main() {
    cin >> N >> M;
    G.resize(N);
    seen.assign(N, -1);
    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    for (int v = 0; v < N; v++) {
        if (seen[v] != -1) continue;

        dfs(v);
        cnt++;
    }

    int q;  cin >> q;
    for (int i = 0; i < q; i++) {
        int a, b; cin >> a >> b;
        if (seen[a] == seen[b]) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 11672
import java.util.Scanner;

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

		int a = in.nextInt();
		int b = in.nextInt();
		int c = in.nextInt();

		if ((a * 100 + b * 10 + c) % 4 == 0) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

	}
}

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

typedef long long ll;

int main()
{
    string n;
    cin >> n;
    int k;
    cin >> k;
    int i,j;
    int digit = n.size();
    vector<vector<vector<ll>>> dp(digit+1,vector<vector<ll>>(2,vector<ll>(k+1,0)));
    dp.at(0).at(1).at(0) = 1;
    for(i = 0;i < digit;++i){
        for(j = 0;j <= k;++j){
            if(n.at(i) == '0'){
                if(j == 0){
                    dp.at(i+1).at(0).at(j) = dp.at(i).at(0).at(j);
                    dp.at(i+1).at(1).at(j) = dp.at(i).at(1).at(j);
                }else{
                    dp.at(i+1).at(0).at(j) = dp.at(i).at(0).at(j) + dp.at(i).at(0).at(j-1)*9;
                    dp.at(i+1).at(1).at(j) = dp.at(i).at(1).at(j);
                }
            }else{
               if(j == 0){
                    dp.at(i+1).at(0).at(j) = dp.at(i).at(0).at(j) + dp.at(i).at(1).at(j);
                }else{
                    dp.at(i+1).at(0).at(j) = dp.at(i).at(0).at(j) + dp.at(i).at(0).at(j-1)*9 + dp.at(i).at(1).at(j) + dp.at(i).at(1).at(j-1)*(n.at(i) - '0' -1);
                    dp.at(i+1).at(1).at(j) = dp.at(i).at(1).at(j-1);
                }
            }
        }
    }
    cout << dp.at(digit).at(0).at(k) + dp.at(digit).at(1).at(k) << endl;
    return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

vector<ll> enum_prime(ll N){
	deque<bool> is_prime(N+1,true);
	vector<ll> P;
	for(ll i=2;i<=N;i++){
		if(is_prime[i]){
			for(ll j=i*i;j<=N;j+=i){
				is_prime[j] = false;
			}
			P.emplace_back(i);
		}
	}
	return P;
}

// 入力された数字を素因数分解する ex)8を入力したら[2,2,2]が返る
vector<ll> prime_factor(ll n){
	ll sn = sqrt(n)+1;
	auto prime_list = enum_prime(sn);
	vector<ll> res;
	for(int i=0,ei=prime_list.size();i<ei;i++){
		ll v = prime_list[i];
		if(v*v>n) break;
		while(!(n%v)){
			n /= v;
			res.push_back(v);
		}
	}
	if(n>1){
		res.push_back(n);
	}

	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	while(true){
		int N=in();
		if(!N) break;
		map<int,int> C;
		REP(i,N){
			auto P=prime_factor(i+1);
			for(auto& x:P) C[x]++;
		}
		out(min(C[2],C[5]));
	}
	return 0;
}



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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define all(x) (x).begin,(x).end()
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

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


int main(){
  int d; cin >> d;
  cout << "Christmas";
  if(d<25) cout << " Eve";
  if(d<24) cout << " Eve";
  if(d<23) cout << " Eve";
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

/**
 * Kadai
 */
public class Main {

    public void go() {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextLine()) {
            String lines0;
            String lines1;
            lines0 = sc.nextLine();
            if (lines0.equals(".")) {
                sc.close();
                return;
            }
            lines1 = sc.nextLine();

            if (lines0.equals(lines1)) {
                System.out.println("IDENTICAL");
                continue;
            }

            String[] strSplit0 = lines0.split("\"", -1);
            String[] strSplit1 = lines1.split("\"", -1);
            if (strSplit0.length != strSplit1.length) {
                System.out.println("DIFFERENT");
                continue;
            }

            int close = 0;
            for (int j = 0; j < strSplit0.length; j++) {
                if (!strSplit0[j].equals(strSplit1[j])) {
                    if (j % 2 == 1) {
                        close++;
                    } else {
                        close = 2;
                        break;
                    }
                }

            }
            switch (close) {
            case 1:
                System.out.println("CLOSE");
                break;
            case 0:
                System.out.println("IDENTICAL");
                break;
            default:
                System.out.println("DIFFERENT");

            }
        }
    }

    public static void main(String[] args) {
        Main kadai = new Main();
        kadai.go();
    }
}


Measured memory_bytes: 28740
%:pragma GCC optimize("Ofast")
%:pragma GCC optimize("inline")
#include<bits/stdc++.h>
#define fo(i, n) for(int i = 1; i <= (n); i ++)
#define out(x) cout << #x << " = " << x << "\n"
#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); ++ it)
using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
  x = 0; char c = getchar(); bool f = 0;
  for(; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
  for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if(f) x = -x;
}
template<typename tp> inline void arr(tp *a, int n) {
  for(int i = 1; i <= n; i ++)
    cout << a[i] << " ";
  puts("");
}
const int N = 3e5 + 233;
int n;
vector<int> g[N];

inline int dfs(int u, int fat, int fff) {
  int t = 0;
  vector<int> vec;
  for(auto v: g[u]) if(v != fat) t ^= 1 + dfs(v, u, fff ^ 1);
  return t;
}

main(void) {
  read(n);
  for(int i = 1; i <= n - 1; i ++) {
    int x, y; read(x); read(y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  cout << (dfs(1, 0, 1) ? "Alice" : "Bob") << "\n";
}

Measured memory_bytes: 16640
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

money = 1000
stock = 0
cnt = 0
buy = True    

while True:
    if buy == False:
        while True:
            if cnt >= N-1:
                break
            if A[cnt+1] < A[cnt]:
                break
            cnt += 1
        if cnt >= N-1:
            break
        buy = True
        money += (stock*A[cnt])
        stock = 0
    else:
        while True:
            if cnt >= N-1:
                break
            if A[cnt+1] > A[cnt]:
                break
            cnt += 1
        if cnt >= N-1:
            break
        buy = False
        stock += (money//A[cnt])
        money %= A[cnt]
    if cnt >= N-1:
        break
money += (stock*A[-1])
print(max(money,1000))

Measured memory_bytes: 9208
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace abc185
{
    class Program
    {
        static void Main(string[] args)
        {
            if (File.Exists("input.txt"))
            {
                Console.SetIn(new StreamReader("input.txt"));
            }
			solve_abc185A();
        }

        public static void solve_abc185B()
        {

        }

        public static void solve_abc185A()
        {
            string s = Console.ReadLine();

            if (s.Contains('A') && s.Contains('B'))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


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

using namespace std;

int main()
{
    int n,v[100001]={},x;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        v[x]=i;
    }
    for(int i=1;i<=n;i++)
    {
        cout<<v[i]<<" ";
    }
    return 0;
}


Measured memory_bytes: 1152
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

ll ext_gcd(ll a, ll b, ll &x, ll &y){
	if(b==0){
		x = 1;
		y = 0;
		return a;
	}
	
	ll d = ext_gcd(b, a%b, y, x);
	y -= a/b * x;
	return d;
}

ll mod_inv(ll a, ll m){
	ll x,y;
	ext_gcd(a,m,x,y);
	return (m + x%m)%m;
}

int main(){
	int x,y;
	cin >> x >> y;
	const ll mod = 1000000007;
	
	if((x+y)%3!=0){
		cout << 0 << endl;
		return 0;
	}
	
	int x1=(2*y-x)/3;
	int x2=y-2*x1;
	
	if(x1<0 || x2<0 || x1+2*x2!=x || 2*x1+x2!=y){
		cout << 0 << endl;
		return 0;
	}
	
	ll ans=1;
	for(int i=1; i<=x1+x2; i++){
		ans = (ans*i)%mod;
		if(i<=x1){
			ans = (ans*mod_inv(i,mod))%mod;
		}else{
			int factor = i-x1;
			ans = (ans*mod_inv(factor,mod))%mod;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3628
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;
import java.util.Queue;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		
		// input:N枚のカード
		// input conditon
		// 1<= N <= 100
		// ai(1<= i <= N) は1以上100以下
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		
		if(N<1 || N>100) {
			System.out.println("N is illegal");
			System.exit(1);
		}
		
		int number_array[] = new int[N];
		
		for(int i = 0; i < N; i++) {
			 
			int a_i = scan.nextInt();
			if(a_i < 1 || a_i > 100 ) {
				System.out.println("N is illegal");
				System.exit(1);
			}
			number_array[i] = a_i;
		}
		//debug print
		//printArray(number_array);
		
		// condition:
		//	Alice/Bobは残ったカードのうち、最大の値のカードを選択する
		//	Aliceが先行
		
		//logic
		//	1.リストのうち、最大の値を検索し、取り出す。
		//		検索処理回数が(N/2 - 1)
		//  2.始めに大きい順にソートして、リストの頭から順次取り出す ★
		//		検索処理回数は0,ソート回数1
		int Alice_point = 0, Bob_point = 0;
		int difference = 0;
		
		//ソートして整列
		//number_array = quicksort(number_array);
		Arrays.sort(number_array);
		//printArray(number_array);
		//System.exit(1);
		
		Deque<Integer> stack = arrayToStack(number_array);
		//(繰り返し)
		//	奇数番目なら、Alice_pointにデータ加算。偶数番目ならBob_pointにデータ加算。(listからどんどんデータを取っていく)
		//(listがからなら抜ける)
		for(int turn = 1; turn <= N; turn++) {
			if(turn % 2 == 1) Alice_point = Alice_point + stack.pop();  
			if(turn % 2 == 0) Bob_point = Bob_point + stack.pop();
		}
		if(!stack.isEmpty()) System.out.println("Card is rest yet.");
		
		// output:Alice は Bob より何点多く取るか
		difference = Alice_point - Bob_point;
		System.out.println(String.valueOf(difference));
	}

	
	public static Deque<Integer> arrayToStack(int[] array) {
		Deque<Integer> stack = new ArrayDeque<Integer>();
		
		for(int i = 0; i < array.length; i++) {
			stack.push(array[i]);
		}
		return stack;
	}
	
	public static void printArray(int[] array) {
		System.out.println("---debug print----");
		for(int i = 0; i < array.length; i++) {
			System.out.println(array[i]);
		}
		System.out.println("-------------------");
	}

}


Measured memory_bytes: 24020
use std::io::*;
use std::str::FromStr;

fn main(){
    println!("{}", if read::<i32>() % read::<i32>() == 0 {0} else {1});
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

Measured memory_bytes: 4352
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7

n=int(input())
abc=[list(map(int,input().split())) for i in range(n-1)]
q,k=map(int,input().split())
xy=[list(map(int,input().split())) for i in range(q)]

lst=[[] for i in range(n+1)]
# print(lst)
for i in range(n-1):
    a,b,c=abc[i]
    lst[a].append([b,c])
    lst[b].append([a,c])
dist=[float('inf')]*(n+1)
# dist[k]=0
# print(lst)
d=deque()
d.append([[[k,0]],0])
while d:
    tmp=d.popleft()
    # print(tmp)
    for i in range(len(tmp[0])):
        # print(tmp[0][i])
        if dist[tmp[0][i][0]]==float('inf'):
            dist[tmp[0][i][0]]=tmp[0][i][1]+tmp[-1]
            d.append([lst[tmp[0][i][0]],dist[tmp[0][i][0]]])
# print(dist)
for i in range(q):
    x,y=xy[i]
    print(dist[x]+dist[y])

Measured memory_bytes: 125784
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney,chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun


#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")

int ctoi(char c) {
	switch (c)
	{
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default:
		cout << "ERR_ctoi" << endl;
		return -1;
	}
}
int main() {
	int n, i;
	cin >> n >> i;
	PRI(n + 1 - i);
	return 0;
}

Measured memory_bytes: 3612
S = input()
Q = int(input())

flg = "moto"

atama = list()
shippo = list()

for _ in range(Q):
    tmp = list(map(str, input().split()))
    if flg == "moto":
        if int(tmp[0]) == 1:
            flg = "hanten"
        else:
            if int(tmp[1]) == 1:
                atama.append(tmp[2])
            else:
                shippo.append(tmp[2])
    
    else:
        if int(tmp[0]) == 1:
            flg = "moto"
        else:
            if int(tmp[1]) == 1:
                shippo.append(tmp[2])
            else:
                atama.append(tmp[2])

if flg == "moto":
    atama = atama[::-1]
    print("".join(atama) + S + "".join(shippo))

else:
    shippo = shippo[::-1]
    print("".join(shippo) + S[::-1] + "".join(atama))


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

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()
const int INF = INT_MAX/3;
const double EPS = 1e-14;

template<typename U, typename T>
void chmin(U &x, T y) { x = min(x, y); }

template<typename U, typename T>
void chmax(U &x, T y) { x = max(x, y); }

typedef long long int lli;
typedef long double ld;

int memo[10][10][10][10];

bool wins(int la, int ra, int lb, int rb) {
  if (memo[la][ra][lb][rb] >= 0) return memo[la][ra][lb][rb];
  if (la == 5 && ra == 5) return false;
  if (lb == 5 && rb == 5) return true;
  bool ll = la < 5 && lb < 5 && !wins(min(lb + la, 5), rb, la, ra);
  bool rl = ra < 5 && lb < 5 && !wins(min(lb + ra, 5), rb, la, ra);
  bool lr = la < 5 && rb < 5 && !wins(lb, min(rb + la, 5), la, ra);
  bool rr = ra < 5 && rb < 5 && !wins(lb, min(rb + ra, 5), la, ra);
  bool ans = ll || rl || lr || rr;
  memo[la][ra][lb][rb] = ans;
  return ans;
}

int main() {
  REP(i,10) REP(j,10) REP(k,10) REP(l,10) memo[i][j][k][l] = -1;
  int li, ri, ln, rn;
  cin >> li >> ri >> ln >> rn;
  bool ans = wins(li, ri, ln, rn);
  cout << (ans ? "ISONO":"NAKAJIMA") << endl;
  return 0;
}

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

int main() {
    char c;
    cin >> c;
    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }
}

Measured memory_bytes: 764
let to_z x = if x = -0. then 0. else x;;
let read_str () = read_line () |> Str.split (Str.regexp_string ",")
           |> List.map (fun x-> float_of_string x) |> List.nth;;
let () =
  let rec read () =
    try let l = read_str () in
        let x0, y0, x1, y1, xq, yq = l 0, l 1, l 2, l 3, l 4, l 5 in
        let p1_sqr = ( (x1-.x0)**2. +. (y1-.y0)**2. ) and
            in_p = ((x1-.x0)*.(xq-.x0)+.(y1-.y0)*.(yq-.y0)) in
        let x, y = 2.*.in_p*.(x1-.x0)/.p1_sqr +. 2.*.x0 -.xq , 2.*.in_p*.(y1-.y0)/.p1_sqr +. 2.*.y0 -. yq in
        Printf.printf "%f %f\n" (to_z x) (to_z y);read ()
    with End_of_file -> ()
  in
  read ();;

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

using namespace std;

int main(){

 long long n ,m;
 cin >> n>>m;
 long long s[n];
 for(int i = 0; i < n; i++){
  cin >> s[i];
 }
 if(m == 2){
    cout << n-1;
 return 0;
 }
 int c =0;
 for(int i = 0 ;i < n ;i=i+(m-1)){
  c++;
  if(i%2==0){
    i++;
  }
 }
 cout<<c;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <stdio.h>

using namespace std;

#define WMAX 1000
#define NMAX 1000
int main(void)
{
    int W, n;
    int cyc = 0;
    while (cin >> W && W && cin >> n) {
        cyc++;
        int dp[WMAX+1][NMAX+1] = {};
        for (int i = 0; i < n; i++) {
            int v, w;
            scanf("%d,%d", &v, &w);
            for (int j = 0; j < W+1; j++)
                dp[j][i+1] = max(dp[j][i], (j-w >= 0 ? dp[j-w][i] + v : 0));
        }
        cout << "Case " << cyc << ":" << endl;
        for (int j = 0; j < W+1; j++) {
            if (dp[j][n] == dp[W][n]) {
                cout << dp[j][n] << endl << j << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 7052
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;

const int INF = 100000;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s; cin >> s;
    for (int i = 0; i < s.size() - 1; i++) {
        if (s.at(i) == s.at(i + 1)) {
            cout << "Bad" << endl;
            return 0;
        }
    }
    
    cout << "Good" << endl;
    
    return 0;
}


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long Inf=(long)1e18+1;
		HashSet<long> H=new HashSet<long>();
		H.Add(2);
		H.Add(8);
		L=new List<long>();
		L.Add(2);
		L.Add(8);
		for(int i=2;i<18;i++){
			HashSet<long> nxt=new HashSet<long>();
			foreach(var l in H){
				if(Inf/l>=10){
					if(l*10+2<Inf){
						nxt.Add(l*10+2);
						L.Add(l*10+2);
					}
					if(l*10+8<Inf){
						nxt.Add(l*10+8);
						L.Add(l*10+8);
					}
				}
			}
			H=nxt;
		}
		
		memo=new Dictionary<long,int>();
		dfs(N,0);
		
		if(!memo.ContainsKey(1)){
			Console.WriteLine(-1);
		}else{
			Console.WriteLine(memo[1]);
		}
	}
	long N;
	List<long> L;
	Dictionary<long,int> memo;
	
	void dfs(long rem,int depth){
		for(int i=0;i<L.Count;i++){
			if(L[i]>rem)break;
			if(rem%L[i]!=0)continue;
			if(memo.ContainsKey(rem/L[i])==false){
				memo.Add(rem/L[i],depth+1);
				dfs(rem/L[i],depth+1);
			}else if(memo[rem/L[i]]<depth+1){
				memo[rem/L[i]]=depth+1;
				dfs(rem/L[i],depth+1);
			}
		}
	}
	
	
	
	public Sol(){
		N=rl();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}

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

#define     F       first
#define     S       second
typedef pair<int, int>  pi;
typedef long long       ll;

const int MAX=59;
int n, m, q, a[MAX], b[MAX], c[MAX], d[MAX];
vector< vector<int> > all;
vector<int> cur;

void gen(int i, int lst) {
    if (i==n) {
        all.push_back(cur);
        return;
    }

    for (int j=lst; j<=m; ++j) {
        cur.push_back(j);
        gen(i+1, j);
        cur.pop_back();
    }
}

ll check(int idx) {
    ll ret=0;
    for (int i=1; i<=q; ++i) {
        if (all[idx][b[i]]-all[idx][a[i]]==c[i]) {
            ret+=d[i];
        }
    }

    return ret;
}

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

    cin >> n >> m >> q;
    for (int i=1; i<=q; ++i) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        --a[i]; --b[i];
    }

    gen(0, 1);
    ll ans=0;
    for (int i=0; i<all.size(); ++i) {
        ans=max(ans, check(i));
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 9752
n,y=map(int,input().split())
ans=[-1,-1,-1]
for i in range(n+1):
  for j in range(n-i+1):
    if y-10000*i-5000*j==1000*(n-i-j):
      ans=[i,j,n-i-j]
      print(ans[0],ans[1],ans[2])
      exit()
print(ans[0],ans[1],ans[2])

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

#define mp make_pair
#define fst first
#define snd second

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef pair<i64,int> pli;
typedef pair<int,i64> pil;
typedef pair<i64,i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;

template <typename T>
T id(T b) {return b;};
template <class It>
bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It>
bool any(It f,It l){return std::any_of(f,l,id<bool>);}

const int MAX_N = 100000;
int n,m;
vi g[MAX_N+1];
vi rg[MAX_N+1];
bool vis[MAX_N+1];
int comp[MAX_N+1];
vi path;

void dfs(int u) {
  vis[u] = true;
  for (int v : g[u]) {
    if (!vis[v]) dfs(v);
  }
  path.push_back(u);
}

void rdfs(int u, int k) {
  vis[u] = true;
  comp[u] = k;
  for (int v :  rg[u]) {
    if (!vis[v]) rdfs(v, k);
  }
}

int main()
{
  cin >> n >> m;
  int a,b;
  for (int i = 1; i <= n-1+m; i++) {
    cin >> a >> b;
    g[a].push_back(b);
    rg[b].push_back(a);
  }

  fill_n(vis,n+1,false);
  for (int u = 1; u <= n; u++)
    if (!vis[u]) dfs(u);

  fill_n(vis,n+1,false);
  int k = 1;
  for (int i = path.size()-1; i >= 0; i--) {
    int u = path[i];
    if (!vis[u]) rdfs(u, k++);
  }

  /*
  for (int u = 1; u <= n; u++) {
    printf("u=%d %d\n",u,comp[u]);
  }
  */

  for (int u = 1; u <= n; u++) {
    if (rg[u].size() == 0) {
      cout << 0 << endl;
    } else if (rg[u].size() == 1) {
      cout << rg[u][0] << endl;
    } else {
      int k = 0, p = -1;
      for (int v : rg[u]) {
        if (comp[v] > k) {
          k = comp[v];
          p = v;
        }
      }
      cout << p << endl;
    }
  }

  return 0;
}


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

namespace ConsoleApp1
{
    class Program
    {
        struct Store
        {
            public long Price { get; }
            public int Count { get; }

            public Store(long price, int count)
            {
                Price = price;
                Count = count;
            }
        }

        static void ReadInt2(out int a, out int b)
        {
            var array = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
            a = array[0];
            b = array[1];
        }

        static void ReadLong2(out long a, out long b)
        {
            var array = Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();
            a = array[0];
            b = array[1];
        }

        static Store ReadStore()
        {
            long price, count;
            ReadLong2(out price, out count);
            return new Store(price, (int)count);
        }

        static void Main(string[] args)
        {
            int n, m;
            ReadInt2(out n, out m);

            var stores = (from _ in Enumerable.Repeat(0, n)
                          let store = ReadStore()
                          orderby store.Price
                          select store).ToArray();

            long answer = 0;
            int remain = m;
            foreach (var store in stores)
            {
                if (remain <= 0)
                {
                    break;
                }

                int count = Math.Min(remain, store.Count);
                answer += store.Price * count;
                remain -= count;
            }

            Console.WriteLine(answer);
        }
    }
}

Measured memory_bytes: 31668
using namespace std;
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 1000010
int n,m,k;
char str[N];
int s[N],t[N];
struct Node{
	Node *pre,*suc;
	int s,n;
} *fir,*lst;
Node *ins(Node *p,int s,int n=1){
	Node *nw=new Node;
	*nw={p,p->suc,s,n};
	if (p->suc)
		p->suc->pre=nw;
	else
		lst=nw;
	p->suc=nw;
	return nw;
}
Node *check(Node *p){
	if (p->n==0){
		p->pre->suc=p->suc;
		if (p->suc)
			p->suc->pre=p->pre;
		else
			lst=p->pre;
		return p->pre;
	}
	if (p->pre && p->s==p->pre->s){
		p->pre->n+=p->n;
		p->pre->suc=p->suc;
		if (p->suc)
			p->suc->pre=p->pre;
		else
			lst=p->pre;
		return p->pre;
	}
	return p;
}
int ans[N*2],cnt;
int main(){
	scanf("%d%d%d",&n,&m,&k);
	scanf("%s",str);
	for (int i=0;i<n;++i)
		s[i]=str[n-1-i]-'0';
	scanf("%s",str);
	for (int i=0;i<m;++i)
		t[i]=str[m-1-i]-'0';
	n=max(n,m);	
	fir=lst=new Node;
	*lst=(Node){NULL,NULL,0,1000000000};
	for (int i=n-1;i>=0;--i)
		if (s[i]==1 && t[i]==1){
			int z=k;
			Node *p=lst;
			while (z){
				while (1){
					Node *q=check(p);
					if (q==p) break;
					p=q;
				}
				if (p->n==0){
					p->pre->suc=p->suc;
					if (p->suc) 
						p->suc->pre=p->pre;
					else
						lst=p->pre;
					p=p->pre;
					continue;
				}
				if (p->s==0){
					if (p->n<=z){
						z-=p->n;
						p=p->pre;
						if (z==0)
							ins(p,3,1);
					}
					else{
						p->n-=z;
						Node *q=ins(p,0,z);
						ins(p,3,1);
						break;
					}
				}
				else{
					while (1){
						Node *q=check(p->pre);
						if (q==p->pre) break;
						p->pre=q;
					}
					if (p->s==1){
						if (p->pre->s==0){
							p->s=0,p->n--;
							Node *q=ins(p,2,1),*r=ins(q,0,1);
							p->pre->n--;
							check(p->pre);
							ins(p->pre,1,1);
							check(p);
							break;
						}
						else{
							p->s=0,p->n--;
							Node *q=ins(p,2,1),*r=ins(q,0,1);
							p->pre->n--;
							p=p->pre;
							z--;
							check(p->suc);
							if (z==0)
								ins(p,3,1);
							p=check(p);
						}
					}
					else if (p->s==2){
						if (p->pre->s==0){
							p->s=0,p->n--;
							Node *q=ins(p,1,1),*r=ins(q,0,1);
							p->pre->n--;
							check(p->pre);
							ins(p->pre,2,1);
							check(p);
							break;
						}
						else{
							p->s=0,p->n--;
							Node *q=ins(p,1,1),*r=ins(q,0,1);
							p->pre->n--;
							p=p->pre;
							z--;
							check(p->suc);
							if (z==0)
								ins(p,3,1);
							p=check(p);
						}
					}
//				else
//					printf("fuck\n");
				}
			}
		}
		else{
			int f=s[i]|t[i]<<1;
			if (f==lst->s)
				lst->n++;
			else
				lst=ins(lst,f,1);
		}
	for (Node *p=lst;p!=fir;p=p->pre)
		for (int i=0;i<p->n;++i)
			ans[cnt++]=p->s;
	bool bz=0;
	for (int i=cnt-1;i>=0;--i){
		bz|=ans[i]&1;
		if (bz)
			putchar('0'+(ans[i]&1));
	}
	if (bz==0)
		putchar('0');
	putchar('\n');
	bz=0;
	for (int i=cnt-1;i>=0;--i){
		bz|=ans[i]>>1;
		if (bz)
			putchar('0'+(ans[i]>>1));
	}
	if (bz==0)
		putchar('0');
	return 0;
}





















Measured memory_bytes: 145268