akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
int64_t INF = 1000000007;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n;
    cin >> n;
    vi a(n);
    rep(i,n) cin >> a.at(i);
    deque<int64_t> b;
    if(n%2==0){
        rep(i,n/2){
            b.push_back(a.at(2*i));
            b.push_front(a.at(2*i+1));
        }
    }else{
        rep(i,n/2){
            b.push_front(a.at(2*i));
            b.push_back(a.at(2*i+1));
        }
        b.push_front(a.at(n-1));
    }
    rep(i,n){
        cout << b.at(i) << " ";
    }
    cout << endl;
}

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

#define rng(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define urng(i, a, b) for(int i = int(b) - 1; i >= int(a); i--)
#define urep(i, b) urng(i, 0, b)
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed

main() {
  int n, a, b, ans = 0, min = 200001;
  //string s;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p.at(i);
  rep(i, n) {
    if(p.at(i) < min) {
      min = p.at(i);
      ans++;
    }
  }
  //for(int i = 0; i < n; i++){}
  cout << ans << endl;
}

Measured memory_bytes: 1152
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt(); in.nextLine();
		int[] ary = new int[5];
		while( N-- > 0 ) {
			char c = in.nextLine().charAt(0);
			switch(c) {
				case 'M': ary[0]++; break;
				case 'A': ary[1]++; break;
				case 'R': ary[2]++; break;
				case 'C': ary[3]++; break;
				case 'H': ary[4]++; break;
				default: break;
			}
		}
		//Arrays.fill(ary,20000);
		//System.out.println(Arrays.toString(ary));
		long total = 0;
		for( int i = 0; i < 3; i++ ) {
			for( int j = i+1; j < 4; j++ ) {
				for( int k = j+1 ; k < 5; k++ ) {
					total += (long)ary[i]*ary[j]*ary[k];
					//System.out.printf("%d %d %d\n",i,j,k);
				}
			}
		}
		System.out.println(total);
	}
}

Measured memory_bytes: 92912
k,a,b=map(int,input().split())
q=(k-a+1)//2
if a>=b or a+1==b or a+2==b:
  print(k+1)
else:
  if k>=a+1:
    if (k-a+1)%2==1:
      print(b+(q-1)*(b-a)+1)
    else:
      print(b+(q-1)*(b-a))
  else:
    print(k+1)

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

typedef long long ll;
#define pa pair<int, int> 
#define pal pair<long long, long long>
#define pad pair<double, double>
#define pb push_back
#define mp make_pair
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}

typedef vector<bool> bvec;
typedef vector<int> ivec;
typedef vector<long long> lvec;
typedef vector<double> dvec;
typedef vector<pa> pvec;

typedef vector< vector<bool> > bmat;
typedef vector< vector<int> > imat;
typedef vector<string> svec;
typedef vector< vector<string> > smat;
const ll infll = (1LL << 60) - 1;
const int inf = (1 << 30) - 1;

void print(int h, int w, svec &memo){
    for(int i=0; i<h; i++){
        for(int j=0; j<h; j++){
            cout << memo[i][j] << ' ';
        }
        cout << endl;
    }
}

int bfs(int i, int j, int h, int w, svec &memo){
    queue<pair<pa, int >> q;
    memo[i][j] = '#';
    int c=0;
    q.push(pair<pa, int>(pa(i,j), c));
    while(!q.empty()){
        auto &node = q.front();
        int x=node.first.first, y=node.first.second, cnt=node.second;
        c = max(cnt, c);
        q.pop();
        for (int k : {-1, 1}){
            if(k==-1 && x==0) continue;
            if(k==1 && x == h-1) continue;
            if (memo[x+k][y] != '#') {
                memo[x+k][y] = '#';
                q.push(pair<pa, int>(pa(x+k, y), cnt+1));
            }
        }

        for (int k : {-1, 1}){
            if(k==-1 && y==0) continue;
            if(k==1 && y == w-1) continue;
            if (memo[x][y+k] != '#') {
                memo[x][y+k] = '#';
                q.push(pair<pa, int>(pa(x, y+k), cnt+1));
            }
        }
    }
    return c;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int  h, w;
    cin >> h >> w;
    svec map(h, string(w, '.'));
    queue<pa> q;
    for (int i = 0; i < h; i++) for (int j=0; j<w; j++) {
        cin >> map[i][j]; 
    }
    int ans=0;
    for (int i = 0; i < h; i++){
        for (int j=0; j<w; j++){
            svec memo = map; 
            if(map[i][j] != '#') ans = max(ans, bfs(i,j, h, w,memo));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <utility>
#include <functional>
#include <queue>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>      // std::setprecision
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor_ct.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/pending/disjoint_sets.hpp>
#include <boost/icl/interval_map.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/strong_components.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/kruskal_min_spanning_tree.hpp>
#include <boost/graph/graph_utility.hpp>
#include <boost/numeric/ublas/vector.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;
using namespace boost::numeric;
namespace bst = boost;

int main() {
  int A;

  cin >> A;

  cout << A*A*A << endl;

  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <math.h>
#include <string>
#include <ios>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <queue>

#define LL long long
using namespace std;
int main() {
	LL N,M;
	LL res = 0;
	cin >> N >> M;
	map<int, priority_queue<pair<int,int>>> salary;

	for (int i = 0; i < N; i++) {
		LL A, B;
		cin >> A >> B;
		salary[A].push(make_pair(B,A));
	}
	
	priority_queue<pair<int, int>> tmp;
	for (int max_m = 1; max_m <= M; max_m++) {
		if (salary[max_m].size() > 0) {
			tmp.push(salary[max_m].top());
			salary[max_m].pop();
		}

		int id_pop = 0;
		if (tmp.size() > 0) {
			res += tmp.top().first;
			id_pop = tmp.top().second;
			tmp.pop();
		}

		if (salary[id_pop].size() > 0) {
			tmp.push(salary[id_pop].top());
			salary[id_pop].pop();
		}
	}
	cout << res;

	return 0;
}

Measured memory_bytes: 10880
#include <stdio.h>

int IsPrime(int n){
	int i;
	if(n==1) return 0;
	if(n==2)return 1;
	else if(n%2==0)return 0;
	for(i=3;i*i<=n;i+=2)if(n%i==0)return 0;
	return 1;
}

int main(void){
	int n , i , count;
	int dp[1000000] = {0};
	for(i=1;i<1000000;i++) if(IsPrime(i)) dp[i] = 1;
	while(scanf("%d" , &n)!=EOF){
		count = 0;
		for(i=1;i<=n;i++)if(dp[i]==1)count++;
		printf("%d\n" , count);
	}
	return 0;
}

Measured memory_bytes: 4316
A = int(input())						# 5
B = int(input())						# 5
C = int(input())						# 5
X = int(input())						# 5

ans = 0
for a in range(A+1):
	for b in range(B+1):
		for c in range(C+1):
			if X == ( (500*a)+(100*b)+(50*c) ):
				ans += 1


print(ans)


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

int main(){
  int a[30];
  char gomi;
  int w,n,box1,box2;
  cin >> w >> n;
  for(int i=0;i<w;i++){
    a[i] = i+1;
  }
  for(int i=0;i<n;i++){
    cin >> box1 >> gomi >> box2;
    swap(a[box1-1],a[box2-1]);
  }
  for(int i=0;i<w;i++){
    cout << a[i] << endl;
  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int dp[100005];
vector<int> v[100005];
int maxlen(int t)
{
    if(dp[t]>=0) return dp[t];
    if(v[t].empty())
    {
        dp[t]=0;
        return 0;
    }
    int maxd=0;
    for(int i=0;i<v[t].size();i++)
    {
        maxd=max(maxd,maxlen(v[t][i]));
    }
    dp[t]=maxd+1;
    return dp[t];
}
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        dp[i]=-1;
    }
    for(int i=1;i<=m;i++)
    {
        int c,d;
        cin>>c>>d;
        v[c].push_back(d);
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        if(dp[i]==-1)
        {
            ans=max(ans,maxlen(i));
        }
    }
    cout<<ans<<'\n';
}


Measured memory_bytes: 8192
#!/usr/bin/env python
# -*- coding:utf-8 -*-

from __future__ import division, print_function, absolute_import, unicode_literals
import sys

s = input()


start = s.find('C')
if start == -1:
    print("No")
    sys.exit()
start = s.find('F', start)
if start == -1:
    print("No")
else:
    print("Yes")


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

using namespace std;

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

  int n, a;
  cin >> n;
  map<int, int> hash;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    hash[a]++;
    hash[a+1]++;
    hash[a-1]++;
  }
  int res = (*max_element(hash.begin(), hash.end(), 
      [&](pair<int, int> x, pair<int,int> y) {return x.second < y.second;})).second;
  cout << res << endl;

  return 0;
}



Measured memory_bytes: 4736
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto s = readln.chomp;
    int i;
    foreach (c; s) {
        if (i == 0 && c == 'C') ++i;
        if (i == 1 && c == 'F') ++i;
    }
    writeln(i == 2 ? "Yes" : "No");
}

Measured memory_bytes: 256
import Data.List



select :: [a] -> [(a, [a])]
select [x]    = [(x, [])]
select (x:xs) = (x, xs) : map (\(y, ys) -> (y, x:ys)) (select xs)

combinations :: Int -> [Int] -> [[Int]]
combinations n xs = comb n (length xs) xs where
  comb 0 _ _ = [[]]
  comb r n a@(x:xs)
    | n == r    = [a]
    | otherwise = map (x:) (comb (r - 1) (n - 1) xs) ++ comb r (n - 1) xs

main = do
  n <- getLine
  xs <- map read . words <$> getLine
  if length xs < 3 then print 0
                   else print $ length $ filter (\[a, b, c] -> a + b > c && b + c > a && c + a > b) $ filter (\[a, b, c] -> a /= b && a/=c && c/=b) $ combinations 3 xs

Measured memory_bytes: 6772
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl

/*-- template --*/

int main() {
    int N;
    cin >> N;
    int L[N];
    rep(i, N) cin >> L[i];
    sort(L, L + N);
    int ans = 0;
    rep(i, N) {
        for(int j = i + 1; j < N; ++j) {
            int l = lower_bound(L + j + 1, L + N, L[j]) - L;
            int r = lower_bound(L + j + 1, L + N, L[j] + L[i]) - L;
            ans += r - l;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

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

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

  string n;
  cin >> n;
  for (char c : n) {
    if (c == '7') {
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long  a,b,k;
  cin>>a>>b>>k;
  if (a>=k)
    cout <<a-k<<' '<<b<<endl;
  else if (a+b>k)
    cout <<0<<' '<<b-(k-a)<<endl;
  else 
    cout <<0<<' '<<0<<endl;
  }

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

int main(int argc, char const *argv[])
{
	int x, y, z; cin >> x >> y >> z;
	x -= z;
	printf("%d\n", x / (y + z));
	return 0;
}

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

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

ll lcm(ll a, ll b){
    // cout << "a" << a << "b"<< b << endl;
    ll g = gcd(a, b);
    // cout << "gcd" << g << endl;
    return a /g * b;
}


int main(){
    cin >> N;

    ll ans = 1LL;
    for(int i = 0; i< N; i++){
        ll gg;
        cin >> gg;
        if(ans > gg){
            ans = lcm(ans, gg);
        }else{
            ans = lcm(gg, ans);
        }

        // ans = lcm(ans, gg);
    }

    cout << ans << endl;

}

Measured memory_bytes: 764
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var ary = ToIntArray(input.ReadLine(), n);

        var c = 0;
        for(int i=1; i<n-1; i++) {
            if (ary[i - 1] < ary[i] && ary[i] < ary[i + 1]) {
                c++;
            } else if (ary[i + 1] < ary[i] && ary[i] < ary[i - 1]) {
                c++;
            }
        }

        return c;
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#define INFTY 1<<20
typedef long long int ll;
const int MOD=1000000007;

int main(){
    double s,w;
    cin>>s>>w;

    if(w>=s)cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
    return 0;
}

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

int main(void){
  
    long A,B,K;

    std::cin >> A >> B >> K;
    
    if(K >= A+B){

        A = 0;
        B = 0;
    } else if ( (K > A )&& (K < (A+B))){

        B = B - (K-A);
        A = 0;
    } else {
        A = A - K;
    }


    std::cout << A <<" "<< B << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

int main() {
  int n;
  scanf("%d", &n);
  vi x(n);
  vector<pii> x_sorted(n);
  vvi a(n, vi(n, -1)); // 最後に各要素を+1
  rep (i, n) {
    scanf("%d", &x[i]);
    x[i] -= 1;
    a[i][i] = x[i];
    x_sorted[i] = (make_pair(x[i], i));
  }
  sort(all(x_sorted));
  vi order(n*n);
  rep (i, n*n) {
    order[i] = i;
  }
  for (int i = n-1; i >= 0; --i) {
    order.erase(begin(order) + x_sorted[i].first);
  }

  rep (i, n) {
    int xi = x_sorted[i].first;
    if (lower_bound(all(order), xi) - begin(order) < x_sorted[i].second) {
      printf("No\n");
      return 0;
    }
    rep (j, x_sorted[i].second) {
      a[x_sorted[i].second][j] = order[j];
    }
    order.erase(begin(order), begin(order) + x_sorted[i].second);
  }


  rep (i, n) {
    if (order.empty()) {
      break;
    }
    int xi = x_sorted[i].first;
    if (order.at(0) < xi) {
      printf("No\n");
      return 0;
    }
    int offset = x_sorted[i].second + 1;
    FOR (j, offset, n) {
      a[x_sorted[i].second][j] = order[j - offset];
    }
    order.erase(begin(order), begin(order) + (n - offset));
  }

  vi a_print(n*n);
  rep (i, n) {
    rep (j, n) {
      a_print[a[i][j]] = i + 1;
    }
  }
  printf("Yes\n");
  rep (i, n*n-1) {
    printf("%d ", a_print[i]);
  }
  printf("%d\n", a_print[n*n-1]);

  return 0;
}


Measured memory_bytes: 4096
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
vector<int> parent;
vector<int> nodes;

int getParent(int x) {
  int y = x;
  while (y != parent[y]) {
    y = parent[y];
  }
  parent[x] = y;
  return y;
}

bool unite(int x, int y) {
  x = getParent(x);
  y = getParent(y);
  if (x == y) return false;
  if (nodes[x] < nodes[y]) swap(x, y);
  parent[y] = x;
  nodes[x] += nodes[y];
  return true;
}

int main(void) {
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<pair<int64_t, int>> A(N);
  rep(i, N) {
    int64_t a;
    cin >> a;
    A[i] = {a, i};
  }
  sort(A.begin(), A.end());

  parent.resize(N);
  nodes.resize(N);
  rep(i, N) {
    parent[i] = i;
    nodes[i] = 1;
  }
  int pnum = N;
  rep(i, M) {
    int x, y;
    cin >> x >> y;
    if (unite(x, y)) pnum--;
  }
  if (pnum == 1) {
    cout << 0 << endl;
    return 0;
  }

  vector<bool> usedP(N, false);
  vector<int64_t> B;
  int64_t answer = 0;
  int count = 0;
  rep(i, N) {
    int x = getParent(A[i].second);
    if (usedP[x]) {
      B.emplace_back(A[i].first);
      continue;
    }
    usedP[x] = true;
    answer += A[i].first;
    count++;
  }

  int BN = B.size();
  int need = 2 * (pnum - 1) - count;
  if (BN < need) {
    cout << "Impossible" << endl;
    return 0;
  }
  rep(i, need) { answer += B[i]; }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 6720
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
const ll MOD = (ll)1e9+7;
const ll INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

int main(){
	int n, k;
	cin >> n >> k;
	vector<ll> line(n);
	foreach(i, line)cin>>i;
	vector<ll> subs;
	rep(i, n){
		ll sum = 0;
		for(int j=i;j<n;++j){
			sum += line[j];
			subs.push_back(sum);
		}
	}

	auto func = [&](int hp){
		vector<ll> sub;
		foreach(i, subs)if(i&bit(hp))sub.push_back(i);
		if(sub.size()<k)return 0ll;
		ll res = bit(hp);
		per(i, hp){
			vector<ll> nsub;
			foreach(j, sub)if(j&bit(i))nsub.push_back(j);
			if(nsub.size()<k)continue;
			res |= bit(i);
			sub = nsub;
		}
		return res;
	};

	ll ans = 0;
	rep(i, 60)chmax(ans, func(i));
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 8404
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int n, m, t, p;
    //int cnt[661][661];
    for(;;) {
        cin >> n >> m >> t >> p;
        vector<vector<int>> cnt(1000,vector<int>(1000,0));
        if(n == 0 && m == 0 && t == 0 && p == 0) return 0;
        rep(i, m) {
            rep(j, n) {         
                cnt[i][j] = 1;
            }
        }
        /*
        for(int i = m; i <= 660 ; i++) {
            for(int j = n; j <= 660; j++) {
                cnt[i][j] = 0;
            }
        }
        */
        int a = -1, b = -1;
        rep(i, t) {
            int d, c; cin >> d >> c;
            if(d == 2) {
                a += c;
                int l = a;
                for(int k = a; k >= 0; k--) {
                    l ++;
                    rep(j, 600) {
                        cnt[l][j] += cnt[k][j];
                        cnt[k][j] = 0;
                    }
                }
            } if(d == 1) {
                b += c;
                int l = b;
                for(int k = b; k >= 0; k--) {
                    l ++;
                    rep(j, 600) {
                        cnt[j][l] += cnt[j][k];
                        cnt[j][k] = 0;
                    }
                }
            }
        }
        rep(j, p) {
            int x, y; cin >> x >> y;
            cout << cnt[y  + a + 1][x + b + 1] << endl;
        }
       
        /*rep(i, m) {
            rep(j, n) {
                cout << cnt[i + a + 1][j + b + 1] << " ";
            }
            cout << endl;
        }
        */
        
    }
	return 0;
}



Measured memory_bytes: 6868
import java.util.Scanner;

public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		while (true) {
			String g = scan.next();
			if (g.equals("#"))
				return;
			int y = scan.nextInt();
			int m = scan.nextInt();
			int d = scan.nextInt();
			if (y < 31)
				System.out.println(g + " " + y + " " + m + " " + d);
			else if (y == 31 && m < 5)
				System.out.println(g + " " + y + " " + m + " " + d);
			else
				System.out.println("? " + (y - 30) + " " + m + " " + d);
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}

}



Measured memory_bytes: 27140
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <cstring>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front

using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;

typedef pair<int, int> P;

bool ps1(const P &forall_a_in_P, const P &forall_b_in_P)
{ //first昇順
    return forall_a_in_P.first < forall_b_in_P.first;
}
bool ps2(const P &forall_a_in_P, const P &forall_b_in_P)
{ //first降順
    return forall_a_in_P.first > forall_b_in_P.first;
}
bool ps3(const P &forall_a_in_P, const P &forall_b_in_P)
{ //second昇順
    return forall_a_in_P.second < forall_b_in_P.second;
}
bool ps4(const P &forall_a_in_P, const P &forall_b_in_P)
{ //second降順
    return forall_a_in_P.second > forall_b_in_P.second;
}


int main()
{
    int n;
    cin>>n;
    vector<int>p(n);
    int me=1e9;
    int cnt=0;
    rep(i,n){
        cin>>p[i];
        if(me>=p[i]){
            cnt++;
        }
        me=min(me,p[i]);
    }
   
   cout<<cnt<<endl;
}

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

int main(void){
   int a;
   int b;
   int c;
   cin >> a>>b>>c;
   if(a<b&&b<c){
   cout << "Yes";
   }else {
     cout <<"No";
   }
   cout <<endl;
   
}


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define for_each(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = __INT_MAX__;               // 2^31 - 1
const long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

double dp[305][305][305];

int main() {
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    int cnt_1, cnt_2, cnt_3;
    cnt_1 = cnt_2 = cnt_3 = 0;
    SPC(10);
    rep(i, n) {
        if (a[i] == 1) cnt_1++;
        if (a[i] == 2) cnt_2++;
        if (a[i] == 3) cnt_3++;
    }

    rep(k, n + 1) {
        rep(j, n + 1) {
            rep(i, n + 1) {
                int sum = i + j + k;
                if (sum == 0) continue;

                dp[i][j][k] = 1.0 * n / sum;
                if (i > 0) dp[i][j][k] += dp[i - 1][j][k] * i / sum;
                if (j > 0) dp[i][j][k] += dp[i + 1][j - 1][k] * j / sum;
                if (k > 0) dp[i][j][k] += dp[i][j + 1][k - 1] * k / sum;
                // debug(dp[i][j][k]);
                // debug(i);
                // debug(j);
                // debug(k);
            }
        }
    }

    out(dp[cnt_1][cnt_2][cnt_3]);
    return 0;
}


Measured memory_bytes: 219392
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define debug(a) cout << #a ": " << a << endl
using namespace std;
typedef long long ll;
const double eps = 1e-9;
ll a, b, n;
ll calc(ll x){
    return a*x/b - a*(x/b);
}
int main(void){
    IOS;
    cin >> a >> b >> n;
    if (n <= b){
        cout << calc(min(n, b-1)) << endl; return 0;
    }
    ll l = b+1, r = n, ans = b;
    while (l < r-10){
        ll m1 = (l+r) >> 1;
        ll m2 = (m1+r) >> 1;
        if (calc(m1) > calc(m2)){
            ans = m1;
            r = m2-1;
        }else{
            l = m1+1;
        }
    }
    for (ll i = l; i <= r; ++i){
        if (calc(i) > calc(ans)) ans = i;
    }
    cout << max(calc(ans), calc(b-1)) << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,w;
vector<vector<int>> a,dp;

int ans=0;
int fun(int pos,int w)
{
    if(pos==n)
    return 0;
     
    if(dp[pos][w]!=-1)
    return dp[pos][w];
   
  
         
    int x=0;
    if(w>=a[pos][0])
        x=a[pos][1]+fun(pos+1,w-a[pos][0]);
    dp[pos][w]=max(x,fun(pos+1,w));
    ans=max(ans,dp[pos][w]);
    return dp[pos][w];
}

signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 cin>>n>>w;
 dp=vector<vector<int>>(n,vector<int>(w+5,-1));
 a=vector<vector<int>>(n,vector<int>(2));
 for(int i=0;i<n;i++)
 {
      cin>>a[i][0]>>a[i][1];
 }
 fun(0,w);
 cout<<ans;
 
} 

Measured memory_bytes: 79488
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, K, L = 0;
  cin >> N >> K;
  vector<int> h(N);
  for (int i = 0; i < N; i++) {cin >> h.at(i);}
  for (int i = 0; i < N; i++) {
    if (h.at(i) >= K) {L++;} 
  }
  cout << L << endl;
}

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

#define MAX 101

int total_cost = 0;

vector<vector<int>> adj_mat(MAX, vector<int>(MAX, INT_MAX));

int find_node(vector<int> cost){
    int node;
    int min = INT_MAX;
    rep(i, cost.size()){
        if(cost.at(i) < min){
            node = i;
            min = cost.at(i);
        }
    }
    total_cost += min;

    return node;
}

void prim(int node_size){
    int node = 0;
    vector<int> U(node_size, 0);  // 最小全域木に含まれない頂点
    vector<int> cost(node_size); //構築中の木と未処理ノードvの間のコスト

    // cost, nearestNodeの初期化
    rep(i, node_size){
        cost.at(i) = adj_mat.at(node).at(i);
    }

    // rep(i, node_size) cout << cost.at(i) << " ";
    // cout << endl;

    U.at(node) = 1; //nodeは処理済み

    while(accumulate(U.begin(), U.end(), 0) != node_size){
        // 構築中の木に一番近いノードを探す
        int x = find_node(cost);
        // cout << "add node :" << x << endl;
        U.at(x) = 1;

        cost.at(x) = INT_MAX; // 自分自身へのコストは無限大とする

        rep(i, node_size){
            if(U.at(i) == 1){
                continue;
            }
            // 未処理ノードと新たに加えたノードとの距離が、以前のcostよりも小さい場合、更新
            if(adj_mat.at(x).at(i) < cost.at(i)){
                cost.at(i) = adj_mat.at(x).at(i);
            }
        }
        // rep(i, node_size) cout << cost.at(i) << " ";
        // cout << endl;
    }
} 

int main(){
    int n; cin >> n;
    rep(i, n){
        rep(j, n){
            cin >> adj_mat.at(i).at(j);
            if(adj_mat.at(i).at(j) == -1){
                adj_mat.at(i).at(j) = INT_MAX;
            }
        }
    }


    prim(n);
    cout << total_cost << endl;
}


Measured memory_bytes: 3204
import java.io.*;
import java.util.*;

public class Main {

    void run() {
        int N = readInt();
        int M = readInt();
        double[] L = new double[N];
        double[] A = new double[N];
        double[] B = new double[N];
        for (int i = 0; i < N; i++) {
            L[i] = readDouble();
            A[i] = readDouble();
            B[i] = readDouble();
        }
        double max = 0.0;
        for (int i = 0; i < 1 << N; i++) {
            if (Integer.bitCount(i) == M) {
                double sum = 0.0;
                for (int a = 0; a < N; a++) {
                    for (int b = a + 1; b < N; b++) {
                        if (((i >> a) & 1) != 0 && ((i >> b) & 1) != 0) {
                            double dl = L[a] - L[b];
                            double da = A[a] - A[b];
                            double db = B[a] - B[b];
                            sum += (dl * dl + da * da + db * db);
                        }
                    }
                }
                max = Math.max(max, sum);
            }
        }
        sysout.printf("%.5f\n", max);
    }

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

    // flush automatically iff you call `println` or `printf` or `format`.
    PrintWriter sysout = new PrintWriter(System.out, true);

    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer buffer = new StringTokenizer("");

    String read() {
        if (!buffer.hasMoreTokens()) {
            try {
                buffer = new StringTokenizer(in.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return buffer.nextToken();
    }

    int readInt() {
        return Integer.parseInt(read());
    }

    long readLong() {
        return Long.parseLong(read());
    }

    double readDouble() {
        return Double.parseDouble(read());
    }

    String readLine() {
        buffer = new StringTokenizer("");
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

Measured memory_bytes: 20016
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
while(true){
   var mn=arr.shift();
   if(mn=="0 0")break;
   mn=mn.split(" ").map(Number);
   var m=mn[0];
   var n=mn[1];
   var ary=[];
   for(var i=0;i<18;i++)ary[i]=0;
   ary[0]=m;
   for(var j=1;j<n;j++){
      var plus=[];
      for(var i=0;i<18;i++)plus[i]=0;
      ary.forEach(function(v,i){
         var k=v*m;
         if(k>=10000){
            ary[i]=k%10000;
            plus[i+1]+=Math.floor(k/10000);
         }else{
            ary[i]=k;
         }
      });
      ary.forEach(function(v,i){
         var k=ary[i]+plus[i];
         if(k>=10000){
            ary[i]=k%10000;
            ary[i+1]+=Math.floor(k/10000);
         }else{
            ary[i]=k;
         }
      });
   }
   var us=["","Man","Oku","Cho","Kei","Gai","Jo","Jou","Ko","Kan","Sei","Sai","Gok","Ggs","Asg","Nyt","Fks","Mts"];
   var str="";
   ary.forEach(function(v,i){
      if(v!=0)str=v+us[i]+str;
   });
   if(str=="")str=0;
   console.log(str);
}

Measured memory_bytes: 17932
int main() {
    int H, W, i, x;
    for(;scanf("%d%d", &H, &W);){
        if(H == 0 && W == 0)break;
        for(i=0;i<H;i++){
            if(i==0|| i==(H-1))
                for(x=0;x<W;x++)
                    printf("#");
            else{
                printf("#");
                for(x=1;x<(W-1);x++)
                    printf(".");
                printf("#");}
            printf("\n");}
        printf("\n");}
    return 0;
}

Measured memory_bytes: 572
#include <stdio.h>
#include <stdlib.h>

struct node{
    int to, cap; // 行き先, 容量
    struct node *next;
};
typedef struct node graph;

void add_edge(graph *g[], int u, int v, int c){
    graph *new_edge = (graph*)malloc(sizeof(graph));
    new_edge->to = v; new_edge->cap = c;
    // 新しい辺は先頭に追加していく
    new_edge->next = g[u];
    g[u] = new_edge;
}

void print_graph(graph *g[], int v){
    for(int i = 0; i <= v; i++){
        if(g[i] == NULL) continue;
        graph *tmp = g[i];
        while(tmp){
            printf("(from:%d, to:%d, cap:%d) ", i, tmp->to, tmp->cap);
            tmp = tmp->next;
        }
        printf("\n");
    }
}

void init_graph(graph *g[], int n){
    for(int i = 0; i <= n; i++){
        g[i] = NULL;
    }
}

int can_push(int height[], int from, int to, int res){
    // h(u) == h(v) + 1 && 残余容量 > 0
    return height[from] == height[to] + 1 && res > 0;
}

void push(graph *g, int from, int v, int flow[v][v], int *excess){
    int to = g->to, res = g->cap - flow[from][to];
     // 流せる最大量を求める
    int f = excess[from] < res ? excess[from] : res;
    excess[from] -= f;
    excess[to] += f;
    flow[from][to] += f;
    flow[to][from] -= f;
}

void rift(graph *g[], int from, int *height, int v, int flow[v][v]){
    graph *tmp = g[from];
    int min_h = v * 2 - 1;
    while(tmp){
        int res = tmp->cap - flow[from][tmp->to];
        if(res > 0){
            min_h = min_h < height[tmp->to] ? min_h : height[tmp->to];
        }
        tmp = tmp->next;
    }
    height[from] = min_h + 1;
}

int check(graph *g[], int s, int t, int excess[]){
    for(int i = s; i <= t; i++){
        graph *tmp = g[i];
        while(tmp){
            if(tmp->to != s && tmp->to != t && excess[tmp->to] > 0) return tmp->to;
            tmp = tmp->next;
        }
    }
    return -1;
}

void init(graph *g[], int v, int s, int *height, int *excess, int flow[v][v]){
    for(int i = 0; i < v; i++){
        height[i] = 0; excess[i] = 0;
        for(int j = 0; j < v; j++) flow[i][j] = 0;
    }
    height[s] = v;
    graph *tmp = g[s];
    while(tmp){
        excess[s] += tmp->cap;
        push(tmp, s, v, flow, excess);
        tmp = tmp->next;
    }
}

void preflow_push(graph *g[], int v, int s, int t){
    int height[v], excess[v], flow[v][v];
    init(g, v, s, height, excess, flow);
    int cur = check(g, s, t, excess);
    while(cur != -1){
        graph *tmp = g[cur];
        while(tmp){
            if(can_push(height, cur, tmp->to, tmp->cap - flow[cur][tmp->to]) != 0) break;
            tmp = tmp->next;
        }
        if(tmp != NULL) push(tmp, cur, v, flow, excess);
        else rift(g, cur, height, v, flow);
        cur = check(g, s, t, excess);
    }
    printf("%d\n", excess[t]);
}

int main(){
    int v, e; // v -> 頂点数, e -> 辺数
    scanf("%d %d", &v, &e);
    graph *g[v];
    init_graph(g, v);
    int s, t, c;
    for(int i = 0; i < e; i++){
        scanf("%d %d %d", &s, &t, &c);
        //s--; t--;
        add_edge(g, s, t, c); // 辺を追加
        add_edge(g, t, s, 0); // 辺を追加
    }
    preflow_push(g, v, 0, v - 1);
    // print_graph(g, v);
    return 0;
}



Measured memory_bytes: 2140
using System;
using System.Text;

namespace B {
    class Program {
        static void Main(string[] args) {
            string S = Console.ReadLine();
            int w = int.Parse(Console.ReadLine());

            var tmp = S.ToCharArray();
            StringBuilder ans = new StringBuilder();
            for (int i = 0; i < S.Length; ++i) {
                if (i % w == 0) ans.Append(tmp[i]);
            }

            Console.WriteLine(ans.ToString());
        }
    }
}


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

int main() {
    int n;
    long long v;
    cin >> n >> v;
    long long a[4][n];
    for (int i = 0; i < 4; ++i) for (int j = 0; j < n; ++j) cin >> a[i][j];
    long long b[n*n], c[n*n];
    for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) b[i*n+j] = a[0][i] + a[1][j];
    for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) c[i*n+j] = a[2][i] + a[3][j];
    sort(c, c+n*n);
    long long res = 0;
    for (int i = 0; i < n*n; ++i) res += upper_bound(c, c+n*n, v-b[i]) - lower_bound(c, c+n*n, v-b[i]);
    cout << res << endl;
}


Measured memory_bytes: 18788
K,X=(int(x) for x in input().split())
min=X-K+1
max=X+K-1

if min<=0:
  total=max-min+1
  for g in range(total):
    print(min+g,end=" ")
elif min>0:
  total=max-min+1
  for g in range(total):
    print(min+g,end=" ")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i < (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; }
template<class T> inline bool change(T& a, T b) { if (a != b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;

char c[7][7];

int main(){
    int h,w,k; cin >> h >> w >> k;
    int db=0;
    rep(i,h){
        rep(j,w){
            cin >> c[i][j];
            if(c[i][j]=='#') db++;
        }
    }
    int target=db-k;
    int hh=1<<h;
    int ww=1<<w;
    int ans=0;
    rep(i,hh){
        rep(j,ww){
            int cnt=0;
            rep(ii,h){
                rep(jj,w){
                    if(j & (1<<jj)){
                        if(c[ii][jj]=='#') cnt++;
                    }else if(i & (1<<ii)){
                        if(c[ii][jj]=='#') cnt++;
                    }
                }
            }
            if(cnt==target) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
//----------------------------おまじない
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
//----------------------------
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#define eb(i,j) emplace_back((i),(j))
#include <bits/stdc++.h>
using namespace std;
//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;
const int mod = 1000000009;

struct node {
    ll v, d;
    node(ll v, ll d):v(v),d(d){}
    bool operator<(const node &n) const { return d > n.d; }
};
struct edge { ll to, d; edge(ll ti, ll di){to = ti; d = di;} };
vector<edge> G[ 100010 ];
ll dist[ 100010 ]; // shortest distance

void dijkstra(ll s) {
    REP(i,100010) dist[i] = -1;
    priority_queue<node> que;
    que.push(node(s, 0));
    while(!que.empty()){
        ll v = que.top().v, d = que.top().d;
        que.pop();
        if(dist[v] >= 0 and dist[v] <= d) continue;
        dist[v] = d;
        for(auto j : G[v])
            que.push(node(j.to, d+j.d));
    }
}

ll yen[100010], snuuk[100010],ans[100010];
int n,m,s,t;
int train[100010][4];
constexpr ll asset = 1000000000000000LL;


int main(){
    I(n); I(m); I(s); I(t);
    REP(i,m) REP(j,4) I(train[i][j]);

    //YEN
    REP(i,m){
        auto line = train[i];
        G[line[0]].pb( edge(line[1],line[2]) );
        G[line[1]].pb( edge(line[0],line[2]) );
    }
    dijkstra(s);
    
    swap(yen,dist);
    
    REP(i,100010) G[i].clear();

    //SNUUK
    REP(i,m){
        auto line = train[i];
        G[line[0]].pb( edge(line[1],line[3]) );
        G[line[1]].pb( edge(line[0],line[3]) );
    }
    dijkstra(t);
    swap(snuuk,dist);

    ans[0] = asset;
    ans[n+1] = asset;
    REPN(i,n){
        ans[i] = min(ans[i+1], yen[i]+snuuk[i]);
    }
    FOR(i,1,n+1) printf("%lld\n",asset-ans[i]);

}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
	cin.tie(0);
    
    int sz, k;
    cin >> sz >> k;
    
    vector<int> hs(sz, 0);
    for (auto &h : hs) {
        cin >> h;
    }
    
    vector<int> dp(sz, INT_MAX);
    dp[0] = 0;
    
    for (int i = 0; i < sz; ++i) {
        for (int j = 1; j <= k && i + j < sz; ++j) {
            dp[i + j] = min(dp[i + j], dp[i] + abs(hs[i] - hs[i + j]));
        }
    }
    
    cout << dp.back() << endl;

    return 0;
}


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

#define size 10

bool dfs(int a[],int i,int b,int c){
  if(i==0)return 1;

  bool flag=0;

  if(a[size-i]>b){
    flag += dfs(a,i-1,a[size-i],c);
  }
  if(a[size-i]>c){
    flag += dfs(a,i-1,b,a[size-i]);
  }

  return flag;
}

int main(){
  int n;
  cin >> n;
  while(n>0){
    int a[size];

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

    if(dfs(a,size,0,0)){
      cout << "YES\n";
    }else{
      cout << "NO\n";
    }

    n--;
  }

  return 0;
}


Measured memory_bytes: 3000
#include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY  1
#define BLACK 2
int  n, M[N][N], color[N], f[N], d[N], t;
void dfs_visit(int);
void dfs();
int main(){
  int u, k, v;
  int i, j;

  scanf("%d", &n);

  for( i = 0; i < n; i++ ){
    for( j = 0; j < n; j++ ){
      M[i][j] = 0;
    }
  }
  for( i = 0; i < n; i++ ){
    scanf("%d", &u);
    scanf("%d", &k);
    u--;
    for( j = 0; j < k; j++ ){
      scanf("%d", &v);
      v--;
      M[u][v] = 1;
    }
  }
  dfs();
  
  return 0;
}

void dfs_visit(int u){
  int v;
  color[u] = GRAY;
  d[u] = ++t;
  for( v = 0; v < n; v++ ){
    if( M[u][v] && color[v] == WHITE ){
      dfs_visit(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++t;
}

void dfs(){
  int u;
  for( u = 0; u < n; u++ ){
    color[u] = WHITE;
  }
  t = 0;
  for( u = 0; u < n; u++ ){
    if( color[u] == WHITE ){
      dfs_visit(u);
    }
  }
  for( u = 0; u < n; u++ ){
    printf("%d %d %d\n", u + 1, d[u], f[u]);
  }
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
//mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count());
//int rnd(int x) { return mrand()%x;}
typedef long long ll;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll d[10100];
int main(){
	ll k,q;
	scanf("%lld%lld",&k,&q);
	for(int i=1;i<=k;i++){
		scanf("%lld",&d[i]);
	}
	while(q--){
		ll n,x,m;
		scanf("%lld%lld%lld",&n,&x,&m);
		ll pre=0;
		for(int i=1;i<=k;i++){
			pre+=d[i]%m;
			if(d[i]%m==0) pre+=m;
		}
		ll tmp=(n-1)/k;
		ll ans=n-1;
		ll pt=tmp*pre;
		for(int i=1;i<=(n-1)%k;i++){
			pt+=d[i]%m;
			if(d[i]%m==0) pt+=m;
		}
		pt=(pt+x%m)/m;
		ans-=pt;
		printf("%lld\n",ans);
	}
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<string>
#include<functional>
using namespace std;

signed main() {
	int a; scanf("%d", &a);
	vector<int>b(100), c(100);
	int d; scanf("%d", &d);
	for (int e = 0; e < d; e++) {
		string f; int g;
		cin >> f >> g;
		if (f == "D")b.push_back(g);
	}
	scanf("%d", &d);
	for (int e = 0; e < d; e++) {
		string f; int g;
		cin >> f >> g;
		if (f == "DD")c.push_back(g);
	}
	sort(b.begin(), b.end(), greater<int>());
	sort(c.begin(), c.end(), greater<int>());
	int MAX = 0;
	for (int i = 0; i <= a; i++) {//b??????????????????
		int sum = 0;
		for (int j = 0; j < i; j++) {
			sum += b[j];
		}
		for (int j = 0; j < (a - i) / 2; j++) {
			sum += c[j];
		}
		MAX = max(MAX, sum);
	}
	printf("%d\n", MAX);
}

Measured memory_bytes: 3320
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define str string
#define vi vector<int>
#define vd vector<double>
#define vs vector<string>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m-1);i>=(int)(n);i--)
#define rev(i, n) revi(i, n, 0)
#define each(i, n) for(auto&& i: n)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size()) 
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define dump(x) cerr << #x << "=" << x <<endl
#define gcd __gcd
#define popcount __builtin_popcountll
int lcm(int a, int b){return a / gcd(a, b) * b;}
const int INF = 1e18;
const int MOD = 1e9 + 7;
const double EPS = 1e-15;
const double PI = acos(-1);

void solve(){
	str S, T;
	cin >> S >> T;
	int dd = 8101919;
	str ans = "UNRESTORABLE";
	rep(d, sz(S) - sz(T) + 1) {
		int f = 1;
		rep(i, sz(T)) {
			if (S[d + i] != T[i] && S[d + i] != '?') {
				f = 0;
			}
		}
		if (f) dd = d;
	}
	if (dd < 8101919) {
		rep(i, sz(S)) {
			if (S[i] == '?') {
				S[i] = 'a';
			}
		}
		rep(i, sz(T)) {
			S[dd + i] = T[i];
		}
		ans = S;
	}
	cout << ans << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>

using namespace std;
#define LOCAL  1
#define UPLOAD 2
#define ll long long
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';

int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
  long A = input();
  long minVal = 1000000000000;
  for(long i=1;i<=sqrt(A);i++){
    if(A%i == 0){
      minVal = min(i + A/i - 2, minVal);
    }
  }
  output(minVal);

  return 0;
}

Measured memory_bytes: 256
import math
a,b,x = map(int,input().split())

if x > b*a**2/2:
    y = 2*b - 2*x/(a**2)
    print(math.atan(y/a)*180/math.pi)
else:
    y = 2*x/(a*b)
    print(math.atan(b/y)*180/math.pi)

Measured memory_bytes: 3060